[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 17/20: Use enum classes for status.

noreply at xfce.org noreply at xfce.org
Thu Feb 6 12:03:34 CET 2020


This is an automated email from the git hooks/post-receive script.

g   o   t   t   c   o   d   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-whiskermenu-plugin.

commit 6ba4871500d78c5ccf0feb291e3d50e77f5f8af4
Author: Graeme Gott <graeme at gottcode.org>
Date:   Wed Feb 5 09:23:53 2020 -0500

    Use enum classes for status.
---
 panel-plugin/applications-page.cpp | 30 ++++++++++--------------------
 panel-plugin/applications-page.h   | 10 +++++++++-
 panel-plugin/command.cpp           | 27 +++++++++------------------
 panel-plugin/command.h             |  9 ++++++++-
 4 files changed, 36 insertions(+), 40 deletions(-)

diff --git a/panel-plugin/applications-page.cpp b/panel-plugin/applications-page.cpp
index f347306..cc5ff29 100644
--- a/panel-plugin/applications-page.cpp
+++ b/panel-plugin/applications-page.cpp
@@ -36,21 +36,11 @@ using namespace WhiskerMenu;
 
 //-----------------------------------------------------------------------------
 
-enum
-{
-	STATUS_INVALID,
-	STATUS_LOADING,
-	STATUS_LOADING_RELOAD,
-	STATUS_LOADED
-};
-
-//-----------------------------------------------------------------------------
-
 ApplicationsPage::ApplicationsPage(Window* window) :
 	Page(window),
 	m_garcon_menu(nullptr),
 	m_garcon_settings_menu(nullptr),
-	m_load_status(STATUS_INVALID)
+	m_status(LoadStatus::Invalid)
 {
 	// Set desktop environment for applications
 	const gchar* desktop = g_getenv("XDG_CURRENT_DESKTOP");
@@ -157,13 +147,13 @@ void ApplicationsPage::apply_filter(GtkToggleButton* togglebutton)
 
 void ApplicationsPage::invalidate_applications()
 {
-	if (m_load_status == STATUS_LOADED)
+	if (m_status == LoadStatus::Done)
 	{
-		m_load_status = STATUS_INVALID;
+		m_status = LoadStatus::Invalid;
 	}
-	else if (m_load_status == STATUS_LOADING)
+	else if (m_status == LoadStatus::Loading)
 	{
-		m_load_status = STATUS_LOADING_RELOAD;
+		m_status = LoadStatus::ReloadRequired;
 	}
 }
 
@@ -172,16 +162,16 @@ void ApplicationsPage::invalidate_applications()
 bool ApplicationsPage::load_applications()
 {
 	// Check if already loaded
-	if (m_load_status == STATUS_LOADED)
+	if (m_status == LoadStatus::Done)
 	{
 		return true;
 	}
 	// Check if currently loading
-	else if ((m_load_status == STATUS_LOADING) || (m_load_status == STATUS_LOADING_RELOAD))
+	else if (m_status != LoadStatus::Invalid)
 	{
 		return false;
 	}
-	m_load_status = STATUS_LOADING;
+	m_status = LoadStatus::Loading;
 
 	// Load menu
 	clear_applications();
@@ -314,7 +304,7 @@ void ApplicationsPage::load_contents()
 	{
 		get_window()->set_loaded();
 
-		m_load_status = STATUS_INVALID;
+		m_status = LoadStatus::Invalid;
 
 		return;
 	}
@@ -339,7 +329,7 @@ void ApplicationsPage::load_contents()
 	get_window()->set_items();
 	get_window()->set_loaded();
 
-	m_load_status = (m_load_status == STATUS_LOADING) ? STATUS_LOADED : STATUS_INVALID;
+	m_status = (m_status == LoadStatus::Loading) ? LoadStatus::Done : LoadStatus::Invalid;
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/applications-page.h b/panel-plugin/applications-page.h
index cefd71a..9bb2035 100644
--- a/panel-plugin/applications-page.h
+++ b/panel-plugin/applications-page.h
@@ -70,7 +70,15 @@ private:
 	GarconMenu* m_garcon_settings_menu;
 	std::vector<Category*> m_categories;
 	std::unordered_map<std::string, Launcher*> m_items;
-	int m_load_status;
+
+	enum class LoadStatus
+	{
+		Invalid,
+		Loading,
+		ReloadRequired,
+		Done
+	}
+	m_status;
 };
 
 }
diff --git a/panel-plugin/command.cpp b/panel-plugin/command.cpp
index 97ee450..8b68634 100644
--- a/panel-plugin/command.cpp
+++ b/panel-plugin/command.cpp
@@ -29,15 +29,6 @@ using namespace WhiskerMenu;
 
 //-----------------------------------------------------------------------------
 
-enum
-{
-	WHISKERMENU_COMMAND_UNCHECKED = -1,
-	WHISKERMENU_COMMAND_INVALID,
-	WHISKERMENU_COMMAND_VALID
-};
-
-//-----------------------------------------------------------------------------
-
 Command::Command(const gchar* icon, const gchar* text, const gchar* command, const gchar* error_text, const gchar* confirm_question, const gchar* confirm_status) :
 	m_button(nullptr),
 	m_menuitem(nullptr),
@@ -45,8 +36,8 @@ Command::Command(const gchar* icon, const gchar* text, const gchar* command, con
 	m_mnemonic(g_strdup(text)),
 	m_command(g_strdup(command)),
 	m_error_text(g_strdup(error_text)),
-	m_status(WHISKERMENU_COMMAND_UNCHECKED),
 	m_shown(true),
+	m_status(CommandStatus::Unchecked),
 	m_timeout_details({nullptr, g_strdup(confirm_question), g_strdup(confirm_status), 0})
 {
 	std::string tooltip(text ? text : "");
@@ -104,7 +95,7 @@ GtkWidget* Command::get_button()
 	gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(image));
 
 	gtk_widget_set_visible(m_button, m_shown);
-	gtk_widget_set_sensitive(m_button, m_status == WHISKERMENU_COMMAND_VALID);
+	gtk_widget_set_sensitive(m_button, m_status == CommandStatus::Valid);
 
 	g_object_ref_sink(m_button);
 
@@ -124,7 +115,7 @@ GtkWidget* Command::get_menuitem()
 	g_signal_connect_slot<GtkMenuItem*>(m_menuitem, "activate", &Command::activate, this);
 
 	gtk_widget_set_visible(m_menuitem, m_shown);
-	gtk_widget_set_sensitive(m_menuitem, m_status == WHISKERMENU_COMMAND_VALID);
+	gtk_widget_set_sensitive(m_menuitem, m_status == CommandStatus::Valid);
 
 	g_object_ref_sink(m_menuitem);
 
@@ -142,7 +133,7 @@ void Command::set(const gchar* command)
 
 	g_free(m_command);
 	m_command = g_strdup(command);
-	m_status = WHISKERMENU_COMMAND_UNCHECKED;
+	m_status = CommandStatus::Unchecked;
 	wm_settings->set_modified();
 }
 
@@ -172,31 +163,31 @@ void Command::set_shown(bool shown)
 
 void Command::check()
 {
-	if (m_status == WHISKERMENU_COMMAND_UNCHECKED)
+	if (m_status == CommandStatus::Unchecked)
 	{
 		gchar** argv;
 		if (g_shell_parse_argv(m_command, nullptr, &argv, nullptr))
 		{
 			gchar* path = g_find_program_in_path(argv[0]);
-			m_status = path ? WHISKERMENU_COMMAND_VALID : WHISKERMENU_COMMAND_INVALID;
+			m_status = path ? CommandStatus::Valid : CommandStatus::Invalid;
 			g_free(path);
 			g_strfreev(argv);
 		}
 		else
 		{
-			m_status = WHISKERMENU_COMMAND_INVALID;
+			m_status = CommandStatus::Invalid;
 		}
 	}
 
 	if (m_button)
 	{
 		gtk_widget_set_visible(m_button, m_shown);
-		gtk_widget_set_sensitive(m_button, m_status == WHISKERMENU_COMMAND_VALID);
+		gtk_widget_set_sensitive(m_button, m_status == CommandStatus::Valid);
 	}
 	if (m_menuitem)
 	{
 		gtk_widget_set_visible(m_menuitem, m_shown);
-		gtk_widget_set_sensitive(m_menuitem, m_status == WHISKERMENU_COMMAND_VALID);
+		gtk_widget_set_sensitive(m_menuitem, m_status == CommandStatus::Valid);
 	}
 }
 
diff --git a/panel-plugin/command.h b/panel-plugin/command.h
index 1e812c7..89dbc99 100644
--- a/panel-plugin/command.h
+++ b/panel-plugin/command.h
@@ -77,9 +77,16 @@ private:
 	gchar* m_text;
 	gchar* m_command;
 	gchar* m_error_text;
-	int m_status;
 	bool m_shown;
 
+	enum class CommandStatus
+	{
+		Unchecked,
+		Invalid,
+		Valid
+	}
+	m_status;
+
 	struct TimeoutDetails
 	{
 		GtkWidget* dialog;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list