aboutsummaryrefslogtreecommitdiff
path: root/src/lib/glade.c
blob: f15dfca6faca06d194e49e18db9a08c488c44fda (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
     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;
}


/**
 * Obtain a string from a GtkTreeView's model.
 *
 * @param treeview treeview to inspect
 * @param treepath path that identifies the item
 * @param column number of the column with the string
 * @param value where to store the string
 * @return TRUE on success, FALSE on errors
 */
gboolean
GNUNET_GTK_get_tree_string (GtkTreeView * treeview, GtkTreePath * treepath,
                            guint column, gchar ** value)
{
  gboolean ok;
  GtkTreeModel *model;

  model = gtk_tree_view_get_model (treeview);
  if (!model)
    return FALSE;

  GtkTreeIter iter;

  ok = gtk_tree_model_get_iter (model, &iter, treepath);
  if (!ok)
    return FALSE;

  *value = NULL;
  gtk_tree_model_get (model, &iter, column, value, -1);
  if (*value == NULL)
    return FALSE;
  return TRUE;
}


/**
 * 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;
}


/**
 * Remove the given entry and all of its children from the tree store.
 *
 * @param ts tree store to change
 * @param root root of the subtree to remove
 */
void
GNUNET_FS_GTK_remove_treestore_subtree (GtkTreeStore * ts,
					GtkTreeIter * root)
{
  GtkTreeIter child;
  
  while (gtk_tree_model_iter_children (GTK_TREE_MODEL (ts), &child, root))
    GNUNET_FS_GTK_remove_treestore_subtree (ts, &child);
  gtk_tree_store_remove (ts, root);
}


/* end of glade.c */