-rw-r--r-- | libopie/big-screen/omodalhelper.h | 91 |
1 files changed, 79 insertions, 12 deletions
diff --git a/libopie/big-screen/omodalhelper.h b/libopie/big-screen/omodalhelper.h index 643458f..32d921d 100644 --- a/libopie/big-screen/omodalhelper.h +++ b/libopie/big-screen/omodalhelper.h | |||
@@ -1,72 +1,139 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> | 3 | .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef HAZE_OMODAL_HELPER_H | 29 | #ifndef HAZE_OMODAL_HELPER_H |
30 | #define HAZE_OMODAL_HELPER_H | 30 | #define HAZE_OMODAL_HELPER_H |
31 | 31 | ||
32 | #include <qwidget.h> | 32 | #include <qwidget.h> |
33 | #include <qvaluelist.h> | ||
34 | #include <qmap.h> | ||
33 | 35 | ||
34 | class OModalHelperSignal : public QObject { | 36 | typedef int TransactionID; |
35 | Q_OBJECT | ||
36 | public: | ||
37 | OModalHelperSignal(); | ||
38 | 37 | ||
39 | signals: | 38 | class OModalHelperControler; |
40 | done( int status, int transaction ); | 39 | class OModalHelperSignal; |
41 | accpeted( int transaction ); | 40 | class QDialog; |
42 | rejected( int transaction ); | 41 | |
42 | struct OModalHelperBase { | ||
43 | virtual void done( TransactionID id, QWidget* ) = 0; | ||
44 | virtual void next( TransactionID, OModalHelperControler * ); | ||
45 | virtual void prev( TransactionID, OModalHelperControler * ); | ||
43 | }; | 46 | }; |
44 | 47 | ||
45 | /** | 48 | /** |
46 | * Modality sucks! ;) But it is easy to work with | 49 | * Modality sucks! ;) But it is easy to work with |
47 | * do exec() on a dialog and you know everything is funky. | 50 | * do exec() on a dialog and you know everything is funky. |
48 | * You only need to have one Dialog loaded and so on. | 51 | * You only need to have one Dialog loaded and so on. |
49 | * This class helps you to work like with modality and help | 52 | * This class helps you to work like with modality and help |
50 | * you to keep things in sync | 53 | * you to keep things in sync |
51 | * It's a template class but it sends signals once one Item is ready | 54 | * It's a template class but it sends signals once one Item is ready |
52 | * the signals contains the status and id of the item and then you | 55 | * the signals contains the status and id of the item and then you |
53 | * can fetch it. | 56 | * can fetch it. |
54 | * Also if you edit an record external you can tell this class and it'll | 57 | * Also if you edit an record external you can tell this class and it'll |
55 | * call the merge() function of your widget to maybe merge in these changes. | 58 | * call the merge() function of your widget to maybe merge in these changes. |
56 | * It also supports multiple modes. Either it can create new dialogs | 59 | * It also supports multiple modes. Either it can create new dialogs |
57 | * for each item or it can queue them depending on your usage. But it is | 60 | * for each item or it can queue them depending on your usage. But it is |
58 | * so smart that if only one item is shown that the queue bar is not shown | 61 | * so smart that if only one item is shown that the queue bar is not shown |
59 | * See the example for simple usage. | 62 | * See the example for simple usage. |
60 | * | 63 | * |
61 | * @short helps to live without modaility | 64 | * @short helps to life without modaility |
62 | * @author hOlgAr | 65 | * @author hOlgAr |
63 | * @version 0.01 | 66 | * @version 0.01 |
64 | */ | 67 | */ |
65 | template<class Dialog, class Record> | 68 | template<class Dialog, class Record, typename Id = QString> |
66 | class OModalHelper{ | 69 | class OModalHelper : private OModalHelperBase{ |
70 | friend class OModalHelperSignal; | ||
71 | friend class OModalHelperControler; | ||
67 | public: | 72 | public: |
68 | OModalHelper(QObject* parnet ); | 73 | typedef QValueList<Record> RecordList; |
74 | typedef QMap<Id, Record> IdMap; | ||
75 | typedef QMap<TransactionID, Id> TransactionMap; | ||
76 | typedef QMap<QDialog*, TransactionID> DialogMap | ||
77 | enum Mode { Queue, New }; | ||
78 | OModalHelper(enum Mode mode, QObject* parnet ); | ||
79 | |||
80 | bool handles( Id id)const; | ||
81 | |||
82 | void cancel(); | ||
83 | void cancel( TransactionID ); | ||
69 | 84 | ||
85 | void connect( QObject* rec, const char* slot ); | ||
86 | |||
87 | TransactionID handle( const Record& rec = Record() ); | ||
88 | |||
89 | void edited( TransactionID, int what, const QString& data ); | ||
90 | |||
91 | Record record( TransactionID )const; | ||
92 | RecordList done()const; | ||
93 | private: | ||
70 | }; | 94 | }; |
71 | 95 | ||
96 | |||
97 | |||
98 | /* ### FIXME use namespace with Qt3 */ | ||
99 | |||
100 | /* | ||
101 | * A note on flow. The Signal is used for QT Signals when | ||
102 | * a record is done. | ||
103 | * There is either one controler and this controler slot will | ||
104 | * be connected to a dialog signal. | ||
105 | * In Queue we get the next and prev signals and call the Helper. | ||
106 | * this then changes the Record of the dialog and sets the transactionId | ||
107 | * of the controler. | ||
108 | * For the new mode | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | class OModalHelperSignal : public QObject { | ||
113 | Q_OBJECT | ||
114 | public: | ||
115 | OModalHelperSignal(); | ||
116 | |||
117 | signals: | ||
118 | done( int status, TransactionID transaction ); | ||
119 | accpeted( TransactionID transaction ); | ||
120 | rejected( TransactionID transaction ); | ||
121 | }; | ||
122 | |||
123 | |||
124 | class OModalHelperControler : public QObject { | ||
125 | Q_OBJECT | ||
126 | public: | ||
127 | OModalHelperControler( TransactionID id ); | ||
128 | virtual TransactionID transactionID()const; | ||
129 | void setTransactionID( TransactionID id ); | ||
130 | QDialog* dialog()const; | ||
131 | |||
132 | public slots: | ||
133 | virtual done(int result ); | ||
134 | private: | ||
135 | QDialog *m_dia; | ||
136 | TransactionID m_id; | ||
137 | } | ||
138 | |||
72 | #endif | 139 | #endif |