From 0db60065c03637c9d40d4496064c16998c76f066 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 23 Jul 2007 12:12:55 +0000 Subject: [PATCH] - Removed useless mutex in GUI - started to optimize headers includes for compilation speed --- TODO | 3 + src/FinishedTorrents.cpp | 142 +++++++++++++++++++++------------------ src/FinishedTorrents.h | 10 ++- src/GUI.cpp | 4 +- src/GUI.h | 12 +--- src/rss_imp.cpp | 1 + src/rss_imp.h | 1 - 7 files changed, 88 insertions(+), 85 deletions(-) diff --git a/TODO b/TODO index f770ff7a6..3958df1e5 100644 --- a/TODO +++ b/TODO @@ -47,6 +47,9 @@ - .ico support? - display debug when fastresume data is rejected - Download/Finished lists cleanup + - Use valgrind to detect memory leaks + - optimize includes for compilation speed + - Move transfer lists refreshers to threads - Wait for some bug fixes in libtorrent : - upload/download limit per torrent - ipfilter crash diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index 133791c2e..0507b73b2 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -22,9 +22,13 @@ #include "misc.h" #include "GUI.h" #include "properties_imp.h" +#include "bittorrent.h" #include "allocationDlg.h" +#include "FinishedListDelegate.h" + #include #include +#include FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){ setupUi(this); @@ -115,73 +119,6 @@ void FinishedTorrents::setRowColor(int row, QString color){ } } -void FinishedTorrents::sortFinishedList(int index){ - static Qt::SortOrder sortOrder = Qt::AscendingOrder; - if(finishedList->header()->sortIndicatorSection() == index){ - if(sortOrder == Qt::AscendingOrder){ - sortOrder = Qt::DescendingOrder; - }else{ - sortOrder = Qt::AscendingOrder; - } - } - finishedList->header()->setSortIndicator(index, sortOrder); - switch(index){ - case F_SIZE: - case F_UPSPEED: - case F_PROGRESS: - sortFinishedListFloat(index, sortOrder); - break; - default: - sortFinishedListString(index, sortOrder); - } -} - -void FinishedTorrents::sortFinishedListFloat(int index, Qt::SortOrder sortOrder){ - QList > lines; - // insertion sorting - unsigned int nbRows = finishedListModel->rowCount(); - for(unsigned int i=0; i(i, finishedListModel->data(finishedListModel->index(i, index)).toDouble()), sortOrder); - } - // Insert items in new model, in correct order - unsigned int nbRows_old = lines.size(); - for(unsigned int row=0; rowinsertRow(finishedListModel->rowCount()); - unsigned int sourceRow = lines[row].first; - unsigned int nbColumns = finishedListModel->columnCount(); - for(unsigned int col=0; colsetData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col))); - finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole); - finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole); - } - } - // Remove old rows - finishedListModel->removeRows(0, nbRows_old); -} - -void FinishedTorrents::sortFinishedListString(int index, Qt::SortOrder sortOrder){ - QList > lines; - // Insertion sorting - unsigned int nbRows = finishedListModel->rowCount(); - for(unsigned int i=0; i(i, finishedListModel->data(finishedListModel->index(i, index)).toString()), sortOrder); - } - // Insert items in new model, in correct order - unsigned int nbRows_old = lines.size(); - for(unsigned int row=0; rowinsertRow(finishedListModel->rowCount()); - unsigned int sourceRow = lines[row].first; - unsigned int nbColumns = finishedListModel->columnCount(); - for(unsigned int col=0; colsetData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col))); - finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole); - finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole); - } - } - // Remove old rows - finishedListModel->removeRows(0, nbRows_old); -} - // Load columns width in a file that were saved previously // (finished list) bool FinishedTorrents::loadColWidthFinishedList(){ @@ -350,3 +287,74 @@ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){ // XXX: why mapToGlobal() is not enough? myFinishedListMenu.exec(mapToGlobal(pos)+QPoint(10,55)); } + +/* + * Sorting functions + */ + +void FinishedTorrents::sortFinishedList(int index){ + static Qt::SortOrder sortOrder = Qt::AscendingOrder; + if(finishedList->header()->sortIndicatorSection() == index){ + if(sortOrder == Qt::AscendingOrder){ + sortOrder = Qt::DescendingOrder; + }else{ + sortOrder = Qt::AscendingOrder; + } + } + finishedList->header()->setSortIndicator(index, sortOrder); + switch(index){ + case F_SIZE: + case F_UPSPEED: + case F_PROGRESS: + sortFinishedListFloat(index, sortOrder); + break; + default: + sortFinishedListString(index, sortOrder); + } +} + +void FinishedTorrents::sortFinishedListFloat(int index, Qt::SortOrder sortOrder){ + QList > lines; + // insertion sorting + unsigned int nbRows = finishedListModel->rowCount(); + for(unsigned int i=0; i(i, finishedListModel->data(finishedListModel->index(i, index)).toDouble()), sortOrder); + } + // Insert items in new model, in correct order + unsigned int nbRows_old = lines.size(); + for(unsigned int row=0; rowinsertRow(finishedListModel->rowCount()); + unsigned int sourceRow = lines[row].first; + unsigned int nbColumns = finishedListModel->columnCount(); + for(unsigned int col=0; colsetData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col))); + finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole); + finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole); + } + } + // Remove old rows + finishedListModel->removeRows(0, nbRows_old); +} + +void FinishedTorrents::sortFinishedListString(int index, Qt::SortOrder sortOrder){ + QList > lines; + // Insertion sorting + unsigned int nbRows = finishedListModel->rowCount(); + for(unsigned int i=0; i(i, finishedListModel->data(finishedListModel->index(i, index)).toString()), sortOrder); + } + // Insert items in new model, in correct order + unsigned int nbRows_old = lines.size(); + for(unsigned int row=0; rowinsertRow(finishedListModel->rowCount()); + unsigned int sourceRow = lines[row].first; + unsigned int nbColumns = finishedListModel->columnCount(); + for(unsigned int col=0; colsetData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col))); + finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole); + finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::TextColorRole), Qt::TextColorRole); + } + } + // Remove old rows + finishedListModel->removeRows(0, nbRows_old); +} diff --git a/src/FinishedTorrents.h b/src/FinishedTorrents.h index bb19f0af0..dd8cdfdff 100644 --- a/src/FinishedTorrents.h +++ b/src/FinishedTorrents.h @@ -23,9 +23,13 @@ #define SEEDING_H #include "ui_seeding.h" -#include "bittorrent.h" -#include "FinishedListDelegate.h" -#include +#include + +class QStandardItemModel; +class bittorrent; +class FinishedListDelegate; + +using namespace libtorrent; class FinishedTorrents : public QWidget, public Ui::seeding{ Q_OBJECT diff --git a/src/GUI.cpp b/src/GUI.cpp index cde19c61a..92de49f8e 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -45,6 +44,7 @@ #include "rss_imp.h" #include "FinishedTorrents.h" #include "allocationDlg.h" +#include "bittorrent.h" /***************************************************** * * @@ -542,7 +542,6 @@ void GUI::sortProgressColumnDelayed() { void GUI::updateDlList(bool force){ char tmp[MAX_CHAR_TMP]; char tmp2[MAX_CHAR_TMP]; - QMutexLocker lock(&DLListAccess); // update global informations snprintf(tmp, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadUploadRate()/1024.); snprintf(tmp2, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadDownloadRate()/1024.); @@ -726,7 +725,6 @@ void GUI::sortDownloadListString(int index, Qt::SortOrder sortOrder){ } void GUI::sortDownloadList(int index, Qt::SortOrder startSortOrder, bool fromLoadColWidth){ - QMutexLocker lock(&DLListAccess); qDebug("Called sort download list"); static Qt::SortOrder sortOrder = startSortOrder; if(!fromLoadColWidth && downloadList->header()->sortIndicatorSection() == index){ diff --git a/src/GUI.h b/src/GUI.h index 7f451bd90..ec2aed5fe 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -25,23 +25,14 @@ #include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include #include "ui_MainWindow.h" #include "options_imp.h" #include "about_imp.h" #include "previewSelect.h" #include "trackerLogin.h" -#include "bittorrent.h" +class bittorrent; class createtorrent; class QTimer; class FinishedTorrents; @@ -86,7 +77,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{ bool force_exit; bool delayedSorting; Qt::SortOrder delayedSortingOrder; - QMutex DLListAccess; // Keyboard shortcuts QShortcut *createShortcut; QShortcut *openShortcut; diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index 8989e8466..a6a40ed4b 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "misc.h" // display a right-click menu diff --git a/src/rss_imp.h b/src/rss_imp.h index 5c6a68ae8..c3c601d2c 100644 --- a/src/rss_imp.h +++ b/src/rss_imp.h @@ -26,7 +26,6 @@ #include #include "ui_rss.h" #include "rss.h" -#include "GUI.h" #define DESCRIPTION_CHILD 0 #define URL_CHILD 1