[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:21:59 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=45664f1
The following commit has been merged in the master branch:
commit 45664f1255386599e0c36cd561cd0201b4b1872a
Author: Lasath Fernando <kde at lasath.org>
Date: Fri Jun 15 23:04:11 2012 +1000
Finally implement formatting plugin
It took me forever becuase of some annoying bug that was really
hard to find. (Turns out I was accidentally trying to match a
regex special character)
It also adds new tests.
---
filters/formatting/CMakeLists.txt | 28 ++++++++
filters/formatting/format-filter.cpp | 75 ++++++++++++++++++++++
.../formatting/format-filter.h | 26 ++++----
.../ktptextui_message_filter_formatting.desktop} | 4 +-
tests/message-processor-basic-tests.cpp | 11 +++-
tests/message-processor-basic-tests.h | 3 +-
6 files changed, 127 insertions(+), 20 deletions(-)
diff --git a/filters/formatting/CMakeLists.txt b/filters/formatting/CMakeLists.txt
new file mode 100644
index 0000000..11741f0
--- /dev/null
+++ b/filters/formatting/CMakeLists.txt
@@ -0,0 +1,28 @@
+set (ktptextui_message_filter_formatting_SRCS
+ format-filter.cpp
+)
+
+kde4_add_ui_files (ktptextui_message_filter_formatting_SRCS
+)
+
+kde4_add_plugin (ktptextui_message_filter_formatting
+ ${ktptextui_message_filter_formatting_SRCS}
+)
+
+target_link_libraries (ktptextui_message_filter_formatting
+ ktpchat
+ ${QT_LIBRARIES}
+ ${KDE4_KDEUI_LIBS}
+ ${TELEPATHY_QT4_LIBRARIES}
+ ${KDE4_KEMOTICONS_LIBS}
+)
+
+# Install:
+install (TARGETS ktptextui_message_filter_formatting
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
+
+install (FILES ktptextui_message_filter_formatting.desktop
+ DESTINATION ${SERVICES_INSTALL_DIR}
+)
+
diff --git a/filters/formatting/format-filter.cpp b/filters/formatting/format-filter.cpp
new file mode 100644
index 0000000..7cfa3b4
--- /dev/null
+++ b/filters/formatting/format-filter.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Lasath Fernando <kde at lasath.org>
+ *
+ * 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 "format-filter.h"
+
+#include <QRegExp>
+
+#include <KPluginFactory>
+#include <KDebug>
+
+typedef QPair<QRegExp, QString> FormatTag;
+
+class FormatFilter::Private {
+public:
+ QList<FormatTag> tags;
+};
+
+FormatFilter::FormatFilter (QObject* parent, const QVariantList&) :
+ AbstractMessageFilter (parent), d(new Private())
+{
+ addTag("_", 'i');
+ addTag("\*", 'b');
+ addTag("-", 's');
+}
+
+void FormatFilter::filterMessage (Message& message)
+{
+ Q_FOREACH(FormatTag tag, d->tags) {
+ QString msg = message.mainMessagePart();
+
+ msg = msg.replace(tag.first, tag.second);
+ message.setMainMessagePart(msg);
+ }
+}
+
+
+void FormatFilter::addTag (const char *markingCharacter, char htmlTag)
+{
+ QString pattern = QLatin1String("%1(\S.*\S)%1");
+ pattern = pattern.arg(QLatin1String(markingCharacter));
+
+ QString repl = QLatin1String("<%1>\1</%1>");
+ repl = repl.arg(htmlTag);
+
+ QRegExp exp = QRegExp(pattern);
+ exp.setMinimal(true);
+
+ d->tags.append(FormatTag(exp, repl));
+
+ QString singleCharPattern = QLatin1String("%1(\S)%1");
+ singleCharPattern = singleCharPattern.arg(QLatin1String(markingCharacter));
+
+ QRegExp singleCharExp = QRegExp(singleCharPattern);
+ singleCharExp.setMinimal(true);
+
+ d->tags.append(FormatTag(singleCharExp, repl));
+}
+
+K_PLUGIN_FACTORY(MessageFilterFactory, registerPlugin<FormatFilter>();)
+K_EXPORT_PLUGIN(MessageFilterFactory("ktptextui_formatting_filter_escape"))
\ No newline at end of file
diff --git a/tests/sync-processor.h b/filters/formatting/format-filter.h
similarity index 67%
copy from tests/sync-processor.h
copy to filters/formatting/format-filter.h
index 7ae999e..f3d8387 100644
--- a/tests/sync-processor.h
+++ b/filters/formatting/format-filter.h
@@ -16,25 +16,23 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef SYNC_PROCESSOR_H
-#define SYNC_PROCESSOR_H
+#ifndef FORMAT_FILTER_H
+#define FORMAT_FILTER_H
+#include <KTp/AbstractMessageFilter>
-#include <message-processor.h>
-
-class SyncProcessor
+class FormatFilter : public AbstractMessageFilter
{
+Q_OBJECT
public:
- SyncProcessor();
- ~SyncProcessor();
-
- Message processIncommingMessage(const Tp::ReceivedMessage& message);
- Message processOutGoingMessage ( Tp::Message message );
- QString getProcessedMessage ( const char* contents );
+ FormatFilter (QObject* parent, const QVariantList &);
+ virtual void filterMessage (Message& message);
private:
- class SyncProcessorPrivate;
- SyncProcessorPrivate *d;
+ void addTag (const char *markingCharacter, char htmlTag);
+
+ class Private;
+ Private *d;
};
-#endif // SYNC_PROCESSOR_H
+#endif // FORMAT_FILTER_H
diff --git a/filters/emoticons/ktptextui_message_filter_emoticons.desktop b/filters/formatting/ktptextui_message_filter_formatting.desktop
similarity index 81%
copy from filters/emoticons/ktptextui_message_filter_emoticons.desktop
copy to filters/formatting/ktptextui_message_filter_formatting.desktop
index 9bff5a5..854bc50 100644
--- a/filters/emoticons/ktptextui_message_filter_emoticons.desktop
+++ b/filters/formatting/ktptextui_message_filter_formatting.desktop
@@ -4,10 +4,10 @@ Comment=//TODO:.
Type=Service
ServiceTypes=KTpTextUi/MessageFilter
-X-KDE-Library=ktptextui_message_filter_emoticons
+X-KDE-Library=ktptextui_message_filter_formatting
X-KDE-PluginInfo-Author=Lasath Fernando
X-KDE-PluginInfo-Email=kde at lasath.org
-X-KDE-PluginInfo-Name=emoticons
+X-KDE-PluginInfo-Name=formatting
X-KDE-PluginInfo-Version=0.3
X-KDE-PluginInfo-Website=http://community.kde.org/Real-Time_Communication_and_Collaboration
X-KDE-PluginInfo-License=GPL
diff --git a/tests/message-processor-basic-tests.cpp b/tests/message-processor-basic-tests.cpp
index 14d4615..3abfff4 100644
--- a/tests/message-processor-basic-tests.cpp
+++ b/tests/message-processor-basic-tests.cpp
@@ -96,15 +96,20 @@ void MessageProcessorBasicTests::compare(const char *input, const char *expected
QCOMPARE(processed, href);
}
+void MessageProcessorBasicTests::testSingleCharBold()
+{
+ compare("*b*", "<b>b</b>");
+}
+
void MessageProcessorBasicTests::testBold()
{
- compare("**b**", "<b>b</b>");
+ compare("*this* shoudl *be in bold*", "<b>this</b> shoudl <b>be in bold</b>");
}
void MessageProcessorBasicTests::testBoldItalics()
{
- compare("_*this is bold italics_*", "<i><b>this is bold italics</b></i>");
- compare("_*this is bold italics*_", "<i><b>this is bold italics</i></b>");
+ compare("_*this is bold italics*_", "<i><b>this is bold italics</b></i>");
+ compare("_*this is bold italics_*", "<i><b>this is bold italics</i></b>");
}
void MessageProcessorBasicTests::testMultiWordItalics()
diff --git a/tests/message-processor-basic-tests.h b/tests/message-processor-basic-tests.h
index 8b09fda..12a85dd 100644
--- a/tests/message-processor-basic-tests.h
+++ b/tests/message-processor-basic-tests.h
@@ -42,9 +42,10 @@ private Q_SLOTS:
void testMultipleURLCatching();
void testSingleWordItalics();
void testMultiWordItalics();
- void testBold();
+ void testSingleCharBold();
void testBoldItalics();
void testStrikethrough();
+ void testBold();
};
#endif // MESSAGE_PROCESSOR_BASIC_TESTS_H
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list