Commit b349e0c4ee3b86ceac899a0c0734bd30d2a15de3

Authored by Perry Werneck
1 parent 68f3236d
Exists in master and in 1 other branch develop

Reimplementing load of queue from xml file.

src/include/v3270/filetransfer.h
... ... @@ -116,6 +116,8 @@
116 116  
117 117 LIB3270_EXPORT GObject * v3270_ft_activity_new();
118 118  
  119 + LIB3270_EXPORT void v3270_ft_activity_set_from_context(GObject * activity, GMarkupParseContext * context);
  120 +
119 121 LIB3270_EXPORT const gchar * v3270_ft_activity_get_local_filename(GObject *object);
120 122 LIB3270_EXPORT const gchar * v3270_ft_activity_get_remote_filename(GObject *object);
121 123 LIB3270_EXPORT LIB3270_FT_OPTION v3270_ft_activity_get_options(GObject *object);
... ...
src/v3270ft/activity.c
... ... @@ -192,3 +192,78 @@
192 192 G_V3270_FT_ACTIVITY(object)->values[id] = value;
193 193 }
194 194  
  195 + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, V3270FTActivity *activity, GError **error)
  196 + {
  197 + if(!g_ascii_strcasecmp(element_name,"file"))
  198 + {
  199 + const gchar *type;
  200 + const gchar *path;
  201 +
  202 + if(!g_markup_collect_attributes(
  203 + element_name,names,values,error,
  204 + G_MARKUP_COLLECT_STRING, "type", &type,
  205 + G_MARKUP_COLLECT_STRING, "path", &path,
  206 + G_MARKUP_COLLECT_INVALID
  207 + )) {
  208 +
  209 + return;
  210 +
  211 + }
  212 +
  213 + if(g_ascii_strcasecmp(type,"local") == 0)
  214 + v3270_ft_activity_set_local_filename(G_OBJECT(activity),path);
  215 + else if(g_ascii_strcasecmp(type,"remote") == 0)
  216 + v3270_ft_activity_set_remote_filename(G_OBJECT(activity),path);
  217 +
  218 + }
  219 + else if(!g_ascii_strcasecmp(element_name,"option"))
  220 + {
  221 + const gchar *name;
  222 + const gchar *value;
  223 +
  224 + if(!g_markup_collect_attributes(
  225 + element_name,names,values,error,
  226 + G_MARKUP_COLLECT_STRING, "name", &name,
  227 + G_MARKUP_COLLECT_STRING, "value", &value,
  228 + G_MARKUP_COLLECT_INVALID
  229 + )) {
  230 +
  231 + return;
  232 +
  233 + }
  234 +
  235 +
  236 + }
  237 + else if(!g_ascii_strcasecmp(element_name,"parameter"))
  238 + {
  239 + const gchar *name;
  240 + const gchar *value;
  241 +
  242 + if(!g_markup_collect_attributes(
  243 + element_name,names,values,error,
  244 + G_MARKUP_COLLECT_STRING, "name", &name,
  245 + G_MARKUP_COLLECT_STRING, "value", &value,
  246 + G_MARKUP_COLLECT_INVALID
  247 + )) {
  248 +
  249 + return;
  250 +
  251 + }
  252 +
  253 + }
  254 +
  255 + }
  256 +
  257 + void v3270_ft_activity_set_from_context(GObject * activity, GMarkupParseContext * context)
  258 + {
  259 + static const GMarkupParser parser = {
  260 + (void (*)(GMarkupParseContext *, const gchar *, const gchar **, const gchar **, gpointer, GError **)) element_start,
  261 + (void (*)(GMarkupParseContext *, const gchar *, gpointer, GError **)) NULL,
  262 + (void (*)(GMarkupParseContext *, const gchar *, gsize, gpointer, GError **)) NULL,
  263 + (void (*)(GMarkupParseContext *, const gchar *, gsize, gpointer, GError **)) NULL,
  264 + (void (*)(GMarkupParseContext *, GError *, gpointer)) NULL
  265 + };
  266 +
  267 + g_markup_parse_context_push(context,&parser,activity);
  268 +
  269 + }
... ...
src/v3270ft/activitylist.c
... ... @@ -63,32 +63,6 @@
63 63  
64 64 /*--[ Implement ]------------------------------------------------------------------------------------*/
65 65  
66   - static const struct _option_list
67   - {
68   - LIB3270_FT_OPTION option;
69   - const gchar * name;
70   - const gchar * value;
71   - }
72   - option_list[] =
73   - {
74   -
75   - { LIB3270_FT_OPTION_SEND, "type", "send", },
76   - { LIB3270_FT_OPTION_RECEIVE, "type", "receive", },
77   - { LIB3270_FT_OPTION_ASCII, "format", "ascii", },
78   - { LIB3270_FT_OPTION_CRLF, "format", "crlf", },
79   - { LIB3270_FT_OPTION_APPEND, "format", "append", },
80   - { LIB3270_FT_OPTION_REMAP, "format", "remap", },
81   - { LIB3270_FT_OPTION_UNIX, "file-format", "unix", },
82   - { LIB3270_FT_RECORD_FORMAT_DEFAULT, "record-format", "default", },
83   - { LIB3270_FT_RECORD_FORMAT_FIXED, "record-format", "fixed", },
84   - { LIB3270_FT_RECORD_FORMAT_VARIABLE, "record-format", "variable", },
85   - { LIB3270_FT_RECORD_FORMAT_UNDEFINED, "record-format", "undefined", },
86   - { LIB3270_FT_ALLOCATION_UNITS_DEFAULT, "units", "default", },
87   - { LIB3270_FT_ALLOCATION_UNITS_TRACKS, "units", "tracks", },
88   - { LIB3270_FT_ALLOCATION_UNITS_CYLINDERS, "units", "cylinders", },
89   - { LIB3270_FT_ALLOCATION_UNITS_AVBLOCK, "units", "avblock", },
90   - };
91   -
92 66 static void dispose(GObject *object)
93 67 {
94 68 debug("%s",__FUNCTION__);
... ... @@ -183,6 +157,59 @@
183 157 gtk_list_store_set((GtkListStore *) model, &iter, 0, activity, -1);
184 158 }
185 159  
  160 + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, V3270FTActivityList *widget, GError **error)
  161 + {
  162 + if(!g_ascii_strcasecmp(element_name,"entry"))
  163 + {
  164 + // Create new activity
  165 + GObject * activity = v3270_ft_activity_new();
  166 + v3270_ft_activity_set_from_context(activity,context);
  167 + v3270_activity_list_append(GTK_WIDGET(widget), activity);
  168 + }
  169 +
  170 + }
  171 +
  172 + static void element_end(GMarkupParseContext *context, const gchar *element_name, G_GNUC_UNUSED void *info,G_GNUC_UNUSED GError **error)
  173 + {
  174 + if(!g_ascii_strcasecmp(element_name,"entry"))
  175 + {
  176 + g_markup_parse_context_pop(context);
  177 + }
  178 + }
  179 +
  180 + static void reload(GtkWidget *widget)
  181 + {
  182 + static const GMarkupParser parser = {
  183 + (void (*)(GMarkupParseContext *, const gchar *, const gchar **, const gchar **, gpointer, GError **)) element_start,
  184 + (void (*)(GMarkupParseContext *, const gchar *, gpointer, GError **)) element_end,
  185 + (void (*)(GMarkupParseContext *, const gchar *, gsize, gpointer, GError **)) NULL,
  186 + (void (*)(GMarkupParseContext *, const gchar *, gsize, gpointer, GError **)) NULL,
  187 + (void (*)(GMarkupParseContext *, GError *, gpointer)) NULL
  188 + };
  189 +
  190 + GError * error = NULL;
  191 + g_autofree gchar * text = NULL;
  192 +
  193 + if(g_file_get_contents(GTK_V3270_FT_ACTIVITY_LIST(widget)->filename,&text,NULL,&error)) {
  194 +
  195 + GMarkupParseContext * context =
  196 + g_markup_parse_context_new(
  197 + &parser,
  198 + G_MARKUP_TREAT_CDATA_AS_TEXT|G_MARKUP_PREFIX_ERROR_POSITION,
  199 + widget,
  200 + NULL
  201 + );
  202 +
  203 + /*
  204 + GMarkupParseContext * context = g_markup_parse_context_new(&parser,G_MARKUP_TREAT_CDATA_AS_TEXT|G_MARKUP_PREFIX_ERROR_POSITION,GTK_V3270FT(widget),NULL);
  205 + g_markup_parse_context_parse(context,text,strlen(text),&error);
  206 + g_markup_parse_context_free(context);
  207 + */
  208 +
  209 + }
  210 +
  211 + }
  212 +
186 213 void v3270_activity_list_load(GtkWidget *widget)
187 214 {
188 215 V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget);
... ... @@ -200,8 +227,11 @@
200 227 list->filename = filename;
201 228 }
202 229  
  230 + reload(widget);
  231 +
203 232 g_signal_emit(widget, v3270_activity_list_signals[V3270_ACTIVITY_LIST_HAS_FILE_SIGNAL], 0, (list->filename == NULL ? FALSE : TRUE));
204 233  
  234 +
205 235 }
206 236  
207 237 void v3270_activity_list_save(GtkWidget *widget)
... ... @@ -232,10 +262,10 @@
232 262 g_string_append_printf(str,"\t\t<file type=\'remote\' path=\'%s\' />\n",v3270_ft_activity_get_remote_filename(activity));
233 263  
234 264 LIB3270_FT_OPTION options = v3270_ft_activity_get_options(activity);
235   - for(ix = 0; ix < G_N_ELEMENTS(option_list);ix++)
  265 + for(ix = 0; ix < v3270_activity_list_options[ix].name;ix++)
236 266 {
237   - if(options & option_list[ix].option)
238   - g_string_append_printf(str,"\t\t<option name=\'%s\' value=\'%s\' />\n",option_list[ix].name,option_list[ix].value);
  267 + if(options & v3270_activity_list_options[ix].option)
  268 + g_string_append_printf(str,"\t\t<option name=\'%s\' value=\'%s\' />\n",v3270_activity_list_options[ix].name,v3270_activity_list_options[ix].value);
239 269 }
240 270  
241 271 for(ix=0;ix<LIB3270_FT_VALUE_COUNT;ix++) {
... ...
src/v3270ft/private.h
... ... @@ -97,9 +97,17 @@
97 97  
98 98 };
99 99  
100   - extern const struct v3270ft_option ft_option[];
101   - extern const struct v3270ft_type ft_type[];
102   - extern const struct v3270ft_value ft_value[];
  100 + struct v3270_activity_list_option
  101 + {
  102 + LIB3270_FT_OPTION option;
  103 + const gchar * name;
  104 + const gchar * value;
  105 + };
  106 +
  107 + G_GNUC_INTERNAL extern const struct v3270ft_option ft_option[];
  108 + G_GNUC_INTERNAL extern const struct v3270ft_type ft_type[];
  109 + G_GNUC_INTERNAL extern const struct v3270ft_value ft_value[];
  110 + G_GNUC_INTERNAL extern const struct v3270_activity_list_option v3270_activity_list_options[];
103 111  
104 112 #define ENTRY_FILENAME_LENGTH FILENAME_MAX
105 113 struct v3270ft_entry {
... ...
src/v3270ft/tables.c
... ... @@ -197,3 +197,24 @@ const struct v3270ft_value ft_value[] = {
197 197  
198 198 };
199 199  
  200 +const struct v3270_activity_list_option v3270_activity_list_options[] =
  201 +{
  202 +
  203 + { LIB3270_FT_OPTION_SEND, "type", "send" },
  204 + { LIB3270_FT_OPTION_RECEIVE, "type", "receive" },
  205 + { LIB3270_FT_OPTION_ASCII, "format", "ascii" },
  206 + { LIB3270_FT_OPTION_CRLF, "format", "crlf" },
  207 + { LIB3270_FT_OPTION_APPEND, "format", "append" },
  208 + { LIB3270_FT_OPTION_REMAP, "format", "remap" },
  209 + { LIB3270_FT_OPTION_UNIX, "file-format", "unix" },
  210 + { LIB3270_FT_RECORD_FORMAT_DEFAULT, "record-format", "default" },
  211 + { LIB3270_FT_RECORD_FORMAT_FIXED, "record-format", "fixed" },
  212 + { LIB3270_FT_RECORD_FORMAT_VARIABLE, "record-format", "variable" },
  213 + { LIB3270_FT_RECORD_FORMAT_UNDEFINED, "record-format", "undefined" },
  214 + { LIB3270_FT_ALLOCATION_UNITS_DEFAULT, "units", "default" },
  215 + { LIB3270_FT_ALLOCATION_UNITS_TRACKS, "units", "tracks" },
  216 + { LIB3270_FT_ALLOCATION_UNITS_CYLINDERS, "units", "cylinders" },
  217 + { LIB3270_FT_ALLOCATION_UNITS_AVBLOCK, "units", "avblock" },
  218 + { 0, NULL, NULL }
  219 +};
  220 +
... ...