]> git.sur5r.net Git - minitube/blob - src/regionsview.cpp
Big 2.1 commit
[minitube] / src / regionsview.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 "regionsview.h"
22 #include "ytregions.h"
23 #include "mainwindow.h"
24
25 RegionsView::RegionsView(QWidget *parent) : QWidget(parent) {
26     QBoxLayout *l = new QVBoxLayout(this);
27     l->setMargin(30);
28     l->setSpacing(30);
29
30     layout = new QGridLayout();
31     layout->setMargin(0);
32     layout->setSpacing(0);
33     l->addLayout(layout);
34
35     addRegion(YTRegions::worldwideRegion());
36     foreach(YTRegion region, YTRegions::list())
37         addRegion(region);
38
39     doneButton = new QPushButton(tr("Done"));
40     doneButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
41     doneButton->setDefault(true);
42     doneButton->setProperty("custom", true);
43     doneButton->setProperty("important", true);
44     doneButton->setProperty("big", true);
45     connect(doneButton, SIGNAL(clicked()), MainWindow::instance(), SLOT(goBack()));
46     l->addWidget(doneButton, 0, Qt::AlignCenter);
47 }
48
49 void RegionsView::addRegion(const YTRegion &region) {
50     QPushButton *button = new QPushButton(region.name);
51     button->setProperty("regionId", region.id);
52     button->setCheckable(true);
53     button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
54     button->setFocusPolicy(Qt::StrongFocus);
55     button->setIcon(YTRegions::iconForRegionId(region.id));
56     connect(button, SIGNAL(clicked()), SLOT(buttonClicked()));
57     const int i = layout->count();
58     static const int rows = 10;
59     layout->addWidget(button, i % rows, i / rows);
60 }
61
62 void RegionsView::appear() {
63     doneButton->setFocus();
64
65     QString currentRegionId = YTRegions::currentRegionId();
66     for (int i = 0; i < layout->count(); i++) {
67         QLayoutItem *item = layout->itemAt(i);
68         QPushButton *b = static_cast<QPushButton*>(item->widget());
69         QString regionId = b->property("regionId").toString();
70         b->setChecked(currentRegionId == regionId);
71     }
72 }
73
74 void RegionsView::buttonClicked() {
75     QObject* o = sender();
76     QString regionId = o->property("regionId").toString();
77     YTRegions::setRegion(regionId);
78     emit regionChanged();
79     doneButton->click();
80
81     // uncheck other buttons
82     /*
83     for (int i = 0; i < layout->count(); i++) {
84         QLayoutItem *item = layout->itemAt(i);
85         QPushButton *b = static_cast<QPushButton*>(item->widget());
86         if (b != o && b->isChecked()) b->setChecked(false);
87     }
88     */
89 }