~vikoadi/elementaryos/os-patch-indicator-session-trusty-fix-lock

« back to all changes in this revision

Viewing changes to src/guest.c

  • Committer: Cody Garver
  • Date: 2014-04-03 17:08:08 UTC
  • Revision ID: cody@elementaryos.org-20140403170808-z56s93rorb1dzvmk
Initial import, version 12.10.5+14.04.20140324-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *   Charles Kerr <charles.kerr@canonical.com>
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License version 3, as published
 
9
 * by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
 * PURPOSE.  See the GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "guest.h"
 
21
 
 
22
G_DEFINE_TYPE (IndicatorSessionGuest,
 
23
               indicator_session_guest,
 
24
               G_TYPE_OBJECT)
 
25
 
 
26
enum
 
27
{
 
28
  PROP_0,
 
29
  PROP_ALLOWED,
 
30
  PROP_LOGGED_IN,
 
31
  PROP_ACTIVE,
 
32
  PROP_LAST
 
33
};
 
34
 
 
35
static GParamSpec *properties[PROP_LAST];
 
36
 
 
37
static void
 
38
my_get_property (GObject     * o,
 
39
                 guint         property_id,
 
40
                 GValue      * value,
 
41
                 GParamSpec  * pspec)
 
42
{
 
43
  IndicatorSessionGuest * self = INDICATOR_SESSION_GUEST (o);
 
44
 
 
45
  switch (property_id)
 
46
    {
 
47
      case PROP_ALLOWED:
 
48
        g_value_set_boolean (value, indicator_session_guest_is_allowed (self));
 
49
        break;
 
50
 
 
51
      case PROP_LOGGED_IN:
 
52
        g_value_set_boolean (value, indicator_session_guest_is_logged_in (self));
 
53
        break;
 
54
 
 
55
      case PROP_ACTIVE:
 
56
        g_value_set_boolean (value, indicator_session_guest_is_active (self));
 
57
        break;
 
58
         
 
59
      default:
 
60
        G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
 
61
    }
 
62
}
 
63
 
 
64
static void
 
65
my_dispose (GObject *object)
 
66
{
 
67
  G_OBJECT_CLASS (indicator_session_guest_parent_class)->dispose (object);
 
68
}
 
69
 
 
70
static void
 
71
/* cppcheck-suppress unusedFunction */
 
72
indicator_session_guest_class_init (IndicatorSessionGuestClass * klass)
 
73
{
 
74
  GObjectClass * object_class;
 
75
  const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS;
 
76
 
 
77
  object_class = G_OBJECT_CLASS (klass);
 
78
  object_class->get_property = my_get_property;
 
79
  object_class->dispose = my_dispose;
 
80
 
 
81
  klass->is_allowed = NULL;
 
82
  klass->is_logged_in = NULL;
 
83
  klass->is_active = NULL;
 
84
  klass->switch_to_guest = NULL;
 
85
 
 
86
  properties[PROP_0] = NULL;
 
87
 
 
88
  properties[PROP_ALLOWED] =
 
89
    g_param_spec_boolean (INDICATOR_SESSION_GUEST_PROPERTY_ALLOWED,
 
90
                          "Is Allowed",
 
91
                          "Whether or not a Guest user is allowed",
 
92
                          FALSE, flags);
 
93
 
 
94
  properties[PROP_LOGGED_IN] =
 
95
    g_param_spec_boolean (INDICATOR_SESSION_GUEST_PROPERTY_LOGGED_IN,
 
96
                          "Is Logged In",
 
97
                          "Whether or not the Guest account is logged in",
 
98
                          FALSE, flags);
 
99
 
 
100
  properties[PROP_ACTIVE] =
 
101
    g_param_spec_boolean (INDICATOR_SESSION_GUEST_PROPERTY_ACTIVE,
 
102
                          "Is Active",
 
103
                          "If the Guest account has the current session",
 
104
                          FALSE, flags);
 
105
 
 
106
  g_object_class_install_properties (object_class, PROP_LAST, properties);
 
107
}
 
108
 
 
109
static void
 
110
/* cppcheck-suppress unusedFunction */
 
111
indicator_session_guest_init (IndicatorSessionGuest *self G_GNUC_UNUSED)
 
112
{
 
113
}
 
114
 
 
115
/***
 
116
****
 
117
***/
 
118
 
 
119
gboolean
 
120
indicator_session_guest_is_active (IndicatorSessionGuest * self)
 
121
{
 
122
  g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST (self), FALSE);
 
123
 
 
124
  return INDICATOR_SESSION_GUEST_GET_CLASS (self)->is_active (self);
 
125
}
 
126
 
 
127
gboolean
 
128
indicator_session_guest_is_allowed (IndicatorSessionGuest * self)
 
129
{
 
130
  g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST (self), FALSE);
 
131
 
 
132
  return INDICATOR_SESSION_GUEST_GET_CLASS (self)->is_allowed (self);
 
133
}
 
134
 
 
135
gboolean
 
136
indicator_session_guest_is_logged_in (IndicatorSessionGuest * self)
 
137
{
 
138
  g_return_val_if_fail (INDICATOR_IS_SESSION_GUEST (self), FALSE);
 
139
 
 
140
  return INDICATOR_SESSION_GUEST_GET_CLASS (self)->is_logged_in (self);
 
141
}
 
142
 
 
143
/***
 
144
****
 
145
***/
 
146
static void
 
147
notify_func (IndicatorSessionGuest * self, int prop)
 
148
{
 
149
  g_return_if_fail (INDICATOR_IS_SESSION_GUEST (self));
 
150
 
 
151
  g_debug ("%s %s emitting '%s' prop notify", G_STRLOC, G_STRFUNC, properties[prop]->name);
 
152
 
 
153
  g_object_notify_by_pspec (G_OBJECT(self), properties[prop]);
 
154
}
 
155
 
 
156
void
 
157
indicator_session_guest_notify_active (IndicatorSessionGuest * self)
 
158
{
 
159
  notify_func (self, PROP_ACTIVE);
 
160
}
 
161
 
 
162
void
 
163
indicator_session_guest_notify_allowed (IndicatorSessionGuest * self)
 
164
{
 
165
  notify_func (self, PROP_ALLOWED);
 
166
}
 
167
 
 
168
void
 
169
indicator_session_guest_notify_logged_in (IndicatorSessionGuest * self)
 
170
{
 
171
  notify_func (self, PROP_LOGGED_IN);
 
172
}
 
173
 
 
174
/***
 
175
****
 
176
***/
 
177
 
 
178
void
 
179
indicator_session_guest_switch_to_guest (IndicatorSessionGuest * self)
 
180
{
 
181
  gboolean allowed;
 
182
 
 
183
  g_return_if_fail (INDICATOR_IS_SESSION_GUEST (self));
 
184
 
 
185
  g_object_get (self, INDICATOR_SESSION_GUEST_PROPERTY_ALLOWED, &allowed, NULL);
 
186
  g_return_if_fail (allowed);
 
187
 
 
188
  INDICATOR_SESSION_GUEST_GET_CLASS (self)->switch_to_guest (self);
 
189
}
 
190