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 three of the GNU Affero 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 Affero 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.
30 * preRestore -> dialog put up to determine the restore type
32 * Kern Sibbald, February MMVII
39 /* Constructor to have job id list default in */
40 prerestorePage::prerestorePage(QString &data, unsigned int datatype)
43 m_dataInType = datatype;
47 /* Basic Constructor */
48 prerestorePage::prerestorePage()
51 m_dataInType = R_NONE;
56 * This is really the constructor
58 void prerestorePage::buildPage()
60 m_name = tr("Restore");
63 m_conn = m_console->notifyOff();
64 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
65 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
67 jobCombo->addItems(m_console->job_list);
68 filesetCombo->addItems(m_console->fileset_list);
69 clientCombo->addItems(m_console->client_list);
70 poolCombo->addItem(tr("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(mainWin->m_dtformat);
76 beforeDateTime->setDateTime(QDateTime::currentDateTime());
77 beforeDateTime->setEnabled(false);
78 selectFilesRadio->setChecked(true);
79 if (m_dataInType == R_NONE) {
80 selectJobRadio->setChecked(true);
81 selectJobIdsRadio->setChecked(false);
82 jobIdEdit->setText(tr("Comma separted list of Job Ids"));
83 jobIdEdit->setEnabled(false);
84 } else if (m_dataInType == R_JOBIDLIST) {
85 selectJobIdsRadio->setChecked(true);
86 selectJobRadio->setChecked(false);
87 jobIdEdit->setText(m_dataIn);
88 jobRadioClicked(false);
89 QStringList fieldlist;
90 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
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));
95 } else if (m_dataInType == R_JOBDATETIME) {
96 selectJobRadio->setChecked(true);
97 selectJobIdsRadio->setChecked(false);
98 jobIdEdit->setText(tr("Comma separted list of Job Ids"));
99 jobIdEdit->setEnabled(false);
100 recentCheckBox->setCheckState(Qt::Unchecked);
101 jobRadioClicked(true);
102 QStringList fieldlist;
103 if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
104 filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
105 clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
106 jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
107 beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], mainWin->m_dtformat));
111 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
112 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
113 connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
114 connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
115 connect(selectJobRadio, SIGNAL(clicked(bool)), this, SLOT(jobRadioClicked(bool)));
116 connect(selectJobIdsRadio, SIGNAL(clicked(bool)), this, SLOT(jobidsRadioClicked(bool)));
117 connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
122 if (mainWin->m_miscDebug) Pmsg0(000, "Leave preRestore\n");
127 * Check to make sure all is ok then start either the select window or the restore
130 void prerestorePage::okButtonPushed()
132 if (!selectJobRadio->isChecked()) {
133 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());
171 * Send off command that looks something like:
173 * restore fileset="Full Set" client="timmy-fd"
174 * storage="File" current select
176 m_console->write_dir(m_conn, cmd.toUtf8().data());
178 /* Note, do not turn notifier back on here ... */
179 if (selectFilesRadio->isChecked()) {
182 /* wait will be exited in the restore page constructor */
183 mainWin->waitEnter();
186 mainWin->resetFocus();
188 m_console->notify(m_conn, true);
189 if (mainWin->m_miscDebug) Pmsg0(000, "preRestore OK pressed\n");
194 * Destroy the instace of the class
196 void prerestorePage::cancelButtonPushed()
198 mainWin->set_status(tr("Canceled"));
200 m_console->notify(m_conn, true);
206 * Handle updating the other widget with job defaults when the job combo is changed.
208 void prerestorePage::job_name_change(int index)
210 job_defaults job_defs;
213 job_defs.job_name = jobCombo->currentText();
214 if (m_console->get_job_defaults(m_conn, job_defs)) {
215 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
216 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
217 poolCombo->setCurrentIndex(poolCombo->findText(tr("Any"), Qt::MatchExactly));
218 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
223 * Handle the change of enabled of input widgets when the recent checkbox state
226 void prerestorePage::recentChanged(int state)
228 if ((state == Qt::Unchecked) && (selectJobRadio->isChecked())) {
229 beforeDateTime->setEnabled(true);
231 beforeDateTime->setEnabled(false);
237 * For when jobs list is to be used, return a list which is the needed items from
240 int prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString &jobId)
242 QString job, client, fileset;
244 query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
245 " FileSet.FileSet AS FileSet, Job.EndTime AS JobEnd,"
246 " Job.Type AS JobType"
247 " From Job, Client, FileSet"
248 " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
249 " AND JobId=\'" + jobId + "\'";
250 if (mainWin->m_sqlDebug) { Pmsg1(000, "query = %s\n", query.toUtf8().data()); }
252 if (m_console->sql_cmd(m_conn, query, results)) {
255 /* Iterate through the lines of results, there should only be one. */
256 foreach (QString resultline, results) {
257 fieldlist = resultline.split("\t");
258 } /* foreach resultline */
259 } /* if results from query */
261 /* ***FIXME*** This should not ever be getting more than one */
262 return results.count() >= 1;
266 * Function to handle when the jobidlist line edit input loses focus or is entered
268 void prerestorePage::jobIdEditFinished()
273 bool prerestorePage::checkJobIdList()
275 /* Need to check and make sure the text is a comma separated list of integers */
276 QString line = jobIdEdit->text();
277 if (line.contains(" ")) {
278 QMessageBox::warning(this, "Bat",
279 tr("There can be no spaces in the text for the joblist.\n"
280 "Press OK to continue?"), QMessageBox::Ok );
283 QStringList joblist = line.split(",", QString::SkipEmptyParts);
284 bool allintokay = true, alljobok = true, allisjob = true;
285 QString jobName(""), clientName("");
286 foreach (QString job, joblist) {
288 job.toInt(&intok, 10);
290 /* are the integers representing a list of jobs all with the same job
293 if (jobdefsFromJob(fields, job) == 1) {
296 else if (jobName != fields[0])
298 if (clientName == "")
299 clientName = fields[1];
300 else if (clientName != fields[1])
310 QMessageBox::warning(this, "Bat",
311 tr("The string is not a comma separated list of integers.\n"
312 "Press OK to continue?"), QMessageBox::Ok );
316 QMessageBox::warning(this, tr("Bat"),
317 tr("At least one of the jobs is not a valid job of type \"Backup\".\n"
318 "Press OK to continue?"), QMessageBox::Ok );
322 QMessageBox::warning(this, "Bat",
323 tr("All jobs in the list must be of the same jobName and same client.\n"
324 "Press OK to continue?"), QMessageBox::Ok );
331 * Handle the change of enabled of input widgets when the job radio buttons
334 void prerestorePage::jobRadioClicked(bool checked)
337 jobCombo->setEnabled(true);
338 filesetCombo->setEnabled(true);
339 clientCombo->setEnabled(true);
340 poolCombo->setEnabled(true);
341 storageCombo->setEnabled(true);
342 recentCheckBox->setEnabled(true);
343 if (!recentCheckBox->isChecked()) {
344 beforeDateTime->setEnabled(true);
346 jobIdEdit->setEnabled(false);
347 selectJobRadio->setChecked(true);
348 selectJobIdsRadio->setChecked(false);
350 jobCombo->setEnabled(false);
351 filesetCombo->setEnabled(false);
352 clientCombo->setEnabled(false);
353 poolCombo->setEnabled(false);
354 storageCombo->setEnabled(false);
355 recentCheckBox->setEnabled(false);
356 beforeDateTime->setEnabled(false);
357 jobIdEdit->setEnabled(true);
358 selectJobRadio->setChecked(false);
359 selectJobIdsRadio->setChecked(true);
361 if (mainWin->m_miscDebug) {
362 Pmsg2(000, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
363 selectJobIdsRadio->isChecked());
367 void prerestorePage::jobidsRadioClicked(bool checked)
370 jobCombo->setEnabled(false);
371 filesetCombo->setEnabled(false);
372 clientCombo->setEnabled(false);
373 poolCombo->setEnabled(false);
374 storageCombo->setEnabled(false);
375 recentCheckBox->setEnabled(false);
376 beforeDateTime->setEnabled(false);
377 jobIdEdit->setEnabled(true);
378 selectJobRadio->setChecked(false);
379 selectJobIdsRadio->setChecked(true);
381 jobCombo->setEnabled(true);
382 filesetCombo->setEnabled(true);
383 clientCombo->setEnabled(true);
384 poolCombo->setEnabled(true);
385 storageCombo->setEnabled(true);
386 recentCheckBox->setEnabled(true);
387 if (!recentCheckBox->isChecked()) {
388 beforeDateTime->setEnabled(true);
390 jobIdEdit->setEnabled(false);
391 selectJobRadio->setChecked(true);
392 selectJobIdsRadio->setChecked(false);
394 if (mainWin->m_miscDebug) {
395 Pmsg2(000, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(),
396 selectJobIdsRadio->isChecked());