]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/restore/prerestore.cpp
This change of the regular expressions should fix any restoretree issues
[bacula/bacula] / bacula / src / qt-console / restore / prerestore.cpp
index be7d85e7c16e0ffce740aa266b52085be00d3f53..cc13480ac3011eb3855cebe9720ad4c65dcb4c6a 100644 (file)
@@ -7,8 +7,8 @@
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,7 +27,7 @@
 */
  
 /*
- *   Version $Id: restore.cpp 4307 2007-03-04 10:24:39Z kerns $
+ *   Version $Id$
  *
  *  preRestore -> dialog put up to determine the restore type
  *
 #include "restore.h"
 
 /* Constructor to have job id list default in */
-prerestorePage::prerestorePage(QString &jobIdString)
+prerestorePage::prerestorePage(QString &data, unsigned int datatype)
 {
-   m_jobIdListIn = jobIdString;
+   m_dataIn = data;
+   m_dataInType = datatype;
    buildPage();
 }
 
 /* Basic Constructor */
 prerestorePage::prerestorePage()
 {
-   m_jobIdListIn = "";
+   m_dataIn = "";
+   m_dataInType = R_NONE;
    buildPage();
 }
 
@@ -57,12 +59,16 @@ prerestorePage::prerestorePage()
  */
 void prerestorePage::buildPage()
 {
-   m_dtformat = "yyyy-MM-dd HH:MM:ss";
    m_name = "Restore";
    setupUi(this);
    pgInitialize();
    m_console->notify(false);
    m_closeable = true;
+   QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
+   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/restore.png")));
+
+   if (!m_console->preventInUseConnect())
+       return;
 
    jobCombo->addItems(m_console->job_list);
    filesetCombo->addItems(m_console->fileset_list);
@@ -72,30 +78,48 @@ void prerestorePage::buildPage()
    storageCombo->addItems(m_console->storage_list);
    /* current or before . .  Start out with current checked */
    recentCheckBox->setCheckState(Qt::Checked);
-   beforeDateTime->setDisplayFormat(m_dtformat);
+   beforeDateTime->setDisplayFormat(mainWin->m_dtformat);
    beforeDateTime->setDateTime(QDateTime::currentDateTime());
    beforeDateTime->setEnabled(false);
    selectFilesRadio->setChecked(true);
-   if (m_jobIdListIn == "") {
-      selectJobsRadio->setChecked(true);
+   if (m_dataInType == R_NONE) {
+      selectJobRadio->setChecked(true);
+      selectJobIdsRadio->setChecked(false);
       jobIdEdit->setText("Comma separted list of jobs id's");
       jobIdEdit->setEnabled(false);
-   } else {
-      listJobsRadio->setChecked(true);
-      jobIdEdit->setText(m_jobIdListIn);
-      jobsRadioClicked(false);
+   } else if (m_dataInType == R_JOBIDLIST) {
+      selectJobIdsRadio->setChecked(true);
+      selectJobRadio->setChecked(false);
+      jobIdEdit->setText(m_dataIn);
+      jobRadioClicked(false);
+      QStringList fieldlist;
+      if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
+         filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
+         clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
+         jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
+      }
+   } else if (m_dataInType == R_JOBDATETIME) {
+      selectJobRadio->setChecked(true);
+      selectJobIdsRadio->setChecked(false);
+      jobIdEdit->setText("Comma separted list of jobs id's");
+      jobIdEdit->setEnabled(false);
+      recentCheckBox->setCheckState(Qt::Unchecked);
+      jobRadioClicked(true);
       QStringList fieldlist;
-      jobdefsFromJob(fieldlist,m_jobIdListIn);
-      filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
-      clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
-      jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
+      if (jobdefsFromJob(fieldlist, m_dataIn) == 1) {
+         filesetCombo->setCurrentIndex(filesetCombo->findText(fieldlist[2], Qt::MatchExactly));
+         clientCombo->setCurrentIndex(clientCombo->findText(fieldlist[1], Qt::MatchExactly));
+         jobCombo->setCurrentIndex(jobCombo->findText(fieldlist[0], Qt::MatchExactly));
+         beforeDateTime->setDateTime(QDateTime::fromString(fieldlist[3], mainWin->m_dtformat));
+     }
    }
    job_name_change(0);
    connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
    connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
    connect(cancelButton, SIGNAL(pressed()), this, SLOT(cancelButtonPushed()));
    connect(recentCheckBox, SIGNAL(stateChanged(int)), this, SLOT(recentChanged(int)));
-   connect(selectJobsRadio, SIGNAL(toggled(bool)), this, SLOT(jobsRadioClicked(bool)));
+   connect(selectJobRadio, SIGNAL(clicked(bool)), this, SLOT(jobRadioClicked(bool)));
+   connect(selectJobIdsRadio, SIGNAL(clicked(bool)), this, SLOT(jobidsRadioClicked(bool)));
    connect(jobIdEdit, SIGNAL(editingFinished()), this, SLOT(jobIdEditFinished()));
 
    dockPage();
@@ -110,7 +134,7 @@ void prerestorePage::buildPage()
  */
 void prerestorePage::okButtonPushed()
 {
-   if (!selectJobsRadio->isChecked()) {
+   if (!selectJobRadio->isChecked()) {
       if (!checkJobIdList())
          return;
    }
@@ -118,32 +142,34 @@ void prerestorePage::okButtonPushed()
 
    this->hide();
 
-   cmd = QString("restore ");
-   if (selectFilesRadio->isChecked()) {
-      cmd += "select ";
-   } else {
-      cmd += "all done ";
-   }
-   cmd += "fileset=\"" + filesetCombo->currentText() + "\" ";
-   cmd += "client=\"" + clientCombo->currentText() + "\" ";
-   if (selectJobsRadio->isChecked()) {
+   cmd = QString("restore");
+   cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
+   cmd += " client=\"" + clientCombo->currentText() + "\"";
+   if (selectJobRadio->isChecked()) {
       if (poolCombo->currentText() != "Any" ){
-         cmd += "pool=\"" + poolCombo->currentText() + "\" ";
+         cmd += " pool=\"" + poolCombo->currentText() + "\"";
       }
-      cmd += "storage=\"" + storageCombo->currentText() + "\" ";
+      cmd += " storage=\"" + storageCombo->currentText() + "\"";
       if (recentCheckBox->checkState() == Qt::Checked) {
          cmd += " current";
       } else {
          QDateTime stamp = beforeDateTime->dateTime();
-         QString before = stamp.toString(m_dtformat);
+         QString before = stamp.toString(mainWin->m_dtformat);
          cmd += " before=\"" + before + "\"";
       }
    } else {
-      cmd += "jobid=\"" + jobIdEdit->text() + "\"";
+      cmd += " jobid=\"" + jobIdEdit->text() + "\"";
+   }
+   if (selectFilesRadio->isChecked()) {
+      if (!selectJobIdsRadio->isChecked())
+         cmd += " select";
+   } else {
+      cmd += " all done";
    }
 
-   /* ***FIXME*** */
-   //printf("preRestore command \'%s\'\n", cmd.toUtf8().data());
+   if (mainWin->m_commandDebug) {
+      Pmsg1(000, "preRestore command \'%s\'\n", cmd.toUtf8().data());
+   }
    consoleCommand(cmd);
    /* Note, do not turn notifier back on here ... */
    if (selectFilesRadio->isChecked()) {
@@ -193,55 +219,29 @@ void prerestorePage::job_name_change(int index)
  */
 void prerestorePage::recentChanged(int state)
 {
-   if ((state == Qt::Unchecked) && (selectJobsRadio->isChecked())) {
+   if ((state == Qt::Unchecked) && (selectJobRadio->isChecked())) {
       beforeDateTime->setEnabled(true);
    } else {
       beforeDateTime->setEnabled(false);
    }
 }
 
-/*
- * Handle the change of enabled of input widgets when the job radio buttons
- * are changed.
- */
-void prerestorePage::jobsRadioClicked(bool checked)
-{
-   if (checked) {
-      jobCombo->setEnabled(true);
-      filesetCombo->setEnabled(true);
-      clientCombo->setEnabled(true);
-      poolCombo->setEnabled(true);
-      storageCombo->setEnabled(true);
-      recentCheckBox->setEnabled(true);
-      if (!recentCheckBox->isChecked()) {
-         beforeDateTime->setEnabled(true);
-      }
-      jobIdEdit->setEnabled(false);
-   } else {
-      jobCombo->setEnabled(false);
-      filesetCombo->setEnabled(false);
-      clientCombo->setEnabled(false);
-      poolCombo->setEnabled(false);
-      storageCombo->setEnabled(false);
-      recentCheckBox->setEnabled(false);
-      beforeDateTime->setEnabled(false);
-      jobIdEdit->setEnabled(true);
-   }
-}
 
 /*
  * For when jobs list is to be used, return a list which is the needed items from
  * the job record
  */
-void prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString jobId)
+int prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString &jobId)
 {
    QString job, client, fileset;
    QString query("");
-   query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client, Fileset.Fileset AS Fileset "
-   " From Job, Client, Fileset"
-   " WHERE Job.FilesetId=FileSet.FilesetId AND Job.ClientId=Client.ClientId"
+   query = "SELECT DISTINCT Job.Name AS JobName, Client.Name AS Client,"
+   " FileSet.FileSet AS FileSet, Job.EndTime AS JobEnd,"
+   " Job.Type AS JobType"
+   " From Job, Client, FileSet"
+   " WHERE Job.FileSetId=FileSet.FileSetId AND Job.ClientId=Client.ClientId"
    " AND JobId=\'" + jobId + "\'";
-   //printf("query = %s\n", query.toUtf8().data());
+   if (mainWin->m_sqlDebug) { Pmsg1(000, "query = %s\n", query.toUtf8().data()); }
    QStringList results;
    if (m_console->sql_cmd(query, results)) {
       QString field;
@@ -251,6 +251,7 @@ void prerestorePage::jobdefsFromJob(QStringList &fieldlist, QString jobId)
          fieldlist = resultline.split("\t");
       } /* foreach resultline */
    } /* if results from query */
+   return results.count();
 }
 
 /*
@@ -271,7 +272,6 @@ bool prerestorePage::checkJobIdList()
          "Press OK to continue?"), QMessageBox::Ok );
       return false;
    }
-   //printf("In prerestorePage::jobIdEditFinished %s\n",line.toUtf8().data());
    QStringList joblist = line.split(",", QString::SkipEmptyParts);
    bool allintokay = true, alljobok = true, allisjob = true;
    QString jobName(""), clientName("");
@@ -279,12 +279,10 @@ bool prerestorePage::checkJobIdList()
       bool intok;
       job.toInt(&intok, 10);
       if (intok) {
-         /* are the intergers representing a list of jobs all with the same job
+         /* are the integers representing a list of jobs all with the same job
           * and client */
          QStringList fields;
-         jobdefsFromJob(fields, job);
-         int count = fields.count();
-         if (count > 0) {
+         if (jobdefsFromJob(fields, job) == 1) {
             if (jobName == "")
                jobName = fields[0];
             else if (jobName != fields[0])
@@ -308,7 +306,7 @@ bool prerestorePage::checkJobIdList()
    }
    if (!allisjob){
       QMessageBox::warning(this, tr("Bat"),
-         tr("At least one of the jobs is not a valid job.\n"
+         tr("At least one of the jobs is not a valid job of type \"Backup\".\n"
          "Press OK to continue?"), QMessageBox::Ok );
       return false;
    }
@@ -321,3 +319,68 @@ bool prerestorePage::checkJobIdList()
    return true;
 }
 
+/*
+ * Handle the change of enabled of input widgets when the job radio buttons
+ * are changed.
+ */
+void prerestorePage::jobRadioClicked(bool checked)
+{
+   if (checked) {
+      jobCombo->setEnabled(true);
+      filesetCombo->setEnabled(true);
+      clientCombo->setEnabled(true);
+      poolCombo->setEnabled(true);
+      storageCombo->setEnabled(true);
+      recentCheckBox->setEnabled(true);
+      if (!recentCheckBox->isChecked()) {
+         beforeDateTime->setEnabled(true);
+      }
+      jobIdEdit->setEnabled(false);
+      selectJobRadio->setChecked(true);
+      selectJobIdsRadio->setChecked(false);
+   } else {
+      jobCombo->setEnabled(false);
+      filesetCombo->setEnabled(false);
+      clientCombo->setEnabled(false);
+      poolCombo->setEnabled(false);
+      storageCombo->setEnabled(false);
+      recentCheckBox->setEnabled(false);
+      beforeDateTime->setEnabled(false);
+      jobIdEdit->setEnabled(true);
+      selectJobRadio->setChecked(false);
+      selectJobIdsRadio->setChecked(true);
+   }
+   Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(), 
+         selectJobIdsRadio->isChecked());
+}
+
+void prerestorePage::jobidsRadioClicked(bool checked)
+{
+   if (checked) {
+      jobCombo->setEnabled(false);
+      filesetCombo->setEnabled(false);
+      clientCombo->setEnabled(false);
+      poolCombo->setEnabled(false);
+      storageCombo->setEnabled(false);
+      recentCheckBox->setEnabled(false);
+      beforeDateTime->setEnabled(false);
+      jobIdEdit->setEnabled(true);
+      selectJobRadio->setChecked(false);
+      selectJobIdsRadio->setChecked(true);
+   } else {
+      jobCombo->setEnabled(true);
+      filesetCombo->setEnabled(true);
+      clientCombo->setEnabled(true);
+      poolCombo->setEnabled(true);
+      storageCombo->setEnabled(true);
+      recentCheckBox->setEnabled(true);
+      if (!recentCheckBox->isChecked()) {
+         beforeDateTime->setEnabled(true);
+      }
+      jobIdEdit->setEnabled(false);
+      selectJobRadio->setChecked(true);
+      selectJobIdsRadio->setChecked(false);
+   }
+   Dmsg2(200, "jobRadio=%d jobidsRadio=%d\n", selectJobRadio->isChecked(), 
+         selectJobIdsRadio->isChecked());
+}