summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-10-07 07:31:05 +0200
committerMontel Laurent <[email protected]>2015-10-07 07:31:05 +0200
commit6c214c208de614b6ce787917f11bc6fb7d77fe3c (patch)
tree65388a8dd18d1ef01000c1c84265a1ada93632cc
parente515e32cce0eb2bab396317432249008694d246f (diff)
Add one new engine
-rw-r--r--pimcommon/src/customtools/shorturlplugin/CMakeLists.txt1
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/CMakeLists.txt14
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/pimcommon_ur1cashorturlengineplugin.desktop5
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/triopabshorturlengineplugin.cpp48
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/triopabshorturlengineplugin.h39
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.cpp81
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.h42
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.cpp48
-rw-r--r--pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.h39
9 files changed, 317 insertions, 0 deletions
diff --git a/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt b/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt
index 8a3aa09..803f4f2 100644
--- a/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt
+++ b/pimcommon/src/customtools/shorturlplugin/CMakeLists.txt
@@ -28,3 +28,4 @@ add_subdirectory(shorturl/shorturlengineplugin/tinyurlengineplugin/)
#add_subdirectory(shorturl/shorturlengineplugin/googleshorturlengineplugin)
add_subdirectory(shorturl/shorturlengineplugin/isgdshorturlengineplugin)
add_subdirectory(shorturl/shorturlengineplugin/triopabshorturlengineplugin/)
+add_subdirectory(shorturl/shorturlengineplugin/ur1cashorturlengineplugin/)
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/CMakeLists.txt b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/CMakeLists.txt
new file mode 100644
index 0000000..5ba4c08
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(pimcommon_ur1cashorturlengineplugin_SRCS
+ ur1cashorturlengineplugin.cpp
+ ur1cashorturlengineinterface.cpp
+)
+
+add_library(pimcommon_ur1cashorturlengineplugin MODULE ${pimcommon_ur1cashorturlengineplugin_SRCS})
+
+target_link_libraries(pimcommon_ur1cashorturlengineplugin
+ KF5::PimCommon
+)
+
+install(TARGETS pimcommon_ur1cashorturlengineplugin DESTINATION ${PLUGIN_INSTALL_DIR}/pimcommon)
+kcoreaddons_desktop_to_json(pimcommon_ur1cashorturlengineplugin pimcommon_ur1cashorturlengineplugin.desktop)
+
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/pimcommon_ur1cashorturlengineplugin.desktop b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/pimcommon_ur1cashorturlengineplugin.desktop
new file mode 100644
index 0000000..31d151c
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/pimcommon_ur1cashorturlengineplugin.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=PimCommonShortUrlEngine/Plugin
+X-KDE-Library=pimcommon_ur1cashorturlengineplugin
+Name=Ur1Ca
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/triopabshorturlengineplugin.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/triopabshorturlengineplugin.cpp
new file mode 100644
index 0000000..a69583e
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/triopabshorturlengineplugin.cpp
@@ -0,0 +1,48 @@
+/*
+ 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()
+{
+
+}
+
+PimCommon::ShortUrlEngineInterface *TriopAbShortUrlEnginePlugin::createInterface(QObject *parent)
+{
+ return new PimCommon::TripAbShortUrlEngineInterface(this, parent);
+}
+
+QString TriopAbShortUrlEnginePlugin::engineName() const
+{
+ return QStringLiteral("triopabshorturl");
+}
+
+
+#include "triopabshorturlengineplugin.moc"
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/triopabshorturlengineplugin.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/triopabshorturlengineplugin.h
new file mode 100644
index 0000000..660fd76
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/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();
+
+ ShortUrlEngineInterface *createInterface(QObject *parent) Q_DECL_OVERRIDE;
+ QString engineName() const Q_DECL_OVERRIDE;
+};
+}
+
+#endif // ISGDSHORTURLENGINEPLUGIN_H
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.cpp
new file mode 100644
index 0000000..a7a27e6
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.cpp
@@ -0,0 +1,81 @@
+/*
+ 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 "ur1cashorturlengineinterface.h"
+#include "pimcommon/shorturlengineplugin.h"
+
+#include <QJsonDocument>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+
+using namespace PimCommon;
+
+Ur1CaShortUrlEngineInterface::Ur1CaShortUrlEngineInterface(ShortUrlEnginePlugin *plugin, QObject *parent)
+ : PimCommon::ShortUrlEngineInterface(plugin, parent)
+{
+ connect(mNetworkAccessManager, &QNetworkAccessManager::sslErrors, this, &Ur1CaShortUrlEngineInterface::slotSslErrors);
+}
+
+Ur1CaShortUrlEngineInterface::~Ur1CaShortUrlEngineInterface()
+{
+
+}
+
+QString Ur1CaShortUrlEngineInterface::engineName() const
+{
+ return mEnginePlugin->engineName();
+}
+
+
+void Ur1CaShortUrlEngineInterface::generateShortUrl()
+{
+ QNetworkRequest request(QUrl(QStringLiteral("http://ur1.ca/")));
+ const QString data = QStringLiteral("longurl=\"%1\"").arg(mOriginalUrl);
+
+ QNetworkReply *reply = mNetworkAccessManager->post(request, data.toUtf8());
+ connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &Ur1CaShortUrlEngineInterface::slotErrorFound);
+}
+
+void Ur1CaShortUrlEngineInterface::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)
+{
+ reply->ignoreSslErrors(error);
+}
+
+void Ur1CaShortUrlEngineInterface::slotShortUrlFinished(QNetworkReply *reply)
+{
+ if (mErrorFound) {
+ reply->deleteLater();
+ return;
+ }
+
+ QString output = QLatin1String(reply->readAll());
+ //qCDebug(PIMCOMMON_LOG) << "void Ur1CaShortUrl::slotShortUrlFinished(QNetworkReply *reply) " << output;
+ QRegExp rx(QStringLiteral("<p class=[\'\"]success[\'\"]>(.*)</p>"));
+ rx.setMinimal(true);
+ output = rx.cap(1);
+ rx.setPattern(QStringLiteral("href=[\'\"](.*)[\'\"]"));
+ rx.indexIn(output);
+ output = rx.cap(1);
+ //qCDebug(PIMCOMMON_LOG) << "Short url is: " << output;
+ if (!output.isEmpty()) {
+ Q_EMIT shortUrlGenerated(output);
+ } else {
+ //TODO
+ Q_EMIT shortUrlFailed(QString());
+ }
+ reply->deleteLater();
+}
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.h
new file mode 100644
index 0000000..fc0ae09
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineinterface.h
@@ -0,0 +1,42 @@
+/*
+ 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 UR1CASHORTURLENGINEINTERFACE_H
+#define UR1CASHORTURLENGINEINTERFACE_H
+
+#include <pimcommon/shorturlengineinterface.h>
+
+#include <QSslError>
+class QNetworkReply;
+namespace PimCommon
+{
+class Ur1CaShortUrlEngineInterface : public PimCommon::ShortUrlEngineInterface
+{
+public:
+ explicit Ur1CaShortUrlEngineInterface(PimCommon::ShortUrlEnginePlugin *plugin, QObject *parent = Q_NULLPTR);
+ ~Ur1CaShortUrlEngineInterface();
+
+ void generateShortUrl() Q_DECL_OVERRIDE;
+ QString engineName() const Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+ void slotShortUrlFinished(QNetworkReply *reply);
+ void slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
+};
+}
+
+#endif
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.cpp b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.cpp
new file mode 100644
index 0000000..79c81fe
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.cpp
@@ -0,0 +1,48 @@
+/*
+ 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 "ur1cashorturlengineplugin.h"
+#include "ur1cashorturlengineinterface.h"
+#include <kpluginfactory.h>
+
+using namespace PimCommon;
+
+K_PLUGIN_FACTORY_WITH_JSON(Ur1CaShortUrlEnginePluginFactory, "pimcommon_ur1cashorturlengineplugin.json", registerPlugin<Ur1CaShortUrlEnginePlugin>();)
+
+Ur1CaShortUrlEnginePlugin::Ur1CaShortUrlEnginePlugin(QObject *parent, const QList<QVariant> &)
+ : PimCommon::ShortUrlEnginePlugin(parent)
+{
+
+}
+
+Ur1CaShortUrlEnginePlugin::~Ur1CaShortUrlEnginePlugin()
+{
+
+}
+
+PimCommon::ShortUrlEngineInterface *Ur1CaShortUrlEnginePlugin::createInterface(QObject *parent)
+{
+ return new PimCommon::Ur1CaShortUrlEngineInterface(this, parent);
+}
+
+QString Ur1CaShortUrlEnginePlugin::engineName() const
+{
+ return QStringLiteral("urlcashorturl");
+}
+
+
+#include "ur1cashorturlengineplugin.moc"
diff --git a/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.h b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.h
new file mode 100644
index 0000000..fdbb89c
--- /dev/null
+++ b/pimcommon/src/customtools/shorturlplugin/shorturl/shorturlengineplugin/ur1cashorturlengineplugin/ur1cashorturlengineplugin.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 UR1CASHORTURLENGINEPLUGIN_H
+#define UR1CASHORTURLENGINEPLUGIN_H
+
+#include "../shorturlengineplugin.h"
+
+#include <QVariant>
+
+namespace PimCommon
+{
+class Ur1CaShortUrlEnginePlugin : public PimCommon::ShortUrlEnginePlugin
+{
+ Q_OBJECT
+public:
+ explicit Ur1CaShortUrlEnginePlugin(QObject *parent = Q_NULLPTR, const QList<QVariant> & = QList<QVariant>());
+ ~Ur1CaShortUrlEnginePlugin();
+
+ ShortUrlEngineInterface *createInterface(QObject *parent) Q_DECL_OVERRIDE;
+ QString engineName() const Q_DECL_OVERRIDE;
+};
+}
+
+#endif // UR1CASHORTURLENGINEPLUGIN_H