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 "regionsview.h"
22 #include "ytregions.h"
23 #include "mainwindow.h"
25 RegionsView::RegionsView(QWidget *parent) : View(parent) {
26 QBoxLayout *l = new QVBoxLayout(this);
30 layout = new QGridLayout();
32 layout->setSpacing(0);
35 addRegion(YTRegions::worldwideRegion());
36 foreach(YTRegion region, YTRegions::list())
39 doneButton = new QPushButton(tr("Done"));
40 doneButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
41 doneButton->setDefault(true);
43 doneButton->setProperty("custom", true);
44 doneButton->setProperty("important", true);
45 doneButton->setProperty("big", true);
47 connect(doneButton, SIGNAL(clicked()), MainWindow::instance(), SLOT(goBack()));
48 l->addWidget(doneButton, 0, Qt::AlignHCenter | Qt::AlignTop);
51 void RegionsView::addRegion(const YTRegion ®ion) {
52 QPushButton *button = new QPushButton(region.name);
53 button->setProperty("regionId", region.id);
54 button->setCheckable(true);
55 button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
56 button->setFocusPolicy(Qt::StrongFocus);
57 button->setIcon(YTRegions::iconForRegionId(region.id));
58 connect(button, SIGNAL(clicked()), SLOT(buttonClicked()));
59 const int i = layout->count();
60 static const int rows = 10;
61 layout->addWidget(button, i % rows, i / rows);
64 void RegionsView::appear() {
65 doneButton->setFocus();
67 QString currentRegionId = YTRegions::currentRegionId();
68 for (int i = 0; i < layout->count(); i++) {
69 QLayoutItem *item = layout->itemAt(i);
70 QPushButton *b = static_cast<QPushButton*>(item->widget());
71 QString regionId = b->property("regionId").toString();
72 b->setChecked(currentRegionId == regionId);
76 void RegionsView::buttonClicked() {
77 QObject* o = sender();
78 QString regionId = o->property("regionId").toString();
79 YTRegions::setRegion(regionId);
83 // uncheck other buttons
85 for (int i = 0; i < layout->count(); i++) {
86 QLayoutItem *item = layout->itemAt(i);
87 QPushButton *b = static_cast<QPushButton*>(item->widget());
88 if (b != o && b->isChecked()) b->setChecked(false);