]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/storage/storage.cpp
I could not get a few files to compile until I opened and saved these
[bacula/bacula] / bacula / src / qt-console / storage / storage.cpp
index 8a8f7f06c067019a7b669c4462348d122a2ed950..6e8ffedcb52ef82dee4942c57bc18dbad1de5782 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: storage.cpp 4230 2007-02-21 20:07:37Z kerns $
+ *   Version $Id$
  *
  *  Storage Class
  *
 #include <QAbstractEventDispatcher>
 #include <QMenu>
 #include "bat.h"
-#include "storage/storage.h"
+#include "storage.h"
+#include "label/label.h"
+#include "../mount/mount.h"
 
 Storage::Storage()
 {
    setupUi(this);
    m_name = "Storage";
    pgInitialize();
+   QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
+   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
 
    /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_storage.h */
    m_populated = false;
    m_checkcurwidget = true;
    m_closeable = false;
-   setTitle();
+   m_currentStorage = "";
+   /* add context sensitive menu items specific to this classto the page
+    * selector tree. m_contextActions is QList of QActions */
+   m_contextActions.append(actionRefreshStorage);
+   dockPage();
 }
 
 Storage::~Storage()
@@ -65,6 +73,9 @@ void Storage::populateTree()
 {
    QTreeWidgetItem *storageItem, *topItem;
 
+   if (!m_console->preventInUseConnect())
+       return;
+
    m_checkcurwidget = false;
    mp_treeWidget->clear();
    m_checkcurwidget = true;
@@ -79,8 +90,6 @@ void Storage::populateTree()
 
    mp_treeWidget->setColumnCount(headerlist.count());
    mp_treeWidget->setHeaderLabels(headerlist);
-   /* This could be a log item */
-   //printf("In Storage::populateTree()\n");
 
    foreach(QString storageName, m_console->storage_list){
       storageItem = new QTreeWidgetItem(topItem);
@@ -89,16 +98,16 @@ void Storage::populateTree()
       storageItem->setExpanded(true);
 
       /* Set up query QString and header QStringList */
-      QString query("");
-      query += "SELECT Name AS StorageName, StorageId AS ID, AutoChanger"
-           " FROM Storage"
-           " WHERE ";
-      query += " Name='" + storageName + "'";
-      query += " ORDER BY Name";
+      QString query("SELECT StorageId AS ID, AutoChanger AS Changer"
+               " FROM Storage WHERE");
+      query += " Name='" + storageName + "'"
+               " ORDER BY Name";
 
       QStringList results;
       /* This could be a log item */
-      //printf("Storage query cmd : %s\n",query.toUtf8().data());
+      if (mainWin->m_sqlDebug) {
+         Pmsg1(000, "Storage query cmd : %s\n",query.toUtf8().data());
+      }
       if (m_console->sql_cmd(query, results)) {
          int resultCount = results.count();
          if (resultCount == 1){
@@ -122,6 +131,10 @@ void Storage::populateTree()
          }
       }
    }
+   /* Resize the columns */
+   for(int cnter=1; cnter<headerlist.size(); cnter++) {
+      mp_treeWidget->resizeColumnToContents(cnter);
+   }
 }
 
 /*
@@ -150,6 +163,12 @@ void Storage::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetIte
          int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
          if (treedepth == 1){
             mp_treeWidget->removeAction(actionStatusStorageInConsole);
+            mp_treeWidget->removeAction(actionLabelStorage);
+            mp_treeWidget->removeAction(actionMountStorage);
+            mp_treeWidget->removeAction(actionUnMountStorage);
+            mp_treeWidget->removeAction(actionUpdateSlots);
+            mp_treeWidget->removeAction(actionUpdateSlotsScan);
+            mp_treeWidget->removeAction(actionRelease);
          }
       }
 
@@ -157,8 +176,32 @@ void Storage::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetIte
       if (treedepth == 1){
          /* set a hold variable to the storage name in case the context sensitive
           * menu is used */
-         m_currentlyselected=currentwidgetitem->text(0);
+         m_currentStorage = currentwidgetitem->text(0);
+         m_currentAutoChanger = currentwidgetitem->text(2).toInt();
          mp_treeWidget->addAction(actionStatusStorageInConsole);
+         mp_treeWidget->addAction(actionLabelStorage);
+         mp_treeWidget->addAction(actionMountStorage);
+         mp_treeWidget->addAction(actionUnMountStorage);
+         mp_treeWidget->addAction(actionRelease);
+         QString text;
+         text = "Status Storage \"" + m_currentStorage + "\"";
+         actionStatusStorageInConsole->setText(text);
+         text = "Label media in Storage \"" + m_currentStorage + "\"";
+         actionLabelStorage->setText(text);
+         text = "Mount media in Storage \"" + m_currentStorage + "\"";
+         actionMountStorage->setText(text);
+         text = "\"UN\" Mount media in Storage \"" + m_currentStorage + "\"";
+         actionUnMountStorage->setText(text);
+         text = "Release media in Storage \"" + m_currentStorage + "\"";
+         actionRelease->setText(text);
+         if (m_currentAutoChanger != 0) {
+            mp_treeWidget->addAction(actionUpdateSlots);
+            mp_treeWidget->addAction(actionUpdateSlotsScan);
+            text = "Barcode Scan media in Storage \"" + m_currentStorage + "\"";
+            actionUpdateSlots->setText(text);
+            text = "Mount and read scan media in Storage \"" + m_currentStorage + "\"";
+            actionUpdateSlotsScan->setText(text);
+         }
       }
    }
 }
@@ -180,21 +223,18 @@ void Storage::createContextMenu()
                 SLOT(populateTree()));
    connect(actionStatusStorageInConsole, SIGNAL(triggered()), this,
                 SLOT(consoleStatusStorage()));
-}
-
-/*
- * Function responding to actionListJobsofStorage which calls mainwin function
- * to create a window of a list of jobs of this storage.
- */
-void Storage::consoleStatusStorage()
-{
-   QString cmd("status storage=");
-   cmd += m_currentlyselected;
-   consoleCommand(cmd);
-//   m_console->write_dir(cmd.toUtf8().data());
-//   m_console->displayToPrompt();
-   /* Bring this directors console to the front of the stack */
-//   mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(m_console));
+   connect(actionLabelStorage, SIGNAL(triggered()), this,
+                SLOT(consoleLabelStorage()));
+   connect(actionMountStorage, SIGNAL(triggered()), this,
+                SLOT(consoleMountStorage()));
+   connect(actionUnMountStorage, SIGNAL(triggered()), this,
+                SLOT(consoleUnMountStorage()));
+   connect(actionUpdateSlots, SIGNAL(triggered()), this,
+                SLOT(consoleUpdateSlots()));
+   connect(actionUpdateSlotsScan, SIGNAL(triggered()), this,
+                SLOT(consoleUpdateSlotsScan()));
+   connect(actionRelease, SIGNAL(triggered()), this,
+                SLOT(consoleRelease()));
 }
 
 /*
@@ -204,12 +244,72 @@ void Storage::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(actionRefreshStorage);
       /* Create the context menu for the storage tree */
       createContextMenu();
       m_populated=true;
    }
 }
+
+/*
+ *  Functions to respond to local context sensitive menu sending console commands
+ *  If I could figure out how to make these one function passing a string, Yaaaaaa
+ */
+void Storage::consoleStatusStorage()
+{
+   QString cmd("status storage=");
+   cmd += m_currentStorage;
+   consoleCommand(cmd);
+}
+
+/* Label Media populating current storage by default */
+void Storage::consoleLabelStorage()
+{
+   new labelPage(m_currentStorage);
+}
+
+/* Mount currently selected storage */
+void Storage::consoleMountStorage()
+{
+   if (m_currentAutoChanger == 0){
+      /* no autochanger, just execute the command in the console */
+      QString cmd("mount storage=");
+      cmd += m_currentStorage;
+      consoleCommand(cmd);
+   } else {
+      setConsoleCurrent();
+      /* if this storage is an autochanger, lets ask for the slot */
+      new mountDialog(m_console, m_currentStorage);
+   }
+}
+
+/* Unmount Currently selected storage */
+void Storage::consoleUnMountStorage()
+{
+   QString cmd("umount storage=");
+   cmd += m_currentStorage;
+   consoleCommand(cmd);
+}
+
+/* Update Slots */
+void Storage::consoleUpdateSlots()
+{
+   QString cmd("update slots storage=");
+   cmd += m_currentStorage;
+   consoleCommand(cmd);
+}
+
+/* Update Slots Scan*/
+void Storage::consoleUpdateSlotsScan()
+{
+   QString cmd("update slots scan storage=");
+   cmd += m_currentStorage;
+   consoleCommand(cmd);
+}
+
+/* Release a tape in the drive */
+void Storage::consoleRelease()
+{
+   QString cmd("release storage=");
+   cmd += m_currentStorage;
+   consoleCommand(cmd);
+}