]> git.sur5r.net Git - minitube/blob - src/ytregions.cpp
Upload 3.9.3-2 to unstable
[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 #include "iconutils.h"
23
24 YTRegions::YTRegions() : QObject() {}
25
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"),
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         std::sort(l.begin(), l.end());
76         return l;
77     }();
78
79     return list;
80 }
81
82 YTRegion YTRegions::r(const QString &name, const QString &id) {
83     YTRegion r = {id, name};
84     return r;
85 }
86
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;
92         }
93         return YTRegion();
94     }();
95     return region;
96 }
97
98 const YTRegion &YTRegions::worldwideRegion() {
99     static const YTRegion region = {"", tr("Worldwide")};
100     return region;
101 }
102
103 void YTRegions::setRegion(const QString &regionId) {
104     QSettings settings;
105     settings.setValue("regionId", regionId);
106 }
107
108 QString YTRegions::currentRegionId() {
109     QSettings settings;
110     return settings.value("regionId").toString();
111 }
112
113 const YTRegion &YTRegions::currentRegion() {
114     return regionById(currentRegionId());
115 }
116
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;
121     }
122     return worldwideRegion();
123 }
124
125 QIcon YTRegions::iconForRegionId(const QString &regionId) {
126     if (regionId.isEmpty()) return IconUtils::icon("worldwide");
127     return QIcon(":flags/" + regionId.toLower() + ".png");
128 }