From 596737ba2fc4fd6e0ca8bfcb2f179b4c8fe64c4c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 13 Mar 2011 10:09:31 +0000 Subject: [PATCH] Improve lists columns state saving --- src/properties/peerlistwidget.cpp | 38 +++-------------------------- src/properties/propertieswidget.cpp | 27 ++++++++++---------- src/properties/propertieswidget.h | 4 +++ src/properties/trackerlist.cpp | 15 +++--------- src/torrentadditiondlg.cpp | 18 +++++++++++--- src/torrentadditiondlg.h | 8 ++++-- src/transferlistwidget.cpp | 7 +++--- 7 files changed, 49 insertions(+), 68 deletions(-) diff --git a/src/properties/peerlistwidget.cpp b/src/properties/peerlistwidget.cpp index ac0a0bb86..97f7ec33d 100644 --- a/src/properties/peerlistwidget.cpp +++ b/src/properties/peerlistwidget.cpp @@ -49,6 +49,8 @@ using namespace libtorrent; PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), properties(parent), display_flags(false) { + // Load settings + loadSettings(); // Visual settings setRootIsDecorated(false); setItemsExpandable(false); @@ -77,8 +79,6 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), pro setItemDelegate(listDelegate); // Enable sorting setSortingEnabled(true); - // Load settings - loadSettings(); // IP to Hostname resolver updatePeerHostNameResolutionState(); // SIGNAL/SLOT @@ -262,42 +262,12 @@ void PeerListWidget::clear() { void PeerListWidget::loadSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QList contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth")).toStringList()); - if(!contentColsWidths.empty()) { - for(int i=0; irestoreState(settings.value("TorrentProperties/Peers/PeerListState").toByteArray()); } void PeerListWidget::saveSettings() const { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QStringList contentColsWidths; - for(int i=0; icolumnCount(); ++i) { - contentColsWidths << QString::number(columnWidth(i)); - } - settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), contentColsWidths); - // Save sorted column - Qt::SortOrder sortOrder = header()->sortIndicatorOrder(); - QString sortOrderLetter; - if(sortOrder == Qt::AscendingOrder) - sortOrderLetter = QString::fromUtf8("a"); - else - sortOrderLetter = QString::fromUtf8("d"); - int index = header()->sortIndicatorSection(); - settings.setValue(QString::fromUtf8("TorrentProperties/Peers/PeerListSortedCol"), QVariant(QString::number(index)+sortOrderLetter)); + settings.setValue("TorrentProperties/Peers/PeerListState", header()->saveState()); } void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) { diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index e30f8269c..f56949720 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -61,8 +61,9 @@ using namespace libtorrent; PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList): QWidget(parent), transferList(transferList), main_window(main_window) { - setupUi(this); + loadFilesListState(); + // Icons deleteWS_button->setIcon(IconProvider::instance()->getIcon("list-remove")); addWS_button->setIcon(IconProvider::instance()->getIcon("list-add")); @@ -129,6 +130,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra } PropertiesWidget::~PropertiesWidget() { + saveFilesListState(); delete refreshTimer; delete trackerList; delete peersList; @@ -272,16 +274,18 @@ void PropertiesWidget::loadTorrentInfos(const QTorrentHandle &_h) { loadDynamicData(); } +void PropertiesWidget::loadFilesListState() { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); + filesList->header()->restoreState(settings.value("TorrentProperties/FilesListState").toByteArray()); +} + +void PropertiesWidget::saveFilesListState() { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); + settings.setValue("TorrentProperties/FilesListState", filesList->header()->saveState()); +} + void PropertiesWidget::readSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QList contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/filesColsWidth")).toStringList()); - if(contentColsWidths.empty()) { - filesList->header()->resizeSection(0, 300); - } else { - for(int i=0; isetColumnWidth(i, contentColsWidths.at(i)); - } - } // Restore splitter sizes QStringList sizes_str = settings.value(QString::fromUtf8("TorrentProperties/SplitterSizes"), QString()).toString().split(","); if(sizes_str.size() == 2) { @@ -300,11 +304,6 @@ void PropertiesWidget::readSettings() { void PropertiesWidget::saveSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); settings.setValue("TorrentProperties/Visible", state==VISIBLE); - QStringList contentColsWidths; - for(int i=0; imodel()->columnCount(); ++i) { - contentColsWidths << QString::number(filesList->columnWidth(i)); - } - settings.setValue(QString::fromUtf8("TorrentProperties/filesColsWidth"), contentColsWidths); // Splitter sizes QSplitter *hSplitter = static_cast(parentWidget()); QList sizes; diff --git a/src/properties/propertieswidget.h b/src/properties/propertieswidget.h index 9e656fbd3..fd9b287b2 100644 --- a/src/properties/propertieswidget.h +++ b/src/properties/propertieswidget.h @@ -95,6 +95,10 @@ public slots: void openDoubleClickedFile(QModelIndex); void updateSavePath(const QTorrentHandle& h); +private: + void loadFilesListState(); + void saveFilesListState(); + private: TransferListWidget *transferList; MainWindow *main_window; diff --git a/src/properties/trackerlist.cpp b/src/properties/trackerlist.cpp index afbf27064..52b30797e 100644 --- a/src/properties/trackerlist.cpp +++ b/src/properties/trackerlist.cpp @@ -47,6 +47,7 @@ using namespace libtorrent; TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) { + loadSettings(); // Graphical settings setRootIsDecorated(false); setAllColumnsShowFocus(true); @@ -71,7 +72,6 @@ TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), propertie lsd_item = new QTreeWidgetItem(QStringList("** "+tr("[LSD]")+" **")); insertTopLevelItem(2, lsd_item); setRowColor(2, QColor("grey")); - loadSettings(); } TrackerList::~TrackerList() { @@ -368,21 +368,12 @@ void TrackerList::showTrackerListMenu(QPoint) { void TrackerList::loadSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QList contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth")).toStringList()); - if(!contentColsWidths.empty()) { - for(int i=0; irestoreState(settings.value("TorrentProperties/Trackers/TrackerListState").toByteArray())) { setColumnWidth(0, 300); } } void TrackerList::saveSettings() const { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); - QStringList contentColsWidths; - for(int i=0; isaveState()); } diff --git a/src/torrentadditiondlg.cpp b/src/torrentadditiondlg.cpp index 1e3459671..21c717c85 100644 --- a/src/torrentadditiondlg.cpp +++ b/src/torrentadditiondlg.cpp @@ -63,6 +63,7 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) : const Preferences pref; setupUi(this); setAttribute(Qt::WA_DeleteOnClose); + loadFilesListState(); // Icons CancelButton->setIcon(IconProvider::instance()->getIcon("dialog-cancel")); OkButton->setIcon(IconProvider::instance()->getIcon("list-add")); @@ -127,6 +128,7 @@ torrentAdditionDialog::~torrentAdditionDialog() { void torrentAdditionDialog::closeEvent(QCloseEvent *event) { qDebug() << Q_FUNC_INFO; + saveFilesListState(); saveSettings(); QDialog::closeEvent(event); } @@ -134,14 +136,24 @@ void torrentAdditionDialog::closeEvent(QCloseEvent *event) void torrentAdditionDialog::readSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); restoreGeometry(settings.value("TorrentAdditionDlg/dimensions").toByteArray()); - torrentContentList->header()->resizeSection(0, 200); //Default - torrentContentList->header()->restoreState(settings.value("TorrentAdditionDlg/contentHeaderState").toByteArray()); + } void torrentAdditionDialog::saveSettings() { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); settings.setValue("TorrentAdditionDlg/dimensions", saveGeometry()); - settings.setValue("TorrentAdditionDlg/contentHeaderState", torrentContentList->header()->saveState()); +} + +void torrentAdditionDialog::loadFilesListState() { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); + if(!torrentContentList->header()->restoreState(settings.value("TorrentAdditionDlg/ContentHeaderState").toByteArray())) { + torrentContentList->header()->resizeSection(0, 200); //Default + } +} + +void torrentAdditionDialog::saveFilesListState() { + QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); + settings.setValue("TorrentAdditionDlg/ContentHeaderState", torrentContentList->header()->saveState()); } void torrentAdditionDialog::limitDialogWidth() { diff --git a/src/torrentadditiondlg.h b/src/torrentadditiondlg.h index 9b453a5f1..e5e77f3ce 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -46,8 +46,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ public: torrentAdditionDialog(QWidget *parent); ~torrentAdditionDialog(); - void readSettings(); - void saveSettings(); void showLoadMagnetURI(QString magnet_uri); void showLoad(QString filePath, QString from_url=QString::null); QString getCurrentTruncatedSavePath(QString* root_folder_or_file_name = 0) const; @@ -73,6 +71,12 @@ public slots: protected: void closeEvent(QCloseEvent *event); +private: + void readSettings(); + void saveSettings(); + void loadFilesListState(); + void saveFilesListState(); + private: QString fileName; QString hash; diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 7161c5b32..73f80696c 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -65,6 +65,10 @@ using namespace libtorrent; TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession): QTreeView(parent), BTSession(_BTSession), main_window(main_window) { + + // Load settings + loadSettings(); + // Create and apply delegate listDelegate = new TransferListDelegate(this); setItemDelegate(listDelegate); @@ -120,9 +124,6 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&))); header()->setContextMenuPolicy(Qt::CustomContextMenu); connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&))); - - // Load settings - loadSettings(); } TransferListWidget::~TransferListWidget() {