]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/run.cpp
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / qt-console / run / run.cpp
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20  
21 /*
22  *  Run Dialog class
23  *
24  *   Kern Sibbald, February MMVII
25  *
26  */ 
27
28 #include "bat.h"
29 #include "run.h"
30
31
32 runPage::runPage() : Pages()
33 {
34    init();
35    show();
36 }
37
38 runPage::runPage(const QString &defJob) : Pages()
39 {
40    m_dockOnFirstUse = false;
41    init();
42    if (defJob != "")
43       jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
44    show();
45 }
46
47
48 runPage::runPage(const QString &defJob, const QString &level, 
49                  const QString &pool, const QString &storage,
50                  const QString &client, const QString &fileset)
51    : Pages()
52 {
53    m_dockOnFirstUse = false;
54    init();
55    jobCombo->setCurrentIndex(jobCombo->findText(defJob, Qt::MatchExactly));
56    job_name_change(0);
57    filesetCombo->setCurrentIndex(filesetCombo->findText(fileset,
58                                                         Qt::MatchExactly));
59    levelCombo->setCurrentIndex(levelCombo->findText(level, Qt::MatchExactly));
60    clientCombo->setCurrentIndex(clientCombo->findText(client,Qt::MatchExactly));
61    poolCombo->setCurrentIndex(poolCombo->findText(pool, Qt::MatchExactly));
62
63    if (storage != "") {         // TODO: enable storage
64       storageCombo->setCurrentIndex(storageCombo->findText(storage, 
65                                                            Qt::MatchExactly));
66    }
67    show();
68 }
69
70
71 /*
72  * Setup all the combo boxes and display the dialog
73  */
74 void runPage::init()
75 {
76    QDateTime dt;
77    QDesktopWidget *desk = QApplication::desktop(); 
78    QRect scrn;
79
80    m_name = tr("Run");
81    pgInitialize();
82    setupUi(this);
83    /* Get screen rectangle */
84    scrn = desk->screenGeometry(desk->primaryScreen());
85    /* Position this window in the middle of the screen */
86    this->move((scrn.width()-this->width())/2, (scrn.height()-this->height())/2);
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 middle 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       QString cmd;
173       typeLabel->setText("<H3>"+job_defs.type+"</H3>");
174       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
175       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
176       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
177       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
178       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
179       messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
180       m_console->level_list.clear();
181       cmd = ".levels " + job_defs.type;
182       m_console->dir_cmd(cmd, m_console->level_list);
183       levelCombo->clear();
184       levelCombo->addItems(m_console->level_list);
185       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, 0 /*Qt::MatchExactly*/));
186    }
187 }