1 // Copyright 2010 Jochen Becher
3 // This file is part of MovieSchedule.
5 // MovieSchedule is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // MovieSchedule is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with MovieSchedule. If not, see <http://www.gnu.org/licenses/>.
18 #include "locationdialog.h"
19 #include "ui_locationdialog.h"
21 LocationDialog::LocationDialog(QWidget *parent) :
23 ui(new Ui::LocationDialog)
26 ui->_button_box->addButton(ui->Search, QDialogButtonBox::AcceptRole);
27 connect(ui->_button_box, SIGNAL(accepted()), this, SLOT(SearchClicked()));
28 connect(ui->_button_box, SIGNAL(rejected()), this, SLOT(deleteLater()));
29 connect(ui->GPS, SIGNAL(clicked()), this, SLOT(GPSClicked()));
30 connect(ui->Location1, SIGNAL(clicked()), this, SLOT(PreviousLocation1Clicked()));
31 connect(ui->Location2, SIGNAL(clicked()), this, SLOT(PreviousLocation2Clicked()));
32 connect(ui->Location3, SIGNAL(clicked()), this, SLOT(PreviousLocation3Clicked()));
33 connect(ui->Location4, SIGNAL(clicked()), this, SLOT(PreviousLocation4Clicked()));
34 connect(ui->Location5, SIGNAL(clicked()), this, SLOT(PreviousLocation5Clicked()));
35 connect(this, SIGNAL(accepted()), this, SLOT(SearchClicked()));
36 connect(this, SIGNAL(rejected()), this, SIGNAL(Cancel()));
37 _location_buttons.append(ui->Location1);
38 _location_buttons.append(ui->Location2);
39 _location_buttons.append(ui->Location3);
40 _location_buttons.append(ui->Location4);
41 _location_buttons.append(ui->Location5);
44 LocationDialog::~LocationDialog()
49 void LocationDialog::SetLocation(const Location &location)
51 ui->Location->setText(location.GetLocationName());
54 void LocationDialog::SetPreviousLocations(const Locations &previous_locations)
56 _previous_locations = previous_locations;
57 QListIterator<Location> it(_previous_locations);
59 while (it.hasNext() && i < _location_buttons.size()) {
60 const Location &location = it.next();
61 if (location.IsValid()) {
62 _location_buttons[i]->setText(location.GetLocationName());
63 _location_buttons[i]->setVisible(true);
64 _location_buttons[i]->setEnabled(true);
68 while (i < _location_buttons.size()) {
69 _location_buttons[i]->setVisible(false);
70 _location_buttons[i]->setEnabled(false);
75 void LocationDialog::SetGPSEnabled(bool gps_enabled)
77 ui->GPS->setVisible(gps_enabled);
78 ui->GPS->setEnabled(gps_enabled);
81 void LocationDialog::show()
83 ui->gridLayout->removeWidget(ui->GPS);
84 for (int i = 0; i < _location_buttons.size(); ++i) {
85 ui->gridLayout->removeWidget(_location_buttons[i]);
89 if (ui->GPS->isEnabled()) {
90 ui->gridLayout->addWidget(ui->GPS, row, column);
93 for (int i = 0; i < _location_buttons.size(); ++i) {
94 if (_location_buttons[i]->isEnabled()) {
95 ui->gridLayout->addWidget(_location_buttons[i], row, column);
103 for (int i = 0; i < _location_buttons.size(); ++i) {
104 if (_location_buttons[i]->text() == ui->Location->text()) {
105 ui->Location->setText("");
110 ui->Search->setDefault(true);
111 ui->Location->setFocus();
115 void LocationDialog::SearchClicked()
118 location.SetLocationName(ui->Location->text());
119 if (location.IsValid()) {
120 emit Search(location);
126 void LocationDialog::GPSClicked()
133 void LocationDialog::PreviousLocation1Clicked()
135 PreviousLocationClicked(0);
138 void LocationDialog::PreviousLocation2Clicked()
140 PreviousLocationClicked(1);
143 void LocationDialog::PreviousLocation3Clicked()
145 PreviousLocationClicked(2);
148 void LocationDialog::PreviousLocation4Clicked()
150 PreviousLocationClicked(3);
153 void LocationDialog::PreviousLocation5Clicked()
155 PreviousLocationClicked(4);
158 void LocationDialog::PreviousLocationClicked(int i)
161 location.SetLocationName(_location_buttons[i]->text());
162 emit SearchPreviousLocation(location);
167 void LocationDialog::changeEvent(QEvent *e)
169 QDialog::changeEvent(e);
171 case QEvent::LanguageChange:
172 ui->retranslateUi(this);