source: confclerk_git/src/gui/eventdialog.cpp @ 8cb2bc7

qt5
Last change on this file since 8cb2bc7 was 8cb2bc7, checked in by gregor herrmann <gregoa@…>, 6 years ago

eventdialog: only convertFromPlainText description and abstract if they are not richtext.

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