Skip to content

Commit

Permalink
[FEATURE][native] Add badge count support for the linux platform
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Sep 7, 2018
1 parent 1002824 commit 5030121
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1335,6 +1335,10 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
{
QgsGui::instance()->nativePlatformInterface()->hideApplicationProgress();
} );
connect( QgsApplication::taskManager(), &QgsTaskManager::countActiveTasksChanged, this, []( int count )
{
QgsGui::instance()->nativePlatformInterface()->setApplicationBadgeCount( count );
} );

if ( !( QgsGui::nativePlatformInterface()->capabilities() & QgsNative::NativeDesktopNotifications ) )
{
Expand Down
16 changes: 16 additions & 0 deletions src/native/linux/qgslinuxnative.cpp
Expand Up @@ -102,6 +102,22 @@ void QgsLinuxNative::hideApplicationProgress()
QDBusConnection::sessionBus().send( message );
}

void QgsLinuxNative::setApplicationBadgeCount( int count )
{
// the badge will only be shown when the count is greater than one
const QVariantMap properties
{
{ QStringLiteral( "count-visible" ), count > 1 },
{ QStringLiteral( "count" ), static_cast< long long >( count ) }
};

QDBusMessage message = QDBusMessage::createSignal( QStringLiteral( "/org/qgis/UnityLauncher" ),
QStringLiteral( "com.canonical.Unity.LauncherEntry" ),
QStringLiteral( "Update" ) );
message.setArguments( {mDesktopFile, properties} );
QDBusConnection::sessionBus().send( message );
}

/**
* Automatic marshaling of a QImage for org.freedesktop.Notifications.Notify
*
Expand Down
1 change: 1 addition & 0 deletions src/native/linux/qgslinuxnative.h
Expand Up @@ -42,6 +42,7 @@ class NATIVE_EXPORT QgsLinuxNative : public QgsNative
void showUndefinedApplicationProgress() override;
void setApplicationProgress( double progress ) override;
void hideApplicationProgress() override;
void setApplicationBadgeCount( int count ) override;
NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings = NotificationSettings() ) override;
private:
QString mDesktopFile;
Expand Down
5 changes: 5 additions & 0 deletions src/native/qgsnative.cpp
Expand Up @@ -63,6 +63,11 @@ void QgsNative::hideApplicationProgress()

}

void QgsNative::setApplicationBadgeCount( int )
{

}

QgsNative::NotificationResult QgsNative::showDesktopNotification( const QString &, const QString &, const NotificationSettings & )
{
NotificationResult result;
Expand Down
7 changes: 7 additions & 0 deletions src/native/qgsnative.h
Expand Up @@ -124,6 +124,13 @@ class NATIVE_EXPORT QgsNative
*/
virtual void hideApplicationProgress();

/**
* Shows an application badge count.
*
* The default implementation does nothing.
* \since QGIS 3.4
*/
virtual void setApplicationBadgeCount( int count );

/**
* Notification settings, for use with showDesktopNotification().
Expand Down

0 comments on commit 5030121

Please sign in to comment.