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);
164 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
166 /* set a hold variable to the client name in case the context sensitive
168 m_currentlyselected=currentwidgetitem->text(0);
169 mp_treeWidget->addAction(actionListJobsofClient);
170 mp_treeWidget->addAction(actionStatusClientInConsole);
176 * Setup a context menu
177 * Made separate from populate so that it would not create context menu over and
178 * over as the tree is repopulated.
180 void Clients::createContextMenu()
182 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
183 mp_treeWidget->addAction(actionRefreshClients);
184 connect(mp_treeWidget, SIGNAL(
185 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
186 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
187 /* connect to the action specific to this pages class */
188 connect(actionRefreshClients, SIGNAL(triggered()), this,
189 SLOT(populateTree()));
190 connect(actionListJobsofClient, SIGNAL(triggered()), this,
192 connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
193 SLOT(consoleStatusClient()));
197 * Function responding to actionListJobsofClient which calls mainwin function
198 * to create a window of a list of jobs of this client.
200 void Clients::showJobs()
202 QString emptymedia("");
203 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
204 mainWin->createPageJobList(emptymedia, m_currentlyselected, parentItem);
208 * Function responding to actionListJobsofClient which calls mainwin function
209 * to create a window of a list of jobs of this client.
211 void Clients::consoleStatusClient()
213 QString cmd("status client=");
214 cmd += m_currentlyselected;
219 * Virtual function which is called when this page is visible on the stack
221 void Clients::currentStackItem()
225 /* add context sensitive menu items specific to this classto the page
226 * selector tree. m_contextActions is QList of QActions, so this is
227 * only done once with the first population. */
228 m_contextActions.append(actionRefreshClients);
229 /* Create the context menu for the client tree */