]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/jobs/jobs.cpp
Set keyword replacement on files
[bacula/bacula] / bacula / src / qt-console / jobs / jobs.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
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
11    in the file LICENSE.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28  
29 /*
30  *   Version $Id$
31  *
32  *  Jobs Class
33  *
34  *   Dirk Bartley, March 2007
35  *
36  */ 
37
38 #include "bat.h"
39 #include "jobs/jobs.h"
40 #include "run/run.h"
41
42 Jobs::Jobs()
43 {
44    setupUi(this);
45    m_name = "Jobs";
46    pgInitialize();
47    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
48    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
49
50    /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */
51    m_populated = false;
52    m_checkcurwidget = true;
53    m_closeable = false;
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);
57    createContextMenu();
58    dockPage();
59 }
60
61 Jobs::~Jobs()
62 {
63 }
64
65 /*
66  * The main meat of the class!!  The function that querries the director and 
67  * creates the widgets with appropriate values.
68  */
69 void Jobs::populateTree()
70 {
71    QTreeWidgetItem *jobsItem, *topItem;
72
73    if (!m_console->preventInUseConnect())
74       return;
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");
81
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);
87
88    mp_treeWidget->setColumnCount(headerlist.count());
89    mp_treeWidget->setHeaderLabels(headerlist);
90
91    foreach (QString jobName, m_console->job_list){
92       jobsItem = new QTreeWidgetItem(topItem);
93       jobsItem->setText(0, jobName);
94       //jobsItem->setExpanded(true);
95
96       for (int i=0; i<headerlist.count(); i++)
97          jobsItem->setData(i, Qt::UserRole, 1);
98
99       job_defaults job_defs;
100       job_defs.job_name = jobName;
101       if (m_console->get_job_defaults(job_defs)) {
102          int col = 1;
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");
114          } else {
115             jobsItem->setText(col++, "No");
116          }
117       }
118    }
119    /* Resize the columns */
120    for(int cnter=0; cnter<headerlist.size(); cnter++) {
121       mp_treeWidget->resizeColumnToContents(cnter);
122    }
123 }
124
125 /*
126  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
127  * The tree has been populated.
128  */
129 void Jobs::PgSeltreeWidgetClicked()
130 {
131    if(!m_populated) {
132       populateTree();
133       m_populated=true;
134    }
135 }
136
137 /*
138  * Added to set the context menu policy based on currently active treeWidgetItem
139  * signaled by currentItemChanged
140  */
141 void Jobs::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
142 {
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);
149          }
150       }
151
152       int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
153       if (treedepth == 1){
154          /* set a hold variable to the client name in case the context sensitive
155           * menu is used */
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);
166       }
167    }
168 }
169
170 /* 
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.
174  */
175 void Jobs::createContextMenu()
176 {
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()));
193 }
194
195 /*
196  * Virtual function which is called when this page is visible on the stack
197  */
198 void Jobs::currentStackItem()
199 {
200    populateTree();
201    if(!m_populated) {
202       /* Create the context menu for the client tree */
203       m_populated=true;
204    }
205 }
206
207 /*
208  * The following functions are slots responding to users clicking on the context
209  * sensitive menu
210  */
211
212 void Jobs::consoleListFiles()
213 {
214    QString cmd("list files job=");
215    cmd += m_currentlyselected;
216    consoleCommand(cmd);
217 }
218
219 void Jobs::consoleListVolume()
220 {
221    QString cmd("list volumes job=");
222    cmd += m_currentlyselected;
223    consoleCommand(cmd);
224 }
225
226 void Jobs::consoleListNextVolume()
227 {
228    QString cmd("list nextvolume job=");
229    cmd += m_currentlyselected;
230    consoleCommand(cmd);
231 }
232
233 void Jobs::consoleEnable()
234 {
235    QString cmd("enable job=");
236    cmd += m_currentlyselected;
237    consoleCommand(cmd);
238 }
239
240 void Jobs::consoleDisable()
241 {
242    QString cmd("disable job=");
243    cmd += m_currentlyselected;
244    consoleCommand(cmd);
245 }
246
247 void Jobs::consoleCancel()
248 {
249    QString cmd("cancel job=");
250    cmd += m_currentlyselected;
251    consoleCommand(cmd);
252 }
253
254 void Jobs::listJobs()
255 {
256    QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
257    mainWin->createPageJobList("", "", m_currentlyselected, "", parentItem);
258 }
259
260 /*
261  * Open a new job run page with the currentley selected "Backup" job 
262  * defaulted In
263  */
264 void Jobs::runJob()
265 {
266    new runPage(m_currentlyselected);
267 }