2
* arch-tag: Implementation of new internet radio station dialog
4
* Copyright (C) 2002,2003 Colin Walters <walters@gnu.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include <libgnomevfs/gnome-vfs.h>
24
#include <libgnome/gnome-i18n.h>
25
#include <gtk/gtkentry.h>
26
#include <gtk/gtklabel.h>
27
#include <gtk/gtkcombo.h>
28
#include <gtk/gtkbox.h>
29
#include <gtk/gtktable.h>
30
#include <gtk/gtkdialog.h>
31
#include <gtk/gtkstock.h>
32
#include <glade/glade.h>
36
#include "rb-new-station-dialog.h"
37
#include "rb-glade-helpers.h"
38
#include "rb-dialog.h"
40
static void rb_new_station_dialog_class_init (RBNewStationDialogClass *klass);
41
static void rb_new_station_dialog_init (RBNewStationDialog *dialog);
42
static void rb_new_station_dialog_finalize (GObject *object);
43
static void rb_new_station_dialog_set_property (GObject *object,
47
static void rb_new_station_dialog_get_property (GObject *object,
51
static void rb_new_station_dialog_response_cb (GtkDialog *gtkdialog,
53
RBNewStationDialog *dialog);
54
static void rb_new_station_dialog_entry_changed_cb (GtkEntry *entry,
55
RBNewStationDialog *dialog);
57
struct RBNewStationDialogPrivate
65
GtkWidget *cancelbutton;
74
static GObjectClass *parent_class = NULL;
77
rb_new_station_dialog_get_type (void)
79
static GType rb_new_station_dialog_type = 0;
81
if (rb_new_station_dialog_type == 0)
83
static const GTypeInfo our_info =
85
sizeof (RBNewStationDialogClass),
88
(GClassInitFunc) rb_new_station_dialog_class_init,
91
sizeof (RBNewStationDialog),
93
(GInstanceInitFunc) rb_new_station_dialog_init
96
rb_new_station_dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
101
return rb_new_station_dialog_type;
105
rb_new_station_dialog_class_init (RBNewStationDialogClass *klass)
107
GObjectClass *object_class = G_OBJECT_CLASS (klass);
109
parent_class = g_type_class_peek_parent (klass);
111
object_class->set_property = rb_new_station_dialog_set_property;
112
object_class->get_property = rb_new_station_dialog_get_property;
114
g_object_class_install_property (object_class,
116
g_param_spec_object ("db",
120
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
122
object_class->finalize = rb_new_station_dialog_finalize;
126
rb_new_station_dialog_init (RBNewStationDialog *dialog)
130
/* create the dialog and some buttons forward - close */
131
dialog->priv = g_new0 (RBNewStationDialogPrivate, 1);
133
g_signal_connect_object (G_OBJECT (dialog),
135
G_CALLBACK (rb_new_station_dialog_response_cb),
138
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
139
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
140
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
142
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
144
gtk_window_set_title (GTK_WINDOW (dialog), _("New Internet Radio Station"));
146
dialog->priv->cancelbutton = gtk_dialog_add_button (GTK_DIALOG (dialog),
148
GTK_RESPONSE_CANCEL);
149
dialog->priv->okbutton = gtk_dialog_add_button (GTK_DIALOG (dialog),
152
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
154
xml = rb_glade_xml_new ("station-new.glade",
157
glade_xml_signal_autoconnect (xml);
159
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
160
glade_xml_get_widget (xml, "newstation"));
162
/* get the widgets from the XML */
163
dialog->priv->title = glade_xml_get_widget (xml, "titleEntry");
164
dialog->priv->genre = glade_xml_get_widget (xml, "genreCombo");
165
dialog->priv->location = glade_xml_get_widget (xml, "locationEntry");
166
g_signal_connect_object (G_OBJECT (dialog->priv->title),
168
G_CALLBACK (rb_new_station_dialog_entry_changed_cb),
171
g_signal_connect_object (G_OBJECT (GTK_COMBO (dialog->priv->genre)->entry),
173
G_CALLBACK (rb_new_station_dialog_entry_changed_cb),
176
g_signal_connect_object (G_OBJECT (dialog->priv->location),
178
G_CALLBACK (rb_new_station_dialog_entry_changed_cb),
181
gtk_combo_set_popdown_strings (GTK_COMBO (dialog->priv->genre),
182
g_list_append (NULL, _("Unknown")));
185
gtk_widget_grab_focus (dialog->priv->title);
187
gtk_widget_set_sensitive (dialog->priv->okbutton, FALSE);
189
g_object_unref (G_OBJECT (xml));
193
rb_new_station_dialog_finalize (GObject *object)
195
RBNewStationDialog *dialog;
197
g_return_if_fail (object != NULL);
198
g_return_if_fail (RB_IS_NEW_STATION_DIALOG (object));
200
dialog = RB_NEW_STATION_DIALOG (object);
202
g_return_if_fail (dialog->priv != NULL);
204
g_free (dialog->priv);
206
G_OBJECT_CLASS (parent_class)->finalize (object);
210
rb_new_station_dialog_set_property (GObject *object,
215
RBNewStationDialog *dialog = RB_NEW_STATION_DIALOG (object);
220
dialog->priv->db = g_value_get_object (value);
223
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229
rb_new_station_dialog_get_property (GObject *object,
234
RBNewStationDialog *dialog = RB_NEW_STATION_DIALOG (object);
239
g_value_set_object (value, dialog->priv->db);
242
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
248
rb_new_station_dialog_new (RhythmDB *db)
250
RBNewStationDialog *dialog;
253
g_return_val_if_fail (RHYTHMDB_IS (db), NULL);
255
dialog = g_object_new (RB_TYPE_NEW_STATION_DIALOG, "db", db, NULL);
257
/* genrenames = rb_iradio_backend_get_genre_names (backend); */
259
if (genrenames != NULL) {
260
gtk_combo_set_popdown_strings (GTK_COMBO (dialog->priv->genre),
262
g_list_free (genrenames);
265
g_return_val_if_fail (dialog->priv != NULL, NULL);
267
return GTK_WIDGET (dialog);
271
rb_new_station_dialog_response_cb (GtkDialog *gtkdialog,
273
RBNewStationDialog *dialog)
275
const char *location;
276
GValue title_val = { 0, };
277
GValue genre_val = { 0, };
278
RhythmDBEntry *entry;
279
if (response_id != GTK_RESPONSE_OK)
282
location = gtk_entry_get_text (GTK_ENTRY (dialog->priv->location));
284
g_value_init (&title_val, G_TYPE_STRING);
285
g_value_set_string (&title_val, gtk_entry_get_text (GTK_ENTRY (dialog->priv->title)));
286
g_value_init (&genre_val, G_TYPE_STRING);
287
g_value_set_string (&genre_val,
288
gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (dialog->priv->genre)->entry)));
289
rhythmdb_write_lock (dialog->priv->db);
290
entry = rhythmdb_entry_lookup_by_location (dialog->priv->db, location);
292
entry = rhythmdb_entry_new (dialog->priv->db,
293
RHYTHMDB_ENTRY_TYPE_IRADIO_STATION,
295
rhythmdb_entry_set (dialog->priv->db, entry, RHYTHMDB_PROP_TITLE, &title_val);
296
rhythmdb_entry_set (dialog->priv->db, entry, RHYTHMDB_PROP_GENRE, &genre_val);
297
rhythmdb_write_unlock (dialog->priv->db);
298
g_value_unset (&title_val);
299
g_value_unset (&genre_val);
303
rb_new_station_dialog_entry_changed_cb (GtkEntry *entry,
304
RBNewStationDialog *dialog)
306
gtk_widget_set_sensitive (dialog->priv->okbutton,
307
g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (dialog->priv->title)), -1) > 0
308
&& g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (dialog->priv->genre)->entry)), -1) > 0
309
&& g_utf8_collate (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (dialog->priv->genre)->entry)), _("All"))
310
&& g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (dialog->priv->location)), -1) > 0);