~khurshid-alam/unity-control-center/sharing-panel

« back to all changes in this revision

Viewing changes to panels/sharing/cc-media-sharing.c

  • Committer: Khurshid Alam
  • Date: 2018-03-12 14:06:28 UTC
  • Revision ID: khurshid.alam@linuxmail.org-20180312140628-rsnrcib4gttusg2w
Import sharing panel from gnome-control-center
This commit imports sharing panel from gnome-control-center and removes old screen-sharing panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  gchar *path;
 
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_free (path);
 
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,
 
46
                                 NULL);
 
47
    }
 
48
 
 
49
  g_free (path);
 
50
 
 
51
  return file;
 
52
}
 
53
 
 
54
void
 
55
cc_media_sharing_get_preferences (gchar  ***folders)
 
56
{
 
57
  GKeyFile *file;
 
58
 
 
59
  file = cc_media_sharing_open_key_file ();
 
60
 
 
61
  if (folders)
 
62
    {
 
63
      gsize length;
 
64
      GPtrArray *array;
 
65
      char **str_list, **orig_list;
 
66
 
 
67
      str_list = g_key_file_get_string_list (file, "MediaExport", "uris",
 
68
                                             &length, NULL);
 
69
      orig_list = str_list;
 
70
      array = g_ptr_array_new ();
 
71
 
 
72
      while (str_list && *str_list)
 
73
        {
 
74
          const char *dir;
 
75
 
 
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);
 
82
          else
 
83
            dir = g_strdup (*str_list);
 
84
 
 
85
          if (dir != NULL)
 
86
            g_ptr_array_add (array, g_strdup (dir));
 
87
 
 
88
          str_list++;
 
89
        }
 
90
 
 
91
      g_ptr_array_add (array, NULL);
 
92
 
 
93
      *folders = (char **) g_ptr_array_free (array, FALSE);
 
94
      g_strfreev (orig_list);
 
95
    }
 
96
 
 
97
  g_key_file_free (file);
 
98
}
 
99
 
 
100
void
 
101
cc_media_sharing_set_preferences (gchar    **folders)
 
102
{
 
103
  GKeyFile *file;
 
104
  gchar **str_list;
 
105
  gchar *path;
 
106
  gsize length;
 
107
  gchar *data;
 
108
 
 
109
  file = cc_media_sharing_open_key_file ();
 
110
 
 
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);
 
114
 
 
115
  str_list = folders;
 
116
  length = 0;
 
117
 
 
118
  while (str_list && *str_list)
 
119
    {
 
120
      if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC)) == 0)
 
121
        {
 
122
          g_free (*str_list);
 
123
          *str_list = g_strdup ("@MUSIC@");
 
124
        }
 
125
 
 
126
      if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS)) == 0)
 
127
        {
 
128
          g_free (*str_list);
 
129
          *str_list = g_strdup ("@VIDEOS@");
 
130
        }
 
131
 
 
132
      if (g_strcmp0 (*str_list, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)) == 0)
 
133
        {
 
134
          g_free (*str_list);
 
135
          *str_list = g_strdup ("@PICTURES@");
 
136
        }
 
137
 
 
138
      str_list++;
 
139
      length++;
 
140
    }
 
141
 
 
142
  g_key_file_set_string_list (file, "MediaExport", "uris", (const gchar**) folders, length);
 
143
 
 
144
  data = g_key_file_to_data (file, NULL, NULL);
 
145
 
 
146
  path = g_build_filename (g_get_user_config_dir (), "rygel.conf", NULL);
 
147
 
 
148
  g_file_set_contents (path, data, -1, NULL);
 
149
 
 
150
  g_free (path);
 
151
 
 
152
  g_key_file_free (file);
 
153
}