source: src/gui/mainwindow.cpp @ 1fb7a33

qt5
Last change on this file since 1fb7a33 was 1fb7a33, checked in by pavelpa <pavelpa@…>, 12 years ago

possible to have multiple conferences in the DB

  • possible to switch among them
  • conference schedules have to follow FOSDEM conference xml structure
  • 'select Conference' bar is visible only if there are more than one conference available
  • Property mode set to 100644
File size: 6.1 KB
Line 
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
24MainWindow::MainWindow(int aEventId, QWidget *aParent)
25    : QMainWindow(aParent)
26{
27    setupUi(this);
28
29    int confId = Conference::activeConference();
30
31    connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
32
33    // event details have changed
34    connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
35    connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
36    connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
37    connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
38    connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
39    connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
40
41    // event conference map button clicked
42    connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
43
44    connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
45
46    selectConference->setDuplicatesEnabled(false);
47    int confCount = Conference::getAll().count();
48    if(confCount)
49    {
50        initTabs();
51        fillAndShowConferenceHeader();
52        setWindowTitle(Conference::getById(confId).title());
53
54        if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
55            selectConferenceWidget->hide();
56        else
57        {
58            // have to fill comboBox with available conferences
59            QList<Conference> confs = Conference::getAll();
60            QListIterator<Conference> i(confs);
61            while(i.hasNext())
62            {
63                Conference conf = i.next();
64                selectConference->addItem(conf.title(),conf.id());
65            }
66            int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
67            selectConference->setCurrentIndex(idx);
68        }
69        connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
70    }
71    else
72    {
73        conferenceHeader->hide();
74        selectConferenceWidget->hide();
75        // go to the 'conferenceTab', so the user can import the schedule
76        tabWidget->setCurrentIndex(6); // 6 - conference tab
77    }
78
79    // open dialog for given Event ID
80    // this is used in case Alarm Dialog request application to start
81    if(aEventId)
82    {
83        try
84        {
85            EventDialog dialog(aEventId,this);
86            dialog.exec();
87        }
88        catch(OrmNoObjectException&) {} // just start application
89        catch(...) {} // just start application
90    }
91}
92
93void MainWindow::scheduleImported(int aConfId)
94{
95    Q_UNUSED(aConfId);
96
97    Conference conf = Conference::getById(aConfId);
98    if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
99    {
100        disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
101        selectConference->addItem(conf.title(),conf.id());
102        connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
103    }
104    int confCount = Conference::getAll().count();
105    if(confCount)
106    {
107        int idx = selectConference->findText(conf.title());
108        selectConference->setCurrentIndex(idx);
109
110        if(confCount>1)
111            selectConferenceWidget->show();
112
113        conferenceChanged(idx);
114    }
115}
116
117void MainWindow::aboutApp()
118{
119    QDialog dialog(this);
120    Ui::AboutDialog ui;
121    ui.setupUi(&dialog);
122    dialog.exec();
123}
124
125void MainWindow::conferenceMapClicked()
126{
127    QString mapPath = QString(":/maps/campus.png");
128    if(!QFile::exists(mapPath))
129        mapPath = QString(":/maps/rooms/not-available.png");
130
131    QString roomName;
132
133    QPixmap map(mapPath);
134    MapWindow window(map,roomName,this);
135    window.exec();
136}
137
138void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
139{
140    dayTabContainer->updateTreeViewModel(aEventId);
141    favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
142    tracksTabContainer->updateTreeViewModel(aEventId);
143    nowTabContainer->updateTreeViewModel(aEventId);
144    roomsTabContainer->updateTreeViewModel(aEventId);
145    searchTabContainer->updateTreeViewModel(aEventId);
146}
147
148void MainWindow::fillAndShowConferenceHeader()
149{
150    int confId = Conference::activeConference();
151    conferenceTitle->setText(Conference::getById(confId).title());
152    conferenceSubtitle->setText(Conference::getById(confId).subtitle());
153    conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
154    conferenceWhen->setText(
155            Conference::getById(confId).start().toString("dd-MM-yyyy")
156            + ", " +
157            Conference::getById(confId).end().toString("dd-MM-yyyy"));
158    conferenceHeader->show();
159}
160
161void MainWindow::initTabs()
162{
163    int confId = Conference::activeConference();
164    QDate startDate = Conference::getById(confId).start();
165    QDate endDate = Conference::getById(confId).end();
166
167    // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
168    dayTabContainer->setDates(startDate, endDate);
169    tracksTabContainer->setDates(startDate, endDate);
170    roomsTabContainer->setDates(startDate, endDate);
171    favsTabContainer->setDates(startDate, endDate);
172    searchTabContainer->setDates(startDate, endDate);
173    searchTabContainer->searchAgainClicked();
174    nowTabContainer->updateTreeView(QDate::currentDate());
175}
176
177void MainWindow::conferenceChanged(int aIndex)
178{
179    Conference::getById(Conference::activeConference()).update("active",0);
180    Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
181
182    initTabs();
183    fillAndShowConferenceHeader();
184    setWindowTitle(Conference::getById(Conference::activeConference()).title());
185}
186
Note: See TracBrowser for help on using the repository browser.