diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2018-04-08 19:22:39 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2018-05-29 16:09:51 -0300 |
commit | 10cf920fef3cab239bfd1bf5fc952d2121686cf0 (patch) | |
tree | a8e4f03bc962d2369cef85bb7518d95479cbdc83 | |
parent | a78cbe39634192e6e050c9bd2e6518aabf462a18 (diff) | |
download | gnome-control-center-10cf920fef3cab239bfd1bf5fc952d2121686cf0.tar.gz |
panel-loader: Add support for static init functions
Static init functions are functions that initialize resources
or monitor daemons without needing any contextual information,
such as a CcPanel instance or access to a CcShell implementation.
These functions are meant to be used for monitoring a panel's
visibility, when it makes sense. Usually, panels that represent
hardware that potentially is not available or is not supported
should hide itself.
Following this commit, the Wi-Fi panel panel will be adapted as
the first user of this new API. Other panels that require this
functionality will be adapted later.
-rw-r--r-- | shell/cc-panel-loader.c | 68 | ||||
-rw-r--r-- | shell/cc-panel.h | 14 |
2 files changed, 55 insertions, 27 deletions
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c index 55492ef98..b64ad034a 100644 --- a/shell/cc-panel-loader.c +++ b/shell/cc-panel-loader.c @@ -24,6 +24,7 @@ #include <string.h> #include <gio/gdesktopappinfo.h> +#include "cc-panel.h" #include "cc-panel-loader.h" #ifndef CC_PANEL_LOADER_NO_GTYPES @@ -63,11 +64,11 @@ extern GType cc_user_panel_get_type (void); extern GType cc_wacom_panel_get_type (void); #endif /* BUILD_WACOM */ -#define PANEL_TYPE(name, get_type) { name, get_type } +#define PANEL_TYPE(name, get_type, init_func) { name, get_type, init_func } #else /* CC_PANEL_LOADER_NO_GTYPES */ -#define PANEL_TYPE(name, get_type) { name } +#define PANEL_TYPE(name, get_type, init_func) { name } #endif @@ -75,40 +76,41 @@ static struct { const char *name; #ifndef CC_PANEL_LOADER_NO_GTYPES GType (*get_type)(void); + CcPanelStaticInitFunc static_init_func; #endif } all_panels[] = { - PANEL_TYPE("background", cc_background_panel_get_type ), + PANEL_TYPE("background", cc_background_panel_get_type, NULL), #ifdef BUILD_BLUETOOTH - PANEL_TYPE("bluetooth", cc_bluetooth_panel_get_type ), + PANEL_TYPE("bluetooth", cc_bluetooth_panel_get_type, NULL), #endif - PANEL_TYPE("color", cc_color_panel_get_type ), - PANEL_TYPE("datetime", cc_date_time_panel_get_type ), - PANEL_TYPE("display", cc_display_panel_get_type ), - PANEL_TYPE("info-overview", cc_info_overview_panel_get_type), - PANEL_TYPE("default-apps", cc_info_default_apps_panel_get_type), - PANEL_TYPE("removable-media", cc_info_removable_media_panel_get_type), - PANEL_TYPE("keyboard", cc_keyboard_panel_get_type ), - PANEL_TYPE("mouse", cc_mouse_panel_get_type ), + PANEL_TYPE("color", cc_color_panel_get_type, NULL), + PANEL_TYPE("datetime", cc_date_time_panel_get_type, NULL), + PANEL_TYPE("display", cc_display_panel_get_type, NULL), + PANEL_TYPE("info-overview", cc_info_overview_panel_get_type, NULL), + PANEL_TYPE("default-apps", cc_info_default_apps_panel_get_type, NULL), + PANEL_TYPE("removable-media", cc_info_removable_media_panel_get_type, NULL), + PANEL_TYPE("keyboard", cc_keyboard_panel_get_type, NULL), + PANEL_TYPE("mouse", cc_mouse_panel_get_type, NULL), #ifdef BUILD_NETWORK - PANEL_TYPE("network", cc_network_panel_get_type ), - PANEL_TYPE("wifi", cc_wifi_panel_get_type ), + PANEL_TYPE("network", cc_network_panel_get_type, NULL), + PANEL_TYPE("wifi", cc_wifi_panel_get_type, NULL), #endif - PANEL_TYPE("notifications", cc_notifications_panel_get_type), - PANEL_TYPE("online-accounts", cc_goa_panel_get_type ), - PANEL_TYPE("power", cc_power_panel_get_type ), - PANEL_TYPE("printers", cc_printers_panel_get_type ), - PANEL_TYPE("privacy", cc_privacy_panel_get_type ), - PANEL_TYPE("region", cc_region_panel_get_type ), - PANEL_TYPE("search", cc_search_panel_get_type ), - PANEL_TYPE("sharing", cc_sharing_panel_get_type ), - PANEL_TYPE("sound", cc_sound_panel_get_type ), + PANEL_TYPE("notifications", cc_notifications_panel_get_type, NULL), + PANEL_TYPE("online-accounts", cc_goa_panel_get_type, NULL), + PANEL_TYPE("power", cc_power_panel_get_type, NULL), + PANEL_TYPE("printers", cc_printers_panel_get_type, NULL), + PANEL_TYPE("privacy", cc_privacy_panel_get_type, NULL), + PANEL_TYPE("region", cc_region_panel_get_type, NULL), + PANEL_TYPE("search", cc_search_panel_get_type, NULL), + PANEL_TYPE("sharing", cc_sharing_panel_get_type, NULL), + PANEL_TYPE("sound", cc_sound_panel_get_type, NULL), #ifdef BUILD_THUNDERBOLT - PANEL_TYPE("thunderbolt", cc_bolt_panel_get_type ), + PANEL_TYPE("thunderbolt", cc_bolt_panel_get_type, NULL), #endif - PANEL_TYPE("universal-access", cc_ua_panel_get_type ), - PANEL_TYPE("user-accounts", cc_user_panel_get_type ), + PANEL_TYPE("universal-access", cc_ua_panel_get_type, NULL), + PANEL_TYPE("user-accounts", cc_user_panel_get_type, NULL), #ifdef BUILD_WACOM - PANEL_TYPE("wacom", cc_wacom_panel_get_type ), + PANEL_TYPE("wacom", cc_wacom_panel_get_type, NULL), #endif }; @@ -192,6 +194,18 @@ cc_panel_loader_fill_model (CcShellModel *model) cc_shell_model_add_item (model, category, G_APP_INFO (app), all_panels[i].name); } + + /* If there's an static init function, execute it after adding all panels to + * the model. This will allow the panels to show or hide themselves without + * having an instance running. + */ +#ifndef CC_PANEL_LOADER_NO_GTYPES + for (i = 0; i < G_N_ELEMENTS (all_panels); i++) + { + if (all_panels[i].static_init_func) + all_panels[i].static_init_func (); + } +#endif } #ifndef CC_PANEL_LOADER_NO_GTYPES diff --git a/shell/cc-panel.h b/shell/cc-panel.h index c14bad893..5c705a4aa 100644 --- a/shell/cc-panel.h +++ b/shell/cc-panel.h @@ -32,6 +32,20 @@ */ #define CC_PANEL_REGISTER(PluginName, plugin_name) G_DEFINE_TYPE (PluginName, plugin_name, CC_TYPE_PANEL) +/** + * CcPanelStaticInitFunc: + * + * Function that statically allocates resources and initializes + * any data that the panel will make use of during runtime. + * + * If panels represent hardware that can potentially not exist, + * e.g. the Wi-Fi panel, these panels can use this function to + * show or hide themselves without needing to have an instance + * created and running. + */ +typedef void (*CcPanelStaticInitFunc) (void); + + #define CC_TYPE_PANEL (cc_panel_get_type()) G_DECLARE_DERIVABLE_TYPE (CcPanel, cc_panel, CC, PANEL, GtkBin) |