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)
34 // first time run aplication: -> let's have it direct connection in this case
35 if(!AppSettings::contains("proxyIsDirectConnection"))
36 AppSettings::setDirectConnection(true);
38 if(AppSettings::isDirectConnection())
40 qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
43 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
44 AppSettings::proxyAddress(),
45 AppSettings::proxyPort(),
48 QNetworkProxy::setApplicationProxy(proxy);
50 int confId = Conference::activeConference();
52 connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
54 // event details have changed
55 connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
56 connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
57 connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
58 connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
59 connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
60 connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
62 // event conference map button clicked
63 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
65 connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
67 selectConference->setDuplicatesEnabled(false);
68 int confCount = Conference::getAll().count();
72 fillAndShowConferenceHeader();
73 setWindowTitle(Conference::getById(confId).title());
75 if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
76 selectConferenceWidget->hide();
79 // have to fill comboBox with available conferences
80 QList<Conference> confs = Conference::getAll();
81 QListIterator<Conference> i(confs);
84 Conference conf = i.next();
85 selectConference->addItem(conf.title(),conf.id());
87 int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
88 selectConference->setCurrentIndex(idx);
90 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
94 conferenceHeader->hide();
95 selectConferenceWidget->hide();
96 // go to the 'conferenceTab', so the user can import the schedule
97 tabWidget->setCurrentIndex(6); // 6 - conference tab
100 // open dialog for given Event ID
101 // this is used in case Alarm Dialog request application to start
106 EventDialog dialog(aEventId,this);
109 catch(OrmNoObjectException&) {} // just start application
110 catch(...) {} // just start application
114 void MainWindow::scheduleImported(int aConfId)
118 Conference conf = Conference::getById(aConfId);
119 if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
121 disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
122 selectConference->addItem(conf.title(),conf.id());
123 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
125 int confCount = Conference::getAll().count();
128 int idx = selectConference->findText(conf.title());
129 selectConference->setCurrentIndex(idx);
132 selectConferenceWidget->show();
134 conferenceChanged(idx);
138 void MainWindow::aboutApp()
140 QDialog dialog(this);
146 void MainWindow::conferenceMapClicked()
148 QString mapPath = QString(":/maps/campus.png");
149 if(!QFile::exists(mapPath))
150 mapPath = QString(":/maps/rooms/not-available.png");
154 QPixmap map(mapPath);
155 MapWindow window(map,roomName,this);
159 void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
161 dayTabContainer->updateTreeViewModel(aEventId);
162 favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
163 tracksTabContainer->updateTreeViewModel(aEventId);
164 nowTabContainer->updateTreeViewModel(aEventId);
165 roomsTabContainer->updateTreeViewModel(aEventId);
166 searchTabContainer->updateTreeViewModel(aEventId);
169 void MainWindow::fillAndShowConferenceHeader()
171 int confId = Conference::activeConference();
172 conferenceTitle->setText(Conference::getById(confId).title());
173 conferenceSubtitle->setText(Conference::getById(confId).subtitle());
174 conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
175 conferenceWhen->setText(
176 Conference::getById(confId).start().toString("dd-MM-yyyy")
178 Conference::getById(confId).end().toString("dd-MM-yyyy"));
179 conferenceHeader->show();
182 void MainWindow::initTabs()
184 int confId = Conference::activeConference();
185 QDate startDate = Conference::getById(confId).start();
186 QDate endDate = Conference::getById(confId).end();
188 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
189 dayTabContainer->setDates(startDate, endDate);
190 tracksTabContainer->setDates(startDate, endDate);
191 roomsTabContainer->setDates(startDate, endDate);
192 favsTabContainer->setDates(startDate, endDate);
193 searchTabContainer->setDates(startDate, endDate);
194 searchTabContainer->searchAgainClicked();
195 nowTabContainer->updateTreeView(QDate::currentDate());
198 void MainWindow::conferenceChanged(int aIndex)
200 Conference::getById(Conference::activeConference()).update("active",0);
201 Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
204 fillAndShowConferenceHeader();
205 setWindowTitle(Conference::getById(Conference::activeConference()).title());