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 rb_daap_sharing_default_share_name ()
47 const gchar
*real_name
;
49 real_name
= g_get_real_name ();
50 if (strcmp (real_name
, "Unknown") == 0) {
51 real_name
= g_get_user_name ();
54 return g_strdup_printf (_("%s's Music"), real_name
);
58 create_share (RBShell
*shell
)
61 RBPlaylistManager
*playlist_manager
;
64 gboolean require_password
;
66 g_assert (share
== NULL
);
67 rb_debug ("initialize daap sharing");
69 name
= eel_gconf_get_string (CONF_DAAP_SHARE_NAME
);
70 if (name
== NULL
|| *name
== '\0') {
72 name
= rb_daap_sharing_default_share_name ();
77 "playlist-manager", &playlist_manager
, NULL
);
79 require_password
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
80 if (require_password
) {
81 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
86 share
= rb_daap_share_new (name
, password
, db
, RHYTHMDB_ENTRY_TYPE_SONG
, playlist_manager
);
89 g_object_unref (playlist_manager
);
96 enable_sharing_changed_cb (GConfClient
*client
,
103 enabled
= eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING
);
107 create_share (shell
);
110 rb_debug ("shutdown daap sharing");
113 g_object_unref (share
);
120 require_password_changed_cb (GConfClient
*client
,
132 required
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
135 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
140 g_object_set (G_OBJECT (share
), "password", password
, NULL
);
145 share_name_changed_cb (GConfClient
*client
,
156 name
= eel_gconf_get_string (CONF_DAAP_SHARE_NAME
);
157 if (name
== NULL
|| name
[0] == '\0') {
159 name
= rb_daap_sharing_default_share_name ();
162 g_object_set (G_OBJECT (share
), "name", name
, NULL
);
167 share_password_changed_cb (GConfClient
*client
,
172 gboolean require_password
;
179 require_password
= eel_gconf_get_boolean (CONF_DAAP_REQUIRE_PASSWORD
);
181 /* Don't do anything unless we require a password */
182 if (! require_password
) {
186 password
= eel_gconf_get_string (CONF_DAAP_SHARE_PASSWORD
);
187 g_object_set (G_OBJECT (share
), "password", password
, NULL
);
192 rb_daap_sharing_init (RBShell
*shell
)
194 g_object_ref (shell
);
196 if (eel_gconf_get_boolean (CONF_DAAP_ENABLE_SHARING
)) {
197 create_share (shell
);
200 enable_sharing_notify_id
=
201 eel_gconf_notification_add (CONF_DAAP_ENABLE_SHARING
,
202 (GConfClientNotifyFunc
) enable_sharing_changed_cb
,
204 require_password_notify_id
=
205 eel_gconf_notification_add (CONF_DAAP_REQUIRE_PASSWORD
,
206 (GConfClientNotifyFunc
) require_password_changed_cb
,
208 share_name_notify_id
=
209 eel_gconf_notification_add (CONF_DAAP_SHARE_NAME
,
210 (GConfClientNotifyFunc
) share_name_changed_cb
,
212 share_password_notify_id
=
213 eel_gconf_notification_add (CONF_DAAP_SHARE_PASSWORD
,
214 (GConfClientNotifyFunc
) share_password_changed_cb
,
219 rb_daap_sharing_shutdown (RBShell
*shell
)
222 rb_debug ("shutdown daap sharing");
224 g_object_unref (share
);
228 if (enable_sharing_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
229 eel_gconf_notification_remove (enable_sharing_notify_id
);
230 enable_sharing_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
232 if (require_password_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
233 eel_gconf_notification_remove (require_password_notify_id
);
234 require_password_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
236 if (share_name_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
237 eel_gconf_notification_remove (share_name_notify_id
);
238 share_name_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
240 if (share_password_notify_id
!= EEL_GCONF_UNDEFINED_CONNECTION
) {
241 eel_gconf_notification_remove (share_password_notify_id
);
242 share_password_notify_id
= EEL_GCONF_UNDEFINED_CONNECTION
;
245 g_object_unref (shell
);