Browse Source

- Fix possible crash in search field autocompletion

- Optimized autocompletion code
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
9fbe2ff6c4
  1. 28
      src/searchEngine.cpp
  2. 3
      src/searchEngine.h

28
src/searchEngine.cpp

@ -57,7 +57,6 @@ SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, b @@ -57,7 +57,6 @@ SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, b
setupUi(this);
// new qCompleter to the search pattern
startSearchHistory();
searchCompleter = 0;
createCompleter();
// Add close tab button
closeTab_button = new QPushButton();
@ -142,8 +141,7 @@ void SearchEngine::displayPatternContextMenu(QPoint) { @@ -142,8 +141,7 @@ void SearchEngine::displayPatternContextMenu(QPoint) {
QAction *act = myMenu.exec(QCursor::pos());
if(act != 0) {
if(act == &clearHistoryAct) {
searchHistory.clear();
createCompleter();
searchHistory.setStringList(QStringList());
} else if (act == &pasteAct) {
} else if (act == &pasteAct) {
search_pattern->paste();
@ -181,18 +179,13 @@ void SearchEngine::on_enginesButton_clicked() { @@ -181,18 +179,13 @@ void SearchEngine::on_enginesButton_clicked() {
// get the last searchs from a QSettings to a QStringList
void SearchEngine::startSearchHistory(){
QSettings settings("qBittorrent", "qBittorrent");
settings.beginGroup("Search");
searchHistory = settings.value("searchHistory",-1).toStringList();
settings.endGroup();
searchHistory.setStringList(settings.value("Search/searchHistory",QStringList()).toStringList());
}
// Save the history list into the QSettings for the next session
void SearchEngine::saveSearchHistory()
{
void SearchEngine::saveSearchHistory() {
QSettings settings("qBittorrent", "qBittorrent");
settings.beginGroup("Search");
settings.setValue("searchHistory",searchHistory);
settings.endGroup();
settings.setValue("Search/searchHistory",searchHistory.stringList());
}
// Function called when we click on search button
@ -220,13 +213,14 @@ void SearchEngine::on_search_button_clicked(){ @@ -220,13 +213,14 @@ void SearchEngine::on_search_button_clicked(){
tabWidget->setCurrentWidget(currentSearchTab);
closeTab_button->setEnabled(true);
// if the pattern is not in the pattern
if(searchHistory.indexOf(pattern) == -1){
QStringList wordList = searchHistory.stringList();
if(wordList.indexOf(pattern) == -1){
//update the searchHistory list
searchHistory.append(pattern);
wordList.append(pattern);
// verify the max size of the history
if(searchHistory.size() > SEARCHHISTORY_MAXSIZE)
searchHistory = searchHistory.mid(searchHistory.size()/2,searchHistory.size()/2);
createCompleter();
if(wordList.size() > SEARCHHISTORY_MAXSIZE)
wordList = wordList.mid(wordList.size()/2);
searchHistory.setStringList(wordList);
}
// Getting checked search engines
@ -252,7 +246,7 @@ void SearchEngine::on_search_button_clicked(){ @@ -252,7 +246,7 @@ void SearchEngine::on_search_button_clicked(){
void SearchEngine::createCompleter() {
if(searchCompleter)
delete searchCompleter;
searchCompleter = new QCompleter(searchHistory, this);
searchCompleter = new QCompleter(&searchHistory);
searchCompleter->setCaseSensitivity(Qt::CaseInsensitive);
search_pattern->setCompleter(searchCompleter);
}

3
src/searchEngine.h

@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
#include <QList>
#include <QPair>
#include <QPointer>
#include <QStringListModel>
#include "ui_search.h"
#include "engineSelectDlg.h"
#include "SearchTab.h"
@ -60,7 +61,7 @@ private: @@ -60,7 +61,7 @@ private:
QByteArray search_result_line_truncated;
unsigned long nb_search_results;
QPointer<QCompleter> searchCompleter;
QStringList searchHistory;
QStringListModel searchHistory;
bittorrent *BTSession;
QSystemTrayIcon *myTrayIcon;
bool systrayIntegration;

Loading…
Cancel
Save