Updated Macedonian translation <arangela@cvs.gnome.org>
[rhythmbox.git] / podcast / rb-podcast-properties-dialog.c
blobc021673b028872ded8811d76a5a47f5515e11e58
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;
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);
316 g_free (tmp);
319 static void
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));
326 static void
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));
333 static void
334 rb_podcast_properties_dialog_update_duration (RBPodcastPropertiesDialog *dialog)
336 char *text;
337 gulong duration = 0;
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);
343 g_free (text);
346 static void
347 rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog *dialog)
349 char *unescaped;
350 unescaped = gnome_vfs_unescape_string_for_display (dialog->priv->current_entry->location);
351 gtk_label_set_text (GTK_LABEL (dialog->priv->location), unescaped);
352 g_free (unescaped);
355 static void
356 rb_podcast_properties_dialog_rated_cb (RBRating *rating,
357 double score,
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,
372 &value);
373 rhythmdb_commit (dialog->priv->db);
374 g_value_unset (&value);
376 g_object_set (G_OBJECT (dialog->priv->rating),
377 "rating", score,
378 NULL);
381 static void
382 rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog *dialog)
384 char *text;
385 text = g_strdup_printf ("%ld", dialog->priv->current_entry->play_count);
386 gtk_label_set_text (GTK_LABEL (dialog->priv->playcount), text);
387 g_free (text);
390 static void
391 rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog *dialog)
393 char *tmp = NULL;
394 gulong bitrate = 0;
396 bitrate = dialog->priv->current_entry->bitrate;
397 if (bitrate > 0)
398 tmp = g_strdup_printf (_("%lu kbps"), bitrate);
399 else
400 tmp = g_strdup (_("Unknown"));
402 gtk_label_set_text (GTK_LABEL (dialog->priv->bitrate), tmp);
403 g_free (tmp);
406 static void
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));
413 static void
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);
422 static void
423 rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog *dialog)
425 char *time;
427 time = rb_podcast_properties_dialog_parse_time (dialog->priv->current_entry->podcast->post_time);
429 gtk_label_set (GTK_LABEL (dialog->priv->date),
430 time);
431 g_free (time);
434 static void
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));
441 static char *
442 rb_podcast_properties_dialog_parse_time (gulong value)
444 char *str;
446 if (0 == value) {
447 str = g_strdup (_("Unknown"));
448 } else {
449 str = rb_utf_friendly_time ((time_t)value);
452 return str;