1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * arch-tag: Headfile of podcast properties dialog
5 * Copyright (C) 2005 Renato Araujo Oliveira Filho <renato.filho@indt.org>
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.
28 #include <glib/gi18n.h>
30 #include <glade/glade.h>
31 #include <libgnomevfs/gnome-vfs.h>
33 #include "rb-podcast-properties-dialog.h"
34 #include "rb-file-helpers.h"
35 #include "rb-glade-helpers.h"
36 #include "rb-dialog.h"
37 #include "rb-rating.h"
39 #include "rb-cut-and-paste-code.h"
41 static void rb_podcast_properties_dialog_class_init (RBPodcastPropertiesDialogClass
*klass
);
42 static void rb_podcast_properties_dialog_init (RBPodcastPropertiesDialog
*dialog
);
43 static void rb_podcast_properties_dialog_finalize (GObject
*object
);
44 static void rb_podcast_properties_dialog_set_property (GObject
*object
,
48 static void rb_podcast_properties_dialog_get_property (GObject
*object
,
52 static gboolean
rb_podcast_properties_dialog_get_current_entry (RBPodcastPropertiesDialog
*dialog
);
53 static void rb_podcast_properties_dialog_response_cb (GtkDialog
*gtkdialog
,
55 RBPodcastPropertiesDialog
*dialog
);
57 static void rb_podcast_properties_dialog_update (RBPodcastPropertiesDialog
*dialog
);
58 static void rb_podcast_properties_dialog_update_title (RBPodcastPropertiesDialog
*dialog
);
59 static void rb_podcast_properties_dialog_update_title_label (RBPodcastPropertiesDialog
*dialog
);
60 static void rb_podcast_properties_dialog_update_feed (RBPodcastPropertiesDialog
*dialog
);
61 static void rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog
*dialog
);
62 static void rb_podcast_properties_dialog_update_download_location (RBPodcastPropertiesDialog
*dialog
);
63 static void rb_podcast_properties_dialog_update_duration (RBPodcastPropertiesDialog
*dialog
);
64 static void rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog
*dialog
);
65 static void rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog
*dialog
);
66 static void rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog
*dialog
);
67 static void rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog
*dialog
);
68 static void rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog
*dialog
);
69 static void rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog
*dialog
);
70 static gchar
* rb_podcast_properties_dialog_parse_time (gulong time
);
71 static void rb_podcast_properties_dialog_rated_cb (RBRating
*rating
,
73 RBPodcastPropertiesDialog
*dialog
);
75 struct RBPodcastPropertiesDialogPrivate
77 RBEntryView
*entry_view
;
79 RhythmDBEntry
*current_entry
;
84 GtkWidget
*download_location
;
86 GtkWidget
*lastplayed
;
91 GtkWidget
*description
;
93 GtkWidget
*close_button
;
103 G_DEFINE_TYPE (RBPodcastPropertiesDialog
, rb_podcast_properties_dialog
, GTK_TYPE_DIALOG
)
106 rb_podcast_properties_dialog_class_init (RBPodcastPropertiesDialogClass
*klass
)
108 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
110 object_class
->set_property
= rb_podcast_properties_dialog_set_property
;
111 object_class
->get_property
= rb_podcast_properties_dialog_get_property
;
113 g_object_class_install_property (object_class
,
115 g_param_spec_object ("entry-view",
117 "RBEntryView object",
119 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
121 object_class
->finalize
= rb_podcast_properties_dialog_finalize
;
123 g_type_class_add_private (klass
, sizeof (RBPodcastPropertiesDialogPrivate
));
127 rb_podcast_properties_dialog_init (RBPodcastPropertiesDialog
*dialog
)
131 dialog
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (dialog
,
132 RB_TYPE_PODCAST_PROPERTIES_DIALOG
,
133 RBPodcastPropertiesDialogPrivate
);
135 g_signal_connect_object (G_OBJECT (dialog
),
137 G_CALLBACK (rb_podcast_properties_dialog_response_cb
),
140 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
141 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 5);
142 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog
)->vbox
), 2);
144 gtk_dialog_set_default_response (GTK_DIALOG (dialog
),
147 xml
= rb_glade_xml_new ("podcast-properties.glade",
150 glade_xml_signal_autoconnect (xml
);
152 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
),
153 glade_xml_get_widget (xml
, "podcastproperties"));
154 dialog
->priv
->close_button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
157 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_CLOSE
);
159 /* get the widgets from the XML */
160 dialog
->priv
->title
= glade_xml_get_widget (xml
, "titleLabel");
161 dialog
->priv
->feed
= glade_xml_get_widget (xml
, "feedLabel");
162 dialog
->priv
->duration
= glade_xml_get_widget (xml
, "durationLabel");
163 dialog
->priv
->location
= glade_xml_get_widget (xml
, "locationLabel");
164 dialog
->priv
->download_location
= glade_xml_get_widget (xml
, "downloadLocationLabel");
165 dialog
->priv
->lastplayed
= glade_xml_get_widget (xml
, "lastplayedLabel");
166 dialog
->priv
->playcount
= glade_xml_get_widget (xml
, "playcountLabel");
167 dialog
->priv
->bitrate
= glade_xml_get_widget (xml
, "bitrateLabel");
168 dialog
->priv
->date
= glade_xml_get_widget (xml
, "dateLabel");
169 dialog
->priv
->description
= glade_xml_get_widget (xml
, "descriptionLabel");
171 rb_glade_boldify_label (xml
, "titleDescLabel");
172 rb_glade_boldify_label (xml
, "feedDescLabel");
173 rb_glade_boldify_label (xml
, "locationDescLabel");
174 rb_glade_boldify_label (xml
, "downloadLocationDescLabel");
175 rb_glade_boldify_label (xml
, "durationDescLabel");
176 rb_glade_boldify_label (xml
, "ratingDescLabel");
177 rb_glade_boldify_label (xml
, "lastplayedDescLabel");
178 rb_glade_boldify_label (xml
, "playcountDescLabel");
179 rb_glade_boldify_label (xml
, "bitrateDescLabel");
180 rb_glade_boldify_label (xml
, "dateDescLabel");
181 rb_glade_boldify_label (xml
, "descriptionDescLabel");
183 dialog
->priv
->rating
= GTK_WIDGET (rb_rating_new ());
184 g_signal_connect_object (dialog
->priv
->rating
,
186 G_CALLBACK (rb_podcast_properties_dialog_rated_cb
),
187 G_OBJECT (dialog
), 0);
188 gtk_container_add (GTK_CONTAINER (glade_xml_get_widget (xml
, "ratingVBox")),
189 dialog
->priv
->rating
);
190 g_object_unref (G_OBJECT (xml
));
194 rb_podcast_properties_dialog_finalize (GObject
*object
)
196 RBPodcastPropertiesDialog
*dialog
;
198 g_return_if_fail (object
!= NULL
);
199 g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (object
));
201 dialog
= RB_PODCAST_PROPERTIES_DIALOG (object
);
203 g_return_if_fail (dialog
->priv
!= NULL
);
205 if (dialog
->priv
->db
!= NULL
) {
206 g_object_unref (dialog
->priv
->db
);
209 G_OBJECT_CLASS (rb_podcast_properties_dialog_parent_class
)->finalize (object
);
213 rb_podcast_properties_dialog_set_entry_view (RBPodcastPropertiesDialog
*dialog
,
216 if (dialog
->priv
->db
!= NULL
) {
217 g_object_unref (dialog
->priv
->db
);
220 dialog
->priv
->entry_view
= view
;
222 if (dialog
->priv
->entry_view
!= NULL
) {
223 g_object_get (dialog
->priv
->entry_view
,
224 "db", &dialog
->priv
->db
, NULL
);
229 rb_podcast_properties_dialog_set_property (GObject
*object
,
234 RBPodcastPropertiesDialog
*dialog
= RB_PODCAST_PROPERTIES_DIALOG (object
);
237 case PROP_ENTRY_VIEW
:
238 rb_podcast_properties_dialog_set_entry_view (dialog
, g_value_get_object (value
));
241 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
247 rb_podcast_properties_dialog_get_property (GObject
*object
,
252 RBPodcastPropertiesDialog
*dialog
= RB_PODCAST_PROPERTIES_DIALOG (object
);
255 case PROP_ENTRY_VIEW
:
256 g_value_set_object (value
, dialog
->priv
->entry_view
);
259 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
265 rb_podcast_properties_dialog_new (RBEntryView
*entry_view
)
267 RBPodcastPropertiesDialog
*dialog
;
269 g_return_val_if_fail (RB_IS_ENTRY_VIEW (entry_view
), NULL
);
271 dialog
= g_object_new (RB_TYPE_PODCAST_PROPERTIES_DIALOG
,
272 "entry-view", entry_view
, NULL
);
274 if (!rb_podcast_properties_dialog_get_current_entry (dialog
)) {
275 g_object_unref (G_OBJECT (dialog
));
278 rb_podcast_properties_dialog_update (dialog
);
280 return GTK_WIDGET (dialog
);
284 rb_podcast_properties_dialog_response_cb (GtkDialog
*gtkdialog
,
286 RBPodcastPropertiesDialog
*dialog
)
288 if (response_id
!= GTK_RESPONSE_OK
)
291 gtk_widget_destroy (GTK_WIDGET (dialog
));
295 rb_podcast_properties_dialog_get_current_entry (RBPodcastPropertiesDialog
*dialog
)
297 GList
*selected_entries
;
300 selected_entries
= rb_entry_view_get_selected_entries (dialog
->priv
->entry_view
);
302 if ((selected_entries
== NULL
) ||
303 (selected_entries
->data
== NULL
)) {
304 dialog
->priv
->current_entry
= NULL
;
308 dialog
->priv
->current_entry
= selected_entries
->data
;
313 rb_podcast_properties_dialog_update (RBPodcastPropertiesDialog
*dialog
)
315 g_return_if_fail (dialog
->priv
->current_entry
!= NULL
);
316 rb_podcast_properties_dialog_update_location (dialog
);
317 rb_podcast_properties_dialog_update_download_location (dialog
);
318 rb_podcast_properties_dialog_update_title (dialog
);
319 rb_podcast_properties_dialog_update_title_label (dialog
);
320 rb_podcast_properties_dialog_update_feed (dialog
);
321 rb_podcast_properties_dialog_update_duration (dialog
);
322 rb_podcast_properties_dialog_update_play_count (dialog
);
323 rb_podcast_properties_dialog_update_bitrate (dialog
);
324 rb_podcast_properties_dialog_update_last_played (dialog
);
325 rb_podcast_properties_dialog_update_rating (dialog
);
326 rb_podcast_properties_dialog_update_date (dialog
);
327 rb_podcast_properties_dialog_update_description (dialog
);
331 rb_podcast_properties_dialog_update_title (RBPodcastPropertiesDialog
*dialog
)
336 name
= rhythmdb_entry_get_string (dialog
->priv
->current_entry
, RHYTHMDB_PROP_TITLE
);
337 tmp
= g_strdup_printf (_("%s Properties"), name
);
338 gtk_window_set_title (GTK_WINDOW (dialog
), tmp
);
343 rb_podcast_properties_dialog_update_title_label (RBPodcastPropertiesDialog
*dialog
)
347 title
= rhythmdb_entry_get_string (dialog
->priv
->current_entry
, RHYTHMDB_PROP_TITLE
);
348 gtk_label_set_text (GTK_LABEL (dialog
->priv
->title
), title
);
352 rb_podcast_properties_dialog_update_feed (RBPodcastPropertiesDialog
*dialog
)
356 feed
= rhythmdb_entry_get_string (dialog
->priv
->current_entry
, RHYTHMDB_PROP_ALBUM
);
357 gtk_label_set_text (GTK_LABEL (dialog
->priv
->feed
), feed
);
361 rb_podcast_properties_dialog_update_duration (RBPodcastPropertiesDialog
*dialog
)
366 duration
= rhythmdb_entry_get_ulong (dialog
->priv
->current_entry
, RHYTHMDB_PROP_DURATION
);
368 text
= rb_make_duration_string (duration
);
369 gtk_label_set_text (GTK_LABEL (dialog
->priv
->duration
), text
);
374 rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog
*dialog
)
376 const char *location
;
379 location
= rhythmdb_entry_get_string (dialog
->priv
->current_entry
, RHYTHMDB_PROP_LOCATION
);
380 display
= gnome_vfs_format_uri_for_display (location
);
381 gtk_label_set_text (GTK_LABEL (dialog
->priv
->location
), display
);
386 rb_podcast_properties_dialog_update_download_location (RBPodcastPropertiesDialog
*dialog
)
388 const char *location
;
390 location
= rhythmdb_entry_get_string (dialog
->priv
->current_entry
, RHYTHMDB_PROP_MOUNTPOINT
);
391 if (location
!= NULL
&& location
[0] != '\0') {
393 display
= gnome_vfs_format_uri_for_display (location
);
394 gtk_label_set_text (GTK_LABEL (dialog
->priv
->download_location
), display
);
397 gtk_label_set_text (GTK_LABEL (dialog
->priv
->download_location
), _("Not Downloaded"));
402 rb_podcast_properties_dialog_rated_cb (RBRating
*rating
,
404 RBPodcastPropertiesDialog
*dialog
)
406 GValue value
= { 0, };
408 g_return_if_fail (RB_IS_RATING (rating
));
409 g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (dialog
));
410 g_return_if_fail (score
>= 0 && score
<= 5 );
412 /* set the new value for the song */
413 g_value_init (&value
, G_TYPE_DOUBLE
);
414 g_value_set_double (&value
, score
);
415 rhythmdb_entry_set (dialog
->priv
->db
,
416 dialog
->priv
->current_entry
,
417 RHYTHMDB_PROP_RATING
,
419 rhythmdb_commit (dialog
->priv
->db
);
420 g_value_unset (&value
);
422 g_object_set (G_OBJECT (dialog
->priv
->rating
),
428 rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog
*dialog
)
433 count
= rhythmdb_entry_get_ulong (dialog
->priv
->current_entry
, RHYTHMDB_PROP_PLAY_COUNT
);
434 text
= g_strdup_printf ("%ld", count
);
435 gtk_label_set_text (GTK_LABEL (dialog
->priv
->playcount
), text
);
440 rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog
*dialog
)
445 bitrate
= rhythmdb_entry_get_ulong (dialog
->priv
->current_entry
, RHYTHMDB_PROP_BITRATE
);
447 tmp
= g_strdup_printf (_("%lu kbps"), bitrate
);
449 tmp
= g_strdup (_("Unknown"));
451 gtk_label_set_text (GTK_LABEL (dialog
->priv
->bitrate
), tmp
);
456 rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog
*dialog
)
460 str
= rhythmdb_entry_get_string (dialog
->priv
->current_entry
, RHYTHMDB_PROP_LAST_PLAYED_STR
);
461 gtk_label_set (GTK_LABEL (dialog
->priv
->lastplayed
), str
);
465 rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog
*dialog
)
469 rating
= rhythmdb_entry_get_double (dialog
->priv
->current_entry
, RHYTHMDB_PROP_RATING
);
470 g_object_set (G_OBJECT (dialog
->priv
->rating
), "rating", rating
, NULL
);
474 rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog
*dialog
)
479 post_time
= rhythmdb_entry_get_ulong (dialog
->priv
->current_entry
, RHYTHMDB_PROP_POST_TIME
);
480 time
= rb_podcast_properties_dialog_parse_time (post_time
);
482 gtk_label_set (GTK_LABEL (dialog
->priv
->date
),
488 rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog
*dialog
)
492 str
= rhythmdb_entry_get_string (dialog
->priv
->current_entry
, RHYTHMDB_PROP_DESCRIPTION
);
493 gtk_label_set (GTK_LABEL (dialog
->priv
->description
), str
);
497 rb_podcast_properties_dialog_parse_time (gulong value
)
502 str
= g_strdup (_("Unknown"));
504 str
= rb_utf_friendly_time ((time_t)value
);