diff options
author | Gerald Combs <gerald@wireshark.org> | 2013-02-08 18:07:34 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2013-02-08 18:07:34 +0000 |
commit | d21f62b73b84086173901da197fe15eaa4e9dcce (patch) | |
tree | d14fa98879d71abccd2c8f3003090565c1890326 | |
parent | c7525936983ae67912df1baffbddf60a2e69242b (diff) |
Add a directory name preference type (PREF_DIRNAME) and registration
routine (prefs_register_directory_preference). Add PREF_FILENAME and
PREF_DIRNAME support to the Qt module preferences. Change a couple of
preferences to directory names.
Clean up some names and default settings.
svn path=/trunk/; revision=47573
-rw-r--r-- | epan/dissectors/packet-etch.c | 6 | ||||
-rw-r--r-- | epan/dissectors/packet-kerberos.c | 2 | ||||
-rw-r--r-- | epan/libwireshark.def | 1 | ||||
-rw-r--r-- | epan/prefs-int.h | 3 | ||||
-rw-r--r-- | epan/prefs.c | 27 | ||||
-rw-r--r-- | epan/prefs.h | 9 | ||||
-rw-r--r-- | ui/gtk/prefs_dlg.c | 38 | ||||
-rw-r--r-- | ui/preference_utils.c | 4 | ||||
-rw-r--r-- | ui/qt/main_window_preferences_frame.ui | 2 | ||||
-rw-r--r-- | ui/qt/module_preferences_scroll_area.cpp | 98 | ||||
-rw-r--r-- | ui/qt/module_preferences_scroll_area.h | 2 | ||||
-rw-r--r-- | ui/qt/preferences_dialog.cpp | 17 |
12 files changed, 177 insertions, 32 deletions
diff --git a/epan/dissectors/packet-etch.c b/epan/dissectors/packet-etch.c index eb6884c5f6..4c0b22fe66 100644 --- a/epan/dissectors/packet-etch.c +++ b/epan/dissectors/packet-etch.c @@ -937,7 +937,7 @@ void proto_register_etch(void) }; proto_etch = proto_register_protocol("Apache Etch Protocol", /* name */ - "ETCH", /* short name */ + "Etch", /* short name */ "etch" /* abbrev */ ); @@ -950,14 +950,14 @@ void proto_register_etch(void) etch_module = prefs_register_protocol(proto_etch, proto_reg_handoff_etch); - prefs_register_string_preference(etch_module, "file", + prefs_register_directory_preference(etch_module, "file", "Apache Etch symbol folder", "Place the hash/symbol files " "(generated by the Apache Etch compiler) " "ending with .ewh here", &gbl_keytab_folder); prefs_register_uint_preference(etch_module, "tcp.port", - "etch TCP Port", + "Etch TCP Port", "Etch TCP port", 10, &gbl_etch_port); diff --git a/epan/dissectors/packet-kerberos.c b/epan/dissectors/packet-kerberos.c index a339ad4c9e..49df094702 100644 --- a/epan/dissectors/packet-kerberos.c +++ b/epan/dissectors/packet-kerberos.c @@ -384,7 +384,7 @@ call_kerberos_callbacks(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int gboolean krb_decrypt = FALSE; /* keytab filename */ -static const char *keytab_filename = "insert filename here"; +static const char *keytab_filename = ""; void read_keytab_file(const char *); diff --git a/epan/libwireshark.def b/epan/libwireshark.def index 75db51b5d8..8b24000988 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -743,6 +743,7 @@ prefs_pref_to_str prefs_pref_type_description prefs_pref_type_name prefs_register_bool_preference +prefs_register_directory_preference prefs_register_enum_preference prefs_register_filename_preference prefs_register_modules diff --git a/epan/prefs-int.h b/epan/prefs-int.h index 2da275397a..46c19429f0 100644 --- a/epan/prefs-int.h +++ b/epan/prefs-int.h @@ -102,7 +102,8 @@ typedef enum { PREF_FILENAME, PREF_COLOR, /* XXX - These are only supported for "internal" (non-protocol) */ PREF_CUSTOM, /* use and not as a generic protocol preference */ - PREF_OBSOLETE + PREF_OBSOLETE, + PREF_DIRNAME } pref_type_t; /** Struct to hold preference data */ diff --git a/epan/prefs.c b/epan/prefs.c index a8d30da05f..8e0c3feaa4 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -186,6 +186,7 @@ free_pref(gpointer data, gpointer user_data _U_) break; case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: g_free((char *)*pref->varp.string); *pref->varp.string = NULL; g_free(pref->default_val.string); @@ -978,6 +979,18 @@ prefs_register_filename_preference(module_t *module, const char *name, } /* + * Register a preference with a directory name (string) value. + */ +void +prefs_register_directory_preference(module_t *module, const char *name, + const char *title, const char *description, + const char **var) +{ + register_string_like_preference(module, name, title, description, var, + PREF_DIRNAME); +} + +/* * Register a preference with a ranged value. */ void @@ -1989,7 +2002,7 @@ prefs_register_modules(void) 10, &prefs.gui_recent_df_entries_max); - prefs_register_string_preference(gui_module, "fileopen.dir", "Start Directory", + prefs_register_directory_preference(gui_module, "fileopen.dir", "Start Directory", "Directory to start in when opening File Open dialog.", (const char**)(&prefs.gui_fileopen_dir)); prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir"); @@ -2714,6 +2727,7 @@ reset_pref(pref_t *pref) case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: g_free((void *)*pref->varp.string); *pref->varp.string = g_strdup(pref->default_val.string); break; @@ -3828,6 +3842,7 @@ set_pref(gchar *pref_name, const gchar *value, void *private_data _U_, case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: if (strcmp(*pref->varp.string, value) != 0) { module->prefs_changed = TRUE; g_free((void *)*pref->varp.string); @@ -3935,6 +3950,10 @@ prefs_pref_type_name(pref_t *pref) type_name = "Filename"; break; + case PREF_DIRNAME: + type_name = "Directory"; + break; + case PREF_RANGE: type_name = "Range"; break; @@ -4019,6 +4038,10 @@ prefs_pref_type_description(pref_t *pref) type_desc = "A path to a file"; break; + case PREF_DIRNAME: + type_desc = "A path to a directory"; + break; + case PREF_RANGE: { type_desc = "A string denoting an positive integer range (e.g., \"1-20,30-40\")"; @@ -4078,6 +4101,7 @@ prefs_pref_is_default(pref_t *pref) { case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: if (!(g_strcmp0(pref->default_val.string, *pref->varp.string))) return TRUE; break; @@ -4197,6 +4221,7 @@ prefs_pref_to_str(pref_t *pref, pref_source_t source) { case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: return g_strdup(pref_string); break; diff --git a/epan/prefs.h b/epan/prefs.h index 8b29860ca6..a2d569fadc 100644 --- a/epan/prefs.h +++ b/epan/prefs.h @@ -387,6 +387,15 @@ extern void prefs_register_filename_preference(module_t *module, const char *nam const char *title, const char *description, const char **var); /* + * Register a preference with a directory name (string) value. + * Directory name preferences are basically like string preferences + * except that the GUI gives the user the ability to browse for a + * directory. + */ +extern void prefs_register_directory_preference(module_t *module, const char *name, + const char *title, const char *description, const char **var); + +/* * Register a preference with a ranged value. */ extern void prefs_register_range_preference(module_t *module, const char *name, diff --git a/ui/gtk/prefs_dlg.c b/ui/gtk/prefs_dlg.c index f3a2189593..fb6236c425 100644 --- a/ui/gtk/prefs_dlg.c +++ b/ui/gtk/prefs_dlg.c @@ -76,8 +76,8 @@ static gboolean prefs_main_delete_event_cb(GtkWidget *, GdkEvent *, gpointer); static void prefs_main_destroy_cb(GtkWidget *, gpointer); static void prefs_tree_select_cb(GtkTreeSelection *, gpointer); -static GtkWidget *create_preference_filename_entry(GtkWidget *, int, - const gchar *, const gchar *, char *); +static GtkWidget *create_preference_path_entry(GtkWidget *, int, + const gchar *, const gchar *, char *, gboolean); #define E_PREFSW_SCROLLW_KEY "prefsw_scrollw" #define E_PREFSW_TREE_KEY "prefsw_tree" @@ -213,10 +213,17 @@ pref_show(pref_t *pref, gpointer user_data) break; case PREF_FILENAME: - pref->control = create_preference_filename_entry(main_grid, pref->ordinal, + pref->control = create_preference_path_entry(main_grid, pref->ordinal, label_string, tooltip_txt, - pref->stashed_val.string); + pref->stashed_val.string, FALSE); + break; + + case PREF_DIRNAME: + pref->control = create_preference_path_entry(main_grid, pref->ordinal, + label_string, + tooltip_txt, + pref->stashed_val.string, TRUE); break; case PREF_RANGE: @@ -839,13 +846,21 @@ static void preference_filename_entry_cb(GtkWidget *button, GtkWidget *filename_te) { /* XXX - use a better browser dialog title */ - file_selection_browse(button, filename_te, "Wireshark: file preference", + file_selection_browse(button, filename_te, "Wireshark: File preference", FILE_SELECTION_READ_BROWSE); } +static void +preference_dirname_entry_cb(GtkWidget *button, GtkWidget *filename_te) +{ + /* XXX - use a better browser dialog title */ + file_selection_browse(button, filename_te, "Wireshark: Directory preference", + FILE_SELECTION_CREATE_FOLDER); +} + static GtkWidget * -create_preference_filename_entry(GtkWidget *main_grid, int grid_position, - const gchar *label_text, const gchar *tooltip_text, char *value) +create_preference_path_entry(GtkWidget *main_grid, int grid_position, + const gchar *label_text, const gchar *tooltip_text, char *value, gboolean dir_only) { GtkWidget *entry; GtkWidget *button, *file_bt_hb; @@ -867,8 +882,11 @@ create_preference_filename_entry(GtkWidget *main_grid, int grid_position, gtk_widget_set_tooltip_text(entry, tooltip_text); gtk_widget_show(entry); - g_signal_connect(button, "clicked", G_CALLBACK(preference_filename_entry_cb), entry); - + if (dir_only) { + g_signal_connect(button, "clicked", G_CALLBACK(preference_dirname_entry_cb), entry); + } else { + g_signal_connect(button, "clicked", G_CALLBACK(preference_filename_entry_cb), entry); + } return entry; } @@ -956,6 +974,7 @@ pref_check(pref_t *pref, gpointer user_data) case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: /* Value can't be bad. */ break; @@ -1054,6 +1073,7 @@ pref_fetch(pref_t *pref, gpointer user_data) case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: str_val = gtk_entry_get_text(GTK_ENTRY(pref->control)); if (strcmp(*pref->varp.string, str_val) != 0) { *pref_changed_p = TRUE; diff --git a/ui/preference_utils.c b/ui/preference_utils.c index 29e403f5f8..005817a10c 100644 --- a/ui/preference_utils.c +++ b/ui/preference_utils.c @@ -61,6 +61,7 @@ pref_stash(pref_t *pref, gpointer unused _U_) case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: g_free(pref->stashed_val.string); pref->stashed_val.string = g_strdup(*pref->varp.string); break; @@ -117,6 +118,7 @@ pref_unstash(pref_t *pref, gpointer changed_p) case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: if (strcmp(*pref->varp.string, pref->stashed_val.string) != 0) { *pref_changed_p = TRUE; g_free((void *)*pref->varp.string); @@ -166,6 +168,7 @@ reset_stashed_pref(pref_t *pref) { case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: g_free(pref->stashed_val.string); pref->stashed_val.string = g_strdup(pref->default_val.string); break; @@ -206,6 +209,7 @@ pref_clean_stash(pref_t *pref, gpointer unused _U_) case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: if (pref->stashed_val.string != NULL) { g_free(pref->stashed_val.string); pref->stashed_val.string = NULL; diff --git a/ui/qt/main_window_preferences_frame.ui b/ui/qt/main_window_preferences_frame.ui index 7a4e8af51c..42646127c3 100644 --- a/ui/qt/main_window_preferences_frame.ui +++ b/ui/qt/main_window_preferences_frame.ui @@ -70,7 +70,7 @@ <item row="1" column="2"> <widget class="QPushButton" name="foStyleSpecifiedPushButton"> <property name="text"> - <string>Choose...</string> + <string>Browse...</string> </property> </widget> </item> diff --git a/ui/qt/module_preferences_scroll_area.cpp b/ui/qt/module_preferences_scroll_area.cpp index ada6e557d2..e30dbdbada 100644 --- a/ui/qt/module_preferences_scroll_area.cpp +++ b/ui/qt/module_preferences_scroll_area.cpp @@ -32,6 +32,7 @@ #include <QButtonGroup> #include <QCheckBox> #include <QComboBox> +#include <QFileDialog> #include <QHBoxLayout> #include <QLabel> #include <QLineEdit> @@ -152,6 +153,29 @@ pref_show(pref_t *pref, gpointer layout_ptr) vb->addLayout(hb); break; } + case PREF_FILENAME: + case PREF_DIRNAME: + { + vb->addWidget(new QLabel(pref->title)); + QHBoxLayout *hb = new QHBoxLayout(); + QLineEdit *path_le = new QLineEdit(); + QStyleOption style_opt; + path_le->setProperty(pref_prop_, qVariantFromValue(pref)); + path_le->setMinimumWidth(path_le->fontMetrics().height() * 20); + path_le->setStyleSheet(QString( + "QLineEdit {" + " margin-left: %1px;" + "}" + ) + .arg(path_le->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left())); + hb->addWidget(path_le); + QPushButton *path_pb = new QPushButton("Browse..."); + path_pb->setProperty(pref_prop_, qVariantFromValue(pref)); + hb->addWidget(path_pb); + hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum)); + vb->addLayout(hb); + break; + } case PREF_COLOR: { // XXX - Not needed yet. When it is needed we can add a label + QFrame which pops up a @@ -182,12 +206,20 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg pref_t *pref = le->property(pref_prop_).value<pref_t *>(); if (!pref) continue; - if (pref->type == PREF_UINT) { + switch (pref->type) { + case PREF_UINT: connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString))); - } else if (pref->type == PREF_STRING) { + break; + case PREF_STRING: + case PREF_FILENAME: + case PREF_DIRNAME: connect(le, SIGNAL(textEdited(QString)), this, SLOT(stringLineEditTextEdited(QString))); - } else if (pref->type == PREF_RANGE) { + break; + case PREF_RANGE: connect(le, SIGNAL(textEdited(QString)), this, SLOT(rangeSyntaxLineEditTextEdited(QString))); + break; + default: + break; } } @@ -200,30 +232,34 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg } } - foreach (QRadioButton *enum_rb, findChildren<QRadioButton *>()) { - pref_t *pref = enum_rb->property(pref_prop_).value<pref_t *>(); + foreach (QRadioButton *rb, findChildren<QRadioButton *>()) { + pref_t *pref = rb->property(pref_prop_).value<pref_t *>(); if (!pref) continue; if (pref->type == PREF_ENUM && pref->info.enum_info.radio_buttons) { - connect(enum_rb, SIGNAL(toggled(bool)), this, SLOT(enumRadioButtonToggled(bool))); + connect(rb, SIGNAL(toggled(bool)), this, SLOT(enumRadioButtonToggled(bool))); } } - foreach (QComboBox *enum_cb, findChildren<QComboBox *>()) { - pref_t *pref = enum_cb->property(pref_prop_).value<pref_t *>(); + foreach (QComboBox *combo, findChildren<QComboBox *>()) { + pref_t *pref = combo->property(pref_prop_).value<pref_t *>(); if (!pref) continue; if (pref->type == PREF_ENUM && !pref->info.enum_info.radio_buttons) { - connect(enum_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(enumComboBoxCurrentIndexChanged(int))); + connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(enumComboBoxCurrentIndexChanged(int))); } } - foreach (QPushButton *uat_pb, findChildren<QPushButton *>()) { - pref_t *pref = uat_pb->property(pref_prop_).value<pref_t *>(); + foreach (QPushButton *pb, findChildren<QPushButton *>()) { + pref_t *pref = pb->property(pref_prop_).value<pref_t *>(); if (!pref) continue; if (pref->type == PREF_UAT) { - connect(uat_pb, SIGNAL(pressed()), this, SLOT(uatPushButtonPressed())); + connect(pb, SIGNAL(pressed()), this, SLOT(uatPushButtonPressed())); + } else if (pref->type == PREF_FILENAME) { + connect(pb, SIGNAL(pressed()), this, SLOT(filenamePushButtonPressed())); + } else if (pref->type == PREF_DIRNAME) { + connect(pb, SIGNAL(pressed()), this, SLOT(dirnamePushButtonPressed())); } } @@ -400,6 +436,44 @@ void ModulePreferencesScrollArea::uatPushButtonPressed() qDebug() << "FIX Implement UATs:" << pref->title; } +void ModulePreferencesScrollArea::filenamePushButtonPressed() +{ + QPushButton *filename_pb = qobject_cast<QPushButton*>(sender()); + if (!filename_pb) return; + + pref_t *pref = filename_pb->property(pref_prop_).value<pref_t *>(); + if (!pref) return; + + QString filename = QFileDialog::getSaveFileName(this, + QString("Wireshark: ") + pref->description, + pref->stashed_val.string); + + if (!filename.isEmpty()) { + g_free((void *)pref->stashed_val.string); + pref->stashed_val.string = qstring_strdup(filename); + updateWidgets(); + } +} + +void ModulePreferencesScrollArea::dirnamePushButtonPressed() +{ + QPushButton *dirname_pb = qobject_cast<QPushButton*>(sender()); + if (!dirname_pb) return; + + pref_t *pref = dirname_pb->property(pref_prop_).value<pref_t *>(); + if (!pref) return; + + QString dirname = QFileDialog::getExistingDirectory(this, + QString("Wireshark: ") + pref->description, + pref->stashed_val.string); + + if (!dirname.isEmpty()) { + g_free((void *)pref->stashed_val.string); + pref->stashed_val.string = qstring_strdup(dirname); + updateWidgets(); + } +} + /* * Editor modelines * diff --git a/ui/qt/module_preferences_scroll_area.h b/ui/qt/module_preferences_scroll_area.h index 8a297ef86c..f5be4c7c1b 100644 --- a/ui/qt/module_preferences_scroll_area.h +++ b/ui/qt/module_preferences_scroll_area.h @@ -65,6 +65,8 @@ private slots: void stringLineEditTextEdited(const QString &new_str); void rangeSyntaxLineEditTextEdited(const QString &new_str); void uatPushButtonPressed(); + void filenamePushButtonPressed(); + void dirnamePushButtonPressed(); }; #endif // MODULE_PREFERENCES_SCROLL_AREA_H diff --git a/ui/qt/preferences_dialog.cpp b/ui/qt/preferences_dialog.cpp index 4c2da2c703..8332b37025 100644 --- a/ui/qt/preferences_dialog.cpp +++ b/ui/qt/preferences_dialog.cpp @@ -48,7 +48,6 @@ #include <QKeyEvent> #include <QLineEdit> #include <QMessageBox> -#include <QPushButton> #include <QSpacerItem> #include <QTreeWidgetItemIterator> @@ -427,6 +426,7 @@ bool PreferencesDialog::stashedPrefIsDefault(pref_t *pref) case PREF_STRING: case PREF_FILENAME: + case PREF_DIRNAME: if (!(g_strcmp0(pref->default_val.string, pref->stashed_val.string))) return true; break; @@ -597,10 +597,19 @@ void PreferencesDialog::on_advancedTree_itemActivated(QTreeWidgetItem *item, int break; } case PREF_FILENAME: + case PREF_DIRNAME: { - QString filename = QFileDialog::getSaveFileName(this, - QString("Wireshark: ") + pref->description, - pref->stashed_val.string); + QString filename; + + if (pref->type == PREF_FILENAME) { + filename = QFileDialog::getSaveFileName(this, + QString("Wireshark: ") + pref->description, + pref->stashed_val.string); + } else { + filename = QFileDialog::getExistingDirectory(this, + QString("Wireshark: ") + pref->description, + pref->stashed_val.string); + } if (!filename.isEmpty()) { g_free((void *)pref->stashed_val.string); pref->stashed_val.string = qstring_strdup(filename); |