diff --git a/src/plugins/cpaster/codepasterprotocol.cpp b/src/plugins/cpaster/codepasterprotocol.cpp
index 9c82a2adf06a4546df552f6fd6b8b3482c8ea4e3..2e444dcf5295ef5fae6a8c7febb3825216f16297 100644
--- a/src/plugins/cpaster/codepasterprotocol.cpp
+++ b/src/plugins/cpaster/codepasterprotocol.cpp
@@ -38,17 +38,23 @@
 #include <coreplugin/messagemanager.h>
 #include <coreplugin/messageoutputwindow.h>
 
+#include <utils/qtcassert.h>
+
 #include <QtGui/QListWidget>
 #include <QtNetwork/QNetworkReply>
+#include <QtCore/QDebug>
+
+enum { debug = 0 };
 
-using namespace CodePaster;
-using namespace Core;
+namespace CodePaster {
 
-CodePasterProtocol::CodePasterProtocol()
+CodePasterProtocol::CodePasterProtocol() :
+    m_page(new CodePaster::CodePasterSettingsPage),
+    m_pasteReply(0),
+    m_fetchReply(0),
+    m_listReply(0),
+    m_fetchId(-1)
 {
-    m_page = new CodePaster::CodePasterSettingsPage();
-    connect(&http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
-            this, SLOT(readPostResponseHeader(const QHttpResponseHeader&)));
 }
 
 CodePasterProtocol::~CodePasterProtocol()
@@ -68,14 +74,14 @@ unsigned CodePasterProtocol::capabilities() const
 bool CodePasterProtocol::isValidHostName(const QString& hostName)
 {
     if (hostName.isEmpty()) {
-        ICore::instance()->messageManager()->printToOutputPane(
+        Core::ICore::instance()->messageManager()->printToOutputPane(
 #ifdef Q_OS_MAC
                        tr("No Server defined in the CodePaster preferences."),
 #else
                        tr("No Server defined in the CodePaster options."),
 #endif
                        true /*error*/);
-        ICore::instance()->messageManager()->showOutputPane();
+        Core::ICore::instance()->messageManager()->showOutputPane();
         return false;
     }
     return true;
@@ -83,6 +89,8 @@ bool CodePasterProtocol::isValidHostName(const QString& hostName)
 
 void CodePasterProtocol::fetch(const QString &id)
 {
+    QTC_ASSERT(!m_fetchReply, return; )
+
     QString hostName = m_page->hostName();
     if (!isValidHostName(hostName))
         return;
@@ -93,13 +101,15 @@ void CodePasterProtocol::fetch(const QString &id)
     QUrl url(link);
     QNetworkRequest r(url);
 
-    reply = manager.get(r);
-    connect(reply, SIGNAL(finished()), this, SLOT(fetchFinished()));
-    fetchId = id;
+    m_fetchReply = m_manager.get(r);
+    connect(m_fetchReply, SIGNAL(finished()), this, SLOT(fetchFinished()));
+    m_fetchId = id;
 }
 
 void CodePasterProtocol::list()
 {
+    QTC_ASSERT(!m_listReply, return; )
+
     QString hostName = m_page->hostName();
     if (!isValidHostName(hostName))
         return;
@@ -108,16 +118,18 @@ void CodePasterProtocol::list()
     link += QLatin1String("/?command=browse&format=raw");
     QUrl url(link);
     QNetworkRequest r(url);
-    listReply = manager.get(r);
-    connect(listReply, SIGNAL(finished()), this, SLOT(listFinished()));
+    m_listReply = m_manager.get(r);
+    connect(m_listReply, SIGNAL(finished()), this, SLOT(listFinished()));
 }
 
 void CodePasterProtocol::paste(const QString &text,
+                               ContentType /* ct */,
                                const QString &username,
                                const QString &comment,
                                const QString &description)
 {
-    QString hostName = m_page->hostName();
+    QTC_ASSERT(!m_pasteReply, return; )
+    const QString hostName = m_page->hostName();
     if (!isValidHostName(hostName))
         return;
 
@@ -126,12 +138,33 @@ void CodePasterProtocol::paste(const QString &text,
     data += "&comment=";
     data += CGI::encodeURL(comment).toLatin1();
     data += "&code=";
-    data += CGI::encodeURL(text).toLatin1();
+    data += CGI::encodeURL(fixNewLines(text)).toLatin1();
     data += "&poster=";
     data += CGI::encodeURL(username).toLatin1();
 
-    http.setHost(hostName);
-    http.post(QString(QLatin1Char('/')), data);
+    QUrl url(QLatin1String("http://") + hostName);
+    QNetworkRequest r(url);
+    m_pasteReply = m_manager.post(r, data);
+    connect(m_pasteReply, SIGNAL(finished()), this, SLOT(pasteFinished()));
+}
+
+void CodePasterProtocol::pasteFinished()
+{
+    if (m_pasteReply->error()) {
+        qWarning("Error pasting: %s", qPrintable(m_pasteReply->errorString()));
+    } else {
+        // Cut out the href-attribute
+        QString contents = QString::fromAscii(m_pasteReply->readAll());
+        int hrefPos = contents.indexOf(QLatin1String("href=\""));
+        if (hrefPos != -1) {
+            hrefPos += 6;
+            const int endPos = contents.indexOf(QLatin1Char('"'), hrefPos);
+            if (endPos != -1)
+                emit pasteDone(contents.mid(hrefPos, endPos - hrefPos));
+        }
+    }
+    m_pasteReply->deleteLater();
+    m_pasteReply = 0;
 }
 
 bool CodePasterProtocol::hasSettings() const
@@ -148,38 +181,35 @@ void CodePasterProtocol::fetchFinished()
 {
     QString title;
     QString content;
-    bool error = reply->error();
+    bool error = m_fetchReply->error();
     if (error) {
-        content = reply->errorString();
+        content = m_fetchReply->errorString();
     } else {
-        content = reply->readAll();
+        content = m_fetchReply->readAll();
+        if (debug)
+            qDebug() << content;
         if (content.contains("<B>No such paste!</B>")) {
             content = tr("No such paste");
             error = true;
         }
-        title = QString::fromLatin1("Codepaster: %1").arg(fetchId);
+        title = QString::fromLatin1("Codepaster: %1").arg(m_fetchId);
     }
-    reply->deleteLater();
-    reply = 0;
+    m_fetchReply->deleteLater();
+    m_fetchReply = 0;
     emit fetchDone(title, content, error);
 }
 
 void CodePasterProtocol::listFinished()
 {
-    if (listReply->error()) {
-        ICore::instance()->messageManager()->printToOutputPane(listReply->errorString(), true);
+    if (m_listReply->error()) {
+        Core::ICore::instance()->messageManager()->printToOutputPane(m_listReply->errorString(), true);
     } else {
-        const QByteArray data = listReply->readAll();
+        const QByteArray data = m_listReply->readAll();
         const QStringList lines = QString::fromAscii(data).split(QLatin1Char('\n'));
         emit listDone(name(), lines);
     }
-    listReply->deleteLater();
-    listReply = 0;
+    m_listReply->deleteLater();
+    m_listReply = 0;
 }
 
-void CodePasterProtocol::readPostResponseHeader(const QHttpResponseHeader &header)
-{
-    QString link = header.value("location");
-    if (!link.isEmpty())
-        emit pasteDone(link);
-}
+} // namespace CodePaster
diff --git a/src/plugins/cpaster/codepasterprotocol.h b/src/plugins/cpaster/codepasterprotocol.h
index 977c028782592950419c309cff05fa5850661b28..f6e6df058a8b61aa42dc4a7697279de7afa7d035 100644
--- a/src/plugins/cpaster/codepasterprotocol.h
+++ b/src/plugins/cpaster/codepasterprotocol.h
@@ -32,7 +32,6 @@
 
 #include "protocol.h"
 
-#include <QtNetwork/QHttp>
 #include <QtNetwork/QNetworkAccessManager>
 
 QT_BEGIN_NAMESPACE
@@ -59,22 +58,23 @@ public:
     void fetch(const QString &id);
     void list();
     void paste(const QString &text,
+               ContentType ct = Text,
                const QString &username = QString(),
                const QString &comment = QString(),
                const QString &description = QString());
 public slots:
     void fetchFinished();
     void listFinished();
-    void readPostResponseHeader(const QHttpResponseHeader &);
+    void pasteFinished();
 
 private:
     bool isValidHostName(const QString& hostName);
     CodePasterSettingsPage *m_page;
-    QHttp http;
-    QNetworkAccessManager manager;
-    QNetworkReply *reply;
-    QNetworkReply *listReply;
-    QString fetchId;
+    QNetworkAccessManager m_manager;
+    QNetworkReply *m_pasteReply;
+    QNetworkReply *m_fetchReply;
+    QNetworkReply *m_listReply;
+    QString m_fetchId;
 };
 
 } // namespace CodePaster
diff --git a/src/plugins/cpaster/columnindicatortextedit.cpp b/src/plugins/cpaster/columnindicatortextedit.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9b7ce3fc741a70184699d46862abbe5a8e309092
--- /dev/null
+++ b/src/plugins/cpaster/columnindicatortextedit.cpp
@@ -0,0 +1,66 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 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://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "columnindicatortextedit.h"
+
+#include <QtGui/QPainter>
+#include <QtGui/QScrollBar>
+
+namespace CodePaster {
+
+ColumnIndicatorTextEdit::ColumnIndicatorTextEdit(QWidget *parent) :
+        QTextEdit(parent), m_columnIndicator(0)
+{
+    QFont font;
+    font.setFamily(QString::fromUtf8("Courier New"));
+    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);
+}
+
+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");
+}
+
+} // namespace CodePaster
diff --git a/src/plugins/cpaster/columnindicatortextedit.h b/src/plugins/cpaster/columnindicatortextedit.h
new file mode 100644
index 0000000000000000000000000000000000000000..20bb25ebddf057cc3d4498d70458693da4677b5a
--- /dev/null
+++ b/src/plugins/cpaster/columnindicatortextedit.h
@@ -0,0 +1,54 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 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://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef COLUMNINDICATORTEXTEDIT_H
+#define COLUMNINDICATORTEXTEDIT_H
+
+#include <QtGui/QTextEdit>
+
+namespace CodePaster {
+
+// Indicate text column 100 by a vertical line.
+class ColumnIndicatorTextEdit : public QTextEdit
+{
+public:
+    explicit ColumnIndicatorTextEdit(QWidget *parent);
+
+    int columnIndicator() const { return m_columnIndicator; }
+
+protected:
+    virtual void paintEvent(QPaintEvent *event);
+
+private:
+    int m_columnIndicator;
+    QFont m_columnIndicatorFont;
+};
+} // namespace CodePaster
+
+#endif // COLUMNINDICATORTEXTEDIT_H
diff --git a/src/plugins/cpaster/cpaster.pro b/src/plugins/cpaster/cpaster.pro
index a705b1463b33d6307fc5f1447e39bc1210f9aba1..6abf90914cf2f2c24bd7d7da040c8d51748724bf 100644
--- a/src/plugins/cpaster/cpaster.pro
+++ b/src/plugins/cpaster/cpaster.pro
@@ -14,7 +14,8 @@ HEADERS += cpasterplugin.h \
     pastebindotcomsettings.h \
     pastebindotcaprotocol.h \
     settings.h \
-    pasteselectdialog.h
+    pasteselectdialog.h \
+    columnindicatortextedit.h
 SOURCES += cpasterplugin.cpp \
     settingspage.cpp \
     protocol.cpp \
@@ -25,7 +26,8 @@ SOURCES += cpasterplugin.cpp \
     pastebindotcomsettings.cpp \
     pastebindotcaprotocol.cpp \
     settings.cpp \
-    pasteselectdialog.cpp
+    pasteselectdialog.cpp \
+    columnindicatortextedit.cpp
 FORMS += settingspage.ui \
     pasteselect.ui \
     pasteview.ui \
diff --git a/src/plugins/cpaster/cpasterplugin.cpp b/src/plugins/cpaster/cpasterplugin.cpp
index 7ce13005308eb9e8478dc1ed32599c3c9ef38dbf..ea2dccc5173aa02314b556d98c5d960353a52458 100644
--- a/src/plugins/cpaster/cpasterplugin.cpp
+++ b/src/plugins/cpaster/cpasterplugin.cpp
@@ -48,7 +48,7 @@
 #include <coreplugin/messagemanager.h>
 #include <coreplugin/uniqueidmanager.h>
 #include <utils/qtcassert.h>
-#include <texteditor/itexteditor.h>
+#include <texteditor/basetexteditor.h>
 
 #include <QtCore/QtPlugin>
 #include <QtCore/QDebug>
@@ -145,36 +145,41 @@ void CodepasterPlugin::shutdown()
     }
 }
 
+static inline void fixSpecialCharacters(QString &data)
+{
+    QChar *uc = data.data();
+    QChar *e = uc + data.size();
+
+    for (; uc != e; ++uc) {
+        switch (uc->unicode()) {
+        case 0xfdd0: // QTextBeginningOfFrame
+        case 0xfdd1: // QTextEndOfFrame
+        case QChar::ParagraphSeparator:
+        case QChar::LineSeparator:
+            *uc = QLatin1Char('\n');
+            break;
+        case QChar::Nbsp:
+            *uc = QLatin1Char(' ');
+            break;
+        default:
+            break;
+        }
+    }
+}
+
 void CodepasterPlugin::post()
 {
-    IEditor* editor = EditorManager::instance()->currentEditor();
-    ITextEditor* textEditor = qobject_cast<ITextEditor*>(editor);
+    const IEditor* editor = EditorManager::instance()->currentEditor();
+    const BaseTextEditorEditable *textEditor = qobject_cast<const BaseTextEditorEditable *>(editor);
     if (!textEditor)
         return;
 
     QString data = textEditor->selectedText();
-    if (!data.isEmpty()) {
-        QChar *uc = data.data();
-        QChar *e = uc + data.size();
-
-        for (; uc != e; ++uc) {
-            switch (uc->unicode()) {
-            case 0xfdd0: // QTextBeginningOfFrame
-            case 0xfdd1: // QTextEndOfFrame
-            case QChar::ParagraphSeparator:
-            case QChar::LineSeparator:
-                *uc = QLatin1Char('\n');
-                break;
-            case QChar::Nbsp:
-                *uc = QLatin1Char(' ');
-                break;
-            default:
-                ;
-            }
-        }
-    } else
+    if (data.isEmpty())
         data = textEditor->contents();
-
+    if (data.isEmpty())
+        return;
+    fixSpecialCharacters(data);
     FileDataList lst = splitDiffToFiles(data.toLatin1());
     QString username = m_settings->username;
     QString description;
@@ -192,22 +197,13 @@ void CodepasterPlugin::post()
     comment = view.comment();
     data = view.content();
     protocolName = view.protocol();
-
-    // Copied from cpaster. Otherwise lineendings will screw up
-    if (!data.contains("\r\n")) {
-        if (data.contains('\n'))
-            data.replace('\n', "\r\n");
-        else if (data.contains('\r'))
-            data.replace('\r', "\r\n");
-    }
-
     foreach(Protocol *protocol, m_protocols) {
         if (protocol->name() == protocolName) {
-            protocol->paste(data, username, comment, description);
+            const Protocol::ContentType ct = Protocol::contentType(textEditor->editor()->mimeType());
+            protocol->paste(data, ct, username, comment, description);
             break;
         }
     }
-
 }
 
 void CodepasterPlugin::fetch()
diff --git a/src/plugins/cpaster/pastebindotcaprotocol.cpp b/src/plugins/cpaster/pastebindotcaprotocol.cpp
index 83b7e8e867fb633036c249884f7d05bf55ae4d1f..c40276cd169c906475936927ba1134712746acb7 100644
--- a/src/plugins/cpaster/pastebindotcaprotocol.cpp
+++ b/src/plugins/cpaster/pastebindotcaprotocol.cpp
@@ -53,14 +53,15 @@ void PasteBinDotCaProtocol::fetch(const QString &id)
 }
 
 void PasteBinDotCaProtocol::paste(const QString &text,
-                                   const QString &username,
-                                   const QString &comment,
-                                   const QString &description)
+                                  ContentType /* ct */,
+                                  const QString &username,
+                                  const QString &comment,
+                                  const QString &description)
 {
     Q_UNUSED(comment);
     Q_UNUSED(description);
     QString data = "content=";
-    data += CGI::encodeURL(text);
+    data += CGI::encodeURL(fixNewLines(text));
     data += "&description=";
     data += CGI::encodeURL(description);
     data += "&type=1&expiry=1%20day&name=";
diff --git a/src/plugins/cpaster/pastebindotcaprotocol.h b/src/plugins/cpaster/pastebindotcaprotocol.h
index 3356e8e8c6d7b2c92e109afb6166febf289fa7ac..b1d0c07bd0cf542d803b4845d2462b93c4d765cc 100644
--- a/src/plugins/cpaster/pastebindotcaprotocol.h
+++ b/src/plugins/cpaster/pastebindotcaprotocol.h
@@ -48,6 +48,7 @@ public:
 
     void fetch(const QString &id);
     void paste(const QString &text,
+               ContentType ct = Text,
                const QString &username = QString(),
                const QString &comment = QString(),
                const QString &description = QString());
diff --git a/src/plugins/cpaster/pastebindotcomprotocol.cpp b/src/plugins/cpaster/pastebindotcomprotocol.cpp
index bead94988cd5471e2ddbcd5e500e5f02157048fd..5e6f8498cb8be1d7eed43b451f14c95cbb9528c9 100644
--- a/src/plugins/cpaster/pastebindotcomprotocol.cpp
+++ b/src/plugins/cpaster/pastebindotcomprotocol.cpp
@@ -29,128 +29,298 @@
 
 #include "pastebindotcomprotocol.h"
 #include "pastebindotcomsettings.h"
-#include "cgi.h"
 
 #include <coreplugin/icore.h>
 
+#include <utils/qtcassert.h>
+
 #include <QtCore/QDebug>
 #include <QtCore/QTextStream>
-#include <QtNetwork/QNetworkReply>
+#include <QtCore/QXmlStreamReader>
+#include <QtCore/QXmlStreamAttributes>
 
-using namespace Core;
+#include <QtNetwork/QNetworkReply>
 
 enum { debug = 0 };
 
-static const char phpScriptpC[] = "api_public.php";
+static const char pastePhpScriptpC[] = "api_public.php";
+static const char fetchPhpScriptpC[] = "raw.php";
 
 namespace CodePaster {
-PasteBinDotComProtocol::PasteBinDotComProtocol()
+PasteBinDotComProtocol::PasteBinDotComProtocol() :
+    m_settings(new PasteBinDotComSettings),
+    m_fetchReply(0),
+    m_pasteReply(0),
+    m_listReply(0),
+    m_fetchId(-1),
+    m_postId(-1)
 {
-    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&)));
 }
 
-QString PasteBinDotComProtocol::hostName() const
+unsigned PasteBinDotComProtocol::capabilities() const
 {
+    return ListCapability;
+}
 
-    QString rc = settings->hostPrefix();
-    if (!rc.isEmpty())
-        rc.append(QLatin1Char('.'));
+QString PasteBinDotComProtocol::hostName(bool withSubDomain) const
+{
+
+    QString rc;
+    if (withSubDomain) {
+        rc = m_settings->hostPrefix();
+        if (!rc.isEmpty())
+            rc.append(QLatin1Char('.'));
+    }
     rc.append(QLatin1String("pastebin.com"));
     return rc;
 }
 
-void PasteBinDotComProtocol::fetch(const QString &id)
+static inline QByteArray format(Protocol::ContentType ct)
 {
-    QString link;
-    QTextStream(&link) << "http://" << hostName() << '/' << phpScriptpC << "?dl=" << id;
-    if (debug)
-        qDebug() << "fetch: sending " << link;
-    QUrl url(link);
-    QNetworkRequest r(url);
-
-    reply = manager.get(r);
-    connect(reply, SIGNAL(finished()), this, SLOT(fetchFinished()));
-    fetchId = id;
+    switch (ct) {
+    case Protocol::Text:
+        break;
+    case Protocol::C:
+        return "paste_format=cpp";
+        break;
+    case Protocol::JavaScript:
+        return "paste_format=javascript";
+        break;
+    case Protocol::Diff:
+        return "paste_format=dff";
+        break;
+    case Protocol::Xml:
+        return "paste_format=xml";
+        break;
+    }
+    return QByteArray();
 }
 
 void PasteBinDotComProtocol::paste(const QString &text,
+                                   ContentType ct,
                                    const QString &username,
                                    const QString & /* comment */,
                                    const QString & /* description */)
 {
-    QString data;
-    QTextStream str(&data);
-    str << "paste_code=" << CGI::encodeURL(text) << "&paste_name="
-            << CGI::encodeURL(username);
-    QHttpRequestHeader header(QLatin1String("POST"), QLatin1String(phpScriptpC));
-
-    const QString host = hostName();
-    header.setValue(QLatin1String("host"), host);
-    header.setContentType(QLatin1String("application/x-www-form-urlencoded"));
-    http.setHost(host, QHttp::ConnectionModeHttp);
-    header.setValue(QLatin1String("User-Agent"), QLatin1String("CreatorPastebin"));
-    postId = http.request(header, data.toAscii());
+    QTC_ASSERT(!m_pasteReply, return;)
+
+    // Format body
+    m_pasteData = format(ct);
+    if (!m_pasteData.isEmpty())
+        m_pasteData.append('&');
+    m_pasteData += "paste_name=";
+    m_pasteData += QUrl::toPercentEncoding(username);
+
+    const QString subDomain = m_settings->hostPrefix();
+    if (!subDomain.isEmpty()) {
+        m_pasteData += "&paste_subdomain=";
+        m_pasteData += QUrl::toPercentEncoding(subDomain);
+    }
+
+    m_pasteData += "&paste_code=";
+    m_pasteData += QUrl::toPercentEncoding(fixNewLines(text));
+
+    // fire request
+    QString link;
+    QTextStream(&link) << "http://" << hostName(false) << '/' << pastePhpScriptpC;
+
+    QUrl url(link);
+    QNetworkRequest r(url);
+    m_pasteReply = m_manager.post(r, m_pasteData);
+    connect(m_pasteReply, SIGNAL(finished()), this, SLOT(pasteFinished()));
     if (debug)
-        qDebug() << "paste" << data << postId << host;
+        qDebug() << "paste: sending " << m_pasteReply << link << m_pasteData;
 }
 
-void PasteBinDotComProtocol::readPostResponseHeader(const QHttpResponseHeader &header)
+void PasteBinDotComProtocol::pasteFinished()
 {
-    const int code = header.statusCode();
-    if (debug)
-        qDebug() << "readPostResponseHeader" << code << header.toString() << header.values();
-    switch (code) {
-        // If we receive any of those, everything is bon.
-    case 301:
-    case 303:
-    case 307:
-    case 200:
-    case 302: {
-        QString link = header.value("Location");
-        emit pasteDone(link);
-        break;
-    }
-    default:
-        emit pasteDone(tr("Error during paste"));
+    if (m_pasteReply->error()) {
+        qWarning("Pastebin.com protocol error: %s", qPrintable(m_pasteReply->errorString()));
+    } else {
+        emit pasteDone(QString::fromAscii(m_pasteReply->readAll()));
     }
+
+    m_pasteReply->deleteLater();
+    m_pasteReply = 0;
 }
 
-void PasteBinDotComProtocol::postRequestFinished(int id, bool error)
+void PasteBinDotComProtocol::fetch(const QString &id)
 {
-    if (id == postId && error) {
-        const QString errorMessage = http.errorString();
-        if (debug)
-            qDebug() << "postRequestFinished" << id << errorMessage;
-        emit pasteDone(errorMessage);
+    const QString httpProtocolPrefix = QLatin1String("http://");
+
+    QTC_ASSERT(!m_fetchReply, return;)
+
+    // Did we get a complete URL or just an id. Insert a call to the php-script
+    QString link;
+    if (id.startsWith(httpProtocolPrefix)) {
+        // Change "http://host/id" -> "http://host/script?i=id".
+        const int lastSlashPos = id.lastIndexOf(QLatin1Char('/'));
+        link = id.mid(0, lastSlashPos);
+        QTextStream(&link) << '/' << fetchPhpScriptpC<< "?i=" << id.mid(lastSlashPos + 1);
+    } else {
+        // format "http://host/script?i=id".
+        QTextStream(&link) << "http://" << hostName(true) << '/' << fetchPhpScriptpC<< "?i=" << id;
     }
+
+    if (debug)
+        qDebug() << "fetch: sending " << link;
+    QUrl url(link);
+    QNetworkRequest r(url);
+
+    m_fetchReply = m_manager.get(r);
+    connect(m_fetchReply, SIGNAL(finished()), this, SLOT(fetchFinished()));
+    m_fetchId = id;
 }
 
 void PasteBinDotComProtocol::fetchFinished()
 {
     QString title;
     QString content;
-    const bool error = reply->error();
+    const bool error = m_fetchReply->error();
     if (error) {
-        content = reply->errorString();
+        content = m_fetchReply->errorString();
         if (debug)
-            qDebug() << "fetchFinished: error" << fetchId << content;
+            qDebug() << "fetchFinished: error" << m_fetchId << content;
     } else {
-        title = QString::fromLatin1("Pastebin.com: %1").arg(fetchId);
-        content = QString::fromAscii(reply->readAll());
-        if (debug)
-            qDebug() << "fetchFinished: " << content.size();
+        title = QString::fromLatin1("Pastebin.com: %1").arg(m_fetchId);
+        content = QString::fromAscii(m_fetchReply->readAll());
+        // Cut out from '<pre>' formatting
+        const int preEnd = content.lastIndexOf(QLatin1String("</pre>"));
+        if (preEnd != -1)
+            content.truncate(preEnd);
+        const int preStart = content.indexOf(QLatin1String("<pre>"));
+        if (preStart != -1)
+            content.remove(0, preStart + 5);
+        // Make applicable as patch.
+        content = Protocol::textFromHtml(content);
+        content += QLatin1Char('\n');
+        // -------------
+        if (debug) {
+            QDebug nsp = qDebug().nospace();
+            nsp << "fetchFinished: " << content.size() << " Bytes";
+            if (debug > 1)
+                nsp << content;
+        }
     }
-    reply->deleteLater();
-    reply = 0;
+    m_fetchReply->deleteLater();
+    m_fetchReply = 0;
     emit fetchDone(title, content, error);
 }
 
+void PasteBinDotComProtocol::list()
+{
+    QTC_ASSERT(!m_listReply, return;)
+
+    // fire request
+    QUrl url(QLatin1String("http://") + hostName(true));
+    QNetworkRequest r(url);
+    m_listReply = m_manager.get(r);
+    connect(m_listReply, SIGNAL(finished()), this, SLOT(listFinished()));
+    if (debug)
+        qDebug() << "list: sending " << m_listReply;
+}
+
+static inline void padString(QString *s, int len)
+{
+    const int missing = len - s->length();
+    if (missing > 0)
+        s->append(QString(missing, QLatin1Char(' ')));
+}
+
+/* Quick & dirty: Parse the <div>-elements with the "Recent Posts" listing
+ * out of the page.
+\code
+<div class="content_left_title">Recent Posts</div>
+    <div class="content_left_box">
+        <div class="clb_top"><a href="http://pastebin.com/id">User</a></div>
+        <div class="clb_bottom"><span>Title</div>
+\endcode */
+
+static inline QStringList parseLists(QIODevice *io)
+{
+    enum State { OutsideRecentPostList, InsideRecentPostBox, InsideRecentPost };
+
+    QStringList rc;
+    QXmlStreamReader reader(io);
+
+    const QString classAttribute = QLatin1String("class");
+    const QString divElement = QLatin1String("div");
+    const QString anchorElement = QLatin1String("a");
+    const QString spanElement = QLatin1String("span");
+    State state = OutsideRecentPostList;
+    while (!reader.atEnd()) {
+        switch(reader.readNext()) {
+        case QXmlStreamReader::StartElement:
+            // Inside a <div> of an entry: Anchor or description
+            if (state == InsideRecentPost) {
+                if (reader.name() == anchorElement) { // Anchor
+                    // Strip host from link
+                    QString link = reader.attributes().value(QLatin1String("href")).toString();
+                    const int slashPos = link.lastIndexOf(QLatin1Char('/'));
+                    if (slashPos != -1)
+                        link.remove(0, slashPos + 1);
+                    const QString user = reader.readElementText();
+                    rc.push_back(link + QLatin1Char(' ') + user);
+                } else if (reader.name() == spanElement) { // <span> with description
+                    const QString description = reader.readElementText();
+                    QTC_ASSERT(!rc.isEmpty(), return rc; )
+                    padString(&rc.back(), 25);
+                    rc.back() += QLatin1Char(' ');
+                    rc.back() += description;
+                }
+            } else if (reader.name() == divElement) { // "<div>" state switching
+                switch (state) {
+                case OutsideRecentPostList:
+                    if (reader.attributes().value(classAttribute) == QLatin1String("content_left_box"))
+                        state = InsideRecentPostBox;
+                    break;
+                case InsideRecentPostBox:
+                    state = InsideRecentPost;
+                    break;
+                default:
+                    break;
+                }
+            } // divElement
+            break;
+        case QXmlStreamReader::EndElement:
+            if (reader.name() == divElement) {
+                switch (state) {
+                case InsideRecentPost:
+                    state = InsideRecentPostBox;
+                    break;
+                case InsideRecentPostBox: // Stop parsing  when leaving the box.
+                    return rc;
+                    break;
+                default:
+                    break;
+                }
+            }
+            break;
+       default:
+            break;
+        }
+    }
+    return rc;
+}
+
+void PasteBinDotComProtocol::listFinished()
+{
+    const bool error = m_listReply->error();
+    if (error) {
+        if (debug)
+            qDebug() << "listFinished: error" << m_listReply->errorString();
+    } else {
+        QStringList list = parseLists(m_listReply);
+        emit listDone(name(), list);
+        if (debug)
+            qDebug() << list;
+    }
+    m_listReply->deleteLater();
+    m_listReply = 0;
+}
+
 Core::IOptionsPage *PasteBinDotComProtocol::settingsPage()
 {
-    return settings;
+    return m_settings;
 }
 } // namespace CodePaster
diff --git a/src/plugins/cpaster/pastebindotcomprotocol.h b/src/plugins/cpaster/pastebindotcomprotocol.h
index 433c9fc1e2ff3ba3f84812821e72353f6eb53629..a7e2d30513726546294c22aac0fbf487527fd0f3 100644
--- a/src/plugins/cpaster/pastebindotcomprotocol.h
+++ b/src/plugins/cpaster/pastebindotcomprotocol.h
@@ -35,6 +35,8 @@
 #include <QtNetwork/QNetworkAccessManager>
 #include <QtNetwork/QHttp>
 
+#include <QtCore/QByteArray>
+
 namespace CodePaster {
 class PasteBinDotComSettings;
 
@@ -46,33 +48,35 @@ public:
 
     QString name() const { return QLatin1String("Pastebin.Com"); }
 
-    virtual unsigned capabilities() const { return 0; }
+    virtual unsigned capabilities() const;
     bool hasSettings() const { return true; }
     Core::IOptionsPage *settingsPage();
 
-    bool canList() const { return false; }
+    virtual void fetch(const QString &id);
+    virtual void paste(const QString &text,
+                       ContentType ct = Text,
+                       const QString &username = QString(),
+                       const QString &comment = QString(),
+                       const QString &description = QString());
+    virtual void list();
 
-    void fetch(const QString &id);
-    void paste(const QString &text,
-               const QString &username = QString(),
-               const QString &comment = QString(),
-               const QString &description = QString());
 public slots:
     void fetchFinished();
-
-    void postRequestFinished(int id, bool error);
-    void readPostResponseHeader(const QHttpResponseHeader &);
+    void pasteFinished();
+    void listFinished();
 
 private:
-    QString hostName() const;
+    QString hostName(bool withSubDomain) const;
 
-    PasteBinDotComSettings *settings;
-    QNetworkAccessManager manager;
-    QNetworkReply *reply;
-    QString fetchId;
+    PasteBinDotComSettings *m_settings;
+    QNetworkAccessManager m_manager;
+    QNetworkReply *m_fetchReply;
+    QNetworkReply *m_pasteReply;
+    QNetworkReply *m_listReply;
+    QByteArray m_pasteData;
 
-    QHttp http;
-    int postId;
+    QString m_fetchId;
+    int m_postId;
 };
 } // namespace CodePaster
 #endif // PASTEBINDOTCOMPROTOCOL_H
diff --git a/src/plugins/cpaster/pastebindotcomsettings.cpp b/src/plugins/cpaster/pastebindotcomsettings.cpp
index 7ec1607f2d693f0b96c75438bb213985613958e0..ba831d9b2c083afc388d500640fb5750547bdba2 100644
--- a/src/plugins/cpaster/pastebindotcomsettings.cpp
+++ b/src/plugins/cpaster/pastebindotcomsettings.cpp
@@ -35,14 +35,16 @@
 #include <QtCore/QSettings>
 #include <QtCore/QCoreApplication>
 
+static const char groupC[] = "PasteBinDotComSettings";
+static const char prefixKeyC[] = "Prefix";
+
 namespace CodePaster {
 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();
+        const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
+        m_hostPrefix = m_settings->value(rootKey + QLatin1String(prefixKeyC), QString()).toString();
     }
 }
 
@@ -86,8 +88,8 @@ void PasteBinDotComSettings::apply()
     if (!m_settings)
         return;
 
-    m_settings->beginGroup("PasteBinDotComSettings");
-    m_settings->setValue("Prefix", m_hostPrefix);
+    m_settings->beginGroup(QLatin1String(groupC));
+    m_settings->setValue(QLatin1String(prefixKeyC), m_hostPrefix);
     m_settings->endGroup();
 }
 
diff --git a/src/plugins/cpaster/pasteview.cpp b/src/plugins/cpaster/pasteview.cpp
index 79cbec1476b7553bbfe30a64dbe982e02da03fff..35ed030f1c44b6a5fae05541d9181575f3fadd90 100644
--- a/src/plugins/cpaster/pasteview.cpp
+++ b/src/plugins/cpaster/pasteview.cpp
@@ -30,6 +30,8 @@
 #include "pasteview.h"
 #include "protocol.h"
 
+#include <coreplugin/icore.h>
+
 #include <QtGui/QFontMetrics>
 #include <QtGui/QPainter>
 #include <QtGui/QScrollBar>
@@ -37,59 +39,19 @@
 #include <QtCore/QSettings>
 #include <QtCore/QByteArray>
 
-namespace CodePaster {
-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");
-}
+static const char groupC[] = "CPaster";
+static const char heightKeyC[] = "PasteViewHeight";
+static const char widthKeyC[] = "PasteViewWidth";
 
+namespace CodePaster {
 // -------------------------------------------------------------------------------------------------
-
-
 PasteView::PasteView(const QList<Protocol *> protocols,
                      QWidget *parent)
-    : QDialog(parent), m_protocols(protocols)
+    : QDialog(parent), m_protocols(protocols),
+    m_commentPlaceHolder(tr("<Comment>"))
 {
     m_ui.setupUi(this);
 
-    // Swap out the Patch PasteView widget with a ColumnIndicatorTextEdit, which will indicate column 100
-    delete m_ui.uiPatchView;
-    m_ui.uiPatchView = new ColumnIndicatorTextEdit(m_ui.groupBox);
-    m_ui.vboxLayout1->addWidget(m_ui.uiPatchView);
     m_ui.buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Paste"));
     connect(m_ui.uiPatchList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(contentChanged()));
 
@@ -106,23 +68,20 @@ PasteView::~PasteView()
 QString PasteView::user() const
 {
     const QString username = m_ui.uiUsername->text();
-    if (username.isEmpty() || username == tr("<Username>"))
-        return "Anonymous";
+    if (username.isEmpty())
+        return QLatin1String("Anonymous");
     return username;
 }
 
 QString PasteView::description() const
 {
-    const QString description = m_ui.uiDescription->text();
-    if (description == tr("<Description>"))
-        return QString();
-    return description;
+    return m_ui.uiDescription->text();
 }
 
 QString PasteView::comment() const
 {
     const QString comment = m_ui.uiComment->toPlainText();
-    if (comment == tr("<Comment>"))
+    if (comment == m_commentPlaceHolder)
         return QString();
     return comment;
 }
@@ -158,18 +117,11 @@ void PasteView::protocolChanged(int p)
 int PasteView::show(const QString &user, const QString &description, const QString &comment,
                const FileDataList &parts)
 {
-    if (user.isEmpty())
-        m_ui.uiUsername->setText(tr("<Username>"));
-    else
-        m_ui.uiUsername->setText(user);
-
-    if (description.isEmpty())
-        m_ui.uiDescription->setText(tr("<Description>"));
-    else
-        m_ui.uiDescription->setText(description);
+    m_ui.uiUsername->setText(user);
+    m_ui.uiDescription->setText(description);
 
     if (comment.isEmpty())
-        m_ui.uiComment->setPlainText(tr("<Comment>"));
+        m_ui.uiComment->setPlainText(m_commentPlaceHolder);
     else
         m_ui.uiComment->setPlainText(comment);
 
@@ -188,16 +140,22 @@ int PasteView::show(const QString &user, const QString &description, const QStri
     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();
+    QSettings *settings = Core::ICore::instance()->settings();
+    const QString rootKey = QLatin1String(groupC) + QLatin1Char('/');
+    const int h = settings->value(rootKey + QLatin1String(heightKeyC), height()).toInt();
+    const int defaultWidth = m_ui.uiPatchView->columnIndicator() + 50;
+    const int w = settings->value(rootKey + QLatin1String(widthKeyC), defaultWidth).toInt();
+
     resize(w, h);
-    int ret = QDialog::exec();
-    settings.setValue("/gui/height", height());
-    settings.setValue("/gui/width", width());
 
+    const int ret = QDialog::exec();
+
+    if (ret == QDialog::Accepted) {
+        settings->beginGroup(QLatin1String(groupC));
+        settings->setValue(QLatin1String(heightKeyC), height());
+        settings->setValue(QLatin1String(widthKeyC), width());
+        settings->endGroup();
+    }
     return ret;
 }
 
diff --git a/src/plugins/cpaster/pasteview.h b/src/plugins/cpaster/pasteview.h
index a69cc8588726f06a131e96aaf93e558eafe68f5b..9ccd10051d7b1d6c06f4f847cd56f95474119bb4 100644
--- a/src/plugins/cpaster/pasteview.h
+++ b/src/plugins/cpaster/pasteview.h
@@ -62,6 +62,7 @@ private slots:
 
 private:
     const QList<Protocol *> m_protocols;
+    const QString m_commentPlaceHolder;
 
     Ui::ViewDialog m_ui;
     FileDataList m_parts;
diff --git a/src/plugins/cpaster/pasteview.ui b/src/plugins/cpaster/pasteview.ui
index 3efe66c7cebf52e34907d6fd3e8b1b815b69d6e8..b7764d29d24b5a1dfa9b521b1bc9a5982d7f0576 100644
--- a/src/plugins/cpaster/pasteview.ui
+++ b/src/plugins/cpaster/pasteview.ui
@@ -38,7 +38,7 @@
      </item>
      <item row="1" column="1">
       <widget class="QLineEdit" name="uiUsername">
-       <property name="text">
+       <property name="placeholderText">
         <string>&lt;Username&gt;</string>
        </property>
       </widget>
@@ -55,7 +55,7 @@
      </item>
      <item row="2" column="1">
       <widget class="QLineEdit" name="uiDescription">
-       <property name="text">
+       <property name="placeholderText">
         <string>&lt;Description&gt;</string>
        </property>
       </widget>
@@ -83,7 +83,7 @@
       <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
 &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
 p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
 &lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&amp;lt;Comment&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
      </property>
     </widget>
@@ -133,7 +133,7 @@ p, li { white-space: pre-wrap; }
        </widget>
       </item>
       <item>
-       <widget class="QTextEdit" name="uiPatchView">
+       <widget class="CodePaster::ColumnIndicatorTextEdit" name="uiPatchView">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
           <horstretch>0</horstretch>
@@ -165,6 +165,13 @@ p, li { white-space: pre-wrap; }
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>CodePaster::ColumnIndicatorTextEdit</class>
+   <extends>QTextEdit</extends>
+   <header>columnindicatortextedit.h</header>
+  </customwidget>
+ </customwidgets>
  <tabstops>
   <tabstop>uiUsername</tabstop>
   <tabstop>uiDescription</tabstop>
diff --git a/src/plugins/cpaster/protocol.cpp b/src/plugins/cpaster/protocol.cpp
index 93c16dfb3114efac1b9188410e1d055d88faedee..be649f06775cded8a9655a1917ed7178ce477995 100644
--- a/src/plugins/cpaster/protocol.cpp
+++ b/src/plugins/cpaster/protocol.cpp
@@ -28,6 +28,9 @@
 **************************************************************************/
 #include "protocol.h"
 
+#include <cpptools/cpptoolsconstants.h>
+#include <qmljseditor/qmljseditorconstants.h>
+
 namespace CodePaster {
 
 Protocol::Protocol()
@@ -64,4 +67,45 @@ void Protocol::list()
     qFatal("Base Protocol list() called");
 }
 
+Protocol::ContentType Protocol::contentType(const QString &mt)
+{
+    if (mt  == QLatin1String(CppTools::Constants::C_SOURCE_MIMETYPE)
+        || mt == QLatin1String(CppTools::Constants::C_HEADER_MIMETYPE)
+        || mt == QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)
+        || mt == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)
+        || mt == QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE))
+        return C;
+    if (mt == QLatin1String(QmlJSEditor::Constants::QML_MIMETYPE)
+        || mt == QLatin1String(QmlJSEditor::Constants::JS_MIMETYPE))
+        return JavaScript;
+    if (mt == QLatin1String("text/x-patch"))
+        return Diff;
+    if (mt == QLatin1String("text/xml") || mt == QLatin1String("application/xml"))
+        return Xml;
+    return Text;
+}
+
+QString Protocol::fixNewLines(QString data)
+{
+    // Copied from cpaster. Otherwise lineendings will screw up
+    // HTML requires "\r\n".
+    if (data.contains(QLatin1String("\r\n")))
+        return data;
+    if (data.contains(QLatin1Char('\n'))) {
+        data.replace(QLatin1Char('\n'), QLatin1String("\r\n"));
+        return data;
+    }
+    if (data.contains(QLatin1Char('\r')))
+        data.replace(QLatin1Char('\r'), QLatin1String("\r\n"));
+    return data;
+}
+
+QString Protocol::textFromHtml(QString data)
+{
+    data.remove(QLatin1Char('\r'));
+    data.replace(QLatin1String("&lt;"), QString(QLatin1Char('<')));
+    data.replace(QLatin1String("&gt;"), QString(QLatin1Char('>')));
+    data.replace(QLatin1String("&amp;"), QString(QLatin1Char('&')));
+    return data;
+}
 } //namespace CodePaster
diff --git a/src/plugins/cpaster/protocol.h b/src/plugins/cpaster/protocol.h
index eed43167a341d328bf606daf5a3d6ef04bb4ebf1..914a5748a4e58639c23d84bea87e4ff6ddd3d227 100644
--- a/src/plugins/cpaster/protocol.h
+++ b/src/plugins/cpaster/protocol.h
@@ -41,6 +41,10 @@ class Protocol : public QObject
 {
     Q_OBJECT
 public:
+    enum ContentType{
+        Text, C, JavaScript, Diff, Xml
+    };
+
     enum Capabilities  {
         ListCapability = 0x1,
         PostCommentCapability = 0x2,
@@ -62,16 +66,25 @@ public:
     virtual void fetch(const QString &id) = 0;
     virtual void list();
     virtual void paste(const QString &text,
+                       ContentType ct = Text,
                        const QString &username = QString(),
                        const QString &comment = QString(),
                        const QString &description = QString()) = 0;
 
+    // Convenience to determine content type from mime type
+    static ContentType contentType(const QString &mimeType);
+
 signals:
     void pasteDone(const QString &link);
     void fetchDone(const QString &titleDescription,
                    const QString &content,
                    bool error);
     void listDone(const QString &name, const QStringList &result);
+
+protected:
+    static QString textFromHtml(QString data);
+    static QString fixNewLines(QString in);
+
 };
 
 } //namespace CodePaster