From cb7ac8c92b68b2229e8d1759bbce3d0e2b597c17 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 5 Nov 2014 13:16:58 -0500 Subject: Add a new utility: lumina-search This utility provides quick searching for applications (the default), or for searching the entire user's home directory. The file search also supports the "*" wildcard for the search terms. --- lumina-search/MainUI.cpp | 131 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 lumina-search/MainUI.cpp (limited to 'lumina-search/MainUI.cpp') diff --git a/lumina-search/MainUI.cpp b/lumina-search/MainUI.cpp new file mode 100644 index 00000000..df247324 --- /dev/null +++ b/lumina-search/MainUI.cpp @@ -0,0 +1,131 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "MainUI.h" +#include "ui_MainUI.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 + + livetime = new QTimer(this); + livetime->setInterval(300); //1/2 second for live searches + livetime->setSingleShot(true); + + workthread = new QThread(this); + workthread->setObjectName("Lumina Search Process"); + + searcher = new Worker(); + searcher->moveToThread(workthread); + + //Setup the connections + connect(livetime, SIGNAL(timeout()), this, SLOT(startSearch()) ); + connect(this, SIGNAL(SearchTerm(QString, bool)), searcher, SLOT(StartSearch(QString, bool)) ); + connect(searcher, SIGNAL(FoundItem(QString)), this, SLOT(foundSearchItem(QString)) ); + connect(searcher, SIGNAL(SearchUpdate(QString)), this, SLOT(searchMessage(QString)) ); + connect(searcher, SIGNAL(SearchDone()), this, SLOT(searchFinished()) ); + connect(ui->tool_stop, SIGNAL(clicked()), this, SLOT(stopSearch()) ); + connect(ui->push_done, SIGNAL(clicked()), this, SLOT(closeApplication()) ); + connect(ui->push_launch, SIGNAL(clicked()), this, SLOT(LaunchItem()) ); + connect(ui->line_search, SIGNAL(textEdited(QString)), this, SLOT(searchChanged()) ); + connect(ui->line_search, SIGNAL(returnPressed()), this, SLOT(LaunchItem()) ); + 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*)) ); + + //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(); +} + +MainUI::~MainUI(){ + workthread->quit(); + workthread->wait(); +} + +void MainUI::setupIcons(){ + //Setup the icons + this->setWindowIcon( LXDG::findIcon("edit-find","") ); + ui->push_launch->setIcon( LXDG::findIcon("quickopen","") ); + ui->push_done->setIcon( LXDG::findIcon("window-close","") ); + ui->tool_stop->setIcon( LXDG::findIcon("dialog-cancel","") ); +} + +//============== +// PRIVATE SLOTS +//============== +void MainUI::LaunchItem(){ +int index = ui->listWidget->currentRow(); +if(index<0 && ui->listWidget->count()>0){ index = 0; } //grab the first item instead +else if(index<0){ return; } //no items available/selected +QString item = ui->listWidget->item(index)->whatsThis(); +QProcess::startDetached("lumina-open \""+item+"\""); +//Close the search utility if an application was launched (quick launch functionality) +if(ui->radio_apps->isChecked()){ this->close(); } +} + +void MainUI::LaunchItem(QListWidgetItem *item){ + QProcess::startDetached("lumina-open \""+item->whatsThis()+"\""); +} + +void MainUI::searchTypeChanged(){ + startSearch(); +} + +void MainUI::searchChanged(){ + if(livetime->isActive()){ livetime->stop(); } + livetime->start(); +} + +//Worker Interaction +void MainUI::startSearch(){ + ui->listWidget->clear(); + stopSearch(); //just in case a search is still running + if(ui->line_search->text().isEmpty()){ return; } //nothing to search for + + //emit the proper signal for the worker + 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); +} + +void MainUI::foundSearchItem(QString path){ + //To get the worker's results + QListWidgetItem *it = new QListWidgetItem; + it->setWhatsThis(path); + it->setToolTip(path); + //Now setup the visuals + if(path.endsWith(".desktop")){ + bool ok = false; + XDGDesktop desk = LXDG::loadDesktopFile(path,ok); + if(!ok){delete it; return; } //invalid file + it->setText(desk.name); + it->setIcon( LXDG::findIcon(desk.icon, "application-x-desktop") ); + }else{ + it->setText( path.section("/",-1) ); + it->setIcon( LXDG::findMimeIcon(path.section(".",-1)) ); + } + //Now add it to the widget + ui->listWidget->addItem(it); +} + +void MainUI::stopSearch(){ + searcher->StopSearch(); + ui->tool_stop->setVisible(false); +} + +void MainUI::searchMessage(QString msg){ + ui->statusbar->showMessage(msg,2000); +} + +void MainUI::searchFinished(){ + ui->tool_stop->setVisible(false); +} -- cgit From d7b4dd01b7e8d803d3321dbc1eb3852cacf55e49 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 5 Nov 2014 13:31:40 -0500 Subject: Fix the display of a few of the search results in lumina-search --- lumina-search/MainUI.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lumina-search/MainUI.cpp') diff --git a/lumina-search/MainUI.cpp b/lumina-search/MainUI.cpp index df247324..d7abcd65 100644 --- a/lumina-search/MainUI.cpp +++ b/lumina-search/MainUI.cpp @@ -103,15 +103,21 @@ void MainUI::foundSearchItem(QString path){ it->setWhatsThis(path); it->setToolTip(path); //Now setup the visuals - if(path.endsWith(".desktop")){ + if(path.simplified().endsWith(".desktop")){ bool ok = false; XDGDesktop desk = LXDG::loadDesktopFile(path,ok); - if(!ok){delete it; return; } //invalid file + if( !ok || !LXDG::checkValidity(desk) ){delete it; return; } //invalid file it->setText(desk.name); it->setIcon( LXDG::findIcon(desk.icon, "application-x-desktop") ); }else{ - it->setText( path.section("/",-1) ); - it->setIcon( LXDG::findMimeIcon(path.section(".",-1)) ); + if(QFileInfo(path).isDir()){ + it->setIcon( LXDG::findIcon("inode-directory","") ); + it->setText( path.replace(QDir::homePath(), "~") ); + }else{ + it->setIcon( LXDG::findMimeIcon(path.section("/",-1).section(".",-1)) ); + it->setText( path.section("/",-1) ); + } + } //Now add it to the widget ui->listWidget->addItem(it); -- cgit