2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
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.
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.
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
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.
30 * Version $Id: restore.cpp 4307 2007-03-04 10:24:39Z kerns $
32 * preRestore -> dialog put up to determine the restore type
34 * Kern Sibbald, February MMVII
41 /* Constructor to have job id list default in */
42 prerestorePage::prerestorePage(QString &data, unsigned int datatype)
45 m_dataInType = datatype;
49 /* Basic Constructor */
50 prerestorePage::prerestorePage()
53 m_dataInType = R_NONE;
58 * This is really the constructor
60 void prerestorePage::buildPage()
62 m_dtformat = "yyyy-MM-dd HH:mm:ss";
66 m_console->notify(false);
69 jobCombo->addItems(m_console->job_list);
70 filesetCombo->addItems(m_console->fileset_list);
71 clientCombo->addItems(m_console->client_list);
72 poolCombo->addItem("Any");
73 poolCombo->addItems(m_console->pool_list);
74 storageCombo->addItems(m_console->storage_list);
75 /* current or before . . Start out with current checked */
76 recentCheckBox->setCheckState(Qt::Checked);
77 beforeDateTime->setDisplayFormat(m_dtformat);
78 beforeDateTime->setDateTime(QDateTime::currentDateTime());
79 beforeDateTime->setEnabled(false);
80 selectFilesRadio->setChecked(true);
81 if (m_dataInType == R_NONE) {
82 selectJobsRadio->setChecked(true);
83 jobIdEdit->setText("Comma separted list of jobs id's");
84 jobIdEdit->setEnabled(false);
85 } else if (m_dataInType == R_JOBIDLIST) {
86 listJobsRadio->setChecked(true);
87 jobIdEdit->setText(m_dataIn);
88 jobsRadioClicked(false);
89 QStringList fieldlist;
90 jobdefsFromJob(fieldlist,m_dataIn);
91 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
92 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
93 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
94 } else if (m_dataInType == R_JOBDATETIME) {
95 selectJobsRadio->setChecked(true);
96 jobIdEdit->setText("Comma separted list of jobs id's");
97 jobIdEdit->setEnabled(false);
98 recentCheckBox->setCheckState(Qt::Unchecked);
99 jobsRadioClicked(true);
100 QStringList fieldlist;
101 jobdefsFromJob(fieldlist,m_dataIn);
102 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
103 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
104 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
105 beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], m_dtformat));
108 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
109 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
110 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
111 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
112 connect(selectJobsRadio, SIGNAL(toggled(bool)), this, SLOT(jobsRadioClicked(bool)));
113 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
122 * Check to make sure all is ok then start either the select window or the restore
125 void prerestorePage::okButtonPushed()
127 if (!selectJobsRadio->isChecked()) {
128 if (!checkJobIdList())
135 cmd = QString("restore");
136 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
137 cmd += " client=\"" + clientCombo->currentText() + "\"";
138 if (selectJobsRadio->isChecked()) {
139 if (poolCombo->currentText() != "Any" ){
140 cmd += " pool=\"" + poolCombo->currentText() + "\"";
142 cmd += " storage=\"" + storageCombo->currentText() + "\"";
143 if (recentCheckBox->checkState() == Qt::Checked) {
146 QDateTime stamp = beforeDateTime->dateTime();
147 QString before = stamp.toString(m_dtformat);
148 cmd += " before=\"" + before + "\"";
151 cmd += " jobid=\"" + jobIdEdit->text() + "\"";
153 if (selectFilesRadio->isChecked()) {
154 if (!listJobsRadio->isChecked())
161 printf("preRestore command \'%s\'\n", cmd.toUtf8().data());
163 /* Note, do not turn notifier back on here ... */
164 if (selectFilesRadio->isChecked()) {
169 m_console->notify(true);
171 mainWin->resetFocus();
177 * Destroy the instace of the class
179 void prerestorePage::cancelButtonPushed()
181 mainWin->set_status("Canceled");
183 m_console->notify(true);
189 * Handle updating the other widget with job defaults when the job combo is changed.
191 void prerestorePage::job_name_change(int index)
193 job_defaults job_defs;
196 job_defs.job_name = jobCombo->currentText();
197 if (m_console->get_job_defaults(job_defs)) {
198 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
199 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
200 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
201 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
206 * Handle the change of enabled of input widgets when the recent checkbox state
209 void prerestorePage::recentChanged(int state)
211 if ((state == Qt::Unchecked) && (selectJobsRadio->isChecked())) {
212 beforeDateTime->setEnabled(true);
214 beforeDateTime->setEnabled(false);
219 * Handle the change of enabled of input widgets when the job radio buttons
222 void prerestorePage::jobsRadioClicked(bool checked)
225 jobCombo->setEnabled(true);
226 filesetCombo->setEnabled(true);
227 clientCombo->setEnabled(true);
228 poolCombo->setEnabled(true);
229 storageCombo->setEnabled(true);
230 recentCheckBox->setEnabled(true);
231 if (!recentCheckBox->isChecked()) {
232 beforeDateTime->setEnabled(true);
234 jobIdEdit->setEnabled(false);
236 jobCombo->setEnabled(false);
237 filesetCombo->setEnabled(false);
238 clientCombo->setEnabled(false);
239 poolCombo->setEnabled(false);
240 storageCombo->setEnabled(false);
241 recentCheckBox->setEnabled(false);
242 beforeDateTime->setEnabled(false);
243 jobIdEdit->setEnabled(true);
248 * For when jobs list is to be used, return a list which is the needed items from
251 void prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString jobId)
253 QString job, client, fileset;
255 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
256 " FileSet.FileSet AS FileSet, Job.EndTime AS JobEnd"
257 " From Job, Client, FileSet"
258 " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
259 " AND JobId=\'" + jobId + "\'";
260 //printf("query = %s\n", query.toUtf8().data());
262 if (m_console->sql_cmd(query, results)) {
265 /* Iterate through the lines of results, there should only be one. */
266 foreach (QString resultline, results) {
267 fieldlist = resultline.split("\t");
268 } /* foreach resultline */
269 } /* if results from query */
273 * Function to handle when the jobidlist line edit input loses focus or is entered
275 void prerestorePage::jobIdEditFinished()
280 bool prerestorePage::checkJobIdList()
282 /* Need to check and make sure the text is a comma separated list of integers */
283 QString line = jobIdEdit->text();
284 if (line.contains(" ")) {
285 QMessageBox::warning(this, tr("Bat"),
286 tr("There can be no spaces in the text for the joblist.\n"
287 "Press OK to continue?"), QMessageBox::Ok );
290 QStringList joblist = line.split(",", QString::SkipEmptyParts);
291 bool allintokay = true, alljobok = true, allisjob = true;
292 QString jobName(""), clientName("");
293 foreach (QString job, joblist) {
295 job.toInt(&intok, 10);
297 /* are the intergers representing a list of jobs all with the same job
300 jobdefsFromJob(fields, job);
301 int count = fields.count();
305 else if (jobName != fields[0])
307 if (clientName == "")
308 clientName = fields[1];
309 else if (clientName != fields[1])
319 QMessageBox::warning(this, tr("Bat"),
320 tr("The string is not a comma separated list if integers.\n"
321 "Press OK to continue?"), QMessageBox::Ok );
325 QMessageBox::warning(this, tr("Bat"),
326 tr("At least one of the jobs is not a valid job.\n"
327 "Press OK to continue?"), QMessageBox::Ok );
331 QMessageBox::warning(this, tr("Bat"),
332 tr("All jobs in the list must be of the same jobName and same client.\n"
333 "Press OK to continue?"), QMessageBox::Ok );