]> git.sur5r.net Git - bacula/bacula/commitdiff
Clear list before populating lists in console.
authorDirk H Bartley <dbartley@schupan.com>
Thu, 7 Jun 2007 20:40:27 +0000 (20:40 +0000)
committerDirk H Bartley <dbartley@schupan.com>
Thu, 7 Jun 2007 20:40:27 +0000 (20:40 +0000)
Add a table in restore tree to show what jobs were selected.  Use IN keyword
in sql statements to represent better what the selections really are.  They
are show me stuff for this condition preselecting a list of jobs.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4996 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/qt-console/console/console.cpp
bacula/src/qt-console/restore/restoretree.cpp
bacula/src/qt-console/restore/restoretree.h
bacula/src/qt-console/restore/restoretree.ui

index 90ca1100f413e256e0cafe22da6b725e566bd48f..269c423066f723d066d9731a3101048760ed8990 100644 (file)
@@ -230,6 +230,15 @@ void Console::connect_dir()
    displayToPrompt();
 
    beginNewCommand();
+   job_list.clear();
+   client_list.clear();
+   fileset_list.clear();
+   fileset_list.clear();
+   messages_list.clear();
+   pool_list.clear();
+   storage_list.clear();
+   type_list.clear();
+   level_list.clear();
    dir_cmd(".jobs", job_list);
    dir_cmd(".clients", client_list);
    dir_cmd(".filesets", fileset_list);  
index 14b815202c31e6df4de235af373e094642190204..0b8573960fb6cba947bca7a4f0bf8e7f356cb34b 100644 (file)
@@ -97,13 +97,15 @@ void restoreTree::populateDirectoryTree()
    m_dirPaths.clear();
    directoryTree->clear();
    fileTable->clear();
+   fileTable->setRowCount(0);
+   fileTable->setColumnCount(0);
    versionTable->clear();
-   QString cmd =
-      "SELECT DISTINCT Path.Path FROM Path"
-      " LEFT OUTER JOIN File ON (File.PathId=Path.PathId)"
-      " LEFT OUTER JOIN Job ON (File.JobId=Job.JobId)"
-      " LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId)"
-      " LEFT OUTER JOIN FileSet ON (Job.FileSetId=FileSet.FileSetId) WHERE";
+   versionTable->setRowCount(0);
+   versionTable->setColumnCount(0);
+   jobTable->clear();
+   jobTable->setRowCount(0);
+   jobTable->setColumnCount(0);
+
    m_condition = " Job.name = '" + jobCombo->itemText(jobCombo->currentIndex()) + "'";
    int clientIndex = clientCombo->currentIndex();
    if ((clientIndex >= 0) && (clientCombo->itemText(clientIndex) != "Any")) {
@@ -113,7 +115,25 @@ void restoreTree::populateDirectoryTree()
    if ((fileSetIndex >= 0) && (fileSetCombo->itemText(fileSetIndex) != "Any")) {
       m_condition.append(" AND FileSet.FileSet='" + fileSetCombo->itemText(fileSetIndex) + "'");
    }
-   cmd += m_condition;
+   m_jobQueryPart =
+      " LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId)"
+      " LEFT OUTER JOIN FileSet ON (Job.FileSetId=FileSet.FileSetId)"
+      " WHERE" + m_condition +
+      " AND Job.purgedfiles=0";
+   m_jobQuery =
+      "SELECT Job.Jobid"
+      " From Job" + m_jobQueryPart;
+   if (mainWin->m_sqlDebug) {
+      Pmsg1(000, "Query cmd : %s\n",m_jobQuery.toUtf8().data());
+   }
+   populateJobTable();
+
+   QString cmd =
+      "SELECT DISTINCT Path.Path"
+      " FROM Path"
+      " LEFT OUTER JOIN File ON (File.PathId=Path.PathId)"
+      " LEFT OUTER JOIN Job ON (File.JobId=Job.JobId)"
+      " WHERE Job.Jobid IN (" + m_jobQuery + ")";
    if (mainWin->m_sqlDebug) {
       Pmsg1(000, "Query cmd : %s\n",cmd.toUtf8().data());
    }
@@ -306,12 +326,13 @@ void restoreTree::directoryItemChanged(QTreeWidgetItem *item, QTreeWidgetItem *)
    directoryLabel->setText("Present Working Directory : " + directory);
    QString cmd =
       "SELECT DISTINCT Filename.Name"
-      " FROM File LEFT OUTER JOIN Filename on (Filename.FilenameId=File.FilenameId)"
+      " FROM File "
+      " LEFT OUTER JOIN Filename on (Filename.FilenameId=File.FilenameId)"
       " LEFT OUTER JOIN Path ON (Path.PathId=File.PathId)"
       " LEFT OUTER JOIN Job ON (File.JobId=Job.JobId)"
-      " LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId)"
-      " LEFT OUTER JOIN FileSet ON (Job.FileSetId=FileSet.FileSetId)";
-   cmd += " WHERE Path.Path='" + directory + "' AND Filename.Name!='' AND " + m_condition;
+      " WHERE Path.Path='" + directory + "' AND Filename.Name!=''"
+      " AND Job.Jobid IN (" + m_jobQuery + ")";
 
    QStringList headerlist = (QStringList() << "File Name");
    fileTable->clear();
@@ -327,7 +348,6 @@ void restoreTree::directoryItemChanged(QTreeWidgetItem *item, QTreeWidgetItem *)
    }
    QStringList results;
    if (m_console->sql_cmd(cmd, results)) {
-      m_resultCount = results.count();
    
       QTableWidgetItem* tableItem;
       QString field;
@@ -375,9 +395,8 @@ void restoreTree::fileItemChanged(QTableWidgetItem *fileTableItem, QTableWidgetI
       " LEFT OUTER JOIN Filename on (Filename.FilenameId=File.FilenameId)"
       " LEFT OUTER JOIN Path ON (Path.PathId=File.PathId)"
       " LEFT OUTER JOIN Job ON (File.JobId=Job.JobId)"
-      " LEFT OUTER JOIN Client ON (Job.ClientId=Client.ClientId)"
-      " LEFT OUTER JOIN FileSet ON (Job.FileSetId=FileSet.FileSetId)";
-   cmd += " WHERE Filename.Name='" + file + "' AND Path.Path='" + directory + "' AND " + m_condition;
+      " WHERE Filename.Name='" + file + "' AND Path.Path='" + directory + "'"
+      " AND Job.Jobid IN (" + m_jobQuery + ")";
 
    QStringList headerlist = (QStringList() << "File Id" << "Job Id" << "End Time" << "Md5");
    versionTable->clear();
@@ -389,7 +408,6 @@ void restoreTree::fileItemChanged(QTableWidgetItem *fileTableItem, QTableWidgetI
    }
    QStringList results;
    if (m_console->sql_cmd(cmd, results)) {
-      m_resultCount = results.count();
    
       QTableWidgetItem* tableItem;
       QString field;
@@ -456,3 +474,51 @@ void restoreTree::directoryItemExpanded(QTreeWidgetItem *item)
       child->setIcon(0,QIcon(QString::fromUtf8(":images/folder.png")));
    }
 }
+
+void restoreTree::populateJobTable()
+{
+   QBrush blackBrush(Qt::black);
+   QStringList headerlist = (QStringList() << "Job Id" << "End Time" << "Type");
+   jobTable->clear();
+   jobTable->setColumnCount(headerlist.size());
+   jobTable->setHorizontalHeaderLabels(headerlist);
+   QString jobQuery =
+      "SELECT Job.Jobid AS Id, Job.Endtime AS EndTime, Job.Level AS Level"
+      " FROM Job" + m_jobQueryPart +
+      " ORDER BY Job.Endtime DESC";
+   if (mainWin->m_sqlDebug) {
+      Pmsg1(000, "Query cmd : %s\n",jobQuery.toUtf8().data());
+   }
+
+   QStringList results;
+   if (m_console->sql_cmd(jobQuery, results)) {
+   
+      QTableWidgetItem* tableItem;
+      QString field;
+      QStringList fieldlist;
+      jobTable->setRowCount(results.size());
+
+      int row = 0;
+      /* Iterate through the record returned from the query */
+      foreach (QString resultline, results) {
+         fieldlist = resultline.split("\t");
+         int column = 0;
+         /* remove directory */
+         if (fieldlist[0].trimmed() != "") {
+            /* Iterate through fields in the record */
+            foreach (field, fieldlist) {
+               field = field.trimmed();  /* strip leading & trailing spaces */
+               tableItem = new QTableWidgetItem(field,1);
+               tableItem->setFlags(0);
+               tableItem->setForeground(blackBrush);
+               jobTable->setItem(row, column, tableItem);
+               column++;
+            }
+            row++;
+         }
+      }
+   }
+   jobTable->resizeColumnsToContents();
+   jobTable->resizeRowsToContents();
+   jobTable->verticalHeader()->hide();
+}
index 589d2cd4e5b96702d8a9db6016d5fcc9bff9aa24..8666ce69106e6a9802e019ee48c41e3150d62fe5 100644 (file)
@@ -59,6 +59,7 @@ private slots:
 
 private:
    void populateDirectoryTree();
+   void populateJobTable();
    void parseDirectory(QString &dir_in);
    bool addDirectory(QString &, QString &);
    void setupPage();
@@ -72,7 +73,8 @@ private:
    //QString m_jobCondition;
    QHash<QString, QTreeWidgetItem *> m_dirPaths;
    QString m_condition;
-   int m_resultCount;
+   QString m_jobQuery;
+   QString m_jobQueryPart;
    int m_debugCnt;
    bool m_debugTrap;
 };
index 8a01cff03fc69395bb5d04feed70b11df700ec26..e6a08ff115e8e741b022666be2b52bef200e3a6c 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>515</width>
-    <height>333</height>
+    <width>400</width>
+    <height>319</height>
    </rect>
   </property>
   <property name="windowTitle" >
    </property>
    <item row="0" column="0" >
     <widget class="QSplitter" name="splitter" >
-     <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>7</hsizetype>
-       <vsizetype>7</vsizetype>
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>
      </property>
+     <widget class="QWidget" name="layoutWidget_2" >
+      <layout class="QGridLayout" >
+       <property name="margin" >
+        <number>0</number>
+       </property>
+       <property name="spacing" >
+        <number>6</number>
+       </property>
+       <item row="1" column="0" >
+        <widget class="QTableWidget" name="jobTable" />
+       </item>
+       <item row="0" column="0" >
+        <widget class="QLabel" name="jobLabel" >
+         <property name="text" >
+          <string>Jobs</string>
+         </property>
+         <property name="alignment" >
+          <set>Qt::AlignCenter</set>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
      <widget class="QTreeWidget" name="directoryTree" />
-     <widget class="QWidget" name="" >
+     <widget class="QWidget" name="layoutWidget" >
       <layout class="QGridLayout" >
        <property name="margin" >
         <number>0</number>
@@ -56,7 +71,7 @@
        </item>
       </layout>
      </widget>
-     <widget class="QWidget" name="" >
+     <widget class="QWidget" name="layoutWidget_3" >
       <layout class="QGridLayout" >
        <property name="margin" >
         <number>0</number>