~snaggen/rhythmbox/bpm

« back to all changes in this revision

Viewing changes to widgets/rb-uri-dialog.c

  • Committer: Jonathan Matthew
  • Author(s): Jonathan Matthew
  • Date: 2007-01-07 12:16:12 UTC
  • Revision ID: git-v1:5b6958ea3cf24f2c8bcfa15b9cab1fc7798b7305
Moved lots of files around. Now everything should be in the directory it's

2007-01-07  Jonathan Matthew  <jonathan@kaolin.wh9.net>

        Moved lots of files around.  Now everything should be in the directory
        it's built in and all plugin-specific files should be installed into
        the plugin directory.

        * plugins/audioscrobbler/rb-audioscrobbler-plugin.c:
        (impl_create_configure_dialog):
        * plugins/audioscrobbler/rb-audioscrobbler.c:
        (rb_audioscrobbler_class_init), (rb_audioscrobbler_dispose),
        (rb_audioscrobbler_finalize),
        (rb_audioscrobbler_get_config_widget):
        * plugins/audioscrobbler/rb-audioscrobbler.h:
        Use rb_plugin_find_file where needed.

        * widgets/rb-uri-dialog.c: (rb_uri_dialog_class_init),
        (rb_uri_dialog_init), (rb_uri_dialog_finalize),
        (rb_uri_dialog_new), (rb_uri_dialog_response_cb),
        (rb_uri_dialog_text_changed):
        * widgets/rb-uri-dialog.h:
        New common 'enter a URI' dialog, used by iradio and podcast code.

        * plugins/iradio/rb-iradio-plugin.c: (impl_activate):
        * plugins/iradio/rb-iradio-source.c:
        (rb_iradio_source_constructor), (rb_iradio_source_new),
        (impl_song_properties), (rb_iradio_source_first_time_changed),
        (new_station_location_added), (rb_iradio_source_cmd_new_station):
        * plugins/iradio/rb-iradio-source.h:
        * plugins/iradio/rb-station-properties-dialog.c:
        (rb_station_properties_dialog_class_init),
        (rb_station_properties_dialog_init),
        (rb_station_properties_dialog_constructor),
        (rb_station_properties_dialog_set_property),
        (rb_station_properties_dialog_get_property),
        (rb_station_properties_dialog_new):
        * plugins/iradio/rb-station-properties-dialog.h:
        Use the common URI dialog, use rb_plugin_find_file where needed.

        * sources/rb-podcast-source.c:
        (rb_podcast_source_location_added_cb),
        (rb_podcast_source_cmd_new_podcast):
        Use the common URI dialog.

svn path=/trunk/; revision=4725

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 *
 
3
 *  arch-tag: Implementation of new station dialog
 
4
 *
 
5
 *  Copyright (C) 2005 Renato Araujo Oliveira Filho - INdT <renato.filho@indt.org.br>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 *
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <string.h>
 
26
#include <time.h>
 
27
 
 
28
#include <glib/gi18n.h>
 
29
#include <gtk/gtk.h>
 
30
#include <glade/glade.h>
 
31
#include <libgnomevfs/gnome-vfs.h>
 
32
 
 
33
#include "rb-uri-dialog.h"
 
34
#include "rb-glade-helpers.h"
 
35
#include "rb-dialog.h"
 
36
#include "rb-debug.h"
 
37
 
 
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,
 
42
                                       int response_id,
 
43
                                       RBURIDialog *dialog);
 
44
static void rb_uri_dialog_text_changed (GtkEditable *buffer,
 
45
                                        RBURIDialog *dialog);
 
46
 
 
47
struct RBURIDialogPrivate
 
48
{
 
49
        GtkWidget   *label;
 
50
        GtkWidget   *url;
 
51
        GtkWidget   *okbutton;
 
52
        GtkWidget   *cancelbutton;
 
53
};
 
54
 
 
55
#define RB_URI_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_URI_DIALOG, RBURIDialogPrivate))
 
56
 
 
57
enum
 
58
{
 
59
        LOCATION_ADDED,
 
60
        LAST_SIGNAL
 
61
};
 
62
 
 
63
static guint rb_uri_dialog_signals [LAST_SIGNAL] = { 0 };
 
64
 
 
65
G_DEFINE_TYPE (RBURIDialog, rb_uri_dialog, GTK_TYPE_DIALOG)
 
66
 
 
67
static void
 
68
rb_uri_dialog_class_init (RBURIDialogClass *klass)
 
69
{
 
70
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
71
 
 
72
        object_class->finalize = rb_uri_dialog_finalize;
 
73
 
 
74
        rb_uri_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 (RBURIDialogClass, location_added),
 
79
                              NULL, NULL,
 
80
                              g_cclosure_marshal_VOID__STRING,
 
81
                              G_TYPE_NONE,
 
82
                              1,
 
83
                              G_TYPE_STRING);
 
84
 
 
85
        g_type_class_add_private (klass, sizeof (RBURIDialogPrivate));
 
86
}
 
87
 
 
88
static void
 
89
rb_uri_dialog_init (RBURIDialog *dialog)
 
90
{
 
91
        GladeXML *xml;
 
92
 
 
93
        /* create the dialog and some buttons forward - close */
 
94
        dialog->priv = RB_URI_DIALOG_GET_PRIVATE (dialog);
 
95
 
 
96
        g_signal_connect_object (G_OBJECT (dialog),
 
97
                                 "response",
 
98
                                 G_CALLBACK (rb_uri_dialog_response_cb),
 
99
                                 dialog, 0);
 
100
 
 
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);
 
104
 
 
105
        /*gtk_window_set_title (GTK_WINDOW (dialog), _("New Internet Radio Station"));*/
 
106
 
 
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);
 
114
 
 
115
        xml = rb_glade_xml_new ("uri-new.glade",
 
116
                                "newuri",
 
117
                                dialog);
 
118
 
 
119
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
 
120
                           glade_xml_get_widget (xml, "newuri"));
 
121
 
 
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);
 
126
 
 
127
        g_signal_connect_object (G_OBJECT (dialog->priv->url),
 
128
                                 "changed",
 
129
                                 G_CALLBACK (rb_uri_dialog_text_changed),
 
130
                                 dialog, 0);
 
131
 
 
132
        /* default focus */
 
133
        gtk_widget_grab_focus (dialog->priv->url);
 
134
 
 
135
        /* FIXME */
 
136
        gtk_widget_set_sensitive (dialog->priv->okbutton, FALSE);
 
137
 
 
138
        g_object_unref (G_OBJECT (xml));
 
139
}
 
140
 
 
141
static void
 
142
rb_uri_dialog_finalize (GObject *object)
 
143
{
 
144
        RBURIDialog *dialog;
 
145
 
 
146
        g_return_if_fail (object != NULL);
 
147
        g_return_if_fail (RB_IS_URI_DIALOG (object));
 
148
 
 
149
        dialog = RB_URI_DIALOG (object);
 
150
 
 
151
        g_return_if_fail (dialog->priv != NULL);
 
152
 
 
153
        G_OBJECT_CLASS (rb_uri_dialog_parent_class)->finalize (object);
 
154
}
 
155
 
 
156
GtkWidget *
 
157
rb_uri_dialog_new (const char *title, const char *label)
 
158
{
 
159
        RBURIDialog *dialog;
 
160
 
 
161
        dialog = g_object_new (RB_TYPE_URI_DIALOG, NULL);
 
162
 
 
163
        gtk_window_set_title (GTK_WINDOW (dialog), title);
 
164
        gtk_label_set_text (GTK_LABEL (dialog->priv->label), label);
 
165
 
 
166
        return GTK_WIDGET (dialog);
 
167
}
 
168
 
 
169
static void
 
170
rb_uri_dialog_response_cb (GtkDialog *gtkdialog,
 
171
                                   int response_id,
 
172
                                   RBURIDialog *dialog)
 
173
{
 
174
        char *valid_url;
 
175
        char *str;
 
176
 
 
177
        if (response_id != GTK_RESPONSE_OK)
 
178
                return;
 
179
 
 
180
        str = gtk_editable_get_chars (GTK_EDITABLE (dialog->priv->url), 0, -1);
 
181
        valid_url = g_strstrip (str);
 
182
 
 
183
        g_signal_emit (dialog, rb_uri_dialog_signals [LOCATION_ADDED], 0, valid_url);
 
184
 
 
185
        g_free (str);
 
186
 
 
187
        gtk_widget_hide (GTK_WIDGET (gtkdialog));
 
188
}
 
189
 
 
190
static void
 
191
rb_uri_dialog_text_changed (GtkEditable *buffer,
 
192
                                    RBURIDialog *dialog)
 
193
{
 
194
        char *text = gtk_editable_get_chars (buffer, 0, -1);
 
195
        gboolean has_text = ((text != NULL) && (*text != 0));
 
196
 
 
197
        g_free (text);
 
198
 
 
199
        gtk_widget_set_sensitive (dialog->priv->okbutton, has_text);
 
200
}