2007-01-26 [wwp] 2.7.2cvs2
[claws.git] / src / plugins / trayicon / trayicon_prefs.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2007 the Claws Mail Team
4  *
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 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation, 
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29
30 #include "gtkutils.h"
31 #include "utils.h"
32 #include "prefs.h"
33 #include "prefs_gtk.h"
34 #include "prefswindow.h"
35
36 #include "trayicon_prefs.h"
37
38 TrayIconPrefs trayicon_prefs;
39
40 typedef struct _TrayIconPage TrayIconPage;
41
42 struct _TrayIconPage {
43         PrefsPage page;
44         GtkWidget *hide_at_startup;
45 };
46
47 static PrefParam param[] = {
48         {"hide_at_startup", "FALSE", &trayicon_prefs.hide_at_startup, P_BOOL, NULL, NULL, NULL},
49         {0,0,0,0,0,0,0}
50 };
51
52 static TrayIconPage prefs_page;
53
54 static void create_trayicon_prefs_page  (PrefsPage *page,
55                                          GtkWindow *window,
56                                          gpointer   data);
57 static void destroy_trayicon_prefs_page (PrefsPage *page);
58 static void save_trayicon_prefs         (PrefsPage *page);
59
60 void trayicon_prefs_init(void)
61 {
62         static gchar *path[3];
63         gchar *rcpath;
64
65         path[0] = _("Plugins");
66         path[1] = _("TrayIcon");
67         path[2] = NULL;
68
69         prefs_set_default(param);
70         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
71         prefs_read_config(param, "TrayIcon", rcpath, NULL);
72         g_free(rcpath);
73         
74         prefs_page.page.path = path;
75         prefs_page.page.create_widget = create_trayicon_prefs_page;
76         prefs_page.page.destroy_widget = destroy_trayicon_prefs_page;
77         prefs_page.page.save_page = save_trayicon_prefs;
78
79         prefs_gtk_register_page((PrefsPage *) &prefs_page);
80 }
81
82 void trayicon_prefs_done(void)
83 {
84         prefs_gtk_unregister_page((PrefsPage *) &prefs_page);
85 }
86
87 static void create_trayicon_prefs_page(PrefsPage *page,
88                                     GtkWindow *window,
89                                     gpointer data)
90 {
91         TrayIconPage *prefs_page = (TrayIconPage *) page;
92
93         GtkWidget *vbox;
94         GtkWidget *hide_at_startup_checkbox;
95         GtkTooltips *hide_at_startup_tooltip;
96
97         vbox = gtk_vbox_new(FALSE, 3);
98         gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
99         gtk_widget_show(vbox);
100         
101         hide_at_startup_tooltip = gtk_tooltips_new();
102         hide_at_startup_checkbox = gtk_check_button_new_with_label
103                                 (_("Hide at start-up"));
104         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hide_at_startup_checkbox),
105                                      trayicon_prefs.hide_at_startup);
106         gtk_box_pack_start(GTK_BOX(vbox), hide_at_startup_checkbox, FALSE, FALSE, 0);
107         gtk_widget_show(hide_at_startup_checkbox);
108         gtk_tooltips_set_tip(GTK_TOOLTIPS(hide_at_startup_tooltip), hide_at_startup_checkbox,
109                              _("Hide Claws Mail at start-up"), NULL);
110         
111         prefs_page->hide_at_startup = hide_at_startup_checkbox;
112         prefs_page->page.widget = vbox;
113 }
114
115 static void destroy_trayicon_prefs_page(PrefsPage *page)
116 {
117         /* Do nothing! */
118 }
119
120 static void save_trayicon_prefs(PrefsPage *page)
121 {
122         TrayIconPage *prefs_page = (TrayIconPage *) page;
123         PrefFile *pref_file;
124         gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
125                                           COMMON_RC, NULL);
126         
127         trayicon_prefs.hide_at_startup = gtk_toggle_button_get_active
128                                 (GTK_TOGGLE_BUTTON(prefs_page->hide_at_startup));
129         
130         pref_file = prefs_write_open(rc_file_path);
131         g_free(rc_file_path);
132         
133         if (!(pref_file) ||
134             (prefs_set_block_label(pref_file, "TrayIcon") < 0))
135           return;
136         
137         if (prefs_write_param(param, pref_file->fp) < 0) {
138           g_warning("failed to write TrayIcon Plugin configuration\n");
139           prefs_file_close_revert(pref_file);
140           return;
141         }
142         fprintf(pref_file->fp, "\n");
143         prefs_file_close(pref_file);
144 }