From ccaf1148568ac91f0cb1dbbc35dae7aea669c2be Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 4 Aug 2009 15:12:07 +0200 Subject: [PATCH] connect button from mediainfo to real actions --- bacula/src/qt-console/job/job.ui | 25 ++- bacula/src/qt-console/mediainfo/mediainfo.cpp | 179 +++++++++++++++++- bacula/src/qt-console/mediainfo/mediainfo.h | 6 + bacula/src/qt-console/mediainfo/mediainfo.ui | 44 +++-- 4 files changed, 223 insertions(+), 31 deletions(-) diff --git a/bacula/src/qt-console/job/job.ui b/bacula/src/qt-console/job/job.ui index 6a9d246bd2..b3873b2e61 100644 --- a/bacula/src/qt-console/job/job.ui +++ b/bacula/src/qt-console/job/job.ui @@ -33,6 +33,9 @@ + + false + View errors for this Job @@ -50,6 +53,9 @@ + + false + Media @@ -64,6 +70,9 @@ + + false + History @@ -78,6 +87,9 @@ + + false + 0 @@ -98,6 +110,9 @@ + + false + Read doc @@ -108,6 +123,9 @@ + + false + FileSet @@ -122,6 +140,9 @@ + + false + Stats @@ -654,8 +675,8 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"></p></body></html> +</style></head><body style=" font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> diff --git a/bacula/src/qt-console/mediainfo/mediainfo.cpp b/bacula/src/qt-console/mediainfo/mediainfo.cpp index f66a9b8366..bedbcbb328 100644 --- a/bacula/src/qt-console/mediainfo/mediainfo.cpp +++ b/bacula/src/qt-console/mediainfo/mediainfo.cpp @@ -30,8 +30,12 @@ #include #include #include +#include "mediaedit/mediaedit.h" +#include "relabel/relabel.h" +#include "run/run.h" #include "mediainfo.h" #include "util/fmtwidgetitem.h" +#include "job/job.h" /* * A constructor @@ -43,25 +47,99 @@ MediaInfo::MediaInfo(QTreeWidgetItem *parentWidget, QString &mediaName) QTreeWidgetItem* thisitem = mainWin->getFromHash(this); thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge-edit.png"))); m_mediaName = mediaName; + connect(pbPrune, SIGNAL(clicked()), this, SLOT(pruneVol())); + connect(pbPurge, SIGNAL(clicked()), this, SLOT(purgeVol())); + connect(pbDelete, SIGNAL(clicked()), this, SLOT(deleteVol())); + connect(pbEdit, SIGNAL(clicked()), this, SLOT(editVol())); + connect(tableJob, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(showInfoForJob(QTableWidgetItem *))); + m_closeable = true; dockPage(); setCurrent(); populateForm(); } +/* + * Subroutine to call class to show the log in the database from that job + */ +void MediaInfo::showInfoForJob(QTableWidgetItem * item) +{ + QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this); + int row = item->row(); + QString jobid = tableJob->item(row, 0)->text(); + Job *j=new Job(jobid, pageSelectorTreeWidgetItem); + connect(j, SIGNAL(destroyed()), this, SLOT(populateTree())); +} + +void MediaInfo::pruneVol() +{ + prunePage* prune = new prunePage(m_mediaName, ""); + connect(prune, SIGNAL(destroyed()), this, SLOT(populateTree())); +} + +// TODO: use same functions as in medialist.cpp +void MediaInfo::purgeVol() +{ + if (QMessageBox::warning(this, "Bat", + tr("Are you sure you want to purge ?? !!!.\n" +"The Purge command will delete associated Catalog database records from Jobs and" +" Volumes without considering the retention period. Purge works only on the" +" Catalog database and does not affect data written to Volumes. This command can" +" be dangerous because you can delete catalog records associated with current" +" backups of files, and we recommend that you do not use it unless you know what" +" you are doing.\n" + "Press OK to proceed with the purge operation?"), + QMessageBox::Ok | QMessageBox::Cancel) + == QMessageBox::Cancel) { return; } + + QString cmd("purge volume="); + cmd += m_mediaName; + consoleCommand(cmd); +} + +void MediaInfo::deleteVol() +{ + if (QMessageBox::warning(this, "Bat", + tr("Are you sure you want to delete?? !!!.\n" +"This delete command is used to delete a Volume record and all associated catalog" +" records that were created. This command operates only on the Catalog" +" database and has no effect on the actual data written to a Volume. This" +" command can be dangerous and we strongly recommend that you do not use" +" it unless you know what you are doing. All Jobs and all associated" +" records (File and JobMedia) will be deleted from the catalog." + "Press OK to proceed with delete operation.?"), + QMessageBox::Ok | QMessageBox::Cancel) + == QMessageBox::Cancel) { return; } + + QString cmd("delete volume="); + cmd += m_mediaName; + consoleCommand(cmd); +} + +void MediaInfo::editVol() +{ + MediaEdit* edit = new MediaEdit(mainWin->getFromHash(this), + m_mediaId); + connect(edit, SIGNAL(destroyed()), this, SLOT(populateTree())); +} + /* * Populate the text in the window */ void MediaInfo::populateForm() { - QString stat; + utime_t t; + time_t ttime; + + QString stat, LastWritten; + struct tm tm; char buf[256]; QString query = - "SELECT VolumeName, Pool.Name, MediaType, FirstWritten," + "SELECT MediaId, VolumeName, Pool.Name, MediaType, FirstWritten," "LastWritten, VolMounts, VolBytes, Media.Enabled," "Location.Location, VolStatus, RecyclePool.Name, Media.Recycle, " "VolReadTime, VolWriteTime, Media.VolUseDuration, Media.MaxVolJobs, " - "Media.MaxVolFiles, Media.MaxVolBytes, Media.VolRetention,Slot,InChanger " + "Media.MaxVolFiles, Media.MaxVolBytes, Media.VolRetention,InChanger,Slot " "FROM Media JOIN Pool USING (PoolId) LEFT JOIN Pool AS RecyclePool " "ON (Media.RecyclePoolId = RecyclePool.PoolId) " "LEFT JOIN Location USING (LocationId) " @@ -75,11 +153,14 @@ void MediaInfo::populateForm() foreach (resultline, results) { // should have only one result fieldlist = resultline.split("\t"); QStringListIterator fld(fieldlist); + m_mediaId = fld.next(); + label_VolumeName->setText(fld.next()); label_Pool->setText(fld.next()); label_MediaType->setText(fld.next()); label_FirstWritten->setText(fld.next()); - label_LastWritten->setText(fld.next()); + LastWritten = fld.next(); + label_LastWritten->setText(LastWritten); // label_VolFiles->setText(fld.next()); label_VolMounts->setText(fld.next()); label_VolBytes->setText(convertBytesSI(fld.next().toULongLong())); @@ -88,22 +169,100 @@ void MediaInfo::populateForm() label_VolStatus->setText(fld.next()); label_RecyclePool->setText(fld.next()); chkbox_Recycle->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked); - label_VolReadTime->setText(fld.next()); - label_VolWriteTime->setText(fld.next()); - label_VolUseDuration->setText(fld.next()); + edit_utime(fld.next().toULongLong(), buf, sizeof(buf)); + label_VolReadTime->setText(QString(buf)); + + edit_utime(fld.next().toULongLong(), buf, sizeof(buf)); + label_VolWriteTime->setText(QString(buf)); + + edit_utime(fld.next().toULongLong(), buf, sizeof(buf)); + label_VolUseDuration->setText(QString(buf)); + label_MaxVolJobs->setText(fld.next()); label_MaxVolFiles->setText(fld.next()); label_MaxVolBytes->setText(fld.next()); - label_VolRetention->setText(fld.next()); - + + stat = fld.next(); + edit_utime(stat.toULongLong(), buf, sizeof(buf)); + label_VolRetention->setText(QString(buf)); + + t = str_to_utime(LastWritten.toAscii().data()); + t = t + stat.toULongLong(); + ttime = t; + localtime_r(&ttime, &tm); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm); + label_Expire->setText(QString(buf)); + label_Online->setPixmap(QPixmap(":/images/inflag"+fld.next()+".png")); // label_VolFiles->setText(fld.next()); // label_VolErrors->setText(fld.next()); // stat=fld.next(); -// label_Online->setPixmap(QPixmap(":/images/inflag" + stat + ".png")); + // jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf)); // stat = buf; // } } + + query = + "SELECT DISTINCT JobId, Name, StartTime, Type, Level, JobFiles," + "JobBytes,JobStatus " + "FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) " + "WHERE Media.VolumeName = '" + m_mediaName + "'"; + + results.clear(); + if (m_console->sql_cmd(query, results)) { + QString resultline; + QStringList fieldlist; + int row = 0; + tableJob->setRowCount(results.size()); + foreach (resultline, results) { + fieldlist = resultline.split("\t"); + QStringListIterator fld(fieldlist); + int index=0; + TableItemFormatter jobitem(*tableJob, row); + + /* JobId */ + jobitem.setNumericFld(index++, fld.next()); + + /* job name */ + jobitem.setTextFld(index++, fld.next()); + + /* job starttime */ + jobitem.setTextFld(index++, fld.next(), true); + + /* job type */ + jobitem.setJobTypeFld(index++, fld.next()); + + /* job level */ + jobitem.setJobLevelFld(index++, fld.next()); + + /* job files */ + jobitem.setNumericFld(index++, fld.next()); + + /* job bytes */ + jobitem.setBytesFld(index++, fld.next()); + + /* job status */ + jobitem.setJobStatusFld(index++, fld.next()); + row++; + } + } + + tableJob->resizeColumnsToContents(); + tableJob->resizeRowsToContents(); + tableJob->verticalHeader()->hide(); + + /* make read only */ + int rcnt = tableJob->rowCount(); + int ccnt = tableJob->columnCount(); + for(int r=0; r < rcnt; r++) { + for(int c=0; c < ccnt; c++) { + QTableWidgetItem* item = tableJob->item(r, c); + if (item) { + item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable))); + } + } + } + } diff --git a/bacula/src/qt-console/mediainfo/mediainfo.h b/bacula/src/qt-console/mediainfo/mediainfo.h index fc9ed754c0..a275c41077 100644 --- a/bacula/src/qt-console/mediainfo/mediainfo.h +++ b/bacula/src/qt-console/mediainfo/mediainfo.h @@ -45,10 +45,16 @@ public: MediaInfo(QTreeWidgetItem *parentWidget, QString &mediaId); private slots: + void pruneVol(); + void purgeVol(); + void deleteVol(); + void editVol(); + void showInfoForJob(QTableWidgetItem * item); private: void populateForm(); QString m_mediaName; + QString m_mediaId; }; #endif /* _MEDIAINFO_H_ */ diff --git a/bacula/src/qt-console/mediainfo/mediainfo.ui b/bacula/src/qt-console/mediainfo/mediainfo.ui index 2a04b68d94..e073e26539 100644 --- a/bacula/src/qt-console/mediainfo/mediainfo.ui +++ b/bacula/src/qt-console/mediainfo/mediainfo.ui @@ -16,13 +16,13 @@ - + - Load + Edit - :/images/intern.png:/images/intern.png + :/images/edit.png:/images/edit.png true @@ -30,13 +30,13 @@ - + - Unload + Purge - :/images/extern.png:/images/extern.png + :/images/purge.png:/images/purge.png true @@ -44,13 +44,13 @@ - + - Edit + Delete - :/images/edit.png:/images/edit.png + :/images/purge.png:/images/purge.png true @@ -58,13 +58,13 @@ - + - Purge + Prune - :/images/purge.png:/images/purge.png + :/images/edit-cut.png:/images/edit-cut.png true @@ -72,13 +72,16 @@ - + + + false + - Prune + Load - :/images/edit-cut.png:/images/edit-cut.png + :/images/intern.png:/images/intern.png true @@ -86,13 +89,16 @@ - + + + false + - Delete + Unload - :/images/purge.png:/images/purge.png + :/images/extern.png:/images/extern.png true @@ -640,7 +646,7 @@ - + JobId -- 2.39.5