1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/***************************************************************************
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <kservicegroup.h>
#include <ksycocaentry.h>
#include <ksycocatype.h>
#include <kapplication.h>
#include <knuminput.h>
#include <kcombobox.h>
#include <qcheckbox.h>
#include "settings.h"
#include "programcatalog.h"
#include "program.h"
#include "actionregistry.h"
#include "actionrunprogram.h"
K_EXPORT_COMPONENT_FACTORY( katapult_programcatalog,
KGenericFactory<ProgramCatalog>( "katapult_programcatalog" ) )
ProgramCatalog::ProgramCatalog(QObject *, const char *, const QStringList&)
: CachedCatalog()
{
_minQueryLen = 1;
_ignoreIconless = TRUE;
_ignoreTerminal = TRUE;
_useExecName = FALSE;
ActionRegistry::self()->registerAction(new ActionRunProgram());
}
ProgramCatalog::~ProgramCatalog()
{
}
void ProgramCatalog::initialize()
{
cacheProgramList(QString::null);
}
void ProgramCatalog::cacheProgramList(QString 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<KServiceGroup *>(e));
if(!g->noDisplay())
cacheProgramList(g->relPath());
} else if(e->isType(KST_KService))
{
KService::Ptr s(static_cast<KService *>(e));
if(s->type() == "Application" &&
(!_ignoreIconless || !s->icon().isEmpty()) &&
(!_ignoreTerminal || !s->terminal())
) {
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);
}
QWidget * ProgramCatalog::configure()
{
ProgramCatalogSettings *settings = new ProgramCatalogSettings();
settings->minQueryLen->setValue(_minQueryLen);
connect(settings->minQueryLen, SIGNAL(valueChanged(int)), this, SLOT(minQueryLenChanged(int)));
settings->ignoreIconless->setChecked(_ignoreIconless);
connect(settings->ignoreIconless, SIGNAL(toggled(bool)), this, SLOT(toggleIgnoreIconless(bool)));
settings->useExecName->setChecked(_useExecName);
connect(settings->useExecName, SIGNAL(toggled(bool)), this, SLOT(toggleUseExecName(bool)));
settings->ignoreTerminal->setChecked(_ignoreTerminal);
connect(settings->ignoreTerminal, SIGNAL(toggled(bool)), this, 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;
}
|