1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "modest-widget-memory.h"
34 #define PARAM_HEIGHT "height"
35 #define PARAM_WIDTH "width"
36 #define PARAM_POS "pos"
39 get_keyname (ModestConf *conf, const gchar *name, const gchar *param)
41 gchar *esc_name, *keyname;
42 esc_name = modest_conf_key_escape (conf, name);
44 keyname = g_strdup_printf ("%s/%s/%s",
45 MODEST_CONF_WIDGET_NAMESPACE,
54 save_settings_widget (ModestConf *conf, GtkWidget *widget, const gchar *name)
58 key = get_keyname (conf, name, PARAM_HEIGHT);
59 modest_conf_set_int (conf, key, GTK_WIDGET(widget)->allocation.height, NULL);
62 key = get_keyname (conf, name, PARAM_WIDTH);
63 modest_conf_set_int (conf, key, GTK_WIDGET(widget)->allocation.width, NULL);
71 restore_settings_widget (ModestConf *conf, GtkWidget *widget, const gchar *name)
76 key = get_keyname (conf, name, PARAM_HEIGHT);
78 if (modest_conf_key_exists (conf, key, NULL))
79 req.height = modest_conf_get_int (conf, key, NULL);
83 key = get_keyname (conf, name, PARAM_WIDTH);
84 if (modest_conf_key_exists (conf, key, NULL))
85 req.width = modest_conf_get_int (conf, key, NULL);
88 if (req.height && req.width)
89 gtk_widget_size_request (widget, &req);
98 save_settings_window (ModestConf *conf, GtkWindow *win, const gchar *name)
103 gtk_window_get_size (win, &width, &height);
105 key = get_keyname (conf, name, PARAM_HEIGHT);
106 modest_conf_set_int (conf, key, height, NULL);
109 key = get_keyname (conf, name, PARAM_WIDTH);
110 modest_conf_set_int (conf, key, width, NULL);
118 restore_settings_window (ModestConf *conf, GtkWindow *win, const gchar *name)
121 int height = 0, width = 0;
123 key = get_keyname (conf, name, PARAM_HEIGHT);
125 if (modest_conf_key_exists (conf, key, NULL))
126 height = modest_conf_get_int (conf, key, NULL);
130 key = get_keyname (conf, name, PARAM_WIDTH);
131 if (modest_conf_key_exists (conf, key, NULL))
132 width = modest_conf_get_int (conf, key, NULL);
137 gtk_window_set_default_size (win, width, height);
144 save_settings_paned (ModestConf *conf, GtkPaned *paned, const gchar *name)
149 pos = gtk_paned_get_position (paned);
151 key = get_keyname (conf, name, PARAM_POS);
152 modest_conf_set_int (conf, key, pos, NULL);
160 restore_settings_paned (ModestConf *conf, GtkPaned *paned, const gchar *name)
165 key = get_keyname (conf, name, PARAM_POS);
167 if (modest_conf_key_exists (conf, key, NULL)) {
168 pos = modest_conf_get_int (conf, key, NULL);
169 gtk_paned_set_position (paned, pos);
178 modest_widget_memory_save_settings (ModestConf *conf, GtkWidget *widget,
181 g_return_val_if_fail (conf, FALSE);
182 g_return_val_if_fail (widget, FALSE);
183 g_return_val_if_fail (name, FALSE);
185 if (GTK_IS_WINDOW(widget))
186 return save_settings_window (conf, (GtkWindow*)widget, name);
187 else if (GTK_IS_PANED(widget))
188 return save_settings_paned (conf, (GtkPaned*)widget, name);
189 else if (GTK_IS_WIDGET(widget))
190 return save_settings_widget (conf, widget, name);
198 modest_widget_memory_restore_settings (ModestConf *conf, GtkWidget *widget,
201 g_return_val_if_fail (conf, FALSE);
202 g_return_val_if_fail (widget, FALSE);
203 g_return_val_if_fail (name, FALSE);
205 if (GTK_IS_WINDOW(widget))
206 return restore_settings_window (conf, (GtkWindow*)widget, name);
207 else if (GTK_IS_PANED(widget))
208 return restore_settings_paned (conf, (GtkPaned*)widget, name);
209 else if (GTK_IS_WIDGET(widget))
210 return restore_settings_widget (conf, widget, name);