aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/qt/CMakeLists.txt4
-rw-r--r--ui/qt/coloring_rules_dialog.cpp14
-rw-r--r--ui/qt/coloring_rules_dialog.h2
-rw-r--r--ui/qt/io_graph_dialog.cpp14
-rw-r--r--ui/qt/io_graph_dialog.h2
-rw-r--r--ui/qt/uat_dialog.cpp15
-rw-r--r--ui/qt/uat_dialog.h2
-rw-r--r--ui/qt/uat_frame.cpp12
-rw-r--r--ui/qt/uat_frame.h2
-rw-r--r--ui/qt/uat_frame.ui7
-rw-r--r--ui/qt/widgets/copy_from_profile_button.cpp (renamed from ui/qt/widgets/copy_from_profile_menu.cpp)71
-rw-r--r--ui/qt/widgets/copy_from_profile_button.h43
-rw-r--r--ui/qt/widgets/copy_from_profile_menu.h35
13 files changed, 126 insertions, 97 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index 8772dfd5ad..ea68c240b8 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -16,7 +16,7 @@ set(WIRESHARK_WIDGET_HEADERS
widgets/capture_filter_combo.h
widgets/capture_filter_edit.h
widgets/clickable_label.h
- widgets/copy_from_profile_menu.h
+ widgets/copy_from_profile_button.h
widgets/display_filter_combo.h
widgets/display_filter_edit.h
widgets/dissector_tables_view.h
@@ -245,7 +245,7 @@ set(WIRESHARK_WIDGET_SRCS
widgets/capture_filter_combo.cpp
widgets/capture_filter_edit.cpp
widgets/clickable_label.cpp
- widgets/copy_from_profile_menu.cpp
+ widgets/copy_from_profile_button.cpp
widgets/display_filter_combo.cpp
widgets/display_filter_edit.cpp
widgets/dissector_tables_view.cpp
diff --git a/ui/qt/coloring_rules_dialog.cpp b/ui/qt/coloring_rules_dialog.cpp
index cfe997175c..87d886d6e6 100644
--- a/ui/qt/coloring_rules_dialog.cpp
+++ b/ui/qt/coloring_rules_dialog.cpp
@@ -22,7 +22,7 @@
#include "wireshark_application.h"
#include "ui/qt/utils/qt_ui_utils.h"
-#include "ui/qt/widgets/copy_from_profile_menu.h"
+#include "ui/qt/widgets/copy_from_profile_button.h"
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QColorDialog>
@@ -90,12 +90,9 @@ ColoringRulesDialog::ColoringRulesDialog(QWidget *parent, QString add_filter) :
export_button_ = ui->buttonBox->addButton(tr("Export" UTF8_HORIZONTAL_ELLIPSIS), QDialogButtonBox::ApplyRole);
export_button_->setToolTip(tr("Save filters in a file."));
- QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
- CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(COLORFILTERS_FILE_NAME, copy_button);
- copy_button->setMenu(copy_from_menu);
- copy_button->setToolTip(tr("Copy coloring rules from another profile."));
- copy_button->setEnabled(copy_from_menu->haveProfiles());
- connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
+ CopyFromProfileButton * copy_button = new CopyFromProfileButton(this, COLORFILTERS_FILE_NAME, tr("Copy coloring rules from another profile."));
+ ui->buttonBox->addButton(copy_button, QDialogButtonBox::ActionRole);
+ connect(copy_button, &CopyFromProfileButton::copyProfile, this, &ColoringRulesDialog::copyFromProfile);
QString abs_path = gchar_free_to_qstring(get_persconffile_path(COLORFILTERS_FILE_NAME, TRUE));
if (file_exists(abs_path.toUtf8().constData())) {
@@ -141,9 +138,8 @@ void ColoringRulesDialog::checkUnknownColorfilters()
}
}
-void ColoringRulesDialog::copyFromProfile(QAction *action)
+void ColoringRulesDialog::copyFromProfile(QString filename)
{
- QString filename = action->data().toString();
QString err;
if (!colorRuleModel_.importColors(filename, err)) {
diff --git a/ui/qt/coloring_rules_dialog.h b/ui/qt/coloring_rules_dialog.h
index 5678354f5b..06b09b4498 100644
--- a/ui/qt/coloring_rules_dialog.h
+++ b/ui/qt/coloring_rules_dialog.h
@@ -39,7 +39,7 @@ protected:
void showEvent(QShowEvent *);
private slots:
- void copyFromProfile(QAction *action);
+ void copyFromProfile(QString fileName);
void colorRuleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void on_fGPushButton_clicked();
void on_bGPushButton_clicked();
diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp
index 28409b655e..a91c3b3246 100644
--- a/ui/qt/io_graph_dialog.cpp
+++ b/ui/qt/io_graph_dialog.cpp
@@ -29,7 +29,7 @@
#include <wsutil/report_message.h>
#include <ui/qt/utils/tango_colors.h> //provides some default colors
-#include <ui/qt/widgets/copy_from_profile_menu.h>
+#include <ui/qt/widgets/copy_from_profile_button.h>
#include "ui/qt/widgets/wireshark_file_dialog.h"
#include <QClipboard>
@@ -326,12 +326,9 @@ IOGraphDialog::IOGraphDialog(QWidget &parent, CaptureFile &cf) :
QPushButton *copy_bt = ui->buttonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
connect (copy_bt, SIGNAL(clicked()), this, SLOT(copyAsCsvClicked()));
- QPushButton *copy_from_bt = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
- CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu("io_graphs", copy_from_bt);
- copy_from_bt->setMenu(copy_from_menu);
- copy_from_bt->setToolTip(tr("Copy graphs from another profile."));
- copy_from_bt->setEnabled(copy_from_menu->haveProfiles());
- connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
+ CopyFromProfileButton * copy_button = new CopyFromProfileButton(this, "io_graphs", tr("Copy graphs from another profile."));
+ ui->buttonBox->addButton(copy_button, QDialogButtonBox::ActionRole);
+ connect(copy_button, &CopyFromProfileButton::copyProfile, this, &IOGraphDialog::copyFromProfile);
QPushButton *close_bt = ui->buttonBox->button(QDialogButtonBox::Close);
if (close_bt) {
@@ -430,9 +427,8 @@ IOGraphDialog::~IOGraphDialog()
ui = NULL;
}
-void IOGraphDialog::copyFromProfile(QAction *action)
+void IOGraphDialog::copyFromProfile(QString filename)
{
- QString filename = action->data().toString();
guint orig_data_len = iog_uat_->raw_data->len;
gchar *err = NULL;
diff --git a/ui/qt/io_graph_dialog.h b/ui/qt/io_graph_dialog.h
index 6dc18b37e0..08a03d9299 100644
--- a/ui/qt/io_graph_dialog.h
+++ b/ui/qt/io_graph_dialog.h
@@ -200,7 +200,7 @@ private:
bool graphIsEnabled(int row) const;
private slots:
- void copyFromProfile(QAction *action);
+ void copyFromProfile(QString filename);
void updateWidgets();
void graphClicked(QMouseEvent *event);
void mouseMoved(QMouseEvent *event);
diff --git a/ui/qt/uat_dialog.cpp b/ui/qt/uat_dialog.cpp
index 63e56e195a..9cb64b8d69 100644
--- a/ui/qt/uat_dialog.cpp
+++ b/ui/qt/uat_dialog.cpp
@@ -16,7 +16,7 @@
#include "ui/help_url.h"
#include <wsutil/report_message.h>
-#include <ui/qt/widgets/copy_from_profile_menu.h>
+#include <ui/qt/widgets/copy_from_profile_button.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include <QDesktopServices>
@@ -101,12 +101,9 @@ void UatDialog::setUat(epan_uat *uat)
}
if (uat->from_profile) {
- QPushButton *copy_button = ui->buttonBox->addButton(tr("Copy from"), QDialogButtonBox::ActionRole);
- CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(uat->filename, copy_button);
- copy_button->setMenu(copy_from_menu);
- copy_button->setToolTip(tr("Copy entries from another profile."));
- copy_button->setEnabled(copy_from_menu->haveProfiles());
- connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
+ CopyFromProfileButton * copy_button = new CopyFromProfileButton(this, uat->filename);
+ ui->buttonBox->addButton(copy_button, QDialogButtonBox::ActionRole);
+ connect(copy_button, &CopyFromProfileButton::copyProfile, this, &UatDialog::copyFromProfile);
}
QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE));
@@ -140,10 +137,8 @@ void UatDialog::setUat(epan_uat *uat)
setWindowTitle(title);
}
-void UatDialog::copyFromProfile(QAction *action)
+void UatDialog::copyFromProfile(QString filename)
{
- QString filename = action->data().toString();
-
gchar *err = NULL;
if (uat_load(uat_, filename.toUtf8().constData(), &err)) {
uat_->changed = TRUE;
diff --git a/ui/qt/uat_dialog.h b/ui/qt/uat_dialog.h
index 7bce5434dc..55be5af0b5 100644
--- a/ui/qt/uat_dialog.h
+++ b/ui/qt/uat_dialog.h
@@ -38,7 +38,7 @@ public:
void setUat(struct epan_uat *uat = NULL);
private slots:
- void copyFromProfile(QAction *action);
+ void copyFromProfile(QString filename);
void modelDataChanged(const QModelIndex &topLeft);
void modelRowsRemoved();
void modelRowsReset();
diff --git a/ui/qt/uat_frame.cpp b/ui/qt/uat_frame.cpp
index 0a8cb69e2c..aa8504fd30 100644
--- a/ui/qt/uat_frame.cpp
+++ b/ui/qt/uat_frame.cpp
@@ -18,7 +18,7 @@
#include <ui/qt/widgets/display_filter_edit.h>
#include "wireshark_application.h"
-#include <ui/qt/widgets/copy_from_profile_menu.h>
+#include <ui/qt/widgets/copy_from_profile_button.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include <wsutil/report_message.h>
@@ -91,10 +91,8 @@ void UatFrame::setUat(epan_uat *uat)
}
if (uat->from_profile) {
- CopyFromProfileMenu *copy_from_menu = new CopyFromProfileMenu(uat_->filename, ui->copyFromProfileButton);
- ui->copyFromProfileButton->setMenu(copy_from_menu);
- ui->copyFromProfileButton->setEnabled(copy_from_menu->haveProfiles());
- connect(copy_from_menu, SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
+ ui->copyFromProfileButton->setFilename(uat->filename);
+ connect(ui->copyFromProfileButton, &CopyFromProfileButton::copyProfile, this, &UatFrame::copyFromProfile);
}
QString abs_path = gchar_free_to_qstring(uat_get_actual_filename(uat_, FALSE));
@@ -119,10 +117,8 @@ void UatFrame::setUat(epan_uat *uat)
setWindowTitle(title);
}
-void UatFrame::copyFromProfile(QAction *action)
+void UatFrame::copyFromProfile(QString filename)
{
- QString filename = action->data().toString();
-
gchar *err = NULL;
if (uat_load(uat_, filename.toUtf8().constData(), &err)) {
uat_->changed = TRUE;
diff --git a/ui/qt/uat_frame.h b/ui/qt/uat_frame.h
index ccf46e1fbf..f420e16a28 100644
--- a/ui/qt/uat_frame.h
+++ b/ui/qt/uat_frame.h
@@ -49,7 +49,7 @@ private:
void applyChanges();
private slots:
- void copyFromProfile(QAction *action);
+ void copyFromProfile(QString filename);
void modelDataChanged(const QModelIndex &topLeft);
void modelRowsRemoved();
void modelRowsReset();
diff --git a/ui/qt/uat_frame.ui b/ui/qt/uat_frame.ui
index 786aa2c07a..452ae65d09 100644
--- a/ui/qt/uat_frame.ui
+++ b/ui/qt/uat_frame.ui
@@ -102,7 +102,7 @@
</widget>
</item>
<item>
- <widget class="QPushButton" name="copyFromProfileButton">
+ <widget class="CopyFromProfileButton" name="copyFromProfileButton">
<property name="toolTip">
<string>Copy entries from another profile.</string>
</property>
@@ -150,6 +150,11 @@
<extends>QToolButton</extends>
<header>widgets/stock_icon_tool_button.h</header>
</customwidget>
+ <customwidget>
+ <class>CopyFromProfileButton</class>
+ <extends>QPushButton</extends>
+ <header>widgets/copy_from_profile_button.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
diff --git a/ui/qt/widgets/copy_from_profile_menu.cpp b/ui/qt/widgets/copy_from_profile_button.cpp
index c97002cdbb..1093439252 100644
--- a/ui/qt/widgets/copy_from_profile_menu.cpp
+++ b/ui/qt/widgets/copy_from_profile_button.cpp
@@ -1,4 +1,4 @@
-/* copy_from_profile_menu.cpp
+/* copy_from_profile_button.cpp
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
@@ -7,17 +7,37 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
-#include <ui/qt/widgets/copy_from_profile_menu.h>
+#include <ui/qt/widgets/copy_from_profile_button.h>
#include <ui/qt/models/profile_model.h>
#include <wsutil/filesystem.h>
#include <QDir>
#include <QFileInfo>
+#include <QMenu>
+#include <QAction>
-CopyFromProfileMenu::CopyFromProfileMenu(QString filename, QWidget *parent) :
- QMenu(parent),
- have_profiles_(false)
+CopyFromProfileButton::CopyFromProfileButton(QWidget * parent, QString fileName, QString toolTip) :
+ QPushButton(parent),
+ buttonMenu_(Q_NULLPTR)
{
+ setText(tr("Copy from"));
+ if ( toolTip.length() == 0 )
+ setToolTip(tr("Copy entries from another profile."));
+ else {
+ setToolTip(toolTip);
+ }
+
+ if ( fileName.length() > 0 )
+ setFilename(fileName);
+}
+
+void CopyFromProfileButton::setFilename(QString filename)
+{
+ setEnabled(false);
+
+ if ( filename.length() <= 0 )
+ return;
+
ProfileModel model(this);
QList<QAction *> global;
@@ -27,6 +47,12 @@ CopyFromProfileMenu::CopyFromProfileMenu(QString filename, QWidget *parent) :
if ( pa )
global << pa;
+ if ( ! buttonMenu_ )
+ buttonMenu_ = new QMenu();
+
+ if ( buttonMenu_->actions().count() > 0 )
+ buttonMenu_->clear();
+
for(int cnt = 0; cnt < model.rowCount(); cnt++)
{
QModelIndex idx = model.index(cnt, ProfileModel::COL_NAME);
@@ -51,7 +77,7 @@ CopyFromProfileMenu::CopyFromProfileMenu(QString filename, QWidget *parent) :
QString name = idx.data().toString();
pa = new QAction(name, this);
if ( idx.data(ProfileModel::DATA_IS_DEFAULT).toBool() )
- addAction(pa);
+ buttonMenu_->addAction(pa);
else if ( idx.data(ProfileModel::DATA_IS_GLOBAL).toBool() )
global << pa;
else
@@ -60,30 +86,27 @@ CopyFromProfileMenu::CopyFromProfileMenu(QString filename, QWidget *parent) :
pa->setFont(idx.data(Qt::FontRole).value<QFont>());
pa->setProperty("profile_name", name);
pa->setProperty("profile_is_global", idx.data(ProfileModel::DATA_IS_GLOBAL));
-
- pa->setProperty("filename", fi.absoluteFilePath());
- pa->setData(fi.absoluteFilePath().toUtf8().constData());
+ pa->setProperty("profile_filename", fi.absoluteFilePath());
}
- addActions(user);
+ buttonMenu_->addActions(user);
if (global.count() > 0)
{
if ( actions().count() > 0 )
- addSeparator();
- addActions(global);
+ buttonMenu_->addSeparator();
+ buttonMenu_->addActions(global);
}
+ if ( buttonMenu_->actions().count() <= 0 )
+ return;
- have_profiles_ = actions().count() > 0;
-}
-
-bool CopyFromProfileMenu::haveProfiles()
-{
- return have_profiles_;
+ connect(buttonMenu_, &QMenu::triggered, this, &CopyFromProfileButton::menuActionTriggered);
+ setMenu(buttonMenu_);
+ setEnabled(true);
}
// "System default" is not a profile.
// Add a special entry for this if the filename exists.
-QAction * CopyFromProfileMenu::systemDefault(QString filename)
+QAction * CopyFromProfileButton::systemDefault(QString filename)
{
QAction * data = Q_NULLPTR;
@@ -100,3 +123,13 @@ QAction * CopyFromProfileMenu::systemDefault(QString filename)
return data;
}
+
+void CopyFromProfileButton::menuActionTriggered(QAction * action)
+{
+ if ( action->property("profile_filename").toString().length() > 0 )
+ {
+ QString filename = action->property("profile_filename").toString();
+ if ( QFileInfo::exists(filename) )
+ emit copyProfile(filename);
+ }
+}
diff --git a/ui/qt/widgets/copy_from_profile_button.h b/ui/qt/widgets/copy_from_profile_button.h
new file mode 100644
index 0000000000..b54ed35a6c
--- /dev/null
+++ b/ui/qt/widgets/copy_from_profile_button.h
@@ -0,0 +1,43 @@
+/* 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 <QMenu>
+#include <QPushButton>
+#include <QDialogButtonBox>
+#include <QMetaObject>
+
+class CopyFromProfileButton : public QPushButton
+{
+ Q_OBJECT
+
+public:
+ CopyFromProfileButton(QWidget * parent = Q_NULLPTR, QString profileFile = QString(), QString toolTip = QString());
+
+ void setFilename(QString filename);
+
+Q_SIGNALS:
+ void copyProfile(QString filename);
+
+private:
+ QString filename_;
+ QMenu * buttonMenu_;
+
+ QAction * systemDefault(QString filename);
+
+private slots:
+ void menuActionTriggered(QAction *);
+};
+
+#endif // COPY_FROM_PROFILE_BUTTON_H
diff --git a/ui/qt/widgets/copy_from_profile_menu.h b/ui/qt/widgets/copy_from_profile_menu.h
deleted file mode 100644
index f120d51195..0000000000
--- a/ui/qt/widgets/copy_from_profile_menu.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* copy_from_profile_menu.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_MENU_H
-#define COPY_FROM_PROFILE_MENU_H
-
-#include <config.h>
-#include <glib.h>
-
-#include <QMenu>
-
-class CopyFromProfileMenu : public QMenu
-{
- Q_OBJECT
-
-public:
- explicit CopyFromProfileMenu(QString filename, QWidget *parent = Q_NULLPTR);
- ~CopyFromProfileMenu() { }
-
- bool haveProfiles();
-
-private:
-
- QAction * systemDefault(QString filename);
-
- bool have_profiles_;
-};
-
-#endif // COPY_FROM_PROFILE_MENU_H