changeset 342:07d635081926

2003-12-28 Brian Masney <masneyb@gftp.org> * src/gtk/gtkui.c src/text/textui.c - necessary UI related files for each port of gftp. The uicommon code will call these functions.
author masneyb
date Sun, 28 Dec 2003 16:04:30 +0000
parents eedc2c5727fa
children 0417d2b4d9bb
files ChangeLog src/gtk/gtkui.c src/text/textui.c
diffstat 3 files changed, 340 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Dec 28 16:02:07 2003 +0000
+++ b/ChangeLog	Sun Dec 28 16:04:30 2003 +0000
@@ -1,5 +1,8 @@
 2003-12-28 Brian Masney <masneyb@gftp.org>
-
+	* src/gtk/gtkui.c src/text/textui.c - necessary UI related files for
+	each port of gftp. The uicommon code will call these functions.
+
+2003-12-28 Brian Masney <masneyb@gftp.org>
 	**** NOTE: this commit breaks a lot of functionality in gftp. I ****
 	**** still have more work to do on this. Please don't email me  ****
 	**** saying that the CVS code is broken.                        ****
@@ -1882,7 +1885,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.187 2003/12/28 16:01:57 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.188 2003/12/28 16:04:28 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gtk/gtkui.c	Sun Dec 28 16:04:30 2003 +0000
@@ -0,0 +1,276 @@
+/*****************************************************************************/
+/*  gtkui.c - GTK+ UI related functions for gFTP                             */
+/*  Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>                  */
+/*                                                                           */
+/*  This program is free software; you can redistribute it and/or modify     */
+/*  it under the terms of the GNU General Public License as published by     */
+/*  the Free Software Foundation; either version 2 of the License, or        */
+/*  (at your option) any later version.                                      */
+/*                                                                           */
+/*  This program is distributed in the hope that it will be useful,          */
+/*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
+/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
+/*  GNU General Public License for more details.                             */
+/*                                                                           */
+/*  You should have received a copy of the GNU General Public License        */
+/*  along with this program; if not, write to the Free Software              */
+/*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA      */
+/*****************************************************************************/
+
+#include "gftp-gtk.h"
+static const char cvsid[] = "$Id$";
+
+
+void
+gftpui_lookup_file_colors (gftp_file * fle, char **start_color,
+                           char ** end_color)
+{
+  *start_color = GFTPUI_COMMON_COLOR_NONE;
+  *end_color = GFTPUI_COMMON_COLOR_NONE;
+}
+
+
+void
+gftpui_run_command (GtkWidget * widget, gpointer data)
+{
+  const char *txt;
+
+  txt = gtk_entry_get_text (GTK_ENTRY (gftpui_command_widget));
+  gftpui_common_process_command (txt);
+  gtk_entry_set_text (GTK_ENTRY (gftpui_command_widget), "");
+}
+
+
+void
+gftpui_refresh (void *uidata)
+{
+  gftp_window_data * wdata;
+
+  wdata = uidata;
+  if (!check_status (_("Refresh"), wdata, 0, 0, 0, 1))
+    return;
+
+  if (check_reconnect (wdata) < 0)
+    return;
+
+  gtk_clist_freeze (GTK_CLIST (wdata->listbox));
+  remove_files_window (wdata);
+  gftp_delete_cache_entry (wdata->request, NULL, 0);
+  ftp_list_files (wdata, 0);
+  gtk_clist_thaw (GTK_CLIST (wdata->listbox));
+}
+
+
+void *
+gftpui_generic_thread (void * (*func) (void *), void *data)
+{
+  gftpui_callback_data * cdata;
+  gftp_window_data * wdata;
+  void * ret;
+
+  cdata = data;
+  wdata = cdata->uidata;
+
+  wdata->request->stopable = 1;
+  gtk_widget_set_sensitive (stop_btn, 1);
+  pthread_create (&wdata->tid, NULL, func, wdata);
+
+  while (wdata->request->stopable)
+    {
+      GDK_THREADS_LEAVE ();
+#if GTK_MAJOR_VERSION == 1
+      g_main_iteration (TRUE);
+#else
+      g_main_context_iteration (NULL, TRUE);
+#endif
+    }
+
+  pthread_join (wdata->tid, &ret);
+  gtk_widget_set_sensitive (stop_btn, 0);
+
+  if (!GFTP_IS_CONNECTED (wdata->request))
+    disconnect (wdata);
+
+  return (ret);
+}
+
+
+int
+gftpui_check_reconnect (gftpui_callback_data * cdata)
+{
+  gftp_window_data * wdata;
+
+  wdata = cdata->uidata;
+  return (wdata->request->cached && wdata->request->datafd < 0 &&
+          !wdata->request->always_connected &&
+          !ftp_connect (wdata, wdata->request, 0) ? -1 : 0);
+}
+
+
+void
+gftpui_run_function_callback (gftp_window_data * wdata,
+                              gftp_dialog_data * ddata)
+{
+  gftpui_callback_data * cdata;
+  const char *edttext;
+  int ret;
+
+  cdata = ddata->yespointer;
+  if (ddata->edit != NULL)
+    {
+      edttext = gtk_entry_get_text (GTK_ENTRY (ddata->edit));
+      if (*edttext == '\0')
+        {
+          ftp_log (gftp_logging_misc, NULL,
+                   _("Operation canceled...you must enter a string\n"));
+          return;
+        }
+
+      cdata->input_string = g_strdup (edttext);
+    }
+
+  ret = gftpui_common_run_callback_function (cdata);
+}
+
+
+void
+gftpui_run_function_cancel_callback (gftp_window_data * wdata,
+                                     gftp_dialog_data * ddata)
+{
+  gftpui_callback_data * cdata;
+
+  cdata = ddata->yespointer;
+  if (cdata->input_string != NULL)
+    g_free (cdata->input_string);
+  if (cdata->source_string != NULL)
+    g_free (cdata->source_string);
+  g_free (cdata);
+}
+
+
+void
+gftpui_mkdir_dialog (gpointer data)
+{
+  gftpui_callback_data * cdata;
+  gftp_window_data * wdata;
+
+  wdata = data;
+  cdata = g_malloc0 (sizeof (*cdata));
+  cdata->request = wdata->request;
+  cdata->uidata = wdata;
+  cdata->run_function = gftpui_common_run_mkdir;
+
+  if (!check_status (_("Mkdir"), wdata, gftpui_common_use_threads (wdata->request), 0, 0, wdata->request->mkdir != NULL))
+    return;
+
+  MakeEditDialog (_("Make Directory"), _("Enter name of directory to create"),
+                  NULL, 1, NULL, gftp_dialog_button_create,
+                  gftpui_run_function_callback, cdata,
+                  gftpui_run_function_cancel_callback, cdata);
+}
+
+
+void
+gftpui_rename_dialog (gpointer data)
+{
+  gftpui_callback_data * cdata;
+  GList *templist, *filelist;
+  gftp_window_data * wdata;
+  gftp_file * curfle;
+  char *tempstr;
+  int num;
+
+  wdata = data;
+  cdata = g_malloc0 (sizeof (*cdata));
+  cdata->request = wdata->request;
+  cdata->uidata = wdata;
+  cdata->run_function = gftpui_common_run_rename;
+
+  if (!check_status (_("Rename"), wdata, gftpui_common_use_threads (wdata->request), 1, 1, wdata->request->rename != NULL))
+    return;
+
+  templist = GTK_CLIST (wdata->listbox)->selection;
+  num = 0;
+  filelist = wdata->files;
+  templist = get_next_selection (templist, &filelist, &num);
+  curfle = filelist->data;
+  cdata->source_string = g_strdup (curfle->file);
+
+  tempstr = g_strdup_printf (_("What would you like to rename %s to?"),
+                             cdata->source_string);
+  MakeEditDialog (_("Rename"), tempstr, cdata->source_string, 1, NULL,
+                  gftp_dialog_button_rename,
+                  gftpui_run_function_callback, cdata,
+                  gftpui_run_function_cancel_callback, cdata);
+  g_free (tempstr);
+}
+
+
+void
+gftpui_site_dialog (gpointer data)
+{
+  gftpui_callback_data * cdata;
+  gftp_window_data * wdata;
+
+  wdata = data;
+  cdata = g_malloc0 (sizeof (*cdata));
+  cdata->request = wdata->request;
+  cdata->uidata = wdata;
+  cdata->run_function = gftpui_common_run_site;
+
+  if (!check_status (_("Site"), wdata, 0, 0, 0, wdata->request->site != NULL))
+    return;
+
+  MakeEditDialog (_("Site"), _("Enter site-specific command"), NULL, 1,
+                  NULL, gftp_dialog_button_ok,
+                  gftpui_run_function_callback, cdata,
+                  gftpui_run_function_cancel_callback, cdata);
+}
+
+
+int
+gftpui_run_chdir (gpointer uidata, char *directory)
+{
+  gftpui_callback_data * cdata;
+  gftp_window_data * wdata;
+  int ret;
+
+  wdata = uidata;
+  cdata = g_malloc0 (sizeof (*cdata));
+  cdata->request = wdata->request;
+  cdata->uidata = wdata;
+  cdata->run_function = gftpui_common_run_chdir;
+  cdata->input_string = directory;
+
+  ret = gftpui_common_run_callback_function (cdata);
+
+  g_free (cdata);
+  return (ret);
+}
+
+
+void
+gftpui_chdir_dialog (gpointer data)
+{
+  GList *templist, *filelist;
+  gftp_window_data * wdata;
+  gftp_file * curfle;
+  char *tempstr;
+  int num;
+
+  wdata = data;
+  if (!check_status (_("Chdir"), wdata, gftpui_common_use_threads (wdata->request), 1, 0,
+                     wdata->request->chdir != NULL))
+    return;
+
+  templist = GTK_CLIST (wdata->listbox)->selection;
+  num = 0;
+  filelist = wdata->files;
+  templist = get_next_selection (templist, &filelist, &num);
+  curfle = filelist->data;
+
+  tempstr = gftp_build_path (wdata->request->directory, curfle->file, NULL);
+  gftpui_run_chdir (wdata, tempstr);
+  g_free (tempstr);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/text/textui.c	Sun Dec 28 16:04:30 2003 +0000
@@ -0,0 +1,59 @@
+/*****************************************************************************/
+/*  textui.c - Text UI related functions for gFTP                            */
+/*  Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>                  */
+/*                                                                           */
+/*  This program is free software; you can redistribute it and/or modify     */
+/*  it under the terms of the GNU General Public License as published by     */
+/*  the Free Software Foundation; either version 2 of the License, or        */
+/*  (at your option) any later version.                                      */
+/*                                                                           */
+/*  This program is distributed in the hope that it will be useful,          */
+/*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
+/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
+/*  GNU General Public License for more details.                             */
+/*                                                                           */
+/*  You should have received a copy of the GNU General Public License        */
+/*  along with this program; if not, write to the Free Software              */
+/*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA      */
+/*****************************************************************************/
+
+#include "gftp-text.h"
+static const char cvsid[] = "$Id$";
+
+void
+gftpui_lookup_file_colors (gftp_file * fle, char **start_color,
+                           char ** end_color)
+{
+  if (*fle->attribs == 'd')
+    *start_color = GFTPUI_COMMON_COLOR_BLUE;
+  else if (*fle->attribs == 'l')
+    *start_color = GFTPUI_COMMON_COLOR_WHITE;
+  else if (strchr (fle->attribs, 'x') != NULL)
+    *start_color = GFTPUI_COMMON_COLOR_GREEN;
+  else
+    *start_color = GFTPUI_COMMON_COLOR_DEFAULT;
+
+  *end_color = GFTPUI_COMMON_COLOR_DEFAULT;
+}
+
+
+void
+gftpui_refresh (void *uidata)
+{
+  /* FIXME - clear the cache entry */
+}
+
+
+void *
+gftpui_generic_thread (void * (*func) (void *), void *data)
+{
+  return (NULL);
+}
+
+
+int
+gftpui_check_reconnect (gftpui_callback_data * cdata)
+{
+  return (1);
+}
+