diff options
author | Roland Knall <rknall@gmail.com> | 2019-08-13 11:28:48 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-08-26 06:34:31 +0000 |
commit | a9fc3681f67628fd112a76b0dc5ec145cc20ef4c (patch) | |
tree | 3a43f5a79ff0b2236a3dc7620b3c119ab9c755ae /ui/qt/widgets | |
parent | efe2926a66d3d7187a260226678daeb2aa6e4832 (diff) |
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>
Diffstat (limited to 'ui/qt/widgets')
-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.h | 43 | ||||
-rw-r--r-- | ui/qt/widgets/copy_from_profile_menu.h | 35 |
3 files changed, 95 insertions, 54 deletions
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 |