diff --git a/src/filetransfer/private.h b/src/filetransfer/private.h index 4924fb5..ef8dd96 100644 --- a/src/filetransfer/private.h +++ b/src/filetransfer/private.h @@ -128,6 +128,7 @@ G_GNUC_INTERNAL extern const struct v3270ft_value ft_value[]; G_GNUC_INTERNAL extern const struct v3270_activity_list_option v3270_activity_list_options[]; G_GNUC_INTERNAL extern const struct v3270_ft_worker_field v3270_ft_worker_fields[PROGRESS_FIELD_COUNT]; + G_GNUC_INTERNAL extern const gchar * v3270_text_file_extensions[]; #define ENTRY_FILENAME_LENGTH FILENAME_MAX struct v3270ft_entry { diff --git a/src/filetransfer/settings.c b/src/filetransfer/settings.c index 72bc0fd..ba6ddd6 100644 --- a/src/filetransfer/settings.c +++ b/src/filetransfer/settings.c @@ -352,7 +352,8 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP set_valid(widget, VALIDITY_LOCAL_FILENAME); } - static void remote_file_changed(GtkEntry *entry, V3270FTSettings *widget) { + static void remote_file_changed(GtkEntry *entry, V3270FTSettings *widget) + { const gchar * text = gtk_entry_get_text(entry); @@ -366,6 +367,65 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP } + LIB3270_EXPORT gboolean v3270_ft_settings_set_from_filename(GtkWidget *widget, const gchar *filename) + { + g_return_val_if_fail(GTK_IS_V3270_FT_SETTINGS(widget) && g_file_test(filename,G_FILE_TEST_IS_REGULAR),FALSE); + + debug("%s(%s)",__FUNCTION__,filename); + + // Setup dialog from filename. + V3270FTSettings * settings = GTK_V3270_FT_SETTINGS(widget); + LIB3270_FT_OPTION options = LIB3270_FT_OPTION_SEND; + size_t ix; + + for(ix = 0; v3270_text_file_extensions[ix]; ix++) + { + if(g_str_has_suffix(filename,v3270_text_file_extensions[ix])) + { + options |= (LIB3270_FT_OPTION_ASCII|LIB3270_FT_OPTION_CRLF|LIB3270_FT_OPTION_REMAP); + break; + } + } + + + + gtk_entry_set_text(settings->file.local,filename); + + g_autofree gchar * basename = g_path_get_basename(filename); + gtk_entry_set_text(settings->file.remote,basename); + + v3270_ft_settings_set_options(widget,options); + + return TRUE; + } + + guint v3270_ft_settings_set_from_selection(GtkWidget *widget, GtkSelectionData *data) + { + gchar **uris = g_strsplit((const gchar *) gtk_selection_data_get_text(data),"\n",-1); + guint rc = 0; + size_t ix; + + for(ix = 0; uris[ix]; ix++) + { + if(!g_ascii_strncasecmp("file:///",uris[ix],8)) { + + if(v3270_ft_settings_set_from_filename(widget,uris[ix]+7)) + break; + + } + } + + g_strfreev(uris); + + return rc; +} + + 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) + { + debug("%s",__FUNCTION__); + gtk_drag_finish(context, v3270_ft_settings_set_from_selection(widget, data) > 0, FALSE, time); + } + static void V3270FTSettings_init(V3270FTSettings *widget) { size_t ix; @@ -537,6 +597,15 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP gtk_widget_set_sensitive(GTK_WIDGET(widget->file.local),FALSE); gtk_widget_set_sensitive(GTK_WIDGET(widget->file.remote),FALSE); + // Setup drag & drop + // http://ftp.math.utah.edu/u/ma/hohn/linux/gnome/developer.gnome.org/doc/tutorials/gnome-libs/x1003.html + static const GtkTargetEntry targets[] = { + { "text/plain", GTK_TARGET_OTHER_APP, 0 } + }; + + gtk_drag_dest_set(GTK_WIDGET(widget),GTK_DEST_DEFAULT_ALL,targets,G_N_ELEMENTS(targets),GDK_ACTION_COPY); + g_signal_connect(widget,"drag-data-received",G_CALLBACK(drag_data_received),widget); + } LIB3270_EXPORT GtkWidget * v3270_ft_settings_new() diff --git a/src/filetransfer/tables.c b/src/filetransfer/tables.c index 5eedaee..9c1baca 100644 --- a/src/filetransfer/tables.c +++ b/src/filetransfer/tables.c @@ -223,3 +223,12 @@ const struct v3270_ft_worker_field v3270_ft_worker_fields[PROGRESS_FIELD_COUNT] { N_("Speed:"), N_("Transfer speed") }, { N_("ETA:"), N_("Estimated transfer arrival") } }; + +const gchar * v3270_text_file_extensions[] = +{ + ".txt", + ".c", + ".h" + NULL +}; + diff --git a/src/include/v3270/filetransfer.h b/src/include/v3270/filetransfer.h index 1fab56a..17a15a7 100644 --- a/src/include/v3270/filetransfer.h +++ b/src/include/v3270/filetransfer.h @@ -97,6 +97,8 @@ LIB3270_EXPORT void v3270_ft_settings_set_activity(GtkWidget *widget, GObject *activity); LIB3270_EXPORT GObject * v3270_ft_settings_get_activity(GtkWidget *widget); + LIB3270_EXPORT gboolean v3270_ft_settings_set_from_filename(GtkWidget *widget, const gchar *filename); + LIB3270_EXPORT GObject * v3270_ft_settings_create_activity(GtkWidget *widget); LIB3270_EXPORT void v3270_ft_settings_reset(GtkWidget *widget); diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index c316a6a..722199d 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -184,18 +184,16 @@ static void ft_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) v3270_ft_activity_set_options(activity,LIB3270_FT_OPTION_RECEIVE|LIB3270_FT_OPTION_ASCII|LIB3270_FT_OPTION_REMAP); */ - /* // // Test settings dialog // GtkWidget * dialog = v3270_ft_settings_dialog_new(terminal); // v3270_ft_settings_dialog_append_activity(dialog,activity,NULL); - */ // // V5.1 dialog // - GtkWidget *dialog = v3270ft_new(); + //GtkWidget *dialog = v3270ft_new(); /* // -- libgit2 0.21.2