]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/runcmd.cpp
Turn off debug code
[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
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28  
29 /*
30  *  Run Command Dialog class
31  *
32  *  This is called when a Run Command signal is received from the
33  *    Director. We parse the Director's output and throw up a 
34  *    dialog box.  This happens, for example, after the user finishes
35  *    selecting files to be restored. The Director will then submit a
36  *    run command, that causes this page to be popped up.
37  *
38  *   Kern Sibbald, March MMVII
39  *
40  */ 
41
42 #include "bat.h"
43 #include "run.h"
44
45 /*
46  * Setup all the combo boxes and display the dialog
47  */
48 runCmdPage::runCmdPage(int conn)
49 {
50    m_name = tr("Restore Run");
51    pgInitialize();
52    setupUi(this);
53    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
54    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
55    m_conn = conn;
56    m_console->notify(conn, false);
57
58    fill();
59    m_console->discardToPrompt(m_conn);
60
61    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
62    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
63    //dockPage();
64    setCurrent();
65    this->show();
66
67 }
68
69 void runCmdPage::fill()
70 {
71    QString item, val;
72    QStringList items;
73    QRegExp rx("^.*:\\s*(\\S.*$)");   /* Regex to get value */
74
75    clientCombo->addItems(m_console->client_list);
76    filesetCombo->addItems(m_console->fileset_list);
77    replaceCombo->addItems(QStringList() << tr("never") << tr("always") << tr("ifnewer") 
78         << tr("ifolder"));
79    replaceCombo->setCurrentIndex(replaceCombo->findText(tr("never"), Qt::MatchExactly));
80    storageCombo->addItems(m_console->storage_list);
81    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
82
83    m_console->read(m_conn);
84    item = m_console->msg(m_conn);
85    items = item.split("\n");
86    foreach(item, items) {
87       rx.indexIn(item);
88       val = rx.cap(1);
89       Dmsg1(100, "Item=%s\n", item.toUtf8().data());
90       Dmsg1(100, "Value=%s\n", val.toUtf8().data());
91
92       if (item.startsWith("Title:")) {
93          run->setText(val);
94       }
95       if (item.startsWith("JobName:")) {
96          jobCombo->addItem(val);
97          continue;
98       }
99       if (item.startsWith("Bootstrap:")) {
100          bootstrap->setText(val);
101          continue;
102       }
103       if (item.startsWith("Backup Client:")) {
104          clientCombo->setCurrentIndex(clientCombo->findText(val, Qt::MatchExactly));
105          continue;
106       }
107       if (item.startsWith("Storage:")) {
108          storageCombo->setCurrentIndex(storageCombo->findText(val, Qt::MatchExactly));
109          continue;
110       }
111       if (item.startsWith("Where:")) {
112          where->setText(val);
113          continue;
114       }
115       if (item.startsWith("When:")) {
116          dateTimeEdit->setDateTime(QDateTime::fromString(val,mainWin->m_dtformat));
117          continue;
118       }
119       if (item.startsWith("Catalog:")) {
120          catalogCombo->addItem(val);
121          continue;
122       }
123       if (item.startsWith("FileSet:")) {
124          filesetCombo->setCurrentIndex(filesetCombo->findText(val, Qt::MatchExactly));
125          continue;
126       }
127       if (item.startsWith("Priority:")) {
128          bool okay;
129          int pri = val.toInt(&okay, 10);
130          if (okay) 
131             prioritySpin->setValue(pri);
132          continue;
133       }
134       if (item.startsWith("Replace:")) {
135          int replaceIndex = replaceCombo->findText(val, Qt::MatchExactly);
136          if (replaceIndex >= 0)
137             replaceCombo->setCurrentIndex(replaceIndex);
138          continue;
139       }
140    }
141 }
142
143 void runCmdPage::okButtonPushed()
144 {
145    QString cmd(".mod");
146    cmd += " restoreclient=\"" + clientCombo->currentText() + "\"";
147    cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
148    cmd += " storage=\"" + storageCombo->currentText() + "\"";
149    cmd += " replace=\"" + replaceCombo->currentText() + "\"";
150    cmd += " when=\"" + dateTimeEdit->dateTime().toString(mainWin->m_dtformat) + "\"";
151    cmd += " bootstrap=\"" + bootstrap->text() + "\"";
152    cmd += " where=\"" + where->text() + "\"";
153    QString pri;
154    QTextStream(&pri) << " priority=\"" << prioritySpin->value() << "\"";
155    cmd += pri;
156    cmd += " yes\n";
157    
158    setConsoleCurrent();
159    QString displayhtml("<font color=\"blue\">");
160    displayhtml += cmd + "</font>\n";
161    m_console->display_html(displayhtml);
162    m_console->display_text("\n");
163    m_console->write_dir(m_conn, cmd.toUtf8().data());
164    m_console->displayToPrompt(m_conn);
165 //   consoleCommand(cmd); ***FIXME set back to consoleCommand when connection issue is resolved
166
167    m_console->notify(m_conn, true);
168    closeStackPage();
169 }
170
171
172 void runCmdPage::cancelButtonPushed()
173 {
174    m_console->displayToPrompt(m_conn);
175    m_console->write_dir(".");
176    m_console->displayToPrompt(m_conn);
177    mainWin->set_status(tr(" Canceled"));
178    this->hide();
179    m_console->notify(m_conn, true);
180    closeStackPage();
181    mainWin->resetFocus();
182 }