From: Dirk H Bartley Date: Sat, 28 Apr 2007 19:23:47 +0000 (+0000) Subject: Add slot to display in medialist. Turn media edit into a QDialog like the label X-Git-Tag: Release-7.0.0~6482 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5d5b2df2be7b9b1adfe9cf985add1c8b7f8e18a3;p=bacula%2Fbacula Add slot to display in medialist. Turn media edit into a QDialog like the label 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 --- diff --git a/bacula/src/qt-console/mediaedit/mediaedit.cpp b/bacula/src/qt-console/mediaedit/mediaedit.cpp index 9a3eebb1b0..851051d482 100644 --- a/bacula/src/qt-console/mediaedit/mediaedit.cpp +++ b/bacula/src/qt-console/mediaedit/mediaedit.cpp @@ -33,16 +33,142 @@ #include #include +#include #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(); } diff --git a/bacula/src/qt-console/mediaedit/mediaedit.h b/bacula/src/qt-console/mediaedit/mediaedit.h index ad6906c4f4..52856c2237 100644 --- a/bacula/src/qt-console/mediaedit/mediaedit.h +++ b/bacula/src/qt-console/mediaedit/mediaedit.h @@ -37,18 +37,23 @@ #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_ */ diff --git a/bacula/src/qt-console/mediaedit/mediaedit.ui b/bacula/src/qt-console/mediaedit/mediaedit.ui index 792caa3b05..f9b6e59331 100644 --- a/bacula/src/qt-console/mediaedit/mediaedit.ui +++ b/bacula/src/qt-console/mediaedit/mediaedit.ui @@ -1,16 +1,19 @@ - MediaEdit - + mediaeditForm + + + Qt::WindowModal + 0 0 - 540 - 421 + 416 + 230 - Form + Label @@ -19,11 +22,234 @@ 6 + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 16777215 + 48 + + + + Volume : + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + 6 + + + + + Volume Status: + + + + + + + + + + + + + 10000 + + + + + + + Pool: + + + poolCombo + + + + + + + Slot: + + + slotSpin + + + + + - + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 71 + 21 + + + + + + + + + 16777215 + 30 + + + + <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> + + + + + + + Qt::Horizontal + + + + 81 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Maximum + + + + 21 + 16 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + QSizePolicy::Maximum + + + + 398 + 16 + + + - + + + buttonBox + accepted() + mediaeditForm + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + mediaeditForm + reject() + + + 316 + 260 + + + 286 + 274 + + + + diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index e0d3805e45..0e3d7d52ce 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -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())); } /*