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;
60 * The main meat of the class!! The function that querries the director and
61 * creates the widgets with appropriate values.
63 void Clients::populateTree()
65 QTreeWidgetItem *clientItem, *topItem;
67 if (!m_console->preventInUseConnect())
69 m_checkcurwidget = false;
70 mp_treeWidget->clear();
71 m_checkcurwidget = true;
73 QStringList headerlist = (QStringList() << "Client Name" << "File Retention"
74 << "Job Retention" << "AutoPrune" << "ClientId" << "Uname" );
76 topItem = new QTreeWidgetItem(mp_treeWidget);
77 topItem->setText(0, "Clients");
78 topItem->setData(0, Qt::UserRole, 0);
79 topItem->setExpanded(true);
81 mp_treeWidget->setColumnCount(headerlist.count());
82 mp_treeWidget->setHeaderLabels(headerlist);
84 foreach (QString clientName, m_console->client_list){
85 clientItem = new QTreeWidgetItem(topItem);
86 clientItem->setText(0, clientName);
87 clientItem->setData(0, Qt::UserRole, 1);
88 clientItem->setExpanded(true);
90 /* Set up query QString and header QStringList */
92 query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname"
95 query += " Name='" + clientName + "'";
96 query += " ORDER BY Name";
99 /* This could be a log item */
100 if (mainWin->m_sqlDebug) {
101 Pmsg1(000, "Clients query cmd : %s\n",query.toUtf8().data());
103 if (m_console->sql_cmd(query, results)) {
104 int resultCount = results.count();
105 if (resultCount == 1){
108 QStringList fieldlist;
109 /* there will only be one of these */
110 foreach (resultline, results) {
111 fieldlist = resultline.split("\t");
113 /* Iterate through fields in the record */
114 foreach (field, fieldlist) {
115 field = field.trimmed(); /* strip leading & trailing spaces */
116 clientItem->setData(index+1, Qt::UserRole, 1);
117 /* Put media fields under the pool tree item */
118 clientItem->setData(index+1, Qt::UserRole, 1);
119 clientItem->setText(index+1, field);
126 /* Resize the columns */
127 for(int cnter=0; cnter<headerlist.size(); cnter++) {
128 mp_treeWidget->resizeColumnToContents(cnter);
133 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
134 * The tree has been populated.
136 void Clients::PgSeltreeWidgetClicked()
146 * Added to set the context menu policy based on currently active treeWidgetItem
147 * signaled by currentItemChanged
149 void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
151 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
152 if (m_checkcurwidget) {
153 /* The Previous item */
154 if (previouswidgetitem) { /* avoid a segfault if first time */
155 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
157 mp_treeWidget->removeAction(actionListJobsofClient);
158 mp_treeWidget->removeAction(actionStatusClientInConsole);
162 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
164 /* set a hold variable to the client name in case the context sensitive
166 m_currentlyselected=currentwidgetitem->text(0);
167 mp_treeWidget->addAction(actionListJobsofClient);
168 mp_treeWidget->addAction(actionStatusClientInConsole);
174 * Setup a context menu
175 * Made separate from populate so that it would not create context menu over and
176 * over as the tree is repopulated.
178 void Clients::createContextMenu()
180 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
181 mp_treeWidget->addAction(actionRefreshClients);
182 connect(mp_treeWidget, SIGNAL(
183 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
184 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
185 /* connect to the action specific to this pages class */
186 connect(actionRefreshClients, SIGNAL(triggered()), this,
187 SLOT(populateTree()));
188 connect(actionListJobsofClient, SIGNAL(triggered()), this,
190 connect(actionStatusClientInConsole, SIGNAL(triggered()), this,
191 SLOT(consoleStatusClient()));
195 * Function responding to actionListJobsofClient which calls mainwin function
196 * to create a window of a list of jobs of this client.
198 void Clients::showJobs()
200 QString emptymedia("");
201 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
202 mainWin->createPageJobList(emptymedia, m_currentlyselected, parentItem);
206 * Function responding to actionListJobsofClient which calls mainwin function
207 * to create a window of a list of jobs of this client.
209 void Clients::consoleStatusClient()
211 QString cmd("status client=");
212 cmd += m_currentlyselected;
217 * Virtual function which is called when this page is visible on the stack
219 void Clients::currentStackItem()
223 /* add context sensitive menu items specific to this classto the page
224 * selector tree. m_contextActions is QList of QActions, so this is
225 * only done once with the first population. */
226 m_contextActions.append(actionRefreshClients);
227 /* Create the context menu for the client tree */