2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
23 * Dirk Bartley, March 2007
27 #include "jobs/jobs.h"
29 #include "util/fmtwidgetitem.h"
31 Jobs::Jobs() : Pages()
36 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
37 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
39 /* tableWidget, Storage Tree Tree Widget inherited from ui_client.h */
41 m_checkcurwidget = true;
43 /* add context sensitive menu items specific to this classto the page
44 * selector tree. m_contextActions is QList of QActions */
45 m_contextActions.append(actionRefreshJobs);
48 connect(tableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)),
49 this, SLOT(runJob()));
57 * The main meat of the class!! The function that querries the director and
58 * creates the widgets with appropriate values.
60 void Jobs::populateTable()
65 Freeze frz(*tableWidget); /* disable updating*/
67 QBrush blackBrush(Qt::black);
68 m_checkcurwidget = false;
70 m_checkcurwidget = true;
71 QStringList headerlist = (QStringList() << tr("Job Name")
72 << tr("Pool") << tr("Messages") << tr("Client")
73 << tr("Storage") << tr("Level") << tr("Type")
74 << tr("FileSet") << tr("Catalog") << tr("Enabled")
77 m_typeIndex = headerlist.indexOf(tr("Type"));
79 tableWidget->setColumnCount(headerlist.count());
80 tableWidget->setHorizontalHeaderLabels(headerlist);
81 tableWidget->horizontalHeader()->setHighlightSections(false);
82 tableWidget->setRowCount(m_console->job_list.count());
83 tableWidget->verticalHeader()->hide();
84 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
85 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
86 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
89 foreach (QString jobName, m_console->job_list){
90 job_defaults job_defs;
91 job_defs.job_name = jobName;
92 if (m_console->get_job_defaults(job_defs)) {
94 TableItemFormatter jobsItem(*tableWidget, row);
95 jobsItem.setTextFld(col++, jobName);
96 jobsItem.setTextFld(col++, job_defs.pool_name);
97 jobsItem.setTextFld(col++, job_defs.messages_name);
98 jobsItem.setTextFld(col++, job_defs.client_name);
99 jobsItem.setTextFld(col++, job_defs.store_name);
100 jobsItem.setTextFld(col++, job_defs.level);
101 jobsItem.setTextFld(col++, job_defs.type);
102 jobsItem.setTextFld(col++, job_defs.fileset_name);
103 jobsItem.setTextFld(col++, job_defs.catalog_name);
104 jobsItem.setBoolFld(col++, job_defs.enabled);
105 jobsItem.setTextFld(col++, job_defs.where);
109 /* set default sorting */
110 tableWidget->sortByColumn(headerlist.indexOf(tr("Job Name")), Qt::AscendingOrder);
111 tableWidget->setSortingEnabled(true);
113 /* Resize rows and columns */
114 tableWidget->resizeColumnsToContents();
115 tableWidget->resizeRowsToContents();
118 tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
125 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
126 * The tree has been populated.
128 void Jobs::PgSeltreeWidgetClicked()
136 * Added to set the context menu policy based on currently active tableWidgetItem
137 * signaled by currentItemChanged
139 void Jobs::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem )
141 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
142 if (m_checkcurwidget && currentwidgetitem) {
143 /* The Previous item */
144 if (previouswidgetitem) { /* avoid a segfault if first time */
145 foreach(QAction* jobAction, tableWidget->actions()) {
146 tableWidget->removeAction(jobAction);
149 int currentRow = currentwidgetitem->row();
150 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
151 m_currentlyselected = currentrowzeroitem->text();
152 QTableWidgetItem *currenttypeitem = tableWidget->item(currentRow, m_typeIndex);
153 QString type = currenttypeitem->text();
155 if (m_currentlyselected.length() != 0) {
156 /* set a hold variable to the client name in case the context sensitive
158 tableWidget->addAction(actionRefreshJobs);
159 tableWidget->addAction(actionConsoleListFiles);
160 tableWidget->addAction(actionConsoleListVolumes);
161 tableWidget->addAction(actionConsoleListNextVolume);
162 tableWidget->addAction(actionConsoleEnableJob);
163 tableWidget->addAction(actionConsoleDisableJob);
164 tableWidget->addAction(actionConsoleCancel);
165 tableWidget->addAction(actionJobListQuery);
166 tableWidget->addAction(actionRunJob);
172 * Setup a context menu
173 * Made separate from populate so that it would not create context menu over and
174 * over as the table is repopulated.
176 void Jobs::createContextMenu()
178 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
179 tableWidget->addAction(actionRefreshJobs);
180 connect(tableWidget, SIGNAL(
181 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
182 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
183 /* connect to the action specific to this pages class */
184 connect(actionRefreshJobs, SIGNAL(triggered()), this,
185 SLOT(populateTable()));
186 connect(actionConsoleListFiles, SIGNAL(triggered()), this, SLOT(consoleListFiles()));
187 connect(actionConsoleListVolumes, SIGNAL(triggered()), this, SLOT(consoleListVolume()));
188 connect(actionConsoleListNextVolume, SIGNAL(triggered()), this, SLOT(consoleListNextVolume()));
189 connect(actionConsoleEnableJob, SIGNAL(triggered()), this, SLOT(consoleEnable()));
190 connect(actionConsoleDisableJob, SIGNAL(triggered()), this, SLOT(consoleDisable()));
191 connect(actionConsoleCancel, SIGNAL(triggered()), this, SLOT(consoleCancel()));
192 connect(actionJobListQuery, SIGNAL(triggered()), this, SLOT(listJobs()));
193 connect(actionRunJob, SIGNAL(triggered()), this, SLOT(runJob()));
197 * Virtual function which is called when this page is visible on the stack
199 void Jobs::currentStackItem()
202 /* Create the context menu for the client table */
208 * The following functions are slots responding to users clicking on the context
212 void Jobs::consoleListFiles()
214 QString cmd = "list files job=\"" + m_currentlyselected + "\"";
215 if (mainWin->m_longList) { cmd.prepend("l"); }
219 void Jobs::consoleListVolume()
221 QString cmd = "list volumes job=\"" + m_currentlyselected + "\"";
222 if (mainWin->m_longList) { cmd.prepend("l"); }
226 void Jobs::consoleListNextVolume()
228 QString cmd = "list nextvolume job=\"" + m_currentlyselected + "\"";
229 if (mainWin->m_longList) { cmd.prepend("l"); }
233 void Jobs::consoleEnable()
235 QString cmd = "enable job=\"" + m_currentlyselected + "\"";
239 void Jobs::consoleDisable()
241 QString cmd = "disable job=\"" + m_currentlyselected + "\"";
245 void Jobs::consoleCancel()
247 QString cmd = "cancel job=\"" + m_currentlyselected + "\"";
251 void Jobs::listJobs()
253 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
254 mainWin->createPageJobList("", "", m_currentlyselected, "", parentItem);
258 * Open a new job run page with the currently selected job
263 new runPage(m_currentlyselected);