From: Enar Väikene Date: Mon, 28 Nov 2011 11:36:28 +0000 (+0200) Subject: * Added auto-completor to the directory field X-Git-Url: https://vaikene.ee/gitweb/pswgen07.html?a=commitdiff_plain;h=7eca3433b1db8f2bcc61fa8db60bc7546f5cb578;p=evaf * Added auto-completor to the directory field * Limited the number of history items that are stored * Search fields are disabled while the search is ongoing. --- diff --git a/src/apps/FileFinder/GUI/gui.cpp b/src/apps/FileFinder/GUI/gui.cpp index a849da9..29dcd71 100644 --- a/src/apps/FileFinder/GUI/gui.cpp +++ b/src/apps/FileFinder/GUI/gui.cpp @@ -75,6 +75,8 @@ void FileFinder::GUI::Internal::MainWidget::keyPressEvent(QKeyEvent * e) //------------------------------------------------------------------- +int const FileFinder::GUI::Module::MaxHistoryItems = 20; + FileFinder::GUI::Module::Module() : Plugins::iPlugin() , mReady(false) @@ -138,6 +140,8 @@ void FileFinder::GUI::Module::done() { mReady = false; + mFinder = 0; + /* * Widgets are deleted by the SdiWindow module. We use wMain to track calls to done() without * proper init(). @@ -155,27 +159,27 @@ void FileFinder::GUI::Module::saveHistory() QSettings settings(VER_COMPANY_NAME_STR, Common::iApp::instance()->name()); QStringList t; - for (int i = 0; i < wDirectory->count(); ++i) + for (int i = 0; i < wDirectory->count() && i < MaxHistoryItems; ++i) t.append(wDirectory->itemText(i)); settings.setValue("FileFinder/Directories", t); t.clear(); - for (int i = 0; i < wIncludeNames->count(); ++i) + for (int i = 0; i < wIncludeNames->count() && i < MaxHistoryItems; ++i) t.append(wIncludeNames->itemText(i)); settings.setValue("FileFinder/IncludeNames", t); t.clear(); - for (int i = 0; i < wExcludeNames->count(); ++i) + for (int i = 0; i < wExcludeNames->count() && i < MaxHistoryItems; ++i) t.append(wExcludeNames->itemText(i)); settings.setValue("FileFinder/ExcludeNames", t); t.clear(); - for (int i = 0; i < wIncludeContent->count(); ++i) + for (int i = 0; i < wIncludeContent->count() && i < MaxHistoryItems; ++i) t.append(wIncludeContent->itemText(i)); settings.setValue("FileFinder/IncludeContent", t); t.clear(); - for (int i = 0; i < wExcludeContent->count(); ++i) + for (int i = 0; i < wExcludeContent->count() && i < MaxHistoryItems; ++i) t.append(wExcludeContent->itemText(i)); settings.setValue("FileFinder/ExcludeContent", t); @@ -187,6 +191,7 @@ void FileFinder::GUI::Module::loadHistory() wDirectory->addItems(settings.value("FileFinder/Directories").toStringList()); wDirectory->setEditText(QDir::currentPath()); + mDirModel->setRootPath(QDir::currentPath()); wIncludeNames->addItems(settings.value("FileFinder/IncludeNames").toStringList()); wIncludeNames->setEditText(""); @@ -216,12 +221,17 @@ void FileFinder::GUI::Module::createWidgets() wDirectory->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); wDirectory->setEditable(true); wDirectory->setInsertPolicy(QComboBox::InsertAtTop); + QCompleter * completer = new QCompleter(wMain); + mDirModel = new QFileSystemModel(wMain); + mDirModel->setFilter(QDir::AllDirs | QDir::Dirs | QDir::NoDotAndDotDot); + completer->setModel(mDirModel); + wDirectory->setCompleter(completer); l->setBuddy(wDirectory); hbox->addWidget(wDirectory); - QPushButton * btn = new QPushButton(tr("&Browse")); - connect(btn, SIGNAL(clicked()), this, SLOT(browseDirectory())); - hbox->addWidget(btn); + wBrowse = new QPushButton(tr("&Browse")); + connect(wBrowse, SIGNAL(clicked()), this, SLOT(browseDirectory())); + hbox->addWidget(wBrowse); wRecursive = new QCheckBox(tr("&Recursive")); wRecursive->setChecked(true); @@ -286,7 +296,7 @@ void FileFinder::GUI::Module::createWidgets() connect(wFind, SIGNAL(clicked()), this, SLOT(find())); hbox->addWidget(wFind); - btn = new QPushButton(tr("&Close")); + QPushButton * btn = new QPushButton(tr("&Close")); connect(btn, SIGNAL(clicked()), qApp, SLOT(quit())); hbox->addWidget(btn); } @@ -323,7 +333,27 @@ void FileFinder::GUI::Module::find() } else { wResults->clear(); - + + if (wDirectory->findText(wDirectory->currentText()) == -1) + wDirectory->insertItem(0, wDirectory->currentText()); + if (wIncludeNames->findText(wIncludeNames->currentText()) == -1) + wIncludeNames->insertItem(0, wIncludeNames->currentText()); + if (wExcludeNames->findText(wExcludeNames->currentText()) == -1) + wExcludeNames->insertItem(0, wExcludeNames->currentText()); + if (wIncludeContent->findText(wIncludeContent->currentText()) == -1) + wIncludeContent->insertItem(0, wIncludeContent->currentText()); + if (wExcludeContent->findText(wExcludeContent->currentText()) == -1) + wExcludeContent->insertItem(0, wExcludeContent->currentText()); + + // Disable input fields + wDirectory->setEnabled(false); + wBrowse->setEnabled(false); + wRecursive->setEnabled(false); + wIncludeNames->setEnabled(false); + wExcludeNames->setEnabled(false); + wIncludeContent->setEnabled(false); + wExcludeContent->setEnabled(false); + mFinder->search(wDirectory->currentText(), wRecursive->isChecked(), FileFinder::Filter( @@ -351,6 +381,15 @@ void FileFinder::GUI::Module::finished(bool canceled) { Q_UNUSED(canceled) + // Enable input fields + wDirectory->setEnabled(true); + wBrowse->setEnabled(true); + wRecursive->setEnabled(true); + wIncludeNames->setEnabled(true); + wExcludeNames->setEnabled(true); + wIncludeContent->setEnabled(true); + wExcludeContent->setEnabled(true); + wFind->setText(tr("&Search")); } diff --git a/src/apps/FileFinder/GUI/gui.h b/src/apps/FileFinder/GUI/gui.h index 809dab1..e4c0c8e 100644 --- a/src/apps/FileFinder/GUI/gui.h +++ b/src/apps/FileFinder/GUI/gui.h @@ -33,6 +33,7 @@ class QComboBox; class QPushButton; class QListWidget; class QAction; +class QFileSystemModel; namespace eVaf { namespace SdiWindow { @@ -113,6 +114,9 @@ private slots: private: // Members + /// Max number of items in each field that we save + static int const MaxHistoryItems; + /// Flag indicating that the module is ready bool mReady; @@ -126,6 +130,7 @@ private: // Members /// Widgets on the screen Internal::MainWidget * wMain; QComboBox * wDirectory; + QPushButton * wBrowse; QCheckBox * wRecursive; QComboBox * wIncludeNames; QComboBox * wExcludeNames; @@ -134,6 +139,9 @@ private: // Members QListWidget * wResults; QPushButton * wFind; + /// File system auto-completion model for the directory field + QFileSystemModel * mDirModel; + private: // Methods diff --git a/src/apps/FileFinder/GUI/version.h b/src/apps/FileFinder/GUI/version.h index 745d9c7..dd5c198 100644 --- a/src/apps/FileFinder/GUI/version.h +++ b/src/apps/FileFinder/GUI/version.h @@ -25,12 +25,12 @@ /** * Module/library version number in the form major,minor,release,build */ -#define VER_FILE_VERSION 0,1,1,1 +#define VER_FILE_VERSION 0,1,2,2 /** * Module/library version number in the string format (shall end with \0) */ -#define VER_FILE_VERSION_STR "0.1.1.1\0" +#define VER_FILE_VERSION_STR "0.1.2.2\0" /** * Module/library name (shall end with \0)