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