2019-06-22 12:01:54 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
2021-08-26 14:46:24 +00:00
|
|
|
namespace Countries {
|
2019-06-22 12:01:54 +00:00
|
|
|
|
2021-08-27 09:02:47 +00:00
|
|
|
struct CallingCodeInfo {
|
|
|
|
QString callingCode;
|
|
|
|
std::vector<QString> prefixes;
|
|
|
|
std::vector<QString> patterns;
|
|
|
|
};
|
|
|
|
|
2021-08-26 14:53:59 +00:00
|
|
|
struct Info {
|
2021-08-26 16:01:31 +00:00
|
|
|
QString name;
|
|
|
|
QString iso2;
|
|
|
|
QString alternativeName;
|
2021-08-27 09:02:47 +00:00
|
|
|
std::vector<CallingCodeInfo> codes;
|
|
|
|
bool isHidden = false;
|
2019-06-22 12:01:54 +00:00
|
|
|
};
|
|
|
|
|
2021-08-27 14:07:04 +00:00
|
|
|
struct FormatResult {
|
|
|
|
QString formatted;
|
2021-08-27 14:09:31 +00:00
|
|
|
QVector<int> groups;
|
2021-08-29 19:15:35 +00:00
|
|
|
QString code;
|
2021-08-27 14:07:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FormatArgs {
|
|
|
|
QString phone;
|
2021-08-27 14:09:31 +00:00
|
|
|
bool onlyGroups = false;
|
|
|
|
bool skipCode = false;
|
2021-08-27 14:28:00 +00:00
|
|
|
bool incomplete = false;
|
2021-08-29 19:15:35 +00:00
|
|
|
bool onlyCode = false;
|
2021-08-27 14:07:04 +00:00
|
|
|
};
|
|
|
|
|
2021-08-26 15:15:49 +00:00
|
|
|
class CountriesInstance final {
|
|
|
|
public:
|
|
|
|
using Map = QHash<QString, const Info *>;
|
2019-06-22 12:01:54 +00:00
|
|
|
|
2021-08-26 15:22:54 +00:00
|
|
|
CountriesInstance();
|
|
|
|
[[nodiscard]] const std::vector<Info> &list();
|
|
|
|
void setList(std::vector<Info> &&infos);
|
2019-06-22 12:01:54 +00:00
|
|
|
|
2021-08-26 15:15:49 +00:00
|
|
|
[[nodiscard]] const Map &byCode();
|
|
|
|
[[nodiscard]] const Map &byISO2();
|
|
|
|
|
|
|
|
[[nodiscard]] QString validPhoneCode(QString fullCode);
|
|
|
|
[[nodiscard]] QString countryNameByISO2(const QString &iso);
|
|
|
|
[[nodiscard]] QString countryISO2ByPhone(const QString &phone);
|
|
|
|
|
2021-08-27 14:07:04 +00:00
|
|
|
[[nodiscard]] FormatResult format(FormatArgs args);
|
|
|
|
|
2021-09-02 20:24:53 +00:00
|
|
|
[[nodiscard]] rpl::producer<> updated() const;
|
|
|
|
|
2021-08-26 15:15:49 +00:00
|
|
|
private:
|
2021-08-26 15:22:54 +00:00
|
|
|
std::vector<Info> _list;
|
|
|
|
|
2021-08-26 15:15:49 +00:00
|
|
|
Map _byCode;
|
|
|
|
Map _byISO2;
|
|
|
|
|
2021-09-02 20:24:53 +00:00
|
|
|
rpl::event_stream<> _updated;
|
|
|
|
|
2021-08-26 15:15:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CountriesInstance &Instance();
|
2019-06-22 12:01:54 +00:00
|
|
|
|
2021-08-29 19:15:35 +00:00
|
|
|
[[nodiscard]] QString ExtractPhoneCode(const QString &phone);
|
|
|
|
|
2021-08-26 14:46:24 +00:00
|
|
|
} // namespace Countries
|