'nowTab' updated/loaded when application starts
[toast/confclerk.git] / src / gui / mainwindow.cpp
1 #include "mainwindow.h"
2
3 #include <QTreeView>
4 #include <QFile>
5
6 #include <sqlengine.h>
7
8 #include <track.h>
9 #include <eventmodel.h>
10 #include <delegate.h>
11
12 #include <conference.h>
13
14 #include <QDialog>
15 #include <QMessageBox>
16 #include "ui_about.h"
17 #include <eventdialog.h>
18 #include "daynavigatorwidget.h"
19 #include "importschedulewidget.h"
20 #include "mapwindow.h"
21
22 #include <tabcontainer.h>
23
24 MainWindow::MainWindow(int aEventId, QWidget *aParent)
25     : QMainWindow(aParent)
26 {
27     setupUi(this);
28
29     int confId = Conference::activeConference();
30
31     QList<Conference> confs = Conference::getAll();
32     if(confs.count())
33     {
34         setWindowTitle(confs[0].title());
35     }
36
37     connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
38
39     // event details have changed
40     connect(dayTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
41     connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
42     connect(tracksTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
43     connect(roomsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
44     connect(nowTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
45     connect(searchTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
46
47
48     // event conference map button clicked
49     connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
50
51     connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
52
53     if(Conference::getAll().count()) // no conference(s) in the DB
54     {
55         QDate startDate = Conference::getById(confId).start();
56         QDate endDate = Conference::getById(confId).end();
57         //
58         dayTabContainer->setDates(startDate, endDate);
59         tracksTabContainer->setDates(startDate, endDate);
60         roomsTabContainer->setDates(startDate, endDate);
61         favsTabContainer->setDates(startDate, endDate);
62         searchTabContainer->setDates(startDate, endDate);
63         nowTabContainer->updateTreeView(QDate::currentDate());
64         //
65         conferenceTitle->setText(Conference::getById(confId).title());
66         conferenceSubtitle->setText(Conference::getById(confId).subtitle());
67         conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
68         conferenceWhen->setText(
69                 Conference::getById(confId).start().toString("dd-MM-yyyy")
70                 + ", " +
71                 Conference::getById(confId).end().toString("dd-MM-yyyy"));
72     }
73
74     // open dialog for given Event ID
75     // this is used in case Alarm Dialog request application to start
76     if(aEventId)
77     {
78         try
79         {
80             EventDialog dialog(aEventId,this);
81             dialog.exec();
82         }
83         catch(OrmNoObjectException&) {} // just start application
84         catch(...) {} // just start application
85     }
86 }
87
88 void MainWindow::scheduleImported(int aConfId)
89 {
90     Q_UNUSED(aConfId);
91
92     QList<Conference> confs = Conference::getAll();
93     if(confs.count())
94     {
95         // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
96         QDate startDate = Conference::getById(Conference::activeConference()).start();
97         QDate endDate = Conference::getById(Conference::activeConference()).end();
98         dayTabContainer->setDates(startDate, endDate);
99         tracksTabContainer->setDates(startDate, endDate);
100         roomsTabContainer->setDates(startDate, endDate);
101         favsTabContainer->setDates(startDate, endDate);
102     }
103 }
104
105 void MainWindow::aboutApp()
106 {
107     QDialog dialog(this);
108     Ui::AboutDialog ui;
109     ui.setupUi(&dialog);
110     dialog.exec();
111 }
112
113 void MainWindow::conferenceMapClicked()
114 {
115     QString mapPath = QString(":/maps/campus.png");
116     if(!QFile::exists(mapPath))
117         mapPath = QString(":/maps/rooms/not-available.png");
118
119     QString roomName;
120
121     QPixmap map(mapPath);
122     MapWindow window(map,roomName,this);
123     window.exec();
124 }
125
126 void MainWindow::eventHasChanged(int aEventId)
127 {
128     dayTabContainer->updateTreeViewModel(aEventId);
129     favsTabContainer->updateTreeViewModel(aEventId);
130     tracksTabContainer->updateTreeViewModel(aEventId);
131     nowTabContainer->updateTreeViewModel(aEventId);
132     roomsTabContainer->updateTreeViewModel(aEventId);
133     searchTabContainer->updateTreeViewModel(aEventId);
134 }
135