[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [Choqok] c19a127: is.gd shortener job made async too (Do not freeze
From:       Mehrdad Momeny <mehrdad.momeny () gmail ! com>
Date:       2010-12-19 12:39:45
Message-ID: 20101219123945.E0148A608F () git ! kde ! org
[Download RAW message or body]

commit c19a12706b239885ddfba393598bc8fbaa65f557
branch master
Author: Mehrdad Momeny <mehrdad.momeny@gmail.com>
Date:   Sat Dec 18 22:07:08 2010 +0330

    is.gd shortener job made async too (Do not freeze UI)

diff --git a/plugins/shorteners/is_gd/is_gd.cpp b/plugins/shorteners/is_gd/is_gd.cpp
index f532ce0..7afbc63 100644
--- a/plugins/shorteners/is_gd/is_gd.cpp
+++ b/plugins/shorteners/is_gd/is_gd.cpp
@@ -29,6 +29,7 @@
 #include <KAboutData>
 #include <KGenericFactory>
 #include <kglobal.h>
+#include <qeventloop.h>
 
 K_PLUGIN_FACTORY( MyPluginFactory, registerPlugin < Is_gd > (); )
 K_EXPORT_PLUGIN( MyPluginFactory( "choqok_is_gd" ) )
@@ -45,21 +46,24 @@ Is_gd::~Is_gd()
 QString Is_gd::shorten( const QString& url )
 {
     kDebug() << "Using is.gd";
-    QByteArray data;
     KUrl reqUrl( "http://is.gd/api.php" );
     reqUrl.addQueryItem( "longurl", KUrl( url ).url() );
 
-    KIO::Job* job = KIO::get( reqUrl, KIO::Reload, KIO::HideProgressInfo );
+    QEventLoop loop;
+    KIO::StoredTransferJob* job = KIO::storedGet( reqUrl, KIO::Reload, KIO::HideProgressInfo );
+    connect(job, SIGNAL(result(KJob*)), &loop, SLOT(quit()));
+    job->start();
+    loop.exec();
 
-    if( KIO::NetAccess::synchronousRun( job, 0, &data ) ) {
-        QString output(data);
+    if( job->error() == KJob::NoError ) {
+        QString output(job->data());
         kDebug() << "Short url is: " << output;
         if( !output.isEmpty() ) {
             return output;
         }
     }
     else {
-        kDebug() << "Cannot create a shorten url.\t" << "KJob ERROR";
+        kDebug() << "KJob ERROR" << job->errorString();
     }
     return url;
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic