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