Add a plugin method to allow updating stored passwords on master password change.
[claws.git] / src / plugins / rssyl / rssyl_subscribe_gtk.c
1 /*
2  * Claws-Mail-- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2004 Hiroyuki Yamamoto
4  * This file (C) 2005 Andrej Kacian <andrej@kacian.sk>
5  *
6  * - Dialog which appears when manually subscribing a new feed.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 /* Global includes */
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30
31 /* Claws Mail includes */
32 #include <mainwindow.h>
33
34 /* Local includes */
35 #include "libfeed/feed.h"
36 #include "rssyl_subscribe_gtk.h"
37
38 void rssyl_subscribe_dialog(RSubCtx *ctx) {
39         GtkWidget *win, *vbox, *title, *titleframe, *titlelabel, *editprops;
40         gint ret;
41         gchar *newtitle;
42
43         g_return_if_fail(ctx != NULL);
44         g_return_if_fail(ctx->feed != NULL);
45
46         /* Create window */
47         win = gtk_dialog_new_with_buttons(_("Subscribe new feed?"),
48                         GTK_WINDOW(mainwindow_get_mainwindow()->window),
49                         GTK_DIALOG_DESTROY_WITH_PARENT,
50                         GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
51                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
52                         NULL);
53         gtk_dialog_set_default_response(GTK_DIALOG(win), GTK_RESPONSE_ACCEPT);
54
55         vbox = gtk_dialog_get_content_area(GTK_DIALOG(win));
56
57         /* Feed title */
58         titleframe = gtk_frame_new(NULL);
59         gtk_container_set_border_width(GTK_CONTAINER(titleframe), 5);
60         gtk_frame_set_label_align(GTK_FRAME(titleframe), 0.05, 0.5);
61         gtk_frame_set_shadow_type(GTK_FRAME(titleframe), GTK_SHADOW_ETCHED_OUT);
62         gtk_box_pack_start(GTK_BOX(vbox), titleframe, FALSE, FALSE, 0);
63
64         titlelabel = gtk_label_new(g_strconcat("<b>",_("Feed folder:"),"</b>", NULL));
65         gtk_label_set_use_markup(GTK_LABEL(titlelabel), TRUE);
66         gtk_misc_set_padding(GTK_MISC(titlelabel), 5, 0);
67         gtk_frame_set_label_widget(GTK_FRAME(titleframe), titlelabel);
68
69         title = gtk_entry_new();
70         gtk_entry_set_text(GTK_ENTRY(title), feed_get_title(ctx->feed));
71         gtk_entry_set_activates_default(GTK_ENTRY(title), TRUE);
72         gtk_widget_set_tooltip_text(title,
73                         _("Instead of using official title, you can enter a different folder "
74                                 "name for the feed."));
75         gtk_container_add(GTK_CONTAINER(titleframe), title);
76
77         editprops = gtk_check_button_new_with_mnemonic(_("_Edit feed properties after subscribing"));
78         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(editprops), FALSE);
79         gtk_box_pack_start(GTK_BOX(vbox), editprops, FALSE, FALSE, 0);
80
81         gtk_widget_show_all(vbox);
82
83         ret = gtk_dialog_run(GTK_DIALOG(win));
84
85         if (ret == GTK_RESPONSE_ACCEPT) {
86                 /* Modify ctx->feed based on user changes in dialog */
87                 newtitle = (gchar *)gtk_entry_get_text(GTK_ENTRY(title));
88                 if (strcmp(feed_get_title(ctx->feed), newtitle)) {
89                         debug_print("RSSyl: Using user-supplied feed title '%s', instead of '%s'\n", newtitle, feed_get_title(ctx->feed));
90                         ctx->official_title = g_strdup(feed_get_title(ctx->feed));
91                         feed_set_title(ctx->feed, newtitle);
92                 }
93                 ctx->edit_properties =
94                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(editprops));
95         } else {
96                 /* Destroy the feed to signal outside that user cancelled subscribing */
97                 feed_free(ctx->feed);
98                 ctx->feed = NULL;
99         }
100
101         gtk_widget_destroy(win);
102 }