2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2021 Philipp Spitzer, gregor herrmann, Stefan Stahl
5 * This file is part of ConfClerk.
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)
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
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/>.
20 #include "eventdialog.h"
21 #include "conference.h"
27 #include "appsettings.h"
30 QString toHtmlEscaped(const QString& string) {
31 #if QT_VERSION >= 0x050000
32 return string.toHtmlEscaped();
34 return Qt::escape(string);
38 EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialog(parent), mConferenceId(conferenceId), mEventId(eventId) {
45 Event event = Event::getById(mEventId, mConferenceId);
49 info.append(QString("<h1>%1</h1>\n").arg(toHtmlEscaped(event.title())));
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(", "));
58 info += QString("<h2>%1</h2>\n").arg(tr("Abstract"));
59 if (Qt::mightBeRichText(event.abstract())) {
60 info += event.abstract();
62 info += Qt::convertFromPlainText(event.abstract(), Qt::WhiteSpaceNormal);
66 info += QString("<h2>%1</h2>\n").arg(tr("Description"));
67 if (Qt::mightBeRichText(event.description())) {
68 info += event.description();
70 QString description = Qt::convertFromPlainText(event.description(), Qt::WhiteSpaceNormal);
71 // make links clickable
72 QRegExp rx("<?(((s?ftp|https?|svn|svn\\+ssh|git|git\\+ssh)://|(file|news):|www\\.)[-a-z0-9_.:%]*[a-z0-9](/[^][{}\\s\"<>()]*[^][{}\\s\"<>().,:!])?/?)>?");
73 info += description.replace(rx, "<a href=\"\\1\">\\1</a>");
77 info += QString("<h2>%1</h2>\n<ul>\n").arg(tr("Links"));
78 QMapIterator<QString, QString> i(event.links());
81 QString url(i.value());
82 QString name(i.key());
83 if (url.isEmpty() || url == "http://") continue;
84 if (name.isEmpty()) name = url;
85 info += QString("<li><a href=\"%1\">%2</a></li>\n").arg(toHtmlEscaped(url), toHtmlEscaped(name));
87 info += QString("</ul>\n");
88 eventInfoTextBrowser->setHtml(info);
90 // make sure colours are the same as usual
91 eventInfoTextBrowser->setPalette(qApp->palette());
92 // reduce font size, on maemo
94 QFont font = eventInfoTextBrowser->font();
95 font.setPointSizeF(font.pointSizeF()*0.8);
96 eventInfoTextBrowser->setFont(font);
99 connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
100 connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
102 updateFavouriteButton(event);
106 alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
110 void EventDialog::favouriteClicked()
112 Event event = Event::getById(mEventId, mConferenceId);
113 event.cycleFavourite();
114 event.update("favourite");
115 updateFavouriteButton(event);
117 // 'conflicts' list may have changed
118 QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
120 // have to emit 'eventChanged' signal on all events in conflict
121 for(int i=0; i<conflicts.count(); i++)
122 emit eventChanged(conflicts[i].id(), false);
124 // since the Favourite icon has changed, update TreeViews accordingly
125 // all TreeViews have to listen on this signal
126 emit eventChanged(event.id(), true);
129 void EventDialog::alarmClicked()
131 Event event = Event::getById(mEventId, mConferenceId);
135 event.setHasAlarm(false); // update DB
136 alarmButton->setIcon(QIcon(":/icons/alarm-off.png"));
138 // remove alarm from the 'alarmd' alarms list
140 alarm.deleteAlarm(event.conferenceId(), event.id());
141 // TODO: test if removing was successfull
146 event.setHasAlarm(true);
147 alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
149 // add alarm to the 'alarmd'
151 alarm.addAlarm(event.conferenceId(), event.id(), event.title(), event.start().addSecs(-AppSettings::preEventAlarmSec()));
154 event.update("alarm");
155 // since the Alarm icon has changed, update TreeView accordingly
156 // all TreeViews have to listen on this signal
157 emit eventChanged(event.id(), false);
161 void EventDialog::updateFavouriteButton(const Event& event) {
162 switch (event.favourite()) {
163 case Favourite_no: favouriteButton->setIcon(QIcon(":/icons/favourite-no.png")); break;
164 case Favourite_weak: favouriteButton->setIcon(QIcon(":/icons/favourite-weak.png")); break;
165 case Favourite_strong: favouriteButton->setIcon(QIcon(":/icons/favourite-strong.png")); break;