[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bacula-devel] patch: more formatting changes for bat



The attached patch makes other (trivial) formatting changes to bat:
- fix column size on fileset tree
- reformats clients page
- enable "run job" menuitem also for verify jobs, removes for disabled jobs
- reorder job list so that scheduled but not started jobs are at top

N.B.
Must be applied on top of my previous formatting patch

Riccardo
diff -r 3ca0bd94d07c bacula/src/qt-console/clients/clients.cpp
--- a/bacula/src/qt-console/clients/clients.cpp	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/clients/clients.cpp	Sun May 04 20:26:33 2008 +0200
@@ -40,6 +40,7 @@
 #include "bat.h"
 #include "clients/clients.h"
 #include "run/run.h"
+#include "util/fmtwidgetitem.h"
 
 Clients::Clients()
 {
@@ -70,7 +71,7 @@
  */
 void Clients::populateTree()
 {
-   QTreeWidgetItem *clientItem, *topItem;
+   QTreeWidgetItem *topItem;
 
    if (!m_console->preventInUseConnect())
       return;
@@ -90,10 +91,9 @@
    mp_treeWidget->setHeaderLabels(headerlist);
 
    foreach (QString clientName, m_console->client_list){
-      clientItem = new QTreeWidgetItem(topItem);
-      clientItem->setText(0, clientName);
-      clientItem->setData(0, Qt::UserRole, 1);
-      clientItem->setExpanded(true);
+      ItemFormatter clientItem(*topItem, 1);
+      clientItem.setTextFld(0, clientName);
+      clientItem.widget()->setExpanded(true);
 
       /* Set up query QString and header QStringList */
       QString query("");
@@ -112,21 +112,33 @@
          int resultCount = results.count();
          if (resultCount == 1){
             QString resultline;
-            QString field;
             QStringList fieldlist;
             /* there will only be one of these */
             foreach (resultline, results) {
                fieldlist = resultline.split("\t");
-               int index = 0;
-               /* Iterate through fields in the record */
-               foreach (field, fieldlist) {
-                  field = field.trimmed();  /* strip leading & trailing spaces */
-                  clientItem->setData(index+1, Qt::UserRole, 1);
-                  /* Put media fields under the pool tree item */
-                  clientItem->setData(index+1, Qt::UserRole, 1);
-                  clientItem->setText(index+1, field);
-                  index++;
-               }
+ 
+	       if (fieldlist.size() < 5)
+		  continue; // some fields missing, ignore row
+
+	       /* Iterate through fields in the record */
+	       QStringListIterator fld(fieldlist);
+	       int index = 1;
+
+ 	       /* file retention */
+	       clientItem.setDurationFld(index++, fld.next()); 
+
+ 	       /* job retention */
+	       clientItem.setDurationFld(index++, fld.next()); 
+
+ 	       /* autoprune */
+	       clientItem.setBoolFld(index++, fld.next()); 
+
+ 	       /* id */
+	       clientItem.setNumericFld(index++, fld.next()); 
+
+ 	       /* uname */
+	       clientItem.setTextFld(index++, fld.next()); 
+
             }
          }
       }
diff -r 3ca0bd94d07c bacula/src/qt-console/fileset/fileset.cpp
--- a/bacula/src/qt-console/fileset/fileset.cpp	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/fileset/fileset.cpp	Sun May 04 20:26:33 2008 +0200
@@ -132,7 +132,7 @@
       }
    }
    /* Resize the columns */
-   for (int cnter=1; cnter<headerlist.size(); cnter++) {
+   for (int cnter=0; cnter<headerlist.size(); cnter++) {
       mp_treeWidget->resizeColumnToContents(cnter);
    }
 
diff -r 3ca0bd94d07c bacula/src/qt-console/joblist/joblist.cpp
--- a/bacula/src/qt-console/joblist/joblist.cpp	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/joblist/joblist.cpp	Sun May 04 20:26:33 2008 +0200
@@ -112,118 +112,11 @@
        return;
 
    /* Can't do this in constructor because not neccesarily conected in constructor */
-   if (!m_populated) {
-      clientComboBox->addItem("Any");
-      clientComboBox->addItems(m_console->client_list);
-      int clientIndex = clientComboBox->findText(m_clientName, Qt::MatchExactly);
-      if (clientIndex != -1)
-         clientComboBox->setCurrentIndex(clientIndex);
-
-      QStringList volumeList;
-      m_console->getVolumeList(volumeList);
-      volumeComboBox->addItem("Any");
-      volumeComboBox->addItems(volumeList);
-      int volumeIndex = volumeComboBox->findText(m_mediaName, Qt::MatchExactly);
-      if (volumeIndex != -1) {
-         volumeComboBox->setCurrentIndex(volumeIndex);
-      }
-      jobComboBox->addItem("Any");
-      jobComboBox->addItems(m_console->job_list);
-      int jobIndex = jobComboBox->findText(m_jobName, Qt::MatchExactly);
-      if (jobIndex != -1) {
-         jobComboBox->setCurrentIndex(jobIndex);
-      }
-      levelComboBox->addItem("Any");
-      levelComboBox->addItems( QStringList() << "F" << "D" << "I");
-      purgedComboBox->addItem("Any");
-      purgedComboBox->addItems( QStringList() << "0" << "1");
-      fileSetComboBox->addItem("Any");
-      fileSetComboBox->addItems(m_console->fileset_list);
-      int filesetIndex = fileSetComboBox->findText(m_filesetName, Qt::MatchExactly);
-      if (filesetIndex != -1) {
-         fileSetComboBox->setCurrentIndex(filesetIndex);
-      }
-      QStringList statusLongList;
-      m_console->getStatusList(statusLongList);
-      statusComboBox->addItem("Any");
-      statusComboBox->addItems(statusLongList);
-   }
+   prepareFilterWidgets();
 
    /* Set up query */
-   QString query("");
-   int volumeIndex = volumeComboBox->currentIndex();
-   if (volumeIndex != -1)
-      m_mediaName = volumeComboBox->itemText(volumeIndex);
-   query += "SELECT Job.Jobid AS Id, Job.Name AS JobName, " 
-            " Client.Name AS Client,"
-            " Job.Starttime AS JobStart, Job.Type AS JobType,"
-            " Job.Level AS BackupLevel, Job.Jobfiles AS FileCount,"
-            " Job.JobBytes AS Bytes,"
-            " Job.JobStatus AS Status, Status.JobStatusLong AS StatusLong,"
-            " Job.PurgedFiles AS Purged, FileSet.FileSet"
-            " FROM Job"
-            " JOIN Client ON (Client.ClientId=Job.ClientId)"
-            " JOIN Status ON (Job.JobStatus=Status.JobStatus)"
-            " LEFT OUTER JOIN FileSet ON (FileSet.FileSetId=Job.FileSetId) ";
-   QStringList conditions;
-   if (m_mediaName != "Any") {
-      query += " LEFT OUTER JOIN JobMedia ON (JobMedia.JobId=Job.JobId) "
-               " LEFT OUTER JOIN Media ON (JobMedia.MediaId=Media.MediaId) ";
-      conditions.append("Media.VolumeName='" + m_mediaName + "'");
-   }
-   int clientIndex = clientComboBox->currentIndex();
-   if (clientIndex != -1)
-      m_clientName = clientComboBox->itemText(clientIndex);
-   if (m_clientName != "Any") {
-      conditions.append("Client.Name='" + m_clientName + "'");
-   }
-   int jobIndex = jobComboBox->currentIndex();
-   if (jobIndex != -1)
-      m_jobName = jobComboBox->itemText(jobIndex);
-   if ((jobIndex != -1) && (jobComboBox->itemText(jobIndex) != "Any")) {
-      conditions.append("Job.Name='" + jobComboBox->itemText(jobIndex) + "'");
-   }
-   int levelIndex = levelComboBox->currentIndex();
-   if ((levelIndex != -1) && (levelComboBox->itemText(levelIndex) != "Any")) {
-      conditions.append("Job.Level='" + levelComboBox->itemText(levelIndex) + "'");
-   }
-   int statusIndex = statusComboBox->currentIndex();
-   if ((statusIndex != -1) && (statusComboBox->itemText(statusIndex) != "Any")) {
-      conditions.append("Status.JobStatusLong='" + statusComboBox->itemText(statusIndex) + "'");
-   }
-   int purgedIndex = purgedComboBox->currentIndex();
-   if ((purgedIndex != -1) && (purgedComboBox->itemText(purgedIndex) != "Any")) {
-      conditions.append("Job.PurgedFiles='" + purgedComboBox->itemText(purgedIndex) + "'");
-   }
-   int fileSetIndex = fileSetComboBox->currentIndex();
-   if (fileSetIndex != -1)
-      m_filesetName = fileSetComboBox->itemText(fileSetIndex);
-   if ((fileSetIndex != -1) && (fileSetComboBox->itemText(fileSetIndex) != "Any")) {
-      conditions.append("FileSet.FileSet='" + fileSetComboBox->itemText(fileSetIndex) + "'");
-   }
-   /* If Limit check box For limit by days is checked  */
-   if (daysCheckBox->checkState() == Qt::Checked) {
-      QDateTime stamp = QDateTime::currentDateTime().addDays(-daysSpinBox->value());
-      QString since = stamp.toString(Qt::ISODate);
-      conditions.append("Job.Starttime>'" + since + "'");
-   }
-   bool first = true;
-   foreach (QString condition, conditions) {
-      if (first) {
-         query += " WHERE " + condition;
-         first = false;
-      } else {
-         query += " AND " + condition;
-      }
-   }
-   /* Descending */
-   query += " ORDER BY Job.Starttime DESC, Job.JobId DESC";
-   /* If Limit check box for limit records returned is checked  */
-   if (limitCheckBox->checkState() == Qt::Checked) {
-      QString limit;
-      limit.setNum(limitSpinBox->value());
-      query += " LIMIT " + limit;
-   }
+   QString query;
+   fillQueryString(query);
 
    /* Set up the Header for the table */
    QStringList headerlist = (QStringList()
@@ -292,6 +185,125 @@
          "Press OK to continue?"), QMessageBox::Ok );
    }
 }
+
+void JobList::prepareFilterWidgets()
+{
+   if (!m_populated) {
+      clientComboBox->addItem("Any");
+      clientComboBox->addItems(m_console->client_list);
+      int clientIndex = clientComboBox->findText(m_clientName, Qt::MatchExactly);
+      if (clientIndex != -1)
+         clientComboBox->setCurrentIndex(clientIndex);
+
+      QStringList volumeList;
+      m_console->getVolumeList(volumeList);
+      volumeComboBox->addItem("Any");
+      volumeComboBox->addItems(volumeList);
+      int volumeIndex = volumeComboBox->findText(m_mediaName, Qt::MatchExactly);
+      if (volumeIndex != -1) {
+         volumeComboBox->setCurrentIndex(volumeIndex);
+      }
+      jobComboBox->addItem("Any");
+      jobComboBox->addItems(m_console->job_list);
+      int jobIndex = jobComboBox->findText(m_jobName, Qt::MatchExactly);
+      if (jobIndex != -1) {
+         jobComboBox->setCurrentIndex(jobIndex);
+      }
+      levelComboBox->addItem("Any");
+      levelComboBox->addItems( QStringList() << "F" << "D" << "I");
+      purgedComboBox->addItem("Any");
+      purgedComboBox->addItems( QStringList() << "0" << "1");
+      fileSetComboBox->addItem("Any");
+      fileSetComboBox->addItems(m_console->fileset_list);
+      int filesetIndex = fileSetComboBox->findText(m_filesetName, Qt::MatchExactly);
+      if (filesetIndex != -1) {
+         fileSetComboBox->setCurrentIndex(filesetIndex);
+      }
+      QStringList statusLongList;
+      m_console->getStatusList(statusLongList);
+      statusComboBox->addItem("Any");
+      statusComboBox->addItems(statusLongList);
+   }
+}
+
+void JobList::fillQueryString(QString &query)
+{
+   query = "";
+   int volumeIndex = volumeComboBox->currentIndex();
+   if (volumeIndex != -1)
+      m_mediaName = volumeComboBox->itemText(volumeIndex);
+   query += "SELECT Job.Jobid AS Id, Job.Name AS JobName, " 
+            " Client.Name AS Client,"
+            " Job.Starttime AS JobStart, Job.Type AS JobType,"
+            " Job.Level AS BackupLevel, Job.Jobfiles AS FileCount,"
+            " Job.JobBytes AS Bytes,"
+            " Job.JobStatus AS Status, Status.JobStatusLong AS StatusLong,"
+            " Job.PurgedFiles AS Purged, FileSet.FileSet"
+            " FROM Job"
+            " JOIN Client ON (Client.ClientId=Job.ClientId)"
+            " JOIN Status ON (Job.JobStatus=Status.JobStatus)"
+            " LEFT OUTER JOIN FileSet ON (FileSet.FileSetId=Job.FileSetId) ";
+   QStringList conditions;
+   if (m_mediaName != "Any") {
+      query += " LEFT OUTER JOIN JobMedia ON (JobMedia.JobId=Job.JobId) "
+               " LEFT OUTER JOIN Media ON (JobMedia.MediaId=Media.MediaId) ";
+      conditions.append("Media.VolumeName='" + m_mediaName + "'");
+   }
+   int clientIndex = clientComboBox->currentIndex();
+   if (clientIndex != -1)
+      m_clientName = clientComboBox->itemText(clientIndex);
+   if (m_clientName != "Any") {
+      conditions.append("Client.Name='" + m_clientName + "'");
+   }
+   int jobIndex = jobComboBox->currentIndex();
+   if (jobIndex != -1)
+      m_jobName = jobComboBox->itemText(jobIndex);
+   if ((jobIndex != -1) && (jobComboBox->itemText(jobIndex) != "Any")) {
+      conditions.append("Job.Name='" + jobComboBox->itemText(jobIndex) + "'");
+   }
+   int levelIndex = levelComboBox->currentIndex();
+   if ((levelIndex != -1) && (levelComboBox->itemText(levelIndex) != "Any")) {
+      conditions.append("Job.Level='" + levelComboBox->itemText(levelIndex) + "'");
+   }
+   int statusIndex = statusComboBox->currentIndex();
+   if ((statusIndex != -1) && (statusComboBox->itemText(statusIndex) != "Any")) {
+      conditions.append("Status.JobStatusLong='" + statusComboBox->itemText(statusIndex) + "'");
+   }
+   int purgedIndex = purgedComboBox->currentIndex();
+   if ((purgedIndex != -1) && (purgedComboBox->itemText(purgedIndex) != "Any")) {
+      conditions.append("Job.PurgedFiles='" + purgedComboBox->itemText(purgedIndex) + "'");
+   }
+   int fileSetIndex = fileSetComboBox->currentIndex();
+   if (fileSetIndex != -1)
+      m_filesetName = fileSetComboBox->itemText(fileSetIndex);
+   if ((fileSetIndex != -1) && (fileSetComboBox->itemText(fileSetIndex) != "Any")) {
+      conditions.append("FileSet.FileSet='" + fileSetComboBox->itemText(fileSetIndex) + "'");
+   }
+   /* If Limit check box For limit by days is checked  */
+   if (daysCheckBox->checkState() == Qt::Checked) {
+      QDateTime stamp = QDateTime::currentDateTime().addDays(-daysSpinBox->value());
+      QString since = stamp.toString(Qt::ISODate);
+      conditions.append("Job.Starttime>'" + since + "'");
+   }
+   bool first = true;
+   foreach (QString condition, conditions) {
+      if (first) {
+         query += " WHERE " + condition;
+         first = false;
+      } else {
+         query += " AND " + condition;
+      }
+   }
+   /* Descending */
+   query += " ORDER BY Job.Starttime=0 DESC, Job.Starttime DESC, Job.JobId DESC";
+   /* If Limit check box for limit records returned is checked  */
+   if (limitCheckBox->checkState() == Qt::Checked) {
+      QString limit;
+      limit.setNum(limitSpinBox->value());
+      query += " LIMIT " + limit;
+   }
+}
+
 
 void JobList::setStatusColor(QTableWidgetItem *item, QString &field)
 {
diff -r 3ca0bd94d07c bacula/src/qt-console/joblist/joblist.h
--- a/bacula/src/qt-console/joblist/joblist.h	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/joblist/joblist.h	Sun May 04 20:26:33 2008 +0200
@@ -74,6 +74,8 @@
    void setStatusColor(QTableWidgetItem *item, QString &field);
    void writeSettings();
    void readSettings();
+   void prepareFilterWidgets();
+   void fillQueryString(QString &query);
    QSplitter *m_splitter;
    QString m_groupText;
    QString m_splitText;
diff -r 3ca0bd94d07c bacula/src/qt-console/jobs/jobs.cpp
--- a/bacula/src/qt-console/jobs/jobs.cpp	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/jobs/jobs.cpp	Sun May 04 20:26:33 2008 +0200
@@ -38,6 +38,7 @@
 #include "bat.h"
 #include "jobs/jobs.h"
 #include "run/run.h"
+#include "util/fmtwidgetitem.h"
 
 Jobs::Jobs()
 {
@@ -68,7 +69,7 @@
  */
 void Jobs::populateTree()
 {
-   QTreeWidgetItem *jobsItem, *topItem;
+   QTreeWidgetItem *topItem;
 
    if (!m_console->preventInUseConnect())
       return;
@@ -80,6 +81,7 @@
       << "Catalog" << "Enabled");
 
    m_typeIndex = headerlist.indexOf("Type");
+   m_enabledIndex = headerlist.indexOf("Enabled");
    topItem = new QTreeWidgetItem(mp_treeWidget);
    topItem->setText(0, "Jobs");
    topItem->setData(0, Qt::UserRole, 0);
@@ -89,31 +91,23 @@
    mp_treeWidget->setHeaderLabels(headerlist);
 
    foreach (QString jobName, m_console->job_list){
-      jobsItem = new QTreeWidgetItem(topItem);
-      jobsItem->setText(0, jobName);
-      //jobsItem->setExpanded(true);
-
-      for (int i=0; i<headerlist.count(); i++)
-         jobsItem->setData(i, Qt::UserRole, 1);
+      int col = 0;
+      ItemFormatter jobsItem(*topItem, 1);
+      jobsItem.setTextFld(col++, jobName); 
 
       job_defaults job_defs;
       job_defs.job_name = jobName;
       if (m_console->get_job_defaults(job_defs)) {
-         int col = 1;
-         jobsItem->setText(col++, job_defs.pool_name);
-         jobsItem->setText(col++, job_defs.messages_name);
-         jobsItem->setText(col++, job_defs.client_name);
-         jobsItem->setText(col++, job_defs.store_name);
-         jobsItem->setText(col++, job_defs.where);
-         jobsItem->setText(col++, job_defs.level);
-         jobsItem->setText(col++, job_defs.type);
-         jobsItem->setText(col++, job_defs.fileset_name);
-         jobsItem->setText(col++, job_defs.catalog_name);
-         if (job_defs.enabled) {
-            jobsItem->setText(col++, "Yes");
-         } else {
-            jobsItem->setText(col++, "No");
-         }
+         jobsItem.setTextFld(col++, job_defs.pool_name);
+         jobsItem.setTextFld(col++, job_defs.messages_name);
+         jobsItem.setTextFld(col++, job_defs.client_name);
+         jobsItem.setTextFld(col++, job_defs.store_name);
+         jobsItem.setTextFld(col++, job_defs.where);
+         jobsItem.setTextFld(col++, job_defs.level);
+         jobsItem.setTextFld(col++, job_defs.type);
+         jobsItem.setTextFld(col++, job_defs.fileset_name);
+         jobsItem.setTextFld(col++, job_defs.catalog_name);
+         jobsItem.setBoolFld(col++, job_defs.enabled);
       }
    }
    /* Resize the columns */
@@ -156,12 +150,13 @@
          m_currentlyselected=currentwidgetitem->text(0);
          mp_treeWidget->addAction(actionConsoleListFiles);
          mp_treeWidget->addAction(actionConsoleListVolumes);
-         mp_treeWidget->addAction(actionConsoleListNextVolume);
+	 if (currentwidgetitem->text(m_typeIndex) == "Backup")
+	    mp_treeWidget->addAction(actionConsoleListNextVolume);
          mp_treeWidget->addAction(actionConsoleEnableJob);
          mp_treeWidget->addAction(actionConsoleDisableJob);
          mp_treeWidget->addAction(actionConsoleCancel);
          mp_treeWidget->addAction(actionJobListQuery);
-         if (currentwidgetitem->text(m_typeIndex) == "Backup")
+	 if (currentwidgetitem->text(m_enabledIndex) == "Yes")
             mp_treeWidget->addAction(actionRunJob);
       }
    }
diff -r 3ca0bd94d07c bacula/src/qt-console/jobs/jobs.h
--- a/bacula/src/qt-console/jobs/jobs.h	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/jobs/jobs.h	Sun May 04 20:26:33 2008 +0200
@@ -68,6 +68,7 @@
    bool m_populated;
    bool m_checkcurwidget;
    int m_typeIndex;
+   int m_enabledIndex;
 };
 
 #endif /* _JOBS_H_ */
diff -r 3ca0bd94d07c bacula/src/qt-console/run/run.cpp
--- a/bacula/src/qt-console/run/run.cpp	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/run/run.cpp	Sun May 04 20:26:33 2008 +0200
@@ -133,6 +133,7 @@
    (void)index;
    job_defs.job_name = jobCombo->currentText();
    if (m_console->get_job_defaults(job_defs)) {
+     typeLabel->setText("<H3>"+job_defs.type+"</H3>");
       filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
       levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
       clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
diff -r 3ca0bd94d07c bacula/src/qt-console/util/fmtwidgetitem.cpp
--- a/bacula/src/qt-console/util/fmtwidgetitem.cpp	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/util/fmtwidgetitem.cpp	Sun May 04 20:26:33 2008 +0200
@@ -50,6 +50,13 @@
 void ItemFormatter::setBoolFld(int index, const QString &fld, bool center)
 {
    if (fld.trimmed().toInt())
+     setTextFld(index, "Yes", center);
+   else
+     setTextFld(index, "No", center);
+}
+void ItemFormatter::setBoolFld(int index, bool fld, bool center)
+{
+   if (fld)
      setTextFld(index, "Yes", center);
    else
      setTextFld(index, "No", center);
diff -r 3ca0bd94d07c bacula/src/qt-console/util/fmtwidgetitem.h
--- a/bacula/src/qt-console/util/fmtwidgetitem.h	Sun May 04 20:25:58 2008 +0200
+++ b/bacula/src/qt-console/util/fmtwidgetitem.h	Sun May 04 20:26:33 2008 +0200
@@ -49,6 +49,7 @@
 
    /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
    void setBoolFld(int index, const QString &fld, bool center = true);
+   void setBoolFld(int index, bool fld, bool center = true);
 
    /* Normal text field. Centers field if center true*/
    void setTextFld(int index, const QString &fld, bool center = false);
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Bacula-devel mailing list
Bacula-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/bacula-devel


This mailing list archive is a service of Copilotco.