diff --git a/Changelog b/Changelog index e3037aafd..94d9da523 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,7 @@ - FEATURE: Display total amount of uploaded data in finished list - FEATURE: Resizing a column in a search results tab affects all tabs - FEATURE: Search results tab columns are now remembered upon startup + - FEATURE: Added right click menu in search engine to clear completion history - BUGFIX: Provide more helpful explanation when an I/O error occured - COSMETIC: Redesigned program preferences - COSMETIC: Updated icons set diff --git a/src/search.ui b/src/search.ui index 5d5a2df90..f5036472f 100644 --- a/src/search.ui +++ b/src/search.ui @@ -1,7 +1,8 @@ - + + search_engine - - + + 0 0 @@ -9,27 +10,27 @@ 453 - + Search - + - - + + 6 - + 0 - - + + 16777215 35 - + Sans Serif 9 @@ -40,37 +41,40 @@ false - + Search Pattern: - - + + 16777215 22 + + Qt::CustomContextMenu + - - + + 34 29 - + - - - :/Icons/oxygen/edit_clear.png:/Icons/oxygen/edit_clear.png + + + :/Icons/oxygen/edit_clear.png:/Icons/oxygen/edit_clear.png - + 30 21 @@ -79,37 +83,37 @@ - - + + 16777215 29 - + Search - - + + false - + 16777215 29 - + Stop - - + + Search engines... @@ -117,16 +121,16 @@ - + - - + + 16777215 35 - + Sans Serif 9 @@ -137,26 +141,26 @@ false - + Status: - - + + 400 0 - + 16777215 35 - + Sans Serif 9 @@ -167,17 +171,17 @@ false - + Stopped - + Qt::Horizontal - + 188 21 @@ -188,40 +192,40 @@ - + - - + + 6 - + 0 - - + + 6 - + 0 - - + + false - + Download - + Qt::Horizontal - + 601 20 @@ -236,7 +240,7 @@ - + @@ -245,11 +249,11 @@ search_button click() - + 421 37 - + 685 45 diff --git a/src/searchEngine.cpp b/src/searchEngine.cpp index b7817b49e..0d11baa17 100644 --- a/src/searchEngine.cpp +++ b/src/searchEngine.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "searchEngine.h" #include "bittorrent.h" @@ -53,9 +54,8 @@ SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, b setupUi(this); // new qCompleter to the search pattern startSearchHistory(); - searchCompleter = new QCompleter(searchHistory, this); - searchCompleter->setCaseSensitivity(Qt::CaseInsensitive); - search_pattern->setCompleter(searchCompleter); + searchCompleter = 0; + createCompleter(); // Add close tab button closeTab_button = new QPushButton(); closeTab_button->setIcon(QIcon(QString::fromUtf8(":/Icons/gnome-shutdown.png"))); @@ -79,6 +79,7 @@ SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, b loadEngineSettings(); // Update nova.py search plugin if necessary updateNova(); + connect(search_pattern, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(displayPatternContextMenu(QPoint))); } SearchEngine::~SearchEngine(){ @@ -94,7 +95,21 @@ SearchEngine::~SearchEngine(){ } delete searchTimeout; delete searchProcess; - delete searchCompleter; + if(searchCompleter) + delete searchCompleter; +} + +void SearchEngine::displayPatternContextMenu(QPoint) { + QMenu myMenu(this); + QAction clearHistoryAct(tr("Clear history"), &myMenu); + myMenu.addAction(&clearHistoryAct); + QAction *act = myMenu.exec(QCursor::pos()); + if(act != 0) { + if(act == &clearHistoryAct) { + searchHistory.clear(); + createCompleter(); + } + } } void SearchEngine::tab_changed(int t) @@ -178,12 +193,9 @@ void SearchEngine::on_search_button_clicked(){ // 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); + createCompleter(); } - // Getting checked search engines Q_ASSERT(!enabled_engines.empty()); QStringList params; @@ -203,6 +215,14 @@ void SearchEngine::on_search_button_clicked(){ searchTimeout->start(180000); // 3min } +void SearchEngine::createCompleter() { + if(searchCompleter) + delete searchCompleter; + searchCompleter = new QCompleter(searchHistory, this); + searchCompleter->setCaseSensitivity(Qt::CaseInsensitive); + search_pattern->setCompleter(searchCompleter); +} + void SearchEngine::propagateSectionResized(int index, int , int newsize) { foreach(SearchTab * tab, all_tab) { tab->getCurrentTreeView()->setColumnWidth(index, newsize); diff --git a/src/searchEngine.h b/src/searchEngine.h index 065a459d6..fea63f75a 100644 --- a/src/searchEngine.h +++ b/src/searchEngine.h @@ -36,6 +36,7 @@ #include #include #include +#include #include "ui_search.h" #include "engineSelectDlg.h" #include "SearchTab.h" @@ -57,7 +58,7 @@ class SearchEngine : public QWidget, public Ui::search_engine{ bool no_search_results; QByteArray search_result_line_truncated; unsigned long nb_search_results; - QCompleter *searchCompleter; + QPointer searchCompleter; QStringList searchHistory; bittorrent *BTSession; QSystemTrayIcon *myTrayIcon; @@ -94,6 +95,8 @@ class SearchEngine : public QWidget, public Ui::search_engine{ void saveResultsColumnsWidth(); void downloadFinished(int exitcode, QProcess::ExitStatus); void downloadTorrent(QString engine_url, QString torrent_url); + void displayPatternContextMenu(QPoint); + void createCompleter(); }; #endif