00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00030 #include <stdlib.h>
00031 #include "parse-gtk.h"
00032 #include "duifield-gtk.h"
00033 #include "duitop-gtk.h"
00034 #include "duifield.h"
00035 #include "interface.h"
00036 #include "signal.h"
00037 #include "window.h"
00038 #include "perr.h"
00039
00040 #include "parse-utils.h"
00041 #include "readfile.h"
00042
00043
00044
00045
00046 struct DwiGtkParseCtxt_s
00047 {
00048 DuiParser *parser;
00049
00050 DuiGtkTop *top;
00051
00053 DuiWindow *window;
00054
00056 DuiAction *action;
00057 };
00058
00059
00060
00061 static void
00062 window_start (gpointer self, const gchar **attrs)
00063 {
00064 static const gchar * eltname = "<window>";
00065 DwiGtkParseCtxt *ctx = self;
00066 DuiParser *par = ctx->parser;
00067
00068 gint i;
00069 const gchar * provider = NULL;
00070 const gchar * winname = NULL;
00071 const gchar * filepath = NULL;
00072 const gchar * root_widget = NULL;
00073 const gchar * mainattr = NULL;
00074 gint is_main = 0;
00075
00076 GENERIC_CHECKS ;
00077
00078 i = 0;
00079 while (attrs[i])
00080 {
00081 CASE ("provider", provider)
00082 CASE ("name", winname)
00083 CASE ("filename", filepath)
00084 CASE ("root_widget", root_widget)
00085 CASE ("main", mainattr)
00086 CASE_UNKNOWN ;
00087 i += 2;
00088 }
00089
00090 if (!winname)
00091 {
00092 REQUIRE (filepath, "a file path!");
00093 REQUIRE (root_widget, "a root widget!");
00094 }
00095
00096
00097
00098 if (winname)
00099 {
00100 ctx->window = dui_gtk_top_find_window_by_name (ctx->top, winname);
00101 }
00102 if (NULL == ctx->window)
00103 {
00104 gchar * glade_path;
00105 REQUIRE (filepath, "a file path!");
00106 REQUIRE (root_widget, "a root widget!");
00107
00108 if (mainattr && !strcasecmp (mainattr, "yes")) is_main = 1;
00109 glade_path = g_strconcat (estron_parser_get_fileparent (par),
00110 "/", filepath, NULL);
00111 PINFO ("glade path=%s", glade_path);
00112 ctx->window = dui_window_new (winname, ctx->top);
00113 dui_window_set_glade (ctx->window, glade_path, root_widget, is_main);
00114 g_free (glade_path);
00115 }
00116 }
00117
00118 static void
00119 window_end (gpointer self)
00120 {
00121 DwiGtkParseCtxt *ctx = self;
00122 ctx->window = NULL;
00123 }
00124
00125 static DuiParserElementPlugin *
00126 dwi_window_parser_plugin (DwiGtkParseCtxt *ctx)
00127 {
00128 DuiParserElementPlugin *plg = g_new0 (DuiParserElementPlugin, 1);
00129
00130 plg->eltname = "window";
00131 plg->start_handler = window_start;
00132 plg->end_handler = window_end;
00133 plg->user_data = ctx;
00134
00135 return plg;
00136 }
00137
00138
00139
00140 static void
00141 sigaction_start (gpointer self, const gchar **attrs)
00142 {
00143 static const gchar * eltname = "<sigaction>";
00144 DwiGtkParseCtxt *ctx = self;
00145 DuiParser *par = ctx->parser;
00146 gint i;
00147 const gchar * widgetname = NULL;
00148 const gchar * signalname = NULL;
00149 const gchar * sigaction = NULL;
00150
00151 GENERIC_CHECKS;
00152 CHECK_NEST (ctx->window, "<window>");
00153
00154 i = 0;
00155 while (attrs[i])
00156 {
00157 CASE ("widget", widgetname)
00158 CASE ("signal", signalname)
00159 CASE ("action", sigaction)
00160 CASE_UNKNOWN;
00161 i += 2;
00162 }
00163
00164 REQUIRE (widgetname, "a widget!");
00165 REQUIRE (signalname, "a valid signal name on the widget!");
00166 REQUIRE (sigaction, "an action to perform!");
00167
00168 DuiSignal *sig = dui_signal_new (widgetname, signalname, sigaction);
00169 dui_window_add_signal (ctx->window, sig, NULL);
00170 }
00171
00172 static DuiParserElementPlugin *
00173 dwi_sigaction_parser_plugin (DwiGtkParseCtxt *ctx)
00174 {
00175 DuiParserElementPlugin *plg = g_new0 (DuiParserElementPlugin, 1);
00176
00177 plg->eltname = "sigaction";
00178 plg->start_handler = sigaction_start;
00179 plg->end_handler = NULL;
00180 plg->user_data = ctx;
00181
00182 return plg;
00183 }
00184
00185
00186
00187 static void
00188 submit_start (gpointer self, const gchar **attrs)
00189 {
00190 static const gchar * eltname = "<submit>";
00191 DwiGtkParseCtxt *ctx = self;
00192 DuiParser *par = ctx->parser;
00193 gint i;
00194 const gchar * widgetname = NULL;
00195 const gchar * signalname = NULL;
00196
00197 GENERIC_CHECKS ;
00198 CHECK_NEST (ctx->action, "<form>");
00199
00200 i = 0;
00201 while (attrs[i])
00202 {
00203 CASE ("widget", widgetname)
00204 CASE ("signal", signalname)
00205 CASE_UNKNOWN ;
00206 i += 2;
00207 }
00208
00209 REQUIRE (widgetname, "a widget!");
00210 REQUIRE (signalname, "a signal!");
00211
00212 DuiSignal *sig = dui_signal_new (widgetname, signalname, "submit_form");
00213
00214 dui_window_add_signal (ctx->window, sig, ctx->action);
00215 }
00216
00217 static DuiParserElementPlugin *
00218 dwi_submit_parser_plugin (DwiGtkParseCtxt *ctx)
00219 {
00220 DuiParserElementPlugin *plg = g_new0 (DuiParserElementPlugin, 1);
00221
00222 plg->eltname = "submit";
00223 plg->start_handler = submit_start;
00224 plg->end_handler = NULL;
00225 plg->user_data = ctx;
00226
00227 return plg;
00228 }
00229
00230
00231
00232
00233 static const gchar *
00234 gtk_row_handler (gpointer self, DuiFieldMap *fm, const gchar **attrs)
00235 {
00236 DwiGtkParseCtxt G_GNUC_UNUSED *ctx = self;
00237 const gchar * widgetname = NULL;
00238 const gchar * match_col = NULL;
00239 gint mcol = -1;
00240
00241 gint i=0;
00242 while (attrs[i])
00243 {
00244 CASE ("widget", widgetname)
00245 CASE ("match_column", match_col)
00246 {}
00247 i += 2;
00248 }
00249
00250 if (match_col) mcol = atoi (match_col);
00251
00252
00253 if (widgetname)
00254 {
00255 dui_field_set_wid_where (&fm->target, widgetname, mcol, "equal");
00256 }
00257 return widgetname;
00258 }
00259
00260 static DuiParserTablePlugin *
00261 gtk_parser_table_plugin (DwiGtkParseCtxt *ctx)
00262 {
00263 DuiParserTablePlugin *plg = g_new0 (DuiParserTablePlugin, 1);
00264
00265 plg->plugin_name = "gtk_parser";
00266 plg->handler = gtk_row_handler;
00267 plg->user_data = ctx;
00268
00269 return plg;
00270 }
00271
00272
00273
00274 static gboolean
00275 dwi_widget_field_handler (gpointer self, DuiField *fld,
00276 const gchar * row_context, const gchar **attrs)
00277 {
00278 DwiGtkParseCtxt G_GNUC_UNUSED *ctx = self;
00279 const gchar * widgetname = NULL;
00280 const gchar * column = NULL;
00281 gint colnum = -1;
00282
00283 gint i=0;
00284 while (attrs[i])
00285 {
00286 CASE ("widget", widgetname)
00287 CASE ("column", column)
00288 {}
00289 i += 2;
00290 }
00291 if (column) colnum = atoi (column);
00292
00293
00294
00295 if (widgetname)
00296 {
00297 dui_field_set_widget (fld, widgetname, colnum);
00298 return TRUE;
00299 }
00300 return FALSE;
00301 }
00302
00303 static DuiParserFieldPlugin *
00304 dwi_widget_parser_plugin (DwiGtkParseCtxt *ctx)
00305 {
00306 DuiParserFieldPlugin *plg = g_new0 (DuiParserFieldPlugin, 1);
00307
00308 plg->fieldname = "widget";
00309 plg->handler = dwi_widget_field_handler;
00310 plg->user_data = ctx;
00311
00312 return plg;
00313 }
00314
00315
00316
00317 static gboolean
00318 dwi_widdata_field_handler (gpointer self, DuiField *fld,
00319 const gchar * row_context, const gchar **attrs)
00320 {
00321 DwiGtkParseCtxt G_GNUC_UNUSED *ctx = self;
00322 const gchar * widgetname = NULL;
00323 const gchar * datakey = NULL;
00324 const gchar * column = NULL;
00325 gint colnum = -1;
00326
00327 gint i=0;
00328 while (attrs[i])
00329 {
00330 CASE ("widget", widgetname)
00331 CASE ("column", column)
00332 CASE ("data", datakey)
00333 {}
00334 i += 2;
00335 }
00336 if (column) colnum = atoi (column);
00337
00338
00339
00340
00341
00342 if (widgetname)
00343 {
00344 dui_field_set_wid_data (fld, widgetname, colnum, datakey);
00345 return TRUE;
00346 }
00347 return FALSE;
00348 }
00349
00350 static DuiParserFieldPlugin *
00351 dwi_widdata_parser_plugin (DwiGtkParseCtxt *ctx)
00352 {
00353 DuiParserFieldPlugin *plg = g_new0 (DuiParserFieldPlugin, 1);
00354
00355 plg->fieldname = "widget_data";
00356 plg->handler = dwi_widdata_field_handler;
00357 plg->user_data = ctx;
00358
00359 return plg;
00360 }
00361
00362
00363
00364 static gboolean
00365 dwi_widarg_field_handler (gpointer self, DuiField *fld,
00366 const gchar * row_context, const gchar **attrs)
00367 {
00368 DwiGtkParseCtxt G_GNUC_UNUSED *ctx = self;
00369 const gchar * widgetname = NULL;
00370 const gchar * argname = NULL;
00371 const gchar * column = NULL;
00372 gint colnum = -1;
00373
00374 gint i=0;
00375 while (attrs[i])
00376 {
00377 CASE ("widget", widgetname)
00378 CASE ("column", column)
00379 CASE ("arg", argname)
00380 {}
00381 i += 2;
00382 }
00383 if (column) colnum = atoi (column);
00384
00385
00386
00387
00388
00389 if (widgetname)
00390 {
00391 dui_field_set_wid_arg (fld, widgetname, colnum, argname);
00392 return TRUE;
00393 }
00394 return FALSE;
00395 }
00396
00397 static DuiParserFieldPlugin *
00398 dwi_widarg_parser_plugin (DwiGtkParseCtxt *ctx)
00399 {
00400 DuiParserFieldPlugin *plg = g_new0 (DuiParserFieldPlugin, 1);
00401
00402 plg->fieldname = "widget_arg";
00403 plg->handler = dwi_widarg_field_handler;
00404 plg->user_data = ctx;
00405
00406 return plg;
00407 }
00408
00409
00410
00411 static void
00412 add_action (gpointer self, DuiAction *act)
00413 {
00414 DwiGtkParseCtxt *ctx = self;
00415 dui_window_add_action (ctx->window, act);
00416 ctx->action = act;
00417 }
00418
00419 static void
00420 add_report (gpointer self, DuiReport *rpt)
00421 {
00422 DwiGtkParseCtxt *ctx = self;
00423 dui_window_add_report (ctx->window, rpt);
00424 }
00425
00426 static DuiParserStructPlugin *
00427 dwi_struct_plugin (DwiGtkParseCtxt *ctx)
00428 {
00429 DuiParserStructPlugin *plg = g_new0 (DuiParserStructPlugin, 1);
00430
00431 plg->action_created = add_action;
00432 plg->report_created = add_report;
00433 plg->user_data = ctx;
00434 return plg;
00435 }
00436
00437
00438
00439 DwiGtkParseCtxt *
00440 dwi_gtk_parser_new (DuiParser *par)
00441 {
00442 DuiParserElementPlugin *plg;
00443 DwiGtkParseCtxt *ctx = g_new0 (DwiGtkParseCtxt, 1);
00444
00445 ctx->top = dui_gtk_top_new();
00446 ctx->parser = par;
00447 ctx->window = NULL;
00448 ctx->action = NULL;
00449
00450
00451 DuiInterfacePlugin *dip = dui_gtk_top_plugin_new(ctx->top);
00452 DuiInterface *iface = dui_parser_get_interface (par);
00453 dui_interface_register_plugin (iface, dip);
00454
00455 plg = dwi_sigaction_parser_plugin(ctx);
00456 dui_parser_register_element_plugin (par, plg);
00457
00458 plg = dwi_submit_parser_plugin(ctx);
00459 dui_parser_register_element_plugin (par, plg);
00460
00463 plg = dwi_window_parser_plugin(ctx);
00464 dui_parser_register_element_plugin (par, plg);
00465
00466 DuiParserTablePlugin *tbl;
00467 tbl = gtk_parser_table_plugin (ctx);
00468 dui_parser_register_table_plugin (par, tbl);
00469
00470 DuiParserFieldPlugin *fp;
00471 fp = dwi_widget_parser_plugin (ctx);
00472 dui_parser_register_field_plugin (par, fp);
00473
00474 fp = dwi_widdata_parser_plugin (ctx);
00475 dui_parser_register_field_plugin (par, fp);
00476
00477 fp = dwi_widarg_parser_plugin (ctx);
00478 dui_parser_register_field_plugin (par, fp);
00479
00480 DuiParserStructPlugin *psp;
00481 psp = dwi_struct_plugin (ctx);
00482 dui_parser_register_struct_plugin (par, psp);
00483
00484 return ctx;
00485 }
00486
00487
00488