diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-12 18:09:55 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-12 18:09:55 +0000 |
commit | 630b7196d93786595546565329160ff26332704b (patch) | |
tree | 16f570c8f65cf789945d96ab7c4c7c9a46c10e2f /src/locater.cpp | |
download | tdeio-locate-630b7196d93786595546565329160ff26332704b.tar.gz tdeio-locate-630b7196d93786595546565329160ff26332704b.zip |
Added KDE3 version of kio-locate
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kio-locate@1089224 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/locater.cpp')
-rw-r--r-- | src/locater.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/locater.cpp b/src/locater.cpp new file mode 100644 index 0000000..4072209 --- /dev/null +++ b/src/locater.cpp @@ -0,0 +1,131 @@ +/*************************************************************************** + * kio-locate: KDE I/O Slave for the locate command * + * * + * Copyright (C) 2005 by Tobi Vollebregt * + * tobivollebregt@gmail.com * + * * + * Thanks to Google's Summer Of Code Program! * + * * + * Copyright (C) 2004 by Armin Straub * + * linux@arminstraub.de * + * * + * This program was initially written by Michael Schuerig. * + * Although I have completely rewritten it, most ideas are adopted * + * from his original work. * + * * + * Copyright (C) 2002 by Michael Schuerig * + * michael@schuerig.de * + * * + * * + * 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. * + ***************************************************************************/ + +#include <qtextcodec.h> + +#include <kdebug.h> +#include <kstandarddirs.h> + +#include "locater.h" + + +Locater::Locater(QObject *parent, const char *name) + : QObject(parent, name), m_process(QTextCodec::codecForLocale()) +{ + DEBUGSTR << "Locater::Locater" << endl; + + connect(&m_process, SIGNAL(processExited(KProcess*)), + this, SLOT(finished(KProcess*))); + connect(&m_process, SIGNAL(readReady(KProcIO*)), + this, SLOT(gotOutput(KProcIO*))); + + setupLocate(); +} + + +Locater::~Locater() +{ + DEBUGSTR << "Locater::~Locater" << endl; +} + + +void Locater::setupLocate(const QString& binary, const QString& additionalArguments) +{ + DEBUGSTR << "Locater::setupLocate(" << binary << ", " << additionalArguments << ")" << endl; + + // Automatically choose the correct binary if not specified. + if (binary.isEmpty()) { + if (KStandardDirs::findExe("slocate")) { + m_binary = "slocate"; + } else if (KStandardDirs::findExe("rlocate")) { + m_binary = "rlocate"; + } else { + m_binary = "locate"; + } + DEBUGSTR << "Using binary:" << m_binary << endl; + } else { + m_binary = binary; + } + m_additionalArguments = additionalArguments; + m_binaryExists = KStandardDirs::findExe(m_binary) != QString::null; +} + + +bool Locater::locate(const QString& pattern, bool ignoreCase, bool regExp) +{ + DEBUGSTR << "Locater::locate(" << pattern << "," << ignoreCase << "," << regExp << ")" << endl; + + m_process.resetAll(); + m_process << m_binary; + if (!m_additionalArguments.isEmpty()) { + m_process << m_additionalArguments; + } + if (ignoreCase) { + // m_process << "--ignore-case"; + m_process << "-i"; + } + if (regExp) { + m_process << "-r"; + } + m_process << pattern; + + return m_process.start(KProcess::Block, false); +} + +void Locater::stop() +{ + DEBUGSTR << "Locater::stop()" << endl; + + m_process.kill(); + emit finished(); +} + + +void Locater::gotOutput(KProcIO* /*proc*/) +{ + //DEBUGSTR << "Locater::gotOutput" << endl; + + QStringList items; + QString line; + + while (m_process.readln(line) != -1) { + //DEBUGSTR << "OUTPUT>> '" << line << "'" << endl; + + items << line; + } + + emit found(items); +} + + +void Locater::finished(KProcess* /*proc*/) +{ + DEBUGSTR << "Locater::finished" << endl; + + emit finished(); +} + + +#include "locater.moc" |