source: src/gui/mainwindow.cpp @ ca90cb1

qt5
Last change on this file since ca90cb1 was ca90cb1, checked in by uzakmat <uzakmat@…>, 12 years ago

A header with the proper copyright/lincence statement was added into each source/header file.

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of fosdem-schedule.
5 *
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule.  If not, see <http://www.gnu.org/licenses/>.
18 */
19#include "mainwindow.h"
20
21#include <QTreeView>
22#include <QFile>
23#include <QNetworkProxy>
24
25#include <sqlengine.h>
26
27#include <track.h>
28#include <eventmodel.h>
29#include <delegate.h>
30
31#include <conference.h>
32
33#include <QDialog>
34#include <QMessageBox>
35#include "ui_about.h"
36#include <eventdialog.h>
37#include "daynavigatorwidget.h"
38#include "importschedulewidget.h"
39#include "mapwindow.h"
40
41#include <tabcontainer.h>
42#include <appsettings.h>
43
44const QString PROXY_USERNAME;
45const QString PROXY_PASSWD;
46
47MainWindow::MainWindow(int aEventId, QWidget *aParent)
48    : QMainWindow(aParent)
49{
50    setupUi(this);
51
52#ifdef N810
53    tabWidget->setTabText(1,"Favs");
54    //tabWidget->setTabText(2,"Day");
55#endif
56
57    // first time run aplication: -> let's have it direct connection in this case
58    if(!AppSettings::contains("proxyIsDirectConnection"))
59        AppSettings::setDirectConnection(true);
60
61    if(AppSettings::isDirectConnection())
62    {
63        qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
64    }
65    QNetworkProxy proxy(
66            AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
67            AppSettings::proxyAddress(),
68            AppSettings::proxyPort(),
69            PROXY_USERNAME,
70            PROXY_PASSWD);
71    QNetworkProxy::setApplicationProxy(proxy);
72
73    int confId = Conference::activeConference();
74
75    connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
76
77    // event details have changed
78    connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
79    connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
80    connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
81    connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
82    connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
83    connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
84
85    // event conference map button clicked
86    connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
87
88    connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
89
90    selectConference->setDuplicatesEnabled(false);
91    int confCount = Conference::getAll().count();
92    if(confCount)
93    {
94        initTabs();
95        fillAndShowConferenceHeader();
96        setWindowTitle(Conference::getById(confId).title());
97
98        if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
99            selectConferenceWidget->hide();
100        else
101        {
102            // have to fill comboBox with available conferences
103            QList<Conference> confs = Conference::getAll();
104            QListIterator<Conference> i(confs);
105            while(i.hasNext())
106            {
107                Conference conf = i.next();
108                selectConference->addItem(conf.title(),conf.id());
109            }
110            int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
111            selectConference->setCurrentIndex(idx);
112        }
113        connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
114    }
115    else
116    {
117        conferenceHeader->hide();
118        selectConferenceWidget->hide();
119        // go to the 'conferenceTab', so the user can import the schedule
120        tabWidget->setCurrentIndex(6); // 6 - conference tab
121    }
122
123    // open dialog for given Event ID
124    // this is used in case Alarm Dialog request application to start
125    if(aEventId)
126    {
127        try
128        {
129            EventDialog dialog(aEventId,this);
130            dialog.exec();
131        }
132        catch(OrmNoObjectException&) {} // just start application
133        catch(...) {} // just start application
134    }
135}
136
137void MainWindow::scheduleImported(int aConfId)
138{
139    Q_UNUSED(aConfId);
140
141    Conference conf = Conference::getById(aConfId);
142    if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
143    {
144        disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
145        selectConference->addItem(conf.title(),conf.id());
146        connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
147    }
148    int confCount = Conference::getAll().count();
149    if(confCount)
150    {
151        int idx = selectConference->findText(conf.title());
152        selectConference->setCurrentIndex(idx);
153
154        if(confCount>1)
155            selectConferenceWidget->show();
156
157        conferenceChanged(idx);
158    }
159}
160
161void MainWindow::aboutApp()
162{
163    QDialog dialog(this);
164    Ui::AboutDialog ui;
165    ui.setupUi(&dialog);
166#ifdef N810
167    dialog.setFixedWidth(width());
168#endif
169    dialog.exec();
170}
171
172void MainWindow::conferenceMapClicked()
173{
174    QString mapPath = QString(":/maps/campus.png");
175    if(!QFile::exists(mapPath))
176        mapPath = QString(":/maps/rooms/not-available.png");
177
178    QString roomName;
179
180    QPixmap map(mapPath);
181    MapWindow window(map,roomName,this);
182    window.exec();
183}
184
185void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
186{
187    dayTabContainer->updateTreeViewModel(aEventId);
188    favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
189    tracksTabContainer->updateTreeViewModel(aEventId);
190    nowTabContainer->updateTreeViewModel(aEventId);
191    roomsTabContainer->updateTreeViewModel(aEventId);
192    searchTabContainer->updateTreeViewModel(aEventId);
193}
194
195void MainWindow::fillAndShowConferenceHeader()
196{
197    int confId = Conference::activeConference();
198    conferenceTitle->setText(Conference::getById(confId).title());
199    conferenceSubtitle->setText(Conference::getById(confId).subtitle());
200    conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
201    conferenceWhen->setText(
202            Conference::getById(confId).start().toString("dd-MM-yyyy")
203            + ", " +
204            Conference::getById(confId).end().toString("dd-MM-yyyy"));
205    conferenceHeader->show();
206}
207
208void MainWindow::initTabs()
209{
210    int confId = Conference::activeConference();
211    QDate startDate = Conference::getById(confId).start();
212    QDate endDate = Conference::getById(confId).end();
213
214    // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
215    dayTabContainer->setDates(startDate, endDate);
216    tracksTabContainer->setDates(startDate, endDate);
217    roomsTabContainer->setDates(startDate, endDate);
218    favsTabContainer->setDates(startDate, endDate);
219    searchTabContainer->setDates(startDate, endDate);
220    searchTabContainer->searchAgainClicked();
221    nowTabContainer->updateTreeView(QDate::currentDate());
222}
223
224void MainWindow::conferenceChanged(int aIndex)
225{
226    Conference::getById(Conference::activeConference()).update("active",0);
227    Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
228
229    initTabs();
230    fillAndShowConferenceHeader();
231    setWindowTitle(Conference::getById(Conference::activeConference()).title());
232}
233
Note: See TracBrowser for help on using the repository browser.