"Fossies" - the Fresh Open Source Software Archive

Member "evolution-mapi-3.46.1/src/configuration/e-mapi-config-ui-extension.c" (2 Dec 2022, 4591 Bytes) of package /linux/misc/evolution-mapi-3.46.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "e-mapi-config-ui-extension.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * e-mapi-config-ui-extension.c
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU Lesser General Public
    6  * License as published by the Free Software Foundation; either
    7  * version 2 of the License, or (at your option) version 3.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12  * Lesser General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU Lesser General Public
   15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
   16  *
   17  */
   18 
   19 #include "evolution-mapi-config.h"
   20 
   21 #include <glib/gi18n-lib.h>
   22 #include <gtk/gtk.h>
   23 
   24 #include <shell/e-shell-view.h>
   25 
   26 #include "e-mapi-config-utils.h"
   27 
   28 #include "e-mapi-config-ui-extension.h"
   29 
   30 G_DEFINE_DYNAMIC_TYPE (
   31     EMapiConfigUIExtension,
   32     e_mapi_config_ui_extension,
   33     E_TYPE_EXTENSION)
   34 
   35 static void
   36 e_mapi_config_ui_extension_shell_view_toggled_cb (EShellView *shell_view,
   37                           EMapiConfigUIExtension *ui_ext)
   38 {
   39     EShellViewClass *shell_view_class;
   40     EShellWindow *shell_window;
   41     GtkUIManager *ui_manager;
   42     gpointer key = NULL, value = NULL;
   43     const gchar *ui_def;
   44     gboolean is_active, need_update;
   45 
   46     g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
   47     g_return_if_fail (ui_ext != NULL);
   48 
   49     shell_view_class = E_SHELL_VIEW_GET_CLASS (shell_view);
   50     g_return_if_fail (shell_view_class != NULL);
   51 
   52     shell_window = e_shell_view_get_shell_window (shell_view);
   53     ui_manager = e_shell_window_get_ui_manager (shell_window);
   54 
   55     need_update = ui_ext->current_ui_id != 0;
   56     if (ui_ext->current_ui_id) {
   57         gtk_ui_manager_remove_ui (ui_manager, ui_ext->current_ui_id);
   58         ui_ext->current_ui_id = 0;
   59     }
   60 
   61     is_active = e_shell_view_is_active (shell_view);
   62     if (!is_active) {
   63         if (need_update)
   64             gtk_ui_manager_ensure_update (ui_manager);
   65 
   66         return;
   67     }
   68 
   69     if (!g_hash_table_lookup_extended (ui_ext->ui_definitions, shell_view_class->ui_manager_id, &key, &value)) {
   70         gchar *ui_definition = NULL;
   71 
   72         e_mapi_config_utils_init_ui (shell_view, shell_view_class->ui_manager_id, &ui_definition);
   73         g_hash_table_insert (ui_ext->ui_definitions, g_strdup (shell_view_class->ui_manager_id), ui_definition);
   74     }
   75 
   76     ui_def = g_hash_table_lookup (ui_ext->ui_definitions, shell_view_class->ui_manager_id);
   77     if (ui_def) {
   78         GError *error = NULL;
   79 
   80         ui_ext->current_ui_id = gtk_ui_manager_add_ui_from_string (ui_manager, ui_def, -1, &error);
   81         need_update = TRUE;
   82 
   83         if (error) {
   84             g_warning ("%s: Failed to add ui definition: %s", G_STRFUNC, error->message);
   85             g_error_free (error);
   86         }
   87     }
   88 
   89     if (need_update)
   90         gtk_ui_manager_ensure_update (ui_manager);
   91 }
   92 
   93 static void
   94 e_mapi_config_ui_extension_constructed (GObject *object)
   95 {
   96     EExtension *extension;
   97     EExtensible *extensible;
   98 
   99     extension = E_EXTENSION (object);
  100     extensible = e_extension_get_extensible (extension);
  101 
  102     /* Chain up to parent's constructed() method. */
  103     G_OBJECT_CLASS (e_mapi_config_ui_extension_parent_class)->constructed (object);
  104 
  105     g_signal_connect (E_SHELL_VIEW (extensible), "toggled", G_CALLBACK (e_mapi_config_ui_extension_shell_view_toggled_cb), extension);
  106 }
  107 
  108 static void
  109 e_mapi_config_ui_extension_finalize (GObject *object)
  110 {
  111     EMapiConfigUIExtension *ui_ext = (EMapiConfigUIExtension *) object;
  112 
  113     /* Chain up to parent's finalize() method. */
  114     G_OBJECT_CLASS (e_mapi_config_ui_extension_parent_class)->finalize (object);
  115 
  116     g_hash_table_destroy (ui_ext->ui_definitions);
  117 }
  118 
  119 static void
  120 e_mapi_config_ui_extension_class_init (EMapiConfigUIExtensionClass *class)
  121 {
  122     GObjectClass *object_class;
  123     EExtensionClass *extension_class;
  124 
  125     object_class = G_OBJECT_CLASS (class);
  126     object_class->constructed = e_mapi_config_ui_extension_constructed;
  127     object_class->finalize = e_mapi_config_ui_extension_finalize;
  128 
  129     extension_class = E_EXTENSION_CLASS (class);
  130     extension_class->extensible_type = E_TYPE_SHELL_VIEW;
  131 }
  132 
  133 static void
  134 e_mapi_config_ui_extension_class_finalize (EMapiConfigUIExtensionClass *class)
  135 {
  136 }
  137 
  138 static void
  139 e_mapi_config_ui_extension_init (EMapiConfigUIExtension *extension)
  140 {
  141     extension->current_ui_id = 0;
  142     extension->ui_definitions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
  143 }
  144 
  145 void
  146 e_mapi_config_ui_extension_type_register (GTypeModule *type_module)
  147 {
  148     /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
  149      *     function, so we have to wrap it with a public function in
  150      *     order to register types from a separate compilation unit. */
  151     e_mapi_config_ui_extension_register_type (type_module);
  152 }