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>
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.
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.
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.
29 #include <glib/gi18n.h>
30 #include <gdk/gdkkeysyms.h>
32 /* Claws Mail includes */
33 #include <mainwindow.h>
34 #include <prefs_gtk.h>
38 #include "rssyl_feed.h"
39 #include "rssyl_feed_props.h"
40 #include "rssyl_prefs.h"
41 #include "rssyl_update_feed.h"
43 static void rssyl_gtk_prop_store(RFolderItem *ritem)
45 gchar *url, *auth_user, *auth_pass;
46 gint x, old_ri, old_fetch_comments;
47 gboolean use_default_ri = FALSE, keep_old = FALSE;
50 g_return_if_fail(ritem != NULL);
51 g_return_if_fail(ritem->feedprop != NULL);
53 url = (gchar *)gtk_entry_get_text(GTK_ENTRY(ritem->feedprop->url));
55 if( strlen(url) && strcmp(ritem->url, url)) {
57 rssyl_passwd_set(ritem, NULL);
60 ritem->url = g_strdup(url);
63 ritem->auth->type = gtk_combo_box_get_active(GTK_COMBO_BOX(ritem->feedprop->auth_type));
65 auth_user = (gchar *)gtk_entry_get_text(GTK_ENTRY(ritem->feedprop->auth_username));
66 if (auth_user != NULL) {
67 if (ritem->auth->username) {
68 g_free(ritem->auth->username);
70 ritem->auth->username = g_strdup(auth_user);
73 auth_pass = (gchar *)gtk_entry_get_text(GTK_ENTRY(ritem->feedprop->auth_password));
74 rssyl_passwd_set(ritem, auth_pass);
76 use_default_ri = gtk_toggle_button_get_active(
77 GTK_TOGGLE_BUTTON(ritem->feedprop->default_refresh_interval));
78 ritem->default_refresh_interval = use_default_ri;
79 debug_print("store: default refresh interval is %s\n",
80 ( use_default_ri ? "ON" : "OFF" ) );
82 /* Use default if checkbutton is set */
84 x = rssyl_prefs_get()->refresh;
86 x = gtk_spin_button_get_value_as_int(
87 GTK_SPIN_BUTTON(ritem->feedprop->refresh_interval) );
89 old_ri = ritem->refresh_interval;
90 ritem->refresh_interval = x;
92 /* Set timer for next automatic refresh, if needed. */
94 if( old_ri != x || ritem->refresh_id == 0 ) {
95 debug_print("RSSyl: GTK - refresh interval changed to %d , updating "
96 "timeout\n", ritem->refresh_interval);
97 rssyl_feed_start_refresh_timeout(ritem);
100 ritem->refresh_id = 0;
102 old_fetch_comments = ritem->fetch_comments;
103 ritem->fetch_comments = gtk_toggle_button_get_active(
104 GTK_TOGGLE_BUTTON(ritem->feedprop->fetch_comments));
106 if (!old_fetch_comments && ritem->fetch_comments) {
107 /* reset the RFolderItem's mtime to be sure we get all
108 * available comments */
109 ritem->item.mtime = 0;
112 ritem->fetch_comments_max_age = gtk_spin_button_get_value_as_int(
113 GTK_SPIN_BUTTON(ritem->feedprop->fetch_comments_max_age));
115 keep_old = gtk_toggle_button_get_active(
116 GTK_TOGGLE_BUTTON(ritem->feedprop->keep_old));
117 ritem->keep_old = keep_old;
119 ritem->silent_update =
120 gtk_combo_box_get_active(GTK_COMBO_BOX(ritem->feedprop->silent_update));
122 ritem->write_heading = gtk_toggle_button_get_active(
123 GTK_TOGGLE_BUTTON(ritem->feedprop->write_heading));
125 ritem->ignore_title_rename = gtk_toggle_button_get_active(
126 GTK_TOGGLE_BUTTON(ritem->feedprop->ignore_title_rename));
128 ritem->ssl_verify_peer = gtk_toggle_button_get_active(
129 GTK_TOGGLE_BUTTON(ritem->feedprop->ssl_verify_peer));
131 /* Store updated properties */
133 item->folder->klass->item_get_xml(item->folder, item);
137 rssyl_feedprop_togglebutton_toggled_cb(GtkToggleButton *tb,
140 gboolean active = gtk_toggle_button_get_active(tb);
141 RFeedProp *feedprop = (RFeedProp *)data;
142 GtkWidget *sb = NULL;
144 if( (GtkWidget *)tb == feedprop->default_refresh_interval ) {
146 sb = feedprop->refresh_interval;
147 } else if( (GtkWidget *)tb == feedprop->fetch_comments ) {
148 sb = feedprop->fetch_comments_max_age;
151 g_return_val_if_fail(sb != NULL, FALSE);
153 gtk_widget_set_sensitive(sb, active);
159 rssyl_feedprop_auth_type_changed_cb(GtkComboBox *cb, gpointer data)
161 RFeedProp *feedprop = (RFeedProp *)data;
162 gboolean enable = (FEED_AUTH_NONE != gtk_combo_box_get_active(cb));
163 gtk_widget_set_sensitive(GTK_WIDGET(feedprop->auth_username), enable);
164 gtk_widget_set_sensitive(GTK_WIDGET(feedprop->auth_password), enable);
168 rssyl_props_cancel_cb(GtkWidget *widget, gpointer data)
170 RFolderItem *ritem = (RFolderItem *)data;
172 debug_print("RSSyl: Cancel pressed\n");
174 gtk_widget_destroy(ritem->feedprop->window);
180 rssyl_props_ok_cb(GtkWidget *widget, gpointer data)
182 RFolderItem *ritem = (RFolderItem *)data;
184 debug_print("RSSyl: OK pressed\n");
185 rssyl_gtk_prop_store(ritem);
187 gtk_widget_destroy(ritem->feedprop->window);
193 rssyl_props_trim_cb(GtkWidget *widget, gpointer data)
195 RFolderItem *ritem = (RFolderItem *)data;
196 gboolean k = ritem->keep_old;
199 ritem->keep_old = FALSE;
201 rssyl_update_feed(ritem, FALSE);
204 ritem->keep_old = TRUE;
210 rssyl_props_key_press_cb(GtkWidget *widget, GdkEventKey *event,
214 switch (event->keyval) {
216 rssyl_props_cancel_cb(widget, data);
220 rssyl_props_ok_cb(widget, data);
230 void rssyl_gtk_prop(RFolderItem *ritem)
232 MainWindow *mainwin = mainwindow_get_mainwindow();
234 GtkWidget *vbox, *frame, *label, *hbox,
235 *inner_vbox, *auth_hbox, *auth_user_label, *auth_pass_label,
236 *bbox, *cancel_button, *cancel_align,
237 *cancel_hbox, *cancel_image, *cancel_label, *ok_button, *ok_align,
238 *ok_hbox, *ok_image, *ok_label, *trim_button, *silent_update_label;
242 g_return_if_fail(ritem != NULL);
244 feedprop = g_new0(RFeedProp, 1);
246 /**** Create required widgets ****/
249 feedprop->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
252 feedprop->url = gtk_entry_new();
253 gtk_entry_set_text(GTK_ENTRY(feedprop->url), ritem->url);
255 /* URL auth type combo */
256 #if !GTK_CHECK_VERSION(2, 24, 0)
257 feedprop->auth_type = gtk_combo_box_new_text();
258 gtk_combo_box_append_text(GTK_COMBO_BOX(feedprop->auth_type),
260 feedprop->auth_type = gtk_combo_box_text_new();
261 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(feedprop->auth_type),
263 _("No authentication"));
264 #if !GTK_CHECK_VERSION(2, 24, 0)
265 gtk_combo_box_append_text(GTK_COMBO_BOX(feedprop->auth_type),
267 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(feedprop->auth_type),
269 _("HTTP Basic authentication"));
270 gtk_combo_box_set_active(GTK_COMBO_BOX(feedprop->auth_type),
274 feedprop->auth_username = gtk_entry_new();
275 gtk_entry_set_text(GTK_ENTRY(feedprop->auth_username),
276 ritem->auth->username);
279 feedprop->auth_password = gtk_entry_new();
280 gtk_entry_set_visibility(GTK_ENTRY(feedprop->auth_password), FALSE);
281 gchar *pwd = rssyl_passwd_get(ritem);
282 gtk_entry_set_text(GTK_ENTRY(feedprop->auth_password), pwd);
284 memset(pwd, 0, strlen(pwd));
288 /* "Use default refresh interval" checkbutton */
289 feedprop->default_refresh_interval = gtk_check_button_new_with_mnemonic(
290 _("Use default refresh interval"));
291 gtk_toggle_button_set_active(
292 GTK_TOGGLE_BUTTON(feedprop->default_refresh_interval),
293 ritem->default_refresh_interval);
295 if( ritem->refresh_interval >= 0 && !ritem->default_refresh_interval )
296 refresh = ritem->refresh_interval;
298 refresh = rssyl_prefs_get()->refresh;
300 /* "Keep old items" checkbutton */
301 feedprop->keep_old = gtk_check_button_new_with_mnemonic(
302 _("Keep old items"));
303 gtk_toggle_button_set_active(
304 GTK_TOGGLE_BUTTON(feedprop->keep_old),
308 trim_button = gtk_button_new_with_mnemonic(_("_Trim"));
309 gtk_widget_set_tooltip_text(trim_button,
310 _("Update feed, deleting items which are no longer in the source feed"));
312 feedprop->fetch_comments = gtk_check_button_new_with_mnemonic(
313 _("Fetch comments if possible"));
314 gtk_toggle_button_set_active(
315 GTK_TOGGLE_BUTTON(feedprop->fetch_comments),
316 ritem->fetch_comments);
318 /* Fetch comments max age spinbutton */
319 adj = gtk_adjustment_new(ritem->fetch_comments_max_age,
320 -1, 100000, 1, 10, 0);
321 feedprop->fetch_comments_max_age = gtk_spin_button_new(GTK_ADJUSTMENT(adj),
324 /* Refresh interval spinbutton */
325 adj = gtk_adjustment_new(refresh,
326 0, 100000, 10, 100, 0);
327 feedprop->refresh_interval = gtk_spin_button_new(GTK_ADJUSTMENT(adj),
330 /* Silent update - combobox */
331 #if !GTK_CHECK_VERSION(2, 24, 0)
332 feedprop->silent_update = gtk_combo_box_new_text();
333 gtk_combo_box_append_text(GTK_COMBO_BOX(feedprop->silent_update),
335 feedprop->silent_update = gtk_combo_box_text_new();
336 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(feedprop->silent_update),
338 _("Always mark it as new"));
339 #if !GTK_CHECK_VERSION(2, 24, 0)
340 gtk_combo_box_append_text(GTK_COMBO_BOX(feedprop->silent_update),
342 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(feedprop->silent_update),
344 _("Only mark it as new if its text has changed"));
345 #if !GTK_CHECK_VERSION(2, 24, 0)
346 gtk_combo_box_append_text(GTK_COMBO_BOX(feedprop->silent_update),
348 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(feedprop->silent_update),
350 _("Never mark it as new"));
351 gtk_combo_box_set_active(GTK_COMBO_BOX(feedprop->silent_update),
352 ritem->silent_update);
354 feedprop->write_heading = gtk_check_button_new_with_mnemonic(
355 _("Add item title to the top of message"));
356 gtk_toggle_button_set_active(
357 GTK_TOGGLE_BUTTON(feedprop->write_heading),
358 ritem->write_heading);
360 /* Ignore title rename - checkbox */
361 feedprop->ignore_title_rename = gtk_check_button_new_with_mnemonic(
362 _("Ignore title rename"));
363 gtk_toggle_button_set_active(
364 GTK_TOGGLE_BUTTON(feedprop->ignore_title_rename),
365 ritem->ignore_title_rename);
366 gtk_widget_set_tooltip_text(feedprop->ignore_title_rename,
367 _("Enable this to keep current folder name, even if feed author changes title of the feed."));
369 /* Verify SSL peer certificate */
370 feedprop->ssl_verify_peer = gtk_check_button_new_with_label(
371 _("Verify SSL certificate validity"));
372 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(feedprop->ssl_verify_peer),
373 ritem->ssl_verify_peer);
375 /* === Now pack all the widgets */
376 vbox = gtk_vbox_new(FALSE, 5);
377 gtk_container_add(GTK_CONTAINER(feedprop->window), vbox);
378 gtk_container_set_border_width(GTK_CONTAINER(feedprop->window), 10);
380 inner_vbox = gtk_vbox_new(FALSE, 7);
381 gtk_box_pack_start(GTK_BOX(inner_vbox), feedprop->url, FALSE, FALSE, 0);
382 gtk_entry_set_activates_default(GTK_ENTRY(feedprop->url), TRUE);
384 /* Auth combo + user (label + entry) + pass (label + entry) */
385 auth_hbox = gtk_hbox_new(FALSE, 7);
386 gtk_box_pack_start(GTK_BOX(auth_hbox), feedprop->auth_type, FALSE, FALSE, 0);
387 g_signal_connect(G_OBJECT(feedprop->auth_type), "changed",
388 G_CALLBACK(rssyl_feedprop_auth_type_changed_cb),
389 (gpointer) feedprop);
390 g_signal_emit_by_name(G_OBJECT(feedprop->auth_type), "changed");
391 auth_user_label = gtk_label_new(_("User name"));
392 gtk_box_pack_start(GTK_BOX(auth_hbox), auth_user_label, FALSE, FALSE, 0);
393 gtk_box_pack_start(GTK_BOX(auth_hbox), feedprop->auth_username, FALSE, FALSE, 0);
394 auth_pass_label = gtk_label_new(_("Password"));
395 gtk_box_pack_start(GTK_BOX(auth_hbox), auth_pass_label, FALSE, FALSE, 0);
396 gtk_box_pack_start(GTK_BOX(auth_hbox), feedprop->auth_password, FALSE, FALSE, 0);
397 gtk_box_pack_start(GTK_BOX(inner_vbox), auth_hbox, FALSE, FALSE, 0);
399 /* Verify SSL peer certificate - checkbutton */
400 gtk_box_pack_start(GTK_BOX(inner_vbox), feedprop->ssl_verify_peer, FALSE, FALSE, 0);
401 /* Ignore title rename - checkbutton */
402 gtk_box_pack_start(GTK_BOX(inner_vbox), feedprop->ignore_title_rename, FALSE, FALSE, 0);
404 PACK_FRAME (vbox, frame, _("Source URL"));
405 gtk_container_set_border_width(GTK_CONTAINER(inner_vbox), 7);
406 gtk_container_add(GTK_CONTAINER(frame), inner_vbox);
408 inner_vbox = gtk_vbox_new(FALSE, 7);
409 /* Fetch comments - checkbutton */
410 g_signal_connect(G_OBJECT(feedprop->fetch_comments), "toggled",
411 G_CALLBACK(rssyl_feedprop_togglebutton_toggled_cb),
413 gtk_box_pack_start(GTK_BOX(inner_vbox), feedprop->fetch_comments, FALSE, FALSE, 0);
415 hbox = gtk_hbox_new(FALSE, 7);
416 /* Fetch comments max age - label */
417 label = gtk_label_new(_("Fetch comments on posts aged less than"));
418 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
419 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
420 /* Fetch comments max age - spinbutton */
421 gtk_widget_set_sensitive(feedprop->fetch_comments_max_age,
422 ritem->fetch_comments);
423 gtk_box_pack_start(GTK_BOX(hbox), feedprop->fetch_comments_max_age, FALSE, FALSE, 0);
424 /* Fetch comments max age - units label */
425 label = gtk_label_new(g_strconcat(_("day(s)"), "<small> ",
426 _("Set to -1 to fetch all comments"), "</small>", NULL));
427 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
428 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
429 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
430 gtk_box_pack_start(GTK_BOX(inner_vbox), hbox, FALSE, FALSE, 0);
432 PACK_FRAME (vbox, frame, _("Comments"));
433 gtk_container_set_border_width(GTK_CONTAINER(inner_vbox), 7);
434 gtk_container_add(GTK_CONTAINER(frame), inner_vbox);
436 inner_vbox = gtk_vbox_new(FALSE, 7);
437 hbox = gtk_hbox_new(FALSE, 7);
438 /* Write heading - checkbox */
439 gtk_box_pack_start(GTK_BOX(inner_vbox), feedprop->write_heading, FALSE, FALSE, 0);
440 /* Keep old items - checkbutton */
441 gtk_box_pack_start(GTK_BOX(hbox), feedprop->keep_old, FALSE, FALSE, 0);
442 /* 'Trim' - button */
443 gtk_box_pack_start(GTK_BOX(hbox), trim_button, FALSE, FALSE, 0);
444 g_signal_connect(G_OBJECT(trim_button), "clicked",
445 G_CALLBACK(rssyl_props_trim_cb), ritem);
446 gtk_box_pack_start(GTK_BOX(inner_vbox), hbox, FALSE, FALSE, 0);
448 hbox = gtk_hbox_new(FALSE, 7);
449 /* Silent update - label */
450 silent_update_label = gtk_label_new(_("If an item changes"));
451 gtk_box_pack_start(GTK_BOX(hbox), silent_update_label, FALSE, FALSE, 0);
452 gtk_box_pack_start(GTK_BOX(hbox), feedprop->silent_update, FALSE, FALSE, 0);
453 gtk_box_pack_start(GTK_BOX(inner_vbox), hbox, FALSE, FALSE, 0);
455 PACK_FRAME (vbox, frame, _("Items"));
456 gtk_container_set_border_width(GTK_CONTAINER(inner_vbox), 7);
457 gtk_container_add(GTK_CONTAINER(frame), inner_vbox);
459 inner_vbox = gtk_vbox_new(FALSE, 7);
460 /* Use default refresh interval - checkbutton */
461 gtk_box_pack_start(GTK_BOX(inner_vbox), feedprop->default_refresh_interval, FALSE, FALSE, 0);
462 g_signal_connect(G_OBJECT(feedprop->default_refresh_interval), "toggled",
463 G_CALLBACK(rssyl_feedprop_togglebutton_toggled_cb),
466 hbox = gtk_hbox_new(FALSE, 7);
467 /* Refresh interval - label */
468 label = gtk_label_new(_("Refresh interval"));
469 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
470 /* Refresh interval - spinbutton */
471 gtk_widget_set_sensitive(feedprop->refresh_interval,
472 !ritem->default_refresh_interval);
473 gtk_box_pack_start(GTK_BOX(hbox), feedprop->refresh_interval, FALSE, FALSE, 0);
474 /* Refresh interval - units label */
475 label = gtk_label_new(g_strconcat(_("minute(s)"), "<small> ",
476 _("Set to 0 to disable automatic refreshing for this feed"),
478 gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
479 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
480 gtk_box_pack_start(GTK_BOX(inner_vbox), hbox, FALSE, FALSE, 0);
482 PACK_FRAME (vbox, frame, _("Refresh"));
483 gtk_container_set_border_width(GTK_CONTAINER(inner_vbox), 7);
484 gtk_container_add(GTK_CONTAINER(frame), inner_vbox);
487 bbox = gtk_hbutton_box_new();
488 gtk_container_set_border_width(GTK_CONTAINER(bbox), 5);
489 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
490 gtk_box_set_spacing(GTK_BOX(bbox), 5);
491 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
494 cancel_button = gtk_button_new();
495 gtk_container_add(GTK_CONTAINER(bbox), cancel_button);
497 cancel_align = gtk_alignment_new(0.5, 0.5, 0, 0);
498 gtk_container_add(GTK_CONTAINER(cancel_button), cancel_align);
500 cancel_hbox = gtk_hbox_new(FALSE, 2);
501 gtk_container_add(GTK_CONTAINER(cancel_align), cancel_hbox);
503 cancel_image = gtk_image_new_from_stock(GTK_STOCK_CANCEL,
504 GTK_ICON_SIZE_BUTTON);
505 gtk_box_pack_start(GTK_BOX(cancel_hbox), cancel_image, FALSE, FALSE, 0);
507 cancel_label = gtk_label_new_with_mnemonic(_("_Cancel"));
508 gtk_box_pack_end(GTK_BOX(cancel_hbox), cancel_label, FALSE, FALSE, 0);
510 g_signal_connect(G_OBJECT(cancel_button), "clicked",
511 G_CALLBACK(rssyl_props_cancel_cb), ritem);
514 ok_button = gtk_button_new();
515 gtk_container_add(GTK_CONTAINER(bbox), ok_button);
516 GTK_WIDGET_SET_FLAGS(ok_button, GTK_CAN_DEFAULT );
518 ok_align = gtk_alignment_new(0.5, 0.5, 0, 0);
519 gtk_container_add(GTK_CONTAINER(ok_button), ok_align);
521 ok_hbox = gtk_hbox_new(FALSE, 2);
522 gtk_container_add(GTK_CONTAINER(ok_align), ok_hbox);
524 ok_image = gtk_image_new_from_stock(GTK_STOCK_OK,
525 GTK_ICON_SIZE_BUTTON);
526 gtk_box_pack_start(GTK_BOX(ok_hbox), ok_image, FALSE, FALSE, 0);
528 ok_label = gtk_label_new_with_mnemonic(_("_OK"));
529 gtk_box_pack_end(GTK_BOX(ok_hbox), ok_label, FALSE, FALSE, 0);
531 g_signal_connect(G_OBJECT(ok_button), "clicked",
532 G_CALLBACK(rssyl_props_ok_cb), ritem);
534 /* Set some misc. stuff */
535 gtk_window_set_title(GTK_WINDOW(feedprop->window),
536 g_strdup(_("Set feed properties")) );
537 gtk_window_set_modal(GTK_WINDOW(feedprop->window), TRUE);
538 gtk_window_set_transient_for(GTK_WINDOW(feedprop->window),
539 GTK_WINDOW(mainwin->window) );
541 /* Attach callbacks to handle Enter and Escape keys */
542 g_signal_connect(G_OBJECT(feedprop->window), "key_press_event",
543 G_CALLBACK(rssyl_props_key_press_cb), ritem);
546 gtk_widget_show_all(feedprop->window);
547 gtk_widget_grab_default(ok_button);
549 /* Unselect the text in URL entry */
550 gtk_editable_select_region(GTK_EDITABLE(feedprop->url), 0, 0);
552 ritem->feedprop = feedprop;