~ci-train-bot/indicator-session/indicator-session-ubuntu-zesty-2188

« back to all changes in this revision

Viewing changes to src/users.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
 * 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 "users.h"
 
21
 
 
22
/* signals enum */
 
23
enum
 
24
{
 
25
  USER_ADDED,
 
26
  USER_REMOVED,
 
27
  USER_CHANGED,
 
28
  LAST_SIGNAL
 
29
};
 
30
 
 
31
static guint signals[LAST_SIGNAL] = { 0 };
 
32
 
 
33
G_DEFINE_TYPE (IndicatorSessionUsers, indicator_session_users, G_TYPE_OBJECT)
 
34
 
 
35
enum
 
36
{
 
37
  PROP_0,
 
38
  PROP_IS_LIVE_SESSION,
 
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
  IndicatorSessionUsers * self = INDICATOR_SESSION_USERS (o);
 
51
 
 
52
  switch (property_id)
 
53
    {
 
54
      case PROP_IS_LIVE_SESSION:
 
55
        g_value_set_boolean (value, indicator_session_users_is_live_session (self));
 
56
        break;
 
57
 
 
58
      default:
 
59
        G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
 
60
    }
 
61
}
 
62
 
 
63
static void
 
64
/* cppcheck-suppress unusedFunction */
 
65
indicator_session_users_class_init (IndicatorSessionUsersClass * klass)
 
66
{
 
67
  GObjectClass * object_class;
 
68
  const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS;
 
69
 
 
70
  object_class = G_OBJECT_CLASS (klass);
 
71
  object_class->get_property = my_get_property;
 
72
 
 
73
  signals[USER_ADDED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_ADDED,
 
74
                                      G_TYPE_FROM_CLASS(klass),
 
75
                                      G_SIGNAL_RUN_LAST,
 
76
                                      G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_added),
 
77
                                      NULL, NULL,
 
78
                                      g_cclosure_marshal_VOID__STRING,
 
79
                                      G_TYPE_NONE, 1, G_TYPE_STRING);
 
80
 
 
81
  signals[USER_REMOVED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_REMOVED,
 
82
                                        G_TYPE_FROM_CLASS(klass),
 
83
                                        G_SIGNAL_RUN_LAST,
 
84
                                        G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_removed),
 
85
                                        NULL, NULL,
 
86
                                        g_cclosure_marshal_VOID__STRING,
 
87
                                        G_TYPE_NONE, 1, G_TYPE_STRING);
 
88
 
 
89
  signals[USER_CHANGED] = g_signal_new (INDICATOR_SESSION_USERS_SIGNAL_USER_CHANGED,
 
90
                                        G_TYPE_FROM_CLASS(klass),
 
91
                                        G_SIGNAL_RUN_LAST,
 
92
                                        G_STRUCT_OFFSET (IndicatorSessionUsersClass, user_changed),
 
93
                                        NULL, NULL,
 
94
                                        g_cclosure_marshal_VOID__STRING,
 
95
                                        G_TYPE_NONE, 1, G_TYPE_STRING);
 
96
 
 
97
 
 
98
  properties[PROP_IS_LIVE_SESSION] =
 
99
    g_param_spec_boolean (INDICATOR_SESSION_USERS_PROP_IS_LIVE_SESSION,
 
100
                          "Is Live Session",
 
101
                          "Whether or this is a 'live session', such as booting from a live CD",
 
102
                          FALSE, flags);
 
103
 
 
104
  g_object_class_install_properties (object_class, PROP_LAST, properties);
 
105
 
 
106
}
 
107
 
 
108
static void
 
109
/* cppcheck-suppress unusedFunction */
 
110
indicator_session_users_init (IndicatorSessionUsers * self G_GNUC_UNUSED)
 
111
{
 
112
}
 
113
 
 
114
/***
 
115
****  Virtual Functions
 
116
***/
 
117
 
 
118
GStrv
 
119
indicator_session_users_get_keys (IndicatorSessionUsers * self)
 
120
{
 
121
  g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), NULL);
 
122
 
 
123
  return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_keys (self);
 
124
}
 
125
 
 
126
IndicatorSessionUser *
 
127
indicator_session_users_get_user (IndicatorSessionUsers * self,
 
128
                                  const char            * key)
 
129
{
 
130
  g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), NULL);
 
131
 
 
132
  return INDICATOR_SESSION_USERS_GET_CLASS (self)->get_user (self, key);
 
133
}
 
134
 
 
135
void
 
136
indicator_session_users_activate_user (IndicatorSessionUsers * self, 
 
137
                                       const char            * key)
 
138
{
 
139
  g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
 
140
 
 
141
  INDICATOR_SESSION_USERS_GET_CLASS (self)->activate_user (self, key);
 
142
}
 
143
 
 
144
gboolean
 
145
indicator_session_users_is_live_session (IndicatorSessionUsers * self)
 
146
{
 
147
  g_return_val_if_fail (INDICATOR_IS_SESSION_USERS (self), FALSE);
 
148
 
 
149
  return INDICATOR_SESSION_USERS_GET_CLASS (self)->is_live_session (self);
 
150
}
 
151
 
 
152
void
 
153
indicator_session_user_free (IndicatorSessionUser * user)
 
154
{
 
155
  g_return_if_fail (user != NULL);
 
156
 
 
157
  g_free (user->real_name);
 
158
  g_free (user->user_name);
 
159
  g_free (user->icon_file);
 
160
  g_free (user);
 
161
}
 
162
 
 
163
/***
 
164
****  Signal Convenience
 
165
***/
 
166
 
 
167
void
 
168
indicator_session_users_added (IndicatorSessionUsers * self, const char * key)
 
169
{
 
170
  g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
 
171
 
 
172
  g_signal_emit (self, signals[USER_ADDED], 0, key);
 
173
}
 
174
 
 
175
void
 
176
indicator_session_users_removed (IndicatorSessionUsers * self, const char * key)
 
177
{
 
178
  g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
 
179
 
 
180
  g_signal_emit (self, signals[USER_REMOVED], 0, key);
 
181
}
 
182
 
 
183
void
 
184
indicator_session_users_changed (IndicatorSessionUsers * self, const char * key)
 
185
{
 
186
  g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
 
187
 
 
188
  g_signal_emit (self, signals[USER_CHANGED], 0, key);
 
189
}
 
190
 
 
191
void
 
192
indicator_session_users_notify_is_live_session (IndicatorSessionUsers * self)
 
193
{
 
194
  g_return_if_fail (INDICATOR_IS_SESSION_USERS (self));
 
195
 
 
196
  g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_IS_LIVE_SESSION]);
 
197
}
 
198