[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 06/09: Load applications in a thread. (bug #12903)

noreply at xfce.org noreply at xfce.org
Sun Apr 15 01:13:25 CEST 2018


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 5c285dc7de12df8ae9ea7e13ac3f339952506161
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Oct 16 18:55:08 2017 -0400

    Load applications in a thread. (bug #12903)
---
 panel-plugin/applications-page.cpp | 50 ++++++++++++++++++++++++++++++++------
 panel-plugin/applications-page.h   | 17 +++++++++++--
 panel-plugin/window.cpp            | 37 ++++++++++++++++++++++++----
 panel-plugin/window.h              |  4 +++
 4 files changed, 94 insertions(+), 14 deletions(-)

diff --git a/panel-plugin/applications-page.cpp b/panel-plugin/applications-page.cpp
index 376fcb9..631e2d7 100644
--- a/panel-plugin/applications-page.cpp
+++ b/panel-plugin/applications-page.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015, 2016 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2015, 2016, 2017 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
@@ -49,6 +49,7 @@ ApplicationsPage::ApplicationsPage(Window* window) :
 	Page(window),
 	m_garcon_menu(NULL),
 	m_garcon_settings_menu(NULL),
+	m_load_thread(NULL),
 	m_load_status(STATUS_INVALID)
 {
 	// Set desktop environment for applications
@@ -161,20 +162,36 @@ void ApplicationsPage::invalidate_applications()
 
 //-----------------------------------------------------------------------------
 
-void ApplicationsPage::load_applications()
+bool ApplicationsPage::load_applications()
 {
 	// Check if already loaded
 	if (m_load_status == STATUS_LOADED)
 	{
-		return;
+		return true;
+	}
+	// Check if currently loading
+	else if (m_load_status == STATUS_LOADING)
+	{
+		return false;
+	}
+	// Check if loading garcon
+	else if (m_load_thread)
+	{
+		return false;
 	}
 	m_load_status = STATUS_LOADING;
 
 	// Load menu
 	clear_applications();
-	load_contents();
 
-	return;
+	// Load contents in thread if possible
+	m_load_thread = g_thread_try_new(NULL, &ApplicationsPage::load_garcon_menu_slot, this, NULL);
+	if (!m_load_thread)
+	{
+		load_garcon_menu();
+	}
+
+	return false;
 }
 
 //-----------------------------------------------------------------------------
@@ -225,7 +242,7 @@ void ApplicationsPage::clear_applications()
 
 //-----------------------------------------------------------------------------
 
-void ApplicationsPage::load_contents()
+void ApplicationsPage::load_garcon_menu()
 {
 	// Create menu
 	if (wm_settings->custom_menu_file.empty())
@@ -288,9 +305,26 @@ void ApplicationsPage::load_contents()
 	category->sort();
 	m_categories.insert(m_categories.begin(), category);
 
+	g_idle_add(&ApplicationsPage::load_contents_slot, this);
+}
+
+//-----------------------------------------------------------------------------
+
+void ApplicationsPage::load_contents()
+{
+	if (!m_garcon_menu)
+	{
+		get_window()->set_loaded();
+
+		m_load_status = STATUS_INVALID;
+		m_load_thread = NULL;
+
+		return;
+	}
+
 	// Set all applications category
 	get_view()->set_fixed_height_mode(true);
-	get_view()->set_model(category->get_model());
+	get_view()->set_model(m_categories.front()->get_model());
 
 	// Add buttons for categories
 	std::vector<SectionButton*> category_buttons;
@@ -306,8 +340,10 @@ void ApplicationsPage::load_contents()
 
 	// Update menu items of other panels
 	get_window()->set_items();
+	get_window()->set_loaded();
 
 	m_load_status = STATUS_LOADED;
+	m_load_thread = NULL;
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/applications-page.h b/panel-plugin/applications-page.h
index 295d4d3..65abeea 100644
--- a/panel-plugin/applications-page.h
+++ b/panel-plugin/applications-page.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2015, 2017 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
@@ -43,7 +43,7 @@ public:
 	Launcher* get_application(const std::string& desktop_id) const;
 
 	void invalidate_applications();
-	void load_applications();
+	bool load_applications();
 	void reload_category_icon_size();
 
 private:
@@ -54,11 +54,24 @@ private:
 	void load_menu(GarconMenu* menu, Category* parent_category);
 	void load_menu_item(GarconMenuItem* menu_item, Category* category);
 
+	static gpointer load_garcon_menu_slot(gpointer obj)
+	{
+		reinterpret_cast<ApplicationsPage*>(obj)->load_garcon_menu();
+		return NULL;
+	}
+
+	static gboolean load_contents_slot(gpointer obj)
+	{
+		reinterpret_cast<ApplicationsPage*>(obj)->load_contents();
+		return G_SOURCE_REMOVE;
+	}
+
 private:
 	GarconMenu* m_garcon_menu;
 	GarconMenu* m_garcon_settings_menu;
 	std::vector<Category*> m_categories;
 	std::map<std::string, Launcher*> m_items;
+	GThread* m_load_thread;
 	int m_load_status;
 };
 
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index 7e84460..e6d82d3 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -125,6 +125,16 @@ WhiskerMenu::Window::Window() :
 	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
 	gtk_container_add(GTK_CONTAINER(m_window), frame);
 
+	// Create window contents stack
+	m_window_stack = GTK_STACK(gtk_stack_new());
+	gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(m_window_stack));
+
+	// Create loading message
+	m_window_load_spinner = GTK_SPINNER(gtk_spinner_new());
+	gtk_widget_set_halign(GTK_WIDGET(m_window_load_spinner), GTK_ALIGN_CENTER);
+	gtk_widget_set_valign(GTK_WIDGET(m_window_load_spinner), GTK_ALIGN_CENTER);
+	gtk_stack_add_named(m_window_stack, GTK_WIDGET(m_window_load_spinner), "load");
+
 	// Create the profile picture
 	m_profilepic = new ProfilePicture(this);
 
@@ -191,8 +201,8 @@ WhiskerMenu::Window::Window() :
 
 	// Create box for packing children
 	m_vbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 6));
-	gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(m_vbox));
 	gtk_container_set_border_width(GTK_CONTAINER(m_vbox), 2);
+	gtk_stack_add_named(m_window_stack, GTK_WIDGET(m_vbox), "contents");
 
 	// Create box for packing commands
 	m_commands_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
@@ -339,10 +349,15 @@ void WhiskerMenu::Window::show(GtkWidget* parent, bool horizontal)
 	m_recent->enforce_item_count();
 
 	// Make sure applications list is current; does nothing unless list has changed
-	m_applications->load_applications();
-
-	// Focus search entry
-	gtk_widget_grab_focus(GTK_WIDGET(m_search_entry));
+	if (m_applications->load_applications())
+	{
+		set_loaded();
+	}
+	else
+	{
+		gtk_stack_set_visible_child_name(m_window_stack, "load");
+		gtk_spinner_start(m_window_load_spinner);
+	}
 
 	// Update default page
 	if (wm_settings->display_recent && (m_default_page == m_favorites))
@@ -690,6 +705,18 @@ void WhiskerMenu::Window::set_items()
 
 //-----------------------------------------------------------------------------
 
+void WhiskerMenu::Window::set_loaded()
+{
+	// Hide loading spinner
+	gtk_spinner_stop(m_window_load_spinner);
+	gtk_stack_set_visible_child_full(m_window_stack, "contents", GTK_STACK_TRANSITION_TYPE_CROSSFADE);
+
+	// Focus search entry
+	gtk_widget_grab_focus(GTK_WIDGET(m_search_entry));
+}
+
+//-----------------------------------------------------------------------------
+
 void WhiskerMenu::Window::unset_items()
 {
 	m_search_results->unset_menu_items();
diff --git a/panel-plugin/window.h b/panel-plugin/window.h
index 8789ec0..b3c1a91 100644
--- a/panel-plugin/window.h
+++ b/panel-plugin/window.h
@@ -71,6 +71,7 @@ public:
 	void on_context_menu_destroyed();
 	void set_categories(const std::vector<SectionButton*>& categories);
 	void set_items();
+	void set_loaded();
 	void unset_items();
 
 private:
@@ -94,6 +95,9 @@ private:
 private:
 	GtkWindow* m_window;
 
+	GtkStack* m_window_stack;
+	GtkSpinner* m_window_load_spinner;
+
 	GtkBox* m_vbox;
 	GtkBox* m_title_box;
 	GtkBox* m_commands_box;

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


More information about the Xfce4-commits mailing list