|
| 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 | +} |
0 commit comments