2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2007 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 plus additions
11 that are listed in the file LICENSE.
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.
30 * Version $Id: client.cpp 4230 2007-02-21 20:07:37Z kerns $
34 * Dirk Bartley, March 2007
38 #include <QAbstractEventDispatcher>
41 #include "clients/clients.h"
49 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
50 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/network-server.png")));
52 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */
54 m_checkcurwidget = true;
56 /* add context sensitive menu items specific to this classto the page
57 * selector tree. m_contextActions is QList of QActions */
58 m_contextActions.append(actionRefreshClients);
66 * The main meat of the class!! The function that querries the director and
67 * creates the widgets with appropriate values.
69 void Clients::populateTree()
71 QTreeWidgetItem *clientItem, *topItem;
73 if (!m_console->preventInUseConnect())
75 m_checkcurwidget = false;
76 mp_treeWidget->clear();
77 m_checkcurwidget = true;
79 QStringList headerlist = (QStringList() << "Client Name" << "File Retention"
80 << "Job Retention" << "AutoPrune" << "ClientId" << "Uname" );
82 topItem = new QTreeWidgetItem(mp_treeWidget);
83 topItem->setText(0, "Clients");
84 topItem->setData(0, Qt::UserRole, 0);
85 topItem->setExpanded(true);
87 mp_treeWidget->setColumnCount(headerlist.count());
88 mp_treeWidget->setHeaderLabels(headerlist);
90 foreach (QString clientName, m_console->client_list){
91 clientItem = new QTreeWidgetItem(topItem);
92 clientItem->setText(0, clientName);
93 clientItem->setData(0, Qt::UserRole, 1);
94 clientItem->setExpanded(true);
96 /* Set up query QString and header QStringList */
98 query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname"
101 query += " Name='" + clientName + "'";
102 query += " ORDER BY Name";
105 /* This could be a log item */
106 if (mainWin->m_sqlDebug) {
107 Pmsg1(000, "Clients query cmd : %s\n",query.toUtf8().data());
109 if (m_console->sql_cmd(query, results)) {
110 int resultCount = results.count();
111 if (resultCount == 1){
114 QStringList fieldlist;
115 /* there will only be one of these */
116 foreach (resultline, results) {
117 fieldlist = resultline.split("\t");
119 /* Iterate through fields in the record */
120 foreach (field, fieldlist) {
121 field = field.trimmed(); /* strip leading & trailing spaces */
122 clientItem->setData(index+1, Qt::UserRole, 1);
123 /* Put media fields under the pool tree item */
124 clientItem->setData(index+1, Qt::UserRole, 1);
125 clientItem->setText(index+1, field);
132 /* Resize the columns */
133 for(int cnter=0; cnter<headerlist.size(); cnter++) {
134 mp_treeWidget->resizeColumnToContents(cnter);
139 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
140 * The tree has been populated.
142 void Clients::PgSeltreeWidgetClicked()
152 * Added to set the context menu policy based on currently active treeWidgetItem
153 * signaled by currentItemChanged
155 void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
157 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
158 if (m_checkcurwidget) {
159 /* The Previous item */
160 if (previouswidgetitem) { /* avoid a segfault if first time */
161 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
163 mp_treeWidget->removeAction(actionListJobsofClient);
164 mp_treeWidget->removeAction(actionStatusClientInConsole);
165 mp_treeWidget->removeAction(actionPurgeJobs);
166 mp_treeWidget->removeAction(actionPrune);
170 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
172 /* set a hold variable to the client name in case the context sensitive
174 m_currentlyselected=currentwidgetitem->text(0);
175 mp_treeWidget->addAction(actionListJobsofClient);
176 mp_treeWidget->addAction(actionStatusClientInConsole);
177 mp_treeWidget->addAction(actionPurgeJobs);
178 mp_treeWidget->addAction(actionPrune);
184 * Setup a context menu
185 * Made separate from populate so that it would not create context menu over and
186 * over as the tree is repopulated.
188 void Clients::createContextMenu()
190 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
191 mp_treeWidget->addAction(actionRefreshClients);
192 connect(mp_treeWidget, SIGNAL(
193 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
194 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
195 /* connect to the action specific to this pages class */
196 connect(actionRefreshClients, SIGNAL(triggered()), this,
197 SLOT(populateTree()));
198 connect(actionListJobsofClient, SIGNAL(triggered()), this,
200 connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
201 SLOT(consoleStatusClient()));
202 connect(actionPurgeJobs, SIGNAL(triggered()), this,
203 SLOT(consolePurgeJobs()));
204 connect(actionPrune, SIGNAL(triggered()), this,
209 * Function responding to actionListJobsofClient which calls mainwin function
210 * to create a window of a list of jobs of this client.
212 void Clients::showJobs()
214 QString emptymedia("");
215 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
216 mainWin->createPageJobList(emptymedia, m_currentlyselected, parentItem);
220 * Function responding to actionListJobsofClient which calls mainwin function
221 * to create a window of a list of jobs of this client.
223 void Clients::consoleStatusClient()
225 QString cmd("status client=");
226 cmd += m_currentlyselected;
231 * Virtual function which is called when this page is visible on the stack
233 void Clients::currentStackItem()
237 /* Create the context menu for the client tree */
244 * Function responding to actionPurgeJobs
246 void Clients::consolePurgeJobs()
248 if (QMessageBox::warning(this, tr("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);