forked from qt-creator/qt-creator
CPaster: Remove KDE paster
There is no official API anymore after the latest change of the KDE paster and it was probably almost no more in use after the need for credentials. Remove everything related except the base implementation of the sticky notes part as it could be re-used for another paster that based on the old approach used by the KDE paster. Change-Id: I0e2c3f279bc9eaa373147ee2909c9538f0d62498 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -38,7 +38,6 @@
|
||||
\list
|
||||
\li \uicontrol {Pastebin.Com}
|
||||
\li \uicontrol {Pastecode.Xyz}
|
||||
\li \uicontrol {Paste.KDE.Org}
|
||||
\li \uicontrol {Shared network drives}
|
||||
\endlist
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "authenticationdialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
AuthenticationDialog::AuthenticationDialog(const QString &details, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addWidget(new QLabel(details));
|
||||
auto *formLayout = new QFormLayout;
|
||||
formLayout->addRow(tr("Username:"), m_user = new QLineEdit);
|
||||
formLayout->addRow(tr("Password:"), m_pass = new QLineEdit);
|
||||
m_pass->setEchoMode(QLineEdit::Password);
|
||||
mainLayout->addLayout(formLayout);
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
QString AuthenticationDialog::userName() const
|
||||
{
|
||||
return m_user->text();
|
||||
}
|
||||
|
||||
QString AuthenticationDialog::password() const
|
||||
{
|
||||
return m_pass->text();
|
||||
}
|
||||
|
||||
} // namespace CodePaster
|
||||
@@ -1,53 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLineEdit;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
class AuthenticationDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AuthenticationDialog(const QString &details, QWidget *parent = nullptr);
|
||||
|
||||
bool authenticated() const { return m_authenticated; }
|
||||
QString userName() const;
|
||||
QString password() const;
|
||||
|
||||
private:
|
||||
bool m_authenticated = false;
|
||||
QLineEdit *m_user = nullptr;
|
||||
QLineEdit *m_pass = nullptr;
|
||||
};
|
||||
|
||||
} // namespace CodePaster
|
||||
@@ -12,10 +12,9 @@ HEADERS += cpasterplugin.h \
|
||||
columnindicatortextedit.h \
|
||||
fileshareprotocol.h \
|
||||
fileshareprotocolsettingspage.h \
|
||||
kdepasteprotocol.h \
|
||||
stickynotespasteprotocol.h \
|
||||
urlopenprotocol.h \
|
||||
codepasterservice.h \
|
||||
authenticationdialog.h
|
||||
codepasterservice.h
|
||||
|
||||
SOURCES += cpasterplugin.cpp \
|
||||
settingspage.cpp \
|
||||
@@ -28,9 +27,8 @@ SOURCES += cpasterplugin.cpp \
|
||||
columnindicatortextedit.cpp \
|
||||
fileshareprotocol.cpp \
|
||||
fileshareprotocolsettingspage.cpp \
|
||||
kdepasteprotocol.cpp \
|
||||
urlopenprotocol.cpp \
|
||||
authenticationdialog.cpp
|
||||
stickynotespasteprotocol.cpp \
|
||||
urlopenprotocol.cpp
|
||||
|
||||
FORMS += settingspage.ui \
|
||||
pasteselect.ui \
|
||||
|
||||
@@ -24,8 +24,6 @@ QtcPlugin {
|
||||
"fileshareprotocolsettingspage.cpp",
|
||||
"fileshareprotocolsettingspage.h",
|
||||
"fileshareprotocolsettingswidget.ui",
|
||||
"kdepasteprotocol.cpp",
|
||||
"kdepasteprotocol.h",
|
||||
"pastebindotcomprotocol.cpp",
|
||||
"pastebindotcomprotocol.h",
|
||||
"pastebindotcomsettings.ui",
|
||||
@@ -44,10 +42,10 @@ QtcPlugin {
|
||||
"settingspage.cpp",
|
||||
"settingspage.h",
|
||||
"settingspage.ui",
|
||||
"stickynotespasteprotocol.cpp",
|
||||
"stickynotespasteprotocol.h",
|
||||
"urlopenprotocol.cpp",
|
||||
"urlopenprotocol.h",
|
||||
"authenticationdialog.cpp",
|
||||
"authenticationdialog.h"
|
||||
]
|
||||
|
||||
Group {
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "cpasterplugin.h"
|
||||
|
||||
#include "pasteview.h"
|
||||
#include "kdepasteprotocol.h"
|
||||
#include "pastebindotcomprotocol.h"
|
||||
#include "pastecodedotxyzprotocol.h"
|
||||
#include "fileshareprotocol.h"
|
||||
@@ -120,7 +119,6 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *errorMe
|
||||
|
||||
// Create the protocols and append them to the Settings
|
||||
Protocol *protos[] = {new PasteBinDotComProtocol,
|
||||
new KdePasteProtocol,
|
||||
new FileShareProtocol,
|
||||
new PasteCodeDotXyzProtocol,
|
||||
};
|
||||
|
||||
@@ -14,14 +14,12 @@ HEADERS = ../protocol.h \
|
||||
../cpasterconstants.h \
|
||||
../pastebindotcomprotocol.h \
|
||||
../pastecodedotxyzprotocol.h \
|
||||
../kdepasteprotocol.h \
|
||||
../urlopenprotocol.h \
|
||||
argumentscollector.h
|
||||
|
||||
SOURCES += ../protocol.cpp \
|
||||
../pastebindotcomprotocol.cpp \
|
||||
../pastecodedotxyzprotocol.cpp \
|
||||
../kdepasteprotocol.cpp \
|
||||
../urlopenprotocol.cpp \
|
||||
argumentscollector.cpp \
|
||||
main.cpp
|
||||
|
||||
@@ -23,7 +23,6 @@ QtcTool {
|
||||
prefix: "../"
|
||||
files: [
|
||||
"cpasterconstants.h",
|
||||
"kdepasteprotocol.h", "kdepasteprotocol.cpp",
|
||||
"pastebindotcomprotocol.h", "pastebindotcomprotocol.cpp",
|
||||
"pastecodedotxyzprotocol.h", "pastecodedotxyzprotocol.cpp",
|
||||
"protocol.h", "protocol.cpp",
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "argumentscollector.h"
|
||||
#include "../kdepasteprotocol.h"
|
||||
#include "../pastebindotcomprotocol.h"
|
||||
#include "../pastecodedotxyzprotocol.h"
|
||||
|
||||
@@ -46,9 +45,7 @@ class PasteReceiver : public QObject
|
||||
public:
|
||||
PasteReceiver(const QString &protocol, const QString &filePath) : m_filePath(filePath)
|
||||
{
|
||||
if (protocol == KdePasteProtocol::protocolName().toLower())
|
||||
m_protocol.reset(new KdePasteProtocol);
|
||||
else if (protocol == PasteBinDotComProtocol::protocolName().toLower())
|
||||
if (protocol == PasteBinDotComProtocol::protocolName().toLower())
|
||||
m_protocol.reset(new PasteBinDotComProtocol);
|
||||
else if (protocol == PasteCodeDotXyzProtocol::protocolName().toLower())
|
||||
m_protocol.reset(new PasteCodeDotXyzProtocol);
|
||||
@@ -91,8 +88,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
const QStringList protocols = {KdePasteProtocol::protocolName().toLower(),
|
||||
PasteBinDotComProtocol::protocolName().toLower(),
|
||||
const QStringList protocols = {PasteBinDotComProtocol::protocolName().toLower(),
|
||||
PasteCodeDotXyzProtocol::protocolName().toLower()};
|
||||
ArgumentsCollector argsCollector(protocols);
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "protocol.h"
|
||||
#ifdef CPASTER_PLUGIN_GUI
|
||||
#include "authenticationdialog.h"
|
||||
#endif
|
||||
|
||||
#include <utils/networkaccessmanager.h>
|
||||
|
||||
@@ -50,7 +47,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <QApplication>
|
||||
#include <QPushButton>
|
||||
#include <QAuthenticator>
|
||||
|
||||
namespace CodePaster {
|
||||
|
||||
@@ -207,35 +203,8 @@ QNetworkReply *NetworkProtocol::httpPost(const QString &link, const QByteArray &
|
||||
return Utils::NetworkAccessManager::instance()->post(r, data);
|
||||
}
|
||||
|
||||
NetworkProtocol::NetworkProtocol()
|
||||
: Protocol()
|
||||
{
|
||||
connect(Utils::NetworkAccessManager::instance(), &QNetworkAccessManager::authenticationRequired,
|
||||
this, &NetworkProtocol::authenticationRequired);
|
||||
}
|
||||
|
||||
NetworkProtocol::~NetworkProtocol() = default;
|
||||
|
||||
void NetworkProtocol::requestAuthentication(const QUrl &url, QNetworkReply *reply, QAuthenticator *authenticator)
|
||||
{
|
||||
#ifdef CPASTER_PLUGIN_GUI
|
||||
if (reply->request().url().host() == url.host()) {
|
||||
const QString details = tr("Pasting needs authentication.<br/>"
|
||||
"Enter your identity credentials to continue.");
|
||||
AuthenticationDialog authDialog(details, Core::ICore::dialogParent());
|
||||
authDialog.setWindowTitle(tr("Authenticate for Paster"));
|
||||
if (authDialog.exec() == QDialog::Accepted) {
|
||||
authenticator->setUser(authDialog.userName());
|
||||
authenticator->setPassword(authDialog.password());
|
||||
}
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(url);
|
||||
Q_UNUSED(reply);
|
||||
Q_UNUSED(authenticator);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool NetworkProtocol::httpStatus(QString url, QString *errorMessage, bool useHttps)
|
||||
{
|
||||
// Connect to host and display a message box, using its event loop.
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QSharedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAuthenticator;
|
||||
class QNetworkReply;
|
||||
class QWidget;
|
||||
QT_END_NAMESPACE
|
||||
@@ -108,16 +107,11 @@ class NetworkProtocol : public Protocol
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NetworkProtocol();
|
||||
NetworkProtocol() = default;
|
||||
|
||||
~NetworkProtocol() override;
|
||||
|
||||
signals:
|
||||
void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
|
||||
|
||||
protected:
|
||||
void requestAuthentication(const QUrl &url, QNetworkReply *reply, QAuthenticator *authenticator);
|
||||
|
||||
QNetworkReply *httpGet(const QString &url, bool handleCookies = false);
|
||||
|
||||
QNetworkReply *httpPost(const QString &link, const QByteArray &data,
|
||||
|
||||
@@ -23,9 +23,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "kdepasteprotocol.h"
|
||||
#include "stickynotespasteprotocol.h"
|
||||
#ifdef CPASTER_PLUGIN_GUI
|
||||
#include "authenticationdialog.h"
|
||||
#endif
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -266,129 +265,5 @@ void StickyNotesPasteProtocol::listFinished()
|
||||
m_listReply = nullptr;
|
||||
}
|
||||
|
||||
KdePasteProtocol::KdePasteProtocol()
|
||||
{
|
||||
setHostUrl(QLatin1String("https://pastebin.kde.org/"));
|
||||
connect(this, &KdePasteProtocol::authenticationFailed, this, [this] () {
|
||||
m_loginFailed = true;
|
||||
paste(m_text, m_contentType, m_expiryDays, QString(), QString(), m_description);
|
||||
});
|
||||
}
|
||||
|
||||
void KdePasteProtocol::paste(const QString &text, Protocol::ContentType ct, int expiryDays,
|
||||
const QString &username, const QString &comment,
|
||||
const QString &description)
|
||||
{
|
||||
Q_UNUSED(username);
|
||||
Q_UNUSED(comment);
|
||||
// KDE paster needs authentication nowadays
|
||||
#ifdef CPASTER_PLUGIN_GUI
|
||||
QString details = tr("Pasting to KDE paster needs authentication.<br/>"
|
||||
"Enter your KDE Identity credentials to continue.");
|
||||
if (m_loginFailed)
|
||||
details.prepend("<span style='background-color:LightYellow;color:red'>"
|
||||
+ tr("Login failed") + "</span><br/><br/>");
|
||||
|
||||
AuthenticationDialog authDialog(details, Core::ICore::dialogParent());
|
||||
authDialog.setWindowTitle("Authenticate for KDE paster");
|
||||
if (authDialog.exec() != QDialog::Accepted) {
|
||||
m_loginFailed = false;
|
||||
return;
|
||||
}
|
||||
const QString user = authDialog.userName();
|
||||
const QString passwd = authDialog.password();
|
||||
#else
|
||||
// FIXME get the credentials for the cmdline cpaster somehow
|
||||
const QString user;
|
||||
const QString passwd;
|
||||
qDebug() << "KDE needs credentials for pasting";
|
||||
emit pasteDone(QString());
|
||||
return;
|
||||
#endif
|
||||
// store input data as members to be able to use them after the authentication succeeded
|
||||
m_text = text;
|
||||
m_contentType = ct;
|
||||
m_expiryDays = expiryDays;
|
||||
m_description = description;
|
||||
authenticate(user, passwd);
|
||||
}
|
||||
|
||||
QString KdePasteProtocol::protocolName()
|
||||
{
|
||||
return QLatin1String("Paste.KDE.Org");
|
||||
}
|
||||
|
||||
void KdePasteProtocol::authenticate(const QString &user, const QString &passwd)
|
||||
{
|
||||
QTC_ASSERT(!m_authReply, return);
|
||||
|
||||
// first we need to obtain the hidden form token for logging in
|
||||
m_authReply = httpGet(hostUrl() + "user/login");
|
||||
connect(m_authReply, &QNetworkReply::finished, this, [this, user, passwd] () {
|
||||
onPreAuthFinished(user, passwd);
|
||||
});
|
||||
}
|
||||
|
||||
void KdePasteProtocol::onPreAuthFinished(const QString &user, const QString &passwd)
|
||||
{
|
||||
if (m_authReply->error() != QNetworkReply::NoError) {
|
||||
m_authReply->deleteLater();
|
||||
m_authReply = nullptr;
|
||||
return;
|
||||
}
|
||||
const QByteArray page = m_authReply->readAll();
|
||||
m_authReply->deleteLater();
|
||||
const QRegularExpression regex("name=\"_token\"\\s+type=\"hidden\"\\s+value=\"(.*?)\">");
|
||||
const QRegularExpressionMatch match = regex.match(QLatin1String(page));
|
||||
if (!match.hasMatch()) {
|
||||
m_authReply = nullptr;
|
||||
return;
|
||||
}
|
||||
const QString token = match.captured(1);
|
||||
|
||||
QByteArray data("username=" + QUrl::toPercentEncoding(user)
|
||||
+ "&password=" + QUrl::toPercentEncoding(passwd)
|
||||
+ "&_token=" + QUrl::toPercentEncoding(token));
|
||||
m_authReply = httpPost(hostUrl() + "user/login", data, true);
|
||||
connect(m_authReply, &QNetworkReply::finished, this, &KdePasteProtocol::onAuthFinished);
|
||||
}
|
||||
|
||||
void KdePasteProtocol::onAuthFinished()
|
||||
{
|
||||
if (m_authReply->error() != QNetworkReply::NoError) {
|
||||
m_authReply->deleteLater();
|
||||
m_authReply = nullptr;
|
||||
return;
|
||||
}
|
||||
const QVariant attribute = m_authReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
|
||||
m_redirectUrl = redirectUrl(attribute.toUrl().toString(), m_redirectUrl);
|
||||
if (!m_redirectUrl.isEmpty()) { // we need to perform a redirect
|
||||
QUrl url(m_redirectUrl);
|
||||
if (url.path().isEmpty())
|
||||
url.setPath("/"); // avoid issue inside cookiesForUrl()
|
||||
m_authReply->deleteLater();
|
||||
m_authReply = httpGet(url.url(), true);
|
||||
connect(m_authReply, &QNetworkReply::finished, this, &KdePasteProtocol::onAuthFinished);
|
||||
} else { // auth should be done now
|
||||
const QByteArray page = m_authReply->readAll();
|
||||
m_authReply->deleteLater();
|
||||
m_authReply = nullptr;
|
||||
if (page.contains("https://identity.kde.org")) // we're back on the login page
|
||||
emit authenticationFailed();
|
||||
else {
|
||||
m_loginFailed = false;
|
||||
StickyNotesPasteProtocol::paste(m_text, m_contentType, m_expiryDays, QString(),
|
||||
QString(), m_description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString KdePasteProtocol::redirectUrl(const QString &redirect, const QString &oldRedirect) const
|
||||
{
|
||||
QString redirectUrl;
|
||||
if (!redirect.isEmpty() && redirect != oldRedirect)
|
||||
redirectUrl = redirect;
|
||||
return redirectUrl;
|
||||
}
|
||||
|
||||
} // namespace CodePaster
|
||||
@@ -68,35 +68,4 @@ private:
|
||||
bool m_hostChecked = false;
|
||||
};
|
||||
|
||||
class KdePasteProtocol : public StickyNotesPasteProtocol
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KdePasteProtocol();
|
||||
|
||||
void paste(const QString &text, ContentType ct = Text, int expiryDays = 1,
|
||||
const QString &username = QString(),
|
||||
const QString &comment = QString() ,
|
||||
const QString &description = QString()) override;
|
||||
|
||||
QString name() const override { return protocolName(); }
|
||||
static QString protocolName();
|
||||
signals:
|
||||
void authenticationFailed();
|
||||
private:
|
||||
void authenticate(const QString &user, const QString &passwd);
|
||||
void onPreAuthFinished(const QString &user, const QString &passwd);
|
||||
void onAuthFinished();
|
||||
QString redirectUrl(const QString &redirect, const QString &oldRedirect) const;
|
||||
|
||||
QNetworkReply *m_authReply = nullptr;
|
||||
QString m_text;
|
||||
ContentType m_contentType = Text;
|
||||
int m_expiryDays = 1;
|
||||
bool m_loginFailed = false;
|
||||
QString m_description;
|
||||
QString m_redirectUrl;
|
||||
|
||||
};
|
||||
|
||||
} // namespace CodePaster
|
||||
Reference in New Issue
Block a user