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"
48 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/network-server.png")));
51 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */
53 m_checkcurwidget = true;
62 * The main meat of the class!! The function that querries the director and
63 * creates the widgets with appropriate values.
65 void Clients::populateTree()
67 QTreeWidgetItem *clientItem, *topItem;
69 if (!m_console->preventInUseConnect())
71 m_checkcurwidget = false;
72 mp_treeWidget->clear();
73 m_checkcurwidget = true;
75 QStringList headerlist = (QStringList() << "Client Name" << "File Retention"
76 << "Job Retention" << "AutoPrune" << "ClientId" << "Uname" );
78 topItem = new QTreeWidgetItem(mp_treeWidget);
79 topItem->setText(0, "Clients");
80 topItem->setData(0, Qt::UserRole, 0);
81 topItem->setExpanded(true);
83 mp_treeWidget->setColumnCount(headerlist.count());
84 mp_treeWidget->setHeaderLabels(headerlist);
86 foreach (QString clientName, m_console->client_list){
87 clientItem = new QTreeWidgetItem(topItem);
88 clientItem->setText(0, clientName);
89 clientItem->setData(0, Qt::UserRole, 1);
90 clientItem->setExpanded(true);
92 /* Set up query QString and header QStringList */
94 query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname"
97 query += " Name='" + clientName + "'";
98 query += " ORDER BY Name";
101 /* This could be a log item */
102 if (mainWin->m_sqlDebug) {
103 Pmsg1(000, "Clients query cmd : %s\n",query.toUtf8().data());
105 if (m_console->sql_cmd(query, results)) {
106 int resultCount = results.count();
107 if (resultCount == 1){
110 QStringList fieldlist;
111 /* there will only be one of these */
112 foreach (resultline, results) {
113 fieldlist = resultline.split("\t");
115 /* Iterate through fields in the record */
116 foreach (field, fieldlist) {
117 field = field.trimmed(); /* strip leading & trailing spaces */
118 clientItem->setData(index+1, Qt::UserRole, 1);
119 /* Put media fields under the pool tree item */
120 clientItem->setData(index+1, Qt::UserRole, 1);
121 clientItem->setText(index+1, field);
128 /* Resize the columns */
129 for(int cnter=0; cnter<headerlist.size(); cnter++) {
130 mp_treeWidget->resizeColumnToContents(cnter);
135 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
136 * The tree has been populated.
138 void Clients::PgSeltreeWidgetClicked()
148 * Added to set the context menu policy based on currently active treeWidgetItem
149 * signaled by currentItemChanged
151 void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
153 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
154 if (m_checkcurwidget) {
155 /* The Previous item */
156 if (previouswidgetitem) { /* avoid a segfault if first time */
157 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
159 mp_treeWidget->removeAction(actionListJobsofClient);
160 mp_treeWidget->removeAction(actionStatusClientInConsole);
161 mp_treeWidget->removeAction(actionPurgeJobs);
165 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
167 /* set a hold variable to the client name in case the context sensitive
169 m_currentlyselected=currentwidgetitem->text(0);
170 mp_treeWidget->addAction(actionListJobsofClient);
171 mp_treeWidget->addAction(actionStatusClientInConsole);
172 mp_treeWidget->addAction(actionPurgeJobs);
178 * Setup a context menu
179 * Made separate from populate so that it would not create context menu over and
180 * over as the tree is repopulated.
182 void Clients::createContextMenu()
184 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
185 mp_treeWidget->addAction(actionRefreshClients);
186 connect(mp_treeWidget, SIGNAL(
187 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
188 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
189 /* connect to the action specific to this pages class */
190 connect(actionRefreshClients, SIGNAL(triggered()), this,
191 SLOT(populateTree()));
192 connect(actionListJobsofClient, SIGNAL(triggered()), this,
194 connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
195 SLOT(consoleStatusClient()));
196 connect(actionPurgeJobs, SIGNAL(triggered()), this,
197 SLOT(consolePurgeJobs()));
201 * Function responding to actionListJobsofClient which calls mainwin function
202 * to create a window of a list of jobs of this client.
204 void Clients::showJobs()
206 QString emptymedia("");
207 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
208 mainWin->createPageJobList(emptymedia, m_currentlyselected, parentItem);
212 * Function responding to actionListJobsofClient which calls mainwin function
213 * to create a window of a list of jobs of this client.
215 void Clients::consoleStatusClient()
217 QString cmd("status client=");
218 cmd += m_currentlyselected;
223 * Virtual function which is called when this page is visible on the stack
225 void Clients::currentStackItem()
229 /* add context sensitive menu items specific to this classto the page
230 * selector tree. m_contextActions is QList of QActions, so this is
231 * only done once with the first population. */
232 m_contextActions.append(actionRefreshClients);
233 /* Create the context menu for the client tree */
240 * Function responding to actionPurgeJobs
242 void Clients::consolePurgeJobs()
244 if (QMessageBox::warning(this, tr("Bat"),
245 tr("Are you sure you want to purge ?? !!!.\n"
246 "The Purge command will delete associated Catalog database records from Jobs and"
247 " Volumes without considering the retention period. Purge works only on the"
248 " Catalog database and does not affect data written to Volumes. This command can"
249 " be dangerous because you can delete catalog records associated with current"
250 " backups of files, and we recommend that you do not use it unless you know what"
251 " you are doing.\n\n"
252 " Is there any way I can get you to Click cancel here. You really don't want to do"
254 "Press OK to proceed with the purge operation?"),
255 QMessageBox::Ok | QMessageBox::Cancel)
256 == QMessageBox::Cancel) { return; }
258 QString cmd("purge jobs client=");
259 cmd += m_currentlyselected;