Browse Source

Improve lists columns state saving

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
596737ba2f
  1. 38
      src/properties/peerlistwidget.cpp
  2. 27
      src/properties/propertieswidget.cpp
  3. 4
      src/properties/propertieswidget.h
  4. 15
      src/properties/trackerlist.cpp
  5. 18
      src/torrentadditiondlg.cpp
  6. 8
      src/torrentadditiondlg.h
  7. 7
      src/transferlistwidget.cpp

38
src/properties/peerlistwidget.cpp

@ -49,6 +49,8 @@
using namespace libtorrent; using namespace libtorrent;
PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), properties(parent), display_flags(false) { PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), properties(parent), display_flags(false) {
// Load settings
loadSettings();
// Visual settings // Visual settings
setRootIsDecorated(false); setRootIsDecorated(false);
setItemsExpandable(false); setItemsExpandable(false);
@ -77,8 +79,6 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent): QTreeView(parent), pro
setItemDelegate(listDelegate); setItemDelegate(listDelegate);
// Enable sorting // Enable sorting
setSortingEnabled(true); setSortingEnabled(true);
// Load settings
loadSettings();
// IP to Hostname resolver // IP to Hostname resolver
updatePeerHostNameResolutionState(); updatePeerHostNameResolutionState();
// SIGNAL/SLOT // SIGNAL/SLOT
@ -262,42 +262,12 @@ void PeerListWidget::clear() {
void PeerListWidget::loadSettings() { void PeerListWidget::loadSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth")).toStringList()); header()->restoreState(settings.value("TorrentProperties/Peers/PeerListState").toByteArray());
if(!contentColsWidths.empty()) {
for(int i=0; i<contentColsWidths.size(); ++i) {
setColumnWidth(i, contentColsWidths.at(i));
}
}
// Load sorted column
QString sortedCol = settings.value(QString::fromUtf8("TorrentProperties/Peers/PeerListSortedCol"), QString()).toString();
if(!sortedCol.isEmpty()) {
Qt::SortOrder sortOrder;
if(sortedCol.endsWith(QString::fromUtf8("d")))
sortOrder = Qt::DescendingOrder;
else
sortOrder = Qt::AscendingOrder;
sortedCol.chop(1);
int index = sortedCol.toInt();
sortByColumn(index, sortOrder);
}
} }
void PeerListWidget::saveSettings() const { void PeerListWidget::saveSettings() const {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QStringList contentColsWidths; settings.setValue("TorrentProperties/Peers/PeerListState", header()->saveState());
for(int i=0; i<listModel->columnCount(); ++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));
} }
void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) { void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) {

27
src/properties/propertieswidget.cpp

@ -61,8 +61,9 @@ using namespace libtorrent;
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList): PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList):
QWidget(parent), transferList(transferList), main_window(main_window) { QWidget(parent), transferList(transferList), main_window(main_window) {
setupUi(this); setupUi(this);
loadFilesListState();
// Icons // Icons
deleteWS_button->setIcon(IconProvider::instance()->getIcon("list-remove")); deleteWS_button->setIcon(IconProvider::instance()->getIcon("list-remove"));
addWS_button->setIcon(IconProvider::instance()->getIcon("list-add")); addWS_button->setIcon(IconProvider::instance()->getIcon("list-add"));
@ -129,6 +130,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
} }
PropertiesWidget::~PropertiesWidget() { PropertiesWidget::~PropertiesWidget() {
saveFilesListState();
delete refreshTimer; delete refreshTimer;
delete trackerList; delete trackerList;
delete peersList; delete peersList;
@ -272,16 +274,18 @@ void PropertiesWidget::loadTorrentInfos(const QTorrentHandle &_h) {
loadDynamicData(); 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() { void PropertiesWidget::readSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/filesColsWidth")).toStringList());
if(contentColsWidths.empty()) {
filesList->header()->resizeSection(0, 300);
} else {
for(int i=0; i<contentColsWidths.size(); ++i) {
filesList->setColumnWidth(i, contentColsWidths.at(i));
}
}
// Restore splitter sizes // Restore splitter sizes
QStringList sizes_str = settings.value(QString::fromUtf8("TorrentProperties/SplitterSizes"), QString()).toString().split(","); QStringList sizes_str = settings.value(QString::fromUtf8("TorrentProperties/SplitterSizes"), QString()).toString().split(",");
if(sizes_str.size() == 2) { if(sizes_str.size() == 2) {
@ -300,11 +304,6 @@ void PropertiesWidget::readSettings() {
void PropertiesWidget::saveSettings() { void PropertiesWidget::saveSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.setValue("TorrentProperties/Visible", state==VISIBLE); settings.setValue("TorrentProperties/Visible", state==VISIBLE);
QStringList contentColsWidths;
for(int i=0; i<PropListModel->model()->columnCount(); ++i) {
contentColsWidths << QString::number(filesList->columnWidth(i));
}
settings.setValue(QString::fromUtf8("TorrentProperties/filesColsWidth"), contentColsWidths);
// Splitter sizes // Splitter sizes
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget()); QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
QList<int> sizes; QList<int> sizes;

4
src/properties/propertieswidget.h

@ -95,6 +95,10 @@ public slots:
void openDoubleClickedFile(QModelIndex); void openDoubleClickedFile(QModelIndex);
void updateSavePath(const QTorrentHandle& h); void updateSavePath(const QTorrentHandle& h);
private:
void loadFilesListState();
void saveFilesListState();
private: private:
TransferListWidget *transferList; TransferListWidget *transferList;
MainWindow *main_window; MainWindow *main_window;

15
src/properties/trackerlist.cpp

@ -47,6 +47,7 @@
using namespace libtorrent; using namespace libtorrent;
TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) { TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) {
loadSettings();
// Graphical settings // Graphical settings
setRootIsDecorated(false); setRootIsDecorated(false);
setAllColumnsShowFocus(true); setAllColumnsShowFocus(true);
@ -71,7 +72,6 @@ TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), propertie
lsd_item = new QTreeWidgetItem(QStringList("** "+tr("[LSD]")+" **")); lsd_item = new QTreeWidgetItem(QStringList("** "+tr("[LSD]")+" **"));
insertTopLevelItem(2, lsd_item); insertTopLevelItem(2, lsd_item);
setRowColor(2, QColor("grey")); setRowColor(2, QColor("grey"));
loadSettings();
} }
TrackerList::~TrackerList() { TrackerList::~TrackerList() {
@ -368,21 +368,12 @@ void TrackerList::showTrackerListMenu(QPoint) {
void TrackerList::loadSettings() { void TrackerList::loadSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth")).toStringList()); if(!header()->restoreState(settings.value("TorrentProperties/Trackers/TrackerListState").toByteArray())) {
if(!contentColsWidths.empty()) {
for(int i=0; i<contentColsWidths.size(); ++i) {
setColumnWidth(i, contentColsWidths.at(i));
}
} else {
setColumnWidth(0, 300); setColumnWidth(0, 300);
} }
} }
void TrackerList::saveSettings() const { void TrackerList::saveSettings() const {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QStringList contentColsWidths; settings.setValue("TorrentProperties/Trackers/TrackerListState", header()->saveState());
for(int i=0; i<columnCount(); ++i) {
contentColsWidths << QString::number(columnWidth(i));
}
settings.setValue(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth"), contentColsWidths);
} }

18
src/torrentadditiondlg.cpp

@ -63,6 +63,7 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
const Preferences pref; const Preferences pref;
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
loadFilesListState();
// 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"));
@ -127,6 +128,7 @@ torrentAdditionDialog::~torrentAdditionDialog() {
void torrentAdditionDialog::closeEvent(QCloseEvent *event) void torrentAdditionDialog::closeEvent(QCloseEvent *event)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
saveFilesListState();
saveSettings(); saveSettings();
QDialog::closeEvent(event); QDialog::closeEvent(event);
} }
@ -134,14 +136,24 @@ void torrentAdditionDialog::closeEvent(QCloseEvent *event)
void torrentAdditionDialog::readSettings() { void torrentAdditionDialog::readSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
restoreGeometry(settings.value("TorrentAdditionDlg/dimensions").toByteArray()); restoreGeometry(settings.value("TorrentAdditionDlg/dimensions").toByteArray());
torrentContentList->header()->resizeSection(0, 200); //Default
torrentContentList->header()->restoreState(settings.value("TorrentAdditionDlg/contentHeaderState").toByteArray());
} }
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/dimensions", saveGeometry()); 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() { void torrentAdditionDialog::limitDialogWidth() {

8
src/torrentadditiondlg.h

@ -46,8 +46,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
public: public:
torrentAdditionDialog(QWidget *parent); torrentAdditionDialog(QWidget *parent);
~torrentAdditionDialog(); ~torrentAdditionDialog();
void readSettings();
void saveSettings();
void showLoadMagnetURI(QString magnet_uri); void showLoadMagnetURI(QString magnet_uri);
void showLoad(QString filePath, QString from_url=QString::null); void showLoad(QString filePath, QString from_url=QString::null);
QString getCurrentTruncatedSavePath(QString* root_folder_or_file_name = 0) const; QString getCurrentTruncatedSavePath(QString* root_folder_or_file_name = 0) const;
@ -73,6 +71,12 @@ public slots:
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
private:
void readSettings();
void saveSettings();
void loadFilesListState();
void saveFilesListState();
private: private:
QString fileName; QString fileName;
QString hash; QString hash;

7
src/transferlistwidget.cpp

@ -65,6 +65,10 @@ using namespace libtorrent;
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession): TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession):
QTreeView(parent), BTSession(_BTSession), main_window(main_window) { QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
// Load settings
loadSettings();
// Create and apply delegate // Create and apply delegate
listDelegate = new TransferListDelegate(this); listDelegate = new TransferListDelegate(this);
setItemDelegate(listDelegate); setItemDelegate(listDelegate);
@ -120,9 +124,6 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window,
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&))); connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&)));
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&))); connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&)));
// Load settings
loadSettings();
} }
TransferListWidget::~TransferListWidget() { TransferListWidget::~TransferListWidget() {

Loading…
Cancel
Save