Browse Source

Fix torrent addition dialog geometry saving

When switching between single-file and multi-file torrents, the
dialog geometry saving / loading code was not behaving correctly.
(cherry picked from commit 443f693acf5482df213e1a44eba1e454a0b45124)
adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
7846afaeb8
  1. 62
      src/torrentadditiondlg.cpp
  2. 1
      src/torrentadditiondlg.h
  3. 20
      src/torrentadditiondlg.ui

62
src/torrentadditiondlg.cpp

@ -59,10 +59,11 @@
using namespace libtorrent; using namespace libtorrent;
torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) : torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
QDialog(parent), old_label(""), hidden_height(0) { QDialog(parent), old_label(""), hidden_height(0), m_showContentList(true) {
const Preferences pref; const Preferences pref;
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setMinimumSize(0, 0);
// Icons // Icons
CancelButton->setIcon(IconProvider::instance()->getIcon("dialog-cancel")); CancelButton->setIcon(IconProvider::instance()->getIcon("dialog-cancel"));
OkButton->setIcon(IconProvider::instance()->getIcon("list-add")); OkButton->setIcon(IconProvider::instance()->getIcon("list-add"));
@ -85,8 +86,6 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
contentFilterLayout->insertWidget(1, contentFilterLine); contentFilterLayout->insertWidget(1, contentFilterLine);
// Important: as a default, it inserts at the bottom which is not desirable // Important: as a default, it inserts at the bottom which is not desirable
savePathTxt->setInsertPolicy(QComboBox::InsertAtCurrent); savePathTxt->setInsertPolicy(QComboBox::InsertAtCurrent);
// Remember columns width
readSettings();
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch); //torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
defaultSavePath = pref.getSavePath(); defaultSavePath = pref.getSavePath();
appendLabelToSavePath = pref.appendTorrentLabel(); appendLabelToSavePath = pref.appendTorrentLabel();
@ -132,18 +131,33 @@ void torrentAdditionDialog::closeEvent(QCloseEvent *event)
} }
void torrentAdditionDialog::readSettings() { void torrentAdditionDialog::readSettings() {
// The window should NOT be shown before calling this method
Q_ASSERT(!isVisible());
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
restoreGeometry(settings.value("TorrentAdditionDlg/dimensions").toByteArray()); QString mode = m_showContentList ? "Full" : "Short";
if(!torrentContentList->header()->restoreState(settings.value("TorrentAdditionDlg/ContentHeaderState").toByteArray())) { qDebug() << Q_FUNC_INFO << "mode:" << mode;
qDebug() << Q_FUNC_INFO << "First executation, resize first section to 400px..."; if (!restoreGeometry(settings.value("TorrentAdditionDlg/geometry" + mode).toByteArray())) {
torrentContentList->header()->resizeSection(0, 400); //Default qDebug() << Q_FUNC_INFO << "Failed to load last known dialog geometry";
if (!m_showContentList) {
qDebug() << Q_FUNC_INFO << "Short mode: adapting default size";
resize(width(), height() - 220); // Default size is for full mode
}
}
if (m_showContentList) {
if(!torrentContentList->header()->restoreState(settings.value("TorrentAdditionDlg/ContentHeaderState").toByteArray())) {
qDebug() << Q_FUNC_INFO << "First executation, resize first section to 400px...";
torrentContentList->header()->resizeSection(0, 400); // Default
}
} }
} }
void torrentAdditionDialog::saveSettings() { void torrentAdditionDialog::saveSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.setValue("TorrentAdditionDlg/ContentHeaderState", torrentContentList->header()->saveState()); QString mode = m_showContentList ? "Full" : "Short";
settings.setValue("TorrentAdditionDlg/dimensions", saveGeometry()); settings.setValue("TorrentAdditionDlg/geometry" + mode, saveGeometry());
if (m_showContentList) {
settings.setValue("TorrentAdditionDlg/ContentHeaderState", torrentContentList->header()->saveState());
}
} }
void torrentAdditionDialog::limitDialogWidth() { void torrentAdditionDialog::limitDialogWidth() {
@ -165,26 +179,22 @@ void torrentAdditionDialog::limitDialogWidth() {
void torrentAdditionDialog::hideTorrentContent() { void torrentAdditionDialog::hideTorrentContent() {
// Disable useless widgets // Disable useless widgets
hidden_height += torrentContentList->height();
torrentContentList->setVisible(false); torrentContentList->setVisible(false);
hidden_height += torrentContentLbl->height();
//torrentContentLbl->setVisible(false); //torrentContentLbl->setVisible(false);
hidden_height += selectAllButton->height(); for(int i=0; i<selectionBtnsLayout->count(); ++i) {
selectNoneButton->setVisible(false); if(selectionBtnsLayout->itemAt(i)->widget())
selectAllButton->setVisible(false); selectionBtnsLayout->itemAt(i)->widget()->setVisible(false);
}
for(int i=0; i<contentFilterLayout->count(); ++i) { for(int i=0; i<contentFilterLayout->count(); ++i) {
if(contentFilterLayout->itemAt(i)->widget()) if(contentFilterLayout->itemAt(i)->widget())
contentFilterLayout->itemAt(i)->widget()->setVisible(false); contentFilterLayout->itemAt(i)->widget()->setVisible(false);
} }
contentFilterLayout->update(); contentFilterLayout->update();
// Resize main window m_showContentList = false;
setMinimumSize(0, 0);
resize(width(), height()-hidden_height);
} }
void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) { void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
show();
is_magnet = true; is_magnet = true;
this->from_url = magnet_uri; this->from_url = magnet_uri;
@ -210,8 +220,15 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
// No need to display torrent content // No need to display torrent content
hideTorrentContent(); hideTorrentContent();
// Remember dialog geometry
readSettings();
// Limit dialog width // Limit dialog width
limitDialogWidth(); limitDialogWidth();
// Display dialog
show();
} }
void torrentAdditionDialog::showLoad(QString filePath, QString from_url) { void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@ -317,15 +334,18 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
// Update size labels // Update size labels
updateDiskSpaceLabels(); updateDiskSpaceLabels();
// Show the dialog
show();
// Hide useless widgets // Hide useless widgets
if(t->num_files() <= 1) if(t->num_files() <= 1)
hideTorrentContent(); hideTorrentContent();
// Remember dialog geometry
readSettings();
// Limit dialog width // Limit dialog width
limitDialogWidth(); limitDialogWidth();
// Show the dialog
show();
} }
void torrentAdditionDialog::displayContentListMenu(const QPoint&) { void torrentAdditionDialog::displayContentListMenu(const QPoint&) {

1
src/torrentadditiondlg.h

@ -91,6 +91,7 @@ private:
bool is_magnet; bool is_magnet;
int hidden_height; int hidden_height;
QStringList path_history; QStringList path_history;
bool m_showContentList;
}; };
#endif #endif

20
src/torrentadditiondlg.ui

@ -190,12 +190,6 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer> </spacer>
</item> </item>
</layout> </layout>
@ -217,18 +211,12 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout" name="selectionBtnsLayout">
<item> <item>
<spacer> <spacer>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer> </spacer>
</item> </item>
<item> <item>
@ -250,12 +238,6 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer> </spacer>
</item> </item>
</layout> </layout>

Loading…
Cancel
Save