1 /* main_window_preferences_frame.cpp
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "main_window_preferences_frame.h"
25 #include "ui_main_window_preferences_frame.h"
27 #include <epan/prefs-int.h>
29 #include <QFileDialog>
32 MainWindowPreferencesFrame::MainWindowPreferencesFrame(QWidget
*parent
) :
34 ui(new Ui::MainWindowPreferencesFrame
)
38 pref_geometry_save_position_
= prefFromPrefPtr(&prefs
.gui_geometry_save_position
);
39 pref_geometry_save_size_
= prefFromPrefPtr(&prefs
.gui_geometry_save_size
);
40 pref_geometry_save_maximized_
= prefFromPrefPtr(&prefs
.gui_geometry_save_maximized
);
41 pref_fileopen_style_
= prefFromPrefPtr(&prefs
.gui_fileopen_style
);
42 pref_fileopen_dir_
= prefFromPrefPtr(&prefs
.gui_fileopen_dir
);
43 pref_recent_df_entries_max_
= prefFromPrefPtr(&prefs
.gui_recent_df_entries_max
);
44 pref_recent_files_count_max_
= prefFromPrefPtr(&prefs
.gui_recent_files_count_max
);
45 pref_ask_unsaved_
= prefFromPrefPtr(&prefs
.gui_ask_unsaved
);
46 pref_auto_scroll_on_expand_
= prefFromPrefPtr(&prefs
.gui_auto_scroll_on_expand
);
47 pref_auto_scroll_percentage_
= prefFromPrefPtr(&prefs
.gui_auto_scroll_percentage
);
48 pref_toolbar_main_style_
= prefFromPrefPtr(&prefs
.gui_toolbar_main_style
);
49 pref_toolbar_filter_style_
= prefFromPrefPtr(&prefs
.gui_toolbar_filter_style
);
50 pref_qt_language_
= prefFromPrefPtr(&prefs
.gui_qt_language
);
52 QStyleOption style_opt
;
53 QString indent_ss
= QString(
54 "QRadioButton, QLineEdit, QLabel {"
57 ).arg(ui
->geometryCheckBox
->style()->subElementRect(QStyle::SE_CheckBoxContents
, &style_opt
).left());
58 ui
->foStyleLastOpenedRadioButton
->setStyleSheet(indent_ss
);
59 ui
->foStyleSpecifiedRadioButton
->setStyleSheet(indent_ss
);
60 ui
->maxFilterLineEdit
->setStyleSheet(indent_ss
);
61 ui
->maxRecentLineEdit
->setStyleSheet(indent_ss
);
63 ui
->autoScrollPercentageLabel
->setStyleSheet(indent_ss
);
65 int num_entry_width
= ui
->maxFilterLineEdit
->fontMetrics().height() * 3;
66 ui
->maxFilterLineEdit
->setMaximumWidth(num_entry_width
);
67 ui
->maxRecentLineEdit
->setMaximumWidth(num_entry_width
);
68 ui
->autoScrollPercentageLineEdit
->setMaximumWidth(num_entry_width
);
71 MainWindowPreferencesFrame::~MainWindowPreferencesFrame()
76 void MainWindowPreferencesFrame::showEvent(QShowEvent
*evt
)
82 void MainWindowPreferencesFrame::updateWidgets()
84 // Yes, this means we're potentially clobbering two prefs in favor of one.
85 if (pref_geometry_save_position_
->stashed_val
.boolval
|| pref_geometry_save_size_
->stashed_val
.boolval
|| pref_geometry_save_maximized_
->stashed_val
.boolval
) {
86 ui
->geometryCheckBox
->setChecked(true);
88 ui
->geometryCheckBox
->setChecked(false);
91 if (pref_fileopen_style_
->stashed_val
.enumval
== FO_STYLE_LAST_OPENED
) {
92 ui
->foStyleLastOpenedRadioButton
->setChecked(true);
94 ui
->foStyleSpecifiedRadioButton
->setChecked(true);
97 ui
->foStyleSpecifiedLineEdit
->setText(pref_fileopen_dir_
->stashed_val
.string
);
99 ui
->maxFilterLineEdit
->setText(QString::number(pref_recent_df_entries_max_
->stashed_val
.uint
));
100 ui
->maxRecentLineEdit
->setText(QString::number(pref_recent_files_count_max_
->stashed_val
.uint
));
102 ui
->autoScrollCheckBox
->setChecked(pref_auto_scroll_on_expand_
->stashed_val
.boolval
);
103 ui
->autoScrollPercentageLineEdit
->setText(QString::number(pref_auto_scroll_on_expand_
->stashed_val
.uint
));
105 ui
->mainToolbarComboBox
->setCurrentIndex(pref_toolbar_main_style_
->stashed_val
.enumval
);
106 ui
->filterToolbarComboBox
->setCurrentIndex(pref_toolbar_filter_style_
->stashed_val
.enumval
);
107 ui
->languageComboBox
->setCurrentIndex(pref_qt_language_
->stashed_val
.enumval
);
110 void MainWindowPreferencesFrame::on_geometryCheckBox_toggled(bool checked
)
112 pref_geometry_save_position_
->stashed_val
.boolval
= checked
;
113 pref_geometry_save_size_
->stashed_val
.boolval
= checked
;
114 pref_geometry_save_maximized_
->stashed_val
.boolval
= checked
;
117 void MainWindowPreferencesFrame::on_foStyleLastOpenedRadioButton_toggled(bool checked
)
120 pref_fileopen_style_
->stashed_val
.enumval
= FO_STYLE_LAST_OPENED
;
124 void MainWindowPreferencesFrame::on_foStyleSpecifiedRadioButton_toggled(bool checked
)
127 pref_fileopen_style_
->stashed_val
.enumval
= FO_STYLE_SPECIFIED
;
131 void MainWindowPreferencesFrame::on_foStyleSpecifiedLineEdit_textEdited(const QString
&new_dir
)
133 g_free(pref_fileopen_dir_
->stashed_val
.string
);
134 pref_fileopen_dir_
->stashed_val
.string
= g_strdup(new_dir
.toUtf8().constData());
135 pref_fileopen_style_
->stashed_val
.enumval
= FO_STYLE_SPECIFIED
;
139 void MainWindowPreferencesFrame::on_foStyleSpecifiedPushButton_clicked()
141 QString specified_dir
= QFileDialog::getExistingDirectory(this, tr("Open Files In"));
143 if (specified_dir
.isEmpty()) return;
145 ui
->foStyleSpecifiedLineEdit
->setText(specified_dir
);
146 g_free(pref_fileopen_dir_
->stashed_val
.string
);
147 pref_fileopen_dir_
->stashed_val
.string
= g_strdup(specified_dir
.toUtf8().constData());
148 pref_fileopen_style_
->stashed_val
.enumval
= FO_STYLE_SPECIFIED
;
152 void MainWindowPreferencesFrame::on_maxFilterLineEdit_textEdited(const QString
&new_max
)
154 pref_recent_df_entries_max_
->stashed_val
.uint
= new_max
.toUInt();
157 void MainWindowPreferencesFrame::on_maxRecentLineEdit_textEdited(const QString
&new_max
)
159 pref_recent_df_entries_max_
->stashed_val
.uint
= new_max
.toUInt();
162 void MainWindowPreferencesFrame::on_confirmUnsavedCheckBox_toggled(bool checked
)
164 pref_ask_unsaved_
->stashed_val
.boolval
= checked
;
167 void MainWindowPreferencesFrame::on_autoScrollCheckBox_toggled(bool checked
)
169 pref_auto_scroll_on_expand_
->stashed_val
.boolval
= checked
;
172 void MainWindowPreferencesFrame::on_autoScrollPercentageLineEdit_textEdited(const QString
&new_pct
)
174 pref_auto_scroll_percentage_
->stashed_val
.uint
= new_pct
.toUInt();
175 pref_auto_scroll_on_expand_
->stashed_val
.boolval
= TRUE
;
176 ui
->autoScrollCheckBox
->setChecked(true);
179 void MainWindowPreferencesFrame::on_mainToolbarComboBox_currentIndexChanged(int index
)
181 pref_toolbar_main_style_
->stashed_val
.enumval
= index
;
184 void MainWindowPreferencesFrame::on_filterToolbarComboBox_currentIndexChanged(int index
)
186 pref_toolbar_filter_style_
->stashed_val
.enumval
= index
;
189 void MainWindowPreferencesFrame::on_languageComboBox_currentIndexChanged(int index
)
191 pref_qt_language_
->stashed_val
.enumval
= index
;
200 * indent-tabs-mode: nil
203 * ex: set shiftwidth=4 tabstop=8 expandtab:
204 * :indentSize=4:tabSize=8:noTabs=true: