]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/restore/prerestore.cpp
Should prevent a page from coming to the front that has not yet been populated
[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 = "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       setConsoleCurrent();
114       new restorePage();
115       closeStackPage();
116    } else {
117       m_console->notify(true);
118       closeStackPage();
119       mainWin->resetFocus();
120    }
121 }
122
123
124 void prerestorePage::cancelButtonPushed()
125 {
126    mainWin->set_status("Canceled");
127    this->hide();
128    m_console->notify(true);
129    closeStackPage();
130 }
131
132
133 void prerestorePage::job_name_change(int index)
134 {
135    job_defaults job_defs;
136
137    (void)index;
138    job_defs.job_name = jobCombo->currentText();
139    if (m_console->get_job_defaults(job_defs)) {
140       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
141       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
142       poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
143       storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
144    }
145 }
146
147 void prerestorePage::recentChanged(int state)
148 {
149    if ((state == Qt::Unchecked) && (selectJobsRadio->isChecked())) {
150       beforeDateTime->setEnabled(true);
151    } else {
152       beforeDateTime->setEnabled(false);
153    }
154 }
155
156 void prerestorePage::jobsRadioClicked(bool checked)
157 {
158    if (checked) {
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       jobCombo->setEnabled(false);
171 //      filesetCombo->setEnabled(false);
172       clientCombo->setEnabled(false);
173       poolCombo->setEnabled(false);
174       storageCombo->setEnabled(false);
175       recentCheckBox->setEnabled(false);
176       beforeDateTime->setEnabled(false);
177       jobIdEdit->setEnabled(true);
178    }
179 }