New RSSyl replacing old one.
[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, *titleframe, *titlelabel;
40 #if !(GTK_CHECK_VERSION(2, 12, 0))
41         GtkTooltips *tooltips;
42 #endif
43         gint ret;
44         gchar *newtitle;
45
46         g_return_if_fail(ctx != NULL);
47         g_return_if_fail(ctx->feed != NULL);
48
49         /* Create window */
50         win = gtk_dialog_new_with_buttons(_("Subscribe new feed?"),
51                         GTK_WINDOW(mainwindow_get_mainwindow()->window),
52                         GTK_DIALOG_DESTROY_WITH_PARENT,
53                         GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
54                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
55                         NULL);
56         gtk_dialog_set_default_response(GTK_DIALOG(win), GTK_RESPONSE_ACCEPT);
57
58         vbox = gtk_dialog_get_content_area(GTK_DIALOG(win));
59
60 #if !(GTK_CHECK_VERSION(2, 12, 0))
61         tooltips = gtk_tooltips_new();
62         gtk_tooltips_enable(tooltips);
63 #endif
64
65         /* Feed title */
66         titleframe = gtk_frame_new(NULL);
67         gtk_container_set_border_width(GTK_CONTAINER(titleframe), 5);
68         gtk_frame_set_label_align(GTK_FRAME(titleframe), 0.05, 0.5);
69         gtk_frame_set_shadow_type(GTK_FRAME(titleframe), GTK_SHADOW_ETCHED_OUT);
70         gtk_box_pack_start(GTK_BOX(vbox), titleframe, FALSE, FALSE, 0);
71
72         titlelabel = gtk_label_new(_("<b>Feed folder:</b>"));
73         gtk_label_set_use_markup(GTK_LABEL(titlelabel), TRUE);
74         gtk_misc_set_padding(GTK_MISC(titlelabel), 5, 0);
75         gtk_frame_set_label_widget(GTK_FRAME(titleframe), titlelabel);
76
77         ctx->title = gtk_entry_new();
78         gtk_entry_set_text(GTK_ENTRY(ctx->title), feed_get_title(ctx->feed));
79         gtk_entry_set_activates_default(GTK_ENTRY(ctx->title), TRUE);
80 #if !(GTK_CHECK_VERSION(2, 12, 0))
81         gtk_tooltips_set_tip(tooltips, ctx->title,
82                         _("Instead of using official title, you can enter a different folder "
83                                 "name for the feed."), NULL);
84 #else
85         gtk_widget_set_tooltip_text(ctx->title,
86                         _("Instead of using official title, you can enter a different folder "
87                                 "name for the feed."));
88 #endif
89         gtk_container_add(GTK_CONTAINER(titleframe), ctx->title);
90
91         gtk_widget_show_all(vbox);
92
93         ret = gtk_dialog_run(GTK_DIALOG(win));
94
95         if (ret == GTK_RESPONSE_ACCEPT) {
96                 /* Modify ctx->feed based on user changes in dialog */
97                 newtitle = (gchar *)gtk_entry_get_text(GTK_ENTRY(ctx->title));
98                 if (strcmp(feed_get_title(ctx->feed), newtitle)) {
99                         debug_print("RSSyl: Using feed title '%s'\n", newtitle);
100                         feed_set_title(ctx->feed, newtitle);
101                 }
102         } else {
103                 /* Destroy the feed to signal outside that user cancelled subscribing */
104                 feed_free(ctx->feed);
105                 ctx->feed = NULL;
106         }
107
108         gtk_widget_destroy(win);
109 }