]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/medialist/medialist.cpp
Apply win32-fixes patch from Riccardo that makes the Win32
[bacula/bacula] / bacula / src / qt-console / medialist / medialist.cpp
index 8a871dcf55d69fed570517f855698ae65c008577..bf891fa4c19399d868ce6a8f4b796e5199770c7a 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-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.
@@ -20,7 +20,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 
 #include <QAbstractEventDispatcher>
 #include <QMenu>
+#include <math.h>
 #include "bat.h"
 #include "medialist.h"
 #include "mediaedit/mediaedit.h"
 #include "joblist/joblist.h"
 #include "relabel/relabel.h"
 #include "run/run.h"
+#include "util/fmtwidgetitem.h"
 
 MediaList::MediaList()
 {
    setupUi(this);
-   m_name = "Media";
+   m_name = tr("Media");
    pgInitialize();
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge.png")));
@@ -74,31 +76,27 @@ MediaList::~MediaList()
  */
 void MediaList::populateTree()
 {
-   QTreeWidgetItem *mediatreeitem, *pooltreeitem;
+   if (m_populated)
+      writeExpandedSettings();
+   m_populated = true;
 
    if (!m_console->preventInUseConnect())
        return;
 
+   Freeze frz(*mp_treeWidget); /* disable updating*/
+
    QStringList headerlist = (QStringList()
-      << "Volume Name" << "Id" << "Status" << "Enabled" << "Bytes" << "Files"
-      << "Jobs" << "Retention" << "Media Type" << "Slot" << "Use Duration"
-      << "Max Jobs" << "Max Files" << "Max Bytes" << "Recycle" << "Enabled"
-      << "RecyclePool" << "Last Written");
-   int statusIndex = headerlist.indexOf("Status");
-   QStringList flaglist = (QStringList()
-      << "L" << "R" << "L" << "R" << "BR" << "R"
-      << "R" << "RS" << "L" << "R" << "RS"
-      << "R" << "R" << "BR" << "R" << "R"
-      << "L" << "L");
+      << tr("Volume Name") << tr("Id") << tr("Status") << tr("Enabled") << tr("Bytes") << tr("Files")
+      << tr("Jobs") << tr("Retention") << tr("Media Type") << tr("Slot") << tr("Use Duration")
+      << tr("Max Jobs") << tr("Max Files") << tr("Max Bytes") << tr("Recycle")
+      << tr("RecyclePool") << tr("Last Written"));
 
    m_checkcurwidget = false;
-   if (m_populated)
-      writeExpandedSettings();
    mp_treeWidget->clear();
    m_checkcurwidget = true;
    mp_treeWidget->setColumnCount(headerlist.count());
    m_topItem = new QTreeWidgetItem(mp_treeWidget);
-   m_topItem->setText(0, "Pools");
+   m_topItem->setText(0, tr("Pools"));
    m_topItem->setData(0, Qt::UserRole, 0);
    m_topItem->setExpanded(true);
    
@@ -108,6 +106,7 @@ void MediaList::populateTree()
    settings.beginGroup("MediaListTreeExpanded");
    QString query;
 
+   QTreeWidgetItem *pooltreeitem;
    foreach (QString pool_listItem, m_console->pool_list) {
       pooltreeitem = new QTreeWidgetItem(m_topItem);
       pooltreeitem->setText(0, pool_listItem);
@@ -123,11 +122,11 @@ void MediaList::populateTree()
          " Media.Enabled AS Enabled, Media.VolBytes AS Bytes,"
          " Media.VolFiles AS FileCount, Media.VolJobs AS JobCount,"
          " Media.VolRetention AS VolumeRetention, Media.MediaType AS MediaType,"
-         " Media.Slot AS Slot, Media.VolUseDuration AS UseDuration,"
+         " Media.InChanger AS InChanger, Media.Slot AS Slot, "
+         " Media.VolUseDuration AS UseDuration,"
          " Media.MaxVolJobs AS MaxJobs, Media.MaxVolFiles AS MaxFiles,"
          " Media.MaxVolBytes AS MaxBytes, Media.Recycle AS Recycle,"
-         " Media.Enabled AS enabled, Pol.Name AS RecyclePool,"
-         " Media.LastWritten AS LastWritten"
+         " Pol.Name AS RecyclePool, Media.LastWritten AS LastWritten"
          " FROM Media"
          " JOIN Pool ON (Media.PoolId=Pool.PoolId)"
          " LEFT OUTER JOIN Pool AS Pol ON (Media.RecyclePoolId=Pol.PoolId)"
@@ -140,50 +139,80 @@ void MediaList::populateTree()
       }
       QStringList results;
       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");
-            int index = 0;
-            mediatreeitem = new QTreeWidgetItem(pooltreeitem);
 
+           if (fieldlist.size() < 18)
+              continue; // some fields missing, ignore row
+
+            int index = 0;
+           TreeItemFormatter mediaitem(*pooltreeitem, 2);
+  
             /* Iterate through fields in the record */
-            foreach (field, fieldlist) {
-               field = field.trimmed();  /* strip leading & trailing spaces */
-               if (field != "") {
-                  mediatreeitem->setData(index, Qt::UserRole, 2);
-                  mediatreeitem->setData(index, Qt::UserRole, 2);
-                  mediatreeitem->setText(index, field);
-                  if (index == statusIndex) {
-                     setStatusColor(mediatreeitem, field, index);
-                  } 
-                  if (flaglist[index].contains("B")) {
-                     QString text;
-                     bool okay;
-                     qlonglong bytes = field.toULongLong(&okay);
-                     if (okay){
-                        QString test =  QString("%1").arg(bytes);
-                        mainWin->hrConvert(text, bytes);
-                        mediatreeitem->setText(index, text);
-                     } else { Pmsg1(000, "conversion error %s\n", field.toUtf8().data()); }
-                  }
-                  if (flaglist[index].contains("S")) {
-                     QString text;
-                     bool okay;
-                     qlonglong seconds = field.toULongLong(&okay);
-                     if (okay){
-                        QString test =  QString("%1").arg(seconds);
-                        mainWin->hrConvertSeconds(text, seconds);
-                        mediatreeitem->setText(index, text);
-                     } else { Pmsg1(000, "conversion error %s\n", field.toUtf8().data()); }
-                  }
-                  if (flaglist[index].contains("R"))
-                     mediatreeitem->setTextAlignment(index, Qt::AlignRight);
-               }
-               index++;
-            } /* foreach field */
+           QStringListIterator fld(fieldlist);
+
+           /* volname */
+            mediaitem.setTextFld(index++, fld.next()); 
+
+           /* id */
+            mediaitem.setNumericFld(index++, fld.next()); 
+
+           /* status */
+            mediaitem.setVolStatusFld(index++, fld.next());
+
+           /* enabled */
+           mediaitem.setBoolFld(index++, fld.next());
+
+            /* bytes */
+           mediaitem.setBytesFld(index++, fld.next());
+
+           /* files */
+            mediaitem.setNumericFld(index++, fld.next()); 
+
+           /* jobs */
+            mediaitem.setNumericFld(index++, fld.next()); 
+
+           /* retention */
+           mediaitem.setDurationFld(index++, fld.next());
+
+           /* media type */
+            mediaitem.setTextFld(index++, fld.next()); 
+
+           /* inchanger + slot */
+           int inchanger = fld.next().toInt();
+            if (inchanger) {
+               mediaitem.setNumericFld(index++, fld.next()); 
+            }
+            else {
+               /* volume not in changer, show blank slot */
+               mediaitem.setNumericFld(index++, ""); 
+               fld.next();
+           }
+
+           /* use duration */
+           mediaitem.setDurationFld(index++, fld.next());
+
+           /* max jobs */
+            mediaitem.setNumericFld(index++, fld.next()); 
+
+           /* max files */
+            mediaitem.setNumericFld(index++, fld.next()); 
+
+            /* max bytes */
+           mediaitem.setBytesFld(index++, fld.next());
+
+           /* recycle */
+           mediaitem.setBoolFld(index++, fld.next());
+
+           /* recycle pool */
+            mediaitem.setTextFld(index++, fld.next()); 
+
+           /* last written */
+            mediaitem.setTextFld(index++, fld.next()); 
+
          } /* foreach resultline */
       } /* if results from query */
    } /* foreach pool_listItem */
@@ -194,17 +223,6 @@ void MediaList::populateTree()
    }
 }
 
-void MediaList::setStatusColor(QTreeWidgetItem *item, QString &field, int &index)
-{
-   if (field == "Append" ) {
-      item->setBackground(index, Qt::green);
-   } else if (field == "Error") {
-      item->setBackground(index, Qt::red);
-   } else if ((field == "Used") || ("Full")){
-      item->setBackground(index, Qt::yellow);
-   }
-}
-
 /*
  * Called from the signal of the context sensitive menu!
  */
@@ -232,7 +250,6 @@ void MediaList::PgSeltreeWidgetClicked()
    if (!m_populated) {
       populateTree();
       createContextMenu();
-      m_populated=true;
    }
 }
 
@@ -303,7 +320,6 @@ void MediaList::currentStackItem()
       populateTree();
       /* Create the context menu for the medialist tree */
       createContextMenu();
-      m_populated=true;
    }
 }
 
@@ -312,7 +328,7 @@ void MediaList::currentStackItem()
  */
 void MediaList::deleteVolume()
 {
-   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 Volume record and all associated catalog"
 " records that were created. This command operates only on the Catalog"
@@ -334,7 +350,7 @@ void MediaList::deleteVolume()
  */
 void MediaList::purgeVolume()
 {
-   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"
@@ -405,12 +421,14 @@ void MediaList::volumeFromPool()
  */
 void MediaList::writeExpandedSettings()
 {
-   QSettings settings(m_console->m_dir->name(), "bat");
-   settings.beginGroup("MediaListTreeExpanded");
-   int childcount = m_topItem->childCount();
-   for (int cnt=0; cnt<childcount; cnt++) {
-      QTreeWidgetItem *poolitem = m_topItem->child(cnt);
-      settings.setValue(poolitem->text(0), poolitem->isExpanded());
+   if (m_topItem) {
+      QSettings settings(m_console->m_dir->name(), "bat");
+      settings.beginGroup("MediaListTreeExpanded");
+      int childcount = m_topItem->childCount();
+      for (int cnt=0; cnt<childcount; cnt++) {
+         QTreeWidgetItem *poolitem = m_topItem->child(cnt);
+         settings.setValue(poolitem->text(0), poolitem->isExpanded());
+      }
+      settings.endGroup();
    }
-   settings.endGroup();
 }