Commit 01fbec78 authored by Laurent Montel's avatar Laurent Montel 😁

initialize plugin

parent 5afd06bc
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)
......
......@@ -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
......
......@@ -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();
}
......@@ -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
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment