summaryrefslogtreecommitdiff
path: root/ui/preference_utils.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2013-01-18 00:50:14 +0000
committerGerald Combs <gerald@wireshark.org>2013-01-18 00:50:14 +0000
commitae7ee61e842f46d0e7a7a4dc64c848866a6d7afb (patch)
tree6e483f057cb06bc3c9a8ee68a6211bd4be557f6a /ui/preference_utils.c
parent7a9095ee15c9ef012f3c8fd77c8f8cd06bdaa37b (diff)
downloadwireshark-ae7ee61e842f46d0e7a7a4dc64c848866a6d7afb.tar.gz
Rename the "saved_val" preference element to "stashed_val" in order to
more clearly indicate that it's a copy of a preference value rather than something we've saved in the preferences file. Update prefs_pref_to_str() to handle default, stashed, and current prefs. Create ui/preference_utils.[ch] and move some common routines there. Use prefs_pref_type_name() in the GTK+ preferences dialog. Make the "OK" button in the Qt preferences dialog work. We simply write the prefs and redissect on "OK" and do nothing on "Cancel". This is intentionally different from the Apply/OK/Cancel behavior in the GTK+ version. Add a general "emitAppSignal" method to wsApp and use it for packet dissection and preference changes. Suggest that we might want to create a WsString class to make conversion between QStrings, gchar *s, and GStrings easier. svn path=/trunk/; revision=47139
Diffstat (limited to 'ui/preference_utils.c')
-rw-r--r--ui/preference_utils.c295
1 files changed, 295 insertions, 0 deletions
diff --git a/ui/preference_utils.c b/ui/preference_utils.c
new file mode 100644
index 0000000000..faf6b6d3e9
--- /dev/null
+++ b/ui/preference_utils.c
@@ -0,0 +1,295 @@
+/* preference_utils.h
+ * Routines for handling preferences
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <errno.h>
+
+#include <glib.h>
+
+#include <epan/filesystem.h>
+#include <epan/prefs.h>
+#include <epan/prefs-int.h>
+
+#ifdef HAVE_LIBPCAP
+#include "capture_opts.h"
+#include "ui/capture_globals.h"
+#endif
+
+#include "ui/preference_utils.h"
+#include "ui/simple_dialog.h"
+
+guint
+pref_stash(pref_t *pref, gpointer unused _U_)
+{
+ g_log(NULL,G_LOG_LEVEL_INFO, "=stashing %s", pref->name);
+ switch (pref->type) {
+
+ case PREF_UINT:
+ pref->stashed_val.uint = *pref->varp.uint;
+ break;
+
+ case PREF_BOOL:
+ pref->stashed_val.boolval = *pref->varp.boolp;
+ break;
+
+ case PREF_ENUM:
+ pref->stashed_val.enumval = *pref->varp.enump;
+ break;
+
+ case PREF_STRING:
+ case PREF_FILENAME:
+ g_free(pref->stashed_val.string);
+ pref->stashed_val.string = g_strdup(*pref->varp.string);
+ break;
+
+ case PREF_RANGE:
+ g_free(pref->stashed_val.range);
+ pref->stashed_val.range = range_copy(*pref->varp.range);
+ break;
+
+ case PREF_COLOR:
+ g_log(NULL,G_LOG_LEVEL_INFO, "=stashing %s", pref->name);
+ pref->stashed_val.color = *pref->varp.colorp;
+ break;
+
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
+ }
+ return 0;
+}
+
+guint
+pref_unstash(pref_t *pref, gpointer changed_p)
+{
+ gboolean *pref_changed_p = changed_p;
+
+ /* Revert the preference to its saved value. */
+ switch (pref->type) {
+
+ case PREF_UINT:
+ if (*pref->varp.uint != pref->stashed_val.uint) {
+ *pref_changed_p = TRUE;
+ *pref->varp.uint = pref->stashed_val.uint;
+ }
+ break;
+
+ case PREF_BOOL:
+ if (*pref->varp.boolp != pref->stashed_val.boolval) {
+ *pref_changed_p = TRUE;
+ *pref->varp.boolp = pref->stashed_val.boolval;
+ }
+ break;
+
+ case PREF_ENUM:
+ if (*pref->varp.enump != pref->stashed_val.enumval) {
+ *pref_changed_p = TRUE;
+ *pref->varp.enump = pref->stashed_val.enumval;
+ }
+ break;
+
+ case PREF_STRING:
+ case PREF_FILENAME:
+ if (strcmp(*pref->varp.string, pref->stashed_val.string) != 0) {
+ *pref_changed_p = TRUE;
+ g_free((void *)*pref->varp.string);
+ *pref->varp.string = g_strdup(pref->stashed_val.string);
+ }
+ break;
+
+ case PREF_RANGE:
+ if (!ranges_are_equal(*pref->varp.range, pref->stashed_val.range)) {
+ *pref_changed_p = TRUE;
+ g_free(*pref->varp.range);
+ *pref->varp.range = range_copy(pref->stashed_val.range);
+ }
+ break;
+
+ case PREF_COLOR:
+ *pref->varp.colorp = pref->stashed_val.color;
+ break;
+
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
+ }
+ return 0;
+}
+
+void
+reset_stashed_pref(pref_t *pref) {
+ switch (pref->type) {
+
+ case PREF_UINT:
+ pref->stashed_val.uint = pref->default_val.uint;
+ break;
+
+ case PREF_BOOL:
+ pref->stashed_val.boolval = pref->default_val.boolval;
+ break;
+
+ case PREF_ENUM:
+ pref->stashed_val.enumval = pref->default_val.enumval;
+ break;
+
+ case PREF_STRING:
+ case PREF_FILENAME:
+ g_free(pref->stashed_val.string);
+ pref->stashed_val.string = g_strdup(pref->default_val.string);
+ break;
+
+ case PREF_RANGE:
+ g_free(pref->stashed_val.range);
+ pref->stashed_val.range = range_copy(pref->default_val.range);
+ break;
+
+ case PREF_COLOR:
+ memcpy(&pref->stashed_val.color, &pref->default_val.color, sizeof(color_t));
+ break;
+
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
+ }
+}
+
+guint
+pref_clean_stash(pref_t *pref, gpointer unused _U_)
+{
+ switch (pref->type) {
+
+ case PREF_UINT:
+ break;
+
+ case PREF_BOOL:
+ break;
+
+ case PREF_ENUM:
+ break;
+
+ case PREF_STRING:
+ case PREF_FILENAME:
+ if (pref->stashed_val.string != NULL) {
+ g_free(pref->stashed_val.string);
+ pref->stashed_val.string = NULL;
+ }
+ break;
+
+ case PREF_RANGE:
+ if (pref->stashed_val.range != NULL) {
+ g_free(pref->stashed_val.range);
+ pref->stashed_val.range = NULL;
+ }
+ break;
+
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_COLOR:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
+ }
+ return 0;
+}
+
+/* Fill in capture options with values from the preferences */
+void
+prefs_to_capture_opts(void)
+{
+#ifdef HAVE_LIBPCAP
+ /* Set promiscuous mode from the preferences setting. */
+ /* the same applies to other preferences settings as well. */
+ global_capture_opts.default_options.promisc_mode = prefs.capture_prom_mode;
+ global_capture_opts.use_pcapng = prefs.capture_pcap_ng;
+ global_capture_opts.show_info = prefs.capture_show_info;
+ global_capture_opts.real_time_mode = prefs.capture_real_time;
+ auto_scroll_live = prefs.capture_auto_scroll;
+#endif /* HAVE_LIBPCAP */
+}
+
+void
+prefs_main_write(void)
+{
+ int err;
+ char *pf_dir_path;
+ char *pf_path;
+
+ /* Create the directory that holds personal configuration files, if
+ necessary. */
+ if (create_persconffile_dir(&pf_dir_path) == -1) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Can't create directory\n\"%s\"\nfor preferences file: %s.", pf_dir_path,
+ g_strerror(errno));
+ g_free(pf_dir_path);
+ } else {
+ /* Write the preferencs out. */
+ err = write_prefs(&pf_path);
+ if (err != 0) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+ "Can't open preferences file\n\"%s\": %s.", pf_path,
+ g_strerror(err));
+ g_free(pf_path);
+ }
+ }
+
+#ifdef HAVE_AIRPCAP
+ /*
+ * Load the Wireshark decryption keys (just set) and save
+ * the changes to the adapters' registry
+ */
+ airpcap_load_decryption_keys(airpcap_if_list);
+#endif
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 2
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=2 tabstop=8 expandtab:
+ * :indentSize=2:tabSize=8:noTabs=true:
+ */