]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/run.cpp
bat: Add a re-run button on job info page, that allows to
[bacula/bacula] / bacula / src / qt-console / run / run.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2009 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 Kern Sibbald.
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  *  Run Dialog class
31  *
32  *   Kern Sibbald, February MMVII
33  *
34  *  $Id$
35  */ 
36
37 #include "bat.h"
38 #include "run.h"
39
40
41 runPage::runPage()
42 {
43    init();
44    show();
45 }
46
47 runPage::runPage(const QString &defJob)
48 {
49    init();
50    if (defJob != "")
51       jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
52    show();
53 }
54
55
56 runPage::runPage(const QString &defJob, const QString &level, 
57                  const QString &pool, const QString &storage,
58                  const QString &client, const QString &fileset)
59 {
60    init();
61    jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
62    job_name_change(0);
63    filesetCombo->setCurrentIndex(filesetCombo->findText(fileset,
64                                                         Qt::MatchExactly));
65    levelCombo->setCurrentIndex(levelCombo->findText(level, Qt::MatchExactly));
66    clientCombo->setCurrentIndex(clientCombo->findText(client,Qt::MatchExactly));
67    poolCombo->setCurrentIndex(poolCombo->findText(pool, Qt::MatchExactly));
68
69    if (storage != "") {         // TODO: enable storage
70       storageCombo->setCurrentIndex(storageCombo->findText(storage, 
71                                                            Qt::MatchExactly));
72    }
73    show();
74 }
75
76
77 /*
78  * Setup all the combo boxes and display the dialog
79  */
80 void runPage::init()
81 {
82    QDateTime dt;
83
84    m_name = tr("Run");
85    pgInitialize();
86    setupUi(this);
87    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
88    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
89    m_conn = m_console->notifyOff();
90
91    m_console->beginNewCommand(m_conn);
92    jobCombo->addItems(m_console->job_list);
93    filesetCombo->addItems(m_console->fileset_list);
94    levelCombo->addItems(m_console->level_list);
95    clientCombo->addItems(m_console->client_list);
96    poolCombo->addItems(m_console->pool_list);
97    storageCombo->addItems(m_console->storage_list);
98    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
99    dateTimeEdit->setDateTime(dt.currentDateTime());
100    /*printf("listing messages resources");  ***FIME ***
101    foreach(QString mes, m_console->messages_list) {
102       printf("%s\n", mes.toUtf8().data());
103    }*/
104    messagesCombo->addItems(m_console->messages_list);
105    messagesCombo->setEnabled(false);
106    job_name_change(0);
107    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
108    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
109    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
110
111    // find a way to place the new window at the cursor position
112    // or in the midle of the page
113 //   dockPage();
114    setCurrent();
115 }
116
117 void runPage::okButtonPushed()
118 {
119    this->hide();
120    QString cmd;
121    QTextStream(&cmd) << "run" << 
122       " job=\"" << jobCombo->currentText() << "\"" <<
123       " fileset=\"" << filesetCombo->currentText() << "\"" <<
124       " level=\"" << levelCombo->currentText() << "\"" <<
125       " client=\"" << clientCombo->currentText() << "\"" <<
126       " pool=\"" << poolCombo->currentText() << "\"" <<
127       " storage=\"" << storageCombo->currentText() << "\"" <<
128       " priority=\"" << prioritySpin->value() << "\""
129       " when=\"" << dateTimeEdit->dateTime().toString(mainWin->m_dtformat) << "\"";
130 #ifdef xxx
131       " messages=\"" << messagesCombo->currentText() << "\"";
132      /* FIXME when there is an option to modify the messages resoruce associated
133       * with a  job */
134 #endif
135    if (bootstrap->text() != "") {
136       cmd += " bootstrap=\"" + bootstrap->text() + "\""; 
137    }
138    cmd += " yes";
139
140    if (mainWin->m_commandDebug) {
141       Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
142    }
143
144    consoleCommand(cmd);
145    m_console->notify(m_conn, true);
146    closeStackPage();
147    mainWin->resetFocus();
148 }
149
150
151 void runPage::cancelButtonPushed()
152 {
153    mainWin->set_status(tr(" Canceled"));
154    this->hide();
155    m_console->notify(m_conn, true);
156    closeStackPage();
157    mainWin->resetFocus();
158 }
159
160 /*
161  * Called here when the jobname combo box is changed.
162  *  We load the default values for the new job in the
163  *  other combo boxes.
164  */
165 void runPage::job_name_change(int index)
166 {
167    job_defaults job_defs;
168
169    (void)index;
170    job_defs.job_name = jobCombo->currentText();
171    if (m_console->get_job_defaults(job_defs)) {
172       typeLabel->setText("<H3>"+job_defs.type+"</H3>");
173       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
174       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
175       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
176       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
177       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
178       messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
179    }
180 }