Commit eccd504d4a2a5711a18b546315eb272b54388993
1 parent
064bb96e
Exists in
master
and in
1 other branch
Adding drag&drop support in the activity list component.
Showing
7 changed files
with
112 additions
and
37 deletions
Show diff stats
src/filetransfer/activity.c
| ... | ... | @@ -165,6 +165,36 @@ |
| 165 | 165 | return g_object_new(G_TYPE_V3270_FT_ACTIVITY, NULL); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | + LIB3270_EXPORT GObject * v3270_ft_activity_new_from_filename(const gchar *filename) | |
| 169 | + { | |
| 170 | + GObject *activity = g_object_new(G_TYPE_V3270_FT_ACTIVITY, NULL); | |
| 171 | + | |
| 172 | + // Set local filename | |
| 173 | + v3270_ft_activity_set_local_filename(activity,filename); | |
| 174 | + | |
| 175 | + // Set options | |
| 176 | + LIB3270_FT_OPTION options = LIB3270_FT_OPTION_SEND; | |
| 177 | + size_t ix; | |
| 178 | + | |
| 179 | + for(ix = 0; v3270_text_file_extensions[ix]; ix++) | |
| 180 | + { | |
| 181 | + if(g_str_has_suffix(filename,v3270_text_file_extensions[ix])) | |
| 182 | + { | |
| 183 | + options |= (LIB3270_FT_OPTION_ASCII|LIB3270_FT_OPTION_CRLF|LIB3270_FT_OPTION_REMAP); | |
| 184 | + break; | |
| 185 | + } | |
| 186 | + } | |
| 187 | + | |
| 188 | + v3270_ft_activity_set_options(activity,options); | |
| 189 | + | |
| 190 | + // Set remote filename | |
| 191 | + g_autofree gchar * basename = g_path_get_basename(filename); | |
| 192 | + v3270_ft_activity_set_remote_filename(activity,basename); | |
| 193 | + | |
| 194 | + return activity; | |
| 195 | + } | |
| 196 | + | |
| 197 | + | |
| 168 | 198 | /** |
| 169 | 199 | * v3270_ft_activity_get_local_filename: |
| 170 | 200 | * @object: a #V3270FTActivity | ... | ... |
src/filetransfer/activitylist.c
| ... | ... | @@ -138,6 +138,65 @@ |
| 138 | 138 | g_object_set(G_OBJECT(cell),"text",v3270_ft_activity_get_remote_filename(activity),NULL); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | + gboolean v3270_activity_list_append_filename(GtkWidget *widget, const gchar *filename) | |
| 142 | + { | |
| 143 | + debug("%s(%s)",__FUNCTION__,filename); | |
| 144 | + | |
| 145 | + GtkTreeModel * model = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 146 | + GtkTreeIter iter; | |
| 147 | + | |
| 148 | + if(gtk_tree_model_get_iter_first(model,&iter)) | |
| 149 | + { | |
| 150 | + do | |
| 151 | + { | |
| 152 | + GObject * activity = NULL; | |
| 153 | + gtk_tree_model_get(model, &iter, 0, &activity, -1); | |
| 154 | + | |
| 155 | + if(activity && !strcmp(filename,v3270_ft_activity_get_local_filename(activity))) | |
| 156 | + { | |
| 157 | + debug("%s already in the list",filename); | |
| 158 | + return FALSE; | |
| 159 | + } | |
| 160 | + | |
| 161 | + | |
| 162 | + } | |
| 163 | + while(gtk_tree_model_iter_next(model,&iter)); | |
| 164 | + } | |
| 165 | + | |
| 166 | + // Append filename | |
| 167 | + v3270_activity_list_append(widget,v3270_ft_activity_new_from_filename(filename)); | |
| 168 | + | |
| 169 | + return TRUE; | |
| 170 | + } | |
| 171 | + | |
| 172 | + guint v3270_activity_list_set_from_selection(GtkWidget *widget, GtkSelectionData *data) | |
| 173 | + { | |
| 174 | + gchar **uris = g_strsplit((const gchar *) gtk_selection_data_get_text(data),"\n",-1); | |
| 175 | + guint rc = 0; | |
| 176 | + size_t ix; | |
| 177 | + | |
| 178 | + for(ix = 0; uris[ix]; ix++) | |
| 179 | + { | |
| 180 | + if(!g_ascii_strncasecmp("file:///",uris[ix],8)) { | |
| 181 | + if(v3270_activity_list_append_filename(widget,uris[ix]+7)) | |
| 182 | + rc++; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + | |
| 186 | + g_strfreev(uris); | |
| 187 | + | |
| 188 | + debug("%s exits with rc=%u",__FUNCTION__,rc); | |
| 189 | + return rc; | |
| 190 | +} | |
| 191 | + | |
| 192 | + | |
| 193 | + 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) | |
| 194 | + { | |
| 195 | + debug("activitylist::%s",__FUNCTION__); | |
| 196 | + gtk_drag_finish(context, v3270_activity_list_set_from_selection(widget, data) > 0, FALSE, time); | |
| 197 | + | |
| 198 | + } | |
| 199 | + | |
| 141 | 200 | static void V3270FTActivityList_init(V3270FTActivityList *widget) |
| 142 | 201 | { |
| 143 | 202 | 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 @@ |
| 166 | 225 | 0, NULL |
| 167 | 226 | ); |
| 168 | 227 | |
| 228 | + v3270_drag_dest_set(GTK_WIDGET(widget), G_CALLBACK(drag_data_received)); | |
| 229 | + | |
| 169 | 230 | } |
| 170 | 231 | |
| 171 | 232 | GtkWidget * v3270_activity_list_new() |
| ... | ... | @@ -308,33 +369,7 @@ |
| 308 | 369 | { |
| 309 | 370 | GObject * activity = NULL; |
| 310 | 371 | gtk_tree_model_get(model, &iter, 0, &activity, -1); |
| 311 | - | |
| 312 | 372 | v3270_ft_activity_xml_encode(activity,str); |
| 313 | - | |
| 314 | - /* | |
| 315 | - if(activity) | |
| 316 | - { | |
| 317 | - g_string_append(str,"\t<entry>\n"); | |
| 318 | - | |
| 319 | - g_string_append_printf(str,"\t\t<file type=\'local\' path=\'%s\' />\n",v3270_ft_activity_get_local_filename(activity)); | |
| 320 | - g_string_append_printf(str,"\t\t<file type=\'remote\' path=\'%s\' />\n",v3270_ft_activity_get_remote_filename(activity)); | |
| 321 | - | |
| 322 | - LIB3270_FT_OPTION options = v3270_ft_activity_get_options(activity); | |
| 323 | - for(ix = 0; v3270_activity_list_options[ix].name; ix++) | |
| 324 | - { | |
| 325 | - if((options & v3270_activity_list_options[ix].option) == v3270_activity_list_options[ix].option) | |
| 326 | - 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); | |
| 327 | - } | |
| 328 | - | |
| 329 | - for(ix=0;ix<LIB3270_FT_VALUE_COUNT;ix++) | |
| 330 | - { | |
| 331 | - g_string_append_printf(str,"\t\t<parameter name=\"%s\" value=\"%u\"/>\n",ft_value[ix].name,v3270_ft_activity_get_value(activity,(LIB3270_FT_VALUE) ix)); | |
| 332 | - } | |
| 333 | - | |
| 334 | - g_string_append(str,"\t</entry>\n"); | |
| 335 | - } | |
| 336 | - */ | |
| 337 | - | |
| 338 | 373 | } |
| 339 | 374 | while(gtk_tree_model_iter_next(model,&iter)); |
| 340 | 375 | } | ... | ... |
src/filetransfer/misc.c
| ... | ... | @@ -94,3 +94,15 @@ void v3270ft_update_actions(v3270ft *dialog) { |
| 94 | 94 | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | +void v3270_drag_dest_set(GtkWidget *widget, GCallback callback) | |
| 98 | +{ | |
| 99 | + | |
| 100 | + // http://ftp.math.utah.edu/u/ma/hohn/linux/gnome/developer.gnome.org/doc/tutorials/gnome-libs/x1003.html | |
| 101 | + static const GtkTargetEntry targets[] = { | |
| 102 | + { "text/plain", GTK_TARGET_OTHER_APP, 0 } | |
| 103 | + }; | |
| 104 | + | |
| 105 | + gtk_drag_dest_set(widget,GTK_DEST_DEFAULT_ALL,targets,G_N_ELEMENTS(targets),GDK_ACTION_COPY); | |
| 106 | + g_signal_connect(widget,"drag-data-received",callback,widget); | |
| 107 | + | |
| 108 | +} | ... | ... |
src/filetransfer/settings.c
| ... | ... | @@ -388,7 +388,6 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
| 391 | - | |
| 392 | 391 | gtk_entry_set_text(settings->file.local,filename); |
| 393 | 392 | |
| 394 | 393 | 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 |
| 410 | 409 | if(!g_ascii_strncasecmp("file:///",uris[ix],8)) { |
| 411 | 410 | |
| 412 | 411 | if(v3270_ft_settings_set_from_filename(widget,uris[ix]+7)) |
| 412 | + { | |
| 413 | + rc++; | |
| 413 | 414 | break; |
| 415 | + } | |
| 414 | 416 | |
| 415 | 417 | } |
| 416 | 418 | } |
| ... | ... | @@ -422,7 +424,7 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP |
| 422 | 424 | |
| 423 | 425 | 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 | 426 | { |
| 425 | - debug("%s",__FUNCTION__); | |
| 427 | + debug("settings::%s",__FUNCTION__); | |
| 426 | 428 | gtk_drag_finish(context, v3270_ft_settings_set_from_selection(widget, data) > 0, FALSE, time); |
| 427 | 429 | } |
| 428 | 430 | |
| ... | ... | @@ -597,14 +599,7 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP |
| 597 | 599 | gtk_widget_set_sensitive(GTK_WIDGET(widget->file.local),FALSE); |
| 598 | 600 | gtk_widget_set_sensitive(GTK_WIDGET(widget->file.remote),FALSE); |
| 599 | 601 | |
| 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); | |
| 602 | + v3270_drag_dest_set(GTK_WIDGET(widget), G_CALLBACK(drag_data_received)); | |
| 608 | 603 | |
| 609 | 604 | } |
| 610 | 605 | ... | ... |
src/filetransfer/tables.c
src/include/internals.h
| ... | ... | @@ -47,6 +47,8 @@ |
| 47 | 47 | |
| 48 | 48 | G_BEGIN_DECLS |
| 49 | 49 | |
| 50 | + G_GNUC_INTERNAL void v3270_drag_dest_set(GtkWidget *widget, GCallback callback); | |
| 51 | + | |
| 50 | 52 | G_GNUC_INTERNAL GtkWidget * v3270_box_pack_start(GtkWidget *box, GtkWidget *child, gboolean expand, gboolean fill, guint padding); |
| 51 | 53 | G_GNUC_INTERNAL GtkWidget * v3270_box_pack_end(GtkWidget *box, GtkWidget *child, gboolean expand, gboolean fill, guint padding); |
| 52 | 54 | 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); | ... | ... |
src/include/v3270/filetransfer.h
| ... | ... | @@ -119,6 +119,7 @@ |
| 119 | 119 | typedef struct _V3270FTActivityClass V3270FTActivityClass; |
| 120 | 120 | |
| 121 | 121 | LIB3270_EXPORT GObject * v3270_ft_activity_new(); |
| 122 | + LIB3270_EXPORT GObject * v3270_ft_activity_new_from_filename(const gchar *filename); | |
| 122 | 123 | |
| 123 | 124 | LIB3270_EXPORT void v3270_ft_activity_set_from_context(GObject * activity, GMarkupParseContext * context); |
| 124 | 125 | ... | ... |