Commit 064bb96ecc94269f0540302f4c5d06d8e3e45034
1 parent
5454f9f5
Exists in
master
and in
1 other branch
Implementing drag&drop on the file settings widget.
Showing
5 changed files
with
83 additions
and
4 deletions
Show diff stats
src/filetransfer/private.h
... | ... | @@ -128,6 +128,7 @@ |
128 | 128 | G_GNUC_INTERNAL extern const struct v3270ft_value ft_value[]; |
129 | 129 | G_GNUC_INTERNAL extern const struct v3270_activity_list_option v3270_activity_list_options[]; |
130 | 130 | G_GNUC_INTERNAL extern const struct v3270_ft_worker_field v3270_ft_worker_fields[PROGRESS_FIELD_COUNT]; |
131 | + G_GNUC_INTERNAL extern const gchar * v3270_text_file_extensions[]; | |
131 | 132 | |
132 | 133 | #define ENTRY_FILENAME_LENGTH FILENAME_MAX |
133 | 134 | struct v3270ft_entry { | ... | ... |
src/filetransfer/settings.c
... | ... | @@ -352,7 +352,8 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP |
352 | 352 | set_valid(widget, VALIDITY_LOCAL_FILENAME); |
353 | 353 | } |
354 | 354 | |
355 | - static void remote_file_changed(GtkEntry *entry, V3270FTSettings *widget) { | |
355 | + static void remote_file_changed(GtkEntry *entry, V3270FTSettings *widget) | |
356 | + { | |
356 | 357 | |
357 | 358 | const gchar * text = gtk_entry_get_text(entry); |
358 | 359 | |
... | ... | @@ -366,6 +367,65 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP |
366 | 367 | |
367 | 368 | } |
368 | 369 | |
370 | + LIB3270_EXPORT gboolean v3270_ft_settings_set_from_filename(GtkWidget *widget, const gchar *filename) | |
371 | + { | |
372 | + g_return_val_if_fail(GTK_IS_V3270_FT_SETTINGS(widget) && g_file_test(filename,G_FILE_TEST_IS_REGULAR),FALSE); | |
373 | + | |
374 | + debug("%s(%s)",__FUNCTION__,filename); | |
375 | + | |
376 | + // Setup dialog from filename. | |
377 | + V3270FTSettings * settings = GTK_V3270_FT_SETTINGS(widget); | |
378 | + LIB3270_FT_OPTION options = LIB3270_FT_OPTION_SEND; | |
379 | + size_t ix; | |
380 | + | |
381 | + for(ix = 0; v3270_text_file_extensions[ix]; ix++) | |
382 | + { | |
383 | + if(g_str_has_suffix(filename,v3270_text_file_extensions[ix])) | |
384 | + { | |
385 | + options |= (LIB3270_FT_OPTION_ASCII|LIB3270_FT_OPTION_CRLF|LIB3270_FT_OPTION_REMAP); | |
386 | + break; | |
387 | + } | |
388 | + } | |
389 | + | |
390 | + | |
391 | + | |
392 | + gtk_entry_set_text(settings->file.local,filename); | |
393 | + | |
394 | + g_autofree gchar * basename = g_path_get_basename(filename); | |
395 | + gtk_entry_set_text(settings->file.remote,basename); | |
396 | + | |
397 | + v3270_ft_settings_set_options(widget,options); | |
398 | + | |
399 | + return TRUE; | |
400 | + } | |
401 | + | |
402 | + guint v3270_ft_settings_set_from_selection(GtkWidget *widget, GtkSelectionData *data) | |
403 | + { | |
404 | + gchar **uris = g_strsplit((const gchar *) gtk_selection_data_get_text(data),"\n",-1); | |
405 | + guint rc = 0; | |
406 | + size_t ix; | |
407 | + | |
408 | + for(ix = 0; uris[ix]; ix++) | |
409 | + { | |
410 | + if(!g_ascii_strncasecmp("file:///",uris[ix],8)) { | |
411 | + | |
412 | + if(v3270_ft_settings_set_from_filename(widget,uris[ix]+7)) | |
413 | + break; | |
414 | + | |
415 | + } | |
416 | + } | |
417 | + | |
418 | + g_strfreev(uris); | |
419 | + | |
420 | + return rc; | |
421 | +} | |
422 | + | |
423 | + static void drag_data_received(GtkWidget *widget, GdkDragContext *context, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, GtkSelectionData *data, G_GNUC_UNUSED guint info, guint time) | |
424 | + { | |
425 | + debug("%s",__FUNCTION__); | |
426 | + gtk_drag_finish(context, v3270_ft_settings_set_from_selection(widget, data) > 0, FALSE, time); | |
427 | + } | |
428 | + | |
369 | 429 | static void V3270FTSettings_init(V3270FTSettings *widget) |
370 | 430 | { |
371 | 431 | size_t ix; |
... | ... | @@ -537,6 +597,15 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP |
537 | 597 | gtk_widget_set_sensitive(GTK_WIDGET(widget->file.local),FALSE); |
538 | 598 | gtk_widget_set_sensitive(GTK_WIDGET(widget->file.remote),FALSE); |
539 | 599 | |
600 | + // Setup drag & drop | |
601 | + // http://ftp.math.utah.edu/u/ma/hohn/linux/gnome/developer.gnome.org/doc/tutorials/gnome-libs/x1003.html | |
602 | + static const GtkTargetEntry targets[] = { | |
603 | + { "text/plain", GTK_TARGET_OTHER_APP, 0 } | |
604 | + }; | |
605 | + | |
606 | + gtk_drag_dest_set(GTK_WIDGET(widget),GTK_DEST_DEFAULT_ALL,targets,G_N_ELEMENTS(targets),GDK_ACTION_COPY); | |
607 | + g_signal_connect(widget,"drag-data-received",G_CALLBACK(drag_data_received),widget); | |
608 | + | |
540 | 609 | } |
541 | 610 | |
542 | 611 | LIB3270_EXPORT GtkWidget * v3270_ft_settings_new() | ... | ... |
src/filetransfer/tables.c
... | ... | @@ -223,3 +223,12 @@ const struct v3270_ft_worker_field v3270_ft_worker_fields[PROGRESS_FIELD_COUNT] |
223 | 223 | { N_("Speed:"), N_("Transfer speed") }, |
224 | 224 | { N_("ETA:"), N_("Estimated transfer arrival") } |
225 | 225 | }; |
226 | + | |
227 | +const gchar * v3270_text_file_extensions[] = | |
228 | +{ | |
229 | + ".txt", | |
230 | + ".c", | |
231 | + ".h" | |
232 | + NULL | |
233 | +}; | |
234 | + | ... | ... |
src/include/v3270/filetransfer.h
... | ... | @@ -97,6 +97,8 @@ |
97 | 97 | LIB3270_EXPORT void v3270_ft_settings_set_activity(GtkWidget *widget, GObject *activity); |
98 | 98 | LIB3270_EXPORT GObject * v3270_ft_settings_get_activity(GtkWidget *widget); |
99 | 99 | |
100 | + LIB3270_EXPORT gboolean v3270_ft_settings_set_from_filename(GtkWidget *widget, const gchar *filename); | |
101 | + | |
100 | 102 | LIB3270_EXPORT GObject * v3270_ft_settings_create_activity(GtkWidget *widget); |
101 | 103 | |
102 | 104 | LIB3270_EXPORT void v3270_ft_settings_reset(GtkWidget *widget); | ... | ... |
src/testprogram/testprogram.c
... | ... | @@ -184,18 +184,16 @@ static void ft_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) |
184 | 184 | v3270_ft_activity_set_options(activity,LIB3270_FT_OPTION_RECEIVE|LIB3270_FT_OPTION_ASCII|LIB3270_FT_OPTION_REMAP); |
185 | 185 | */ |
186 | 186 | |
187 | - /* | |
188 | 187 | // |
189 | 188 | // Test settings dialog |
190 | 189 | // |
191 | 190 | GtkWidget * dialog = v3270_ft_settings_dialog_new(terminal); |
192 | 191 | // v3270_ft_settings_dialog_append_activity(dialog,activity,NULL); |
193 | - */ | |
194 | 192 | |
195 | 193 | // |
196 | 194 | // V5.1 dialog |
197 | 195 | // |
198 | - GtkWidget *dialog = v3270ft_new(); | |
196 | + //GtkWidget *dialog = v3270ft_new(); | |
199 | 197 | |
200 | 198 | /* |
201 | 199 | // | ... | ... |