source: src/gui/mainwindow.cpp @ 6645e1f

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

implemented 'proxy settings' dialog

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