]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/runcmd.cpp
Fix invalid .mod command in BAT during restore
[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
48    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
49    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
50    //dockPage();
51    setCurrent();
52    this->show();
53
54 }
55
56 void runCmdPage::fill()
57 {
58    QString item, val;
59    QStringList items;
60    QRegExp rx("^.*:\\s*(\\S.*$)");   /* Regex to get value */
61
62    clientCombo->addItems(m_console->client_list);
63    filesetCombo->addItems(m_console->fileset_list);
64    replaceCombo->addItems(QStringList() << tr("never") << tr("always") << tr("ifnewer")
65         << tr("ifolder"));
66    replaceCombo->setCurrentIndex(replaceCombo->findText(tr("never"), Qt::MatchExactly));
67    storageCombo->addItems(m_console->storage_list);
68    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
69
70    m_console->read(m_conn);
71    item = m_console->msg(m_conn);
72    items = item.split("\n");
73    foreach(item, items) {
74       rx.indexIn(item);
75       val = rx.cap(1);
76       Dmsg1(100, "Item=%s\n", item.toUtf8().data());
77       Dmsg1(100, "Value=%s\n", val.toUtf8().data());
78
79       if (item.startsWith("Title:")) {
80          run->setText(val);
81       }
82       if (item.startsWith("JobName:")) {
83          jobCombo->addItem(val);
84          continue;
85       }
86       if (item.startsWith("Bootstrap:")) {
87          bootstrap->setText(val);
88          continue;
89       }
90       if (item.startsWith("Backup Client:")) {
91          clientCombo->setCurrentIndex(clientCombo->findText(val, Qt::MatchExactly));
92          continue;
93       }
94       if (item.startsWith("Storage:")) {
95          storageCombo->setCurrentIndex(storageCombo->findText(val, Qt::MatchExactly));
96          continue;
97       }
98       if (item.startsWith("Where:")) {
99          where->setText(val);
100          continue;
101       }
102       if (item.startsWith("When:")) {
103          dateTimeEdit->setDateTime(QDateTime::fromString(val,mainWin->m_dtformat));
104          continue;
105       }
106       if (item.startsWith("Catalog:")) {
107          catalogCombo->addItem(val);
108          continue;
109       }
110       if (item.startsWith("FileSet:")) {
111          filesetCombo->setCurrentIndex(filesetCombo->findText(val, Qt::MatchExactly));
112          continue;
113       }
114       if (item.startsWith("Priority:")) {
115          bool okay;
116          int pri = val.toInt(&okay, 10);
117          if (okay)
118             prioritySpin->setValue(pri);
119          continue;
120       }
121       if (item.startsWith("Replace:")) {
122          int replaceIndex = replaceCombo->findText(val, Qt::MatchExactly);
123          if (replaceIndex >= 0)
124             replaceCombo->setCurrentIndex(replaceIndex);
125          continue;
126       }
127    }
128 }
129
130 void runCmdPage::okButtonPushed()
131 {
132    QString cmd(".mod");
133    cmd += " restoreclient=\"" + clientCombo->currentText() + "\"";
134    cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
135    cmd += " storage=\"" + storageCombo->currentText() + "\"";
136    cmd += " replace=\"" + replaceCombo->currentText() + "\"";
137    cmd += " when=\"" + dateTimeEdit->dateTime().toString(mainWin->m_dtformat) + "\"";
138    cmd += " bootstrap=\"" + bootstrap->text() + "\"";
139    cmd += " where=\"" + where->text() + "\"";
140    QString pri;
141    QTextStream(&pri) << " priority=\"" << prioritySpin->value() << "\"";
142    cmd += pri;
143    cmd += " yes\n";
144
145    setConsoleCurrent();
146    QString displayhtml("<font color=\"blue\">");
147    displayhtml += cmd + "</font>\n";
148    m_console->display_html(displayhtml);
149    m_console->display_text("\n");
150    m_console->write_dir(m_conn, cmd.toUtf8().data());
151    m_console->displayToPrompt(m_conn);
152 //   consoleCommand(cmd); ***FIXME set back to consoleCommand when connection issue is resolved
153
154    m_console->notify(m_conn, true);
155    closeStackPage();
156 }
157
158
159 void runCmdPage::cancelButtonPushed()
160 {
161    this->hide();
162    m_console->write_dir(m_conn, "no");
163    m_console->displayToPrompt(m_conn);
164    m_console->notify(m_conn, true);
165    mainWin->set_status(tr(" Canceled"));
166    closeStackPage();
167    mainWin->resetFocus();
168 }