[ca90cb1] | 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 | */ |
---|
[05afe5f] | 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" |
---|
[58eb7cc] | 30 | #include "room.h" |
---|
| 31 | #include "errormessage.h" |
---|
[05afe5f] | 32 | |
---|
[ea638ef] | 33 | #include "conflictsdialog.h" |
---|
| 34 | |
---|
[05afe5f] | 35 | TabContainer::TabContainer(QWidget *aParent) |
---|
| 36 | : QWidget(aParent) |
---|
| 37 | { |
---|
| 38 | setupUi(this); |
---|
| 39 | |
---|
| 40 | treeView->setHeaderHidden(true); |
---|
| 41 | treeView->setRootIsDecorated(false); |
---|
| 42 | treeView->setIndentation(0); |
---|
| 43 | treeView->setAnimated(true); |
---|
| 44 | treeView->setModel(new EventModel()); |
---|
| 45 | treeView->setItemDelegate(new Delegate(treeView)); |
---|
| 46 | |
---|
| 47 | connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &))); |
---|
| 48 | |
---|
[872aeaa] | 49 | connect(treeView, SIGNAL(eventHasChanged(int,bool)), SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 50 | connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
| 51 | connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); |
---|
[ea638ef] | 52 | connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &))); |
---|
[05afe5f] | 53 | |
---|
[bb6f7d6] | 54 | // day navigator is hidden by default |
---|
| 55 | dayNavigator->hide(); |
---|
[05afe5f] | 56 | } |
---|
| 57 | |
---|
| 58 | void TabContainer::updateTreeView(const QDate &aDate) |
---|
| 59 | { |
---|
[04acaf9] | 60 | int active_id = Conference::activeConference(); |
---|
[05afe5f] | 61 | dayNavigator->show(); |
---|
[04acaf9] | 62 | if (active_id > 0) { |
---|
| 63 | loadEvents(aDate, active_id); |
---|
| 64 | } else { |
---|
| 65 | static_cast<EventModel*>(treeView->model())->clearModel(); |
---|
| 66 | } |
---|
[05afe5f] | 67 | } |
---|
| 68 | |
---|
| 69 | void TabContainer::itemClicked(const QModelIndex &aIndex) |
---|
| 70 | { |
---|
| 71 | // have to handle only events, not time-groups |
---|
| 72 | if(!aIndex.parent().isValid()) // time-group |
---|
| 73 | return; |
---|
| 74 | |
---|
| 75 | EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
[5d22816] | 76 | #ifdef N810 |
---|
| 77 | dialog.setFixedWidth(static_cast<QWidget*>(parent())->width()); |
---|
| 78 | #endif |
---|
[872aeaa] | 79 | connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 80 | dialog.exec(); |
---|
[872aeaa] | 81 | disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 82 | } |
---|
| 83 | |
---|
| 84 | void TabContainer::displayMap(const QModelIndex &aIndex) |
---|
| 85 | { |
---|
| 86 | Event *event = static_cast<Event*>(aIndex.internalPointer()); |
---|
| 87 | |
---|
[58eb7cc] | 88 | Room room = Room::retrieve(event->roomId()); |
---|
| 89 | QVariant mapPathV = room.map(); |
---|
| 90 | QString mapPath; |
---|
| 91 | if (!mapPathV.isValid()) { |
---|
| 92 | error_message("No map for this room"); |
---|
| 93 | return; |
---|
| 94 | } else { |
---|
| 95 | mapPath = mapPathV.toString(); |
---|
| 96 | if (!QFile::exists(mapPath)) { |
---|
| 97 | error_message("Map for this room not found: " + mapPath); |
---|
| 98 | return; |
---|
| 99 | } |
---|
| 100 | } |
---|
[05afe5f] | 101 | |
---|
| 102 | QPixmap map(mapPath); |
---|
[58eb7cc] | 103 | MapWindow window(map, room.name(),this); |
---|
[05afe5f] | 104 | window.exec(); |
---|
| 105 | } |
---|
| 106 | |
---|
[ea638ef] | 107 | void TabContainer::displayConflicts(const QModelIndex &aIndex) |
---|
[05afe5f] | 108 | { |
---|
[d49254d] | 109 | ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
[5d22816] | 110 | #ifdef N810 |
---|
| 111 | dialog.setFixedWidth(static_cast<QWidget*>(parent())->width()); |
---|
| 112 | #endif |
---|
[872aeaa] | 113 | connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[ea638ef] | 114 | dialog.exec(); |
---|
[872aeaa] | 115 | disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool))); |
---|
[05afe5f] | 116 | } |
---|
| 117 | |
---|
[872aeaa] | 118 | void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel) |
---|
[05afe5f] | 119 | { |
---|
[872aeaa] | 120 | if(aReloadModel) |
---|
| 121 | { |
---|
| 122 | // requires special handling |
---|
| 123 | // eg. in case of favourities - some favourities may have changed |
---|
| 124 | // and so we need to reload them |
---|
| 125 | int confId = Conference::activeConference(); |
---|
| 126 | QDate startDate = Conference::getById(confId).start(); |
---|
| 127 | QDate endDate = Conference::getById(confId).end(); |
---|
| 128 | dayNavigator->setDates(startDate, endDate); |
---|
| 129 | updateTreeView( Conference::getById(confId).start() ); |
---|
| 130 | } |
---|
| 131 | else |
---|
| 132 | { |
---|
| 133 | // just update event in the question |
---|
| 134 | static_cast<EventModel*>(treeView->model())->updateModel(aEventId); |
---|
| 135 | } |
---|
[05afe5f] | 136 | } |
---|
| 137 | |
---|
| 138 | void TabContainer::setDates(const QDate &aStart, const QDate &aEnd) |
---|
| 139 | { |
---|
| 140 | dayNavigator->setDates(aStart, aEnd); |
---|
| 141 | } |
---|
| 142 | |
---|
[04acaf9] | 143 | void TabContainer::clearModel() |
---|
| 144 | { |
---|
| 145 | static_cast<EventModel*>(treeView->model())->clearModel(); |
---|
| 146 | } |
---|
| 147 | |
---|