1 | #include "eventdialog.h" |
---|
2 | #include <appsettings.h> |
---|
3 | |
---|
4 | #include <QScrollBar> |
---|
5 | |
---|
6 | #ifdef MAEMO |
---|
7 | #include <alarm.h> |
---|
8 | #endif |
---|
9 | |
---|
10 | DetailsContainer::DetailsContainer(QWidget *aParent) |
---|
11 | : QWidget(aParent) |
---|
12 | { |
---|
13 | mAbstract.setWordWrap(true); |
---|
14 | mDescription.setWordWrap(true); |
---|
15 | |
---|
16 | QFont f = QLabel().font(); |
---|
17 | f.setBold(true); |
---|
18 | f.setItalic(true); |
---|
19 | mMainLayout = new QVBoxLayout(this); |
---|
20 | QLabel *persons = new QLabel("Persons:"); |
---|
21 | persons->setFont(f); |
---|
22 | mMainLayout->addWidget(persons); |
---|
23 | mMainLayout->addWidget(&mPersons); |
---|
24 | mMainLayout->addWidget(new QLabel("")); // spacer |
---|
25 | QLabel *abstract = new QLabel("Abstract:"); |
---|
26 | abstract->setFont(f); |
---|
27 | mMainLayout->addWidget(abstract); |
---|
28 | mMainLayout->addWidget(&mAbstract); |
---|
29 | mMainLayout->addWidget(new QLabel("")); // spacer |
---|
30 | QLabel *description = new QLabel("Description:"); |
---|
31 | description->setFont(f); |
---|
32 | mMainLayout->addWidget(description); |
---|
33 | mMainLayout->addWidget(&mDescription); |
---|
34 | setLayout(mMainLayout); |
---|
35 | } |
---|
36 | |
---|
37 | void DetailsContainer::setPersons(const QStringList &aPersons) |
---|
38 | { |
---|
39 | mPersons.setText(aPersons.join(" and ")); |
---|
40 | } |
---|
41 | |
---|
42 | void DetailsContainer::setAbstract(const QString &aAbstract) |
---|
43 | { |
---|
44 | mAbstract.setText(aAbstract); |
---|
45 | } |
---|
46 | |
---|
47 | void DetailsContainer::setDescription(const QString &aDescription) |
---|
48 | { |
---|
49 | mDescription.setText(aDescription); |
---|
50 | } |
---|
51 | |
---|
52 | EventDialog::EventDialog(const int &aEventId, QWidget *aParent) |
---|
53 | : QDialog(aParent) |
---|
54 | , mEventId(aEventId) |
---|
55 | { |
---|
56 | setupUi(this); |
---|
57 | |
---|
58 | #ifdef MAEMO |
---|
59 | showFullScreen(); |
---|
60 | #endif |
---|
61 | |
---|
62 | Event event = Event::getById(mEventId,AppSettings::confId()); |
---|
63 | |
---|
64 | title->setText(event.title()); |
---|
65 | mDetails.setPersons(event.persons()); |
---|
66 | mDetails.setAbstract(event.abstract()); |
---|
67 | mDetails.setDescription(event.description()); |
---|
68 | scrollArea->setWidget(&mDetails); |
---|
69 | |
---|
70 | connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked())); |
---|
71 | connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked())); |
---|
72 | |
---|
73 | if(event.isFavourite()) |
---|
74 | { |
---|
75 | favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png")); |
---|
76 | } |
---|
77 | |
---|
78 | if(event.hasAlarm()) |
---|
79 | { |
---|
80 | alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png")); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void EventDialog::favouriteClicked() |
---|
85 | { |
---|
86 | Event event = Event::getById(mEventId,AppSettings::confId()); |
---|
87 | |
---|
88 | if(event.isFavourite()) |
---|
89 | { |
---|
90 | event.setFavourite(false); |
---|
91 | favouriteButton->setIcon(QIcon(":/icons/favourite-offBig.png")); |
---|
92 | } |
---|
93 | else |
---|
94 | { |
---|
95 | event.setFavourite(true); |
---|
96 | favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png")); |
---|
97 | } |
---|
98 | event.update("favourite"); |
---|
99 | qDebug() << " FAVOURITE [" << event.id() << "] -> " << event.isFavourite(); |
---|
100 | // update EVENT_CONFLICT table |
---|
101 | event.updateConflicts(); |
---|
102 | // since the Favourite icon has changed, update TreeViews accordingly |
---|
103 | // all TreeViews have to listen on this signal |
---|
104 | emit(eventHasChanged(event.id())); |
---|
105 | } |
---|
106 | |
---|
107 | void EventDialog::alarmClicked() |
---|
108 | { |
---|
109 | Event event = Event::getById(mEventId,AppSettings::confId()); |
---|
110 | |
---|
111 | if(event.hasAlarm()) |
---|
112 | { |
---|
113 | event.setHasAlarm(false); // update DB |
---|
114 | alarmButton->setIcon(QIcon(":/icons/alarm-offBig.png")); |
---|
115 | #ifdef MAEMO |
---|
116 | // remove alarm from the 'alarmd' alrms list |
---|
117 | Alarm alarm; |
---|
118 | alarm.deleteAlarm(event.id()); |
---|
119 | // TODO: test if removing was successfull |
---|
120 | #endif /* MAEMO */ |
---|
121 | } |
---|
122 | else |
---|
123 | { |
---|
124 | event.setHasAlarm(true); |
---|
125 | alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png")); |
---|
126 | #ifdef MAEMO |
---|
127 | // add alarm to the 'alarmd' |
---|
128 | Alarm alarm; |
---|
129 | int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10)); |
---|
130 | qDebug() << "cookie: " << cookie; |
---|
131 | #endif /* MAEMO */ |
---|
132 | } |
---|
133 | event.update("alarm"); |
---|
134 | qDebug() << " ALARM [" << event.id() << "] -> " << event.hasAlarm(); |
---|
135 | // since the Alarm icon has changed, update TreeView accordingly |
---|
136 | // all TreeViews have to listen on this signal |
---|
137 | emit(eventHasChanged(event.id())); |
---|
138 | } |
---|
139 | |
---|