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