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 &jobIdString)
44 m_jobIdListIn = jobIdString;
48 /* Basic Constructor */
49 prerestorePage::prerestorePage()
56 * This is really the constructor
58 void prerestorePage::buildPage()
60 m_dtformat = "yyyy-MM-dd HH:MM:ss";
64 m_console->notify(false);
67 jobCombo->addItems(m_console->job_list);
68 filesetCombo->addItems(m_console->fileset_list);
69 clientCombo->addItems(m_console->client_list);
70 poolCombo->addItem("Any");
71 poolCombo->addItems(m_console->pool_list);
72 storageCombo->addItems(m_console->storage_list);
73 /* current or before . . Start out with current checked */
74 recentCheckBox->setCheckState(Qt::Checked);
75 beforeDateTime->setDisplayFormat(m_dtformat);
76 beforeDateTime->setDateTime(QDateTime::currentDateTime());
77 beforeDateTime->setEnabled(false);
78 selectFilesRadio->setChecked(true);
79 if (m_jobIdListIn == "") {
80 selectJobsRadio->setChecked(true);
81 jobIdEdit->setText("Comma separted list of jobs id's");
82 jobIdEdit->setEnabled(false);
84 listJobsRadio->setChecked(true);
85 jobIdEdit->setText(m_jobIdListIn);
86 jobsRadioClicked(false);
87 QStringList fieldlist;
88 jobdefsFromJob(fieldlist,m_jobIdListIn);
89 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
90 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
91 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
94 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
95 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
96 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
97 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
98 connect(selectJobsRadio, SIGNAL(toggled(bool)), this, SLOT(jobsRadioClicked(bool)));
99 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
108 * Check to make sure all is ok then start either the select window or the restore
111 void prerestorePage::okButtonPushed()
113 if (!selectJobsRadio->isChecked()) {
114 if (!checkJobIdList())
121 cmd = QString("restore ");
122 if (selectFilesRadio->isChecked()) {
127 cmd += "fileset=\"" + filesetCombo->currentText() + "\" ";
128 cmd += "client=\"" + clientCombo->currentText() + "\" ";
129 if (selectJobsRadio->isChecked()) {
130 if (poolCombo->currentText() != "Any" ){
131 cmd += "pool=\"" + poolCombo->currentText() + "\" ";
133 cmd += "storage=\"" + storageCombo->currentText() + "\" ";
134 if (recentCheckBox->checkState() == Qt::Checked) {
137 QDateTime stamp = beforeDateTime->dateTime();
138 QString before = stamp.toString(m_dtformat);
139 cmd += " before=\"" + before + "\"";
142 cmd += "jobid=\"" + jobIdEdit->text() + "\"";
146 //printf("preRestore command \'%s\'\n", cmd.toUtf8().data());
148 /* Note, do not turn notifier back on here ... */
149 if (selectFilesRadio->isChecked()) {
154 m_console->notify(true);
156 mainWin->resetFocus();
162 * Destroy the instace of the class
164 void prerestorePage::cancelButtonPushed()
166 mainWin->set_status("Canceled");
168 m_console->notify(true);
174 * Handle updating the other widget with job defaults when the job combo is changed.
176 void prerestorePage::job_name_change(int index)
178 job_defaults job_defs;
181 job_defs.job_name = jobCombo->currentText();
182 if (m_console->get_job_defaults(job_defs)) {
183 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
184 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
185 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
186 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
191 * Handle the change of enabled of input widgets when the recent checkbox state
194 void prerestorePage::recentChanged(int state)
196 if ((state == Qt::Unchecked) && (selectJobsRadio->isChecked())) {
197 beforeDateTime->setEnabled(true);
199 beforeDateTime->setEnabled(false);
204 * Handle the change of enabled of input widgets when the job radio buttons
207 void prerestorePage::jobsRadioClicked(bool checked)
210 jobCombo->setEnabled(true);
211 filesetCombo->setEnabled(true);
212 clientCombo->setEnabled(true);
213 poolCombo->setEnabled(true);
214 storageCombo->setEnabled(true);
215 recentCheckBox->setEnabled(true);
216 if (!recentCheckBox->isChecked()) {
217 beforeDateTime->setEnabled(true);
219 jobIdEdit->setEnabled(false);
221 jobCombo->setEnabled(false);
222 filesetCombo->setEnabled(false);
223 clientCombo->setEnabled(false);
224 poolCombo->setEnabled(false);
225 storageCombo->setEnabled(false);
226 recentCheckBox->setEnabled(false);
227 beforeDateTime->setEnabled(false);
228 jobIdEdit->setEnabled(true);
233 * For when jobs list is to be used, return a list which is the needed items from
236 void prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString jobId)
238 QString job, client, fileset;
240 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client, Fileset.Fileset AS Fileset "
241 " From Job, Client, Fileset"
242 " WHERE Job.FilesetId=FileSet.FilesetId AND Job.ClientId=Client.ClientId"
243 " AND JobId=\'" + jobId + "\'";
244 //printf("query = %s\n", query.toUtf8().data());
246 if (m_console->sql_cmd(query, results)) {
249 /* Iterate through the lines of results, there should only be one. */
250 foreach (QString resultline, results) {
251 fieldlist = resultline.split("\t");
252 } /* foreach resultline */
253 } /* if results from query */
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 //printf("In prerestorePage::jobIdEditFinished %s\n",line.toUtf8().data());
275 QStringList joblist = line.split(",", QString::SkipEmptyParts);
276 bool allintokay = true, alljobok = true, allisjob = true;
277 QString jobName(""), clientName("");
278 foreach (QString job, joblist) {
280 job.toInt(&intok, 10);
282 /* are the intergers representing a list of jobs all with the same job
285 jobdefsFromJob(fields, job);
286 int count = fields.count();
290 else if (jobName != fields[0])
292 if (clientName == "")
293 clientName = fields[1];
294 else if (clientName != fields[1])
304 QMessageBox::warning(this, tr("Bat"),
305 tr("The string is not a comma separated list if integers.\n"
306 "Press OK to continue?"), QMessageBox::Ok );
310 QMessageBox::warning(this, tr("Bat"),
311 tr("At least one of the jobs is not a valid job.\n"
312 "Press OK to continue?"), QMessageBox::Ok );
316 QMessageBox::warning(this, tr("Bat"),
317 tr("All jobs in the list must be of the same jobName and same client.\n"
318 "Press OK to continue?"), QMessageBox::Ok );