Commit f46ef476 authored by Laurent Montel's avatar Laurent Montel 😁

Remove it now

parent 01fbec78
set(shorturlpluginprivate_SRCS
shorturl/shorturlengineplugin/shorturlengineinterface.cpp
shorturl/shorturlengineplugin/shorturlengineplugin.cpp
)
add_library(shorturlpluginprivate ${shorturlpluginprivate_SRCS})
generate_export_header(shorturlpluginprivate BASE_NAME shorturl)
target_link_libraries(shorturlpluginprivate
PRIVATE
Qt5::Network KF5::I18n
)
set_target_properties(shorturlpluginprivate
PROPERTIES VERSION ${KDEPIMADDONS_LIB_VERSION} SOVERSION ${KDEPIMADDONS_LIB_SOVERSION}
)
install(TARGETS shorturlpluginprivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
set(pimcommon_shorturlplugin_SRCS
shorturlplugin.cpp
shorturlview.cpp
)
set(pimcommon_shorturlplugin_shorturllib_SRCS
shorturl/shorturlwidgetng.cpp
shorturl/shorturlconfigurewidget.cpp
shorturl/shorturlconfiguredialog.cpp
shorturl/shorturlengineplugin/shorturlenginepluginmanager.cpp
)
kcoreaddons_add_plugin(pimcommon_shorturlplugin JSON pimcommon_shorturlplugin.json SOURCES
${pimcommon_shorturlplugin_SRCS} ${pimcommon_shorturlplugin_shorturllib_SRCS} INSTALL_NAMESPACE pimcommon)
target_link_libraries(pimcommon_shorturlplugin
KF5::PimCommon KF5::XmlGui KF5::Completion KF5::KIOWidgets KF5::Libkdepim shorturlpluginprivate KF5::I18n
)
add_subdirectory(shorturl)
{
"KPlugin": {
"Description": "This plugin allows you to expand URL.",
"Description[ca@valencia]": "Este connector permet expandir els URL.",
"Description[ca]": "Aquest connector permet expandir els URL.",
"Description[de]": "Mit diesem Modul können Sie URLs/Adressen erweitern.",
"Description[es]": "Este complemento le permite expandir un URL.",
"Description[et]": "See plugin võimaldab laiendada URL-e.",
"Description[fi]": "Tällä liitännäisellä voit laventaa verkko-osoitteita.",
"Description[fr]": "Ce module permet de développer les URL.",
"Description[it]": "Questa estensione permette di espandere URL.",
"Description[ko]": "이 플러그인은 단축 URL을 확장합니다.",
"Description[nl]": "Deze plug-in stelt u in staat een URL te expanderen.",
"Description[pl]": "Ta wtyczka umożliwia ci rozwijanie adresów URL.",
"Description[pt]": "Este 'plugin' permite-lhe expandir o URL.",
"Description[ru]": "Этот модуль позволяет раскрывать сокращённые ссылки.",
"Description[sk]": "Tento plugin vám umožní expandovať URL.",
"Description[sl]": "Ta vstavek omogoča razširitev okrajšanih naslovov URL.",
"Description[sr@ijekavian]": "Овај прикључак омогућава проширивање УРЛ‑ова",
"Description[sr@ijekavianlatin]": "Ovaj priključak omogućava proširivanje URL‑ova",
"Description[sr@latin]": "Ovaj priključak omogućava proširivanje URL‑ova",
"Description[sr]": "Овај прикључак омогућава проширивање УРЛ‑ова",
"Description[sv]": "Insticksprogrammet gör det möjligt att expandera webbadresser.",
"Description[tr]": "Bu eklenti URL'yi genişletmenize imkan verir.",
"Description[uk]": "За допомогою цього додатка можна розгортати скорочені адреси.",
"Description[x-test]": "xxThis plugin allows you to expand URL.xx",
"Description[zh_CN]": "此插件允许您展开 URL。",
"EnabledByDefault": "false",
"Id": "customtoolsshorturl",
"Name": "Shorturl",
"Name[ca@valencia]": "URL curt",
"Name[ca]": "URL curt",
"Name[et]": "Lühi-URL",
"Name[fi]": "Lyhytosoite",
"Name[fr]": "URL courte",
"Name[it]": "URL breve",
"Name[ko]": "단축 URL",
"Name[pl]": "Krótki adres URL",
"Name[pt]": "URL Curto",
"Name[pt_BR]": "URL curta",
"Name[ru]": "Короткие ссылки",
"Name[sl]": "Kratki URL",
"Name[sr@ijekavian]": "Скраћени УРЛ",
"Name[sr@ijekavianlatin]": "Skraćeni URL",
"Name[sr@latin]": "Skraćeni URL",
"Name[sr]": "Скраћени УРЛ",
"Name[sv]": "Kort webbadress",
"Name[tr]": "Kısa url",
"Name[uk]": "Скорочення адрес",
"Name[x-test]": "xxShorturlxx",
"Name[zh_CN]": "短链接",
"ServiceTypes": [
"PimCommonCustomTools/Plugin"
],
"Version": "1.0"
}
}
if (BUILD_TESTING)
add_subdirectory(tests)
add_subdirectory(autotests)
endif()
add_subdirectory(shorturlengineplugin)
/*
Copyright (C) 2013-2017 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 "shorturlconfiguredialog.h"
#include "shorturlconfigurewidget.h"
#include <KLocalizedString>
#include <KSeparator>
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
ShortUrlConfigureDialog::ShortUrlConfigureDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(i18n("Configure engine"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::RestoreDefaults, this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &ShortUrlConfigureDialog::slotOkClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ShortUrlConfigureDialog::reject);
connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &ShortUrlConfigureDialog::slotDefaultClicked);
QWidget *w = new QWidget;
QVBoxLayout *lay = new QVBoxLayout(w);
lay->setMargin(0);
mainLayout->addWidget(w);
mainLayout->addWidget(buttonBox);
mConfigureWidget = new ShortUrlConfigureWidget();
mConfigureWidget->loadConfig();
lay->addWidget(mConfigureWidget);
lay->addWidget(new KSeparator);
}
ShortUrlConfigureDialog::~ShortUrlConfigureDialog()
{
}
void ShortUrlConfigureDialog::slotOkClicked()
{
mConfigureWidget->writeConfig();
accept();
}
void ShortUrlConfigureDialog::slotDefaultClicked()
{
mConfigureWidget->resetToDefault();
}
#include "moc_shorturlconfiguredialog.cpp"
/*
Copyright (C) 2013-2017 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 SHORTURLCONFIGUREDIALOG_H
#define SHORTURLCONFIGUREDIALOG_H
#include <QDialog>
class ShortUrlConfigureWidget;
class ShortUrlConfigureDialog : public QDialog
{
Q_OBJECT
public:
explicit ShortUrlConfigureDialog(QWidget *parent = nullptr);
~ShortUrlConfigureDialog();
private:
void slotOkClicked();
void slotDefaultClicked();
ShortUrlConfigureWidget *mConfigureWidget = nullptr;
};
#endif // SHORTURLCONFIGUREDIALOG_H
/*
Copyright (C) 2013-2017 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 "shorturlconfigurewidget.h"
#include "shorturlengineplugin/shorturlenginepluginmanager.h"
#include <KLocalizedString>
#include <QLabel>
#include <QComboBox>
#include <QHBoxLayout>
#include <KConfigGroup>
#include <KSharedConfig>
#include "shorturlengineplugin/shorturlengineplugin.h"
class ShortUrlConfigureWidgetPrivate
{
public:
ShortUrlConfigureWidgetPrivate()
{
}
QComboBox *mShortUrlServer = nullptr;
bool mChanged = false;
};
ShortUrlConfigureWidget::ShortUrlConfigureWidget(QWidget *parent)
: QWidget(parent)
, d(new ShortUrlConfigureWidgetPrivate)
{
QHBoxLayout *lay = new QHBoxLayout(this);
lay->setMargin(0);
QLabel *lab = new QLabel(i18n("Select Short URL server:"), this);
lay->addWidget(lab);
d->mShortUrlServer = new QComboBox(this);
connect(d->mShortUrlServer, QOverload<int>::of(&QComboBox::activated), this, &ShortUrlConfigureWidget::slotChanged);
lay->addWidget(d->mShortUrlServer);
init();
loadConfig();
}
ShortUrlConfigureWidget::~ShortUrlConfigureWidget()
{
delete d;
}
void ShortUrlConfigureWidget::slotChanged()
{
d->mChanged = true;
}
void ShortUrlConfigureWidget::init()
{
const QVector<ShortUrlEnginePlugin *> lstPlugin = ShortUrlEnginePluginManager::self()->pluginsList();
for (ShortUrlEnginePlugin *plugin : lstPlugin) {
d->mShortUrlServer->addItem(plugin->pluginName(), plugin->engineName());
}
}
void ShortUrlConfigureWidget::loadConfig()
{
KConfigGroup grp(KSharedConfig::openConfig(), "ShortUrl");
const QString engineName = grp.readEntry("EngineName");
int index = d->mShortUrlServer->findData(engineName);
if (index < 0) {
index = 0;
}
d->mShortUrlServer->setCurrentIndex(index);
d->mChanged = false;
}
void ShortUrlConfigureWidget::writeConfig()
{
if (d->mChanged) {
KConfigGroup grp(KSharedConfig::openConfig(), "ShortUrl");
const QString engineName = grp.readEntry("EngineName");
grp.writeEntry("EngineName", d->mShortUrlServer->itemData(d->mShortUrlServer->currentIndex()).toString());
grp.sync();
Q_EMIT settingsChanged();
}
d->mChanged = false;
}
void ShortUrlConfigureWidget::resetToDefault()
{
d->mShortUrlServer->setCurrentIndex(0);
d->mChanged = false;
}
/*
Copyright (C) 2013-2017 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 SHORTURLCONFIGUREWIDGET_H
#define SHORTURLCONFIGUREWIDGET_H
#include <QWidget>
class ShortUrlConfigureWidgetPrivate;
class ShortUrlConfigureWidget : public QWidget
{
Q_OBJECT
public:
explicit ShortUrlConfigureWidget(QWidget *parent = nullptr);
~ShortUrlConfigureWidget();
void loadConfig();
void writeConfig();
void resetToDefault();
Q_SIGNALS:
void settingsChanged();
private:
void slotChanged();
void init();
ShortUrlConfigureWidgetPrivate *const d;
};
#endif // SHORTURLCONFIGUREWIDGET_H
/*
Copyright (C) 2013-2017 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 "shorturlwidgetng.h"
#include "shorturlengineplugin/shorturlengineplugin.h"
#include "shorturlengineplugin/shorturlengineinterface.h"
#include "shorturlconfiguredialog.h"
#include "Libkdepim/ProgressIndicatorLabel"
#include "shorturlengineplugin/shorturlenginepluginmanager.h"
#include <PimCommon/NetworkManager>
#include <KLineEdit>
#include <KLocalizedString>
#include <KMessageBox>
#include <KToggleAction>
#include <KSharedConfig>
#include <KRun>
#include <QIcon>
#include <QNetworkConfigurationManager>
#include <QLabel>
#include <QGridLayout>
#include <QPushButton>
#include <QApplication>
#include <QClipboard>
#include <QToolButton>
#include <QPointer>
#include <KActionCollection>
#include <KConfigGroup>
ShortUrlWidgetNg::ShortUrlWidgetNg(QWidget *parent)
: QWidget(parent)
, mShorturlServiceName(nullptr)
, mCurrentEngine(nullptr)
{
QGridLayout *grid = new QGridLayout(this);
grid->setMargin(2);
QToolButton *closeBtn = new QToolButton(this);
closeBtn->setIcon(QIcon::fromTheme(QStringLiteral("dialog-close")));
closeBtn->setIconSize(QSize(16, 16));
closeBtn->setToolTip(i18n("Close"));
#ifndef QT_NO_ACCESSIBILITY
closeBtn->setAccessibleName(i18n("Close"));
#endif
closeBtn->setAutoRaise(true);
connect(closeBtn, &QToolButton::clicked, this, &ShortUrlWidgetNg::slotCloseWidget);
grid->addWidget(closeBtn, 0, 0);
mIndicatorLabel = new KPIM::ProgressIndicatorLabel(i18n("Generating short URL..."), this);
grid->addWidget(mIndicatorLabel, 0, 1);
QPushButton *configure = new QPushButton(i18n("Configure..."), this);
connect(configure, &QPushButton::clicked, this, &ShortUrlWidgetNg::slotConfigure);
grid->addWidget(configure, 0, 2);
mShorturlServiceName = new QLabel(/*mEngine->shortUrlName()*/ this);
grid->addWidget(mShorturlServiceName, 1, 1);
mConvertButton = new QPushButton(i18n("Convert"));
grid->addWidget(mConvertButton, 1, 2);
connect(mConvertButton, &QPushButton::clicked, this, &ShortUrlWidgetNg::slotConvertUrl);
mInsertShortUrl = new QPushButton(i18n("Insert Short URL"));
connect(mInsertShortUrl, &QPushButton::clicked, this, &ShortUrlWidgetNg::slotInsertShortUrl);
grid->addWidget(mInsertShortUrl, 2, 2);
QLabel *lab = new QLabel(i18n("Original URL:"), this);
grid->addWidget(lab, 3, 0);
mOriginalUrl = new KLineEdit(this);
mOriginalUrl->setClearButtonEnabled(true);
mOriginalUrl->setTrapReturnKey(true);
connect(mOriginalUrl, &KLineEdit::textChanged, this, &ShortUrlWidgetNg::slotOriginalUrlChanged);
connect(mOriginalUrl, &KLineEdit::returnPressed, this, &ShortUrlWidgetNg::slotConvertUrl);
grid->addWidget(mOriginalUrl, 3, 1);
mCopyToClipboard = new QPushButton(i18n("Copy to clipboard"), this);
connect(mCopyToClipboard, &QPushButton::clicked, this, &ShortUrlWidgetNg::slotPasteToClipboard);
grid->addWidget(mCopyToClipboard, 3, 2);
lab = new QLabel(i18n("Short URL:"), this);
grid->addWidget(lab, 4, 0);
mShortUrl = new QLineEdit(this);
connect(mShortUrl, &QLineEdit::textChanged, this, &ShortUrlWidgetNg::slotShortUrlChanged);
mShortUrl->setReadOnly(true);
grid->addWidget(mShortUrl, 4, 1);
mOpenShortUrl = new QPushButton(i18n("Open Short URL"), this);
connect(mOpenShortUrl, &QPushButton::clicked, this, &ShortUrlWidgetNg::slotOpenShortUrl);
grid->addWidget(mOpenShortUrl, 4, 2);
grid->setRowStretch(5, 1);
mConvertButton->setEnabled(false);
mCopyToClipboard->setEnabled(false);
mInsertShortUrl->setEnabled(false);
mOpenShortUrl->setEnabled(false);
initializePlugins();
loadEngine();
}
ShortUrlWidgetNg::~ShortUrlWidgetNg()
{
}
void ShortUrlWidgetNg::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 ShortUrlWidgetNg::slotInsertShortUrl()
{
const QString shortUrl = mShortUrl->text();
if (!shortUrl.isEmpty()) {
Q_EMIT insertText(shortUrl);
}
}
void ShortUrlWidgetNg::slotConfigure()
{
QPointer<ShortUrlConfigureDialog> dlg = new ShortUrlConfigureDialog(this);
if (dlg->exec()) {
loadEngine();
}
delete dlg;
}
void ShortUrlWidgetNg::settingsUpdated()
{
loadEngine();
}
void ShortUrlWidgetNg::loadEngine()
{
if (mCurrentEngine) {
disconnect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlGenerated, this, &ShortUrlWidgetNg::slotShortUrlDone);
disconnect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlFailed, this, &ShortUrlWidgetNg::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) {
mShorturlServiceName->setText(mCurrentEngine->pluginName());
connect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlGenerated, this, &ShortUrlWidgetNg::slotShortUrlDone);
connect(mCurrentEngine, &ShortUrlEngineInterface::shortUrlFailed, this, &ShortUrlWidgetNg::slotShortUrlFailed);
}
}
void ShortUrlWidgetNg::slotConvertUrl()
{
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();
}
void ShortUrlWidgetNg::slotPasteToClipboard()
{
const QString shortUrl = mShortUrl->text();
if (!shortUrl.isEmpty()) {
QApplication::clipboard()->setText(shortUrl);
}
}
void ShortUrlWidgetNg::slotOriginalUrlChanged(const QString &text)
{
mConvertButton->setEnabled(!text.isEmpty());
}
void ShortUrlWidgetNg::slotShortUrlChanged(const QString &text)
{
const bool textIsEmpty = {!text.isEmpty()};
mCopyToClipboard->setEnabled(textIsEmpty);
mInsertShortUrl->setEnabled(textIsEmpty);
mOpenShortUrl->setEnabled(textIsEmpty);
}
void ShortUrlWidgetNg::slotShortUrlDone(const QString &url)
{
mShortUrl->setText(url);
mIndicatorLabel->stop();
}
void ShortUrlWidgetNg::slotShortUrlFailed(const QString &errMsg)
{
KMessageBox::error(this, i18n("An error occurred: \"%1\"", errMsg));
mIndicatorLabel->stop();
}
void ShortUrlWidgetNg::slotCloseWidget()
{
mOriginalUrl->clear();
mShortUrl->clear();
mIndicatorLabel->stop();
Q_EMIT toolsWasClosed();
}
void ShortUrlWidgetNg::slotOpenShortUrl()
{
const QString shortUrl = mShortUrl->text();
if (!shortUrl.isEmpty()) {
new KRun(QUrl(shortUrl), this);
}
}
/*
Copyright (C) 2013-2017 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.
*/