1 #include "mainwindow.h"
5 #include <QNetworkProxy>
10 #include <eventmodel.h>
13 #include <conference.h>
16 #include <QMessageBox>
18 #include <eventdialog.h>
19 #include "daynavigatorwidget.h"
20 #include "importschedulewidget.h"
21 #include "mapwindow.h"
23 #include <tabcontainer.h>
24 #include <appsettings.h>
26 const QString PROXY_USERNAME;
27 const QString PROXY_PASSWD;
29 MainWindow::MainWindow(int aEventId, QWidget *aParent)
30 : QMainWindow(aParent)
35 tabWidget->setTabText(1,"Favs");
36 //tabWidget->setTabText(2,"Day");
39 // first time run aplication: -> let's have it direct connection in this case
40 if(!AppSettings::contains("proxyIsDirectConnection"))
41 AppSettings::setDirectConnection(true);
43 if(AppSettings::isDirectConnection())
45 qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
48 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
49 AppSettings::proxyAddress(),
50 AppSettings::proxyPort(),
53 QNetworkProxy::setApplicationProxy(proxy);
55 int confId = Conference::activeConference();
57 connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
59 // event details have changed
60 connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
61 connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
62 connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
63 connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
64 connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
65 connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
67 // event conference map button clicked
68 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
70 connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
72 selectConference->setDuplicatesEnabled(false);
73 int confCount = Conference::getAll().count();
77 fillAndShowConferenceHeader();
78 setWindowTitle(Conference::getById(confId).title());
80 if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
81 selectConferenceWidget->hide();
84 // have to fill comboBox with available conferences
85 QList<Conference> confs = Conference::getAll();
86 QListIterator<Conference> i(confs);
89 Conference conf = i.next();
90 selectConference->addItem(conf.title(),conf.id());
92 int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
93 selectConference->setCurrentIndex(idx);
95 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
99 conferenceHeader->hide();
100 selectConferenceWidget->hide();
101 // go to the 'conferenceTab', so the user can import the schedule
102 tabWidget->setCurrentIndex(6); // 6 - conference tab
105 // open dialog for given Event ID
106 // this is used in case Alarm Dialog request application to start
111 EventDialog dialog(aEventId,this);
114 catch(OrmNoObjectException&) {} // just start application
115 catch(...) {} // just start application
119 void MainWindow::scheduleImported(int aConfId)
123 Conference conf = Conference::getById(aConfId);
124 if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
126 disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
127 selectConference->addItem(conf.title(),conf.id());
128 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
130 int confCount = Conference::getAll().count();
133 int idx = selectConference->findText(conf.title());
134 selectConference->setCurrentIndex(idx);
137 selectConferenceWidget->show();
139 conferenceChanged(idx);
143 void MainWindow::aboutApp()
145 QDialog dialog(this);
149 dialog.setFixedWidth(width());
154 void MainWindow::conferenceMapClicked()
156 QString mapPath = QString(":/maps/campus.png");
157 if(!QFile::exists(mapPath))
158 mapPath = QString(":/maps/rooms/not-available.png");
162 QPixmap map(mapPath);
163 MapWindow window(map,roomName,this);
167 void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
169 dayTabContainer->updateTreeViewModel(aEventId);
170 favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
171 tracksTabContainer->updateTreeViewModel(aEventId);
172 nowTabContainer->updateTreeViewModel(aEventId);
173 roomsTabContainer->updateTreeViewModel(aEventId);
174 searchTabContainer->updateTreeViewModel(aEventId);
177 void MainWindow::fillAndShowConferenceHeader()
179 int confId = Conference::activeConference();
180 conferenceTitle->setText(Conference::getById(confId).title());
181 conferenceSubtitle->setText(Conference::getById(confId).subtitle());
182 conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
183 conferenceWhen->setText(
184 Conference::getById(confId).start().toString("dd-MM-yyyy")
186 Conference::getById(confId).end().toString("dd-MM-yyyy"));
187 conferenceHeader->show();
190 void MainWindow::initTabs()
192 int confId = Conference::activeConference();
193 QDate startDate = Conference::getById(confId).start();
194 QDate endDate = Conference::getById(confId).end();
196 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
197 dayTabContainer->setDates(startDate, endDate);
198 tracksTabContainer->setDates(startDate, endDate);
199 roomsTabContainer->setDates(startDate, endDate);
200 favsTabContainer->setDates(startDate, endDate);
201 searchTabContainer->setDates(startDate, endDate);
202 searchTabContainer->searchAgainClicked();
203 nowTabContainer->updateTreeView(QDate::currentDate());
206 void MainWindow::conferenceChanged(int aIndex)
208 Conference::getById(Conference::activeConference()).update("active",0);
209 Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
212 fillAndShowConferenceHeader();
213 setWindowTitle(Conference::getById(Conference::activeConference()).title());