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 #pragma once 13 14 #include "item.h" 15 #include "section.h" 16 #include <glib-object.h> 17 18 G_BEGIN_DECLS 19 20 typedef struct _BriskBackend BriskBackend; 21 typedef struct _BriskBackendClass BriskBackendClass; 22 23 /** 24 * Flags to indicate the support level of a given backend 25 */ 26 typedef enum { 27 BRISK_BACKEND_KEYBOARD = 1 << 0, /**<Supports keyboard shortcuts */ 28 BRISK_BACKEND_SOURCE = 1 << 1, /**<Provides data which must be loaded */ 29 } BriskBackendFlags; 30 31 struct _BriskBackendClass { 32 GObjectClass parent_class; 33 34 /* All plugins must implement these methods */ 35 unsigned int (*get_flags)(BriskBackend *); 36 const gchar *(*get_id)(BriskBackend *); 37 const gchar *(*get_display_name)(BriskBackend *); 38 39 /* Optional method for providing context menu items */ 40 GMenu *(*get_item_actions)(BriskBackend *, BriskItem *, GActionGroup *); 41 42 /* All plugins given an opportunity to load later in life */ 43 gboolean (*load)(BriskBackend *); 44 45 /* Signals, gtk-doc style with param names */ 46 void (*item_added)(BriskBackend *backend, BriskItem *item); 47 void (*item_removed)(BriskBackend *backend, const gchar *id); 48 void (*section_added)(BriskBackend *backend, BriskSection *section); 49 void (*section_removed)(BriskBackend *backend, const gchar *id); 50 void (*invalidate_filter)(BriskBackend *backend); 51 void (*hide_menu)(BriskBackend *backend); 52 void (*reset)(BriskBackend *backend); 53 54 gpointer padding[12]; 55 }; 56 57 /** 58 * BriskBackend is an abstract top-level class which is used as the base 59 * of all other backend implementations within Brisk. 60 */ 61 struct _BriskBackend { 62 GObject parent; 63 }; 64 65 #define BRISK_TYPE_BACKEND brisk_backend_get_type() 66 #define BRISK_BACKEND(o) (G_TYPE_CHECK_INSTANCE_CAST((o), BRISK_TYPE_BACKEND, BriskBackend)) 67 #define BRISK_IS_BACKEND(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), BRISK_TYPE_BACKEND)) 68 #define BRISK_BACKEND_CLASS(o) (G_TYPE_CHECK_CLASS_CAST((o), BRISK_TYPE_BACKEND, BriskBackendClass)) 69 #define BRISK_IS_BACKEND_CLASS(o) (G_TYPE_CHECK_CLASS_TYPE((o), BRISK_TYPE_BACKEND)) 70 #define BRISK_BACKEND_GET_CLASS(o) \ 71 (G_TYPE_INSTANCE_GET_CLASS((o), BRISK_TYPE_BACKEND, BriskBackendClass)) 72 73 GType brisk_backend_get_type(void); 74 75 /* API Methods Follow */ 76 77 /* Core vfuncs required by everyone */ 78 unsigned int brisk_backend_get_flags(BriskBackend *backend); 79 const gchar *brisk_backend_get_id(BriskBackend *backend); 80 const gchar *brisk_backend_get_display_name(BriskBackend *backend); 81 GMenu *brisk_backend_get_item_actions(BriskBackend *backend, BriskItem *item, GActionGroup *group); 82 83 /* Attempt to load for the first time */ 84 gboolean brisk_backend_load(BriskBackend *backend); 85 86 /** 87 * Helpers for subclasses 88 */ 89 void brisk_backend_item_added(BriskBackend *backend, BriskItem *item); 90 void brisk_backend_item_removed(BriskBackend *backend, const gchar *id); 91 void brisk_backend_section_added(BriskBackend *backend, BriskSection *section); 92 void brisk_backend_section_removed(BriskBackend *backend, const gchar *id); 93 void brisk_backend_invalidate_filter(BriskBackend *backend); 94 void brisk_backend_hide_menu(BriskBackend *backend); 95 void brisk_backend_reset(BriskBackend *backend); 96 97 G_END_DECLS 98 99 /* 100 * Editor modelines - https://www.wireshark.org/tools/modelines.html 101 * 102 * Local variables: 103 * c-basic-offset: 8 104 * tab-width: 8 105 * indent-tabs-mode: nil 106 * End: 107 * 108 * vi: set shiftwidth=8 tabstop=8 expandtab: 109 * :indentSize=8:tabSize=8:noTabs=true: 110 */ 111