Commit 21efd2da3d95d5b25990e96ae250784b530fa5b6
1 parent
1bd9a779
Exists in
master
and in
1 other branch
Working on new FT dialog.
Showing
4 changed files
with
160 additions
and
32 deletions
Show diff stats
src/include/internals.h
| @@ -83,6 +83,8 @@ | @@ -83,6 +83,8 @@ | ||
| 83 | G_GNUC_INTERNAL GtkWidget * v3270_activity_list_new(); | 83 | G_GNUC_INTERNAL GtkWidget * v3270_activity_list_new(); |
| 84 | G_GNUC_INTERNAL void v3270_activity_list_append(GtkWidget *widget, GObject *activity); | 84 | G_GNUC_INTERNAL void v3270_activity_list_append(GtkWidget *widget, GObject *activity); |
| 85 | G_GNUC_INTERNAL void v3270_activity_list_load(GtkWidget *widget); | 85 | G_GNUC_INTERNAL void v3270_activity_list_load(GtkWidget *widget); |
| 86 | + G_GNUC_INTERNAL void v3270_activity_list_save(GtkWidget *widget); | ||
| 87 | + G_GNUC_INTERNAL void v3270_activity_list_save_as(GtkWidget *widget); | ||
| 86 | 88 | ||
| 87 | G_END_DECLS | 89 | G_END_DECLS |
| 88 | 90 |
src/v3270ft/activitylist.c
| @@ -55,7 +55,6 @@ | @@ -55,7 +55,6 @@ | ||
| 55 | { | 55 | { |
| 56 | GtkTreeView parent; | 56 | GtkTreeView parent; |
| 57 | gchar * filename; | 57 | gchar * filename; |
| 58 | - | ||
| 59 | }; | 58 | }; |
| 60 | 59 | ||
| 61 | G_DEFINE_TYPE(V3270FTActivityList, V3270FTActivityList, GTK_TYPE_TREE_VIEW); | 60 | G_DEFINE_TYPE(V3270FTActivityList, V3270FTActivityList, GTK_TYPE_TREE_VIEW); |
| @@ -64,13 +63,41 @@ | @@ -64,13 +63,41 @@ | ||
| 64 | 63 | ||
| 65 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 64 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 66 | 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 | + | ||
| 67 | static void dispose(GObject *object) | 92 | static void dispose(GObject *object) |
| 68 | { | 93 | { |
| 69 | debug("%s",__FUNCTION__); | 94 | debug("%s",__FUNCTION__); |
| 70 | 95 | ||
| 71 | V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(object); | 96 | V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(object); |
| 72 | 97 | ||
| 98 | + debug("Freeing %s",list->filename); | ||
| 73 | g_free(list->filename); | 99 | g_free(list->filename); |
| 100 | + list->filename = NULL; | ||
| 74 | 101 | ||
| 75 | } | 102 | } |
| 76 | 103 | ||
| @@ -148,11 +175,6 @@ | @@ -148,11 +175,6 @@ | ||
| 148 | return g_object_new(GTK_TYPE_V3270_FT_ACTIVITY_LIST, NULL); | 175 | return g_object_new(GTK_TYPE_V3270_FT_ACTIVITY_LIST, NULL); |
| 149 | } | 176 | } |
| 150 | 177 | ||
| 151 | - void v3270_activity_list_load(GtkWidget *widget) | ||
| 152 | - { | ||
| 153 | - | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | void v3270_activity_list_append(GtkWidget *widget, GObject *activity) | 178 | void v3270_activity_list_append(GtkWidget *widget, GObject *activity) |
| 157 | { | 179 | { |
| 158 | GtkTreeModel * model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | 180 | GtkTreeModel * model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); |
| @@ -161,3 +183,109 @@ | @@ -161,3 +183,109 @@ | ||
| 161 | gtk_list_store_set((GtkListStore *) model, &iter, 0, activity, -1); | 183 | gtk_list_store_set((GtkListStore *) model, &iter, 0, activity, -1); |
| 162 | } | 184 | } |
| 163 | 185 | ||
| 186 | + void v3270_activity_list_load(GtkWidget *widget) | ||
| 187 | + { | ||
| 188 | + V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget); | ||
| 189 | + | ||
| 190 | + gchar * filename = v3270ft_select_file( | ||
| 191 | + widget, | ||
| 192 | + _("Load queue from file"), | ||
| 193 | + _("Load"), GTK_FILE_CHOOSER_ACTION_OPEN, | ||
| 194 | + "", | ||
| 195 | + N_("XML file"), "*.xml", | ||
| 196 | + NULL ); | ||
| 197 | + | ||
| 198 | + if(filename) { | ||
| 199 | + g_free(list->filename); | ||
| 200 | + list->filename = filename; | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + void v3270_activity_list_save(GtkWidget *widget) | ||
| 206 | + { | ||
| 207 | + V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget); | ||
| 208 | + GString * str = g_string_new("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<filelist>\n"); | ||
| 209 | + GError * error = NULL; | ||
| 210 | + size_t ix; | ||
| 211 | + | ||
| 212 | + // Serialize activities. | ||
| 213 | + GtkTreeIter iter; | ||
| 214 | + GtkTreeModel * model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | ||
| 215 | + | ||
| 216 | + if(gtk_tree_model_get_iter_first(model,&iter)) | ||
| 217 | + { | ||
| 218 | + do | ||
| 219 | + { | ||
| 220 | + GObject * activity = NULL; | ||
| 221 | + gtk_tree_model_get(model, &iter, 0, &activity, -1); | ||
| 222 | + | ||
| 223 | + if(activity) | ||
| 224 | + { | ||
| 225 | + g_string_append(str,"\t<entry>\n"); | ||
| 226 | + | ||
| 227 | + g_string_append_printf(str,"\t\t<file type=\'local\' path=\'%s\' />\n",v3270_ft_activity_get_local_filename(activity)); | ||
| 228 | + g_string_append_printf(str,"\t\t<file type=\'remote\' path=\'%s\' />\n",v3270_ft_activity_get_remote_filename(activity)); | ||
| 229 | + | ||
| 230 | + LIB3270_FT_OPTION options = v3270_ft_activity_get_options(activity); | ||
| 231 | + for(ix = 0; ix < G_N_ELEMENTS(option_list);ix++) | ||
| 232 | + { | ||
| 233 | + if(options & option_list[ix].option) | ||
| 234 | + g_string_append_printf(str,"\t\t<option name=\'%s\' value=\'%s\' />\n",option_list[ix].name,option_list[ix].value); | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + g_string_append(str,"\t</entry>\n"); | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + } | ||
| 241 | + while(gtk_tree_model_iter_next(model,&iter)); | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + g_string_append(str,"</filelist>\n"); | ||
| 245 | + | ||
| 246 | + | ||
| 247 | + // Save activity list | ||
| 248 | + g_autofree gchar * text = g_string_free(str,FALSE); | ||
| 249 | + | ||
| 250 | + if(!g_file_set_contents(list->filename,text,-1,&error)) { | ||
| 251 | + | ||
| 252 | + GtkWidget *popup = gtk_message_dialog_new_with_markup( | ||
| 253 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | ||
| 254 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | ||
| 255 | + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, | ||
| 256 | + _("Can't save %s"),list->filename | ||
| 257 | + ); | ||
| 258 | + | ||
| 259 | + gtk_window_set_title(GTK_WINDOW(popup),_("Operation has failed")); | ||
| 260 | + | ||
| 261 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",error->message); | ||
| 262 | + g_error_free(error); | ||
| 263 | + | ||
| 264 | + gtk_dialog_run(GTK_DIALOG(popup)); | ||
| 265 | + gtk_widget_destroy(popup); | ||
| 266 | + | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + void v3270_activity_list_save_as(GtkWidget *widget) | ||
| 273 | + { | ||
| 274 | + V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget); | ||
| 275 | + | ||
| 276 | + gchar * filename = v3270ft_select_file( | ||
| 277 | + widget, | ||
| 278 | + _("Save queue to file"), | ||
| 279 | + _("Save"), | ||
| 280 | + GTK_FILE_CHOOSER_ACTION_SAVE, | ||
| 281 | + "", | ||
| 282 | + N_("XML file"), "*.xml", | ||
| 283 | + NULL ); | ||
| 284 | + | ||
| 285 | + if(filename) { | ||
| 286 | + g_free(list->filename); | ||
| 287 | + list->filename = filename; | ||
| 288 | + v3270_activity_list_save(widget); | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + |
src/v3270ft/dialog.c
| @@ -68,30 +68,6 @@ static void V3270FTDialog_class_init(G_GNUC_UNUSED V3270FTDialogClass *klass) | @@ -68,30 +68,6 @@ static void V3270FTDialog_class_init(G_GNUC_UNUSED V3270FTDialogClass *klass) | ||
| 68 | { | 68 | { |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | -/* | ||
| 72 | -static void apply_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *dialog) | ||
| 73 | -{ | ||
| 74 | - gtk_dialog_response(GTK_DIALOG(dialog),GTK_RESPONSE_APPLY); | ||
| 75 | -} | ||
| 76 | - | ||
| 77 | -static void cancel_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *dialog) | ||
| 78 | -{ | ||
| 79 | - gtk_dialog_response(GTK_DIALOG(dialog),GTK_RESPONSE_CANCEL); | ||
| 80 | -} | ||
| 81 | -*/ | ||
| 82 | - | ||
| 83 | -/* | ||
| 84 | -static GtkWidget * create_button(V3270FTDialog *widget, FT_BUTTON id, const gchar *icon, const gchar *tooltip, GCallback callback) | ||
| 85 | -{ | ||
| 86 | - widget->buttons[id] = gtk_button_new_from_icon_name(icon,GTK_ICON_SIZE_BUTTON); | ||
| 87 | - gtk_widget_set_tooltip_markup(widget->buttons[id],tooltip); | ||
| 88 | - | ||
| 89 | - // g_signal_connect(widget->buttons[id],"clicked",callback,widget); | ||
| 90 | - | ||
| 91 | - return widget->buttons[id]; | ||
| 92 | -} | ||
| 93 | -*/ | ||
| 94 | - | ||
| 95 | void activity_selected(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn G_GNUC_UNUSED(*column), V3270FTDialog *widget) | 71 | void activity_selected(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn G_GNUC_UNUSED(*column), V3270FTDialog *widget) |
| 96 | { | 72 | { |
| 97 | GtkTreeIter iter; | 73 | GtkTreeIter iter; |
| @@ -127,6 +103,21 @@ static void update_clicked(GtkButton G_GNUC_UNUSED(*button), V3270FTDialog *widg | @@ -127,6 +103,21 @@ static void update_clicked(GtkButton G_GNUC_UNUSED(*button), V3270FTDialog *widg | ||
| 127 | gtk_tree_view_columns_autosize(GTK_TREE_VIEW(widget->queue.view)); | 103 | gtk_tree_view_columns_autosize(GTK_TREE_VIEW(widget->queue.view)); |
| 128 | } | 104 | } |
| 129 | 105 | ||
| 106 | +static void load_queue_clicked(GtkButton G_GNUC_UNUSED(*button), V3270FTDialog *widget) | ||
| 107 | +{ | ||
| 108 | + v3270_activity_list_load(widget->queue.view); | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +static void save_queue_clicked(GtkButton G_GNUC_UNUSED(*button), V3270FTDialog *widget) | ||
| 112 | +{ | ||
| 113 | + v3270_activity_list_save(widget->queue.view); | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +static void save_queue_as_clicked(GtkButton G_GNUC_UNUSED(*button), V3270FTDialog *widget) | ||
| 117 | +{ | ||
| 118 | + v3270_activity_list_save_as(widget->queue.view); | ||
| 119 | +} | ||
| 120 | + | ||
| 130 | static void insert_clicked(GtkWidget *button, V3270FTDialog *widget) | 121 | static void insert_clicked(GtkWidget *button, V3270FTDialog *widget) |
| 131 | { | 122 | { |
| 132 | GtkTreeIter iter; | 123 | GtkTreeIter iter; |
| @@ -254,13 +245,16 @@ static void V3270FTDialog_init(V3270FTDialog *widget) | @@ -254,13 +245,16 @@ static void V3270FTDialog_init(V3270FTDialog *widget) | ||
| 254 | // https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html | 245 | // https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html |
| 255 | widget->queue.load = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_SMALL_TOOLBAR); | 246 | widget->queue.load = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_SMALL_TOOLBAR); |
| 256 | gtk_widget_set_tooltip_markup(widget->queue.load,_("Get transfer queue from file")); | 247 | gtk_widget_set_tooltip_markup(widget->queue.load,_("Get transfer queue from file")); |
| 248 | + g_signal_connect(widget->queue.load,"clicked",G_CALLBACK(load_queue_clicked),widget); | ||
| 257 | 249 | ||
| 258 | widget->queue.save = gtk_button_new_from_icon_name("document-save",GTK_ICON_SIZE_SMALL_TOOLBAR); | 250 | widget->queue.save = gtk_button_new_from_icon_name("document-save",GTK_ICON_SIZE_SMALL_TOOLBAR); |
| 259 | gtk_widget_set_tooltip_markup(widget->queue.save,_("Save transfer queue")); | 251 | gtk_widget_set_tooltip_markup(widget->queue.save,_("Save transfer queue")); |
| 252 | + g_signal_connect(widget->queue.load,"clicked",G_CALLBACK(save_queue_clicked),widget); | ||
| 260 | gtk_widget_set_sensitive(widget->queue.save,FALSE); | 253 | gtk_widget_set_sensitive(widget->queue.save,FALSE); |
| 261 | 254 | ||
| 262 | widget->queue.saveAs = gtk_button_new_from_icon_name("document-save-as",GTK_ICON_SIZE_SMALL_TOOLBAR); | 255 | widget->queue.saveAs = gtk_button_new_from_icon_name("document-save-as",GTK_ICON_SIZE_SMALL_TOOLBAR); |
| 263 | gtk_widget_set_tooltip_markup(widget->queue.saveAs,_("Save transfer queue to file")); | 256 | gtk_widget_set_tooltip_markup(widget->queue.saveAs,_("Save transfer queue to file")); |
| 257 | + g_signal_connect(widget->queue.saveAs,"clicked",G_CALLBACK(save_queue_as_clicked),widget); | ||
| 264 | 258 | ||
| 265 | if(header) | 259 | if(header) |
| 266 | { | 260 | { |
src/v3270ft/select.c
| @@ -77,12 +77,14 @@ gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar * | @@ -77,12 +77,14 @@ gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar * | ||
| 77 | 77 | ||
| 78 | gchar *rc = NULL; | 78 | gchar *rc = NULL; |
| 79 | 79 | ||
| 80 | + debug("%s",__FUNCTION__); | ||
| 81 | + | ||
| 80 | #if GTK_CHECK_VERSION(3,20,0) | 82 | #if GTK_CHECK_VERSION(3,20,0) |
| 81 | 83 | ||
| 82 | GtkFileChooserNative *native = gtk_file_chooser_native_new | 84 | GtkFileChooserNative *native = gtk_file_chooser_native_new |
| 83 | ( | 85 | ( |
| 84 | title, | 86 | title, |
| 85 | - GTK_WINDOW(dialog), | 87 | + GTK_WINDOW(gtk_widget_get_toplevel(dialog)), |
| 86 | action, | 88 | action, |
| 87 | button, | 89 | button, |
| 88 | _( "_Cancel" ) | 90 | _( "_Cancel" ) |
| @@ -173,7 +175,7 @@ gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar * | @@ -173,7 +175,7 @@ gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar * | ||
| 173 | GtkWidget * chooser = gtk_file_chooser_dialog_new | 175 | GtkWidget * chooser = gtk_file_chooser_dialog_new |
| 174 | ( | 176 | ( |
| 175 | title, | 177 | title, |
| 176 | - GTK_WINDOW(dialog), | 178 | + GTK_WINDOW(gtk_widget_get_toplevel(dialog)), |
| 177 | action, | 179 | action, |
| 178 | _("_Cancel" ), GTK_RESPONSE_CANCEL, | 180 | _("_Cancel" ), GTK_RESPONSE_CANCEL, |
| 179 | button, GTK_RESPONSE_ACCEPT, | 181 | button, GTK_RESPONSE_ACCEPT, |
| @@ -192,6 +194,8 @@ gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar * | @@ -192,6 +194,8 @@ gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar * | ||
| 192 | 194 | ||
| 193 | #endif // WIN32 | 195 | #endif // WIN32 |
| 194 | 196 | ||
| 197 | + debug("%s=%p",__FUNCTION__,rc); | ||
| 198 | + | ||
| 195 | return rc; | 199 | return rc; |
| 196 | 200 | ||
| 197 | } | 201 | } |