mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Allow searching USA by 'United States'.
This commit is contained in:
parent
dc102bd9e8
commit
a4d83b679a
Telegram
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "storage/localstorage.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "countries.h"
|
||||
#include "auth_session.h"
|
||||
#include "data/data_session.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
|
@ -1,255 +0,0 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
struct CountryInfo {
|
||||
CountryInfo(const char *_name, const char *_iso2, const char *_code) : name(_name), iso2(_iso2), code(_code) {
|
||||
}
|
||||
const char *name, *iso2, *code;
|
||||
};
|
||||
|
||||
static const CountryInfo countries[] = {
|
||||
CountryInfo("Afghanistan", "AF", "93"),
|
||||
CountryInfo("Albania", "AL", "355"),
|
||||
CountryInfo("Algeria", "DZ", "213"),
|
||||
CountryInfo("American Samoa", "AS", "1684"),
|
||||
CountryInfo("Andorra", "AD", "376"),
|
||||
CountryInfo("Angola", "AO", "244"),
|
||||
CountryInfo("Anguilla", "AI", "1264"),
|
||||
CountryInfo("Antigua & Barbuda", "AG", "1268"),
|
||||
CountryInfo("Argentina", "AR", "54"),
|
||||
CountryInfo("Armenia", "AM", "374"),
|
||||
CountryInfo("Aruba", "AW", "297"),
|
||||
CountryInfo("Australia", "AU", "61"),
|
||||
CountryInfo("Austria", "AT", "43"),
|
||||
CountryInfo("Azerbaijan", "AZ", "994"),
|
||||
CountryInfo("Bahamas", "BS", "1242"),
|
||||
CountryInfo("Bahrain", "BH", "973"),
|
||||
CountryInfo("Bangladesh", "BD", "880"),
|
||||
CountryInfo("Barbados", "BB", "1246"),
|
||||
CountryInfo("Belarus", "BY", "375"),
|
||||
CountryInfo("Belgium", "BE", "32"),
|
||||
CountryInfo("Belize", "BZ", "501"),
|
||||
CountryInfo("Benin", "BJ", "229"),
|
||||
CountryInfo("Bermuda", "BM", "1441"),
|
||||
CountryInfo("Bhutan", "BT", "975"),
|
||||
CountryInfo("Bolivia", "BO", "591"),
|
||||
CountryInfo("Bonaire, Sint Eustatius & Saba", "BQ", "599"),
|
||||
CountryInfo("Bosnia & Herzegovina", "BA", "387"),
|
||||
CountryInfo("Botswana", "BW", "267"),
|
||||
CountryInfo("Brazil", "BR", "55"),
|
||||
CountryInfo("British Virgin Islands", "VG", "1284"),
|
||||
CountryInfo("Brunei Darussalam", "BN", "673"),
|
||||
CountryInfo("Bulgaria", "BG", "359"),
|
||||
CountryInfo("Burkina Faso", "BF", "226"),
|
||||
CountryInfo("Burundi", "BI", "257"),
|
||||
CountryInfo("Cambodia", "KH", "855"),
|
||||
CountryInfo("Cameroon", "CM", "237"),
|
||||
CountryInfo("Canada", "CA", "1"),
|
||||
CountryInfo("Cape Verde", "CV", "238"),
|
||||
CountryInfo("Cayman Islands", "KY", "1345"),
|
||||
CountryInfo("Central African Republic", "CF", "236"),
|
||||
CountryInfo("Chad", "TD", "235"),
|
||||
CountryInfo("Chile", "CL", "56"),
|
||||
CountryInfo("China", "CN", "86"),
|
||||
CountryInfo("Colombia", "CO", "57"),
|
||||
CountryInfo("Comoros", "KM", "269"),
|
||||
CountryInfo("Congo", "CG", "242"),
|
||||
CountryInfo("Congo, Democratic Republic", "CD", "243"),
|
||||
CountryInfo("Cook Islands", "CK", "682"),
|
||||
CountryInfo("Costa Rica", "CR", "506"),
|
||||
CountryInfo("Croatia", "HR", "385"),
|
||||
CountryInfo("Cuba", "CU", "53"),
|
||||
CountryInfo("Curaçao", "CW", "599"),
|
||||
CountryInfo("Cyprus", "CY", "357"),
|
||||
CountryInfo("Czech Republic", "CZ", "420"),
|
||||
CountryInfo("Côte d`Ivoire", "CI", "225"),
|
||||
CountryInfo("Denmark", "DK", "45"),
|
||||
CountryInfo("Diego Garcia", "IO", "246"),
|
||||
CountryInfo("Djibouti", "DJ", "253"),
|
||||
CountryInfo("Dominica", "DM", "1767"),
|
||||
CountryInfo("Dominican Republic", "DO", "1"),
|
||||
CountryInfo("Ecuador", "EC", "593"),
|
||||
CountryInfo("Egypt", "EG", "20"),
|
||||
CountryInfo("El Salvador", "SV", "503"),
|
||||
CountryInfo("Equatorial Guinea", "GQ", "240"),
|
||||
CountryInfo("Eritrea", "ER", "291"),
|
||||
CountryInfo("Estonia", "EE", "372"),
|
||||
CountryInfo("Ethiopia", "ET", "251"),
|
||||
CountryInfo("Falkland Islands", "FK", "500"),
|
||||
CountryInfo("Faroe Islands", "FO", "298"),
|
||||
CountryInfo("Fiji", "FJ", "679"),
|
||||
CountryInfo("Finland", "FI", "358"),
|
||||
CountryInfo("France", "FR", "33"),
|
||||
CountryInfo("French Guiana", "GF", "594"),
|
||||
CountryInfo("French Polynesia", "PF", "689"),
|
||||
CountryInfo("Gabon", "GA", "241"),
|
||||
CountryInfo("Gambia", "GM", "220"),
|
||||
CountryInfo("Georgia", "GE", "995"),
|
||||
CountryInfo("Germany", "DE", "49"),
|
||||
CountryInfo("Ghana", "GH", "233"),
|
||||
CountryInfo("Gibraltar", "GI", "350"),
|
||||
CountryInfo("Greece", "GR", "30"),
|
||||
CountryInfo("Greenland", "GL", "299"),
|
||||
CountryInfo("Grenada", "GD", "1473"),
|
||||
CountryInfo("Guadeloupe", "GP", "590"),
|
||||
CountryInfo("Guam", "GU", "1671"),
|
||||
CountryInfo("Guatemala", "GT", "502"),
|
||||
CountryInfo("Guinea", "GN", "224"),
|
||||
CountryInfo("Guinea-Bissau", "GW", "245"),
|
||||
CountryInfo("Guyana", "GY", "592"),
|
||||
CountryInfo("Haiti", "HT", "509"),
|
||||
CountryInfo("Honduras", "HN", "504"),
|
||||
CountryInfo("Hong Kong", "HK", "852"),
|
||||
CountryInfo("Hungary", "HU", "36"),
|
||||
CountryInfo("Iceland", "IS", "354"),
|
||||
CountryInfo("India", "IN", "91"),
|
||||
CountryInfo("Indonesia", "ID", "62"),
|
||||
CountryInfo("Iran", "IR", "98"),
|
||||
CountryInfo("Iraq", "IQ", "964"),
|
||||
CountryInfo("Ireland", "IE", "353"),
|
||||
CountryInfo("Israel", "IL", "972"),
|
||||
CountryInfo("Italy", "IT", "39"),
|
||||
CountryInfo("Jamaica", "JM", "1876"),
|
||||
CountryInfo("Japan", "JP", "81"),
|
||||
CountryInfo("Jordan", "JO", "962"),
|
||||
CountryInfo("Kazakhstan", "KZ", "7"),
|
||||
CountryInfo("Kenya", "KE", "254"),
|
||||
CountryInfo("Kiribati", "KI", "686"),
|
||||
CountryInfo("Kuwait", "KW", "965"),
|
||||
CountryInfo("Kyrgyzstan", "KG", "996"),
|
||||
CountryInfo("Laos", "LA", "856"),
|
||||
CountryInfo("Latvia", "LV", "371"),
|
||||
CountryInfo("Lebanon", "LB", "961"),
|
||||
CountryInfo("Lesotho", "LS", "266"),
|
||||
CountryInfo("Liberia", "LR", "231"),
|
||||
CountryInfo("Libya", "LY", "218"),
|
||||
CountryInfo("Liechtenstein", "LI", "423"),
|
||||
CountryInfo("Lithuania", "LT", "370"),
|
||||
CountryInfo("Luxembourg", "LU", "352"),
|
||||
CountryInfo("Macau", "MO", "853"),
|
||||
CountryInfo("Macedonia", "MK", "389"),
|
||||
CountryInfo("Madagascar", "MG", "261"),
|
||||
CountryInfo("Malawi", "MW", "265"),
|
||||
CountryInfo("Malaysia", "MY", "60"),
|
||||
CountryInfo("Maldives", "MV", "960"),
|
||||
CountryInfo("Mali", "ML", "223"),
|
||||
CountryInfo("Malta", "MT", "356"),
|
||||
CountryInfo("Marshall Islands", "MH", "692"),
|
||||
CountryInfo("Martinique", "MQ", "596"),
|
||||
CountryInfo("Mauritania", "MR", "222"),
|
||||
CountryInfo("Mauritius", "MU", "230"),
|
||||
CountryInfo("Mexico", "MX", "52"),
|
||||
CountryInfo("Micronesia", "FM", "691"),
|
||||
CountryInfo("Moldova", "MD", "373"),
|
||||
CountryInfo("Monaco", "MC", "377"),
|
||||
CountryInfo("Mongolia", "MN", "976"),
|
||||
CountryInfo("Montenegro", "ME", "382"),
|
||||
CountryInfo("Montserrat", "MS", "1664"),
|
||||
CountryInfo("Morocco", "MA", "212"),
|
||||
CountryInfo("Mozambique", "MZ", "258"),
|
||||
CountryInfo("Myanmar", "MM", "95"),
|
||||
CountryInfo("Namibia", "NA", "264"),
|
||||
CountryInfo("Nauru", "NR", "674"),
|
||||
CountryInfo("Nepal", "NP", "977"),
|
||||
CountryInfo("Netherlands", "NL", "31"),
|
||||
CountryInfo("New Caledonia", "NC", "687"),
|
||||
CountryInfo("New Zealand", "NZ", "64"),
|
||||
CountryInfo("Nicaragua", "NI", "505"),
|
||||
CountryInfo("Niger", "NE", "227"),
|
||||
CountryInfo("Nigeria", "NG", "234"),
|
||||
CountryInfo("Niue", "NU", "683"),
|
||||
CountryInfo("Norfolk Island", "NF", "672"),
|
||||
CountryInfo("North Korea", "KP", "850"),
|
||||
CountryInfo("Northern Mariana Islands", "MP", "1670"),
|
||||
CountryInfo("Norway", "NO", "47"),
|
||||
CountryInfo("Oman", "OM", "968"),
|
||||
CountryInfo("Pakistan", "PK", "92"),
|
||||
CountryInfo("Palau", "PW", "680"),
|
||||
CountryInfo("Palestine", "PS", "970"),
|
||||
CountryInfo("Panama", "PA", "507"),
|
||||
CountryInfo("Papua New Guinea", "PG", "675"),
|
||||
CountryInfo("Paraguay", "PY", "595"),
|
||||
CountryInfo("Peru", "PE", "51"),
|
||||
CountryInfo("Philippines", "PH", "63"),
|
||||
CountryInfo("Poland", "PL", "48"),
|
||||
CountryInfo("Portugal", "PT", "351"),
|
||||
CountryInfo("Puerto Rico", "PR", "1"),
|
||||
CountryInfo("Qatar", "QA", "974"),
|
||||
CountryInfo("Romania", "RO", "40"),
|
||||
CountryInfo("Russian Federation", "RU", "7"),
|
||||
CountryInfo("Rwanda", "RW", "250"),
|
||||
CountryInfo("Réunion", "RE", "262"),
|
||||
CountryInfo("Saint Helena", "SH", "247"),
|
||||
CountryInfo("Saint Helena", "SH2", "290"),
|
||||
CountryInfo("Saint Kitts & Nevis", "KN", "1869"),
|
||||
CountryInfo("Saint Lucia", "LC", "1758"),
|
||||
CountryInfo("Saint Pierre & Miquelon", "PM", "508"),
|
||||
CountryInfo("Saint Vincent & the Grenadines", "VC", "1784"),
|
||||
CountryInfo("Samoa", "WS", "685"),
|
||||
CountryInfo("San Marino", "SM", "378"),
|
||||
CountryInfo("Saudi Arabia", "SA", "966"),
|
||||
CountryInfo("Senegal", "SN", "221"),
|
||||
CountryInfo("Serbia", "RS", "381"),
|
||||
CountryInfo("Seychelles", "SC", "248"),
|
||||
CountryInfo("Sierra Leone", "SL", "232"),
|
||||
CountryInfo("Singapore", "SG", "65"),
|
||||
CountryInfo("Sint Maarten", "SX", "1721"),
|
||||
CountryInfo("Slovakia", "SK", "421"),
|
||||
CountryInfo("Slovenia", "SI", "386"),
|
||||
CountryInfo("Solomon Islands", "SB", "677"),
|
||||
CountryInfo("Somalia", "SO", "252"),
|
||||
CountryInfo("South Africa", "ZA", "27"),
|
||||
CountryInfo("South Korea", "KR", "82"),
|
||||
CountryInfo("South Sudan", "SS", "211"),
|
||||
CountryInfo("Spain", "ES", "34"),
|
||||
CountryInfo("Sri Lanka", "LK", "94"),
|
||||
CountryInfo("Sudan", "SD", "249"),
|
||||
CountryInfo("Suriname", "SR", "597"),
|
||||
CountryInfo("Swaziland", "SZ", "268"),
|
||||
CountryInfo("Sweden", "SE", "46"),
|
||||
CountryInfo("Switzerland", "CH", "41"),
|
||||
CountryInfo("Syrian Arab Republic", "SY", "963"),
|
||||
CountryInfo("São Tomé & Príncipe", "ST", "239"),
|
||||
CountryInfo("Taiwan", "TW", "886"),
|
||||
CountryInfo("Tajikistan", "TJ", "992"),
|
||||
CountryInfo("Tanzania", "TZ", "255"),
|
||||
CountryInfo("Thailand", "TH", "66"),
|
||||
CountryInfo("Timor-Leste", "TL", "670"),
|
||||
CountryInfo("Togo", "TG", "228"),
|
||||
CountryInfo("Tokelau", "TK", "690"),
|
||||
CountryInfo("Tonga", "TO", "676"),
|
||||
CountryInfo("Trinidad & Tobago", "TT", "1868"),
|
||||
CountryInfo("Tunisia", "TN", "216"),
|
||||
CountryInfo("Turkey", "TR", "90"),
|
||||
CountryInfo("Turkmenistan", "TM", "993"),
|
||||
CountryInfo("Turks & Caicos Islands", "TC", "1649"),
|
||||
CountryInfo("Tuvalu", "TV", "688"),
|
||||
CountryInfo("US Virgin Islands", "VI", "1340"),
|
||||
CountryInfo("USA", "US", "1"),
|
||||
CountryInfo("Uganda", "UG", "256"),
|
||||
CountryInfo("Ukraine", "UA", "380"),
|
||||
CountryInfo("United Arab Emirates", "AE", "971"),
|
||||
CountryInfo("United Kingdom", "GB", "44"),
|
||||
CountryInfo("Uruguay", "UY", "598"),
|
||||
CountryInfo("Uzbekistan", "UZ", "998"),
|
||||
CountryInfo("Vanuatu", "VU", "678"),
|
||||
CountryInfo("Venezuela", "VE", "58"),
|
||||
CountryInfo("Vietnam", "VN", "84"),
|
||||
CountryInfo("Wallis & Futuna", "WF", "681"),
|
||||
CountryInfo("Yemen", "YE", "967"),
|
||||
CountryInfo("Zambia", "ZM", "260"),
|
||||
CountryInfo("Zimbabwe", "ZW", "263"),
|
||||
};
|
||||
|
||||
typedef QHash<QString, const CountryInfo *> CountriesByCode;
|
||||
typedef QHash<QString, const CountryInfo *> CountriesByISO2;
|
||||
|
||||
const CountriesByCode &countriesByCode();
|
||||
const CountriesByISO2 &countriesByISO2();
|
301
Telegram/SourceFiles/data/data_countries.cpp
Normal file
301
Telegram/SourceFiles/data/data_countries.cpp
Normal file
@ -0,0 +1,301 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "data/data_countries.h"
|
||||
|
||||
namespace Data {
|
||||
namespace {
|
||||
|
||||
const std::array<CountryInfo, 231> List = { {
|
||||
{ "Afghanistan", "AF", "93" },
|
||||
{ "Albania", "AL", "355" },
|
||||
{ "Algeria", "DZ", "213" },
|
||||
{ "American Samoa", "AS", "1684" },
|
||||
{ "Andorra", "AD", "376" },
|
||||
{ "Angola", "AO", "244" },
|
||||
{ "Anguilla", "AI", "1264" },
|
||||
{ "Antigua & Barbuda", "AG", "1268" },
|
||||
{ "Argentina", "AR", "54" },
|
||||
{ "Armenia", "AM", "374" },
|
||||
{ "Aruba", "AW", "297" },
|
||||
{ "Australia", "AU", "61" },
|
||||
{ "Austria", "AT", "43" },
|
||||
{ "Azerbaijan", "AZ", "994" },
|
||||
{ "Bahamas", "BS", "1242" },
|
||||
{ "Bahrain", "BH", "973" },
|
||||
{ "Bangladesh", "BD", "880" },
|
||||
{ "Barbados", "BB", "1246" },
|
||||
{ "Belarus", "BY", "375" },
|
||||
{ "Belgium", "BE", "32" },
|
||||
{ "Belize", "BZ", "501" },
|
||||
{ "Benin", "BJ", "229" },
|
||||
{ "Bermuda", "BM", "1441" },
|
||||
{ "Bhutan", "BT", "975" },
|
||||
{ "Bolivia", "BO", "591" },
|
||||
{ "Bonaire, Sint Eustatius & Saba", "BQ", "599" },
|
||||
{ "Bosnia & Herzegovina", "BA", "387" },
|
||||
{ "Botswana", "BW", "267" },
|
||||
{ "Brazil", "BR", "55" },
|
||||
{ "British Virgin Islands", "VG", "1284" },
|
||||
{ "Brunei Darussalam", "BN", "673" },
|
||||
{ "Bulgaria", "BG", "359" },
|
||||
{ "Burkina Faso", "BF", "226" },
|
||||
{ "Burundi", "BI", "257" },
|
||||
{ "Cambodia", "KH", "855" },
|
||||
{ "Cameroon", "CM", "237" },
|
||||
{ "Canada", "CA", "1" },
|
||||
{ "Cape Verde", "CV", "238" },
|
||||
{ "Cayman Islands", "KY", "1345" },
|
||||
{ "Central African Republic", "CF", "236" },
|
||||
{ "Chad", "TD", "235" },
|
||||
{ "Chile", "CL", "56" },
|
||||
{ "China", "CN", "86" },
|
||||
{ "Colombia", "CO", "57" },
|
||||
{ "Comoros", "KM", "269" },
|
||||
{ "Congo", "CG", "242" },
|
||||
{ "Congo, Democratic Republic", "CD", "243" },
|
||||
{ "Cook Islands", "CK", "682" },
|
||||
{ "Costa Rica", "CR", "506" },
|
||||
{ "Croatia", "HR", "385" },
|
||||
{ "Cuba", "CU", "53" },
|
||||
{ "Curaçao", "CW", "599" },
|
||||
{ "Cyprus", "CY", "357" },
|
||||
{ "Czech Republic", "CZ", "420" },
|
||||
{ "Côte d`Ivoire", "CI", "225" },
|
||||
{ "Denmark", "DK", "45" },
|
||||
{ "Diego Garcia", "IO", "246" },
|
||||
{ "Djibouti", "DJ", "253" },
|
||||
{ "Dominica", "DM", "1767" },
|
||||
{ "Dominican Republic", "DO", "1" },
|
||||
{ "Ecuador", "EC", "593" },
|
||||
{ "Egypt", "EG", "20" },
|
||||
{ "El Salvador", "SV", "503" },
|
||||
{ "Equatorial Guinea", "GQ", "240" },
|
||||
{ "Eritrea", "ER", "291" },
|
||||
{ "Estonia", "EE", "372" },
|
||||
{ "Ethiopia", "ET", "251" },
|
||||
{ "Falkland Islands", "FK", "500" },
|
||||
{ "Faroe Islands", "FO", "298" },
|
||||
{ "Fiji", "FJ", "679" },
|
||||
{ "Finland", "FI", "358" },
|
||||
{ "France", "FR", "33" },
|
||||
{ "French Guiana", "GF", "594" },
|
||||
{ "French Polynesia", "PF", "689" },
|
||||
{ "Gabon", "GA", "241" },
|
||||
{ "Gambia", "GM", "220" },
|
||||
{ "Georgia", "GE", "995" },
|
||||
{ "Germany", "DE", "49" },
|
||||
{ "Ghana", "GH", "233" },
|
||||
{ "Gibraltar", "GI", "350" },
|
||||
{ "Greece", "GR", "30" },
|
||||
{ "Greenland", "GL", "299" },
|
||||
{ "Grenada", "GD", "1473" },
|
||||
{ "Guadeloupe", "GP", "590" },
|
||||
{ "Guam", "GU", "1671" },
|
||||
{ "Guatemala", "GT", "502" },
|
||||
{ "Guinea", "GN", "224" },
|
||||
{ "Guinea-Bissau", "GW", "245" },
|
||||
{ "Guyana", "GY", "592" },
|
||||
{ "Haiti", "HT", "509" },
|
||||
{ "Honduras", "HN", "504" },
|
||||
{ "Hong Kong", "HK", "852" },
|
||||
{ "Hungary", "HU", "36" },
|
||||
{ "Iceland", "IS", "354" },
|
||||
{ "India", "IN", "91" },
|
||||
{ "Indonesia", "ID", "62" },
|
||||
{ "Iran", "IR", "98" },
|
||||
{ "Iraq", "IQ", "964" },
|
||||
{ "Ireland", "IE", "353" },
|
||||
{ "Israel", "IL", "972" },
|
||||
{ "Italy", "IT", "39" },
|
||||
{ "Jamaica", "JM", "1876" },
|
||||
{ "Japan", "JP", "81" },
|
||||
{ "Jordan", "JO", "962" },
|
||||
{ "Kazakhstan", "KZ", "7" },
|
||||
{ "Kenya", "KE", "254" },
|
||||
{ "Kiribati", "KI", "686" },
|
||||
{ "Kuwait", "KW", "965" },
|
||||
{ "Kyrgyzstan", "KG", "996" },
|
||||
{ "Laos", "LA", "856" },
|
||||
{ "Latvia", "LV", "371" },
|
||||
{ "Lebanon", "LB", "961" },
|
||||
{ "Lesotho", "LS", "266" },
|
||||
{ "Liberia", "LR", "231" },
|
||||
{ "Libya", "LY", "218" },
|
||||
{ "Liechtenstein", "LI", "423" },
|
||||
{ "Lithuania", "LT", "370" },
|
||||
{ "Luxembourg", "LU", "352" },
|
||||
{ "Macau", "MO", "853" },
|
||||
{ "Macedonia", "MK", "389" },
|
||||
{ "Madagascar", "MG", "261" },
|
||||
{ "Malawi", "MW", "265" },
|
||||
{ "Malaysia", "MY", "60" },
|
||||
{ "Maldives", "MV", "960" },
|
||||
{ "Mali", "ML", "223" },
|
||||
{ "Malta", "MT", "356" },
|
||||
{ "Marshall Islands", "MH", "692" },
|
||||
{ "Martinique", "MQ", "596" },
|
||||
{ "Mauritania", "MR", "222" },
|
||||
{ "Mauritius", "MU", "230" },
|
||||
{ "Mexico", "MX", "52" },
|
||||
{ "Micronesia", "FM", "691" },
|
||||
{ "Moldova", "MD", "373" },
|
||||
{ "Monaco", "MC", "377" },
|
||||
{ "Mongolia", "MN", "976" },
|
||||
{ "Montenegro", "ME", "382" },
|
||||
{ "Montserrat", "MS", "1664" },
|
||||
{ "Morocco", "MA", "212" },
|
||||
{ "Mozambique", "MZ", "258" },
|
||||
{ "Myanmar", "MM", "95" },
|
||||
{ "Namibia", "NA", "264" },
|
||||
{ "Nauru", "NR", "674" },
|
||||
{ "Nepal", "NP", "977" },
|
||||
{ "Netherlands", "NL", "31" },
|
||||
{ "New Caledonia", "NC", "687" },
|
||||
{ "New Zealand", "NZ", "64" },
|
||||
{ "Nicaragua", "NI", "505" },
|
||||
{ "Niger", "NE", "227" },
|
||||
{ "Nigeria", "NG", "234" },
|
||||
{ "Niue", "NU", "683" },
|
||||
{ "Norfolk Island", "NF", "672" },
|
||||
{ "North Korea", "KP", "850" },
|
||||
{ "Northern Mariana Islands", "MP", "1670" },
|
||||
{ "Norway", "NO", "47" },
|
||||
{ "Oman", "OM", "968" },
|
||||
{ "Pakistan", "PK", "92" },
|
||||
{ "Palau", "PW", "680" },
|
||||
{ "Palestine", "PS", "970" },
|
||||
{ "Panama", "PA", "507" },
|
||||
{ "Papua New Guinea", "PG", "675" },
|
||||
{ "Paraguay", "PY", "595" },
|
||||
{ "Peru", "PE", "51" },
|
||||
{ "Philippines", "PH", "63" },
|
||||
{ "Poland", "PL", "48" },
|
||||
{ "Portugal", "PT", "351" },
|
||||
{ "Puerto Rico", "PR", "1" },
|
||||
{ "Qatar", "QA", "974" },
|
||||
{ "Romania", "RO", "40" },
|
||||
{ "Russian Federation", "RU", "7" },
|
||||
{ "Rwanda", "RW", "250" },
|
||||
{ "Réunion", "RE", "262" },
|
||||
{ "Saint Helena", "SH", "247" },
|
||||
{ "Saint Helena", "SH2", "290" },
|
||||
{ "Saint Kitts & Nevis", "KN", "1869" },
|
||||
{ "Saint Lucia", "LC", "1758" },
|
||||
{ "Saint Pierre & Miquelon", "PM", "508" },
|
||||
{ "Saint Vincent & the Grenadines", "VC", "1784" },
|
||||
{ "Samoa", "WS", "685" },
|
||||
{ "San Marino", "SM", "378" },
|
||||
{ "Saudi Arabia", "SA", "966" },
|
||||
{ "Senegal", "SN", "221" },
|
||||
{ "Serbia", "RS", "381" },
|
||||
{ "Seychelles", "SC", "248" },
|
||||
{ "Sierra Leone", "SL", "232" },
|
||||
{ "Singapore", "SG", "65" },
|
||||
{ "Sint Maarten", "SX", "1721" },
|
||||
{ "Slovakia", "SK", "421" },
|
||||
{ "Slovenia", "SI", "386" },
|
||||
{ "Solomon Islands", "SB", "677" },
|
||||
{ "Somalia", "SO", "252" },
|
||||
{ "South Africa", "ZA", "27" },
|
||||
{ "South Korea", "KR", "82" },
|
||||
{ "South Sudan", "SS", "211" },
|
||||
{ "Spain", "ES", "34" },
|
||||
{ "Sri Lanka", "LK", "94" },
|
||||
{ "Sudan", "SD", "249" },
|
||||
{ "Suriname", "SR", "597" },
|
||||
{ "Swaziland", "SZ", "268" },
|
||||
{ "Sweden", "SE", "46" },
|
||||
{ "Switzerland", "CH", "41" },
|
||||
{ "Syrian Arab Republic", "SY", "963" },
|
||||
{ "São Tomé & Príncipe", "ST", "239" },
|
||||
{ "Taiwan", "TW", "886" },
|
||||
{ "Tajikistan", "TJ", "992" },
|
||||
{ "Tanzania", "TZ", "255" },
|
||||
{ "Thailand", "TH", "66" },
|
||||
{ "Timor-Leste", "TL", "670" },
|
||||
{ "Togo", "TG", "228" },
|
||||
{ "Tokelau", "TK", "690" },
|
||||
{ "Tonga", "TO", "676" },
|
||||
{ "Trinidad & Tobago", "TT", "1868" },
|
||||
{ "Tunisia", "TN", "216" },
|
||||
{ "Turkey", "TR", "90" },
|
||||
{ "Turkmenistan", "TM", "993" },
|
||||
{ "Turks & Caicos Islands", "TC", "1649" },
|
||||
{ "Tuvalu", "TV", "688" },
|
||||
{ "US Virgin Islands", "VI", "1340" },
|
||||
{ "USA", "US", "1", "United States of America" },
|
||||
{ "Uganda", "UG", "256" },
|
||||
{ "Ukraine", "UA", "380" },
|
||||
{ "United Arab Emirates", "AE", "971" },
|
||||
{ "United Kingdom", "GB", "44" },
|
||||
{ "Uruguay", "UY", "598" },
|
||||
{ "Uzbekistan", "UZ", "998" },
|
||||
{ "Vanuatu", "VU", "678" },
|
||||
{ "Venezuela", "VE", "58" },
|
||||
{ "Vietnam", "VN", "84" },
|
||||
{ "Wallis & Futuna", "WF", "681" },
|
||||
{ "Yemen", "YE", "967" },
|
||||
{ "Zambia", "ZM", "260" },
|
||||
{ "Zimbabwe", "ZW", "263" },
|
||||
} };
|
||||
|
||||
QHash<QString, const CountryInfo *> ByCode;
|
||||
QHash<QString, const CountryInfo *> ByISO2;
|
||||
|
||||
} // namespace
|
||||
|
||||
const std::array<CountryInfo, 231> &Countries() {
|
||||
return List;
|
||||
}
|
||||
|
||||
const QHash<QString, const CountryInfo *> &CountriesByCode() {
|
||||
if (ByCode.isEmpty()) {
|
||||
ByCode.reserve(List.size());
|
||||
for (const auto &entry : List) {
|
||||
ByCode.insert(entry.code, &entry);
|
||||
}
|
||||
}
|
||||
return ByCode;
|
||||
}
|
||||
|
||||
const QHash<QString, const CountryInfo *> &CountriesByISO2() {
|
||||
if (ByISO2.isEmpty()) {
|
||||
ByISO2.reserve(List.size());
|
||||
for (const auto &entry : List) {
|
||||
ByISO2.insert(entry.iso2, &entry);
|
||||
}
|
||||
}
|
||||
return ByISO2;
|
||||
}
|
||||
|
||||
QString ValidPhoneCode(QString fullCode) {
|
||||
const auto &byCode = CountriesByCode();
|
||||
while (fullCode.length()) {
|
||||
const auto i = byCode.constFind(fullCode);
|
||||
if (i != byCode.cend()) {
|
||||
return (*i)->code;
|
||||
}
|
||||
fullCode.chop(1);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString CountryNameByISO2(const QString &iso) {
|
||||
const auto &byISO2 = CountriesByISO2();
|
||||
const auto i = byISO2.constFind(iso);
|
||||
return (i != byISO2.cend()) ? QString::fromUtf8((*i)->name) : QString();
|
||||
}
|
||||
|
||||
QString CountryISO2ByPhone(const QString &phone) {
|
||||
const auto &byCode = Data::CountriesByCode();
|
||||
const auto code = Data::ValidPhoneCode(phone);
|
||||
const auto i = byCode.find(code);
|
||||
return (i != byCode.cend()) ? QString::fromUtf8((*i)->iso2) : QString();
|
||||
}
|
||||
|
||||
} // namespace Data
|
29
Telegram/SourceFiles/data/data_countries.h
Normal file
29
Telegram/SourceFiles/data/data_countries.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Data {
|
||||
|
||||
struct CountryInfo {
|
||||
const char *name = nullptr;
|
||||
const char *iso2 = nullptr;
|
||||
const char *code = nullptr;
|
||||
const char *alternativeName = nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] const std::array<CountryInfo, 231> &Countries();
|
||||
|
||||
[[nodiscard]] const QHash<QString, const CountryInfo *> &CountriesByCode();
|
||||
[[nodiscard]] const QHash<QString, const CountryInfo *> &CountriesByISO2();
|
||||
|
||||
[[nodiscard]] QString ValidPhoneCode(QString fullCode);
|
||||
[[nodiscard]] QString CountryNameByISO2(const QString &iso);
|
||||
[[nodiscard]] QString CountryISO2ByPhone(const QString &phone);
|
||||
|
||||
} // namespace Data
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/countryinput.h"
|
||||
#include "core/update_checker.h"
|
||||
#include "data/data_countries.h"
|
||||
#include "layout.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
@ -114,7 +115,7 @@ EditDocumentScheme GetDocumentScheme(
|
||||
using ValueClass = Scheme::ValueClass;
|
||||
const auto DontFormat = nullptr;
|
||||
const auto CountryFormat = [](const QString &value) {
|
||||
const auto result = CountrySelectBox::NameByISO(value);
|
||||
const auto result = Data::CountryNameByISO2(value);
|
||||
return result.isEmpty() ? value : result;
|
||||
};
|
||||
const auto GenderFormat = [](const QString &value) {
|
||||
@ -313,7 +314,7 @@ EditDocumentScheme GetDocumentScheme(
|
||||
if (!language.isEmpty()) {
|
||||
return tr::lng_passport_native_name_language_about(tr::now);
|
||||
}
|
||||
const auto name = CountrySelectBox::NameByISO(countryCode);
|
||||
const auto name = Data::CountryNameByISO2(countryCode);
|
||||
Assert(!name.isEmpty());
|
||||
return tr::lng_passport_native_name_about(
|
||||
tr::now,
|
||||
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/countryinput.h"
|
||||
#include "auth_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_countries.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_passport.h"
|
||||
|
||||
@ -301,7 +302,7 @@ void AbstractTextRow<Input>::finishInnerAnimating() {
|
||||
}
|
||||
|
||||
QString CountryString(const QString &code) {
|
||||
const auto name = CountrySelectBox::NameByISO(code);
|
||||
const auto name = Data::CountryNameByISO2(code);
|
||||
return name.isEmpty() ? tr::lng_passport_country_choose(tr::now) : name;
|
||||
}
|
||||
|
||||
@ -378,8 +379,8 @@ void CountryRow::errorAnimationCallback() {
|
||||
|
||||
void CountryRow::chooseCountry() {
|
||||
const auto top = _value.current();
|
||||
const auto name = CountrySelectBox::NameByISO(top);
|
||||
const auto isoByPhone = CountrySelectBox::ISOByPhone(
|
||||
const auto name = Data::CountryNameByISO2(top);
|
||||
const auto isoByPhone = Data::CountryISO2ByPhone(
|
||||
Auth().user()->phone());
|
||||
const auto box = _controller->show(Box<CountrySelectBox>(!name.isEmpty()
|
||||
? top
|
||||
|
@ -11,74 +11,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/widgets/multi_select.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "countries.h"
|
||||
#include "data/data_countries.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_intro.h"
|
||||
|
||||
namespace {
|
||||
|
||||
typedef QList<const CountryInfo *> CountriesFiltered;
|
||||
typedef QVector<int> CountriesIds;
|
||||
typedef QHash<QChar, CountriesIds> CountriesByLetter;
|
||||
typedef QVector<QString> CountryNames;
|
||||
typedef QVector<CountryNames> CountriesNames;
|
||||
|
||||
CountriesByCode _countriesByCode;
|
||||
CountriesByISO2 _countriesByISO2;
|
||||
CountriesFiltered countriesFiltered, countriesAll, *countriesNow = &countriesAll;
|
||||
CountriesByLetter countriesByLetter;
|
||||
CountriesNames countriesNames;
|
||||
|
||||
QString lastValidISO;
|
||||
int countriesCount = sizeof(countries) / sizeof(countries[0]);
|
||||
|
||||
void initCountries() {
|
||||
if (!_countriesByCode.isEmpty()) return;
|
||||
|
||||
_countriesByCode.reserve(countriesCount);
|
||||
_countriesByISO2.reserve(countriesCount);
|
||||
for (int i = 0; i < countriesCount; ++i) {
|
||||
const CountryInfo *info(countries + i);
|
||||
_countriesByCode.insert(info->code, info);
|
||||
CountriesByISO2::const_iterator already = _countriesByISO2.constFind(info->iso2);
|
||||
if (already != _countriesByISO2.cend()) {
|
||||
QString badISO = info->iso2;
|
||||
(void)badISO;
|
||||
}
|
||||
_countriesByISO2.insert(info->iso2, info);
|
||||
}
|
||||
countriesAll.reserve(countriesCount);
|
||||
countriesFiltered.reserve(countriesCount);
|
||||
countriesNames.resize(countriesCount);
|
||||
}
|
||||
QString LastValidISO;
|
||||
|
||||
} // namespace
|
||||
|
||||
const CountriesByCode &countriesByCode() {
|
||||
initCountries();
|
||||
return _countriesByCode;
|
||||
}
|
||||
|
||||
const CountriesByISO2 &countriesByISO2() {
|
||||
initCountries();
|
||||
return _countriesByISO2;
|
||||
}
|
||||
|
||||
QString findValidCode(QString fullCode) {
|
||||
while (fullCode.length()) {
|
||||
CountriesByCode::const_iterator i = _countriesByCode.constFind(fullCode);
|
||||
if (i != _countriesByCode.cend()) {
|
||||
return (*i)->code;
|
||||
}
|
||||
fullCode = fullCode.mid(0, fullCode.length() - 1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
CountryInput::CountryInput(QWidget *parent, const style::InputField &st) : TWidget(parent)
|
||||
, _st(st)
|
||||
, _text(tr::lng_country_code(tr::now)) {
|
||||
initCountries();
|
||||
resize(_st.width, _st.heightMin);
|
||||
|
||||
auto availableWidth = width() - _st.textMargins.left() - _st.textMargins.right() - _st.placeholderMargins.left() - _st.placeholderMargins.right() - 1;
|
||||
@ -163,10 +108,11 @@ void CountryInput::onChooseCode(const QString &code) {
|
||||
Ui::hideLayer();
|
||||
_chosenIso = QString();
|
||||
if (code.length()) {
|
||||
CountriesByCode::const_iterator i = _countriesByCode.constFind(code);
|
||||
if (i != _countriesByCode.cend()) {
|
||||
const CountryInfo *info = *i;
|
||||
_chosenIso = lastValidISO = info->iso2;
|
||||
const auto &byCode = Data::CountriesByCode();
|
||||
const auto i = byCode.constFind(code);
|
||||
if (i != byCode.cend()) {
|
||||
const auto info = *i;
|
||||
_chosenIso = LastValidISO = info->iso2;
|
||||
setText(QString::fromUtf8(info->name));
|
||||
} else {
|
||||
setText(tr::lng_bad_country_code(tr::now));
|
||||
@ -180,12 +126,13 @@ void CountryInput::onChooseCode(const QString &code) {
|
||||
bool CountryInput::onChooseCountry(const QString &iso) {
|
||||
Ui::hideLayer();
|
||||
|
||||
CountriesByISO2::const_iterator i = _countriesByISO2.constFind(iso);
|
||||
const CountryInfo *info = (i == _countriesByISO2.cend()) ? 0 : (*i);
|
||||
const auto &byISO2 = Data::CountriesByISO2();
|
||||
const auto i = byISO2.constFind(iso);
|
||||
const auto info = (i != byISO2.cend()) ? (*i) : nullptr;
|
||||
|
||||
_chosenIso = QString();
|
||||
if (info) {
|
||||
_chosenIso = lastValidISO = info->iso2;
|
||||
_chosenIso = LastValidISO = info->iso2;
|
||||
setText(QString::fromUtf8(info->name));
|
||||
emit codeChanged(info->code);
|
||||
update();
|
||||
@ -205,28 +152,7 @@ CountrySelectBox::CountrySelectBox(QWidget*)
|
||||
CountrySelectBox::CountrySelectBox(QWidget*, const QString &iso, Type type)
|
||||
: _type(type)
|
||||
, _select(this, st::contactsMultiSelect, tr::lng_country_ph()) {
|
||||
lastValidISO = iso;
|
||||
}
|
||||
|
||||
QString CountrySelectBox::NameByISO(const QString &iso) {
|
||||
if (_countriesByISO2.isEmpty()) {
|
||||
initCountries();
|
||||
}
|
||||
const auto i = _countriesByISO2.constFind(iso);
|
||||
return (i == _countriesByISO2.cend())
|
||||
? QString()
|
||||
: QString::fromUtf8((*i)->name);
|
||||
}
|
||||
|
||||
QString CountrySelectBox::ISOByPhone(const QString &phone) {
|
||||
if (_countriesByCode.isEmpty()) {
|
||||
initCountries();
|
||||
}
|
||||
const auto code = findValidCode(phone);
|
||||
const auto i = _countriesByCode.find(code);
|
||||
return (i == _countriesByCode.cend())
|
||||
? QString()
|
||||
: QString::fromUtf8((*i)->iso2);
|
||||
LastValidISO = iso;
|
||||
}
|
||||
|
||||
void CountrySelectBox::prepare() {
|
||||
@ -295,45 +221,47 @@ CountrySelectBox::Inner::Inner(QWidget *parent, Type type)
|
||||
, _rowHeight(st::countryRowHeight) {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
|
||||
if (countriesNames.isEmpty()) {
|
||||
initCountries();
|
||||
const auto &byISO2 = Data::CountriesByISO2();
|
||||
|
||||
_list.reserve(byISO2.size());
|
||||
_namesList.reserve(byISO2.size());
|
||||
|
||||
const auto l = byISO2.constFind(LastValidISO);
|
||||
const auto lastValid = (l != byISO2.cend()) ? (*l) : nullptr;
|
||||
if (lastValid) {
|
||||
_list.emplace_back(lastValid);
|
||||
}
|
||||
|
||||
CountriesByISO2::const_iterator l = _countriesByISO2.constFind(lastValidISO);
|
||||
bool seenLastValid = false;
|
||||
int already = countriesAll.size();
|
||||
|
||||
countriesByLetter.clear();
|
||||
const CountryInfo *lastValid = (l == _countriesByISO2.cend()) ? 0 : (*l);
|
||||
for (int i = 0; i < countriesCount; ++i) {
|
||||
const CountryInfo *ins = lastValid ? (i ? (countries + i - (seenLastValid ? 0 : 1)) : lastValid) : (countries + i);
|
||||
if (lastValid && i && ins == lastValid) {
|
||||
seenLastValid = true;
|
||||
++ins;
|
||||
for (const auto &entry : Data::Countries()) {
|
||||
if (&entry != lastValid) {
|
||||
_list.emplace_back(&entry);
|
||||
}
|
||||
if (already > i) {
|
||||
countriesAll[i] = ins;
|
||||
} else {
|
||||
countriesAll.push_back(ins);
|
||||
}
|
||||
|
||||
auto namesList = QString::fromUtf8(ins->name).toLower().split(QRegularExpression("[\\s\\-]"), QString::SkipEmptyParts);
|
||||
auto &names = countriesNames[i];
|
||||
int l = namesList.size();
|
||||
names.resize(0);
|
||||
names.reserve(l);
|
||||
for (int j = 0, l = namesList.size(); j < l; ++j) {
|
||||
auto name = namesList[j].trimmed();
|
||||
if (!name.length()) continue;
|
||||
|
||||
auto ch = name[0];
|
||||
auto &v = countriesByLetter[ch];
|
||||
if (v.isEmpty() || v.back() != i) {
|
||||
v.push_back(i);
|
||||
}
|
||||
auto index = 0;
|
||||
for (const auto info : _list) {
|
||||
auto full = QString::fromUtf8(info->name)
|
||||
+ ' '
|
||||
+ (info->alternativeName
|
||||
? QString::fromUtf8(info->alternativeName)
|
||||
: QString());
|
||||
const auto namesList = std::move(full).toLower().split(
|
||||
QRegularExpression("[\\s\\-]"),
|
||||
QString::SkipEmptyParts);
|
||||
auto &names = _namesList.emplace_back();
|
||||
names.reserve(namesList.size());
|
||||
for (const auto &name : namesList) {
|
||||
const auto part = name.trimmed();
|
||||
if (part.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.push_back(name);
|
||||
const auto ch = part[0];
|
||||
auto &byLetter = _byLetter[ch];
|
||||
if (byLetter.empty() || byLetter.back() != index) {
|
||||
byLetter.push_back(index);
|
||||
}
|
||||
names.push_back(part);
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
||||
_filter = qsl("a");
|
||||
@ -345,51 +273,52 @@ void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) {
|
||||
QRect r(e->rect());
|
||||
p.setClipRect(r);
|
||||
|
||||
int l = countriesNow->size();
|
||||
if (l) {
|
||||
if (r.intersects(QRect(0, 0, width(), st::countriesSkip))) {
|
||||
p.fillRect(r.intersected(QRect(0, 0, width(), st::countriesSkip)), st::countryRowBg);
|
||||
}
|
||||
int32 from = floorclamp(r.y() - st::countriesSkip, _rowHeight, 0, l);
|
||||
int32 to = ceilclamp(r.y() + r.height() - st::countriesSkip, _rowHeight, 0, l);
|
||||
for (int32 i = from; i < to; ++i) {
|
||||
auto selected = (i == (_pressed >= 0 ? _pressed : _selected));
|
||||
auto y = st::countriesSkip + i * _rowHeight;
|
||||
|
||||
p.fillRect(0, y, width(), _rowHeight, selected ? st::countryRowBgOver : st::countryRowBg);
|
||||
if (_ripples.size() > i && _ripples[i]) {
|
||||
_ripples[i]->paint(p, 0, y, width());
|
||||
if (_ripples[i]->empty()) {
|
||||
_ripples[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
auto code = QString("+") + (*countriesNow)[i]->code;
|
||||
auto codeWidth = st::countryRowCodeFont->width(code);
|
||||
|
||||
auto name = QString::fromUtf8((*countriesNow)[i]->name);
|
||||
auto nameWidth = st::countryRowNameFont->width(name);
|
||||
auto availWidth = width() - st::countryRowPadding.left() - st::countryRowPadding.right() - codeWidth - st::boxLayerScroll.width;
|
||||
if (nameWidth > availWidth) {
|
||||
name = st::countryRowNameFont->elided(name, availWidth);
|
||||
nameWidth = st::countryRowNameFont->width(name);
|
||||
}
|
||||
|
||||
p.setFont(st::countryRowNameFont);
|
||||
p.setPen(st::countryRowNameFg);
|
||||
p.drawTextLeft(st::countryRowPadding.left(), y + st::countryRowPadding.top(), width(), name);
|
||||
|
||||
if (_type == Type::Phones) {
|
||||
p.setFont(st::countryRowCodeFont);
|
||||
p.setPen(selected ? st::countryRowCodeFgOver : st::countryRowCodeFg);
|
||||
p.drawTextLeft(st::countryRowPadding.left() + nameWidth + st::countryRowPadding.right(), y + st::countryRowPadding.top(), width(), code);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const auto &list = current();
|
||||
if (list.empty()) {
|
||||
p.fillRect(r, st::boxBg);
|
||||
p.setFont(st::noContactsFont);
|
||||
p.setPen(st::noContactsColor);
|
||||
p.drawText(QRect(0, 0, width(), st::noContactsHeight), tr::lng_country_none(tr::now), style::al_center);
|
||||
return;
|
||||
}
|
||||
const auto l = list.size();
|
||||
if (r.intersects(QRect(0, 0, width(), st::countriesSkip))) {
|
||||
p.fillRect(r.intersected(QRect(0, 0, width(), st::countriesSkip)), st::countryRowBg);
|
||||
}
|
||||
int32 from = floorclamp(r.y() - st::countriesSkip, _rowHeight, 0, l);
|
||||
int32 to = ceilclamp(r.y() + r.height() - st::countriesSkip, _rowHeight, 0, l);
|
||||
for (int32 i = from; i < to; ++i) {
|
||||
auto selected = (i == (_pressed >= 0 ? _pressed : _selected));
|
||||
auto y = st::countriesSkip + i * _rowHeight;
|
||||
|
||||
p.fillRect(0, y, width(), _rowHeight, selected ? st::countryRowBgOver : st::countryRowBg);
|
||||
if (_ripples.size() > i && _ripples[i]) {
|
||||
_ripples[i]->paint(p, 0, y, width());
|
||||
if (_ripples[i]->empty()) {
|
||||
_ripples[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
auto code = QString("+") + list[i]->code;
|
||||
auto codeWidth = st::countryRowCodeFont->width(code);
|
||||
|
||||
auto name = QString::fromUtf8(list[i]->name);
|
||||
auto nameWidth = st::countryRowNameFont->width(name);
|
||||
auto availWidth = width() - st::countryRowPadding.left() - st::countryRowPadding.right() - codeWidth - st::boxLayerScroll.width;
|
||||
if (nameWidth > availWidth) {
|
||||
name = st::countryRowNameFont->elided(name, availWidth);
|
||||
nameWidth = st::countryRowNameFont->width(name);
|
||||
}
|
||||
|
||||
p.setFont(st::countryRowNameFont);
|
||||
p.setPen(st::countryRowNameFg);
|
||||
p.drawTextLeft(st::countryRowPadding.left(), y + st::countryRowPadding.top(), width(), name);
|
||||
|
||||
if (_type == Type::Phones) {
|
||||
p.setFont(st::countryRowCodeFont);
|
||||
p.setPen(selected ? st::countryRowCodeFgOver : st::countryRowCodeFg);
|
||||
p.drawTextLeft(st::countryRowPadding.left() + nameWidth + st::countryRowPadding.right(), y + st::countryRowPadding.top(), width(), code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,7 +345,8 @@ void CountrySelectBox::Inner::mousePressEvent(QMouseEvent *e) {
|
||||
updateSelected(e->pos());
|
||||
|
||||
setPressed(_selected);
|
||||
if (_pressed >= 0 && _pressed < countriesNow->size()) {
|
||||
const auto &list = current();
|
||||
if (_pressed >= 0 && _pressed < list.size()) {
|
||||
if (_ripples.size() <= _pressed) {
|
||||
_ripples.reserve(_pressed + 1);
|
||||
while (_ripples.size() <= _pressed) {
|
||||
@ -445,55 +375,54 @@ void CountrySelectBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::updateFilter(QString filter) {
|
||||
auto words = TextUtilities::PrepareSearchWords(filter);
|
||||
const auto words = TextUtilities::PrepareSearchWords(filter);
|
||||
filter = words.isEmpty() ? QString() : words.join(' ');
|
||||
if (_filter != filter) {
|
||||
_filter = filter;
|
||||
|
||||
if (_filter.isEmpty()) {
|
||||
countriesNow = &countriesAll;
|
||||
} else {
|
||||
QChar first = _filter[0].toLower();
|
||||
CountriesIds &ids(countriesByLetter[first]);
|
||||
|
||||
QStringList::const_iterator fb = words.cbegin(), fe = words.cend(), fi;
|
||||
|
||||
countriesFiltered.clear();
|
||||
for (CountriesIds::const_iterator i = ids.cbegin(), e = ids.cend(); i != e; ++i) {
|
||||
int index = *i;
|
||||
CountryNames &names(countriesNames[index]);
|
||||
CountryNames::const_iterator nb = names.cbegin(), ne = names.cend(), ni;
|
||||
for (fi = fb; fi != fe; ++fi) {
|
||||
QString filterName(*fi);
|
||||
for (ni = nb; ni != ne; ++ni) {
|
||||
if (ni->startsWith(*fi)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ni == ne) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fi == fe) {
|
||||
countriesFiltered.push_back(countriesAll[index]);
|
||||
}
|
||||
}
|
||||
countriesNow = &countriesFiltered;
|
||||
}
|
||||
refresh();
|
||||
_selected = countriesNow->isEmpty() ? -1 : 0;
|
||||
update();
|
||||
if (_filter == filter) {
|
||||
return;
|
||||
}
|
||||
_filter = filter;
|
||||
|
||||
const auto findWord = [&](
|
||||
const std::vector<QString> &names,
|
||||
const QString &word) {
|
||||
for (const auto &name : names) {
|
||||
if (name.startsWith(word)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const auto hasAllWords = [&](const std::vector<QString> &names) {
|
||||
for (const auto &word : words) {
|
||||
if (!findWord(names, word)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (!_filter.isEmpty()) {
|
||||
_filtered.clear();
|
||||
for (const auto index : _byLetter[_filter[0].toLower()]) {
|
||||
const auto &names = _namesList[index];
|
||||
if (hasAllWords(_namesList[index])) {
|
||||
_filtered.push_back(_list[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
refresh();
|
||||
_selected = current().empty() ? -1 : 0;
|
||||
update();
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::selectSkip(int32 dir) {
|
||||
_mouseSelection = false;
|
||||
|
||||
const auto &list = current();
|
||||
int cur = (_selected >= 0) ? _selected : -1;
|
||||
cur += dir;
|
||||
if (cur <= 0) {
|
||||
_selected = countriesNow->isEmpty() ? -1 : 0;
|
||||
} else if (cur >= countriesNow->size()) {
|
||||
_selected = list.empty() ? -1 : 0;
|
||||
} else if (cur >= list.size()) {
|
||||
_selected = -1;
|
||||
} else {
|
||||
_selected = cur;
|
||||
@ -511,21 +440,15 @@ void CountrySelectBox::Inner::selectSkipPage(int32 h, int32 dir) {
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::chooseCountry() {
|
||||
QString result;
|
||||
if (_filter.isEmpty()) {
|
||||
if (_selected >= 0 && _selected < countriesAll.size()) {
|
||||
result = countriesAll[_selected]->iso2;
|
||||
}
|
||||
} else {
|
||||
if (_selected >= 0 && _selected < countriesFiltered.size()) {
|
||||
result = countriesFiltered[_selected]->iso2;
|
||||
}
|
||||
}
|
||||
emit countryChosen(result);
|
||||
const auto &list = current();
|
||||
emit countryChosen((_selected >= 0 && _selected < list.size())
|
||||
? QString(list[_selected]->iso2)
|
||||
: QString());
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::refresh() {
|
||||
resize(width(), countriesNow->length() ? (countriesNow->length() * _rowHeight + st::countriesSkip) : st::noContactsHeight);
|
||||
const auto &list = current();
|
||||
resize(width(), list.empty() ? st::noContactsHeight : (list.size() * _rowHeight + st::countriesSkip));
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::updateSelected(QPoint localPos) {
|
||||
@ -533,7 +456,8 @@ void CountrySelectBox::Inner::updateSelected(QPoint localPos) {
|
||||
|
||||
auto in = parentWidget()->rect().contains(parentWidget()->mapFromGlobal(QCursor::pos()));
|
||||
|
||||
auto selected = (in && localPos.y() >= st::countriesSkip && localPos.y() < st::countriesSkip + countriesNow->size() * _rowHeight) ? ((localPos.y() - st::countriesSkip) / _rowHeight) : -1;
|
||||
const auto &list = current();
|
||||
auto selected = (in && localPos.y() >= st::countriesSkip && localPos.y() < st::countriesSkip + list.size() * _rowHeight) ? ((localPos.y() - st::countriesSkip) / _rowHeight) : -1;
|
||||
if (_selected != selected) {
|
||||
updateSelectedRow();
|
||||
_selected = selected;
|
||||
@ -541,6 +465,11 @@ void CountrySelectBox::Inner::updateSelected(QPoint localPos) {
|
||||
}
|
||||
}
|
||||
|
||||
auto CountrySelectBox::Inner::current() const
|
||||
-> const std::vector<not_null<const Data::CountryInfo*>> & {
|
||||
return _filter.isEmpty() ? _list : _filtered;
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::updateSelectedRow() {
|
||||
updateRow(_selected);
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
QString findValidCode(QString fullCode);
|
||||
namespace Data {
|
||||
struct CountryInfo;
|
||||
} // namespace Data
|
||||
|
||||
namespace Ui {
|
||||
class MultiSelect;
|
||||
@ -64,9 +66,6 @@ public:
|
||||
CountrySelectBox(QWidget*);
|
||||
CountrySelectBox(QWidget*, const QString &iso, Type type);
|
||||
|
||||
static QString NameByISO(const QString &iso);
|
||||
static QString ISOByPhone(const QString &phone);
|
||||
|
||||
signals:
|
||||
void countryChosen(const QString &iso);
|
||||
|
||||
@ -127,6 +126,7 @@ private:
|
||||
void updateSelectedRow();
|
||||
void updateRow(int index);
|
||||
void setPressed(int pressed);
|
||||
const std::vector<not_null<const Data::CountryInfo*>> ¤t() const;
|
||||
|
||||
Type _type = Type::Phones;
|
||||
int _rowHeight = 0;
|
||||
@ -138,4 +138,9 @@ private:
|
||||
|
||||
std::vector<std::unique_ptr<Ui::RippleAnimation>> _ripples;
|
||||
|
||||
std::vector<not_null<const Data::CountryInfo*>> _list;
|
||||
std::vector<not_null<const Data::CountryInfo*>> _filtered;
|
||||
base::flat_map<QChar, std::vector<int>> _byLetter;
|
||||
std::vector<std::vector<QString>> _namesList;
|
||||
|
||||
};
|
||||
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_countries.h" // Data::ValidPhoneCode
|
||||
#include "mainwindow.h"
|
||||
#include "numbers.h"
|
||||
#include "auth_session.h"
|
||||
@ -3968,7 +3969,7 @@ void CountryCodeInput::correctValue(
|
||||
}
|
||||
}
|
||||
if (!addToNumber.isEmpty()) {
|
||||
auto validCode = findValidCode(newText.mid(1));
|
||||
auto validCode = Data::ValidPhoneCode(newText.mid(1));
|
||||
addToNumber = newText.mid(1 + validCode.length()) + addToNumber;
|
||||
newText = '+' + validCode;
|
||||
}
|
||||
|
@ -174,6 +174,8 @@
|
||||
<(src_loc)/data/data_channel.h
|
||||
<(src_loc)/data/data_channel_admins.cpp
|
||||
<(src_loc)/data/data_channel_admins.h
|
||||
<(src_loc)/data/data_countries.cpp
|
||||
<(src_loc)/data/data_countries.h
|
||||
<(src_loc)/data/data_document.cpp
|
||||
<(src_loc)/data/data_document.h
|
||||
<(src_loc)/data/data_document_good_thumbnail.cpp
|
||||
@ -874,7 +876,6 @@
|
||||
<(src_loc)/auth_session.cpp
|
||||
<(src_loc)/auth_session.h
|
||||
<(src_loc)/config.h
|
||||
<(src_loc)/countries.h
|
||||
<(src_loc)/facades.cpp
|
||||
<(src_loc)/facades.h
|
||||
<(src_loc)/layout.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user