5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "qt_ui_utils.h"
29 #include "ui/recent.h"
30 #include "ui/ui_util.h"
32 // XXX - Copied from ui/gtk/gui_utils.c
34 #define WINDOW_GEOM_KEY "window_geom"
36 /* load the geometry values for a window from previously saved values */
37 static gboolean window_geom_load(const gchar *name, window_geometry_t *geom);
39 /* the geometry hashtable for all known window classes,
40 * the window name is the key, and the geometry struct is the value */
41 static GHashTable *window_geom_hash = NULL;
43 /* save the window and it's current geometry into the geometry hashtable */
45 window_geom_save(const gchar *name, window_geometry_t *geom)
48 window_geometry_t *work;
50 /* init hashtable, if not already done */
51 if(!window_geom_hash) {
52 window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
54 /* if we have an old one, remove and free it first */
55 work = (window_geometry_t *) g_hash_table_lookup(window_geom_hash, name);
57 g_hash_table_remove(window_geom_hash, name);
62 /* g_malloc and insert the new one */
63 work = (window_geometry_t *) g_malloc(sizeof(*geom));
67 g_hash_table_insert(window_geom_hash, key, work);
71 /* load the desired geometry for this window from the geometry hashtable */
73 window_geom_load(const gchar *name, window_geometry_t *geom)
77 /* init hashtable, if not already done */
78 if(!window_geom_hash) {
79 window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
82 p = (window_geometry_t *) g_hash_table_lookup(window_geom_hash, name);
92 /* read in a single key value pair from the recent file into the geometry hashtable */
94 window_geom_recent_read_pair(const char *name, const char *key, const char *value)
96 window_geometry_t geom;
99 /* find window geometry maybe already in hashtable */
100 if(!window_geom_load(name, &geom)) {
101 /* not in table, init geom with "basic" values */
102 geom.key = NULL; /* Will be set in window_geom_save () */
103 geom.set_pos = FALSE;
106 geom.set_size = FALSE;
110 geom.set_maximized = FALSE;/* this is valid in GTK2 only */
111 geom.maximized = FALSE; /* this is valid in GTK2 only */
114 if (strcmp(key, "x") == 0) {
115 geom.x = strtol(value, NULL, 10);
117 } else if (strcmp(key, "y") == 0) {
118 geom.y = strtol(value, NULL, 10);
120 } else if (strcmp(key, "width") == 0) {
121 geom.width = strtol(value, NULL, 10);
122 geom.set_size = TRUE;
123 } else if (strcmp(key, "height") == 0) {
124 geom.height = strtol(value, NULL, 10);
125 geom.set_size = TRUE;
126 } else if (strcmp(key, "maximized") == 0) {
127 if (g_ascii_strcasecmp(value, "true") == 0) {
128 geom.maximized = TRUE;
131 geom.maximized = FALSE;
133 geom.set_maximized = TRUE;
136 * Silently ignore the bogus key. We shouldn't abort here,
137 * as this could be due to a corrupt recent file.
139 * XXX - should we print a message about this?
144 /* save / replace geometry in hashtable */
145 window_geom_save(name, &geom);
148 /* write all geometry values of all windows from the hashtable to the recent file */
150 window_geom_recent_write_all(gpointer rf)
152 /* init hashtable, if not already done */
153 if(!window_geom_hash) {
154 window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
157 g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);