From 7bd0dff802a278561be16e2dfd4b049da7f50306 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 24 Jan 2009 19:54:33 +0000 Subject: [PATCH] - Still optimizing --- src/FinishedTorrents.cpp | 15 +++++---------- src/arborescence.h | 27 +++++++++++---------------- src/properties_imp.cpp | 5 ++--- src/properties_imp.h | 2 +- src/src.pro | 2 +- src/torrentAddition.h | 9 ++++----- 6 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index 4a69c49fe..65c73299e 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -133,9 +133,8 @@ void FinishedTorrents::setRowColor(int row, QString color){ QStringList FinishedTorrents::getSelectedTorrents(bool only_one) const{ QStringList res; - QModelIndex index; QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); - foreach(index, selectedIndexes) { + foreach(const QModelIndex &index, selectedIndexes) { if(index.column() == F_NAME) { // Get the file hash QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString(); @@ -218,9 +217,8 @@ void FinishedTorrents::saveColWidthFinishedList() const{ void FinishedTorrents::on_actionSet_upload_limit_triggered(){ QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); - QModelIndex index; QStringList hashes; - foreach(index, selectedIndexes){ + foreach(const QModelIndex &index, selectedIndexes){ if(index.column() == F_NAME){ // Get the file hash hashes << finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString(); @@ -330,8 +328,7 @@ void FinishedTorrents::updateFileSize(QString hash){ // display properties of selected items void FinishedTorrents::propertiesSelection(){ QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); - QModelIndex index; - foreach(index, selectedIndexes){ + foreach(const QModelIndex &index, selectedIndexes){ if(index.column() == F_NAME){ showProperties(index); } @@ -340,8 +337,7 @@ void FinishedTorrents::propertiesSelection(){ void FinishedTorrents::forceRecheck(){ QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); - QModelIndex index; - foreach(index, selectedIndexes){ + foreach(const QModelIndex &index, selectedIndexes){ if(index.column() == F_NAME){ QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString(); QTorrentHandle h = BTSession->getTorrentHandle(hash); @@ -352,11 +348,10 @@ void FinishedTorrents::forceRecheck(){ void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){ QMenu myFinishedListMenu(this); - QModelIndex index; // Enable/disable pause/start action given the DL state QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); bool has_pause = false, has_start = false, has_preview = false; - foreach(index, selectedIndexes) { + foreach(const QModelIndex &index, selectedIndexes) { if(index.column() == F_NAME) { // Get the file name QString hash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString(); diff --git a/src/arborescence.h b/src/arborescence.h index 061ee5a77..d2d0af623 100644 --- a/src/arborescence.h +++ b/src/arborescence.h @@ -32,7 +32,7 @@ class torrent_file { torrent_file *parent; bool is_dir; QString rel_path; - QList children; + QList children; size_type size; float progress; int priority; @@ -68,8 +68,7 @@ class torrent_file { } float wanted = 0.; float done = 0.; - torrent_file *child; - foreach(child, children) { + foreach(const torrent_file *child, children) { wanted += child->getSize(); done += child->getSize()*child->getProgress(); } @@ -80,8 +79,7 @@ class torrent_file { void updatePriority(int prio) { Q_ASSERT(is_dir); - torrent_file *child; - foreach(child, children) { + foreach(const torrent_file *child, children) { if(child->getPriority() != prio) return; } priority = prio; @@ -111,14 +109,13 @@ class torrent_file { return (!children.isEmpty()); } - QList getChildren() const { + QList getChildren() const { return children; } - torrent_file* getChild(QString fileName) const { + const torrent_file* getChild(QString fileName) const { Q_ASSERT(is_dir); - torrent_file* f; - foreach(f, children) { + foreach(const torrent_file *f, children) { if(f->name() == fileName) return f; } return 0; @@ -141,16 +138,15 @@ class torrent_file { return f; } - bool removeFromFS(QString saveDir) { + bool removeFromFS(QString saveDir) const { QString full_path = saveDir + QDir::separator() + rel_path; if(!QFile::exists(full_path)) { qDebug("%s does not exist, no need to remove it", full_path.toUtf8().data()); return true; } bool success = true; - torrent_file *f; qDebug("We have %d children", children.size()); - foreach(f, children) { + foreach(const torrent_file *f, children) { bool s = f->removeFromFS(saveDir); success = s && success; } @@ -239,14 +235,13 @@ class arborescence { if(relative_path.at(0) ==QDir::separator()) relative_path.remove(0, 1); QStringList fileNames = relative_path.split(QDir::separator()); - QString fileName; torrent_file *dad = root; unsigned int nb_i = 0; unsigned int size = fileNames.size(); - foreach(fileName, fileNames) { + foreach(const QString &fileName, fileNames) { ++nb_i; if(fileName == ".") continue; - torrent_file* child = dad->getChild(fileName); + const torrent_file* child = dad->getChild(fileName); if(!child) { if(nb_i != size) { // Folder @@ -256,7 +251,7 @@ class arborescence { child = dad->addChild(fileName, false, file_size, index, progress, priority); } } - dad = child; + dad = (torrent_file*)child; } } }; diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index 3036e4a31..713dee271 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -146,7 +146,7 @@ properties::~properties(){ delete progressBar; } -void properties::addFilesToTree(torrent_file *root, QStandardItem *parent) { +void properties::addFilesToTree(const torrent_file *root, QStandardItem *parent) { QList child; // Name QStandardItem *first; @@ -168,8 +168,7 @@ void properties::addFilesToTree(torrent_file *root, QStandardItem *parent) { // Add the child to the tree parent->appendRow(child); // Add childs - torrent_file *childFile; - foreach(childFile, root->getChildren()) { + foreach(const torrent_file *childFile, root->getChildren()) { addFilesToTree(childFile, first); } } diff --git a/src/properties_imp.h b/src/properties_imp.h index d1ed50732..06a736d40 100644 --- a/src/properties_imp.h +++ b/src/properties_imp.h @@ -72,7 +72,7 @@ class properties : public QDialog, private Ui::properties{ void saveWebSeeds(); void loadWebSeedsFromFile(); void deleteSelectedUrlSeeds(); - void addFilesToTree(torrent_file *root, QStandardItem *parent); + void addFilesToTree(const torrent_file *root, QStandardItem *parent); void updateChildrenPriority(QStandardItem *item, int priority); void updateParentsPriority(QStandardItem *item, int priority); void updatePriorities(QStandardItem *item); diff --git a/src/src.pro b/src/src.pro index 7f49e6a8d..413188c3c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -3,7 +3,7 @@ LANG_PATH = lang ICONS_PATH = Icons # Set the following variable to 1 to enable debug -DEBUG_MODE = 0 +DEBUG_MODE = 1 # Global TEMPLATE = app diff --git a/src/torrentAddition.h b/src/torrentAddition.h index f36b10f5e..18ddcb475 100644 --- a/src/torrentAddition.h +++ b/src/torrentAddition.h @@ -141,7 +141,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ show(); } - void addFilesToTree(torrent_file *root, QStandardItem *parent) { + void addFilesToTree(const torrent_file *root, QStandardItem *parent) { QList child; // Name QStandardItem *first; @@ -163,10 +163,9 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ // Add the child to the tree parent->appendRow(child); // Add children - QList children = root->getChildren(); - unsigned int nbChildren = children.size(); - for(unsigned int i=0; i < nbChildren; ++i) { - addFilesToTree(children.at(i), first); + QList children = root->getChildren(); + foreach(const torrent_file *child, children) { + addFilesToTree(child, first); } }