summaryrefslogtreecommitdiffstats
path: root/katapult/plugins/catalogs/googlecatalog
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/googlecatalog
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/googlecatalog')
-rw-r--r--katapult/plugins/catalogs/googlecatalog/Makefile.am20
-rw-r--r--katapult/plugins/catalogs/googlecatalog/actionsearch.cpp83
-rw-r--r--katapult/plugins/catalogs/googlecatalog/actionsearch.h51
-rw-r--r--katapult/plugins/catalogs/googlecatalog/googlecatalog.cpp122
-rw-r--r--katapult/plugins/catalogs/googlecatalog/googlecatalog.h76
-rw-r--r--katapult/plugins/catalogs/googlecatalog/katapult_googlecatalog.desktop8
-rw-r--r--katapult/plugins/catalogs/googlecatalog/query.cpp66
-rw-r--r--katapult/plugins/catalogs/googlecatalog/query.h59
-rw-r--r--katapult/plugins/catalogs/googlecatalog/settings.ui65
9 files changed, 550 insertions, 0 deletions
diff --git a/katapult/plugins/catalogs/googlecatalog/Makefile.am b/katapult/plugins/catalogs/googlecatalog/Makefile.am
new file mode 100644
index 0000000..a632da7
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/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 = actionsearch.h googlecatalog.h query.h
+
+# use automoc
+METASOURCES = AUTO
+
+KDE_ICON = AUTO
+
+# our plugin
+kde_module_LTLIBRARIES = katapult_googlecatalog.la
+katapult_googlecatalog_la_SOURCES = settings.ui googlecatalog.cpp query.cpp actionsearch.cpp
+katapult_googlecatalog_la_LDFLAGS = -module $(KDE_RPATH) $(KDE_PLUGIN) $(all_libraries)
+katapult_googlecatalog_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KIO) $(top_builddir)/katapult/common/libkatapult.la
+kde_services_DATA = katapult_googlecatalog.desktop
diff --git a/katapult/plugins/catalogs/googlecatalog/actionsearch.cpp b/katapult/plugins/catalogs/googlecatalog/actionsearch.cpp
new file mode 100644
index 0000000..b9af97e
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/actionsearch.cpp
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * 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 <kurl.h>
+#include <krun.h>
+
+#include "googlecatalog.h"
+#include "query.h"
+#include "katapultitem.h"
+#include "actionsearch.h"
+
+ActionSearch::ActionSearch()
+ : KatapultAction(), _searchquery(0)
+{
+}
+
+ActionSearch::~ActionSearch()
+{
+}
+
+QString ActionSearch::text() const
+{
+ return i18n("Search Google");
+}
+
+QPixmap ActionSearch::icon(int size) const
+{
+ return KGlobal::iconLoader()->loadIcon("viewmag", KIcon::NoGroup, size);
+}
+
+bool ActionSearch::accepts(const KatapultItem* item) const
+{
+ bool accept = strcmp(item->className(), "SearchQuery") == 0;
+ if (accept) {
+ _searchquery = (const SearchQuery*)item;
+ }
+ return accept;
+}
+
+void ActionSearch::execute(const KatapultItem* item) const
+{
+ if (strcmp(item->className(), "SearchQuery") == 0) {
+ _searchquery = (const SearchQuery*)item;
+
+ KURL _gotourl;
+ _gotourl.setProtocol("http");
+ _gotourl.setHost("www.google.com");
+ _gotourl.setPath("/search");
+ _gotourl.addQueryItem("q", _searchquery->text().mid(_searchquery->catalog()->triggerWordLength() + 1));
+ _gotourl.addQueryItem("ie", "UTF-8");
+ _gotourl.addQueryItem("oe", "UTF-8");
+ new KRun(_gotourl);
+
+
+ }
+}
diff --git a/katapult/plugins/catalogs/googlecatalog/actionsearch.h b/katapult/plugins/catalogs/googlecatalog/actionsearch.h
new file mode 100644
index 0000000..c35b394
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/actionsearch.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 ACTIONSEARCH_H
+#define ACTIONSEARCH_H
+
+#include "katapultaction.h"
+
+class KatapultItem;
+class SearchQuery;
+
+class ActionSearch : public KatapultAction
+{
+ public:
+ ActionSearch();
+ ~ActionSearch();
+
+ 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 SearchQuery* _searchquery;
+
+};
+
+#endif
diff --git a/katapult/plugins/catalogs/googlecatalog/googlecatalog.cpp b/katapult/plugins/catalogs/googlecatalog/googlecatalog.cpp
new file mode 100644
index 0000000..a180a30
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/googlecatalog.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 "googlecatalog.h"
+#include "actionregistry.h"
+#include "actionsearch.h"
+#include "status.h"
+
+K_EXPORT_COMPONENT_FACTORY( katapult_googlecatalog,
+ KGenericFactory<GoogleCatalog>( "katapult_googlecatalog" ) )
+
+GoogleCatalog::GoogleCatalog(QObject*, const char*, const QStringList&): _result(this, QString::null)
+{
+ ActionRegistry::self()->registerAction(new ActionSearch());
+}
+
+GoogleCatalog::~GoogleCatalog()
+{
+}
+
+void GoogleCatalog::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 GoogleCatalog::accepts(const QString& str) const
+{
+ //accept if we begin with the triggerWord
+ int length = _triggerWord.length();
+ return str.left(length + 1) == _triggerWord + " ";
+}
+
+void GoogleCatalog::readSettings(KConfigBase* config)
+{
+ _triggerWord = config->readEntry("TriggerWord", i18n("Should be short, easy and quick to type", "google"));
+}
+
+void GoogleCatalog::writeSettings(KConfigBase* config)
+{
+ config->writeEntry("TriggerWord", _triggerWord);
+}
+
+QWidget * GoogleCatalog::configure()
+{
+ GoogleCatalogSettings* settings = new GoogleCatalogSettings();
+
+ settings->triggerWordLE->setText(_triggerWord);
+ connect(settings->triggerWordLE, SIGNAL(textChanged(const QString&)), this, SLOT(triggerWordChanged(const QString&)));
+
+ settings->introLabel->setText(i18n("Use with \"%1 search query\"").arg(_triggerWord));
+
+ return settings;
+}
+
+void GoogleCatalog::triggerWordChanged(const QString& triggerWord)
+{
+ _triggerWord = QString(triggerWord);
+}
+
+int GoogleCatalog::triggerWordLength()
+{
+ return _triggerWord.length();
+}
+
+void GoogleCatalog::reset()
+{
+ _result.setText(QString::null);
+}
+
+#include "googlecatalog.moc"
diff --git a/katapult/plugins/catalogs/googlecatalog/googlecatalog.h b/katapult/plugins/catalogs/googlecatalog/googlecatalog.h
new file mode 100644
index 0000000..3dfd342
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/googlecatalog.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 GOOGLECATALOG_H
+#define GOOGLECATALOG_H
+
+#include <kgenericfactory.h>
+
+#include <qstring.h>
+
+#include "query.h"
+#include "katapultcatalog.h"
+
+class QWidget;
+
+/**
+@author Jonathan Riddell
+ */
+class GoogleCatalog : public KatapultCatalog
+{
+ Q_OBJECT
+
+ public:
+
+ GoogleCatalog(QObject*, const char*, const QStringList&);
+ virtual ~GoogleCatalog();
+
+ 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;
+
+ SearchQuery _result; // The one result (there's always one).
+
+ void reset();
+
+ protected slots:
+ void triggerWordChanged(const QString& triggerWord);
+
+};
+
+#endif
diff --git a/katapult/plugins/catalogs/googlecatalog/katapult_googlecatalog.desktop b/katapult/plugins/catalogs/googlecatalog/katapult_googlecatalog.desktop
new file mode 100644
index 0000000..d7cc211
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/katapult_googlecatalog.desktop
@@ -0,0 +1,8 @@
+# Copyright (C) 2007 Martin Meredith
+[Desktop Entry]
+Name=Google Catalog
+Comment=Search Google
+ServiceTypes=Katapult/Catalog
+Type=Service
+X-KDE-Library=katapult_googlecatalog
+X-Katapult-ID=Google Catalog
diff --git a/katapult/plugins/catalogs/googlecatalog/query.cpp b/katapult/plugins/catalogs/googlecatalog/query.cpp
new file mode 100644
index 0000000..c97f00e
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/query.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 "googlecatalog.h"
+#include "query.h"
+
+
+SearchQuery::SearchQuery(GoogleCatalog* catalog, const QString& text): KatapultItem(), _catalog(catalog), _text(text)
+{
+}
+
+SearchQuery::~SearchQuery() {
+}
+
+QPixmap SearchQuery::icon(int size) const
+{
+ return KGlobal::iconLoader()->loadIcon("help", KIcon::NoGroup, size);
+}
+
+QString SearchQuery::text() const
+{
+ return _text;
+}
+
+void SearchQuery::setText(const QString& text)
+{
+ _text = text;
+}
+
+GoogleCatalog* SearchQuery::catalog() const
+{
+ return _catalog;
+}
+
+
+#include "query.moc"
diff --git a/katapult/plugins/catalogs/googlecatalog/query.h b/katapult/plugins/catalogs/googlecatalog/query.h
new file mode 100644
index 0000000..6759f13
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/query.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 QUERY_H
+#define QUERY_H
+
+#include <kspell.h>
+
+#include <katapultitem.h>
+
+class GoogleCatalog;
+
+/**
+@author Tobi Vollebregt
+*/
+class SearchQuery : public KatapultItem
+{
+ Q_OBJECT
+ public:
+ SearchQuery(GoogleCatalog*, const QString&);
+ ~SearchQuery();
+
+ virtual QPixmap icon(int) const;
+ virtual QString text() const;
+
+ void setText(const QString&);
+
+ GoogleCatalog* catalog() const;
+
+ private:
+ GoogleCatalog* const _catalog;
+ QString _text;
+
+
+};
+
+#endif
diff --git a/katapult/plugins/catalogs/googlecatalog/settings.ui b/katapult/plugins/catalogs/googlecatalog/settings.ui
new file mode 100644
index 0000000..5549c3b
--- /dev/null
+++ b/katapult/plugins/catalogs/googlecatalog/settings.ui
@@ -0,0 +1,65 @@
+<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
+<class>GoogleCatalogSettings</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>GoogleCatalogSettings</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: "google Search Query"</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>