From 6dd78d33aba6a3a1e274f6a5f959097d352c5855 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 30 Jul 2007 10:27:56 +0000 Subject: [PATCH] - Improved download list popup menu code - Added some asserts - bit of code improvement/clean up --- TODO | 1 + src/GUI.cpp | 39 ++++++++++++++++++++++++++------------- src/GUI.h | 4 ++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index 5fe0e5681..938dd3d05 100644 --- a/TODO +++ b/TODO @@ -32,6 +32,7 @@ - Web interface (turbogears?) - improve and test tracker authentication code (remember login/pass) - support zipped torrents? +- Split Download list / GUI code // in v1.0.0 (partial) - WIP - Check storage st creation + hasher in torrent creation diff --git a/src/GUI.cpp b/src/GUI.cpp index e5c01967b..a42ee641b 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -389,6 +389,7 @@ void GUI::on_actionSet_download_limit_triggered(){ hashes << DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); } } + Q_ASSERT(hashes.size() > 0); new BandwidthAllocationDialog(this, false, BTSession, hashes); } @@ -402,10 +403,11 @@ void GUI::on_actionSet_upload_limit_triggered(){ hashes << DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); } } + Q_ASSERT(hashes.size() > 0); new BandwidthAllocationDialog(this, true, BTSession, hashes); } -void GUI::handleDownloadFromUrlFailure(QString url, QString reason){ +void GUI::handleDownloadFromUrlFailure(QString url, QString reason) const{ // Display a message box QMessageBox::critical(0, tr("Url download error"), tr("Couldn't download file at url: %1, reason: %2.").arg(url).arg(reason)); } @@ -423,7 +425,7 @@ void GUI::on_actionSet_global_download_limit_triggered(){ void GUI::on_actionPreview_file_triggered(){ if(tabs->currentIndex() > 1) return; bool inDownloadList = true; - if(tabs->currentIndex() != 0) + if(tabs->currentIndex()) inDownloadList = false; QModelIndex index; QModelIndexList selectedIndexes; @@ -447,7 +449,9 @@ void GUI::on_actionPreview_file_triggered(){ } void GUI::cleanTempPreviewFile(int, QProcess::ExitStatus){ - QFile::remove(QDir::tempPath()+QDir::separator()+"qBT_preview.tmp"); + if(!QFile::remove(QDir::tempPath()+QDir::separator()+"qBT_preview.tmp")){ + std::cerr << "Couldn't remove temporary file: " << (const char*)(QDir::tempPath()+QDir::separator()+"qBT_preview.tmp").toUtf8() << "\n"; + } } void GUI::displayDLListMenu(const QPoint& pos){ @@ -457,28 +461,37 @@ void GUI::displayDLListMenu(const QPoint& pos){ QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); QSettings settings("qBittorrent", "qBittorrent"); QString previewProgram = settings.value("Options/Misc/PreviewProgram", QString()).toString(); + bool has_pause = false, has_start = false, has_preview = false; foreach(index, selectedIndexes){ if(index.column() == NAME){ // Get the file name QString fileHash = DLListModel->data(DLListModel->index(index.row(), HASH)).toString(); // Get handle and pause the torrent torrent_handle h = BTSession->getTorrentHandle(fileHash); + if(!h.is_valid()) continue; if(h.is_paused()){ - myDLLlistMenu.addAction(actionStart); + if(!has_start){ + myDLLlistMenu.addAction(actionStart); + has_start = true; + } }else{ - myDLLlistMenu.addAction(actionPause); + if(!has_pause){ + myDLLlistMenu.addAction(actionPause); + has_pause = true; + } } - myDLLlistMenu.addAction(actionDelete); - myDLLlistMenu.addAction(actionDelete_Permanently); - myDLLlistMenu.addAction(actionSet_download_limit); - myDLLlistMenu.addAction(actionSet_upload_limit); - myDLLlistMenu.addAction(actionTorrent_Properties); - if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(fileHash) && selectedIndexes.size()<=DLListModel->columnCount()){ + if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(fileHash) && !has_preview){ myDLLlistMenu.addAction(actionPreview_file); + has_preview = true; } - break; + if(has_pause && has_start && has_preview) break; } } + myDLLlistMenu.addAction(actionDelete); + myDLLlistMenu.addAction(actionDelete_Permanently); + myDLLlistMenu.addAction(actionSet_download_limit); + myDLLlistMenu.addAction(actionSet_upload_limit); + myDLLlistMenu.addAction(actionTorrent_Properties); // Call menu // XXX: why mapToGlobal() is not enough? myDLLlistMenu.exec(mapToGlobal(pos)+QPoint(22,180)); @@ -809,7 +822,7 @@ void GUI::toggleVisibility(QSystemTrayIcon::ActivationReason e){ } // Center window -QPoint GUI::screenCenter(){ +QPoint GUI::screenCenter() const{ int scrn = 0; QWidget *w = this->topLevelWidget(); diff --git a/src/GUI.h b/src/GUI.h index ffc92f3c1..2b96e0b1c 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -130,7 +130,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void displayUpTab(); void displaySearchTab(); void displayRSSTab(); - void handleDownloadFromUrlFailure(QString, QString); + void handleDownloadFromUrlFailure(QString, QString) const; // Torrent actions void showProperties(const QModelIndex &index); void on_actionTorrent_Properties_triggered(); @@ -188,7 +188,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ // Methods int getRowFromHash(QString hash) const; unsigned int getCurrentTabIndex() const; - QPoint screenCenter(); + QPoint screenCenter() const; }; #endif