1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
* Copyright (C) 2013-2020 Graeme Gott <graeme@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/>.
*/
#ifndef WHISKERMENU_ELEMENT_H
#define WHISKERMENU_ELEMENT_H
#include <libxfce4ui/libxfce4ui.h>
#include <gdk/gdk.h>
namespace WhiskerMenu
{
class Query;
class Element
{
public:
virtual ~Element()
{
if (m_icon)
{
g_object_unref(m_icon);
}
g_free(m_text);
g_free(m_tooltip);
g_free(m_sort_key);
}
Element(const Element&) = delete;
Element(Element&&) = delete;
Element& operator=(const Element&) = delete;
Element& operator=(Element&&) = delete;
GIcon* get_icon() const
{
return m_icon;
}
const gchar* get_text() const
{
return m_text;
}
const gchar* get_tooltip() const
{
return m_tooltip;
}
virtual void run(GdkScreen*) const
{
}
virtual unsigned int search(const Query&)
{
return UINT_MAX;
}
static bool less_than(const Element* lhs, const Element* rhs)
{
return g_strcmp0(lhs->m_sort_key, rhs->m_sort_key) < 0;
}
protected:
Element() = default;
void set_icon(const gchar* icon);
void set_text(const gchar* text)
{
g_free(m_text);
g_free(m_sort_key);
m_text = g_strdup(text);
m_sort_key = g_utf8_collate_key(m_text, -1);
}
void set_text(gchar* text)
{
g_free(m_text);
g_free(m_sort_key);
m_text = text;
m_sort_key = g_utf8_collate_key(m_text, -1);
}
void set_tooltip(const gchar* tooltip)
{
g_free(m_tooltip);
m_tooltip = !xfce_str_is_empty(tooltip) ? g_markup_escape_text(tooltip, -1) : nullptr;
}
void spawn(GdkScreen* screen, const gchar* command, const gchar* working_directory, gboolean startup_notify, const gchar* icon_name) const;
private:
GIcon* m_icon = nullptr;
gchar* m_text = nullptr;
gchar* m_tooltip = nullptr;
gchar* m_sort_key = nullptr;
};
}
#endif // WHISKERMENU_ELEMENT_H
|