1 /*
2  * This file is part of brisk-menu.
3  *
4  * Copyright © 2017-2020 Brisk Menu Developers
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11 
12 #define _GNU_SOURCE
13 
14 #include "util.h"
15 
16 BRISK_BEGIN_PEDANTIC
17 #include "all-section.h"
18 #include <gio/gio.h>
19 #include <glib/gi18n.h>
20 BRISK_END_PEDANTIC
21 
22 struct _BriskAllItemsSectionClass {
23         BriskSectionClass parent_class;
24 };
25 
26 /**
27  * BriskAllItemsSection is an incredibly simple backend that simple adds a single
28  * section to the sidebar, and is allowed to display any item when the category
29  * is active.
30  *
31  * It also serves as a great starting point for anyone wishing to implement their
32  * own backends.
33  */
34 struct _BriskAllItemsSection {
35         BriskSection parent;
36         GIcon *icon; /**<Display icon */
37 };
38 
39 G_DEFINE_TYPE(BriskAllItemsSection, brisk_all_items_section, BRISK_TYPE_SECTION)
40 
41 /**
42  * Basic subclassing
43  */
44 static const gchar *brisk_all_items_section_get_id(BriskSection *item);
45 static const gchar *brisk_all_items_section_get_name(BriskSection *item);
46 static const GIcon *brisk_all_items_section_get_icon(BriskSection *item);
47 static const gchar *brisk_all_items_section_get_backend_id(BriskSection *item);
48 static gboolean brisk_all_items_section_can_show_item(BriskSection *section, BriskItem *item);
49 
50 /**
51  * brisk_all_items_section_dispose:
52  *
53  * Clean up a BriskAllItemsSection instance
54  */
brisk_all_items_section_dispose(GObject * obj)55 static void brisk_all_items_section_dispose(GObject *obj)
56 {
57         BriskAllItemsSection *self = BRISK_ALL_ITEMS_SECTION(obj);
58 
59         g_clear_object(&self->icon);
60 
61         G_OBJECT_CLASS(brisk_all_items_section_parent_class)->dispose(obj);
62 }
63 
64 /**
65  * brisk_all_items_section_class_init:
66  *
67  * Handle class initialisation
68  */
brisk_all_items_section_class_init(BriskAllItemsSectionClass * klazz)69 static void brisk_all_items_section_class_init(BriskAllItemsSectionClass *klazz)
70 {
71         BriskSectionClass *s_class = BRISK_SECTION_CLASS(klazz);
72         GObjectClass *obj_class = G_OBJECT_CLASS(klazz);
73 
74         /* item vtable hookup */
75         s_class->get_id = brisk_all_items_section_get_id;
76         s_class->get_name = brisk_all_items_section_get_name;
77         s_class->get_icon = brisk_all_items_section_get_icon;
78         s_class->get_backend_id = brisk_all_items_section_get_backend_id;
79         s_class->can_show_item = brisk_all_items_section_can_show_item;
80 
81         obj_class->dispose = brisk_all_items_section_dispose;
82 }
83 
84 /**
85  * brisk_all_items_section_init:
86  *
87  * Handle construction of the BriskAllItemsSection. Does absolutely nothing
88  * special outside of creating our icon.
89  */
brisk_all_items_section_init(BriskAllItemsSection * self)90 static void brisk_all_items_section_init(BriskAllItemsSection *self)
91 {
92         self->icon = g_themed_icon_new_with_default_fallbacks("starred");
93 }
94 
brisk_all_items_section_get_id(__brisk_unused__ BriskSection * section)95 static const gchar *brisk_all_items_section_get_id(__brisk_unused__ BriskSection *section)
96 {
97         return "all-items:main";
98 }
99 
brisk_all_items_section_get_name(__brisk_unused__ BriskSection * section)100 static const gchar *brisk_all_items_section_get_name(__brisk_unused__ BriskSection *section)
101 {
102         return _("All");
103 }
104 
brisk_all_items_section_get_icon(BriskSection * section)105 static const GIcon *brisk_all_items_section_get_icon(BriskSection *section)
106 {
107         BriskAllItemsSection *self = BRISK_ALL_ITEMS_SECTION(section);
108         return (const GIcon *)self->icon;
109 }
110 
brisk_all_items_section_get_backend_id(__brisk_unused__ BriskSection * item)111 static const gchar *brisk_all_items_section_get_backend_id(__brisk_unused__ BriskSection *item)
112 {
113         return "all-items";
114 }
115 
116 /**
117  * Being the magical "all" filter, we return TRUE for everything.
118  * Cuz we can show them all. :3
119  */
brisk_all_items_section_can_show_item(__brisk_unused__ BriskSection * section,__brisk_unused__ BriskItem * item)120 static gboolean brisk_all_items_section_can_show_item(__brisk_unused__ BriskSection *section,
121                                                       __brisk_unused__ BriskItem *item)
122 {
123         return TRUE;
124 }
125 
126 /**
127  * brisk_all_items_section_new:
128  *
129  * Return a new BriskAllItemsSection
130  */
brisk_all_items_section_new()131 BriskSection *brisk_all_items_section_new()
132 {
133         return g_object_new(BRISK_TYPE_ALL_ITEMS_SECTION, NULL);
134 }
135 
136 /*
137  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
138  *
139  * Local variables:
140  * c-basic-offset: 8
141  * tab-width: 8
142  * indent-tabs-mode: nil
143  * End:
144  *
145  * vi: set shiftwidth=8 tabstop=8 expandtab:
146  * :indentSize=8:tabSize=8:noTabs=true:
147  */
148