~ubuntu-branches/ubuntu/trusty/gcompris/trusty

« back to all changes in this revision

Viewing changes to src/gcompris/profile.c

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2006-12-15 23:08:17 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215230817-exr5ks1hd73s3tlk
Tags: 8.2.2-1
* New upstream bugfix release, fixes among other things the support for
  the version of gnucap shipped in etch.
* Add missing dependency on python-gtk2 (Closes: #396523).
* Removed reference to non-existent sound file from memory.c (upstream
  fix - impacts 8.2 as well).  
* Now suggests gnuchess, gnucap, and tuxpaint.
* Updated extended description for the main package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gcompris - profile.c
 
2
 *
 
3
 * Time-stamp: <2006/08/21 23:26:49 bruno>
 
4
 *
 
5
 * Copyright (C) 2005 Bruno Coudoin
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#include <stdio.h>
 
23
#include "gcompris.h"
 
24
#include "properties.h"
 
25
 
 
26
/** Return the current profile or NULL if sqlite not activated
 
27
 *
 
28
 */
 
29
GcomprisProfile*
 
30
gc_profile_get_current()
 
31
{
 
32
  GcomprisProperties    *properties = gc_prop_get();
 
33
 
 
34
  if (properties->profile)
 
35
    return properties->profile;
 
36
 
 
37
  properties->profile = gc_db_get_profile();
 
38
 
 
39
  return properties->profile;
 
40
 
 
41
}
 
42
 
 
43
 
 
44
void
 
45
gc_profile_set_current_user(GcomprisUser *user)
 
46
{
 
47
  GcomprisProperties    *properties = gc_prop_get();
 
48
 
 
49
  if (user)
 
50
    properties->logged_user = user;
 
51
  else {
 
52
    g_warning("No user, getting one from system.");
 
53
    GcomprisUser *sys_user = g_malloc0(sizeof(GcomprisUser));
 
54
 
 
55
    const gchar *user_name = g_get_user_name ();
 
56
    if (user_name)
 
57
      sys_user->login = g_strdup(user_name);
 
58
    else
 
59
      sys_user->login = g_strdup("nobody");
 
60
 
 
61
    const gchar *last_name = g_get_real_name ();
 
62
    if (last_name)
 
63
      sys_user->lastname = g_strdup(last_name);
 
64
    else
 
65
      sys_user->lastname = g_strdup("Nobody There ?");
 
66
 
 
67
    sys_user->firstname = g_strdup("Unknown");
 
68
    sys_user->birthdate = g_strdup("");
 
69
 
 
70
    properties->logged_user = sys_user;
 
71
  }
 
72
 
 
73
  GTimeVal now;
 
74
  g_get_current_time (&now);
 
75
 
 
76
  gchar *session_id_str = g_strdup_printf("%s%ld%ld", (properties->logged_user)->login, now.tv_sec, now.tv_usec);
 
77
 
 
78
  (properties->logged_user)->session_id = g_str_hash((gconstpointer) session_id_str);
 
79
  g_free(session_id_str);
 
80
 
 
81
}
 
82
 
 
83
void gc_profile_destroy(GcomprisProfile*prof)
 
84
{
 
85
  if(!prof)
 
86
    return;
 
87
 
 
88
  g_free(prof->name);
 
89
  g_free(prof->directory);
 
90
  g_free(prof->description);
 
91
  g_free(prof);
 
92
}
 
93
 
 
94
void gc_user_destroy(GcomprisUser*user)
 
95
{
 
96
  if(!user)
 
97
    return;
 
98
 
 
99
  g_free(user->login);
 
100
  g_free(user->lastname);
 
101
  g_free(user->firstname);
 
102
  g_free(user->birthdate);
 
103
  g_free(user);
 
104
}
 
105
 
 
106
GcomprisUser*
 
107
gc_profile_get_current_user()
 
108
{
 
109
  GcomprisProperties    *properties = gc_prop_get();
 
110
  return properties->logged_user;
 
111
}
 
112