source: src/gui/eventdialog.cpp @ 83020cd

qt5
Last change on this file since 83020cd was 872aeaa, checked in by pavelpa <pavelpa@…>, 12 years ago

some performance optimizations

  • favourities reloaded only if they have really changed
  • otherwise only event in the question is updated
  • Property mode set to 100644
File size: 3.1 KB
Line 
1#include "eventdialog.h"
2#include <conference.h>
3
4#include <QScrollBar>
5
6#ifdef MAEMO
7#include <alarm.h>
8#endif
9
10EventDialog::EventDialog(const int &aEventId, QWidget *aParent)
11    : QDialog(aParent)
12    , mEventId(aEventId)
13{
14    setupUi(this);
15
16#ifdef MAEMO
17    showFullScreen();
18#else
19    alarmButton->hide();
20#endif
21
22    Event event = Event::getById(mEventId,Conference::activeConference());
23
24    title->setText(event.title());
25    persons->setText(event.persons().join(" and "));
26    abstract->setText(event.abstract());
27    description->setText(event.description());
28    links->setText(static_cast<QStringList>(event.links().values()).join("\n"));
29
30    connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
31    connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
32
33    if(event.isFavourite())
34    {
35        favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png"));
36    }
37
38    if(event.hasAlarm())
39    {
40        alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png"));
41    }
42}
43
44void EventDialog::favouriteClicked()
45{
46    Event event = Event::getById(mEventId,Conference::activeConference());
47
48    QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
49    if(event.isFavourite())
50    {
51        event.setFavourite(false);
52        favouriteButton->setIcon(QIcon(":/icons/favourite-offBig.png"));
53    }
54    else
55    {
56        event.setFavourite(true);
57        favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png"));
58    }
59    event.update("favourite");
60
61    if(event.isFavourite())
62    {
63        // event has became 'favourite' and so 'conflicts' list may have changed
64        conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
65    }
66
67    qDebug() << " FAVOURITE [" << event.id() << "] -> " << event.isFavourite();
68
69    // have to emit 'eventHasChanged' signal on all events in conflict
70    for(int i=0; i<conflicts.count(); i++)
71        emit(eventHasChanged(conflicts[i].id()));
72
73    // since the Favourite icon has changed, update TreeViews accordingly
74    // all TreeViews have to listen on this signal
75    emit(eventHasChanged(event.id(),true));
76}
77
78void EventDialog::alarmClicked()
79{
80    Event event = Event::getById(mEventId,Conference::activeConference());
81
82    if(event.hasAlarm())
83    {
84        event.setHasAlarm(false); // update DB
85        alarmButton->setIcon(QIcon(":/icons/alarm-offBig.png"));
86#ifdef MAEMO
87        // remove alarm from the 'alarmd' alrms list
88        Alarm alarm;
89        alarm.deleteAlarm(event.id());
90        // TODO: test if removing was successfull
91#endif /* MAEMO */
92    }
93    else
94    {
95        event.setHasAlarm(true);
96        alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png"));
97#ifdef MAEMO
98        // add alarm to the 'alarmd'
99        Alarm alarm;
100        int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10));
101        qDebug() << "cookie: " << cookie;
102#endif /* MAEMO */
103    }
104    event.update("alarm");
105    qDebug() << " ALARM [" << event.id() << "] -> " << event.hasAlarm();
106    // since the Alarm icon has changed, update TreeView accordingly
107    // all TreeViews have to listen on this signal
108    emit(eventHasChanged(event.id()));
109}
110
Note: See TracBrowser for help on using the repository browser.