udapted vi.po
[rhythmbox.git] / iradio / rb-new-station-dialog.c
blobb6457f0897efaaf27555978e77311699832cba38
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.
23 #include "config.h"
25 #include <string.h>
26 #include <time.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.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"
37 #include "rb-debug.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,
43 int response_id,
44 RBNewStationDialog *dialog);
45 static void rb_new_station_dialog_text_changed (GtkEditable *buffer,
46 RBNewStationDialog *dialog);
48 struct RBNewStationDialogPrivate
50 GtkWidget *url;
51 GtkWidget *okbutton;
52 GtkWidget *cancelbutton;
55 #define RB_NEW_STATION_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_NEW_STATION_DIALOG, RBNewStationDialogPrivate))
57 enum
59 LOCATION_ADDED,
60 LAST_SIGNAL
63 static guint rb_new_station_dialog_signals [LAST_SIGNAL] = { 0 };
65 G_DEFINE_TYPE (RBNewStationDialog, rb_new_station_dialog, GTK_TYPE_DIALOG)
67 static void
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),
77 G_SIGNAL_RUN_LAST,
78 G_STRUCT_OFFSET (RBNewStationDialogClass, location_added),
79 NULL, NULL,
80 g_cclosure_marshal_VOID__STRING,
81 G_TYPE_NONE,
83 G_TYPE_STRING);
85 g_type_class_add_private (klass, sizeof (RBNewStationDialogPrivate));
88 static void
89 rb_new_station_dialog_init (RBNewStationDialog *dialog)
91 GladeXML *xml;
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),
97 "response",
98 G_CALLBACK (rb_new_station_dialog_response_cb),
99 dialog, 0);
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),
108 GTK_STOCK_CANCEL,
109 GTK_RESPONSE_CANCEL);
110 dialog->priv->okbutton = gtk_dialog_add_button (GTK_DIALOG (dialog),
111 GTK_STOCK_ADD,
112 GTK_RESPONSE_OK);
113 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
115 xml = rb_glade_xml_new ("station-new.glade",
116 "newstation",
117 dialog);
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),
127 "changed",
128 G_CALLBACK (rb_new_station_dialog_text_changed),
129 dialog, 0);
131 /* default focus */
132 gtk_widget_grab_focus (dialog->priv->url);
134 /* FIXME */
135 gtk_widget_set_sensitive (dialog->priv->okbutton, FALSE);
137 g_object_unref (G_OBJECT (xml));
140 static void
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);
155 GtkWidget *
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);
165 static void
166 rb_new_station_dialog_create_station (RBNewStationDialog *dialog)
168 char *valid_url;
169 char *str;
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);
176 g_free (str);
179 static void
180 rb_new_station_dialog_response_cb (GtkDialog *gtkdialog,
181 int response_id,
182 RBNewStationDialog *dialog)
185 if (response_id != GTK_RESPONSE_OK)
186 return;
188 rb_new_station_dialog_create_station (dialog);
190 gtk_widget_hide (GTK_WIDGET (gtkdialog));
193 static void
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));
200 g_free (text);
202 gtk_widget_set_sensitive (dialog->priv->okbutton, has_text);