2015-07-03 20:52:49 +00:00
|
|
|
/* funnel_string_dialog.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 "funnel_string_dialog.h"
|
2016-06-12 21:00:21 +00:00
|
|
|
#include <ui_funnel_string_dialog.h>
|
2015-07-03 20:52:49 +00:00
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/qt_ui_utils.h>
|
2015-07-03 20:52:49 +00:00
|
|
|
#include "wireshark_application.h"
|
|
|
|
|
2015-09-03 12:29:06 +00:00
|
|
|
// Helper object used for sending close signal to open dialogs from a C function
|
|
|
|
static FunnelStringDialogHelper dialogHelper;
|
|
|
|
|
2015-07-03 20:52:49 +00:00
|
|
|
const int min_edit_width_ = 20; // em widths
|
|
|
|
FunnelStringDialog::FunnelStringDialog(const QString title, const QStringList field_name_list, funnel_dlg_cb_t dialog_cb, void *dialog_cb_data) :
|
|
|
|
QDialog(NULL),
|
|
|
|
ui(new Ui::FunnelStringDialog),
|
|
|
|
dialog_cb_(dialog_cb),
|
|
|
|
dialog_cb_data_(dialog_cb_data)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setWindowTitle(wsApp->windowTitleString(title));
|
|
|
|
int one_em = fontMetrics().height();
|
|
|
|
|
|
|
|
int row = 0;
|
|
|
|
foreach (QString field_name, field_name_list) {
|
|
|
|
QLabel *field_label = new QLabel(field_name, this);
|
|
|
|
ui->stringGridLayout->addWidget(field_label, row, 0);
|
|
|
|
QLineEdit *field_edit = new QLineEdit(this);
|
|
|
|
field_edit->setMinimumWidth(one_em * min_edit_width_);
|
|
|
|
field_edits_ << field_edit;
|
|
|
|
ui->stringGridLayout->addWidget(field_edit, row, 1);
|
|
|
|
row++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FunnelStringDialog::~FunnelStringDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2015-09-03 12:29:06 +00:00
|
|
|
void FunnelStringDialog::accept()
|
|
|
|
{
|
|
|
|
QDialog::accept();
|
|
|
|
|
|
|
|
disconnect();
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunnelStringDialog::reject()
|
|
|
|
{
|
|
|
|
QDialog::reject();
|
|
|
|
|
|
|
|
disconnect();
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
2015-07-03 20:52:49 +00:00
|
|
|
void FunnelStringDialog::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
if (!dialog_cb_) return;
|
|
|
|
|
|
|
|
GPtrArray* returns = g_ptr_array_new();
|
|
|
|
|
|
|
|
foreach (QLineEdit *field_edit, field_edits_) {
|
|
|
|
g_ptr_array_add(returns, qstring_strdup(field_edit->text()));
|
|
|
|
}
|
|
|
|
g_ptr_array_add(returns, NULL);
|
|
|
|
|
|
|
|
dialog_cb_((gchar**)returns->pdata, dialog_cb_data_);
|
|
|
|
|
|
|
|
g_ptr_array_free(returns, FALSE);
|
|
|
|
}
|
|
|
|
|
2015-09-03 12:29:06 +00:00
|
|
|
void FunnelStringDialog::stringDialogNew(const QString title, const QStringList field_name_list, funnel_dlg_cb_t dialog_cb, void *dialog_cb_data)
|
2015-07-03 20:52:49 +00:00
|
|
|
{
|
|
|
|
FunnelStringDialog *fsd = new FunnelStringDialog(title, field_name_list, dialog_cb, dialog_cb_data);
|
2015-09-03 12:29:06 +00:00
|
|
|
connect(&dialogHelper, SIGNAL(closeDialogs()), fsd, SLOT(close()));
|
2015-07-03 20:52:49 +00:00
|
|
|
fsd->show();
|
|
|
|
}
|
|
|
|
|
2015-09-03 12:29:06 +00:00
|
|
|
void FunnelStringDialogHelper::emitCloseDialogs()
|
|
|
|
{
|
|
|
|
emit closeDialogs();
|
|
|
|
}
|
2015-08-11 12:08:08 +00:00
|
|
|
|
2015-07-03 20:52:49 +00:00
|
|
|
void string_dialog_new(const gchar *title, const gchar **fieldnames, funnel_dlg_cb_t dialog_cb, void *dialog_cb_data)
|
|
|
|
{
|
|
|
|
QStringList field_name_list;
|
|
|
|
for (int i = 0; fieldnames[i]; i++) {
|
|
|
|
field_name_list << fieldnames[i];
|
|
|
|
}
|
2015-09-03 12:29:06 +00:00
|
|
|
FunnelStringDialog::stringDialogNew(title, field_name_list, dialog_cb, dialog_cb_data);
|
2015-08-11 12:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void string_dialogs_close(void)
|
|
|
|
{
|
2015-09-03 12:29:06 +00:00
|
|
|
dialogHelper.emitCloseDialogs();
|
2015-07-03 20:52:49 +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:
|
|
|
|
*/
|