[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 148/473: Derive category and launcher from shared class.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:55:18 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 711907edbab6679962d45b985797c20327cec40b
Author: Graeme Gott <graeme at gottcode.org>
Date: Thu Aug 1 12:14:10 2013 -0400
Derive category and launcher from shared class.
---
src/category.cpp | 18 +++++++++--
src/category.hpp | 21 ++++++++----
src/{category.hpp => element.hpp} | 64 ++++++++++++++++++++++---------------
src/launcher.cpp | 18 ++++-------
src/launcher.hpp | 20 ++++++------
5 files changed, 84 insertions(+), 57 deletions(-)
diff --git a/src/category.cpp b/src/category.cpp
index 71bbe20..e67c894 100644
--- a/src/category.cpp
+++ b/src/category.cpp
@@ -24,6 +24,7 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
Category::Category(GarconMenuDirectory* directory) :
+ m_button(NULL),
m_model(NULL)
{
// Fetch icon
@@ -32,6 +33,7 @@ Category::Category(GarconMenuDirectory* directory) :
{
icon = "";
}
+ set_icon(icon);
// Fetch text
const gchar* text = garcon_menu_directory_get_name(directory);
@@ -39,9 +41,7 @@ Category::Category(GarconMenuDirectory* directory) :
{
text = "";
}
-
- // Create button
- m_button = new SectionButton(icon, text);
+ set_text(text);
}
//-----------------------------------------------------------------------------
@@ -55,6 +55,18 @@ Category::~Category()
//-----------------------------------------------------------------------------
+SectionButton* Category::get_button()
+{
+ if (!m_button)
+ {
+ m_button = new SectionButton(get_icon(), get_text());
+ }
+
+ return m_button;
+}
+
+//-----------------------------------------------------------------------------
+
GtkTreeModel* Category::get_model()
{
if (!m_model)
diff --git a/src/category.hpp b/src/category.hpp
index e47f465..d0ae965 100644
--- a/src/category.hpp
+++ b/src/category.hpp
@@ -17,12 +17,13 @@
#ifndef WHISKERMENU_CATEGORY_HPP
#define WHISKERMENU_CATEGORY_HPP
+#include "element.hpp"
+
#include <vector>
extern "C"
{
#include <garcon/garcon.h>
-#include <gtk/gtk.h>
}
namespace WhiskerMenu
@@ -31,19 +32,25 @@ namespace WhiskerMenu
class Launcher;
class SectionButton;
-class Category
+class Category : public Element
{
public:
explicit Category(GarconMenuDirectory* directory);
~Category();
- GtkTreeModel* get_model();
-
- SectionButton* get_button() const
+ enum
{
- return m_button;
+ Type = 1
+ };
+ int get_type() const
+ {
+ return Type;
}
+ SectionButton* get_button();
+
+ GtkTreeModel* get_model();
+
bool empty() const
{
return m_items.empty();
@@ -59,8 +66,8 @@ private:
void unset_model();
private:
- std::vector<Launcher*> m_items;
SectionButton* m_button;
+ std::vector<Launcher*> m_items;
GtkTreeModel* m_model;
};
diff --git a/src/category.hpp b/src/element.hpp
similarity index 56%
copy from src/category.hpp
copy to src/element.hpp
index e47f465..541a3de 100644
--- a/src/category.hpp
+++ b/src/element.hpp
@@ -14,56 +14,70 @@
// along with this library. If not, see <http://www.gnu.org/licenses/>.
-#ifndef WHISKERMENU_CATEGORY_HPP
-#define WHISKERMENU_CATEGORY_HPP
-
-#include <vector>
+#ifndef WHISKERMENU_ELEMENT_HPP
+#define WHISKERMENU_ELEMENT_HPP
extern "C"
{
-#include <garcon/garcon.h>
#include <gtk/gtk.h>
}
namespace WhiskerMenu
{
-class Launcher;
-class SectionButton;
-
-class Category
+class Element
{
public:
- explicit Category(GarconMenuDirectory* directory);
- ~Category();
+ Element() :
+ m_icon(NULL),
+ m_text(NULL)
+ {
+ }
- GtkTreeModel* get_model();
+ virtual ~Element()
+ {
+ g_free(m_icon);
+ g_free(m_text);
+ }
- SectionButton* get_button() const
+ virtual int get_type() const = 0;
+
+ const gchar* get_icon() const
{
- return m_button;
+ return m_icon;
}
- bool empty() const
+ const gchar* get_text() const
{
- return m_items.empty();
+ return m_text;
}
- void push_back(Launcher* launcher)
+protected:
+ void set_icon(const gchar* icon)
{
- m_items.push_back(launcher);
- unset_model();
+ m_icon = g_strdup(icon);
}
-private:
- void unset_model();
+ void set_icon(gchar* icon)
+ {
+ m_icon = icon;
+ }
+
+ void set_text(const gchar* text)
+ {
+ m_text = g_strdup(text);
+ }
+
+ void set_text(gchar* text)
+ {
+ m_text = text;
+ }
private:
- std::vector<Launcher*> m_items;
- SectionButton* m_button;
- GtkTreeModel* m_model;
+ gchar* m_icon;
+ gchar* m_text;
};
}
-#endif // WHISKERMENU_CATEGORY_HPP
+#endif // WHISKERMENU_ELEMENT_HPP
diff --git a/src/launcher.cpp b/src/launcher.cpp
index 74beebc..7d53678 100644
--- a/src/launcher.cpp
+++ b/src/launcher.cpp
@@ -77,9 +77,7 @@ static void replace_with_quoted_string(std::string& command, size_t& index, gcha
//-----------------------------------------------------------------------------
Launcher::Launcher(GarconMenuItem* item) :
- m_item(item),
- m_icon(NULL),
- m_text(NULL)
+ m_item(item)
{
garcon_menu_item_ref(m_item);
@@ -92,7 +90,7 @@ Launcher::Launcher(GarconMenuItem* item) :
gchar* pos = g_strrstr(icon, ".");
if (!pos)
{
- m_icon = g_strdup(icon);
+ set_icon(icon);
}
else
{
@@ -102,18 +100,18 @@ Launcher::Launcher(GarconMenuItem* item) :
|| (strcmp(suffix, ".svg") == 0)
|| (strcmp(suffix, ".svgz") == 0))
{
- m_icon = g_strndup(icon, pos - icon);
+ set_icon(g_strndup(icon, pos - icon));
}
else
{
- m_icon = g_strdup(icon);
+ set_icon(icon);
}
g_free(suffix);
}
}
else
{
- m_icon = g_strdup(icon);
+ set_icon(icon);
}
}
@@ -140,7 +138,7 @@ Launcher::Launcher(GarconMenuItem* item) :
{
details = generic_name;
}
- m_text = g_markup_printf_escaped("%s<b>%s</b>\n%s%s", direction, m_display_name, direction, details);
+ set_text(g_markup_printf_escaped("%s<b>%s</b>\n%s%s", direction, m_display_name, direction, details));
// Create search text for comment
gchar* normalized = g_utf8_normalize(details, -1, G_NORMALIZE_DEFAULT);
@@ -151,7 +149,7 @@ Launcher::Launcher(GarconMenuItem* item) :
}
else
{
- m_text = g_markup_printf_escaped("%s%s", direction, m_display_name);
+ set_text(g_markup_printf_escaped("%s%s", direction, m_display_name));
}
// Create search text for display name
@@ -178,8 +176,6 @@ Launcher::Launcher(GarconMenuItem* item) :
Launcher::~Launcher()
{
garcon_menu_item_unref(m_item);
- g_free(m_icon);
- g_free(m_text);
}
//-----------------------------------------------------------------------------
diff --git a/src/launcher.hpp b/src/launcher.hpp
index c49e391..1f1a74c 100644
--- a/src/launcher.hpp
+++ b/src/launcher.hpp
@@ -17,6 +17,7 @@
#ifndef WHISKERMENU_LAUNCHER_HPP
#define WHISKERMENU_LAUNCHER_HPP
+#include "element.hpp"
#include "query.hpp"
#include <string>
@@ -30,25 +31,24 @@ extern "C"
namespace WhiskerMenu
{
-class Launcher
+class Launcher : public Element
{
public:
explicit Launcher(GarconMenuItem* item);
~Launcher();
- const gchar* get_display_name() const
+ enum
{
- return m_display_name;
- }
-
- const gchar* get_icon() const
+ Type = 2
+ };
+ int get_type() const
{
- return m_icon;
+ return Type;
}
- const gchar* get_text() const
+ const gchar* get_display_name() const
{
- return m_text;
+ return m_display_name;
}
const gchar* get_desktop_id() const
@@ -77,8 +77,6 @@ private:
private:
GarconMenuItem* m_item;
const gchar* m_display_name;
- gchar* m_icon;
- gchar* m_text;
std::string m_search_name;
std::string m_search_comment;
std::string m_search_command;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list