Make WebKitWidgets dependency optional, several minor fixes to ResourceWidget

parent c93a4888
......@@ -72,7 +72,8 @@ include(CheckIncludeFiles)
check_include_files(malloc.h HAVE_MALLOC_H)
check_include_files(pthread.h HAVE_PTHREAD_H)
find_package(Qt5 CONFIG REQUIRED Core DBus Widgets Script Svg Quick)
find_package(Qt5 REQUIRED COMPONENTS Core DBus Widgets Script Svg Quick )
find_package(Qt5 OPTIONAL_COMPONENTS WebKitWidgets QUIET)
find_package(KF5 REQUIRED COMPONENTS Archive Bookmarks CoreAddons Config ConfigWidgets
DBusAddons KIO WidgetsAddons Plotting NotifyConfig NewStuff XmlGui Notifications GuiAddons TextWidgets IconThemes DocTools Crash OPTIONAL_COMPONENTS FileMetaData)
......
......@@ -43,7 +43,6 @@ endif(NOT MLT_MELTBIN_failed)
option(WITH_JogShuttle "Build Jog/Shuttle support" ON)
set(FFMPEG_SUFFIX "" CACHE STRING "FFmpeg custom suffix")
find_package (Qt5WebKitWidgets)
find_package(LibV4L2)
set_package_properties(LibV4L2 PROPERTIES
DESCRIPTION "Collection of video4linux support libraries"
......@@ -108,7 +107,9 @@ add_subdirectory(onmonitoritems/rotoscoping)
add_subdirectory(mltcontroller)
add_subdirectory(bin)
add_subdirectory(qml)
add_subdirectory(qt-oauth-lib)
if (Qt5WebKitWidgets_FOUND)
add_subdirectory(qt-oauth-lib)
endif(Qt5WebKitWidgets_FOUND)
add_subdirectory(library)
list(APPEND kdenlive_SRCS
......@@ -263,7 +264,6 @@ target_link_libraries(kdenlive
KF5::TextWidgets
KF5::IconThemes
KF5::Crash
Qt5::WebKitWidgets
${Qt5_LIBRARIES}
Qt5::Svg
${OPENGL_LIBRARIES}
......@@ -282,6 +282,15 @@ endif()
qt5_use_modules( kdenlive Script Widgets Concurrent Qml Quick)
if (Qt5WebKitWidgets_FOUND)
message(STATUS "Found Qt5 WebKitWidgets. You can use your Freesound.org credentials to download files")
add_definitions(-DQT5_USE_WEBKIT)
target_link_libraries(kdenlive Qt5::WebKitWidgets)
else()
message(STATUS "Qt5 WebKitWidgets not found. You cannot use your Freesound.org credentials, only preview files can be downloaded from the Online Resources Widget")
endif()
if(Q_WS_X11)
include_directories(${X11_Xlib_INCLUDE_PATH})
target_link_libraries(kdenlive ${X11_LIBRARIES})
......
......@@ -48,9 +48,6 @@
#include <KConfigGroup>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
QString OAuth2::m_strClientSecret ="441d88374716e7a3503997151e4780566f007313"; //obtained when ttguy registered the kdenlive application with freesound
#endif /* DOXYGEN_SHOULD_SKIP_THIS ^^^ don't make this any more public than it is. This preprocessing directive makes the Doxygen documention ignore this line */
OAuth2::OAuth2(QWidget* parent)
{
......@@ -106,7 +103,7 @@ OAuth2::OAuth2(QWidget* parent)
*/
QString OAuth2::getClientSecret() const
{
return m_strClientSecret;
return OAuth2_strClientSecret;
}
/**
......@@ -266,8 +263,8 @@ void OAuth2::RequestAccessCode(bool pIsReRequest, QString pCode)
void OAuth2::serviceRequestFinished(QNetworkReply* reply)
{
// QString sRefreshToken;
int iExpiresIn ;
// QString sRefreshToken;
// int iExpiresIn;
QString sErrorText;
......@@ -280,7 +277,7 @@ void OAuth2::serviceRequestFinished(QNetworkReply* reply)
if (jsonError.error != QJsonParseError::NoError) {
qDebug()<<"OAuth2::serviceRequestFinished jsonError.error: " << jsonError.errorString();
ForgetAccessToken();
emit accessTokenReceived("");//notifies ResourceWidget::slotAccessTokenReceived - empty string in access token indicates error
emit accessTokenReceived(QString());//notifies ResourceWidget::slotAccessTokenReceived - empty string in access token indicates error
}
......@@ -303,14 +300,14 @@ void OAuth2::serviceRequestFinished(QNetworkReply* reply)
mstr_RefreshToken = map.value("refresh_token").toString();
}
if (map.contains("expires_in")) {
iExpiresIn = map.value("expires_in").toInt();//time in seconds until the access_token expires
// iExpiresIn = map.value("expires_in").toInt(); //time in seconds until the access_token expires
}
if (map.contains("error")) {
m_bAccessTokenRec=false;
sErrorText = map.value("error").toString();
qDebug() << "OAuth2::serviceRequestFinished map error: "<< sErrorText;
ForgetAccessToken();
emit accessTokenReceived("");//notifies ResourceWidget::slotAccessTokenReceived - empty string in access token indicates error
emit accessTokenReceived(QString());//notifies ResourceWidget::slotAccessTokenReceived - empty string in access token indicates error
}
if (m_bAccessTokenRec)
......
......@@ -41,6 +41,12 @@
#include <QObject>
#include <QNetworkReply>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
static QString OAuth2_strClientSecret ="441d88374716e7a3503997151e4780566f007313"; //obtained when ttguy registered the kdenlive application with freesound
#endif /* DOXYGEN_SHOULD_SKIP_THIS ^^^ don't make this any more public than it is. This preprocessing directive makes the Doxygen documention ignore this line */
#ifdef QT5_USE_WEBKIT
class LoginDialog;
/**
......@@ -138,4 +144,6 @@ private:
QWidget* m_pParent;
};
#endif // QT5_USE_WEBKIT
#endif // OAUTH2_H
......@@ -65,17 +65,15 @@ void FreeSound::slotStartSearch(const QString &searchText, int page)
{
// ver 2 of freesound API
m_listWidget->clear();
QString uri = "https://www.freesound.org/apiv2/search/text/?format=json&query=";
uri.append(searchText);
if (page > 1)
uri.append("&page=" + QString::number(page));
uri.append("&token=" + OAuth2::m_strClientSecret);
uri.append("&token=" + OAuth2_strClientSecret);
// qDebug()<<uri;
KIO::StoredTransferJob* resolveJob = KIO::storedGet( QUrl(uri), KIO::NoReload, KIO::HideProgressInfo );
connect(resolveJob, &KIO::StoredTransferJob::result, this, &FreeSound::slotShowResults);
}
/**
......@@ -133,10 +131,7 @@ void FreeSound::slotShowResults(KJob* job)
item->setData(authorUrl, "http://freesound.org/people/" + soundmap.value("username").toString());
item->setData(licenseRole, soundmap.value("license"));
item->setData(infoData,"http://www.freesound.org/apiv2/sounds/"+ vid.toString() +"/?format=json&token=" + OAuth2::m_strClientSecret);
item->setData(infoData, "http://www.freesound.org/apiv2/sounds/"+ vid.toString() +"/?format=json&token=" + OAuth2_strClientSecret);
}
}
}
......@@ -185,7 +180,6 @@ OnlineItemInfo FreeSound::displayItemDetails(QListWidgetItem *item)
// when the KJob resolveJob emits a result signal slotParseResults will be notified
connect(resolveJob, &KJob::result, this, &FreeSound::slotParseResults);
}
return info;
}
......@@ -197,7 +191,6 @@ OnlineItemInfo FreeSound::displayItemDetails(QListWidgetItem *item)
*/
void FreeSound::slotParseResults(KJob* job)
{
KIO::StoredTransferJob* storedQueryJob = static_cast<KIO::StoredTransferJob*>( job );
QJsonParseError jsonError;
QJsonDocument doc = QJsonDocument::fromJson(storedQueryJob->data(), &jsonError);
......@@ -210,16 +203,16 @@ void FreeSound::slotParseResults(KJob* job)
if (data.canConvert(QVariant::Map)) {
QMap <QString, QVariant> info = data.toMap();
html += "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">";
if (info.contains("duration")) {
html += "<tr>";
html += "<td>" + i18n("Duration (s)") + "</td><td>" + QString::number( info.value("duration").toDouble()) + "</td></tr>";
m_metaInfo.remove(i18n("Duration"));
m_metaInfo.insert(i18n("Duration"), info.value("duration").toString());
}
if (info.contains("samplerate")) {
html += "<tr class=\"cellone\">";
html += "<td>" + i18n("Samplerate") + "</td><td>" + QString::number(info.value("samplerate").toDouble()) + "</td></tr>";
......@@ -244,14 +237,13 @@ void FreeSound::slotParseResults(KJob* job)
if (info.contains("previews")) {
QMap <QString, QVariant> previews = info.value("previews").toMap();
if (previews.contains("preview-lq-mp3")) {
m_metaInfo.insert("itemPreview", previews.value("preview-lq-mp3").toString());
}
if (previews.contains("preview-hq-mp3")) {// Can use the high qual preview as alternative download if user does not have a free sound account
if (previews.contains("preview-hq-mp3")) {
// Can use the HQ preview as alternative download if user does not have a freesound account
m_metaInfo.insert("HQpreview", previews.value("preview-hq-mp3").toString());
}
}
......@@ -286,18 +278,17 @@ void FreeSound::slotParseResults(KJob* job)
* @return
*/
bool FreeSound::startItemPreview(QListWidgetItem *item)
{
{
if (!item)
return false;
const QString url = m_metaInfo.value("itemPreview");
if (url.isEmpty())
return false;
if (m_previewProcess) {
if (m_previewProcess->state() != QProcess::NotRunning) {
m_previewProcess->close();
}
// m_previewProcess->start(KdenliveSettings::ffplaypath() + " " + url + " -nodisp -autoexit");
qDebug()<<KdenliveSettings::ffplaypath() + " " + url + " -nodisp -autoexit";
if (m_previewProcess->state() != QProcess::NotRunning) {
m_previewProcess->close();
}
qDebug()<<KdenliveSettings::ffplaypath() + " " + url + " -nodisp -autoexit";
m_previewProcess->start(KdenliveSettings::ffplaypath(), QStringList() << url << QStringLiteral("-nodisp") << QStringLiteral("-autoexit"));
}
......@@ -357,14 +348,14 @@ QString FreeSound::getDefaultDownloadName(QListWidgetItem *item)
* emits signal picked up by ResourceWidget that ResouceWidget uses
* to set the Preview button back to the text Preview (it will say "Stop" before this.)
*/
void FreeSound::slotPreviewFinished(int exitCode, QProcess::ExitStatus exitStatus)
void FreeSound::slotPreviewFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
emit previewFinished();
Q_UNUSED(exitCode);
Q_UNUSED(exitStatus);
emit previewFinished();
}
void FreeSound::slotPreviewErrored(QProcess::ProcessError error)
{
qDebug()<< error;
qDebug()<< error;
}
......@@ -44,7 +44,6 @@
#include <KRun>
#include <KConfigGroup>
#include <KPixmapSequence>
#include <KPixmapSequenceOverlayPainter>
#include <KFileItem>
#include <KMessageBox>
#include <QUrlQuery>
......@@ -55,7 +54,9 @@
#include <QMovie>
#include <QPixmap>
#ifdef QT5_USE_WEBKIT
#include "qt-oauth-lib/oauth2.h"
#endif
ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
QDialog(parent),
......@@ -68,9 +69,6 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
setAttribute(Qt::WA_DeleteOnClose);
m_tmpThumbFile = new QTemporaryFile;
service_list->addItem(i18n("Freesound Audio Library"), FREESOUND);
service_list->addItem(i18n("Archive.org Video Library"), ARCHIVEORG);
service_list->addItem(i18n("Open Clip Art Graphic Library"), OPENCLIPART);
......@@ -85,7 +83,6 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
connect(item_license, SIGNAL(leftClickedUrl(QString)), this, SLOT(slotOpenUrl(QString)));
connect(service_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeService()));
m_networkManager = new QNetworkConfigurationManager(this);
if (!m_networkManager->isOnline()) {
......@@ -98,7 +95,7 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
connect(info_browser, SIGNAL(anchorClicked(QUrl)), this, SLOT(slotOpenLink(QUrl)));
m_networkAccessManager = new QNetworkAccessManager(this);
m_autoPlay = new QAction(i18n("Auto Play"), this);
m_autoPlay->setCheckable(true);
QMenu *resourceMenu = new QMenu;
......@@ -106,19 +103,17 @@ ResourceWidget::ResourceWidget(const QString & folder, QWidget * parent) :
config_button->setMenu(resourceMenu);
config_button->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
m_busyWidget = new KPixmapSequenceOverlayPainter(this);
m_busyWidget->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_busyWidget->setWidget(search_results->viewport());
sound_box->setEnabled(false);
search_text->setFocus();
connect(search_text, SIGNAL(returnPressed()), this, SLOT(slotStartSearch()));
#ifdef QT5_USE_WEBKIT
m_pOAuth2 = new OAuth2(this);
connect(m_pOAuth2, SIGNAL(accessTokenReceived(QString)), this, SLOT(slotAccessTokenReceived(QString)));
connect(m_pOAuth2, SIGNAL(accessDenied()), this, SLOT(slotFreesoundAccessDenied()));
connect(m_pOAuth2, SIGNAL( UseHQPreview()), this, SLOT(slotFreesoundUseHQPreview()));
connect(m_pOAuth2, SIGNAL(Canceled()), this, SLOT(slotFreesoundCanceled()));
#endif
m_currentService = new FreeSound(search_results);
m_currentService->slotStartSearch("dummy", 0);// Run a dummy search to initialise the search.
// for reasons I (ttguy) can not fathom the first search that gets run fails
......@@ -170,7 +165,7 @@ void ResourceWidget::saveConfig()
*/
void ResourceWidget::slotStartSearch(int page)
{
m_busyWidget->start();
this->setCursor(Qt::WaitCursor);
info_browser->clear();
page_number->blockSignals(true);
page_number->setValue(page);
......@@ -338,7 +333,7 @@ void ResourceWidget::slotPlaySound()
if (!m_currentService)
return;
caption= button_preview->text();
if (caption.contains( sPreview))
if (caption.contains(sPreview))
{
const bool started = m_currentService->startItemPreview(search_results->currentItem());
if (started)
......@@ -381,10 +376,13 @@ void ResourceWidget::slotSaveItem(const QString &originalUrl)
if(m_currentService->serviceType==FREESOUND)
{
sFileExt=m_currentService->getExtension(search_results->currentItem());
#ifdef QT5_USE_WEBKIT
sFileExt = m_currentService->getExtension(search_results->currentItem());
#else
sFileExt = QStringLiteral("*.") + m_currentInfo.HQpreview.section('.', -1);
#endif
if ( sFileExt.isEmpty())
sFileExt=QStringLiteral("*.") + m_currentInfo.fileType;// if the file name had no extension then use the file type freesound says it is.
ext ="Audio ("+ sFileExt +");;All Files(*.*)";
}
......@@ -408,6 +406,7 @@ void ResourceWidget::slotSaveItem(const QString &originalUrl)
}
slotSetDescription("");
button_import->setEnabled(false); // disable buttons while download runs. enabled in slotGotFile
#ifdef QT5_USE_WEBKIT
if(m_currentService->serviceType==FREESOUND)// open a dialog to authenticate with free sound and download the file
{
m_pOAuth2->obtainAccessToken();// when job finished ResourceWidget::slotAccessTokenReceived will be called
......@@ -416,6 +415,14 @@ void ResourceWidget::slotSaveItem(const QString &originalUrl)
{
DoFileDownload(srcUrl, QUrl (saveUrl));
}
#else
saveUrl=QUrl::fromLocalFile (mSaveLocation);
if(m_currentService->serviceType==FREESOUND) {
// No OAuth, default to HQ preview
srcUrl = QUrl(m_currentInfo.HQpreview);
}
DoFileDownload(srcUrl, QUrl (saveUrl));
#endif
}
/**
......@@ -501,7 +508,7 @@ void ResourceWidget::slotGotFile(KJob *job)
KIO::FileCopyJob* copyJob = static_cast<KIO::FileCopyJob*>( job );
const QUrl filePath = copyJob->destUrl();
KMessageBox::information(this,i18n( "Resource saved to ") + filePath.toString(), i18n("Data Imported"));
KMessageBox::information(this,i18n( "Resource saved to ") + filePath.path(), i18n("Data Imported"));
emit addClip(filePath);
}
}
......@@ -543,7 +550,7 @@ void ResourceWidget::slotChangeService()
connect(m_currentService, SIGNAL(maxPages(int)), this, SLOT(slotSetMaximum(int)));
connect(m_currentService, SIGNAL(searchInfo(QString)), search_info, SLOT(setText(QString)));
connect(m_currentService, SIGNAL(gotThumb(QString)), this, SLOT(slotLoadThumb(QString)));
connect(m_currentService, SIGNAL(searchDone()), m_busyWidget, SLOT(stop()));
connect(m_currentService, SIGNAL(searchDone()), this, SLOT(slotSearchFinished()));
if (m_currentService->hasPreview)
connect (m_currentService,SIGNAL(previewFinished()),this, SLOT(slotPreviewFinished()));
......@@ -555,6 +562,12 @@ void ResourceWidget::slotChangeService()
if (!search_text->text().isEmpty())
slotStartSearch();// automatically kick of a search if we have search text and we switch services.
}
void ResourceWidget::slotSearchFinished()
{
this->setCursor(Qt::ArrowCursor);
}
/**
* @brief ResourceWidget::slotSetMaximum
* @param max
......@@ -857,7 +870,9 @@ void ResourceWidget::DownloadRequestFinished(QNetworkReply* reply)
}
else
{
#ifdef QT5_USE_WEBKIT
m_pOAuth2->ForgetAccessToken();
#endif
m_desc.append("<br>" + i18n("Error Saving File"));
updateLayout();
......@@ -869,14 +884,16 @@ void ResourceWidget::DownloadRequestFinished(QNetworkReply* reply)
if (reply->error()==QNetworkReply::AuthenticationRequiredError)
{
QString sErrorText = reply->readAll();
QString sErrorText = reply->readAll();
#ifdef QT5_USE_WEBKIT
m_pOAuth2->obtainNewAccessToken();
#endif
}
else
{
#ifdef QT5_USE_WEBKIT
m_pOAuth2->ForgetAccessToken();
#endif
m_desc.append("<br>" + i18n( "Error Downloading File. Error code: ") + reply->error() + "<br>");
m_desc.append("<br><b>" + i18n("Try importing again to obtain a new freesound connection")+ "</b>");
updateLayout();
......
......@@ -29,16 +29,13 @@
#include <QDialog>
#include <kio/jobclasses.h>
#include "qt-oauth-lib/oauth2.h"
#include <QNetworkReply>
class KPixmapSequenceOverlayPainter;
class QAction;
class QNetworkConfigurationManager;
class QTemporaryFile;
class QMovie;
class OAuth2;
/**
\brief This is the window that appears from Project>Online Resources
......@@ -57,10 +54,6 @@ public:
explicit ResourceWidget(const QString & folder, QWidget * parent = 0);
~ResourceWidget();
//private:
// OAuth2* m_pOAuth2;
private slots:
void slotStartSearch(int page = 0);
/**
......@@ -93,7 +86,7 @@ private slots:
void slotAccessTokenReceived(QString sAccessToken);
void slotFreesoundUseHQPreview();
void slotFreesoundCanceled();
void slotSearchFinished();
void slotLoadPreview(const QString &url);
void slotLoadAnimatedGif(KJob *job);
......@@ -111,7 +104,6 @@ private:
QString mSaveLocation;
AbstractService *m_currentService;
OnlineItemInfo m_currentInfo;
KPixmapSequenceOverlayPainter *m_busyWidget;
QAction *m_autoPlay;
QTemporaryFile *m_tmpThumbFile;
QString m_title;
......
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