Browse Source

- Still optimizing

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
7bd0dff802
  1. 15
      src/FinishedTorrents.cpp
  2. 27
      src/arborescence.h
  3. 5
      src/properties_imp.cpp
  4. 2
      src/properties_imp.h
  5. 2
      src/src.pro
  6. 9
      src/torrentAddition.h

15
src/FinishedTorrents.cpp

@ -133,9 +133,8 @@ void FinishedTorrents::setRowColor(int row, QString color){ @@ -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{ @@ -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){ @@ -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(){ @@ -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(){ @@ -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();

27
src/arborescence.h

@ -32,7 +32,7 @@ class torrent_file { @@ -32,7 +32,7 @@ class torrent_file {
torrent_file *parent;
bool is_dir;
QString rel_path;
QList<torrent_file*> children;
QList<const torrent_file*> children;
size_type size;
float progress;
int priority;
@ -68,8 +68,7 @@ class torrent_file { @@ -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 { @@ -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 { @@ -111,14 +109,13 @@ class torrent_file {
return (!children.isEmpty());
}
QList<torrent_file*> getChildren() const {
QList<const torrent_file*> 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 { @@ -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 { @@ -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 { @@ -256,7 +251,7 @@ class arborescence {
child = dad->addChild(fileName, false, file_size, index, progress, priority);
}
}
dad = child;
dad = (torrent_file*)child;
}
}
};

5
src/properties_imp.cpp

@ -146,7 +146,7 @@ properties::~properties(){ @@ -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<QStandardItem*> child;
// Name
QStandardItem *first;
@ -168,8 +168,7 @@ void properties::addFilesToTree(torrent_file *root, QStandardItem *parent) { @@ -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);
}
}

2
src/properties_imp.h

@ -72,7 +72,7 @@ class properties : public QDialog, private Ui::properties{ @@ -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);

2
src/src.pro

@ -3,7 +3,7 @@ LANG_PATH = lang @@ -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

9
src/torrentAddition.h

@ -141,7 +141,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -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<QStandardItem*> child;
// Name
QStandardItem *first;
@ -163,10 +163,9 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ @@ -163,10 +163,9 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
// Add the child to the tree
parent->appendRow(child);
// Add children
QList<torrent_file*> children = root->getChildren();
unsigned int nbChildren = children.size();
for(unsigned int i=0; i < nbChildren; ++i) {
addFilesToTree(children.at(i), first);
QList<const torrent_file*> children = root->getChildren();
foreach(const torrent_file *child, children) {
addFilesToTree(child, first);
}
}

Loading…
Cancel
Save