From 3629e091c448f4a7418f3fd7dad830c5b4df8933 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Mon, 13 Jul 2009 08:32:46 +0200 Subject: refactor and add support for pastebin.com - created protocol class as basis for different paste servers - removed custom classes and replaced functionality with simple QHttp* usage - removed poster and fetcher classes copied from cpaster application. It not getting updated anyways in creator - Known issue: Listing does not update, when user changes protocol - TODO: add pastebin.ca support. Code is done already, just needs to be placed inside plugin. --- src/plugins/cpaster/codepasterprotocol.cpp | 154 ++++++++++++++++++ src/plugins/cpaster/codepasterprotocol.h | 78 +++++++++ src/plugins/cpaster/codepastersettings.cpp | 104 ++++++++++++ src/plugins/cpaster/codepastersettings.h | 74 +++++++++ src/plugins/cpaster/cpaster.pro | 23 ++- src/plugins/cpaster/cpasterplugin.cpp | 174 +++++++------------- src/plugins/cpaster/cpasterplugin.h | 51 +----- src/plugins/cpaster/pastebindotcomprotocol.cpp | 131 +++++++++++++++ src/plugins/cpaster/pastebindotcomprotocol.h | 73 +++++++++ src/plugins/cpaster/pastebindotcomsettings.cpp | 94 +++++++++++ src/plugins/cpaster/pastebindotcomsettings.h | 68 ++++++++ src/plugins/cpaster/pastebindotcomsettings.ui | 66 ++++++++ src/plugins/cpaster/pasteselect.ui | 24 +-- src/plugins/cpaster/pasteview.cpp | 193 ++++++++++++++++++++++ src/plugins/cpaster/pasteview.h | 65 ++++++++ src/plugins/cpaster/pasteview.ui | 211 +++++++++++++++++++++++++ src/plugins/cpaster/protocol.cpp | 65 ++++++++ src/plugins/cpaster/protocol.h | 66 ++++++++ src/plugins/cpaster/settingspage.cpp | 18 ++- src/plugins/cpaster/settingspage.h | 7 +- src/plugins/cpaster/settingspage.ui | 78 +++++---- 21 files changed, 1601 insertions(+), 216 deletions(-) create mode 100644 src/plugins/cpaster/codepasterprotocol.cpp create mode 100644 src/plugins/cpaster/codepasterprotocol.h create mode 100644 src/plugins/cpaster/codepastersettings.cpp create mode 100644 src/plugins/cpaster/codepastersettings.h create mode 100644 src/plugins/cpaster/pastebindotcomprotocol.cpp create mode 100644 src/plugins/cpaster/pastebindotcomprotocol.h create mode 100644 src/plugins/cpaster/pastebindotcomsettings.cpp create mode 100644 src/plugins/cpaster/pastebindotcomsettings.h create mode 100644 src/plugins/cpaster/pastebindotcomsettings.ui create mode 100644 src/plugins/cpaster/pasteview.cpp create mode 100644 src/plugins/cpaster/pasteview.h create mode 100644 src/plugins/cpaster/pasteview.ui create mode 100644 src/plugins/cpaster/protocol.cpp create mode 100644 src/plugins/cpaster/protocol.h (limited to 'src/plugins') diff --git a/src/plugins/cpaster/codepasterprotocol.cpp b/src/plugins/cpaster/codepasterprotocol.cpp new file mode 100644 index 0000000000..26406a3150 --- /dev/null +++ b/src/plugins/cpaster/codepasterprotocol.cpp @@ -0,0 +1,154 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#include "codepasterprotocol.h" +#include "codepastersettings.h" +#include "cpasterplugin.h" +#include "cgi.h" + +#include +#include +#include +#include +#include + +using namespace CodePaster; +using namespace Core; + +CodePasterProtocol::CodePasterProtocol() +{ + m_page = new CodePaster::CodePasterSettingsPage(); + connect(&http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), + this, SLOT(readPostResponseHeader(const QHttpResponseHeader&))); +} + +CodePasterProtocol::~CodePasterProtocol() +{ +} + +QString CodePasterProtocol::name() const +{ + return "CodePaster"; +} + +bool CodePasterProtocol::canList() const +{ + return true; +} + +void CodePasterProtocol::fetch(const QString &id) +{ + QString link = "http://"; + link.append(m_page->hostName()); + link.append("/?format=raw&id="); + link.append(id); + QUrl url(link); + QNetworkRequest r(url); + + reply = manager.get(r); + connect(reply, SIGNAL(finished()), this, SLOT(fetchFinished())); + fetchId = id; +} + +void CodePasterProtocol::list(QListWidget *listWidget) +{ + this->listWidget = listWidget; + QString link = QLatin1String("http://"); + link += m_page->hostName(); + link += QLatin1String("/?command=browse&format=raw"); + QUrl url(link); + QNetworkRequest r(url); + listReply = manager.get(r); + connect(listReply, SIGNAL(finished()), this, SLOT(listFinished())); +} + +void CodePasterProtocol::paste(const QString &text, + const QString &username, + const QString &comment, + const QString &description) +{ + QByteArray data = "command=processcreate&submit=submit&highlight_type=0&description="; + data += CGI::encodeURL(description).toLatin1(); + data += "&comment="; + data += CGI::encodeURL(comment).toLatin1(); + data += "&code="; + data += CGI::encodeURL(text).toLatin1(); + data += "&poster="; + data += CGI::encodeURL(username).toLatin1(); + + http.setHost(m_page->hostName()); + http.post("/", data); +} + +bool CodePasterProtocol::hasSettings() const +{ + return true; +} + +Core::IOptionsPage* CodePasterProtocol::settingsPage() +{ + return m_page; +} + +void CodePasterProtocol::fetchFinished() +{ + if (reply->error()) { + ICore::instance()->messageManager()->printToOutputPane(reply->errorString(), true); + } else { + QString data = reply->readAll(); + if (data.contains("No such paste!")) + ICore::instance()->messageManager()->printToOutputPane(tr("No such paste"), true); + QString title = QString::fromLatin1("Codepaster: %1").arg(fetchId); + EditorManager::instance()->newFile(Core::Constants::K_DEFAULT_TEXT_EDITOR, &title, data); + } + reply->deleteLater(); + reply = 0; +} + +void CodePasterProtocol::listFinished() +{ + if (listReply->error()) { + ICore::instance()->messageManager()->printToOutputPane(reply->errorString(), true); + } else { + QByteArray data = listReply->readAll(); + listWidget->clear(); + QStringList lines = QString(data).split(QLatin1Char('\n')); + listWidget->addItems(lines); + listWidget = 0; + } + listReply->deleteLater(); + listReply = 0; +} + +void CodePasterProtocol::readPostResponseHeader(const QHttpResponseHeader &header) +{ + QString link = header.value("location"); + if (!link.isEmpty()) + emit pasteDone(link); +} diff --git a/src/plugins/cpaster/codepasterprotocol.h b/src/plugins/cpaster/codepasterprotocol.h new file mode 100644 index 0000000000..c67edd0104 --- /dev/null +++ b/src/plugins/cpaster/codepasterprotocol.h @@ -0,0 +1,78 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#ifndef CODEPASTERPROTOCOL_H +#define CODEPASTERPROTOCOL_H +#include "protocol.h" + +#include +#include +#include +#include + +namespace CodePaster { + + class CodePasterSettingsPage; + +class CodePasterProtocol : public Protocol +{ + Q_OBJECT +public: + CodePasterProtocol(); + ~CodePasterProtocol(); + + QString name() const; + + bool canList() const; + bool hasSettings() const; + Core::IOptionsPage* settingsPage(); + + void fetch(const QString &id); + void list(QListWidget *listWidget); + void paste(const QString &text, + const QString &username = "", + const QString &comment = "", + const QString &description = ""); +public slots: + void fetchFinished(); + void listFinished(); + void readPostResponseHeader(const QHttpResponseHeader&); + +private: + CodePasterSettingsPage *m_page; + QHttp http; + QNetworkAccessManager manager; + QNetworkReply* reply; + QNetworkReply* listReply; + QListWidget* listWidget; + QString fetchId; +}; + +} +#endif // CODEPASTERPROTOCOL_H diff --git a/src/plugins/cpaster/codepastersettings.cpp b/src/plugins/cpaster/codepastersettings.cpp new file mode 100644 index 0000000000..15a33523d1 --- /dev/null +++ b/src/plugins/cpaster/codepastersettings.cpp @@ -0,0 +1,104 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#include "codepastersettings.h" + +#include + +#include +#include +#include +#include +#include + +using namespace CodePaster; + +CodePasterSettingsPage::CodePasterSettingsPage() +{ + m_settings = Core::ICore::instance()->settings(); + if (m_settings) { + m_settings->beginGroup("CodePasterSettings"); + m_host = m_settings->value("Server", "").toString(); + m_settings->endGroup(); + } +} + +QString CodePasterSettingsPage::id() const +{ + return QLatin1String("CodePaster"); +} + +QString CodePasterSettingsPage::trName() const +{ + return tr("CodePaster"); +} + +QString CodePasterSettingsPage::category() const +{ + return QLatin1String("CodePaster"); +} + +QString CodePasterSettingsPage::trCategory() const +{ + return tr("CodePaster"); +} + +QWidget *CodePasterSettingsPage::createPage(QWidget *parent) +{ + QWidget *w = new QWidget(parent); + QLabel *label = new QLabel(tr("Server:")); + QLineEdit *lineedit = new QLineEdit; + lineedit->setText(m_host); + connect(lineedit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString))); + QGridLayout* layout = new QGridLayout(); + layout->addWidget(label, 0, 0); + layout->addWidget(lineedit, 0, 1); + w->setLayout(layout); + return w; +} + +void CodePasterSettingsPage::apply() +{ + if (!m_settings) + return; + + m_settings->beginGroup("CodePasterSettings"); + m_settings->setValue("Server", m_host); + m_settings->endGroup(); +} + +void CodePasterSettingsPage::serverChanged(const QString &host) +{ + m_host = host; +} + +QString CodePasterSettingsPage::hostName() const +{ + return m_host; +} diff --git a/src/plugins/cpaster/codepastersettings.h b/src/plugins/cpaster/codepastersettings.h new file mode 100644 index 0000000000..7d6dfe9991 --- /dev/null +++ b/src/plugins/cpaster/codepastersettings.h @@ -0,0 +1,74 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#ifndef CODEPASTERSETTINGSPAGE_H +#define CODEPASTERSETTINGSPAGE_H + +#include "ui_settingspage.h" + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace CodePaster { + +class CodePasterSettingsPage : public Core::IOptionsPage +{ + Q_OBJECT + +public: + CodePasterSettingsPage(); + + QString id() const; + QString trName() const; + QString category() const; + QString trCategory() const; + + QWidget *createPage(QWidget *parent); + void apply(); + void finish() { } + + QString hostName() const; +public slots: + void serverChanged(const QString &host); + +private: + QSettings *m_settings; + QString m_host; +}; + +} // namespace CodePaster + +#endif // SETTINGSPAGE_H diff --git a/src/plugins/cpaster/cpaster.pro b/src/plugins/cpaster/cpaster.pro index e12ba9845f..dc4dfd4ae9 100644 --- a/src/plugins/cpaster/cpaster.pro +++ b/src/plugins/cpaster/cpaster.pro @@ -1,15 +1,26 @@ QT += network TEMPLATE = lib TARGET = CodePaster - include(../../qtcreatorplugin.pri) include(cpaster_dependencies.pri) - HEADERS += cpasterplugin.h \ - settingspage.h + settingspage.h \ + protocol.h \ + codepasterprotocol.h \ + pasteview.h \ + codepastersettings.h \ + pastebindotcomprotocol.h \ + pastebindotcomsettings.h SOURCES += cpasterplugin.cpp \ - settingspage.cpp + settingspage.cpp \ + protocol.cpp \ + codepasterprotocol.cpp \ + pasteview.cpp \ + codepastersettings.cpp \ + pastebindotcomprotocol.cpp \ + pastebindotcomsettings.cpp FORMS += settingspage.ui \ - pasteselect.ui - + pasteselect.ui \ + pasteview.ui \ + pastebindotcomsettings.ui include(../../shared/cpaster/cpaster.pri) diff --git a/src/plugins/cpaster/cpasterplugin.cpp b/src/plugins/cpaster/cpasterplugin.cpp index 31aca66d7d..d4ca9a4daf 100644 --- a/src/plugins/cpaster/cpasterplugin.cpp +++ b/src/plugins/cpaster/cpasterplugin.cpp @@ -32,7 +32,9 @@ #include "ui_pasteselect.h" #include "splitter.h" -#include "view.h" +#include "pasteview.h" +#include "codepasterprotocol.h" +#include "pastebindotcomprotocol.h" #include #include @@ -59,7 +61,7 @@ using namespace Core; using namespace TextEditor; CodepasterPlugin::CodepasterPlugin() - : m_settingsPage(0), m_fetcher(0), m_poster(0) + : m_settingsPage(0) { } @@ -70,6 +72,8 @@ CodepasterPlugin::~CodepasterPlugin() delete m_settingsPage; m_settingsPage = 0; } + foreach(Protocol* item, m_protocols) + removeObject(item->settingsPage()); } bool CodepasterPlugin::initialize(const QStringList &arguments, QString *error_message) @@ -85,6 +89,18 @@ bool CodepasterPlugin::initialize(const QStringList &arguments, QString *error_m m_settingsPage = new SettingsPage(); addObject(m_settingsPage); + // Create the protocols and append them to the Settings + Protocol *protos[] = { new CodePasterProtocol(), + new PasteBinDotComProtocol(), + 0}; + for(int i=0; protos[i] != 0; ++i) { + connect(protos[i], SIGNAL(pasteDone(QString)), this, SLOT(finishPost(QString))); + m_settingsPage->addProtocol(protos[i]->name()); + if (protos[i]->hasSettings()) + addObject(protos[i]->settingsPage()); + m_protocols.append(protos[i]); + } + //register actions Core::ActionManager *actionManager = ICore::instance()->actionManager(); @@ -121,23 +137,8 @@ void CodepasterPlugin::extensionsInitialized() { } -QString CodepasterPlugin::serverUrl() const -{ - QString url = m_settingsPage->serverUrl().toString(); - if (url.startsWith("http://")) - url = url.mid(7); - if (url.endsWith('/')) - url.chop(1); - return url; -} - void CodepasterPlugin::post() { - // FIXME: The whole m_poster thing is de facto a simple function call. - if (m_poster) { - delete m_poster; - m_poster = 0; - } IEditor* editor = EditorManager::instance()->currentEditor(); ITextEditor* textEditor = qobject_cast(editor); if (!textEditor) @@ -170,8 +171,13 @@ void CodepasterPlugin::post() QString username = m_settingsPage->username(); QString description; QString comment; + QString protocolName; + + PasteView view(0); + foreach (Protocol *p, m_protocols) { + view.addProtocol(p->name(), p->name() == m_settingsPage->defaultProtocol()); + } - View view(0); if (!view.show(username, description, comment, lst)) return; // User canceled post @@ -179,12 +185,7 @@ void CodepasterPlugin::post() description = view.getDescription(); comment = view.getComment(); data = view.getContent(); - - // Submit to codepaster - - m_poster = new CustomPoster(serverUrl(), - m_settingsPage->copyToClipBoard(), - m_settingsPage->displayOutput()); + protocolName = view.getProtocol(); // Copied from cpaster. Otherwise lineendings will screw up if (!data.contains("\r\n")) { @@ -193,118 +194,61 @@ void CodepasterPlugin::post() else if (data.contains('\r')) data.replace('\r', "\r\n"); } - m_poster->post(description, comment, data, username); + + foreach(Protocol *protocol, m_protocols) { + if (protocol->name() == protocolName) { + protocol->paste(data, username, comment, description); + break; + } + } + } void CodepasterPlugin::fetch() { - if (m_fetcher) { - delete m_fetcher; - m_fetcher = 0; - } - m_fetcher = new CustomFetcher(serverUrl()); - QDialog dialog(ICore::instance()->mainWindow()); Ui_PasteSelectDialog ui; ui.setupUi(&dialog); + foreach(const Protocol *protocol, m_protocols) + ui.protocolBox->addItem(protocol->name()); + ui.protocolBox->setCurrentIndex(ui.protocolBox->findText(m_settingsPage->defaultProtocol())); - ui.listWidget->addItems(QStringList() << tr("Waiting for items")); + ui.listWidget->addItems(QStringList() << tr("This protocol supports no listing")); ui.listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); ui.listWidget->setFrameStyle(QFrame::NoFrame); - m_fetcher->list(ui.listWidget); + // ### TODO2: when we change the protocol, we need to relist + foreach(Protocol *protocol, m_protocols) { + if (protocol->name() == ui.protocolBox->currentText() && protocol->canList()) { + ui.listWidget->clear(); + ui.listWidget->addItems(QStringList() << tr("Waiting for items")); + protocol->list(ui.listWidget); + break; + } + } int result = dialog.exec(); if (!result) return; - bool ok; QStringList list = ui.pasteEdit->text().split(QLatin1Char(' ')); - int pasteID = !list.isEmpty() ? list.first().toInt(&ok) : -1; - if (!ok || pasteID <= 0) + if (list.isEmpty()) return; + QString pasteID = list.first(); - delete m_fetcher; - m_fetcher = new CustomFetcher(serverUrl()); - m_fetcher->fetch(pasteID); -} - -CustomFetcher::CustomFetcher(const QString &host) - : Fetcher(host) - , m_host(host) - , m_listWidget(0) - , m_id(-1) - , m_customError(false) -{ - // cpaster calls QCoreApplication::exit which we want to avoid here - disconnect(this, SIGNAL(requestFinished(int,bool)) - ,this, SLOT(gotRequestFinished(int,bool))); - connect(this, SIGNAL(requestFinished(int,bool)) - , SLOT(customRequestFinished(int,bool))); -} - -void CustomFetcher::customRequestFinished(int, bool error) -{ - m_customError = error; - if (m_customError || hadError()) { - QMessageBox::warning(0, tr("CodePaster Error") - , tr("Could not fetch code") - , QMessageBox::Ok); - return; - } - - QByteArray data = body(); - if (!m_listWidget) { - QString title = QString::fromLatin1("CodePaster: %1").arg(m_id); - EditorManager::instance()->newFile(Core::Constants::K_DEFAULT_TEXT_EDITOR, &title, data); - } else { - m_listWidget->clear(); - QStringList lines = QString(data).split(QLatin1Char('\n')); - m_listWidget->addItems(lines); - m_listWidget = 0; + // Get Protocol + foreach(Protocol *protocol, m_protocols) { + if (protocol->name() == ui.protocolBox->currentText()) { + protocol->fetch(pasteID); + break; + } } } -int CustomFetcher::fetch(int pasteID) +void CodepasterPlugin::finishPost(const QString &link) { - m_id = pasteID; - return Fetcher::fetch(pasteID); -} - -void CustomFetcher::list(QListWidget* list) -{ - m_listWidget = list; - QString url = QLatin1String("http://"); - url += m_host; - url += QLatin1String("/?command=browse&format=raw"); - Fetcher::fetch(url); -} - -CustomPoster::CustomPoster(const QString &host, bool copyToClipboard, bool displayOutput) - : Poster(host), m_copy(copyToClipboard), m_output(displayOutput) -{ - // cpaster calls QCoreApplication::exit which we want to avoid here - disconnect(this, SIGNAL(requestFinished(int,bool)), - this, SLOT(gotRequestFinished(int,bool))); - connect(this, SIGNAL(requestFinished(int,bool)), - SLOT(customRequestFinished(int,bool))); -} - -void CustomPoster::customRequestFinished(int, bool error) -{ - if (!error) { - if (m_copy) - QApplication::clipboard()->setText(pastedUrl()); - ICore::instance()->messageManager()->printToOutputPane(pastedUrl(), m_output); - } else - QMessageBox::warning(0, tr("CodePaster Error"), tr("Some error occured while posting"), QMessageBox::Ok); -#if 0 // Figure out how to access - Core::Internal::MessageOutputWindow* messageWindow = - ExtensionSystem::PluginManager::instance()->getObject(); - if (!messageWindow) - qDebug() << "Pasted at:" << pastedUrl(); - - messageWindow->append(pastedUrl()); - messageWindow->setFocus(); -#endif + if (m_settingsPage->copyToClipBoard()) + QApplication::clipboard()->setText(link); + ICore::instance()->messageManager()->printToOutputPane(link, + m_settingsPage->displayOutput()); } Q_EXPORT_PLUGIN(CodepasterPlugin) diff --git a/src/plugins/cpaster/cpasterplugin.h b/src/plugins/cpaster/cpasterplugin.h index c4a4bc13bc..ea2af4a7e8 100644 --- a/src/plugins/cpaster/cpasterplugin.h +++ b/src/plugins/cpaster/cpasterplugin.h @@ -31,14 +31,14 @@ #define CODEPASTERPLUGIN_H #include "settingspage.h" -#include "fetcher.h" -#include "poster.h" +#include "protocol.h" #include #include #include #include +#include QT_BEGIN_NAMESPACE class QListWidget; @@ -63,54 +63,13 @@ public: public slots: void post(); void fetch(); + void finishPost(const QString &link); private: - QString serverUrl() const; - QAction *m_postAction; QAction *m_fetchAction; - SettingsPage *m_settingsPage; - CustomFetcher *m_fetcher; - CustomPoster *m_poster; -}; - - -class CustomFetcher : public Fetcher -{ - Q_OBJECT - -public: - CustomFetcher(const QString &host); - - int fetch(int pasteID); - bool hadCustomError() { return m_customError; } - - void list(QListWidget *); - -private slots: - void customRequestFinished(int id, bool error); - -private: - QString m_host; - QListWidget *m_listWidget; - int m_id; - bool m_customError; -}; - - -class CustomPoster : public Poster -{ - Q_OBJECT -public: - CustomPoster(const QString &host, bool copyToClipboard = true, - bool displayOutput = true); - -private slots: - void customRequestFinished(int id, bool error); - -private: - bool m_copy; - bool m_output; + SettingsPage *m_settingsPage; + QList m_protocols; }; } // namespace CodePaster diff --git a/src/plugins/cpaster/pastebindotcomprotocol.cpp b/src/plugins/cpaster/pastebindotcomprotocol.cpp new file mode 100644 index 0000000000..166fb93632 --- /dev/null +++ b/src/plugins/cpaster/pastebindotcomprotocol.cpp @@ -0,0 +1,131 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#include "pastebindotcomprotocol.h" +#include "pastebindotcomsettings.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace Core; + +PasteBinDotComProtocol::PasteBinDotComProtocol() +{ + settings = new PasteBinDotComSettings(); + connect(&http, SIGNAL(requestFinished(int,bool)), + this, SLOT(postRequestFinished(int,bool))); + connect(&http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), + this, SLOT(readPostResponseHeader(const QHttpResponseHeader&))); +} + +void PasteBinDotComProtocol::fetch(const QString &id) +{ + QString link = QLatin1String("http://"); + if (!settings->hostPrefix().isEmpty()) + link.append(QString("%1.").arg(settings->hostPrefix())); + link.append("pastebin.com/pastebin.php?dl="); + link.append(id); + QUrl url(link); + QNetworkRequest r(url); + + reply = manager.get(r); + connect(reply, SIGNAL(finished()), this, SLOT(fetchFinished())); + fetchId = id; +} + +void PasteBinDotComProtocol::paste(const QString &text, + const QString &username, + const QString &comment, + const QString &description) +{ + Q_UNUSED(comment); + Q_UNUSED(description); + QString data = "code2="; + data += text; + data += "&parent_pid=&format=text&expiry=d&poster="; + data += username; + data += "&paste=Send"; + QHttpRequestHeader header("POST", "/pastebin.php"); + header.setValue("host", "qt.pastebin.com" ); + header.setContentType("application/x-www-form-urlencoded"); + http.setHost("qt.pastebin.com", QHttp::ConnectionModeHttp); + header.setValue("User-Agent", "CreatorPastebin"); + postId = http.request(header, data.toAscii()); +} + +void PasteBinDotComProtocol::readPostResponseHeader(const QHttpResponseHeader &header) +{ + switch (header.statusCode()) + { + // If we receive any of those, everything is bon. + case 200: + case 301: + case 303: + case 307: + break; + + case 302: { + QString link = header.value("Location"); + emit pasteDone(link); + break; + } + default: + emit pasteDone(tr("Error during paste")); + } +} + +void PasteBinDotComProtocol::postRequestFinished(int id, bool error) +{ + if (id == postId && error) + emit pasteDone(http.errorString()); +} + +void PasteBinDotComProtocol::fetchFinished() +{ + if (reply->error()) { + ICore::instance()->messageManager()->printToOutputPane(reply->errorString(), true); + } else { + QString title = QString::fromLatin1("Pastebin.com: %1").arg(fetchId); + QString data = reply->readAll(); + EditorManager::instance()->newFile(Core::Constants::K_DEFAULT_TEXT_EDITOR, &title, data); + } + reply->deleteLater(); +} + +Core::IOptionsPage* PasteBinDotComProtocol::settingsPage() +{ + return settings; +} diff --git a/src/plugins/cpaster/pastebindotcomprotocol.h b/src/plugins/cpaster/pastebindotcomprotocol.h new file mode 100644 index 0000000000..b7600d653f --- /dev/null +++ b/src/plugins/cpaster/pastebindotcomprotocol.h @@ -0,0 +1,73 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#ifndef PASTEBINDOTCOMPROTOCOL_H +#define PASTEBINDOTCOMPROTOCOL_H +#include "protocol.h" +#include +#include +#include + +class PasteBinDotComSettings; + +class PasteBinDotComProtocol : public Protocol +{ + Q_OBJECT +public: + PasteBinDotComProtocol(); + + QString name() const { return QLatin1String("Pastebin.Com"); } + + bool hasSettings() const { return true; } + Core::IOptionsPage* settingsPage(); + + bool canList() const { return false; } + + void fetch(const QString &id); + void paste(const QString &text, + const QString &username = "", + const QString &comment = "", + const QString &description = ""); +public slots: + void fetchFinished(); + + void postRequestFinished(int id, bool error); + void readPostResponseHeader(const QHttpResponseHeader&); + +private: + PasteBinDotComSettings *settings; + QNetworkAccessManager manager; + QNetworkReply *reply; + QString fetchId; + + QHttp http; + int postId; +}; + +#endif // PASTEBINDOTCOMPROTOCOL_H diff --git a/src/plugins/cpaster/pastebindotcomsettings.cpp b/src/plugins/cpaster/pastebindotcomsettings.cpp new file mode 100644 index 0000000000..98a3cbc28f --- /dev/null +++ b/src/plugins/cpaster/pastebindotcomsettings.cpp @@ -0,0 +1,94 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#include "pastebindotcomsettings.h" +#include "ui_pastebindotcomsettings.h" + +#include +#include + +PasteBinDotComSettings::PasteBinDotComSettings() +{ + m_settings = Core::ICore::instance()->settings(); + if (m_settings) { + m_settings->beginGroup("PasteBinDotComSettings"); + m_hostPrefix = m_settings->value("Prefix", "").toString(); + m_settings->endGroup(); + } +} + +QString PasteBinDotComSettings::id() const +{ + return QLatin1String("Pastebin.com"); +} + +QString PasteBinDotComSettings::trName() const +{ + return tr("Pastebin.com"); +} + +QString PasteBinDotComSettings::category() const +{ + return QLatin1String("CodePaster"); +} + +QString PasteBinDotComSettings::trCategory() const +{ + return tr("CodePaster"); +} + +QWidget *PasteBinDotComSettings::createPage(QWidget *parent) +{ + Ui_PasteBinComSettingsWidget* ui = new Ui_PasteBinComSettingsWidget; + QWidget *w = new QWidget(parent); + ui->setupUi(w); + ui->lineEdit->setText(hostPrefix()); + connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(serverChanged(QString))); + return w; +} + +void PasteBinDotComSettings::apply() +{ + if (!m_settings) + return; + + m_settings->beginGroup("PasteBinDotComSettings"); + m_settings->setValue("Prefix", m_hostPrefix); + m_settings->endGroup(); +} + +void PasteBinDotComSettings::serverChanged(const QString &prefix) +{ + m_hostPrefix = prefix; +} + +QString PasteBinDotComSettings::hostPrefix() const +{ + return m_hostPrefix; +} diff --git a/src/plugins/cpaster/pastebindotcomsettings.h b/src/plugins/cpaster/pastebindotcomsettings.h new file mode 100644 index 0000000000..41f6ee5fdc --- /dev/null +++ b/src/plugins/cpaster/pastebindotcomsettings.h @@ -0,0 +1,68 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#ifndef PASTEBINDOTCOMSETTINGS_H +#define PASTEBINDOTCOMSETTINGS_H + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +class PasteBinDotComSettings : public Core::IOptionsPage +{ + Q_OBJECT + +public: + PasteBinDotComSettings(); + + QString id() const; + QString trName() const; + QString category() const; + QString trCategory() const; + + QWidget *createPage(QWidget *parent); + void apply(); + void finish() { } + + QString hostPrefix() const; +public slots: + void serverChanged(const QString &host); + +private: + QSettings *m_settings; + QString m_hostPrefix; +}; + +#endif diff --git a/src/plugins/cpaster/pastebindotcomsettings.ui b/src/plugins/cpaster/pastebindotcomsettings.ui new file mode 100644 index 0000000000..10a19e05d1 --- /dev/null +++ b/src/plugins/cpaster/pastebindotcomsettings.ui @@ -0,0 +1,66 @@ + + + PasteBinComSettingsWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + Server Prefix: + + + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://pastebin.com"><span style=" text-decoration: underline; color:#0000ff;">pastebin.com</span></a><span style=" font-size:8pt;"> allows to send posts to custom subdomains (eg. qtcreator.pastebin.com). Fill in the desired prefix.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Note that the plugin will use this for posting as well as fetching.</span></p></body></html> + + + Qt::RichText + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 135 + + + + + + + + + diff --git a/src/plugins/cpaster/pasteselect.ui b/src/plugins/cpaster/pasteselect.ui index 6c5f99ceee..05c6697cb5 100644 --- a/src/plugins/cpaster/pasteselect.ui +++ b/src/plugins/cpaster/pasteselect.ui @@ -7,7 +7,7 @@ 0 0 451 - 215 + 308 @@ -18,14 +18,18 @@ - - - 6 - - - QLayout::SetDefaultConstraint - - + + + + + Protocol: + + + + + + + @@ -38,7 +42,7 @@ - + diff --git a/src/plugins/cpaster/pasteview.cpp b/src/plugins/cpaster/pasteview.cpp new file mode 100644 index 0000000000..2466a8a290 --- /dev/null +++ b/src/plugins/cpaster/pasteview.cpp @@ -0,0 +1,193 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#include "pasteview.h" + +#include +#include +#include +#include +#include + +class ColumnIndicatorTextEdit : public QTextEdit +{ +public: + ColumnIndicatorTextEdit(QWidget *parent) : QTextEdit(parent), m_columnIndicator(0) + { + QFont font; + font.setFamily(QString::fromUtf8("Courier New")); + //font.setPointSizeF(8.0); + setFont(font); + setReadOnly(true); + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + sizePolicy.setVerticalStretch(3); + setSizePolicy(sizePolicy); + int cmx = 0, cmy = 0, cmw = 0, cmh = 0; + getContentsMargins(&cmx, &cmy, &cmw, &cmh); + m_columnIndicator = QFontMetrics(font).width('W') * 100 + cmx + 1; + m_columnIndicatorFont.setFamily(QString::fromUtf8("Times")); + m_columnIndicatorFont.setPointSizeF(7.0); + } + + int m_columnIndicator; + QFont m_columnIndicatorFont; + +protected: + virtual void paintEvent(QPaintEvent *event); +}; + +void ColumnIndicatorTextEdit::paintEvent(QPaintEvent *event) +{ + QTextEdit::paintEvent(event); + + QPainter p(viewport()); + p.setFont(m_columnIndicatorFont); + p.setPen(QPen(QColor(0xa0, 0xa0, 0xa0, 0xa0))); + p.drawLine(m_columnIndicator, 0, m_columnIndicator, viewport()->height()); + int yOffset = verticalScrollBar()->value(); + p.drawText(m_columnIndicator + 1, m_columnIndicatorFont.pointSize() - yOffset, "100"); +} + +// ------------------------------------------------------------------------------------------------- + + +PasteView::PasteView(QWidget *parent) + : QDialog(parent) +{ + m_ui.setupUi(this); + + // Swap out the Patch PasteView widget with a ColumnIndicatorTextEdit, which will indicate column 100 + delete m_ui.uiPatchView; + m_ui.uiPatchView = new ColumnIndicatorTextEdit(m_ui.groupBox); + m_ui.vboxLayout1->addWidget(m_ui.uiPatchView); + m_ui.buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Paste")); + connect(m_ui.uiPatchList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(contentChanged())); +} + +PasteView::~PasteView() +{ +} + +QString PasteView::getUser() +{ + const QString username = m_ui.uiUsername->text(); + if (username.isEmpty() || username == tr("")) + return "Anonymous"; + return username; +} + +QString PasteView::getDescription() +{ + const QString description = m_ui.uiDescription->text(); + if (description == tr("")) + return QString(); + return description; +} + +QString PasteView::getComment() +{ + const QString comment = m_ui.uiComment->toPlainText(); + if (comment == tr("")) + return QString(); + return comment; +} + +QByteArray PasteView::getContent() +{ + QByteArray newContent; + for (int i = 0; i < m_ui.uiPatchList->count(); ++i) { + QListWidgetItem *item = m_ui.uiPatchList->item(i); + if (item->checkState() != Qt::Unchecked) + newContent += m_parts.at(i).content; + } + return newContent; +} + +QString PasteView::getProtocol() +{ + return m_ui.protocolBox->currentText(); +} + +void PasteView::contentChanged() +{ + m_ui.uiPatchView->setPlainText(getContent()); +} + +int PasteView::show(const QString &user, const QString &description, const QString &comment, + const FileDataList &parts) +{ + if (user.isEmpty()) + m_ui.uiUsername->setText(tr("")); + else + m_ui.uiUsername->setText(user); + + if (description.isEmpty()) + m_ui.uiDescription->setText(tr("")); + else + m_ui.uiDescription->setText(description); + + if (comment.isEmpty()) + m_ui.uiComment->setPlainText(tr("")); + else + m_ui.uiComment->setPlainText(comment); + + QByteArray content; + m_parts = parts; + m_ui.uiPatchList->clear(); + foreach (const FileData part, parts) { + QListWidgetItem *itm = new QListWidgetItem(part.filename, m_ui.uiPatchList); + itm->setCheckState(Qt::Checked); + itm->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); + content += part.content; + } + m_ui.uiPatchView->setPlainText(content); + + m_ui.uiDescription->setFocus(); + m_ui.uiDescription->selectAll(); + + // (Re)store dialog size + QSettings settings("Trolltech", "cpaster"); + int h = settings.value("/gui/height", height()).toInt(); + int w = settings.value("/gui/width", + ((ColumnIndicatorTextEdit*)m_ui.uiPatchView)->m_columnIndicator + 50) + .toInt(); + resize(w, h); + int ret = QDialog::exec(); + settings.setValue("/gui/height", height()); + settings.setValue("/gui/width", width()); + + return ret; +} + +void PasteView::addProtocol(const QString &protocol, bool defaultProtocol) +{ + m_ui.protocolBox->addItem(protocol); + if (defaultProtocol) + m_ui.protocolBox->setCurrentIndex(m_ui.protocolBox->findText(protocol)); +} diff --git a/src/plugins/cpaster/pasteview.h b/src/plugins/cpaster/pasteview.h new file mode 100644 index 0000000000..7554e6be9c --- /dev/null +++ b/src/plugins/cpaster/pasteview.h @@ -0,0 +1,65 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#ifndef PASTEVIEW_H +#define PASTEVIEW_H + +#include +#include + +#include "splitter.h" +#include "ui_pasteview.h" + +class PasteView : public QDialog +{ + Q_OBJECT +public: + PasteView(QWidget *parent); + ~PasteView(); + + int show(const QString &user, const QString &description, const QString &comment, + const FileDataList &parts); + + void addProtocol(const QString &protocol, bool defaultProtocol = false); + + QString getUser(); + QString getDescription(); + QString getComment(); + QByteArray getContent(); + QString getProtocol(); + +private slots: + void contentChanged(); + +private: + Ui::ViewDialog m_ui; + FileDataList m_parts; +}; + +#endif // VIEW_H diff --git a/src/plugins/cpaster/pasteview.ui b/src/plugins/cpaster/pasteview.ui new file mode 100644 index 0000000000..3efe66c7ce --- /dev/null +++ b/src/plugins/cpaster/pasteview.ui @@ -0,0 +1,211 @@ + + + ViewDialog + + + + 0 + 0 + 600 + 500 + + + + Send to Codepaster + + + + + + + + Protocol: + + + + + + + + + + &Username: + + + uiUsername + + + + + + + <Username> + + + + + + + &Description: + + + uiDescription + + + + + + + <Description> + + + + + + + + + + 0 + 0 + + + + + 16777215 + 100 + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:9pt;">&lt;Comment&gt;</span></p></body></html> + + + + + + + + 0 + 0 + + + + Parts to send to server + + + true + + + + 2 + + + 0 + + + + + + 0 + 1 + + + + true + + + + Patch 1 + + + + + Patch 2 + + + + + + + + + 0 + 3 + + + + + Courier New + + + + true + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + uiUsername + uiDescription + uiComment + buttonBox + uiPatchList + uiPatchView + + + + + buttonBox + accepted() + ViewDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ViewDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/cpaster/protocol.cpp b/src/plugins/cpaster/protocol.cpp new file mode 100644 index 0000000000..152749186f --- /dev/null +++ b/src/plugins/cpaster/protocol.cpp @@ -0,0 +1,65 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ +#include "protocol.h" + +#include + +Protocol::Protocol() + : QObject() +{ +} + +Protocol::~Protocol() +{ +} + +bool Protocol::canFetch() const +{ + return true; +} + +bool Protocol::canPost() const +{ + return true; +} + +bool Protocol::hasSettings() const +{ + return false; +} + +Core::IOptionsPage* Protocol::settingsPage() +{ + return 0; +} + +void Protocol::list(QListWidget*) +{ + qFatal("Base Protocol list() called"); +} diff --git a/src/plugins/cpaster/protocol.h b/src/plugins/cpaster/protocol.h new file mode 100644 index 0000000000..a45c04790c --- /dev/null +++ b/src/plugins/cpaster/protocol.h @@ -0,0 +1,66 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ +#ifndef PROTOCOL_H +#define PROTOCOL_H +#include "settingspage.h" + +#include + +#include +#include + +class QListWidget; + +class Protocol : public QObject +{ + Q_OBJECT +public: + Protocol(); + virtual ~Protocol(); + + virtual QString name() const = 0; + + bool canFetch() const; + bool canPost() const; + virtual bool canList() const = 0; + virtual bool hasSettings() const; + virtual Core::IOptionsPage* settingsPage(); + + virtual void fetch(const QString &id) = 0; + virtual void list(QListWidget *listWidget); + virtual void paste(const QString &text, + const QString &username = "", + const QString &comment = "", + const QString &description = "") = 0; + +signals: + void pasteDone(const QString &link); +}; + +#endif // PROTOCOL_H diff --git a/src/plugins/cpaster/settingspage.cpp b/src/plugins/cpaster/settingspage.cpp index 897bc57e18..5b447c32c9 100644 --- a/src/plugins/cpaster/settingspage.cpp +++ b/src/plugins/cpaster/settingspage.cpp @@ -45,7 +45,7 @@ SettingsPage::SettingsPage() if (m_settings) { m_settings->beginGroup("CodePaster"); m_username = m_settings->value("UserName", qgetenv("USER")).toString(); - m_server = m_settings->value("Server", "").toUrl(); + m_protocol = m_settings->value("DefaultProtocol", "CodePaster").toString(); m_copy = m_settings->value("CopyToClipboard", true).toBool(); m_output = m_settings->value("DisplayOutput", true).toBool(); m_settings->endGroup(); @@ -76,8 +76,9 @@ QWidget *SettingsPage::createPage(QWidget *parent) { QWidget *w = new QWidget(parent); m_ui.setupUi(w); + m_ui.defaultProtocol->clear(); + m_ui.defaultProtocol->insertItems(0, m_protocols); m_ui.userEdit->setText(m_username); - m_ui.serverEdit->setText(m_server.toString()); m_ui.clipboardBox->setChecked(m_copy); m_ui.displayBox->setChecked(m_output); return w; @@ -86,7 +87,7 @@ QWidget *SettingsPage::createPage(QWidget *parent) void SettingsPage::apply() { m_username = m_ui.userEdit->text(); - m_server = QUrl(m_ui.serverEdit->text()); + m_protocol = m_ui.defaultProtocol->currentText(); m_copy = m_ui.clipboardBox->isChecked(); m_output = m_ui.displayBox->isChecked(); @@ -95,18 +96,23 @@ void SettingsPage::apply() m_settings->beginGroup("CodePaster"); m_settings->setValue("UserName", m_username); - m_settings->setValue("Server", m_server); + m_settings->setValue("DefaultProtocol", m_protocol); m_settings->setValue("CopyToClipboard", m_copy); m_settings->setValue("DisplayOutput", m_output); m_settings->endGroup(); } +void SettingsPage::addProtocol(const QString &name) +{ + m_protocols.append(name); +} + QString SettingsPage::username() const { return m_username; } -QUrl SettingsPage::serverUrl() const +QString SettingsPage::defaultProtocol() const { - return m_server; + return m_protocol; } diff --git a/src/plugins/cpaster/settingspage.h b/src/plugins/cpaster/settingspage.h index 761295e25b..f7e3e36844 100644 --- a/src/plugins/cpaster/settingspage.h +++ b/src/plugins/cpaster/settingspage.h @@ -34,6 +34,7 @@ #include +#include #include #include @@ -59,8 +60,9 @@ public: void apply(); void finish() { } + void addProtocol(const QString& name); QString username() const; - QUrl serverUrl() const; + QString defaultProtocol() const; inline bool copyToClipBoard() const { return m_copy; } inline bool displayOutput() const { return m_output; } @@ -69,8 +71,9 @@ private: Ui_SettingsPage m_ui; QSettings *m_settings; + QStringList m_protocols; QString m_username; - QUrl m_server; + QString m_protocol; bool m_copy; bool m_output; }; diff --git a/src/plugins/cpaster/settingspage.ui b/src/plugins/cpaster/settingspage.ui index 0ad3e9613b..3dc2f9a939 100644 --- a/src/plugins/cpaster/settingspage.ui +++ b/src/plugins/cpaster/settingspage.ui @@ -1,58 +1,74 @@ - + CodePaster::SettingsPage - - + + 0 0 - 341 - 258 + 362 + 320 - + - - - + + + 0 0 - + General - - - - - CodePaster Server: + + + + + Default Protocol: - - + + + + + CodePaster + + + + + Pastebin.ca + + + + + Pastebin.com + + + - - - + + + Username: - - + + - - - + + + Copy Paste URL to clipboard - - - + + + Display Output Pane after sending a post @@ -61,11 +77,11 @@ - - + + Qt::Vertical - + 223 100 -- cgit v1.2.1