fix CID 1596595: Resource leaks, and CID 1596594: (CHECKED_RETURN)
[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-2019 the Claws Mail team
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                         _("_Cancel"), GTK_RESPONSE_REJECT,
51                         _("_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_widget_set_margin_start(GTK_WIDGET(titlelabel), 5);
67         gtk_widget_set_margin_end(GTK_WIDGET(titlelabel), 0);
68         gtk_frame_set_label_widget(GTK_FRAME(titleframe), titlelabel);
69
70         title = gtk_entry_new();
71         gtk_entry_set_text(GTK_ENTRY(title), feed_get_title(ctx->feed));
72         gtk_entry_set_activates_default(GTK_ENTRY(title), TRUE);
73         gtk_widget_set_tooltip_text(title,
74                         _("Instead of using official title, you can enter a different folder "
75                                 "name for the feed."));
76         gtk_container_add(GTK_CONTAINER(titleframe), title);
77
78         editprops = gtk_check_button_new_with_mnemonic(_("_Edit feed properties after subscribing"));
79         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(editprops), FALSE);
80         gtk_box_pack_start(GTK_BOX(vbox), editprops, FALSE, FALSE, 0);
81
82         gtk_widget_show_all(vbox);
83
84         ret = gtk_dialog_run(GTK_DIALOG(win));
85
86         if (ret == GTK_RESPONSE_ACCEPT) {
87                 /* Modify ctx->feed based on user changes in dialog */
88                 newtitle = (gchar *)gtk_entry_get_text(GTK_ENTRY(title));
89                 if (strcmp(feed_get_title(ctx->feed), newtitle)) {
90                         debug_print("RSSyl: Using user-supplied feed title '%s', instead of '%s'\n", newtitle, feed_get_title(ctx->feed));
91                         ctx->official_title = g_strdup(feed_get_title(ctx->feed));
92                         feed_set_title(ctx->feed, newtitle);
93                 }
94                 ctx->edit_properties =
95                         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(editprops));
96         } else {
97                 /* Destroy the feed to signal outside that user cancelled subscribing */
98                 feed_free(ctx->feed);
99                 ctx->feed = NULL;
100         }
101
102         gtk_widget_destroy(win);
103 }