hythmbox-2.98/lib/rb-builder-helpers.c

No issues found

  1 /*
  2  *  Copyright (C) 2002 Jorn Baayen
  3  *
  4  *  This program is free software; you can redistribute it and/or modify
  5  *  it under the terms of the GNU General Public License as published by
  6  *  the Free Software Foundation; either version 2, or (at your option)
  7  *  any later version.
  8  *
  9  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 10  *  GStreamer plugins to be used and distributed together with GStreamer
 11  *  and Rhythmbox. This permission is above and beyond the permissions granted
 12  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 13  *  you may extend this exception to your version of the code, but you are not
 14  *  obligated to do so. If you do not wish to do so, delete this exception
 15  *  statement from your version.
 16  *
 17  *  This program is distributed in the hope that it will be useful,
 18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20  *  GNU General Public License for more details.
 21  *
 22  *  You should have received a copy of the GNU General Public License
 23  *  along with this program; if not, write to the Free Software
 24  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 25  *
 26  */
 27 
 28 #include "config.h"
 29 
 30 #include <gtk/gtk.h>
 31 #include <string.h>
 32 
 33 #include "rb-builder-helpers.h"
 34 #include "rb-file-helpers.h"
 35 
 36 /**
 37  * SECTION:rb-builder-helpers
 38  * @short_description: helper functions for dealing with GtkBuilder files
 39  *
 40  * Some simple helper functions to make it a bit easier to deal with
 41  * widgets built from GtkBuilder files.
 42  */
 43 
 44 /**
 45  * rb_builder_load:
 46  * @file: filename, either absolute or relative to the data directory
 47  * @user_data: user data to pass to autoconnected signal handlers
 48  *
 49  * Locates and reads a GtkBuilder file, automatically connecting
 50  * signal handlers where possible.  The caller can specify a path
 51  * relative to the shared data directory, or its 'ui' or 'art'
 52  * subdirectories.
 53  *
 54  * Return value: (transfer full): #GtkBuilder object built from the file
 55  */
 56 GtkBuilder *
 57 rb_builder_load (const char *file, gpointer user_data)
 58 {
 59 	GtkBuilder *builder;
 60 	const char *name;
 61 	GError *error = NULL;
 62 
 63 	g_return_val_if_fail (file != NULL, NULL);
 64 
 65 	/* if the first character is /, it's an absolute path, otherwise locate it */
 66 	if (file[0] == G_DIR_SEPARATOR)
 67 		name = file;
 68 	else
 69 		name = rb_file (file);
 70 
 71 	builder = gtk_builder_new ();
 72 	gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
 73 	if (gtk_builder_add_from_file (builder, name, &error) == 0) {
 74 		g_warning ("Error loading GtkBuilder file %s: %s", name, error->message);
 75 		g_error_free (error);
 76 	}
 77 
 78 	gtk_builder_connect_signals (builder, user_data);
 79 
 80 	return builder;
 81 }
 82 
 83 
 84 /**
 85  * rb_builder_boldify_label:
 86  * @builder: a #GtkBuilder instance
 87  * @name: name of the label to boldify
 88  *
 89  * Makes a label built from a GtkBuilder file bold.
 90  */
 91 void
 92 rb_builder_boldify_label (GtkBuilder *builder, const char *name)
 93 {
 94 	GObject *widget;
 95 	gchar *str_final;
 96 
 97 	/* once we require gtk+ 2.16 or newer, we can set the attributes on
 98 	 * the labels in the builder files, so we won't need this any more.
 99 	 */
100 
101 	widget = gtk_builder_get_object (builder, name);
102 	if (widget == NULL) {
103 		g_warning ("widget '%s' not found", name);
104 		return;
105 	}
106 
107 	str_final = g_strdup_printf ("<b>%s</b>", gtk_label_get_label (GTK_LABEL (widget)));
108 	gtk_label_set_markup_with_mnemonic (GTK_LABEL (widget), str_final);
109 	g_free (str_final);
110 }
111 
112 /**
113  * rb_combo_box_hyphen_separator_func:
114  * @model: a #GtkTreeModel
115  * @iter: a #GtkTreeIter
116  * @data: nothing
117  *
118  * A row separator function to use for GtkComboBox widgets.
119  * It expects the model to contain a string in its first column,
120  * and interprets a string containing a single hyphen character
121  * as a separator.
122  *
123  * Return value: %TRUE if the row pointed to by @iter is a separator
124  */
125 gboolean
126 rb_combo_box_hyphen_separator_func (GtkTreeModel *model,
127 				    GtkTreeIter *iter,
128 				    gpointer data)
129 {
130 	const char *s;
131 
132 	gtk_tree_model_get (model, iter, 0, &s, -1);
133 
134 	if (s == NULL)
135 		return FALSE;
136 
137 	return (strcmp (s, "-") == 0);
138 }