[gnome-panel] panel: Talk to gnome-screensaver via dbus
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] panel: Talk to gnome-screensaver via dbus
- Date: Mon, 28 Mar 2011 21:12:20 +0000 (UTC)
commit 16187fe1f3671496652eb624657c191e20309861
Author: Vincent Untz <vuntz gnome org>
Date: Thu Mar 24 13:27:28 2011 +0100
panel: Talk to gnome-screensaver via dbus
We were using gnome-screensaver-command before, but there's no reason to
stay this way.
This means we lose support for xscreensaver; it could be added back,
if some people want it, but this doesn't make a lot of sense since
xscreensaver doesn't completely integrate in GNOME (in the system
settings, for example).
Also, open the system settings on the screen panel for screensaver
properties.
gnome-panel/gnome-desktop-item-edit.c | 2 -
gnome-panel/libpanel-util/Makefile.am | 2 +
gnome-panel/libpanel-util/panel-screensaver.c | 155 +++++++++++++++++++++++++
gnome-panel/libpanel-util/panel-screensaver.h | 61 ++++++++++
gnome-panel/panel-action-button.c | 38 ++++--
gnome-panel/panel-util.c | 113 ------------------
gnome-panel/panel-util.h | 4 -
7 files changed, 244 insertions(+), 131 deletions(-)
---
diff --git a/gnome-panel/gnome-desktop-item-edit.c b/gnome-panel/gnome-desktop-item-edit.c
index ec315ca..6075f69 100644
--- a/gnome-panel/gnome-desktop-item-edit.c
+++ b/gnome-panel/gnome-desktop-item-edit.c
@@ -16,8 +16,6 @@
GSList *panel_applet_list_applets (void) { return NULL; }
#include "panel-gconf.h"
GConfClient *panel_gconf_get_client (void) { return NULL; }
-#include "panel-lockdown.h"
-gboolean panel_lockdown_get_disable_lock_screen_s (void) { return FALSE; }
#include "panel-bindings.h"
guint panel_bindings_get_mouse_button_modifier_keymask (void) { return 0; }
#include "panel-toplevel.h"
diff --git a/gnome-panel/libpanel-util/Makefile.am b/gnome-panel/libpanel-util/Makefile.am
index 8cd034c..ec9dd03 100644
--- a/gnome-panel/libpanel-util/Makefile.am
+++ b/gnome-panel/libpanel-util/Makefile.am
@@ -29,6 +29,8 @@ libpanel_util_la_SOURCES = \
panel-launch.h \
panel-list.c \
panel-list.h \
+ panel-screensaver.c \
+ panel-screensaver.h \
panel-session-manager.c \
panel-session-manager.h \
panel-show.c \
diff --git a/gnome-panel/libpanel-util/panel-screensaver.c b/gnome-panel/libpanel-util/panel-screensaver.c
new file mode 100644
index 0000000..cfaf773
--- /dev/null
+++ b/gnome-panel/libpanel-util/panel-screensaver.c
@@ -0,0 +1,155 @@
+/*
+ * panel-screensaver.c:
+ *
+ * Copyright (C) 2011 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ * Vincent Untz <vuntz gnome org>
+ */
+
+#include <dbus/dbus-glib.h>
+
+#include "panel-cleanup.h"
+#include "panel-dbus-service.h"
+
+#include "panel-screensaver.h"
+
+static GObject *panel_screensaver_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties);
+
+G_DEFINE_TYPE (PanelScreensaver, panel_screensaver, PANEL_TYPE_DBUS_SERVICE);
+
+static void
+panel_screensaver_class_init (PanelScreensaverClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructor = panel_screensaver_constructor;
+}
+
+static void
+panel_screensaver_init (PanelScreensaver *manager)
+{
+}
+
+static GObject *
+panel_screensaver_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ GObject *obj;
+ GError *error;
+
+ obj = G_OBJECT_CLASS (panel_screensaver_parent_class)->constructor (
+ type,
+ n_construct_properties,
+ construct_properties);
+
+
+ panel_dbus_service_define_service (PANEL_DBUS_SERVICE (obj),
+ "org.gnome.ScreenSaver",
+ "/org/gnome/ScreenSaver",
+ "org.gnome.ScreenSaver");
+
+ error = NULL;
+ if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (obj),
+ &error)) {
+ g_message ("Could not connect to screensaver: %s",
+ error->message);
+ g_error_free (error);
+ }
+
+ return obj;
+}
+
+void
+panel_screensaver_lock (PanelScreensaver *screensaver)
+{
+ GError *error;
+ DBusGProxy *proxy;
+
+ g_return_if_fail (PANEL_IS_SCREENSAVER (screensaver));
+
+ error = NULL;
+
+ if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (screensaver),
+ &error)) {
+ g_warning ("Could not connect to screensaver: %s",
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (screensaver));
+
+ if (!dbus_g_proxy_call (proxy, "Lock", &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID) &&
+ error != NULL) {
+ g_warning ("Could not ask screensaver to lock: %s",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+void
+panel_screensaver_activate (PanelScreensaver *screensaver)
+{
+ GError *error;
+ DBusGProxy *proxy;
+
+ g_return_if_fail (PANEL_IS_SCREENSAVER (screensaver));
+
+ error = NULL;
+
+ if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (screensaver),
+ &error)) {
+ g_warning ("Could not connect to screensaver: %s",
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (screensaver));
+
+ if (!dbus_g_proxy_call (proxy, "SetActive", &error,
+ G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID,
+ G_TYPE_INVALID) &&
+ error != NULL) {
+ g_warning ("Could not ask screensaver to activate: %s",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+PanelScreensaver *
+panel_screensaver_get (void)
+{
+ static PanelScreensaver *screensaver = NULL;
+
+ if (screensaver == NULL) {
+ screensaver = g_object_new (PANEL_TYPE_SCREENSAVER, NULL);
+ panel_cleanup_register (panel_cleanup_unref_and_nullify,
+ &screensaver);
+ }
+
+ return screensaver;
+}
diff --git a/gnome-panel/libpanel-util/panel-screensaver.h b/gnome-panel/libpanel-util/panel-screensaver.h
new file mode 100644
index 0000000..82de9da
--- /dev/null
+++ b/gnome-panel/libpanel-util/panel-screensaver.h
@@ -0,0 +1,61 @@
+/*
+ * panel-screensaver.h:
+ *
+ * Copyright (C) 2011 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ * Vincent Untz <vuntz gnome org>
+ */
+
+#ifndef PANEL_SCREENSAVER_H
+#define PANEL_SCREENSAVER_H
+
+#include <glib-object.h>
+
+#include "panel-dbus-service.h"
+
+G_BEGIN_DECLS
+
+#define PANEL_TYPE_SCREENSAVER (panel_screensaver_get_type ())
+#define PANEL_SCREENSAVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_SCREENSAVER, PanelScreensaver))
+#define PANEL_SCREENSAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_SCREENSAVER, PanelScreensaverClass))
+#define PANEL_IS_SCREENSAVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_SCREENSAVER))
+#define PANEL_IS_SCREENSAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_SCREENSAVER))
+#define PANEL_SCREENSAVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_SCREENSAVER, PanelScreensaverClass))
+
+typedef struct _PanelScreensaver PanelScreensaver;
+typedef struct _PanelScreensaverClass PanelScreensaverClass;
+
+struct _PanelScreensaver {
+ PanelDBusService parent;
+};
+
+struct _PanelScreensaverClass {
+ PanelDBusServiceClass parent_class;
+};
+
+GType panel_screensaver_get_type (void);
+
+PanelScreensaver *panel_screensaver_get (void);
+
+void panel_screensaver_lock (PanelScreensaver *screensaver);
+void panel_screensaver_activate (PanelScreensaver *screensaver);
+
+G_END_DECLS
+
+#endif /* PANEL_SCREENSAVER_H */
diff --git a/gnome-panel/panel-action-button.c b/gnome-panel/panel-action-button.c
index 37f142b..28f74c8 100644
--- a/gnome-panel/panel-action-button.c
+++ b/gnome-panel/panel-action-button.c
@@ -33,7 +33,9 @@
#include <glib/gi18n.h>
#include <libpanel-util/panel-error.h>
+#include <libpanel-util/panel-glib.h>
#include <libpanel-util/panel-launch.h>
+#include <libpanel-util/panel-screensaver.h>
#include <libpanel-util/panel-session-manager.h>
#include <libpanel-util/panel-show.h>
@@ -88,32 +90,36 @@ static GConfEnumStringPair panel_action_type_map [] = {
static void
panel_action_lock_screen (GtkWidget *widget)
{
- panel_lock_screen_action (gtk_widget_get_screen (widget), "lock");
+ panel_screensaver_lock (panel_screensaver_get ());
}
static gboolean
screensaver_properties_enabled (void)
{
+ char *desktop;
+ gboolean found;
+
if (panel_lockdown_get_panels_locked_down_s () ||
panel_lockdown_get_disable_lock_screen_s ())
return FALSE;
- return panel_lock_screen_action_available ("prefs");
+ desktop = panel_g_lookup_in_applications_dirs ("gnome-screen-panel.desktop");
+ found = (desktop != NULL);
+ g_free (desktop);
+
+ return found;
}
static gboolean
-screensaver_enabled (void)
+panel_action_lock_is_enabled (void)
{
- if (panel_lockdown_get_disable_lock_screen_s ())
- return FALSE;
-
- return panel_lock_screen_action_available ("lock");
+ return !panel_lockdown_get_disable_lock_screen_s ();
}
static gboolean
panel_action_lock_is_disabled (void)
{
- return !screensaver_enabled ();
+ return !panel_action_lock_is_enabled ();
}
static void
@@ -123,13 +129,13 @@ panel_action_lock_setup_menu (PanelActionButton *button)
"lock",
NULL,
_("_Lock Screen"),
- screensaver_enabled);
+ panel_action_lock_is_enabled);
panel_applet_add_callback (button->priv->info,
"activate",
NULL,
_("_Activate Screensaver"),
- screensaver_enabled);
+ NULL);
panel_applet_add_callback (button->priv->info,
"prefs",
@@ -145,8 +151,16 @@ panel_action_lock_invoke_menu (PanelActionButton *button,
g_return_if_fail (PANEL_IS_ACTION_BUTTON (button));
g_return_if_fail (callback_name != NULL);
- panel_lock_screen_action (gtk_widget_get_screen (GTK_WIDGET (button)),
- callback_name);
+ if (g_strcmp0 (callback_name, "lock") == 0)
+ panel_screensaver_lock (panel_screensaver_get ());
+ else if (g_strcmp0 (callback_name, "activate") == 0)
+ panel_screensaver_activate (panel_screensaver_get ());
+ else if (g_strcmp0 (callback_name, "prefs") == 0)
+ panel_launch_desktop_file ("gnome-screen-panel.desktop",
+ gtk_widget_get_screen (GTK_WIDGET (button)),
+ NULL);
+ else
+ g_assert_not_reached ();
}
/* Log Out
diff --git a/gnome-panel/panel-util.c b/gnome-panel/panel-util.c
index cd47b3a..411d009 100644
--- a/gnome-panel/panel-util.c
+++ b/gnome-panel/panel-util.c
@@ -41,7 +41,6 @@
#include "panel-globals.h"
#include "launcher.h"
#include "panel-icon-names.h"
-#include "panel-lockdown.h"
#include "panel-schemas.h"
char *
@@ -334,118 +333,6 @@ panel_load_icon (GtkIconTheme *icon_theme,
return retval;
}
-static char *
-panel_lock_screen_action_get_command (const char *action)
-{
- char *command = NULL;
- gboolean use_gscreensaver = FALSE;
-
- if (panel_is_program_in_path ("gnome-screensaver-command")
- && panel_is_program_in_path ("gnome-screensaver-preferences"))
- use_gscreensaver = TRUE;
- else if (!panel_is_program_in_path ("xscreensaver-command"))
- return NULL;
-
- if (strcmp (action, "prefs") == 0) {
- if (use_gscreensaver) {
- command = g_strdup ("gnome-screensaver-preferences");
- } else if (panel_is_program_in_path ("xscreensaver-demo")) {
- command = g_strdup ("xscreensaver-demo");
- } else {
- command = NULL;
- }
- } else if (strcmp (action, "activate") == 0
- || strcmp (action, "lock") == 0) {
- /* Neither gnome-screensaver or xscreensaver allow root
- * to lock the screen */
- if (geteuid () == 0) {
- command = NULL;
- } else {
- if (use_gscreensaver) {
- command = g_strdup_printf ("gnome-screensaver-command --%s", action);
- } else {
- command = g_strdup_printf ("xscreensaver-command -%s", action);
- }
- }
- }
-
- return command;
-}
-
-gboolean
-panel_lock_screen_action_available (const char *action)
-{
- char *command;
- gboolean enabled = FALSE;
-
- g_return_val_if_fail (action != NULL, FALSE);
-
- if (strcmp (action, "prefs") != 0 &&
- panel_lockdown_get_disable_lock_screen_s ())
- return FALSE;
-
- command = panel_lock_screen_action_get_command (action);
- if (command)
- enabled = TRUE;
-
- g_free (command);
-
- return enabled;
-}
-
-void
-panel_lock_screen_action (GdkScreen *screen,
- const char *action)
-{
- GError *error = NULL;
- char *command = NULL;
- GdkAppLaunchContext *launch_context = NULL;
- GAppInfo *app_info = NULL;
- GdkDisplay *display;
-
- g_return_if_fail (GDK_IS_SCREEN (screen));
- g_return_if_fail (action != NULL);
-
- if (strcmp (action, "prefs") != 0 &&
- panel_lockdown_get_disable_lock_screen_s ())
- return;
-
- command = panel_lock_screen_action_get_command (action);
-
- if (!command)
- return;
-
- app_info = g_app_info_create_from_commandline (command,
- NULL,
- G_APP_INFO_CREATE_NONE,
- &error);
-
- if (!error) {
- display = gdk_screen_get_display (screen);
- launch_context = gdk_display_get_app_launch_context (display);
- gdk_app_launch_context_set_screen (launch_context, screen);
- g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error);
-
- g_object_unref (launch_context);
- }
-
- /* error either by create or launch the command */
- if (error) {
- char *primary;
-
- primary = g_strdup_printf (_("Could not execute '%s'"),
- command);
- panel_error_dialog (NULL, screen,
- "cannot_exec_screensaver", TRUE,
- primary, error->message);
- g_free (primary);
- g_error_free (error);
- }
-
- g_free (command);
- g_object_unref (app_info);
-}
-
#define PANEL_LAUNCHER_PERSONAL_PATH "panel2.d/default/launchers"
static char *
diff --git a/gnome-panel/panel-util.h b/gnome-panel/panel-util.h
index f1ca69d..7399a71 100644
--- a/gnome-panel/panel-util.h
+++ b/gnome-panel/panel-util.h
@@ -20,10 +20,6 @@ gboolean panel_is_program_in_path (const char *program);
gboolean panel_is_uri_writable (const char *uri);
gboolean panel_uri_exists (const char *uri);
-void panel_lock_screen_action (GdkScreen *screen,
- const char *action);
-gboolean panel_lock_screen_action_available (const char *action);
-
char * panel_find_icon (GtkIconTheme *icon_theme,
const char *icon_name,
int size);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]