2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2007 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() << "Job Name" << "Pool" << "Messages"
79 << "Client" << "Storage" << "Where" << "Level" << "Type" << "FileSet"
80 << "Catalog" << "Enabled");
82 m_typeIndex = headerlist.indexOf("Type");
83 topItem = new QTreeWidgetItem(mp_treeWidget);
84 topItem->setText(0, "Jobs");
85 topItem->setData(0, Qt::UserRole, 0);
86 topItem->setExpanded(true);
88 mp_treeWidget->setColumnCount(headerlist.count());
89 mp_treeWidget->setHeaderLabels(headerlist);
91 foreach (QString jobName, m_console->job_list){
92 jobsItem = new QTreeWidgetItem(topItem);
93 jobsItem->setText(0, jobName);
94 //jobsItem->setExpanded(true);
96 for (int i=0; i<headerlist.count(); i++)
97 jobsItem->setData(i, Qt::UserRole, 1);
99 job_defaults job_defs;
100 job_defs.job_name = jobName;
101 if (m_console->get_job_defaults(job_defs)) {
103 jobsItem->setText(col++, job_defs.pool_name);
104 jobsItem->setText(col++, job_defs.messages_name);
105 jobsItem->setText(col++, job_defs.client_name);
106 jobsItem->setText(col++, job_defs.store_name);
107 jobsItem->setText(col++, job_defs.where);
108 jobsItem->setText(col++, job_defs.level);
109 jobsItem->setText(col++, job_defs.type);
110 jobsItem->setText(col++, job_defs.fileset_name);
111 jobsItem->setText(col++, job_defs.catalog_name);
112 if (job_defs.enabled) {
113 jobsItem->setText(col++, "Yes");
115 jobsItem->setText(col++, "No");
119 /* Resize the columns */
120 for(int cnter=0; cnter<headerlist.size(); cnter++) {
121 mp_treeWidget->resizeColumnToContents(cnter);
126 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
127 * The tree has been populated.
129 void Jobs::PgSeltreeWidgetClicked()
138 * Added to set the context menu policy based on currently active treeWidgetItem
139 * signaled by currentItemChanged
141 void Jobs::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
143 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
144 if (m_checkcurwidget) {
145 /* The Previous item */
146 if (previouswidgetitem) { /* avoid a segfault if first time */
147 foreach(QAction* jobAction, mp_treeWidget->actions()) {
148 mp_treeWidget->removeAction(jobAction);
152 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
154 /* set a hold variable to the client name in case the context sensitive
156 m_currentlyselected=currentwidgetitem->text(0);
157 mp_treeWidget->addAction(actionConsoleListFiles);
158 mp_treeWidget->addAction(actionConsoleListVolumes);
159 mp_treeWidget->addAction(actionConsoleListNextVolume);
160 mp_treeWidget->addAction(actionConsoleEnableJob);
161 mp_treeWidget->addAction(actionConsoleDisableJob);
162 mp_treeWidget->addAction(actionConsoleCancel);
163 mp_treeWidget->addAction(actionJobListQuery);
164 if (currentwidgetitem->text(m_typeIndex) == "Backup")
165 mp_treeWidget->addAction(actionRunJob);
171 * Setup a context menu
172 * Made separate from populate so that it would not create context menu over and
173 * over as the tree is repopulated.
175 void Jobs::createContextMenu()
177 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
178 mp_treeWidget->addAction(actionRefreshJobs);
179 connect(mp_treeWidget, SIGNAL(
180 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
181 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
182 /* connect to the action specific to this pages class */
183 connect(actionRefreshJobs, SIGNAL(triggered()), this,
184 SLOT(populateTree()));
185 connect(actionConsoleListFiles, SIGNAL(triggered()), this, SLOT(consoleListFiles()));
186 connect(actionConsoleListVolumes, SIGNAL(triggered()), this, SLOT(consoleListVolume()));
187 connect(actionConsoleListNextVolume, SIGNAL(triggered()), this, SLOT(consoleListNextVolume()));
188 connect(actionConsoleEnableJob, SIGNAL(triggered()), this, SLOT(consoleEnable()));
189 connect(actionConsoleDisableJob, SIGNAL(triggered()), this, SLOT(consoleDisable()));
190 connect(actionConsoleCancel, SIGNAL(triggered()), this, SLOT(consoleCancel()));
191 connect(actionJobListQuery, SIGNAL(triggered()), this, SLOT(listJobs()));
192 connect(actionRunJob, SIGNAL(triggered()), this, SLOT(runJob()));
196 * Virtual function which is called when this page is visible on the stack
198 void Jobs::currentStackItem()
202 /* Create the context menu for the client tree */
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 + "\"";
218 void Jobs::consoleListVolume()
220 QString cmd = "list volumes job=\"" + m_currentlyselected + "\"";
224 void Jobs::consoleListNextVolume()
226 QString cmd = "list nextvolume job=\"" + m_currentlyselected + "\"";
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 currentley selected "Backup" job
260 new runPage(m_currentlyselected);