summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinfirit <[email protected]>2015-09-11 18:21:21 +0200
committerinfirit <[email protected]>2015-09-16 15:08:28 +0200
commita559f53de33bba182b8c751a25a7379803a23a3c (patch)
tree00dfba915f7c3e072ad1b617aafa179da24ce112
parent1bd759eb09dd59ff6ed30d528966d4899e06ea79 (diff)
downloadmate-polkit-a559f53de33bba182b8c751a25a7379803a23a3c.tar.bz2
mate-polkit-a559f53de33bba182b8c751a25a7379803a23a3c.tar.xz
Add support for application indicators
Patch by Jan Arne Petersen taken from https://bugzilla.gnome.org/show_bug.cgi?id=609680
-rw-r--r--configure.ac25
-rw-r--r--src/Makefile.am2
-rw-r--r--src/main.c53
3 files changed, 80 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 6553cb9..852bb11 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,6 +123,7 @@ MATE_MAINTAINER_MODE_DEFINES
GLIB_REQUIRED=2.36.0
POLKIT_AGENT_REQUIRED=0.97
POLKIT_GOBJECT_REQUIRED=0.97
+APPINDICATOR_REQUIRED=0.0.13
AC_MSG_CHECKING([which gtk+ version to compile against])
AC_ARG_WITH([gtk],
@@ -164,6 +165,29 @@ AC_ARG_ENABLE([accountsservice],
AM_CONDITIONAL([HAVE_ACCOUNTSSERVICE], [test "x$enable_accountsservice" = xyes])
+# Application indicator
+AC_ARG_ENABLE([appindicator],
+ AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators]),
+ [enable_appindicator=$enableval],
+ [enable_appindicator="auto"])
+
+
+if test "x$enable_appindicator" = "xauto"; then
+ PKG_CHECK_EXISTS(appindicator-0.1 >= $APPINDICATOR_REQUIRED,
+ [enable_appindicator="yes"],
+ [enable_appindicator="no"])
+fi
+
+if test "x$enable_appindicator" = "xyes"; then
+ PKG_CHECK_MODULES(APPINDICATOR,
+ [appindicator-0.1 >= $APPINDICATOR_REQUIRED],
+ [AC_DEFINE(HAVE_APPINDICATOR, 1, [Have AppIndicator])])
+fi
+
+AM_CONDITIONAL(HAVE_APPINDICATOR, test "x$enable_appindicator" = "xyes")
+AC_SUBST(APPINDICATOR_CFLAGS)
+AC_SUBST(APPINDICATOR_LIBS)
+
AC_ARG_ENABLE([examples],
AC_HELP_STRING([--enable-examples], [Build the example programs]),,
[enable_examples=yes])
@@ -240,6 +264,7 @@ echo "
Gtk+ version: ${GTK_API_VERSION}
Accountsservice: ${enable_accountsservice}
+ Application indciator: ${enable_appindicator}
Maintainer mode: ${USE_MAINTAINER_MODE}
Building api docs: ${enable_gtk_doc}
GObject Introspection: ${enable_introspection}
diff --git a/src/Makefile.am b/src/Makefile.am
index eb2fcfc..93f17f9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,7 @@ polkit_mate_authentication_agent_1_CFLAGS = \
$(GLIB_CFLAGS) \
$(POLKIT_AGENT_CFLAGS) \
$(POLKIT_GOBJECT_CFLAGS) \
+ $(APPINDICATOR_CFLAGS) \
$(WARN_CFLAGS) \
$(AM_CFLAGS)
@@ -44,6 +45,7 @@ polkit_mate_authentication_agent_1_LDADD = \
$(GLIB_LIBS) \
$(POLKIT_AGENT_LIBS) \
$(POLKIT_GOBJECT_LIBS) \
+ $(APPINDICATOR_LIBS) \
$(INTLLIBS)
EXTRA_DIST = \
diff --git a/src/main.c b/src/main.c
index d3fa136..e889a52 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,10 @@
#include <glib/gi18n.h>
#include <polkitagent/polkitagent.h>
+#ifdef HAVE_APPINDICATOR
+#include <libappindicator/app-indicator.h>
+#endif
+
#include "polkitmatelistener.h"
/* session management support for auto-restart */
@@ -47,7 +51,11 @@ static PolkitSubject *session = NULL;
/* the current set of temporary authorizations */
static GList *current_temporary_authorizations = NULL;
+#ifdef HAVE_APPINDICATOR
+static AppIndicator *app_indicator = NULL;
+#else
static GtkStatusIcon *status_icon = NULL;
+#endif
static GDBusProxy *sm_proxy;
static GDBusProxy *client_proxy = NULL;
@@ -82,6 +90,14 @@ revoke_tmp_authz (void)
NULL);
}
+#ifdef HAVE_APPINDICATOR
+static void
+on_menu_item_activate (GtkMenuItem *menu_item,
+ gpointer user_data)
+{
+ revoke_tmp_authz ();
+}
+#else
static void
on_status_icon_activate (GtkStatusIcon *status_icon,
gpointer user_data)
@@ -97,6 +113,7 @@ on_status_icon_popup_menu (GtkStatusIcon *status_icon,
{
revoke_tmp_authz ();
}
+#endif
static void
update_temporary_authorization_icon_real (void)
@@ -134,6 +151,31 @@ update_temporary_authorization_icon_real (void)
if (current_temporary_authorizations != NULL)
{
/* show icon */
+#ifdef HAVE_APPINDICATOR
+ if (app_indicator == NULL)
+ {
+ GtkWidget *item, *menu;
+
+ app_indicator = app_indicator_new ("mate-polkit",
+ "gtk-dialog-authentication",
+ APP_INDICATOR_CATEGORY_SYSTEM_SERVICES);
+
+ item = gtk_menu_item_new_with_label (_("Drop all elevated privileges"));
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (on_menu_item_activate),
+ NULL);
+ menu = gtk_menu_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show_all (menu);
+
+ app_indicator_set_menu (app_indicator,
+ GTK_MENU (menu));
+ app_indicator_set_status (app_indicator,
+ APP_INDICATOR_STATUS_ACTIVE);
+ }
+
+#else
if (status_icon == NULL)
{
status_icon = gtk_status_icon_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION);
@@ -148,16 +190,27 @@ update_temporary_authorization_icon_real (void)
G_CALLBACK (on_status_icon_popup_menu),
NULL);
}
+#endif
}
else
{
/* hide icon */
+#ifdef HAVE_APPINDICATOR
+ if (app_indicator != NULL)
+ {
+ app_indicator_set_status (app_indicator,
+ APP_INDICATOR_STATUS_PASSIVE);
+ g_object_unref (app_indicator);
+ app_indicator = NULL;
+ }
+#else
if (status_icon != NULL)
{
gtk_status_icon_set_visible (status_icon, FALSE);
g_object_unref (status_icon);
status_icon = NULL;
}
+#endif
}
}