2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2007-2012 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/>.
21 #include "claws-features.h"
27 #include <glib/gi18n.h>
33 #include "prefs_gtk.h"
34 #include "prefswindow.h"
36 #include "trayicon_prefs.h"
38 TrayIconPrefs trayicon_prefs;
40 typedef struct _TrayIconPage TrayIconPage;
42 struct _TrayIconPage {
44 GtkWidget *hide_at_startup;
45 GtkWidget *close_to_tray;
46 GtkWidget *hide_when_iconified;
49 static PrefParam param[] = {
50 {"hide_at_startup", "FALSE", &trayicon_prefs.hide_at_startup, P_BOOL, NULL, NULL, NULL},
51 {"close_to_tray", "FALSE", &trayicon_prefs.close_to_tray, P_BOOL, NULL, NULL, NULL},
52 {"hide_when_iconified", "FALSE", &trayicon_prefs.hide_when_iconified, P_BOOL, NULL, NULL, NULL},
56 static TrayIconPage prefs_page;
58 static void create_trayicon_prefs_page (PrefsPage *page,
61 static void destroy_trayicon_prefs_page (PrefsPage *page);
62 static void save_trayicon_prefs (PrefsPage *page);
64 void trayicon_prefs_init(void)
66 static gchar *path[3];
69 path[0] = _("Plugins");
70 path[1] = _("Trayicon");
73 prefs_set_default(param);
74 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
75 prefs_read_config(param, "TrayIcon", rcpath, NULL);
78 prefs_page.page.path = path;
79 prefs_page.page.create_widget = create_trayicon_prefs_page;
80 prefs_page.page.destroy_widget = destroy_trayicon_prefs_page;
81 prefs_page.page.save_page = save_trayicon_prefs;
83 prefs_gtk_register_page((PrefsPage *) &prefs_page);
86 void trayicon_prefs_done(void)
88 prefs_gtk_unregister_page((PrefsPage *) &prefs_page);
91 static void create_trayicon_prefs_page(PrefsPage *page,
95 TrayIconPage *prefs_page = (TrayIconPage *) page;
98 GtkWidget *hide_at_startup_checkbox;
99 GtkWidget *close_to_tray_checkbox;
100 GtkWidget *hide_when_iconified_checkbox;
102 vbox = gtk_vbox_new(FALSE, 3);
103 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
104 gtk_widget_show(vbox);
106 hide_at_startup_checkbox = gtk_check_button_new_with_label
107 (_("Hide at start-up"));
108 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_at_startup_checkbox),
109 trayicon_prefs.hide_at_startup);
110 gtk_box_pack_start(GTK_BOX(vbox), hide_at_startup_checkbox, FALSE, FALSE, 0);
111 gtk_widget_show(hide_at_startup_checkbox);
112 CLAWS_SET_TIP(hide_at_startup_checkbox,
113 _("Hide Claws Mail at start-up"));
115 close_to_tray_checkbox = gtk_check_button_new_with_label
116 (_("Close to tray"));
117 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(close_to_tray_checkbox),
118 trayicon_prefs.close_to_tray);
119 gtk_box_pack_start(GTK_BOX(vbox), close_to_tray_checkbox, FALSE, FALSE, 0);
120 gtk_widget_show(close_to_tray_checkbox);
121 CLAWS_SET_TIP(close_to_tray_checkbox,
122 _("Hide Claws Mail using the tray icon instead of closing it\nwhen the window close button is clicked"));
124 hide_when_iconified_checkbox = gtk_check_button_new_with_label
125 (_("Minimize to tray"));
126 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_when_iconified_checkbox),
127 trayicon_prefs.hide_when_iconified);
128 gtk_box_pack_start(GTK_BOX(vbox), hide_when_iconified_checkbox, FALSE, FALSE, 0);
129 gtk_widget_show(hide_when_iconified_checkbox);
130 CLAWS_SET_TIP(hide_when_iconified_checkbox,
131 _("Hide Claws Mail using the tray icon instead of minimizing it"));
133 prefs_page->hide_at_startup = hide_at_startup_checkbox;
134 prefs_page->close_to_tray = close_to_tray_checkbox;
135 prefs_page->hide_when_iconified = hide_when_iconified_checkbox;
136 prefs_page->page.widget = vbox;
139 static void destroy_trayicon_prefs_page(PrefsPage *page)
144 static void save_trayicon_prefs(PrefsPage *page)
146 TrayIconPage *prefs_page = (TrayIconPage *) page;
148 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
151 trayicon_prefs.hide_at_startup = gtk_toggle_button_get_active
152 (GTK_TOGGLE_BUTTON(prefs_page->hide_at_startup));
153 trayicon_prefs.close_to_tray = gtk_toggle_button_get_active
154 (GTK_TOGGLE_BUTTON(prefs_page->close_to_tray));
155 trayicon_prefs.hide_when_iconified = gtk_toggle_button_get_active
156 (GTK_TOGGLE_BUTTON(prefs_page->hide_when_iconified));
158 pref_file = prefs_write_open(rc_file_path);
159 g_free(rc_file_path);
162 (prefs_set_block_label(pref_file, "TrayIcon") < 0))
165 if (prefs_write_param(param, pref_file->fp) < 0) {
166 g_warning("failed to write TrayIcon Plugin configuration\n");
167 prefs_file_close_revert(pref_file);
170 if (fprintf(pref_file->fp, "\n") < 0) {
171 FILE_OP_ERROR(rc_file_path, "fprintf");
172 prefs_file_close_revert(pref_file);
174 prefs_file_close(pref_file);