From 4db36e1a74437b4b97bce1cfb043bce466cd6ce8 Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sun, 15 Apr 2007 03:08:37 +0000 Subject: [PATCH] dhb Added joblist to the stack and the page selector. Joblist starts in an all jobs by default and can be repopulated. If a list of jobs is gotten from a context sensitive query, it can be closed. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4556 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/console/console.cpp | 3 +- bacula/src/qt-console/joblist/joblist.cpp | 52 ++++-- bacula/src/qt-console/joblist/joblist.h | 10 +- bacula/src/qt-console/joblist/joblist.ui | 11 ++ bacula/src/qt-console/main.ui | 11 ++ bacula/src/qt-console/mainwin.cpp | 161 +++++++++++++----- bacula/src/qt-console/mainwin.h | 10 ++ bacula/src/qt-console/medialist/medialist.cpp | 10 +- bacula/src/qt-console/medialist/medialist.ui | 3 + bacula/src/qt-console/pages.cpp | 29 +++- bacula/src/qt-console/pages.h | 5 +- bacula/src/qt-console/restore/brestore.cpp | 1 + 12 files changed, 241 insertions(+), 65 deletions(-) diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 2dc8b1b739..4e431a410a 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -41,7 +41,8 @@ Console::Console(QStackedWidget *parent) { QFont font; - m_parent=parent; + m_parent = parent; + m_closeable = false; (void)parent; setupUi(this); diff --git a/bacula/src/qt-console/joblist/joblist.cpp b/bacula/src/qt-console/joblist/joblist.cpp index 2c54b893d5..356f69c301 100644 --- a/bacula/src/qt-console/joblist/joblist.cpp +++ b/bacula/src/qt-console/joblist/joblist.cpp @@ -40,14 +40,18 @@ /* * Constructor for the class */ -JobList::JobList(Console *console, QString &medianame) +JobList::JobList(QStackedWidget *parent, Console *console, QString &medianame) { setupUi(this); /* Store passed variables in member variables */ mp_console = console; + m_parent = parent; m_medianame = medianame; - - populateTable(); + m_populated = false; + m_closeable = false; + /* connect to the action specific to this pages class */ + connect(actionRepopulateJobList, SIGNAL(triggered()), this, + SLOT(populateTable())); } /* @@ -58,16 +62,20 @@ JobList::JobList(Console *console, QString &medianame) */ void JobList::populateTable() { - QStringList results; - QString resultline; + QStringList results; + QString resultline; - /* Set up query QString and header QStringList */ - QString query(""); - query += "SELECT j.jobid,j.name,j.starttime,j.type,j.level,j.jobfiles," + /* 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" " FROM job j, jobmedia jm, media m" - " WHERE jm.jobid=j.jobid and jm.mediaid=m.mediaid and m.VolumeName='"; - query += m_medianame + "' ORDER BY j.starttime"; + " 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"; QStringList headerlist = (QStringList() << "Job Id" << "Job Name" << "Job Starttime" << "Job Type" << "Job Level" << "Job Files" << "Job Status"); @@ -100,3 +108,27 @@ void JobList::populateTable() } } } + +/* + * * When the treeWidgetItem in the page selector tree is singleclicked, Make sure + * * The tree has been populated. + * */ +void JobList::PgSeltreeWidgetClicked() +{ + if (!m_populated) { + populateTable(); + m_populated=true; + } +} + +/* + * Virtual function which is called when this page is visible on the stack + */ +void JobList::currentStackItem() +{ + if (!m_populated) { + populateTable(); + m_contextActions.append(actionRepopulateJobList); + m_populated=true; + } +} diff --git a/bacula/src/qt-console/joblist/joblist.h b/bacula/src/qt-console/joblist/joblist.h index ee7a0341aa..15b8ca60df 100644 --- a/bacula/src/qt-console/joblist/joblist.h +++ b/bacula/src/qt-console/joblist/joblist.h @@ -36,22 +36,24 @@ #include #include "ui_joblist.h" #include "console.h" +#include "pages.h" -class JobList : public QWidget, public Ui::JobListForm +class JobList : public Pages, public Ui::JobListForm { Q_OBJECT public: - JobList(Console *console, QString &medianame ); + JobList(QStackedWidget *parent, Console *console, QString &medianame); + virtual void PgSeltreeWidgetClicked(); + virtual void currentStackItem(); public slots: - -private: void populateTable(); private: Console *mp_console; QString m_medianame; + bool m_populated; }; #endif /* _JOBLIST_H_ */ diff --git a/bacula/src/qt-console/joblist/joblist.ui b/bacula/src/qt-console/joblist/joblist.ui index 86f820a6e0..dd1e01dab4 100644 --- a/bacula/src/qt-console/joblist/joblist.ui +++ b/bacula/src/qt-console/joblist/joblist.ui @@ -23,6 +23,17 @@ + + + ../images/run.png + + + Repopulate Job List + + + Requery the director for the list of jobs. + + diff --git a/bacula/src/qt-console/main.ui b/bacula/src/qt-console/main.ui index 26e1518dbd..4f2b988734 100644 --- a/bacula/src/qt-console/main.ui +++ b/bacula/src/qt-console/main.ui @@ -462,6 +462,17 @@ ToggleDock + + + images/unmark.png + + + Close Page + + + Close The Current Page + + diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 3d0d5f480b..bb3d3a9b91 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -36,6 +36,7 @@ */ #include "bat.h" +#include "joblist/joblist.h" MainWin::MainWin(QWidget *parent) : QMainWindow(parent) { @@ -63,7 +64,7 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) void MainWin::createPages() { DIRRES *dir; - QTreeWidgetItem *item, *topItem; + QTreeWidgetItem *item; /* Create console tree stacked widget item */ m_console = new Console(stackedWidget); @@ -76,14 +77,14 @@ void MainWin::createPages() UnlockRes(); /* The top tree item representing the director */ - topItem = createTopPage(dir->name()); - topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); + m_topItem = createTopPage(dir->name()); + m_topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); /* Create Tree Widget Item */ - item = createPage("Console", topItem); + item = createPage("Console", m_topItem); m_console->setTreeItem(item); - /* Append to pagelist */ + /* insert the cosole and tree widget item into the hashes */ hashInsert(item, m_console); /* Set Color of treeWidgetItem for the console @@ -91,32 +92,61 @@ void MainWin::createPages() */ QBrush redBrush(Qt::red); item->setForeground(0, redBrush); + m_console->dockPage(); - /* - * Now with the console created, on with the rest, these are easy - * All should be - * 1. create tree widget item - * 2. create object passing pointer to tree widget item (modified constructors to pass QTreeWidget pointers) - * 3. append to stackhash - */ - - /* brestore */ - item=createPage("brestore", topItem); - bRestore* brestore=new bRestore(stackedWidget); - hashInsert(item, brestore); + /* create instances of the rest of the classes that will by default exist + * under each director */ + createPagebrestore(); + createPagemedialist(); + QString emptymedia(""); + createPagejoblist(emptymedia); + treeWidget->expandItem(m_topItem); + stackedWidget->setCurrentWidget(m_console); +} - /* lastly for now, the medialist */ - item=createPage("Media", topItem ); - MediaList* medialist=new MediaList(stackedWidget, m_console); - hashInsert(item, medialist); +/* + * create an instance of the the brestore class on the stack + */ +void MainWin::createPagebrestore() +{ + QTreeWidgetItem *item=createPage("brestore", m_topItem); + bRestore* brestore = new bRestore(stackedWidget); + hashInsert(item, brestore); + brestore->dockPage(); +} - /* Iterate through and add to the stack */ - foreach(Pages *page, m_pagehash) - page->dockPage(); +/* + * create an instance of the the medialist class on the stack + */ +void MainWin::createPagemedialist() +{ + QTreeWidgetItem *item=createPage("Media", m_topItem); + MediaList* medialist = new MediaList(stackedWidget, m_console); + hashInsert(item, medialist); + medialist->dockPage(); +} - treeWidget->expandItem(topItem); - stackedWidget->setCurrentWidget(m_console); +/* + * create an instance of the the joblist class on the stack + */ +void MainWin::createPagejoblist(QString &media) +{ + QTreeWidgetItem *item; + if (media == "") { + item=createPage("All Jobs", m_topItem); + } else { + QString desc("Jobs on "); + desc += media; + item=createPage(desc.toUtf8().data(), m_topItem); + } + JobList* joblist = new JobList(stackedWidget, m_console, media); + hashInsert(item, joblist); + joblist->dockPage(); + if (media != "") { + stackedWidget->setCurrentWidget(joblist); + treeWidget->setCurrentItem(item); + } } /* Create a root Tree Widget */ @@ -202,6 +232,7 @@ void MainWin::createConnections() connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked())); connect(actionUndock, SIGNAL(triggered()), this, SLOT(undockWindowButton())); connect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow())); + connect(actionClosePage, SIGNAL(triggered()), this, SLOT(closePage())); } /* @@ -213,8 +244,8 @@ void MainWin::closeEvent(QCloseEvent *event) m_console->writeSettings(); m_console->terminate(); event->accept(); - foreach(Pages *page, m_pagehash){ - if( !page->isDocked() ) + foreach(Pages *page, m_pagehash) { + if (!page->isDocked()) page->close(); } } @@ -246,11 +277,11 @@ void MainWin::readSettings() void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/) { /* Is this a page that has been inserted into the hash */ - if( getFromHash(item) ){ + if (getFromHash(item)) { Pages* page = getFromHash(item); int stackindex=stackedWidget->indexOf(page); - if( stackindex >= 0 ){ + if (stackindex >= 0) { stackedWidget->setCurrentWidget(page); } /* run the virtual function in case this class overrides it */ @@ -262,8 +293,12 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/) * This subroutine is called with an item in the Page Selection window * is double clicked */ -void MainWin::treeItemDoubleClicked(QTreeWidgetItem * /*item*/, int /*column*/) +/* This could be removed from here and from pages and from medialist + * Do you agree dhb */ +void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int /*column*/) { + Pages* page = getFromHash(item); + page->PgSeltreeWidgetDoubleClicked(); } /* @@ -273,24 +308,28 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre { /* The Previous item */ - if ( previousitem ){ + if (previousitem) { /* Is this a page that has been inserted into the hash */ - if( getFromHash(previousitem) ){ + if (getFromHash(previousitem)) { Pages* page = getFromHash(previousitem); treeWidget->removeAction(actionToggleDock); - foreach( QAction* pageaction, page->m_contextActions ){ + /* make sure the close window option is removed */ + if (page->isCloseable()) { + treeWidget->removeAction(actionClosePage); + } + foreach(QAction* pageaction, page->m_contextActions) { treeWidget->removeAction(pageaction); } } } /* Is this a page that has been inserted into the hash */ - if( getFromHash(currentitem) ){ + if (getFromHash(currentitem)) { Pages* page = getFromHash(currentitem); int stackindex = stackedWidget->indexOf(page); /* Is this page currently on the stack */ - if( stackindex >= 0 ){ + if (stackindex >= 0) { /* put this page on the top of the stack */ stackedWidget->setCurrentIndex(stackindex); } else { @@ -300,6 +339,10 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre setContextMenuDockText(page, currentitem); treeWidget->addAction(actionToggleDock); + /* if this page is closeable, then add that action */ + if (page->isCloseable()) { + treeWidget->addAction(actionClosePage); + } /* Add the actions to the Page Selectors tree widget that are part of the * current items list of desired actions regardless of whether on top of stack*/ @@ -393,10 +436,10 @@ void MainWin::toggleDockContextWindow() QTreeWidgetItem *currentitem = treeWidget->currentItem(); /* Is this a page that has been inserted into the hash */ - if( getFromHash(currentitem) ){ + if (getFromHash(currentitem)) { Pages* page = getFromHash(currentitem); page->togglePageDocking(); - if ( page->isDocked() ){ + if (page->isDocked()) { stackedWidget->setCurrentWidget(page); } /* Toggle the menu item. The window's dock status has been toggled */ @@ -416,7 +459,7 @@ void MainWin::setContextMenuDockText() QTreeWidgetItem *currentitem = treeWidget->currentItem(); /* Is this a page that has been inserted into the hash */ - if( getFromHash(currentitem) ){ + if (getFromHash(currentitem)) { Pages* page = getFromHash(currentitem); setContextMenuDockText(page, currentitem); } @@ -429,7 +472,7 @@ void MainWin::setContextMenuDockText() void MainWin::setContextMenuDockText(Pages* page, QTreeWidgetItem* item) { QString docktext(""); - if( page->isDocked() ){ + if (page->isDocked()) { docktext += "UnDock "; } else { docktext += "ReDock "; @@ -446,8 +489,8 @@ void MainWin::setContextMenuDockText(Pages* page, QTreeWidgetItem* item) */ void MainWin::setTreeWidgetItemDockColor(Pages* page, QTreeWidgetItem* item) { - if( item->text(0) != "Console" ){ - if( page->isDocked() ){ + if (item->text(0) != "Console") { + if (page->isDocked()) { /* Set the brush to blue if undocked */ QBrush blackBrush(Qt::black); item->setForeground(0, blackBrush); @@ -466,7 +509,7 @@ void MainWin::setTreeWidgetItemDockColor(Pages* page, QTreeWidgetItem* item) void MainWin::setTreeWidgetItemDockColor(Pages* page) { QTreeWidgetItem* item = getFromHash(page); - if( item ){ + if (item) { setTreeWidgetItemDockColor(page, item); } } @@ -493,6 +536,20 @@ void MainWin::hashInsert(QTreeWidgetItem *item, Pages *page) m_widgethash.insert(page, item); } +/* + * Function to simplify removal of QTreeWidgetItem <-> Page association + * into a double direction hash. + */ +void MainWin::hashRemove(QTreeWidgetItem *item, Pages *page) +{ + /* I had all sorts of return status checking code here. Do we have a log + * level capability in bat. I would have left it in but it used printf's + * and it should really be some kind of log level facility ??? + * ******FIXME********/ + m_pagehash.remove(item); + m_widgethash.remove(page); +} + /* * Function to retrieve a Page* when the item in the page selector's tree is * known. @@ -510,3 +567,21 @@ QTreeWidgetItem* MainWin::getFromHash(Pages *page) { return m_widgethash.value(page); } + +/* + * Function to respond to action on page selector context menu to close the + * current window. + */ +void MainWin::closePage() +{ + QTreeWidgetItem *currentitem = treeWidget->currentItem(); + + /* Is this a page that has been inserted into the hash */ + if (getFromHash(currentitem)) { + Pages* page = getFromHash(currentitem); + if (page->isCloseable()) { + page->closeStackPage(); + } + } +} + diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 97747b1c2e..d5fabe4294 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -45,6 +45,7 @@ #include "run/run.h" #include "restore/restore.h" #include "medialist/medialist.h" +#include "joblist/joblist.h" class Console; @@ -65,12 +66,15 @@ public: void setTreeWidgetItemDockColor(Pages *, QTreeWidgetItem *); void setTreeWidgetItemDockColor(Pages *); void hashInsert(QTreeWidgetItem *, Pages *); + void hashRemove(Pages *); + void hashRemove(QTreeWidgetItem *, Pages *); Pages* getFromHash(QTreeWidgetItem *); QTreeWidgetItem* getFromHash(Pages *); /* This hash is to get the page when the page selector widget is known */ QHash m_pagehash; /* This hash is to get the page selector widget when the page is known */ QHash m_widgethash; + void createPagejoblist(QString &); public slots: void input_line(); @@ -84,6 +88,7 @@ public slots: void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *); void stackItemChanged(int); void toggleDockContextWindow(); + void closePage(); protected: void closeEvent(QCloseEvent *event); @@ -94,6 +99,11 @@ private: void createPages(); QTreeWidgetItem *createTopPage(char *name ); QTreeWidgetItem *createPage(char *name, QTreeWidgetItem *parent ); + void createPagebrestore(); + void createPagemedialist(); + /* Temporarily putting this here until we figure out how to handle + * multiple directors. */ + QTreeWidgetItem *m_topItem; private: Console *m_console; diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index 663e34901c..73beb5d06a 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -52,6 +52,7 @@ MediaList::MediaList(QStackedWidget *parent, Console *console) createConnections(); m_populated = false; m_checkcurwidget = true; + m_closeable = false; } MediaList::~MediaList() @@ -164,8 +165,7 @@ void MediaList::editMedia() */ void MediaList::showJobs() { - JobList* joblist = new JobList(mp_console, m_currentlyselected); - joblist->show(); + mainWin->createPagejoblist(m_currentlyselected); } /* @@ -198,7 +198,7 @@ void MediaList::PgSeltreeWidgetDoubleClicked() */ void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *) /*previouswidgetitem*/ { - if ( m_checkcurwidget ) { + if (m_checkcurwidget) { int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt(); if (treedepth == 2){ mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); @@ -238,7 +238,11 @@ 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(actionRepopulateMediaTree); + /* 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 8a78a43f73..803efcb806 100644 --- a/bacula/src/qt-console/medialist/medialist.ui +++ b/bacula/src/qt-console/medialist/medialist.ui @@ -30,6 +30,9 @@ Repopulate Media Tree + + Requery the director for the media. + diff --git a/bacula/src/qt-console/pages.cpp b/bacula/src/qt-console/pages.cpp index 76eab6a205..53683dd836 100644 --- a/bacula/src/qt-console/pages.cpp +++ b/bacula/src/qt-console/pages.cpp @@ -88,15 +88,22 @@ void Pages::togglePageDocking() } /* - * This function is because I wanted for some reason to keep it private but still + * This function is because I wanted for some reason to keep it protected but still * give any subclasses the ability to find out if it is currently stacked or not. */ - bool Pages::isDocked() { return m_docked; } +/* + * To keep m_closeable protected as well + */ +bool Pages::isCloseable() +{ + return m_closeable; +} + /* * When a window is closed, this slot is called. The idea is to put it back in the * stack here, and it works. I wanted to get it to the top of the stack so that the @@ -111,7 +118,7 @@ void Pages::closeEvent(QCloseEvent* event) dockPage(); /* is the tree widget item for "this" the current widget item */ - if( mainWin->treeWidget->currentItem() == mainWin->getFromHash(this) ) + if (mainWin->treeWidget->currentItem() == mainWin->getFromHash(this)) /* in case the current widget is the one which represents this, lets set the context * menu to undock */ mainWin->setContextMenuDockText(); @@ -153,3 +160,19 @@ void Pages::PgSeltreeWidgetDoubleClicked() void Pages::currentStackItem() { } + +/* + * Function to close the stacked page and remove the widget from the + * Page selector window + */ +void Pages::closeStackPage() +{ + /* First get the tree widget item and destroy it */ + QTreeWidgetItem *item=mainWin->getFromHash(this); + /* remove the QTreeWidgetItem <-> page from the hash */ + mainWin->hashRemove(item, this); + /* remove the item from the page selector by destroying it */ + delete item; + /* remove this */ + delete this; +} diff --git a/bacula/src/qt-console/pages.h b/bacula/src/qt-console/pages.h index a1b3eb2995..7698344f8d 100644 --- a/bacula/src/qt-console/pages.h +++ b/bacula/src/qt-console/pages.h @@ -57,17 +57,20 @@ public: void undockPage(); void togglePageDocking(); bool isDocked(); + bool isCloseable(); QStackedWidget *m_parent; QList m_contextActions; virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); virtual void currentStackItem(); + void closeStackPage(); public slots: /* closeEvent is a virtual function inherited from QWidget */ virtual void closeEvent(QCloseEvent* event); -private: +protected: + bool m_closeable; bool m_docked; }; diff --git a/bacula/src/qt-console/restore/brestore.cpp b/bacula/src/qt-console/restore/brestore.cpp index 0e38dd69de..33678e35e5 100644 --- a/bacula/src/qt-console/restore/brestore.cpp +++ b/bacula/src/qt-console/restore/brestore.cpp @@ -41,6 +41,7 @@ bRestore::bRestore(QStackedWidget *parent) { m_parent = parent; + m_closeable = true; (void)parent; setupUi(this); } -- 2.39.5