refactored Event 'details' dialog
[toast/confclerk.git] / src / gui / eventdialog.cpp
1 #include "eventdialog.h"
2 #include <appsettings.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 #endif
19
20     Event event = Event::getById(mEventId,AppSettings::confId());
21
22     title->setText(event.title());
23     persons->setText(event.persons().join(" and "));
24     abstract->setText(event.abstract());
25     description->setText(event.description());
26
27     connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
28     connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
29
30     if(event.isFavourite())
31     {
32         favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png"));
33     }
34
35     if(event.hasAlarm())
36     {
37         alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png"));
38     }
39 }
40
41 void EventDialog::favouriteClicked()
42 {
43     Event event = Event::getById(mEventId,AppSettings::confId());
44
45     if(event.isFavourite())
46     {
47         event.setFavourite(false);
48         favouriteButton->setIcon(QIcon(":/icons/favourite-offBig.png"));
49     }
50     else
51     {
52         event.setFavourite(true);
53         favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png"));
54     }
55     event.update("favourite");
56     qDebug() << " FAVOURITE [" << event.id() << "] -> " << event.isFavourite();
57     // update EVENT_CONFLICT table
58     event.updateConflicts();
59     // since the Favourite icon has changed, update TreeViews accordingly
60     // all TreeViews have to listen on this signal
61     emit(eventHasChanged(event.id()));
62 }
63
64 void EventDialog::alarmClicked()
65 {
66     Event event = Event::getById(mEventId,AppSettings::confId());
67
68     if(event.hasAlarm())
69     {
70         event.setHasAlarm(false); // update DB
71         alarmButton->setIcon(QIcon(":/icons/alarm-offBig.png"));
72 #ifdef MAEMO
73         // remove alarm from the 'alarmd' alrms list
74         Alarm alarm;
75         alarm.deleteAlarm(event.id());
76         // TODO: test if removing was successfull
77 #endif /* MAEMO */
78     }
79     else
80     {
81         event.setHasAlarm(true);
82         alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png"));
83 #ifdef MAEMO
84         // add alarm to the 'alarmd'
85         Alarm alarm;
86         int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10));
87         qDebug() << "cookie: " << cookie;
88 #endif /* MAEMO */
89     }
90     event.update("alarm");
91     qDebug() << " ALARM [" << event.id() << "] -> " << event.hasAlarm();
92     // since the Alarm icon has changed, update TreeView accordingly
93     // all TreeViews have to listen on this signal
94     emit(eventHasChanged(event.id()));
95 }
96