File indexing completed on 2025-01-19 04:46:40
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "shorturlengineinterface.h" 0008 #include "shorturlengineplugin.h" 0009 0010 #include <KLocalizedString> 0011 0012 #include <QNetworkAccessManager> 0013 0014 ShortUrlEngineInterface::ShortUrlEngineInterface(ShortUrlEnginePlugin *plugin, QObject *parent) 0015 : QObject(parent) 0016 , mNetworkAccessManager(new QNetworkAccessManager(this)) 0017 , mEnginePlugin(plugin) 0018 { 0019 mNetworkAccessManager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy); 0020 mNetworkAccessManager->setStrictTransportSecurityEnabled(true); 0021 mNetworkAccessManager->enableStrictTransportSecurityStore(true); 0022 } 0023 0024 ShortUrlEngineInterface::~ShortUrlEngineInterface() = default; 0025 0026 void ShortUrlEngineInterface::slotErrorFound(QNetworkReply::NetworkError error) 0027 { 0028 mErrorFound = true; 0029 auto reply = qobject_cast<QNetworkReply *>(sender()); 0030 Q_EMIT shortUrlFailed(i18n("Error reported by server:\n\'%1\'", (reply ? reply->errorString() : QString::number(error)))); 0031 } 0032 0033 void ShortUrlEngineInterface::setShortUrl(const QString &url) 0034 { 0035 mErrorFound = false; 0036 if (!url.trimmed().startsWith(QLatin1StringView("http://")) && !url.trimmed().startsWith(QLatin1StringView("https://")) 0037 && !url.trimmed().startsWith(QLatin1StringView("ftp://")) && !url.trimmed().startsWith(QLatin1StringView("ftps://"))) { 0038 mOriginalUrl = QLatin1StringView("http://") + url; 0039 } else { 0040 mOriginalUrl = url; 0041 } 0042 } 0043 0044 QString ShortUrlEngineInterface::pluginName() const 0045 { 0046 return mEnginePlugin->pluginName(); 0047 } 0048 0049 void ShortUrlEngineInterface::setTextCursor(const QTextCursor &cursor) 0050 { 0051 mTextCursor = cursor; 0052 } 0053 0054 #include "moc_shorturlengineinterface.cpp"