Mercurial > audlegacy
annotate src/libeggsmclient/eggsmclient.c @ 4879:012b478a282f
First step in fixing hang-ups when playing a CD.
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Sun, 03 May 2009 20:44:00 -0400 |
parents | c942eaef7bc6 |
children |
rev | line source |
---|---|
4315
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
1 /* |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
2 * Copyright (C) 2007 Novell, Inc. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
3 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
4 * This library is free software; you can redistribute it and/or |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
5 * modify it under the terms of the GNU Library General Public |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
6 * License as published by the Free Software Foundation; either |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
7 * version 2 of the License, or (at your option) any later version. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
8 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
9 * This library is distributed in the hope that it will be useful, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
12 * Library General Public License for more details. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
13 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU Library General Public |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
15 * License along with this library; if not, write to the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
17 * Boston, MA 02111-1307, USA. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
18 */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
19 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
20 #include <string.h> |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
21 #include <glib/gi18n.h> |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
22 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
23 #include "eggsmclient.h" |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
24 #include "eggsmclient-private.h" |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
25 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
26 static void egg_sm_client_debug_handler (const char *log_domain, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
27 GLogLevelFlags log_level, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
28 const char *message, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
29 gpointer user_data); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
30 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
31 enum { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
32 SAVE_STATE, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
33 QUIT_REQUESTED, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
34 QUIT_CANCELLED, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
35 QUIT, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
36 LAST_SIGNAL |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
37 }; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
38 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
39 static guint signals[LAST_SIGNAL] = { 0 }; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
40 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
41 struct _EggSMClientPrivate { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
42 GKeyFile *state_file; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
43 }; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
44 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
45 #define EGG_SM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EGG_TYPE_SM_CLIENT, EggSMClientPrivate)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
46 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
47 G_DEFINE_TYPE (EggSMClient, egg_sm_client, G_TYPE_OBJECT) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
48 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
49 static EggSMClient *global_client; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
50 static EggSMClientMode global_client_mode = EGG_SM_CLIENT_MODE_NORMAL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
51 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
52 static void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
53 egg_sm_client_init (EggSMClient *client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
54 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
55 ; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
56 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
57 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
58 static void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
59 egg_sm_client_class_init (EggSMClientClass *klass) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
60 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
61 GObjectClass *object_class = G_OBJECT_CLASS (klass); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
62 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
63 g_type_class_add_private (klass, sizeof (EggSMClientPrivate)); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
64 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
65 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
66 * EggSMClient::save_state: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
67 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
68 * @state_file: a #GKeyFile to save state information into |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
69 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
70 * Emitted when the session manager has requested that the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
71 * application save information about its current state. The |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
72 * application should save its state into @state_file, and then the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
73 * session manager may then restart the application in a future |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
74 * session and tell it to initialize itself from that state. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
75 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
76 * You should not save any data into @state_file's "start group" |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
77 * (ie, the %NULL group). Instead, applications should save their |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
78 * data into groups with names that start with the application name, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
79 * and libraries that connect to this signal should save their data |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
80 * into groups with names that start with the library name. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
81 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
82 * Alternatively, rather than (or in addition to) using @state_file, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
83 * the application can save its state by calling |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
84 * egg_sm_client_set_restart_command() during the processing of this |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
85 * signal (eg, to include a list of files to open). |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
86 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
87 signals[SAVE_STATE] = |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
88 g_signal_new ("save_state", |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
89 G_OBJECT_CLASS_TYPE (object_class), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
90 G_SIGNAL_RUN_LAST, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
91 G_STRUCT_OFFSET (EggSMClientClass, save_state), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
92 NULL, NULL, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
93 g_cclosure_marshal_VOID__POINTER, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
94 G_TYPE_NONE, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
95 1, G_TYPE_POINTER); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
96 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
97 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
98 * EggSMClient::quit_requested: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
99 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
100 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
101 * Emitted when the session manager requests that the application |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
102 * exit (generally because the user is logging out). The application |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
103 * should decide whether or not it is willing to quit (perhaps after |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
104 * asking the user what to do with documents that have unsaved |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
105 * changes) and then call egg_sm_client_will_quit(), passing %TRUE |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
106 * or %FALSE to give its answer to the session manager. (It does not |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
107 * need to give an answer before returning from the signal handler; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
108 * it can interact with the user asynchronously and then give its |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
109 * answer later on.) If the application does not connect to this |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
110 * signal, then #EggSMClient will automatically return %TRUE on its |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
111 * behalf. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
112 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
113 * The application should not save its session state as part of |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
114 * handling this signal; if the user has requested that the session |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
115 * be saved when logging out, then ::save_state will be emitted |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
116 * separately. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
117 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
118 * If the application agrees to quit, it should then wait for either |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
119 * the ::quit_cancelled or ::quit signals to be emitted. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
120 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
121 signals[QUIT_REQUESTED] = |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
122 g_signal_new ("quit_requested", |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
123 G_OBJECT_CLASS_TYPE (object_class), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
124 G_SIGNAL_RUN_LAST, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
125 G_STRUCT_OFFSET (EggSMClientClass, quit_requested), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
126 NULL, NULL, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
127 g_cclosure_marshal_VOID__VOID, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
128 G_TYPE_NONE, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
129 0); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
130 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
131 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
132 * EggSMClient::quit_cancelled: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
133 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
134 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
135 * Emitted when the session manager decides to cancel a logout after |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
136 * the application has already agreed to quit. After receiving this |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
137 * signal, the application can go back to what it was doing before |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
138 * receiving the ::quit_requested signal. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
139 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
140 signals[QUIT_CANCELLED] = |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
141 g_signal_new ("quit_cancelled", |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
142 G_OBJECT_CLASS_TYPE (object_class), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
143 G_SIGNAL_RUN_LAST, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
144 G_STRUCT_OFFSET (EggSMClientClass, quit_cancelled), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
145 NULL, NULL, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
146 g_cclosure_marshal_VOID__VOID, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
147 G_TYPE_NONE, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
148 0); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
149 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
150 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
151 * EggSMClient::quit: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
152 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
153 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
154 * Emitted when the session manager wants the application to quit |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
155 * (generally because the user is logging out). The application |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
156 * should exit as soon as possible after receiving this signal; if |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
157 * it does not, the session manager may choose to forcibly kill it. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
158 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
159 * Normally a GUI application would only be sent a ::quit if it |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
160 * agreed to quit in response to a ::quit_requested signal. However, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
161 * this is not guaranteed; in some situations the session manager |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
162 * may decide to end the session without giving applications a |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
163 * chance to object. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
164 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
165 signals[QUIT] = |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
166 g_signal_new ("quit", |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
167 G_OBJECT_CLASS_TYPE (object_class), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
168 G_SIGNAL_RUN_LAST, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
169 G_STRUCT_OFFSET (EggSMClientClass, quit), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
170 NULL, NULL, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
171 g_cclosure_marshal_VOID__VOID, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
172 G_TYPE_NONE, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
173 0); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
174 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
175 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
176 static gboolean sm_client_disable = FALSE; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
177 static char *sm_client_state_file = NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
178 static char *sm_client_id = NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
179 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
180 static GOptionEntry entries[] = { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
181 { "sm-client-disable", 0, 0, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
182 G_OPTION_ARG_NONE, &sm_client_disable, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
183 N_("Disable connection to session manager"), NULL }, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
184 { "sm-client-state-file", 0, 0, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
185 G_OPTION_ARG_STRING, &sm_client_state_file, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
186 N_("Specify file containing saved configuration"), N_("FILE") }, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
187 { "sm-client-id", 0, 0, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
188 G_OPTION_ARG_STRING, &sm_client_id, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
189 N_("Specify session management ID"), N_("ID") }, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
190 { NULL } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
191 }; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
192 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
193 static gboolean |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
194 sm_client_post_parse_func (GOptionContext *context, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
195 GOptionGroup *group, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
196 gpointer data, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
197 GError **error) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
198 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
199 EggSMClient *client = egg_sm_client_get (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
200 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
201 if (EGG_SM_CLIENT_GET_CLASS (client)->startup) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
202 EGG_SM_CLIENT_GET_CLASS (client)->startup (client, sm_client_id); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
203 return TRUE; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
204 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
205 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
206 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
207 * egg_sm_client_get_option_group: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
208 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
209 * Creates a %GOptionGroup containing the session-management-related |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
210 * options. You should add this group to the application's |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
211 * %GOptionContext if you want to use #EggSMClient. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
212 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
213 * Return value: the %GOptionGroup |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
214 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
215 GOptionGroup * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
216 egg_sm_client_get_option_group (void) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
217 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
218 GOptionGroup *group; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
219 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
220 /* Use our own debug handler for the "EggSMClient" domain. */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
221 g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
222 egg_sm_client_debug_handler, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
223 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
224 group = g_option_group_new ("sm-client", |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
225 _("Session Management Options"), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
226 _("Show Session Management options"), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
227 NULL, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
228 g_option_group_add_entries (group, entries); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
229 g_option_group_set_parse_hooks (group, NULL, sm_client_post_parse_func); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
230 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
231 return group; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
232 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
233 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
234 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
235 * egg_sm_client_set_mode: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
236 * @mode: an #EggSMClient mode |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
237 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
238 * Sets the "mode" of #EggSMClient as follows: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
239 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
240 * %EGG_SM_CLIENT_MODE_DISABLED: Session management is completely |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
241 * disabled. The application will not even connect to the session |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
242 * manager. (egg_sm_client_get() will still return an #EggSMClient, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
243 * but it will just be a dummy object.) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
244 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
245 * %EGG_SM_CLIENT_MODE_NO_RESTART: The application will connect to |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
246 * the session manager (and thus will receive notification when the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
247 * user is logging out, etc), but will request to not be |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
248 * automatically restarted with saved state in future sessions. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
249 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
250 * %EGG_SM_CLIENT_MODE_NORMAL: The default. #EggSMCLient will |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
251 * function normally. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
252 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
253 * This must be called before the application's main loop begins. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
254 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
255 void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
256 egg_sm_client_set_mode (EggSMClientMode mode) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
257 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
258 global_client_mode = mode; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
259 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
260 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
261 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
262 * egg_sm_client_get_mode: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
263 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
264 * Gets the global #EggSMClientMode. See egg_sm_client_set_mode() |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
265 * for details. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
266 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
267 * Return value: the global #EggSMClientMode |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
268 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
269 EggSMClientMode |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
270 egg_sm_client_get_mode (void) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
271 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
272 return global_client_mode; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
273 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
274 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
275 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
276 * egg_sm_client_get: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
277 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
278 * Returns the master #EggSMClient for the application. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
279 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
280 * On platforms that support saved sessions (ie, POSIX/X11), the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
281 * application will only request to be restarted by the session |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
282 * manager if you call egg_set_desktop_file() to set an application |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
283 * desktop file. In particular, if the desktop file contains the key |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
284 * "X |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
285 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
286 * Return value: the master #EggSMClient. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
287 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
288 EggSMClient * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
289 egg_sm_client_get (void) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
290 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
291 if (!global_client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
292 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
293 if (global_client_mode != EGG_SM_CLIENT_MODE_DISABLED && |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
294 !sm_client_disable) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
295 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
296 #if defined (GDK_WINDOWING_WIN32) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
297 global_client = egg_sm_client_win32_new (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
298 #elif defined (GDK_WINDOWING_QUARTZ) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
299 global_client = egg_sm_client_osx_new (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
300 #else |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
301 /* If both D-Bus and XSMP are compiled in, try D-Bus first |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
302 * and fall back to XSMP if D-Bus session management isn't |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
303 * available. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
304 */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
305 # ifdef EGG_SM_CLIENT_BACKEND_DBUS |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
306 global_client = egg_sm_client_dbus_new (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
307 # endif |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
308 # ifdef EGG_SM_CLIENT_BACKEND_XSMP |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
309 if (!global_client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
310 global_client = egg_sm_client_xsmp_new (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
311 # endif |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
312 #endif |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
313 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
314 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
315 /* Fallback: create a dummy client, so that callers don't have |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
316 * to worry about a %NULL return value. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
317 */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
318 if (!global_client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
319 global_client = g_object_new (EGG_TYPE_SM_CLIENT, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
320 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
321 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
322 return global_client; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
323 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
324 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
325 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
326 * egg_sm_client_is_resumed: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
327 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
328 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
329 * Checks whether or not the current session has been resumed from |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
330 * a previous saved session. If so, the application should call |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
331 * egg_sm_client_get_state_file() and restore its state from the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
332 * returned #GKeyFile. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
333 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
334 * Return value: %TRUE if the session has been resumed |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
335 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
336 gboolean |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
337 egg_sm_client_is_resumed (EggSMClient *client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
338 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
339 g_return_val_if_fail (client == global_client, FALSE); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
340 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
341 return sm_client_state_file != NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
342 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
343 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
344 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
345 * egg_sm_client_get_state_file: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
346 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
347 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
348 * If the application was resumed by the session manager, this will |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
349 * return the #GKeyFile containing its state from the previous |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
350 * session. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
351 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
352 * Note that other libraries and #EggSMClient itself may also store |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
353 * state in the key file, so if you call egg_sm_client_get_groups(), |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
354 * on it, the return value will likely include groups that you did not |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
355 * put there yourself. (It is also not guaranteed that the first |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
356 * group created by the application will still be the "start group" |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
357 * when it is resumed.) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
358 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
359 * Return value: the #GKeyFile containing the application's earlier |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
360 * state, or %NULL on error. You should not free this key file; it |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
361 * is owned by @client. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
362 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
363 GKeyFile * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
364 egg_sm_client_get_state_file (EggSMClient *client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
365 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
366 EggSMClientPrivate *priv = EGG_SM_CLIENT_GET_PRIVATE (client); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
367 char *state_file_path; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
368 GError *err = NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
369 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
370 g_return_val_if_fail (client == global_client, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
371 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
372 if (!sm_client_state_file) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
373 return NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
374 if (priv->state_file) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
375 return priv->state_file; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
376 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
377 if (!strncmp (sm_client_state_file, "file://", 7)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
378 state_file_path = g_filename_from_uri (sm_client_state_file, NULL, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
379 else |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
380 state_file_path = g_strdup (sm_client_state_file); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
381 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
382 priv->state_file = g_key_file_new (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
383 if (!g_key_file_load_from_file (priv->state_file, state_file_path, 0, &err)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
384 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
385 g_warning ("Could not load SM state file '%s': %s", |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
386 sm_client_state_file, err->message); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
387 g_clear_error (&err); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
388 g_key_file_free (priv->state_file); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
389 priv->state_file = NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
390 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
391 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
392 g_free (state_file_path); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
393 return priv->state_file; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
394 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
395 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
396 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
397 * egg_sm_client_set_restart_command: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
398 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
399 * @argc: the length of @argv |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
400 * @argv: argument vector |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
401 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
402 * Sets the command used to restart @client if it does not have a |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
403 * .desktop file that can be used to find its restart command. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
404 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
405 * This can also be used when handling the ::save_state signal, to |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
406 * save the current state via an updated command line. (Eg, providing |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
407 * a list of filenames to open when the application is resumed.) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
408 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
409 void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
410 egg_sm_client_set_restart_command (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
411 int argc, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
412 const char **argv) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
413 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
414 g_return_if_fail (EGG_IS_SM_CLIENT (client)); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
415 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
416 if (EGG_SM_CLIENT_GET_CLASS (client)->set_restart_command) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
417 EGG_SM_CLIENT_GET_CLASS (client)->set_restart_command (client, argc, argv); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
418 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
419 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
420 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
421 * egg_sm_client_will_quit: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
422 * @client: the client |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
423 * @will_quit: whether or not the application is willing to quit |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
424 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
425 * This MUST be called in response to the ::quit_requested signal, to |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
426 * indicate whether or not the application is willing to quit. The |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
427 * application may call it either directly from the signal handler, or |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
428 * at some later point (eg, after asynchronously interacting with the |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
429 * user). |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
430 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
431 * If the application does not connect to ::quit_requested, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
432 * #EggSMClient will call this method on its behalf (passing %TRUE |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
433 * for @will_quit). |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
434 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
435 * After calling this method, the application should wait to receive |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
436 * either ::quit_cancelled or ::quit. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
437 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
438 void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
439 egg_sm_client_will_quit (EggSMClient *client, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
440 gboolean will_quit) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
441 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
442 g_return_if_fail (EGG_IS_SM_CLIENT (client)); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
443 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
444 if (EGG_SM_CLIENT_GET_CLASS (client)->will_quit) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
445 EGG_SM_CLIENT_GET_CLASS (client)->will_quit (client, will_quit); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
446 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
447 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
448 /** |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
449 * egg_sm_client_end_session: |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
450 * @style: a hint at how to end the session |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
451 * @request_confirmation: whether or not the user should get a chance |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
452 * to confirm the action |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
453 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
454 * Requests that the session manager end the current session. @style |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
455 * indicates how the session should be ended, and |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
456 * @request_confirmation indicates whether or not the user should be |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
457 * given a chance to confirm the logout/reboot/shutdown. Both of these |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
458 * flags are merely hints though; the session manager may choose to |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
459 * ignore them. |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
460 * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
461 * Return value: %TRUE if the request was sent; %FALSE if it could not |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
462 * be (eg, because it could not connect to the session manager). |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
463 **/ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
464 gboolean |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
465 egg_sm_client_end_session (EggSMClientEndStyle style, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
466 gboolean request_confirmation) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
467 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
468 EggSMClient *client = egg_sm_client_get (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
469 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
470 g_return_val_if_fail (EGG_IS_SM_CLIENT (client), FALSE); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
471 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
472 if (EGG_SM_CLIENT_GET_CLASS (client)->end_session) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
473 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
474 return EGG_SM_CLIENT_GET_CLASS (client)->end_session (client, style, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
475 request_confirmation); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
476 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
477 else |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
478 return FALSE; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
479 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
480 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
481 /* Signal-emitting callbacks from platform-specific code */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
482 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
483 GKeyFile * |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
484 egg_sm_client_save_state (EggSMClient *client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
485 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
486 GKeyFile *state_file; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
487 char *group; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
488 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
489 g_return_val_if_fail (client == global_client, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
490 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
491 state_file = g_key_file_new (); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
492 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
493 g_debug ("Emitting save_state"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
494 g_signal_emit (client, signals[SAVE_STATE], 0, state_file); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
495 g_debug ("Done emitting save_state"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
496 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
497 group = g_key_file_get_start_group (state_file); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
498 if (group) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
499 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
500 g_free (group); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
501 return state_file; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
502 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
503 else |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
504 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
505 g_key_file_free (state_file); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
506 return NULL; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
507 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
508 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
509 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
510 void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
511 egg_sm_client_quit_requested (EggSMClient *client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
512 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
513 g_return_if_fail (client == global_client); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
514 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
515 if (!g_signal_has_handler_pending (client, signals[QUIT_REQUESTED], 0, FALSE)) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
516 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
517 g_debug ("Not emitting quit_requested because no one is listening"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
518 egg_sm_client_will_quit (client, TRUE); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
519 return; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
520 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
521 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
522 g_debug ("Emitting quit_requested"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
523 g_signal_emit (client, signals[QUIT_REQUESTED], 0); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
524 g_debug ("Done emitting quit_requested"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
525 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
526 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
527 void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
528 egg_sm_client_quit_cancelled (EggSMClient *client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
529 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
530 g_return_if_fail (client == global_client); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
531 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
532 g_debug ("Emitting quit_cancelled"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
533 g_signal_emit (client, signals[QUIT_CANCELLED], 0); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
534 g_debug ("Done emitting quit_cancelled"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
535 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
536 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
537 void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
538 egg_sm_client_quit (EggSMClient *client) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
539 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
540 g_return_if_fail (client == global_client); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
541 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
542 g_debug ("Emitting quit"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
543 g_signal_emit (client, signals[QUIT], 0); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
544 g_debug ("Done emitting quit"); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
545 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
546 /* FIXME: should we just call gtk_main_quit() here? */ |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
547 } |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
548 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
549 static void |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
550 egg_sm_client_debug_handler (const char *log_domain, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
551 GLogLevelFlags log_level, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
552 const char *message, |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
553 gpointer user_data) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
554 { |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
555 static int debug = -1; |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
556 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
557 if (debug < 0) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
558 debug = (g_getenv ("EGG_SM_CLIENT_DEBUG") != NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
559 |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
560 if (debug) |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
561 g_log_default_handler (log_domain, log_level, message, NULL); |
c942eaef7bc6
Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff
changeset
|
562 } |