be98e2981276d33881d39d52658476a0f2302282
[toast/confclerk.git] / src / gui / eventdialog.cpp
1 #include "eventdialog.h"
2 #include <conference.h>
3
4 #include <QScrollBar>
5
6 #ifdef MAEMO
7 #include <alarm.h>
8 #endif
9
10 EventDialog::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
44 void EventDialog::favouriteClicked()
45 {
46     Event event = Event::getById(mEventId,Conference::activeConference());
47
48     if(event.isFavourite())
49     {
50         event.setFavourite(false);
51         favouriteButton->setIcon(QIcon(":/icons/favourite-offBig.png"));
52     }
53     else
54     {
55         event.setFavourite(true);
56         favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png"));
57     }
58     event.update("favourite");
59     qDebug() << " FAVOURITE [" << event.id() << "] -> " << event.isFavourite();
60     // update EVENT_CONFLICT table
61     event.updateConflicts();
62     // since the Favourite icon has changed, update TreeViews accordingly
63     // all TreeViews have to listen on this signal
64     emit(eventHasChanged(event.id()));
65 }
66
67 void EventDialog::alarmClicked()
68 {
69     Event event = Event::getById(mEventId,Conference::activeConference());
70
71     if(event.hasAlarm())
72     {
73         event.setHasAlarm(false); // update DB
74         alarmButton->setIcon(QIcon(":/icons/alarm-offBig.png"));
75 #ifdef MAEMO
76         // remove alarm from the 'alarmd' alrms list
77         Alarm alarm;
78         alarm.deleteAlarm(event.id());
79         // TODO: test if removing was successfull
80 #endif /* MAEMO */
81     }
82     else
83     {
84         event.setHasAlarm(true);
85         alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png"));
86 #ifdef MAEMO
87         // add alarm to the 'alarmd'
88         Alarm alarm;
89         int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10));
90         qDebug() << "cookie: " << cookie;
91 #endif /* MAEMO */
92     }
93     event.update("alarm");
94     qDebug() << " ALARM [" << event.id() << "] -> " << event.hasAlarm();
95     // since the Alarm icon has changed, update TreeView accordingly
96     // all TreeViews have to listen on this signal
97     emit(eventHasChanged(event.id()));
98 }
99