]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/restore/prerestore.cpp
Add intelegence to prerestore. Radio buttons for select or all files. Radio
[bacula/bacula] / bacula / src / qt-console / restore / prerestore.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  *   Version $Id: restore.cpp 4307 2007-03-04 10:24:39Z kerns $
31  *
32  *  preRestore -> dialog put up to determine the restore type
33  *
34  *   Kern Sibbald, February MMVII
35  *
36  */ 
37
38 #include "bat.h"
39 #include "restore.h"
40
41
42 prerestorePage::prerestorePage()
43 {
44    m_dtformat = "yyyy-MM-dd HH:MM:ss";
45    m_name = "Pre-Restore";
46    setupUi(this);
47    pgInitialize();
48    m_console->notify(false);
49    m_closeable = true;
50
51    jobCombo->addItems(m_console->job_list);
52    filesetCombo->addItems(m_console->fileset_list);
53    clientCombo->addItems(m_console->client_list);
54    poolCombo->addItem("Any");
55    poolCombo->addItems(m_console->pool_list);
56    storageCombo->addItems(m_console->storage_list);
57    /* current or before . .  Start out with current checked */
58    recentCheckBox->setCheckState(Qt::Checked);
59    beforeDateTime->setDisplayFormat(m_dtformat);
60    beforeDateTime->setDateTime(QDateTime::currentDateTime());
61    beforeDateTime->setEnabled(false);
62    selectFilesRadio->setChecked(true);
63    selectJobsRadio->setChecked(true);
64    jobIdEdit->setText("Comma separted list of jobs id's");
65    jobIdEdit->setEnabled(false);
66    job_name_change(0);
67    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
68    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
69    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
70    connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
71    connect(selectJobsRadio, SIGNAL(toggled(bool)), this, SLOT(jobsRadioClicked(bool)));
72
73    dockPage();
74    setCurrent();
75    this->show();
76 }
77
78 void prerestorePage::okButtonPushed()
79 {
80    QString cmd;
81
82    this->hide();
83
84    cmd = QString("restore ");
85    if (selectFilesRadio->isChecked()) {
86       cmd += "select ";
87    } else {
88       cmd += "all done ";
89    }
90    cmd += "fileset=\"" + filesetCombo->currentText() + "\" ";
91    if (selectJobsRadio->isChecked()) {
92       cmd += "client=\"" + clientCombo->currentText() + "\" ";
93       if (poolCombo->currentText() != "Any" ){
94          cmd += "pool=\"" + poolCombo->currentText() + "\" ";
95       }
96       cmd += "storage=\"" + storageCombo->currentText() + "\" ";
97       if (recentCheckBox->checkState() == Qt::Checked) {
98          cmd += " current";
99       } else {
100          QDateTime stamp = beforeDateTime->dateTime();
101          QString before = stamp.toString(m_dtformat);
102          cmd += " before=\"" + before + "\"";
103       }
104    } else {
105       cmd += "jobid=\"" + jobIdEdit->text() + "\"";
106    }
107
108    /* ***FIXME*** */
109    //printf("preRestore command \'%s\'\n", cmd.toUtf8().data());
110    consoleCommand(cmd);
111    /* Note, do not turn notifier back on here ... */
112    if (selectFilesRadio->isChecked()) {
113       new restorePage();
114       closeStackPage();
115    } else {
116       m_console->notify(true);
117       closeStackPage();
118       mainWin->resetFocus();
119    }
120 }
121
122
123 void prerestorePage::cancelButtonPushed()
124 {
125    mainWin->set_status("Canceled");
126    this->hide();
127    m_console->notify(true);
128    closeStackPage();
129 }
130
131
132 void prerestorePage::job_name_change(int index)
133 {
134    job_defaults job_defs;
135
136    (void)index;
137    job_defs.job_name = jobCombo->currentText();
138    if (m_console->get_job_defaults(job_defs)) {
139       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
140       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
141       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
142       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
143    }
144 }
145
146 void prerestorePage::recentChanged(int state)
147 {
148    if ((state == Qt::Unchecked) && (selectJobsRadio->isChecked())) {
149       beforeDateTime->setEnabled(true);
150    } else {
151       beforeDateTime->setEnabled(false);
152    }
153 }
154
155 void prerestorePage::jobsRadioClicked(bool checked)
156 {
157    if (checked) {
158       printf("In prerestorePage::jobsRadioClicked checked\n");
159       jobCombo->setEnabled(true);
160 //      filesetCombo->setEnabled(true);
161       clientCombo->setEnabled(true);
162       poolCombo->setEnabled(true);
163       storageCombo->setEnabled(true);
164       recentCheckBox->setEnabled(true);
165       if (!recentCheckBox->isChecked()) {
166          beforeDateTime->setEnabled(true);
167       }
168       jobIdEdit->setEnabled(false);
169    } else {
170       printf("In prerestorePage::jobsRadioClicked UNchecked\n");
171       jobCombo->setEnabled(false);
172 //      filesetCombo->setEnabled(false);
173       clientCombo->setEnabled(false);
174       poolCombo->setEnabled(false);
175       storageCombo->setEnabled(false);
176       recentCheckBox->setEnabled(false);
177       beforeDateTime->setEnabled(false);
178       jobIdEdit->setEnabled(true);
179    }
180 }