2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
34 * Dirk Bartley, March 2007
38 #include <QAbstractEventDispatcher>
41 #include "clients/clients.h"
43 #include "status/clientstat.h"
48 m_name = tr("Clients");
50 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
51 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/network-server.png")));
53 /* tableWidget, Storage Tree Tree Widget inherited from ui_client.h */
55 m_checkcurwidget = true;
57 /* add context sensitive menu items specific to this classto the page
58 * selector tree. m_contextActions is QList of QActions */
59 m_contextActions.append(actionRefreshClients);
69 * The main meat of the class!! The function that querries the director and
70 * creates the widgets with appropriate values.
72 void Clients::populateTable()
74 QTableWidgetItem *tableItem;
75 QBrush blackBrush(Qt::black);
77 if (!m_console->preventInUseConnect())
79 m_checkcurwidget = false;
81 m_checkcurwidget = true;
83 QStringList headerlist = (QStringList() << tr("Client Name") << tr("File Retention")
84 << tr("Job Retention") << tr("AutoPrune") << tr("ClientId") << tr("Uname") );
86 tableWidget->setColumnCount(headerlist.count());
87 tableWidget->setHorizontalHeaderLabels(headerlist);
88 tableWidget->setRowCount(m_console->client_list.count());
89 tableWidget->verticalHeader()->hide();
92 foreach (QString clientName, m_console->client_list){
93 /* Set up query QString and header QStringList */
95 query += "SELECT Name, FileRetention, JobRetention, AutoPrune, ClientId, Uname"
98 query += " Name='" + clientName + "'";
99 query += " ORDER BY ClientId LIMIT 1";
102 /* This could be a log item */
103 if (mainWin->m_sqlDebug) {
104 Pmsg1(000, "Clients query cmd : %s\n",query.toUtf8().data());
106 if (m_console->sql_cmd(query, results)) {
107 int resultCount = results.count();
111 QStringList fieldlist;
112 resultline = results[resultCount - 1];
113 fieldlist = resultline.split("\t");
116 /* Iterate through fields in the record */
117 foreach (field, fieldlist) {
118 field = field.trimmed(); /* strip leading & trailing spaces */
119 tableItem = new QTableWidgetItem(field, 1);
120 tableItem->setFlags(Qt::ItemIsSelectable);
121 tableItem->setForeground(blackBrush);
122 tableItem->setData(Qt::UserRole, 1);
123 tableWidget->setItem(row, column, tableItem);
130 /* Resize the columns */
131 for(int cnter=0; cnter<headerlist.size(); cnter++) {
132 tableWidget->resizeColumnToContents(cnter);
137 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
138 * The tree has been populated.
140 void Clients::PgSeltreeWidgetClicked()
149 * Added to set the context menu policy based on currently active treeWidgetItem
150 * signaled by currentItemChanged
152 void Clients::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem )
154 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
155 if (m_checkcurwidget) {
156 int currentRow = currentwidgetitem->row();
157 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
158 m_currentlyselected = currentrowzeroitem->text();
160 /* The Previous item */
161 if (previouswidgetitem) { /* avoid a segfault if first time */
162 tableWidget->removeAction(actionListJobsofClient);
163 tableWidget->removeAction(actionStatusClientInConsole);
164 tableWidget->removeAction(actionStatusClientWindow);
165 tableWidget->removeAction(actionPurgeJobs);
166 tableWidget->removeAction(actionPrune);
169 if (m_currentlyselected.length() != 0) {
170 /* set a hold variable to the client name in case the context sensitive
172 tableWidget->addAction(actionListJobsofClient);
173 tableWidget->addAction(actionStatusClientInConsole);
174 tableWidget->addAction(actionStatusClientWindow);
175 tableWidget->addAction(actionPurgeJobs);
176 tableWidget->addAction(actionPrune);
182 * Setup a context menu
183 * Made separate from populate so that it would not create context menu over and
184 * over as the tree is repopulated.
186 void Clients::createContextMenu()
188 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
189 tableWidget->addAction(actionRefreshClients);
190 /* for the tableItemChanged to maintain m_currentJob */
191 connect(tableWidget, SIGNAL(
192 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
193 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
195 /* connect to the action specific to this pages class */
196 connect(actionRefreshClients, SIGNAL(triggered()), this,
197 SLOT(populateTable()));
198 connect(actionListJobsofClient, SIGNAL(triggered()), this,
200 connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
201 SLOT(consoleStatusClient()));
202 connect(actionStatusClientWindow, SIGNAL(triggered()), this,
203 SLOT(statusClientWindow()));
204 connect(actionPurgeJobs, SIGNAL(triggered()), this,
205 SLOT(consolePurgeJobs()));
206 connect(actionPrune, SIGNAL(triggered()), this,
211 * Function responding to actionListJobsofClient which calls mainwin function
212 * to create a window of a list of jobs of this client.
214 void Clients::showJobs()
216 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
217 mainWin->createPageJobList("", m_currentlyselected, "", "", parentItem);
221 * Function responding to actionListJobsofClient which calls mainwin function
222 * to create a window of a list of jobs of this client.
224 void Clients::consoleStatusClient()
226 QString cmd("status client=");
227 cmd += m_currentlyselected;
232 * Virtual function which is called when this page is visible on the stack
234 void Clients::currentStackItem()
238 /* Create the context menu for the client table */
244 * Function responding to actionPurgeJobs
246 void Clients::consolePurgeJobs()
248 if (QMessageBox::warning(this, "Bat",
249 tr("Are you sure you want to purge ?? !!!.\n"
250 "The Purge command will delete associated Catalog database records from Jobs and"
251 " Volumes without considering the retention period. Purge works only on the"
252 " Catalog database and does not affect data written to Volumes. This command can"
253 " be dangerous because you can delete catalog records associated with current"
254 " backups of files, and we recommend that you do not use it unless you know what"
255 " you are doing.\n\n"
256 " Is there any way I can get you to click Cancel here? You really don't want to do"
258 "Press OK to proceed with the purge operation?"),
259 QMessageBox::Ok | QMessageBox::Cancel)
260 == QMessageBox::Cancel) { return; }
262 QString cmd("purge jobs client=");
263 cmd += m_currentlyselected;
268 * Function responding to actionPrune
270 void Clients::prune()
272 new prunePage("", m_currentlyselected);
276 * Function responding to action to create new client status window
278 void Clients::statusClientWindow()
280 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
281 new ClientStat(m_currentlyselected, parentItem);