summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Montel <[email protected]>2017-12-27 07:26:30 +0100
committerLaurent Montel <[email protected]>2017-12-27 07:26:30 +0100
commit01fbec78d698efcd16f164e159646401d36f69d7 (patch)
tree6c46ae32a17e1906e072d0e13080269c8dedc1f5
parent5afd06bca6b0f901681c89f2186931c40168a3ef (diff)
initialize plugin
-rw-r--r--kmail/editorplugins/insertshorturl/CMakeLists.txt5
-rw-r--r--kmail/editorplugins/insertshorturl/autotests/CMakeLists.txt2
-rw-r--r--kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.cpp66
-rw-r--r--kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.h7
-rw-r--r--kmail/editorplugins/insertshorturl/shorturlengineplugin/shorturlenginepluginmanager.h3
5 files changed, 79 insertions, 4 deletions
diff --git a/kmail/editorplugins/insertshorturl/CMakeLists.txt b/kmail/editorplugins/insertshorturl/CMakeLists.txt
index 0360530..09e7406 100644
--- a/kmail/editorplugins/insertshorturl/CMakeLists.txt
+++ b/kmail/editorplugins/insertshorturl/CMakeLists.txt
@@ -1,6 +1,7 @@
set(shorturlpluginprivate_SRCS
shorturlengineplugin/shorturlengineinterface.cpp
shorturlengineplugin/shorturlengineplugin.cpp
+ shorturlengineplugin/shorturlenginepluginmanager.cpp
)
@@ -9,7 +10,7 @@ generate_export_header(shorturlpluginprivate BASE_NAME shorturl)
target_link_libraries(shorturlpluginprivate
PRIVATE
- Qt5::Network KF5::I18n
+ Qt5::Network KF5::I18n KF5::CoreAddons
)
set_target_properties(shorturlpluginprivate
@@ -34,7 +35,7 @@ kcoreaddons_add_plugin(kmail_insertshorturleditorplugin JSON kmail_insertshortur
${kmail_insertshorturleditorplugin_SRCS} INSTALL_NAMESPACE kmail)
target_link_libraries(kmail_insertshorturleditorplugin
- KF5::IconThemes KF5::MessageComposer KF5::XmlGui KF5::I18n shorturlpluginprivate
+ KF5::IconThemes KF5::MessageComposer KF5::XmlGui KF5::I18n shorturlpluginprivate KF5::CoreAddons
)
if(BUILD_TESTING)
diff --git a/kmail/editorplugins/insertshorturl/autotests/CMakeLists.txt b/kmail/editorplugins/insertshorturl/autotests/CMakeLists.txt
index a74200b..0d25c03 100644
--- a/kmail/editorplugins/insertshorturl/autotests/CMakeLists.txt
+++ b/kmail/editorplugins/insertshorturl/autotests/CMakeLists.txt
@@ -5,7 +5,7 @@ macro(add_kmail_editorplugin_unittest _source _additional)
add_test(NAME ${_name} COMMAND ${_name} )
ecm_mark_as_test(kmail_editorplugin-${_name})
- target_link_libraries( ${_name} Qt5::Test KF5::XmlGui KF5::IconThemes KF5::MessageComposer KF5::I18n)
+ target_link_libraries( ${_name} Qt5::Test KF5::XmlGui KF5::IconThemes KF5::MessageComposer KF5::I18n shorturlpluginprivate)
endmacro ()
add_kmail_editorplugin_unittest(insertshorturlplugineditortest.cpp
diff --git a/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.cpp b/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.cpp
index c69a7c5..95c04e0 100644
--- a/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.cpp
+++ b/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.cpp
@@ -22,16 +22,55 @@
#include <KLocalizedString>
#include <KActionCollection>
#include <QAction>
+#include <KSharedConfig>
+#include <KSharedConfig>
+#include <KConfigGroup>
+#include "shorturlengineplugin/shorturlengineinterface.h"
+#include "shorturlengineplugin/shorturlengineplugin.h"
+#include "shorturlengineplugin/shorturlenginepluginmanager.h"
InsertShorturlPluginEditorInterface::InsertShorturlPluginEditorInterface(QObject *parent)
: MessageComposer::PluginEditorInterface(parent)
{
+ initializePlugins();
}
InsertShorturlPluginEditorInterface::~InsertShorturlPluginEditorInterface()
{
}
+void InsertShorturlPluginEditorInterface::initializePlugins()
+{
+ const QVector<ShortUrlEnginePlugin *> lstPlugin = ShortUrlEnginePluginManager::self()->pluginsList();
+ for (ShortUrlEnginePlugin *plugin : lstPlugin) {
+ ShortUrlEngineInterface *interface = plugin->createInterface(this);
+ if (interface) {
+ mLstInterface.insert(interface->engineName(), interface);
+ }
+ }
+}
+
+void InsertShorturlPluginEditorInterface::loadEngine()
+{
+ if (mCurrentEngine) {
+ disconnect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlGenerated, this, &InsertShorturlPluginEditorInterface::slotShortUrlDone);
+ disconnect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlFailed, this, &InsertShorturlPluginEditorInterface::slotShortUrlFailed);
+ }
+
+ KConfigGroup grp(KSharedConfig::openConfig(), "ShortUrl");
+ const QString engineName = grp.readEntry("EngineName");
+ mCurrentEngine = mLstInterface.value(engineName);
+ if (!mCurrentEngine && !mLstInterface.isEmpty()) {
+ mCurrentEngine = mLstInterface.cbegin().value();
+ }
+
+ if (mCurrentEngine) {
+ connect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlGenerated, this, &InsertShorturlPluginEditorInterface::slotShortUrlDone);
+ connect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlFailed, this, &InsertShorturlPluginEditorInterface::slotShortUrlFailed);
+ }
+}
+
+
void InsertShorturlPluginEditorInterface::createAction(KActionCollection *ac)
{
QAction *action = new QAction(i18n("Insert Short Url..."), this);
@@ -52,9 +91,36 @@ void InsertShorturlPluginEditorInterface::exec()
if (textCursor.hasSelection()) {
QString urlStr = textCursor.selectedText();
if (urlStr.startsWith(QLatin1String("http:")) || urlStr.startsWith(QLatin1String("https:"))) {
+ /*
+ if (!mCurrentEngine) {
+ return;
+ }
+ if (!PimCommon::NetworkManager::self()->networkConfigureManager()->isOnline()) {
+ KMessageBox::information(this, i18n("No network connection detected, we cannot shorten URL."), i18n("No network"));
+ return;
+ }
+ if (mOriginalUrl->text().isEmpty()) {
+ return;
+ }
+ mIndicatorLabel->start();
+ mCurrentEngine->setShortUrl(mOriginalUrl->text());
+ mShortUrl->clear();
+ mCurrentEngine->generateShortUrl();
+ */
//textCursor.insertText(newText);
}
}
//editorUtil.upperCase(textCursor);
}
+void InsertShorturlPluginEditorInterface::slotShortUrlDone(const QString &url)
+{
+ //mIndicatorLabel->stop();
+}
+
+void InsertShorturlPluginEditorInterface::slotShortUrlFailed(const QString &errMsg)
+{
+ //KMessageBox::error(this, i18n("An error occurred: \"%1\"", errMsg));
+ //mIndicatorLabel->stop();
+}
+
diff --git a/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.h b/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.h
index 3db4789..c697a55 100644
--- a/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.h
+++ b/kmail/editorplugins/insertshorturl/insertshorturlplugineditorinterface.h
@@ -23,6 +23,7 @@
#include <messagecomposer/plugineditorinterface.h>
#include <QPointer>
class SelectMailDialog;
+class ShortUrlEngineInterface;
class InsertShorturlPluginEditorInterface : public MessageComposer::PluginEditorInterface
{
Q_OBJECT
@@ -34,7 +35,13 @@ public:
void exec() override;
private:
+ void initializePlugins();
void slotActivated();
+ void loadEngine();
+ void slotShortUrlDone(const QString &url);
+ void slotShortUrlFailed(const QString &errMsg);
+ QHash<QString, ShortUrlEngineInterface *> mLstInterface;
+ ShortUrlEngineInterface *mCurrentEngine = nullptr;
};
#endif
diff --git a/kmail/editorplugins/insertshorturl/shorturlengineplugin/shorturlenginepluginmanager.h b/kmail/editorplugins/insertshorturl/shorturlengineplugin/shorturlenginepluginmanager.h
index 68f0401..4f78b01 100644
--- a/kmail/editorplugins/insertshorturl/shorturlengineplugin/shorturlenginepluginmanager.h
+++ b/kmail/editorplugins/insertshorturl/shorturlengineplugin/shorturlenginepluginmanager.h
@@ -21,9 +21,10 @@
#define SHORTURLENGINEPLUGINMANAGER_H
#include <QObject>
+#include "shorturl_export.h"
class ShortUrlEnginePlugin;
class ShortUrlEnginePluginManagerPrivate;
-class ShortUrlEnginePluginManager : public QObject
+class SHORTURL_EXPORT ShortUrlEnginePluginManager : public QObject
{
Q_OBJECT
public: