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"
38
#include "rb-cut-and-paste-code.h"
40
static void rb_podcast_properties_dialog_class_init (RBPodcastPropertiesDialogClass *klass);
41
static void rb_podcast_properties_dialog_init (RBPodcastPropertiesDialog *dialog);
42
static void rb_podcast_properties_dialog_finalize (GObject *object);
43
static void rb_podcast_properties_dialog_set_property (GObject *object,
47
static void rb_podcast_properties_dialog_get_property (GObject *object,
51
static gboolean rb_podcast_properties_dialog_get_current_entry (RBPodcastPropertiesDialog *dialog);
52
static void rb_podcast_properties_dialog_update_title (RBPodcastPropertiesDialog *dialog);
53
static void rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog *dialog);
54
static void rb_podcast_properties_dialog_response_cb (GtkDialog *gtkdialog,
56
RBPodcastPropertiesDialog *dialog);
58
static void rb_podcast_properties_dialog_update (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_play_count (RBPodcastPropertiesDialog *dialog);
62
static void rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog *dialog);
63
static void rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog *dialog);
64
static void rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog *dialog);
65
static void rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog *dialog);
66
static void rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog *dialog);
67
static gchar* rb_podcast_properties_dialog_parse_time (gulong time);
68
static void rb_podcast_properties_dialog_rated_cb (RBRating *rating,
70
RBPodcastPropertiesDialog *dialog);
71
static GtkWidget * boldify_label (GtkWidget *label);
73
struct RBPodcastPropertiesDialogPrivate
75
RBEntryView *entry_view;
77
RhythmDBEntry *current_entry;
82
GtkWidget *lastplayed;
87
GtkWidget *description;
99
G_DEFINE_TYPE (RBPodcastPropertiesDialog, rb_podcast_properties_dialog, GTK_TYPE_DIALOG)
103
rb_podcast_properties_dialog_class_init (RBPodcastPropertiesDialogClass *klass)
105
GObjectClass *object_class = G_OBJECT_CLASS (klass);
107
object_class->set_property = rb_podcast_properties_dialog_set_property;
108
object_class->get_property = rb_podcast_properties_dialog_get_property;
110
g_object_class_install_property (object_class,
112
g_param_spec_object ("entry-view",
114
"RBEntryView object",
116
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
118
object_class->finalize = rb_podcast_properties_dialog_finalize;
122
rb_podcast_properties_dialog_init (RBPodcastPropertiesDialog *dialog)
126
dialog->priv = g_new0 (RBPodcastPropertiesDialogPrivate, 1);
128
g_signal_connect_object (G_OBJECT (dialog),
130
G_CALLBACK (rb_podcast_properties_dialog_response_cb),
133
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
134
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
135
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
137
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
140
xml = rb_glade_xml_new ("podcast-properties.glade",
143
glade_xml_signal_autoconnect (xml);
145
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
146
glade_xml_get_widget (xml, "podcastproperties"));
147
dialog->priv->okbutton = gtk_dialog_add_button (GTK_DIALOG (dialog),
150
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
152
/* get the widgets from the XML */
153
dialog->priv->title = glade_xml_get_widget (xml, "titleLabel");
154
dialog->priv->feed = glade_xml_get_widget (xml, "feedLabel");
155
dialog->priv->location = glade_xml_get_widget (xml, "locationLabel");
156
dialog->priv->lastplayed = glade_xml_get_widget (xml, "lastplayedLabel");
157
dialog->priv->playcount = glade_xml_get_widget (xml, "playcountLabel");
158
dialog->priv->bitrate = glade_xml_get_widget (xml, "bitrateLabel");
159
dialog->priv->date = glade_xml_get_widget (xml, "dateLabel");
160
dialog->priv->description = glade_xml_get_widget (xml, "descriptionLabel");
162
boldify_label (glade_xml_get_widget (xml, "titleDescLabel"));
163
boldify_label (glade_xml_get_widget (xml, "feedDescLabel"));
164
boldify_label (glade_xml_get_widget (xml, "locationDescLabel"));
165
boldify_label (glade_xml_get_widget (xml, "ratingDescLabel"));
166
boldify_label (glade_xml_get_widget (xml, "lastplayedDescLabel"));
167
boldify_label (glade_xml_get_widget (xml, "playcountDescLabel"));
168
boldify_label (glade_xml_get_widget (xml, "bitrateDescLabel"));
169
boldify_label (glade_xml_get_widget (xml, "dateDescLabel"));
170
boldify_label (glade_xml_get_widget (xml, "descriptionDescLabel"));
172
dialog->priv->rating = GTK_WIDGET (rb_rating_new ());
173
g_signal_connect_object (dialog->priv->rating,
175
G_CALLBACK (rb_podcast_properties_dialog_rated_cb),
176
G_OBJECT (dialog), 0);
177
gtk_container_add (GTK_CONTAINER (glade_xml_get_widget (xml, "ratingVBox")),
178
dialog->priv->rating);
179
g_object_unref (G_OBJECT (xml));
183
rb_podcast_properties_dialog_finalize (GObject *object)
185
RBPodcastPropertiesDialog *dialog;
187
g_return_if_fail (object != NULL);
188
g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (object));
190
dialog = RB_PODCAST_PROPERTIES_DIALOG (object);
192
g_return_if_fail (dialog->priv != NULL);
194
g_free (dialog->priv);
196
G_OBJECT_CLASS (rb_podcast_properties_dialog_parent_class)->finalize (object);
200
rb_podcast_properties_dialog_set_property (GObject *object,
205
RBPodcastPropertiesDialog *dialog = RB_PODCAST_PROPERTIES_DIALOG (object);
208
case PROP_ENTRY_VIEW:
209
dialog->priv->entry_view = g_value_get_object (value);
210
g_object_get (G_OBJECT (dialog->priv->entry_view), "db",
211
&dialog->priv->db, NULL);
214
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220
rb_podcast_properties_dialog_get_property (GObject *object,
225
RBPodcastPropertiesDialog *dialog = RB_PODCAST_PROPERTIES_DIALOG (object);
228
case PROP_ENTRY_VIEW:
229
g_value_set_object (value, dialog->priv->entry_view);
232
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
238
rb_podcast_properties_dialog_new (RBEntryView *entry_view)
240
RBPodcastPropertiesDialog *dialog;
242
g_return_val_if_fail (RB_IS_ENTRY_VIEW (entry_view), NULL);
244
dialog = g_object_new (RB_TYPE_PODCAST_PROPERTIES_DIALOG,
245
"entry-view", entry_view, NULL);
247
if (!rb_podcast_properties_dialog_get_current_entry (dialog)) {
248
g_object_unref (G_OBJECT (dialog));
251
rb_podcast_properties_dialog_update (dialog);
253
return GTK_WIDGET (dialog);
257
boldify_label (GtkWidget *label)
260
str_final = g_strdup_printf ("<b>%s</b>",
261
gtk_label_get_label (GTK_LABEL (label)));
262
gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), str_final);
268
rb_podcast_properties_dialog_response_cb (GtkDialog *gtkdialog,
270
RBPodcastPropertiesDialog *dialog)
272
if (response_id != GTK_RESPONSE_OK)
275
gtk_widget_destroy (GTK_WIDGET (dialog));
279
rb_podcast_properties_dialog_get_current_entry (RBPodcastPropertiesDialog *dialog)
281
GList *selected_entries;
284
selected_entries = rb_entry_view_get_selected_entries (dialog->priv->entry_view);
286
if ((selected_entries == NULL) ||
287
(selected_entries->data == NULL)) {
288
dialog->priv->current_entry = NULL;
292
dialog->priv->current_entry = selected_entries->data;
297
rb_podcast_properties_dialog_update (RBPodcastPropertiesDialog *dialog)
299
g_return_if_fail (dialog->priv->current_entry != NULL);
300
rb_podcast_properties_dialog_update_location (dialog);
301
rb_podcast_properties_dialog_update_title (dialog);
302
rb_podcast_properties_dialog_update_title_label (dialog);
303
rb_podcast_properties_dialog_update_feed (dialog);
304
rb_podcast_properties_dialog_update_play_count (dialog);
305
rb_podcast_properties_dialog_update_bitrate (dialog);
306
rb_podcast_properties_dialog_update_last_played (dialog);
307
rb_podcast_properties_dialog_update_rating (dialog);
308
rb_podcast_properties_dialog_update_date (dialog);
309
rb_podcast_properties_dialog_update_description (dialog);
313
rb_podcast_properties_dialog_update_title (RBPodcastPropertiesDialog *dialog)
317
name = rb_refstring_get (dialog->priv->current_entry->title);
318
tmp = g_strdup_printf (_("Properties for %s"), name);
319
gtk_window_set_title (GTK_WINDOW (dialog), tmp);
324
rb_podcast_properties_dialog_update_title_label (RBPodcastPropertiesDialog *dialog)
326
gtk_label_set_text (GTK_LABEL (dialog->priv->title),
327
rb_refstring_get (dialog->priv->current_entry->title));
331
rb_podcast_properties_dialog_update_feed (RBPodcastPropertiesDialog *dialog)
333
gtk_label_set_text (GTK_LABEL (dialog->priv->feed),
334
rb_refstring_get (dialog->priv->current_entry->podcast->subtitle));
338
rb_podcast_properties_dialog_update_location (RBPodcastPropertiesDialog *dialog)
341
unescaped = gnome_vfs_unescape_string_for_display (dialog->priv->current_entry->location);
342
gtk_label_set_text (GTK_LABEL (dialog->priv->location), unescaped);
347
rb_podcast_properties_dialog_rated_cb (RBRating *rating,
349
RBPodcastPropertiesDialog *dialog)
351
GValue value = { 0, };
353
g_return_if_fail (RB_IS_RATING (rating));
354
g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (dialog));
355
g_return_if_fail (score >= 0 && score <= 5 );
357
/* set the new value for the song */
358
g_value_init (&value, G_TYPE_DOUBLE);
359
g_value_set_double (&value, score);
360
rhythmdb_entry_set (dialog->priv->db,
361
dialog->priv->current_entry,
362
RHYTHMDB_PROP_RATING,
364
rhythmdb_commit (dialog->priv->db);
365
g_value_unset (&value);
367
g_object_set (G_OBJECT (dialog->priv->rating),
373
rb_podcast_properties_dialog_update_play_count (RBPodcastPropertiesDialog *dialog)
376
text = g_strdup_printf ("%ld", dialog->priv->current_entry->play_count);
377
gtk_label_set_text (GTK_LABEL (dialog->priv->playcount), text);
382
rb_podcast_properties_dialog_update_bitrate (RBPodcastPropertiesDialog *dialog)
387
val = dialog->priv->current_entry->bitrate;
389
text = g_strdup (_("Unknown"));
391
text = g_strdup_printf ("%d", val);
393
gtk_label_set_text (GTK_LABEL (dialog->priv->bitrate), text);
398
rb_podcast_properties_dialog_update_last_played (RBPodcastPropertiesDialog *dialog)
400
gtk_label_set (GTK_LABEL (dialog->priv->lastplayed),
401
rb_refstring_get (dialog->priv->current_entry->last_played_str));
405
rb_podcast_properties_dialog_update_rating (RBPodcastPropertiesDialog *dialog)
407
g_return_if_fail (RB_IS_PODCAST_PROPERTIES_DIALOG (dialog));
409
g_object_set (G_OBJECT (dialog->priv->rating),
410
"rating", dialog->priv->current_entry->rating, NULL);
414
rb_podcast_properties_dialog_update_date (RBPodcastPropertiesDialog *dialog)
418
time = rb_podcast_properties_dialog_parse_time (dialog->priv->current_entry->podcast->post_time);
420
gtk_label_set (GTK_LABEL (dialog->priv->date),
426
rb_podcast_properties_dialog_update_description (RBPodcastPropertiesDialog *dialog)
428
gtk_label_set (GTK_LABEL (dialog->priv->description),
429
rb_refstring_get (dialog->priv->current_entry->podcast->description));
433
rb_podcast_properties_dialog_parse_time (gulong value)
442
localtime_r ((time_t*)&value, &then);
443
str = eel_strdup_strftime (_("%Y-%m-%d %H:%M"), &then);