summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-10-06 13:34:27 +0200
committerMontel Laurent <[email protected]>2015-10-06 13:59:16 +0200
commit761be70dc116145afbbc8b6df11a539a1640e7f9 (patch)
tree9dfaa815b16068a4dd27301b5e017b857ea9df04
parentd55ee514c3dbd702dda0c862db463c1ed86dd265 (diff)
Fix api. Add triopabshorturl engine
-rw-r--r--pimcommon/src/customtools/shorturlplugin/CMakeLists.txt1
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.cpp5
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.h1
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.cpp5
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.h1
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.cpp12
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.h2
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.cpp13
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.h1
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/CMakeLists.txt14
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/pimcommon_triopabshorturlengineplugin.desktop4
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.cpp53
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.h40
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.cpp47
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.h39
15 files changed, 211 insertions, 27 deletions
diff --git a/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt b/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt
index f2b4d00..c8e9373 100644
--- a/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt
+++ b/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt
@@ -35,3 +35,4 @@ endif()
add_subdirectory(shorturl/shorturlengineplugin/tinyurlengineplugin/)
add_subdirectory(shorturl/shorturlengineplugin/googleshorturlengineplugin)
add_subdirectory(shorturl/shorturlengineplugin/isgdshorturlengineplugin)
+add_subdirectory(shorturl/shorturlengineplugin/triopabshorturlengineplugin/)
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.cpp
index 2c3ad62..e23350f 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.cpp
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.cpp
@@ -30,11 +30,6 @@ GoogleShortUrlEngineInterface::~GoogleShortUrlEngineInterface()
}
-void GoogleShortUrlEngineInterface::setShortUrl(const QString &url)
-{
-
-}
-
void GoogleShortUrlEngineInterface::generateShortUrl()
{
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.h
index 6ee3475..c8e03b5 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.h
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/googleshorturlengineplugin/googleshorturlengineinterface.h
@@ -28,7 +28,6 @@ public:
explicit GoogleShortUrlEngineInterface(QObject *parent = Q_NULLPTR);
~GoogleShortUrlEngineInterface();
- void setShortUrl(const QString &url) Q_DECL_OVERRIDE;
void generateShortUrl() Q_DECL_OVERRIDE;
};
}
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.cpp
index 875aa53..6a76873 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.cpp
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.cpp
@@ -34,11 +34,6 @@ IsgdShortUrlEngineInterface::~IsgdShortUrlEngineInterface()
}
-void IsgdShortUrlEngineInterface::setShortUrl(const QString &url)
-{
-
-}
-
void IsgdShortUrlEngineInterface::generateShortUrl()
{
const QString requestUrl = QStringLiteral("http://is.gd/create.php?%1&url=%2").arg(QStringLiteral("format=json")).arg(mOriginalUrl);
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.h
index 6f7349a..1ff75fd 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.h
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/isgdshorturlengineplugin/isgdshorturlengineinterface.h
@@ -30,7 +30,6 @@ public:
explicit IsgdShortUrlEngineInterface(QObject *parent = Q_NULLPTR);
~IsgdShortUrlEngineInterface();
- void setShortUrl(const QString &url) Q_DECL_OVERRIDE;
void generateShortUrl() Q_DECL_OVERRIDE;
private Q_SLOTS:
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.cpp
index 50bfa9d..562672d 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.cpp
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.cpp
@@ -43,3 +43,15 @@ void ShortUrlEngineInterface::slotErrorFound(QNetworkReply::NetworkError error)
Q_EMIT shortUrlFailed(i18n("Error reported by server:\n\'%1\'", (reply ? reply->errorString() : QString::number(error))));
}
+void ShortUrlEngineInterface::setShortUrl(const QString &url)
+{
+ mErrorFound = false;
+ if (!url.trimmed().startsWith(QStringLiteral("http://")) &&
+ !url.trimmed().startsWith(QStringLiteral("https://")) &&
+ !url.trimmed().startsWith(QStringLiteral("ftp://")) &&
+ !url.trimmed().startsWith(QStringLiteral("ftps://"))) {
+ mOriginalUrl = QLatin1String("http://") + url;
+ } else {
+ mOriginalUrl = url;
+ }
+}
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.h
index a82e751..f21a9c8 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.h
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/shorturlengineinterface.h
@@ -31,7 +31,7 @@ public:
explicit ShortUrlEngineInterface(QObject *parent = Q_NULLPTR);
~ShortUrlEngineInterface();
- virtual void setShortUrl(const QString &url) = 0;
+ void setShortUrl(const QString &url);
virtual void generateShortUrl() = 0;
protected Q_SLOTS:
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.cpp
index 5bb53dc..7e7560d 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.cpp
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.cpp
@@ -33,19 +33,6 @@ TinyUrlEngineInterface::~TinyUrlEngineInterface()
}
-void TinyUrlEngineInterface::setShortUrl(const QString &url)
-{
- mErrorFound = false;
- if (!url.trimmed().startsWith(QStringLiteral("http://")) &&
- !url.trimmed().startsWith(QStringLiteral("https://")) &&
- !url.trimmed().startsWith(QStringLiteral("ftp://")) &&
- !url.trimmed().startsWith(QStringLiteral("ftps://"))) {
- mOriginalUrl = QLatin1String("http://") + url;
- } else {
- mOriginalUrl = url;
- }
-}
-
void TinyUrlEngineInterface::generateShortUrl()
{
const QString requestUrl = QStringLiteral("http://tinyurl.com/api-create.php?url=%1").arg(mOriginalUrl);
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.h
index 8ec8e27..c252e9d 100644
--- a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.h
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/tinyurlengineplugin/tinyurlengineinterface.h
@@ -29,7 +29,6 @@ public:
explicit TinyUrlEngineInterface(QObject *parent = Q_NULLPTR);
~TinyUrlEngineInterface();
- void setShortUrl(const QString &url) Q_DECL_OVERRIDE;
void generateShortUrl() Q_DECL_OVERRIDE;
private Q_SLOTS:
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/CMakeLists.txt b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/CMakeLists.txt
new file mode 100644
index 0000000..abbb66c
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(pimcommon_triopabshorturlengineplugin_SRCS
+ triopabshorturlengineplugin.cpp
+ triopabshorturlengineinterface.cpp
+)
+
+add_library(pimcommon_triopabshorturlengineplugin MODULE ${pimcommon_triopabshorturlengineplugin_SRCS})
+
+target_link_libraries(pimcommon_triopabshorturlengineplugin
+ KF5::PimCommon
+)
+
+install(TARGETS pimcommon_triopabshorturlengineplugin DESTINATION ${PLUGIN_INSTALL_DIR}/pimcommon)
+kcoreaddons_desktop_to_json(pimcommon_triopabshorturlengineplugin pimcommon_triopabshorturlengineplugin.desktop)
+
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/pimcommon_triopabshorturlengineplugin.desktop b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/pimcommon_triopabshorturlengineplugin.desktop
new file mode 100644
index 0000000..82948fd
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/pimcommon_triopabshorturlengineplugin.desktop
@@ -0,0 +1,4 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=PimCommonShortUrlEngine/Plugin
+X-KDE-Library=pimcommon_triopabshorturlengineplugin
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.cpp
new file mode 100644
index 0000000..4236eb7
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.cpp
@@ -0,0 +1,53 @@
+/*
+ Copyright (c) 2015 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "triopabshorturlengineinterface.h"
+
+#include <QJsonDocument>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+
+using namespace PimCommon;
+
+TripAbShortUrlEngineInterface::TripAbShortUrlEngineInterface(QObject *parent)
+ : PimCommon::ShortUrlEngineInterface(parent)
+{
+
+}
+
+TripAbShortUrlEngineInterface::~TripAbShortUrlEngineInterface()
+{
+
+}
+
+void TripAbShortUrlEngineInterface::generateShortUrl()
+{
+ const QString requestUrl = QStringLiteral("http://to.ly/api.php?longurl=%1").arg(mOriginalUrl);
+ QNetworkReply *reply = mNetworkAccessManager->get(QNetworkRequest(QUrl(requestUrl)));
+ connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &TripAbShortUrlEngineInterface::slotErrorFound);
+}
+
+void TripAbShortUrlEngineInterface::slotShortUrlFinished(QNetworkReply *reply)
+{
+ if (!mErrorFound) {
+ const QString data = QString::fromUtf8(reply->readAll());
+ if (!data.isEmpty()) {
+ Q_EMIT shortUrlGenerated(data);
+ }
+ }
+ reply->deleteLater();
+}
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.h
new file mode 100644
index 0000000..09177ef
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineinterface.h
@@ -0,0 +1,40 @@
+/*
+ Copyright (c) 2015 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef TRIOPABSHORTURLENGINEINTERFACE_H
+#define TRIOPABSHORTURLENGINEINTERFACE_H
+
+#include <pimcommon/shorturlengineinterface.h>
+
+#include <QSslError>
+class QNetworkReply;
+namespace PimCommon
+{
+class TripAbShortUrlEngineInterface : public PimCommon::ShortUrlEngineInterface
+{
+public:
+ explicit TripAbShortUrlEngineInterface(QObject *parent = Q_NULLPTR);
+ ~TripAbShortUrlEngineInterface();
+
+ void generateShortUrl() Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+ void slotShortUrlFinished(QNetworkReply *reply);
+};
+}
+
+#endif
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.cpp
new file mode 100644
index 0000000..624e111
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.cpp
@@ -0,0 +1,47 @@
+/*
+ Copyright (c) 2015 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "triopabshorturlengineplugin.h"
+#include "triopabshorturlengineinterface.h"
+#include <kpluginfactory.h>
+
+using namespace PimCommon;
+
+K_PLUGIN_FACTORY_WITH_JSON(TriopAbShortUrlEnginePluginFactory, "pimcommon_triopabshorturlengineplugin.json", registerPlugin<TriopAbShortUrlEnginePlugin>();)
+
+TriopAbShortUrlEnginePlugin::TriopAbShortUrlEnginePlugin(QObject *parent, const QList<QVariant> &)
+ : PimCommon::ShortUrlEnginePlugin(parent)
+{
+
+}
+
+TriopAbShortUrlEnginePlugin::~TriopAbShortUrlEnginePlugin()
+{
+
+}
+
+QString TriopAbShortUrlEnginePlugin::engineName() const
+{
+ return QStringLiteral("triopabshorturl");
+}
+
+PimCommon::ShortUrlEngineInterface *TriopAbShortUrlEnginePlugin::createInterface(QObject *parent)
+{
+ return new PimCommon::TripAbShortUrlEngineInterface(parent);
+}
+
+#include "triopabshorturlengineplugin.moc"
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.h
new file mode 100644
index 0000000..b92f423
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/triopabshorturlengineplugin/triopabshorturlengineplugin.h
@@ -0,0 +1,39 @@
+/*
+ Copyright (c) 2015 Montel Laurent <[email protected]>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ 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; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef ISGDSHORTURLENGINEPLUGIN_H
+#define ISGDSHORTURLENGINEPLUGIN_H
+
+#include "../shorturlengineplugin.h"
+
+#include <QVariant>
+
+namespace PimCommon
+{
+class TriopAbShortUrlEnginePlugin : public PimCommon::ShortUrlEnginePlugin
+{
+ Q_OBJECT
+public:
+ explicit TriopAbShortUrlEnginePlugin(QObject *parent = Q_NULLPTR, const QList<QVariant> & = QList<QVariant>());
+ ~TriopAbShortUrlEnginePlugin();
+
+ QString engineName() const Q_DECL_OVERRIDE;
+ ShortUrlEngineInterface *createInterface(QObject *parent) Q_DECL_OVERRIDE;
+};
+}
+
+#endif // ISGDSHORTURLENGINEPLUGIN_H