KDE/kdeplasma-addons/applets/pastebin

Artur Duque de Souza morpheuz at gmail.com
Thu Jul 9 15:22:32 CEST 2009


SVN commit 993753 by asouza:

TinyURL support on pastebin

Now if you drop an http url on pastebin it will give you back a
tinyurl. Right now I didn't implement this as a backend as we do
not have others for tinyurl, but we may want this to be a backend
for the sake of cleaness.

CCMAIL:plasma-devel at kde.org


 M  +25 -0     pastebin.cpp  
 M  +5 -0      pastebin.h  


--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.cpp #993752:993753
@@ -693,6 +693,23 @@
 #endif //Q_WS_WIN
 }
 
+void Pastebin::processTinyUrl(QNetworkReply *reply)
+{
+    QByteArray dataRaw(reply->readAll());
+    QString data(dataRaw);
+
+    QRegExp re(".*<blockquote><b>([^<]+)</b><br>.*");
+
+    if (!re.exactMatch(data)) {
+        // couldn't find url
+        showErrors();
+        return;
+    }
+
+    QString tinyUrl = re.cap(1);
+    showResults(tinyUrl);
+}
+
 void Pastebin::postContent(QString text, QImage imageData)
 {
     bool image = false;
@@ -722,6 +739,14 @@
             file.open(QIODevice::ReadOnly);
             QTextStream in(&file);
             text = in.readAll();
+        } else if (testPath.scheme().toLower() == QString("http")) {
+            // lets make use of tiny url ;)
+            QString tinyUrl = QString("http://tinyurl.com/create.php?url=%1").arg(testPath.prettyUrl());
+            manager = new QNetworkAccessManager(this);
+            connect(manager, SIGNAL(finished(QNetworkReply*)),
+                    this, SLOT(processTinyUrl(QNetworkReply*)));
+            manager->get(QNetworkRequest(tinyUrl));
+            return;
         }
 
         // upload text
--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.h #993752:993753
@@ -34,6 +34,7 @@
 
 #include <QTimer>
 #include <QPen>
+#include <QtNetwork>
 
 class QSignalMapper;
 class KAction;
@@ -86,6 +87,7 @@
     void showErrors();
     void openLink();
     void postClipboard();
+    void processTinyUrl(QNetworkReply *reply);
 
 protected:
     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
@@ -146,6 +148,9 @@
     QAction *m_topSeparator;
     QAction *m_bottomSeparator;
 
+    // to handle request to tinyUrl
+    QNetworkAccessManager *manager;
+
     Ui::pastebinConfig uiConfig;
     Ui::pastebinServersConfig uiServers;
 };


More information about the Plasma-devel mailing list