From 8df90e2567c1678e2fe8292a236c41b3285a9643 Mon Sep 17 00:00:00 2001 From: Arnaud Demaiziere Date: Sun, 4 Mar 2007 17:13:29 +0000 Subject: [PATCH] added autocompletion to search engine --- Changelog | 1 + TODO | 3 +-- src/GUI.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- src/GUI.h | 5 +++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index 095ae0705..2b7723b99 100644 --- a/Changelog +++ b/Changelog @@ -10,6 +10,7 @@ - FEATURE: User is warned when hard drive becomes full and downloads are paused - FEATURE: Number of complete/incomplete sources are now displayed in download list for each torrent - FEATURE: Implemented close to systray + - FEATURE: Added Autocompletion to search engine - BUGFIX: Two torrents can now have the same name although they are different - BUGFIX: Fixed download from url that would fail sometimes - BUGFIX: Save directory was reset to default when filtering files in torrent diff --git a/TODO b/TODO index 9a6a0b034..4817879ca 100644 --- a/TODO +++ b/TODO @@ -30,7 +30,6 @@ - Split kernel from GUI? (would be a lot better but require some deep changes) - Web interface? - Use downloader class to download search plugin updates -- Add autocompletion in search engine - Allow to set upload limit for each torrent - Add a torrent scheduler @@ -42,4 +41,4 @@ - UPnP support // In v0.9.0 -- Wait for libtorrent v0.12 official release \ No newline at end of file +- Wait for libtorrent v0.12 official release diff --git a/src/GUI.cpp b/src/GUI.cpp index 9ca206276..e43273456 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,8 @@ #include "downloadFromURLImp.h" #include "torrentAddition.h" +#define SEARCHHISTORY_MAXSIZE 50 + /***************************************************** * * * GUI * @@ -64,8 +67,8 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ setupUi(this); setWindowTitle(tr("qBittorrent ")+VERSION); readSettings(); - s = new session(fingerprint("qB", VERSION_MAJOR, VERSION_MINOR, VERSION_BUGFIX, 0)); + s = new session(fingerprint("qB", VERSION_MAJOR, VERSION_MINOR, VERSION_BUGFIX, 0)); // Setting icons this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/qbittorrent32.png"))); actionOpen->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/open.png"))); @@ -215,6 +218,14 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ if(!loadColWidthSearchList()){ resultsBrowser->header()->resizeSection(0, 275); } + + // new qCompleter to the search pattern + startSearchHistory(); + QCompleter *searchCompleter = new QCompleter(searchHistory, this); + searchCompleter->setCaseSensitivity(Qt::CaseInsensitive); + search_pattern->setCompleter(searchCompleter); + + // Boolean initialization search_stopped = false; // Connect signals to slots (search part) @@ -256,6 +267,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ // Destructor GUI::~GUI(){ + qDebug("GUI destruction"); delete options; delete checkConnect; delete timerScan; @@ -876,6 +888,8 @@ void GUI::closeEvent(QCloseEvent *e){ return; } } + // save the searchHistory for later uses + saveSearchHistory(); // Save DHT entry if(DHTEnabled){ try{ @@ -1923,6 +1937,23 @@ void GUI::checkConnectionStatus(){ * * *****************************************************/ +// get the last searchs from a QSettings to a QStringList +void GUI::startSearchHistory(){ + QSettings settings("qBittorrent", "qBittorrent"); + settings.beginGroup("Search"); + searchHistory = settings.value("searchHistory",-1).toStringList(); + settings.endGroup(); +} + +// Save the history list into the QSettings for the next session +void GUI::saveSearchHistory() +{ + QSettings settings("qBittorrent", "qBittorrent"); + settings.beginGroup("Search"); + settings.setValue("searchHistory",searchHistory); + settings.endGroup(); +} + // Function called when we click on search button void GUI::on_search_button_clicked(){ QString pattern = search_pattern->text().trimmed(); @@ -1931,6 +1962,19 @@ void GUI::on_search_button_clicked(){ QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first")); return; } + // if the pattern is not in the pattern + if(searchHistory.indexOf(pattern) == -1){ + //update the searchHistory list + searchHistory.append(pattern); + // verify the max size of the history + if(searchHistory.size() > SEARCHHISTORY_MAXSIZE) + searchHistory = searchHistory.mid(searchHistory.size()/2,searchHistory.size()/2); + searchCompleter = new QCompleter(searchHistory, this); + searchCompleter->setCaseSensitivity(Qt::CaseInsensitive); + search_pattern->setCompleter(searchCompleter); + } + + // Getting checked search engines if(!mininova->isChecked() && ! piratebay->isChecked()/* && !reactor->isChecked()*/ && !isohunt->isChecked()/* && !btjunkie->isChecked()*/ && !meganova->isChecked()){ QMessageBox::critical(0, tr("No seach engine selected"), tr("You must select at least one search engine.")); diff --git a/src/GUI.h b/src/GUI.h index 37c854eaa..d537824e9 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -50,6 +50,7 @@ class createtorrent; class QTimer; +class QCompleter; class DLListDelegate; class SearchListDelegate; class downloadThread; @@ -101,6 +102,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{ unsigned long nb_search_results; QTcpServer tcpServer; QTcpSocket *clientConnection; + QCompleter *searchCompleter; + QStringList searchHistory; protected slots: // GUI related slots @@ -174,6 +177,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void readSearchOutput(); void searchStarted(); void downloadSelectedItem(const QModelIndex& index); + void startSearchHistory(); + void saveSearchHistory(); // Utils slots void setRowColor(int row, const QString& color, bool inDLList=true); // Options slots