From b8200fd7b2047a9b82e96581dc5518c2dbefacb5 Mon Sep 17 00:00:00 2001 From: Arnaud Demaiziere Date: Mon, 19 Nov 2007 00:58:14 +0000 Subject: [PATCH] feature : allow to hide/show columns --- Changelog | 1 + src/FinishedTorrents.cpp | 187 +++++++++++++++++++++++++++++++++- src/FinishedTorrents.h | 11 ++ src/download.ui | 45 ++++++++ src/downloadingTorrents.cpp | 197 +++++++++++++++++++++++++++++++++++- src/downloadingTorrents.h | 13 +++ src/seeding.ui | 35 +++++++ 7 files changed, 480 insertions(+), 9 deletions(-) diff --git a/Changelog b/Changelog index d6bcb5b2e..dca03252d 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ * Tuesday October 06 2007 - Christophe Dumez - v1.1.0 + - FEATURE: Allow to hide/show some columns in download and seeding lists - FEATURE: Option to start qBittorrent minimized in systray - FEATURE: Allow to define double-click actions in torrents lists - FEATURE: Allow to open torrent destination folder diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index a47154198..319861115 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -45,6 +45,7 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession) : par finishedListModel->setHeaderData(F_SEEDSLEECH, Qt::Horizontal, tr("Leechers", "i.e: full/partial sources")); finishedListModel->setHeaderData(F_RATIO, Qt::Horizontal, tr("Ratio")); finishedList->setModel(finishedListModel); + loadHiddenColumns(); // Hide ETA & hash column finishedList->hideColumn(F_HASH); // Load last columns width for download list @@ -71,10 +72,19 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession) : par connect(actionDelete_Permanently, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionDelete_Permanently_triggered())); connect(actionOpen_destination_folder, SIGNAL(triggered()), (GUI*)parent, SLOT(openDestinationFolder())); connect(actionTorrent_Properties, SIGNAL(triggered()), this, SLOT(propertiesSelection())); + + connect(actionHOSColName, SIGNAL(triggered()), this, SLOT(hideOrShowColumnName())); + connect(actionHOSColSize, SIGNAL(triggered()), this, SLOT(hideOrShowColumnSize())); + connect(actionHOSColProgress, SIGNAL(triggered()), this, SLOT(hideOrShowColumnProgress())); + connect(actionHOSColUpSpeed, SIGNAL(triggered()), this, SLOT(hideOrShowColumnUpSpeed())); + connect(actionHOSColLeechers, SIGNAL(triggered()), this, SLOT(hideOrShowColumnLeechers())); + connect(actionHOSColRatio, SIGNAL(triggered()), this, SLOT(hideOrShowColumnRatio())); + connect(actionResizeAllColumns, SIGNAL(triggered()), this, SLOT(resetAllColumns())); } FinishedTorrents::~FinishedTorrents(){ saveColWidthFinishedList(); + saveHiddenColumns(); delete finishedListDelegate; delete finishedListModel; } @@ -157,7 +167,7 @@ bool FinishedTorrents::loadColWidthFinishedList(){ if(line.isEmpty()) return false; QStringList width_list = line.split(' '); - if(width_list.size() != finishedListModel->columnCount()-1) + if(width_list.size() < finishedListModel->columnCount()-1) return false; unsigned int listSize = width_list.size(); for(unsigned int i=0; icolumnCount()-1; - for(unsigned int i=0; icolumnWidth(i)).c_str()); + QStringList new_width_list; + short nbColumns = finishedListModel->columnCount()-1; + + QString line = settings.value("FinishedListColsWidth", QString()).toString(); + if(!line.isEmpty()) { + width_list = line.split(' '); + } + for(short i=0; icolumnWidth(i)<1 && width_list.size() == finishedListModel->columnCount()-1 && width_list.at(i).toInt()>=1) { + // load the former width + new_width_list << width_list.at(i); + } else if(finishedList->columnWidth(i)>=1) { + // usual case, save the current width + new_width_list << QString::fromUtf8(misc::toString(finishedList->columnWidth(i)).c_str()); + } else { + // default width + finishedList->resizeColumnToContents(i); + new_width_list << QString::fromUtf8(misc::toString(finishedList->columnWidth(i)).c_str()); + } } - settings.setValue("FinishedListColsWidth", width_list.join(" ")); + settings.setValue("FinishedListColsWidth", new_width_list.join(" ")); qDebug("Finished list columns width saved"); } @@ -355,11 +381,162 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){ myFinishedListMenu.addSeparator(); myFinishedListMenu.addAction(actionOpen_destination_folder); myFinishedListMenu.addAction(actionTorrent_Properties); + // hide/show columns menu + QMenu hideshowColumn(this); + hideshowColumn.setTitle(tr("Hide or Show Column")); + for(int i=0; i<=F_RATIO; i++) { + hideshowColumn.addAction(getActionHoSCol(i)); + } + hideshowColumn.addAction(actionResizeAllColumns); + myFinishedListMenu.addMenu(&hideshowColumn); + // Call menu // XXX: why mapToGlobal() is not enough? myFinishedListMenu.exec(mapToGlobal(pos)+QPoint(10,55)); } +/* + * Hiding Columns functions + */ + +// toggle hide/show a column +void FinishedTorrents::hideOrShowColumn(int index) { + if(!finishedList->isColumnHidden(index)) { + unsigned short i=0, nbColDisplayed = 0; + while(icolumnCount()-1 && nbColDisplayed<=1) { + if(!finishedList->isColumnHidden(i)) + nbColDisplayed++; + i++; + } + // can't hide a lonely column + if(nbColDisplayed>1) { + finishedList->setColumnHidden(index, true); + getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); + } + } else { + //short buf_width = finishedList->columnWidth(index); + short nbColumns = 0; + finishedList->setColumnHidden(index, false); + /*finishedList->resizeColumnToContents(index); + if(finishedList->columnWidth(index)setColumnWidth(index, buf_width);*/ + getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); + //resize all others non-hidden columns + for(int i=0; icolumnCount()-1; i++) { + if(finishedList->isColumnHidden(i)) + nbColumns++; + } + for(int i=0; icolumnCount()-1; i++) { + if(i != index) { + finishedList->setColumnWidth(i, floor(finishedList->columnWidth(i)-(finishedList->columnWidth(index)/(nbColumns-1)))); + } + } + } +} + +void FinishedTorrents::hideOrShowColumnName() { + hideOrShowColumn(F_NAME); +} + +void FinishedTorrents::hideOrShowColumnSize() { + hideOrShowColumn(F_SIZE); +} + +void FinishedTorrents::hideOrShowColumnProgress() { + hideOrShowColumn(F_PROGRESS); +} + +void FinishedTorrents::hideOrShowColumnUpSpeed() { + hideOrShowColumn(F_UPSPEED); +} + +void FinishedTorrents::hideOrShowColumnLeechers() { + hideOrShowColumn(F_SEEDSLEECH); +} + +void FinishedTorrents::hideOrShowColumnRatio() { + hideOrShowColumn(F_RATIO); +} + +void FinishedTorrents::resetAllColumns() { + for(int i=0; icolumnCount()-1; i++) { + finishedList->setColumnHidden(i, false); + finishedList->resizeColumnToContents(i); + getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); + } + finishedList->setColumnWidth(F_NAME,270); +} + +// load the previous settings, and hide the columns +bool FinishedTorrents::loadHiddenColumns() { + bool loaded = false; + QSettings settings("qBittorrent", "qBittorrent"); + QString line = settings.value("FinishedListColsHoS", QString()).toString(); + QStringList ishidden_list; + if(!line.isEmpty()) { + ishidden_list = line.split(' '); + if(ishidden_list.size() == finishedListModel->columnCount()-1) { + unsigned int listSize = ishidden_list.size(); + for(unsigned int i=0; iheader()->resizeSection(i, ishidden_list.at(i).toInt()); + } + loaded = true; + } + } + for(int i=0; icolumnCount()-1; i++) { + if(loaded && ishidden_list.at(i) == "0") { + finishedList->setColumnHidden(i, true); + getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); + } else { + getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); + } + } + return loaded; +} + +// save the hidden columns in settings +void FinishedTorrents::saveHiddenColumns() { + QSettings settings("qBittorrent", "qBittorrent"); + QStringList ishidden_list; + short nbColumns = finishedListModel->columnCount()-1; + + for(short i=0; iisColumnHidden(i)) { + ishidden_list << QString::fromUtf8(misc::toString(0).c_str()); + } else { + ishidden_list << QString::fromUtf8(misc::toString(1).c_str()); + } + } + settings.setValue("FinishedListColsHoS", ishidden_list.join(" ")); +} + +// getter, return the action hide or show whose id is index +QAction* FinishedTorrents::getActionHoSCol(int index) { + switch(index) { + case F_NAME : + return actionHOSColName; + break; + case F_SIZE : + return actionHOSColSize; + break; + case F_PROGRESS : + return actionHOSColProgress; + break; + case F_UPSPEED : + return actionHOSColUpSpeed; + break; + case F_SEEDSLEECH : + return actionHOSColLeechers; + break; + case F_RATIO : + return actionHOSColRatio; + break; + default : + return NULL; + } +} + + /* * Sorting functions */ diff --git a/src/FinishedTorrents.h b/src/FinishedTorrents.h index ee4ae035e..5cd4464ac 100644 --- a/src/FinishedTorrents.h +++ b/src/FinishedTorrents.h @@ -39,6 +39,10 @@ class FinishedTorrents : public QWidget, public Ui::seeding { FinishedListDelegate *finishedListDelegate; QStandardItemModel *finishedListModel; unsigned int nbFinished; + void hideOrShowColumn(int index); + bool loadHiddenColumns(); + void saveHiddenColumns(); + QAction* getActionHoSCol(int index); public: FinishedTorrents(QObject *parent, bittorrent *BTSession); @@ -71,6 +75,13 @@ class FinishedTorrents : public QWidget, public Ui::seeding { void propertiesSelection(); void deleteTorrent(QString hash); void showPropertiesFromHash(QString hash); + void hideOrShowColumnName(); + void hideOrShowColumnSize(); + void hideOrShowColumnProgress(); + void hideOrShowColumnUpSpeed(); + void hideOrShowColumnLeechers(); + void hideOrShowColumnRatio(); + void resetAllColumns(); signals: void torrentMovedFromFinishedList(QString); diff --git a/src/download.ui b/src/download.ui index 27167d847..5ddc65b98 100644 --- a/src/download.ui +++ b/src/download.ui @@ -388,6 +388,51 @@ Open destination folder + + + Name + + + + + Size + + + + + Progress + + + + + DLSpeed + + + + + UpSpeed + + + + + Seeds/Leechs + + + + + Ratio + + + + + ETA + + + + + Resize all + + diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index e98051ed9..1dcef85fc 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -65,6 +65,7 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) downloadList->setItemDelegate(DLDelegate); // Hide hash column downloadList->hideColumn(HASH); + loadHiddenColumns(); connect(BTSession, SIGNAL(addedTorrent(QString, QTorrentHandle&, bool)), this, SLOT(torrentAdded(QString, QTorrentHandle&, bool))); connect(BTSession, SIGNAL(duplicateTorrent(QString)), this, SLOT(torrentDuplicate(QString))); @@ -95,6 +96,17 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) connect(actionDelete_Permanently, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionDelete_Permanently_triggered())); connect(actionOpen_destination_folder, SIGNAL(triggered()), (GUI*)parent, SLOT(openDestinationFolder())); connect(actionTorrent_Properties, SIGNAL(triggered()), this, SLOT(propertiesSelection())); + + connect(actionHOSColName, SIGNAL(triggered()), this, SLOT(hideOrShowColumnName())); + connect(actionHOSColSize, SIGNAL(triggered()), this, SLOT(hideOrShowColumnSize())); + connect(actionHOSColProgress, SIGNAL(triggered()), this, SLOT(hideOrShowColumnProgress())); + connect(actionHOSColDownSpeed, SIGNAL(triggered()), this, SLOT(hideOrShowColumnDownSpeed())); + connect(actionHOSColUpSpeed, SIGNAL(triggered()), this, SLOT(hideOrShowColumnUpSpeed())); + connect(actionHOSColSeedersLeechers, SIGNAL(triggered()), this, SLOT(hideOrShowColumnSeedersLeechers())); + connect(actionHOSColRatio, SIGNAL(triggered()), this, SLOT(hideOrShowColumnRatio())); + connect(actionHOSColEta, SIGNAL(triggered()), this, SLOT(hideOrShowColumnEta())); + connect(actionResizeAllColumns, SIGNAL(triggered()), this, SLOT(resetAllColumns())); + // Set info Bar infos setInfoBar(tr("qBittorrent %1 started.", "e.g: qBittorrent v0.x started.").arg(QString::fromUtf8(""VERSION))); setInfoBar(tr("Be careful, sharing copyrighted material without permission is against the law."), QString::fromUtf8("red")); @@ -103,6 +115,7 @@ DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) DownloadingTorrents::~DownloadingTorrents() { saveColWidthDLList(); + saveHiddenColumns(); delete DLDelegate; delete DLListModel; } @@ -289,15 +302,176 @@ void DownloadingTorrents::displayDLListMenu(const QPoint& pos) { myDLLlistMenu.addSeparator(); myDLLlistMenu.addAction(actionOpen_destination_folder); myDLLlistMenu.addAction(actionTorrent_Properties); + // hide/show columns menu + QMenu hideshowColumn(this); + hideshowColumn.setTitle(tr("Hide or Show Column")); + for(int i=0; i<=ETA; i++) { + hideshowColumn.addAction(getActionHoSCol(i)); + } + hideshowColumn.addAction(actionResizeAllColumns); + myDLLlistMenu.addMenu(&hideshowColumn); // Call menu // XXX: why mapToGlobal() is not enough? myDLLlistMenu.exec(mapToGlobal(pos)+QPoint(10,60)); } + +/* + * Hiding Columns functions + */ + +// toggle hide/show a column +void DownloadingTorrents::hideOrShowColumn(int index) { + if(!downloadList->isColumnHidden(index)) { + unsigned short i=0, nbColDisplayed = 0; + while(icolumnCount()-1 && nbColDisplayed<=1) { + if(!downloadList->isColumnHidden(i)) + nbColDisplayed++; + i++; + } + // can't hide a lonely column + if(nbColDisplayed>1) { + downloadList->setColumnHidden(index, true); + getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); + } + } else { + short nbColumns = 0; + downloadList->setColumnHidden(index, false); + getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); + //resize all others non-hidden columns + for(int i=0; icolumnCount()-1; i++) { + if(downloadList->isColumnHidden(i)) + nbColumns++; + } + for(int i=0; icolumnCount()-1; i++) { + if(i != index) { + downloadList->setColumnWidth(i, floor(downloadList->columnWidth(i)-(downloadList->columnWidth(index)/(nbColumns-1)))); + } + } + } +} + +// save the hidden columns in settings +void DownloadingTorrents::saveHiddenColumns() { + QSettings settings("qBittorrent", "qBittorrent"); + QStringList ishidden_list; + short nbColumns = DLListModel->columnCount()-1; + + for(short i=0; iisColumnHidden(i)) { + ishidden_list << QString::fromUtf8(misc::toString(0).c_str()); + } else { + ishidden_list << QString::fromUtf8(misc::toString(1).c_str()); + } + } + settings.setValue("DownloadListColsHoS", ishidden_list.join(" ")); +} + +// load the previous settings, and hide the columns +bool DownloadingTorrents::loadHiddenColumns() { + bool loaded = false; + QSettings settings("qBittorrent", "qBittorrent"); + QString line = settings.value("DownloadListColsHoS", QString()).toString(); + QStringList ishidden_list; + if(!line.isEmpty()) { + ishidden_list = line.split(' '); + if(ishidden_list.size() == DLListModel->columnCount()-1) { + unsigned int listSize = ishidden_list.size(); + for(unsigned int i=0; iheader()->resizeSection(i, ishidden_list.at(i).toInt()); + } + loaded = true; + } + } + for(int i=0; icolumnCount()-1; i++) { + if(loaded && ishidden_list.at(i) == "0") { + downloadList->setColumnHidden(i, true); + getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png"))); + } else { + getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); + } + } + return loaded; +} + +void DownloadingTorrents::hideOrShowColumnName() { + hideOrShowColumn(NAME); +} + +void DownloadingTorrents::hideOrShowColumnSize() { + hideOrShowColumn(SIZE); +} + +void DownloadingTorrents::hideOrShowColumnProgress() { + hideOrShowColumn(PROGRESS); +} + +void DownloadingTorrents::hideOrShowColumnDownSpeed() { + hideOrShowColumn(DLSPEED); +} + +void DownloadingTorrents::hideOrShowColumnUpSpeed() { + hideOrShowColumn(UPSPEED); +} + +void DownloadingTorrents::hideOrShowColumnSeedersLeechers() { + hideOrShowColumn(SEEDSLEECH); +} + +void DownloadingTorrents::hideOrShowColumnRatio() { + hideOrShowColumn(RATIO); +} + +void DownloadingTorrents::hideOrShowColumnEta() { + hideOrShowColumn(ETA); +} + + void DownloadingTorrents::on_actionClearLog_triggered() { infoBar->clear(); } +// getter, return the action hide or show whose id is index +QAction* DownloadingTorrents::getActionHoSCol(int index) { + switch(index) { + case NAME : + return actionHOSColName; + break; + case SIZE : + return actionHOSColSize; + break; + case PROGRESS : + return actionHOSColProgress; + break; + case DLSPEED : + return actionHOSColDownSpeed; + break; + case UPSPEED : + return actionHOSColUpSpeed; + break; + case SEEDSLEECH : + return actionHOSColSeedersLeechers; + break; + case RATIO : + return actionHOSColRatio; + break; + case ETA : + return actionHOSColEta; + break; + default : + return NULL; + } +} + +void DownloadingTorrents::resetAllColumns() { + for(int i=0; icolumnCount()-1; i++) { + downloadList->setColumnHidden(i, false); + downloadList->resizeColumnToContents(i); + getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png"))); + } + downloadList->setColumnWidth(NAME,270); +} + QStringList DownloadingTorrents::getSelectedTorrents(bool only_one) const{ QStringList res; QModelIndex index; @@ -570,11 +744,26 @@ void DownloadingTorrents::saveColWidthDLList() const{ qDebug("Saving columns width in download list"); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QStringList width_list; - unsigned int nbColumns = DLListModel->columnCount()-1; - for(unsigned int i=0; icolumnWidth(i)); + QStringList new_width_list; + short nbColumns = DLListModel->columnCount()-1; + QString line = settings.value("DownloadListColsWidth", QString()).toString(); + if(!line.isEmpty()) { + width_list = line.split(' '); + } + for(short i=0; icolumnWidth(i)<1 && width_list.size() == DLListModel->columnCount()-1 && width_list.at(i).toInt()>=1) { + // load the former width + new_width_list << width_list.at(i); + } else if(downloadList->columnWidth(i)>=1) { + // usual case, save the current width + new_width_list << QString::fromUtf8(misc::toString(downloadList->columnWidth(i)).c_str()); + } else { + // default width + downloadList->resizeColumnToContents(i); + new_width_list << QString::fromUtf8(misc::toString(downloadList->columnWidth(i)).c_str()); + } } - settings.setValue(QString::fromUtf8("DownloadListColsWidth"), width_list.join(QString::fromUtf8(" "))); + settings.setValue(QString::fromUtf8("DownloadListColsWidth"), new_width_list.join(QString::fromUtf8(" "))); qDebug("Download list columns width saved"); } diff --git a/src/downloadingTorrents.h b/src/downloadingTorrents.h index aaa1fe25e..a9f1fa1de 100644 --- a/src/downloadingTorrents.h +++ b/src/downloadingTorrents.h @@ -41,6 +41,10 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{ bool delayedSorting; unsigned int nbTorrents; Qt::SortOrder delayedSortingOrder; + void hideOrShowColumn(int index); + bool loadHiddenColumns(); + void saveHiddenColumns(); + QAction* getActionHoSCol(int index); public: DownloadingTorrents(QObject *parent, bittorrent *BTSession); @@ -92,6 +96,15 @@ class DownloadingTorrents : public QWidget, public Ui::downloading{ void sortProgressColumnDelayed(); void updateFileSizeAndProgress(QString hash); void showPropertiesFromHash(QString hash); + void hideOrShowColumnName(); + void hideOrShowColumnSize(); + void hideOrShowColumnProgress(); + void hideOrShowColumnDownSpeed(); + void hideOrShowColumnUpSpeed(); + void hideOrShowColumnSeedersLeechers(); + void hideOrShowColumnRatio(); + void hideOrShowColumnEta(); + void resetAllColumns(); }; #endif diff --git a/src/seeding.ui b/src/seeding.ui index 255c0009f..6c754fc10 100644 --- a/src/seeding.ui +++ b/src/seeding.ui @@ -101,6 +101,41 @@ Open destination folder + + + Name + + + + + Size + + + + + Progress + + + + + Upload Speed + + + + + Leechers + + + + + Ratio + + + + + Resize All + +