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-uri-dialog.h"
34
#include "rb-glade-helpers.h"
35
#include "rb-dialog.h"
38
static void rb_uri_dialog_class_init (RBURIDialogClass *klass);
39
static void rb_uri_dialog_init (RBURIDialog *dialog);
40
static void rb_uri_dialog_finalize (GObject *object);
41
static void rb_uri_dialog_response_cb (GtkDialog *gtkdialog,
44
static void rb_uri_dialog_text_changed (GtkEditable *buffer,
47
struct RBURIDialogPrivate
52
GtkWidget *cancelbutton;
55
#define RB_URI_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_URI_DIALOG, RBURIDialogPrivate))
63
static guint rb_uri_dialog_signals [LAST_SIGNAL] = { 0 };
65
G_DEFINE_TYPE (RBURIDialog, rb_uri_dialog, GTK_TYPE_DIALOG)
68
rb_uri_dialog_class_init (RBURIDialogClass *klass)
70
GObjectClass *object_class = G_OBJECT_CLASS (klass);
72
object_class->finalize = rb_uri_dialog_finalize;
74
rb_uri_dialog_signals [LOCATION_ADDED] =
75
g_signal_new ("location-added",
76
G_OBJECT_CLASS_TYPE (object_class),
78
G_STRUCT_OFFSET (RBURIDialogClass, location_added),
80
g_cclosure_marshal_VOID__STRING,
85
g_type_class_add_private (klass, sizeof (RBURIDialogPrivate));
89
rb_uri_dialog_init (RBURIDialog *dialog)
93
/* create the dialog and some buttons forward - close */
94
dialog->priv = RB_URI_DIALOG_GET_PRIVATE (dialog);
96
g_signal_connect_object (G_OBJECT (dialog),
98
G_CALLBACK (rb_uri_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 ("uri-new.glade",
119
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
120
glade_xml_get_widget (xml, "newuri"));
122
/* get the widgets from the XML */
123
dialog->priv->label = glade_xml_get_widget (xml, "label");
124
dialog->priv->url = glade_xml_get_widget (xml, "txt_url");
125
gtk_entry_set_activates_default (GTK_ENTRY (dialog->priv->url), TRUE);
127
g_signal_connect_object (G_OBJECT (dialog->priv->url),
129
G_CALLBACK (rb_uri_dialog_text_changed),
133
gtk_widget_grab_focus (dialog->priv->url);
136
gtk_widget_set_sensitive (dialog->priv->okbutton, FALSE);
138
g_object_unref (G_OBJECT (xml));
142
rb_uri_dialog_finalize (GObject *object)
146
g_return_if_fail (object != NULL);
147
g_return_if_fail (RB_IS_URI_DIALOG (object));
149
dialog = RB_URI_DIALOG (object);
151
g_return_if_fail (dialog->priv != NULL);
153
G_OBJECT_CLASS (rb_uri_dialog_parent_class)->finalize (object);
157
rb_uri_dialog_new (const char *title, const char *label)
161
dialog = g_object_new (RB_TYPE_URI_DIALOG, NULL);
163
gtk_window_set_title (GTK_WINDOW (dialog), title);
164
gtk_label_set_text (GTK_LABEL (dialog->priv->label), label);
166
return GTK_WIDGET (dialog);
170
rb_uri_dialog_response_cb (GtkDialog *gtkdialog,
177
if (response_id != GTK_RESPONSE_OK)
180
str = gtk_editable_get_chars (GTK_EDITABLE (dialog->priv->url), 0, -1);
181
valid_url = g_strstrip (str);
183
g_signal_emit (dialog, rb_uri_dialog_signals [LOCATION_ADDED], 0, valid_url);
187
gtk_widget_hide (GTK_WIDGET (gtkdialog));
191
rb_uri_dialog_text_changed (GtkEditable *buffer,
194
char *text = gtk_editable_get_chars (buffer, 0, -1);
195
gboolean has_text = ((text != NULL) && (*text != 0));
199
gtk_widget_set_sensitive (dialog->priv->okbutton, has_text);