summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-08-08 06:00:28 (GMT)
committerMontel Laurent <montel@kde.org>2016-08-08 06:00:28 (GMT)
commit75191ad8695117bb586919ead4e3e5dea28ddf44 (patch)
tree3ea0db1acb729c4232ea2562f4e34e8cac607ada
parent2ab4a3e4c01a7f7ca61e7aa1d90f469c549dedf5 (diff)
Add insert breaking space as plugin
-rw-r--r--kmail/editorplugins/CMakeLists.txt1
-rw-r--r--kmail/editorplugins/nonbreakingspace/CMakeLists.txt17
-rw-r--r--kmail/editorplugins/nonbreakingspace/autotests/CMakeLists.txt13
-rw-r--r--kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.cpp43
-rw-r--r--kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.h35
-rw-r--r--kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.cpp42
-rw-r--r--kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.h35
-rw-r--r--kmail/editorplugins/nonbreakingspace/kmail_nonbreakingspaceeditorplugin.json10
-rw-r--r--kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.cpp43
-rw-r--r--kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.h38
-rw-r--r--kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.cpp54
-rw-r--r--kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.h40
12 files changed, 371 insertions, 0 deletions
diff --git a/kmail/editorplugins/CMakeLists.txt b/kmail/editorplugins/CMakeLists.txt
index 1b953f0..1c1e87f 100644
--- a/kmail/editorplugins/CMakeLists.txt
+++ b/kmail/editorplugins/CMakeLists.txt
@@ -2,3 +2,4 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kmail_editor_plugins\")
add_subdirectory(insertspecialcharacter)
add_subdirectory(changecase)
add_subdirectory(zoomtext)
+add_subdirectory(nonbreakingspace)
diff --git a/kmail/editorplugins/nonbreakingspace/CMakeLists.txt b/kmail/editorplugins/nonbreakingspace/CMakeLists.txt
new file mode 100644
index 0000000..1eca397
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/CMakeLists.txt
@@ -0,0 +1,17 @@
+set(kmail_nonbreakingspaceeditorplugin_SRCS
+ nonbreakingspaceplugineditor.cpp
+ nonbreakingspaceplugineditorinterface.cpp
+)
+
+add_library(kmail_nonbreakingspaceeditorplugin MODULE ${kmail_nonbreakingspaceeditorplugin_SRCS})
+
+target_link_libraries(kmail_nonbreakingspaceeditorplugin
+ KF5::IconThemes KF5::MessageComposer KF5::XmlGui KF5::I18n
+)
+
+install(TARGETS kmail_nonbreakingspaceeditorplugin DESTINATION ${PLUGIN_INSTALL_DIR}/kmail)
+
+if(BUILD_TESTING)
+ add_subdirectory(autotests)
+endif()
+
diff --git a/kmail/editorplugins/nonbreakingspace/autotests/CMakeLists.txt b/kmail/editorplugins/nonbreakingspace/autotests/CMakeLists.txt
new file mode 100644
index 0000000..5768092
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/autotests/CMakeLists.txt
@@ -0,0 +1,13 @@
+macro(add_kmail_editorplugin_unittest _source _additional)
+ set( _test ${_source} ${_additional})
+ get_filename_component(_name ${_source} NAME_WE)
+ add_executable( ${_name} ${_test} )
+ add_test( ${_name} ${_name} )
+
+ ecm_mark_as_test(kmail_editorplugin-${_name})
+ target_link_libraries( ${_name} Qt5::Test KF5::XmlGui KF5::IconThemes KF5::MessageComposer KF5::I18n)
+endmacro ()
+
+add_kmail_editorplugin_unittest(nonbreakingspaceplugineditortest.cpp "../nonbreakingspaceplugineditor.cpp;../nonbreakingspaceplugineditorinterface.cpp")
+
+add_kmail_editorplugin_unittest(nonbreakingspaceplugineditorinterfacetest.cpp "../nonbreakingspaceplugineditorinterface.cpp")
diff --git a/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.cpp b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.cpp
new file mode 100644
index 0000000..f7eef32
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.cpp
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "nonbreakingspaceplugineditorinterfacetest.h"
+#include "../nonbreakingspaceplugineditorinterface.h"
+#include <QTest>
+
+NonBreakingSpacePluginEditorInterfaceTest::NonBreakingSpacePluginEditorInterfaceTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+NonBreakingSpacePluginEditorInterfaceTest::~NonBreakingSpacePluginEditorInterfaceTest()
+{
+
+}
+
+void NonBreakingSpacePluginEditorInterfaceTest::shouldHaveDefaultValue()
+{
+ NonBreakingSpacePluginEditorInterface interface;
+ QVERIFY(!interface.hasConfigureDialog());
+ QVERIFY(!interface.hasPopupMenuSupport());
+ QVERIFY(!interface.hasToolBarSupport());
+}
+
+QTEST_MAIN(NonBreakingSpacePluginEditorInterfaceTest)
diff --git a/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.h b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.h
new file mode 100644
index 0000000..2092e2a
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditorinterfacetest.h
@@ -0,0 +1,35 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef NonBreakingSpacePLUGINEDITORINTERFACETEST_H
+#define NonBreakingSpacePLUGINEDITORINTERFACETEST_H
+
+#include <QObject>
+
+class NonBreakingSpacePluginEditorInterfaceTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit NonBreakingSpacePluginEditorInterfaceTest(QObject *parent = Q_NULLPTR);
+ ~NonBreakingSpacePluginEditorInterfaceTest();
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+};
+
+#endif
diff --git a/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.cpp b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.cpp
new file mode 100644
index 0000000..d1e0199
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.cpp
@@ -0,0 +1,42 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "nonbreakingspaceplugineditortest.h"
+#include "../nonbreakingspaceplugineditor.h"
+#include <KActionCollection>
+#include <QTest>
+
+NonBreakingSpacePluginEditorTest::NonBreakingSpacePluginEditorTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+NonBreakingSpacePluginEditorTest::~NonBreakingSpacePluginEditorTest()
+{
+
+}
+
+void NonBreakingSpacePluginEditorTest::shouldHaveDefaultValue()
+{
+ NonBreakingSpacePluginEditor plugin;
+ QVERIFY(plugin.createInterface(new KActionCollection(this)));
+}
+
+QTEST_MAIN(NonBreakingSpacePluginEditorTest)
diff --git a/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.h b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.h
new file mode 100644
index 0000000..ac918f8
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/autotests/nonbreakingspaceplugineditortest.h
@@ -0,0 +1,35 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef NonBreakingSpacePLUGINEDITORTEST_H
+#define NonBreakingSpacePLUGINEDITORTEST_H
+
+#include <QObject>
+
+class NonBreakingSpacePluginEditorTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit NonBreakingSpacePluginEditorTest(QObject *parent = Q_NULLPTR);
+ ~NonBreakingSpacePluginEditorTest();
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+};
+
+#endif
diff --git a/kmail/editorplugins/nonbreakingspace/kmail_nonbreakingspaceeditorplugin.json b/kmail/editorplugins/nonbreakingspace/kmail_nonbreakingspaceeditorplugin.json
new file mode 100644
index 0000000..943a206
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/kmail_nonbreakingspaceeditorplugin.json
@@ -0,0 +1,10 @@
+{
+ "KPlugin": {
+ "Name": "Insert Non Braking Space",
+ "ServiceTypes": [
+ "KMailEditor/Plugin"
+ ],
+ "Version": "1.0"
+ },
+ "X-KDE-KMailEditor-Order": "2"
+}
diff --git a/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.cpp b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.cpp
new file mode 100644
index 0000000..f46a8ec
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.cpp
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "nonbreakingspaceplugineditor.h"
+#include "nonbreakingspaceplugineditorinterface.h"
+#include <kpluginfactory.h>
+
+K_PLUGIN_FACTORY_WITH_JSON(NonBreakingSpacePluginEditorFactory, "kmail_nonbreakingspaceeditorplugin.json", registerPlugin<NonBreakingSpacePluginEditor>();)
+
+NonBreakingSpacePluginEditor::NonBreakingSpacePluginEditor(QObject *parent, const QList<QVariant> &)
+ : MessageComposer::PluginEditor(parent)
+{
+}
+
+NonBreakingSpacePluginEditor::~NonBreakingSpacePluginEditor()
+{
+
+}
+
+MessageComposer::PluginEditorInterface *NonBreakingSpacePluginEditor::createInterface(KActionCollection *ac, QObject *parent)
+{
+ NonBreakingSpacePluginEditorInterface *interface = new NonBreakingSpacePluginEditorInterface(parent);
+ interface->createAction(ac);
+ return interface;
+}
+
+#include "nonbreakingspaceplugineditor.moc"
diff --git a/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.h b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.h
new file mode 100644
index 0000000..071dcd5
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditor.h
@@ -0,0 +1,38 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef NONBREAKINGSPACEPLUGINEDITOR_H
+#define NONBREAKINGSPACEPLUGINEDITOR_H
+
+#include <messagecomposer/plugineditor.h>
+
+#include <messagecomposer/plugineditorinterface.h>
+#include <QVariant>
+
+class NonBreakingSpacePluginEditor : public MessageComposer::PluginEditor
+{
+ Q_OBJECT
+public:
+ explicit NonBreakingSpacePluginEditor(QObject *parent = Q_NULLPTR, const QList<QVariant> & = QList<QVariant>());
+ ~NonBreakingSpacePluginEditor();
+
+ MessageComposer::PluginEditorInterface *createInterface(KActionCollection *ac, QObject *parent = Q_NULLPTR) Q_DECL_OVERRIDE;
+};
+
+#endif
diff --git a/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.cpp b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.cpp
new file mode 100644
index 0000000..5d3889e
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.cpp
@@ -0,0 +1,54 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "nonbreakingspaceplugineditorinterface.h"
+#include <KPIMTextEdit/RichTextEditor>
+#include <KLocalizedString>
+#include <KActionCollection>
+#include <QAction>
+#include <QDebug>
+NonBreakingSpacePluginEditorInterface::NonBreakingSpacePluginEditorInterface(QObject *parent)
+ : MessageComposer::PluginEditorInterface(parent)
+{
+}
+
+NonBreakingSpacePluginEditorInterface::~NonBreakingSpacePluginEditorInterface()
+{
+
+}
+
+void NonBreakingSpacePluginEditorInterface::createAction(KActionCollection *ac)
+{
+ QAction *action = new QAction(i18n("Insert Non Breaking Space"), this);
+ ac->addAction(QStringLiteral("insert_non_breaking_space"), action);
+ ac->setDefaultShortcut(action, Qt::CTRL + Qt::Key_Space);
+ connect(action, &QAction::triggered, this, &NonBreakingSpacePluginEditorInterface::slotActivated);
+ MessageComposer::ActionType type(action, MessageComposer::ActionType::Edit);
+ setActionType(type);
+}
+
+void NonBreakingSpacePluginEditorInterface::slotActivated()
+{
+ Q_EMIT emitPluginActivated(this);
+}
+
+void NonBreakingSpacePluginEditorInterface::exec()
+{
+ richTextEditor()->insertPlainText(QChar(0x000A0));
+}
diff --git a/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.h b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.h
new file mode 100644
index 0000000..cb0ac5d
--- /dev/null
+++ b/kmail/editorplugins/nonbreakingspace/nonbreakingspaceplugineditorinterface.h
@@ -0,0 +1,40 @@
+/*
+ Copyright (C) 2016 Montel Laurent <montel@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; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef NONBREAKINGSPACEPLUGINEDITORINTERFACE_H
+#define NONBREAKINGSPACEPLUGINEDITORINTERFACE_H
+
+#include <messagecomposer/plugineditorinterface.h>
+#include <QPointer>
+
+class NonBreakingSpacePluginEditorInterface : public MessageComposer::PluginEditorInterface
+{
+ Q_OBJECT
+public:
+ explicit NonBreakingSpacePluginEditorInterface(QObject *parent = Q_NULLPTR);
+ ~NonBreakingSpacePluginEditorInterface();
+
+ void createAction(KActionCollection *ac) Q_DECL_OVERRIDE;
+ void exec() Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+ void slotActivated();
+};
+
+#endif