From 762df4b914ec6b025ad327311a2936f39920f800 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 11 Apr 2007 13:10:13 +0000 Subject: [PATCH] - Columns width are now remembered on restart for the finished torrent list --- TODO | 3 ++- src/FinishedTorrents.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/FinishedTorrents.h | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 8365f9dbe..fcaae4eae 100644 --- a/TODO +++ b/TODO @@ -46,4 +46,5 @@ - Get upload/download limit per torrent (uncomment some code) - Improve ratio display / calculation / saving / per torrent... - Use buttonboxes when possible -- Display the sum of the size of the selected files in the torrent instead of the whole torrent size in download list \ No newline at end of file +- Display the sum of the size of the selected files in the torrent instead of the whole torrent size in download list +- Support column sorting in finished list \ No newline at end of file diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index c4d2cdc4c..0a4763fde 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -43,6 +43,10 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){ finishedList->setModel(finishedListModel); // Hide hash column finishedList->hideColumn(HASH); + // Load last columns width for download list + if(!loadColWidthFinishedList()){ + finishedList->header()->resizeSection(0, 200); + } finishedListDelegate = new DLListDelegate(); finishedList->setItemDelegate(finishedListDelegate); connect(finishedList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFinishedListMenu(const QPoint&))); @@ -58,6 +62,7 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){ } FinishedTorrents::~FinishedTorrents(){ + saveColWidthFinishedList(); delete finishedListDelegate; delete finishedListModel; } @@ -106,6 +111,39 @@ void FinishedTorrents::setRowColor(int row, const QString& color){ } } +// Load columns width in a file that were saved previously +// (finished list) +bool FinishedTorrents::loadColWidthFinishedList(){ + qDebug("Loading columns width for finished list"); + QSettings settings("qBittorrent", "qBittorrent"); + QString line = settings.value("FinishedListColsWidth", QString()).toString(); + if(line.isEmpty()) + return false; + QStringList width_list = line.split(' '); + if(width_list.size() != finishedListModel->columnCount()) + return false; + unsigned int listSize = width_list.size(); + for(unsigned int i=0; iheader()->resizeSection(i, width_list.at(i).toInt()); + } + qDebug("Finished list columns width loaded"); + return true; +} + +// Save columns width in a file to remember them +// (finished list) +void FinishedTorrents::saveColWidthFinishedList() const{ + qDebug("Saving columns width in finished list"); + QSettings settings("qBittorrent", "qBittorrent"); + QStringList width_list; + unsigned int nbColumns = finishedListModel->columnCount(); + for(unsigned int i=0; icolumnWidth(i)).c_str()); + } + settings.setValue("FinishedListColsWidth", width_list.join(" ")); + qDebug("Finished list columns width saved"); +} + void FinishedTorrents::on_actionSet_upload_limit_triggered(){ QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); QModelIndex index; diff --git a/src/FinishedTorrents.h b/src/FinishedTorrents.h index 1e015dc38..1545e3472 100644 --- a/src/FinishedTorrents.h +++ b/src/FinishedTorrents.h @@ -44,6 +44,7 @@ class FinishedTorrents : public QWidget, public Ui::seeding{ QStringList getFinishedSHAs(); QTreeView* getFinishedList(); QStandardItemModel* getFinishedListModel(); + bool loadColWidthFinishedList(); public slots: void addFinishedSHA(QString sha); @@ -53,6 +54,7 @@ class FinishedTorrents : public QWidget, public Ui::seeding{ void propertiesSelection(); void displayFinishedListMenu(const QPoint&); void setRowColor(int row, const QString& color); + void saveColWidthFinishedList() const; protected slots: void on_actionSet_upload_limit_triggered();