source: src/gui/mainwindow.cpp @ d97bcab

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

implement deleting a conference

pass event about it to mainwindow to update select control
fix Conference::activeConference() to work when first conference is removed

  • Property mode set to 100644
File size: 8.8 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#include "settingsdialog.h"
41
42#include <tabcontainer.h>
43#include <appsettings.h>
44
45const QString PROXY_USERNAME;
46const QString PROXY_PASSWD;
47
48MainWindow::MainWindow(int aEventId, QWidget *aParent)
49    : QMainWindow(aParent)
50{
51    setupUi(this);
52
53#ifdef N810
54    tabWidget->setTabText(1,"Favs");
55    //tabWidget->setTabText(2,"Day");
56#endif
57
58    // first time run aplication: -> let's have it direct connection in this case
59    if(!AppSettings::contains("proxyIsDirectConnection"))
60        AppSettings::setDirectConnection(true);
61
62    if(AppSettings::isDirectConnection())
63    {
64        qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
65    }
66    QNetworkProxy proxy(
67            AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
68            AppSettings::proxyAddress(),
69            AppSettings::proxyPort(),
70            PROXY_USERNAME,
71            PROXY_PASSWD);
72    QNetworkProxy::setApplicationProxy(proxy);
73
74    int confId = Conference::activeConference();
75
76    connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
77    connect(importScheduleWidget, SIGNAL(scheduleDeleted(const QString&)), SLOT(scheduleDeleted(const QString&)));
78
79    // event details have changed
80    connect(dayTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
81    connect(favsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
82    connect(tracksTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
83    connect(roomsTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
84    connect(nowTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
85    connect(searchTabContainer, SIGNAL(eventHasChanged(int,bool)), SLOT(eventHasChanged(int,bool)));
86
87    // event conference map button clicked
88    connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
89
90    connect(aboutAction, SIGNAL(triggered()), SLOT(aboutApp()));
91    connect(settingsAction, SIGNAL(triggered()), SLOT(setup()));
92
93    selectConference->setDuplicatesEnabled(false);
94    int confCount = Conference::getAll().count();
95    if(confCount)
96    {
97        initTabs();
98        fillAndShowConferenceHeader();
99        setWindowTitle(Conference::getById(confId).title());
100
101        if(confCount==1) // don't have to show 'selectConference' widget, if there is only one conference in the DB
102            selectConferenceWidget->hide();
103        else
104        {
105            // have to fill comboBox with available conferences
106            QList<Conference> confs = Conference::getAll();
107            QListIterator<Conference> i(confs);
108            while(i.hasNext())
109            {
110                Conference conf = i.next();
111                selectConference->addItem(conf.title(),conf.id());
112            }
113            int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title());
114            selectConference->setCurrentIndex(idx);
115        }
116        connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
117    }
118    else
119    {
120        conferenceHeader->hide();
121        selectConferenceWidget->hide();
122        // go to the 'conferenceTab', so the user can import the schedule
123        tabWidget->setCurrentIndex(6); // 6 - conference tab
124    }
125
126    // open dialog for given Event ID
127    // this is used in case Alarm Dialog request application to start
128    if(aEventId)
129    {
130        try
131        {
132            EventDialog dialog(aEventId,this);
133            dialog.exec();
134        }
135        catch(OrmNoObjectException&) {} // just start application
136        catch(...) {} // just start application
137    }
138}
139
140void MainWindow::scheduleImported(int aConfId)
141{
142    Q_UNUSED(aConfId);
143
144    Conference conf = Conference::getById(aConfId);
145    if( selectConference->findText(conf.title()) < 0 ) // item doesn't exist
146    {
147        disconnect(selectConference, SIGNAL(currentIndexChanged(int)), this, SLOT(conferenceChanged(int)));
148        selectConference->addItem(conf.title(),conf.id());
149        connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int)));
150    }
151    int confCount = Conference::getAll().count();
152    if(confCount)
153    {
154        int idx = selectConference->findText(conf.title());
155        selectConference->setCurrentIndex(idx);
156
157        if(confCount>1)
158            selectConferenceWidget->show();
159
160        conferenceChanged(idx);
161    }
162}
163
164void MainWindow::scheduleDeleted(const QString& title)
165{
166    int idx = selectConference->findText(title);
167
168    if (idx == -1) {
169        // should not happen
170        qWarning() << __PRETTY_FUNCTION__ << "removed non-existent item:" << title;
171    } else {
172        // will it signal "changed"?
173        selectConference->removeItem(idx);
174    }
175}
176
177void MainWindow::aboutApp()
178{
179    QDialog dialog(this);
180    Ui::AboutDialog ui;
181    ui.setupUi(&dialog);
182#ifdef N810
183    dialog.setFixedWidth(width());
184#endif
185    dialog.exec();
186}
187
188void MainWindow::conferenceMapClicked()
189{
190    QString mapPath = QString(":/maps/campus.png");
191    if(!QFile::exists(mapPath))
192        mapPath = QString(":/maps/rooms/not-available.png");
193
194    QString roomName;
195
196    QPixmap map(mapPath);
197    MapWindow window(map,roomName,this);
198    window.exec();
199}
200
201void MainWindow::eventHasChanged(int aEventId, bool aReloadModel)
202{
203    dayTabContainer->updateTreeViewModel(aEventId);
204    favsTabContainer->updateTreeViewModel(aEventId,aReloadModel);
205    tracksTabContainer->updateTreeViewModel(aEventId);
206    nowTabContainer->updateTreeViewModel(aEventId);
207    roomsTabContainer->updateTreeViewModel(aEventId);
208    searchTabContainer->updateTreeViewModel(aEventId);
209}
210
211void MainWindow::fillAndShowConferenceHeader()
212{
213    int confId = Conference::activeConference();
214    conferenceTitle->setText(Conference::getById(confId).title());
215    conferenceSubtitle->setText(Conference::getById(confId).subtitle());
216    conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
217    conferenceWhen->setText(
218            Conference::getById(confId).start().toString("dd-MM-yyyy")
219            + ", " +
220            Conference::getById(confId).end().toString("dd-MM-yyyy"));
221    conferenceHeader->show();
222}
223
224void MainWindow::initTabs()
225{
226    int confId = Conference::activeConference();
227    QDate startDate = Conference::getById(confId).start();
228    QDate endDate = Conference::getById(confId).end();
229
230    // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
231    dayTabContainer->setDates(startDate, endDate);
232    tracksTabContainer->setDates(startDate, endDate);
233    roomsTabContainer->setDates(startDate, endDate);
234    favsTabContainer->setDates(startDate, endDate);
235    searchTabContainer->setDates(startDate, endDate);
236    searchTabContainer->searchAgainClicked();
237    nowTabContainer->updateTreeView(QDate::currentDate());
238}
239
240void MainWindow::conferenceChanged(int aIndex)
241{
242    Conference::getById(Conference::activeConference()).update("active",0);
243    Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);
244
245    initTabs();
246    fillAndShowConferenceHeader();
247    setWindowTitle(Conference::getById(Conference::activeConference()).title());
248}
249
250void MainWindow::setup()
251{
252    SettingsDialog dialog;
253    dialog.exec();
254
255    qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
256    QNetworkProxy proxy(
257            AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
258            AppSettings::proxyAddress(),
259            AppSettings::proxyPort(),
260            PROXY_USERNAME,
261            PROXY_PASSWD);
262    QNetworkProxy::setApplicationProxy(proxy);
263}
Note: See TracBrowser for help on using the repository browser.