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 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"),
34 r(tr("Colombia"), "CO"),
35 r(tr("Czech Republic"), "CZ"),
37 r(tr("France"), "FR"),
38 r(tr("Germany"), "DE"),
40 r(tr("Greece"), "GR"),
41 r(tr("Hong Kong"), "HK"),
42 r(tr("Hungary"), "HU"),
44 r(tr("Indonesia"), "ID"),
45 r(tr("Ireland"), "IE"),
46 r(tr("Israel"), "IL"),
49 r(tr("Jordan"), "JO"),
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"),
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"),
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());
81 YTRegion YTRegions::r(const QString &name, const QString &id) {
82 YTRegion r = {id, name};
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;
97 const YTRegion &YTRegions::worldwideRegion() {
98 static const YTRegion region = {"", tr("Worldwide")};
102 void YTRegions::setRegion(const QString ®ionId) {
104 settings.setValue("regionId", regionId);
107 QString YTRegions::currentRegionId() {
109 return settings.value("regionId").toString();
112 const YTRegion &YTRegions::currentRegion() {
113 return regionById(currentRegionId());
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;
121 return worldwideRegion();
124 QIcon YTRegions::iconForRegionId(const QString ®ionId) {
125 if (regionId.isEmpty()) return QIcon(":images/worldwide.png");
126 return QIcon(":flags/" + regionId.toLower() + ".png");