From e72538600e7a0dd4a07fa9066bb6eefa3645ef0c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 18 Apr 2007 19:45:32 +0000 Subject: [PATCH] First cut multiple consoles git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4568 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/clients/clients.cpp | 3 +- bacula/src/qt-console/mainwin.cpp | 115 ++++++++++-------- bacula/src/qt-console/mainwin.h | 20 +-- bacula/src/qt-console/medialist/medialist.cpp | 5 +- 4 files changed, 80 insertions(+), 63 deletions(-) diff --git a/bacula/src/qt-console/clients/clients.cpp b/bacula/src/qt-console/clients/clients.cpp index c7a5a1ef26..1fca13c053 100644 --- a/bacula/src/qt-console/clients/clients.cpp +++ b/bacula/src/qt-console/clients/clients.cpp @@ -188,7 +188,8 @@ void Clients::createContextMenu() void Clients::showJobs() { QString emptymedia(""); - mainWin->createPageJobList(emptymedia, m_currentlyselected); + mainWin->createPageJobList(emptymedia, m_currentlyselected, + mainWin->topItem(), mainWin->console()); } /* diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index a3fe6f26ab..4478d2c42d 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -64,54 +64,69 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) void MainWin::createPages() { DIRRES *dir; - QTreeWidgetItem *item; + QTreeWidgetItem *item, *topItem; + Console *console; - /* Create console tree stacked widget item */ - m_console = new Console(stackedWidget); - - /* Console is special -> needs director*/ - /* Just take the first Director */ LockRes(); - dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); - m_console->setDirRes(dir); + foreach_res(dir, R_DIRECTOR) { + + /* Create console tree stacked widget item */ + console = new Console(stackedWidget); + console->setDirRes(dir); + + /* The top tree item representing the director */ + topItem = createTopPage(dir->name()); + topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); + + /* Create Tree Widget Item */ + item = createPage("Console", topItem); + console->setTreeItem(item); + + /* insert the cosole and tree widget item into the hashes */ + hashInsert(item, console); + + /* Set Color of treeWidgetItem for the console + * It will be set to green in the console class if the connection is made. + */ + QBrush redBrush(Qt::red); + item->setForeground(0, redBrush); + console->dockPage(); + + /* create instances of the rest of the classes that will by default exist + * under each director */ + createPagebRestore(topItem, console); + createPageMediaList(topItem, console); + QString emptymedia(""), emptyclient(""); + createPageJobList(emptymedia, emptyclient, topItem, console); + createPageClients(topItem, console); + + treeWidget->expandItem(topItem); + stackedWidget->setCurrentWidget(console); + + /* + * Set the first console as current console + * + * ***FIXME**** note, to make this work correctly, we need a + * list of consoles, so that we can save/restore the settings + * for all consoles, and we need to figure out some way to + * set the current console and the current topItem (actually Director) + * when a page within a given console is clicked. We also need + * to redo the connections (signals/slots) that use m_console. + */ + if (!m_console) { + m_console = console; + m_topItem = topItem; + } + } UnlockRes(); - - /* The top tree item representing the director */ - m_topItem = createTopPage(dir->name()); - m_topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); - - /* Create Tree Widget Item */ - item = createPage("Console", m_topItem); - m_console->setTreeItem(item); - - /* insert the cosole and tree widget item into the hashes */ - hashInsert(item, m_console); - - /* Set Color of treeWidgetItem for the console - * It will be set to green in the console class if the connection is made. - */ - QBrush redBrush(Qt::red); - item->setForeground(0, redBrush); - m_console->dockPage(); - - /* create instances of the rest of the classes that will by default exist - * under each director */ - createPagebRestore(); - createPageMediaList(); - QString emptymedia(""), emptyclient(""); - createPageJobList(emptymedia, emptyclient); - createPageClients(); - - treeWidget->expandItem(m_topItem); - stackedWidget->setCurrentWidget(m_console); } /* * create an instance of the the brestore class on the stack */ -void MainWin::createPagebRestore() +void MainWin::createPagebRestore(QTreeWidgetItem *parent, Console * /*console*/) { - QTreeWidgetItem *item=createPage("brestore", m_topItem); + QTreeWidgetItem *item=createPage("brestore", parent); bRestore* brestore = new bRestore(stackedWidget); hashInsert(item, brestore); brestore->dockPage(); @@ -120,10 +135,10 @@ void MainWin::createPagebRestore() /* * create an instance of the the medialist class on the stack */ -void MainWin::createPageMediaList() +void MainWin::createPageMediaList(QTreeWidgetItem *parent, Console *console) { - QTreeWidgetItem *item=createPage("Media", m_topItem); - MediaList* medialist = new MediaList(stackedWidget, m_console); + QTreeWidgetItem *item=createPage("Media", parent); + MediaList* medialist = new MediaList(stackedWidget, console); hashInsert(item, medialist); medialist->dockPage(); } @@ -131,13 +146,14 @@ void MainWin::createPageMediaList() /* * create an instance of the the joblist class on the stack */ -void MainWin::createPageJobList(QString &media, QString &client) +void MainWin::createPageJobList(QString &media, QString &client, + QTreeWidgetItem *parent, Console *console) { QTreeWidgetItem *item, *holdItem; /* save current tree widget item in case query produces no results */ holdItem = treeWidget->currentItem(); if ((media == "") && (client == "")) { - item=createPage("All Jobs", m_topItem); + item = createPage("All Jobs", parent); } else { QString desc("Jobs "); if (media != "" ) { @@ -146,9 +162,9 @@ void MainWin::createPageJobList(QString &media, QString &client) if (client != "" ) { desc += "of Client " + client; } - item=createPage(desc.toUtf8().data(), m_topItem); + item = createPage(desc.toUtf8().data(), parent); } - JobList* joblist = new JobList(stackedWidget, m_console, media, client); + JobList* joblist = new JobList(stackedWidget, console, media, client); hashInsert(item, joblist); joblist->dockPage(); /* If this is a query of jobs on a specific media */ @@ -166,10 +182,10 @@ void MainWin::createPageJobList(QString &media, QString &client) /* * create an instance of the the Clients class on the stack */ -void MainWin::createPageClients() +void MainWin::createPageClients(QTreeWidgetItem *parent, Console *console) { - QTreeWidgetItem *item=createPage("Clients", m_topItem); - Clients* clients = new Clients(stackedWidget, m_console); + QTreeWidgetItem *item=createPage("Clients", parent); + Clients* clients = new Clients(stackedWidget, console); hashInsert(item, clients); clients->dockPage(); } @@ -608,4 +624,3 @@ void MainWin::closePage() } } } - diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 36fe8938a8..c0cabd3b07 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -25,7 +25,6 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ - /* * Version $Id$ * @@ -69,13 +68,16 @@ public: void hashInsert(QTreeWidgetItem *, Pages *); void hashRemove(Pages *); void hashRemove(QTreeWidgetItem *, Pages *); + QTreeWidgetItem *topItem() { return m_topItem; }; + Console *console() { return m_console; }; 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 &, QString &); + void createPageJobList(QString &, QString &, QTreeWidgetItem *parent, + Console *console); public slots: void input_line(); @@ -98,17 +100,15 @@ protected: private: void createConnections(); void createPages(); - QTreeWidgetItem *createTopPage(char *name ); - QTreeWidgetItem *createPage(char *name, QTreeWidgetItem *parent ); - void createPagebRestore(); - void createPageMediaList(); - void createPageClients(); - /* Temporarily putting this here until we figure out how to handle - * multiple directors. */ - QTreeWidgetItem *m_topItem; + QTreeWidgetItem *createTopPage(char *name); + QTreeWidgetItem *createPage(char *name, QTreeWidgetItem *parent); + void createPagebRestore(QTreeWidgetItem *parent, Console *console); + void createPageMediaList(QTreeWidgetItem *parent, Console *console); + void createPageClients(QTreeWidgetItem *parent, Console *console); private: Console *m_console; + QTreeWidgetItem *m_topItem; Pages *m_pagespophold; QStringList m_cmd_history; int m_cmd_last; diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index eecbb5d6d5..ce1a53830b 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -167,7 +167,8 @@ void MediaList::editMedia() void MediaList::showJobs() { QString emptyclient(""); - mainWin->createPageJobList(m_currentlyselected, emptyclient); + mainWin->createPageJobList(m_currentlyselected, emptyclient, + mainWin->topItem(), mainWin->console()); } /* @@ -176,7 +177,7 @@ void MediaList::showJobs() */ void MediaList::PgSeltreeWidgetClicked() { - if(!m_populated) { + if (!m_populated) { populateTree(); createContextMenu(); m_populated=true; -- 2.39.5