source: src/gui/mainwindow.cpp @ 5d22816

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

GUI changes for N810 device

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