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
);
72 g_object_get (G_OBJECT (shell
), "db", &db
, "playlist-manager", &playlist_manager
, NULL
);
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
);
81 share
= rb_daap_share_new (name
, password
, db
, playlist_manager
);
88 enable_sharing_changed_cb (GConfClient
*client
,
95 enabled
= eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING
);
102 rb_debug ("shutdown daap sharing");
105 g_object_unref (share
);
112 require_password_changed_cb (GConfClient
*client
,
124 required
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
127 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
132 g_object_set (G_OBJECT (share
), "password", password
, NULL
);
137 share_name_changed_cb (GConfClient
*client
,
148 name
= eel_gconf_get_string (CONF_DAAP_SHARE_NAME
);
149 g_object_set (G_OBJECT (share
), "name", name
, NULL
);
154 share_password_changed_cb (GConfClient
*client
,
159 gboolean require_password
;
166 require_password
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
168 /* Don't do anything unless we require a password */
169 if (! require_password
) {
173 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
174 g_object_set (G_OBJECT (share
), "password", password
, NULL
);
180 rb_daap_sharing_init (RBShell
*shell
)
182 g_object_ref (shell
);
184 if (eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING
)) {
185 create_share (shell
);
188 enable_sharing_notify_id
=
189 eel_gconf_notification_add (CONF_DAAP_ENABLE_SHARING
,
190 (GConfClientNotifyFunc
) enable_sharing_changed_cb
,
192 require_password_notify_id
=
193 eel_gconf_notification_add (CONF_DAAP_REQUIRE_PASSWORD
,
194 (GConfClientNotifyFunc
) require_password_changed_cb
,
196 share_name_notify_id
=
197 eel_gconf_notification_add (CONF_DAAP_SHARE_NAME
,
198 (GConfClientNotifyFunc
) share_name_changed_cb
,
200 share_password_notify_id
=
201 eel_gconf_notification_add (CONF_DAAP_SHARE_PASSWORD
,
202 (GConfClientNotifyFunc
) share_password_changed_cb
,
207 rb_daap_sharing_shutdown (RBShell
*shell
)
210 rb_debug ("shutdown daap sharing");
212 g_object_unref (share
);
216 if (enable_sharing_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
217 eel_gconf_notification_remove (enable_sharing_notify_id
);
218 enable_sharing_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
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
;
224 if (share_name_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
225 eel_gconf_notification_remove (share_name_notify_id
);
226 share_name_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
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
;
233 g_object_unref (shell
);