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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
)
76 rb_new_podcast_dialog_class_init (RBNewPodcastDialogClass
*klass
)
78 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
80 object_class
->set_property
= rb_new_podcast_dialog_set_property
;
81 object_class
->get_property
= rb_new_podcast_dialog_get_property
;
83 g_object_class_install_property (object_class
,
85 g_param_spec_object ("podcast-manager",
87 "RBPodcastManager object",
88 RB_TYPE_PODCAST_MANAGER
,
89 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
91 object_class
->finalize
= rb_new_podcast_dialog_finalize
;
93 g_type_class_add_private (klass
, sizeof (RBNewPodcastDialogPrivate
));
97 rb_new_podcast_dialog_init (RBNewPodcastDialog
*dialog
)
101 /* create the dialog and some buttons forward - close */
102 dialog
->priv
= RB_NEW_PODCAST_DIALOG_GET_PRIVATE (dialog
);
104 g_signal_connect_object (G_OBJECT (dialog
),
106 G_CALLBACK (rb_new_podcast_dialog_response_cb
),
109 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
110 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 5);
111 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog
)->vbox
), 2);
113 gtk_window_set_title (GTK_WINDOW (dialog
), _("New Podcast Feed"));
115 dialog
->priv
->cancelbutton
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
117 GTK_RESPONSE_CANCEL
);
118 dialog
->priv
->okbutton
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
121 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_OK
);
123 xml
= rb_glade_xml_new ("podcast-new.glade",
127 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
),
128 glade_xml_get_widget (xml
, "newpodcast"));
131 /* get the widgets from the XML */
132 dialog
->priv
->url
= glade_xml_get_widget (xml
, "txt_url");
133 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->priv
->url
), TRUE
);
135 g_signal_connect_object (G_OBJECT (dialog
->priv
->url
),
137 G_CALLBACK (rb_new_podcast_dialog_text_changed
),
141 gtk_widget_grab_focus (dialog
->priv
->url
);
144 gtk_widget_set_sensitive (dialog
->priv
->okbutton
, FALSE
);
146 g_object_unref (G_OBJECT (xml
));
150 rb_new_podcast_dialog_finalize (GObject
*object
)
152 RBNewPodcastDialog
*dialog
;
154 g_return_if_fail (object
!= NULL
);
155 g_return_if_fail (RB_IS_NEW_PODCAST_DIALOG (object
));
157 dialog
= RB_NEW_PODCAST_DIALOG (object
);
159 g_return_if_fail (dialog
->priv
!= NULL
);
161 G_OBJECT_CLASS (rb_new_podcast_dialog_parent_class
)->finalize (object
);
165 rb_new_podcast_dialog_set_property (GObject
*object
,
170 RBNewPodcastDialog
*dialog
= RB_NEW_PODCAST_DIALOG (object
);
174 case PROP_PODCAST_MANAGER
:
175 dialog
->priv
->pd
= g_value_get_object (value
);
178 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
184 rb_new_podcast_dialog_get_property (GObject
*object
,
189 RBNewPodcastDialog
*dialog
= RB_NEW_PODCAST_DIALOG (object
);
193 case PROP_PODCAST_MANAGER
:
194 g_value_set_object (value
, dialog
->priv
->pd
);
197 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
203 rb_new_podcast_dialog_new (RBPodcastManager
*pd
)
205 RBNewPodcastDialog
*dialog
;
207 g_return_val_if_fail (RB_PODCAST_MANAGER (pd
), NULL
);
209 dialog
= g_object_new (RB_TYPE_NEW_PODCAST_DIALOG
, "podcast-manager", pd
, NULL
);
211 g_return_val_if_fail (dialog
->priv
!= NULL
, NULL
);
213 return GTK_WIDGET (dialog
);
217 rb_new_podcast_dialog_response_cb (GtkDialog
*gtkdialog
,
219 RBNewPodcastDialog
*dialog
)
224 if (response_id
!= GTK_RESPONSE_OK
)
227 str
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->priv
->url
), 0, -1);
229 valid_url
= g_strstrip (str
);
231 rb_podcast_manager_subscribe_feed (dialog
->priv
->pd
, valid_url
);
233 gtk_widget_hide (GTK_WIDGET (gtkdialog
));
239 rb_new_podcast_dialog_text_changed (GtkEditable
*buffer
,
240 RBNewPodcastDialog
*dialog
)
242 char *text
= gtk_editable_get_chars (buffer
, 0, -1);
243 gboolean has_text
= ((text
!= NULL
) && (*text
!= 0));
247 gtk_widget_set_sensitive (dialog
->priv
->okbutton
, has_text
);