2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 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 and included
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 Kern Sibbald.
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.
34 * Dirk Bartley, March 2007
39 #include "jobs/jobs.h"
41 #include "util/fmtwidgetitem.h"
48 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
51 /* tableWidget, Storage Tree Tree Widget inherited from ui_client.h */
53 m_checkcurwidget = true;
55 /* add context sensitive menu items specific to this classto the page
56 * selector tree. m_contextActions is QList of QActions */
57 m_contextActions.append(actionRefreshJobs);
67 * The main meat of the class!! The function that querries the director and
68 * creates the widgets with appropriate values.
70 void Jobs::populateTable()
75 Freeze frz(*tableWidget); /* disable updating*/
77 QBrush blackBrush(Qt::black);
78 m_checkcurwidget = false;
80 m_checkcurwidget = true;
81 QStringList headerlist = (QStringList() << tr("Job Name")
82 << tr("Pool") << tr("Messages") << tr("Client")
83 << tr("Storage") << tr("Level") << tr("Type")
84 << tr("FileSet") << tr("Catalog") << tr("Enabled")
87 m_typeIndex = headerlist.indexOf(tr("Type"));
89 tableWidget->setColumnCount(headerlist.count());
90 tableWidget->setHorizontalHeaderLabels(headerlist);
91 tableWidget->horizontalHeader()->setHighlightSections(false);
92 tableWidget->setRowCount(m_console->job_list.count());
93 tableWidget->verticalHeader()->hide();
94 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
95 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
96 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
99 foreach (QString jobName, m_console->job_list){
100 job_defaults job_defs;
101 job_defs.job_name = jobName;
102 if (m_console->get_job_defaults(job_defs)) {
104 TableItemFormatter jobsItem(*tableWidget, row);
105 jobsItem.setTextFld(col++, jobName);
106 jobsItem.setTextFld(col++, job_defs.pool_name);
107 jobsItem.setTextFld(col++, job_defs.messages_name);
108 jobsItem.setTextFld(col++, job_defs.client_name);
109 jobsItem.setTextFld(col++, job_defs.store_name);
110 jobsItem.setTextFld(col++, job_defs.level);
111 jobsItem.setTextFld(col++, job_defs.type);
112 jobsItem.setTextFld(col++, job_defs.fileset_name);
113 jobsItem.setTextFld(col++, job_defs.catalog_name);
114 jobsItem.setBoolFld(col++, job_defs.enabled);
115 jobsItem.setTextFld(col++, job_defs.where);
120 /* set default sorting */
121 tableWidget->sortByColumn(headerlist.indexOf(tr("Job Name")), Qt::AscendingOrder);
122 tableWidget->setSortingEnabled(true);
124 /* Resize rows and columns */
125 tableWidget->resizeColumnsToContents();
126 tableWidget->resizeRowsToContents();
129 int rcnt = tableWidget->rowCount();
130 int ccnt = tableWidget->columnCount();
131 for(int r=0; r < rcnt; r++) {
132 for(int c=0; c < ccnt; c++) {
133 QTableWidgetItem* item = tableWidget->item(r, c);
135 item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable)));
143 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
144 * The tree has been populated.
146 void Jobs::PgSeltreeWidgetClicked()
154 * Added to set the context menu policy based on currently active tableWidgetItem
155 * signaled by currentItemChanged
157 void Jobs::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem )
159 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
160 if (m_checkcurwidget && currentwidgetitem) {
161 /* The Previous item */
162 if (previouswidgetitem) { /* avoid a segfault if first time */
163 foreach(QAction* jobAction, tableWidget->actions()) {
164 tableWidget->removeAction(jobAction);
167 int currentRow = currentwidgetitem->row();
168 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
169 m_currentlyselected = currentrowzeroitem->text();
170 QTableWidgetItem *currenttypeitem = tableWidget->item(currentRow, m_typeIndex);
171 QString type = currenttypeitem->text();
173 if (m_currentlyselected.length() != 0) {
174 /* set a hold variable to the client name in case the context sensitive
176 tableWidget->addAction(actionConsoleListFiles);
177 tableWidget->addAction(actionConsoleListVolumes);
178 tableWidget->addAction(actionConsoleListNextVolume);
179 tableWidget->addAction(actionConsoleEnableJob);
180 tableWidget->addAction(actionConsoleDisableJob);
181 tableWidget->addAction(actionConsoleCancel);
182 tableWidget->addAction(actionJobListQuery);
183 tableWidget->addAction(actionRunJob);
189 * Setup a context menu
190 * Made separate from populate so that it would not create context menu over and
191 * over as the table is repopulated.
193 void Jobs::createContextMenu()
195 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
196 tableWidget->addAction(actionRefreshJobs);
197 connect(tableWidget, SIGNAL(
198 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
199 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
200 /* connect to the action specific to this pages class */
201 connect(actionRefreshJobs, SIGNAL(triggered()), this,
202 SLOT(populateTable()));
203 connect(actionConsoleListFiles, SIGNAL(triggered()), this, SLOT(consoleListFiles()));
204 connect(actionConsoleListVolumes, SIGNAL(triggered()), this, SLOT(consoleListVolume()));
205 connect(actionConsoleListNextVolume, SIGNAL(triggered()), this, SLOT(consoleListNextVolume()));
206 connect(actionConsoleEnableJob, SIGNAL(triggered()), this, SLOT(consoleEnable()));
207 connect(actionConsoleDisableJob, SIGNAL(triggered()), this, SLOT(consoleDisable()));
208 connect(actionConsoleCancel, SIGNAL(triggered()), this, SLOT(consoleCancel()));
209 connect(actionJobListQuery, SIGNAL(triggered()), this, SLOT(listJobs()));
210 connect(actionRunJob, SIGNAL(triggered()), this, SLOT(runJob()));
214 * Virtual function which is called when this page is visible on the stack
216 void Jobs::currentStackItem()
219 /* Create the context menu for the client table */
225 * The following functions are slots responding to users clicking on the context
229 void Jobs::consoleListFiles()
231 QString cmd = "list files job=\"" + m_currentlyselected + "\"";
232 if (mainWin->m_longList) { cmd.prepend("l"); }
236 void Jobs::consoleListVolume()
238 QString cmd = "list volumes job=\"" + m_currentlyselected + "\"";
239 if (mainWin->m_longList) { cmd.prepend("l"); }
243 void Jobs::consoleListNextVolume()
245 QString cmd = "list nextvolume job=\"" + m_currentlyselected + "\"";
246 if (mainWin->m_longList) { cmd.prepend("l"); }
250 void Jobs::consoleEnable()
252 QString cmd = "enable job=\"" + m_currentlyselected + "\"";
256 void Jobs::consoleDisable()
258 QString cmd = "disable job=\"" + m_currentlyselected + "\"";
262 void Jobs::consoleCancel()
264 QString cmd = "cancel job=\"" + m_currentlyselected + "\"";
268 void Jobs::listJobs()
270 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
271 mainWin->createPageJobList("", "", m_currentlyselected, "", parentItem);
275 * Open a new job run page with the currently selected job
280 new runPage(m_currentlyselected);