1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * arch-tag: Implementation of new podcast 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-podcast-dialog.h"
34 #include "rb-glade-helpers.h"
35 #include "rb-dialog.h"
36 #include "rb-podcast-manager.h"
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
,
45 static void rb_new_podcast_dialog_get_property (GObject
*object
,
49 static void rb_new_podcast_dialog_response_cb (GtkDialog
*gtkdialog
,
51 RBNewPodcastDialog
*dialog
);
52 static void rb_new_podcast_dialog_text_changed (GtkEditable
*buffer
,
53 RBNewPodcastDialog
*dialog
);
55 struct RBNewPodcastDialogPrivate
61 GtkWidget
*cancelbutton
;
64 #define RB_NEW_PODCAST_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_NEW_PODCAST_DIALOG, RBNewPodcastDialogPrivate))
72 G_DEFINE_TYPE (RBNewPodcastDialog
, rb_new_podcast_dialog
, GTK_TYPE_DIALOG
)
75 rb_new_podcast_dialog_class_init (RBNewPodcastDialogClass
*klass
)
77 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
79 object_class
->set_property
= rb_new_podcast_dialog_set_property
;
80 object_class
->get_property
= rb_new_podcast_dialog_get_property
;
82 g_object_class_install_property (object_class
,
84 g_param_spec_object ("podcast-manager",
86 "RBPodcastManager object",
87 RB_TYPE_PODCAST_MANAGER
,
88 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
90 object_class
->finalize
= rb_new_podcast_dialog_finalize
;
92 g_type_class_add_private (klass
, sizeof (RBNewPodcastDialogPrivate
));
96 rb_new_podcast_dialog_init (RBNewPodcastDialog
*dialog
)
100 /* create the dialog and some buttons forward - close */
101 dialog
->priv
= RB_NEW_PODCAST_DIALOG_GET_PRIVATE (dialog
);
103 g_signal_connect_object (G_OBJECT (dialog
),
105 G_CALLBACK (rb_new_podcast_dialog_response_cb
),
108 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
109 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 5);
110 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog
)->vbox
), 2);
112 gtk_window_set_title (GTK_WINDOW (dialog
), _("New Podcast Feed"));
114 dialog
->priv
->cancelbutton
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
116 GTK_RESPONSE_CANCEL
);
117 dialog
->priv
->okbutton
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
120 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
);
122 xml
= rb_glade_xml_new ("podcast-new.glade",
126 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
),
127 glade_xml_get_widget (xml
, "newpodcast"));
129 /* get the widgets from the XML */
130 dialog
->priv
->url
= glade_xml_get_widget (xml
, "txt_url");
131 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->priv
->url
), TRUE
);
133 g_signal_connect_object (G_OBJECT (dialog
->priv
->url
),
135 G_CALLBACK (rb_new_podcast_dialog_text_changed
),
139 gtk_widget_grab_focus (dialog
->priv
->url
);
142 gtk_widget_set_sensitive (dialog
->priv
->okbutton
, FALSE
);
144 g_object_unref (G_OBJECT (xml
));
148 rb_new_podcast_dialog_finalize (GObject
*object
)
150 RBNewPodcastDialog
*dialog
;
152 g_return_if_fail (object
!= NULL
);
153 g_return_if_fail (RB_IS_NEW_PODCAST_DIALOG (object
));
155 dialog
= RB_NEW_PODCAST_DIALOG (object
);
157 g_return_if_fail (dialog
->priv
!= NULL
);
159 G_OBJECT_CLASS (rb_new_podcast_dialog_parent_class
)->finalize (object
);
163 rb_new_podcast_dialog_set_property (GObject
*object
,
168 RBNewPodcastDialog
*dialog
= RB_NEW_PODCAST_DIALOG (object
);
172 case PROP_PODCAST_MANAGER
:
173 dialog
->priv
->pd
= g_value_get_object (value
);
176 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
182 rb_new_podcast_dialog_get_property (GObject
*object
,
187 RBNewPodcastDialog
*dialog
= RB_NEW_PODCAST_DIALOG (object
);
191 case PROP_PODCAST_MANAGER
:
192 g_value_set_object (value
, dialog
->priv
->pd
);
195 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
201 rb_new_podcast_dialog_new (RBPodcastManager
*pd
)
203 RBNewPodcastDialog
*dialog
;
205 g_return_val_if_fail (RB_PODCAST_MANAGER (pd
), NULL
);
207 dialog
= g_object_new (RB_TYPE_NEW_PODCAST_DIALOG
, "podcast-manager", pd
, NULL
);
209 g_return_val_if_fail (dialog
->priv
!= NULL
, NULL
);
211 return GTK_WIDGET (dialog
);
215 rb_new_podcast_dialog_response_cb (GtkDialog
*gtkdialog
,
217 RBNewPodcastDialog
*dialog
)
222 if (response_id
!= GTK_RESPONSE_OK
)
225 str
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->priv
->url
), 0, -1);
227 valid_url
= g_strstrip (str
);
229 rb_podcast_manager_subscribe_feed (dialog
->priv
->pd
, valid_url
);
231 gtk_widget_hide (GTK_WIDGET (gtkdialog
));
237 rb_new_podcast_dialog_text_changed (GtkEditable
*buffer
,
238 RBNewPodcastDialog
*dialog
)
240 char *text
= gtk_editable_get_chars (buffer
, 0, -1);
241 gboolean has_text
= ((text
!= NULL
) && (*text
!= 0));
245 gtk_widget_set_sensitive (dialog
->priv
->okbutton
, has_text
);