From c01cdd4e47687bf6be505f989ff5e5b54b089ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Mon, 13 Feb 2017 23:00:00 +0100 Subject: Qt: Reset Default profile support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for resetting the Default profile by deleting it in the Profile Dialog. All profile files will be deleted and all other files will be kept. Change-Id: I795a6db3ee7b2c29e7aba461183e6cc411798b75 Reviewed-on: https://code.wireshark.org/review/20097 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke --- docbook/release-notes.asciidoc | 1 + ui/qt/profile_dialog.cpp | 64 ++++++++++++++++++++++++++++++----------- ui/qt/profile_dialog.ui | 2 +- ui/qt/wireshark_application.cpp | 5 ++-- ui/qt/wireshark_application.h | 2 +- wsutil/filesystem.c | 34 ++++++++++++++++++++++ 6 files changed, 88 insertions(+), 20 deletions(-) diff --git a/docbook/release-notes.asciidoc b/docbook/release-notes.asciidoc index a247917dcf..df4e40900a 100644 --- a/docbook/release-notes.asciidoc +++ b/docbook/release-notes.asciidoc @@ -44,6 +44,7 @@ since version 2.2.0: * Added support for dissectors to include a unit name natively in their hf field. A field can now automatically append "seconds" or "ms" to its value without additional printf-style APIs. +* The Default profile can now be reset to default values. //=== Removed Dissectors diff --git a/ui/qt/profile_dialog.cpp b/ui/qt/profile_dialog.cpp index e5c697d445..2bd75f90db 100644 --- a/ui/qt/profile_dialog.cpp +++ b/ui/qt/profile_dialog.cpp @@ -149,7 +149,7 @@ void ProfileDialog::updateWidgets() current_profile = (profile_def *) VariantPointer::asPtr(item->data(0, Qt::UserRole))->data; enable_new = true; enable_copy = true; - if (!current_profile->is_global && current_profile->status != PROF_STAT_DEFAULT) { + if (!current_profile->is_global && !(item->font(0).strikeOut())) { enable_del = true; } } @@ -159,7 +159,11 @@ void ProfileDialog::updateWidgets() QString profile_info; switch (current_profile->status) { case PROF_STAT_DEFAULT: - profile_path = get_persconffile_path("", FALSE); + if (item->font(0).strikeOut()) { + profile_info = tr("Will be reset to default values"); + } else { + profile_path = get_persconffile_path("", FALSE); + } break; case PROF_STAT_EXISTS: profile_path = current_profile->is_global ? get_global_profiles_dir() : get_profiles_dir(); @@ -218,6 +222,9 @@ void ProfileDialog::updateWidgets() pd_ui_->infoLabel->setText(tr("A profile already exists with this name")); } enable_ok = false; + } else if (item->font(0).strikeOut()) { + item->setToolTip(0, tr("The profile will be reset to default values.")); + item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_deprecated)); } else { item->setBackground(0, QBrush()); } @@ -259,15 +266,22 @@ void ProfileDialog::on_deleteToolButton_clicked() if (item) { GList *fl_entry = VariantPointer::asPtr(item->data(0, Qt::UserRole)); profile_def *profile = (profile_def *) fl_entry->data; - if (profile->is_global || profile->status == PROF_STAT_DEFAULT) { + if (profile->is_global || item->font(0).strikeOut()) { return; } - delete item; + if (profile->status == PROF_STAT_DEFAULT) { + QFont ti_font = item->font(0); + ti_font.setStrikeOut(true); + item->setFont(0, ti_font); + updateWidgets(); + } else { + delete item; - // Select the default - pd_ui_->profileTreeWidget->setCurrentItem(pd_ui_->profileTreeWidget->topLevelItem(0)); + // Select the default + pd_ui_->profileTreeWidget->setCurrentItem(pd_ui_->profileTreeWidget->topLevelItem(0)); - remove_from_profile_list(fl_entry); + remove_from_profile_list(fl_entry); + } } } @@ -311,7 +325,23 @@ void ProfileDialog::on_copyToolButton_clicked() void ProfileDialog::on_buttonBox_accepted() { const gchar *err_msg; + QTreeWidgetItem *default_item = pd_ui_->profileTreeWidget->topLevelItem(0); QTreeWidgetItem *item = pd_ui_->profileTreeWidget->currentItem(); + gchar *profile_name = NULL; + bool write_recent = true; + bool item_data_removed = false; + + if (default_item && default_item->font(0).strikeOut()) { + // Reset Default profile. + GList *fl_entry = VariantPointer::asPtr(default_item->data(0, Qt::UserRole)); + remove_from_profile_list(fl_entry); + + // Don't write recent file if leaving the Default profile after this has been reset. + write_recent = !is_default_profile(); + + // Don't fetch profile data if removed. + item_data_removed = (item == default_item); + } if ((err_msg = apply_profile_changes()) != NULL) { QMessageBox::critical(this, tr("Profile Error"), @@ -321,16 +351,18 @@ void ProfileDialog::on_buttonBox_accepted() return; } - if (item) { + if (item && !item_data_removed) { profile_def *profile = (profile_def *) VariantPointer::asPtr(item->data(0, Qt::UserRole))->data; - if (profile_exists (profile->name, FALSE) || profile_exists (profile->name, TRUE)) { - /* The new profile exists, change */ - wsApp->setConfigurationProfile (profile->name); - } else if (!profile_exists (get_profile_name(), FALSE)) { - /* The new profile does not exist, and the previous profile has - been deleted. Change to the default profile */ - wsApp->setConfigurationProfile (NULL); - } + profile_name = profile->name; + } + + if (profile_exists (profile_name, FALSE) || profile_exists (profile_name, TRUE)) { + // The new profile exists, change. + wsApp->setConfigurationProfile (profile_name, write_recent); + } else if (!profile_exists (get_profile_name(), FALSE)) { + // The new profile does not exist, and the previous profile has + // been deleted. Change to the default profile. + wsApp->setConfigurationProfile (NULL, write_recent); } } diff --git a/ui/qt/profile_dialog.ui b/ui/qt/profile_dialog.ui index bf52a58226..a8f2bd33ec 100644 --- a/ui/qt/profile_dialog.ui +++ b/ui/qt/profile_dialog.ui @@ -57,7 +57,7 @@ - Remove this profile. The Default profile and system provided profiles cannot be removed. + Remove this profile. System provided profiles cannot be removed. diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index a136bc3d74..ee224f96f8 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -319,7 +319,7 @@ int WiresharkApplication::monospaceTextSize(const char *str) return fm.width(str); } -void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) +void WiresharkApplication::setConfigurationProfile(const gchar *profile_name, bool write_recent) { char *gdp_path, *dp_path; char *rf_path; @@ -363,7 +363,8 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name) /* Get the current geometry, before writing it to disk */ emit profileChanging(); - if (profile_exists(get_profile_name(), FALSE)) { + if (write_recent && profile_exists(get_profile_name(), FALSE)) + { /* Write recent file for profile we are leaving, if it still exists */ write_profile_recent(); } diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h index c4b4b786d2..fffce30a73 100644 --- a/ui/qt/wireshark_application.h +++ b/ui/qt/wireshark_application.h @@ -114,7 +114,7 @@ public: const QFont monospaceFont() const { return mono_font_; } void setMonospaceFont(const char *font_string); int monospaceTextSize(const char *str); - void setConfigurationProfile(const gchar *profile_name); + void setConfigurationProfile(const gchar *profile_name, bool write_recent = true); void reloadLuaPluginsDelayed(); bool isInitialized() { return initialized_; } void setReloadingLua(bool is_reloading) { is_reloading_lua_ = is_reloading; } diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index 4fffcd4016..7ea4776a91 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -1471,9 +1471,43 @@ delete_directory (const char *directory, char **pf_dir_path_return) return ret; } +static int +reset_default_profile(char **pf_dir_path_return) +{ + const char *profile_dir = get_persconffile_dir(NULL); + gchar *filename, *del_file; + GList *files, *file; + int ret = 0; + + files = g_hash_table_get_keys(profile_files); + file = g_list_first(files); + while (file) { + filename = (gchar *)file->data; + del_file = g_strdup_printf("%s%s%s", profile_dir, G_DIR_SEPARATOR_S, filename); + + if (file_exists(del_file)) { + ret = ws_remove(del_file); + if (ret != 0) { + *pf_dir_path_return = g_strdup(profile_dir); + g_free(del_file); + return ret; + } + } + + g_free(del_file); + file = g_list_next(file); + } + + return 0; +} + int delete_persconffile_profile(const char *profilename, char **pf_dir_path_return) { + if (strcmp(profilename, DEFAULT_PROFILE) == 0) { + return reset_default_profile(pf_dir_path_return); + } + const char *profile_dir = get_persconffile_dir(profilename); int ret = 0; -- cgit v1.2.3