2
* Copyright 2013 Canonical Ltd.
5
* Charles Kerr <charles.kerr@canonical.com>
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.
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.
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/>.
20
#include "backend-mock.h"
21
#include "backend-mock-users.h"
23
struct _IndicatorSessionUsersMockPriv
28
typedef IndicatorSessionUsersMockPriv priv_t;
30
G_DEFINE_TYPE (IndicatorSessionUsersMock,
31
indicator_session_users_mock,
32
INDICATOR_TYPE_SESSION_USERS)
35
**** IndicatorSessionUsers virtual functions
39
my_is_live_session (IndicatorSessionUsers * users G_GNUC_UNUSED)
41
return g_settings_get_boolean (mock_settings, "is-live-session");
45
my_activate_user (IndicatorSessionUsers * users, guint uid)
47
g_message ("%s %s users %p uid %u FIXME", G_STRLOC, G_STRFUNC, (void*)users, uid);
51
my_get_uids (IndicatorSessionUsers * users)
53
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(users), NULL);
55
return g_hash_table_get_keys (INDICATOR_SESSION_USERS_MOCK(users)->priv->users);
58
static IndicatorSessionUser *
59
my_get_user (IndicatorSessionUsers * self, guint uid)
62
const IndicatorSessionUser * src;
63
IndicatorSessionUser * ret = NULL;
65
g_return_val_if_fail (INDICATOR_IS_SESSION_USERS_MOCK(self), NULL);
66
p = INDICATOR_SESSION_USERS_MOCK (self)->priv;
68
if ((src = g_hash_table_lookup (p->users, GUINT_TO_POINTER(uid))))
70
ret = g_new0 (IndicatorSessionUser, 1);
71
ret->is_current_user = src->is_current_user;
72
ret->is_logged_in = src->is_logged_in;
74
ret->login_frequency = src->login_frequency;
75
ret->user_name = g_strdup (src->user_name);
76
ret->real_name = g_strdup (src->real_name);
77
ret->icon_file = g_strdup (src->icon_file);
84
**** GObject virtual functions
88
my_dispose (GObject * o)
90
G_OBJECT_CLASS (indicator_session_users_mock_parent_class)->dispose (o);
94
my_finalize (GObject * o)
96
priv_t * p = INDICATOR_SESSION_USERS_MOCK (o)->priv;
98
g_hash_table_destroy (p->users);
100
G_OBJECT_CLASS (indicator_session_users_mock_parent_class)->finalize (o);
104
**** GObject boilerplate
108
/* cppcheck-suppress unusedFunction */
109
indicator_session_users_mock_class_init (IndicatorSessionUsersMockClass * klass)
111
GObjectClass * object_class;
112
IndicatorSessionUsersClass * users_class;
114
object_class = G_OBJECT_CLASS (klass);
115
object_class->dispose = my_dispose;
116
object_class->finalize = my_finalize;
118
users_class = INDICATOR_SESSION_USERS_CLASS (klass);
119
users_class->is_live_session = my_is_live_session;
120
users_class->get_uids = my_get_uids;
121
users_class->get_user = my_get_user;
122
users_class->activate_user = my_activate_user;
124
g_type_class_add_private (klass, sizeof (IndicatorSessionUsersMockPriv));
128
/* cppcheck-suppress unusedFunction */
129
indicator_session_users_mock_init (IndicatorSessionUsersMock * self)
133
p = G_TYPE_INSTANCE_GET_PRIVATE (self,
134
INDICATOR_TYPE_SESSION_USERS_MOCK,
135
IndicatorSessionUsersMockPriv);
138
p->users = g_hash_table_new_full (g_direct_hash,
141
(GDestroyNotify)indicator_session_user_free);
143
g_signal_connect_swapped (mock_settings, "changed::is-live-session",
144
G_CALLBACK(indicator_session_users_notify_is_live_session), self);
151
IndicatorSessionUsers *
152
indicator_session_users_mock_new (void)
154
gpointer o = g_object_new (INDICATOR_TYPE_SESSION_USERS_MOCK, NULL);
156
return INDICATOR_SESSION_USERS (o);
161
indicator_session_users_mock_add_user (IndicatorSessionUsersMock * self,
162
IndicatorSessionUser * user)
164
g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self));
165
g_return_if_fail (user != NULL);
166
g_return_if_fail (user->uid > 0);
167
g_return_if_fail (!g_hash_table_contains (self->priv->users, GUINT_TO_POINTER(user->uid)));
169
g_hash_table_insert (self->priv->users, GUINT_TO_POINTER(user->uid), user);
170
indicator_session_users_added (INDICATOR_SESSION_USERS (self), user->uid);
174
indicator_session_users_mock_remove_user (IndicatorSessionUsersMock * self,
177
g_return_if_fail (INDICATOR_IS_SESSION_USERS_MOCK (self));
178
g_return_if_fail (uid > 0);
180
g_hash_table_remove (self->priv->users, GUINT_TO_POINTER(uid));
181
indicator_session_users_removed (INDICATOR_SESSION_USERS (self), uid);