changeset 863:9f10d3c835cb

2006-11-30 Brian Masney <masneyb@gftp.org> * lib/options.h src/gtk/gftp-gtk.c - added new option: connect_to_remote_on_startup. If this is enabled, then the application will automatically connect to the remote server when it is started. (closes #330418)
author masneyb
date Sat, 23 Dec 2006 18:16:32 +0000
parents 885038cb945b
children c71bc7d32ce5
files ChangeLog lib/options.h src/gtk/gftp-gtk.c
diffstat 3 files changed, 66 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Dec 23 16:12:21 2006 +0000
+++ b/ChangeLog	Sat Dec 23 18:16:32 2006 +0000
@@ -1,4 +1,9 @@
 2006-11-30 Brian Masney <masneyb@gftp.org>
+	* lib/options.h src/gtk/gftp-gtk.c - added new option:
+	connect_to_remote_on_startup. If this is enabled, then the application
+	will automatically connect to the remote server when it is started.
+	(closes #330418)
+
 	* lib/gftp.h src/uicommon/gftpui.c - when a file transfer is restarted,
 	get the file size of the destination file. This is so that the file is 
 	restarted at the proper position (closes #160239). 
@@ -3753,7 +3758,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.506 2006/12/23 16:12:17 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.507 2006/12/23 18:16:31 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/options.h	Sat Dec 23 16:12:21 2006 +0000
+++ b/lib/options.h	Sat Dec 23 18:16:32 2006 +0000
@@ -112,6 +112,10 @@
    gftp_option_type_checkbox, GINT_TO_POINTER(0), NULL, 0,
    N_("Save the last local and remote directory when the application is closed"),
    GFTP_PORT_GTK, NULL},
+  {"connect_to_remote_on_startup", N_("Connect to remote server on startup"), 
+   gftp_option_type_checkbox, GINT_TO_POINTER(0), NULL, 0,
+   N_("Automatically connect to the remote server when the application is started."),
+   GFTP_PORT_GTK, NULL},
 
   {"", N_("Network"), gftp_option_type_notebook, NULL, NULL, 
    GFTP_CVARS_FLAGS_SHOW_BOOKMARK, NULL, GFTP_PORT_GTK, NULL},
--- a/src/gtk/gftp-gtk.c	Sat Dec 23 16:12:21 2006 +0000
+++ b/src/gtk/gftp-gtk.c	Sat Dec 23 18:16:32 2006 +0000
@@ -1072,16 +1072,13 @@
 }
 
 
-static void
-init_gftp (int argc, char *argv[], GtkWidget * parent)
+static int
+_get_selected_protocol ()
 {
-  if (argc == 2 && strncmp (argv[1], "--", 2) != 0)
-    {
-      if (gftp_parse_url (window2.request, argv[1]) == 0)
-	ftp_connect (&window2, window2.request);
-      else
-	gftp_usage ();
-    }
+  GtkWidget * tempwid;
+  
+  tempwid = gtk_menu_get_active (GTK_MENU (protocol_menu));
+  return (GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (tempwid))));
 }
 
 
@@ -1105,8 +1102,7 @@
   if (GFTP_IS_CONNECTED (current_wdata->request))
     gftp_disconnect (current_wdata->request);
 
-  tempwid = gtk_menu_get_active (GTK_MENU (protocol_menu));
-  num = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (tempwid)));
+  num = _get_selected_protocol ();
   init = gftp_protocols[num].init;
   if (init (current_wdata->request) < 0)
     return;
@@ -1301,6 +1297,53 @@
 }
 
 
+static void
+_setup_window1 ()
+{
+  if (gftp_protocols[GFTP_LOCAL_NUM].init (window1.request) == 0)
+    {
+      gftp_setup_startup_directory (window1.request,
+                                    "local_startup_directory");
+      gftp_connect (window1.request);
+      ftp_list_files (&window1);
+    }
+}
+
+
+static void
+_setup_window2 (int argc, char **argv)
+{
+  intptr_t connect_to_remote_on_startup;
+
+  gftp_lookup_request_option (window2.request, "connect_to_remote_on_startup",
+                              &connect_to_remote_on_startup);
+
+  if (argc == 2 && strncmp (argv[1], "--", 2) != 0)
+    {
+      if (gftp_parse_url (window2.request, argv[1]) == 0)
+        ftp_connect (&window2, window2.request);
+      else
+        gftp_usage ();
+    }
+  else if (connect_to_remote_on_startup)
+    {
+      if (gftp_protocols[_get_selected_protocol ()].init (current_wdata->request) == 0)
+        {
+          gftp_setup_startup_directory (window2.request,
+                                        "remote_startup_directory");
+          gftp_connect (window2.request);
+          ftp_list_files (&window2);
+        }
+    }
+  else
+    {
+      /* On the remote window, even though we aren't connected, draw the sort
+         icon on that side */
+      sortrows (GTK_CLIST (window2.listbox), -1, &window2);
+    }
+}
+
+
 int
 main (int argc, char **argv)
 {
@@ -1356,19 +1399,9 @@
   gftpui_common_about (ftp_log, NULL);
 
   gtk_timeout_add (1000, update_downloads, NULL);
-  if (gftp_protocols[GFTP_LOCAL_NUM].init (window1.request) == 0)
-    {
-      gftp_setup_startup_directory (window1.request,
-                                    "local_startup_directory");
-      gftp_connect (window1.request);
-      ftp_list_files (&window1);
-    }
 
-  /* On the remote window, even though we aren't connected, draw the sort
-     icon on that side */
-  sortrows (GTK_CLIST (window2.listbox), -1, &window2);
-
-  init_gftp (argc, argv, window);
+  _setup_window1 ();
+  _setup_window2 (argc, argv);
 
   GDK_THREADS_ENTER ();
   gtk_main ();