summaryrefslogtreecommitdiffstats
path: root/katapult/plugins/catalogs/execcatalog
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-03 02:45:19 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-03 02:45:19 +0000
commit4e1a5c3eebf50657629e2b4eba13649c2b599598 (patch)
tree7757743b67ed172d113dad73a3daa5b8aa6f871a /katapult/plugins/catalogs/execcatalog
downloadkatapult-4e1a5c3eebf50657629e2b4eba13649c2b599598.tar.gz
katapult-4e1a5c3eebf50657629e2b4eba13649c2b599598.zip
Added abandoned KDE3 version of katapult
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/katapult@1084407 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'katapult/plugins/catalogs/execcatalog')
-rw-r--r--katapult/plugins/catalogs/execcatalog/Makefile.am20
-rw-r--r--katapult/plugins/catalogs/execcatalog/actionrun.cpp75
-rw-r--r--katapult/plugins/catalogs/execcatalog/actionrun.h51
-rw-r--r--katapult/plugins/catalogs/execcatalog/command.cpp66
-rw-r--r--katapult/plugins/catalogs/execcatalog/command.h59
-rw-r--r--katapult/plugins/catalogs/execcatalog/execcatalog.cpp122
-rw-r--r--katapult/plugins/catalogs/execcatalog/execcatalog.h76
-rw-r--r--katapult/plugins/catalogs/execcatalog/katapult_execcatalog.desktop8
-rw-r--r--katapult/plugins/catalogs/execcatalog/settings.ui65
9 files changed, 542 insertions, 0 deletions
diff --git a/katapult/plugins/catalogs/execcatalog/Makefile.am b/katapult/plugins/catalogs/execcatalog/Makefile.am
new file mode 100644
index 0000000..ffc4753
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/Makefile.am
@@ -0,0 +1,20 @@
+# Copyright (C) 2007 Martin Meredith
+# Copyright (C) 2006 Jonathan Riddell
+
+# set the include path for X, qt and KDE
+INCLUDES = -I$(top_srcdir)/katapult/common $(all_includes)
+
+# header files
+noinst_HEADERS = actionrun.h execcatalog.h command.h
+
+# use automoc
+METASOURCES = AUTO
+
+KDE_ICON = AUTO
+
+# our plugin
+kde_module_LTLIBRARIES = katapult_execcatalog.la
+katapult_execcatalog_la_SOURCES = settings.ui execcatalog.cpp command.cpp actionrun.cpp
+katapult_execcatalog_la_LDFLAGS = -module $(KDE_RPATH) $(KDE_PLUGIN) $(all_libraries)
+katapult_execcatalog_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KIO) $(top_builddir)/katapult/common/libkatapult.la
+kde_services_DATA = katapult_execcatalog.desktop
diff --git a/katapult/plugins/catalogs/execcatalog/actionrun.cpp b/katapult/plugins/catalogs/execcatalog/actionrun.cpp
new file mode 100644
index 0000000..a1e5e7b
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/actionrun.cpp
@@ -0,0 +1,75 @@
+/***************************************************************************
+ * Copyright (C) 2007 Martin Meredith *
+ * mez@ubuntu.com *
+ * *
+ * Copyright (C) 2006 Jonathan Riddell *
+ * jriddell@ubuntu.com *
+ * *
+ * 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 <kapplication.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <klocale.h>
+#include <krun.h>
+
+#include "execcatalog.h"
+#include "command.h"
+#include "katapultitem.h"
+#include "actionrun.h"
+
+ActionRun::ActionRun()
+ : KatapultAction(), _command(0)
+{
+}
+
+ActionRun::~ActionRun()
+{
+}
+
+QString ActionRun::text() const
+{
+ return i18n("Execute");
+}
+
+QPixmap ActionRun::icon(int size) const
+{
+ return KGlobal::iconLoader()->loadIcon("exec", KIcon::NoGroup, size);
+}
+
+bool ActionRun::accepts(const KatapultItem* item) const
+{
+ bool accept = strcmp(item->className(), "Command") == 0;
+ if (accept) {
+ _command = (const Command*)item;
+ }
+ return accept;
+}
+
+void ActionRun::execute(const KatapultItem* item) const
+{
+ if (strcmp(item->className(), "Command") == 0) {
+ _command = (const Command*)item;
+
+ KRun::runCommand(_command->text().mid(_command->catalog()->triggerWordLength() + 1));
+
+
+ }
+}
diff --git a/katapult/plugins/catalogs/execcatalog/actionrun.h b/katapult/plugins/catalogs/execcatalog/actionrun.h
new file mode 100644
index 0000000..d81f103
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/actionrun.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2007 Martin Meredith *
+ * mez@ubuntu.com *
+ * *
+ * Copyright (C) 2006 Jonathan Riddell *
+ * jriddell@ubuntu.com *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef ACTIONRUN_H
+#define ACTIONRUN_H
+
+#include "katapultaction.h"
+
+class KatapultItem;
+class Command;
+
+class ActionRun : public KatapultAction
+{
+ public:
+ ActionRun();
+ ~ActionRun();
+
+ virtual void execute(const KatapultItem*) const;
+ virtual bool accepts(const KatapultItem*) const;
+ virtual QString text() const;
+ virtual QPixmap icon(int) const;
+
+ private:
+ //_expr needs to be mutable because accepts() is const.
+ mutable const Command* _command;
+
+};
+
+#endif
diff --git a/katapult/plugins/catalogs/execcatalog/command.cpp b/katapult/plugins/catalogs/execcatalog/command.cpp
new file mode 100644
index 0000000..0057bf8
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/command.cpp
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (C) 2007 Martin Meredith *
+ * mez@ubuntu.com *
+ * *
+ * Copyright (C) 2006 Jonathan Riddell *
+ * jriddell@ubuntu.com *
+ * *
+ * 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 <kservice.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <kapplication.h>
+
+#include <qclipboard.h>
+
+#include "execcatalog.h"
+#include "command.h"
+
+
+Command::Command(ExecCatalog* catalog, const QString& text): KatapultItem(), _catalog(catalog), _text(text)
+{
+}
+
+Command::~Command() {
+}
+
+QPixmap Command::icon(int size) const
+{
+ return KGlobal::iconLoader()->loadIcon("konsole", KIcon::NoGroup, size);
+}
+
+QString Command::text() const
+{
+ return _text;
+}
+
+void Command::setText(const QString& text)
+{
+ _text = text;
+}
+
+ExecCatalog* Command::catalog() const
+{
+ return _catalog;
+}
+
+
+#include "command.moc"
diff --git a/katapult/plugins/catalogs/execcatalog/command.h b/katapult/plugins/catalogs/execcatalog/command.h
new file mode 100644
index 0000000..7e649bf
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/command.h
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * Copyright (C) 2007 Martin Meredith *
+ * mez@ubuntu.com *
+ * *
+ * Copyright (C) 2006 Jonathan Riddell *
+ * jriddell@ubuntu.com *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef COMMAND_H
+#define COMMAND_H
+
+#include <kspell.h>
+
+#include <katapultitem.h>
+
+class ExecCatalog;
+
+/**
+@author Tobi Vollebregt
+*/
+class Command : public KatapultItem
+{
+ Q_OBJECT
+ public:
+ Command(ExecCatalog*, const QString&);
+ ~Command();
+
+ virtual QPixmap icon(int) const;
+ virtual QString text() const;
+
+ void setText(const QString&);
+
+ ExecCatalog* catalog() const;
+
+ private:
+ ExecCatalog* const _catalog;
+ QString _text;
+
+
+};
+
+#endif
diff --git a/katapult/plugins/catalogs/execcatalog/execcatalog.cpp b/katapult/plugins/catalogs/execcatalog/execcatalog.cpp
new file mode 100644
index 0000000..177df77
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/execcatalog.cpp
@@ -0,0 +1,122 @@
+/***************************************************************************
+ * Copyright (C) 2007 Martin Meredith *
+ * mez@ubuntu.com *
+ * *
+ * Copyright (C) 2006 Jonathan Riddell *
+ * jriddell@ubuntu.com *
+ * *
+ * 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 <kservicegroup.h>
+#include <ksycocaentry.h>
+#include <ksycocatype.h>
+#include <kapplication.h>
+
+#include <qlineedit.h>
+#include <qlabel.h>
+
+#include "settings.h"
+#include "execcatalog.h"
+#include "actionregistry.h"
+#include "actionrun.h"
+#include "status.h"
+
+K_EXPORT_COMPONENT_FACTORY( katapult_execcatalog,
+ KGenericFactory<ExecCatalog>( "katapult_execcatalog" ) )
+
+ExecCatalog::ExecCatalog(QObject*, const char*, const QStringList&): _result(this, QString::null)
+{
+ ActionRegistry::self()->registerAction(new ActionRun());
+}
+
+ExecCatalog::~ExecCatalog()
+{
+}
+
+void ExecCatalog::queryChanged()
+{
+ int newStatus = 0;
+ QString cmd = query();
+ int origLength = cmd.length();
+
+ if (cmd.isEmpty()) {
+ reset();
+ setBestMatch(Match());
+ } else {
+ if (accepts(cmd)) {
+ _result.setText(cmd);
+
+ setBestMatch(Match(&_result, 100, origLength));
+ //set status.
+ //add S_Multiple to make sure katapult doesn't auto-exec and close the window
+ //add S_Active to make sure katapult doesn't start the hideTimer or clearTimer
+ newStatus = S_HasResults | S_Multiple | S_Active;
+ } else {
+ newStatus = 0;
+ }
+ }
+ setStatus(newStatus);
+}
+
+bool ExecCatalog::accepts(const QString& str) const
+{
+ //accept if we begin with the triggerWord
+ int length = _triggerWord.length();
+ return str.left(length + 1) == _triggerWord + " ";
+}
+
+void ExecCatalog::readSettings(KConfigBase* config)
+{
+ _triggerWord = config->readEntry("TriggerWord", i18n("Should be short, easy and quick to type", "exec"));
+}
+
+void ExecCatalog::writeSettings(KConfigBase* config)
+{
+ config->writeEntry("TriggerWord", _triggerWord);
+}
+
+QWidget * ExecCatalog::configure()
+{
+ ExecCatalogSettings* settings = new ExecCatalogSettings();
+
+ settings->triggerWordLE->setText(_triggerWord);
+ connect(settings->triggerWordLE, SIGNAL(textChanged(const QString&)), this, SLOT(triggerWordChanged(const QString&)));
+
+ settings->introLabel->setText(i18n("Use with \"%1 exec query\"").arg(_triggerWord));
+
+ return settings;
+}
+
+void ExecCatalog::triggerWordChanged(const QString& triggerWord)
+{
+ _triggerWord = QString(triggerWord);
+}
+
+int ExecCatalog::triggerWordLength()
+{
+ return _triggerWord.length();
+}
+
+void ExecCatalog::reset()
+{
+ _result.setText(QString::null);
+}
+
+#include "execcatalog.moc"
diff --git a/katapult/plugins/catalogs/execcatalog/execcatalog.h b/katapult/plugins/catalogs/execcatalog/execcatalog.h
new file mode 100644
index 0000000..df550ee
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/execcatalog.h
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (C) 2007 Martin Meredith *
+ * mez@ubuntu.com *
+ * *
+ * Copyright (C) 2006 Jonathan Riddell *
+ * jriddell@ubuntu.com *
+ * *
+ * Copyright (C) 2005 Tobi Vollebregt *
+ * tobivollebregt@gmail.com *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef EXECCATALOG_H
+#define EXECCATALOG_H
+
+#include <kgenericfactory.h>
+
+#include <qstring.h>
+
+#include "command.h"
+#include "katapultcatalog.h"
+
+class QWidget;
+
+/**
+@author Jonathan Riddell
+ */
+class ExecCatalog : public KatapultCatalog
+{
+ Q_OBJECT
+
+ public:
+
+ ExecCatalog(QObject*, const char*, const QStringList&);
+ virtual ~ExecCatalog();
+
+ virtual void readSettings(KConfigBase*);
+ virtual void writeSettings(KConfigBase*);
+ virtual QWidget* configure();
+ int triggerWordLength();
+
+ protected:
+
+ virtual void queryChanged();
+
+ private:
+ bool accepts(const QString&) const;
+
+ QString _triggerWord;
+
+ Command _result; // The one result (there's always one).
+
+ void reset();
+
+ protected slots:
+ void triggerWordChanged(const QString& triggerWord);
+
+};
+
+#endif
diff --git a/katapult/plugins/catalogs/execcatalog/katapult_execcatalog.desktop b/katapult/plugins/catalogs/execcatalog/katapult_execcatalog.desktop
new file mode 100644
index 0000000..d1fbe93
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/katapult_execcatalog.desktop
@@ -0,0 +1,8 @@
+# Copyright (C) 2007 Martin Meredith
+[Desktop Entry]
+Name=Execution Catalog
+Comment=Execute commands
+ServiceTypes=Katapult/Catalog
+Type=Service
+X-KDE-Library=katapult_execcatalog
+X-Katapult-ID=Execution Catalog
diff --git a/katapult/plugins/catalogs/execcatalog/settings.ui b/katapult/plugins/catalogs/execcatalog/settings.ui
new file mode 100644
index 0000000..6186013
--- /dev/null
+++ b/katapult/plugins/catalogs/execcatalog/settings.ui
@@ -0,0 +1,65 @@
+<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
+<class>ExecCatalogSettings</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>ExecCatalogSettings</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>356</width>
+ <height>265</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>Settings</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLineEdit" row="1" column="1">
+ <property name="name">
+ <cstring>triggerWordLE</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="0">
+ <property name="name">
+ <cstring>triggerWordLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Trigger Word:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>introLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Use with: "run command"</string>
+ </property>
+ </widget>
+ <spacer row="2" column="1">
+ <property name="name">
+ <cstring>spacer2</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>150</height>
+ </size>
+ </property>
+ </spacer>
+ </grid>
+</widget>
+<tabstops>
+</tabstops>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>