[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 02/06: Share icon code in elements.
noreply at xfce.org
noreply at xfce.org
Tue Jan 14 11:43:55 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 b22d7f15be875d2e4bde0a722283115891e57478
Author: Graeme Gott <graeme at gottcode.org>
Date: Mon Oct 16 08:10:27 2017 -0400
Share icon code in elements.
---
panel-plugin/CMakeLists.txt | 2 +-
panel-plugin/element.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++
panel-plugin/element.h | 12 +-------
panel-plugin/launcher.cpp | 32 +---------------------
4 files changed, 70 insertions(+), 43 deletions(-)
diff --git a/panel-plugin/CMakeLists.txt b/panel-plugin/CMakeLists.txt
index bd9e181..21fe169 100644
--- a/panel-plugin/CMakeLists.txt
+++ b/panel-plugin/CMakeLists.txt
@@ -74,7 +74,7 @@ add_library(whiskermenu MODULE
command.cpp
command-edit.cpp
configuration-dialog.cpp
- element.h
+ element.cpp
favorites-page.cpp
icon-size.cpp
launcher.cpp
diff --git a/panel-plugin/element.cpp b/panel-plugin/element.cpp
new file mode 100644
index 0000000..17a71ee
--- /dev/null
+++ b/panel-plugin/element.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 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
+ * 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 "element.h"
+
+using namespace WhiskerMenu;
+
+//-----------------------------------------------------------------------------
+
+void Element::set_icon(const gchar* icon)
+{
+ if (m_icon)
+ {
+ g_free(m_icon);
+ m_icon = NULL;
+ }
+
+ if (G_UNLIKELY(!icon))
+ {
+ return;
+ }
+
+ if (!g_path_is_absolute(icon))
+ {
+ const gchar* pos = g_strrstr(icon, ".");
+ if (!pos)
+ {
+ m_icon = g_strdup(icon);
+ }
+ else
+ {
+ gchar* suffix = g_utf8_casefold(pos, -1);
+ if ((g_strcmp0(suffix, ".png") == 0)
+ || (g_strcmp0(suffix, ".xpm") == 0)
+ || (g_strcmp0(suffix, ".svg") == 0)
+ || (g_strcmp0(suffix, ".svgz") == 0))
+ {
+ m_icon = g_strndup(icon, pos - icon);
+ }
+ else
+ {
+ m_icon = g_strdup(icon);
+ }
+ g_free(suffix);
+ }
+ }
+ else
+ {
+ m_icon = g_strdup(icon);
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/panel-plugin/element.h b/panel-plugin/element.h
index 6a23b73..12f9abf 100644
--- a/panel-plugin/element.h
+++ b/panel-plugin/element.h
@@ -77,17 +77,7 @@ public:
}
protected:
- void set_icon(const gchar* icon)
- {
- g_free(m_icon);
- m_icon = g_strdup(icon);
- }
-
- void set_icon(gchar* icon)
- {
- g_free(m_icon);
- m_icon = icon;
- }
+ void set_icon(const gchar* icon);
void set_text(const gchar* text)
{
diff --git a/panel-plugin/launcher.cpp b/panel-plugin/launcher.cpp
index 879b8d8..710aa46 100644
--- a/panel-plugin/launcher.cpp
+++ b/panel-plugin/launcher.cpp
@@ -105,37 +105,7 @@ Launcher::Launcher(GarconMenuItem* item) :
{
// Fetch icon
const gchar* icon = garcon_menu_item_get_icon_name(m_item);
- if (G_LIKELY(icon))
- {
- if (!g_path_is_absolute(icon))
- {
- gchar* pos = g_strrstr(icon, ".");
- if (!pos)
- {
- set_icon(icon);
- }
- else
- {
- gchar* suffix = g_utf8_casefold(pos, -1);
- if ((strcmp(suffix, ".png") == 0)
- || (strcmp(suffix, ".xpm") == 0)
- || (strcmp(suffix, ".svg") == 0)
- || (strcmp(suffix, ".svgz") == 0))
- {
- set_icon(g_strndup(icon, pos - icon));
- }
- else
- {
- set_icon(icon);
- }
- g_free(suffix);
- }
- }
- else
- {
- set_icon(icon);
- }
- }
+ set_icon(icon);
// Fetch text
const gchar* name = garcon_menu_item_get_name(m_item);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list