add .cvsignore files
[claws.git] / src / plugins / rssyl / rssyl_cb_gtk.c
1 /*
2  * Sylpheed -- 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  * - callback handler functions for GTK signals and timeouts
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 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29
30 #include "folderview.h"
31 #include "alertpanel.h"
32 #include "gtk/inputdialog.h"
33
34 #include "date.h"
35 #include "feed.h"
36 #include "rssyl.h"
37 #include "rssyl_gtk.h"
38 #include "rssyl_cb_gtk.h"
39 #include "prefs_common.h"
40
41 gboolean rssyl_props_cancel_cb(GtkWidget *widget, gpointer data)
42 {
43         RSSylFolderItem *ritem = (RSSylFolderItem *)data;
44
45         debug_print("RSSyl: Cancel pressed\n");
46         gtk_widget_destroy(ritem->feedprop->window);
47         return FALSE;
48 }
49
50 gboolean rssyl_props_ok_cb(GtkWidget *widget, gpointer data)
51 {
52         RSSylFolderItem *ritem = (RSSylFolderItem *)data;
53
54         debug_print("RSSyl: OK pressed\n");
55         rssyl_gtk_prop_store(ritem);
56
57         gtk_widget_destroy(ritem->feedprop->window);
58
59         return FALSE;
60 }
61
62 gboolean rssyl_refresh_timeout_cb(gpointer data)
63 {
64         RSSylRefreshCtx *ctx = (RSSylRefreshCtx *)data;
65         time_t tt = time(NULL);
66         gchar *tmpdate;
67
68         g_return_val_if_fail(ctx != NULL, FALSE);
69
70         if( prefs_common_get_prefs()->work_offline)
71                 return TRUE;
72
73         if( ctx->ritem == NULL || ctx->ritem->url == NULL ) {
74                 debug_print("RSSyl: refresh_timeout_cb - ritem or url NULL\n");
75                 g_free(ctx);
76                 return FALSE;
77         }
78
79         if( ctx->id != ctx->ritem->refresh_id ) {
80                 tmpdate = createRFC822Date(&tt);
81                 debug_print(" %s: timeout id changed, stopping: %d != %d\n",
82                                 tmpdate, ctx->id, ctx->ritem->refresh_id);
83                 g_free(tmpdate);
84                 g_free(ctx);
85                 return FALSE;
86         }
87
88         tmpdate = createRFC822Date(&tt);
89         debug_print(" %s: refresh %s (%d)\n", tmpdate, ctx->ritem->url,
90                         ctx->ritem->refresh_id);
91         g_free(tmpdate);
92         rssyl_update_feed(ctx->ritem);
93
94         return TRUE;
95 }
96
97 gboolean rssyl_default_refresh_interval_toggled_cb(GtkToggleButton *default_ri,
98                 gpointer data)
99 {
100         gboolean active = gtk_toggle_button_get_active(default_ri);
101         GtkWidget *refresh_interval = (GtkWidget *)data;
102
103         debug_print("default is %s\n", ( active ? "ON" : "OFF" ) );
104
105         gtk_widget_set_sensitive(refresh_interval, !active);
106
107         return FALSE;
108 }
109
110 gboolean rssyl_default_expired_num_toggled_cb(GtkToggleButton *default_ex,
111                 gpointer data)
112 {
113         gboolean active = gtk_toggle_button_get_active(default_ex);
114         GtkWidget *expired_num = (GtkWidget *)data;
115
116         debug_print("default is %s\n", ( active ? "ON" : "OFF" ) );
117
118         gtk_widget_set_sensitive(expired_num, !active);
119
120         return FALSE;
121 }
122
123 gboolean rssyl_fetch_comments_toggled_cb(GtkToggleButton *fetch_comments,
124                 gpointer data)
125 {
126         gboolean active = gtk_toggle_button_get_active(fetch_comments);
127         GtkWidget *num_comments = (GtkWidget *)data;
128
129         debug_print("fetch comments is %s\n", (active ? "ON" : "OFF") );
130
131         gtk_widget_set_sensitive(num_comments, active);
132
133         return FALSE;
134 }
135
136 gboolean rssyl_props_key_press_cb(GtkWidget *widget, GdkEventKey *event,
137                 gpointer data)
138 {
139         if (event) {
140                 switch (event->keyval) {
141                         case GDK_Escape:
142                                 rssyl_props_cancel_cb(widget, data);
143                                 return TRUE;
144                         case GDK_Return:
145                         case GDK_KP_Enter:
146                                 rssyl_props_ok_cb(widget, data);
147                                 return TRUE;
148                         default:
149                                 break;
150                 }
151         }
152
153         return FALSE;
154 }