[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 87/473: Check for null launchers.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:54:17 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 62f7dff219128a95730e243a2f294c4247e59b5f
Author: Graeme Gott <graeme at gottcode.org>
Date:   Wed Jul 10 15:22:28 2013 -0400

    Check for null launchers.
---
 src/CMakeLists.txt        |    1 +
 src/applications_page.cpp |    4 ++++
 src/favorites_page.cpp    |    5 +++++
 src/list_page.cpp         |   10 ++++++++++
 src/menu.cpp              |    1 -
 src/page.cpp              |   17 +++++++++++++++--
 src/recent_page.cpp       |    5 +++++
 src/search_page.cpp       |    9 +++++++--
 8 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5eecd3b..29c3570 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -86,6 +86,7 @@ target_link_libraries(whiskermenu
 
 string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_TOLOWER)
 if(CMAKE_BUILD_TYPE_TOLOWER MATCHES release)
+    add_definitions(-DG_DISABLE_ASSERT=1)
     add_custom_command(TARGET whiskermenu POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:whiskermenu>)
 endif()
 
diff --git a/src/applications_page.cpp b/src/applications_page.cpp
index 8e93caa..d5821d6 100644
--- a/src/applications_page.cpp
+++ b/src/applications_page.cpp
@@ -124,6 +124,10 @@ bool ApplicationsPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
 
 	Launcher* launcher = NULL;
 	gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+	if (!launcher)
+	{
+		return false;
+	}
 
 	const std::vector<Launcher*>& category = m_categories[m_current_category];
 	return std::find(category.begin(), category.end(), launcher) != category.end();
diff --git a/src/favorites_page.cpp b/src/favorites_page.cpp
index b5519cf..99f3138 100644
--- a/src/favorites_page.cpp
+++ b/src/favorites_page.cpp
@@ -48,6 +48,11 @@ FavoritesPage::FavoritesPage(XfceRc* settings, Menu* menu) :
 
 void FavoritesPage::add(Launcher* launcher)
 {
+	if (!launcher)
+	{
+		return;
+	}
+
 	// Remove item if already in list
 	remove(launcher);
 
diff --git a/src/list_page.cpp b/src/list_page.cpp
index 06e0beb..e6d3673 100644
--- a/src/list_page.cpp
+++ b/src/list_page.cpp
@@ -64,6 +64,11 @@ ListPage::~ListPage()
 
 bool ListPage::contains(Launcher* launcher) const
 {
+	if (!launcher)
+	{
+		return false;
+	}
+
 	std::string desktop_id = garcon_menu_item_get_desktop_id(launcher->get_item());
 	return std::find(m_desktop_ids.begin(), m_desktop_ids.end(), desktop_id) != m_desktop_ids.end();
 }
@@ -103,6 +108,11 @@ void ListPage::set_menu_items(const std::map<std::string, Launcher*>& items)
 	// Fetch menu items or remove them from list if missing
 	for (std::vector<std::string>::iterator i = m_desktop_ids.begin(); i != m_desktop_ids.end(); ++i)
 	{
+		if (i->empty())
+		{
+			continue;
+		}
+
 		std::map<std::string, Launcher*>::const_iterator item = items.find(*i);
 		if (item != items.end())
 		{
diff --git a/src/menu.cpp b/src/menu.cpp
index d452083..0c2bbc1 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -18,7 +18,6 @@
 
 #include "applications_page.hpp"
 #include "favorites_page.hpp"
-#include "launcher_model.hpp"
 #include "launcher_view.hpp"
 #include "recent_page.hpp"
 #include "resizer_widget.hpp"
diff --git a/src/page.cpp b/src/page.cpp
index 6e3159f..36d7ade 100644
--- a/src/page.cpp
+++ b/src/page.cpp
@@ -91,6 +91,10 @@ void Page::launcher_activated(GtkTreeView* view, GtkTreePath* path, GtkTreeViewC
 	// Find launcher
 	Launcher* launcher = NULL;
 	gtk_tree_model_get(model, &iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
+	if (!launcher)
+	{
+		return;
+	}
 
 	// Add to recent
 	m_menu->get_recent()->add(launcher);
@@ -154,8 +158,12 @@ void Page::on_unmap()
 
 void Page::create_context_menu(GtkTreeIter* iter, GdkEventButton* event)
 {
-	gtk_tree_view_set_hover_selection(GTK_TREE_VIEW(m_view->get_widget()), false);
 	m_selected_path = gtk_tree_model_get_path(m_view->get_model(), iter);
+	Launcher* launcher = get_selected_launcher();
+	if (!launcher)
+	{
+		return;
+	}
 
 	// Create context menu
 	GtkWidget* menu = gtk_menu_new();
@@ -164,7 +172,7 @@ void Page::create_context_menu(GtkTreeIter* iter, GdkEventButton* event)
 	// Add menu items
 	GtkWidget* menuitem = NULL;
 
-	if (!m_menu->get_favorites()->contains(get_selected_launcher()))
+	if (!m_menu->get_favorites()->contains(launcher))
 	{
 		menuitem = gtk_menu_item_new_with_label(_("Add to Favorites"));
 		g_signal_connect_swapped(menuitem, "activate", SLOT_CALLBACK(Page::add_selected_to_favorites), this);
@@ -202,6 +210,7 @@ void Page::create_context_menu(GtkTreeIter* iter, GdkEventButton* event)
 		event_time = gtk_get_current_event_time ();
 	}
 
+	gtk_tree_view_set_hover_selection(GTK_TREE_VIEW(m_view->get_widget()), false);
 	gtk_menu_attach_to_widget(GTK_MENU(menu), m_view->get_widget(), NULL);
 	gtk_menu_popup(GTK_MENU(menu), NULL, NULL, position_func, this, button, event_time);
 }
@@ -250,6 +259,7 @@ void Page::add_selected_to_desktop()
 
 	// Fetch launcher source
 	Launcher* launcher = get_selected_launcher();
+	g_assert(launcher != NULL);
 	GFile* source_file = garcon_menu_item_get_file(launcher->get_item());
 
 	// Fetch launcher destination
@@ -288,6 +298,7 @@ void Page::add_selected_to_panel()
 	{
 		// Fetch launcher desktop ID
 		Launcher* launcher = get_selected_launcher();
+		g_assert(launcher != NULL);
 		const gchar* parameters[] = { garcon_menu_item_get_desktop_id(launcher->get_item()), NULL };
 
 		// Tell panel to add item
@@ -318,6 +329,7 @@ void Page::add_selected_to_panel()
 void Page::add_selected_to_favorites()
 {
 	Launcher* launcher = get_selected_launcher();
+	g_assert(launcher != NULL);
 	m_menu->get_favorites()->add(launcher);
 	m_menu->set_modified();
 }
@@ -327,6 +339,7 @@ void Page::add_selected_to_favorites()
 void Page::remove_selected_from_favorites()
 {
 	Launcher* launcher = get_selected_launcher();
+	g_assert(launcher != NULL);
 	m_menu->get_favorites()->remove(launcher);
 	m_menu->set_modified();
 }
diff --git a/src/recent_page.cpp b/src/recent_page.cpp
index d2411b4..9ba43c4 100644
--- a/src/recent_page.cpp
+++ b/src/recent_page.cpp
@@ -40,6 +40,11 @@ RecentPage::RecentPage(XfceRc* settings, Menu* menu) :
 
 void RecentPage::add(Launcher* launcher)
 {
+	if (!launcher)
+	{
+		return;
+	}
+
 	// Remove item if already in list
 	remove(launcher);
 
diff --git a/src/search_page.cpp b/src/search_page.cpp
index cace7e2..98d1ae3 100644
--- a/src/search_page.cpp
+++ b/src/search_page.cpp
@@ -101,7 +101,10 @@ void SearchPage::set_menu_items(GtkTreeModel* model)
 	{
 		Launcher* launcher = NULL;
 		gtk_tree_model_get(model, &iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
-		m_launchers.push_back(launcher);
+		if (launcher)
+		{
+			m_launchers.push_back(launcher);
+		}
 		valid = gtk_tree_model_iter_next(model, &iter);
 	}
 
@@ -133,7 +136,7 @@ bool SearchPage::on_filter(GtkTreeModel* model, GtkTreeIter* iter)
 	// Check if launcher search string contains text
 	Launcher* launcher = NULL;
 	gtk_tree_model_get(model, iter, LauncherModel::COLUMN_LAUNCHER, &launcher, -1);
-	return launcher->get_search_results(m_query) != UINT_MAX;
+	return launcher && (launcher->get_search_results(m_query) != UINT_MAX);
 }
 
 //-----------------------------------------------------------------------------
@@ -142,9 +145,11 @@ gint SearchPage::on_sort(GtkTreeModel* model, GtkTreeIter* a, GtkTreeIter* b, Se
 {
 	Launcher* launcher_a = NULL;
 	gtk_tree_model_get(model, a, LauncherModel::COLUMN_LAUNCHER, &launcher_a, -1);
+	g_assert(launcher_a != NULL);
 
 	Launcher* launcher_b = NULL;
 	gtk_tree_model_get(model, b, LauncherModel::COLUMN_LAUNCHER, &launcher_b, -1);
+	g_assert(launcher_b != NULL);
 
 	return launcher_a->get_search_results(page->m_query) - launcher_b->get_search_results(page->m_query);
 }

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


More information about the Xfce4-commits mailing list