2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
19 #include "mainwindow.h"
23 #include <QNetworkProxy>
25 #include <sqlengine.h>
28 #include <eventmodel.h>
31 #include <conference.h>
34 #include <QMessageBox>
36 #include <eventdialog.h>
37 #include "daynavigatorwidget.h"
38 #include "importschedulewidget.h"
39 #include "mapwindow.h"
40 #include "settingsdialog.h"
42 #include <tabcontainer.h>
43 #include <appsettings.h>
45 const QString PROXY_USERNAME;
46 const QString PROXY_PASSWD;
48 MainWindow::MainWindow(int aEventId, QWidget *aParent)
49 : QMainWindow(aParent)
54 tabWidget->setTabText(1,"Favs");
55 //tabWidget->setTabText(2,"Day");
58 // first time run aplication: -> let's have it direct connection in this case
59 if(!AppSettings::contains("proxyIsDirectConnection"))
60 AppSettings::setDirectConnection(true);
62 if(AppSettings::isDirectConnection())
64 qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
67 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
68 AppSettings::proxyAddress(),
69 AppSettings::proxyPort(),
72 QNetworkProxy::setApplicationProxy(proxy);
74 int confId = Conference::activeConference();
76 connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
78 // event details have changed
79 connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
80 connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
81 connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
82 connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
83 connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
84 connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
86 // event conference map button clicked
87 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
89 connect(aboutAction, SIGNAL(triggered()), SLOT(aboutApp()));
90 connect(settingsAction, SIGNAL(triggered()), SLOT(setup()));
92 selectConference->setDuplicatesEnabled(false);
93 int confCount = Conference::getAll().count();
97 fillAndShowConferenceHeader();
98 setWindowTitle(Conference::getById(confId).title());
100 if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
101 selectConferenceWidget->hide();
104 // have to fill comboBox with available conferences
105 QList<Conference> confs = Conference::getAll();
106 QListIterator<Conference> i(confs);
109 Conference conf = i.next();
110 selectConference->addItem(conf.title(),conf.id());
112 int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
113 selectConference->setCurrentIndex(idx);
115 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
119 conferenceHeader->hide();
120 selectConferenceWidget->hide();
121 // go to the 'conferenceTab', so the user can import the schedule
122 tabWidget->setCurrentIndex(6); // 6 - conference tab
125 // open dialog for given Event ID
126 // this is used in case Alarm Dialog request application to start
131 EventDialog dialog(aEventId,this);
134 catch(OrmNoObjectException&) {} // just start application
135 catch(...) {} // just start application
139 void MainWindow::scheduleImported(int aConfId)
143 Conference conf = Conference::getById(aConfId);
144 if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
146 disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
147 selectConference->addItem(conf.title(),conf.id());
148 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
150 int confCount = Conference::getAll().count();
153 int idx = selectConference->findText(conf.title());
154 selectConference->setCurrentIndex(idx);
157 selectConferenceWidget->show();
159 conferenceChanged(idx);
163 void MainWindow::aboutApp()
165 QDialog dialog(this);
169 dialog.setFixedWidth(width());
174 void MainWindow::conferenceMapClicked()
176 QString mapPath = QString(":/maps/campus.png");
177 if(!QFile::exists(mapPath))
178 mapPath = QString(":/maps/rooms/not-available.png");
182 QPixmap map(mapPath);
183 MapWindow window(map,roomName,this);
187 void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
189 dayTabContainer->updateTreeViewModel(aEventId);
190 favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
191 tracksTabContainer->updateTreeViewModel(aEventId);
192 nowTabContainer->updateTreeViewModel(aEventId);
193 roomsTabContainer->updateTreeViewModel(aEventId);
194 searchTabContainer->updateTreeViewModel(aEventId);
197 void MainWindow::fillAndShowConferenceHeader()
199 int confId = Conference::activeConference();
200 conferenceTitle->setText(Conference::getById(confId).title());
201 conferenceSubtitle->setText(Conference::getById(confId).subtitle());
202 conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
203 conferenceWhen->setText(
204 Conference::getById(confId).start().toString("dd-MM-yyyy")
206 Conference::getById(confId).end().toString("dd-MM-yyyy"));
207 conferenceHeader->show();
210 void MainWindow::initTabs()
212 int confId = Conference::activeConference();
213 QDate startDate = Conference::getById(confId).start();
214 QDate endDate = Conference::getById(confId).end();
216 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
217 dayTabContainer->setDates(startDate, endDate);
218 tracksTabContainer->setDates(startDate, endDate);
219 roomsTabContainer->setDates(startDate, endDate);
220 favsTabContainer->setDates(startDate, endDate);
221 searchTabContainer->setDates(startDate, endDate);
222 searchTabContainer->searchAgainClicked();
223 nowTabContainer->updateTreeView(QDate::currentDate());
226 void MainWindow::conferenceChanged(int aIndex)
228 Conference::getById(Conference::activeConference()).update("active",0);
229 Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
232 fillAndShowConferenceHeader();
233 setWindowTitle(Conference::getById(Conference::activeConference()).title());
236 void MainWindow::setup()
238 SettingsDialog dialog;
241 qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
243 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
244 AppSettings::proxyAddress(),
245 AppSettings::proxyPort(),
248 QNetworkProxy::setApplicationProxy(proxy);