From: Dirk H Bartley Date: Mon, 16 Apr 2007 02:38:15 +0000 (+0000) Subject: dhb Added a clients page to the stack. Do some name changing to be more X-Git-Tag: Release-7.0.0~6566 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6c6e907bdfada83dbddc7e145ff78c50734542ff;p=bacula%2Fbacula dhb Added a clients page to the stack. Do some name changing to be more consistent. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4562 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/bat.pro b/bacula/src/qt-console/bat.pro index df4c673183..e91810d71b 100644 --- a/bacula/src/qt-console/bat.pro +++ b/bacula/src/qt-console/bat.pro @@ -24,6 +24,7 @@ FORMS += restore/restore.ui restore/prerestore.ui restore/brestore.ui FORMS += run/run.ui run/runcmd.ui FORMS += select/select.ui FORMS += medialist/medialist.ui mediaedit/mediaedit.ui joblist/joblist.ui +FORMS += clients/clients.ui HEADERS += mainwin.h bat.h bat_conf.h qstd.h SOURCES += main.cpp bat_conf.cpp mainwin.cpp qstd.cpp @@ -63,3 +64,7 @@ SOURCES += mediaedit/mediaedit.cpp ## JobList HEADERS += joblist/joblist.h SOURCES += joblist/joblist.cpp + +## Clients +HEADERS += clients/clients.h +SOURCES += clients/clients.cpp diff --git a/bacula/src/qt-console/clients/clients.cpp b/bacula/src/qt-console/clients/clients.cpp new file mode 100644 index 0000000000..af3b0614c3 --- /dev/null +++ b/bacula/src/qt-console/clients/clients.cpp @@ -0,0 +1,197 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation plus additions + that are listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ + +/* + * Version $Id: client.cpp 4230 2007-02-21 20:07:37Z kerns $ + * + * Clients Class + * + * Dirk Bartley, March 2007 + * + */ + +#include +#include +#include "bat.h" +#include "clients/clients.h" + +Clients::Clients(QStackedWidget *parent, Console *console) +{ + setupUi(this); + + /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */ + mp_console = console; + m_parent = parent; + m_populated = false; + m_checkcurwidget = true; + m_closeable = false; +} + +Clients::~Clients() +{ +} + +/* + * The main meat of the class!! The function that querries the director and + * creates the widgets with appropriate values. + */ +void Clients::populateTree() +{ + QTreeWidgetItem *clientItem, *topItem; + + m_checkcurwidget = false; + mp_treeWidget->clear(); + m_checkcurwidget = true; + + QStringList headerlist = (QStringList() << "Client Name" << "File Retention" + << "Job Retention" << "AutoPrune" << "ClientId" << "Uname" ); + + topItem = new QTreeWidgetItem(mp_treeWidget); + topItem->setText(0, "Clients"); + topItem->setData(0, Qt::UserRole, 0); + topItem->setExpanded(true); + + mp_treeWidget->setColumnCount(headerlist.count()); + mp_treeWidget->setHeaderLabels(headerlist); + /* This could be a log item */ + //printf("In Clients::populateTree()\n"); + + foreach(QString clientName, mp_console->client_list){ + clientItem = new QTreeWidgetItem(topItem); + clientItem->setText(0, clientName); + clientItem->setData(0, Qt::UserRole, 1); + clientItem->setExpanded(true); + + /* Set up query QString and header QStringList */ + QString query(""); + query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname" + " FROM client" + " WHERE "; + query += " Name='" + clientName + "'"; + query += " ORDER BY Name"; + + QStringList results; + /* This could be a log item */ + //printf("Clients query cmd : %s\n",query.toUtf8().data()); + if (mp_console->sql_cmd(query, results)) { + int resultCount = results.count(); + if (resultCount == 1){ + QString resultline; + QString field; + QStringList fieldlist; + /* there will only be one of these */ + 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 */ + clientItem->setData(index+1, Qt::UserRole, 1); + /* Put media fields under the pool tree item */ + clientItem->setData(index+1, Qt::UserRole, 1); + clientItem->setText(index+1, field); + index++; + } + } + } + } + } +} + +/* + * When the treeWidgetItem in the page selector tree is singleclicked, Make sure + * The tree has been populated. + */ +void Clients::PgSeltreeWidgetClicked() +{ + if(!m_populated) { + populateTree(); + createContextMenu(); + m_populated=true; + } +} + +/* + * Added to set the context menu policy based on currently active treeWidgetItem + * signaled by currentItemChanged + */ +void Clients::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 == 1){ +// mp_treeWidget->removeAction(actionEditVolume); + } + } + + int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt(); + if (treedepth == 1){ + /* set a hold variable to the client name in case the context sensitive + * menu is used */ + m_currentlyselected=currentwidgetitem->text(1); +// mp_treeWidget->addAction(actionEditVolume); + } + } +} + +/* + * 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 Clients::createContextMenu() +{ + mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); + mp_treeWidget->addAction(actionRefreshClients); + connect(mp_treeWidget, SIGNAL( + currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), + this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); + /* connect to the action specific to this pages class */ + connect(actionRefreshClients, SIGNAL(triggered()), this, + SLOT(populateTree())); +} + +/* + * Virtual function which is called when this page is visible on the stack + */ +void Clients::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(actionRefreshClients); + /* Create the context menu for the client tree */ + createContextMenu(); + m_populated=true; + } +} diff --git a/bacula/src/qt-console/clients/clients.h b/bacula/src/qt-console/clients/clients.h new file mode 100644 index 0000000000..4e03ad4b52 --- /dev/null +++ b/bacula/src/qt-console/clients/clients.h @@ -0,0 +1,68 @@ +#ifndef _CLIENTS_H_g +#define _CLIENTS_H_g +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation plus additions + that are listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Version $Id: clients.h 4230 2007-02-21 20:07:37Z kerns $ + * + * Dirk Bartley, March 2007 + */ + +#include +#include "ui_clients.h" +#include "console.h" +#include "pages.h" +//#include + +class Clients : public Pages, public Ui::ClientForm +{ + Q_OBJECT + +public: + Clients(QStackedWidget *parent, Console *console); + ~Clients(); + virtual void PgSeltreeWidgetClicked(); + virtual void currentStackItem(); + +public slots: + void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *); + +private slots: + void populateTree(); + +private: + void createContextMenu(); + +private: + Console *mp_console; + QString m_currentlyselected; + bool m_populated; + bool m_checkcurwidget; +}; + +#endif /* _CLIENTS_H_g */ diff --git a/bacula/src/qt-console/clients/clients.ui b/bacula/src/qt-console/clients/clients.ui new file mode 100644 index 0000000000..3ae91719d5 --- /dev/null +++ b/bacula/src/qt-console/clients/clients.ui @@ -0,0 +1,40 @@ + + ClientForm + + + + 0 + 0 + 763 + 650 + + + + Client Tree + + + + 9 + + + 6 + + + + + + + + ../images/run.png + + + Refresh Client List + + + Requery the director for the list of clients. + + + + + + diff --git a/bacula/src/qt-console/joblist/joblist.cpp b/bacula/src/qt-console/joblist/joblist.cpp index 46f0983bd8..dd09f5a37b 100644 --- a/bacula/src/qt-console/joblist/joblist.cpp +++ b/bacula/src/qt-console/joblist/joblist.cpp @@ -51,7 +51,7 @@ JobList::JobList(QStackedWidget *parent, Console *console, QString &medianame) m_populated = false; m_closeable = false; /* connect to the action specific to this pages class */ - connect(actionRepopulateJobList, SIGNAL(triggered()), this, + connect(actionRefreshJobList, SIGNAL(triggered()), this, SLOT(populateTable())); } @@ -138,7 +138,7 @@ void JobList::currentStackItem() { if (!m_populated) { populateTable(); - m_contextActions.append(actionRepopulateJobList); + m_contextActions.append(actionRefreshJobList); m_populated=true; } } diff --git a/bacula/src/qt-console/joblist/joblist.ui b/bacula/src/qt-console/joblist/joblist.ui index dd1e01dab4..872e241ad7 100644 --- a/bacula/src/qt-console/joblist/joblist.ui +++ b/bacula/src/qt-console/joblist/joblist.ui @@ -23,12 +23,12 @@ - + ../images/run.png - Repopulate Job List + Refresh Job List Requery the director for the list of jobs. diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 09192ab621..f2f8e914f7 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -96,10 +96,11 @@ void MainWin::createPages() /* create instances of the rest of the classes that will by default exist * under each director */ - createPagebrestore(); - createPagemedialist(); + createPagebRestore(); + createPageMediaList(); QString emptymedia(""); - createPagejoblist(emptymedia); + createPageJobList(emptymedia); + createPageClients(); treeWidget->expandItem(m_topItem); stackedWidget->setCurrentWidget(m_console); @@ -108,7 +109,7 @@ void MainWin::createPages() /* * create an instance of the the brestore class on the stack */ -void MainWin::createPagebrestore() +void MainWin::createPagebRestore() { QTreeWidgetItem *item=createPage("brestore", m_topItem); bRestore* brestore = new bRestore(stackedWidget); @@ -119,7 +120,7 @@ void MainWin::createPagebrestore() /* * create an instance of the the medialist class on the stack */ -void MainWin::createPagemedialist() +void MainWin::createPageMediaList() { QTreeWidgetItem *item=createPage("Media", m_topItem); MediaList* medialist = new MediaList(stackedWidget, m_console); @@ -130,7 +131,7 @@ void MainWin::createPagemedialist() /* * create an instance of the the joblist class on the stack */ -void MainWin::createPagejoblist(QString &media) +void MainWin::createPageJobList(QString &media) { QTreeWidgetItem *item, *holdItem; /* save current tree widget item in case query produces no results */ @@ -157,6 +158,18 @@ void MainWin::createPagejoblist(QString &media) } } +/* + * create an instance of the the Clients class on the stack + */ +void MainWin::createPageClients() +{ + QTreeWidgetItem *item=createPage("Clients", m_topItem); + Clients* clients = new Clients(stackedWidget, m_console); + hashInsert(item, clients); + clients->dockPage(); +} + + /* Create a root Tree Widget */ QTreeWidgetItem *MainWin::createTopPage(char *name) { diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index d5fabe4294..c9054dda95 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -46,6 +46,7 @@ #include "restore/restore.h" #include "medialist/medialist.h" #include "joblist/joblist.h" +#include "clients/clients.h" class Console; @@ -74,7 +75,7 @@ public: QHash m_pagehash; /* This hash is to get the page selector widget when the page is known */ QHash m_widgethash; - void createPagejoblist(QString &); + void createPageJobList(QString &); public slots: void input_line(); @@ -99,8 +100,9 @@ private: void createPages(); QTreeWidgetItem *createTopPage(char *name ); QTreeWidgetItem *createPage(char *name, QTreeWidgetItem *parent ); - void createPagebrestore(); - void createPagemedialist(); + void createPagebRestore(); + void createPageMediaList(); + void createPageClients(); /* Temporarily putting this here until we figure out how to handle * multiple directors. */ QTreeWidgetItem *m_topItem; diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index 0ef2205658..056082e3b4 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -166,7 +166,7 @@ void MediaList::editMedia() */ void MediaList::showJobs() { - mainWin->createPagejoblist(m_currentlyselected); + mainWin->createPageJobList(m_currentlyselected); } /* diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index fb4e2c94e4..d28b3560e3 100644 --- a/bacula/src/qt-console/medialist/medialist.h +++ b/bacula/src/qt-console/medialist/medialist.h @@ -30,7 +30,7 @@ /* * Version $Id: medialist.h 4230 2007-02-21 20:07:37Z kerns $ * - * Dirk Bentley, March 2007 + * Dirk Bartley, March 2007 */ #include