Git commit ede6f74de910cea0264b51e7a5b16b681b0b669b by Jean-Baptiste Mardel= le. Committed on 31/12/2011 at 20:07. Pushed by mardelle into branch 'master'. Cleanup online resource feature M +2 -2 src/mainwindow.cpp M +3 -0 src/utils/CMakeLists.txt C +37 -42 src/utils/abstractservice.cpp [from: src/utils/freesound.h -= 052% similarity] A +92 -0 src/utils/abstractservice.h [License: GPL (v2+)] M +102 -313 src/utils/freesound.cpp M +16 -27 src/utils/freesound.h A +123 -0 src/utils/openclipart.cpp [License: GPL (v2+)] C +15 -34 src/utils/openclipart.h [from: src/utils/freesound.h - 057% = similarity] A +313 -0 src/utils/resourcewidget.cpp [License: Public Domain GPL= (v2+)] C +11 -15 src/utils/resourcewidget.h [from: src/utils/freesound.h - 07= 8% similarity] M +2 -5 src/widgets/freesound_ui.ui http://commits.kde.org/kdenlive/ede6f74de910cea0264b51e7a5b16b681b0b669b diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fa60af9..3f24cad 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -64,7 +64,7 @@ #include "audioscopes/spectrogram.h" #include "archivewidget.h" #include "databackup/backupwidget.h" -#include "utils/freesound.h" +#include "utils/resourcewidget.h" = = #include @@ -4508,7 +4508,7 @@ void MainWindow::slotDownloadResources() QString currentFolder; if (m_activeDocument) currentFolder =3D m_activeDocument->projectFolde= r().path(); else currentFolder =3D KdenliveSettings::defaultprojectfolder(); - FreeSound *d =3D new FreeSound(currentFolder); + ResourceWidget *d =3D new ResourceWidget(currentFolder); connect(d, SIGNAL(addClip(KUrl, const QString &)), this, SLOT(slotAddP= rojectClip(KUrl, const QString &))); d->show(); } diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 00e9edd..8c80687 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -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/freesound.h b/src/utils/abstractservice.cpp similarity index 52% copy from src/utils/freesound.h copy to src/utils/abstractservice.cpp index 149acab..9692eea 100644 --- a/src/utils/freesound.h +++ b/src/utils/abstractservice.cpp @@ -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 = * @@ -19,56 +19,51 @@ *************************************************************************= **/ = = -#ifndef FREESOUND_H -#define FREESOUND_H +#include "abstractservice.h" = +#include = -#include "ui_freesound_ui.h" = -#include -#include -#include +AbstractService::AbstractService(QListWidget *listWidget, QObject * parent= ) : + QObject(parent), + hasPreview(false), + hasMetadata(false), + serviceType(NOSERVICE), + m_listWidget(listWidget) +{ +} = -enum SERVICETYPE { FREESOUND =3D 0, OPENCLIPART =3D 1 }; +AbstractService::~AbstractService() +{ +} = -class FreeSound : public QDialog, public Ui::FreeSound_UI +void AbstractService::slotStartSearch(const QString , int ) { - Q_OBJECT +} = -public: - FreeSound(const QString & folder, QWidget * parent =3D 0); - ~FreeSound(); +OnlineItemInfo AbstractService::displayItemDetails(QListWidgetItem */*item= */) +{ + OnlineItemInfo info; + return info; +} = +bool AbstractService::startItemPreview(QListWidgetItem *) +{ + return false; +} = -private slots: - void slotStartSearch(int page =3D 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(); +void AbstractService::stopItemPreview(QListWidgetItem *) +{ +} = -private: - QString m_folder; - 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 &); -}; +QString AbstractService::getExtension(QListWidgetItem *) +{ + return QString(); +} = = -#endif +QString AbstractService::getDefaultDownloadName(QListWidgetItem *) +{ + return QString(); +} = diff --git a/src/utils/abstractservice.h b/src/utils/abstractservice.h new file mode 100644 index 0000000..52c3026 --- /dev/null +++ b/src/utils/abstractservice.h @@ -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 + +const int imageRole =3D Qt::UserRole; +const int urlRole =3D Qt::UserRole + 1; +const int downloadRole =3D Qt::UserRole + 2; +const int durationRole =3D Qt::UserRole + 3; +const int previewRole =3D Qt::UserRole + 4; +const int authorRole =3D Qt::UserRole + 5; +const int authorUrl =3D Qt::UserRole + 6; +const int infoUrl =3D Qt::UserRole + 7; +const int infoData =3D Qt::UserRole + 8; +const int idRole =3D Qt::UserRole + 9; +const int licenseRole =3D Qt::UserRole + 10; +const int descriptionRole =3D Qt::UserRole + 11; + +enum SERVICETYPE { NOSERVICE =3D 0, FREESOUND =3D 1, OPENCLIPART =3D 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 =3D 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 previe= w 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 =3D 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 info); +}; + + +#endif + diff --git a/src/utils/freesound.cpp b/src/utils/freesound.cpp index bb8a2e5..cb44593 100644 --- a/src/utils/freesound.cpp +++ b/src/utils/freesound.cpp @@ -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 = * @@ -49,56 +49,14 @@ #include #endif = -const int imageRole =3D Qt::UserRole; -const int urlRole =3D Qt::UserRole + 1; -const int downloadRole =3D Qt::UserRole + 2; -const int durationRole =3D Qt::UserRole + 3; -const int previewRole =3D Qt::UserRole + 4; -const int authorRole =3D Qt::UserRole + 5; -const int authorUrl =3D Qt::UserRole + 6; -const int infoUrl =3D Qt::UserRole + 7; -const int infoData =3D Qt::UserRole + 8; -const int idRole =3D Qt::UserRole + 9; -const int licenseRole =3D Qt::UserRole + 10; -const int descriptionRole =3D 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"), OPENCLIPA= RT); - setWindowTitle(i18n("Search Online Resources")); - info_widget->setStyleSheet(QString("QTreeWidget { background-color: tr= ansparent;}")); - item_description->setStyleSheet(QString("KTextBrowser { background-col= or: transparent;}")); - connect(button_search, SIGNAL(clicked()), this, SLOT(slotStartSearch()= )); - connect(search_results, SIGNAL(currentRowChanged(int)), this, SLOT(slo= tUpdateCurrentSound())); - connect(button_preview, SIGNAL(clicked()), this, SLOT(slotPlaySound())= ); - connect(button_import, SIGNAL(clicked()), this, SLOT(slotSaveSound())); - connect(sound_author, SIGNAL(leftClickedUrl(const QString &)), this, S= LOT(slotOpenUrl(const QString &))); - connect(item_license, SIGNAL(leftClickedUrl(const QString &)), this, S= LOT(slotOpenUrl(const QString &))); - connect(sound_name, SIGNAL(leftClickedUrl(const QString &)), this, SLO= T(slotOpenUrl(const QString &))); - m_previewProcess =3D new QProcess; - connect(m_previewProcess, SIGNAL(stateChanged(QProcess::ProcessState))= , this, SLOT(slotPreviewStatusChanged(QProcess::ProcessState))); - connect(service_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slo= tChangeService())); - sound_image->setFixedWidth(180); - if (Solid::Networking::status() =3D=3D Solid::Networking::Unconnected)= { - slotOffline(); - } - connect(Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, = SLOT(slotOnline())); - connect(Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), thi= s, 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(slotStartSe= arch(int))); - sound_box->setEnabled(false); - search_text->setFocus(); - Nepomuk::ResourceManager::instance()->init(); + serviceType =3D FREESOUND; + hasPreview =3D true; + hasMetadata =3D 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 =3D=3D FREESOUND) { - uri =3D "http://www.freesound.org/api/sounds/search/?q=3D"; - uri.append(search_text->text()); - if (page > 1) uri.append("&p=3D" + QString::number(page)); - uri.append("&api_key=3Da1772c8236e945a4bee30a64058dabf8"); - } - else if (m_service =3D=3D OPENCLIPART) { - uri =3D "http://openclipart.org/api/search/?query=3D"; - uri.append(search_text->text()); - if (page > 1) uri.append("&page=3D" + QString::number(page)); - } - = + m_listWidget->clear(); + QString uri =3D "http://www.freesound.org/api/sounds/search/?q=3D"; + uri.append(searchText); + if (page > 1) uri.append("&p=3D" + QString::number(page)); + uri.append("&api_key=3Da1772c8236e945a4bee30a64058dabf8"); + KJob* resolveJob =3D KIO::storedGet( KUrl(uri), KIO::NoReload, KIO::Hi= deProgressInfo ); connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotShowRe= sults( KJob* ) ) ); } @@ -134,143 +80,85 @@ void FreeSound::slotStartSearch(int page) void FreeSound::slotShowResults(KJob* job) { if (job->error() !=3D 0 ) return; - search_results->blockSignals(true); - search_results->clear(); + m_listWidget->blockSignals(true); KIO::StoredTransferJob* storedQueryJob =3D static_cast( job ); - if (m_service =3D=3D FREESOUND) { #ifdef USE_QJSON - QJson::Parser parser; - bool ok; - //kDebug()<<"// GOT RESULT: "<data(), &ok); - QVariant sounds; - if (data.canConvert(QVariant::Map)) { - QMap map =3D data.toMap(); - QMap::const_iterator i =3D map.constBegin(); - while (i !=3D map.constEnd()) { - if (i.key() =3D=3D "num_results") search_info->setText(i18= np("Found %1 result", "Found %1 results", i.value().toInt())); - else if (i.key() =3D=3D "num_pages") { - page_number->setMaximum(i.value().toInt()); - } - else if (i.key() =3D=3D "sounds") { - sounds =3D i.value(); - if (sounds.canConvert(QVariant::List)) { - QList soundsList =3D sounds.toList(); - for (int j =3D 0; j < soundsList.count(); j++) { - if (soundsList.at(j).canConvert(QVariant::Map)= ) { - QMap soundmap =3D soun= dsList.at(j).toMap(); - if (soundmap.contains("original_filename")= ) { - QListWidgetItem *item =3D new QListW= idgetItem(soundmap.value("original_filename").toString(), search_results); - item->setData(imageRole, soundmap.valu= e("waveform_m").toString()); - item->setData(infoUrl, soundmap.value(= "url").toString()); - item->setData(infoData, soundmap.value= ("ref").toString() + "?api_key=3Da1772c8236e945a4bee30a64058dabf8"); - item->setData(durationRole, soundmap.v= alue("duration").toDouble()); - item->setData(idRole, soundmap.value("= id").toInt()); - item->setData(previewRole, soundmap.va= lue("preview-hq-mp3").toString()); - item->setData(downloadRole, soundmap.v= alue("serve").toString() + "?api_key=3Da1772c8236e945a4bee30a64058dabf8"); - QVariant authorInfo =3D soundmap.value= ("user"); - if (authorInfo.canConvert(QVariant::Ma= p)) { - QMap authorMap= =3D authorInfo.toMap(); - if (authorMap.contains("username")= ) { - item->setData(authorRole, auth= orMap.value("username").toString()); - item->setData(authorUrl, autho= rMap.value("url").toString()); - } + QJson::Parser parser; + bool ok; + //kDebug()<<"// GOT RESULT: "<data(), &ok); + QVariant sounds; + if (data.canConvert(QVariant::Map)) { + QMap map =3D data.toMap(); + QMap::const_iterator i =3D map.constBegin(); + while (i !=3D map.constEnd()) { + if (i.key() =3D=3D "num_results") emit searchInfo(i18np("Found= %1 result", "Found %1 results", i.value().toInt())); + else if (i.key() =3D=3D "num_pages") { + emit maxPages(i.value().toInt()); + } + else if (i.key() =3D=3D "sounds") { + sounds =3D i.value(); + if (sounds.canConvert(QVariant::List)) { + QList soundsList =3D sounds.toList(); + for (int j =3D 0; j < soundsList.count(); j++) { + if (soundsList.at(j).canConvert(QVariant::Map)) { + QMap soundmap =3D soundsLi= st.at(j).toMap(); + if (soundmap.contains("original_filename")) { + QListWidgetItem *item =3D new QListWidge= tItem(soundmap.value("original_filename").toString(), m_listWidget); + item->setData(imageRole, soundmap.value("w= aveform_m").toString()); + item->setData(infoUrl, soundmap.value("url= ").toString()); + item->setData(infoData, soundmap.value("re= f").toString() + "?api_key=3Da1772c8236e945a4bee30a64058dabf8"); + 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=3Da1772c8236e945a4bee30a64058dabf8"); + QVariant authorInfo =3D soundmap.value("us= er"); + if (authorInfo.canConvert(QVariant::Map)) { + QMap authorMap =3D= authorInfo.toMap(); + if (authorMap.contains("username")) { + item->setData(authorRole, authorMa= p.value("username").toString()); + item->setData(authorUrl, authorMap= .value("url").toString()); } } } } } } - ++i; } + ++i; } -#endif = } - else if (m_service =3D=3D OPENCLIPART) { - QDomDocument doc; - doc.setContent(storedQueryJob->data()); - QDomNodeList items =3D doc.documentElement().elementsByTagName("it= em"); - for (int i =3D 0; i < items.count(); i++) { - QDomElement currentClip =3D items.at(i).toElement(); - QDomElement title =3D currentClip.firstChildElement("title"); - QListWidgetItem *item =3D new QListWidgetItem(title.firstChild= ().nodeValue(), search_results); - QDomElement thumb =3D currentClip.firstChildElement("media:thu= mbnail"); - item->setData(imageRole, thumb.attribute("url")); - QDomElement enclosure =3D currentClip.firstChildElement("enclo= sure"); - item->setData(downloadRole, enclosure.attribute("url")); - QDomElement link =3D currentClip.firstChildElement("link"); - item->setData(infoUrl, link.firstChild().nodeValue()); - QDomElement license =3D currentClip.firstChildElement("cc:lice= nse"); - item->setData(licenseRole, license.firstChild().nodeValue()); - QDomElement desc =3D currentClip.firstChildElement("descriptio= n"); - item->setData(descriptionRole, desc.firstChild().nodeValue()); - QDomElement author =3D currentClip.firstChildElement("dc:creat= or"); - 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 =3D search_results->currentItem(); + OnlineItemInfo info; + m_metaInfo.clear(); if (!item) { - sound_box->setEnabled(false); - return; - } - m_currentPreview =3D item->data(previewRole).toString(); - m_currentUrl =3D item->data(downloadRole).toString(); - m_currentId =3D 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 =3D item->data(infoData).toString(); - if (!extraInfo.isEmpty()) { - KJob* resolveJob =3D KIO::storedGet( KUrl(extraInfo), KIO::NoReloa= d, KIO::HideProgressInfo ); + return info; + } + info.itemPreview =3D item->data(previewRole).toString(); + info.itemDownload =3D item->data(downloadRole).toString(); + info.itemId =3D item->data(idRole).toInt(); + info.itemName =3D item->text(); + info.infoUrl =3D item->data(infoUrl).toString(); + info.author =3D item->data(authorRole).toString(); + info.authorUrl =3D item->data(authorUrl).toString(); + m_metaInfo.insert(i18n("Duration"), item->data(durationRole).toString(= )); + info.license =3D item->data(licenseRole).toString(); + info.description =3D item->data(descriptionRole).toString(); + = + QString extraInfoUrl =3D item->data(infoData).toString(); + if (!extraInfoUrl.isEmpty()) { + KJob* resolveJob =3D KIO::storedGet( KUrl(extraInfoUrl), KIO::NoRe= load, KIO::HideProgressInfo ); connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotPa= rseResults( 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 =3D pix.height() * sound_image->width() / pix.wi= dth(); - 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 =3D item->data(imageRole).toString(); + return info; } = = @@ -283,155 +171,56 @@ void FreeSound::slotParseResults(KJob* job) QVariant data =3D parser.parse(storedQueryJob->data(), &ok); if (data.canConvert(QVariant::Map)) { QMap infos =3D data.toMap(); - if (m_currentId !=3D infos.value("id").toInt()) return; + //if (m_currentId !=3D infos.value("id").toInt()) return; if (infos.contains("samplerate")) - new QTreeWidgetItem(info_widget, QStringList() << i18n("Sample= rate") << QString::number(infos.value("samplerate").toDouble())); + m_metaInfo.insert(i18n("Samplerate"), QString::number(infos.va= lue("samplerate").toDouble())); if (infos.contains("channels")) - new QTreeWidgetItem(info_widget, QStringList() << i18n("Channe= ls") << QString::number(infos.value("channels").toInt())); + m_metaInfo.insert(i18n("Channels"), QString::number(infos.valu= e("channels").toInt())); if (infos.contains("filesize")) { KIO::filesize_t fSize =3D infos.value("filesize").toDouble(); - new QTreeWidgetItem(info_widget, QStringList() << i18n("File s= ize") << 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").to= String()); } 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 =3D item->data(previewRole).toString(); + if (url.isEmpty()) return false; if (m_previewProcess && m_previewProcess->state() !=3D QProcess::NotRu= nning) { 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 !=3D FREESOUND) return; - m_previewProcess->close(); - if (m_currentPreview.isEmpty()) return; - if (play) - m_previewProcess->start("ffplay", QStringList() << m_currentPrevie= w << "-nodisp"); -} - -void FreeSound::slotPreviewStatusChanged(QProcess::ProcessState state) -{ - if (state =3D=3D QProcess::NotRunning) - button_preview->setText(i18n("Preview")); - else = - button_preview->setText(i18n("Stop")); -} - -void FreeSound::slotSaveSound() -{ - if (m_currentUrl.isEmpty()) return; - QString path =3D m_folder; - if (!path.endsWith('/')) path.append('/'); - path.append(sound_name->text()); - QString ext; - if (m_service =3D=3D FREESOUND) { - ext =3D "*." + sound_name->text().section('.', -1); - } - else if (m_service =3D=3D OPENCLIPART) { - path.append("." + m_currentUrl.section('.', -1)); - ext =3D "*." + m_currentUrl.section('.', -1); - } - QString saveUrl =3D KFileDialog::getSaveFileName(KUrl(path), ext); - if (saveUrl.isEmpty()) return; - if (KIO::NetAccess::download(KUrl(m_currentUrl), saveUrl, this)) { - const KUrl filePath =3D KUrl(saveUrl); -#ifdef USE_NEPOMUK - Nepomuk::Resource res( filePath ); - res.setProperty( Nepomuk::Vocabulary::NIE::license(), (Nepomuk::Va= riant) item_license->text() ); - res.setProperty( Nepomuk::Vocabulary::NIE::licenseType(), (Nepomuk= ::Variant) item_license->url() ); - res.setProperty( Nepomuk::Vocabulary::NDO::copiedFrom(), sound_nam= e->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 =3D (SERVICETYPE) service_list->itemData(service_list->curre= ntIndex()).toInt(); - if (m_service =3D=3D FREESOUND) { - button_preview->setVisible(true); - search_info->setVisible(true); - sound_autoplay->setVisible(true); - info_widget->setVisible(true); - } - else if (m_service =3D=3D 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() !=3D QProcess::NotRu= nning) { + 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 =3D 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 =3D page_number->value(); - if (ix > 1) page_number->setValue(ix - 1); -} - -void FreeSound::parseLicense(const QString &licenseUrl) -{ - QString licenseName; - if (licenseUrl.contains("/sampling+/")) - licenseName =3D "Sampling+"; - else if (licenseUrl.contains("/by/")) - licenseName =3D "Attribution"; - else if (licenseUrl.contains("/by-nd/")) - licenseName =3D "Attribution-NoDerivs"; - else if (licenseUrl.contains("/by-nc-sa/")) - licenseName =3D "Attribution-NonCommercial-ShareAlike"; - else if (licenseUrl.contains("/by-sa/")) - licenseName =3D "Attribution-ShareAlike"; - else if (licenseUrl.contains("/by-nc/")) - licenseName =3D "Attribution-NonCommercial"; - else if (licenseUrl.contains("/by-nc-nd/")) - licenseName =3D "Attribution-NonCommercial-NoDerivs"; - else if (licenseUrl.contains("/publicdomain/zero/")) - licenseName =3D "Creative Commons 0"; - else if (licenseUrl.endsWith("/publicdomain")) - licenseName =3D "Public Domain"; - item_license->setText(i18n("License: %1", licenseName)); - item_license->setUrl(licenseUrl); -} - diff --git a/src/utils/freesound.h b/src/utils/freesound.h index 149acab..88251a0 100644 --- a/src/utils/freesound.h +++ b/src/utils/freesound.h @@ -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 = * @@ -23,48 +23,37 @@ #define FREESOUND_H = = -#include "ui_freesound_ui.h" +#include "abstractservice.h" = -#include #include #include = -enum SERVICETYPE { FREESOUND =3D 0, OPENCLIPART =3D 1 }; = -class FreeSound : public QDialog, public Ui::FreeSound_UI +class FreeSound : public AbstractService { Q_OBJECT = public: - FreeSound(const QString & folder, QWidget * parent =3D 0); + FreeSound(QListWidget *listWidget, QObject * parent =3D 0); ~FreeSound(); + virtual QString getExtension(QListWidgetItem *item); + virtual QString getDefaultDownloadName(QListWidgetItem *item); + = +public slots: + virtual void slotStartSearch(const QString searchText, int page =3D 0); + virtual OnlineItemInfo displayItemDetails(QListWidgetItem *item); + virtual bool startItemPreview(QListWidgetItem *item); + virtual void stopItemPreview(QListWidgetItem *item); = = private slots: - void slotStartSearch(int page =3D 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 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 index 0000000..2340d99 --- /dev/null +++ b/src/utils/openclipart.cpp @@ -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 +#include + +#include +#include +#include + + +OpenClipArt::OpenClipArt(QListWidget *listWidget, QObject *parent) : + AbstractService(listWidget, parent) +{ + serviceType =3D OPENCLIPART; +} + +OpenClipArt::~OpenClipArt() +{ +} + +void OpenClipArt::slotStartSearch(const QString searchText, int page) +{ + m_listWidget->clear(); + QString uri =3D "http://openclipart.org/api/search/?query=3D"; + uri.append(searchText); + if (page > 1) uri.append("&page=3D" + QString::number(page)); + = + KJob* resolveJob =3D KIO::storedGet( KUrl(uri), KIO::NoReload, KIO::Hi= deProgressInfo ); + connect( resolveJob, SIGNAL( result( KJob* ) ), this, SLOT( slotShowRe= sults( KJob* ) ) ); +} + + +void OpenClipArt::slotShowResults(KJob* job) +{ + if (job->error() !=3D 0 ) return; + m_listWidget->blockSignals(true); + = + = + KIO::StoredTransferJob* storedQueryJob =3D static_cast( job ); + = + QDomDocument doc; + doc.setContent(storedQueryJob->data()); + QDomNodeList items =3D doc.documentElement().elementsByTagName("it= em"); + for (int i =3D 0; i < items.count(); i++) { + QDomElement currentClip =3D items.at(i).toElement(); + QDomElement title =3D currentClip.firstChildElement("title"); + QListWidgetItem *item =3D new QListWidgetItem(title.firstChild= ().nodeValue(), m_listWidget); + QDomElement thumb =3D currentClip.firstChildElement("media:thu= mbnail"); + item->setData(imageRole, thumb.attribute("url")); + QDomElement enclosure =3D currentClip.firstChildElement("enclo= sure"); + item->setData(downloadRole, enclosure.attribute("url")); + QDomElement link =3D currentClip.firstChildElement("link"); + item->setData(infoUrl, link.firstChild().nodeValue()); + QDomElement license =3D currentClip.firstChildElement("cc:lice= nse"); + item->setData(licenseRole, license.firstChild().nodeValue()); + QDomElement desc =3D currentClip.firstChildElement("descriptio= n"); + item->setData(descriptionRole, desc.firstChild().nodeValue()); + QDomElement author =3D currentClip.firstChildElement("dc:creat= or"); + 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 =3D item->data(previewRole).toString(); + info.itemDownload =3D item->data(downloadRole).toString(); + info.itemId =3D item->data(idRole).toInt(); + info.itemName =3D item->text(); + info.infoUrl =3D item->data(infoUrl).toString(); + info.author =3D item->data(authorRole).toString(); + info.authorUrl =3D item->data(authorUrl).toString(); + info.license =3D item->data(licenseRole).toString(); + info.description =3D item->data(descriptionRole).toString(); + info.imagePreview =3D item->data(imageRole).toString(); + return info; +} + +QString OpenClipArt::getExtension(QListWidgetItem *item) +{ + if (!item) return QString(); + QString url =3D item->data(downloadRole).toString(); + return QString("*.") + url.section('.', -1); +} + +QString OpenClipArt::getDefaultDownloadName(QListWidgetItem *item) +{ + if (!item) return QString(); + QString url =3D item->data(downloadRole).toString(); + QString path =3D item->text(); + path.append("." + url.section('.', -1)); + return path; +} + diff --git a/src/utils/freesound.h b/src/utils/openclipart.h similarity index 57% copy from src/utils/freesound.h copy to src/utils/openclipart.h index 149acab..66f2556 100644 --- a/src/utils/freesound.h +++ b/src/utils/openclipart.h @@ -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 = * @@ -19,54 +19,35 @@ *************************************************************************= **/ = = -#ifndef FREESOUND_H -#define FREESOUND_H +#ifndef OPENCLIPART_H +#define OPENCLIPART_H = = -#include "ui_freesound_ui.h" +#include "abstractservice.h" = -#include #include #include = -enum SERVICETYPE { FREESOUND =3D 0, OPENCLIPART =3D 1 }; = -class FreeSound : public QDialog, public Ui::FreeSound_UI +class OpenClipArt : public AbstractService { Q_OBJECT = public: - FreeSound(const QString & folder, QWidget * parent =3D 0); - ~FreeSound(); + OpenClipArt(QListWidget *listWidget, QObject * parent =3D 0); + ~OpenClipArt(); + virtual QString getExtension(QListWidgetItem *item); + virtual QString getDefaultDownloadName(QListWidgetItem *item); + = +public slots: + virtual void slotStartSearch(const QString searchText, int page =3D 0); + virtual OnlineItemInfo displayItemDetails(QListWidgetItem *item); + = = private slots: - void slotStartSearch(int page =3D 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; - QProcess *m_previewProcess; - SERVICETYPE m_service; - void parseLicense(const QString &); - = -signals: - void addClip(KUrl, const QString &); }; = = diff --git a/src/utils/resourcewidget.cpp b/src/utils/resourcewidget.cpp new file mode 100644 index 0000000..e2b4fa2 --- /dev/null +++ b/src/utils/resourcewidget.cpp @@ -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 +#include +#include +#include + +#include +#include "kdenlivesettings.h" +#include +#include +#include +#include +#include +#include +#include + +#ifdef USE_NEPOMUK +#include +#include +#include +#include +#include +#include +#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"), OPENCLIPA= RT); + setWindowTitle(i18n("Search Online Resources")); + info_widget->setStyleSheet(QString("QTreeWidget { background-color: tr= ansparent;}")); + item_description->setStyleSheet(QString("KTextBrowser { background-col= or: transparent;}")); + connect(button_search, SIGNAL(clicked()), this, SLOT(slotStartSearch()= )); + connect(search_results, SIGNAL(currentRowChanged(int)), this, SLOT(slo= tUpdateCurrentSound())); + connect(button_preview, SIGNAL(clicked()), this, SLOT(slotPlaySound())= ); + connect(button_import, SIGNAL(clicked()), this, SLOT(slotSaveSound())); + connect(sound_author, SIGNAL(leftClickedUrl(const QString &)), this, S= LOT(slotOpenUrl(const QString &))); + connect(item_license, SIGNAL(leftClickedUrl(const QString &)), this, S= LOT(slotOpenUrl(const QString &))); + connect(sound_name, SIGNAL(leftClickedUrl(const QString &)), this, SLO= T(slotOpenUrl(const QString &))); + connect(service_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slo= tChangeService())); + sound_image->setFixedWidth(180); + if (Solid::Networking::status() =3D=3D Solid::Networking::Unconnected)= { + slotOffline(); + } + connect(Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, = SLOT(slotOnline())); + connect(Solid::Networking::notifier(), SIGNAL(shouldDisconnect()), thi= s, 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(slotStartSe= arch(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 =3D=3D FREESOUND) { + uri =3D "http://www.freesound.org/api/sounds/search/?q=3D"; + uri.append(search_text->text()); + if (page > 1) uri.append("&p=3D" + QString::number(page)); + uri.append("&api_key=3Da1772c8236e945a4bee30a64058dabf8"); + } + else if (m_service =3D=3D OPENCLIPART) { + uri =3D "http://openclipart.org/api/search/?query=3D"; + uri.append(search_text->text()); + if (page > 1) uri.append("&page=3D" + QString::number(page)); + }*/ +} + +void ResourceWidget::slotUpdateCurrentSound() +{ + if (!sound_autoplay->isChecked()) m_currentService->stopItemPreview(NU= LL); + info_widget->clear(); + item_description->clear(); + item_license->clear(); + QListWidgetItem *item =3D search_results->currentItem(); + if (!item) { + sound_box->setEnabled(false); + return; + } + m_currentInfo =3D m_currentService->displayItemDetails(item); + /*m_currentPreview =3D item->data(previewRole).toString(); + m_currentUrl =3D item->data(downloadRole).toString(); + m_currentId =3D item->data(idRole).toInt();*/ + = + if (sound_autoplay->isChecked()) m_currentService->startItemPreview(it= em); + 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 =3D pix.height() * sound_image->width() / pix.wi= dth(); + 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 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::const_iterator i =3D metaInfo.constBegin(); + while (i !=3D metaInfo.constEnd()) { + new QTreeWidgetItem(info_widget, QStringList() << i.key() << i.val= ue()); + ++i; + } + info_widget->resizeColumnToContents(0); + info_widget->resizeColumnToContents(1); +} + + +void ResourceWidget::slotPlaySound() +{ + if (!m_currentService) return; + bool started =3D m_currentService->startItemPreview(search_results->cu= rrentItem()); + if (started) button_preview->setText(i18n("Preview")); + else button_preview->setText(i18n("Stop")); +} + + +void ResourceWidget::slotForcePlaySound(bool play) +{ + /* + if (m_service !=3D FREESOUND) return; + m_previewProcess->close(); + if (m_currentPreview.isEmpty()) return; + if (play) + m_previewProcess->start("ffplay", QStringList() << m_currentPrevie= w << "-nodisp"); + */ +} + +void ResourceWidget::slotPreviewStatusChanged(QProcess::ProcessState state) +{ + /*if (state =3D=3D QProcess::NotRunning) + button_preview->setText(i18n("Preview")); + else = + button_preview->setText(i18n("Stop"));*/ +} + +void ResourceWidget::slotSaveSound() +{ + //if (m_currentUrl.isEmpty()) return; + QListWidgetItem *item =3D search_results->currentItem(); + if (!item) return; + QString path =3D m_folder; + if (!path.endsWith('/')) path.append('/'); + path.append(m_currentService->getDefaultDownloadName(item)); + QString ext =3D m_currentService->getExtension(search_results->current= Item()); + QString saveUrl =3D KFileDialog::getSaveFileName(KUrl(path), ext); + if (saveUrl.isEmpty()) return; + if (KIO::NetAccess::download(KUrl(m_currentInfo.itemDownload), saveUrl= , this)) { + const KUrl filePath =3D KUrl(saveUrl); +#ifdef USE_NEPOMUK + Nepomuk::Resource res( filePath ); + res.setProperty( Nepomuk::Vocabulary::NIE::license(), (Nepomuk::Va= riant) item_license->text() ); + res.setProperty( Nepomuk::Vocabulary::NIE::licenseType(), (Nepomuk= ::Variant) item_license->url() ); + res.setProperty( Nepomuk::Vocabulary::NDO::copiedFrom(), sound_nam= e->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 =3D NULL; + } + SERVICETYPE service =3D (SERVICETYPE) service_list->itemData(service_l= ist->currentIndex()).toInt(); + if (service =3D=3D FREESOUND) { + m_currentService =3D new FreeSound(search_results); + } + else if (service =3D=3D OPENCLIPART) { + m_currentService =3D new OpenClipArt(search_results); + } + connect(m_currentService, SIGNAL(gotMetaInfo(QMap ))= , this, SLOT(slotDisplayMetaInfo(QMap ))); + connect(m_currentService, SIGNAL(maxPages(int)), page_number, SLOT(set= Maximum(int))); + connect(m_currentService, SIGNAL(searchInfo(QString)), search_info, SL= OT(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 =3D page_number->value(); + if (search_results->count() > 0) page_number->setValue(ix + 1); +} + +void ResourceWidget::slotPreviousPage() +{ + int ix =3D page_number->value(); + if (ix > 1) page_number->setValue(ix - 1); +} + +void ResourceWidget::parseLicense(const QString &licenseUrl) +{ + QString licenseName; + if (licenseUrl.contains("/sampling+/")) + licenseName =3D "Sampling+"; + else if (licenseUrl.contains("/by/")) + licenseName =3D "Attribution"; + else if (licenseUrl.contains("/by-nd/")) + licenseName =3D "Attribution-NoDerivs"; + else if (licenseUrl.contains("/by-nc-sa/")) + licenseName =3D "Attribution-NonCommercial-ShareAlike"; + else if (licenseUrl.contains("/by-sa/")) + licenseName =3D "Attribution-ShareAlike"; + else if (licenseUrl.contains("/by-nc/")) + licenseName =3D "Attribution-NonCommercial"; + else if (licenseUrl.contains("/by-nc-nd/")) + licenseName =3D "Attribution-NonCommercial-NoDerivs"; + else if (licenseUrl.contains("/publicdomain/zero/")) + licenseName =3D "Creative Commons 0"; + else if (licenseUrl.endsWith("/publicdomain")) + licenseName =3D "Public Domain"; + item_license->setText(i18n("License: %1", licenseName)); + item_license->setUrl(licenseUrl); +} + diff --git a/src/utils/freesound.h b/src/utils/resourcewidget.h similarity index 78% copy from src/utils/freesound.h copy to src/utils/resourcewidget.h index 149acab..001b01f 100644 --- a/src/utils/freesound.h +++ b/src/utils/resourcewidget.h @@ -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 = * @@ -19,35 +19,34 @@ *************************************************************************= **/ = = -#ifndef FREESOUND_H -#define FREESOUND_H +#ifndef RESOURCEWIDGET_H +#define RESOURCEWIDGET_H = = #include "ui_freesound_ui.h" +#include "abstractservice.h" = #include #include #include = -enum SERVICETYPE { FREESOUND =3D 0, OPENCLIPART =3D 1 }; = -class FreeSound : public QDialog, public Ui::FreeSound_UI +class ResourceWidget : public QDialog, public Ui::FreeSound_UI { Q_OBJECT = public: - FreeSound(const QString & folder, QWidget * parent =3D 0); - ~FreeSound(); + ResourceWidget(const QString & folder, QWidget * parent =3D 0); + ~ResourceWidget(); = = private slots: void slotStartSearch(int page =3D 0); - void slotShowResults(KJob* job); - void slotParseResults(KJob* job); void slotUpdateCurrentSound(); void slotPlaySound(); void slotForcePlaySound(bool play); void slotPreviewStatusChanged(QProcess::ProcessState state); + void slotDisplayMetaInfo(QMap metaInfo); void slotSaveSound(); void slotOpenUrl(const QString &url); void slotChangeService(); @@ -58,12 +57,9 @@ private slots: = private: QString m_folder; - QString m_currentPreview; - QString m_currentUrl; - int m_currentId; - QProcess *m_previewProcess; - SERVICETYPE m_service; + AbstractService *m_currentService; void parseLicense(const QString &); + OnlineItemInfo m_currentInfo; = signals: void addClip(KUrl, const QString &); diff --git a/src/widgets/freesound_ui.ui b/src/widgets/freesound_ui.ui index 095e94a..5c34302 100644 --- a/src/widgets/freesound_ui.ui +++ b/src/widgets/freesound_ui.ui @@ -6,8 +6,8 @@ 0 0 - 396 - 315 + 424 + 391 @@ -217,9 +217,6 @@ 0 - - page - 1