Example #1
0
void Worker::beginsearch(){
  stopsearch = false; //just starting search - always set this to false initially
  emit SearchUpdate( QString(tr("Starting Search: %1")).arg(sterm) );
  //Now Perform the search
  if(sapp){
    //First try to match based on the name
    QStringList tmp = applist.filter(":::1:::"+sterm, Qt::CaseInsensitive);
    tmp.sort();
    for(int i=0; i<tmp.length(); i++){
      if(stopsearch){ return; }
      emit FoundItem( tmp[i].section(":::4:::",1,1) );
    }
    //Check if this is a binary name
    if(stopsearch){ return; }
    if(LUtils::isValidBinary(sterm)){
      emit FoundItem(sterm);
      return;
    }
    //If items found, go ahead and stop now
    if(stopsearch){ return; }
    if(tmp.length()<1){
      //Now try to match based on the generic name
      tmp = applist.filter(":::2:::"+sterm, Qt::CaseInsensitive);
      tmp.sort();
      for(int i=0; i<tmp.length(); i++){
        if(stopsearch){ return; }
        emit FoundItem( tmp[i].section(":::4:::",1,1) );
      }
    }
    //If items found, go ahead and stop now
    if(stopsearch){ return; }
    if(tmp.length()<1){
      //Now try to match based on anything (name/genericname/comment)
      tmp = applist.filter(sterm, Qt::CaseInsensitive);
      tmp.sort();
      for(int i=0; i<tmp.length(); i++){
        if(stopsearch){ return; }
        emit FoundItem( tmp[i].section(":::4:::",1,1) );
      }
    }
    
  }else{
    //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
    }
    if(startDir.isEmpty()){ startDir = QDir::homePath(); }
    searchDir(startDir);
    
  }
  emit SearchUpdate( tr("Search Finished") );
  emit SearchDone();
}
Example #2
0
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/3 second for live searches
    livetime->setSingleShot(true);

    workthread = new QThread(this);
    workthread->setObjectName("Lumina Search Process");

    searcher = new Worker();
    searcher->moveToThread(workthread);

    closeShort = new QShortcut(QKeySequence(tr("Esc")), this);

    //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*)) );
    connect(ui->tool_configure, SIGNAL(clicked()), this, SLOT(configureSearch()) );
    connect(closeShort, SIGNAL(activated()), this, SLOT( close() ) );

    //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();
    updateDefaultStatusTip();
    this->show();
    workthread->start();
    QTimer::singleShot(0,this, SLOT(setupIcons()) );
}
Example #3
0
bool Worker::searchDir(QString dirpath){
  //This is a recursive search algorithm for scanning a directory
  QDir dir(dirpath);
  //First look for files that match the search term	
  if(stopsearch){ return true; }
  emit SearchUpdate( QString(tr("Searching: %1")).arg(dirpath.replace(QDir::homePath(),"~")) );
  QStringList tmp;
  if(sterm.startsWith(".")){ tmp = dir.entryList(QStringList(sterm), QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden, QDir::Name); }
  else{ tmp = dir.entryList(QStringList(sterm), QDir::AllEntries | QDir::NoDotAndDotDot , QDir::Name); }
  for(int i=0; i<tmp.length(); i++){
    if(stopsearch){ return true; }
    emit FoundItem( dir.absoluteFilePath(tmp[i]) );
  }
  if(stopsearch){ return true; }
  //Now recursively scan the sub directories
  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])) || tmp[i]=="proc" ){ continue; } //this dir is skipped
       //Special case - skip the "proc" directory heirarchy (highly-recursive layout for *every* process which is running)
    if( searchDir(dir.absoluteFilePath(tmp[i])) ){ return true; }
  }
  return false;
}