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)));
77 connect(importScheduleWidget, SIGNAL(scheduleDeleted(const QString&)), SLOT(scheduleDeleted(const QString&)));
79 // event details have changed
80 connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
81 connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
82 connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
83 connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
84 connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
85 connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
87 // event conference map button clicked
88 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
90 connect(aboutAction, SIGNAL(triggered()), SLOT(aboutApp()));
91 connect(settingsAction, SIGNAL(triggered()), SLOT(setup()));
93 selectConference->setDuplicatesEnabled(false);
94 int confCount = Conference::getAll().count();
98 fillAndShowConferenceHeader();
99 setWindowTitle(Conference::getById(confId).title());
101 if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
102 selectConferenceWidget->hide();
105 // have to fill comboBox with available conferences
106 QList<Conference> confs = Conference::getAll();
107 QListIterator<Conference> i(confs);
110 Conference conf = i.next();
111 selectConference->addItem(conf.title(),conf.id());
113 int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
114 selectConference->setCurrentIndex(idx);
116 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
120 conferenceHeader->hide();
121 selectConferenceWidget->hide();
122 // go to the 'conferenceTab', so the user can import the schedule
123 tabWidget->setCurrentIndex(6); // 6 - conference tab
126 // open dialog for given Event ID
127 // this is used in case Alarm Dialog request application to start
132 EventDialog dialog(aEventId,this);
135 catch(OrmNoObjectException&) {} // just start application
136 catch(...) {} // just start application
140 void MainWindow::scheduleImported(int aConfId)
144 Conference conf = Conference::getById(aConfId);
145 if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
147 disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
148 selectConference->addItem(conf.title(),conf.id());
149 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
151 int confCount = Conference::getAll().count();
154 int idx = selectConference->findText(conf.title());
155 selectConference->setCurrentIndex(idx);
158 selectConferenceWidget->show();
160 conferenceChanged(idx);
164 void MainWindow::scheduleDeleted(const QString& title)
166 int idx = selectConference->findText(title);
170 qWarning() << __PRETTY_FUNCTION__ << "removed non-existent item:" << title;
172 // will it signal "changed"?
173 selectConference->removeItem(idx);
177 void MainWindow::aboutApp()
179 QDialog dialog(this);
183 dialog.setFixedWidth(width());
188 void MainWindow::conferenceMapClicked()
190 QString mapPath = QString(":/maps/campus.png");
191 if(!QFile::exists(mapPath))
192 mapPath = QString(":/maps/rooms/not-available.png");
196 QPixmap map(mapPath);
197 MapWindow window(map,roomName,this);
201 void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
203 dayTabContainer->updateTreeViewModel(aEventId);
204 favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
205 tracksTabContainer->updateTreeViewModel(aEventId);
206 nowTabContainer->updateTreeViewModel(aEventId);
207 roomsTabContainer->updateTreeViewModel(aEventId);
208 searchTabContainer->updateTreeViewModel(aEventId);
211 void MainWindow::fillAndShowConferenceHeader()
213 int confId = Conference::activeConference();
214 conferenceTitle->setText(Conference::getById(confId).title());
215 conferenceSubtitle->setText(Conference::getById(confId).subtitle());
216 conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
217 conferenceWhen->setText(
218 Conference::getById(confId).start().toString("dd-MM-yyyy")
220 Conference::getById(confId).end().toString("dd-MM-yyyy"));
221 conferenceHeader->show();
224 void MainWindow::initTabs()
226 int confId = Conference::activeConference();
227 QDate startDate = Conference::getById(confId).start();
228 QDate endDate = Conference::getById(confId).end();
230 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
231 dayTabContainer->setDates(startDate, endDate);
232 tracksTabContainer->setDates(startDate, endDate);
233 roomsTabContainer->setDates(startDate, endDate);
234 favsTabContainer->setDates(startDate, endDate);
235 searchTabContainer->setDates(startDate, endDate);
236 searchTabContainer->searchAgainClicked();
237 nowTabContainer->updateTreeView(QDate::currentDate());
240 void MainWindow::conferenceChanged(int aIndex)
242 Conference::getById(Conference::activeConference()).update("active",0);
243 Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
246 fillAndShowConferenceHeader();
247 setWindowTitle(Conference::getById(Conference::activeConference()).title());
250 void MainWindow::setup()
252 SettingsDialog dialog;
255 qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
257 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
258 AppSettings::proxyAddress(),
259 AppSettings::proxyPort(),
262 QNetworkProxy::setApplicationProxy(proxy);