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 @@ @@ -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 @@ -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() { @@ -262,42 +262,12 @@ void PeerListWidget::clear() {
void PeerListWidget::loadSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth")).toStringList());
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);
}
header()->restoreState(settings.value("TorrentProperties/Peers/PeerListState").toByteArray());
}
void PeerListWidget::saveSettings() const {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QStringList contentColsWidths;
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));
settings.setValue("TorrentProperties/Peers/PeerListState", header()->saveState());
}
void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) {

27
src/properties/propertieswidget.cpp

@ -61,8 +61,9 @@ using namespace libtorrent; @@ -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 @@ -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) { @@ -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<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
QStringList sizes_str = settings.value(QString::fromUtf8("TorrentProperties/SplitterSizes"), QString()).toString().split(",");
if(sizes_str.size() == 2) {
@ -300,11 +304,6 @@ void PropertiesWidget::readSettings() { @@ -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; i<PropListModel->model()->columnCount(); ++i) {
contentColsWidths << QString::number(filesList->columnWidth(i));
}
settings.setValue(QString::fromUtf8("TorrentProperties/filesColsWidth"), contentColsWidths);
// Splitter sizes
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
QList<int> sizes;

4
src/properties/propertieswidget.h

@ -95,6 +95,10 @@ public slots: @@ -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;

15
src/properties/trackerlist.cpp

@ -47,6 +47,7 @@ @@ -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 @@ -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) { @@ -368,21 +368,12 @@ void TrackerList::showTrackerListMenu(QPoint) {
void TrackerList::loadSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth")).toStringList());
if(!contentColsWidths.empty()) {
for(int i=0; i<contentColsWidths.size(); ++i) {
setColumnWidth(i, contentColsWidths.at(i));
}
} else {
if(!header()->restoreState(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; i<columnCount(); ++i) {
contentColsWidths << QString::number(columnWidth(i));
}
settings.setValue(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth"), contentColsWidths);
settings.setValue("TorrentProperties/Trackers/TrackerListState", header()->saveState());
}

18
src/torrentadditiondlg.cpp

@ -63,6 +63,7 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) : @@ -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() { @@ -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) @@ -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() {

8
src/torrentadditiondlg.h

@ -46,8 +46,6 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -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: @@ -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;

7
src/transferlistwidget.cpp

@ -65,6 +65,10 @@ using namespace libtorrent; @@ -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, @@ -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() {

Loading…
Cancel
Save