source: src/gui/mainwindow.cpp @ 9f367eb

qt5
Last change on this file since 9f367eb was 3a8dc71, checked in by pavelpa <pavelpa@…>, 12 years ago

SqlEngine? made STATIC

  • Property mode set to 100644
File size: 7.8 KB
Line 
1#include "mainwindow.h"
2#include <appsettings.h>
3
4#include <QTreeView>
5#include <QFile>
6
7#include <sqlengine.h>
8
9#include <track.h>
10#include <eventmodel.h>
11#include <delegate.h>
12
13#include <conference.h>
14
15#include <QDialog>
16#include <QMessageBox>
17#include "ui_about.h"
18#include <eventdialog.h>
19#include "daynavigatorwidget.h"
20#include "importschedulewidget.h"
21#include "mapwindow.h"
22
23#include <tabcontainer.h>
24
25MainWindow::MainWindow(int aEventId, QWidget *aParent)
26    : QMainWindow(aParent)
27{
28    setupUi(this);
29
30    // Sanity check for existence of any Conference in the DB
31    // it AppSettings::confId() is 0, but there are any Conference(s) in the DB
32    // set the confId in the AppSettings for the ID of the first conference in the DB
33    QList<Conference> confs = Conference::getAll();
34    if(!confs.count()) // no conference(s) in the DB
35    {
36        AppSettings::setConfId(0); // no conference in the DB
37    }
38    else
39    {
40        if(AppSettings::confId() == 0)
41            AppSettings::setConfId(confs[0].id());
42
43        setWindowTitle(confs[0].title());
44    }
45
46    dayTabContainer->setType(TabContainer::EContainerTypeDay);
47    favsTabContainer->setType(TabContainer::EContainerTypeFavs);
48    tracksTabContainer->setType(TabContainer::EContainerTypeTracks);
49    nowTabContainer->setType(TabContainer::EContainerTypeNow);
50    roomsTabContainer->setType(TabContainer::EContainerTypeRooms);
51
52    connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
53
54    connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
55
56    // SEARCH EVENTS View
57        searchTreeView->setHeaderHidden(true);
58        searchTreeView->setRootIsDecorated(false);
59        searchTreeView->setIndentation(0);
60        searchTreeView->setAnimated(true);
61        searchTreeView->setModel(new EventModel());
62        searchTreeView->setItemDelegate(new Delegate(searchTreeView));
63
64    // event details have changed
65    connect(dayTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
66    connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
67    connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
68    connect(roomsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
69    connect(nowTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
70
71    connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
72
73    // event clicked
74    connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
75
76    // event search button clicked
77    connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
78    connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
79
80    // event conference map button clicked
81    connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
82    //
83    connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
84
85    if(Conference::getAll().count()) // no conference(s) in the DB
86    {
87        QDate aStartDate = Conference::getById(AppSettings::confId()).start();
88        QDate aEndDate = Conference::getById(AppSettings::confId()).end();
89        searchDayNavigator->setDates(aStartDate, aEndDate);
90        //
91        dayTabContainer->setDates(aStartDate, aEndDate);
92        tracksTabContainer->setDates(aStartDate, aEndDate);
93        roomsTabContainer->setDates(aStartDate, aEndDate);
94        favsTabContainer->setDates(aStartDate, aEndDate);
95        //
96        conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
97        conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle());
98        conferenceWhere->setText(Conference::getById(AppSettings::confId()).city() + ", " + Conference::getById(AppSettings::confId()).venue());
99        conferenceWhen->setText(
100                Conference::getById(AppSettings::confId()).start().toString("dd-MM-yyyy")
101                + ", " +
102                Conference::getById(AppSettings::confId()).end().toString("dd-MM-yyyy"));
103    }
104
105    searchTreeView->hide();
106    searchVerticalWidget->hide();
107    searchHead->show();
108
109    // open dialog for given Event ID
110    // this is used in case Alarm Dialog request application to start
111    if(aEventId)
112    {
113        try
114        {
115            EventDialog dialog(aEventId,this);
116            dialog.exec();
117        }
118        catch(OrmNoObjectException&) {} // just start application
119        catch(...) {} // just start application
120    }
121}
122
123void MainWindow::scheduleImported(int aConfId)
124{
125    Q_UNUSED(aConfId);
126
127    QList<Conference> confs = Conference::getAll();
128    if(!confs.count()) // no conference(s) in the DB
129    {
130        AppSettings::setConfId(0); // no conference in the DB
131    }
132    else
133    {
134        if(AppSettings::confId() == 0)
135            AppSettings::setConfId(confs[0].id());
136
137        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
138        QDate startDate = Conference::getById(AppSettings::confId()).start();
139        QDate endDate = Conference::getById(AppSettings::confId()).end();
140        dayTabContainer->setDates(startDate, endDate);
141        tracksTabContainer->setDates(startDate, endDate);
142        roomsTabContainer->setDates(startDate, endDate);
143        favsTabContainer->setDates(startDate, endDate);
144    }
145}
146
147void MainWindow::aboutApp()
148{
149    QDialog dialog(this);
150    Ui::AboutDialog ui;
151    ui.setupUi(&dialog);
152    dialog.exec();
153}
154
155void MainWindow::updateSearchView(const QDate &aDate)
156{
157    qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ;
158    searchTreeView->reset();
159    int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
160    if( eventsCount ||
161            searchDayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
162        searchVerticalWidget->show();
163        //searchAgainButton->show();
164        searchTreeView->show();
165        searchHead->hide();
166    }
167    else{
168        searchTreeView->hide();
169        searchVerticalWidget->hide();
170        searchHead->show();
171    }
172}
173
174void MainWindow::searchClicked()
175{
176    QHash<QString,QString> columns;
177
178    if( searchTitle->isChecked() )
179        columns.insertMulti("EVENT", "title");
180    if( searchAbstract->isChecked() )
181        columns.insertMulti("EVENT", "abstract");
182    if( searchTag->isChecked() )
183        columns.insertMulti("EVENT", "tag");
184    if( searchSpeaker->isChecked() )
185        columns["PERSON"] = "name";
186    if( searchRoom->isChecked() )
187        columns["ROOM"] = "name";
188
189    QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
190    qDebug() << "\nKeyword to search: " << keyword;
191    SqlEngine::searchEvent( AppSettings::confId(), columns, keyword );
192
193    QDate aStartDate = Conference::getById(AppSettings::confId()).start();
194    QDate aEndDate = Conference::getById(AppSettings::confId()).end();
195    searchDayNavigator->setDates(aStartDate, aEndDate);
196    updateSearchView( Conference::getById(AppSettings::confId()).start() );
197}
198
199void MainWindow::searchAgainClicked()
200{
201    searchHead->show();
202    //searchAgainButton->hide();
203    searchVerticalWidget->hide();
204    searchTreeView->hide();
205}
206
207void MainWindow::conferenceMapClicked()
208{
209    QString mapPath = QString(":/maps/campus.png");
210    if(!QFile::exists(mapPath))
211        mapPath = QString(":/maps/rooms/not-available.png");
212
213    QString roomName;
214
215    QPixmap map(mapPath);
216    MapWindow window(map,roomName,this);
217    window.exec();
218}
219
220void MainWindow::eventHasChanged(int aEventId)
221{
222    dayTabContainer->updateTreeViewModel(aEventId);
223    favsTabContainer->updateTreeViewModel(aEventId);
224    tracksTabContainer->updateTreeViewModel(aEventId);
225    nowTabContainer->updateTreeViewModel(aEventId);
226    roomsTabContainer->updateTreeViewModel(aEventId);
227
228    static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
229}
230
Note: See TracBrowser for help on using the repository browser.