]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/medialist/medialist.cpp
Fix bat browser for Win32
[bacula/bacula] / bacula / src / qt-console / medialist / medialist.cpp
index 544f0c91f1aee20e5254771e2e9eb7c42fbc9cb0..ee8a9d3321c50c2ba091354431282a82b1934671 100644 (file)
@@ -1,14 +1,14 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2007 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
@@ -27,7 +27,7 @@
 */
  
 /*
- *   Version $Id: medialist.cpp 4230 2007-02-21 20:07:37Z kerns $
+ *   Version $Id$
  *
  *  MediaList Class
  *
 #include "mediaedit/mediaedit.h"
 #include "joblist/joblist.h"
 #include "relabel/relabel.h"
+#include "run/run.h"
 
 MediaList::MediaList()
 {
    setupUi(this);
    m_name = "Media";
    pgInitialize();
+   QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
+   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge.png")));
 
    /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_medialist.h */
    m_populated = false;
    m_checkcurwidget = true;
    m_closeable = false;
+   /* 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()
@@ -71,9 +78,10 @@ void MediaList::populateTree()
        return;
 
    QStringList headerlist = (QStringList()
-      << "Volume Name" << "Id" << "Status" << "Enabled"
-      << "Bytes" << "Files" << "Jobs" << "Retention" 
-      << "Media Type" << "Slot" << "Last Written");
+      << "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");
 
    m_checkcurwidget = false;
@@ -100,10 +108,16 @@ 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.LastWritten AS LastWritten"
-         " FROM Media, Pool"
-         " WHERE Media.PoolId=Pool.PoolId";
-      query += " AND Pool.Name='" + pool_listItem + "'";
+         " 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"
+         " 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";
    
       if (mainWin->m_sqlDebug) {
@@ -158,7 +172,7 @@ void MediaList::setStatusColor(QTreeWidgetItem *item, QString &field, int &index
  */
 void MediaList::editVolume()
 {
-   MediaEdit* edit = new MediaEdit(m_console, m_currentVolumeId);
+   MediaEdit* edit = new MediaEdit(mainWin->getFromHash(this), m_currentVolumeId);
    connect(edit, SIGNAL(destroyed()), this, SLOT(populateTree()));
 }
 
@@ -167,9 +181,8 @@ void MediaList::editVolume()
  */
 void MediaList::showJobs()
 {
-   QString emptyclient("");
    QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
-   mainWin->createPageJobList(m_currentVolumeName, emptyclient, parentItem);
+   mainWin->createPageJobList(m_currentVolumeName, "", "", "", parentItem);
 }
 
 /*
@@ -195,25 +208,25 @@ void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetI
    if (m_checkcurwidget) {
       /* The Previous item */
       if (previouswidgetitem) { /* avoid a segfault if first time */
-         int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
-         if (treedepth == 2){
-            mp_treeWidget->removeAction(actionEditVolume);
-            mp_treeWidget->removeAction(actionListJobsOnVolume);
-            mp_treeWidget->removeAction(actionDeleteVolume);
-            mp_treeWidget->removeAction(actionPurgeVolume);
-            mp_treeWidget->removeAction(actionRelabelVolume);
+         foreach(QAction* mediaAction, mp_treeWidget->actions()) {
+            mp_treeWidget->removeAction(mediaAction);
          }
       }
 
       int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
+      m_currentVolumeName=currentwidgetitem->text(0);
+      mp_treeWidget->addAction(actionRefreshMediaList);
       if (treedepth == 2){
-         m_currentVolumeName=currentwidgetitem->text(0);
          m_currentVolumeId=currentwidgetitem->text(1);
          mp_treeWidget->addAction(actionEditVolume);
          mp_treeWidget->addAction(actionListJobsOnVolume);
          mp_treeWidget->addAction(actionDeleteVolume);
+         mp_treeWidget->addAction(actionPruneVolume);
          mp_treeWidget->addAction(actionPurgeVolume);
          mp_treeWidget->addAction(actionRelabelVolume);
+         mp_treeWidget->addAction(actionVolumeFromPool);
+      } else if (treedepth == 1) {
+         mp_treeWidget->addAction(actionAllVolumesFromPool);
       }
    }
 }
@@ -226,11 +239,11 @@ void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetI
 void MediaList::createContextMenu()
 {
    mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
-   mp_treeWidget->addAction(actionRefreshMediaList);
    connect(actionEditVolume, SIGNAL(triggered()), this, SLOT(editVolume()));
    connect(actionListJobsOnVolume, SIGNAL(triggered()), this, SLOT(showJobs()));
    connect(actionDeleteVolume, SIGNAL(triggered()), this, SLOT(deleteVolume()));
    connect(actionPurgeVolume, SIGNAL(triggered()), this, SLOT(purgeVolume()));
+   connect(actionPruneVolume, SIGNAL(triggered()), this, SLOT(pruneVolume()));
    connect(actionRelabelVolume, SIGNAL(triggered()), this, SLOT(relabelVolume()));
    connect(mp_treeWidget, SIGNAL(
            currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
@@ -238,6 +251,9 @@ void MediaList::createContextMenu()
    /* connect to the action specific to this pages class */
    connect(actionRefreshMediaList, SIGNAL(triggered()), this,
                 SLOT(populateTree()));
+   connect(actionAllVolumes, SIGNAL(triggered()), this, SLOT(allVolumes()));
+   connect(actionAllVolumesFromPool, SIGNAL(triggered()), this, SLOT(allVolumesFromPool()));
+   connect(actionVolumeFromPool, SIGNAL(triggered()), this, SLOT(volumeFromPool()));
 }
 
 /*
@@ -247,10 +263,6 @@ void MediaList::currentStackItem()
 {
    if(!m_populated) {
       populateTree();
-      /* add context sensitive menu items specific to this classto the page
-       * selector tree. m_m_contextActions is QList of QActions, so this is 
-       * only done once with the first population. */
-      m_contextActions.append(actionRefreshMediaList);
       /* Create the context menu for the medialist tree */
       createContextMenu();
       m_populated=true;
@@ -258,7 +270,7 @@ void MediaList::currentStackItem()
 }
 
 /*
- * Called from the signal of the context sensitive menu!
+ * Called from the signal of the context sensitive menu to delete a volume!
  */
 void MediaList::deleteVolume()
 {
@@ -278,8 +290,9 @@ void MediaList::deleteVolume()
    cmd += m_currentVolumeName;
    consoleCommand(cmd);
 }
+
 /*
- * Called from the signal of the context sensitive menu!
+ * Called from the signal of the context sensitive menu to purge!
  */
 void MediaList::purgeVolume()
 {
@@ -300,11 +313,51 @@ void MediaList::purgeVolume()
    consoleCommand(cmd);
    populateTree();
 }
+
 /*
- * Called from the signal of the context sensitive menu!
+ * Called from the signal of the context sensitive menu to prune!
+ */
+void MediaList::pruneVolume()
+{
+   new prunePage(m_currentVolumeName, "");
+}
+
+/*
+ * Called from the signal of the context sensitive menu to relabel!
  */
 void MediaList::relabelVolume()
 {
    setConsoleCurrent();
    new relabelDialog(m_console, m_currentVolumeName);
 }
+
+/*
+ * Called from the signal of the context sensitive menu to purge!
+ */
+void MediaList::allVolumesFromPool()
+{
+   QString cmd = "update volume AllFromPool=" + m_currentVolumeName;
+   consoleCommand(cmd);
+   populateTree();
+}
+
+void MediaList::allVolumes()
+{
+   QString cmd = "update volume allfrompools";
+   consoleCommand(cmd);
+   populateTree();
+}
+
+/*
+ * Called from the signal of the context sensitive menu to purge!
+ */
+void MediaList::volumeFromPool()
+{
+   QTreeWidgetItem *currentItem = mp_treeWidget->currentItem();
+   QTreeWidgetItem *parent = currentItem->parent();
+   QString pool = parent->text(0);
+   QString cmd;
+   cmd = "update volume=" + m_currentVolumeName + " frompool=" + pool;
+   consoleCommand(cmd);
+   populateTree();
+}