From 0e09ce1dd3ebbfd41a278ae851985adfb6c3fc06 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 25 Jun 2008 19:04:42 +0000 Subject: [PATCH] =?UTF-8?q?-=20Initial=20commit=20for=20multi=20tab=20supp?= =?UTF-8?q?ort=20in=20search=20engine=20(code=20by=20Grigis=20Ga=C3=ABtan)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/search.ui | 87 +----------------- src/searchEngine.cpp | 214 +++++++++++++++++++++++++------------------ src/searchEngine.h | 47 +++++++--- 3 files changed, 166 insertions(+), 182 deletions(-) diff --git a/src/search.ui b/src/search.ui index 95be02a28..a4da18bf2 100644 --- a/src/search.ui +++ b/src/search.ui @@ -5,7 +5,7 @@ 0 0 - 811 + 820 453 @@ -195,6 +195,10 @@ + + + + @@ -212,87 +216,6 @@ 0 - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 16777215 - 20 - - - - - Sans Serif - 9 - 75 - false - true - false - false - - - - Results: - - - - - - - Qt::Horizontal - - - - 721 - 20 - - - - - - - - - - - 0 - 200 - - - - Qt::CustomContextMenu - - - true - - - QAbstractItemView::ExtendedSelection - - - 1 - - - false - - - diff --git a/src/searchEngine.cpp b/src/searchEngine.cpp index d77e86027..86c8f8152 100644 --- a/src/searchEngine.cpp +++ b/src/searchEngine.cpp @@ -43,82 +43,78 @@ #define SEARCHHISTORY_MAXSIZE 50 -SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration) : QWidget(), BTSession(BTSession), myTrayIcon(myTrayIcon), systrayIntegration(systrayIntegration){ - setupUi(this); - downloader = new downloadThread(this); - // Set Search results list model - SearchListModel = new QStandardItemModel(0,5); - 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); - SearchDelegate = new SearchListDelegate(); - resultsBrowser->setItemDelegate(SearchDelegate); - // Make search list header clickable for sorting - resultsBrowser->header()->setClickable(true); - resultsBrowser->header()->setSortIndicatorShown(true); - // Load last columns width for search results list - if(!loadColWidthSearchList()){ - resultsBrowser->header()->resizeSection(0, 275); - } +/*TAB SYSTEM TO MOVE IN ANOTHER FILE*/ +QList* TabbedSearch::all_tab = new QList(); +TabbedSearch::TabbedSearch(QString &title,QTabWidget *tab_barWidget,SearchEngine *searchEngi) : QWidget() +{ + box=new QVBoxLayout(); + results_lbl=new QLabel(); + resultsBrowser = new QTreeView(); + box->addWidget(results_lbl); + box->addWidget(resultsBrowser); + + setLayout(box); + // Set Search results list model + SearchListModel = new QStandardItemModel(0,5); + 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); + SearchDelegate = new SearchListDelegate(); + resultsBrowser->setItemDelegate(SearchDelegate); + // Make search list header clickable for sorting + resultsBrowser->header()->setClickable(true); + resultsBrowser->header()->setSortIndicatorShown(true); + + // Connect signals to slots (search part) + connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), searchEngi, SLOT(downloadSelectedItem(const QModelIndex&))); + connect(resultsBrowser->header(), SIGNAL(sectionPressed(int)), this, SLOT(sortSearchList(int))); + + // Load last columns width for search results list + if(!loadColWidthSearchList()){ + resultsBrowser->header()->resizeSection(0, 275); + } + tab_barWidget->addTab(this, title); + all_tab->append(this); +} - // new qCompleter to the search pattern - startSearchHistory(); - searchCompleter = new QCompleter(searchHistory, this); - searchCompleter->setCaseSensitivity(Qt::CaseInsensitive); - search_pattern->setCompleter(searchCompleter); +TabbedSearch::~TabbedSearch() +{ + saveColWidthSearchList(); + delete resultsBrowser; + delete SearchListModel; + delete SearchDelegate; +} - // Boolean initialization - search_stopped = false; - // Connect signals to slots (search part) - connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&))); - connect(resultsBrowser->header(), SIGNAL(sectionPressed(int)), this, SLOT(sortSearchList(int))); - // Creating Search Process - searchProcess = new QProcess(this); - connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted())); - connect(searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput())); - connect(searchProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(searchFinished(int,QProcess::ExitStatus))); - searchTimeout = new QTimer(this); - searchTimeout->setSingleShot(true); - connect(searchTimeout, SIGNAL(timeout()), this, SLOT(on_stop_search_button_clicked())); - // Check last enabled search engines - loadEngineSettings(); - // Update nova.py search plugin if necessary - updateNova(); +/*LES FONCTIONS POUR GET LA BETE*/ +QLabel* TabbedSearch::getCurrentLabel() +{ + return results_lbl; } -SearchEngine::~SearchEngine(){ - qDebug("Search destruction"); - // save the searchHistory for later uses - saveSearchHistory(); - saveColWidthSearchList(); - searchProcess->kill(); - searchProcess->waitForFinished(); - delete searchTimeout; - delete searchProcess; - delete searchCompleter; - delete SearchListModel; - delete SearchDelegate; - delete downloader; +QTreeView* TabbedSearch::getCurrentTreeView() +{ + return resultsBrowser; +} + +QStandardItemModel* TabbedSearch::getCurrentSearchListModel() +{ + return SearchListModel; } // Set the color of a row in data model -void SearchEngine::setRowColor(int row, QString color){ +void TabbedSearch::setRowColor(int row, QString color){ for(int i=0; icolumnCount(); ++i){ SearchListModel->setData(SearchListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); } } -void SearchEngine::sortSearchList(int index){ +void TabbedSearch::sortSearchList(int index){ static Qt::SortOrder sortOrder = Qt::AscendingOrder; if(resultsBrowser->header()->sortIndicatorSection() == index){ - if(sortOrder == Qt::AscendingOrder){ - sortOrder = Qt::DescendingOrder; - }else{ - sortOrder = Qt::AscendingOrder; - } + sortOrder = (sortOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder; ; } resultsBrowser->header()->setSortIndicator(index, sortOrder); switch(index){ @@ -133,7 +129,7 @@ void SearchEngine::sortSearchList(int index){ } } -void SearchEngine::sortSearchListInt(int index, Qt::SortOrder sortOrder){ +void TabbedSearch::sortSearchListInt(int index, Qt::SortOrder sortOrder){ QList > lines; // Insertion sorting for(int i=0; irowCount(); ++i){ @@ -153,7 +149,7 @@ void SearchEngine::sortSearchListInt(int index, Qt::SortOrder sortOrder){ SearchListModel->removeRows(0, nbRows_old); } -void SearchEngine::sortSearchListString(int index, Qt::SortOrder sortOrder){ +void TabbedSearch::sortSearchListString(int index, Qt::SortOrder sortOrder){ QList > lines; // Insetion sorting for(int i=0; irowCount(); ++i){ @@ -175,7 +171,7 @@ void SearchEngine::sortSearchListString(int index, Qt::SortOrder sortOrder){ // Save columns width in a file to remember them // (download list) -void SearchEngine::saveColWidthSearchList() const{ +void TabbedSearch::saveColWidthSearchList() const{ qDebug("Saving columns width in search list"); QSettings settings("qBittorrent", "qBittorrent"); QStringList width_list; @@ -186,14 +182,9 @@ void SearchEngine::saveColWidthSearchList() const{ qDebug("Search list columns width saved"); } -void SearchEngine::on_enginesButton_clicked() { - engineSelectDlg *dlg = new engineSelectDlg(this); - connect(dlg, SIGNAL(enginesChanged()), this, SLOT(loadEngineSettings())); -} - // Load columns width in a file that were saved previously // (search list) -bool SearchEngine::loadColWidthSearchList(){ +bool TabbedSearch::loadColWidthSearchList(){ qDebug("Loading columns width for search list"); QSettings settings("qBittorrent", "qBittorrent"); QString line = settings.value("SearchListColsWidth", QString()).toString(); @@ -208,6 +199,51 @@ bool SearchEngine::loadColWidthSearchList(){ qDebug("Search list columns width loaded"); return true; } +/*END TAB SYSTME*/ + +/*SEARCH ENGINE START*/ +SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration) : QWidget(), BTSession(BTSession), myTrayIcon(myTrayIcon), systrayIntegration(systrayIntegration){ + setupUi(this); + downloader = new downloadThread(this); + + // new qCompleter to the search pattern + startSearchHistory(); + searchCompleter = new QCompleter(searchHistory, this); + searchCompleter->setCaseSensitivity(Qt::CaseInsensitive); + search_pattern->setCompleter(searchCompleter); + + // Boolean initialization + search_stopped = false; + // Creating Search Process + searchProcess = new QProcess(this); + connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted())); + connect(searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput())); + connect(searchProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(searchFinished(int,QProcess::ExitStatus))); + searchTimeout = new QTimer(this); + searchTimeout->setSingleShot(true); + connect(searchTimeout, SIGNAL(timeout()), this, SLOT(on_stop_search_button_clicked())); + // Check last enabled search engines + loadEngineSettings(); + // Update nova.py search plugin if necessary + updateNova(); +} + +SearchEngine::~SearchEngine(){ + qDebug("Search destruction"); + // save the searchHistory for later uses + saveSearchHistory(); + searchProcess->kill(); + searchProcess->waitForFinished(); + delete searchTimeout; + delete searchProcess; + delete searchCompleter; + delete downloader; +} + +void SearchEngine::on_enginesButton_clicked() { + engineSelectDlg *dlg = new engineSelectDlg(this); + connect(dlg, SIGNAL(enginesChanged()), this, SLOT(loadEngineSettings())); +} // get the last searchs from a QSettings to a QStringList void SearchEngine::startSearchHistory(){ @@ -254,6 +290,8 @@ void SearchEngine::on_search_button_clicked(){ searchTimeout->stop(); } QString pattern = search_pattern->text().trimmed(); + //AJOUT TAB obligé de passé le widget en param sinon crash + tab_search=new TabbedSearch(pattern,tabWidget,this); // No search pattern entered if(pattern.isEmpty()){ QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first")); @@ -284,7 +322,8 @@ void SearchEngine::on_search_button_clicked(){ no_search_results = true; nb_search_results = 0; search_result_line_truncated.clear(); - results_lbl->setText(tr("Results")+" (0):"); + //on change le texte du label courrant + tab_search->getCurrentLabel()->setText(tr("Results")+" (0):"); // Launch search searchProcess->start("python", params, QIODevice::ReadOnly); searchTimeout->start(180000); // 3min @@ -296,21 +335,21 @@ void SearchEngine::searchStarted(){ search_status->repaint(); stop_search_button->setEnabled(true); stop_search_button->repaint(); - // clear results window - SearchListModel->removeRows(0, SearchListModel->rowCount()); + // clear results window ... not needed since we got Tabbed + //SearchListModel->removeRows(0, SearchListModel->rowCount()); // Clear previous results urls too - searchResultsUrls.clear(); + //searchResultsUrls.clear(); } // Download the given item from search results list void SearchEngine::downloadSelectedItem(const QModelIndex& index){ int row = index.row(); // Get Item url - QString url = searchResultsUrls.value(SearchListModel->data(SearchListModel->index(row, NAME)).toString()); + QString url = searchResultsUrls.value(TabbedSearch::all_tab->at(tabWidget->currentIndex())->getCurrentSearchListModel()->data(TabbedSearch::all_tab->at(tabWidget->currentIndex())->getCurrentSearchListModel()->index(row, NAME)).toString()); // Download from url BTSession->downloadFromUrl(url); // Set item color to RED - setRowColor(row, "red"); + tab_search->setRowColor(row, "red"); } // search Qprocess return output as soon as it gets new @@ -329,7 +368,7 @@ void SearchEngine::readSearchOutput(){ foreach(line, lines_list){ appendSearchResult(QString(line)); } - results_lbl->setText(tr("Results")+QString::fromUtf8(" (")+misc::toQString(nb_search_results)+QString::fromUtf8("):")); + tab_search->getCurrentLabel()->setText(tr("Results")+QString::fromUtf8(" (")+misc::toQString(nb_search_results)+QString::fromUtf8("):")); } // Update nova.py search plugin if necessary @@ -416,7 +455,7 @@ void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus){ } } } - results_lbl->setText(tr("Results", "i.e: Search results")+QString::fromUtf8(" (")+misc::toQString(nb_search_results)+QString::fromUtf8("):")); + tab_search->getCurrentLabel()->setText(tr("Results", "i.e: Search results")+QString::fromUtf8(" (")+misc::toQString(nb_search_results)+QString::fromUtf8("):")); search_button->setEnabled(true); stop_search_button->setEnabled(false); } @@ -436,13 +475,13 @@ void SearchEngine::appendSearchResult(QString line){ return; } // Add item to search result list - int row = SearchListModel->rowCount(); - SearchListModel->insertRow(row); + int row = tab_search->getCurrentSearchListModel()->rowCount(); + tab_search->getCurrentSearchListModel()->insertRow(row); for(int i=0; i<5; ++i){ if(parts.at(i).toFloat() == -1 && i != SIZE) - SearchListModel->setData(SearchListModel->index(row, i), tr("Unknown")); + tab_search->getCurrentSearchListModel()->setData(tab_search->getCurrentSearchListModel()->index(row, i), tr("Unknown")); else - SearchListModel->setData(SearchListModel->index(row, i), QVariant(parts.at(i))); + tab_search->getCurrentSearchListModel()->setData(tab_search->getCurrentSearchListModel()->index(row, i), QVariant(parts.at(i))); } // Add url to searchResultsUrls associative array searchResultsUrls.insert(filename, url); @@ -468,12 +507,12 @@ void SearchEngine::on_clear_button_clicked(){ search_stopped = true; searchTimeout->stop(); searchResultsUrls.clear(); - SearchListModel->removeRows(0, SearchListModel->rowCount()); + tab_search->getCurrentSearchListModel()->removeRows(0, tab_search->getCurrentSearchListModel()->rowCount()); // Disable clear & download buttons clear_button->setEnabled(false); download_button->setEnabled(false); nb_search_results = 0; - results_lbl->setText(tr("Results")+" (0):"); + tab_search->getCurrentLabel()->setText(tr("Results")+" (0):"); // focus on search pattern search_pattern->clear(); search_pattern->setFocus(); @@ -486,14 +525,15 @@ void SearchEngine::on_clearPatternButton_clicked() { // Download selected items in search results list void SearchEngine::on_download_button_clicked(){ - QModelIndexList selectedIndexes = resultsBrowser->selectionModel()->selectedIndexes(); + //QModelIndexList selectedIndexes = tab_search->getCurrentTreeView()->selectionModel()->selectedIndexes(); + QModelIndexList selectedIndexes = TabbedSearch::all_tab->at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); QModelIndex index; foreach(index, selectedIndexes){ if(index.column() == NAME){ // Get Item url QString url = searchResultsUrls.value(index.data().toString()); BTSession->downloadFromUrl(url); - setRowColor(index.row(), "red"); + tab_search->setRowColor(index.row(), "red"); } } } diff --git a/src/searchEngine.h b/src/searchEngine.h index 0da77d136..333a69d52 100644 --- a/src/searchEngine.h +++ b/src/searchEngine.h @@ -25,6 +25,8 @@ #define TIME_TRAY_BALLOON 5000 #include +#include +#include #include "ui_search.h" #include "engineSelectDlg.h" @@ -34,6 +36,33 @@ class bittorrent; class QSystemTrayIcon; class downloadThread; class QTimer; +class SearchEngine; +class TabbedSearch : public QWidget, public Ui::search_engine +{ + Q_OBJECT + + private: + QVBoxLayout *box; + QLabel *results_lbl; + QTreeView *resultsBrowser; + QStandardItemModel *SearchListModel; + SearchListDelegate *SearchDelegate; + public: + static QList *all_tab; // To store all tabs + TabbedSearch(QString &title,QTabWidget *tab_barWidget,SearchEngine *searchEngi); + ~TabbedSearch(); + bool loadColWidthSearchList(); + QLabel * getCurrentLabel(); + QStandardItemModel * getCurrentSearchListModel(); + QTreeView * getCurrentTreeView(); + void setRowColor(int row, QString color); + protected slots: + void sortSearchList(int index); + void sortSearchListInt(int index, Qt::SortOrder sortOrder); + void sortSearchListString(int index, Qt::SortOrder sortOrder); + void saveColWidthSearchList() const; + +}; class SearchEngine : public QWidget, public Ui::search_engine{ Q_OBJECT @@ -48,42 +77,34 @@ class SearchEngine : public QWidget, public Ui::search_engine{ unsigned long nb_search_results; QCompleter *searchCompleter; QStringList searchHistory; - QStandardItemModel *SearchListModel; - SearchListDelegate *SearchDelegate; bittorrent *BTSession; QSystemTrayIcon *myTrayIcon; bool systrayIntegration; downloadThread *downloader; QStringList enabled_engines; QTimer *searchTimeout; - + TabbedSearch *tab_search; public: SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration); ~SearchEngine(); float getPluginVersion(QString filePath) const; - bool loadColWidthSearchList(); - + public slots: + void on_download_button_clicked(); + void downloadSelectedItem(const QModelIndex& index); protected slots: // Search slots void on_search_button_clicked(); void on_stop_search_button_clicked(); void on_clear_button_clicked(); - void on_download_button_clicked(); void appendSearchResult(QString line); void searchFinished(int exitcode,QProcess::ExitStatus); void readSearchOutput(); - void setRowColor(int row, QString color); + void loadEngineSettings(); void searchStarted(); - void downloadSelectedItem(const QModelIndex& index); void startSearchHistory(); void updateNova(); void saveSearchHistory(); - void saveColWidthSearchList() const; - void sortSearchList(int index); - void sortSearchListInt(int index, Qt::SortOrder sortOrder); - void sortSearchListString(int index, Qt::SortOrder sortOrder); void on_enginesButton_clicked(); - void loadEngineSettings(); void on_clearPatternButton_clicked(); };