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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_update_title (RBPodcastPropertiesDialog
*dialog
);
54 static void rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog
*dialog
);
55 static void rb_podcast_properties_dialog_response_cb (GtkDialog
*gtkdialog
,
57 RBPodcastPropertiesDialog
*dialog
);
59 static void rb_podcast_properties_dialog_update (RBPodcastPropertiesDialog
*dialog
);
60 static void rb_podcast_properties_dialog_update_title_label (RBPodcastPropertiesDialog
*dialog
);
61 static void rb_podcast_properties_dialog_update_feed (RBPodcastPropertiesDialog
*dialog
);
62 static void rb_podcast_properties_dialog_update_duration (RBPodcastPropertiesDialog
*dialog
);
63 static void rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog
*dialog
);
64 static void rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog
*dialog
);
65 static void rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog
*dialog
);
66 static void rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog
*dialog
);
67 static void rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog
*dialog
);
68 static void rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog
*dialog
);
69 static gchar
* rb_podcast_properties_dialog_parse_time (gulong time
);
70 static void rb_podcast_properties_dialog_rated_cb (RBRating
*rating
,
72 RBPodcastPropertiesDialog
*dialog
);
74 struct RBPodcastPropertiesDialogPrivate
76 RBEntryView
*entry_view
;
78 RhythmDBEntry
*current_entry
;
84 GtkWidget
*lastplayed
;
89 GtkWidget
*description
;
91 GtkWidget
*close_button
;
94 #define RB_PODCAST_PROPERTIES_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_PODCAST_PROPERTIES_DIALOG, RBPodcastPropertiesDialogPrivate))
103 G_DEFINE_TYPE (RBPodcastPropertiesDialog
, rb_podcast_properties_dialog
, GTK_TYPE_DIALOG
)
107 rb_podcast_properties_dialog_class_init (RBPodcastPropertiesDialogClass
*klass
)
109 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
111 object_class
->set_property
= rb_podcast_properties_dialog_set_property
;
112 object_class
->get_property
= rb_podcast_properties_dialog_get_property
;
114 g_object_class_install_property (object_class
,
116 g_param_spec_object ("entry-view",
118 "RBEntryView object",
120 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
122 object_class
->finalize
= rb_podcast_properties_dialog_finalize
;
124 g_type_class_add_private (klass
, sizeof (RBPodcastPropertiesDialogPrivate
));
128 rb_podcast_properties_dialog_init (RBPodcastPropertiesDialog
*dialog
)
132 dialog
->priv
= RB_PODCAST_PROPERTIES_DIALOG_GET_PRIVATE (dialog
);
134 g_signal_connect_object (G_OBJECT (dialog
),
136 G_CALLBACK (rb_podcast_properties_dialog_response_cb
),
139 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
140 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 5);
141 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog
)->vbox
), 2);
143 gtk_dialog_set_default_response (GTK_DIALOG (dialog
),
146 xml
= rb_glade_xml_new ("podcast-properties.glade",
149 glade_xml_signal_autoconnect (xml
);
151 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
),
152 glade_xml_get_widget (xml
, "podcastproperties"));
153 dialog
->priv
->close_button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
156 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_CLOSE
);
158 /* get the widgets from the XML */
159 dialog
->priv
->title
= glade_xml_get_widget (xml
, "titleLabel");
160 dialog
->priv
->feed
= glade_xml_get_widget (xml
, "feedLabel");
161 dialog
->priv
->duration
= glade_xml_get_widget (xml
, "durationLabel");
162 dialog
->priv
->location
= glade_xml_get_widget (xml
, "locationLabel");
163 dialog
->priv
->lastplayed
= glade_xml_get_widget (xml
, "lastplayedLabel");
164 dialog
->priv
->playcount
= glade_xml_get_widget (xml
, "playcountLabel");
165 dialog
->priv
->bitrate
= glade_xml_get_widget (xml
, "bitrateLabel");
166 dialog
->priv
->date
= glade_xml_get_widget (xml
, "dateLabel");
167 dialog
->priv
->description
= glade_xml_get_widget (xml
, "descriptionLabel");
169 rb_glade_boldify_label (xml
, "titleDescLabel");
170 rb_glade_boldify_label (xml
, "feedDescLabel");
171 rb_glade_boldify_label (xml
, "locationDescLabel");
172 rb_glade_boldify_label (xml
, "durationDescLabel");
173 rb_glade_boldify_label (xml
, "ratingDescLabel");
174 rb_glade_boldify_label (xml
, "lastplayedDescLabel");
175 rb_glade_boldify_label (xml
, "playcountDescLabel");
176 rb_glade_boldify_label (xml
, "bitrateDescLabel");
177 rb_glade_boldify_label (xml
, "dateDescLabel");
178 rb_glade_boldify_label (xml
, "descriptionDescLabel");
180 dialog
->priv
->rating
= GTK_WIDGET (rb_rating_new ());
181 g_signal_connect_object (dialog
->priv
->rating
,
183 G_CALLBACK (rb_podcast_properties_dialog_rated_cb
),
184 G_OBJECT (dialog
), 0);
185 gtk_container_add (GTK_CONTAINER (glade_xml_get_widget (xml
, "ratingVBox")),
186 dialog
->priv
->rating
);
187 g_object_unref (G_OBJECT (xml
));
191 rb_podcast_properties_dialog_finalize (GObject
*object
)
193 RBPodcastPropertiesDialog
*dialog
;
195 g_return_if_fail (object
!= NULL
);
196 g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (object
));
198 dialog
= RB_PODCAST_PROPERTIES_DIALOG (object
);
200 g_return_if_fail (dialog
->priv
!= NULL
);
202 G_OBJECT_CLASS (rb_podcast_properties_dialog_parent_class
)->finalize (object
);
206 rb_podcast_properties_dialog_set_property (GObject
*object
,
211 RBPodcastPropertiesDialog
*dialog
= RB_PODCAST_PROPERTIES_DIALOG (object
);
214 case PROP_ENTRY_VIEW
:
215 dialog
->priv
->entry_view
= g_value_get_object (value
);
216 g_object_get (G_OBJECT (dialog
->priv
->entry_view
), "db",
217 &dialog
->priv
->db
, NULL
);
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
226 rb_podcast_properties_dialog_get_property (GObject
*object
,
231 RBPodcastPropertiesDialog
*dialog
= RB_PODCAST_PROPERTIES_DIALOG (object
);
234 case PROP_ENTRY_VIEW
:
235 g_value_set_object (value
, dialog
->priv
->entry_view
);
238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
244 rb_podcast_properties_dialog_new (RBEntryView
*entry_view
)
246 RBPodcastPropertiesDialog
*dialog
;
248 g_return_val_if_fail (RB_IS_ENTRY_VIEW (entry_view
), NULL
);
250 dialog
= g_object_new (RB_TYPE_PODCAST_PROPERTIES_DIALOG
,
251 "entry-view", entry_view
, NULL
);
253 if (!rb_podcast_properties_dialog_get_current_entry (dialog
)) {
254 g_object_unref (G_OBJECT (dialog
));
257 rb_podcast_properties_dialog_update (dialog
);
259 return GTK_WIDGET (dialog
);
263 rb_podcast_properties_dialog_response_cb (GtkDialog
*gtkdialog
,
265 RBPodcastPropertiesDialog
*dialog
)
267 if (response_id
!= GTK_RESPONSE_OK
)
270 gtk_widget_destroy (GTK_WIDGET (dialog
));
274 rb_podcast_properties_dialog_get_current_entry (RBPodcastPropertiesDialog
*dialog
)
276 GList
*selected_entries
;
279 selected_entries
= rb_entry_view_get_selected_entries (dialog
->priv
->entry_view
);
281 if ((selected_entries
== NULL
) ||
282 (selected_entries
->data
== NULL
)) {
283 dialog
->priv
->current_entry
= NULL
;
287 dialog
->priv
->current_entry
= selected_entries
->data
;
292 rb_podcast_properties_dialog_update (RBPodcastPropertiesDialog
*dialog
)
294 g_return_if_fail (dialog
->priv
->current_entry
!= NULL
);
295 rb_podcast_properties_dialog_update_location (dialog
);
296 rb_podcast_properties_dialog_update_title (dialog
);
297 rb_podcast_properties_dialog_update_title_label (dialog
);
298 rb_podcast_properties_dialog_update_feed (dialog
);
299 rb_podcast_properties_dialog_update_duration (dialog
);
300 rb_podcast_properties_dialog_update_play_count (dialog
);
301 rb_podcast_properties_dialog_update_bitrate (dialog
);
302 rb_podcast_properties_dialog_update_last_played (dialog
);
303 rb_podcast_properties_dialog_update_rating (dialog
);
304 rb_podcast_properties_dialog_update_date (dialog
);
305 rb_podcast_properties_dialog_update_description (dialog
);
309 rb_podcast_properties_dialog_update_title (RBPodcastPropertiesDialog
*dialog
)
313 name
= rb_refstring_get (dialog
->priv
->current_entry
->title
);
314 tmp
= g_strdup_printf (_("%s Properties"), name
);
315 gtk_window_set_title (GTK_WINDOW (dialog
), tmp
);
320 rb_podcast_properties_dialog_update_title_label (RBPodcastPropertiesDialog
*dialog
)
322 gtk_label_set_text (GTK_LABEL (dialog
->priv
->title
),
323 rb_refstring_get (dialog
->priv
->current_entry
->title
));
327 rb_podcast_properties_dialog_update_feed (RBPodcastPropertiesDialog
*dialog
)
329 gtk_label_set_text (GTK_LABEL (dialog
->priv
->feed
),
330 rb_refstring_get (dialog
->priv
->current_entry
->album
));
334 rb_podcast_properties_dialog_update_duration (RBPodcastPropertiesDialog
*dialog
)
339 duration
= rhythmdb_entry_get_ulong (dialog
->priv
->current_entry
, RHYTHMDB_PROP_DURATION
);
341 text
= rb_make_duration_string (duration
);
342 gtk_label_set_text (GTK_LABEL (dialog
->priv
->duration
), text
);
347 rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog
*dialog
)
350 unescaped
= gnome_vfs_unescape_string_for_display (dialog
->priv
->current_entry
->location
);
351 gtk_label_set_text (GTK_LABEL (dialog
->priv
->location
), unescaped
);
356 rb_podcast_properties_dialog_rated_cb (RBRating
*rating
,
358 RBPodcastPropertiesDialog
*dialog
)
360 GValue value
= { 0, };
362 g_return_if_fail (RB_IS_RATING (rating
));
363 g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (dialog
));
364 g_return_if_fail (score
>= 0 && score
<= 5 );
366 /* set the new value for the song */
367 g_value_init (&value
, G_TYPE_DOUBLE
);
368 g_value_set_double (&value
, score
);
369 rhythmdb_entry_set (dialog
->priv
->db
,
370 dialog
->priv
->current_entry
,
371 RHYTHMDB_PROP_RATING
,
373 rhythmdb_commit (dialog
->priv
->db
);
374 g_value_unset (&value
);
376 g_object_set (G_OBJECT (dialog
->priv
->rating
),
382 rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog
*dialog
)
385 text
= g_strdup_printf ("%ld", dialog
->priv
->current_entry
->play_count
);
386 gtk_label_set_text (GTK_LABEL (dialog
->priv
->playcount
), text
);
391 rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog
*dialog
)
396 bitrate
= dialog
->priv
->current_entry
->bitrate
;
398 tmp
= g_strdup_printf (_("%lu kbps"), bitrate
);
400 tmp
= g_strdup (_("Unknown"));
402 gtk_label_set_text (GTK_LABEL (dialog
->priv
->bitrate
), tmp
);
407 rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog
*dialog
)
409 gtk_label_set (GTK_LABEL (dialog
->priv
->lastplayed
),
410 rb_refstring_get (dialog
->priv
->current_entry
->last_played_str
));
414 rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog
*dialog
)
416 g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (dialog
));
418 g_object_set (G_OBJECT (dialog
->priv
->rating
),
419 "rating", dialog
->priv
->current_entry
->rating
, NULL
);
423 rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog
*dialog
)
427 time
= rb_podcast_properties_dialog_parse_time (dialog
->priv
->current_entry
->podcast
->post_time
);
429 gtk_label_set (GTK_LABEL (dialog
->priv
->date
),
435 rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog
*dialog
)
437 gtk_label_set (GTK_LABEL (dialog
->priv
->description
),
438 rb_refstring_get (dialog
->priv
->current_entry
->podcast
->description
));
442 rb_podcast_properties_dialog_parse_time (gulong value
)
447 str
= g_strdup (_("Unknown"));
449 str
= rb_utf_friendly_time ((time_t)value
);