]> git.sesse.net Git - kdenlive/commitdiff
Asynchronous download for online resource widget (still some bugs)
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 4 Jan 2012 01:02:55 +0000 (02:02 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 4 Jan 2012 01:02:55 +0000 (02:02 +0100)
src/utils/openclipart.cpp
src/utils/resourcewidget.cpp
src/utils/resourcewidget.h

index f0cf579cbf86e3584d3c77de52328ead0deae05e..0ba51fa4ea4a9cffe51dd6a41516a888aded044e 100644 (file)
@@ -54,9 +54,7 @@ void OpenClipArt::slotStartSearch(const QString searchText, int page)
 void OpenClipArt::slotShowResults(KJob* job)
 {
     if (job->error() != 0 ) return;
-    m_listWidget->blockSignals(true);
-    
-    
+    m_listWidget->blockSignals(true);    
     KIO::StoredTransferJob* storedQueryJob = static_cast<KIO::StoredTransferJob*>( job );
     
     QDomDocument doc;
index 60b210ecb57c21c19c9a0e778d168cc60e59179f..cce3858314c4d6c7d9df39fc94d0491bb6ff84a9 100644 (file)
@@ -48,6 +48,7 @@
 #include <Soprano/Vocabulary/NAO>
 #include <Nepomuk/Vocabulary/NIE>
 #include <Nepomuk/Vocabulary/NDO>
+#include <kfileitem.h>
 #endif
 #endif
 
@@ -211,9 +212,22 @@ void ResourceWidget::slotSaveItem(const QString originalUrl)
         ext = m_currentService->getExtension(search_results->currentItem());
     }
     QString saveUrl = KFileDialog::getSaveFileName(KUrl(path), ext);
-    if (saveUrl.isEmpty()) return;
-    if (KIO::NetAccess::download(KUrl(m_currentInfo.itemDownload), saveUrl, this)) {
-        const KUrl filePath = KUrl(saveUrl);
+    KIO::UDSEntry entry;
+    KUrl srcUrl(m_currentInfo.itemDownload);
+    if (saveUrl.isEmpty() || !KIO::NetAccess::stat(srcUrl, entry, this)) return;
+    KIO::FileCopyJob * getJob = KIO::file_copy(srcUrl, KUrl(saveUrl), -1, KIO::Overwrite);
+    
+    KFileItem info(entry, srcUrl); 
+    getJob->setSourceSize(info.size());
+    connect(getJob, SIGNAL(result(KJob*)), this, SLOT(slotGotFile(KJob*)));
+    getJob->start();
+}
+
+void ResourceWidget::slotGotFile(KJob *job)
+{
+    if (job->error() != 0 ) return;
+    KIO::FileCopyJob* copyJob = static_cast<KIO::FileCopyJob*>( job );
+    const KUrl filePath = copyJob->destUrl();
 #ifdef USE_NEPOMUK
 #if KDE_IS_VERSION(4,6,0)
         Nepomuk::Resource res( filePath );
@@ -224,8 +238,7 @@ void ResourceWidget::slotSaveItem(const QString originalUrl)
         //res.setProperty( Soprano::Vocabulary::NAO::description(), 
 #endif
 #endif
-        emit addClip(KUrl(saveUrl), QString());//, sound_name->url());
-    }
+        emit addClip(filePath, QString());//, sound_name->url());
 }
 
 void ResourceWidget::slotOpenUrl(const QString &url)
index f4a19c158386ec17bfeb4a3eb80a12525db3d286..575f46101b372077900867cdac852a0afc61cfa2 100644 (file)
@@ -57,6 +57,8 @@ private slots:
     void slotGotMetaInfo(const QString info);
     void slotOpenLink(const QUrl &url);
     void slotLoadThumb(const QString url);
+    /** @brief A file download is finished */
+    void slotGotFile(KJob *job);
 
 private:
     QString m_folder;