diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-06-17 08:41:41 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-06-18 00:46:50 +0000 |
commit | 9c28594529b79619643948128dc2bbbaa3dcbb0e (patch) | |
tree | 2bcff16babc1acceea9b0d83f7068c4b06f41443 /ui | |
parent | 2dd030d4f65286aad17f54c12b41471ec153ed4f (diff) | |
download | wireshark-9c28594529b79619643948128dc2bbbaa3dcbb0e.tar.gz |
Add a preferences editor frame.
This replaces the single preference editor dialog in the GTK+ UI.
Change-Id: I10e030981e9f7d1ec121811593586b65cf0797c5
Reviewed-on: https://code.wireshark.org/review/8966
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/CMakeLists.txt | 3 | ||||
-rw-r--r-- | ui/qt/Makefile.am | 2 | ||||
-rw-r--r-- | ui/qt/Makefile.common | 4 | ||||
-rw-r--r-- | ui/qt/Wireshark.pro | 3 | ||||
-rw-r--r-- | ui/qt/main_window.cpp | 8 | ||||
-rw-r--r-- | ui/qt/main_window.h | 3 | ||||
-rw-r--r-- | ui/qt/main_window.ui | 9 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 43 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 2 | ||||
-rw-r--r-- | ui/qt/packet_list.h | 1 | ||||
-rw-r--r-- | ui/qt/preference_editor_frame.cpp | 241 | ||||
-rw-r--r-- | ui/qt/preference_editor_frame.h | 84 | ||||
-rw-r--r-- | ui/qt/preference_editor_frame.ui | 104 | ||||
-rw-r--r-- | ui/qt/proto_tree.cpp | 2 | ||||
-rw-r--r-- | ui/qt/proto_tree.h | 1 | ||||
-rw-r--r-- | ui/qt/protocol_preferences_menu.cpp | 104 | ||||
-rw-r--r-- | ui/qt/protocol_preferences_menu.h | 4 |
17 files changed, 562 insertions, 56 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index bbe6f09113..91a13a2dab 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -82,6 +82,7 @@ set(WIRESHARK_QT_HEADERS packet_list.h packet_list_model.h packet_range_group_box.h + preference_editor_frame.h preferences_dialog.h print_dialog.h profile_dialog.h @@ -200,6 +201,7 @@ set(WIRESHARK_QT_SRC packet_list_model.cpp packet_list_record.cpp packet_range_group_box.cpp + preference_editor_frame.cpp preferences_dialog.cpp print_dialog.cpp profile_dialog.cpp @@ -303,6 +305,7 @@ set(WIRESHARK_QT_UI packet_dialog.ui packet_format_group_box.ui packet_range_group_box.ui + preference_editor_frame.ui preferences_dialog.ui print_dialog.ui profile_dialog.ui diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am index 9c3aacf77e..89e4ada4f5 100644 --- a/ui/qt/Makefile.am +++ b/ui/qt/Makefile.am @@ -194,6 +194,8 @@ packet_format_group_box.cpp packet_format_group_box.h: ui_packet_format_group_bo packet_range_group_box.cpp packet_range_group_box.h: ui_packet_range_group_box.h +preference_editor_frame.cpp preference_editor_frame.h: ui_preference_editor_frame.h + preferences_dialog.cpp preferences_dialog.h: ui_preferences_dialog.h print_dialog.cpp print_dialog.h: ui_print_dialog.h diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common index d9a46bd794..e01bfb4bc3 100644 --- a/ui/qt/Makefile.common +++ b/ui/qt/Makefile.common @@ -66,6 +66,7 @@ NODIST_GENERATED_HEADER_FILES = \ ui_packet_dialog.h \ ui_packet_format_group_box.h \ ui_packet_range_group_box.h \ + ui_preference_editor_frame.h \ ui_preferences_dialog.h \ ui_print_dialog.h \ ui_profile_dialog.h \ @@ -186,6 +187,7 @@ MOC_HDRS = \ packet_list.h \ packet_list_model.h \ packet_range_group_box.h \ + preference_editor_frame.h \ preferences_dialog.h \ print_dialog.h \ profile_dialog.h \ @@ -265,6 +267,7 @@ UI_FILES = \ packet_range_group_box.ui \ packet_comment_dialog.ui \ packet_dialog.ui \ + preference_editor_frame.ui \ preferences_dialog.ui \ print_dialog.ui \ profile_dialog.ui \ @@ -403,6 +406,7 @@ WIRESHARK_QT_SRC = \ packet_list_model.cpp \ packet_list_record.cpp \ packet_range_group_box.cpp \ + preference_editor_frame.cpp \ preferences_dialog.cpp \ print_dialog.cpp \ profile_dialog.cpp \ diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro index bb35bb3863..6c40828f69 100644 --- a/ui/qt/Wireshark.pro +++ b/ui/qt/Wireshark.pro @@ -242,6 +242,7 @@ FORMS += \ packet_dialog.ui \ packet_format_group_box.ui \ packet_range_group_box.ui \ + preference_editor_frame.ui \ preferences_dialog.ui \ print_dialog.ui \ profile_dialog.ui \ @@ -307,6 +308,7 @@ HEADERS += $$HEADERS_WS_C \ packet_comment_dialog.h \ packet_dialog.h \ packet_format_group_box.h \ + preference_editor_frame.h \ preferences_dialog.h \ print_dialog.h \ profile_dialog.h \ @@ -679,6 +681,7 @@ SOURCES += \ packet_list_model.cpp \ packet_list_record.cpp \ packet_range_group_box.cpp \ + preference_editor_frame.cpp \ preferences_dialog.cpp \ print_dialog.cpp \ profile_dialog.cpp \ diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index eabfae5711..9212c593c2 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -249,6 +249,7 @@ MainWindow::MainWindow(QWidget *parent) : main_ui_->statusBar, SLOT(pushTemporaryStatus(const QString&))); main_ui_->columnEditorFrame->hide(); + main_ui_->preferenceEditorFrame->hide(); #ifndef HAVE_LIBPCAP main_ui_->menuCapture->setEnabled(false); @@ -378,6 +379,9 @@ MainWindow::MainWindow(QWidget *parent) : connect(main_welcome_, SIGNAL(popFilterSyntaxStatus()), main_ui_->statusBar, SLOT(popFilterStatus())); + connect(main_ui_->preferenceEditorFrame, SIGNAL(showProtocolPreferences(QString)), + this, SLOT(showPreferencesDialog(QString))); + connect(this, SIGNAL(setCaptureFile(capture_file*)), main_ui_->searchFrame, SLOT(setCaptureFile(capture_file*))); connect(this, SIGNAL(setCaptureFile(capture_file*)), @@ -420,6 +424,8 @@ MainWindow::MainWindow(QWidget *parent) : this, SLOT(showPreferencesDialog(PreferencesDialog::PreferencesPane))); connect(packet_list_, SIGNAL(showProtocolPreferences(QString)), this, SLOT(showPreferencesDialog(QString))); + connect(packet_list_, SIGNAL(editProtocolPreference(preference*,pref_module*)), + main_ui_->preferenceEditorFrame, SLOT(editPreference(preference*,pref_module*))); connect(packet_list_, SIGNAL(editColumn(int)), this, SLOT(showColumnEditor(int))); connect(main_ui_->columnEditorFrame, SIGNAL(columnEdited()), packet_list_, SLOT(redrawVisiblePackets())); @@ -436,6 +442,8 @@ MainWindow::MainWindow(QWidget *parent) : this, SLOT(openPacketDialog(bool))); connect(proto_tree_, SIGNAL(showProtocolPreferences(QString)), this, SLOT(showPreferencesDialog(QString))); + connect(proto_tree_, SIGNAL(editProtocolPreference(preference*,pref_module*)), + main_ui_->preferenceEditorFrame, SLOT(editPreference(preference*,pref_module*))); connect(byte_view_tab_, SIGNAL(byteFieldHovered(const QString&)), main_ui_->statusBar, SLOT(pushByteStatus(const QString&))); diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 600142c438..fe5e4db731 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -59,6 +59,7 @@ #include "follow_stream_dialog.h" #include "preferences_dialog.h" +class AccordionFrame; class ByteViewTab; class MainWelcome; class PacketList; @@ -247,7 +248,9 @@ private slots: void captureFilterSyntaxChanged(bool valid); void redissectPackets(); void fieldsChanged(); + void showAccordionFrame(AccordionFrame *show_frame, bool toggle = false); void showColumnEditor(int column); + void showPreferenceEditor(); // module_t *, pref * void addStatsPluginsToMenu(); void addExternalMenus(); diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui index 74b922428e..06b6dbc601 100644 --- a/ui/qt/main_window.ui +++ b/ui/qt/main_window.ui @@ -95,6 +95,9 @@ <widget class="ColumnEditorFrame" name="columnEditorFrame"/> </item> <item> + <widget class="PreferenceEditorFrame" name="preferenceEditorFrame"/> + </item> + <item> <widget class="QStackedWidget" name="mainStack"> <property name="enabled"> <bool>true</bool> @@ -2376,6 +2379,12 @@ <header>column_editor_frame.h</header> <container>1</container> </customwidget> + <customwidget> + <class>PreferenceEditorFrame</class> + <extends>QFrame</extends> + <header>preference_editor_frame.h</header> + <container>1</container> + </customwidget> </customwidgets> <resources> <include location="../../image/toolbar.qrc"/> diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 2a6aa7309b..fabc408dd2 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1400,14 +1400,35 @@ void MainWindow::fieldsChanged() proto_free_deregistered_fields(); } +void MainWindow::showAccordionFrame(AccordionFrame *show_frame, bool toggle) +{ + QList<AccordionFrame *>frame_list = QList<AccordionFrame *>() + << main_ui_->goToFrame << main_ui_->searchFrame + << main_ui_->columnEditorFrame << main_ui_->preferenceEditorFrame; + + frame_list.removeAll(show_frame); + foreach (AccordionFrame *af, frame_list) af->animatedHide(); + + if (toggle) { + if (show_frame->isVisible()) { + show_frame->animatedHide(); + return; + } + } + show_frame->animatedShow(); +} + void MainWindow::showColumnEditor(int column) { previous_focus_ = wsApp->focusWidget(); connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus())); - main_ui_->goToFrame->animatedHide(); - main_ui_->searchFrame->animatedHide(); + showAccordionFrame(main_ui_->columnEditorFrame); main_ui_->columnEditorFrame->editColumn(column); - main_ui_->columnEditorFrame->animatedShow(); +} + +void MainWindow::showPreferenceEditor() +{ + showAccordionFrame(main_ui_->preferenceEditorFrame); } void MainWindow::addStatsPluginsToMenu() { @@ -1862,13 +1883,7 @@ void MainWindow::on_actionEditFindPacket_triggered() } previous_focus_ = wsApp->focusWidget(); connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus())); - main_ui_->goToFrame->animatedHide(); - main_ui_->columnEditorFrame->animatedHide(); - if (main_ui_->searchFrame->isVisible()) { - main_ui_->searchFrame->animatedHide(); - } else { - main_ui_->searchFrame->animatedShow(); - } + showAccordionFrame(main_ui_->searchFrame, true); } void MainWindow::on_actionEditFindNext_triggered() @@ -2933,15 +2948,11 @@ void MainWindow::on_actionGoGoToPacket_triggered() { previous_focus_ = wsApp->focusWidget(); connect(previous_focus_, SIGNAL(destroyed()), this, SLOT(resetPreviousFocus())); - main_ui_->searchFrame->animatedHide(); - main_ui_->columnEditorFrame->animatedHide(); + showAccordionFrame(main_ui_->goToFrame, true); if (main_ui_->goToFrame->isVisible()) { - main_ui_->goToFrame->animatedHide(); - } else { - main_ui_->goToFrame->animatedShow(); main_ui_->goToLineEdit->clear(); + main_ui_->goToLineEdit->setFocus(); } - main_ui_->goToLineEdit->setFocus(); } void MainWindow::on_actionGoAutoScroll_toggled(bool checked) diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 9240a142fc..c15f142d71 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -425,6 +425,8 @@ PacketList::PacketList(QWidget *parent) : connect(&proto_prefs_menu_, SIGNAL(showProtocolPreferences(QString)), this, SIGNAL(showProtocolPreferences(QString))); + connect(&proto_prefs_menu_, SIGNAL(editProtocolPreference(preference*,pref_module*)), + this, SIGNAL(editProtocolPreference(preference*,pref_module*))); } void PacketList::setProtoTree (ProtoTree *proto_tree) { diff --git a/ui/qt/packet_list.h b/ui/qt/packet_list.h index 206b8b5858..de08a228be 100644 --- a/ui/qt/packet_list.h +++ b/ui/qt/packet_list.h @@ -117,6 +117,7 @@ signals: void editColumn(int column); void packetListScrolled(bool at_end); void showProtocolPreferences(const QString module_name); + void editProtocolPreference(struct preference *pref, struct pref_module *module); public slots: void setCaptureFile(capture_file *cf); diff --git a/ui/qt/preference_editor_frame.cpp b/ui/qt/preference_editor_frame.cpp new file mode 100644 index 0000000000..794c9b5859 --- /dev/null +++ b/ui/qt/preference_editor_frame.cpp @@ -0,0 +1,241 @@ +/* preference_editor_frame.h + * + * 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 <glib.h> + +#include <epan/prefs.h> +#include <epan/prefs-int.h> + +#include <ui/preference_utils.h> + +#include "preference_editor_frame.h" +#include "ui_preference_editor_frame.h" + +#include "qt_ui_utils.h" + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +// Qt::escape +#include <QTextDocument> +#endif + +// To do: +// - Handle PREF_FILENAME and PREF_DIRNAME. + +PreferenceEditorFrame::PreferenceEditorFrame(QWidget *parent) : + AccordionFrame(parent), + ui(new Ui::PreferenceEditorFrame), + module_(NULL), + pref_(NULL) +{ + ui->setupUi(this); +} + +PreferenceEditorFrame::~PreferenceEditorFrame() +{ + delete ui; +} + +void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module) +{ + pref_ = pref; + module_ = module; + + if (!pref || !module) { + hide(); + return; + } + + ui->modulePreferencesToolButton->setText(tr("Open %1 preferences").arg(module_->title)); + + pref_stash(pref_, NULL); + ui->preferenceTitleLabel->setText(pref->title); + + // Convert the pref description from plain text to rich text. + QString description; +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + description = Qt::escape(pref->description); +#else + description = QString(pref->description).toHtmlEscaped(); +#endif + description.replace('\n', "<br>"); + QString tooltip = QString("<span>%1</span>").arg(description); + ui->preferenceTitleLabel->setToolTip(tooltip); + ui->preferenceLineEdit->setToolTip(tooltip); + + ui->preferenceLineEdit->clear(); + ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty); + disconnect(ui->preferenceLineEdit); + + bool show = false; + + switch (pref_->type) { + case PREF_UINT: + new_uint_ = pref->stashed_val.uint; + connect(ui->preferenceLineEdit, SIGNAL(textEdited(QString)), + this, SLOT(uintLineEditTextEdited(QString))); + show = true; + break; + case PREF_STRING: + new_str_ = pref->stashed_val.string; + connect(ui->preferenceLineEdit, SIGNAL(textEdited(QString)), + this, SLOT(stringLineEditTextEdited(QString))); + show = true; + break; + case PREF_RANGE: + g_free(new_range_); + new_range_ = range_copy(pref->stashed_val.range); + connect(ui->preferenceLineEdit, SIGNAL(textEdited(QString)), + this, SLOT(rangeLineEditTextEdited(QString))); + show = true; + break; + default: + break; + } + + if (show) { + ui->preferenceLineEdit->setText(gchar_free_to_qstring(prefs_pref_to_str(pref_, pref_stashed)).remove(QRegExp("\n\t"))); + animatedShow(); + } +} + +void PreferenceEditorFrame::uintLineEditTextEdited(const QString &new_str) +{ + if (new_str.isEmpty()) { + new_uint_ = pref_->stashed_val.uint; + ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty); + ui->okButton->setEnabled(true); + return; + } + + bool ok; + uint new_uint = new_str.toUInt(&ok); + if (ok) { + new_uint_ = new_uint; + ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Valid); + } else { + new_uint_ = pref_->stashed_val.uint; + ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Invalid); + } + ui->okButton->setEnabled(ok); +} + +void PreferenceEditorFrame::stringLineEditTextEdited(const QString &new_str) +{ + new_str_ = new_str; +} + +void PreferenceEditorFrame::rangeLineEditTextEdited(const QString &new_str) +{ + range_t *new_range = NULL; + + convert_ret_t ret = range_convert_str(&new_range, new_str.toUtf8().constData(), pref_->info.max_value); + g_free(new_range_); + new_range_ = new_range; + + if (ret == CVT_NO_ERROR) { + if (new_str.isEmpty()) { + ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty); + } else { + ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Valid); + } + } else { + ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Invalid); + } +} + +void PreferenceEditorFrame::on_modulePreferencesToolButton_clicked() +{ + on_cancelButton_clicked(); + if (module_) { + QString module_name = module_->name; + emit showProtocolPreferences(module_name); + } +} + +void PreferenceEditorFrame::on_preferenceLineEdit_returnPressed() +{ + if (ui->okButton->isEnabled()) { + on_okButton_clicked(); + } +} + +void PreferenceEditorFrame::on_okButton_clicked() +{ + bool apply = false; + switch(pref_->type) { + case PREF_UINT: + if (pref_->stashed_val.uint != new_uint_) { + pref_->stashed_val.uint = new_uint_; + apply = true; + } + break; + case PREF_STRING: + if (new_str_.compare(pref_->stashed_val.string) != 0) { + g_free(pref_->stashed_val.string); + pref_->stashed_val.string = qstring_strdup(new_str_); + apply = true; + } + break; + case PREF_RANGE: + if (!ranges_are_equal(pref_->stashed_val.range, new_range_)) { + g_free(pref_->stashed_val.range); + pref_->stashed_val.range = range_copy(new_range_); + apply = true; + } + break; + default: + break; + } + + if (apply && module_) { + pref_unstash(pref_, &module_->prefs_changed); + prefs_apply(module_); + if (!prefs.gui_use_pref_save) { + prefs_main_write(); + } + } + on_cancelButton_clicked(); +} + +void PreferenceEditorFrame::on_cancelButton_clicked() +{ + pref_ = NULL; + module_ = NULL; + g_free(new_range_); + new_range_ = NULL; + ui->preferenceLineEdit->clear(); + animatedHide(); +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/preference_editor_frame.h b/ui/qt/preference_editor_frame.h new file mode 100644 index 0000000000..d652572828 --- /dev/null +++ b/ui/qt/preference_editor_frame.h @@ -0,0 +1,84 @@ +/* preference_editor_frame.h + * + * 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. + */ + +#ifndef PREFERENCE_EDITOR_FRAME_H +#define PREFERENCE_EDITOR_FRAME_H + +#include "accordion_frame.h" + +struct pref_module; +struct preference; +struct epan_range; + +namespace Ui { +class PreferenceEditorFrame; +} + +class PreferenceEditorFrame : public AccordionFrame +{ + Q_OBJECT + +public: + explicit PreferenceEditorFrame(QWidget *parent = 0); + ~PreferenceEditorFrame(); + +public slots: + void editPreference(struct preference *pref = NULL, struct pref_module *module = NULL); + +signals: + void showProtocolPreferences(const QString module_name); + +private slots: + // Similar to ModulePreferencesScrollArea + void uintLineEditTextEdited(const QString &new_str); + void stringLineEditTextEdited(const QString &new_str); + void rangeLineEditTextEdited(const QString &new_str); + + void on_modulePreferencesToolButton_clicked(); + void on_preferenceLineEdit_returnPressed(); + void on_okButton_clicked(); + void on_cancelButton_clicked(); + +private: + Ui::PreferenceEditorFrame *ui; + + struct pref_module *module_; + struct preference *pref_; + + unsigned int new_uint_; + QString new_str_; + struct epan_range *new_range_; +}; + +#endif // PREFERENCE_EDITOR_FRAME_H + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/preference_editor_frame.ui b/ui/qt/preference_editor_frame.ui new file mode 100644 index 0000000000..37b47d1c81 --- /dev/null +++ b/ui/qt/preference_editor_frame.ui @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PreferenceEditorFrame</class> + <widget class="QFrame" name="PreferenceEditorFrame"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>458</width> + <height>22</height> + </rect> + </property> + <property name="windowTitle"> + <string>Frame</string> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0,0,0,0,0"> + <property name="topMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QToolButton" name="modulePreferencesToolButton"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>81</width> + <height>5</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="preferenceTitleLabel"> + <property name="text"> + <string>a preference</string> + </property> + </widget> + </item> + <item> + <widget class="SyntaxLineEdit" name="preferenceLineEdit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>13</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QToolButton" name="okButton"> + <property name="text"> + <string>OK</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="cancelButton"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>SyntaxLineEdit</class> + <extends>QLineEdit</extends> + <header>syntax_line_edit.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index e2848f41f3..05bd726ad4 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -272,6 +272,8 @@ ProtoTree::ProtoTree(QWidget *parent) : connect(&proto_prefs_menu_, SIGNAL(showProtocolPreferences(QString)), this, SIGNAL(showProtocolPreferences(QString))); + connect(&proto_prefs_menu_, SIGNAL(editProtocolPreference(preference*,pref_module*)), + this, SIGNAL(editProtocolPreference(preference*,pref_module*))); } void ProtoTree::clear() { diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h index 2114fccd7c..4bef897fff 100644 --- a/ui/qt/proto_tree.h +++ b/ui/qt/proto_tree.h @@ -60,6 +60,7 @@ signals: void goToPacket(int); void relatedFrame(int, ft_framenum_type_t); void showProtocolPreferences(const QString module_name); + void editProtocolPreference(struct preference *pref, struct pref_module *module); public slots: void setMonospaceFont(const QFont &mono_font); diff --git a/ui/qt/protocol_preferences_menu.cpp b/ui/qt/protocol_preferences_menu.cpp index ddc285cf93..fca9e22909 100644 --- a/ui/qt/protocol_preferences_menu.cpp +++ b/ui/qt/protocol_preferences_menu.cpp @@ -32,16 +32,34 @@ #include "protocol_preferences_menu.h" +#include "qt_ui_utils.h" #include "uat_dialog.h" #include "wireshark_application.h" // To do: -// - Add a PreferencesEditorFrame to the main window similar to -// menu_prefs_edit_dlg in the GTK+ UI. For now we just open the main -// preferences dialog. // - Elide really long items? +// - Handle PREF_FILENAME and PREF_DIRNAME. +// - Handle color prefs. -#include <QDebug> +class BoolPreferenceAction : public QAction +{ +public: + BoolPreferenceAction(pref_t *pref) : + QAction(NULL), + pref_(pref) + { + setText(pref_->title); + setCheckable(true); + setChecked(*pref->varp.boolp); + } + + void setBoolValue() { + *pref_->varp.boolp = isChecked(); + } + +private: + pref_t *pref_; +}; class EnumPreferenceAction : public QAction { @@ -88,11 +106,11 @@ private: pref_t *pref_; }; - -class PreferenceAction : public QAction +// Preference requires an external editor (PreferenceEditorFrame) +class EditorPreferenceAction : public QAction { public: - PreferenceAction(pref_t *pref) : + EditorPreferenceAction(pref_t *pref) : QAction(NULL), pref_(pref) { @@ -115,34 +133,20 @@ public: title.append(QString(": %1" UTF8_HORIZONTAL_ELLIPSIS).arg(QString::number(*pref->varp.uint, base))); break; } - case PREF_BOOL: - setCheckable(true); - setChecked(*pref->varp.boolp); - break; - case PREF_ENUM: - // We shoudn't be here. - break; case PREF_STRING: title.append(QString(": %1" UTF8_HORIZONTAL_ELLIPSIS).arg(*pref->varp.string)); break; - case PREF_UAT: - title.append(UTF8_HORIZONTAL_ELLIPSIS); + case PREF_RANGE: + title.append(QString(": %1" UTF8_HORIZONTAL_ELLIPSIS).arg(range_to_qstring(*pref->varp.range))); break; - case PREF_COLOR: // XXX Add an icon? - - case PREF_CUSTOM: // We shouldn't be here. - case PREF_STATIC_TEXT: - case PREF_OBSOLETE: default: + // We shouldn't be here. break; } setText(title); } - - void setBoolValue() { - *pref_->varp.boolp = isChecked(); - } + pref_t *pref() { return pref_; } private: pref_t *pref_; @@ -203,7 +207,7 @@ void ProtocolPreferencesMenu::setModule(const char *module_name) action = addAction(tr("Open %1 preferences" UTF8_HORIZONTAL_ELLIPSIS).arg(proto_name)); action->setData(QString(module_name)); - connect(action, SIGNAL(triggered(bool)), this, SLOT(protocolPreferencesTriggered())); + connect(action, SIGNAL(triggered(bool)), this, SLOT(modulePreferencesTriggered())); addSeparator(); @@ -213,6 +217,13 @@ void ProtocolPreferencesMenu::setModule(const char *module_name) void ProtocolPreferencesMenu::addMenuItem(preference *pref) { switch (pref->type) { + case PREF_BOOL: + { + BoolPreferenceAction *bpa = new BoolPreferenceAction(pref); + addAction(bpa); + connect(bpa, SIGNAL(triggered(bool)), this, SLOT(boolPreferenceTriggered())); + break; + } case PREF_ENUM: { QActionGroup *ag = new QActionGroup(this); @@ -227,6 +238,15 @@ void ProtocolPreferencesMenu::addMenuItem(preference *pref) } break; } + case PREF_UINT: + case PREF_STRING: + case PREF_RANGE: + { + EditorPreferenceAction *epa = new EditorPreferenceAction(pref); + addAction(epa); + connect(epa, SIGNAL(triggered(bool)), this, SLOT(editorPreferenceTriggered())); + break; + } case PREF_UAT: { UatPreferenceAction *upa = new UatPreferenceAction(pref); @@ -239,36 +259,42 @@ void ProtocolPreferencesMenu::addMenuItem(preference *pref) case PREF_OBSOLETE: break; default: - { - PreferenceAction *pa = new PreferenceAction(pref); - addAction(pa); - if (pref->type == PREF_BOOL) { - connect(pa, SIGNAL(triggered(bool)), this, SLOT(boolPreferenceTriggered())); - } else { - connect(pa, SIGNAL(triggered(bool)), this, SLOT(protocolPreferencesTriggered())); - } + // A type we currently don't handle (e.g. PREF_FILENAME). Just open + // the prefs dialog. + QString title = QString("%1" UTF8_HORIZONTAL_ELLIPSIS).arg(pref->title); + QAction *mpa = addAction(title); + connect(mpa, SIGNAL(triggered(bool)), this, SLOT(modulePreferencesTriggered())); break; } - } if (pref->type != PREF_ENUM) { } else { } } -void ProtocolPreferencesMenu::protocolPreferencesTriggered() +void ProtocolPreferencesMenu::modulePreferencesTriggered() { if (!module_name_.isEmpty()) { emit showProtocolPreferences(module_name_); } } +void ProtocolPreferencesMenu::editorPreferenceTriggered() +{ + EditorPreferenceAction *epa = static_cast<EditorPreferenceAction *>(QObject::sender()); + if (!epa) return; + + if (epa->pref() && module_) { + emit editProtocolPreference(epa->pref(), module_); + } +} + void ProtocolPreferencesMenu::boolPreferenceTriggered() { - PreferenceAction *pa = static_cast<PreferenceAction *>(QObject::sender()); - if (!pa) return; + BoolPreferenceAction *bpa = static_cast<BoolPreferenceAction *>(QObject::sender()); + if (!bpa) return; - pa->setBoolValue(); + bpa->setBoolValue(); prefs_apply(module_); if (!prefs.gui_use_pref_save) { diff --git a/ui/qt/protocol_preferences_menu.h b/ui/qt/protocol_preferences_menu.h index da39b61c94..d85855a4a7 100644 --- a/ui/qt/protocol_preferences_menu.h +++ b/ui/qt/protocol_preferences_menu.h @@ -39,13 +39,15 @@ public: signals: void showProtocolPreferences(const QString module_name); + void editProtocolPreference(struct preference *pref, struct pref_module *module); private: QString module_name_; struct pref_module *module_; private slots: - void protocolPreferencesTriggered(); + void modulePreferencesTriggered(); + void editorPreferenceTriggered(); void boolPreferenceTriggered(); void enumPreferenceTriggered(); void uatPreferenceTriggered(); |