]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/runcmd.cpp
e9369ca7fe6de143defe523970e7c73570e67baa
[bacula/bacula] / bacula / src / qt-console / run / runcmd.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from many
7    others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    Bacula® is a registered trademark of Kern Sibbald.
15 */
16
17 /*
18  *  Run Command Dialog class
19  *
20  *  This is called when a Run Command signal is received from the
21  *    Director. We parse the Director's output and throw up a
22  *    dialog box.  This happens, for example, after the user finishes
23  *    selecting files to be restored. The Director will then submit a
24  *    run command, that causes this page to be popped up.
25  *
26  *   Kern Sibbald, March MMVII
27  *
28  */
29
30 #include "bat.h"
31 #include "run.h"
32
33 /*
34  * Setup all the combo boxes and display the dialog
35  */
36 runCmdPage::runCmdPage(int conn) : Pages()
37 {
38    m_name = tr("Restore Run");
39    pgInitialize();
40    setupUi(this);
41    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
42    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
43    m_conn = conn;
44    m_console->notify(conn, false);
45
46    fill();
47    m_console->discardToPrompt(m_conn);
48
49    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
50    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
51    //dockPage();
52    setCurrent();
53    this->show();
54
55 }
56
57 void runCmdPage::fill()
58 {
59    QString item, val;
60    QStringList items;
61    QRegExp rx("^.*:\\s*(\\S.*$)");   /* Regex to get value */
62
63    clientCombo->addItems(m_console->client_list);
64    filesetCombo->addItems(m_console->fileset_list);
65    replaceCombo->addItems(QStringList() << tr("never") << tr("always") << tr("ifnewer")
66         << tr("ifolder"));
67    replaceCombo->setCurrentIndex(replaceCombo->findText(tr("never"), Qt::MatchExactly));
68    storageCombo->addItems(m_console->storage_list);
69    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
70
71    m_console->read(m_conn);
72    item = m_console->msg(m_conn);
73    items = item.split("\n");
74    foreach(item, items) {
75       rx.indexIn(item);
76       val = rx.cap(1);
77       Dmsg1(100, "Item=%s\n", item.toUtf8().data());
78       Dmsg1(100, "Value=%s\n", val.toUtf8().data());
79
80       if (item.startsWith("Title:")) {
81          run->setText(val);
82       }
83       if (item.startsWith("JobName:")) {
84          jobCombo->addItem(val);
85          continue;
86       }
87       if (item.startsWith("Bootstrap:")) {
88          bootstrap->setText(val);
89          continue;
90       }
91       if (item.startsWith("Backup Client:")) {
92          clientCombo->setCurrentIndex(clientCombo->findText(val, Qt::MatchExactly));
93          continue;
94       }
95       if (item.startsWith("Storage:")) {
96          storageCombo->setCurrentIndex(storageCombo->findText(val, Qt::MatchExactly));
97          continue;
98       }
99       if (item.startsWith("Where:")) {
100          where->setText(val);
101          continue;
102       }
103       if (item.startsWith("When:")) {
104          dateTimeEdit->setDateTime(QDateTime::fromString(val,mainWin->m_dtformat));
105          continue;
106       }
107       if (item.startsWith("Catalog:")) {
108          catalogCombo->addItem(val);
109          continue;
110       }
111       if (item.startsWith("FileSet:")) {
112          filesetCombo->setCurrentIndex(filesetCombo->findText(val, Qt::MatchExactly));
113          continue;
114       }
115       if (item.startsWith("Priority:")) {
116          bool okay;
117          int pri = val.toInt(&okay, 10);
118          if (okay)
119             prioritySpin->setValue(pri);
120          continue;
121       }
122       if (item.startsWith("Replace:")) {
123          int replaceIndex = replaceCombo->findText(val, Qt::MatchExactly);
124          if (replaceIndex >= 0)
125             replaceCombo->setCurrentIndex(replaceIndex);
126          continue;
127       }
128    }
129 }
130
131 void runCmdPage::okButtonPushed()
132 {
133    QString cmd(".mod");
134    cmd += " restoreclient=\"" + clientCombo->currentText() + "\"";
135    cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
136    cmd += " storage=\"" + storageCombo->currentText() + "\"";
137    cmd += " replace=\"" + replaceCombo->currentText() + "\"";
138    cmd += " when=\"" + dateTimeEdit->dateTime().toString(mainWin->m_dtformat) + "\"";
139    cmd += " bootstrap=\"" + bootstrap->text() + "\"";
140    cmd += " where=\"" + where->text() + "\"";
141    QString pri;
142    QTextStream(&pri) << " priority=\"" << prioritySpin->value() << "\"";
143    cmd += pri;
144    cmd += " yes\n";
145
146    setConsoleCurrent();
147    QString displayhtml("<font color=\"blue\">");
148    displayhtml += cmd + "</font>\n";
149    m_console->display_html(displayhtml);
150    m_console->display_text("\n");
151    m_console->write_dir(m_conn, cmd.toUtf8().data());
152    m_console->displayToPrompt(m_conn);
153 //   consoleCommand(cmd); ***FIXME set back to consoleCommand when connection issue is resolved
154
155    m_console->notify(m_conn, true);
156    closeStackPage();
157 }
158
159
160 void runCmdPage::cancelButtonPushed()
161 {
162    m_console->displayToPrompt(m_conn);
163    m_console->write_dir(".");
164    m_console->displayToPrompt(m_conn);
165    mainWin->set_status(tr(" Canceled"));
166    this->hide();
167    m_console->notify(m_conn, true);
168    closeStackPage();
169    mainWin->resetFocus();
170 }