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 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 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.
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()
65 m_console->notify(false);
67 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
68 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
70 if (!m_console->preventInUseConnect())
73 jobCombo->addItems(m_console->job_list);
74 filesetCombo->addItems(m_console->fileset_list);
75 clientCombo->addItems(m_console->client_list);
76 poolCombo->addItem("Any");
77 poolCombo->addItems(m_console->pool_list);
78 storageCombo->addItems(m_console->storage_list);
79 /* current or before . . Start out with current checked */
80 recentCheckBox->setCheckState(Qt::Checked);
81 beforeDateTime->setDisplayFormat(mainWin->m_dtformat);
82 beforeDateTime->setDateTime(QDateTime::currentDateTime());
83 beforeDateTime->setEnabled(false);
84 selectFilesRadio->setChecked(true);
85 if (m_dataInType == R_NONE) {
86 selectJobRadio->setChecked(true);
87 selectJobIdsRadio->setChecked(false);
88 jobIdEdit->setText("Comma separted list of jobs id's");
89 jobIdEdit->setEnabled(false);
90 } else if (m_dataInType == R_JOBIDLIST) {
91 selectJobIdsRadio->setChecked(true);
92 selectJobRadio->setChecked(false);
93 jobIdEdit->setText(m_dataIn);
94 jobRadioClicked(false);
95 QStringList fieldlist;
96 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
97 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
98 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
99 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
101 } else if (m_dataInType == R_JOBDATETIME) {
102 selectJobRadio->setChecked(true);
103 selectJobIdsRadio->setChecked(false);
104 jobIdEdit->setText("Comma separted list of jobs id's");
105 jobIdEdit->setEnabled(false);
106 recentCheckBox->setCheckState(Qt::Unchecked);
107 jobRadioClicked(true);
108 QStringList fieldlist;
109 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
110 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
111 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
112 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
113 beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], mainWin->m_dtformat));
117 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
118 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
119 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
120 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
121 connect(selectJobRadio, SIGNAL(clicked(bool)), this, SLOT(jobRadioClicked(bool)));
122 connect(selectJobIdsRadio, SIGNAL(clicked(bool)), this, SLOT(jobidsRadioClicked(bool)));
123 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
132 * Check to make sure all is ok then start either the select window or the restore
135 void prerestorePage::okButtonPushed()
137 if (!selectJobRadio->isChecked()) {
138 if (!checkJobIdList())
145 cmd = QString("restore");
146 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
147 cmd += " client=\"" + clientCombo->currentText() + "\"";
148 if (selectJobRadio->isChecked()) {
149 if (poolCombo->currentText() != "Any" ){
150 cmd += " pool=\"" + poolCombo->currentText() + "\"";
152 cmd += " storage=\"" + storageCombo->currentText() + "\"";
153 if (recentCheckBox->checkState() == Qt::Checked) {
156 QDateTime stamp = beforeDateTime->dateTime();
157 QString before = stamp.toString(mainWin->m_dtformat);
158 cmd += " before=\"" + before + "\"";
161 cmd += " jobid=\"" + jobIdEdit->text() + "\"";
163 if (selectFilesRadio->isChecked()) {
164 if (!selectJobIdsRadio->isChecked())
170 if (mainWin->m_commandDebug) {
171 Pmsg1(000, "preRestore command \'%s\'\n", cmd.toUtf8().data());
174 /* Note, do not turn notifier back on here ... */
175 if (selectFilesRadio->isChecked()) {
180 m_console->notify(true);
182 mainWin->resetFocus();
188 * Destroy the instace of the class
190 void prerestorePage::cancelButtonPushed()
192 mainWin->set_status("Canceled");
194 m_console->notify(true);
200 * Handle updating the other widget with job defaults when the job combo is changed.
202 void prerestorePage::job_name_change(int index)
204 job_defaults job_defs;
207 job_defs.job_name = jobCombo->currentText();
208 if (m_console->get_job_defaults(job_defs)) {
209 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
210 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
211 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
212 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
217 * Handle the change of enabled of input widgets when the recent checkbox state
220 void prerestorePage::recentChanged(int state)
222 if ((state == Qt::Unchecked) && (selectJobRadio->isChecked())) {
223 beforeDateTime->setEnabled(true);
225 beforeDateTime->setEnabled(false);
231 * For when jobs list is to be used, return a list which is the needed items from
234 int prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString &jobId)
236 QString job, client, fileset;
238 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
239 " FileSet.FileSet AS FileSet, Job.EndTime AS JobEnd,"
240 " Job.Type AS JobType"
241 " From Job, Client, FileSet"
242 " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
243 " AND JobId=\'" + jobId + "\'";
244 if (mainWin->m_sqlDebug) { Pmsg1(000, "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 */
254 return results.count();
258 * Function to handle when the jobidlist line edit input loses focus or is entered
260 void prerestorePage::jobIdEditFinished()
265 bool prerestorePage::checkJobIdList()
267 /* Need to check and make sure the text is a comma separated list of integers */
268 QString line = jobIdEdit->text();
269 if (line.contains(" ")) {
270 QMessageBox::warning(this, tr("Bat"),
271 tr("There can be no spaces in the text for the joblist.\n"
272 "Press OK to continue?"), QMessageBox::Ok );
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 integers representing a list of jobs all with the same job
285 if (jobdefsFromJob(fields, job) == 1) {
288 else if (jobName != fields[0])
290 if (clientName == "")
291 clientName = fields[1];
292 else if (clientName != fields[1])
302 QMessageBox::warning(this, tr("Bat"),
303 tr("The string is not a comma separated list if integers.\n"
304 "Press OK to continue?"), QMessageBox::Ok );
308 QMessageBox::warning(this, tr("Bat"),
309 tr("At least one of the jobs is not a valid job of type \"Backup\".\n"
310 "Press OK to continue?"), QMessageBox::Ok );
314 QMessageBox::warning(this, tr("Bat"),
315 tr("All jobs in the list must be of the same jobName and same client.\n"
316 "Press OK to continue?"), QMessageBox::Ok );
323 * Handle the change of enabled of input widgets when the job radio buttons
326 void prerestorePage::jobRadioClicked(bool checked)
329 jobCombo->setEnabled(true);
330 filesetCombo->setEnabled(true);
331 clientCombo->setEnabled(true);
332 poolCombo->setEnabled(true);
333 storageCombo->setEnabled(true);
334 recentCheckBox->setEnabled(true);
335 if (!recentCheckBox->isChecked()) {
336 beforeDateTime->setEnabled(true);
338 jobIdEdit->setEnabled(false);
339 selectJobRadio->setChecked(true);
340 selectJobIdsRadio->setChecked(false);
342 jobCombo->setEnabled(false);
343 filesetCombo->setEnabled(false);
344 clientCombo->setEnabled(false);
345 poolCombo->setEnabled(false);
346 storageCombo->setEnabled(false);
347 recentCheckBox->setEnabled(false);
348 beforeDateTime->setEnabled(false);
349 jobIdEdit->setEnabled(true);
350 selectJobRadio->setChecked(false);
351 selectJobIdsRadio->setChecked(true);
353 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
354 selectJobIdsRadio->isChecked());
357 void prerestorePage::jobidsRadioClicked(bool checked)
360 jobCombo->setEnabled(false);
361 filesetCombo->setEnabled(false);
362 clientCombo->setEnabled(false);
363 poolCombo->setEnabled(false);
364 storageCombo->setEnabled(false);
365 recentCheckBox->setEnabled(false);
366 beforeDateTime->setEnabled(false);
367 jobIdEdit->setEnabled(true);
368 selectJobRadio->setChecked(false);
369 selectJobIdsRadio->setChecked(true);
371 jobCombo->setEnabled(true);
372 filesetCombo->setEnabled(true);
373 clientCombo->setEnabled(true);
374 poolCombo->setEnabled(true);
375 storageCombo->setEnabled(true);
376 recentCheckBox->setEnabled(true);
377 if (!recentCheckBox->isChecked()) {
378 beforeDateTime->setEnabled(true);
380 jobIdEdit->setEnabled(false);
381 selectJobRadio->setChecked(true);
382 selectJobIdsRadio->setChecked(false);
384 Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
385 selectJobIdsRadio->isChecked());