[SCM] ktp-text-ui packaging branch, master, updated. debian/16.04.2-1-88-g820317b
Maximiliano Curia
maxy at moszumanska.debian.org
Tue Sep 12 14:10:01 UTC 2017
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=78a720b
The following commit has been merged in the master branch:
commit 78a720b656a84340d026dc9085864a325c431e37
Author: Alexandr Akulich <akulichalexander at gmail.com>
Date: Fri Jul 15 13:40:16 2016 +0500
[filters] Added Geopoint filter plugin.
---
filters/CMakeLists.txt | 1 +
filters/geopoint/CMakeLists.txt | 21 ++++++
filters/geopoint/geopoint-filter.cpp | 76 ++++++++++++++++++++++
.../otr-filter.h => geopoint/geopoint-filter.h} | 15 ++---
...ktptextui_message_filter_geopoint.desktop.cmake | 17 +++++
5 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/filters/CMakeLists.txt b/filters/CMakeLists.txt
index 8118b13..ce06ba7 100644
--- a/filters/CMakeLists.txt
+++ b/filters/CMakeLists.txt
@@ -1,6 +1,7 @@
add_subdirectory(bugzilla)
add_subdirectory(emoticons)
add_subdirectory(formatting)
+add_subdirectory(geopoint)
add_subdirectory(images)
add_subdirectory(latex)
add_subdirectory(searchexpansion)
diff --git a/filters/geopoint/CMakeLists.txt b/filters/geopoint/CMakeLists.txt
new file mode 100644
index 0000000..0a3414f
--- /dev/null
+++ b/filters/geopoint/CMakeLists.txt
@@ -0,0 +1,21 @@
+add_library(ktptextui_message_filter_geopoint MODULE geopoint-filter.cpp)
+
+target_link_libraries(ktptextui_message_filter_geopoint
+ ktpchat
+ KF5::KIOWidgets
+ KTp::CommonInternals
+ )
+
+# Install:
+install(TARGETS ktptextui_message_filter_geopoint
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ktptextui_message_filter_geopoint.desktop.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/ktptextui_message_filter_geopoint.desktop
+ @ONLY
+)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ktptextui_message_filter_geopoint.desktop
+ DESTINATION ${SERVICES_INSTALL_DIR}
+)
diff --git a/filters/geopoint/geopoint-filter.cpp b/filters/geopoint/geopoint-filter.cpp
new file mode 100644
index 0000000..40a74ae
--- /dev/null
+++ b/filters/geopoint/geopoint-filter.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2016 Alexandr Akulich <akulichalexander at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "geopoint-filter.h"
+
+#include <KPluginFactory>
+
+#include <QRegularExpression>
+#include <QRegularExpressionMatch>
+
+GeopointFilter::GeopointFilter(QObject *parent, const QVariantList &args) :
+ AbstractMessageFilter(parent)
+{
+ Q_UNUSED(args)
+}
+
+void GeopointFilter::filterMessage(KTp::Message &message, const KTp::MessageContext&)
+{
+ static const QString linkTemplate = QStringLiteral("<a href=\"%1\">%1</a>");
+ static const QString mapTemplate = QStringLiteral(
+ "<iframe width=\"420\" height=\"350\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\""
+ "https://www.openlinkmap.org/small.php?lat=%1&lon=%2&zoom=%3\" "
+ "style=\"border: 1px solid black\" "
+ "frameborder=\"0\"></iframe>"
+ );
+
+ static const QRegularExpression geoTextExpression(QStringLiteral(
+ "geo:"
+ "(?<latitude>[\+\-]?\d{1,3}(\.[0-9]+)?),"
+ "(?<longitude>[\+\-]?\d{1,3}(\.[0-9]+)?)"
+ "(\?z=(?<zoom>\d+))?"));
+ QRegularExpressionMatch match;
+ QString messageText = message.mainMessagePart();
+ int index = 0;
+
+ while ((index = messageText.indexOf(geoTextExpression, index, &match)) >= 0) {
+ const double latitude = match.capturedRef(QStringLiteral("latitude")).toDouble();
+ const double longitude = match.capturedRef(QStringLiteral("longitude")).toDouble();
+
+ const QStringRef zoomStr = match.capturedRef(QStringLiteral("zoom"));
+
+ int zoom = 12;
+ if (!zoomStr.isNull()) {
+ zoom = zoomStr.toInt();
+ }
+
+ message.appendMessagePart(QStringLiteral("<br/>") + mapTemplate.arg(latitude).arg(longitude).arg(zoom));
+ messageText.replace(index, match.capturedLength(), linkTemplate.arg(match.captured()));
+
+ index = match.capturedEnd(QStringLiteral("longitude"));
+ // Shift the index by the length of added text: we added the second copy of "geo:..." text,
+ // plus the html code itself and minus the length of argument placeholders (%1 and %1).
+ index += match.capturedLength() + linkTemplate.length() - 4;
+ }
+
+ message.setMainMessagePart(messageText);
+}
+
+K_PLUGIN_FACTORY(MessageFilterFactory, registerPlugin<GeopointFilter>();)
+
+#include "geopoint-filter.moc"
diff --git a/filters/otr/otr-filter.h b/filters/geopoint/geopoint-filter.h
similarity index 70%
copy from filters/otr/otr-filter.h
copy to filters/geopoint/geopoint-filter.h
index e3cc36b..376f460 100644
--- a/filters/otr/otr-filter.h
+++ b/filters/geopoint/geopoint-filter.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 Marcin Ziemiński <zieminn at gmail.com>
+ * Copyright (C) 2016 Alexandr Akulich <akulichalexander at gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -16,18 +16,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef OTR_FILTER_H
-#define OTR_FILTER_H
+#ifndef GEOPOINT_FILTER_H
+#define GEOPOINT_FILTER_H
#include <KTp/abstract-message-filter.h>
-class OTRFilter : public KTp::AbstractMessageFilter
+class GeopointFilter : public KTp::AbstractMessageFilter
{
Q_OBJECT
-
public:
- OTRFilter(QObject *parent, const QVariantList &);
- virtual void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
+ GeopointFilter(QObject *parent, const QVariantList &args);
+ void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
};
-#endif // OTR_FILTER_H
+#endif // GEOPOINT_FILTER_H
diff --git a/filters/geopoint/ktptextui_message_filter_geopoint.desktop.cmake b/filters/geopoint/ktptextui_message_filter_geopoint.desktop.cmake
new file mode 100644
index 0000000..64658ba
--- /dev/null
+++ b/filters/geopoint/ktptextui_message_filter_geopoint.desktop.cmake
@@ -0,0 +1,17 @@
+[Desktop Entry]
+Encoding=UTF-8
+Type=Service
+ServiceTypes=KTpTextUi/MessageFilter
+
+X-KDE-Library=ktptextui_message_filter_geopoint
+X-KDE-PluginInfo-Author=Alexandr Akulich
+X-KDE-PluginInfo-Email=akulichalexander at gmail.com
+X-KDE-PluginInfo-Name=geopoint
+X-KDE-PluginInfo-Version=@KTP_TEXT_UI_VERSION@
+X-KDE-PluginInfo-Website=http://community.kde.org/KTp
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=false
+X-KTp-PluginInfo-Version=@KTP_MESSAGE_FILTER_FRAMEWORK_VERSION@
+
+Name=Geopoint Preview
+Comment=Show geo URI on a map view.
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list