~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to src/moonlightconfiguration.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * moonlightconfiguration.cpp: 
 
4
 *
 
5
 * Contact:
 
6
 *   Moonlight List (moonlight-list@lists.ximian.com)
 
7
 *
 
8
 * Copyright 2007 Novell, Inc. (http://www.novell.com)
 
9
 *
 
10
 * See the LICENSE file included with the distribution for details.
 
11
 */
 
12
 
 
13
#include <config.h>
 
14
#include <stdio.h>
 
15
#include <errno.h>
 
16
#include <string.h>
 
17
 
 
18
#include "moonlightconfiguration.h"
 
19
 
 
20
MoonlightConfiguration::MoonlightConfiguration ()
 
21
{
 
22
        filename = g_build_filename (g_get_user_config_dir (), "moonlight", "configuration", NULL);;
 
23
        data = g_key_file_new ();
 
24
        // We don't care about errors.
 
25
        g_key_file_load_from_file (data, filename, (GKeyFileFlags) (G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS), NULL);
 
26
}
 
27
 
 
28
MoonlightConfiguration::~MoonlightConfiguration ()
 
29
{
 
30
        g_key_file_free (data);
 
31
        g_free (filename);
 
32
}
 
33
 
 
34
void
 
35
MoonlightConfiguration::Save ()
 
36
{
 
37
        gsize length;
 
38
        gchar *contents = g_key_file_to_data (data, &length, NULL);
 
39
        char *dir = g_path_get_dirname (filename);
 
40
        GError *error = NULL;
 
41
 
 
42
        // Make sure the directory exists
 
43
        if (g_mkdir_with_parents (dir, 0700) == -1)
 
44
                fprintf (stderr, "Moonlight: Could not create configuration directory '%s': %s.\n", dir, strerror (errno));
 
45
 
 
46
 
 
47
        if (!g_file_set_contents (filename, contents, length, &error)) {
 
48
                fprintf (stderr, "Moonlight: Could not store configuration in '%s': %s.\n", filename, error->message);
 
49
                g_error_free (error);
 
50
        }
 
51
 
 
52
        g_free (contents);
 
53
        g_free (dir);
 
54
}
 
55
        
 
56
void 
 
57
MoonlightConfiguration::SetBooleanValue (const char *group, const char *key, gboolean value)
 
58
{
 
59
        g_key_file_set_boolean (data, group, key, value);
 
60
}
 
61
 
 
62
void
 
63
MoonlightConfiguration::SetStringValue (const char *group, const char *key, const char *value)
 
64
{
 
65
        g_key_file_set_string (data, group, key, value);
 
66
}
 
67
 
 
68
char *
 
69
MoonlightConfiguration::GetStringValue (const char *group, const char *key)
 
70
{
 
71
        return g_key_file_get_string (data, group, key, NULL);
 
72
}
 
73
 
 
74
gboolean
 
75
MoonlightConfiguration::GetBooleanValue (const char *group, const char *key)
 
76
{
 
77
        return g_key_file_get_boolean (data, group, key, NULL);
 
78
}
 
79