]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
2003-07-30 Robert Collins <rbtcollins@hotmail.com>
authorRobert Collins <rbtcollins@hotmail.com>
Wed, 30 Jul 2003 09:04:27 +0000 (09:04 +0000)
committerRobert Collins <rbtcollins@hotmail.com>
Wed, 30 Jul 2003 09:04:27 +0000 (09:04 +0000)
* ConnectionSetting.cc: New file, persist connection type selection.
* ConnectionSetting.h: Ditto.
* net.cc: Hold a ConnectionSetting instance to trigger the logic.
(NetPage::OnInit): Don't force net_method to any value.
* Makefile.am: Add new source files.

ChangeLog
ConnectionSetting.cc [new file with mode: 0644]
ConnectionSetting.h [new file with mode: 0644]
Makefile.am
net.cc

index 1858341eaf3d6692125ed8ca356135bad749aa72..6a5e2c2488c4141e838d3e8d66a91a53113d3302 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-07-30  Robert Collins  <rbtcollins@hotmail.com>
+
+       * ConnectionSetting.cc: New file, persist connection type selection.
+       * ConnectionSetting.h: Ditto.
+       * net.cc: Hold a ConnectionSetting instance to trigger the logic.
+       (NetPage::OnInit): Don't force net_method to any value.
+       * Makefile.am: Add new source files.
+       
 2003-07-30  Robert Collins  <rbtcollins@hotmail.com>
 
        * SourceSetting.cc: New file, persist source selection.
diff --git a/ConnectionSetting.cc b/ConnectionSetting.cc
new file mode 100644 (file)
index 0000000..0f86b93
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2003, Robert Collins <rbtcollins@hotmail.com>
+ *
+ *     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.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ * Written by Robert Collins.
+ *
+ */
+
+#if 0
+static const char *cvsid =
+  "\n%%% $Id$\n";
+#endif
+
+#include "ConnectionSetting.h"
+#include "UserSettings.h"
+#include "io_stream.h"
+#include "state.h"
+#include "resource.h"
+#include "String++.h"
+
+void
+ConnectionSetting::load()
+{
+  static int inited = 0;
+  if (inited)
+    return;
+  io_stream *f = UserSettings::Instance().settingFileForLoad("last-connection");
+  if (f)
+    {
+      char localdir[1000];
+      char *fg_ret = f->gets (localdir, 1000);
+      delete f;
+      if (fg_ret)
+        net_method = typeFromString(fg_ret);
+    }
+  inited = 1;
+}
+
+void
+ConnectionSetting::save()
+{
+  
+  io_stream *f = UserSettings::Instance().settingFileForSave("last-connection");
+  if (f)
+    {
+      switch (net_method) {
+        case IDC_NET_DIRECT:
+            f->write("Direct\n",7);
+            break;
+        case IDC_NET_IE5:
+            f->write("IE\n",3);
+            break;
+        case IDC_NET_PROXY:
+            f->write("Proxy\n",6);
+            // TODO: also write the proxy and port, and then parse them in load.
+            break;
+        default:
+            break;
+      }
+      delete f;
+    }
+}
+
+int
+ConnectionSetting::typeFromString(String const & aType)
+{
+  if (!aType.casecompare("Direct"))
+    return IDC_NET_DIRECT;
+  if (!aType.casecompare("IE"))
+    return IDC_NET_IE5;
+  if (!aType.casecompare("Proxy"))
+    return IDC_NET_PROXY;
+
+  /* A sanish default */
+  return IDC_NET_IE5;
+}
diff --git a/ConnectionSetting.h b/ConnectionSetting.h
new file mode 100644 (file)
index 0000000..47e2310
--- /dev/null
@@ -0,0 +1,34 @@
+/*\r
+ * Copyright (c) 2003, Robert Collins <rbtcollins@hotmail.com>\r
+ *\r
+ *     This program is free software; you can redistribute it and/or modify\r
+ *     it under the terms of the GNU General Public License as published by\r
+ *     the Free Software Foundation; either version 2 of the License, or\r
+ *     (at your option) any later version.\r
+ *\r
+ *     A copy of the GNU General Public License can be found at\r
+ *     http://www.gnu.org/\r
+ *\r
+ * Written by Robert Collins.\r
+ *\r
+ */\r
+\r
+#ifndef SETUP_CONNECTIONSETTING_H\r
+#define SETUP_CONNECTIONSETTING_H\r
+\r
+// This is the header for the ConnectionSetting class, which persists and reads\r
+// in user settings to decide how setup should connect...\r
+\r
+#include "UserSetting.h"\r
+\r
+class String;\r
+class ConnectionSetting : public UserSetting \r
+{\r
+  public:\r
+    virtual void load();\r
+    virtual void save();\r
+  private:\r
+    int typeFromString(String const &aType);\r
+};\r
+\r
+#endif /* SETUP_CONNECTIONSETTING_H */\r
index e9b1efba6fdc78cc1f2ed6759722ab5bf23529dc..20cf69d823b66b9c2ff9c073277ce9eab9bf1668 100644 (file)
@@ -138,6 +138,8 @@ setup_SOURCES = \
        compress_bz.h \
        compress_gz.cc \
        compress_gz.h \
+       ConnectionSetting.cc \
+       ConnectionSetting.h \
        cygpackage.cc \
        cygpackage.h \
        desktop.cc \
diff --git a/net.cc b/net.cc
index 698726ce20d42748193dfb4ba17a376695bcf09a..84c7cea69b1676cad4fff8a17afada307f0ee8bf 100644 (file)
--- a/net.cc
+++ b/net.cc
-/*
- * Copyright (c) 2000, Red Hat, Inc.
- *
- *     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.
- *
- *     A copy of the GNU General Public License can be found at
- *     http://www.gnu.org/
- *
- * Written by DJ Delorie <dj@cygnus.com>
- *
- */
-
-/* The purpose of this file is to get the network configuration
-   information from the user. */
-
-#if 0
-static const char *cvsid =
-  "\n%%% $Id$\n";
-#endif
-
-#include "win32.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include "dialog.h"
-#include "resource.h"
-#include "state.h"
-#include "msg.h"
-#include "log.h"
-
-#include "net.h"
-#include "propsheet.h"
-#include "threebar.h"
-extern ThreeBarProgressPage Progress;
-
-static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };
-
-void
-NetPage::CheckIfEnableNext ()
-{
-  int e = 0, p = 0, pu = 0;
-  DWORD ButtonFlags = PSWIZB_BACK;
-
-  if (net_method == IDC_NET_IE5)
-    pu = 1;
-  if (net_method == IDC_NET_IE5 || net_method == IDC_NET_DIRECT)
-    e = 1;
-  else if (net_method == IDC_NET_PROXY)
-    {
-      p = pu = 1;
-      if (net_proxy_host && net_proxy_port)
-       e = 1;
-    }
-       if (e)
-       {
-               // There's something in the proxy and port boxes, enable "Next".
-               ButtonFlags |= PSWIZB_NEXT;
-       }
-
-  GetOwner ()->SetButtons (ButtonFlags);
-
-  EnableWindow (GetDlgItem (IDC_PROXY_HOST), p);
-  EnableWindow (GetDlgItem (IDC_PROXY_PORT), p);
-}
-
-static void
-load_dialog (HWND h)
-{
-  rbset (h, rb, net_method);
-  eset (h, IDC_PROXY_HOST, net_proxy_host);
-  if (net_proxy_port == 0)
-    net_proxy_port = 80;
-  eset (h, IDC_PROXY_PORT, net_proxy_port);
-}
-
-static void
-save_dialog (HWND h)
-{
-  net_method = rbget (h, rb);
-  net_proxy_host = eget (h, IDC_PROXY_HOST, net_proxy_host);
-  net_proxy_port = eget (h, IDC_PROXY_PORT);
-}
-
-bool
-NetPage::Create ()
-{
-  return PropertyPage::Create (IDD_NET);
-}
-
-void
-NetPage::OnInit ()
-{
-  HWND h = GetHWND ();
-
-  net_method = IDC_NET_DIRECT;
-  load_dialog (h);
-  CheckIfEnableNext();
-
-  // Check to see if any radio buttons are selected. If not, select a default.
-  if ((!SendMessage (GetDlgItem (IDC_NET_IE5), BM_GETCHECK, 0, 0) ==
-       BST_CHECKED)
-      && (!SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0)
-         == BST_CHECKED))
-    {
-      SendMessage (GetDlgItem (IDC_NET_DIRECT), BM_CLICK, 0, 0);
-    }
-}
-
-long
-NetPage::OnNext ()
-{
-  save_dialog (GetHWND ());
-
-  log (LOG_PLAIN, String ("net: ") +
-       ((net_method == IDC_NET_IE5) ? "IE5" :
-       (net_method == IDC_NET_DIRECT) ? "Direct" : "Proxy"));
-
-  Progress.SetActivateTask (WM_APP_START_SITE_INFO_DOWNLOAD);
-  return IDD_INSTATUS;
-}
-
-long
-NetPage::OnUnattended()
-{
-  return OnNext ();
-}
-
-long
-NetPage::OnBack ()
-{
-  save_dialog (GetHWND ());
-  return 0;
-}
-
-bool
-NetPage::OnMessageCmd (int id, HWND hwndctl, UINT code)
-{
-  switch (id)
-    {
-    case IDC_NET_IE5:
-    case IDC_NET_DIRECT:
-    case IDC_NET_PROXY:
-    case IDC_PROXY_HOST:
-    case IDC_PROXY_PORT:
-      save_dialog (GetHWND());
-      CheckIfEnableNext ();
-      break;
-
-    default:
-      // Wasn't recognized or handled.
-      return false;
-    }
-
-  // Was handled since we never got to default above.
-  return true;
-}
+/*\r
+ * Copyright (c) 2000, Red Hat, Inc.\r
+ *\r
+ *     This program is free software; you can redistribute it and/or modify\r
+ *     it under the terms of the GNU General Public License as published by\r
+ *     the Free Software Foundation; either version 2 of the License, or\r
+ *     (at your option) any later version.\r
+ *\r
+ *     A copy of the GNU General Public License can be found at\r
+ *     http://www.gnu.org/\r
+ *\r
+ * Written by DJ Delorie <dj@cygnus.com>\r
+ *\r
+ */\r
+\r
+/* The purpose of this file is to get the network configuration\r
+   information from the user. */\r
+\r
+#if 0\r
+static const char *cvsid =\r
+  "\n%%% $Id$\n";\r
+#endif\r
+\r
+#include "win32.h"\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "dialog.h"\r
+#include "resource.h"\r
+#include "state.h"\r
+#include "msg.h"\r
+#include "log.h"\r
+\r
+#include "net.h"\r
+#include "propsheet.h"\r
+#include "threebar.h"\r
+#include "ConnectionSetting.h"\r
+extern ThreeBarProgressPage Progress;\r
+\r
+static int rb[] = { IDC_NET_IE5, IDC_NET_DIRECT, IDC_NET_PROXY, 0 };\r
+static ConnectionSetting theSetting;\r
+\r
+void\r
+NetPage::CheckIfEnableNext ()\r
+{\r
+  int e = 0, p = 0, pu = 0;\r
+  DWORD ButtonFlags = PSWIZB_BACK;\r
+\r
+  if (net_method == IDC_NET_IE5)\r
+    pu = 1;\r
+  if (net_method == IDC_NET_IE5 || net_method == IDC_NET_DIRECT)\r
+    e = 1;\r
+  else if (net_method == IDC_NET_PROXY)\r
+    {\r
+      p = pu = 1;\r
+      if (net_proxy_host && net_proxy_port)\r
+       e = 1;\r
+    }\r
+       if (e)\r
+       {\r
+               // There's something in the proxy and port boxes, enable "Next".\r
+               ButtonFlags |= PSWIZB_NEXT;\r
+       }\r
+\r
+  GetOwner ()->SetButtons (ButtonFlags);\r
+\r
+  EnableWindow (GetDlgItem (IDC_PROXY_HOST), p);\r
+  EnableWindow (GetDlgItem (IDC_PROXY_PORT), p);\r
+}\r
+\r
+static void\r
+load_dialog (HWND h)\r
+{\r
+  rbset (h, rb, net_method);\r
+  eset (h, IDC_PROXY_HOST, net_proxy_host);\r
+  if (net_proxy_port == 0)\r
+    net_proxy_port = 80;\r
+  eset (h, IDC_PROXY_PORT, net_proxy_port);\r
+}\r
+\r
+static void\r
+save_dialog (HWND h)\r
+{\r
+  net_method = rbget (h, rb);\r
+  net_proxy_host = eget (h, IDC_PROXY_HOST, net_proxy_host);\r
+  net_proxy_port = eget (h, IDC_PROXY_PORT);\r
+}\r
+\r
+bool\r
+NetPage::Create ()\r
+{\r
+  return PropertyPage::Create (IDD_NET);\r
+}\r
+\r
+void\r
+NetPage::OnInit ()\r
+{\r
+  HWND h = GetHWND ();\r
+\r
+  if (!net_method)\r
+    net_method = IDC_NET_DIRECT;\r
+  load_dialog (h);\r
+  CheckIfEnableNext();\r
+\r
+  // Check to see if any radio buttons are selected. If not, select a default.\r
+  if ((!SendMessage (GetDlgItem (IDC_NET_IE5), BM_GETCHECK, 0, 0) ==\r
+       BST_CHECKED)\r
+      && (!SendMessage (GetDlgItem (IDC_NET_PROXY), BM_GETCHECK, 0, 0)\r
+         == BST_CHECKED))\r
+    {\r
+      SendMessage (GetDlgItem (IDC_NET_DIRECT), BM_CLICK, 0, 0);\r
+    }\r
+}\r
+\r
+long\r
+NetPage::OnNext ()\r
+{\r
+  save_dialog (GetHWND ());\r
+\r
+  log (LOG_PLAIN, String ("net: ") +\r
+       ((net_method == IDC_NET_IE5) ? "IE5" :\r
+       (net_method == IDC_NET_DIRECT) ? "Direct" : "Proxy"));\r
+\r
+  Progress.SetActivateTask (WM_APP_START_SITE_INFO_DOWNLOAD);\r
+  return IDD_INSTATUS;\r
+}\r
+\r
+long\r
+NetPage::OnUnattended()\r
+{\r
+  return OnNext ();\r
+}\r
+\r
+long\r
+NetPage::OnBack ()\r
+{\r
+  save_dialog (GetHWND ());\r
+  return 0;\r
+}\r
+\r
+bool\r
+NetPage::OnMessageCmd (int id, HWND hwndctl, UINT code)\r
+{\r
+  switch (id)\r
+    {\r
+    case IDC_NET_IE5:\r
+    case IDC_NET_DIRECT:\r
+    case IDC_NET_PROXY:\r
+    case IDC_PROXY_HOST:\r
+    case IDC_PROXY_PORT:\r
+      save_dialog (GetHWND());\r
+      CheckIfEnableNext ();\r
+      break;\r
+\r
+    default:\r
+      // Wasn't recognized or handled.\r
+      return false;\r
+    }\r
+\r
+  // Was handled since we never got to default above.\r
+  return true;\r
+}\r
This page took 0.050408 seconds and 5 git commands to generate.