From df33773999405350f83e295e1d563df220fa9f42 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 16 Jul 2013 13:17:58 +0200 Subject: [PATCH] Remove CodePaster protocol. Change-Id: Iad4455ba80f374968e16d5d4eeb256a7b6883552 Reviewed-by: Robert Loehning Reviewed-by: Eike Ziller --- src/plugins/cpaster/codepasterprotocol.cpp | 212 --------------------- src/plugins/cpaster/codepasterprotocol.h | 81 -------- src/plugins/cpaster/codepastersettings.cpp | 99 ---------- src/plugins/cpaster/codepastersettings.h | 63 ------ src/plugins/cpaster/cpaster.pro | 4 - src/plugins/cpaster/cpaster.qbs | 4 - src/plugins/cpaster/cpasterplugin.cpp | 2 - 7 files changed, 465 deletions(-) delete mode 100644 src/plugins/cpaster/codepasterprotocol.cpp delete mode 100644 src/plugins/cpaster/codepasterprotocol.h delete mode 100644 src/plugins/cpaster/codepastersettings.cpp delete mode 100644 src/plugins/cpaster/codepastersettings.h diff --git a/src/plugins/cpaster/codepasterprotocol.cpp b/src/plugins/cpaster/codepasterprotocol.cpp deleted file mode 100644 index 232f977a69d..00000000000 --- a/src/plugins/cpaster/codepasterprotocol.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codepasterprotocol.h" -#include "codepastersettings.h" - -#include -#include - -#include -#include - -#include -#include - -enum { debug = 0 }; - -namespace CodePaster { - -CodePasterProtocol::CodePasterProtocol() : - m_page(new CodePaster::CodePasterSettingsPage), - m_pasteReply(0), - m_fetchReply(0), - m_listReply(0), - m_fetchId(-1) -{ -} - -CodePasterProtocol::~CodePasterProtocol() -{ -} - -QString CodePasterProtocol::name() const -{ - return QLatin1String("CodePaster"); -} - -unsigned CodePasterProtocol::capabilities() const -{ - return ListCapability|PostCommentCapability|PostDescriptionCapability; -} - -bool CodePasterProtocol::checkConfiguration(QString *errorMessage) -{ - const QString hostName = m_page->hostName(); - if (hostName.isEmpty()) { - if (errorMessage) { - *errorMessage = Utils::HostOsInfo::isMacHost() - ? tr("No Server defined in the CodePaster preferences.") - : tr("No Server defined in the CodePaster options."); - } - return false; - } - // Check the host once. Note that it can be modified in the settings page. - if (m_hostChecked == hostName) - return true; - const bool ok = httpStatus(m_page->hostName(), errorMessage); - if (ok) - m_hostChecked = hostName; - return ok; -} - -void CodePasterProtocol::fetch(const QString &id) -{ - QTC_ASSERT(!m_fetchReply, return); - - QString hostName = m_page->hostName(); - const QString httpPrefix = QLatin1String("http://"); - QString link; - // Did the user enter a complete URL instead of an id? - if (id.startsWith(httpPrefix)) { - // Append 'raw' format option - link = id; - link += QLatin1String("&format=raw"); - const int idPos = id.lastIndexOf(QLatin1Char('=')); - m_fetchId = idPos != -1 ? id.mid(idPos + 1) : id; - } else { - link = httpPrefix; - link.append(hostName); - link.append(QLatin1String("/?format=raw&id=")); - link.append(id); - m_fetchId = id; - } - m_fetchReply = httpGet(link); - connect(m_fetchReply, SIGNAL(finished()), this, SLOT(fetchFinished())); -} - -void CodePasterProtocol::list() -{ - QTC_ASSERT(!m_listReply, return); - - QString hostName = m_page->hostName(); - QString link = QLatin1String("http://"); - link += hostName; - link += QLatin1String("/?command=browse&format=raw"); - m_listReply = httpGet(link); - connect(m_listReply, SIGNAL(finished()), this, SLOT(listFinished())); -} - -void CodePasterProtocol::paste(const QString &text, - ContentType /* ct */, int /* expiryDays */, - const QString &username, - const QString &comment, - const QString &description) -{ - QTC_ASSERT(!m_pasteReply, return); - const QString hostName = m_page->hostName(); - - QByteArray data = "command=processcreate&submit=submit&highlight_type=0&description="; - data += QUrl::toPercentEncoding(description); - data += "&comment="; - data += QUrl::toPercentEncoding(comment); - data += "&code="; - data += QUrl::toPercentEncoding(fixNewLines(text)); - data += "&poster="; - data += QUrl::toPercentEncoding(username); - - m_pasteReply = httpPost(QLatin1String("http://") + hostName, data); - connect(m_pasteReply, SIGNAL(finished()), this, SLOT(pasteFinished())); -} - -void CodePasterProtocol::pasteFinished() -{ - if (m_pasteReply->error()) { - qWarning("Error pasting: %s", qPrintable(m_pasteReply->errorString())); - } else { - // Cut out the href-attribute - QString contents = QString::fromLatin1(m_pasteReply->readAll()); - int hrefPos = contents.indexOf(QLatin1String("href=\"")); - if (hrefPos != -1) { - hrefPos += 6; - const int endPos = contents.indexOf(QLatin1Char('"'), hrefPos); - if (endPos != -1) - emit pasteDone(contents.mid(hrefPos, endPos - hrefPos)); - } - } - m_pasteReply->deleteLater(); - m_pasteReply = 0; -} - -bool CodePasterProtocol::hasSettings() const -{ - return true; -} - -Core::IOptionsPage *CodePasterProtocol::settingsPage() const -{ - return m_page; -} - -void CodePasterProtocol::fetchFinished() -{ - QString title; - QString content; - bool error = m_fetchReply->error(); - if (error) { - content = m_fetchReply->errorString(); - } else { - content = QString::fromLatin1(m_fetchReply->readAll()); // Codepaster does not support special characters. - if (debug) - qDebug() << content; - if (content.contains(QLatin1String("No such paste!"))) { - content = tr("No such paste"); - error = true; - } - title = QString::fromLatin1("Codepaster: %1").arg(m_fetchId); - } - m_fetchReply->deleteLater(); - m_fetchReply = 0; - emit fetchDone(title, content, error); -} - -void CodePasterProtocol::listFinished() -{ - if (m_listReply->error()) { - Core::ICore::messageManager()->printToOutputPane(m_listReply->errorString(), Core::MessageManager::NoModeSwitch); - } else { - const QByteArray data = m_listReply->readAll(); - const QStringList lines = QString::fromLatin1(data).split(QLatin1Char('\n')); - emit listDone(name(), lines); - } - m_listReply->deleteLater(); - m_listReply = 0; -} - -} // namespace CodePaster diff --git a/src/plugins/cpaster/codepasterprotocol.h b/src/plugins/cpaster/codepasterprotocol.h deleted file mode 100644 index 699d38c626e..00000000000 --- a/src/plugins/cpaster/codepasterprotocol.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEPASTERPROTOCOL_H -#define CODEPASTERPROTOCOL_H - -#include "protocol.h" - -QT_BEGIN_NAMESPACE -class QNetworkReply; -QT_END_NAMESPACE - -namespace CodePaster { - -class CodePasterSettingsPage; - -class CodePasterProtocol : public NetworkProtocol -{ - Q_OBJECT -public: - explicit CodePasterProtocol(); - ~CodePasterProtocol(); - - QString name() const; - - virtual unsigned capabilities() const; - bool hasSettings() const; - Core::IOptionsPage *settingsPage() const; - - virtual bool checkConfiguration(QString *errorMessage = 0); - void fetch(const QString &id); - void list(); - void paste(const QString &text, - ContentType ct = Text, - int expiryDays = 1, - const QString &username = QString(), - const QString &comment = QString(), - const QString &description = QString()); -public slots: - void fetchFinished(); - void listFinished(); - void pasteFinished(); - -private: - CodePasterSettingsPage *m_page; - QNetworkReply *m_pasteReply; - QNetworkReply *m_fetchReply; - QNetworkReply *m_listReply; - QString m_fetchId; - QString m_hostChecked; -}; - -} // namespace CodePaster - -#endif // CODEPASTERPROTOCOL_H diff --git a/src/plugins/cpaster/codepastersettings.cpp b/src/plugins/cpaster/codepastersettings.cpp deleted file mode 100644 index 4f2e4558e60..00000000000 --- a/src/plugins/cpaster/codepastersettings.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "codepastersettings.h" -#include "cpasterconstants.h" - -#include - -#include -#include -#include -#include -#include -#include - -static const char settingsGroupC[] = "CodePasterSettings"; -static const char serverKeyC[] = "Server"; - -namespace CodePaster { - -CodePasterSettingsPage::CodePasterSettingsPage() -{ - setId("C.CodePaster"); - setDisplayName(tr("CodePaster")); - setCategory(Constants::CPASTER_SETTINGS_CATEGORY); - setDisplayCategory(QCoreApplication::translate("CodePaster", - Constants::CPASTER_SETTINGS_TR_CATEGORY)); - - const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/'); - m_host = Core::ICore::settings()->value(keyRoot + QLatin1String(serverKeyC), QString()).toString(); -} - -QWidget *CodePasterSettingsPage::createPage(QWidget *parent) -{ - QWidget *outerWidget = new QWidget(parent); - QVBoxLayout *outerLayout = new QVBoxLayout(outerWidget); - - QFormLayout *formLayout = new QFormLayout; - formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - QLineEdit *lineEdit = new QLineEdit(m_host); - connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString))); - formLayout->addRow(tr("Server:"), lineEdit); - outerLayout->addLayout(formLayout); - outerLayout->addSpacerItem(new QSpacerItem(0, 3, QSizePolicy::Ignored, QSizePolicy::Fixed)); - - QLabel *noteLabel = new QLabel(tr("Note: Specify the host name for the CodePaster service " - "without any protocol prepended (e.g. codepaster.mycompany.com).")); - noteLabel->setWordWrap(true); - outerLayout->addWidget(noteLabel); - - outerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); - return outerWidget; -} - -void CodePasterSettingsPage::apply() -{ - QSettings *settings = Core::ICore::settings(); - const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/'); - settings->beginGroup(QLatin1String(settingsGroupC)); - settings->setValue(QLatin1String(serverKeyC), m_host); - settings->endGroup(); -} - -void CodePasterSettingsPage::serverChanged(const QString &host) -{ - m_host = host.trimmed(); -} - -QString CodePasterSettingsPage::hostName() const -{ - return m_host; -} -} // namespace CodePaster diff --git a/src/plugins/cpaster/codepastersettings.h b/src/plugins/cpaster/codepastersettings.h deleted file mode 100644 index ebc58d45ab9..00000000000 --- a/src/plugins/cpaster/codepastersettings.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CODEPASTERSETTINGSPAGE_H -#define CODEPASTERSETTINGSPAGE_H - -#include - -QT_BEGIN_NAMESPACE -class QSettings; -QT_END_NAMESPACE - -namespace CodePaster { - -class CodePasterSettingsPage : public Core::IOptionsPage -{ - Q_OBJECT - -public: - CodePasterSettingsPage(); - - QWidget *createPage(QWidget *parent); - void apply(); - void finish() { } - - QString hostName() const; - -public slots: - void serverChanged(const QString &host); - -private: - QString m_host; -}; - -} // namespace CodePaster - -#endif // SETTINGSPAGE_H diff --git a/src/plugins/cpaster/cpaster.pro b/src/plugins/cpaster/cpaster.pro index d73d6152800..f697c94e166 100644 --- a/src/plugins/cpaster/cpaster.pro +++ b/src/plugins/cpaster/cpaster.pro @@ -3,10 +3,8 @@ include(../../qtcreatorplugin.pri) HEADERS += cpasterplugin.h \ settingspage.h \ protocol.h \ - codepasterprotocol.h \ pasteview.h \ cpasterconstants.h \ - codepastersettings.h \ pastebindotcomprotocol.h \ pastebindotcaprotocol.h \ settings.h \ @@ -20,9 +18,7 @@ HEADERS += cpasterplugin.h \ SOURCES += cpasterplugin.cpp \ settingspage.cpp \ protocol.cpp \ - codepasterprotocol.cpp \ pasteview.cpp \ - codepastersettings.cpp \ pastebindotcomprotocol.cpp \ pastebindotcaprotocol.cpp \ settings.cpp \ diff --git a/src/plugins/cpaster/cpaster.qbs b/src/plugins/cpaster/cpaster.qbs index c1857e6106f..01815bb7c5c 100644 --- a/src/plugins/cpaster/cpaster.qbs +++ b/src/plugins/cpaster/cpaster.qbs @@ -12,10 +12,6 @@ QtcPlugin { cpp.includePaths: base.concat("../../shared/cpaster") files: [ - "codepasterprotocol.cpp", - "codepasterprotocol.h", - "codepastersettings.cpp", - "codepastersettings.h", "columnindicatortextedit.cpp", "columnindicatortextedit.h", "cpasterconstants.h", diff --git a/src/plugins/cpaster/cpasterplugin.cpp b/src/plugins/cpaster/cpasterplugin.cpp index 1c2e4e4a125..8b0cf24ea02 100644 --- a/src/plugins/cpaster/cpasterplugin.cpp +++ b/src/plugins/cpaster/cpasterplugin.cpp @@ -30,7 +30,6 @@ #include "cpasterplugin.h" #include "pasteview.h" -#include "codepasterprotocol.h" #include "kdepasteprotocol.h" #include "pastebindotcomprotocol.h" #include "pastebindotcaprotocol.h" @@ -133,7 +132,6 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *errorMe Protocol *protos[] = { new PasteBinDotComProtocol, new PasteBinDotCaProtocol, new KdePasteProtocol, - new CodePasterProtocol, new FileShareProtocol }; const int count = sizeof(protos) / sizeof(Protocol *);