diff --git a/src/filetransfer/activity.c b/src/filetransfer/activity.c index a5f2df6..f84b2c5 100644 --- a/src/filetransfer/activity.c +++ b/src/filetransfer/activity.c @@ -165,6 +165,36 @@ return g_object_new(G_TYPE_V3270_FT_ACTIVITY, NULL); } + LIB3270_EXPORT GObject * v3270_ft_activity_new_from_filename(const gchar *filename) + { + GObject *activity = g_object_new(G_TYPE_V3270_FT_ACTIVITY, NULL); + + // Set local filename + v3270_ft_activity_set_local_filename(activity,filename); + + // Set options + 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; + } + } + + v3270_ft_activity_set_options(activity,options); + + // Set remote filename + g_autofree gchar * basename = g_path_get_basename(filename); + v3270_ft_activity_set_remote_filename(activity,basename); + + return activity; + } + + /** * v3270_ft_activity_get_local_filename: * @object: a #V3270FTActivity diff --git a/src/filetransfer/activitylist.c b/src/filetransfer/activitylist.c index 127f58e..8ad288c 100644 --- a/src/filetransfer/activitylist.c +++ b/src/filetransfer/activitylist.c @@ -138,6 +138,65 @@ g_object_set(G_OBJECT(cell),"text",v3270_ft_activity_get_remote_filename(activity),NULL); } + gboolean v3270_activity_list_append_filename(GtkWidget *widget, const gchar *filename) + { + debug("%s(%s)",__FUNCTION__,filename); + + GtkTreeModel * model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); + GtkTreeIter iter; + + if(gtk_tree_model_get_iter_first(model,&iter)) + { + do + { + GObject * activity = NULL; + gtk_tree_model_get(model, &iter, 0, &activity, -1); + + if(activity && !strcmp(filename,v3270_ft_activity_get_local_filename(activity))) + { + debug("%s already in the list",filename); + return FALSE; + } + + + } + while(gtk_tree_model_iter_next(model,&iter)); + } + + // Append filename + v3270_activity_list_append(widget,v3270_ft_activity_new_from_filename(filename)); + + return TRUE; + } + + guint v3270_activity_list_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_activity_list_append_filename(widget,uris[ix]+7)) + rc++; + } + } + + g_strfreev(uris); + + debug("%s exits with rc=%u",__FUNCTION__,rc); + 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("activitylist::%s",__FUNCTION__); + gtk_drag_finish(context, v3270_activity_list_set_from_selection(widget, data) > 0, FALSE, time); + + } + static void V3270FTActivityList_init(V3270FTActivityList *widget) { GtkTreeModel * model = GTK_TREE_MODEL(gtk_list_store_new(1,G_TYPE_POINTER)); // Using pointer type because I take care of refcounts. @@ -166,6 +225,8 @@ 0, NULL ); + v3270_drag_dest_set(GTK_WIDGET(widget), G_CALLBACK(drag_data_received)); + } GtkWidget * v3270_activity_list_new() @@ -308,33 +369,7 @@ { GObject * activity = NULL; gtk_tree_model_get(model, &iter, 0, &activity, -1); - v3270_ft_activity_xml_encode(activity,str); - - /* - if(activity) - { - g_string_append(str,"\t\n"); - - g_string_append_printf(str,"\t\t\n",v3270_ft_activity_get_local_filename(activity)); - g_string_append_printf(str,"\t\t\n",v3270_ft_activity_get_remote_filename(activity)); - - LIB3270_FT_OPTION options = v3270_ft_activity_get_options(activity); - for(ix = 0; v3270_activity_list_options[ix].name; ix++) - { - if((options & v3270_activity_list_options[ix].option) == v3270_activity_list_options[ix].option) - g_string_append_printf(str,"\t\t\n"); - } - */ - } while(gtk_tree_model_iter_next(model,&iter)); } diff --git a/src/filetransfer/misc.c b/src/filetransfer/misc.c index 0c6461a..253b753 100644 --- a/src/filetransfer/misc.c +++ b/src/filetransfer/misc.c @@ -94,3 +94,15 @@ void v3270ft_update_actions(v3270ft *dialog) { } +void v3270_drag_dest_set(GtkWidget *widget, GCallback callback) +{ + + // 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(widget,GTK_DEST_DEFAULT_ALL,targets,G_N_ELEMENTS(targets),GDK_ACTION_COPY); + g_signal_connect(widget,"drag-data-received",callback,widget); + +} diff --git a/src/filetransfer/settings.c b/src/filetransfer/settings.c index ba6ddd6..043ae0b 100644 --- a/src/filetransfer/settings.c +++ b/src/filetransfer/settings.c @@ -388,7 +388,6 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP } - gtk_entry_set_text(settings->file.local,filename); g_autofree gchar * basename = g_path_get_basename(filename); @@ -410,7 +409,10 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP if(!g_ascii_strncasecmp("file:///",uris[ix],8)) { if(v3270_ft_settings_set_from_filename(widget,uris[ix]+7)) + { + rc++; break; + } } } @@ -422,7 +424,7 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP 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__); + debug("settings::%s",__FUNCTION__); gtk_drag_finish(context, v3270_ft_settings_set_from_selection(widget, data) > 0, FALSE, time); } @@ -597,14 +599,7 @@ 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); + v3270_drag_dest_set(GTK_WIDGET(widget), G_CALLBACK(drag_data_received)); } diff --git a/src/filetransfer/tables.c b/src/filetransfer/tables.c index 9c1baca..2b6a07b 100644 --- a/src/filetransfer/tables.c +++ b/src/filetransfer/tables.c @@ -228,7 +228,7 @@ const gchar * v3270_text_file_extensions[] = { ".txt", ".c", - ".h" + ".h", NULL }; diff --git a/src/include/internals.h b/src/include/internals.h index ff77f03..9704e74 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -47,6 +47,8 @@ G_BEGIN_DECLS + G_GNUC_INTERNAL void v3270_drag_dest_set(GtkWidget *widget, GCallback callback); + G_GNUC_INTERNAL GtkWidget * v3270_box_pack_start(GtkWidget *box, GtkWidget *child, gboolean expand, gboolean fill, guint padding); G_GNUC_INTERNAL GtkWidget * v3270_box_pack_end(GtkWidget *box, GtkWidget *child, gboolean expand, gboolean fill, guint padding); G_GNUC_INTERNAL GtkWidget * v3270_box_pack_frame(GtkWidget *box, GtkWidget *child, const gchar *title, const gchar *tooltip, GtkAlign align, gboolean expand, gboolean fill, guint padding); diff --git a/src/include/v3270/filetransfer.h b/src/include/v3270/filetransfer.h index 17a15a7..18f386e 100644 --- a/src/include/v3270/filetransfer.h +++ b/src/include/v3270/filetransfer.h @@ -119,6 +119,7 @@ typedef struct _V3270FTActivityClass V3270FTActivityClass; LIB3270_EXPORT GObject * v3270_ft_activity_new(); + LIB3270_EXPORT GObject * v3270_ft_activity_new_from_filename(const gchar *filename); LIB3270_EXPORT void v3270_ft_activity_set_from_context(GObject * activity, GMarkupParseContext * context); -- libgit2 0.21.2