udapted vi.po
[rhythmbox.git] / podcast / rb-podcast-properties-dialog.c
blob26c6a153163fe9baed2bdb3ac08325b385a9dd55
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.
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_response_cb (GtkDialog *gtkdialog,
54 int response_id,
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,
72 double score,
73 RBPodcastPropertiesDialog *dialog);
75 struct RBPodcastPropertiesDialogPrivate
77 RBEntryView *entry_view;
78 RhythmDB *db;
79 RhythmDBEntry *current_entry;
81 GtkWidget *title;
82 GtkWidget *feed;
83 GtkWidget *location;
84 GtkWidget *download_location;
85 GtkWidget *duration;
86 GtkWidget *lastplayed;
87 GtkWidget *playcount;
88 GtkWidget *bitrate;
89 GtkWidget *rating;
90 GtkWidget *date;
91 GtkWidget *description;
93 GtkWidget *close_button;
96 enum
98 PROP_0,
99 PROP_ENTRY_VIEW,
100 PROP_BACKEND
103 G_DEFINE_TYPE (RBPodcastPropertiesDialog, rb_podcast_properties_dialog, GTK_TYPE_DIALOG)
105 static void
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,
114 PROP_ENTRY_VIEW,
115 g_param_spec_object ("entry-view",
116 "RBEntryView",
117 "RBEntryView object",
118 RB_TYPE_ENTRY_VIEW,
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));
126 static void
127 rb_podcast_properties_dialog_init (RBPodcastPropertiesDialog *dialog)
129 GladeXML *xml;
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),
136 "response",
137 G_CALLBACK (rb_podcast_properties_dialog_response_cb),
138 dialog, 0);
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),
145 GTK_RESPONSE_OK);
147 xml = rb_glade_xml_new ("podcast-properties.glade",
148 "podcastproperties",
149 dialog);
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),
155 GTK_STOCK_CLOSE,
156 GTK_RESPONSE_CLOSE);
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,
185 "rated",
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));
193 static void
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);
212 static void
213 rb_podcast_properties_dialog_set_entry_view (RBPodcastPropertiesDialog *dialog,
214 RBEntryView *view)
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);
228 static void
229 rb_podcast_properties_dialog_set_property (GObject *object,
230 guint prop_id,
231 const GValue *value,
232 GParamSpec *pspec)
234 RBPodcastPropertiesDialog *dialog = RB_PODCAST_PROPERTIES_DIALOG (object);
236 switch (prop_id) {
237 case PROP_ENTRY_VIEW:
238 rb_podcast_properties_dialog_set_entry_view (dialog, g_value_get_object (value));
239 break;
240 default:
241 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
242 break;
246 static void
247 rb_podcast_properties_dialog_get_property (GObject *object,
248 guint prop_id,
249 GValue *value,
250 GParamSpec *pspec)
252 RBPodcastPropertiesDialog *dialog = RB_PODCAST_PROPERTIES_DIALOG (object);
254 switch (prop_id) {
255 case PROP_ENTRY_VIEW:
256 g_value_set_object (value, dialog->priv->entry_view);
257 break;
258 default:
259 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
260 break;
264 GtkWidget *
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));
276 return NULL;
278 rb_podcast_properties_dialog_update (dialog);
280 return GTK_WIDGET (dialog);
283 static void
284 rb_podcast_properties_dialog_response_cb (GtkDialog *gtkdialog,
285 int response_id,
286 RBPodcastPropertiesDialog *dialog)
288 if (response_id != GTK_RESPONSE_OK)
289 goto cleanup;
290 cleanup:
291 gtk_widget_destroy (GTK_WIDGET (dialog));
294 static gboolean
295 rb_podcast_properties_dialog_get_current_entry (RBPodcastPropertiesDialog *dialog)
297 GList *selected_entries;
299 /* get the entry */
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;
305 return FALSE;
308 dialog->priv->current_entry = selected_entries->data;
309 return TRUE;
312 static void
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);
330 static void
331 rb_podcast_properties_dialog_update_title (RBPodcastPropertiesDialog *dialog)
333 const char *name;
334 char *tmp;
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);
339 g_free (tmp);
342 static void
343 rb_podcast_properties_dialog_update_title_label (RBPodcastPropertiesDialog *dialog)
345 const char *title;
347 title = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_TITLE);
348 gtk_label_set_text (GTK_LABEL (dialog->priv->title), title);
351 static void
352 rb_podcast_properties_dialog_update_feed (RBPodcastPropertiesDialog *dialog)
354 const char *feed;
356 feed = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_ALBUM);
357 gtk_label_set_text (GTK_LABEL (dialog->priv->feed), feed);
360 static void
361 rb_podcast_properties_dialog_update_duration (RBPodcastPropertiesDialog *dialog)
363 char *text;
364 gulong duration = 0;
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);
370 g_free (text);
373 static void
374 rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog *dialog)
376 const char *location;
377 char *display;
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);
382 g_free (display);
385 static void
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') {
392 char *display;
393 display = gnome_vfs_format_uri_for_display (location);
394 gtk_label_set_text (GTK_LABEL (dialog->priv->download_location), display);
395 g_free (display);
396 } else {
397 gtk_label_set_text (GTK_LABEL (dialog->priv->download_location), _("Not Downloaded"));
401 static void
402 rb_podcast_properties_dialog_rated_cb (RBRating *rating,
403 double score,
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,
418 &value);
419 rhythmdb_commit (dialog->priv->db);
420 g_value_unset (&value);
422 g_object_set (G_OBJECT (dialog->priv->rating),
423 "rating", score,
424 NULL);
427 static void
428 rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog *dialog)
430 gulong count;
431 char *text;
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);
436 g_free (text);
439 static void
440 rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog *dialog)
442 char *tmp = NULL;
443 gulong bitrate = 0;
445 bitrate = rhythmdb_entry_get_ulong (dialog->priv->current_entry, RHYTHMDB_PROP_BITRATE);
446 if (bitrate > 0)
447 tmp = g_strdup_printf (_("%lu kbps"), bitrate);
448 else
449 tmp = g_strdup (_("Unknown"));
451 gtk_label_set_text (GTK_LABEL (dialog->priv->bitrate), tmp);
452 g_free (tmp);
455 static void
456 rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog *dialog)
458 const char *str;
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);
464 static void
465 rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog *dialog)
467 double rating;
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);
473 static void
474 rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog *dialog)
476 gulong post_time;
477 char *time;
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),
483 time);
484 g_free (time);
487 static void
488 rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog *dialog)
490 const char *str;
492 str = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_DESCRIPTION);
493 gtk_label_set (GTK_LABEL (dialog->priv->description), str);
496 static char *
497 rb_podcast_properties_dialog_parse_time (gulong value)
499 char *str;
501 if (0 == value) {
502 str = g_strdup (_("Unknown"));
503 } else {
504 str = rb_utf_friendly_time ((time_t)value);
507 return str;