forked from osmocom/wireshark
Qt: Add copy from another profile for colorfilters
Add a new button to the Coloring Rules dialog to copy entries from another profile, or system defaults. The "copy from profile" button will also be used for other dialogs. Add a clear all button to easily remove all existing entries before importing or copying from another profile. Change-Id: Ia1e66444731018372b4354164c5a722fd73d403b Reviewed-on: https://code.wireshark.org/review/30008 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
This commit is contained in:
parent
4e38af0e74
commit
84a0eccebd
|
@ -16,6 +16,7 @@ set(WIRESHARK_WIDGET_HEADERS
|
|||
widgets/capture_filter_combo.h
|
||||
widgets/capture_filter_edit.h
|
||||
widgets/clickable_label.h
|
||||
widgets/copy_from_profile_button.h
|
||||
widgets/display_filter_combo.h
|
||||
widgets/display_filter_edit.h
|
||||
widgets/dissector_tables_view.h
|
||||
|
@ -238,6 +239,7 @@ set(WIRESHARK_WIDGET_SRCS
|
|||
widgets/capture_filter_combo.cpp
|
||||
widgets/capture_filter_edit.cpp
|
||||
widgets/clickable_label.cpp
|
||||
widgets/copy_from_profile_button.cpp
|
||||
widgets/display_filter_combo.cpp
|
||||
widgets/display_filter_edit.cpp
|
||||
widgets/dissector_tables_view.cpp
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
#include "wsutil/filesystem.h"
|
||||
|
||||
#include "wireshark_application.h"
|
||||
#include "ui/qt/widgets/copy_from_profile_button.h"
|
||||
#include "ui/qt/widgets/wireshark_file_dialog.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QMenu>
|
||||
|
||||
/*
|
||||
* @file Coloring Rules dialog
|
||||
|
@ -62,12 +64,20 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
|
|||
this, SLOT(invalidField(const QModelIndex&, const QString&)));
|
||||
connect(&colorRuleDelegate_, SIGNAL(validField(const QModelIndex&)),
|
||||
this, SLOT(validField(const QModelIndex&)));
|
||||
connect(&colorRuleModel_, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowCountChanged()));
|
||||
connect(&colorRuleModel_, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(rowCountChanged()));
|
||||
|
||||
rowCountChanged();
|
||||
|
||||
import_button_ = ui->buttonBox->addButton(tr("Import" UTF8_HORIZONTAL_ELLIPSIS), QDialogButtonBox::ApplyRole);
|
||||
import_button_->setToolTip(tr("Select a file and add its filters to the end of the list."));
|
||||
export_button_ = ui->buttonBox->addButton(tr("Export" UTF8_HORIZONTAL_ELLIPSIS), QDialogButtonBox::ApplyRole);
|
||||
export_button_->setToolTip(tr("Save filters in a file."));
|
||||
|
||||
QPushButton *copy_button = new CopyFromProfileButton("colorfilters");
|
||||
ui->buttonBox->addButton(copy_button, QDialogButtonBox::ApplyRole);
|
||||
connect(copy_button->menu(), SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
|
||||
|
||||
if (!add_filter.isEmpty()) {
|
||||
colorRuleModel_.addColor(false, add_filter, palette().color(QPalette::Text), palette().color(QPalette::Base));
|
||||
|
||||
|
@ -80,6 +90,18 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
|
|||
ui->coloringRulesTreeView->setCurrentIndex(QModelIndex());
|
||||
}
|
||||
|
||||
checkUnknownColorfilters();
|
||||
|
||||
updateHint();
|
||||
}
|
||||
|
||||
ColoringRulesDialog::~ColoringRulesDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ColoringRulesDialog::checkUnknownColorfilters()
|
||||
{
|
||||
if (prefs.unknown_colorfilters) {
|
||||
QMessageBox mb;
|
||||
mb.setText(tr("Your coloring rules file contains unknown rules"));
|
||||
|
@ -90,13 +112,22 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
|
|||
mb.exec();
|
||||
prefs.unknown_colorfilters = FALSE;
|
||||
}
|
||||
|
||||
updateHint();
|
||||
}
|
||||
|
||||
ColoringRulesDialog::~ColoringRulesDialog()
|
||||
void ColoringRulesDialog::copyFromProfile(QAction *action)
|
||||
{
|
||||
delete ui;
|
||||
QString filename = action->data().toString();
|
||||
QString err;
|
||||
|
||||
if (!colorRuleModel_.importColors(filename, err)) {
|
||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err.toUtf8().constData());
|
||||
}
|
||||
|
||||
for (int i = 0; i < colorRuleModel_.columnCount(); i++) {
|
||||
ui->coloringRulesTreeView->resizeColumnToContents(i);
|
||||
}
|
||||
|
||||
checkUnknownColorfilters();
|
||||
}
|
||||
|
||||
void ColoringRulesDialog::showEvent(QShowEvent *)
|
||||
|
@ -106,6 +137,11 @@ void ColoringRulesDialog::showEvent(QShowEvent *)
|
|||
ui->displayFilterPushButton->setFixedHeight(ui->copyToolButton->geometry().height());
|
||||
}
|
||||
|
||||
void ColoringRulesDialog::rowCountChanged()
|
||||
{
|
||||
ui->clearToolButton->setEnabled(colorRuleModel_.rowCount() > 0);
|
||||
}
|
||||
|
||||
void ColoringRulesDialog::invalidField(const QModelIndex &index, const QString& errMessage)
|
||||
{
|
||||
errors_.insert(index, errMessage);
|
||||
|
@ -285,6 +321,11 @@ void ColoringRulesDialog::on_copyToolButton_clicked()
|
|||
addRule(true);
|
||||
}
|
||||
|
||||
void ColoringRulesDialog::on_clearToolButton_clicked()
|
||||
{
|
||||
colorRuleModel_.removeRows(0, colorRuleModel_.rowCount());
|
||||
}
|
||||
|
||||
void ColoringRulesDialog::on_buttonBox_clicked(QAbstractButton *button)
|
||||
{
|
||||
QString err;
|
||||
|
|
|
@ -39,6 +39,7 @@ protected:
|
|||
void showEvent(QShowEvent *);
|
||||
|
||||
private slots:
|
||||
void copyFromProfile(QAction *action);
|
||||
void colorRuleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
void on_fGPushButton_clicked();
|
||||
void on_bGPushButton_clicked();
|
||||
|
@ -46,9 +47,11 @@ private slots:
|
|||
void on_newToolButton_clicked();
|
||||
void on_deleteToolButton_clicked();
|
||||
void on_copyToolButton_clicked();
|
||||
void on_clearToolButton_clicked();
|
||||
void on_buttonBox_clicked(QAbstractButton *button);
|
||||
void on_buttonBox_accepted();
|
||||
void on_buttonBox_helpRequested();
|
||||
void rowCountChanged();
|
||||
void invalidField(const QModelIndex &index, const QString& errMessage);
|
||||
void validField(const QModelIndex &index);
|
||||
|
||||
|
@ -61,6 +64,7 @@ private:
|
|||
|
||||
QMap<QModelIndex, QString> errors_;
|
||||
|
||||
void checkUnknownColorfilters();
|
||||
void setColorButtons(QModelIndex &index);
|
||||
void updateHint();
|
||||
|
||||
|
|
|
@ -102,6 +102,21 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="clearToolButton">
|
||||
<property name="toolTip">
|
||||
<string>Clear all coloring rules.</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../image/stock_icons.qrc">
|
||||
<normaloff>:/stock/delete_list.png</normaloff>:/stock/delete_list.png
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="fGPushButton">
|
||||
<property name="toolTip">
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/* copy_from_profile_button.cpp
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <ui/qt/widgets/copy_from_profile_button.h>
|
||||
#include <ui/profile.h>
|
||||
#include <wsutil/filesystem.h>
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMenu>
|
||||
|
||||
CopyFromProfileButton::CopyFromProfileButton(QString filename) :
|
||||
menu_(new QMenu(this)),
|
||||
filename_(filename)
|
||||
{
|
||||
const gchar *profile_name = get_profile_name();
|
||||
bool profiles_added = false;
|
||||
bool globals_started = false;
|
||||
|
||||
setText(tr("Copy from"));
|
||||
setToolTip(tr("Copy entries from another profile."));
|
||||
|
||||
setMenu(menu_);
|
||||
|
||||
init_profile_list();
|
||||
const GList *fl_entry = edited_profile_list();
|
||||
while (fl_entry && fl_entry->data) {
|
||||
profile_def *profile = (profile_def *) fl_entry->data;
|
||||
char *profile_dir = get_profile_dir(profile->name, profile->is_global);
|
||||
char *file_name = g_build_filename(profile_dir, filename_.toUtf8().constData(), NULL);
|
||||
if (file_exists(file_name) && strcmp(profile_name, profile->name) != 0) {
|
||||
if (profile->is_global && !globals_started) {
|
||||
if (profiles_added) {
|
||||
menu_->addSeparator();
|
||||
}
|
||||
addSystemDefault();
|
||||
globals_started = true;
|
||||
}
|
||||
QAction *action = menu_->addAction(profile->name);
|
||||
action->setData(QString(file_name));
|
||||
if (profile->is_global) {
|
||||
QFont ti_font = action->font();
|
||||
ti_font.setItalic(true);
|
||||
action->setFont(ti_font);
|
||||
}
|
||||
profiles_added = true;
|
||||
}
|
||||
g_free(file_name);
|
||||
g_free(profile_dir);
|
||||
fl_entry = g_list_next(fl_entry);
|
||||
}
|
||||
|
||||
if (!globals_started) {
|
||||
if (profiles_added) {
|
||||
menu_->addSeparator();
|
||||
}
|
||||
addSystemDefault();
|
||||
}
|
||||
|
||||
setEnabled(profiles_added);
|
||||
}
|
||||
|
||||
// "System default" is not a profile.
|
||||
// Add a special entry for this if the filename exists.
|
||||
void CopyFromProfileButton::addSystemDefault()
|
||||
{
|
||||
char *file_name = g_build_filename(get_datafile_dir(), filename_.toUtf8().constData(), NULL);
|
||||
if (file_exists(file_name)) {
|
||||
QAction *action = menu_->addAction("System default");
|
||||
action->setData(QString(file_name));
|
||||
QFont ti_font = action->font();
|
||||
ti_font.setItalic(true);
|
||||
action->setFont(ti_font);
|
||||
}
|
||||
g_free(file_name);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* copy_from_profile_button.h
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef COPY_FROM_PROFILE_BUTTON_H
|
||||
#define COPY_FROM_PROFILE_BUTTON_H
|
||||
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
class QMenu;
|
||||
|
||||
class CopyFromProfileButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CopyFromProfileButton(QString filename);
|
||||
~CopyFromProfileButton() { }
|
||||
|
||||
private:
|
||||
void addSystemDefault();
|
||||
|
||||
QMenu *menu_;
|
||||
QString filename_;
|
||||
};
|
||||
|
||||
#endif // COPY_FROM_PROFILE_BUTTON_H
|
Loading…
Reference in New Issue