Diffstat (limited to 'core/pim/todo/taskeditoralarms.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/todo/taskeditoralarms.cpp | 190 |
1 files changed, 176 insertions, 14 deletions
diff --git a/core/pim/todo/taskeditoralarms.cpp b/core/pim/todo/taskeditoralarms.cpp index 3cb5576..bff3338 100644 --- a/core/pim/todo/taskeditoralarms.cpp +++ b/core/pim/todo/taskeditoralarms.cpp | |||
@@ -28,49 +28,211 @@ | |||
28 | 28 | ||
29 | #include "taskeditoralarms.h" | 29 | #include "taskeditoralarms.h" |
30 | 30 | ||
31 | #include <opie/otodo.h> | ||
32 | #include <opie/opimnotifymanager.h> | ||
33 | #include <opie/otimepicker.h> | ||
34 | |||
35 | #include <qpe/datebookmonth.h> | ||
31 | #include <qpe/resource.h> | 36 | #include <qpe/resource.h> |
37 | #include <qpe/timestring.h> | ||
32 | 38 | ||
39 | #include <qdatetime.h> | ||
33 | #include <qlistview.h> | 40 | #include <qlistview.h> |
34 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
42 | #include <qpopupmenu.h> | ||
35 | #include <qlayout.h> | 43 | #include <qlayout.h> |
36 | #include <qwhatsthis.h> | 44 | #include <qwhatsthis.h> |
37 | 45 | ||
38 | TaskEditorAlarms::TaskEditorAlarms( QWidget* parent, const char* name, WFlags fl ) | 46 | |
47 | class AlarmItem : public QListViewItem { | ||
48 | public: | ||
49 | AlarmItem( QListView*, const OPimAlarm& ); | ||
50 | ~AlarmItem(); | ||
51 | |||
52 | OPimAlarm alarm()const; | ||
53 | void setAlarm( const OPimAlarm& ); | ||
54 | private: | ||
55 | QDateTime m_dt; | ||
56 | int m_type; | ||
57 | }; | ||
58 | AlarmItem::AlarmItem( QListView* view, const OPimAlarm& dt) | ||
59 | : QListViewItem(view) { | ||
60 | setAlarm( dt ); | ||
61 | } | ||
62 | void AlarmItem::setAlarm( const OPimAlarm& dt ) { | ||
63 | m_dt = dt.dateTime(); | ||
64 | m_type = dt.sound(); | ||
65 | setText( 0, TimeString::dateString( m_dt.date() ) ); | ||
66 | setText( 1, TimeString::timeString( m_dt.time() ) ); | ||
67 | setText( 2, m_type == 0 ? QObject::tr("silent") : QObject::tr("loud") ); | ||
68 | } | ||
69 | AlarmItem::~AlarmItem() { | ||
70 | } | ||
71 | OPimAlarm AlarmItem::alarm()const{ | ||
72 | OPimAlarm al( m_type, m_dt ); | ||
73 | |||
74 | return al; | ||
75 | } | ||
76 | |||
77 | TaskEditorAlarms::TaskEditorAlarms( QWidget* parent, int, const char* name, WFlags fl ) | ||
39 | : QWidget( parent, name, fl ) | 78 | : QWidget( parent, name, fl ) |
40 | { | 79 | { |
41 | QGridLayout *layout = new QGridLayout( this, 2, 3, 4, 4 ); | 80 | m_date = m_type = m_time = 0; |
81 | QGridLayout *layout = new QGridLayout( this, 2, 2, 4, 4 ); | ||
42 | 82 | ||
43 | lstAlarms = new QListView( this ); | 83 | lstAlarms = new QListView( this ); |
84 | lstAlarms->addColumn( tr("Date") ); | ||
85 | lstAlarms->addColumn( tr("Time") ); | ||
86 | lstAlarms->addColumn( tr("Type") ); | ||
87 | |||
88 | connect( lstAlarms, SIGNAL(clicked ( QListViewItem *, const QPoint &, int ) ), | ||
89 | this, SLOT(inlineEdit(QListViewItem*, const QPoint&, int ) ) ); | ||
90 | |||
44 | layout->addMultiCellWidget( lstAlarms, 0, 0, 0, 2 ); | 91 | layout->addMultiCellWidget( lstAlarms, 0, 0, 0, 2 ); |
45 | 92 | ||
46 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), this ); | 93 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), this ); |
47 | //QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); | 94 | //QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); |
48 | //connect( btn, SIGNAL( clicked() ), this, SLOT( slotNew() ) ); | 95 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotNew() ) ); |
49 | layout->addWidget( btn, 1, 0 ); | 96 | layout->addWidget( btn, 1, 0 ); |
50 | 97 | /* use when we've reminders too */ | |
98 | #if 0 | ||
51 | btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), this ); | 99 | btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), this ); |
52 | //QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); | 100 | //QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); |
53 | //connect( btn, SIGNAL( clicked() ), this, SLOT( slotEdit() ) ); | 101 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotEdit() ) ); |
54 | layout->addWidget( btn, 1, 1 ); | 102 | layout->addWidget( btn, 1, 1 ); |
103 | #endif | ||
55 | 104 | ||
56 | btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), this ); | 105 | btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), this ); |
57 | //QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); | 106 | //QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); |
58 | //connect( btn, SIGNAL( clicked() ), this, SLOT( slotDelete() ) ); | 107 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDelete() ) ); |
59 | layout->addWidget( btn, 1, 2 ); | 108 | layout->addWidget( btn, 1, 2 ); |
60 | } | 109 | } |
61 | 110 | ||
62 | TaskEditorAlarms::~TaskEditorAlarms() | 111 | TaskEditorAlarms::~TaskEditorAlarms(){ |
63 | { | ||
64 | } | 112 | } |
65 | 113 | ||
66 | void TaskEditorAlarms::slotNew() | 114 | void TaskEditorAlarms::slotNew(){ |
67 | { | 115 | (void)new AlarmItem(lstAlarms, OPimAlarm(0, QDateTime::currentDateTime() ) ); |
68 | } | 116 | } |
69 | 117 | ||
70 | void TaskEditorAlarms::slotEdit() | 118 | void TaskEditorAlarms::slotEdit(){ |
71 | { | ||
72 | } | 119 | } |
73 | 120 | ||
74 | void TaskEditorAlarms::slotDelete() | 121 | void TaskEditorAlarms::slotDelete(){ |
75 | { | 122 | QListViewItem* item = lstAlarms->currentItem(); |
123 | if (!item) return; | ||
124 | |||
125 | lstAlarms->takeItem( item ); delete item; | ||
126 | |||
127 | |||
128 | } | ||
129 | |||
130 | void TaskEditorAlarms::load( const OTodo& todo) { | ||
131 | lstAlarms->clear(); | ||
132 | if (!todo.hasNotifiers() ) return; | ||
133 | |||
134 | OPimNotifyManager::Alarms als = todo.notifiers().alarms(); | ||
135 | |||
136 | if (als.isEmpty() ) return; | ||
137 | |||
138 | OPimNotifyManager::Alarms::Iterator it = als.begin(); | ||
139 | for ( ; it != als.end(); ++it ) | ||
140 | (void)new AlarmItem( lstAlarms, (*it) ); | ||
141 | |||
142 | |||
143 | } | ||
144 | void TaskEditorAlarms::save( OTodo& todo ) { | ||
145 | if (lstAlarms->childCount() <= 0 ) return; | ||
146 | |||
147 | OPimNotifyManager::Alarms alarms; | ||
148 | |||
149 | for ( QListViewItem* item = lstAlarms->firstChild(); item; item = item->nextSibling() ) { | ||
150 | AlarmItem *alItem = static_cast<AlarmItem*>(item); | ||
151 | alarms.append( alItem->alarm() ); | ||
152 | } | ||
153 | |||
154 | OPimNotifyManager& manager = todo.notifiers(); | ||
155 | manager.setAlarms( alarms ); | ||
156 | } | ||
157 | void TaskEditorAlarms::inlineEdit( QListViewItem* alarm, const QPoint& p, int col ) { | ||
158 | if (!alarm) return; | ||
159 | |||
160 | AlarmItem* item = static_cast<AlarmItem*>(alarm); | ||
161 | switch( col ) { | ||
162 | // date | ||
163 | case 0: | ||
164 | return inlineSetDate( item, p ); | ||
165 | // time | ||
166 | case 1: | ||
167 | return inlineSetTime( item ); | ||
168 | // type | ||
169 | case 2: | ||
170 | return inlineSetType( item, p ); | ||
171 | } | ||
172 | } | ||
173 | void TaskEditorAlarms::inlineSetDate( AlarmItem* item, const QPoint& p ) { | ||
174 | QPopupMenu* pop = popup( 0 ); | ||
175 | m_dbMonth->setDate( item->alarm().dateTime().date() ); | ||
176 | pop->exec(p); | ||
177 | |||
178 | OPimAlarm al = item->alarm(); | ||
179 | QDateTime dt = al.dateTime(); | ||
180 | dt.setDate( m_dbMonth->selectedDate() ); | ||
181 | al.setDateTime( dt ); | ||
182 | item->setAlarm( al ); | ||
183 | } | ||
184 | void TaskEditorAlarms::inlineSetType( AlarmItem* item, const QPoint& p ) { | ||
185 | int type; | ||
186 | QPopupMenu* pop = popup( 2 ); | ||
187 | switch( pop->exec(p) ) { | ||
188 | case 10: | ||
189 | type = 1; | ||
190 | break; | ||
191 | case 20: | ||
192 | default: | ||
193 | type = 0; | ||
194 | } | ||
195 | OPimAlarm al = item->alarm(); | ||
196 | al.setSound( type ); | ||
197 | item->setAlarm( al ); | ||
198 | } | ||
199 | void TaskEditorAlarms::inlineSetTime( AlarmItem* item ) { | ||
200 | OPimAlarm al = item->alarm(); | ||
201 | QDateTime dt = al.dateTime(); | ||
202 | |||
203 | OTimePickerDialog dialog; | ||
204 | dialog.setTime( dt.time() ); | ||
205 | if ( dialog.exec() == QDialog::Accepted ) { | ||
206 | dt.setTime( dialog.time() ); | ||
207 | al.setDateTime( dt ); | ||
208 | item->setAlarm( al ); | ||
209 | } | ||
210 | } | ||
211 | QPopupMenu* TaskEditorAlarms::popup( int column ) { | ||
212 | QPopupMenu* pop = 0; | ||
213 | switch( column ) { | ||
214 | case 0:{ | ||
215 | if (!m_date) { | ||
216 | m_date = new QPopupMenu(this); | ||
217 | m_dbMonth = new DateBookMonth(m_date, 0, TRUE); | ||
218 | m_date->insertItem(m_dbMonth); | ||
219 | } | ||
220 | pop = m_date; | ||
221 | } | ||
222 | break; | ||
223 | case 1: | ||
224 | break; | ||
225 | case 2:{ | ||
226 | if (!m_type) { | ||
227 | m_type = new QPopupMenu(this); | ||
228 | m_type->insertItem( QObject::tr("loud"), 10 ); | ||
229 | m_type->insertItem( QObject::tr("silent"), 20 ); | ||
230 | } | ||
231 | pop = m_type; | ||
232 | } | ||
233 | break; | ||
234 | default: | ||
235 | break; | ||
236 | } | ||
237 | return pop; | ||
76 | } | 238 | } |