2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 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 and included
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 Kern Sibbald.
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.
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_name = tr("Restore");
65 m_conn = m_console->notifyOff();
67 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
68 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
70 jobCombo->addItems(m_console->job_list);
71 filesetCombo->addItems(m_console->fileset_list);
72 clientCombo->addItems(m_console->client_list);
73 poolCombo->addItem(tr("Any"));
74 poolCombo->addItems(m_console->pool_list);
75 storageCombo->addItems(m_console->storage_list);
76 /* current or before . . Start out with current checked */
77 recentCheckBox->setCheckState(Qt::Checked);
78 beforeDateTime->setDisplayFormat(mainWin->m_dtformat);
79 beforeDateTime->setDateTime(QDateTime::currentDateTime());
80 beforeDateTime->setEnabled(false);
81 selectFilesRadio->setChecked(true);
82 if (m_dataInType == R_NONE) {
83 selectJobRadio->setChecked(true);
84 selectJobIdsRadio->setChecked(false);
85 jobIdEdit->setText(tr("Comma separted list of Job Ids"));
86 jobIdEdit->setEnabled(false);
87 } else if (m_dataInType == R_JOBIDLIST) {
88 selectJobIdsRadio->setChecked(true);
89 selectJobRadio->setChecked(false);
90 jobIdEdit->setText(m_dataIn);
91 jobRadioClicked(false);
92 QStringList fieldlist;
93 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
94 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
95 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
96 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
98 } else if (m_dataInType == R_JOBDATETIME) {
99 selectJobRadio->setChecked(true);
100 selectJobIdsRadio->setChecked(false);
101 jobIdEdit->setText(tr("Comma separted list of Job Ids"));
102 jobIdEdit->setEnabled(false);
103 recentCheckBox->setCheckState(Qt::Unchecked);
104 jobRadioClicked(true);
105 QStringList fieldlist;
106 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
107 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
108 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
109 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
110 beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], mainWin->m_dtformat));
114 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
115 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
116 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
117 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
118 connect(selectJobRadio, SIGNAL(clicked(bool)), this, SLOT(jobRadioClicked(bool)));
119 connect(selectJobIdsRadio, SIGNAL(clicked(bool)), this, SLOT(jobidsRadioClicked(bool)));
120 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
129 * Check to make sure all is ok then start either the select window or the restore
132 void prerestorePage::okButtonPushed()
134 if (!selectJobRadio->isChecked()) {
135 if (!checkJobIdList())
142 cmd = QString("restore");
143 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
144 cmd += " client=\"" + clientCombo->currentText() + "\"";
145 if (selectJobRadio->isChecked()) {
146 if (poolCombo->currentText() != tr("Any") ){
147 cmd += " pool=\"" + poolCombo->currentText() + "\"";
149 cmd += " storage=\"" + storageCombo->currentText() + "\"";
150 if (recentCheckBox->checkState() == Qt::Checked) {
153 QDateTime stamp = beforeDateTime->dateTime();
154 QString before = stamp.toString(mainWin->m_dtformat);
155 cmd += " before=\"" + before + "\"";
158 cmd += " jobid=\"" + jobIdEdit->text() + "\"";
160 if (selectFilesRadio->isChecked()) {
161 if (!selectJobIdsRadio->isChecked())
167 if (mainWin->m_commandDebug) {
168 Pmsg1(000, "preRestore command \'%s\'\n", cmd.toUtf8().data());
170 m_console->write_dir(m_conn, cmd.toUtf8().data());
172 /* Note, do not turn notifier back on here ... */
173 if (selectFilesRadio->isChecked()) {
176 /* wait will be exited in the restore page constructor */
177 mainWin->waitEnter();
180 mainWin->resetFocus();
182 m_console->notify(m_conn, true);
187 * Destroy the instace of the class
189 void prerestorePage::cancelButtonPushed()
191 mainWin->set_status(tr("Canceled"));
193 m_console->notify(m_conn, 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(m_conn, 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(tr("Any"), 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(m_conn, 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 */
254 /* FIXME This should not be getting more than one ever */
255 if(results.count() >= 1) return 1;
260 * Function to handle when the jobidlist line edit input loses focus or is entered
262 void prerestorePage::jobIdEditFinished()
267 bool prerestorePage::checkJobIdList()
269 /* Need to check and make sure the text is a comma separated list of integers */
270 QString line = jobIdEdit->text();
271 if (line.contains(" ")) {
272 QMessageBox::warning(this, "Bat",
273 tr("There can be no spaces in the text for the joblist.\n"
274 "Press OK to continue?"), QMessageBox::Ok );
277 QStringList joblist = line.split(",", QString::SkipEmptyParts);
278 bool allintokay = true, alljobok = true, allisjob = true;
279 QString jobName(""), clientName("");
280 foreach (QString job, joblist) {
282 job.toInt(&intok, 10);
284 /* are the integers representing a list of jobs all with the same job
287 if (jobdefsFromJob(fields, job) == 1) {
290 else if (jobName != fields[0])
292 if (clientName == "")
293 clientName = fields[1];
294 else if (clientName != fields[1])
304 QMessageBox::warning(this, "Bat",
305 tr("The string is not a comma separated list of 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 of type \"Backup\".\n"
312 "Press OK to continue?"), QMessageBox::Ok );
316 QMessageBox::warning(this, "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 );
325 * Handle the change of enabled of input widgets when the job radio buttons
328 void prerestorePage::jobRadioClicked(bool checked)
331 jobCombo->setEnabled(true);
332 filesetCombo->setEnabled(true);
333 clientCombo->setEnabled(true);
334 poolCombo->setEnabled(true);
335 storageCombo->setEnabled(true);
336 recentCheckBox->setEnabled(true);
337 if (!recentCheckBox->isChecked()) {
338 beforeDateTime->setEnabled(true);
340 jobIdEdit->setEnabled(false);
341 selectJobRadio->setChecked(true);
342 selectJobIdsRadio->setChecked(false);
344 jobCombo->setEnabled(false);
345 filesetCombo->setEnabled(false);
346 clientCombo->setEnabled(false);
347 poolCombo->setEnabled(false);
348 storageCombo->setEnabled(false);
349 recentCheckBox->setEnabled(false);
350 beforeDateTime->setEnabled(false);
351 jobIdEdit->setEnabled(true);
352 selectJobRadio->setChecked(false);
353 selectJobIdsRadio->setChecked(true);
355 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
356 selectJobIdsRadio->isChecked());
359 void prerestorePage::jobidsRadioClicked(bool checked)
362 jobCombo->setEnabled(false);
363 filesetCombo->setEnabled(false);
364 clientCombo->setEnabled(false);
365 poolCombo->setEnabled(false);
366 storageCombo->setEnabled(false);
367 recentCheckBox->setEnabled(false);
368 beforeDateTime->setEnabled(false);
369 jobIdEdit->setEnabled(true);
370 selectJobRadio->setChecked(false);
371 selectJobIdsRadio->setChecked(true);
373 jobCombo->setEnabled(true);
374 filesetCombo->setEnabled(true);
375 clientCombo->setEnabled(true);
376 poolCombo->setEnabled(true);
377 storageCombo->setEnabled(true);
378 recentCheckBox->setEnabled(true);
379 if (!recentCheckBox->isChecked()) {
380 beforeDateTime->setEnabled(true);
382 jobIdEdit->setEnabled(false);
383 selectJobRadio->setChecked(true);
384 selectJobIdsRadio->setChecked(false);
386 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
387 selectJobIdsRadio->isChecked());