diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 000340c37..18e644921 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -59,9 +59,7 @@ Preferences *Preferences::m_instance = 0; -Preferences::Preferences() -{ -} +Preferences::Preferences() {} Preferences *Preferences::instance() { @@ -195,7 +193,6 @@ void Preferences::setCloseToTray(bool b) { setValue("Preferences/General/CloseToTray", b); } - #endif bool Preferences::isToolbarDisplayed() const @@ -267,7 +264,6 @@ void Preferences::setWinStartup(bool b) settings.remove("qBittorrent"); } } - #endif // Downloads @@ -744,7 +740,6 @@ void Preferences::useSystemIconTheme(bool enabled) { setValue("Preferences/Advanced/useSystemIconTheme", enabled); } - #endif bool Preferences::recursiveDownloadDisabled() const @@ -983,7 +978,6 @@ void Preferences::setMagnetLinkAssoc(bool set) SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); } - #endif #ifdef Q_OS_MAC @@ -1040,7 +1034,6 @@ void Preferences::setMagnetLinkAssoc() CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId); } - #endif int Preferences::getTrackerPort() const @@ -1063,7 +1056,6 @@ void Preferences::setUpdateCheckEnabled(bool enabled) { setValue("Preferences/Advanced/updateCheck", enabled); } - #endif bool Preferences::confirmTorrentDeletion() const @@ -1106,7 +1098,6 @@ void Preferences::setTrayIconStyle(TrayIcon::Style style) { setValue("Preferences/Advanced/TrayIconStyle", style); } - #endif // Stuff that don't appear in the Options GUI but are saved @@ -1468,9 +1459,10 @@ void Preferences::upgrade() QStringList labels = value("TransferListFilters/customLabels").toStringList(); if (!labels.isEmpty()) { QVariantMap categories = value("BitTorrent/Session/Categories").toMap(); - foreach (const QString &label, labels) + foreach (const QString &label, labels) { if (!categories.contains(label)) categories[label] = ""; + } setValue("BitTorrent/Session/Categories", categories); SettingsStorage::instance()->removeValue("TransferListFilters/customLabels"); } diff --git a/src/base/preferences.h b/src/base/preferences.h index fe021bc78..e7f2e53e8 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -90,7 +90,7 @@ class Preferences: public QObject const QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; void setValue(const QString &key, const QVariant &value); - static Preferences* m_instance; + static Preferences *m_instance; signals: void changed(); @@ -98,7 +98,7 @@ signals: public: static void initInstance(); static void freeInstance(); - static Preferences* instance(); + static Preferences *instance(); // General options QString getLocale() const; @@ -328,7 +328,7 @@ public: int getToolbarTextPosition() const; void setToolbarTextPosition(const int position); - //From old RssSettings class + // From old RssSettings class bool isRSSWidgetEnabled() const; void setRSSWidgetVisible(const bool enabled); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index c17fee4b8..0b891d3c4 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -50,7 +50,7 @@ mainwindow.h messageboxraised.h optionsdlg.h previewlistdelegate.h -previewselect.h +previewselectdialog.h scanfoldersdelegate.h shutdownconfirmdlg.h speedlimitdlg.h @@ -93,7 +93,7 @@ loglistwidget.cpp mainwindow.cpp messageboxraised.cpp optionsdlg.cpp -previewselect.cpp +previewselectdialog.cpp scanfoldersdelegate.cpp shutdownconfirmdlg.cpp speedlimitdlg.cpp @@ -133,7 +133,7 @@ mainwindow.ui about.ui banlistoptions.ui cookiesdialog.ui -preview.ui +previewselectdialog.ui login.ui downloadfromurldlg.ui bandwidth_limit.ui diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 81233251e..581b05c97 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -21,7 +21,6 @@ HEADERS += \ $$PWD/statusbar.h \ $$PWD/speedlimitdlg.h \ $$PWD/about_imp.h \ - $$PWD/previewselect.h \ $$PWD/previewlistdelegate.h \ $$PWD/downloadfromurldlg.h \ $$PWD/trackerlogin.h \ @@ -62,6 +61,7 @@ HEADERS += \ $$PWD/rss/htmlbrowser.h \ $$PWD/fspathedit.h \ $$PWD/fspathedit_p.h \ + $$PWD/previewselectdialog.h \ SOURCES += \ $$PWD/mainwindow.cpp \ @@ -77,7 +77,6 @@ SOURCES += \ $$PWD/torrentcontenttreeview.cpp \ $$PWD/executionlog.cpp \ $$PWD/speedlimitdlg.cpp \ - $$PWD/previewselect.cpp \ $$PWD/guiiconprovider.cpp \ $$PWD/updownratiodlg.cpp \ $$PWD/loglistwidget.cpp \ @@ -114,7 +113,8 @@ SOURCES += \ $$PWD/rss/automatedrssdownloader.cpp \ $$PWD/rss/htmlbrowser.cpp \ $$PWD/fspathedit.cpp \ - $$PWD/fspathedit_p.cpp + $$PWD/fspathedit_p.cpp \ + $$PWD/previewselectdialog.cpp \ win32|macx { HEADERS += $$PWD/programupdater.h @@ -129,7 +129,7 @@ macx { FORMS += \ $$PWD/mainwindow.ui \ $$PWD/about.ui \ - $$PWD/preview.ui \ + $$PWD/previewselectdialog.ui \ $$PWD/login.ui \ $$PWD/downloadfromurldlg.ui \ $$PWD/bandwidth_limit.ui \ diff --git a/src/gui/previewlistdelegate.h b/src/gui/previewlistdelegate.h index 6dfb085ce..9efb1c387 100644 --- a/src/gui/previewlistdelegate.h +++ b/src/gui/previewlistdelegate.h @@ -39,7 +39,7 @@ #include #include "base/utils/misc.h" #include "base/utils/string.h" -#include "previewselect.h" +#include "previewselectdialog.h" #ifdef Q_OS_WIN #include @@ -58,11 +58,11 @@ class PreviewListDelegate: public QItemDelegate { QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); switch(index.column()) { - case PreviewSelect::SIZE: + case PreviewSelectDialog::SIZE: QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); break; - case PreviewSelect::PROGRESS:{ + case PreviewSelectDialog::PROGRESS:{ QStyleOptionProgressBar newopt; qreal progress = index.data().toDouble()*100.; newopt.rect = opt.rect; diff --git a/src/gui/previewselect.cpp b/src/gui/previewselectdialog.cpp similarity index 78% rename from src/gui/previewselect.cpp rename to src/gui/previewselectdialog.cpp index 763ebeacf..3bd55fd86 100644 --- a/src/gui/previewselect.cpp +++ b/src/gui/previewselectdialog.cpp @@ -26,7 +26,7 @@ * exception statement from your version. */ -#include "previewselect.h" +#include "previewselectdialog.h" #include #include @@ -40,15 +40,19 @@ #include "base/utils/misc.h" #include "previewlistdelegate.h" -PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const torrent) +#define SETTINGS_KEY(name) "PreviewSelectDialog/" name + +PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent) : QDialog(parent) , m_torrent(torrent) + , m_storeDialogSize(SETTINGS_KEY("Dimension")) + , m_storeTreeHeaderState(SETTINGS_KEY("HeaderState")) { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview")); - connect(buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelect::previewButtonClicked); + connect(buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelectDialog::previewButtonClicked); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); Preferences *const pref = Preferences::instance(); @@ -69,7 +73,6 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t previewList->hideColumn(FILE_INDEX); m_listDelegate = new PreviewListDelegate(this); previewList->setItemDelegate(m_listDelegate); - previewList->header()->resizeSection(0, 200); previewList->setAlternatingRowColors(pref->useAlternatingRowColors()); // Fill list in QVector fp = torrent->filesProgress(); @@ -98,6 +101,9 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t previewList->header()->setSortIndicator(0, Qt::AscendingOrder); previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows); + // Restore dialog state + loadWindowState(); + if (m_previewListModel->rowCount() == 1) { qDebug("Torrent file only contains one file, no need to display selection dialog before preview"); // Only one file : no choice @@ -109,14 +115,15 @@ PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const t } } -PreviewSelect::~PreviewSelect() +PreviewSelectDialog::~PreviewSelectDialog() { + saveWindowState(); + delete m_previewListModel; delete m_listDelegate; } - -void PreviewSelect::previewButtonClicked() +void PreviewSelectDialog::previewButtonClicked() { QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX); if (selectedIndexes.size() == 0) return; @@ -135,3 +142,36 @@ void PreviewSelect::previewButtonClicked() accept(); } + +void PreviewSelectDialog::saveWindowState() +{ + // Persist dialog size + m_storeDialogSize = this->size(); + // Persist TreeView Header state + m_storeTreeHeaderState = previewList->header()->saveState(); +} + +void PreviewSelectDialog::loadWindowState() +{ + // Restore dialog size + if (m_storeDialogSize.value().isValid()) { + resize(m_storeDialogSize); + } + // Restore TreeView Header state + if (!m_storeTreeHeaderState.value().isEmpty()) { + m_headerStateInitialized = previewList->header()->restoreState(m_storeTreeHeaderState); + } +} + +void PreviewSelectDialog::showEvent(QShowEvent *event) +{ + Q_UNUSED(event); + + // Default size, have to be called after show(), because width is needed + // Set Name column width to 60% of TreeView + if (!m_headerStateInitialized) { + int nameSize = (previewList->size().width() * 0.6); + previewList->header()->resizeSection(0, nameSize); + m_headerStateInitialized = true; + } +} diff --git a/src/gui/previewselect.h b/src/gui/previewselectdialog.h similarity index 76% rename from src/gui/previewselect.h rename to src/gui/previewselectdialog.h index 1a32cd114..4608ab707 100644 --- a/src/gui/previewselect.h +++ b/src/gui/previewselectdialog.h @@ -26,20 +26,21 @@ * exception statement from your version. */ -#ifndef PREVIEWSELECT_H -#define PREVIEWSELECT_H +#ifndef PREVIEWSELECTDIALOG_H +#define PREVIEWSELECTDIALOG_H #include #include #include "base/bittorrent/torrenthandle.h" -#include "ui_preview.h" +#include "base/settingvalue.h" +#include "ui_previewselectdialog.h" class QStandardItemModel; class PreviewListDelegate; -class PreviewSelect : public QDialog, private Ui::preview +class PreviewSelectDialog : public QDialog, private Ui::preview { Q_OBJECT @@ -54,19 +55,30 @@ public: NB_COLUMNS }; - PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const torrent); - ~PreviewSelect(); + PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent); + ~PreviewSelectDialog(); signals: void readyToPreviewFile(QString) const; +protected: + void showEvent(QShowEvent *event) override; + private slots: void previewButtonClicked(); private: + void loadWindowState(); + void saveWindowState(); + QStandardItemModel *m_previewListModel; PreviewListDelegate *m_listDelegate; BitTorrent::TorrentHandle *const m_torrent; + bool m_headerStateInitialized = false; + + // Settings + CachedSettingValue m_storeDialogSize; + CachedSettingValue m_storeTreeHeaderState; }; -#endif // PREVIEWSELECT_H +#endif // PREVIEWSELECTDIALOG_H diff --git a/src/gui/preview.ui b/src/gui/previewselectdialog.ui similarity index 100% rename from src/gui/preview.ui rename to src/gui/previewselectdialog.ui diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 84e919574..53f1913b3 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -54,7 +54,7 @@ #include "guiiconprovider.h" #include "mainwindow.h" #include "optionsdlg.h" -#include "previewselect.h" +#include "previewselectdialog.h" #include "speedlimitdlg.h" #include "torrentmodel.h" #include "transferlistdelegate.h" @@ -563,7 +563,7 @@ void TransferListWidget::previewSelectedTorrents() { foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) { if (torrent->hasMetadata()) - new PreviewSelect(this, torrent); + new PreviewSelectDialog(this, torrent); } }