# HG changeset patch # User masneyb # Date 1073353449 0 # Node ID 60d3da6ab3369ed198ca7527a811de34efb812fd # Parent 2ea37b3c015890c9af564bd9946cbdd625b6dad7 2003-1-5 Brian Masney * src/gtk/gftp-gtk.h src/gtk/gtkui.c - when spawning a thread, make sure that the GUI will be updated properly as soon as the thread is finished. * src/uicommon/gftpuicallbacks.c src/uicommon/gftpui.h - added gftpui_common_run_ls() * src/uicommon/gftpui.c (gftpui_common_cmd_ls) src/gtk/transfer.c (ftp_list_files) - converted these functions over to use gftpui_common_run_ls() diff -r 2ea37b3c0158 -r 60d3da6ab336 ChangeLog --- a/ChangeLog Mon Jan 05 23:38:22 2004 +0000 +++ b/ChangeLog Tue Jan 06 01:44:09 2004 +0000 @@ -1,4 +1,15 @@ 2003-1-5 Brian Masney + * src/gtk/gftp-gtk.h src/gtk/gtkui.c - when spawning a thread, + make sure that the GUI will be updated properly as soon as the thread + is finished. + + * src/uicommon/gftpuicallbacks.c src/uicommon/gftpui.h - added + gftpui_common_run_ls() + + * src/uicommon/gftpui.c (gftpui_common_cmd_ls) + src/gtk/transfer.c (ftp_list_files) - converted these functions + over to use gftpui_common_run_ls() + * lib/gftp.h src/gtk/misc-gtk.c src/text/gftp-text.c - added logging level type gftp_logging_misc_nolog. If a message is logged with this level, it will be displayed to the screen but, it will not be logged @@ -1926,7 +1937,7 @@ * cvsclean - added this script - * *.[ch] - added $Id: ChangeLog,v 1.195 2004/01/05 23:38:19 masneyb Exp $ tags + * *.[ch] - added $Id: ChangeLog,v 1.196 2004/01/06 01:44:07 masneyb Exp $ tags * debian/* - updated files from Debian maintainer diff -r 2ea37b3c0158 -r 60d3da6ab336 src/gtk/gftp-gtk.h --- a/src/gtk/gftp-gtk.h Mon Jan 05 23:38:22 2004 +0000 +++ b/src/gtk/gftp-gtk.h Tue Jan 06 01:44:09 2004 +0000 @@ -93,6 +93,13 @@ } gftp_window_data; +typedef struct _gftpui_gtk_thread_data +{ + void * (*func) (void *); + gftpui_callback_data * cdata; +} gftpui_gtk_thread_data; + + typedef struct gftp_graphic_tag { char * filename; diff -r 2ea37b3c0158 -r 60d3da6ab336 src/gtk/gtkui.c --- a/src/gtk/gtkui.c Mon Jan 05 23:38:22 2004 +0000 +++ b/src/gtk/gtkui.c Tue Jan 06 01:44:09 2004 +0000 @@ -61,11 +61,79 @@ } +/* The wakeup main thread functions are so that after the thread terminates + there won't be a delay in updating the GUI */ +static void +_gftpui_wakeup_main_thread (gpointer data, gint source, + GdkInputCondition condition) +{ + gftp_request * request; + char c; + + request = data; + if (request->wakeup_main_thread[0] > 0) + read (request->wakeup_main_thread[0], &c, 1); +} + + +static gint +_gftpui_setup_wakeup_main_thread (gftp_request * request) +{ + gint handler; + + if (socketpair (AF_UNIX, SOCK_STREAM, 0, request->wakeup_main_thread) == 0) + { + handler = gdk_input_add (request->wakeup_main_thread[0], + GDK_INPUT_READ, _gftpui_wakeup_main_thread, + request); + } + else + { + request->wakeup_main_thread[0] = 0; + request->wakeup_main_thread[1] = 0; + handler = 0; + } + + return (handler); +} + + +static void +_gftpui_teardown_wakeup_main_thread (gftp_request * request, gint handler) +{ + if (request->wakeup_main_thread[0] > 0 && request->wakeup_main_thread[1] > 0) + { + gdk_input_remove (handler); + close (request->wakeup_main_thread[0]); + close (request->wakeup_main_thread[1]); + request->wakeup_main_thread[0] = 0; + request->wakeup_main_thread[1] = 0; + } +} + +static void * +_gftpui_gtk_thread_func (void *data) +{ + gftpui_gtk_thread_data * thread_data; + void *ret; + + thread_data = data; + ret = thread_data->func (thread_data->cdata); + + if (thread_data->cdata->request->wakeup_main_thread[1] > 0) + write (thread_data->cdata->request->wakeup_main_thread[1], " ", 1); + + return (ret); +} + + void * gftpui_generic_thread (void * (*func) (void *), void *data) { + gftpui_gtk_thread_data * thread_data; gftpui_callback_data * cdata; gftp_window_data * wdata; + guint handler; void * ret; cdata = data; @@ -73,7 +141,13 @@ wdata->request->stopable = 1; gtk_widget_set_sensitive (stop_btn, 1); - pthread_create (&wdata->tid, NULL, func, cdata); + + thread_data = g_malloc0 (sizeof (*thread_data)); + thread_data->func = func; + thread_data->cdata = cdata; + + handler = _gftpui_setup_wakeup_main_thread (cdata->request); + pthread_create (&wdata->tid, NULL, _gftpui_gtk_thread_func, thread_data); while (wdata->request->stopable) { @@ -85,6 +159,9 @@ #endif } + _gftpui_teardown_wakeup_main_thread (cdata->request, handler); + g_free (thread_data); + pthread_join (wdata->tid, &ret); gtk_widget_set_sensitive (stop_btn, 0); diff -r 2ea37b3c0158 -r 60d3da6ab336 src/gtk/transfer.c --- a/src/gtk/transfer.c Mon Jan 05 23:38:22 2004 +0000 +++ b/src/gtk/transfer.c Tue Jan 06 01:44:09 2004 +0000 @@ -23,189 +23,23 @@ static GtkWidget * dialog; static int num_transfers_in_progress = 0; -static void -wakeup_main_thread (gpointer data, gint source, GdkInputCondition condition) -{ - gftp_request * request; - char c; - - request = data; - if (request->wakeup_main_thread[0] > 0) - read (request->wakeup_main_thread[0], &c, 1); -} - - -static gint -setup_wakeup_main_thread (gftp_request * request) -{ - gint handler; - - if (socketpair (AF_UNIX, SOCK_STREAM, 0, request->wakeup_main_thread) == 0) - { - handler = gdk_input_add (request->wakeup_main_thread[0], - GDK_INPUT_READ, wakeup_main_thread, request); - } - else - { - request->wakeup_main_thread[0] = 0; - request->wakeup_main_thread[1] = 0; - handler = 0; - } - return (handler); -} - - -static void -teardown_wakeup_main_thread (gftp_request * request, gint handler) -{ - if (request->wakeup_main_thread[0] > 0 && request->wakeup_main_thread[1] > 0) - { - gdk_input_remove (handler); - close (request->wakeup_main_thread[0]); - close (request->wakeup_main_thread[1]); - request->wakeup_main_thread[0] = 0; - request->wakeup_main_thread[1] = 0; - } -} - - -static void * -getdir_thread (void * data) -{ - int sj, havedotdot, got; - gftp_request * request; - gftp_file * fle; - GList * files; - - request = data; - - if (gftpui_common_use_threads (request)) - { - sj = sigsetjmp (gftpui_common_jmp_environment, 1); - gftpui_common_use_jmp_environment = 1; - } - else - sj = 0; - - files = NULL; - if (sj == 0 || sj == 2) - { - if (gftp_list_files (request) != 0 || !GFTP_IS_CONNECTED (request)) - { - if (gftpui_common_use_threads (request)) - gftpui_common_use_jmp_environment = 0; - - request->stopable = 0; - if (request->wakeup_main_thread[1] > 0) - write (request->wakeup_main_thread[1], " ", 1); - return (NULL); - } - - request->gotbytes = 0; - havedotdot = 0; - fle = g_malloc0 (sizeof (*fle)); - while ((got = gftp_get_next_file (request, NULL, fle)) > 0 || - got == GFTP_ERETRYABLE) - { - if (got < 0) - { - gftp_file_destroy (fle); - continue; - } - - request->gotbytes += got; - if (strcmp (fle->file, ".") == 0) - { - gftp_file_destroy (fle); - continue; - } - else if (strcmp (fle->file, "..") == 0) - havedotdot = 1; - - files = g_list_append (files, fle); - fle = g_malloc0 (sizeof (*fle)); - } - g_free (fle); - - if (!GFTP_IS_CONNECTED (request)) - { - if (gftpui_common_use_threads (request)) - gftpui_common_use_jmp_environment = 0; - - request->stopable = 0; - if (request->wakeup_main_thread[1] > 0) - write (request->wakeup_main_thread[1], " ", 1); - return (NULL); - } - - gftp_end_transfer (request); - request->gotbytes = -1; - - if (!havedotdot) - { - fle = g_malloc0 (sizeof (*fle)); - fle->file = g_strdup (".."); - fle->user = g_malloc0 (1); - fle->group = g_malloc0 (1); - fle->attribs = g_malloc0 (1); - *fle->attribs = '\0'; - fle->isdir = 1; - files = g_list_prepend (files, fle); - } - } - - if (gftpui_common_use_threads (request)) - gftpui_common_use_jmp_environment = 0; - - request->stopable = 0; - if (request->wakeup_main_thread[1] > 0) - write (request->wakeup_main_thread[1], " ", 1); - return (files); -} - - int ftp_list_files (gftp_window_data * wdata, int usecache) { - guint handler; - void *success; + gftpui_callback_data * cdata; gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); - wdata->show_selected = 0; - if (wdata->files == NULL) - { - if (check_reconnect (wdata) < 0) - return (0); - - gtk_clist_freeze (GTK_CLIST (wdata->listbox)); - wdata->request->stopable = 1; - if (gftpui_common_use_threads (wdata->request)) - { - gtk_widget_set_sensitive (stop_btn, 1); + cdata = g_malloc0 (sizeof (*cdata)); + cdata->request = wdata->request; + cdata->uidata = wdata; + cdata->run_function = gftpui_common_run_ls; - handler = setup_wakeup_main_thread (wdata->request); - pthread_create (&wdata->tid, NULL, getdir_thread, wdata->request); - while (wdata->request->stopable) - { - GDK_THREADS_LEAVE (); -#if GTK_MAJOR_VERSION == 1 - g_main_iteration (TRUE); -#else - g_main_context_iteration (NULL, TRUE); -#endif - } - teardown_wakeup_main_thread (wdata->request, handler); + gftpui_common_run_callback_function (cdata); - pthread_join (wdata->tid, &success); - gtk_widget_set_sensitive (stop_btn, 0); - } - else - success = getdir_thread (wdata->request); - wdata->files = success; - gtk_clist_thaw (GTK_CLIST (wdata->listbox)); - memset (&wdata->tid, 0, sizeof (wdata->tid)); - } + wdata->files = cdata->files; + cdata->files = NULL; + g_free (cdata); if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) { @@ -215,8 +49,10 @@ wdata->sorted = 0; sortrows (GTK_CLIST (wdata->listbox), -1, (gpointer) wdata); + if (IS_NONE_SELECTED (wdata)) gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); + return (1); } @@ -308,7 +144,6 @@ ftp_connect (gftp_window_data * wdata, gftp_request * request, int getdir) { int success; - guint handler; void *ret; ret = 0; @@ -355,7 +190,6 @@ gtk_widget_set_sensitive (stop_btn, 1); pthread_create (&wdata->tid, NULL, connect_thread, request); - handler = setup_wakeup_main_thread (wdata->request); while (request->stopable) { GDK_THREADS_LEAVE (); @@ -366,7 +200,6 @@ #endif } pthread_join (wdata->tid, &ret); - teardown_wakeup_main_thread (wdata->request, handler); gtk_widget_set_sensitive (stop_btn, 0); if (wdata) diff -r 2ea37b3c0158 -r 60d3da6ab336 src/uicommon/gftpui.c --- a/src/uicommon/gftpui.c Mon Jan 05 23:38:22 2004 +0000 +++ b/src/uicommon/gftpui.c Tue Jan 06 01:44:09 2004 +0000 @@ -88,7 +88,7 @@ else ret = GPOINTER_TO_INT (cdata->run_function (cdata)); - if (ret) + if (ret && cdata->run_function != gftpui_common_run_ls) gftpui_refresh (cdata->uidata); return (ret); @@ -497,17 +497,14 @@ } -int +static int gftpui_common_cmd_ls (void *uidata, gftp_request * request, char *command) { - char *startcolor, *endcolor, *filespec, *tempstr; - GList * files, * templist, * delitem; - intptr_t sortcol, sortasds; + char *startcolor, *endcolor, *tempstr; + gftpui_callback_data * cdata; + GList * templist; gftp_file * fle; - time_t curtime; - int got; - time (&curtime); if (!GFTP_IS_CONNECTED (request)) { request->logging_function (gftp_logging_error, request, @@ -515,80 +512,34 @@ return (1); } - filespec = *command != '\0' ? command : NULL; - if (gftp_list_files (request) != 0) - return (1); + cdata = g_malloc0 (sizeof (*cdata)); + cdata->request = request; + cdata->uidata = uidata; + cdata->source_string = *command != '\0' ? command : NULL; + cdata->run_function = gftpui_common_run_ls; - files = NULL; - fle = g_malloc0 (sizeof (*fle)); - while ((got = gftp_get_next_file (request, NULL, fle)) > 0 || - got == GFTP_ERETRYABLE) - { - if (got < 0 || strcmp (fle->file, ".") == 0 || - !gftp_match_filespec (fle->file, filespec)) - { - gftp_file_destroy (fle); - continue; - } - files = g_list_prepend (files, fle); - fle = g_malloc0 (sizeof (*fle)); - } - g_free (fle); + gftpui_common_run_callback_function (cdata); - if (files == NULL) + templist = cdata->files; + while (templist != NULL) { - gftp_end_transfer (request); - return (1); - } - - if (request == gftpui_common_local_request) - { - gftp_lookup_request_option (request, "local_sortcol", &sortcol); - gftp_lookup_request_option (request, "local_sortasds", &sortasds); - } - else - { - gftp_lookup_request_option (request, "remote_sortcol", &sortcol); - gftp_lookup_request_option (request, "remote_sortasds", &sortasds); - } - - files = gftp_sort_filelist (files, sortcol, sortasds); - delitem = NULL; - for (templist = files; templist != NULL; templist = templist->next) - { - if (delitem != NULL) - { - fle = delitem->data; - gftp_file_destroy (fle); - g_free (fle); - delitem = NULL; - } - fle = templist->data; gftpui_lookup_file_colors (fle, &startcolor, &endcolor); tempstr = gftp_gen_ls_string (fle, startcolor, endcolor); - request->logging_function (gftp_logging_misc_nolog, request, "%s\n", tempstr); - g_free (tempstr); - delitem = templist; + templist = templist->next; + gftp_file_destroy (fle); + g_free (fle); } - gftp_end_transfer (request); - if (delitem != NULL) - { - fle = delitem->data; - gftp_file_destroy (fle); - g_free (fle); - delitem = NULL; - } - - if (files != NULL) - g_list_free (files); + if (cdata->files != NULL) + g_list_free (cdata->files); + g_free (cdata); return (1); } diff -r 2ea37b3c0158 -r 60d3da6ab336 src/uicommon/gftpui.h --- a/src/uicommon/gftpui.h Mon Jan 05 23:38:22 2004 +0000 +++ b/src/uicommon/gftpui.h Tue Jan 06 01:44:09 2004 +0000 @@ -32,6 +32,7 @@ void *uidata; char *input_string, *source_string; + GList * files; int (*run_function) (gftpui_callback_data * cdata); }; @@ -100,6 +101,8 @@ int gftpui_common_run_chmod ( gftpui_callback_data * cdata ); +int gftpui_common_run_ls ( gftpui_callback_data * cdata ); + int gftpui_common_run_delete ( gftpui_callback_data * cdata ); int gftpui_common_run_rmdir ( gftpui_callback_data * cdata ); diff -r 2ea37b3c0158 -r 60d3da6ab336 src/uicommon/gftpuicallbacks.c --- a/src/uicommon/gftpuicallbacks.c Mon Jan 05 23:38:22 2004 +0000 +++ b/src/uicommon/gftpuicallbacks.c Tue Jan 06 01:44:09 2004 +0000 @@ -79,6 +79,70 @@ int +gftpui_common_run_ls (gftpui_callback_data * cdata) +{ + int got, matched_filespec, have_dotdot; + intptr_t sortcol, sortasds; + gftp_file * fle; + + if (gftp_list_files (cdata->request) != 0) + return (0); + + have_dotdot = 0; + cdata->request->gotbytes = 0; + cdata->files = NULL; + fle = g_malloc0 (sizeof (*fle)); + while ((got = gftp_get_next_file (cdata->request, NULL, fle)) > 0 || + got == GFTP_ERETRYABLE) + { + if (cdata->source_string == NULL) + matched_filespec = 1; + else + matched_filespec = gftp_match_filespec (fle->file, + cdata->source_string); + + if (got < 0 || strcmp (fle->file, ".") == 0 || !matched_filespec) + { + gftp_file_destroy (fle); + continue; + } + else if (strcmp (fle->file, "..") == 0) + have_dotdot = 1; + + cdata->request->gotbytes += got; + cdata->files = g_list_prepend (cdata->files, fle); + fle = g_malloc0 (sizeof (*fle)); + } + g_free (fle); + + gftp_end_transfer (cdata->request); + cdata->request->gotbytes = -1; + + if (!have_dotdot) + { + fle = g_malloc0 (sizeof (*fle)); + fle->file = g_strdup (".."); + fle->user = g_malloc0 (1); + fle->group = g_malloc0 (1); + fle->attribs = g_malloc0 (1); + *fle->attribs = '\0'; + fle->isdir = 1; + cdata->files = g_list_prepend (cdata->files, fle); + } + + if (cdata->files != NULL) + { + gftp_lookup_global_option ("local_sortcol", &sortcol); /* FIXME */ + gftp_lookup_global_option ("local_sortasds", &sortasds); + + cdata->files = gftp_sort_filelist (cdata->files, sortcol, sortasds); + } + + return (1); +} + + +int gftpui_common_run_delete (gftpui_callback_data * cdata) { int ret;