summaryrefslogtreecommitdiff
path: root/gnome-settings-daemon/gnome-settings-screensaver.c
blob: 75f8cbd458af45ebde871e5d96308d05fdc44cb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* -*- mode: c; style: linux -*- */

/* gnome-settings-screensaver.c
 *
 * Copyright (C) 2002 Sun Microsystems, Inc.
 *
 * Written by Jacob Berkman <jacob@ximian.com>
 *
 * 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, 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.
 */

#include <config.h>

#include "gnome-settings-screensaver.h"

#include <glib/gi18n.h>

#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkbox.h>
#include <gtk/gtkmessagedialog.h>

#define START_SCREENSAVER_KEY   "/apps/gnome_settings_daemon/screensaver/start_screensaver"
#define SHOW_STARTUP_ERRORS_KEY "/apps/gnome_settings_daemon/screensaver/show_startup_errors"
#define XSCREENSAVER_COMMAND    "xscreensaver -nosplash"

void
gnome_settings_screensaver_init (GConfClient *client)
{
	/*
	 * do nothing.
	 *
	 * our settings only apply to startup, and the screensaver
	 * settings are all in xscreensaver and not gconf.
	 *
	 * we could have xscreensaver-demo run gconftool-2 directly,
	 * and start / stop xscreensaver here
	 *
	 */
}

static void
key_toggled_cb (GtkWidget *toggle, gpointer data)
{
	GConfClient *client;

	client = gconf_client_get_default ();
	gconf_client_set_bool (client, 
			       SHOW_STARTUP_ERRORS_KEY,
			       gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle))
			       ? 0 : 1,
			       NULL);
	g_object_unref (client);
}

void
gnome_settings_screensaver_load (GConfClient *client)
{
	GError *gerr = NULL;
	gboolean start_screensaver;
	gboolean show_error;
	GtkWidget *dialog, *toggle;
 
	start_screensaver = gconf_client_get_bool (client, START_SCREENSAVER_KEY, NULL);

	if (!start_screensaver)
		return;

	if (g_spawn_command_line_async (XSCREENSAVER_COMMAND, &gerr))
		return;
	
	show_error = gconf_client_get_bool (client, SHOW_STARTUP_ERRORS_KEY, NULL);
	if (!show_error) {
		g_error_free (gerr);
		return;
	}

	dialog = gtk_message_dialog_new (NULL,
					 0, 
					 GTK_MESSAGE_ERROR,
					 GTK_BUTTONS_OK,
					 _("There was an error starting up the screensaver:\n\n"
					 "%s\n\n"
					 "Screensaver functionality will not work in this session."),
					 gerr->message);

	g_signal_connect (dialog, "response",
			  G_CALLBACK (gtk_widget_destroy),
			  NULL);

	toggle = gtk_check_button_new_with_mnemonic (
		_("_Do not show this message again"));
	gtk_widget_show (toggle);

	if (gconf_client_key_is_writable (client, SHOW_STARTUP_ERRORS_KEY, NULL))
		g_signal_connect (toggle, "toggled",
				  G_CALLBACK (key_toggled_cb),
				  NULL);
	else
		gtk_widget_set_sensitive (toggle, FALSE);
					  
	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), 
			    toggle,
			    FALSE, FALSE, 0);

	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);		

	gtk_widget_show (dialog);
}