/*************************************************************************** * Copyright (C) 2005 by Joe Ferris * * jferris@optimistictech.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include #include #include #include #include #include #include #include "settings.h" #include "programcatalog.h" #include "program.h" #include "actionregistry.h" #include "actionrunprogram.h" K_EXPORT_COMPONENT_FACTORY( katapult_programcatalog, KGenericFactory( "katapult_programcatalog" ) ) ProgramCatalog::ProgramCatalog(TQObject *, const char *, const TQStringList&) : CachedCatalog() { _minQueryLen = 1; _ignoreIconless = TRUE; _ignoreTerminal = TRUE; _useExecName = FALSE; ActionRegistry::self()->registerAction(new ActionRunProgram()); } ProgramCatalog::~ProgramCatalog() { } void ProgramCatalog::initialize() { cacheProgramList(TQString()); } void ProgramCatalog::cacheProgramList(TQString relPath) { KServiceGroup::Ptr group = KServiceGroup::group(relPath); if(!group || !group->isValid()) return; KServiceGroup::List list = group->entries(); if(list.isEmpty()) return; KServiceGroup::List::ConstIterator it = list.begin(); for(; it != list.end(); ++it) { KSycocaEntry *e = *it; if(e != 0) { if(e->isType(KST_KServiceGroup)) { KServiceGroup::Ptr g(static_cast(e)); if(!g->noDisplay()) cacheProgramList(g->relPath()); } else if(e->isType(KST_KService)) { KService::Ptr s(static_cast(e)); if(s->type() == "Application" && (!_ignoreIconless || !s->icon().isEmpty()) && (!_ignoreTerminal || !s->terminal()) && !s->noDisplay() ) { addItem(new Program(s, _useExecName)); } } } } } unsigned int ProgramCatalog::minQueryLen() const { return _minQueryLen; } void ProgramCatalog::readSettings(KConfigBase *config) { _minQueryLen = config->readUnsignedNumEntry("MinQueryLen", 1); _ignoreIconless = config->readBoolEntry("IgnoreIconless", TRUE); _useExecName = config->readBoolEntry("UseExecName", FALSE); _ignoreTerminal = config->readBoolEntry("IgnoreTerminal", TRUE); } void ProgramCatalog::writeSettings(KConfigBase *config) { config->writeEntry("MinQueryLen", _minQueryLen); config->writeEntry("IgnoreIconless", _ignoreIconless); config->writeEntry("UseExecName", _useExecName); config->writeEntry("IgnoreTerminal", _ignoreTerminal); } TQWidget * ProgramCatalog::configure() { ProgramCatalogSettings *settings = new ProgramCatalogSettings(); settings->minQueryLen->setValue(_minQueryLen); connect(settings->minQueryLen, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(minQueryLenChanged(int))); settings->ignoreIconless->setChecked(_ignoreIconless); connect(settings->ignoreIconless, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(toggleIgnoreIconless(bool))); settings->useExecName->setChecked(_useExecName); connect(settings->useExecName, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(toggleUseExecName(bool))); settings->ignoreTerminal->setChecked(_ignoreTerminal); connect(settings->ignoreTerminal, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(toggleIgnoreTerminal(bool))); return settings; } void ProgramCatalog::minQueryLenChanged(int _minQueryLen) { this->_minQueryLen = _minQueryLen; } void ProgramCatalog::toggleIgnoreIconless(bool _ignoreIconless) { this->_ignoreIconless = _ignoreIconless; } void ProgramCatalog::toggleUseExecName(bool _useExecName) { this->_useExecName = _useExecName; } void ProgramCatalog::toggleIgnoreTerminal(bool _ignoreTerminal) { this->_ignoreTerminal = _ignoreTerminal; } #include "programcatalog.moc"