Qt: Fix preference change behavior.

Main window:

Keep track of our current layout and only change it if the preferences
change. This keeps the panes from resizing.

Re-select the current packet if the layout changes so that the proto
tree and byte view aren't left in an invalid state. This fixes a crash
similar to bug 10896.

Search frame:

Get rid of an invalid error message. Update coding style.

I don't think any of these fix bug 10921 since Xiaochuan seems to get a
crash immediately upon opening the dialog.

Change-Id: I0e880a50d3c9ac1c6ae6a01034b05fd2249444f4
Reviewed-on: https://code.wireshark.org/review/6989
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2015-02-06 10:36:27 -08:00
parent 3b3ce87899
commit b3f3dd8d82
5 changed files with 56 additions and 39 deletions

View File

@ -159,6 +159,7 @@ QMenu* MainWindow::findOrAddMenu(QMenu *parent_menu, QString& menu_text) {
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
main_ui_(new Ui::MainWindow),
cur_layout_(QVector<unsigned>()),
df_combo_box_(new DisplayFilterCombo()),
previous_focus_(NULL),
show_hide_actions_(NULL),

View File

@ -108,6 +108,7 @@ private:
QMenu *open_recent_menu_;
QSplitter master_split_;
QSplitter extra_split_;
QVector<unsigned> cur_layout_;
MainWelcome *main_welcome_;
DisplayFilterCombo *df_combo_box_;
CaptureFile capture_file_;

View File

@ -243,6 +243,12 @@ void MainWindow::filterPackets(QString& new_filter, bool force)
void MainWindow::layoutPanes()
{
QVector<unsigned> new_layout = QVector<unsigned>() << prefs.gui_layout_type
<< prefs.gui_layout_content_1
<< prefs.gui_layout_content_2
<< prefs.gui_layout_content_3;
if (cur_layout_ == new_layout) return;
QSplitter *parents[3];
// Reparent all widgets and add them back in the proper order below.
@ -253,6 +259,8 @@ void MainWindow::layoutPanes()
empty_pane_.setParent(main_ui_->mainStack);
extra_split_.setParent(main_ui_->mainStack);
// XXX We should try to preserve geometries if we can, e.g. by
// checking to see if the layout type is the same.
switch(prefs.gui_layout_type) {
case(layout_type_2):
case(layout_type_1):
@ -328,6 +336,10 @@ void MainWindow::layoutPanes()
}
widget->setVisible(show);
}
if (capture_file_.isValid() && capture_file_.capFile()->current_row >= 0) {
cf_select_packet(capture_file_.capFile(), capture_file_.capFile()->current_row);
}
cur_layout_ = new_layout;
}
void MainWindow::layoutToolbars()

View File

@ -29,17 +29,23 @@
#include <QKeyEvent>
#include <QCheckBox>
const int in_packet_list = 0;
const int in_proto_tree = 1;
const int in_bytes = 2;
enum {
in_packet_list_,
in_proto_tree_,
in_bytes_
};
const int df_search = 0;
const int hex_search = 1;
const int string_search = 2;
enum {
df_search_,
hex_search_,
string_search_
};
const int narrow_and_wide_chars = 0;
const int narrow_chars = 1;
const int wide_chars = 2;
enum {
narrow_and_wide_chars_,
narrow_chars_,
wide_chars_
};
SearchFrame::SearchFrame(QWidget *parent) :
AccordionFrame(parent),
@ -53,8 +59,8 @@ SearchFrame::SearchFrame(QWidget *parent) :
w->setAttribute(Qt::WA_MacSmallSize, true);
}
#endif
sf_ui_->searchTypeComboBox->setCurrentIndex(0);
enableWidgets();
sf_ui_->searchTypeComboBox->setCurrentIndex(df_search_);
updateWidgets();
}
SearchFrame::~SearchFrame()
@ -99,15 +105,15 @@ void SearchFrame::setCaptureFile(capture_file *cf)
if (!cf && isVisible()) {
animatedHide();
}
enableWidgets();
updateWidgets();
}
void SearchFrame::findFrameWithFilter(QString &filter)
{
animatedShow();
sf_ui_->searchLineEdit->setText(filter);
sf_ui_->searchTypeComboBox->setCurrentIndex(0);
enableWidgets();
sf_ui_->searchTypeComboBox->setCurrentIndex(df_search_);
updateWidgets();
}
void SearchFrame::keyPressEvent(QKeyEvent *event)
@ -124,7 +130,7 @@ void SearchFrame::keyPressEvent(QKeyEvent *event)
}
}
void SearchFrame::enableWidgets()
void SearchFrame::updateWidgets()
{
if (cap_file_) {
setEnabled(true);
@ -133,16 +139,16 @@ void SearchFrame::enableWidgets()
return;
}
bool enable = sf_ui_->searchTypeComboBox->currentIndex() == string_search;
bool enable = sf_ui_->searchTypeComboBox->currentIndex() == string_search_;
sf_ui_->searchInComboBox->setEnabled(enable);
sf_ui_->caseCheckBox->setEnabled(enable);
sf_ui_->charEncodingComboBox->setEnabled(enable);
switch (sf_ui_->searchTypeComboBox->currentIndex()) {
case df_search:
case df_search_:
sf_ui_->searchLineEdit->checkDisplayFilter(sf_ui_->searchLineEdit->text());
break;
case hex_search:
case hex_search_:
if (sf_ui_->searchLineEdit->text().isEmpty()) {
sf_ui_->searchLineEdit->setSyntaxState(SyntaxLineEdit::Invalid);
} else {
@ -157,7 +163,7 @@ void SearchFrame::enableWidgets()
}
}
break;
case string_search:
case string_search_:
if (sf_ui_->searchLineEdit->text().isEmpty()) {
sf_ui_->searchLineEdit->setSyntaxState(SyntaxLineEdit::Invalid);
} else {
@ -165,8 +171,7 @@ void SearchFrame::enableWidgets()
}
break;
default:
QString err_string = tr("No valid search type selected. Please report this to the development team.");
emit pushFilterSyntaxStatus(err_string);
// currentIndex is probably -1. Nothing is selected or list is empty.
return;
}
@ -177,16 +182,14 @@ void SearchFrame::enableWidgets()
}
}
void SearchFrame::on_searchTypeComboBox_currentIndexChanged(int index)
void SearchFrame::on_searchTypeComboBox_currentIndexChanged(int)
{
Q_UNUSED(index);
enableWidgets();
updateWidgets();
}
void SearchFrame::on_searchLineEdit_textChanged(const QString &search_string)
void SearchFrame::on_searchLineEdit_textChanged(const QString &)
{
Q_UNUSED(search_string);
enableWidgets();
updateWidgets();
}
void SearchFrame::on_findButton_clicked()
@ -211,7 +214,7 @@ void SearchFrame::on_findButton_clicked()
cap_file_->scs_type = SCS_NARROW_AND_WIDE;
switch (sf_ui_->searchTypeComboBox->currentIndex()) {
case df_search:
case df_search_:
if (!dfilter_compile(sf_ui_->searchLineEdit->text().toUtf8().constData(), &dfp, NULL)) {
err_string = tr("Invalid filter.");
emit pushFilterSyntaxStatus(err_string);
@ -224,7 +227,7 @@ void SearchFrame::on_findButton_clicked()
return;
}
break;
case hex_search:
case hex_search_:
bytes = convert_string_to_hex(sf_ui_->searchLineEdit->text().toUtf8().constData(), &nbytes);
if (bytes == NULL) {
err_string = tr("That's not a valid hex string.");
@ -233,7 +236,7 @@ void SearchFrame::on_findButton_clicked()
}
cap_file_->hex = TRUE;
break;
case string_search:
case string_search_:
if (sf_ui_->searchLineEdit->text().isEmpty()) {
err_string = tr("You didn't specify any text for which to search.");
emit pushFilterSyntaxStatus(err_string);
@ -242,13 +245,13 @@ void SearchFrame::on_findButton_clicked()
cap_file_->string = TRUE;
cap_file_->case_type = sf_ui_->caseCheckBox->isChecked() ? FALSE : TRUE;
switch (sf_ui_->charEncodingComboBox->currentIndex()) {
case narrow_and_wide_chars:
case narrow_and_wide_chars_:
cap_file_->scs_type = SCS_NARROW_AND_WIDE;
break;
case narrow_chars:
case narrow_chars_:
cap_file_->scs_type = SCS_NARROW;
break;
case wide_chars:
case wide_chars_:
cap_file_->scs_type = SCS_WIDE;
break;
default:
@ -265,13 +268,13 @@ void SearchFrame::on_findButton_clicked()
}
switch (sf_ui_->searchInComboBox->currentIndex()) {
case in_packet_list:
case in_packet_list_:
cap_file_->summary_data = TRUE;
break;
case in_proto_tree:
case in_proto_tree_:
cap_file_->decode_data = TRUE;
break;
case in_bytes:
case in_bytes_:
cap_file_->packet_data = TRUE;
break;
default:

View File

@ -54,14 +54,14 @@ protected:
void keyPressEvent(QKeyEvent *event);
private:
void enableWidgets();
void updateWidgets();
Ui::SearchFrame *sf_ui_;
capture_file *cap_file_;
private slots:
void on_searchTypeComboBox_currentIndexChanged(int index);
void on_searchLineEdit_textChanged(const QString &search_string);
void on_searchTypeComboBox_currentIndexChanged(int);
void on_searchLineEdit_textChanged(const QString &);
void on_findButton_clicked();
void on_cancelButton_clicked();
void changeEvent(QEvent* event);