mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- Fix possible crash in search field autocompletion
- Optimized autocompletion code
This commit is contained in:
parent
a4383d1b7f
commit
9fbe2ff6c4
@ -57,7 +57,6 @@ SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, b
|
|||||||
setupUi(this);
|
setupUi(this);
|
||||||
// new qCompleter to the search pattern
|
// new qCompleter to the search pattern
|
||||||
startSearchHistory();
|
startSearchHistory();
|
||||||
searchCompleter = 0;
|
|
||||||
createCompleter();
|
createCompleter();
|
||||||
// Add close tab button
|
// Add close tab button
|
||||||
closeTab_button = new QPushButton();
|
closeTab_button = new QPushButton();
|
||||||
@ -142,8 +141,7 @@ void SearchEngine::displayPatternContextMenu(QPoint) {
|
|||||||
QAction *act = myMenu.exec(QCursor::pos());
|
QAction *act = myMenu.exec(QCursor::pos());
|
||||||
if(act != 0) {
|
if(act != 0) {
|
||||||
if(act == &clearHistoryAct) {
|
if(act == &clearHistoryAct) {
|
||||||
searchHistory.clear();
|
searchHistory.setStringList(QStringList());
|
||||||
createCompleter();
|
|
||||||
} else if (act == &pasteAct) {
|
} else if (act == &pasteAct) {
|
||||||
} else if (act == &pasteAct) {
|
} else if (act == &pasteAct) {
|
||||||
search_pattern->paste();
|
search_pattern->paste();
|
||||||
@ -181,18 +179,13 @@ void SearchEngine::on_enginesButton_clicked() {
|
|||||||
// get the last searchs from a QSettings to a QStringList
|
// get the last searchs from a QSettings to a QStringList
|
||||||
void SearchEngine::startSearchHistory(){
|
void SearchEngine::startSearchHistory(){
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
settings.beginGroup("Search");
|
searchHistory.setStringList(settings.value("Search/searchHistory",QStringList()).toStringList());
|
||||||
searchHistory = settings.value("searchHistory",-1).toStringList();
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the history list into the QSettings for the next session
|
// Save the history list into the QSettings for the next session
|
||||||
void SearchEngine::saveSearchHistory()
|
void SearchEngine::saveSearchHistory() {
|
||||||
{
|
|
||||||
QSettings settings("qBittorrent", "qBittorrent");
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
settings.beginGroup("Search");
|
settings.setValue("Search/searchHistory",searchHistory.stringList());
|
||||||
settings.setValue("searchHistory",searchHistory);
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function called when we click on search button
|
// Function called when we click on search button
|
||||||
@ -220,13 +213,14 @@ void SearchEngine::on_search_button_clicked(){
|
|||||||
tabWidget->setCurrentWidget(currentSearchTab);
|
tabWidget->setCurrentWidget(currentSearchTab);
|
||||||
closeTab_button->setEnabled(true);
|
closeTab_button->setEnabled(true);
|
||||||
// if the pattern is not in the pattern
|
// 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
|
//update the searchHistory list
|
||||||
searchHistory.append(pattern);
|
wordList.append(pattern);
|
||||||
// verify the max size of the history
|
// verify the max size of the history
|
||||||
if(searchHistory.size() > SEARCHHISTORY_MAXSIZE)
|
if(wordList.size() > SEARCHHISTORY_MAXSIZE)
|
||||||
searchHistory = searchHistory.mid(searchHistory.size()/2,searchHistory.size()/2);
|
wordList = wordList.mid(wordList.size()/2);
|
||||||
createCompleter();
|
searchHistory.setStringList(wordList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting checked search engines
|
// Getting checked search engines
|
||||||
@ -252,7 +246,7 @@ void SearchEngine::on_search_button_clicked(){
|
|||||||
void SearchEngine::createCompleter() {
|
void SearchEngine::createCompleter() {
|
||||||
if(searchCompleter)
|
if(searchCompleter)
|
||||||
delete searchCompleter;
|
delete searchCompleter;
|
||||||
searchCompleter = new QCompleter(searchHistory, this);
|
searchCompleter = new QCompleter(&searchHistory);
|
||||||
searchCompleter->setCaseSensitivity(Qt::CaseInsensitive);
|
searchCompleter->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
search_pattern->setCompleter(searchCompleter);
|
search_pattern->setCompleter(searchCompleter);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include <QStringListModel>
|
||||||
#include "ui_search.h"
|
#include "ui_search.h"
|
||||||
#include "engineSelectDlg.h"
|
#include "engineSelectDlg.h"
|
||||||
#include "SearchTab.h"
|
#include "SearchTab.h"
|
||||||
@ -60,7 +61,7 @@ private:
|
|||||||
QByteArray search_result_line_truncated;
|
QByteArray search_result_line_truncated;
|
||||||
unsigned long nb_search_results;
|
unsigned long nb_search_results;
|
||||||
QPointer<QCompleter> searchCompleter;
|
QPointer<QCompleter> searchCompleter;
|
||||||
QStringList searchHistory;
|
QStringListModel searchHistory;
|
||||||
bittorrent *BTSession;
|
bittorrent *BTSession;
|
||||||
QSystemTrayIcon *myTrayIcon;
|
QSystemTrayIcon *myTrayIcon;
|
||||||
bool systrayIntegration;
|
bool systrayIntegration;
|
||||||
|
Loading…
Reference in New Issue
Block a user