]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/jobs/jobs.cpp
Add translation strings
[bacula/bacula] / bacula / src / qt-console / jobs / jobs.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 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 = tr("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() << tr("Job Name") << tr("Pool") << tr("Messages")
79       << tr("Client") << tr("Storage") << tr("Where") << tr("Level") << tr("Type") 
80       << tr("FileSet") 
81       << tr("Catalog") << tr("Enabled"));
82
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);
88
89    mp_treeWidget->setColumnCount(headerlist.count());
90    mp_treeWidget->setHeaderLabels(headerlist);
91
92    foreach (QString jobName, m_console->job_list){
93       jobsItem = new QTreeWidgetItem(topItem);
94       jobsItem->setText(0, jobName);
95       //jobsItem->setExpanded(true);
96
97       for (int i=0; i<headerlist.count(); i++)
98          jobsItem->setData(i, Qt::UserRole, 1);
99
100       job_defaults job_defs;
101       job_defs.job_name = jobName;
102       if (m_console->get_job_defaults(job_defs)) {
103          int col = 1;
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");
115          } else {
116             jobsItem->setText(col++, "No");
117          }
118       }
119    }
120    /* Resize the columns */
121    for(int cnter=0; cnter<headerlist.size(); cnter++) {
122       mp_treeWidget->resizeColumnToContents(cnter);
123    }
124 }
125
126 /*
127  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
128  * The tree has been populated.
129  */
130 void Jobs::PgSeltreeWidgetClicked()
131 {
132    if(!m_populated) {
133       populateTree();
134       m_populated=true;
135    }
136 }
137
138 /*
139  * Added to set the context menu policy based on currently active treeWidgetItem
140  * signaled by currentItemChanged
141  */
142 void Jobs::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
143 {
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);
150          }
151       }
152
153       int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
154       if (treedepth == 1){
155          /* set a hold variable to the client name in case the context sensitive
156           * menu is used */
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);
167       }
168    }
169 }
170
171 /* 
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.
175  */
176 void Jobs::createContextMenu()
177 {
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()));
194 }
195
196 /*
197  * Virtual function which is called when this page is visible on the stack
198  */
199 void Jobs::currentStackItem()
200 {
201    populateTree();
202    if(!m_populated) {
203       /* Create the context menu for the client tree */
204       m_populated=true;
205    }
206 }
207
208 /*
209  * The following functions are slots responding to users clicking on the context
210  * sensitive menu
211  */
212
213 void Jobs::consoleListFiles()
214 {
215    QString cmd = "list files job=\"" + m_currentlyselected + "\"";
216    if (mainWin->m_longList) { cmd.prepend("l"); }
217    consoleCommand(cmd);
218 }
219
220 void Jobs::consoleListVolume()
221 {
222    QString cmd = "list volumes job=\"" + m_currentlyselected + "\"";
223    if (mainWin->m_longList) { cmd.prepend("l"); }
224    consoleCommand(cmd);
225 }
226
227 void Jobs::consoleListNextVolume()
228 {
229    QString cmd = "list nextvolume job=\"" + m_currentlyselected + "\"";
230    if (mainWin->m_longList) { cmd.prepend("l"); }
231    consoleCommand(cmd);
232 }
233
234 void Jobs::consoleEnable()
235 {
236    QString cmd = "enable job=\"" + m_currentlyselected + "\"";
237    consoleCommand(cmd);
238 }
239
240 void Jobs::consoleDisable()
241 {
242    QString cmd = "disable job=\"" + m_currentlyselected + "\"";
243    consoleCommand(cmd);
244 }
245
246 void Jobs::consoleCancel()
247 {
248    QString cmd = "cancel job=\"" + m_currentlyselected + "\"";
249    consoleCommand(cmd);
250 }
251
252 void Jobs::listJobs()
253 {
254    QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
255    mainWin->createPageJobList("", "", m_currentlyselected, "", parentItem);
256 }
257
258 /*
259  * Open a new job run page with the currentley selected "Backup" job 
260  * defaulted In
261  */
262 void Jobs::runJob()
263 {
264    new runPage(m_currentlyselected);
265 }