2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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 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.
34 * Dirk Bartley, March 2007
39 #include "jobs/jobs.h"
47 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
48 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
50 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */
52 m_checkcurwidget = true;
54 /* add context sensitive menu items specific to this classto the page
55 * selector tree. m_contextActions is QList of QActions */
56 m_contextActions.append(actionRefreshJobs);
66 * The main meat of the class!! The function that querries the director and
67 * creates the widgets with appropriate values.
69 void Jobs::populateTree()
71 QTreeWidgetItem *jobsItem, *topItem;
73 if (!m_console->preventInUseConnect())
75 m_checkcurwidget = false;
76 mp_treeWidget->clear();
77 m_checkcurwidget = true;
78 QStringList headerlist = (QStringList() << tr("Job Name") << tr("Pool") << tr("Messages")
79 << tr("Client") << tr("Storage") << tr("Where") << tr("Level") << tr("Type")
81 << tr("Catalog") << tr("Enabled"));
83 m_typeIndex = headerlist.indexOf(tr("Type"));
84 topItem = new QTreeWidgetItem(mp_treeWidget);
85 topItem->setText(0, tr("Jobs"));
86 topItem->setData(0, Qt::UserRole, 0);
87 topItem->setExpanded(true);
89 mp_treeWidget->setColumnCount(headerlist.count());
90 mp_treeWidget->setHeaderLabels(headerlist);
92 foreach (QString jobName, m_console->job_list){
93 jobsItem = new QTreeWidgetItem(topItem);
94 jobsItem->setText(0, jobName);
95 //jobsItem->setExpanded(true);
97 for (int i=0; i<headerlist.count(); i++)
98 jobsItem->setData(i, Qt::UserRole, 1);
100 job_defaults job_defs;
101 job_defs.job_name = jobName;
102 if (m_console->get_job_defaults(job_defs)) {
104 jobsItem->setText(col++, job_defs.pool_name);
105 jobsItem->setText(col++, job_defs.messages_name);
106 jobsItem->setText(col++, job_defs.client_name);
107 jobsItem->setText(col++, job_defs.store_name);
108 jobsItem->setText(col++, job_defs.where);
109 jobsItem->setText(col++, job_defs.level);
110 jobsItem->setText(col++, job_defs.type);
111 jobsItem->setText(col++, job_defs.fileset_name);
112 jobsItem->setText(col++, job_defs.catalog_name);
113 if (job_defs.enabled) {
114 jobsItem->setText(col++, "Yes");
116 jobsItem->setText(col++, "No");
120 /* Resize the columns */
121 for(int cnter=0; cnter<headerlist.size(); cnter++) {
122 mp_treeWidget->resizeColumnToContents(cnter);
127 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
128 * The tree has been populated.
130 void Jobs::PgSeltreeWidgetClicked()
139 * Added to set the context menu policy based on currently active treeWidgetItem
140 * signaled by currentItemChanged
142 void Jobs::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
144 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
145 if (m_checkcurwidget) {
146 /* The Previous item */
147 if (previouswidgetitem) { /* avoid a segfault if first time */
148 foreach(QAction* jobAction, mp_treeWidget->actions()) {
149 mp_treeWidget->removeAction(jobAction);
153 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
155 /* set a hold variable to the client name in case the context sensitive
157 m_currentlyselected=currentwidgetitem->text(0);
158 mp_treeWidget->addAction(actionConsoleListFiles);
159 mp_treeWidget->addAction(actionConsoleListVolumes);
160 mp_treeWidget->addAction(actionConsoleListNextVolume);
161 mp_treeWidget->addAction(actionConsoleEnableJob);
162 mp_treeWidget->addAction(actionConsoleDisableJob);
163 mp_treeWidget->addAction(actionConsoleCancel);
164 mp_treeWidget->addAction(actionJobListQuery);
165 if (currentwidgetitem->text(m_typeIndex) == tr("Backup"))
166 mp_treeWidget->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 tree is repopulated.
176 void Jobs::createContextMenu()
178 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
179 mp_treeWidget->addAction(actionRefreshJobs);
180 connect(mp_treeWidget, SIGNAL(
181 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
182 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
183 /* connect to the action specific to this pages class */
184 connect(actionRefreshJobs, SIGNAL(triggered()), this,
185 SLOT(populateTree()));
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()
203 /* Create the context menu for the client tree */
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 currentley selected "Backup" job
264 new runPage(m_currentlyselected);