#include "mediaedit/mediaedit.h"
#include "joblist/joblist.h"
-MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem *treeItem, int indexseq)
+MediaList::MediaList(QStackedWidget *parent, Console *console)
{
- SetPassedValues(parent, treeItem, indexseq );
setupUi(this);
- m_treeWidget = treeWidget; /* our Storage Tree Tree Widget */
- m_console = console;
+ /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_medialist.h */
+ mp_console = console;
+ m_parent = parent;
createConnections();
- m_populated=false;
- m_headerlist = new QStringList();
- m_popupmedia = new QString("");
- m_poollist = new QStringList();
+ m_populated = false;
+ m_checkcurwidget = true;
+ m_closeable = false;
}
MediaList::~MediaList()
{
- delete m_headerlist;
- delete m_popupmedia;
- delete m_poollist;
}
+/*
+ * The main meat of the class!! The function that querries the director and
+ * creates the widgets with appropriate values.
+ */
void MediaList::populateTree()
{
QTreeWidgetItem *mediatreeitem, *pooltreeitem, *topItem;
+ QString currentpool("");
+ QString resultline;
+ QStringList results;
+ const char *query =
+ "SELECT p.Name,m.VolumeName,m.MediaId,m.VolStatus,m.Enabled,m.VolBytes,"
+ "m.VolFiles,m.VolJobs,m.VolRetention,m.MediaType,m.LastWritten"
+ " FROM Media m,Pool p"
+ " WHERE m.PoolId=p.PoolId"
+ " ORDER BY p.Name";
+ QStringList headerlist = (QStringList()
+ << "Pool Name" << "Volume Name" << "Media Id" << "Volume Status" << "Enabled"
+ << "Volume Bytes" << "Volume Files" << "Volume Jobs" << "Volume Retention"
+ << "Media Type" << "Last Written");
- m_treeWidget->clear();
- m_treeWidget->setColumnCount(3);
- topItem = new QTreeWidgetItem(m_treeWidget);
+ m_checkcurwidget = false;
+ mp_treeWidget->clear();
+ m_checkcurwidget = true;
+ mp_treeWidget->setColumnCount(headerlist.count());
+ topItem = new QTreeWidgetItem(mp_treeWidget);
topItem->setText(0, "Pools");
topItem->setData(0, Qt::UserRole, 0);
- topItem->setExpanded( true );
-#ifdef xxx
-#include <QSize>
-***** FIXME *****
-//how to get the size of a column to be larger
-//topItem->setSizeHint(0,QSize(1050,50));
-#endif
-
- /* Start with a list of pools */
- m_poollist->clear();
- m_headerlist->clear();
- m_headerlist->append("Volume Name");
- m_headerlist->append("Media Id");
- m_headerlist->append("Type");
- m_treeWidget->setHeaderLabels(*m_headerlist);
+ topItem->setExpanded(true);
- QString currentpool("");
- QString resultline;
- QStringList results;
- const char* m_cmd = ".sql \"select p.name, m.volumename, m.mediaid, m.mediatype from media m, pool p ORDER BY p.name\"";
- if ( m_console->dir_cmd(m_cmd,results)){
- int recordcounter=0;
- foreach( resultline, results ){
- QRegExp regex("^Using Catalog");
- if ( regex.indexIn(resultline) < 0 ){
- QStringList recorditemlist = resultline.split("\t");
- int recorditemcnter=0;
- /* Iterate through items in the record */
- QString mediarecorditem;
- foreach( mediarecorditem, recorditemlist ){
- QString trimmeditem = mediarecorditem.trimmed();
- if( trimmeditem != "" ){
- if ( recorditemcnter == 0 ){
- if ( currentpool != trimmeditem.toUtf8().data() ){
- currentpool = trimmeditem.toUtf8().data();
- pooltreeitem = new QTreeWidgetItem(topItem);
- pooltreeitem->setText(0, trimmeditem.toUtf8().data());
- pooltreeitem->setData(0, Qt::UserRole, 1);
- pooltreeitem->setExpanded( true );
- }
- mediatreeitem = new QTreeWidgetItem(pooltreeitem);
- } else {
- mediatreeitem->setData(recorditemcnter-1, Qt::UserRole, 2);
- mediatreeitem->setText(recorditemcnter-1, trimmeditem.toUtf8().data());
+ mp_treeWidget->setHeaderLabels(headerlist);
+
+ //printf("MediaList query cmd : %s\n",query);
+ if (mp_console->sql_cmd(query, results)) {
+ QString field;
+ QStringList fieldlist;
+
+ foreach (resultline, results) {
+ fieldlist = resultline.split("\t");
+ int index = 0;
+ /* Iterate through fields in the record */
+ foreach (field, fieldlist) {
+ field = field.trimmed(); /* strip leading & trailing spaces */
+ if (field != "") {
+ /* The first field is the pool name */
+ if (index == 0) {
+ /* If new pool name, create new Pool item */
+ if (currentpool != field) {
+ currentpool = field;
+ pooltreeitem = new QTreeWidgetItem(topItem);
+ pooltreeitem->setText(0, field);
+ pooltreeitem->setData(0, Qt::UserRole, 1);
+ pooltreeitem->setExpanded(true);
}
- recorditemcnter+=1;
+ mediatreeitem = new QTreeWidgetItem(pooltreeitem);
+ mediatreeitem->setData(index, Qt::UserRole, 2);
+ } else {
+ /* Put media fields under the pool tree item */
+ mediatreeitem->setData(index, Qt::UserRole, 2);
+ mediatreeitem->setText(index, field);
}
}
+ index++;
}
- recordcounter+=1;
}
}
}
+/*
+ * Not being used currently, Should this be kept for possible future use.
+ */
void MediaList::createConnections()
{
- connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
+ connect(mp_treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
SLOT(treeItemClicked(QTreeWidgetItem *, int)));
- connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
+ connect(mp_treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
}
-void MediaList::treeItemClicked(QTreeWidgetItem *item, int column)
+/*
+ * Not being used currently, Should this be kept for possible future use.
+ */
+void MediaList::treeItemClicked(QTreeWidgetItem * /*item*/, int /*column*/)
{
- int treedepth = item->data(column, Qt::UserRole).toInt();
- QString text = item->text(0);
- switch (treedepth){
- case 1:
- break;
- case 2:
- /* Can't figure out how to make a right button do this --- Qt::LeftButton, Qt::RightButton, Qt::MidButton */
- *m_popupmedia = text;
- QMenu *popup = new QMenu( m_treeWidget );
- connect(popup->addAction("Edit Properties"), SIGNAL(triggered()), this, SLOT(editMedia()));
- connect(popup->addAction("Show Jobs On Media"), SIGNAL(triggered()), this, SLOT(showJobs()));
- popup->exec(QCursor::pos());
- }
}
-void MediaList::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
+/*
+ * Not being used currently, Should this be kept for possible future use.
+ */
+void MediaList::treeItemDoubleClicked(QTreeWidgetItem * /*item*/, int /*column*/)
{
- int treedepth = item->data(column, Qt::UserRole).toInt();
- if (treedepth >= 0) {
- }
}
+/*
+ * Called from the signal of the context sensitive menu!
+ */
void MediaList::editMedia()
{
- MediaEdit* edit = new MediaEdit(m_console, *m_popupmedia);
+ MediaEdit* edit = new MediaEdit(mp_console, m_currentlyselected);
edit->show();
}
+/*
+ * Called from the signal of the context sensitive menu!
+ */
void MediaList::showJobs()
{
- JobList* joblist = new JobList(m_console, *m_popupmedia);
- joblist->show();
+ QString emptyclient("");
+ mainWin->createPageJobList(m_currentlyselected, emptyclient);
}
+/*
+ * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
+ * The tree has been populated.
+ */
void MediaList::PgSeltreeWidgetClicked()
{
- if( ! m_populated ){
+ if(!m_populated) {
populateTree();
+ createContextMenu();
m_populated=true;
}
}
+/*
+ * When the treeWidgetItem in the page selector tree is doubleclicked, Use that
+ * As a signal to repopulate from a query of the database.
+ * Should this be from a context sensitive menu in either or both of the page selector
+ * or This widnow ???
+ */
void MediaList::PgSeltreeWidgetDoubleClicked()
{
populateTree();
}
+
+/*
+ * Added to set the context menu policy based on currently active treeWidgetItem
+ * signaled by currentItemChanged
+ */
+void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
+{
+ /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
+ if (m_checkcurwidget) {
+ /* The Previous item */
+ if (previouswidgetitem) { /* avoid a segfault if first time */
+ int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
+ if (treedepth == 2){
+ mp_treeWidget->removeAction(actionEditVolume);
+ mp_treeWidget->removeAction(actionListJobsOnVolume);
+ }
+ }
+
+ int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
+ if (treedepth == 2){
+ m_currentlyselected=currentwidgetitem->text(1);
+ mp_treeWidget->addAction(actionEditVolume);
+ mp_treeWidget->addAction(actionListJobsOnVolume);
+ }
+ }
+}
+
+/*
+ * Setup a context menu
+ * Made separate from populate so that it would not create context menu over and
+ * over as the tree is repopulated.
+ */
+void MediaList::createContextMenu()
+{
+ mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+ /*mp_treeWidget->setContextMenuPolicy(Qt::NoContextMenu);*/
+ mp_treeWidget->addAction(actionRefreshMediaList);
+ connect(actionEditVolume, SIGNAL(triggered()), this, SLOT(editMedia()));
+ connect(actionListJobsOnVolume, SIGNAL(triggered()), this, SLOT(showJobs()));
+ mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+ connect(mp_treeWidget, SIGNAL(
+ currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
+ this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+ /* connect to the action specific to this pages class */
+ connect(actionRefreshMediaList, SIGNAL(triggered()), this,
+ SLOT(populateTree()));
+}
+
+/*
+ * Virtual function which is called when this page is visible on the stack
+ */
+void MediaList::currentStackItem()
+{
+ if(!m_populated) {
+ populateTree();
+ /* add context sensitive menu items specific to this classto the page
+ * selector tree. m_m_contextActions is QList of QActions, so this is
+ * only done once with the first population. */
+ m_contextActions.append(actionRefreshMediaList);
+ /* Create the context menu for the medialist tree */
+ createContextMenu();
+ m_populated=true;
+ }
+}