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"
27 #include <QLayoutItem>
29 ContextDialog::ContextDialog(CinemaSchedule *cinema_schedule, QWidget *parent) :
31 ui(new Ui::ContextDialog),
32 _cinema_schedule(cinema_schedule),
38 connect(ui->add_to_calendar, SIGNAL(clicked()), this, SLOT(AddToCalendar()));
39 connect(ui->call_theater_by_phone, SIGNAL(clicked()), this, SLOT(CallTheaterByPhone()));
40 connect(ui->find_route_to_theater, SIGNAL(clicked()), this, SLOT(FindRouteToTheater()));
41 connect(ui->search_movie_in_web, SIGNAL(clicked()), this, SLOT(SearchMovieInWeb()));
42 connect(ui->search_theater_in_web, SIGNAL(clicked()), this, SLOT(SearchTheaterInWeb()));
45 ContextDialog::~ContextDialog()
50 void ContextDialog::Show(ScheduleEntryKey schedule_entry_key)
53 _schedule_entry_key = schedule_entry_key;
54 AssertedReadLocker locker(_cinema_schedule->GetLock());
55 ScheduleEntry schedule_entry = _cinema_schedule->FindScheduleEntry(_schedule_entry_key);
56 if (schedule_entry.IsValid()) {
57 addWidget(ui->add_to_calendar);
58 if (!schedule_entry.GetCinema()->GetTelephone().isEmpty()) {
59 addWidget(ui->call_theater_by_phone);
61 if (!schedule_entry.GetCinema()->GetAddress().isEmpty()) {
62 // TODO enable if find route is implemented
63 // addWidget(ui->find_route_to_theater);
65 addWidget(ui->search_movie_in_web);
66 if (!schedule_entry.GetCinema()->GetAddress().isEmpty()) {
67 addWidget(ui->search_theater_in_web);
74 void ContextDialog::changeEvent(QEvent *e)
76 QDialog::changeEvent(e);
78 case QEvent::LanguageChange:
79 ui->retranslateUi(this);
86 void ContextDialog::removeAllWidgets()
89 while ((item = ui->gridLayout->itemAt(0)) != 0) {
90 if (item->widget() != 0) {
91 item->widget()->setVisible(false);
93 ui->gridLayout->removeItem(item);
99 void ContextDialog::addWidget(QWidget *widget)
101 widget->setVisible(true);
102 ui->gridLayout->addWidget(widget, _next_row, _next_column, 1, 1);
104 if (_next_column > 1) {
110 void ContextDialog::AddToCalendar()
113 emit AddToCalendar(_schedule_entry_key);
116 void ContextDialog::CallTheaterByPhone()
119 emit CallTheaterByPhone(_schedule_entry_key.GetCinemaKey());
122 void ContextDialog::FindRouteToTheater()
125 emit FindRouteToTheater(_schedule_entry_key.GetCinemaKey());
128 void ContextDialog::SearchMovieInWeb()
131 emit SearchMovieInWeb(_schedule_entry_key.GetMovieKey());
134 void ContextDialog::SearchTheaterInWeb()
137 emit SearchTheaterInWeb(_schedule_entry_key.GetCinemaKey());