From c5cfb77a87b638e424c4bf3128e085bba129643f Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sun, 15 Apr 2007 17:03:42 +0000 Subject: [PATCH] Add refresh medialist in context sensitive of medialist tree. If context sensitive joblist on media produces no results, inform user with message. Change text in context sensitive menu's on medilist. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4560 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/joblist/joblist.cpp | 16 ++++++-- bacula/src/qt-console/joblist/joblist.h | 1 + bacula/src/qt-console/mainwin.cpp | 18 +++++--- bacula/src/qt-console/medialist/medialist.cpp | 41 +++++++++++-------- bacula/src/qt-console/medialist/medialist.ui | 22 ++++++++-- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/bacula/src/qt-console/joblist/joblist.cpp b/bacula/src/qt-console/joblist/joblist.cpp index 356f69c301..85d147cfbe 100644 --- a/bacula/src/qt-console/joblist/joblist.cpp +++ b/bacula/src/qt-console/joblist/joblist.cpp @@ -47,6 +47,7 @@ JobList::JobList(QStackedWidget *parent, Console *console, QString &medianame) mp_console = console; m_parent = parent; m_medianame = medianame; + m_resultCount = 0; m_populated = false; m_closeable = false; /* connect to the action specific to this pages class */ @@ -67,15 +68,15 @@ void JobList::populateTable() /* Set up query QString and header QStringList */ QString query(""); - query += "SELECT j.jobid,j.name,j.starttime,j.type,j.level,j.jobfiles," - "j.jobstatus" + query += "SELECT j.Jobid,j.Name,j.Starttime,j.Type,j.Level,j.Jobfiles," + "j.Jobstatus" " FROM job j, jobmedia jm, media m" " WHERE jm.jobid=j.jobid and jm.mediaid=m.mediaid"; if (m_medianame != "") { query += " and m.VolumeName='" + m_medianame + "'"; m_closeable=true; } - query += " ORDER BY j.starttime"; + query += " ORDER BY j.Starttime"; QStringList headerlist = (QStringList() << "Job Id" << "Job Name" << "Job Starttime" << "Job Type" << "Job Level" << "Job Files" << "Job Status"); @@ -85,7 +86,11 @@ void JobList::populateTable() mp_tableWidget->setColumnCount(headerlist.size()); mp_tableWidget->setHorizontalHeaderLabels(headerlist); + /* printf("Query cmd : %s\n",query.toUtf8().data()); + * This could be a debug message?? */ if (mp_console->sql_cmd(query, results)) { + m_resultCount = results.count(); + QTableWidgetItem* p_tableitem; QString field; QStringList fieldlist; @@ -106,6 +111,11 @@ void JobList::populateTable() } row++; } + } + if ((m_medianame != "") && (m_resultCount == 0)){ + /* for context sensitive searches, let the user know if there were no results */ + QMessageBox::warning(this, tr("Bat"), tr("The Jobs query returned no results.\n" + "Press OK to continue?"), QMessageBox::Ok ); } } diff --git a/bacula/src/qt-console/joblist/joblist.h b/bacula/src/qt-console/joblist/joblist.h index 15b8ca60df..c2769dc559 100644 --- a/bacula/src/qt-console/joblist/joblist.h +++ b/bacula/src/qt-console/joblist/joblist.h @@ -46,6 +46,7 @@ public: JobList(QStackedWidget *parent, Console *console, QString &medianame); virtual void PgSeltreeWidgetClicked(); virtual void currentStackItem(); + int m_resultCount; public slots: void populateTable(); diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index bb3d3a9b91..09192ab621 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -132,7 +132,9 @@ void MainWin::createPagemedialist() */ void MainWin::createPagejoblist(QString &media) { - QTreeWidgetItem *item; + QTreeWidgetItem *item, *holdItem; + /* save current tree widget item in case query produces no results */ + holdItem = treeWidget->currentItem(); if (media == "") { item=createPage("All Jobs", m_topItem); } else { @@ -143,9 +145,15 @@ void MainWin::createPagejoblist(QString &media) JobList* joblist = new JobList(stackedWidget, m_console, media); hashInsert(item, joblist); joblist->dockPage(); + /* If this is a query of jobs on a specific media */ if (media != "") { stackedWidget->setCurrentWidget(joblist); treeWidget->setCurrentItem(item); + /* did query produce results, if not close window and set back to hold */ + if (joblist->m_resultCount == 0) { + joblist->closeStackPage(); + treeWidget->setCurrentItem(holdItem); + } } } @@ -309,14 +317,12 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre /* The Previous item */ if (previousitem) { + /* make sure the close window and toggle dock options are removed */ + treeWidget->removeAction(actionClosePage); + treeWidget->removeAction(actionToggleDock); /* Is this a page that has been inserted into the hash */ if (getFromHash(previousitem)) { Pages* page = getFromHash(previousitem); - treeWidget->removeAction(actionToggleDock); - /* make sure the close window option is removed */ - if (page->isCloseable()) { - treeWidget->removeAction(actionClosePage); - } foreach(QAction* pageaction, page->m_contextActions) { treeWidget->removeAction(pageaction); } diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index 73beb5d06a..0ef2205658 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -71,26 +71,27 @@ void MediaList::populateTree() QStringList results; const char *query = "SELECT p.Name,m.VolumeName,m.MediaId,m.VolStatus,m.Enabled,m.VolBytes," - "m.VolFiles,m.VolRetention,m.MediaType,m.LastWritten" + "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 Retention" + << "Volume Bytes" << "Volume Files" << "Volume Jobs" << "Volume Retention" << "Media Type" << "Last Written"); m_checkcurwidget = false; mp_treeWidget->clear(); m_checkcurwidget = true; - mp_treeWidget->setColumnCount(9); + mp_treeWidget->setColumnCount(headerlist.count()); topItem = new QTreeWidgetItem(mp_treeWidget); topItem->setText(0, "Pools"); topItem->setData(0, Qt::UserRole, 0); - topItem->setExpanded( true ); + topItem->setExpanded(true); mp_treeWidget->setHeaderLabels(headerlist); + //printf("MediaList query cmd : %s\n",query); if (mp_console->sql_cmd(query, results)) { QString field; QStringList fieldlist; @@ -196,15 +197,24 @@ void MediaList::PgSeltreeWidgetDoubleClicked() * Added to set the context menu policy based on currently active treeWidgetItem * signaled by currentItemChanged */ -void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *) /*previouswidgetitem*/ +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){ - mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); m_currentlyselected=currentwidgetitem->text(1); - } else { - mp_treeWidget->setContextMenuPolicy(Qt::NoContextMenu); + mp_treeWidget->addAction(actionEditVolume); + mp_treeWidget->addAction(actionListJobsOnVolume); } } } @@ -216,18 +226,17 @@ void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetI */ void MediaList::createContextMenu() { - QAction *editAction = new QAction("Edit Properties", mp_treeWidget); - QAction *listAction = new QAction("List Jobs On Media", mp_treeWidget); - mp_treeWidget->addAction(editAction); - mp_treeWidget->addAction(listAction); - connect(editAction, SIGNAL(triggered()), this, SLOT(editMedia())); - connect(listAction, SIGNAL(triggered()), this, SLOT(showJobs())); + 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(actionRepopulateMediaTree, SIGNAL(triggered()), this, + connect(actionRefreshMediaList, SIGNAL(triggered()), this, SLOT(populateTree())); } @@ -241,7 +250,7 @@ void MediaList::currentStackItem() /* 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(actionRepopulateMediaTree); + m_contextActions.append(actionRefreshMediaList); /* Create the context menu for the medialist tree */ createContextMenu(); m_populated=true; diff --git a/bacula/src/qt-console/medialist/medialist.ui b/bacula/src/qt-console/medialist/medialist.ui index 803efcb806..4531d2939d 100644 --- a/bacula/src/qt-console/medialist/medialist.ui +++ b/bacula/src/qt-console/medialist/medialist.ui @@ -23,15 +23,31 @@ - + ../images/run.png - Repopulate Media Tree + Refresh Media List - Requery the director for the media. + Requery the director for the list of media. + + + + + ../images/status.png + + + Edit Volume + + + + + ../images/unmark.png + + + List Jobs On Volume -- 2.39.5