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 selectJobRadio->setChecked(true);
83 selectJobIdsRadio->setChecked(false);
84 jobIdEdit->setText("Comma separted list of jobs id's");
85 jobIdEdit->setEnabled(false);
86 } else if (m_dataInType == R_JOBIDLIST) {
87 selectJobIdsRadio->setChecked(true);
88 selectJobRadio->setChecked(false);
89 jobIdEdit->setText(m_dataIn);
90 jobRadioClicked(false);
91 QStringList fieldlist;
92 jobdefsFromJob(fieldlist,m_dataIn);
93 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
94 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
95 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
96 } else if (m_dataInType == R_JOBDATETIME) {
97 selectJobRadio->setChecked(true);
98 selectJobIdsRadio->setChecked(false);
99 jobIdEdit->setText("Comma separted list of jobs id's");
100 jobIdEdit->setEnabled(false);
101 recentCheckBox->setCheckState(Qt::Unchecked);
102 jobRadioClicked(true);
103 QStringList fieldlist;
104 jobdefsFromJob(fieldlist,m_dataIn);
105 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
106 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
107 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
108 beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], m_dtformat));
111 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
112 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
113 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
114 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
115 connect(selectJobRadio, SIGNAL(clicked(bool)), this, SLOT(jobRadioClicked(bool)));
116 connect(selectJobIdsRadio, SIGNAL(clicked(bool)), this, SLOT(jobidsRadioClicked(bool)));
117 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
126 * Check to make sure all is ok then start either the select window or the restore
129 void prerestorePage::okButtonPushed()
131 if (!selectJobRadio->isChecked()) {
132 if (!checkJobIdList())
139 cmd = QString("restore");
140 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
141 cmd += " client=\"" + clientCombo->currentText() + "\"";
142 if (selectJobRadio->isChecked()) {
143 if (poolCombo->currentText() != "Any" ){
144 cmd += " pool=\"" + poolCombo->currentText() + "\"";
146 cmd += " storage=\"" + storageCombo->currentText() + "\"";
147 if (recentCheckBox->checkState() == Qt::Checked) {
150 QDateTime stamp = beforeDateTime->dateTime();
151 QString before = stamp.toString(m_dtformat);
152 cmd += " before=\"" + before + "\"";
155 cmd += " jobid=\"" + jobIdEdit->text() + "\"";
157 if (selectFilesRadio->isChecked()) {
158 if (!selectJobIdsRadio->isChecked())
165 printf("preRestore command \'%s\'\n", cmd.toUtf8().data());
167 /* Note, do not turn notifier back on here ... */
168 if (selectFilesRadio->isChecked()) {
173 m_console->notify(true);
175 mainWin->resetFocus();
181 * Destroy the instace of the class
183 void prerestorePage::cancelButtonPushed()
185 mainWin->set_status("Canceled");
187 m_console->notify(true);
193 * Handle updating the other widget with job defaults when the job combo is changed.
195 void prerestorePage::job_name_change(int index)
197 job_defaults job_defs;
200 job_defs.job_name = jobCombo->currentText();
201 if (m_console->get_job_defaults(job_defs)) {
202 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
203 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
204 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
205 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
210 * Handle the change of enabled of input widgets when the recent checkbox state
213 void prerestorePage::recentChanged(int state)
215 if ((state == Qt::Unchecked) && (selectJobRadio->isChecked())) {
216 beforeDateTime->setEnabled(true);
218 beforeDateTime->setEnabled(false);
224 * For when jobs list is to be used, return a list which is the needed items from
227 void prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString jobId)
229 QString job, client, fileset;
231 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
232 " FileSet.FileSet AS FileSet, Job.EndTime AS JobEnd"
233 " From Job, Client, FileSet"
234 " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
235 " AND JobId=\'" + jobId + "\'";
236 //printf("query = %s\n", query.toUtf8().data());
238 if (m_console->sql_cmd(query, results)) {
241 /* Iterate through the lines of results, there should only be one. */
242 foreach (QString resultline, results) {
243 fieldlist = resultline.split("\t");
244 } /* foreach resultline */
245 } /* if results from query */
249 * Function to handle when the jobidlist line edit input loses focus or is entered
251 void prerestorePage::jobIdEditFinished()
256 bool prerestorePage::checkJobIdList()
258 /* Need to check and make sure the text is a comma separated list of integers */
259 QString line = jobIdEdit->text();
260 if (line.contains(" ")) {
261 QMessageBox::warning(this, tr("Bat"),
262 tr("There can be no spaces in the text for the joblist.\n"
263 "Press OK to continue?"), QMessageBox::Ok );
266 QStringList joblist = line.split(",", QString::SkipEmptyParts);
267 bool allintokay = true, alljobok = true, allisjob = true;
268 QString jobName(""), clientName("");
269 foreach (QString job, joblist) {
271 job.toInt(&intok, 10);
273 /* are the intergers representing a list of jobs all with the same job
276 jobdefsFromJob(fields, job);
277 int count = fields.count();
281 else if (jobName != fields[0])
283 if (clientName == "")
284 clientName = fields[1];
285 else if (clientName != fields[1])
295 QMessageBox::warning(this, tr("Bat"),
296 tr("The string is not a comma separated list if integers.\n"
297 "Press OK to continue?"), QMessageBox::Ok );
301 QMessageBox::warning(this, tr("Bat"),
302 tr("At least one of the jobs is not a valid job.\n"
303 "Press OK to continue?"), QMessageBox::Ok );
307 QMessageBox::warning(this, tr("Bat"),
308 tr("All jobs in the list must be of the same jobName and same client.\n"
309 "Press OK to continue?"), QMessageBox::Ok );
316 * Handle the change of enabled of input widgets when the job radio buttons
319 void prerestorePage::jobRadioClicked(bool checked)
322 jobCombo->setEnabled(true);
323 filesetCombo->setEnabled(true);
324 clientCombo->setEnabled(true);
325 poolCombo->setEnabled(true);
326 storageCombo->setEnabled(true);
327 recentCheckBox->setEnabled(true);
328 if (!recentCheckBox->isChecked()) {
329 beforeDateTime->setEnabled(true);
331 jobIdEdit->setEnabled(false);
332 selectJobRadio->setChecked(true);
333 selectJobIdsRadio->setChecked(false);
335 jobCombo->setEnabled(false);
336 filesetCombo->setEnabled(false);
337 clientCombo->setEnabled(false);
338 poolCombo->setEnabled(false);
339 storageCombo->setEnabled(false);
340 recentCheckBox->setEnabled(false);
341 beforeDateTime->setEnabled(false);
342 jobIdEdit->setEnabled(true);
343 selectJobRadio->setChecked(false);
344 selectJobIdsRadio->setChecked(true);
346 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
347 selectJobIdsRadio->isChecked());
350 void prerestorePage::jobidsRadioClicked(bool checked)
353 jobCombo->setEnabled(false);
354 filesetCombo->setEnabled(false);
355 clientCombo->setEnabled(false);
356 poolCombo->setEnabled(false);
357 storageCombo->setEnabled(false);
358 recentCheckBox->setEnabled(false);
359 beforeDateTime->setEnabled(false);
360 jobIdEdit->setEnabled(true);
361 selectJobRadio->setChecked(false);
362 selectJobIdsRadio->setChecked(true);
364 jobCombo->setEnabled(true);
365 filesetCombo->setEnabled(true);
366 clientCombo->setEnabled(true);
367 poolCombo->setEnabled(true);
368 storageCombo->setEnabled(true);
369 recentCheckBox->setEnabled(true);
370 if (!recentCheckBox->isChecked()) {
371 beforeDateTime->setEnabled(true);
373 jobIdEdit->setEnabled(false);
374 selectJobRadio->setChecked(true);
375 selectJobIdsRadio->setChecked(false);
377 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
378 selectJobIdsRadio->isChecked());