From a425a93db8dbbfbecdb929f27a0e971ffc5e6740 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sun, 9 Aug 2009 22:11:05 +0200 Subject: [PATCH 1/1] continue storage content panel --- bacula/src/dird/ua_label.c | 22 +- bacula/src/qt-console/bat.pro.in | 6 +- bacula/src/qt-console/storage/content.cpp | 192 ++++++++++++ bacula/src/qt-console/storage/content.h | 67 +++++ bacula/src/qt-console/storage/content.ui | 342 ++++++++++++++-------- bacula/src/qt-console/storage/storage.cpp | 9 + bacula/src/qt-console/storage/storage.h | 1 + 7 files changed, 505 insertions(+), 134 deletions(-) create mode 100644 bacula/src/qt-console/storage/content.cpp create mode 100644 bacula/src/qt-console/storage/content.h diff --git a/bacula/src/dird/ua_label.c b/bacula/src/dird/ua_label.c index b464be19c9..50b8b4ac1f 100644 --- a/bacula/src/dird/ua_label.c +++ b/bacula/src/dird/ua_label.c @@ -1026,13 +1026,14 @@ void status_slots(UAContext *ua, STORE *store_r) POOL_DBR pr; vol_list_t *vl, *vol_list = NULL; MEDIA_DBR mr; + char ed1[50], ed2[50], ed3[50]; char *slot_list; int max_slots; int drive; int i=1; /* output format */ - const char *slot_api_empty_format="%i|||||\n"; - const char *slot_api_full_format="%i|%i|%s|%s|%s|%s|\n"; + const char *slot_api_empty_format="%i||||||||\n"; + const char *slot_api_full_format="%i|%i|%s|%s|%s|%s|%s|%s|%s\n"; const char *slot_hformat=" %4i%c| %16s | %9s | %20s | %18s |\n"; if (!open_client_db(ua)) { @@ -1124,16 +1125,23 @@ void status_slots(UAContext *ua, STORE *store_r) mr.VolumeName, mr.VolStatus, mr.MediaType, pr.Name); } else { ua->send_msg(slot_api_full_format, - vl->Slot, mr.Slot, mr.VolumeName, mr.VolStatus, - mr.MediaType, pr.Name); + vl->Slot, mr.Slot, mr.VolumeName, + edit_uint64(mr.VolBytes, ed1), + mr.VolStatus, mr.MediaType, pr.Name, + edit_uint64(mr.LastWritten, ed2), + edit_uint64(mr.LastWritten+mr.VolRetention, ed3)); } db_unlock(ua->db); continue; } else { /* TODO: get information from catalog */ - ua->send_msg(slot_hformat, - vl->Slot, '*', - mr.VolumeName, "?", "?", "?"); + if (!ua->api) { + ua->send_msg(slot_hformat, + vl->Slot, '*', + mr.VolumeName, "?", "?", "?"); + } else { + ua->send_msg(slot_api_empty_format, vl->Slot); + } } db_unlock(ua->db); } diff --git a/bacula/src/qt-console/bat.pro.in b/bacula/src/qt-console/bat.pro.in index 45b4d55505..7e3b8ebacf 100644 --- a/bacula/src/qt-console/bat.pro.in +++ b/bacula/src/qt-console/bat.pro.in @@ -52,7 +52,7 @@ FORMS += medialist/medialist.ui mediaedit/mediaedit.ui joblist/joblist.ui FORMS += clients/clients.ui storage/storage.ui fileset/fileset.ui FORMS += joblog/joblog.ui jobs/jobs.ui job/job.ui FORMS += help/help.ui mediainfo/mediainfo.ui -FORMS += status/dirstat.ui +FORMS += status/dirstat.ui storage/content.ui FORMS += status/clientstat.ui FORMS += status/storstat.ui qwt { @@ -115,6 +115,10 @@ SOURCES += clients/clients.cpp HEADERS += storage/storage.h SOURCES += storage/storage.cpp +## Storage content +HEADERS += storage/content.h +SOURCES += storage/content.cpp + ## Fileset HEADERS += fileset/fileset.h SOURCES += fileset/fileset.cpp diff --git a/bacula/src/qt-console/storage/content.cpp b/bacula/src/qt-console/storage/content.cpp new file mode 100644 index 0000000000..8536556ca9 --- /dev/null +++ b/bacula/src/qt-console/storage/content.cpp @@ -0,0 +1,192 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2009 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of Kern Sibbald. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ + +#include "bat.h" +#include +#include +#include "content.h" +#include "label/label.h" +#include "mount/mount.h" +#include "util/fmtwidgetitem.h" +#include "status/storstat.h" + +Content::Content(QString storage) +{ + setupUi(this); + pgInitialize(tr("Storage Content")); + QTreeWidgetItem* thisitem = mainWin->getFromHash(this); + thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png"))); + + m_populated = false; + m_firstpopulation = true; + m_checkcurwidget = true; + m_closeable = true; + m_currentStorage = storage; + + populate(); + + dockPage(); + setCurrent(); +} + +/* + * The main meat of the class!! The function that querries the director and + * creates the widgets with appropriate values. + */ +void Content::populate() +{ + m_populated = true; + m_firstpopulation = false; + Freeze frz(*tableContent); /* disable updating*/ + int row = 0; + QStringList results; + QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\""); + m_console->dir_cmd(cmd, results); + foreach (QString resultline, results){ + Pmsg1(0, "s=%s\n", resultline.toUtf8().data()); + QStringList fieldlist = resultline.split("|"); + QStringListIterator fld(fieldlist); + if (fieldlist.size() < 9) + continue; /* some fields missing, ignore row */ + Pmsg1(0, "s=%s\n", resultline.toUtf8().data()); + TableItemFormatter jobitem(*tableContent, row); + int col=0; + jobitem.setNumericFld(col++, fld.next()); + fld.next(); + jobitem.setTextFld(col++, fld.next()); + jobitem.setNumericFld(col++, fld.next()); + jobitem.setVolStatusFld(col++, fld.next()); + jobitem.setTextFld(col++, fld.next()); + jobitem.setTextFld(col++, fld.next()); + jobitem.setTextFld(col++, fld.next()); + jobitem.setTextFld(col++, fld.next()); + + row++; + } +} + +/* + * Virtual function which is called when this page is visible on the stack + */ +void Content::currentStackItem() +{ + if(!m_populated) { + populate(); + } +} + +/* + * Functions to respond to local context sensitive menu sending console + * commands If I could figure out how to make these one function passing a + * string, Yaaaaaa + */ +void Content::consoleStatusStorage() +{ + QString cmd("status storage="); + cmd += m_currentStorage; + consoleCommand(cmd); +} + +/* Label Media populating current storage by default */ +void Content::consoleLabelStorage() +{ + new labelPage(m_currentStorage); +} + +void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *) +{ + +} + +/* Mount currently selected storage */ +void Content::consoleMountStorage() +{ + if (m_currentAutoChanger == 0){ + /* no autochanger, just execute the command in the console */ + QString cmd("mount storage="); + cmd += m_currentStorage; + consoleCommand(cmd); + } else { + setConsoleCurrent(); + /* if this storage is an autochanger, lets ask for the slot */ + new mountDialog(m_console, m_currentStorage); + } +} + +/* Unmount Currently selected storage */ +void Content::consoleUnMountStorage() +{ + QString cmd("umount storage="); + cmd += m_currentStorage; + consoleCommand(cmd); +} + +/* Update Slots */ +void Content::consoleUpdateSlots() +{ + QString cmd("update slots storage="); + cmd += m_currentStorage; + consoleCommand(cmd); +} + +/* Update Slots Scan*/ +void Content::consoleUpdateSlotsScan() +{ + QString cmd("update slots scan storage="); + cmd += m_currentStorage; + consoleCommand(cmd); +} + +/* Release a tape in the drive */ +void Content::consoleRelease() +{ + QString cmd("release storage="); + cmd += m_currentStorage; + consoleCommand(cmd); +} + +/* + * Open a status storage window + */ +void Content::statusStorageWindow() +{ + /* if one exists, then just set it current */ + bool found = false; + foreach(Pages *page, mainWin->m_pagehash) { + if (mainWin->currentConsole() == page->console()) { + if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) { + found = true; + page->setCurrent(); + } + } + } + if (!found) { + QTreeWidgetItem *parentItem = mainWin->getFromHash(this); + new StorStat(m_currentStorage, parentItem); + } +} diff --git a/bacula/src/qt-console/storage/content.h b/bacula/src/qt-console/storage/content.h new file mode 100644 index 0000000000..65254278c8 --- /dev/null +++ b/bacula/src/qt-console/storage/content.h @@ -0,0 +1,67 @@ +#ifndef _CONTENT_H_ +#define _CONTENT_H_ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2009 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of Kern Sibbald. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ + +#include +#include "ui_content.h" +#include "console.h" +#include "pages.h" + +class Content : public Pages, public Ui::ContentForm +{ + Q_OBJECT + +public: + Content(QString storage); +// virtual void PgSeltreeWidgetClicked(); + virtual void currentStackItem(); + void consoleUnMountStorage(); + void consoleUpdateSlots(); + void consoleUpdateSlotsScan(); + void consoleLabelStorage(); + void consoleStatusStorage(); + void consoleMountStorage(); + void statusStorageWindow(); + void consoleRelease(); + +public slots: + void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *); + +private slots: + void populate(); + +private: + bool m_currentAutoChanger; + bool m_populated; + bool m_firstpopulation; + bool m_checkcurwidget; + QString m_currentStorage; +}; + +#endif /* _STORAGE_H_ */ diff --git a/bacula/src/qt-console/storage/content.ui b/bacula/src/qt-console/storage/content.ui index 4109b2708e..6793daa6c0 100644 --- a/bacula/src/qt-console/storage/content.ui +++ b/bacula/src/qt-console/storage/content.ui @@ -1,139 +1,229 @@ - Form - + ContentForm + 0 0 - 899 - 610 + 851 + 642 Form - - - - 9 - 308 - 881 - 293 - - - - - Slot - - - - - Volume - - - - - Bytes - - - - - Status - - - - - Media Type - - - - - Pool - - - - - Last Written - - - - - When expire? - - - - - - - 630 - 10 - 211 - 171 - - - - - Drive - - - - - Volume - - - - - - - 12 - 12 - 80 - 30 - - - - Update - - - - - - 102 - 12 - 80 - 30 - - - - Label - - - - - - 192 - 12 - 89 - 30 - - - - Move to tray - - - - - - 290 - 10 - 83 - 30 - - - - Empty tray - - + + + + + + + + 0 + 0 + + + + + 240 + 110 + + + + Actions + + + + + + Update + + + :/images/view-refresh.png + + + + + + + Label + + + :/images/label.png + + + + + + + Move to tray + + + :/images/extern.png + + + + + + + Empty tray + + + :/images/intern.png + + + + + + + Mount + + + + + + + Unmount + + + + + + + + + + Qt::Horizontal + + + + 392 + 20 + + + + + + + + Drives + + + + + + + 0 + 0 + + + + + 220 + 100 + + + + + LTO1 + + + + + New Row + + + + + Drive + + + + + Volume + + + + + LTO1 + + + + + VOL1 + + + + + LTO2 + + + + + VOL2 + + + + + + + + + + + + + Content + + + + + + + Slot + + + + + Volume + + + + + Bytes + + + + + Status + + + + + Media Type + + + + + Pool + + + + + Last Written + + + + + When expire? + + + + + + + + diff --git a/bacula/src/qt-console/storage/storage.cpp b/bacula/src/qt-console/storage/storage.cpp index 7141787c79..3fce0c0455 100644 --- a/bacula/src/qt-console/storage/storage.cpp +++ b/bacula/src/qt-console/storage/storage.cpp @@ -39,6 +39,7 @@ #include #include #include "storage.h" +#include "content.h" #include "label/label.h" #include "mount/mount.h" #include "status/storstat.h" @@ -326,6 +327,14 @@ void Storage::createContextMenu() SLOT(consoleRelease())); connect(actionStatusStorageWindow, SIGNAL(triggered()), this, SLOT(statusStorageWindow())); + connect(mp_treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), + this, SLOT(contentWindow())); + +} + +void Storage::contentWindow() +{ + new Content(m_currentStorage); } /* diff --git a/bacula/src/qt-console/storage/storage.h b/bacula/src/qt-console/storage/storage.h index 8f3f416d5a..7facc1ad3e 100644 --- a/bacula/src/qt-console/storage/storage.h +++ b/bacula/src/qt-console/storage/storage.h @@ -61,6 +61,7 @@ private slots: void consoleUpdateSlotsScan(); void consoleRelease(); void statusStorageWindow(); + void contentWindow(); private: void createContextMenu(); -- 2.39.5