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/shared/cpaster/cpaster.pri | 17 +--- src/shared/cpaster/fetcher.cpp | 75 --------------- src/shared/cpaster/fetcher.h | 62 ------------ src/shared/cpaster/poster.cpp | 72 -------------- src/shared/cpaster/poster.h | 60 ------------ src/shared/cpaster/view.cpp | 181 ----------------------------------- src/shared/cpaster/view.h | 62 ------------ src/shared/cpaster/view.ui | 208 ----------------------------------------- 8 files changed, 4 insertions(+), 733 deletions(-) delete mode 100644 src/shared/cpaster/fetcher.cpp delete mode 100644 src/shared/cpaster/fetcher.h delete mode 100644 src/shared/cpaster/poster.cpp delete mode 100644 src/shared/cpaster/poster.h delete mode 100644 src/shared/cpaster/view.cpp delete mode 100644 src/shared/cpaster/view.h delete mode 100644 src/shared/cpaster/view.ui (limited to 'src/shared/cpaster') diff --git a/src/shared/cpaster/cpaster.pri b/src/shared/cpaster/cpaster.pri index 146b9d393b4..519016dd807 100644 --- a/src/shared/cpaster/cpaster.pri +++ b/src/shared/cpaster/cpaster.pri @@ -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 diff --git a/src/shared/cpaster/fetcher.cpp b/src/shared/cpaster/fetcher.cpp deleted file mode 100644 index 9cf2a2c65e7..00000000000 --- a/src/shared/cpaster/fetcher.cpp +++ /dev/null @@ -1,75 +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 "fetcher.h" -#include "cgi.h" - -#include -#include -#include - -Fetcher::Fetcher(const QString &host) - : QHttp(host) -{ - 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))); -} - -int Fetcher::fetch(const QString &url) -{ -// qDebug("Fetcher::fetch(%s)", qPrintable(url)); - return QHttp::get(url); -} - -int Fetcher::fetch(int pasteID) -{ - return fetch("http://" + m_host + "/?format=raw&id=" + QString::number(pasteID)); -} - -void Fetcher::gotRequestFinished(int, bool error) -{ - m_hadError = error; - QCoreApplication::exit(error ? -1 : 0); // ends event-loop -} - -void Fetcher::gotReadyRead(const QHttpResponseHeader & /* resp */) -{ - m_body += QHttp::readAll(); - - // 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("No such paste!")) { - m_body.clear(); - m_status = -1; - m_hadError = true; - } -} diff --git a/src/shared/cpaster/fetcher.h b/src/shared/cpaster/fetcher.h deleted file mode 100644 index 46cdfc22e1b..00000000000 --- a/src/shared/cpaster/fetcher.h +++ /dev/null @@ -1,62 +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. -** -**************************************************************************/ - -#ifndef FETCHER_H -#define FETCHER_H - -#include -#include -#include - -class Fetcher : public QHttp -{ - Q_OBJECT -public: - Fetcher(const QString &host); - - int fetch(const QString &url); - int fetch(int pasteID); - - QByteArray &body() { return m_body; } - - int status() { return m_status; } - bool hadError() { return m_hadError; } - -private slots: - void gotRequestFinished(int id, bool error); - void gotReadyRead(const QHttpResponseHeader &resp); - -private: - QString m_host; - int m_status; - bool m_hadError; - QByteArray m_body; -}; - -#endif // FETCHER_H diff --git a/src/shared/cpaster/poster.cpp b/src/shared/cpaster/poster.cpp deleted file mode 100644 index b07f769a741..00000000000 --- a/src/shared/cpaster/poster.cpp +++ /dev/null @@ -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 -#include -#include - -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"); -} diff --git a/src/shared/cpaster/poster.h b/src/shared/cpaster/poster.h deleted file mode 100644 index 96d138d49e7..00000000000 --- a/src/shared/cpaster/poster.h +++ /dev/null @@ -1,60 +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. -** -**************************************************************************/ - -#ifndef POSTER_H -#define POSTER_H - -#include -#include -#include - -class Poster : public QHttp -{ - Q_OBJECT -public: - Poster(const QString &host); - - void post(const QString &description, const QString &comment, - const QString &text, const QString &user); - - QString pastedUrl() { return m_url; } - int status() { return m_status; } - bool hadError() { return m_hadError; } - -private slots: - void gotRequestFinished(int id, bool error); - void gotResponseHeaderReceived(const QHttpResponseHeader &resp); - -private: - QString m_url; - int m_status; - bool m_hadError; -}; - -#endif // POSTER_H diff --git a/src/shared/cpaster/view.cpp b/src/shared/cpaster/view.cpp deleted file mode 100644 index b053ce9bad8..00000000000 --- a/src/shared/cpaster/view.cpp +++ /dev/null @@ -1,181 +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 "view.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"); -} - -// ------------------------------------------------------------------------------------------------- - - -View::View(QWidget *parent) - : QDialog(parent) -{ - m_ui.setupUi(this); - - // Swap out the Patch View 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())); -} - -View::~View() -{ -} - -QString View::getUser() -{ - const QString username = m_ui.uiUsername->text(); - if (username.isEmpty() || username == tr("")) - return "Anonymous"; - return username; -} - -QString View::getDescription() -{ - const QString description = m_ui.uiDescription->text(); - if (description == tr("")) - return QString(); - return description; -} - -QString View::getComment() -{ - const QString comment = m_ui.uiComment->toPlainText(); - if (comment == tr("")) - return QString(); - return comment; -} - -QByteArray View::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; -} - -void View::contentChanged() -{ - m_ui.uiPatchView->setPlainText(getContent()); -} - -int View::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; -} diff --git a/src/shared/cpaster/view.h b/src/shared/cpaster/view.h deleted file mode 100644 index b61ad7dd7e3..00000000000 --- a/src/shared/cpaster/view.h +++ /dev/null @@ -1,62 +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. -** -**************************************************************************/ - -#ifndef VIEW_H -#define VIEW_H - -#include -#include - -#include "splitter.h" -#include "ui_view.h" - -class View : public QDialog -{ - Q_OBJECT -public: - View(QWidget *parent); - ~View(); - - int show(const QString &user, const QString &description, const QString &comment, - const FileDataList &parts); - - QString getUser(); - QString getDescription(); - QString getComment(); - QByteArray getContent(); - -private slots: - void contentChanged(); - -private: - Ui::ViewDialog m_ui; - FileDataList m_parts; -}; - -#endif // VIEW_H diff --git a/src/shared/cpaster/view.ui b/src/shared/cpaster/view.ui deleted file mode 100644 index b8ede8d1d4a..00000000000 --- a/src/shared/cpaster/view.ui +++ /dev/null @@ -1,208 +0,0 @@ - - ViewDialog - - - - 0 - 0 - 600 - 500 - - - - Send to Codepaster - - - - - - - - &Username: - - - uiUsername - - - - - - - <Username> - - - - - - - &Description: - - - uiDescription - - - - - - - <Description> - - - - - - - - - - 0 - 0 - - - - - 16777215 - 100 - - - - true - - - <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> - - - - - - - - 0 - 0 - - - - Parts to send to codepaster - - - true - - - - 2 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 1 - - - - true - - - - Patch 1 - - - - - Patch 2 - - - - - - - - - 0 - 3 - - - - - Courier New - - - - true - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok - - - - - - - uiUsername - uiDescription - uiComment - buttonBox - uiPatchList - uiPatchView - - - - - buttonBox - accepted() - ViewDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - ViewDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - -- cgit v1.2.3