]> git.sur5r.net Git - minitube/blob - src/ytregions.cpp
Imported Upstream version 2.5.1
[minitube] / src / ytregions.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
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.
10
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.
15
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/>.
18
19 $END_LICENSE */
20
21 #include "ytregions.h"
22
23 YTRegions::YTRegions() : QObject() { }
24
25 const QList<YTRegion> & YTRegions::list() {
26     static QList<YTRegion> list;
27     if (list.isEmpty()) {
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");
75 /*
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");
123              */
124         qSort(list);
125     }
126     return list;
127 }
128
129 YTRegion YTRegions::r(const QString &name, const QString &id) {
130     YTRegion r = {id, name};
131     return r;
132 }
133
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) {
140                 region = r;
141                 break;
142             } // else qDebug() << r.id << country;
143     }
144     return region;
145 }
146
147 const YTRegion & YTRegions::worldwideRegion() {
148     static YTRegion region = {"", tr("Worldwide")};
149     return region;
150 }
151
152 void YTRegions::setRegion(const QString &regionId) {
153     QSettings settings;
154     settings.setValue("regionId", regionId);
155 }
156
157 QString YTRegions::currentRegionId() {
158     QSettings settings;
159     return settings.value("regionId").toString();
160 }
161
162 YTRegion YTRegions::currentRegion() {
163     return regionById(currentRegionId());
164 }
165
166 YTRegion YTRegions::regionById(const QString &id) {
167     if (id.isEmpty()) return worldwideRegion();
168     YTRegion region;
169     foreach (YTRegion r, list())
170         if (r.id == id) {
171             region = r;
172             break;
173         }
174     if (region.name.isEmpty()) return worldwideRegion();
175     return region;
176 }
177
178 QIcon YTRegions::iconForRegionId(const QString &regionId) {
179     if (regionId.isEmpty()) return QIcon(":images/worldwide.png");
180     return QIcon(":flags/" + regionId.toLower() + ".png");
181 }