~larsu/indicator-session/glib-deadlock-workaround

« back to all changes in this revision

Viewing changes to src/actions.c

  • Committer: Charles Kerr
  • Date: 2013-03-22 21:34:34 UTC
  • mto: (384.2.29 ng)
  • mto: This revision was merged to the branch mainline in revision 399.
  • Revision ID: charles.kerr@canonical.com-20130322213434-a85qbob8bi4fvfx2
port indicator-session to GMenu/cmake. Code coverage increased from 0% to 95.4%.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Copyright 2013 Canonical Ltd.
 
4
 *
 
5
 * Authors:
 
6
 *   Charles Kerr <charles.kerr@canonical.com>
 
7
 *
 
8
 * This program is free software: you can redistribute it and/or modify it
 
9
 * under the terms of the GNU General Public License version 3, as published
 
10
 * by the Free Software Foundation.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
14
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
15
 * PURPOSE.  See the GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along
 
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#include "actions.h"
 
22
 
 
23
/***
 
24
****  GObject Boilerplate
 
25
***/
 
26
 
 
27
G_DEFINE_TYPE (IndicatorSessionActions, indicator_session_actions, G_TYPE_OBJECT)
 
28
 
 
29
enum
 
30
{
 
31
  PROP_0,
 
32
  PROP_CAN_SWITCH,
 
33
  PROP_CAN_HIBERNATE,
 
34
  PROP_CAN_SUSPEND,
 
35
  PROP_CAN_LOCK,
 
36
  PROP_CAN_LOGOUT,
 
37
  PROP_CAN_PROMPT,
 
38
  PROP_HAS_ONLINE_ACCOUNT_ERROR,
 
39
  PROP_LAST
 
40
};
 
41
 
 
42
static GParamSpec *properties[PROP_LAST];
 
43
 
 
44
static void
 
45
my_get_property (GObject     * o,
 
46
                 guint         property_id,
 
47
                 GValue      * value,
 
48
                 GParamSpec  * pspec)
 
49
{
 
50
  IndicatorSessionActions * self = INDICATOR_SESSION_ACTIONS (o);
 
51
 
 
52
  switch (property_id)
 
53
    {
 
54
      case PROP_CAN_SWITCH:
 
55
        g_value_set_boolean (value, indicator_session_actions_can_switch (self));
 
56
        break;
 
57
 
 
58
      case PROP_CAN_HIBERNATE:
 
59
        g_value_set_boolean (value, indicator_session_actions_can_hibernate (self));
 
60
        break;
 
61
 
 
62
      case PROP_CAN_SUSPEND:
 
63
        g_value_set_boolean (value, indicator_session_actions_can_suspend (self));
 
64
        break;
 
65
 
 
66
      case PROP_CAN_LOCK:
 
67
        g_value_set_boolean (value, indicator_session_actions_can_lock (self));
 
68
        break;
 
69
 
 
70
      case PROP_CAN_LOGOUT:
 
71
        g_value_set_boolean (value, indicator_session_actions_can_logout (self));
 
72
        break;
 
73
 
 
74
      case PROP_CAN_PROMPT:
 
75
        g_value_set_boolean (value, indicator_session_actions_can_prompt (self));
 
76
        break;
 
77
 
 
78
      case PROP_HAS_ONLINE_ACCOUNT_ERROR:
 
79
        g_value_set_boolean (value, indicator_session_actions_has_online_account_error (self));
 
80
        break;
 
81
 
 
82
      default:
 
83
        G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
 
84
    }
 
85
}
 
86
 
 
87
static void
 
88
/* cppcheck-suppress unusedFunction */
 
89
indicator_session_actions_class_init (IndicatorSessionActionsClass * klass)
 
90
{
 
91
  GObjectClass * object_class;
 
92
  const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS;
 
93
 
 
94
  object_class = G_OBJECT_CLASS (klass);
 
95
  object_class->get_property = my_get_property;
 
96
 
 
97
  klass->can_lock = NULL;
 
98
  klass->can_logout = NULL;
 
99
  klass->can_switch = NULL;
 
100
  klass->can_suspend = NULL;
 
101
  klass->can_hibernate = NULL;
 
102
  klass->has_online_account_error = NULL;
 
103
  klass->logout = NULL;
 
104
  klass->suspend = NULL;
 
105
  klass->hibernate = NULL;
 
106
  klass->restart = NULL;
 
107
  klass->shutdown = NULL;
 
108
  klass->switch_to_screensaver = NULL;
 
109
  klass->switch_to_greeter = NULL;
 
110
  klass->switch_to_guest = NULL;
 
111
  klass->switch_to_username = NULL;
 
112
 
 
113
  /* properties */
 
114
 
 
115
  properties[PROP_0] = NULL;
 
116
 
 
117
  properties[PROP_CAN_SWITCH] =
 
118
    g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_SWITCH,
 
119
                          "Can Switch Sessions",
 
120
                          "Whether or not the system services allow session switching",
 
121
                          TRUE, flags);
 
122
 
 
123
  properties[PROP_CAN_HIBERNATE] =
 
124
    g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_HIBERNATE,
 
125
                          "Can Hibernate",
 
126
                          "Whether or not the system services allow the user to hibernate",
 
127
                          TRUE, flags);
 
128
 
 
129
  properties[PROP_CAN_SUSPEND] =
 
130
    g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_SUSPEND,
 
131
                          "Can Suspend",
 
132
                          "Whether or not the system services allow the user to suspend",
 
133
                          TRUE, flags);
 
134
 
 
135
  properties[PROP_CAN_LOCK] =
 
136
    g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_LOCK,
 
137
                          "Can Lock",
 
138
                          "Whether or not the system services allow the user to lock the screen",
 
139
                          TRUE, flags);
 
140
 
 
141
  properties[PROP_CAN_LOGOUT] =
 
142
    g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_LOGOUT,
 
143
                          "Can Logout",
 
144
                          "Whether or not the system services allow the user to logout",
 
145
                          TRUE, flags);
 
146
 
 
147
  properties[PROP_CAN_PROMPT] =
 
148
    g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_CAN_PROMPT,
 
149
                          "Can Show End Session Dialog",
 
150
                          "Whether or not we can show an End Session dialog",
 
151
                          TRUE, flags);
 
152
 
 
153
  properties[PROP_HAS_ONLINE_ACCOUNT_ERROR] =
 
154
    g_param_spec_boolean (INDICATOR_SESSION_ACTIONS_PROP_HAS_ONLINE_ACCOUNT_ERROR,
 
155
                          "Has Online Account Error",
 
156
                          "Whether or not an online account setting requires attention from the user",
 
157
                          FALSE, flags);
 
158
 
 
159
  g_object_class_install_properties (object_class, PROP_LAST, properties);
 
160
}
 
161
 
 
162
static void
 
163
/* cppcheck-suppress unusedFunction */
 
164
indicator_session_actions_init (IndicatorSessionActions * self G_GNUC_UNUSED)
 
165
{
 
166
}
 
167
 
 
168
/***
 
169
**** 
 
170
***/
 
171
 
 
172
gboolean
 
173
indicator_session_actions_can_lock (IndicatorSessionActions * self)
 
174
{
 
175
  g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
 
176
 
 
177
  return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_lock (self);
 
178
}
 
179
 
 
180
gboolean
 
181
indicator_session_actions_can_logout (IndicatorSessionActions * self)
 
182
{
 
183
  g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
 
184
 
 
185
  return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_logout (self);
 
186
}
 
187
 
 
188
gboolean
 
189
indicator_session_actions_can_switch (IndicatorSessionActions * self)
 
190
{
 
191
  g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
 
192
 
 
193
  return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_switch (self);
 
194
}
 
195
 
 
196
gboolean
 
197
indicator_session_actions_can_suspend (IndicatorSessionActions * self)
 
198
{
 
199
  g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
 
200
 
 
201
  return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_suspend (self);
 
202
}
 
203
 
 
204
gboolean
 
205
indicator_session_actions_can_hibernate (IndicatorSessionActions * self)
 
206
{
 
207
  g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
 
208
 
 
209
  return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_hibernate (self);
 
210
}
 
211
 
 
212
gboolean
 
213
indicator_session_actions_can_prompt (IndicatorSessionActions * self)
 
214
{
 
215
  g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
 
216
 
 
217
  return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->can_prompt (self);
 
218
}
 
219
 
 
220
gboolean
 
221
indicator_session_actions_has_online_account_error (IndicatorSessionActions * self)
 
222
{
 
223
  g_return_val_if_fail (INDICATOR_IS_SESSION_ACTIONS (self), FALSE);
 
224
 
 
225
  return INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->has_online_account_error (self);
 
226
}
 
227
 
 
228
/***
 
229
****
 
230
***/
 
231
 
 
232
void
 
233
indicator_session_actions_settings (IndicatorSessionActions * self)
 
234
{
 
235
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
236
 
 
237
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->settings (self);
 
238
}
 
239
 
 
240
void
 
241
indicator_session_actions_logout (IndicatorSessionActions * self)
 
242
{
 
243
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
244
 
 
245
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->logout (self);
 
246
}
 
247
 
 
248
void
 
249
indicator_session_actions_shutdown (IndicatorSessionActions * self)
 
250
{
 
251
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
252
 
 
253
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->shutdown (self);
 
254
}
 
255
 
 
256
void
 
257
indicator_session_actions_help (IndicatorSessionActions * self)
 
258
{
 
259
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
260
 
 
261
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->help (self);
 
262
}
 
263
 
 
264
void
 
265
indicator_session_actions_about (IndicatorSessionActions * self)
 
266
{
 
267
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
268
 
 
269
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->about (self);
 
270
}
 
271
 
 
272
void
 
273
indicator_session_actions_restart (IndicatorSessionActions * self)
 
274
{
 
275
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
276
 
 
277
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->restart (self);
 
278
}
 
279
 
 
280
void
 
281
indicator_session_actions_suspend (IndicatorSessionActions * self)
 
282
{
 
283
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
284
 
 
285
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->suspend (self);
 
286
}
 
287
 
 
288
void
 
289
indicator_session_actions_hibernate (IndicatorSessionActions * self)
 
290
{
 
291
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
292
 
 
293
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->hibernate (self);
 
294
}
 
295
 
 
296
void
 
297
indicator_session_actions_switch_to_screensaver (IndicatorSessionActions * self)
 
298
{
 
299
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
300
 
 
301
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_screensaver (self);
 
302
}
 
303
 
 
304
void
 
305
indicator_session_actions_switch_to_greeter (IndicatorSessionActions * self)
 
306
{
 
307
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
308
 
 
309
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_greeter (self);
 
310
}
 
311
 
 
312
void
 
313
indicator_session_actions_switch_to_guest (IndicatorSessionActions * self)
 
314
{
 
315
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
316
 
 
317
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_guest (self);
 
318
}
 
319
 
 
320
void
 
321
indicator_session_actions_switch_to_username (IndicatorSessionActions * self,
 
322
                                              const gchar             * username)
 
323
{
 
324
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
325
 
 
326
  INDICATOR_SESSION_ACTIONS_GET_CLASS (self)->switch_to_username (self, username);
 
327
}
 
328
 
 
329
/***
 
330
****
 
331
***/
 
332
 
 
333
static void
 
334
notify_func (IndicatorSessionActions * self, int prop)
 
335
{
 
336
  g_return_if_fail (INDICATOR_IS_SESSION_ACTIONS (self));
 
337
 
 
338
  g_debug ("%s %s emitting '%s' prop notify", G_STRLOC, G_STRFUNC, properties[prop]->name);
 
339
 
 
340
  g_object_notify_by_pspec (G_OBJECT(self), properties[prop]);
 
341
}
 
342
 
 
343
void
 
344
indicator_session_actions_notify_can_lock (IndicatorSessionActions * self)
 
345
{
 
346
  notify_func (self, PROP_CAN_LOCK);
 
347
}
 
348
 
 
349
void
 
350
indicator_session_actions_notify_can_logout (IndicatorSessionActions * self)
 
351
{
 
352
  notify_func (self, PROP_CAN_LOGOUT);
 
353
}
 
354
 
 
355
void
 
356
indicator_session_actions_notify_can_switch (IndicatorSessionActions * self)
 
357
{
 
358
  notify_func (self, PROP_CAN_SWITCH);
 
359
}
 
360
 
 
361
void
 
362
indicator_session_actions_notify_can_suspend (IndicatorSessionActions * self)
 
363
{
 
364
  notify_func (self, PROP_CAN_SUSPEND);
 
365
}
 
366
 
 
367
void
 
368
indicator_session_actions_notify_can_hibernate (IndicatorSessionActions * self)
 
369
{
 
370
  notify_func (self, PROP_CAN_HIBERNATE);
 
371
}
 
372
 
 
373
void
 
374
indicator_session_actions_notify_can_prompt (IndicatorSessionActions * self)
 
375
{
 
376
  notify_func (self, PROP_CAN_PROMPT);
 
377
}
 
378
 
 
379
void
 
380
indicator_session_actions_notify_has_online_account_error (IndicatorSessionActions * self)
 
381
{
 
382
  notify_func (self, PROP_HAS_ONLINE_ACCOUNT_ERROR);
 
383
}