[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 214/473: Use a singleton for settings.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:56:24 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 520a61de521532c4ac23a7cb45b9127f011aa148
Author: Graeme Gott <graeme at gottcode.org>
Date: Sat Nov 2 08:12:14 2013 -0400
Use a singleton for settings.
---
panel-plugin/CMakeLists.txt | 1 +
panel-plugin/applications-page.cpp | 25 +---
panel-plugin/applications-page.h | 3 -
panel-plugin/command-button.cpp | 2 +-
panel-plugin/command-button.h | 4 +-
panel-plugin/configuration-dialog.cpp | 59 +++++-----
panel-plugin/favorites-page.cpp | 44 ++-----
panel-plugin/favorites-page.h | 5 +-
panel-plugin/launcher-view.cpp | 22 +---
panel-plugin/launcher-view.h | 3 -
panel-plugin/launcher.cpp | 40 +------
panel-plugin/launcher.h | 5 -
panel-plugin/list-page.cpp | 37 +-----
panel-plugin/list-page.h | 15 +--
panel-plugin/plugin.cpp | 144 +++++++++--------------
panel-plugin/plugin.h | 28 +----
panel-plugin/recent-page.cpp | 15 ++-
panel-plugin/recent-page.h | 2 +-
panel-plugin/section-button.cpp | 37 +-----
panel-plugin/section-button.h | 5 -
panel-plugin/settings.cpp | 206 +++++++++++++++++++++++++++++++++
panel-plugin/settings.h | 78 +++++++++++++
panel-plugin/window.cpp | 146 ++++-------------------
panel-plugin/window.h | 23 +---
24 files changed, 433 insertions(+), 516 deletions(-)
diff --git a/panel-plugin/CMakeLists.txt b/panel-plugin/CMakeLists.txt
index 093a092..c831aeb 100644
--- a/panel-plugin/CMakeLists.txt
+++ b/panel-plugin/CMakeLists.txt
@@ -78,6 +78,7 @@ add_library(whiskermenu MODULE
resizer-widget.cpp
search-page.cpp
section-button.cpp
+ settings.cpp
window.cpp)
target_link_libraries(whiskermenu
diff --git a/panel-plugin/applications-page.cpp b/panel-plugin/applications-page.cpp
index 9dd0766..eeeb8ad 100644
--- a/panel-plugin/applications-page.cpp
+++ b/panel-plugin/applications-page.cpp
@@ -21,6 +21,7 @@
#include "launcher.h"
#include "launcher-view.h"
#include "section-button.h"
+#include "settings.h"
#include "window.h"
#include <algorithm>
@@ -29,10 +30,6 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-static bool f_load_hierarchy = false;
-
-//-----------------------------------------------------------------------------
-
ApplicationsPage::ApplicationsPage(Window* window) :
Page(window),
m_garcon_menu(NULL),
@@ -129,7 +126,7 @@ void ApplicationsPage::load_applications()
}
// Sort items and categories
- if (!f_load_hierarchy)
+ if (!wm_settings->load_hierarchy)
{
for (std::vector<Category*>::const_iterator i = m_categories.begin(), end = m_categories.end(); i != end; ++i)
{
@@ -210,7 +207,7 @@ void ApplicationsPage::load_menu(GarconMenu* menu, Category* parent_category)
category = new Category(directory);
m_categories.push_back(category);
}
- else if (!f_load_hierarchy)
+ else if (!wm_settings->load_hierarchy)
{
category = parent_category;
}
@@ -232,7 +229,7 @@ void ApplicationsPage::load_menu(GarconMenu* menu, Category* parent_category)
{
load_menu(GARCON_MENU(li->data), category);
}
- else if (GARCON_IS_MENU_SEPARATOR(li->data) && f_load_hierarchy && category)
+ else if (GARCON_IS_MENU_SEPARATOR(li->data) && wm_settings->load_hierarchy && category)
{
category->append_separator();
}
@@ -298,17 +295,3 @@ void ApplicationsPage::load_categories()
}
//-----------------------------------------------------------------------------
-
-bool ApplicationsPage::get_load_hierarchy()
-{
- return f_load_hierarchy;
-}
-
-//-----------------------------------------------------------------------------
-
-void ApplicationsPage::set_load_hierarchy(bool load)
-{
- f_load_hierarchy = load;
-}
-
-//-----------------------------------------------------------------------------
diff --git a/panel-plugin/applications-page.h b/panel-plugin/applications-page.h
index dfb3485..47d6026 100644
--- a/panel-plugin/applications-page.h
+++ b/panel-plugin/applications-page.h
@@ -49,9 +49,6 @@ public:
void invalidate_applications();
void load_applications();
- static bool get_load_hierarchy();
- static void set_load_hierarchy(bool load);
-
private:
void apply_filter(GtkToggleButton* togglebutton);
bool on_filter(GtkTreeModel* model, GtkTreeIter* iter);
diff --git a/panel-plugin/command-button.cpp b/panel-plugin/command-button.cpp
index c4bdf55..101299b 100644
--- a/panel-plugin/command-button.cpp
+++ b/panel-plugin/command-button.cpp
@@ -26,7 +26,7 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-CommandButton::CommandButton(const gchar* icon, const gchar* text, const std::string& command, const std::string& error_text) :
+CommandButton::CommandButton(const gchar* icon, const gchar* text, std::string& command, const std::string& error_text) :
m_command(command),
m_error_text(error_text),
m_status(Unchecked)
diff --git a/panel-plugin/command-button.h b/panel-plugin/command-button.h
index fede2cf..3440d34 100644
--- a/panel-plugin/command-button.h
+++ b/panel-plugin/command-button.h
@@ -38,7 +38,7 @@ class CommandButton
};
public:
- CommandButton(const gchar* icon, const gchar* text, const std::string& command, const std::string& error_text);
+ CommandButton(const gchar* icon, const gchar* text, std::string& command, const std::string& error_text);
~CommandButton();
GtkWidget* get_widget() const
@@ -60,7 +60,7 @@ private:
private:
GtkButton* m_button;
- std::string m_command;
+ std::string& m_command;
std::string m_error_text;
Status m_status;
diff --git a/panel-plugin/configuration-dialog.cpp b/panel-plugin/configuration-dialog.cpp
index eb6a012..bdd16be 100644
--- a/panel-plugin/configuration-dialog.cpp
+++ b/panel-plugin/configuration-dialog.cpp
@@ -17,14 +17,9 @@
#include "configuration-dialog.h"
-#include "applications-page.h"
-#include "favorites-page.h"
#include "icon-size.h"
-#include "launcher.h"
-#include "launcher-view.h"
#include "plugin.h"
-#include "section-button.h"
-#include "window.h"
+#include "settings.h"
extern "C"
{
@@ -119,7 +114,7 @@ void ConfigurationDialog::choose_icon()
void ConfigurationDialog::category_icon_size_changed(GtkComboBox* combo)
{
- SectionButton::set_icon_size(gtk_combo_box_get_active(combo));
+ wm_settings->category_icon_size = gtk_combo_box_get_active(combo);
m_plugin->reload();
}
@@ -127,7 +122,7 @@ void ConfigurationDialog::category_icon_size_changed(GtkComboBox* combo)
void ConfigurationDialog::item_icon_size_changed(GtkComboBox* combo)
{
- LauncherView::set_icon_size(gtk_combo_box_get_active(combo));
+ wm_settings->launcher_icon_size = gtk_combo_box_get_active(combo);
m_plugin->reload();
}
@@ -150,14 +145,14 @@ void ConfigurationDialog::title_changed()
void ConfigurationDialog::toggle_hover_switch_category(GtkToggleButton* button)
{
- SectionButton::set_hover_activate(gtk_toggle_button_get_active(button));
+ wm_settings->category_hover_activate = gtk_toggle_button_get_active(button);
}
//-----------------------------------------------------------------------------
void ConfigurationDialog::toggle_show_name(GtkToggleButton* button)
{
- Launcher::set_show_name(gtk_toggle_button_get_active(button));
+ wm_settings->launcher_show_name = gtk_toggle_button_get_active(button);
m_plugin->reload();
}
@@ -165,7 +160,7 @@ void ConfigurationDialog::toggle_show_name(GtkToggleButton* button)
void ConfigurationDialog::toggle_show_description(GtkToggleButton* button)
{
- Launcher::set_show_description(gtk_toggle_button_get_active(button));
+ wm_settings->launcher_show_description = gtk_toggle_button_get_active(button);
m_plugin->reload();
}
@@ -174,7 +169,7 @@ void ConfigurationDialog::toggle_show_description(GtkToggleButton* button)
void ConfigurationDialog::toggle_position_search_alternate(GtkToggleButton* button)
{
bool active = gtk_toggle_button_get_active(button);
- Window::set_position_search_alternate(gtk_toggle_button_get_active(button));
+ wm_settings->position_search_alternate = gtk_toggle_button_get_active(button);
gtk_widget_set_sensitive(GTK_WIDGET(m_position_commands_alternate), active);
m_plugin->reload();
}
@@ -183,7 +178,7 @@ void ConfigurationDialog::toggle_position_search_alternate(GtkToggleButton* butt
void ConfigurationDialog::toggle_position_commands_alternate(GtkToggleButton* button)
{
- Window::set_position_commands_alternate(gtk_toggle_button_get_active(button));
+ wm_settings->position_commands_alternate = gtk_toggle_button_get_active(button);
m_plugin->reload();
}
@@ -191,7 +186,7 @@ void ConfigurationDialog::toggle_position_commands_alternate(GtkToggleButton* bu
void ConfigurationDialog::toggle_load_hierarchy(GtkToggleButton* button)
{
- ApplicationsPage::set_load_hierarchy(gtk_toggle_button_get_active(button));
+ wm_settings->load_hierarchy = gtk_toggle_button_get_active(button);
m_plugin->reload();
}
@@ -199,14 +194,14 @@ void ConfigurationDialog::toggle_load_hierarchy(GtkToggleButton* button)
void ConfigurationDialog::toggle_remember_favorites(GtkToggleButton* button)
{
- FavoritesPage::set_remember_favorites(gtk_toggle_button_get_active(button));
+ wm_settings->favorites_in_recent = gtk_toggle_button_get_active(button);
}
//-----------------------------------------------------------------------------
void ConfigurationDialog::toggle_display_recent(GtkToggleButton* button)
{
- Window::set_display_recent(gtk_toggle_button_get_active(button));
+ wm_settings->display_recent = gtk_toggle_button_get_active(button);
m_plugin->reload();
}
@@ -215,7 +210,7 @@ void ConfigurationDialog::toggle_display_recent(GtkToggleButton* button)
void ConfigurationDialog::settings_command_changed()
{
const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_settings_command));
- m_plugin->get_window()->set_settings_command(text ? text : "");
+ wm_settings->command_settings = std::string(text ? text : "");
}
//-----------------------------------------------------------------------------
@@ -223,7 +218,7 @@ void ConfigurationDialog::settings_command_changed()
void ConfigurationDialog::lockscreen_command_changed()
{
const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_lockscreen_command));
- m_plugin->get_window()->set_lockscreen_command(text ? text : "");
+ wm_settings->command_lockscreen = std::string(text ? text : "");
}
//-----------------------------------------------------------------------------
@@ -231,7 +226,7 @@ void ConfigurationDialog::lockscreen_command_changed()
void ConfigurationDialog::logout_command_changed()
{
const gchar* text = gtk_entry_get_text(GTK_ENTRY(m_logout_command));
- m_plugin->get_window()->set_logout_command(text ? text : "");
+ wm_settings->command_logout = std::string(text ? text : "");
}
//-----------------------------------------------------------------------------
@@ -265,25 +260,25 @@ GtkWidget* ConfigurationDialog::init_appearance_tab()
// Add option to use generic names
m_show_names = gtk_check_button_new_with_mnemonic(_("Show applications by _name"));
gtk_box_pack_start(appearance_vbox, m_show_names, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_names), Launcher::get_show_name());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_names), wm_settings->launcher_show_name);
g_signal_connect(m_show_names, "toggled", G_CALLBACK(ConfigurationDialog::toggle_show_name_slot), this);
// Add option to hide descriptions
m_show_descriptions = gtk_check_button_new_with_mnemonic(_("Show application _descriptions"));
gtk_box_pack_start(appearance_vbox, m_show_descriptions, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_descriptions), Launcher::get_show_description());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_show_descriptions), wm_settings->launcher_show_description);
g_signal_connect(m_show_descriptions, "toggled", G_CALLBACK(ConfigurationDialog::toggle_show_description_slot), this);
// Add option to use alternate search entry position
m_position_search_alternate = gtk_check_button_new_with_mnemonic(_("Position _search entry next to panel button"));
gtk_box_pack_start(appearance_vbox, m_position_search_alternate, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_position_search_alternate), Window::get_position_search_alternate());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_position_search_alternate), wm_settings->position_search_alternate);
g_signal_connect(m_position_search_alternate, "toggled", G_CALLBACK(ConfigurationDialog::toggle_position_search_alternate_slot), this);
// Add option to use alternate commands position
m_position_commands_alternate = gtk_check_button_new_with_mnemonic(_("Position commands next to search _entry"));
gtk_box_pack_start(appearance_vbox, m_position_commands_alternate, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_position_commands_alternate), Window::get_position_commands_alternate());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_position_commands_alternate), wm_settings->position_commands_alternate);
gtk_widget_set_sensitive(GTK_WIDGET(m_position_commands_alternate), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_position_search_alternate)));
g_signal_connect(m_position_commands_alternate, "toggled", G_CALLBACK(ConfigurationDialog::toggle_position_commands_alternate_slot), this);
@@ -302,7 +297,7 @@ GtkWidget* ConfigurationDialog::init_appearance_tab()
{
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(m_item_icon_size), i->c_str());
}
- gtk_combo_box_set_active(GTK_COMBO_BOX(m_item_icon_size), LauncherView::get_icon_size());
+ gtk_combo_box_set_active(GTK_COMBO_BOX(m_item_icon_size), wm_settings->launcher_icon_size);
gtk_box_pack_start(hbox, m_item_icon_size, false, false, 0);
gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_item_icon_size);
g_signal_connect(m_item_icon_size, "changed", G_CALLBACK(ConfigurationDialog::item_icon_size_changed_slot), this);
@@ -321,7 +316,7 @@ GtkWidget* ConfigurationDialog::init_appearance_tab()
{
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(m_category_icon_size), i->c_str());
}
- gtk_combo_box_set_active(GTK_COMBO_BOX(m_category_icon_size), SectionButton::get_icon_size());
+ gtk_combo_box_set_active(GTK_COMBO_BOX(m_category_icon_size), wm_settings->category_icon_size);
gtk_box_pack_start(hbox, m_category_icon_size, false, false, 0);
gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_category_icon_size);
g_signal_connect(m_category_icon_size, "changed", G_CALLBACK(ConfigurationDialog::category_icon_size_changed_slot), this);
@@ -409,25 +404,25 @@ GtkWidget* ConfigurationDialog::init_behavior_tab()
// Add option to use generic names
m_hover_switch_category = gtk_check_button_new_with_mnemonic(_("Switch categories by _hovering"));
gtk_box_pack_start(behavior_vbox, m_hover_switch_category, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_hover_switch_category), SectionButton::get_hover_activate());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_hover_switch_category), wm_settings->category_hover_activate);
g_signal_connect(m_hover_switch_category, "toggled", G_CALLBACK(ConfigurationDialog::toggle_hover_switch_category_slot), this);
// Add option to load menu hierarchy
m_load_hierarchy = gtk_check_button_new_with_mnemonic(_("Load menu hie_rarchy"));
gtk_box_pack_start(behavior_vbox, m_load_hierarchy, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_load_hierarchy), ApplicationsPage::get_load_hierarchy());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_load_hierarchy), wm_settings->load_hierarchy);
g_signal_connect(m_load_hierarchy, "toggled", G_CALLBACK(ConfigurationDialog::toggle_load_hierarchy_slot), this);
// Add option to remember favorites
m_remember_favorites = gtk_check_button_new_with_mnemonic(_("Include _favorites in recently used"));
gtk_box_pack_start(behavior_vbox, m_remember_favorites, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_remember_favorites), FavoritesPage::get_remember_favorites());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_remember_favorites), wm_settings->favorites_in_recent);
g_signal_connect(m_remember_favorites, "toggled", G_CALLBACK(ConfigurationDialog::toggle_remember_favorites_slot), this);
// Add option to display recently used
m_display_recent = gtk_check_button_new_with_mnemonic(_("Display recently _used by default"));
gtk_box_pack_start(behavior_vbox, m_display_recent, true, true, 0);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_display_recent), Window::get_display_recent());
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_display_recent), wm_settings->display_recent);
g_signal_connect(m_display_recent, "toggled", G_CALLBACK(ConfigurationDialog::toggle_display_recent_slot), this);
return page;
@@ -456,7 +451,7 @@ GtkWidget* ConfigurationDialog::init_commands_tab()
gtk_size_group_add_widget(label_size_group, label);
m_settings_command = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(m_settings_command), m_plugin->get_window()->get_settings_command().c_str());
+ gtk_entry_set_text(GTK_ENTRY(m_settings_command), wm_settings->command_settings.c_str());
gtk_box_pack_start(hbox, m_settings_command, true, true, 0);
gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_settings_command);
g_signal_connect(m_settings_command, "changed", G_CALLBACK(ConfigurationDialog::settings_command_changed_slot), this);
@@ -471,7 +466,7 @@ GtkWidget* ConfigurationDialog::init_commands_tab()
gtk_size_group_add_widget(label_size_group, label);
m_lockscreen_command = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(m_lockscreen_command), m_plugin->get_window()->get_lockscreen_command().c_str());
+ gtk_entry_set_text(GTK_ENTRY(m_lockscreen_command), wm_settings->command_lockscreen.c_str());
gtk_box_pack_start(hbox, m_lockscreen_command, true, true, 0);
gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_lockscreen_command);
g_signal_connect(m_lockscreen_command, "changed", G_CALLBACK(ConfigurationDialog::lockscreen_command_changed_slot), this);
@@ -486,7 +481,7 @@ GtkWidget* ConfigurationDialog::init_commands_tab()
gtk_size_group_add_widget(label_size_group, label);
m_logout_command = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(m_logout_command), m_plugin->get_window()->get_logout_command().c_str());
+ gtk_entry_set_text(GTK_ENTRY(m_logout_command), wm_settings->command_logout.c_str());
gtk_box_pack_start(hbox, m_logout_command, true, true, 0);
gtk_label_set_mnemonic_widget(GTK_LABEL(label), m_logout_command);
g_signal_connect(m_logout_command, "changed", G_CALLBACK(ConfigurationDialog::logout_command_changed_slot), this);
diff --git a/panel-plugin/favorites-page.cpp b/panel-plugin/favorites-page.cpp
index 2a0e43d..52afe24 100644
--- a/panel-plugin/favorites-page.cpp
+++ b/panel-plugin/favorites-page.cpp
@@ -21,6 +21,7 @@
#include "launcher.h"
#include "launcher-model.h"
#include "launcher-view.h"
+#include "settings.h"
#include "window.h"
#include <algorithm>
@@ -29,22 +30,8 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-static bool f_remember_favorites = true;
-
-static const std::string default_favorites[4] =
-{
- "exo-terminal-emulator.desktop",
- "exo-file-manager.desktop",
- "exo-mail-reader.desktop",
- "exo-web-browser.desktop"
-};
-
-//-----------------------------------------------------------------------------
-
-FavoritesPage::FavoritesPage(XfceRc* settings, Window* window) :
- ListPage(settings, "favorites",
- std::vector<std::string>(default_favorites, default_favorites + 4),
- window)
+FavoritesPage::FavoritesPage(Window* window) :
+ ListPage(wm_settings->favorites, window)
{
get_view()->set_reorderable(true);
}
@@ -68,20 +55,6 @@ void FavoritesPage::add(Launcher* launcher)
//-----------------------------------------------------------------------------
-bool FavoritesPage::get_remember_favorites()
-{
- return f_remember_favorites;
-}
-
-//-----------------------------------------------------------------------------
-
-void FavoritesPage::set_remember_favorites(bool remember)
-{
- f_remember_favorites = remember;
-}
-
-//-----------------------------------------------------------------------------
-
void FavoritesPage::extend_context_menu(GtkWidget* menu)
{
GtkWidget* menuitem = gtk_separator_menu_item_new();
@@ -104,15 +77,14 @@ void FavoritesPage::extend_context_menu(GtkWidget* menu)
bool FavoritesPage::remember_launcher(Launcher* launcher)
{
- return f_remember_favorites ? true : !contains(launcher);
+ return wm_settings->favorites_in_recent ? true : !contains(launcher);
}
//-----------------------------------------------------------------------------
void FavoritesPage::sort(std::vector<Launcher*>& items) const
{
- const std::vector<std::string>& desktop_ids = get_desktop_ids();
- for (std::vector<std::string>::const_iterator i = desktop_ids.begin(), end = desktop_ids.end(); i != end; ++i)
+ for (std::vector<std::string>::const_iterator i = wm_settings->favorites.begin(), end = wm_settings->favorites.end(); i != end; ++i)
{
Launcher* launcher = get_window()->get_applications()->get_application(*i);
if (!launcher)
@@ -128,9 +100,10 @@ void FavoritesPage::sort(std::vector<Launcher*>& items) const
void FavoritesPage::sort_ascending()
{
- std::vector<std::string> desktop_ids;
std::vector<Launcher*> items;
sort(items);
+
+ std::vector<std::string> desktop_ids;
for (std::vector<Launcher*>::const_iterator i = items.begin(), end = items.end(); i != end; ++i)
{
desktop_ids.push_back((*i)->get_desktop_id());
@@ -142,9 +115,10 @@ void FavoritesPage::sort_ascending()
void FavoritesPage::sort_descending()
{
- std::vector<std::string> desktop_ids;
std::vector<Launcher*> items;
sort(items);
+
+ std::vector<std::string> desktop_ids;
for (std::vector<Launcher*>::const_reverse_iterator i = items.rbegin(), end = items.rend(); i != end; ++i)
{
desktop_ids.push_back((*i)->get_desktop_id());
diff --git a/panel-plugin/favorites-page.h b/panel-plugin/favorites-page.h
index 38d4657..6e140be 100644
--- a/panel-plugin/favorites-page.h
+++ b/panel-plugin/favorites-page.h
@@ -28,13 +28,10 @@ class Launcher;
class FavoritesPage : public ListPage
{
public:
- FavoritesPage(XfceRc* settings, Window* window);
+ FavoritesPage(Window* window);
void add(Launcher* launcher);
- static bool get_remember_favorites();
- static void set_remember_favorites(bool remember);
-
private:
void extend_context_menu(GtkWidget* menu);
bool remember_launcher(Launcher* launcher);
diff --git a/panel-plugin/launcher-view.cpp b/panel-plugin/launcher-view.cpp
index 4b71df1..aec277c 100644
--- a/panel-plugin/launcher-view.cpp
+++ b/panel-plugin/launcher-view.cpp
@@ -17,8 +17,8 @@
#include "launcher-view.h"
-#include "icon-size.h"
#include "launcher-model.h"
+#include "settings.h"
#include <algorithm>
@@ -32,8 +32,6 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-static IconSize f_icon_size(IconSize::Small);
-
static gboolean is_separator(GtkTreeModel* model, GtkTreeIter* iter, gpointer)
{
const gchar* text;
@@ -182,7 +180,7 @@ void LauncherView::reload_icon_size()
// Force exo to reload SVG icons
int size = 0;
g_object_get(m_icon_renderer, "size", &size, NULL);
- if (size != f_icon_size.get_size())
+ if (size != wm_settings->launcher_icon_size.get_size())
{
gtk_tree_view_remove_column(m_view, m_column);
create_column();
@@ -191,20 +189,6 @@ void LauncherView::reload_icon_size()
//-----------------------------------------------------------------------------
-int LauncherView::get_icon_size()
-{
- return f_icon_size;
-}
-
-//-----------------------------------------------------------------------------
-
-void LauncherView::set_icon_size(const int size)
-{
- f_icon_size = size;
-}
-
-//-----------------------------------------------------------------------------
-
void LauncherView::create_column()
{
m_column = gtk_tree_view_column_new();
@@ -212,7 +196,7 @@ void LauncherView::create_column()
gtk_tree_view_column_set_visible(m_column, true);
m_icon_renderer = exo_cell_renderer_icon_new();
- g_object_set(m_icon_renderer, "size", f_icon_size.get_size(), NULL);
+ g_object_set(m_icon_renderer, "size", wm_settings->launcher_icon_size.get_size(), NULL);
gtk_tree_view_column_pack_start(m_column, m_icon_renderer, false);
gtk_tree_view_column_add_attribute(m_column, m_icon_renderer, "icon", LauncherModel::COLUMN_ICON);
diff --git a/panel-plugin/launcher-view.h b/panel-plugin/launcher-view.h
index 774627d..6b498f2 100644
--- a/panel-plugin/launcher-view.h
+++ b/panel-plugin/launcher-view.h
@@ -62,9 +62,6 @@ public:
void reload_icon_size();
- static int get_icon_size();
- static void set_icon_size(const int size);
-
private:
void create_column();
bool on_key_press_event(GdkEventKey* event);
diff --git a/panel-plugin/launcher.cpp b/panel-plugin/launcher.cpp
index d5e033a..117494b 100644
--- a/panel-plugin/launcher.cpp
+++ b/panel-plugin/launcher.cpp
@@ -18,6 +18,7 @@
#include "launcher.h"
#include "query.h"
+#include "settings.h"
extern "C"
{
@@ -29,11 +30,6 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-static bool f_show_name = true;
-static bool f_show_description = true;
-
-//-----------------------------------------------------------------------------
-
static void replace_with_quoted_string(std::string& command, size_t& index, const gchar* unquoted)
{
if (!exo_str_is_empty(unquoted))
@@ -131,8 +127,8 @@ Launcher::Launcher(GarconMenuItem* item) :
// Create display text
const gchar* direction = (gtk_widget_get_default_direction() != GTK_TEXT_DIR_RTL) ? "\342\200\216" : "\342\200\217";
- m_display_name = (f_show_name || exo_str_is_empty(generic_name)) ? name : generic_name;
- if (f_show_description)
+ m_display_name = (wm_settings->launcher_show_name || exo_str_is_empty(generic_name)) ? name : generic_name;
+ if (wm_settings->launcher_show_description)
{
const gchar* details = garcon_menu_item_get_comment(m_item);
if (!details)
@@ -275,7 +271,7 @@ int Launcher::search(const Query& query) const
match += 10;
}
}
- if ((match == INT_MAX) && f_show_description)
+ if ((match == INT_MAX) && wm_settings->launcher_show_description)
{
match = query.match(m_search_comment);
if (match != INT_MAX)
@@ -288,31 +284,3 @@ int Launcher::search(const Query& query) const
}
//-----------------------------------------------------------------------------
-
-bool Launcher::get_show_name()
-{
- return f_show_name;
-}
-
-//-----------------------------------------------------------------------------
-
-bool Launcher::get_show_description()
-{
- return f_show_description;
-}
-
-//-----------------------------------------------------------------------------
-
-void Launcher::set_show_name(bool show)
-{
- f_show_name = show;
-}
-
-//-----------------------------------------------------------------------------
-
-void Launcher::set_show_description(bool show)
-{
- f_show_description = show;
-}
-
-//-----------------------------------------------------------------------------
diff --git a/panel-plugin/launcher.h b/panel-plugin/launcher.h
index f88c2ad..8537bcb 100644
--- a/panel-plugin/launcher.h
+++ b/panel-plugin/launcher.h
@@ -67,11 +67,6 @@ public:
int search(const Query& query) const;
- static bool get_show_name();
- static bool get_show_description();
- static void set_show_name(bool show);
- static void set_show_description(bool show);
-
private:
Launcher(const Launcher& launcher);
Launcher& operator=(const Launcher& launcher);
diff --git a/panel-plugin/list-page.cpp b/panel-plugin/list-page.cpp
index 29c8d63..5dc4381 100644
--- a/panel-plugin/list-page.cpp
+++ b/panel-plugin/list-page.cpp
@@ -29,26 +29,10 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-ListPage::ListPage(XfceRc* rc, const gchar* key, const std::vector<std::string>& default_desktop_ids, Window* window) :
+ListPage::ListPage(std::vector<std::string>& desktop_ids, Window* window) :
Page(window),
- m_key(key)
+ m_desktop_ids(desktop_ids)
{
- if (!rc || !xfce_rc_has_entry(rc, key))
- {
- m_desktop_ids = default_desktop_ids;
- return;
- }
-
- gchar** values = xfce_rc_read_list_entry(rc, key, ",");
- for (size_t i = 0; values[i] != NULL; ++i)
- {
- std::string desktop_id(values[i]);
- if (std::find(m_desktop_ids.begin(), m_desktop_ids.end(), desktop_id) == m_desktop_ids.end())
- {
- m_desktop_ids.push_back(desktop_id);
- }
- }
- g_strfreev(values);
}
//-----------------------------------------------------------------------------
@@ -81,23 +65,6 @@ void ListPage::remove(Launcher* launcher)
//-----------------------------------------------------------------------------
-void ListPage::save(XfceRc* settings)
-{
- // Save list
- std::string desktop_ids;
- for (std::vector<std::string>::const_iterator i = m_desktop_ids.begin(), end = m_desktop_ids.end(); i != end; ++i)
- {
- if (!desktop_ids.empty())
- {
- desktop_ids += ",";
- }
- desktop_ids += *i;
- }
- xfce_rc_write_entry(settings, m_key, desktop_ids.c_str());
-}
-
-//-----------------------------------------------------------------------------
-
void ListPage::set_menu_items()
{
// Create new model for treeview
diff --git a/panel-plugin/list-page.h b/panel-plugin/list-page.h
index 32688c7..bd7f8df 100644
--- a/panel-plugin/list-page.h
+++ b/panel-plugin/list-page.h
@@ -38,27 +38,17 @@ class LauncherView;
class ListPage : public Page
{
public:
- ListPage(XfceRc* settings, const gchar* key, const std::vector<std::string>& default_desktop_ids, Window* window);
+ ListPage(std::vector<std::string>& desktop_ids, Window* window);
~ListPage();
bool contains(Launcher* launcher) const;
- size_t size() const
- {
- return m_desktop_ids.size();
- }
virtual void add(Launcher* launcher)=0;
void remove(Launcher* launcher);
- void save(XfceRc* settings);
void set_menu_items();
void unset_menu_items();
protected:
- const std::vector<std::string>& get_desktop_ids() const
- {
- return m_desktop_ids;
- }
-
void set_desktop_ids(const std::vector<std::string>& desktop_ids);
private:
@@ -67,8 +57,7 @@ private:
void on_row_deleted(GtkTreePath*);
private:
- const gchar* m_key;
- std::vector<std::string> m_desktop_ids;
+ std::vector<std::string>& m_desktop_ids;
private:
diff --git a/panel-plugin/plugin.cpp b/panel-plugin/plugin.cpp
index 0d4aad0..affe0fb 100644
--- a/panel-plugin/plugin.cpp
+++ b/panel-plugin/plugin.cpp
@@ -19,11 +19,7 @@
#include "applications-page.h"
#include "configuration-dialog.h"
-#include "favorites-page.h"
-#include "icon-size.h"
-#include "launcher.h"
-#include "launcher-view.h"
-#include "section-button.h"
+#include "settings.h"
#include "window.h"
using namespace WhiskerMenu;
@@ -46,60 +42,30 @@ static void whiskermenu_free(XfcePanelPlugin*, Plugin* whiskermenu)
Plugin::Plugin(XfcePanelPlugin* plugin) :
m_plugin(plugin),
- m_window(NULL),
- m_button_title(get_button_title_default()),
- m_button_icon_name("xfce4-whiskermenu"),
- m_button_title_visible(false),
- m_button_icon_visible(true)
+ m_window(NULL)
{
// Load settings
- gchar* file = xfce_panel_plugin_lookup_rc_file(m_plugin);
- if (file)
- {
- XfceRc* settings = xfce_rc_simple_open(file, true);
- g_free(file);
-
- m_button_title = xfce_rc_read_entry(settings, "button-title", m_button_title.c_str());
- m_button_icon_name = xfce_rc_read_entry(settings, "button-icon", m_button_icon_name.c_str());
- m_button_title_visible = xfce_rc_read_bool_entry(settings, "show-button-title", m_button_title_visible);
- m_button_icon_visible = xfce_rc_read_bool_entry(settings, "show-button-icon", m_button_icon_visible);
- Launcher::set_show_name(xfce_rc_read_bool_entry(settings, "launcher-show-name", Launcher::get_show_name()));
- Launcher::set_show_description(xfce_rc_read_bool_entry(settings, "launcher-show-description", Launcher::get_show_description()));
- SectionButton::set_hover_activate(xfce_rc_read_bool_entry(settings, "hover-switch-category", SectionButton::get_hover_activate()));
- SectionButton::set_icon_size(xfce_rc_read_int_entry(settings, "category-icon-size", SectionButton::get_icon_size()));
- LauncherView::set_icon_size(xfce_rc_read_int_entry(settings, "item-icon-size", LauncherView::get_icon_size()));
- ApplicationsPage::set_load_hierarchy(xfce_rc_read_bool_entry(settings, "load-hierarchy", ApplicationsPage::get_load_hierarchy()));
- FavoritesPage::set_remember_favorites(xfce_rc_read_bool_entry(settings, "favorites-in-recent", FavoritesPage::get_remember_favorites()));
- Window::set_display_recent(xfce_rc_read_bool_entry(settings, "display-recent-default", Window::get_display_recent()));
- Window::set_position_search_alternate(xfce_rc_read_bool_entry(settings, "position-search-alternate", Window::get_position_search_alternate()));
- Window::set_position_commands_alternate(xfce_rc_read_bool_entry(settings, "position-commands-alternate", Window::get_position_commands_alternate()));
-
- m_window = new Window(settings);
- m_window->set_settings_command(xfce_rc_read_entry(settings, "command-settings", m_window->get_settings_command().c_str()));
- m_window->set_lockscreen_command(xfce_rc_read_entry(settings, "command-lockscreen", m_window->get_lockscreen_command().c_str()));
- m_window->set_logout_command(xfce_rc_read_entry(settings, "command-logout", m_window->get_logout_command().c_str()));
-
- xfce_rc_close(settings);
- }
- else
- {
- m_window = new Window(NULL);
- }
- g_signal_connect(m_window->get_widget(), "unmap", G_CALLBACK(Plugin::menu_hidden_slot), this);
+ wm_settings = new Settings;
+ wm_settings->button_title = get_button_title_default();
+ wm_settings->load(xfce_panel_plugin_lookup_rc_file(m_plugin));
// Prevent empty panel button
- if (!m_button_icon_visible)
+ if (!wm_settings->button_icon_visible)
{
- if (!m_button_title_visible)
+ if (!wm_settings->button_title_visible)
{
- m_button_icon_visible = true;
+ wm_settings->button_icon_visible = true;
}
- else if (m_button_title.empty())
+ else if (wm_settings->button_title.empty())
{
- m_button_title = get_button_title_default();
+ wm_settings->button_title = get_button_title_default();
}
}
+ // Create menu window
+ m_window = new Window;
+ g_signal_connect(m_window->get_widget(), "unmap", G_CALLBACK(Plugin::menu_hidden_slot), this);
+
// Create toggle button
m_button = xfce_create_panel_toggle_button();
gtk_button_set_relief(GTK_BUTTON(m_button), GTK_RELIEF_NONE);
@@ -110,17 +76,17 @@ Plugin::Plugin(XfcePanelPlugin* plugin) :
gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(m_button_box));
gtk_widget_show(GTK_WIDGET(m_button_box));
- m_button_icon = XFCE_PANEL_IMAGE(xfce_panel_image_new_from_source(m_button_icon_name.c_str()));
+ m_button_icon = XFCE_PANEL_IMAGE(xfce_panel_image_new_from_source(wm_settings->button_icon_name.c_str()));
gtk_box_pack_start(m_button_box, GTK_WIDGET(m_button_icon), false, false, 0);
- if (m_button_icon_visible)
+ if (wm_settings->button_icon_visible)
{
gtk_widget_show(GTK_WIDGET(m_button_icon));
}
m_button_label = GTK_LABEL(gtk_label_new(NULL));
- gtk_label_set_markup(m_button_label, m_button_title.c_str());
+ gtk_label_set_markup(m_button_label, wm_settings->button_title.c_str());
gtk_box_pack_start(m_button_box, GTK_WIDGET(m_button_label), false, false, 0);
- if (m_button_title_visible)
+ if (wm_settings->button_title_visible)
{
gtk_widget_show(GTK_WIDGET(m_button_label));
}
@@ -152,11 +118,28 @@ Plugin::~Plugin()
delete m_window;
m_window = NULL;
+ delete wm_settings;
+ wm_settings = NULL;
+
gtk_widget_destroy(m_button);
}
//-----------------------------------------------------------------------------
+Plugin::ButtonStyle Plugin::get_button_style() const
+{
+ return ButtonStyle(wm_settings->button_icon_visible | (wm_settings->button_title_visible << 1));
+}
+
+//-----------------------------------------------------------------------------
+
+std::string Plugin::get_button_title() const
+{
+ return wm_settings->button_title;
+}
+
+//-----------------------------------------------------------------------------
+
std::string Plugin::get_button_title_default()
{
return _("Applications Menu");
@@ -164,6 +147,13 @@ std::string Plugin::get_button_title_default()
//-----------------------------------------------------------------------------
+std::string Plugin::get_button_icon_name() const
+{
+ return wm_settings->button_icon_name;
+}
+
+//-----------------------------------------------------------------------------
+
void Plugin::reload()
{
m_window->hide();
@@ -174,8 +164,8 @@ void Plugin::reload()
void Plugin::set_button_style(ButtonStyle style)
{
- m_button_icon_visible = style & ShowIcon;
- if (m_button_icon_visible)
+ wm_settings->button_icon_visible = style & ShowIcon;
+ if (wm_settings->button_icon_visible)
{
gtk_widget_show(GTK_WIDGET(m_button_icon));
}
@@ -184,8 +174,8 @@ void Plugin::set_button_style(ButtonStyle style)
gtk_widget_hide(GTK_WIDGET(m_button_icon));
}
- m_button_title_visible = style & ShowText;
- if (m_button_title_visible)
+ wm_settings->button_title_visible = style & ShowText;
+ if (wm_settings->button_title_visible)
{
gtk_widget_show(GTK_WIDGET(m_button_label));
}
@@ -201,8 +191,8 @@ void Plugin::set_button_style(ButtonStyle style)
void Plugin::set_button_title(const std::string& title)
{
- m_button_title = title;
- gtk_label_set_markup(m_button_label, m_button_title.c_str());
+ wm_settings->button_title = title;
+ gtk_label_set_markup(m_button_label, wm_settings->button_title.c_str());
size_changed(xfce_panel_plugin_get_size(m_plugin));
}
@@ -210,7 +200,7 @@ void Plugin::set_button_title(const std::string& title)
void Plugin::set_button_icon_name(const std::string& icon)
{
- m_button_icon_name = icon;
+ wm_settings->button_icon_name = icon;
xfce_panel_image_set_from_source(m_button_icon, icon.c_str());
size_changed(xfce_panel_plugin_get_size(m_plugin));
}
@@ -304,34 +294,8 @@ bool Plugin::remote_event(gchar* name, GValue* value)
void Plugin::save()
{
- gchar* file = xfce_panel_plugin_save_location(m_plugin, true);
- if (!file)
- {
- return;
- }
- XfceRc* settings = xfce_rc_simple_open(file, false);
- g_free(file);
-
- xfce_rc_write_entry(settings, "button-title", m_button_title.c_str());
- xfce_rc_write_entry(settings, "button-icon", m_button_icon_name.c_str());
- xfce_rc_write_bool_entry(settings, "show-button-title", m_button_title_visible);
- xfce_rc_write_bool_entry(settings, "show-button-icon", m_button_icon_visible);
- xfce_rc_write_bool_entry(settings, "launcher-show-name", Launcher::get_show_name());
- xfce_rc_write_bool_entry(settings, "launcher-show-description", Launcher::get_show_description());
- xfce_rc_write_bool_entry(settings, "hover-switch-category", SectionButton::get_hover_activate());
- xfce_rc_write_int_entry(settings, "category-icon-size", SectionButton::get_icon_size());
- xfce_rc_write_int_entry(settings, "item-icon-size", LauncherView::get_icon_size());
- xfce_rc_write_bool_entry(settings, "load-hierarchy", ApplicationsPage::get_load_hierarchy());
- xfce_rc_write_bool_entry(settings, "favorites-in-recent", FavoritesPage::get_remember_favorites());
- xfce_rc_write_bool_entry(settings, "display-recent-default", Window::get_display_recent());
- xfce_rc_write_bool_entry(settings, "position-search-alternate", Window::get_position_search_alternate());
- xfce_rc_write_bool_entry(settings, "position-commands-alternate", Window::get_position_commands_alternate());
- xfce_rc_write_entry(settings, "command-settings", m_window->get_settings_command().c_str());
- xfce_rc_write_entry(settings, "command-lockscreen", m_window->get_lockscreen_command().c_str());
- xfce_rc_write_entry(settings, "command-logout", m_window->get_logout_command().c_str());
- m_window->save(settings);
-
- xfce_rc_close(settings);
+ m_window->save();
+ wm_settings->save(xfce_panel_plugin_save_location(m_plugin, true));
}
//-----------------------------------------------------------------------------
@@ -348,11 +312,11 @@ bool Plugin::size_changed(int size)
// Make icon expand to fill button if title is not visible
gtk_box_set_child_packing(GTK_BOX(m_button_box), GTK_WIDGET(m_button_icon),
- !m_button_title_visible,
- !m_button_title_visible,
+ !wm_settings->button_title_visible,
+ !wm_settings->button_title_visible,
0, GTK_PACK_START);
- if (!m_button_title_visible)
+ if (!wm_settings->button_title_visible)
{
xfce_panel_image_set_size(m_button_icon, -1);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
diff --git a/panel-plugin/plugin.h b/panel-plugin/plugin.h
index e2cb882..75b2c45 100644
--- a/panel-plugin/plugin.h
+++ b/panel-plugin/plugin.h
@@ -49,27 +49,10 @@ public:
ShowIconAndText = ShowIcon | ShowText
};
- Window* get_window() const
- {
- return m_window;
- }
-
- ButtonStyle get_button_style() const
- {
- return ButtonStyle(m_button_icon_visible | (m_button_title_visible << 1));
- }
-
- std::string get_button_title() const
- {
- return m_button_title;
- }
-
+ ButtonStyle get_button_style() const;
+ std::string get_button_title() const;
static std::string get_button_title_default();
-
- std::string get_button_icon_name() const
- {
- return m_button_icon_name;
- }
+ std::string get_button_icon_name() const;
void reload();
void set_button_style(ButtonStyle style);
@@ -91,11 +74,6 @@ private:
XfcePanelPlugin* m_plugin;
Window* m_window;
- std::string m_button_title;
- std::string m_button_icon_name;
- bool m_button_title_visible;
- bool m_button_icon_visible;
-
GtkWidget* m_button;
GtkBox* m_button_box;
GtkLabel* m_button_label;
diff --git a/panel-plugin/recent-page.cpp b/panel-plugin/recent-page.cpp
index 1f4e1ff..dd08bea 100644
--- a/panel-plugin/recent-page.cpp
+++ b/panel-plugin/recent-page.cpp
@@ -20,22 +20,21 @@
#include "launcher.h"
#include "launcher-model.h"
#include "launcher-view.h"
+#include "settings.h"
#include "window.h"
using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-RecentPage::RecentPage(XfceRc* settings, Window* window) :
- ListPage(settings, "recent", std::vector<std::string>(), window),
+RecentPage::RecentPage(Window* window) :
+ ListPage(wm_settings->recent, window),
m_max_items(10)
{
// Prevent going over max
- if (size() > m_max_items)
+ if (wm_settings->recent.size() > m_max_items)
{
- std::vector<std::string> desktop_ids = get_desktop_ids();
- desktop_ids.erase(desktop_ids.begin() + m_max_items, desktop_ids.end());
- set_desktop_ids(desktop_ids);
+ wm_settings->recent.erase(wm_settings->recent.begin() + m_max_items, wm_settings->recent.end());
}
}
@@ -56,7 +55,7 @@ void RecentPage::add(Launcher* launcher)
model.prepend_item(launcher);
// Prevent going over max
- while (size() > m_max_items)
+ while (wm_settings->recent.size() > m_max_items)
{
model.remove_last_item();
}
@@ -81,7 +80,7 @@ void RecentPage::extend_context_menu(GtkWidget* menu)
void RecentPage::clear_menu()
{
LauncherModel model(GTK_LIST_STORE(get_view()->get_model()));
- for (size_t i = 0, count = size(); i < count; ++i)
+ for (size_t i = 0, count = wm_settings->recent.size(); i < count; ++i)
{
model.remove_first_item();
}
diff --git a/panel-plugin/recent-page.h b/panel-plugin/recent-page.h
index 874022c..33969d0 100644
--- a/panel-plugin/recent-page.h
+++ b/panel-plugin/recent-page.h
@@ -29,7 +29,7 @@ class LauncherView;
class RecentPage : public ListPage
{
public:
- RecentPage(XfceRc* settings, Window* window);
+ RecentPage(Window* window);
void add(Launcher* launcher);
diff --git a/panel-plugin/section-button.cpp b/panel-plugin/section-button.cpp
index cbe30c6..690371a 100644
--- a/panel-plugin/section-button.cpp
+++ b/panel-plugin/section-button.cpp
@@ -17,7 +17,7 @@
#include "section-button.h"
-#include "icon-size.h"
+#include "settings.h"
extern "C"
{
@@ -28,9 +28,6 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-static bool f_hover_activate = false;
-static WhiskerMenu::IconSize f_icon_size(WhiskerMenu::IconSize::Smaller);
-
static gboolean hover_timeout(GtkToggleButton* button)
{
if (gtk_widget_get_state(GTK_WIDGET(button)) == GTK_STATE_PRELIGHT)
@@ -42,7 +39,7 @@ static gboolean hover_timeout(GtkToggleButton* button)
static gboolean on_enter_notify_event(GtkWidget*, GdkEventCrossing*, GtkToggleButton* button)
{
- if (f_hover_activate && !gtk_toggle_button_get_active(button))
+ if (wm_settings->category_hover_activate && !gtk_toggle_button_get_active(button))
{
g_timeout_add(150, (GSourceFunc)hover_timeout, button);
}
@@ -81,35 +78,7 @@ SectionButton::~SectionButton()
void SectionButton::reload_icon_size()
{
- xfce_panel_image_set_size(XFCE_PANEL_IMAGE(m_icon), f_icon_size.get_size());
-}
-
-//-----------------------------------------------------------------------------
-
-bool SectionButton::get_hover_activate()
-{
- return f_hover_activate;
-}
-
-//-----------------------------------------------------------------------------
-
-void SectionButton::set_hover_activate(bool hover_activate)
-{
- f_hover_activate = hover_activate;
-}
-
-//-----------------------------------------------------------------------------
-
-int SectionButton::get_icon_size()
-{
- return f_icon_size;
-}
-
-//-----------------------------------------------------------------------------
-
-void SectionButton::set_icon_size(const int size)
-{
- f_icon_size = size;
+ xfce_panel_image_set_size(XFCE_PANEL_IMAGE(m_icon), wm_settings->category_icon_size.get_size());
}
//-----------------------------------------------------------------------------
diff --git a/panel-plugin/section-button.h b/panel-plugin/section-button.h
index 485f34e..921e8c6 100644
--- a/panel-plugin/section-button.h
+++ b/panel-plugin/section-button.h
@@ -59,11 +59,6 @@ public:
void reload_icon_size();
- static bool get_hover_activate();
- static void set_hover_activate(bool hover_activate);
- static int get_icon_size();
- static void set_icon_size(const int size);
-
private:
GtkRadioButton* m_button;
GtkWidget* m_icon;
diff --git a/panel-plugin/settings.cpp b/panel-plugin/settings.cpp
new file mode 100644
index 0000000..078f398
--- /dev/null
+++ b/panel-plugin/settings.cpp
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "settings.h"
+
+#include <algorithm>
+
+extern "C"
+{
+#include <libxfce4util/libxfce4util.h>
+}
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+Settings* WhiskerMenu::wm_settings = NULL;
+
+//-----------------------------------------------------------------------------
+
+static void read_vector_entry(XfceRc* rc, const char* key, std::vector<std::string>& desktop_ids)
+{
+ if (!xfce_rc_has_entry(rc, key))
+ {
+ return;
+ }
+
+ desktop_ids.clear();
+
+ gchar** values = xfce_rc_read_list_entry(rc, key, ",");
+ for (size_t i = 0; values[i] != NULL; ++i)
+ {
+ std::string desktop_id(values[i]);
+ if (std::find(desktop_ids.begin(), desktop_ids.end(), desktop_id) == desktop_ids.end())
+ {
+ desktop_ids.push_back(desktop_id);
+ }
+ }
+ g_strfreev(values);
+}
+
+//-----------------------------------------------------------------------------
+
+static void write_vector_entry(XfceRc* rc, const char* key, const std::vector<std::string>& desktop_ids)
+{
+ const std::vector<std::string>::size_type size = desktop_ids.size();
+ gchar** values = g_new0(gchar*, size + 1);
+ for (std::vector<std::string>::size_type i = 0; i < size; ++i)
+ {
+ values[i] = g_strdup(desktop_ids[i].c_str());
+ }
+ xfce_rc_write_list_entry(rc, key, values, ",");
+ g_strfreev(values);
+}
+
+//-----------------------------------------------------------------------------
+
+Settings::Settings() :
+ button_icon_name("xfce4-whiskermenu"),
+ button_title_visible(false),
+ button_icon_visible(true),
+
+ launcher_show_name(true),
+ launcher_show_description(true),
+ launcher_icon_size(IconSize::Small),
+
+ category_hover_activate(false),
+ category_icon_size(IconSize::Smaller),
+
+ load_hierarchy(false),
+ favorites_in_recent(true),
+
+ display_recent(false),
+ position_search_alternate(false),
+ position_commands_alternate(false),
+
+ command_settings("xfce4-settings-manager"),
+ command_lockscreen("xflock4"),
+ command_logout("xfce4-session-logout"),
+
+ menu_width(400),
+ menu_height(500)
+{
+ favorites.push_back("exo-terminal-emulator.desktop");
+ favorites.push_back("exo-file-manager.desktop");
+ favorites.push_back("exo-mail-reader.desktop");
+ favorites.push_back("exo-web-browser.desktop");
+}
+
+//-----------------------------------------------------------------------------
+
+Settings::~Settings()
+{
+}
+
+//-----------------------------------------------------------------------------
+
+void Settings::load(char* file)
+{
+ if (!file)
+ {
+ return;
+ }
+
+ XfceRc* rc = xfce_rc_simple_open(file, true);
+ g_free(file);
+ if (!rc)
+ {
+ return;
+ }
+
+ read_vector_entry(rc, "favorites", favorites);
+ read_vector_entry(rc, "recent", recent);
+
+ button_title = xfce_rc_read_entry(rc, "button-title", button_title.c_str());
+ button_icon_name = xfce_rc_read_entry(rc, "button-icon", button_icon_name.c_str());
+ button_title_visible = xfce_rc_read_bool_entry(rc, "show-button-title", button_title_visible);
+ button_icon_visible = xfce_rc_read_bool_entry(rc, "show-button-icon", button_icon_visible);
+
+ launcher_show_name = xfce_rc_read_bool_entry(rc, "launcher-show-name", launcher_show_name);
+ launcher_show_description = xfce_rc_read_bool_entry(rc, "launcher-show-description", launcher_show_description);
+ launcher_icon_size = xfce_rc_read_int_entry(rc, "item-icon-size", launcher_icon_size);
+
+ category_hover_activate = xfce_rc_read_bool_entry(rc, "hover-switch-category", category_hover_activate);
+ category_icon_size = xfce_rc_read_int_entry(rc, "category-icon-size", category_icon_size);
+
+ load_hierarchy = xfce_rc_read_bool_entry(rc, "load-hierarchy", load_hierarchy);
+ favorites_in_recent = xfce_rc_read_bool_entry(rc, "favorites-in-recent", favorites_in_recent);
+
+ display_recent = xfce_rc_read_bool_entry(rc, "display-recent-default", display_recent);
+ 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 = xfce_rc_read_entry(rc, "command-settings", command_settings.c_str());
+ command_lockscreen = xfce_rc_read_entry(rc, "command-lockscreen", command_lockscreen.c_str());
+ command_logout = xfce_rc_read_entry(rc, "command-logout", command_logout.c_str());
+
+ 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));
+
+ xfce_rc_close(rc);
+}
+
+//-----------------------------------------------------------------------------
+
+void Settings::save(char* file)
+{
+ if (!file)
+ {
+ return;
+ }
+
+ XfceRc* rc = xfce_rc_simple_open(file, false);
+ g_free(file);
+ if (!rc)
+ {
+ return;
+ }
+
+ write_vector_entry(rc, "favorites", favorites);
+ write_vector_entry(rc, "recent", recent);
+
+ xfce_rc_write_entry(rc, "button-title", button_title.c_str());
+ xfce_rc_write_entry(rc, "button-icon", button_icon_name.c_str());
+ xfce_rc_write_bool_entry(rc, "show-button-title", button_title_visible);
+ xfce_rc_write_bool_entry(rc, "show-button-icon", button_icon_visible);
+
+ xfce_rc_write_bool_entry(rc, "launcher-show-name", launcher_show_name);
+ xfce_rc_write_bool_entry(rc, "launcher-show-description", launcher_show_description);
+ xfce_rc_write_int_entry(rc, "item-icon-size", launcher_icon_size);
+
+ xfce_rc_write_bool_entry(rc, "hover-switch-category", category_hover_activate);
+ xfce_rc_write_int_entry(rc, "category-icon-size", category_icon_size);
+
+ xfce_rc_write_bool_entry(rc, "load-hierarchy", load_hierarchy);
+ xfce_rc_write_bool_entry(rc, "favorites-in-recent", favorites_in_recent);
+
+ xfce_rc_write_bool_entry(rc, "display-recent-default", display_recent);
+ 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.c_str());
+ xfce_rc_write_entry(rc, "command-lockscreen", command_lockscreen.c_str());
+ xfce_rc_write_entry(rc, "command-logout", command_logout.c_str());
+
+ xfce_rc_write_int_entry(rc, "menu-width", menu_width);
+ xfce_rc_write_int_entry(rc, "menu-height", menu_height);
+
+ xfce_rc_close(rc);
+}
+
+//-----------------------------------------------------------------------------
diff --git a/panel-plugin/settings.h b/panel-plugin/settings.h
new file mode 100644
index 0000000..cc25949
--- /dev/null
+++ b/panel-plugin/settings.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef WHISKERMENU_SETTINGS_H
+#define WHISKERMENU_SETTINGS_H
+
+#include "icon-size.h"
+
+#include <string>
+#include <vector>
+
+namespace WhiskerMenu
+{
+
+class Plugin;
+
+class Settings
+{
+ Settings();
+ Settings(const Settings&);
+ Settings& operator=(const Settings&);
+ ~Settings();
+
+ void load(char* file);
+ void save(char* file);
+
+public:
+ std::vector<std::string> favorites;
+ std::vector<std::string> recent;
+
+ std::string button_title;
+ std::string button_icon_name;
+ bool button_title_visible;
+ bool button_icon_visible;
+
+ bool launcher_show_name;
+ bool launcher_show_description;
+ IconSize launcher_icon_size;
+
+ bool category_hover_activate;
+ IconSize category_icon_size;
+
+ bool load_hierarchy;
+ bool favorites_in_recent;
+
+ bool display_recent;
+ bool position_search_alternate;
+ bool position_commands_alternate;
+
+ std::string command_settings;
+ std::string command_lockscreen;
+ std::string command_logout;
+
+ int menu_width;
+ int menu_height;
+
+ friend class Plugin;
+};
+
+extern Settings* wm_settings;
+
+}
+
+#endif // WHISKERMENU_SETTINGS_H
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index 33cefcd..2552447 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -25,6 +25,7 @@
#include "resizer-widget.h"
#include "search-page.h"
#include "section-button.h"
+#include "settings.h"
extern "C"
{
@@ -39,13 +40,7 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-bool Window::m_display_recent = false;
-bool Window::m_position_search_alternate = false;
-bool Window::m_position_commands_alternate = false;
-
-//-----------------------------------------------------------------------------
-
-Window::Window(XfceRc* settings) :
+Window::Window() :
m_window(NULL),
m_layout_left(true),
m_layout_bottom(true),
@@ -55,8 +50,8 @@ Window::Window(XfceRc* settings) :
{
m_geometry.x = 0;
m_geometry.y = 0;
- m_geometry.width = 400;
- m_geometry.height = 500;
+ m_geometry.width = wm_settings->menu_width;
+ m_geometry.height = wm_settings->menu_height;
// Create the window
m_window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
@@ -94,13 +89,16 @@ Window::Window(XfceRc* settings) :
g_free(username);
// Create action buttons
- m_settings_button = new CommandButton("preferences-desktop", _("All Settings"), "xfce4-settings-manager", _("Failed to open settings manager."));
+ m_settings_button = new CommandButton("preferences-desktop", _("All Settings"),
+ wm_settings->command_settings, _("Failed to open settings manager."));
g_signal_connect_swapped(m_settings_button->get_widget(), "clicked", G_CALLBACK(Window::hide_slot), this);
- m_lockscreen_button = new CommandButton("system-lock-screen", _("Lock Screen"), "xflock4", _("Failed to lock screen."));
+ m_lockscreen_button = new CommandButton("system-lock-screen", _("Lock Screen"),
+ wm_settings->command_lockscreen, _("Failed to lock screen."));
g_signal_connect_swapped(m_lockscreen_button->get_widget(), "clicked", G_CALLBACK(Window::hide_slot), this);
- m_logout_button = new CommandButton("system-log-out", _("Log Out"), "xfce4-session-logout", _("Failed to log out."));
+ m_logout_button = new CommandButton("system-log-out", _("Log Out"),
+ wm_settings->command_logout, _("Failed to log out."));
g_signal_connect_swapped(m_logout_button->get_widget(), "clicked", G_CALLBACK(Window::hide_slot), this);
m_resizer = new ResizerWidget(m_window);
@@ -112,13 +110,13 @@ Window::Window(XfceRc* settings) :
g_signal_connect(m_search_entry, "changed", G_CALLBACK(Window::search_slot), this);
// Create favorites
- m_favorites = new FavoritesPage(settings, this);
+ m_favorites = new FavoritesPage(this);
m_favorites_button = new SectionButton("user-bookmarks", _("Favorites"));
g_signal_connect(m_favorites_button->get_button(), "toggled", G_CALLBACK(Window::favorites_toggled_slot), this);
// Create recent
- m_recent = new RecentPage(settings, this);
+ m_recent = new RecentPage(this);
m_recent_button = new SectionButton("document-open-recent", _("Recently Used"));
m_recent_button->set_group(m_favorites_button->get_group());
@@ -131,7 +129,7 @@ Window::Window(XfceRc* settings) :
m_search_results = new SearchPage(this);
// Handle default page
- if (!m_display_recent)
+ if (!wm_settings->display_recent)
{
m_default_button = m_favorites_button;
m_default_page = m_favorites;
@@ -213,11 +211,6 @@ Window::Window(XfceRc* settings) :
gtk_widget_show(frame);
// Resize to last known size
- if (settings)
- {
- m_geometry.width = std::max(300, xfce_rc_read_int_entry(settings, "menu-width", m_geometry.width));
- m_geometry.height = std::max(400, xfce_rc_read_int_entry(settings, "menu-height", m_geometry.height));
- }
gtk_window_set_default_size(m_window, m_geometry.width, m_geometry.height);
g_object_ref_sink(m_window);
@@ -250,12 +243,12 @@ void Window::hide()
gtk_widget_hide(GTK_WIDGET(m_window));
// Update default page
- if (m_display_recent && (m_default_page == m_favorites))
+ if (wm_settings->display_recent && (m_default_page == m_favorites))
{
m_default_button = m_recent_button;
m_default_page = m_recent;
}
- else if (!m_display_recent && (m_default_page == m_recent))
+ else if (!wm_settings->display_recent && (m_default_page == m_recent))
{
m_default_button = m_favorites_button;
m_default_page = m_favorites;
@@ -411,10 +404,10 @@ void Window::show(GtkWidget* parent, bool horizontal)
{
layout_left = !layout_left;
}
- if (m_layout_commands_alternate != m_position_commands_alternate)
+ if (m_layout_commands_alternate != wm_settings->position_commands_alternate)
{
m_layout_left = !layout_left;
- m_layout_commands_alternate = m_position_commands_alternate;
+ m_layout_commands_alternate = wm_settings->position_commands_alternate;
if (m_layout_commands_alternate)
{
g_object_ref(m_commands_align);
@@ -503,10 +496,10 @@ void Window::show(GtkWidget* parent, bool horizontal)
}
}
- if ((layout_bottom != m_layout_bottom) || (m_layout_search_alternate != m_position_search_alternate))
+ if ((layout_bottom != m_layout_bottom) || (m_layout_search_alternate != wm_settings->position_search_alternate))
{
m_layout_bottom = layout_bottom;
- m_layout_search_alternate = m_position_search_alternate;
+ m_layout_search_alternate = wm_settings->position_search_alternate;
if (m_layout_bottom && m_layout_search_alternate)
{
gtk_box_reorder_child(m_vbox, GTK_WIDGET(m_title_box), 0);
@@ -540,16 +533,11 @@ void Window::show(GtkWidget* parent, bool horizontal)
//-----------------------------------------------------------------------------
-void Window::save(XfceRc* settings)
+void Window::save()
{
- if (settings)
- {
- m_favorites->save(settings);
- m_recent->save(settings);
- xfce_rc_write_int_entry(settings, "menu-width", m_geometry.width);
- xfce_rc_write_int_entry(settings, "menu-height", m_geometry.height);
- m_modified = false;
- }
+ wm_settings->menu_width = m_geometry.width;
+ wm_settings->menu_height = m_geometry.height;
+ m_modified = false;
}
//-----------------------------------------------------------------------------
@@ -622,94 +610,6 @@ bool Window::on_enter_notify_event(GdkEventCrossing* event)
//-----------------------------------------------------------------------------
-std::string Window::get_settings_command()
-{
- return m_settings_button->get_command();
-}
-
-//-----------------------------------------------------------------------------
-
-std::string Window::get_lockscreen_command()
-{
- return m_lockscreen_button->get_command();
-}
-
-//-----------------------------------------------------------------------------
-
-std::string Window::get_logout_command()
-{
- return m_logout_button->get_command();
-}
-
-//-----------------------------------------------------------------------------
-
-void Window::set_settings_command(const std::string& command)
-{
- m_settings_button->set_command(command);
-}
-
-//-----------------------------------------------------------------------------
-
-void Window::set_lockscreen_command(const std::string& command)
-{
- m_lockscreen_button->set_command(command);
-}
-
-//-----------------------------------------------------------------------------
-
-void Window::set_logout_command(const std::string& command)
-{
- m_logout_button->set_command(command);
-}
-
-//-----------------------------------------------------------------------------
-
-bool Window::get_display_recent()
-{
- return m_display_recent;
-}
-
-//-----------------------------------------------------------------------------
-
-bool Window::get_position_search_alternate()
-{
- return m_position_search_alternate;
-}
-
-//-----------------------------------------------------------------------------
-
-bool Window::get_position_commands_alternate()
-{
- return m_position_commands_alternate;
-}
-
-//-----------------------------------------------------------------------------
-
-void Window::set_display_recent(bool display)
-{
- m_display_recent = display;
-}
-
-//-----------------------------------------------------------------------------
-
-void Window::set_position_search_alternate(bool alternate)
-{
- m_position_search_alternate = alternate;
- if (!alternate)
- {
- m_position_commands_alternate = false;
- }
-}
-
-//-----------------------------------------------------------------------------
-
-void Window::set_position_commands_alternate(bool alternate)
-{
- m_position_commands_alternate = alternate && m_position_search_alternate;
-}
-
-//-----------------------------------------------------------------------------
-
bool Window::on_leave_notify_event(GdkEventCrossing* event)
{
if ( (event->detail == GDK_NOTIFY_INFERIOR)
diff --git a/panel-plugin/window.h b/panel-plugin/window.h
index f20016c..45be561 100644
--- a/panel-plugin/window.h
+++ b/panel-plugin/window.h
@@ -18,7 +18,6 @@
#ifndef WHISKERMENU_WINDOW_H
#define WHISKERMENU_WINDOW_H
-#include <map>
#include <string>
#include <vector>
@@ -44,7 +43,7 @@ class SectionButton;
class Window
{
public:
- explicit Window(XfceRc* settings);
+ explicit Window();
~Window();
GtkWidget* get_widget() const
@@ -79,26 +78,12 @@ public:
void hide();
void show(GtkWidget* parent, bool horizontal);
- void save(XfceRc* settings);
+ void save();
void set_categories(const std::vector<SectionButton*>& categories);
void set_items();
void set_modified();
void unset_items();
- std::string get_settings_command();
- std::string get_lockscreen_command();
- std::string get_logout_command();
- void set_settings_command(const std::string& command);
- void set_lockscreen_command(const std::string& command);
- void set_logout_command(const std::string& command);
-
- static bool get_display_recent();
- static bool get_position_search_alternate();
- static bool get_position_commands_alternate();
- static void set_display_recent(bool display);
- static void set_position_search_alternate(bool alternate);
- static void set_position_commands_alternate(bool alternate);
-
private:
bool on_enter_notify_event(GdkEventCrossing* event);
bool on_leave_notify_event(GdkEventCrossing* event);
@@ -154,10 +139,6 @@ private:
bool m_layout_commands_alternate;
bool m_modified;
- static bool m_display_recent;
- static bool m_position_search_alternate;
- static bool m_position_commands_alternate;
-
private:
static gboolean on_enter_notify_event_slot(GtkWidget*, GdkEventCrossing* event, Window* obj)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list