]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/run.cpp
update configure
[bacula/bacula] / bacula / src / qt-console / run / run.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2011 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  */ 
35
36 #include "bat.h"
37 #include "run.h"
38
39
40 runPage::runPage() : Pages()
41 {
42    init();
43    show();
44 }
45
46 runPage::runPage(const QString &defJob) : Pages()
47 {
48    m_dockOnFirstUse = false;
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    : Pages()
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    QDesktopWidget *desk = QApplication::desktop(); 
86    QRect scrn;
87
88    m_name = tr("Run");
89    pgInitialize();
90    setupUi(this);
91    /* Get screen rectangle */
92    scrn = desk->screenGeometry(desk->primaryScreen());
93    /* Position this window in the middle of the screen */
94    this->move((scrn.width()-this->width())/2, (scrn.height()-this->height())/2);
95    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
96    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/run.png")));
97    m_conn = m_console->notifyOff();
98
99    m_console->beginNewCommand(m_conn);
100    jobCombo->addItems(m_console->job_list);
101    filesetCombo->addItems(m_console->fileset_list);
102    levelCombo->addItems(m_console->level_list);
103    clientCombo->addItems(m_console->client_list);
104    poolCombo->addItems(m_console->pool_list);
105    storageCombo->addItems(m_console->storage_list);
106    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
107    dateTimeEdit->setDateTime(dt.currentDateTime());
108    /*printf("listing messages resources");  ***FIME ***
109    foreach(QString mes, m_console->messages_list) {
110       printf("%s\n", mes.toUtf8().data());
111    }*/
112    messagesCombo->addItems(m_console->messages_list);
113    messagesCombo->setEnabled(false);
114    job_name_change(0);
115    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
116    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
117    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
118
119    // find a way to place the new window at the cursor position
120    // or in the middle of the page
121 //   dockPage();
122    setCurrent();
123 }
124
125 void runPage::okButtonPushed()
126 {
127    this->hide();
128    QString cmd;
129    QTextStream(&cmd) << "run" << 
130       " job=\"" << jobCombo->currentText() << "\"" <<
131       " fileset=\"" << filesetCombo->currentText() << "\"" <<
132       " level=\"" << levelCombo->currentText() << "\"" <<
133       " client=\"" << clientCombo->currentText() << "\"" <<
134       " pool=\"" << poolCombo->currentText() << "\"" <<
135       " storage=\"" << storageCombo->currentText() << "\"" <<
136       " priority=\"" << prioritySpin->value() << "\""
137       " when=\"" << dateTimeEdit->dateTime().toString(mainWin->m_dtformat) << "\"";
138 #ifdef xxx
139       " messages=\"" << messagesCombo->currentText() << "\"";
140      /* FIXME when there is an option to modify the messages resoruce associated
141       * with a  job */
142 #endif
143    if (bootstrap->text() != "") {
144       cmd += " bootstrap=\"" + bootstrap->text() + "\""; 
145    }
146    cmd += " yes";
147
148    if (mainWin->m_commandDebug) {
149       Pmsg1(000, "command : %s\n", cmd.toUtf8().data());
150    }
151
152    consoleCommand(cmd);
153    m_console->notify(m_conn, true);
154    closeStackPage();
155    mainWin->resetFocus();
156 }
157
158
159 void runPage::cancelButtonPushed()
160 {
161    mainWin->set_status(tr(" Canceled"));
162    this->hide();
163    m_console->notify(m_conn, true);
164    closeStackPage();
165    mainWin->resetFocus();
166 }
167
168 /*
169  * Called here when the jobname combo box is changed.
170  *  We load the default values for the new job in the
171  *  other combo boxes.
172  */
173 void runPage::job_name_change(int index)
174 {
175    job_defaults job_defs;
176
177    (void)index;
178    job_defs.job_name = jobCombo->currentText();
179    if (m_console->get_job_defaults(job_defs)) {
180       QString cmd;
181       typeLabel->setText("<H3>"+job_defs.type+"</H3>");
182       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
183       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
184       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
185       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
186       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
187       messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
188       m_console->level_list.clear();
189       cmd = ".levels " + job_defs.type;
190       m_console->dir_cmd(cmd, m_console->level_list);
191       levelCombo->clear();
192       levelCombo->addItems(m_console->level_list);
193       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, 0 /*Qt::MatchExactly*/));
194    }
195 }