2013-02-08 01:16:46 +00:00
|
|
|
/* module_preferences_scroll_area.cpp
|
|
|
|
*
|
|
|
|
* 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 "module_preferences_scroll_area.h"
|
2015-06-25 16:17:03 +00:00
|
|
|
#include <ui_module_preferences_scroll_area.h>
|
2017-07-05 14:56:45 +00:00
|
|
|
#include <ui/qt/widgets/syntax_line_edit.h>
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/qt_ui_utils.h>
|
2013-07-25 23:49:47 +00:00
|
|
|
#include "uat_dialog.h"
|
2014-12-31 22:21:50 +00:00
|
|
|
#include "wireshark_application.h"
|
2013-02-08 01:16:46 +00:00
|
|
|
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/variant_pointer.h>
|
2017-01-11 12:55:23 +00:00
|
|
|
|
2013-02-08 01:16:46 +00:00
|
|
|
#include <epan/prefs-int.h>
|
|
|
|
|
2015-10-04 17:10:29 +00:00
|
|
|
#include <wsutil/utf8_entities.h>
|
2015-07-31 17:34:43 +00:00
|
|
|
|
2013-02-08 01:16:46 +00:00
|
|
|
#include <QAbstractButton>
|
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
2013-02-08 18:07:34 +00:00
|
|
|
#include <QFileDialog>
|
2013-02-08 01:16:46 +00:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QSpacerItem>
|
|
|
|
|
|
|
|
const char *pref_prop_ = "pref_ptr";
|
|
|
|
|
2015-02-24 18:31:29 +00:00
|
|
|
// Escape our ampersands so that Qt won't try to interpret them as
|
|
|
|
// mnemonics.
|
|
|
|
static const QString title_to_shortcut(const char *title) {
|
|
|
|
QString shortcut_str(title);
|
|
|
|
shortcut_str.replace('&', "&&");
|
|
|
|
return shortcut_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-08 01:16:46 +00:00
|
|
|
extern "C" {
|
|
|
|
// Callbacks prefs routines
|
|
|
|
|
2016-09-29 18:25:52 +00:00
|
|
|
/* Add a single preference to the QVBoxLayout of a preference page */
|
2013-02-08 01:16:46 +00:00
|
|
|
static guint
|
|
|
|
pref_show(pref_t *pref, gpointer layout_ptr)
|
|
|
|
{
|
|
|
|
QVBoxLayout *vb = static_cast<QVBoxLayout *>(layout_ptr);
|
|
|
|
|
|
|
|
if (!pref || !vb) return 0;
|
2015-05-27 23:15:03 +00:00
|
|
|
|
|
|
|
// Convert the pref description from plain text to rich text.
|
2017-01-07 13:52:23 +00:00
|
|
|
QString description = html_escape(prefs_get_description(pref));
|
2015-05-27 23:15:03 +00:00
|
|
|
description.replace('\n', "<br>");
|
|
|
|
QString tooltip = QString("<span>%1</span>").arg(description);
|
2013-02-08 01:16:46 +00:00
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
switch (prefs_get_type(pref)) {
|
2013-02-08 01:16:46 +00:00
|
|
|
case PREF_UINT:
|
2016-10-07 20:25:01 +00:00
|
|
|
case PREF_DECODE_AS_UINT:
|
2013-02-08 01:16:46 +00:00
|
|
|
{
|
|
|
|
QHBoxLayout *hb = new QHBoxLayout();
|
2017-01-07 13:52:23 +00:00
|
|
|
QLabel *label = new QLabel(prefs_get_title(pref));
|
2013-12-14 00:07:27 +00:00
|
|
|
label->setToolTip(tooltip);
|
|
|
|
hb->addWidget(label);
|
2013-02-08 01:16:46 +00:00
|
|
|
QLineEdit *uint_le = new QLineEdit();
|
2013-12-14 00:07:27 +00:00
|
|
|
uint_le->setToolTip(tooltip);
|
2017-01-11 12:55:23 +00:00
|
|
|
uint_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 01:16:46 +00:00
|
|
|
uint_le->setMinimumWidth(uint_le->fontMetrics().height() * 8);
|
|
|
|
hb->addWidget(uint_le);
|
|
|
|
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
vb->addLayout(hb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_BOOL:
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
QCheckBox *bool_cb = new QCheckBox(title_to_shortcut(prefs_get_title(pref)));
|
2013-12-14 00:07:27 +00:00
|
|
|
bool_cb->setToolTip(tooltip);
|
2017-01-11 12:55:23 +00:00
|
|
|
bool_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 01:16:46 +00:00
|
|
|
vb->addWidget(bool_cb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_ENUM:
|
|
|
|
{
|
|
|
|
const enum_val_t *ev;
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_enumvals(pref) == NULL) return 0;
|
2013-02-08 01:16:46 +00:00
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_enum_radiobuttons(pref)) {
|
|
|
|
QLabel *label = new QLabel(prefs_get_title(pref));
|
2013-12-14 00:07:27 +00:00
|
|
|
label->setToolTip(tooltip);
|
|
|
|
vb->addWidget(label);
|
2015-10-04 09:31:19 +00:00
|
|
|
QButtonGroup *enum_bg = new QButtonGroup(vb);
|
2017-01-07 13:52:23 +00:00
|
|
|
for (ev = prefs_get_enumvals(pref); ev && ev->description; ev++) {
|
2015-02-24 18:31:29 +00:00
|
|
|
QRadioButton *enum_rb = new QRadioButton(title_to_shortcut(ev->description));
|
2013-12-14 00:07:27 +00:00
|
|
|
enum_rb->setToolTip(tooltip);
|
2013-02-08 01:16:46 +00:00
|
|
|
QStyleOption style_opt;
|
2017-01-11 12:55:23 +00:00
|
|
|
enum_rb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 01:16:46 +00:00
|
|
|
enum_rb->setStyleSheet(QString(
|
|
|
|
"QRadioButton {"
|
|
|
|
" margin-left: %1px;"
|
|
|
|
"}"
|
|
|
|
)
|
|
|
|
.arg(enum_rb->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
|
|
|
|
enum_bg->addButton(enum_rb, ev->value);
|
|
|
|
vb->addWidget(enum_rb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QHBoxLayout *hb = new QHBoxLayout();
|
|
|
|
QComboBox *enum_cb = new QComboBox();
|
2013-12-14 00:07:27 +00:00
|
|
|
enum_cb->setToolTip(tooltip);
|
2017-01-11 12:55:23 +00:00
|
|
|
enum_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2017-01-07 13:52:23 +00:00
|
|
|
for (ev = prefs_get_enumvals(pref); ev && ev->description; ev++) {
|
2013-02-08 01:16:46 +00:00
|
|
|
enum_cb->addItem(ev->description, QVariant(ev->value));
|
|
|
|
}
|
2017-01-07 13:52:23 +00:00
|
|
|
hb->addWidget(new QLabel(prefs_get_title(pref)));
|
2013-02-08 01:16:46 +00:00
|
|
|
hb->addWidget(enum_cb);
|
|
|
|
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
vb->addLayout(hb);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_STRING:
|
|
|
|
{
|
|
|
|
QHBoxLayout *hb = new QHBoxLayout();
|
2017-01-07 13:52:23 +00:00
|
|
|
QLabel *label = new QLabel(prefs_get_title(pref));
|
2013-12-14 00:07:27 +00:00
|
|
|
label->setToolTip(tooltip);
|
|
|
|
hb->addWidget(label);
|
2013-02-08 01:16:46 +00:00
|
|
|
QLineEdit *string_le = new QLineEdit();
|
2013-12-14 00:07:27 +00:00
|
|
|
string_le->setToolTip(tooltip);
|
2017-01-11 12:55:23 +00:00
|
|
|
string_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 01:16:46 +00:00
|
|
|
string_le->setMinimumWidth(string_le->fontMetrics().height() * 20);
|
|
|
|
hb->addWidget(string_le);
|
|
|
|
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
vb->addLayout(hb);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-07 20:25:01 +00:00
|
|
|
case PREF_DECODE_AS_RANGE:
|
2013-02-08 01:16:46 +00:00
|
|
|
case PREF_RANGE:
|
|
|
|
{
|
|
|
|
QHBoxLayout *hb = new QHBoxLayout();
|
2017-01-07 13:52:23 +00:00
|
|
|
QLabel *label = new QLabel(prefs_get_title(pref));
|
2013-12-14 00:07:27 +00:00
|
|
|
label->setToolTip(tooltip);
|
|
|
|
hb->addWidget(label);
|
2013-02-08 01:16:46 +00:00
|
|
|
SyntaxLineEdit *range_se = new SyntaxLineEdit();
|
2013-12-14 00:07:27 +00:00
|
|
|
range_se->setToolTip(tooltip);
|
2017-01-11 12:55:23 +00:00
|
|
|
range_se->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 01:16:46 +00:00
|
|
|
range_se->setMinimumWidth(range_se->fontMetrics().height() * 20);
|
|
|
|
hb->addWidget(range_se);
|
|
|
|
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
vb->addLayout(hb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_STATIC_TEXT:
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
QLabel *label = new QLabel(prefs_get_title(pref));
|
2013-12-14 00:07:27 +00:00
|
|
|
label->setToolTip(tooltip);
|
2016-09-12 08:53:16 +00:00
|
|
|
label->setWordWrap(true);
|
2013-12-14 00:07:27 +00:00
|
|
|
vb->addWidget(label);
|
2013-02-08 01:16:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_UAT:
|
|
|
|
{
|
|
|
|
QHBoxLayout *hb = new QHBoxLayout();
|
2017-01-07 13:52:23 +00:00
|
|
|
QLabel *label = new QLabel(prefs_get_title(pref));
|
2013-12-14 00:07:27 +00:00
|
|
|
label->setToolTip(tooltip);
|
|
|
|
hb->addWidget(label);
|
2015-07-31 17:34:43 +00:00
|
|
|
QPushButton *uat_pb = new QPushButton(QObject::tr("Edit" UTF8_HORIZONTAL_ELLIPSIS));
|
2013-12-14 00:07:27 +00:00
|
|
|
uat_pb->setToolTip(tooltip);
|
2017-01-11 12:55:23 +00:00
|
|
|
uat_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 01:16:46 +00:00
|
|
|
hb->addWidget(uat_pb);
|
|
|
|
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
vb->addLayout(hb);
|
|
|
|
break;
|
|
|
|
}
|
2017-04-14 09:33:57 +00:00
|
|
|
case PREF_SAVE_FILENAME:
|
|
|
|
case PREF_OPEN_FILENAME:
|
2013-02-08 18:07:34 +00:00
|
|
|
case PREF_DIRNAME:
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
QLabel *label = new QLabel(prefs_get_title(pref));
|
2013-12-14 00:07:27 +00:00
|
|
|
label->setToolTip(tooltip);
|
|
|
|
vb->addWidget(label);
|
2013-02-08 18:07:34 +00:00
|
|
|
QHBoxLayout *hb = new QHBoxLayout();
|
|
|
|
QLineEdit *path_le = new QLineEdit();
|
2013-12-14 00:07:27 +00:00
|
|
|
path_le->setToolTip(tooltip);
|
2013-02-08 18:07:34 +00:00
|
|
|
QStyleOption style_opt;
|
2017-01-11 12:55:23 +00:00
|
|
|
path_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 18:07:34 +00:00
|
|
|
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);
|
2015-07-31 17:34:43 +00:00
|
|
|
QPushButton *path_pb = new QPushButton(QObject::tr("Browse" UTF8_HORIZONTAL_ELLIPSIS));
|
2017-01-11 12:55:23 +00:00
|
|
|
path_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
|
2013-02-08 18:07:34 +00:00
|
|
|
hb->addWidget(path_pb);
|
|
|
|
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
vb->addLayout(hb);
|
|
|
|
break;
|
|
|
|
}
|
2013-02-08 01:16:46 +00:00
|
|
|
case PREF_COLOR:
|
|
|
|
{
|
|
|
|
// XXX - Not needed yet. When it is needed we can add a label + QFrame which pops up a
|
|
|
|
// color picker similar to the Font and Colors prefs.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidget *parent) :
|
|
|
|
QScrollArea(parent),
|
|
|
|
ui(new Ui::ModulePreferencesScrollArea),
|
|
|
|
module_(module)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
if (!module) return;
|
|
|
|
|
2014-11-21 23:23:24 +00:00
|
|
|
/* Show the preference's description at the top of the page */
|
|
|
|
QFont font;
|
|
|
|
font.setBold(TRUE);
|
|
|
|
QLabel *label = new QLabel(module->description);
|
|
|
|
label->setFont(font);
|
|
|
|
ui->verticalLayout->addWidget(label);
|
|
|
|
|
2013-02-08 01:16:46 +00:00
|
|
|
/* Add items for each of the preferences */
|
|
|
|
prefs_pref_foreach(module, pref_show, (gpointer) ui->verticalLayout);
|
|
|
|
|
|
|
|
foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(le->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
switch (prefs_get_type(pref)) {
|
2016-10-07 20:25:01 +00:00
|
|
|
case PREF_DECODE_AS_UINT:
|
|
|
|
connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString)));
|
|
|
|
break;
|
2013-02-08 18:07:34 +00:00
|
|
|
case PREF_UINT:
|
2013-02-08 01:16:46 +00:00
|
|
|
connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString)));
|
2013-02-08 18:07:34 +00:00
|
|
|
break;
|
|
|
|
case PREF_STRING:
|
2017-04-14 09:33:57 +00:00
|
|
|
case PREF_SAVE_FILENAME:
|
|
|
|
case PREF_OPEN_FILENAME:
|
2013-02-08 18:07:34 +00:00
|
|
|
case PREF_DIRNAME:
|
2013-02-08 01:16:46 +00:00
|
|
|
connect(le, SIGNAL(textEdited(QString)), this, SLOT(stringLineEditTextEdited(QString)));
|
2013-02-08 18:07:34 +00:00
|
|
|
break;
|
|
|
|
case PREF_RANGE:
|
2016-10-07 20:25:01 +00:00
|
|
|
case PREF_DECODE_AS_RANGE:
|
2013-02-08 01:16:46 +00:00
|
|
|
connect(le, SIGNAL(textEdited(QString)), this, SLOT(rangeSyntaxLineEditTextEdited(QString)));
|
2013-02-08 18:07:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(cb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_type(pref) == PREF_BOOL) {
|
2013-02-08 01:16:46 +00:00
|
|
|
connect(cb, SIGNAL(toggled(bool)), this, SLOT(boolCheckBoxToggled(bool)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:07:34 +00:00
|
|
|
foreach (QRadioButton *rb, findChildren<QRadioButton *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(rb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_type(pref) == PREF_ENUM && prefs_get_enum_radiobuttons(pref)) {
|
2013-02-08 18:07:34 +00:00
|
|
|
connect(rb, SIGNAL(toggled(bool)), this, SLOT(enumRadioButtonToggled(bool)));
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:07:34 +00:00
|
|
|
foreach (QComboBox *combo, findChildren<QComboBox *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(combo->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_type(pref) == PREF_ENUM && !prefs_get_enum_radiobuttons(pref)) {
|
2013-02-08 18:07:34 +00:00
|
|
|
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(enumComboBoxCurrentIndexChanged(int)));
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:07:34 +00:00
|
|
|
foreach (QPushButton *pb, findChildren<QPushButton *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(pb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
switch (prefs_get_type(pref)) {
|
|
|
|
case PREF_UAT:
|
2013-02-08 18:07:34 +00:00
|
|
|
connect(pb, SIGNAL(pressed()), this, SLOT(uatPushButtonPressed()));
|
2017-01-07 13:52:23 +00:00
|
|
|
break;
|
2017-04-14 09:33:57 +00:00
|
|
|
case PREF_SAVE_FILENAME:
|
|
|
|
connect(pb, SIGNAL(pressed()), this, SLOT(saveFilenamePushButtonPressed()));
|
|
|
|
break;
|
|
|
|
case PREF_OPEN_FILENAME:
|
|
|
|
connect(pb, SIGNAL(pressed()), this, SLOT(openFilenamePushButtonPressed()));
|
2017-01-07 13:52:23 +00:00
|
|
|
break;
|
|
|
|
case PREF_DIRNAME:
|
2013-02-08 18:07:34 +00:00
|
|
|
connect(pb, SIGNAL(pressed()), this, SLOT(dirnamePushButtonPressed()));
|
2017-01-07 13:52:23 +00:00
|
|
|
break;
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->verticalLayout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
|
|
|
}
|
|
|
|
|
|
|
|
ModulePreferencesScrollArea::~ModulePreferencesScrollArea()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2015-02-24 18:31:29 +00:00
|
|
|
void ModulePreferencesScrollArea::showEvent(QShowEvent *)
|
2013-02-08 01:16:46 +00:00
|
|
|
{
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::resizeEvent(QResizeEvent *evt)
|
|
|
|
{
|
|
|
|
QScrollArea::resizeEvent(evt);
|
|
|
|
|
|
|
|
if (verticalScrollBar()->isVisible()) {
|
|
|
|
setFrameStyle(QFrame::StyledPanel);
|
|
|
|
} else {
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::updateWidgets()
|
|
|
|
{
|
|
|
|
foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(le->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
|
|
|
le->setText(gchar_free_to_qstring(prefs_pref_to_str(pref, pref_stashed)).remove(QRegExp("\n\t")));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(cb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_type(pref) == PREF_BOOL) {
|
|
|
|
cb->setChecked(prefs_get_bool_value(pref, pref_stashed));
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QRadioButton *enum_rb, findChildren<QRadioButton *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(enum_rb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
|
|
|
QButtonGroup *enum_bg = enum_rb->group();
|
|
|
|
if (!enum_bg) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_type(pref) == PREF_ENUM && prefs_get_enum_radiobuttons(pref)) {
|
|
|
|
if (prefs_get_enum_value(pref, pref_stashed) == enum_bg->id(enum_rb)) {
|
2013-02-08 01:16:46 +00:00
|
|
|
enum_rb->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QComboBox *enum_cb, findChildren<QComboBox *>()) {
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(enum_cb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) continue;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_type(pref) == PREF_ENUM && !prefs_get_enum_radiobuttons(pref)) {
|
2013-02-08 01:16:46 +00:00
|
|
|
for (int i = 0; i < enum_cb->count(); i++) {
|
2017-01-07 13:52:23 +00:00
|
|
|
if (prefs_get_enum_value(pref, pref_stashed) == enum_cb->itemData(i).toInt()) {
|
2013-02-08 01:16:46 +00:00
|
|
|
enum_cb->setCurrentIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::uintLineEditTextEdited(const QString &new_str)
|
|
|
|
{
|
|
|
|
QLineEdit *uint_le = qobject_cast<QLineEdit*>(sender());
|
|
|
|
if (!uint_le) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(uint_le->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
|
|
|
bool ok;
|
2015-09-04 19:49:11 +00:00
|
|
|
uint new_uint = new_str.toUInt(&ok, 0);
|
2013-02-08 01:16:46 +00:00
|
|
|
if (ok) {
|
2017-01-07 13:52:23 +00:00
|
|
|
prefs_set_uint_value(pref, new_uint, pref_stashed);
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::boolCheckBoxToggled(bool checked)
|
|
|
|
{
|
|
|
|
QCheckBox *bool_cb = qobject_cast<QCheckBox*>(sender());
|
|
|
|
if (!bool_cb) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(bool_cb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
prefs_set_bool_value(pref, checked, pref_stashed);
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::enumRadioButtonToggled(bool checked)
|
|
|
|
{
|
|
|
|
if (!checked) return;
|
|
|
|
QRadioButton *enum_rb = qobject_cast<QRadioButton*>(sender());
|
|
|
|
if (!enum_rb) return;
|
|
|
|
|
|
|
|
QButtonGroup *enum_bg = enum_rb->group();
|
|
|
|
if (!enum_bg) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(enum_rb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
|
|
|
if (enum_bg->checkedId() >= 0) {
|
2017-01-07 13:52:23 +00:00
|
|
|
prefs_set_enum_value(pref, enum_bg->checkedId(), pref_stashed);
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::enumComboBoxCurrentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
QComboBox *enum_cb = qobject_cast<QComboBox*>(sender());
|
|
|
|
if (!enum_cb) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(enum_cb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
prefs_set_enum_value(pref, enum_cb->itemData(index).toInt(), pref_stashed);
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::stringLineEditTextEdited(const QString &new_str)
|
|
|
|
{
|
|
|
|
QLineEdit *string_le = qobject_cast<QLineEdit*>(sender());
|
|
|
|
if (!string_le) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(string_le->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
prefs_set_string_value(pref, new_str.toStdString().c_str(), pref_stashed);
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::rangeSyntaxLineEditTextEdited(const QString &new_str)
|
|
|
|
{
|
|
|
|
SyntaxLineEdit *range_se = qobject_cast<SyntaxLineEdit*>(sender());
|
|
|
|
if (!range_se) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(range_se->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
2017-01-04 15:57:25 +00:00
|
|
|
if (prefs_set_stashed_range_value(pref, new_str.toUtf8().constData())) {
|
2013-02-08 01:16:46 +00:00
|
|
|
if (new_str.isEmpty()) {
|
|
|
|
range_se->setSyntaxState(SyntaxLineEdit::Empty);
|
|
|
|
} else {
|
|
|
|
range_se->setSyntaxState(SyntaxLineEdit::Valid);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
range_se->setSyntaxState(SyntaxLineEdit::Invalid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::uatPushButtonPressed()
|
|
|
|
{
|
|
|
|
QPushButton *uat_pb = qobject_cast<QPushButton*>(sender());
|
|
|
|
if (!uat_pb) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(uat_pb->property(pref_prop_));
|
2013-02-08 01:16:46 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
UatDialog uat_dlg(this, prefs_get_uat_value(pref));
|
2013-07-25 23:49:47 +00:00
|
|
|
uat_dlg.exec();
|
2013-02-08 01:16:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 09:33:57 +00:00
|
|
|
void ModulePreferencesScrollArea::saveFilenamePushButtonPressed()
|
2013-02-08 18:07:34 +00:00
|
|
|
{
|
|
|
|
QPushButton *filename_pb = qobject_cast<QPushButton*>(sender());
|
|
|
|
if (!filename_pb) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(filename_pb->property(pref_prop_));
|
2013-02-08 18:07:34 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
QString filename = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(prefs_get_title(pref)),
|
2017-04-14 09:33:57 +00:00
|
|
|
prefs_get_string_value(pref, pref_stashed));
|
|
|
|
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
prefs_set_string_value(pref, QDir::toNativeSeparators(filename).toStdString().c_str(), pref_stashed);
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::openFilenamePushButtonPressed()
|
|
|
|
{
|
|
|
|
QPushButton *filename_pb = qobject_cast<QPushButton*>(sender());
|
|
|
|
if (!filename_pb) return;
|
|
|
|
|
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(filename_pb->property(pref_prop_));
|
|
|
|
if (!pref) return;
|
2013-02-08 18:07:34 +00:00
|
|
|
|
2017-04-14 09:33:57 +00:00
|
|
|
QString filename = QFileDialog::getOpenFileName(this, wsApp->windowTitleString(prefs_get_title(pref)),
|
|
|
|
prefs_get_string_value(pref, pref_stashed));
|
2013-02-08 18:07:34 +00:00
|
|
|
if (!filename.isEmpty()) {
|
2017-01-07 13:52:23 +00:00
|
|
|
prefs_set_string_value(pref, QDir::toNativeSeparators(filename).toStdString().c_str(), pref_stashed);
|
2013-02-08 18:07:34 +00:00
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModulePreferencesScrollArea::dirnamePushButtonPressed()
|
|
|
|
{
|
|
|
|
QPushButton *dirname_pb = qobject_cast<QPushButton*>(sender());
|
|
|
|
if (!dirname_pb) return;
|
|
|
|
|
2017-01-11 12:55:23 +00:00
|
|
|
pref_t *pref = VariantPointer<pref_t>::asPtr(dirname_pb->property(pref_prop_));
|
2013-02-08 18:07:34 +00:00
|
|
|
if (!pref) return;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
QString dirname = QFileDialog::getExistingDirectory(this, wsApp->windowTitleString(prefs_get_title(pref)),
|
|
|
|
prefs_get_string_value(pref, pref_stashed));
|
2013-02-08 18:07:34 +00:00
|
|
|
|
|
|
|
if (!dirname.isEmpty()) {
|
2017-01-07 13:52:23 +00:00
|
|
|
prefs_set_string_value(pref, QDir::toNativeSeparators(dirname).toStdString().c_str(), pref_stashed);
|
2013-02-08 18:07:34 +00:00
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 01:16:46 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|