--- a/dirbrowser/dirbrowser.cpp
+++ b/dirbrowser/dirbrowser.cpp
@@ -21,6 +21,7 @@
#include <QTimer>
#include <QShortcut>
#include <QLineEdit>
+#include <QCompleter>
#include "dirbrowser.h"
#include "application.h"
@@ -29,9 +30,10 @@
#include "GUI/prefs/sortprefs.h"
#include "HelperStructs/CSettingsStorage.h"
+static const QString cstr_searchhistorykey("/Upplay/dirbrowser/searchhistory");
+
DirBrowser::DirBrowser(QWidget *parent, std::shared_ptr<Playlist> pl)
- : QWidget(parent), ui(new Ui::DirBrowser), m_pl(pl), m_insertactive(false),
- m_randplayer(0)
+ : QWidget(parent), ui(new Ui::DirBrowser), m_pl(pl)
{
QKeySequence seq;
QShortcut *sc;
@@ -92,8 +94,16 @@
connect(ui->serverSearchCB, SIGNAL(stateChanged(int)),
this, SLOT(onSearchKindChanged(int)));
connect(ui->execSearchPB, SIGNAL(clicked()), this, SLOT(serverSearch()));
-
onSearchKindChanged(int(ui->serverSearchCB->checkState()));
+
+ ui->searchCMB->setInsertPolicy(QComboBox::NoInsert);
+ QSettings settings;
+ m_searchHistory =
+ settings.value(cstr_searchhistorykey).toStringList();
+ ui->searchCMB->addItems(m_searchHistory);
+ ui->searchCMB->setEditText("");
+ ui->searchCMB->completer()->setModel(0);
+
ui->execSearchPB->hide();
setPlaylist(pl);
}
@@ -218,6 +228,37 @@
}
}
+void DirBrowser::saveSearchHistory()
+{
+ // Search terms history:
+ // We want to have the new text at the top and any older identical
+ // entry to be erased. There is no standard qt policy to do this ?
+ // So do it by hand.
+ QString txt = ui->searchCMB->currentText();
+ QString txtt = txt.trimmed();
+ int index = ui->searchCMB->findText(txtt);
+ if (index > 0) {
+ ui->searchCMB->removeItem(index);
+ }
+ if (index != 0) {
+ ui->searchCMB->insertItem(0, txtt);
+ ui->searchCMB->setEditText(txt);
+ }
+
+ // Limit saved size to reasonable value
+ const int maxcount = 200;
+ int count = ui->searchCMB->count();
+ if (count > maxcount) {
+ count = maxcount;
+ }
+ m_searchHistory.clear();
+ for (int index = 0; index < count; index++) {
+ m_searchHistory.push_back(ui->searchCMB->itemText(index));
+ }
+ QSettings settings;
+ settings.setValue(cstr_searchhistorykey, m_searchHistory);
+}
+
// Any of the tabs searchcaps changed. Update the current one just in case.
void DirBrowser::onSearchcapsChanged()
{
@@ -312,6 +353,7 @@
ui->searchCMB->insertItem(0, text);
searchNext();
}
+ saveSearchHistory();
}
void DirBrowser::serverSearch()