Browse Source

- Removed useless mutex in GUI

- started to optimize headers includes for compilation speed
adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
0db60065c0
  1. 3
      TODO
  2. 142
      src/FinishedTorrents.cpp
  3. 10
      src/FinishedTorrents.h
  4. 4
      src/GUI.cpp
  5. 12
      src/GUI.h
  6. 1
      src/rss_imp.cpp
  7. 1
      src/rss_imp.h

3
TODO

@ -47,6 +47,9 @@ @@ -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

142
src/FinishedTorrents.cpp

@ -22,9 +22,13 @@ @@ -22,9 +22,13 @@
#include "misc.h"
#include "GUI.h"
#include "properties_imp.h"
#include "bittorrent.h"
#include "allocationDlg.h"
#include "FinishedListDelegate.h"
#include <QFile>
#include <QSettings>
#include <QStandardItemModel>
FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){
setupUi(this);
@ -115,73 +119,6 @@ void FinishedTorrents::setRowColor(int row, QString color){ @@ -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<QPair<int, double> > lines;
// insertion sorting
unsigned int nbRows = finishedListModel->rowCount();
for(unsigned int i=0; i<nbRows; ++i){
misc::insertSort(lines, QPair<int,double>(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; row<nbRows_old; ++row){
finishedListModel->insertRow(finishedListModel->rowCount());
unsigned int sourceRow = lines[row].first;
unsigned int nbColumns = finishedListModel->columnCount();
for(unsigned int col=0; col<nbColumns; ++col){
finishedListModel->setData(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<QPair<int, QString> > lines;
// Insertion sorting
unsigned int nbRows = finishedListModel->rowCount();
for(unsigned int i=0; i<nbRows; ++i){
misc::insertSortString(lines, QPair<int, QString>(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; row<nbRows_old; ++row){
finishedListModel->insertRow(finishedListModel->rowCount());
unsigned int sourceRow = lines[row].first;
unsigned int nbColumns = finishedListModel->columnCount();
for(unsigned int col=0; col<nbColumns; ++col){
finishedListModel->setData(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){ @@ -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<QPair<int, double> > lines;
// insertion sorting
unsigned int nbRows = finishedListModel->rowCount();
for(unsigned int i=0; i<nbRows; ++i){
misc::insertSort(lines, QPair<int,double>(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; row<nbRows_old; ++row){
finishedListModel->insertRow(finishedListModel->rowCount());
unsigned int sourceRow = lines[row].first;
unsigned int nbColumns = finishedListModel->columnCount();
for(unsigned int col=0; col<nbColumns; ++col){
finishedListModel->setData(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<QPair<int, QString> > lines;
// Insertion sorting
unsigned int nbRows = finishedListModel->rowCount();
for(unsigned int i=0; i<nbRows; ++i){
misc::insertSortString(lines, QPair<int, QString>(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; row<nbRows_old; ++row){
finishedListModel->insertRow(finishedListModel->rowCount());
unsigned int sourceRow = lines[row].first;
unsigned int nbColumns = finishedListModel->columnCount();
for(unsigned int col=0; col<nbColumns; ++col){
finishedListModel->setData(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);
}

10
src/FinishedTorrents.h

@ -23,9 +23,13 @@ @@ -23,9 +23,13 @@
#define SEEDING_H
#include "ui_seeding.h"
#include "bittorrent.h"
#include "FinishedListDelegate.h"
#include <QStandardItemModel>
#include <libtorrent/torrent_handle.hpp>
class QStandardItemModel;
class bittorrent;
class FinishedListDelegate;
using namespace libtorrent;
class FinishedTorrents : public QWidget, public Ui::seeding{
Q_OBJECT

4
src/GUI.cpp

@ -27,7 +27,6 @@ @@ -27,7 +27,6 @@
#include <QTcpServer>
#include <QTcpSocket>
#include <QCloseEvent>
#include <QMutexLocker>
#include <QShortcut>
#include <libtorrent/extensions/metadata_transfer.hpp>
@ -45,6 +44,7 @@ @@ -45,6 +44,7 @@
#include "rss_imp.h"
#include "FinishedTorrents.h"
#include "allocationDlg.h"
#include "bittorrent.h"
/*****************************************************
* *
@ -542,7 +542,6 @@ void GUI::sortProgressColumnDelayed() { @@ -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){ @@ -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){

12
src/GUI.h

@ -25,23 +25,14 @@ @@ -25,23 +25,14 @@
#include <QMainWindow>
#include <QProcess>
#include <QSystemTrayIcon>
#include <QMutex>
#include <libtorrent/entry.hpp>
#include <libtorrent/bencode.hpp>
#include <libtorrent/session.hpp>
#include <libtorrent/fingerprint.hpp>
#include <libtorrent/session_settings.hpp>
#include <libtorrent/identify_client.hpp>
#include <libtorrent/alert_types.hpp>
#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{ @@ -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;

1
src/rss_imp.cpp

@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
#include <QInputDialog>
#include <QMenu>
#include <QStandardItemModel>
#include <QMessageBox>
#include "misc.h"
// display a right-click menu

1
src/rss_imp.h

@ -26,7 +26,6 @@ @@ -26,7 +26,6 @@
#include <QTimer>
#include "ui_rss.h"
#include "rss.h"
#include "GUI.h"
#define DESCRIPTION_CHILD 0
#define URL_CHILD 1

Loading…
Cancel
Save