2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2007 the Claws Mail Team
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.
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.
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/>.
26 #include <glib/gi18n.h>
32 #include "prefs_gtk.h"
33 #include "prefswindow.h"
35 #include "trayicon_prefs.h"
37 TrayIconPrefs trayicon_prefs;
39 typedef struct _TrayIconPage TrayIconPage;
41 struct _TrayIconPage {
43 GtkWidget *hide_at_startup;
44 GtkWidget *close_to_tray;
45 GtkWidget *hide_when_iconified;
48 static PrefParam param[] = {
49 {"hide_at_startup", "FALSE", &trayicon_prefs.hide_at_startup, P_BOOL, NULL, NULL, NULL},
50 {"close_to_tray", "FALSE", &trayicon_prefs.close_to_tray, P_BOOL, NULL, NULL, NULL},
51 {"hide_when_iconified", "FALSE", &trayicon_prefs.hide_when_iconified, P_BOOL, NULL, NULL, NULL},
55 static TrayIconPage prefs_page;
57 static void create_trayicon_prefs_page (PrefsPage *page,
60 static void destroy_trayicon_prefs_page (PrefsPage *page);
61 static void save_trayicon_prefs (PrefsPage *page);
63 void trayicon_prefs_init(void)
65 static gchar *path[3];
68 path[0] = _("Plugins");
69 path[1] = _("Trayicon");
72 prefs_set_default(param);
73 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
74 prefs_read_config(param, "TrayIcon", rcpath, NULL);
77 prefs_page.page.path = path;
78 prefs_page.page.create_widget = create_trayicon_prefs_page;
79 prefs_page.page.destroy_widget = destroy_trayicon_prefs_page;
80 prefs_page.page.save_page = save_trayicon_prefs;
82 prefs_gtk_register_page((PrefsPage *) &prefs_page);
85 void trayicon_prefs_done(void)
87 prefs_gtk_unregister_page((PrefsPage *) &prefs_page);
90 static void create_trayicon_prefs_page(PrefsPage *page,
94 TrayIconPage *prefs_page = (TrayIconPage *) page;
97 GtkWidget *hide_at_startup_checkbox;
98 GtkTooltips *hide_at_startup_tooltip;
99 GtkWidget *close_to_tray_checkbox;
100 GtkTooltips *close_to_tray_tooltip;
101 GtkWidget *hide_when_iconified_checkbox;
102 GtkTooltips *hide_when_iconified_tooltip;
104 vbox = gtk_vbox_new(FALSE, 3);
105 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
106 gtk_widget_show(vbox);
108 hide_at_startup_tooltip = gtk_tooltips_new();
109 hide_at_startup_checkbox = gtk_check_button_new_with_label
110 (_("Hide at start-up"));
111 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_at_startup_checkbox),
112 trayicon_prefs.hide_at_startup);
113 gtk_box_pack_start(GTK_BOX(vbox), hide_at_startup_checkbox, FALSE, FALSE, 0);
114 gtk_widget_show(hide_at_startup_checkbox);
115 gtk_tooltips_set_tip(GTK_TOOLTIPS(hide_at_startup_tooltip), hide_at_startup_checkbox,
116 _("Hide Claws Mail at start-up"), NULL);
118 close_to_tray_tooltip = gtk_tooltips_new();
119 close_to_tray_checkbox = gtk_check_button_new_with_label
120 (_("Close to tray"));
121 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(close_to_tray_checkbox),
122 trayicon_prefs.close_to_tray);
123 gtk_box_pack_start(GTK_BOX(vbox), close_to_tray_checkbox, FALSE, FALSE, 0);
124 gtk_widget_show(close_to_tray_checkbox);
125 gtk_tooltips_set_tip(GTK_TOOLTIPS(close_to_tray_tooltip), close_to_tray_checkbox,
126 _("Hide Claws Mail using the tray icon instead of closing it\nwhen the window close button is clicked"), NULL);
128 hide_when_iconified_tooltip = gtk_tooltips_new();
129 hide_when_iconified_checkbox = gtk_check_button_new_with_label
130 (_("Minimize to tray"));
131 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_when_iconified_checkbox),
132 trayicon_prefs.hide_when_iconified);
133 gtk_box_pack_start(GTK_BOX(vbox), hide_when_iconified_checkbox, FALSE, FALSE, 0);
134 gtk_widget_show(hide_when_iconified_checkbox);
135 gtk_tooltips_set_tip(GTK_TOOLTIPS(hide_when_iconified_tooltip), hide_when_iconified_checkbox,
136 _("Hide Claws Mail using the tray icon instead of minimizing it"), NULL);
138 prefs_page->hide_at_startup = hide_at_startup_checkbox;
139 prefs_page->close_to_tray = close_to_tray_checkbox;
140 prefs_page->hide_when_iconified = hide_when_iconified_checkbox;
141 prefs_page->page.widget = vbox;
144 static void destroy_trayicon_prefs_page(PrefsPage *page)
149 static void save_trayicon_prefs(PrefsPage *page)
151 TrayIconPage *prefs_page = (TrayIconPage *) page;
153 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
156 trayicon_prefs.hide_at_startup = gtk_toggle_button_get_active
157 (GTK_TOGGLE_BUTTON(prefs_page->hide_at_startup));
158 trayicon_prefs.close_to_tray = gtk_toggle_button_get_active
159 (GTK_TOGGLE_BUTTON(prefs_page->close_to_tray));
160 trayicon_prefs.hide_when_iconified = gtk_toggle_button_get_active
161 (GTK_TOGGLE_BUTTON(prefs_page->hide_when_iconified));
163 pref_file = prefs_write_open(rc_file_path);
164 g_free(rc_file_path);
167 (prefs_set_block_label(pref_file, "TrayIcon") < 0))
170 if (prefs_write_param(param, pref_file->fp) < 0) {
171 g_warning("failed to write TrayIcon Plugin configuration\n");
172 prefs_file_close_revert(pref_file);
175 if (fprintf(pref_file->fp, "\n") < 0) {
176 FILE_OP_ERROR(rc_file_path, "fprintf");
177 prefs_file_close_revert(pref_file);
179 prefs_file_close(pref_file);