]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mediaedit/mediaedit.cpp
Make bad Storage check in is_on_same_storage non-fatal
[bacula/bacula] / bacula / src / qt-console / mediaedit / mediaedit.cpp
index e1afbed81403b617550f7c01fefeef860a106b84..3e3b6d03bc0a85cd73051f979e7e2264e5182ae2 100644 (file)
@@ -1,54 +1,52 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 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.
    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.
+   modify it under the terms of version three of the GNU Affero General Public
+   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
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    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.
 */
 /*
- *   Version $Id: batstack.h 4230 2007-02-21 20:07:37Z kerns $
+ *   Version $Id$
  *
  *   Dirk Bartley, March 2007
  */
  
+#include "bat.h"
 #include <QAbstractEventDispatcher>
 #include <QTableWidgetItem>
 #include <QMessageBox>
-#include "bat.h"
 #include "mediaedit.h"
-#include <inttypes.h>
 
 /*
  * A constructor 
  */
-MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId)
+MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId) 
+  : Pages()
 {
    setupUi(this);
-   m_name = "Media Edit";
-   pgInitialize(parentWidget);
+   pgInitialize(tr("Media Edit"), parentWidget);
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
-   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge-edit.svg")));
-   m_closeable = true;
+   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge-edit.png")));
    dockPage();
    setCurrent();
 
@@ -61,26 +59,29 @@ MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId)
    connect(useDurationRadio, SIGNAL(pressed()), this, SLOT(useDurationRadioPressed()));
 
    m_pool = "";
+   m_recyclePool = "";
    m_status = "";
    m_slot = 0;
 
-   if (!m_console->preventInUseConnect())
-      return;
-
    /* The media's pool */
    poolCombo->addItems(m_console->pool_list);
 
    /* The media's Status */
-   QStringList statusList = (QStringList() << "Full" << "Used" << "Append" << "Error" << "Purged" << "Recycled");
+   QStringList statusList = (QStringList() << "Full" << "Used" << "Append" 
+       << "Error" << "Purged" << "Recycle" << "Read-Only" << "Cleaning");
    statusCombo->addItems(statusList);
 
    /* Set up the query for the default values */
    QStringList FieldList = (QStringList()
       << "Media.VolumeName" << "Pool.Name" << "Media.VolStatus" << "Media.Slot"
-      << "Media.VolRetention" << "Media.VolUseDuration");
+      << "Media.VolRetention" << "Media.VolUseDuration" << "Media.MaxVolJobs"
+      << "Media.MaxVolFiles" << "Media.MaxVolBytes" << "Media.Recycle" << "Media.Enabled"
+      << "Pol.Name");
    QStringList AsList = (QStringList()
       << "VolumeName" << "PoolName" << "Status" << "Slot"
-      << "Retention" << "UseDuration");
+      << "Retention" << "UseDuration" << "MaxJobs"
+      << "MaxFiles" << "MaxBytes" << "Recycle" << "Enabled"
+      << "RecyclePool");
    int i = 0;
    QString query("SELECT ");
    foreach (QString field, FieldList) {
@@ -90,9 +91,15 @@ MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId)
       query += field + " AS " + AsList[i];
       i += 1;
    }
-   query += " FROM Media, Pool WHERE Media.PoolId=Pool.PoolId";
-   query += " AND Media.MediaId='" + mediaId + "'";
-   query += " ORDER BY Pool.Name";
+
+   QString where = " WHERE Media.VolumeName = '" + mediaId + "' ";
+   if (mediaId.contains(QRegExp("^[0-9]+$"))) {
+      where = " WHERE Media.MediaId=" + mediaId;
+   }
+   query += " FROM Media"
+            " JOIN Pool ON (Media.PoolId=Pool.PoolId)"
+            " LEFT OUTER JOIN Pool AS Pol ON (Media.RecyclePoolId=Pol.PoolId)"
+            + where;
 
    if (mainWin->m_sqlDebug) {
       Pmsg1(000, "MediaList query cmd : %s\n",query.toUtf8().data());
@@ -122,11 +129,28 @@ MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId)
                m_slot = field.toInt(&ok, 10);
                if (!ok){ m_slot = 0; }
             } else if (i == 4) {
-               m_retention = field.toLong(&ok, 10);
+               m_retention = field.toInt(&ok, 10);
                if (!ok){ m_retention = 0; }
             } else if (i == 5) {
-               m_useDuration = field.toLong(&ok, 10);
+               m_useDuration = field.toInt(&ok, 10);
                if (!ok){ m_useDuration = 0; }
+            } else if (i == 6) {
+               m_maxVolJobs = field.toInt(&ok, 10);
+               if (!ok){ m_maxVolJobs = 0; }
+            } else if (i == 7) {
+               m_maxVolFiles = field.toInt(&ok, 10);
+               if (!ok){ m_maxVolFiles = 0; }
+            } else if (i == 8) {
+               m_maxVolBytes = field.toInt(&ok, 10);
+               if (!ok){ m_maxVolBytes = 0; }
+            } else if (i == 9) {
+               if (field == "1") m_recycle = true;
+               else m_recycle = false;
+            } else if (i == 10) {
+               if (field == "1") m_enabled = true;
+               else m_enabled = false;
+            } else if (i == 11) {
+               m_recyclePool = field;
             }
             i++;
          } /* foreach field */
@@ -149,10 +173,25 @@ MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId)
       slotSpin->setValue(m_slot);
       retentionSpin->setValue(m_retention);
       useDurationSpin->setValue(m_useDuration);
-
-      this->show();
+      setSpins(retentionSpin->value());
+      retentionRadio->setChecked(true);
+      maxJobsSpin->setValue(m_maxVolJobs);
+      maxFilesSpin->setValue(m_maxVolFiles);
+      maxBytesSpin->setValue(m_maxVolBytes);
+      if (m_recycle) recycleCheck->setCheckState(Qt::Checked);
+      else recycleCheck->setCheckState(Qt::Unchecked);
+      if (m_enabled) enabledCheck->setCheckState(Qt::Checked);
+      else enabledCheck->setCheckState(Qt::Unchecked);
+      /* default for recycle pool */
+      recyclePoolCombo->addItems(m_console->pool_list);
+      recyclePoolCombo->insertItem(0, "*None*");
+      index = recyclePoolCombo->findText(m_recyclePool, Qt::MatchExactly);
+      if (index == -1) {
+         index = 0;
+      }
+      recyclePoolCombo->setCurrentIndex(index);
    } else {
-      QMessageBox::warning(this, "No Volume name", "No Volume name given",
+      QMessageBox::warning(this, tr("No Volume name"), tr("No Volume name given"),
                            QMessageBox::Ok, QMessageBox::Ok);
       return;
    }
@@ -163,33 +202,66 @@ MediaEdit::MediaEdit(QTreeWidgetItem *parentWidget, QString &mediaId)
  */
 void MediaEdit::okButtonPushed()
 {
-//update volume=xxx slots MaxVolJobs=nnn MaxVolBytes=nnn Recycle=yes|no
-//         enabled=n recyclepool=zzz
-// done pool=yyy volstatus=xxx slot=nnn VolUse=ddd VolRetention=ddd
    QString scmd;
    this->hide();
    bool docmd = false;
    scmd = QString("update volume=\"%1\"")
                   .arg(m_mediaName);
    if (m_pool != poolCombo->currentText()) {
-       scmd += " pool=\"" + poolCombo->currentText() + "\"";
-       docmd = true;
+      scmd += " pool=\"" + poolCombo->currentText() + "\"";
+      docmd = true;
    }
    if (m_status != statusCombo->currentText()) {
-       scmd += " volstatus=\"" + statusCombo->currentText() + "\"";
-       docmd = true;
+      scmd += " volstatus=\"" + statusCombo->currentText() + "\"";
+      docmd = true;
    }
    if (m_slot != slotSpin->value()) {
-       scmd += " slot=" + QString().setNum(slotSpin->value());
-       docmd = true;
+      scmd += " slot=" + QString().setNum(slotSpin->value());
+      docmd = true;
    }
    if (m_retention != retentionSpin->value()) {
-       scmd += " VolRetention=" + QString().setNum(retentionSpin->value());
-       docmd = true;
+      scmd += " VolRetention=" + QString().setNum(retentionSpin->value());
+      docmd = true;
    }
    if (m_useDuration != useDurationSpin->value()) {
-       scmd += " VolUse=" + QString().setNum(useDurationSpin->value());
-       docmd = true;
+      scmd += " VolUse=" + QString().setNum(useDurationSpin->value());
+      docmd = true;
+   }
+   if (m_maxVolJobs != maxJobsSpin->value()) {
+      scmd += " MaxVolJobs=" + QString().setNum(maxJobsSpin->value());
+      docmd = true;
+   }
+   if (m_maxVolFiles != maxFilesSpin->value()) {
+      scmd += " MaxVolFiles=" + QString().setNum(maxFilesSpin->value());
+      docmd = true;
+   }
+   if (m_maxVolBytes != maxBytesSpin->value()) {
+      scmd += " MaxVolBytes=" + QString().setNum(maxBytesSpin->value());
+      docmd = true;
+   }
+   if ((m_recycle) && (recycleCheck->checkState() == Qt::Unchecked)) {
+      scmd += " Recycle=no";
+      docmd = true;
+   }
+   if ((!m_recycle) && (recycleCheck->checkState() == Qt::Checked)) {
+      scmd += " Recycle=yes";
+      docmd = true;
+   }
+   if ((m_enabled) && (enabledCheck->checkState() == Qt::Unchecked)) {
+      scmd += " enabled=no";
+      docmd = true;
+   }
+   if ((!m_enabled) && (enabledCheck->checkState() == Qt::Checked)) {
+      scmd += " enabled=yes";
+      docmd = true;
+   }
+   if (m_recyclePool != recyclePoolCombo->currentText()) {
+      scmd += " recyclepool=\"";
+      if (recyclePoolCombo->currentText() != "*None*") {
+         scmd += recyclePoolCombo->currentText();
+      }
+      scmd += "\"";
+      docmd = true;
    }
    if (docmd) {
       if (mainWin->m_commandDebug) {
@@ -229,10 +301,12 @@ void MediaEdit::useDurationChanged()
  */
 void MediaEdit::setSpins(int value)
 {
-   int years, days, hours, minutes, seconds, left;
-       
+   int years, months, days, hours, minutes, seconds, left;
+        
    years = abs(value / 31536000);
    left = value - years * 31536000;
+   months = abs(left / 2592000);
+   left = left - months * 2592000;
    days = abs(left / 86400);
    left = left - days * 86400;
    hours = abs(left / 3600);
@@ -241,6 +315,7 @@ void MediaEdit::setSpins(int value)
    seconds = left - minutes * 60;
    disconnectSpins();
    yearsSpin->setValue(years);
+   monthsSpin->setValue(months);
    daysSpin->setValue(days);
    hoursSpin->setValue(hours);
    minutesSpin->setValue(minutes);
@@ -267,7 +342,11 @@ void MediaEdit::durationChanged()
       daysSpin->setValue(daysSpin->value()-1);
    }
    if (daysSpin->value() == -1) {
-      daysSpin->setValue(364);
+      daysSpin->setValue(29);
+      monthsSpin->setValue(monthsSpin->value()-1);
+   }
+   if (monthsSpin->value() == -1) {
+      monthsSpin->setValue(11);
       yearsSpin->setValue(yearsSpin->value()-1);
    }
    if (yearsSpin->value() == -1) {
@@ -286,8 +365,12 @@ void MediaEdit::durationChanged()
       hoursSpin->setValue(0);
       daysSpin->setValue(daysSpin->value()+1);
    }
-   if (daysSpin->value() == 365) {
+   if (daysSpin->value() == 30) {
       daysSpin->setValue(0);
+      monthsSpin->setValue(monthsSpin->value()+1);
+   }
+   if (monthsSpin->value() == 12) {
+      monthsSpin->setValue(0);
       yearsSpin->setValue(yearsSpin->value()+1);
    }
    connectSpins();
@@ -295,6 +378,7 @@ void MediaEdit::durationChanged()
       int retention;
       retention = secondsSpin->value() + minutesSpin->value() * 60 + 
          hoursSpin->value() * 3600 + daysSpin->value() * 86400 +
+         monthsSpin->value() * 2592000 +
          yearsSpin->value() * 31536000;
       disconnect(retentionSpin, SIGNAL(valueChanged(int)), this, SLOT(retentionChanged()));
       retentionSpin->setValue(retention);
@@ -304,6 +388,7 @@ void MediaEdit::durationChanged()
       int useDuration;
       useDuration = secondsSpin->value() + minutesSpin->value() * 60 + 
          hoursSpin->value() * 3600 + daysSpin->value() * 86400 +
+         monthsSpin->value() * 2592000 +
          yearsSpin->value() * 31536000;
       disconnect(useDurationSpin, SIGNAL(valueChanged(int)), this, SLOT(useDurationChanged()));
       useDurationSpin->setValue(useDuration);
@@ -318,6 +403,7 @@ void MediaEdit::connectSpins()
    connect(minutesSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
    connect(hoursSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
    connect(daysSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
+   connect(monthsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
    connect(yearsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
 }
 
@@ -328,6 +414,7 @@ void MediaEdit::disconnectSpins()
    disconnect(minutesSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
    disconnect(hoursSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
    disconnect(daysSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
+   disconnect(monthsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
    disconnect(yearsSpin, SIGNAL(valueChanged(int)), this, SLOT(durationChanged()));
 }