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 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */
51 m_checkcurwidget = true;
61 * The main meat of the class!! The function that querries the director and
62 * creates the widgets with appropriate values.
64 void Clients::populateTree()
66 QTreeWidgetItem *clientItem, *topItem;
68 m_checkcurwidget = false;
69 mp_treeWidget->clear();
70 m_checkcurwidget = true;
72 QStringList headerlist = (QStringList() << "Client Name" << "File Retention"
73 << "Job Retention" << "AutoPrune" << "ClientId" << "Uname" );
75 topItem = new QTreeWidgetItem(mp_treeWidget);
76 topItem->setText(0, "Clients");
77 topItem->setData(0, Qt::UserRole, 0);
78 topItem->setExpanded(true);
80 mp_treeWidget->setColumnCount(headerlist.count());
81 mp_treeWidget->setHeaderLabels(headerlist);
82 /* This could be a log item */
83 //printf("In Clients::populateTree()\n");
85 foreach(QString clientName, m_console->client_list){
86 clientItem = new QTreeWidgetItem(topItem);
87 clientItem->setText(0, clientName);
88 clientItem->setData(0, Qt::UserRole, 1);
89 clientItem->setExpanded(true);
91 /* Set up query QString and header QStringList */
93 query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname"
96 query += " Name='" + clientName + "'";
97 query += " ORDER BY Name";
100 /* This could be a log item */
101 //printf("Clients query cmd : %s\n",query.toUtf8().data());
102 if (m_console->sql_cmd(query, results)) {
103 int resultCount = results.count();
104 if (resultCount == 1){
107 QStringList fieldlist;
108 /* there will only be one of these */
109 foreach (resultline, results) {
110 fieldlist = resultline.split("\t");
112 /* Iterate through fields in the record */
113 foreach (field, fieldlist) {
114 field = field.trimmed(); /* strip leading & trailing spaces */
115 clientItem->setData(index+1, Qt::UserRole, 1);
116 /* Put media fields under the pool tree item */
117 clientItem->setData(index+1, Qt::UserRole, 1);
118 clientItem->setText(index+1, field);
128 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
129 * The tree has been populated.
131 void Clients::PgSeltreeWidgetClicked()
141 * Added to set the context menu policy based on currently active treeWidgetItem
142 * signaled by currentItemChanged
144 void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
146 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
147 if (m_checkcurwidget) {
148 /* The Previous item */
149 if (previouswidgetitem) { /* avoid a segfault if first time */
150 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
152 mp_treeWidget->removeAction(actionListJobsofClient);
153 mp_treeWidget->removeAction(actionStatusClientInConsole);
157 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
159 /* set a hold variable to the client name in case the context sensitive
161 m_currentlyselected=currentwidgetitem->text(0);
162 mp_treeWidget->addAction(actionListJobsofClient);
163 mp_treeWidget->addAction(actionStatusClientInConsole);
169 * Setup a context menu
170 * Made separate from populate so that it would not create context menu over and
171 * over as the tree is repopulated.
173 void Clients::createContextMenu()
175 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
176 mp_treeWidget->addAction(actionRefreshClients);
177 connect(mp_treeWidget, SIGNAL(
178 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
179 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
180 /* connect to the action specific to this pages class */
181 connect(actionRefreshClients, SIGNAL(triggered()), this,
182 SLOT(populateTree()));
183 connect(actionListJobsofClient, SIGNAL(triggered()), this,
185 connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
186 SLOT(consoleStatusClient()));
190 * Function responding to actionListJobsofClient which calls mainwin function
191 * to create a window of a list of jobs of this client.
193 void Clients::showJobs()
195 QString emptymedia("");
196 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
197 mainWin->createPageJobList(emptymedia, m_currentlyselected, parentItem);
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::consoleStatusClient()
206 QString cmd("status client=");
207 cmd += m_currentlyselected += "\n";
212 * Virtual function which is called when this page is visible on the stack
214 void Clients::currentStackItem()
218 /* add context sensitive menu items specific to this classto the page
219 * selector tree. m_m_contextActions is QList of QActions, so this is
220 * only done once with the first population. */
221 m_contextActions.append(actionRefreshClients);
222 /* Create the context menu for the client tree */