Re: KDE/kdeplasma-addons/applets/pastebin

2009-07-11 Thread Artur Souza (MoRpHeUz)
On Friday 10 July 2009, 23:52 Travis wrote:
 They prefer you to use the api which returns a small amount of plaintext
 where you just need to take the final line and that's your URL. I've done
 this for the Konversation tinyurl shell script found here:
 http://lxr.kde.org/source/extragear/network/konversation/data/scripts/tinyu
rl

Thanks for your feedback. I was not able to find their api before. I'll fix 
this 
asap ;). That was the idea of CCing the mailing list ;)

Cheers,

--
Artur Duque de Souza
openBossa Research Labs
INdT - Instituto Nokia de Tecnologia
--
Blog: http://blog.morpheuz.cc
PGP: 0xDBEEAAC3 @ wwwkeys.pgp.net
--


signature.asc
Description: This is a digitally signed message part.
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


Re: KDE/kdeplasma-addons/applets/pastebin

2009-07-10 Thread Travis
On Thursday 09 July 2009 6:22:32 am Artur Duque de Souza wrote:
 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@kde.org

It looks like you're using screen-scraping to grab the url which isn't-
A) future proof (what if they change their site design?) and
B) wastes their bandwidth (perhaps marginal, but still a waste). 

They prefer you to use the api which returns a small amount of plaintext where 
you just need to take the final line and that's your URL. I've done this for 
the Konversation tinyurl shell script found here: 
http://lxr.kde.org/source/extragear/network/konversation/data/scripts/tinyurl


Travis McHenry
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


KDE/kdeplasma-addons/applets/pastebin

2009-07-09 Thread Artur Duque de Souza
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@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(.*blockquoteb([^]+)/bbr.*);
+
+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;
 };
___
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel