2
* Copyright (C) 2013 Intel, Inc
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
* Author: Thomas Wood <thomas.wood@intel.com>
22
#include "cc-media-sharing.h"
25
#include <gio/gdesktopappinfo.h>
26
#include <glib/gstdio.h>
29
cc_media_sharing_open_key_file (void)
34
file = g_key_file_new ();
36
path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL);
38
if (!g_key_file_load_from_file (file, path,
39
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
43
path = g_build_filename (SYSCONFDIR, "rygel.conf", NULL);
44
g_key_file_load_from_file (file, path,
45
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
55
cc_media_sharing_get_preferences (gchar ***folders)
59
file = cc_media_sharing_open_key_file ();
65
char **str_list, **orig_list;
67
str_list = g_key_file_get_string_list (file, "MediaExport", "uris",
70
array = g_ptr_array_new ();
72
while (str_list && *str_list)
76
if (g_str_equal (*str_list, "@MUSIC@"))
77
dir = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
78
else if (g_str_equal (*str_list, "@VIDEOS@"))
79
dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
80
else if (g_str_equal (*str_list, "@PICTURES@"))
81
dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
83
dir = g_strdup (*str_list);
86
g_ptr_array_add (array, g_strdup (dir));
91
g_ptr_array_add (array, NULL);
93
*folders = (char **) g_ptr_array_free (array, FALSE);
94
g_strfreev (orig_list);
97
g_key_file_free (file);
101
cc_media_sharing_set_preferences (gchar **folders)
109
file = cc_media_sharing_open_key_file ();
111
g_key_file_set_boolean (file, "general", "upnp-enabled", TRUE);
112
g_key_file_set_boolean (file, "Tracker", "enabled", FALSE);
113
g_key_file_set_boolean (file, "MediaExport", "enabled", TRUE);
118
while (str_list && *str_list)
120
if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC)) == 0)
123
*str_list = g_strdup ("@MUSIC@");
126
if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS)) == 0)
129
*str_list = g_strdup ("@VIDEOS@");
132
if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)) == 0)
135
*str_list = g_strdup ("@PICTURES@");
142
g_key_file_set_string_list (file, "MediaExport", "uris", (const gchar**) folders, length);
144
data = g_key_file_to_data (file, NULL, NULL);
146
path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL);
148
g_file_set_contents (path, data, -1, NULL);
152
g_key_file_free (file);