From 9585308707921844c2ec545701dc6be3d4e2ae0b Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sat, 10 Nov 2007 15:15:36 +0000 Subject: [PATCH] This uses settings to save the expanded state of the pools in the media list. I was interested in not re-setting the expanded state each time. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5890 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/medialist/medialist.cpp | 40 +++++++++++++++---- bacula/src/qt-console/medialist/medialist.h | 2 + 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index ee8a9d3321..a9e792460c 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -64,6 +64,8 @@ MediaList::MediaList() MediaList::~MediaList() { + if (m_populated) + writeExpandedSettings(); } /* @@ -72,7 +74,7 @@ MediaList::~MediaList() */ void MediaList::populateTree() { - QTreeWidgetItem *mediatreeitem, *pooltreeitem, *topItem; + QTreeWidgetItem *mediatreeitem, *pooltreeitem; if (!m_console->preventInUseConnect()) return; @@ -85,23 +87,31 @@ void MediaList::populateTree() int statusIndex = headerlist.indexOf("Status"); m_checkcurwidget = false; + if (m_populated) + writeExpandedSettings(); mp_treeWidget->clear(); m_checkcurwidget = true; mp_treeWidget->setColumnCount(headerlist.count()); - topItem = new QTreeWidgetItem(mp_treeWidget); - topItem->setText(0, "Pools"); - topItem->setData(0, Qt::UserRole, 0); - topItem->setExpanded(true); + m_topItem = new QTreeWidgetItem(mp_treeWidget); + m_topItem->setText(0, "Pools"); + m_topItem->setData(0, Qt::UserRole, 0); + m_topItem->setExpanded(true); mp_treeWidget->setHeaderLabels(headerlist); + QSettings settings(m_console->m_dir->name(), "bat"); + settings.beginGroup("MediaListTreeExpanded"); QString query; foreach (QString pool_listItem, m_console->pool_list) { - pooltreeitem = new QTreeWidgetItem(topItem); + pooltreeitem = new QTreeWidgetItem(m_topItem); pooltreeitem->setText(0, pool_listItem); pooltreeitem->setData(0, Qt::UserRole, 1); - pooltreeitem->setExpanded(true); + if(settings.contains(pool_listItem)) { + pooltreeitem->setExpanded(settings.value(pool_listItem).toBool()); + } else { + pooltreeitem->setExpanded(true); + } query = "SELECT Media.VolumeName AS Media, " " Media.MediaId AS Id, Media.VolStatus AS VolStatus," @@ -150,6 +160,7 @@ void MediaList::populateTree() } /* foreach resultline */ } /* if results from query */ } /* foreach pool_listItem */ + settings.endGroup(); /* Resize the columns */ for(int cnter=0; cnterresizeColumnToContents(cnter); @@ -361,3 +372,18 @@ void MediaList::volumeFromPool() consoleCommand(cmd); populateTree(); } + +/* + * Write settings to save expanded states of the pools + */ +void MediaList::writeExpandedSettings() +{ + QSettings settings(m_console->m_dir->name(), "bat"); + settings.beginGroup("MediaListTreeExpanded"); + int childcount = m_topItem->childCount(); + for (int cnt=0; cntchild(cnt); + settings.setValue(poolitem->text(0), poolitem->isExpanded()); + } + settings.endGroup(); +} diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index c8cb0a5f53..ded7677c46 100644 --- a/bacula/src/qt-console/medialist/medialist.h +++ b/bacula/src/qt-console/medialist/medialist.h @@ -66,10 +66,12 @@ private slots: private: void createContextMenu(); void setStatusColor(QTreeWidgetItem *, QString &, int &); + void writeExpandedSettings(); QString m_currentVolumeName; QString m_currentVolumeId; bool m_populated; bool m_checkcurwidget; + QTreeWidgetItem *m_topItem; }; #endif /* _MEDIALIST_H_ */ -- 2.39.5