X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fqt-console%2Fstorage%2Fstorage.cpp;h=8d5fd055ebf4416f42b8ee6fc4ee4e661d32e346;hb=637c52b00e3ddd50913d44a613e23a4093a658eb;hp=36e077525067b32bb542fae63a6f36e50dfc2a93;hpb=908d0c5a7c352c4473409fd01cab16d968c41b43;p=bacula%2Fbacula diff --git a/bacula/src/qt-console/storage/storage.cpp b/bacula/src/qt-console/storage/storage.cpp index 36e0775250..8d5fd055eb 100644 --- a/bacula/src/qt-console/storage/storage.cpp +++ b/bacula/src/qt-console/storage/storage.cpp @@ -1,12 +1,12 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2008 Free Software Foundation Europe e.V. + 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 + modify it under the terms of version three of the GNU Affero General Public License as published by the Free Software Foundation and included in the file LICENSE. @@ -15,7 +15,7 @@ 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 + You should have received a copy of the GNU Affero 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. @@ -35,16 +35,17 @@ * */ +#include "bat.h" #include #include -#include "bat.h" #include "storage.h" +#include "content.h" #include "label/label.h" #include "mount/mount.h" #include "status/storstat.h" #include "util/fmtwidgetitem.h" -Storage::Storage() +Storage::Storage() : Pages() { setupUi(this); pgInitialize(tr("Storage")); @@ -53,13 +54,13 @@ Storage::Storage() /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_storage.h */ m_populated = false; + m_firstpopulation = true; m_checkcurwidget = true; m_closeable = false; m_currentStorage = ""; /* add context sensitive menu items specific to this classto the page * selector tree. m_contextActions is QList of QActions */ m_contextActions.append(actionRefreshStorage); - dockPage(); } Storage::~Storage() @@ -74,11 +75,11 @@ Storage::~Storage() */ void Storage::populateTree() { - if (!m_console->preventInUseConnect()) - return; - if (m_populated) writeExpandedSettings(); + m_populated = true; + + Freeze frz(*mp_treeWidget); /* disable updating */ m_checkcurwidget = false; mp_treeWidget->clear(); @@ -99,20 +100,27 @@ void Storage::populateTree() QSettings settings(m_console->m_dir->name(), "bat"); settings.beginGroup("StorageTreeExpanded"); - foreach(QString storageName, m_console->storage_list){ - TreeItemFormatter storageItem(*m_topItem, 1); - storageItem.setTextFld(0, storageName); - if(settings.contains(storageName)) { - storageItem.widget()->setExpanded(settings.value(storageName).toBool()); - } else { - storageItem.widget()->setExpanded(true); + bool first = true; + QString storage_comsep(""); + QString storageName; + foreach(storageName, m_console->storage_list){ + if (first) { + storage_comsep += "'" + storageName + "'"; + first = false; } + else + storage_comsep += ",'" + storageName + "'"; + } + if (storage_comsep != "") { /* Set up query QString and header QStringList */ - QString query("SELECT StorageId AS ID, AutoChanger AS Changer" - " FROM Storage WHERE"); - query += " Name='" + storageName + "'" - " ORDER BY Name"; + QString query("SELECT" + " Name AS StorageName," + " StorageId AS ID, AutoChanger AS Changer" + " FROM Storage " + " WHERE StorageId IN (SELECT MAX(StorageId) FROM Storage WHERE"); + query += " Name IN (" + storage_comsep + ")"; + query += " GROUP BY Name) ORDER BY Name"; QStringList results; /* This could be a log item */ @@ -120,25 +128,33 @@ void Storage::populateTree() Pmsg1(000, "Storage query cmd : %s\n",query.toUtf8().data()); } if (m_console->sql_cmd(query, results)) { - int resultCount = results.count(); - if (resultCount == 1){ - QString resultline; - QString field; - QStringList fieldlist; - /* there will only be one of these */ - foreach (resultline, results) { - fieldlist = resultline.split("\t"); - int index = 1; - QStringListIterator fld(fieldlist); - - /* storage id */ - storageItem.setNumericFld(index++, fld.next() ); - - /* changer */ - storageItem.setBoolFld(index++, fld.next() ); - - mediaList(storageItem.widget(), fieldlist.first()); + + QStringList fieldlist; + foreach (QString resultline, results) { + fieldlist = resultline.split("\t"); + storageName = fieldlist.takeFirst(); + if (m_firstpopulation) { + settingsOpenStatus(storageName); } + TreeItemFormatter storageItem(*m_topItem, 1); + storageItem.setTextFld(0, storageName); + if(settings.contains(storageName)) + storageItem.widget()->setExpanded(settings.value(storageName).toBool()); + else + storageItem.widget()->setExpanded(true); + + int index = 1; + QStringListIterator fld(fieldlist); + + /* storage id */ + storageItem.setNumericFld(index++, fld.next() ); + + /* changer */ + QString changer = fld.next(); + storageItem.setBoolFld(index++, changer); + + if (changer == "1") + mediaList(storageItem.widget(), fieldlist.first()); } } } @@ -146,17 +162,22 @@ void Storage::populateTree() for(int cnter=0; cnterresizeColumnToContents(cnter); } + m_firstpopulation = false; } + +/* + * For autochangers A query to show the tapes in the changer. + */ void Storage::mediaList(QTreeWidgetItem *parent, const QString &storageID) { QString query("SELECT Media.VolumeName AS Media, Media.Slot AS Slot," " Media.VolStatus AS VolStatus, Media.Enabled AS Enabled," - " Pool.Name AS MediaPool, Media.MediaType AS MediaType" + " Pool.Name AS MediaPool, Media.MediaType AS MediaType" " From Media" - " JOIN Pool ON (Media.PoolId=Pool.PoolId)" - " WHERE Media.StorageId='" + storageID + "'" - " AND Media.InChanger<>0" - " ORDER BY Media.Slot"); + " JOIN Pool ON (Media.PoolId=Pool.PoolId)" + " WHERE Media.StorageId='" + storageID + "'" + " AND Media.InChanger<>0" + " ORDER BY Media.Slot"); QStringList results; /* This could be a log item */ @@ -170,25 +191,25 @@ void Storage::mediaList(QTreeWidgetItem *parent, const QString &storageID) foreach (resultline, results) { fieldlist = resultline.split("\t"); - if (fieldlist.size() < 6) - continue; + if (fieldlist.size() < 6) + continue; /* Iterate through fields in the record */ QStringListIterator fld(fieldlist); int index = 0; - TreeItemFormatter fmt(*parent, 2); + TreeItemFormatter fmt(*parent, 2); /* volname */ fmt.setTextFld(index++, fld.next()); - /* skip the next two columns, unused by media */ - index += 2; + /* skip the next two columns, unused by media */ + index += 2; - /* slot */ - fmt.setNumericFld(index++, fld.next()); + /* slot */ + fmt.setNumericFld(index++, fld.next()); - /* status */ - fmt.setVolStatusFld(index++, fld.next()); + /* status */ + fmt.setVolStatusFld(index++, fld.next()); /* enabled */ fmt.setBoolFld(index++, fld.next()); @@ -212,7 +233,9 @@ void Storage::PgSeltreeWidgetClicked() if(!m_populated) { populateTree(); createContextMenu(); - m_populated = true; + } + if (!isOnceDocked()) { + dockPage(); } } @@ -306,6 +329,17 @@ 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() +{ + if (m_currentStorage != "" && m_currentAutoChanger) { + QTreeWidgetItem *parentItem = mainWin->getFromHash(this); + new Content(m_currentStorage, parentItem); + } } /* @@ -317,7 +351,6 @@ void Storage::currentStackItem() populateTree(); /* Create the context menu for the storage tree */ createContextMenu(); - m_populated = true; } } @@ -390,8 +423,20 @@ void Storage::consoleRelease() */ void Storage::statusStorageWindow() { - QTreeWidgetItem *parentItem = mainWin->getFromHash(this); - new StorStat(m_currentStorage, parentItem); + /* 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); + } } /* @@ -408,3 +453,28 @@ void Storage::writeExpandedSettings() } settings.endGroup(); } + +/* + * If first time, then check to see if there were status pages open the last time closed + * if so open + */ +void Storage::settingsOpenStatus(QString &storage) +{ + QSettings settings(m_console->m_dir->name(), "bat"); + + settings.beginGroup("OpenOnExit"); + QString toRead = "StorageStatus_" + storage; + if (settings.value(toRead) == 1) { + if (mainWin->m_sqlDebug) { + Pmsg1(000, "Do open Storage Status window for : %s\n", storage.toUtf8().data()); + } + new StorStat(storage, mainWin->getFromHash(this)); + setCurrent(); + mainWin->getFromHash(this)->setExpanded(true); + } else { + if (mainWin->m_sqlDebug) { + Pmsg1(000, "Do NOT open Storage Status window for : %s\n", storage.toUtf8().data()); + } + } + settings.endGroup(); +}