[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [sprinter/gko/master] /: URI plugin
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2014-03-06 10:20:25
Message-ID: E1WLVPd-0007ZS-AB () scm ! kde ! org
[Download RAW message or body]
Git commit 569ca7ae4b2bb4ca9ba145df5331b81a3a77c8e1 by Aaron J. Seigo.
Committed on 26/02/2014 at 14:22.
Pushed by aseigo into branch 'gko/master'.
URI plugin
crashes happening in KIO, however ... need to investigate further
so currently commented out to not interfere with stability while
testing
M +1 -1 docs/TODO
M +6 -0 runners/CMakeLists.txt
A +8 -0 runners/uri/CMakeLists.txt
A +89 -0 runners/uri/uri.cpp [License: GPL (v2+)]
A +15 -0 runners/uri/uri.desktop
A +39 -0 runners/uri/uri.h [License: GPL (v2+)]
A +15 -0 runners/uri/uri.json
http://commits.kde.org/sprinter/569ca7ae4b2bb4ca9ba145df5331b81a3a77c8e1
diff --git a/docs/TODO b/docs/TODO
index c3ee3cc..8538c96 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -8,7 +8,7 @@
* shouldn't need to copy the firefox db file, e.g.
* kill
* locations
- * split into two plugins: one for files, one for network locations
+ * split out file location matcher (already have a URI plugin)
* nepomuksearch
* needs to be ported / rewritten to use baloo
* places
diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt
index a762f6a..92a1531 100644
--- a/runners/CMakeLists.txt
+++ b/runners/CMakeLists.txt
@@ -1,4 +1,5 @@
find_package(KF5DBusAddons)
+find_package(KF5KIO)
find_package(KF5Activities)
find_package(Qalculate)
@@ -10,6 +11,11 @@ if (KF5Activities_FOUND)
add_subdirectory(activities)
endif (KF5Activities_FOUND)
+if (KF5KIO_FOUND)
+# currently this guy crashes somewhere in KIO
+# add_subdirectory(uri)
+endif (KF5KIO_FOUND)
+
add_subdirectory(c)
add_subdirectory(datetime)
add_subdirectory(youtube)
diff --git a/runners/uri/CMakeLists.txt b/runners/uri/CMakeLists.txt
new file mode 100644
index 0000000..c27aaa0
--- /dev/null
+++ b/runners/uri/CMakeLists.txt
@@ -0,0 +1,8 @@
+project(sprinter_org_kde_sprinter_uri)
+
+add_definitions(-DQT_PLUGIN)
+include_directories(${CMAKE_CURRENT_BINARY_DIR} KF5::KIOWidgets)
+add_library(${PROJECT_NAME} SHARED uri.cpp)
+qt5_use_modules(${PROJECT_NAME} Core Gui)
+target_link_libraries(${PROJECT_NAME} KF5::KIOWidgets KF5::KIOCore)
+install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SPRINTER_PLUGINS_PATH})
\ No newline at end of file
diff --git a/runners/uri/uri.cpp b/runners/uri/uri.cpp
new file mode 100644
index 0000000..6f72c64
--- /dev/null
+++ b/runners/uri/uri.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "uri.h"
+
+#include <QDebug>
+#include <QEventLoop>
+#include <QIcon>
+
+#include <KIOCore/KProtocolInfo>
+#include <KIOWidgets/KRun>
+#include <KIOWidgets/KUriFilter>
+
+UriRunner::UriRunner(QObject *parent)
+ : Sprinter::Runner(parent)
+{
+ m_filterList << QStringLiteral("kshorturifilter");
+}
+
+void UriRunner::match(Sprinter::MatchData &matchData)
+{
+ QString location = matchData.queryContext().query();
+ KUriFilter *filter = KUriFilter::self();
+ const bool filtered = filter->filterUri(location, m_filterList);
+
+ if (!filtered) {
+ return;
+ }
+
+ qDebug() << "filtered to" << location;
+ QUrl url(location);
+
+ if (!KProtocolInfo::isKnownProtocol(url.scheme())) {
+ return;
+ }
+
+ Sprinter::QueryMatch match;
+ match.setData(location);
+ QIcon icon = QIcon::fromTheme(KProtocolInfo::icon(url.scheme()));
+ if (!icon.isNull()) {
+ match.setImage(icon.pixmap(matchData.queryContext().imageSize()).toImage());
+ }
+
+ if (KProtocolInfo::isHelperProtocol(url.scheme())) {
+ //qDebug() << "helper protocol" << url.scheme() <<"call external application" ;
+ if (url.scheme() == "mailto") {
+ match.setTitle(tr("Send email to %1").arg(url.path()));
+ match.setType(Sprinter::QuerySession::MessageType);
+ } else {
+ match.setTitle(tr("Launch with %1").arg( KProtocolInfo::exec(url.scheme())));
+ match.setType(Sprinter::QuerySession::NetworkLocationType);
+ }
+ } else {
+ //kDebug() << "protocol managed by browser" << url.scheme();
+ match.setTitle(tr("Go to %1").arg(url.toString()));
+ match.setType(Sprinter::QuerySession::NetworkLocationType);
+ }
+
+ match.setSource(Sprinter::QuerySession::FromInternalSource);
+ match.setPrecision(Sprinter::QuerySession::ExactMatch);
+ matchData << match;
+}
+
+bool UriRunner::exec(const Sprinter::QueryMatch &match)
+{
+ bool success = false;
+ QEventLoop loop;
+ KRun *krun = new KRun(match.data().toString(), 0);
+ connect(krun, &KRun::finished,
+ [&]() { success = !krun->hasError(); loop.exit(); });
+ loop.exec();
+ return success;
+}
+
+#include "moc_uri.cpp"
diff --git a/runners/uri/uri.desktop b/runners/uri/uri.desktop
new file mode 100644
index 0000000..5b81535
--- /dev/null
+++ b/runners/uri/uri.desktop
@@ -0,0 +1,15 @@
+[Desktop Entry]
+Name=Network Locations
+
+Comment=Go to URLs
+
+Icon=internet-web-browser
+
+X-KDE-ServiceTypes=Sprinter/Runner
+Type=Service
+X-KDE-PluginInfo-Author=Aaron Seigo
+X-KDE-PluginInfo-Email=aseigo@kde.org
+X-KDE-PluginInfo-Name=uri
+X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
diff --git a/runners/uri/uri.h b/runners/uri/uri.h
new file mode 100644
index 0000000..5b51f89
--- /dev/null
+++ b/runners/uri/uri.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RUNNER_URI
+#define RUNNER_URI
+
+#include <sprinter/runner.h>
+
+class UriRunner : public Sprinter::Runner
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.kde.sprinter.uri" FILE "uri.json")
+ Q_INTERFACES(Sprinter::Runner)
+
+public:
+ UriRunner(QObject *parent = 0);
+
+ void match(Sprinter::MatchData &matchData);
+ bool exec(const Sprinter::QueryMatch &match);
+
+private:
+ QStringList m_filterList;
+};
+
+#endif
diff --git a/runners/uri/uri.json b/runners/uri/uri.json
new file mode 100644
index 0000000..06f1a96
--- /dev/null
+++ b/runners/uri/uri.json
@@ -0,0 +1,15 @@
+{
+ "Comment": "Go to URLs",
+ "Icon": "internet-web-browser",
+ "Name": "Network Locations",
+ "Type": "Service",
+ "X-KDE-PluginInfo-Author": "Aaron Seigo",
+ "X-KDE-PluginInfo-Email": "aseigo@kde.org",
+ "X-KDE-PluginInfo-EnabledByDefault": true,
+ "X-KDE-PluginInfo-License": "GPL",
+ "X-KDE-PluginInfo-Name": "uri",
+ "X-KDE-PluginInfo-Version": "0.1",
+ "X-KDE-ServiceTypes": [
+ "Sprinter/Runner"
+ ]
+}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic