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 "tabcontainer.h" |
---|
20 | |
---|
21 | #include <QFile> |
---|
22 | #include <QMessageBox> |
---|
23 | #include <QTimer> |
---|
24 | |
---|
25 | #include <treeview.h> |
---|
26 | #include <delegate.h> |
---|
27 | |
---|
28 | #include "eventdialog.h" |
---|
29 | #include "mapwindow.h" |
---|
30 | |
---|
31 | #include "conflictsdialog.h" |
---|
32 | |
---|
33 | TabContainer::TabContainer(QWidget *aParent) |
---|
34 | : QWidget(aParent) |
---|
35 | { |
---|
36 | setupUi(this); |
---|
37 | |
---|
38 | treeView->setHeaderHidden(true); |
---|
39 | treeView->setRootIsDecorated(false); |
---|
40 | treeView->setIndentation(0); |
---|
41 | treeView->setAnimated(true); |
---|
42 | treeView->setModel(new EventModel()); |
---|
43 | treeView->setItemDelegate(new Delegate(treeView)); |
---|
44 | |
---|
45 | connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &))); |
---|
46 | |
---|
47 | connect(treeView, SIGNAL(eventHasChanged(int,bool)), SIGNAL(eventHasChanged(int,bool))); |
---|
48 | connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
49 | connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); |
---|
50 | connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &))); |
---|
51 | |
---|
52 | // day navigator is hidden by default |
---|
53 | dayNavigator->hide(); |
---|
54 | } |
---|
55 | |
---|
56 | void TabContainer::updateTreeView(const QDate &aDate) |
---|
57 | { |
---|
58 | dayNavigator->show(); |
---|
59 | loadEvents( aDate, Conference::activeConference() ); |
---|
60 | treeView->reset(); |
---|
61 | } |
---|
62 | |
---|
63 | void TabContainer::itemClicked(const QModelIndex &aIndex) |
---|
64 | { |
---|
65 | // have to handle only events, not time-groups |
---|
66 | if(!aIndex.parent().isValid()) // time-group |
---|
67 | return; |
---|
68 | |
---|
69 | EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
70 | #ifdef N810 |
---|
71 | dialog.setFixedWidth(static_cast<QWidget*>(parent())->width()); |
---|
72 | #endif |
---|
73 | connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
74 | dialog.exec(); |
---|
75 | disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
76 | } |
---|
77 | |
---|
78 | void TabContainer::displayMap(const QModelIndex &aIndex) |
---|
79 | { |
---|
80 | Event *event = static_cast<Event*>(aIndex.internalPointer()); |
---|
81 | |
---|
82 | // room names are stored in lower-case format |
---|
83 | // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png" |
---|
84 | QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove(".")); |
---|
85 | if(!QFile::exists(mapPath)) |
---|
86 | mapPath = QString(":/maps/rooms/not-available.png"); |
---|
87 | |
---|
88 | QString roomName; |
---|
89 | if(mapPath.contains("not-available", Qt::CaseInsensitive)) |
---|
90 | roomName = QString("Map is not available: %1").arg(event->room()); |
---|
91 | else |
---|
92 | roomName = event->room(); |
---|
93 | |
---|
94 | QPixmap map(mapPath); |
---|
95 | MapWindow window(map,roomName,this); |
---|
96 | window.exec(); |
---|
97 | } |
---|
98 | |
---|
99 | void TabContainer::displayConflicts(const QModelIndex &aIndex) |
---|
100 | { |
---|
101 | ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
102 | #ifdef N810 |
---|
103 | dialog.setFixedWidth(static_cast<QWidget*>(parent())->width()); |
---|
104 | #endif |
---|
105 | connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
106 | dialog.exec(); |
---|
107 | disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
108 | } |
---|
109 | |
---|
110 | void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel) |
---|
111 | { |
---|
112 | if(aReloadModel) |
---|
113 | { |
---|
114 | // requires special handling |
---|
115 | // eg. in case of favourities - some favourities may have changed |
---|
116 | // and so we need to reload them |
---|
117 | int confId = Conference::activeConference(); |
---|
118 | QDate startDate = Conference::getById(confId).start(); |
---|
119 | QDate endDate = Conference::getById(confId).end(); |
---|
120 | dayNavigator->setDates(startDate, endDate); |
---|
121 | updateTreeView( Conference::getById(confId).start() ); |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | // just update event in the question |
---|
126 | static_cast<EventModel*>(treeView->model())->updateModel(aEventId); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | void TabContainer::setDates(const QDate &aStart, const QDate &aEnd) |
---|
131 | { |
---|
132 | dayNavigator->setDates(aStart, aEnd); |
---|
133 | } |
---|
134 | |
---|