~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to podcast/rb-new-podcast-dialog.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

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 podcast 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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-new-podcast-dialog.h"
 
34
#include "rb-glade-helpers.h"
 
35
#include "rb-dialog.h"
 
36
#include "rb-podcast-manager.h"
 
37
 
 
38
static void rb_new_podcast_dialog_class_init (RBNewPodcastDialogClass *klass);
 
39
static void rb_new_podcast_dialog_init (RBNewPodcastDialog *dialog);
 
40
static void rb_new_podcast_dialog_finalize (GObject *object);
 
41
static void rb_new_podcast_dialog_set_property (GObject *object,
 
42
                                                guint prop_id,
 
43
                                                const GValue *value,
 
44
                                                GParamSpec *pspec);
 
45
static void rb_new_podcast_dialog_get_property (GObject *object,
 
46
                                                guint prop_id,
 
47
                                                GValue *value,
 
48
                                                GParamSpec *pspec);
 
49
static void rb_new_podcast_dialog_response_cb (GtkDialog *gtkdialog,
 
50
                                               int response_id,
 
51
                                               RBNewPodcastDialog *dialog);
 
52
static void rb_new_podcast_dialog_text_changed (GtkEditable *buffer,
 
53
                                                RBNewPodcastDialog *dialog);
 
54
 
 
55
struct RBNewPodcastDialogPrivate
 
56
{
 
57
        RBPodcastManager    *pd;
 
58
 
 
59
        GtkWidget   *url;
 
60
        GtkWidget   *okbutton;
 
61
        GtkWidget   *cancelbutton;
 
62
};
 
63
 
 
64
enum 
 
65
{
 
66
        PROP_0,
 
67
        PROP_PODCAST_MANAGER
 
68
};
 
69
 
 
70
G_DEFINE_TYPE (RBNewPodcastDialog, rb_new_podcast_dialog, GTK_TYPE_DIALOG)
 
71
 
 
72
 
 
73
static void
 
74
rb_new_podcast_dialog_class_init (RBNewPodcastDialogClass *klass)
 
75
{
 
76
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
77
 
 
78
        object_class->set_property = rb_new_podcast_dialog_set_property;
 
79
        object_class->get_property = rb_new_podcast_dialog_get_property;
 
80
 
 
81
        g_object_class_install_property (object_class,
 
82
                                         PROP_PODCAST_MANAGER,
 
83
                                         g_param_spec_object ("podcast-manager",
 
84
                                                              "RBPodcastManager",
 
85
                                                              "RBPodcastManager object",
 
86
                                                              RB_TYPE_PODCAST_MANAGER,
 
87
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
88
 
 
89
        object_class->finalize = rb_new_podcast_dialog_finalize;
 
90
}
 
91
 
 
92
static void
 
93
rb_new_podcast_dialog_init (RBNewPodcastDialog *dialog)
 
94
{
 
95
        GladeXML *xml;
 
96
 
 
97
        /* create the dialog and some buttons forward - close */
 
98
        dialog->priv = g_new0 (RBNewPodcastDialogPrivate, 1);
 
99
 
 
100
 
 
101
        g_signal_connect_object (G_OBJECT (dialog),
 
102
                                 "response",
 
103
                                 G_CALLBACK (rb_new_podcast_dialog_response_cb),
 
104
                                 dialog, 0);
 
105
 
 
106
        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
 
107
        gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
 
108
        gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
 
109
 
 
110
        gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 
111
                                         GTK_RESPONSE_OK);
 
112
        gtk_window_set_title (GTK_WINDOW (dialog), _("New Podcast Feed"));
 
113
 
 
114
        dialog->priv->cancelbutton = gtk_dialog_add_button (GTK_DIALOG (dialog),
 
115
                                                            GTK_STOCK_CANCEL,
 
116
                                                            GTK_RESPONSE_CANCEL);
 
117
        dialog->priv->okbutton = gtk_dialog_add_button (GTK_DIALOG (dialog),
 
118
                                                        GTK_STOCK_ADD,
 
119
                                                        GTK_RESPONSE_OK);
 
120
        
 
121
        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
122
 
 
123
        xml = rb_glade_xml_new ("podcast-new.glade",
 
124
                                "newpodcast",
 
125
                                dialog);
 
126
        glade_xml_signal_autoconnect (xml);
 
127
 
 
128
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
 
129
                           glade_xml_get_widget (xml, "newpodcast"));
 
130
 
 
131
        
 
132
        /* get the widgets from the XML */
 
133
        dialog->priv->url = glade_xml_get_widget (xml, "txt_url");
 
134
 
 
135
        g_signal_connect_object (G_OBJECT (dialog->priv->url),
 
136
                                 "changed",
 
137
                                 G_CALLBACK (rb_new_podcast_dialog_text_changed),
 
138
                                 dialog, 0);
 
139
 
 
140
        /* default focus */
 
141
        gtk_widget_grab_focus (dialog->priv->url);
 
142
        
 
143
        /* FIXME */
 
144
        gtk_widget_set_sensitive (dialog->priv->okbutton, FALSE);
 
145
 
 
146
        g_object_unref (G_OBJECT (xml));
 
147
}
 
148
 
 
149
static void
 
150
rb_new_podcast_dialog_finalize (GObject *object)
 
151
{
 
152
        RBNewPodcastDialog *dialog;
 
153
 
 
154
        g_return_if_fail (object != NULL);
 
155
        g_return_if_fail (RB_IS_NEW_PODCAST_DIALOG (object));
 
156
 
 
157
        dialog = RB_NEW_PODCAST_DIALOG (object);
 
158
 
 
159
        g_return_if_fail (dialog->priv != NULL);
 
160
 
 
161
        g_free (dialog->priv);
 
162
 
 
163
        G_OBJECT_CLASS (rb_new_podcast_dialog_parent_class)->finalize (object);
 
164
}
 
165
 
 
166
static void
 
167
rb_new_podcast_dialog_set_property (GObject *object,
 
168
                                    guint prop_id,
 
169
                                    const GValue *value,
 
170
                                    GParamSpec *pspec)
 
171
{
 
172
        RBNewPodcastDialog *dialog = RB_NEW_PODCAST_DIALOG (object);
 
173
 
 
174
        switch (prop_id)
 
175
        {
 
176
        case PROP_PODCAST_MANAGER:
 
177
                dialog->priv->pd = g_value_get_object (value);
 
178
                break;
 
179
        default:
 
180
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
181
                break;
 
182
        }
 
183
}
 
184
 
 
185
static void
 
186
rb_new_podcast_dialog_get_property (GObject *object,
 
187
                                    guint prop_id,
 
188
                                    GValue *value,
 
189
                                    GParamSpec *pspec)
 
190
{
 
191
        RBNewPodcastDialog *dialog = RB_NEW_PODCAST_DIALOG (object);
 
192
 
 
193
        switch (prop_id)
 
194
        {
 
195
        case PROP_PODCAST_MANAGER:
 
196
                g_value_set_object (value, dialog->priv->pd);
 
197
                break;
 
198
        default:
 
199
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
200
                break;
 
201
        }
 
202
}
 
203
 
 
204
GtkWidget *
 
205
rb_new_podcast_dialog_new (RBPodcastManager *pd)
 
206
{
 
207
        RBNewPodcastDialog *dialog;
 
208
        
 
209
        g_return_val_if_fail (RB_PODCAST_MANAGER (pd), NULL);
 
210
        
 
211
        dialog = g_object_new (RB_TYPE_NEW_PODCAST_DIALOG, "podcast-manager", pd, NULL);
 
212
 
 
213
        g_return_val_if_fail (dialog->priv != NULL, NULL);
 
214
 
 
215
        return GTK_WIDGET (dialog);
 
216
}
 
217
 
 
218
static void
 
219
rb_new_podcast_dialog_response_cb (GtkDialog *gtkdialog,
 
220
                                   int response_id,
 
221
                                   RBNewPodcastDialog *dialog)
 
222
{
 
223
        gchar *valid_url;
 
224
        gchar *str;
 
225
 
 
226
        if (response_id != GTK_RESPONSE_OK)
 
227
                return;
 
228
 
 
229
        str = gtk_editable_get_chars (GTK_EDITABLE (dialog->priv->url), 0, -1);
 
230
 
 
231
        valid_url = g_strstrip (str);
 
232
 
 
233
        rb_podcast_manager_subscribe_feed (dialog->priv->pd, valid_url);
 
234
 
 
235
        gtk_widget_hide (GTK_WIDGET (gtkdialog));       
 
236
 
 
237
        g_free (str);
 
238
}
 
239
 
 
240
static void
 
241
rb_new_podcast_dialog_text_changed (GtkEditable *buffer,
 
242
                                    RBNewPodcastDialog *dialog)
 
243
{
 
244
        char *text = gtk_editable_get_chars (buffer, 0, -1);
 
245
        gboolean has_text = ((text != NULL) && (*text != 0));
 
246
 
 
247
        gtk_widget_set_sensitive (dialog->priv->okbutton, has_text);
 
248
        g_free (text);
 
249
}
 
250