Qt: Move CopyFrom from menu to button
Move the CopyFromProfile implementation from a menu to a button to ease integration in existing code Change-Id: I4fb4e952e89665eda99d162e891ac6d3516a6f02 Reviewed-on: https://code.wireshark.org/review/34266 Reviewed-by: Roland Knall <rknall@gmail.com> Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
efe2926a66
commit
a9fc3681f6
|
@ -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
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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/>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue