forked from qt-creator/qt-creator
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.
This commit is contained in:
154
src/plugins/cpaster/codepasterprotocol.cpp
Normal file
154
src/plugins/cpaster/codepasterprotocol.cpp
Normal file
@@ -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 <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <coreplugin/messageoutputwindow.h>
|
||||
|
||||
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("<B>No such paste!</B>"))
|
||||
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);
|
||||
}
|
@@ -27,49 +27,52 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "fetcher.h"
|
||||
#include "cgi.h"
|
||||
#ifndef CODEPASTERPROTOCOL_H
|
||||
#define CODEPASTERPROTOCOL_H
|
||||
#include "protocol.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <QtGui/QListWidget>
|
||||
#include <QtNetwork/QHttp>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
Fetcher::Fetcher(const QString &host)
|
||||
: QHttp(host)
|
||||
namespace CodePaster {
|
||||
|
||||
class CodePasterSettingsPage;
|
||||
|
||||
class CodePasterProtocol : public Protocol
|
||||
{
|
||||
m_host = host;
|
||||
m_status = 0;
|
||||
m_hadError = false;
|
||||
connect(this, SIGNAL(requestFinished(int,bool)), SLOT(gotRequestFinished(int,bool)));
|
||||
connect(this, SIGNAL(readyRead(QHttpResponseHeader)), SLOT(gotReadyRead(QHttpResponseHeader)));
|
||||
}
|
||||
Q_OBJECT
|
||||
public:
|
||||
CodePasterProtocol();
|
||||
~CodePasterProtocol();
|
||||
|
||||
int Fetcher::fetch(const QString &url)
|
||||
{
|
||||
// qDebug("Fetcher::fetch(%s)", qPrintable(url));
|
||||
return QHttp::get(url);
|
||||
}
|
||||
QString name() const;
|
||||
|
||||
int Fetcher::fetch(int pasteID)
|
||||
{
|
||||
return fetch("http://" + m_host + "/?format=raw&id=" + QString::number(pasteID));
|
||||
}
|
||||
bool canList() const;
|
||||
bool hasSettings() const;
|
||||
Core::IOptionsPage* settingsPage();
|
||||
|
||||
void Fetcher::gotRequestFinished(int, bool error)
|
||||
{
|
||||
m_hadError = error;
|
||||
QCoreApplication::exit(error ? -1 : 0); // ends event-loop
|
||||
}
|
||||
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&);
|
||||
|
||||
void Fetcher::gotReadyRead(const QHttpResponseHeader & /* resp */)
|
||||
{
|
||||
m_body += QHttp::readAll();
|
||||
private:
|
||||
CodePasterSettingsPage *m_page;
|
||||
QHttp http;
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkReply* reply;
|
||||
QNetworkReply* listReply;
|
||||
QListWidget* listWidget;
|
||||
QString fetchId;
|
||||
};
|
||||
|
||||
// Hackish check for No Such Paste, as codepaster doesn't send a HTTP code indicating such, or
|
||||
// sends a redirect to an url indicating failure...
|
||||
if (m_body.contains("<B>No such paste!</B>")) {
|
||||
m_body.clear();
|
||||
m_status = -1;
|
||||
m_hadError = true;
|
||||
}
|
||||
}
|
||||
#endif // CODEPASTERPROTOCOL_H
|
104
src/plugins/cpaster/codepastersettings.cpp
Normal file
104
src/plugins/cpaster/codepastersettings.cpp
Normal file
@@ -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 <coreplugin/icore.h>
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
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;
|
||||
}
|
74
src/plugins/cpaster/codepastersettings.h
Normal file
74
src/plugins/cpaster/codepastersettings.h
Normal file
@@ -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 <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
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
|
@@ -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)
|
||||
|
@@ -32,7 +32,9 @@
|
||||
#include "ui_pasteselect.h"
|
||||
|
||||
#include "splitter.h"
|
||||
#include "view.h"
|
||||
#include "pasteview.h"
|
||||
#include "codepasterprotocol.h"
|
||||
#include "pastebindotcomprotocol.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
@@ -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<ITextEditor*>(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<Core::Internal::MessageOutputWindow>();
|
||||
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)
|
||||
|
@@ -31,14 +31,14 @@
|
||||
#define CODEPASTERPLUGIN_H
|
||||
|
||||
#include "settingspage.h"
|
||||
#include "fetcher.h"
|
||||
#include "poster.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
#include <coreplugin/icorelistener.h>
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QList>
|
||||
|
||||
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<Protocol*> m_protocols;
|
||||
};
|
||||
|
||||
} // namespace CodePaster
|
||||
|
131
src/plugins/cpaster/pastebindotcomprotocol.cpp
Normal file
131
src/plugins/cpaster/pastebindotcomprotocol.cpp
Normal file
@@ -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 <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <coreplugin/messageoutputwindow.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QtNetwork/QHttp>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QClipboard>
|
||||
|
||||
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;
|
||||
}
|
73
src/plugins/cpaster/pastebindotcomprotocol.h
Normal file
73
src/plugins/cpaster/pastebindotcomprotocol.h
Normal file
@@ -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 <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/QHttp>
|
||||
|
||||
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
|
94
src/plugins/cpaster/pastebindotcomsettings.cpp
Normal file
94
src/plugins/cpaster/pastebindotcomsettings.cpp
Normal file
@@ -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 <coreplugin/icore.h>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
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;
|
||||
}
|
@@ -27,34 +27,42 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef POSTER_H
|
||||
#define POSTER_H
|
||||
#ifndef PASTEBINDOTCOMSETTINGS_H
|
||||
#define PASTEBINDOTCOMSETTINGS_H
|
||||
|
||||
#include <QHttp>
|
||||
#include <QHttpResponseHeader>
|
||||
#include <QString>
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
class Poster : public QHttp
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class PasteBinDotComSettings : public Core::IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Poster(const QString &host);
|
||||
PasteBinDotComSettings();
|
||||
|
||||
void post(const QString &description, const QString &comment,
|
||||
const QString &text, const QString &user);
|
||||
QString id() const;
|
||||
QString trName() const;
|
||||
QString category() const;
|
||||
QString trCategory() const;
|
||||
|
||||
QString pastedUrl() { return m_url; }
|
||||
int status() { return m_status; }
|
||||
bool hadError() { return m_hadError; }
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
void finish() { }
|
||||
|
||||
private slots:
|
||||
void gotRequestFinished(int id, bool error);
|
||||
void gotResponseHeaderReceived(const QHttpResponseHeader &resp);
|
||||
QString hostPrefix() const;
|
||||
public slots:
|
||||
void serverChanged(const QString &host);
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
int m_status;
|
||||
bool m_hadError;
|
||||
QSettings *m_settings;
|
||||
QString m_hostPrefix;
|
||||
};
|
||||
|
||||
#endif // POSTER_H
|
||||
#endif
|
66
src/plugins/cpaster/pastebindotcomsettings.ui
Normal file
66
src/plugins/cpaster/pastebindotcomsettings.ui
Normal file
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PasteBinComSettingsWidget</class>
|
||||
<widget class="QWidget" name="PasteBinComSettingsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Server Prefix:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string><!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></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>135</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>451</width>
|
||||
<height>215</height>
|
||||
<height>308</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -18,14 +18,18 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Protocol:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="protocolBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
@@ -38,7 +42,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="pasteEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
|
@@ -27,7 +27,7 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "view.h"
|
||||
#include "pasteview.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
#include <QPainter>
|
||||
@@ -77,12 +77,12 @@ void ColumnIndicatorTextEdit::paintEvent(QPaintEvent *event)
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
View::View(QWidget *parent)
|
||||
PasteView::PasteView(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
// Swap out the Patch View widget with a ColumnIndicatorTextEdit, which will indicate column 100
|
||||
// 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);
|
||||
@@ -90,11 +90,11 @@ View::View(QWidget *parent)
|
||||
connect(m_ui.uiPatchList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(contentChanged()));
|
||||
}
|
||||
|
||||
View::~View()
|
||||
PasteView::~PasteView()
|
||||
{
|
||||
}
|
||||
|
||||
QString View::getUser()
|
||||
QString PasteView::getUser()
|
||||
{
|
||||
const QString username = m_ui.uiUsername->text();
|
||||
if (username.isEmpty() || username == tr("<Username>"))
|
||||
@@ -102,7 +102,7 @@ QString View::getUser()
|
||||
return username;
|
||||
}
|
||||
|
||||
QString View::getDescription()
|
||||
QString PasteView::getDescription()
|
||||
{
|
||||
const QString description = m_ui.uiDescription->text();
|
||||
if (description == tr("<Description>"))
|
||||
@@ -110,7 +110,7 @@ QString View::getDescription()
|
||||
return description;
|
||||
}
|
||||
|
||||
QString View::getComment()
|
||||
QString PasteView::getComment()
|
||||
{
|
||||
const QString comment = m_ui.uiComment->toPlainText();
|
||||
if (comment == tr("<Comment>"))
|
||||
@@ -118,7 +118,7 @@ QString View::getComment()
|
||||
return comment;
|
||||
}
|
||||
|
||||
QByteArray View::getContent()
|
||||
QByteArray PasteView::getContent()
|
||||
{
|
||||
QByteArray newContent;
|
||||
for (int i = 0; i < m_ui.uiPatchList->count(); ++i) {
|
||||
@@ -129,12 +129,17 @@ QByteArray View::getContent()
|
||||
return newContent;
|
||||
}
|
||||
|
||||
void View::contentChanged()
|
||||
QString PasteView::getProtocol()
|
||||
{
|
||||
return m_ui.protocolBox->currentText();
|
||||
}
|
||||
|
||||
void PasteView::contentChanged()
|
||||
{
|
||||
m_ui.uiPatchView->setPlainText(getContent());
|
||||
}
|
||||
|
||||
int View::show(const QString &user, const QString &description, const QString &comment,
|
||||
int PasteView::show(const QString &user, const QString &description, const QString &comment,
|
||||
const FileDataList &parts)
|
||||
{
|
||||
if (user.isEmpty())
|
||||
@@ -179,3 +184,10 @@ int View::show(const QString &user, const QString &description, const QString &c
|
||||
|
||||
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));
|
||||
}
|
@@ -27,29 +27,32 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef VIEW_H
|
||||
#define VIEW_H
|
||||
#ifndef PASTEVIEW_H
|
||||
#define PASTEVIEW_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QByteArray>
|
||||
|
||||
#include "splitter.h"
|
||||
#include "ui_view.h"
|
||||
#include "ui_pasteview.h"
|
||||
|
||||
class View : public QDialog
|
||||
class PasteView : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
View(QWidget *parent);
|
||||
~View();
|
||||
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();
|
211
src/plugins/cpaster/pasteview.ui
Normal file
211
src/plugins/cpaster/pasteview.ui
Normal file
@@ -0,0 +1,211 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ViewDialog</class>
|
||||
<widget class="QDialog" name="ViewDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Send to Codepaster</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vboxLayout1">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Protocol:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="protocolBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>&Username:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>uiUsername</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="uiUsername">
|
||||
<property name="text">
|
||||
<string><Username></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>&Description:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>uiDescription</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="uiDescription">
|
||||
<property name="text">
|
||||
<string><Description></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="uiComment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="tabChangesFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!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></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Parts to send to server</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="uiPatchList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Patch 1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Patch 2</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="uiPatchView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>3</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>uiUsername</tabstop>
|
||||
<tabstop>uiDescription</tabstop>
|
||||
<tabstop>uiComment</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
<tabstop>uiPatchList</tabstop>
|
||||
<tabstop>uiPatchView</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ViewDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ViewDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@@ -26,37 +26,40 @@
|
||||
** contact the sales department at http://www.qtsoftware.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
#include "protocol.h"
|
||||
|
||||
#ifndef FETCHER_H
|
||||
#define FETCHER_H
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include <QHttp>
|
||||
#include <QHttpResponseHeader>
|
||||
#include <QString>
|
||||
|
||||
class Fetcher : public QHttp
|
||||
Protocol::Protocol()
|
||||
: QObject()
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Fetcher(const QString &host);
|
||||
}
|
||||
|
||||
int fetch(const QString &url);
|
||||
int fetch(int pasteID);
|
||||
Protocol::~Protocol()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray &body() { return m_body; }
|
||||
bool Protocol::canFetch() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int status() { return m_status; }
|
||||
bool hadError() { return m_hadError; }
|
||||
bool Protocol::canPost() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void gotRequestFinished(int id, bool error);
|
||||
void gotReadyRead(const QHttpResponseHeader &resp);
|
||||
bool Protocol::hasSettings() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_host;
|
||||
int m_status;
|
||||
bool m_hadError;
|
||||
QByteArray m_body;
|
||||
};
|
||||
Core::IOptionsPage* Protocol::settingsPage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // FETCHER_H
|
||||
void Protocol::list(QListWidget*)
|
||||
{
|
||||
qFatal("Base Protocol list() called");
|
||||
}
|
66
src/plugins/cpaster/protocol.h
Normal file
66
src/plugins/cpaster/protocol.h
Normal file
@@ -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 <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
|
||||
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
|
@@ -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", "<no url>").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;
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
@@ -1,58 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0" >
|
||||
<ui version="4.0">
|
||||
<class>CodePaster::SettingsPage</class>
|
||||
<widget class="QWidget" name="CodePaster::SettingsPage" >
|
||||
<property name="geometry" >
|
||||
<widget class="QWidget" name="CodePaster::SettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>341</width>
|
||||
<height>258</height>
|
||||
<width>362</width>
|
||||
<height>320</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Maximum" hsizetype="Preferred" >
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title" >
|
||||
<property name="title">
|
||||
<string>General</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<string>CodePaster Server:</string>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Default Protocol:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QLineEdit" name="serverEdit" />
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="defaultProtocol">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>CodePaster</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Pastebin.ca</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Pastebin.com</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="text" >
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Username:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="QLineEdit" name="userEdit" />
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="userEdit"/>
|
||||
</item>
|
||||
<item row="2" column="1" >
|
||||
<widget class="QCheckBox" name="clipboardBox" >
|
||||
<property name="text" >
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="clipboardBox">
|
||||
<property name="text">
|
||||
<string>Copy Paste URL to clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" >
|
||||
<widget class="QCheckBox" name="displayBox" >
|
||||
<property name="text" >
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="displayBox">
|
||||
<property name="text">
|
||||
<string>Display Output Pane after sending a post</string>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -61,11 +77,11 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer" >
|
||||
<property name="orientation" >
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>223</width>
|
||||
<height>100</height>
|
||||
|
@@ -1,14 +1,5 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += $$PWD/cgi.h \
|
||||
$$PWD/fetcher.h \
|
||||
$$PWD/poster.h \
|
||||
$$PWD/splitter.h \
|
||||
$$PWD/view.h
|
||||
SOURCES += $$PWD/cgi.cpp \
|
||||
$$PWD/fetcher.cpp \
|
||||
$$PWD/poster.cpp \
|
||||
$$PWD/splitter.cpp \
|
||||
$$PWD/view.cpp
|
||||
|
||||
FORMS += $$PWD/view.ui
|
||||
HEADERS += $$PWD/cgi.h \
|
||||
$$PWD/splitter.h
|
||||
SOURCES += $$PWD/cgi.cpp \
|
||||
$$PWD/splitter.cpp
|
||||
|
@@ -1,72 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** 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 "poster.h"
|
||||
#include "cgi.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
|
||||
Poster::Poster(const QString &host)
|
||||
: QHttp(host)
|
||||
{
|
||||
m_status = 0;
|
||||
m_hadError = false;
|
||||
connect(this, SIGNAL(requestFinished(int,bool)), SLOT(gotRequestFinished(int,bool)));
|
||||
connect(this, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), SLOT(gotResponseHeaderReceived(QHttpResponseHeader)));
|
||||
}
|
||||
|
||||
void Poster::post(const QString &description, const QString &comment,
|
||||
const QString &text, const QString &user)
|
||||
{
|
||||
|
||||
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(user).toLatin1();
|
||||
// qDebug("POST [%s]", data.constData());
|
||||
|
||||
QHttp::post("/", data);
|
||||
}
|
||||
|
||||
void Poster::gotRequestFinished(int, bool error)
|
||||
{
|
||||
m_hadError = error;
|
||||
QCoreApplication::exit(error ? -1 : 0); // ends event-loop
|
||||
}
|
||||
|
||||
void Poster::gotResponseHeaderReceived(const QHttpResponseHeader &resp)
|
||||
{
|
||||
m_url = resp.value("location");
|
||||
}
|
@@ -1,208 +0,0 @@
|
||||
<ui version="4.0" >
|
||||
<class>ViewDialog</class>
|
||||
<widget class="QDialog" name="ViewDialog" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Send to Codepaster</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<string>&Username:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>uiUsername</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QLineEdit" name="uiUsername" >
|
||||
<property name="text" >
|
||||
<string><Username></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="text" >
|
||||
<string>&Description:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>uiDescription</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="QLineEdit" name="uiDescription" >
|
||||
<property name="text" >
|
||||
<string><Description></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="uiComment" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="MinimumExpanding" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="tabChangesFocus" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="html" >
|
||||
<string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; 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;">&lt;Comment&gt;</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title" >
|
||||
<string>Parts to send to codepaster</string>
|
||||
</property>
|
||||
<property name="flat" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="uiPatchList" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="uniformItemSizes" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text" >
|
||||
<string>Patch 1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text" >
|
||||
<string>Patch 2</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="uiPatchView" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>3</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font" >
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons" >
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>uiUsername</tabstop>
|
||||
<tabstop>uiDescription</tabstop>
|
||||
<tabstop>uiComment</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
<tabstop>uiPatchList</tabstop>
|
||||
<tabstop>uiPatchView</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ViewDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ViewDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Reference in New Issue
Block a user