]> ToastFreeware Gitweb - toast/confclerk.git/blob - src/gui/eventdialog.cpp
c95104c008a21d2b4b4c7b45316c236bba2e7331
[toast/confclerk.git] / src / gui / eventdialog.cpp
1 /*
2  * Copyright (C) 2010 Ixonos Plc.
3  * Copyright (C) 2011-2013 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 #include "appsettings.h"
28 #endif
29
30 EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialog(parent), mConferenceId(conferenceId), mEventId(eventId) {
31     setupUi(this);
32
33 #ifdef MAEMO
34     showFullScreen();
35 #endif
36
37     Event event = Event::getById(mEventId, mConferenceId);
38
39     title->setText(event.title());
40     persons->setText(event.persons().join(" and "));
41     abstract->setText(event.abstract());
42     description->setText(event.description());
43     QStringList linksText = static_cast<QStringList>(event.links().values());
44     for (QStringList::iterator linkIterator = linksText.begin(); linkIterator != linksText.end(); ++linkIterator)
45         *linkIterator = QString("<a href=\"%1\">%1</a>").arg(*linkIterator);
46     links->setText(linksText.join("<br/>"));
47
48     connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
49     connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
50
51     if(event.isFavourite())
52     {
53         favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
54     }
55
56     if(event.hasAlarm())
57     {
58         alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
59     }
60 }
61
62 void EventDialog::favouriteClicked()
63 {
64     Event event = Event::getById(mEventId, mConferenceId);
65
66     QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
67     if(event.isFavourite())
68     {
69         event.setFavourite(false);
70         favouriteButton->setIcon(QIcon(":/icons/favourite-off.png"));
71     }
72     else
73     {
74         event.setFavourite(true);
75         favouriteButton->setIcon(QIcon(":/icons/favourite-on.png"));
76     }
77     event.update("favourite");
78
79     if(event.isFavourite())
80     {
81         // event has became 'favourite' and so 'conflicts' list may have changed
82         conflicts = Event::conflictEvents(event.id(), mConferenceId);
83     }
84
85     // have to emit 'eventChanged' signal on all events in conflict
86     for(int i=0; i<conflicts.count(); i++)
87         emit eventChanged(conflicts[i].id(), false);
88
89     // since the Favourite icon has changed, update TreeViews accordingly
90     // all TreeViews have to listen on this signal
91     emit eventChanged(event.id(), true);
92 }
93
94 void EventDialog::alarmClicked()
95 {
96     Event event = Event::getById(mEventId, mConferenceId);
97
98     if(event.hasAlarm())
99     {
100         event.setHasAlarm(false); // update DB
101         alarmButton->setIcon(QIcon(":/icons/alarm-off.png"));
102 #ifdef MAEMO
103         // remove alarm from the 'alarmd' alarms list
104         Alarm alarm;
105         alarm.deleteAlarm(event.conferenceId(), event.id());
106         // TODO: test if removing was successfull
107 #endif /* MAEMO */
108     }
109     else
110     {
111         event.setHasAlarm(true);
112         alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
113 #ifdef MAEMO
114         // add alarm to the 'alarmd'
115         Alarm alarm;
116         alarm.addAlarm(event.conferenceId(), event.id(), event.title(), event.start().addSecs(-AppSettings::preEventAlarmSec()));
117 #endif /* MAEMO */
118     }
119     event.update("alarm");
120     // since the Alarm icon has changed, update TreeView accordingly
121     // all TreeViews have to listen on this signal
122     emit eventChanged(event.id(), false);
123 }
124