]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/medialist/medialist.cpp
bat: cleanup MediaView
[bacula/bacula] / bacula / src / qt-console / medialist / medialist.cpp
index 7ce47962ea6af073a21afb781d7ba9548a8fa8e6..96b9f1ee4b0ee6bd483c0ee911e72f5e419e4294 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2009 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.
  *
  */ 
 
+#include "bat.h"
 #include <QAbstractEventDispatcher>
 #include <QMenu>
 #include <math.h>
-#include "bat.h"
 #include "medialist.h"
 #include "mediaedit/mediaedit.h"
+#include "mediainfo/mediainfo.h"
 #include "joblist/joblist.h"
 #include "relabel/relabel.h"
 #include "run/run.h"
@@ -49,7 +50,7 @@
 MediaList::MediaList()
 {
    setupUi(this);
-   m_name = tr("Media");
+   m_name = tr("Pools");
    pgInitialize();
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge.png")));
@@ -61,7 +62,6 @@ MediaList::MediaList()
    /* add context sensitive menu items specific to this classto the page
     * selector tree. m_contextActions is QList of QActions */
    m_contextActions.append(actionRefreshMediaList);
-   dockPage();
 }
 
 MediaList::~MediaList()
@@ -76,23 +76,20 @@ MediaList::~MediaList()
  */
 void MediaList::populateTree()
 {
-   if (m_populating)
-      return;
-   m_populating = true;
-   QTreeWidgetItem *pooltreeitem;
+   if (m_populated)
+      writeExpandedSettings();
+   m_populated = true;
 
-   if (!m_console->preventInUseConnect())
-       return;
+   Freeze frz(*mp_treeWidget); /* disable updating*/
 
    QStringList headerlist = (QStringList()
       << 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"));
+      << tr("Last Written") << tr("First Written") << tr("Read Time")
+      << tr("Write Time") << tr("Recycle Count") << tr("Recycle Pool"));
 
    m_checkcurwidget = false;
-   if (m_populated)
-      writeExpandedSettings();
    mp_treeWidget->clear();
    m_checkcurwidget = true;
    mp_treeWidget->setColumnCount(headerlist.count());
@@ -107,17 +104,23 @@ void MediaList::populateTree()
    settings.beginGroup("MediaListTreeExpanded");
    QString query;
 
+   QTreeWidgetItem *pooltreeitem;
+
+   /* Comma separated list of pools first */
+   bool first = true;
+   QString pool_comsep("");
    foreach (QString pool_listItem, m_console->pool_list) {
-      pooltreeitem = new QTreeWidgetItem(m_topItem);
-      pooltreeitem->setText(0, pool_listItem);
-      pooltreeitem->setData(0, Qt::UserRole, 1);
-      if(settings.contains(pool_listItem)) {
-         pooltreeitem->setExpanded(settings.value(pool_listItem).toBool());
-      } else {
-         pooltreeitem->setExpanded(true);
+      if (first) {
+         pool_comsep += "'" + pool_listItem + "'";
+         first = false;
       }
-
-      query =  "SELECT Media.VolumeName AS Media, "
+      else
+         pool_comsep += ",'" + pool_listItem + "'";
+   }
+   /* Now use pool_comsep list to perform just one query */
+   if (pool_comsep != "") {
+      query =  "SELECT Pool.Name AS pul,"
+         " Media.VolumeName AS Media, "
          " Media.MediaId AS Id, Media.VolStatus AS VolStatus,"
          " Media.Enabled AS Enabled, Media.VolBytes AS Bytes,"
          " Media.VolFiles AS FileCount, Media.VolJobs AS JobCount,"
@@ -126,63 +129,82 @@ void MediaList::populateTree()
          " Media.VolUseDuration AS UseDuration,"
          " Media.MaxVolJobs AS MaxJobs, Media.MaxVolFiles AS MaxFiles,"
          " Media.MaxVolBytes AS MaxBytes, Media.Recycle AS Recycle,"
-         " Pol.Name AS RecyclePool, Media.LastWritten AS LastWritten"
+         " Media.LastWritten AS LastWritten,"
+         " Media.FirstWritten AS FirstWritten,"
+         " (VolReadTime/1000000) AS ReadTime, (VolWriteTime/1000000) AS WriteTime,"
+         " RecycleCount AS ReCyCount,"
+         " RecPool.Name AS RecyclePool"
          " FROM Media"
          " JOIN Pool ON (Media.PoolId=Pool.PoolId)"
-         " LEFT OUTER JOIN Pool AS Pol ON (Media.RecyclePoolId=Pol.PoolId)"
-         " WHERE";
-      query += " Pool.Name='" + pool_listItem + "'";
-      query += " ORDER BY Media";
-   
+         " LEFT OUTER JOIN Pool AS RecPool ON (Media.RecyclePoolId=RecPool.PoolId)"
+         " WHERE ";
+      query += " Pool.Name IN (" + pool_comsep + ")";
+      query += " ORDER BY Pool.Name, Media";
+
       if (mainWin->m_sqlDebug) {
          Pmsg1(000, "MediaList query cmd : %s\n",query.toUtf8().data());
       }
       QStringList results;
+      int counter = 0;
       if (m_console->sql_cmd(query, results)) {
          QStringList fieldlist;
+         QString prev_pool("");
+         QString this_pool("");
 
          /* Iterate through the lines of results. */
          foreach (QString resultline, results) {
             fieldlist = resultline.split("\t");
+            this_pool = fieldlist.takeFirst();
+            if (prev_pool != this_pool) {
+               prev_pool = this_pool;
+               pooltreeitem = new QTreeWidgetItem(m_topItem);
+               pooltreeitem->setText(0, this_pool);
+               pooltreeitem->setData(0, Qt::UserRole, 1);
+            }
+            if(settings.contains(this_pool)) {
+               pooltreeitem->setExpanded(settings.value(this_pool).toBool());
+            } else {
+               pooltreeitem->setExpanded(true);
+            }
 
-           if (fieldlist.size() < 18)
-              continue; // some fields missing, ignore row
+            if (fieldlist.size() < 18)
+               continue; // some fields missing, ignore row
 
             int index = 0;
-           TreeItemFormatter mediaitem(*pooltreeitem, 2);
+            TreeItemFormatter mediaitem(*pooltreeitem, 2);
   
             /* Iterate through fields in the record */
-           QStringListIterator fld(fieldlist);
+            QStringListIterator fld(fieldlist);
 
-           /* volname */
+            /* volname */
             mediaitem.setTextFld(index++, fld.next()); 
 
-           /* id */
+            /* id */
             mediaitem.setNumericFld(index++, fld.next()); 
 
-           /* status */
+            /* status */
             mediaitem.setVolStatusFld(index++, fld.next());
 
-           /* enabled */
-           mediaitem.setBoolFld(index++, fld.next());
+            /* enabled */
+            mediaitem.setBoolFld(index++, fld.next());
 
             /* bytes */
-           mediaitem.setBytesFld(index++, fld.next());
+            mediaitem.setBytesFld(index++, fld.next());
 
-           /* files */
+            /* files */
             mediaitem.setNumericFld(index++, fld.next()); 
 
-           /* jobs */
+            /* jobs */
             mediaitem.setNumericFld(index++, fld.next()); 
 
-           /* retention */
-           mediaitem.setDurationFld(index++, fld.next());
+            /* retention */
+            mediaitem.setDurationFld(index++, fld.next());
 
-           /* media type */
+            /* media type */
             mediaitem.setTextFld(index++, fld.next()); 
 
-           /* inchanger + slot */
-           int inchanger = fld.next().toInt();
+            /* inchanger + slot */
+            int inchanger = fld.next().toInt();
             if (inchanger) {
                mediaitem.setNumericFld(index++, fld.next()); 
             }
@@ -190,30 +212,43 @@ void MediaList::populateTree()
                /* volume not in changer, show blank slot */
                mediaitem.setNumericFld(index++, ""); 
                fld.next();
-           }
+            }
 
-           /* use duration */
-           mediaitem.setDurationFld(index++, fld.next());
+            /* use duration */
+            mediaitem.setDurationFld(index++, fld.next());
 
-           /* max jobs */
+            /* max jobs */
             mediaitem.setNumericFld(index++, fld.next()); 
 
-           /* max files */
+            /* max files */
             mediaitem.setNumericFld(index++, fld.next()); 
 
             /* max bytes */
-           mediaitem.setBytesFld(index++, fld.next());
+            mediaitem.setBytesFld(index++, fld.next());
+
+            /* recycle */
+            mediaitem.setBoolFld(index++, fld.next());
 
-           /* recycle */
-           mediaitem.setBoolFld(index++, fld.next());
+            /* last written */
+            mediaitem.setTextFld(index++, fld.next()); 
 
-           /* recycle pool */
+            /* first written */
             mediaitem.setTextFld(index++, fld.next()); 
 
-           /* last written */
+            /* read time */
+            mediaitem.setDurationFld(index++, fld.next());
+
+            /* write time */
+            mediaitem.setDurationFld(index++, fld.next());
+
+            /* Recycle Count */
+            mediaitem.setNumericFld(index++, fld.next()); 
+
+            /* recycle pool */
             mediaitem.setTextFld(index++, fld.next()); 
 
          } /* foreach resultline */
+         counter += 1;
       } /* if results from query */
    } /* foreach pool_listItem */
    settings.endGroup();
@@ -221,7 +256,6 @@ void MediaList::populateTree()
    for(int cnter=0; cnter<headerlist.count(); cnter++) {
       mp_treeWidget->resizeColumnToContents(cnter);
    }
-   m_populating = false;
 }
 
 /*
@@ -242,6 +276,17 @@ void MediaList::showJobs()
    mainWin->createPageJobList(m_currentVolumeName, "", "", "", parentItem);
 }
 
+/*
+ * Called from the signal of the context sensitive menu!
+ */
+void MediaList::viewVolume()
+{
+   QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
+   MediaInfo* view = new MediaInfo(parentItem, m_currentVolumeName);
+   connect(view, SIGNAL(destroyed()), this, SLOT(populateTree()));
+
+}
+
 /*
  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
  * The tree has been populated.
@@ -251,8 +296,8 @@ void MediaList::PgSeltreeWidgetClicked()
    if (!m_populated) {
       populateTree();
       createContextMenu();
-      m_populated=true;
    }
+   dockPage();
 }
 
 /*
@@ -296,6 +341,7 @@ void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetI
 void MediaList::createContextMenu()
 {
    mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
+   connect(mp_treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(viewVolume()));
    connect(actionEditVolume, SIGNAL(triggered()), this, SLOT(editVolume()));
    connect(actionListJobsOnVolume, SIGNAL(triggered()), this, SLOT(showJobs()));
    connect(actionDeleteVolume, SIGNAL(triggered()), this, SLOT(deleteVolume()));
@@ -322,7 +368,6 @@ void MediaList::currentStackItem()
       populateTree();
       /* Create the context menu for the medialist tree */
       createContextMenu();
-      m_populated=true;
    }
 }
 
@@ -424,12 +469,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();
 }