2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2010 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();
66 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
67 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
69 jobCombo->addItems(m_console->job_list);
70 filesetCombo->addItems(m_console->fileset_list);
71 clientCombo->addItems(m_console->client_list);
72 poolCombo->addItem(tr("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(mainWin->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(tr("Comma separted list of Job Ids"));
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 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
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));
97 } else if (m_dataInType == R_JOBDATETIME) {
98 selectJobRadio->setChecked(true);
99 selectJobIdsRadio->setChecked(false);
100 jobIdEdit->setText(tr("Comma separted list of Job Ids"));
101 jobIdEdit->setEnabled(false);
102 recentCheckBox->setCheckState(Qt::Unchecked);
103 jobRadioClicked(true);
104 QStringList fieldlist;
105 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
106 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
107 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
108 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
109 beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], mainWin->m_dtformat));
113 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
114 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
115 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
116 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
117 connect(selectJobRadio, SIGNAL(clicked(bool)), this, SLOT(jobRadioClicked(bool)));
118 connect(selectJobIdsRadio, SIGNAL(clicked(bool)), this, SLOT(jobidsRadioClicked(bool)));
119 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
124 if (mainWin->m_miscDebug) Pmsg0(000, "Leave preRestore\n");
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()) {
143 cmd = QString("restore");
144 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
145 cmd += " client=\"" + clientCombo->currentText() + "\"";
146 if (selectJobRadio->isChecked()) {
147 if (poolCombo->currentText() != tr("Any") ){
148 cmd += " pool=\"" + poolCombo->currentText() + "\"";
150 cmd += " storage=\"" + storageCombo->currentText() + "\"";
151 if (recentCheckBox->checkState() == Qt::Checked) {
154 QDateTime stamp = beforeDateTime->dateTime();
155 QString before = stamp.toString(mainWin->m_dtformat);
156 cmd += " before=\"" + before + "\"";
159 cmd += " jobid=\"" + jobIdEdit->text() + "\"";
161 if (selectFilesRadio->isChecked()) {
162 if (!selectJobIdsRadio->isChecked())
168 if (mainWin->m_commandDebug) {
169 Pmsg1(000, "preRestore command \'%s\'\n", cmd.toUtf8().data());
172 * Send off command that looks something like:
174 * restore fileset="Full Set" client="timmy-fd"
175 * storage="File" current select
177 m_console->write_dir(m_conn, cmd.toUtf8().data());
179 /* Note, do not turn notifier back on here ... */
180 if (selectFilesRadio->isChecked()) {
183 /* wait will be exited in the restore page constructor */
184 mainWin->waitEnter();
187 mainWin->resetFocus();
189 m_console->notify(m_conn, true);
190 if (mainWin->m_miscDebug) Pmsg0(000, "preRestore OK pressed\n");
195 * Destroy the instace of the class
197 void prerestorePage::cancelButtonPushed()
199 mainWin->set_status(tr("Canceled"));
201 m_console->notify(m_conn, true);
207 * Handle updating the other widget with job defaults when the job combo is changed.
209 void prerestorePage::job_name_change(int index)
211 job_defaults job_defs;
214 job_defs.job_name = jobCombo->currentText();
215 if (m_console->get_job_defaults(m_conn, job_defs)) {
216 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
217 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
218 poolCombo->setCurrentIndex(poolCombo->findText(tr("Any"), Qt::MatchExactly));
219 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
224 * Handle the change of enabled of input widgets when the recent checkbox state
227 void prerestorePage::recentChanged(int state)
229 if ((state == Qt::Unchecked) && (selectJobRadio->isChecked())) {
230 beforeDateTime->setEnabled(true);
232 beforeDateTime->setEnabled(false);
238 * For when jobs list is to be used, return a list which is the needed items from
241 int prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString &jobId)
243 QString job, client, fileset;
245 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
246 " FileSet.FileSet AS FileSet, Job.EndTime AS JobEnd,"
247 " Job.Type AS JobType"
248 " From Job, Client, FileSet"
249 " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
250 " AND JobId=\'" + jobId + "\'";
251 if (mainWin->m_sqlDebug) { Pmsg1(000, "query = %s\n", query.toUtf8().data()); }
253 if (m_console->sql_cmd(m_conn, query, results)) {
256 /* Iterate through the lines of results, there should only be one. */
257 foreach (QString resultline, results) {
258 fieldlist = resultline.split("\t");
259 } /* foreach resultline */
260 } /* if results from query */
262 /* ***FIXME*** This should not ever be getting more than one */
263 return results.count() >= 1;
267 * Function to handle when the jobidlist line edit input loses focus or is entered
269 void prerestorePage::jobIdEditFinished()
274 bool prerestorePage::checkJobIdList()
276 /* Need to check and make sure the text is a comma separated list of integers */
277 QString line = jobIdEdit->text();
278 if (line.contains(" ")) {
279 QMessageBox::warning(this, "Bat",
280 tr("There can be no spaces in the text for the joblist.\n"
281 "Press OK to continue?"), QMessageBox::Ok );
284 QStringList joblist = line.split(",", QString::SkipEmptyParts);
285 bool allintokay = true, alljobok = true, allisjob = true;
286 QString jobName(""), clientName("");
287 foreach (QString job, joblist) {
289 job.toInt(&intok, 10);
291 /* are the integers representing a list of jobs all with the same job
294 if (jobdefsFromJob(fields, job) == 1) {
297 else if (jobName != fields[0])
299 if (clientName == "")
300 clientName = fields[1];
301 else if (clientName != fields[1])
311 QMessageBox::warning(this, "Bat",
312 tr("The string is not a comma separated list of integers.\n"
313 "Press OK to continue?"), QMessageBox::Ok );
317 QMessageBox::warning(this, tr("Bat"),
318 tr("At least one of the jobs is not a valid job of type \"Backup\".\n"
319 "Press OK to continue?"), QMessageBox::Ok );
323 QMessageBox::warning(this, "Bat",
324 tr("All jobs in the list must be of the same jobName and same client.\n"
325 "Press OK to continue?"), QMessageBox::Ok );
332 * Handle the change of enabled of input widgets when the job radio buttons
335 void prerestorePage::jobRadioClicked(bool checked)
338 jobCombo->setEnabled(true);
339 filesetCombo->setEnabled(true);
340 clientCombo->setEnabled(true);
341 poolCombo->setEnabled(true);
342 storageCombo->setEnabled(true);
343 recentCheckBox->setEnabled(true);
344 if (!recentCheckBox->isChecked()) {
345 beforeDateTime->setEnabled(true);
347 jobIdEdit->setEnabled(false);
348 selectJobRadio->setChecked(true);
349 selectJobIdsRadio->setChecked(false);
351 jobCombo->setEnabled(false);
352 filesetCombo->setEnabled(false);
353 clientCombo->setEnabled(false);
354 poolCombo->setEnabled(false);
355 storageCombo->setEnabled(false);
356 recentCheckBox->setEnabled(false);
357 beforeDateTime->setEnabled(false);
358 jobIdEdit->setEnabled(true);
359 selectJobRadio->setChecked(false);
360 selectJobIdsRadio->setChecked(true);
362 if (mainWin->m_miscDebug) {
363 Pmsg2(000, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
364 selectJobIdsRadio->isChecked());
368 void prerestorePage::jobidsRadioClicked(bool checked)
371 jobCombo->setEnabled(false);
372 filesetCombo->setEnabled(false);
373 clientCombo->setEnabled(false);
374 poolCombo->setEnabled(false);
375 storageCombo->setEnabled(false);
376 recentCheckBox->setEnabled(false);
377 beforeDateTime->setEnabled(false);
378 jobIdEdit->setEnabled(true);
379 selectJobRadio->setChecked(false);
380 selectJobIdsRadio->setChecked(true);
382 jobCombo->setEnabled(true);
383 filesetCombo->setEnabled(true);
384 clientCombo->setEnabled(true);
385 poolCombo->setEnabled(true);
386 storageCombo->setEnabled(true);
387 recentCheckBox->setEnabled(true);
388 if (!recentCheckBox->isChecked()) {
389 beforeDateTime->setEnabled(true);
391 jobIdEdit->setEnabled(false);
392 selectJobRadio->setChecked(true);
393 selectJobIdsRadio->setChecked(false);
395 if (mainWin->m_miscDebug) {
396 Pmsg2(000, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
397 selectJobIdsRadio->isChecked());