source: src/gui/mainwindow.cpp @ 5007fde

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

implemented importing the schedule from the Internet

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