]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/run/runcmd.cpp
Lots of icon work. Attempting using .svg files directory. It works in my
[bacula/bacula] / bacula / src / qt-console / run / runcmd.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2007 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 two of the GNU General Public
10    License as published by the Free Software Foundation plus additions
11    that are listed 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 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 John Walker.
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  *  $Id: $
41  */ 
42
43 #include "bat.h"
44 #include "run.h"
45
46 /*
47  * Setup all the combo boxes and display the dialog
48  */
49 runCmdPage::runCmdPage()
50 {
51    m_name = "Restore Run";
52    pgInitialize();
53    setupUi(this);
54    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
55    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
56    m_console->notify(false);
57
58    fill();
59    m_console->discardToPrompt();
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() << "never" << "always" << "ifnewer" << "ifolder");
78    replaceCombo->setCurrentIndex(replaceCombo->findText("never", Qt::MatchExactly));
79    storageCombo->addItems(m_console->storage_list);
80    dateTimeEdit->setDisplayFormat(mainWin->m_dtformat);
81
82    m_console->read();
83    item = m_console->msg();
84    items = item.split("\n");
85    label->setText(items[0]);
86    Dmsg1(200, "Title=%s\n", items[0].toUtf8().data());
87    items.removeFirst();               /* remove title */
88    foreach(item, items) {
89       rx.indexIn(item);
90       val = rx.cap(1);
91       Dmsg1(200, "Item=%s\n", item.toUtf8().data());
92       Dmsg1(200, "Value=%s\n", val.toUtf8().data());
93
94       if (item.startsWith("JobName:")) {
95          jobCombo->addItem(val);
96          continue;
97       }
98       if (item.startsWith("Bootstrap:")) {
99          bootstrap->setText(val);
100          continue;
101       }
102       if (item.startsWith("Backup Client:")) {
103          clientCombo->setCurrentIndex(clientCombo->findText(val, Qt::MatchExactly));
104          continue;
105       }
106       if (item.startsWith("Storage:")) {
107          storageCombo->setCurrentIndex(storageCombo->findText(val, Qt::MatchExactly));
108          continue;
109       }
110       if (item.startsWith("Where:")) {
111          where->setText(val);
112          continue;
113       }
114       if (item.startsWith("When:")) {
115          dateTimeEdit->setDateTime(QDateTime::fromString(val,mainWin->m_dtformat));
116          continue;
117       }
118       if (item.startsWith("Catalog:")) {
119          catalogCombo->addItem(val);
120          continue;
121       }
122       if (item.startsWith("FileSet:")) {
123          filesetCombo->setCurrentIndex(filesetCombo->findText(val, Qt::MatchExactly));
124          continue;
125       }
126       if (item.startsWith("Priority:")) {
127          bool okay;
128          int pri = val.toInt(&okay, 10);
129          if (okay) 
130             prioritySpin->setValue(pri);
131          continue;
132       }
133       if (item.startsWith("Replace:")) {
134          int replaceIndex = replaceCombo->findText(val, Qt::MatchExactly);
135          if (replaceIndex >= 0)
136             replaceCombo->setCurrentIndex(replaceIndex);
137          continue;
138       }
139    }
140 }
141
142 void runCmdPage::okButtonPushed()
143 {
144    QString cmd(".mod");
145    cmd += " restoreclient=\"" + clientCombo->currentText() + "\"";
146    cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
147    cmd += " storage=\"" + storageCombo->currentText() + "\"";
148    cmd += " replace=\"" + replaceCombo->currentText() + "\"";
149    cmd += " when=\"" + dateTimeEdit->dateTime().toString(mainWin->m_dtformat) + "\"";
150    cmd += " bootstrap=\"" + bootstrap->text() + "\"";
151    cmd += " where=\"" + where->text() + "\"";
152    QString pri;
153    QTextStream(&pri) << " priority=\"" << prioritySpin->value() << "\"";
154    cmd += pri;
155    cmd += " yes\n";
156    
157    setConsoleCurrent();
158    QString displayhtml("<font color=\"blue\">");
159    displayhtml += cmd + "</font>\n";
160    m_console->display_html(displayhtml);
161    m_console->display_text("\n");
162    m_console->write_dir(cmd.toUtf8().data());
163    m_console->displayToPrompt();
164 //   consoleCommand(cmd); ***FIXME set back to consoleCommand when connection issue is resolved
165
166    m_console->notify(true);
167    closeStackPage();
168 }
169
170
171 void runCmdPage::cancelButtonPushed()
172 {
173    m_console->displayToPrompt();
174    m_console->write_dir(".");
175    m_console->displayToPrompt();
176    mainWin->set_status(" Canceled");
177    this->hide();
178    m_console->notify(true);
179    closeStackPage();
180    mainWin->resetFocus();
181 }