Back to index

gcompris  8.2.2
profile.c
Go to the documentation of this file.
00001 /* gcompris - profile.c
00002  *
00003  * Time-stamp: <2006/08/21 23:26:49 bruno>
00004  *
00005  * Copyright (C) 2005 Bruno Coudoin
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020  */
00021 
00022 #include <stdio.h>
00023 #include "gcompris.h"
00024 #include "properties.h"
00025 
00029 GcomprisProfile*
00030 gc_profile_get_current()
00031 {
00032   GcomprisProperties *properties = gc_prop_get();
00033 
00034   if (properties->profile)
00035     return properties->profile;
00036 
00037   properties->profile = gc_db_get_profile();
00038 
00039   return properties->profile;
00040 
00041 }
00042 
00043 
00044 void
00045 gc_profile_set_current_user(GcomprisUser *user)
00046 {
00047   GcomprisProperties *properties = gc_prop_get();
00048 
00049   if (user)
00050     properties->logged_user = user;
00051   else {
00052     g_warning("No user, getting one from system.");
00053     GcomprisUser *sys_user = g_malloc0(sizeof(GcomprisUser));
00054 
00055     const gchar *user_name = g_get_user_name ();
00056     if (user_name)
00057       sys_user->login = g_strdup(user_name);
00058     else
00059       sys_user->login = g_strdup("nobody");
00060 
00061     const gchar *last_name = g_get_real_name ();
00062     if (last_name)
00063       sys_user->lastname = g_strdup(last_name);
00064     else
00065       sys_user->lastname = g_strdup("Nobody There ?");
00066 
00067     sys_user->firstname = g_strdup("Unknown");
00068     sys_user->birthdate = g_strdup("");
00069 
00070     properties->logged_user = sys_user;
00071   }
00072 
00073   GTimeVal now;
00074   g_get_current_time (&now);
00075 
00076   gchar *session_id_str = g_strdup_printf("%s%ld%ld", (properties->logged_user)->login, now.tv_sec, now.tv_usec);
00077 
00078   (properties->logged_user)->session_id = g_str_hash((gconstpointer) session_id_str);
00079   g_free(session_id_str);
00080 
00081 }
00082 
00083 void gc_profile_destroy(GcomprisProfile*prof)
00084 {
00085   if(!prof)
00086     return;
00087 
00088   g_free(prof->name);
00089   g_free(prof->directory);
00090   g_free(prof->description);
00091   g_free(prof);
00092 }
00093 
00094 void gc_user_destroy(GcomprisUser*user)
00095 {
00096   if(!user)
00097     return;
00098 
00099   g_free(user->login);
00100   g_free(user->lastname);
00101   g_free(user->firstname);
00102   g_free(user->birthdate);
00103   g_free(user);
00104 }
00105 
00106 GcomprisUser*
00107 gc_profile_get_current_user()
00108 {
00109   GcomprisProperties *properties = gc_prop_get();
00110   return properties->logged_user;
00111 }
00112