[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 03/06: Replace manual thread with GTask.

noreply at xfce.org noreply at xfce.org
Tue Apr 17 15:02:36 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 a0a908b687020570e81742f99f0ad0375a4ed603
Author: Graeme Gott <graeme at gottcode.org>
Date:   Tue Apr 17 05:44:23 2018 -0400

    Replace manual thread with GTask.
---
 panel-plugin/applications-page.cpp | 20 ++++----------------
 panel-plugin/applications-page.h   | 14 ++++++--------
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/panel-plugin/applications-page.cpp b/panel-plugin/applications-page.cpp
index f1ecaa0..0c6483f 100644
--- a/panel-plugin/applications-page.cpp
+++ b/panel-plugin/applications-page.cpp
@@ -50,7 +50,6 @@ 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
@@ -182,22 +181,16 @@ bool ApplicationsPage::load_applications()
 	{
 		return false;
 	}
-	// Check if loading garcon
-	else if (m_load_thread)
-	{
-		return false;
-	}
 	m_load_status = STATUS_LOADING;
 
 	// Load menu
 	clear_applications();
 
 	// 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();
-	}
+	GTask* task = g_task_new(NULL, NULL, &ApplicationsPage::load_contents_slot, this);
+	g_task_set_task_data(task, this, NULL);
+	g_task_run_in_thread(task, &ApplicationsPage::load_garcon_menu_slot);
+	g_object_unref(task);
 
 	return false;
 }
@@ -271,7 +264,6 @@ void ApplicationsPage::load_garcon_menu()
 
 	if (!m_garcon_menu)
 	{
-		m_load_status = STATUS_INVALID;
 		return;
 	}
 
@@ -312,8 +304,6 @@ void ApplicationsPage::load_garcon_menu()
 	}
 	category->sort();
 	m_categories.insert(m_categories.begin(), category);
-
-	g_idle_add(&ApplicationsPage::load_contents_slot, this);
 }
 
 //-----------------------------------------------------------------------------
@@ -325,7 +315,6 @@ void ApplicationsPage::load_contents()
 		get_window()->set_loaded();
 
 		m_load_status = STATUS_INVALID;
-		m_load_thread = NULL;
 
 		return;
 	}
@@ -359,7 +348,6 @@ void ApplicationsPage::load_contents()
 	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 65abeea..faba045 100644
--- a/panel-plugin/applications-page.h
+++ b/panel-plugin/applications-page.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015, 2017 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2015, 2017, 2018 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
@@ -54,16 +54,15 @@ 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)
+	static void load_garcon_menu_slot(GTask* task, gpointer, gpointer task_data, GCancellable*)
 	{
-		reinterpret_cast<ApplicationsPage*>(obj)->load_garcon_menu();
-		return NULL;
+		reinterpret_cast<ApplicationsPage*>(task_data)->load_garcon_menu();
+		g_task_return_boolean(task, true);
 	}
 
-	static gboolean load_contents_slot(gpointer obj)
+	static void load_contents_slot(GObject*, GAsyncResult*, gpointer user_data)
 	{
-		reinterpret_cast<ApplicationsPage*>(obj)->load_contents();
-		return G_SOURCE_REMOVE;
+		reinterpret_cast<ApplicationsPage*>(user_data)->load_contents();
 	}
 
 private:
@@ -71,7 +70,6 @@ private:
 	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;
 };
 

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


More information about the Xfce4-commits mailing list