GCC Code Coverage Report


Directory: ./
File: panels/sharing/cc-media-sharing.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 59 0.0%
Functions: 0 3 0.0%
Branches: 0 26 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2013 Intel, Inc
3 *
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.
8 *
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.
13 *
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.
17 *
18 * Author: Thomas Wood <thomas.wood@intel.com>
19 *
20 */
21
22 #include "cc-media-sharing.h"
23
24 #include <gio/gio.h>
25 #include <gio/gdesktopappinfo.h>
26 #include <glib/gstdio.h>
27
28 static GKeyFile*
29 cc_media_sharing_open_key_file (void)
30 {
31 g_autofree gchar *path = NULL;
32 GKeyFile *file;
33
34 file = g_key_file_new ();
35
36 path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL);
37
38 if (!g_key_file_load_from_file (file, path,
39 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
40 NULL))
41 {
42 g_autofree gchar *sysconf_path = NULL;
43 sysconf_path = g_build_filename (SYSCONFDIR, "rygel.conf", NULL);
44 g_key_file_load_from_file (file, sysconf_path,
45 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
46 NULL);
47 }
48
49 return file;
50 }
51
52 void
53 cc_media_sharing_get_preferences (gchar ***folders)
54 {
55 g_autoptr(GKeyFile) file = NULL;
56
57 file = cc_media_sharing_open_key_file ();
58
59 if (folders)
60 {
61 gsize length;
62 GPtrArray *array;
63 GStrv str_list;
64 g_auto(GStrv) orig_list = NULL;
65
66 str_list = g_key_file_get_string_list (file, "MediaExport", "uris",
67 &length, NULL);
68 orig_list = str_list;
69 array = g_ptr_array_new ();
70
71 while (str_list && *str_list)
72 {
73 const char *dir;
74
75 if (g_str_equal (*str_list, "@MUSIC@"))
76 dir = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
77 else if (g_str_equal (*str_list, "@VIDEOS@"))
78 dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
79 else if (g_str_equal (*str_list, "@PICTURES@"))
80 dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
81 else
82 dir = g_strdup (*str_list);
83
84 if (dir != NULL)
85 g_ptr_array_add (array, g_strdup (dir));
86
87 str_list++;
88 }
89
90 g_ptr_array_add (array, NULL);
91
92 *folders = (char **) g_ptr_array_free (array, FALSE);
93 }
94 }
95
96 void
97 cc_media_sharing_set_preferences (gchar **folders)
98 {
99 g_autoptr(GKeyFile) file = NULL;
100 gchar **str_list;
101 g_autofree gchar *path = NULL;
102 gsize length;
103 g_autofree gchar *data = NULL;
104
105 file = cc_media_sharing_open_key_file ();
106
107 g_key_file_set_boolean (file, "general", "upnp-enabled", TRUE);
108 g_key_file_set_boolean (file, "Tracker", "enabled", FALSE);
109 g_key_file_set_boolean (file, "Tracker3", "enabled", FALSE);
110 g_key_file_set_boolean (file, "MediaExport", "enabled", TRUE);
111
112 str_list = folders;
113 length = 0;
114
115 while (str_list && *str_list)
116 {
117 if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC)) == 0)
118 {
119 g_free (*str_list);
120 *str_list = g_strdup ("@MUSIC@");
121 }
122
123 if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS)) == 0)
124 {
125 g_free (*str_list);
126 *str_list = g_strdup ("@VIDEOS@");
127 }
128
129 if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)) == 0)
130 {
131 g_free (*str_list);
132 *str_list = g_strdup ("@PICTURES@");
133 }
134
135 str_list++;
136 length++;
137 }
138
139 g_key_file_set_string_list (file, "MediaExport", "uris", (const gchar**) folders, length);
140
141 data = g_key_file_to_data (file, NULL, NULL);
142
143 path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL);
144
145 g_file_set_contents (path, data, -1, NULL);
146 }
147