1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * Implmentation of DAAP (iTunes Music Sharing) sharing
5 * Copyright (C) 2005 Charles Schmidt <cschmidt2@emich.edu>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <glib/gi18n.h>
28 #include <glib/gprintf.h>
30 #include "rb-daap-sharing.h"
31 #include "rb-daap-share.h"
33 #include "rb-dialog.h"
34 #include "rb-playlist-manager.h"
35 #include "eel-gconf-extensions.h"
36 #include "rb-preferences.h"
38 static RBDAAPShare
*share
= NULL
;
39 static guint enable_sharing_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
40 static guint require_password_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
41 static guint share_name_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
42 static guint share_password_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
45 create_share (RBShell
*shell
)
48 RBPlaylistManager
*playlist_manager
;
51 gboolean require_password
;
53 g_assert (share
== NULL
);
54 rb_debug ("initialize daap sharing\n");
56 name
= eel_gconf_get_string (CONF_DAAP_SHARE_NAME
);
58 if (name
== NULL
|| *name
== '\0') {
59 const gchar
*real_name
;
63 real_name
= g_get_real_name ();
64 if (strcmp (real_name
, "Unknown") == 0) {
65 real_name
= g_get_user_name ();
68 name
= g_strdup_printf (_("%s's Music"), real_name
);
69 eel_gconf_set_string (CONF_DAAP_SHARE_NAME
, name
);
74 "playlist-manager", &playlist_manager
, NULL
);
76 require_password
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
77 if (require_password
) {
78 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
83 share
= rb_daap_share_new (name
, password
, db
, playlist_manager
);
86 g_object_unref (playlist_manager
);
93 enable_sharing_changed_cb (GConfClient
*client
,
100 enabled
= eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING
);
104 create_share (shell
);
107 rb_debug ("shutdown daap sharing");
110 g_object_unref (share
);
117 require_password_changed_cb (GConfClient
*client
,
129 required
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
132 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
137 g_object_set (G_OBJECT (share
), "password", password
, NULL
);
142 share_name_changed_cb (GConfClient
*client
,
153 name
= eel_gconf_get_string (CONF_DAAP_SHARE_NAME
);
154 g_object_set (G_OBJECT (share
), "name", name
, NULL
);
159 share_password_changed_cb (GConfClient
*client
,
164 gboolean require_password
;
171 require_password
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
173 /* Don't do anything unless we require a password */
174 if (! require_password
) {
178 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
179 g_object_set (G_OBJECT (share
), "password", password
, NULL
);
184 rb_daap_sharing_init (RBShell
*shell
)
186 g_object_ref (shell
);
188 if (eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING
)) {
189 create_share (shell
);
192 enable_sharing_notify_id
=
193 eel_gconf_notification_add (CONF_DAAP_ENABLE_SHARING
,
194 (GConfClientNotifyFunc
) enable_sharing_changed_cb
,
196 require_password_notify_id
=
197 eel_gconf_notification_add (CONF_DAAP_REQUIRE_PASSWORD
,
198 (GConfClientNotifyFunc
) require_password_changed_cb
,
200 share_name_notify_id
=
201 eel_gconf_notification_add (CONF_DAAP_SHARE_NAME
,
202 (GConfClientNotifyFunc
) share_name_changed_cb
,
204 share_password_notify_id
=
205 eel_gconf_notification_add (CONF_DAAP_SHARE_PASSWORD
,
206 (GConfClientNotifyFunc
) share_password_changed_cb
,
211 rb_daap_sharing_shutdown (RBShell
*shell
)
214 rb_debug ("shutdown daap sharing");
216 g_object_unref (share
);
220 if (enable_sharing_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
221 eel_gconf_notification_remove (enable_sharing_notify_id
);
222 enable_sharing_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
224 if (require_password_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
225 eel_gconf_notification_remove (require_password_notify_id
);
226 require_password_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
228 if (share_name_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
229 eel_gconf_notification_remove (share_name_notify_id
);
230 share_name_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
232 if (share_password_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
233 eel_gconf_notification_remove (share_password_notify_id
);
234 share_password_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
237 g_object_unref (shell
);