aboutsummaryrefslogtreecommitdiff
path: root/src/lib/glade.c
blob: 4bfb0f7c3050169c99936f72d23b052bf9ba1148 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
     This file is part of GNUnet.
     (C) 2010 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 2, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file src/lib/glade.c
 * @brief code for integration with glade
 * @author Christian Grothoff
 */
#include "gnunet_gtk_config.h"
#include "gnunet_gtk.h"


/**
 * Initialize GTK search path for icons.
 */
void
GNUNET_GTK_set_icon_search_path ()
{
  char *buf;

  buf = GNUNET_GTK_installation_get_path (GNUNET_OS_IPK_ICONDIR);
  gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), buf);
  GNUNET_free (buf);
}


/**
 * Get the name of the directory where all of our package
 * data is stored ($PREFIX/share/)
 *
 * @return name of the data directory
 */
const char *
GNUNET_GTK_get_data_dir ()
{
  static char *dd;

  if (dd == NULL)
    dd = GNUNET_GTK_installation_get_path (GNUNET_OS_IPK_DATADIR);
  return dd;
}


/**
 * Create an initialize a new builder based on the
 * GNUnet-GTK glade file.
 *
 * @param filename name of the resource file to load
 * @param user_data user_data to pass to signal handlers,
 *        use "NULL" to pass the GtkBuilder itself.
 * @return NULL on error
 */
GtkBuilder *
GNUNET_GTK_get_new_builder (const char *filename,
			    void *user_data)
{
  char *glade_path;
  GtkBuilder *ret;
  GError *error;

  ret = gtk_builder_new ();
  gtk_builder_set_translation_domain (ret, "gnunet-gtk");
  GNUNET_asprintf (&glade_path, "%s%s", GNUNET_GTK_get_data_dir (), filename);
  error = NULL;
  if (0 == gtk_builder_add_from_file (ret, glade_path, &error))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to load `%s': %s\n"),
                glade_path, error->message);
    g_error_free (error);
    GNUNET_free (glade_path);
    return NULL;
  }
  gtk_builder_connect_signals (ret, (user_data == NULL) ? ret : user_data);
  GNUNET_free (glade_path);
  return ret;
}



/* end of glade.c */