]> git.sur5r.net Git - bacula/bacula/commitdiff
connect button from mediainfo to real actions
authorEric Bollengier <eric@eb.homelinux.org>
Tue, 4 Aug 2009 13:12:07 +0000 (15:12 +0200)
committerEric Bollengier <eric@eb.homelinux.org>
Tue, 4 Aug 2009 13:12:07 +0000 (15:12 +0200)
bacula/src/qt-console/job/job.ui
bacula/src/qt-console/mediainfo/mediainfo.cpp
bacula/src/qt-console/mediainfo/mediainfo.h
bacula/src/qt-console/mediainfo/mediainfo.ui

index 6a9d246bd210d2eb5923e96adb8f7d86b77ab5c7..b3873b2e6148b428a978e7690a260cb8652a4a08 100644 (file)
@@ -33,6 +33,9 @@
        </item>
        <item>
         <widget class="QPushButton" name="pbErrors" >
+         <property name="enabled" >
+          <bool>false</bool>
+         </property>
          <property name="toolTip" >
           <string>View errors for this Job</string>
          </property>
@@ -50,6 +53,9 @@
        </item>
        <item>
         <widget class="QPushButton" name="pbMedia" >
+         <property name="enabled" >
+          <bool>false</bool>
+         </property>
          <property name="text" >
           <string>Media</string>
          </property>
@@ -64,6 +70,9 @@
        </item>
        <item>
         <widget class="QPushButton" name="pbHistory" >
+         <property name="enabled" >
+          <bool>false</bool>
+         </property>
          <property name="text" >
           <string>History</string>
          </property>
@@ -78,6 +87,9 @@
        </item>
        <item>
         <widget class="QPushButton" name="pbRun" >
+         <property name="enabled" >
+          <bool>false</bool>
+         </property>
          <property name="sizePolicy" >
           <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
            <horstretch>0</horstretch>
        </item>
        <item>
         <widget class="QPushButton" name="pbDoc" >
+         <property name="enabled" >
+          <bool>false</bool>
+         </property>
          <property name="text" >
           <string>Read doc</string>
          </property>
        </item>
        <item>
         <widget class="QPushButton" name="pbFileSet" >
+         <property name="enabled" >
+          <bool>false</bool>
+         </property>
          <property name="text" >
           <string>FileSet</string>
          </property>
        </item>
        <item>
         <widget class="QPushButton" name="pbStats" >
+         <property name="enabled" >
+          <bool>false</bool>
+         </property>
          <property name="text" >
           <string>Stats</string>
          </property>
       <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
 &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:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;">
-&lt;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;">&lt;/p>&lt;/body>&lt;/html></string>
+&lt;/style>&lt;/head>&lt;body style=" font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;">
+&lt;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;">&lt;/p>&lt;/body>&lt;/html></string>
      </property>
     </widget>
    </item>
index f66a9b8366e47fee695c891fba0ead365ca5c800..bedbcbb328290446fc7e90d7c898d5ca45233009 100644 (file)
 #include <QAbstractEventDispatcher>
 #include <QTableWidgetItem>
 #include <QMessageBox>
+#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)));
+         }
+      }
+   }
+
 }
index fc9ed754c04073f51e69ec1e0f0239e7661e3e0f..a275c41077bc284c482438d8f08693660ade71aa 100644 (file)
@@ -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_ */
index 2a04b68d941142bf40dc9856f845d525df1e064a..e073e26539f009c4cde1b07cbbe5ec287ed4fe92 100644 (file)
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_2" >
      <item>
-      <widget class="QPushButton" name="pushButton" >
+      <widget class="QPushButton" name="pbEdit" >
        <property name="text" >
-        <string>Load</string>
+        <string>Edit</string>
        </property>
        <property name="icon" >
         <iconset resource="../main.qrc" >
-         <normaloff>:/images/intern.png</normaloff>:/images/intern.png</iconset>
+         <normaloff>:/images/edit.png</normaloff>:/images/edit.png</iconset>
        </property>
        <property name="flat" >
         <bool>true</bool>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="pushButton_6" >
+      <widget class="QPushButton" name="pbPurge" >
        <property name="text" >
-        <string>Unload</string>
+        <string>Purge</string>
        </property>
        <property name="icon" >
         <iconset resource="../main.qrc" >
-         <normaloff>:/images/extern.png</normaloff>:/images/extern.png</iconset>
+         <normaloff>:/images/purge.png</normaloff>:/images/purge.png</iconset>
        </property>
        <property name="flat" >
         <bool>true</bool>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="pushButton_2" >
+      <widget class="QPushButton" name="pbDelete" >
        <property name="text" >
-        <string>Edit</string>
+        <string>Delete</string>
        </property>
        <property name="icon" >
         <iconset resource="../main.qrc" >
-         <normaloff>:/images/edit.png</normaloff>:/images/edit.png</iconset>
+         <normaloff>:/images/purge.png</normaloff>:/images/purge.png</iconset>
        </property>
        <property name="flat" >
         <bool>true</bool>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="pushButton_3" >
+      <widget class="QPushButton" name="pbPrune" >
        <property name="text" >
-        <string>Purge</string>
+        <string>Prune</string>
        </property>
        <property name="icon" >
         <iconset resource="../main.qrc" >
-         <normaloff>:/images/purge.png</normaloff>:/images/purge.png</iconset>
+         <normaloff>:/images/edit-cut.png</normaloff>:/images/edit-cut.png</iconset>
        </property>
        <property name="flat" >
         <bool>true</bool>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="pushButton_4" >
+      <widget class="QPushButton" name="pbLoad" >
+       <property name="enabled" >
+        <bool>false</bool>
+       </property>
        <property name="text" >
-        <string>Prune</string>
+        <string>Load</string>
        </property>
        <property name="icon" >
         <iconset resource="../main.qrc" >
-         <normaloff>:/images/edit-cut.png</normaloff>:/images/edit-cut.png</iconset>
+         <normaloff>:/images/intern.png</normaloff>:/images/intern.png</iconset>
        </property>
        <property name="flat" >
         <bool>true</bool>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="pushButton_5" >
+      <widget class="QPushButton" name="pbUnload" >
+       <property name="enabled" >
+        <bool>false</bool>
+       </property>
        <property name="text" >
-        <string>Delete</string>
+        <string>Unload</string>
        </property>
        <property name="icon" >
         <iconset resource="../main.qrc" >
-         <normaloff>:/images/purge.png</normaloff>:/images/purge.png</iconset>
+         <normaloff>:/images/extern.png</normaloff>:/images/extern.png</iconset>
        </property>
        <property name="flat" >
         <bool>true</bool>
      </property>
      <layout class="QHBoxLayout" name="horizontalLayout" >
       <item>
-       <widget class="QTableWidget" name="tableWidget" >
+       <widget class="QTableWidget" name="tableJob" >
         <column>
          <property name="text" >
           <string>JobId</string>