]> ToastFreeware Gitweb - toast/confclerk.git/blob - src/gui/eventdialog.cpp
baaa1b5407522e1f252dff3e2b305a52d849b20f
[toast/confclerk.git] / src / gui / eventdialog.cpp
1 /*
2  * Copyright (C) 2010 Ixonos Plc.
3  * Copyright (C) 2011-2012 Philipp Spitzer, gregor herrmann, Stefan Stahl
4  *
5  * This file is part of ConfClerk.
6  *
7  * ConfClerk is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation, either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * ConfClerk is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "eventdialog.h"
21 #include "conference.h"
22
23 #include <QScrollBar>
24
25 #ifdef MAEMO
26 #include "alarm.h"
27 #endif
28
29 EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialog(parent), mConferenceId(conferenceId), mEventId(eventId) {
30     setupUi(this);
31
32 #ifdef MAEMO
33     showFullScreen();
34 #endif
35
36     Event event = Event::getById(mEventId, mConferenceId);
37
38     title->setText(event.title());
39     persons->setText(event.persons().join(" and "));
40     abstract->setText(event.abstract());
41     description->setText(event.description());
42     QStringList linksText = static_cast<QStringList>(event.links().values());
43     for (QStringList::iterator linkIterator = linksText.begin(); linkIterator != linksText.end(); ++linkIterator)
44         *linkIterator = QString("<a href=\"%1\">%1</a>").arg(*linkIterator);
45     links->setText(linksText.join("<br/>"));
46
47     connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
48     connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
49
50     if(event.isFavourite())
51     {
52         favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
53     }
54
55     if(event.hasAlarm())
56     {
57         alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
58     }
59 }
60
61 void EventDialog::favouriteClicked()
62 {
63     Event event = Event::getById(mEventId, mConferenceId);
64
65     QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
66     if(event.isFavourite())
67     {
68         event.setFavourite(false);
69         favouriteButton->setIcon(QIcon(":/icons/favourite-off.png"));
70     }
71     else
72     {
73         event.setFavourite(true);
74         favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
75     }
76     event.update("favourite");
77
78     if(event.isFavourite())
79     {
80         // event has became 'favourite' and so 'conflicts' list may have changed
81         conflicts = Event::conflictEvents(event.id(), mConferenceId);
82     }
83
84     // have to emit 'eventChanged' signal on all events in conflict
85     for(int i=0; i<conflicts.count(); i++)
86         emit eventChanged(conflicts[i].id(), false);
87
88     // since the Favourite icon has changed, update TreeViews accordingly
89     // all TreeViews have to listen on this signal
90     emit eventChanged(event.id(), true);
91 }
92
93 void EventDialog::alarmClicked()
94 {
95     Event event = Event::getById(mEventId, mConferenceId);
96
97     if(event.hasAlarm())
98     {
99         event.setHasAlarm(false); // update DB
100         alarmButton->setIcon(QIcon(":/icons/alarm-off.png"));
101 #ifdef MAEMO
102         // remove alarm from the 'alarmd' alarms list
103         Alarm alarm;
104         alarm.deleteAlarm(event.conferenceId(), event.id());
105         // TODO: test if removing was successfull
106 #endif /* MAEMO */
107     }
108     else
109     {
110         event.setHasAlarm(true);
111         alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
112 #ifdef MAEMO
113         // add alarm to the 'alarmd'
114         Alarm alarm;
115         alarm.addAlarm(event.conferenceId(), event.id(), event.title(), event.start().addSecs(PRE_EVENT_ALARM_SEC));
116 #endif /* MAEMO */
117     }
118     event.update("alarm");
119     // since the Alarm icon has changed, update TreeView accordingly
120     // all TreeViews have to listen on this signal
121     emit eventChanged(event.id(), false);
122 }
123