Backport KF5 Purpose share feature

parent 3a34c2ab
......@@ -91,7 +91,7 @@ endif()
find_package(KF5 REQUIRED COMPONENTS Archive Bookmarks CoreAddons Config ConfigWidgets
DBusAddons KIO WidgetsAddons NotifyConfig NewStuff XmlGui Notifications GuiAddons TextWidgets IconThemes
OPTIONAL_COMPONENTS DocTools FileMetaData Crash)
OPTIONAL_COMPONENTS DocTools FileMetaData Crash Purpose)
if (KF5FileMetaData_FOUND)
message(STATUS "Found KF5 FileMetadata to extract file metadata")
......@@ -100,6 +100,13 @@ else()
message(STATUS "KF5 FileMetadata not found, file metadata will not be available")
endif()
if (KF5Purpose_FOUND)
message(STATUS "Found KF5 Purpose, filesharing enabled")
set(KF5_PURPOSE TRUE)
else()
message(STATUS "KF5 Purpose not found, filesharing disabled")
endif()
# Search MLT package.
find_package(MLT ${MLT_MIN_VERSION} REQUIRED)
set_package_properties(MLT PROPERTIES
......
......@@ -301,6 +301,11 @@ endif()
target_link_libraries(kdenlive Qt5::Script Qt5::Widgets Qt5::Concurrent Qt5::Qml Qt5::Quick)
if (KF5_PURPOSE)
add_definitions(-DKF5_USE_PURPOSE)
target_link_libraries(kdenlive KF5::Purpose KF5::PurposeWidgets)
endif()
if (Qt5WebKitWidgets_FOUND)
message(STATUS "Found Qt5 WebKitWidgets. You can use your Freesound.org credentials to download files")
add_definitions(-DQT5_USE_WEBKIT)
......
......@@ -51,6 +51,15 @@
#include <QStandardPaths>
#include <QMimeDatabase>
#include <QDir>
#include <QTreeWidgetItem>
#include <QJsonObject>
#include <QJsonArray>
#ifdef KF5_USE_PURPOSE
#include <Purpose/AlternativesModel>
#include <PurposeWidgets/Menu>
#endif
#include <locale>
#ifdef Q_OS_MAC
......@@ -232,6 +241,11 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, const
m_infoMessage->setCloseButtonVisible(false);
m_infoMessage->hide();
m_jobInfoMessage = new KMessageWidget;
m_view.jobInfo->addWidget(m_jobInfoMessage);
m_jobInfoMessage->setCloseButtonVisible(false);
m_jobInfoMessage->hide();
m_view.encoder_threads->setMaximum(QThread::idealThreadCount());
m_view.encoder_threads->setValue(KdenliveSettings::encodethreads());
connect(m_view.encoder_threads, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateEncodeThreads(int)));
......@@ -337,11 +351,42 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, const
if (!interface || (!interface->isServiceRegistered(QStringLiteral("org.kde.ksmserver")) && !interface->isServiceRegistered(QStringLiteral("org.gnome.SessionManager")))) {
m_view.shutdown->setEnabled(false);
}
#ifdef KF5_USE_PURPOSE
m_shareMenu = new Purpose::Menu();
m_view.shareButton->setMenu(m_shareMenu);
m_view.shareButton->setIcon( KoIconUtils::themedIcon(QStringLiteral("document-share")));
connect(m_shareMenu, &Purpose::Menu::finished, this, &RenderWidget::slotShareActionFinished);
#else
m_view.shareButton->setEnabled(false);
#endif
refreshView();
focusFirstVisibleItem();
adjustSize();
}
void RenderWidget::slotShareActionFinished(const QJsonObject &output, int error, const QString &message)
{
#ifdef KF5_USE_PURPOSE
m_jobInfoMessage->hide();
if (error) {
KMessageBox::error(this, i18n("There was a problem sharing the document: %1", message),
i18n("Share"));
} else {
const QString url = output["url"].toString();
if (url.isEmpty()) {
m_jobInfoMessage->setMessageType(KMessageWidget::Positive);
m_jobInfoMessage->setText(i18n("Document shared successfully"));
m_jobInfoMessage->show();
} else {
KMessageBox::information(this, i18n("You can find the shared document at: <a href=\"%1\">%1</a>", url),
i18n("Share"), QString(),
KMessageBox::Notify | KMessageBox::AllowLink);
}
}
#endif
}
QSize RenderWidget::sizeHint() const
{
// Make sure the widget has minimum size on opening
......@@ -357,6 +402,7 @@ RenderWidget::~RenderWidget()
delete m_jobsDelegate;
delete m_scriptsDelegate;
delete m_infoMessage;
delete m_jobInfoMessage;
}
void RenderWidget::slotEditItem(QTreeWidgetItem *item)
......@@ -2207,6 +2253,12 @@ void RenderWidget::setRenderStatus(const QString &dest, int status, const QStrin
est.append(when.toString(QStringLiteral("hh:mm:ss")));
QString t = i18n("Rendering finished in %1", est);
item->setData(1, Qt::UserRole, t);
#ifdef KF5_USE_PURPOSE
m_shareMenu->model()->setInputData(QJsonObject{ {QStringLiteral("mimeType"), QMimeDatabase().mimeTypeForFile(item->text(1)).name()}, {QStringLiteral("urls"), QJsonArray({item->text(1)})}});
m_shareMenu->model()->setPluginType(QStringLiteral("Export"));
m_shareMenu->reload();
#endif
QString notif = i18n("Rendering of %1 finished in %2", item->text(1), est);
KNotification *notify = new KNotification(QStringLiteral("RenderFinished"));
notify->setText(notif);
......@@ -2276,6 +2328,16 @@ void RenderWidget::slotCheckJob()
m_view.start_job->setEnabled(current->status() == WAITINGJOB);
}
activate = true;
#ifdef KF5_USE_PURPOSE
if (current->status() == FINISHEDJOB) {
m_shareMenu->model()->setInputData(QJsonObject{ {QStringLiteral("mimeType"), QMimeDatabase().mimeTypeForFile(current->text(1)).name()}, {QStringLiteral("urls"), QJsonArray({current->text(1)})}});
m_shareMenu->model()->setPluginType(QStringLiteral("Export"));
m_shareMenu->reload();
m_view.shareButton->setEnabled(true);
} else {
m_view.shareButton->setEnabled(false);
}
#endif
}
m_view.abort_job->setEnabled(activate);
/*
......
......@@ -26,6 +26,10 @@
#include <QPainter>
#include <QStyledItemDelegate>
#ifdef KF5_USE_PURPOSE
namespace Purpose { class Menu; }
#endif
#include "definitions.h"
#include "ui_renderwidget_ui.h"
......@@ -198,6 +202,8 @@ private slots:
void adjustSpeed(int videoQuality);
/** @brief Display warning on proxy rendering. */
void slotProxyWarn(bool enableProxy);
/** @brief User shared a rendered file, give feedback. */
void slotShareActionFinished(const QJsonObject &output, int error, const QString &message);
private:
Ui::RenderWidget_UI m_view;
......@@ -208,8 +214,12 @@ private:
bool m_blockProcessing;
QString m_renderer;
KMessageWidget *m_infoMessage;
KMessageWidget *m_jobInfoMessage;
QMap<int, QString>m_errorMessages;
#ifdef KF5_USE_PURPOSE
Purpose::Menu *m_shareMenu;
#endif
void parseMltPresets();
void parseProfiles(const QString &selectedProfile = QString());
void parseFile(const QString &exportFile, bool editable);
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1504</width>
<height>816</height>
<width>1508</width>
<height>832</height>
</rect>
</property>
<property name="windowTitle">
......@@ -58,11 +58,7 @@
</widget>
</item>
<item>
<widget class="KUrlRequester" name="out_file">
<property name="mode">
<set>KFile::File|KFile::LocalOnly</set>
</property>
</widget>
<widget class="KUrlRequester" name="out_file"/>
</item>
</layout>
</item>
......@@ -765,34 +761,7 @@
<string>Job Queue</string>
</attribute>
<layout class="QGridLayout" name="gridLayout2">
<item row="2" column="3">
<spacer name="jobSpace">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="abort_job">
<property name="text">
<string>Abort Job</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="buttonClose2">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="5">
<item row="0" column="0" colspan="6">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -856,27 +825,73 @@
</widget>
</widget>
</item>
<item row="2" column="2">
<item row="3" column="3">
<spacer name="jobSpace">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="abort_job">
<property name="text">
<string>Abort Job</string>
</property>
</widget>
</item>
<item row="3" column="5">
<widget class="QPushButton" name="buttonClose2">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="clean_up">
<property name="text">
<string>Clean Up</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="5">
<item row="2" column="0" colspan="6">
<widget class="QCheckBox" name="shutdown">
<property name="text">
<string>Shutdown computer after renderings</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QPushButton" name="start_job">
<property name="text">
<string>Start Job</string>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QToolButton" name="shareButton">
<property name="text">
<string>Share</string>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="6">
<layout class="QHBoxLayout" name="jobInfo"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="scriptsTab">
......
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