diff options
-rw-r--r-- | lumina-search/ConfigUI.cpp | 85 | ||||
-rw-r--r-- | lumina-search/ConfigUI.h | 37 | ||||
-rw-r--r-- | lumina-search/ConfigUI.ui | 125 | ||||
-rw-r--r-- | lumina-search/MainUI.cpp | 37 | ||||
-rw-r--r-- | lumina-search/MainUI.h | 3 | ||||
-rw-r--r-- | lumina-search/MainUI.ui | 10 | ||||
-rw-r--r-- | lumina-search/Worker.cpp | 5 | ||||
-rw-r--r-- | lumina-search/Worker.h | 3 | ||||
-rw-r--r-- | lumina-search/lumina-search.pro | 9 |
9 files changed, 303 insertions, 11 deletions
diff --git a/lumina-search/ConfigUI.cpp b/lumina-search/ConfigUI.cpp new file mode 100644 index 00000000..25c12246 --- /dev/null +++ b/lumina-search/ConfigUI.cpp @@ -0,0 +1,85 @@ +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "ConfigUI.h" +#include "ui_ConfigUI.h" + +#include <QFileDialog> +#include <QListWidget> +#include <QListWidgetItem> +#include <QListView> +#include <QTreeView> +#include <QPoint> + +#include <LuminaXDG.h> + +ConfigUI::ConfigUI(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigUI){ + ui->setupUi(this); + //Make sure this dialog is centered on the parent + if(parent!=0){ + QPoint ctr = parent->geometry().center(); + this->move( ctr.x()-(this->width()/2), ctr.y()-(this->height()/2) ); + } + ui->tool_getStartDir->setIcon( LXDG::findIcon("folder","") ); + ui->tool_adddirs->setIcon( LXDG::findIcon("list-add","") ); + ui->tool_rmdir->setIcon( LXDG::findIcon("list-remove","") ); +} + +ConfigUI::~ConfigUI(){ + +} + +void ConfigUI::loadInitialValues(QString startdir, QStringList skipdirs){ + ui->label_start->setText(startdir); + ui->list_excludes->clear(); + ui->list_excludes->addItems(skipdirs); +} + +void ConfigUI::on_tool_getStartDir_clicked(){ + QString dir = QFileDialog::getExistingDirectory(this, tr("Select Search Directory"), QDir::homePath() ); + if(dir.isEmpty()){ return; } + ui->label_start->setText(dir); +} + +void ConfigUI::on_tool_adddirs_clicked(){ + QFileDialog dlg(this); + dlg.setFileMode(QFileDialog::DirectoryOnly); + QListView *l = dlg.findChild<QListView*>("listView"); + if(l){ l->setSelectionMode(QAbstractItemView::MultiSelection); } + QTreeView *t = dlg.findChild<QTreeView*>(); + if(t){ t->setSelectionMode(QAbstractItemView::MultiSelection); } + dlg.setDirectory(QDir::homePath()); + dlg.setWindowTitle( tr("Exclude Directories") ); + if(dlg.exec()){ + //Directories selected + QStringList paths = dlg.selectedFiles(); + ui->list_excludes->addItems(paths); + } +} + +void ConfigUI::on_tool_rmdir_clicked(){ + QList<QListWidgetItem*> sel = ui->list_excludes->selectedItems(); + for(int i=0; i<sel.length(); i++){ + ui->list_excludes->removeItemWidget(sel[i]); + } +} + +void ConfigUI::on_list_excludes_itemSelectionChanged(){ + ui->tool_rmdir->setEnabled( !ui->list_excludes->selectedItems().isEmpty() ); +} + +void ConfigUI::on_buttonBox_accepted(){ + newStartDir = ui->label_start->text(); + QStringList dirs; + for(int i=0; i<ui->list_excludes->count(); i++){ + dirs << ui->list_excludes->item(i)->text(); + } + dirs.removeDuplicates(); + newSkipDirs = dirs; + this->close(); +} + +void ConfigUI::on_buttonBox_rejected(){ + this->close(); +} diff --git a/lumina-search/ConfigUI.h b/lumina-search/ConfigUI.h new file mode 100644 index 00000000..0ee385c5 --- /dev/null +++ b/lumina-search/ConfigUI.h @@ -0,0 +1,37 @@ +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_SEARCH_CONFIGURATION_DIALOG_H +#define _LUMINA_SEARCH_CONFIGURATION_DIALOG_H + +#include <QDialog> + +namespace Ui{ + class ConfigUI; +}; + +class ConfigUI : public QDialog{ + Q_OBJECT +public: + ConfigUI(QWidget *parent = 0); + ~ConfigUI(); + + void loadInitialValues(QString startdir, QStringList skipdirs); + + QString newStartDir; + QStringList newSkipDirs; + +private: + Ui::ConfigUI *ui; + +private slots: + void on_tool_getStartDir_clicked(); + void on_tool_adddirs_clicked(); + void on_tool_rmdir_clicked(); + void on_list_excludes_itemSelectionChanged(); + void on_buttonBox_accepted(); + void on_buttonBox_rejected(); +}; + +#endif diff --git a/lumina-search/ConfigUI.ui b/lumina-search/ConfigUI.ui new file mode 100644 index 00000000..95d3a4ad --- /dev/null +++ b/lumina-search/ConfigUI.ui @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ConfigUI</class> + <widget class="QDialog" name="ConfigUI"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>350</width> + <height>237</height> + </rect> + </property> + <property name="windowTitle"> + <string>Search Configuration</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Start Search:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_start"> + <property name="text"> + <string notr="true">...</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="tool_getStartDir"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Excluded Directories</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>2</number> + </property> + <property name="topMargin"> + <number>2</number> + </property> + <property name="rightMargin"> + <number>2</number> + </property> + <property name="bottomMargin"> + <number>2</number> + </property> + <item> + <widget class="QListWidget" name="list_excludes"> + <property name="selectionMode"> + <enum>QAbstractItemView::MultiSelection</enum> + </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QToolButton" name="tool_rmdir"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QToolButton" name="tool_adddirs"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item row="2" column="0" colspan="2"> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/lumina-search/MainUI.cpp b/lumina-search/MainUI.cpp index d7abcd65..2a17217d 100644 --- a/lumina-search/MainUI.cpp +++ b/lumina-search/MainUI.cpp @@ -7,14 +7,17 @@ #include "MainUI.h" #include "ui_MainUI.h" +#include "ConfigUI.h" + MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); //load the designer file setupIcons(); ui->radio_apps->setChecked(true); //always default to starting here ui->tool_stop->setVisible(false); //no search running initially + ui->tool_configure->setVisible(false); //app search initially set livetime = new QTimer(this); - livetime->setInterval(300); //1/2 second for live searches + livetime->setInterval(300); //1/3 second for live searches livetime->setSingleShot(true); workthread = new QThread(this); @@ -37,11 +40,14 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->radio_apps, SIGNAL(toggled(bool)), this, SLOT(searchTypeChanged()) ); connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(LaunchItem(QListWidgetItem*)) ); connect(ui->listWidget, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(LaunchItem(QListWidgetItem*)) ); + connect(ui->tool_configure, SIGNAL(clicked()), this, SLOT(configureSearch()) ); + + //Setup the settings file + QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina"); + settings = new QSettings("LuminaDE", "lumina-search",this); + searcher->startDir = settings->value("StartSearchDir", QDir::homePath()).toString(); + searcher->skipDirs = settings->value("SkipSearchDirs", QStringList()).toStringList(); - //Setup the settings file (not used at the moment) - //QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina"); - //settings = new QSettings("LuminaDE", "lumina-search",this); - this->show(); workthread->start(); } @@ -57,6 +63,7 @@ void MainUI::setupIcons(){ ui->push_launch->setIcon( LXDG::findIcon("quickopen","") ); ui->push_done->setIcon( LXDG::findIcon("window-close","") ); ui->tool_stop->setIcon( LXDG::findIcon("dialog-cancel","") ); + ui->tool_configure->setIcon( LXDG::findIcon("configure","") ); } //============== @@ -80,6 +87,23 @@ void MainUI::searchTypeChanged(){ startSearch(); } +void MainUI::configureSearch(){ + ConfigUI dlg(this); + dlg.loadInitialValues( searcher->startDir, searcher->skipDirs); + dlg.exec(); + if(dlg.newStartDir.isEmpty()){ return; }//cancelled + QString startdir = dlg.newStartDir; + QStringList skipdirs = dlg.newSkipDirs; + + //Save these values for later + settings->setValue("StartSearchDir", startdir); + settings->setValue("SkipSearchDirs", skipdirs); + + //Set these values in the searcher + searcher->startDir = startdir; + searcher->skipDirs = skipdirs; +} + void MainUI::searchChanged(){ if(livetime->isActive()){ livetime->stop(); } livetime->start(); @@ -95,6 +119,7 @@ void MainUI::startSearch(){ if(!workthread->isRunning()){ workthread->start(); } //make sure the thread is running emit SearchTerm(ui->line_search->text(), ui->radio_apps->isChecked()); ui->tool_stop->setVisible(true); + ui->tool_configure->setVisible(false); } void MainUI::foundSearchItem(QString path){ @@ -126,6 +151,7 @@ void MainUI::foundSearchItem(QString path){ void MainUI::stopSearch(){ searcher->StopSearch(); ui->tool_stop->setVisible(false); + ui->tool_configure->setVisible(ui->radio_files->isChecked()); } void MainUI::searchMessage(QString msg){ @@ -134,4 +160,5 @@ void MainUI::searchMessage(QString msg){ void MainUI::searchFinished(){ ui->tool_stop->setVisible(false); + ui->tool_configure->setVisible(ui->radio_files->isChecked()); } diff --git a/lumina-search/MainUI.h b/lumina-search/MainUI.h index 77a5de0f..cd4a1db7 100644 --- a/lumina-search/MainUI.h +++ b/lumina-search/MainUI.h @@ -37,7 +37,7 @@ private: QThread *workthread; QTimer *livetime; Worker *searcher; - //QSettings *settings; //not needed at the moment + QSettings *settings; private slots: //Button Slots @@ -47,6 +47,7 @@ private slots: void LaunchItem(); void LaunchItem(QListWidgetItem*); void searchTypeChanged(); + void configureSearch(); void searchChanged(); //for active searching while typing diff --git a/lumina-search/MainUI.ui b/lumina-search/MainUI.ui index 73c7bf18..7a3c664e 100644 --- a/lumina-search/MainUI.ui +++ b/lumina-search/MainUI.ui @@ -25,6 +25,16 @@ </widget> </item> <item> + <widget class="QToolButton" name="tool_configure"> + <property name="toolTip"> + <string>Configure search parameters</string> + </property> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item> <widget class="QToolButton" name="tool_stop"> <property name="toolTip"> <string>Stop Active Search</string> diff --git a/lumina-search/Worker.cpp b/lumina-search/Worker.cpp index 6dc750cb..5d874202 100644 --- a/lumina-search/Worker.cpp +++ b/lumina-search/Worker.cpp @@ -49,6 +49,7 @@ bool Worker::searchDir(QString dirpath){ tmp = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot , QDir::Name); for(int i=0; i<tmp.length(); i++){ if(stopsearch){ return true; } + if( skipDirs.contains(dir.absoluteFilePath(tmp[i])) ){ continue; } //this dir is skipped if( searchDir(dir.absoluteFilePath(tmp[i])) ){ return true; } } return false; @@ -89,12 +90,12 @@ void Worker::beginsearch(){ } } }else{ - emit SearchUpdate( "File Search not implemented yet" ); //Search through the user's home directory and look for a file/dir starting with that term if(!sterm.contains("*")){ sterm.prepend("*"); sterm.append("*"); //make sure it is a search glob pattern } - searchDir(QDir::homePath()); + if(startDir.isEmpty()){ startDir = QDir::homePath(); } + searchDir(startDir); } emit SearchUpdate( tr("Search Finished") ); diff --git a/lumina-search/Worker.h b/lumina-search/Worker.h index c7dd3707..87cf1e3b 100644 --- a/lumina-search/Worker.h +++ b/lumina-search/Worker.h @@ -18,6 +18,9 @@ public: Worker(QObject *parent = 0); ~Worker(); + QString startDir; + QStringList skipDirs; + public slots: void StartSearch(QString term, bool isApp); void StopSearch(); diff --git a/lumina-search/lumina-search.pro b/lumina-search/lumina-search.pro index f81b4b4f..e738b5db 100644 --- a/lumina-search/lumina-search.pro +++ b/lumina-search/lumina-search.pro @@ -16,12 +16,15 @@ TEMPLATE = app SOURCES += main.cpp \ MainUI.cpp \ - Worker.cpp + Worker.cpp \ + ConfigUI.cpp HEADERS += MainUI.h \ - Worker.h + Worker.h \ + ConfigUI.h -FORMS += MainUI.ui +FORMS += MainUI.ui \ + ConfigUI.ui INCLUDEPATH += ../libLumina $$PREFIX/include |