Add a new button to UAT dialogs to copy entries from another profile.
Change-Id: I641ba764d8738f738466529d74d4a21ff13075a0
Reviewed-on: https://code.wireshark.org/review/30028
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>
"A table of secrets for different identities.",
identsecret_uat);
- uat_load(secmode_uat, &uat_load_err);
- uat_load(seckey_uat, &uat_load_err);
- uat_load(identsecret_uat, &uat_load_err);
+ uat_load(secmode_uat, NULL, &uat_load_err);
+ uat_load(seckey_uat, NULL, &uat_load_err);
+ uat_load(identsecret_uat, NULL, &uat_load_err);
}
static void dof_handoff(void)
if (!u->loaded) {
err = NULL;
- if (!uat_load(u, &err)) {
+ if (!uat_load(u, NULL, &err)) {
report_failure("Error loading table '%s': %s",u->name,err);
g_free(err);
}
/** Populate a uat using its file.
*
* @param uat_in Pointer to a uat. Must not be NULL.
+ * @param filename Filename to load, NULL to fetch from current profile.
* @param err Upon failure, points to an error string.
*
* @return TRUE on success, FALSE on failure.
*/
WS_DLL_PUBLIC
-gboolean uat_load(uat_t* uat_in, char** err);
+gboolean uat_load(uat_t* uat_in, const gchar *filename, char** err);
/** Create or update a single uat entry using a string.
*
DIAG_ON_FLEX
gboolean
-uat_load(uat_t *uat, char **errx)
+uat_load(uat_t *uat, const gchar *filename, char **errx)
{
- gchar *fname = uat_get_actual_filename(uat, FALSE);
+ gchar *fname;
FILE *in;
yyscan_t scanner;
uat_load_scanner_state_t state;
+ if (filename) {
+ fname = g_strdup(filename);
+ } else {
+ fname = uat_get_actual_filename(uat, FALSE);
+ }
+
if (!fname) {
UAT_UPDATE(uat);
io_graph_fields);
char* err = NULL;
- if (!uat_load(iog_uat_, &err)) {
+ if (!uat_load(iog_uat_, NULL, &err)) {
report_failure("Error while loading %s: %s. Default graph values will be used", iog_uat_->name, err);
g_free(err);
uat_clear(iog_uat_);
}
}
+void UatModel::reloadUat()
+{
+ beginResetModel();
+ loadUat(uat_);
+ endResetModel();
+}
+
Qt::ItemFlags UatModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
bool copyRow(int dst_row, int src_row);
bool moveRow(int src_row, int dst_row);
+ void reloadUat();
bool hasErrors() const;
void clearAll();
uat_t *uat = prefs_get_uat_value(pref);
uat_clear(uat);
- if (!uat_load(uat, &err)) {
+ if (!uat_load(uat, NULL, &err)) {
/* XXX - report this through the GUI */
g_log(NULL, G_LOG_LEVEL_WARNING, "Error loading table '%s': %s", uat->name, err);
g_free(err);
#include "ui/help_url.h"
#include <wsutil/report_message.h>
+#include <ui/qt/widgets/copy_from_profile_button.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include <QDesktopServices>
#include <QPushButton>
#include <QUrl>
+#include <QMenu>
#include <QDebug>
ok_button_ = ui->buttonBox->button(QDialogButtonBox::Ok);
help_button_ = ui->buttonBox->button(QDialogButtonBox::Help);
+ if (uat->from_profile) {
+ QPushButton *copy_button = new CopyFromProfileButton(uat->filename);
+ ui->buttonBox->addButton(copy_button, QDialogButtonBox::ApplyRole);
+ connect(copy_button->menu(), SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *)));
+ }
+
#ifdef Q_OS_MAC
ui->newToolButton->setAttribute(Qt::WA_MacSmallSize, true);
ui->deleteToolButton->setAttribute(Qt::WA_MacSmallSize, true);
delete uat_model_;
}
+void UatDialog::copyFromProfile(QAction *action)
+{
+ QString filename = action->data().toString();
+
+ gchar *err = NULL;
+ if (uat_load(uat_, filename.toUtf8().constData(), &err)) {
+ uat_->changed = TRUE;
+ uat_model_->reloadUat();
+ } else {
+ report_failure("Error while loading %s: %s", uat_->name, err);
+ g_free(err);
+ }
+}
+
void UatDialog::setUat(epan_uat *uat)
{
QString title(tr("Unknown User Accessible Table"));
void UatDialog::modelRowsReset()
{
ui->deleteToolButton->setEnabled(false);
- ui->clearToolButton->setEnabled(false);
+ ui->clearToolButton->setEnabled(uat_model_->rowCount() != 0);
ui->copyToolButton->setEnabled(false);
ui->moveUpToolButton->setEnabled(false);
ui->moveDownToolButton->setEnabled(false);
if (uat_->changed) {
gchar *err = NULL;
uat_clear(uat_);
- if (!uat_load(uat_, &err)) {
+ if (!uat_load(uat_, NULL, &err)) {
report_failure("Error while loading %s: %s", uat_->name, err);
g_free(err);
}
void setUat(struct epan_uat *uat = NULL);
private slots:
+ void copyFromProfile(QAction *action);
void modelDataChanged(const QModelIndex &topLeft);
void modelRowsRemoved();
void modelRowsReset();
if (uat_->changed) {
gchar *err = NULL;
uat_clear(uat_);
- if (!uat_load(uat_, &err)) {
+ if (!uat_load(uat_, NULL, &err)) {
report_failure("Error while loading %s: %s", uat_->name, err);
g_free(err);
}