#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();
}
#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_ */
<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><html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt; font-weight:600;">Edit a Volume</span></p></body></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>
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();
topItem->setData(0, Qt::UserRole, 0);
topItem->setExpanded(true);
- mp_treeWidget->setHeaderLabels(headerlist);
+ mp_treeWidget->setHeaderLabels(headerlist);
QString query;
" 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());
void MediaList::editMedia()
{
MediaEdit* edit = new MediaEdit(m_console, m_currentlyselected);
- edit->show();
+ connect(edit, SIGNAL(destroyed()), this, SLOT(populateTree()));
}
/*