[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 03/06: Use GIcon instead of icon name.

noreply at xfce.org noreply at xfce.org
Tue Jan 14 11:43:56 CET 2020


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 d3409edcb9e71c0c8c209808008f86e2a00caaa0
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Oct 16 06:23:32 2017 -0400

    Use GIcon instead of icon name.
---
 panel-plugin/applications-page.cpp  |  2 +-
 panel-plugin/category.cpp           |  4 ++--
 panel-plugin/element.cpp            | 14 +++++++++-----
 panel-plugin/element.h              |  9 ++++++---
 panel-plugin/launcher-icon-view.cpp |  2 +-
 panel-plugin/launcher-tree-view.cpp |  5 ++---
 panel-plugin/search-page.cpp        |  2 +-
 panel-plugin/section-button.cpp     | 17 ++---------------
 panel-plugin/section-button.h       |  5 ++---
 panel-plugin/window.cpp             |  8 ++++++--
 10 files changed, 32 insertions(+), 36 deletions(-)

diff --git a/panel-plugin/applications-page.cpp b/panel-plugin/applications-page.cpp
index 4d6dc4b..3648d02 100644
--- a/panel-plugin/applications-page.cpp
+++ b/panel-plugin/applications-page.cpp
@@ -79,7 +79,7 @@ GtkTreeModel* ApplicationsPage::create_launcher_model(std::vector<std::string>&
 	// Create new model for treeview
 	GtkListStore* store = gtk_list_store_new(
 			LauncherView::N_COLUMNS,
-			G_TYPE_STRING,
+			G_TYPE_ICON,
 			G_TYPE_STRING,
 			G_TYPE_STRING,
 			G_TYPE_POINTER);
diff --git a/panel-plugin/category.cpp b/panel-plugin/category.cpp
index 9c257df..d03ebed 100644
--- a/panel-plugin/category.cpp
+++ b/panel-plugin/category.cpp
@@ -104,7 +104,7 @@ GtkTreeModel* Category::get_model()
 		{
 			GtkTreeStore* model = gtk_tree_store_new(
 					LauncherView::N_COLUMNS,
-					G_TYPE_STRING,
+					G_TYPE_ICON,
 					G_TYPE_STRING,
 					G_TYPE_STRING,
 					G_TYPE_POINTER);
@@ -115,7 +115,7 @@ GtkTreeModel* Category::get_model()
 		{
 			GtkListStore* model = gtk_list_store_new(
 					LauncherView::N_COLUMNS,
-					G_TYPE_STRING,
+					G_TYPE_ICON,
 					G_TYPE_STRING,
 					G_TYPE_STRING,
 					G_TYPE_POINTER);
diff --git a/panel-plugin/element.cpp b/panel-plugin/element.cpp
index 17a71ee..86737d2 100644
--- a/panel-plugin/element.cpp
+++ b/panel-plugin/element.cpp
@@ -25,7 +25,7 @@ void Element::set_icon(const gchar* icon)
 {
 	if (m_icon)
 	{
-		g_free(m_icon);
+		g_object_unref(m_icon);
 		m_icon = NULL;
 	}
 
@@ -39,7 +39,7 @@ void Element::set_icon(const gchar* icon)
 		const gchar* pos = g_strrstr(icon, ".");
 		if (!pos)
 		{
-			m_icon = g_strdup(icon);
+			m_icon = g_themed_icon_new_with_default_fallbacks(icon);
 		}
 		else
 		{
@@ -49,18 +49,22 @@ void Element::set_icon(const gchar* icon)
 					|| (g_strcmp0(suffix, ".svg") == 0)
 					|| (g_strcmp0(suffix, ".svgz") == 0))
 			{
-				m_icon = g_strndup(icon, pos - icon);
+				gchar* name = g_strndup(icon, pos - icon);
+				m_icon = g_themed_icon_new_with_default_fallbacks(name);
+				g_free(name);
 			}
 			else
 			{
-				m_icon = g_strdup(icon);
+				m_icon = g_themed_icon_new_with_default_fallbacks(icon);
 			}
 			g_free(suffix);
 		}
 	}
 	else
 	{
-		m_icon = g_strdup(icon);
+		GFile* file = g_file_new_for_path(icon);
+		m_icon = g_file_icon_new(file);
+		g_object_unref(file);
 	}
 }
 
diff --git a/panel-plugin/element.h b/panel-plugin/element.h
index 12f9abf..9e02963 100644
--- a/panel-plugin/element.h
+++ b/panel-plugin/element.h
@@ -39,7 +39,10 @@ public:
 
 	virtual ~Element()
 	{
-		g_free(m_icon);
+		if (m_icon)
+		{
+			g_object_unref(m_icon);
+		}
 		g_free(m_text);
 		g_free(m_tooltip);
 		g_free(m_sort_key);
@@ -47,7 +50,7 @@ public:
 
 	virtual int get_type() const = 0;
 
-	const gchar* get_icon() const
+	GIcon* get_icon() const
 	{
 		return m_icon;
 	}
@@ -106,7 +109,7 @@ private:
 	Element& operator=(const Element&);
 
 private:
-	gchar* m_icon;
+	GIcon* m_icon;
 	gchar* m_text;
 	gchar* m_tooltip;
 	gchar* m_sort_key;
diff --git a/panel-plugin/launcher-icon-view.cpp b/panel-plugin/launcher-icon-view.cpp
index 80554c7..6a4675f 100644
--- a/panel-plugin/launcher-icon-view.cpp
+++ b/panel-plugin/launcher-icon-view.cpp
@@ -41,7 +41,7 @@ LauncherIconView::LauncherIconView() :
 			NULL);
 	GtkCellLayout* cell_layout = GTK_CELL_LAYOUT(m_view);
 	gtk_cell_layout_pack_start(cell_layout, m_icon_renderer, false);
-	gtk_cell_layout_set_attributes(cell_layout, m_icon_renderer, "icon", COLUMN_ICON, NULL);
+	gtk_cell_layout_set_attributes(cell_layout, m_icon_renderer, "gicon", COLUMN_ICON, NULL);
 
 	gtk_icon_view_set_markup_column(m_view, COLUMN_TEXT);
 
diff --git a/panel-plugin/launcher-tree-view.cpp b/panel-plugin/launcher-tree-view.cpp
index 805028c..b22dfff 100644
--- a/panel-plugin/launcher-tree-view.cpp
+++ b/panel-plugin/launcher-tree-view.cpp
@@ -254,10 +254,9 @@ void LauncherTreeView::create_column()
 	if (m_icon_size > 1)
 	{
 		GtkCellRenderer* icon_renderer = exo_cell_renderer_icon_new();
-		g_object_set(icon_renderer, "follow-state", false, NULL);
-		g_object_set(icon_renderer, "size", m_icon_size, NULL);
+		g_object_set(icon_renderer, "follow-state", false, "size", m_icon_size, NULL);
 		gtk_tree_view_column_pack_start(m_column, icon_renderer, false);
-		gtk_tree_view_column_add_attribute(m_column, icon_renderer, "icon", COLUMN_ICON);
+		gtk_tree_view_column_add_attribute(m_column, icon_renderer, "gicon", COLUMN_ICON);
 	}
 
 	GtkCellRenderer* text_renderer = gtk_cell_renderer_text_new();
diff --git a/panel-plugin/search-page.cpp b/panel-plugin/search-page.cpp
index aac145c..6cd2fe4 100644
--- a/panel-plugin/search-page.cpp
+++ b/panel-plugin/search-page.cpp
@@ -109,7 +109,7 @@ void SearchPage::set_filter(const gchar* filter)
 	// Show search results
 	GtkListStore* store = gtk_list_store_new(
 			LauncherView::N_COLUMNS,
-			G_TYPE_STRING,
+			G_TYPE_ICON,
 			G_TYPE_STRING,
 			G_TYPE_STRING,
 			G_TYPE_POINTER);
diff --git a/panel-plugin/section-button.cpp b/panel-plugin/section-button.cpp
index dff5c56..c20ab01 100644
--- a/panel-plugin/section-button.cpp
+++ b/panel-plugin/section-button.cpp
@@ -45,8 +45,7 @@ static gboolean on_enter_notify_event(GtkWidget*, GdkEventCrossing*, GtkToggleBu
 
 //-----------------------------------------------------------------------------
 
-SectionButton::SectionButton(const gchar* icon, const gchar* text) :
-	m_icon_name(g_strdup(icon))
+SectionButton::SectionButton(GIcon* icon, const gchar* text)
 {
 	m_button = GTK_RADIO_BUTTON(gtk_radio_button_new(NULL));
 	gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(m_button), false);
@@ -58,18 +57,7 @@ SectionButton::SectionButton(const gchar* icon, const gchar* text) :
 	m_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4));
 	gtk_container_add(GTK_CONTAINER(m_button), GTK_WIDGET(m_box));
 
-	if (!g_path_is_absolute(icon))
-	{
-		m_icon = gtk_image_new_from_icon_name(icon, GTK_ICON_SIZE_BUTTON);
-	}
-	else
-	{
-		GFile* file = g_file_new_for_path(icon);
-		GIcon* gicon = g_file_icon_new(file);
-		m_icon = gtk_image_new_from_gicon(gicon, GTK_ICON_SIZE_BUTTON);
-		g_object_unref(gicon);
-		g_object_unref(file);
-	}
+	m_icon = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_BUTTON);
 	gtk_box_pack_start(m_box, m_icon, false, false, 0);
 
 	m_label = gtk_label_new(text);
@@ -84,7 +72,6 @@ SectionButton::SectionButton(const gchar* icon, const gchar* text) :
 
 SectionButton::~SectionButton()
 {
-	g_free(m_icon_name);
 	gtk_widget_destroy(GTK_WIDGET(m_button));
 }
 
diff --git a/panel-plugin/section-button.h b/panel-plugin/section-button.h
index ae2c46d..8b48b20 100644
--- a/panel-plugin/section-button.h
+++ b/panel-plugin/section-button.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2016 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 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
@@ -26,7 +26,7 @@ namespace WhiskerMenu
 class SectionButton
 {
 public:
-	SectionButton(const gchar* icon, const gchar* text);
+	SectionButton(GIcon* icon, const gchar* text);
 	~SectionButton();
 
 	GtkRadioButton* get_button() const
@@ -61,7 +61,6 @@ private:
 	GtkBox* m_box;
 	GtkWidget* m_icon;
 	GtkWidget* m_label;
-	gchar* m_icon_name;
 };
 
 }
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index 408eaf7..a38344d 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -155,13 +155,17 @@ WhiskerMenu::Window::Window(Plugin* plugin) :
 	// Create favorites
 	m_favorites = new FavoritesPage(this);
 
-	m_favorites_button = new SectionButton("user-bookmarks", _("Favorites"));
+	GIcon* icon = g_themed_icon_new("user-bookmarks");
+	m_favorites_button = new SectionButton(icon, _("Favorites"));
+	g_object_unref(icon);
 	g_signal_connect_slot<GtkToggleButton*>(m_favorites_button->get_button(), "toggled", &Window::favorites_toggled, this);
 
 	// Create recent
 	m_recent = new RecentPage(this);
 
-	m_recent_button = new SectionButton("document-open-recent", _("Recently Used"));
+	icon = g_themed_icon_new("document-open-recent");
+	m_recent_button = new SectionButton(icon, _("Recently Used"));
+	g_object_unref(icon);
 	m_recent_button->set_group(m_favorites_button->get_group());
 	g_signal_connect_slot<GtkToggleButton*>(m_recent_button->get_button(), "toggled", &Window::recent_toggled, this);
 

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


More information about the Xfce4-commits mailing list