Minor fix for another change in Google's movie pages and a fix in
[movie-schedule] / src / movieschedule.cpp
1 // Copyright 2010 Jochen Becher
2 //
3 // This file is part of MovieSchedule.
4 //
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.
9 //
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.
14 //
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/>.
17
18 #include "movieschedule.h"
19
20 #include "data/settings.h"
21 #include "data/cinemaschedule.h"
22 #include "control/settingscontroller.h"
23 #include "control/maincontroller.h"
24 #include "control/theatercontroller.h"
25 #include "control/moviecontroller.h"
26 #include "control/locationcontroller.h"
27 #include "control/actioncontroller.h"
28 #include "control/itemmodelsortcontroller.h"
29 #include "ui/mainwindow.h"
30 #include "ui/moviemodel.h"
31 #include "ui/moviewindow.h"
32 #include "ui/theatermodel.h"
33 #include "ui/theaterwindow.h"
34 #include "ui/ratingprovider.h"
35 #include "ui/styleutils.h"
36
37 #include <QApplication>
38 #include <QTranslator>
39 #include <QLocale>
40 #include <QThread>
41 #include <iostream>
42
43 #ifdef MAEMO_SDK
44 #include <glib-object.h>
45 #endif
46
47 #define _STRINGIZE_(x) #x
48 #define _STRINGIZE(x) _STRINGIZE_(x)
49
50 class ControllerThread : public QThread
51 {
52 public:
53     void run()
54     {
55         exec();
56     }
57
58     void quit()
59     {
60         QThread::quit();
61         wait();
62     }
63 };
64
65 MovieSchedule::MovieSchedule()
66 {
67 }
68
69 int MovieSchedule::exec(int argc, char *argv[])
70 {
71     QApplication app(argc, argv);
72
73 #ifdef MAEMO_SDK
74     g_type_init();
75 #endif
76
77     qRegisterMetaType<Location>();
78
79     StyleUtilsSingleton style_utils_singleton;
80     (void) style_utils_singleton;
81
82     QString app_dir;
83 #ifdef DEFAULT_PREFIX
84     app_dir = QApplication::applicationDirPath();
85 #else
86     app_dir = _STRINGIZE(DATADIR) "/movie-schedule";
87 #endif
88     //std::cout << "app_dir = " << qPrintable(app_dir) << std::endl;
89
90     QString locale = QLocale::system().name();
91     //std::cout << "locale: " << qPrintable(locale) << std::endl;
92
93 #if 1
94     QTranslator translator;
95     translator.load(app_dir + "/translations/movie-schedule_" + locale);
96     app.installTranslator(&translator);
97 #endif
98
99     RatingSingleton rating_singleton;
100     (void) rating_singleton;
101
102     CinemaSchedule cinema_schedule;
103
104     MainWindow main_window(&cinema_schedule);
105     main_window.show();
106
107     Settings settings;
108     SettingsController settings_controller(&main_window, &settings);
109     settings_controller.Load();
110
111     ActionController action_controller(&cinema_schedule);
112
113     ControllerThread sort_worker;
114     sort_worker.start();
115
116     ControllerThread search_worker;
117     search_worker.start();
118
119     ItemModelSortController sort_controller(&cinema_schedule);
120     sort_controller.moveToThread(&sort_worker);
121
122     TheaterWindow theater_window(&cinema_schedule, &main_window);
123     TheaterController theater_controller(&theater_window, &cinema_schedule, &action_controller,
124                                          &sort_controller, &search_worker);
125
126     MovieWindow movie_window(&cinema_schedule, &main_window);
127     MovieController movie_controller(&movie_window, &cinema_schedule, &action_controller,
128                                      &sort_controller, &search_worker);
129
130     LocationController location_controller(&main_window, &settings);
131
132     MainController main_controller(&main_window, &settings, &cinema_schedule, &theater_controller,
133                                    &movie_controller, &location_controller, &action_controller,
134                                    &settings_controller, &sort_controller, &search_worker);
135
136     settings_controller.EmitInitialSettings();
137     main_controller.Run();
138
139     int rc = app.exec();
140
141     if (rc == 0) {
142         settings_controller.Save();
143     }
144
145     search_worker.quit();
146
147     sort_worker.quit();
148
149     return rc;
150 }