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>
25 const QString PROXY_URL("192.168.0.252");
26 const quint16 PROXY_PORT = 4040;
27 const QString PROXY_USERNAME;
28 const QString PROXY_PASSWD;
29 const bool DIRECT_CONNECTION = false;
31 MainWindow::MainWindow(int aEventId, QWidget *aParent)
32 : QMainWindow(aParent)
36 qDebug() << "Setting-up proxy: " << PROXY_URL << ":" << PROXY_PORT;
37 QNetworkProxy proxy(DIRECT_CONNECTION ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
38 PROXY_URL, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWD);
39 QNetworkProxy::setApplicationProxy(proxy);
41 int confId = Conference::activeConference();
43 connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
45 // event details have changed
46 connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
47 connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
48 connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
49 connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
50 connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
51 connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
53 // event conference map button clicked
54 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
56 connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
58 selectConference->setDuplicatesEnabled(false);
59 int confCount = Conference::getAll().count();
63 fillAndShowConferenceHeader();
64 setWindowTitle(Conference::getById(confId).title());
66 if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
67 selectConferenceWidget->hide();
70 // have to fill comboBox with available conferences
71 QList<Conference> confs = Conference::getAll();
72 QListIterator<Conference> i(confs);
75 Conference conf = i.next();
76 selectConference->addItem(conf.title(),conf.id());
78 int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
79 selectConference->setCurrentIndex(idx);
81 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
85 conferenceHeader->hide();
86 selectConferenceWidget->hide();
87 // go to the 'conferenceTab', so the user can import the schedule
88 tabWidget->setCurrentIndex(6); // 6 - conference tab
91 // open dialog for given Event ID
92 // this is used in case Alarm Dialog request application to start
97 EventDialog dialog(aEventId,this);
100 catch(OrmNoObjectException&) {} // just start application
101 catch(...) {} // just start application
105 void MainWindow::scheduleImported(int aConfId)
109 Conference conf = Conference::getById(aConfId);
110 if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
112 disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
113 selectConference->addItem(conf.title(),conf.id());
114 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
116 int confCount = Conference::getAll().count();
119 int idx = selectConference->findText(conf.title());
120 selectConference->setCurrentIndex(idx);
123 selectConferenceWidget->show();
125 conferenceChanged(idx);
129 void MainWindow::aboutApp()
131 QDialog dialog(this);
137 void MainWindow::conferenceMapClicked()
139 QString mapPath = QString(":/maps/campus.png");
140 if(!QFile::exists(mapPath))
141 mapPath = QString(":/maps/rooms/not-available.png");
145 QPixmap map(mapPath);
146 MapWindow window(map,roomName,this);
150 void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
152 dayTabContainer->updateTreeViewModel(aEventId);
153 favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
154 tracksTabContainer->updateTreeViewModel(aEventId);
155 nowTabContainer->updateTreeViewModel(aEventId);
156 roomsTabContainer->updateTreeViewModel(aEventId);
157 searchTabContainer->updateTreeViewModel(aEventId);
160 void MainWindow::fillAndShowConferenceHeader()
162 int confId = Conference::activeConference();
163 conferenceTitle->setText(Conference::getById(confId).title());
164 conferenceSubtitle->setText(Conference::getById(confId).subtitle());
165 conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
166 conferenceWhen->setText(
167 Conference::getById(confId).start().toString("dd-MM-yyyy")
169 Conference::getById(confId).end().toString("dd-MM-yyyy"));
170 conferenceHeader->show();
173 void MainWindow::initTabs()
175 int confId = Conference::activeConference();
176 QDate startDate = Conference::getById(confId).start();
177 QDate endDate = Conference::getById(confId).end();
179 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
180 dayTabContainer->setDates(startDate, endDate);
181 tracksTabContainer->setDates(startDate, endDate);
182 roomsTabContainer->setDates(startDate, endDate);
183 favsTabContainer->setDates(startDate, endDate);
184 searchTabContainer->setDates(startDate, endDate);
185 searchTabContainer->searchAgainClicked();
186 nowTabContainer->updateTreeView(QDate::currentDate());
189 void MainWindow::conferenceChanged(int aIndex)
191 Conference::getById(Conference::activeConference()).update("active",0);
192 Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
195 fillAndShowConferenceHeader();
196 setWindowTitle(Conference::getById(Conference::activeConference()).title());