1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* arch-tag: Implementation of internet radio station properties dialog
5
* Copyright (C) 2002 Colin Walters <walters@gnu.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.
28
#include <glib/gi18n.h>
30
#include <glade/glade.h>
31
#include <libgnomevfs/gnome-vfs.h>
33
#include "rb-station-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
static void rb_station_properties_dialog_class_init (RBStationPropertiesDialogClass *klass);
40
static void rb_station_properties_dialog_init (RBStationPropertiesDialog *dialog);
41
static void rb_station_properties_dialog_dispose (GObject *object);
42
static void rb_station_properties_dialog_finalize (GObject *object);
43
static void rb_station_properties_dialog_set_property (GObject *object,
47
static void rb_station_properties_dialog_get_property (GObject *object,
51
static gboolean rb_station_properties_dialog_get_current_entry (RBStationPropertiesDialog *dialog);
52
static void rb_station_properties_dialog_update_title (RBStationPropertiesDialog *dialog);
53
static void rb_station_properties_dialog_update_location (RBStationPropertiesDialog *dialog);
54
static void rb_station_properties_dialog_response_cb (GtkDialog *gtkdialog,
56
RBStationPropertiesDialog *dialog);
58
static void rb_station_properties_dialog_update (RBStationPropertiesDialog *dialog);
59
static void rb_station_properties_dialog_update_title_entry (RBStationPropertiesDialog *dialog);
60
static void rb_station_properties_dialog_update_genre (RBStationPropertiesDialog *dialog);
61
static void rb_station_properties_dialog_update_play_count (RBStationPropertiesDialog *dialog);
62
static void rb_station_properties_dialog_update_bitrate (RBStationPropertiesDialog *dialog);
63
static void rb_station_properties_dialog_update_last_played (RBStationPropertiesDialog *dialog);
64
static void rb_station_properties_dialog_update_rating (RBStationPropertiesDialog *dialog);
65
static void rb_station_properties_dialog_update_playback_error (RBStationPropertiesDialog *dialog);
66
static void rb_station_properties_dialog_rated_cb (RBRating *rating,
68
RBStationPropertiesDialog *dialog);
69
static void rb_station_properties_dialog_sync_entries (RBStationPropertiesDialog *dialog);
70
static void rb_station_properties_dialog_show (GtkWidget *widget);
71
static void rb_station_properties_dialog_location_changed_cb (GtkEntry *entry,
72
RBStationPropertiesDialog *dialog);
74
struct RBStationPropertiesDialogPrivate
76
RBEntryView *entry_view;
78
RhythmDBEntry *current_entry;
83
GtkWidget *lastplayed;
87
GtkWidget *playback_error;
88
GtkWidget *playback_error_box;
89
GtkWidget *close_button;
93
#define RB_STATION_PROPERTIES_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_STATION_PROPERTIES_DIALOG, RBStationPropertiesDialogPrivate))
101
G_DEFINE_TYPE (RBStationPropertiesDialog,
102
rb_station_properties_dialog,
106
rb_station_properties_dialog_class_init (RBStationPropertiesDialogClass *klass)
108
GObjectClass *object_class = G_OBJECT_CLASS (klass);
109
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
111
object_class->set_property = rb_station_properties_dialog_set_property;
112
object_class->get_property = rb_station_properties_dialog_get_property;
114
widget_class->show = rb_station_properties_dialog_show;
116
g_object_class_install_property (object_class,
118
g_param_spec_object ("entry-view",
120
"RBEntryView object",
122
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
124
object_class->dispose = rb_station_properties_dialog_dispose;
125
object_class->finalize = rb_station_properties_dialog_finalize;
127
g_type_class_add_private (klass, sizeof (RBStationPropertiesDialogPrivate));
131
rb_station_properties_dialog_init (RBStationPropertiesDialog *dialog)
135
dialog->priv = RB_STATION_PROPERTIES_DIALOG_GET_PRIVATE (dialog);
137
g_signal_connect_object (G_OBJECT (dialog),
139
G_CALLBACK (rb_station_properties_dialog_response_cb),
142
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
143
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
144
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
146
xml = rb_glade_xml_new ("station-properties.glade",
149
glade_xml_signal_autoconnect (xml);
151
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
152
glade_xml_get_widget (xml, "stationproperties"));
154
dialog->priv->close_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
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, "titleEntry");
161
dialog->priv->genre = glade_xml_get_widget (xml, "genreEntry");
162
dialog->priv->location = glade_xml_get_widget (xml, "locationEntry");
164
dialog->priv->lastplayed = glade_xml_get_widget (xml, "lastplayedLabel");
165
dialog->priv->playcount = glade_xml_get_widget (xml, "playcountLabel");
166
dialog->priv->bitrate = glade_xml_get_widget (xml, "bitrateLabel");
167
dialog->priv->playback_error = glade_xml_get_widget (xml, "errorLabel");
168
dialog->priv->playback_error_box = glade_xml_get_widget (xml, "errorBox");
170
rb_glade_boldify_label (xml, "titleLabel");
171
rb_glade_boldify_label (xml, "genreLabel");
172
rb_glade_boldify_label (xml, "locationLabel");
173
rb_glade_boldify_label (xml, "ratingLabel");
174
rb_glade_boldify_label (xml, "lastplayedDescLabel");
175
rb_glade_boldify_label (xml, "playcountDescLabel");
176
rb_glade_boldify_label (xml, "bitrateDescLabel");
178
g_signal_connect_object (G_OBJECT (dialog->priv->location),
180
G_CALLBACK (rb_station_properties_dialog_location_changed_cb),
183
dialog->priv->rating = GTK_WIDGET (rb_rating_new ());
184
g_signal_connect_object (dialog->priv->rating,
186
G_CALLBACK (rb_station_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));
194
rb_station_properties_dialog_dispose (GObject *object)
196
RBStationPropertiesDialog *dialog;
198
g_return_if_fail (object != NULL);
199
g_return_if_fail (RB_IS_STATION_PROPERTIES_DIALOG (object));
201
dialog = RB_STATION_PROPERTIES_DIALOG (object);
202
g_return_if_fail (dialog->priv != NULL);
204
if (dialog->priv->db != NULL) {
205
g_object_unref (dialog->priv->db);
208
G_OBJECT_CLASS (rb_station_properties_dialog_parent_class)->dispose (object);
212
rb_station_properties_dialog_finalize (GObject *object)
214
RBStationPropertiesDialog *dialog;
216
g_return_if_fail (object != NULL);
217
g_return_if_fail (RB_IS_STATION_PROPERTIES_DIALOG (object));
219
dialog = RB_STATION_PROPERTIES_DIALOG (object);
221
g_return_if_fail (dialog->priv != NULL);
223
G_OBJECT_CLASS (rb_station_properties_dialog_parent_class)->finalize (object);
227
rb_station_properties_dialog_set_property (GObject *object,
232
RBStationPropertiesDialog *dialog = RB_STATION_PROPERTIES_DIALOG (object);
235
case PROP_ENTRY_VIEW:
236
if (dialog->priv->db != NULL) {
237
g_object_unref (dialog->priv->db);
240
dialog->priv->entry_view = g_value_get_object (value);
242
g_object_get (G_OBJECT (dialog->priv->entry_view),
243
"db", &dialog->priv->db, NULL);
246
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
252
rb_station_properties_dialog_get_property (GObject *object,
257
RBStationPropertiesDialog *dialog = RB_STATION_PROPERTIES_DIALOG (object);
260
case PROP_ENTRY_VIEW:
261
g_value_set_object (value, dialog->priv->entry_view);
264
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
270
rb_station_properties_dialog_new (RBEntryView *entry_view)
272
RBStationPropertiesDialog *dialog;
274
g_return_val_if_fail (RB_IS_ENTRY_VIEW (entry_view), NULL);
276
dialog = g_object_new (RB_TYPE_STATION_PROPERTIES_DIALOG,
277
"entry-view", entry_view,
280
if (!rb_station_properties_dialog_get_current_entry (dialog)) {
281
g_object_unref (G_OBJECT (dialog));
285
rb_station_properties_dialog_update (dialog);
287
return GTK_WIDGET (dialog);
291
rb_station_properties_dialog_response_cb (GtkDialog *gtkdialog,
293
RBStationPropertiesDialog *dialog)
295
if (dialog->priv->current_entry)
296
rb_station_properties_dialog_sync_entries (dialog);
298
gtk_widget_destroy (GTK_WIDGET (dialog));
302
rb_station_properties_dialog_get_current_entry (RBStationPropertiesDialog *dialog)
304
GList *selected_entries;
307
selected_entries = rb_entry_view_get_selected_entries (dialog->priv->entry_view);
309
if ((selected_entries == NULL) ||
310
(selected_entries->data == NULL)) {
311
dialog->priv->current_entry = NULL;
315
if (dialog->priv->current_entry != NULL) {
316
rhythmdb_entry_unref (dialog->priv->current_entry);
319
dialog->priv->current_entry = rhythmdb_entry_ref (selected_entries->data);
321
g_list_foreach (selected_entries, (GFunc)rhythmdb_entry_unref, NULL);
322
g_list_free (selected_entries);
328
rb_station_properties_dialog_update (RBStationPropertiesDialog *dialog)
330
rb_station_properties_dialog_update_title (dialog);
332
if (dialog->priv->current_entry) {
333
rb_station_properties_dialog_update_location (dialog);
334
rb_station_properties_dialog_update_title_entry (dialog);
335
rb_station_properties_dialog_update_genre (dialog);
338
rb_station_properties_dialog_update_play_count (dialog);
339
rb_station_properties_dialog_update_bitrate (dialog);
340
rb_station_properties_dialog_update_last_played (dialog);
341
rb_station_properties_dialog_update_rating (dialog);
342
rb_station_properties_dialog_location_changed_cb (GTK_ENTRY (dialog->priv->location), dialog);
346
rb_station_properties_dialog_update_title (RBStationPropertiesDialog *dialog)
351
if (dialog->priv->current_entry) {
352
name = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_TITLE);
353
tmp = g_strdup_printf (_("%s Properties"), name);
354
gtk_window_set_title (GTK_WINDOW (dialog), tmp);
357
gtk_window_set_title (GTK_WINDOW (dialog), _("New Internet Radio Station"));
362
rb_station_properties_dialog_update_title_entry (RBStationPropertiesDialog *dialog)
366
title = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_TITLE);
367
gtk_entry_set_text (GTK_ENTRY (dialog->priv->title),title);
371
rb_station_properties_dialog_update_genre (RBStationPropertiesDialog *dialog)
375
genre = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_GENRE);
376
gtk_entry_set_text (GTK_ENTRY (dialog->priv->genre), genre);
380
rb_station_properties_dialog_update_location (RBStationPropertiesDialog *dialog)
382
const char *location;
385
location = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_LOCATION);
386
unescaped = gnome_vfs_unescape_string_for_display (location);
387
gtk_entry_set_text (GTK_ENTRY (dialog->priv->location), unescaped);
392
rb_station_properties_dialog_rated_cb (RBRating *rating,
394
RBStationPropertiesDialog *dialog)
396
GValue value = {0, };
398
g_return_if_fail (RB_IS_RATING (rating));
399
g_return_if_fail (RB_IS_STATION_PROPERTIES_DIALOG (dialog));
400
g_return_if_fail (score >= 0 && score <= 5 );
402
if (!dialog->priv->current_entry)
405
g_value_init (&value, G_TYPE_DOUBLE);
406
g_value_set_double (&value, score);
408
/* set the new value for the song */
409
rhythmdb_entry_set (dialog->priv->db,
410
dialog->priv->current_entry,
411
RHYTHMDB_PROP_RATING,
413
g_value_unset (&value);
414
rhythmdb_commit (dialog->priv->db);
416
g_object_set (G_OBJECT (dialog->priv->rating), "rating", score, NULL);
420
rb_station_properties_dialog_update_play_count (RBStationPropertiesDialog *dialog)
425
if (dialog->priv->current_entry)
426
count = rhythmdb_entry_get_ulong (dialog->priv->current_entry, RHYTHMDB_PROP_PLAY_COUNT);
428
text = g_strdup_printf ("%ld", count);
429
gtk_label_set_text (GTK_LABEL (dialog->priv->playcount), text);
434
rb_station_properties_dialog_update_bitrate (RBStationPropertiesDialog *dialog)
439
if (dialog->priv->current_entry)
440
val = rhythmdb_entry_get_ulong (dialog->priv->current_entry, RHYTHMDB_PROP_BITRATE);
443
text = g_strdup (_("Unknown"));
445
text = g_strdup_printf (_("%lu kbps"), val);
447
gtk_label_set_text (GTK_LABEL (dialog->priv->bitrate), text);
452
rb_station_properties_dialog_update_last_played (RBStationPropertiesDialog *dialog)
454
const char *last_played = _("Never");
456
if (dialog->priv->current_entry)
457
last_played = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_LAST_PLAYED_STR);
458
gtk_label_set (GTK_LABEL (dialog->priv->lastplayed), last_played);
462
rb_station_properties_dialog_update_rating (RBStationPropertiesDialog *dialog)
464
gdouble rating = 0.0;
465
g_return_if_fail (RB_IS_STATION_PROPERTIES_DIALOG (dialog));
467
if (dialog->priv->current_entry)
468
rating = rhythmdb_entry_get_double (dialog->priv->current_entry, RHYTHMDB_PROP_RATING);
470
g_object_set (G_OBJECT (dialog->priv->rating), "rating", rating, NULL);
474
rb_station_properties_dialog_update_playback_error (RBStationPropertiesDialog *dialog)
478
g_return_if_fail (RB_IS_STATION_PROPERTIES_DIALOG (dialog));
480
error = rhythmdb_entry_get_string (dialog->priv->current_entry, RHYTHMDB_PROP_PLAYBACK_ERROR);
481
if (dialog->priv->current_entry && error) {
482
gtk_label_set_text (GTK_LABEL (dialog->priv->playback_error), error);
483
gtk_widget_show (dialog->priv->playback_error_box);
485
gtk_label_set_text (GTK_LABEL (dialog->priv->playback_error), "");
486
gtk_widget_hide (dialog->priv->playback_error_box);
491
rb_station_properties_dialog_sync_entries (RBStationPropertiesDialog *dialog)
495
const char *location;
498
gboolean changed = FALSE;
499
RhythmDBEntry *entry = dialog->priv->current_entry;
501
title = gtk_entry_get_text (GTK_ENTRY (dialog->priv->title));
502
genre = gtk_entry_get_text (GTK_ENTRY (dialog->priv->genre));
503
location = gtk_entry_get_text (GTK_ENTRY (dialog->priv->location));
505
string = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE);
506
if (strcmp (title, string)) {
507
g_value_init (&val, G_TYPE_STRING);
508
g_value_set_string (&val, title);
509
rhythmdb_entry_set (dialog->priv->db, entry,
512
g_value_unset (&val);
516
string = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_GENRE);
517
if (strcmp (genre, string)) {
518
g_value_init (&val, G_TYPE_STRING);
519
g_value_set_string (&val, genre);
520
rhythmdb_entry_set (dialog->priv->db, entry,
521
RHYTHMDB_PROP_GENRE, &val);
522
g_value_unset (&val);
526
string = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);
527
if (strcmp (location, string)) {
528
g_value_init (&val, G_TYPE_STRING);
529
g_value_set_string (&val, location);
530
rhythmdb_entry_set (dialog->priv->db, entry,
531
RHYTHMDB_PROP_LOCATION, &val);
532
g_value_unset (&val);
537
rhythmdb_commit (dialog->priv->db);
541
rb_station_properties_dialog_show (GtkWidget *widget)
543
if (GTK_WIDGET_CLASS (rb_station_properties_dialog_parent_class)->show)
544
GTK_WIDGET_CLASS (rb_station_properties_dialog_parent_class)->show (widget);
546
rb_station_properties_dialog_update_playback_error (
547
RB_STATION_PROPERTIES_DIALOG (widget));
551
rb_station_properties_dialog_location_changed_cb (GtkEntry *entry,
552
RBStationPropertiesDialog *dialog)