[gnome-applets] inhibit: port to GDBus
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets] inhibit: port to GDBus
- Date: Sun, 23 Aug 2015 23:01:25 +0000 (UTC)
commit 30ef1961f0ec022822d799807af799e812ab9643
Author: Balló György <ballogyor gmail com>
Date: Mon Aug 17 00:20:40 2015 +0200
inhibit: port to GDBus
inhibit/Makefile.am | 19 +++++-
inhibit/inhibit-applet.c | 58 ++++++++-----------
inhibit/org.gnome.SessionManager.xml | 102 ++++++++++++++++++++++++++++++++++
3 files changed, 142 insertions(+), 37 deletions(-)
---
diff --git a/inhibit/Makefile.am b/inhibit/Makefile.am
index c50c33b..c260898 100644
--- a/inhibit/Makefile.am
+++ b/inhibit/Makefile.am
@@ -5,19 +5,27 @@ AM_CPPFLAGS = \
-I$(srcdir) \
-DINHIBIT_MENU_UI_DIR=\""$(uidir)"\" \
$(GNOME_APPLETS_CFLAGS) \
- $(DBUS_CFLAGS) \
$(WARN_CFLAGS) \
$(NULL)
libexec_PROGRAMS=gnome-inhibit-applet
gnome_inhibit_applet_SOURCES = \
+ dbus-inhibit.h \
+ dbus-inhibit.c \
inhibit-applet.c
gnome_inhibit_applet_LDADD = \
- $(DBUS_LIBS) \
$(GNOME_APPLETS_LIBS)
+dbus-inhibit.h:
+dbus-inhibit.c: org.gnome.SessionManager.xml Makefile.am
+ $(AM_V_GEN) gdbus-codegen \
+ --interface-prefix=org.gnome. \
+ --generate-c-code dbus-inhibit \
+ --c-namespace DBus \
+ org.gnome.SessionManager.xml
+
appletdir = $(LIBPANEL_APPLET_DIR)
applet_in_files = org.gnome.InhibitApplet.panel-applet.in
applet_DATA = $(applet_in_files:.panel-applet.in=.panel-applet)
@@ -42,7 +50,12 @@ org.gnome.panel.applet.InhibitAppletFactory.service: $(service_in_files)
uidir = $(pkgdatadir)/ui
ui_DATA = inhibit-applet-menu.xml
-CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA)
+BUILT_SOURCES = \
+ dbus-inhibit.c \
+ dbus-inhibit.h \
+ $(NULL)
+
+CLEANFILES = $(applet_DATA) $(applet_DATA).in $(BUILT_SOURCES) $(service_DATA)
EXTRA_DIST = \
org.gnome.InhibitApplet.panel-applet.in.in \
diff --git a/inhibit/inhibit-applet.c b/inhibit/inhibit-applet.c
index 9525dec..a76b658 100644
--- a/inhibit/inhibit-applet.c
+++ b/inhibit/inhibit-applet.c
@@ -32,7 +32,8 @@
#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
+
+#include "dbus-inhibit.h"
#define GPM_TYPE_INHIBIT_APPLET (gpm_inhibit_applet_get_type ())
#define GPM_INHIBIT_APPLET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_INHIBIT_APPLET,
GpmInhibitApplet))
@@ -48,8 +49,7 @@ typedef struct{
/* the icon */
GtkWidget *image;
/* connection to gnome-session */
- DBusGProxy *proxy;
- DBusGConnection *connection;
+ DBusSessionManager *proxy;
guint bus_watch_id;
guint level;
} GpmInhibitApplet;
@@ -62,7 +62,6 @@ GType gpm_inhibit_applet_get_type (void);
#define GS_DBUS_SERVICE "org.gnome.SessionManager"
#define GS_DBUS_PATH "/org/gnome/SessionManager"
-#define GS_DBUS_INTERFACE "org.gnome.SessionManager"
static void gpm_inhibit_applet_class_init (GpmInhibitAppletClass *klass);
static void gpm_inhibit_applet_init (GpmInhibitApplet *applet);
@@ -106,14 +105,14 @@ gpm_applet_inhibit (GpmInhibitApplet *applet,
return FALSE;
}
- ret = dbus_g_proxy_call (applet->proxy, "Inhibit", &error,
- G_TYPE_STRING, appname,
- G_TYPE_UINT, 0, /* xid */
- G_TYPE_STRING, reason,
- G_TYPE_UINT, 1+2+4+8, /* logoff, switch, suspend, and idle */
- G_TYPE_INVALID,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID);
+ ret = dbus_session_manager_call_inhibit_sync (applet->proxy,
+ appname,
+ 0, /* xid */
+ reason,
+ 1+2+4+8, /* logoff, switch, suspend, and idle */
+ cookie,
+ NULL,
+ &error);
if (error) {
g_debug ("ERROR: %s", error->message);
g_error_free (error);
@@ -139,10 +138,10 @@ gpm_applet_uninhibit (GpmInhibitApplet *applet,
return FALSE;
}
- ret = dbus_g_proxy_call (applet->proxy, "Uninhibit", &error,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ ret = dbus_session_manager_call_uninhibit_sync (applet->proxy,
+ cookie,
+ NULL,
+ &error);
if (error) {
g_debug ("ERROR: %s", error->message);
g_error_free (error);
@@ -190,7 +189,7 @@ gpm_applet_size_allocate_cb (GtkWidget *widget,
GdkRectangle *allocation)
{
GpmInhibitApplet *applet = GPM_INHIBIT_APPLET (widget);
- int size;
+ int size = NULL;
switch (panel_applet_get_orient (PANEL_APPLET (applet))) {
case PANEL_APPLET_ORIENT_LEFT:
@@ -365,25 +364,15 @@ gpm_inhibit_applet_dbus_connect (GpmInhibitApplet *applet)
{
GError *error = NULL;
- if (applet->connection == NULL) {
- g_debug ("get connection\n");
- g_clear_error (&error);
- applet->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (error != NULL) {
- g_warning ("Could not connect to DBUS daemon: %s", error->message);
- g_error_free (error);
- applet->connection = NULL;
- return FALSE;
- }
- }
if (applet->proxy == NULL) {
g_debug ("get proxy\n");
g_clear_error (&error);
- applet->proxy = dbus_g_proxy_new_for_name_owner (applet->connection,
- GS_DBUS_SERVICE,
- GS_DBUS_PATH,
- GS_DBUS_INTERFACE,
- &error);
+ applet->proxy = dbus_session_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ GS_DBUS_SERVICE,
+ GS_DBUS_PATH,
+ NULL,
+ &error);
if (error != NULL) {
g_warning ("Cannot connect, maybe the daemon is not running: %s\n", error->message);
g_error_free (error);
@@ -442,7 +431,6 @@ gpm_inhibit_applet_init (GpmInhibitApplet *applet)
/* initialize fields */
applet->image = NULL;
applet->cookie = 0;
- applet->connection = NULL;
applet->proxy = NULL;
/* Add application specific icons to search path */
@@ -499,6 +487,8 @@ gpm_applet_cb (PanelApplet *_applet, const gchar *iid, gpointer data)
return FALSE;
}
+ gtk_window_set_default_icon_name (GPM_INHIBIT_APPLET_ICON);
+
action_group = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (action_group),
menu_actions,
diff --git a/inhibit/org.gnome.SessionManager.xml b/inhibit/org.gnome.SessionManager.xml
new file mode 100644
index 0000000..2f17448
--- /dev/null
+++ b/inhibit/org.gnome.SessionManager.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
+ <interface name="org.gnome.SessionManager">
+
+ <!-- Running phase interfaces -->
+
+ <method name="Inhibit">
+ <arg type="s" name="app_id" direction="in">
+ <doc:doc>
+ <doc:summary>The application identifier</doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="u" name="toplevel_xid" direction="in">
+ <doc:doc>
+ <doc:summary>The toplevel X window identifier</doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="s" name="reason" direction="in">
+ <doc:doc>
+ <doc:summary>The reason for the inhibit</doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="u" name="flags" direction="in">
+ <doc:doc>
+ <doc:summary>Flags that specify what should be inhibited</doc:summary>
+ </doc:doc>
+ </arg>
+ <arg type="u" name="inhibit_cookie" direction="out">
+ <doc:doc>
+ <doc:summary>The cookie</doc:summary>
+ </doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:summary>
+ Proactively indicates that the calling application is performing an action that should not be
interrupted and sets a reason to be displayed to the user when an interruption is about to take placea.
+ </doc:summary>
+ <doc:description>
+ <doc:para>Applications should invoke this method when they begin an operation that
+ should not be interrupted, such as creating a CD or DVD. The types of actions
+ that may be blocked are specified by the flags parameter. When the application
+ completes the operation it should call <doc:ref type="method"
to="org.gnome.SessionManager.Uninhibit">Uninhibit()</doc:ref>
+ or disconnect from the session bus.
+ </doc:para>
+ <doc:para>
+ Applications should not expect that they will always be able to block the
+ action. In most cases, users will be given the option to force the action
+ to take place.
+ </doc:para>
+ <doc:para>
+ Reasons should be short and to the point.
+ </doc:para>
+ <doc:para>
+ The flags parameter must include at least one of the following:
+ <doc:list>
+ <doc:item>
+ <doc:term>1</doc:term>
+ <doc:definition>Inhibit logging out</doc:definition>
+ </doc:item>
+ <doc:item>
+ <doc:term>2</doc:term>
+ <doc:definition>Inhibit user switching</doc:definition>
+ </doc:item>
+ <doc:item>
+ <doc:term>4</doc:term>
+ <doc:definition>Inhibit suspending the session or computer</doc:definition>
+ </doc:item>
+ <doc:item>
+ <doc:term>8</doc:term>
+ <doc:definition>Inhibit the session being marked as idle</doc:definition>
+ </doc:item>
+ <doc:item>
+ <doc:term>16</doc:term>
+ <doc:definition>Inhibit auto-mounting removable media for the session</doc:definition>
+ </doc:item>
+ </doc:list>
+ Values for flags may be bitwise or'ed together.
+ </doc:para>
+ <doc:para>
+ The returned cookie is used to uniquely identify this request. It should be used
+ as an argument to <doc:ref type="method"
to="org.gnome.SessionManager.Uninhibit">Uninhibit()</doc:ref> in
+ order to remove the request.
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ </method>
+
+ <method name="Uninhibit">
+ <arg type="u" name="inhibit_cookie" direction="in">
+ <doc:doc>
+ <doc:summary>The cookie</doc:summary>
+ </doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:description>
+ <doc:para>Cancel a previous call to <doc:ref type="method"
to="org.gnome.SessionManager.Inhibit">Inhibit()</doc:ref> identified by the cookie.</doc:para>
+ </doc:description>
+ </doc:doc>
+ </method>
+
+ </interface>
+</node>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]