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"
41 #include <tabcontainer.h>
42 #include <appsettings.h>
44 const QString PROXY_USERNAME;
45 const QString PROXY_PASSWD;
47 MainWindow::MainWindow(int aEventId, QWidget *aParent)
48 : QMainWindow(aParent)
53 tabWidget->setTabText(1,"Favs");
54 //tabWidget->setTabText(2,"Day");
57 // first time run aplication: -> let's have it direct connection in this case
58 if(!AppSettings::contains("proxyIsDirectConnection"))
59 AppSettings::setDirectConnection(true);
61 if(AppSettings::isDirectConnection())
63 qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
66 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
67 AppSettings::proxyAddress(),
68 AppSettings::proxyPort(),
71 QNetworkProxy::setApplicationProxy(proxy);
73 int confId = Conference::activeConference();
75 connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
77 // event details have changed
78 connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
79 connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
80 connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
81 connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
82 connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
83 connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
85 // event conference map button clicked
86 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
88 connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
90 selectConference->setDuplicatesEnabled(false);
91 int confCount = Conference::getAll().count();
95 fillAndShowConferenceHeader();
96 setWindowTitle(Conference::getById(confId).title());
98 if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
99 selectConferenceWidget->hide();
102 // have to fill comboBox with available conferences
103 QList<Conference> confs = Conference::getAll();
104 QListIterator<Conference> i(confs);
107 Conference conf = i.next();
108 selectConference->addItem(conf.title(),conf.id());
110 int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
111 selectConference->setCurrentIndex(idx);
113 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
117 conferenceHeader->hide();
118 selectConferenceWidget->hide();
119 // go to the 'conferenceTab', so the user can import the schedule
120 tabWidget->setCurrentIndex(6); // 6 - conference tab
123 // open dialog for given Event ID
124 // this is used in case Alarm Dialog request application to start
129 EventDialog dialog(aEventId,this);
132 catch(OrmNoObjectException&) {} // just start application
133 catch(...) {} // just start application
137 void MainWindow::scheduleImported(int aConfId)
141 Conference conf = Conference::getById(aConfId);
142 if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
144 disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
145 selectConference->addItem(conf.title(),conf.id());
146 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
148 int confCount = Conference::getAll().count();
151 int idx = selectConference->findText(conf.title());
152 selectConference->setCurrentIndex(idx);
155 selectConferenceWidget->show();
157 conferenceChanged(idx);
161 void MainWindow::aboutApp()
163 QDialog dialog(this);
167 dialog.setFixedWidth(width());
172 void MainWindow::conferenceMapClicked()
174 QString mapPath = QString(":/maps/campus.png");
175 if(!QFile::exists(mapPath))
176 mapPath = QString(":/maps/rooms/not-available.png");
180 QPixmap map(mapPath);
181 MapWindow window(map,roomName,this);
185 void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
187 dayTabContainer->updateTreeViewModel(aEventId);
188 favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
189 tracksTabContainer->updateTreeViewModel(aEventId);
190 nowTabContainer->updateTreeViewModel(aEventId);
191 roomsTabContainer->updateTreeViewModel(aEventId);
192 searchTabContainer->updateTreeViewModel(aEventId);
195 void MainWindow::fillAndShowConferenceHeader()
197 int confId = Conference::activeConference();
198 conferenceTitle->setText(Conference::getById(confId).title());
199 conferenceSubtitle->setText(Conference::getById(confId).subtitle());
200 conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
201 conferenceWhen->setText(
202 Conference::getById(confId).start().toString("dd-MM-yyyy")
204 Conference::getById(confId).end().toString("dd-MM-yyyy"));
205 conferenceHeader->show();
208 void MainWindow::initTabs()
210 int confId = Conference::activeConference();
211 QDate startDate = Conference::getById(confId).start();
212 QDate endDate = Conference::getById(confId).end();
214 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
215 dayTabContainer->setDates(startDate, endDate);
216 tracksTabContainer->setDates(startDate, endDate);
217 roomsTabContainer->setDates(startDate, endDate);
218 favsTabContainer->setDates(startDate, endDate);
219 searchTabContainer->setDates(startDate, endDate);
220 searchTabContainer->searchAgainClicked();
221 nowTabContainer->updateTreeView(QDate::currentDate());
224 void MainWindow::conferenceChanged(int aIndex)
226 Conference::getById(Conference::activeConference()).update("active",0);
227 Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
230 fillAndShowConferenceHeader();
231 setWindowTitle(Conference::getById(Conference::activeConference()).title());