1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * moonlightconfiguration.cpp:
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.
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
);
35 MoonlightConfiguration::Save ()
38 gchar
*contents
= g_key_file_to_data (data
, &length
, NULL
);
39 char *dir
= g_path_get_dirname (filename
);
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
);
57 MoonlightConfiguration::SetBooleanValue (const char *group
, const char *key
, gboolean value
)
59 g_key_file_set_boolean (data
, group
, key
, value
);
63 MoonlightConfiguration::SetStringValue (const char *group
, const char *key
, const char *value
)
65 g_key_file_set_string (data
, group
, key
, value
);
69 MoonlightConfiguration::GetStringValue (const char *group
, const char *key
)
71 return g_key_file_get_string (data
, group
, key
, NULL
);
75 MoonlightConfiguration::GetBooleanValue (const char *group
, const char *key
)
77 return g_key_file_get_boolean (data
, group
, key
, NULL
);