]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/medialist/medialist.cpp
Joblist: change page select widget name to "JobList"
[bacula/bacula] / bacula / src / qt-console / medialist / medialist.cpp
index 53025ac4491e9704efabaa5e095597e1419abb11..dc1e974c6f6886251c341a27606daecb2fbfadd2 100644 (file)
 #include "medialist.h"
 #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.svg")));
 
    /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_medialist.h */
    m_populated = false;
    m_checkcurwidget = true;
    m_closeable = false;
-   setTitle();
+   /* 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()
@@ -67,10 +74,15 @@ void MediaList::populateTree()
 {
    QTreeWidgetItem *mediatreeitem, *pooltreeitem, *topItem;
 
+   if (!m_console->preventInUseConnect())
+       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;
    mp_treeWidget->clear();
@@ -96,14 +108,21 @@ 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"
+         " LEFT OUTER 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";
    
-      /* FIXME Make this a user configurable loggin action and dont use printf */
-      //printf("MediaList query cmd : %s\n",query.toUtf8().data());
+      if (mainWin->m_sqlDebug) {
+         Pmsg1(000, "MediaList query cmd : %s\n",query.toUtf8().data());
+      }
       QStringList results;
       if (m_console->sql_cmd(query, results)) {
          QString field;
@@ -122,6 +141,9 @@ void MediaList::populateTree()
                   mediatreeitem->setData(index, Qt::UserRole, 2);
                   mediatreeitem->setData(index, Qt::UserRole, 2);
                   mediatreeitem->setText(index, field);
+                  if (index == statusIndex) {
+                     setStatusColor(mediatreeitem, field, index);
+                  }
                }
                index++;
             } /* foreach field */
@@ -134,12 +156,23 @@ 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!
  */
 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()));
 }
 
@@ -176,23 +209,31 @@ 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(actionEditVolume);
+         mp_treeWidget->removeAction(actionListJobsOnVolume);
+         mp_treeWidget->removeAction(actionDeleteVolume);
+         mp_treeWidget->removeAction(actionPruneVolume);
+         mp_treeWidget->removeAction(actionPurgeVolume);
+          mp_treeWidget->removeAction(actionRelabelVolume);
+         mp_treeWidget->removeAction(actionAllVolumesFromPool);
       }
 
       int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
+      m_currentVolumeName=currentwidgetitem->text(0);
       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);
+      } else if (treedepth == 1) {
+/*  *******FIXME******
+ *  I can't seem to get "All volumes from pool" or "Volume from pool" to work
+ *  in one sentence command.   Works when you do it one step at a time vi console
+         mp_treeWidget->addAction(actionAllVolumesFromPool);
+*/
       }
    }
 }
@@ -210,12 +251,15 @@ void MediaList::createContextMenu()
    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 *)),
            this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
    /* connect to the action specific to this pages class */
    connect(actionRefreshMediaList, SIGNAL(triggered()), this,
                 SLOT(populateTree()));
+   connect(actionAllVolumesFromPool, SIGNAL(triggered()), this, SLOT(allVolumesFromPool()));
 }
 
 /*
@@ -225,10 +269,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;
@@ -236,20 +276,74 @@ 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()
 {
+   if (QMessageBox::warning(this, tr("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"
+" database and has no effect on the actual data written to a Volume. This"
+" command can be dangerous and we strongly recommend that you do not use"
+" it unless you know what you are doing.  All Jobs and all associated"
+" records (File and JobMedia) will be deleted from the catalog."
+      "Press OK to proceed with delete operation.?"),
+      QMessageBox::Ok | QMessageBox::Cancel)
+      == QMessageBox::Cancel) { return; }
+
    QString cmd("delete volume=");
    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()
 {
+   if (QMessageBox::warning(this, tr("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"
+" Catalog database and does not affect data written to Volumes. This command can"
+" be dangerous because you can delete catalog records associated with current"
+" backups of files, and we recommend that you do not use it unless you know what"
+" you are doing.\n"
+      "Press OK to proceed with the purge operation?"),
+      QMessageBox::Ok | QMessageBox::Cancel)
+      == QMessageBox::Cancel) { return; }
+
    QString cmd("purge volume=");
    cmd += m_currentVolumeName;
    consoleCommand(cmd);
+   populateTree();
+}
+
+/*
+ * 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 pool=");
+   cmd += m_currentVolumeName + " All Volumes From Pool";
+   consoleCommand(cmd);
+   populateTree();
 }