2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
24 * Dirk Bartley, March 2007
28 #include "jobs/jobs.h"
30 #include "util/fmtwidgetitem.h"
32 Jobs::Jobs() : Pages()
37 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
38 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
40 /* tableWidget, Storage Tree Tree Widget inherited from ui_client.h */
42 m_checkcurwidget = true;
44 /* add context sensitive menu items specific to this classto the page
45 * selector tree. m_contextActions is QList of QActions */
46 m_contextActions.append(actionRefreshJobs);
49 connect(tableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)),
50 this, SLOT(runJob()));
58 * The main meat of the class!! The function that querries the director and
59 * creates the widgets with appropriate values.
61 void Jobs::populateTable()
66 Freeze frz(*tableWidget); /* disable updating*/
68 QBrush blackBrush(Qt::black);
69 m_checkcurwidget = false;
71 m_checkcurwidget = true;
72 QStringList headerlist = (QStringList() << tr("Job Name")
73 << tr("Pool") << tr("Messages") << tr("Client")
74 << tr("Storage") << tr("Level") << tr("Type")
75 << tr("FileSet") << tr("Catalog") << tr("Enabled")
78 m_typeIndex = headerlist.indexOf(tr("Type"));
80 tableWidget->setColumnCount(headerlist.count());
81 tableWidget->setHorizontalHeaderLabels(headerlist);
82 tableWidget->horizontalHeader()->setHighlightSections(false);
83 tableWidget->setRowCount(m_console->job_list.count());
84 tableWidget->verticalHeader()->hide();
85 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
86 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
87 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
90 foreach (QString jobName, m_console->job_list){
91 job_defaults job_defs;
92 job_defs.job_name = jobName;
93 if (m_console->get_job_defaults(job_defs)) {
95 TableItemFormatter jobsItem(*tableWidget, row);
96 jobsItem.setTextFld(col++, jobName);
97 jobsItem.setTextFld(col++, job_defs.pool_name);
98 jobsItem.setTextFld(col++, job_defs.messages_name);
99 jobsItem.setTextFld(col++, job_defs.client_name);
100 jobsItem.setTextFld(col++, job_defs.store_name);
101 jobsItem.setTextFld(col++, job_defs.level);
102 jobsItem.setTextFld(col++, job_defs.type);
103 jobsItem.setTextFld(col++, job_defs.fileset_name);
104 jobsItem.setTextFld(col++, job_defs.catalog_name);
105 jobsItem.setBoolFld(col++, job_defs.enabled);
106 jobsItem.setTextFld(col++, job_defs.where);
110 /* set default sorting */
111 tableWidget->sortByColumn(headerlist.indexOf(tr("Job Name")), Qt::AscendingOrder);
112 tableWidget->setSortingEnabled(true);
114 /* Resize rows and columns */
115 tableWidget->resizeColumnsToContents();
116 tableWidget->resizeRowsToContents();
119 tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
126 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
127 * The tree has been populated.
129 void Jobs::PgSeltreeWidgetClicked()
137 * Added to set the context menu policy based on currently active tableWidgetItem
138 * signaled by currentItemChanged
140 void Jobs::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem )
142 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
143 if (m_checkcurwidget && currentwidgetitem) {
144 /* The Previous item */
145 if (previouswidgetitem) { /* avoid a segfault if first time */
146 foreach(QAction* jobAction, tableWidget->actions()) {
147 tableWidget->removeAction(jobAction);
150 int currentRow = currentwidgetitem->row();
151 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
152 m_currentlyselected = currentrowzeroitem->text();
153 QTableWidgetItem *currenttypeitem = tableWidget->item(currentRow, m_typeIndex);
154 QString type = currenttypeitem->text();
156 if (m_currentlyselected.length() != 0) {
157 /* set a hold variable to the client name in case the context sensitive
159 tableWidget->addAction(actionRefreshJobs);
160 tableWidget->addAction(actionConsoleListFiles);
161 tableWidget->addAction(actionConsoleListVolumes);
162 tableWidget->addAction(actionConsoleListNextVolume);
163 tableWidget->addAction(actionConsoleEnableJob);
164 tableWidget->addAction(actionConsoleDisableJob);
165 tableWidget->addAction(actionConsoleCancel);
166 tableWidget->addAction(actionJobListQuery);
167 tableWidget->addAction(actionRunJob);
173 * Setup a context menu
174 * Made separate from populate so that it would not create context menu over and
175 * over as the table is repopulated.
177 void Jobs::createContextMenu()
179 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
180 tableWidget->addAction(actionRefreshJobs);
181 connect(tableWidget, SIGNAL(
182 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
183 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
184 /* connect to the action specific to this pages class */
185 connect(actionRefreshJobs, SIGNAL(triggered()), this,
186 SLOT(populateTable()));
187 connect(actionConsoleListFiles, SIGNAL(triggered()), this, SLOT(consoleListFiles()));
188 connect(actionConsoleListVolumes, SIGNAL(triggered()), this, SLOT(consoleListVolume()));
189 connect(actionConsoleListNextVolume, SIGNAL(triggered()), this, SLOT(consoleListNextVolume()));
190 connect(actionConsoleEnableJob, SIGNAL(triggered()), this, SLOT(consoleEnable()));
191 connect(actionConsoleDisableJob, SIGNAL(triggered()), this, SLOT(consoleDisable()));
192 connect(actionConsoleCancel, SIGNAL(triggered()), this, SLOT(consoleCancel()));
193 connect(actionJobListQuery, SIGNAL(triggered()), this, SLOT(listJobs()));
194 connect(actionRunJob, SIGNAL(triggered()), this, SLOT(runJob()));
198 * Virtual function which is called when this page is visible on the stack
200 void Jobs::currentStackItem()
203 /* Create the context menu for the client table */
209 * The following functions are slots responding to users clicking on the context
213 void Jobs::consoleListFiles()
215 QString cmd = "list files job=\"" + m_currentlyselected + "\"";
216 if (mainWin->m_longList) { cmd.prepend("l"); }
220 void Jobs::consoleListVolume()
222 QString cmd = "list volumes job=\"" + m_currentlyselected + "\"";
223 if (mainWin->m_longList) { cmd.prepend("l"); }
227 void Jobs::consoleListNextVolume()
229 QString cmd = "list nextvolume job=\"" + m_currentlyselected + "\"";
230 if (mainWin->m_longList) { cmd.prepend("l"); }
234 void Jobs::consoleEnable()
236 QString cmd = "enable job=\"" + m_currentlyselected + "\"";
240 void Jobs::consoleDisable()
242 QString cmd = "disable job=\"" + m_currentlyselected + "\"";
246 void Jobs::consoleCancel()
248 QString cmd = "cancel job=\"" + m_currentlyselected + "\"";
252 void Jobs::listJobs()
254 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
255 mainWin->createPageJobList("", "", m_currentlyselected, "", parentItem);
259 * Open a new job run page with the currently selected job
264 new runPage(m_currentlyselected);