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 if (selectFilesRadio->isChecked()) {
141 cmd += "fileset=\"" + filesetCombo->currentText() + "\" ";
142 cmd += "client=\"" + clientCombo->currentText() + "\" ";
143 if (selectJobsRadio->isChecked()) {
144 if (poolCombo->currentText() != "Any" ){
145 cmd += "pool=\"" + poolCombo->currentText() + "\" ";
147 cmd += "storage=\"" + storageCombo->currentText() + "\" ";
148 if (recentCheckBox->checkState() == Qt::Checked) {
151 QDateTime stamp = beforeDateTime->dateTime();
152 QString before = stamp.toString(m_dtformat);
153 cmd += " before=\"" + before + "\"";
156 cmd += "jobid=\"" + jobIdEdit->text() + "\"";
160 printf("preRestore command \'%s\'\n", cmd.toUtf8().data());
162 /* Note, do not turn notifier back on here ... */
163 if (selectFilesRadio->isChecked()) {
168 m_console->notify(true);
170 mainWin->resetFocus();
176 * Destroy the instace of the class
178 void prerestorePage::cancelButtonPushed()
180 mainWin->set_status("Canceled");
182 m_console->notify(true);
188 * Handle updating the other widget with job defaults when the job combo is changed.
190 void prerestorePage::job_name_change(int index)
192 job_defaults job_defs;
195 job_defs.job_name = jobCombo->currentText();
196 if (m_console->get_job_defaults(job_defs)) {
197 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
198 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
199 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
200 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
205 * Handle the change of enabled of input widgets when the recent checkbox state
208 void prerestorePage::recentChanged(int state)
210 if ((state == Qt::Unchecked) && (selectJobsRadio->isChecked())) {
211 beforeDateTime->setEnabled(true);
213 beforeDateTime->setEnabled(false);
218 * Handle the change of enabled of input widgets when the job radio buttons
221 void prerestorePage::jobsRadioClicked(bool checked)
224 jobCombo->setEnabled(true);
225 filesetCombo->setEnabled(true);
226 clientCombo->setEnabled(true);
227 poolCombo->setEnabled(true);
228 storageCombo->setEnabled(true);
229 recentCheckBox->setEnabled(true);
230 if (!recentCheckBox->isChecked()) {
231 beforeDateTime->setEnabled(true);
233 jobIdEdit->setEnabled(false);
235 jobCombo->setEnabled(false);
236 filesetCombo->setEnabled(false);
237 clientCombo->setEnabled(false);
238 poolCombo->setEnabled(false);
239 storageCombo->setEnabled(false);
240 recentCheckBox->setEnabled(false);
241 beforeDateTime->setEnabled(false);
242 jobIdEdit->setEnabled(true);
247 * For when jobs list is to be used, return a list which is the needed items from
250 void prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString jobId)
252 QString job, client, fileset;
254 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
255 " FileSet.FileSet AS FileSet, Job.Starttime AS JobStart"
256 " From Job, Client, FileSet"
257 " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
258 " AND JobId=\'" + jobId + "\'";
259 //printf("query = %s\n", query.toUtf8().data());
261 if (m_console->sql_cmd(query, results)) {
264 /* Iterate through the lines of results, there should only be one. */
265 foreach (QString resultline, results) {
266 fieldlist = resultline.split("\t");
267 } /* foreach resultline */
268 } /* if results from query */
272 * Function to handle when the jobidlist line edit input loses focus or is entered
274 void prerestorePage::jobIdEditFinished()
279 bool prerestorePage::checkJobIdList()
281 /* Need to check and make sure the text is a comma separated list of integers */
282 QString line = jobIdEdit->text();
283 if (line.contains(" ")) {
284 QMessageBox::warning(this, tr("Bat"),
285 tr("There can be no spaces in the text for the joblist.\n"
286 "Press OK to continue?"), QMessageBox::Ok );
289 QStringList joblist = line.split(",", QString::SkipEmptyParts);
290 bool allintokay = true, alljobok = true, allisjob = true;
291 QString jobName(""), clientName("");
292 foreach (QString job, joblist) {
294 job.toInt(&intok, 10);
296 /* are the intergers representing a list of jobs all with the same job
299 jobdefsFromJob(fields, job);
300 int count = fields.count();
304 else if (jobName != fields[0])
306 if (clientName == "")
307 clientName = fields[1];
308 else if (clientName != fields[1])
318 QMessageBox::warning(this, tr("Bat"),
319 tr("The string is not a comma separated list if integers.\n"
320 "Press OK to continue?"), QMessageBox::Ok );
324 QMessageBox::warning(this, tr("Bat"),
325 tr("At least one of the jobs is not a valid job.\n"
326 "Press OK to continue?"), QMessageBox::Ok );
330 QMessageBox::warning(this, tr("Bat"),
331 tr("All jobs in the list must be of the same jobName and same client.\n"
332 "Press OK to continue?"), QMessageBox::Ok );