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