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 "contextdialog.h"
19 #include "ui_contextdialog.h"
21 #include "data/cinemaschedule.h"
22 #include "data/scheduleentrykey.h"
23 #include "data/cinema.h"
24 #include "data/movie.h"
25 #include "utils/assertedlocker.h"
28 #include <QLayoutItem>
29 #include <QDesktopWidget>
31 ContextDialog::ContextDialog(CinemaSchedule *cinema_schedule, QWidget *parent) :
33 ui(new Ui::ContextDialog),
34 _cinema_schedule(cinema_schedule),
40 connect(ui->add_to_calendar, SIGNAL(clicked()), this, SLOT(AddToCalendar()));
41 connect(ui->call_theater_by_phone, SIGNAL(clicked()), this, SLOT(CallTheaterByPhone()));
42 connect(ui->find_route_to_theater, SIGNAL(clicked()), this, SLOT(FindRouteToTheater()));
43 connect(ui->search_movie_in_web, SIGNAL(clicked()), this, SLOT(SearchMovieInWeb()));
44 connect(ui->search_theater_in_web, SIGNAL(clicked()), this, SLOT(SearchTheaterInWeb()));
45 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(Rotate()));
49 ContextDialog::~ContextDialog()
54 void ContextDialog::Show(ScheduleEntryKey schedule_entry_key)
57 _schedule_entry_key = schedule_entry_key;
58 AssertedReadLocker locker(_cinema_schedule->GetLock());
59 ScheduleEntry schedule_entry = _cinema_schedule->FindScheduleEntry(_schedule_entry_key);
60 if (schedule_entry.IsValid()) {
61 addWidget(ui->add_to_calendar);
62 if (!schedule_entry.GetCinema()->GetTelephone().isEmpty()) {
63 addWidget(ui->call_theater_by_phone);
65 if (!schedule_entry.GetCinema()->GetAddress().isEmpty()) {
66 // TODO enable if find route is implemented
67 // addWidget(ui->find_route_to_theater);
69 addWidget(ui->search_movie_in_web);
70 if (!schedule_entry.GetCinema()->GetAddress().isEmpty()) {
71 addWidget(ui->search_theater_in_web);
78 void ContextDialog::changeEvent(QEvent *e)
80 QDialog::changeEvent(e);
82 case QEvent::LanguageChange:
83 ui->retranslateUi(this);
90 void ContextDialog::removeAllWidgets()
93 while ((item = ui->gridLayout->itemAt(0)) != 0) {
94 if (item->widget() != 0) {
95 item->widget()->setVisible(false);
97 ui->gridLayout->removeItem(item);
103 void ContextDialog::addWidget(QWidget *widget)
105 bool landscape = UiUtils::IsLandscape();
106 widget->setVisible(true);
107 ui->gridLayout->addWidget(widget, _next_row, _next_column, 1, 1);
109 if (_next_column > (landscape ? 1 : 0)) {
115 void ContextDialog::AddToCalendar()
118 emit AddToCalendar(_schedule_entry_key);
121 void ContextDialog::CallTheaterByPhone()
124 emit CallTheaterByPhone(_schedule_entry_key.GetCinemaKey());
127 void ContextDialog::FindRouteToTheater()
130 emit FindRouteToTheater(_schedule_entry_key.GetCinemaKey());
133 void ContextDialog::SearchMovieInWeb()
136 emit SearchMovieInWeb(_schedule_entry_key.GetMovieKey());
139 void ContextDialog::SearchTheaterInWeb()
142 emit SearchTheaterInWeb(_schedule_entry_key.GetCinemaKey());
145 void ContextDialog::Rotate()
148 Show(_schedule_entry_key);