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 if (!m_console->preventInUseConnect())
72 jobCombo->addItems(m_console->job_list);
73 filesetCombo->addItems(m_console->fileset_list);
74 clientCombo->addItems(m_console->client_list);
75 poolCombo->addItem("Any");
76 poolCombo->addItems(m_console->pool_list);
77 storageCombo->addItems(m_console->storage_list);
78 /* current or before . . Start out with current checked */
79 recentCheckBox->setCheckState(Qt::Checked);
80 beforeDateTime->setDisplayFormat(m_dtformat);
81 beforeDateTime->setDateTime(QDateTime::currentDateTime());
82 beforeDateTime->setEnabled(false);
83 selectFilesRadio->setChecked(true);
84 if (m_dataInType == R_NONE) {
85 selectJobRadio->setChecked(true);
86 selectJobIdsRadio->setChecked(false);
87 jobIdEdit->setText("Comma separted list of jobs id's");
88 jobIdEdit->setEnabled(false);
89 } else if (m_dataInType == R_JOBIDLIST) {
90 selectJobIdsRadio->setChecked(true);
91 selectJobRadio->setChecked(false);
92 jobIdEdit->setText(m_dataIn);
93 jobRadioClicked(false);
94 QStringList fieldlist;
95 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
96 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
97 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
98 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
100 } else if (m_dataInType == R_JOBDATETIME) {
101 selectJobRadio->setChecked(true);
102 selectJobIdsRadio->setChecked(false);
103 jobIdEdit->setText("Comma separted list of jobs id's");
104 jobIdEdit->setEnabled(false);
105 recentCheckBox->setCheckState(Qt::Unchecked);
106 jobRadioClicked(true);
107 QStringList fieldlist;
108 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
109 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
110 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
111 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
112 beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], m_dtformat));
116 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
117 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
118 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
119 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
120 connect(selectJobRadio, SIGNAL(clicked(bool)), this, SLOT(jobRadioClicked(bool)));
121 connect(selectJobIdsRadio, SIGNAL(clicked(bool)), this, SLOT(jobidsRadioClicked(bool)));
122 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
131 * Check to make sure all is ok then start either the select window or the restore
134 void prerestorePage::okButtonPushed()
136 if (!selectJobRadio->isChecked()) {
137 if (!checkJobIdList())
144 cmd = QString("restore");
145 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
146 cmd += " client=\"" + clientCombo->currentText() + "\"";
147 if (selectJobRadio->isChecked()) {
148 if (poolCombo->currentText() != "Any" ){
149 cmd += " pool=\"" + poolCombo->currentText() + "\"";
151 cmd += " storage=\"" + storageCombo->currentText() + "\"";
152 if (recentCheckBox->checkState() == Qt::Checked) {
155 QDateTime stamp = beforeDateTime->dateTime();
156 QString before = stamp.toString(m_dtformat);
157 cmd += " before=\"" + before + "\"";
160 cmd += " jobid=\"" + jobIdEdit->text() + "\"";
162 if (selectFilesRadio->isChecked()) {
163 if (!selectJobIdsRadio->isChecked())
169 if (mainWin->m_commandDebug) {
170 Pmsg1(000, "preRestore command \'%s\'\n", cmd.toUtf8().data());
173 /* Note, do not turn notifier back on here ... */
174 if (selectFilesRadio->isChecked()) {
179 m_console->notify(true);
181 mainWin->resetFocus();
187 * Destroy the instace of the class
189 void prerestorePage::cancelButtonPushed()
191 mainWin->set_status("Canceled");
193 m_console->notify(true);
199 * Handle updating the other widget with job defaults when the job combo is changed.
201 void prerestorePage::job_name_change(int index)
203 job_defaults job_defs;
206 job_defs.job_name = jobCombo->currentText();
207 if (m_console->get_job_defaults(job_defs)) {
208 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
209 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
210 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
211 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
216 * Handle the change of enabled of input widgets when the recent checkbox state
219 void prerestorePage::recentChanged(int state)
221 if ((state == Qt::Unchecked) && (selectJobRadio->isChecked())) {
222 beforeDateTime->setEnabled(true);
224 beforeDateTime->setEnabled(false);
230 * For when jobs list is to be used, return a list which is the needed items from
233 int prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString &jobId)
235 QString job, client, fileset;
237 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
238 " FileSet.FileSet AS FileSet, Job.EndTime AS JobEnd,"
239 " Job.Type AS JobType"
240 " From Job, Client, FileSet"
241 " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
242 " AND JobId=\'" + jobId + "\'";
243 if (mainWin->m_sqlDebug) { Pmsg1(000, "query = %s\n", query.toUtf8().data()); }
245 if (m_console->sql_cmd(query, results)) {
248 /* Iterate through the lines of results, there should only be one. */
249 foreach (QString resultline, results) {
250 fieldlist = resultline.split("\t");
251 } /* foreach resultline */
252 } /* if results from query */
253 return results.count();
257 * Function to handle when the jobidlist line edit input loses focus or is entered
259 void prerestorePage::jobIdEditFinished()
264 bool prerestorePage::checkJobIdList()
266 /* Need to check and make sure the text is a comma separated list of integers */
267 QString line = jobIdEdit->text();
268 if (line.contains(" ")) {
269 QMessageBox::warning(this, tr("Bat"),
270 tr("There can be no spaces in the text for the joblist.\n"
271 "Press OK to continue?"), QMessageBox::Ok );
274 QStringList joblist = line.split(",", QString::SkipEmptyParts);
275 bool allintokay = true, alljobok = true, allisjob = true;
276 QString jobName(""), clientName("");
277 foreach (QString job, joblist) {
279 job.toInt(&intok, 10);
281 /* are the intergers representing a list of jobs all with the same job
284 if (jobdefsFromJob(fields, job) == 1) {
287 else if (jobName != fields[0])
289 if (clientName == "")
290 clientName = fields[1];
291 else if (clientName != fields[1])
301 QMessageBox::warning(this, tr("Bat"),
302 tr("The string is not a comma separated list if integers.\n"
303 "Press OK to continue?"), QMessageBox::Ok );
307 QMessageBox::warning(this, tr("Bat"),
308 tr("At least one of the jobs is not a valid job of type \"Backup\".\n"
309 "Press OK to continue?"), QMessageBox::Ok );
313 QMessageBox::warning(this, tr("Bat"),
314 tr("All jobs in the list must be of the same jobName and same client.\n"
315 "Press OK to continue?"), QMessageBox::Ok );
322 * Handle the change of enabled of input widgets when the job radio buttons
325 void prerestorePage::jobRadioClicked(bool checked)
328 jobCombo->setEnabled(true);
329 filesetCombo->setEnabled(true);
330 clientCombo->setEnabled(true);
331 poolCombo->setEnabled(true);
332 storageCombo->setEnabled(true);
333 recentCheckBox->setEnabled(true);
334 if (!recentCheckBox->isChecked()) {
335 beforeDateTime->setEnabled(true);
337 jobIdEdit->setEnabled(false);
338 selectJobRadio->setChecked(true);
339 selectJobIdsRadio->setChecked(false);
341 jobCombo->setEnabled(false);
342 filesetCombo->setEnabled(false);
343 clientCombo->setEnabled(false);
344 poolCombo->setEnabled(false);
345 storageCombo->setEnabled(false);
346 recentCheckBox->setEnabled(false);
347 beforeDateTime->setEnabled(false);
348 jobIdEdit->setEnabled(true);
349 selectJobRadio->setChecked(false);
350 selectJobIdsRadio->setChecked(true);
352 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
353 selectJobIdsRadio->isChecked());
356 void prerestorePage::jobidsRadioClicked(bool checked)
359 jobCombo->setEnabled(false);
360 filesetCombo->setEnabled(false);
361 clientCombo->setEnabled(false);
362 poolCombo->setEnabled(false);
363 storageCombo->setEnabled(false);
364 recentCheckBox->setEnabled(false);
365 beforeDateTime->setEnabled(false);
366 jobIdEdit->setEnabled(true);
367 selectJobRadio->setChecked(false);
368 selectJobIdsRadio->setChecked(true);
370 jobCombo->setEnabled(true);
371 filesetCombo->setEnabled(true);
372 clientCombo->setEnabled(true);
373 poolCombo->setEnabled(true);
374 storageCombo->setEnabled(true);
375 recentCheckBox->setEnabled(true);
376 if (!recentCheckBox->isChecked()) {
377 beforeDateTime->setEnabled(true);
379 jobIdEdit->setEnabled(false);
380 selectJobRadio->setChecked(true);
381 selectJobIdsRadio->setChecked(false);
383 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
384 selectJobIdsRadio->isChecked());