]> git.sur5r.net Git - minitube/blob - src/ytregions.cpp
e24147b3f0860a6c8dbb4c72e24aa2abb609eb26
[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 QVector<YTRegion> &YTRegions::list() {
26     static const QVector<YTRegion> list = [] {
27         QVector<YTRegion> l = {r(tr("Algeria"), "DZ"),
28                                r(tr("Argentina"), "AR"),
29                                r(tr("Australia"), "AU"),
30                                r(tr("Belgium"), "BE"),
31                                r(tr("Brazil"), "BR"),
32                                r(tr("Canada"), "CA"),
33                                r(tr("Chile"), "CL"),
34                                r(tr("Colombia"), "CO"),
35                                r(tr("Czech Republic"), "CZ"),
36                                r(tr("Egypt"), "EG"),
37                                r(tr("France"), "FR"),
38                                r(tr("Germany"), "DE"),
39                                r(tr("Ghana"), "GH"),
40                                r(tr("Greece"), "GR"),
41                                r(tr("Hong Kong"), "HK"),
42                                r(tr("Hungary"), "HU"),
43                                r(tr("India"), "IN"),
44                                r(tr("Indonesia"), "ID"),
45                                r(tr("Ireland"), "IE"),
46                                r(tr("Israel"), "IL"),
47                                r(tr("Italy"), "IT"),
48                                r(tr("Japan"), "JP"),
49                                r(tr("Jordan"), "JO"),
50                                r(tr("Kenya"), "KE"),
51                                r(tr("Malaysia"), "MY"),
52                                r(tr("Mexico"), "MX"),
53                                r(tr("Morocco"), "MA"),
54                                r(tr("Netherlands"), "NL"),
55                                r(tr("New Zealand"), "NZ"),
56                                r(tr("Nigeria"), "NG"),
57                                r(tr("Peru"), "PE"),
58                                r(tr("Philippines"), "PH"),
59                                r(tr("Poland"), "PL"),
60                                r(tr("Russia"), "RU"),
61                                r(tr("Saudi Arabia"), "SA"),
62                                r(tr("Singapore"), "SG"),
63                                r(tr("South Africa"), "ZA"),
64                                r(tr("South Korea"), "KR"),
65                                r(tr("Spain"), "ES"),
66                                r(tr("Sweden"), "SE"),
67                                r(tr("Taiwan"), "TW"),
68                                r(tr("Tunisia"), "TN"),
69                                r(tr("Turkey"), "TR"),
70                                r(tr("Uganda"), "UG"),
71                                r(tr("United Arab Emirates"), "AE"),
72                                r(tr("United Kingdom"), "GB"),
73                                r(tr("Yemen"), "YE")};
74         std::sort(l.begin(), l.end());
75         return l;
76     }();
77
78     return list;
79 }
80
81 YTRegion YTRegions::r(const QString &name, const QString &id) {
82     YTRegion r = {id, name};
83     return r;
84 }
85
86 const YTRegion &YTRegions::localRegion() {
87     static const YTRegion region = [] {
88         QString country = QLocale::system().name().right(2);
89         for (const YTRegion &r : list()) {
90             if (r.id == country) return r;
91         }
92         return YTRegion();
93     }();
94     return region;
95 }
96
97 const YTRegion &YTRegions::worldwideRegion() {
98     static const YTRegion region = {"", tr("Worldwide")};
99     return region;
100 }
101
102 void YTRegions::setRegion(const QString &regionId) {
103     QSettings settings;
104     settings.setValue("regionId", regionId);
105 }
106
107 QString YTRegions::currentRegionId() {
108     QSettings settings;
109     return settings.value("regionId").toString();
110 }
111
112 const YTRegion &YTRegions::currentRegion() {
113     return regionById(currentRegionId());
114 }
115
116 const YTRegion &YTRegions::regionById(const QString &id) {
117     if (id.isEmpty()) return worldwideRegion();
118     for (const YTRegion &r : list()) {
119         if (r.id == id) return r;
120     }
121     return worldwideRegion();
122 }
123
124 QIcon YTRegions::iconForRegionId(const QString &regionId) {
125     if (regionId.isEmpty()) return QIcon(":images/worldwide.png");
126     return QIcon(":flags/" + regionId.toLower() + ".png");
127 }