]> ToastFreeware Gitweb - toast/confclerk.git/blob - src/gui/eventdialog.cpp
ifdef qt4 and qt5
[toast/confclerk.git] / src / gui / eventdialog.cpp
1 /*
2  * Copyright (C) 2010 Ixonos Plc.
3  * Copyright (C) 2011-2017 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 QString toHtmlEscaped(const QString& string) {
31 #if QT_VERSION >= 0x050000
32     return string.toHtmlEscaped();
33 #else
34     return Qt::escape(string);
35 #endif
36 }
37
38 EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialog(parent), mConferenceId(conferenceId), mEventId(eventId) {
39     setupUi(this);
40
41 #ifdef MAEMO
42     showFullScreen();
43 #endif
44
45     Event event = Event::getById(mEventId, mConferenceId);
46
47     QString info;
48     // title
49     info.append(QString("<h1>%1</h1>\n").arg(toHtmlEscaped(event.title())));
50
51     // persons
52     info += QString("<h2>%1</h2>\n").arg(tr("Persons"));
53     QStringList persons = event.persons();
54     for (int i = 0; i != persons.size(); ++i) persons[i] = toHtmlEscaped(persons[i]);
55     info += QString("<p>%1</p>\n").arg(persons.join(", "));
56
57     // abstract
58     info += QString("<h2>%1</h2>\n").arg(tr("Abstract"));
59     if (Qt::mightBeRichText(event.abstract())) {
60         info += event.abstract();
61     } else {
62         info += Qt::convertFromPlainText(event.abstract(), Qt::WhiteSpaceNormal);
63     }
64
65     // description
66     info += QString("<h2>%1</h2>\n").arg(tr("Description"));
67     if (Qt::mightBeRichText(event.description())) {
68         info += event.description();
69     } else {
70         info += Qt::convertFromPlainText(event.description(), Qt::WhiteSpaceNormal);
71     }
72
73     // links
74     info += QString("<h2>%1</h2>\n<ul>\n").arg(tr("Links"));
75     QMapIterator<QString, QString> i(event.links());
76     while (i.hasNext()) {
77         i.next();
78         QString url(i.value());
79         QString name(i.key());
80         if (url.isEmpty() || url == "http://") continue;
81         if (name.isEmpty()) name = url;
82         info += QString("<li><a href=\"%1\">%2</a></li>\n").arg(toHtmlEscaped(url), toHtmlEscaped(name));
83     }
84     info += QString("</ul>\n");
85     eventInfoTextBrowser->setHtml(info);
86
87     // make sure colours are the same as usual
88     eventInfoTextBrowser->setPalette(qApp->palette());
89     // reduce font size, on maemo
90 #ifdef MAEMO
91     QFont font = eventInfoTextBrowser->font();
92     font.setPointSizeF(font.pointSizeF()*0.8);
93     eventInfoTextBrowser->setFont(font);
94 #endif
95
96     connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
97     connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
98
99     updateFavouriteButton(event);
100
101     if(event.hasAlarm())
102     {
103         alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
104     }
105 }
106
107 void EventDialog::favouriteClicked()
108 {
109     Event event = Event::getById(mEventId, mConferenceId);
110     event.cycleFavourite();
111     event.update("favourite");
112     updateFavouriteButton(event);
113
114     // 'conflicts' list may have changed
115     QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
116
117     // have to emit 'eventChanged' signal on all events in conflict
118     for(int i=0; i<conflicts.count(); i++)
119         emit eventChanged(conflicts[i].id(), false);
120
121     // since the Favourite icon has changed, update TreeViews accordingly
122     // all TreeViews have to listen on this signal
123     emit eventChanged(event.id(), true);
124 }
125
126 void EventDialog::alarmClicked()
127 {
128     Event event = Event::getById(mEventId, mConferenceId);
129
130     if(event.hasAlarm())
131     {
132         event.setHasAlarm(false); // update DB
133         alarmButton->setIcon(QIcon(":/icons/alarm-off.png"));
134 #ifdef MAEMO
135         // remove alarm from the 'alarmd' alarms list
136         Alarm alarm;
137         alarm.deleteAlarm(event.conferenceId(), event.id());
138         // TODO: test if removing was successfull
139 #endif /* MAEMO */
140     }
141     else
142     {
143         event.setHasAlarm(true);
144         alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
145 #ifdef MAEMO
146         // add alarm to the 'alarmd'
147         Alarm alarm;
148         alarm.addAlarm(event.conferenceId(), event.id(), event.title(), event.start().addSecs(-AppSettings::preEventAlarmSec()));
149 #endif /* MAEMO */
150     }
151     event.update("alarm");
152     // since the Alarm icon has changed, update TreeView accordingly
153     // all TreeViews have to listen on this signal
154     emit eventChanged(event.id(), false);
155 }
156
157
158 void EventDialog::updateFavouriteButton(const Event& event) {
159     switch (event.favourite()) {
160         case Favourite_no: favouriteButton->setIcon(QIcon(":/icons/favourite-no.png")); break;
161         case Favourite_weak: favouriteButton->setIcon(QIcon(":/icons/favourite-weak.png")); break;
162         case Favourite_strong: favouriteButton->setIcon(QIcon(":/icons/favourite-strong.png")); break;
163     }
164 }
165