# HG changeset patch # User masneyb # Date 1174012385 0 # Node ID 14476a8a4d2b66ea7ccbe8110f1c969e709ffa96 # Parent 331d6ad73a754817dee938911b7cb6bda8bffa73 2007-3-15 Brian Masney * src/gtk/transfer.c src/gtk/view_dialog.c - combined some duplicate code that was used to view and edit files. * lib/gftp.h src/gtk/transfer.c src/gtk/view_dialog.c src/uicommon/gftpui.c - removed is_fd member from the gftp_file structure. diff -r 331d6ad73a75 -r 14476a8a4d2b ChangeLog --- a/ChangeLog Fri Mar 16 01:23:46 2007 +0000 +++ b/ChangeLog Fri Mar 16 02:33:05 2007 +0000 @@ -1,4 +1,11 @@ 2007-3-15 Brian Masney + * src/gtk/transfer.c src/gtk/view_dialog.c - combined some duplicate + code that was used to view and edit files. + + * lib/gftp.h src/gtk/transfer.c src/gtk/view_dialog.c + src/uicommon/gftpui.c - removed is_fd member from the gftp_file + structure. + * lib/rfc959.c - added new function rfc959_setup_file_transfer(). It elimnates some duplicate code that was found by CPD. diff -r 331d6ad73a75 -r 14476a8a4d2b lib/gftp.h --- a/lib/gftp.h Fri Mar 16 01:23:46 2007 +0000 +++ b/lib/gftp.h Fri Mar 16 02:33:05 2007 +0000 @@ -257,7 +257,6 @@ done_rm : 1, /* Remove the file when done */ transfer_done : 1, /* Is current file transfer done? */ retry_transfer : 1, /* Is current file transfer done? */ - is_fd : 1, /* Is this a file descriptor? */ exists_other_side; /* The file exists on the other side during the file transfer */ char transfer_action; /* See the GFTP_TRANS_ACTION_* vars above */ diff -r 331d6ad73a75 -r 14476a8a4d2b src/gtk/transfer.c --- a/src/gtk/transfer.c Fri Mar 16 01:23:46 2007 +0000 +++ b/src/gtk/transfer.c Fri Mar 16 02:33:05 2007 +0000 @@ -404,7 +404,6 @@ if (ve_proc->pid != pid) continue; -printf ("Found pid %d in the linked list\n", pid); deldata = curdata; curdata = curdata->next; @@ -450,7 +449,6 @@ static void on_next_transfer (gftp_transfer * tdata) { - int fd; intptr_t refresh_files; gftp_file * tempfle; @@ -459,33 +457,12 @@ { tempfle = tdata->updfle->data; - if (tempfle->is_fd) - fd = tempfle->fd; - else - fd = 0; - - if (tempfle->done_view) + if (tempfle->done_view || tempfle->done_edit) { if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) - view_file (tempfle->destfile, fd, 1, tempfle->done_rm, 1, 0, - tempfle->file, NULL); - - if (tempfle->is_fd) { - close (tempfle->fd); - tempfle->fd = -1; - } - } - else if (tempfle->done_edit) - { - if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) - view_file (tempfle->destfile, fd, 0, tempfle->done_rm, 1, 0, - tempfle->file, NULL); - - if (tempfle->is_fd) - { - close (tempfle->fd); - tempfle->fd = -1; + view_file (tempfle->destfile, 0, tempfle->done_view, + tempfle->done_rm, 1, 0, tempfle->file, NULL); } } else if (tempfle->done_rm) diff -r 331d6ad73a75 -r 14476a8a4d2b src/gtk/view_dialog.c --- a/src/gtk/view_dialog.c Fri Mar 16 01:23:46 2007 +0000 +++ b/src/gtk/view_dialog.c Fri Mar 16 02:33:05 2007 +0000 @@ -22,19 +22,19 @@ static gftp_file * curfle; -void -view_dialog (gpointer data) +static void +do_view_or_edit_file (gftp_window_data * fromwdata, int is_view) { GList * templist, * filelist, * newfile; - gftp_window_data * fromwdata, * towdata; + gftp_window_data * towdata; gftp_file * new_fle; char *suffix; int num; - fromwdata = data; + if (!check_status (is_view ? _("View") : _("Edit"), fromwdata, 0, 1, 1, 1)) + return; + towdata = fromwdata == &window1 ? &window2 : &window1; - if (!check_status (_("View"), fromwdata, 0, 1, 1, 1)) - return; templist = GTK_CLIST (fromwdata->listbox)->selection; num = 0; @@ -44,13 +44,18 @@ if (S_ISDIR (curfle->st_mode)) { - ftp_log (gftp_logging_error, NULL, - _("View: %s is a directory. Cannot view it.\n"), curfle->file); + if (is_view) + ftp_log (gftp_logging_error, NULL, + _("View: %s is a directory. Cannot view it.\n"), curfle->file); + else + ftp_log (gftp_logging_error, NULL, + _("Edit: %s is a directory. Cannot edit it.\n"), curfle->file); + return; } if (strcmp (gftp_protocols[fromwdata->request->protonum].name, "Local") == 0) - view_file (curfle->file, 0, 1, 0, 1, 1, NULL, fromwdata); + view_file (curfle->file, 0, is_view, 0, 1, 1, NULL, fromwdata); else { new_fle = copy_fdata (curfle); @@ -81,9 +86,14 @@ fchmod (new_fle->fd, S_IRUSR | S_IWUSR); - new_fle->is_fd = 1; - new_fle->done_view = 1; - new_fle->done_rm = 1; + if (is_view) + { + new_fle->done_view = 1; + new_fle->done_rm = 1; + } + else + new_fle->done_edit = 1; + newfile = g_list_append (NULL, new_fle); gftpui_common_add_file_transfer (fromwdata->request, towdata->request, fromwdata, towdata, newfile); @@ -92,18 +102,17 @@ void +view_dialog (gpointer data) +{ + do_view_or_edit_file (data, 1); +} + + +void edit_dialog (gpointer data) { - gftp_window_data * fromwdata, * towdata; - GList * templist, * filelist, * newfile; - gftp_file * new_fle; - char *edit_program, *suffix; - int num; - - fromwdata = data; - towdata = fromwdata == &window1 ? &window2 : &window1; - if (!check_status (_("Edit"), fromwdata, 0, 1, 1, 1)) - return; + gftp_window_data * fromwdata = data; + char *edit_program; gftp_lookup_request_option (fromwdata->request, "edit_program", &edit_program); @@ -115,57 +124,7 @@ return; } - templist = GTK_CLIST (fromwdata->listbox)->selection; - num = 0; - filelist = fromwdata->files; - templist = get_next_selection (templist, &filelist, &num); - curfle = filelist->data; - - if (S_ISDIR (curfle->st_mode)) - { - ftp_log (gftp_logging_error, NULL, - _("Edit: %s is a directory. Cannot edit it.\n"), curfle->file); - return; - } - - if (strcmp (gftp_protocols[fromwdata->request->protonum].name, "Local") == 0) - view_file (curfle->file, 0, 0, 0, 1, 1, NULL, fromwdata); - else - { - new_fle = copy_fdata (curfle); - if (new_fle->destfile) - g_free (new_fle->destfile); - - if ((suffix = strrchr (curfle->file, '.')) != NULL) - { - new_fle->destfile = g_strconcat (g_get_tmp_dir (), - "/gftp-view.XXXXXX", suffix, NULL); - new_fle->fd = mkstemps (new_fle->destfile, strlen (suffix)); - } - else - { - new_fle->destfile = g_strconcat (g_get_tmp_dir (), - "/gftp-view.XXXXXX", NULL); - new_fle->fd = mkstemps (new_fle->destfile, 0); - } - - if (new_fle->fd < 0) - { - ftp_log (gftp_logging_error, NULL, - _("Error: Cannot open %s for writing: %s\n"), - new_fle->destfile, g_strerror (errno)); - gftp_file_destroy (new_fle, 1); - return; - } - - fchmod (new_fle->fd, S_IRUSR | S_IWUSR); - - new_fle->is_fd = 1; - new_fle->done_edit = 1; - newfile = g_list_append (NULL, new_fle); - gftpui_common_add_file_transfer (fromwdata->request, towdata->request, - fromwdata, towdata, newfile); - } + do_view_or_edit_file (data, 0); } diff -r 331d6ad73a75 -r 14476a8a4d2b src/uicommon/gftpui.c --- a/src/uicommon/gftpui.c Fri Mar 16 01:23:46 2007 +0000 +++ b/src/uicommon/gftpui.c Fri Mar 16 02:33:05 2007 +0000 @@ -1225,36 +1225,6 @@ } -static void -_gftpui_common_setup_fds (gftp_transfer * tdata, gftp_file * curfle, - int *fromfd, int *tofd) -{ - *tofd = -1; - *fromfd = -1; - - if (curfle->is_fd) - { - if (tdata->toreq->protonum == GFTP_LOCAL_NUM) - *tofd = curfle->fd; - else if (tdata->fromreq->protonum == GFTP_LOCAL_NUM) - *fromfd = curfle->fd; - } -} - - -static void -_gftpui_common_done_with_fds (gftp_transfer * tdata, gftp_file * curfle) -{ - if (curfle->is_fd) - { - if (tdata->toreq->protonum == GFTP_LOCAL_NUM) - tdata->toreq->datafd = -1; - else - tdata->fromreq->datafd = -1; - } -} - - static ssize_t _do_transfer_block (gftp_transfer * tdata, gftp_file * curfle, char *buf, size_t trans_blksize) @@ -1451,8 +1421,8 @@ static int _gftpui_common_trans_file_or_dir (gftp_transfer * tdata) { - int tofd, fromfd, ret; gftp_file * curfle; + int ret; if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); @@ -1482,8 +1452,6 @@ } else { - _gftpui_common_setup_fds (tdata, curfle, &fromfd, &tofd); - if (curfle->size == 0) { curfle->size = gftp_get_file_size (tdata->fromreq, curfle->file); @@ -1502,10 +1470,10 @@ } tdata->tot_file_trans = gftp_transfer_file (tdata->fromreq, curfle->file, - fromfd, + 0, curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0, - tdata->toreq, curfle->destfile, tofd, + tdata->toreq, curfle->destfile, 0, curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0); if (tdata->tot_file_trans < 0) @@ -1524,15 +1492,10 @@ ret = _gftpui_common_do_transfer_file (tdata, curfle); } - - _gftpui_common_done_with_fds (tdata, curfle); } if (ret == 0) - { - if (!curfle->is_fd) - ret = _gftpui_common_preserve_perm_time (tdata, curfle); - } + ret = _gftpui_common_preserve_perm_time (tdata, curfle); else { curfle->retry_transfer = 1;