From 1cc039c14783515ea117913e8807c231c39c88eb Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 27 Mar 2009 13:27:54 +0000 Subject: [PATCH] - Fixed search engine bug that prevented a torrent from appearing more than once among all tabs --- src/SearchTab.cpp | 3 ++- src/SearchTab.h | 2 ++ src/searchEngine.cpp | 14 ++++++-------- src/searchEngine.h | 1 - 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/SearchTab.cpp b/src/SearchTab.cpp index 57cbeda4b..058c80345 100644 --- a/src/SearchTab.cpp +++ b/src/SearchTab.cpp @@ -47,13 +47,14 @@ SearchTab::SearchTab(SearchEngine *parent) : QWidget() setLayout(box); // Set Search results list model - SearchListModel = new QStandardItemModel(0,5); + SearchListModel = new QStandardItemModel(0,6); SearchListModel->setHeaderData(SEARCH_NAME, Qt::Horizontal, tr("Name", "i.e: file name")); SearchListModel->setHeaderData(SEARCH_SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); SearchListModel->setHeaderData(SEARCH_SEEDERS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources")); SearchListModel->setHeaderData(SEARCH_LEECHERS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources")); SearchListModel->setHeaderData(SEARCH_ENGINE, Qt::Horizontal, tr("Search engine")); resultsBrowser->setModel(SearchListModel); + resultsBrowser->hideColumn(URL_COLUMN); // Hide url column SearchDelegate = new SearchListDelegate(); resultsBrowser->setItemDelegate(SearchDelegate); // Make search list header clickable for sorting diff --git a/src/SearchTab.h b/src/SearchTab.h index 545d0cc47..3cde00245 100644 --- a/src/SearchTab.h +++ b/src/SearchTab.h @@ -24,6 +24,8 @@ #include "ui_search.h" +#define URL_COLUMN 5 + class SearchListDelegate; class SearchEngine; class QTreeView; diff --git a/src/searchEngine.cpp b/src/searchEngine.cpp index 7a75114e1..640613863 100644 --- a/src/searchEngine.cpp +++ b/src/searchEngine.cpp @@ -243,7 +243,8 @@ void SearchEngine::searchStarted(){ void SearchEngine::downloadSelectedItem(const QModelIndex& index){ int row = index.row(); // Get Item url - QString url = searchResultsUrls.value(all_tab.at(tabWidget->currentIndex())->getCurrentSearchListModel()->data(all_tab.at(tabWidget->currentIndex())->getCurrentSearchListModel()->index(row, NAME)).toString()); + QStandardItemModel *model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListModel(); + QString url = model->data(model->index(index.row(), URL_COLUMN)).toString(); // Download from url BTSession->downloadFromUrl(url); // Set item color to RED @@ -375,21 +376,17 @@ void SearchEngine::appendSearchResult(QString line){ } QString url = parts.takeFirst().trimmed(); QString filename = parts.first().trimmed(); - // XXX: Two results can't have the same name (right?) - if(searchResultsUrls.contains(filename)){ - return; - } + parts << url; // Add item to search result list int row = currentSearchTab->getCurrentSearchListModel()->rowCount(); currentSearchTab->getCurrentSearchListModel()->insertRow(row); - for(int i=0; i<5; ++i){ + for(int i=0; i<6; ++i){ if(parts.at(i).trimmed().toFloat() == -1 && i != SIZE) currentSearchTab->getCurrentSearchListModel()->setData(currentSearchTab->getCurrentSearchListModel()->index(row, i), tr("Unknown")); else currentSearchTab->getCurrentSearchListModel()->setData(currentSearchTab->getCurrentSearchListModel()->index(row, i), QVariant(parts.at(i).trimmed())); } // Add url to searchResultsUrls associative array - searchResultsUrls.insert(filename, url); no_search_results = false; ++nb_search_results; // Enable clear & download buttons @@ -440,7 +437,8 @@ void SearchEngine::on_download_button_clicked(){ foreach(const QModelIndex &index, selectedIndexes){ if(index.column() == NAME){ // Get Item url - QString url = searchResultsUrls.value(index.data().toString()); + QStandardItemModel *model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListModel(); + QString url = model->data(model->index(index.row(), URL_COLUMN)).toString(); BTSession->downloadFromUrl(url); all_tab.at(tabWidget->currentIndex())->setRowColor(index.row(), "red"); } diff --git a/src/searchEngine.h b/src/searchEngine.h index d796f66b3..6bf54859f 100644 --- a/src/searchEngine.h +++ b/src/searchEngine.h @@ -41,7 +41,6 @@ class SearchEngine : public QWidget, public Ui::search_engine{ private: // Search related - QHash searchResultsUrls; QProcess *searchProcess; bool search_stopped; bool no_search_results;