]> git.sur5r.net Git - bacula/bacula/commitdiff
Add slot to display in medialist. Turn media edit into a QDialog like the label
authorDirk H Bartley <dbartley@schupan.com>
Sat, 28 Apr 2007 19:23:47 +0000 (19:23 +0000)
committerDirk H Bartley <dbartley@schupan.com>
Sat, 28 Apr 2007 19:23:47 +0000 (19:23 +0000)
dialog and make functional for three propeties.  Pool, Slot and Volume status.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4647 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/qt-console/mediaedit/mediaedit.cpp
bacula/src/qt-console/mediaedit/mediaedit.h
bacula/src/qt-console/mediaedit/mediaedit.ui
bacula/src/qt-console/medialist/medialist.cpp

index 9a3eebb1b0805953531da6fb4307be2123aa7eeb..851051d482dc4441f71ce1a068c4e8bb91358036 100644 (file)
  
 #include <QAbstractEventDispatcher>
 #include <QTableWidgetItem>
+#include <QMessageBox>
 #include "bat.h"
 #include "mediaedit.h"
 
-MediaEdit::MediaEdit(Console *console, QString &medianame)
+/*
+ * A constructor 
+ */
+MediaEdit::MediaEdit(Console *console, QString &mediaId)
 {
-   setupUi(this);
    m_console = console;
-   tableWidget->clear();
-   tableWidget->setColumnCount(2);
-   tableWidget->setRowCount(5);
-   QTableWidgetItem* item = new QTableWidgetItem(medianame,1);
-   tableWidget->setItem(1, 1, item);
+   m_console->notify(false);
+   m_pool = "";
+   m_status = "";
+   m_slot = 0;
+
+
+   setupUi(this);
+
+   /* The media's pool */
+   poolCombo->addItems(console->pool_list);
+
+   /* The media's Status */
+   QStringList statusList = (QStringList() << "Full" << "Append" << "Error");
+   statusCombo->addItems(statusList);
+
+   /* Set up the query for the default values */
+   QStringList FieldList = (QStringList()
+      << "Media.VolumeName" << "Pool.Name" << "Media.VolStatus" << "Media.Slot" );
+   QStringList AsList = (QStringList()
+      << "VolumeName" << "PoolName" << "Status" << "Slot" );
+   int i = 0;
+   QString query("SELECT ");
+   foreach (QString field, FieldList) {
+      if (i != 0) {
+         query += ", ";
+      }
+      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";
+
+   /* FIXME Make this a user configurable logging action and dont use printf */
+   //printf("MediaList query cmd : %s\n",query.toUtf8().data());
+   QStringList results;
+   if (m_console->sql_cmd(query, results)) {
+      QString field;
+      QStringList fieldlist;
+
+      /* Iterate through the lines of results, there should only be one. */
+      foreach (QString resultline, results) {
+         fieldlist = resultline.split("\t");
+         i = 0;
+
+         /* Iterate through fields in the record */
+         foreach (field, fieldlist) {
+            field = field.trimmed();  /* strip leading & trailing spaces */
+            if (i == 0) {
+               m_mediaName = field;
+               volumeLabel->setText(QString("Volume : %1").arg(m_mediaName));
+            } else if (i == 1) {
+               m_pool = field;
+            } else if (i == 2) {
+               m_status = field;
+            } else if (i == 3) {
+               bool ok;
+               m_slot = field.toInt(&ok, 10);
+               if (!ok){ m_slot = 0; }
+            }
+            i++;
+         } /* foreach field */
+      } /* foreach resultline */
+   } /* if results from query */
+
+   if (m_mediaName != "") {
+      int index;
+      /* default value for pool */
+      index = poolCombo->findText(m_pool, Qt::MatchExactly);
+      if (index != -1) {
+         poolCombo->setCurrentIndex(index);
+      }
+
+      /* default value for status */
+      index = statusCombo->findText(m_status, Qt::MatchExactly);
+      if (index != -1) {
+         statusCombo->setCurrentIndex(index);
+      }
+      slotSpin->setValue(m_slot);
+
+      this->show();
+   } else {
+      QMessageBox::warning(this, "No Volume name", "No Volume name given",
+                           QMessageBox::Ok, QMessageBox::Ok);
+      return;
+   }
+
+}
+
+/*
+ * Function to handle updating the record
+ */
+void MediaEdit::accept()
+{
+   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;
+   }
+   if (m_status != statusCombo->currentText()) {
+       scmd += " volstatus=\"" + statusCombo->currentText() + "\"";
+       docmd = true;
+   }
+   if (m_slot != slotSpin->value()) {
+       scmd += " slot=" + QString().setNum(slotSpin->value());
+       docmd = true;
+   }
+   if (docmd) {
+      /* FIXME Make this a user configurable logging action and dont use printf */
+      //printf("sending command : %s\n",scmd.toUtf8().data());
+      m_console->write_dir(scmd.toUtf8().data());
+      m_console->displayToPrompt();
+      m_console->notify(true);
+    }
+   delete this;
+   mainWin->resetFocus();
+}
+
+void MediaEdit::reject()
+{
+   this->hide();
+   m_console->notify(true);
+   delete this;
+   mainWin->resetFocus();
 }
index ad6906c4f4e46f0787df97972853fede1ac32055..52856c22375fd3a8431f512bf4b34e655597da12 100644 (file)
 #include "ui_mediaedit.h"
 #include "console.h"
 
-class MediaEdit : public QWidget, public Ui::MediaEdit
+class MediaEdit : public QDialog, public Ui::mediaeditForm
 {
    Q_OBJECT 
 
 public:
-   MediaEdit(Console *console, QString &medianame );
+   MediaEdit(Console *console, QString &mediaId);
 
 public slots:
+   void accept();
+   void reject();
 
 private:
    Console *m_console;
-
+   QString m_mediaName;
+   QString m_pool;
+   QString m_status;
+   int m_slot;
 };
 
 #endif /* _MEDIAEDIT_H_ */
index 792caa3b05009dac2c14bb489d94883e8f344f14..f9b6e593317a696465da1eeaed4fcc85d7383a46 100644 (file)
@@ -1,16 +1,19 @@
 <ui version="4.0" >
- <class>MediaEdit</class>
- <widget class="QWidget" name="MediaEdit" >
+ <class>mediaeditForm</class>
+ <widget class="QDialog" name="mediaeditForm" >
+  <property name="windowModality" >
+   <enum>Qt::WindowModal</enum>
+  </property>
   <property name="geometry" >
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>540</width>
-    <height>421</height>
+    <width>416</width>
+    <height>230</height>
    </rect>
   </property>
   <property name="windowTitle" >
-   <string>Form</string>
+   <string>Label</string>
   </property>
   <layout class="QGridLayout" >
    <property name="margin" >
    <property name="spacing" >
     <number>6</number>
    </property>
+   <item row="1" column="0" >
+    <layout class="QHBoxLayout" >
+     <property name="margin" >
+      <number>0</number>
+     </property>
+     <property name="spacing" >
+      <number>6</number>
+     </property>
+     <item>
+      <spacer>
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" >
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="volumeLabel" >
+       <property name="maximumSize" >
+        <size>
+         <width>16777215</width>
+         <height>48</height>
+        </size>
+       </property>
+       <property name="text" >
+        <string>Volume : </string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer>
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" >
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="3" column="0" >
+    <layout class="QGridLayout" >
+     <property name="margin" >
+      <number>0</number>
+     </property>
+     <property name="spacing" >
+      <number>6</number>
+     </property>
+     <item row="1" column="0" >
+      <widget class="QLabel" name="label_5" >
+       <property name="text" >
+        <string>Volume Status:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1" >
+      <widget class="QComboBox" name="statusCombo" />
+     </item>
+     <item row="0" column="1" >
+      <widget class="QComboBox" name="poolCombo" />
+     </item>
+     <item row="2" column="1" >
+      <widget class="QSpinBox" name="slotSpin" >
+       <property name="maximum" >
+        <number>10000</number>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="0" >
+      <widget class="QLabel" name="label_3" >
+       <property name="text" >
+        <string>Pool:</string>
+       </property>
+       <property name="buddy" >
+        <cstring>poolCombo</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="0" >
+      <widget class="QLabel" name="label_4" >
+       <property name="text" >
+        <string>Slot:</string>
+       </property>
+       <property name="buddy" >
+        <cstring>slotSpin</cstring>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
    <item row="0" column="0" >
-    <widget class="QTableWidget" name="tableWidget" />
+    <layout class="QHBoxLayout" >
+     <property name="margin" >
+      <number>0</number>
+     </property>
+     <property name="spacing" >
+      <number>6</number>
+     </property>
+     <item>
+      <spacer>
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" >
+        <size>
+         <width>71</width>
+         <height>21</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="label" >
+       <property name="maximumSize" >
+        <size>
+         <width>16777215</width>
+         <height>30</height>
+        </size>
+       </property>
+       <property name="text" >
+        <string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-size:12pt; font-weight:600;">Edit a Volume&lt;/span>&lt;/p>&lt;/body>&lt;/html></string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer>
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" >
+        <size>
+         <width>81</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item row="4" column="0" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType" >
+      <enum>QSizePolicy::Maximum</enum>
+     </property>
+     <property name="sizeHint" >
+      <size>
+       <width>21</width>
+       <height>16</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="5" column="0" >
+    <widget class="QDialogButtonBox" name="buttonBox" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons" >
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType" >
+      <enum>QSizePolicy::Maximum</enum>
+     </property>
+     <property name="sizeHint" >
+      <size>
+       <width>398</width>
+       <height>16</height>
+      </size>
+     </property>
+    </spacer>
    </item>
   </layout>
  </widget>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>mediaeditForm</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>mediaeditForm</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>
index e0d3805e45379aa565cd9825a10ec8d7953260a5..0e3d7d52ceab626753cd736ee01c3bef7dcbff08 100644 (file)
@@ -70,7 +70,7 @@ void MediaList::populateTree()
    QStringList headerlist = (QStringList()
       << "Volume Name" << "Media Id" << "Volume Status" << "Enabled"
       << "Volume Bytes" << "Volume Files" << "Volume Jobs" << "Volume Retention" 
-      << "Media Type" << "Last Written");
+      << "Media Type" << "Slot" << "Last Written");
 
    m_checkcurwidget = false;
    mp_treeWidget->clear();
@@ -81,7 +81,7 @@ void MediaList::populateTree()
    topItem->setData(0, Qt::UserRole, 0);
    topItem->setExpanded(true);
    
-    mp_treeWidget->setHeaderLabels(headerlist);
+   mp_treeWidget->setHeaderLabels(headerlist);
 
    QString query;
 
@@ -96,11 +96,11 @@ 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.LastWritten AS LastWritten"
+         " Media.Slot AS Slot, Media.LastWritten AS LastWritten"
          " FROM Media, Pool"
          " WHERE Media.PoolId=Pool.PoolId";
       query += " AND Pool.Name='" + pool_listItem + "'";
-      query += " ORDER BY Pool.Name";
+      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());
@@ -140,7 +140,7 @@ void MediaList::populateTree()
 void MediaList::editMedia()
 {
    MediaEdit* edit = new MediaEdit(m_console, m_currentlyselected);
-   edit->show();
+   connect(edit, SIGNAL(destroyed()), this, SLOT(populateTree()));
 }
 
 /*