~ubuntu-branches/ubuntu/karmic/xfce4-session/karmic

« back to all changes in this revision

Viewing changes to settings/session/session.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2005-11-06 22:01:12 UTC
  • mto: (4.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051106220112-5rusox237ymjghsp
Tags: upstream-4.2.3
ImportĀ upstreamĀ versionĀ 4.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: session.c 4782 2005-01-22 17:55:32Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
 
4
 * All rights reserved.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *                                                                              
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *                                                                              
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
 * 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <stdio.h>
 
27
#ifdef HAVE_STDLIB_H
 
28
#include <stdlib.h>
 
29
#endif
 
30
#ifdef HAVE_STRING_H
 
31
#include <string.h>
 
32
#endif
 
33
 
 
34
#include <libxfce4mcs/mcs-manager.h>
 
35
#include <libxfce4util/libxfce4util.h>
 
36
#include <libxfcegui4/libxfcegui4.h>
 
37
#include <xfce-mcs-manager/manager-plugin.h>
 
38
 
 
39
 
 
40
#define BORDER 6
 
41
 
 
42
 
 
43
/*
 
44
   Global variables
 
45
 */
 
46
static GtkWidget    *dialog = NULL;
 
47
static GtkWidget    *general_chooser;
 
48
static GtkWidget    *general_autosave;
 
49
static GtkWidget    *general_prompt;
 
50
static GtkWidget    *advanced_kde;
 
51
static GtkWidget    *advanced_gnome;
 
52
static GtkWidget    *advanced_remote;
 
53
static GtkTooltips  *tooltips;
 
54
static gboolean      kiosk_can_chooser;
 
55
static gboolean      kiosk_can_logout;
 
56
static gboolean      kiosk_can_compat;
 
57
static gboolean      kiosk_can_security;
 
58
 
 
59
 
 
60
 
 
61
/*
 
62
   Config
 
63
 */
 
64
static XfceRc*
 
65
config_open (gboolean readonly)
 
66
{
 
67
  return xfce_rc_config_open (XFCE_RESOURCE_CONFIG,
 
68
                              "xfce4-session/xfce4-session.rc",
 
69
                              readonly);
 
70
}
 
71
 
 
72
 
 
73
void
 
74
config_store (void)
 
75
{
 
76
  XfceRc *rc;
 
77
  
 
78
  g_return_if_fail (dialog != NULL);
 
79
  
 
80
  rc = config_open (FALSE);
 
81
 
 
82
  xfce_rc_set_group (rc, "General");
 
83
  if (G_LIKELY (kiosk_can_logout))
 
84
    {
 
85
      xfce_rc_write_bool_entry (rc, "AutoSave", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_autosave)));
 
86
      xfce_rc_write_bool_entry (rc, "PromptOnLogout", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_prompt)));
 
87
    }
 
88
  if (G_LIKELY (kiosk_can_security))
 
89
    {
 
90
      xfce_rc_write_bool_entry (rc, "DisableTcp", !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (advanced_remote)));
 
91
    }
 
92
 
 
93
  if (G_LIKELY (kiosk_can_compat))
 
94
    {
 
95
      xfce_rc_set_group (rc, "Compatibility");
 
96
      xfce_rc_write_bool_entry (rc, "LaunchGnome", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (advanced_gnome)));
 
97
      xfce_rc_write_bool_entry (rc, "LaunchKDE", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (advanced_kde)));
 
98
    }
 
99
 
 
100
  if (G_LIKELY (kiosk_can_chooser))
 
101
    {
 
102
      xfce_rc_set_group (rc, "Chooser");
 
103
      xfce_rc_write_bool_entry (rc, "AlwaysDisplay", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_chooser)));
 
104
    }
 
105
 
 
106
  xfce_rc_close (rc);
 
107
}
 
108
 
 
109
 
 
110
 
 
111
/*
 
112
   General tab
 
113
 */
 
114
static GtkWidget*
 
115
general_create (XfceRc *rc)
 
116
{
 
117
  GtkWidget *frame;
 
118
  GtkWidget *page;
 
119
  GtkWidget *vbox;
 
120
  gboolean   autosave;
 
121
  gboolean   prompt;
 
122
  gboolean   chooser;
 
123
 
 
124
  xfce_rc_set_group (rc, "General");
 
125
  autosave = xfce_rc_read_bool_entry (rc, "AutoSave", FALSE);
 
126
  prompt = xfce_rc_read_bool_entry (rc, "PromptOnLogout", TRUE);
 
127
  xfce_rc_set_group (rc, "Chooser");
 
128
  chooser = xfce_rc_read_bool_entry (rc, "AlwaysDisplay", FALSE);
 
129
 
 
130
  page = gtk_vbox_new (FALSE, BORDER);
 
131
  gtk_container_set_border_width (GTK_CONTAINER (page), BORDER);
 
132
 
 
133
  frame = xfce_framebox_new (_("Session chooser"), TRUE);
 
134
  gtk_box_pack_start (GTK_BOX (page), frame, FALSE, TRUE, 0);
 
135
  vbox = gtk_vbox_new (FALSE, 0);
 
136
  xfce_framebox_add (XFCE_FRAMEBOX (frame), vbox);
 
137
 
 
138
  general_chooser = gtk_check_button_new_with_label (_("Display chooser "
 
139
                                                       "on login"));
 
140
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_chooser), chooser);
 
141
  g_signal_connect (G_OBJECT (general_chooser), "toggled",
 
142
                    G_CALLBACK (config_store), NULL);
 
143
  gtk_widget_set_sensitive (general_chooser, kiosk_can_chooser);
 
144
  gtk_box_pack_start (GTK_BOX (vbox), general_chooser, FALSE, TRUE, 0);
 
145
  gtk_tooltips_set_tip (tooltips, general_chooser,
 
146
                        _("If set, the session manager will ask you to choose "
 
147
                          "a session every time you log in to Xfce."),
 
148
                        NULL);
 
149
 
 
150
  frame = xfce_framebox_new (_("Logout settings"), TRUE);
 
151
  gtk_box_pack_start (GTK_BOX (page), frame, FALSE, TRUE, 0);
 
152
  vbox = gtk_vbox_new (FALSE, 0);
 
153
  gtk_widget_set_sensitive (vbox, kiosk_can_logout);
 
154
  xfce_framebox_add (XFCE_FRAMEBOX (frame), vbox);
 
155
 
 
156
  general_autosave = gtk_check_button_new_with_label (_("Automatically save session on logout"));
 
157
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_autosave), autosave);
 
158
  g_signal_connect (G_OBJECT (general_autosave), "toggled",
 
159
                    G_CALLBACK (config_store), NULL);
 
160
  gtk_box_pack_start (GTK_BOX (vbox), general_autosave, FALSE, TRUE, 0);
 
161
  gtk_tooltips_set_tip (tooltips, general_autosave,
 
162
                        _("This option instructs the session manager to "
 
163
                          "save the current session automatically when "
 
164
                          "you log out. If you don't select this option "
 
165
                          "you'll be prompted whether you want to save "
 
166
                          "the current session on each logout."),
 
167
                        NULL);
 
168
 
 
169
  general_prompt = gtk_check_button_new_with_label (_("Prompt on logout"));
 
170
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_prompt), prompt);
 
171
  g_signal_connect (G_OBJECT (general_prompt), "toggled",
 
172
                    G_CALLBACK (config_store), NULL);
 
173
  gtk_box_pack_start (GTK_BOX (vbox), general_prompt, FALSE, TRUE, 0);
 
174
  gtk_tooltips_set_tip (tooltips, general_prompt,
 
175
                        _("This option disables the logout confirmation "
 
176
                          "dialog. Whether the session will be saved or not "
 
177
                          "depends on whether you enabled the automatic "
 
178
                          "saving of sessions on logout or not."),
 
179
                        NULL);
 
180
 
 
181
  return page;
 
182
}
 
183
 
 
184
 
 
185
 
 
186
/*
 
187
   Advanced
 
188
 */
 
189
static GtkWidget*
 
190
advanced_create (XfceRc *rc)
 
191
{
 
192
  GtkWidget *frame;
 
193
  GtkWidget *image;
 
194
  GtkWidget *page;
 
195
  GtkWidget *hbox;
 
196
  GtkWidget *vbox;
 
197
  GdkPixbuf *icon;
 
198
  gboolean gnome;
 
199
  gboolean kde;
 
200
  gboolean remote;
 
201
 
 
202
  xfce_rc_set_group (rc, "Compatibility");
 
203
  gnome = xfce_rc_read_bool_entry (rc, "LaunchGnome", FALSE);
 
204
  kde = xfce_rc_read_bool_entry (rc, "LaunchKDE", FALSE);
 
205
  xfce_rc_set_group (rc, "General");
 
206
  remote = !xfce_rc_read_bool_entry (rc, "DisableTcp", TRUE);
 
207
 
 
208
  page = gtk_vbox_new (FALSE, BORDER);
 
209
  gtk_container_set_border_width (GTK_CONTAINER (page), BORDER);
 
210
 
 
211
  frame = xfce_framebox_new (_("Compatibility"), TRUE);
 
212
  gtk_box_pack_start (GTK_BOX (page), frame, FALSE, TRUE, 0);
 
213
  hbox = gtk_hbox_new (FALSE, 0);
 
214
  xfce_framebox_add (XFCE_FRAMEBOX (frame), hbox);
 
215
 
 
216
  vbox = gtk_vbox_new (FALSE, 0);
 
217
  gtk_widget_set_sensitive (vbox, kiosk_can_compat);
 
218
  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
 
219
 
 
220
  advanced_gnome = gtk_check_button_new_with_label (_("Launch Gnome services on startup"));
 
221
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (advanced_gnome), gnome);
 
222
  g_signal_connect (G_OBJECT (advanced_gnome), "toggled",
 
223
                    G_CALLBACK (config_store), NULL);
 
224
  gtk_box_pack_start (GTK_BOX (vbox), advanced_gnome, FALSE, TRUE, 0);
 
225
  gtk_tooltips_set_tip (tooltips, advanced_gnome,
 
226
                        _("Enable this if you plan to use Gnome applications. "
 
227
                          "This will instruct the session manager to start "
 
228
                          "some vital Gnome services for you. You should "
 
229
                          "also enable this if you want to use the Assistive "
 
230
                          "Technologies that ship with Gnome."),
 
231
                        NULL);
 
232
 
 
233
  advanced_kde = gtk_check_button_new_with_label (_("Launch KDE services on startup"));
 
234
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (advanced_kde), kde);
 
235
  g_signal_connect (G_OBJECT (advanced_kde), "toggled",
 
236
                    G_CALLBACK (config_store), NULL);
 
237
  gtk_box_pack_start (GTK_BOX (vbox), advanced_kde, FALSE, TRUE, 0);
 
238
  gtk_tooltips_set_tip (tooltips, advanced_kde,
 
239
                        _("Enable this option if you plan to run KDE "
 
240
                          "applications as part of your Xfce Desktop session. "
 
241
                          "This will notably increase the startup time, but "
 
242
                          "on the other hand, KDE applications will startup "
 
243
                          "faster. Some KDE applications may not work at all "
 
244
                          "if you don't enable this option."),
 
245
                        NULL);
 
246
 
 
247
  icon = xfce_themed_icon_load ("xfsm-gnome-kde-logo", 64);
 
248
  image = gtk_image_new_from_pixbuf (icon);
 
249
  gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, TRUE, 0);
 
250
  g_object_unref (icon);
 
251
 
 
252
  frame = xfce_framebox_new (_("Security"), TRUE);
 
253
  gtk_box_pack_start (GTK_BOX (page), frame, FALSE, TRUE, 0);
 
254
  vbox = gtk_vbox_new (FALSE, 0);
 
255
  xfce_framebox_add (XFCE_FRAMEBOX (frame), vbox);
 
256
 
 
257
  advanced_remote = gtk_check_button_new_with_label (_("Manage remote applications"));
 
258
#ifdef HAVE__ICETRANSNOLISTEN
 
259
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (advanced_remote), remote);
 
260
  gtk_widget_set_sensitive (advanced_remote, kiosk_can_security);
 
261
#else
 
262
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (advanced_remote), TRUE);
 
263
  gtk_widget_set_sensitive (advanced_remote, FALSE);
 
264
#endif
 
265
  g_signal_connect (G_OBJECT (advanced_remote), "toggled",
 
266
                    G_CALLBACK (config_store), NULL);
 
267
  gtk_box_pack_start (GTK_BOX (vbox), advanced_remote, FALSE, TRUE, 0);
 
268
  gtk_tooltips_set_tip (tooltips, advanced_remote,
 
269
                        _("Allow the session manager to manage applications "
 
270
                          "running on remote hosts. Do not enable this "
 
271
                          "option unless you know what you are doing."),
 
272
                        NULL);
 
273
 
 
274
  return page;
 
275
}
 
276
 
 
277
 
 
278
 
 
279
/*
 
280
   Dialog
 
281
 */
 
282
static gboolean
 
283
dialog_response (void)
 
284
{
 
285
  if (dialog != NULL)
 
286
    {
 
287
      gtk_widget_destroy (dialog);
 
288
      dialog = NULL;
 
289
    }
 
290
 
 
291
  if (tooltips != NULL)
 
292
    {
 
293
      gtk_object_destroy (GTK_OBJECT (tooltips));
 
294
      tooltips = NULL;
 
295
    }
 
296
 
 
297
  return TRUE;
 
298
}
 
299
 
 
300
 
 
301
static void
 
302
dialog_run (McsPlugin *plugin)
 
303
{
 
304
  GtkWidget *notebook;
 
305
  GtkWidget *header;
 
306
  GtkWidget *label;
 
307
  GtkWidget *page;
 
308
  GtkWidget *dbox;
 
309
  XfceKiosk *kiosk;
 
310
  XfceRc    *rc;
 
311
 
 
312
  if (dialog != NULL)
 
313
    {
 
314
      gtk_window_present (GTK_WINDOW (dialog));
 
315
      return;
 
316
    }
 
317
 
 
318
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
319
 
 
320
  kiosk = xfce_kiosk_new ("xfce4-session");
 
321
  kiosk_can_chooser = xfce_kiosk_query (kiosk, "Chooser");
 
322
  kiosk_can_logout = xfce_kiosk_query (kiosk, "Logout");
 
323
  kiosk_can_compat = xfce_kiosk_query (kiosk, "Compatibility");
 
324
  kiosk_can_security = xfce_kiosk_query (kiosk, "Security");
 
325
  xfce_kiosk_free (kiosk);
 
326
  tooltips = gtk_tooltips_new ();
 
327
 
 
328
  rc = config_open (TRUE);
 
329
 
 
330
  dialog = gtk_dialog_new_with_buttons (_("Sessions and Startup"),
 
331
                                        NULL,
 
332
                                        GTK_DIALOG_NO_SEPARATOR,
 
333
                                        GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
 
334
                                        NULL);
 
335
 
 
336
  gtk_window_set_icon (GTK_WINDOW (dialog), plugin->icon);
 
337
 
 
338
  g_signal_connect (G_OBJECT (dialog), "response",
 
339
                    G_CALLBACK (dialog_response), NULL);
 
340
  g_signal_connect (G_OBJECT (dialog), "delete-event",
 
341
                    G_CALLBACK (dialog_response), NULL);
 
342
 
 
343
  dbox = GTK_DIALOG (dialog)->vbox;
 
344
 
 
345
  header = xfce_create_header (plugin->icon, _("Sessions and Startup"));
 
346
  gtk_box_pack_start (GTK_BOX (dbox), header, FALSE, TRUE, 0);
 
347
  gtk_widget_show (header);
 
348
 
 
349
  notebook = gtk_notebook_new ();
 
350
  gtk_box_pack_start (GTK_BOX (dbox), notebook, TRUE, TRUE, 0);
 
351
  gtk_widget_show (notebook);
 
352
  gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
 
353
 
 
354
  label = gtk_label_new (_("General"));
 
355
  page = general_create (rc);
 
356
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
 
357
  gtk_widget_show_all (page);
 
358
  gtk_widget_show (label);
 
359
 
 
360
  label = gtk_label_new (_("Advanced"));
 
361
  page = advanced_create (rc);
 
362
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label);
 
363
  gtk_widget_show_all (page);
 
364
  gtk_widget_show (label);
 
365
 
 
366
  xfce_gtk_window_center_on_monitor_with_pointer (GTK_WINDOW (dialog));
 
367
  gtk_widget_show (dialog);
 
368
 
 
369
  xfce_rc_close (rc);
 
370
}
 
371
 
 
372
 
 
373
 
 
374
/*
 
375
   Mcs interface
 
376
 */
 
377
McsPluginInitResult
 
378
mcs_plugin_init (McsPlugin *plugin)
 
379
{
 
380
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
381
 
 
382
  plugin->plugin_name = g_strdup ("session");
 
383
  plugin->caption = g_strdup (_("Sessions and Startup"));
 
384
  plugin->run_dialog = dialog_run;
 
385
  plugin->icon = xfce_themed_icon_load ("xfce4-session", 48);
 
386
 
 
387
  return MCS_PLUGIN_INIT_OK;
 
388
}
 
389
 
 
390
 
 
391
MCS_PLUGIN_CHECK_INIT;