]> git.sesse.net Git - kdenlive/commitdiff
Online resources: display description and license
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 31 Dec 2011 04:27:56 +0000 (05:27 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 31 Dec 2011 04:27:56 +0000 (05:27 +0100)
src/archivewidget.cpp
src/utils/freesound.cpp
src/utils/freesound.h
src/widgets/freesound_ui.ui

index db2b9e8db2c6d033c1db1f17a42db70beb343ad0..cee0ab5468062fe8dba11887fd2141fb7486797e 100644 (file)
@@ -338,7 +338,7 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, QStringList items
 void ArchiveWidget::slotCheckSpace()
 {
     KDiskFreeSpaceInfo inf = KDiskFreeSpaceInfo::freeSpaceInfo( archive_url->url().path());
-    KIO::filesize_t freeSize = inf.available();;
+    KIO::filesize_t freeSize = inf.available();
     if (freeSize > m_requestedSize) {
         // everything is ok
         buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
index bf313d49d35c5ca5e87eb14237a0fc719f4fc676..d1d233f91ac3aa04aa2bd62bcb6b445675b6b6cb 100644 (file)
@@ -48,7 +48,10 @@ 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),
@@ -63,11 +66,14 @@ FreeSound::FreeSound(const QString & folder, QWidget * parent) :
 #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)));
@@ -82,6 +88,7 @@ FreeSound::FreeSound(const QString & folder, QWidget * parent) :
     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();
 }
 
 FreeSound::~FreeSound()
@@ -91,7 +98,6 @@ FreeSound::~FreeSound()
 
 void FreeSound::slotStartSearch(int page)
 {
-    m_result.clear();
     m_currentPreview.clear();
     m_currentUrl.clear();
     page_number->blockSignals(true);
@@ -109,29 +115,27 @@ void FreeSound::slotStartSearch(int page)
         uri.append(search_text->text());
         if (page > 1) uri.append("&page=" + QString::number(page));
     }
-    KIO::TransferJob *job = KIO::get(KUrl(uri));
-    connect (job, SIGNAL(  data(KIO::Job *, const QByteArray & )), this, SLOT(slotDataIsHere(KIO::Job *,const QByteArray &)));
-    connect(job, SIGNAL(result(KJob*)), this, SLOT(slotShowResults()));
+    
+    KJob* resolveJob = KIO::storedGet( KUrl(uri), KIO::NoReload, KIO::HideProgressInfo );
+    connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotShowResults( KJob* ) ) );
 }
 
-void FreeSound::slotDataIsHere(KIO::Job *,const QByteArray & data )
-{
-  m_result.append(data);
-}
 
-void FreeSound::slotShowResults()
+void FreeSound::slotShowResults(KJob* job)
 {
+    if (job->error() != 0 ) return;
     search_results->blockSignals(true);
     search_results->clear();
+    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;
-        m_data = parser.parse(m_result, &ok);
+        QVariant data = parser.parse(storedQueryJob->data(), &ok);
         QVariant sounds;
-        if (m_data.canConvert(QVariant::Map)) {
-            QMap <QString, QVariant> map = m_data.toMap();
+        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()));
@@ -149,7 +153,9 @@ void FreeSound::slotShowResults()
                                     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");
@@ -172,7 +178,7 @@ void FreeSound::slotShowResults()
     }
     else if (m_service == OPENCLIPART) {
         QDomDocument doc;
-        doc.setContent(m_result);
+        doc.setContent(storedQueryJob->data());
         QDomNodeList items = doc.documentElement().elementsByTagName("item");
         for (int i = 0; i < items.count(); i++) {
             QDomElement currentClip = items.at(i).toElement();
@@ -184,6 +190,10 @@ void FreeSound::slotShowResults()
             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());
@@ -198,6 +208,9 @@ void FreeSound::slotUpdateCurrentSound()
     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();
     if (!item) {
         sound_box->setEnabled(false);
@@ -205,6 +218,7 @@ void FreeSound::slotUpdateCurrentSound()
     }
     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);
@@ -212,7 +226,22 @@ void FreeSound::slotUpdateCurrentSound()
     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()) sound_duration->setText(QString::number(item->data(durationRole).toDouble()));
+    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 );
+        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)) {
@@ -220,7 +249,7 @@ void FreeSound::slotUpdateCurrentSound()
         if (KIO::NetAccess::download(img, tmpFile, this)) {
             QPixmap pix(tmpFile);
             int newHeight = pix.height() * sound_image->width() / pix.width();
-            if (newHeight > 2 * sound_image->width()) {
+            if (newHeight > 200) {
                 sound_image->setScaledContents(false);
                 //sound_image->setFixedHeight(sound_image->width());
             }
@@ -234,6 +263,38 @@ void FreeSound::slotUpdateCurrentSound()
     }
 }
 
+
+void FreeSound::slotParseResults(KJob* job)
+{
+#ifdef USE_QJSON
+    KIO::StoredTransferJob* storedQueryJob = static_cast<KIO::StoredTransferJob*>( job );
+    QJson::Parser parser;
+    bool ok;
+    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 (infos.contains("samplerate"))
+            new QTreeWidgetItem(info_widget, QStringList() << 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()));
+        if (infos.contains("filesize")) {
+            KIO::filesize_t fSize = infos.value("filesize").toDouble();
+            new QTreeWidgetItem(info_widget, QStringList() << i18n("File size") << KIO::convertSize(fSize));
+        }
+        if (infos.contains("description")) {
+            item_description->setHtml(infos.value("description").toString());
+        }
+        if (infos.contains("license")) {
+            parseLicense(infos.value("license").toString());
+        }
+    }
+    info_widget->resizeColumnToContents(0);
+    info_widget->resizeColumnToContents(1);
+#endif    
+}
+
+
 void FreeSound::slotPlaySound()
 {
     if (m_currentPreview.isEmpty()) return;
@@ -293,16 +354,15 @@ void FreeSound::slotChangeService()
     m_service = (SERVICETYPE) service_list->itemData(service_list->currentIndex()).toInt();
     if (m_service == FREESOUND) {
         button_preview->setVisible(true);
-        duration_label->setVisible(true);
         search_info->setVisible(true);
         sound_autoplay->setVisible(true);
+        info_widget->setVisible(true);
     }
     else if (m_service == OPENCLIPART) {
         button_preview->setVisible(false);
-        duration_label->setVisible(false);
         search_info->setVisible(false);
         sound_autoplay->setVisible(false);
-        sound_duration->setText(QString());
+        info_widget->setVisible(false);
     }
     if (!search_text->text().isEmpty()) slotStartSearch();
 }
@@ -331,3 +391,28 @@ void FreeSound::slotPreviousPage()
     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 48fbfaed4c511d6c2b07d76ca84a587d5941479f..149acab4d70c2db9682755fd87ffd5e6152840a7 100644 (file)
@@ -42,8 +42,8 @@ public:
 
 private slots:
     void slotStartSearch(int page = 0);
-    void slotDataIsHere(KIO::Job *,const QByteArray & data );
-    void slotShowResults();
+    void slotShowResults(KJob* job);
+    void slotParseResults(KJob* job);
     void slotUpdateCurrentSound();
     void slotPlaySound();
     void slotForcePlaySound(bool play);
@@ -58,12 +58,12 @@ private slots:
 
 private:
     QString m_folder;
-    QByteArray m_result;
-    QVariant m_data;
     QString m_currentPreview;
     QString m_currentUrl;
+    int m_currentId;
     QProcess *m_previewProcess;
     SERVICETYPE m_service;
+    void parseLicense(const QString &);
    
 signals:
     void addClip(KUrl, const QString &);
index 15e5cbcfd9f02850212057a4d3e7bb948b994620..095e94abe6a7230a93d4a4bc05d223200bb6faaf 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>360</width>
-    <height>229</height>
+    <width>396</width>
+    <height>315</height>
    </rect>
   </property>
   <property name="windowTitle">
    </item>
    <item row="1" column="4" rowspan="2">
     <widget class="QGroupBox" name="sound_box">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
      <property name="title">
       <string/>
      </property>
         </property>
        </widget>
       </item>
-      <item row="6" column="0" colspan="4">
-       <widget class="QPushButton" name="button_preview">
-        <property name="text">
-         <string>Preview</string>
-        </property>
-       </widget>
-      </item>
-      <item row="7" column="1">
+      <item row="7" column="2">
        <spacer name="verticalSpacer">
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
        </spacer>
       </item>
-      <item row="9" column="0" colspan="4">
+      <item row="12" column="1" colspan="3">
        <widget class="QPushButton" name="button_import">
         <property name="text">
          <string>Import</string>
         </property>
        </widget>
       </item>
-      <item row="4" column="3">
+      <item row="4" column="0" colspan="4">
        <widget class="KUrlLabel" name="sound_author">
+        <property name="minimumSize">
+         <size>
+          <width>26</width>
+          <height>0</height>
+         </size>
+        </property>
         <property name="text">
          <string/>
         </property>
         </property>
        </widget>
       </item>
-      <item row="4" column="1">
-       <widget class="QLabel" name="sound_duration">
+      <item row="0" column="0" colspan="4">
+       <widget class="KUrlLabel" name="sound_name">
         <property name="text">
          <string/>
         </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
        </widget>
       </item>
-      <item row="4" column="0">
-       <widget class="QLabel" name="duration_label">
+      <item row="12" column="0">
+       <widget class="QPushButton" name="button_preview">
         <property name="text">
-         <string>Duration</string>
+         <string>Preview</string>
         </property>
        </widget>
       </item>
-      <item row="4" column="2">
-       <spacer name="horizontalSpacer">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
+      <item row="8" column="0" colspan="4">
+       <widget class="QTreeWidget" name="info_widget">
+        <property name="frameShape">
+         <enum>QFrame::NoFrame</enum>
         </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>40</width>
-          <height>20</height>
-         </size>
+        <property name="alternatingRowColors">
+         <bool>true</bool>
         </property>
-       </spacer>
+        <property name="selectionMode">
+         <enum>QAbstractItemView::NoSelection</enum>
+        </property>
+        <property name="rootIsDecorated">
+         <bool>false</bool>
+        </property>
+        <property name="allColumnsShowFocus">
+         <bool>true</bool>
+        </property>
+        <property name="headerHidden">
+         <bool>true</bool>
+        </property>
+        <property name="columnCount">
+         <number>2</number>
+        </property>
+        <column>
+         <property name="text">
+          <string notr="true">1</string>
+         </property>
+        </column>
+        <column>
+         <property name="text">
+          <string notr="true">2</string>
+         </property>
+        </column>
+       </widget>
       </item>
-      <item row="0" column="0" colspan="4">
-       <widget class="KUrlLabel" name="sound_name">
+      <item row="10" column="0" colspan="4">
+       <widget class="KUrlLabel" name="item_license">
         <property name="text">
          <string/>
         </property>
-        <property name="alignment">
-         <set>Qt::AlignCenter</set>
-        </property>
        </widget>
       </item>
-      <item row="8" column="0" colspan="3">
+      <item row="11" column="0">
        <widget class="QCheckBox" name="sound_autoplay">
         <property name="text">
          <string>Auto play</string>
         </property>
        </widget>
       </item>
+      <item row="9" column="0" colspan="4">
+       <widget class="KTextBrowser" name="item_description">
+        <property name="frameShape">
+         <enum>QFrame::NoFrame</enum>
+        </property>
+        <property name="openExternalLinks">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
    <item row="3" column="1" colspan="2">
     <widget class="QSpinBox" name="page_number">
      <property name="sizePolicy">
-      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+      <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
   </layout>
  </widget>
  <customwidgets>
+  <customwidget>
+   <class>KTextBrowser</class>
+   <extends>QTextBrowser</extends>
+   <header>ktextbrowser.h</header>
+  </customwidget>
   <customwidget>
    <class>KLineEdit</class>
    <extends>QLineEdit</extends>