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 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */
50 m_checkcurwidget = true;
59 * The main meat of the class!! The function that querries the director and
60 * creates the widgets with appropriate values.
62 void Clients::populateTree()
64 QTreeWidgetItem *clientItem, *topItem;
66 m_checkcurwidget = false;
67 mp_treeWidget->clear();
68 m_checkcurwidget = true;
70 QStringList headerlist = (QStringList() << "Client Name" << "File Retention"
71 << "Job Retention" << "AutoPrune" << "ClientId" << "Uname" );
73 topItem = new QTreeWidgetItem(mp_treeWidget);
74 topItem->setText(0, "Clients");
75 topItem->setData(0, Qt::UserRole, 0);
76 topItem->setExpanded(true);
78 mp_treeWidget->setColumnCount(headerlist.count());
79 mp_treeWidget->setHeaderLabels(headerlist);
80 /* This could be a log item */
81 //printf("In Clients::populateTree()\n");
83 foreach(QString clientName, m_console->client_list){
84 clientItem = new QTreeWidgetItem(topItem);
85 clientItem->setText(0, clientName);
86 clientItem->setData(0, Qt::UserRole, 1);
87 clientItem->setExpanded(true);
89 /* Set up query QString and header QStringList */
91 query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname"
94 query += " Name='" + clientName + "'";
95 query += " ORDER BY Name";
98 /* This could be a log item */
99 //printf("Clients query cmd : %s\n",query.toUtf8().data());
100 if (m_console->sql_cmd(query, results)) {
101 int resultCount = results.count();
102 if (resultCount == 1){
105 QStringList fieldlist;
106 /* there will only be one of these */
107 foreach (resultline, results) {
108 fieldlist = resultline.split("\t");
110 /* Iterate through fields in the record */
111 foreach (field, fieldlist) {
112 field = field.trimmed(); /* strip leading & trailing spaces */
113 clientItem->setData(index+1, Qt::UserRole, 1);
114 /* Put media fields under the pool tree item */
115 clientItem->setData(index+1, Qt::UserRole, 1);
116 clientItem->setText(index+1, field);
126 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
127 * The tree has been populated.
129 void Clients::PgSeltreeWidgetClicked()
139 * Added to set the context menu policy based on currently active treeWidgetItem
140 * signaled by currentItemChanged
142 void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
144 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
145 if (m_checkcurwidget) {
146 /* The Previous item */
147 if (previouswidgetitem) { /* avoid a segfault if first time */
148 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
150 mp_treeWidget->removeAction(actionListJobsofClient);
151 mp_treeWidget->removeAction(actionStatusClientInConsole);
155 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
157 /* set a hold variable to the client name in case the context sensitive
159 m_currentlyselected=currentwidgetitem->text(0);
160 mp_treeWidget->addAction(actionListJobsofClient);
161 mp_treeWidget->addAction(actionStatusClientInConsole);
167 * Setup a context menu
168 * Made separate from populate so that it would not create context menu over and
169 * over as the tree is repopulated.
171 void Clients::createContextMenu()
173 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
174 mp_treeWidget->addAction(actionRefreshClients);
175 connect(mp_treeWidget, SIGNAL(
176 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
177 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
178 /* connect to the action specific to this pages class */
179 connect(actionRefreshClients, SIGNAL(triggered()), this,
180 SLOT(populateTree()));
181 connect(actionListJobsofClient, SIGNAL(triggered()), this,
183 connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
184 SLOT(consoleStatusClient()));
188 * Function responding to actionListJobsofClient which calls mainwin function
189 * to create a window of a list of jobs of this client.
191 void Clients::showJobs()
193 QString emptymedia("");
194 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
195 mainWin->createPageJobList(emptymedia, m_currentlyselected, parentItem);
199 * Function responding to actionListJobsofClient which calls mainwin function
200 * to create a window of a list of jobs of this client.
202 void Clients::consoleStatusClient()
204 QString cmd("status client=");
205 cmd += m_currentlyselected += "\n";
210 * Virtual function which is called when this page is visible on the stack
212 void Clients::currentStackItem()
216 /* add context sensitive menu items specific to this classto the page
217 * selector tree. m_m_contextActions is QList of QActions, so this is
218 * only done once with the first population. */
219 m_contextActions.append(actionRefreshClients);
220 /* Create the context menu for the client tree */
227 * Virtual Function to return the name for the medialist tree widget
229 void Clients::treeWidgetName(QString &name)