source: src/gui/eventdialog.cpp

Last change on this file was ffb6be7, checked in by gregor herrmann <gregor@…>, 4 months ago

Bump copyright years.

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2021 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
30QString toHtmlEscaped(const QString& string) {
31#if QT_VERSION >= 0x050000
32    return string.toHtmlEscaped();
33#else
34    return Qt::escape(string);
35#endif
36}
37
38EventDialog::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        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>");
74    }
75
76    // links
77    info += QString("<h2>%1</h2>\n<ul>\n").arg(tr("Links"));
78    QMapIterator<QString, QString> i(event.links());
79    while (i.hasNext()) {
80        i.next();
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));
86    }
87    info += QString("</ul>\n");
88    eventInfoTextBrowser->setHtml(info);
89
90    // make sure colours are the same as usual
91    eventInfoTextBrowser->setPalette(qApp->palette());
92    // reduce font size, on maemo
93#ifdef MAEMO
94    QFont font = eventInfoTextBrowser->font();
95    font.setPointSizeF(font.pointSizeF()*0.8);
96    eventInfoTextBrowser->setFont(font);
97#endif
98
99    connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
100    connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
101
102    updateFavouriteButton(event);
103
104    if(event.hasAlarm())
105    {
106        alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
107    }
108}
109
110void EventDialog::favouriteClicked()
111{
112    Event event = Event::getById(mEventId, mConferenceId);
113    event.cycleFavourite();
114    event.update("favourite");
115    updateFavouriteButton(event);
116
117    // 'conflicts' list may have changed
118    QList<Event> conflicts = Event::conflictEvents(event.id(), mConferenceId);
119
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);
123
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);
127}
128
129void EventDialog::alarmClicked()
130{
131    Event event = Event::getById(mEventId, mConferenceId);
132
133    if(event.hasAlarm())
134    {
135        event.setHasAlarm(false); // update DB
136        alarmButton->setIcon(QIcon(":/icons/alarm-off.png"));
137#ifdef MAEMO
138        // remove alarm from the 'alarmd' alarms list
139        Alarm alarm;
140        alarm.deleteAlarm(event.conferenceId(), event.id());
141        // TODO: test if removing was successfull
142#endif /* MAEMO */
143    }
144    else
145    {
146        event.setHasAlarm(true);
147        alarmButton->setIcon(QIcon(":/icons/alarm-on.png"));
148#ifdef MAEMO
149        // add alarm to the 'alarmd'
150        Alarm alarm;
151        alarm.addAlarm(event.conferenceId(), event.id(), event.title(), event.start().addSecs(-AppSettings::preEventAlarmSec()));
152#endif /* MAEMO */
153    }
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);
158}
159
160
161void 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;
166    }
167}
168
Note: See TracBrowser for help on using the repository browser.