2009-12-01 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / moonlightconfiguration.cpp
blob9f8e790dfd2428e03a5c0205c96f5610cf825337
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * moonlightconfiguration.cpp:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #include <config.h>
14 #include <stdio.h>
15 #include <errno.h>
16 #include <string.h>
18 #include "moonlightconfiguration.h"
20 MoonlightConfiguration::MoonlightConfiguration ()
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);
28 MoonlightConfiguration::~MoonlightConfiguration ()
30 g_key_file_free (data);
31 g_free (filename);
34 void
35 MoonlightConfiguration::Save ()
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;
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));
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);
52 g_free (contents);
53 g_free (dir);
56 void
57 MoonlightConfiguration::SetBooleanValue (const char *group, const char *key, gboolean value)
59 g_key_file_set_boolean (data, group, key, value);
62 void
63 MoonlightConfiguration::SetStringValue (const char *group, const char *key, const char *value)
65 g_key_file_set_string (data, group, key, value);
68 char *
69 MoonlightConfiguration::GetStringValue (const char *group, const char *key)
71 return g_key_file_get_string (data, group, key, NULL);
74 gboolean
75 MoonlightConfiguration::GetBooleanValue (const char *group, const char *key)
77 return g_key_file_get_boolean (data, group, key, NULL);