[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 195/473: Disable command buttons for invalid user specified commands.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:56:05 CET 2015


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

gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit dc14f46d7a10cc99989b757fe008dd4bc3cb8362
Author: Graeme Gott <graeme at gottcode.org>
Date:   Tue Oct 29 09:28:27 2013 -0400

    Disable command buttons for invalid user specified commands.
---
 src/menu.cpp |   36 +++++++++++++++++++++++++++---------
 src/menu.hpp |   33 ++++++++++++++++++++++++++++++---
 2 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/src/menu.cpp b/src/menu.cpp
index 933b2ed..19fbe55 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -49,9 +49,9 @@ static GtkButton* new_action_button(const gchar* icon, const gchar* text)
 	return button;
 }
 
-std::string Menu::m_settings_command = "xfce4-settings-manager";
-std::string Menu::m_lockscreen_command = "xflock4";
-std::string Menu::m_logout_command = "xfce4-session-logout";
+Menu::Command Menu::m_settings_command = "xfce4-settings-manager";
+Menu::Command Menu::m_lockscreen_command = "xflock4";
+Menu::Command Menu::m_logout_command = "xfce4-session-logout";
 bool Menu::m_display_recent = false;
 bool Menu::m_position_search_alternate = false;
 bool Menu::m_position_commands_alternate = false;
@@ -290,6 +290,11 @@ void Menu::show(GtkWidget* parent, bool horizontal)
 	m_recent->get_view()->reload_icon_size();
 	m_applications->get_view()->reload_icon_size();
 
+	// Make sure commands are valid
+	check_command(m_settings_command, GTK_WIDGET(m_settings_button));
+	check_command(m_lockscreen_command, GTK_WIDGET(m_lock_screen_button));
+	check_command(m_logout_command, GTK_WIDGET(m_log_out_button));
+
 	// Make sure applications list is current; does nothing unless list has changed
 	m_applications->load_applications();
 
@@ -628,21 +633,21 @@ bool Menu::on_enter_notify_event(GdkEventCrossing* event)
 
 std::string Menu::get_settings_command()
 {
-	return m_settings_command;
+	return m_settings_command.m_exec;
 }
 
 //-----------------------------------------------------------------------------
 
 std::string Menu::get_lockscreen_command()
 {
-	return m_lockscreen_command;
+	return m_lockscreen_command.m_exec;
 }
 
 //-----------------------------------------------------------------------------
 
 std::string Menu::get_logout_command()
 {
-	return m_logout_command;
+	return m_logout_command.m_exec;
 }
 
 //-----------------------------------------------------------------------------
@@ -958,7 +963,7 @@ void Menu::launch_settings_manager()
 	hide();
 
 	GError* error = NULL;
-	if (g_spawn_command_line_async(m_settings_command.c_str(), &error) == false)
+	if (g_spawn_command_line_async(m_settings_command.m_exec.c_str(), &error) == false)
 	{
 		xfce_dialog_show_error(NULL, error, _("Failed to open settings manager."));
 		g_error_free(error);
@@ -972,7 +977,7 @@ void Menu::lock_screen()
 	hide();
 
 	GError* error = NULL;
-	if (g_spawn_command_line_async(m_lockscreen_command.c_str(), &error) == false)
+	if (g_spawn_command_line_async(m_lockscreen_command.m_exec.c_str(), &error) == false)
 	{
 		xfce_dialog_show_error(NULL, error, _("Failed to lock screen."));
 		g_error_free(error);
@@ -986,7 +991,7 @@ void Menu::log_out()
 	hide();
 
 	GError* error = NULL;
-	if (g_spawn_command_line_async(m_logout_command.c_str(), &error) == false)
+	if (g_spawn_command_line_async(m_logout_command.m_exec.c_str(), &error) == false)
 	{
 		xfce_dialog_show_error(NULL, error, _("Failed to log out."));
 		g_error_free(error);
@@ -994,3 +999,16 @@ void Menu::log_out()
 }
 
 //-----------------------------------------------------------------------------
+
+void Menu::check_command(Command& command, GtkWidget* button)
+{
+	if (command.m_status == Unchecked)
+	{
+		gchar* path = g_find_program_in_path(command.m_exec.c_str());
+		command.m_status = path ? Valid : Invalid;
+		g_free(path);
+	}
+	gtk_widget_set_sensitive(button, command.m_status == Valid);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/menu.hpp b/src/menu.hpp
index 4d89403..ae17c3a 100644
--- a/src/menu.hpp
+++ b/src/menu.hpp
@@ -41,6 +41,32 @@ class SectionButton;
 
 class Menu
 {
+	enum CommandStatus
+	{
+		Unchecked = -1,
+		Invalid,
+		Valid
+	};
+
+	struct Command
+	{
+		std::string m_exec;
+		CommandStatus m_status;
+
+		Command(const char* exec = NULL) :
+			m_exec(exec ? exec : ""),
+			m_status(Unchecked)
+		{
+		}
+
+		Command& operator=(const std::string& exec)
+		{
+			m_exec = exec;
+			m_status = Unchecked;
+			return *this;
+		}
+	};
+
 public:
 	explicit Menu(XfceRc* settings);
 	~Menu();
@@ -114,6 +140,7 @@ private:
 	void launch_settings_manager();
 	void lock_screen();
 	void log_out();
+	static void check_command(Command& command, GtkWidget* button);
 
 private:
 	GtkWindow* m_window;
@@ -154,9 +181,9 @@ private:
 	bool m_layout_commands_alternate;
 	bool m_modified;
 
-	static std::string m_settings_command;
-	static std::string m_lockscreen_command;
-	static std::string m_logout_command;
+	static Command m_settings_command;
+	static Command m_lockscreen_command;
+	static Command m_logout_command;
 	static bool m_display_recent;
 	static bool m_position_search_alternate;
 	static bool m_position_commands_alternate;

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


More information about the Xfce4-commits mailing list