blob: cb45339b7c5dd7240e5cc7f6e52e86c3d27ac099 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* gcompris - profile.c
*
* Copyright (C) 2005 Bruno Coudoin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "gcompris.h"
#include "properties.h"
/** Return the current profile or NULL if sqlite not activated
*
*/
GcomprisProfile*
gc_profile_get_current()
{
GcomprisProperties *properties = gc_prop_get();
if (properties->profile)
return properties->profile;
properties->profile = gc_db_get_profile();
return properties->profile;
}
void
gc_profile_set_current_user(GcomprisUser *user)
{
GcomprisProperties *properties = gc_prop_get();
if (user)
properties->logged_user = user;
else {
g_warning("No user, getting one from system.");
GcomprisUser *sys_user = g_malloc0(sizeof(GcomprisUser));
const gchar *user_name = g_get_user_name ();
if (user_name)
sys_user->login = g_strdup(user_name);
else
sys_user->login = g_strdup("nobody");
const gchar *last_name = g_get_real_name ();
if (last_name)
sys_user->lastname = g_strdup(last_name);
else
sys_user->lastname = g_strdup("Nobody There ?");
sys_user->firstname = g_strdup("Unknown");
sys_user->birthdate = g_strdup("");
sys_user->user_id = -1;
properties->logged_user = sys_user;
}
GTimeVal now;
g_get_current_time (&now);
gchar *session_id_str = g_strdup_printf("%s%ld%ld", (properties->logged_user)->login, now.tv_sec, now.tv_usec);
(properties->logged_user)->session_id = g_str_hash((gconstpointer) session_id_str);
g_free(session_id_str);
}
void gc_profile_destroy(GcomprisProfile*prof)
{
if(!prof)
return;
g_free(prof->name);
g_free(prof->directory);
g_free(prof->description);
g_free(prof);
}
void gc_user_destroy(GcomprisUser*user)
{
if(!user)
return;
g_free(user->login);
g_free(user->lastname);
g_free(user->firstname);
g_free(user->birthdate);
g_free(user);
}
GcomprisUser*
gc_profile_get_current_user()
{
GcomprisProperties *properties = gc_prop_get();
return properties->logged_user;
}
|