source: src/gui/mainwindow.cpp @ 47bfffb

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

if the application is run for first time, network connection is set to Direct connection

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