00001 #ifndef _FUNCTIONS_LIBGLADE_H
00002 #define _FUNCTIONS_LIBGLADE_H
00003
00004 #include <gtkmm.h>
00005 #include <libglademm.h>
00006 #include <glibmm.h>
00007 #include <glade/glade-init.h>
00008 #include <glade/glade-build.h>
00009 #include <uwidgets/UWidgets.h>
00010 #include <usvgwidgets/USVGWidgets.h>
00011 #include <objects/Objects.h>
00012 #include <components/Components.h>
00013 #include <typical/Typical.h>
00014 #include <UPostcreate.h>
00015
00016 using namespace UniWidgets;
00017 using namespace std;
00018
00019
00020 template <class UType> static GtkWidget *glade_new(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00021 {
00022 UType *uw = manage(new UType);
00023 GtkWidget *w = GTK_WIDGET(uw->gobj());
00024 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00025
00026
00027 for (unsigned int i=0; i<info->n_properties; i++) {
00028 Glib::ustring name_prop(info->properties[i].name);
00029 const gchar *name;
00030 if(name_prop == "tooltip")
00031 name = "tooltip-text";
00032 else
00033 name = info->properties[i].name;
00034 const gchar *value = info->properties[i].value;
00035 GParamSpec *pspec;
00036
00037 pspec = g_object_class_find_property (oclass, name);
00038 if (pspec) {
00039 GValue gvalue = { 0 };
00040
00041 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00042 g_object_set_property(G_OBJECT(w), name, &gvalue);
00043 g_value_unset(&gvalue);
00044 }
00045 }
00046 }
00047
00048 return w;
00049 };
00050
00051 template <class UType> static GtkWidget *glade_new_indicatortwo(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00052 {
00053 UType *uw = manage(new UType);
00054 GtkWidget *w = GTK_WIDGET(uw->gobj());
00055 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00056
00057
00058 for (unsigned int i=0; i<info->n_properties; i++) {
00059 Glib::ustring name_prop(info->properties[i].name);
00060 const gchar *name;
00061 if(name_prop == "tooltip")
00062 name = "tooltip-text";
00063 else
00064 name = info->properties[i].name;
00065 const gchar *value = info->properties[i].value;
00066 GParamSpec *pspec;
00067
00068 pspec = g_object_class_find_property (oclass, name);
00069 if (pspec) {
00070 GValue gvalue = { 0 };
00071
00072 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00073 g_object_set_property(G_OBJECT(w), name, &gvalue);
00074 g_value_unset(&gvalue);
00075 }
00076 }
00077 }
00078
00079 UPostcreate<IndicatorTwoState>::run(uw);
00080
00081 return w;
00082 };
00083
00084 template <class UType> static GtkWidget *glade_new_indicatorfour(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00085 {
00086 UType *uw = manage(new UType);
00087 GtkWidget *w = GTK_WIDGET(uw->gobj());
00088 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00089
00090
00091 for (unsigned int i=0; i<info->n_properties; i++) {
00092 Glib::ustring name_prop(info->properties[i].name);
00093 const gchar *name;
00094 if(name_prop == "tooltip")
00095 name = "tooltip-text";
00096 else
00097 name = info->properties[i].name;
00098 const gchar *value = info->properties[i].value;
00099 GParamSpec *pspec;
00100
00101 pspec = g_object_class_find_property (oclass, name);
00102 if (pspec) {
00103 GValue gvalue = { 0 };
00104
00105 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00106 g_object_set_property(G_OBJECT(w), name, &gvalue);
00107 g_value_unset(&gvalue);
00108 }
00109 }
00110 }
00111
00112 UPostcreate<IndicatorFourState>::run(uw);
00113
00114 return w;
00115 };
00116
00117 template <class UType> static GtkWidget *glade_new_gdg(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00118 {
00119 UType *uw = manage(new UType);
00120 GtkWidget *w = GTK_WIDGET(uw->gobj());
00121 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00122
00123
00124 for (unsigned int i=0; i<info->n_properties; i++) {
00125 Glib::ustring name_prop(info->properties[i].name);
00126 const gchar *name;
00127 if(name_prop == "tooltip")
00128 name = "tooltip-text";
00129 else
00130 name = info->properties[i].name;
00131 const gchar *value = info->properties[i].value;
00132 GParamSpec *pspec;
00133
00134 pspec = g_object_class_find_property (oclass, name);
00135 if (pspec) {
00136 GValue gvalue = { 0 };
00137
00138 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00139 g_object_set_property(G_OBJECT(w), name, &gvalue);
00140 g_value_unset(&gvalue);
00141 }
00142 }
00143 }
00144
00145 UPostcreate<GDG>::run(uw);
00146
00147 return w;
00148 };
00149
00150 template <class UType> static GtkWidget *glade_new_vdg(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00151 {
00152 UType *uw = manage(new UType);
00153 GtkWidget *w = GTK_WIDGET(uw->gobj());
00154 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00155
00156
00157 for (unsigned int i=0; i<info->n_properties; i++) {
00158 Glib::ustring name_prop(info->properties[i].name);
00159 const gchar *name;
00160 if(name_prop == "tooltip")
00161 name = "tooltip-text";
00162 else
00163 name = info->properties[i].name;
00164 const gchar *value = info->properties[i].value;
00165 GParamSpec *pspec;
00166
00167 pspec = g_object_class_find_property (oclass, name);
00168 if (pspec) {
00169 GValue gvalue = { 0 };
00170
00171 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00172 g_object_set_property(G_OBJECT(w), name, &gvalue);
00173 g_value_unset(&gvalue);
00174 }
00175 }
00176 }
00177
00178 UPostcreate<VDG>::run(uw);
00179
00180 return w;
00181 };
00182
00183 static GtkWidget
00184 *proxywidget_glade_new(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00185 {
00186
00187 Glib::ustring module_name;
00188 Glib::ustring manager_name;
00189 Glib::ustring alive_sensor;
00190 Glib::ustring confirm_sensor;
00191 Glib::ustring auto_confirm_time_str;
00192
00193 for (unsigned int i=0; i<info->n_properties ; i++) {
00194 Glib::ustring name(info->properties[i].name);
00195 if(name == "tooltip")
00196 name = "tooltip-text";
00197 if ( name == "module_name" ) {
00198 module_name = info->properties[i].value;
00199 }
00200 if ( name == "manager_name" ) {
00201 manager_name = info->properties[i].value;
00202 }
00203 if ( name == "alive_sensor" ) {
00204 alive_sensor = info->properties[i].value;
00205 }
00206 if ( name == "confirm_sensor" ) {
00207 confirm_sensor = info->properties[i].value;
00208 }
00209 if ( name == "auto_confirm_time_str" ) {
00210 auto_confirm_time_str = info->properties[i].value;
00211 }
00212 }
00213
00214 UProxyWidget *proxy_widget = manage(new UProxyWidget(module_name, manager_name
00215 ,alive_sensor
00216 ,confirm_sensor
00217 ,auto_confirm_time_str));
00218 GtkWidget *w = GTK_WIDGET(proxy_widget->gobj());
00219 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00220
00221 for (unsigned int i=0; i<info->n_properties; i++) {
00222 Glib::ustring name_prop(info->properties[i].name);
00223 const gchar *name;
00224 if(name_prop == "tooltip")
00225 name = "tooltip-text";
00226 else
00227 name = info->properties[i].name;
00228 if (Glib::ustring(name) == "module_name")
00229 continue;
00230 if (Glib::ustring(name) == "manager_name")
00231 continue;
00232 if (Glib::ustring(name) == "alive_sensor")
00233 continue;
00234 if (Glib::ustring(name) == "confirm_sensor")
00235 continue;
00236 if (Glib::ustring(name) == "auto_confirm_time_str")
00237 continue;
00238
00239 const gchar *value = info->properties[i].value;
00240 GParamSpec *pspec;
00241
00242 pspec = g_object_class_find_property (oclass, name);
00243 if (pspec) {
00244 GValue gvalue = { 0 };
00245
00246 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00247 g_object_set_property(G_OBJECT(w), name, &gvalue);
00248 g_value_unset(&gvalue);
00249 }
00250 }
00251 }
00252
00253
00254
00255
00256 return w;
00257 }
00258
00259 static GtkWidget
00260 *usvgindicatorplus_glade_new(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00261 {
00262 Glib::ustring image0_path;
00263 Glib::ustring image1_path;
00264 int n=0;
00265 for (unsigned int i=0; i<info->n_properties && n<2; i++) {
00266 Glib::ustring name(info->properties[i].name);
00267 if(name == "tooltip")
00268 name = "tooltip-text";
00269 if (name == "image0_path") {
00270 image0_path = info->properties[i].value;
00271 n++;
00272 }
00273 if (name == "image1_path") {
00274 image1_path = info->properties[i].value;
00275 n++;
00276 }
00277 }
00278 USVGIndicatorPlus *usvgindicatorplus = manage(new USVGIndicatorPlus(image0_path, image1_path));
00279 GtkWidget *w = GTK_WIDGET(usvgindicatorplus->gobj());
00280 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00281
00282 for (unsigned int i=0; i<info->n_properties; i++) {
00283 Glib::ustring name_prop(info->properties[i].name);
00284 const gchar *name;
00285 if(name_prop == "tooltip")
00286 name = "tooltip-text";
00287 else
00288 name = info->properties[i].name;
00289
00290 if (Glib::ustring(name) == "image0-path")
00291 continue;
00292 if (Glib::ustring(name) == "image1-path")
00293 continue;
00294
00295 const gchar *value = info->properties[i].value;
00296 GParamSpec *pspec;
00297
00298 pspec = g_object_class_find_property (oclass, name);
00299 if (pspec) {
00300 GValue gvalue = { 0 };
00301
00302 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00303 g_object_set_property(G_OBJECT(w), name, &gvalue);
00304 g_value_unset(&gvalue);
00305 }
00306 }
00307 }
00308
00309
00310
00311
00312 return w;
00313 }
00314
00315 static GtkWidget
00316 *usvgbuttonindicator_glade_new(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00317 {
00318 Glib::ustring image0_path;
00319 Glib::ustring image1_path;
00320 int n=0;
00321 for (unsigned int i=0; i<info->n_properties && n<2; i++) {
00322 Glib::ustring name(info->properties[i].name);
00323 if(name == "tooltip")
00324 name = "tooltip-text";
00325 if (name == "image0_path") {
00326 image0_path = info->properties[i].value;
00327 n++;
00328 }
00329 if (name == "image1_path") {
00330 image1_path = info->properties[i].value;
00331 n++;
00332 }
00333 }
00334 USVGButtonIndicator *usvgbuttonindicator = manage(new USVGButtonIndicator(image0_path, image1_path));
00335 GtkWidget *w = GTK_WIDGET(usvgbuttonindicator->gobj());
00336 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00337
00338 for (unsigned int i=0; i<info->n_properties; i++) {
00339 Glib::ustring name_prop(info->properties[i].name);
00340 const gchar *name;
00341 if(name_prop == "tooltip")
00342 name = "tooltip-text";
00343 else
00344 name = info->properties[i].name;
00345
00346 if (Glib::ustring(name) == "image0-path")
00347 continue;
00348 if (Glib::ustring(name) == "image1-path")
00349 continue;
00350
00351 const gchar *value = info->properties[i].value;
00352 GParamSpec *pspec;
00353
00354 pspec = g_object_class_find_property (oclass, name);
00355 if (pspec) {
00356 GValue gvalue = { 0 };
00357
00358 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00359 g_object_set_property(G_OBJECT(w), name, &gvalue);
00360 g_value_unset(&gvalue);
00361 }
00362 }
00363 }
00364
00365
00366
00367
00368 return w;
00369 }
00370
00371 static GtkWidget
00372 *usvgindicatorbig_glade_new(GladeXML *xml, GType widget_type, GladeWidgetInfo *info)
00373 {
00374 Glib::ustring image0_path;
00375 Glib::ustring image1_path;
00376 Glib::ustring name;
00377 int n=0;
00378 for (unsigned int i=0; i<info->n_properties && n<3; i++) {
00379 Glib::ustring name(info->properties[i].name);
00380 if(name == "tooltip")
00381 name = "tooltip-text";
00382 if ( name == "falsefile" ) {
00383 image0_path = info->properties[i].value;
00384 n++;
00385 }
00386 if ( name == "truefile" ) {
00387 image1_path = info->properties[i].value;
00388 n++;
00389 }
00390 if ( name == "name" ) {
00391 name = info->properties[i].value;
00392 n++;
00393 }
00394 }
00395
00396 USVGIndicatorBig *usvgindicatorbig = manage(new USVGIndicatorBig(image0_path, image1_path));
00397 GtkWidget *w = GTK_WIDGET(usvgindicatorbig->gobj());
00398 GObjectClass *oclass = G_OBJECT_GET_CLASS(w);
00399
00400 for (unsigned int i=0; i<info->n_properties; i++) {
00401 Glib::ustring name_prop(info->properties[i].name);
00402 const gchar *name;
00403 if(name_prop == "tooltip")
00404 name = "tooltip-text";
00405 else
00406 name = info->properties[i].name;
00407
00408 if (Glib::ustring(name) == "falsefile")
00409 continue;
00410 if (Glib::ustring(name) == "truefile")
00411 continue;
00412
00413 const gchar *value = info->properties[i].value;
00414 GParamSpec *pspec;
00415
00416 pspec = g_object_class_find_property (oclass, name);
00417 if (pspec) {
00418 GValue gvalue = { 0 };
00419
00420 if (glade_xml_set_value_from_string(xml, pspec, value, &gvalue)) {
00421 g_object_set_property(G_OBJECT(w), name, &gvalue);
00422 g_value_unset(&gvalue);
00423 }
00424 }
00425 }
00426
00427
00428
00429
00430 return w;
00431 }
00432
00433 static void
00434 notebook_build_children(GladeXML *self, GtkWidget *parent,
00435 GladeWidgetInfo *info)
00436 {
00437 unsigned int i, j, tab = 0;
00438 enum {
00439 PANE_ITEM,
00440 TAB_ITEM,
00441 MENU_ITEM
00442 } type;
00443
00444 g_object_ref(G_OBJECT(parent));
00445 for (i = 0; i < info->n_children; i++) {
00446 GladeWidgetInfo *childinfo = info->children[i].child;
00447 GtkWidget *child = glade_xml_build_widget(self, childinfo);
00448
00449 type = PANE_ITEM;
00450 for (j = 0; j < info->children[i].n_properties; j++) {
00451 if (!strcmp (info->children[i].properties[j].name, "type")) {
00452 const char *value = info->children[i].properties[j].value;
00453
00454 if (!strcmp (value, "tab"))
00455 type = TAB_ITEM;
00456 break;
00457 }
00458 }
00459
00460 if (type == TAB_ITEM) {
00461 GtkWidget *body;
00462
00463 body = gtk_notebook_get_nth_page (GTK_NOTEBOOK (parent), (tab - 1));
00464 gtk_notebook_set_tab_label (GTK_NOTEBOOK (parent), body, child);
00465 } else {
00466 gtk_notebook_append_page (GTK_NOTEBOOK (parent), child, NULL);
00467 tab++;
00468 }
00469 }
00470 g_object_unref(G_OBJECT(parent));
00471 }
00472
00473
00474 #endif