builder.c (3452B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2010, 2024 GNUnet e.V. 4 5 GNUnet is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with GNUnet; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 21 /** 22 * @file src/util/builder.c 23 * @brief code for integration with GtkBuilder 24 * @author Christian Grothoff 25 */ 26 #include "anastasis_gtk_config.h" 27 #include "anastasis_gtk_util.h" 28 29 30 void 31 ANASTASIS_GTK_set_icon_search_path (const struct GNUNET_OS_ProjectData *pd) 32 { 33 char *buf; 34 35 buf = GNUNET_OS_installation_get_path (pd, 36 GNUNET_OS_IPK_ICONDIR); 37 gtk_icon_theme_add_search_path ( 38 gtk_icon_theme_get_for_display (gdk_display_get_default ()), 39 buf); 40 GNUNET_free (buf); 41 } 42 43 44 const char * 45 ANASTASIS_GTK_get_data_dir (const struct GNUNET_OS_ProjectData *pd) 46 { 47 static char *dd; 48 49 if (NULL == dd) 50 dd = GNUNET_OS_installation_get_path (pd, 51 GNUNET_OS_IPK_DATADIR); 52 return dd; 53 } 54 55 56 void 57 ANASTASIS_GTK_load_css (const struct GNUNET_OS_ProjectData *pd) 58 { 59 GtkCssProvider *css; 60 char *path; 61 62 GNUNET_asprintf (&path, 63 "%s%s", 64 ANASTASIS_GTK_get_data_dir (pd), 65 "anastasis-gtk.css"); 66 css = gtk_css_provider_new (); 67 gtk_css_provider_load_from_path (css, 68 path); 69 gtk_style_context_add_provider_for_display ( 70 gdk_display_get_default (), 71 GTK_STYLE_PROVIDER (css), 72 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); 73 GNUNET_free (path); 74 g_object_unref (css); 75 } 76 77 78 GtkBuilder * 79 ANASTASIS_GTK_get_new_builder (const struct GNUNET_OS_ProjectData *pd, 80 const char *filename, 81 GObject *user_data) 82 { 83 char *ui_path; 84 GtkBuilder *ret; 85 GError *error; 86 87 ret = gtk_builder_new (); 88 /* GtkBuilder connects the signals named in the file while it parses it, and 89 passes the "current object" to the handlers as their user data, so this 90 has to be set before anything is loaded. */ 91 gtk_builder_set_current_object (ret, 92 (NULL != user_data) 93 ? user_data 94 : G_OBJECT (ret)); 95 GNUNET_asprintf (&ui_path, 96 "%s%s", 97 ANASTASIS_GTK_get_data_dir (pd), 98 filename); 99 error = NULL; 100 if (0 == gtk_builder_add_from_file (ret, 101 ui_path, 102 &error)) 103 { 104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 105 _ ("Failed to load `%s': %s\n"), 106 ui_path, 107 error->message); 108 g_error_free (error); 109 GNUNET_free (ui_path); 110 g_object_unref (G_OBJECT (ret)); 111 return NULL; 112 } 113 GNUNET_free (ui_path); 114 return ret; 115 } 116 117 118 /* end of builder.c */