]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/joblist/joblist.cpp
Oops. When I changed the contents of the field earlier, I forgot to make this change
[bacula/bacula] / bacula / src / qt-console / joblist / joblist.cpp
index a5956f858e599254f3cdcfe8cc0f3cdfd7c5bf07..4116d235d6a83f3322253cb901abd7a51e861857 100644 (file)
@@ -1,14 +1,14 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    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
@@ -26,7 +26,7 @@
    Switzerland, email:ftf@fsfeurope.org.
 */
 /*
- *   Version $Id: joblist.h 4230 2007-02-21 20:07:37Z kerns $
+ *   Version $Id$
  *
  *   Dirk Bartley, March 2007
  */
 #include "joblist.h"
 #include "restore.h"
 #include "joblog/joblog.h"
+#include "jobgraphs/jobplot.h"
 
 /*
  * Constructor for the class
  */
 JobList::JobList(const QString &mediaName, const QString &clientName,
-          const QString &jobName, QTreeWidgetItem *parentTreeWidgetItem)
+          const QString &jobName, const QString &filesetName, QTreeWidgetItem *parentTreeWidgetItem)
 {
    setupUi(this);
    m_name = ""; /* treeWidgetName has a virtual override in this class */
    m_mediaName = mediaName;
    m_clientName = clientName;
    m_jobName = jobName;
+   m_filesetName = filesetName;
+   m_filesetName = filesetName;
    pgInitialize(parentTreeWidgetItem);
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
-   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/emblem-system.svg")));
+   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/emblem-system.png")));
 
    m_resultCount = 0;
    m_populated = false;
    m_closeable = false;
-   if ((m_mediaName != "") || (m_clientName != "") || (m_jobName != ""))
+   if ((m_mediaName != "") || (m_clientName != "") || (m_jobName != "") || (m_filesetName != ""))
       m_closeable=true;
    m_checkCurrentWidget = true;
    createConnections();
@@ -67,6 +70,30 @@ JobList::JobList(const QString &mediaName, const QString &clientName,
    daysCheckBox->setCheckState(mainWin->m_daysLimitCheck ? Qt::Checked : Qt::Unchecked);
    daysSpinBox->setValue(mainWin->m_daysLimitVal);
    dockPage();
+
+   QGridLayout *gridLayout = new QGridLayout(this);
+   gridLayout->setSpacing(6);
+   gridLayout->setMargin(9);
+   gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
+
+   m_splitter = new QSplitter(Qt::Vertical, this);
+   QScrollArea *area = new QScrollArea();
+   area->setObjectName(QString::fromUtf8("area"));
+   area->setWidget(frame);
+   area->setWidgetResizable(true);
+   m_splitter->addWidget(mp_tableWidget);
+   m_splitter->addWidget(area);
+
+   gridLayout->addWidget(m_splitter, 0, 0, 1, 1);
+   readSettings();
+}
+
+/*
+ * Write the m_splitter settings in the destructor
+ */
+JobList::~JobList()
+{
+   writeSettings();
 }
 
 /*
@@ -86,59 +113,39 @@ void JobList::populateTable()
 
    /* Can't do this in constructor because not neccesarily conected in constructor */
    if (!m_populated) {
-      clientsComboBox->addItem("Any");
-      clientsComboBox->addItems(m_console->client_list);
-      int clientIndex = clientsComboBox->findText(m_clientName, Qt::MatchExactly);
+      clientComboBox->addItem(tr("Any"));
+      clientComboBox->addItems(m_console->client_list);
+      int clientIndex = clientComboBox->findText(m_clientName, Qt::MatchExactly);
       if (clientIndex != -1)
-         clientsComboBox->setCurrentIndex(clientIndex);
+         clientComboBox->setCurrentIndex(clientIndex);
 
-      QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
-      if (mainWin->m_sqlDebug) {
-         Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
-      }
-      QStringList results, volumeList;
-      if (m_console->sql_cmd(query, results)) {
-         QString field;
-         QStringList fieldlist;
-         /* Iterate through the lines of results. */
-         foreach (QString resultline, results) {
-            fieldlist = resultline.split("\t");
-            volumeList.append(fieldlist[0]);
-         } /* foreach resultline */
-      } /* if results from query */
-      volumeComboBox->addItem("Any");
+      QStringList volumeList;
+      m_console->getVolumeList(volumeList);
+      volumeComboBox->addItem(tr("Any"));
       volumeComboBox->addItems(volumeList);
       int volumeIndex = volumeComboBox->findText(m_mediaName, Qt::MatchExactly);
       if (volumeIndex != -1) {
          volumeComboBox->setCurrentIndex(volumeIndex);
       }
-      jobComboBox->addItem("Any");
+      jobComboBox->addItem(tr("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->addItem(tr("Any"));
       levelComboBox->addItems( QStringList() << "F" << "D" << "I");
-      purgedComboBox->addItem("Any");
+      purgedComboBox->addItem(tr("Any"));
       purgedComboBox->addItems( QStringList() << "0" << "1");
-      statusComboBox->addItem("Any");
-      fileSetComboBox->addItem("Any");
+      fileSetComboBox->addItem(tr("Any"));
       fileSetComboBox->addItems(m_console->fileset_list);
-      QString statusQuery("SELECT JobStatusLong FROM Status");
-      if (mainWin->m_sqlDebug) {
-         Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
+      int filesetIndex = fileSetComboBox->findText(m_filesetName, Qt::MatchExactly);
+      if (filesetIndex != -1) {
+         fileSetComboBox->setCurrentIndex(filesetIndex);
       }
-      QStringList statusResults, statusLongList;
-      if (m_console->sql_cmd(statusQuery, statusResults)) {
-         QString field;
-         QStringList fieldlist;
-         /* Iterate through the lines of results. */
-         foreach (QString resultline, statusResults) {
-            fieldlist = resultline.split("\t");
-            statusLongList.append(fieldlist[0]);
-         } /* foreach resultline */
-      } /* if results from statusquery */
+      QStringList statusLongList;
+      m_console->getStatusList(statusLongList);
+      statusComboBox->addItem(tr("Any"));
       statusComboBox->addItems(statusLongList);
    }
 
@@ -147,48 +154,53 @@ void JobList::populateTable()
    int volumeIndex = volumeComboBox->currentIndex();
    if (volumeIndex != -1)
       m_mediaName = volumeComboBox->itemText(volumeIndex);
-   query += "SELECT DISTINCT Job.Jobid AS Id, Job.Name AS JobName, Client.Name AS Client,"
+   QString distinct = "";
+   if (m_mediaName != tr("Any")) { distinct = "DISTINCT "; }
+   query += "SELECT " + distinct + "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"
-            " LEFT OUTER JOIN Client ON (Client.ClientId=Job.ClientId)"
-            " LEFT OUTER JOIN FileSet ON (FileSet.FileSetId=Job.FileSetId)"
-            " LEFT OUTER JOIN Status ON (Job.JobStatus=Status.JobStatus)"
-            " LEFT OUTER JOIN JobMedia ON (JobMedia.JobId=Job.JobId)"
-            " LEFT OUTER JOIN Media ON (JobMedia.MediaId=Media.MediaId)";
+            " 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") {
+   if (m_mediaName != tr("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 = clientsComboBox->currentIndex();
+   int clientIndex = clientComboBox->currentIndex();
    if (clientIndex != -1)
-      m_clientName = clientsComboBox->itemText(clientIndex);
-   if (m_clientName != "Any") {
+      m_clientName = clientComboBox->itemText(clientIndex);
+   if (m_clientName != tr("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")) {
+   if ((jobIndex != -1) && (jobComboBox->itemText(jobIndex) != tr("Any"))) {
       conditions.append("Job.Name='" + jobComboBox->itemText(jobIndex) + "'");
    }
    int levelIndex = levelComboBox->currentIndex();
-   if ((levelIndex != -1) && (levelComboBox->itemText(levelIndex) != "Any")) {
+   if ((levelIndex != -1) && (levelComboBox->itemText(levelIndex) != tr("Any"))) {
       conditions.append("Job.Level='" + levelComboBox->itemText(levelIndex) + "'");
    }
    int statusIndex = statusComboBox->currentIndex();
-   if ((statusIndex != -1) && (statusComboBox->itemText(statusIndex) != "Any")) {
+   if ((statusIndex != -1) && (statusComboBox->itemText(statusIndex) != tr("Any"))) {
       conditions.append("Status.JobStatusLong='" + statusComboBox->itemText(statusIndex) + "'");
    }
    int purgedIndex = purgedComboBox->currentIndex();
-   if ((purgedIndex != -1) && (purgedComboBox->itemText(purgedIndex) != "Any")) {
+   if ((purgedIndex != -1) && (purgedComboBox->itemText(purgedIndex) != tr("Any"))) {
       conditions.append("Job.PurgedFiles='" + purgedComboBox->itemText(purgedIndex) + "'");
    }
    int fileSetIndex = fileSetComboBox->currentIndex();
-   if ((fileSetIndex != -1) && (fileSetComboBox->itemText(fileSetIndex) != "Any")) {
+   if (fileSetIndex != -1)
+      m_filesetName = fileSetComboBox->itemText(fileSetIndex);
+   if ((fileSetIndex != -1) && (fileSetComboBox->itemText(fileSetIndex) != tr("Any"))) {
       conditions.append("FileSet.FileSet='" + fileSetComboBox->itemText(fileSetIndex) + "'");
    }
    /* If Limit check box For limit by days is checked  */
@@ -217,11 +229,17 @@ void JobList::populateTable()
 
    /* Set up the Header for the table */
    QStringList headerlist = (QStringList()
-      << "Job Id" << "Job Name" << "Client" << "Job Starttime" << "Job Type" 
-      << "Job Level" << "Job Files" << "Job Bytes" << "Job Status"  << "Purged" << "File Set" );
-   m_purgedIndex = headerlist.indexOf("Purged");
-   m_typeIndex = headerlist.indexOf("Job Type");
-   m_statusIndex = headerlist.indexOf("Job Status");
+      << tr("Job Id") << tr("Job Name") << tr("Client") << tr("Job Starttime") 
+      << tr("Job Type") << tr("Job Level") << tr("Job Files") 
+      << tr("Job Bytes") << tr("Job Status")  << tr("Purged") << tr("File Set"));
+   m_jobIdIndex = headerlist.indexOf(tr("Job Id"));
+   m_purgedIndex = headerlist.indexOf(tr("Purged"));
+   m_typeIndex = headerlist.indexOf(tr("Job Type"));
+   m_statusIndex = headerlist.indexOf(tr("Job Status"));
+   m_startIndex = headerlist.indexOf(tr("Job Starttime"));
+   m_filesIndex = headerlist.indexOf(tr("Job Files"));
+   m_bytesIndex = headerlist.indexOf(tr("Job Bytes"));
+   int jobLevelIndex = headerlist.indexOf(tr("Job Level"));
 
    /* Initialize the QTableWidget */
    m_checkCurrentWidget = false;
@@ -255,12 +273,39 @@ void JobList::populateTable()
                m_statusIndexDone = true;
                statusCode = field;
             } else {
-               p_tableitem = new QTableWidgetItem(field,1);
-               p_tableitem->setFlags(0);
+               p_tableitem = new QTableWidgetItem(field, 1);
+               p_tableitem->setFlags(Qt::ItemIsSelectable);
                p_tableitem->setForeground(blackBrush);
                mp_tableWidget->setItem(row, column, p_tableitem);
                if (column == m_statusIndex)
                   setStatusColor(p_tableitem, statusCode);
+               if (column == m_bytesIndex) {
+                  QString text;
+                  bool okay;
+                  qlonglong bytes = field.toULongLong(&okay);
+                  if (okay){
+                     QString test =  QString("%1").arg(bytes);
+                     mainWin->hrConvert(text, bytes);
+                     p_tableitem->setText(text);
+                  } else { Pmsg1(000, "conversion error %s\n", field.toUtf8().data()); }
+               } else if (column == m_purgedIndex) {
+                  bool okay;
+                  int isPurged = field.toInt(&okay);
+                  if (okay){
+                     if (isPurged) { p_tableitem->setText(tr("IS"));
+                     } else { p_tableitem->setText(tr("NOT")); }
+                  }
+               } else if (column == m_typeIndex) {
+                  if (field == "B") { p_tableitem->setText(tr("Backup")); }
+                  else if (field == "R") { p_tableitem->setText(tr("Restore")); }
+               } else if (column == jobLevelIndex) {
+                  if (field == "F") { p_tableitem->setText("Full"); }
+                  else if (field == "D") { p_tableitem->setText("Diff"); }
+                  else if (field == "I") { p_tableitem->setText("Incr"); }
+               }   
+               if ((column == m_bytesIndex) || (column == m_filesIndex)){
+                  p_tableitem->setTextAlignment(Qt::AlignRight);
+               }
                column++;
             }
          }
@@ -271,10 +316,10 @@ void JobList::populateTable()
    mp_tableWidget->resizeColumnsToContents();
    mp_tableWidget->resizeRowsToContents();
    mp_tableWidget->verticalHeader()->hide();
-   if ((m_mediaName != "Any") && (m_resultCount == 0)){
+   if ((m_mediaName != tr("Any")) && (m_resultCount == 0)){
       /* for context sensitive searches, let the user know if there were no
        * results */
-      QMessageBox::warning(this, tr("Bat"),
+      QMessageBox::warning(this, "Bat",
           tr("The Jobs query returned no results.\n"
          "Press OK to continue?"), QMessageBox::Ok );
    }
@@ -323,7 +368,7 @@ void JobList::currentStackItem()
  */
 void JobList::treeWidgetName(QString &desc)
 {
-   if ((m_mediaName == "") && (m_clientName == "") &&  (m_jobName == "")) {
+   if ((m_mediaName == "") && (m_clientName == "") && (m_jobName == "") && (m_filesetName == "")) {
       desc = "JobList";
    } else {
       desc = "JobList ";
@@ -336,6 +381,9 @@ void JobList::treeWidgetName(QString &desc)
       if (m_jobName != "" ) {
          desc += "of Job " + m_jobName;
       }
+      if (m_filesetName != "" ) {
+         desc += "of fileset " + m_filesetName;
+      }
    }
 }
 
@@ -349,12 +397,13 @@ void JobList::tableItemChanged(QTableWidgetItem *currentItem, QTableWidgetItem *
       int row = currentItem->row();
       QTableWidgetItem* jobitem = mp_tableWidget->item(row, 0);
       m_currentJob = jobitem->text();
+      selectedJobsGet();
 
       /* include purged action or not */
       jobitem = mp_tableWidget->item(row, m_purgedIndex);
       QString purged = jobitem->text();
       mp_tableWidget->removeAction(actionPurgeFiles);
-      if (purged == "0") {
+      if (purged == "NOT") {
          mp_tableWidget->addAction(actionPurgeFiles);
       }
       /* include restore from time and job action or not */
@@ -362,7 +411,7 @@ void JobList::tableItemChanged(QTableWidgetItem *currentItem, QTableWidgetItem *
       QString type = jobitem->text();
       mp_tableWidget->removeAction(actionRestoreFromJob);
       mp_tableWidget->removeAction(actionRestoreFromTime);
-      if (type == "B") {
+      if (type == "Backup") {
          mp_tableWidget->addAction(actionRestoreFromJob);
          mp_tableWidget->addAction(actionRestoreFromTime);
       }
@@ -387,6 +436,7 @@ void JobList::createConnections()
    connect(actionRefreshJobList, SIGNAL(triggered()), this,
                 SLOT(populateTable()));
    connect(refreshButton, SIGNAL(pressed()), this, SLOT(populateTable()));
+   connect(graphButton, SIGNAL(pressed()), this, SLOT(graphTable()));
    /* for the tableItemChanged to maintain m_currentJob */
    connect(mp_tableWidget, SIGNAL(
            currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
@@ -473,13 +523,12 @@ void JobList::consoleListVolumes()
 void JobList::consoleListJobTotals()
 {
    QString cmd("list jobtotals");
-   cmd += m_currentJob;
    if (mainWin->m_longList) { cmd.prepend("l"); }
    consoleCommand(cmd);
 }
 void JobList::consoleDeleteJob()
 {
-   if (QMessageBox::warning(this, tr("Bat"),
+   if (QMessageBox::warning(this, "Bat",
       tr("Are you sure you want to delete??  !!!.\n"
 "This delete command is used to delete a Job record and all associated catalog"
 " records that were created. This command operates only on the Catalog"
@@ -492,12 +541,12 @@ void JobList::consoleDeleteJob()
       == QMessageBox::Cancel) { return; }
 
    QString cmd("delete job jobid=");
-   cmd += m_currentJob;
+   cmd += m_selectedJobs;
    consoleCommand(cmd);
 }
 void JobList::consolePurgeFiles()
 {
-   if (QMessageBox::warning(this, tr("Bat"),
+   if (QMessageBox::warning(this, "Bat",
       tr("Are you sure you want to purge ??  !!!.\n"
 "The Purge command will delete associated Catalog database records from Jobs and"
 " Volumes without considering the retention period. Purge  works only on the"
@@ -548,3 +597,79 @@ void JobList::consoleCancelJob()
    cmd += m_currentJob;
    consoleCommand(cmd);
 }
+
+/*
+ * Graph this table
+ */
+void JobList::graphTable()
+{
+   JobPlotPass pass;
+   pass.recordLimitCheck = limitCheckBox->checkState();
+   pass.daysLimitCheck = daysCheckBox->checkState();
+   pass.recordLimitSpin = limitSpinBox->value();
+   pass.daysLimitSpin = daysSpinBox->value();
+   pass.jobCombo = jobComboBox->currentText();
+   pass.clientCombo = clientComboBox->currentText();
+   pass.volumeCombo = volumeComboBox->currentText();
+   pass.fileSetCombo = fileSetComboBox->currentText();
+   pass.purgedCombo = purgedComboBox->currentText();
+   pass.levelCombo = levelComboBox->currentText();
+   pass.statusCombo = statusComboBox->currentText();
+   pass.use = true;
+   QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
+   new JobPlot(pageSelectorTreeWidgetItem, pass);
+}
+/*
+ * Save user settings associated with this page
+ */
+void JobList::writeSettings()
+{
+   QSettings settings(m_console->m_dir->name(), "bat");
+   settings.beginGroup(m_groupText);
+   settings.setValue(m_splitText, m_splitter->saveState());
+   settings.endGroup();
+}
+
+/*
+ * Read and restore user settings associated with this page
+ */
+void JobList::readSettings()
+{
+   m_groupText = "JobListPage";
+   m_splitText = "splitterSizes_1";
+   QSettings settings(m_console->m_dir->name(), "bat");
+   settings.beginGroup(m_groupText);
+   m_splitter->restoreState(settings.value(m_splitText).toByteArray());
+   settings.endGroup();
+}
+
+/*
+ * Function to fill m_selectedJobsCount and m_selectedJobs with selected values
+ */
+void JobList::selectedJobsGet()
+{
+   QList<int> rowList;
+   QList<QTableWidgetItem *> sitems = mp_tableWidget->selectedItems();
+   foreach (QTableWidgetItem *sitem, sitems) {
+      int row = sitem->row();
+      if (!rowList.contains(row)) {
+         rowList.append(row);
+      }
+   }
+
+   m_selectedJobs = "";
+   bool first = true;
+   foreach(int row, rowList) {
+      QTableWidgetItem * sitem = mp_tableWidget->item(row, m_jobIdIndex);
+      if (!first) m_selectedJobs.append(",");
+      else first = false;
+      m_selectedJobs.append(sitem->text());
+   }
+   m_selectedJobsCount = rowList.count();
+   if (m_selectedJobsCount > 1) {
+      QString text = QString("Delete list of %1 Jobs").arg(m_selectedJobsCount);
+      actionDeleteJob->setText(text);
+   } else {
+      actionDeleteJob->setText("Delete Single Job");
+   }
+}