summaryrefslogtreecommitdiff
path: root/applets/inhibit/inhibit-applet.c
diff options
context:
space:
mode:
Diffstat (limited to 'applets/inhibit/inhibit-applet.c')
-rw-r--r--applets/inhibit/inhibit-applet.c200
1 files changed, 60 insertions, 140 deletions
diff --git a/applets/inhibit/inhibit-applet.c b/applets/inhibit/inhibit-applet.c
index eae73fd..93c67aa 100644
--- a/applets/inhibit/inhibit-applet.c
+++ b/applets/inhibit/inhibit-applet.c
@@ -22,12 +22,9 @@
*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
#endif
-/* FIXME: gdk_gc_* needs porting to cairo */
-#undef GDK_DISABLE_DEPRECATED
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -36,10 +33,8 @@
#include <glib-object.h>
#include <glib/gi18n.h>
#include <dbus/dbus-glib.h>
-#include <libmate-desktop/mate-aboutdialog.h>
#include "egg-debug.h"
-#include "egg-dbus-monitor.h"
#include "gpm-common.h"
#define GPM_TYPE_INHIBIT_APPLET (gpm_inhibit_applet_get_type ())
@@ -49,10 +44,6 @@
#define GPM_IS_INHIBIT_APPLET_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_INHIBIT_APPLET))
#define GPM_INHIBIT_APPLET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_INHIBIT_APPLET, GpmInhibitAppletClass))
-#if GTK_CHECK_VERSION (3, 0, 0)
-#define GtkObject GtkWidget
-#endif
-
typedef struct{
MatePanelApplet parent;
/* applet state */
@@ -63,7 +54,7 @@ typedef struct{
/* connection to g-p-m */
DBusGProxy *proxy;
DBusGConnection *connection;
- EggDbusMonitor *monitor;
+ guint bus_watch_id;
guint level;
/* a cache for panel size */
gint size;
@@ -75,9 +66,9 @@ typedef struct{
GType gpm_inhibit_applet_get_type (void);
-#define GS_DBUS_SERVICE "org.mate.SessionManager"
-#define GS_DBUS_PATH "/org/mate/SessionManager"
-#define GS_DBUS_INTERFACE "org.mate.SessionManager"
+#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);
@@ -91,7 +82,7 @@ static void gpm_applet_update_tooltip (GpmInhibitApplet *applet);
static gboolean gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event);
static void gpm_applet_dialog_about_cb (GtkAction *action, gpointer data);
static gboolean gpm_applet_cb (MatePanelApplet *_applet, const gchar *iid, gpointer data);
-static void gpm_applet_destroy_cb (GtkObject *object);
+static void gpm_applet_destroy_cb (GtkWidget *widget);
#define GPM_INHIBIT_APPLET_ID "InhibitApplet"
#define GPM_INHIBIT_APPLET_FACTORY_ID "InhibitAppletFactory"
@@ -169,37 +160,6 @@ gpm_applet_uninhibit (GpmInhibitApplet *applet,
return ret;
}
-#if 0
-static gboolean
-gpm_applet_has_inhibit (GpmInhibitApplet *applet,
- gboolean *has_inhibit)
-{
- GError *error = NULL;
- gboolean ret;
- DBusGProxy *proxy;
-
- proxy = egg_dbus_proxy_get_proxy (applet->gproxy);
- if (proxy == NULL) {
- g_warning ("not connected");
- return FALSE;
- }
-
- ret = dbus_g_proxy_call (proxy, "HasInhibit", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, has_inhibit,
- G_TYPE_INVALID);
- if (error) {
- g_debug ("ERROR: %s", error->message);
- g_error_free (error);
- }
- if (!ret) {
- /* abort as the DBUS method failed */
- g_warning ("HasInhibit failed!");
- }
-
- return ret;
-}
-#endif
/**
* gpm_applet_get_icon:
@@ -288,27 +248,16 @@ static gboolean
gpm_applet_draw_cb (GpmInhibitApplet *applet)
{
gint w, h, bg_type;
-#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA color;
cairo_t *cr;
cairo_pattern_t *pattern;
GtkStyleContext *context;
-#else
- GdkColor color;
- GdkGC *gc;
- GdkPixmap *background;
-#endif
GtkAllocation allocation;
if (gtk_widget_get_window (GTK_WIDGET(applet)) == NULL) {
return FALSE;
}
-#if !GTK_CHECK_VERSION (3, 0, 0)
- /* Clear the window so we can draw on it later */
- gdk_window_clear(gtk_widget_get_window (GTK_WIDGET (applet)));
-#endif
-
/* retrieve applet size */
gpm_applet_get_icon (applet);
gpm_applet_check_size (applet);
@@ -325,58 +274,29 @@ gpm_applet_draw_cb (GpmInhibitApplet *applet)
w = allocation.width;
h = allocation.height;
-#if GTK_CHECK_VERSION (3, 0, 0)
cr = gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET(applet)));
-#else
- gc = gdk_gc_new (gtk_widget_get_window (GTK_WIDGET(applet)));
-#endif
/* draw pixmap background */
-#if GTK_CHECK_VERSION (3, 0, 0)
bg_type = mate_panel_applet_get_background (MATE_PANEL_APPLET (applet), &color, &pattern);
-#else
- bg_type = mate_panel_applet_get_background (MATE_PANEL_APPLET (applet), &color, &background);
-#endif
if (bg_type == PANEL_PIXMAP_BACKGROUND) {
/* fill with given background pixmap */
-#if GTK_CHECK_VERSION (3, 0, 0)
cairo_set_source (cr, pattern);
cairo_rectangle (cr, 0, 0, w, h);
cairo_fill (cr);
-#else
- gdk_draw_drawable (gtk_widget_get_window (GTK_WIDGET(applet)), gc, background, 0, 0, 0, 0, w, h);
-#endif
}
/* draw color background */
if (bg_type == PANEL_COLOR_BACKGROUND) {
-#if GTK_CHECK_VERSION (3, 0, 0)
gdk_cairo_set_source_rgba (cr, &color);
cairo_rectangle (cr, 0, 0, w, h);
cairo_fill (cr);
-#else
- gdk_gc_set_rgb_fg_color (gc,&color);
- gdk_gc_set_fill (gc,GDK_SOLID);
- gdk_draw_rectangle (gtk_widget_get_window (GTK_WIDGET(applet)), gc, TRUE, 0, 0, w, h);
-#endif
}
/* draw icon at center */
-#if GTK_CHECK_VERSION (3, 0, 0)
gdk_cairo_set_source_pixbuf (cr, applet->icon, (w - applet->icon_width)/2, (h - applet->icon_height)/2);
cairo_paint (cr);
-#else
- gdk_draw_pixbuf (gtk_widget_get_window (GTK_WIDGET(applet)), gc, applet->icon,
- 0, 0, (w - applet->icon_width)/2, (h - applet->icon_height)/2,
- applet->icon_width, applet->icon_height,
- GDK_RGB_DITHER_NONE, 0, 0);
-#endif
-#if GTK_CHECK_VERSION (3, 0, 0)
cairo_destroy (cr);
-#else
- g_object_unref (gc);
-#endif
return TRUE;
}
@@ -389,11 +309,7 @@ gpm_applet_draw_cb (GpmInhibitApplet *applet)
static void
gpm_applet_change_background_cb (GpmInhibitApplet *applet,
MatePanelAppletBackgroundType arg1,
-#if GTK_CHECK_VERSION (3, 0, 0)
cairo_pattern_t *arg2,
-#else
- GdkColor *arg2, GdkPixmap *arg3,
-#endif
gpointer data)
{
gtk_widget_queue_draw (GTK_WIDGET (applet));
@@ -463,7 +379,7 @@ gpm_applet_click_cb (GpmInhibitApplet *applet, GdkEventButton *event)
static void
gpm_applet_dialog_about_cb (GtkAction *action, gpointer data)
{
- MateAboutDialog *about;
+ GtkAboutDialog *about;
GdkPixbuf *logo =
gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
@@ -475,6 +391,11 @@ gpm_applet_dialog_about_cb (GtkAction *action, gpointer data)
"Richard Hughes <[email protected]>",
NULL
};
+
+ char copyright[] = \
+ "Copyright \xc2\xa9 2012-2016 MATE developers\n"
+ "Copyright \xc2\xa9 2006-2007 Richard Hughes";
+
const char *documenters [] = {
NULL
};
@@ -499,17 +420,17 @@ gpm_applet_dialog_about_cb (GtkAction *action, gpointer data)
license_trans = g_strconcat (_(license[0]), "\n\n", _(license[1]), "\n\n",
_(license[2]), "\n\n", _(license[3]), "\n", NULL);
- about = (MateAboutDialog*) mate_about_dialog_new ();
- mate_about_dialog_set_program_name (about, GPM_INHIBIT_APPLET_NAME);
- mate_about_dialog_set_version (about, VERSION);
- mate_about_dialog_set_copyright (about, _("Copyright \xc2\xa9 2006-2007 Richard Hughes"));
- mate_about_dialog_set_comments (about, GPM_INHIBIT_APPLET_DESC);
- mate_about_dialog_set_authors (about, authors);
- mate_about_dialog_set_documenters (about, documenters);
- mate_about_dialog_set_translator_credits (about, translator_credits);
- mate_about_dialog_set_logo (about, logo);
- mate_about_dialog_set_license (about, license_trans);
- mate_about_dialog_set_website (about, GPM_HOMEPAGE_URL);
+ about = (GtkAboutDialog*) gtk_about_dialog_new ();
+ gtk_about_dialog_set_program_name (about, GPM_INHIBIT_APPLET_NAME);
+ gtk_about_dialog_set_version (about, VERSION);
+ gtk_about_dialog_set_copyright (about, copyright);
+ gtk_about_dialog_set_comments (about, GPM_INHIBIT_APPLET_DESC);
+ gtk_about_dialog_set_authors (about, authors);
+ gtk_about_dialog_set_documenters (about, documenters);
+ gtk_about_dialog_set_translator_credits (about, translator_credits);
+ gtk_about_dialog_set_logo (about, logo);
+ gtk_about_dialog_set_license (about, license_trans);
+ gtk_about_dialog_set_website (about, "http://www.mate-desktop.org/");
g_signal_connect (G_OBJECT(about), "response",
G_CALLBACK(gtk_widget_destroy), NULL);
@@ -533,19 +454,16 @@ gpm_applet_help_cb (GtkAction *action, gpointer data)
/**
* gpm_applet_destroy_cb:
- * @object: Class instance to destroy
+ * @widget: Class instance to destroy
**/
static void
-gpm_applet_destroy_cb (GtkObject *object)
+gpm_applet_destroy_cb (GtkWidget *widget)
{
- GpmInhibitApplet *applet = GPM_INHIBIT_APPLET(object);
+ GpmInhibitApplet *applet = GPM_INHIBIT_APPLET(widget);
- if (applet->monitor != NULL) {
- g_object_unref (applet->monitor);
- }
- if (applet->icon != NULL) {
+ g_bus_unwatch_name (applet->bus_watch_id);
+ if (applet->icon != NULL)
g_object_unref (applet->icon);
- }
}
/**
@@ -613,27 +531,32 @@ gpm_inhibit_applet_dbus_disconnect (GpmInhibitApplet *applet)
}
/**
- * monitor_connection_cb:
- * @proxy: The dbus raw proxy
- * @status: The status of the service, where TRUE is connected
- * @screensaver: This class instance
+ * gpm_inhibit_applet_name_appeared_cb:
**/
static void
-monitor_connection_cb (EggDbusMonitor *monitor,
- gboolean status,
- GpmInhibitApplet *applet)
+gpm_inhibit_applet_name_appeared_cb (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ GpmInhibitApplet *applet)
{
- if (status) {
- gpm_inhibit_applet_dbus_connect (applet);
- gpm_applet_update_tooltip (applet);
- gpm_applet_get_icon (applet);
- gpm_applet_draw_cb (applet);
- } else {
- gpm_inhibit_applet_dbus_disconnect (applet);
- gpm_applet_update_tooltip (applet);
- gpm_applet_get_icon (applet);
- gpm_applet_draw_cb (applet);
- }
+ gpm_inhibit_applet_dbus_connect (applet);
+ gpm_applet_update_tooltip (applet);
+ gpm_applet_get_icon (applet);
+ gpm_applet_draw_cb (applet);
+}
+
+/**
+ * gpm_inhibit_applet_name_vanished_cb:
+ **/
+void
+gpm_inhibit_applet_name_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ GpmInhibitApplet *applet)
+{
+ gpm_inhibit_applet_dbus_disconnect (applet);
+ gpm_applet_update_tooltip (applet);
+ gpm_applet_get_icon (applet);
+ gpm_applet_draw_cb (applet);
}
/**
@@ -656,12 +579,14 @@ gpm_inhibit_applet_init (GpmInhibitApplet *applet)
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
GPM_DATA G_DIR_SEPARATOR_S "icons");
- applet->monitor = egg_dbus_monitor_new ();
- g_signal_connect (applet->monitor, "connection-changed",
- G_CALLBACK (monitor_connection_cb), applet);
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
- egg_dbus_monitor_assign (applet->monitor, connection, GS_DBUS_SERVICE);
- gpm_inhibit_applet_dbus_connect (applet);
+ /* monitor the daemon */
+ applet->bus_watch_id =
+ g_bus_watch_name (G_BUS_TYPE_SESSION,
+ GS_DBUS_SERVICE,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ (GBusNameAppearedCallback) gpm_inhibit_applet_name_appeared_cb,
+ (GBusNameVanishedCallback) gpm_inhibit_applet_name_vanished_cb,
+ applet, NULL);
/* prepare */
mate_panel_applet_set_flags (MATE_PANEL_APPLET (applet), MATE_PANEL_APPLET_EXPAND_MINOR);
@@ -676,18 +601,13 @@ gpm_inhibit_applet_init (GpmInhibitApplet *applet)
g_signal_connect (G_OBJECT(applet), "button-press-event",
G_CALLBACK(gpm_applet_click_cb), NULL);
-#if GTK_CHECK_VERSION (3, 0, 0)
g_signal_connect (G_OBJECT(applet), "draw",
G_CALLBACK(gpm_applet_draw_cb), NULL);
-#else
- g_signal_connect (G_OBJECT(applet), "expose-event",
- G_CALLBACK(gpm_applet_draw_cb), NULL);
-#endif
/* We use g_signal_connect_after because letting the panel draw
* the background is the only way to have the correct
* background when a theme defines a background picture. */
- g_signal_connect_after (G_OBJECT(applet), "expose-event",
+ g_signal_connect_after (G_OBJECT(applet), "draw",
G_CALLBACK(gpm_applet_draw_cb), NULL);
g_signal_connect (G_OBJECT(applet), "change-background",