]> git.sesse.net Git - kdenlive/blobdiff - src/utils/resourcewidget.cpp
Better to use nepomukcore
[kdenlive] / src / utils / resourcewidget.cpp
index 39c8ec5263eec0f17f8c59c06725ea870ad98233..9935f674d0de89a9aa164104bf6a43c5394c77ab 100644 (file)
 #include <KIO/NetAccess>
 #include <Solid/Networking>
 #include <KRun>
+#if KDE_IS_VERSION(4,4,0)
 #include <KPixmapSequence>
 #include <KPixmapSequenceOverlayPainter>
-
+#endif
+#include <KFileItem>
 
 #ifdef USE_NEPOMUK
 #if KDE_IS_VERSION(4,6,0)
 #include <Nepomuk/Vocabulary/NIE>
 #include <Nepomuk/Vocabulary/NCO>
 #include <Nepomuk/Vocabulary/NDO>
-#include <kfileitem.h>
 #endif
 #endif
 
+#ifdef USE_NEPOMUKCORE
+#include <Nepomuk2/Variant>
+#include <Nepomuk2/Resource>
+#include <Nepomuk2/ResourceManager>
+#include <Nepomuk2/Vocabulary/NIE>
+#include <Nepomuk2/Vocabulary/NCO>
+#include <Nepomuk2/Vocabulary/NDO>
+#endif
+
 ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
         QDialog(parent),
         m_folder(folder),
@@ -75,7 +85,7 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
     connect(search_results, SIGNAL(currentRowChanged(int)), this, SLOT(slotUpdateCurrentSound()));
     connect(button_preview, SIGNAL(clicked()), this, SLOT(slotPlaySound()));
     connect(button_import, SIGNAL(clicked()), this, SLOT(slotSaveItem()));
-    connect(item_license, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
+    connect(item_license, SIGNAL(leftClickedUrl(QString)), this, SLOT(slotOpenUrl(QString)));
     connect(service_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeService()));
     if (Solid::Networking::status() == Solid::Networking::Unconnected) {
         slotOffline();
@@ -85,7 +95,7 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
     connect(page_next, SIGNAL(clicked()), this, SLOT(slotNextPage()));
     connect(page_prev, SIGNAL(clicked()), this, SLOT(slotPreviousPage()));
     connect(page_number, SIGNAL(valueChanged(int)), this, SLOT(slotStartSearch(int)));
-    connect(info_browser, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(slotOpenLink(const QUrl &)));
+    connect(info_browser, SIGNAL(anchorClicked(QUrl)), this, SLOT(slotOpenLink(QUrl)));
     
     m_autoPlay = new QAction(i18n("Auto Play"), this);
     m_autoPlay->setCheckable(true);
@@ -94,9 +104,11 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
     config_button->setMenu(resourceMenu);
     config_button->setIcon(KIcon("configure"));
 
+#if KDE_IS_VERSION(4,4,0)
     m_busyWidget = new KPixmapSequenceOverlayPainter(this);
     m_busyWidget->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
     m_busyWidget->setWidget(search_results->viewport());
+#endif
     
     sound_box->setEnabled(false);
     search_text->setFocus();
@@ -110,7 +122,7 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
 
 ResourceWidget::~ResourceWidget()
 {
-    if (m_currentService) delete m_currentService;
+    delete m_currentService;
     KIO::NetAccess::removeTempFile(m_tmpThumbFile);
 }
 
@@ -119,7 +131,9 @@ void ResourceWidget::slotStartSearch(int page)
     page_number->blockSignals(true);
     page_number->setValue(page);
     page_number->blockSignals(false);
+#if KDE_IS_VERSION(4,4,0)
     m_busyWidget->start();
+#endif
     m_currentService->slotStartSearch(search_text->text(), page);
 }
 
@@ -186,7 +200,7 @@ void ResourceWidget::slotLoadThumb(const QString url)
 }
 
 
-void ResourceWidget::slotDisplayMetaInfo(QMap <QString, QString> metaInfo)
+void ResourceWidget::slotDisplayMetaInfo(const QMap<QString, QString> &metaInfo)
 {
     if (metaInfo.contains("license")) {
         parseLicense(metaInfo.value("license"));
@@ -206,26 +220,7 @@ void ResourceWidget::slotPlaySound()
 }
 
 
-void ResourceWidget::slotForcePlaySound(bool play)
-{
-    /*
-    if (m_service != FREESOUND) return;
-    m_previewProcess->close();
-    if (m_currentPreview.isEmpty()) return;
-    if (play)
-        m_previewProcess->start("ffplay", QStringList() << m_currentPreview << "-nodisp");
-    */
-}
-
-void ResourceWidget::slotPreviewStatusChanged(QProcess::ProcessState state)
-{
-    /*if (state == QProcess::NotRunning)
-        button_preview->setText(i18n("Preview"));
-    else 
-        button_preview->setText(i18n("Stop"));*/
-}
-
-void ResourceWidget::slotSaveItem(const QString originalUrl)
+void ResourceWidget::slotSaveItem(const QString &originalUrl)
 {
     //if (m_currentUrl.isEmpty()) return;
     QListWidgetItem *item = search_results->currentItem();
@@ -235,7 +230,7 @@ void ResourceWidget::slotSaveItem(const QString originalUrl)
     if (!path.endsWith('/')) path.append('/');
     if (!originalUrl.isEmpty()) {
         path.append(KUrl(originalUrl).fileName());
-        ext = "*." + KUrl(originalUrl).fileName().section(".", -1);
+        ext = "*." + KUrl(originalUrl).fileName().section('.', -1);
         m_currentInfo.itemDownload = originalUrl;
     }
     else {
@@ -270,13 +265,23 @@ void ResourceWidget::slotGotFile(KJob *job)
         res.setProperty( Nepomuk::Vocabulary::NIE::license(), (Nepomuk::Variant) job->property("license") );
         res.setProperty( Nepomuk::Vocabulary::NIE::licenseType(), (Nepomuk::Variant) job->property("licenseurl") );
         res.setProperty( Nepomuk::Vocabulary::NDO::copiedFrom(), (Nepomuk::Variant) job->property("originurl") );
-        res.setProperty( Nepomuk::Vocabulary::NDO::copiedFrom(), (Nepomuk::Variant) job->property("originurl") );
         res.setProperty( Nepomuk::Vocabulary::NCO::creator(), (Nepomuk::Variant) job->property("author") );
         //res.setDescription(item_description->toPlainText());
         //res.setProperty( Soprano::Vocabulary::NAO::description(), 
 #endif
 #endif
-        emit addClip(filePath, QString());
+
+#ifdef USE_NEPOMUKCORE
+        Nepomuk2::Resource res( filePath );
+        res.setProperty( Nepomuk2::Vocabulary::NIE::license(), (Nepomuk2::Variant) job->property("license") );
+        res.setProperty( Nepomuk2::Vocabulary::NIE::licenseType(), (Nepomuk2::Variant) job->property("licenseurl") );
+        res.setProperty( Nepomuk2::Vocabulary::NDO::copiedFrom(), (Nepomuk2::Variant) job->property("originurl") );
+        res.setProperty( Nepomuk2::Vocabulary::NCO::creator(), (Nepomuk2::Variant) job->property("author") );
+        //res.setDescription(item_description->toPlainText());
+        //res.setProperty( Soprano::Vocabulary::NAO::description(), 
+#endif
+
+        emit addClip(filePath, stringMap());
 }
 
 void ResourceWidget::slotOpenUrl(const QString &url)
@@ -301,12 +306,14 @@ void ResourceWidget::slotChangeService()
         m_currentService = new ArchiveOrg(search_results);
     }
 
-    connect(m_currentService, SIGNAL(gotMetaInfo(const QString)), this, SLOT(slotSetMetadata(const QString)));
-    connect(m_currentService, SIGNAL(gotMetaInfo(QMap <QString, QString>)), this, SLOT(slotDisplayMetaInfo(QMap <QString, QString>)));
-    connect(m_currentService, SIGNAL(maxPages(int)), page_number, SLOT(setMaximum(int)));
+    connect(m_currentService, SIGNAL(gotMetaInfo(QString)), this, SLOT(slotSetMetadata(QString)));
+    connect(m_currentService, SIGNAL(gotMetaInfo(QMap<QString,QString>)), this, SLOT(slotDisplayMetaInfo(QMap<QString,QString>)));
+    connect(m_currentService, SIGNAL(maxPages(int)), this, SLOT(slotSetMaximum(int)));
     connect(m_currentService, SIGNAL(searchInfo(QString)), search_info, SLOT(setText(QString)));
-    connect(m_currentService, SIGNAL(gotThumb(const QString)), this, SLOT(slotLoadThumb(const QString)));
+    connect(m_currentService, SIGNAL(gotThumb(QString)), this, SLOT(slotLoadThumb(QString)));
+#if KDE_IS_VERSION(4,4,0)
     connect(m_currentService, SIGNAL(searchDone()), m_busyWidget, SLOT(stop()));
+#endif
     
     button_preview->setVisible(m_currentService->hasPreview);
     button_import->setVisible(!m_currentService->inlineDownload);
@@ -314,6 +321,11 @@ void ResourceWidget::slotChangeService()
     if (!search_text->text().isEmpty()) slotStartSearch();
 }
 
+void ResourceWidget::slotSetMaximum(int max)
+{
+    page_number->setMaximum(max);
+}
+
 void ResourceWidget::slotOnline()
 {
     button_search->setEnabled(true);
@@ -378,25 +390,25 @@ void ResourceWidget::slotOpenLink(const QUrl &url)
     }
 }
 
-void ResourceWidget::slotSetDescription(const QString desc)
+void ResourceWidget::slotSetDescription(const QString &desc)
 {
     m_desc = desc;
     updateLayout();
 }
 
-void ResourceWidget::slotSetMetadata(const QString desc)
+void ResourceWidget::slotSetMetadata(const QString &desc)
 {
     m_meta = desc;
     updateLayout();
 }
 
-void ResourceWidget::slotSetImage(const QString desc)
+void ResourceWidget::slotSetImage(const QString &desc)
 {
     m_image = QString("<img src=\"%1\" style=\"max-height:150px\" max-width=\"%2px\" />").arg(desc).arg((int) (info_browser->width() * 0.9));
     updateLayout();
 }
 
-void ResourceWidget::slotSetTitle(const QString desc)
+void ResourceWidget::slotSetTitle(const QString &desc)
 {
     m_title = desc;
     updateLayout();
@@ -409,4 +421,7 @@ void ResourceWidget::updateLayout()
     if (!m_desc.isEmpty()) content.append(m_desc);
     if (!m_meta.isEmpty()) content.append(m_meta);
     info_browser->setHtml(content);
-}
\ No newline at end of file
+}
+
+
+#include "resourcewidget.moc"