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"
23 YTRegions::YTRegions() : QObject() { }
25 const QList<YTRegion> & YTRegions::list() {
26 static QList<YTRegion> list;
28 list << 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")
34 << r(tr("Chile"), "CL")
35 << r(tr("Colombia"), "CO")
36 << r(tr("Czech Republic"), "CZ")
37 << r(tr("Egypt"), "EG")
38 << r(tr("France"), "FR")
39 << r(tr("Germany"), "DE")
40 << r(tr("Ghana"), "GH")
41 << r(tr("Greece"), "GR")
42 << r(tr("Hong Kong"), "HK")
43 << r(tr("Hungary"), "HU")
44 << r(tr("India"), "IN")
45 << r(tr("Indonesia"), "ID")
46 << r(tr("Ireland"), "IE")
47 << r(tr("Israel"), "IL")
48 << r(tr("Italy"), "IT")
49 << r(tr("Japan"), "JP")
50 << r(tr("Jordan"), "JO")
51 << r(tr("Kenya"), "KE")
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")
58 << r(tr("Peru"), "PE")
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")
66 << r(tr("Spain"), "ES")
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");
76 list << r(QLocale::Algeria, "DZ")
77 << r(QLocale::Argentina, "AR")
78 << r(QLocale::Australia, "AU")
79 << r(QLocale::Belgium, "BE")
80 << r(QLocale::Brazil, "BR")
81 << r(QLocale::Canada, "CA")
82 << r(QLocale::Chile, "CL")
83 << r(QLocale::Colombia, "CO")
84 << r(QLocale::CzechRepublic, "CZ")
85 << r(QLocale::Egypt, "EG")
86 << r(QLocale::France, "FR")
87 << r(QLocale::Germany, "DE")
88 << r(QLocale::Ghana, "GH")
89 << r(QLocale::Greece, "GR")
90 << r(QLocale::HongKong, "HK")
91 << r(QLocale::Hungary, "HU")
92 << r(QLocale::India, "IN")
93 << r(QLocale::Indonesia, "ID")
94 << r(QLocale::Ireland, "IE")
95 << r(QLocale::Israel, "IL")
96 << r(QLocale::Italy, "IT")
97 << r(QLocale::Japan, "JP")
98 << r(QLocale::Jordan, "JO")
99 << r(QLocale::Kenya, "KE")
100 << r(QLocale::Malaysia, "MY")
101 << r(QLocale::Mexico, "MX")
102 << r(QLocale::Morocco, "MA")
103 << r(QLocale::Netherlands, "NL")
104 << r(QLocale::NewZealand, "NZ")
105 << r(QLocale::Nigeria, "NG")
106 << r(QLocale::Peru, "PE")
107 << r(QLocale::Philippines, "PH")
108 << r(QLocale::Poland, "PL")
109 << r(QLocale::RussianFederation, "RU")
110 << r(QLocale::SaudiArabia, "SA")
111 << r(QLocale::Singapore, "SG")
112 << r(QLocale::SouthAfrica, "ZA")
113 << r(QLocale::RepublicOfKorea, "KR")
114 << r(QLocale::Spain, "ES")
115 << r(QLocale::Sweden, "SE")
116 << r(QLocale::Taiwan, "TW")
117 << r(QLocale::Tunisia, "TN")
118 << r(QLocale::Turkey, "TR")
119 << r(QLocale::Uganda, "UG")
120 << r(QLocale::UnitedArabEmirates, "AE")
121 << r(QLocale::UnitedKingdom, "GB")
122 << r(QLocale::Yemen, "YE");
129 YTRegion YTRegions::r(const QString &name, const QString &id) {
130 YTRegion r = {id, name};
134 const YTRegion & YTRegions::localRegion() {
135 static YTRegion region;
136 if (region.name.isEmpty()) {
137 QString country = QLocale::system().name().right(2);
138 foreach (YTRegion r, list())
139 if (r.id == country) {
142 } // else qDebug() << r.id << country;
147 const YTRegion & YTRegions::worldwideRegion() {
148 static YTRegion region = {"", tr("Worldwide")};
152 void YTRegions::setRegion(const QString ®ionId) {
154 settings.setValue("regionId", regionId);
157 QString YTRegions::currentRegionId() {
159 return settings.value("regionId").toString();
162 YTRegion YTRegions::currentRegion() {
163 return regionById(currentRegionId());
166 YTRegion YTRegions::regionById(const QString &id) {
167 if (id.isEmpty()) return worldwideRegion();
169 foreach (YTRegion r, list())
174 if (region.name.isEmpty()) return worldwideRegion();
178 QIcon YTRegions::iconForRegionId(const QString ®ionId) {
179 if (regionId.isEmpty()) return QIcon(":images/worldwide.png");
180 return QIcon(":flags/" + regionId.toLower() + ".png");