1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * arch-tag: Implementation of new station dialog
5 * Copyright (C) 2005 Renato Araujo Oliveira Filho - INdT <renato.filho@indt.org.br>
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-new-station-dialog.h"
34 #include "rb-glade-helpers.h"
35 #include "rb-dialog.h"
36 #include "rb-entry-view.h"
39 static void rb_new_station_dialog_class_init (RBNewStationDialogClass
*klass
);
40 static void rb_new_station_dialog_init (RBNewStationDialog
*dialog
);
41 static void rb_new_station_dialog_finalize (GObject
*object
);
42 static void rb_new_station_dialog_response_cb (GtkDialog
*gtkdialog
,
44 RBNewStationDialog
*dialog
);
45 static void rb_new_station_dialog_text_changed (GtkEditable
*buffer
,
46 RBNewStationDialog
*dialog
);
48 struct RBNewStationDialogPrivate
52 GtkWidget
*cancelbutton
;
55 #define RB_NEW_STATION_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_NEW_STATION_DIALOG, RBNewStationDialogPrivate))
63 static guint rb_new_station_dialog_signals
[LAST_SIGNAL
] = { 0 };
65 G_DEFINE_TYPE (RBNewStationDialog
, rb_new_station_dialog
, GTK_TYPE_DIALOG
)
68 rb_new_station_dialog_class_init (RBNewStationDialogClass
*klass
)
70 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
72 object_class
->finalize
= rb_new_station_dialog_finalize
;
74 rb_new_station_dialog_signals
[LOCATION_ADDED
] =
75 g_signal_new ("location-added",
76 G_OBJECT_CLASS_TYPE (object_class
),
78 G_STRUCT_OFFSET (RBNewStationDialogClass
, location_added
),
80 g_cclosure_marshal_VOID__STRING
,
85 g_type_class_add_private (klass
, sizeof (RBNewStationDialogPrivate
));
89 rb_new_station_dialog_init (RBNewStationDialog
*dialog
)
93 /* create the dialog and some buttons forward - close */
94 dialog
->priv
= RB_NEW_STATION_DIALOG_GET_PRIVATE (dialog
);
96 g_signal_connect_object (G_OBJECT (dialog
),
98 G_CALLBACK (rb_new_station_dialog_response_cb
),
101 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
102 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 5);
103 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog
)->vbox
), 2);
105 gtk_window_set_title (GTK_WINDOW (dialog
), _("New Internet Radio Station"));
107 dialog
->priv
->cancelbutton
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
109 GTK_RESPONSE_CANCEL
);
110 dialog
->priv
->okbutton
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
113 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
);
115 xml
= rb_glade_xml_new ("station-new.glade",
119 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
),
120 glade_xml_get_widget (xml
, "newstation"));
122 /* get the widgets from the XML */
123 dialog
->priv
->url
= glade_xml_get_widget (xml
, "txt_url");
124 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->priv
->url
), TRUE
);
126 g_signal_connect_object (G_OBJECT (dialog
->priv
->url
),
128 G_CALLBACK (rb_new_station_dialog_text_changed
),
132 gtk_widget_grab_focus (dialog
->priv
->url
);
135 gtk_widget_set_sensitive (dialog
->priv
->okbutton
, FALSE
);
137 g_object_unref (G_OBJECT (xml
));
141 rb_new_station_dialog_finalize (GObject
*object
)
143 RBNewStationDialog
*dialog
;
145 g_return_if_fail (object
!= NULL
);
146 g_return_if_fail (RB_IS_NEW_STATION_DIALOG (object
));
148 dialog
= RB_NEW_STATION_DIALOG (object
);
150 g_return_if_fail (dialog
->priv
!= NULL
);
152 G_OBJECT_CLASS (rb_new_station_dialog_parent_class
)->finalize (object
);
156 rb_new_station_dialog_new (RBEntryView
*view
)
158 RBNewStationDialog
*dialog
;
160 dialog
= g_object_new (RB_TYPE_NEW_STATION_DIALOG
, NULL
);
162 return GTK_WIDGET (dialog
);
166 rb_new_station_dialog_create_station (RBNewStationDialog
*dialog
)
171 str
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->priv
->url
), 0, -1);
172 valid_url
= g_strstrip (str
);
174 g_signal_emit (dialog
, rb_new_station_dialog_signals
[LOCATION_ADDED
], 0, valid_url
);
180 rb_new_station_dialog_response_cb (GtkDialog
*gtkdialog
,
182 RBNewStationDialog
*dialog
)
185 if (response_id
!= GTK_RESPONSE_OK
)
188 rb_new_station_dialog_create_station (dialog
);
190 gtk_widget_hide (GTK_WIDGET (gtkdialog
));
194 rb_new_station_dialog_text_changed (GtkEditable
*buffer
,
195 RBNewStationDialog
*dialog
)
197 char *text
= gtk_editable_get_chars (buffer
, 0, -1);
198 gboolean has_text
= ((text
!= NULL
) && (*text
!= 0));
202 gtk_widget_set_sensitive (dialog
->priv
->okbutton
, has_text
);