aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-02-02 05:34:31 +0000
committerGuy Harris <guy@alum.mit.edu>2013-02-02 05:34:31 +0000
commit6ebabce7b50702ef8f49653f8d6d2bcde424c027 (patch)
tree8da0cd6d22b1c6b1d7449c603f29b96df9c5880e /ui
parentab3840049e8de97b835a393fc964b2bd61e04ff9 (diff)
Move the GUI-independent window geometry stuff to ui/recent.c, so we
only have one copy. svn path=/trunk/; revision=47440
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk/gui_utils.c134
-rw-r--r--ui/qt/qt_ui_utils.cpp128
-rw-r--r--ui/recent.c178
-rw-r--r--ui/recent.h15
-rw-r--r--ui/recent_utils.h15
5 files changed, 163 insertions, 307 deletions
diff --git a/ui/gtk/gui_utils.c b/ui/gtk/gui_utils.c
index 4680b9ab02..a0fb98bd68 100644
--- a/ui/gtk/gui_utils.c
+++ b/ui/gtk/gui_utils.c
@@ -65,12 +65,6 @@
#define WINDOW_GEOM_KEY "window_geom"
-
-/* load the geometry values for a window from previously saved values */
-static gboolean window_geom_load(const gchar *name, window_geometry_t *geom);
-
-
-
/* Set our window icon. The GDK documentation doesn't provide any
actual documentation for gdk_window_set_icon(), so we'll steal
libgimp/gimpdialog.c:gimp_dialog_realize_callback() from the Gimp
@@ -434,134 +428,6 @@ window_set_geometry(GtkWidget *widget,
}
}
-
-/* the geometry hashtable for all known window classes,
- * the window name is the key, and the geometry struct is the value */
-static GHashTable *window_geom_hash = NULL;
-
-
-/* save the window and it's current geometry into the geometry hashtable */
-static void
-window_geom_save(const gchar *name, window_geometry_t *geom)
-{
- gchar *key;
- window_geometry_t *work;
-
- /* init hashtable, if not already done */
- if(!window_geom_hash) {
- window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
- }
- /* if we have an old one, remove and free it first */
- work = g_hash_table_lookup(window_geom_hash, name);
- if(work) {
- g_hash_table_remove(window_geom_hash, name);
- g_free(work->key);
- g_free(work);
- }
-
- /* g_malloc and insert the new one */
- work = g_malloc(sizeof(*geom));
- *work = *geom;
- key = g_strdup(name);
- work->key = key;
- g_hash_table_insert(window_geom_hash, key, work);
-}
-
-
-/* load the desired geometry for this window from the geometry hashtable */
-static gboolean
-window_geom_load(const gchar *name,
- window_geometry_t *geom)
-{
- window_geometry_t *p;
-
- /* init hashtable, if not already done */
- if(!window_geom_hash) {
- window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
- }
-
- p = g_hash_table_lookup(window_geom_hash, name);
- if(p) {
- *geom = *p;
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-
-/* read in a single key value pair from the recent file into the geometry hashtable */
-void
-window_geom_recent_read_pair(const char *name,
- const char *key,
- const char *value)
-{
- window_geometry_t geom;
-
-
- /* find window geometry maybe already in hashtable */
- if(!window_geom_load(name, &geom)) {
- /* not in table, init geom with "basic" values */
- geom.key = NULL; /* Will be set in window_geom_save() */
- geom.set_pos = FALSE;
- geom.x = -1;
- geom.y = -1;
- geom.set_size = FALSE;
- geom.width = -1;
- geom.height = -1;
-
- geom.set_maximized = FALSE;/* this is valid in GTK2 only */
- geom.maximized = FALSE; /* this is valid in GTK2 only */
- }
-
- if (strcmp(key, "x") == 0) {
- geom.x = (gint)strtol(value, NULL, 10);
- geom.set_pos = TRUE;
- } else if (strcmp(key, "y") == 0) {
- geom.y = (gint)strtol(value, NULL, 10);
- geom.set_pos = TRUE;
- } else if (strcmp(key, "width") == 0) {
- geom.width = (gint)strtol(value, NULL, 10);
- geom.set_size = TRUE;
- } else if (strcmp(key, "height") == 0) {
- geom.height = (gint)strtol(value, NULL, 10);
- geom.set_size = TRUE;
- } else if (strcmp(key, "maximized") == 0) {
- if (g_ascii_strcasecmp(value, "true") == 0) {
- geom.maximized = TRUE;
- }
- else {
- geom.maximized = FALSE;
- }
- geom.set_maximized = TRUE;
- } else {
- /*
- * Silently ignore the bogus key. We shouldn't abort here,
- * as this could be due to a corrupt recent file.
- *
- * XXX - should we print a message about this?
- */
- return;
- }
-
- /* save / replace geometry in hashtable */
- window_geom_save(name, &geom);
-}
-
-
-/* write all geometry values of all windows from the hashtable to the recent file */
-void
-window_geom_recent_write_all(gpointer rf)
-{
- /* init hashtable, if not already done */
- if(!window_geom_hash) {
- window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
- }
-
- g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);
-}
-
-
void
window_destroy(GtkWidget *win)
{
diff --git a/ui/qt/qt_ui_utils.cpp b/ui/qt/qt_ui_utils.cpp
index 5a5677cb1a..b41f9a2c07 100644
--- a/ui/qt/qt_ui_utils.cpp
+++ b/ui/qt/qt_ui_utils.cpp
@@ -31,134 +31,6 @@
#include <wsutil/str_util.h>
-// XXX - Copied from ui/gtk/gui_utils.c
-
-#define WINDOW_GEOM_KEY "window_geom"
-
-/* load the geometry values for a window from previously saved values */
-static gboolean window_geom_load(const gchar *name, window_geometry_t *geom);
-
-/* the geometry hashtable for all known window classes,
- * the window name is the key, and the geometry struct is the value */
-static GHashTable *window_geom_hash = NULL;
-
-/* save the window and it's current geometry into the geometry hashtable */
-static void
-window_geom_save(const gchar *name, window_geometry_t *geom)
-{
- gchar *key;
- window_geometry_t *work;
-
- /* init hashtable, if not already done */
- if(!window_geom_hash) {
- window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
- }
- /* if we have an old one, remove and free it first */
- work = (window_geometry_t *) g_hash_table_lookup(window_geom_hash, name);
- if(work) {
- g_hash_table_remove(window_geom_hash, name);
- g_free(work->key);
- g_free(work);
- }
-
- /* g_malloc and insert the new one */
- work = (window_geometry_t *) g_malloc(sizeof(*geom));
- *work = *geom;
- key = g_strdup(name);
- work->key = key;
- g_hash_table_insert(window_geom_hash, key, work);
-}
-
-
-/* load the desired geometry for this window from the geometry hashtable */
-static gboolean
-window_geom_load(const gchar *name, window_geometry_t *geom)
-{
- window_geometry_t *p;
-
- /* init hashtable, if not already done */
- if(!window_geom_hash) {
- window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
- }
-
- p = (window_geometry_t *) g_hash_table_lookup(window_geom_hash, name);
- if(p) {
- *geom = *p;
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-
-/* read in a single key value pair from the recent file into the geometry hashtable */
-extern "C" void
-window_geom_recent_read_pair(const char *name, const char *key, const char *value)
-{
- window_geometry_t geom;
-
-
- /* find window geometry maybe already in hashtable */
- if(!window_geom_load(name, &geom)) {
- /* not in table, init geom with "basic" values */
- geom.key = NULL; /* Will be set in window_geom_save () */
- geom.set_pos = FALSE;
- geom.x = -1;
- geom.y = -1;
- geom.set_size = FALSE;
- geom.width = -1;
- geom.height = -1;
-
- geom.set_maximized = FALSE;/* this is valid in GTK2 only */
- geom.maximized = FALSE; /* this is valid in GTK2 only */
- }
-
- if (strcmp(key, "x") == 0) {
- geom.x = strtol(value, NULL, 10);
- geom.set_pos = TRUE;
- } else if (strcmp(key, "y") == 0) {
- geom.y = strtol(value, NULL, 10);
- geom.set_pos = TRUE;
- } else if (strcmp(key, "width") == 0) {
- geom.width = strtol(value, NULL, 10);
- geom.set_size = TRUE;
- } else if (strcmp(key, "height") == 0) {
- geom.height = strtol(value, NULL, 10);
- geom.set_size = TRUE;
- } else if (strcmp(key, "maximized") == 0) {
- if (g_ascii_strcasecmp(value, "true") == 0) {
- geom.maximized = TRUE;
- }
- else {
- geom.maximized = FALSE;
- }
- geom.set_maximized = TRUE;
- } else {
- /*
- * Silently ignore the bogus key. We shouldn't abort here,
- * as this could be due to a corrupt recent file.
- *
- * XXX - should we print a message about this?
- */
- return;
- }
-
- /* save / replace geometry in hashtable */
- window_geom_save(name, &geom);
-}
-
-/* write all geometry values of all windows from the hashtable to the recent file */
-extern "C" void
-window_geom_recent_write_all(gpointer rf)
-{
- /* init hashtable, if not already done */
- if(!window_geom_hash) {
- window_geom_hash = g_hash_table_new (g_str_hash, g_str_equal);
- }
-
- g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);
-}
-
/* Make the format_size_flags_e enum usable in C++ */
format_size_flags_e operator|(format_size_flags_e lhs, format_size_flags_e rhs) {
return (format_size_flags_e) ((int)lhs| (int)rhs);
diff --git a/ui/recent.c b/ui/recent.c
index d66759672f..d8af54b353 100644
--- a/ui/recent.c
+++ b/ui/recent.c
@@ -127,6 +127,162 @@ free_col_width_info(recent_settings_t *rs)
rs->col_width_list = NULL;
}
+/** Write the geometry values of a single window to the recent file.
+ *
+ * @param key unused
+ * @param value the geometry values
+ * @param rf recent file handle (FILE)
+ */
+static void
+write_recent_geom(gpointer key _U_, gpointer value, gpointer rf)
+{
+ window_geometry_t *geom = value;
+
+ fprintf(rf, "\n# Geometry and maximized state of %s window.\n", geom->key);
+ fprintf(rf, "# Decimal integers.\n");
+ fprintf(rf, RECENT_GUI_GEOMETRY "%s.x: %d\n", geom->key, geom->x);
+ fprintf(rf, RECENT_GUI_GEOMETRY "%s.y: %d\n", geom->key, geom->y);
+ fprintf(rf, RECENT_GUI_GEOMETRY "%s.width: %d\n", geom->key,
+ geom->width);
+ fprintf(rf, RECENT_GUI_GEOMETRY "%s.height: %d\n", geom->key,
+ geom->height);
+
+ fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
+ fprintf(rf, RECENT_GUI_GEOMETRY "%s.maximized: %s\n", geom->key,
+ geom->maximized == TRUE ? "TRUE" : "FALSE");
+
+}
+
+/* the geometry hashtable for all known window classes,
+ * the window name is the key, and the geometry struct is the value */
+static GHashTable *window_geom_hash = NULL;
+
+/* save the window and it's current geometry into the geometry hashtable */
+void
+window_geom_save(const gchar *name, window_geometry_t *geom)
+{
+ gchar *key;
+ window_geometry_t *work;
+
+ /* init hashtable, if not already done */
+ if(!window_geom_hash) {
+ window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ }
+ /* if we have an old one, remove and free it first */
+ work = g_hash_table_lookup(window_geom_hash, name);
+ if(work) {
+ g_hash_table_remove(window_geom_hash, name);
+ g_free(work->key);
+ g_free(work);
+ }
+
+ /* g_malloc and insert the new one */
+ work = g_malloc(sizeof(*geom));
+ *work = *geom;
+ key = g_strdup(name);
+ work->key = key;
+ g_hash_table_insert(window_geom_hash, key, work);
+}
+
+/* load the desired geometry for this window from the geometry hashtable */
+gboolean
+window_geom_load(const gchar *name,
+ window_geometry_t *geom)
+{
+ window_geometry_t *p;
+
+ /* init hashtable, if not already done */
+ if(!window_geom_hash) {
+ window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ }
+
+ p = g_hash_table_lookup(window_geom_hash, name);
+ if(p) {
+ *geom = *p;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/** Read in a single geometry key value pair from the recent file.
+ *
+ * @param name the geom_name of the window
+ * @param key the subkey of this pair (e.g. "x")
+ * @param value the new value (e.g. "123")
+ */
+static void
+window_geom_recent_read_pair(const char *name,
+ const char *key,
+ const char *value)
+{
+ window_geometry_t geom;
+
+ /* find window geometry maybe already in hashtable */
+ if(!window_geom_load(name, &geom)) {
+ /* not in table, init geom with "basic" values */
+ geom.key = NULL; /* Will be set in window_geom_save() */
+ geom.set_pos = FALSE;
+ geom.x = -1;
+ geom.y = -1;
+ geom.set_size = FALSE;
+ geom.width = -1;
+ geom.height = -1;
+
+ geom.set_maximized = FALSE;/* this is valid in GTK2 only */
+ geom.maximized = FALSE; /* this is valid in GTK2 only */
+ }
+
+ if (strcmp(key, "x") == 0) {
+ geom.x = (gint)strtol(value, NULL, 10);
+ geom.set_pos = TRUE;
+ } else if (strcmp(key, "y") == 0) {
+ geom.y = (gint)strtol(value, NULL, 10);
+ geom.set_pos = TRUE;
+ } else if (strcmp(key, "width") == 0) {
+ geom.width = (gint)strtol(value, NULL, 10);
+ geom.set_size = TRUE;
+ } else if (strcmp(key, "height") == 0) {
+ geom.height = (gint)strtol(value, NULL, 10);
+ geom.set_size = TRUE;
+ } else if (strcmp(key, "maximized") == 0) {
+ if (g_ascii_strcasecmp(value, "true") == 0) {
+ geom.maximized = TRUE;
+ }
+ else {
+ geom.maximized = FALSE;
+ }
+ geom.set_maximized = TRUE;
+ } else {
+ /*
+ * Silently ignore the bogus key. We shouldn't abort here,
+ * as this could be due to a corrupt recent file.
+ *
+ * XXX - should we print a message about this?
+ */
+ return;
+ }
+
+ /* save / replace geometry in hashtable */
+ window_geom_save(name, &geom);
+}
+
+/** Write all geometry values of all windows to the recent file.
+ * Will call write_recent_geom() for every existing window type.
+ *
+ * @param rf recent file handle from caller
+ */
+static void
+window_geom_recent_write_all(FILE *rf)
+{
+ /* init hashtable, if not already done */
+ if(!window_geom_hash) {
+ window_geom_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ }
+
+ g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);
+}
+
/* Attempt to Write out "recent common" to the user's recent common file.
If we got an error report it with a dialog box and return FALSE,
otherwise return TRUE. */
@@ -400,28 +556,6 @@ write_profile_recent(void)
return TRUE;
}
-
-/* write the geometry values of a window to recent file */
-void
-write_recent_geom(gpointer key _U_, gpointer value, gpointer rf)
-{
- window_geometry_t *geom = value;
-
- fprintf(rf, "\n# Geometry and maximized state of %s window.\n", geom->key);
- fprintf(rf, "# Decimal integers.\n");
- fprintf(rf, RECENT_GUI_GEOMETRY "%s.x: %d\n", geom->key, geom->x);
- fprintf(rf, RECENT_GUI_GEOMETRY "%s.y: %d\n", geom->key, geom->y);
- fprintf(rf, RECENT_GUI_GEOMETRY "%s.width: %d\n", geom->key,
- geom->width);
- fprintf(rf, RECENT_GUI_GEOMETRY "%s.height: %d\n", geom->key,
- geom->height);
-
- fprintf(rf, "# TRUE or FALSE (case-insensitive).\n");
- fprintf(rf, RECENT_GUI_GEOMETRY "%s.maximized: %s\n", geom->key,
- geom->maximized == TRUE ? "TRUE" : "FALSE");
-
-}
-
/* set one user's recent common file key/value pair */
static prefs_set_pref_e
read_set_recent_common_pair_static(gchar *key, const gchar *value,
diff --git a/ui/recent.h b/ui/recent.h
index 7b22a6a8cc..0954e71b3b 100644
--- a/ui/recent.h
+++ b/ui/recent.h
@@ -33,6 +33,7 @@ extern "C" {
#include <glib.h>
#include "epan/timestamp.h"
+#include "ui/ui_util.h"
/** @file
* Recent user interface settings.
@@ -138,14 +139,6 @@ extern void recent_read_profile_static(char **rf_path_return, int *rf_errno_retu
*/
extern void recent_read_dynamic(char **rf_path_return, int *rf_errno_return);
-/** Write the geometry values of a single window to the recent file.
- *
- * @param key unused
- * @param value the geometry values
- * @param rf recent file handle (FILE)
- */
-extern void write_recent_geom(gpointer key, gpointer value, gpointer rf);
-
/**
* Given a -o command line string, parse it and set the recent value in
* question. Return an indication of whether it succeeded or failed
@@ -183,6 +176,12 @@ extern gchar recent_get_column_xalign(gint col);
*/
extern void recent_set_column_xalign(gint col, gchar xalign);
+/* save the window and its current geometry into the geometry hashtable */
+extern void window_geom_save(const gchar *name, window_geometry_t *geom);
+
+/* load the desired geometry for this window from the geometry hashtable */
+extern gboolean window_geom_load(const gchar *name, window_geometry_t *geom);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/ui/recent_utils.h b/ui/recent_utils.h
index c32859da31..e19e6046cc 100644
--- a/ui/recent_utils.h
+++ b/ui/recent_utils.h
@@ -82,21 +82,6 @@ gboolean
capture_remote_combo_add_recent(const gchar *s);
#endif
-/** Read in a single geometry key value pair from the recent file.
- *
- * @param name the geom_name of the window
- * @param key the subkey of this pair (e.g. "x")
- * @param value the new value (e.g. "123")
- */
-extern void window_geom_recent_read_pair(const char *name, const char *key, const char *value);
-
-/** Write all geometry values of all windows to the recent file.
- * Will call write_recent_geom() for every existing window type.
- *
- * @param rf recent file handle from caller
- */
-extern void window_geom_recent_write_all(gpointer rf);
-
/** Write all packet list geometry values to the recent file.
*
* @param rf recent file handle from caller