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
RevLine 
[e5bc908]1#include "mainwindow.h"
2
[d0d0a66]3#include <QTreeView>
[05afe5f]4#include <QFile>
[5007fde]5#include <QNetworkProxy>
[d0d0a66]6
[72f6fe4]7#include <sqlengine.h>
8
[4693fa6]9#include <track.h>
[d0d0a66]10#include <eventmodel.h>
[66327a0]11#include <delegate.h>
[d0d0a66]12
[969a840]13#include <conference.h>
14
[c2d66b2]15#include <QDialog>
[3f3e22d]16#include <QMessageBox>
[c2d66b2]17#include "ui_about.h"
[05afe5f]18#include <eventdialog.h>
[969a840]19#include "daynavigatorwidget.h"
[c15be10]20#include "importschedulewidget.h"
[59c6cfe]21#include "mapwindow.h"
[72f6fe4]22
[05afe5f]23#include <tabcontainer.h>
[a023fd2]24#include <appsettings.h>
[05afe5f]25
[5007fde]26const QString PROXY_USERNAME;
27const QString PROXY_PASSWD;
28
[d4a8bbf]29MainWindow::MainWindow(int aEventId, QWidget *aParent)
30    : QMainWindow(aParent)
[e5bc908]31{
[9bbb44e]32    setupUi(this);
[72f6fe4]33
[5d22816]34#ifdef N810
35    tabWidget->setTabText(1,"Favs");
36    //tabWidget->setTabText(2,"Day");
37#endif
38
[47bfffb]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    }
[a023fd2]47    QNetworkProxy proxy(
48            AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
49            AppSettings::proxyAddress(),
50            AppSettings::proxyPort(),
51            PROXY_USERNAME,
52            PROXY_PASSWD);
[5007fde]53    QNetworkProxy::setApplicationProxy(proxy);
54
[0bb39f5]55    int confId = Conference::activeConference();
56
[c15be10]57    connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
58
[c718a77]59    // event details have changed
[872aeaa]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)));
[05afe5f]66
[e7340e1]67    // event conference map button clicked
68    connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
[001c8cf]69
[85340ae]70    connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
[969a840]71
[1fb7a33]72    selectConference->setDuplicatesEnabled(false);
73    int confCount = Conference::getAll().count();
74    if(confCount)
[885a3cc]75    {
76        initTabs();
77        fillAndShowConferenceHeader();
78        setWindowTitle(Conference::getById(confId).title());
[1fb7a33]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)));
[885a3cc]96    }
97    else
[969a840]98    {
[885a3cc]99        conferenceHeader->hide();
[1fb7a33]100        selectConferenceWidget->hide();
[7da2b49]101        // go to the 'conferenceTab', so the user can import the schedule
102        tabWidget->setCurrentIndex(6); // 6 - conference tab
[969a840]103    }
[c5324ca]104
[d4a8bbf]105    // open dialog for given Event ID
106    // this is used in case Alarm Dialog request application to start
107    if(aEventId)
108    {
[95596f6]109        try
110        {
111            EventDialog dialog(aEventId,this);
112            dialog.exec();
113        }
[806b992]114        catch(OrmNoObjectException&) {} // just start application
[95596f6]115        catch(...) {} // just start application
[d4a8bbf]116    }
[e5bc908]117}
[66327a0]118
[c15be10]119void MainWindow::scheduleImported(int aConfId)
[72f6fe4]120{
[c15be10]121    Q_UNUSED(aConfId);
[49c5ad3]122
[1fb7a33]123    Conference conf = Conference::getById(aConfId);
124    if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
[49c5ad3]125    {
[1fb7a33]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);
[969a840]140    }
[72f6fe4]141}
142
[c2d66b2]143void MainWindow::aboutApp()
144{
145    QDialog dialog(this);
146    Ui::AboutDialog ui;
147    ui.setupUi(&dialog);
[5d22816]148#ifdef N810
149    dialog.setFixedWidth(width());
150#endif
[c2d66b2]151    dialog.exec();
152}
153
[e7340e1]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
[872aeaa]167void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
[c718a77]168{
[05afe5f]169    dayTabContainer->updateTreeViewModel(aEventId);
[872aeaa]170    favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
[05afe5f]171    tracksTabContainer->updateTreeViewModel(aEventId);
172    nowTabContainer->updateTreeViewModel(aEventId);
173    roomsTabContainer->updateTreeViewModel(aEventId);
[001c8cf]174    searchTabContainer->updateTreeViewModel(aEventId);
[c718a77]175}
176
[885a3cc]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);
[872aeaa]200    favsTabContainer->setDates(startDate, endDate);
201    searchTabContainer->setDates(startDate, endDate);
[bb6f7d6]202    searchTabContainer->searchAgainClicked();
[885a3cc]203    nowTabContainer->updateTreeView(QDate::currentDate());
204}
205
[1fb7a33]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.