X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Futils%2Fresourcewidget.cpp;h=b88a0db9a91cd69fdeb0991667f8e42276ee53c1;hb=07cc32ca3557ccce583f95cbc8dd114d989b4f49;hp=7201aedb8bb34a2e004ba18a3fd8a3074958ad1d;hpb=bc47853986dd50efdd4cc1ec21af54b5c25e492c;p=kdenlive diff --git a/src/utils/resourcewidget.cpp b/src/utils/resourcewidget.cpp index 7201aedb..b88a0db9 100644 --- a/src/utils/resourcewidget.cpp +++ b/src/utils/resourcewidget.cpp @@ -23,6 +23,7 @@ #include "freesound.h" #include "openclipart.h" #include "archiveorg.h" +#include "kdenlivesettings.h" #include #include @@ -32,7 +33,6 @@ #include #include -#include "kdenlivesettings.h" #include #include #include @@ -40,6 +40,8 @@ #include #include #include +#include + #if KDE_IS_VERSION(4,4,0) #include #include @@ -47,23 +49,23 @@ #include #ifdef USE_NEPOMUK -#if KDE_IS_VERSION(4,6,0) -#include -#include -#include -#include -#include -#include -#endif + #if KDE_IS_VERSION(4,6,0) + #include + #include + #include + #include + #include + #include + #endif #endif #ifdef USE_NEPOMUKCORE -#include -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include + #include #endif ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) : @@ -113,17 +115,36 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) : sound_box->setEnabled(false); search_text->setFocus(); #ifdef USE_NEPOMUK -#if KDE_IS_VERSION(4,6,0) + #if KDE_IS_VERSION(4,6,0) Nepomuk::ResourceManager::instance()->init(); -#endif + #endif #endif slotChangeService(); + loadConfig(); } ResourceWidget::~ResourceWidget() { delete m_currentService; KIO::NetAccess::removeTempFile(m_tmpThumbFile); + saveConfig(); +} + +void ResourceWidget::loadConfig() +{ + KSharedConfigPtr config = KGlobal::config(); + KConfigGroup resourceConfig(config, "ResourceWidget"); + QList size; + size << 100 << 400; + splitter->setSizes(resourceConfig.readEntry( "mainSplitter", size)); +} + +void ResourceWidget::saveConfig() +{ + KSharedConfigPtr config = KGlobal::config(); + KConfigGroup resourceConfig(config, "ResourceWidget"); + resourceConfig.writeEntry(QLatin1String("mainsplitter"), splitter->size()); + config->sync(); } void ResourceWidget::slotStartSearch(int page) @@ -140,7 +161,8 @@ void ResourceWidget::slotStartSearch(int page) void ResourceWidget::slotUpdateCurrentSound() { KIO::NetAccess::removeTempFile(m_tmpThumbFile); - if (!m_autoPlay->isChecked()) m_currentService->stopItemPreview(NULL); + if (!m_autoPlay->isChecked()) + m_currentService->stopItemPreview(NULL); item_license->clear(); m_title.clear(); m_image.clear(); @@ -153,10 +175,12 @@ void ResourceWidget::slotUpdateCurrentSound() } m_currentInfo = m_currentService->displayItemDetails(item); - if (m_autoPlay->isChecked() && m_currentService->hasPreview) m_currentService->startItemPreview(item); + if (m_autoPlay->isChecked() && m_currentService->hasPreview) + m_currentService->startItemPreview(item); sound_box->setEnabled(true); QString title = "

" + m_currentInfo.itemName; - if (!m_currentInfo.infoUrl.isEmpty()) title += QString(" (%2)").arg(m_currentInfo.infoUrl).arg(i18nc("the url link pointing to a web page", "link")); + if (!m_currentInfo.infoUrl.isEmpty()) + title += QString(" (%2)").arg(m_currentInfo.infoUrl).arg(i18nc("the url link pointing to a web page", "link")); title.append("

"); if (!m_currentInfo.authorUrl.isEmpty()) { @@ -168,7 +192,8 @@ void ResourceWidget::slotUpdateCurrentSound() } else if (!m_currentInfo.author.isEmpty()) title.append(m_currentInfo.author + "
"); - else title.append("
"); + else + title.append("
"); slotSetTitle(title); if (!m_currentInfo.description.isEmpty()) slotSetDescription(m_currentInfo.description); @@ -202,21 +227,24 @@ void ResourceWidget::slotLoadThumb(const QString &url) void ResourceWidget::slotDisplayMetaInfo(const QMap &metaInfo) { - if (metaInfo.contains("license")) { - parseLicense(metaInfo.value("license")); + if (metaInfo.contains(QLatin1String("license"))) { + parseLicense(metaInfo.value(QLatin1String("license"))); } - if (metaInfo.contains("description")) { - slotSetDescription(metaInfo.value("description")); + if (metaInfo.contains(QLatin1String("description"))) { + slotSetDescription(metaInfo.value(QLatin1String("description"))); } } 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")); + if (!m_currentService) + return; + const bool started = m_currentService->startItemPreview(search_results->currentItem()); + if (started) + button_preview->setText(i18n("Preview")); + else + button_preview->setText(i18n("Stop")); } @@ -240,7 +268,8 @@ void ResourceWidget::slotSaveItem(const QString &originalUrl) QString saveUrl = KFileDialog::getSaveFileName(KUrl(path), ext); KIO::UDSEntry entry; KUrl srcUrl(m_currentInfo.itemDownload); - if (saveUrl.isEmpty() || !KIO::NetAccess::stat(srcUrl, entry, this)) return; + if (saveUrl.isEmpty() || !KIO::NetAccess::stat(srcUrl, entry, this)) + return; KIO::FileCopyJob * getJob = KIO::file_copy(srcUrl, KUrl(saveUrl), -1, KIO::Overwrite); KFileItem info(entry, srcUrl); @@ -260,7 +289,7 @@ void ResourceWidget::slotGotFile(KJob *job) KIO::FileCopyJob* copyJob = static_cast( job ); const KUrl filePath = copyJob->destUrl(); #ifdef USE_NEPOMUK -#if KDE_IS_VERSION(4,6,0) + #if KDE_IS_VERSION(4,6,0) Nepomuk::Resource res( filePath ); res.setProperty( Nepomuk::Vocabulary::NIE::license(), (Nepomuk::Variant) job->property("license") ); res.setProperty( Nepomuk::Vocabulary::NIE::licenseType(), (Nepomuk::Variant) job->property("licenseurl") ); @@ -268,7 +297,7 @@ void ResourceWidget::slotGotFile(KJob *job) res.setProperty( Nepomuk::Vocabulary::NCO::creator(), (Nepomuk::Variant) job->property("author") ); //res.setDescription(item_description->toPlainText()); //res.setProperty( Soprano::Vocabulary::NAO::description(), -#endif + #endif #endif #ifdef USE_NEPOMUKCORE @@ -291,18 +320,14 @@ void ResourceWidget::slotOpenUrl(const QString &url) void ResourceWidget::slotChangeService() { - if (m_currentService) { - delete m_currentService; - m_currentService = NULL; - } + 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) { + } else if (service == OPENCLIPART) { m_currentService = new OpenClipArt(search_results); - } - else if (service == ARCHIVEORG) { + } else if (service == ARCHIVEORG) { m_currentService = new ArchiveOrg(search_results); } @@ -318,7 +343,8 @@ void ResourceWidget::slotChangeService() button_preview->setVisible(m_currentService->hasPreview); button_import->setVisible(!m_currentService->inlineDownload); search_info->setText(QString()); - if (!search_text->text().isEmpty()) slotStartSearch(); + if (!search_text->text().isEmpty()) + slotStartSearch(); } void ResourceWidget::slotSetMaximum(int max) @@ -340,14 +366,16 @@ void ResourceWidget::slotOffline() void ResourceWidget::slotNextPage() { - int ix = page_number->value(); - if (search_results->count() > 0) page_number->setValue(ix + 1); + const 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); + const int ix = page_number->value(); + if (ix > 1) + page_number->setValue(ix - 1); } void ResourceWidget::parseLicense(const QString &licenseUrl) @@ -392,34 +420,43 @@ void ResourceWidget::slotOpenLink(const QUrl &url) void ResourceWidget::slotSetDescription(const QString &desc) { - m_desc = desc; - updateLayout(); + if(m_desc != desc) { + m_desc = desc; + updateLayout(); + } } void ResourceWidget::slotSetMetadata(const QString &desc) { - m_meta = desc; - updateLayout(); + if (m_meta != desc) { + m_meta = desc; + updateLayout(); + } } void ResourceWidget::slotSetImage(const QString &desc) { - m_image = QString("").arg(desc).arg((int) (info_browser->width() * 0.9)); + m_image = QString::fromLatin1("").arg(desc).arg((int) (info_browser->width() * 0.9)); updateLayout(); } void ResourceWidget::slotSetTitle(const QString &desc) { - m_title = desc; - updateLayout(); + if (m_title != desc) { + m_title = desc; + updateLayout(); + } } void ResourceWidget::updateLayout() { QString content = m_title; - if (!m_image.isEmpty()) content.append(m_image + "
"); - if (!m_desc.isEmpty()) content.append(m_desc); - if (!m_meta.isEmpty()) content.append(m_meta); + if (!m_image.isEmpty()) + content.append(m_image + "
"); + if (!m_desc.isEmpty()) + content.append(m_desc); + if (!m_meta.isEmpty()) + content.append(m_meta); info_browser->setHtml(content); }