No issues found
1 /*
2 * Container / playlist database record class for DAAP sharing
3 *
4 * Copyright (C) 2008 W. Michael Petullo <mike@flyn.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * The Rhythmbox authors hereby grant permission for non-GPL compatible
12 * GStreamer plugins to be used and distributed together with GStreamer
13 * and Rhythmbox. This permission is above and beyond the permissions granted
14 * by the GPL license by which Rhythmbox is covered. If you modify this code
15 * you may extend this exception to your version of the code, but you are not
16 * obligated to do so. If you do not wish to do so, delete this exception
17 * statement from your version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 *
28 */
29
30 #include <sys/stat.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <gtk/gtk.h>
35
36 #include "rhythmdb-query-model.h"
37 #include "rb-daap-container-record.h"
38 #include "rb-rhythmdb-query-model-dmap-db-adapter.h"
39
40 enum {
41 PROP_0,
42 PROP_NAME
43 };
44
45 struct RBDAAPContainerRecordPrivate {
46 char *name;
47 RBPlaylistSource *source;
48 };
49
50 static void rb_daap_container_record_finalize (GObject *object);
51
52 static void
53 rb_daap_container_record_set_property (GObject *object,
54 guint prop_id,
55 const GValue *value,
56 GParamSpec *pspec)
57 {
58 RBDAAPContainerRecord *record = RB_DAAP_CONTAINER_RECORD (object);
59
60 switch (prop_id) {
61 case PROP_NAME:
62 g_free (record->priv->name);
63 record->priv->name = g_value_dup_string (value);
64 break;
65 default:
66 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
67 break;
68 }
69 }
70
71 static void
72 rb_daap_container_record_get_property (GObject *object,
73 guint prop_id,
74 GValue *value,
75 GParamSpec *pspec)
76 {
77 RBDAAPContainerRecord *record = RB_DAAP_CONTAINER_RECORD (object);
78
79 switch (prop_id) {
80 case PROP_NAME:
81 g_value_set_string (value, record->priv->name);
82 break;
83 default:
84 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
85 break;
86 }
87 }
88
89 guint
90 rb_daap_container_record_get_id (DMAPContainerRecord *record)
91 {
92 return GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (RB_DAAP_CONTAINER_RECORD (record)->priv->source), "daap_id"));
93 }
94
95 void
96 rb_daap_container_record_add_entry (DMAPContainerRecord *container_record,
97 DMAPRecord *record, gint id)
98 {
99 g_error ("Unimplemented");
100 }
101
102 guint64
103 rb_daap_container_record_get_entry_count (DMAPContainerRecord *record)
104 {
105 RhythmDBQueryModel *model;
106 guint64 count;
107 g_object_get (RB_DAAP_CONTAINER_RECORD (record)->priv->source,
108 "base-query-model",
109 &model,
110 NULL);
111 count = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL);
112 g_object_unref (model);
113 return count;
114 }
115
116 DMAPDb *
117 rb_daap_container_record_get_entries (DMAPContainerRecord *record)
118 {
119 RhythmDBQueryModel *model;
120 g_object_get (RB_DAAP_CONTAINER_RECORD (record)->priv->source,
121 "base-query-model",
122 &model,
123 NULL);
124 return DMAP_DB (rb_rhythmdb_query_model_dmap_db_adapter_new (model));
125 }
126
127 static void
128 rb_daap_container_record_init (RBDAAPContainerRecord *record)
129 {
130 record->priv = RB_DAAP_CONTAINER_RECORD_GET_PRIVATE (record);
131 }
132
133 static void
134 rb_daap_container_record_class_init (RBDAAPContainerRecordClass *klass)
135 {
136 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
137
138 g_type_class_add_private (klass, sizeof (RBDAAPContainerRecordPrivate));
139
140 gobject_class->set_property = rb_daap_container_record_set_property;
141 gobject_class->get_property = rb_daap_container_record_get_property;
142 gobject_class->finalize = rb_daap_container_record_finalize;
143
144 g_object_class_override_property (gobject_class, PROP_NAME, "name");
145 }
146
147 static void
148 rb_daap_container_record_class_finalize (RBDAAPContainerRecordClass *klass)
149 {
150 }
151
152 static void
153 rb_daap_container_record_daap_iface_init (gpointer iface, gpointer data)
154 {
155 DMAPContainerRecordIface *dmap_container_record = iface;
156
157 g_assert (G_TYPE_FROM_INTERFACE (dmap_container_record) == DMAP_TYPE_CONTAINER_RECORD);
158
159 dmap_container_record->get_id = rb_daap_container_record_get_id;
160 dmap_container_record->add_entry = rb_daap_container_record_add_entry;
161 dmap_container_record->get_entry_count = rb_daap_container_record_get_entry_count;
162 dmap_container_record->get_entries = rb_daap_container_record_get_entries;
163 }
164
165 G_DEFINE_DYNAMIC_TYPE_EXTENDED (RBDAAPContainerRecord,
166 rb_daap_container_record,
167 G_TYPE_OBJECT,
168 0,
169 G_IMPLEMENT_INTERFACE_DYNAMIC (DMAP_TYPE_CONTAINER_RECORD,
170 rb_daap_container_record_daap_iface_init))
171
172 static void
173 rb_daap_container_record_finalize (GObject *object)
174 {
175 RBDAAPContainerRecord *record = RB_DAAP_CONTAINER_RECORD (object);
176
177 g_free (record->priv->name);
178
179 G_OBJECT_CLASS (rb_daap_container_record_parent_class)->finalize (object);
180 }
181
182 RBDAAPContainerRecord *
183 rb_daap_container_record_new (char *name, RBPlaylistSource *source)
184 {
185 RBDAAPContainerRecord *record;
186
187 record = g_object_new (RB_TYPE_DAAP_CONTAINER_RECORD, NULL);
188
189 record->priv->source = source;
190 record->priv->name = name;
191
192 return record;
193 }
194
195 void
196 _rb_daap_container_record_register_type (GTypeModule *module)
197 {
198 rb_daap_container_record_register_type (module);
199 }