2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 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 Bacula® is a registered trademark of Kern Sibbald.
20 * Dirk Bartley, March 2007
24 #include "jobs/jobs.h"
26 #include "util/fmtwidgetitem.h"
28 Jobs::Jobs() : Pages()
33 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
34 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
36 /* tableWidget, Storage Tree Tree Widget inherited from ui_client.h */
38 m_checkcurwidget = true;
40 /* add context sensitive menu items specific to this classto the page
41 * selector tree. m_contextActions is QList of QActions */
42 m_contextActions.append(actionRefreshJobs);
45 connect(tableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)),
46 this, SLOT(runJob()));
54 * The main meat of the class!! The function that querries the director and
55 * creates the widgets with appropriate values.
57 void Jobs::populateTable()
62 Freeze frz(*tableWidget); /* disable updating*/
64 QBrush blackBrush(Qt::black);
65 m_checkcurwidget = false;
67 m_checkcurwidget = true;
68 QStringList headerlist = (QStringList() << tr("Job Name")
69 << tr("Pool") << tr("Messages") << tr("Client")
70 << tr("Storage") << tr("Level") << tr("Type")
71 << tr("FileSet") << tr("Catalog") << tr("Enabled")
74 m_typeIndex = headerlist.indexOf(tr("Type"));
76 tableWidget->setColumnCount(headerlist.count());
77 tableWidget->setHorizontalHeaderLabels(headerlist);
78 tableWidget->horizontalHeader()->setHighlightSections(false);
79 tableWidget->setRowCount(m_console->job_list.count());
80 tableWidget->verticalHeader()->hide();
81 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
82 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
83 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
86 foreach (QString jobName, m_console->job_list){
87 job_defaults job_defs;
88 job_defs.job_name = jobName;
89 if (m_console->get_job_defaults(job_defs)) {
91 TableItemFormatter jobsItem(*tableWidget, row);
92 jobsItem.setTextFld(col++, jobName);
93 jobsItem.setTextFld(col++, job_defs.pool_name);
94 jobsItem.setTextFld(col++, job_defs.messages_name);
95 jobsItem.setTextFld(col++, job_defs.client_name);
96 jobsItem.setTextFld(col++, job_defs.store_name);
97 jobsItem.setTextFld(col++, job_defs.level);
98 jobsItem.setTextFld(col++, job_defs.type);
99 jobsItem.setTextFld(col++, job_defs.fileset_name);
100 jobsItem.setTextFld(col++, job_defs.catalog_name);
101 jobsItem.setBoolFld(col++, job_defs.enabled);
102 jobsItem.setTextFld(col++, job_defs.where);
106 /* set default sorting */
107 tableWidget->sortByColumn(headerlist.indexOf(tr("Job Name")), Qt::AscendingOrder);
108 tableWidget->setSortingEnabled(true);
110 /* Resize rows and columns */
111 tableWidget->resizeColumnsToContents();
112 tableWidget->resizeRowsToContents();
115 tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
122 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
123 * The tree has been populated.
125 void Jobs::PgSeltreeWidgetClicked()
133 * Added to set the context menu policy based on currently active tableWidgetItem
134 * signaled by currentItemChanged
136 void Jobs::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem )
138 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
139 if (m_checkcurwidget && currentwidgetitem) {
140 /* The Previous item */
141 if (previouswidgetitem) { /* avoid a segfault if first time */
142 foreach(QAction* jobAction, tableWidget->actions()) {
143 tableWidget->removeAction(jobAction);
146 int currentRow = currentwidgetitem->row();
147 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
148 m_currentlyselected = currentrowzeroitem->text();
149 QTableWidgetItem *currenttypeitem = tableWidget->item(currentRow, m_typeIndex);
150 QString type = currenttypeitem->text();
152 if (m_currentlyselected.length() != 0) {
153 /* set a hold variable to the client name in case the context sensitive
155 tableWidget->addAction(actionRefreshJobs);
156 tableWidget->addAction(actionConsoleListFiles);
157 tableWidget->addAction(actionConsoleListVolumes);
158 tableWidget->addAction(actionConsoleListNextVolume);
159 tableWidget->addAction(actionConsoleEnableJob);
160 tableWidget->addAction(actionConsoleDisableJob);
161 tableWidget->addAction(actionConsoleCancel);
162 tableWidget->addAction(actionJobListQuery);
163 tableWidget->addAction(actionRunJob);
169 * Setup a context menu
170 * Made separate from populate so that it would not create context menu over and
171 * over as the table is repopulated.
173 void Jobs::createContextMenu()
175 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
176 tableWidget->addAction(actionRefreshJobs);
177 connect(tableWidget, SIGNAL(
178 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
179 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
180 /* connect to the action specific to this pages class */
181 connect(actionRefreshJobs, SIGNAL(triggered()), this,
182 SLOT(populateTable()));
183 connect(actionConsoleListFiles, SIGNAL(triggered()), this, SLOT(consoleListFiles()));
184 connect(actionConsoleListVolumes, SIGNAL(triggered()), this, SLOT(consoleListVolume()));
185 connect(actionConsoleListNextVolume, SIGNAL(triggered()), this, SLOT(consoleListNextVolume()));
186 connect(actionConsoleEnableJob, SIGNAL(triggered()), this, SLOT(consoleEnable()));
187 connect(actionConsoleDisableJob, SIGNAL(triggered()), this, SLOT(consoleDisable()));
188 connect(actionConsoleCancel, SIGNAL(triggered()), this, SLOT(consoleCancel()));
189 connect(actionJobListQuery, SIGNAL(triggered()), this, SLOT(listJobs()));
190 connect(actionRunJob, SIGNAL(triggered()), this, SLOT(runJob()));
194 * Virtual function which is called when this page is visible on the stack
196 void Jobs::currentStackItem()
199 /* Create the context menu for the client table */
205 * The following functions are slots responding to users clicking on the context
209 void Jobs::consoleListFiles()
211 QString cmd = "list files job=\"" + m_currentlyselected + "\"";
212 if (mainWin->m_longList) { cmd.prepend("l"); }
216 void Jobs::consoleListVolume()
218 QString cmd = "list volumes job=\"" + m_currentlyselected + "\"";
219 if (mainWin->m_longList) { cmd.prepend("l"); }
223 void Jobs::consoleListNextVolume()
225 QString cmd = "list nextvolume job=\"" + m_currentlyselected + "\"";
226 if (mainWin->m_longList) { cmd.prepend("l"); }
230 void Jobs::consoleEnable()
232 QString cmd = "enable job=\"" + m_currentlyselected + "\"";
236 void Jobs::consoleDisable()
238 QString cmd = "disable job=\"" + m_currentlyselected + "\"";
242 void Jobs::consoleCancel()
244 QString cmd = "cancel job=\"" + m_currentlyselected + "\"";
248 void Jobs::listJobs()
250 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
251 mainWin->createPageJobList("", "", m_currentlyselected, "", parentItem);
255 * Open a new job run page with the currently selected job
260 new runPage(m_currentlyselected);