From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id DB3E3385AE6D; Fri, 24 Jun 2022 11:27:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB3E3385AE6D To: cygwin-apps-cvs@sourceware.org Subject: [setup - the official Cygwin setup program] branch master, updated. release_2.918-19-gdd645a18 X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 212135acf1be102c98760d7dbeb7cc92ef998a71 X-Git-Newrev: dd645a18ed1cca21a6554b3fb955a9b21040d6ea Message-Id: <20220624112734.DB3E3385AE6D@sourceware.org> Date: Fri, 24 Jun 2022 11:27:34 +0000 (GMT) From: Jon TURNEY X-BeenThere: cygwin-apps-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin-apps git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2022 11:27:35 -0000 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=dd645a18ed1cca21a6554b3fb955a9b21040d6ea commit dd645a18ed1cca21a6554b3fb955a9b21040d6ea Author: Jon Turney Date: Fri Jun 17 15:51:15 2022 +0100 De-clutter the mirror selection listbox Mirrors can now appear up to three times in this list (with ftp://, http:// and https:// protocols). We can't just stop announcing ftp:// and http:// sites in the mirror list, as that will lead to setup warning that those mirrors have been dropped and may be out of date. So instead: Process site list for an optional 4th semi-colon delimited string, to be used for flags. Recognize and store 'noshow' flag. Hide mirror URLs with this noshow flag from the mirror selection listbox, unless they have been already selected in a previous run. We will use this to hide ftp://, and http:// (where https: also exists) URLs. This assumes that: (i) all future mirrors will provide http:// service and (ii) nobody has a good reason for using ftp:// instead of http:// anymore. But those seem reasonable assumptions! Also: drop explicit copy constructor and assignment operator for site_list_type, which just do what the default would. Diff: --- site.cc | 125 +++++++++++++++++++++++++++++----------------------------------- site.h | 6 ++-- 2 files changed, 59 insertions(+), 72 deletions(-) diff --git a/site.cc b/site.cc index 33c06f01..91bf4723 100644 --- a/site.cc +++ b/site.cc @@ -141,13 +141,15 @@ site_list_type::site_list_type (const std::string &_url, const std::string &_servername, const std::string &_area, const std::string &_location, - bool _from_mirrors_lst) + bool _from_mirrors_lst, + bool _noshow = false) { url = _url; servername = _servername; area = _area; location = _location; from_mirrors_lst = _from_mirrors_lst; + noshow = _noshow; /* Canonicalize URL to ensure it ends with a '/' */ if (url.at(url.length()-1) != '/') @@ -179,30 +181,6 @@ site_list_type::site_list_type (const std::string &_url, key += url; } -site_list_type::site_list_type (site_list_type const &rhs) -{ - key = rhs.key; - url = rhs.url; - servername = rhs.servername; - area = rhs.area; - location = rhs.location; - from_mirrors_lst = rhs.from_mirrors_lst; - displayed_url = rhs.displayed_url; -} - -site_list_type & -site_list_type::operator= (site_list_type const &rhs) -{ - key = rhs.key; - url = rhs.url; - servername = rhs.servername; - area = rhs.area; - location = rhs.location; - from_mirrors_lst = rhs.from_mirrors_lst; - displayed_url = rhs.displayed_url; - return *this; -} - bool site_list_type::operator == (site_list_type const &rhs) const { @@ -285,35 +263,34 @@ load_site_list (SiteList& theSites, char *theString) strncmp(bol, "https://", 8) == 0 || strncmp(bol, "ftp://", 6) == 0 || strncmp(bol, "ftps://", 7) == 0) - { - char *semi = strchr (bol, ';'); - char *semi2 = NULL; - char *semi3 = NULL; - if (semi) - { - *semi = 0; - semi++; - semi2 = strchr (semi, ';'); - if (semi2) - { - *semi2 = 0; - semi2++; - semi3 = strchr (semi2, ';'); - if (semi3) - { - *semi3 = 0; - semi3++; - } - } - } + { + int i; + char *semi[4]; - /* Ignore malformed lines */ - if (!semi || !semi2 || !semi3) - continue; + /* split into up to 4 semicolon-delimited parts */ + for (i = 0; i < 4; i++) + semi[i] = 0; - site_list_type newsite (bol, semi, semi2, semi3, true); - site_list_insert (theSites, newsite); - } + char *p = bol; + for (i = 0; i < 4; i++) + { + semi[i] = strchr (p, ';'); + if (!semi[i]) + break; + + *semi[i] = 0; + p = ++semi[i]; + } + + /* Ignore malformed lines */ + if (!semi[0] || !semi[1] || !semi[2]) + continue; + + bool noshow = semi[3] && (strncmp(semi[3], "noshow", 6) == 0); + + site_list_type newsite (bol, semi[0], semi[1], semi[2], true, noshow); + site_list_insert (theSites, newsite); + } else { Log (LOG_BABBLE) << "Discarding line '" << bol << "' due to unknown protocol" << endLog; @@ -668,7 +645,7 @@ SitePage::CheckControlsAndDisableAccordingly () const void SitePage::PopulateListBox () { - int j; + std::vector sel_indicies; HWND listbox = GetDlgItem (IDC_URL_LIST); // Populate the list box with the URLs. @@ -676,26 +653,36 @@ SitePage::PopulateListBox () for (SiteList::const_iterator i = all_site_list.begin (); i != all_site_list.end (); ++i) { - j = SendMessage (listbox, LB_ADDSTRING, 0, - (LPARAM) i->displayed_url.c_str()); - SendMessage (listbox, LB_SETITEMDATA, j, j); + // If selected, always show + SiteList::iterator f = find (site_list.begin(), site_list.end(), *i); + if (f == site_list.end()) + { + // Otherwise, hide redundant legacy URLs: + if (i->noshow) + continue; + } + + int j = SendMessage (listbox, LB_ADDSTRING, 0, + (LPARAM) i->displayed_url.c_str()); + // Set the ListBox item data to the index into all_site_list + SendMessage (listbox, LB_SETITEMDATA, j, (i - all_site_list.begin())); + + // For every selected item, remember the index + if (f != site_list.end()) + { + sel_indicies.push_back(j); + } } // Select the selected ones. - for (SiteList::const_iterator n = site_list.begin (); - n != site_list.end (); ++n) + for (std::vector ::const_iterator n = sel_indicies.begin (); + n != sel_indicies.end (); ++n) { - SiteList::iterator i = find (all_site_list.begin(), - all_site_list.end(), *n); - if (i != all_site_list.end()) - { - int index = i - all_site_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); - } + int index = *n; + // Highlight the selected item + SendMessage (listbox, LB_SELITEMRANGE, TRUE, (index << 16) | index); + // Make sure it's fully visible + SendMessage (listbox, LB_SETCARETINDEX, index, FALSE); } } diff --git a/site.h b/site.h index d16db8e6..69265f23 100644 --- a/site.h +++ b/site.h @@ -48,11 +48,9 @@ class site_list_type { public: site_list_type () : url (), displayed_url (), key () {}; - site_list_type (const site_list_type &); site_list_type (const std::string& , const std::string& , - const std::string& , const std::string&, bool); + const std::string& , const std::string&, bool, bool); ~site_list_type () {}; - site_list_type &operator= (const site_list_type &); std::string url; // provided by mirrors.lst but not used std::string servername; @@ -60,6 +58,8 @@ public: std::string location; // did this site come from mirrors.lst? bool from_mirrors_lst; + // marked as "noshow" + bool noshow; std::string displayed_url; // sort key std::string key;