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