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