udapted vi.po
[rhythmbox.git] / lib / rb-glade-helpers.c
blobc562670f038fbc141fd34436978c93e1181f951b
1 /*
2 * arch-tag: Implementation of Rhythmbox Glade XML utility functions
4 * Copyright (C) 2002 Jorn Baayen
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gmodule.h>
23 #include <gtk/gtk.h>
24 #include <string.h>
26 #include "rb-glade-helpers.h"
27 #include "rb-file-helpers.h"
29 static void glade_signal_connect_func (const gchar *cb_name, GObject *obj,
30 const gchar *signal_name, const gchar *signal_data,
31 GObject *conn_obj, gboolean conn_after,
32 gpointer user_data);
34 GladeXML *
35 rb_glade_xml_new (const char *file,
36 const char *root,
37 gpointer user_data)
39 GladeXML *xml;
40 const char *name;
42 g_return_val_if_fail (file != NULL, NULL);
44 /* is the first characters is /, it's an absolute path, otherwise locate it */
45 if (file[0] == G_DIR_SEPARATOR)
46 name = file;
47 else
48 name = rb_file (file);
50 xml = glade_xml_new (name, root, NULL);
52 glade_xml_signal_autoconnect_full (xml,
53 (GladeXMLConnectFunc) glade_signal_connect_func,
54 user_data);
56 return xml;
59 static void
60 glade_signal_connect_func (const gchar *cb_name, GObject *obj,
61 const gchar *signal_name, const gchar *signal_data,
62 GObject *conn_obj, gboolean conn_after,
63 gpointer user_data)
65 /** Module with all the symbols of the program */
66 static GModule *mod_self = NULL;
67 gpointer handler_func;
69 /* initialize gmodule */
70 if (mod_self == NULL)
72 mod_self = g_module_open (NULL, 0);
73 g_assert (mod_self != NULL);
76 if (g_module_symbol (mod_self, cb_name, &handler_func))
78 /* found callback */
79 if (conn_obj)
81 if (conn_after)
83 g_signal_connect_object
84 (obj, signal_name,
85 handler_func, conn_obj,
86 G_CONNECT_AFTER);
88 else
90 g_signal_connect_object
91 (obj, signal_name,
92 handler_func, conn_obj,
93 G_CONNECT_SWAPPED);
96 else
98 /* no conn_obj; use standard connect */
99 gpointer data = NULL;
101 data = user_data;
103 if (conn_after)
105 g_signal_connect_after
106 (obj, signal_name,
107 handler_func, data);
109 else
111 g_signal_connect
112 (obj, signal_name,
113 handler_func, data);
117 else
119 g_warning("callback function not found: %s", cb_name);
123 void
124 rb_glade_boldify_label (GladeXML *xml, const char *name)
126 GtkWidget *widget;
128 widget = glade_xml_get_widget (xml, name);
130 if (widget == NULL) {
131 g_warning ("widget '%s' not found", name);
132 return;
135 /* this way is probably better, but for some reason doesn't work with
136 * labels with mnemonics.
138 static PangoAttrList *pattrlist = NULL;
140 if (pattrlist == NULL) {
141 PangoAttribute *attr;
143 pattrlist = pango_attr_list_new ();
144 attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
145 attr->start_index = 0;
146 attr->end_index = G_MAXINT;
147 pango_attr_list_insert (pattrlist, attr);
149 gtk_label_set_attributes (GTK_LABEL (widget), pattrlist);*/
151 gchar *str_final;
152 str_final = g_strdup_printf ("<b>%s</b>", gtk_label_get_label (GTK_LABEL (widget)));
153 gtk_label_set_markup_with_mnemonic (GTK_LABEL (widget), str_final);
154 g_free (str_final);
157 gboolean
158 rb_combo_box_hyphen_separator_func (GtkTreeModel *model,
159 GtkTreeIter *iter,
160 gpointer data)
162 const char *s;
164 gtk_tree_model_get (model, iter, 0, &s, -1);
166 if (s == NULL)
167 return FALSE;
169 return (strcmp (s, "-") == 0);