2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
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)
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
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/>.
19 #include "tabcontainer.h"
22 #include <QMessageBox>
28 #include "eventdialog.h"
29 #include "mapwindow.h"
31 #include "conflictsdialog.h"
33 TabContainer::TabContainer(QWidget *aParent)
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));
45 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
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 &)));
52 // day navigator is hidden by default
56 void TabContainer::updateTreeView(const QDate &aDate)
58 int active_id = Conference::activeConference();
61 loadEvents(aDate, active_id);
63 static_cast<EventModel*>(treeView->model())->clearModel();
67 void TabContainer::itemClicked(const QModelIndex &aIndex)
69 // have to handle only events, not time-groups
70 if(!aIndex.parent().isValid()) // time-group
73 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
75 dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
77 connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
79 disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
82 void TabContainer::displayMap(const QModelIndex &aIndex)
84 Event *event = static_cast<Event*>(aIndex.internalPointer());
86 // room names are stored in lower-case format
87 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
88 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
89 if(!QFile::exists(mapPath))
90 mapPath = QString(":/maps/rooms/not-available.png");
93 if(mapPath.contains("not-available", Qt::CaseInsensitive))
94 roomName = QString("Map is not available: %1").arg(event->room());
96 roomName = event->room();
99 MapWindow window(map,roomName,this);
103 void TabContainer::displayConflicts(const QModelIndex &aIndex)
105 ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
107 dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
109 connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
111 disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
114 void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel)
118 // requires special handling
119 // eg. in case of favourities - some favourities may have changed
120 // and so we need to reload them
121 int confId = Conference::activeConference();
122 QDate startDate = Conference::getById(confId).start();
123 QDate endDate = Conference::getById(confId).end();
124 dayNavigator->setDates(startDate, endDate);
125 updateTreeView( Conference::getById(confId).start() );
129 // just update event in the question
130 static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
134 void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
136 dayNavigator->setDates(aStart, aEnd);
139 void TabContainer::clearModel()
141 static_cast<EventModel*>(treeView->model())->clearModel();