~ubuntu-branches/ubuntu/precise/rhythmbox/precise-201203091205

« back to all changes in this revision

Viewing changes to daapsharing/rb-daap-sharing.c

Tags: upstream-0.9.5
ImportĀ upstreamĀ versionĀ 0.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 *
2
3
 *  Implmentation of DAAP (iTunes Music Sharing) sharing
3
4
 *
4
5
 *  Copyright (C) 2005 Charles Schmidt <cschmidt2@emich.edu>
15
16
 *
16
17
 *  You should have received a copy of the GNU General Public License
17
18
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
19
20
 *
20
21
 */
21
22
 
22
 
#include <config.h>
23
 
 
24
 
#include <libgnome/gnome-i18n.h>
 
23
#include "config.h"
 
24
 
 
25
#include <string.h>
 
26
 
 
27
#include <glib/gi18n.h>
25
28
#include <glib/gprintf.h>
26
 
#include <string.h>
27
29
 
28
30
#include "rb-daap-sharing.h"
29
31
#include "rb-daap-share.h"
33
35
#include "eel-gconf-extensions.h"
34
36
#include "rb-preferences.h"
35
37
 
36
 
#define CONF_ENABLE_SHARING CONF_PREFIX "/sharing/enable_sharing"
37
 
#define CONF_SHARE_NAME CONF_PREFIX "/sharing/share_name"
38
 
 
39
38
static RBDAAPShare *share = NULL;
40
39
static guint enable_sharing_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
 
40
static guint require_password_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
41
41
static guint share_name_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
 
42
static guint share_password_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
42
43
 
43
44
static void 
44
45
create_share (RBShell *shell)
45
46
{
46
47
        RhythmDB *db;
47
48
        RBPlaylistManager *playlist_manager;
48
 
        gchar *name;
 
49
        char *name;
 
50
        char *password;
 
51
        gboolean require_password;
49
52
 
50
53
        g_assert (share == NULL);
51
54
        rb_debug ("initialize daap sharing\n");
52
55
 
53
 
        name = eel_gconf_get_string (CONF_SHARE_NAME);
 
56
        name = eel_gconf_get_string (CONF_DAAP_SHARE_NAME);
54
57
 
55
58
        if (name == NULL || *name == '\0') {
56
59
                const gchar *real_name;
63
66
                }
64
67
 
65
68
                name = g_strdup_printf (_("%s's Music"), real_name);
66
 
                eel_gconf_set_string (CONF_SHARE_NAME, name);
 
69
                eel_gconf_set_string (CONF_DAAP_SHARE_NAME, name);
67
70
        }
68
71
 
69
72
        g_object_get (G_OBJECT (shell), "db", &db, "playlist-manager", &playlist_manager, NULL);
70
73
 
71
 
        share = rb_daap_share_new (name, db, playlist_manager);
 
74
        require_password = eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD);
 
75
        if (require_password) {
 
76
                password = eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD);
 
77
        } else {
 
78
                password = NULL;
 
79
        }
 
80
 
 
81
        share = rb_daap_share_new (name, password, db, playlist_manager);
 
82
 
72
83
        g_free (name);
 
84
        g_free (password);
73
85
}
74
86
 
75
87
static void 
80
92
{
81
93
        gboolean enabled;
82
94
 
83
 
        enabled = eel_gconf_get_boolean (CONF_ENABLE_SHARING);
 
95
        enabled = eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING);
84
96
 
85
97
        if (enabled) {
86
 
                if (share == NULL)
 
98
                if (share == NULL) {
87
99
                        create_share (shell);
 
100
                }
88
101
        } else {
89
102
                rb_debug ("shutdown daap sharing");
90
103
 
91
 
                if (share)
 
104
                if (share) {
92
105
                        g_object_unref (share);
 
106
                }
93
107
                share = NULL;
94
108
        }
95
109
}
96
110
 
97
111
static void 
 
112
require_password_changed_cb (GConfClient *client,
 
113
                             guint cnxn_id,
 
114
                             GConfEntry *entry,
 
115
                             RBShell *shell)
 
116
{
 
117
        gboolean required;
 
118
        char    *password;
 
119
 
 
120
        if (share == NULL) {
 
121
                return;
 
122
        }
 
123
 
 
124
        required = eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD);
 
125
 
 
126
        if (required) {
 
127
                password = eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD);
 
128
        } else {
 
129
                password = NULL;
 
130
        }
 
131
 
 
132
        g_object_set (G_OBJECT (share), "password", password, NULL);
 
133
        g_free (password);
 
134
}
 
135
 
 
136
static void 
98
137
share_name_changed_cb (GConfClient *client, 
99
138
                       guint cnxn_id, 
100
139
                       GConfEntry *entry, 
101
140
                       RBShell *shell)
102
141
{
103
 
        if (share) {
104
 
                gchar *name = eel_gconf_get_string (CONF_SHARE_NAME);;
105
 
                g_object_set (G_OBJECT (share), "name", name, NULL);
106
 
                g_free (name);
107
 
        }
 
142
        char *name;
 
143
 
 
144
        if (share == NULL) {
 
145
                return;
 
146
        }
 
147
 
 
148
        name = eel_gconf_get_string (CONF_DAAP_SHARE_NAME);
 
149
        g_object_set (G_OBJECT (share), "name", name, NULL);
 
150
        g_free (name);
 
151
}
 
152
 
 
153
static void 
 
154
share_password_changed_cb (GConfClient *client, 
 
155
                           guint cnxn_id, 
 
156
                           GConfEntry *entry, 
 
157
                           RBShell *shell)
 
158
{
 
159
        gboolean require_password;
 
160
        char    *password;
 
161
 
 
162
        if (share == NULL) {
 
163
                return;
 
164
        }
 
165
 
 
166
        require_password = eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD);
 
167
 
 
168
        /* Don't do anything unless we require a password */
 
169
        if (! require_password) {
 
170
                return;
 
171
        }
 
172
 
 
173
        password = eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD);
 
174
        g_object_set (G_OBJECT (share), "password", password, NULL);
 
175
        g_free (password);
108
176
}
109
177
 
110
178
 
113
181
{
114
182
        g_object_ref (shell);
115
183
 
116
 
        if (eel_gconf_get_boolean (CONF_ENABLE_SHARING)) {
 
184
        if (eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING)) {
117
185
                create_share (shell);
118
186
        }
119
187
 
120
188
        enable_sharing_notify_id =
121
 
                eel_gconf_notification_add (CONF_ENABLE_SHARING,
 
189
                eel_gconf_notification_add (CONF_DAAP_ENABLE_SHARING,
122
190
                                            (GConfClientNotifyFunc) enable_sharing_changed_cb,
123
191
                                            shell);
 
192
        require_password_notify_id =
 
193
                eel_gconf_notification_add (CONF_DAAP_REQUIRE_PASSWORD,
 
194
                                            (GConfClientNotifyFunc) require_password_changed_cb,
 
195
                                            shell);
124
196
        share_name_notify_id =
125
 
                eel_gconf_notification_add (CONF_ENABLE_SHARING,
 
197
                eel_gconf_notification_add (CONF_DAAP_SHARE_NAME,
126
198
                                            (GConfClientNotifyFunc) share_name_changed_cb,
127
199
                                            shell);
 
200
        share_password_notify_id =
 
201
                eel_gconf_notification_add (CONF_DAAP_SHARE_PASSWORD,
 
202
                                            (GConfClientNotifyFunc) share_password_changed_cb,
 
203
                                            shell);
128
204
}
129
205
 
130
206
void 
141
217
                eel_gconf_notification_remove (enable_sharing_notify_id);
142
218
                enable_sharing_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
143
219
        }
 
220
        if (require_password_notify_id != EEL_GCONF_UNDEFINED_CONNECTION) {
 
221
                eel_gconf_notification_remove (require_password_notify_id);
 
222
                require_password_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
 
223
        }
144
224
        if (share_name_notify_id != EEL_GCONF_UNDEFINED_CONNECTION) {
145
225
                eel_gconf_notification_remove (share_name_notify_id);
146
226
                share_name_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
147
227
        }
 
228
        if (share_password_notify_id != EEL_GCONF_UNDEFINED_CONNECTION) {
 
229
                eel_gconf_notification_remove (share_password_notify_id);
 
230
                share_password_notify_id = EEL_GCONF_UNDEFINED_CONNECTION;
 
231
        }
148
232
 
149
233
        g_object_unref (shell);
150
234
}