diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2020-05-18 12:00:50 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2020-05-18 13:32:09 +0000 |
commit | 715dfcd3f8a7953e090ab866d19c54b690b1a237 (patch) | |
tree | 006766f1ee687310b8fedc956aa21744be89c3a8 /src/plugins/cpaster | |
parent | 3d353424a6c6771afd4d5c2910ad4a748b42bf60 (diff) |
CPaster: Replace pastecode.xyz with dpaste.com
The pastecode.xyz service has apparently ceased to exist.
Fixes: QTCREATORBUG-24002
Change-Id: I95fe6ec1388558d4dc176f66b166026619414e89
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/cpaster')
-rw-r--r-- | src/plugins/cpaster/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/plugins/cpaster/cpaster.pro | 4 | ||||
-rw-r--r-- | src/plugins/cpaster/cpaster.qbs | 4 | ||||
-rw-r--r-- | src/plugins/cpaster/cpasterplugin.cpp | 10 | ||||
-rw-r--r-- | src/plugins/cpaster/dpastedotcomprotocol.cpp (renamed from src/plugins/cpaster/pastecodedotxyzprotocol.cpp) | 107 | ||||
-rw-r--r-- | src/plugins/cpaster/dpastedotcomprotocol.h (renamed from src/plugins/cpaster/pastecodedotxyzprotocol.h) | 5 | ||||
-rw-r--r-- | src/plugins/cpaster/frontend/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/plugins/cpaster/frontend/frontend.pro | 4 | ||||
-rw-r--r-- | src/plugins/cpaster/frontend/frontend.qbs | 2 | ||||
-rw-r--r-- | src/plugins/cpaster/frontend/main.cpp | 10 |
10 files changed, 64 insertions, 86 deletions
diff --git a/src/plugins/cpaster/CMakeLists.txt b/src/plugins/cpaster/CMakeLists.txt index d631177c4e..39ab53da64 100644 --- a/src/plugins/cpaster/CMakeLists.txt +++ b/src/plugins/cpaster/CMakeLists.txt @@ -11,6 +11,7 @@ add_qtc_plugin(CodePaster cpasterconstants.h cpaster.qrc cpasterplugin.cpp cpasterplugin.h + dpastedotcomprotocol.cpp dpastedotcomprotocol.h fileshareprotocol.cpp fileshareprotocol.h fileshareprotocolsettingspage.cpp fileshareprotocolsettingspage.h fileshareprotocolsettingswidget.ui @@ -18,7 +19,6 @@ add_qtc_plugin(CodePaster frontend/main.cpp pastebindotcomprotocol.cpp pastebindotcomprotocol.h pastebindotcomsettings.ui - pastecodedotxyzprotocol.cpp pastecodedotxyzprotocol.h pasteselect.ui pasteselectdialog.cpp pasteselectdialog.h pasteview.cpp pasteview.h pasteview.ui diff --git a/src/plugins/cpaster/cpaster.pro b/src/plugins/cpaster/cpaster.pro index 3565f4d03f..c824caa681 100644 --- a/src/plugins/cpaster/cpaster.pro +++ b/src/plugins/cpaster/cpaster.pro @@ -1,12 +1,12 @@ QT += network include(../../qtcreatorplugin.pri) HEADERS += cpasterplugin.h \ + dpastedotcomprotocol.h \ settingspage.h \ protocol.h \ pasteview.h \ cpasterconstants.h \ pastebindotcomprotocol.h \ - pastecodedotxyzprotocol.h \ settings.h \ pasteselectdialog.h \ columnindicatortextedit.h \ @@ -17,11 +17,11 @@ HEADERS += cpasterplugin.h \ codepasterservice.h SOURCES += cpasterplugin.cpp \ + dpastedotcomprotocol.cpp \ settingspage.cpp \ protocol.cpp \ pasteview.cpp \ pastebindotcomprotocol.cpp \ - pastecodedotxyzprotocol.cpp \ settings.cpp \ pasteselectdialog.cpp \ columnindicatortextedit.cpp \ diff --git a/src/plugins/cpaster/cpaster.qbs b/src/plugins/cpaster/cpaster.qbs index 9547f8ad5e..e4aa433130 100644 --- a/src/plugins/cpaster/cpaster.qbs +++ b/src/plugins/cpaster/cpaster.qbs @@ -19,6 +19,8 @@ QtcPlugin { "cpaster.qrc", "cpasterplugin.cpp", "cpasterplugin.h", + "dpastedotcomprotocol.cpp", + "dpastedotcomprotocol.h", "fileshareprotocol.cpp", "fileshareprotocol.h", "fileshareprotocolsettingspage.cpp", @@ -27,8 +29,6 @@ QtcPlugin { "pastebindotcomprotocol.cpp", "pastebindotcomprotocol.h", "pastebindotcomsettings.ui", - "pastecodedotxyzprotocol.cpp", - "pastecodedotxyzprotocol.h", "pasteselect.ui", "pasteselectdialog.cpp", "pasteselectdialog.h", diff --git a/src/plugins/cpaster/cpasterplugin.cpp b/src/plugins/cpaster/cpasterplugin.cpp index 681f1aef3f..49dcc1f085 100644 --- a/src/plugins/cpaster/cpasterplugin.cpp +++ b/src/plugins/cpaster/cpasterplugin.cpp @@ -25,11 +25,11 @@ #include "cpasterplugin.h" -#include "pasteview.h" -#include "pastebindotcomprotocol.h" -#include "pastecodedotxyzprotocol.h" +#include "dpastedotcomprotocol.h" #include "fileshareprotocol.h" +#include "pastebindotcomprotocol.h" #include "pasteselectdialog.h" +#include "pasteview.h" #include "settingspage.h" #include "settings.h" #include "urlopenprotocol.h" @@ -91,12 +91,12 @@ public: PasteBinDotComProtocol pasteBinProto; FileShareProtocol fileShareProto; - PasteCodeDotXyzProtocol pasteCodeProto; + DPasteDotComProtocol dpasteProto; const QList<Protocol *> m_protocols { &pasteBinProto, &fileShareProto, - &pasteCodeProto + &dpasteProto }; SettingsPage m_settingsPage { diff --git a/src/plugins/cpaster/pastecodedotxyzprotocol.cpp b/src/plugins/cpaster/dpastedotcomprotocol.cpp index 71f7ec6c89..1a0d9c6194 100644 --- a/src/plugins/cpaster/pastecodedotxyzprotocol.cpp +++ b/src/plugins/cpaster/dpastedotcomprotocol.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -23,33 +23,28 @@ ** ****************************************************************************/ -#include "pastecodedotxyzprotocol.h" +#include "dpastedotcomprotocol.h" #include <coreplugin/messagemanager.h> -#include <QJsonArray> -#include <QJsonDocument> -#include <QJsonObject> -#include <QJsonParseError> -#include <QJsonValue> #include <QNetworkReply> #include <QUrl> namespace CodePaster { -static QString baseUrl() { return QString("https://pastecode.xyz"); } -static QString apiUrl() { return baseUrl() + "/api"; } +static QString baseUrl() { return QString("http://dpaste.com"); } +static QString apiUrl() { return baseUrl() + "/api/v2/"; } -QString PasteCodeDotXyzProtocol::protocolName() { return QString("Pastecode.Xyz"); } +QString DPasteDotComProtocol::protocolName() { return QString("DPaste.Com"); } -unsigned PasteCodeDotXyzProtocol::capabilities() const +unsigned DPasteDotComProtocol::capabilities() const { - return ListCapability | PostDescriptionCapability | PostUserNameCapability; + return PostDescriptionCapability | PostUserNameCapability; } -void PasteCodeDotXyzProtocol::fetch(const QString &id) +void DPasteDotComProtocol::fetch(const QString &id) { - QNetworkReply * const reply = httpGet(baseUrl() + "/view/raw/" + id); + QNetworkReply * const reply = httpGet(baseUrl() + '/' + id + ".txt"); connect(reply, &QNetworkReply::finished, this, [this, id, reply] { QString title; QString content; @@ -65,9 +60,28 @@ void PasteCodeDotXyzProtocol::fetch(const QString &id) }); } -void PasteCodeDotXyzProtocol::paste( +static QByteArray typeToString(Protocol::ContentType type) +{ + switch (type) { + case Protocol::C: + return "c"; + case Protocol::Cpp: + return "cpp"; + case Protocol::Diff: + return "diff"; + case Protocol::JavaScript: + return "js"; + case Protocol::Text: + return "text"; + case Protocol::Xml: + return "xml"; + } + return {}; // For dumb compilers. +} + +void DPasteDotComProtocol::paste( const QString &text, - Protocol::ContentType ct, + ContentType ct, int expiryDays, bool publicPaste, const QString &username, @@ -75,32 +89,23 @@ void PasteCodeDotXyzProtocol::paste( const QString &description ) { + Q_UNUSED(publicPaste) + Q_UNUSED(comment) + + // See http://dpaste.com/api/v2/ QByteArray data; - data += "text=" + QUrl::toPercentEncoding(fixNewLines(text)); - data += "&expire=" + QUrl::toPercentEncoding(QString::number(expiryDays * 24 * 60)); + data += "content=" + QUrl::toPercentEncoding(fixNewLines(text)); + data += "&expiry_days=" + QByteArray::number(expiryDays); + data += "&syntax=" + typeToString(ct); data += "&title=" + QUrl::toPercentEncoding(description); - data += "&name=" + QUrl::toPercentEncoding(username); - if (!publicPaste) - data += "&private=1"; - static const auto langValue = [](Protocol::ContentType type) -> QByteArray { - switch (type) { - case Protocol::Text: return "text"; - case Protocol::C: return "c"; - case Protocol::Cpp: return "cpp"; - case Protocol::JavaScript: return "javascript"; - case Protocol::Diff: return "diff"; - case Protocol::Xml: return "xml"; - } - return QByteArray(); // Crutch for compiler. - }; - data += "&lang=" + langValue(ct); - Q_UNUSED(comment) + data += "&poster=" + QUrl::toPercentEncoding(username); - QNetworkReply * const reply = httpPost(apiUrl() + "/create", data); + QNetworkReply * const reply = httpPost(apiUrl(), data); connect(reply, &QNetworkReply::finished, this, [this, reply] { QString data; if (reply->error()) { reportError(reply->errorString()); // FIXME: Why can't we properly emit an error here? + reportError(QString::fromUtf8(reply->readAll())); } else { data = QString::fromUtf8(reply->readAll()); if (!data.startsWith(baseUrl())) { @@ -113,40 +118,14 @@ void PasteCodeDotXyzProtocol::paste( }); } -void PasteCodeDotXyzProtocol::list() -{ - QNetworkReply * const reply = httpGet(apiUrl() + "/recent"); - connect(reply, &QNetworkReply::finished, this, [this, reply] { - QStringList ids; - if (reply->error()) { - reportError(reply->errorString()); - } else { - QJsonParseError parseError; - const QJsonDocument jsonData = QJsonDocument::fromJson(reply->readAll(), &parseError); - if (parseError.error != QJsonParseError::NoError) { - reportError(parseError.errorString()); - } else { - const QJsonArray jsonList = jsonData.array(); - for (auto it = jsonList.constBegin(); it != jsonList.constEnd(); ++it) { - const QString id = it->toObject().value("pid").toString(); - if (!id.isEmpty()) - ids << id; - } - } - } - emit listDone(name(), ids); - reply->deleteLater(); - }); -} - -bool PasteCodeDotXyzProtocol::checkConfiguration(QString *errorMessage) +bool DPasteDotComProtocol::checkConfiguration(QString *errorMessage) { if (!m_hostKnownOk) - m_hostKnownOk = httpStatus(apiUrl(), errorMessage); + m_hostKnownOk = httpStatus(baseUrl(), errorMessage); return m_hostKnownOk; } -void PasteCodeDotXyzProtocol::reportError(const QString &message) +void DPasteDotComProtocol::reportError(const QString &message) { const QString fullMessage = tr("%1: %2").arg(protocolName(), message); Core::MessageManager::write(fullMessage, Core::MessageManager::ModeSwitch); diff --git a/src/plugins/cpaster/pastecodedotxyzprotocol.h b/src/plugins/cpaster/dpastedotcomprotocol.h index ef62956d6d..6f01649578 100644 --- a/src/plugins/cpaster/pastecodedotxyzprotocol.h +++ b/src/plugins/cpaster/dpastedotcomprotocol.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -29,7 +29,7 @@ namespace CodePaster { -class PasteCodeDotXyzProtocol : public NetworkProtocol +class DPasteDotComProtocol : public NetworkProtocol { Q_OBJECT public: @@ -47,7 +47,6 @@ private: const QString &username = QString(), const QString &comment = QString(), const QString &description = QString()) override; - void list() override; bool checkConfiguration(QString *errorMessage) override; static void reportError(const QString &message); diff --git a/src/plugins/cpaster/frontend/CMakeLists.txt b/src/plugins/cpaster/frontend/CMakeLists.txt index 9adc4e2e0c..58468f63d1 100644 --- a/src/plugins/cpaster/frontend/CMakeLists.txt +++ b/src/plugins/cpaster/frontend/CMakeLists.txt @@ -3,8 +3,8 @@ add_qtc_executable(cpaster SOURCES argumentscollector.cpp argumentscollector.h main.cpp + ../dpastedotcomprotocol.cpp ../dpastedotcomprotocol.h ../pastebindotcomprotocol.cpp ../pastebindotcomprotocol.h - ../pastecodedotxyzprotocol.cpp ../pastecodedotxyzprotocol.h ../protocol.cpp ../protocol.h ../urlopenprotocol.cpp ../urlopenprotocol.h ) diff --git a/src/plugins/cpaster/frontend/frontend.pro b/src/plugins/cpaster/frontend/frontend.pro index 69b6428a3f..cca00ec980 100644 --- a/src/plugins/cpaster/frontend/frontend.pro +++ b/src/plugins/cpaster/frontend/frontend.pro @@ -12,14 +12,14 @@ QT += network HEADERS = ../protocol.h \ ../cpasterconstants.h \ + ../dpastedotcomprotocol.h \ ../pastebindotcomprotocol.h \ - ../pastecodedotxyzprotocol.h \ ../urlopenprotocol.h \ argumentscollector.h SOURCES += ../protocol.cpp \ + ../dpastedotcomprotocol.cpp \ ../pastebindotcomprotocol.cpp \ - ../pastecodedotxyzprotocol.cpp \ ../urlopenprotocol.cpp \ argumentscollector.cpp \ main.cpp diff --git a/src/plugins/cpaster/frontend/frontend.qbs b/src/plugins/cpaster/frontend/frontend.qbs index 2993953105..94153e93e3 100644 --- a/src/plugins/cpaster/frontend/frontend.qbs +++ b/src/plugins/cpaster/frontend/frontend.qbs @@ -23,8 +23,8 @@ QtcTool { prefix: "../" files: [ "cpasterconstants.h", + "dpastedotcomprotocol.h", "dpastedotcomprotocol.cpp", "pastebindotcomprotocol.h", "pastebindotcomprotocol.cpp", - "pastecodedotxyzprotocol.h", "pastecodedotxyzprotocol.cpp", "protocol.h", "protocol.cpp", "urlopenprotocol.h", "urlopenprotocol.cpp", ] diff --git a/src/plugins/cpaster/frontend/main.cpp b/src/plugins/cpaster/frontend/main.cpp index 50ae182334..afdfdd9166 100644 --- a/src/plugins/cpaster/frontend/main.cpp +++ b/src/plugins/cpaster/frontend/main.cpp @@ -24,8 +24,8 @@ ****************************************************************************/ #include "argumentscollector.h" +#include "../dpastedotcomprotocol.h" #include "../pastebindotcomprotocol.h" -#include "../pastecodedotxyzprotocol.h" #include <QFile> #include <QObject> @@ -47,8 +47,8 @@ public: { if (protocol == PasteBinDotComProtocol::protocolName().toLower()) m_protocol.reset(new PasteBinDotComProtocol); - else if (protocol == PasteCodeDotXyzProtocol::protocolName().toLower()) - m_protocol.reset(new PasteCodeDotXyzProtocol); + else if (protocol == DPasteDotComProtocol::protocolName().toLower()) + m_protocol.reset(new DPasteDotComProtocol); else qFatal("Internal error: Invalid protocol."); } @@ -88,8 +88,8 @@ int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); - const QStringList protocols = {PasteBinDotComProtocol::protocolName().toLower(), - PasteCodeDotXyzProtocol::protocolName().toLower()}; + const QStringList protocols = {DPasteDotComProtocol::protocolName().toLower(), + PasteBinDotComProtocol::protocolName().toLower()}; ArgumentsCollector argsCollector(protocols); QStringList arguments = QCoreApplication::arguments(); arguments.removeFirst(); |