1
/* gcompris - profile.c
3
* Time-stamp: <2006/08/21 23:26:49 bruno>
5
* Copyright (C) 2005 Bruno Coudoin
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
#include "properties.h"
26
/** Return the current profile or NULL if sqlite not activated
30
gc_profile_get_current()
32
GcomprisProperties *properties = gc_prop_get();
34
if (properties->profile)
35
return properties->profile;
37
properties->profile = gc_db_get_profile();
39
return properties->profile;
45
gc_profile_set_current_user(GcomprisUser *user)
47
GcomprisProperties *properties = gc_prop_get();
50
properties->logged_user = user;
52
g_warning("No user, getting one from system.");
53
GcomprisUser *sys_user = g_malloc0(sizeof(GcomprisUser));
55
const gchar *user_name = g_get_user_name ();
57
sys_user->login = g_strdup(user_name);
59
sys_user->login = g_strdup("nobody");
61
const gchar *last_name = g_get_real_name ();
63
sys_user->lastname = g_strdup(last_name);
65
sys_user->lastname = g_strdup("Nobody There ?");
67
sys_user->firstname = g_strdup("Unknown");
68
sys_user->birthdate = g_strdup("");
70
properties->logged_user = sys_user;
74
g_get_current_time (&now);
76
gchar *session_id_str = g_strdup_printf("%s%ld%ld", (properties->logged_user)->login, now.tv_sec, now.tv_usec);
78
(properties->logged_user)->session_id = g_str_hash((gconstpointer) session_id_str);
79
g_free(session_id_str);
83
void gc_profile_destroy(GcomprisProfile*prof)
89
g_free(prof->directory);
90
g_free(prof->description);
94
void gc_user_destroy(GcomprisUser*user)
100
g_free(user->lastname);
101
g_free(user->firstname);
102
g_free(user->birthdate);
107
gc_profile_get_current_user()
109
GcomprisProperties *properties = gc_prop_get();
110
return properties->logged_user;