Updated Macedonian Translation <arangela@cvs.gnome.org>
[rhythmbox.git] / podcast / rb-podcast-properties-dialog.c
blob7d39553ad9b640a5dfc8e5c014b553330a078ccd
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
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.
23 #include <config.h>
25 #include <string.h>
26 #include <time.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.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"
38 #include "rb-util.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,
45 guint prop_id,
46 const GValue *value,
47 GParamSpec *pspec);
48 static void rb_podcast_properties_dialog_get_property (GObject *object,
49 guint prop_id,
50 GValue *value,
51 GParamSpec *pspec);
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,
56 int response_id,
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,
71 double score,
72 RBPodcastPropertiesDialog *dialog);
74 struct RBPodcastPropertiesDialogPrivate
76 RBEntryView *entry_view;
77 RhythmDB *db;
78 RhythmDBEntry *current_entry;
80 GtkWidget *title;
81 GtkWidget *feed;
82 GtkWidget *location;
83 GtkWidget *duration;
84 GtkWidget *lastplayed;
85 GtkWidget *playcount;
86 GtkWidget *bitrate;
87 GtkWidget *rating;
88 GtkWidget *date;
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))
96 enum
98 PROP_0,
99 PROP_ENTRY_VIEW,
100 PROP_BACKEND
103 G_DEFINE_TYPE (RBPodcastPropertiesDialog, rb_podcast_properties_dialog, GTK_TYPE_DIALOG)
106 static void
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,
115 PROP_ENTRY_VIEW,
116 g_param_spec_object ("entry-view",
117 "RBEntryView",
118 "RBEntryView object",
119 RB_TYPE_ENTRY_VIEW,
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));
127 static void
128 rb_podcast_properties_dialog_init (RBPodcastPropertiesDialog *dialog)
130 GladeXML *xml;
132 dialog->priv = RB_PODCAST_PROPERTIES_DIALOG_GET_PRIVATE (dialog);
134 g_signal_connect_object (G_OBJECT (dialog),
135 "response",
136 G_CALLBACK (rb_podcast_properties_dialog_response_cb),
137 dialog, 0);
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),
144 GTK_RESPONSE_OK);
146 xml = rb_glade_xml_new ("podcast-properties.glade",
147 "podcastproperties",
148 dialog);
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),
154 GTK_STOCK_CLOSE,
155 GTK_RESPONSE_CLOSE);
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,
182 "rated",
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));
190 static void
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);
205 static void
206 rb_podcast_properties_dialog_set_property (GObject *object,
207 guint prop_id,
208 const GValue *value,
209 GParamSpec *pspec)
211 RBPodcastPropertiesDialog *dialog = RB_PODCAST_PROPERTIES_DIALOG (object);
213 switch (prop_id) {
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);
218 break;
219 default:
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
221 break;
225 static void
226 rb_podcast_properties_dialog_get_property (GObject *object,
227 guint prop_id,
228 GValue *value,
229 GParamSpec *pspec)
231 RBPodcastPropertiesDialog *dialog = RB_PODCAST_PROPERTIES_DIALOG (object);
233 switch (prop_id) {
234 case PROP_ENTRY_VIEW:
235 g_value_set_object (value, dialog->priv->entry_view);
236 break;
237 default:
238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 break;
243 GtkWidget *
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));
255 return NULL;
257 rb_podcast_properties_dialog_update (dialog);
259 return GTK_WIDGET (dialog);
262 static void
263 rb_podcast_properties_dialog_response_cb (GtkDialog *gtkdialog,
264 int response_id,
265 RBPodcastPropertiesDialog *dialog)
267 if (response_id != GTK_RESPONSE_OK)
268 goto cleanup;
269 cleanup:
270 gtk_widget_destroy (GTK_WIDGET (dialog));
273 static gboolean
274 rb_podcast_properties_dialog_get_current_entry (RBPodcastPropertiesDialog *dialog)
276 GList *selected_entries;
278 /* get the entry */
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;
284 return FALSE;
287 dialog->priv->current_entry = selected_entries->data;
288 return TRUE;
291 static void
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);
308 static void
309 rb_podcast_properties_dialog_update_title (RBPodcastPropertiesDialog *dialog)
311 const char *name;
312 char *tmp;
314 name = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_TITLE);
315 tmp = g_strdup_printf (_("%s Properties"), name);
316 gtk_window_set_title (GTK_WINDOW (dialog), tmp);
317 g_free (tmp);
320 static void
321 rb_podcast_properties_dialog_update_title_label (RBPodcastPropertiesDialog *dialog)
323 const char *title;
325 title = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_TITLE);
326 gtk_label_set_text (GTK_LABEL (dialog->priv->title), title);
329 static void
330 rb_podcast_properties_dialog_update_feed (RBPodcastPropertiesDialog *dialog)
332 const char *feed;
334 feed = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_ALBUM);
335 gtk_label_set_text (GTK_LABEL (dialog->priv->feed), feed);
338 static void
339 rb_podcast_properties_dialog_update_duration (RBPodcastPropertiesDialog *dialog)
341 char *text;
342 gulong duration = 0;
344 duration = rhythmdb_entry_get_ulong (dialog->priv->current_entry, RHYTHMDB_PROP_DURATION);
346 text = rb_make_duration_string (duration);
347 gtk_label_set_text (GTK_LABEL (dialog->priv->duration), text);
348 g_free (text);
351 static void
352 rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog *dialog)
354 const char *location;
355 char *unescaped;
357 location = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_LOCATION);
358 unescaped = gnome_vfs_unescape_string_for_display (location);
359 gtk_label_set_text (GTK_LABEL (dialog->priv->location), unescaped);
360 g_free (unescaped);
363 static void
364 rb_podcast_properties_dialog_rated_cb (RBRating *rating,
365 double score,
366 RBPodcastPropertiesDialog *dialog)
368 GValue value = { 0, };
370 g_return_if_fail (RB_IS_RATING (rating));
371 g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (dialog));
372 g_return_if_fail (score >= 0 && score <= 5 );
374 /* set the new value for the song */
375 g_value_init (&value, G_TYPE_DOUBLE);
376 g_value_set_double (&value, score);
377 rhythmdb_entry_set (dialog->priv->db,
378 dialog->priv->current_entry,
379 RHYTHMDB_PROP_RATING,
380 &value);
381 rhythmdb_commit (dialog->priv->db);
382 g_value_unset (&value);
384 g_object_set (G_OBJECT (dialog->priv->rating),
385 "rating", score,
386 NULL);
389 static void
390 rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog *dialog)
392 gulong count;
393 char *text;
395 count = rhythmdb_entry_get_ulong (dialog->priv->current_entry, RHYTHMDB_PROP_PLAY_COUNT);
396 text = g_strdup_printf ("%ld", count);
397 gtk_label_set_text (GTK_LABEL (dialog->priv->playcount), text);
398 g_free (text);
401 static void
402 rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog *dialog)
404 char *tmp = NULL;
405 gulong bitrate = 0;
407 bitrate = rhythmdb_entry_get_ulong (dialog->priv->current_entry, RHYTHMDB_PROP_BITRATE);
408 if (bitrate > 0)
409 tmp = g_strdup_printf (_("%lu kbps"), bitrate);
410 else
411 tmp = g_strdup (_("Unknown"));
413 gtk_label_set_text (GTK_LABEL (dialog->priv->bitrate), tmp);
414 g_free (tmp);
417 static void
418 rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog *dialog)
420 const char *str;
422 str = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_LAST_PLAYED_STR);
423 gtk_label_set (GTK_LABEL (dialog->priv->lastplayed), str);
426 static void
427 rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog *dialog)
429 double rating;
431 rating = rhythmdb_entry_get_double (dialog->priv->current_entry, RHYTHMDB_PROP_RATING);
432 g_object_set (G_OBJECT (dialog->priv->rating), "rating", rating, NULL);
435 static void
436 rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog *dialog)
438 gulong post_time;
439 char *time;
441 post_time = rhythmdb_entry_get_ulong (dialog->priv->current_entry, RHYTHMDB_PROP_POST_TIME);
442 time = rb_podcast_properties_dialog_parse_time (post_time);
444 gtk_label_set (GTK_LABEL (dialog->priv->date),
445 time);
446 g_free (time);
449 static void
450 rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog *dialog)
452 const char *str;
454 str = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_DESCRIPTION);
455 gtk_label_set (GTK_LABEL (dialog->priv->description), str);
458 static char *
459 rb_podcast_properties_dialog_parse_time (gulong value)
461 char *str;
463 if (0 == value) {
464 str = g_strdup (_("Unknown"));
465 } else {
466 str = rb_utf_friendly_time ((time_t)value);
469 return str;