3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #include "ytregions.h"
22 #include "iconutils.h"
24 YTRegions::YTRegions() : QObject() {}
26 const QVector<YTRegion> &YTRegions::list() {
27 static const QVector<YTRegion> list = [] {
28 QVector<YTRegion> l = {r(tr("Algeria"), "DZ"),
29 r(tr("Argentina"), "AR"),
30 r(tr("Australia"), "AU"),
31 r(tr("Belgium"), "BE"),
32 r(tr("Brazil"), "BR"),
33 r(tr("Canada"), "CA"),
35 r(tr("Colombia"), "CO"),
36 r(tr("Czech Republic"), "CZ"),
38 r(tr("France"), "FR"),
39 r(tr("Germany"), "DE"),
41 r(tr("Greece"), "GR"),
42 r(tr("Hong Kong"), "HK"),
43 r(tr("Hungary"), "HU"),
45 r(tr("Indonesia"), "ID"),
46 r(tr("Ireland"), "IE"),
47 r(tr("Israel"), "IL"),
50 r(tr("Jordan"), "JO"),
52 r(tr("Malaysia"), "MY"),
53 r(tr("Mexico"), "MX"),
54 r(tr("Morocco"), "MA"),
55 r(tr("Netherlands"), "NL"),
56 r(tr("New Zealand"), "NZ"),
57 r(tr("Nigeria"), "NG"),
59 r(tr("Philippines"), "PH"),
60 r(tr("Poland"), "PL"),
61 r(tr("Russia"), "RU"),
62 r(tr("Saudi Arabia"), "SA"),
63 r(tr("Singapore"), "SG"),
64 r(tr("South Africa"), "ZA"),
65 r(tr("South Korea"), "KR"),
67 r(tr("Sweden"), "SE"),
68 r(tr("Taiwan"), "TW"),
69 r(tr("Tunisia"), "TN"),
70 r(tr("Turkey"), "TR"),
71 r(tr("Uganda"), "UG"),
72 r(tr("United Arab Emirates"), "AE"),
73 r(tr("United Kingdom"), "GB"),
74 r(tr("Yemen"), "YE")};
75 std::sort(l.begin(), l.end());
82 YTRegion YTRegions::r(const QString &name, const QString &id) {
83 YTRegion r = {id, name};
87 const YTRegion &YTRegions::localRegion() {
88 static const YTRegion region = []() -> YTRegion {
89 QString country = QLocale::system().name().right(2);
90 for (const YTRegion &r : list()) {
91 if (r.id == country) return r;
98 const YTRegion &YTRegions::worldwideRegion() {
99 static const YTRegion region = {"", tr("Worldwide")};
103 void YTRegions::setRegion(const QString ®ionId) {
105 settings.setValue("regionId", regionId);
108 QString YTRegions::currentRegionId() {
110 return settings.value("regionId").toString();
113 const YTRegion &YTRegions::currentRegion() {
114 return regionById(currentRegionId());
117 const YTRegion &YTRegions::regionById(const QString &id) {
118 if (id.isEmpty()) return worldwideRegion();
119 for (const YTRegion &r : list()) {
120 if (r.id == id) return r;
122 return worldwideRegion();
125 QIcon YTRegions::iconForRegionId(const QString ®ionId) {
126 if (regionId.isEmpty()) return IconUtils::icon("worldwide");
127 return QIcon(":flags/" + regionId.toLower() + ".png");