diff --git a/src/app/GUI/RenderWidgets/renderwidget.cpp b/src/app/GUI/RenderWidgets/renderwidget.cpp index ecd688854..7c38bfcad 100644 --- a/src/app/GUI/RenderWidgets/renderwidget.cpp +++ b/src/app/GUI/RenderWidgets/renderwidget.cpp @@ -35,6 +35,8 @@ #include "../mainwindow.h" #include "../timelinedockwidget.h" +using namespace Friction; + RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) , mMainLayout(nullptr) @@ -48,6 +50,9 @@ RenderWidget::RenderWidget(QWidget *parent) , mScrollArea(nullptr) , mCurrentRenderedSettings(nullptr) , mState(RenderState::none) +#ifdef HAS_DBUS + , mUnity(nullptr) +#endif { mMainLayout = new QVBoxLayout(this); mMainLayout->setMargin(0); @@ -174,6 +179,20 @@ RenderWidget::RenderWidget(QWidget *parent) this, &RenderWidget::handleRenderFailed); connect(vidEmitter, &VideoEncoderEmitter::encodingStartFailed, this, &RenderWidget::sendNextForRender); + +#ifdef HAS_DBUS + mUnity = new Ui::UnityLauncherEntry(QStringLiteral("%1.desktop").arg(AppSupport::getAppID()), this); + connect(this, &RenderWidget::progress, + this, [this](int frame, int total) { + if (total > 0) { + const double currentProgress = static_cast(frame) / total; + mUnity->setProgress(currentProgress); + mUnity->setProgressVisible(frame < total); + } else { + mUnity->setProgressVisible(false); + } + }); +#endif } void RenderWidget::createNewRenderInstanceWidgetForCanvas(Canvas *canvas) diff --git a/src/app/GUI/RenderWidgets/renderwidget.h b/src/app/GUI/RenderWidgets/renderwidget.h index 1927fe9c8..15db65d9f 100644 --- a/src/app/GUI/RenderWidgets/renderwidget.h +++ b/src/app/GUI/RenderWidgets/renderwidget.h @@ -33,6 +33,10 @@ #include #include "renderinstancesettings.h" +#ifdef HAS_DBUS +#include "desktop/unitylauncherentry.h" +#endif + class ScrollArea; class Canvas; class RenderInstanceWidget; @@ -75,6 +79,10 @@ class RenderWidget : public QWidget QList mAwaitingSettings; RenderState mState; +#ifdef HAS_DBUS + Friction::Ui::UnityLauncherEntry *mUnity; +#endif + void handleRenderState(const RenderState &state); void handleRenderStarted(); void handleRenderFinished(); diff --git a/src/cmake/friction-common.cmake b/src/cmake/friction-common.cmake index 64b91d597..9f5140206 100644 --- a/src/cmake/friction-common.cmake +++ b/src/cmake/friction-common.cmake @@ -102,6 +102,12 @@ set(QT_LIBRARIES #Qt${QT_VERSION_MAJOR}::Svg ) +if(UNIX AND NOT APPLE) + find_package(Qt${QT_VERSION_MAJOR} COMPONENTS DBus REQUIRED) + list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::DBus) + add_definitions(-DHAS_DBUS) +endif() + if(WIN32) set(SKIA_LIBRARIES skia diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 87e26b119..033be02f1 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -42,6 +42,7 @@ include_directories( set( SOURCES + desktop/unitylauncherentry.cpp dialogs/adjustscenedialog.cpp dialogs/applyexpressiondialog.cpp dialogs/askdialog.cpp @@ -129,6 +130,7 @@ endif() set( HEADERS ui_global.h + desktop/unitylauncherentry.h dialogs/adjustscenedialog.h dialogs/applyexpressiondialog.h dialogs/askdialog.h diff --git a/src/ui/desktop/unitylauncherentry.cpp b/src/ui/desktop/unitylauncherentry.cpp new file mode 100644 index 000000000..4c2e28eda --- /dev/null +++ b/src/ui/desktop/unitylauncherentry.cpp @@ -0,0 +1,100 @@ +/* +# +# Friction - https://friction.graphics +# +# Copyright (c) Ole-André Rodlie and contributors +# +# 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, version 3. +# +# 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, see . +# +# See 'README.md' for more information. +# +*/ + +#include "unitylauncherentry.h" + +#ifdef HAS_DBUS +#include +#include +#endif + +using namespace Friction::Ui; + +UnityLauncherEntry::UnityLauncherEntry(const QString &desktopFileName, + QObject *parent) + : QObject(parent) + , mProgress(0.0) + , mProgressVisible(false) + , mCount(0) + , mCountVisible(false) + , mUrgent(false) +{ + mAppUri = QStringLiteral("application://%1").arg(desktopFileName); +} + +void UnityLauncherEntry::setProgress(double progress) +{ + const double clampedProgress = qBound(0.0, progress, 1.0); + if (qFuzzyCompare(mProgress, clampedProgress)) { return; } + + mProgress = clampedProgress; + sendUpdate(); +} + +void UnityLauncherEntry::setProgressVisible(bool visible) +{ + if (mProgressVisible == visible) { return; } + mProgressVisible = visible; + sendUpdate(); +} + +void UnityLauncherEntry::setCount(qint64 count) +{ + if (mCount == count) { return; } + mCount = count; + sendUpdate(); +} + +void UnityLauncherEntry::setCountVisible(bool visible) +{ + if (mCountVisible == visible) { return; } + mCountVisible = visible; + sendUpdate(); +} + +void UnityLauncherEntry::setUrgent(bool urgent) +{ + if (mUrgent == urgent) { return; } + mUrgent = urgent; + sendUpdate(); +} + +void UnityLauncherEntry::sendUpdate() +{ +#ifdef HAS_DBUS + QVariantMap properties; + properties.insert(QStringLiteral("progress"), mProgress); + properties.insert(QStringLiteral("progress-visible"), mProgressVisible); + properties.insert(QStringLiteral("count"), mCount); + properties.insert(QStringLiteral("count-visible"), mCountVisible); + properties.insert(QStringLiteral("urgent"), mUrgent); + + QDBusMessage message = QDBusMessage::createSignal( + QStringLiteral("/com/canonical/unity/launcherentry/1"), + QStringLiteral("com.canonical.Unity.LauncherEntry"), + QStringLiteral("Update") + ); + + message << mAppUri << properties; + QDBusConnection::sessionBus().send(message); +#endif +} diff --git a/src/ui/desktop/unitylauncherentry.h b/src/ui/desktop/unitylauncherentry.h new file mode 100644 index 000000000..846b4bfa2 --- /dev/null +++ b/src/ui/desktop/unitylauncherentry.h @@ -0,0 +1,62 @@ +/* +# +# Friction - https://friction.graphics +# +# Copyright (c) Ole-André Rodlie and contributors +# +# 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, version 3. +# +# 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, see . +# +# See 'README.md' for more information. +# +*/ + +#ifndef FRICTION_UNITY_LAUNCHER_ENTRY_H +#define FRICTION_UNITY_LAUNCHER_ENTRY_H + +#include "ui_global.h" + +#include +#include + +namespace Friction +{ + namespace Ui + { + class UI_EXPORT UnityLauncherEntry : public QObject + { + Q_OBJECT + public: + explicit UnityLauncherEntry(const QString &desktopFileName, + QObject *parent = nullptr); + + public slots: + void setProgress(double progress); + void setProgressVisible(bool visible); + void setCount(qint64 count); + void setCountVisible(bool visible); + void setUrgent(bool urgent); + + private: + void sendUpdate(); + + QString mAppUri; + double mProgress; + bool mProgressVisible; + qint64 mCount; + bool mCountVisible; + bool mUrgent; + }; + } +} + +#endif // FRICTION_UNITY_LAUNCHER_ENTRY_H