]> git.sesse.net Git - kdenlive/commitdiff
Cleanup online resource feature
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 31 Dec 2011 19:07:59 +0000 (20:07 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 31 Dec 2011 19:07:59 +0000 (20:07 +0100)
src/mainwindow.cpp
src/utils/CMakeLists.txt
src/utils/abstractservice.cpp [new file with mode: 0644]
src/utils/abstractservice.h [new file with mode: 0644]
src/utils/freesound.cpp
src/utils/freesound.h
src/utils/openclipart.cpp [new file with mode: 0644]
src/utils/openclipart.h [new file with mode: 0644]
src/utils/resourcewidget.cpp [new file with mode: 0644]
src/utils/resourcewidget.h [new file with mode: 0644]
src/widgets/freesound_ui.ui

index fa60af96e0234294ea2aadb46a3245010011c410..3f24cada12fca918e49eb37883bca8e1ee98ce5c 100644 (file)
@@ -64,7 +64,7 @@
 #include "audioscopes/spectrogram.h"
 #include "archivewidget.h"
 #include "databackup/backupwidget.h"
-#include "utils/freesound.h"
+#include "utils/resourcewidget.h"
 
 
 #include <KApplication>
@@ -4508,7 +4508,7 @@ void MainWindow::slotDownloadResources()
     QString currentFolder;
     if (m_activeDocument) currentFolder = m_activeDocument->projectFolder().path();
     else currentFolder = KdenliveSettings::defaultprojectfolder();
-    FreeSound *d = new FreeSound(currentFolder);
+    ResourceWidget *d = new ResourceWidget(currentFolder);
     connect(d, SIGNAL(addClip(KUrl, const QString &)), this, SLOT(slotAddProjectClip(KUrl, const QString &)));
     d->show();
 }
index 00e9eddff2431df02dc0a18b8c2c1b229b0ba4b1..8c80687ee07b6e29599c53a858f8237d5ffedd96 100644 (file)
@@ -1,6 +1,9 @@
 set(kdenlive_SRCS
   ${kdenlive_SRCS}
+  utils/abstractservice.cpp
   utils/freesound.cpp
+  utils/openclipart.cpp
+  utils/resourcewidget.cpp
   PARENT_SCOPE
 )
 
diff --git a/src/utils/abstractservice.cpp b/src/utils/abstractservice.cpp
new file mode 100644 (file)
index 0000000..9692eea
--- /dev/null
@@ -0,0 +1,69 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#include "abstractservice.h"
+
+#include <QObject>
+
+
+AbstractService::AbstractService(QListWidget *listWidget, QObject * parent) :
+        QObject(parent),
+        hasPreview(false),
+        hasMetadata(false),
+        serviceType(NOSERVICE),
+        m_listWidget(listWidget)
+{
+}
+
+AbstractService::~AbstractService()
+{
+}
+
+void AbstractService::slotStartSearch(const QString , int )
+{
+}
+
+OnlineItemInfo AbstractService::displayItemDetails(QListWidgetItem */*item*/)
+{
+    OnlineItemInfo info;
+    return info;
+}
+
+bool AbstractService::startItemPreview(QListWidgetItem *)
+{
+    return false;
+}
+
+void AbstractService::stopItemPreview(QListWidgetItem *)
+{
+}
+
+QString AbstractService::getExtension(QListWidgetItem *)
+{
+    return QString();
+}
+
+
+QString AbstractService::getDefaultDownloadName(QListWidgetItem *)
+{
+    return QString();
+}
+
diff --git a/src/utils/abstractservice.h b/src/utils/abstractservice.h
new file mode 100644 (file)
index 0000000..52c3026
--- /dev/null
@@ -0,0 +1,92 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef ABSTRACTSERVICE_H
+#define ABSTRACTSERVICE_H
+
+
+#include <QListWidget>
+
+const int imageRole = Qt::UserRole;
+const int urlRole = Qt::UserRole + 1;
+const int downloadRole = Qt::UserRole + 2;
+const int durationRole = Qt::UserRole + 3;
+const int previewRole = Qt::UserRole + 4;
+const int authorRole = Qt::UserRole + 5;
+const int authorUrl = Qt::UserRole + 6;
+const int infoUrl = Qt::UserRole + 7;
+const int infoData = Qt::UserRole + 8;
+const int idRole = Qt::UserRole + 9;
+const int licenseRole = Qt::UserRole + 10;
+const int descriptionRole = Qt::UserRole + 11;
+
+enum SERVICETYPE { NOSERVICE = 0, FREESOUND = 1, OPENCLIPART = 2 };
+
+struct OnlineItemInfo {
+    QString imagePreview;
+    QString itemPreview;
+    QString itemName;
+    QString itemDownload;
+    QString itemId;
+    QString infoUrl;
+    QString license;
+    QString author;
+    QString authorUrl;
+    QString description;
+};
+
+
+class AbstractService : public QObject
+{
+    Q_OBJECT
+
+public:
+    AbstractService(QListWidget *listWidget, QObject * parent = 0);
+    ~AbstractService();
+    /** @brief Get file extension for currently selected item. */
+    virtual QString getExtension(QListWidgetItem *item);
+    /** @brief Get recommanded download file name. */
+    virtual QString getDefaultDownloadName(QListWidgetItem *item);
+        /** @brief Does this service provide a preview (for example preview a sound. */
+    bool hasPreview;
+    /** @brief Does this service provide meta info about the item. */
+    bool hasMetadata;
+    /** @brief The type for this service. */
+    SERVICETYPE serviceType;
+
+public slots:
+    virtual void slotStartSearch(const QString searchText, int page = 0);
+    virtual OnlineItemInfo displayItemDetails(QListWidgetItem *item);
+    virtual bool startItemPreview(QListWidgetItem *item);
+    virtual void stopItemPreview(QListWidgetItem *item);
+
+protected:
+    QListWidget *m_listWidget;
+    
+signals:
+    void searchInfo(const QString &);
+    void maxPages(int);
+    void gotMetaInfo(QMap <QString, QString> info);
+};
+
+
+#endif
+
index bb8a2e5ba18365a1c87a7ee001d6c358e35a30a2..cb4459344afb302ff49360df5f534c3244ce8856 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
- *   Copyright (C) 2011 by Marco Gittler (marco@gitma.de)                  *
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
 #include <qjson/parser.h>
 #endif
 
-const int imageRole = Qt::UserRole;
-const int urlRole = Qt::UserRole + 1;
-const int downloadRole = Qt::UserRole + 2;
-const int durationRole = Qt::UserRole + 3;
-const int previewRole = Qt::UserRole + 4;
-const int authorRole = Qt::UserRole + 5;
-const int authorUrl = Qt::UserRole + 6;
-const int infoUrl = Qt::UserRole + 7;
-const int infoData = Qt::UserRole + 8;
-const int idRole = Qt::UserRole + 9;
-const int licenseRole = Qt::UserRole + 10;
-const int descriptionRole = Qt::UserRole + 11;
-
-FreeSound::FreeSound(const QString & folder, QWidget * parent) :
-        QDialog(parent),
-        m_folder(folder),
-        m_service(FREESOUND)
+FreeSound::FreeSound(QListWidget *listWidget, QObject *parent) :
+        AbstractService(listWidget, parent),
+        m_previewProcess(new QProcess)
 {
-    setFont(KGlobalSettings::toolBarFont());
-    setupUi(this);
-    setAttribute(Qt::WA_DeleteOnClose);
-#ifdef USE_QJSON
-    service_list->addItem(i18n("Freesound Audio Library"), FREESOUND);
-#endif
-    service_list->addItem(i18n("Open Clip Art Graphic Library"), OPENCLIPART);
-    setWindowTitle(i18n("Search Online Resources"));
-    info_widget->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
-    item_description->setStyleSheet(QString("KTextBrowser { background-color: transparent;}"));
-    connect(button_search, SIGNAL(clicked()), this, SLOT(slotStartSearch()));
-    connect(search_results, SIGNAL(currentRowChanged(int)), this, SLOT(slotUpdateCurrentSound()));
-    connect(button_preview, SIGNAL(clicked()), this, SLOT(slotPlaySound()));
-    connect(button_import, SIGNAL(clicked()), this, SLOT(slotSaveSound()));
-    connect(sound_author, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
-    connect(item_license, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
-    connect(sound_name, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
-    m_previewProcess = new QProcess;
-    connect(m_previewProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotPreviewStatusChanged(QProcess::ProcessState)));
-    connect(service_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeService()));
-    sound_image->setFixedWidth(180);
-    if (Solid::Networking::status() == Solid::Networking::Unconnected) {
-        slotOffline();
-    }
-    connect(Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, SLOT(slotOnline()));
-    connect(Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), this, SLOT(slotOffline()));
-    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)));
-    sound_box->setEnabled(false);
-    search_text->setFocus();
-    Nepomuk::ResourceManager::instance()->init();
+    serviceType = FREESOUND;
+    hasPreview = true;
+    hasMetadata = true;
+    //connect(m_previewProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotPreviewStatusChanged(QProcess::ProcessState)));
 }
 
 FreeSound::~FreeSound()
@@ -106,26 +64,14 @@ FreeSound::~FreeSound()
     if (m_previewProcess) delete m_previewProcess;
 }
 
-void FreeSound::slotStartSearch(int page)
+void FreeSound::slotStartSearch(const QString searchText, int page)
 {
-    m_currentPreview.clear();
-    m_currentUrl.clear();
-    page_number->blockSignals(true);
-    page_number->setValue(page);
-    page_number->blockSignals(false);
-    QString uri;
-    if (m_service == FREESOUND) {
-        uri = "http://www.freesound.org/api/sounds/search/?q=";
-        uri.append(search_text->text());
-        if (page > 1) uri.append("&p=" + QString::number(page));
-        uri.append("&api_key=a1772c8236e945a4bee30a64058dabf8");
-    }
-    else if (m_service == OPENCLIPART) {
-        uri = "http://openclipart.org/api/search/?query=";
-        uri.append(search_text->text());
-        if (page > 1) uri.append("&page=" + QString::number(page));
-    }
-    
+    m_listWidget->clear();
+    QString uri = "http://www.freesound.org/api/sounds/search/?q=";
+    uri.append(searchText);
+    if (page > 1) uri.append("&p=" + QString::number(page));
+    uri.append("&api_key=a1772c8236e945a4bee30a64058dabf8");
+
     KJob* resolveJob = KIO::storedGet( KUrl(uri), KIO::NoReload, KIO::HideProgressInfo );
     connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotShowResults( KJob* ) ) );
 }
@@ -134,143 +80,85 @@ void FreeSound::slotStartSearch(int page)
 void FreeSound::slotShowResults(KJob* job)
 {
     if (job->error() != 0 ) return;
-    search_results->blockSignals(true);
-    search_results->clear();
+    m_listWidget->blockSignals(true);
     KIO::StoredTransferJob* storedQueryJob = static_cast<KIO::StoredTransferJob*>( job );
-    if (m_service == FREESOUND) {
 #ifdef USE_QJSON
-        QJson::Parser parser;
-        bool ok;
-        //kDebug()<<"// GOT RESULT: "<<m_result;
-        QVariant data = parser.parse(storedQueryJob->data(), &ok);
-        QVariant sounds;
-        if (data.canConvert(QVariant::Map)) {
-            QMap <QString, QVariant> map = data.toMap();
-            QMap<QString, QVariant>::const_iterator i = map.constBegin();
-            while (i != map.constEnd()) {
-                if (i.key() == "num_results") search_info->setText(i18np("Found %1 result", "Found %1 results", i.value().toInt()));
-                else if (i.key() == "num_pages") {
-                    page_number->setMaximum(i.value().toInt());
-                }
-                else if (i.key() == "sounds") {
-                    sounds = i.value();
-                    if (sounds.canConvert(QVariant::List)) {
-                        QList <QVariant> soundsList = sounds.toList();
-                        for (int j = 0; j < soundsList.count(); j++) {
-                            if (soundsList.at(j).canConvert(QVariant::Map)) {
-                                QMap <QString, QVariant> soundmap = soundsList.at(j).toMap();
-                                if (soundmap.contains("original_filename")) {
-                                    QListWidgetItem *item = new   QListWidgetItem(soundmap.value("original_filename").toString(), search_results);
-                                    item->setData(imageRole, soundmap.value("waveform_m").toString());
-                                    item->setData(infoUrl, soundmap.value("url").toString());
-                                    item->setData(infoData, soundmap.value("ref").toString() + "?api_key=a1772c8236e945a4bee30a64058dabf8");
-                                    item->setData(durationRole, soundmap.value("duration").toDouble());
-                                    item->setData(idRole, soundmap.value("id").toInt());
-                                    item->setData(previewRole, soundmap.value("preview-hq-mp3").toString());
-                                    item->setData(downloadRole, soundmap.value("serve").toString() + "?api_key=a1772c8236e945a4bee30a64058dabf8");
-                                    QVariant authorInfo = soundmap.value("user");
-                                    if (authorInfo.canConvert(QVariant::Map)) {
-                                        QMap <QString, QVariant> authorMap = authorInfo.toMap();
-                                        if (authorMap.contains("username")) {
-                                            item->setData(authorRole, authorMap.value("username").toString());
-                                            item->setData(authorUrl, authorMap.value("url").toString());
-                                        }
+    QJson::Parser parser;
+    bool ok;
+    //kDebug()<<"// GOT RESULT: "<<m_result;
+    QVariant data = parser.parse(storedQueryJob->data(), &ok);
+    QVariant sounds;
+    if (data.canConvert(QVariant::Map)) {
+        QMap <QString, QVariant> map = data.toMap();
+        QMap<QString, QVariant>::const_iterator i = map.constBegin();
+        while (i != map.constEnd()) {
+            if (i.key() == "num_results") emit searchInfo(i18np("Found %1 result", "Found %1 results", i.value().toInt()));
+            else if (i.key() == "num_pages") {
+                emit maxPages(i.value().toInt());
+            }
+            else if (i.key() == "sounds") {
+                sounds = i.value();
+                if (sounds.canConvert(QVariant::List)) {
+                    QList <QVariant> soundsList = sounds.toList();
+                    for (int j = 0; j < soundsList.count(); j++) {
+                        if (soundsList.at(j).canConvert(QVariant::Map)) {
+                            QMap <QString, QVariant> soundmap = soundsList.at(j).toMap();
+                            if (soundmap.contains("original_filename")) {
+                                QListWidgetItem *item = new   QListWidgetItem(soundmap.value("original_filename").toString(), m_listWidget);
+                                item->setData(imageRole, soundmap.value("waveform_m").toString());
+                                item->setData(infoUrl, soundmap.value("url").toString());
+                                item->setData(infoData, soundmap.value("ref").toString() + "?api_key=a1772c8236e945a4bee30a64058dabf8");
+                                item->setData(durationRole, soundmap.value("duration").toDouble());
+                                item->setData(idRole, soundmap.value("id").toInt());
+                                item->setData(previewRole, soundmap.value("preview-hq-mp3").toString());
+                                item->setData(downloadRole, soundmap.value("serve").toString() + "?api_key=a1772c8236e945a4bee30a64058dabf8");
+                                QVariant authorInfo = soundmap.value("user");
+                                if (authorInfo.canConvert(QVariant::Map)) {
+                                    QMap <QString, QVariant> authorMap = authorInfo.toMap();
+                                    if (authorMap.contains("username")) {
+                                        item->setData(authorRole, authorMap.value("username").toString());
+                                        item->setData(authorUrl, authorMap.value("url").toString());
                                     }
                                 }
                             }
                         }
                     }
                 }
-                ++i;
             }
+            ++i;
         }
-#endif  
     }
-    else if (m_service == OPENCLIPART) {
-        QDomDocument doc;
-        doc.setContent(storedQueryJob->data());
-        QDomNodeList items = doc.documentElement().elementsByTagName("item");
-        for (int i = 0; i < items.count(); i++) {
-            QDomElement currentClip = items.at(i).toElement();
-            QDomElement title = currentClip.firstChildElement("title");
-            QListWidgetItem *item = new QListWidgetItem(title.firstChild().nodeValue(), search_results);
-            QDomElement thumb = currentClip.firstChildElement("media:thumbnail");
-            item->setData(imageRole, thumb.attribute("url"));
-            QDomElement enclosure = currentClip.firstChildElement("enclosure");
-            item->setData(downloadRole, enclosure.attribute("url"));
-            QDomElement link = currentClip.firstChildElement("link");
-            item->setData(infoUrl, link.firstChild().nodeValue());
-            QDomElement license = currentClip.firstChildElement("cc:license");
-            item->setData(licenseRole, license.firstChild().nodeValue());
-            QDomElement desc = currentClip.firstChildElement("description");
-            item->setData(descriptionRole, desc.firstChild().nodeValue());
-            QDomElement author = currentClip.firstChildElement("dc:creator");
-            item->setData(authorRole, author.firstChild().nodeValue());
-            item->setData(authorUrl, QString("http://openclipart.org/user-detail/") + author.firstChild().nodeValue());
-        }
-    }
-    search_results->blockSignals(false);
-    search_results->setCurrentRow(0);
+#endif  
+    m_listWidget->blockSignals(false);
+    m_listWidget->setCurrentRow(0);
 }
+    
 
-void FreeSound::slotUpdateCurrentSound()
+OnlineItemInfo FreeSound::displayItemDetails(QListWidgetItem *item)
 {
-    if (!sound_autoplay->isChecked()) slotForcePlaySound(false);
-    m_currentPreview.clear();
-    m_currentUrl.clear();
-    info_widget->clear();
-    item_description->clear();
-    item_license->clear();
-    QListWidgetItem *item = search_results->currentItem();
+    OnlineItemInfo info;
+    m_metaInfo.clear();
     if (!item) {
-        sound_box->setEnabled(false);
-        return;
-    }
-    m_currentPreview = item->data(previewRole).toString();
-    m_currentUrl = item->data(downloadRole).toString();
-    m_currentId = item->data(idRole).toInt();
-    if (sound_autoplay->isChecked()) slotForcePlaySound(true);
-    button_preview->setEnabled(!m_currentPreview.isEmpty());
-    sound_box->setEnabled(true);
-    sound_name->setText(item->text());
-    sound_name->setUrl(item->data(infoUrl).toString());
-    sound_author->setText(item->data(authorRole).toString());
-    sound_author->setUrl(item->data(authorUrl).toString());
-    if (!item->data(durationRole).isNull()) {
-        new QTreeWidgetItem(info_widget, QStringList() << i18n("Duration") << QString::number(item->data(durationRole).toDouble()));
-    }
-    if (!item->data(licenseRole).isNull()) {
-        parseLicense(item->data(licenseRole).toString());
-    }
-    if (!item->data(descriptionRole).isNull()) {
-        item_description->setHtml(item->data(descriptionRole).toString());
-    }
-    QString extraInfo = item->data(infoData).toString();
-    if (!extraInfo.isEmpty()) {
-        KJob* resolveJob = KIO::storedGet( KUrl(extraInfo), KIO::NoReload, KIO::HideProgressInfo );
+        return info;
+    }
+    info.itemPreview = item->data(previewRole).toString();
+    info.itemDownload = item->data(downloadRole).toString();
+    info.itemId = item->data(idRole).toInt();
+    info.itemName = item->text();
+    info.infoUrl = item->data(infoUrl).toString();
+    info.author = item->data(authorRole).toString();
+    info.authorUrl = item->data(authorUrl).toString();
+    m_metaInfo.insert(i18n("Duration"), item->data(durationRole).toString());
+    info.license = item->data(licenseRole).toString();
+    info.description = item->data(descriptionRole).toString();
+    
+    QString extraInfoUrl = item->data(infoData).toString();
+    if (!extraInfoUrl.isEmpty()) {
+        KJob* resolveJob = KIO::storedGet( KUrl(extraInfoUrl), KIO::NoReload, KIO::HideProgressInfo );
         connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotParseResults( KJob* ) ) );
     }
-    else info_widget->resizeColumnToContents(0);
-
-    KUrl img(item->data(imageRole).toString());
-    if (img.isEmpty()) return;
-    if (KIO::NetAccess::exists(img, KIO::NetAccess::SourceSide, this)) {
-        QString tmpFile;
-        if (KIO::NetAccess::download(img, tmpFile, this)) {
-            QPixmap pix(tmpFile);
-            int newHeight = pix.height() * sound_image->width() / pix.width();
-            if (newHeight > 200) {
-                sound_image->setScaledContents(false);
-                //sound_image->setFixedHeight(sound_image->width());
-            }
-            else {
-                sound_image->setScaledContents(true);
-                sound_image->setFixedHeight(newHeight);
-            }
-            sound_image->setPixmap(pix);
-            KIO::NetAccess::removeTempFile(tmpFile);
-        }
-    }
+    info.imagePreview = item->data(imageRole).toString();
+    return info;
 }
 
 
@@ -283,155 +171,56 @@ void FreeSound::slotParseResults(KJob* job)
     QVariant data = parser.parse(storedQueryJob->data(), &ok);
     if (data.canConvert(QVariant::Map)) {
         QMap <QString, QVariant> infos = data.toMap();
-        if (m_currentId != infos.value("id").toInt()) return;
+        //if (m_currentId != infos.value("id").toInt()) return;
         if (infos.contains("samplerate"))
-            new QTreeWidgetItem(info_widget, QStringList() << i18n("Samplerate") << QString::number(infos.value("samplerate").toDouble()));
+            m_metaInfo.insert(i18n("Samplerate"), QString::number(infos.value("samplerate").toDouble()));
         if (infos.contains("channels"))
-            new QTreeWidgetItem(info_widget, QStringList() << i18n("Channels") << QString::number(infos.value("channels").toInt()));
+            m_metaInfo.insert(i18n("Channels"), QString::number(infos.value("channels").toInt()));
         if (infos.contains("filesize")) {
             KIO::filesize_t fSize = infos.value("filesize").toDouble();
-            new QTreeWidgetItem(info_widget, QStringList() << i18n("File size") << KIO::convertSize(fSize));
+            m_metaInfo.insert(i18n("File size"), KIO::convertSize(fSize));
         }
         if (infos.contains("description")) {
-            item_description->setHtml(infos.value("description").toString());
+            m_metaInfo.insert("description", infos.value("description").toString());
         }
         if (infos.contains("license")) {
-            parseLicense(infos.value("license").toString());
+            m_metaInfo.insert("license", infos.value("license").toString());
         }
     }
-    info_widget->resizeColumnToContents(0);
-    info_widget->resizeColumnToContents(1);
+    emit gotMetaInfo(m_metaInfo);
 #endif    
 }
 
 
-void FreeSound::slotPlaySound()
-{
-    if (m_currentPreview.isEmpty()) return;
+bool FreeSound::startItemPreview(QListWidgetItem *item)
+{    
+    if (!item) return false;
+    QString url = item->data(previewRole).toString();
+    if (url.isEmpty()) return false;
     if (m_previewProcess && m_previewProcess->state() != QProcess::NotRunning) {
         m_previewProcess->close();
-        return;
     }
-    m_previewProcess->start("ffplay", QStringList() << m_currentPreview << "-nodisp");
+    m_previewProcess->start("ffplay", QStringList() << url << "-nodisp");
+    return true;
 }
 
 
-void FreeSound::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 FreeSound::slotPreviewStatusChanged(QProcess::ProcessState state)
-{
-    if (state == QProcess::NotRunning)
-        button_preview->setText(i18n("Preview"));
-    else 
-        button_preview->setText(i18n("Stop"));
-}
-
-void FreeSound::slotSaveSound()
-{
-    if (m_currentUrl.isEmpty()) return;
-    QString path = m_folder;
-    if (!path.endsWith('/')) path.append('/');
-    path.append(sound_name->text());
-    QString ext;
-    if (m_service == FREESOUND) {
-        ext = "*." + sound_name->text().section('.', -1);
-    }
-    else if (m_service == OPENCLIPART) {
-        path.append("." + m_currentUrl.section('.', -1));
-        ext = "*." + m_currentUrl.section('.', -1);
-    }
-    QString saveUrl = KFileDialog::getSaveFileName(KUrl(path), ext);
-    if (saveUrl.isEmpty()) return;
-    if (KIO::NetAccess::download(KUrl(m_currentUrl), saveUrl, this)) {
-        const KUrl filePath = KUrl(saveUrl);
-#ifdef USE_NEPOMUK
-        Nepomuk::Resource res( filePath );
-        res.setProperty( Nepomuk::Vocabulary::NIE::license(), (Nepomuk::Variant) item_license->text() );
-        res.setProperty( Nepomuk::Vocabulary::NIE::licenseType(), (Nepomuk::Variant) item_license->url() );
-        res.setProperty( Nepomuk::Vocabulary::NDO::copiedFrom(), sound_name->url() );
-        //res.setDescription(item_description->toPlainText());
-        //res.setProperty( Soprano::Vocabulary::NAO::description(), 
-#endif
-        emit addClip(KUrl(saveUrl), QString());//, sound_name->url());
-    }
-}
-
-void FreeSound::slotOpenUrl(const QString &url)
-{
-    new KRun(KUrl(url), this);
-}
-
-void FreeSound::slotChangeService()
-{
-    m_service = (SERVICETYPE) service_list->itemData(service_list->currentIndex()).toInt();
-    if (m_service == FREESOUND) {
-        button_preview->setVisible(true);
-        search_info->setVisible(true);
-        sound_autoplay->setVisible(true);
-        info_widget->setVisible(true);
-    }
-    else if (m_service == OPENCLIPART) {
-        button_preview->setVisible(false);
-        search_info->setVisible(false);
-        sound_autoplay->setVisible(false);
-        info_widget->setVisible(false);
+void FreeSound::stopItemPreview(QListWidgetItem *item)
+{    
+    if (m_previewProcess && m_previewProcess->state() != QProcess::NotRunning) {
+        m_previewProcess->close();
     }
-    if (!search_text->text().isEmpty()) slotStartSearch();
 }
 
-void FreeSound::slotOnline()
+QString FreeSound::getExtension(QListWidgetItem *item)
 {
-    button_search->setEnabled(true);
-    search_info->setText(QString());
+    if (!item) return QString();
+    return QString("*.") + item->text().section('.', -1);
 }
 
-void FreeSound::slotOffline()
-{
-    button_search->setEnabled(false);
-    search_info->setText(i18n("You need to be online\n for searching"));
-}
 
-void FreeSound::slotNextPage()
+QString FreeSound::getDefaultDownloadName(QListWidgetItem *item)
 {
-    int ix = page_number->value();
-    if (search_results->count() > 0) page_number->setValue(ix + 1);
+    if (!item) return QString();
+    return item->text();
 }
-
-void FreeSound::slotPreviousPage()
-{
-    int ix = page_number->value();
-    if (ix > 1) page_number->setValue(ix - 1);
-}
-
-void FreeSound::parseLicense(const QString &licenseUrl)
-{
-    QString licenseName;
-    if (licenseUrl.contains("/sampling+/"))
-        licenseName = "Sampling+";
-    else if (licenseUrl.contains("/by/"))
-        licenseName = "Attribution";
-    else if (licenseUrl.contains("/by-nd/"))
-        licenseName = "Attribution-NoDerivs";
-    else if (licenseUrl.contains("/by-nc-sa/"))
-        licenseName = "Attribution-NonCommercial-ShareAlike";
-    else if (licenseUrl.contains("/by-sa/"))
-        licenseName = "Attribution-ShareAlike";
-    else if (licenseUrl.contains("/by-nc/"))
-        licenseName = "Attribution-NonCommercial";
-    else if (licenseUrl.contains("/by-nc-nd/"))
-        licenseName = "Attribution-NonCommercial-NoDerivs";
-    else if (licenseUrl.contains("/publicdomain/zero/"))
-        licenseName = "Creative Commons 0";
-    else if (licenseUrl.endsWith("/publicdomain"))
-        licenseName = "Public Domain";
-    item_license->setText(i18n("License: %1", licenseName));
-    item_license->setUrl(licenseUrl);
-}
-
index 149acab4d70c2db9682755fd87ffd5e6152840a7..88251a0ec3ba28f2168f36d8875dd23ef0b03e8c 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
- *   Copyright (C) 2011 by Marco Gittler (marco@gitma.de)                  *
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
 #define FREESOUND_H
 
 
-#include "ui_freesound_ui.h"
+#include "abstractservice.h"
 
-#include <QDialog>
 #include <QProcess>
 #include <kio/jobclasses.h>
 
-enum SERVICETYPE { FREESOUND = 0, OPENCLIPART = 1 };
 
-class FreeSound : public QDialog, public Ui::FreeSound_UI
+class FreeSound : public AbstractService
 {
     Q_OBJECT
 
 public:
-    FreeSound(const QString & folder, QWidget * parent = 0);
+    FreeSound(QListWidget *listWidget, QObject * parent = 0);
     ~FreeSound();
+    virtual QString getExtension(QListWidgetItem *item);
+    virtual QString getDefaultDownloadName(QListWidgetItem *item);
+
 
+public slots:
+    virtual void slotStartSearch(const QString searchText, int page = 0);
+    virtual OnlineItemInfo displayItemDetails(QListWidgetItem *item);
+    virtual bool startItemPreview(QListWidgetItem *item);
+    virtual void stopItemPreview(QListWidgetItem *item);    
 
 private slots:
-    void slotStartSearch(int page = 0);
     void slotShowResults(KJob* job);
     void slotParseResults(KJob* job);
-    void slotUpdateCurrentSound();
-    void slotPlaySound();
-    void slotForcePlaySound(bool play);
-    void slotPreviewStatusChanged(QProcess::ProcessState state);
-    void slotSaveSound();
-    void slotOpenUrl(const QString &url);
-    void slotChangeService();
-    void slotOnline();
-    void slotOffline();
-    void slotNextPage();
-    void slotPreviousPage();
-
+    
 private:
-    QString m_folder;
-    QString m_currentPreview;
-    QString m_currentUrl;
-    int m_currentId;
+    QMap <QString, QString> m_metaInfo;
     QProcess *m_previewProcess;
-    SERVICETYPE m_service;
-    void parseLicense(const QString &);
-   
+
 signals:
     void addClip(KUrl, const QString &);
 };
diff --git a/src/utils/openclipart.cpp b/src/utils/openclipart.cpp
new file mode 100644 (file)
index 0000000..2340d99
--- /dev/null
@@ -0,0 +1,123 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#include "openclipart.h"
+
+#include <QListWidget>
+#include <QDomDocument>
+
+#include <KDebug>
+#include <kio/job.h>
+#include <KIO/NetAccess>
+
+
+OpenClipArt::OpenClipArt(QListWidget *listWidget, QObject *parent) :
+        AbstractService(listWidget, parent)
+{
+    serviceType = OPENCLIPART;
+}
+
+OpenClipArt::~OpenClipArt()
+{
+}
+
+void OpenClipArt::slotStartSearch(const QString searchText, int page)
+{
+    m_listWidget->clear();
+    QString uri = "http://openclipart.org/api/search/?query=";
+    uri.append(searchText);
+    if (page > 1) uri.append("&page=" + QString::number(page));
+        
+    KJob* resolveJob = KIO::storedGet( KUrl(uri), KIO::NoReload, KIO::HideProgressInfo );
+    connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotShowResults( KJob* ) ) );
+}
+
+
+void OpenClipArt::slotShowResults(KJob* job)
+{
+    if (job->error() != 0 ) return;
+    m_listWidget->blockSignals(true);
+    
+    
+    KIO::StoredTransferJob* storedQueryJob = static_cast<KIO::StoredTransferJob*>( job );
+    
+    QDomDocument doc;
+        doc.setContent(storedQueryJob->data());
+        QDomNodeList items = doc.documentElement().elementsByTagName("item");
+        for (int i = 0; i < items.count(); i++) {
+            QDomElement currentClip = items.at(i).toElement();
+            QDomElement title = currentClip.firstChildElement("title");
+            QListWidgetItem *item = new QListWidgetItem(title.firstChild().nodeValue(), m_listWidget);
+            QDomElement thumb = currentClip.firstChildElement("media:thumbnail");
+            item->setData(imageRole, thumb.attribute("url"));
+            QDomElement enclosure = currentClip.firstChildElement("enclosure");
+            item->setData(downloadRole, enclosure.attribute("url"));
+            QDomElement link = currentClip.firstChildElement("link");
+            item->setData(infoUrl, link.firstChild().nodeValue());
+            QDomElement license = currentClip.firstChildElement("cc:license");
+            item->setData(licenseRole, license.firstChild().nodeValue());
+            QDomElement desc = currentClip.firstChildElement("description");
+            item->setData(descriptionRole, desc.firstChild().nodeValue());
+            QDomElement author = currentClip.firstChildElement("dc:creator");
+            item->setData(authorRole, author.firstChild().nodeValue());
+            item->setData(authorUrl, QString("http://openclipart.org/user-detail/") + author.firstChild().nodeValue());
+        }
+            
+    m_listWidget->blockSignals(false);
+    m_listWidget->setCurrentRow(0);
+}
+    
+
+OnlineItemInfo OpenClipArt::displayItemDetails(QListWidgetItem *item)
+{
+    OnlineItemInfo info;
+    if (!item) {
+        return info;
+    }
+    info.itemPreview = item->data(previewRole).toString();
+    info.itemDownload = item->data(downloadRole).toString();
+    info.itemId = item->data(idRole).toInt();
+    info.itemName = item->text();
+    info.infoUrl = item->data(infoUrl).toString();
+    info.author = item->data(authorRole).toString();
+    info.authorUrl = item->data(authorUrl).toString();
+    info.license = item->data(licenseRole).toString();
+    info.description = item->data(descriptionRole).toString();
+    info.imagePreview = item->data(imageRole).toString();
+    return info;
+}
+
+QString OpenClipArt::getExtension(QListWidgetItem *item)
+{
+    if (!item) return QString();
+    QString url = item->data(downloadRole).toString();
+    return QString("*.") + url.section('.', -1);
+}
+
+QString OpenClipArt::getDefaultDownloadName(QListWidgetItem *item)
+{
+    if (!item) return QString();
+    QString url = item->data(downloadRole).toString();
+    QString path = item->text();
+    path.append("." + url.section('.', -1));
+    return path;
+}
+
diff --git a/src/utils/openclipart.h b/src/utils/openclipart.h
new file mode 100644 (file)
index 0000000..66f2556
--- /dev/null
@@ -0,0 +1,55 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef OPENCLIPART_H
+#define OPENCLIPART_H
+
+
+#include "abstractservice.h"
+
+#include <QProcess>
+#include <kio/jobclasses.h>
+
+
+class OpenClipArt : public AbstractService
+{
+    Q_OBJECT
+
+public:
+    OpenClipArt(QListWidget *listWidget, QObject * parent = 0);
+    ~OpenClipArt();
+    virtual QString getExtension(QListWidgetItem *item);
+    virtual QString getDefaultDownloadName(QListWidgetItem *item);
+
+
+public slots:
+    virtual void slotStartSearch(const QString searchText, int page = 0);
+    virtual OnlineItemInfo displayItemDetails(QListWidgetItem *item);
+
+private slots:
+    void slotShowResults(KJob* job);
+
+};
+
+
+#endif
+
diff --git a/src/utils/resourcewidget.cpp b/src/utils/resourcewidget.cpp
new file mode 100644 (file)
index 0000000..e2b4fa2
--- /dev/null
@@ -0,0 +1,313 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#include "resourcewidget.h"
+#include "freesound.h"
+#include "openclipart.h"
+
+#include <QPushButton>
+#include <QSpinBox>
+#include <QListWidget>
+#include <QDomDocument>
+
+#include <KDebug>
+#include "kdenlivesettings.h"
+#include <KGlobalSettings>
+#include <KMessageBox>
+#include <KFileDialog>
+#include <kio/job.h>
+#include <KIO/NetAccess>
+#include <Solid/Networking>
+#include <KRun>
+
+#ifdef USE_NEPOMUK
+#include <Nepomuk/Variant>
+#include <Nepomuk/Resource>
+#include <Nepomuk/ResourceManager>
+#include <Soprano/Vocabulary/NAO>
+#include <Nepomuk/Vocabulary/NIE>
+#include <Nepomuk/Vocabulary/NDO>
+#endif
+
+
+ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
+        QDialog(parent),
+        m_folder(folder),
+        m_currentService(NULL)
+{
+    setFont(KGlobalSettings::toolBarFont());
+    setupUi(this);
+    setAttribute(Qt::WA_DeleteOnClose);
+#ifdef USE_QJSON
+    service_list->addItem(i18n("Freesound Audio Library"), FREESOUND);
+#endif
+    service_list->addItem(i18n("Open Clip Art Graphic Library"), OPENCLIPART);
+    setWindowTitle(i18n("Search Online Resources"));
+    info_widget->setStyleSheet(QString("QTreeWidget { background-color: transparent;}"));
+    item_description->setStyleSheet(QString("KTextBrowser { background-color: transparent;}"));
+    connect(button_search, SIGNAL(clicked()), this, SLOT(slotStartSearch()));
+    connect(search_results, SIGNAL(currentRowChanged(int)), this, SLOT(slotUpdateCurrentSound()));
+    connect(button_preview, SIGNAL(clicked()), this, SLOT(slotPlaySound()));
+    connect(button_import, SIGNAL(clicked()), this, SLOT(slotSaveSound()));
+    connect(sound_author, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
+    connect(item_license, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
+    connect(sound_name, SIGNAL(leftClickedUrl(const QString &)), this, SLOT(slotOpenUrl(const QString &)));
+    connect(service_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeService()));
+    sound_image->setFixedWidth(180);
+    if (Solid::Networking::status() == Solid::Networking::Unconnected) {
+        slotOffline();
+    }
+    connect(Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, SLOT(slotOnline()));
+    connect(Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), this, SLOT(slotOffline()));
+    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)));
+    sound_box->setEnabled(false);
+    search_text->setFocus();
+    Nepomuk::ResourceManager::instance()->init();
+    slotChangeService();
+}
+
+ResourceWidget::~ResourceWidget()
+{
+    if (m_currentService) delete m_currentService;
+}
+
+void ResourceWidget::slotStartSearch(int page)
+{
+    /*m_currentPreview.clear();
+    m_currentUrl.clear();*/
+    page_number->blockSignals(true);
+    page_number->setValue(page);
+    page_number->blockSignals(false);
+    m_currentService->slotStartSearch(search_text->text(), page);
+    /*QString uri;
+    if (m_service == FREESOUND) {
+        uri = "http://www.freesound.org/api/sounds/search/?q=";
+        uri.append(search_text->text());
+        if (page > 1) uri.append("&p=" + QString::number(page));
+        uri.append("&api_key=a1772c8236e945a4bee30a64058dabf8");
+    }
+    else if (m_service == OPENCLIPART) {
+        uri = "http://openclipart.org/api/search/?query=";
+        uri.append(search_text->text());
+        if (page > 1) uri.append("&page=" + QString::number(page));
+    }*/
+}
+
+void ResourceWidget::slotUpdateCurrentSound()
+{
+    if (!sound_autoplay->isChecked()) m_currentService->stopItemPreview(NULL);
+    info_widget->clear();
+    item_description->clear();
+    item_license->clear();
+    QListWidgetItem *item = search_results->currentItem();
+    if (!item) {
+        sound_box->setEnabled(false);
+        return;
+    }
+    m_currentInfo = m_currentService->displayItemDetails(item);
+    /*m_currentPreview = item->data(previewRole).toString();
+    m_currentUrl = item->data(downloadRole).toString();
+    m_currentId = item->data(idRole).toInt();*/
+    
+    if (sound_autoplay->isChecked()) m_currentService->startItemPreview(item);
+    sound_box->setEnabled(true);
+    sound_name->setText(item->text());
+    sound_name->setUrl(m_currentInfo.infoUrl);
+    sound_author->setText(m_currentInfo.author);
+    sound_author->setUrl(m_currentInfo.authorUrl);
+    item_description->setHtml(m_currentInfo.description);
+    
+
+    KUrl img(m_currentInfo.imagePreview);
+    if (img.isEmpty()) return;
+    if (KIO::NetAccess::exists(img, KIO::NetAccess::SourceSide, this)) {
+        QString tmpFile;
+        if (KIO::NetAccess::download(img, tmpFile, this)) {
+            QPixmap pix(tmpFile);
+            int newHeight = pix.height() * sound_image->width() / pix.width();
+            if (newHeight > 200) {
+                sound_image->setScaledContents(false);
+                //sound_image->setFixedHeight(sound_image->width());
+            }
+            else {
+                sound_image->setScaledContents(true);
+                sound_image->setFixedHeight(newHeight);
+            }
+            sound_image->setPixmap(pix);
+            KIO::NetAccess::removeTempFile(tmpFile);
+        }
+    }
+}
+
+
+void ResourceWidget::slotDisplayMetaInfo(QMap <QString, QString> metaInfo)
+{
+    if (metaInfo.contains("description")) {
+        item_description->setHtml(metaInfo.value("description"));
+        metaInfo.remove("description");
+    }
+    if (metaInfo.contains("license")) {
+        parseLicense(metaInfo.value("license"));
+        metaInfo.remove("license");
+    }
+    QMap<QString, QString>::const_iterator i = metaInfo.constBegin();
+    while (i != metaInfo.constEnd()) {
+        new QTreeWidgetItem(info_widget, QStringList() << i.key() << i.value());
+        ++i;
+    }
+    info_widget->resizeColumnToContents(0);
+    info_widget->resizeColumnToContents(1);
+}
+
+
+void ResourceWidget::slotPlaySound()
+{
+    if (!m_currentService) return;
+    bool started = m_currentService->startItemPreview(search_results->currentItem());
+    if (started) button_preview->setText(i18n("Preview"));
+    else button_preview->setText(i18n("Stop"));
+}
+
+
+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::slotSaveSound()
+{
+    //if (m_currentUrl.isEmpty()) return;
+    QListWidgetItem *item = search_results->currentItem();
+    if (!item) return;
+    QString path = m_folder;
+    if (!path.endsWith('/')) path.append('/');
+    path.append(m_currentService->getDefaultDownloadName(item));
+    QString 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);
+#ifdef USE_NEPOMUK
+        Nepomuk::Resource res( filePath );
+        res.setProperty( Nepomuk::Vocabulary::NIE::license(), (Nepomuk::Variant) item_license->text() );
+        res.setProperty( Nepomuk::Vocabulary::NIE::licenseType(), (Nepomuk::Variant) item_license->url() );
+        res.setProperty( Nepomuk::Vocabulary::NDO::copiedFrom(), sound_name->url() );
+        //res.setDescription(item_description->toPlainText());
+        //res.setProperty( Soprano::Vocabulary::NAO::description(), 
+#endif
+        emit addClip(KUrl(saveUrl), QString());//, sound_name->url());
+    }
+}
+
+void ResourceWidget::slotOpenUrl(const QString &url)
+{
+    new KRun(KUrl(url), this);
+}
+
+void ResourceWidget::slotChangeService()
+{
+    if (m_currentService) {
+        delete m_currentService;
+        m_currentService = NULL;
+    }
+    SERVICETYPE service = (SERVICETYPE) service_list->itemData(service_list->currentIndex()).toInt();
+    if (service == FREESOUND) {
+        m_currentService = new FreeSound(search_results);
+    }
+    else if (service == OPENCLIPART) {
+        m_currentService = new OpenClipArt(search_results);
+    }
+    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(searchInfo(QString)), search_info, SLOT(setText(QString)));
+    
+    button_preview->setVisible(m_currentService->hasPreview);
+    sound_autoplay->setVisible(m_currentService->hasPreview);
+    search_info->setText(QString());
+    info_widget->setVisible(m_currentService->hasMetadata);
+    if (!search_text->text().isEmpty()) slotStartSearch();
+}
+
+void ResourceWidget::slotOnline()
+{
+    button_search->setEnabled(true);
+    search_info->setText(QString());
+}
+
+void ResourceWidget::slotOffline()
+{
+    button_search->setEnabled(false);
+    search_info->setText(i18n("You need to be online\n for searching"));
+}
+
+void ResourceWidget::slotNextPage()
+{
+    int ix = page_number->value();
+    if (search_results->count() > 0) page_number->setValue(ix + 1);
+}
+
+void ResourceWidget::slotPreviousPage()
+{
+    int ix = page_number->value();
+    if (ix > 1) page_number->setValue(ix - 1);
+}
+
+void ResourceWidget::parseLicense(const QString &licenseUrl)
+{
+    QString licenseName;
+    if (licenseUrl.contains("/sampling+/"))
+        licenseName = "Sampling+";
+    else if (licenseUrl.contains("/by/"))
+        licenseName = "Attribution";
+    else if (licenseUrl.contains("/by-nd/"))
+        licenseName = "Attribution-NoDerivs";
+    else if (licenseUrl.contains("/by-nc-sa/"))
+        licenseName = "Attribution-NonCommercial-ShareAlike";
+    else if (licenseUrl.contains("/by-sa/"))
+        licenseName = "Attribution-ShareAlike";
+    else if (licenseUrl.contains("/by-nc/"))
+        licenseName = "Attribution-NonCommercial";
+    else if (licenseUrl.contains("/by-nc-nd/"))
+        licenseName = "Attribution-NonCommercial-NoDerivs";
+    else if (licenseUrl.contains("/publicdomain/zero/"))
+        licenseName = "Creative Commons 0";
+    else if (licenseUrl.endsWith("/publicdomain"))
+        licenseName = "Public Domain";
+    item_license->setText(i18n("License: %1", licenseName));
+    item_license->setUrl(licenseUrl);
+}
+
diff --git a/src/utils/resourcewidget.h b/src/utils/resourcewidget.h
new file mode 100644 (file)
index 0000000..001b01f
--- /dev/null
@@ -0,0 +1,70 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef RESOURCEWIDGET_H
+#define RESOURCEWIDGET_H
+
+
+#include "ui_freesound_ui.h"
+#include "abstractservice.h"
+
+#include <QDialog>
+#include <QProcess>
+#include <kio/jobclasses.h>
+
+
+class ResourceWidget : public QDialog, public Ui::FreeSound_UI
+{
+    Q_OBJECT
+
+public:
+    ResourceWidget(const QString & folder, QWidget * parent = 0);
+    ~ResourceWidget();
+
+
+private slots:
+    void slotStartSearch(int page = 0);
+    void slotUpdateCurrentSound();
+    void slotPlaySound();
+    void slotForcePlaySound(bool play);
+    void slotPreviewStatusChanged(QProcess::ProcessState state);
+    void slotDisplayMetaInfo(QMap <QString, QString> metaInfo);
+    void slotSaveSound();
+    void slotOpenUrl(const QString &url);
+    void slotChangeService();
+    void slotOnline();
+    void slotOffline();
+    void slotNextPage();
+    void slotPreviousPage();
+
+private:
+    QString m_folder;
+    AbstractService *m_currentService;
+    void parseLicense(const QString &);
+    OnlineItemInfo m_currentInfo;
+   
+signals:
+    void addClip(KUrl, const QString &);
+};
+
+
+#endif
+
index 095e94abe6a7230a93d4a4bc05d223200bb6faaf..5c3430203b62fc135f2dafe0c623dbfa358f5e27 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>396</width>
-    <height>315</height>
+    <width>424</width>
+    <height>391</height>
    </rect>
   </property>
   <property name="windowTitle">
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <property name="prefix">
-      <string>page </string>
-     </property>
      <property name="minimum">
       <number>1</number>
      </property>