This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[PATCH setup v3 3/6] Create new page UserSitePage for user URLs
- From: Ken Brown <kbrown at cornell dot edu>
- To: cygwin-apps at cygwin dot com
- Date: Wed, 6 Dec 2017 15:45:56 -0500
- Subject: [PATCH setup v3 3/6] Create new page UserSitePage for user URLs
- Authentication-results: sourceware.org; auth=none
- References: <20171206204559.4756-1-kbrown@cornell.edu>
This is done in two new files, usersite.h and usersite.cc, based on
site.h and site.cc. The new page is activated after the mirror
selection page if IDC_ALLOW_USER_URL is checked.
---
Makefile.am | 2 +
main.cc | 4 +
res.rc | 25 +++++++
resource.h | 2 +
site.cc | 24 +++---
usersite.cc | 242 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
usersite.h | 43 +++++++++++
7 files changed, 329 insertions(+), 13 deletions(-)
create mode 100644 usersite.cc
create mode 100644 usersite.h
diff --git a/Makefile.am b/Makefile.am
index a238d88..a0b0450 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -258,6 +258,8 @@ inilint_SOURCES = \
threebar.h \
UserSettings.cc \
UserSettings.h \
+ usersite.cc \
+ usersite.h \
win32.cc \
win32.h \
window.cc \
diff --git a/main.cc b/main.cc
index b44f9b6..a01fb43 100644
--- a/main.cc
+++ b/main.cc
@@ -53,6 +53,7 @@
#include "localdir.h"
#include "net.h"
#include "site.h"
+#include "usersite.h"
#include "choose.h"
#include "prereq.h"
#include "threebar.h"
@@ -133,6 +134,7 @@ main_display ()
LocalDirPage LocalDir;
NetPage Net;
SitePage Site;
+ UserSitePage UserSite;
ChooserPage Chooser;
PrereqPage Prereq;
DesktopSetupPage Desktop;
@@ -173,6 +175,7 @@ main_display ()
LocalDir.Create ();
Net.Create ();
Site.Create ();
+ UserSite.Create ();
Chooser.Create ();
Prereq.Create ();
Progress.Create ();
@@ -187,6 +190,7 @@ main_display ()
MainWindow.AddPage (&LocalDir);
MainWindow.AddPage (&Net);
MainWindow.AddPage (&Site);
+ MainWindow.AddPage (&UserSite);
MainWindow.AddPage (&Chooser);
MainWindow.AddPage (&Prereq);
MainWindow.AddPage (&Progress);
diff --git a/res.rc b/res.rc
index ffc4722..d982e9d 100644
--- a/res.rc
+++ b/res.rc
@@ -150,6 +150,31 @@ BEGIN
IDC_ALLOW_USER_URL,"Button",BS_AUTOCHECKBOX,15,162,350,8
END
+IDD_USERSITE DIALOG DISCARDABLE 0, 0, SETUP_STANDARD_DIALOG_DIMS
+STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_CHILD | WS_VISIBLE |
+ WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_CONTROLPARENT
+CAPTION "Cygwin Setup - Choose Additional Download Site(s)"
+FONT 8, "MS Shell Dlg"
+BEGIN
+ ICON IDI_CYGWIN,IDC_HEADICON,SETUP_HEADICON_X,0,21,20
+ LISTBOX IDC_USER_URL_LIST,66,45,185,110,LBS_NOINTEGRALHEIGHT |
+ LBS_EXTENDEDSEL | WS_VSCROLL | WS_HSCROLL | WS_GROUP |
+ WS_TABSTOP
+ LTEXT "Known Download Sites:",IDC_STATIC,66,34,183,8,NOT
+ WS_GROUP
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ SETUP_STANDARD_DIALOG_W,1
+ LTEXT "Choose a site from this list, or add additional sites to the list",
+ IDC_STATIC,21,9,239,16,NOT WS_GROUP
+ LTEXT "Choose A Download Site",IDC_STATIC_HEADER_TITLE,7,0,258,
+ 8,NOT WS_GROUP
+ EDITTEXT IDC_EDIT_USER_URL,65,160,185,14,ES_AUTOHSCROLL |
+ WS_GROUP
+ LTEXT "User URL:",IDC_SITE_USERURL,15,162,45,8,NOT WS_GROUP
+ PUSHBUTTON "Add",IDC_BUTTON_ADD_URL,255,160,50,14
+END
+
IDD_NET DIALOG DISCARDABLE 0, 0, SETUP_STANDARD_DIALOG_DIMS
STYLE DS_MODALFRAME | DS_CENTER | WS_CHILD | WS_CAPTION | WS_SYSMENU
CAPTION "Cygwin Setup - Select Connection Type"
diff --git a/resource.h b/resource.h
index d111853..27449f9 100644
--- a/resource.h
+++ b/resource.h
@@ -67,6 +67,7 @@
#define IDD_POSTINSTALL 222
#define IDD_FILE_INUSE 223
#define IDD_DOWNLOAD_ERROR 224
+#define IDD_USERSITE 225
// Bitmaps
@@ -178,3 +179,4 @@
#define IDC_NET_DIRECT_LEGACY 593
#define IDC_DOWNLOAD_EDIT 594
#define IDC_ALLOW_USER_URL 595
+#define IDC_USER_URL_LIST 596
diff --git a/site.cc b/site.cc
index 85ae70c..accc264 100644
--- a/site.cc
+++ b/site.cc
@@ -642,10 +642,10 @@ SitePage::OnNext ()
n != selected_mirror_list.end (); ++n)
Log (LOG_PLAIN) << "site: " << n->url << endLog;
+ if (allow_user_url)
+ return IDD_USERSITE;
Progress.SetActivateTask (WM_APP_START_SETUP_INI_DOWNLOAD);
return IDD_INSTATUS;
-
- return 0;
}
long
@@ -662,12 +662,9 @@ SitePage::OnBack ()
void
SitePage::OnActivate ()
{
- // Fill the list box with all known sites.
+ // Fill the list box with all known mirrors.
PopulateListBox ();
- // Load the user URL box with nothing - it is in the list already.
- eset (GetHWND (), IDC_EDIT_USER_URL, "");
-
// Get the enabled/disabled states of the controls set accordingly.
CheckControlsAndDisableAccordingly ();
}
@@ -675,7 +672,8 @@ SitePage::OnActivate ()
long
SitePage::OnUnattended ()
{
- if (SendMessage (GetDlgItem (IDC_URL_LIST), LB_GETSELCOUNT, 0, 0) > 0)
+ if (allow_user_url
+ || SendMessage (GetDlgItem (IDC_URL_LIST), LB_GETSELCOUNT, 0, 0) > 0)
return OnNext ();
else
return -2;
@@ -686,12 +684,11 @@ SitePage::CheckControlsAndDisableAccordingly () const
{
DWORD ButtonFlags = PSWIZB_BACK;
- // Check that at least one download site is selected.
- if (SendMessage (GetDlgItem (IDC_URL_LIST), LB_GETSELCOUNT, 0, 0) > 0)
- {
- // At least one site selected, enable "Next".
- ButtonFlags |= PSWIZB_NEXT;
- }
+ // Enable Next if at least one mirror is selected or if we'll be
+ // going to the user URL page.
+ if (allow_user_url
+ || SendMessage (GetDlgItem (IDC_URL_LIST), LB_GETSELCOUNT, 0, 0) > 0)
+ ButtonFlags |= PSWIZB_NEXT;
GetOwner ()->SetButtons (ButtonFlags);
}
@@ -752,6 +749,7 @@ bool SitePage::OnMessageCmd (int id, HWND hwndctl, UINT code)
selected_usersite_list.clear ();
site_list = selected_mirror_list;
}
+ CheckControlsAndDisableAccordingly ();
}
break;
}
diff --git a/usersite.cc b/usersite.cc
new file mode 100644
index 0000000..34fc097
--- /dev/null
+++ b/usersite.cc
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2017, Ken Brown
+ *
+ * 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/
+ *
+ * Based on site.cc, written by DJ Delorie <dj@cygnus.com>
+ *
+ */
+
+/* The purpose of this file is to let the user choose download sites
+ that are not cygwin.com mirrors. */
+
+#include <string>
+#include <algorithm>
+
+#include "usersite.h"
+#include "site.h"
+#include "win32.h"
+#include "dialog.h"
+#include "resource.h"
+#include "state.h"
+#include "LogSingleton.h"
+#include "io_stream.h"
+#include "propsheet.h"
+#include "threebar.h"
+#include "ControlAdjuster.h"
+
+using namespace std;
+
+extern ThreeBarProgressPage Progress;
+
+/*
+ Sizing information.
+ */
+static ControlAdjuster::ControlInfo UserSiteControlsInfo[] = {
+ {IDC_USER_URL_LIST, CP_STRETCH, CP_STRETCH},
+ {IDC_EDIT_USER_URL, CP_STRETCH, CP_BOTTOM},
+ {IDC_BUTTON_ADD_URL, CP_RIGHT, CP_BOTTOM},
+ {IDC_SITE_USERURL, CP_LEFT, CP_BOTTOM},
+ {0, CP_LEFT, CP_TOP}
+};
+
+UserSitePage::UserSitePage ()
+{
+ sizeProcessor.AddControlInfo (UserSiteControlsInfo);
+}
+
+using namespace std;
+
+/* Defined in site.cc */
+extern SiteList all_usersite_list;
+extern SiteList site_list;
+extern SiteList selected_mirror_list;
+extern SiteList selected_usersite_list;
+
+static void
+save_dialog (HWND h)
+{
+ // Remove anything that was previously in the selected usersite list.
+ selected_usersite_list.clear ();
+
+ HWND listbox = GetDlgItem (h, IDC_USER_URL_LIST);
+ int sel_count = SendMessage (listbox, LB_GETSELCOUNT, 0, 0);
+ if (sel_count > 0)
+ {
+ int sel_buffer[sel_count];
+ SendMessage (listbox, LB_GETSELITEMS, sel_count, (LPARAM) sel_buffer);
+ for (int n = 0; n < sel_count; n++)
+ {
+ int mirror =
+ SendMessage (listbox, LB_GETITEMDATA, sel_buffer[n], 0);
+ selected_usersite_list.push_back (all_usersite_list[mirror]);
+ }
+ }
+ site_list = selected_mirror_list;
+ site_list.insert (site_list.end (), selected_usersite_list.begin (),
+ selected_usersite_list.end ());
+}
+
+bool UserSitePage::Create ()
+{
+ return PropertyPage::Create (IDD_USERSITE);
+}
+
+long
+UserSitePage::OnNext ()
+{
+ HWND h = GetHWND ();
+
+ save_dialog (h);
+
+ // Log all the selected URLs from the list.
+ for (SiteList::const_iterator n = selected_usersite_list.begin ();
+ n != selected_usersite_list.end (); ++n)
+ Log (LOG_PLAIN) << "site: " << n->url << endLog;
+
+ Progress.SetActivateTask (WM_APP_START_SETUP_INI_DOWNLOAD);
+ return IDD_INSTATUS;
+}
+
+long
+UserSitePage::OnBack ()
+{
+ HWND h = GetHWND ();
+
+ save_dialog (h);
+
+ // Go back to the mirror selection page
+ return 0;
+}
+
+void
+UserSitePage::OnActivate ()
+{
+ // Fill the list box with all known sites.
+ PopulateListBox ();
+
+ // Load the user URL box with nothing - it is in the list already.
+ eset (GetHWND (), IDC_EDIT_USER_URL, "");
+
+ // Get the enabled/disabled states of the controls set accordingly.
+ CheckControlsAndDisableAccordingly ();
+}
+
+long
+UserSitePage::OnUnattended ()
+{
+ if (site_list.size ())
+ return OnNext ();
+ else
+ return -2;
+}
+
+void
+UserSitePage::CheckControlsAndDisableAccordingly () const
+{
+ DWORD ButtonFlags = PSWIZB_BACK;
+
+ // Enable Next if at least one download site is selected.
+ if (selected_mirror_list.size ()
+ || SendMessage (GetDlgItem (IDC_USER_URL_LIST), LB_GETSELCOUNT, 0, 0) > 0)
+ ButtonFlags |= PSWIZB_NEXT;
+ GetOwner ()->SetButtons (ButtonFlags);
+}
+
+void
+UserSitePage::PopulateListBox ()
+{
+ int j;
+ HWND listbox = GetDlgItem (IDC_USER_URL_LIST);
+
+ // Populate the list box with the URLs.
+ SendMessage (listbox, LB_RESETCONTENT, 0, 0);
+ for (SiteList::const_iterator i = all_usersite_list.begin ();
+ i != all_usersite_list.end (); ++i)
+ {
+ j = SendMessage (listbox, LB_ADDSTRING, 0,
+ (LPARAM) i->displayed_url.c_str());
+ SendMessage (listbox, LB_SETITEMDATA, j, j);
+ }
+
+ // Select the selected ones.
+ for (SiteList::const_iterator n = selected_usersite_list.begin ();
+ n != selected_usersite_list.end (); ++n)
+ {
+ SiteList::iterator i = find (all_usersite_list.begin(),
+ all_usersite_list.end(), *n);
+ if (i != all_usersite_list.end())
+ {
+ int index = i - all_usersite_list.begin();
+
+ // Highlight the selected item
+ SendMessage (listbox, LB_SELITEMRANGE, TRUE, (index << 16) | index);
+ // Make sure it's fully visible
+ SendMessage (listbox, LB_SETCARETINDEX, index, FALSE);
+ }
+ }
+}
+
+bool UserSitePage::OnMessageCmd (int id, HWND hwndctl, UINT code)
+{
+ switch (id)
+ {
+ case IDC_EDIT_USER_URL:
+ {
+ // Set the default pushbutton to ADD if the user is entering text.
+ if (code == EN_CHANGE)
+ SendMessage (GetHWND (), DM_SETDEFID, (WPARAM) IDC_BUTTON_ADD_URL, 0);
+ break;
+ }
+ case IDC_USER_URL_LIST:
+ {
+ if (code == LBN_SELCHANGE)
+ {
+ CheckControlsAndDisableAccordingly ();
+ save_dialog (GetHWND ());
+ }
+ break;
+ }
+ case IDC_BUTTON_ADD_URL:
+ {
+ if (code == BN_CLICKED)
+ {
+ // User pushed the Add button.
+ std::string other_url = egetString (GetHWND (), IDC_EDIT_USER_URL);
+ if (other_url.size())
+ {
+ site_list_type newsite (other_url, "", "", "", false);
+ SiteList::iterator i = find (all_usersite_list.begin(),
+ all_usersite_list.end(), newsite);
+ if (i == all_usersite_list.end())
+ {
+ all_usersite_list.push_back (newsite);
+ Log (LOG_BABBLE) << "Adding site: " << other_url << endLog;
+ selected_usersite_list.push_back (newsite);
+ }
+ else
+ selected_usersite_list.push_back (*i);
+
+ // Update the list box.
+ PopulateListBox ();
+ // And allow the user to continue
+ CheckControlsAndDisableAccordingly ();
+ eset (GetHWND (), IDC_EDIT_USER_URL, "");
+ }
+ }
+ break;
+ }
+ default:
+ // Wasn't recognized or handled.
+ return false;
+ }
+
+ // Was handled since we never got to default above.
+ return true;
+}
diff --git a/usersite.h b/usersite.h
new file mode 100644
index 0000000..842a0b0
--- /dev/null
+++ b/usersite.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, Ken Brown
+ *
+ * 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/
+ *
+ * Based on site.h, written by Robert Collins <rbtcollins@hotmail.com>
+ *
+ */
+
+#ifndef SETUP_USERSITE_H
+#define SETUP_USERSITE_H
+
+#include "proppage.h"
+
+// For user URLs that are not mirrors of cygwin.com.
+class UserSitePage : public PropertyPage
+{
+public:
+ UserSitePage ();
+ virtual ~ UserSitePage ()
+ {
+ };
+
+ bool Create ();
+
+ virtual void OnActivate ();
+ virtual long OnNext ();
+ virtual long OnBack ();
+ virtual long OnUnattended ();
+
+ virtual bool OnMessageCmd (int id, HWND hwndctl, UINT code);
+
+ void PopulateListBox();
+ void CheckControlsAndDisableAccordingly () const;
+};
+
+#endif /* SETUP_USERSITE_H */
--
2.15.1