[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 256/473: Use an array for commands.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:57:06 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 e403a7a73b3a01c4b9b47321a77f67ef0a969ab8
Author: Graeme Gott <graeme at gottcode.org>
Date:   Wed Nov 20 19:39:12 2013 -0500

    Use an array for commands.
---
 panel-plugin/configuration-dialog.cpp |   44 ++++++++--------------
 panel-plugin/configuration-dialog.h   |    8 ++--
 panel-plugin/plugin.cpp               |    2 +-
 panel-plugin/settings.cpp             |   66 ++++++++++++++-------------------
 panel-plugin/settings.h               |   15 +++++---
 panel-plugin/window.cpp               |   61 +++++++++++++++---------------
 panel-plugin/window.h                 |    1 +
 7 files changed, 90 insertions(+), 107 deletions(-)

diff --git a/panel-plugin/configuration-dialog.cpp b/panel-plugin/configuration-dialog.cpp
index 263ac75..638c46c 100644
--- a/panel-plugin/configuration-dialog.cpp
+++ b/panel-plugin/configuration-dialog.cpp
@@ -77,11 +77,10 @@ ConfigurationDialog::ConfigurationDialog(Plugin* plugin) :
 
 ConfigurationDialog::~ConfigurationDialog()
 {
-	delete m_settings_command;
-	delete m_lockscreen_command;
-	delete m_switchuser_command;
-	delete m_logout_command;
-	delete m_menueditor_command;
+	for (std::vector<CommandEdit*>::size_type i = 0; i < m_commands.size(); ++i)
+	{
+		delete m_commands[i];
+	}
 
 	m_plugin->set_configure_enabled(true);
 }
@@ -222,11 +221,10 @@ void ConfigurationDialog::response(int response_id)
 		m_plugin->set_button_title(Plugin::get_button_title_default());
 	}
 
-	wm_settings->command_settings->check();
-	wm_settings->command_lockscreen->check();
-	wm_settings->command_switchuser->check();
-	wm_settings->command_logout->check();
-	wm_settings->command_menueditor->check();
+	for (int i = 0; i < Settings::CountCommands; ++i)
+	{
+		wm_settings->command[i]->check();
+	}
 
 	if (response_id == GTK_RESPONSE_CLOSE)
 	{
@@ -416,25 +414,13 @@ GtkWidget* ConfigurationDialog::init_behavior_tab()
 	gtk_box_pack_start(behavior_vbox, commands_frame, false, false, 6);
 	gtk_container_set_border_width(GTK_CONTAINER(commands_frame), 0);
 
-	// Add settings command entry
-	m_settings_command = new CommandEdit(wm_settings->command_settings, label_size_group);
-	gtk_box_pack_start(commands_vbox, m_settings_command->get_widget(), false, false, 0);
-
-	// Add lock screen command entry
-	m_lockscreen_command = new CommandEdit(wm_settings->command_lockscreen, label_size_group);
-	gtk_box_pack_start(commands_vbox, m_lockscreen_command->get_widget(), false, false, 0);
-
-	// Add switch user command entry
-	m_switchuser_command = new CommandEdit(wm_settings->command_switchuser, label_size_group);
-	gtk_box_pack_start(commands_vbox, m_switchuser_command->get_widget(), false, false, 0);
-
-	// Add log out command entry
-	m_logout_command = new CommandEdit(wm_settings->command_logout, label_size_group);
-	gtk_box_pack_start(commands_vbox, m_logout_command->get_widget(), false, false, 0);
-
-	// Add menu editor command entry
-	m_menueditor_command = new CommandEdit(wm_settings->command_menueditor, label_size_group);
-	gtk_box_pack_start(commands_vbox, m_menueditor_command->get_widget(), false, false, 0);
+	// Add command entries
+	for (int i = 0; i < Settings::CountCommands; ++i)
+	{
+		CommandEdit* command_edit = new CommandEdit(wm_settings->command[i], label_size_group);
+		gtk_box_pack_start(commands_vbox, command_edit->get_widget(), false, false, 0);
+		m_commands.push_back(command_edit);
+	}
 
 	return page;
 }
diff --git a/panel-plugin/configuration-dialog.h b/panel-plugin/configuration-dialog.h
index ed30074..30282a7 100644
--- a/panel-plugin/configuration-dialog.h
+++ b/panel-plugin/configuration-dialog.h
@@ -18,6 +18,8 @@
 #ifndef WHISKERMENU_CONFIGURATION_DIALOG_H
 #define WHISKERMENU_CONFIGURATION_DIALOG_H
 
+#include <vector>
+
 #include <gtk/gtk.h>
 
 namespace WhiskerMenu
@@ -78,11 +80,7 @@ private:
 	GtkWidget* m_hover_switch_category;
 	GtkWidget* m_remember_favorites;
 	GtkWidget* m_display_recent;
-	CommandEdit* m_settings_command;
-	CommandEdit* m_lockscreen_command;
-	CommandEdit* m_switchuser_command;
-	CommandEdit* m_logout_command;
-	CommandEdit* m_menueditor_command;
+	std::vector<CommandEdit*> m_commands;
 
 
 private:
diff --git a/panel-plugin/plugin.cpp b/panel-plugin/plugin.cpp
index 5f29700..a6256dd 100644
--- a/panel-plugin/plugin.cpp
+++ b/panel-plugin/plugin.cpp
@@ -115,7 +115,7 @@ Plugin::Plugin(XfcePanelPlugin* plugin) :
 	g_signal_connect(plugin, "size-changed", G_CALLBACK(Plugin::size_changed_slot), this);
 
 	xfce_panel_plugin_menu_show_configure(plugin);
-	xfce_panel_plugin_menu_insert_item(plugin, GTK_MENU_ITEM(wm_settings->command_menueditor->get_menuitem()));
+	xfce_panel_plugin_menu_insert_item(plugin, GTK_MENU_ITEM(wm_settings->command[Settings::CommandMenuEditor]->get_menuitem()));
 
 #if (LIBXFCE4PANEL_CHECK_VERSION(4,9,0))
 	mode_changed_slot(m_plugin, xfce_panel_plugin_get_mode(m_plugin), this);
diff --git a/panel-plugin/settings.cpp b/panel-plugin/settings.cpp
index 62d81a9..9c9978c 100644
--- a/panel-plugin/settings.cpp
+++ b/panel-plugin/settings.cpp
@@ -29,6 +29,14 @@ using namespace WhiskerMenu;
 
 Settings* WhiskerMenu::wm_settings = NULL;
 
+static const char* const settings_command[Settings::CountCommands][2] = {
+	{ "command-settings",   "show-command-settings"   },
+	{ "command-lockscreen", "show-command-lockscreen" },
+	{ "command-switchuser", "show-command-switchuser" },
+	{ "command-logout",     "show-command-logout"     },
+	{ "command-menueditor", "show-command-menueditor" }
+};
+
 //-----------------------------------------------------------------------------
 
 static void read_vector_entry(XfceRc* rc, const char* key, std::vector<std::string>& desktop_ids)
@@ -97,22 +105,21 @@ Settings::Settings() :
 	favorites.push_back("exo-mail-reader.desktop");
 	favorites.push_back("exo-web-browser.desktop");
 
-	command_settings = new Command("preferences-desktop", _("All _Settings"), "xfce4-settings-manager", _("Failed to open settings manager."));
-	command_lockscreen = new Command("system-lock-screen", _("_Lock Screen"), "xflock4", _("Failed to lock screen."));
-	command_switchuser = new Command("system-users", _("Switch _Users"), "gdmflexiserver", _("Failed to switch users."));
-	command_logout = new Command("system-log-out", _("Log _Out"), "xfce4-session-logout", _("Failed to log out."));
-	command_menueditor = new Command("xfce4-menueditor", _("_Edit Applications"), "menulibre", _("Failed to launch menu editor."));
+	command[CommandSettings] = new Command("preferences-desktop", _("All _Settings"), "xfce4-settings-manager", _("Failed to open settings manager."));
+	command[CommandLockScreen] = new Command("system-lock-screen", _("_Lock Screen"), "xflock4", _("Failed to lock screen."));
+	command[CommandSwitchUser] = new Command("system-users", _("Switch _Users"), "gdmflexiserver", _("Failed to switch users."));
+	command[CommandLogOut] = new Command("system-log-out", _("Log _Out"), "xfce4-session-logout", _("Failed to log out."));
+	command[CommandMenuEditor] = new Command("xfce4-menueditor", _("_Edit Applications"), "menulibre", _("Failed to launch menu editor."));
 }
 
 //-----------------------------------------------------------------------------
 
 Settings::~Settings()
 {
-	delete command_settings;
-	delete command_lockscreen;
-	delete command_switchuser;
-	delete command_logout;
-	delete command_menueditor;
+	for (int i = 0; i < CountCommands; ++i)
+	{
+		delete command[i];
+	}
 }
 
 //-----------------------------------------------------------------------------
@@ -153,17 +160,12 @@ void Settings::load(char* file)
 	position_search_alternate = xfce_rc_read_bool_entry(rc, "position-search-alternate", position_search_alternate);
 	position_commands_alternate = xfce_rc_read_bool_entry(rc, "position-commands-alternate", position_commands_alternate) && position_search_alternate;
 
-	command_settings->set(xfce_rc_read_entry(rc, "command-settings", command_settings->get()));
-	command_lockscreen->set(xfce_rc_read_entry(rc, "command-lockscreen", command_lockscreen->get()));
-	command_switchuser->set(xfce_rc_read_entry(rc, "command-switchuser", command_switchuser->get()));
-	command_logout->set(xfce_rc_read_entry(rc, "command-logout", command_logout->get()));
-	command_menueditor->set(xfce_rc_read_entry(rc, "command-menueditor", command_menueditor->get()));
-
-	command_settings->set_shown(xfce_rc_read_bool_entry(rc, "show-command-settings", command_settings->get_shown()));
-	command_lockscreen->set_shown(xfce_rc_read_bool_entry(rc, "show-command-lockscreen", command_lockscreen->get_shown()));
-	command_switchuser->set_shown(xfce_rc_read_bool_entry(rc, "show-command-switchuser", command_switchuser->get_shown()));
-	command_logout->set_shown(xfce_rc_read_bool_entry(rc, "show-command-logout", command_logout->get_shown()));
-	command_menueditor->set_shown(xfce_rc_read_bool_entry(rc, "show-command-menueditor", command_menueditor->get_shown()));
+	for (int i = 0; i < CountCommands; ++i)
+	{
+		command[i]->set(xfce_rc_read_entry(rc, settings_command[i][0], command[i]->get()));
+		command[i]->set_shown(xfce_rc_read_bool_entry(rc, settings_command[i][1], command[i]->get_shown()));
+		command[i]->check();
+	}
 
 	menu_width = std::max(300, xfce_rc_read_int_entry(rc, "menu-width", menu_width));
 	menu_height = std::max(400, xfce_rc_read_int_entry(rc, "menu-height", menu_height));
@@ -171,12 +173,6 @@ void Settings::load(char* file)
 	xfce_rc_close(rc);
 
 	m_modified = false;
-
-	command_settings->check();
-	command_lockscreen->check();
-	command_switchuser->check();
-	command_logout->check();
-	command_menueditor->check();
 }
 
 //-----------------------------------------------------------------------------
@@ -217,17 +213,11 @@ void Settings::save(char* file)
 	xfce_rc_write_bool_entry(rc, "position-search-alternate", position_search_alternate);
 	xfce_rc_write_bool_entry(rc, "position-commands-alternate", position_commands_alternate);
 
-	xfce_rc_write_entry(rc, "command-settings", command_settings->get());
-	xfce_rc_write_entry(rc, "command-lockscreen", command_lockscreen->get());
-	xfce_rc_write_entry(rc, "command-switchuser", command_switchuser->get());
-	xfce_rc_write_entry(rc, "command-logout", command_logout->get());
-	xfce_rc_write_entry(rc, "command-menueditor", command_menueditor->get());
-
-	xfce_rc_write_bool_entry(rc, "show-command-settings", command_settings->get_shown());
-	xfce_rc_write_bool_entry(rc, "show-command-lockscreen", command_lockscreen->get_shown());
-	xfce_rc_write_bool_entry(rc, "show-command-switchuser", command_switchuser->get_shown());
-	xfce_rc_write_bool_entry(rc, "show-command-logout", command_logout->get_shown());
-	xfce_rc_write_bool_entry(rc, "show-command-menueditor", command_menueditor->get_shown());
+	for (int i = 0; i < CountCommands; ++i)
+	{
+		xfce_rc_write_entry(rc, settings_command[i][0], command[i]->get());
+		xfce_rc_write_bool_entry(rc, settings_command[i][1], command[i]->get_shown());
+	}
 
 	xfce_rc_write_int_entry(rc, "menu-width", menu_width);
 	xfce_rc_write_int_entry(rc, "menu-height", menu_height);
diff --git a/panel-plugin/settings.h b/panel-plugin/settings.h
index 5b9efbd..55e22fc 100644
--- a/panel-plugin/settings.h
+++ b/panel-plugin/settings.h
@@ -75,11 +75,16 @@ public:
 	bool position_search_alternate;
 	bool position_commands_alternate;
 
-	Command* command_settings;
-	Command* command_lockscreen;
-	Command* command_switchuser;
-	Command* command_logout;
-	Command* command_menueditor;
+	enum Commands
+	{
+		CommandSettings = 0,
+		CommandLockScreen,
+		CommandSwitchUser,
+		CommandLogOut,
+		CommandMenuEditor,
+		CountCommands
+	};
+	Command* command[CountCommands];
 
 	int menu_width;
 	int menu_height;
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index 69515fb..6f16699 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -102,10 +102,14 @@ Window::Window() :
 	g_free(username);
 
 	// Create action buttons
-	g_signal_connect_swapped(wm_settings->command_settings->get_button(), "clicked", G_CALLBACK(Window::hide_slot), this);
-	g_signal_connect_swapped(wm_settings->command_lockscreen->get_button(), "clicked", G_CALLBACK(Window::hide_slot), this);
-	g_signal_connect_swapped(wm_settings->command_switchuser->get_button(), "clicked", G_CALLBACK(Window::hide_slot), this);
-	g_signal_connect_swapped(wm_settings->command_logout->get_button(), "clicked", G_CALLBACK(Window::hide_slot), this);
+	m_commands_button[0] = wm_settings->command[Settings::CommandSettings]->get_button();
+	m_commands_button[1] = wm_settings->command[Settings::CommandLockScreen]->get_button();
+	m_commands_button[2] = wm_settings->command[Settings::CommandSwitchUser]->get_button();
+	m_commands_button[3] = wm_settings->command[Settings::CommandLogOut]->get_button();
+	for (int i = 0; i < 4; ++i)
+	{
+		g_signal_connect_swapped(m_commands_button[i], "clicked", G_CALLBACK(Window::hide_slot), this);
+	}
 
 	m_resizer = new ResizerWidget(m_window);
 
@@ -154,10 +158,10 @@ Window::Window() :
 	// Create box for packing commands
 	m_commands_align = GTK_ALIGNMENT(gtk_alignment_new(1, 0, 0, 0));
 	m_commands_box = GTK_BOX(gtk_hbox_new(false, 0));
-	gtk_box_pack_start(m_commands_box, GTK_WIDGET(wm_settings->command_settings->get_button()), false, false, 0);
-	gtk_box_pack_start(m_commands_box, GTK_WIDGET(wm_settings->command_lockscreen->get_button()), false, false, 0);
-	gtk_box_pack_start(m_commands_box, GTK_WIDGET(wm_settings->command_switchuser->get_button()), false, false, 0);
-	gtk_box_pack_start(m_commands_box, GTK_WIDGET(wm_settings->command_logout->get_button()), false, false, 0);
+	for (int i = 0; i < 4; ++i)
+	{
+		gtk_box_pack_start(m_commands_box, m_commands_button[i], false, false, 0);
+	}
 	gtk_container_add(GTK_CONTAINER(m_commands_align), GTK_WIDGET(m_commands_box));
 
 	// Create box for packing username, commands, and resize widget
@@ -264,11 +268,10 @@ void Window::show(GtkWidget* parent, bool horizontal)
 	m_applications->get_view()->reload_icon_size();
 
 	// Make sure commands are valid and visible
-	wm_settings->command_settings->check();
-	wm_settings->command_lockscreen->check();
-	wm_settings->command_switchuser->check();
-	wm_settings->command_logout->check();
-	wm_settings->command_menueditor->check();
+	for (int i = 0; i < Settings::CountCommands; ++i)
+	{
+		wm_settings->command[i]->check();
+	}
 
 	// Make sure applications list is current; does nothing unless list has changed
 	if (m_applications->load_applications())
@@ -440,10 +443,10 @@ void Window::show(GtkWidget* parent, bool horizontal)
 			gtk_misc_set_alignment(GTK_MISC(m_username), 0.0f, 0.5f);
 
 			gtk_alignment_set(m_commands_align, 1, 0, 0, 0);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_settings->get_button()), 0);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_lockscreen->get_button()), 1);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_switchuser->get_button()), 2);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_logout->get_button()), 3);
+			for (int i = 0; i < 4; ++i)
+			{
+				gtk_box_reorder_child(m_commands_box, m_commands_button[i], i);
+			}
 
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 0);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 1);
@@ -459,10 +462,10 @@ void Window::show(GtkWidget* parent, bool horizontal)
 			gtk_misc_set_alignment(GTK_MISC(m_username), 1.0f, 0.5f);
 
 			gtk_alignment_set(m_commands_align, 0, 0, 0, 0);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_settings->get_button()), 3);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_lockscreen->get_button()), 2);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_switchuser->get_button()), 1);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_logout->get_button()), 0);
+			for (int i = 0; i < 4; ++i)
+			{
+				gtk_box_reorder_child(m_commands_box, m_commands_button[i], 3 - i);
+			}
 
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 1);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_resizer->get_widget()), 0);
@@ -478,10 +481,10 @@ void Window::show(GtkWidget* parent, bool horizontal)
 			gtk_misc_set_alignment(GTK_MISC(m_username), 0.0f, 0.5f);
 
 			gtk_alignment_set(m_commands_align, 1, 0, 0, 0);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_settings->get_button()), 0);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_lockscreen->get_button()), 1);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_switchuser->get_button()), 2);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_logout->get_button()), 3);
+			for (int i = 0; i < 4; ++i)
+			{
+				gtk_box_reorder_child(m_commands_box, m_commands_button[i], i);
+			}
 
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 0);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_commands_align), 1);
@@ -495,10 +498,10 @@ void Window::show(GtkWidget* parent, bool horizontal)
 			gtk_misc_set_alignment(GTK_MISC(m_username), 1.0f, 0.5f);
 
 			gtk_alignment_set(m_commands_align, 0, 0, 0, 0);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_settings->get_button()), 3);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_lockscreen->get_button()), 2);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_switchuser->get_button()), 1);
-			gtk_box_reorder_child(m_commands_box, GTK_WIDGET(wm_settings->command_logout->get_button()), 0);
+			for (int i = 0; i < 4; ++i)
+			{
+				gtk_box_reorder_child(m_commands_box, m_commands_button[i], 3 - i);
+			}
 
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_username), 2);
 			gtk_box_reorder_child(m_title_box, GTK_WIDGET(m_commands_align), 1);
diff --git a/panel-plugin/window.h b/panel-plugin/window.h
index 9a2d974..3749a84 100644
--- a/panel-plugin/window.h
+++ b/panel-plugin/window.h
@@ -108,6 +108,7 @@ private:
 	ResizerWidget* m_resizer;
 
 	GtkAlignment* m_commands_align;
+	GtkWidget* m_commands_button[4];
 
 	GtkEntry* m_search_entry;
 

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


More information about the Xfce4-commits mailing list