Skip to content

Commit ed8b446

Browse files
committed
Initial support for Unity Launcher API
1 parent c0cdc5d commit ed8b446

6 files changed

Lines changed: 197 additions & 0 deletions

File tree

src/app/GUI/RenderWidgets/renderwidget.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "../mainwindow.h"
3636
#include "../timelinedockwidget.h"
3737

38+
using namespace Friction;
39+
3840
RenderWidget::RenderWidget(QWidget *parent)
3941
: QWidget(parent)
4042
, mMainLayout(nullptr)
@@ -48,6 +50,9 @@ RenderWidget::RenderWidget(QWidget *parent)
4850
, mScrollArea(nullptr)
4951
, mCurrentRenderedSettings(nullptr)
5052
, mState(RenderState::none)
53+
#ifdef HAS_DBUS
54+
, mUnity(nullptr)
55+
#endif
5156
{
5257
mMainLayout = new QVBoxLayout(this);
5358
mMainLayout->setMargin(0);
@@ -174,6 +179,20 @@ RenderWidget::RenderWidget(QWidget *parent)
174179
this, &RenderWidget::handleRenderFailed);
175180
connect(vidEmitter, &VideoEncoderEmitter::encodingStartFailed,
176181
this, &RenderWidget::sendNextForRender);
182+
183+
#ifdef HAS_DBUS
184+
mUnity = new Ui::UnityLauncherEntry(QStringLiteral("%1.desktop").arg(AppSupport::getAppID()), this);
185+
connect(this, &RenderWidget::progress,
186+
this, [this](int frame, int total) {
187+
if (total > 0) {
188+
const double currentProgress = static_cast<double>(frame) / total;
189+
mUnity->setProgress(currentProgress);
190+
mUnity->setProgressVisible(frame < total);
191+
} else {
192+
mUnity->setProgressVisible(false);
193+
}
194+
});
195+
#endif
177196
}
178197

179198
void RenderWidget::createNewRenderInstanceWidgetForCanvas(Canvas *canvas)

src/app/GUI/RenderWidgets/renderwidget.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include <QPushButton>
3434
#include "renderinstancesettings.h"
3535

36+
#ifdef HAS_DBUS
37+
#include "desktop/unitylauncherentry.h"
38+
#endif
39+
3640
class ScrollArea;
3741
class Canvas;
3842
class RenderInstanceWidget;
@@ -75,6 +79,10 @@ class RenderWidget : public QWidget
7579
QList<RenderInstanceWidget*> mAwaitingSettings;
7680
RenderState mState;
7781

82+
#ifdef HAS_DBUS
83+
Friction::Ui::UnityLauncherEntry *mUnity;
84+
#endif
85+
7886
void handleRenderState(const RenderState &state);
7987
void handleRenderStarted();
8088
void handleRenderFinished();

src/cmake/friction-common.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ set(QT_LIBRARIES
102102
#Qt${QT_VERSION_MAJOR}::Svg
103103
)
104104

105+
if(UNIX AND NOT APPLE)
106+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS DBus REQUIRED)
107+
list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::DBus)
108+
add_definitions(-DHAS_DBUS)
109+
endif()
110+
105111
if(WIN32)
106112
set(SKIA_LIBRARIES
107113
skia

src/ui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ include_directories(
4242

4343
set(
4444
SOURCES
45+
desktop/unitylauncherentry.cpp
4546
dialogs/adjustscenedialog.cpp
4647
dialogs/applyexpressiondialog.cpp
4748
dialogs/askdialog.cpp
@@ -129,6 +130,7 @@ endif()
129130
set(
130131
HEADERS
131132
ui_global.h
133+
desktop/unitylauncherentry.h
132134
dialogs/adjustscenedialog.h
133135
dialogs/applyexpressiondialog.h
134136
dialogs/askdialog.h
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
#
3+
# Friction - https://friction.graphics
4+
#
5+
# Copyright (c) Ole-André Rodlie and contributors
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, version 3.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
# See 'README.md' for more information.
20+
#
21+
*/
22+
23+
#include "unitylauncherentry.h"
24+
25+
#ifdef HAS_DBUS
26+
#include <QDBusMessage>
27+
#include <QDBusConnection>
28+
#endif
29+
30+
using namespace Friction::Ui;
31+
32+
UnityLauncherEntry::UnityLauncherEntry(const QString &desktopFileName,
33+
QObject *parent)
34+
: QObject(parent)
35+
, mProgress(0.0)
36+
, mProgressVisible(false)
37+
, mCount(0)
38+
, mCountVisible(false)
39+
, mUrgent(false)
40+
{
41+
mAppUri = QStringLiteral("application://%1").arg(desktopFileName);
42+
}
43+
44+
void UnityLauncherEntry::setProgress(double progress)
45+
{
46+
const double clampedProgress = qBound(0.0, progress, 1.0);
47+
if (qFuzzyCompare(mProgress, clampedProgress)) { return; }
48+
49+
mProgress = clampedProgress;
50+
sendUpdate();
51+
}
52+
53+
void UnityLauncherEntry::setProgressVisible(bool visible)
54+
{
55+
if (mProgressVisible == visible) { return; }
56+
mProgressVisible = visible;
57+
sendUpdate();
58+
}
59+
60+
void UnityLauncherEntry::setCount(qint64 count)
61+
{
62+
if (mCount == count) { return; }
63+
mCount = count;
64+
sendUpdate();
65+
}
66+
67+
void UnityLauncherEntry::setCountVisible(bool visible)
68+
{
69+
if (mCountVisible == visible) { return; }
70+
mCountVisible = visible;
71+
sendUpdate();
72+
}
73+
74+
void UnityLauncherEntry::setUrgent(bool urgent)
75+
{
76+
if (mUrgent == urgent) { return; }
77+
mUrgent = urgent;
78+
sendUpdate();
79+
}
80+
81+
void UnityLauncherEntry::sendUpdate()
82+
{
83+
#ifdef HAS_DBUS
84+
QVariantMap properties;
85+
properties.insert(QStringLiteral("progress"), mProgress);
86+
properties.insert(QStringLiteral("progress-visible"), mProgressVisible);
87+
properties.insert(QStringLiteral("count"), mCount);
88+
properties.insert(QStringLiteral("count-visible"), mCountVisible);
89+
properties.insert(QStringLiteral("urgent"), mUrgent);
90+
91+
QDBusMessage message = QDBusMessage::createSignal(
92+
QStringLiteral("/com/canonical/unity/launcherentry/1"),
93+
QStringLiteral("com.canonical.Unity.LauncherEntry"),
94+
QStringLiteral("Update")
95+
);
96+
97+
message << mAppUri << properties;
98+
QDBusConnection::sessionBus().send(message);
99+
#endif
100+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
#
3+
# Friction - https://friction.graphics
4+
#
5+
# Copyright (c) Ole-André Rodlie and contributors
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, version 3.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
# See 'README.md' for more information.
20+
#
21+
*/
22+
23+
#ifndef FRICTION_UNITY_LAUNCHER_ENTRY_H
24+
#define FRICTION_UNITY_LAUNCHER_ENTRY_H
25+
26+
#include "ui_global.h"
27+
28+
#include <QObject>
29+
#include <QString>
30+
31+
namespace Friction
32+
{
33+
namespace Ui
34+
{
35+
class UI_EXPORT UnityLauncherEntry : public QObject
36+
{
37+
Q_OBJECT
38+
public:
39+
explicit UnityLauncherEntry(const QString &desktopFileName,
40+
QObject *parent = nullptr);
41+
42+
public slots:
43+
void setProgress(double progress);
44+
void setProgressVisible(bool visible);
45+
void setCount(qint64 count);
46+
void setCountVisible(bool visible);
47+
void setUrgent(bool urgent);
48+
49+
private:
50+
void sendUpdate();
51+
52+
QString mAppUri;
53+
double mProgress;
54+
bool mProgressVisible;
55+
qint64 mCount;
56+
bool mCountVisible;
57+
bool mUrgent;
58+
};
59+
}
60+
}
61+
62+
#endif // FRICTION_UNITY_LAUNCHER_ENTRY_H

0 commit comments

Comments
 (0)