Diffstat (limited to 'libopie/big-screen/omodalhelper.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/big-screen/omodalhelper.h | 121 |
1 files changed, 103 insertions, 18 deletions
diff --git a/libopie/big-screen/omodalhelper.h b/libopie/big-screen/omodalhelper.h index c483403..bc20d10 100644 --- a/libopie/big-screen/omodalhelper.h +++ b/libopie/big-screen/omodalhelper.h | |||
@@ -55,5 +55,8 @@ struct OModalHelperBase { | |||
55 | * It's a template class but it sends signals once one Item is ready | 55 | * It's a template class but it sends signals once one Item is ready |
56 | * the signals contains the status and id of the item and then you | 56 | * the signals contains the status and id of the item and then you |
57 | * can fetch it. | 57 | * need fetch it. |
58 | * Handled Records will stay available until the first call to retrieve | ||
59 | * either the record via the TransactionID or via the QValueList<Record>. Note | ||
60 | * that most functions do not take handled records into account. | ||
58 | * Also if you edit an record external you can tell this class and it'll | 61 | * Also if you edit an record external you can tell this class and it'll |
59 | * call the merge() function of your widget to maybe merge in these changes. | 62 | * call the merge() function of your widget to maybe merge in these changes. |
@@ -80,4 +83,5 @@ public: | |||
80 | 83 | ||
81 | bool handles( Id id)const; | 84 | bool handles( Id id)const; |
85 | TransactionID transactionID( Id id)const; | ||
82 | 86 | ||
83 | void cancel(); | 87 | void cancel(); |
@@ -95,7 +99,7 @@ public: | |||
95 | RecordList done()const; | 99 | RecordList done()const; |
96 | private: | 100 | private: |
97 | virtual void done( TransactionID, QDialog* ); | 101 | virtual void done( TransactionID ); |
98 | virtual void next( TransactionID, OModalHelperControler * ); | 102 | virtual void next( TransactionID ); |
99 | virtual void prev( TransactionID, OModalHelperControler * ); | 103 | virtual void prev( TransactionID ); |
100 | 104 | ||
101 | Record nextRecord( TransactionID, int * )const; | 105 | Record nextRecord( TransactionID, int * )const; |
@@ -108,4 +112,5 @@ private: | |||
108 | OModalHelperControler *m_controler; | 112 | OModalHelperControler *m_controler; |
109 | IdMap m_ids; // maps ids (uids) to a record | 113 | IdMap m_ids; // maps ids (uids) to a record |
114 | IdMap m_doneIds; | ||
110 | TransactionMap m_transactions; // activate transactions | 115 | TransactionMap m_transactions; // activate transactions |
111 | TransactionMap m_done; // done and waiting for getting picked | 116 | TransactionMap m_done; // done and waiting for getting picked |
@@ -134,4 +139,5 @@ class OModalHelperSignal : public QObject { | |||
134 | public: | 139 | public: |
135 | OModalHelperSignal(OModalHelperBase* base, QObject* parent); | 140 | OModalHelperSignal(OModalHelperBase* base, QObject* parent); |
141 | ~OModalHelperSignal(); | ||
136 | 142 | ||
137 | signals: | 143 | signals: |
@@ -154,5 +160,7 @@ public: | |||
154 | 160 | ||
155 | public slots: | 161 | public slots: |
156 | virtual done(int result ); | 162 | virtual void done(int result ); |
163 | virtual void next(); | ||
164 | virtual void prev(); | ||
157 | private: | 165 | private: |
158 | QDialog *m_dia; | 166 | QDialog *m_dia; |
@@ -161,9 +169,9 @@ private: | |||
161 | } | 169 | } |
162 | 170 | ||
163 | class OModalQueueBar; | 171 | struct OModalQueueBar; |
164 | class OModalQueuedDialog : public QDialog { | 172 | class OModalQueuedDialog : public QDialog { |
165 | Q_OBJECT | 173 | Q_OBJECT |
166 | public: | 174 | public: |
167 | OModalQueuedDialog(QWidget *mainWidget); | 175 | OModalQueuedDialog(QDialog *mainWidget); |
168 | ~OModalQueuedDialog(); | 176 | ~OModalQueuedDialog(); |
169 | 177 | ||
@@ -172,6 +180,12 @@ public: | |||
172 | void setQueueBarEnabled( bool = true ); | 180 | void setQueueBarEnabled( bool = true ); |
173 | void setRecord( int record, int count ); | 181 | void setRecord( int record, int count ); |
182 | |||
183 | signals: | ||
184 | void next(); | ||
185 | void prev(); | ||
186 | |||
174 | private: | 187 | private: |
175 | OModalQueueBar *m_bar; | 188 | OModalQueueBar *m_bar; |
189 | QDialog *m_center; | ||
176 | }; | 190 | }; |
177 | 191 | ||
@@ -195,4 +209,5 @@ OModalHelper<Dialog, Record, Id>::OModalHelper( enum Mode mode, QObject* parent | |||
195 | m_signal = new OModalHelperSignal( this, parent ); | 209 | m_signal = new OModalHelperSignal( this, parent ); |
196 | m_controler = new OModalHelperControler( this, m_signal ); | 210 | m_controler = new OModalHelperControler( this, m_signal ); |
211 | |||
197 | } | 212 | } |
198 | 213 | ||
@@ -200,7 +215,6 @@ OModalHelper<Dialog, Record, Id>::OModalHelper( enum Mode mode, QObject* parent | |||
200 | /** | 215 | /** |
201 | * This functions looks for your record and sees if it is | 216 | * This functions looks for your record and sees if it is |
202 | * handled with this helper. Note that done and edited records | 217 | * handled with this helper. Note that done records |
203 | * will not be returned. But if you edit an already edited record | 218 | * will not be returned. |
204 | * the done record will be used | ||
205 | * | 219 | * |
206 | * @return true if the record is currenlty edited otherwise false | 220 | * @return true if the record is currenlty edited otherwise false |
@@ -221,11 +235,30 @@ bool OModalHelper<Dialog, Record, Id>::handles( Id id )const { | |||
221 | } | 235 | } |
222 | 236 | ||
237 | |||
238 | /** | ||
239 | * just like handles( Id ) but returns the TransactionId | ||
240 | */ | ||
241 | template<class Dialog, class Record, typename Id> | ||
242 | TransactionID OModalHelper<Dialog, Record, Id>::transactionID( Id id)const { | ||
243 | if ( m_transactions.isEmpty() ) | ||
244 | return false; | ||
245 | |||
246 | TransactionMap::ConstIterator it = m_transactions.begin(); | ||
247 | for ( ; it != m_transactions.end(); ++it ) | ||
248 | if ( it.data() == id ) | ||
249 | return true; | ||
250 | |||
251 | return false; | ||
252 | } | ||
253 | |||
223 | /** | 254 | /** |
224 | * Cancel will cancel all current operations and clear the list | 255 | * Cancel will cancel all current operations and clear the list |
225 | * of done operations as well. | 256 | * of done operations as well. |
257 | * This also clears all done operations you did not popped | ||
226 | */ | 258 | */ |
227 | template<class Dialog, class Record, typename Id> | 259 | template<class Dialog, class Record, typename Id> |
228 | void OModalHelper<Dialog, Record, Id>::cancel() { | 260 | void OModalHelper<Dialog, Record, Id>::cancel() { |
229 | m_ids.clear(); | 261 | m_ids.clear(); |
262 | m_doneIds.clear(); | ||
230 | m_done.clear(); | 263 | m_done.clear(); |
231 | m_transactions.clear(); | 264 | m_transactions.clear(); |
@@ -240,5 +273,5 @@ void OModalHelper<Dialog, Record, Id>::cancel() { | |||
240 | queuedDialog()->setRecord( 0, 0 ); | 273 | queuedDialog()->setRecord( 0, 0 ); |
241 | 274 | ||
242 | 275 | m_controler->setTransactionID( -1 ); | |
243 | } | 276 | } |
244 | 277 | ||
@@ -279,8 +312,13 @@ void OModalHelper::cancel( TransactionID tid ) { | |||
279 | static_cast<Dialog*>( queuedDialog()->centerDialog() )->setRecord( rec ); | 312 | static_cast<Dialog*>( queuedDialog()->centerDialog() )->setRecord( rec ); |
280 | queuedDialog()->setRecord( pos, m_transactions.count() ); | 313 | queuedDialog()->setRecord( pos, m_transactions.count() ); |
314 | m_controler->setTransactionID( tid ); | ||
281 | } | 315 | } |
282 | } | 316 | } |
283 | /* now remove from the various maps */ | 317 | /* now remove from the various maps done and currently editing map*/ |
284 | m_ids.remove( m_transactions.contains( tid ) ? m_transactions[tid] : m_done[tid ] ); | 318 | if (m_transactions.contains( tid ) ) |
319 | m_ids.remove( m_transactions[tid] ); | ||
320 | if (m_done.contains( tid ) ) | ||
321 | m_doneIds.remove( m_done[tid ] ); | ||
322 | |||
285 | 323 | ||
286 | m_done.remove( tid ); | 324 | m_done.remove( tid ); |
@@ -302,6 +340,6 @@ void OModalHelper<Dialog, Record, Id>::connectDone( QObject* rec, const char* sl | |||
302 | 340 | ||
303 | /** | 341 | /** |
304 | * Connect to the accepted Signal. SIGNAL( done(int, TransactionID ) ) | 342 | * Connect to the accepted Signal. SIGNAL( accepted(TransactionID ) ) |
305 | * This signal gets emitted whenever a Record was accepted or rejected | 343 | * This signal gets emitted whenever a Record was accepted |
306 | * | 344 | * |
307 | * @param rec The object where the slot belongs to | 345 | * @param rec The object where the slot belongs to |
@@ -309,12 +347,59 @@ void OModalHelper<Dialog, Record, Id>::connectDone( QObject* rec, const char* sl | |||
309 | */ | 347 | */ |
310 | template<class Dialog, class Record, typename Id> | 348 | template<class Dialog, class Record, typename Id> |
311 | void OModalHelper<Dialog, Record, Id>::( QObject* rec, const char* slot ) { | 349 | void OModalHelper<Dialog, Record, Id>::connectAccepted( QObject* rec, const char* slot ) { |
312 | 350 | QObject::connect(m_signal, SIGNAL(accepted(TransactionID) ), | |
351 | rec, slot ); | ||
313 | } | 352 | } |
314 | 353 | ||
354 | /** | ||
355 | * Same as the accepted method but this one gets emitted if the dialog | ||
356 | * got rejected. | ||
357 | * SIGNAL( rejected(TransactionID) ) | ||
358 | * | ||
359 | * @param rec The QObject of the slot | ||
360 | * @param slot The slot make sure the signature is correct | ||
361 | */ | ||
362 | template<class Dialog, class Record, typename Id> | ||
363 | void OModalHelper<Dialog, Record, Id>::connectRejected( QObject* rec, const char* slot ) { | ||
364 | QObject::connect(m_signal, SIGNAL(rejected(TransactionID) ), | ||
365 | rec, slot ); | ||
366 | } | ||
315 | 367 | ||
368 | /** | ||
369 | * Tell the helper to handle a record. If the record is currently handled | ||
370 | * it will be made active. | ||
371 | * Already handled record which are waiting getting popped are not taken into account | ||
372 | * Otherwise this helpers make the record editable. | ||
373 | * The record supplied needs to have a valid copy operator and constructor. | ||
374 | * In the case where the record is already present the parameter gets discarded. | ||
375 | * If you want the new record to be taken you need to cancel the Transaction first | ||
376 | * | ||
377 | * @param id The Identification of the Record. For PIM it would uid() | ||
378 | * @param rec The record we want to be edited | ||
379 | * | ||
380 | * @returns This functions returns the TransactionId assigned to the record | ||
381 | * | ||
382 | */ | ||
316 | template<class Dialog, class Record, typename Id> | 383 | template<class Dialog, class Record, typename Id> |
317 | void OModalHelper<Dialog, Record, Id>::( QObject* rec, const char* slot ) { | 384 | TransactionID OModalHelper<Dialog, Record, Id>::handle( Id id, const Record& rec ) { |
385 | static TransactionID t_id = 0; | ||
386 | t_id++; | ||
387 | /* | ||
388 | *this method consists out of two parts divided each into New and Queued Mode. | ||
389 | * Either we have the dialog already, in this case we need to highlight the widget | ||
390 | * Or we need to add it. | ||
391 | */ | ||
392 | TransactionID tid = 0; | ||
393 | /* we already have the record lets see if it was done or not */ | ||
394 | if ( m_ids.contains( id ) ) { | ||
318 | 395 | ||
396 | } | ||
397 | |||
398 | /* fall through if the record is in the done list */ | ||
399 | tid = t_id; | ||
400 | |||
401 | |||
402 | return; | ||
319 | } | 403 | } |
404 | |||
320 | #endif | 405 | #endif |