Now one can also search and import image clips from openclipart.org

parent 4d59dfaf
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<gui name="kdenlive" version="67">
<gui name="kdenlive" version="68">
<ToolBar name="extraToolBar" >
<text>Extra Toolbar</text>
<Action name="project_render" />
......@@ -25,7 +25,7 @@
<Action name="add_text_clip" />
<Action name="add_text_template_clip" />
<Action name="add_folder" />
<Action name="download_audio" />
<Action name="download_resource" />
<Menu name="extract_audio" ><text>Extract Audio</text>
</Menu>
<Menu name="stabilize" ><text>Stabilize</text>
......
......@@ -1640,9 +1640,9 @@ void MainWindow::setupActions()
collection.addAction("add_folder", addFolderButton);
connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
QAction *downloadAudio = new KAction(KIcon("download"), i18n("Download Audio"), this);
collection.addAction("download_audio", downloadAudio);
connect(downloadAudio , SIGNAL(triggered()), this, SLOT(slotDownloadAudio()));
QAction *downloadResources = new KAction(KIcon("download"), i18n("Online Resources"), this);
collection.addAction("download_resource", downloadResources);
connect(downloadResources , SIGNAL(triggered()), this, SLOT(slotDownloadResources()));
QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
collection.addAction("clip_properties", clipProperties);
......@@ -1686,6 +1686,7 @@ void MainWindow::setupActions()
addClips->addAction(addTitleClip);
addClips->addAction(addTitleTemplateClip);
addClips->addAction(addFolderButton);
addClips->addAction(downloadResources);
addClips->addAction(reloadClip);
addClips->addAction(proxyClip);
......@@ -4502,7 +4503,7 @@ void MainWindow::slotElapsedTime()
}
void MainWindow::slotDownloadAudio()
void MainWindow::slotDownloadResources()
{
QString currentFolder;
if (m_activeDocument) currentFolder = m_activeDocument->projectFolder().path();
......
......@@ -550,8 +550,8 @@ private slots:
void slotDisableProxies();
void slotElapsedTime();
/** @brief Open the freesound audio search dialog. */
void slotDownloadAudio();
/** @brief Open the online services search dialog. */
void slotDownloadResources();
signals:
Q_SCRIPTABLE void abortRenderJob(const QString &url);
......
......@@ -24,6 +24,7 @@
#include <QPushButton>
#include <QSpinBox>
#include <QListWidget>
#include <QDomDocument>
#include <KDebug>
#include "kdenlivesettings.h"
......@@ -38,21 +39,25 @@
const int imageRole = Qt::UserRole;
const int urlRole = Qt::UserRole + 1;
const int soundRole = Qt::UserRole + 2;
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 soundUrl = Qt::UserRole + 7;
const int infoUrl = Qt::UserRole + 7;
FreeSound::FreeSound(const QString & folder, QWidget * parent) :
QDialog(parent),
m_folder(folder)
m_folder(folder),
m_service(FREESOUND)
{
setFont(KGlobalSettings::toolBarFont());
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(i18n("Search FreeSound Audio Library"));
service_list->addItem(i18n("Freesound Audio Library"), FREESOUND);
service_list->addItem(i18n("Open Clip Art Graphic Library"), OPENCLIPART);
setWindowTitle(i18n("Search Online Resources"));
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()));
......@@ -61,6 +66,8 @@ FreeSound::FreeSound(const QString & folder, QWidget * parent) :
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);
}
FreeSound::~FreeSound()
......@@ -76,9 +83,17 @@ void FreeSound::slotStartSearch()
page_number->blockSignals(true);
page_number->setValue(0);
page_number->blockSignals(false);
QString uri = "http://www.freesound.org/api/sounds/search/?q=";
uri.append(search_text->text());
uri.append("&api_key=a1772c8236e945a4bee30a64058dabf8");
QString uri;
if (m_service == FREESOUND) {
uri = "http://www.freesound.org/api/sounds/search/?q=";
uri.append(search_text->text());
uri.append("&api_key=a1772c8236e945a4bee30a64058dabf8");
}
else if (m_service == OPENCLIPART) {
uri = "http://openclipart.org/api/search/?query=";
uri.append(search_text->text());
//water&page=4
}
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()));
......@@ -86,54 +101,75 @@ void FreeSound::slotStartSearch()
void FreeSound::slotDataIsHere(KIO::Job *,const QByteArray & data )
{
//kDebug() << "data is here";
m_result.append(data);
}
void FreeSound::slotShowResults()
{
QJson::Parser parser;
bool ok;
m_data = parser.parse(m_result, &ok);
QVariant sounds;
search_results->blockSignals(true);
search_results->clear();
if (m_data.canConvert(QVariant::Map)) {
QMap <QString, QVariant> map = m_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(soundUrl, soundmap.value("url").toString());
item->setData(durationRole, soundmap.value("duration").toDouble());
item->setData(previewRole, soundmap.value("preview-hq-mp3").toString());
item->setData(soundRole, 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());
if (m_service == FREESOUND) {
QJson::Parser parser;
bool ok;
kDebug()<<"// GOT RESULT: "<<m_result;
m_data = parser.parse(m_result, &ok);
QVariant sounds;
if (m_data.canConvert(QVariant::Map)) {
QMap <QString, QVariant> map = m_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(durationRole, soundmap.value("duration").toDouble());
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;
}
}
else if (m_service == OPENCLIPART) {
QDomDocument doc;
doc.setContent(m_result);
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 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);
......@@ -150,20 +186,29 @@ void FreeSound::slotUpdateCurrentSound()
return;
}
m_currentPreview = item->data(previewRole).toString();
m_currentUrl = item->data(soundRole).toString();
m_currentUrl = item->data(downloadRole).toString();
button_preview->setEnabled(!m_currentPreview.isEmpty());
sound_box->setEnabled(true);
sound_name->setText(item->text());
sound_name->setUrl(item->data(soundUrl).toString());
sound_name->setUrl(item->data(infoUrl).toString());
sound_author->setText(item->data(authorRole).toString());
sound_author->setUrl(item->data(authorUrl).toString());
sound_duration->setText(QString::number(item->data(durationRole).toDouble()));
if (!item->data(durationRole).isNull()) sound_duration->setText(QString::number(item->data(durationRole).toDouble()));
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 > 2 * sound_image->width()) {
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);
}
......@@ -195,7 +240,14 @@ void FreeSound::slotSaveSound()
QString path = m_folder;
if (!path.endsWith('/')) path.append('/');
path.append(sound_name->text());
QString ext = "*." + sound_name->text().section('.', -1);
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)) {
......@@ -207,3 +259,21 @@ 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);
duration_label->setVisible(true);
search_info->setVisible(true);
}
else if (m_service == OPENCLIPART) {
button_preview->setVisible(false);
duration_label->setVisible(false);
search_info->setVisible(false);
sound_duration->setText(QString());
}
if (!search_text->text().isEmpty()) slotStartSearch();
}
......@@ -29,7 +29,7 @@
#include <QProcess>
#include <kio/jobclasses.h>
enum SERVICETYPE { FREESOUND = 0, OPENCLIPART = 1 };
class FreeSound : public QDialog, public Ui::FreeSound_UI
{
......@@ -49,6 +49,7 @@ private slots:
void slotPreviewStatusChanged(QProcess::ProcessState state);
void slotSaveSound();
void slotOpenUrl(const QString &url);
void slotChangeService();
private:
QString m_folder;
......@@ -57,6 +58,7 @@ private:
QString m_currentPreview;
QString m_currentUrl;
QProcess *m_previewProcess;
SERVICETYPE m_service;
signals:
void addClip(KUrl, const QString &);
......
......@@ -6,25 +6,53 @@
<rect>
<x>0</x>
<y>0</y>
<width>334</width>
<height>284</height>
<width>250</width>
<height>227</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="KLineEdit" name="search_text"/>
<item row="0" column="0" colspan="5">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Service</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="service_list">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2" colspan="2">
<item row="1" column="0" colspan="2">
<widget class="KLineEdit" name="search_text">
<property name="clickMessage">
<string/>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2" colspan="2">
<widget class="QPushButton" name="button_search">
<property name="text">
<string>Search</string>
</property>
</widget>
</item>
<item row="0" column="4" rowspan="2">
<item row="1" column="4" rowspan="2">
<widget class="QGroupBox" name="sound_box">
<property name="title">
<string/>
......@@ -35,8 +63,8 @@
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
......@@ -47,17 +75,7 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Similar sounds</string>
</property>
</widget>
</item>
<item row="7" column="3">
<widget class="QComboBox" name="similar_list"/>
</item>
<item row="8" column="1">
<item row="7" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -70,7 +88,7 @@
</property>
</spacer>
</item>
<item row="9" column="0" colspan="4">
<item row="8" column="0" colspan="4">
<widget class="QPushButton" name="button_import">
<property name="text">
<string>Import</string>
......@@ -95,7 +113,7 @@
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="duration_label">
<property name="text">
<string>Duration</string>
</property>
......@@ -127,14 +145,14 @@
</layout>
</widget>
</item>
<item row="1" column="0" colspan="4">
<item row="2" column="0" colspan="4">
<widget class="QListWidget" name="search_results">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QPushButton" name="page_prev">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
......@@ -147,7 +165,7 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<item row="3" column="1" colspan="2">
<widget class="QSpinBox" name="page_number">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
......@@ -157,7 +175,7 @@
</property>
</widget>
</item>
<item row="2" column="3">
<item row="3" column="3">
<widget class="QPushButton" name="page_next">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
......@@ -170,14 +188,14 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<item row="4" column="0" colspan="4">
<widget class="QLabel" name="search_info">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="4">
<item row="4" column="4">
<widget class="QDialogButtonBox" name="ButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment