71 files changed, 2288 insertions, 826 deletions
diff --git a/libopie2/opiepim/backend/backends.pro b/libopie2/opiepim/backend/backends.pro new file mode 100644 index 0000000..4231a00 --- a/dev/null +++ b/libopie2/opiepim/backend/backends.pro | |||
@@ -0,0 +1,31 @@ | |||
1 | SOURCES += core/backends/ocontactaccessbackend_sql.cpp \ | ||
2 | core/backends/ocontactaccessbackend_vcard.cpp \ | ||
3 | core/backends/ocontactaccessbackend_xml.cpp \ | ||
4 | core/backends/ocontactaccess.cpp \ | ||
5 | core/backends/odatebookaccessbackend.cpp \ | ||
6 | core/backends/odatebookaccessbackend_xml.cpp \ | ||
7 | core/backends/otodoaccessbackend.cpp \ | ||
8 | core/backends/otodoaccess.cpp \ | ||
9 | core/backends/otodoaccesssql.cpp \ | ||
10 | core/backends/otodoaccessvcal.cpp \ | ||
11 | core/backends/otodoaccessxml.cpp \ | ||
12 | core/backends/odatebookaccess.cpp \ | ||
13 | core/backends/odatebookaccessbackend_sql.cpp | ||
14 | |||
15 | HEADERS += core/backends/obackendfactory.h \ | ||
16 | core/backends/ocontactaccessbackend.h \ | ||
17 | core/backends/ocontactaccessbackend_sql.h \ | ||
18 | core/backends/ocontactaccessbackend_vcard.h \ | ||
19 | core/backends/ocontactaccessbackend_xml.h \ | ||
20 | core/backends/ocontactaccess.h \ | ||
21 | core/backends/odatebookaccessbackend.h \ | ||
22 | core/backends/odatebookaccessbackend_sql.h \ | ||
23 | core/backends/odatebookaccessbackend_xml.h \ | ||
24 | core/backends/opimaccessbackend.h \ | ||
25 | core/backends/opimaccesstemplate.h \ | ||
26 | core/backends/otodoaccessbackend.h \ | ||
27 | core/backends/otodoaccess.h \ | ||
28 | core/backends/otodoaccesssql.h \ | ||
29 | core/backends/otodoaccessvcal.h \ | ||
30 | core/backends/otodoaccessxml.h \ | ||
31 | core/backends/odatebookaccess.h | ||
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 761ab9a..346e2f5 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,194 +1,150 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage Backends. | 2 | This file is part of the Opie Project |
3 | * | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | * | 5 | .=l. |
6 | * ===================================================================== | 6 | .>+-= |
7 | *This program is free software; you can redistribute it and/or | 7 | _;:, .> :=|. This program is free software; you can |
8 | *modify it under the terms of the GNU Library General Public | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | * License as published by the Free Software Foundation; | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | * either version 2 of the License, or (at your option) any later | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | * version. | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
12 | * ===================================================================== | 30 | * ===================================================================== |
13 | * ToDo: Use plugins | 31 | * ToDo: Use plugins |
14 | * ===================================================================== | 32 | * ===================================================================== |
15 | * Version: $Id$ | ||
16 | * ===================================================================== | ||
17 | * History: | ||
18 | * $Log$ | ||
19 | * Revision 1.9 2003/12/22 10:19:26 eilers | ||
20 | * Finishing implementation of sql-backend for datebook. But I have to | ||
21 | * port the PIM datebook application to use it, before I could debug the | ||
22 | * whole stuff. | ||
23 | * Thus, PIM-Database backend is finished, but highly experimental. And some | ||
24 | * parts are still generic. For instance, the "queryByExample()" methods are | ||
25 | * not (or not fully) implemented. Todo: custom-entries not stored. | ||
26 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | ||
27 | * expression search in the database, which is not supported by sqlite ! | ||
28 | * Therefore we need either an extended sqlite or a workaround which would | ||
29 | * be very slow and memory consuming.. | ||
30 | * | ||
31 | * Revision 1.8 2003/09/22 14:31:16 eilers | ||
32 | * Added first experimental incarnation of sql-backend for addressbook. | ||
33 | * Some modifications to be able to compile the todo sql-backend. | ||
34 | * A lot of changes fill follow... | ||
35 | * | ||
36 | * Revision 1.7 2003/08/01 12:30:16 eilers | ||
37 | * Merging changes from BRANCH_1_0 to HEAD | ||
38 | * | ||
39 | * Revision 1.6.4.1 2003/06/30 14:34:19 eilers | ||
40 | * Patches from Zecke: | ||
41 | * Fixing and cleaning up extraMap handling | ||
42 | * Adding d_ptr for binary compatibility in the future | ||
43 | * | ||
44 | * Revision 1.6 2003/04/13 18:07:10 zecke | ||
45 | * More API doc | ||
46 | * QString -> const QString& | ||
47 | * QString = 0l -> QString::null | ||
48 | * | ||
49 | * Revision 1.5 2003/02/21 23:31:52 zecke | ||
50 | * Add XML datebookresource | ||
51 | * -clean up todoaccessxml header | ||
52 | * -implement some more stuff in the oeven tester | ||
53 | * -extend DefaultFactory to not crash and to use datebook | ||
54 | * | ||
55 | * -reading of OEvents is working nicely.. saving will be added | ||
56 | * tomorrow | ||
57 | * -fix spelling in ODateBookAcces | ||
58 | * | ||
59 | * Revision 1.4 2002/10/14 15:55:18 eilers | ||
60 | * Redeactivate SQL.. ;) | ||
61 | * | ||
62 | * Revision 1.3 2002/10/10 17:08:58 zecke | ||
63 | * The Cache is finally in place | ||
64 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) | ||
65 | * The read ahead functionality does not make sense for XMLs backends because most of the stuff is already in memory. While using readahead on SQL makes things a lot faster.... | ||
66 | * I still have to fully implement read ahead | ||
67 | * This change is bic but sc | ||
68 | * | ||
69 | * Revision 1.2 2002/10/08 09:27:36 eilers | ||
70 | * Fixed libopie.pro to include the new pim-API. | ||
71 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | ||
72 | * compile itself would need to install libsqlite, libopiesql... | ||
73 | * Therefore, the backend currently uses XML only.. | ||
74 | * | ||
75 | * Revision 1.1 2002/10/07 17:35:01 eilers | ||
76 | * added OBackendFactory for advanced backend access | ||
77 | * | ||
78 | * | ||
79 | * ===================================================================== | ||
80 | */ | 33 | */ |
81 | #ifndef OPIE_BACKENDFACTORY_H_ | 34 | #ifndef OPIE_BACKENDFACTORY_H_ |
82 | #define OPIE_BACKENDFACTORY_H_ | 35 | #define OPIE_BACKENDFACTORY_H_ |
83 | 36 | ||
84 | #include <qstring.h> | 37 | #include <qstring.h> |
85 | #include <qasciidict.h> | 38 | #include <qasciidict.h> |
86 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
87 | 40 | ||
88 | #include "otodoaccessxml.h" | 41 | #include <opie2/otodoaccessxml.h> |
89 | #include "ocontactaccessbackend_xml.h" | 42 | #include <opie2/ocontactaccessbackend_xml.h> |
90 | #include "odatebookaccessbackend_xml.h" | 43 | #include <opie2/odatebookaccessbackend_xml.h> |
91 | 44 | ||
92 | #ifdef __USE_SQL | 45 | #ifdef __USE_SQL |
93 | #include "otodoaccesssql.h" | 46 | #include <opie2/otodoaccesssql.h> |
94 | #include "ocontactaccessbackend_sql.h" | 47 | #include <opie2/ocontactaccessbackend_sql.h> |
95 | #include "odatebookaccessbackend_sql.h" | 48 | #include <opie2/odatebookaccessbackend_sql.h> |
96 | #endif | 49 | #endif |
97 | 50 | ||
51 | namespace Opie { | ||
52 | |||
98 | class OBackendPrivate; | 53 | class OBackendPrivate; |
99 | 54 | ||
100 | /** | 55 | /** |
101 | * This class is our factory. It will give us the default implementations | 56 | * This class is our factory. It will give us the default implementations |
102 | * of at least Todolist, Contacts and Datebook. In the future this class will | 57 | * of at least Todolist, Contacts and Datebook. In the future this class will |
103 | * allow users to switch the backend with ( XML->SQLite ) without the need | 58 | * allow users to switch the backend with ( XML->SQLite ) without the need |
104 | * to recompile.# | 59 | * to recompile.# |
105 | * This class as the whole PIM Api is making use of templates | 60 | * This class as the whole PIM Api is making use of templates |
106 | * | 61 | * |
107 | * <pre> | 62 | * <pre> |
108 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | 63 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); |
109 | * backend->load(); | 64 | * backend->load(); |
110 | * </pre> | 65 | * </pre> |
111 | * | 66 | * |
112 | * @author Stefan Eilers | 67 | * @author Stefan Eilers |
113 | * @version 0.1 | 68 | * @version 0.1 |
114 | */ | 69 | */ |
115 | template<class T> | 70 | template<class T> |
116 | class OBackendFactory | 71 | class OBackendFactory |
117 | { | 72 | { |
118 | public: | 73 | public: |
119 | OBackendFactory() {}; | 74 | OBackendFactory() {}; |
120 | 75 | ||
121 | enum BACKENDS { | 76 | enum BACKENDS { |
122 | TODO, | 77 | TODO, |
123 | CONTACT, | 78 | CONTACT, |
124 | DATE | 79 | DATE |
125 | }; | 80 | }; |
126 | 81 | ||
127 | /** | 82 | /** |
128 | * Returns a backend implementation for backendName | 83 | * Returns a backend implementation for backendName |
129 | * @param backendName the type of the backend | 84 | * @param backendName the type of the backend |
130 | * @param appName will be passed on to the backend | 85 | * @param appName will be passed on to the backend |
131 | */ | 86 | */ |
132 | static T* Default( const QString backendName, const QString& appName ){ | 87 | static T* Default( const QString backendName, const QString& appName ){ |
133 | 88 | ||
134 | // __asm__("int3"); | 89 | // __asm__("int3"); |
135 | 90 | ||
136 | Config config( "pimaccess" ); | 91 | Config config( "pimaccess" ); |
137 | config.setGroup ( backendName ); | 92 | config.setGroup ( backendName ); |
138 | QString backend = config.readEntry( "usebackend" ); | 93 | QString backend = config.readEntry( "usebackend" ); |
139 | 94 | ||
140 | qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() ); | 95 | qWarning("Selected backend for %s is: %s", backendName.latin1(), backend.latin1() ); |
141 | 96 | ||
142 | QAsciiDict<int> dict ( 3 ); | 97 | QAsciiDict<int> dict ( 3 ); |
143 | dict.setAutoDelete ( TRUE ); | 98 | dict.setAutoDelete ( TRUE ); |
144 | 99 | ||
145 | dict.insert( "todo", new int (TODO) ); | 100 | dict.insert( "todo", new int (TODO) ); |
146 | dict.insert( "contact", new int (CONTACT) ); | 101 | dict.insert( "contact", new int (CONTACT) ); |
147 | dict.insert( "datebook", new int(DATE) ); | 102 | dict.insert( "datebook", new int(DATE) ); |
148 | 103 | ||
149 | int *find = dict[ backendName ]; | 104 | int *find = dict[ backendName ]; |
150 | if (!find ) return 0; | 105 | if (!find ) return 0; |
151 | 106 | ||
152 | switch ( *find ){ | 107 | switch ( *find ){ |
153 | case TODO: | 108 | case TODO: |
154 | #ifdef __USE_SQL | 109 | #ifdef __USE_SQL |
155 | if ( backend == "sql" ) | 110 | if ( backend == "sql" ) |
156 | return (T*) new OTodoAccessBackendSQL(""); | 111 | return (T*) new OTodoAccessBackendSQL(""); |
157 | #else | 112 | #else |
158 | if ( backend == "sql" ) | 113 | if ( backend == "sql" ) |
159 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); | 114 | qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); |
160 | #endif | 115 | #endif |
161 | 116 | ||
162 | return (T*) new OTodoAccessXML( appName ); | 117 | return (T*) new OTodoAccessXML( appName ); |
163 | case CONTACT: | 118 | case CONTACT: |
164 | #ifdef __USE_SQL | 119 | #ifdef __USE_SQL |
165 | if ( backend == "sql" ) | 120 | if ( backend == "sql" ) |
166 | return (T*) new OContactAccessBackend_SQL(""); | 121 | return (T*) new OContactAccessBackend_SQL(""); |
167 | #else | 122 | #else |
168 | if ( backend == "sql" ) | 123 | if ( backend == "sql" ) |
169 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); | 124 | qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); |
170 | #endif | 125 | #endif |
171 | 126 | ||
172 | return (T*) new OContactAccessBackend_XML( appName ); | 127 | return (T*) new OContactAccessBackend_XML( appName ); |
173 | case DATE: | 128 | case DATE: |
174 | #ifdef __USE_SQL | 129 | #ifdef __USE_SQL |
175 | if ( backend == "sql" ) | 130 | if ( backend == "sql" ) |
176 | return (T*) new ODateBookAccessBackend_SQL(""); | 131 | return (T*) new ODateBookAccessBackend_SQL(""); |
177 | #else | 132 | #else |
178 | if ( backend == "sql" ) | 133 | if ( backend == "sql" ) |
179 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); | 134 | qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); |
180 | #endif | 135 | #endif |
181 | 136 | ||
182 | return (T*) new ODateBookAccessBackend_XML( appName ); | 137 | return (T*) new ODateBookAccessBackend_XML( appName ); |
183 | default: | 138 | default: |
184 | return NULL; | 139 | return NULL; |
185 | } | 140 | } |
186 | 141 | ||
187 | 142 | ||
188 | } | 143 | } |
189 | private: | 144 | private: |
190 | OBackendPrivate* d; | 145 | OBackendPrivate* d; |
191 | }; | 146 | }; |
192 | 147 | ||
148 | } | ||
193 | 149 | ||
194 | #endif | 150 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index 0eac6dc..6113cea 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -1,128 +1,114 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | /** | 29 | /** |
2 | * The class responsible for managing a backend. | 30 | * The class responsible for managing a backend. |
3 | * The implementation of this abstract class contains | 31 | * The implementation of this abstract class contains |
4 | * the complete database handling. | 32 | * the complete database handling. |
5 | * | 33 | * |
6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 34 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 35 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
8 | * | 36 | * |
9 | * ===================================================================== | ||
10 | *This program is free software; you can redistribute it and/or | ||
11 | *modify it under the terms of the GNU Library General Public | ||
12 | * License as published by the Free Software Foundation; | ||
13 | * either version 2 of the License, or (at your option) any later | ||
14 | * version. | ||
15 | * ===================================================================== | ||
16 | * ToDo: Define enum for query settings | ||
17 | * ===================================================================== | ||
18 | * Version: $Id$ | ||
19 | * ===================================================================== | ||
20 | * History: | ||
21 | * $Log$ | ||
22 | * Revision 1.7 2004/02/19 02:05:37 zecke | ||
23 | * Add notes for API fixes and BC stuff | ||
24 | * | ||
25 | * Revision 1.6 2003/08/01 12:30:16 eilers | ||
26 | * Merging changes from BRANCH_1_0 to HEAD | ||
27 | * | ||
28 | * Revision 1.5.4.1 2003/06/30 14:34:19 eilers | ||
29 | * Patches from Zecke: | ||
30 | * Fixing and cleaning up extraMap handling | ||
31 | * Adding d_ptr for binary compatibility in the future | ||
32 | * | ||
33 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
34 | * More API doc | ||
35 | * QString -> const QString& | ||
36 | * QString = 0l -> QString::null | ||
37 | * | ||
38 | * Revision 1.4 2002/11/13 14:14:51 eilers | ||
39 | * Added sorted for Contacts.. | ||
40 | * | ||
41 | * Revision 1.3 2002/11/01 15:10:42 eilers | ||
42 | * Added regExp-search in database for all fields in a contact. | ||
43 | * | ||
44 | * Revision 1.2 2002/10/07 17:34:24 eilers | ||
45 | * added OBackendFactory for advanced backend access | ||
46 | * | ||
47 | * Revision 1.1 2002/09/27 17:11:44 eilers | ||
48 | * Added API for accessing the Contact-Database ! It is compiling, but | ||
49 | * please do not expect that anything is working ! | ||
50 | * I will debug that stuff in the next time .. | ||
51 | * Please read README_COMPILE for compiling ! | ||
52 | * | ||
53 | * ===================================================================== | ||
54 | * | ||
55 | */ | 37 | */ |
56 | 38 | ||
57 | #ifndef _OCONTACTACCESSBACKEND_H_ | 39 | #ifndef _OCONTACTACCESSBACKEND_H_ |
58 | #define _OCONTACTACCESSBACKEND_H_ | 40 | #define _OCONTACTACCESSBACKEND_H_ |
59 | 41 | ||
60 | #include "ocontact.h" | 42 | #include <opie2/ocontact.h> |
61 | #include "opimaccessbackend.h" | 43 | #include <opie2/opimaccessbackend.h> |
62 | 44 | ||
63 | #include <qregexp.h> | 45 | #include <qregexp.h> |
64 | 46 | ||
47 | namespace Opie { | ||
65 | /** | 48 | /** |
66 | * This class represents the interface of all Contact Backends. | 49 | * This class represents the interface of all Contact Backends. |
67 | * Derivates of this class will be used to access the contacts. | 50 | * Derivates of this class will be used to access the contacts. |
68 | * As implementation currently XML and vCard exist. This class needs to be implemented | 51 | * As implementation currently XML and vCard exist. This class needs to be implemented |
69 | * if you want to provide your own storage. | 52 | * if you want to provide your own storage. |
70 | * In all queries a list of uids is passed on instead of loading the actual record! | 53 | * In all queries a list of uids is passed on instead of loading the actual record! |
71 | * | 54 | * |
72 | * @see OContactAccessBackend_VCard | 55 | * @see OContactAccessBackend_VCard |
73 | * @see OContactAccessBackend_XML | 56 | * @see OContactAccessBackend_XML |
74 | */ | 57 | */ |
75 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 58 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
76 | public: | 59 | public: |
77 | /** | 60 | /** |
78 | * @todo make non line in regard to BC guide of KDE | 61 | * @todo make non line in regard to BC guide of KDE |
79 | */ | 62 | */ |
80 | OContactAccessBackend() {} | 63 | OContactAccessBackend() {} |
81 | /** | 64 | /** |
82 | * @todo make non inline in regard to the BC guide of KDE | 65 | * @todo make non inline in regard to the BC guide of KDE |
83 | */ | 66 | */ |
84 | virtual ~OContactAccessBackend() {} | 67 | virtual ~OContactAccessBackend() {} |
85 | 68 | ||
86 | 69 | ||
87 | /** | 70 | /** |
88 | * Return if database was changed externally. | 71 | * Return if database was changed externally. |
89 | * This may just make sense on file based databases like a XML-File. | 72 | * This may just make sense on file based databases like a XML-File. |
90 | * It is used to prevent to overwrite the current database content | 73 | * It is used to prevent to overwrite the current database content |
91 | * if the file was already changed by something else ! | 74 | * if the file was already changed by something else ! |
92 | * If this happens, we have to reload before save our data. | 75 | * If this happens, we have to reload before save our data. |
93 | * If we use real databases, this should be handled by the database | 76 | * If we use real databases, this should be handled by the database |
94 | * management system themselve, therefore this function should always return false in | 77 | * management system themselve, therefore this function should always return false in |
95 | * this case. It is not our problem to handle this conflict ... | 78 | * this case. It is not our problem to handle this conflict ... |
96 | * @return <i>true</i> if the database was changed and if save without reload will | 79 | * @return <i>true</i> if the database was changed and if save without reload will |
97 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 80 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
98 | * in this situation. | 81 | * in this situation. |
99 | */ | 82 | */ |
100 | virtual bool wasChangedExternally() = 0; | 83 | virtual bool wasChangedExternally() = 0; |
101 | 84 | ||
102 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 85 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
103 | 86 | ||
104 | /** | 87 | /** |
105 | * Return all possible settings. | 88 | * Return all possible settings. |
106 | * @return All settings provided by the current backend | 89 | * @return All settings provided by the current backend |
107 | * (i.e.: query_WildCards & query_IgnoreCase) | 90 | * (i.e.: query_WildCards & query_IgnoreCase) |
108 | */ | 91 | */ |
109 | virtual const uint querySettings() = 0; | 92 | virtual const uint querySettings() = 0; |
110 | 93 | ||
111 | /** | 94 | /** |
112 | * Check whether settings are correct. | 95 | * Check whether settings are correct. |
113 | * @return <i>true</i> if the given settings are correct and possible. | 96 | * @return <i>true</i> if the given settings are correct and possible. |
114 | */ | 97 | */ |
115 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 98 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
116 | 99 | ||
117 | /** | 100 | /** |
118 | * FIXME!!! | 101 | * FIXME!!! |
119 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category | 102 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category |
120 | */ | 103 | */ |
121 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | 104 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; |
122 | 105 | ||
123 | 106 | ||
124 | private: | 107 | private: |
125 | class Private; | 108 | class Private; |
126 | Private *d; | 109 | Private *d; |
127 | }; | 110 | }; |
111 | |||
112 | } | ||
113 | |||
128 | #endif | 114 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index a5be4c8..d0c8052 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -1,276 +1,265 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
2 | * SQL Backend for the OPIE-Contact Database. | 30 | * SQL Backend for the OPIE-Contact Database. |
3 | * | ||
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * ===================================================================== | ||
13 | * Version: $Id$ | ||
14 | * ===================================================================== | ||
15 | * History: | ||
16 | * $Log$ | ||
17 | * Revision 1.4 2003/12/22 10:19:26 eilers | ||
18 | * Finishing implementation of sql-backend for datebook. But I have to | ||
19 | * port the PIM datebook application to use it, before I could debug the | ||
20 | * whole stuff. | ||
21 | * Thus, PIM-Database backend is finished, but highly experimental. And some | ||
22 | * parts are still generic. For instance, the "queryByExample()" methods are | ||
23 | * not (or not fully) implemented. Todo: custom-entries not stored. | ||
24 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | ||
25 | * expression search in the database, which is not supported by sqlite ! | ||
26 | * Therefore we need either an extended sqlite or a workaround which would | ||
27 | * be very slow and memory consuming.. | ||
28 | * | ||
29 | * Revision 1.3 2003/12/08 15:18:10 eilers | ||
30 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
31 | * | ||
32 | * Revision 1.2 2003/09/29 07:44:26 eilers | ||
33 | * Improvement of PIM-SQL Databases, but search queries are still limited. | ||
34 | * Addressbook: Changed table layout. Now, we just need 1/3 of disk-space. | ||
35 | * Todo: Started to add new attributes. Some type conversions missing. | ||
36 | * | ||
37 | * Revision 1.1 2003/09/22 14:31:16 eilers | ||
38 | * Added first experimental incarnation of sql-backend for addressbook. | ||
39 | * Some modifications to be able to compile the todo sql-backend. | ||
40 | * A lot of changes fill follow... | ||
41 | * | ||
42 | */ | 31 | */ |
43 | 32 | ||
44 | #include "ocontactaccessbackend_sql.h" | 33 | #include "ocontactaccessbackend_sql.h" |
45 | 34 | ||
46 | #include <qarray.h> | 35 | #include <qarray.h> |
47 | #include <qdatetime.h> | 36 | #include <qdatetime.h> |
48 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
49 | 38 | ||
50 | #include <qpe/global.h> | 39 | #include <qpe/global.h> |
51 | #include <qpe/recordfields.h> | 40 | #include <qpe/recordfields.h> |
52 | 41 | ||
53 | #include <opie/ocontactfields.h> | 42 | #include <opie2/ocontactfields.h> |
54 | #include <opie/oconversion.h> | 43 | #include <opie2/oconversion.h> |
55 | #include <opie2/osqldriver.h> | 44 | #include <opie2/osqldriver.h> |
56 | #include <opie2/osqlresult.h> | 45 | #include <opie2/osqlresult.h> |
57 | #include <opie2/osqlmanager.h> | 46 | #include <opie2/osqlmanager.h> |
58 | #include <opie2/osqlquery.h> | 47 | #include <opie2/osqlquery.h> |
59 | 48 | ||
60 | 49 | ||
61 | 50 | ||
62 | 51 | ||
63 | // If defined, we use a horizontal table ( uid, attr1, attr2, attr3, ..., attrn ) instead | 52 | // If defined, we use a horizontal table ( uid, attr1, attr2, attr3, ..., attrn ) instead |
64 | // vertical like "uid, type, value". | 53 | // vertical like "uid, type, value". |
65 | // DON'T DEACTIVATE THIS DEFINE IN PRODUCTIVE ENVIRONMENTS !! | 54 | // DON'T DEACTIVATE THIS DEFINE IN PRODUCTIVE ENVIRONMENTS !! |
66 | #define __STORE_HORIZONTAL_ | 55 | #define __STORE_HORIZONTAL_ |
67 | 56 | ||
68 | // Distinct loading is not very fast. If I expect that every person has just | 57 | // Distinct loading is not very fast. If I expect that every person has just |
69 | // one (and always one) 'Last Name', I can request all uid's for existing lastnames, | 58 | // one (and always one) 'Last Name', I can request all uid's for existing lastnames, |
70 | // which is faster.. | 59 | // which is faster.. |
71 | // But this may not be true for all entries, like company contacts.. | 60 | // But this may not be true for all entries, like company contacts.. |
72 | // The current AddressBook application handles this problem, but other may not.. (eilers) | 61 | // The current AddressBook application handles this problem, but other may not.. (eilers) |
73 | #define __USE_SUPERFAST_LOADQUERY | 62 | #define __USE_SUPERFAST_LOADQUERY |
74 | 63 | ||
75 | 64 | ||
76 | /* | 65 | /* |
77 | * Implementation of used query types | 66 | * Implementation of used query types |
78 | * CREATE query | 67 | * CREATE query |
79 | * LOAD query | 68 | * LOAD query |
80 | * INSERT | 69 | * INSERT |
81 | * REMOVE | 70 | * REMOVE |
82 | * CLEAR | 71 | * CLEAR |
83 | */ | 72 | */ |
84 | namespace { | 73 | namespace Opie { |
85 | /** | 74 | /** |
86 | * CreateQuery for the Todolist Table | 75 | * CreateQuery for the Todolist Table |
87 | */ | 76 | */ |
88 | class CreateQuery : public OSQLQuery { | 77 | class CreateQuery : public OSQLQuery { |
89 | public: | 78 | public: |
90 | CreateQuery(); | 79 | CreateQuery(); |
91 | ~CreateQuery(); | 80 | ~CreateQuery(); |
92 | QString query()const; | 81 | QString query()const; |
93 | }; | 82 | }; |
94 | 83 | ||
95 | /** | 84 | /** |
96 | * Clears (delete) a Table | 85 | * Clears (delete) a Table |
97 | */ | 86 | */ |
98 | class ClearQuery : public OSQLQuery { | 87 | class ClearQuery : public OSQLQuery { |
99 | public: | 88 | public: |
100 | ClearQuery(); | 89 | ClearQuery(); |
101 | ~ClearQuery(); | 90 | ~ClearQuery(); |
102 | QString query()const; | 91 | QString query()const; |
103 | 92 | ||
104 | }; | 93 | }; |
105 | 94 | ||
106 | 95 | ||
107 | /** | 96 | /** |
108 | * LoadQuery | 97 | * LoadQuery |
109 | * this one queries for all uids | 98 | * this one queries for all uids |
110 | */ | 99 | */ |
111 | class LoadQuery : public OSQLQuery { | 100 | class LoadQuery : public OSQLQuery { |
112 | public: | 101 | public: |
113 | LoadQuery(); | 102 | LoadQuery(); |
114 | ~LoadQuery(); | 103 | ~LoadQuery(); |
115 | QString query()const; | 104 | QString query()const; |
116 | }; | 105 | }; |
117 | 106 | ||
118 | /** | 107 | /** |
119 | * inserts/adds a OContact to the table | 108 | * inserts/adds a OContact to the table |
120 | */ | 109 | */ |
121 | class InsertQuery : public OSQLQuery { | 110 | class InsertQuery : public OSQLQuery { |
122 | public: | 111 | public: |
123 | InsertQuery(const OContact& ); | 112 | InsertQuery(const OContact& ); |
124 | ~InsertQuery(); | 113 | ~InsertQuery(); |
125 | QString query()const; | 114 | QString query()const; |
126 | private: | 115 | private: |
127 | OContact m_contact; | 116 | OContact m_contact; |
128 | }; | 117 | }; |
129 | 118 | ||
130 | 119 | ||
131 | /** | 120 | /** |
132 | * removes one from the table | 121 | * removes one from the table |
133 | */ | 122 | */ |
134 | class RemoveQuery : public OSQLQuery { | 123 | class RemoveQuery : public OSQLQuery { |
135 | public: | 124 | public: |
136 | RemoveQuery(int uid ); | 125 | RemoveQuery(int uid ); |
137 | ~RemoveQuery(); | 126 | ~RemoveQuery(); |
138 | QString query()const; | 127 | QString query()const; |
139 | private: | 128 | private: |
140 | int m_uid; | 129 | int m_uid; |
141 | }; | 130 | }; |
142 | 131 | ||
143 | /** | 132 | /** |
144 | * a find query for noncustom elements | 133 | * a find query for noncustom elements |
145 | */ | 134 | */ |
146 | class FindQuery : public OSQLQuery { | 135 | class FindQuery : public OSQLQuery { |
147 | public: | 136 | public: |
148 | FindQuery(int uid); | 137 | FindQuery(int uid); |
149 | FindQuery(const QArray<int>& ); | 138 | FindQuery(const QArray<int>& ); |
150 | ~FindQuery(); | 139 | ~FindQuery(); |
151 | QString query()const; | 140 | QString query()const; |
152 | private: | 141 | private: |
153 | QString single()const; | 142 | QString single()const; |
154 | QString multi()const; | 143 | QString multi()const; |
155 | QArray<int> m_uids; | 144 | QArray<int> m_uids; |
156 | int m_uid; | 145 | int m_uid; |
157 | }; | 146 | }; |
158 | 147 | ||
159 | /** | 148 | /** |
160 | * a find query for custom elements | 149 | * a find query for custom elements |
161 | */ | 150 | */ |
162 | class FindCustomQuery : public OSQLQuery { | 151 | class FindCustomQuery : public OSQLQuery { |
163 | public: | 152 | public: |
164 | FindCustomQuery(int uid); | 153 | FindCustomQuery(int uid); |
165 | FindCustomQuery(const QArray<int>& ); | 154 | FindCustomQuery(const QArray<int>& ); |
166 | ~FindCustomQuery(); | 155 | ~FindCustomQuery(); |
167 | QString query()const; | 156 | QString query()const; |
168 | private: | 157 | private: |
169 | QString single()const; | 158 | QString single()const; |
170 | QString multi()const; | 159 | QString multi()const; |
171 | QArray<int> m_uids; | 160 | QArray<int> m_uids; |
172 | int m_uid; | 161 | int m_uid; |
173 | }; | 162 | }; |
174 | 163 | ||
175 | 164 | ||
176 | 165 | ||
177 | // We using three tables to store the information: | 166 | // We using three tables to store the information: |
178 | // 1. addressbook : It contains General information about the contact (non custom) | 167 | // 1. addressbook : It contains General information about the contact (non custom) |
179 | // 2. custom_data : Not official supported entries | 168 | // 2. custom_data : Not official supported entries |
180 | // All tables are connected by the uid of the contact. | 169 | // All tables are connected by the uid of the contact. |
181 | // Maybe I should add a table for meta-information ? | 170 | // Maybe I should add a table for meta-information ? |
182 | CreateQuery::CreateQuery() : OSQLQuery() {} | 171 | CreateQuery::CreateQuery() : OSQLQuery() {} |
183 | CreateQuery::~CreateQuery() {} | 172 | CreateQuery::~CreateQuery() {} |
184 | QString CreateQuery::query()const { | 173 | QString CreateQuery::query()const { |
185 | QString qu; | 174 | QString qu; |
186 | #ifdef __STORE_HORIZONTAL_ | 175 | #ifdef __STORE_HORIZONTAL_ |
187 | 176 | ||
188 | qu += "create table addressbook( uid PRIMARY KEY "; | 177 | qu += "create table addressbook( uid PRIMARY KEY "; |
189 | 178 | ||
190 | QStringList fieldList = OContactFields::untrfields( false ); | 179 | QStringList fieldList = OContactFields::untrfields( false ); |
191 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 180 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
192 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); | 181 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); |
193 | } | 182 | } |
194 | qu += " );"; | 183 | qu += " );"; |
195 | 184 | ||
196 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; | 185 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; |
197 | 186 | ||
198 | #else | 187 | #else |
199 | 188 | ||
200 | qu += "create table addressbook( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id));"; | 189 | qu += "create table addressbook( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id));"; |
201 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; | 190 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; |
202 | // qu += "create table dates( uid PRIMARY KEY, type, day, month, year, hour, minute, second );"; | 191 | // qu += "create table dates( uid PRIMARY KEY, type, day, month, year, hour, minute, second );"; |
203 | 192 | ||
204 | #endif // __STORE_HORIZONTAL_ | 193 | #endif // __STORE_HORIZONTAL_ |
205 | return qu; | 194 | return qu; |
206 | } | 195 | } |
207 | 196 | ||
208 | ClearQuery::ClearQuery() | 197 | ClearQuery::ClearQuery() |
209 | : OSQLQuery() {} | 198 | : OSQLQuery() {} |
210 | ClearQuery::~ClearQuery() {} | 199 | ClearQuery::~ClearQuery() {} |
211 | QString ClearQuery::query()const { | 200 | QString ClearQuery::query()const { |
212 | QString qu = "drop table addressbook;"; | 201 | QString qu = "drop table addressbook;"; |
213 | qu += "drop table custom_data;"; | 202 | qu += "drop table custom_data;"; |
214 | // qu += "drop table dates;"; | 203 | // qu += "drop table dates;"; |
215 | return qu; | 204 | return qu; |
216 | } | 205 | } |
217 | 206 | ||
218 | 207 | ||
219 | LoadQuery::LoadQuery() : OSQLQuery() {} | 208 | LoadQuery::LoadQuery() : OSQLQuery() {} |
220 | LoadQuery::~LoadQuery() {} | 209 | LoadQuery::~LoadQuery() {} |
221 | QString LoadQuery::query()const { | 210 | QString LoadQuery::query()const { |
222 | QString qu; | 211 | QString qu; |
223 | #ifdef __STORE_HORIZONTAL_ | 212 | #ifdef __STORE_HORIZONTAL_ |
224 | qu += "select uid from addressbook"; | 213 | qu += "select uid from addressbook"; |
225 | #else | 214 | #else |
226 | # ifndef __USE_SUPERFAST_LOADQUERY | 215 | # ifndef __USE_SUPERFAST_LOADQUERY |
227 | qu += "select distinct uid from addressbook"; | 216 | qu += "select distinct uid from addressbook"; |
228 | # else | 217 | # else |
229 | qu += "select uid from addressbook where type = 'Last Name'"; | 218 | qu += "select uid from addressbook where type = 'Last Name'"; |
230 | # endif // __USE_SUPERFAST_LOADQUERY | 219 | # endif // __USE_SUPERFAST_LOADQUERY |
231 | #endif // __STORE_HORIZONTAL_ | 220 | #endif // __STORE_HORIZONTAL_ |
232 | 221 | ||
233 | return qu; | 222 | return qu; |
234 | } | 223 | } |
235 | 224 | ||
236 | 225 | ||
237 | InsertQuery::InsertQuery( const OContact& contact ) | 226 | InsertQuery::InsertQuery( const OContact& contact ) |
238 | : OSQLQuery(), m_contact( contact ) { | 227 | : OSQLQuery(), m_contact( contact ) { |
239 | } | 228 | } |
240 | 229 | ||
241 | InsertQuery::~InsertQuery() { | 230 | InsertQuery::~InsertQuery() { |
242 | } | 231 | } |
243 | 232 | ||
244 | /* | 233 | /* |
245 | * converts from a OContact to a query | 234 | * converts from a OContact to a query |
246 | */ | 235 | */ |
247 | QString InsertQuery::query()const{ | 236 | QString InsertQuery::query()const{ |
248 | 237 | ||
249 | #ifdef __STORE_HORIZONTAL_ | 238 | #ifdef __STORE_HORIZONTAL_ |
250 | QString qu; | 239 | QString qu; |
251 | qu += "insert into addressbook VALUES( " + | 240 | qu += "insert into addressbook VALUES( " + |
252 | QString::number( m_contact.uid() ); | 241 | QString::number( m_contact.uid() ); |
253 | 242 | ||
254 | // Get all information out of the contact-class | 243 | // Get all information out of the contact-class |
255 | // Remember: The category is stored in contactMap, too ! | 244 | // Remember: The category is stored in contactMap, too ! |
256 | QMap<int, QString> contactMap = m_contact.toMap(); | 245 | QMap<int, QString> contactMap = m_contact.toMap(); |
257 | 246 | ||
258 | QStringList fieldList = OContactFields::untrfields( false ); | 247 | QStringList fieldList = OContactFields::untrfields( false ); |
259 | QMap<QString, int> translate = OContactFields::untrFieldsToId(); | 248 | QMap<QString, int> translate = OContactFields::untrFieldsToId(); |
260 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 249 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
261 | // Convert Column-String to Id and get value for this id.. | 250 | // Convert Column-String to Id and get value for this id.. |
262 | // Hmmm.. Maybe not very cute solution.. | 251 | // Hmmm.. Maybe not very cute solution.. |
263 | int id = translate[*it]; | 252 | int id = translate[*it]; |
264 | switch ( id ){ | 253 | switch ( id ){ |
265 | case Qtopia::Birthday:{ | 254 | case Qtopia::Birthday:{ |
266 | // These entries should stored in a special format | 255 | // These entries should stored in a special format |
267 | // year-month-day | 256 | // year-month-day |
268 | QDate day = m_contact.birthday(); | 257 | QDate day = m_contact.birthday(); |
269 | if ( day.isValid() ){ | 258 | if ( day.isValid() ){ |
270 | qu += QString(",\"%1-%2-%3\"") | 259 | qu += QString(",\"%1-%2-%3\"") |
271 | .arg( day.year() ) | 260 | .arg( day.year() ) |
272 | .arg( day.month() ) | 261 | .arg( day.month() ) |
273 | .arg( day.day() ); | 262 | .arg( day.day() ); |
274 | } else { | 263 | } else { |
275 | qu += ",\"\""; | 264 | qu += ",\"\""; |
276 | } | 265 | } |
@@ -279,384 +268,386 @@ namespace { | |||
279 | case Qtopia::Anniversary:{ | 268 | case Qtopia::Anniversary:{ |
280 | // These entries should stored in a special format | 269 | // These entries should stored in a special format |
281 | // year-month-day | 270 | // year-month-day |
282 | QDate day = m_contact.anniversary(); | 271 | QDate day = m_contact.anniversary(); |
283 | if ( day.isValid() ){ | 272 | if ( day.isValid() ){ |
284 | qu += QString(",\"%1-%2-%3\"") | 273 | qu += QString(",\"%1-%2-%3\"") |
285 | .arg( day.year() ) | 274 | .arg( day.year() ) |
286 | .arg( day.month() ) | 275 | .arg( day.month() ) |
287 | .arg( day.day() ); | 276 | .arg( day.day() ); |
288 | } else { | 277 | } else { |
289 | qu += ",\"\""; | 278 | qu += ",\"\""; |
290 | } | 279 | } |
291 | } | 280 | } |
292 | break; | 281 | break; |
293 | 282 | ||
294 | default: | 283 | default: |
295 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); | 284 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); |
296 | } | 285 | } |
297 | } | 286 | } |
298 | qu += " );"; | 287 | qu += " );"; |
299 | 288 | ||
300 | 289 | ||
301 | #else | 290 | #else |
302 | // Get all information out of the contact-class | 291 | // Get all information out of the contact-class |
303 | // Remember: The category is stored in contactMap, too ! | 292 | // Remember: The category is stored in contactMap, too ! |
304 | QMap<int, QString> contactMap = m_contact.toMap(); | 293 | QMap<int, QString> contactMap = m_contact.toMap(); |
305 | 294 | ||
306 | QMap<QString, QString> addressbook_db; | 295 | QMap<QString, QString> addressbook_db; |
307 | 296 | ||
308 | // Get the translation from the ID to the String | 297 | // Get the translation from the ID to the String |
309 | QMap<int, QString> transMap = OContactFields::idToUntrFields(); | 298 | QMap<int, QString> transMap = OContactFields::idToUntrFields(); |
310 | 299 | ||
311 | for( QMap<int, QString>::Iterator it = contactMap.begin(); | 300 | for( QMap<int, QString>::Iterator it = contactMap.begin(); |
312 | it != contactMap.end(); ++it ){ | 301 | it != contactMap.end(); ++it ){ |
313 | switch ( it.key() ){ | 302 | switch ( it.key() ){ |
314 | case Qtopia::Birthday:{ | 303 | case Qtopia::Birthday:{ |
315 | // These entries should stored in a special format | 304 | // These entries should stored in a special format |
316 | // year-month-day | 305 | // year-month-day |
317 | QDate day = m_contact.birthday(); | 306 | QDate day = m_contact.birthday(); |
318 | addressbook_db.insert( transMap[it.key()], | 307 | addressbook_db.insert( transMap[it.key()], |
319 | QString("%1-%2-%3") | 308 | QString("%1-%2-%3") |
320 | .arg( day.year() ) | 309 | .arg( day.year() ) |
321 | .arg( day.month() ) | 310 | .arg( day.month() ) |
322 | .arg( day.day() ) ); | 311 | .arg( day.day() ) ); |
323 | } | 312 | } |
324 | break; | 313 | break; |
325 | case Qtopia::Anniversary:{ | 314 | case Qtopia::Anniversary:{ |
326 | // These entries should stored in a special format | 315 | // These entries should stored in a special format |
327 | // year-month-day | 316 | // year-month-day |
328 | QDate day = m_contact.anniversary(); | 317 | QDate day = m_contact.anniversary(); |
329 | addressbook_db.insert( transMap[it.key()], | 318 | addressbook_db.insert( transMap[it.key()], |
330 | QString("%1-%2-%3") | 319 | QString("%1-%2-%3") |
331 | .arg( day.year() ) | 320 | .arg( day.year() ) |
332 | .arg( day.month() ) | 321 | .arg( day.month() ) |
333 | .arg( day.day() ) ); | 322 | .arg( day.day() ) ); |
334 | } | 323 | } |
335 | break; | 324 | break; |
336 | case Qtopia::AddressUid: // Ignore UID | 325 | case Qtopia::AddressUid: // Ignore UID |
337 | break; | 326 | break; |
338 | default: // Translate id to String | 327 | default: // Translate id to String |
339 | addressbook_db.insert( transMap[it.key()], it.data() ); | 328 | addressbook_db.insert( transMap[it.key()], it.data() ); |
340 | break; | 329 | break; |
341 | } | 330 | } |
342 | 331 | ||
343 | } | 332 | } |
344 | 333 | ||
345 | // Now convert this whole stuff into a SQL String, beginning with | 334 | // Now convert this whole stuff into a SQL String, beginning with |
346 | // the addressbook table.. | 335 | // the addressbook table.. |
347 | QString qu; | 336 | QString qu; |
348 | // qu += "begin transaction;"; | 337 | // qu += "begin transaction;"; |
349 | int id = 0; | 338 | int id = 0; |
350 | for( QMap<QString, QString>::Iterator it = addressbook_db.begin(); | 339 | for( QMap<QString, QString>::Iterator it = addressbook_db.begin(); |
351 | it != addressbook_db.end(); ++it ){ | 340 | it != addressbook_db.end(); ++it ){ |
352 | qu += "insert into addressbook VALUES(" | 341 | qu += "insert into addressbook VALUES(" |
353 | + QString::number( m_contact.uid() ) | 342 | + QString::number( m_contact.uid() ) |
354 | + "," | 343 | + "," |
355 | + QString::number( id++ ) | 344 | + QString::number( id++ ) |
356 | + ",'" | 345 | + ",'" |
357 | + it.key() //.latin1() | 346 | + it.key() //.latin1() |
358 | + "'," | 347 | + "'," |
359 | + "0" // Priority for future enhancements | 348 | + "0" // Priority for future enhancements |
360 | + ",'" | 349 | + ",'" |
361 | + it.data() //.latin1() | 350 | + it.data() //.latin1() |
362 | + "');"; | 351 | + "');"; |
363 | } | 352 | } |
364 | 353 | ||
365 | #endif //__STORE_HORIZONTAL_ | 354 | #endif //__STORE_HORIZONTAL_ |
366 | // Now add custom data.. | 355 | // Now add custom data.. |
367 | #ifdef __STORE_HORIZONTAL_ | 356 | #ifdef __STORE_HORIZONTAL_ |
368 | int id = 0; | 357 | int id = 0; |
369 | #endif | 358 | #endif |
370 | id = 0; | 359 | id = 0; |
371 | QMap<QString, QString> customMap = m_contact.toExtraMap(); | 360 | QMap<QString, QString> customMap = m_contact.toExtraMap(); |
372 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 361 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
373 | it != customMap.end(); ++it ){ | 362 | it != customMap.end(); ++it ){ |
374 | qu += "insert into custom_data VALUES(" | 363 | qu += "insert into custom_data VALUES(" |
375 | + QString::number( m_contact.uid() ) | 364 | + QString::number( m_contact.uid() ) |
376 | + "," | 365 | + "," |
377 | + QString::number( id++ ) | 366 | + QString::number( id++ ) |
378 | + ",'" | 367 | + ",'" |
379 | + it.key() //.latin1() | 368 | + it.key() //.latin1() |
380 | + "'," | 369 | + "'," |
381 | + "0" // Priority for future enhancements | 370 | + "0" // Priority for future enhancements |
382 | + ",'" | 371 | + ",'" |
383 | + it.data() //.latin1() | 372 | + it.data() //.latin1() |
384 | + "');"; | 373 | + "');"; |
385 | } | 374 | } |
386 | // qu += "commit;"; | 375 | // qu += "commit;"; |
387 | qWarning("add %s", qu.latin1() ); | 376 | qWarning("add %s", qu.latin1() ); |
388 | return qu; | 377 | return qu; |
389 | } | 378 | } |
390 | 379 | ||
391 | 380 | ||
392 | RemoveQuery::RemoveQuery(int uid ) | 381 | RemoveQuery::RemoveQuery(int uid ) |
393 | : OSQLQuery(), m_uid( uid ) {} | 382 | : OSQLQuery(), m_uid( uid ) {} |
394 | RemoveQuery::~RemoveQuery() {} | 383 | RemoveQuery::~RemoveQuery() {} |
395 | QString RemoveQuery::query()const { | 384 | QString RemoveQuery::query()const { |
396 | QString qu = "DELETE from addressbook where uid = " | 385 | QString qu = "DELETE from addressbook where uid = " |
397 | + QString::number(m_uid) + ";"; | 386 | + QString::number(m_uid) + ";"; |
398 | qu += "DELETE from custom_data where uid = " | 387 | qu += "DELETE from custom_data where uid = " |
399 | + QString::number(m_uid) + ";"; | 388 | + QString::number(m_uid) + ";"; |
400 | return qu; | 389 | return qu; |
401 | } | 390 | } |
402 | 391 | ||
403 | 392 | ||
404 | 393 | ||
405 | 394 | ||
406 | FindQuery::FindQuery(int uid) | 395 | FindQuery::FindQuery(int uid) |
407 | : OSQLQuery(), m_uid( uid ) { | 396 | : OSQLQuery(), m_uid( uid ) { |
408 | } | 397 | } |
409 | FindQuery::FindQuery(const QArray<int>& ints) | 398 | FindQuery::FindQuery(const QArray<int>& ints) |
410 | : OSQLQuery(), m_uids( ints ){ | 399 | : OSQLQuery(), m_uids( ints ){ |
411 | } | 400 | } |
412 | FindQuery::~FindQuery() { | 401 | FindQuery::~FindQuery() { |
413 | } | 402 | } |
414 | QString FindQuery::query()const{ | 403 | QString FindQuery::query()const{ |
415 | // if ( m_uids.count() == 0 ) | 404 | // if ( m_uids.count() == 0 ) |
416 | return single(); | 405 | return single(); |
417 | } | 406 | } |
418 | /* | 407 | /* |
419 | else | 408 | else |
420 | return multi(); | 409 | return multi(); |
421 | } | 410 | } |
422 | QString FindQuery::multi()const { | 411 | QString FindQuery::multi()const { |
423 | QString qu = "select uid, type, value from addressbook where"; | 412 | QString qu = "select uid, type, value from addressbook where"; |
424 | for (uint i = 0; i < m_uids.count(); i++ ) { | 413 | for (uint i = 0; i < m_uids.count(); i++ ) { |
425 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 414 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
426 | } | 415 | } |
427 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. | 416 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. |
428 | return qu; | 417 | return qu; |
429 | } | 418 | } |
430 | */ | 419 | */ |
431 | #ifdef __STORE_HORIZONTAL_ | 420 | #ifdef __STORE_HORIZONTAL_ |
432 | QString FindQuery::single()const{ | 421 | QString FindQuery::single()const{ |
433 | QString qu = "select *"; | 422 | QString qu = "select *"; |
434 | qu += " from addressbook where uid = " + QString::number(m_uid); | 423 | qu += " from addressbook where uid = " + QString::number(m_uid); |
435 | 424 | ||
436 | // qWarning("find query: %s", qu.latin1() ); | 425 | // qWarning("find query: %s", qu.latin1() ); |
437 | return qu; | 426 | return qu; |
438 | } | 427 | } |
439 | #else | 428 | #else |
440 | QString FindQuery::single()const{ | 429 | QString FindQuery::single()const{ |
441 | QString qu = "select uid, type, value from addressbook where uid = "; | 430 | QString qu = "select uid, type, value from addressbook where uid = "; |
442 | qu += QString::number(m_uid); | 431 | qu += QString::number(m_uid); |
443 | return qu; | 432 | return qu; |
444 | } | 433 | } |
445 | #endif | 434 | #endif |
446 | 435 | ||
447 | 436 | ||
448 | FindCustomQuery::FindCustomQuery(int uid) | 437 | FindCustomQuery::FindCustomQuery(int uid) |
449 | : OSQLQuery(), m_uid( uid ) { | 438 | : OSQLQuery(), m_uid( uid ) { |
450 | } | 439 | } |
451 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) | 440 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) |
452 | : OSQLQuery(), m_uids( ints ){ | 441 | : OSQLQuery(), m_uids( ints ){ |
453 | } | 442 | } |
454 | FindCustomQuery::~FindCustomQuery() { | 443 | FindCustomQuery::~FindCustomQuery() { |
455 | } | 444 | } |
456 | QString FindCustomQuery::query()const{ | 445 | QString FindCustomQuery::query()const{ |
457 | // if ( m_uids.count() == 0 ) | 446 | // if ( m_uids.count() == 0 ) |
458 | return single(); | 447 | return single(); |
459 | } | 448 | } |
460 | QString FindCustomQuery::single()const{ | 449 | QString FindCustomQuery::single()const{ |
461 | QString qu = "select uid, type, value from custom_data where uid = "; | 450 | QString qu = "select uid, type, value from custom_data where uid = "; |
462 | qu += QString::number(m_uid); | 451 | qu += QString::number(m_uid); |
463 | return qu; | 452 | return qu; |
464 | } | 453 | } |
465 | 454 | ||
466 | }; | 455 | }; |
467 | 456 | ||
468 | 457 | ||
469 | /* --------------------------------------------------------------------------- */ | 458 | /* --------------------------------------------------------------------------- */ |
470 | 459 | ||
460 | namespace Opie { | ||
461 | |||
471 | OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, | 462 | OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, |
472 | const QString& filename ): | 463 | const QString& filename ): |
473 | OContactAccessBackend(), m_changed(false), m_driver( NULL ) | 464 | OContactAccessBackend(), m_changed(false), m_driver( NULL ) |
474 | { | 465 | { |
475 | qWarning("C'tor OContactAccessBackend_SQL starts"); | 466 | qWarning("C'tor OContactAccessBackend_SQL starts"); |
476 | QTime t; | 467 | QTime t; |
477 | t.start(); | 468 | t.start(); |
478 | 469 | ||
479 | /* Expecting to access the default filename if nothing else is set */ | 470 | /* Expecting to access the default filename if nothing else is set */ |
480 | if ( filename.isEmpty() ){ | 471 | if ( filename.isEmpty() ){ |
481 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); | 472 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); |
482 | } else | 473 | } else |
483 | m_fileName = filename; | 474 | m_fileName = filename; |
484 | 475 | ||
485 | // Get the standart sql-driver from the OSQLManager.. | 476 | // Get the standart sql-driver from the OSQLManager.. |
486 | OSQLManager man; | 477 | OSQLManager man; |
487 | m_driver = man.standard(); | 478 | m_driver = man.standard(); |
488 | m_driver->setUrl( m_fileName ); | 479 | m_driver->setUrl( m_fileName ); |
489 | 480 | ||
490 | load(); | 481 | load(); |
491 | 482 | ||
492 | qWarning("C'tor OContactAccessBackend_SQL ends: %d ms", t.elapsed() ); | 483 | qWarning("C'tor OContactAccessBackend_SQL ends: %d ms", t.elapsed() ); |
493 | } | 484 | } |
494 | 485 | ||
495 | OContactAccessBackend_SQL::~OContactAccessBackend_SQL () | 486 | OContactAccessBackend_SQL::~OContactAccessBackend_SQL () |
496 | { | 487 | { |
497 | if( m_driver ) | 488 | if( m_driver ) |
498 | delete m_driver; | 489 | delete m_driver; |
499 | } | 490 | } |
500 | 491 | ||
501 | bool OContactAccessBackend_SQL::load () | 492 | bool OContactAccessBackend_SQL::load () |
502 | { | 493 | { |
503 | if (!m_driver->open() ) | 494 | if (!m_driver->open() ) |
504 | return false; | 495 | return false; |
505 | 496 | ||
506 | // Don't expect that the database exists. | 497 | // Don't expect that the database exists. |
507 | // It is save here to create the table, even if it | 498 | // It is save here to create the table, even if it |
508 | // do exist. ( Is that correct for all databases ?? ) | 499 | // do exist. ( Is that correct for all databases ?? ) |
509 | CreateQuery creat; | 500 | CreateQuery creat; |
510 | OSQLResult res = m_driver->query( &creat ); | 501 | OSQLResult res = m_driver->query( &creat ); |
511 | 502 | ||
512 | update(); | 503 | update(); |
513 | 504 | ||
514 | return true; | 505 | return true; |
515 | 506 | ||
516 | } | 507 | } |
517 | 508 | ||
518 | bool OContactAccessBackend_SQL::reload() | 509 | bool OContactAccessBackend_SQL::reload() |
519 | { | 510 | { |
520 | return load(); | 511 | return load(); |
521 | } | 512 | } |
522 | 513 | ||
523 | bool OContactAccessBackend_SQL::save() | 514 | bool OContactAccessBackend_SQL::save() |
524 | { | 515 | { |
525 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 516 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
526 | } | 517 | } |
527 | 518 | ||
528 | 519 | ||
529 | void OContactAccessBackend_SQL::clear () | 520 | void OContactAccessBackend_SQL::clear () |
530 | { | 521 | { |
531 | ClearQuery cle; | 522 | ClearQuery cle; |
532 | OSQLResult res = m_driver->query( &cle ); | 523 | OSQLResult res = m_driver->query( &cle ); |
533 | 524 | ||
534 | reload(); | 525 | reload(); |
535 | } | 526 | } |
536 | 527 | ||
537 | bool OContactAccessBackend_SQL::wasChangedExternally() | 528 | bool OContactAccessBackend_SQL::wasChangedExternally() |
538 | { | 529 | { |
539 | return false; | 530 | return false; |
540 | } | 531 | } |
541 | 532 | ||
542 | QArray<int> OContactAccessBackend_SQL::allRecords() const | 533 | QArray<int> OContactAccessBackend_SQL::allRecords() const |
543 | { | 534 | { |
544 | 535 | ||
545 | // FIXME: Think about cute handling of changed tables.. | 536 | // FIXME: Think about cute handling of changed tables.. |
546 | // Thus, we don't have to call update here... | 537 | // Thus, we don't have to call update here... |
547 | if ( m_changed ) | 538 | if ( m_changed ) |
548 | ((OContactAccessBackend_SQL*)this)->update(); | 539 | ((OContactAccessBackend_SQL*)this)->update(); |
549 | 540 | ||
550 | return m_uids; | 541 | return m_uids; |
551 | } | 542 | } |
552 | 543 | ||
553 | bool OContactAccessBackend_SQL::add ( const OContact &newcontact ) | 544 | bool OContactAccessBackend_SQL::add ( const OContact &newcontact ) |
554 | { | 545 | { |
555 | InsertQuery ins( newcontact ); | 546 | InsertQuery ins( newcontact ); |
556 | OSQLResult res = m_driver->query( &ins ); | 547 | OSQLResult res = m_driver->query( &ins ); |
557 | 548 | ||
558 | if ( res.state() == OSQLResult::Failure ) | 549 | if ( res.state() == OSQLResult::Failure ) |
559 | return false; | 550 | return false; |
560 | 551 | ||
561 | int c = m_uids.count(); | 552 | int c = m_uids.count(); |
562 | m_uids.resize( c+1 ); | 553 | m_uids.resize( c+1 ); |
563 | m_uids[c] = newcontact.uid(); | 554 | m_uids[c] = newcontact.uid(); |
564 | 555 | ||
565 | return true; | 556 | return true; |
566 | } | 557 | } |
567 | 558 | ||
568 | 559 | ||
569 | bool OContactAccessBackend_SQL::remove ( int uid ) | 560 | bool OContactAccessBackend_SQL::remove ( int uid ) |
570 | { | 561 | { |
571 | RemoveQuery rem( uid ); | 562 | RemoveQuery rem( uid ); |
572 | OSQLResult res = m_driver->query(&rem ); | 563 | OSQLResult res = m_driver->query(&rem ); |
573 | 564 | ||
574 | if ( res.state() == OSQLResult::Failure ) | 565 | if ( res.state() == OSQLResult::Failure ) |
575 | return false; | 566 | return false; |
576 | 567 | ||
577 | m_changed = true; | 568 | m_changed = true; |
578 | 569 | ||
579 | return true; | 570 | return true; |
580 | } | 571 | } |
581 | 572 | ||
582 | bool OContactAccessBackend_SQL::replace ( const OContact &contact ) | 573 | bool OContactAccessBackend_SQL::replace ( const OContact &contact ) |
583 | { | 574 | { |
584 | if ( !remove( contact.uid() ) ) | 575 | if ( !remove( contact.uid() ) ) |
585 | return false; | 576 | return false; |
586 | 577 | ||
587 | return add( contact ); | 578 | return add( contact ); |
588 | } | 579 | } |
589 | 580 | ||
590 | 581 | ||
591 | OContact OContactAccessBackend_SQL::find ( int uid ) const | 582 | OContact OContactAccessBackend_SQL::find ( int uid ) const |
592 | { | 583 | { |
593 | qWarning("OContactAccessBackend_SQL::find()"); | 584 | qWarning("OContactAccessBackend_SQL::find()"); |
594 | QTime t; | 585 | QTime t; |
595 | t.start(); | 586 | t.start(); |
596 | 587 | ||
597 | OContact retContact( requestNonCustom( uid ) ); | 588 | OContact retContact( requestNonCustom( uid ) ); |
598 | retContact.setExtraMap( requestCustom( uid ) ); | 589 | retContact.setExtraMap( requestCustom( uid ) ); |
599 | 590 | ||
600 | qWarning("OContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); | 591 | qWarning("OContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); |
601 | return retContact; | 592 | return retContact; |
602 | } | 593 | } |
603 | 594 | ||
604 | 595 | ||
605 | 596 | ||
606 | QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ) | 597 | QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ) |
607 | { | 598 | { |
608 | QString qu = "SELECT uid FROM addressbook WHERE"; | 599 | QString qu = "SELECT uid FROM addressbook WHERE"; |
609 | 600 | ||
610 | QMap<int, QString> queryFields = query.toMap(); | 601 | QMap<int, QString> queryFields = query.toMap(); |
611 | QStringList fieldList = OContactFields::untrfields( false ); | 602 | QStringList fieldList = OContactFields::untrfields( false ); |
612 | QMap<QString, int> translate = OContactFields::untrFieldsToId(); | 603 | QMap<QString, int> translate = OContactFields::untrFieldsToId(); |
613 | 604 | ||
614 | // Convert every filled field to a SQL-Query | 605 | // Convert every filled field to a SQL-Query |
615 | bool isAnyFieldSelected = false; | 606 | bool isAnyFieldSelected = false; |
616 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 607 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
617 | int id = translate[*it]; | 608 | int id = translate[*it]; |
618 | QString queryStr = queryFields[id]; | 609 | QString queryStr = queryFields[id]; |
619 | if ( !queryStr.isEmpty() ){ | 610 | if ( !queryStr.isEmpty() ){ |
620 | isAnyFieldSelected = true; | 611 | isAnyFieldSelected = true; |
621 | switch( id ){ | 612 | switch( id ){ |
622 | default: | 613 | default: |
623 | // Switching between case sensitive and insensitive... | 614 | // Switching between case sensitive and insensitive... |
624 | // LIKE is not case sensitive, GLOB is case sensitive | 615 | // LIKE is not case sensitive, GLOB is case sensitive |
625 | // Do exist a better solution to switch this ? | 616 | // Do exist a better solution to switch this ? |
626 | if ( settings & OContactAccess::IgnoreCase ) | 617 | if ( settings & OContactAccess::IgnoreCase ) |
627 | qu += "(\"" + *it + "\"" + " LIKE " + "'" | 618 | qu += "(\"" + *it + "\"" + " LIKE " + "'" |
628 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND "; | 619 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND "; |
629 | else | 620 | else |
630 | qu += "(\"" + *it + "\"" + " GLOB " + "'" | 621 | qu += "(\"" + *it + "\"" + " GLOB " + "'" |
631 | + queryStr + "'" + ") AND "; | 622 | + queryStr + "'" + ") AND "; |
632 | 623 | ||
633 | } | 624 | } |
634 | } | 625 | } |
635 | } | 626 | } |
636 | // Skip trailing "AND" | 627 | // Skip trailing "AND" |
637 | if ( isAnyFieldSelected ) | 628 | if ( isAnyFieldSelected ) |
638 | qu = qu.left( qu.length() - 4 ); | 629 | qu = qu.left( qu.length() - 4 ); |
639 | 630 | ||
640 | qWarning( "queryByExample query: %s", qu.latin1() ); | 631 | qWarning( "queryByExample query: %s", qu.latin1() ); |
641 | 632 | ||
642 | // Execute query and return the received uid's | 633 | // Execute query and return the received uid's |
643 | OSQLRawQuery raw( qu ); | 634 | OSQLRawQuery raw( qu ); |
644 | OSQLResult res = m_driver->query( &raw ); | 635 | OSQLResult res = m_driver->query( &raw ); |
645 | if ( res.state() != OSQLResult::Success ){ | 636 | if ( res.state() != OSQLResult::Success ){ |
646 | QArray<int> empty; | 637 | QArray<int> empty; |
647 | return empty; | 638 | return empty; |
648 | } | 639 | } |
649 | 640 | ||
650 | QArray<int> list = extractUids( res ); | 641 | QArray<int> list = extractUids( res ); |
651 | 642 | ||
652 | return list; | 643 | return list; |
653 | } | 644 | } |
654 | 645 | ||
655 | QArray<int> OContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 646 | QArray<int> OContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
656 | { | 647 | { |
657 | QArray<int> nix(0); | 648 | QArray<int> nix(0); |
658 | return nix; | 649 | return nix; |
659 | } | 650 | } |
660 | 651 | ||
661 | const uint OContactAccessBackend_SQL::querySettings() | 652 | const uint OContactAccessBackend_SQL::querySettings() |
662 | { | 653 | { |
@@ -751,192 +742,194 @@ void OContactAccessBackend_SQL::update() | |||
751 | t.start(); | 742 | t.start(); |
752 | 743 | ||
753 | // Now load the database set and extract the uid's | 744 | // Now load the database set and extract the uid's |
754 | // which will be held locally | 745 | // which will be held locally |
755 | 746 | ||
756 | LoadQuery lo; | 747 | LoadQuery lo; |
757 | OSQLResult res = m_driver->query(&lo); | 748 | OSQLResult res = m_driver->query(&lo); |
758 | if ( res.state() != OSQLResult::Success ) | 749 | if ( res.state() != OSQLResult::Success ) |
759 | return; | 750 | return; |
760 | 751 | ||
761 | m_uids = extractUids( res ); | 752 | m_uids = extractUids( res ); |
762 | 753 | ||
763 | m_changed = false; | 754 | m_changed = false; |
764 | 755 | ||
765 | qWarning("Update ends %d ms", t.elapsed() ); | 756 | qWarning("Update ends %d ms", t.elapsed() ); |
766 | } | 757 | } |
767 | 758 | ||
768 | QArray<int> OContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 759 | QArray<int> OContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
769 | { | 760 | { |
770 | qWarning("extractUids"); | 761 | qWarning("extractUids"); |
771 | QTime t; | 762 | QTime t; |
772 | t.start(); | 763 | t.start(); |
773 | OSQLResultItem::ValueList list = res.results(); | 764 | OSQLResultItem::ValueList list = res.results(); |
774 | OSQLResultItem::ValueList::Iterator it; | 765 | OSQLResultItem::ValueList::Iterator it; |
775 | QArray<int> ints(list.count() ); | 766 | QArray<int> ints(list.count() ); |
776 | qWarning(" count = %d", list.count() ); | 767 | qWarning(" count = %d", list.count() ); |
777 | 768 | ||
778 | int i = 0; | 769 | int i = 0; |
779 | for (it = list.begin(); it != list.end(); ++it ) { | 770 | for (it = list.begin(); it != list.end(); ++it ) { |
780 | ints[i] = (*it).data("uid").toInt(); | 771 | ints[i] = (*it).data("uid").toInt(); |
781 | i++; | 772 | i++; |
782 | } | 773 | } |
783 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); | 774 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); |
784 | 775 | ||
785 | return ints; | 776 | return ints; |
786 | 777 | ||
787 | } | 778 | } |
788 | 779 | ||
789 | #ifdef __STORE_HORIZONTAL_ | 780 | #ifdef __STORE_HORIZONTAL_ |
790 | QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const | 781 | QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const |
791 | { | 782 | { |
792 | QTime t; | 783 | QTime t; |
793 | t.start(); | 784 | t.start(); |
794 | 785 | ||
795 | QMap<int, QString> nonCustomMap; | 786 | QMap<int, QString> nonCustomMap; |
796 | 787 | ||
797 | int t2needed = 0; | 788 | int t2needed = 0; |
798 | int t3needed = 0; | 789 | int t3needed = 0; |
799 | QTime t2; | 790 | QTime t2; |
800 | t2.start(); | 791 | t2.start(); |
801 | FindQuery query( uid ); | 792 | FindQuery query( uid ); |
802 | OSQLResult res_noncustom = m_driver->query( &query ); | 793 | OSQLResult res_noncustom = m_driver->query( &query ); |
803 | t2needed = t2.elapsed(); | 794 | t2needed = t2.elapsed(); |
804 | 795 | ||
805 | OSQLResultItem resItem = res_noncustom.first(); | 796 | OSQLResultItem resItem = res_noncustom.first(); |
806 | 797 | ||
807 | QTime t3; | 798 | QTime t3; |
808 | t3.start(); | 799 | t3.start(); |
809 | // Now loop through all columns | 800 | // Now loop through all columns |
810 | QStringList fieldList = OContactFields::untrfields( false ); | 801 | QStringList fieldList = OContactFields::untrfields( false ); |
811 | QMap<QString, int> translate = OContactFields::untrFieldsToId(); | 802 | QMap<QString, int> translate = OContactFields::untrFieldsToId(); |
812 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 803 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
813 | // Get data for the selected column and store it with the | 804 | // Get data for the selected column and store it with the |
814 | // corresponding id into the map.. | 805 | // corresponding id into the map.. |
815 | 806 | ||
816 | int id = translate[*it]; | 807 | int id = translate[*it]; |
817 | QString value = resItem.data( (*it) ); | 808 | QString value = resItem.data( (*it) ); |
818 | 809 | ||
819 | // qWarning("Reading %s... found: %s", (*it).latin1(), value.latin1() ); | 810 | // qWarning("Reading %s... found: %s", (*it).latin1(), value.latin1() ); |
820 | 811 | ||
821 | switch( id ){ | 812 | switch( id ){ |
822 | case Qtopia::Birthday: | 813 | case Qtopia::Birthday: |
823 | case Qtopia::Anniversary:{ | 814 | case Qtopia::Anniversary:{ |
824 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) | 815 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) |
825 | QStringList list = QStringList::split( '-', value ); | 816 | QStringList list = QStringList::split( '-', value ); |
826 | QStringList::Iterator lit = list.begin(); | 817 | QStringList::Iterator lit = list.begin(); |
827 | int year = (*lit).toInt(); | 818 | int year = (*lit).toInt(); |
828 | int month = (*(++lit)).toInt(); | 819 | int month = (*(++lit)).toInt(); |
829 | int day = (*(++lit)).toInt(); | 820 | int day = (*(++lit)).toInt(); |
830 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ | 821 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ |
831 | QDate date( year, month, day ); | 822 | QDate date( year, month, day ); |
832 | nonCustomMap.insert( id, OConversion::dateToString( date ) ); | 823 | nonCustomMap.insert( id, OConversion::dateToString( date ) ); |
833 | } | 824 | } |
834 | } | 825 | } |
835 | break; | 826 | break; |
836 | case Qtopia::AddressCategory: | 827 | case Qtopia::AddressCategory: |
837 | qWarning("Category is: %s", value.latin1() ); | 828 | qWarning("Category is: %s", value.latin1() ); |
838 | default: | 829 | default: |
839 | nonCustomMap.insert( id, value ); | 830 | nonCustomMap.insert( id, value ); |
840 | } | 831 | } |
841 | } | 832 | } |
842 | 833 | ||
843 | // First insert uid | 834 | // First insert uid |
844 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); | 835 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); |
845 | t3needed = t3.elapsed(); | 836 | t3needed = t3.elapsed(); |
846 | 837 | ||
847 | // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() ); | 838 | // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() ); |
848 | qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", | 839 | qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", |
849 | t.elapsed(), t2needed, t3needed ); | 840 | t.elapsed(), t2needed, t3needed ); |
850 | 841 | ||
851 | return nonCustomMap; | 842 | return nonCustomMap; |
852 | } | 843 | } |
853 | #else | 844 | #else |
854 | 845 | ||
855 | QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const | 846 | QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const |
856 | { | 847 | { |
857 | QTime t; | 848 | QTime t; |
858 | t.start(); | 849 | t.start(); |
859 | 850 | ||
860 | QMap<int, QString> nonCustomMap; | 851 | QMap<int, QString> nonCustomMap; |
861 | 852 | ||
862 | int t2needed = 0; | 853 | int t2needed = 0; |
863 | QTime t2; | 854 | QTime t2; |
864 | t2.start(); | 855 | t2.start(); |
865 | FindQuery query( uid ); | 856 | FindQuery query( uid ); |
866 | OSQLResult res_noncustom = m_driver->query( &query ); | 857 | OSQLResult res_noncustom = m_driver->query( &query ); |
867 | t2needed = t2.elapsed(); | 858 | t2needed = t2.elapsed(); |
868 | 859 | ||
869 | if ( res_noncustom.state() == OSQLResult::Failure ) { | 860 | if ( res_noncustom.state() == OSQLResult::Failure ) { |
870 | qWarning("OSQLResult::Failure in find query !!"); | 861 | qWarning("OSQLResult::Failure in find query !!"); |
871 | QMap<int, QString> empty; | 862 | QMap<int, QString> empty; |
872 | return empty; | 863 | return empty; |
873 | } | 864 | } |
874 | 865 | ||
875 | int t3needed = 0; | 866 | int t3needed = 0; |
876 | QTime t3; | 867 | QTime t3; |
877 | t3.start(); | 868 | t3.start(); |
878 | QMap<QString, int> translateMap = OContactFields::untrFieldsToId(); | 869 | QMap<QString, int> translateMap = OContactFields::untrFieldsToId(); |
879 | 870 | ||
880 | OSQLResultItem::ValueList list = res_noncustom.results(); | 871 | OSQLResultItem::ValueList list = res_noncustom.results(); |
881 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 872 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
882 | for ( ; it != list.end(); ++it ) { | 873 | for ( ; it != list.end(); ++it ) { |
883 | if ( (*it).data("type") != "" ){ | 874 | if ( (*it).data("type") != "" ){ |
884 | int typeId = translateMap[(*it).data( "type" )]; | 875 | int typeId = translateMap[(*it).data( "type" )]; |
885 | switch( typeId ){ | 876 | switch( typeId ){ |
886 | case Qtopia::Birthday: | 877 | case Qtopia::Birthday: |
887 | case Qtopia::Anniversary:{ | 878 | case Qtopia::Anniversary:{ |
888 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) | 879 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) |
889 | QStringList list = QStringList::split( '-', (*it).data( "value" ) ); | 880 | QStringList list = QStringList::split( '-', (*it).data( "value" ) ); |
890 | QStringList::Iterator lit = list.begin(); | 881 | QStringList::Iterator lit = list.begin(); |
891 | int year = (*lit).toInt(); | 882 | int year = (*lit).toInt(); |
892 | qWarning("1. %s", (*lit).latin1()); | 883 | qWarning("1. %s", (*lit).latin1()); |
893 | int month = (*(++lit)).toInt(); | 884 | int month = (*(++lit)).toInt(); |
894 | qWarning("2. %s", (*lit).latin1()); | 885 | qWarning("2. %s", (*lit).latin1()); |
895 | int day = (*(++lit)).toInt(); | 886 | int day = (*(++lit)).toInt(); |
896 | qWarning("3. %s", (*lit).latin1()); | 887 | qWarning("3. %s", (*lit).latin1()); |
897 | qWarning( "RequestNonCustom->Converting:%s to Year: %d, Month: %d, Day: %d ", (*it).data( "value" ).latin1(), year, month, day ); | 888 | qWarning( "RequestNonCustom->Converting:%s to Year: %d, Month: %d, Day: %d ", (*it).data( "value" ).latin1(), year, month, day ); |
898 | QDate date( year, month, day ); | 889 | QDate date( year, month, day ); |
899 | nonCustomMap.insert( typeId, OConversion::dateToString( date ) ); | 890 | nonCustomMap.insert( typeId, OConversion::dateToString( date ) ); |
900 | } | 891 | } |
901 | break; | 892 | break; |
902 | default: | 893 | default: |
903 | nonCustomMap.insert( typeId, | 894 | nonCustomMap.insert( typeId, |
904 | (*it).data( "value" ) ); | 895 | (*it).data( "value" ) ); |
905 | } | 896 | } |
906 | } | 897 | } |
907 | } | 898 | } |
908 | // Add UID to Map.. | 899 | // Add UID to Map.. |
909 | nonCustomMap.insert( Qtopia::AddressUid, QString::number( uid ) ); | 900 | nonCustomMap.insert( Qtopia::AddressUid, QString::number( uid ) ); |
910 | t3needed = t3.elapsed(); | 901 | t3needed = t3.elapsed(); |
911 | 902 | ||
912 | qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", t.elapsed(), t2needed, t3needed ); | 903 | qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", t.elapsed(), t2needed, t3needed ); |
913 | return nonCustomMap; | 904 | return nonCustomMap; |
914 | } | 905 | } |
915 | 906 | ||
916 | #endif // __STORE_HORIZONTAL_ | 907 | #endif // __STORE_HORIZONTAL_ |
917 | 908 | ||
918 | QMap<QString, QString> OContactAccessBackend_SQL::requestCustom( int uid ) const | 909 | QMap<QString, QString> OContactAccessBackend_SQL::requestCustom( int uid ) const |
919 | { | 910 | { |
920 | QTime t; | 911 | QTime t; |
921 | t.start(); | 912 | t.start(); |
922 | 913 | ||
923 | QMap<QString, QString> customMap; | 914 | QMap<QString, QString> customMap; |
924 | 915 | ||
925 | FindCustomQuery query( uid ); | 916 | FindCustomQuery query( uid ); |
926 | OSQLResult res_custom = m_driver->query( &query ); | 917 | OSQLResult res_custom = m_driver->query( &query ); |
927 | 918 | ||
928 | if ( res_custom.state() == OSQLResult::Failure ) { | 919 | if ( res_custom.state() == OSQLResult::Failure ) { |
929 | qWarning("OSQLResult::Failure in find query !!"); | 920 | qWarning("OSQLResult::Failure in find query !!"); |
930 | QMap<QString, QString> empty; | 921 | QMap<QString, QString> empty; |
931 | return empty; | 922 | return empty; |
932 | } | 923 | } |
933 | 924 | ||
934 | OSQLResultItem::ValueList list = res_custom.results(); | 925 | OSQLResultItem::ValueList list = res_custom.results(); |
935 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 926 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
936 | for ( ; it != list.end(); ++it ) { | 927 | for ( ; it != list.end(); ++it ) { |
937 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 928 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
938 | } | 929 | } |
939 | 930 | ||
940 | qWarning("RequestCustom needed: %d ms", t.elapsed() ); | 931 | qWarning("RequestCustom needed: %d ms", t.elapsed() ); |
941 | return customMap; | 932 | return customMap; |
942 | } | 933 | } |
934 | |||
935 | } | ||
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h index b8f1d8d..55b95fd 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.h | |||
@@ -1,101 +1,109 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
2 | * SQL Backend for the OPIE-Contact Database. | 30 | * SQL Backend for the OPIE-Contact Database. |
3 | * | ||
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * | ||
13 | * | ||
14 | * ===================================================================== | ||
15 | * Version: $Id$ | ||
16 | * ===================================================================== | ||
17 | * History: | ||
18 | * $Log$ | ||
19 | * Revision 1.2 2003/12/08 15:18:11 eilers | ||
20 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
21 | * | ||
22 | * Revision 1.1 2003/09/22 14:31:16 eilers | ||
23 | * Added first experimental incarnation of sql-backend for addressbook. | ||
24 | * Some modifications to be able to compile the todo sql-backend. | ||
25 | * A lot of changes fill follow... | ||
26 | * | ||
27 | * | ||
28 | */ | 31 | */ |
29 | 32 | ||
30 | #ifndef _OContactAccessBackend_SQL_ | 33 | #ifndef _OContactAccessBackend_SQL_ |
31 | #define _OContactAccessBackend_SQL_ | 34 | #define _OContactAccessBackend_SQL_ |
32 | 35 | ||
33 | #include "ocontactaccessbackend.h" | 36 | #include <opie2/ocontactaccessbackend.h> |
34 | #include "ocontactaccess.h" | 37 | #include <opie2/ocontactaccess.h> |
35 | 38 | ||
36 | #include <qlist.h> | 39 | #include <qlist.h> |
37 | #include <qdict.h> | 40 | #include <qdict.h> |
38 | 41 | ||
42 | /* aren't in namespace Opie yet - alwin */ | ||
39 | class OSQLDriver; | 43 | class OSQLDriver; |
40 | class OSQLResult; | 44 | class OSQLResult; |
41 | class OSQLResultItem; | 45 | class OSQLResultItem; |
42 | 46 | ||
47 | namespace Opie { | ||
48 | |||
43 | /* the default xml implementation */ | 49 | /* the default xml implementation */ |
44 | /** | 50 | /** |
45 | * This class is the SQL implementation of a Contact backend | 51 | * This class is the SQL implementation of a Contact backend |
46 | * it does implement everything available for OContact. | 52 | * it does implement everything available for OContact. |
47 | * @see OPimAccessBackend for more information of available methods | 53 | * @see OPimAccessBackend for more information of available methods |
48 | */ | 54 | */ |
49 | class OContactAccessBackend_SQL : public OContactAccessBackend { | 55 | class OContactAccessBackend_SQL : public OContactAccessBackend { |
50 | public: | 56 | public: |
51 | OContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null ); | 57 | OContactAccessBackend_SQL ( const QString& appname, const QString& filename = QString::null ); |
52 | 58 | ||
53 | ~OContactAccessBackend_SQL (); | 59 | ~OContactAccessBackend_SQL (); |
54 | 60 | ||
55 | bool save(); | 61 | bool save(); |
56 | 62 | ||
57 | bool load (); | 63 | bool load (); |
58 | 64 | ||
59 | void clear (); | 65 | void clear (); |
60 | 66 | ||
61 | bool wasChangedExternally(); | 67 | bool wasChangedExternally(); |
62 | 68 | ||
63 | QArray<int> allRecords() const; | 69 | QArray<int> allRecords() const; |
64 | 70 | ||
65 | OContact find ( int uid ) const; | 71 | OContact find ( int uid ) const; |
66 | // FIXME: Add lookahead-cache support ! | 72 | // FIXME: Add lookahead-cache support ! |
67 | //OContact find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; | 73 | //OContact find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; |
68 | 74 | ||
69 | QArray<int> queryByExample ( const OContact &query, int settings, | 75 | QArray<int> queryByExample ( const OContact &query, int settings, |
70 | const QDateTime& d ); | 76 | const QDateTime& d ); |
71 | 77 | ||
72 | QArray<int> matchRegexp( const QRegExp &r ) const; | 78 | QArray<int> matchRegexp( const QRegExp &r ) const; |
73 | 79 | ||
74 | const uint querySettings(); | 80 | const uint querySettings(); |
75 | 81 | ||
76 | bool hasQuerySettings (uint querySettings) const; | 82 | bool hasQuerySettings (uint querySettings) const; |
77 | 83 | ||
78 | // Currently only asc implemented.. | 84 | // Currently only asc implemented.. |
79 | QArray<int> sorted( bool asc, int , int , int ); | 85 | QArray<int> sorted( bool asc, int , int , int ); |
80 | bool add ( const OContact &newcontact ); | 86 | bool add ( const OContact &newcontact ); |
81 | 87 | ||
82 | bool replace ( const OContact &contact ); | 88 | bool replace ( const OContact &contact ); |
83 | 89 | ||
84 | bool remove ( int uid ); | 90 | bool remove ( int uid ); |
85 | bool reload(); | 91 | bool reload(); |
86 | 92 | ||
87 | private: | 93 | private: |
88 | QArray<int> extractUids( OSQLResult& res ) const; | 94 | QArray<int> extractUids( OSQLResult& res ) const; |
89 | QMap<int, QString> requestNonCustom( int uid ) const; | 95 | QMap<int, QString> requestNonCustom( int uid ) const; |
90 | QMap<QString, QString> requestCustom( int uid ) const; | 96 | QMap<QString, QString> requestCustom( int uid ) const; |
91 | void update(); | 97 | void update(); |
92 | 98 | ||
93 | protected: | 99 | protected: |
94 | bool m_changed; | 100 | bool m_changed; |
95 | QString m_fileName; | 101 | QString m_fileName; |
96 | QArray<int> m_uids; | 102 | QArray<int> m_uids; |
97 | 103 | ||
98 | OSQLDriver* m_driver; | 104 | OSQLDriver* m_driver; |
99 | }; | 105 | }; |
100 | 106 | ||
107 | } | ||
108 | |||
101 | #endif | 109 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index b60c5be..f85cf38 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -1,290 +1,233 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
2 | * VCard Backend for the OPIE-Contact Database. | 30 | * VCard Backend for the OPIE-Contact Database. |
3 | * | ||
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
6 | * | ||
7 | * ===================================================================== | ||
8 | *This program is free software; you can redistribute it and/or | ||
9 | *modify it under the terms of the GNU Library General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2 of the License, or (at your option) any later version. | ||
12 | * ===================================================================== | ||
13 | * ToDo: | ||
14 | * | ||
15 | * ===================================================================== | ||
16 | * Version: $Id$ | ||
17 | * ===================================================================== | ||
18 | * History: | ||
19 | * $Log$ | ||
20 | * Revision 1.11 2003/08/01 12:30:16 eilers | ||
21 | * Merging changes from BRANCH_1_0 to HEAD | ||
22 | * | ||
23 | * Revision 1.10.4.3 2003/07/23 08:54:37 eilers | ||
24 | * Default email was added to the list of all emails, which already contains | ||
25 | * the default email.. | ||
26 | * This closes bug #1045 | ||
27 | * | ||
28 | * Revision 1.10.4.2 2003/07/23 08:44:45 eilers | ||
29 | * Importing of Notes in vcard files wasn't implemented. | ||
30 | * Closes bug #1044 | ||
31 | * | ||
32 | * Revision 1.10.4.1 2003/06/02 13:37:49 eilers | ||
33 | * Fixing memory leak | ||
34 | * | ||
35 | * Revision 1.10 2003/04/13 18:07:10 zecke | ||
36 | * More API doc | ||
37 | * QString -> const QString& | ||
38 | * QString = 0l -> QString::null | ||
39 | * | ||
40 | * Revision 1.9 2003/03/21 10:33:09 eilers | ||
41 | * Merged speed optimized xml backend for contacts to main. | ||
42 | * Added QDateTime to querybyexample. For instance, it is now possible to get | ||
43 | * all Birthdays/Anniversaries between two dates. This should be used | ||
44 | * to show all birthdays in the datebook.. | ||
45 | * This change is sourcecode backward compatible but you have to upgrade | ||
46 | * the binaries for today-addressbook. | ||
47 | * | ||
48 | * Revision 1.8 2003/02/21 16:52:49 zecke | ||
49 | * -Remove old Todo classes they're deprecated and today I already using the | ||
50 | * new API | ||
51 | * -Guard against self assignment in OTodo | ||
52 | * -Add test apps for OPIM | ||
53 | * -Opiefied Event classes | ||
54 | * -Added TimeZone handling and pinning of TimeZones to OEvent | ||
55 | * -Adjust ORecur and the widget to better timezone behaviour | ||
56 | * | ||
57 | * Revision 1.7 2003/02/16 22:25:46 zecke | ||
58 | * 0000276 Fix for that bug.. or better temp workaround | ||
59 | * A Preferred Number is HOME|VOICE | ||
60 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test | ||
61 | * triggers both | ||
62 | * and the cell phone number overrides the other entries.. | ||
63 | * | ||
64 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the | ||
65 | * number | ||
66 | * | ||
67 | * The right and final fix would be to reorder the if statement to make it | ||
68 | * if else based and the less common thing put to the bottom | ||
69 | * | ||
70 | * OTodoAccessVcal fix the date for beaming | ||
71 | * | ||
72 | * Revision 1.6 2003/01/13 15:49:31 eilers | ||
73 | * Fixing crash when businesscard.vcf is missing.. | ||
74 | * | ||
75 | * Revision 1.5 2002/12/07 13:26:22 eilers | ||
76 | * Fixing bug in storing anniversary.. | ||
77 | * | ||
78 | * Revision 1.4 2002/11/13 14:14:51 eilers | ||
79 | * Added sorted for Contacts.. | ||
80 | * | ||
81 | * Revision 1.3 2002/11/11 16:41:09 kergoth | ||
82 | * no default arguments in implementation | ||
83 | * | ||
84 | * Revision 1.2 2002/11/10 15:41:53 eilers | ||
85 | * Bugfixes.. | ||
86 | * | ||
87 | * Revision 1.1 2002/11/09 14:34:52 eilers | ||
88 | * Added VCard Backend. | ||
89 | * | ||
90 | */ | 31 | */ |
91 | #include "ocontactaccessbackend_vcard.h" | 32 | #include <opie2/ocontactaccessbackend_vcard.h> |
92 | #include "../../library/backend/vobject_p.h" | 33 | #include "../../../../library/backend/vobject_p.h" |
93 | #include "../../library/backend/qfiledirect_p.h" | 34 | #include "../../../../library/backend/qfiledirect_p.h" |
94 | 35 | ||
95 | #include <qpe/timeconversion.h> | 36 | #include <qpe/timeconversion.h> |
96 | 37 | ||
97 | #include <qfile.h> | 38 | #include <qfile.h> |
98 | 39 | ||
40 | namespace Opie { | ||
41 | |||
99 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): | 42 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): |
100 | m_dirty( false ), | 43 | m_dirty( false ), |
101 | m_file( filename ) | 44 | m_file( filename ) |
102 | { | 45 | { |
103 | load(); | 46 | load(); |
104 | } | 47 | } |
105 | 48 | ||
106 | 49 | ||
107 | bool OContactAccessBackend_VCard::load () | 50 | bool OContactAccessBackend_VCard::load () |
108 | { | 51 | { |
109 | m_map.clear(); | 52 | m_map.clear(); |
110 | m_dirty = false; | 53 | m_dirty = false; |
111 | 54 | ||
112 | VObject* obj = 0l; | 55 | VObject* obj = 0l; |
113 | 56 | ||
114 | if ( QFile::exists(m_file) ){ | 57 | if ( QFile::exists(m_file) ){ |
115 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 58 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
116 | if ( !obj ) | 59 | if ( !obj ) |
117 | return false; | 60 | return false; |
118 | }else{ | 61 | }else{ |
119 | qWarning("File \"%s\" not found !", m_file.latin1() ); | 62 | qWarning("File \"%s\" not found !", m_file.latin1() ); |
120 | return false; | 63 | return false; |
121 | } | 64 | } |
122 | 65 | ||
123 | while ( obj ) { | 66 | while ( obj ) { |
124 | OContact con = parseVObject( obj ); | 67 | OContact con = parseVObject( obj ); |
125 | /* | 68 | /* |
126 | * if uid is 0 assign a new one | 69 | * if uid is 0 assign a new one |
127 | * this at least happens on | 70 | * this at least happens on |
128 | * Nokia6210 | 71 | * Nokia6210 |
129 | */ | 72 | */ |
130 | if ( con.uid() == 0 ){ | 73 | if ( con.uid() == 0 ){ |
131 | con.setUid( 1 ); | 74 | con.setUid( 1 ); |
132 | qWarning("assigned new uid %d",con.uid() ); | 75 | qWarning("assigned new uid %d",con.uid() ); |
133 | } | 76 | } |
134 | 77 | ||
135 | m_map.insert( con.uid(), con ); | 78 | m_map.insert( con.uid(), con ); |
136 | 79 | ||
137 | VObject *t = obj; | 80 | VObject *t = obj; |
138 | obj = nextVObjectInList(obj); | 81 | obj = nextVObjectInList(obj); |
139 | cleanVObject( t ); | 82 | cleanVObject( t ); |
140 | } | 83 | } |
141 | 84 | ||
142 | return true; | 85 | return true; |
143 | 86 | ||
144 | } | 87 | } |
145 | bool OContactAccessBackend_VCard::reload() | 88 | bool OContactAccessBackend_VCard::reload() |
146 | { | 89 | { |
147 | return load(); | 90 | return load(); |
148 | } | 91 | } |
149 | bool OContactAccessBackend_VCard::save() | 92 | bool OContactAccessBackend_VCard::save() |
150 | { | 93 | { |
151 | if (!m_dirty ) | 94 | if (!m_dirty ) |
152 | return true; | 95 | return true; |
153 | 96 | ||
154 | QFileDirect file( m_file ); | 97 | QFileDirect file( m_file ); |
155 | if (!file.open(IO_WriteOnly ) ) | 98 | if (!file.open(IO_WriteOnly ) ) |
156 | return false; | 99 | return false; |
157 | 100 | ||
158 | VObject *obj; | 101 | VObject *obj; |
159 | obj = newVObject( VCCalProp ); | 102 | obj = newVObject( VCCalProp ); |
160 | addPropValue( obj, VCVersionProp, "1.0" ); | 103 | addPropValue( obj, VCVersionProp, "1.0" ); |
161 | 104 | ||
162 | VObject *vo; | 105 | VObject *vo; |
163 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 106 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
164 | vo = createVObject( *it ); | 107 | vo = createVObject( *it ); |
165 | writeVObject( file.directHandle() , vo ); | 108 | writeVObject( file.directHandle() , vo ); |
166 | cleanVObject( vo ); | 109 | cleanVObject( vo ); |
167 | } | 110 | } |
168 | cleanStrTbl(); | 111 | cleanStrTbl(); |
169 | deleteVObject( obj ); | 112 | deleteVObject( obj ); |
170 | 113 | ||
171 | m_dirty = false; | 114 | m_dirty = false; |
172 | return true; | 115 | return true; |
173 | 116 | ||
174 | 117 | ||
175 | } | 118 | } |
176 | void OContactAccessBackend_VCard::clear () | 119 | void OContactAccessBackend_VCard::clear () |
177 | { | 120 | { |
178 | m_map.clear(); | 121 | m_map.clear(); |
179 | m_dirty = true; // ??? sure ? (se) | 122 | m_dirty = true; // ??? sure ? (se) |
180 | } | 123 | } |
181 | 124 | ||
182 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 125 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
183 | { | 126 | { |
184 | m_map.insert( newcontact.uid(), newcontact ); | 127 | m_map.insert( newcontact.uid(), newcontact ); |
185 | m_dirty = true; | 128 | m_dirty = true; |
186 | return true; | 129 | return true; |
187 | } | 130 | } |
188 | 131 | ||
189 | bool OContactAccessBackend_VCard::remove ( int uid ) | 132 | bool OContactAccessBackend_VCard::remove ( int uid ) |
190 | { | 133 | { |
191 | m_map.remove( uid ); | 134 | m_map.remove( uid ); |
192 | m_dirty = true; | 135 | m_dirty = true; |
193 | return true; | 136 | return true; |
194 | } | 137 | } |
195 | 138 | ||
196 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 139 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) |
197 | { | 140 | { |
198 | m_map.replace( contact.uid(), contact ); | 141 | m_map.replace( contact.uid(), contact ); |
199 | m_dirty = true; | 142 | m_dirty = true; |
200 | return true; | 143 | return true; |
201 | } | 144 | } |
202 | 145 | ||
203 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 146 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
204 | { | 147 | { |
205 | return m_map[uid]; | 148 | return m_map[uid]; |
206 | } | 149 | } |
207 | 150 | ||
208 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 151 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
209 | { | 152 | { |
210 | QArray<int> ar( m_map.count() ); | 153 | QArray<int> ar( m_map.count() ); |
211 | QMap<int, OContact>::ConstIterator it; | 154 | QMap<int, OContact>::ConstIterator it; |
212 | int i = 0; | 155 | int i = 0; |
213 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 156 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
214 | ar[i] = it.key(); | 157 | ar[i] = it.key(); |
215 | i++; | 158 | i++; |
216 | } | 159 | } |
217 | return ar; | 160 | return ar; |
218 | } | 161 | } |
219 | 162 | ||
220 | // Not implemented | 163 | // Not implemented |
221 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int, const QDateTime& ) | 164 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int, const QDateTime& ) |
222 | { | 165 | { |
223 | QArray<int> ar(0); | 166 | QArray<int> ar(0); |
224 | return ar; | 167 | return ar; |
225 | } | 168 | } |
226 | 169 | ||
227 | // Not implemented | 170 | // Not implemented |
228 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 171 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
229 | { | 172 | { |
230 | QArray<int> ar(0); | 173 | QArray<int> ar(0); |
231 | return ar; | 174 | return ar; |
232 | } | 175 | } |
233 | 176 | ||
234 | const uint OContactAccessBackend_VCard::querySettings() | 177 | const uint OContactAccessBackend_VCard::querySettings() |
235 | { | 178 | { |
236 | return 0; // No search possible | 179 | return 0; // No search possible |
237 | } | 180 | } |
238 | 181 | ||
239 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 182 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const |
240 | { | 183 | { |
241 | return false; // No search possible, therefore all settings invalid ;) | 184 | return false; // No search possible, therefore all settings invalid ;) |
242 | } | 185 | } |
243 | 186 | ||
244 | bool OContactAccessBackend_VCard::wasChangedExternally() | 187 | bool OContactAccessBackend_VCard::wasChangedExternally() |
245 | { | 188 | { |
246 | return false; // Don't expect concurrent access | 189 | return false; // Don't expect concurrent access |
247 | } | 190 | } |
248 | 191 | ||
249 | // Not implemented | 192 | // Not implemented |
250 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | 193 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) |
251 | { | 194 | { |
252 | QArray<int> ar(0); | 195 | QArray<int> ar(0); |
253 | return ar; | 196 | return ar; |
254 | } | 197 | } |
255 | 198 | ||
256 | // *** Private stuff *** | 199 | // *** Private stuff *** |
257 | 200 | ||
258 | 201 | ||
259 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 202 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) |
260 | { | 203 | { |
261 | OContact c; | 204 | OContact c; |
262 | 205 | ||
263 | VObjectIterator it; | 206 | VObjectIterator it; |
264 | initPropIterator( &it, obj ); | 207 | initPropIterator( &it, obj ); |
265 | while( moreIteration( &it ) ) { | 208 | while( moreIteration( &it ) ) { |
266 | VObject *o = nextVObject( &it ); | 209 | VObject *o = nextVObject( &it ); |
267 | QCString name = vObjectName( o ); | 210 | QCString name = vObjectName( o ); |
268 | QCString value = vObjectStringZValue( o ); | 211 | QCString value = vObjectStringZValue( o ); |
269 | if ( name == VCNameProp ) { | 212 | if ( name == VCNameProp ) { |
270 | VObjectIterator nit; | 213 | VObjectIterator nit; |
271 | initPropIterator( &nit, o ); | 214 | initPropIterator( &nit, o ); |
272 | while( moreIteration( &nit ) ) { | 215 | while( moreIteration( &nit ) ) { |
273 | VObject *o = nextVObject( &nit ); | 216 | VObject *o = nextVObject( &nit ); |
274 | QCString name = vObjectTypeInfo( o ); | 217 | QCString name = vObjectTypeInfo( o ); |
275 | QString value = vObjectStringZValue( o ); | 218 | QString value = vObjectStringZValue( o ); |
276 | if ( name == VCNamePrefixesProp ) | 219 | if ( name == VCNamePrefixesProp ) |
277 | c.setTitle( value ); | 220 | c.setTitle( value ); |
278 | else if ( name == VCNameSuffixesProp ) | 221 | else if ( name == VCNameSuffixesProp ) |
279 | c.setSuffix( value ); | 222 | c.setSuffix( value ); |
280 | else if ( name == VCFamilyNameProp ) | 223 | else if ( name == VCFamilyNameProp ) |
281 | c.setLastName( value ); | 224 | c.setLastName( value ); |
282 | else if ( name == VCGivenNameProp ) | 225 | else if ( name == VCGivenNameProp ) |
283 | c.setFirstName( value ); | 226 | c.setFirstName( value ); |
284 | else if ( name == VCAdditionalNamesProp ) | 227 | else if ( name == VCAdditionalNamesProp ) |
285 | c.setMiddleName( value ); | 228 | c.setMiddleName( value ); |
286 | } | 229 | } |
287 | } | 230 | } |
288 | else if ( name == VCAdrProp ) { | 231 | else if ( name == VCAdrProp ) { |
289 | bool work = TRUE; // default address is work address | 232 | bool work = TRUE; // default address is work address |
290 | QString street; | 233 | QString street; |
@@ -455,192 +398,194 @@ OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
455 | c.setNickname( value ); | 398 | c.setNickname( value ); |
456 | } | 399 | } |
457 | else if ( name == "X-Qtopia-Children" ) { | 400 | else if ( name == "X-Qtopia-Children" ) { |
458 | c.setChildren( value ); | 401 | c.setChildren( value ); |
459 | } | 402 | } |
460 | else if ( name == VCBirthDateProp ) { | 403 | else if ( name == VCBirthDateProp ) { |
461 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 404 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
462 | c.setBirthday( convVCardDateToDate( value ) ); | 405 | c.setBirthday( convVCardDateToDate( value ) ); |
463 | 406 | ||
464 | } | 407 | } |
465 | else if ( name == VCCommentProp ) { | 408 | else if ( name == VCCommentProp ) { |
466 | c.setNotes( value ); | 409 | c.setNotes( value ); |
467 | } | 410 | } |
468 | #if 0 | 411 | #if 0 |
469 | else { | 412 | else { |
470 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 413 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
471 | VObjectIterator nit; | 414 | VObjectIterator nit; |
472 | initPropIterator( &nit, o ); | 415 | initPropIterator( &nit, o ); |
473 | while( moreIteration( &nit ) ) { | 416 | while( moreIteration( &nit ) ) { |
474 | VObject *o = nextVObject( &nit ); | 417 | VObject *o = nextVObject( &nit ); |
475 | QCString name = vObjectName( o ); | 418 | QCString name = vObjectName( o ); |
476 | QString value = vObjectStringZValue( o ); | 419 | QString value = vObjectStringZValue( o ); |
477 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 420 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
478 | } | 421 | } |
479 | } | 422 | } |
480 | #endif | 423 | #endif |
481 | } | 424 | } |
482 | c.setFileAs(); | 425 | c.setFileAs(); |
483 | return c; | 426 | return c; |
484 | } | 427 | } |
485 | 428 | ||
486 | 429 | ||
487 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | 430 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) |
488 | { | 431 | { |
489 | VObject *vcard = newVObject( VCCardProp ); | 432 | VObject *vcard = newVObject( VCCardProp ); |
490 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 433 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
491 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 434 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
492 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | 435 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); |
493 | 436 | ||
494 | // full name | 437 | // full name |
495 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | 438 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); |
496 | 439 | ||
497 | // name properties | 440 | // name properties |
498 | VObject *name = safeAddProp( vcard, VCNameProp ); | 441 | VObject *name = safeAddProp( vcard, VCNameProp ); |
499 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | 442 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); |
500 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); | 443 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); |
501 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); | 444 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); |
502 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); | 445 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); |
503 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); | 446 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); |
504 | 447 | ||
505 | // home properties | 448 | // home properties |
506 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); | 449 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); |
507 | safeAddProp( home_adr, VCHomeProp ); | 450 | safeAddProp( home_adr, VCHomeProp ); |
508 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); | 451 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); |
509 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); | 452 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); |
510 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); | 453 | safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); |
511 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); | 454 | safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); |
512 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); | 455 | safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); |
513 | 456 | ||
514 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); | 457 | VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); |
515 | safeAddProp( home_phone, VCHomeProp ); | 458 | safeAddProp( home_phone, VCHomeProp ); |
516 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); | 459 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); |
517 | safeAddProp( home_phone, VCHomeProp ); | 460 | safeAddProp( home_phone, VCHomeProp ); |
518 | safeAddProp( home_phone, VCCellularProp ); | 461 | safeAddProp( home_phone, VCCellularProp ); |
519 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); | 462 | home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); |
520 | safeAddProp( home_phone, VCHomeProp ); | 463 | safeAddProp( home_phone, VCHomeProp ); |
521 | safeAddProp( home_phone, VCFaxProp ); | 464 | safeAddProp( home_phone, VCFaxProp ); |
522 | 465 | ||
523 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); | 466 | VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); |
524 | safeAddProp( url, VCHomeProp ); | 467 | safeAddProp( url, VCHomeProp ); |
525 | 468 | ||
526 | // work properties | 469 | // work properties |
527 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); | 470 | VObject *work_adr= safeAddProp( vcard, VCAdrProp ); |
528 | safeAddProp( work_adr, VCWorkProp ); | 471 | safeAddProp( work_adr, VCWorkProp ); |
529 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); | 472 | safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); |
530 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); | 473 | safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); |
531 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); | 474 | safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); |
532 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); | 475 | safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); |
533 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); | 476 | safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); |
534 | 477 | ||
535 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); | 478 | VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); |
536 | safeAddProp( work_phone, VCWorkProp ); | 479 | safeAddProp( work_phone, VCWorkProp ); |
537 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); | 480 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); |
538 | safeAddProp( work_phone, VCWorkProp ); | 481 | safeAddProp( work_phone, VCWorkProp ); |
539 | safeAddProp( work_phone, VCCellularProp ); | 482 | safeAddProp( work_phone, VCCellularProp ); |
540 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); | 483 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); |
541 | safeAddProp( work_phone, VCWorkProp ); | 484 | safeAddProp( work_phone, VCWorkProp ); |
542 | safeAddProp( work_phone, VCFaxProp ); | 485 | safeAddProp( work_phone, VCFaxProp ); |
543 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); | 486 | work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); |
544 | safeAddProp( work_phone, VCWorkProp ); | 487 | safeAddProp( work_phone, VCWorkProp ); |
545 | safeAddProp( work_phone, VCPagerProp ); | 488 | safeAddProp( work_phone, VCPagerProp ); |
546 | 489 | ||
547 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); | 490 | url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); |
548 | safeAddProp( url, VCWorkProp ); | 491 | safeAddProp( url, VCWorkProp ); |
549 | 492 | ||
550 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); | 493 | VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); |
551 | safeAddProp( title, VCWorkProp ); | 494 | safeAddProp( title, VCWorkProp ); |
552 | 495 | ||
553 | 496 | ||
554 | QStringList emails = c.emailList(); | 497 | QStringList emails = c.emailList(); |
555 | // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 | 498 | // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 |
556 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 499 | for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
557 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); | 500 | VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); |
558 | safeAddProp( email, VCInternetProp ); | 501 | safeAddProp( email, VCInternetProp ); |
559 | } | 502 | } |
560 | 503 | ||
561 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); | 504 | safeAddPropValue( vcard, VCNoteProp, c.notes() ); |
562 | 505 | ||
563 | // Exporting Birthday regarding RFC 2425 (5.8.4) | 506 | // Exporting Birthday regarding RFC 2425 (5.8.4) |
564 | if ( c.birthday().isValid() ){ | 507 | if ( c.birthday().isValid() ){ |
565 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); | 508 | qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); |
566 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); | 509 | safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); |
567 | } | 510 | } |
568 | 511 | ||
569 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { | 512 | if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { |
570 | VObject *org = safeAddProp( vcard, VCOrgProp ); | 513 | VObject *org = safeAddProp( vcard, VCOrgProp ); |
571 | safeAddPropValue( org, VCOrgNameProp, c.company() ); | 514 | safeAddPropValue( org, VCOrgNameProp, c.company() ); |
572 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); | 515 | safeAddPropValue( org, VCOrgUnitProp, c.department() ); |
573 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); | 516 | safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); |
574 | } | 517 | } |
575 | 518 | ||
576 | // some values we have to export as custom fields | 519 | // some values we have to export as custom fields |
577 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); | 520 | safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); |
578 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); | 521 | safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); |
579 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); | 522 | safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); |
580 | 523 | ||
581 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); | 524 | safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); |
582 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); | 525 | safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); |
583 | if ( c.anniversary().isValid() ){ | 526 | if ( c.anniversary().isValid() ){ |
584 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); | 527 | qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); |
585 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); | 528 | safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); |
586 | } | 529 | } |
587 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); | 530 | safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); |
588 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); | 531 | safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); |
589 | 532 | ||
590 | return vcard; | 533 | return vcard; |
591 | } | 534 | } |
592 | 535 | ||
593 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const | 536 | QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const |
594 | { | 537 | { |
595 | QString str_rfc2425 = QString("%1-%2-%3") | 538 | QString str_rfc2425 = QString("%1-%2-%3") |
596 | .arg( d.year() ) | 539 | .arg( d.year() ) |
597 | .arg( d.month(), 2 ) | 540 | .arg( d.month(), 2 ) |
598 | .arg( d.day(), 2 ); | 541 | .arg( d.day(), 2 ); |
599 | // Now replace spaces with "0"... | 542 | // Now replace spaces with "0"... |
600 | int pos = 0; | 543 | int pos = 0; |
601 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) | 544 | while ( ( pos = str_rfc2425.find (' ') ) > 0 ) |
602 | str_rfc2425.replace( pos, 1, "0" ); | 545 | str_rfc2425.replace( pos, 1, "0" ); |
603 | 546 | ||
604 | return str_rfc2425; | 547 | return str_rfc2425; |
605 | } | 548 | } |
606 | 549 | ||
607 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) | 550 | QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) |
608 | { | 551 | { |
609 | int monthPos = datestr.find('-'); | 552 | int monthPos = datestr.find('-'); |
610 | int dayPos = datestr.find('-', monthPos+1 ); | 553 | int dayPos = datestr.find('-', monthPos+1 ); |
611 | int sep_ignore = 1; | 554 | int sep_ignore = 1; |
612 | if ( monthPos == -1 || dayPos == -1 ) { | 555 | if ( monthPos == -1 || dayPos == -1 ) { |
613 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 556 | qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
614 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) | 557 | // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) |
615 | if ( datestr.length() == 8 ){ | 558 | if ( datestr.length() == 8 ){ |
616 | monthPos = 4; | 559 | monthPos = 4; |
617 | dayPos = 6; | 560 | dayPos = 6; |
618 | sep_ignore = 0; | 561 | sep_ignore = 0; |
619 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); | 562 | qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); |
620 | } else { | 563 | } else { |
621 | return QDate(); | 564 | return QDate(); |
622 | } | 565 | } |
623 | } | 566 | } |
624 | int y = datestr.left( monthPos ).toInt(); | 567 | int y = datestr.left( monthPos ).toInt(); |
625 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); | 568 | int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); |
626 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); | 569 | int d = datestr.mid( dayPos + sep_ignore ).toInt(); |
627 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); | 570 | qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); |
628 | QDate date ( y,m,d ); | 571 | QDate date ( y,m,d ); |
629 | return date; | 572 | return date; |
630 | } | 573 | } |
631 | 574 | ||
632 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 575 | VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
633 | { | 576 | { |
634 | VObject *ret = 0; | 577 | VObject *ret = 0; |
635 | if ( o && !value.isEmpty() ) | 578 | if ( o && !value.isEmpty() ) |
636 | ret = addPropValue( o, prop, value.latin1() ); | 579 | ret = addPropValue( o, prop, value.latin1() ); |
637 | return ret; | 580 | return ret; |
638 | } | 581 | } |
639 | 582 | ||
640 | VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) | 583 | VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) |
641 | { | 584 | { |
642 | VObject *ret = 0; | 585 | VObject *ret = 0; |
643 | if ( o ) | 586 | if ( o ) |
644 | ret = addProp( o, prop ); | 587 | ret = addProp( o, prop ); |
645 | return ret; | 588 | return ret; |
646 | } | 589 | } |
590 | |||
591 | } | ||
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h index 712d769..11be027 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | |||
@@ -1,96 +1,85 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
2 | * VCard Backend for the OPIE-Contact Database. | 30 | * VCard Backend for the OPIE-Contact Database. |
3 | * | ||
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
6 | * | ||
7 | * ===================================================================== | ||
8 | *This program is free software; you can redistribute it and/or | ||
9 | *modify it under the terms of the GNU Library General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2 of the License, or (at your option) any later version. | ||
12 | * ===================================================================== | ||
13 | * ToDo: | ||
14 | * | ||
15 | * ===================================================================== | ||
16 | * Version: $Id$ | ||
17 | * ===================================================================== | ||
18 | * History: | ||
19 | * $Log$ | ||
20 | * Revision 1.6 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
25 | * Revision 1.5 2003/03/21 10:33:09 eilers | ||
26 | * Merged speed optimized xml backend for contacts to main. | ||
27 | * Added QDateTime to querybyexample. For instance, it is now possible to get | ||
28 | * all Birthdays/Anniversaries between two dates. This should be used | ||
29 | * to show all birthdays in the datebook.. | ||
30 | * This change is sourcecode backward compatible but you have to upgrade | ||
31 | * the binaries for today-addressbook. | ||
32 | * | ||
33 | * Revision 1.4 2002/12/07 13:26:22 eilers | ||
34 | * Fixing bug in storing anniversary.. | ||
35 | * | ||
36 | * Revision 1.3 2002/11/13 14:14:51 eilers | ||
37 | * Added sorted for Contacts.. | ||
38 | * | ||
39 | * Revision 1.2 2002/11/10 15:41:53 eilers | ||
40 | * Bugfixes.. | ||
41 | * | ||
42 | * Revision 1.1 2002/11/09 14:34:52 eilers | ||
43 | * Added VCard Backend. | ||
44 | * | ||
45 | */ | 31 | */ |
46 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ | 32 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ |
47 | #define __OCONTACTACCESSBACKEND_VCARD_H_ | 33 | #define __OCONTACTACCESSBACKEND_VCARD_H_ |
48 | 34 | ||
49 | #include <opie/ocontact.h> | 35 | #include <opie2/ocontact.h> |
50 | 36 | ||
51 | #include "ocontactaccessbackend.h" | 37 | #include <opie2/ocontactaccessbackend.h> |
52 | 38 | ||
53 | class VObject; | 39 | class VObject; |
54 | 40 | ||
41 | namespace Opie { | ||
55 | /** | 42 | /** |
56 | * This is the vCard 2.1 implementation of the Contact Storage | 43 | * This is the vCard 2.1 implementation of the Contact Storage |
57 | * @see OContactAccessBackend_XML | 44 | * @see OContactAccessBackend_XML |
58 | * @see OPimAccessBackend | 45 | * @see OPimAccessBackend |
59 | */ | 46 | */ |
60 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 47 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
61 | public: | 48 | public: |
62 | OContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null ); | 49 | OContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null ); |
63 | 50 | ||
64 | bool load (); | 51 | bool load (); |
65 | bool reload(); | 52 | bool reload(); |
66 | bool save(); | 53 | bool save(); |
67 | void clear (); | 54 | void clear (); |
68 | 55 | ||
69 | bool add ( const OContact& newcontact ); | 56 | bool add ( const OContact& newcontact ); |
70 | bool remove ( int uid ); | 57 | bool remove ( int uid ); |
71 | bool replace ( const OContact& contact ); | 58 | bool replace ( const OContact& contact ); |
72 | 59 | ||
73 | OContact find ( int uid ) const; | 60 | OContact find ( int uid ) const; |
74 | QArray<int> allRecords() const; | 61 | QArray<int> allRecords() const; |
75 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 62 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
76 | QArray<int> matchRegexp( const QRegExp &r ) const; | 63 | QArray<int> matchRegexp( const QRegExp &r ) const; |
77 | 64 | ||
78 | const uint querySettings(); | 65 | const uint querySettings(); |
79 | bool hasQuerySettings (uint querySettings) const; | 66 | bool hasQuerySettings (uint querySettings) const; |
80 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 67 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
81 | bool wasChangedExternally(); | 68 | bool wasChangedExternally(); |
82 | 69 | ||
83 | private: | 70 | private: |
84 | OContact parseVObject( VObject* obj ); | 71 | OContact parseVObject( VObject* obj ); |
85 | VObject* createVObject( const OContact& c ); | 72 | VObject* createVObject( const OContact& c ); |
86 | QString convDateToVCardDate( const QDate& c ) const; | 73 | QString convDateToVCardDate( const QDate& c ) const; |
87 | QDate convVCardDateToDate( const QString& datestr ); | 74 | QDate convVCardDateToDate( const QString& datestr ); |
88 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 75 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
89 | VObject *safeAddProp( VObject* o, const char* prop); | 76 | VObject *safeAddProp( VObject* o, const char* prop); |
90 | 77 | ||
91 | bool m_dirty : 1; | 78 | bool m_dirty : 1; |
92 | QString m_file; | 79 | QString m_file; |
93 | QMap<int, OContact> m_map; | 80 | QMap<int, OContact> m_map; |
94 | }; | 81 | }; |
95 | 82 | ||
83 | } | ||
84 | |||
96 | #endif | 85 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index aae7fca..4c3da0c 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -1,318 +1,248 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
2 | * XML Backend for the OPIE-Contact Database. | 30 | * XML Backend for the OPIE-Contact Database. |
3 | * | ||
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * | ||
13 | * ===================================================================== | ||
14 | * Version: $Id$ | ||
15 | * ===================================================================== | ||
16 | * History: | ||
17 | * $Log$ | ||
18 | * Revision 1.9 2003/09/22 14:31:16 eilers | ||
19 | * Added first experimental incarnation of sql-backend for addressbook. | ||
20 | * Some modifications to be able to compile the todo sql-backend. | ||
21 | * A lot of changes fill follow... | ||
22 | * | ||
23 | * Revision 1.8 2003/08/30 15:28:26 eilers | ||
24 | * Removed some unimportant debug output which causes slow down.. | ||
25 | * | ||
26 | * Revision 1.7 2003/08/01 12:30:16 eilers | ||
27 | * Merging changes from BRANCH_1_0 to HEAD | ||
28 | * | ||
29 | * Revision 1.6 2003/07/07 16:19:47 eilers | ||
30 | * Fixing serious bug in hasQuerySettings() | ||
31 | * | ||
32 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
33 | * More API doc | ||
34 | * QString -> const QString& | ||
35 | * QString = 0l -> QString::null | ||
36 | * | ||
37 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | ||
38 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | ||
39 | * | ||
40 | * Revision 1.3 2003/03/21 12:26:28 eilers | ||
41 | * Fixing small bug: If we search a birthday from today to today, it returned | ||
42 | * every contact .. | ||
43 | * | ||
44 | * Revision 1.2 2003/03/21 10:33:09 eilers | ||
45 | * Merged speed optimized xml backend for contacts to main. | ||
46 | * Added QDateTime to querybyexample. For instance, it is now possible to get | ||
47 | * all Birthdays/Anniversaries between two dates. This should be used | ||
48 | * to show all birthdays in the datebook.. | ||
49 | * This change is sourcecode backward compatible but you have to upgrade | ||
50 | * the binaries for today-addressbook. | ||
51 | * | ||
52 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | ||
53 | * Speed optimization. Removed the sequential search loops. | ||
54 | * | ||
55 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | ||
56 | * Writing offsets to debug output.. | ||
57 | * | ||
58 | * Revision 1.1 2003/02/09 15:05:01 eilers | ||
59 | * Nothing happened.. Just some cleanup before I will start.. | ||
60 | * | ||
61 | * Revision 1.12 2003/01/03 16:58:03 eilers | ||
62 | * Reenable debug output | ||
63 | * | ||
64 | * Revision 1.11 2003/01/03 12:31:28 eilers | ||
65 | * Bugfix for calculating data diffs.. | ||
66 | * | ||
67 | * Revision 1.10 2003/01/02 14:27:12 eilers | ||
68 | * Improved query by example: Search by date is possible.. First step | ||
69 | * for a today plugin for birthdays.. | ||
70 | * | ||
71 | * Revision 1.9 2002/12/08 12:48:57 eilers | ||
72 | * Moved journal-enum from ocontact into i the xml-backend.. | ||
73 | * | ||
74 | * Revision 1.8 2002/11/14 17:04:24 eilers | ||
75 | * Sorting will now work if fullname is identical on some entries | ||
76 | * | ||
77 | * Revision 1.7 2002/11/13 15:02:46 eilers | ||
78 | * Small Bug in sorted fixed | ||
79 | * | ||
80 | * Revision 1.6 2002/11/13 14:14:51 eilers | ||
81 | * Added sorted for Contacts.. | ||
82 | * | ||
83 | * Revision 1.5 2002/11/01 15:10:42 eilers | ||
84 | * Added regExp-search in database for all fields in a contact. | ||
85 | * | ||
86 | * Revision 1.4 2002/10/16 10:52:40 eilers | ||
87 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
88 | * | ||
89 | * Revision 1.3 2002/10/14 16:21:54 eilers | ||
90 | * Some minor interface updates | ||
91 | * | ||
92 | * Revision 1.2 2002/10/07 17:34:24 eilers | ||
93 | * added OBackendFactory for advanced backend access | ||
94 | * | ||
95 | * Revision 1.1 2002/09/27 17:11:44 eilers | ||
96 | * Added API for accessing the Contact-Database ! It is compiling, but | ||
97 | * please do not expect that anything is working ! | ||
98 | * I will debug that stuff in the next time .. | ||
99 | * Please read README_COMPILE for compiling ! | ||
100 | * | ||
101 | * | ||
102 | */ | 31 | */ |
103 | 32 | ||
104 | #include "ocontactaccessbackend_xml.h" | 33 | #include <opie2/ocontactaccessbackend_xml.h> |
105 | 34 | ||
106 | #include <qasciidict.h> | 35 | #include <qasciidict.h> |
107 | #include <qdatetime.h> | 36 | #include <qdatetime.h> |
108 | #include <qfile.h> | 37 | #include <qfile.h> |
109 | #include <qfileinfo.h> | 38 | #include <qfileinfo.h> |
110 | #include <qregexp.h> | 39 | #include <qregexp.h> |
111 | #include <qarray.h> | 40 | #include <qarray.h> |
112 | #include <qmap.h> | 41 | #include <qmap.h> |
113 | #include <qdatetime.h> | 42 | #include <qdatetime.h> |
114 | 43 | ||
115 | #include <qpe/global.h> | 44 | #include <qpe/global.h> |
116 | 45 | ||
117 | #include <opie/xmltree.h> | 46 | #include <opie/xmltree.h> |
118 | #include "ocontactaccessbackend.h" | 47 | #include <opie2/ocontactaccessbackend.h> |
119 | #include "ocontactaccess.h" | 48 | #include <opie2/ocontactaccess.h> |
120 | 49 | ||
121 | #include <stdlib.h> | 50 | #include <stdlib.h> |
122 | #include <errno.h> | 51 | #include <errno.h> |
123 | 52 | ||
124 | using namespace Opie; | 53 | using namespace Opie; |
125 | 54 | ||
126 | 55 | ||
56 | namespace Opie { | ||
127 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): | 57 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): |
128 | m_changed( false ) | 58 | m_changed( false ) |
129 | { | 59 | { |
130 | // Just m_contactlist should call delete if an entry | 60 | // Just m_contactlist should call delete if an entry |
131 | // is removed. | 61 | // is removed. |
132 | m_contactList.setAutoDelete( true ); | 62 | m_contactList.setAutoDelete( true ); |
133 | m_uidToContact.setAutoDelete( false ); | 63 | m_uidToContact.setAutoDelete( false ); |
134 | 64 | ||
135 | m_appName = appname; | 65 | m_appName = appname; |
136 | 66 | ||
137 | /* Set journalfile name ... */ | 67 | /* Set journalfile name ... */ |
138 | m_journalName = getenv("HOME"); | 68 | m_journalName = getenv("HOME"); |
139 | m_journalName +="/.abjournal" + appname; | 69 | m_journalName +="/.abjournal" + appname; |
140 | 70 | ||
141 | /* Expecting to access the default filename if nothing else is set */ | 71 | /* Expecting to access the default filename if nothing else is set */ |
142 | if ( filename.isEmpty() ){ | 72 | if ( filename.isEmpty() ){ |
143 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 73 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
144 | } else | 74 | } else |
145 | m_fileName = filename; | 75 | m_fileName = filename; |
146 | 76 | ||
147 | /* Load Database now */ | 77 | /* Load Database now */ |
148 | load (); | 78 | load (); |
149 | } | 79 | } |
150 | 80 | ||
151 | bool OContactAccessBackend_XML::save() | 81 | bool OContactAccessBackend_XML::save() |
152 | { | 82 | { |
153 | 83 | ||
154 | if ( !m_changed ) | 84 | if ( !m_changed ) |
155 | return true; | 85 | return true; |
156 | 86 | ||
157 | QString strNewFile = m_fileName + ".new"; | 87 | QString strNewFile = m_fileName + ".new"; |
158 | QFile f( strNewFile ); | 88 | QFile f( strNewFile ); |
159 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 89 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
160 | return false; | 90 | return false; |
161 | 91 | ||
162 | int total_written; | 92 | int total_written; |
163 | int idx_offset = 0; | 93 | int idx_offset = 0; |
164 | QString out; | 94 | QString out; |
165 | 95 | ||
166 | // Write Header | 96 | // Write Header |
167 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 97 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
168 | " <Groups>\n" | 98 | " <Groups>\n" |
169 | " </Groups>\n" | 99 | " </Groups>\n" |
170 | " <Contacts>\n"; | 100 | " <Contacts>\n"; |
171 | QCString cstr = out.utf8(); | 101 | QCString cstr = out.utf8(); |
172 | f.writeBlock( cstr.data(), cstr.length() ); | 102 | f.writeBlock( cstr.data(), cstr.length() ); |
173 | idx_offset += cstr.length(); | 103 | idx_offset += cstr.length(); |
174 | out = ""; | 104 | out = ""; |
175 | 105 | ||
176 | // Write all contacts | 106 | // Write all contacts |
177 | QListIterator<OContact> it( m_contactList ); | 107 | QListIterator<OContact> it( m_contactList ); |
178 | for ( ; it.current(); ++it ) { | 108 | for ( ; it.current(); ++it ) { |
179 | // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); | 109 | // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); |
180 | out += "<Contact "; | 110 | out += "<Contact "; |
181 | (*it)->save( out ); | 111 | (*it)->save( out ); |
182 | out += "/>\n"; | 112 | out += "/>\n"; |
183 | cstr = out.utf8(); | 113 | cstr = out.utf8(); |
184 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 114 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
185 | idx_offset += cstr.length(); | 115 | idx_offset += cstr.length(); |
186 | if ( total_written != int(cstr.length()) ) { | 116 | if ( total_written != int(cstr.length()) ) { |
187 | f.close(); | 117 | f.close(); |
188 | QFile::remove( strNewFile ); | 118 | QFile::remove( strNewFile ); |
189 | return false; | 119 | return false; |
190 | } | 120 | } |
191 | out = ""; | 121 | out = ""; |
192 | } | 122 | } |
193 | out += " </Contacts>\n</AddressBook>\n"; | 123 | out += " </Contacts>\n</AddressBook>\n"; |
194 | 124 | ||
195 | // Write Footer | 125 | // Write Footer |
196 | cstr = out.utf8(); | 126 | cstr = out.utf8(); |
197 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 127 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
198 | if ( total_written != int( cstr.length() ) ) { | 128 | if ( total_written != int( cstr.length() ) ) { |
199 | f.close(); | 129 | f.close(); |
200 | QFile::remove( strNewFile ); | 130 | QFile::remove( strNewFile ); |
201 | return false; | 131 | return false; |
202 | } | 132 | } |
203 | f.close(); | 133 | f.close(); |
204 | 134 | ||
205 | // move the file over, I'm just going to use the system call | 135 | // move the file over, I'm just going to use the system call |
206 | // because, I don't feel like using QDir. | 136 | // because, I don't feel like using QDir. |
207 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 137 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
208 | qWarning( "problem renaming file %s to %s, errno: %d", | 138 | qWarning( "problem renaming file %s to %s, errno: %d", |
209 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 139 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
210 | // remove the tmp file... | 140 | // remove the tmp file... |
211 | QFile::remove( strNewFile ); | 141 | QFile::remove( strNewFile ); |
212 | } | 142 | } |
213 | 143 | ||
214 | /* The journalfile should be removed now... */ | 144 | /* The journalfile should be removed now... */ |
215 | removeJournal(); | 145 | removeJournal(); |
216 | 146 | ||
217 | m_changed = false; | 147 | m_changed = false; |
218 | return true; | 148 | return true; |
219 | } | 149 | } |
220 | 150 | ||
221 | bool OContactAccessBackend_XML::load () | 151 | bool OContactAccessBackend_XML::load () |
222 | { | 152 | { |
223 | m_contactList.clear(); | 153 | m_contactList.clear(); |
224 | m_uidToContact.clear(); | 154 | m_uidToContact.clear(); |
225 | 155 | ||
226 | /* Load XML-File and journal if it exists */ | 156 | /* Load XML-File and journal if it exists */ |
227 | if ( !load ( m_fileName, false ) ) | 157 | if ( !load ( m_fileName, false ) ) |
228 | return false; | 158 | return false; |
229 | /* The returncode of the journalfile is ignored due to the | 159 | /* The returncode of the journalfile is ignored due to the |
230 | * fact that it does not exist when this class is instantiated ! | 160 | * fact that it does not exist when this class is instantiated ! |
231 | * But there may such a file exist, if the application crashed. | 161 | * But there may such a file exist, if the application crashed. |
232 | * Therefore we try to load it to get the changes before the # | 162 | * Therefore we try to load it to get the changes before the # |
233 | * crash happened... | 163 | * crash happened... |
234 | */ | 164 | */ |
235 | load (m_journalName, true); | 165 | load (m_journalName, true); |
236 | 166 | ||
237 | return true; | 167 | return true; |
238 | } | 168 | } |
239 | 169 | ||
240 | void OContactAccessBackend_XML::clear () | 170 | void OContactAccessBackend_XML::clear () |
241 | { | 171 | { |
242 | m_contactList.clear(); | 172 | m_contactList.clear(); |
243 | m_uidToContact.clear(); | 173 | m_uidToContact.clear(); |
244 | 174 | ||
245 | m_changed = false; | 175 | m_changed = false; |
246 | } | 176 | } |
247 | 177 | ||
248 | bool OContactAccessBackend_XML::wasChangedExternally() | 178 | bool OContactAccessBackend_XML::wasChangedExternally() |
249 | { | 179 | { |
250 | QFileInfo fi( m_fileName ); | 180 | QFileInfo fi( m_fileName ); |
251 | 181 | ||
252 | QDateTime lastmod = fi.lastModified (); | 182 | QDateTime lastmod = fi.lastModified (); |
253 | 183 | ||
254 | return (lastmod != m_readtime); | 184 | return (lastmod != m_readtime); |
255 | } | 185 | } |
256 | 186 | ||
257 | QArray<int> OContactAccessBackend_XML::allRecords() const | 187 | QArray<int> OContactAccessBackend_XML::allRecords() const |
258 | { | 188 | { |
259 | QArray<int> uid_list( m_contactList.count() ); | 189 | QArray<int> uid_list( m_contactList.count() ); |
260 | 190 | ||
261 | uint counter = 0; | 191 | uint counter = 0; |
262 | QListIterator<OContact> it( m_contactList ); | 192 | QListIterator<OContact> it( m_contactList ); |
263 | for( ; it.current(); ++it ){ | 193 | for( ; it.current(); ++it ){ |
264 | uid_list[counter++] = (*it)->uid(); | 194 | uid_list[counter++] = (*it)->uid(); |
265 | } | 195 | } |
266 | 196 | ||
267 | return ( uid_list ); | 197 | return ( uid_list ); |
268 | } | 198 | } |
269 | 199 | ||
270 | OContact OContactAccessBackend_XML::find ( int uid ) const | 200 | OContact OContactAccessBackend_XML::find ( int uid ) const |
271 | { | 201 | { |
272 | OContact foundContact; //Create empty contact | 202 | OContact foundContact; //Create empty contact |
273 | 203 | ||
274 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); | 204 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); |
275 | 205 | ||
276 | if ( found ){ | 206 | if ( found ){ |
277 | foundContact = *found; | 207 | foundContact = *found; |
278 | } | 208 | } |
279 | 209 | ||
280 | return ( foundContact ); | 210 | return ( foundContact ); |
281 | } | 211 | } |
282 | 212 | ||
283 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 213 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
284 | const QDateTime& d ) | 214 | const QDateTime& d ) |
285 | { | 215 | { |
286 | 216 | ||
287 | QArray<int> m_currentQuery( m_contactList.count() ); | 217 | QArray<int> m_currentQuery( m_contactList.count() ); |
288 | QListIterator<OContact> it( m_contactList ); | 218 | QListIterator<OContact> it( m_contactList ); |
289 | uint arraycounter = 0; | 219 | uint arraycounter = 0; |
290 | 220 | ||
291 | for( ; it.current(); ++it ){ | 221 | for( ; it.current(); ++it ){ |
292 | /* Search all fields and compare them with query object. Store them into list | 222 | /* Search all fields and compare them with query object. Store them into list |
293 | * if all fields matches. | 223 | * if all fields matches. |
294 | */ | 224 | */ |
295 | QDate* queryDate = 0l; | 225 | QDate* queryDate = 0l; |
296 | QDate* checkDate = 0l; | 226 | QDate* checkDate = 0l; |
297 | bool allcorrect = true; | 227 | bool allcorrect = true; |
298 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 228 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
299 | // Birthday and anniversary are special nonstring fields and should | 229 | // Birthday and anniversary are special nonstring fields and should |
300 | // be handled specially | 230 | // be handled specially |
301 | switch ( i ){ | 231 | switch ( i ){ |
302 | case Qtopia::Birthday: | 232 | case Qtopia::Birthday: |
303 | queryDate = new QDate( query.birthday() ); | 233 | queryDate = new QDate( query.birthday() ); |
304 | checkDate = new QDate( (*it)->birthday() ); | 234 | checkDate = new QDate( (*it)->birthday() ); |
305 | case Qtopia::Anniversary: | 235 | case Qtopia::Anniversary: |
306 | if ( queryDate == 0l ){ | 236 | if ( queryDate == 0l ){ |
307 | queryDate = new QDate( query.anniversary() ); | 237 | queryDate = new QDate( query.anniversary() ); |
308 | checkDate = new QDate( (*it)->anniversary() ); | 238 | checkDate = new QDate( (*it)->anniversary() ); |
309 | } | 239 | } |
310 | 240 | ||
311 | if ( queryDate->isValid() ){ | 241 | if ( queryDate->isValid() ){ |
312 | if( checkDate->isValid() ){ | 242 | if( checkDate->isValid() ){ |
313 | if ( settings & OContactAccess::DateYear ){ | 243 | if ( settings & OContactAccess::DateYear ){ |
314 | if ( queryDate->year() != checkDate->year() ) | 244 | if ( queryDate->year() != checkDate->year() ) |
315 | allcorrect = false; | 245 | allcorrect = false; |
316 | } | 246 | } |
317 | if ( settings & OContactAccess::DateMonth ){ | 247 | if ( settings & OContactAccess::DateMonth ){ |
318 | if ( queryDate->month() != checkDate->month() ) | 248 | if ( queryDate->month() != checkDate->month() ) |
@@ -629,192 +559,193 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | |||
629 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 559 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
630 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 560 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
631 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 561 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
632 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 562 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
633 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 563 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
634 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 564 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
635 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 565 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
636 | dict.insert( "Company", new int(Qtopia::Company) ); | 566 | dict.insert( "Company", new int(Qtopia::Company) ); |
637 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 567 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
638 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 568 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
639 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 569 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
640 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 570 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
641 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 571 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
642 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 572 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
643 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 573 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
644 | dict.insert( "Department", new int(Qtopia::Department) ); | 574 | dict.insert( "Department", new int(Qtopia::Department) ); |
645 | dict.insert( "Office", new int(Qtopia::Office) ); | 575 | dict.insert( "Office", new int(Qtopia::Office) ); |
646 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 576 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
647 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 577 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
648 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 578 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
649 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 579 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
650 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 580 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
651 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 581 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
652 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 582 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
653 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 583 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
654 | dict.insert( "Children", new int(Qtopia::Children) ); | 584 | dict.insert( "Children", new int(Qtopia::Children) ); |
655 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 585 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
656 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 586 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
657 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 587 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
658 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 588 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
659 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 589 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
660 | dict.insert( "action", new int(JOURNALACTION) ); | 590 | dict.insert( "action", new int(JOURNALACTION) ); |
661 | dict.insert( "actionrow", new int(JOURNALROW) ); | 591 | dict.insert( "actionrow", new int(JOURNALROW) ); |
662 | 592 | ||
663 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 593 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
664 | 594 | ||
665 | XMLElement *root = XMLElement::load( filename ); | 595 | XMLElement *root = XMLElement::load( filename ); |
666 | if(root != 0l ){ // start parsing | 596 | if(root != 0l ){ // start parsing |
667 | /* Parse all XML-Elements and put the data into the | 597 | /* Parse all XML-Elements and put the data into the |
668 | * Contact-Class | 598 | * Contact-Class |
669 | */ | 599 | */ |
670 | XMLElement *element = root->firstChild(); | 600 | XMLElement *element = root->firstChild(); |
671 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 601 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
672 | element = element->firstChild(); | 602 | element = element->firstChild(); |
673 | 603 | ||
674 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 604 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
675 | while( element && !isJournal ){ | 605 | while( element && !isJournal ){ |
676 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 606 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
677 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 607 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
678 | // element->tagName().latin1()); | 608 | // element->tagName().latin1()); |
679 | element = element->nextChild(); | 609 | element = element->nextChild(); |
680 | } else { | 610 | } else { |
681 | element = element->firstChild(); | 611 | element = element->firstChild(); |
682 | break; | 612 | break; |
683 | } | 613 | } |
684 | } | 614 | } |
685 | /* Parse all Contacts and ignore unknown tags */ | 615 | /* Parse all Contacts and ignore unknown tags */ |
686 | while( element ){ | 616 | while( element ){ |
687 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 617 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
688 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 618 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
689 | // element->tagName().latin1()); | 619 | // element->tagName().latin1()); |
690 | element = element->nextChild(); | 620 | element = element->nextChild(); |
691 | continue; | 621 | continue; |
692 | } | 622 | } |
693 | /* Found alement with tagname "contact", now parse and store all | 623 | /* Found alement with tagname "contact", now parse and store all |
694 | * attributes contained | 624 | * attributes contained |
695 | */ | 625 | */ |
696 | //qWarning("OContactDefBack::load element tagName() : %s", | 626 | //qWarning("OContactDefBack::load element tagName() : %s", |
697 | // element->tagName().latin1() ); | 627 | // element->tagName().latin1() ); |
698 | QString dummy; | 628 | QString dummy; |
699 | foundAction = false; | 629 | foundAction = false; |
700 | 630 | ||
701 | XMLElement::AttributeMap aMap = element->attributes(); | 631 | XMLElement::AttributeMap aMap = element->attributes(); |
702 | XMLElement::AttributeMap::Iterator it; | 632 | XMLElement::AttributeMap::Iterator it; |
703 | contactMap.clear(); | 633 | contactMap.clear(); |
704 | customMap.clear(); | 634 | customMap.clear(); |
705 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 635 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
706 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 636 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
707 | 637 | ||
708 | int *find = dict[ it.key() ]; | 638 | int *find = dict[ it.key() ]; |
709 | /* Unknown attributes will be stored as "Custom" elements */ | 639 | /* Unknown attributes will be stored as "Custom" elements */ |
710 | if ( !find ) { | 640 | if ( !find ) { |
711 | // qWarning("Attribute %s not known.", it.key().latin1()); | 641 | // qWarning("Attribute %s not known.", it.key().latin1()); |
712 | //contact.setCustomField(it.key(), it.data()); | 642 | //contact.setCustomField(it.key(), it.data()); |
713 | customMap.insert( it.key(), it.data() ); | 643 | customMap.insert( it.key(), it.data() ); |
714 | continue; | 644 | continue; |
715 | } | 645 | } |
716 | 646 | ||
717 | /* Check if special conversion is needed and add attribute | 647 | /* Check if special conversion is needed and add attribute |
718 | * into Contact class | 648 | * into Contact class |
719 | */ | 649 | */ |
720 | switch( *find ) { | 650 | switch( *find ) { |
721 | /* | 651 | /* |
722 | case Qtopia::AddressUid: | 652 | case Qtopia::AddressUid: |
723 | contact.setUid( it.data().toInt() ); | 653 | contact.setUid( it.data().toInt() ); |
724 | break; | 654 | break; |
725 | case Qtopia::AddressCategory: | 655 | case Qtopia::AddressCategory: |
726 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 656 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
727 | break; | 657 | break; |
728 | */ | 658 | */ |
729 | case JOURNALACTION: | 659 | case JOURNALACTION: |
730 | action = journal_action(it.data().toInt()); | 660 | action = journal_action(it.data().toInt()); |
731 | foundAction = true; | 661 | foundAction = true; |
732 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 662 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
733 | break; | 663 | break; |
734 | case JOURNALROW: | 664 | case JOURNALROW: |
735 | journalKey = it.data().toInt(); | 665 | journalKey = it.data().toInt(); |
736 | break; | 666 | break; |
737 | default: // no conversion needed add them to the map | 667 | default: // no conversion needed add them to the map |
738 | contactMap.insert( *find, it.data() ); | 668 | contactMap.insert( *find, it.data() ); |
739 | break; | 669 | break; |
740 | } | 670 | } |
741 | } | 671 | } |
742 | /* now generate the Contact contact */ | 672 | /* now generate the Contact contact */ |
743 | OContact contact( contactMap ); | 673 | OContact contact( contactMap ); |
744 | 674 | ||
745 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 675 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
746 | contact.setCustomField( customIt.key(), customIt.data() ); | 676 | contact.setCustomField( customIt.key(), customIt.data() ); |
747 | } | 677 | } |
748 | 678 | ||
749 | if (foundAction){ | 679 | if (foundAction){ |
750 | foundAction = false; | 680 | foundAction = false; |
751 | switch ( action ) { | 681 | switch ( action ) { |
752 | case ACTION_ADD: | 682 | case ACTION_ADD: |
753 | addContact_p (contact); | 683 | addContact_p (contact); |
754 | break; | 684 | break; |
755 | case ACTION_REMOVE: | 685 | case ACTION_REMOVE: |
756 | if ( !remove (contact.uid()) ) | 686 | if ( !remove (contact.uid()) ) |
757 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 687 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
758 | contact.uid() ); | 688 | contact.uid() ); |
759 | break; | 689 | break; |
760 | case ACTION_REPLACE: | 690 | case ACTION_REPLACE: |
761 | if ( !replace ( contact ) ) | 691 | if ( !replace ( contact ) ) |
762 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 692 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
763 | contact.uid() ); | 693 | contact.uid() ); |
764 | break; | 694 | break; |
765 | default: | 695 | default: |
766 | qWarning ("Unknown action: ignored !"); | 696 | qWarning ("Unknown action: ignored !"); |
767 | break; | 697 | break; |
768 | } | 698 | } |
769 | }else{ | 699 | }else{ |
770 | /* Add contact to list */ | 700 | /* Add contact to list */ |
771 | addContact_p (contact); | 701 | addContact_p (contact); |
772 | } | 702 | } |
773 | 703 | ||
774 | /* Move to next element */ | 704 | /* Move to next element */ |
775 | element = element->nextChild(); | 705 | element = element->nextChild(); |
776 | } | 706 | } |
777 | }else { | 707 | }else { |
778 | qWarning("ODefBack::could not load"); | 708 | qWarning("ODefBack::could not load"); |
779 | } | 709 | } |
780 | delete root; | 710 | delete root; |
781 | qWarning("returning from loading" ); | 711 | qWarning("returning from loading" ); |
782 | return true; | 712 | return true; |
783 | } | 713 | } |
784 | 714 | ||
785 | 715 | ||
786 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 716 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
787 | journal_action action ) | 717 | journal_action action ) |
788 | { | 718 | { |
789 | QFile f( m_journalName ); | 719 | QFile f( m_journalName ); |
790 | bool created = !f.exists(); | 720 | bool created = !f.exists(); |
791 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 721 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
792 | return; | 722 | return; |
793 | 723 | ||
794 | QString buf; | 724 | QString buf; |
795 | QCString str; | 725 | QCString str; |
796 | 726 | ||
797 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 727 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
798 | // get a XML-File which is readable by our parser. | 728 | // get a XML-File which is readable by our parser. |
799 | // This is just a cheat, but better than rewrite the parser. | 729 | // This is just a cheat, but better than rewrite the parser. |
800 | if ( created ){ | 730 | if ( created ){ |
801 | buf = "<Contacts>"; | 731 | buf = "<Contacts>"; |
802 | QCString cstr = buf.utf8(); | 732 | QCString cstr = buf.utf8(); |
803 | f.writeBlock( cstr.data(), cstr.length() ); | 733 | f.writeBlock( cstr.data(), cstr.length() ); |
804 | } | 734 | } |
805 | 735 | ||
806 | buf = "<Contact "; | 736 | buf = "<Contact "; |
807 | cnt.save( buf ); | 737 | cnt.save( buf ); |
808 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 738 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
809 | buf += "/>\n"; | 739 | buf += "/>\n"; |
810 | QCString cstr = buf.utf8(); | 740 | QCString cstr = buf.utf8(); |
811 | f.writeBlock( cstr.data(), cstr.length() ); | 741 | f.writeBlock( cstr.data(), cstr.length() ); |
812 | } | 742 | } |
813 | 743 | ||
814 | void OContactAccessBackend_XML::removeJournal() | 744 | void OContactAccessBackend_XML::removeJournal() |
815 | { | 745 | { |
816 | QFile f ( m_journalName ); | 746 | QFile f ( m_journalName ); |
817 | if ( f.exists() ) | 747 | if ( f.exists() ) |
818 | f.remove(); | 748 | f.remove(); |
819 | } | 749 | } |
820 | 750 | ||
751 | } | ||
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index a0cae4d..f439c4c 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h | |||
@@ -1,160 +1,108 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
2 | * XML Backend for the OPIE-Contact Database. | 30 | * XML Backend for the OPIE-Contact Database. |
3 | * | ||
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | ||
13 | * File Locking to protect against concurrent access | ||
14 | * | ||
15 | * | ||
16 | * ===================================================================== | ||
17 | * Version: $Id$ | ||
18 | * ===================================================================== | ||
19 | * History: | ||
20 | * $Log$ | ||
21 | * Revision 1.15 2003/09/22 14:31:16 eilers | ||
22 | * Added first experimental incarnation of sql-backend for addressbook. | ||
23 | * Some modifications to be able to compile the todo sql-backend. | ||
24 | * A lot of changes fill follow... | ||
25 | * | ||
26 | * Revision 1.14 2003/04/13 18:07:10 zecke | ||
27 | * More API doc | ||
28 | * QString -> const QString& | ||
29 | * QString = 0l -> QString::null | ||
30 | * | ||
31 | * Revision 1.13 2003/03/21 10:33:09 eilers | ||
32 | * Merged speed optimized xml backend for contacts to main. | ||
33 | * Added QDateTime to querybyexample. For instance, it is now possible to get | ||
34 | * all Birthdays/Anniversaries between two dates. This should be used | ||
35 | * to show all birthdays in the datebook.. | ||
36 | * This change is sourcecode backward compatible but you have to upgrade | ||
37 | * the binaries for today-addressbook. | ||
38 | * | ||
39 | * Revision 1.12.2.2 2003/02/11 12:17:28 eilers | ||
40 | * Speed optimization. Removed the sequential search loops. | ||
41 | * | ||
42 | * Revision 1.12.2.1 2003/02/09 15:05:01 eilers | ||
43 | * Nothing happened.. Just some cleanup before I will start.. | ||
44 | * | ||
45 | * Revision 1.12 2003/01/03 16:58:03 eilers | ||
46 | * Reenable debug output | ||
47 | * | ||
48 | * Revision 1.11 2003/01/03 12:31:28 eilers | ||
49 | * Bugfix for calculating data diffs.. | ||
50 | * | ||
51 | * Revision 1.10 2003/01/02 14:27:12 eilers | ||
52 | * Improved query by example: Search by date is possible.. First step | ||
53 | * for a today plugin for birthdays.. | ||
54 | * | ||
55 | * Revision 1.9 2002/12/08 12:48:57 eilers | ||
56 | * Moved journal-enum from ocontact into i the xml-backend.. | ||
57 | * | ||
58 | * Revision 1.8 2002/11/14 17:04:24 eilers | ||
59 | * Sorting will now work if fullname is identical on some entries | ||
60 | * | ||
61 | * Revision 1.7 2002/11/13 15:02:46 eilers | ||
62 | * Small Bug in sorted fixed | ||
63 | * | ||
64 | * Revision 1.6 2002/11/13 14:14:51 eilers | ||
65 | * Added sorted for Contacts.. | ||
66 | * | ||
67 | * Revision 1.5 2002/11/01 15:10:42 eilers | ||
68 | * Added regExp-search in database for all fields in a contact. | ||
69 | * | ||
70 | * Revision 1.4 2002/10/16 10:52:40 eilers | ||
71 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
72 | * | ||
73 | * Revision 1.3 2002/10/14 16:21:54 eilers | ||
74 | * Some minor interface updates | ||
75 | * | ||
76 | * Revision 1.2 2002/10/07 17:34:24 eilers | ||
77 | * added OBackendFactory for advanced backend access | ||
78 | * | ||
79 | * Revision 1.1 2002/09/27 17:11:44 eilers | ||
80 | * Added API for accessing the Contact-Database ! It is compiling, but | ||
81 | * please do not expect that anything is working ! | ||
82 | * I will debug that stuff in the next time .. | ||
83 | * Please read README_COMPILE for compiling ! | ||
84 | * | ||
85 | * | ||
86 | */ | 31 | */ |
87 | 32 | ||
88 | #ifndef _OContactAccessBackend_XML_ | 33 | #ifndef _OContactAccessBackend_XML_ |
89 | #define _OContactAccessBackend_XML_ | 34 | #define _OContactAccessBackend_XML_ |
90 | 35 | ||
91 | #include "ocontactaccessbackend.h" | 36 | #include <opie2/ocontactaccessbackend.h> |
92 | #include "ocontactaccess.h" | 37 | #include <opie2/ocontactaccess.h> |
93 | 38 | ||
94 | #include <qlist.h> | 39 | #include <qlist.h> |
95 | #include <qdict.h> | 40 | #include <qdict.h> |
96 | 41 | ||
42 | namespace Opie { | ||
97 | /* the default xml implementation */ | 43 | /* the default xml implementation */ |
98 | /** | 44 | /** |
99 | * This class is the XML implementation of a Contact backend | 45 | * This class is the XML implementation of a Contact backend |
100 | * it does implement everything available for OContact. | 46 | * it does implement everything available for OContact. |
101 | * @see OPimAccessBackend for more information of available methods | 47 | * @see OPimAccessBackend for more information of available methods |
102 | */ | 48 | */ |
103 | class OContactAccessBackend_XML : public OContactAccessBackend { | 49 | class OContactAccessBackend_XML : public OContactAccessBackend { |
104 | public: | 50 | public: |
105 | OContactAccessBackend_XML ( const QString& appname, const QString& filename = QString::null ); | 51 | OContactAccessBackend_XML ( const QString& appname, const QString& filename = QString::null ); |
106 | 52 | ||
107 | bool save(); | 53 | bool save(); |
108 | 54 | ||
109 | bool load (); | 55 | bool load (); |
110 | 56 | ||
111 | void clear (); | 57 | void clear (); |
112 | 58 | ||
113 | bool wasChangedExternally(); | 59 | bool wasChangedExternally(); |
114 | 60 | ||
115 | QArray<int> allRecords() const; | 61 | QArray<int> allRecords() const; |
116 | 62 | ||
117 | OContact find ( int uid ) const; | 63 | OContact find ( int uid ) const; |
118 | 64 | ||
119 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 65 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
120 | 66 | ||
121 | QArray<int> matchRegexp( const QRegExp &r ) const; | 67 | QArray<int> matchRegexp( const QRegExp &r ) const; |
122 | 68 | ||
123 | const uint querySettings(); | 69 | const uint querySettings(); |
124 | 70 | ||
125 | bool hasQuerySettings (uint querySettings) const; | 71 | bool hasQuerySettings (uint querySettings) const; |
126 | 72 | ||
127 | // Currently only asc implemented.. | 73 | // Currently only asc implemented.. |
128 | QArray<int> sorted( bool asc, int , int , int ); | 74 | QArray<int> sorted( bool asc, int , int , int ); |
129 | bool add ( const OContact &newcontact ); | 75 | bool add ( const OContact &newcontact ); |
130 | 76 | ||
131 | bool replace ( const OContact &contact ); | 77 | bool replace ( const OContact &contact ); |
132 | 78 | ||
133 | bool remove ( int uid ); | 79 | bool remove ( int uid ); |
134 | bool reload(); | 80 | bool reload(); |
135 | 81 | ||
136 | private: | 82 | private: |
137 | 83 | ||
138 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 84 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
139 | 85 | ||
140 | void addContact_p( const OContact &newcontact ); | 86 | void addContact_p( const OContact &newcontact ); |
141 | 87 | ||
142 | /* This function loads the xml-database and the journalfile */ | 88 | /* This function loads the xml-database and the journalfile */ |
143 | bool load( const QString filename, bool isJournal ); | 89 | bool load( const QString filename, bool isJournal ); |
144 | 90 | ||
145 | 91 | ||
146 | void updateJournal( const OContact& cnt, journal_action action ); | 92 | void updateJournal( const OContact& cnt, journal_action action ); |
147 | void removeJournal(); | 93 | void removeJournal(); |
148 | 94 | ||
149 | protected: | 95 | protected: |
150 | bool m_changed; | 96 | bool m_changed; |
151 | QString m_journalName; | 97 | QString m_journalName; |
152 | QString m_fileName; | 98 | QString m_fileName; |
153 | QString m_appName; | 99 | QString m_appName; |
154 | QList<OContact> m_contactList; | 100 | QList<OContact> m_contactList; |
155 | QDateTime m_readtime; | 101 | QDateTime m_readtime; |
156 | 102 | ||
157 | QDict<OContact> m_uidToContact; | 103 | QDict<OContact> m_uidToContact; |
158 | }; | 104 | }; |
159 | 105 | ||
106 | } | ||
107 | |||
160 | #endif | 108 | #endif |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp index f0c5d65..9bf4bf0 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp | |||
@@ -1,182 +1,216 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qtl.h> | 29 | #include <qtl.h> |
2 | 30 | ||
3 | #include "orecur.h" | 31 | #include <opie2/orecur.h> |
4 | 32 | ||
5 | #include "odatebookaccessbackend.h" | 33 | #include <opie2/odatebookaccessbackend.h> |
34 | |||
35 | using namespace Opie; | ||
6 | 36 | ||
7 | namespace { | 37 | namespace { |
8 | /* a small helper to get all NonRepeating events for a range of time */ | 38 | /* a small helper to get all NonRepeating events for a range of time */ |
9 | void events( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& events, | 39 | void events( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& events, |
10 | const QDate& from, const QDate& to ) { | 40 | const QDate& from, const QDate& to ) { |
11 | QDateTime dtStart, dtEnd; | 41 | QDateTime dtStart, dtEnd; |
12 | 42 | ||
13 | for ( OEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { | 43 | for ( OEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { |
14 | dtStart = (*it).startDateTime(); | 44 | dtStart = (*it).startDateTime(); |
15 | dtEnd = (*it).endDateTime(); | 45 | dtEnd = (*it).endDateTime(); |
16 | 46 | ||
17 | /* | 47 | /* |
18 | * If in range | 48 | * If in range |
19 | */ | 49 | */ |
20 | if (dtStart.date() >= from && dtEnd.date() <= to ) { | 50 | if (dtStart.date() >= from && dtEnd.date() <= to ) { |
21 | OEffectiveEvent eff; | 51 | OEffectiveEvent eff; |
22 | eff.setEvent( (*it) ); | 52 | eff.setEvent( (*it) ); |
23 | eff.setDate( dtStart.date() ); | 53 | eff.setDate( dtStart.date() ); |
24 | eff.setStartTime( dtStart.time() ); | 54 | eff.setStartTime( dtStart.time() ); |
25 | 55 | ||
26 | /* if not on the same day */ | 56 | /* if not on the same day */ |
27 | if ( dtStart.date() != dtEnd.date() ) | 57 | if ( dtStart.date() != dtEnd.date() ) |
28 | eff.setEndTime( QTime(23, 59, 0 ) ); | 58 | eff.setEndTime( QTime(23, 59, 0 ) ); |
29 | else | 59 | else |
30 | eff.setEndTime( dtEnd.time() ); | 60 | eff.setEndTime( dtEnd.time() ); |
31 | 61 | ||
32 | tmpList.append( eff ); | 62 | tmpList.append( eff ); |
33 | } | 63 | } |
34 | 64 | ||
35 | /* we must also check for end date information... */ | 65 | /* we must also check for end date information... */ |
36 | if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) { | 66 | if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) { |
37 | QDateTime dt = dtStart.addDays( 1 ); | 67 | QDateTime dt = dtStart.addDays( 1 ); |
38 | dt.setTime( QTime(0, 0, 0 ) ); | 68 | dt.setTime( QTime(0, 0, 0 ) ); |
39 | QDateTime dtStop; | 69 | QDateTime dtStop; |
40 | if ( dtEnd > to ) | 70 | if ( dtEnd > to ) |
41 | dtStop = to; | 71 | dtStop = to; |
42 | else | 72 | else |
43 | dtStop = dtEnd; | 73 | dtStop = dtEnd; |
44 | 74 | ||
45 | while ( dt <= dtStop ) { | 75 | while ( dt <= dtStop ) { |
46 | OEffectiveEvent eff; | 76 | OEffectiveEvent eff; |
47 | eff.setEvent( (*it) ); | 77 | eff.setEvent( (*it) ); |
48 | eff.setDate( dt.date() ); | 78 | eff.setDate( dt.date() ); |
49 | 79 | ||
50 | if ( dt >= from ) { | 80 | if ( dt >= from ) { |
51 | eff.setStartTime( QTime(0, 0, 0 ) ); | 81 | eff.setStartTime( QTime(0, 0, 0 ) ); |
52 | if ( dt.date() == dtEnd.date() ) | 82 | if ( dt.date() == dtEnd.date() ) |
53 | eff.setEndTime( dtEnd.time() ); | 83 | eff.setEndTime( dtEnd.time() ); |
54 | else | 84 | else |
55 | eff.setEndTime( QTime(23, 59, 0 ) ); | 85 | eff.setEndTime( QTime(23, 59, 0 ) ); |
56 | tmpList.append( eff ); | 86 | tmpList.append( eff ); |
57 | } | 87 | } |
58 | dt = dt.addDays( 1 ); | 88 | dt = dt.addDays( 1 ); |
59 | } | 89 | } |
60 | } | 90 | } |
61 | } | 91 | } |
62 | } | 92 | } |
63 | 93 | ||
64 | void repeat( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& list, | 94 | void repeat( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& list, |
65 | const QDate& from, const QDate& to ) { | 95 | const QDate& from, const QDate& to ) { |
66 | QDate repeat; | 96 | QDate repeat; |
67 | for ( OEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { | 97 | for ( OEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { |
68 | int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); | 98 | int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); |
69 | QDate itDate = from.addDays(-dur ); | 99 | QDate itDate = from.addDays(-dur ); |
70 | ORecur rec = (*it).recurrence(); | 100 | ORecur rec = (*it).recurrence(); |
71 | if ( !rec.hasEndDate() || rec.endDate() > to ) { | 101 | if ( !rec.hasEndDate() || rec.endDate() > to ) { |
72 | rec.setEndDate( to ); | 102 | rec.setEndDate( to ); |
73 | rec.setHasEndDate( true ); | 103 | rec.setHasEndDate( true ); |
74 | } | 104 | } |
75 | while (rec.nextOcurrence(itDate, repeat ) ) { | 105 | while (rec.nextOcurrence(itDate, repeat ) ) { |
76 | if (repeat > to ) break; | 106 | if (repeat > to ) break; |
77 | OEffectiveEvent eff; | 107 | OEffectiveEvent eff; |
78 | eff.setDate( repeat ); | 108 | eff.setDate( repeat ); |
79 | if ( (*it).isAllDay() ) { | 109 | if ( (*it).isAllDay() ) { |
80 | eff.setStartTime( QTime(0, 0, 0 ) ); | 110 | eff.setStartTime( QTime(0, 0, 0 ) ); |
81 | eff.setEndTime( QTime(23, 59, 59 ) ); | 111 | eff.setEndTime( QTime(23, 59, 59 ) ); |
82 | }else { | 112 | }else { |
83 | /* we only occur by days, not hours/minutes/seconds. Hence | 113 | /* we only occur by days, not hours/minutes/seconds. Hence |
84 | * the actual end and start times will be the same for | 114 | * the actual end and start times will be the same for |
85 | * every repeated event. For multi day events this is | 115 | * every repeated event. For multi day events this is |
86 | * fixed up later if on wronge day span | 116 | * fixed up later if on wronge day span |
87 | */ | 117 | */ |
88 | eff.setStartTime( (*it).startDateTime().time() ); | 118 | eff.setStartTime( (*it).startDateTime().time() ); |
89 | eff.setEndTime( (*it).endDateTime().time() ); | 119 | eff.setEndTime( (*it).endDateTime().time() ); |
90 | } | 120 | } |
91 | if ( dur != 0 ) { | 121 | if ( dur != 0 ) { |
92 | // multi-day repeating events | 122 | // multi-day repeating events |
93 | QDate sub_it = QMAX( repeat, from ); | 123 | QDate sub_it = QMAX( repeat, from ); |
94 | QDate startDate = repeat; | 124 | QDate startDate = repeat; |
95 | QDate endDate = startDate.addDays( dur ); | 125 | QDate endDate = startDate.addDays( dur ); |
96 | 126 | ||
97 | while ( sub_it <= endDate && sub_it <= to ) { | 127 | while ( sub_it <= endDate && sub_it <= to ) { |
98 | OEffectiveEvent tmpEff = eff; | 128 | OEffectiveEvent tmpEff = eff; |
99 | tmpEff.setEvent( (*it) ); | 129 | tmpEff.setEvent( (*it) ); |
100 | if ( sub_it != startDate ) | 130 | if ( sub_it != startDate ) |
101 | tmpEff.setStartTime( QTime(0, 0, 0 ) ); | 131 | tmpEff.setStartTime( QTime(0, 0, 0 ) ); |
102 | if ( sub_it != endDate ) | 132 | if ( sub_it != endDate ) |
103 | tmpEff.setEndTime( QTime( 23, 59, 59 ) ); | 133 | tmpEff.setEndTime( QTime( 23, 59, 59 ) ); |
104 | 134 | ||
105 | tmpEff.setDate( sub_it ); | 135 | tmpEff.setDate( sub_it ); |
106 | tmpEff.setEffectiveDates( startDate, endDate ); | 136 | tmpEff.setEffectiveDates( startDate, endDate ); |
107 | tmpList.append( tmpEff ); | 137 | tmpList.append( tmpEff ); |
108 | 138 | ||
109 | sub_it = sub_it.addDays( 1 ); | 139 | sub_it = sub_it.addDays( 1 ); |
110 | } | 140 | } |
111 | itDate = endDate; | 141 | itDate = endDate; |
112 | }else { | 142 | }else { |
113 | eff.setEvent( (*it) ); | 143 | eff.setEvent( (*it) ); |
114 | tmpList.append( eff ); | 144 | tmpList.append( eff ); |
115 | itDate = repeat.addDays( 1 ); | 145 | itDate = repeat.addDays( 1 ); |
116 | } | 146 | } |
117 | } | 147 | } |
118 | } | 148 | } |
119 | } | 149 | } |
120 | } | 150 | } |
121 | 151 | ||
152 | namespace Opie { | ||
153 | |||
122 | ODateBookAccessBackend::ODateBookAccessBackend() | 154 | ODateBookAccessBackend::ODateBookAccessBackend() |
123 | : OPimAccessBackend<OEvent>() | 155 | : OPimAccessBackend<OEvent>() |
124 | { | 156 | { |
125 | 157 | ||
126 | } | 158 | } |
127 | ODateBookAccessBackend::~ODateBookAccessBackend() { | 159 | ODateBookAccessBackend::~ODateBookAccessBackend() { |
128 | 160 | ||
129 | } | 161 | } |
130 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from, | 162 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from, |
131 | const QDate& to ) { | 163 | const QDate& to ) { |
132 | OEffectiveEvent::ValueList tmpList; | 164 | OEffectiveEvent::ValueList tmpList; |
133 | OEvent::ValueList list = directNonRepeats(); | 165 | OEvent::ValueList list = directNonRepeats(); |
134 | 166 | ||
135 | events( tmpList, list, from, to ); | 167 | events( tmpList, list, from, to ); |
136 | repeat( tmpList, directRawRepeats(),from,to ); | 168 | repeat( tmpList, directRawRepeats(),from,to ); |
137 | 169 | ||
138 | list = directRawRepeats(); // Useless, isn't it ? (eilers) | 170 | list = directRawRepeats(); // Useless, isn't it ? (eilers) |
139 | 171 | ||
140 | qHeapSort( tmpList ); | 172 | qHeapSort( tmpList ); |
141 | return tmpList; | 173 | return tmpList; |
142 | } | 174 | } |
143 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) { | 175 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) { |
144 | OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() ); | 176 | OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() ); |
145 | OEffectiveEvent::ValueList::Iterator it; | 177 | OEffectiveEvent::ValueList::Iterator it; |
146 | 178 | ||
147 | OEffectiveEvent::ValueList tmpList; | 179 | OEffectiveEvent::ValueList tmpList; |
148 | QDateTime dtTmp; | 180 | QDateTime dtTmp; |
149 | for ( it = day.begin(); it != day.end(); ++it ) { | 181 | for ( it = day.begin(); it != day.end(); ++it ) { |
150 | dtTmp = QDateTime( (*it).date(), (*it).startTime() ); | 182 | dtTmp = QDateTime( (*it).date(), (*it).startTime() ); |
151 | if ( QABS(dt.secsTo(dtTmp) ) < 60 ) | 183 | if ( QABS(dt.secsTo(dtTmp) ) < 60 ) |
152 | tmpList.append( (*it) ); | 184 | tmpList.append( (*it) ); |
153 | } | 185 | } |
154 | 186 | ||
155 | return tmpList; | 187 | return tmpList; |
156 | } | 188 | } |
157 | 189 | ||
158 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, | 190 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, |
159 | const QDate& to ) { | 191 | const QDate& to ) { |
160 | OEffectiveEvent::ValueList tmpList; | 192 | OEffectiveEvent::ValueList tmpList; |
161 | OEvent::ValueList list = directNonRepeats(); | 193 | OEvent::ValueList list = directNonRepeats(); |
162 | 194 | ||
163 | events( tmpList, list, from, to ); | 195 | events( tmpList, list, from, to ); |
164 | 196 | ||
165 | qHeapSort( tmpList ); | 197 | qHeapSort( tmpList ); |
166 | return tmpList; | 198 | return tmpList; |
167 | } | 199 | } |
168 | 200 | ||
169 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { | 201 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { |
170 | OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); | 202 | OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); |
171 | OEffectiveEvent::ValueList::Iterator it; | 203 | OEffectiveEvent::ValueList::Iterator it; |
172 | 204 | ||
173 | OEffectiveEvent::ValueList tmpList; | 205 | OEffectiveEvent::ValueList tmpList; |
174 | QDateTime dtTmp; | 206 | QDateTime dtTmp; |
175 | for ( it = day.begin(); it != day.end(); ++it ) { | 207 | for ( it = day.begin(); it != day.end(); ++it ) { |
176 | dtTmp = QDateTime( (*it).date(), (*it).startTime() ); | 208 | dtTmp = QDateTime( (*it).date(), (*it).startTime() ); |
177 | if ( QABS(dt.secsTo(dtTmp) ) < 60 ) | 209 | if ( QABS(dt.secsTo(dtTmp) ) < 60 ) |
178 | tmpList.append( (*it) ); | 210 | tmpList.append( (*it) ); |
179 | } | 211 | } |
180 | 212 | ||
181 | return tmpList; | 213 | return tmpList; |
182 | } | 214 | } |
215 | |||
216 | } | ||
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h index 3472ab3..6853670 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend.h | |||
@@ -1,90 +1,121 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H | 29 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H | 30 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H |
3 | 31 | ||
4 | #include <qarray.h> | 32 | #include <qarray.h> |
5 | 33 | ||
6 | #include "opimaccessbackend.h" | 34 | #include <opie2/opimaccessbackend.h> |
7 | #include "oevent.h" | 35 | #include <opie2/oevent.h> |
8 | 36 | ||
37 | namespace Opie { | ||
9 | /** | 38 | /** |
10 | * This class is the interface to the storage of Events. | 39 | * This class is the interface to the storage of Events. |
11 | * @see OPimAccessBackend | 40 | * @see OPimAccessBackend |
12 | * | 41 | * |
13 | */ | 42 | */ |
14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { | 43 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { |
15 | public: | 44 | public: |
16 | typedef int UID; | 45 | typedef int UID; |
17 | 46 | ||
18 | /** | 47 | /** |
19 | * c'tor without parameter | 48 | * c'tor without parameter |
20 | */ | 49 | */ |
21 | ODateBookAccessBackend(); | 50 | ODateBookAccessBackend(); |
22 | ~ODateBookAccessBackend(); | 51 | ~ODateBookAccessBackend(); |
23 | 52 | ||
24 | /** | 53 | /** |
25 | * This method should return a list of UIDs containing | 54 | * This method should return a list of UIDs containing |
26 | * all events. No filter should be applied | 55 | * all events. No filter should be applied |
27 | * @return list of events | 56 | * @return list of events |
28 | */ | 57 | */ |
29 | virtual QArray<UID> rawEvents()const = 0; | 58 | virtual QArray<UID> rawEvents()const = 0; |
30 | 59 | ||
31 | /** | 60 | /** |
32 | * This method should return a list of UIDs containing | 61 | * This method should return a list of UIDs containing |
33 | * all repeating events. No filter should be applied | 62 | * all repeating events. No filter should be applied |
34 | * @return list of repeating events | 63 | * @return list of repeating events |
35 | */ | 64 | */ |
36 | virtual QArray<UID> rawRepeats()const = 0; | 65 | virtual QArray<UID> rawRepeats()const = 0; |
37 | 66 | ||
38 | /** | 67 | /** |
39 | * This mthod should return a list of UIDs containing all non | 68 | * This mthod should return a list of UIDs containing all non |
40 | * repeating events. No filter should be applied | 69 | * repeating events. No filter should be applied |
41 | * @return list of nonrepeating events | 70 | * @return list of nonrepeating events |
42 | */ | 71 | */ |
43 | virtual QArray<UID> nonRepeats() const = 0; | 72 | virtual QArray<UID> nonRepeats() const = 0; |
44 | 73 | ||
45 | /** | 74 | /** |
46 | * If you do not want to implement the effectiveEvents methods below | 75 | * If you do not want to implement the effectiveEvents methods below |
47 | * you need to supply it with directNonRepeats. | 76 | * you need to supply it with directNonRepeats. |
48 | * This method can return empty lists if effectiveEvents is implememted | 77 | * This method can return empty lists if effectiveEvents is implememted |
49 | */ | 78 | */ |
50 | virtual OEvent::ValueList directNonRepeats() = 0; | 79 | virtual OEvent::ValueList directNonRepeats() = 0; |
51 | 80 | ||
52 | /** | 81 | /** |
53 | * Same as above but return raw repeats! | 82 | * Same as above but return raw repeats! |
54 | */ | 83 | */ |
55 | virtual OEvent::ValueList directRawRepeats() = 0; | 84 | virtual OEvent::ValueList directRawRepeats() = 0; |
56 | 85 | ||
57 | /* is implemented by default but you can reimplement it*/ | 86 | /* is implemented by default but you can reimplement it*/ |
58 | /** | 87 | /** |
59 | * Effective Events are special event occuring during a time frame. This method does calcualte | 88 | * Effective Events are special event occuring during a time frame. This method does calcualte |
60 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method | 89 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method |
61 | * yourself | 90 | * yourself |
62 | */ | 91 | */ |
63 | virtual OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); | 92 | virtual OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); |
64 | 93 | ||
65 | /** | 94 | /** |
66 | * this is an overloaded member function | 95 | * this is an overloaded member function |
67 | * @see effectiveEvents( const QDate& from, const QDate& to ) | 96 | * @see effectiveEvents( const QDate& from, const QDate& to ) |
68 | */ | 97 | */ |
69 | virtual OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ); | 98 | virtual OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ); |
70 | 99 | ||
71 | /** | 100 | /** |
72 | * Effective Events are special event occuring during a time frame. This method does calcualte | 101 | * Effective Events are special event occuring during a time frame. This method does calcualte |
73 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method | 102 | * EffectiveEvents bases on the directNonRepeats and directRawRepeats. You may implement this method |
74 | * yourself | 103 | * yourself |
75 | */ | 104 | */ |
76 | virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ); | 105 | virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ); |
77 | 106 | ||
78 | /** | 107 | /** |
79 | * this is an overloaded member function | 108 | * this is an overloaded member function |
80 | * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) | 109 | * @see effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) |
81 | */ | 110 | */ |
82 | virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ); | 111 | virtual OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ); |
83 | 112 | ||
84 | private: | 113 | private: |
85 | class Private; | 114 | class Private; |
86 | Private *d; | 115 | Private *d; |
87 | 116 | ||
88 | }; | 117 | }; |
89 | 118 | ||
119 | } | ||
120 | |||
90 | #endif | 121 | #endif |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 756f405..e79696c 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -1,367 +1,366 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
2 | * SQL Backend for the OPIE-Calender Database. | 30 | * SQL Backend for the OPIE-Calender Database. |
3 | * | 31 | * |
4 | * Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * ===================================================================== | ||
13 | * Version: $Id$ | ||
14 | * ===================================================================== | ||
15 | * History: | ||
16 | * $Log$ | ||
17 | * Revision 1.3 2003/12/22 11:41:39 eilers | ||
18 | * Fixing stupid bug, found by sourcode review.. | ||
19 | * | ||
20 | * Revision 1.2 2003/12/22 10:19:26 eilers | ||
21 | * Finishing implementation of sql-backend for datebook. But I have to | ||
22 | * port the PIM datebook application to use it, before I could debug the | ||
23 | * whole stuff. | ||
24 | * Thus, PIM-Database backend is finished, but highly experimental. And some | ||
25 | * parts are still generic. For instance, the "queryByExample()" methods are | ||
26 | * not (or not fully) implemented. Todo: custom-entries not stored. | ||
27 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | ||
28 | * expression search in the database, which is not supported by sqlite ! | ||
29 | * Therefore we need either an extended sqlite or a workaround which would | ||
30 | * be very slow and memory consuming.. | ||
31 | * | ||
32 | * Revision 1.1 2003/12/08 15:18:12 eilers | ||
33 | * Committing unfinished sql implementation before merging to libopie2 starts.. | ||
34 | * | ||
35 | * | ||
36 | */ | 32 | */ |
37 | 33 | ||
38 | #include <stdio.h> | 34 | #include <stdio.h> |
39 | #include <stdlib.h> | 35 | #include <stdlib.h> |
40 | 36 | ||
41 | #include <qarray.h> | 37 | #include <qarray.h> |
42 | #include <qstringlist.h> | 38 | #include <qstringlist.h> |
43 | 39 | ||
44 | #include <qpe/global.h> | 40 | #include <qpe/global.h> |
45 | 41 | ||
46 | #include <opie2/osqldriver.h> | 42 | #include <opie2/osqldriver.h> |
47 | #include <opie2/osqlmanager.h> | 43 | #include <opie2/osqlmanager.h> |
48 | #include <opie2/osqlquery.h> | 44 | #include <opie2/osqlquery.h> |
49 | 45 | ||
50 | #include "orecur.h" | 46 | #include <opie2/orecur.h> |
51 | #include "odatebookaccessbackend_sql.h" | 47 | #include <opie2/odatebookaccessbackend_sql.h> |
52 | 48 | ||
49 | namespace Opie { | ||
53 | 50 | ||
54 | 51 | ||
55 | ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | 52 | ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , |
56 | const QString& fileName ) | 53 | const QString& fileName ) |
57 | : ODateBookAccessBackend(), m_driver( NULL ) | 54 | : ODateBookAccessBackend(), m_driver( NULL ) |
58 | { | 55 | { |
59 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; | 56 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; |
60 | 57 | ||
61 | // Get the standart sql-driver from the OSQLManager.. | 58 | // Get the standart sql-driver from the OSQLManager.. |
62 | OSQLManager man; | 59 | OSQLManager man; |
63 | m_driver = man.standard(); | 60 | m_driver = man.standard(); |
64 | m_driver->setUrl( m_fileName ); | 61 | m_driver->setUrl( m_fileName ); |
65 | 62 | ||
66 | initFields(); | 63 | initFields(); |
67 | 64 | ||
68 | load(); | 65 | load(); |
69 | } | 66 | } |
70 | 67 | ||
71 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { | 68 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { |
72 | if( m_driver ) | 69 | if( m_driver ) |
73 | delete m_driver; | 70 | delete m_driver; |
74 | } | 71 | } |
75 | 72 | ||
76 | void ODateBookAccessBackend_SQL::initFields() | 73 | void ODateBookAccessBackend_SQL::initFields() |
77 | { | 74 | { |
78 | 75 | ||
79 | // This map contains the translation of the fieldtype id's to | 76 | // This map contains the translation of the fieldtype id's to |
80 | // the names of the table columns | 77 | // the names of the table columns |
81 | m_fieldMap.insert( OEvent::FUid, "uid" ); | 78 | m_fieldMap.insert( OEvent::FUid, "uid" ); |
82 | m_fieldMap.insert( OEvent::FCategories, "Categories" ); | 79 | m_fieldMap.insert( OEvent::FCategories, "Categories" ); |
83 | m_fieldMap.insert( OEvent::FDescription, "Description" ); | 80 | m_fieldMap.insert( OEvent::FDescription, "Description" ); |
84 | m_fieldMap.insert( OEvent::FLocation, "Location" ); | 81 | m_fieldMap.insert( OEvent::FLocation, "Location" ); |
85 | m_fieldMap.insert( OEvent::FType, "Type" ); | 82 | m_fieldMap.insert( OEvent::FType, "Type" ); |
86 | m_fieldMap.insert( OEvent::FAlarm, "Alarm" ); | 83 | m_fieldMap.insert( OEvent::FAlarm, "Alarm" ); |
87 | m_fieldMap.insert( OEvent::FSound, "Sound" ); | 84 | m_fieldMap.insert( OEvent::FSound, "Sound" ); |
88 | m_fieldMap.insert( OEvent::FRType, "RType" ); | 85 | m_fieldMap.insert( OEvent::FRType, "RType" ); |
89 | m_fieldMap.insert( OEvent::FRWeekdays, "RWeekdays" ); | 86 | m_fieldMap.insert( OEvent::FRWeekdays, "RWeekdays" ); |
90 | m_fieldMap.insert( OEvent::FRPosition, "RPosition" ); | 87 | m_fieldMap.insert( OEvent::FRPosition, "RPosition" ); |
91 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); | 88 | m_fieldMap.insert( OEvent::FRFreq, "RFreq" ); |
92 | m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); | 89 | m_fieldMap.insert( OEvent::FRHasEndDate, "RHasEndDate" ); |
93 | m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); | 90 | m_fieldMap.insert( OEvent::FREndDate, "REndDate" ); |
94 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); | 91 | m_fieldMap.insert( OEvent::FRCreated, "RCreated" ); |
95 | m_fieldMap.insert( OEvent::FRExceptions, "RExceptions" ); | 92 | m_fieldMap.insert( OEvent::FRExceptions, "RExceptions" ); |
96 | m_fieldMap.insert( OEvent::FStart, "Start" ); | 93 | m_fieldMap.insert( OEvent::FStart, "Start" ); |
97 | m_fieldMap.insert( OEvent::FEnd, "End" ); | 94 | m_fieldMap.insert( OEvent::FEnd, "End" ); |
98 | m_fieldMap.insert( OEvent::FNote, "Note" ); | 95 | m_fieldMap.insert( OEvent::FNote, "Note" ); |
99 | m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); | 96 | m_fieldMap.insert( OEvent::FTimeZone, "TimeZone" ); |
100 | m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); | 97 | m_fieldMap.insert( OEvent::FRecParent, "RecParent" ); |
101 | m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); | 98 | m_fieldMap.insert( OEvent::FRecChildren, "Recchildren" ); |
102 | 99 | ||
103 | // Create a map that maps the column name to the id | 100 | // Create a map that maps the column name to the id |
104 | QMapConstIterator<int, QString> it; | 101 | QMapConstIterator<int, QString> it; |
105 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 102 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
106 | m_reverseFieldMap.insert( it.data(), it.key() ); | 103 | m_reverseFieldMap.insert( it.data(), it.key() ); |
107 | } | 104 | } |
108 | 105 | ||
109 | } | 106 | } |
110 | 107 | ||
111 | bool ODateBookAccessBackend_SQL::load() | 108 | bool ODateBookAccessBackend_SQL::load() |
112 | { | 109 | { |
113 | if (!m_driver->open() ) | 110 | if (!m_driver->open() ) |
114 | return false; | 111 | return false; |
115 | 112 | ||
116 | // Don't expect that the database exists. | 113 | // Don't expect that the database exists. |
117 | // It is save here to create the table, even if it | 114 | // It is save here to create the table, even if it |
118 | // do exist. ( Is that correct for all databases ?? ) | 115 | // do exist. ( Is that correct for all databases ?? ) |
119 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; | 116 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; |
120 | 117 | ||
121 | QMap<int, QString>::Iterator it; | 118 | QMap<int, QString>::Iterator it; |
122 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 119 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
123 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); | 120 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); |
124 | } | 121 | } |
125 | qu += " );"; | 122 | qu += " );"; |
126 | 123 | ||
127 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; | 124 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; |
128 | 125 | ||
129 | qWarning( "command: %s", qu.latin1() ); | 126 | qWarning( "command: %s", qu.latin1() ); |
130 | 127 | ||
131 | OSQLRawQuery raw( qu ); | 128 | OSQLRawQuery raw( qu ); |
132 | OSQLResult res = m_driver->query( &raw ); | 129 | OSQLResult res = m_driver->query( &raw ); |
133 | if ( res.state() != OSQLResult::Success ) | 130 | if ( res.state() != OSQLResult::Success ) |
134 | return false; | 131 | return false; |
135 | 132 | ||
136 | update(); | 133 | update(); |
137 | 134 | ||
138 | return true; | 135 | return true; |
139 | } | 136 | } |
140 | 137 | ||
141 | void ODateBookAccessBackend_SQL::update() | 138 | void ODateBookAccessBackend_SQL::update() |
142 | { | 139 | { |
143 | 140 | ||
144 | QString qu = "select uid from datebook"; | 141 | QString qu = "select uid from datebook"; |
145 | OSQLRawQuery raw( qu ); | 142 | OSQLRawQuery raw( qu ); |
146 | OSQLResult res = m_driver->query( &raw ); | 143 | OSQLResult res = m_driver->query( &raw ); |
147 | if ( res.state() != OSQLResult::Success ){ | 144 | if ( res.state() != OSQLResult::Success ){ |
148 | // m_uids.clear(); | 145 | // m_uids.clear(); |
149 | return; | 146 | return; |
150 | } | 147 | } |
151 | 148 | ||
152 | m_uids = extractUids( res ); | 149 | m_uids = extractUids( res ); |
153 | 150 | ||
154 | } | 151 | } |
155 | 152 | ||
156 | bool ODateBookAccessBackend_SQL::reload() | 153 | bool ODateBookAccessBackend_SQL::reload() |
157 | { | 154 | { |
158 | return load(); | 155 | return load(); |
159 | } | 156 | } |
160 | 157 | ||
161 | bool ODateBookAccessBackend_SQL::save() | 158 | bool ODateBookAccessBackend_SQL::save() |
162 | { | 159 | { |
163 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 160 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
164 | } | 161 | } |
165 | 162 | ||
166 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const | 163 | QArray<int> ODateBookAccessBackend_SQL::allRecords()const |
167 | { | 164 | { |
168 | return m_uids; | 165 | return m_uids; |
169 | } | 166 | } |
170 | 167 | ||
171 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { | 168 | QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OEvent&, int, const QDateTime& ) { |
172 | return QArray<int>(); | 169 | return QArray<int>(); |
173 | } | 170 | } |
174 | 171 | ||
175 | void ODateBookAccessBackend_SQL::clear() | 172 | void ODateBookAccessBackend_SQL::clear() |
176 | { | 173 | { |
177 | QString qu = "drop table datebook;"; | 174 | QString qu = "drop table datebook;"; |
178 | qu += "drop table custom_data;"; | 175 | qu += "drop table custom_data;"; |
179 | 176 | ||
180 | OSQLRawQuery raw( qu ); | 177 | OSQLRawQuery raw( qu ); |
181 | OSQLResult res = m_driver->query( &raw ); | 178 | OSQLResult res = m_driver->query( &raw ); |
182 | 179 | ||
183 | reload(); | 180 | reload(); |
184 | } | 181 | } |
185 | 182 | ||
186 | 183 | ||
187 | OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ | 184 | OEvent ODateBookAccessBackend_SQL::find( int uid ) const{ |
188 | QString qu = "select *"; | 185 | QString qu = "select *"; |
189 | qu += "from datebook where uid = " + QString::number(uid); | 186 | qu += "from datebook where uid = " + QString::number(uid); |
190 | 187 | ||
191 | OSQLRawQuery raw( qu ); | 188 | OSQLRawQuery raw( qu ); |
192 | OSQLResult res = m_driver->query( &raw ); | 189 | OSQLResult res = m_driver->query( &raw ); |
193 | 190 | ||
194 | OSQLResultItem resItem = res.first(); | 191 | OSQLResultItem resItem = res.first(); |
195 | 192 | ||
196 | // Create Map for date event and insert UID | 193 | // Create Map for date event and insert UID |
197 | QMap<int,QString> dateEventMap; | 194 | QMap<int,QString> dateEventMap; |
198 | dateEventMap.insert( OEvent::FUid, QString::number( uid ) ); | 195 | dateEventMap.insert( OEvent::FUid, QString::number( uid ) ); |
199 | 196 | ||
200 | // Now insert the data out of the columns into the map. | 197 | // Now insert the data out of the columns into the map. |
201 | QMapConstIterator<int, QString> it; | 198 | QMapConstIterator<int, QString> it; |
202 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 199 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
203 | dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); | 200 | dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); |
204 | } | 201 | } |
205 | 202 | ||
206 | // Last step: Put map into date event and return it | 203 | // Last step: Put map into date event and return it |
207 | OEvent retDate( dateEventMap ); | 204 | OEvent retDate( dateEventMap ); |
208 | 205 | ||
209 | return retDate; | 206 | return retDate; |
210 | } | 207 | } |
211 | 208 | ||
212 | // FIXME: Speed up update of uid's.. | 209 | // FIXME: Speed up update of uid's.. |
213 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) | 210 | bool ODateBookAccessBackend_SQL::add( const OEvent& ev ) |
214 | { | 211 | { |
215 | QMap<int,QString> eventMap = ev.toMap(); | 212 | QMap<int,QString> eventMap = ev.toMap(); |
216 | 213 | ||
217 | QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); | 214 | QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); |
218 | QMap<int, QString>::Iterator it; | 215 | QMap<int, QString>::Iterator it; |
219 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 216 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
220 | if ( !eventMap[it.key()].isEmpty() ) | 217 | if ( !eventMap[it.key()].isEmpty() ) |
221 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); | 218 | qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); |
222 | else | 219 | else |
223 | qu += QString( ",\"\"" ); | 220 | qu += QString( ",\"\"" ); |
224 | } | 221 | } |
225 | qu += " );"; | 222 | qu += " );"; |
226 | 223 | ||
227 | // Add custom entries | 224 | // Add custom entries |
228 | int id = 0; | 225 | int id = 0; |
229 | QMap<QString, QString> customMap = ev.toExtraMap(); | 226 | QMap<QString, QString> customMap = ev.toExtraMap(); |
230 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 227 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
231 | it != customMap.end(); ++it ){ | 228 | it != customMap.end(); ++it ){ |
232 | qu += "insert into custom_data VALUES(" | 229 | qu += "insert into custom_data VALUES(" |
233 | + QString::number( ev.uid() ) | 230 | + QString::number( ev.uid() ) |
234 | + "," | 231 | + "," |
235 | + QString::number( id++ ) | 232 | + QString::number( id++ ) |
236 | + ",'" | 233 | + ",'" |
237 | + it.key() //.latin1() | 234 | + it.key() //.latin1() |
238 | + "'," | 235 | + "'," |
239 | + "0" // Priority for future enhancements | 236 | + "0" // Priority for future enhancements |
240 | + ",'" | 237 | + ",'" |
241 | + it.data() //.latin1() | 238 | + it.data() //.latin1() |
242 | + "');"; | 239 | + "');"; |
243 | } | 240 | } |
244 | qWarning("add %s", qu.latin1() ); | 241 | qWarning("add %s", qu.latin1() ); |
245 | 242 | ||
246 | OSQLRawQuery raw( qu ); | 243 | OSQLRawQuery raw( qu ); |
247 | OSQLResult res = m_driver->query( &raw ); | 244 | OSQLResult res = m_driver->query( &raw ); |
248 | if ( res.state() != OSQLResult::Success ){ | 245 | if ( res.state() != OSQLResult::Success ){ |
249 | return false; | 246 | return false; |
250 | } | 247 | } |
251 | 248 | ||
252 | // Update list of uid's | 249 | // Update list of uid's |
253 | update(); | 250 | update(); |
254 | 251 | ||
255 | return true; | 252 | return true; |
256 | } | 253 | } |
257 | 254 | ||
258 | // FIXME: Speed up update of uid's.. | 255 | // FIXME: Speed up update of uid's.. |
259 | bool ODateBookAccessBackend_SQL::remove( int uid ) | 256 | bool ODateBookAccessBackend_SQL::remove( int uid ) |
260 | { | 257 | { |
261 | QString qu = "DELETE from datebook where uid = " | 258 | QString qu = "DELETE from datebook where uid = " |
262 | + QString::number( uid ) + ";"; | 259 | + QString::number( uid ) + ";"; |
263 | qu += "DELETE from custom_data where uid = " | 260 | qu += "DELETE from custom_data where uid = " |
264 | + QString::number( uid ) + ";"; | 261 | + QString::number( uid ) + ";"; |
265 | 262 | ||
266 | OSQLRawQuery raw( qu ); | 263 | OSQLRawQuery raw( qu ); |
267 | OSQLResult res = m_driver->query( &raw ); | 264 | OSQLResult res = m_driver->query( &raw ); |
268 | if ( res.state() != OSQLResult::Success ){ | 265 | if ( res.state() != OSQLResult::Success ){ |
269 | return false; | 266 | return false; |
270 | } | 267 | } |
271 | 268 | ||
272 | // Update list of uid's | 269 | // Update list of uid's |
273 | update(); | 270 | update(); |
274 | 271 | ||
275 | return true; | 272 | return true; |
276 | } | 273 | } |
277 | 274 | ||
278 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) | 275 | bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) |
279 | { | 276 | { |
280 | remove( ev.uid() ); | 277 | remove( ev.uid() ); |
281 | return add( ev ); | 278 | return add( ev ); |
282 | } | 279 | } |
283 | 280 | ||
284 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const | 281 | QArray<int> ODateBookAccessBackend_SQL::rawEvents()const |
285 | { | 282 | { |
286 | return allRecords(); | 283 | return allRecords(); |
287 | } | 284 | } |
288 | 285 | ||
289 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const | 286 | QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const |
290 | { | 287 | { |
291 | QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; | 288 | QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; |
292 | OSQLRawQuery raw( qu ); | 289 | OSQLRawQuery raw( qu ); |
293 | OSQLResult res = m_driver->query( &raw ); | 290 | OSQLResult res = m_driver->query( &raw ); |
294 | if ( res.state() != OSQLResult::Success ){ | 291 | if ( res.state() != OSQLResult::Success ){ |
295 | QArray<int> nix; | 292 | QArray<int> nix; |
296 | return nix; | 293 | return nix; |
297 | } | 294 | } |
298 | 295 | ||
299 | return extractUids( res ); | 296 | return extractUids( res ); |
300 | } | 297 | } |
301 | 298 | ||
302 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const | 299 | QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const |
303 | { | 300 | { |
304 | QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; | 301 | QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; |
305 | OSQLRawQuery raw( qu ); | 302 | OSQLRawQuery raw( qu ); |
306 | OSQLResult res = m_driver->query( &raw ); | 303 | OSQLResult res = m_driver->query( &raw ); |
307 | if ( res.state() != OSQLResult::Success ){ | 304 | if ( res.state() != OSQLResult::Success ){ |
308 | QArray<int> nix; | 305 | QArray<int> nix; |
309 | return nix; | 306 | return nix; |
310 | } | 307 | } |
311 | 308 | ||
312 | return extractUids( res ); | 309 | return extractUids( res ); |
313 | } | 310 | } |
314 | 311 | ||
315 | OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() | 312 | OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() |
316 | { | 313 | { |
317 | QArray<int> nonRepUids = nonRepeats(); | 314 | QArray<int> nonRepUids = nonRepeats(); |
318 | OEvent::ValueList list; | 315 | OEvent::ValueList list; |
319 | 316 | ||
320 | for (uint i = 0; i < nonRepUids.count(); ++i ){ | 317 | for (uint i = 0; i < nonRepUids.count(); ++i ){ |
321 | list.append( find( nonRepUids[i] ) ); | 318 | list.append( find( nonRepUids[i] ) ); |
322 | } | 319 | } |
323 | 320 | ||
324 | return list; | 321 | return list; |
325 | 322 | ||
326 | } | 323 | } |
327 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() | 324 | OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() |
328 | { | 325 | { |
329 | QArray<int> rawRepUids = rawRepeats(); | 326 | QArray<int> rawRepUids = rawRepeats(); |
330 | OEvent::ValueList list; | 327 | OEvent::ValueList list; |
331 | 328 | ||
332 | for (uint i = 0; i < rawRepUids.count(); ++i ){ | 329 | for (uint i = 0; i < rawRepUids.count(); ++i ){ |
333 | list.append( find( rawRepUids[i] ) ); | 330 | list.append( find( rawRepUids[i] ) ); |
334 | } | 331 | } |
335 | 332 | ||
336 | return list; | 333 | return list; |
337 | } | 334 | } |
338 | 335 | ||
339 | 336 | ||
340 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 337 | QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
341 | { | 338 | { |
342 | QArray<int> null; | 339 | QArray<int> null; |
343 | return null; | 340 | return null; |
344 | } | 341 | } |
345 | 342 | ||
346 | /* ===== Private Functions ========================================== */ | 343 | /* ===== Private Functions ========================================== */ |
347 | 344 | ||
348 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const | 345 | QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const |
349 | { | 346 | { |
350 | qWarning("extractUids"); | 347 | qWarning("extractUids"); |
351 | QTime t; | 348 | QTime t; |
352 | t.start(); | 349 | t.start(); |
353 | OSQLResultItem::ValueList list = res.results(); | 350 | OSQLResultItem::ValueList list = res.results(); |
354 | OSQLResultItem::ValueList::Iterator it; | 351 | OSQLResultItem::ValueList::Iterator it; |
355 | QArray<int> ints(list.count() ); | 352 | QArray<int> ints(list.count() ); |
356 | qWarning(" count = %d", list.count() ); | 353 | qWarning(" count = %d", list.count() ); |
357 | 354 | ||
358 | int i = 0; | 355 | int i = 0; |
359 | for (it = list.begin(); it != list.end(); ++it ) { | 356 | for (it = list.begin(); it != list.end(); ++it ) { |
360 | ints[i] = (*it).data("uid").toInt(); | 357 | ints[i] = (*it).data("uid").toInt(); |
361 | i++; | 358 | i++; |
362 | } | 359 | } |
363 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); | 360 | qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); |
364 | 361 | ||
365 | return ints; | 362 | return ints; |
366 | 363 | ||
367 | } | 364 | } |
365 | |||
366 | } | ||
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h index f39e154..89939ef 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h | |||
@@ -1,62 +1,93 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H | 29 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H | 30 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_SQL__H |
3 | 31 | ||
4 | #include <qmap.h> | 32 | #include <qmap.h> |
5 | #include <opie2/osqlresult.h> | 33 | #include <opie2/osqlresult.h> |
6 | 34 | ||
7 | #include "odatebookaccessbackend.h" | 35 | #include <opie2/odatebookaccessbackend.h> |
8 | 36 | ||
9 | class OSQLDriver; | 37 | class OSQLDriver; |
10 | 38 | ||
39 | namespace Opie { | ||
11 | /** | 40 | /** |
12 | * This is the default SQL implementation for DateBoook SQL storage | 41 | * This is the default SQL implementation for DateBoook SQL storage |
13 | * It fully implements the interface | 42 | * It fully implements the interface |
14 | * @see ODateBookAccessBackend | 43 | * @see ODateBookAccessBackend |
15 | * @see OPimAccessBackend | 44 | * @see OPimAccessBackend |
16 | */ | 45 | */ |
17 | class ODateBookAccessBackend_SQL : public ODateBookAccessBackend { | 46 | class ODateBookAccessBackend_SQL : public ODateBookAccessBackend { |
18 | public: | 47 | public: |
19 | ODateBookAccessBackend_SQL( const QString& appName, | 48 | ODateBookAccessBackend_SQL( const QString& appName, |
20 | const QString& fileName = QString::null); | 49 | const QString& fileName = QString::null); |
21 | ~ODateBookAccessBackend_SQL(); | 50 | ~ODateBookAccessBackend_SQL(); |
22 | 51 | ||
23 | bool load(); | 52 | bool load(); |
24 | bool reload(); | 53 | bool reload(); |
25 | bool save(); | 54 | bool save(); |
26 | 55 | ||
27 | QArray<int> allRecords()const; | 56 | QArray<int> allRecords()const; |
28 | QArray<int> matchRegexp(const QRegExp &r) const; | 57 | QArray<int> matchRegexp(const QRegExp &r) const; |
29 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); | 58 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); |
30 | OEvent find( int uid )const; | 59 | OEvent find( int uid )const; |
31 | void clear(); | 60 | void clear(); |
32 | bool add( const OEvent& ev ); | 61 | bool add( const OEvent& ev ); |
33 | bool remove( int uid ); | 62 | bool remove( int uid ); |
34 | bool replace( const OEvent& ev ); | 63 | bool replace( const OEvent& ev ); |
35 | 64 | ||
36 | QArray<UID> rawEvents()const; | 65 | QArray<UID> rawEvents()const; |
37 | QArray<UID> rawRepeats()const; | 66 | QArray<UID> rawRepeats()const; |
38 | QArray<UID> nonRepeats()const; | 67 | QArray<UID> nonRepeats()const; |
39 | 68 | ||
40 | OEvent::ValueList directNonRepeats(); | 69 | OEvent::ValueList directNonRepeats(); |
41 | OEvent::ValueList directRawRepeats(); | 70 | OEvent::ValueList directRawRepeats(); |
42 | 71 | ||
43 | private: | 72 | private: |
44 | bool loadFile(); | 73 | bool loadFile(); |
45 | QString m_fileName; | 74 | QString m_fileName; |
46 | QArray<int> m_uids; | 75 | QArray<int> m_uids; |
47 | 76 | ||
48 | QMap<int, QString> m_fieldMap; | 77 | QMap<int, QString> m_fieldMap; |
49 | QMap<QString, int> m_reverseFieldMap; | 78 | QMap<QString, int> m_reverseFieldMap; |
50 | 79 | ||
51 | OSQLDriver* m_driver; | 80 | OSQLDriver* m_driver; |
52 | 81 | ||
53 | class Private; | 82 | class Private; |
54 | Private *d; | 83 | Private *d; |
55 | 84 | ||
56 | void initFields(); | 85 | void initFields(); |
57 | void update(); | 86 | void update(); |
58 | QArray<int> extractUids( OSQLResult& res ) const; | 87 | QArray<int> extractUids( OSQLResult& res ) const; |
59 | 88 | ||
60 | }; | 89 | }; |
61 | 90 | ||
91 | } | ||
92 | |||
62 | #endif | 93 | #endif |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp index 929d004..0ebda98 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp | |||
@@ -1,360 +1,391 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <errno.h> | 29 | #include <errno.h> |
2 | #include <fcntl.h> | 30 | #include <fcntl.h> |
3 | 31 | ||
4 | #include <stdio.h> | 32 | #include <stdio.h> |
5 | #include <stdlib.h> | 33 | #include <stdlib.h> |
6 | 34 | ||
7 | #include <sys/types.h> | 35 | #include <sys/types.h> |
8 | #include <sys/mman.h> | 36 | #include <sys/mman.h> |
9 | #include <sys/stat.h> | 37 | #include <sys/stat.h> |
10 | 38 | ||
11 | #include <unistd.h> | 39 | #include <unistd.h> |
12 | 40 | ||
13 | #include <qasciidict.h> | 41 | #include <qasciidict.h> |
14 | #include <qfile.h> | 42 | #include <qfile.h> |
15 | 43 | ||
16 | #include <qtopia/global.h> | 44 | #include <qtopia/global.h> |
17 | #include <qtopia/stringutil.h> | 45 | #include <qtopia/stringutil.h> |
18 | #include <qtopia/timeconversion.h> | 46 | #include <qtopia/timeconversion.h> |
19 | 47 | ||
20 | #include "opimnotifymanager.h" | 48 | #include <opie2/opimnotifymanager.h> |
21 | #include "orecur.h" | 49 | #include <opie2/orecur.h> |
22 | #include "otimezone.h" | 50 | #include <opie2/otimezone.h> |
23 | #include "odatebookaccessbackend_xml.h" | 51 | #include <opie2/odatebookaccessbackend_xml.h> |
52 | |||
53 | using namespace Opie; | ||
24 | 54 | ||
25 | namespace { | 55 | namespace { |
26 | // FROM TT again | 56 | // FROM TT again |
27 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 57 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
28 | { | 58 | { |
29 | char needleChar; | 59 | char needleChar; |
30 | char haystackChar; | 60 | char haystackChar; |
31 | if (!needle || !haystack || !hLen || !nLen) | 61 | if (!needle || !haystack || !hLen || !nLen) |
32 | return 0; | 62 | return 0; |
33 | 63 | ||
34 | const char* hsearch = haystack; | 64 | const char* hsearch = haystack; |
35 | 65 | ||
36 | if ((needleChar = *needle++) != 0) { | 66 | if ((needleChar = *needle++) != 0) { |
37 | nLen--; //(to make up for needle++) | 67 | nLen--; //(to make up for needle++) |
38 | do { | 68 | do { |
39 | do { | 69 | do { |
40 | if ((haystackChar = *hsearch++) == 0) | 70 | if ((haystackChar = *hsearch++) == 0) |
41 | return (0); | 71 | return (0); |
42 | if (hsearch >= haystack + hLen) | 72 | if (hsearch >= haystack + hLen) |
43 | return (0); | 73 | return (0); |
44 | } while (haystackChar != needleChar); | 74 | } while (haystackChar != needleChar); |
45 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 75 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
46 | hsearch--; | 76 | hsearch--; |
47 | } | 77 | } |
48 | return ((char *)hsearch); | 78 | return ((char *)hsearch); |
49 | } | 79 | } |
50 | } | 80 | } |
51 | 81 | ||
52 | namespace { | 82 | namespace { |
53 | time_t start, end, created, rp_end; | 83 | time_t start, end, created, rp_end; |
54 | ORecur* rec; | 84 | ORecur* rec; |
55 | ORecur* recur() { | 85 | ORecur* recur() { |
56 | if (!rec) | 86 | if (!rec) |
57 | rec = new ORecur; | 87 | rec = new ORecur; |
58 | 88 | ||
59 | return rec; | 89 | return rec; |
60 | } | 90 | } |
61 | int alarmTime; | 91 | int alarmTime; |
62 | int snd; | 92 | int snd; |
63 | enum Attribute{ | 93 | enum Attribute{ |
64 | FDescription = 0, | 94 | FDescription = 0, |
65 | FLocation, | 95 | FLocation, |
66 | FCategories, | 96 | FCategories, |
67 | FUid, | 97 | FUid, |
68 | FType, | 98 | FType, |
69 | FAlarm, | 99 | FAlarm, |
70 | FSound, | 100 | FSound, |
71 | FRType, | 101 | FRType, |
72 | FRWeekdays, | 102 | FRWeekdays, |
73 | FRPosition, | 103 | FRPosition, |
74 | FRFreq, | 104 | FRFreq, |
75 | FRHasEndDate, | 105 | FRHasEndDate, |
76 | FREndDate, | 106 | FREndDate, |
77 | FRStart, | 107 | FRStart, |
78 | FREnd, | 108 | FREnd, |
79 | FNote, | 109 | FNote, |
80 | FCreated, // Should't this be called FRCreated ? | 110 | FCreated, // Should't this be called FRCreated ? |
81 | FTimeZone, | 111 | FTimeZone, |
82 | FRecParent, | 112 | FRecParent, |
83 | FRecChildren, | 113 | FRecChildren, |
84 | FExceptions | 114 | FExceptions |
85 | }; | 115 | }; |
86 | 116 | ||
87 | // FIXME: Use OEvent::toMap() here !! (eilers) | 117 | // FIXME: Use OEvent::toMap() here !! (eilers) |
88 | inline void save( const OEvent& ev, QString& buf ) { | 118 | inline void save( const OEvent& ev, QString& buf ) { |
89 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); | 119 | qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); |
90 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; | 120 | buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; |
91 | if (!ev.location().isEmpty() ) | 121 | if (!ev.location().isEmpty() ) |
92 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; | 122 | buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; |
93 | 123 | ||
94 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; | 124 | buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; |
95 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; | 125 | buf += " uid=\"" + QString::number( ev.uid() ) + "\""; |
96 | 126 | ||
97 | if (ev.isAllDay() ) | 127 | if (ev.isAllDay() ) |
98 | buf += " type=\"AllDay\""; // is that all ?? (eilers) | 128 | buf += " type=\"AllDay\""; // is that all ?? (eilers) |
99 | 129 | ||
100 | if (ev.hasNotifiers() ) { | 130 | if (ev.hasNotifiers() ) { |
101 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first | 131 | OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first |
102 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; | 132 | int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; |
103 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; | 133 | buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; |
104 | if ( alarm.sound() == OPimAlarm::Loud ) | 134 | if ( alarm.sound() == OPimAlarm::Loud ) |
105 | buf += "loud"; | 135 | buf += "loud"; |
106 | else | 136 | else |
107 | buf += "silent"; | 137 | buf += "silent"; |
108 | buf += "\""; | 138 | buf += "\""; |
109 | } | 139 | } |
110 | if ( ev.hasRecurrence() ) { | 140 | if ( ev.hasRecurrence() ) { |
111 | buf += ev.recurrence().toString(); | 141 | buf += ev.recurrence().toString(); |
112 | } | 142 | } |
113 | 143 | ||
114 | /* | 144 | /* |
115 | * fscking timezones :) well, we'll first convert | 145 | * fscking timezones :) well, we'll first convert |
116 | * the QDateTime to a QDateTime in UTC time | 146 | * the QDateTime to a QDateTime in UTC time |
117 | * and then we'll create a nice time_t | 147 | * and then we'll create a nice time_t |
118 | */ | 148 | */ |
119 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 149 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
120 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; | 150 | buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OTimeZone::utc() ) ) ) + "\""; |
121 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; | 151 | buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OTimeZone::utc() ) ) ) + "\""; |
122 | if (!ev.note().isEmpty() ) { | 152 | if (!ev.note().isEmpty() ) { |
123 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; | 153 | buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; |
124 | } | 154 | } |
125 | 155 | ||
126 | buf += " timezone=\""; | 156 | buf += " timezone=\""; |
127 | if ( ev.timeZone().isEmpty() ) | 157 | if ( ev.timeZone().isEmpty() ) |
128 | buf += "None"; | 158 | buf += "None"; |
129 | else | 159 | else |
130 | buf += ev.timeZone(); | 160 | buf += ev.timeZone(); |
131 | buf += "\""; | 161 | buf += "\""; |
132 | 162 | ||
133 | if (ev.parent() != 0 ) { | 163 | if (ev.parent() != 0 ) { |
134 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; | 164 | buf += " recparent=\""+QString::number(ev.parent() )+"\""; |
135 | } | 165 | } |
136 | 166 | ||
137 | if (ev.children().count() != 0 ) { | 167 | if (ev.children().count() != 0 ) { |
138 | QArray<int> children = ev.children(); | 168 | QArray<int> children = ev.children(); |
139 | buf += " recchildren=\""; | 169 | buf += " recchildren=\""; |
140 | for ( uint i = 0; i < children.count(); i++ ) { | 170 | for ( uint i = 0; i < children.count(); i++ ) { |
141 | if ( i != 0 ) buf += " "; | 171 | if ( i != 0 ) buf += " "; |
142 | buf += QString::number( children[i] ); | 172 | buf += QString::number( children[i] ); |
143 | } | 173 | } |
144 | buf+= "\""; | 174 | buf+= "\""; |
145 | } | 175 | } |
146 | 176 | ||
147 | // skip custom writing | 177 | // skip custom writing |
148 | } | 178 | } |
149 | 179 | ||
150 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { | 180 | inline bool forAll( const QMap<int, OEvent>& list, QFile& file ) { |
151 | QMap<int, OEvent>::ConstIterator it; | 181 | QMap<int, OEvent>::ConstIterator it; |
152 | QString buf; | 182 | QString buf; |
153 | QCString str; | 183 | QCString str; |
154 | int total_written; | 184 | int total_written; |
155 | for ( it = list.begin(); it != list.end(); ++it ) { | 185 | for ( it = list.begin(); it != list.end(); ++it ) { |
156 | buf = "<event"; | 186 | buf = "<event"; |
157 | save( it.data(), buf ); | 187 | save( it.data(), buf ); |
158 | buf += " />\n"; | 188 | buf += " />\n"; |
159 | str = buf.utf8(); | 189 | str = buf.utf8(); |
160 | 190 | ||
161 | total_written = file.writeBlock(str.data(), str.length() ); | 191 | total_written = file.writeBlock(str.data(), str.length() ); |
162 | if ( total_written != int(str.length() ) ) | 192 | if ( total_written != int(str.length() ) ) |
163 | return false; | 193 | return false; |
164 | } | 194 | } |
165 | return true; | 195 | return true; |
166 | } | 196 | } |
167 | } | 197 | } |
168 | 198 | ||
199 | namespace Opie { | ||
169 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , | 200 | ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , |
170 | const QString& fileName ) | 201 | const QString& fileName ) |
171 | : ODateBookAccessBackend() { | 202 | : ODateBookAccessBackend() { |
172 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; | 203 | m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; |
173 | m_changed = false; | 204 | m_changed = false; |
174 | } | 205 | } |
175 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { | 206 | ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { |
176 | } | 207 | } |
177 | bool ODateBookAccessBackend_XML::load() { | 208 | bool ODateBookAccessBackend_XML::load() { |
178 | return loadFile(); | 209 | return loadFile(); |
179 | } | 210 | } |
180 | bool ODateBookAccessBackend_XML::reload() { | 211 | bool ODateBookAccessBackend_XML::reload() { |
181 | clear(); | 212 | clear(); |
182 | return load(); | 213 | return load(); |
183 | } | 214 | } |
184 | bool ODateBookAccessBackend_XML::save() { | 215 | bool ODateBookAccessBackend_XML::save() { |
185 | if (!m_changed) return true; | 216 | if (!m_changed) return true; |
186 | 217 | ||
187 | int total_written; | 218 | int total_written; |
188 | QString strFileNew = m_name + ".new"; | 219 | QString strFileNew = m_name + ".new"; |
189 | 220 | ||
190 | QFile f( strFileNew ); | 221 | QFile f( strFileNew ); |
191 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; | 222 | if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; |
192 | 223 | ||
193 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); | 224 | QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
194 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; | 225 | buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; |
195 | buf += "<events>\n"; | 226 | buf += "<events>\n"; |
196 | QCString str = buf.utf8(); | 227 | QCString str = buf.utf8(); |
197 | total_written = f.writeBlock( str.data(), str.length() ); | 228 | total_written = f.writeBlock( str.data(), str.length() ); |
198 | if ( total_written != int(str.length() ) ) { | 229 | if ( total_written != int(str.length() ) ) { |
199 | f.close(); | 230 | f.close(); |
200 | QFile::remove( strFileNew ); | 231 | QFile::remove( strFileNew ); |
201 | return false; | 232 | return false; |
202 | } | 233 | } |
203 | 234 | ||
204 | if (!forAll( m_raw, f ) ) { | 235 | if (!forAll( m_raw, f ) ) { |
205 | f.close(); | 236 | f.close(); |
206 | QFile::remove( strFileNew ); | 237 | QFile::remove( strFileNew ); |
207 | return false; | 238 | return false; |
208 | } | 239 | } |
209 | if (!forAll( m_rep, f ) ) { | 240 | if (!forAll( m_rep, f ) ) { |
210 | f.close(); | 241 | f.close(); |
211 | QFile::remove( strFileNew ); | 242 | QFile::remove( strFileNew ); |
212 | return false; | 243 | return false; |
213 | } | 244 | } |
214 | 245 | ||
215 | buf = "</events>\n</DATEBOOK>\n"; | 246 | buf = "</events>\n</DATEBOOK>\n"; |
216 | str = buf.utf8(); | 247 | str = buf.utf8(); |
217 | total_written = f.writeBlock( str.data(), str.length() ); | 248 | total_written = f.writeBlock( str.data(), str.length() ); |
218 | if ( total_written != int(str.length() ) ) { | 249 | if ( total_written != int(str.length() ) ) { |
219 | f.close(); | 250 | f.close(); |
220 | QFile::remove( strFileNew ); | 251 | QFile::remove( strFileNew ); |
221 | return false; | 252 | return false; |
222 | } | 253 | } |
223 | f.close(); | 254 | f.close(); |
224 | 255 | ||
225 | if ( ::rename( strFileNew, m_name ) < 0 ) { | 256 | if ( ::rename( strFileNew, m_name ) < 0 ) { |
226 | QFile::remove( strFileNew ); | 257 | QFile::remove( strFileNew ); |
227 | return false; | 258 | return false; |
228 | } | 259 | } |
229 | 260 | ||
230 | m_changed = false; | 261 | m_changed = false; |
231 | return true; | 262 | return true; |
232 | } | 263 | } |
233 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { | 264 | QArray<int> ODateBookAccessBackend_XML::allRecords()const { |
234 | QArray<int> ints( m_raw.count()+ m_rep.count() ); | 265 | QArray<int> ints( m_raw.count()+ m_rep.count() ); |
235 | uint i = 0; | 266 | uint i = 0; |
236 | QMap<int, OEvent>::ConstIterator it; | 267 | QMap<int, OEvent>::ConstIterator it; |
237 | 268 | ||
238 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 269 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
239 | ints[i] = it.key(); | 270 | ints[i] = it.key(); |
240 | i++; | 271 | i++; |
241 | } | 272 | } |
242 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 273 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
243 | ints[i] = it.key(); | 274 | ints[i] = it.key(); |
244 | i++; | 275 | i++; |
245 | } | 276 | } |
246 | 277 | ||
247 | return ints; | 278 | return ints; |
248 | } | 279 | } |
249 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { | 280 | QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { |
250 | return QArray<int>(); | 281 | return QArray<int>(); |
251 | } | 282 | } |
252 | void ODateBookAccessBackend_XML::clear() { | 283 | void ODateBookAccessBackend_XML::clear() { |
253 | m_changed = true; | 284 | m_changed = true; |
254 | m_raw.clear(); | 285 | m_raw.clear(); |
255 | m_rep.clear(); | 286 | m_rep.clear(); |
256 | } | 287 | } |
257 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ | 288 | OEvent ODateBookAccessBackend_XML::find( int uid ) const{ |
258 | if ( m_raw.contains( uid ) ) | 289 | if ( m_raw.contains( uid ) ) |
259 | return m_raw[uid]; | 290 | return m_raw[uid]; |
260 | else | 291 | else |
261 | return m_rep[uid]; | 292 | return m_rep[uid]; |
262 | } | 293 | } |
263 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { | 294 | bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { |
264 | m_changed = true; | 295 | m_changed = true; |
265 | if (ev.hasRecurrence() ) | 296 | if (ev.hasRecurrence() ) |
266 | m_rep.insert( ev.uid(), ev ); | 297 | m_rep.insert( ev.uid(), ev ); |
267 | else | 298 | else |
268 | m_raw.insert( ev.uid(), ev ); | 299 | m_raw.insert( ev.uid(), ev ); |
269 | 300 | ||
270 | return true; | 301 | return true; |
271 | } | 302 | } |
272 | bool ODateBookAccessBackend_XML::remove( int uid ) { | 303 | bool ODateBookAccessBackend_XML::remove( int uid ) { |
273 | m_changed = true; | 304 | m_changed = true; |
274 | m_rep.remove( uid ); | 305 | m_rep.remove( uid ); |
275 | m_rep.remove( uid ); | 306 | m_rep.remove( uid ); |
276 | 307 | ||
277 | return true; | 308 | return true; |
278 | } | 309 | } |
279 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { | 310 | bool ODateBookAccessBackend_XML::replace( const OEvent& ev ) { |
280 | replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers) | 311 | replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers) |
281 | return add( ev ); | 312 | return add( ev ); |
282 | } | 313 | } |
283 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { | 314 | QArray<int> ODateBookAccessBackend_XML::rawEvents()const { |
284 | return allRecords(); | 315 | return allRecords(); |
285 | } | 316 | } |
286 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { | 317 | QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { |
287 | QArray<int> ints( m_rep.count() ); | 318 | QArray<int> ints( m_rep.count() ); |
288 | uint i = 0; | 319 | uint i = 0; |
289 | QMap<int, OEvent>::ConstIterator it; | 320 | QMap<int, OEvent>::ConstIterator it; |
290 | 321 | ||
291 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { | 322 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { |
292 | ints[i] = it.key(); | 323 | ints[i] = it.key(); |
293 | i++; | 324 | i++; |
294 | } | 325 | } |
295 | 326 | ||
296 | return ints; | 327 | return ints; |
297 | } | 328 | } |
298 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { | 329 | QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { |
299 | QArray<int> ints( m_raw.count() ); | 330 | QArray<int> ints( m_raw.count() ); |
300 | uint i = 0; | 331 | uint i = 0; |
301 | QMap<int, OEvent>::ConstIterator it; | 332 | QMap<int, OEvent>::ConstIterator it; |
302 | 333 | ||
303 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { | 334 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { |
304 | ints[i] = it.key(); | 335 | ints[i] = it.key(); |
305 | i++; | 336 | i++; |
306 | } | 337 | } |
307 | 338 | ||
308 | return ints; | 339 | return ints; |
309 | } | 340 | } |
310 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { | 341 | OEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { |
311 | OEvent::ValueList list; | 342 | OEvent::ValueList list; |
312 | QMap<int, OEvent>::ConstIterator it; | 343 | QMap<int, OEvent>::ConstIterator it; |
313 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) | 344 | for (it = m_raw.begin(); it != m_raw.end(); ++it ) |
314 | list.append( it.data() ); | 345 | list.append( it.data() ); |
315 | 346 | ||
316 | return list; | 347 | return list; |
317 | } | 348 | } |
318 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { | 349 | OEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { |
319 | OEvent::ValueList list; | 350 | OEvent::ValueList list; |
320 | QMap<int, OEvent>::ConstIterator it; | 351 | QMap<int, OEvent>::ConstIterator it; |
321 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) | 352 | for (it = m_rep.begin(); it != m_rep.end(); ++it ) |
322 | list.append( it.data() ); | 353 | list.append( it.data() ); |
323 | 354 | ||
324 | return list; | 355 | return list; |
325 | } | 356 | } |
326 | 357 | ||
327 | // FIXME: Use OEvent::fromMap() (eilers) | 358 | // FIXME: Use OEvent::fromMap() (eilers) |
328 | bool ODateBookAccessBackend_XML::loadFile() { | 359 | bool ODateBookAccessBackend_XML::loadFile() { |
329 | m_changed = false; | 360 | m_changed = false; |
330 | 361 | ||
331 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); | 362 | int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); |
332 | if ( fd < 0 ) return false; | 363 | if ( fd < 0 ) return false; |
333 | 364 | ||
334 | struct stat attribute; | 365 | struct stat attribute; |
335 | if ( ::fstat(fd, &attribute ) == -1 ) { | 366 | if ( ::fstat(fd, &attribute ) == -1 ) { |
336 | ::close( fd ); | 367 | ::close( fd ); |
337 | return false; | 368 | return false; |
338 | } | 369 | } |
339 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 370 | void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
340 | if ( map_addr == ( (caddr_t)-1) ) { | 371 | if ( map_addr == ( (caddr_t)-1) ) { |
341 | ::close( fd ); | 372 | ::close( fd ); |
342 | return false; | 373 | return false; |
343 | } | 374 | } |
344 | 375 | ||
345 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); | 376 | ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); |
346 | ::close( fd ); | 377 | ::close( fd ); |
347 | 378 | ||
348 | QAsciiDict<int> dict(FExceptions+1); | 379 | QAsciiDict<int> dict(FExceptions+1); |
349 | dict.setAutoDelete( true ); | 380 | dict.setAutoDelete( true ); |
350 | dict.insert( "description", new int(FDescription) ); | 381 | dict.insert( "description", new int(FDescription) ); |
351 | dict.insert( "location", new int(FLocation) ); | 382 | dict.insert( "location", new int(FLocation) ); |
352 | dict.insert( "categories", new int(FCategories) ); | 383 | dict.insert( "categories", new int(FCategories) ); |
353 | dict.insert( "uid", new int(FUid) ); | 384 | dict.insert( "uid", new int(FUid) ); |
354 | dict.insert( "type", new int(FType) ); | 385 | dict.insert( "type", new int(FType) ); |
355 | dict.insert( "alarm", new int(FAlarm) ); | 386 | dict.insert( "alarm", new int(FAlarm) ); |
356 | dict.insert( "sound", new int(FSound) ); | 387 | dict.insert( "sound", new int(FSound) ); |
357 | dict.insert( "rtype", new int(FRType) ); | 388 | dict.insert( "rtype", new int(FRType) ); |
358 | dict.insert( "rweekdays", new int(FRWeekdays) ); | 389 | dict.insert( "rweekdays", new int(FRWeekdays) ); |
359 | dict.insert( "rposition", new int(FRPosition) ); | 390 | dict.insert( "rposition", new int(FRPosition) ); |
360 | dict.insert( "rfreq", new int(FRFreq) ); | 391 | dict.insert( "rfreq", new int(FRFreq) ); |
@@ -421,192 +452,194 @@ bool ODateBookAccessBackend_XML::loadFile() { | |||
421 | continue; | 452 | continue; |
422 | } | 453 | } |
423 | 454 | ||
424 | QCString value( dt+i, j-i+1 ); | 455 | QCString value( dt+i, j-i+1 ); |
425 | i = j + 1; | 456 | i = j + 1; |
426 | 457 | ||
427 | QString str = (haveUtf ? QString::fromUtf8( value ) | 458 | QString str = (haveUtf ? QString::fromUtf8( value ) |
428 | : QString::fromLatin1( value ) ); | 459 | : QString::fromLatin1( value ) ); |
429 | if ( haveEnt ) | 460 | if ( haveEnt ) |
430 | str = Qtopia::plainString( str ); | 461 | str = Qtopia::plainString( str ); |
431 | 462 | ||
432 | /* | 463 | /* |
433 | * add key + value | 464 | * add key + value |
434 | */ | 465 | */ |
435 | find = dict[attr.data()]; | 466 | find = dict[attr.data()]; |
436 | if (!find) | 467 | if (!find) |
437 | ev.setCustomField( attr, str ); | 468 | ev.setCustomField( attr, str ); |
438 | else { | 469 | else { |
439 | setField( ev, *find, str ); | 470 | setField( ev, *find, str ); |
440 | } | 471 | } |
441 | } | 472 | } |
442 | /* time to finalize */ | 473 | /* time to finalize */ |
443 | finalizeRecord( ev ); | 474 | finalizeRecord( ev ); |
444 | delete rec; | 475 | delete rec; |
445 | } | 476 | } |
446 | ::munmap(map_addr, attribute.st_size ); | 477 | ::munmap(map_addr, attribute.st_size ); |
447 | m_changed = false; // changed during add | 478 | m_changed = false; // changed during add |
448 | 479 | ||
449 | return true; | 480 | return true; |
450 | } | 481 | } |
451 | 482 | ||
452 | // FIXME: Use OEvent::fromMap() which makes this obsolete.. (eilers) | 483 | // FIXME: Use OEvent::fromMap() which makes this obsolete.. (eilers) |
453 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { | 484 | void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { |
454 | /* AllDay is alway in UTC */ | 485 | /* AllDay is alway in UTC */ |
455 | if ( ev.isAllDay() ) { | 486 | if ( ev.isAllDay() ) { |
456 | OTimeZone utc = OTimeZone::utc(); | 487 | OTimeZone utc = OTimeZone::utc(); |
457 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); | 488 | ev.setStartDateTime( utc.fromUTCDateTime( start ) ); |
458 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); | 489 | ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); |
459 | ev.setTimeZone( "UTC"); // make sure it is really utc | 490 | ev.setTimeZone( "UTC"); // make sure it is really utc |
460 | }else { | 491 | }else { |
461 | /* to current date time */ | 492 | /* to current date time */ |
462 | // qWarning(" Start is %d", start ); | 493 | // qWarning(" Start is %d", start ); |
463 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); | 494 | OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); |
464 | QDateTime date = zone.toDateTime( start ); | 495 | QDateTime date = zone.toDateTime( start ); |
465 | qWarning(" Start is %s", date.toString().latin1() ); | 496 | qWarning(" Start is %s", date.toString().latin1() ); |
466 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | 497 | ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); |
467 | 498 | ||
468 | date = zone.toDateTime( end ); | 499 | date = zone.toDateTime( end ); |
469 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | 500 | ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); |
470 | } | 501 | } |
471 | if ( rec && rec->doesRecur() ) { | 502 | if ( rec && rec->doesRecur() ) { |
472 | OTimeZone utc = OTimeZone::utc(); | 503 | OTimeZone utc = OTimeZone::utc(); |
473 | ORecur recu( *rec ); // call copy c'tor; | 504 | ORecur recu( *rec ); // call copy c'tor; |
474 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); | 505 | recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); |
475 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); | 506 | recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); |
476 | recu.setStart( ev.startDateTime().date() ); | 507 | recu.setStart( ev.startDateTime().date() ); |
477 | ev.setRecurrence( recu ); | 508 | ev.setRecurrence( recu ); |
478 | } | 509 | } |
479 | 510 | ||
480 | if (alarmTime != -1 ) { | 511 | if (alarmTime != -1 ) { |
481 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); | 512 | QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); |
482 | OPimAlarm al( snd , dt ); | 513 | OPimAlarm al( snd , dt ); |
483 | ev.notifiers().add( al ); | 514 | ev.notifiers().add( al ); |
484 | } | 515 | } |
485 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { | 516 | if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { |
486 | qWarning("already contains assign uid"); | 517 | qWarning("already contains assign uid"); |
487 | ev.setUid( 1 ); | 518 | ev.setUid( 1 ); |
488 | } | 519 | } |
489 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); | 520 | qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); |
490 | if ( ev.hasRecurrence() ) | 521 | if ( ev.hasRecurrence() ) |
491 | m_rep.insert( ev.uid(), ev ); | 522 | m_rep.insert( ev.uid(), ev ); |
492 | else | 523 | else |
493 | m_raw.insert( ev.uid(), ev ); | 524 | m_raw.insert( ev.uid(), ev ); |
494 | 525 | ||
495 | } | 526 | } |
496 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { | 527 | void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& value) { |
497 | // qWarning(" setting %s", value.latin1() ); | 528 | // qWarning(" setting %s", value.latin1() ); |
498 | switch( id ) { | 529 | switch( id ) { |
499 | case FDescription: | 530 | case FDescription: |
500 | e.setDescription( value ); | 531 | e.setDescription( value ); |
501 | break; | 532 | break; |
502 | case FLocation: | 533 | case FLocation: |
503 | e.setLocation( value ); | 534 | e.setLocation( value ); |
504 | break; | 535 | break; |
505 | case FCategories: | 536 | case FCategories: |
506 | e.setCategories( e.idsFromString( value ) ); | 537 | e.setCategories( e.idsFromString( value ) ); |
507 | break; | 538 | break; |
508 | case FUid: | 539 | case FUid: |
509 | e.setUid( value.toInt() ); | 540 | e.setUid( value.toInt() ); |
510 | break; | 541 | break; |
511 | case FType: | 542 | case FType: |
512 | if ( value == "AllDay" ) { | 543 | if ( value == "AllDay" ) { |
513 | e.setAllDay( true ); | 544 | e.setAllDay( true ); |
514 | e.setTimeZone( "UTC" ); | 545 | e.setTimeZone( "UTC" ); |
515 | } | 546 | } |
516 | break; | 547 | break; |
517 | case FAlarm: | 548 | case FAlarm: |
518 | alarmTime = value.toInt(); | 549 | alarmTime = value.toInt(); |
519 | break; | 550 | break; |
520 | case FSound: | 551 | case FSound: |
521 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; | 552 | snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; |
522 | break; | 553 | break; |
523 | // recurrence stuff | 554 | // recurrence stuff |
524 | case FRType: | 555 | case FRType: |
525 | if ( value == "Daily" ) | 556 | if ( value == "Daily" ) |
526 | recur()->setType( ORecur::Daily ); | 557 | recur()->setType( ORecur::Daily ); |
527 | else if ( value == "Weekly" ) | 558 | else if ( value == "Weekly" ) |
528 | recur()->setType( ORecur::Weekly); | 559 | recur()->setType( ORecur::Weekly); |
529 | else if ( value == "MonthlyDay" ) | 560 | else if ( value == "MonthlyDay" ) |
530 | recur()->setType( ORecur::MonthlyDay ); | 561 | recur()->setType( ORecur::MonthlyDay ); |
531 | else if ( value == "MonthlyDate" ) | 562 | else if ( value == "MonthlyDate" ) |
532 | recur()->setType( ORecur::MonthlyDate ); | 563 | recur()->setType( ORecur::MonthlyDate ); |
533 | else if ( value == "Yearly" ) | 564 | else if ( value == "Yearly" ) |
534 | recur()->setType( ORecur::Yearly ); | 565 | recur()->setType( ORecur::Yearly ); |
535 | else | 566 | else |
536 | recur()->setType( ORecur::NoRepeat ); | 567 | recur()->setType( ORecur::NoRepeat ); |
537 | break; | 568 | break; |
538 | case FRWeekdays: | 569 | case FRWeekdays: |
539 | recur()->setDays( value.toInt() ); | 570 | recur()->setDays( value.toInt() ); |
540 | break; | 571 | break; |
541 | case FRPosition: | 572 | case FRPosition: |
542 | recur()->setPosition( value.toInt() ); | 573 | recur()->setPosition( value.toInt() ); |
543 | break; | 574 | break; |
544 | case FRFreq: | 575 | case FRFreq: |
545 | recur()->setFrequency( value.toInt() ); | 576 | recur()->setFrequency( value.toInt() ); |
546 | break; | 577 | break; |
547 | case FRHasEndDate: | 578 | case FRHasEndDate: |
548 | recur()->setHasEndDate( value.toInt() ); | 579 | recur()->setHasEndDate( value.toInt() ); |
549 | break; | 580 | break; |
550 | case FREndDate: { | 581 | case FREndDate: { |
551 | rp_end = (time_t) value.toLong(); | 582 | rp_end = (time_t) value.toLong(); |
552 | break; | 583 | break; |
553 | } | 584 | } |
554 | case FRStart: { | 585 | case FRStart: { |
555 | start = (time_t) value.toLong(); | 586 | start = (time_t) value.toLong(); |
556 | break; | 587 | break; |
557 | } | 588 | } |
558 | case FREnd: { | 589 | case FREnd: { |
559 | end = ( (time_t) value.toLong() ); | 590 | end = ( (time_t) value.toLong() ); |
560 | break; | 591 | break; |
561 | } | 592 | } |
562 | case FNote: | 593 | case FNote: |
563 | e.setNote( value ); | 594 | e.setNote( value ); |
564 | break; | 595 | break; |
565 | case FCreated: | 596 | case FCreated: |
566 | created = value.toInt(); | 597 | created = value.toInt(); |
567 | break; | 598 | break; |
568 | case FRecParent: | 599 | case FRecParent: |
569 | e.setParent( value.toInt() ); | 600 | e.setParent( value.toInt() ); |
570 | break; | 601 | break; |
571 | case FRecChildren:{ | 602 | case FRecChildren:{ |
572 | QStringList list = QStringList::split(' ', value ); | 603 | QStringList list = QStringList::split(' ', value ); |
573 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 604 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
574 | e.addChild( (*it).toInt() ); | 605 | e.addChild( (*it).toInt() ); |
575 | } | 606 | } |
576 | } | 607 | } |
577 | break; | 608 | break; |
578 | case FExceptions:{ | 609 | case FExceptions:{ |
579 | QStringList list = QStringList::split(' ', value ); | 610 | QStringList list = QStringList::split(' ', value ); |
580 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 611 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
581 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); | 612 | QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); |
582 | qWarning("adding exception %s", date.toString().latin1() ); | 613 | qWarning("adding exception %s", date.toString().latin1() ); |
583 | recur()->exceptions().append( date ); | 614 | recur()->exceptions().append( date ); |
584 | } | 615 | } |
585 | } | 616 | } |
586 | break; | 617 | break; |
587 | case FTimeZone: | 618 | case FTimeZone: |
588 | if ( value != "None" ) | 619 | if ( value != "None" ) |
589 | e.setTimeZone( value ); | 620 | e.setTimeZone( value ); |
590 | break; | 621 | break; |
591 | default: | 622 | default: |
592 | break; | 623 | break; |
593 | } | 624 | } |
594 | } | 625 | } |
595 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 626 | QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
596 | { | 627 | { |
597 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); | 628 | QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); |
598 | uint arraycounter = 0; | 629 | uint arraycounter = 0; |
599 | QMap<int, OEvent>::ConstIterator it; | 630 | QMap<int, OEvent>::ConstIterator it; |
600 | 631 | ||
601 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) | 632 | for ( it = m_raw.begin(); it != m_raw.end(); ++it ) |
602 | if ( it.data().match( r ) ) | 633 | if ( it.data().match( r ) ) |
603 | m_currentQuery[arraycounter++] = it.data().uid(); | 634 | m_currentQuery[arraycounter++] = it.data().uid(); |
604 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) | 635 | for ( it = m_rep.begin(); it != m_rep.end(); ++it ) |
605 | if ( it.data().match( r ) ) | 636 | if ( it.data().match( r ) ) |
606 | m_currentQuery[arraycounter++] = it.data().uid(); | 637 | m_currentQuery[arraycounter++] = it.data().uid(); |
607 | 638 | ||
608 | // Shrink to fit.. | 639 | // Shrink to fit.. |
609 | m_currentQuery.resize(arraycounter); | 640 | m_currentQuery.resize(arraycounter); |
610 | 641 | ||
611 | return m_currentQuery; | 642 | return m_currentQuery; |
612 | } | 643 | } |
644 | |||
645 | } | ||
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h index a5cc0fc..29f5f4f 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h | |||
@@ -1,55 +1,86 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H | 29 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H | 30 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H |
3 | 31 | ||
4 | #include <qmap.h> | 32 | #include <qmap.h> |
5 | 33 | ||
6 | #include "odatebookaccessbackend.h" | 34 | #include <opie2/odatebookaccessbackend.h> |
7 | 35 | ||
36 | namespace Opie { | ||
8 | /** | 37 | /** |
9 | * This is the default XML implementation for DateBoook XML storage | 38 | * This is the default XML implementation for DateBoook XML storage |
10 | * It fully implements the interface | 39 | * It fully implements the interface |
11 | * @see ODateBookAccessBackend | 40 | * @see ODateBookAccessBackend |
12 | * @see OPimAccessBackend | 41 | * @see OPimAccessBackend |
13 | */ | 42 | */ |
14 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { | 43 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { |
15 | public: | 44 | public: |
16 | ODateBookAccessBackend_XML( const QString& appName, | 45 | ODateBookAccessBackend_XML( const QString& appName, |
17 | const QString& fileName = QString::null); | 46 | const QString& fileName = QString::null); |
18 | ~ODateBookAccessBackend_XML(); | 47 | ~ODateBookAccessBackend_XML(); |
19 | 48 | ||
20 | bool load(); | 49 | bool load(); |
21 | bool reload(); | 50 | bool reload(); |
22 | bool save(); | 51 | bool save(); |
23 | 52 | ||
24 | QArray<int> allRecords()const; | 53 | QArray<int> allRecords()const; |
25 | QArray<int> matchRegexp(const QRegExp &r) const; | 54 | QArray<int> matchRegexp(const QRegExp &r) const; |
26 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); | 55 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); |
27 | OEvent find( int uid )const; | 56 | OEvent find( int uid )const; |
28 | void clear(); | 57 | void clear(); |
29 | bool add( const OEvent& ev ); | 58 | bool add( const OEvent& ev ); |
30 | bool remove( int uid ); | 59 | bool remove( int uid ); |
31 | bool replace( const OEvent& ev ); | 60 | bool replace( const OEvent& ev ); |
32 | 61 | ||
33 | QArray<UID> rawEvents()const; | 62 | QArray<UID> rawEvents()const; |
34 | QArray<UID> rawRepeats()const; | 63 | QArray<UID> rawRepeats()const; |
35 | QArray<UID> nonRepeats()const; | 64 | QArray<UID> nonRepeats()const; |
36 | 65 | ||
37 | OEvent::ValueList directNonRepeats(); | 66 | OEvent::ValueList directNonRepeats(); |
38 | OEvent::ValueList directRawRepeats(); | 67 | OEvent::ValueList directRawRepeats(); |
39 | 68 | ||
40 | private: | 69 | private: |
41 | bool m_changed :1 ; | 70 | bool m_changed :1 ; |
42 | bool loadFile(); | 71 | bool loadFile(); |
43 | inline void finalizeRecord( OEvent& ev ); | 72 | inline void finalizeRecord( OEvent& ev ); |
44 | inline void setField( OEvent&, int field, const QString& val ); | 73 | inline void setField( OEvent&, int field, const QString& val ); |
45 | QString m_name; | 74 | QString m_name; |
46 | QMap<int, OEvent> m_raw; | 75 | QMap<int, OEvent> m_raw; |
47 | QMap<int, OEvent> m_rep; | 76 | QMap<int, OEvent> m_rep; |
48 | 77 | ||
49 | struct Data; | 78 | struct Data; |
50 | Data* data; | 79 | Data* data; |
51 | class Private; | 80 | class Private; |
52 | Private *d; | 81 | Private *d; |
53 | }; | 82 | }; |
54 | 83 | ||
84 | } | ||
85 | |||
55 | #endif | 86 | #endif |
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h index fd264fc..505358e 100644 --- a/libopie2/opiepim/backend/opimaccessbackend.h +++ b/libopie2/opiepim/backend/opimaccessbackend.h | |||
@@ -1,160 +1,192 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_ACCESS_BACKEND | 29 | #ifndef OPIE_PIM_ACCESS_BACKEND |
2 | #define OPIE_PIM_ACCESS_BACKEND | 30 | #define OPIE_PIM_ACCESS_BACKEND |
3 | 31 | ||
4 | #include <qarray.h> | 32 | #include <qarray.h> |
5 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
6 | 34 | ||
7 | #include <opie/otemplatebase.h> | 35 | #include <opie2/otemplatebase.h> |
8 | #include <opie/opimrecord.h> | 36 | #include <opie2/opimrecord.h> |
9 | 37 | ||
10 | 38 | ||
39 | namespace Opie { | ||
11 | class OPimAccessBackendPrivate; | 40 | class OPimAccessBackendPrivate; |
12 | /** | 41 | /** |
13 | * OPimAccessBackend is the base class | 42 | * OPimAccessBackend is the base class |
14 | * for all private backends | 43 | * for all private backends |
15 | * it operates on OPimRecord as the base class | 44 | * it operates on OPimRecord as the base class |
16 | * and it's responsible for fast manipulating | 45 | * and it's responsible for fast manipulating |
17 | * the resource the implementation takes care | 46 | * the resource the implementation takes care |
18 | * of | 47 | * of |
19 | */ | 48 | */ |
20 | template <class T = OPimRecord> | 49 | template <class T = OPimRecord> |
21 | class OPimAccessBackend { | 50 | class OPimAccessBackend { |
22 | public: | 51 | public: |
23 | typedef OTemplateBase<T> Frontend; | 52 | typedef OTemplateBase<T> Frontend; |
24 | 53 | ||
25 | /** The access hint from the frontend */ | 54 | /** The access hint from the frontend */ |
26 | OPimAccessBackend(int access = 0); | 55 | OPimAccessBackend(int access = 0); |
27 | virtual ~OPimAccessBackend(); | 56 | virtual ~OPimAccessBackend(); |
28 | 57 | ||
29 | /** | 58 | /** |
30 | * load the resource | 59 | * load the resource |
31 | */ | 60 | */ |
32 | virtual bool load() = 0; | 61 | virtual bool load() = 0; |
33 | 62 | ||
34 | /** | 63 | /** |
35 | * reload the resource | 64 | * reload the resource |
36 | */ | 65 | */ |
37 | virtual bool reload() = 0; | 66 | virtual bool reload() = 0; |
38 | 67 | ||
39 | /** | 68 | /** |
40 | * save the resource and | 69 | * save the resource and |
41 | * all it's changes | 70 | * all it's changes |
42 | */ | 71 | */ |
43 | virtual bool save() = 0; | 72 | virtual bool save() = 0; |
44 | 73 | ||
45 | /** | 74 | /** |
46 | * return an array of | 75 | * return an array of |
47 | * all available uids | 76 | * all available uids |
48 | */ | 77 | */ |
49 | virtual QArray<int> allRecords()const = 0; | 78 | virtual QArray<int> allRecords()const = 0; |
50 | 79 | ||
51 | /** | 80 | /** |
52 | * return a List of records | 81 | * return a List of records |
53 | * that match the regex | 82 | * that match the regex |
54 | */ | 83 | */ |
55 | virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; | 84 | virtual QArray<int> matchRegexp(const QRegExp &r) const = 0; |
56 | 85 | ||
57 | /** | 86 | /** |
58 | * queryByExample for T with the given Settings | 87 | * queryByExample for T with the given Settings |
59 | * | 88 | * |
60 | */ | 89 | */ |
61 | virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; | 90 | virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0; |
62 | 91 | ||
63 | /** | 92 | /** |
64 | * find the OPimRecord with uid @param uid | 93 | * find the OPimRecord with uid @param uid |
65 | * returns T and T.isEmpty() if nothing was found | 94 | * returns T and T.isEmpty() if nothing was found |
66 | */ | 95 | */ |
67 | virtual T find(int uid )const = 0; | 96 | virtual T find(int uid )const = 0; |
68 | 97 | ||
69 | virtual T find(int uid, const QArray<int>& items, | 98 | virtual T find(int uid, const QArray<int>& items, |
70 | uint current, typename Frontend::CacheDirection )const ; | 99 | uint current, typename Frontend::CacheDirection )const ; |
71 | /** | 100 | /** |
72 | * clear the back end | 101 | * clear the back end |
73 | */ | 102 | */ |
74 | virtual void clear() = 0; | 103 | virtual void clear() = 0; |
75 | 104 | ||
76 | /** | 105 | /** |
77 | * add T | 106 | * add T |
78 | */ | 107 | */ |
79 | virtual bool add( const T& t ) = 0; | 108 | virtual bool add( const T& t ) = 0; |
80 | 109 | ||
81 | /** | 110 | /** |
82 | * remove | 111 | * remove |
83 | */ | 112 | */ |
84 | virtual bool remove( int uid ) = 0; | 113 | virtual bool remove( int uid ) = 0; |
85 | 114 | ||
86 | /** | 115 | /** |
87 | * replace a record with T.uid() | 116 | * replace a record with T.uid() |
88 | */ | 117 | */ |
89 | virtual bool replace( const T& t ) = 0; | 118 | virtual bool replace( const T& t ) = 0; |
90 | 119 | ||
91 | /* | 120 | /* |
92 | * setTheFrontEnd!!! | 121 | * setTheFrontEnd!!! |
93 | */ | 122 | */ |
94 | void setFrontend( Frontend* front ); | 123 | void setFrontend( Frontend* front ); |
95 | 124 | ||
96 | /** | 125 | /** |
97 | * set the read ahead count | 126 | * set the read ahead count |
98 | */ | 127 | */ |
99 | void setReadAhead( uint count ); | 128 | void setReadAhead( uint count ); |
100 | protected: | 129 | protected: |
101 | int access()const; | 130 | int access()const; |
102 | void cache( const T& t )const; | 131 | void cache( const T& t )const; |
103 | 132 | ||
104 | /** | 133 | /** |
105 | * use a prime number here! | 134 | * use a prime number here! |
106 | */ | 135 | */ |
107 | void setSaneCacheSize( int ); | 136 | void setSaneCacheSize( int ); |
108 | 137 | ||
109 | uint readAhead()const; | 138 | uint readAhead()const; |
110 | 139 | ||
111 | private: | 140 | private: |
112 | OPimAccessBackendPrivate *d; | 141 | OPimAccessBackendPrivate *d; |
113 | Frontend* m_front; | 142 | Frontend* m_front; |
114 | uint m_read; | 143 | uint m_read; |
115 | int m_acc; | 144 | int m_acc; |
116 | 145 | ||
117 | }; | 146 | }; |
118 | 147 | ||
119 | template <class T> | 148 | template <class T> |
120 | OPimAccessBackend<T>::OPimAccessBackend(int acc) | 149 | OPimAccessBackend<T>::OPimAccessBackend(int acc) |
121 | : m_acc( acc ) | 150 | : m_acc( acc ) |
122 | { | 151 | { |
123 | m_front = 0l; | 152 | m_front = 0l; |
124 | } | 153 | } |
125 | template <class T> | 154 | template <class T> |
126 | OPimAccessBackend<T>::~OPimAccessBackend() { | 155 | OPimAccessBackend<T>::~OPimAccessBackend() { |
127 | 156 | ||
128 | } | 157 | } |
129 | template <class T> | 158 | template <class T> |
130 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { | 159 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { |
131 | m_front = fr; | 160 | m_front = fr; |
132 | } | 161 | } |
133 | template <class T> | 162 | template <class T> |
134 | void OPimAccessBackend<T>::cache( const T& t )const { | 163 | void OPimAccessBackend<T>::cache( const T& t )const { |
135 | if (m_front ) | 164 | if (m_front ) |
136 | m_front->cache( t ); | 165 | m_front->cache( t ); |
137 | } | 166 | } |
138 | template <class T> | 167 | template <class T> |
139 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { | 168 | void OPimAccessBackend<T>::setSaneCacheSize( int size) { |
140 | if (m_front ) | 169 | if (m_front ) |
141 | m_front->setSaneCacheSize( size ); | 170 | m_front->setSaneCacheSize( size ); |
142 | } | 171 | } |
143 | template <class T> | 172 | template <class T> |
144 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 173 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
145 | uint, typename Frontend::CacheDirection )const { | 174 | uint, typename Frontend::CacheDirection )const { |
146 | return find( uid ); | 175 | return find( uid ); |
147 | } | 176 | } |
148 | template <class T> | 177 | template <class T> |
149 | void OPimAccessBackend<T>::setReadAhead( uint count ) { | 178 | void OPimAccessBackend<T>::setReadAhead( uint count ) { |
150 | m_read = count; | 179 | m_read = count; |
151 | } | 180 | } |
152 | template <class T> | 181 | template <class T> |
153 | uint OPimAccessBackend<T>::readAhead()const { | 182 | uint OPimAccessBackend<T>::readAhead()const { |
154 | return m_read; | 183 | return m_read; |
155 | } | 184 | } |
156 | template <class T> | 185 | template <class T> |
157 | int OPimAccessBackend<T>::access()const { | 186 | int OPimAccessBackend<T>::access()const { |
158 | return m_acc; | 187 | return m_acc; |
159 | } | 188 | } |
189 | |||
190 | } | ||
191 | |||
160 | #endif | 192 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.cpp b/libopie2/opiepim/backend/otodoaccessbackend.cpp index baaeecc..d27f5ef 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.cpp +++ b/libopie2/opiepim/backend/otodoaccessbackend.cpp | |||
@@ -1,10 +1,41 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | 29 | ||
2 | #include "otodoaccessbackend.h" | 30 | #include <opie2/otodoaccessbackend.h> |
3 | 31 | ||
32 | namespace Opie { | ||
4 | OTodoAccessBackend::OTodoAccessBackend() | 33 | OTodoAccessBackend::OTodoAccessBackend() |
5 | : OPimAccessBackend<OTodo>() | 34 | : OPimAccessBackend<OTodo>() |
6 | { | 35 | { |
7 | } | 36 | } |
8 | OTodoAccessBackend::~OTodoAccessBackend() { | 37 | OTodoAccessBackend::~OTodoAccessBackend() { |
9 | 38 | ||
10 | } | 39 | } |
40 | |||
41 | } | ||
diff --git a/libopie2/opiepim/backend/otodoaccessbackend.h b/libopie2/opiepim/backend/otodoaccessbackend.h index 6be95bc..54b52cc 100644 --- a/libopie2/opiepim/backend/otodoaccessbackend.h +++ b/libopie2/opiepim/backend/otodoaccessbackend.h | |||
@@ -1,28 +1,59 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_TODO_ACCESS_BACKEND_H | 29 | #ifndef OPIE_TODO_ACCESS_BACKEND_H |
2 | #define OPIE_TODO_ACCESS_BACKEND_H | 30 | #define OPIE_TODO_ACCESS_BACKEND_H |
3 | 31 | ||
4 | #include <qbitarray.h> | 32 | #include <qbitarray.h> |
5 | 33 | ||
6 | #include "otodo.h" | 34 | #include <opie2/otodo.h> |
7 | #include "opimaccessbackend.h" | 35 | #include <opie2/opimaccessbackend.h> |
8 | 36 | ||
37 | namespace Opie { | ||
9 | class OTodoAccessBackend : public OPimAccessBackend<OTodo> { | 38 | class OTodoAccessBackend : public OPimAccessBackend<OTodo> { |
10 | public: | 39 | public: |
11 | OTodoAccessBackend(); | 40 | OTodoAccessBackend(); |
12 | ~OTodoAccessBackend(); | 41 | ~OTodoAccessBackend(); |
13 | virtual QArray<int> effectiveToDos( const QDate& start, | 42 | virtual QArray<int> effectiveToDos( const QDate& start, |
14 | const QDate& end, | 43 | const QDate& end, |
15 | bool includeNoDates ) = 0; | 44 | bool includeNoDates ) = 0; |
16 | virtual QArray<int> overDue() = 0; | 45 | virtual QArray<int> overDue() = 0; |
17 | virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, | 46 | virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, |
18 | int cat ) = 0; | 47 | int cat ) = 0; |
19 | virtual void removeAllCompleted() = 0; | 48 | virtual void removeAllCompleted() = 0; |
20 | virtual QBitArray supports()const = 0; | 49 | virtual QBitArray supports()const = 0; |
21 | 50 | ||
22 | private: | 51 | private: |
23 | class Private; | 52 | class Private; |
24 | Private *d; | 53 | Private *d; |
25 | 54 | ||
26 | }; | 55 | }; |
27 | 56 | ||
57 | } | ||
58 | |||
28 | #endif | 59 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 3764c7e..944f82a 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -1,492 +1,523 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | 29 | ||
2 | #include <qdatetime.h> | 30 | #include <qdatetime.h> |
3 | 31 | ||
4 | #include <qpe/global.h> | 32 | #include <qpe/global.h> |
5 | 33 | ||
6 | #include <opie2/osqldriver.h> | 34 | #include <opie2/osqldriver.h> |
7 | #include <opie2/osqlresult.h> | 35 | #include <opie2/osqlresult.h> |
8 | #include <opie2/osqlmanager.h> | 36 | #include <opie2/osqlmanager.h> |
9 | #include <opie2/osqlquery.h> | 37 | #include <opie2/osqlquery.h> |
10 | 38 | ||
11 | #include "otodoaccesssql.h" | 39 | #include <opie2/otodoaccesssql.h> |
12 | #include "opimstate.h" | 40 | #include <opie2/opimstate.h> |
13 | #include "opimnotifymanager.h" | 41 | #include <opie2/opimnotifymanager.h> |
14 | #include "orecur.h" | 42 | #include <opie2/orecur.h> |
15 | 43 | ||
44 | using namespace Opie; | ||
16 | /* | 45 | /* |
17 | * first some query | 46 | * first some query |
18 | * CREATE query | 47 | * CREATE query |
19 | * LOAD query | 48 | * LOAD query |
20 | * INSERT | 49 | * INSERT |
21 | * REMOVE | 50 | * REMOVE |
22 | * CLEAR | 51 | * CLEAR |
23 | */ | 52 | */ |
24 | namespace { | 53 | namespace { |
25 | /** | 54 | /** |
26 | * CreateQuery for the Todolist Table | 55 | * CreateQuery for the Todolist Table |
27 | */ | 56 | */ |
28 | class CreateQuery : public OSQLQuery { | 57 | class CreateQuery : public OSQLQuery { |
29 | public: | 58 | public: |
30 | CreateQuery(); | 59 | CreateQuery(); |
31 | ~CreateQuery(); | 60 | ~CreateQuery(); |
32 | QString query()const; | 61 | QString query()const; |
33 | }; | 62 | }; |
34 | 63 | ||
35 | /** | 64 | /** |
36 | * LoadQuery | 65 | * LoadQuery |
37 | * this one queries for all uids | 66 | * this one queries for all uids |
38 | */ | 67 | */ |
39 | class LoadQuery : public OSQLQuery { | 68 | class LoadQuery : public OSQLQuery { |
40 | public: | 69 | public: |
41 | LoadQuery(); | 70 | LoadQuery(); |
42 | ~LoadQuery(); | 71 | ~LoadQuery(); |
43 | QString query()const; | 72 | QString query()const; |
44 | }; | 73 | }; |
45 | 74 | ||
46 | /** | 75 | /** |
47 | * inserts/adds a OTodo to the table | 76 | * inserts/adds a OTodo to the table |
48 | */ | 77 | */ |
49 | class InsertQuery : public OSQLQuery { | 78 | class InsertQuery : public OSQLQuery { |
50 | public: | 79 | public: |
51 | InsertQuery(const OTodo& ); | 80 | InsertQuery(const OTodo& ); |
52 | ~InsertQuery(); | 81 | ~InsertQuery(); |
53 | QString query()const; | 82 | QString query()const; |
54 | private: | 83 | private: |
55 | OTodo m_todo; | 84 | OTodo m_todo; |
56 | }; | 85 | }; |
57 | 86 | ||
58 | /** | 87 | /** |
59 | * removes one from the table | 88 | * removes one from the table |
60 | */ | 89 | */ |
61 | class RemoveQuery : public OSQLQuery { | 90 | class RemoveQuery : public OSQLQuery { |
62 | public: | 91 | public: |
63 | RemoveQuery(int uid ); | 92 | RemoveQuery(int uid ); |
64 | ~RemoveQuery(); | 93 | ~RemoveQuery(); |
65 | QString query()const; | 94 | QString query()const; |
66 | private: | 95 | private: |
67 | int m_uid; | 96 | int m_uid; |
68 | }; | 97 | }; |
69 | 98 | ||
70 | /** | 99 | /** |
71 | * Clears (delete) a Table | 100 | * Clears (delete) a Table |
72 | */ | 101 | */ |
73 | class ClearQuery : public OSQLQuery { | 102 | class ClearQuery : public OSQLQuery { |
74 | public: | 103 | public: |
75 | ClearQuery(); | 104 | ClearQuery(); |
76 | ~ClearQuery(); | 105 | ~ClearQuery(); |
77 | QString query()const; | 106 | QString query()const; |
78 | 107 | ||
79 | }; | 108 | }; |
80 | 109 | ||
81 | /** | 110 | /** |
82 | * a find query | 111 | * a find query |
83 | */ | 112 | */ |
84 | class FindQuery : public OSQLQuery { | 113 | class FindQuery : public OSQLQuery { |
85 | public: | 114 | public: |
86 | FindQuery(int uid); | 115 | FindQuery(int uid); |
87 | FindQuery(const QArray<int>& ); | 116 | FindQuery(const QArray<int>& ); |
88 | ~FindQuery(); | 117 | ~FindQuery(); |
89 | QString query()const; | 118 | QString query()const; |
90 | private: | 119 | private: |
91 | QString single()const; | 120 | QString single()const; |
92 | QString multi()const; | 121 | QString multi()const; |
93 | QArray<int> m_uids; | 122 | QArray<int> m_uids; |
94 | int m_uid; | 123 | int m_uid; |
95 | }; | 124 | }; |
96 | 125 | ||
97 | /** | 126 | /** |
98 | * overdue query | 127 | * overdue query |
99 | */ | 128 | */ |
100 | class OverDueQuery : public OSQLQuery { | 129 | class OverDueQuery : public OSQLQuery { |
101 | public: | 130 | public: |
102 | OverDueQuery(); | 131 | OverDueQuery(); |
103 | ~OverDueQuery(); | 132 | ~OverDueQuery(); |
104 | QString query()const; | 133 | QString query()const; |
105 | }; | 134 | }; |
106 | class EffQuery : public OSQLQuery { | 135 | class EffQuery : public OSQLQuery { |
107 | public: | 136 | public: |
108 | EffQuery( const QDate&, const QDate&, bool inc ); | 137 | EffQuery( const QDate&, const QDate&, bool inc ); |
109 | ~EffQuery(); | 138 | ~EffQuery(); |
110 | QString query()const; | 139 | QString query()const; |
111 | private: | 140 | private: |
112 | QString with()const; | 141 | QString with()const; |
113 | QString out()const; | 142 | QString out()const; |
114 | QDate m_start; | 143 | QDate m_start; |
115 | QDate m_end; | 144 | QDate m_end; |
116 | bool m_inc :1; | 145 | bool m_inc :1; |
117 | }; | 146 | }; |
118 | 147 | ||
119 | 148 | ||
120 | CreateQuery::CreateQuery() : OSQLQuery() {} | 149 | CreateQuery::CreateQuery() : OSQLQuery() {} |
121 | CreateQuery::~CreateQuery() {} | 150 | CreateQuery::~CreateQuery() {} |
122 | QString CreateQuery::query()const { | 151 | QString CreateQuery::query()const { |
123 | QString qu; | 152 | QString qu; |
124 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; | 153 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
125 | qu += "description, summary, priority, DueDate, progress , state, "; | 154 | qu += "description, summary, priority, DueDate, progress , state, "; |
126 | // This is the recurrance-stuff .. Exceptions are currently not supported (see ORecur.cpp) ! (eilers) | 155 | // This is the recurrance-stuff .. Exceptions are currently not supported (see ORecur.cpp) ! (eilers) |
127 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; | 156 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; |
128 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; | 157 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; |
129 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 158 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
130 | return qu; | 159 | return qu; |
131 | } | 160 | } |
132 | 161 | ||
133 | LoadQuery::LoadQuery() : OSQLQuery() {} | 162 | LoadQuery::LoadQuery() : OSQLQuery() {} |
134 | LoadQuery::~LoadQuery() {} | 163 | LoadQuery::~LoadQuery() {} |
135 | QString LoadQuery::query()const { | 164 | QString LoadQuery::query()const { |
136 | QString qu; | 165 | QString qu; |
137 | // We do not need "distinct" here. The primary key is always unique.. | 166 | // We do not need "distinct" here. The primary key is always unique.. |
138 | //qu += "select distinct uid from todolist"; | 167 | //qu += "select distinct uid from todolist"; |
139 | qu += "select uid from todolist"; | 168 | qu += "select uid from todolist"; |
140 | 169 | ||
141 | return qu; | 170 | return qu; |
142 | } | 171 | } |
143 | 172 | ||
144 | InsertQuery::InsertQuery( const OTodo& todo ) | 173 | InsertQuery::InsertQuery( const OTodo& todo ) |
145 | : OSQLQuery(), m_todo( todo ) { | 174 | : OSQLQuery(), m_todo( todo ) { |
146 | } | 175 | } |
147 | InsertQuery::~InsertQuery() { | 176 | InsertQuery::~InsertQuery() { |
148 | } | 177 | } |
149 | /* | 178 | /* |
150 | * converts from a OTodo to a query | 179 | * converts from a OTodo to a query |
151 | * we leave out X-Ref + Alarms | 180 | * we leave out X-Ref + Alarms |
152 | */ | 181 | */ |
153 | QString InsertQuery::query()const{ | 182 | QString InsertQuery::query()const{ |
154 | 183 | ||
155 | int year, month, day; | 184 | int year, month, day; |
156 | year = month = day = 0; | 185 | year = month = day = 0; |
157 | if (m_todo.hasDueDate() ) { | 186 | if (m_todo.hasDueDate() ) { |
158 | QDate date = m_todo.dueDate(); | 187 | QDate date = m_todo.dueDate(); |
159 | year = date.year(); | 188 | year = date.year(); |
160 | month = date.month(); | 189 | month = date.month(); |
161 | day = date.day(); | 190 | day = date.day(); |
162 | } | 191 | } |
163 | int sYear = 0, sMonth = 0, sDay = 0; | 192 | int sYear = 0, sMonth = 0, sDay = 0; |
164 | if( m_todo.hasStartDate() ){ | 193 | if( m_todo.hasStartDate() ){ |
165 | QDate sDate = m_todo.startDate(); | 194 | QDate sDate = m_todo.startDate(); |
166 | sYear = sDate.year(); | 195 | sYear = sDate.year(); |
167 | sMonth= sDate.month(); | 196 | sMonth= sDate.month(); |
168 | sDay = sDate.day(); | 197 | sDay = sDate.day(); |
169 | } | 198 | } |
170 | 199 | ||
171 | int eYear = 0, eMonth = 0, eDay = 0; | 200 | int eYear = 0, eMonth = 0, eDay = 0; |
172 | if( m_todo.hasCompletedDate() ){ | 201 | if( m_todo.hasCompletedDate() ){ |
173 | QDate eDate = m_todo.completedDate(); | 202 | QDate eDate = m_todo.completedDate(); |
174 | eYear = eDate.year(); | 203 | eYear = eDate.year(); |
175 | eMonth= eDate.month(); | 204 | eMonth= eDate.month(); |
176 | eDay = eDate.day(); | 205 | eDay = eDate.day(); |
177 | } | 206 | } |
178 | QString qu; | 207 | QString qu; |
179 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); | 208 | QMap<int, QString> recMap = m_todo.recurrence().toMap(); |
180 | qu = "insert into todolist VALUES(" | 209 | qu = "insert into todolist VALUES(" |
181 | + QString::number( m_todo.uid() ) + "," | 210 | + QString::number( m_todo.uid() ) + "," |
182 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," | 211 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
183 | + QString::number( m_todo.isCompleted() ) + "," | 212 | + QString::number( m_todo.isCompleted() ) + "," |
184 | + "'" + m_todo.description() + "'" + "," | 213 | + "'" + m_todo.description() + "'" + "," |
185 | + "'" + m_todo.summary() + "'" + "," | 214 | + "'" + m_todo.summary() + "'" + "," |
186 | + QString::number(m_todo.priority() ) + "," | 215 | + QString::number(m_todo.priority() ) + "," |
187 | + "'" + QString::number(year) + "-" | 216 | + "'" + QString::number(year) + "-" |
188 | + QString::number(month) | 217 | + QString::number(month) |
189 | + "-" + QString::number( day ) + "'" + "," | 218 | + "-" + QString::number( day ) + "'" + "," |
190 | + QString::number( m_todo.progress() ) + "," | 219 | + QString::number( m_todo.progress() ) + "," |
191 | + QString::number( m_todo.state().state() ) + "," | 220 | + QString::number( m_todo.state().state() ) + "," |
192 | + "'" + recMap[ ORecur::RType ] + "'" + "," | 221 | + "'" + recMap[ ORecur::RType ] + "'" + "," |
193 | + "'" + recMap[ ORecur::RWeekdays ] + "'" + "," | 222 | + "'" + recMap[ ORecur::RWeekdays ] + "'" + "," |
194 | + "'" + recMap[ ORecur::RPosition ] + "'" + "," | 223 | + "'" + recMap[ ORecur::RPosition ] + "'" + "," |
195 | + "'" + recMap[ ORecur::RFreq ] + "'" + "," | 224 | + "'" + recMap[ ORecur::RFreq ] + "'" + "," |
196 | + "'" + recMap[ ORecur::RHasEndDate ] + "'" + "," | 225 | + "'" + recMap[ ORecur::RHasEndDate ] + "'" + "," |
197 | + "'" + recMap[ ORecur::EndDate ] + "'" + "," | 226 | + "'" + recMap[ ORecur::EndDate ] + "'" + "," |
198 | + "'" + recMap[ ORecur::Created ] + "'" + "," | 227 | + "'" + recMap[ ORecur::Created ] + "'" + "," |
199 | + "'" + recMap[ ORecur::Exceptions ] + "'" + ","; | 228 | + "'" + recMap[ ORecur::Exceptions ] + "'" + ","; |
200 | 229 | ||
201 | if ( m_todo.hasNotifiers() ) { | 230 | if ( m_todo.hasNotifiers() ) { |
202 | OPimNotifyManager manager = m_todo.notifiers(); | 231 | OPimNotifyManager manager = m_todo.notifiers(); |
203 | qu += "'" + manager.remindersToString() + "'" + "," | 232 | qu += "'" + manager.remindersToString() + "'" + "," |
204 | + "'" + manager.alarmsToString() + "'" + ","; | 233 | + "'" + manager.alarmsToString() + "'" + ","; |
205 | } | 234 | } |
206 | else{ | 235 | else{ |
207 | qu += QString( "''" ) + "," | 236 | qu += QString( "''" ) + "," |
208 | + "''" + ","; | 237 | + "''" + ","; |
209 | } | 238 | } |
210 | 239 | ||
211 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) | 240 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) |
212 | + "'" + QString::number(sYear) + "-" | 241 | + "'" + QString::number(sYear) + "-" |
213 | + QString::number(sMonth) | 242 | + QString::number(sMonth) |
214 | + "-" + QString::number(sDay) + "'" + "," | 243 | + "-" + QString::number(sDay) + "'" + "," |
215 | + "'" + QString::number(eYear) + "-" | 244 | + "'" + QString::number(eYear) + "-" |
216 | + QString::number(eMonth) | 245 | + QString::number(eMonth) |
217 | + "-"+QString::number(eDay) + "'" | 246 | + "-"+QString::number(eDay) + "'" |
218 | + ")"; | 247 | + ")"; |
219 | 248 | ||
220 | qWarning("add %s", qu.latin1() ); | 249 | qWarning("add %s", qu.latin1() ); |
221 | return qu; | 250 | return qu; |
222 | } | 251 | } |
223 | 252 | ||
224 | RemoveQuery::RemoveQuery(int uid ) | 253 | RemoveQuery::RemoveQuery(int uid ) |
225 | : OSQLQuery(), m_uid( uid ) {} | 254 | : OSQLQuery(), m_uid( uid ) {} |
226 | RemoveQuery::~RemoveQuery() {} | 255 | RemoveQuery::~RemoveQuery() {} |
227 | QString RemoveQuery::query()const { | 256 | QString RemoveQuery::query()const { |
228 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); | 257 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); |
229 | return qu; | 258 | return qu; |
230 | } | 259 | } |
231 | 260 | ||
232 | 261 | ||
233 | ClearQuery::ClearQuery() | 262 | ClearQuery::ClearQuery() |
234 | : OSQLQuery() {} | 263 | : OSQLQuery() {} |
235 | ClearQuery::~ClearQuery() {} | 264 | ClearQuery::~ClearQuery() {} |
236 | QString ClearQuery::query()const { | 265 | QString ClearQuery::query()const { |
237 | QString qu = "drop table todolist"; | 266 | QString qu = "drop table todolist"; |
238 | return qu; | 267 | return qu; |
239 | } | 268 | } |
240 | FindQuery::FindQuery(int uid) | 269 | FindQuery::FindQuery(int uid) |
241 | : OSQLQuery(), m_uid(uid ) { | 270 | : OSQLQuery(), m_uid(uid ) { |
242 | } | 271 | } |
243 | FindQuery::FindQuery(const QArray<int>& ints) | 272 | FindQuery::FindQuery(const QArray<int>& ints) |
244 | : OSQLQuery(), m_uids(ints){ | 273 | : OSQLQuery(), m_uids(ints){ |
245 | } | 274 | } |
246 | FindQuery::~FindQuery() { | 275 | FindQuery::~FindQuery() { |
247 | } | 276 | } |
248 | QString FindQuery::query()const{ | 277 | QString FindQuery::query()const{ |
249 | if (m_uids.count() == 0 ) | 278 | if (m_uids.count() == 0 ) |
250 | return single(); | 279 | return single(); |
251 | else | 280 | else |
252 | return multi(); | 281 | return multi(); |
253 | } | 282 | } |
254 | QString FindQuery::single()const{ | 283 | QString FindQuery::single()const{ |
255 | QString qu = "select * from todolist where uid = " + QString::number(m_uid); | 284 | QString qu = "select * from todolist where uid = " + QString::number(m_uid); |
256 | return qu; | 285 | return qu; |
257 | } | 286 | } |
258 | QString FindQuery::multi()const { | 287 | QString FindQuery::multi()const { |
259 | QString qu = "select * from todolist where "; | 288 | QString qu = "select * from todolist where "; |
260 | for (uint i = 0; i < m_uids.count(); i++ ) { | 289 | for (uint i = 0; i < m_uids.count(); i++ ) { |
261 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 290 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
262 | } | 291 | } |
263 | qu.remove( qu.length()-2, 2 ); | 292 | qu.remove( qu.length()-2, 2 ); |
264 | return qu; | 293 | return qu; |
265 | } | 294 | } |
266 | 295 | ||
267 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 296 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
268 | OverDueQuery::~OverDueQuery() {} | 297 | OverDueQuery::~OverDueQuery() {} |
269 | QString OverDueQuery::query()const { | 298 | QString OverDueQuery::query()const { |
270 | QDate date = QDate::currentDate(); | 299 | QDate date = QDate::currentDate(); |
271 | QString str; | 300 | QString str; |
272 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); | 301 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); |
273 | 302 | ||
274 | return str; | 303 | return str; |
275 | } | 304 | } |
276 | 305 | ||
277 | 306 | ||
278 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 307 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
279 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 308 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
280 | EffQuery::~EffQuery() {} | 309 | EffQuery::~EffQuery() {} |
281 | QString EffQuery::query()const { | 310 | QString EffQuery::query()const { |
282 | return m_inc ? with() : out(); | 311 | return m_inc ? with() : out(); |
283 | } | 312 | } |
284 | QString EffQuery::with()const { | 313 | QString EffQuery::with()const { |
285 | QString str; | 314 | QString str; |
286 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 315 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
287 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) | 316 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) |
288 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); | 317 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); |
289 | return str; | 318 | return str; |
290 | } | 319 | } |
291 | QString EffQuery::out()const { | 320 | QString EffQuery::out()const { |
292 | QString str; | 321 | QString str; |
293 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 322 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
294 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 323 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
295 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 324 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
296 | 325 | ||
297 | return str; | 326 | return str; |
298 | } | 327 | } |
299 | }; | 328 | }; |
300 | 329 | ||
330 | |||
331 | namespace Opie { | ||
301 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 332 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
302 | : OTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) | 333 | : OTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) |
303 | { | 334 | { |
304 | QString fi = file; | 335 | QString fi = file; |
305 | if ( fi.isEmpty() ) | 336 | if ( fi.isEmpty() ) |
306 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 337 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
307 | OSQLManager man; | 338 | OSQLManager man; |
308 | m_driver = man.standard(); | 339 | m_driver = man.standard(); |
309 | m_driver->setUrl(fi); | 340 | m_driver->setUrl(fi); |
310 | // fillDict(); | 341 | // fillDict(); |
311 | } | 342 | } |
312 | 343 | ||
313 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 344 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
314 | if( m_driver ) | 345 | if( m_driver ) |
315 | delete m_driver; | 346 | delete m_driver; |
316 | } | 347 | } |
317 | 348 | ||
318 | bool OTodoAccessBackendSQL::load(){ | 349 | bool OTodoAccessBackendSQL::load(){ |
319 | if (!m_driver->open() ) | 350 | if (!m_driver->open() ) |
320 | return false; | 351 | return false; |
321 | 352 | ||
322 | CreateQuery creat; | 353 | CreateQuery creat; |
323 | OSQLResult res = m_driver->query(&creat ); | 354 | OSQLResult res = m_driver->query(&creat ); |
324 | 355 | ||
325 | m_dirty = true; | 356 | m_dirty = true; |
326 | return true; | 357 | return true; |
327 | } | 358 | } |
328 | bool OTodoAccessBackendSQL::reload(){ | 359 | bool OTodoAccessBackendSQL::reload(){ |
329 | return load(); | 360 | return load(); |
330 | } | 361 | } |
331 | 362 | ||
332 | bool OTodoAccessBackendSQL::save(){ | 363 | bool OTodoAccessBackendSQL::save(){ |
333 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 364 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
334 | } | 365 | } |
335 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 366 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
336 | if (m_dirty ) | 367 | if (m_dirty ) |
337 | update(); | 368 | update(); |
338 | 369 | ||
339 | return m_uids; | 370 | return m_uids; |
340 | } | 371 | } |
341 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ | 372 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ |
342 | QArray<int> ints(0); | 373 | QArray<int> ints(0); |
343 | return ints; | 374 | return ints; |
344 | } | 375 | } |
345 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 376 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
346 | FindQuery query( uid ); | 377 | FindQuery query( uid ); |
347 | return todo( m_driver->query(&query) ); | 378 | return todo( m_driver->query(&query) ); |
348 | 379 | ||
349 | } | 380 | } |
350 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 381 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
351 | uint cur, Frontend::CacheDirection dir ) const{ | 382 | uint cur, Frontend::CacheDirection dir ) const{ |
352 | uint CACHE = readAhead(); | 383 | uint CACHE = readAhead(); |
353 | qWarning("searching for %d", uid ); | 384 | qWarning("searching for %d", uid ); |
354 | QArray<int> search( CACHE ); | 385 | QArray<int> search( CACHE ); |
355 | uint size =0; | 386 | uint size =0; |
356 | OTodo to; | 387 | OTodo to; |
357 | 388 | ||
358 | // we try to cache CACHE items | 389 | // we try to cache CACHE items |
359 | switch( dir ) { | 390 | switch( dir ) { |
360 | /* forward */ | 391 | /* forward */ |
361 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) | 392 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) |
362 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 393 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
363 | qWarning("size %d %d", size, ints[i] ); | 394 | qWarning("size %d %d", size, ints[i] ); |
364 | search[size] = ints[i]; | 395 | search[size] = ints[i]; |
365 | size++; | 396 | size++; |
366 | } | 397 | } |
367 | break; | 398 | break; |
368 | /* reverse */ | 399 | /* reverse */ |
369 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) | 400 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) |
370 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 401 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
371 | search[size] = ints[i]; | 402 | search[size] = ints[i]; |
372 | size++; | 403 | size++; |
373 | } | 404 | } |
374 | break; | 405 | break; |
375 | } | 406 | } |
376 | search.resize( size ); | 407 | search.resize( size ); |
377 | FindQuery query( search ); | 408 | FindQuery query( search ); |
378 | OSQLResult res = m_driver->query( &query ); | 409 | OSQLResult res = m_driver->query( &query ); |
379 | if ( res.state() != OSQLResult::Success ) | 410 | if ( res.state() != OSQLResult::Success ) |
380 | return to; | 411 | return to; |
381 | 412 | ||
382 | return todo( res ); | 413 | return todo( res ); |
383 | } | 414 | } |
384 | void OTodoAccessBackendSQL::clear() { | 415 | void OTodoAccessBackendSQL::clear() { |
385 | ClearQuery cle; | 416 | ClearQuery cle; |
386 | OSQLResult res = m_driver->query( &cle ); | 417 | OSQLResult res = m_driver->query( &cle ); |
387 | CreateQuery qu; | 418 | CreateQuery qu; |
388 | res = m_driver->query(&qu); | 419 | res = m_driver->query(&qu); |
389 | } | 420 | } |
390 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 421 | bool OTodoAccessBackendSQL::add( const OTodo& t) { |
391 | InsertQuery ins( t ); | 422 | InsertQuery ins( t ); |
392 | OSQLResult res = m_driver->query( &ins ); | 423 | OSQLResult res = m_driver->query( &ins ); |
393 | 424 | ||
394 | if ( res.state() == OSQLResult::Failure ) | 425 | if ( res.state() == OSQLResult::Failure ) |
395 | return false; | 426 | return false; |
396 | int c = m_uids.count(); | 427 | int c = m_uids.count(); |
397 | m_uids.resize( c+1 ); | 428 | m_uids.resize( c+1 ); |
398 | m_uids[c] = t.uid(); | 429 | m_uids[c] = t.uid(); |
399 | 430 | ||
400 | return true; | 431 | return true; |
401 | } | 432 | } |
402 | bool OTodoAccessBackendSQL::remove( int uid ) { | 433 | bool OTodoAccessBackendSQL::remove( int uid ) { |
403 | RemoveQuery rem( uid ); | 434 | RemoveQuery rem( uid ); |
404 | OSQLResult res = m_driver->query(&rem ); | 435 | OSQLResult res = m_driver->query(&rem ); |
405 | 436 | ||
406 | if ( res.state() == OSQLResult::Failure ) | 437 | if ( res.state() == OSQLResult::Failure ) |
407 | return false; | 438 | return false; |
408 | 439 | ||
409 | m_dirty = true; | 440 | m_dirty = true; |
410 | return true; | 441 | return true; |
411 | } | 442 | } |
412 | /* | 443 | /* |
413 | * FIXME better set query | 444 | * FIXME better set query |
414 | * but we need the cache for that | 445 | * but we need the cache for that |
415 | * now we remove | 446 | * now we remove |
416 | */ | 447 | */ |
417 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 448 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
418 | remove( t.uid() ); | 449 | remove( t.uid() ); |
419 | bool b= add(t); | 450 | bool b= add(t); |
420 | m_dirty = false; // we changed some stuff but the UID stayed the same | 451 | m_dirty = false; // we changed some stuff but the UID stayed the same |
421 | return b; | 452 | return b; |
422 | } | 453 | } |
423 | QArray<int> OTodoAccessBackendSQL::overDue() { | 454 | QArray<int> OTodoAccessBackendSQL::overDue() { |
424 | OverDueQuery qu; | 455 | OverDueQuery qu; |
425 | return uids( m_driver->query(&qu ) ); | 456 | return uids( m_driver->query(&qu ) ); |
426 | } | 457 | } |
427 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 458 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
428 | const QDate& t, | 459 | const QDate& t, |
429 | bool u) { | 460 | bool u) { |
430 | EffQuery ef(s, t, u ); | 461 | EffQuery ef(s, t, u ); |
431 | return uids (m_driver->query(&ef) ); | 462 | return uids (m_driver->query(&ef) ); |
432 | } | 463 | } |
433 | /* | 464 | /* |
434 | * | 465 | * |
435 | */ | 466 | */ |
436 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 467 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
437 | int sortFilter, int cat ) { | 468 | int sortFilter, int cat ) { |
438 | qWarning("sorted %d, %d", asc, sortOrder ); | 469 | qWarning("sorted %d, %d", asc, sortOrder ); |
439 | QString query; | 470 | QString query; |
440 | query = "select uid from todolist WHERE "; | 471 | query = "select uid from todolist WHERE "; |
441 | 472 | ||
442 | /* | 473 | /* |
443 | * Sort Filter stuff | 474 | * Sort Filter stuff |
444 | * not that straight forward | 475 | * not that straight forward |
445 | * FIXME: Replace magic numbers | 476 | * FIXME: Replace magic numbers |
446 | * | 477 | * |
447 | */ | 478 | */ |
448 | /* Category */ | 479 | /* Category */ |
449 | if ( sortFilter & 1 ) { | 480 | if ( sortFilter & 1 ) { |
450 | QString str; | 481 | QString str; |
451 | if (cat != 0 ) str = QString::number( cat ); | 482 | if (cat != 0 ) str = QString::number( cat ); |
452 | query += " categories like '%" +str+"%' AND"; | 483 | query += " categories like '%" +str+"%' AND"; |
453 | } | 484 | } |
454 | /* Show only overdue */ | 485 | /* Show only overdue */ |
455 | if ( sortFilter & 2 ) { | 486 | if ( sortFilter & 2 ) { |
456 | QDate date = QDate::currentDate(); | 487 | QDate date = QDate::currentDate(); |
457 | QString due; | 488 | QString due; |
458 | QString base; | 489 | QString base; |
459 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | 490 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); |
460 | query += " " + base + " AND"; | 491 | query += " " + base + " AND"; |
461 | } | 492 | } |
462 | /* not show completed */ | 493 | /* not show completed */ |
463 | if ( sortFilter & 4 ) { | 494 | if ( sortFilter & 4 ) { |
464 | query += " completed = 0 AND"; | 495 | query += " completed = 0 AND"; |
465 | }else{ | 496 | }else{ |
466 | query += " ( completed = 1 OR completed = 0) AND"; | 497 | query += " ( completed = 1 OR completed = 0) AND"; |
467 | } | 498 | } |
468 | /* srtip the end */ | 499 | /* srtip the end */ |
469 | query = query.remove( query.length()-3, 3 ); | 500 | query = query.remove( query.length()-3, 3 ); |
470 | 501 | ||
471 | 502 | ||
472 | /* | 503 | /* |
473 | * sort order stuff | 504 | * sort order stuff |
474 | * quite straight forward | 505 | * quite straight forward |
475 | */ | 506 | */ |
476 | query += "ORDER BY "; | 507 | query += "ORDER BY "; |
477 | switch( sortOrder ) { | 508 | switch( sortOrder ) { |
478 | /* completed */ | 509 | /* completed */ |
479 | case 0: | 510 | case 0: |
480 | query += "completed"; | 511 | query += "completed"; |
481 | break; | 512 | break; |
482 | case 1: | 513 | case 1: |
483 | query += "priority"; | 514 | query += "priority"; |
484 | break; | 515 | break; |
485 | case 2: | 516 | case 2: |
486 | query += "summary"; | 517 | query += "summary"; |
487 | break; | 518 | break; |
488 | case 3: | 519 | case 3: |
489 | query += "DueDate"; | 520 | query += "DueDate"; |
490 | break; | 521 | break; |
491 | } | 522 | } |
492 | 523 | ||
@@ -502,192 +533,194 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
502 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 533 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
503 | if ( str == "0-0-0" ) | 534 | if ( str == "0-0-0" ) |
504 | return false; | 535 | return false; |
505 | else{ | 536 | else{ |
506 | int day, year, month; | 537 | int day, year, month; |
507 | QStringList list = QStringList::split("-", str ); | 538 | QStringList list = QStringList::split("-", str ); |
508 | year = list[0].toInt(); | 539 | year = list[0].toInt(); |
509 | month = list[1].toInt(); | 540 | month = list[1].toInt(); |
510 | day = list[2].toInt(); | 541 | day = list[2].toInt(); |
511 | da.setYMD( year, month, day ); | 542 | da.setYMD( year, month, day ); |
512 | return true; | 543 | return true; |
513 | } | 544 | } |
514 | } | 545 | } |
515 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 546 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
516 | if ( res.state() == OSQLResult::Failure ) { | 547 | if ( res.state() == OSQLResult::Failure ) { |
517 | OTodo to; | 548 | OTodo to; |
518 | return to; | 549 | return to; |
519 | } | 550 | } |
520 | 551 | ||
521 | OSQLResultItem::ValueList list = res.results(); | 552 | OSQLResultItem::ValueList list = res.results(); |
522 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 553 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
523 | qWarning("todo1"); | 554 | qWarning("todo1"); |
524 | OTodo to = todo( (*it) ); | 555 | OTodo to = todo( (*it) ); |
525 | cache( to ); | 556 | cache( to ); |
526 | ++it; | 557 | ++it; |
527 | 558 | ||
528 | for ( ; it != list.end(); ++it ) { | 559 | for ( ; it != list.end(); ++it ) { |
529 | qWarning("caching"); | 560 | qWarning("caching"); |
530 | cache( todo( (*it) ) ); | 561 | cache( todo( (*it) ) ); |
531 | } | 562 | } |
532 | return to; | 563 | return to; |
533 | } | 564 | } |
534 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 565 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
535 | qWarning("todo"); | 566 | qWarning("todo"); |
536 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 567 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
537 | hasDueDate = date( dueDate, item.data("DueDate") ); | 568 | hasDueDate = date( dueDate, item.data("DueDate") ); |
538 | QStringList cats = QStringList::split(";", item.data("categories") ); | 569 | QStringList cats = QStringList::split(";", item.data("categories") ); |
539 | 570 | ||
540 | qWarning("Item is completed: %d", item.data("completed").toInt() ); | 571 | qWarning("Item is completed: %d", item.data("completed").toInt() ); |
541 | 572 | ||
542 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 573 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
543 | cats, item.data("summary"), item.data("description"), | 574 | cats, item.data("summary"), item.data("description"), |
544 | item.data("progress").toUShort(), hasDueDate, dueDate, | 575 | item.data("progress").toUShort(), hasDueDate, dueDate, |
545 | item.data("uid").toInt() ); | 576 | item.data("uid").toInt() ); |
546 | 577 | ||
547 | bool isOk; | 578 | bool isOk; |
548 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | 579 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); |
549 | if ( isOk ) | 580 | if ( isOk ) |
550 | to.setPriority( prioInt ); | 581 | to.setPriority( prioInt ); |
551 | 582 | ||
552 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | 583 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); |
553 | hasStartDate = date( startDate, item.data("startdate") ); | 584 | hasStartDate = date( startDate, item.data("startdate") ); |
554 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); | 585 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); |
555 | hasCompletedDate = date( completedDate, item.data("completeddate") ); | 586 | hasCompletedDate = date( completedDate, item.data("completeddate") ); |
556 | 587 | ||
557 | if ( hasStartDate ) | 588 | if ( hasStartDate ) |
558 | to.setStartDate( startDate ); | 589 | to.setStartDate( startDate ); |
559 | if ( hasCompletedDate ) | 590 | if ( hasCompletedDate ) |
560 | to.setCompletedDate( completedDate ); | 591 | to.setCompletedDate( completedDate ); |
561 | 592 | ||
562 | OPimNotifyManager& manager = to.notifiers(); | 593 | OPimNotifyManager& manager = to.notifiers(); |
563 | manager.alarmsFromString( item.data("alarms") ); | 594 | manager.alarmsFromString( item.data("alarms") ); |
564 | manager.remindersFromString( item.data("reminders") ); | 595 | manager.remindersFromString( item.data("reminders") ); |
565 | 596 | ||
566 | OPimState pimState; | 597 | OPimState pimState; |
567 | pimState.setState( QString( item.data("state") ).toInt() ); | 598 | pimState.setState( QString( item.data("state") ).toInt() ); |
568 | to.setState( pimState ); | 599 | to.setState( pimState ); |
569 | 600 | ||
570 | QMap<int, QString> recMap; | 601 | QMap<int, QString> recMap; |
571 | recMap.insert( ORecur::RType , item.data("RType") ); | 602 | recMap.insert( ORecur::RType , item.data("RType") ); |
572 | recMap.insert( ORecur::RWeekdays , item.data("RWeekdays") ); | 603 | recMap.insert( ORecur::RWeekdays , item.data("RWeekdays") ); |
573 | recMap.insert( ORecur::RPosition , item.data("RPosition") ); | 604 | recMap.insert( ORecur::RPosition , item.data("RPosition") ); |
574 | recMap.insert( ORecur::RFreq , item.data("RFreq") ); | 605 | recMap.insert( ORecur::RFreq , item.data("RFreq") ); |
575 | recMap.insert( ORecur::RHasEndDate, item.data("RHasEndDate") ); | 606 | recMap.insert( ORecur::RHasEndDate, item.data("RHasEndDate") ); |
576 | recMap.insert( ORecur::EndDate , item.data("EndDate") ); | 607 | recMap.insert( ORecur::EndDate , item.data("EndDate") ); |
577 | recMap.insert( ORecur::Created , item.data("Created") ); | 608 | recMap.insert( ORecur::Created , item.data("Created") ); |
578 | recMap.insert( ORecur::Exceptions , item.data("Exceptions") ); | 609 | recMap.insert( ORecur::Exceptions , item.data("Exceptions") ); |
579 | 610 | ||
580 | ORecur recur; | 611 | ORecur recur; |
581 | recur.fromMap( recMap ); | 612 | recur.fromMap( recMap ); |
582 | to.setRecurrence( recur ); | 613 | to.setRecurrence( recur ); |
583 | 614 | ||
584 | return to; | 615 | return to; |
585 | } | 616 | } |
586 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 617 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
587 | FindQuery find( uid ); | 618 | FindQuery find( uid ); |
588 | return todo( m_driver->query(&find) ); | 619 | return todo( m_driver->query(&find) ); |
589 | } | 620 | } |
590 | /* | 621 | /* |
591 | * update the dict | 622 | * update the dict |
592 | */ | 623 | */ |
593 | void OTodoAccessBackendSQL::fillDict() { | 624 | void OTodoAccessBackendSQL::fillDict() { |
594 | /* initialize dict */ | 625 | /* initialize dict */ |
595 | /* | 626 | /* |
596 | * UPDATE dict if you change anything!!! | 627 | * UPDATE dict if you change anything!!! |
597 | * FIXME: Isn't this dict obsolete ? (eilers) | 628 | * FIXME: Isn't this dict obsolete ? (eilers) |
598 | */ | 629 | */ |
599 | m_dict.setAutoDelete( TRUE ); | 630 | m_dict.setAutoDelete( TRUE ); |
600 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 631 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
601 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 632 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
602 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 633 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
603 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 634 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
604 | m_dict.insert("Description" , new int(OTodo::Description) ); | 635 | m_dict.insert("Description" , new int(OTodo::Description) ); |
605 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 636 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
606 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 637 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
607 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 638 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
608 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 639 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
609 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 640 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
610 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 641 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
611 | m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) | 642 | m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) |
612 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 643 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
613 | // m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) | 644 | // m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) |
614 | // m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) | 645 | // m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) |
615 | } | 646 | } |
616 | /* | 647 | /* |
617 | * need to be const so let's fool the | 648 | * need to be const so let's fool the |
618 | * compiler :( | 649 | * compiler :( |
619 | */ | 650 | */ |
620 | void OTodoAccessBackendSQL::update()const { | 651 | void OTodoAccessBackendSQL::update()const { |
621 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | 652 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; |
622 | LoadQuery lo; | 653 | LoadQuery lo; |
623 | OSQLResult res = m_driver->query(&lo); | 654 | OSQLResult res = m_driver->query(&lo); |
624 | if ( res.state() != OSQLResult::Success ) | 655 | if ( res.state() != OSQLResult::Success ) |
625 | return; | 656 | return; |
626 | 657 | ||
627 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); | 658 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
628 | } | 659 | } |
629 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 660 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
630 | 661 | ||
631 | OSQLResultItem::ValueList list = res.results(); | 662 | OSQLResultItem::ValueList list = res.results(); |
632 | OSQLResultItem::ValueList::Iterator it; | 663 | OSQLResultItem::ValueList::Iterator it; |
633 | QArray<int> ints(list.count() ); | 664 | QArray<int> ints(list.count() ); |
634 | qWarning(" count = %d", list.count() ); | 665 | qWarning(" count = %d", list.count() ); |
635 | 666 | ||
636 | int i = 0; | 667 | int i = 0; |
637 | for (it = list.begin(); it != list.end(); ++it ) { | 668 | for (it = list.begin(); it != list.end(); ++it ) { |
638 | ints[i] = (*it).data("uid").toInt(); | 669 | ints[i] = (*it).data("uid").toInt(); |
639 | i++; | 670 | i++; |
640 | } | 671 | } |
641 | return ints; | 672 | return ints; |
642 | } | 673 | } |
643 | 674 | ||
644 | QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | 675 | QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const |
645 | { | 676 | { |
646 | 677 | ||
647 | #warning OTodoAccessBackendSQL::matchRegexp() not implemented !! | 678 | #warning OTodoAccessBackendSQL::matchRegexp() not implemented !! |
648 | 679 | ||
649 | #if 0 | 680 | #if 0 |
650 | 681 | ||
651 | Copied from xml-backend by not adapted to sql (eilers) | 682 | Copied from xml-backend by not adapted to sql (eilers) |
652 | 683 | ||
653 | QArray<int> m_currentQuery( m_events.count() ); | 684 | QArray<int> m_currentQuery( m_events.count() ); |
654 | uint arraycounter = 0; | 685 | uint arraycounter = 0; |
655 | 686 | ||
656 | 687 | ||
657 | 688 | ||
658 | QMap<int, OTodo>::ConstIterator it; | 689 | QMap<int, OTodo>::ConstIterator it; |
659 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 690 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
660 | if ( it.data().match( r ) ) | 691 | if ( it.data().match( r ) ) |
661 | m_currentQuery[arraycounter++] = it.data().uid(); | 692 | m_currentQuery[arraycounter++] = it.data().uid(); |
662 | 693 | ||
663 | } | 694 | } |
664 | // Shrink to fit.. | 695 | // Shrink to fit.. |
665 | m_currentQuery.resize(arraycounter); | 696 | m_currentQuery.resize(arraycounter); |
666 | 697 | ||
667 | return m_currentQuery; | 698 | return m_currentQuery; |
668 | #endif | 699 | #endif |
669 | QArray<int> empty; | 700 | QArray<int> empty; |
670 | return empty; | 701 | return empty; |
671 | } | 702 | } |
672 | QBitArray OTodoAccessBackendSQL::supports()const { | 703 | QBitArray OTodoAccessBackendSQL::supports()const { |
673 | 704 | ||
674 | return sup(); | 705 | return sup(); |
675 | } | 706 | } |
676 | 707 | ||
677 | QBitArray OTodoAccessBackendSQL::sup() const{ | 708 | QBitArray OTodoAccessBackendSQL::sup() const{ |
678 | 709 | ||
679 | QBitArray ar( OTodo::CompletedDate + 1 ); | 710 | QBitArray ar( OTodo::CompletedDate + 1 ); |
680 | ar.fill( true ); | 711 | ar.fill( true ); |
681 | ar[OTodo::CrossReference] = false; | 712 | ar[OTodo::CrossReference] = false; |
682 | ar[OTodo::State ] = false; | 713 | ar[OTodo::State ] = false; |
683 | ar[OTodo::Reminders] = false; | 714 | ar[OTodo::Reminders] = false; |
684 | ar[OTodo::Notifiers] = false; | 715 | ar[OTodo::Notifiers] = false; |
685 | ar[OTodo::Maintainer] = false; | 716 | ar[OTodo::Maintainer] = false; |
686 | 717 | ||
687 | return ar; | 718 | return ar; |
688 | } | 719 | } |
689 | 720 | ||
690 | void OTodoAccessBackendSQL::removeAllCompleted(){ | 721 | void OTodoAccessBackendSQL::removeAllCompleted(){ |
691 | #warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! | 722 | #warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! |
692 | 723 | ||
693 | } | 724 | } |
725 | |||
726 | } | ||
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index 1c55567..1a6f614 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h | |||
@@ -1,56 +1,88 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_ACCESS_SQL_H | 29 | #ifndef OPIE_PIM_ACCESS_SQL_H |
2 | #define OPIE_PIM_ACCESS_SQL_H | 30 | #define OPIE_PIM_ACCESS_SQL_H |
3 | 31 | ||
4 | #include <qasciidict.h> | 32 | #include <qasciidict.h> |
5 | 33 | ||
6 | #include "otodoaccessbackend.h" | 34 | #include <opie2/otodoaccessbackend.h> |
7 | 35 | ||
8 | class OSQLDriver; | 36 | class OSQLDriver; |
9 | class OSQLResult; | 37 | class OSQLResult; |
10 | class OSQLResultItem; | 38 | class OSQLResultItem; |
39 | |||
40 | namespace Opie { | ||
41 | |||
11 | class OTodoAccessBackendSQL : public OTodoAccessBackend { | 42 | class OTodoAccessBackendSQL : public OTodoAccessBackend { |
12 | public: | 43 | public: |
13 | OTodoAccessBackendSQL( const QString& file ); | 44 | OTodoAccessBackendSQL( const QString& file ); |
14 | ~OTodoAccessBackendSQL(); | 45 | ~OTodoAccessBackendSQL(); |
15 | 46 | ||
16 | bool load(); | 47 | bool load(); |
17 | bool reload(); | 48 | bool reload(); |
18 | bool save(); | 49 | bool save(); |
19 | QArray<int> allRecords()const; | 50 | QArray<int> allRecords()const; |
20 | 51 | ||
21 | QArray<int> queryByExample( const OTodo& t, int settings, const QDateTime& d = QDateTime() ); | 52 | QArray<int> queryByExample( const OTodo& t, int settings, const QDateTime& d = QDateTime() ); |
22 | OTodo find(int uid)const; | 53 | OTodo find(int uid)const; |
23 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; | 54 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; |
24 | void clear(); | 55 | void clear(); |
25 | bool add( const OTodo& t ); | 56 | bool add( const OTodo& t ); |
26 | bool remove( int uid ); | 57 | bool remove( int uid ); |
27 | bool replace( const OTodo& t ); | 58 | bool replace( const OTodo& t ); |
28 | 59 | ||
29 | QArray<int> overDue(); | 60 | QArray<int> overDue(); |
30 | QArray<int> effectiveToDos( const QDate& start, | 61 | QArray<int> effectiveToDos( const QDate& start, |
31 | const QDate& end, bool includeNoDates ); | 62 | const QDate& end, bool includeNoDates ); |
32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 63 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
33 | 64 | ||
34 | QBitArray supports()const; | 65 | QBitArray supports()const; |
35 | QArray<int> matchRegexp( const QRegExp &r ) const; | 66 | QArray<int> matchRegexp( const QRegExp &r ) const; |
36 | void removeAllCompleted(); | 67 | void removeAllCompleted(); |
37 | 68 | ||
38 | 69 | ||
39 | private: | 70 | private: |
40 | void update()const; | 71 | void update()const; |
41 | void fillDict(); | 72 | void fillDict(); |
42 | inline bool date( QDate& date, const QString& )const; | 73 | inline bool date( QDate& date, const QString& )const; |
43 | inline OTodo todo( const OSQLResult& )const; | 74 | inline OTodo todo( const OSQLResult& )const; |
44 | inline OTodo todo( OSQLResultItem& )const; | 75 | inline OTodo todo( OSQLResultItem& )const; |
45 | inline QArray<int> uids( const OSQLResult& )const; | 76 | inline QArray<int> uids( const OSQLResult& )const; |
46 | OTodo todo( int uid )const; | 77 | OTodo todo( int uid )const; |
47 | QBitArray sup() const; | 78 | QBitArray sup() const; |
48 | 79 | ||
49 | QAsciiDict<int> m_dict; | 80 | QAsciiDict<int> m_dict; |
50 | OSQLDriver* m_driver; | 81 | OSQLDriver* m_driver; |
51 | QArray<int> m_uids; | 82 | QArray<int> m_uids; |
52 | bool m_dirty : 1; | 83 | bool m_dirty : 1; |
53 | }; | 84 | }; |
54 | 85 | ||
86 | } | ||
55 | 87 | ||
56 | #endif | 88 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp index 6415952..e364ee2 100644 --- a/libopie2/opiepim/backend/otodoaccessvcal.cpp +++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp | |||
@@ -1,249 +1,282 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qfile.h> | 29 | #include <qfile.h> |
2 | 30 | ||
3 | #include <qtopia/private/vobject_p.h> | 31 | #include <qtopia/private/vobject_p.h> |
4 | #include <qtopia/timeconversion.h> | 32 | #include <qtopia/timeconversion.h> |
5 | #include <qtopia/private/qfiledirect_p.h> | 33 | #include <qtopia/private/qfiledirect_p.h> |
6 | 34 | ||
7 | #include "otodoaccessvcal.h" | 35 | #include <opie2/otodoaccessvcal.h> |
36 | |||
37 | using namespace Opie; | ||
8 | 38 | ||
9 | namespace { | 39 | namespace { |
10 | static OTodo eventByVObj( VObject *obj ){ | 40 | static OTodo eventByVObj( VObject *obj ){ |
11 | OTodo event; | 41 | OTodo event; |
12 | VObject *ob; | 42 | VObject *ob; |
13 | QCString name; | 43 | QCString name; |
14 | // no uid, attendees, ... and no fun | 44 | // no uid, attendees, ... and no fun |
15 | // description | 45 | // description |
16 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ | 46 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ |
17 | name = vObjectStringZValue( ob ); | 47 | name = vObjectStringZValue( ob ); |
18 | #if 0 | 48 | #if 0 |
19 | event.setDescription( name ); | 49 | event.setDescription( name ); |
20 | #else | 50 | #else |
21 | event.setSummary( name ); | 51 | event.setSummary( name ); |
22 | #endif | 52 | #endif |
23 | } | 53 | } |
24 | // summary | 54 | // summary |
25 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { | 55 | if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { |
26 | name = vObjectStringZValue( ob ); | 56 | name = vObjectStringZValue( ob ); |
27 | #if 0 | 57 | #if 0 |
28 | event.setSummary( name ); | 58 | event.setSummary( name ); |
29 | #else | 59 | #else |
30 | event.setDescription( name ); | 60 | event.setDescription( name ); |
31 | #endif | 61 | #endif |
32 | } | 62 | } |
33 | // completed | 63 | // completed |
34 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ | 64 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ |
35 | name = vObjectStringZValue( ob ); | 65 | name = vObjectStringZValue( ob ); |
36 | if( name == "COMPLETED" ){ | 66 | if( name == "COMPLETED" ){ |
37 | event.setCompleted( true ); | 67 | event.setCompleted( true ); |
38 | }else{ | 68 | }else{ |
39 | event.setCompleted( false ); | 69 | event.setCompleted( false ); |
40 | } | 70 | } |
41 | }else | 71 | }else |
42 | event.setCompleted( false ); | 72 | event.setCompleted( false ); |
43 | // priority | 73 | // priority |
44 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { | 74 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { |
45 | name = vObjectStringZValue( ob ); | 75 | name = vObjectStringZValue( ob ); |
46 | bool ok; | 76 | bool ok; |
47 | event.setPriority(name.toInt(&ok) ); | 77 | event.setPriority(name.toInt(&ok) ); |
48 | } | 78 | } |
49 | //due date | 79 | //due date |
50 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ | 80 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ |
51 | event.setHasDueDate( true ); | 81 | event.setHasDueDate( true ); |
52 | name = vObjectStringZValue( ob ); | 82 | name = vObjectStringZValue( ob ); |
53 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); | 83 | event.setDueDate( TimeConversion::fromISO8601( name).date() ); |
54 | } | 84 | } |
55 | // categories | 85 | // categories |
56 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ | 86 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ |
57 | name = vObjectStringZValue( ob ); | 87 | name = vObjectStringZValue( ob ); |
58 | qWarning("Categories:%s", name.data() ); | 88 | qWarning("Categories:%s", name.data() ); |
59 | } | 89 | } |
60 | 90 | ||
61 | event.setUid( 1 ); | 91 | event.setUid( 1 ); |
62 | return event; | 92 | return event; |
63 | }; | 93 | }; |
64 | static VObject *vobjByEvent( const OTodo &event ) { | 94 | static VObject *vobjByEvent( const OTodo &event ) { |
65 | VObject *task = newVObject( VCTodoProp ); | 95 | VObject *task = newVObject( VCTodoProp ); |
66 | if( task == 0 ) | 96 | if( task == 0 ) |
67 | return 0l; | 97 | return 0l; |
68 | 98 | ||
69 | if( event.hasDueDate() ) { | 99 | if( event.hasDueDate() ) { |
70 | QTime time(0, 0, 0); | 100 | QTime time(0, 0, 0); |
71 | QDateTime date(event.dueDate(), time ); | 101 | QDateTime date(event.dueDate(), time ); |
72 | addPropValue( task, VCDueProp, | 102 | addPropValue( task, VCDueProp, |
73 | TimeConversion::toISO8601( date ) ); | 103 | TimeConversion::toISO8601( date ) ); |
74 | } | 104 | } |
75 | 105 | ||
76 | if( event.isCompleted() ) | 106 | if( event.isCompleted() ) |
77 | addPropValue( task, VCStatusProp, "COMPLETED"); | 107 | addPropValue( task, VCStatusProp, "COMPLETED"); |
78 | 108 | ||
79 | QString string = QString::number(event.priority() ); | 109 | QString string = QString::number(event.priority() ); |
80 | addPropValue( task, VCPriorityProp, string.local8Bit() ); | 110 | addPropValue( task, VCPriorityProp, string.local8Bit() ); |
81 | 111 | ||
82 | addPropValue( task, VCCategoriesProp, | 112 | addPropValue( task, VCCategoriesProp, |
83 | event.idsToString( event.categories() ).local8Bit() ); | 113 | event.idsToString( event.categories() ).local8Bit() ); |
84 | 114 | ||
85 | #if 0 | 115 | #if 0 |
86 | 116 | ||
87 | // There seems a misrepresentation between summary in otodoevent | 117 | // There seems a misrepresentation between summary in otodoevent |
88 | // and summary in vcard. | 118 | // and summary in vcard. |
89 | // The same with description.. | 119 | // The same with description.. |
90 | // Description is summary and vice versa.. Argh.. (eilers) | 120 | // Description is summary and vice versa.. Argh.. (eilers) |
91 | 121 | ||
92 | 122 | ||
93 | addPropValue( task, VCDescriptionProp, | 123 | addPropValue( task, VCDescriptionProp, |
94 | event.description().local8Bit() ); | 124 | event.description().local8Bit() ); |
95 | 125 | ||
96 | addPropValue( task, VCSummaryProp, | 126 | addPropValue( task, VCSummaryProp, |
97 | event.summary().local8Bit() ); | 127 | event.summary().local8Bit() ); |
98 | 128 | ||
99 | #else | 129 | #else |
100 | addPropValue( task, VCDescriptionProp, | 130 | addPropValue( task, VCDescriptionProp, |
101 | event.summary().local8Bit() ); | 131 | event.summary().local8Bit() ); |
102 | 132 | ||
103 | addPropValue( task, VCSummaryProp, | 133 | addPropValue( task, VCSummaryProp, |
104 | event.description().local8Bit() ); | 134 | event.description().local8Bit() ); |
105 | #endif | 135 | #endif |
106 | return task; | 136 | return task; |
107 | }; | 137 | }; |
108 | } | 138 | } |
109 | 139 | ||
140 | namespace Opie { | ||
110 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) | 141 | OTodoAccessVCal::OTodoAccessVCal( const QString& path ) |
111 | : m_dirty(false), m_file( path ) | 142 | : m_dirty(false), m_file( path ) |
112 | { | 143 | { |
113 | } | 144 | } |
114 | OTodoAccessVCal::~OTodoAccessVCal() { | 145 | OTodoAccessVCal::~OTodoAccessVCal() { |
115 | } | 146 | } |
116 | bool OTodoAccessVCal::load() { | 147 | bool OTodoAccessVCal::load() { |
117 | m_map.clear(); | 148 | m_map.clear(); |
118 | m_dirty = false; | 149 | m_dirty = false; |
119 | 150 | ||
120 | VObject* vcal = 0l; | 151 | VObject* vcal = 0l; |
121 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 152 | vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
122 | if (!vcal ) | 153 | if (!vcal ) |
123 | return false; | 154 | return false; |
124 | 155 | ||
125 | // Iterate over the list | 156 | // Iterate over the list |
126 | VObjectIterator it; | 157 | VObjectIterator it; |
127 | VObject* vobj; | 158 | VObject* vobj; |
128 | 159 | ||
129 | initPropIterator(&it, vcal); | 160 | initPropIterator(&it, vcal); |
130 | 161 | ||
131 | while( moreIteration( &it ) ) { | 162 | while( moreIteration( &it ) ) { |
132 | vobj = ::nextVObject( &it ); | 163 | vobj = ::nextVObject( &it ); |
133 | QCString name = ::vObjectName( vobj ); | 164 | QCString name = ::vObjectName( vobj ); |
134 | if( name == VCTodoProp ){ | 165 | if( name == VCTodoProp ){ |
135 | OTodo to = eventByVObj( vobj ); | 166 | OTodo to = eventByVObj( vobj ); |
136 | m_map.insert( to.uid(), to ); | 167 | m_map.insert( to.uid(), to ); |
137 | } | 168 | } |
138 | } | 169 | } |
139 | 170 | ||
140 | // Should I do a delete vcal? | 171 | // Should I do a delete vcal? |
141 | 172 | ||
142 | return true; | 173 | return true; |
143 | } | 174 | } |
144 | bool OTodoAccessVCal::reload() { | 175 | bool OTodoAccessVCal::reload() { |
145 | return load(); | 176 | return load(); |
146 | } | 177 | } |
147 | bool OTodoAccessVCal::save() { | 178 | bool OTodoAccessVCal::save() { |
148 | if (!m_dirty ) | 179 | if (!m_dirty ) |
149 | return true; | 180 | return true; |
150 | 181 | ||
151 | QFileDirect file( m_file ); | 182 | QFileDirect file( m_file ); |
152 | if (!file.open(IO_WriteOnly ) ) | 183 | if (!file.open(IO_WriteOnly ) ) |
153 | return false; | 184 | return false; |
154 | 185 | ||
155 | VObject *obj; | 186 | VObject *obj; |
156 | obj = newVObject( VCCalProp ); | 187 | obj = newVObject( VCCalProp ); |
157 | addPropValue( obj, VCVersionProp, "1.0" ); | 188 | addPropValue( obj, VCVersionProp, "1.0" ); |
158 | VObject *vo; | 189 | VObject *vo; |
159 | for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 190 | for(QMap<int, OTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
160 | vo = vobjByEvent( it.data() ); | 191 | vo = vobjByEvent( it.data() ); |
161 | addVObjectProp(obj, vo ); | 192 | addVObjectProp(obj, vo ); |
162 | } | 193 | } |
163 | writeVObject( file.directHandle(), obj ); | 194 | writeVObject( file.directHandle(), obj ); |
164 | cleanVObject( obj ); | 195 | cleanVObject( obj ); |
165 | cleanStrTbl(); | 196 | cleanStrTbl(); |
166 | 197 | ||
167 | m_dirty = false; | 198 | m_dirty = false; |
168 | return true; | 199 | return true; |
169 | } | 200 | } |
170 | void OTodoAccessVCal::clear() { | 201 | void OTodoAccessVCal::clear() { |
171 | m_map.clear(); | 202 | m_map.clear(); |
172 | m_dirty = true; | 203 | m_dirty = true; |
173 | } | 204 | } |
174 | bool OTodoAccessVCal::add( const OTodo& to ) { | 205 | bool OTodoAccessVCal::add( const OTodo& to ) { |
175 | m_map.insert( to.uid(), to ); | 206 | m_map.insert( to.uid(), to ); |
176 | m_dirty = true; | 207 | m_dirty = true; |
177 | return true; | 208 | return true; |
178 | } | 209 | } |
179 | bool OTodoAccessVCal::remove( int uid ) { | 210 | bool OTodoAccessVCal::remove( int uid ) { |
180 | m_map.remove( uid ); | 211 | m_map.remove( uid ); |
181 | m_dirty = true; | 212 | m_dirty = true; |
182 | return true; | 213 | return true; |
183 | } | 214 | } |
184 | void OTodoAccessVCal::removeAllCompleted() { | 215 | void OTodoAccessVCal::removeAllCompleted() { |
185 | for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) { | 216 | for ( QMap<int, OTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) { |
186 | if ( (*it).isCompleted() ) | 217 | if ( (*it).isCompleted() ) |
187 | m_map.remove( it ); | 218 | m_map.remove( it ); |
188 | } | 219 | } |
189 | } | 220 | } |
190 | bool OTodoAccessVCal::replace( const OTodo& to ) { | 221 | bool OTodoAccessVCal::replace( const OTodo& to ) { |
191 | m_map.replace( to.uid(), to ); | 222 | m_map.replace( to.uid(), to ); |
192 | m_dirty = true; | 223 | m_dirty = true; |
193 | return true; | 224 | return true; |
194 | } | 225 | } |
195 | OTodo OTodoAccessVCal::find(int uid )const { | 226 | OTodo OTodoAccessVCal::find(int uid )const { |
196 | return m_map[uid]; | 227 | return m_map[uid]; |
197 | } | 228 | } |
198 | QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { | 229 | QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { |
199 | QArray<int> ar(0); | 230 | QArray<int> ar(0); |
200 | return ar; | 231 | return ar; |
201 | } | 232 | } |
202 | QArray<int> OTodoAccessVCal::allRecords()const { | 233 | QArray<int> OTodoAccessVCal::allRecords()const { |
203 | QArray<int> ar( m_map.count() ); | 234 | QArray<int> ar( m_map.count() ); |
204 | QMap<int, OTodo>::ConstIterator it; | 235 | QMap<int, OTodo>::ConstIterator it; |
205 | int i = 0; | 236 | int i = 0; |
206 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 237 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
207 | ar[i] = it.key(); | 238 | ar[i] = it.key(); |
208 | i++; | 239 | i++; |
209 | } | 240 | } |
210 | return ar; | 241 | return ar; |
211 | } | 242 | } |
212 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { | 243 | QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { |
213 | QArray<int> ar(0); | 244 | QArray<int> ar(0); |
214 | return ar; | 245 | return ar; |
215 | } | 246 | } |
216 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { | 247 | QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { |
217 | QArray<int> ar(0); | 248 | QArray<int> ar(0); |
218 | return ar; | 249 | return ar; |
219 | } | 250 | } |
220 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , | 251 | QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , |
221 | const QDate& , | 252 | const QDate& , |
222 | bool ) { | 253 | bool ) { |
223 | QArray<int> ar(0); | 254 | QArray<int> ar(0); |
224 | return ar; | 255 | return ar; |
225 | } | 256 | } |
226 | QArray<int> OTodoAccessVCal::overDue() { | 257 | QArray<int> OTodoAccessVCal::overDue() { |
227 | QArray<int> ar(0); | 258 | QArray<int> ar(0); |
228 | return ar; | 259 | return ar; |
229 | } | 260 | } |
230 | QBitArray OTodoAccessVCal::supports()const { | 261 | QBitArray OTodoAccessVCal::supports()const { |
231 | static QBitArray ar = sup(); | 262 | static QBitArray ar = sup(); |
232 | 263 | ||
233 | return ar; | 264 | return ar; |
234 | } | 265 | } |
235 | QBitArray OTodoAccessVCal::sup() { | 266 | QBitArray OTodoAccessVCal::sup() { |
236 | QBitArray ar ( OTodo::CompletedDate +1 ); | 267 | QBitArray ar ( OTodo::CompletedDate +1 ); |
237 | ar.fill( true ); | 268 | ar.fill( true ); |
238 | 269 | ||
239 | ar[OTodo::CrossReference] = false; | 270 | ar[OTodo::CrossReference] = false; |
240 | ar[OTodo::State ] = false; | 271 | ar[OTodo::State ] = false; |
241 | ar[OTodo::Reminders] = false; | 272 | ar[OTodo::Reminders] = false; |
242 | ar[OTodo::Notifiers] = false; | 273 | ar[OTodo::Notifiers] = false; |
243 | ar[OTodo::Maintainer] = false; | 274 | ar[OTodo::Maintainer] = false; |
244 | ar[OTodo::Progress] = false; | 275 | ar[OTodo::Progress] = false; |
245 | ar[OTodo::Alarms ] = false; | 276 | ar[OTodo::Alarms ] = false; |
246 | ar[OTodo::Recurrence] = false; | 277 | ar[OTodo::Recurrence] = false; |
247 | 278 | ||
248 | return ar; | 279 | return ar; |
249 | } | 280 | } |
281 | |||
282 | } | ||
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.h b/libopie2/opiepim/backend/otodoaccessvcal.h index 2b17147..f9323fb 100644 --- a/libopie2/opiepim/backend/otodoaccessvcal.h +++ b/libopie2/opiepim/backend/otodoaccessvcal.h | |||
@@ -1,40 +1,72 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_OTODO_ACCESS_VCAL_H | 29 | #ifndef OPIE_OTODO_ACCESS_VCAL_H |
2 | #define OPIE_OTODO_ACCESS_VCAL_H | 30 | #define OPIE_OTODO_ACCESS_VCAL_H |
3 | 31 | ||
4 | #include "otodoaccessbackend.h" | 32 | #include <opie2/otodoaccessbackend.h> |
33 | |||
34 | namespace Opie { | ||
5 | 35 | ||
6 | class OTodoAccessVCal : public OTodoAccessBackend { | 36 | class OTodoAccessVCal : public OTodoAccessBackend { |
7 | public: | 37 | public: |
8 | OTodoAccessVCal(const QString& ); | 38 | OTodoAccessVCal(const QString& ); |
9 | ~OTodoAccessVCal(); | 39 | ~OTodoAccessVCal(); |
10 | 40 | ||
11 | bool load(); | 41 | bool load(); |
12 | bool reload(); | 42 | bool reload(); |
13 | bool save(); | 43 | bool save(); |
14 | 44 | ||
15 | QArray<int> allRecords()const; | 45 | QArray<int> allRecords()const; |
16 | QArray<int> matchRegexp(const QRegExp &r) const; | 46 | QArray<int> matchRegexp(const QRegExp &r) const; |
17 | QArray<int> queryByExample( const OTodo& t, int sort, const QDateTime& d = QDateTime() ); | 47 | QArray<int> queryByExample( const OTodo& t, int sort, const QDateTime& d = QDateTime() ); |
18 | QArray<int> effectiveToDos( const QDate& start, | 48 | QArray<int> effectiveToDos( const QDate& start, |
19 | const QDate& end, | 49 | const QDate& end, |
20 | bool includeNoDates ); | 50 | bool includeNoDates ); |
21 | QArray<int> overDue(); | 51 | QArray<int> overDue(); |
22 | QArray<int> sorted( bool asc, int sortOrder, int sortFilter, | 52 | QArray<int> sorted( bool asc, int sortOrder, int sortFilter, |
23 | int cat ); | 53 | int cat ); |
24 | OTodo find(int uid)const; | 54 | OTodo find(int uid)const; |
25 | void clear(); | 55 | void clear(); |
26 | bool add( const OTodo& ); | 56 | bool add( const OTodo& ); |
27 | bool remove( int uid ); | 57 | bool remove( int uid ); |
28 | bool replace( const OTodo& ); | 58 | bool replace( const OTodo& ); |
29 | 59 | ||
30 | void removeAllCompleted(); | 60 | void removeAllCompleted(); |
31 | virtual QBitArray supports()const; | 61 | virtual QBitArray supports()const; |
32 | 62 | ||
33 | private: | 63 | private: |
34 | static QBitArray sup(); | 64 | static QBitArray sup(); |
35 | bool m_dirty : 1; | 65 | bool m_dirty : 1; |
36 | QString m_file; | 66 | QString m_file; |
37 | QMap<int, OTodo> m_map; | 67 | QMap<int, OTodo> m_map; |
38 | }; | 68 | }; |
39 | 69 | ||
70 | } | ||
71 | |||
40 | #endif | 72 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index 4a5cb33..2d50ecd 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -1,260 +1,291 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <errno.h> | 29 | #include <errno.h> |
2 | #include <fcntl.h> | 30 | #include <fcntl.h> |
3 | 31 | ||
4 | #include <sys/mman.h> | 32 | #include <sys/mman.h> |
5 | #include <sys/stat.h> | 33 | #include <sys/stat.h> |
6 | #include <sys/types.h> | 34 | #include <sys/types.h> |
7 | 35 | ||
8 | #include <unistd.h> | 36 | #include <unistd.h> |
9 | 37 | ||
10 | 38 | ||
11 | #include <qfile.h> | 39 | #include <qfile.h> |
12 | #include <qvector.h> | 40 | #include <qvector.h> |
13 | 41 | ||
14 | #include <qpe/global.h> | 42 | #include <qpe/global.h> |
15 | #include <qpe/stringutil.h> | 43 | #include <qpe/stringutil.h> |
16 | #include <qpe/timeconversion.h> | 44 | #include <qpe/timeconversion.h> |
17 | 45 | ||
18 | #include "oconversion.h" | 46 | #include <opie2/oconversion.h> |
19 | #include "opimstate.h" | 47 | #include <opie2/opimstate.h> |
20 | #include "otimezone.h" | 48 | #include <opie2/otimezone.h> |
21 | #include "opimnotifymanager.h" | 49 | #include <opie2/opimnotifymanager.h> |
22 | #include "orecur.h" | 50 | #include <opie2/orecur.h> |
23 | #include "otodoaccessxml.h" | 51 | #include <opie2/otodoaccessxml.h> |
52 | |||
53 | using namespace Opie; | ||
24 | 54 | ||
25 | namespace { | 55 | namespace { |
26 | time_t rp_end; | 56 | time_t rp_end; |
27 | ORecur* rec; | 57 | ORecur* rec; |
28 | ORecur *recur() { | 58 | ORecur *recur() { |
29 | if (!rec ) rec = new ORecur; | 59 | if (!rec ) rec = new ORecur; |
30 | return rec; | 60 | return rec; |
31 | } | 61 | } |
32 | int snd; | 62 | int snd; |
33 | enum MoreAttributes { | 63 | enum MoreAttributes { |
34 | FRType = OTodo::CompletedDate + 2, | 64 | FRType = OTodo::CompletedDate + 2, |
35 | FRWeekdays, | 65 | FRWeekdays, |
36 | FRPosition, | 66 | FRPosition, |
37 | FRFreq, | 67 | FRFreq, |
38 | FRHasEndDate, | 68 | FRHasEndDate, |
39 | FREndDate, | 69 | FREndDate, |
40 | FRStart, | 70 | FRStart, |
41 | FREnd | 71 | FREnd |
42 | }; | 72 | }; |
43 | // FROM TT again | 73 | // FROM TT again |
44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 74 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
45 | { | 75 | { |
46 | char needleChar; | 76 | char needleChar; |
47 | char haystackChar; | 77 | char haystackChar; |
48 | if (!needle || !haystack || !hLen || !nLen) | 78 | if (!needle || !haystack || !hLen || !nLen) |
49 | return 0; | 79 | return 0; |
50 | 80 | ||
51 | const char* hsearch = haystack; | 81 | const char* hsearch = haystack; |
52 | 82 | ||
53 | if ((needleChar = *needle++) != 0) { | 83 | if ((needleChar = *needle++) != 0) { |
54 | nLen--; //(to make up for needle++) | 84 | nLen--; //(to make up for needle++) |
55 | do { | 85 | do { |
56 | do { | 86 | do { |
57 | if ((haystackChar = *hsearch++) == 0) | 87 | if ((haystackChar = *hsearch++) == 0) |
58 | return (0); | 88 | return (0); |
59 | if (hsearch >= haystack + hLen) | 89 | if (hsearch >= haystack + hLen) |
60 | return (0); | 90 | return (0); |
61 | } while (haystackChar != needleChar); | 91 | } while (haystackChar != needleChar); |
62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 92 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
63 | hsearch--; | 93 | hsearch--; |
64 | } | 94 | } |
65 | return ((char *)hsearch); | 95 | return ((char *)hsearch); |
66 | } | 96 | } |
67 | } | 97 | } |
68 | 98 | ||
99 | namespace Opie { | ||
69 | 100 | ||
70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, | 101 | OTodoAccessXML::OTodoAccessXML( const QString& appName, |
71 | const QString& fileName ) | 102 | const QString& fileName ) |
72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) | 103 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) |
73 | { | 104 | { |
74 | if (!fileName.isEmpty() ) | 105 | if (!fileName.isEmpty() ) |
75 | m_file = fileName; | 106 | m_file = fileName; |
76 | else | 107 | else |
77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); | 108 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); |
78 | } | 109 | } |
79 | OTodoAccessXML::~OTodoAccessXML() { | 110 | OTodoAccessXML::~OTodoAccessXML() { |
80 | 111 | ||
81 | } | 112 | } |
82 | bool OTodoAccessXML::load() { | 113 | bool OTodoAccessXML::load() { |
83 | rec = 0; | 114 | rec = 0; |
84 | m_opened = true; | 115 | m_opened = true; |
85 | m_changed = false; | 116 | m_changed = false; |
86 | /* initialize dict */ | 117 | /* initialize dict */ |
87 | /* | 118 | /* |
88 | * UPDATE dict if you change anything!!! | 119 | * UPDATE dict if you change anything!!! |
89 | */ | 120 | */ |
90 | QAsciiDict<int> dict(26); | 121 | QAsciiDict<int> dict(26); |
91 | dict.setAutoDelete( TRUE ); | 122 | dict.setAutoDelete( TRUE ); |
92 | dict.insert("Categories" , new int(OTodo::Category) ); | 123 | dict.insert("Categories" , new int(OTodo::Category) ); |
93 | dict.insert("Uid" , new int(OTodo::Uid) ); | 124 | dict.insert("Uid" , new int(OTodo::Uid) ); |
94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); | 125 | dict.insert("HasDate" , new int(OTodo::HasDate) ); |
95 | dict.insert("Completed" , new int(OTodo::Completed) ); | 126 | dict.insert("Completed" , new int(OTodo::Completed) ); |
96 | dict.insert("Description" , new int(OTodo::Description) ); | 127 | dict.insert("Description" , new int(OTodo::Description) ); |
97 | dict.insert("Summary" , new int(OTodo::Summary) ); | 128 | dict.insert("Summary" , new int(OTodo::Summary) ); |
98 | dict.insert("Priority" , new int(OTodo::Priority) ); | 129 | dict.insert("Priority" , new int(OTodo::Priority) ); |
99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); | 130 | dict.insert("DateDay" , new int(OTodo::DateDay) ); |
100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 131 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); | 132 | dict.insert("DateYear" , new int(OTodo::DateYear) ); |
102 | dict.insert("Progress" , new int(OTodo::Progress) ); | 133 | dict.insert("Progress" , new int(OTodo::Progress) ); |
103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); | 134 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); |
104 | dict.insert("StartDate", new int(OTodo::StartDate) ); | 135 | dict.insert("StartDate", new int(OTodo::StartDate) ); |
105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 136 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
106 | dict.insert("State", new int(OTodo::State) ); | 137 | dict.insert("State", new int(OTodo::State) ); |
107 | dict.insert("Alarms", new int(OTodo::Alarms) ); | 138 | dict.insert("Alarms", new int(OTodo::Alarms) ); |
108 | dict.insert("Reminders", new int(OTodo::Reminders) ); | 139 | dict.insert("Reminders", new int(OTodo::Reminders) ); |
109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); | 140 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); |
110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); | 141 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); |
111 | dict.insert("rtype", new int(FRType) ); | 142 | dict.insert("rtype", new int(FRType) ); |
112 | dict.insert("rweekdays", new int(FRWeekdays) ); | 143 | dict.insert("rweekdays", new int(FRWeekdays) ); |
113 | dict.insert("rposition", new int(FRPosition) ); | 144 | dict.insert("rposition", new int(FRPosition) ); |
114 | dict.insert("rfreq", new int(FRFreq) ); | 145 | dict.insert("rfreq", new int(FRFreq) ); |
115 | dict.insert("start", new int(FRStart) ); | 146 | dict.insert("start", new int(FRStart) ); |
116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); | 147 | dict.insert("rhasenddate", new int(FRHasEndDate) ); |
117 | dict.insert("enddt", new int(FREndDate) ); | 148 | dict.insert("enddt", new int(FREndDate) ); |
118 | 149 | ||
119 | // here the custom XML parser from TT it's GPL | 150 | // here the custom XML parser from TT it's GPL |
120 | // but we want to push OpiePIM... to TT..... | 151 | // but we want to push OpiePIM... to TT..... |
121 | // mmap part from zecke :) | 152 | // mmap part from zecke :) |
122 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); | 153 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); |
123 | struct stat attribut; | 154 | struct stat attribut; |
124 | if ( fd < 0 ) return false; | 155 | if ( fd < 0 ) return false; |
125 | 156 | ||
126 | if ( fstat(fd, &attribut ) == -1 ) { | 157 | if ( fstat(fd, &attribut ) == -1 ) { |
127 | ::close( fd ); | 158 | ::close( fd ); |
128 | return false; | 159 | return false; |
129 | } | 160 | } |
130 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 161 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
131 | if ( map_addr == ( (caddr_t)-1) ) { | 162 | if ( map_addr == ( (caddr_t)-1) ) { |
132 | ::close(fd ); | 163 | ::close(fd ); |
133 | return false; | 164 | return false; |
134 | } | 165 | } |
135 | /* advise the kernel who we want to read it */ | 166 | /* advise the kernel who we want to read it */ |
136 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); | 167 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); |
137 | /* we do not the file any more */ | 168 | /* we do not the file any more */ |
138 | ::close( fd ); | 169 | ::close( fd ); |
139 | 170 | ||
140 | char* dt = (char*)map_addr; | 171 | char* dt = (char*)map_addr; |
141 | int len = attribut.st_size; | 172 | int len = attribut.st_size; |
142 | int i = 0; | 173 | int i = 0; |
143 | char *point; | 174 | char *point; |
144 | const char* collectionString = "<Task "; | 175 | const char* collectionString = "<Task "; |
145 | int strLen = strlen(collectionString); | 176 | int strLen = strlen(collectionString); |
146 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { | 177 | while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { |
147 | i = point -dt; | 178 | i = point -dt; |
148 | i+= strLen; | 179 | i+= strLen; |
149 | qWarning("Found a start at %d %d", i, (point-dt) ); | 180 | qWarning("Found a start at %d %d", i, (point-dt) ); |
150 | 181 | ||
151 | OTodo ev; | 182 | OTodo ev; |
152 | m_year = m_month = m_day = 0; | 183 | m_year = m_month = m_day = 0; |
153 | 184 | ||
154 | while ( TRUE ) { | 185 | while ( TRUE ) { |
155 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 186 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
156 | ++i; | 187 | ++i; |
157 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 188 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
158 | break; | 189 | break; |
159 | 190 | ||
160 | // we have another attribute, read it. | 191 | // we have another attribute, read it. |
161 | int j = i; | 192 | int j = i; |
162 | while ( j < len && dt[j] != '=' ) | 193 | while ( j < len && dt[j] != '=' ) |
163 | ++j; | 194 | ++j; |
164 | QCString attr( dt+i, j-i+1); | 195 | QCString attr( dt+i, j-i+1); |
165 | 196 | ||
166 | i = ++j; // skip = | 197 | i = ++j; // skip = |
167 | 198 | ||
168 | // find the start of quotes | 199 | // find the start of quotes |
169 | while ( i < len && dt[i] != '"' ) | 200 | while ( i < len && dt[i] != '"' ) |
170 | ++i; | 201 | ++i; |
171 | j = ++i; | 202 | j = ++i; |
172 | 203 | ||
173 | bool haveUtf = FALSE; | 204 | bool haveUtf = FALSE; |
174 | bool haveEnt = FALSE; | 205 | bool haveEnt = FALSE; |
175 | while ( j < len && dt[j] != '"' ) { | 206 | while ( j < len && dt[j] != '"' ) { |
176 | if ( ((unsigned char)dt[j]) > 0x7f ) | 207 | if ( ((unsigned char)dt[j]) > 0x7f ) |
177 | haveUtf = TRUE; | 208 | haveUtf = TRUE; |
178 | if ( dt[j] == '&' ) | 209 | if ( dt[j] == '&' ) |
179 | haveEnt = TRUE; | 210 | haveEnt = TRUE; |
180 | ++j; | 211 | ++j; |
181 | } | 212 | } |
182 | if ( i == j ) { | 213 | if ( i == j ) { |
183 | // empty value | 214 | // empty value |
184 | i = j + 1; | 215 | i = j + 1; |
185 | continue; | 216 | continue; |
186 | } | 217 | } |
187 | 218 | ||
188 | QCString value( dt+i, j-i+1 ); | 219 | QCString value( dt+i, j-i+1 ); |
189 | i = j + 1; | 220 | i = j + 1; |
190 | 221 | ||
191 | QString str = (haveUtf ? QString::fromUtf8( value ) | 222 | QString str = (haveUtf ? QString::fromUtf8( value ) |
192 | : QString::fromLatin1( value ) ); | 223 | : QString::fromLatin1( value ) ); |
193 | if ( haveEnt ) | 224 | if ( haveEnt ) |
194 | str = Qtopia::plainString( str ); | 225 | str = Qtopia::plainString( str ); |
195 | 226 | ||
196 | /* | 227 | /* |
197 | * add key + value | 228 | * add key + value |
198 | */ | 229 | */ |
199 | todo( &dict, ev, attr, str ); | 230 | todo( &dict, ev, attr, str ); |
200 | 231 | ||
201 | } | 232 | } |
202 | /* | 233 | /* |
203 | * now add it | 234 | * now add it |
204 | */ | 235 | */ |
205 | qWarning("End at %d", i ); | 236 | qWarning("End at %d", i ); |
206 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { | 237 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { |
207 | ev.setUid( 1 ); | 238 | ev.setUid( 1 ); |
208 | m_changed = true; | 239 | m_changed = true; |
209 | } | 240 | } |
210 | if ( ev.hasDueDate() ) { | 241 | if ( ev.hasDueDate() ) { |
211 | ev.setDueDate( QDate(m_year, m_month, m_day) ); | 242 | ev.setDueDate( QDate(m_year, m_month, m_day) ); |
212 | } | 243 | } |
213 | if ( rec && rec->doesRecur() ) { | 244 | if ( rec && rec->doesRecur() ) { |
214 | OTimeZone utc = OTimeZone::utc(); | 245 | OTimeZone utc = OTimeZone::utc(); |
215 | ORecur recu( *rec ); // call copy c'tor | 246 | ORecur recu( *rec ); // call copy c'tor |
216 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); | 247 | recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); |
217 | recu.setStart( ev.dueDate() ); | 248 | recu.setStart( ev.dueDate() ); |
218 | ev.setRecurrence( recu ); | 249 | ev.setRecurrence( recu ); |
219 | } | 250 | } |
220 | m_events.insert(ev.uid(), ev ); | 251 | m_events.insert(ev.uid(), ev ); |
221 | m_year = m_month = m_day = -1; | 252 | m_year = m_month = m_day = -1; |
222 | delete rec; | 253 | delete rec; |
223 | rec = 0; | 254 | rec = 0; |
224 | } | 255 | } |
225 | 256 | ||
226 | munmap(map_addr, attribut.st_size ); | 257 | munmap(map_addr, attribut.st_size ); |
227 | 258 | ||
228 | qWarning("counts %d records loaded!", m_events.count() ); | 259 | qWarning("counts %d records loaded!", m_events.count() ); |
229 | return true; | 260 | return true; |
230 | } | 261 | } |
231 | bool OTodoAccessXML::reload() { | 262 | bool OTodoAccessXML::reload() { |
232 | m_events.clear(); | 263 | m_events.clear(); |
233 | return load(); | 264 | return load(); |
234 | } | 265 | } |
235 | bool OTodoAccessXML::save() { | 266 | bool OTodoAccessXML::save() { |
236 | // qWarning("saving"); | 267 | // qWarning("saving"); |
237 | if (!m_opened || !m_changed ) { | 268 | if (!m_opened || !m_changed ) { |
238 | // qWarning("not saving"); | 269 | // qWarning("not saving"); |
239 | return true; | 270 | return true; |
240 | } | 271 | } |
241 | QString strNewFile = m_file + ".new"; | 272 | QString strNewFile = m_file + ".new"; |
242 | QFile f( strNewFile ); | 273 | QFile f( strNewFile ); |
243 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 274 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
244 | return false; | 275 | return false; |
245 | 276 | ||
246 | int written; | 277 | int written; |
247 | QString out; | 278 | QString out; |
248 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 279 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
249 | 280 | ||
250 | // for all todos | 281 | // for all todos |
251 | QMap<int, OTodo>::Iterator it; | 282 | QMap<int, OTodo>::Iterator it; |
252 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 283 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
253 | out+= "<Task " + toString( (*it) ) + " />\n"; | 284 | out+= "<Task " + toString( (*it) ) + " />\n"; |
254 | QCString cstr = out.utf8(); | 285 | QCString cstr = out.utf8(); |
255 | written = f.writeBlock( cstr.data(), cstr.length() ); | 286 | written = f.writeBlock( cstr.data(), cstr.length() ); |
256 | 287 | ||
257 | /* less written then we wanted */ | 288 | /* less written then we wanted */ |
258 | if ( written != (int)cstr.length() ) { | 289 | if ( written != (int)cstr.length() ) { |
259 | f.close(); | 290 | f.close(); |
260 | QFile::remove( strNewFile ); | 291 | QFile::remove( strNewFile ); |
@@ -685,192 +716,194 @@ public: | |||
685 | QString string( const OTodo& todo) { | 716 | QString string( const OTodo& todo) { |
686 | return todo.summary().isEmpty() ? | 717 | return todo.summary().isEmpty() ? |
687 | todo.description().left(20 ) : | 718 | todo.description().left(20 ) : |
688 | todo.summary(); | 719 | todo.summary(); |
689 | } | 720 | } |
690 | /** | 721 | /** |
691 | * we take the sortorder( switch on it ) | 722 | * we take the sortorder( switch on it ) |
692 | * | 723 | * |
693 | */ | 724 | */ |
694 | int compareItems( Item d1, Item d2 ) { | 725 | int compareItems( Item d1, Item d2 ) { |
695 | bool seComp, sePrio, seDesc, seDeadline; | 726 | bool seComp, sePrio, seDesc, seDeadline; |
696 | seComp = sePrio = seDeadline = seDesc = false; | 727 | seComp = sePrio = seDeadline = seDesc = false; |
697 | int ret =0; | 728 | int ret =0; |
698 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; | 729 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; |
699 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; | 730 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; |
700 | 731 | ||
701 | /* same item */ | 732 | /* same item */ |
702 | if ( con1->todo.uid() == con2->todo.uid() ) | 733 | if ( con1->todo.uid() == con2->todo.uid() ) |
703 | return 0; | 734 | return 0; |
704 | 735 | ||
705 | switch ( m_sort ) { | 736 | switch ( m_sort ) { |
706 | /* completed */ | 737 | /* completed */ |
707 | case 0: { | 738 | case 0: { |
708 | ret = completed( con1->todo, con2->todo ); | 739 | ret = completed( con1->todo, con2->todo ); |
709 | seComp = TRUE; | 740 | seComp = TRUE; |
710 | break; | 741 | break; |
711 | } | 742 | } |
712 | /* priority */ | 743 | /* priority */ |
713 | case 1: { | 744 | case 1: { |
714 | ret = priority( con1->todo, con2->todo ); | 745 | ret = priority( con1->todo, con2->todo ); |
715 | sePrio = TRUE; | 746 | sePrio = TRUE; |
716 | break; | 747 | break; |
717 | } | 748 | } |
718 | /* description */ | 749 | /* description */ |
719 | case 2: { | 750 | case 2: { |
720 | ret = description( con1->todo, con2->todo ); | 751 | ret = description( con1->todo, con2->todo ); |
721 | seDesc = TRUE; | 752 | seDesc = TRUE; |
722 | break; | 753 | break; |
723 | } | 754 | } |
724 | /* deadline */ | 755 | /* deadline */ |
725 | case 3: { | 756 | case 3: { |
726 | ret = deadline( con1->todo, con2->todo ); | 757 | ret = deadline( con1->todo, con2->todo ); |
727 | seDeadline = TRUE; | 758 | seDeadline = TRUE; |
728 | break; | 759 | break; |
729 | } | 760 | } |
730 | default: | 761 | default: |
731 | ret = 0; | 762 | ret = 0; |
732 | break; | 763 | break; |
733 | }; | 764 | }; |
734 | /* | 765 | /* |
735 | * FIXME do better sorting if the first sort criteria | 766 | * FIXME do better sorting if the first sort criteria |
736 | * ret equals 0 start with complete and so on... | 767 | * ret equals 0 start with complete and so on... |
737 | */ | 768 | */ |
738 | 769 | ||
739 | /* twist it we're not ascending*/ | 770 | /* twist it we're not ascending*/ |
740 | if (!m_asc) | 771 | if (!m_asc) |
741 | ret = ret * -1; | 772 | ret = ret * -1; |
742 | 773 | ||
743 | if ( ret ) | 774 | if ( ret ) |
744 | return ret; | 775 | return ret; |
745 | 776 | ||
746 | // default did not gave difference let's try it other way around | 777 | // default did not gave difference let's try it other way around |
747 | /* | 778 | /* |
748 | * General try if already checked if not test | 779 | * General try if already checked if not test |
749 | * and return | 780 | * and return |
750 | * 1.Completed | 781 | * 1.Completed |
751 | * 2.Priority | 782 | * 2.Priority |
752 | * 3.Description | 783 | * 3.Description |
753 | * 4.DueDate | 784 | * 4.DueDate |
754 | */ | 785 | */ |
755 | if (!seComp ) { | 786 | if (!seComp ) { |
756 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { | 787 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { |
757 | if (!m_asc ) ret *= -1; | 788 | if (!m_asc ) ret *= -1; |
758 | return ret; | 789 | return ret; |
759 | } | 790 | } |
760 | } | 791 | } |
761 | if (!sePrio ) { | 792 | if (!sePrio ) { |
762 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { | 793 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { |
763 | if (!m_asc ) ret *= -1; | 794 | if (!m_asc ) ret *= -1; |
764 | return ret; | 795 | return ret; |
765 | } | 796 | } |
766 | } | 797 | } |
767 | if (!seDesc ) { | 798 | if (!seDesc ) { |
768 | if ( (ret = description(con1->todo, con2->todo ) ) ) { | 799 | if ( (ret = description(con1->todo, con2->todo ) ) ) { |
769 | if (!m_asc) ret *= -1; | 800 | if (!m_asc) ret *= -1; |
770 | return ret; | 801 | return ret; |
771 | } | 802 | } |
772 | } | 803 | } |
773 | if (!seDeadline) { | 804 | if (!seDeadline) { |
774 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { | 805 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { |
775 | if (!m_asc) ret *= -1; | 806 | if (!m_asc) ret *= -1; |
776 | return ret; | 807 | return ret; |
777 | } | 808 | } |
778 | } | 809 | } |
779 | 810 | ||
780 | return 0; | 811 | return 0; |
781 | } | 812 | } |
782 | private: | 813 | private: |
783 | bool m_asc; | 814 | bool m_asc; |
784 | int m_sort; | 815 | int m_sort; |
785 | 816 | ||
786 | }; | 817 | }; |
787 | 818 | ||
788 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | 819 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, |
789 | int sortFilter, int cat ) { | 820 | int sortFilter, int cat ) { |
790 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); | 821 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); |
791 | QMap<int, OTodo>::Iterator it; | 822 | QMap<int, OTodo>::Iterator it; |
792 | int item = 0; | 823 | int item = 0; |
793 | 824 | ||
794 | bool bCat = sortFilter & 1 ? true : false; | 825 | bool bCat = sortFilter & 1 ? true : false; |
795 | bool bOnly = sortFilter & 2 ? true : false; | 826 | bool bOnly = sortFilter & 2 ? true : false; |
796 | bool comp = sortFilter & 4 ? true : false; | 827 | bool comp = sortFilter & 4 ? true : false; |
797 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 828 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
798 | 829 | ||
799 | /* show category */ | 830 | /* show category */ |
800 | /* -1 == unfiled */ | 831 | /* -1 == unfiled */ |
801 | if ( bCat && cat == -1 ) { | 832 | if ( bCat && cat == -1 ) { |
802 | if(!(*it).categories().isEmpty() ) | 833 | if(!(*it).categories().isEmpty() ) |
803 | continue; | 834 | continue; |
804 | }else if ( bCat && cat != 0) | 835 | }else if ( bCat && cat != 0) |
805 | if (!(*it).categories().contains( cat ) ) { | 836 | if (!(*it).categories().contains( cat ) ) { |
806 | continue; | 837 | continue; |
807 | } | 838 | } |
808 | /* isOverdue but we should not show overdue - why?*/ | 839 | /* isOverdue but we should not show overdue - why?*/ |
809 | /* if ( (*it).isOverdue() && !bOnly ) { | 840 | /* if ( (*it).isOverdue() && !bOnly ) { |
810 | qWarning("item is overdue but !bOnly"); | 841 | qWarning("item is overdue but !bOnly"); |
811 | continue; | 842 | continue; |
812 | } | 843 | } |
813 | */ | 844 | */ |
814 | if ( !(*it).isOverdue() && bOnly ) { | 845 | if ( !(*it).isOverdue() && bOnly ) { |
815 | continue; | 846 | continue; |
816 | } | 847 | } |
817 | 848 | ||
818 | if ((*it).isCompleted() && comp ) { | 849 | if ((*it).isCompleted() && comp ) { |
819 | continue; | 850 | continue; |
820 | } | 851 | } |
821 | 852 | ||
822 | 853 | ||
823 | OTodoXMLContainer* con = new OTodoXMLContainer(); | 854 | OTodoXMLContainer* con = new OTodoXMLContainer(); |
824 | con->todo = (*it); | 855 | con->todo = (*it); |
825 | vector.insert(item, con ); | 856 | vector.insert(item, con ); |
826 | item++; | 857 | item++; |
827 | } | 858 | } |
828 | vector.resize( item ); | 859 | vector.resize( item ); |
829 | /* sort it now */ | 860 | /* sort it now */ |
830 | vector.sort(); | 861 | vector.sort(); |
831 | /* now get the uids */ | 862 | /* now get the uids */ |
832 | QArray<int> array( vector.count() ); | 863 | QArray<int> array( vector.count() ); |
833 | for (uint i= 0; i < vector.count(); i++ ) { | 864 | for (uint i= 0; i < vector.count(); i++ ) { |
834 | array[i] = ( vector.at(i) )->todo.uid(); | 865 | array[i] = ( vector.at(i) )->todo.uid(); |
835 | } | 866 | } |
836 | return array; | 867 | return array; |
837 | }; | 868 | }; |
838 | void OTodoAccessXML::removeAllCompleted() { | 869 | void OTodoAccessXML::removeAllCompleted() { |
839 | QMap<int, OTodo> events = m_events; | 870 | QMap<int, OTodo> events = m_events; |
840 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { | 871 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { |
841 | if ( (*it).isCompleted() ) | 872 | if ( (*it).isCompleted() ) |
842 | events.remove( it.key() ); | 873 | events.remove( it.key() ); |
843 | } | 874 | } |
844 | m_events = events; | 875 | m_events = events; |
845 | } | 876 | } |
846 | QBitArray OTodoAccessXML::supports()const { | 877 | QBitArray OTodoAccessXML::supports()const { |
847 | static QBitArray ar = sup(); | 878 | static QBitArray ar = sup(); |
848 | return ar; | 879 | return ar; |
849 | } | 880 | } |
850 | QBitArray OTodoAccessXML::sup() { | 881 | QBitArray OTodoAccessXML::sup() { |
851 | QBitArray ar( OTodo::CompletedDate +1 ); | 882 | QBitArray ar( OTodo::CompletedDate +1 ); |
852 | ar.fill( true ); | 883 | ar.fill( true ); |
853 | ar[OTodo::CrossReference] = false; | 884 | ar[OTodo::CrossReference] = false; |
854 | ar[OTodo::State ] = false; | 885 | ar[OTodo::State ] = false; |
855 | ar[OTodo::Reminders] = false; | 886 | ar[OTodo::Reminders] = false; |
856 | ar[OTodo::Notifiers] = false; | 887 | ar[OTodo::Notifiers] = false; |
857 | ar[OTodo::Maintainer] = false; | 888 | ar[OTodo::Maintainer] = false; |
858 | 889 | ||
859 | return ar; | 890 | return ar; |
860 | } | 891 | } |
861 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const | 892 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const |
862 | { | 893 | { |
863 | QArray<int> m_currentQuery( m_events.count() ); | 894 | QArray<int> m_currentQuery( m_events.count() ); |
864 | uint arraycounter = 0; | 895 | uint arraycounter = 0; |
865 | 896 | ||
866 | QMap<int, OTodo>::ConstIterator it; | 897 | QMap<int, OTodo>::ConstIterator it; |
867 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 898 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
868 | if ( it.data().match( r ) ) | 899 | if ( it.data().match( r ) ) |
869 | m_currentQuery[arraycounter++] = it.data().uid(); | 900 | m_currentQuery[arraycounter++] = it.data().uid(); |
870 | 901 | ||
871 | } | 902 | } |
872 | // Shrink to fit.. | 903 | // Shrink to fit.. |
873 | m_currentQuery.resize(arraycounter); | 904 | m_currentQuery.resize(arraycounter); |
874 | 905 | ||
875 | return m_currentQuery; | 906 | return m_currentQuery; |
876 | } | 907 | } |
908 | |||
909 | } | ||
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h index e4850a1..d634398 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.h +++ b/libopie2/opiepim/backend/otodoaccessxml.h | |||
@@ -1,60 +1,89 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_TODO_ACCESS_XML_H | 29 | #ifndef OPIE_TODO_ACCESS_XML_H |
2 | #define OPIE_TODO_ACCESS_XML_H | 30 | #define OPIE_TODO_ACCESS_XML_H |
3 | 31 | ||
4 | #include <qasciidict.h> | 32 | #include <qasciidict.h> |
5 | #include <qmap.h> | 33 | #include <qmap.h> |
6 | 34 | ||
7 | #include "otodoaccessbackend.h" | 35 | #include <opie2/otodoaccessbackend.h> |
8 | 36 | ||
9 | namespace Opie { | 37 | namespace Opie { |
10 | class XMLElement; | 38 | class XMLElement; |
11 | }; | ||
12 | 39 | ||
13 | class OTodoAccessXML : public OTodoAccessBackend { | 40 | class OTodoAccessXML : public OTodoAccessBackend { |
14 | public: | 41 | public: |
15 | /** | 42 | /** |
16 | * fileName if Empty we will use the default path | 43 | * fileName if Empty we will use the default path |
17 | */ | 44 | */ |
18 | OTodoAccessXML( const QString& appName, | 45 | OTodoAccessXML( const QString& appName, |
19 | const QString& fileName = QString::null ); | 46 | const QString& fileName = QString::null ); |
20 | ~OTodoAccessXML(); | 47 | ~OTodoAccessXML(); |
21 | 48 | ||
22 | bool load(); | 49 | bool load(); |
23 | bool reload(); | 50 | bool reload(); |
24 | bool save(); | 51 | bool save(); |
25 | 52 | ||
26 | QArray<int> allRecords()const; | 53 | QArray<int> allRecords()const; |
27 | QArray<int> matchRegexp(const QRegExp &r) const; | 54 | QArray<int> matchRegexp(const QRegExp &r) const; |
28 | QArray<int> queryByExample( const OTodo&, int querysettings, const QDateTime& d = QDateTime() ); | 55 | QArray<int> queryByExample( const OTodo&, int querysettings, const QDateTime& d = QDateTime() ); |
29 | OTodo find( int uid )const; | 56 | OTodo find( int uid )const; |
30 | void clear(); | 57 | void clear(); |
31 | bool add( const OTodo& ); | 58 | bool add( const OTodo& ); |
32 | bool remove( int uid ); | 59 | bool remove( int uid ); |
33 | void removeAllCompleted(); | 60 | void removeAllCompleted(); |
34 | bool replace( const OTodo& ); | 61 | bool replace( const OTodo& ); |
35 | 62 | ||
36 | /* our functions */ | 63 | /* our functions */ |
37 | QArray<int> effectiveToDos( const QDate& start, | 64 | QArray<int> effectiveToDos( const QDate& start, |
38 | const QDate& end, | 65 | const QDate& end, |
39 | bool includeNoDates ); | 66 | bool includeNoDates ); |
40 | QArray<int> overDue(); | 67 | QArray<int> overDue(); |
41 | QArray<int> sorted( bool asc, int sortOrder, | 68 | QArray<int> sorted( bool asc, int sortOrder, |
42 | int sortFilter, int cat ); | 69 | int sortFilter, int cat ); |
43 | QBitArray supports()const; | 70 | QBitArray supports()const; |
44 | private: | 71 | private: |
45 | static QBitArray sup(); | 72 | static QBitArray sup(); |
46 | void todo( QAsciiDict<int>*, OTodo&,const QCString&,const QString& ); | 73 | void todo( QAsciiDict<int>*, OTodo&,const QCString&,const QString& ); |
47 | QString toString( const OTodo& )const; | 74 | QString toString( const OTodo& )const; |
48 | QString toString( const QArray<int>& ints ) const; | 75 | QString toString( const QArray<int>& ints ) const; |
49 | QMap<int, OTodo> m_events; | 76 | QMap<int, OTodo> m_events; |
50 | QString m_file; | 77 | QString m_file; |
51 | QString m_app; | 78 | QString m_app; |
52 | bool m_opened : 1; | 79 | bool m_opened : 1; |
53 | bool m_changed : 1; | 80 | bool m_changed : 1; |
54 | class OTodoAccessXMLPrivate; | 81 | class OTodoAccessXMLPrivate; |
55 | OTodoAccessXMLPrivate* d; | 82 | OTodoAccessXMLPrivate* d; |
56 | int m_year, m_month, m_day; | 83 | int m_year, m_month, m_day; |
57 | 84 | ||
58 | }; | 85 | }; |
59 | 86 | ||
87 | }; | ||
88 | |||
60 | #endif | 89 | #endif |
diff --git a/libopie2/opiepim/core/core.pro b/libopie2/opiepim/core/core.pro new file mode 100644 index 0000000..dae37f1 --- a/dev/null +++ b/libopie2/opiepim/core/core.pro | |||
@@ -0,0 +1,21 @@ | |||
1 | HEADERS += core/oconversion.h \ | ||
2 | core/opimcache.h \ | ||
3 | core/opimmaintainer.h \ | ||
4 | core/opimresolver.h \ | ||
5 | core/opimstate.h \ | ||
6 | core/opimxref.h \ | ||
7 | core/opimxrefmanager.h \ | ||
8 | core/opimxrefpartner.h \ | ||
9 | core/orecur.h \ | ||
10 | core/otemplatebase.h \ | ||
11 | core/otimezone.h \ | ||
12 | |||
13 | SOURCES += core/oconversion.cpp \ | ||
14 | core/opimmaintainer.cpp \ | ||
15 | core/opimresolver.cpp \ | ||
16 | core/opimstate.cpp \ | ||
17 | core/opimxref.cpp \ | ||
18 | core/opimxrefmanager.cpp \ | ||
19 | core/opimxrefpartner.cpp \ | ||
20 | core/orecur.cpp \ | ||
21 | core/otimezone.cpp \ | ||
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 2e3ec1f..f67a40c 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp | |||
@@ -1,168 +1,152 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage the Contacts. | 2 | This file is part of the Opie Project |
3 | * | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | * | 5 | .=l. |
6 | * ===================================================================== | 6 | .>+-= |
7 | *This program is free software; you can redistribute it and/or | 7 | _;:, .> :=|. This program is free software; you can |
8 | *modify it under the terms of the GNU Library General Public | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | * License as published by the Free Software Foundation; either | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | * version 2 of the License, or (at your option) any later version. | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | * ===================================================================== | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | * Info: This class could just work with a change in the header-file | 12 | ._= =} : or (at your option) any later version. |
13 | * of the Contact class ! Therefore our libopie only compiles | 13 | .%`+i> _;_. |
14 | * with our version of libqpe | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
15 | * ===================================================================== | 30 | * ===================================================================== |
16 | * ToDo: XML-Backend: Automatic reload if something was changed... | 31 | * ToDo: XML-Backend: Automatic reload if something was changed... |
17 | * | 32 | * |
18 | * | 33 | * |
19 | * ===================================================================== | ||
20 | * Version: $Id$ | ||
21 | * ===================================================================== | ||
22 | * History: | ||
23 | * $Log$ | ||
24 | * Revision 1.8 2003/05/08 13:55:09 tille | ||
25 | * search stuff | ||
26 | * and match, toRichText & toShortText in oevent | ||
27 | * | ||
28 | * Revision 1.7 2002/11/13 14:14:51 eilers | ||
29 | * Added sorted for Contacts.. | ||
30 | * | ||
31 | * Revision 1.6 2002/11/01 15:10:42 eilers | ||
32 | * Added regExp-search in database for all fields in a contact. | ||
33 | * | ||
34 | * Revision 1.5 2002/10/16 10:52:40 eilers | ||
35 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
36 | * | ||
37 | * Revision 1.4 2002/10/14 16:21:54 eilers | ||
38 | * Some minor interface updates | ||
39 | * | ||
40 | * Revision 1.3 2002/10/07 17:34:24 eilers | ||
41 | * added OBackendFactory for advanced backend access | ||
42 | * | ||
43 | * Revision 1.2 2002/10/02 16:18:11 eilers | ||
44 | * debugged and seems to work almost perfectly .. | ||
45 | * | ||
46 | * Revision 1.1 2002/09/27 17:11:44 eilers | ||
47 | * Added API for accessing the Contact-Database ! It is compiling, but | ||
48 | * please do not expect that anything is working ! | ||
49 | * I will debug that stuff in the next time .. | ||
50 | * Please read README_COMPILE for compiling ! | ||
51 | * | ||
52 | * | ||
53 | */ | 34 | */ |
54 | 35 | ||
55 | #include "ocontactaccess.h" | 36 | #include "ocontactaccess.h" |
56 | #include "obackendfactory.h" | 37 | #include "obackendfactory.h" |
57 | 38 | ||
58 | #include <qasciidict.h> | 39 | #include <qasciidict.h> |
59 | #include <qdatetime.h> | 40 | #include <qdatetime.h> |
60 | #include <qfile.h> | 41 | #include <qfile.h> |
61 | #include <qregexp.h> | 42 | #include <qregexp.h> |
62 | #include <qlist.h> | 43 | #include <qlist.h> |
63 | #include <qcopchannel_qws.h> | 44 | #include <qcopchannel_qws.h> |
64 | 45 | ||
65 | //#include <qpe/qcopenvelope_qws.h> | 46 | //#include <qpe/qcopenvelope_qws.h> |
66 | #include <qpe/global.h> | 47 | #include <qpe/global.h> |
67 | 48 | ||
68 | #include <errno.h> | 49 | #include <errno.h> |
69 | #include <fcntl.h> | 50 | #include <fcntl.h> |
70 | #include <unistd.h> | 51 | #include <unistd.h> |
71 | #include <stdlib.h> | 52 | #include <stdlib.h> |
72 | 53 | ||
73 | #include "ocontactaccessbackend_xml.h" | 54 | #include <opie2/ocontactaccessbackend_xml.h> |
74 | 55 | ||
56 | namespace Opie { | ||
75 | 57 | ||
76 | OContactAccess::OContactAccess ( const QString appname, const QString , | 58 | OContactAccess::OContactAccess ( const QString appname, const QString , |
77 | OContactAccessBackend* end, bool autosync ): | 59 | OContactAccessBackend* end, bool autosync ): |
78 | OPimAccessTemplate<OContact>( end ) | 60 | OPimAccessTemplate<OContact>( end ) |
79 | { | 61 | { |
80 | /* take care of the backend. If there is no one defined, we | 62 | /* take care of the backend. If there is no one defined, we |
81 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | 63 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). |
82 | */ | 64 | */ |
83 | if( end == 0 ) { | 65 | if( end == 0 ) { |
84 | qWarning ("Using BackendFactory !"); | 66 | qWarning ("Using BackendFactory !"); |
85 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); | 67 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); |
86 | } | 68 | } |
87 | // Set backend locally and in template | 69 | // Set backend locally and in template |
88 | m_backEnd = end; | 70 | m_backEnd = end; |
89 | OPimAccessTemplate<OContact>::setBackEnd (end); | 71 | OPimAccessTemplate<OContact>::setBackEnd (end); |
90 | 72 | ||
91 | 73 | ||
92 | /* Connect signal of external db change to function */ | 74 | /* Connect signal of external db change to function */ |
93 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); | 75 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); |
94 | connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), | 76 | connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), |
95 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 77 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
96 | if ( autosync ){ | 78 | if ( autosync ){ |
97 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); | 79 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); |
98 | connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), | 80 | connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), |
99 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 81 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
100 | } | 82 | } |
101 | 83 | ||
102 | 84 | ||
103 | } | 85 | } |
104 | OContactAccess::~OContactAccess () | 86 | OContactAccess::~OContactAccess () |
105 | { | 87 | { |
106 | /* The user may forget to save the changed database, therefore try to | 88 | /* The user may forget to save the changed database, therefore try to |
107 | * do it for him.. | 89 | * do it for him.. |
108 | */ | 90 | */ |
109 | save(); | 91 | save(); |
110 | // delete m_backEnd; is done by template.. | 92 | // delete m_backEnd; is done by template.. |
111 | } | 93 | } |
112 | 94 | ||
113 | 95 | ||
114 | bool OContactAccess::save () | 96 | bool OContactAccess::save () |
115 | { | 97 | { |
116 | /* If the database was changed externally, we could not save the | 98 | /* If the database was changed externally, we could not save the |
117 | * Data. This will remove added items which is unacceptable ! | 99 | * Data. This will remove added items which is unacceptable ! |
118 | * Therefore: Reload database and merge the data... | 100 | * Therefore: Reload database and merge the data... |
119 | */ | 101 | */ |
120 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) | 102 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) |
121 | reload(); | 103 | reload(); |
122 | 104 | ||
123 | bool status = OPimAccessTemplate<OContact>::save(); | 105 | bool status = OPimAccessTemplate<OContact>::save(); |
124 | if ( !status ) return false; | 106 | if ( !status ) return false; |
125 | 107 | ||
126 | /* Now tell everyone that new data is available. | 108 | /* Now tell everyone that new data is available. |
127 | */ | 109 | */ |
128 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 110 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
129 | 111 | ||
130 | return true; | 112 | return true; |
131 | } | 113 | } |
132 | 114 | ||
133 | const uint OContactAccess::querySettings() | 115 | const uint OContactAccess::querySettings() |
134 | { | 116 | { |
135 | return ( m_backEnd->querySettings() ); | 117 | return ( m_backEnd->querySettings() ); |
136 | } | 118 | } |
137 | 119 | ||
138 | bool OContactAccess::hasQuerySettings ( int querySettings ) const | 120 | bool OContactAccess::hasQuerySettings ( int querySettings ) const |
139 | { | 121 | { |
140 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 122 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
141 | } | 123 | } |
142 | ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const | 124 | ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const |
143 | { | 125 | { |
144 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); | 126 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); |
145 | return ( ORecordList<OContact>(matchingContacts, this) ); | 127 | return ( ORecordList<OContact>(matchingContacts, this) ); |
146 | } | 128 | } |
147 | 129 | ||
148 | 130 | ||
149 | bool OContactAccess::wasChangedExternally()const | 131 | bool OContactAccess::wasChangedExternally()const |
150 | { | 132 | { |
151 | return ( m_backEnd->wasChangedExternally() ); | 133 | return ( m_backEnd->wasChangedExternally() ); |
152 | } | 134 | } |
153 | 135 | ||
154 | 136 | ||
155 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 137 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
156 | { | 138 | { |
157 | if ( msg == "addressbookUpdated()" ){ | 139 | if ( msg == "addressbookUpdated()" ){ |
158 | qWarning ("OContactAccess: Received addressbokUpdated()"); | 140 | qWarning ("OContactAccess: Received addressbokUpdated()"); |
159 | emit signalChanged ( this ); | 141 | emit signalChanged ( this ); |
160 | } else if ( msg == "flush()" ) { | 142 | } else if ( msg == "flush()" ) { |
161 | qWarning ("OContactAccess: Received flush()"); | 143 | qWarning ("OContactAccess: Received flush()"); |
162 | save (); | 144 | save (); |
163 | } else if ( msg == "reload()" ) { | 145 | } else if ( msg == "reload()" ) { |
164 | qWarning ("OContactAccess: Received reload()"); | 146 | qWarning ("OContactAccess: Received reload()"); |
165 | reload (); | 147 | reload (); |
166 | emit signalChanged ( this ); | 148 | emit signalChanged ( this ); |
167 | } | 149 | } |
168 | } | 150 | } |
151 | |||
152 | } | ||
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index bd6da40..505c87b 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -1,193 +1,158 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage the Contacts. | 2 | This file is part of the Opie Project |
3 | * | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 5 | .=l. |
6 | * | 6 | .>+-= |
7 | * ===================================================================== | 7 | _;:, .> :=|. This program is free software; you can |
8 | *This program is free software; you can redistribute it and/or | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | *modify it under the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | * either version 2 of the License, or (at your option) any later | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | * version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | /* | ||
13 | * ===================================================================== | 30 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 31 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 32 | * ===================================================================== |
16 | * Version: $Id$ | ||
17 | * ===================================================================== | ||
18 | * History: | ||
19 | * $Log$ | ||
20 | * Revision 1.10 2003/12/22 10:19:26 eilers | ||
21 | * Finishing implementation of sql-backend for datebook. But I have to | ||
22 | * port the PIM datebook application to use it, before I could debug the | ||
23 | * whole stuff. | ||
24 | * Thus, PIM-Database backend is finished, but highly experimental. And some | ||
25 | * parts are still generic. For instance, the "queryByExample()" methods are | ||
26 | * not (or not fully) implemented. Todo: custom-entries not stored. | ||
27 | * The big show stopper: matchRegExp() (needed by OpieSearch) needs regular | ||
28 | * expression search in the database, which is not supported by sqlite ! | ||
29 | * Therefore we need either an extended sqlite or a workaround which would | ||
30 | * be very slow and memory consuming.. | ||
31 | * | ||
32 | * Revision 1.9 2003/08/01 12:30:16 eilers | ||
33 | * Merging changes from BRANCH_1_0 to HEAD | ||
34 | * | ||
35 | * Revision 1.8.2.1 2003/06/30 14:34:19 eilers | ||
36 | * Patches from Zecke: | ||
37 | * Fixing and cleaning up extraMap handling | ||
38 | * Adding d_ptr for binary compatibility in the future | ||
39 | * | ||
40 | * Revision 1.8 2003/05/08 13:55:09 tille | ||
41 | * search stuff | ||
42 | * and match, toRichText & toShortText in oevent | ||
43 | * | ||
44 | * Revision 1.7 2003/04/13 18:07:10 zecke | ||
45 | * More API doc | ||
46 | * QString -> const QString& | ||
47 | * QString = 0l -> QString::null | ||
48 | * | ||
49 | * Revision 1.6 2003/01/02 14:27:12 eilers | ||
50 | * Improved query by example: Search by date is possible.. First step | ||
51 | * for a today plugin for birthdays.. | ||
52 | * | ||
53 | * Revision 1.5 2002/11/13 14:14:51 eilers | ||
54 | * Added sorted for Contacts.. | ||
55 | * | ||
56 | * Revision 1.4 2002/11/01 15:10:42 eilers | ||
57 | * Added regExp-search in database for all fields in a contact. | ||
58 | * | ||
59 | * Revision 1.3 2002/10/16 10:52:40 eilers | ||
60 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
61 | * | ||
62 | * Revision 1.2 2002/10/14 16:21:54 eilers | ||
63 | * Some minor interface updates | ||
64 | * | ||
65 | * Revision 1.1 2002/09/27 17:11:44 eilers | ||
66 | * Added API for accessing the Contact-Database ! It is compiling, but | ||
67 | * please do not expect that anything is working ! | ||
68 | * I will debug that stuff in the next time .. | ||
69 | * Please read README_COMPILE for compiling ! | ||
70 | * | ||
71 | * ===================================================================== | ||
72 | */ | 33 | */ |
73 | #ifndef _OCONTACTACCESS_H | 34 | #ifndef _OCONTACTACCESS_H |
74 | #define _OCONTACTACCESS_H | 35 | #define _OCONTACTACCESS_H |
75 | 36 | ||
76 | #include <qobject.h> | 37 | #include <qobject.h> |
77 | 38 | ||
78 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
79 | 40 | ||
80 | #include <qvaluelist.h> | 41 | #include <qvaluelist.h> |
81 | #include <qfileinfo.h> | 42 | #include <qfileinfo.h> |
82 | 43 | ||
83 | #include "ocontact.h" | 44 | #include <opie2/ocontact.h> |
84 | #include "ocontactaccessbackend.h" | 45 | #include <opie2/ocontactaccessbackend.h> |
85 | #include "opimaccesstemplate.h" | 46 | #include <opie2/opimaccesstemplate.h> |
86 | 47 | ||
48 | namespace Opie { | ||
87 | /** | 49 | /** |
88 | * Class to access the contacts database. | 50 | * Class to access the contacts database. |
89 | * This is just a frontend for the real database handling which is | 51 | * This is just a frontend for the real database handling which is |
90 | * done by the backend. | 52 | * done by the backend. |
91 | * This class is used to access the Contacts on a system. This class as any OPIE PIM | 53 | * This class is used to access the Contacts on a system. This class as any OPIE PIM |
92 | * class is backend independent. | 54 | * class is backend independent. |
93 | * @author Stefan Eilers, Holger Freyther | 55 | * @author Stefan Eilers, Holger Freyther |
94 | * @see OPimAccessTemplate | 56 | * @see OPimAccessTemplate |
95 | */ | 57 | */ |
96 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 58 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
97 | { | 59 | { |
98 | Q_OBJECT | 60 | Q_OBJECT |
99 | 61 | ||
100 | public: | 62 | public: |
101 | /** | 63 | /** |
102 | * Create Database with contacts (addressbook). | 64 | * Create Database with contacts (addressbook). |
103 | * @param appname Name of application which wants access to the database | 65 | * @param appname Name of application which wants access to the database |
104 | * (i.e. "todolist") | 66 | * (i.e. "todolist") |
105 | * @param filename The name of the database file. If not set, the default one | 67 | * @param filename The name of the database file. If not set, the default one |
106 | * is used. | 68 | * is used. |
107 | * @param backend Pointer to an alternative Backend. If not set, we will use | 69 | * @param backend Pointer to an alternative Backend. If not set, we will use |
108 | * the default backend. | 70 | * the default backend. |
109 | * @param handlesync If <b>true</b> the database stores the current state | 71 | * @param handlesync If <b>true</b> the database stores the current state |
110 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 72 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
111 | * which are used before and after synchronisation. If the application wants | 73 | * which are used before and after synchronisation. If the application wants |
112 | * to react itself, it should be disabled by setting it to <b>false</b> | 74 | * to react itself, it should be disabled by setting it to <b>false</b> |
113 | * @see OContactAccessBackend | 75 | * @see OContactAccessBackend |
114 | */ | 76 | */ |
115 | OContactAccess (const QString appname, const QString filename = 0l, | 77 | OContactAccess (const QString appname, const QString filename = 0l, |
116 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 78 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
117 | ~OContactAccess (); | 79 | ~OContactAccess (); |
118 | 80 | ||
119 | /** Constants for query. | 81 | /** Constants for query. |
120 | * Use this constants to set the query parameters. | 82 | * Use this constants to set the query parameters. |
121 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 83 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
122 | * @see queryByExample() | 84 | * @see queryByExample() |
123 | */ | 85 | */ |
124 | enum QuerySettings { | 86 | enum QuerySettings { |
125 | WildCards = 0x0001, | 87 | WildCards = 0x0001, |
126 | IgnoreCase = 0x0002, | 88 | IgnoreCase = 0x0002, |
127 | RegExp = 0x0004, | 89 | RegExp = 0x0004, |
128 | ExactMatch = 0x0008, | 90 | ExactMatch = 0x0008, |
129 | MatchOne = 0x0010, // Only one Entry must match | 91 | MatchOne = 0x0010, // Only one Entry must match |
130 | DateDiff = 0x0020, // Find all entries from today until given date | 92 | DateDiff = 0x0020, // Find all entries from today until given date |
131 | DateYear = 0x0040, // The year matches | 93 | DateYear = 0x0040, // The year matches |
132 | DateMonth = 0x0080, // The month matches | 94 | DateMonth = 0x0080, // The month matches |
133 | DateDay = 0x0100, // The day matches | 95 | DateDay = 0x0100, // The day matches |
134 | }; | 96 | }; |
135 | 97 | ||
136 | 98 | ||
137 | /** Return all Contacts in a sorted manner. | 99 | /** Return all Contacts in a sorted manner. |
138 | * @param ascending true: Sorted in acending order. | 100 | * @param ascending true: Sorted in acending order. |
139 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | 101 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess |
140 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | 102 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess |
141 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | 103 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess |
142 | */ | 104 | */ |
143 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | 105 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; |
144 | 106 | ||
145 | /** Return all possible settings. | 107 | /** Return all possible settings. |
146 | * @return All settings provided by the current backend | 108 | * @return All settings provided by the current backend |
147 | * (i.e.: query_WildCards & query_IgnoreCase) | 109 | * (i.e.: query_WildCards & query_IgnoreCase) |
148 | */ | 110 | */ |
149 | const uint querySettings(); | 111 | const uint querySettings(); |
150 | 112 | ||
151 | /** Check whether settings are correct. | 113 | /** Check whether settings are correct. |
152 | * @return <i>true</i> if the given settings are correct and possible. | 114 | * @return <i>true</i> if the given settings are correct and possible. |
153 | */ | 115 | */ |
154 | bool hasQuerySettings ( int querySettings ) const; | 116 | bool hasQuerySettings ( int querySettings ) const; |
155 | 117 | ||
156 | /** | 118 | /** |
157 | * if the resource was changed externally. | 119 | * if the resource was changed externally. |
158 | * You should use the signal instead of polling possible changes ! | 120 | * You should use the signal instead of polling possible changes ! |
159 | */ | 121 | */ |
160 | bool wasChangedExternally()const; | 122 | bool wasChangedExternally()const; |
161 | 123 | ||
162 | 124 | ||
163 | /** Save contacts database. | 125 | /** Save contacts database. |
164 | * Save is more a "commit". After calling this function, all changes are public available. | 126 | * Save is more a "commit". After calling this function, all changes are public available. |
165 | * @return true if successful | 127 | * @return true if successful |
166 | */ | 128 | */ |
167 | bool save(); | 129 | bool save(); |
168 | 130 | ||
169 | signals: | 131 | signals: |
170 | /* Signal is emitted if the database was changed. Therefore | 132 | /* Signal is emitted if the database was changed. Therefore |
171 | * we may need to reload to stay consistent. | 133 | * we may need to reload to stay consistent. |
172 | * @param which Pointer to the database who created this event. This pointer | 134 | * @param which Pointer to the database who created this event. This pointer |
173 | * is useful if an application has to handle multiple databases at the same time. | 135 | * is useful if an application has to handle multiple databases at the same time. |
174 | * @see reload() | 136 | * @see reload() |
175 | */ | 137 | */ |
176 | void signalChanged ( const OContactAccess *which ); | 138 | void signalChanged ( const OContactAccess *which ); |
177 | 139 | ||
178 | 140 | ||
179 | private: | 141 | private: |
180 | // class OContactAccessPrivate; | 142 | // class OContactAccessPrivate; |
181 | // OContactAccessPrivate* d; | 143 | // OContactAccessPrivate* d; |
182 | OContactAccessBackend *m_backEnd; | 144 | OContactAccessBackend *m_backEnd; |
183 | bool m_loading:1; | 145 | bool m_loading:1; |
184 | 146 | ||
185 | private slots: | 147 | private slots: |
186 | void copMessage( const QCString &msg, const QByteArray &data ); | 148 | void copMessage( const QCString &msg, const QByteArray &data ); |
187 | 149 | ||
188 | private: | 150 | private: |
189 | class Private; | 151 | class Private; |
190 | Private *d; | 152 | Private *d; |
191 | 153 | ||
192 | }; | 154 | }; |
155 | |||
156 | } | ||
157 | |||
193 | #endif | 158 | #endif |
diff --git a/libopie2/opiepim/core/oconversion.cpp b/libopie2/opiepim/core/oconversion.cpp index 0d15414..b7eebef 100644 --- a/libopie2/opiepim/core/oconversion.cpp +++ b/libopie2/opiepim/core/oconversion.cpp | |||
@@ -1,113 +1,132 @@ | |||
1 | /********************************************************************** | 1 | /* |
2 | ** Copyright (C) 2003 by Stefan Eilers (eilers.stefan@epost.de) | 2 | This file is part of the Opie Project |
3 | ** | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | ** This file may be distributed and/or modified under the terms of the | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | ** GNU Lesser General Public License version 2 as published by the Free Software | 5 | .=l. |
6 | ** Foundation and appearing in the file LICENSE.GPL included in the | 6 | .>+-= |
7 | ** packaging of this file. | 7 | _;:, .> :=|. This program is free software; you can |
8 | ** | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | ** | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | **********************************************************************/ | 12 | ._= =} : or (at your option) any later version. |
13 | 13 | .%`+i> _;_. | |
14 | #include "oconversion.h" | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
30 | #include <opie2/oconversion.h> | ||
15 | #include <qpe/timeconversion.h> | 31 | #include <qpe/timeconversion.h> |
16 | 32 | ||
17 | 33 | ||
34 | namespace Opie { | ||
35 | |||
18 | QString OConversion::dateToString( const QDate &d ) | 36 | QString OConversion::dateToString( const QDate &d ) |
19 | { | 37 | { |
20 | if ( d.isNull() || !d.isValid() ) | 38 | if ( d.isNull() || !d.isValid() ) |
21 | return QString::null; | 39 | return QString::null; |
22 | 40 | ||
23 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 | 41 | // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 |
24 | QString year = QString::number( d.year() ); | 42 | QString year = QString::number( d.year() ); |
25 | QString month = QString::number( d.month() ); | 43 | QString month = QString::number( d.month() ); |
26 | month = month.rightJustify( 2, '0' ); | 44 | month = month.rightJustify( 2, '0' ); |
27 | QString day = QString::number( d.day() ); | 45 | QString day = QString::number( d.day() ); |
28 | day = day.rightJustify( 2, '0' ); | 46 | day = day.rightJustify( 2, '0' ); |
29 | 47 | ||
30 | QString str = year + month + day; | 48 | QString str = year + month + day; |
31 | //qDebug( "\tPimContact dateToStr = %s", str.latin1() ); | 49 | //qDebug( "\tPimContact dateToStr = %s", str.latin1() ); |
32 | 50 | ||
33 | return str; | 51 | return str; |
34 | } | 52 | } |
35 | 53 | ||
36 | QDate OConversion::dateFromString( const QString& s ) | 54 | QDate OConversion::dateFromString( const QString& s ) |
37 | { | 55 | { |
38 | QDate date; | 56 | QDate date; |
39 | 57 | ||
40 | if ( s.isEmpty() ) | 58 | if ( s.isEmpty() ) |
41 | return date; | 59 | return date; |
42 | 60 | ||
43 | // Be backward compatible to old Opie format: | 61 | // Be backward compatible to old Opie format: |
44 | // Try to load old format. If it fails, try new ISO-Format! | 62 | // Try to load old format. If it fails, try new ISO-Format! |
45 | date = TimeConversion::fromString ( s ); | 63 | date = TimeConversion::fromString ( s ); |
46 | if ( date.isValid() ) | 64 | if ( date.isValid() ) |
47 | return date; | 65 | return date; |
48 | 66 | ||
49 | // Read ISO-Format (YYYYMMDD) | 67 | // Read ISO-Format (YYYYMMDD) |
50 | int year = s.mid(0, 4).toInt(); | 68 | int year = s.mid(0, 4).toInt(); |
51 | int month = s.mid(4,2).toInt(); | 69 | int month = s.mid(4,2).toInt(); |
52 | int day = s.mid(6,2).toInt(); | 70 | int day = s.mid(6,2).toInt(); |
53 | 71 | ||
54 | // do some quick sanity checking -eilers | 72 | // do some quick sanity checking -eilers |
55 | // but we isValid() again? -zecke | 73 | // but we isValid() again? -zecke |
56 | if ( year < 1900 || year > 3000 ) { | 74 | if ( year < 1900 || year > 3000 ) { |
57 | qWarning( "PimContact year is not in range"); | 75 | qWarning( "PimContact year is not in range"); |
58 | return date; | 76 | return date; |
59 | } | 77 | } |
60 | if ( month < 0 || month > 12 ) { | 78 | if ( month < 0 || month > 12 ) { |
61 | qWarning( "PimContact month is not in range"); | 79 | qWarning( "PimContact month is not in range"); |
62 | return date; | 80 | return date; |
63 | } | 81 | } |
64 | if ( day < 0 || day > 31 ) { | 82 | if ( day < 0 || day > 31 ) { |
65 | qWarning( "PimContact day is not in range"); | 83 | qWarning( "PimContact day is not in range"); |
66 | return date; | 84 | return date; |
67 | } | 85 | } |
68 | 86 | ||
69 | date.setYMD( year, month, day ); | 87 | date.setYMD( year, month, day ); |
70 | if ( !date.isValid() ) { | 88 | if ( !date.isValid() ) { |
71 | qWarning( "PimContact date is not valid"); | 89 | qWarning( "PimContact date is not valid"); |
72 | return date; | 90 | return date; |
73 | } | 91 | } |
74 | 92 | ||
75 | return date; | 93 | return date; |
76 | } | 94 | } |
77 | QString OConversion::dateTimeToString( const QDateTime& dt ) { | 95 | QString OConversion::dateTimeToString( const QDateTime& dt ) { |
78 | if (!dt.isValid() || dt.isNull() ) return QString::null; | 96 | if (!dt.isValid() || dt.isNull() ) return QString::null; |
79 | 97 | ||
80 | QString year = QString::number( dt.date().year() ); | 98 | QString year = QString::number( dt.date().year() ); |
81 | QString month = QString::number( dt.date().month() ); | 99 | QString month = QString::number( dt.date().month() ); |
82 | QString day = QString::number( dt.date().day() ); | 100 | QString day = QString::number( dt.date().day() ); |
83 | 101 | ||
84 | QString hour = QString::number( dt.time().hour() ); | 102 | QString hour = QString::number( dt.time().hour() ); |
85 | QString min = QString::number( dt.time().minute() ); | 103 | QString min = QString::number( dt.time().minute() ); |
86 | QString sec = QString::number( dt.time().second() ); | 104 | QString sec = QString::number( dt.time().second() ); |
87 | 105 | ||
88 | month = month.rightJustify( 2, '0' ); | 106 | month = month.rightJustify( 2, '0' ); |
89 | day = day. rightJustify( 2, '0' ); | 107 | day = day. rightJustify( 2, '0' ); |
90 | hour = hour. rightJustify( 2, '0' ); | 108 | hour = hour. rightJustify( 2, '0' ); |
91 | min = min. rightJustify( 2, '0' ); | 109 | min = min. rightJustify( 2, '0' ); |
92 | sec = sec. rightJustify( 2, '0' ); | 110 | sec = sec. rightJustify( 2, '0' ); |
93 | 111 | ||
94 | QString str = day + month + year + hour + min + sec; | 112 | QString str = day + month + year + hour + min + sec; |
95 | 113 | ||
96 | return str; | 114 | return str; |
97 | } | 115 | } |
98 | QDateTime OConversion::dateTimeFromString( const QString& str) { | 116 | QDateTime OConversion::dateTimeFromString( const QString& str) { |
99 | 117 | ||
100 | if ( str.isEmpty() ) return QDateTime(); | 118 | if ( str.isEmpty() ) return QDateTime(); |
101 | int day = str.mid(0, 2).toInt(); | 119 | int day = str.mid(0, 2).toInt(); |
102 | int month = str.mid(2, 2).toInt(); | 120 | int month = str.mid(2, 2).toInt(); |
103 | int year = str.mid(4, 4).toInt(); | 121 | int year = str.mid(4, 4).toInt(); |
104 | int hour = str.mid(8, 2).toInt(); | 122 | int hour = str.mid(8, 2).toInt(); |
105 | int min = str.mid(10, 2).toInt(); | 123 | int min = str.mid(10, 2).toInt(); |
106 | int sec = str.mid(12, 2).toInt(); | 124 | int sec = str.mid(12, 2).toInt(); |
107 | 125 | ||
108 | QDate date( year, month, day ); | 126 | QDate date( year, month, day ); |
109 | QTime time( hour, min, sec ); | 127 | QTime time( hour, min, sec ); |
110 | QDateTime dt( date, time ); | 128 | QDateTime dt( date, time ); |
111 | return dt; | 129 | return dt; |
112 | } | 130 | } |
113 | 131 | ||
132 | } \ No newline at end of file | ||
diff --git a/libopie2/opiepim/core/oconversion.h b/libopie2/opiepim/core/oconversion.h index 4c0a497..3c4fdf3 100644 --- a/libopie2/opiepim/core/oconversion.h +++ b/libopie2/opiepim/core/oconversion.h | |||
@@ -1,48 +1,62 @@ | |||
1 | /********************************************************************** | 1 | /* |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | This file is part of the Opie Project |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | ** | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | .=l. |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | .>+-= |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | _;:, .> :=|. This program is free software; you can |
8 | ** packaging of this file. | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | ** | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ** | 12 | ._= =} : or (at your option) any later version. |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | .%`+i> _;_. |
14 | ** | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | ** not clear to you. | 16 | : .. .:, . . . without even the implied warranty of |
17 | **********************************************************************/ | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
18 | 29 | ||
19 | #ifndef __oconversion_h__ | 30 | #ifndef __oconversion_h__ |
20 | #define __oconversion_h__ | 31 | #define __oconversion_h__ |
21 | 32 | ||
22 | /* #include <time.h> */ | 33 | /* #include <time.h> */ |
23 | /* #include <sys/types.h> */ | 34 | /* #include <sys/types.h> */ |
24 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
25 | 36 | ||
26 | /* FIXME namespace? -zecke */ | 37 | namespace Opie { |
38 | |||
27 | class OConversion | 39 | class OConversion |
28 | { | 40 | { |
29 | public: | 41 | public: |
30 | static QString dateToString( const QDate &d ); | 42 | static QString dateToString( const QDate &d ); |
31 | static QDate dateFromString( const QString &datestr ); | 43 | static QDate dateFromString( const QString &datestr ); |
32 | 44 | ||
33 | /** | 45 | /** |
34 | * simple function to store DateTime as string and read from string | 46 | * simple function to store DateTime as string and read from string |
35 | * no timezone changing is done | 47 | * no timezone changing is done |
36 | * DDMMYYYYHHMMSS is the simple format | 48 | * DDMMYYYYHHMMSS is the simple format |
37 | */ | 49 | */ |
38 | static QString dateTimeToString( const QDateTime& ); | 50 | static QString dateTimeToString( const QDateTime& ); |
39 | static QDateTime dateTimeFromString( const QString& ); | 51 | static QDateTime dateTimeFromString( const QString& ); |
40 | 52 | ||
41 | private: | 53 | private: |
42 | class Private; | 54 | class Private; |
43 | Private* d; | 55 | Private* d; |
44 | 56 | ||
45 | }; | 57 | }; |
46 | 58 | ||
59 | } | ||
60 | |||
47 | #endif // __oconversion_h__ | 61 | #endif // __oconversion_h__ |
48 | 62 | ||
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index d95fed6..8c527f6 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp | |||
@@ -1,81 +1,112 @@ | |||
1 | #include "obackendfactory.h" | 1 | /* |
2 | #include "odatebookaccess.h" | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | #include <opie2/obackendfactory.h> | ||
30 | #include <opie2/odatebookaccess.h> | ||
3 | 31 | ||
32 | namespace Opie { | ||
4 | /** | 33 | /** |
5 | * Simple constructor | 34 | * Simple constructor |
6 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation | 35 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation |
7 | * will be used! | 36 | * will be used! |
8 | * @param back The backend to be used or 0 for the default backend | 37 | * @param back The backend to be used or 0 for the default backend |
9 | * @param ac What kind of access is intended | 38 | * @param ac What kind of access is intended |
10 | */ | 39 | */ |
11 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) | 40 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) |
12 | : OPimAccessTemplate<OEvent>( back ) | 41 | : OPimAccessTemplate<OEvent>( back ) |
13 | { | 42 | { |
14 | if (!back ) | 43 | if (!back ) |
15 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); | 44 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); |
16 | 45 | ||
17 | m_backEnd = back; | 46 | m_backEnd = back; |
18 | setBackEnd( m_backEnd ); | 47 | setBackEnd( m_backEnd ); |
19 | } | 48 | } |
20 | ODateBookAccess::~ODateBookAccess() { | 49 | ODateBookAccess::~ODateBookAccess() { |
21 | } | 50 | } |
22 | 51 | ||
23 | /** | 52 | /** |
24 | * @return all events available | 53 | * @return all events available |
25 | */ | 54 | */ |
26 | ODateBookAccess::List ODateBookAccess::rawEvents()const { | 55 | ODateBookAccess::List ODateBookAccess::rawEvents()const { |
27 | QArray<int> ints = m_backEnd->rawEvents(); | 56 | QArray<int> ints = m_backEnd->rawEvents(); |
28 | 57 | ||
29 | List lis( ints, this ); | 58 | List lis( ints, this ); |
30 | return lis; | 59 | return lis; |
31 | } | 60 | } |
32 | 61 | ||
33 | /** | 62 | /** |
34 | * @return all repeating events | 63 | * @return all repeating events |
35 | */ | 64 | */ |
36 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { | 65 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { |
37 | QArray<int> ints = m_backEnd->rawRepeats(); | 66 | QArray<int> ints = m_backEnd->rawRepeats(); |
38 | 67 | ||
39 | List lis( ints, this ); | 68 | List lis( ints, this ); |
40 | return lis; | 69 | return lis; |
41 | } | 70 | } |
42 | 71 | ||
43 | /** | 72 | /** |
44 | * @return all non repeating events | 73 | * @return all non repeating events |
45 | */ | 74 | */ |
46 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { | 75 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { |
47 | QArray<int> ints = m_backEnd->nonRepeats(); | 76 | QArray<int> ints = m_backEnd->nonRepeats(); |
48 | 77 | ||
49 | List lis( ints, this ); | 78 | List lis( ints, this ); |
50 | return lis; | 79 | return lis; |
51 | } | 80 | } |
52 | 81 | ||
53 | /** | 82 | /** |
54 | * @return dates in the time span between from and to | 83 | * @return dates in the time span between from and to |
55 | * @param from Include all events from... | 84 | * @param from Include all events from... |
56 | * @param to Include all events to... | 85 | * @param to Include all events to... |
57 | */ | 86 | */ |
58 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { | 87 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { |
59 | return m_backEnd->effectiveEvents( from, to ); | 88 | return m_backEnd->effectiveEvents( from, to ); |
60 | } | 89 | } |
61 | /** | 90 | /** |
62 | * @return all events at a given datetime | 91 | * @return all events at a given datetime |
63 | */ | 92 | */ |
64 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { | 93 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { |
65 | return m_backEnd->effectiveEvents( start ); | 94 | return m_backEnd->effectiveEvents( start ); |
66 | } | 95 | } |
67 | 96 | ||
68 | /** | 97 | /** |
69 | * @return non repeating dates in the time span between from and to | 98 | * @return non repeating dates in the time span between from and to |
70 | * @param from Include all events from... | 99 | * @param from Include all events from... |
71 | * @param to Include all events to... | 100 | * @param to Include all events to... |
72 | */ | 101 | */ |
73 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { | 102 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { |
74 | return m_backEnd->effectiveNonRepeatingEvents( from, to ); | 103 | return m_backEnd->effectiveNonRepeatingEvents( from, to ); |
75 | } | 104 | } |
76 | /** | 105 | /** |
77 | * @return all non repeating events at a given datetime | 106 | * @return all non repeating events at a given datetime |
78 | */ | 107 | */ |
79 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { | 108 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { |
80 | return m_backEnd->effectiveNonRepeatingEvents( start ); | 109 | return m_backEnd->effectiveNonRepeatingEvents( start ); |
81 | } | 110 | } |
111 | |||
112 | } | ||
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h index 62196da..38dc754 100644 --- a/libopie2/opiepim/core/odatebookaccess.h +++ b/libopie2/opiepim/core/odatebookaccess.h | |||
@@ -1,44 +1,75 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_H | 29 | #ifndef OPIE_DATE_BOOK_ACCESS_H |
2 | #define OPIE_DATE_BOOK_ACCESS_H | 30 | #define OPIE_DATE_BOOK_ACCESS_H |
3 | 31 | ||
4 | #include "odatebookaccessbackend.h" | 32 | #include "odatebookaccessbackend.h" |
5 | #include "opimaccesstemplate.h" | 33 | #include "opimaccesstemplate.h" |
6 | 34 | ||
7 | #include "oevent.h" | 35 | #include <opie2/oevent.h> |
8 | 36 | ||
37 | namespace Opie { | ||
9 | /** | 38 | /** |
10 | * This is the object orientated datebook database. It'll use OBackendFactory | 39 | * This is the object orientated datebook database. It'll use OBackendFactory |
11 | * to query for a backend. | 40 | * to query for a backend. |
12 | * All access to the datebook should be done via this class. | 41 | * All access to the datebook should be done via this class. |
13 | * Make sure to load and save the datebook this is not part of | 42 | * Make sure to load and save the datebook this is not part of |
14 | * destructing and creating the object | 43 | * destructing and creating the object |
15 | * | 44 | * |
16 | * @author Holger Freyther, Stefan Eilers | 45 | * @author Holger Freyther, Stefan Eilers |
17 | */ | 46 | */ |
18 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { | 47 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { |
19 | public: | 48 | public: |
20 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); | 49 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); |
21 | ~ODateBookAccess(); | 50 | ~ODateBookAccess(); |
22 | 51 | ||
23 | /* return all events */ | 52 | /* return all events */ |
24 | List rawEvents()const; | 53 | List rawEvents()const; |
25 | 54 | ||
26 | /* return repeating events */ | 55 | /* return repeating events */ |
27 | List rawRepeats()const; | 56 | List rawRepeats()const; |
28 | 57 | ||
29 | /* return non repeating events */ | 58 | /* return non repeating events */ |
30 | List nonRepeats()const; | 59 | List nonRepeats()const; |
31 | 60 | ||
32 | /* return non repeating events (from,to) */ | 61 | /* return non repeating events (from,to) */ |
33 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; | 62 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; |
34 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; | 63 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; |
35 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; | 64 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; |
36 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; | 65 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; |
37 | 66 | ||
38 | private: | 67 | private: |
39 | ODateBookAccessBackend* m_backEnd; | 68 | ODateBookAccessBackend* m_backEnd; |
40 | class Private; | 69 | class Private; |
41 | Private* d; | 70 | Private* d; |
42 | }; | 71 | }; |
43 | 72 | ||
73 | } | ||
74 | |||
44 | #endif | 75 | #endif |
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index ecbeb68..5826cbc 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -1,302 +1,335 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 29 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 30 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 31 | ||
4 | #include <qarray.h> | 32 | #include <qarray.h> |
5 | 33 | ||
6 | #include <opie/opimrecord.h> | 34 | #include <opie2/opimrecord.h> |
7 | #include <opie/opimaccessbackend.h> | 35 | #include <opie2/opimaccessbackend.h> |
8 | #include <opie/orecordlist.h> | 36 | #include <opie2/orecordlist.h> |
9 | 37 | ||
10 | #include "opimcache.h" | 38 | #include <opie2/opimcache.h> |
11 | #include "otemplatebase.h" | 39 | #include <opie2/otemplatebase.h> |
40 | |||
41 | namespace Opie { | ||
12 | 42 | ||
13 | class OPimAccessTemplatePrivate; | 43 | class OPimAccessTemplatePrivate; |
14 | /** | 44 | /** |
15 | * Thats the frontend to our OPIE PIM | 45 | * Thats the frontend to our OPIE PIM |
16 | * Library. Either you want to use it's | 46 | * Library. Either you want to use it's |
17 | * interface or you want to implement | 47 | * interface or you want to implement |
18 | * your own Access lib | 48 | * your own Access lib |
19 | * Just create a OPimRecord and inherit from | 49 | * Just create a OPimRecord and inherit from |
20 | * the plugins | 50 | * the plugins |
21 | */ | 51 | */ |
22 | 52 | ||
23 | template <class T = OPimRecord > | 53 | template <class T = OPimRecord > |
24 | class OPimAccessTemplate : public OTemplateBase<T> { | 54 | class OPimAccessTemplate : public OTemplateBase<T> { |
25 | public: | 55 | public: |
26 | enum Access { | 56 | enum Access { |
27 | Random = 0, | 57 | Random = 0, |
28 | SortedAccess | 58 | SortedAccess |
29 | }; | 59 | }; |
30 | typedef ORecordList<T> List; | 60 | typedef ORecordList<T> List; |
31 | typedef OPimAccessBackend<T> BackEnd; | 61 | typedef OPimAccessBackend<T> BackEnd; |
32 | typedef OPimCache<T> Cache; | 62 | typedef OPimCache<T> Cache; |
33 | 63 | ||
34 | /** | 64 | /** |
35 | * c'tor BackEnd | 65 | * c'tor BackEnd |
36 | * enum Access a small hint on how to handle the backend | 66 | * enum Access a small hint on how to handle the backend |
37 | */ | 67 | */ |
38 | OPimAccessTemplate( BackEnd* end); | 68 | OPimAccessTemplate( BackEnd* end); |
39 | 69 | ||
40 | virtual ~OPimAccessTemplate(); | 70 | virtual ~OPimAccessTemplate(); |
41 | 71 | ||
42 | /** | 72 | /** |
43 | * load from the backend | 73 | * load from the backend |
44 | */ | 74 | */ |
45 | bool load(); | 75 | bool load(); |
46 | 76 | ||
47 | /** Reload database. | 77 | /** Reload database. |
48 | * You should execute this function if the external database | 78 | * You should execute this function if the external database |
49 | * was changed. | 79 | * was changed. |
50 | * This function will load the external database and afterwards | 80 | * This function will load the external database and afterwards |
51 | * rejoin the local changes. Therefore the local database will be set consistent. | 81 | * rejoin the local changes. Therefore the local database will be set consistent. |
52 | */ | 82 | */ |
53 | virtual bool reload(); | 83 | virtual bool reload(); |
54 | 84 | ||
55 | /** Save contacts database. | 85 | /** Save contacts database. |
56 | * Save is more a "commit". After calling this function, all changes are public available. | 86 | * Save is more a "commit". After calling this function, all changes are public available. |
57 | * @return true if successful | 87 | * @return true if successful |
58 | */ | 88 | */ |
59 | bool save(); | 89 | bool save(); |
60 | 90 | ||
61 | /** | 91 | /** |
62 | * if the resource was changed externally | 92 | * if the resource was changed externally |
63 | * You should use the signal handling instead of polling possible changes ! | 93 | * You should use the signal handling instead of polling possible changes ! |
64 | * zecke: Do you implement a signal for otodoaccess ? | 94 | * zecke: Do you implement a signal for otodoaccess ? |
65 | */ | 95 | */ |
66 | bool wasChangedExternally()const; | 96 | bool wasChangedExternally()const; |
67 | 97 | ||
68 | /** | 98 | /** |
69 | * return a List of records | 99 | * return a List of records |
70 | * you can iterate over them | 100 | * you can iterate over them |
71 | */ | 101 | */ |
72 | virtual List allRecords()const; | 102 | virtual List allRecords()const; |
73 | 103 | ||
74 | /** | 104 | /** |
75 | * return a List of records | 105 | * return a List of records |
76 | * that match the regex | 106 | * that match the regex |
77 | */ | 107 | */ |
78 | virtual List matchRegexp( const QRegExp &r ) const; | 108 | virtual List matchRegexp( const QRegExp &r ) const; |
79 | 109 | ||
80 | /** | 110 | /** |
81 | * queryByExample. | 111 | * queryByExample. |
82 | * @see otodoaccess, ocontactaccess | 112 | * @see otodoaccess, ocontactaccess |
83 | */ | 113 | */ |
84 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); | 114 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); |
85 | 115 | ||
86 | /** | 116 | /** |
87 | * find the OPimRecord uid | 117 | * find the OPimRecord uid |
88 | */ | 118 | */ |
89 | virtual T find( int uid )const; | 119 | virtual T find( int uid )const; |
90 | 120 | ||
91 | /** | 121 | /** |
92 | * read ahead cache find method ;) | 122 | * read ahead cache find method ;) |
93 | */ | 123 | */ |
94 | virtual T find( int uid, const QArray<int>&, | 124 | virtual T find( int uid, const QArray<int>&, |
95 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; | 125 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; |
96 | 126 | ||
97 | /* invalidate cache here */ | 127 | /* invalidate cache here */ |
98 | /** | 128 | /** |
99 | * clears the backend and invalidates the backend | 129 | * clears the backend and invalidates the backend |
100 | */ | 130 | */ |
101 | void clear() ; | 131 | void clear() ; |
102 | 132 | ||
103 | /** | 133 | /** |
104 | * add T to the backend | 134 | * add T to the backend |
105 | * @param t The item to add. | 135 | * @param t The item to add. |
106 | * @return <i>true</i> if added successfully. | 136 | * @return <i>true</i> if added successfully. |
107 | */ | 137 | */ |
108 | virtual bool add( const T& t ) ; | 138 | virtual bool add( const T& t ) ; |
109 | bool add( const OPimRecord& ); | 139 | bool add( const OPimRecord& ); |
110 | 140 | ||
111 | /* only the uid matters */ | 141 | /* only the uid matters */ |
112 | /** | 142 | /** |
113 | * remove T from the backend | 143 | * remove T from the backend |
114 | * @param t The item to remove | 144 | * @param t The item to remove |
115 | * @return <i>true</i> if successful. | 145 | * @return <i>true</i> if successful. |
116 | */ | 146 | */ |
117 | virtual bool remove( const T& t ); | 147 | virtual bool remove( const T& t ); |
118 | 148 | ||
119 | /** | 149 | /** |
120 | * remove the OPimRecord with uid | 150 | * remove the OPimRecord with uid |
121 | * @param uid The ID of the item to remove | 151 | * @param uid The ID of the item to remove |
122 | * @return <i>true</i> if successful. | 152 | * @return <i>true</i> if successful. |
123 | */ | 153 | */ |
124 | bool remove( int uid ); | 154 | bool remove( int uid ); |
125 | bool remove( const OPimRecord& ); | 155 | bool remove( const OPimRecord& ); |
126 | 156 | ||
127 | /** | 157 | /** |
128 | * replace T from backend | 158 | * replace T from backend |
129 | * @param t The item to replace | 159 | * @param t The item to replace |
130 | * @return <i>true</i> if successful. | 160 | * @return <i>true</i> if successful. |
131 | */ | 161 | */ |
132 | virtual bool replace( const T& t) ; | 162 | virtual bool replace( const T& t) ; |
133 | 163 | ||
134 | void setReadAhead( uint count ); | 164 | void setReadAhead( uint count ); |
135 | /** | 165 | /** |
136 | * @internal | 166 | * @internal |
137 | */ | 167 | */ |
138 | void cache( const T& )const; | 168 | void cache( const T& )const; |
139 | void setSaneCacheSize( int ); | 169 | void setSaneCacheSize( int ); |
140 | 170 | ||
141 | QArray<int> records()const; | 171 | QArray<int> records()const; |
142 | protected: | 172 | protected: |
143 | /** | 173 | /** |
144 | * invalidate the cache | 174 | * invalidate the cache |
145 | */ | 175 | */ |
146 | void invalidateCache(); | 176 | void invalidateCache(); |
147 | 177 | ||
148 | void setBackEnd( BackEnd* end ); | 178 | void setBackEnd( BackEnd* end ); |
149 | /** | 179 | /** |
150 | * returns the backend | 180 | * returns the backend |
151 | */ | 181 | */ |
152 | BackEnd* backEnd(); | 182 | BackEnd* backEnd(); |
153 | BackEnd* m_backEnd; | 183 | BackEnd* m_backEnd; |
154 | Cache m_cache; | 184 | Cache m_cache; |
155 | 185 | ||
156 | private: | 186 | private: |
157 | OPimAccessTemplatePrivate *d; | 187 | OPimAccessTemplatePrivate *d; |
158 | 188 | ||
159 | }; | 189 | }; |
160 | 190 | ||
161 | template <class T> | 191 | template <class T> |
162 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 192 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
163 | : OTemplateBase<T>(), m_backEnd( end ) | 193 | : OTemplateBase<T>(), m_backEnd( end ) |
164 | { | 194 | { |
165 | if (end ) | 195 | if (end ) |
166 | end->setFrontend( this ); | 196 | end->setFrontend( this ); |
167 | } | 197 | } |
168 | template <class T> | 198 | template <class T> |
169 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 199 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
170 | qWarning("~OPimAccessTemplate<T>"); | 200 | qWarning("~OPimAccessTemplate<T>"); |
171 | delete m_backEnd; | 201 | delete m_backEnd; |
172 | } | 202 | } |
173 | template <class T> | 203 | template <class T> |
174 | bool OPimAccessTemplate<T>::load() { | 204 | bool OPimAccessTemplate<T>::load() { |
175 | invalidateCache(); | 205 | invalidateCache(); |
176 | return m_backEnd->load(); | 206 | return m_backEnd->load(); |
177 | } | 207 | } |
178 | template <class T> | 208 | template <class T> |
179 | bool OPimAccessTemplate<T>::reload() { | 209 | bool OPimAccessTemplate<T>::reload() { |
180 | invalidateCache(); // zecke: I think this should be added (se) | 210 | invalidateCache(); // zecke: I think this should be added (se) |
181 | return m_backEnd->reload(); | 211 | return m_backEnd->reload(); |
182 | } | 212 | } |
183 | template <class T> | 213 | template <class T> |
184 | bool OPimAccessTemplate<T>::save() { | 214 | bool OPimAccessTemplate<T>::save() { |
185 | return m_backEnd->save(); | 215 | return m_backEnd->save(); |
186 | } | 216 | } |
187 | template <class T> | 217 | template <class T> |
188 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 218 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
189 | QArray<int> ints = m_backEnd->allRecords(); | 219 | QArray<int> ints = m_backEnd->allRecords(); |
190 | List lis(ints, this ); | 220 | List lis(ints, this ); |
191 | return lis; | 221 | return lis; |
192 | } | 222 | } |
193 | template <class T> | 223 | template <class T> |
194 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { | 224 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { |
195 | QArray<int> ints = m_backEnd->matchRegexp( r ); | 225 | QArray<int> ints = m_backEnd->matchRegexp( r ); |
196 | List lis(ints, this ); | 226 | List lis(ints, this ); |
197 | return lis; | 227 | return lis; |
198 | } | 228 | } |
199 | template <class T> | 229 | template <class T> |
200 | QArray<int> OPimAccessTemplate<T>::records()const { | 230 | QArray<int> OPimAccessTemplate<T>::records()const { |
201 | return m_backEnd->allRecords(); | 231 | return m_backEnd->allRecords(); |
202 | } | 232 | } |
203 | template <class T> | 233 | template <class T> |
204 | typename OPimAccessTemplate<T>::List | 234 | typename OPimAccessTemplate<T>::List |
205 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { | 235 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { |
206 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); | 236 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); |
207 | 237 | ||
208 | List lis(ints, this ); | 238 | List lis(ints, this ); |
209 | return lis; | 239 | return lis; |
210 | } | 240 | } |
211 | template <class T> | 241 | template <class T> |
212 | T OPimAccessTemplate<T>::find( int uid ) const{ | 242 | T OPimAccessTemplate<T>::find( int uid ) const{ |
213 | T t = m_backEnd->find( uid ); | 243 | T t = m_backEnd->find( uid ); |
214 | cache( t ); | 244 | cache( t ); |
215 | return t; | 245 | return t; |
216 | } | 246 | } |
217 | template <class T> | 247 | template <class T> |
218 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 248 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
219 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { | 249 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { |
220 | /* | 250 | /* |
221 | * better do T.isEmpty() | 251 | * better do T.isEmpty() |
222 | * after a find this way we would | 252 | * after a find this way we would |
223 | * avoid two finds in QCache... | 253 | * avoid two finds in QCache... |
224 | */ | 254 | */ |
225 | // qWarning("find it now %d", uid ); | 255 | // qWarning("find it now %d", uid ); |
226 | if (m_cache.contains( uid ) ) { | 256 | if (m_cache.contains( uid ) ) { |
227 | return m_cache.find( uid ); | 257 | return m_cache.find( uid ); |
228 | } | 258 | } |
229 | 259 | ||
230 | T t = m_backEnd->find( uid, ar, current, dir ); | 260 | T t = m_backEnd->find( uid, ar, current, dir ); |
231 | cache( t ); | 261 | cache( t ); |
232 | return t; | 262 | return t; |
233 | } | 263 | } |
234 | template <class T> | 264 | template <class T> |
235 | void OPimAccessTemplate<T>::clear() { | 265 | void OPimAccessTemplate<T>::clear() { |
236 | invalidateCache(); | 266 | invalidateCache(); |
237 | m_backEnd->clear(); | 267 | m_backEnd->clear(); |
238 | } | 268 | } |
239 | template <class T> | 269 | template <class T> |
240 | bool OPimAccessTemplate<T>::add( const T& t ) { | 270 | bool OPimAccessTemplate<T>::add( const T& t ) { |
241 | cache( t ); | 271 | cache( t ); |
242 | return m_backEnd->add( t ); | 272 | return m_backEnd->add( t ); |
243 | } | 273 | } |
244 | template <class T> | 274 | template <class T> |
245 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 275 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { |
246 | /* same type */ | 276 | /* same type */ |
247 | if ( rec.rtti() == T::rtti() ) { | 277 | if ( rec.rtti() == T::rtti() ) { |
248 | const T &t = static_cast<const T&>(rec); | 278 | const T &t = static_cast<const T&>(rec); |
249 | return add(t); | 279 | return add(t); |
250 | } | 280 | } |
251 | return false; | 281 | return false; |
252 | } | 282 | } |
253 | template <class T> | 283 | template <class T> |
254 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 284 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
255 | return remove( t.uid() ); | 285 | return remove( t.uid() ); |
256 | } | 286 | } |
257 | template <class T> | 287 | template <class T> |
258 | bool OPimAccessTemplate<T>::remove( int uid ) { | 288 | bool OPimAccessTemplate<T>::remove( int uid ) { |
259 | m_cache.remove( uid ); | 289 | m_cache.remove( uid ); |
260 | return m_backEnd->remove( uid ); | 290 | return m_backEnd->remove( uid ); |
261 | } | 291 | } |
262 | template <class T> | 292 | template <class T> |
263 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | 293 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { |
264 | return remove( rec.uid() ); | 294 | return remove( rec.uid() ); |
265 | } | 295 | } |
266 | template <class T> | 296 | template <class T> |
267 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 297 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
268 | m_cache.replace( t ); | 298 | m_cache.replace( t ); |
269 | return m_backEnd->replace( t ); | 299 | return m_backEnd->replace( t ); |
270 | } | 300 | } |
271 | template <class T> | 301 | template <class T> |
272 | void OPimAccessTemplate<T>::invalidateCache() { | 302 | void OPimAccessTemplate<T>::invalidateCache() { |
273 | m_cache.invalidate(); | 303 | m_cache.invalidate(); |
274 | } | 304 | } |
275 | template <class T> | 305 | template <class T> |
276 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 306 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
277 | return m_backEnd; | 307 | return m_backEnd; |
278 | } | 308 | } |
279 | template <class T> | 309 | template <class T> |
280 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 310 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
281 | return false; | 311 | return false; |
282 | } | 312 | } |
283 | template <class T> | 313 | template <class T> |
284 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 314 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
285 | m_backEnd = end; | 315 | m_backEnd = end; |
286 | if (m_backEnd ) | 316 | if (m_backEnd ) |
287 | m_backEnd->setFrontend( this ); | 317 | m_backEnd->setFrontend( this ); |
288 | } | 318 | } |
289 | template <class T> | 319 | template <class T> |
290 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 320 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
291 | /* hacky we need to work around the const*/ | 321 | /* hacky we need to work around the const*/ |
292 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 322 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
293 | } | 323 | } |
294 | template <class T> | 324 | template <class T> |
295 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 325 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
296 | m_cache.setSize( size ); | 326 | m_cache.setSize( size ); |
297 | } | 327 | } |
298 | template <class T> | 328 | template <class T> |
299 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | 329 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { |
300 | m_backEnd->setReadAhead( count ); | 330 | m_backEnd->setReadAhead( count ); |
301 | } | 331 | } |
332 | |||
333 | } | ||
334 | |||
302 | #endif | 335 | #endif |
diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h index 7f7cff5..e70a910 100644 --- a/libopie2/opiepim/core/opimcache.h +++ b/libopie2/opiepim/core/opimcache.h | |||
@@ -1,131 +1,162 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_CACHE_H | 29 | #ifndef OPIE_PIM_CACHE_H |
2 | #define OPIE_PIM_CACHE_H | 30 | #define OPIE_PIM_CACHE_H |
3 | 31 | ||
4 | #include <qintcache.h> | 32 | #include <qintcache.h> |
5 | 33 | ||
6 | #include "opimrecord.h" | 34 | #include <opie2/opimrecord.h> |
7 | 35 | ||
36 | namespace Opie { | ||
8 | class OPimCacheItemPrivate; | 37 | class OPimCacheItemPrivate; |
9 | 38 | ||
10 | template <class T = OPimRecord> | 39 | template <class T = OPimRecord> |
11 | class OPimCacheItem { | 40 | class OPimCacheItem { |
12 | public: | 41 | public: |
13 | OPimCacheItem( const T& t = T() ); | 42 | OPimCacheItem( const T& t = T() ); |
14 | OPimCacheItem( const OPimCacheItem& ); | 43 | OPimCacheItem( const OPimCacheItem& ); |
15 | ~OPimCacheItem(); | 44 | ~OPimCacheItem(); |
16 | 45 | ||
17 | OPimCacheItem &operator=( const OPimCacheItem& ); | 46 | OPimCacheItem &operator=( const OPimCacheItem& ); |
18 | 47 | ||
19 | T record()const; | 48 | T record()const; |
20 | void setRecord( const T& ); | 49 | void setRecord( const T& ); |
21 | private: | 50 | private: |
22 | T m_t; | 51 | T m_t; |
23 | OPimCacheItemPrivate *d; | 52 | OPimCacheItemPrivate *d; |
24 | }; | 53 | }; |
25 | 54 | ||
26 | 55 | ||
27 | class OPimCachePrivate; | 56 | class OPimCachePrivate; |
28 | /** | 57 | /** |
29 | * OPimCache for caching the items | 58 | * OPimCache for caching the items |
30 | * We support adding, removing | 59 | * We support adding, removing |
31 | * and finding | 60 | * and finding |
32 | */ | 61 | */ |
33 | template <class T = OPimRecord> | 62 | template <class T = OPimRecord> |
34 | class OPimCache { | 63 | class OPimCache { |
35 | public: | 64 | public: |
36 | typedef OPimCacheItem<T> Item; | 65 | typedef OPimCacheItem<T> Item; |
37 | OPimCache(); | 66 | OPimCache(); |
38 | OPimCache( const OPimCache& ); | 67 | OPimCache( const OPimCache& ); |
39 | ~OPimCache(); | 68 | ~OPimCache(); |
40 | 69 | ||
41 | OPimCache &operator=( const OPimCache& ); | 70 | OPimCache &operator=( const OPimCache& ); |
42 | 71 | ||
43 | bool contains(int uid)const; | 72 | bool contains(int uid)const; |
44 | void invalidate(); | 73 | void invalidate(); |
45 | void setSize( int size ); | 74 | void setSize( int size ); |
46 | 75 | ||
47 | T find(int uid )const; | 76 | T find(int uid )const; |
48 | void add( const T& ); | 77 | void add( const T& ); |
49 | void remove( int uid ); | 78 | void remove( int uid ); |
50 | void replace( const T& ); | 79 | void replace( const T& ); |
51 | 80 | ||
52 | private: | 81 | private: |
53 | QIntCache<Item> m_cache; | 82 | QIntCache<Item> m_cache; |
54 | OPimCachePrivate* d; | 83 | OPimCachePrivate* d; |
55 | }; | 84 | }; |
56 | 85 | ||
57 | // Implementation | 86 | // Implementation |
58 | template <class T> | 87 | template <class T> |
59 | OPimCacheItem<T>::OPimCacheItem( const T& t ) | 88 | OPimCacheItem<T>::OPimCacheItem( const T& t ) |
60 | : m_t(t) { | 89 | : m_t(t) { |
61 | } | 90 | } |
62 | template <class T> | 91 | template <class T> |
63 | OPimCacheItem<T>::~OPimCacheItem() { | 92 | OPimCacheItem<T>::~OPimCacheItem() { |
64 | 93 | ||
65 | } | 94 | } |
66 | template <class T> | 95 | template <class T> |
67 | T OPimCacheItem<T>::record()const { | 96 | T OPimCacheItem<T>::record()const { |
68 | return m_t; | 97 | return m_t; |
69 | } | 98 | } |
70 | template <class T> | 99 | template <class T> |
71 | void OPimCacheItem<T>::setRecord( const T& t ) { | 100 | void OPimCacheItem<T>::setRecord( const T& t ) { |
72 | m_t = t; | 101 | m_t = t; |
73 | } | 102 | } |
74 | // Cache | 103 | // Cache |
75 | template <class T> | 104 | template <class T> |
76 | OPimCache<T>::OPimCache() | 105 | OPimCache<T>::OPimCache() |
77 | : m_cache(100, 53 ) | 106 | : m_cache(100, 53 ) |
78 | { | 107 | { |
79 | m_cache.setAutoDelete( TRUE ); | 108 | m_cache.setAutoDelete( TRUE ); |
80 | } | 109 | } |
81 | template <class T> | 110 | template <class T> |
82 | OPimCache<T>::~OPimCache() { | 111 | OPimCache<T>::~OPimCache() { |
83 | 112 | ||
84 | } | 113 | } |
85 | template <class T> | 114 | template <class T> |
86 | bool OPimCache<T>::contains(int uid )const { | 115 | bool OPimCache<T>::contains(int uid )const { |
87 | Item* it = m_cache.find( uid, FALSE ); | 116 | Item* it = m_cache.find( uid, FALSE ); |
88 | if (!it) | 117 | if (!it) |
89 | return false; | 118 | return false; |
90 | return true; | 119 | return true; |
91 | } | 120 | } |
92 | template <class T> | 121 | template <class T> |
93 | void OPimCache<T>::invalidate() { | 122 | void OPimCache<T>::invalidate() { |
94 | m_cache.clear(); | 123 | m_cache.clear(); |
95 | } | 124 | } |
96 | template <class T> | 125 | template <class T> |
97 | void OPimCache<T>::setSize( int size ) { | 126 | void OPimCache<T>::setSize( int size ) { |
98 | m_cache.setMaxCost( size ); | 127 | m_cache.setMaxCost( size ); |
99 | } | 128 | } |
100 | template <class T> | 129 | template <class T> |
101 | T OPimCache<T>::find(int uid )const { | 130 | T OPimCache<T>::find(int uid )const { |
102 | Item *it = m_cache.find( uid ); | 131 | Item *it = m_cache.find( uid ); |
103 | if (it) | 132 | if (it) |
104 | return it->record(); | 133 | return it->record(); |
105 | return T(); | 134 | return T(); |
106 | } | 135 | } |
107 | template <class T> | 136 | template <class T> |
108 | void OPimCache<T>::add( const T& t ) { | 137 | void OPimCache<T>::add( const T& t ) { |
109 | Item* it = 0l; | 138 | Item* it = 0l; |
110 | it = m_cache.find(t.uid(), FALSE ); | 139 | it = m_cache.find(t.uid(), FALSE ); |
111 | 140 | ||
112 | if (it ) | 141 | if (it ) |
113 | it->setRecord( t ); | 142 | it->setRecord( t ); |
114 | 143 | ||
115 | it = new Item( t ); | 144 | it = new Item( t ); |
116 | if (!m_cache.insert( t.uid(), it ) ) | 145 | if (!m_cache.insert( t.uid(), it ) ) |
117 | delete it; | 146 | delete it; |
118 | } | 147 | } |
119 | template <class T> | 148 | template <class T> |
120 | void OPimCache<T>::remove( int uid ) { | 149 | void OPimCache<T>::remove( int uid ) { |
121 | m_cache.remove( uid ); | 150 | m_cache.remove( uid ); |
122 | } | 151 | } |
123 | template <class T> | 152 | template <class T> |
124 | void OPimCache<T>::replace( const T& t) { | 153 | void OPimCache<T>::replace( const T& t) { |
125 | Item *it = m_cache.find( t.uid() ); | 154 | Item *it = m_cache.find( t.uid() ); |
126 | if ( it ) { | 155 | if ( it ) { |
127 | it->setRecord( t ); | 156 | it->setRecord( t ); |
128 | } | 157 | } |
129 | } | 158 | } |
130 | 159 | ||
160 | } | ||
161 | |||
131 | #endif | 162 | #endif |
diff --git a/libopie2/opiepim/core/opimmaintainer.cpp b/libopie2/opiepim/core/opimmaintainer.cpp index 92cb25a..b2eff12 100644 --- a/libopie2/opiepim/core/opimmaintainer.cpp +++ b/libopie2/opiepim/core/opimmaintainer.cpp | |||
@@ -1,37 +1,69 @@ | |||
1 | #include "opimmaintainer.h" | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
2 | 29 | ||
30 | #include <opie2/opimmaintainer.h> | ||
31 | |||
32 | namespace Opie { | ||
3 | OPimMaintainer::OPimMaintainer( int mode, int uid ) | 33 | OPimMaintainer::OPimMaintainer( int mode, int uid ) |
4 | : m_mode(mode), m_uid(uid ) | 34 | : m_mode(mode), m_uid(uid ) |
5 | {} | 35 | {} |
6 | OPimMaintainer::~OPimMaintainer() { | 36 | OPimMaintainer::~OPimMaintainer() { |
7 | } | 37 | } |
8 | OPimMaintainer::OPimMaintainer( const OPimMaintainer& main ) { | 38 | OPimMaintainer::OPimMaintainer( const OPimMaintainer& main ) { |
9 | *this = main; | 39 | *this = main; |
10 | } | 40 | } |
11 | OPimMaintainer &OPimMaintainer::operator=( const OPimMaintainer& main ) { | 41 | OPimMaintainer &OPimMaintainer::operator=( const OPimMaintainer& main ) { |
12 | m_mode = main.m_mode; | 42 | m_mode = main.m_mode; |
13 | m_uid = main.m_uid; | 43 | m_uid = main.m_uid; |
14 | 44 | ||
15 | return *this; | 45 | return *this; |
16 | } | 46 | } |
17 | bool OPimMaintainer::operator==( const OPimMaintainer& main ) { | 47 | bool OPimMaintainer::operator==( const OPimMaintainer& main ) { |
18 | if (m_mode != main.m_mode ) return false; | 48 | if (m_mode != main.m_mode ) return false; |
19 | if (m_uid != main.m_uid ) return false; | 49 | if (m_uid != main.m_uid ) return false; |
20 | 50 | ||
21 | return true; | 51 | return true; |
22 | } | 52 | } |
23 | bool OPimMaintainer::operator!=( const OPimMaintainer& main ) { | 53 | bool OPimMaintainer::operator!=( const OPimMaintainer& main ) { |
24 | return !(*this == main ); | 54 | return !(*this == main ); |
25 | } | 55 | } |
26 | int OPimMaintainer::mode()const { | 56 | int OPimMaintainer::mode()const { |
27 | return m_mode; | 57 | return m_mode; |
28 | } | 58 | } |
29 | int OPimMaintainer::uid()const { | 59 | int OPimMaintainer::uid()const { |
30 | return m_uid; | 60 | return m_uid; |
31 | } | 61 | } |
32 | void OPimMaintainer::setMode( int mo) { | 62 | void OPimMaintainer::setMode( int mo) { |
33 | m_mode = mo; | 63 | m_mode = mo; |
34 | } | 64 | } |
35 | void OPimMaintainer::setUid( int uid ) { | 65 | void OPimMaintainer::setUid( int uid ) { |
36 | m_uid = uid; | 66 | m_uid = uid; |
37 | } | 67 | } |
68 | |||
69 | } | ||
diff --git a/libopie2/opiepim/core/opimmaintainer.h b/libopie2/opiepim/core/opimmaintainer.h index 793d066..46bc9d2 100644 --- a/libopie2/opiepim/core/opimmaintainer.h +++ b/libopie2/opiepim/core/opimmaintainer.h | |||
@@ -1,40 +1,71 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_MAINTAINER_H | 29 | #ifndef OPIE_PIM_MAINTAINER_H |
2 | #define OPIE_PIM_MAINTAINER_H | 30 | #define OPIE_PIM_MAINTAINER_H |
3 | 31 | ||
4 | #include <qstring.h> | 32 | #include <qstring.h> |
5 | 33 | ||
34 | namespace Opie { | ||
6 | /** | 35 | /** |
7 | * Who maintains what? | 36 | * Who maintains what? |
8 | */ | 37 | */ |
9 | class OPimMaintainer { | 38 | class OPimMaintainer { |
10 | public: | 39 | public: |
11 | enum Mode { Undefined = -1, | 40 | enum Mode { Undefined = -1, |
12 | Nothing = 0, | 41 | Nothing = 0, |
13 | Responsible, | 42 | Responsible, |
14 | DoneBy, | 43 | DoneBy, |
15 | Coordinating, | 44 | Coordinating, |
16 | }; | 45 | }; |
17 | OPimMaintainer( int mode = Undefined, int uid = 0); | 46 | OPimMaintainer( int mode = Undefined, int uid = 0); |
18 | OPimMaintainer( const OPimMaintainer& ); | 47 | OPimMaintainer( const OPimMaintainer& ); |
19 | ~OPimMaintainer(); | 48 | ~OPimMaintainer(); |
20 | 49 | ||
21 | OPimMaintainer &operator=( const OPimMaintainer& ); | 50 | OPimMaintainer &operator=( const OPimMaintainer& ); |
22 | bool operator==( const OPimMaintainer& ); | 51 | bool operator==( const OPimMaintainer& ); |
23 | bool operator!=( const OPimMaintainer& ); | 52 | bool operator!=( const OPimMaintainer& ); |
24 | 53 | ||
25 | 54 | ||
26 | int mode()const; | 55 | int mode()const; |
27 | int uid()const; | 56 | int uid()const; |
28 | 57 | ||
29 | void setMode( int mode ); | 58 | void setMode( int mode ); |
30 | void setUid( int uid ); | 59 | void setUid( int uid ); |
31 | 60 | ||
32 | private: | 61 | private: |
33 | int m_mode; | 62 | int m_mode; |
34 | int m_uid; | 63 | int m_uid; |
35 | class Private; | 64 | class Private; |
36 | Private *d; | 65 | Private *d; |
37 | 66 | ||
38 | }; | 67 | }; |
39 | 68 | ||
69 | } | ||
70 | |||
40 | #endif | 71 | #endif |
diff --git a/libopie2/opiepim/core/opimnotify.cpp b/libopie2/opiepim/core/opimnotify.cpp index af5514b..c61f9da 100644 --- a/libopie2/opiepim/core/opimnotify.cpp +++ b/libopie2/opiepim/core/opimnotify.cpp | |||
@@ -1,227 +1,258 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qshared.h> | 29 | #include <qshared.h> |
2 | 30 | ||
3 | #include "opimnotify.h" | 31 | #include <opie2/opimnotify.h> |
32 | |||
33 | namespace Opie { | ||
4 | 34 | ||
5 | struct OPimNotify::Data : public QShared { | 35 | struct OPimNotify::Data : public QShared { |
6 | Data() : QShared(),dur(-1),parent(0) { | 36 | Data() : QShared(),dur(-1),parent(0) { |
7 | 37 | ||
8 | } | 38 | } |
9 | QDateTime start; | 39 | QDateTime start; |
10 | int dur; | 40 | int dur; |
11 | QString application; | 41 | QString application; |
12 | int parent; | 42 | int parent; |
13 | }; | 43 | }; |
14 | 44 | ||
15 | OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) { | 45 | OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) { |
16 | data = new Data; | 46 | data = new Data; |
17 | data->start = start; | 47 | data->start = start; |
18 | data->dur = duration; | 48 | data->dur = duration; |
19 | data->parent = parent; | 49 | data->parent = parent; |
20 | } | 50 | } |
21 | OPimNotify::OPimNotify( const OPimNotify& noti) | 51 | OPimNotify::OPimNotify( const OPimNotify& noti) |
22 | : data( noti.data ) | 52 | : data( noti.data ) |
23 | { | 53 | { |
24 | data->ref(); | 54 | data->ref(); |
25 | } | 55 | } |
26 | OPimNotify::~OPimNotify() { | 56 | OPimNotify::~OPimNotify() { |
27 | if ( data->deref() ) { | 57 | if ( data->deref() ) { |
28 | delete data; | 58 | delete data; |
29 | data = 0l; | 59 | data = 0l; |
30 | } | 60 | } |
31 | } | 61 | } |
32 | 62 | ||
33 | OPimNotify &OPimNotify::operator=( const OPimNotify& noti) { | 63 | OPimNotify &OPimNotify::operator=( const OPimNotify& noti) { |
34 | noti.data->ref(); | 64 | noti.data->ref(); |
35 | deref(); | 65 | deref(); |
36 | data = noti.data; | 66 | data = noti.data; |
37 | 67 | ||
38 | return *this; | 68 | return *this; |
39 | } | 69 | } |
40 | bool OPimNotify::operator==( const OPimNotify& noti ) { | 70 | bool OPimNotify::operator==( const OPimNotify& noti ) { |
41 | if ( data == noti.data ) return true; | 71 | if ( data == noti.data ) return true; |
42 | if ( data->dur != noti.data->dur ) return false; | 72 | if ( data->dur != noti.data->dur ) return false; |
43 | if ( data->parent != noti.data->parent ) return false; | 73 | if ( data->parent != noti.data->parent ) return false; |
44 | if ( data->application != noti.data->application ) return false; | 74 | if ( data->application != noti.data->application ) return false; |
45 | if ( data->start != noti.data->start ) return false; | 75 | if ( data->start != noti.data->start ) return false; |
46 | 76 | ||
47 | return true; | 77 | return true; |
48 | } | 78 | } |
49 | QDateTime OPimNotify::dateTime()const { | 79 | QDateTime OPimNotify::dateTime()const { |
50 | return data->start; | 80 | return data->start; |
51 | } | 81 | } |
52 | QString OPimNotify::service()const { | 82 | QString OPimNotify::service()const { |
53 | return data->application; | 83 | return data->application; |
54 | } | 84 | } |
55 | int OPimNotify::parent()const { | 85 | int OPimNotify::parent()const { |
56 | return data->parent; | 86 | return data->parent; |
57 | } | 87 | } |
58 | int OPimNotify::duration()const { | 88 | int OPimNotify::duration()const { |
59 | return data->dur; | 89 | return data->dur; |
60 | } | 90 | } |
61 | QDateTime OPimNotify::endTime()const { | 91 | QDateTime OPimNotify::endTime()const { |
62 | return QDateTime( data->start.date(), data->start.time().addSecs( data->dur) ); | 92 | return QDateTime( data->start.date(), data->start.time().addSecs( data->dur) ); |
63 | } | 93 | } |
64 | void OPimNotify::setDateTime( const QDateTime& time ) { | 94 | void OPimNotify::setDateTime( const QDateTime& time ) { |
65 | copyIntern(); | 95 | copyIntern(); |
66 | data->start = time; | 96 | data->start = time; |
67 | } | 97 | } |
68 | void OPimNotify::setDuration( int dur ) { | 98 | void OPimNotify::setDuration( int dur ) { |
69 | copyIntern(); | 99 | copyIntern(); |
70 | data->dur = dur; | 100 | data->dur = dur; |
71 | } | 101 | } |
72 | void OPimNotify::setParent( int uid ) { | 102 | void OPimNotify::setParent( int uid ) { |
73 | copyIntern(); | 103 | copyIntern(); |
74 | data->parent = uid; | 104 | data->parent = uid; |
75 | } | 105 | } |
76 | void OPimNotify::setService( const QString& str ) { | 106 | void OPimNotify::setService( const QString& str ) { |
77 | copyIntern(); | 107 | copyIntern(); |
78 | data->application = str; | 108 | data->application = str; |
79 | } | 109 | } |
80 | void OPimNotify::copyIntern() { | 110 | void OPimNotify::copyIntern() { |
81 | if ( data->count != 1 ) { | 111 | if ( data->count != 1 ) { |
82 | data->deref(); | 112 | data->deref(); |
83 | Data* dat = new Data; | 113 | Data* dat = new Data; |
84 | dat->start = data->start; | 114 | dat->start = data->start; |
85 | dat->dur = data->dur; | 115 | dat->dur = data->dur; |
86 | dat->application = data->application; | 116 | dat->application = data->application; |
87 | dat->parent = data->parent; | 117 | dat->parent = data->parent; |
88 | data = dat; | 118 | data = dat; |
89 | } | 119 | } |
90 | } | 120 | } |
91 | void OPimNotify::deref() { | 121 | void OPimNotify::deref() { |
92 | if ( data->deref() ) { | 122 | if ( data->deref() ) { |
93 | delete data; | 123 | delete data; |
94 | data = 0; | 124 | data = 0; |
95 | } | 125 | } |
96 | } | 126 | } |
97 | 127 | ||
98 | /***********************************************************/ | 128 | /***********************************************************/ |
99 | struct OPimAlarm::Data : public QShared { | 129 | struct OPimAlarm::Data : public QShared { |
100 | Data() : QShared() { | 130 | Data() : QShared() { |
101 | sound = 1; | 131 | sound = 1; |
102 | } | 132 | } |
103 | int sound; | 133 | int sound; |
104 | QString file; | 134 | QString file; |
105 | }; | 135 | }; |
106 | OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent ) | 136 | OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent ) |
107 | : OPimNotify( start, duration, parent ) | 137 | : OPimNotify( start, duration, parent ) |
108 | { | 138 | { |
109 | data = new Data; | 139 | data = new Data; |
110 | data->sound = sound; | 140 | data->sound = sound; |
111 | } | 141 | } |
112 | OPimAlarm::OPimAlarm( const OPimAlarm& al) | 142 | OPimAlarm::OPimAlarm( const OPimAlarm& al) |
113 | : OPimNotify(al), data( al.data ) | 143 | : OPimNotify(al), data( al.data ) |
114 | { | 144 | { |
115 | data->ref(); | 145 | data->ref(); |
116 | } | 146 | } |
117 | OPimAlarm::~OPimAlarm() { | 147 | OPimAlarm::~OPimAlarm() { |
118 | if ( data->deref() ) { | 148 | if ( data->deref() ) { |
119 | delete data; | 149 | delete data; |
120 | data = 0l; | 150 | data = 0l; |
121 | } | 151 | } |
122 | } | 152 | } |
123 | OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al) | 153 | OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al) |
124 | { | 154 | { |
125 | OPimNotify::operator=( al ); | 155 | OPimNotify::operator=( al ); |
126 | deref(); | 156 | deref(); |
127 | al.data->ref(); | 157 | al.data->ref(); |
128 | 158 | ||
129 | data = al.data; | 159 | data = al.data; |
130 | 160 | ||
131 | 161 | ||
132 | return *this; | 162 | return *this; |
133 | } | 163 | } |
134 | bool OPimAlarm::operator==( const OPimAlarm& al) { | 164 | bool OPimAlarm::operator==( const OPimAlarm& al) { |
135 | if ( data->sound != al.data->sound ) return false; | 165 | if ( data->sound != al.data->sound ) return false; |
136 | else if ( data->sound == Custom && data->file != al.data->file ) | 166 | else if ( data->sound == Custom && data->file != al.data->file ) |
137 | return false; | 167 | return false; |
138 | 168 | ||
139 | return OPimNotify::operator==( al ); | 169 | return OPimNotify::operator==( al ); |
140 | } | 170 | } |
141 | QString OPimAlarm::type()const { | 171 | QString OPimAlarm::type()const { |
142 | return QString::fromLatin1("OPimAlarm"); | 172 | return QString::fromLatin1("OPimAlarm"); |
143 | } | 173 | } |
144 | int OPimAlarm::sound()const { | 174 | int OPimAlarm::sound()const { |
145 | return data->sound; | 175 | return data->sound; |
146 | } | 176 | } |
147 | QString OPimAlarm::file()const { | 177 | QString OPimAlarm::file()const { |
148 | return data->file; | 178 | return data->file; |
149 | } | 179 | } |
150 | void OPimAlarm::setSound( int snd) { | 180 | void OPimAlarm::setSound( int snd) { |
151 | copyIntern(); | 181 | copyIntern(); |
152 | data->sound = snd; | 182 | data->sound = snd; |
153 | } | 183 | } |
154 | void OPimAlarm::setFile( const QString& sound ) { | 184 | void OPimAlarm::setFile( const QString& sound ) { |
155 | copyIntern(); | 185 | copyIntern(); |
156 | data->file = sound; | 186 | data->file = sound; |
157 | } | 187 | } |
158 | void OPimAlarm::deref() { | 188 | void OPimAlarm::deref() { |
159 | if ( data->deref() ) { | 189 | if ( data->deref() ) { |
160 | delete data; | 190 | delete data; |
161 | data = 0l; | 191 | data = 0l; |
162 | } | 192 | } |
163 | } | 193 | } |
164 | void OPimAlarm::copyIntern() { | 194 | void OPimAlarm::copyIntern() { |
165 | if ( data->count != 1 ) { | 195 | if ( data->count != 1 ) { |
166 | data->deref(); | 196 | data->deref(); |
167 | Data *newDat = new Data; | 197 | Data *newDat = new Data; |
168 | newDat->sound = data->sound; | 198 | newDat->sound = data->sound; |
169 | newDat->file = data->file; | 199 | newDat->file = data->file; |
170 | data = newDat; | 200 | data = newDat; |
171 | } | 201 | } |
172 | } | 202 | } |
173 | /************************/ | 203 | /************************/ |
174 | struct OPimReminder::Data : public QShared { | 204 | struct OPimReminder::Data : public QShared { |
175 | Data() : QShared(), record( 0) { | 205 | Data() : QShared(), record( 0) { |
176 | } | 206 | } |
177 | int record; | 207 | int record; |
178 | 208 | ||
179 | }; | 209 | }; |
180 | OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent ) | 210 | OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent ) |
181 | : OPimNotify( start, dur, parent ) | 211 | : OPimNotify( start, dur, parent ) |
182 | { | 212 | { |
183 | data = new Data; | 213 | data = new Data; |
184 | data->record = uid; | 214 | data->record = uid; |
185 | } | 215 | } |
186 | OPimReminder::OPimReminder( const OPimReminder& rem ) | 216 | OPimReminder::OPimReminder( const OPimReminder& rem ) |
187 | : OPimNotify( rem ), data( rem.data ) | 217 | : OPimNotify( rem ), data( rem.data ) |
188 | { | 218 | { |
189 | data->ref(); | 219 | data->ref(); |
190 | } | 220 | } |
191 | OPimReminder& OPimReminder::operator=( const OPimReminder& rem) { | 221 | OPimReminder& OPimReminder::operator=( const OPimReminder& rem) { |
192 | OPimNotify::operator=(rem ); | 222 | OPimNotify::operator=(rem ); |
193 | 223 | ||
194 | deref(); | 224 | deref(); |
195 | rem.data->ref(); | 225 | rem.data->ref(); |
196 | data = rem.data; | 226 | data = rem.data; |
197 | 227 | ||
198 | return *this; | 228 | return *this; |
199 | } | 229 | } |
200 | bool OPimReminder::operator==( const OPimReminder& rem) { | 230 | bool OPimReminder::operator==( const OPimReminder& rem) { |
201 | if ( data->record != rem.data->record ) return false; | 231 | if ( data->record != rem.data->record ) return false; |
202 | 232 | ||
203 | return OPimNotify::operator==( rem ); | 233 | return OPimNotify::operator==( rem ); |
204 | } | 234 | } |
205 | QString OPimReminder::type()const { | 235 | QString OPimReminder::type()const { |
206 | return QString::fromLatin1("OPimReminder"); | 236 | return QString::fromLatin1("OPimReminder"); |
207 | } | 237 | } |
208 | int OPimReminder::recordUid()const { | 238 | int OPimReminder::recordUid()const { |
209 | return data->record; | 239 | return data->record; |
210 | } | 240 | } |
211 | void OPimReminder::setRecordUid( int uid ) { | 241 | void OPimReminder::setRecordUid( int uid ) { |
212 | copyIntern(); | 242 | copyIntern(); |
213 | data->record = uid; | 243 | data->record = uid; |
214 | } | 244 | } |
215 | void OPimReminder::deref() { | 245 | void OPimReminder::deref() { |
216 | if ( data->deref() ) { | 246 | if ( data->deref() ) { |
217 | delete data; | 247 | delete data; |
218 | data = 0l; | 248 | data = 0l; |
219 | } | 249 | } |
220 | } | 250 | } |
221 | void OPimReminder::copyIntern() { | 251 | void OPimReminder::copyIntern() { |
222 | if ( data->count != 1 ) { | 252 | if ( data->count != 1 ) { |
223 | Data* da = new Data; | 253 | Data* da = new Data; |
224 | da->record = data->record; | 254 | da->record = data->record; |
225 | data = da; | 255 | data = da; |
226 | } | 256 | } |
227 | } | 257 | } |
258 | } | ||
diff --git a/libopie2/opiepim/core/opimnotify.h b/libopie2/opiepim/core/opimnotify.h index 58417db..fed3970 100644 --- a/libopie2/opiepim/core/opimnotify.h +++ b/libopie2/opiepim/core/opimnotify.h | |||
@@ -1,144 +1,176 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_NOTIFY_H | 29 | #ifndef OPIE_PIM_NOTIFY_H |
2 | #define OPIE_PIM_NOTIFY_H | 30 | #define OPIE_PIM_NOTIFY_H |
3 | 31 | ||
4 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
5 | #include <qvaluelist.h> | 33 | #include <qvaluelist.h> |
6 | 34 | ||
35 | |||
36 | namespace Opie { | ||
7 | /** | 37 | /** |
8 | * This is the base class of Notifiers. Possible | 38 | * This is the base class of Notifiers. Possible |
9 | * notifiers would be Alarms, Reminders | 39 | * notifiers would be Alarms, Reminders |
10 | * What they share is that they have | 40 | * What they share is that they have |
11 | * A DateTime, Type, Duration | 41 | * A DateTime, Type, Duration |
12 | * This is what this base class takes care of | 42 | * This is what this base class takes care of |
13 | * on top of that it's shared | 43 | * on top of that it's shared |
14 | */ | 44 | */ |
15 | /* | 45 | /* |
16 | * TALK to eilers: have a class OPimDuration which sets the Duration | 46 | * TALK to eilers: have a class OPimDuration which sets the Duration |
17 | * given on the Due/Start Date? -zecke | 47 | * given on the Due/Start Date? -zecke |
18 | * discuss: do we need a uid for the notify? -zecke | 48 | * discuss: do we need a uid for the notify? -zecke |
19 | */ | 49 | */ |
20 | class OPimNotify { | 50 | class OPimNotify { |
21 | public: | 51 | public: |
22 | typedef QValueList<OPimNotify> ValueList; | 52 | typedef QValueList<OPimNotify> ValueList; |
23 | OPimNotify( const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 ); | 53 | OPimNotify( const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 ); |
24 | OPimNotify( const OPimNotify& ); | 54 | OPimNotify( const OPimNotify& ); |
25 | virtual ~OPimNotify(); | 55 | virtual ~OPimNotify(); |
26 | 56 | ||
27 | OPimNotify &operator=(const OPimNotify& ); | 57 | OPimNotify &operator=(const OPimNotify& ); |
28 | bool operator==( const OPimNotify& ); | 58 | bool operator==( const OPimNotify& ); |
29 | 59 | ||
30 | virtual QString type()const = 0; | 60 | virtual QString type()const = 0; |
31 | 61 | ||
32 | /** start date */ | 62 | /** start date */ |
33 | QDateTime dateTime()const; | 63 | QDateTime dateTime()const; |
34 | QString service()const; | 64 | QString service()const; |
35 | 65 | ||
36 | /** | 66 | /** |
37 | * RETURN the parent uid | 67 | * RETURN the parent uid |
38 | */ | 68 | */ |
39 | int parent()const; | 69 | int parent()const; |
40 | 70 | ||
41 | /** | 71 | /** |
42 | * in Seconds | 72 | * in Seconds |
43 | */ | 73 | */ |
44 | int duration()const; | 74 | int duration()const; |
45 | 75 | ||
46 | /** | 76 | /** |
47 | * Start Time + Duration | 77 | * Start Time + Duration |
48 | */ | 78 | */ |
49 | QDateTime endTime()const; | 79 | QDateTime endTime()const; |
50 | 80 | ||
51 | void setDateTime( const QDateTime& ); | 81 | void setDateTime( const QDateTime& ); |
52 | void setDuration( int dur ); | 82 | void setDuration( int dur ); |
53 | void setParent(int uid ); | 83 | void setParent(int uid ); |
54 | void setService( const QString& ); | 84 | void setService( const QString& ); |
55 | 85 | ||
56 | 86 | ||
57 | private: | 87 | private: |
58 | inline void copyIntern(); | 88 | inline void copyIntern(); |
59 | void deref(); | 89 | void deref(); |
60 | struct Data; | 90 | struct Data; |
61 | Data* data; | 91 | Data* data; |
62 | 92 | ||
63 | /* d-pointer */ | 93 | /* d-pointer */ |
64 | class NotifyPrivate; | 94 | class NotifyPrivate; |
65 | NotifyPrivate* d; | 95 | NotifyPrivate* d; |
66 | 96 | ||
67 | }; | 97 | }; |
68 | /** | 98 | /** |
69 | * An alarm is a sound/mail/buzzer played/send | 99 | * An alarm is a sound/mail/buzzer played/send |
70 | * at a given time to inform about | 100 | * at a given time to inform about |
71 | * an Event | 101 | * an Event |
72 | */ | 102 | */ |
73 | class OPimAlarm : public OPimNotify { | 103 | class OPimAlarm : public OPimNotify { |
74 | public: | 104 | public: |
75 | enum Sound{Loud=1, Silent=0, Custom=2 }; | 105 | enum Sound{Loud=1, Silent=0, Custom=2 }; |
76 | OPimAlarm( int sound = Silent, const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 ); | 106 | OPimAlarm( int sound = Silent, const QDateTime& start = QDateTime(), int duration = 0, int parent = 0 ); |
77 | OPimAlarm( const OPimAlarm& ); | 107 | OPimAlarm( const OPimAlarm& ); |
78 | ~OPimAlarm(); | 108 | ~OPimAlarm(); |
79 | 109 | ||
80 | OPimAlarm &operator=( const OPimAlarm& ); | 110 | OPimAlarm &operator=( const OPimAlarm& ); |
81 | bool operator==( const OPimAlarm& ); | 111 | bool operator==( const OPimAlarm& ); |
82 | QString type()const; | 112 | QString type()const; |
83 | 113 | ||
84 | int sound()const; | 114 | int sound()const; |
85 | QString file()const; | 115 | QString file()const; |
86 | 116 | ||
87 | void setSound( int ); | 117 | void setSound( int ); |
88 | /* only when sound is custom... */ | 118 | /* only when sound is custom... */ |
89 | void setFile( const QString& sound ); | 119 | void setFile( const QString& sound ); |
90 | 120 | ||
91 | private: | 121 | private: |
92 | void deref(); | 122 | void deref(); |
93 | void copyIntern(); | 123 | void copyIntern(); |
94 | struct Data; | 124 | struct Data; |
95 | Data * data; | 125 | Data * data; |
96 | 126 | ||
97 | class Private; | 127 | class Private; |
98 | Private* d; | 128 | Private* d; |
99 | 129 | ||
100 | }; | 130 | }; |
101 | 131 | ||
102 | /** | 132 | /** |
103 | * A Reminder will be put into the | 133 | * A Reminder will be put into the |
104 | * datebook | 134 | * datebook |
105 | * Note that the returned dateTime() may be not valid. | 135 | * Note that the returned dateTime() may be not valid. |
106 | * In these cases one must resolve the uid and get the OEvent | 136 | * In these cases one must resolve the uid and get the OEvent |
107 | */ | 137 | */ |
108 | class OPimReminder : public OPimNotify { | 138 | class OPimReminder : public OPimNotify { |
109 | public: | 139 | public: |
110 | 140 | ||
111 | /** | 141 | /** |
112 | * c'tor of a reminder | 142 | * c'tor of a reminder |
113 | * @param uid The uid of the Record inside the Datebook | 143 | * @param uid The uid of the Record inside the Datebook |
114 | * @param start the StartDate invalid for all day... | 144 | * @param start the StartDate invalid for all day... |
115 | * @param duration The duration of the event ( -1 for all day ) | 145 | * @param duration The duration of the event ( -1 for all day ) |
116 | * @param parent The 'parent' record of this reminder | 146 | * @param parent The 'parent' record of this reminder |
117 | */ | 147 | */ |
118 | OPimReminder( int uid = 0, const QDateTime& start = QDateTime(), | 148 | OPimReminder( int uid = 0, const QDateTime& start = QDateTime(), |
119 | int duration = 0, int parent = 0 ); | 149 | int duration = 0, int parent = 0 ); |
120 | OPimReminder( const OPimReminder& ); | 150 | OPimReminder( const OPimReminder& ); |
121 | OPimReminder &operator=(const OPimReminder& ); | 151 | OPimReminder &operator=(const OPimReminder& ); |
122 | 152 | ||
123 | QString type()const; | 153 | QString type()const; |
124 | 154 | ||
125 | bool operator==( const OPimReminder& ); | 155 | bool operator==( const OPimReminder& ); |
126 | 156 | ||
127 | /** | 157 | /** |
128 | * the uid of the alarm | 158 | * the uid of the alarm |
129 | * inside the 'datebook' application | 159 | * inside the 'datebook' application |
130 | */ | 160 | */ |
131 | int recordUid()const; | 161 | int recordUid()const; |
132 | void setRecordUid( int uid ); | 162 | void setRecordUid( int uid ); |
133 | 163 | ||
134 | private: | 164 | private: |
135 | void deref(); | 165 | void deref(); |
136 | void copyIntern(); | 166 | void copyIntern(); |
137 | 167 | ||
138 | struct Data; | 168 | struct Data; |
139 | Data* data; | 169 | Data* data; |
140 | class Private; | 170 | class Private; |
141 | Private *d; | 171 | Private *d; |
142 | }; | 172 | }; |
143 | 173 | ||
174 | } | ||
175 | |||
144 | #endif | 176 | #endif |
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp index d6f0ead..1771fad 100644 --- a/libopie2/opiepim/core/opimnotifymanager.cpp +++ b/libopie2/opiepim/core/opimnotifymanager.cpp | |||
@@ -1,162 +1,193 @@ | |||
1 | #include "opimnotifymanager.h" | 1 | /* |
2 | 2 | This file is part of the Opie Project | |
3 | #include "oconversion.h" | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | #include <opie2/opimnotifymanager.h> | ||
30 | |||
31 | #include <opie2/oconversion.h> | ||
4 | 32 | ||
5 | #include <qstringlist.h> | 33 | #include <qstringlist.h> |
6 | 34 | ||
35 | namespace Opie { | ||
36 | |||
7 | OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) | 37 | OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) |
8 | : m_rem( rem ), m_al( al ) | 38 | : m_rem( rem ), m_al( al ) |
9 | {} | 39 | {} |
10 | OPimNotifyManager::~OPimNotifyManager() { | 40 | OPimNotifyManager::~OPimNotifyManager() { |
11 | } | 41 | } |
12 | /* use static_cast and type instead of dynamic... */ | 42 | /* use static_cast and type instead of dynamic... */ |
13 | void OPimNotifyManager::add( const OPimNotify& noti) { | 43 | void OPimNotifyManager::add( const OPimNotify& noti) { |
14 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | 44 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { |
15 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 45 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); |
16 | m_rem.append( rem ); | 46 | m_rem.append( rem ); |
17 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | 47 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { |
18 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 48 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); |
19 | m_al.append( al ); | 49 | m_al.append( al ); |
20 | } | 50 | } |
21 | } | 51 | } |
22 | void OPimNotifyManager::remove( const OPimNotify& noti) { | 52 | void OPimNotifyManager::remove( const OPimNotify& noti) { |
23 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | 53 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { |
24 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 54 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); |
25 | m_rem.remove( rem ); | 55 | m_rem.remove( rem ); |
26 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | 56 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { |
27 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 57 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); |
28 | m_al.remove( al ); | 58 | m_al.remove( al ); |
29 | } | 59 | } |
30 | } | 60 | } |
31 | void OPimNotifyManager::replace( const OPimNotify& noti) { | 61 | void OPimNotifyManager::replace( const OPimNotify& noti) { |
32 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { | 62 | if ( noti.type() == QString::fromLatin1("OPimReminder") ) { |
33 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); | 63 | const OPimReminder& rem = static_cast<const OPimReminder&>(noti); |
34 | m_rem.remove( rem ); | 64 | m_rem.remove( rem ); |
35 | m_rem.append( rem ); | 65 | m_rem.append( rem ); |
36 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { | 66 | }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { |
37 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); | 67 | const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); |
38 | m_al.remove( al ); | 68 | m_al.remove( al ); |
39 | m_al.append( al ); | 69 | m_al.append( al ); |
40 | } | 70 | } |
41 | } | 71 | } |
42 | OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { | 72 | OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { |
43 | return m_rem; | 73 | return m_rem; |
44 | } | 74 | } |
45 | OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { | 75 | OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { |
46 | return m_al; | 76 | return m_al; |
47 | } | 77 | } |
48 | OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const { | 78 | OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const { |
49 | Alarms::ConstIterator it; | 79 | Alarms::ConstIterator it; |
50 | found = true; | 80 | found = true; |
51 | 81 | ||
52 | for ( it = m_al.begin(); it != m_al.end(); ++it ){ | 82 | for ( it = m_al.begin(); it != m_al.end(); ++it ){ |
53 | if ( (*it).dateTime() == when ) | 83 | if ( (*it).dateTime() == when ) |
54 | return (*it); | 84 | return (*it); |
55 | } | 85 | } |
56 | 86 | ||
57 | // Fall through if nothing could be found | 87 | // Fall through if nothing could be found |
58 | found = false; | 88 | found = false; |
59 | OPimAlarm empty; | 89 | OPimAlarm empty; |
60 | return empty; | 90 | return empty; |
61 | } | 91 | } |
62 | 92 | ||
63 | 93 | ||
64 | void OPimNotifyManager::setAlarms( const Alarms& al) { | 94 | void OPimNotifyManager::setAlarms( const Alarms& al) { |
65 | m_al = al; | 95 | m_al = al; |
66 | } | 96 | } |
67 | void OPimNotifyManager::setReminders( const Reminders& rem) { | 97 | void OPimNotifyManager::setReminders( const Reminders& rem) { |
68 | m_rem = rem; | 98 | m_rem = rem; |
69 | } | 99 | } |
70 | /* FIXME!!! */ | 100 | /* FIXME!!! */ |
71 | /** | 101 | /** |
72 | * The idea is to check if the provider for our service | 102 | * The idea is to check if the provider for our service |
73 | * is online | 103 | * is online |
74 | * if it is we will use QCOP | 104 | * if it is we will use QCOP |
75 | * if not the Factory to get the backend... | 105 | * if not the Factory to get the backend... |
76 | * Qtopia1.6 services would be kewl to have here.... | 106 | * Qtopia1.6 services would be kewl to have here.... |
77 | */ | 107 | */ |
78 | void OPimNotifyManager::registerNotify( const OPimNotify& ) { | 108 | void OPimNotifyManager::registerNotify( const OPimNotify& ) { |
79 | 109 | ||
80 | } | 110 | } |
81 | /* FIXME!!! */ | 111 | /* FIXME!!! */ |
82 | /** | 112 | /** |
83 | * same as above... | 113 | * same as above... |
84 | * Also implement Url model | 114 | * Also implement Url model |
85 | * have a MainWindow.... | 115 | * have a MainWindow.... |
86 | */ | 116 | */ |
87 | void OPimNotifyManager::deregister( const OPimNotify& ) { | 117 | void OPimNotifyManager::deregister( const OPimNotify& ) { |
88 | 118 | ||
89 | } | 119 | } |
90 | 120 | ||
91 | bool OPimNotifyManager::isEmpty()const { | 121 | bool OPimNotifyManager::isEmpty()const { |
92 | qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); | 122 | qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); |
93 | if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; | 123 | if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; |
94 | else return false; | 124 | else return false; |
95 | } | 125 | } |
96 | 126 | ||
97 | // Taken from otodoaccessxml.. | 127 | // Taken from otodoaccessxml.. |
98 | QString OPimNotifyManager::alarmsToString() const | 128 | QString OPimNotifyManager::alarmsToString() const |
99 | { | 129 | { |
100 | QString str; | 130 | QString str; |
101 | 131 | ||
102 | OPimNotifyManager::Alarms alarms = m_al; | 132 | OPimNotifyManager::Alarms alarms = m_al; |
103 | if ( !alarms.isEmpty() ) { | 133 | if ( !alarms.isEmpty() ) { |
104 | QStringList als; | 134 | QStringList als; |
105 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); | 135 | OPimNotifyManager::Alarms::Iterator it = alarms.begin(); |
106 | for ( ; it != alarms.end(); ++it ) { | 136 | for ( ; it != alarms.end(); ++it ) { |
107 | /* only if time is valid */ | 137 | /* only if time is valid */ |
108 | if ( (*it).dateTime().isValid() ) { | 138 | if ( (*it).dateTime().isValid() ) { |
109 | als << OConversion::dateTimeToString( (*it).dateTime() ) | 139 | als << OConversion::dateTimeToString( (*it).dateTime() ) |
110 | + ":" + QString::number( (*it).duration() ) | 140 | + ":" + QString::number( (*it).duration() ) |
111 | + ":" + QString::number( (*it).sound() ) | 141 | + ":" + QString::number( (*it).sound() ) |
112 | + ":"; | 142 | + ":"; |
113 | } | 143 | } |
114 | } | 144 | } |
115 | // now write the list | 145 | // now write the list |
116 | qWarning("als: %s", als.join("____________").latin1() ); | 146 | qWarning("als: %s", als.join("____________").latin1() ); |
117 | str = als.join(";"); | 147 | str = als.join(";"); |
118 | } | 148 | } |
119 | 149 | ||
120 | return str; | 150 | return str; |
121 | } | 151 | } |
122 | QString OPimNotifyManager::remindersToString() const | 152 | QString OPimNotifyManager::remindersToString() const |
123 | { | 153 | { |
124 | QString str; | 154 | QString str; |
125 | 155 | ||
126 | OPimNotifyManager::Reminders reminders = m_rem; | 156 | OPimNotifyManager::Reminders reminders = m_rem; |
127 | if (!reminders.isEmpty() ) { | 157 | if (!reminders.isEmpty() ) { |
128 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); | 158 | OPimNotifyManager::Reminders::Iterator it = reminders.begin(); |
129 | QStringList records; | 159 | QStringList records; |
130 | for ( ; it != reminders.end(); ++it ) { | 160 | for ( ; it != reminders.end(); ++it ) { |
131 | records << QString::number( (*it).recordUid() ); | 161 | records << QString::number( (*it).recordUid() ); |
132 | } | 162 | } |
133 | str = records.join(";"); | 163 | str = records.join(";"); |
134 | } | 164 | } |
135 | 165 | ||
136 | return str; | 166 | return str; |
137 | } | 167 | } |
138 | 168 | ||
139 | void OPimNotifyManager::alarmsFromString( const QString& str ) | 169 | void OPimNotifyManager::alarmsFromString( const QString& str ) |
140 | { | 170 | { |
141 | QStringList als = QStringList::split(";", str ); | 171 | QStringList als = QStringList::split(";", str ); |
142 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { | 172 | for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { |
143 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty | 173 | QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty |
144 | qWarning("alarm: %s", alarm.join("___").latin1() ); | 174 | qWarning("alarm: %s", alarm.join("___").latin1() ); |
145 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), | 175 | qWarning("alarm[0]: %s %s", alarm[0].latin1(), |
146 | OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); | 176 | OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); |
147 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), | 177 | OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), |
148 | alarm[1].toInt() ); | 178 | alarm[1].toInt() ); |
149 | add( al ); | 179 | add( al ); |
150 | } | 180 | } |
151 | } | 181 | } |
152 | 182 | ||
153 | void OPimNotifyManager::remindersFromString( const QString& str ) | 183 | void OPimNotifyManager::remindersFromString( const QString& str ) |
154 | { | 184 | { |
155 | 185 | ||
156 | QStringList rems = QStringList::split(";", str ); | 186 | QStringList rems = QStringList::split(";", str ); |
157 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { | 187 | for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { |
158 | OPimReminder rem( (*it).toInt() ); | 188 | OPimReminder rem( (*it).toInt() ); |
159 | add( rem ); | 189 | add( rem ); |
160 | } | 190 | } |
161 | 191 | ||
162 | } | 192 | } |
193 | } | ||
diff --git a/libopie2/opiepim/core/opimnotifymanager.h b/libopie2/opiepim/core/opimnotifymanager.h index f3c22f9..0272e5d 100644 --- a/libopie2/opiepim/core/opimnotifymanager.h +++ b/libopie2/opiepim/core/opimnotifymanager.h | |||
@@ -1,91 +1,122 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_NOTIFY_MANAGER_H | 29 | #ifndef OPIE_PIM_NOTIFY_MANAGER_H |
2 | #define OPIE_PIM_NOTIFY_MANAGER_H | 30 | #define OPIE_PIM_NOTIFY_MANAGER_H |
3 | 31 | ||
4 | #include <qvaluelist.h> | 32 | #include <qvaluelist.h> |
5 | 33 | ||
6 | #include <opie/opimnotify.h> | 34 | #include <opie2/opimnotify.h> |
7 | 35 | ||
36 | namespace Opie { | ||
8 | /** | 37 | /** |
9 | * The notify manager keeps track of the Notifiers.... | 38 | * The notify manager keeps track of the Notifiers.... |
10 | */ | 39 | */ |
11 | class OPimNotifyManager { | 40 | class OPimNotifyManager { |
12 | public: | 41 | public: |
13 | typedef QValueList<OPimReminder> Reminders; | 42 | typedef QValueList<OPimReminder> Reminders; |
14 | typedef QValueList<OPimAlarm> Alarms; | 43 | typedef QValueList<OPimAlarm> Alarms; |
15 | OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() ); | 44 | OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() ); |
16 | ~OPimNotifyManager(); | 45 | ~OPimNotifyManager(); |
17 | 46 | ||
18 | /* we will cast it for you ;) */ | 47 | /* we will cast it for you ;) */ |
19 | void add( const OPimNotify& ); | 48 | void add( const OPimNotify& ); |
20 | void remove( const OPimNotify& ); | 49 | void remove( const OPimNotify& ); |
21 | /* replaces all with this one! */ | 50 | /* replaces all with this one! */ |
22 | void replace( const OPimNotify& ); | 51 | void replace( const OPimNotify& ); |
23 | 52 | ||
24 | Reminders reminders()const; | 53 | Reminders reminders()const; |
25 | 54 | ||
26 | /** | 55 | /** |
27 | * Return | 56 | * Return |
28 | */ | 57 | */ |
29 | Alarms alarms()const; | 58 | Alarms alarms()const; |
30 | 59 | ||
31 | /** | 60 | /** |
32 | * Return alarm at DateTime "when". If more than one is registered at this | 61 | * Return alarm at DateTime "when". If more than one is registered at this |
33 | * DateTime, the first one is returned. | 62 | * DateTime, the first one is returned. |
34 | * If none was found, an empty Alarm is returned. | 63 | * If none was found, an empty Alarm is returned. |
35 | * @param when The date and time of the returned alarm | 64 | * @param when The date and time of the returned alarm |
36 | * @param found Returns true if anything was found. | 65 | * @param found Returns true if anything was found. |
37 | * @return Returns the found alarm at given DateTime. It is empty if found is false | 66 | * @return Returns the found alarm at given DateTime. It is empty if found is false |
38 | * (nothing could be found at given date and time) | 67 | * (nothing could be found at given date and time) |
39 | */ | 68 | */ |
40 | OPimAlarm alarmAtDateTime( const QDateTime& when, bool& found ) const; | 69 | OPimAlarm alarmAtDateTime( const QDateTime& when, bool& found ) const; |
41 | 70 | ||
42 | void setAlarms( const Alarms& ); | 71 | void setAlarms( const Alarms& ); |
43 | void setReminders( const Reminders& ); | 72 | void setReminders( const Reminders& ); |
44 | 73 | ||
45 | /* register is a Ansi C keyword... */ | 74 | /* register is a Ansi C keyword... */ |
46 | /** | 75 | /** |
47 | * This function will register the Notify to the Alarm Server | 76 | * This function will register the Notify to the Alarm Server |
48 | * or datebook depending on the type of the notify | 77 | * or datebook depending on the type of the notify |
49 | */ | 78 | */ |
50 | void registerNotify( const OPimNotify& ); | 79 | void registerNotify( const OPimNotify& ); |
51 | 80 | ||
52 | /** | 81 | /** |
53 | * this will do the opposite.. | 82 | * this will do the opposite.. |
54 | */ | 83 | */ |
55 | void deregister( const OPimNotify& ); | 84 | void deregister( const OPimNotify& ); |
56 | 85 | ||
57 | bool isEmpty()const; | 86 | bool isEmpty()const; |
58 | 87 | ||
59 | /** | 88 | /** |
60 | * Return all alarms as string | 89 | * Return all alarms as string |
61 | */ | 90 | */ |
62 | QString alarmsToString() const; | 91 | QString alarmsToString() const; |
63 | /** | 92 | /** |
64 | * Return all notifiers as string | 93 | * Return all notifiers as string |
65 | */ | 94 | */ |
66 | QString remindersToString() const; | 95 | QString remindersToString() const; |
67 | 96 | ||
68 | /** | 97 | /** |
69 | * Convert string to alarms | 98 | * Convert string to alarms |
70 | * @param str String created by alarmsToString() | 99 | * @param str String created by alarmsToString() |
71 | */ | 100 | */ |
72 | void alarmsFromString( const QString& str ); | 101 | void alarmsFromString( const QString& str ); |
73 | 102 | ||
74 | /** | 103 | /** |
75 | * Convert string to reminders | 104 | * Convert string to reminders |
76 | * @param str String created by remindersToString() | 105 | * @param str String created by remindersToString() |
77 | */ | 106 | */ |
78 | void remindersFromString( const QString& str ); | 107 | void remindersFromString( const QString& str ); |
79 | 108 | ||
80 | 109 | ||
81 | 110 | ||
82 | private: | 111 | private: |
83 | Reminders m_rem; | 112 | Reminders m_rem; |
84 | Alarms m_al; | 113 | Alarms m_al; |
85 | 114 | ||
86 | class Private; | 115 | class Private; |
87 | Private *d; | 116 | Private *d; |
88 | 117 | ||
89 | }; | 118 | }; |
90 | 119 | ||
120 | } | ||
121 | |||
91 | #endif | 122 | #endif |
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp index 2365748..72bb372 100644 --- a/libopie2/opiepim/core/opimrecord.cpp +++ b/libopie2/opiepim/core/opimrecord.cpp | |||
@@ -1,182 +1,213 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qarray.h> | 29 | #include <qarray.h> |
2 | 30 | ||
3 | #include <qpe/categories.h> | 31 | #include <qpe/categories.h> |
4 | #include <qpe/categoryselect.h> | 32 | #include <qpe/categoryselect.h> |
5 | 33 | ||
6 | #include "opimrecord.h" | 34 | #include <opie2/opimrecord.h> |
7 | 35 | ||
36 | namespace Opie { | ||
8 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | 37 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); |
9 | 38 | ||
10 | 39 | ||
11 | OPimRecord::OPimRecord( int uid ) | 40 | OPimRecord::OPimRecord( int uid ) |
12 | : Qtopia::Record() { | 41 | : Qtopia::Record() { |
13 | 42 | ||
14 | m_lastHit = -1; | 43 | m_lastHit = -1; |
15 | setUid( uid ); | 44 | setUid( uid ); |
16 | } | 45 | } |
17 | OPimRecord::~OPimRecord() { | 46 | OPimRecord::~OPimRecord() { |
18 | } | 47 | } |
19 | OPimRecord::OPimRecord( const OPimRecord& rec ) | 48 | OPimRecord::OPimRecord( const OPimRecord& rec ) |
20 | : Qtopia::Record( rec ) | 49 | : Qtopia::Record( rec ) |
21 | { | 50 | { |
22 | (*this) = rec; | 51 | (*this) = rec; |
23 | } | 52 | } |
24 | 53 | ||
25 | OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { | 54 | OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { |
26 | if ( this == &rec ) return *this; | 55 | if ( this == &rec ) return *this; |
27 | 56 | ||
28 | Qtopia::Record::operator=( rec ); | 57 | Qtopia::Record::operator=( rec ); |
29 | m_xrefman = rec.m_xrefman; | 58 | m_xrefman = rec.m_xrefman; |
30 | m_lastHit = rec.m_lastHit; | 59 | m_lastHit = rec.m_lastHit; |
31 | 60 | ||
32 | return *this; | 61 | return *this; |
33 | } | 62 | } |
34 | /* | 63 | /* |
35 | * category names | 64 | * category names |
36 | */ | 65 | */ |
37 | QStringList OPimRecord::categoryNames( const QString& appname ) const { | 66 | QStringList OPimRecord::categoryNames( const QString& appname ) const { |
38 | QStringList list; | 67 | QStringList list; |
39 | QArray<int> cats = categories(); | 68 | QArray<int> cats = categories(); |
40 | Categories catDB; | 69 | Categories catDB; |
41 | catDB.load( categoryFileName() ); | 70 | catDB.load( categoryFileName() ); |
42 | 71 | ||
43 | for (uint i = 0; i < cats.count(); i++ ) { | 72 | for (uint i = 0; i < cats.count(); i++ ) { |
44 | list << catDB.label( appname, cats[i] ); | 73 | list << catDB.label( appname, cats[i] ); |
45 | } | 74 | } |
46 | 75 | ||
47 | return list; | 76 | return list; |
48 | } | 77 | } |
49 | void OPimRecord::setCategoryNames( const QStringList& ) { | 78 | void OPimRecord::setCategoryNames( const QStringList& ) { |
50 | 79 | ||
51 | } | 80 | } |
52 | void OPimRecord::addCategoryName( const QString& ) { | 81 | void OPimRecord::addCategoryName( const QString& ) { |
53 | Categories catDB; | 82 | Categories catDB; |
54 | catDB.load( categoryFileName() ); | 83 | catDB.load( categoryFileName() ); |
55 | 84 | ||
56 | 85 | ||
57 | } | 86 | } |
58 | bool OPimRecord::isEmpty()const { | 87 | bool OPimRecord::isEmpty()const { |
59 | return ( uid() == 0 ); | 88 | return ( uid() == 0 ); |
60 | } | 89 | } |
61 | /*QString OPimRecord::crossToString()const { | 90 | /*QString OPimRecord::crossToString()const { |
62 | QString str; | 91 | QString str; |
63 | QMap<QString, QArray<int> >::ConstIterator it; | 92 | QMap<QString, QArray<int> >::ConstIterator it; |
64 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { | 93 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { |
65 | QArray<int> id = it.data(); | 94 | QArray<int> id = it.data(); |
66 | for ( uint i = 0; i < id.size(); ++i ) { | 95 | for ( uint i = 0; i < id.size(); ++i ) { |
67 | str += it.key() + "," + QString::number( i ) + ";"; | 96 | str += it.key() + "," + QString::number( i ) + ";"; |
68 | } | 97 | } |
69 | } | 98 | } |
70 | str = str.remove( str.length()-1, 1); // strip the ; | 99 | str = str.remove( str.length()-1, 1); // strip the ; |
71 | //qWarning("IDS " + str ); | 100 | //qWarning("IDS " + str ); |
72 | 101 | ||
73 | return str; | 102 | return str; |
74 | }*/ | 103 | }*/ |
75 | /* if uid = 1 assign a new one */ | 104 | /* if uid = 1 assign a new one */ |
76 | void OPimRecord::setUid( int uid ) { | 105 | void OPimRecord::setUid( int uid ) { |
77 | if ( uid == 1) | 106 | if ( uid == 1) |
78 | uid = uidGen().generate(); | 107 | uid = uidGen().generate(); |
79 | 108 | ||
80 | Qtopia::Record::setUid( uid ); | 109 | Qtopia::Record::setUid( uid ); |
81 | }; | 110 | }; |
82 | Qtopia::UidGen &OPimRecord::uidGen() { | 111 | Qtopia::UidGen &OPimRecord::uidGen() { |
83 | return m_uidGen; | 112 | return m_uidGen; |
84 | } | 113 | } |
85 | OPimXRefManager &OPimRecord::xrefmanager() { | 114 | OPimXRefManager &OPimRecord::xrefmanager() { |
86 | return m_xrefman; | 115 | return m_xrefman; |
87 | } | 116 | } |
88 | int OPimRecord::rtti(){ | 117 | int OPimRecord::rtti(){ |
89 | return 0; | 118 | return 0; |
90 | } | 119 | } |
91 | 120 | ||
92 | /** | 121 | /** |
93 | * now let's put our data into the stream | 122 | * now let's put our data into the stream |
94 | */ | 123 | */ |
95 | /* | 124 | /* |
96 | * First read UID | 125 | * First read UID |
97 | * Categories | 126 | * Categories |
98 | * XRef | 127 | * XRef |
99 | */ | 128 | */ |
100 | bool OPimRecord::loadFromStream( QDataStream& stream ) { | 129 | bool OPimRecord::loadFromStream( QDataStream& stream ) { |
101 | int Int; | 130 | int Int; |
102 | uint UInt; | 131 | uint UInt; |
103 | stream >> Int; | 132 | stream >> Int; |
104 | setUid(Int); | 133 | setUid(Int); |
105 | 134 | ||
106 | /** Categories */ | 135 | /** Categories */ |
107 | stream >> UInt; | 136 | stream >> UInt; |
108 | QArray<int> array(UInt); | 137 | QArray<int> array(UInt); |
109 | for (uint i = 0; i < UInt; i++ ) { | 138 | for (uint i = 0; i < UInt; i++ ) { |
110 | stream >> array[i]; | 139 | stream >> array[i]; |
111 | } | 140 | } |
112 | setCategories( array ); | 141 | setCategories( array ); |
113 | 142 | ||
114 | /* | 143 | /* |
115 | * now we do the X-Ref stuff | 144 | * now we do the X-Ref stuff |
116 | */ | 145 | */ |
117 | OPimXRef xref; | 146 | OPimXRef xref; |
118 | stream >> UInt; | 147 | stream >> UInt; |
119 | for ( uint i = 0; i < UInt; i++ ) { | 148 | for ( uint i = 0; i < UInt; i++ ) { |
120 | xref.setPartner( OPimXRef::One, partner( stream ) ); | 149 | xref.setPartner( OPimXRef::One, partner( stream ) ); |
121 | xref.setPartner( OPimXRef::Two, partner( stream ) ); | 150 | xref.setPartner( OPimXRef::Two, partner( stream ) ); |
122 | m_xrefman.add( xref ); | 151 | m_xrefman.add( xref ); |
123 | } | 152 | } |
124 | 153 | ||
125 | return true; | 154 | return true; |
126 | } | 155 | } |
127 | bool OPimRecord::saveToStream( QDataStream& stream )const { | 156 | bool OPimRecord::saveToStream( QDataStream& stream )const { |
128 | /** UIDs */ | 157 | /** UIDs */ |
129 | 158 | ||
130 | stream << uid(); | 159 | stream << uid(); |
131 | 160 | ||
132 | /** Categories */ | 161 | /** Categories */ |
133 | stream << categories().count(); | 162 | stream << categories().count(); |
134 | for ( uint i = 0; i < categories().count(); i++ ) { | 163 | for ( uint i = 0; i < categories().count(); i++ ) { |
135 | stream << categories()[i]; | 164 | stream << categories()[i]; |
136 | } | 165 | } |
137 | 166 | ||
138 | /* | 167 | /* |
139 | * first the XRef count | 168 | * first the XRef count |
140 | * then the xrefs | 169 | * then the xrefs |
141 | */ | 170 | */ |
142 | stream << m_xrefman.list().count(); | 171 | stream << m_xrefman.list().count(); |
143 | for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); | 172 | for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); |
144 | it != m_xrefman.list().end(); ++it ) { | 173 | it != m_xrefman.list().end(); ++it ) { |
145 | flush( (*it).partner( OPimXRef::One), stream ); | 174 | flush( (*it).partner( OPimXRef::One), stream ); |
146 | flush( (*it).partner( OPimXRef::Two), stream ); | 175 | flush( (*it).partner( OPimXRef::Two), stream ); |
147 | } | 176 | } |
148 | return true; | 177 | return true; |
149 | } | 178 | } |
150 | void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ | 179 | void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ |
151 | str << par.service(); | 180 | str << par.service(); |
152 | str << par.uid(); | 181 | str << par.uid(); |
153 | str << par.field(); | 182 | str << par.field(); |
154 | } | 183 | } |
155 | OPimXRefPartner OPimRecord::partner( QDataStream& stream ) { | 184 | OPimXRefPartner OPimRecord::partner( QDataStream& stream ) { |
156 | OPimXRefPartner par; | 185 | OPimXRefPartner par; |
157 | QString str; | 186 | QString str; |
158 | int i; | 187 | int i; |
159 | 188 | ||
160 | stream >> str; | 189 | stream >> str; |
161 | par.setService( str ); | 190 | par.setService( str ); |
162 | 191 | ||
163 | stream >> i; | 192 | stream >> i; |
164 | par.setUid( i ); | 193 | par.setUid( i ); |
165 | 194 | ||
166 | stream >> i ; | 195 | stream >> i ; |
167 | par.setField( i ); | 196 | par.setField( i ); |
168 | 197 | ||
169 | return par; | 198 | return par; |
170 | } | 199 | } |
171 | void OPimRecord::setLastHitField( int lastHit )const { | 200 | void OPimRecord::setLastHitField( int lastHit )const { |
172 | m_lastHit = lastHit; | 201 | m_lastHit = lastHit; |
173 | } | 202 | } |
174 | int OPimRecord::lastHitField()const{ | 203 | int OPimRecord::lastHitField()const{ |
175 | return m_lastHit; | 204 | return m_lastHit; |
176 | } | 205 | } |
177 | QMap<QString, QString> OPimRecord::toExtraMap()const { | 206 | QMap<QString, QString> OPimRecord::toExtraMap()const { |
178 | return customMap; | 207 | return customMap; |
179 | } | 208 | } |
180 | void OPimRecord::setExtraMap( const QMap<QString, QString>& map) { | 209 | void OPimRecord::setExtraMap( const QMap<QString, QString>& map) { |
181 | customMap = map; | 210 | customMap = map; |
182 | } | 211 | } |
212 | |||
213 | } | ||
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h index 3d774e2..63a3a98 100644 --- a/libopie2/opiepim/core/opimrecord.h +++ b/libopie2/opiepim/core/opimrecord.h | |||
@@ -1,158 +1,187 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_RECORD_H | 29 | #ifndef OPIE_PIM_RECORD_H |
2 | #define OPIE_PIM_RECORD_H | 30 | #define OPIE_PIM_RECORD_H |
3 | 31 | ||
4 | #include <qdatastream.h> | 32 | #include <qdatastream.h> |
5 | #include <qmap.h> | 33 | #include <qmap.h> |
6 | #include <qstring.h> | 34 | #include <qstring.h> |
7 | #include <qstringlist.h> | 35 | #include <qstringlist.h> |
8 | 36 | ||
9 | /* | 37 | /* |
10 | * we need to get customMap which is private... | 38 | * we need to get customMap which is private... |
11 | */ | 39 | */ |
12 | #define private protected | 40 | #define private protected |
13 | #include <qpe/palmtoprecord.h> | 41 | #include <qpe/palmtoprecord.h> |
14 | #undef private | 42 | #undef private |
15 | 43 | ||
16 | #include <opie/opimxrefmanager.h> | 44 | #include <opie2/opimxrefmanager.h> |
17 | 45 | ||
46 | namespace Opie { | ||
18 | /** | 47 | /** |
19 | * This is the base class for | 48 | * This is the base class for |
20 | * all PIM Records | 49 | * all PIM Records |
21 | * | 50 | * |
22 | */ | 51 | */ |
23 | class OPimRecord : public Qtopia::Record { | 52 | class OPimRecord : public Qtopia::Record { |
24 | public: | 53 | public: |
25 | /** | 54 | /** |
26 | * c'tor | 55 | * c'tor |
27 | * uid of 0 isEmpty | 56 | * uid of 0 isEmpty |
28 | * uid of 1 will be assigned a new one | 57 | * uid of 1 will be assigned a new one |
29 | */ | 58 | */ |
30 | OPimRecord(int uid = 0); | 59 | OPimRecord(int uid = 0); |
31 | ~OPimRecord(); | 60 | ~OPimRecord(); |
32 | 61 | ||
33 | /** | 62 | /** |
34 | * copy c'tor | 63 | * copy c'tor |
35 | */ | 64 | */ |
36 | OPimRecord( const OPimRecord& rec ); | 65 | OPimRecord( const OPimRecord& rec ); |
37 | 66 | ||
38 | /** | 67 | /** |
39 | * copy operator | 68 | * copy operator |
40 | */ | 69 | */ |
41 | OPimRecord &operator=( const OPimRecord& ); | 70 | OPimRecord &operator=( const OPimRecord& ); |
42 | 71 | ||
43 | /** | 72 | /** |
44 | * category names resolved | 73 | * category names resolved |
45 | */ | 74 | */ |
46 | QStringList categoryNames( const QString& appname )const; | 75 | QStringList categoryNames( const QString& appname )const; |
47 | 76 | ||
48 | /** | 77 | /** |
49 | * set category names they will be resolved | 78 | * set category names they will be resolved |
50 | */ | 79 | */ |
51 | void setCategoryNames( const QStringList& ); | 80 | void setCategoryNames( const QStringList& ); |
52 | 81 | ||
53 | /** | 82 | /** |
54 | * addCategoryName adds a name | 83 | * addCategoryName adds a name |
55 | * to the internal category list | 84 | * to the internal category list |
56 | */ | 85 | */ |
57 | void addCategoryName( const QString& ); | 86 | void addCategoryName( const QString& ); |
58 | 87 | ||
59 | /** | 88 | /** |
60 | * if a Record isEmpty | 89 | * if a Record isEmpty |
61 | * it's empty if it's 0 | 90 | * it's empty if it's 0 |
62 | */ | 91 | */ |
63 | virtual bool isEmpty()const; | 92 | virtual bool isEmpty()const; |
64 | 93 | ||
65 | /** | 94 | /** |
66 | * toRichText summary | 95 | * toRichText summary |
67 | */ | 96 | */ |
68 | virtual QString toRichText()const = 0; | 97 | virtual QString toRichText()const = 0; |
69 | 98 | ||
70 | /** | 99 | /** |
71 | * a small one line summary | 100 | * a small one line summary |
72 | */ | 101 | */ |
73 | virtual QString toShortText()const = 0; | 102 | virtual QString toShortText()const = 0; |
74 | 103 | ||
75 | /** | 104 | /** |
76 | * the name of the Record | 105 | * the name of the Record |
77 | */ | 106 | */ |
78 | virtual QString type()const = 0; | 107 | virtual QString type()const = 0; |
79 | 108 | ||
80 | /** | 109 | /** |
81 | * matches the Records the regular expression? | 110 | * matches the Records the regular expression? |
82 | */ | 111 | */ |
83 | virtual bool match( const QString ®exp ) const | 112 | virtual bool match( const QString ®exp ) const |
84 | {setLastHitField( -1 ); | 113 | {setLastHitField( -1 ); |
85 | return Qtopia::Record::match(QRegExp(regexp));}; | 114 | return Qtopia::Record::match(QRegExp(regexp));}; |
86 | 115 | ||
87 | /** | 116 | /** |
88 | * if implemented this function returns which item has been | 117 | * if implemented this function returns which item has been |
89 | * last hit by the match() function. | 118 | * last hit by the match() function. |
90 | * or -1 if not implemented or no hit has occured | 119 | * or -1 if not implemented or no hit has occured |
91 | */ | 120 | */ |
92 | int lastHitField()const; | 121 | int lastHitField()const; |
93 | 122 | ||
94 | /** | 123 | /** |
95 | * converts the internal structure to a map | 124 | * converts the internal structure to a map |
96 | */ | 125 | */ |
97 | virtual QMap<int, QString> toMap()const = 0; | 126 | virtual QMap<int, QString> toMap()const = 0; |
98 | // virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers) | 127 | // virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers) |
99 | 128 | ||
100 | /** | 129 | /** |
101 | * key value representation of extra items | 130 | * key value representation of extra items |
102 | */ | 131 | */ |
103 | QMap<QString, QString> toExtraMap()const; | 132 | QMap<QString, QString> toExtraMap()const; |
104 | void setExtraMap( const QMap<QString, QString>& ); | 133 | void setExtraMap( const QMap<QString, QString>& ); |
105 | 134 | ||
106 | /** | 135 | /** |
107 | * the name for a recordField | 136 | * the name for a recordField |
108 | */ | 137 | */ |
109 | virtual QString recordField(int)const = 0; | 138 | virtual QString recordField(int)const = 0; |
110 | 139 | ||
111 | /** | 140 | /** |
112 | * returns a reference of the | 141 | * returns a reference of the |
113 | * Cross Reference Manager | 142 | * Cross Reference Manager |
114 | * Partner 'One' is THIS PIM RECORD! | 143 | * Partner 'One' is THIS PIM RECORD! |
115 | * 'Two' is the Partner where we link to | 144 | * 'Two' is the Partner where we link to |
116 | */ | 145 | */ |
117 | OPimXRefManager& xrefmanager(); | 146 | OPimXRefManager& xrefmanager(); |
118 | 147 | ||
119 | /** | 148 | /** |
120 | * set the uid | 149 | * set the uid |
121 | */ | 150 | */ |
122 | virtual void setUid( int uid ); | 151 | virtual void setUid( int uid ); |
123 | 152 | ||
124 | /* | 153 | /* |
125 | * used inside the Templates for casting | 154 | * used inside the Templates for casting |
126 | * REIMPLEMENT in your .... | 155 | * REIMPLEMENT in your .... |
127 | */ | 156 | */ |
128 | static int rtti(); | 157 | static int rtti(); |
129 | 158 | ||
130 | /** | 159 | /** |
131 | * some marshalling and de marshalling code | 160 | * some marshalling and de marshalling code |
132 | * saves the OPimRecord | 161 | * saves the OPimRecord |
133 | * to and from a DataStream | 162 | * to and from a DataStream |
134 | */ | 163 | */ |
135 | virtual bool loadFromStream(QDataStream& ); | 164 | virtual bool loadFromStream(QDataStream& ); |
136 | virtual bool saveToStream( QDataStream& stream )const; | 165 | virtual bool saveToStream( QDataStream& stream )const; |
137 | 166 | ||
138 | protected: | 167 | protected: |
139 | // need to be const cause it is called from const methods | 168 | // need to be const cause it is called from const methods |
140 | mutable int m_lastHit; | 169 | mutable int m_lastHit; |
141 | void setLastHitField( int lastHit )const; | 170 | void setLastHitField( int lastHit )const; |
142 | Qtopia::UidGen &uidGen(); | 171 | Qtopia::UidGen &uidGen(); |
143 | // QString crossToString()const; | 172 | // QString crossToString()const; |
144 | 173 | ||
145 | private: | 174 | private: |
146 | class OPimRecordPrivate; | 175 | class OPimRecordPrivate; |
147 | OPimRecordPrivate *d; | 176 | OPimRecordPrivate *d; |
148 | OPimXRefManager m_xrefman; | 177 | OPimXRefManager m_xrefman; |
149 | static Qtopia::UidGen m_uidGen; | 178 | static Qtopia::UidGen m_uidGen; |
150 | 179 | ||
151 | private: | 180 | private: |
152 | void flush( const OPimXRefPartner&, QDataStream& stream )const; | 181 | void flush( const OPimXRefPartner&, QDataStream& stream )const; |
153 | OPimXRefPartner partner( QDataStream& ); | 182 | OPimXRefPartner partner( QDataStream& ); |
154 | }; | 183 | }; |
155 | 184 | ||
156 | 185 | } | |
157 | 186 | ||
158 | #endif | 187 | #endif |
diff --git a/libopie2/opiepim/core/opimresolver.cpp b/libopie2/opiepim/core/opimresolver.cpp index 4ebbd6e..eceabcb 100644 --- a/libopie2/opiepim/core/opimresolver.cpp +++ b/libopie2/opiepim/core/opimresolver.cpp | |||
@@ -1,198 +1,230 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qcopchannel_qws.h> | 29 | #include <qcopchannel_qws.h> |
2 | 30 | ||
3 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
4 | 32 | ||
5 | #include "otodoaccess.h" | 33 | #include <opie2/otodoaccess.h> |
6 | #include "ocontactaccess.h" | 34 | #include <opie2/ocontactaccess.h> |
7 | 35 | ||
8 | //#include "opimfactory.h" | 36 | //#include "opimfactory.h" |
9 | #include "opimresolver.h" | 37 | #include <opie2/opimresolver.h> |
38 | |||
39 | namespace Opie { | ||
10 | 40 | ||
11 | OPimResolver* OPimResolver::m_self = 0l; | 41 | OPimResolver* OPimResolver::m_self = 0l; |
12 | 42 | ||
13 | OPimResolver::OPimResolver() { | 43 | OPimResolver::OPimResolver() { |
14 | /* the built in channels */ | 44 | /* the built in channels */ |
15 | m_builtIns << "Todolist" << "Addressbook" << "Datebook"; | 45 | m_builtIns << "Todolist" << "Addressbook" << "Datebook"; |
16 | } | 46 | } |
17 | OPimResolver* OPimResolver::self() { | 47 | OPimResolver* OPimResolver::self() { |
18 | if (!m_self) | 48 | if (!m_self) |
19 | m_self = new OPimResolver(); | 49 | m_self = new OPimResolver(); |
20 | 50 | ||
21 | return m_self; | 51 | return m_self; |
22 | } | 52 | } |
23 | 53 | ||
24 | /* | 54 | /* |
25 | * FIXME use a cache here too | 55 | * FIXME use a cache here too |
26 | */ | 56 | */ |
27 | OPimRecord* OPimResolver::record( const QString& service, int uid ) { | 57 | OPimRecord* OPimResolver::record( const QString& service, int uid ) { |
28 | OPimRecord* rec = 0l; | 58 | OPimRecord* rec = 0l; |
29 | OPimBase* base = backend( service ); | 59 | OPimBase* base = backend( service ); |
30 | 60 | ||
31 | if ( base ) | 61 | if ( base ) |
32 | rec = base->record( uid ); | 62 | rec = base->record( uid ); |
33 | delete base; | 63 | delete base; |
34 | 64 | ||
35 | return rec; | 65 | return rec; |
36 | } | 66 | } |
37 | OPimRecord* OPimResolver::record( const QString& service ) { | 67 | OPimRecord* OPimResolver::record( const QString& service ) { |
38 | return record( serviceId( service ) ); | 68 | return record( serviceId( service ) ); |
39 | } | 69 | } |
40 | OPimRecord* OPimResolver::record( int rtti ) { | 70 | OPimRecord* OPimResolver::record( int rtti ) { |
41 | OPimRecord* rec = 0l; | 71 | OPimRecord* rec = 0l; |
42 | switch( rtti ) { | 72 | switch( rtti ) { |
43 | case 1: /* todolist */ | 73 | case 1: /* todolist */ |
44 | rec = new OTodo(); | 74 | rec = new OTodo(); |
45 | case 2: /* contact */ | 75 | case 2: /* contact */ |
46 | rec = new OContact(); | 76 | rec = new OContact(); |
47 | default: | 77 | default: |
48 | break; | 78 | break; |
49 | } | 79 | } |
50 | /* | 80 | /* |
51 | * FIXME resolve externally | 81 | * FIXME resolve externally |
52 | */ | 82 | */ |
53 | if (!rec ) { | 83 | if (!rec ) { |
54 | ; | 84 | ; |
55 | } | 85 | } |
56 | return 0l; | 86 | return 0l; |
57 | } | 87 | } |
58 | bool OPimResolver::isBuiltIn( const QString& str) const{ | 88 | bool OPimResolver::isBuiltIn( const QString& str) const{ |
59 | return m_builtIns.contains( str ); | 89 | return m_builtIns.contains( str ); |
60 | } | 90 | } |
61 | QCString OPimResolver::qcopChannel( enum BuiltIn& built)const { | 91 | QCString OPimResolver::qcopChannel( enum BuiltIn& built)const { |
62 | QCString str("QPE/"); | 92 | QCString str("QPE/"); |
63 | switch( built ) { | 93 | switch( built ) { |
64 | case TodoList: | 94 | case TodoList: |
65 | str += "Todolist"; | 95 | str += "Todolist"; |
66 | break; | 96 | break; |
67 | case DateBook: | 97 | case DateBook: |
68 | str += "Datebook"; | 98 | str += "Datebook"; |
69 | break; | 99 | break; |
70 | case AddressBook: | 100 | case AddressBook: |
71 | str += "Addressbook"; | 101 | str += "Addressbook"; |
72 | break; | 102 | break; |
73 | default: | 103 | default: |
74 | break; | 104 | break; |
75 | } | 105 | } |
76 | 106 | ||
77 | return str; | 107 | return str; |
78 | } | 108 | } |
79 | QCString OPimResolver::qcopChannel( const QString& service )const { | 109 | QCString OPimResolver::qcopChannel( const QString& service )const { |
80 | QCString str("QPE/"); | 110 | QCString str("QPE/"); |
81 | str += service.latin1(); | 111 | str += service.latin1(); |
82 | return str; | 112 | return str; |
83 | } | 113 | } |
84 | /* | 114 | /* |
85 | * Implement services!! | 115 | * Implement services!! |
86 | * FIXME | 116 | * FIXME |
87 | */ | 117 | */ |
88 | QCString OPimResolver::applicationChannel( enum BuiltIn& built)const { | 118 | QCString OPimResolver::applicationChannel( enum BuiltIn& built)const { |
89 | QCString str("QPE/Application/"); | 119 | QCString str("QPE/Application/"); |
90 | switch( built ) { | 120 | switch( built ) { |
91 | case TodoList: | 121 | case TodoList: |
92 | str += "todolist"; | 122 | str += "todolist"; |
93 | break; | 123 | break; |
94 | case DateBook: | 124 | case DateBook: |
95 | str += "datebook"; | 125 | str += "datebook"; |
96 | break; | 126 | break; |
97 | case AddressBook: | 127 | case AddressBook: |
98 | str += "addressbook"; | 128 | str += "addressbook"; |
99 | break; | 129 | break; |
100 | } | 130 | } |
101 | 131 | ||
102 | return str; | 132 | return str; |
103 | } | 133 | } |
104 | QCString OPimResolver::applicationChannel( const QString& service )const { | 134 | QCString OPimResolver::applicationChannel( const QString& service )const { |
105 | QCString str("QPE/Application/"); | 135 | QCString str("QPE/Application/"); |
106 | 136 | ||
107 | if ( isBuiltIn( service ) ) { | 137 | if ( isBuiltIn( service ) ) { |
108 | if ( service == "Todolist" ) | 138 | if ( service == "Todolist" ) |
109 | str += "todolist"; | 139 | str += "todolist"; |
110 | else if ( service == "Datebook" ) | 140 | else if ( service == "Datebook" ) |
111 | str += "datebook"; | 141 | str += "datebook"; |
112 | else if ( service == "Addressbook" ) | 142 | else if ( service == "Addressbook" ) |
113 | str += "addressbook"; | 143 | str += "addressbook"; |
114 | }else | 144 | }else |
115 | ; // FIXME for additional stuff | 145 | ; // FIXME for additional stuff |
116 | 146 | ||
117 | return str; | 147 | return str; |
118 | } | 148 | } |
119 | QStringList OPimResolver::services()const { | 149 | QStringList OPimResolver::services()const { |
120 | return m_builtIns; | 150 | return m_builtIns; |
121 | } | 151 | } |
122 | QString OPimResolver::serviceName( int rtti ) const{ | 152 | QString OPimResolver::serviceName( int rtti ) const{ |
123 | QString str; | 153 | QString str; |
124 | switch ( rtti ) { | 154 | switch ( rtti ) { |
125 | case TodoList: | 155 | case TodoList: |
126 | str = "Todolist"; | 156 | str = "Todolist"; |
127 | break; | 157 | break; |
128 | case DateBook: | 158 | case DateBook: |
129 | str = "Datebook"; | 159 | str = "Datebook"; |
130 | break; | 160 | break; |
131 | case AddressBook: | 161 | case AddressBook: |
132 | str = "Addressbook"; | 162 | str = "Addressbook"; |
133 | break; | 163 | break; |
134 | default: | 164 | default: |
135 | break; | 165 | break; |
136 | } | 166 | } |
137 | return str; | 167 | return str; |
138 | // FIXME me for 3rd party | 168 | // FIXME me for 3rd party |
139 | } | 169 | } |
140 | int OPimResolver::serviceId( const QString& service ) { | 170 | int OPimResolver::serviceId( const QString& service ) { |
141 | int rtti = 0; | 171 | int rtti = 0; |
142 | if ( service == "Todolist" ) | 172 | if ( service == "Todolist" ) |
143 | rtti = TodoList; | 173 | rtti = TodoList; |
144 | else if ( service == "Datebook" ) | 174 | else if ( service == "Datebook" ) |
145 | rtti = DateBook; | 175 | rtti = DateBook; |
146 | else if ( service == "Addressbook" ) | 176 | else if ( service == "Addressbook" ) |
147 | rtti = AddressBook; | 177 | rtti = AddressBook; |
148 | 178 | ||
149 | return rtti; | 179 | return rtti; |
150 | } | 180 | } |
151 | /** | 181 | /** |
152 | * check if the 'service' is registered and if so we'll | 182 | * check if the 'service' is registered and if so we'll |
153 | */ | 183 | */ |
154 | bool OPimResolver::add( const QString& service, const OPimRecord& rec) { | 184 | bool OPimResolver::add( const QString& service, const OPimRecord& rec) { |
155 | if ( QCopChannel::isRegistered( applicationChannel( service ) ) ) { | 185 | if ( QCopChannel::isRegistered( applicationChannel( service ) ) ) { |
156 | QByteArray data; | 186 | QByteArray data; |
157 | QDataStream arg(data, IO_WriteOnly ); | 187 | QDataStream arg(data, IO_WriteOnly ); |
158 | if ( rec.saveToStream( arg ) ) { | 188 | if ( rec.saveToStream( arg ) ) { |
159 | QCopEnvelope env( applicationChannel( service ), "add(int,QByteArray)" ); | 189 | QCopEnvelope env( applicationChannel( service ), "add(int,QByteArray)" ); |
160 | env << rec.rtti(); | 190 | env << rec.rtti(); |
161 | env << data; | 191 | env << data; |
162 | }else | 192 | }else |
163 | return false; | 193 | return false; |
164 | }else{ | 194 | }else{ |
165 | OPimBase* base = backend( service ); | 195 | OPimBase* base = backend( service ); |
166 | if (!base ) return false; | 196 | if (!base ) return false; |
167 | 197 | ||
168 | base->load(); | 198 | base->load(); |
169 | base->add( rec ); | 199 | base->add( rec ); |
170 | base->save(); | 200 | base->save(); |
171 | delete base; | 201 | delete base; |
172 | } | 202 | } |
173 | 203 | ||
174 | return true; | 204 | return true; |
175 | } | 205 | } |
176 | OPimBase* OPimResolver::backend( const QString& service ) { | 206 | OPimBase* OPimResolver::backend( const QString& service ) { |
177 | return backend( serviceId( service ) ); | 207 | return backend( serviceId( service ) ); |
178 | } | 208 | } |
179 | OPimBase* OPimResolver::backend( int rtti ) { | 209 | OPimBase* OPimResolver::backend( int rtti ) { |
180 | OPimBase* base = 0l; | 210 | OPimBase* base = 0l; |
181 | switch( rtti ) { | 211 | switch( rtti ) { |
182 | case TodoList: | 212 | case TodoList: |
183 | base = new OTodoAccess(); | 213 | base = new OTodoAccess(); |
184 | break; | 214 | break; |
185 | case DateBook: | 215 | case DateBook: |
186 | break; | 216 | break; |
187 | case AddressBook: | 217 | case AddressBook: |
188 | base = new OContactAccess("Resolver"); | 218 | base = new OContactAccess("Resolver"); |
189 | break; | 219 | break; |
190 | default: | 220 | default: |
191 | break; | 221 | break; |
192 | } | 222 | } |
193 | // FIXME for 3rd party | 223 | // FIXME for 3rd party |
194 | if (!base ) | 224 | if (!base ) |
195 | ; | 225 | ; |
196 | 226 | ||
197 | return base; | 227 | return base; |
198 | } | 228 | } |
229 | |||
230 | } | ||
diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h index 1ce1619..adc7c16 100644 --- a/libopie2/opiepim/core/opimresolver.h +++ b/libopie2/opiepim/core/opimresolver.h | |||
@@ -1,90 +1,121 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_RESOLVER | 29 | #ifndef OPIE_PIM_RESOLVER |
2 | #define OPIE_PIM_RESOLVER | 30 | #define OPIE_PIM_RESOLVER |
3 | 31 | ||
4 | #include <qstring.h> | 32 | #include <qstring.h> |
5 | #include <qvaluelist.h> | 33 | #include <qvaluelist.h> |
6 | 34 | ||
7 | #include <opie/otemplatebase.h> | 35 | #include <opie2/otemplatebase.h> |
8 | 36 | ||
37 | namespace Opie { | ||
9 | /** | 38 | /** |
10 | * OPimResolver is a MetaClass to access | 39 | * OPimResolver is a MetaClass to access |
11 | * available backends read only. | 40 | * available backends read only. |
12 | * It will be used to resolve uids + app names | 41 | * It will be used to resolve uids + app names |
13 | * to full informations | 42 | * to full informations |
14 | * to traverse through a list of alarms, reminders | 43 | * to traverse through a list of alarms, reminders |
15 | * to get access to built in PIM functionality | 44 | * to get access to built in PIM functionality |
16 | * and to more stuff | 45 | * and to more stuff |
17 | * THE PERFORMANCE will depend on THE BACKEND | 46 | * THE PERFORMANCE will depend on THE BACKEND |
18 | * USING XML is a waste of memory!!!!! | 47 | * USING XML is a waste of memory!!!!! |
19 | */ | 48 | */ |
20 | class OPimResolver { | 49 | class OPimResolver { |
21 | public: | 50 | public: |
22 | enum BuiltIn { TodoList = 0, | 51 | enum BuiltIn { TodoList = 0, |
23 | DateBook, | 52 | DateBook, |
24 | AddressBook | 53 | AddressBook |
25 | }; | 54 | }; |
26 | static OPimResolver* self(); | 55 | static OPimResolver* self(); |
27 | 56 | ||
28 | 57 | ||
29 | /** | 58 | /** |
30 | * return a record for a uid | 59 | * return a record for a uid |
31 | * and an service | 60 | * and an service |
32 | * You've THE OWNERSHIP NOW! | 61 | * You've THE OWNERSHIP NOW! |
33 | */ | 62 | */ |
34 | OPimRecord *record( const QString& service, int uid ); | 63 | OPimRecord *record( const QString& service, int uid ); |
35 | 64 | ||
36 | /** | 65 | /** |
37 | * return the QCopChannel for service | 66 | * return the QCopChannel for service |
38 | * When we will use Qtopia Services it will be used here | 67 | * When we will use Qtopia Services it will be used here |
39 | */ | 68 | */ |
40 | QCString qcopChannel( enum BuiltIn& )const; | 69 | QCString qcopChannel( enum BuiltIn& )const; |
41 | QCString qcopChannel( const QString& service )const; | 70 | QCString qcopChannel( const QString& service )const; |
42 | 71 | ||
43 | /** | 72 | /** |
44 | * The Application channel (QPE/Application/name) | 73 | * The Application channel (QPE/Application/name) |
45 | */ | 74 | */ |
46 | QCString applicationChannel( enum BuiltIn& )const; | 75 | QCString applicationChannel( enum BuiltIn& )const; |
47 | QCString applicationChannel( const QString& service )const; | 76 | QCString applicationChannel( const QString& service )const; |
48 | 77 | ||
49 | /** | 78 | /** |
50 | * return a list of available services | 79 | * return a list of available services |
51 | */ | 80 | */ |
52 | QStringList services()const; | 81 | QStringList services()const; |
53 | inline QString serviceName(int rrti )const; | 82 | inline QString serviceName(int rrti )const; |
54 | int serviceId( const QString& Service); | 83 | int serviceId( const QString& Service); |
55 | /** | 84 | /** |
56 | * add a record to a service... ;) | 85 | * add a record to a service... ;) |
57 | */ | 86 | */ |
58 | bool add( const QString& service, const OPimRecord& ); | 87 | bool add( const QString& service, const OPimRecord& ); |
59 | 88 | ||
60 | 89 | ||
61 | /** | 90 | /** |
62 | * record returns an empty record for a given service. | 91 | * record returns an empty record for a given service. |
63 | * Be sure to delete it!!! | 92 | * Be sure to delete it!!! |
64 | * | 93 | * |
65 | */ | 94 | */ |
66 | OPimRecord* record( const QString& service ); | 95 | OPimRecord* record( const QString& service ); |
67 | OPimRecord* record( int rtti ); | 96 | OPimRecord* record( int rtti ); |
68 | 97 | ||
69 | /** | 98 | /** |
70 | * you can cast to your | 99 | * you can cast to your |
71 | */ | 100 | */ |
72 | OPimBase* backend( const QString& service ); | 101 | OPimBase* backend( const QString& service ); |
73 | OPimBase* backend( int rtti ); | 102 | OPimBase* backend( int rtti ); |
74 | private: | 103 | private: |
75 | OPimResolver(); | 104 | OPimResolver(); |
76 | void loadData(); | 105 | void loadData(); |
77 | inline bool isBuiltIn( const QString& )const; | 106 | inline bool isBuiltIn( const QString& )const; |
78 | OPimRecord* recordExtern( const QString&, int ); | 107 | OPimRecord* recordExtern( const QString&, int ); |
79 | OPimRecord* recordExtern( const QString& ); | 108 | OPimRecord* recordExtern( const QString& ); |
80 | 109 | ||
81 | static OPimResolver* m_self; | 110 | static OPimResolver* m_self; |
82 | struct Data; | 111 | struct Data; |
83 | class Private; | 112 | class Private; |
84 | 113 | ||
85 | Data* data; | 114 | Data* data; |
86 | Private* d; | 115 | Private* d; |
87 | QStringList m_builtIns; | 116 | QStringList m_builtIns; |
88 | }; | 117 | }; |
89 | 118 | ||
119 | } | ||
120 | |||
90 | #endif | 121 | #endif |
diff --git a/libopie2/opiepim/core/opimstate.cpp b/libopie2/opiepim/core/opimstate.cpp index 6fb2feb..1013a1c 100644 --- a/libopie2/opiepim/core/opimstate.cpp +++ b/libopie2/opiepim/core/opimstate.cpp | |||
@@ -1,64 +1,95 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qshared.h> | 29 | #include <qshared.h> |
2 | 30 | ||
3 | #include "opimstate.h" | 31 | #include "opimstate.h" |
4 | 32 | ||
33 | namespace Opie { | ||
5 | /* | 34 | /* |
6 | * for one int this does not make | 35 | * for one int this does not make |
7 | * much sense but never the less | 36 | * much sense but never the less |
8 | * we will do it for the future | 37 | * we will do it for the future |
9 | */ | 38 | */ |
10 | struct OPimState::Data : public QShared { | 39 | struct OPimState::Data : public QShared { |
11 | Data() : QShared(),state(Undefined) { | 40 | Data() : QShared(),state(Undefined) { |
12 | } | 41 | } |
13 | int state; | 42 | int state; |
14 | }; | 43 | }; |
15 | 44 | ||
16 | OPimState::OPimState( int state ) { | 45 | OPimState::OPimState( int state ) { |
17 | data = new Data; | 46 | data = new Data; |
18 | data->state = state; | 47 | data->state = state; |
19 | } | 48 | } |
20 | OPimState::OPimState( const OPimState& st) : | 49 | OPimState::OPimState( const OPimState& st) : |
21 | data( st.data ) { | 50 | data( st.data ) { |
22 | /* ref up */ | 51 | /* ref up */ |
23 | data->ref(); | 52 | data->ref(); |
24 | } | 53 | } |
25 | OPimState::~OPimState() { | 54 | OPimState::~OPimState() { |
26 | if ( data->deref() ) { | 55 | if ( data->deref() ) { |
27 | delete data ; | 56 | delete data ; |
28 | data = 0; | 57 | data = 0; |
29 | } | 58 | } |
30 | } | 59 | } |
31 | bool OPimState::operator==( const OPimState& st) { | 60 | bool OPimState::operator==( const OPimState& st) { |
32 | if ( data->state == st.data->state ) return true; | 61 | if ( data->state == st.data->state ) return true; |
33 | 62 | ||
34 | return false; | 63 | return false; |
35 | } | 64 | } |
36 | OPimState &OPimState::operator=( const OPimState& st) { | 65 | OPimState &OPimState::operator=( const OPimState& st) { |
37 | st.data->ref(); | 66 | st.data->ref(); |
38 | deref(); | 67 | deref(); |
39 | data = st.data; | 68 | data = st.data; |
40 | 69 | ||
41 | return *this; | 70 | return *this; |
42 | } | 71 | } |
43 | void OPimState::setState( int st) { | 72 | void OPimState::setState( int st) { |
44 | copyInternally(); | 73 | copyInternally(); |
45 | data->state = st; | 74 | data->state = st; |
46 | } | 75 | } |
47 | int OPimState::state()const { | 76 | int OPimState::state()const { |
48 | return data->state; | 77 | return data->state; |
49 | } | 78 | } |
50 | void OPimState::deref() { | 79 | void OPimState::deref() { |
51 | if ( data->deref() ) { | 80 | if ( data->deref() ) { |
52 | delete data; | 81 | delete data; |
53 | data = 0l; | 82 | data = 0l; |
54 | } | 83 | } |
55 | } | 84 | } |
56 | void OPimState::copyInternally() { | 85 | void OPimState::copyInternally() { |
57 | /* we need to change it */ | 86 | /* we need to change it */ |
58 | if ( data->count != 1 ) { | 87 | if ( data->count != 1 ) { |
59 | data->deref(); | 88 | data->deref(); |
60 | Data* d2 = new Data; | 89 | Data* d2 = new Data; |
61 | d2->state = data->state; | 90 | d2->state = data->state; |
62 | data = d2; | 91 | data = d2; |
63 | } | 92 | } |
64 | } | 93 | } |
94 | |||
95 | } | ||
diff --git a/libopie2/opiepim/core/opimstate.h b/libopie2/opiepim/core/opimstate.h index cf6af46..78e8cd0 100644 --- a/libopie2/opiepim/core/opimstate.h +++ b/libopie2/opiepim/core/opimstate.h | |||
@@ -1,46 +1,75 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_STATE_H | 29 | #ifndef OPIE_PIM_STATE_H |
2 | #define OPIE_PIM_STATE_H | 30 | #define OPIE_PIM_STATE_H |
3 | 31 | ||
4 | #include <qstring.h> | 32 | #include <qstring.h> |
5 | 33 | ||
34 | namespace Opie { | ||
6 | /** | 35 | /** |
7 | * The State of a Task | 36 | * The State of a Task |
8 | * This class encapsules the state of a todo | 37 | * This class encapsules the state of a todo |
9 | * and it's shared too | 38 | * and it's shared too |
10 | */ | 39 | */ |
11 | /* | 40 | /* |
12 | * in c a simple struct would be enough ;) | 41 | * in c a simple struct would be enough ;) |
13 | * g_new_state(); | 42 | * g_new_state(); |
14 | * g_do_some_thing( state_t* ); | 43 | * g_do_some_thing( state_t* ); |
15 | * ;) | 44 | * ;) |
16 | */ | 45 | */ |
17 | class OPimState { | 46 | class OPimState { |
18 | public: | 47 | public: |
19 | enum State { | 48 | enum State { |
20 | Started = 0, | 49 | Started = 0, |
21 | Postponed, | 50 | Postponed, |
22 | Finished, | 51 | Finished, |
23 | NotStarted, | 52 | NotStarted, |
24 | Undefined | 53 | Undefined |
25 | }; | 54 | }; |
26 | OPimState( int state = Undefined ); | 55 | OPimState( int state = Undefined ); |
27 | OPimState( const OPimState& ); | 56 | OPimState( const OPimState& ); |
28 | ~OPimState(); | 57 | ~OPimState(); |
29 | 58 | ||
30 | bool operator==( const OPimState& ); | 59 | bool operator==( const OPimState& ); |
31 | OPimState &operator=( const OPimState& ); | 60 | OPimState &operator=( const OPimState& ); |
32 | void setState( int state); | 61 | void setState( int state); |
33 | int state()const; | 62 | int state()const; |
34 | private: | 63 | private: |
35 | void deref(); | 64 | void deref(); |
36 | inline void copyInternally(); | 65 | inline void copyInternally(); |
37 | 66 | ||
38 | struct Data; | 67 | struct Data; |
39 | Data* data; | 68 | Data* data; |
40 | 69 | ||
41 | class Private; | 70 | class Private; |
42 | Private *d; | 71 | Private *d; |
43 | }; | 72 | }; |
44 | 73 | ||
45 | 74 | } | |
46 | #endif | 75 | #endif |
diff --git a/libopie2/opiepim/core/opimxref.cpp b/libopie2/opiepim/core/opimxref.cpp index 8eefbd8..85d3345 100644 --- a/libopie2/opiepim/core/opimxref.cpp +++ b/libopie2/opiepim/core/opimxref.cpp | |||
@@ -1,47 +1,79 @@ | |||
1 | #include "opimxref.h" | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | #include <opie2/opimxref.h> | ||
30 | |||
31 | namespace Opie { | ||
2 | 32 | ||
3 | OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two ) | 33 | OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two ) |
4 | : m_partners(2) | 34 | : m_partners(2) |
5 | { | 35 | { |
6 | m_partners[0] = one; | 36 | m_partners[0] = one; |
7 | m_partners[1] = two; | 37 | m_partners[1] = two; |
8 | } | 38 | } |
9 | OPimXRef::OPimXRef() | 39 | OPimXRef::OPimXRef() |
10 | : m_partners(2) | 40 | : m_partners(2) |
11 | { | 41 | { |
12 | 42 | ||
13 | } | 43 | } |
14 | OPimXRef::OPimXRef( const OPimXRef& ref) { | 44 | OPimXRef::OPimXRef( const OPimXRef& ref) { |
15 | *this = ref; | 45 | *this = ref; |
16 | } | 46 | } |
17 | OPimXRef::~OPimXRef() { | 47 | OPimXRef::~OPimXRef() { |
18 | } | 48 | } |
19 | OPimXRef &OPimXRef::operator=( const OPimXRef& ref) { | 49 | OPimXRef &OPimXRef::operator=( const OPimXRef& ref) { |
20 | m_partners = ref.m_partners; | 50 | m_partners = ref.m_partners; |
21 | m_partners.detach(); | 51 | m_partners.detach(); |
22 | 52 | ||
23 | return* this; | 53 | return* this; |
24 | } | 54 | } |
25 | bool OPimXRef::operator==( const OPimXRef& oper ) { | 55 | bool OPimXRef::operator==( const OPimXRef& oper ) { |
26 | if ( m_partners == oper.m_partners ) return true; | 56 | if ( m_partners == oper.m_partners ) return true; |
27 | 57 | ||
28 | return false; | 58 | return false; |
29 | } | 59 | } |
30 | OPimXRefPartner OPimXRef::partner( enum Partners par) const{ | 60 | OPimXRefPartner OPimXRef::partner( enum Partners par) const{ |
31 | return m_partners[par]; | 61 | return m_partners[par]; |
32 | } | 62 | } |
33 | void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) { | 63 | void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) { |
34 | m_partners[par] = part; | 64 | m_partners[par] = part; |
35 | } | 65 | } |
36 | bool OPimXRef::containsString( const QString& string ) const{ | 66 | bool OPimXRef::containsString( const QString& string ) const{ |
37 | if ( m_partners[One].service() == string || | 67 | if ( m_partners[One].service() == string || |
38 | m_partners[Two].service() == string ) return true; | 68 | m_partners[Two].service() == string ) return true; |
39 | 69 | ||
40 | return false; | 70 | return false; |
41 | } | 71 | } |
42 | bool OPimXRef::containsUid( int uid ) const{ | 72 | bool OPimXRef::containsUid( int uid ) const{ |
43 | if ( m_partners[One].uid() == uid || | 73 | if ( m_partners[One].uid() == uid || |
44 | m_partners[Two].uid() == uid ) return true; | 74 | m_partners[Two].uid() == uid ) return true; |
45 | 75 | ||
46 | return false; | 76 | return false; |
47 | } | 77 | } |
78 | |||
79 | } | ||
diff --git a/libopie2/opiepim/core/opimxref.h b/libopie2/opiepim/core/opimxref.h index 6852651..820c9c4 100644 --- a/libopie2/opiepim/core/opimxref.h +++ b/libopie2/opiepim/core/opimxref.h | |||
@@ -1,39 +1,71 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
1 | #ifndef OPIM_XREF_H | 30 | #ifndef OPIM_XREF_H |
2 | #define OPIM_XREF_H | 31 | #define OPIM_XREF_H |
3 | 32 | ||
4 | #include <qarray.h> | 33 | #include <qarray.h> |
5 | #include <qvaluelist.h> | 34 | #include <qvaluelist.h> |
6 | 35 | ||
7 | #include <opie/opimxrefpartner.h> | 36 | #include <opie2/opimxrefpartner.h> |
8 | 37 | ||
38 | namespace Opie { | ||
9 | /** | 39 | /** |
10 | * this is a Cross Referecne between | 40 | * this is a Cross Referecne between |
11 | * two Cross Reference Partners | 41 | * two Cross Reference Partners |
12 | */ | 42 | */ |
13 | class OPimXRef { | 43 | class OPimXRef { |
14 | public: | 44 | public: |
15 | typedef QValueList<OPimXRef> ValueList; | 45 | typedef QValueList<OPimXRef> ValueList; |
16 | enum Partners { One, Two }; | 46 | enum Partners { One, Two }; |
17 | OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); | 47 | OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); |
18 | OPimXRef(); | 48 | OPimXRef(); |
19 | OPimXRef( const OPimXRef& ); | 49 | OPimXRef( const OPimXRef& ); |
20 | ~OPimXRef(); | 50 | ~OPimXRef(); |
21 | 51 | ||
22 | OPimXRef &operator=( const OPimXRef& ); | 52 | OPimXRef &operator=( const OPimXRef& ); |
23 | bool operator==( const OPimXRef& ); | 53 | bool operator==( const OPimXRef& ); |
24 | 54 | ||
25 | OPimXRefPartner partner( enum Partners )const; | 55 | OPimXRefPartner partner( enum Partners )const; |
26 | 56 | ||
27 | void setPartner( enum Partners, const OPimXRefPartner& ); | 57 | void setPartner( enum Partners, const OPimXRefPartner& ); |
28 | 58 | ||
29 | bool containsString( const QString& service)const; | 59 | bool containsString( const QString& service)const; |
30 | bool containsUid( int uid )const; | 60 | bool containsUid( int uid )const; |
31 | 61 | ||
32 | private: | 62 | private: |
33 | QArray<OPimXRefPartner> m_partners; | 63 | QArray<OPimXRefPartner> m_partners; |
34 | 64 | ||
35 | class Private; | 65 | class Private; |
36 | Private *d; | 66 | Private *d; |
37 | }; | 67 | }; |
38 | 68 | ||
69 | } | ||
70 | |||
39 | #endif | 71 | #endif |
diff --git a/libopie2/opiepim/core/opimxrefmanager.cpp b/libopie2/opiepim/core/opimxrefmanager.cpp index 58bfd24..bf6fed6 100644 --- a/libopie2/opiepim/core/opimxrefmanager.cpp +++ b/libopie2/opiepim/core/opimxrefmanager.cpp | |||
@@ -1,71 +1,102 @@ | |||
1 | #include "opimxrefmanager.h" | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | #include <opie2/opimxrefmanager.h> | ||
2 | 30 | ||
31 | namespace Opie { | ||
3 | 32 | ||
4 | OPimXRefManager::OPimXRefManager() { | 33 | OPimXRefManager::OPimXRefManager() { |
5 | } | 34 | } |
6 | OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) { | 35 | OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) { |
7 | m_list = ref.m_list; | 36 | m_list = ref.m_list; |
8 | } | 37 | } |
9 | OPimXRefManager::~OPimXRefManager() { | 38 | OPimXRefManager::~OPimXRefManager() { |
10 | } | 39 | } |
11 | OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) { | 40 | OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) { |
12 | m_list = ref.m_list; | 41 | m_list = ref.m_list; |
13 | return *this; | 42 | return *this; |
14 | } | 43 | } |
15 | bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) { | 44 | bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) { |
16 | // if ( m_list == ref.m_list ) return true; | 45 | // if ( m_list == ref.m_list ) return true; |
17 | 46 | ||
18 | return false; | 47 | return false; |
19 | } | 48 | } |
20 | void OPimXRefManager::add( const OPimXRef& ref) { | 49 | void OPimXRefManager::add( const OPimXRef& ref) { |
21 | m_list.append( ref ); | 50 | m_list.append( ref ); |
22 | } | 51 | } |
23 | void OPimXRefManager::remove( const OPimXRef& ref) { | 52 | void OPimXRefManager::remove( const OPimXRef& ref) { |
24 | m_list.remove( ref ); | 53 | m_list.remove( ref ); |
25 | } | 54 | } |
26 | void OPimXRefManager::replace( const OPimXRef& ref) { | 55 | void OPimXRefManager::replace( const OPimXRef& ref) { |
27 | m_list.remove( ref ); | 56 | m_list.remove( ref ); |
28 | m_list.append( ref ); | 57 | m_list.append( ref ); |
29 | } | 58 | } |
30 | void OPimXRefManager::clear() { | 59 | void OPimXRefManager::clear() { |
31 | m_list.clear(); | 60 | m_list.clear(); |
32 | } | 61 | } |
33 | QStringList OPimXRefManager::apps()const { | 62 | QStringList OPimXRefManager::apps()const { |
34 | OPimXRef::ValueList::ConstIterator it; | 63 | OPimXRef::ValueList::ConstIterator it; |
35 | QStringList list; | 64 | QStringList list; |
36 | 65 | ||
37 | QString str; | 66 | QString str; |
38 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 67 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
39 | str = (*it).partner( OPimXRef::One ).service(); | 68 | str = (*it).partner( OPimXRef::One ).service(); |
40 | if ( !list.contains( str ) ) list << str; | 69 | if ( !list.contains( str ) ) list << str; |
41 | 70 | ||
42 | str = (*it).partner( OPimXRef::Two ).service(); | 71 | str = (*it).partner( OPimXRef::Two ).service(); |
43 | if ( !list.contains( str ) ) list << str; | 72 | if ( !list.contains( str ) ) list << str; |
44 | } | 73 | } |
45 | return list; | 74 | return list; |
46 | } | 75 | } |
47 | OPimXRef::ValueList OPimXRefManager::list()const { | 76 | OPimXRef::ValueList OPimXRefManager::list()const { |
48 | return m_list; | 77 | return m_list; |
49 | } | 78 | } |
50 | OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{ | 79 | OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{ |
51 | OPimXRef::ValueList list; | 80 | OPimXRef::ValueList list; |
52 | OPimXRef::ValueList::ConstIterator it; | 81 | OPimXRef::ValueList::ConstIterator it; |
53 | 82 | ||
54 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 83 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
55 | if ( (*it).containsString( appName ) ) | 84 | if ( (*it).containsString( appName ) ) |
56 | list.append( (*it) ); | 85 | list.append( (*it) ); |
57 | } | 86 | } |
58 | 87 | ||
59 | return list; | 88 | return list; |
60 | } | 89 | } |
61 | OPimXRef::ValueList OPimXRefManager::list( int uid )const { | 90 | OPimXRef::ValueList OPimXRefManager::list( int uid )const { |
62 | OPimXRef::ValueList list; | 91 | OPimXRef::ValueList list; |
63 | OPimXRef::ValueList::ConstIterator it; | 92 | OPimXRef::ValueList::ConstIterator it; |
64 | 93 | ||
65 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 94 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
66 | if ( (*it).containsUid( uid ) ) | 95 | if ( (*it).containsUid( uid ) ) |
67 | list.append( (*it) ); | 96 | list.append( (*it) ); |
68 | } | 97 | } |
69 | 98 | ||
70 | return list; | 99 | return list; |
71 | } | 100 | } |
101 | |||
102 | } | ||
diff --git a/libopie2/opiepim/core/opimxrefmanager.h b/libopie2/opiepim/core/opimxrefmanager.h index c485e98..fa2d7f4 100644 --- a/libopie2/opiepim/core/opimxrefmanager.h +++ b/libopie2/opiepim/core/opimxrefmanager.h | |||
@@ -1,43 +1,74 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIM_XREF_MANAGER_H | 29 | #ifndef OPIM_XREF_MANAGER_H |
2 | #define OPIM_XREF_MANAGER_H | 30 | #define OPIM_XREF_MANAGER_H |
3 | 31 | ||
4 | #include <qstringlist.h> | 32 | #include <qstringlist.h> |
5 | 33 | ||
6 | #include <opie/opimxref.h> | 34 | #include <opie2/opimxref.h> |
7 | 35 | ||
36 | namespace Opie { | ||
8 | /** | 37 | /** |
9 | * This is a simple manager for | 38 | * This is a simple manager for |
10 | * OPimXRefs. | 39 | * OPimXRefs. |
11 | * It allows addition, removing, replacing | 40 | * It allows addition, removing, replacing |
12 | * clearing and 'querying' the XRef... | 41 | * clearing and 'querying' the XRef... |
13 | */ | 42 | */ |
14 | class OPimXRefManager { | 43 | class OPimXRefManager { |
15 | public: | 44 | public: |
16 | OPimXRefManager(); | 45 | OPimXRefManager(); |
17 | OPimXRefManager( const OPimXRefManager& ); | 46 | OPimXRefManager( const OPimXRefManager& ); |
18 | ~OPimXRefManager(); | 47 | ~OPimXRefManager(); |
19 | 48 | ||
20 | OPimXRefManager& operator=( const OPimXRefManager& ); | 49 | OPimXRefManager& operator=( const OPimXRefManager& ); |
21 | bool operator==( const OPimXRefManager& ); | 50 | bool operator==( const OPimXRefManager& ); |
22 | 51 | ||
23 | void add( const OPimXRef& ); | 52 | void add( const OPimXRef& ); |
24 | void remove( const OPimXRef& ); | 53 | void remove( const OPimXRef& ); |
25 | void replace( const OPimXRef& ); | 54 | void replace( const OPimXRef& ); |
26 | 55 | ||
27 | void clear(); | 56 | void clear(); |
28 | 57 | ||
29 | /** | 58 | /** |
30 | * apps participating | 59 | * apps participating |
31 | */ | 60 | */ |
32 | QStringList apps()const; | 61 | QStringList apps()const; |
33 | OPimXRef::ValueList list()const; | 62 | OPimXRef::ValueList list()const; |
34 | OPimXRef::ValueList list( const QString& service )const; | 63 | OPimXRef::ValueList list( const QString& service )const; |
35 | OPimXRef::ValueList list( int uid )const; | 64 | OPimXRef::ValueList list( int uid )const; |
36 | 65 | ||
37 | private: | 66 | private: |
38 | OPimXRef::ValueList m_list; | 67 | OPimXRef::ValueList m_list; |
39 | class Private; | 68 | class Private; |
40 | Private *d; | 69 | Private *d; |
41 | }; | 70 | }; |
42 | 71 | ||
72 | } | ||
73 | |||
43 | #endif | 74 | #endif |
diff --git a/libopie2/opiepim/core/opimxrefpartner.cpp b/libopie2/opiepim/core/opimxrefpartner.cpp index 6ef3efb..f6ccc7f 100644 --- a/libopie2/opiepim/core/opimxrefpartner.cpp +++ b/libopie2/opiepim/core/opimxrefpartner.cpp | |||
@@ -1,43 +1,75 @@ | |||
1 | #include "opimxrefpartner.h" | 1 | /* |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | #include <opie2/opimxrefpartner.h> | ||
30 | |||
31 | namespace Opie { | ||
2 | 32 | ||
3 | OPimXRefPartner::OPimXRefPartner( const QString& appName, | 33 | OPimXRefPartner::OPimXRefPartner( const QString& appName, |
4 | int uid, int field ) | 34 | int uid, int field ) |
5 | : m_app(appName), m_uid(uid), m_field( field ) { | 35 | : m_app(appName), m_uid(uid), m_field( field ) { |
6 | } | 36 | } |
7 | OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) { | 37 | OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) { |
8 | *this = ref; | 38 | *this = ref; |
9 | } | 39 | } |
10 | OPimXRefPartner::~OPimXRefPartner() { | 40 | OPimXRefPartner::~OPimXRefPartner() { |
11 | } | 41 | } |
12 | OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) { | 42 | OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) { |
13 | m_app = par.m_app; | 43 | m_app = par.m_app; |
14 | m_uid = par.m_uid; | 44 | m_uid = par.m_uid; |
15 | m_field = par.m_field; | 45 | m_field = par.m_field; |
16 | 46 | ||
17 | return *this; | 47 | return *this; |
18 | } | 48 | } |
19 | bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) { | 49 | bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) { |
20 | if ( m_app != par.m_app ) return false; | 50 | if ( m_app != par.m_app ) return false; |
21 | if ( m_uid != par.m_uid ) return false; | 51 | if ( m_uid != par.m_uid ) return false; |
22 | if ( m_field != par.m_field ) return false; | 52 | if ( m_field != par.m_field ) return false; |
23 | 53 | ||
24 | return true; | 54 | return true; |
25 | } | 55 | } |
26 | QString OPimXRefPartner::service()const { | 56 | QString OPimXRefPartner::service()const { |
27 | return m_app; | 57 | return m_app; |
28 | } | 58 | } |
29 | int OPimXRefPartner::uid()const { | 59 | int OPimXRefPartner::uid()const { |
30 | return m_uid; | 60 | return m_uid; |
31 | } | 61 | } |
32 | int OPimXRefPartner::field()const { | 62 | int OPimXRefPartner::field()const { |
33 | return m_field; | 63 | return m_field; |
34 | } | 64 | } |
35 | void OPimXRefPartner::setService( const QString& appName ) { | 65 | void OPimXRefPartner::setService( const QString& appName ) { |
36 | m_app = appName; | 66 | m_app = appName; |
37 | } | 67 | } |
38 | void OPimXRefPartner::setUid( int uid ) { | 68 | void OPimXRefPartner::setUid( int uid ) { |
39 | m_uid = uid; | 69 | m_uid = uid; |
40 | } | 70 | } |
41 | void OPimXRefPartner::setField( int field ) { | 71 | void OPimXRefPartner::setField( int field ) { |
42 | m_field = field; | 72 | m_field = field; |
43 | } | 73 | } |
74 | |||
75 | } | ||
diff --git a/libopie2/opiepim/core/opimxrefpartner.h b/libopie2/opiepim/core/opimxrefpartner.h index d76e384..6853d5b 100644 --- a/libopie2/opiepim/core/opimxrefpartner.h +++ b/libopie2/opiepim/core/opimxrefpartner.h | |||
@@ -1,40 +1,70 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIM_XREF_PARTNER_H | 29 | #ifndef OPIM_XREF_PARTNER_H |
2 | #define OPIM_XREF_PARTNER_H | 30 | #define OPIM_XREF_PARTNER_H |
3 | 31 | ||
4 | #include <qstring.h> | 32 | #include <qstring.h> |
5 | 33 | ||
34 | namespace Opie { | ||
6 | /** | 35 | /** |
7 | * This class represents one partner | 36 | * This class represents one partner |
8 | * of a Cross Reference. | 37 | * of a Cross Reference. |
9 | * In Opie one application | 38 | * In Opie one application |
10 | * can link one uid | 39 | * can link one uid |
11 | * with one tableId( fieldId ) to another. | 40 | * with one tableId( fieldId ) to another. |
12 | */ | 41 | */ |
13 | class OPimXRefPartner { | 42 | class OPimXRefPartner { |
14 | public: | 43 | public: |
15 | OPimXRefPartner( const QString& service = QString::null, | 44 | OPimXRefPartner( const QString& service = QString::null, |
16 | int uid = 0, int field = -1 ); | 45 | int uid = 0, int field = -1 ); |
17 | OPimXRefPartner( const OPimXRefPartner& ); | 46 | OPimXRefPartner( const OPimXRefPartner& ); |
18 | OPimXRefPartner& operator=( const OPimXRefPartner& ); | 47 | OPimXRefPartner& operator=( const OPimXRefPartner& ); |
19 | ~OPimXRefPartner(); | 48 | ~OPimXRefPartner(); |
20 | 49 | ||
21 | bool operator==(const OPimXRefPartner& ); | 50 | bool operator==(const OPimXRefPartner& ); |
22 | 51 | ||
23 | QString service()const; | 52 | QString service()const; |
24 | int uid()const; | 53 | int uid()const; |
25 | int field()const; | 54 | int field()const; |
26 | 55 | ||
27 | void setService( const QString& service ); | 56 | void setService( const QString& service ); |
28 | void setUid( int uid ); | 57 | void setUid( int uid ); |
29 | void setField( int field ); | 58 | void setField( int field ); |
30 | private: | 59 | private: |
31 | QString m_app; | 60 | QString m_app; |
32 | int m_uid; | 61 | int m_uid; |
33 | int m_field; | 62 | int m_field; |
34 | 63 | ||
35 | class Private; | 64 | class Private; |
36 | Private* d; | 65 | Private* d; |
37 | }; | 66 | }; |
38 | 67 | ||
68 | } | ||
39 | 69 | ||
40 | #endif | 70 | #endif |
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index f46f22e..033f264 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -1,201 +1,231 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
1 | #include <time.h> | 30 | #include <time.h> |
2 | 31 | ||
3 | #include <qshared.h> | 32 | #include <qshared.h> |
4 | 33 | ||
5 | #include <qtopia/timeconversion.h> | 34 | #include <qtopia/timeconversion.h> |
6 | 35 | ||
7 | #include "otimezone.h" | 36 | #include <opie2/otimezone.h> |
8 | #include "orecur.h" | 37 | #include <opie2/orecur.h> |
9 | 38 | ||
39 | namespace Opie { | ||
10 | struct ORecur::Data : public QShared { | 40 | struct ORecur::Data : public QShared { |
11 | Data() : QShared() { | 41 | Data() : QShared() { |
12 | type = ORecur::NoRepeat; | 42 | type = ORecur::NoRepeat; |
13 | freq = -1; | 43 | freq = -1; |
14 | days = 0; | 44 | days = 0; |
15 | pos = 0; | 45 | pos = 0; |
16 | create = QDateTime::currentDateTime(); | 46 | create = QDateTime::currentDateTime(); |
17 | hasEnd = FALSE; | 47 | hasEnd = FALSE; |
18 | end = QDate::currentDate(); | 48 | end = QDate::currentDate(); |
19 | } | 49 | } |
20 | char days; // Q_UINT8 for 8 seven days;) | 50 | char days; // Q_UINT8 for 8 seven days;) |
21 | ORecur::RepeatType type; | 51 | ORecur::RepeatType type; |
22 | int freq; | 52 | int freq; |
23 | int pos; | 53 | int pos; |
24 | bool hasEnd : 1; | 54 | bool hasEnd : 1; |
25 | QDate end; | 55 | QDate end; |
26 | QDateTime create; | 56 | QDateTime create; |
27 | int rep; | 57 | int rep; |
28 | QString app; | 58 | QString app; |
29 | ExceptionList list; | 59 | ExceptionList list; |
30 | QDate start; | 60 | QDate start; |
31 | }; | 61 | }; |
32 | 62 | ||
33 | 63 | ||
34 | ORecur::ORecur() { | 64 | ORecur::ORecur() { |
35 | data = new Data; | 65 | data = new Data; |
36 | } | 66 | } |
37 | 67 | ||
38 | ORecur::ORecur( const QMap<int, QString>& map ) | 68 | ORecur::ORecur( const QMap<int, QString>& map ) |
39 | { | 69 | { |
40 | ORecur(); | 70 | ORecur(); |
41 | fromMap( map ); | 71 | fromMap( map ); |
42 | } | 72 | } |
43 | 73 | ||
44 | 74 | ||
45 | ORecur::ORecur( const ORecur& rec) | 75 | ORecur::ORecur( const ORecur& rec) |
46 | : data( rec.data ) | 76 | : data( rec.data ) |
47 | { | 77 | { |
48 | data->ref(); | 78 | data->ref(); |
49 | } | 79 | } |
50 | ORecur::~ORecur() { | 80 | ORecur::~ORecur() { |
51 | if ( data->deref() ) { | 81 | if ( data->deref() ) { |
52 | delete data; | 82 | delete data; |
53 | data = 0l; | 83 | data = 0l; |
54 | } | 84 | } |
55 | } | 85 | } |
56 | void ORecur::deref() { | 86 | void ORecur::deref() { |
57 | if ( data->deref() ) { | 87 | if ( data->deref() ) { |
58 | delete data; | 88 | delete data; |
59 | data = 0l; | 89 | data = 0l; |
60 | } | 90 | } |
61 | } | 91 | } |
62 | bool ORecur::operator==( const ORecur& )const { | 92 | bool ORecur::operator==( const ORecur& )const { |
63 | return false; | 93 | return false; |
64 | } | 94 | } |
65 | ORecur &ORecur::operator=( const ORecur& re) { | 95 | ORecur &ORecur::operator=( const ORecur& re) { |
66 | if ( *this == re ) return *this; | 96 | if ( *this == re ) return *this; |
67 | 97 | ||
68 | re.data->ref(); | 98 | re.data->ref(); |
69 | deref(); | 99 | deref(); |
70 | data = re.data; | 100 | data = re.data; |
71 | 101 | ||
72 | return *this; | 102 | return *this; |
73 | } | 103 | } |
74 | bool ORecur::doesRecur()const { | 104 | bool ORecur::doesRecur()const { |
75 | return !( type() == NoRepeat ); | 105 | return !( type() == NoRepeat ); |
76 | } | 106 | } |
77 | /* | 107 | /* |
78 | * we try to be smart here | 108 | * we try to be smart here |
79 | * | 109 | * |
80 | */ | 110 | */ |
81 | bool ORecur::doesRecur( const QDate& date ) { | 111 | bool ORecur::doesRecur( const QDate& date ) { |
82 | /* the day before the recurrance */ | 112 | /* the day before the recurrance */ |
83 | QDate da = date.addDays(-1); | 113 | QDate da = date.addDays(-1); |
84 | 114 | ||
85 | QDate recur; | 115 | QDate recur; |
86 | if (!nextOcurrence( da, recur ) ) | 116 | if (!nextOcurrence( da, recur ) ) |
87 | return false; | 117 | return false; |
88 | 118 | ||
89 | return (recur == date); | 119 | return (recur == date); |
90 | } | 120 | } |
91 | // FIXME unuglify! | 121 | // FIXME unuglify! |
92 | // GPL from Datebookdb.cpp | 122 | // GPL from Datebookdb.cpp |
93 | // FIXME exception list! | 123 | // FIXME exception list! |
94 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { | 124 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { |
95 | bool stillLooking; | 125 | bool stillLooking; |
96 | stillLooking = p_nextOccurrence( from, next ); | 126 | stillLooking = p_nextOccurrence( from, next ); |
97 | while ( stillLooking && data->list.contains(next) ) | 127 | while ( stillLooking && data->list.contains(next) ) |
98 | stillLooking = p_nextOccurrence( next.addDays(1), next ); | 128 | stillLooking = p_nextOccurrence( next.addDays(1), next ); |
99 | 129 | ||
100 | return stillLooking; | 130 | return stillLooking; |
101 | } | 131 | } |
102 | bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { | 132 | bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { |
103 | 133 | ||
104 | // easy checks, first are we too far in the future or too far in the past? | 134 | // easy checks, first are we too far in the future or too far in the past? |
105 | QDate tmpDate; | 135 | QDate tmpDate; |
106 | int freq = frequency(); | 136 | int freq = frequency(); |
107 | int diff, diff2, a; | 137 | int diff, diff2, a; |
108 | int iday, imonth, iyear; | 138 | int iday, imonth, iyear; |
109 | int dayOfWeek = 0; | 139 | int dayOfWeek = 0; |
110 | int firstOfWeek = 0; | 140 | int firstOfWeek = 0; |
111 | int weekOfMonth; | 141 | int weekOfMonth; |
112 | 142 | ||
113 | 143 | ||
114 | if (hasEndDate() && endDate() < from) | 144 | if (hasEndDate() && endDate() < from) |
115 | return FALSE; | 145 | return FALSE; |
116 | 146 | ||
117 | if (start() >= from ) { | 147 | if (start() >= from ) { |
118 | next = start(); | 148 | next = start(); |
119 | return TRUE; | 149 | return TRUE; |
120 | } | 150 | } |
121 | 151 | ||
122 | switch ( type() ) { | 152 | switch ( type() ) { |
123 | case Weekly: | 153 | case Weekly: |
124 | /* weekly is just daily by 7 */ | 154 | /* weekly is just daily by 7 */ |
125 | /* first convert the repeatPattern.Days() mask to the next | 155 | /* first convert the repeatPattern.Days() mask to the next |
126 | day of week valid after from */ | 156 | day of week valid after from */ |
127 | dayOfWeek = from.dayOfWeek(); | 157 | dayOfWeek = from.dayOfWeek(); |
128 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ | 158 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ |
129 | 159 | ||
130 | /* this is done in case freq > 1 and from in week not | 160 | /* this is done in case freq > 1 and from in week not |
131 | for this round */ | 161 | for this round */ |
132 | // firstOfWeek = 0; this is already done at decl. | 162 | // firstOfWeek = 0; this is already done at decl. |
133 | while(!((1 << firstOfWeek) & days() )) | 163 | while(!((1 << firstOfWeek) & days() )) |
134 | firstOfWeek++; | 164 | firstOfWeek++; |
135 | 165 | ||
136 | /* there is at least one 'day', or there would be no event */ | 166 | /* there is at least one 'day', or there would be no event */ |
137 | while(!((1 << (dayOfWeek % 7)) & days() )) | 167 | while(!((1 << (dayOfWeek % 7)) & days() )) |
138 | dayOfWeek++; | 168 | dayOfWeek++; |
139 | 169 | ||
140 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ | 170 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ |
141 | dayOfWeek -= start().dayOfWeek() -1; | 171 | dayOfWeek -= start().dayOfWeek() -1; |
142 | 172 | ||
143 | firstOfWeek = firstOfWeek % 7; /* the actual first of week */ | 173 | firstOfWeek = firstOfWeek % 7; /* the actual first of week */ |
144 | firstOfWeek -= start().dayOfWeek() -1; | 174 | firstOfWeek -= start().dayOfWeek() -1; |
145 | 175 | ||
146 | // dayOfWeek may be negitive now | 176 | // dayOfWeek may be negitive now |
147 | // day of week is number of days to add to start day | 177 | // day of week is number of days to add to start day |
148 | 178 | ||
149 | freq *= 7; | 179 | freq *= 7; |
150 | // FALL-THROUGH !!!!! | 180 | // FALL-THROUGH !!!!! |
151 | case Daily: | 181 | case Daily: |
152 | // the add is for the possible fall through from weekly */ | 182 | // the add is for the possible fall through from weekly */ |
153 | if(start().addDays(dayOfWeek) > from) { | 183 | if(start().addDays(dayOfWeek) > from) { |
154 | /* first week exception */ | 184 | /* first week exception */ |
155 | next = QDate(start().addDays(dayOfWeek) ); | 185 | next = QDate(start().addDays(dayOfWeek) ); |
156 | if ((next > endDate()) | 186 | if ((next > endDate()) |
157 | && hasEndDate() ) | 187 | && hasEndDate() ) |
158 | return FALSE; | 188 | return FALSE; |
159 | return TRUE; | 189 | return TRUE; |
160 | } | 190 | } |
161 | /* if from is middle of a non-week */ | 191 | /* if from is middle of a non-week */ |
162 | 192 | ||
163 | diff = start().addDays(dayOfWeek).daysTo(from) % freq; | 193 | diff = start().addDays(dayOfWeek).daysTo(from) % freq; |
164 | diff2 = start().addDays(firstOfWeek).daysTo(from) % freq; | 194 | diff2 = start().addDays(firstOfWeek).daysTo(from) % freq; |
165 | 195 | ||
166 | if(diff != 0) | 196 | if(diff != 0) |
167 | diff = freq - diff; | 197 | diff = freq - diff; |
168 | if(diff2 != 0) | 198 | if(diff2 != 0) |
169 | diff2 = freq - diff2; | 199 | diff2 = freq - diff2; |
170 | diff = QMIN(diff, diff2); | 200 | diff = QMIN(diff, diff2); |
171 | 201 | ||
172 | next = QDate(from.addDays(diff)); | 202 | next = QDate(from.addDays(diff)); |
173 | if ( (next > endDate()) | 203 | if ( (next > endDate()) |
174 | && hasEndDate() ) | 204 | && hasEndDate() ) |
175 | return FALSE; | 205 | return FALSE; |
176 | return TRUE; | 206 | return TRUE; |
177 | case MonthlyDay: | 207 | case MonthlyDay: |
178 | iday = from.day(); | 208 | iday = from.day(); |
179 | iyear = from.year(); | 209 | iyear = from.year(); |
180 | imonth = from.month(); | 210 | imonth = from.month(); |
181 | /* find equivelent day of month for this month */ | 211 | /* find equivelent day of month for this month */ |
182 | dayOfWeek = start().dayOfWeek(); | 212 | dayOfWeek = start().dayOfWeek(); |
183 | weekOfMonth = (start().day() - 1) / 7; | 213 | weekOfMonth = (start().day() - 1) / 7; |
184 | 214 | ||
185 | /* work out when the next valid month is */ | 215 | /* work out when the next valid month is */ |
186 | a = from.year() - start().year(); | 216 | a = from.year() - start().year(); |
187 | a *= 12; | 217 | a *= 12; |
188 | a = a + (imonth - start().month()); | 218 | a = a + (imonth - start().month()); |
189 | /* a is e.start()monthsFrom(from); */ | 219 | /* a is e.start()monthsFrom(from); */ |
190 | if(a % freq) { | 220 | if(a % freq) { |
191 | a = freq - (a % freq); | 221 | a = freq - (a % freq); |
192 | imonth = from.month() + a; | 222 | imonth = from.month() + a; |
193 | if (imonth > 12) { | 223 | if (imonth > 12) { |
194 | imonth--; | 224 | imonth--; |
195 | iyear += imonth / 12; | 225 | iyear += imonth / 12; |
196 | imonth = imonth % 12; | 226 | imonth = imonth % 12; |
197 | imonth++; | 227 | imonth++; |
198 | } | 228 | } |
199 | } | 229 | } |
200 | /* imonth is now the first month after or on | 230 | /* imonth is now the first month after or on |
201 | from that matches the frequency given */ | 231 | from that matches the frequency given */ |
@@ -402,192 +432,194 @@ QString ORecur::service()const { | |||
402 | return data->app; | 432 | return data->app; |
403 | } | 433 | } |
404 | ORecur::ExceptionList& ORecur::exceptions() { | 434 | ORecur::ExceptionList& ORecur::exceptions() { |
405 | return data->list; | 435 | return data->list; |
406 | } | 436 | } |
407 | void ORecur::setType( const RepeatType& z) { | 437 | void ORecur::setType( const RepeatType& z) { |
408 | checkOrModify(); | 438 | checkOrModify(); |
409 | data->type = z; | 439 | data->type = z; |
410 | } | 440 | } |
411 | void ORecur::setFrequency( int freq ) { | 441 | void ORecur::setFrequency( int freq ) { |
412 | checkOrModify(); | 442 | checkOrModify(); |
413 | data->freq = freq; | 443 | data->freq = freq; |
414 | } | 444 | } |
415 | void ORecur::setPosition( int pos ) { | 445 | void ORecur::setPosition( int pos ) { |
416 | checkOrModify(); | 446 | checkOrModify(); |
417 | data->pos = pos; | 447 | data->pos = pos; |
418 | } | 448 | } |
419 | void ORecur::setDays( char c ) { | 449 | void ORecur::setDays( char c ) { |
420 | checkOrModify(); | 450 | checkOrModify(); |
421 | data->days = c; | 451 | data->days = c; |
422 | } | 452 | } |
423 | void ORecur::setEndDate( const QDate& dt) { | 453 | void ORecur::setEndDate( const QDate& dt) { |
424 | checkOrModify(); | 454 | checkOrModify(); |
425 | data->end = dt; | 455 | data->end = dt; |
426 | } | 456 | } |
427 | void ORecur::setCreatedDateTime( const QDateTime& t) { | 457 | void ORecur::setCreatedDateTime( const QDateTime& t) { |
428 | checkOrModify(); | 458 | checkOrModify(); |
429 | data->create = t; | 459 | data->create = t; |
430 | } | 460 | } |
431 | void ORecur::setHasEndDate( bool b) { | 461 | void ORecur::setHasEndDate( bool b) { |
432 | checkOrModify(); | 462 | checkOrModify(); |
433 | data->hasEnd = b; | 463 | data->hasEnd = b; |
434 | } | 464 | } |
435 | void ORecur::setRepitition( int rep ) { | 465 | void ORecur::setRepitition( int rep ) { |
436 | checkOrModify(); | 466 | checkOrModify(); |
437 | data->rep = rep; | 467 | data->rep = rep; |
438 | } | 468 | } |
439 | void ORecur::setService( const QString& app ) { | 469 | void ORecur::setService( const QString& app ) { |
440 | checkOrModify(); | 470 | checkOrModify(); |
441 | data->app = app; | 471 | data->app = app; |
442 | } | 472 | } |
443 | void ORecur::setStart( const QDate& dt ) { | 473 | void ORecur::setStart( const QDate& dt ) { |
444 | checkOrModify(); | 474 | checkOrModify(); |
445 | data->start = dt; | 475 | data->start = dt; |
446 | } | 476 | } |
447 | void ORecur::checkOrModify() { | 477 | void ORecur::checkOrModify() { |
448 | if ( data->count != 1 ) { | 478 | if ( data->count != 1 ) { |
449 | data->deref(); | 479 | data->deref(); |
450 | Data* d2 = new Data; | 480 | Data* d2 = new Data; |
451 | d2->days = data->days; | 481 | d2->days = data->days; |
452 | d2->type = data->type; | 482 | d2->type = data->type; |
453 | d2->freq = data->freq; | 483 | d2->freq = data->freq; |
454 | d2->pos = data->pos; | 484 | d2->pos = data->pos; |
455 | d2->hasEnd = data->hasEnd; | 485 | d2->hasEnd = data->hasEnd; |
456 | d2->end = data->end; | 486 | d2->end = data->end; |
457 | d2->create = data->create; | 487 | d2->create = data->create; |
458 | d2->rep = data->rep; | 488 | d2->rep = data->rep; |
459 | d2->app = data->app; | 489 | d2->app = data->app; |
460 | d2->list = data->list; | 490 | d2->list = data->list; |
461 | d2->start = data->start; | 491 | d2->start = data->start; |
462 | data = d2; | 492 | data = d2; |
463 | } | 493 | } |
464 | } | 494 | } |
465 | QString ORecur::toString()const { | 495 | QString ORecur::toString()const { |
466 | QString buf; | 496 | QString buf; |
467 | QMap<int, QString> recMap = toMap(); | 497 | QMap<int, QString> recMap = toMap(); |
468 | 498 | ||
469 | buf += " rtype=\""; | 499 | buf += " rtype=\""; |
470 | buf += recMap[ORecur::RType]; | 500 | buf += recMap[ORecur::RType]; |
471 | buf += "\""; | 501 | buf += "\""; |
472 | if (data->days > 0 ) | 502 | if (data->days > 0 ) |
473 | buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; | 503 | buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; |
474 | if ( data->pos != 0 ) | 504 | if ( data->pos != 0 ) |
475 | buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; | 505 | buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; |
476 | 506 | ||
477 | buf += " rfreq=\"" + recMap[ORecur::RFreq] + "\""; | 507 | buf += " rfreq=\"" + recMap[ORecur::RFreq] + "\""; |
478 | buf += " rhasenddate=\"" + recMap[ORecur::RHasEndDate]+ "\""; | 508 | buf += " rhasenddate=\"" + recMap[ORecur::RHasEndDate]+ "\""; |
479 | if ( data->hasEnd ) | 509 | if ( data->hasEnd ) |
480 | buf += " enddt=\"" | 510 | buf += " enddt=\"" |
481 | + recMap[ORecur::EndDate] | 511 | + recMap[ORecur::EndDate] |
482 | + "\""; | 512 | + "\""; |
483 | buf += " created=\"" + recMap[ORecur::Created] + "\""; | 513 | buf += " created=\"" + recMap[ORecur::Created] + "\""; |
484 | 514 | ||
485 | if ( data->list.isEmpty() ) return buf; | 515 | if ( data->list.isEmpty() ) return buf; |
486 | buf += " exceptions=\""; | 516 | buf += " exceptions=\""; |
487 | buf += recMap[ORecur::Exceptions]; | 517 | buf += recMap[ORecur::Exceptions]; |
488 | buf += "\" "; | 518 | buf += "\" "; |
489 | 519 | ||
490 | return buf; | 520 | return buf; |
491 | } | 521 | } |
492 | 522 | ||
493 | QString ORecur::rTypeString() const | 523 | QString ORecur::rTypeString() const |
494 | { | 524 | { |
495 | QString retString; | 525 | QString retString; |
496 | switch ( data->type ) { | 526 | switch ( data->type ) { |
497 | case ORecur::Daily: | 527 | case ORecur::Daily: |
498 | retString = "Daily"; | 528 | retString = "Daily"; |
499 | break; | 529 | break; |
500 | case ORecur::Weekly: | 530 | case ORecur::Weekly: |
501 | retString = "Weekly"; | 531 | retString = "Weekly"; |
502 | break; | 532 | break; |
503 | case ORecur::MonthlyDay: | 533 | case ORecur::MonthlyDay: |
504 | retString = "MonthlyDay"; | 534 | retString = "MonthlyDay"; |
505 | break; | 535 | break; |
506 | case ORecur::MonthlyDate: | 536 | case ORecur::MonthlyDate: |
507 | retString = "MonthlyDate"; | 537 | retString = "MonthlyDate"; |
508 | break; | 538 | break; |
509 | case ORecur::Yearly: | 539 | case ORecur::Yearly: |
510 | retString = "Yearly"; | 540 | retString = "Yearly"; |
511 | break; | 541 | break; |
512 | default: | 542 | default: |
513 | retString = "NoRepeat"; | 543 | retString = "NoRepeat"; |
514 | break; | 544 | break; |
515 | 545 | ||
516 | } | 546 | } |
517 | 547 | ||
518 | return retString; | 548 | return retString; |
519 | } | 549 | } |
520 | 550 | ||
521 | QMap<QString, ORecur::RepeatType> ORecur::rTypeValueConvertMap() const | 551 | QMap<QString, ORecur::RepeatType> ORecur::rTypeValueConvertMap() const |
522 | { | 552 | { |
523 | QMap<QString, RepeatType> convertMap; | 553 | QMap<QString, RepeatType> convertMap; |
524 | 554 | ||
525 | convertMap.insert( QString( "Daily" ), ORecur::Daily ); | 555 | convertMap.insert( QString( "Daily" ), ORecur::Daily ); |
526 | convertMap.insert( QString( "Weekly" ), ORecur::Weekly ); | 556 | convertMap.insert( QString( "Weekly" ), ORecur::Weekly ); |
527 | convertMap.insert( QString( "MonthlyDay" ), ORecur::MonthlyDay ); | 557 | convertMap.insert( QString( "MonthlyDay" ), ORecur::MonthlyDay ); |
528 | convertMap.insert( QString( "MonthlyDate" ), ORecur::MonthlyDate ); | 558 | convertMap.insert( QString( "MonthlyDate" ), ORecur::MonthlyDate ); |
529 | convertMap.insert( QString( "Yearly" ), ORecur::Yearly ); | 559 | convertMap.insert( QString( "Yearly" ), ORecur::Yearly ); |
530 | convertMap.insert( QString( "NoRepeat" ), ORecur::NoRepeat ); | 560 | convertMap.insert( QString( "NoRepeat" ), ORecur::NoRepeat ); |
531 | 561 | ||
532 | return convertMap; | 562 | return convertMap; |
533 | } | 563 | } |
534 | 564 | ||
535 | 565 | ||
536 | QMap<int, QString> ORecur::toMap() const | 566 | QMap<int, QString> ORecur::toMap() const |
537 | { | 567 | { |
538 | QMap<int, QString> retMap; | 568 | QMap<int, QString> retMap; |
539 | 569 | ||
540 | retMap.insert( ORecur::RType, rTypeString() ); | 570 | retMap.insert( ORecur::RType, rTypeString() ); |
541 | retMap.insert( ORecur::RWeekdays, QString::number( static_cast<int>( data->days ) ) ); | 571 | retMap.insert( ORecur::RWeekdays, QString::number( static_cast<int>( data->days ) ) ); |
542 | retMap.insert( ORecur::RPosition, QString::number(data->pos ) ); | 572 | retMap.insert( ORecur::RPosition, QString::number(data->pos ) ); |
543 | retMap.insert( ORecur::RFreq, QString::number( data->freq ) ); | 573 | retMap.insert( ORecur::RFreq, QString::number( data->freq ) ); |
544 | retMap.insert( ORecur::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) ); | 574 | retMap.insert( ORecur::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) ); |
545 | if( data -> hasEnd ) | 575 | if( data -> hasEnd ) |
546 | retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); | 576 | retMap.insert( ORecur::EndDate, QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) ); |
547 | retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); | 577 | retMap.insert( ORecur::Created, QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) ); |
548 | 578 | ||
549 | if ( data->list.isEmpty() ) return retMap; | 579 | if ( data->list.isEmpty() ) return retMap; |
550 | 580 | ||
551 | // save exceptions list here!! | 581 | // save exceptions list here!! |
552 | ExceptionList::ConstIterator it; | 582 | ExceptionList::ConstIterator it; |
553 | ExceptionList list = data->list; | 583 | ExceptionList list = data->list; |
554 | QString exceptBuf; | 584 | QString exceptBuf; |
555 | QDate date; | 585 | QDate date; |
556 | for ( it = list.begin(); it != list.end(); ++it ) { | 586 | for ( it = list.begin(); it != list.end(); ++it ) { |
557 | date = (*it); | 587 | date = (*it); |
558 | if ( it != list.begin() ) exceptBuf += " "; | 588 | if ( it != list.begin() ) exceptBuf += " "; |
559 | 589 | ||
560 | exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); | 590 | exceptBuf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); |
561 | } | 591 | } |
562 | 592 | ||
563 | retMap.insert( ORecur::Exceptions, exceptBuf ); | 593 | retMap.insert( ORecur::Exceptions, exceptBuf ); |
564 | 594 | ||
565 | return retMap; | 595 | return retMap; |
566 | } | 596 | } |
567 | 597 | ||
568 | void ORecur::fromMap( const QMap<int, QString>& map ) | 598 | void ORecur::fromMap( const QMap<int, QString>& map ) |
569 | { | 599 | { |
570 | QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); | 600 | QMap<QString, RepeatType> repTypeMap = rTypeValueConvertMap(); |
571 | 601 | ||
572 | data -> type = repTypeMap[ map [ORecur::RType] ]; | 602 | data -> type = repTypeMap[ map [ORecur::RType] ]; |
573 | data -> days = (char) map[ ORecur::RWeekdays ].toInt(); | 603 | data -> days = (char) map[ ORecur::RWeekdays ].toInt(); |
574 | data -> pos = map[ ORecur::RPosition ].toInt(); | 604 | data -> pos = map[ ORecur::RPosition ].toInt(); |
575 | data -> freq = map[ ORecur::RFreq ].toInt(); | 605 | data -> freq = map[ ORecur::RFreq ].toInt(); |
576 | data -> hasEnd= map[ ORecur::RHasEndDate ].toInt() ? true : false; | 606 | data -> hasEnd= map[ ORecur::RHasEndDate ].toInt() ? true : false; |
577 | OTimeZone utc = OTimeZone::utc(); | 607 | OTimeZone utc = OTimeZone::utc(); |
578 | if ( data -> hasEnd ){ | 608 | if ( data -> hasEnd ){ |
579 | data -> end = utc.fromUTCDateTime( (time_t) map[ ORecur::EndDate ].toLong() ).date(); | 609 | data -> end = utc.fromUTCDateTime( (time_t) map[ ORecur::EndDate ].toLong() ).date(); |
580 | } | 610 | } |
581 | data -> create = utc.fromUTCDateTime( (time_t) map[ ORecur::Created ].toLong() ).date(); | 611 | data -> create = utc.fromUTCDateTime( (time_t) map[ ORecur::Created ].toLong() ).date(); |
582 | 612 | ||
583 | #if 0 | 613 | #if 0 |
584 | // FIXME: Exceptions currently not supported... | 614 | // FIXME: Exceptions currently not supported... |
585 | // Convert the list of exceptions from QString into ExceptionList | 615 | // Convert the list of exceptions from QString into ExceptionList |
586 | data -> list.clear(); | 616 | data -> list.clear(); |
587 | QString exceptStr = map[ ORecur::Exceptions ]; | 617 | QString exceptStr = map[ ORecur::Exceptions ]; |
588 | QStringList exceptList = QStringList::split( " ", exceptStr ); | 618 | QStringList exceptList = QStringList::split( " ", exceptStr ); |
589 | ... | 619 | ... |
590 | #endif | 620 | #endif |
591 | 621 | ||
592 | 622 | ||
593 | } | 623 | } |
624 | |||
625 | } \ No newline at end of file | ||
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h index d7ecd90..60508f5 100644 --- a/libopie2/opiepim/core/orecur.h +++ b/libopie2/opiepim/core/orecur.h | |||
@@ -1,107 +1,134 @@ | |||
1 | /* | 1 | /* |
2 | * GPL from TT | 2 | This file is part of the Opie Project |
3 | */ | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
4 | 29 | ||
5 | #ifndef OPIE_RECUR_H | 30 | #ifndef OPIE_RECUR_H |
6 | #define OPIE_RECUR_H | 31 | #define OPIE_RECUR_H |
7 | 32 | ||
8 | #include <sys/types.h> | 33 | #include <sys/types.h> |
9 | 34 | ||
10 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
11 | #include <qvaluelist.h> | 36 | #include <qvaluelist.h> |
12 | #include <qmap.h> | 37 | #include <qmap.h> |
13 | 38 | ||
14 | 39 | ||
40 | namespace Opie { | ||
15 | /** | 41 | /** |
16 | * Class to handle Recurrencies.. | 42 | * Class to handle Recurrencies.. |
17 | */ | 43 | */ |
18 | 44 | ||
19 | class ORecur { | 45 | class ORecur { |
20 | public: | 46 | public: |
21 | typedef QValueList<QDate> ExceptionList; | 47 | typedef QValueList<QDate> ExceptionList; |
22 | enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, | 48 | enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, |
23 | MonthlyDate, Yearly }; | 49 | MonthlyDate, Yearly }; |
24 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, | 50 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, |
25 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; | 51 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; |
26 | enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate, | 52 | enum Fields{ RType = 0, RWeekdays, RPosition, RFreq, RHasEndDate, |
27 | EndDate, Created, Exceptions }; | 53 | EndDate, Created, Exceptions }; |
28 | 54 | ||
29 | ORecur(); | 55 | ORecur(); |
30 | ORecur( const QMap<int, QString>& map ); | 56 | ORecur( const QMap<int, QString>& map ); |
31 | ORecur( const ORecur& ); | 57 | ORecur( const ORecur& ); |
32 | ~ORecur(); | 58 | ~ORecur(); |
33 | 59 | ||
34 | ORecur &operator=( const ORecur& ); | 60 | ORecur &operator=( const ORecur& ); |
35 | bool operator==(const ORecur& )const; | 61 | bool operator==(const ORecur& )const; |
36 | 62 | ||
37 | bool doesRecur()const; | 63 | bool doesRecur()const; |
38 | /* if it recurrs on that day */ | 64 | /* if it recurrs on that day */ |
39 | bool doesRecur( const QDate& ); | 65 | bool doesRecur( const QDate& ); |
40 | RepeatType type()const; | 66 | RepeatType type()const; |
41 | int frequency()const; | 67 | int frequency()const; |
42 | int position()const; | 68 | int position()const; |
43 | char days()const; | 69 | char days()const; |
44 | bool hasEndDate()const; | 70 | bool hasEndDate()const; |
45 | QDate start()const; | 71 | QDate start()const; |
46 | QDate endDate()const; | 72 | QDate endDate()const; |
47 | QDateTime createdDateTime()const; | 73 | QDateTime createdDateTime()const; |
48 | /** | 74 | /** |
49 | * starting on monday=0, sunday=6 | 75 | * starting on monday=0, sunday=6 |
50 | * for convience | 76 | * for convience |
51 | */ | 77 | */ |
52 | bool repeatOnWeekDay( int day )const; | 78 | bool repeatOnWeekDay( int day )const; |
53 | 79 | ||
54 | /** | 80 | /** |
55 | * FromWhereToStart is not included!!! | 81 | * FromWhereToStart is not included!!! |
56 | */ | 82 | */ |
57 | bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate ); | 83 | bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate ); |
58 | 84 | ||
59 | /** | 85 | /** |
60 | * The module this ORecur belongs to | 86 | * The module this ORecur belongs to |
61 | */ | 87 | */ |
62 | QString service()const; | 88 | QString service()const; |
63 | 89 | ||
64 | /* | 90 | /* |
65 | * reference to the exception list | 91 | * reference to the exception list |
66 | */ | 92 | */ |
67 | ExceptionList &exceptions(); | 93 | ExceptionList &exceptions(); |
68 | 94 | ||
69 | /** | 95 | /** |
70 | * the current repetition | 96 | * the current repetition |
71 | */ | 97 | */ |
72 | int repetition()const; | 98 | int repetition()const; |
73 | 99 | ||
74 | void setType( const RepeatType& ); | 100 | void setType( const RepeatType& ); |
75 | void setFrequency( int freq ); | 101 | void setFrequency( int freq ); |
76 | void setPosition( int pos ); | 102 | void setPosition( int pos ); |
77 | void setDays( char c); | 103 | void setDays( char c); |
78 | void setEndDate( const QDate& dt ); | 104 | void setEndDate( const QDate& dt ); |
79 | void setStart( const QDate& dt ); | 105 | void setStart( const QDate& dt ); |
80 | void setCreatedDateTime( const QDateTime& ); | 106 | void setCreatedDateTime( const QDateTime& ); |
81 | void setHasEndDate( bool b ); | 107 | void setHasEndDate( bool b ); |
82 | void setRepitition(int ); | 108 | void setRepitition(int ); |
83 | 109 | ||
84 | void setService( const QString& ser ); | 110 | void setService( const QString& ser ); |
85 | 111 | ||
86 | QMap<int, QString> toMap() const; | 112 | QMap<int, QString> toMap() const; |
87 | void fromMap( const QMap<int, QString>& map ); | 113 | void fromMap( const QMap<int, QString>& map ); |
88 | 114 | ||
89 | /* almost internal */ | 115 | /* almost internal */ |
90 | QString toString()const; | 116 | QString toString()const; |
91 | private: | 117 | private: |
92 | bool p_nextOccurrence( const QDate& from, QDate& next ); | 118 | bool p_nextOccurrence( const QDate& from, QDate& next ); |
93 | void deref(); | 119 | void deref(); |
94 | inline void checkOrModify(); | 120 | inline void checkOrModify(); |
95 | 121 | ||
96 | /* Converts rType to String */ | 122 | /* Converts rType to String */ |
97 | QString rTypeString() const; | 123 | QString rTypeString() const; |
98 | /* Returns a map to convert Stringname for RType to RepeatType */ | 124 | /* Returns a map to convert Stringname for RType to RepeatType */ |
99 | QMap<QString, RepeatType> rTypeValueConvertMap() const; | 125 | QMap<QString, RepeatType> rTypeValueConvertMap() const; |
100 | 126 | ||
101 | class Data; | 127 | class Data; |
102 | Data* data; | 128 | Data* data; |
103 | class ORecurPrivate; | 129 | class ORecurPrivate; |
104 | ORecurPrivate *d; | 130 | ORecurPrivate *d; |
105 | }; | 131 | }; |
106 | 132 | ||
133 | } | ||
107 | #endif | 134 | #endif |
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h index cadac74..17d9961 100644 --- a/libopie2/opiepim/core/otemplatebase.h +++ b/libopie2/opiepim/core/otemplatebase.h | |||
@@ -1,98 +1,129 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_TEMPLATE_BASE_H | 29 | #ifndef OPIE_TEMPLATE_BASE_H |
2 | #define OPIE_TEMPLATE_BASE_H | 30 | #define OPIE_TEMPLATE_BASE_H |
3 | 31 | ||
4 | #include <qarray.h> | 32 | #include <qarray.h> |
5 | 33 | ||
6 | #include <opie/opimrecord.h> | 34 | #include <opie2/opimrecord.h> |
7 | 35 | ||
8 | 36 | ||
37 | namespace Opie { | ||
9 | /** | 38 | /** |
10 | * Templates do not have a base class, This is why | 39 | * Templates do not have a base class, This is why |
11 | * we've this class | 40 | * we've this class |
12 | * this is here to give us the possibility | 41 | * this is here to give us the possibility |
13 | * to have a common base class | 42 | * to have a common base class |
14 | * You may not want to use that interface internaly | 43 | * You may not want to use that interface internaly |
15 | * POOR mans interface | 44 | * POOR mans interface |
16 | */ | 45 | */ |
17 | class OPimBasePrivate; | 46 | class OPimBasePrivate; |
18 | struct OPimBase { | 47 | struct OPimBase { |
19 | /** | 48 | /** |
20 | * return the rtti | 49 | * return the rtti |
21 | */ | 50 | */ |
22 | virtual int rtti()= 0; | 51 | virtual int rtti()= 0; |
23 | virtual OPimRecord* record()const = 0; | 52 | virtual OPimRecord* record()const = 0; |
24 | virtual OPimRecord* record(int uid)const = 0; | 53 | virtual OPimRecord* record(int uid)const = 0; |
25 | virtual bool add( const OPimRecord& ) = 0; | 54 | virtual bool add( const OPimRecord& ) = 0; |
26 | virtual bool remove( int uid ) = 0; | 55 | virtual bool remove( int uid ) = 0; |
27 | virtual bool remove( const OPimRecord& ) = 0; | 56 | virtual bool remove( const OPimRecord& ) = 0; |
28 | virtual void clear() = 0; | 57 | virtual void clear() = 0; |
29 | virtual bool load() = 0; | 58 | virtual bool load() = 0; |
30 | virtual bool save() = 0; | 59 | virtual bool save() = 0; |
31 | virtual QArray<int> records()const = 0; | 60 | virtual QArray<int> records()const = 0; |
32 | /* | 61 | /* |
33 | * ADD editing here? | 62 | * ADD editing here? |
34 | * -zecke | 63 | * -zecke |
35 | */ | 64 | */ |
36 | private: | 65 | private: |
37 | OPimBasePrivate* d; | 66 | OPimBasePrivate* d; |
38 | 67 | ||
39 | }; | 68 | }; |
40 | /** | 69 | /** |
41 | * internal template base | 70 | * internal template base |
42 | * T needs to implement the copy c'tor!!! | 71 | * T needs to implement the copy c'tor!!! |
43 | */ | 72 | */ |
44 | class OTemplateBasePrivate; | 73 | class OTemplateBasePrivate; |
45 | template <class T = OPimRecord> | 74 | template <class T = OPimRecord> |
46 | class OTemplateBase : public OPimBase { | 75 | class OTemplateBase : public OPimBase { |
47 | public: | 76 | public: |
48 | enum CacheDirection { Forward=0, Reverse }; | 77 | enum CacheDirection { Forward=0, Reverse }; |
49 | OTemplateBase() { | 78 | OTemplateBase() { |
50 | }; | 79 | }; |
51 | virtual ~OTemplateBase() { | 80 | virtual ~OTemplateBase() { |
52 | } | 81 | } |
53 | virtual T find( int uid )const = 0; | 82 | virtual T find( int uid )const = 0; |
54 | 83 | ||
55 | /** | 84 | /** |
56 | * read ahead find | 85 | * read ahead find |
57 | */ | 86 | */ |
58 | virtual T find( int uid, const QArray<int>& items, | 87 | virtual T find( int uid, const QArray<int>& items, |
59 | uint current, CacheDirection dir = Forward )const = 0; | 88 | uint current, CacheDirection dir = Forward )const = 0; |
60 | virtual void cache( const T& )const = 0; | 89 | virtual void cache( const T& )const = 0; |
61 | virtual void setSaneCacheSize( int ) = 0; | 90 | virtual void setSaneCacheSize( int ) = 0; |
62 | 91 | ||
63 | /* reimplement of OPimBase */ | 92 | /* reimplement of OPimBase */ |
64 | int rtti(); | 93 | int rtti(); |
65 | OPimRecord* record()const; | 94 | OPimRecord* record()const; |
66 | OPimRecord* record(int uid )const; | 95 | OPimRecord* record(int uid )const; |
67 | static T* rec(); | 96 | static T* rec(); |
68 | 97 | ||
69 | private: | 98 | private: |
70 | OTemplateBasePrivate *d; | 99 | OTemplateBasePrivate *d; |
71 | }; | 100 | }; |
72 | 101 | ||
73 | /* | 102 | /* |
74 | * implementation | 103 | * implementation |
75 | */ | 104 | */ |
76 | template <class T> | 105 | template <class T> |
77 | int | 106 | int |
78 | OTemplateBase<T>::rtti() { | 107 | OTemplateBase<T>::rtti() { |
79 | return T::rtti(); | 108 | return T::rtti(); |
80 | } | 109 | } |
81 | template <class T> | 110 | template <class T> |
82 | OPimRecord* OTemplateBase<T>::record()const { | 111 | OPimRecord* OTemplateBase<T>::record()const { |
83 | T* t = new T; | 112 | T* t = new T; |
84 | return t; | 113 | return t; |
85 | } | 114 | } |
86 | template <class T> | 115 | template <class T> |
87 | OPimRecord* OTemplateBase<T>::record(int uid )const { | 116 | OPimRecord* OTemplateBase<T>::record(int uid )const { |
88 | T t2 = find(uid ); | 117 | T t2 = find(uid ); |
89 | T* t1 = new T(t2); | 118 | T* t1 = new T(t2); |
90 | 119 | ||
91 | return t1; | 120 | return t1; |
92 | }; | 121 | }; |
93 | template <class T> | 122 | template <class T> |
94 | T* OTemplateBase<T>::rec() { | 123 | T* OTemplateBase<T>::rec() { |
95 | return new T; | 124 | return new T; |
96 | } | 125 | } |
97 | 126 | ||
127 | } | ||
128 | |||
98 | #endif | 129 | #endif |
diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/otimezone.cpp index 34659c3..dab68af 100644 --- a/libopie2/opiepim/core/otimezone.cpp +++ b/libopie2/opiepim/core/otimezone.cpp | |||
@@ -1,113 +1,146 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
1 | #include <stdio.h> | 30 | #include <stdio.h> |
2 | #include <stdlib.h> | 31 | #include <stdlib.h> |
3 | 32 | ||
4 | #include <sys/types.h> | 33 | #include <sys/types.h> |
5 | 34 | ||
6 | #include "otimezone.h" | 35 | #include <opie2/otimezone.h> |
7 | 36 | ||
8 | namespace { | 37 | namespace Opie { |
9 | 38 | ||
10 | QDateTime utcTime( time_t t) { | 39 | QDateTime utcTime( time_t t) { |
11 | tm* broken = ::gmtime( &t ); | 40 | tm* broken = ::gmtime( &t ); |
12 | QDateTime ret; | 41 | QDateTime ret; |
13 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); | 42 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); |
14 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); | 43 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); |
15 | return ret; | 44 | return ret; |
16 | } | 45 | } |
17 | QDateTime utcTime( time_t t, const QString& zone) { | 46 | QDateTime utcTime( time_t t, const QString& zone) { |
18 | QCString org = ::getenv( "TZ" ); | 47 | QCString org = ::getenv( "TZ" ); |
19 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac | 48 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac |
20 | ::setenv( "TZ", zone.latin1(), true ); | 49 | ::setenv( "TZ", zone.latin1(), true ); |
21 | ::tzset(); | 50 | ::tzset(); |
22 | 51 | ||
23 | tm* broken = ::localtime( &t ); | 52 | tm* broken = ::localtime( &t ); |
24 | ::setenv( "TZ", org, true ); | 53 | ::setenv( "TZ", org, true ); |
25 | #else | 54 | #else |
26 | #warning "Need a replacement for MacOSX!!" | 55 | #warning "Need a replacement for MacOSX!!" |
27 | tm* broken = ::localtime( &t ); | 56 | tm* broken = ::localtime( &t ); |
28 | #endif | 57 | #endif |
29 | 58 | ||
30 | QDateTime ret; | 59 | QDateTime ret; |
31 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); | 60 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); |
32 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); | 61 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); |
33 | 62 | ||
34 | return ret; | 63 | return ret; |
35 | } | 64 | } |
36 | time_t to_Time_t( const QDateTime& utc, const QString& str ) { | 65 | time_t to_Time_t( const QDateTime& utc, const QString& str ) { |
37 | QDate d = utc.date(); | 66 | QDate d = utc.date(); |
38 | QTime t = utc.time(); | 67 | QTime t = utc.time(); |
39 | 68 | ||
40 | tm broken; | 69 | tm broken; |
41 | broken.tm_year = d.year() - 1900; | 70 | broken.tm_year = d.year() - 1900; |
42 | broken.tm_mon = d.month() - 1; | 71 | broken.tm_mon = d.month() - 1; |
43 | broken.tm_mday = d.day(); | 72 | broken.tm_mday = d.day(); |
44 | broken.tm_hour = t.hour(); | 73 | broken.tm_hour = t.hour(); |
45 | broken.tm_min = t.minute(); | 74 | broken.tm_min = t.minute(); |
46 | broken.tm_sec = t.second(); | 75 | broken.tm_sec = t.second(); |
47 | 76 | ||
48 | QCString org = ::getenv( "TZ" ); | 77 | QCString org = ::getenv( "TZ" ); |
49 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac | 78 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac |
50 | ::setenv( "TZ", str.latin1(), true ); | 79 | ::setenv( "TZ", str.latin1(), true ); |
51 | ::tzset(); | 80 | ::tzset(); |
52 | 81 | ||
53 | time_t ti = ::mktime( &broken ); | 82 | time_t ti = ::mktime( &broken ); |
54 | ::setenv( "TZ", org, true ); | 83 | ::setenv( "TZ", org, true ); |
55 | #else | 84 | #else |
56 | #warning "Need a replacement for MacOSX!!" | 85 | #warning "Need a replacement for MacOSX!!" |
57 | time_t ti = ::mktime( &broken ); | 86 | time_t ti = ::mktime( &broken ); |
58 | #endif | 87 | #endif |
59 | return ti; | 88 | return ti; |
60 | } | 89 | } |
61 | } | 90 | } |
91 | |||
92 | namespace Opie { | ||
62 | OTimeZone::OTimeZone( const ZoneName& zone ) | 93 | OTimeZone::OTimeZone( const ZoneName& zone ) |
63 | : m_name(zone) { | 94 | : m_name(zone) { |
64 | } | 95 | } |
65 | OTimeZone::~OTimeZone() { | 96 | OTimeZone::~OTimeZone() { |
66 | } | 97 | } |
67 | 98 | ||
68 | bool OTimeZone::isValid()const { | 99 | bool OTimeZone::isValid()const { |
69 | return !m_name.isEmpty(); | 100 | return !m_name.isEmpty(); |
70 | } | 101 | } |
71 | 102 | ||
72 | /* | 103 | /* |
73 | * we will get the current timezone | 104 | * we will get the current timezone |
74 | * and ask it to convert to the timezone date | 105 | * and ask it to convert to the timezone date |
75 | */ | 106 | */ |
76 | QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) { | 107 | QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) { |
77 | return OTimeZone::current().toDateTime( dt, *this ); | 108 | return OTimeZone::current().toDateTime( dt, *this ); |
78 | } | 109 | } |
79 | QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) { | 110 | QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) { |
80 | return OTimeZone::utc().toDateTime( dt, *this ); | 111 | return OTimeZone::utc().toDateTime( dt, *this ); |
81 | } | 112 | } |
82 | QDateTime OTimeZone::fromUTCDateTime( time_t t) { | 113 | QDateTime OTimeZone::fromUTCDateTime( time_t t) { |
83 | return utcTime( t ); | 114 | return utcTime( t ); |
84 | } | 115 | } |
85 | QDateTime OTimeZone::toDateTime( time_t t) { | 116 | QDateTime OTimeZone::toDateTime( time_t t) { |
86 | return utcTime( t, m_name ); | 117 | return utcTime( t, m_name ); |
87 | } | 118 | } |
88 | /* | 119 | /* |
89 | * convert dt to utc using zone.m_name | 120 | * convert dt to utc using zone.m_name |
90 | * convert utc -> timeZoneDT using this->m_name | 121 | * convert utc -> timeZoneDT using this->m_name |
91 | */ | 122 | */ |
92 | QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) { | 123 | QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) { |
93 | time_t utc = to_Time_t( dt, zone.m_name ); | 124 | time_t utc = to_Time_t( dt, zone.m_name ); |
94 | qWarning("%d %s", utc, zone.m_name.latin1() ); | 125 | qWarning("%d %s", utc, zone.m_name.latin1() ); |
95 | return utcTime( utc, m_name ); | 126 | return utcTime( utc, m_name ); |
96 | } | 127 | } |
97 | time_t OTimeZone::fromDateTime( const QDateTime& time ) { | 128 | time_t OTimeZone::fromDateTime( const QDateTime& time ) { |
98 | return to_Time_t( time, m_name ); | 129 | return to_Time_t( time, m_name ); |
99 | } | 130 | } |
100 | time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) { | 131 | time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) { |
101 | return to_Time_t( time, "UTC" ); | 132 | return to_Time_t( time, "UTC" ); |
102 | } | 133 | } |
103 | OTimeZone OTimeZone::current() { | 134 | OTimeZone OTimeZone::current() { |
104 | QCString str = ::getenv("TZ"); | 135 | QCString str = ::getenv("TZ"); |
105 | OTimeZone zone( str ); | 136 | OTimeZone zone( str ); |
106 | return zone; | 137 | return zone; |
107 | } | 138 | } |
108 | OTimeZone OTimeZone::utc() { | 139 | OTimeZone OTimeZone::utc() { |
109 | return OTimeZone("UTC"); | 140 | return OTimeZone("UTC"); |
110 | } | 141 | } |
111 | QString OTimeZone::timeZone()const { | 142 | QString OTimeZone::timeZone()const { |
112 | return m_name; | 143 | return m_name; |
113 | } | 144 | } |
145 | |||
146 | } | ||
diff --git a/libopie2/opiepim/core/otimezone.h b/libopie2/opiepim/core/otimezone.h index bb08349..28ae6cb 100644 --- a/libopie2/opiepim/core/otimezone.h +++ b/libopie2/opiepim/core/otimezone.h | |||
@@ -1,71 +1,102 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
1 | #ifndef OPIE_TIME_ZONE_H | 30 | #ifndef OPIE_TIME_ZONE_H |
2 | #define OPIE_TIME_ZONE_H | 31 | #define OPIE_TIME_ZONE_H |
3 | 32 | ||
4 | #include <time.h> | 33 | #include <time.h> |
5 | #include <qdatetime.h> | 34 | #include <qdatetime.h> |
6 | 35 | ||
36 | namespace Opie | ||
37 | { | ||
7 | /** | 38 | /** |
8 | * A very primitive class to convert time | 39 | * A very primitive class to convert time |
9 | * from one timezone to another | 40 | * from one timezone to another |
10 | * and to localtime | 41 | * and to localtime |
11 | * and time_t | 42 | * and time_t |
12 | */ | 43 | */ |
13 | class OTimeZone { | 44 | class OTimeZone { |
14 | public: | 45 | public: |
15 | typedef QString ZoneName; | 46 | typedef QString ZoneName; |
16 | OTimeZone( const ZoneName& = ZoneName::null ); | 47 | OTimeZone( const ZoneName& = ZoneName::null ); |
17 | virtual ~OTimeZone(); // just in case. | 48 | virtual ~OTimeZone(); // just in case. |
18 | 49 | ||
19 | bool isValid()const; | 50 | bool isValid()const; |
20 | 51 | ||
21 | /** | 52 | /** |
22 | * converts the QDateTime to a DateTime | 53 | * converts the QDateTime to a DateTime |
23 | * in the local timezone | 54 | * in the local timezone |
24 | * if QDateTime is 25th Jan and takes place in Europe/Berlin at 12h | 55 | * if QDateTime is 25th Jan and takes place in Europe/Berlin at 12h |
25 | * and the current timezone is Europe/London the returned | 56 | * and the current timezone is Europe/London the returned |
26 | * time will be 11h. | 57 | * time will be 11h. |
27 | */ | 58 | */ |
28 | QDateTime toLocalDateTime( const QDateTime& dt ); | 59 | QDateTime toLocalDateTime( const QDateTime& dt ); |
29 | 60 | ||
30 | /** | 61 | /** |
31 | * converts the QDateTime to UTC time | 62 | * converts the QDateTime to UTC time |
32 | */ | 63 | */ |
33 | QDateTime toUTCDateTime( const QDateTime& dt ); | 64 | QDateTime toUTCDateTime( const QDateTime& dt ); |
34 | 65 | ||
35 | /** | 66 | /** |
36 | * reads the time_t into a QDateTime using UTC as timezone! | 67 | * reads the time_t into a QDateTime using UTC as timezone! |
37 | */ | 68 | */ |
38 | QDateTime fromUTCDateTime( time_t ); | 69 | QDateTime fromUTCDateTime( time_t ); |
39 | 70 | ||
40 | /** | 71 | /** |
41 | * converts the time_t to the time in the timezone | 72 | * converts the time_t to the time in the timezone |
42 | */ | 73 | */ |
43 | QDateTime toDateTime( time_t ); | 74 | QDateTime toDateTime( time_t ); |
44 | 75 | ||
45 | /** | 76 | /** |
46 | * converts the QDateTime from one timezone to this timeZone | 77 | * converts the QDateTime from one timezone to this timeZone |
47 | */ | 78 | */ |
48 | QDateTime toDateTime( const QDateTime&, const OTimeZone& timeZone ); | 79 | QDateTime toDateTime( const QDateTime&, const OTimeZone& timeZone ); |
49 | 80 | ||
50 | /** | 81 | /** |
51 | * converts the date time into a time_t. It takes the timezone into account | 82 | * converts the date time into a time_t. It takes the timezone into account |
52 | */ | 83 | */ |
53 | time_t fromDateTime( const QDateTime& ); | 84 | time_t fromDateTime( const QDateTime& ); |
54 | 85 | ||
55 | /** | 86 | /** |
56 | * converts the datetime with timezone UTC | 87 | * converts the datetime with timezone UTC |
57 | */ | 88 | */ |
58 | time_t fromUTCDateTime( const QDateTime& ); | 89 | time_t fromUTCDateTime( const QDateTime& ); |
59 | 90 | ||
60 | static OTimeZone current(); | 91 | static OTimeZone current(); |
61 | static OTimeZone utc(); | 92 | static OTimeZone utc(); |
62 | 93 | ||
63 | QString timeZone()const; | 94 | QString timeZone()const; |
64 | private: | 95 | private: |
65 | ZoneName m_name; | 96 | ZoneName m_name; |
66 | class Private; | 97 | class Private; |
67 | Private* d; | 98 | Private* d; |
68 | }; | 99 | }; |
69 | 100 | }; | |
70 | 101 | ||
71 | #endif | 102 | #endif |
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 37f6fbc..2a3695d 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp | |||
@@ -1,62 +1,93 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
2 | 30 | ||
3 | #include <qpe/alarmserver.h> | 31 | #include <qpe/alarmserver.h> |
4 | 32 | ||
5 | // #include "otodoaccesssql.h" | 33 | // #include "otodoaccesssql.h" |
6 | #include "otodoaccess.h" | 34 | #include <opie2/otodoaccess.h> |
7 | #include "obackendfactory.h" | 35 | #include <opie2/obackendfactory.h> |
8 | 36 | ||
37 | namespace Opie { | ||
9 | OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access ) | 38 | OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access ) |
10 | : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) | 39 | : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) |
11 | { | 40 | { |
12 | // if (end == 0l ) | 41 | // if (end == 0l ) |
13 | // m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); | 42 | // m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); |
14 | 43 | ||
15 | // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben ! | 44 | // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! |
16 | if (end == 0l ) | 45 | if (end == 0l ) |
17 | m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); | 46 | m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); |
18 | 47 | ||
19 | setBackEnd( m_todoBackEnd ); | 48 | setBackEnd( m_todoBackEnd ); |
20 | } | 49 | } |
21 | OTodoAccess::~OTodoAccess() { | 50 | OTodoAccess::~OTodoAccess() { |
22 | // qWarning("~OTodoAccess"); | 51 | // qWarning("~OTodoAccess"); |
23 | } | 52 | } |
24 | void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { | 53 | void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { |
25 | QValueList<OTodo>::ConstIterator it; | 54 | QValueList<OTodo>::ConstIterator it; |
26 | for ( it = list.begin(); it != list.end(); ++it ) { | 55 | for ( it = list.begin(); it != list.end(); ++it ) { |
27 | replace( (*it) ); | 56 | replace( (*it) ); |
28 | } | 57 | } |
29 | } | 58 | } |
30 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, | 59 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, |
31 | const QDate& end, | 60 | const QDate& end, |
32 | bool includeNoDates ) { | 61 | bool includeNoDates ) { |
33 | QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); | 62 | QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); |
34 | 63 | ||
35 | List lis( ints, this ); | 64 | List lis( ints, this ); |
36 | return lis; | 65 | return lis; |
37 | } | 66 | } |
38 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, | 67 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, |
39 | bool includeNoDates ) { | 68 | bool includeNoDates ) { |
40 | return effectiveToDos( start, QDate::currentDate(), | 69 | return effectiveToDos( start, QDate::currentDate(), |
41 | includeNoDates ); | 70 | includeNoDates ); |
42 | } | 71 | } |
43 | OTodoAccess::List OTodoAccess::overDue() { | 72 | OTodoAccess::List OTodoAccess::overDue() { |
44 | List lis( m_todoBackEnd->overDue(), this ); | 73 | List lis( m_todoBackEnd->overDue(), this ); |
45 | return lis; | 74 | return lis; |
46 | } | 75 | } |
47 | /* sort order */ | 76 | /* sort order */ |
48 | OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { | 77 | OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { |
49 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, | 78 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, |
50 | filter, cat ); | 79 | filter, cat ); |
51 | OTodoAccess::List list( ints, this ); | 80 | OTodoAccess::List list( ints, this ); |
52 | return list; | 81 | return list; |
53 | } | 82 | } |
54 | void OTodoAccess::removeAllCompleted() { | 83 | void OTodoAccess::removeAllCompleted() { |
55 | m_todoBackEnd->removeAllCompleted(); | 84 | m_todoBackEnd->removeAllCompleted(); |
56 | } | 85 | } |
57 | QBitArray OTodoAccess::backendSupport( const QString& ) const{ | 86 | QBitArray OTodoAccess::backendSupport( const QString& ) const{ |
58 | return m_todoBackEnd->supports(); | 87 | return m_todoBackEnd->supports(); |
59 | } | 88 | } |
60 | bool OTodoAccess::backendSupports( int attr, const QString& ar) const{ | 89 | bool OTodoAccess::backendSupports( int attr, const QString& ar) const{ |
61 | return backendSupport(ar).testBit( attr ); | 90 | return backendSupport(ar).testBit( attr ); |
62 | } | 91 | } |
92 | |||
93 | } | ||
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index 916923f..e13d277 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h | |||
@@ -1,105 +1,136 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_TODO_ACCESS_H | 29 | #ifndef OPIE_TODO_ACCESS_H |
2 | #define OPIE_TODO_ACCESS_H | 30 | #define OPIE_TODO_ACCESS_H |
3 | 31 | ||
4 | #include <qobject.h> | 32 | #include <qobject.h> |
5 | #include <qvaluelist.h> | 33 | #include <qvaluelist.h> |
6 | 34 | ||
7 | #include "otodo.h" | 35 | #include <opie2/otodo.h> |
8 | #include "otodoaccessbackend.h" | 36 | #include <opie2/otodoaccessbackend.h> |
9 | #include "opimaccesstemplate.h" | 37 | #include <opie2/opimaccesstemplate.h> |
10 | 38 | ||
39 | namespace Opie { | ||
11 | 40 | ||
12 | /** | 41 | /** |
13 | * OTodoAccess | 42 | * OTodoAccess |
14 | * the class to get access to | 43 | * the class to get access to |
15 | * the todolist | 44 | * the todolist |
16 | */ | 45 | */ |
17 | class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { | 46 | class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { |
18 | Q_OBJECT | 47 | Q_OBJECT |
19 | public: | 48 | public: |
20 | enum SortOrder { Completed = 0, | 49 | enum SortOrder { Completed = 0, |
21 | Priority, | 50 | Priority, |
22 | Description, | 51 | Description, |
23 | Deadline }; | 52 | Deadline }; |
24 | enum SortFilter{ Category =1, | 53 | enum SortFilter{ Category =1, |
25 | OnlyOverDue= 2, | 54 | OnlyOverDue= 2, |
26 | DoNotShowCompleted =4 }; | 55 | DoNotShowCompleted =4 }; |
27 | /** | 56 | /** |
28 | * if you use 0l | 57 | * if you use 0l |
29 | * the default resource will be | 58 | * the default resource will be |
30 | * picked up | 59 | * picked up |
31 | */ | 60 | */ |
32 | OTodoAccess( OTodoAccessBackend* = 0l, enum Access acc = Random ); | 61 | OTodoAccess( OTodoAccessBackend* = 0l, enum Access acc = Random ); |
33 | ~OTodoAccess(); | 62 | ~OTodoAccess(); |
34 | 63 | ||
35 | 64 | ||
36 | /* our functions here */ | 65 | /* our functions here */ |
37 | /** | 66 | /** |
38 | * include todos from start to end | 67 | * include todos from start to end |
39 | * includeNoDates whether or not to include | 68 | * includeNoDates whether or not to include |
40 | * events with no dates | 69 | * events with no dates |
41 | */ | 70 | */ |
42 | List effectiveToDos( const QDate& start, | 71 | List effectiveToDos( const QDate& start, |
43 | const QDate& end, | 72 | const QDate& end, |
44 | bool includeNoDates = true ); | 73 | bool includeNoDates = true ); |
45 | 74 | ||
46 | /** | 75 | /** |
47 | * start | 76 | * start |
48 | * end date taken from the currentDate() | 77 | * end date taken from the currentDate() |
49 | */ | 78 | */ |
50 | List effectiveToDos( const QDate& start, | 79 | List effectiveToDos( const QDate& start, |
51 | bool includeNoDates = true ); | 80 | bool includeNoDates = true ); |
52 | 81 | ||
53 | 82 | ||
54 | /** | 83 | /** |
55 | * return overdue OTodos | 84 | * return overdue OTodos |
56 | */ | 85 | */ |
57 | List overDue(); | 86 | List overDue(); |
58 | 87 | ||
59 | /** | 88 | /** |
60 | * | 89 | * |
61 | */ | 90 | */ |
62 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 91 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
63 | 92 | ||
64 | /** | 93 | /** |
65 | * merge a list of OTodos into | 94 | * merge a list of OTodos into |
66 | * the resource | 95 | * the resource |
67 | */ | 96 | */ |
68 | void mergeWith( const QValueList<OTodo>& ); | 97 | void mergeWith( const QValueList<OTodo>& ); |
69 | 98 | ||
70 | /** | 99 | /** |
71 | * delete all already completed items | 100 | * delete all already completed items |
72 | */ | 101 | */ |
73 | void removeAllCompleted(); | 102 | void removeAllCompleted(); |
74 | 103 | ||
75 | /** | 104 | /** |
76 | * request information about what a backend supports. | 105 | * request information about what a backend supports. |
77 | * Supports in the sense of beeing able to store. | 106 | * Supports in the sense of beeing able to store. |
78 | * This is related to the enum in OTodo | 107 | * This is related to the enum in OTodo |
79 | * | 108 | * |
80 | * @param backend Will be used in the future when we support multiple backend | 109 | * @param backend Will be used in the future when we support multiple backend |
81 | */ | 110 | */ |
82 | QBitArray backendSupport( const QString& backend = QString::null )const; | 111 | QBitArray backendSupport( const QString& backend = QString::null )const; |
83 | 112 | ||
84 | /** | 113 | /** |
85 | * see above but for a specefic attribute. This method was added for convience | 114 | * see above but for a specefic attribute. This method was added for convience |
86 | * @param attr The attribute to be queried for | 115 | * @param attr The attribute to be queried for |
87 | * @param backend Will be used in the future when we support multiple backends | 116 | * @param backend Will be used in the future when we support multiple backends |
88 | */ | 117 | */ |
89 | bool backendSupports( int attr, const QString& backend = QString::null )const; | 118 | bool backendSupports( int attr, const QString& backend = QString::null )const; |
90 | signals: | 119 | signals: |
91 | /** | 120 | /** |
92 | * if the OTodoAccess was changed | 121 | * if the OTodoAccess was changed |
93 | */ | 122 | */ |
94 | void changed( const OTodoAccess* ); | 123 | void changed( const OTodoAccess* ); |
95 | void changed( const OTodoAccess*, int uid ); | 124 | void changed( const OTodoAccess*, int uid ); |
96 | void added( const OTodoAccess*, int uid ); | 125 | void added( const OTodoAccess*, int uid ); |
97 | void removed( const OTodoAccess*, int uid ); | 126 | void removed( const OTodoAccess*, int uid ); |
98 | private: | 127 | private: |
99 | int m_cat; | 128 | int m_cat; |
100 | OTodoAccessBackend* m_todoBackEnd; | 129 | OTodoAccessBackend* m_todoBackEnd; |
101 | class OTodoAccessPrivate; | 130 | class OTodoAccessPrivate; |
102 | OTodoAccessPrivate* d; | 131 | OTodoAccessPrivate* d; |
103 | }; | 132 | }; |
104 | 133 | ||
134 | } | ||
135 | |||
105 | #endif | 136 | #endif |
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index fcf3b26..f1a22a7 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp | |||
@@ -1,241 +1,271 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
29 | |||
1 | /********************************************************************** | 30 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 31 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 32 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 33 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 34 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 35 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 36 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 37 | ** packaging of this file. |
9 | ** | 38 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 39 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 40 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 41 | ** |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 42 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
14 | ** | 43 | ** |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 44 | ** Contact info@trolltech.com if any conditions of this licensing are |
16 | ** not clear to you. | 45 | ** not clear to you. |
17 | ** | 46 | ** |
18 | **********************************************************************/ | 47 | **********************************************************************/ |
19 | 48 | ||
20 | #define QTOPIA_INTERNAL_CONTACT_MRE | 49 | #define QTOPIA_INTERNAL_CONTACT_MRE |
21 | 50 | ||
22 | #include "ocontact.h" | 51 | #include <opie2/ocontact.h> |
23 | #include "opimresolver.h" | 52 | #include <opie2/opimresolver.h> |
24 | #include "oconversion.h" | 53 | #include <opie2/oconversion.h> |
25 | 54 | ||
26 | #include <qpe/stringutil.h> | 55 | #include <qpe/stringutil.h> |
27 | #include <qpe/timestring.h> | 56 | #include <qpe/timestring.h> |
28 | #include <qpe/config.h> | 57 | #include <qpe/config.h> |
29 | 58 | ||
30 | #include <qobject.h> | 59 | #include <qobject.h> |
31 | #include <qregexp.h> | 60 | #include <qregexp.h> |
32 | #include <qstylesheet.h> | 61 | #include <qstylesheet.h> |
33 | #include <qfileinfo.h> | 62 | #include <qfileinfo.h> |
34 | #include <qmap.h> | 63 | #include <qmap.h> |
35 | 64 | ||
36 | #include <stdio.h> | 65 | #include <stdio.h> |
37 | 66 | ||
38 | /*! | 67 | /*! |
39 | \class Contact contact.h | 68 | \class Contact contact.h |
40 | \brief The Contact class holds the data of an address book entry. | 69 | \brief The Contact class holds the data of an address book entry. |
41 | 70 | ||
42 | This data includes information the name of the person, contact | 71 | This data includes information the name of the person, contact |
43 | information, and business information such as deparment and job title. | 72 | information, and business information such as deparment and job title. |
44 | 73 | ||
45 | \ingroup qtopiaemb | 74 | \ingroup qtopiaemb |
46 | \ingroup qtopiadesktop | 75 | \ingroup qtopiadesktop |
47 | */ | 76 | */ |
48 | 77 | ||
49 | 78 | ||
79 | namespace Opie { | ||
50 | /*! | 80 | /*! |
51 | Creates a new, empty contact. | 81 | Creates a new, empty contact. |
52 | */ | 82 | */ |
53 | OContact::OContact() | 83 | OContact::OContact() |
54 | : OPimRecord(), mMap(), d( 0 ) | 84 | : OPimRecord(), mMap(), d( 0 ) |
55 | { | 85 | { |
56 | } | 86 | } |
57 | 87 | ||
58 | /*! | 88 | /*! |
59 | \internal | 89 | \internal |
60 | Creates a new contact. The properties of the contact are | 90 | Creates a new contact. The properties of the contact are |
61 | set from \a fromMap. | 91 | set from \a fromMap. |
62 | */ | 92 | */ |
63 | OContact::OContact( const QMap<int, QString> &fromMap ) : | 93 | OContact::OContact( const QMap<int, QString> &fromMap ) : |
64 | OPimRecord(), mMap( fromMap ), d( 0 ) | 94 | OPimRecord(), mMap( fromMap ), d( 0 ) |
65 | { | 95 | { |
66 | QString cats = mMap[ Qtopia::AddressCategory ]; | 96 | QString cats = mMap[ Qtopia::AddressCategory ]; |
67 | if ( !cats.isEmpty() ) | 97 | if ( !cats.isEmpty() ) |
68 | setCategories( idsFromString( cats ) ); | 98 | setCategories( idsFromString( cats ) ); |
69 | 99 | ||
70 | QString uidStr = find( Qtopia::AddressUid ); | 100 | QString uidStr = find( Qtopia::AddressUid ); |
71 | 101 | ||
72 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ | 102 | if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ |
73 | qWarning( "Invalid UID found. Generate new one.." ); | 103 | qWarning( "Invalid UID found. Generate new one.." ); |
74 | setUid( uidGen().generate() ); | 104 | setUid( uidGen().generate() ); |
75 | }else | 105 | }else |
76 | setUid( uidStr.toInt() ); | 106 | setUid( uidStr.toInt() ); |
77 | 107 | ||
78 | // if ( !uidStr.isEmpty() ) | 108 | // if ( !uidStr.isEmpty() ) |
79 | // setUid( uidStr.toInt() ); | 109 | // setUid( uidStr.toInt() ); |
80 | } | 110 | } |
81 | 111 | ||
82 | /*! | 112 | /*! |
83 | Destroys a contact. | 113 | Destroys a contact. |
84 | */ | 114 | */ |
85 | OContact::~OContact() | 115 | OContact::~OContact() |
86 | { | 116 | { |
87 | } | 117 | } |
88 | 118 | ||
89 | /*! \fn void OContact::setTitle( const QString &str ) | 119 | /*! \fn void OContact::setTitle( const QString &str ) |
90 | Sets the title of the contact to \a str. | 120 | Sets the title of the contact to \a str. |
91 | */ | 121 | */ |
92 | 122 | ||
93 | /*! \fn void OContact::setFirstName( const QString &str ) | 123 | /*! \fn void OContact::setFirstName( const QString &str ) |
94 | Sets the first name of the contact to \a str. | 124 | Sets the first name of the contact to \a str. |
95 | */ | 125 | */ |
96 | 126 | ||
97 | /*! \fn void OContact::setMiddleName( const QString &str ) | 127 | /*! \fn void OContact::setMiddleName( const QString &str ) |
98 | Sets the middle name of the contact to \a str. | 128 | Sets the middle name of the contact to \a str. |
99 | */ | 129 | */ |
100 | 130 | ||
101 | /*! \fn void OContact::setLastName( const QString &str ) | 131 | /*! \fn void OContact::setLastName( const QString &str ) |
102 | Sets the last name of the contact to \a str. | 132 | Sets the last name of the contact to \a str. |
103 | */ | 133 | */ |
104 | 134 | ||
105 | /*! \fn void OContact::setSuffix( const QString &str ) | 135 | /*! \fn void OContact::setSuffix( const QString &str ) |
106 | Sets the suffix of the contact to \a str. | 136 | Sets the suffix of the contact to \a str. |
107 | */ | 137 | */ |
108 | 138 | ||
109 | /*! \fn void OContact::setFileAs( const QString &str ) | 139 | /*! \fn void OContact::setFileAs( const QString &str ) |
110 | Sets the contact to filed as \a str. | 140 | Sets the contact to filed as \a str. |
111 | */ | 141 | */ |
112 | 142 | ||
113 | /*! \fn void OContact::setDefaultEmail( const QString &str ) | 143 | /*! \fn void OContact::setDefaultEmail( const QString &str ) |
114 | Sets the default email of the contact to \a str. | 144 | Sets the default email of the contact to \a str. |
115 | */ | 145 | */ |
116 | 146 | ||
117 | /*! \fn void OContact::setHomeStreet( const QString &str ) | 147 | /*! \fn void OContact::setHomeStreet( const QString &str ) |
118 | Sets the home street address of the contact to \a str. | 148 | Sets the home street address of the contact to \a str. |
119 | */ | 149 | */ |
120 | 150 | ||
121 | /*! \fn void OContact::setHomeCity( const QString &str ) | 151 | /*! \fn void OContact::setHomeCity( const QString &str ) |
122 | Sets the home city of the contact to \a str. | 152 | Sets the home city of the contact to \a str. |
123 | */ | 153 | */ |
124 | 154 | ||
125 | /*! \fn void OContact::setHomeState( const QString &str ) | 155 | /*! \fn void OContact::setHomeState( const QString &str ) |
126 | Sets the home state of the contact to \a str. | 156 | Sets the home state of the contact to \a str. |
127 | */ | 157 | */ |
128 | 158 | ||
129 | /*! \fn void OContact::setHomeZip( const QString &str ) | 159 | /*! \fn void OContact::setHomeZip( const QString &str ) |
130 | Sets the home zip code of the contact to \a str. | 160 | Sets the home zip code of the contact to \a str. |
131 | */ | 161 | */ |
132 | 162 | ||
133 | /*! \fn void OContact::setHomeCountry( const QString &str ) | 163 | /*! \fn void OContact::setHomeCountry( const QString &str ) |
134 | Sets the home country of the contact to \a str. | 164 | Sets the home country of the contact to \a str. |
135 | */ | 165 | */ |
136 | 166 | ||
137 | /*! \fn void OContact::setHomePhone( const QString &str ) | 167 | /*! \fn void OContact::setHomePhone( const QString &str ) |
138 | Sets the home phone number of the contact to \a str. | 168 | Sets the home phone number of the contact to \a str. |
139 | */ | 169 | */ |
140 | 170 | ||
141 | /*! \fn void OContact::setHomeFax( const QString &str ) | 171 | /*! \fn void OContact::setHomeFax( const QString &str ) |
142 | Sets the home fax number of the contact to \a str. | 172 | Sets the home fax number of the contact to \a str. |
143 | */ | 173 | */ |
144 | 174 | ||
145 | /*! \fn void OContact::setHomeMobile( const QString &str ) | 175 | /*! \fn void OContact::setHomeMobile( const QString &str ) |
146 | Sets the home mobile phone number of the contact to \a str. | 176 | Sets the home mobile phone number of the contact to \a str. |
147 | */ | 177 | */ |
148 | 178 | ||
149 | /*! \fn void OContact::setHomeWebpage( const QString &str ) | 179 | /*! \fn void OContact::setHomeWebpage( const QString &str ) |
150 | Sets the home webpage of the contact to \a str. | 180 | Sets the home webpage of the contact to \a str. |
151 | */ | 181 | */ |
152 | 182 | ||
153 | /*! \fn void OContact::setCompany( const QString &str ) | 183 | /*! \fn void OContact::setCompany( const QString &str ) |
154 | Sets the company for contact to \a str. | 184 | Sets the company for contact to \a str. |
155 | */ | 185 | */ |
156 | 186 | ||
157 | /*! \fn void OContact::setJobTitle( const QString &str ) | 187 | /*! \fn void OContact::setJobTitle( const QString &str ) |
158 | Sets the job title of the contact to \a str. | 188 | Sets the job title of the contact to \a str. |
159 | */ | 189 | */ |
160 | 190 | ||
161 | /*! \fn void OContact::setDepartment( const QString &str ) | 191 | /*! \fn void OContact::setDepartment( const QString &str ) |
162 | Sets the department for contact to \a str. | 192 | Sets the department for contact to \a str. |
163 | */ | 193 | */ |
164 | 194 | ||
165 | /*! \fn void OContact::setOffice( const QString &str ) | 195 | /*! \fn void OContact::setOffice( const QString &str ) |
166 | Sets the office for contact to \a str. | 196 | Sets the office for contact to \a str. |
167 | */ | 197 | */ |
168 | 198 | ||
169 | /*! \fn void OContact::setBusinessStreet( const QString &str ) | 199 | /*! \fn void OContact::setBusinessStreet( const QString &str ) |
170 | Sets the business street address of the contact to \a str. | 200 | Sets the business street address of the contact to \a str. |
171 | */ | 201 | */ |
172 | 202 | ||
173 | /*! \fn void OContact::setBusinessCity( const QString &str ) | 203 | /*! \fn void OContact::setBusinessCity( const QString &str ) |
174 | Sets the business city of the contact to \a str. | 204 | Sets the business city of the contact to \a str. |
175 | */ | 205 | */ |
176 | 206 | ||
177 | /*! \fn void OContact::setBusinessState( const QString &str ) | 207 | /*! \fn void OContact::setBusinessState( const QString &str ) |
178 | Sets the business state of the contact to \a str. | 208 | Sets the business state of the contact to \a str. |
179 | */ | 209 | */ |
180 | 210 | ||
181 | /*! \fn void OContact::setBusinessZip( const QString &str ) | 211 | /*! \fn void OContact::setBusinessZip( const QString &str ) |
182 | Sets the business zip code of the contact to \a str. | 212 | Sets the business zip code of the contact to \a str. |
183 | */ | 213 | */ |
184 | 214 | ||
185 | /*! \fn void OContact::setBusinessCountry( const QString &str ) | 215 | /*! \fn void OContact::setBusinessCountry( const QString &str ) |
186 | Sets the business country of the contact to \a str. | 216 | Sets the business country of the contact to \a str. |
187 | */ | 217 | */ |
188 | 218 | ||
189 | /*! \fn void OContact::setBusinessPhone( const QString &str ) | 219 | /*! \fn void OContact::setBusinessPhone( const QString &str ) |
190 | Sets the business phone number of the contact to \a str. | 220 | Sets the business phone number of the contact to \a str. |
191 | */ | 221 | */ |
192 | 222 | ||
193 | /*! \fn void OContact::setBusinessFax( const QString &str ) | 223 | /*! \fn void OContact::setBusinessFax( const QString &str ) |
194 | Sets the business fax number of the contact to \a str. | 224 | Sets the business fax number of the contact to \a str. |
195 | */ | 225 | */ |
196 | 226 | ||
197 | /*! \fn void OContact::setBusinessMobile( const QString &str ) | 227 | /*! \fn void OContact::setBusinessMobile( const QString &str ) |
198 | Sets the business mobile phone number of the contact to \a str. | 228 | Sets the business mobile phone number of the contact to \a str. |
199 | */ | 229 | */ |
200 | 230 | ||
201 | /*! \fn void OContact::setBusinessPager( const QString &str ) | 231 | /*! \fn void OContact::setBusinessPager( const QString &str ) |
202 | Sets the business pager number of the contact to \a str. | 232 | Sets the business pager number of the contact to \a str. |
203 | */ | 233 | */ |
204 | 234 | ||
205 | /*! \fn void OContact::setBusinessWebpage( const QString &str ) | 235 | /*! \fn void OContact::setBusinessWebpage( const QString &str ) |
206 | Sets the business webpage of the contact to \a str. | 236 | Sets the business webpage of the contact to \a str. |
207 | */ | 237 | */ |
208 | 238 | ||
209 | /*! \fn void OContact::setProfession( const QString &str ) | 239 | /*! \fn void OContact::setProfession( const QString &str ) |
210 | Sets the profession of the contact to \a str. | 240 | Sets the profession of the contact to \a str. |
211 | */ | 241 | */ |
212 | 242 | ||
213 | /*! \fn void OContact::setAssistant( const QString &str ) | 243 | /*! \fn void OContact::setAssistant( const QString &str ) |
214 | Sets the assistant of the contact to \a str. | 244 | Sets the assistant of the contact to \a str. |
215 | */ | 245 | */ |
216 | 246 | ||
217 | /*! \fn void OContact::setManager( const QString &str ) | 247 | /*! \fn void OContact::setManager( const QString &str ) |
218 | Sets the manager of the contact to \a str. | 248 | Sets the manager of the contact to \a str. |
219 | */ | 249 | */ |
220 | 250 | ||
221 | /*! \fn void OContact::setSpouse( const QString &str ) | 251 | /*! \fn void OContact::setSpouse( const QString &str ) |
222 | Sets the spouse of the contact to \a str. | 252 | Sets the spouse of the contact to \a str. |
223 | */ | 253 | */ |
224 | 254 | ||
225 | /*! \fn void OContact::setGender( const QString &str ) | 255 | /*! \fn void OContact::setGender( const QString &str ) |
226 | Sets the gender of the contact to \a str. | 256 | Sets the gender of the contact to \a str. |
227 | */ | 257 | */ |
228 | 258 | ||
229 | /*! \fn void OContact::setNickname( const QString &str ) | 259 | /*! \fn void OContact::setNickname( const QString &str ) |
230 | Sets the nickname of the contact to \a str. | 260 | Sets the nickname of the contact to \a str. |
231 | */ | 261 | */ |
232 | 262 | ||
233 | /*! \fn void OContact::setNotes( const QString &str ) | 263 | /*! \fn void OContact::setNotes( const QString &str ) |
234 | Sets the notes about the contact to \a str. | 264 | Sets the notes about the contact to \a str. |
235 | */ | 265 | */ |
236 | 266 | ||
237 | /*! \fn QString OContact::title() const | 267 | /*! \fn QString OContact::title() const |
238 | Returns the title of the contact. | 268 | Returns the title of the contact. |
239 | */ | 269 | */ |
240 | 270 | ||
241 | /*! \fn QString OContact::firstName() const | 271 | /*! \fn QString OContact::firstName() const |
@@ -1016,192 +1046,193 @@ void OContact::setEmails( const QString &str ) | |||
1016 | Sets the list of children for the contact to those contained in \a str. | 1046 | Sets the list of children for the contact to those contained in \a str. |
1017 | */ | 1047 | */ |
1018 | void OContact::setChildren( const QString &str ) | 1048 | void OContact::setChildren( const QString &str ) |
1019 | { | 1049 | { |
1020 | replace( Qtopia::Children, str ); | 1050 | replace( Qtopia::Children, str ); |
1021 | } | 1051 | } |
1022 | 1052 | ||
1023 | /*! | 1053 | /*! |
1024 | \overload | 1054 | \overload |
1025 | Returns TRUE if the contact matches the regular expression \a regexp. | 1055 | Returns TRUE if the contact matches the regular expression \a regexp. |
1026 | Otherwise returns FALSE. | 1056 | Otherwise returns FALSE. |
1027 | */ | 1057 | */ |
1028 | bool OContact::match( const QRegExp &r ) const | 1058 | bool OContact::match( const QRegExp &r ) const |
1029 | { | 1059 | { |
1030 | setLastHitField( -1 ); | 1060 | setLastHitField( -1 ); |
1031 | bool match; | 1061 | bool match; |
1032 | match = false; | 1062 | match = false; |
1033 | QMap<int, QString>::ConstIterator it; | 1063 | QMap<int, QString>::ConstIterator it; |
1034 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { | 1064 | for ( it = mMap.begin(); it != mMap.end(); ++it ) { |
1035 | if ( (*it).find( r ) > -1 ) { | 1065 | if ( (*it).find( r ) > -1 ) { |
1036 | setLastHitField( it.key() ); | 1066 | setLastHitField( it.key() ); |
1037 | match = true; | 1067 | match = true; |
1038 | break; | 1068 | break; |
1039 | } | 1069 | } |
1040 | } | 1070 | } |
1041 | return match; | 1071 | return match; |
1042 | } | 1072 | } |
1043 | 1073 | ||
1044 | 1074 | ||
1045 | QString OContact::toShortText() const | 1075 | QString OContact::toShortText() const |
1046 | { | 1076 | { |
1047 | return ( fullName() ); | 1077 | return ( fullName() ); |
1048 | } | 1078 | } |
1049 | QString OContact::type() const | 1079 | QString OContact::type() const |
1050 | { | 1080 | { |
1051 | return QString::fromLatin1( "OContact" ); | 1081 | return QString::fromLatin1( "OContact" ); |
1052 | } | 1082 | } |
1053 | 1083 | ||
1054 | 1084 | ||
1055 | 1085 | ||
1056 | class QString OContact::recordField( int pos ) const | 1086 | class QString OContact::recordField( int pos ) const |
1057 | { | 1087 | { |
1058 | QStringList SLFIELDS = fields(); // ?? why this ? (se) | 1088 | QStringList SLFIELDS = fields(); // ?? why this ? (se) |
1059 | return SLFIELDS[pos]; | 1089 | return SLFIELDS[pos]; |
1060 | } | 1090 | } |
1061 | 1091 | ||
1062 | // In future releases, we should store birthday and anniversary | 1092 | // In future releases, we should store birthday and anniversary |
1063 | // internally as QDate instead of QString ! | 1093 | // internally as QDate instead of QString ! |
1064 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) | 1094 | // QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) |
1065 | 1095 | ||
1066 | /*! \fn void OContact::setBirthday( const QDate& date ) | 1096 | /*! \fn void OContact::setBirthday( const QDate& date ) |
1067 | Sets the birthday for the contact to \a date. If date is null | 1097 | Sets the birthday for the contact to \a date. If date is null |
1068 | the current stored date will be removed. | 1098 | the current stored date will be removed. |
1069 | */ | 1099 | */ |
1070 | void OContact::setBirthday( const QDate &v ) | 1100 | void OContact::setBirthday( const QDate &v ) |
1071 | { | 1101 | { |
1072 | if ( v.isNull() ){ | 1102 | if ( v.isNull() ){ |
1073 | qWarning( "Remove Birthday"); | 1103 | qWarning( "Remove Birthday"); |
1074 | replace( Qtopia::Birthday, QString::null ); | 1104 | replace( Qtopia::Birthday, QString::null ); |
1075 | return; | 1105 | return; |
1076 | } | 1106 | } |
1077 | 1107 | ||
1078 | if ( v.isValid() ) | 1108 | if ( v.isValid() ) |
1079 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); | 1109 | replace( Qtopia::Birthday, OConversion::dateToString( v ) ); |
1080 | 1110 | ||
1081 | } | 1111 | } |
1082 | 1112 | ||
1083 | 1113 | ||
1084 | /*! \fn void OContact::setAnniversary( const QDate &date ) | 1114 | /*! \fn void OContact::setAnniversary( const QDate &date ) |
1085 | Sets the anniversary of the contact to \a date. If date is | 1115 | Sets the anniversary of the contact to \a date. If date is |
1086 | null, the current stored date will be removed. | 1116 | null, the current stored date will be removed. |
1087 | */ | 1117 | */ |
1088 | void OContact::setAnniversary( const QDate &v ) | 1118 | void OContact::setAnniversary( const QDate &v ) |
1089 | { | 1119 | { |
1090 | if ( v.isNull() ){ | 1120 | if ( v.isNull() ){ |
1091 | qWarning( "Remove Anniversary"); | 1121 | qWarning( "Remove Anniversary"); |
1092 | replace( Qtopia::Anniversary, QString::null ); | 1122 | replace( Qtopia::Anniversary, QString::null ); |
1093 | return; | 1123 | return; |
1094 | } | 1124 | } |
1095 | 1125 | ||
1096 | if ( v.isValid() ) | 1126 | if ( v.isValid() ) |
1097 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); | 1127 | replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); |
1098 | } | 1128 | } |
1099 | 1129 | ||
1100 | /*! \fn QDate OContact::birthday() const | 1130 | /*! \fn QDate OContact::birthday() const |
1101 | Returns the birthday of the contact. | 1131 | Returns the birthday of the contact. |
1102 | */ | 1132 | */ |
1103 | QDate OContact::birthday() const | 1133 | QDate OContact::birthday() const |
1104 | { | 1134 | { |
1105 | QString str = find( Qtopia::Birthday ); | 1135 | QString str = find( Qtopia::Birthday ); |
1106 | // qWarning ("Birthday %s", str.latin1() ); | 1136 | // qWarning ("Birthday %s", str.latin1() ); |
1107 | if ( !str.isEmpty() ) | 1137 | if ( !str.isEmpty() ) |
1108 | return OConversion::dateFromString ( str ); | 1138 | return OConversion::dateFromString ( str ); |
1109 | else | 1139 | else |
1110 | return QDate(); | 1140 | return QDate(); |
1111 | } | 1141 | } |
1112 | 1142 | ||
1113 | 1143 | ||
1114 | /*! \fn QDate OContact::anniversary() const | 1144 | /*! \fn QDate OContact::anniversary() const |
1115 | Returns the anniversary of the contact. | 1145 | Returns the anniversary of the contact. |
1116 | */ | 1146 | */ |
1117 | QDate OContact::anniversary() const | 1147 | QDate OContact::anniversary() const |
1118 | { | 1148 | { |
1119 | QDate empty; | 1149 | QDate empty; |
1120 | QString str = find( Qtopia::Anniversary ); | 1150 | QString str = find( Qtopia::Anniversary ); |
1121 | // qWarning ("Anniversary %s", str.latin1() ); | 1151 | // qWarning ("Anniversary %s", str.latin1() ); |
1122 | if ( !str.isEmpty() ) | 1152 | if ( !str.isEmpty() ) |
1123 | return OConversion::dateFromString ( str ); | 1153 | return OConversion::dateFromString ( str ); |
1124 | else | 1154 | else |
1125 | return empty; | 1155 | return empty; |
1126 | } | 1156 | } |
1127 | 1157 | ||
1128 | 1158 | ||
1129 | void OContact::insertEmail( const QString &v ) | 1159 | void OContact::insertEmail( const QString &v ) |
1130 | { | 1160 | { |
1131 | //qDebug("insertEmail %s", v.latin1()); | 1161 | //qDebug("insertEmail %s", v.latin1()); |
1132 | QString e = v.simplifyWhiteSpace(); | 1162 | QString e = v.simplifyWhiteSpace(); |
1133 | QString def = defaultEmail(); | 1163 | QString def = defaultEmail(); |
1134 | 1164 | ||
1135 | // if no default, set it as the default email and don't insert | 1165 | // if no default, set it as the default email and don't insert |
1136 | if ( def.isEmpty() ) { | 1166 | if ( def.isEmpty() ) { |
1137 | setDefaultEmail( e ); // will insert into the list for us | 1167 | setDefaultEmail( e ); // will insert into the list for us |
1138 | return; | 1168 | return; |
1139 | } | 1169 | } |
1140 | 1170 | ||
1141 | // otherwise, insert assuming doesn't already exist | 1171 | // otherwise, insert assuming doesn't already exist |
1142 | QString emailsStr = find( Qtopia::Emails ); | 1172 | QString emailsStr = find( Qtopia::Emails ); |
1143 | if ( emailsStr.contains( e )) | 1173 | if ( emailsStr.contains( e )) |
1144 | return; | 1174 | return; |
1145 | if ( !emailsStr.isEmpty() ) | 1175 | if ( !emailsStr.isEmpty() ) |
1146 | emailsStr += emailSeparator(); | 1176 | emailsStr += emailSeparator(); |
1147 | emailsStr += e; | 1177 | emailsStr += e; |
1148 | replace( Qtopia::Emails, emailsStr ); | 1178 | replace( Qtopia::Emails, emailsStr ); |
1149 | } | 1179 | } |
1150 | 1180 | ||
1151 | void OContact::removeEmail( const QString &v ) | 1181 | void OContact::removeEmail( const QString &v ) |
1152 | { | 1182 | { |
1153 | QString e = v.simplifyWhiteSpace(); | 1183 | QString e = v.simplifyWhiteSpace(); |
1154 | QString def = defaultEmail(); | 1184 | QString def = defaultEmail(); |
1155 | QString emailsStr = find( Qtopia::Emails ); | 1185 | QString emailsStr = find( Qtopia::Emails ); |
1156 | QStringList emails = emailList(); | 1186 | QStringList emails = emailList(); |
1157 | 1187 | ||
1158 | // otherwise, must first contain it | 1188 | // otherwise, must first contain it |
1159 | if ( !emailsStr.contains( e ) ) | 1189 | if ( !emailsStr.contains( e ) ) |
1160 | return; | 1190 | return; |
1161 | 1191 | ||
1162 | // remove it | 1192 | // remove it |
1163 | //qDebug(" removing email from list %s", e.latin1()); | 1193 | //qDebug(" removing email from list %s", e.latin1()); |
1164 | emails.remove( e ); | 1194 | emails.remove( e ); |
1165 | // reset the string | 1195 | // reset the string |
1166 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator | 1196 | emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator |
1167 | replace( Qtopia::Emails, emailsStr ); | 1197 | replace( Qtopia::Emails, emailsStr ); |
1168 | 1198 | ||
1169 | // if default, then replace the default email with the first one | 1199 | // if default, then replace the default email with the first one |
1170 | if ( def == e ) { | 1200 | if ( def == e ) { |
1171 | //qDebug("removeEmail is default; setting new default"); | 1201 | //qDebug("removeEmail is default; setting new default"); |
1172 | if ( !emails.count() ) | 1202 | if ( !emails.count() ) |
1173 | clearEmails(); | 1203 | clearEmails(); |
1174 | else // setDefaultEmail will remove e from the list | 1204 | else // setDefaultEmail will remove e from the list |
1175 | setDefaultEmail( emails.first() ); | 1205 | setDefaultEmail( emails.first() ); |
1176 | } | 1206 | } |
1177 | } | 1207 | } |
1178 | void OContact::clearEmails() | 1208 | void OContact::clearEmails() |
1179 | { | 1209 | { |
1180 | mMap.remove( Qtopia::DefaultEmail ); | 1210 | mMap.remove( Qtopia::DefaultEmail ); |
1181 | mMap.remove( Qtopia::Emails ); | 1211 | mMap.remove( Qtopia::Emails ); |
1182 | } | 1212 | } |
1183 | void OContact::setDefaultEmail( const QString &v ) | 1213 | void OContact::setDefaultEmail( const QString &v ) |
1184 | { | 1214 | { |
1185 | QString e = v.simplifyWhiteSpace(); | 1215 | QString e = v.simplifyWhiteSpace(); |
1186 | 1216 | ||
1187 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); | 1217 | //qDebug("OContact::setDefaultEmail %s", e.latin1()); |
1188 | replace( Qtopia::DefaultEmail, e ); | 1218 | replace( Qtopia::DefaultEmail, e ); |
1189 | 1219 | ||
1190 | if ( !e.isEmpty() ) | 1220 | if ( !e.isEmpty() ) |
1191 | insertEmail( e ); | 1221 | insertEmail( e ); |
1192 | 1222 | ||
1193 | } | 1223 | } |
1194 | 1224 | ||
1195 | void OContact::insertEmails( const QStringList &v ) | 1225 | void OContact::insertEmails( const QStringList &v ) |
1196 | { | 1226 | { |
1197 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) | 1227 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) |
1198 | insertEmail( *it ); | 1228 | insertEmail( *it ); |
1199 | } | 1229 | } |
1200 | int OContact::rtti() { | 1230 | int OContact::rtti() { |
1201 | return OPimResolver::AddressBook; | 1231 | return OPimResolver::AddressBook; |
1202 | } | 1232 | } |
1203 | void OContact::setUid( int i ) | 1233 | void OContact::setUid( int i ) |
1204 | { | 1234 | { |
1205 | OPimRecord::setUid(i); | 1235 | OPimRecord::setUid(i); |
1206 | replace( Qtopia::AddressUid , QString::number(i)); | 1236 | replace( Qtopia::AddressUid , QString::number(i)); |
1207 | } | 1237 | } |
1238 | } | ||
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h index 1d46b81..34888dc 100644 --- a/libopie2/opiepim/ocontact.h +++ b/libopie2/opiepim/ocontact.h | |||
@@ -1,240 +1,251 @@ | |||
1 | /********************************************************************** | 1 | /* |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | This file is part of the Opie Project |
3 | ** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | ** | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | .=l. |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | .>+-= |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | _;:, .> :=|. This program is free software; you can |
8 | ** packaging of this file. | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | ** | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ** | 12 | ._= =} : or (at your option) any later version. |
13 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 13 | .%`+i> _;_. |
14 | ** | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | ** Contact info@trolltech.com if any conditions of this licensing are | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | ** not clear to you. | 16 | : .. .:, . . . without even the implied warranty of |
17 | ** | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | **********************************************************************/ | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | 19 | ..}^=.= = ; Library General Public License for more | |
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
20 | #ifndef __OCONTACT_H__ | 29 | #ifndef __OCONTACT_H__ |
21 | #define __OCONTACT_H__ | 30 | #define __OCONTACT_H__ |
22 | 31 | ||
23 | #include <opie/opimrecord.h> | 32 | #include <opie2/opimrecord.h> |
24 | #include <qpe/recordfields.h> | 33 | #include <qpe/recordfields.h> |
25 | 34 | ||
26 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
28 | 37 | ||
29 | #if defined(QPC_TEMPLATEDLL) | 38 | #if defined(QPC_TEMPLATEDLL) |
30 | // MOC_SKIP_BEGIN | 39 | // MOC_SKIP_BEGIN |
31 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; | 40 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
32 | // MOC_SKIP_END | 41 | // MOC_SKIP_END |
33 | #endif | 42 | #endif |
34 | 43 | ||
44 | namespace Opie { | ||
35 | class OContactPrivate; | 45 | class OContactPrivate; |
36 | 46 | ||
37 | /** | 47 | /** |
38 | * OContact class represents a specialised PIM Record for contacts. | 48 | * OContact class represents a specialised PIM Record for contacts. |
39 | * It does store all kind of persopn related information. | 49 | * It does store all kind of persopn related information. |
40 | * | 50 | * |
41 | * @short Contact Container | 51 | * @short Contact Container |
42 | * @author TT, Stefan Eiler, Holger Freyther | 52 | * @author TT, Stefan Eiler, Holger Freyther |
43 | */ | 53 | */ |
44 | class QPC_EXPORT OContact : public OPimRecord | 54 | class QPC_EXPORT OContact : public OPimRecord |
45 | { | 55 | { |
46 | friend class DataSet; | 56 | friend class DataSet; |
47 | public: | 57 | public: |
48 | OContact(); | 58 | OContact(); |
49 | OContact( const QMap<int, QString> &fromMap ); | 59 | OContact( const QMap<int, QString> &fromMap ); |
50 | virtual ~OContact(); | 60 | virtual ~OContact(); |
51 | 61 | ||
52 | enum DateFormat{ | 62 | enum DateFormat{ |
53 | Zip_City_State = 0, | 63 | Zip_City_State = 0, |
54 | City_State_Zip | 64 | City_State_Zip |
55 | }; | 65 | }; |
56 | 66 | ||
57 | /* | 67 | /* |
58 | * do we need to inline them | 68 | * do we need to inline them |
59 | * if yes do we need to inline them this way? | 69 | * if yes do we need to inline them this way? |
60 | * -zecke | 70 | * -zecke |
61 | */ | 71 | */ |
62 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 72 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
63 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 73 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
64 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 74 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
65 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 75 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
66 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 76 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
67 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 77 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
68 | void setFileAs(); | 78 | void setFileAs(); |
69 | 79 | ||
70 | // default email address | 80 | // default email address |
71 | void setDefaultEmail( const QString &v ); | 81 | void setDefaultEmail( const QString &v ); |
72 | // inserts email to list and ensure's doesn't already exist | 82 | // inserts email to list and ensure's doesn't already exist |
73 | void insertEmail( const QString &v ); | 83 | void insertEmail( const QString &v ); |
74 | void removeEmail( const QString &v ); | 84 | void removeEmail( const QString &v ); |
75 | void clearEmails(); | 85 | void clearEmails(); |
76 | void insertEmails( const QStringList &v ); | 86 | void insertEmails( const QStringList &v ); |
77 | 87 | ||
78 | // home | 88 | // home |
79 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 89 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
80 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 90 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
81 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 91 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
82 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 92 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
83 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 93 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
84 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 94 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
85 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 95 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
86 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 96 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
87 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 97 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
88 | 98 | ||
89 | // business | 99 | // business |
90 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 100 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
91 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 101 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
92 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 102 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
93 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 103 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
94 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 104 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
95 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 105 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
96 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 106 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
97 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } | 107 | void setJobTitle( const QString &v ) { replace( Qtopia::JobTitle, v ); } |
98 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } | 108 | void setDepartment( const QString &v ) { replace( Qtopia::Department, v ); } |
99 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } | 109 | void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } |
100 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } | 110 | void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } |
101 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } | 111 | void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } |
102 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } | 112 | void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } |
103 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } | 113 | void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } |
104 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } | 114 | void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } |
105 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } | 115 | void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } |
106 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } | 116 | void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } |
107 | 117 | ||
108 | // personal | 118 | // personal |
109 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } | 119 | void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } |
110 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } | 120 | void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } |
111 | void setBirthday( const QDate &v ); | 121 | void setBirthday( const QDate &v ); |
112 | void setAnniversary( const QDate &v ); | 122 | void setAnniversary( const QDate &v ); |
113 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } | 123 | void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } |
114 | void setChildren( const QString &v ); | 124 | void setChildren( const QString &v ); |
115 | 125 | ||
116 | // other | 126 | // other |
117 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } | 127 | void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } |
118 | 128 | ||
119 | virtual bool match( const QRegExp ®exp ) const; | 129 | virtual bool match( const QRegExp ®exp ) const; |
120 | 130 | ||
121 | // // custom | 131 | // // custom |
122 | // void setCustomField( const QString &key, const QString &v ) | 132 | // void setCustomField( const QString &key, const QString &v ) |
123 | // { replace(Custom- + key, v ); } | 133 | // { replace(Custom- + key, v ); } |
124 | 134 | ||
125 | // name | 135 | // name |
126 | QString fullName() const; | 136 | QString fullName() const; |
127 | QString title() const { return find( Qtopia::Title ); } | 137 | QString title() const { return find( Qtopia::Title ); } |
128 | QString firstName() const { return find( Qtopia::FirstName ); } | 138 | QString firstName() const { return find( Qtopia::FirstName ); } |
129 | QString middleName() const { return find( Qtopia::MiddleName ); } | 139 | QString middleName() const { return find( Qtopia::MiddleName ); } |
130 | QString lastName() const { return find( Qtopia::LastName ); } | 140 | QString lastName() const { return find( Qtopia::LastName ); } |
131 | QString suffix() const { return find( Qtopia::Suffix ); } | 141 | QString suffix() const { return find( Qtopia::Suffix ); } |
132 | QString fileAs() const { return find( Qtopia::FileAs ); } | 142 | QString fileAs() const { return find( Qtopia::FileAs ); } |
133 | 143 | ||
134 | 144 | ||
135 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } | 145 | QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } |
136 | QStringList emailList() const; | 146 | QStringList emailList() const; |
137 | 147 | ||
138 | // home | 148 | // home |
139 | /* | 149 | /* |
140 | * OPimAddress address(enum Location)const; | 150 | * OPimAddress address(enum Location)const; |
141 | * would be some how nicer... | 151 | * would be some how nicer... |
142 | * -zecke | 152 | * -zecke |
143 | */ | 153 | */ |
144 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } | 154 | QString homeStreet() const { return find( Qtopia::HomeStreet ); } |
145 | QString homeCity() const { return find( Qtopia::HomeCity ); } | 155 | QString homeCity() const { return find( Qtopia::HomeCity ); } |
146 | QString homeState() const { return find( Qtopia::HomeState ); } | 156 | QString homeState() const { return find( Qtopia::HomeState ); } |
147 | QString homeZip() const { return find( Qtopia::HomeZip ); } | 157 | QString homeZip() const { return find( Qtopia::HomeZip ); } |
148 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } | 158 | QString homeCountry() const { return find( Qtopia::HomeCountry ); } |
149 | QString homePhone() const { return find( Qtopia::HomePhone ); } | 159 | QString homePhone() const { return find( Qtopia::HomePhone ); } |
150 | QString homeFax() const { return find( Qtopia::HomeFax ); } | 160 | QString homeFax() const { return find( Qtopia::HomeFax ); } |
151 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } | 161 | QString homeMobile() const { return find( Qtopia::HomeMobile ); } |
152 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } | 162 | QString homeWebpage() const { return find( Qtopia::HomeWebPage ); } |
153 | /** Multi line string containing all non-empty address info in the form | 163 | /** Multi line string containing all non-empty address info in the form |
154 | * Street | 164 | * Street |
155 | * City, State Zip | 165 | * City, State Zip |
156 | * Country | 166 | * Country |
157 | */ | 167 | */ |
158 | QString displayHomeAddress() const; | 168 | QString displayHomeAddress() const; |
159 | 169 | ||
160 | // business | 170 | // business |
161 | QString company() const { return find( Qtopia::Company ); } | 171 | QString company() const { return find( Qtopia::Company ); } |
162 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } | 172 | QString businessStreet() const { return find( Qtopia::BusinessStreet ); } |
163 | QString businessCity() const { return find( Qtopia::BusinessCity ); } | 173 | QString businessCity() const { return find( Qtopia::BusinessCity ); } |
164 | QString businessState() const { return find( Qtopia::BusinessState ); } | 174 | QString businessState() const { return find( Qtopia::BusinessState ); } |
165 | QString businessZip() const { return find( Qtopia::BusinessZip ); } | 175 | QString businessZip() const { return find( Qtopia::BusinessZip ); } |
166 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } | 176 | QString businessCountry() const { return find( Qtopia::BusinessCountry ); } |
167 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } | 177 | QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } |
168 | QString jobTitle() const { return find( Qtopia::JobTitle ); } | 178 | QString jobTitle() const { return find( Qtopia::JobTitle ); } |
169 | QString department() const { return find( Qtopia::Department ); } | 179 | QString department() const { return find( Qtopia::Department ); } |
170 | QString office() const { return find( Qtopia::Office ); } | 180 | QString office() const { return find( Qtopia::Office ); } |
171 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } | 181 | QString businessPhone() const { return find( Qtopia::BusinessPhone ); } |
172 | QString businessFax() const { return find( Qtopia::BusinessFax ); } | 182 | QString businessFax() const { return find( Qtopia::BusinessFax ); } |
173 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } | 183 | QString businessMobile() const { return find( Qtopia::BusinessMobile ); } |
174 | QString businessPager() const { return find( Qtopia::BusinessPager ); } | 184 | QString businessPager() const { return find( Qtopia::BusinessPager ); } |
175 | QString profession() const { return find( Qtopia::Profession ); } | 185 | QString profession() const { return find( Qtopia::Profession ); } |
176 | QString assistant() const { return find( Qtopia::Assistant ); } | 186 | QString assistant() const { return find( Qtopia::Assistant ); } |
177 | QString manager() const { return find( Qtopia::Manager ); } | 187 | QString manager() const { return find( Qtopia::Manager ); } |
178 | /** Multi line string containing all non-empty address info in the form | 188 | /** Multi line string containing all non-empty address info in the form |
179 | * Street | 189 | * Street |
180 | * City, State Zip | 190 | * City, State Zip |
181 | * Country | 191 | * Country |
182 | */ | 192 | */ |
183 | QString displayBusinessAddress() const; | 193 | QString displayBusinessAddress() const; |
184 | 194 | ||
185 | //personal | 195 | //personal |
186 | QString spouse() const { return find( Qtopia::Spouse ); } | 196 | QString spouse() const { return find( Qtopia::Spouse ); } |
187 | QString gender() const { return find( Qtopia::Gender ); } | 197 | QString gender() const { return find( Qtopia::Gender ); } |
188 | QDate birthday() const; | 198 | QDate birthday() const; |
189 | QDate anniversary() const; | 199 | QDate anniversary() const; |
190 | QString nickname() const { return find( Qtopia::Nickname ); } | 200 | QString nickname() const { return find( Qtopia::Nickname ); } |
191 | QString children() const { return find( Qtopia::Children ); } | 201 | QString children() const { return find( Qtopia::Children ); } |
192 | QStringList childrenList() const; | 202 | QStringList childrenList() const; |
193 | 203 | ||
194 | // other | 204 | // other |
195 | QString notes() const { return find( Qtopia::Notes ); } | 205 | QString notes() const { return find( Qtopia::Notes ); } |
196 | QString groups() const { return find( Qtopia::Groups ); } | 206 | QString groups() const { return find( Qtopia::Groups ); } |
197 | QStringList groupList() const; | 207 | QStringList groupList() const; |
198 | 208 | ||
199 | QString toRichText() const; | 209 | QString toRichText() const; |
200 | QMap<int, QString> toMap() const; | 210 | QMap<int, QString> toMap() const; |
201 | QString field( int key ) const { return find( key ); } | 211 | QString field( int key ) const { return find( key ); } |
202 | 212 | ||
203 | 213 | ||
204 | void setUid( int i ); | 214 | void setUid( int i ); |
205 | 215 | ||
206 | QString toShortText()const; | 216 | QString toShortText()const; |
207 | QString type()const; | 217 | QString type()const; |
208 | class QString recordField(int) const; | 218 | class QString recordField(int) const; |
209 | 219 | ||
210 | // Why private ? (eilers,se) | 220 | // Why private ? (eilers,se) |
211 | QString emailSeparator() const { return " "; } | 221 | QString emailSeparator() const { return " "; } |
212 | 222 | ||
213 | // the emails should be seperated by a comma | 223 | // the emails should be seperated by a comma |
214 | void setEmails( const QString &v ); | 224 | void setEmails( const QString &v ); |
215 | QString emails() const { return find( Qtopia::Emails ); } | 225 | QString emails() const { return find( Qtopia::Emails ); } |
216 | static int rtti(); | 226 | static int rtti(); |
217 | 227 | ||
218 | private: | 228 | private: |
219 | // The XML Backend needs some access to the private functions | 229 | // The XML Backend needs some access to the private functions |
220 | friend class OContactAccessBackend_XML; | 230 | friend class OContactAccessBackend_XML; |
221 | 231 | ||
222 | void insert( int key, const QString &value ); | 232 | void insert( int key, const QString &value ); |
223 | void replace( int key, const QString &value ); | 233 | void replace( int key, const QString &value ); |
224 | QString find( int key ) const; | 234 | QString find( int key ) const; |
225 | static QStringList fields(); | 235 | static QStringList fields(); |
226 | 236 | ||
227 | void save( QString &buf ) const; | 237 | void save( QString &buf ) const; |
228 | 238 | ||
229 | QString displayAddress( const QString &street, | 239 | QString displayAddress( const QString &street, |
230 | const QString &city, | 240 | const QString &city, |
231 | const QString &state, | 241 | const QString &state, |
232 | const QString &zip, | 242 | const QString &zip, |
233 | const QString &country ) const; | 243 | const QString &country ) const; |
234 | 244 | ||
235 | QMap<int, QString> mMap; | 245 | QMap<int, QString> mMap; |
236 | OContactPrivate *d; | 246 | OContactPrivate *d; |
237 | }; | 247 | }; |
238 | 248 | ||
249 | } | ||
239 | 250 | ||
240 | #endif | 251 | #endif |
diff --git a/libopie2/opiepim/ocontactfields.cpp b/libopie2/opiepim/ocontactfields.cpp index 0f08a5a..deaa1e5 100644 --- a/libopie2/opiepim/ocontactfields.cpp +++ b/libopie2/opiepim/ocontactfields.cpp | |||
@@ -1,203 +1,232 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | 29 | ||
2 | #include "ocontactfields.h" | 30 | #include <opie2/ocontactfields.h> |
3 | 31 | ||
4 | #include <qstringlist.h> | 32 | #include <qstringlist.h> |
5 | #include <qobject.h> | 33 | #include <qobject.h> |
6 | 34 | ||
7 | // We should use our own enum in the future .. | 35 | // We should use our own enum in the future .. |
8 | #include <qpe/recordfields.h> | 36 | #include <qpe/recordfields.h> |
9 | #include <qpe/config.h> | 37 | #include <qpe/config.h> |
10 | #include <opie/ocontact.h> | 38 | #include <opie2/ocontact.h> |
11 | 39 | ||
40 | namespace Opie { | ||
12 | /*! | 41 | /*! |
13 | \internal | 42 | \internal |
14 | Returns a list of personal field names for a contact. | 43 | Returns a list of personal field names for a contact. |
15 | */ | 44 | */ |
16 | QStringList OContactFields::personalfields( bool sorted, bool translated ) | 45 | QStringList OContactFields::personalfields( bool sorted, bool translated ) |
17 | { | 46 | { |
18 | QStringList list; | 47 | QStringList list; |
19 | QMap<int, QString> mapIdToStr; | 48 | QMap<int, QString> mapIdToStr; |
20 | if ( translated ) | 49 | if ( translated ) |
21 | mapIdToStr = idToTrFields(); | 50 | mapIdToStr = idToTrFields(); |
22 | else | 51 | else |
23 | mapIdToStr = idToUntrFields(); | 52 | mapIdToStr = idToUntrFields(); |
24 | 53 | ||
25 | list.append( mapIdToStr[ Qtopia::AddressUid ] ); | 54 | list.append( mapIdToStr[ Qtopia::AddressUid ] ); |
26 | list.append( mapIdToStr[ Qtopia::AddressCategory ] ); | 55 | list.append( mapIdToStr[ Qtopia::AddressCategory ] ); |
27 | 56 | ||
28 | list.append( mapIdToStr[ Qtopia::Title ] ); | 57 | list.append( mapIdToStr[ Qtopia::Title ] ); |
29 | list.append( mapIdToStr[ Qtopia::FirstName ] ); | 58 | list.append( mapIdToStr[ Qtopia::FirstName ] ); |
30 | list.append( mapIdToStr[ Qtopia::MiddleName ] ); | 59 | list.append( mapIdToStr[ Qtopia::MiddleName ] ); |
31 | list.append( mapIdToStr[ Qtopia::LastName ] ); | 60 | list.append( mapIdToStr[ Qtopia::LastName ] ); |
32 | list.append( mapIdToStr[ Qtopia::Suffix ] ); | 61 | list.append( mapIdToStr[ Qtopia::Suffix ] ); |
33 | list.append( mapIdToStr[ Qtopia::FileAs ] ); | 62 | list.append( mapIdToStr[ Qtopia::FileAs ] ); |
34 | 63 | ||
35 | list.append( mapIdToStr[ Qtopia::JobTitle ] ); | 64 | list.append( mapIdToStr[ Qtopia::JobTitle ] ); |
36 | list.append( mapIdToStr[ Qtopia::Department ] ); | 65 | list.append( mapIdToStr[ Qtopia::Department ] ); |
37 | list.append( mapIdToStr[ Qtopia::Company ] ); | 66 | list.append( mapIdToStr[ Qtopia::Company ] ); |
38 | 67 | ||
39 | list.append( mapIdToStr[ Qtopia::Notes ] ); | 68 | list.append( mapIdToStr[ Qtopia::Notes ] ); |
40 | list.append( mapIdToStr[ Qtopia::Groups ] ); | 69 | list.append( mapIdToStr[ Qtopia::Groups ] ); |
41 | 70 | ||
42 | if (sorted) list.sort(); | 71 | if (sorted) list.sort(); |
43 | return list; | 72 | return list; |
44 | } | 73 | } |
45 | 74 | ||
46 | /*! | 75 | /*! |
47 | \internal | 76 | \internal |
48 | Returns a list of details field names for a contact. | 77 | Returns a list of details field names for a contact. |
49 | */ | 78 | */ |
50 | QStringList OContactFields::detailsfields( bool sorted, bool translated ) | 79 | QStringList OContactFields::detailsfields( bool sorted, bool translated ) |
51 | { | 80 | { |
52 | QStringList list; | 81 | QStringList list; |
53 | QMap<int, QString> mapIdToStr; | 82 | QMap<int, QString> mapIdToStr; |
54 | if ( translated ) | 83 | if ( translated ) |
55 | mapIdToStr = idToTrFields(); | 84 | mapIdToStr = idToTrFields(); |
56 | else | 85 | else |
57 | mapIdToStr = idToUntrFields(); | 86 | mapIdToStr = idToUntrFields(); |
58 | 87 | ||
59 | list.append( mapIdToStr[ Qtopia::Office ] ); | 88 | list.append( mapIdToStr[ Qtopia::Office ] ); |
60 | list.append( mapIdToStr[ Qtopia::Profession ] ); | 89 | list.append( mapIdToStr[ Qtopia::Profession ] ); |
61 | list.append( mapIdToStr[ Qtopia::Assistant ] ); | 90 | list.append( mapIdToStr[ Qtopia::Assistant ] ); |
62 | list.append( mapIdToStr[ Qtopia::Manager ] ); | 91 | list.append( mapIdToStr[ Qtopia::Manager ] ); |
63 | 92 | ||
64 | list.append( mapIdToStr[ Qtopia::Spouse ] ); | 93 | list.append( mapIdToStr[ Qtopia::Spouse ] ); |
65 | list.append( mapIdToStr[ Qtopia::Gender ] ); | 94 | list.append( mapIdToStr[ Qtopia::Gender ] ); |
66 | list.append( mapIdToStr[ Qtopia::Birthday ] ); | 95 | list.append( mapIdToStr[ Qtopia::Birthday ] ); |
67 | list.append( mapIdToStr[ Qtopia::Anniversary ] ); | 96 | list.append( mapIdToStr[ Qtopia::Anniversary ] ); |
68 | list.append( mapIdToStr[ Qtopia::Nickname ] ); | 97 | list.append( mapIdToStr[ Qtopia::Nickname ] ); |
69 | list.append( mapIdToStr[ Qtopia::Children ] ); | 98 | list.append( mapIdToStr[ Qtopia::Children ] ); |
70 | 99 | ||
71 | if (sorted) list.sort(); | 100 | if (sorted) list.sort(); |
72 | return list; | 101 | return list; |
73 | } | 102 | } |
74 | 103 | ||
75 | /*! | 104 | /*! |
76 | \internal | 105 | \internal |
77 | Returns a list of phone field names for a contact. | 106 | Returns a list of phone field names for a contact. |
78 | */ | 107 | */ |
79 | QStringList OContactFields::phonefields( bool sorted, bool translated ) | 108 | QStringList OContactFields::phonefields( bool sorted, bool translated ) |
80 | { | 109 | { |
81 | QStringList list; | 110 | QStringList list; |
82 | QMap<int, QString> mapIdToStr; | 111 | QMap<int, QString> mapIdToStr; |
83 | if ( translated ) | 112 | if ( translated ) |
84 | mapIdToStr = idToTrFields(); | 113 | mapIdToStr = idToTrFields(); |
85 | else | 114 | else |
86 | mapIdToStr = idToUntrFields(); | 115 | mapIdToStr = idToUntrFields(); |
87 | 116 | ||
88 | list.append( mapIdToStr[Qtopia::BusinessPhone] ); | 117 | list.append( mapIdToStr[Qtopia::BusinessPhone] ); |
89 | list.append( mapIdToStr[Qtopia::BusinessFax] ); | 118 | list.append( mapIdToStr[Qtopia::BusinessFax] ); |
90 | list.append( mapIdToStr[Qtopia::BusinessMobile] ); | 119 | list.append( mapIdToStr[Qtopia::BusinessMobile] ); |
91 | list.append( mapIdToStr[Qtopia::BusinessPager] ); | 120 | list.append( mapIdToStr[Qtopia::BusinessPager] ); |
92 | list.append( mapIdToStr[Qtopia::BusinessWebPage] ); | 121 | list.append( mapIdToStr[Qtopia::BusinessWebPage] ); |
93 | 122 | ||
94 | list.append( mapIdToStr[Qtopia::DefaultEmail] ); | 123 | list.append( mapIdToStr[Qtopia::DefaultEmail] ); |
95 | list.append( mapIdToStr[Qtopia::Emails] ); | 124 | list.append( mapIdToStr[Qtopia::Emails] ); |
96 | 125 | ||
97 | list.append( mapIdToStr[Qtopia::HomePhone] ); | 126 | list.append( mapIdToStr[Qtopia::HomePhone] ); |
98 | list.append( mapIdToStr[Qtopia::HomeFax] ); | 127 | list.append( mapIdToStr[Qtopia::HomeFax] ); |
99 | list.append( mapIdToStr[Qtopia::HomeMobile] ); | 128 | list.append( mapIdToStr[Qtopia::HomeMobile] ); |
100 | // list.append( mapIdToStr[Qtopia::HomePager] ); | 129 | // list.append( mapIdToStr[Qtopia::HomePager] ); |
101 | list.append( mapIdToStr[Qtopia::HomeWebPage] ); | 130 | list.append( mapIdToStr[Qtopia::HomeWebPage] ); |
102 | 131 | ||
103 | if (sorted) list.sort(); | 132 | if (sorted) list.sort(); |
104 | 133 | ||
105 | return list; | 134 | return list; |
106 | } | 135 | } |
107 | 136 | ||
108 | /*! | 137 | /*! |
109 | \internal | 138 | \internal |
110 | Returns a list of field names for a contact. | 139 | Returns a list of field names for a contact. |
111 | */ | 140 | */ |
112 | QStringList OContactFields::fields( bool sorted, bool translated ) | 141 | QStringList OContactFields::fields( bool sorted, bool translated ) |
113 | { | 142 | { |
114 | QStringList list; | 143 | QStringList list; |
115 | QMap<int, QString> mapIdToStr; | 144 | QMap<int, QString> mapIdToStr; |
116 | if ( translated ) | 145 | if ( translated ) |
117 | mapIdToStr = idToTrFields(); | 146 | mapIdToStr = idToTrFields(); |
118 | else | 147 | else |
119 | mapIdToStr = idToUntrFields(); | 148 | mapIdToStr = idToUntrFields(); |
120 | 149 | ||
121 | list += personalfields( sorted, translated ); | 150 | list += personalfields( sorted, translated ); |
122 | 151 | ||
123 | list += phonefields( sorted, translated ); | 152 | list += phonefields( sorted, translated ); |
124 | 153 | ||
125 | list.append( mapIdToStr[Qtopia::BusinessStreet] ); | 154 | list.append( mapIdToStr[Qtopia::BusinessStreet] ); |
126 | list.append( mapIdToStr[Qtopia::BusinessCity] ); | 155 | list.append( mapIdToStr[Qtopia::BusinessCity] ); |
127 | list.append( mapIdToStr[Qtopia::BusinessState] ); | 156 | list.append( mapIdToStr[Qtopia::BusinessState] ); |
128 | list.append( mapIdToStr[Qtopia::BusinessZip] ); | 157 | list.append( mapIdToStr[Qtopia::BusinessZip] ); |
129 | list.append( mapIdToStr[Qtopia::BusinessCountry] ); | 158 | list.append( mapIdToStr[Qtopia::BusinessCountry] ); |
130 | 159 | ||
131 | list.append( mapIdToStr[Qtopia::HomeStreet] ); | 160 | list.append( mapIdToStr[Qtopia::HomeStreet] ); |
132 | list.append( mapIdToStr[Qtopia::HomeCity] ); | 161 | list.append( mapIdToStr[Qtopia::HomeCity] ); |
133 | list.append( mapIdToStr[Qtopia::HomeState] ); | 162 | list.append( mapIdToStr[Qtopia::HomeState] ); |
134 | list.append( mapIdToStr[Qtopia::HomeZip] ); | 163 | list.append( mapIdToStr[Qtopia::HomeZip] ); |
135 | list.append( mapIdToStr[Qtopia::HomeCountry] ); | 164 | list.append( mapIdToStr[Qtopia::HomeCountry] ); |
136 | 165 | ||
137 | list += detailsfields( sorted, translated ); | 166 | list += detailsfields( sorted, translated ); |
138 | 167 | ||
139 | if (sorted) list.sort(); | 168 | if (sorted) list.sort(); |
140 | 169 | ||
141 | return list; | 170 | return list; |
142 | } | 171 | } |
143 | 172 | ||
144 | 173 | ||
145 | /*! | 174 | /*! |
146 | \internal | 175 | \internal |
147 | Returns an untranslated list of personal field names for a contact. | 176 | Returns an untranslated list of personal field names for a contact. |
148 | */ | 177 | */ |
149 | QStringList OContactFields::untrpersonalfields( bool sorted ) | 178 | QStringList OContactFields::untrpersonalfields( bool sorted ) |
150 | { | 179 | { |
151 | return personalfields( sorted, false ); | 180 | return personalfields( sorted, false ); |
152 | } | 181 | } |
153 | 182 | ||
154 | 183 | ||
155 | /*! | 184 | /*! |
156 | \internal | 185 | \internal |
157 | Returns a translated list of personal field names for a contact. | 186 | Returns a translated list of personal field names for a contact. |
158 | */ | 187 | */ |
159 | QStringList OContactFields::trpersonalfields( bool sorted ) | 188 | QStringList OContactFields::trpersonalfields( bool sorted ) |
160 | { | 189 | { |
161 | return personalfields( sorted, true ); | 190 | return personalfields( sorted, true ); |
162 | } | 191 | } |
163 | 192 | ||
164 | 193 | ||
165 | /*! | 194 | /*! |
166 | \internal | 195 | \internal |
167 | Returns an untranslated list of details field names for a contact. | 196 | Returns an untranslated list of details field names for a contact. |
168 | */ | 197 | */ |
169 | QStringList OContactFields::untrdetailsfields( bool sorted ) | 198 | QStringList OContactFields::untrdetailsfields( bool sorted ) |
170 | { | 199 | { |
171 | return detailsfields( sorted, false ); | 200 | return detailsfields( sorted, false ); |
172 | } | 201 | } |
173 | 202 | ||
174 | 203 | ||
175 | /*! | 204 | /*! |
176 | \internal | 205 | \internal |
177 | Returns a translated list of details field names for a contact. | 206 | Returns a translated list of details field names for a contact. |
178 | */ | 207 | */ |
179 | QStringList OContactFields::trdetailsfields( bool sorted ) | 208 | QStringList OContactFields::trdetailsfields( bool sorted ) |
180 | { | 209 | { |
181 | return detailsfields( sorted, true ); | 210 | return detailsfields( sorted, true ); |
182 | } | 211 | } |
183 | 212 | ||
184 | 213 | ||
185 | /*! | 214 | /*! |
186 | \internal | 215 | \internal |
187 | Returns a translated list of phone field names for a contact. | 216 | Returns a translated list of phone field names for a contact. |
188 | */ | 217 | */ |
189 | QStringList OContactFields::trphonefields( bool sorted ) | 218 | QStringList OContactFields::trphonefields( bool sorted ) |
190 | { | 219 | { |
191 | return phonefields( sorted, true ); | 220 | return phonefields( sorted, true ); |
192 | } | 221 | } |
193 | 222 | ||
194 | /*! | 223 | /*! |
195 | \internal | 224 | \internal |
196 | Returns an untranslated list of phone field names for a contact. | 225 | Returns an untranslated list of phone field names for a contact. |
197 | */ | 226 | */ |
198 | QStringList OContactFields::untrphonefields( bool sorted ) | 227 | QStringList OContactFields::untrphonefields( bool sorted ) |
199 | { | 228 | { |
200 | return phonefields( sorted, false ); | 229 | return phonefields( sorted, false ); |
201 | } | 230 | } |
202 | 231 | ||
203 | 232 | ||
@@ -286,192 +315,194 @@ QMap<int, QString> OContactFields::idToTrFields() | |||
286 | } | 315 | } |
287 | 316 | ||
288 | QMap<int, QString> OContactFields::idToUntrFields() | 317 | QMap<int, QString> OContactFields::idToUntrFields() |
289 | { | 318 | { |
290 | QMap<int, QString> ret_map; | 319 | QMap<int, QString> ret_map; |
291 | 320 | ||
292 | ret_map.insert( Qtopia::AddressUid, "User Id" ); | 321 | ret_map.insert( Qtopia::AddressUid, "User Id" ); |
293 | ret_map.insert( Qtopia::AddressCategory, "Categories" ); | 322 | ret_map.insert( Qtopia::AddressCategory, "Categories" ); |
294 | 323 | ||
295 | ret_map.insert( Qtopia::Title, "Name Title" ); | 324 | ret_map.insert( Qtopia::Title, "Name Title" ); |
296 | ret_map.insert( Qtopia::FirstName, "First Name" ); | 325 | ret_map.insert( Qtopia::FirstName, "First Name" ); |
297 | ret_map.insert( Qtopia::MiddleName, "Middle Name" ); | 326 | ret_map.insert( Qtopia::MiddleName, "Middle Name" ); |
298 | ret_map.insert( Qtopia::LastName, "Last Name" ); | 327 | ret_map.insert( Qtopia::LastName, "Last Name" ); |
299 | ret_map.insert( Qtopia::Suffix, "Suffix" ); | 328 | ret_map.insert( Qtopia::Suffix, "Suffix" ); |
300 | ret_map.insert( Qtopia::FileAs, "File As" ); | 329 | ret_map.insert( Qtopia::FileAs, "File As" ); |
301 | 330 | ||
302 | ret_map.insert( Qtopia::JobTitle, "Job Title" ); | 331 | ret_map.insert( Qtopia::JobTitle, "Job Title" ); |
303 | ret_map.insert( Qtopia::Department, "Department" ); | 332 | ret_map.insert( Qtopia::Department, "Department" ); |
304 | ret_map.insert( Qtopia::Company, "Company" ); | 333 | ret_map.insert( Qtopia::Company, "Company" ); |
305 | ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); | 334 | ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); |
306 | ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); | 335 | ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); |
307 | ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); | 336 | ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); |
308 | 337 | ||
309 | 338 | ||
310 | ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); | 339 | ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); |
311 | ret_map.insert( Qtopia::Emails, "Emails" ); | 340 | ret_map.insert( Qtopia::Emails, "Emails" ); |
312 | 341 | ||
313 | ret_map.insert( Qtopia::HomePhone, "Home Phone" ); | 342 | ret_map.insert( Qtopia::HomePhone, "Home Phone" ); |
314 | ret_map.insert( Qtopia::HomeFax, "Home Fax" ); | 343 | ret_map.insert( Qtopia::HomeFax, "Home Fax" ); |
315 | ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); | 344 | ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); |
316 | 345 | ||
317 | // business | 346 | // business |
318 | ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); | 347 | ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); |
319 | ret_map.insert( Qtopia::BusinessCity, "Business City" ); | 348 | ret_map.insert( Qtopia::BusinessCity, "Business City" ); |
320 | ret_map.insert( Qtopia::BusinessState, "Business State" ); | 349 | ret_map.insert( Qtopia::BusinessState, "Business State" ); |
321 | ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); | 350 | ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); |
322 | ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); | 351 | ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); |
323 | ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); | 352 | ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); |
324 | ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); | 353 | ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); |
325 | 354 | ||
326 | ret_map.insert( Qtopia::Office, "Office" ); | 355 | ret_map.insert( Qtopia::Office, "Office" ); |
327 | ret_map.insert( Qtopia::Profession, "Profession" ); | 356 | ret_map.insert( Qtopia::Profession, "Profession" ); |
328 | ret_map.insert( Qtopia::Assistant, "Assistant" ); | 357 | ret_map.insert( Qtopia::Assistant, "Assistant" ); |
329 | ret_map.insert( Qtopia::Manager, "Manager" ); | 358 | ret_map.insert( Qtopia::Manager, "Manager" ); |
330 | 359 | ||
331 | // home | 360 | // home |
332 | ret_map.insert( Qtopia::HomeStreet, "Home Street" ); | 361 | ret_map.insert( Qtopia::HomeStreet, "Home Street" ); |
333 | ret_map.insert( Qtopia::HomeCity, "Home City" ); | 362 | ret_map.insert( Qtopia::HomeCity, "Home City" ); |
334 | ret_map.insert( Qtopia::HomeState, "Home State" ); | 363 | ret_map.insert( Qtopia::HomeState, "Home State" ); |
335 | ret_map.insert( Qtopia::HomeZip, "Home Zip" ); | 364 | ret_map.insert( Qtopia::HomeZip, "Home Zip" ); |
336 | ret_map.insert( Qtopia::HomeCountry, "Home Country" ); | 365 | ret_map.insert( Qtopia::HomeCountry, "Home Country" ); |
337 | ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); | 366 | ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); |
338 | 367 | ||
339 | //personal | 368 | //personal |
340 | ret_map.insert( Qtopia::Spouse, "Spouse" ); | 369 | ret_map.insert( Qtopia::Spouse, "Spouse" ); |
341 | ret_map.insert( Qtopia::Gender, "Gender" ); | 370 | ret_map.insert( Qtopia::Gender, "Gender" ); |
342 | ret_map.insert( Qtopia::Birthday, "Birthday" ); | 371 | ret_map.insert( Qtopia::Birthday, "Birthday" ); |
343 | ret_map.insert( Qtopia::Anniversary, "Anniversary" ); | 372 | ret_map.insert( Qtopia::Anniversary, "Anniversary" ); |
344 | ret_map.insert( Qtopia::Nickname, "Nickname" ); | 373 | ret_map.insert( Qtopia::Nickname, "Nickname" ); |
345 | ret_map.insert( Qtopia::Children, "Children" ); | 374 | ret_map.insert( Qtopia::Children, "Children" ); |
346 | 375 | ||
347 | // other | 376 | // other |
348 | ret_map.insert( Qtopia::Notes, "Notes" ); | 377 | ret_map.insert( Qtopia::Notes, "Notes" ); |
349 | ret_map.insert( Qtopia::Groups, "Groups" ); | 378 | ret_map.insert( Qtopia::Groups, "Groups" ); |
350 | 379 | ||
351 | 380 | ||
352 | return ret_map; | 381 | return ret_map; |
353 | } | 382 | } |
354 | 383 | ||
355 | QMap<QString, int> OContactFields::trFieldsToId() | 384 | QMap<QString, int> OContactFields::trFieldsToId() |
356 | { | 385 | { |
357 | QMap<int, QString> idtostr = idToTrFields(); | 386 | QMap<int, QString> idtostr = idToTrFields(); |
358 | QMap<QString, int> ret_map; | 387 | QMap<QString, int> ret_map; |
359 | 388 | ||
360 | 389 | ||
361 | QMap<int, QString>::Iterator it; | 390 | QMap<int, QString>::Iterator it; |
362 | for( it = idtostr.begin(); it != idtostr.end(); ++it ) | 391 | for( it = idtostr.begin(); it != idtostr.end(); ++it ) |
363 | ret_map.insert( *it, it.key() ); | 392 | ret_map.insert( *it, it.key() ); |
364 | 393 | ||
365 | 394 | ||
366 | return ret_map; | 395 | return ret_map; |
367 | } | 396 | } |
368 | 397 | ||
369 | /* ======================================================================= */ | 398 | /* ======================================================================= */ |
370 | 399 | ||
371 | QMap<QString, int> OContactFields::untrFieldsToId() | 400 | QMap<QString, int> OContactFields::untrFieldsToId() |
372 | { | 401 | { |
373 | QMap<int, QString> idtostr = idToUntrFields(); | 402 | QMap<int, QString> idtostr = idToUntrFields(); |
374 | QMap<QString, int> ret_map; | 403 | QMap<QString, int> ret_map; |
375 | 404 | ||
376 | 405 | ||
377 | QMap<int, QString>::Iterator it; | 406 | QMap<int, QString>::Iterator it; |
378 | for( it = idtostr.begin(); it != idtostr.end(); ++it ) | 407 | for( it = idtostr.begin(); it != idtostr.end(); ++it ) |
379 | ret_map.insert( *it, it.key() ); | 408 | ret_map.insert( *it, it.key() ); |
380 | 409 | ||
381 | 410 | ||
382 | return ret_map; | 411 | return ret_map; |
383 | } | 412 | } |
384 | 413 | ||
385 | 414 | ||
386 | OContactFields::OContactFields(): | 415 | OContactFields::OContactFields(): |
387 | fieldOrder( DEFAULT_FIELD_ORDER ), | 416 | fieldOrder( DEFAULT_FIELD_ORDER ), |
388 | changedFieldOrder( false ) | 417 | changedFieldOrder( false ) |
389 | { | 418 | { |
390 | // Get the global field order from the config file and | 419 | // Get the global field order from the config file and |
391 | // use it as a start pattern | 420 | // use it as a start pattern |
392 | Config cfg ( "AddressBook" ); | 421 | Config cfg ( "AddressBook" ); |
393 | cfg.setGroup( "ContactFieldOrder" ); | 422 | cfg.setGroup( "ContactFieldOrder" ); |
394 | globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); | 423 | globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); |
395 | } | 424 | } |
396 | 425 | ||
397 | OContactFields::~OContactFields(){ | 426 | OContactFields::~OContactFields(){ |
398 | 427 | ||
399 | // We will store the fieldorder into the config file | 428 | // We will store the fieldorder into the config file |
400 | // to reuse it for the future.. | 429 | // to reuse it for the future.. |
401 | if ( changedFieldOrder ){ | 430 | if ( changedFieldOrder ){ |
402 | Config cfg ( "AddressBook" ); | 431 | Config cfg ( "AddressBook" ); |
403 | cfg.setGroup( "ContactFieldOrder" ); | 432 | cfg.setGroup( "ContactFieldOrder" ); |
404 | cfg.writeEntry( "General", globalFieldOrder ); | 433 | cfg.writeEntry( "General", globalFieldOrder ); |
405 | } | 434 | } |
406 | } | 435 | } |
407 | 436 | ||
408 | 437 | ||
409 | 438 | ||
410 | void OContactFields::saveToRecord( OContact &cnt ){ | 439 | void OContactFields::saveToRecord( OContact &cnt ){ |
411 | 440 | ||
412 | qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); | 441 | qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); |
413 | 442 | ||
414 | // Store fieldorder into this contact. | 443 | // Store fieldorder into this contact. |
415 | cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); | 444 | cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); |
416 | 445 | ||
417 | globalFieldOrder = fieldOrder; | 446 | globalFieldOrder = fieldOrder; |
418 | changedFieldOrder = true; | 447 | changedFieldOrder = true; |
419 | 448 | ||
420 | } | 449 | } |
421 | 450 | ||
422 | void OContactFields::loadFromRecord( const OContact &cnt ){ | 451 | void OContactFields::loadFromRecord( const OContact &cnt ){ |
423 | qDebug("ocontactfields loadFromRecord"); | 452 | qDebug("ocontactfields loadFromRecord"); |
424 | qDebug("loading >%s<",cnt.fullName().latin1()); | 453 | qDebug("loading >%s<",cnt.fullName().latin1()); |
425 | 454 | ||
426 | // Get fieldorder for this contact. If none is defined, | 455 | // Get fieldorder for this contact. If none is defined, |
427 | // we will use the global one from the config file.. | 456 | // we will use the global one from the config file.. |
428 | 457 | ||
429 | fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); | 458 | fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); |
430 | 459 | ||
431 | qDebug("fieldOrder from contact>%s<",fieldOrder.latin1()); | 460 | qDebug("fieldOrder from contact>%s<",fieldOrder.latin1()); |
432 | 461 | ||
433 | if (fieldOrder.isEmpty()){ | 462 | if (fieldOrder.isEmpty()){ |
434 | fieldOrder = globalFieldOrder; | 463 | fieldOrder = globalFieldOrder; |
435 | } | 464 | } |
436 | 465 | ||
437 | 466 | ||
438 | qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1()); | 467 | qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1()); |
439 | } | 468 | } |
440 | 469 | ||
441 | void OContactFields::setFieldOrder( int num, int index ){ | 470 | void OContactFields::setFieldOrder( int num, int index ){ |
442 | qDebug("qcontactfields setfieldorder pos %i -> %i",num,index); | 471 | qDebug("qcontactfields setfieldorder pos %i -> %i",num,index); |
443 | 472 | ||
444 | fieldOrder[num] = QString::number( index, 16 )[0]; | 473 | fieldOrder[num] = QString::number( index, 16 )[0]; |
445 | 474 | ||
446 | // We will store this new fieldorder globally to | 475 | // We will store this new fieldorder globally to |
447 | // remember it for contacts which have none | 476 | // remember it for contacts which have none |
448 | globalFieldOrder = fieldOrder; | 477 | globalFieldOrder = fieldOrder; |
449 | changedFieldOrder = true; | 478 | changedFieldOrder = true; |
450 | 479 | ||
451 | qDebug("fieldOrder >%s<",fieldOrder.latin1()); | 480 | qDebug("fieldOrder >%s<",fieldOrder.latin1()); |
452 | } | 481 | } |
453 | 482 | ||
454 | int OContactFields::getFieldOrder( int num, int defIndex ){ | 483 | int OContactFields::getFieldOrder( int num, int defIndex ){ |
455 | qDebug("ocontactfields getFieldOrder"); | 484 | qDebug("ocontactfields getFieldOrder"); |
456 | qDebug("fieldOrder >%s<",fieldOrder.latin1()); | 485 | qDebug("fieldOrder >%s<",fieldOrder.latin1()); |
457 | 486 | ||
458 | // Get index of combo as char.. | 487 | // Get index of combo as char.. |
459 | QChar poschar = fieldOrder[num]; | 488 | QChar poschar = fieldOrder[num]; |
460 | 489 | ||
461 | bool ok; | 490 | bool ok; |
462 | int ret = 0; | 491 | int ret = 0; |
463 | // Convert char to number.. | 492 | // Convert char to number.. |
464 | if ( !( poschar == QChar::null ) ) | 493 | if ( !( poschar == QChar::null ) ) |
465 | ret = QString( poschar ).toInt(&ok, 16); | 494 | ret = QString( poschar ).toInt(&ok, 16); |
466 | else | 495 | else |
467 | ok = false; | 496 | ok = false; |
468 | 497 | ||
469 | // Return default value if index for | 498 | // Return default value if index for |
470 | // num was not set or if anything else happened.. | 499 | // num was not set or if anything else happened.. |
471 | if ( !ok ) ret = defIndex; | 500 | if ( !ok ) ret = defIndex; |
472 | 501 | ||
473 | qDebug("returning >%i<",ret); | 502 | qDebug("returning >%i<",ret); |
474 | 503 | ||
475 | return ret; | 504 | return ret; |
476 | 505 | ||
477 | } | 506 | } |
507 | |||
508 | } | ||
diff --git a/libopie2/opiepim/ocontactfields.h b/libopie2/opiepim/ocontactfields.h index f105de7..993ce3b 100644 --- a/libopie2/opiepim/ocontactfields.h +++ b/libopie2/opiepim/ocontactfields.h | |||
@@ -1,67 +1,96 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_CONTACTS_FIELDS | 29 | #ifndef OPIE_CONTACTS_FIELDS |
2 | #define OPIE_CONTACTS_FIELDS | 30 | #define OPIE_CONTACTS_FIELDS |
3 | 31 | ||
4 | class QStringList; | 32 | class QStringList; |
5 | 33 | ||
6 | #include <qmap.h> | 34 | #include <qmap.h> |
7 | #include <qstring.h> | 35 | #include <qstring.h> |
8 | #include <opie/ocontact.h> | 36 | #include <opie2/ocontact.h> |
9 | 37 | ||
10 | #define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" | 38 | #define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" |
11 | #define DEFAULT_FIELD_ORDER "__________" | 39 | #define DEFAULT_FIELD_ORDER "__________" |
12 | 40 | ||
41 | namespace Opie { | ||
13 | class OContactFields{ | 42 | class OContactFields{ |
14 | 43 | ||
15 | public: | 44 | public: |
16 | OContactFields(); | 45 | OContactFields(); |
17 | ~OContactFields(); | 46 | ~OContactFields(); |
18 | /** Set the index for combo boxes. | 47 | /** Set the index for combo boxes. |
19 | * Sets the <b>index</b> of combo <b>num</b>. | 48 | * Sets the <b>index</b> of combo <b>num</b>. |
20 | * @param num selects the number of the combo | 49 | * @param num selects the number of the combo |
21 | * @param index sets the index in the combo | 50 | * @param index sets the index in the combo |
22 | */ | 51 | */ |
23 | void setFieldOrder( int num, int index ); | 52 | void setFieldOrder( int num, int index ); |
24 | 53 | ||
25 | /** Get the index for combo boxes. | 54 | /** Get the index for combo boxes. |
26 | * Returns the index of combo <b>num</b> or defindex | 55 | * Returns the index of combo <b>num</b> or defindex |
27 | * if none was defined.. | 56 | * if none was defined.. |
28 | * @param num Selects the number of the combo | 57 | * @param num Selects the number of the combo |
29 | * @param defIndex will be returned if none was defined (either | 58 | * @param defIndex will be returned if none was defined (either |
30 | * globally in the config file, nor by the contact which was used | 59 | * globally in the config file, nor by the contact which was used |
31 | * by loadFromRecord() ) | 60 | * by loadFromRecord() ) |
32 | */ | 61 | */ |
33 | int getFieldOrder( int num, int defIndex); | 62 | int getFieldOrder( int num, int defIndex); |
34 | 63 | ||
35 | /** Store fieldorder to contact. */ | 64 | /** Store fieldorder to contact. */ |
36 | void saveToRecord( OContact& ); | 65 | void saveToRecord( OContact& ); |
37 | /** Get Fieldorder from contact. */ | 66 | /** Get Fieldorder from contact. */ |
38 | void loadFromRecord( const OContact& ); | 67 | void loadFromRecord( const OContact& ); |
39 | 68 | ||
40 | private: | 69 | private: |
41 | QString fieldOrder; | 70 | QString fieldOrder; |
42 | QString globalFieldOrder; | 71 | QString globalFieldOrder; |
43 | bool changedFieldOrder; | 72 | bool changedFieldOrder; |
44 | 73 | ||
45 | public: | 74 | public: |
46 | static QStringList personalfields( bool sorted = true, bool translated = false ); | 75 | static QStringList personalfields( bool sorted = true, bool translated = false ); |
47 | static QStringList phonefields( bool sorted = true, bool translated = false ); | 76 | static QStringList phonefields( bool sorted = true, bool translated = false ); |
48 | static QStringList detailsfields( bool sorted = true, bool translated = false ); | 77 | static QStringList detailsfields( bool sorted = true, bool translated = false ); |
49 | static QStringList fields( bool sorted = true, bool translated = false ); | 78 | static QStringList fields( bool sorted = true, bool translated = false ); |
50 | 79 | ||
51 | static QStringList trpersonalfields( bool sorted = true ); | 80 | static QStringList trpersonalfields( bool sorted = true ); |
52 | static QStringList untrpersonalfields( bool sorted = true ); | 81 | static QStringList untrpersonalfields( bool sorted = true ); |
53 | static QStringList trphonefields( bool sorted = true ); | 82 | static QStringList trphonefields( bool sorted = true ); |
54 | static QStringList untrphonefields( bool sorted = true ); | 83 | static QStringList untrphonefields( bool sorted = true ); |
55 | static QStringList trdetailsfields( bool sorted = true ); | 84 | static QStringList trdetailsfields( bool sorted = true ); |
56 | static QStringList untrdetailsfields( bool sorted = true ); | 85 | static QStringList untrdetailsfields( bool sorted = true ); |
57 | static QStringList trfields( bool sorted = true ); | 86 | static QStringList trfields( bool sorted = true ); |
58 | static QStringList untrfields( bool sorted = true ); | 87 | static QStringList untrfields( bool sorted = true ); |
59 | 88 | ||
60 | static QMap<int, QString> idToTrFields(); | 89 | static QMap<int, QString> idToTrFields(); |
61 | static QMap<QString, int> trFieldsToId(); | 90 | static QMap<QString, int> trFieldsToId(); |
62 | static QMap<int, QString> idToUntrFields(); | 91 | static QMap<int, QString> idToUntrFields(); |
63 | static QMap<QString, int> untrFieldsToId(); | 92 | static QMap<QString, int> untrFieldsToId(); |
64 | 93 | ||
65 | }; | 94 | }; |
66 | 95 | } | |
67 | #endif | 96 | #endif |
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp index 9b31957..de5e30b 100644 --- a/libopie2/opiepim/oevent.cpp +++ b/libopie2/opiepim/oevent.cpp | |||
@@ -1,204 +1,234 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qshared.h> | 29 | #include <qshared.h> |
2 | #include <qarray.h> | 30 | #include <qarray.h> |
3 | 31 | ||
4 | #include <qpe/palmtopuidgen.h> | 32 | #include <qpe/palmtopuidgen.h> |
5 | #include <qpe/categories.h> | 33 | #include <qpe/categories.h> |
6 | #include <qpe/stringutil.h> | 34 | #include <qpe/stringutil.h> |
7 | 35 | ||
8 | #include "orecur.h" | 36 | #include <opie2/orecur.h> |
9 | #include "opimresolver.h" | 37 | #include <opie2/opimresolver.h> |
10 | #include "opimnotifymanager.h" | 38 | #include <opie2/opimnotifymanager.h> |
11 | 39 | ||
12 | #include "oevent.h" | 40 | #include <opie2/oevent.h> |
41 | |||
42 | namespace Opie { | ||
13 | 43 | ||
14 | int OCalendarHelper::week( const QDate& date) { | 44 | int OCalendarHelper::week( const QDate& date) { |
15 | // Calculates the week this date is in within that | 45 | // Calculates the week this date is in within that |
16 | // month. Equals the "row" is is in in the month view | 46 | // month. Equals the "row" is is in in the month view |
17 | int week = 1; | 47 | int week = 1; |
18 | QDate tmp( date.year(), date.month(), 1 ); | 48 | QDate tmp( date.year(), date.month(), 1 ); |
19 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) | 49 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) |
20 | ++week; | 50 | ++week; |
21 | 51 | ||
22 | week += ( date.day() - 1 ) / 7; | 52 | week += ( date.day() - 1 ) / 7; |
23 | 53 | ||
24 | return week; | 54 | return week; |
25 | } | 55 | } |
26 | int OCalendarHelper::ocurrence( const QDate& date) { | 56 | int OCalendarHelper::ocurrence( const QDate& date) { |
27 | // calculates the number of occurrances of this day of the | 57 | // calculates the number of occurrances of this day of the |
28 | // week till the given date (e.g 3rd Wednesday of the month) | 58 | // week till the given date (e.g 3rd Wednesday of the month) |
29 | return ( date.day() - 1 ) / 7 + 1; | 59 | return ( date.day() - 1 ) / 7 + 1; |
30 | } | 60 | } |
31 | int OCalendarHelper::dayOfWeek( char day ) { | 61 | int OCalendarHelper::dayOfWeek( char day ) { |
32 | int dayOfWeek = 1; | 62 | int dayOfWeek = 1; |
33 | char i = ORecur::MON; | 63 | char i = ORecur::MON; |
34 | while ( !( i & day ) && i <= ORecur::SUN ) { | 64 | while ( !( i & day ) && i <= ORecur::SUN ) { |
35 | i <<= 1; | 65 | i <<= 1; |
36 | ++dayOfWeek; | 66 | ++dayOfWeek; |
37 | } | 67 | } |
38 | return dayOfWeek; | 68 | return dayOfWeek; |
39 | } | 69 | } |
40 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { | 70 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { |
41 | return ( second.year() - first.year() ) * 12 + | 71 | return ( second.year() - first.year() ) * 12 + |
42 | second.month() - first.month(); | 72 | second.month() - first.month(); |
43 | } | 73 | } |
44 | 74 | ||
45 | struct OEvent::Data : public QShared { | 75 | struct OEvent::Data : public QShared { |
46 | Data() : QShared() { | 76 | Data() : QShared() { |
47 | child = 0; | 77 | child = 0; |
48 | recur = 0; | 78 | recur = 0; |
49 | manager = 0; | 79 | manager = 0; |
50 | isAllDay = false; | 80 | isAllDay = false; |
51 | parent = 0; | 81 | parent = 0; |
52 | } | 82 | } |
53 | ~Data() { | 83 | ~Data() { |
54 | delete manager; | 84 | delete manager; |
55 | delete recur; | 85 | delete recur; |
56 | } | 86 | } |
57 | QString description; | 87 | QString description; |
58 | QString location; | 88 | QString location; |
59 | OPimNotifyManager* manager; | 89 | OPimNotifyManager* manager; |
60 | ORecur* recur; | 90 | ORecur* recur; |
61 | QString note; | 91 | QString note; |
62 | QDateTime created; | 92 | QDateTime created; |
63 | QDateTime start; | 93 | QDateTime start; |
64 | QDateTime end; | 94 | QDateTime end; |
65 | bool isAllDay : 1; | 95 | bool isAllDay : 1; |
66 | QString timezone; | 96 | QString timezone; |
67 | QArray<int>* child; | 97 | QArray<int>* child; |
68 | int parent; | 98 | int parent; |
69 | }; | 99 | }; |
70 | 100 | ||
71 | OEvent::OEvent( int uid ) | 101 | OEvent::OEvent( int uid ) |
72 | : OPimRecord( uid ) { | 102 | : OPimRecord( uid ) { |
73 | data = new Data; | 103 | data = new Data; |
74 | } | 104 | } |
75 | OEvent::OEvent( const OEvent& ev) | 105 | OEvent::OEvent( const OEvent& ev) |
76 | : OPimRecord( ev ), data( ev.data ) | 106 | : OPimRecord( ev ), data( ev.data ) |
77 | { | 107 | { |
78 | data->ref(); | 108 | data->ref(); |
79 | } | 109 | } |
80 | 110 | ||
81 | OEvent::OEvent( const QMap<int, QString> map ) | 111 | OEvent::OEvent( const QMap<int, QString> map ) |
82 | : OPimRecord( 0 ) | 112 | : OPimRecord( 0 ) |
83 | { | 113 | { |
84 | data = new Data; | 114 | data = new Data; |
85 | 115 | ||
86 | fromMap( map ); | 116 | fromMap( map ); |
87 | } | 117 | } |
88 | 118 | ||
89 | OEvent::~OEvent() { | 119 | OEvent::~OEvent() { |
90 | if ( data->deref() ) { | 120 | if ( data->deref() ) { |
91 | delete data; | 121 | delete data; |
92 | data = 0; | 122 | data = 0; |
93 | } | 123 | } |
94 | } | 124 | } |
95 | OEvent& OEvent::operator=( const OEvent& ev) { | 125 | OEvent& OEvent::operator=( const OEvent& ev) { |
96 | if ( this == &ev ) return *this; | 126 | if ( this == &ev ) return *this; |
97 | 127 | ||
98 | OPimRecord::operator=( ev ); | 128 | OPimRecord::operator=( ev ); |
99 | ev.data->ref(); | 129 | ev.data->ref(); |
100 | deref(); | 130 | deref(); |
101 | data = ev.data; | 131 | data = ev.data; |
102 | 132 | ||
103 | 133 | ||
104 | return *this; | 134 | return *this; |
105 | } | 135 | } |
106 | QString OEvent::description()const { | 136 | QString OEvent::description()const { |
107 | return data->description; | 137 | return data->description; |
108 | } | 138 | } |
109 | void OEvent::setDescription( const QString& description ) { | 139 | void OEvent::setDescription( const QString& description ) { |
110 | changeOrModify(); | 140 | changeOrModify(); |
111 | data->description = description; | 141 | data->description = description; |
112 | } | 142 | } |
113 | void OEvent::setLocation( const QString& loc ) { | 143 | void OEvent::setLocation( const QString& loc ) { |
114 | changeOrModify(); | 144 | changeOrModify(); |
115 | data->location = loc; | 145 | data->location = loc; |
116 | } | 146 | } |
117 | QString OEvent::location()const { | 147 | QString OEvent::location()const { |
118 | return data->location; | 148 | return data->location; |
119 | } | 149 | } |
120 | OPimNotifyManager &OEvent::notifiers()const { | 150 | OPimNotifyManager &OEvent::notifiers()const { |
121 | // I hope we can skip the changeOrModify here | 151 | // I hope we can skip the changeOrModify here |
122 | // the notifier should take care of it | 152 | // the notifier should take care of it |
123 | // and OPimNotify is shared too | 153 | // and OPimNotify is shared too |
124 | if (!data->manager ) | 154 | if (!data->manager ) |
125 | data->manager = new OPimNotifyManager; | 155 | data->manager = new OPimNotifyManager; |
126 | 156 | ||
127 | return *data->manager; | 157 | return *data->manager; |
128 | } | 158 | } |
129 | bool OEvent::hasNotifiers()const { | 159 | bool OEvent::hasNotifiers()const { |
130 | if (!data->manager ) | 160 | if (!data->manager ) |
131 | return false; | 161 | return false; |
132 | if (data->manager->reminders().isEmpty() && | 162 | if (data->manager->reminders().isEmpty() && |
133 | data->manager->alarms().isEmpty() ) | 163 | data->manager->alarms().isEmpty() ) |
134 | return false; | 164 | return false; |
135 | 165 | ||
136 | return true; | 166 | return true; |
137 | } | 167 | } |
138 | ORecur OEvent::recurrence()const { | 168 | ORecur OEvent::recurrence()const { |
139 | if (!data->recur) | 169 | if (!data->recur) |
140 | data->recur = new ORecur; | 170 | data->recur = new ORecur; |
141 | 171 | ||
142 | return *data->recur; | 172 | return *data->recur; |
143 | } | 173 | } |
144 | void OEvent::setRecurrence( const ORecur& rec) { | 174 | void OEvent::setRecurrence( const ORecur& rec) { |
145 | changeOrModify(); | 175 | changeOrModify(); |
146 | if (data->recur ) | 176 | if (data->recur ) |
147 | (*data->recur) = rec; | 177 | (*data->recur) = rec; |
148 | else | 178 | else |
149 | data->recur = new ORecur( rec ); | 179 | data->recur = new ORecur( rec ); |
150 | } | 180 | } |
151 | bool OEvent::hasRecurrence()const { | 181 | bool OEvent::hasRecurrence()const { |
152 | if (!data->recur ) return false; | 182 | if (!data->recur ) return false; |
153 | return data->recur->doesRecur(); | 183 | return data->recur->doesRecur(); |
154 | } | 184 | } |
155 | QString OEvent::note()const { | 185 | QString OEvent::note()const { |
156 | return data->note; | 186 | return data->note; |
157 | } | 187 | } |
158 | void OEvent::setNote( const QString& note ) { | 188 | void OEvent::setNote( const QString& note ) { |
159 | changeOrModify(); | 189 | changeOrModify(); |
160 | data->note = note; | 190 | data->note = note; |
161 | } | 191 | } |
162 | QDateTime OEvent::createdDateTime()const { | 192 | QDateTime OEvent::createdDateTime()const { |
163 | return data->created; | 193 | return data->created; |
164 | } | 194 | } |
165 | void OEvent::setCreatedDateTime( const QDateTime& time ) { | 195 | void OEvent::setCreatedDateTime( const QDateTime& time ) { |
166 | changeOrModify(); | 196 | changeOrModify(); |
167 | data->created = time; | 197 | data->created = time; |
168 | } | 198 | } |
169 | QDateTime OEvent::startDateTime()const { | 199 | QDateTime OEvent::startDateTime()const { |
170 | if ( data->isAllDay ) | 200 | if ( data->isAllDay ) |
171 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); | 201 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); |
172 | return data->start; | 202 | return data->start; |
173 | } | 203 | } |
174 | QDateTime OEvent::startDateTimeInZone()const { | 204 | QDateTime OEvent::startDateTimeInZone()const { |
175 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 205 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
176 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); | 206 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); |
177 | 207 | ||
178 | OTimeZone zone(data->timezone ); | 208 | OTimeZone zone(data->timezone ); |
179 | return zone.toDateTime( data->start, OTimeZone::current() ); | 209 | return zone.toDateTime( data->start, OTimeZone::current() ); |
180 | } | 210 | } |
181 | void OEvent::setStartDateTime( const QDateTime& dt ) { | 211 | void OEvent::setStartDateTime( const QDateTime& dt ) { |
182 | changeOrModify(); | 212 | changeOrModify(); |
183 | data->start = dt; | 213 | data->start = dt; |
184 | } | 214 | } |
185 | QDateTime OEvent::endDateTime()const { | 215 | QDateTime OEvent::endDateTime()const { |
186 | /* | 216 | /* |
187 | * if all Day event the end time needs | 217 | * if all Day event the end time needs |
188 | * to be on the same day as the start | 218 | * to be on the same day as the start |
189 | */ | 219 | */ |
190 | if ( data->isAllDay ) | 220 | if ( data->isAllDay ) |
191 | return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); | 221 | return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); |
192 | return data->end; | 222 | return data->end; |
193 | } | 223 | } |
194 | QDateTime OEvent::endDateTimeInZone()const { | 224 | QDateTime OEvent::endDateTimeInZone()const { |
195 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 225 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
196 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); | 226 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); |
197 | 227 | ||
198 | OTimeZone zone(data->timezone ); | 228 | OTimeZone zone(data->timezone ); |
199 | return zone.toDateTime( data->end, OTimeZone::current() ); | 229 | return zone.toDateTime( data->end, OTimeZone::current() ); |
200 | } | 230 | } |
201 | void OEvent::setEndDateTime( const QDateTime& dt ) { | 231 | void OEvent::setEndDateTime( const QDateTime& dt ) { |
202 | changeOrModify(); | 232 | changeOrModify(); |
203 | data->end = dt; | 233 | data->end = dt; |
204 | } | 234 | } |
@@ -526,192 +556,194 @@ void OEvent::addChild( int uid ) { | |||
526 | (*data->child)[0] = uid; | 556 | (*data->child)[0] = uid; |
527 | }else{ | 557 | }else{ |
528 | int count = data->child->count(); | 558 | int count = data->child->count(); |
529 | data->child->resize( count + 1 ); | 559 | data->child->resize( count + 1 ); |
530 | (*data->child)[count] = uid; | 560 | (*data->child)[count] = uid; |
531 | } | 561 | } |
532 | } | 562 | } |
533 | void OEvent::removeChild( int uid ) { | 563 | void OEvent::removeChild( int uid ) { |
534 | if (!data->child || !data->child->contains( uid ) ) return; | 564 | if (!data->child || !data->child->contains( uid ) ) return; |
535 | changeOrModify(); | 565 | changeOrModify(); |
536 | QArray<int> newAr( data->child->count() - 1 ); | 566 | QArray<int> newAr( data->child->count() - 1 ); |
537 | int j = 0; | 567 | int j = 0; |
538 | uint count = data->child->count(); | 568 | uint count = data->child->count(); |
539 | for ( uint i = 0; i < count; i++ ) { | 569 | for ( uint i = 0; i < count; i++ ) { |
540 | if ( (*data->child)[i] != uid ) { | 570 | if ( (*data->child)[i] != uid ) { |
541 | newAr[j] = (*data->child)[i]; | 571 | newAr[j] = (*data->child)[i]; |
542 | j++; | 572 | j++; |
543 | } | 573 | } |
544 | } | 574 | } |
545 | (*data->child) = newAr; | 575 | (*data->child) = newAr; |
546 | } | 576 | } |
547 | struct OEffectiveEvent::Data : public QShared { | 577 | struct OEffectiveEvent::Data : public QShared { |
548 | Data() : QShared() { | 578 | Data() : QShared() { |
549 | } | 579 | } |
550 | OEvent event; | 580 | OEvent event; |
551 | QDate date; | 581 | QDate date; |
552 | QTime start, end; | 582 | QTime start, end; |
553 | QDate startDate, endDate; | 583 | QDate startDate, endDate; |
554 | bool dates : 1; | 584 | bool dates : 1; |
555 | }; | 585 | }; |
556 | 586 | ||
557 | OEffectiveEvent::OEffectiveEvent() { | 587 | OEffectiveEvent::OEffectiveEvent() { |
558 | data = new Data; | 588 | data = new Data; |
559 | data->date = QDate::currentDate(); | 589 | data->date = QDate::currentDate(); |
560 | data->start = data->end = QTime::currentTime(); | 590 | data->start = data->end = QTime::currentTime(); |
561 | data->dates = false; | 591 | data->dates = false; |
562 | } | 592 | } |
563 | OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, | 593 | OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, |
564 | Position pos ) { | 594 | Position pos ) { |
565 | data = new Data; | 595 | data = new Data; |
566 | data->event = ev; | 596 | data->event = ev; |
567 | data->date = startDate; | 597 | data->date = startDate; |
568 | if ( pos & Start ) | 598 | if ( pos & Start ) |
569 | data->start = ev.startDateTime().time(); | 599 | data->start = ev.startDateTime().time(); |
570 | else | 600 | else |
571 | data->start = QTime( 0, 0, 0 ); | 601 | data->start = QTime( 0, 0, 0 ); |
572 | 602 | ||
573 | if ( pos & End ) | 603 | if ( pos & End ) |
574 | data->end = ev.endDateTime().time(); | 604 | data->end = ev.endDateTime().time(); |
575 | else | 605 | else |
576 | data->end = QTime( 23, 59, 59 ); | 606 | data->end = QTime( 23, 59, 59 ); |
577 | 607 | ||
578 | data->dates = false; | 608 | data->dates = false; |
579 | } | 609 | } |
580 | OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { | 610 | OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { |
581 | data = ev.data; | 611 | data = ev.data; |
582 | data->ref(); | 612 | data->ref(); |
583 | } | 613 | } |
584 | OEffectiveEvent::~OEffectiveEvent() { | 614 | OEffectiveEvent::~OEffectiveEvent() { |
585 | if ( data->deref() ) { | 615 | if ( data->deref() ) { |
586 | delete data; | 616 | delete data; |
587 | data = 0; | 617 | data = 0; |
588 | } | 618 | } |
589 | } | 619 | } |
590 | OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { | 620 | OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { |
591 | if ( *this == ev ) return *this; | 621 | if ( *this == ev ) return *this; |
592 | 622 | ||
593 | ev.data->ref(); | 623 | ev.data->ref(); |
594 | deref(); | 624 | deref(); |
595 | data = ev.data; | 625 | data = ev.data; |
596 | 626 | ||
597 | return *this; | 627 | return *this; |
598 | } | 628 | } |
599 | 629 | ||
600 | void OEffectiveEvent::setStartTime( const QTime& ti) { | 630 | void OEffectiveEvent::setStartTime( const QTime& ti) { |
601 | changeOrModify(); | 631 | changeOrModify(); |
602 | data->start = ti; | 632 | data->start = ti; |
603 | } | 633 | } |
604 | void OEffectiveEvent::setEndTime( const QTime& en) { | 634 | void OEffectiveEvent::setEndTime( const QTime& en) { |
605 | changeOrModify(); | 635 | changeOrModify(); |
606 | data->end = en; | 636 | data->end = en; |
607 | } | 637 | } |
608 | void OEffectiveEvent::setEvent( const OEvent& ev) { | 638 | void OEffectiveEvent::setEvent( const OEvent& ev) { |
609 | changeOrModify(); | 639 | changeOrModify(); |
610 | data->event = ev; | 640 | data->event = ev; |
611 | } | 641 | } |
612 | void OEffectiveEvent::setDate( const QDate& da) { | 642 | void OEffectiveEvent::setDate( const QDate& da) { |
613 | changeOrModify(); | 643 | changeOrModify(); |
614 | data->date = da; | 644 | data->date = da; |
615 | } | 645 | } |
616 | void OEffectiveEvent::setEffectiveDates( const QDate& from, | 646 | void OEffectiveEvent::setEffectiveDates( const QDate& from, |
617 | const QDate& to ) { | 647 | const QDate& to ) { |
618 | if (!from.isValid() ) { | 648 | if (!from.isValid() ) { |
619 | data->dates = false; | 649 | data->dates = false; |
620 | return; | 650 | return; |
621 | } | 651 | } |
622 | 652 | ||
623 | data->startDate = from; | 653 | data->startDate = from; |
624 | data->endDate = to; | 654 | data->endDate = to; |
625 | } | 655 | } |
626 | QString OEffectiveEvent::description()const { | 656 | QString OEffectiveEvent::description()const { |
627 | return data->event.description(); | 657 | return data->event.description(); |
628 | } | 658 | } |
629 | QString OEffectiveEvent::location()const { | 659 | QString OEffectiveEvent::location()const { |
630 | return data->event.location(); | 660 | return data->event.location(); |
631 | } | 661 | } |
632 | QString OEffectiveEvent::note()const { | 662 | QString OEffectiveEvent::note()const { |
633 | return data->event.note(); | 663 | return data->event.note(); |
634 | } | 664 | } |
635 | OEvent OEffectiveEvent::event()const { | 665 | OEvent OEffectiveEvent::event()const { |
636 | return data->event; | 666 | return data->event; |
637 | } | 667 | } |
638 | QTime OEffectiveEvent::startTime()const { | 668 | QTime OEffectiveEvent::startTime()const { |
639 | return data->start; | 669 | return data->start; |
640 | } | 670 | } |
641 | QTime OEffectiveEvent::endTime()const { | 671 | QTime OEffectiveEvent::endTime()const { |
642 | return data->end; | 672 | return data->end; |
643 | } | 673 | } |
644 | QDate OEffectiveEvent::date()const { | 674 | QDate OEffectiveEvent::date()const { |
645 | return data->date; | 675 | return data->date; |
646 | } | 676 | } |
647 | int OEffectiveEvent::length()const { | 677 | int OEffectiveEvent::length()const { |
648 | return (data->end.hour() * 60 - data->start.hour() * 60) | 678 | return (data->end.hour() * 60 - data->start.hour() * 60) |
649 | + QABS(data->start.minute() - data->end.minute() ); | 679 | + QABS(data->start.minute() - data->end.minute() ); |
650 | } | 680 | } |
651 | int OEffectiveEvent::size()const { | 681 | int OEffectiveEvent::size()const { |
652 | return ( data->end.hour() - data->start.hour() ) * 3600 | 682 | return ( data->end.hour() - data->start.hour() ) * 3600 |
653 | + (data->end.minute() - data->start.minute() * 60 | 683 | + (data->end.minute() - data->start.minute() * 60 |
654 | + data->end.second() - data->start.second() ); | 684 | + data->end.second() - data->start.second() ); |
655 | } | 685 | } |
656 | QDate OEffectiveEvent::startDate()const { | 686 | QDate OEffectiveEvent::startDate()const { |
657 | if ( data->dates ) | 687 | if ( data->dates ) |
658 | return data->startDate; | 688 | return data->startDate; |
659 | else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer | 689 | else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer |
660 | return data->date; | 690 | return data->date; |
661 | else | 691 | else |
662 | return data->event.startDateTime().date(); | 692 | return data->event.startDateTime().date(); |
663 | } | 693 | } |
664 | QDate OEffectiveEvent::endDate()const { | 694 | QDate OEffectiveEvent::endDate()const { |
665 | if ( data->dates ) | 695 | if ( data->dates ) |
666 | return data->endDate; | 696 | return data->endDate; |
667 | else if ( data->event.hasRecurrence() ) | 697 | else if ( data->event.hasRecurrence() ) |
668 | return data->date; | 698 | return data->date; |
669 | else | 699 | else |
670 | return data->event.endDateTime().date(); | 700 | return data->event.endDateTime().date(); |
671 | } | 701 | } |
672 | void OEffectiveEvent::deref() { | 702 | void OEffectiveEvent::deref() { |
673 | if ( data->deref() ) { | 703 | if ( data->deref() ) { |
674 | delete data; | 704 | delete data; |
675 | data = 0; | 705 | data = 0; |
676 | } | 706 | } |
677 | } | 707 | } |
678 | void OEffectiveEvent::changeOrModify() { | 708 | void OEffectiveEvent::changeOrModify() { |
679 | if ( data->count != 1 ) { | 709 | if ( data->count != 1 ) { |
680 | data->deref(); | 710 | data->deref(); |
681 | Data* d2 = new Data; | 711 | Data* d2 = new Data; |
682 | d2->event = data->event; | 712 | d2->event = data->event; |
683 | d2->date = data->date; | 713 | d2->date = data->date; |
684 | d2->start = data->start; | 714 | d2->start = data->start; |
685 | d2->end = data->end; | 715 | d2->end = data->end; |
686 | d2->startDate = data->startDate; | 716 | d2->startDate = data->startDate; |
687 | d2->endDate = data->endDate; | 717 | d2->endDate = data->endDate; |
688 | d2->dates = data->dates; | 718 | d2->dates = data->dates; |
689 | data = d2; | 719 | data = d2; |
690 | } | 720 | } |
691 | } | 721 | } |
692 | bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ | 722 | bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ |
693 | if ( data->date < e.date() ) | 723 | if ( data->date < e.date() ) |
694 | return TRUE; | 724 | return TRUE; |
695 | if ( data->date == e.date() ) | 725 | if ( data->date == e.date() ) |
696 | return ( startTime() < e.startTime() ); | 726 | return ( startTime() < e.startTime() ); |
697 | else | 727 | else |
698 | return FALSE; | 728 | return FALSE; |
699 | } | 729 | } |
700 | bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ | 730 | bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ |
701 | return (data->date <= e.date() ); | 731 | return (data->date <= e.date() ); |
702 | } | 732 | } |
703 | bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { | 733 | bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { |
704 | return ( date() == e.date() | 734 | return ( date() == e.date() |
705 | && startTime() == e.startTime() | 735 | && startTime() == e.startTime() |
706 | && endTime()== e.endTime() | 736 | && endTime()== e.endTime() |
707 | && event() == e.event() ); | 737 | && event() == e.event() ); |
708 | } | 738 | } |
709 | bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { | 739 | bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { |
710 | return !(*this == e ); | 740 | return !(*this == e ); |
711 | } | 741 | } |
712 | bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { | 742 | bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { |
713 | return !(*this <= e ); | 743 | return !(*this <= e ); |
714 | } | 744 | } |
715 | bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { | 745 | bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { |
716 | return !(*this < e); | 746 | return !(*this < e); |
717 | } | 747 | } |
748 | |||
749 | } | ||
diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h index 9eb948f..9502efa 100644 --- a/libopie2/opiepim/oevent.h +++ b/libopie2/opiepim/oevent.h | |||
@@ -1,236 +1,268 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | // CONTAINS GPLed code of TT | 29 | // CONTAINS GPLed code of TT |
2 | 30 | ||
3 | #ifndef OPIE_PIM_EVENT_H | 31 | #ifndef OPIE_PIM_EVENT_H |
4 | #define OPIE_PIM_EVENT_H | 32 | #define OPIE_PIM_EVENT_H |
5 | 33 | ||
6 | #include <qstring.h> | 34 | #include <qstring.h> |
7 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
8 | #include <qvaluelist.h> | 36 | #include <qvaluelist.h> |
9 | 37 | ||
10 | #include <qpe/recordfields.h> | 38 | #include <qpe/recordfields.h> |
11 | #include <qpe/palmtopuidgen.h> | 39 | #include <qpe/palmtopuidgen.h> |
12 | 40 | ||
13 | #include "otimezone.h" | 41 | #include <opie2/otimezone.h> |
14 | #include "opimrecord.h" | 42 | #include <opie2/opimrecord.h> |
15 | 43 | ||
44 | namespace Opie { | ||
16 | struct OCalendarHelper { | 45 | struct OCalendarHelper { |
17 | /** calculate the week number of the date */ | 46 | /** calculate the week number of the date */ |
18 | static int week( const QDate& ); | 47 | static int week( const QDate& ); |
19 | /** calculate the occurence of week days since the start of the month */ | 48 | /** calculate the occurence of week days since the start of the month */ |
20 | static int ocurrence( const QDate& ); | 49 | static int ocurrence( const QDate& ); |
21 | 50 | ||
22 | // returns the dayOfWeek for the *first* day it finds (ignores | 51 | // returns the dayOfWeek for the *first* day it finds (ignores |
23 | // any further days!). Returns 1 (Monday) if there isn't any day found | 52 | // any further days!). Returns 1 (Monday) if there isn't any day found |
24 | static int dayOfWeek( char day ); | 53 | static int dayOfWeek( char day ); |
25 | 54 | ||
26 | /** returns the diff of month */ | 55 | /** returns the diff of month */ |
27 | static int monthDiff( const QDate& first, const QDate& second ); | 56 | static int monthDiff( const QDate& first, const QDate& second ); |
28 | 57 | ||
29 | }; | 58 | }; |
30 | 59 | ||
31 | class OPimNotifyManager; | 60 | class OPimNotifyManager; |
32 | class ORecur; | 61 | class ORecur; |
33 | 62 | ||
34 | /** | 63 | /** |
35 | * This is the container for all Events. It encapsules all | 64 | * This is the container for all Events. It encapsules all |
36 | * available information for a single Event | 65 | * available information for a single Event |
37 | * @short container for events. | 66 | * @short container for events. |
38 | */ | 67 | */ |
39 | class OEvent : public OPimRecord { | 68 | class OEvent : public OPimRecord { |
40 | public: | 69 | public: |
41 | typedef QValueList<OEvent> ValueList; | 70 | typedef QValueList<OEvent> ValueList; |
42 | /** | 71 | /** |
43 | * RecordFields contain possible attributes | 72 | * RecordFields contain possible attributes |
44 | * used in the Results of toMap().. | 73 | * used in the Results of toMap().. |
45 | */ | 74 | */ |
46 | enum RecordFields { | 75 | enum RecordFields { |
47 | FUid = Qtopia::UID_ID, | 76 | FUid = Qtopia::UID_ID, |
48 | FCategories = Qtopia::CATEGORY_ID, | 77 | FCategories = Qtopia::CATEGORY_ID, |
49 | FDescription = 0, | 78 | FDescription = 0, |
50 | FLocation, | 79 | FLocation, |
51 | FType, | 80 | FType, |
52 | FAlarm, | 81 | FAlarm, |
53 | FSound, | 82 | FSound, |
54 | FRType, | 83 | FRType, |
55 | FRWeekdays, | 84 | FRWeekdays, |
56 | FRPosition, | 85 | FRPosition, |
57 | FRFreq, | 86 | FRFreq, |
58 | FRHasEndDate, | 87 | FRHasEndDate, |
59 | FREndDate, | 88 | FREndDate, |
60 | FRCreated, | 89 | FRCreated, |
61 | FRExceptions, | 90 | FRExceptions, |
62 | FStart, | 91 | FStart, |
63 | FEnd, | 92 | FEnd, |
64 | FNote, | 93 | FNote, |
65 | FTimeZone, | 94 | FTimeZone, |
66 | FRecParent, | 95 | FRecParent, |
67 | FRecChildren, | 96 | FRecChildren, |
68 | }; | 97 | }; |
69 | 98 | ||
70 | /** | 99 | /** |
71 | * Start with an Empty OEvent. UID == 0 means that it is empty | 100 | * Start with an Empty OEvent. UID == 0 means that it is empty |
72 | */ | 101 | */ |
73 | OEvent(int uid = 0); | 102 | OEvent(int uid = 0); |
74 | 103 | ||
75 | /** | 104 | /** |
76 | * copy c'tor | 105 | * copy c'tor |
77 | */ | 106 | */ |
78 | OEvent( const OEvent& ); | 107 | OEvent( const OEvent& ); |
79 | 108 | ||
80 | /** | 109 | /** |
81 | * Create OEvent, initialized by map | 110 | * Create OEvent, initialized by map |
82 | * @see enum RecordFields | 111 | * @see enum RecordFields |
83 | */ | 112 | */ |
84 | OEvent( const QMap<int, QString> map ); | 113 | OEvent( const QMap<int, QString> map ); |
85 | ~OEvent(); | 114 | ~OEvent(); |
86 | OEvent &operator=( const OEvent& ); | 115 | OEvent &operator=( const OEvent& ); |
87 | 116 | ||
88 | QString description()const; | 117 | QString description()const; |
89 | void setDescription( const QString& description ); | 118 | void setDescription( const QString& description ); |
90 | 119 | ||
91 | QString location()const; | 120 | QString location()const; |
92 | void setLocation( const QString& loc ); | 121 | void setLocation( const QString& loc ); |
93 | 122 | ||
94 | bool hasNotifiers()const; | 123 | bool hasNotifiers()const; |
95 | OPimNotifyManager ¬ifiers()const; | 124 | OPimNotifyManager ¬ifiers()const; |
96 | 125 | ||
97 | ORecur recurrence()const; | 126 | ORecur recurrence()const; |
98 | void setRecurrence( const ORecur& ); | 127 | void setRecurrence( const ORecur& ); |
99 | bool hasRecurrence()const; | 128 | bool hasRecurrence()const; |
100 | 129 | ||
101 | QString note()const; | 130 | QString note()const; |
102 | void setNote( const QString& note ); | 131 | void setNote( const QString& note ); |
103 | 132 | ||
104 | 133 | ||
105 | QDateTime createdDateTime()const; | 134 | QDateTime createdDateTime()const; |
106 | void setCreatedDateTime( const QDateTime& dt); | 135 | void setCreatedDateTime( const QDateTime& dt); |
107 | 136 | ||
108 | /** set the date to dt. dt is the QDateTime in localtime */ | 137 | /** set the date to dt. dt is the QDateTime in localtime */ |
109 | void setStartDateTime( const QDateTime& ); | 138 | void setStartDateTime( const QDateTime& ); |
110 | /** returns the datetime in the local timeZone */ | 139 | /** returns the datetime in the local timeZone */ |
111 | QDateTime startDateTime()const; | 140 | QDateTime startDateTime()const; |
112 | 141 | ||
113 | /** returns the start datetime in the current zone */ | 142 | /** returns the start datetime in the current zone */ |
114 | QDateTime startDateTimeInZone()const; | 143 | QDateTime startDateTimeInZone()const; |
115 | 144 | ||
116 | /** in current timezone */ | 145 | /** in current timezone */ |
117 | void setEndDateTime( const QDateTime& ); | 146 | void setEndDateTime( const QDateTime& ); |
118 | /** in current timezone */ | 147 | /** in current timezone */ |
119 | QDateTime endDateTime()const; | 148 | QDateTime endDateTime()const; |
120 | QDateTime endDateTimeInZone()const; | 149 | QDateTime endDateTimeInZone()const; |
121 | 150 | ||
122 | bool isMultipleDay()const; | 151 | bool isMultipleDay()const; |
123 | bool isAllDay()const; | 152 | bool isAllDay()const; |
124 | void setAllDay( bool isAllDay ); | 153 | void setAllDay( bool isAllDay ); |
125 | 154 | ||
126 | /* pin this event to a timezone! FIXME */ | 155 | /* pin this event to a timezone! FIXME */ |
127 | void setTimeZone( const QString& timeZone ); | 156 | void setTimeZone( const QString& timeZone ); |
128 | QString timeZone()const; | 157 | QString timeZone()const; |
129 | 158 | ||
130 | 159 | ||
131 | virtual bool match( const QRegExp& )const; | 160 | virtual bool match( const QRegExp& )const; |
132 | 161 | ||
133 | /** For exception to recurrence here is a list of children... */ | 162 | /** For exception to recurrence here is a list of children... */ |
134 | QArray<int> children()const; | 163 | QArray<int> children()const; |
135 | void setChildren( const QArray<int>& ); | 164 | void setChildren( const QArray<int>& ); |
136 | void addChild( int uid ); | 165 | void addChild( int uid ); |
137 | void removeChild( int uid ); | 166 | void removeChild( int uid ); |
138 | 167 | ||
139 | /** return the parent OEvent */ | 168 | /** return the parent OEvent */ |
140 | int parent()const; | 169 | int parent()const; |
141 | void setParent( int uid ); | 170 | void setParent( int uid ); |
142 | 171 | ||
143 | 172 | ||
144 | /* needed reimp */ | 173 | /* needed reimp */ |
145 | QString toRichText()const; | 174 | QString toRichText()const; |
146 | QString toShortText()const; | 175 | QString toShortText()const; |
147 | QString type()const; | 176 | QString type()const; |
148 | 177 | ||
149 | QMap<int, QString> toMap()const; | 178 | QMap<int, QString> toMap()const; |
150 | void fromMap( const QMap<int, QString>& map ); | 179 | void fromMap( const QMap<int, QString>& map ); |
151 | QString recordField(int )const; | 180 | QString recordField(int )const; |
152 | 181 | ||
153 | static int rtti(); | 182 | static int rtti(); |
154 | 183 | ||
155 | bool loadFromStream( QDataStream& ); | 184 | bool loadFromStream( QDataStream& ); |
156 | bool saveToStream( QDataStream& )const; | 185 | bool saveToStream( QDataStream& )const; |
157 | 186 | ||
158 | /* bool operator==( const OEvent& ); | 187 | /* bool operator==( const OEvent& ); |
159 | bool operator!=( const OEvent& ); | 188 | bool operator!=( const OEvent& ); |
160 | bool operator<( const OEvent& ); | 189 | bool operator<( const OEvent& ); |
161 | bool operator<=( const OEvent& ); | 190 | bool operator<=( const OEvent& ); |
162 | bool operator>( const OEvent& ); | 191 | bool operator>( const OEvent& ); |
163 | bool operator>=(const OEvent& ); | 192 | bool operator>=(const OEvent& ); |
164 | */ | 193 | */ |
165 | private: | 194 | private: |
166 | inline void changeOrModify(); | 195 | inline void changeOrModify(); |
167 | void deref(); | 196 | void deref(); |
168 | struct Data; | 197 | struct Data; |
169 | Data* data; | 198 | Data* data; |
170 | class Private; | 199 | class Private; |
171 | Private* priv; | 200 | Private* priv; |
172 | 201 | ||
173 | }; | 202 | }; |
174 | 203 | ||
175 | /** | 204 | /** |
176 | * AN Event can span through multiple days. We split up a multiday eve | 205 | * AN Event can span through multiple days. We split up a multiday eve |
177 | */ | 206 | */ |
178 | class OEffectiveEvent { | 207 | class OEffectiveEvent { |
179 | public: | 208 | public: |
180 | typedef QValueList<OEffectiveEvent> ValueList; | 209 | typedef QValueList<OEffectiveEvent> ValueList; |
181 | enum Position { MidWay, Start, End, StartEnd }; | 210 | enum Position { MidWay, Start, End, StartEnd }; |
182 | // If we calculate the effective event of a multi-day event | 211 | // If we calculate the effective event of a multi-day event |
183 | // we have to figure out whether we are at the first day, | 212 | // we have to figure out whether we are at the first day, |
184 | // at the end, or anywhere else ("middle"). This is important | 213 | // at the end, or anywhere else ("middle"). This is important |
185 | // for the start/end times (00:00/23:59) | 214 | // for the start/end times (00:00/23:59) |
186 | // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- | 215 | // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- |
187 | // day event | 216 | // day event |
188 | // Start: start time -> 23:59 | 217 | // Start: start time -> 23:59 |
189 | // End: 00:00 -> end time | 218 | // End: 00:00 -> end time |
190 | // Start | End == StartEnd: for single-day events (default) | 219 | // Start | End == StartEnd: for single-day events (default) |
191 | // here we draw start time -> end time | 220 | // here we draw start time -> end time |
192 | OEffectiveEvent(); | 221 | OEffectiveEvent(); |
193 | OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd ); | 222 | OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd ); |
194 | OEffectiveEvent( const OEffectiveEvent& ); | 223 | OEffectiveEvent( const OEffectiveEvent& ); |
195 | OEffectiveEvent &operator=(const OEffectiveEvent& ); | 224 | OEffectiveEvent &operator=(const OEffectiveEvent& ); |
196 | ~OEffectiveEvent(); | 225 | ~OEffectiveEvent(); |
197 | 226 | ||
198 | void setStartTime( const QTime& ); | 227 | void setStartTime( const QTime& ); |
199 | void setEndTime( const QTime& ); | 228 | void setEndTime( const QTime& ); |
200 | void setEvent( const OEvent& ); | 229 | void setEvent( const OEvent& ); |
201 | void setDate( const QDate& ); | 230 | void setDate( const QDate& ); |
202 | 231 | ||
203 | void setEffectiveDates( const QDate& from, const QDate& to ); | 232 | void setEffectiveDates( const QDate& from, const QDate& to ); |
204 | 233 | ||
205 | QString description()const; | 234 | QString description()const; |
206 | QString location()const; | 235 | QString location()const; |
207 | QString note()const; | 236 | QString note()const; |
208 | OEvent event()const; | 237 | OEvent event()const; |
209 | QTime startTime()const; | 238 | QTime startTime()const; |
210 | QTime endTime()const; | 239 | QTime endTime()const; |
211 | QDate date()const; | 240 | QDate date()const; |
212 | 241 | ||
213 | /* return the length in hours */ | 242 | /* return the length in hours */ |
214 | int length()const; | 243 | int length()const; |
215 | int size()const; | 244 | int size()const; |
216 | 245 | ||
217 | QDate startDate()const; | 246 | QDate startDate()const; |
218 | QDate endDate()const; | 247 | QDate endDate()const; |
219 | 248 | ||
220 | bool operator<( const OEffectiveEvent &e ) const; | 249 | bool operator<( const OEffectiveEvent &e ) const; |
221 | bool operator<=( const OEffectiveEvent &e ) const; | 250 | bool operator<=( const OEffectiveEvent &e ) const; |
222 | bool operator==( const OEffectiveEvent &e ) const; | 251 | bool operator==( const OEffectiveEvent &e ) const; |
223 | bool operator!=( const OEffectiveEvent &e ) const; | 252 | bool operator!=( const OEffectiveEvent &e ) const; |
224 | bool operator>( const OEffectiveEvent &e ) const; | 253 | bool operator>( const OEffectiveEvent &e ) const; |
225 | bool operator>= ( const OEffectiveEvent &e ) const; | 254 | bool operator>= ( const OEffectiveEvent &e ) const; |
226 | 255 | ||
227 | private: | 256 | private: |
228 | void deref(); | 257 | void deref(); |
229 | inline void changeOrModify(); | 258 | inline void changeOrModify(); |
230 | class Private; | 259 | class Private; |
231 | Private* priv; | 260 | Private* priv; |
232 | struct Data; | 261 | struct Data; |
233 | Data* data; | 262 | Data* data; |
234 | 263 | ||
235 | }; | 264 | }; |
265 | |||
266 | } | ||
267 | |||
236 | #endif | 268 | #endif |
diff --git a/libopie2/opiepim/opiepim.pro b/libopie2/opiepim/opiepim.pro index 3972c3f..82737f4 100644 --- a/libopie2/opiepim/opiepim.pro +++ b/libopie2/opiepim/opiepim.pro | |||
@@ -1,24 +1,30 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = | 4 | HEADERS = ocontact.h ocontactfields.h opimrecord.h otodo.h opimnotify.h opimnotifymanager.h oevent.h |
5 | 5 | ||
6 | SOURCES = | 6 | SOURCES = ocontact.cpp ocontactfields.cpp opimrecord.cpp otodo.cpp opimnotify.cpp \ |
7 | opimnotifymanager.cpp oevent.cpp | ||
7 | INTERFACES = | 8 | INTERFACES = |
8 | TARGET = opiepim2 | 9 | TARGET = opiepim2 |
9 | VERSION = 1.8.2 | 10 | VERSION = 1.8.2 |
10 | INCLUDEPATH += $(OPIEDIR)/include | 11 | INCLUDEPATH += $(OPIEDIR)/include |
11 | DEPENDPATH += $(OPIEDIR)/include | 12 | DEPENDPATH += $(OPIEDIR)/include |
12 | 13 | ||
14 | include ( core/core.pro ) | ||
15 | include ( core/backends/backends.pro ) | ||
16 | include ( ui/ui.pro ) | ||
17 | |||
13 | MOC_DIR = moc | 18 | MOC_DIR = moc |
14 | OBJECTS_DIR = obj | 19 | OBJECTS_DIR = obj |
15 | 20 | ||
16 | 21 | ||
17 | !contains( platform, x11 ) { | 22 | !contains( platform, x11 ) { |
18 | include ( $(OPIEDIR)/include.pro ) | 23 | include ( $(OPIEDIR)/include.pro ) |
19 | } | 24 | } |
20 | 25 | ||
21 | contains( platform, x11 ) { | 26 | contains( platform, x11 ) { |
22 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 27 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
23 | } | 28 | } |
24 | 29 | ||
30 | LIBS += -lopiecore2 | ||
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 5211f57..8f0011b 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -1,306 +1,336 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | 29 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 30 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 31 | #define OPIE_RECORD_LIST_H |
4 | 32 | ||
5 | #include <qarray.h> | 33 | #include <qarray.h> |
6 | 34 | ||
7 | #include "otemplatebase.h" | 35 | #include <opie2/otemplatebase.h> |
8 | #include "opimrecord.h" | 36 | #include <opie2/opimrecord.h> |
37 | |||
38 | namespace Opie { | ||
9 | 39 | ||
10 | class ORecordListIteratorPrivate; | 40 | class ORecordListIteratorPrivate; |
11 | /** | 41 | /** |
12 | * Our List Iterator | 42 | * Our List Iterator |
13 | * it behaves like STL or Qt | 43 | * it behaves like STL or Qt |
14 | * | 44 | * |
15 | * for(it = list.begin(); it != list.end(); ++it ) | 45 | * for(it = list.begin(); it != list.end(); ++it ) |
16 | * doSomeCoolStuff( (*it) ); | 46 | * doSomeCoolStuff( (*it) ); |
17 | */ | 47 | */ |
18 | template <class T> class ORecordList; | 48 | template <class T> class ORecordList; |
19 | template <class T = OPimRecord> | 49 | template <class T = OPimRecord> |
20 | class ORecordListIterator { | 50 | class ORecordListIterator { |
21 | friend class ORecordList<T>; | 51 | friend class ORecordList<T>; |
22 | public: | 52 | public: |
23 | typedef OTemplateBase<T> Base; | 53 | typedef OTemplateBase<T> Base; |
24 | 54 | ||
25 | /** | 55 | /** |
26 | * The c'tor used internally from | 56 | * The c'tor used internally from |
27 | * ORecordList | 57 | * ORecordList |
28 | */ | 58 | */ |
29 | ORecordListIterator( const QArray<int>, const Base* ); | 59 | ORecordListIterator( const QArray<int>, const Base* ); |
30 | 60 | ||
31 | /** | 61 | /** |
32 | * The standard c'tor | 62 | * The standard c'tor |
33 | */ | 63 | */ |
34 | ORecordListIterator(); | 64 | ORecordListIterator(); |
35 | ~ORecordListIterator(); | 65 | ~ORecordListIterator(); |
36 | 66 | ||
37 | ORecordListIterator( const ORecordListIterator& ); | 67 | ORecordListIterator( const ORecordListIterator& ); |
38 | ORecordListIterator &operator=(const ORecordListIterator& ); | 68 | ORecordListIterator &operator=(const ORecordListIterator& ); |
39 | 69 | ||
40 | /** | 70 | /** |
41 | * a * operator ;) | 71 | * a * operator ;) |
42 | * use it like this T = (*it); | 72 | * use it like this T = (*it); |
43 | */ | 73 | */ |
44 | T operator*(); | 74 | T operator*(); |
45 | ORecordListIterator &operator++(); | 75 | ORecordListIterator &operator++(); |
46 | ORecordListIterator &operator--(); | 76 | ORecordListIterator &operator--(); |
47 | 77 | ||
48 | bool operator==( const ORecordListIterator& it ); | 78 | bool operator==( const ORecordListIterator& it ); |
49 | bool operator!=( const ORecordListIterator& it ); | 79 | bool operator!=( const ORecordListIterator& it ); |
50 | 80 | ||
51 | /** | 81 | /** |
52 | * the current item | 82 | * the current item |
53 | */ | 83 | */ |
54 | uint current()const; | 84 | uint current()const; |
55 | 85 | ||
56 | /** | 86 | /** |
57 | * the number of items | 87 | * the number of items |
58 | */ | 88 | */ |
59 | uint count()const; | 89 | uint count()const; |
60 | 90 | ||
61 | /** | 91 | /** |
62 | * sets the current item | 92 | * sets the current item |
63 | */ | 93 | */ |
64 | void setCurrent( uint cur ); | 94 | void setCurrent( uint cur ); |
65 | 95 | ||
66 | private: | 96 | private: |
67 | QArray<int> m_uids; | 97 | QArray<int> m_uids; |
68 | uint m_current; | 98 | uint m_current; |
69 | const Base* m_temp; | 99 | const Base* m_temp; |
70 | bool m_end : 1; | 100 | bool m_end : 1; |
71 | T m_record; | 101 | T m_record; |
72 | bool m_direction :1; | 102 | bool m_direction :1; |
73 | 103 | ||
74 | /* d pointer for future versions */ | 104 | /* d pointer for future versions */ |
75 | ORecordListIteratorPrivate *d; | 105 | ORecordListIteratorPrivate *d; |
76 | }; | 106 | }; |
77 | 107 | ||
78 | class ORecordListPrivate; | 108 | class ORecordListPrivate; |
79 | /** | 109 | /** |
80 | * The recordlist used as a return type | 110 | * The recordlist used as a return type |
81 | * from OPimAccessTemplate | 111 | * from OPimAccessTemplate |
82 | */ | 112 | */ |
83 | template <class T = OPimRecord > | 113 | template <class T = OPimRecord > |
84 | class ORecordList { | 114 | class ORecordList { |
85 | public: | 115 | public: |
86 | typedef OTemplateBase<T> Base; | 116 | typedef OTemplateBase<T> Base; |
87 | typedef ORecordListIterator<T> Iterator; | 117 | typedef ORecordListIterator<T> Iterator; |
88 | 118 | ||
89 | /** | 119 | /** |
90 | * c'tor | 120 | * c'tor |
91 | */ | 121 | */ |
92 | ORecordList () { | 122 | ORecordList () { |
93 | } | 123 | } |
94 | ORecordList( const QArray<int>& ids, | 124 | ORecordList( const QArray<int>& ids, |
95 | const Base* ); | 125 | const Base* ); |
96 | ~ORecordList(); | 126 | ~ORecordList(); |
97 | 127 | ||
98 | /** | 128 | /** |
99 | * the first iterator | 129 | * the first iterator |
100 | */ | 130 | */ |
101 | Iterator begin(); | 131 | Iterator begin(); |
102 | 132 | ||
103 | /** | 133 | /** |
104 | * the end | 134 | * the end |
105 | */ | 135 | */ |
106 | Iterator end(); | 136 | Iterator end(); |
107 | 137 | ||
108 | /** | 138 | /** |
109 | * the number of items in the list | 139 | * the number of items in the list |
110 | */ | 140 | */ |
111 | uint count()const; | 141 | uint count()const; |
112 | 142 | ||
113 | T operator[]( uint i ); | 143 | T operator[]( uint i ); |
114 | int uidAt(uint i ); | 144 | int uidAt(uint i ); |
115 | 145 | ||
116 | /** | 146 | /** |
117 | * Remove the contact with given uid | 147 | * Remove the contact with given uid |
118 | */ | 148 | */ |
119 | bool remove( int uid ); | 149 | bool remove( int uid ); |
120 | 150 | ||
121 | /* | 151 | /* |
122 | ConstIterator begin()const; | 152 | ConstIterator begin()const; |
123 | ConstIterator end()const; | 153 | ConstIterator end()const; |
124 | */ | 154 | */ |
125 | private: | 155 | private: |
126 | QArray<int> m_ids; | 156 | QArray<int> m_ids; |
127 | const Base* m_acc; | 157 | const Base* m_acc; |
128 | ORecordListPrivate *d; | 158 | ORecordListPrivate *d; |
129 | }; | 159 | }; |
130 | 160 | ||
131 | /* ok now implement it */ | 161 | /* ok now implement it */ |
132 | template <class T> | 162 | template <class T> |
133 | ORecordListIterator<T>::ORecordListIterator() { | 163 | ORecordListIterator<T>::ORecordListIterator() { |
134 | m_current = 0; | 164 | m_current = 0; |
135 | m_temp = 0l; | 165 | m_temp = 0l; |
136 | m_end = true; | 166 | m_end = true; |
137 | m_record = T(); | 167 | m_record = T(); |
138 | /* forward */ | 168 | /* forward */ |
139 | m_direction = TRUE; | 169 | m_direction = TRUE; |
140 | } | 170 | } |
141 | template <class T> | 171 | template <class T> |
142 | ORecordListIterator<T>::~ORecordListIterator() { | 172 | ORecordListIterator<T>::~ORecordListIterator() { |
143 | /* nothing to delete */ | 173 | /* nothing to delete */ |
144 | } | 174 | } |
145 | 175 | ||
146 | template <class T> | 176 | template <class T> |
147 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 177 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
148 | // qWarning("ORecordListIterator copy c'tor"); | 178 | // qWarning("ORecordListIterator copy c'tor"); |
149 | m_uids = it.m_uids; | 179 | m_uids = it.m_uids; |
150 | m_current = it.m_current; | 180 | m_current = it.m_current; |
151 | m_temp = it.m_temp; | 181 | m_temp = it.m_temp; |
152 | m_end = it.m_end; | 182 | m_end = it.m_end; |
153 | m_record = it.m_record; | 183 | m_record = it.m_record; |
154 | m_direction = it.m_direction; | 184 | m_direction = it.m_direction; |
155 | } | 185 | } |
156 | 186 | ||
157 | template <class T> | 187 | template <class T> |
158 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 188 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
159 | m_uids = it.m_uids; | 189 | m_uids = it.m_uids; |
160 | m_current = it.m_current; | 190 | m_current = it.m_current; |
161 | m_temp = it.m_temp; | 191 | m_temp = it.m_temp; |
162 | m_end = it.m_end; | 192 | m_end = it.m_end; |
163 | m_record = it.m_record; | 193 | m_record = it.m_record; |
164 | 194 | ||
165 | return *this; | 195 | return *this; |
166 | } | 196 | } |
167 | 197 | ||
168 | template <class T> | 198 | template <class T> |
169 | T ORecordListIterator<T>::operator*() { | 199 | T ORecordListIterator<T>::operator*() { |
170 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 200 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
171 | if (!m_end ) | 201 | if (!m_end ) |
172 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 202 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
173 | m_direction ? Base::Forward : | 203 | m_direction ? Base::Forward : |
174 | Base::Reverse ); | 204 | Base::Reverse ); |
175 | else | 205 | else |
176 | m_record = T(); | 206 | m_record = T(); |
177 | 207 | ||
178 | return m_record; | 208 | return m_record; |
179 | } | 209 | } |
180 | 210 | ||
181 | template <class T> | 211 | template <class T> |
182 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 212 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
183 | m_direction = true; | 213 | m_direction = true; |
184 | if (m_current < m_uids.count() ) { | 214 | if (m_current < m_uids.count() ) { |
185 | m_end = false; | 215 | m_end = false; |
186 | ++m_current; | 216 | ++m_current; |
187 | }else | 217 | }else |
188 | m_end = true; | 218 | m_end = true; |
189 | 219 | ||
190 | return *this; | 220 | return *this; |
191 | } | 221 | } |
192 | template <class T> | 222 | template <class T> |
193 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 223 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
194 | m_direction = false; | 224 | m_direction = false; |
195 | if ( m_current > 0 ) { | 225 | if ( m_current > 0 ) { |
196 | --m_current; | 226 | --m_current; |
197 | m_end = false; | 227 | m_end = false; |
198 | } else | 228 | } else |
199 | m_end = true; | 229 | m_end = true; |
200 | 230 | ||
201 | return *this; | 231 | return *this; |
202 | } | 232 | } |
203 | 233 | ||
204 | template <class T> | 234 | template <class T> |
205 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 235 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
206 | 236 | ||
207 | /* if both are at we're the same.... */ | 237 | /* if both are at we're the same.... */ |
208 | if ( m_end == it.m_end ) return true; | 238 | if ( m_end == it.m_end ) return true; |
209 | 239 | ||
210 | if ( m_uids != it.m_uids ) return false; | 240 | if ( m_uids != it.m_uids ) return false; |
211 | if ( m_current != it.m_current ) return false; | 241 | if ( m_current != it.m_current ) return false; |
212 | if ( m_temp != it.m_temp ) return false; | 242 | if ( m_temp != it.m_temp ) return false; |
213 | 243 | ||
214 | return true; | 244 | return true; |
215 | } | 245 | } |
216 | template <class T> | 246 | template <class T> |
217 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 247 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
218 | return !(*this == it ); | 248 | return !(*this == it ); |
219 | } | 249 | } |
220 | template <class T> | 250 | template <class T> |
221 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 251 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
222 | const Base* t ) | 252 | const Base* t ) |
223 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 253 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
224 | m_direction( false ) | 254 | m_direction( false ) |
225 | { | 255 | { |
226 | /* if the list is empty we're already at the end of the list */ | 256 | /* if the list is empty we're already at the end of the list */ |
227 | if (uids.count() == 0 ) | 257 | if (uids.count() == 0 ) |
228 | m_end = true; | 258 | m_end = true; |
229 | } | 259 | } |
230 | template <class T> | 260 | template <class T> |
231 | uint ORecordListIterator<T>::current()const { | 261 | uint ORecordListIterator<T>::current()const { |
232 | return m_current; | 262 | return m_current; |
233 | } | 263 | } |
234 | template <class T> | 264 | template <class T> |
235 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 265 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
236 | if( cur < m_uids.count() ) { | 266 | if( cur < m_uids.count() ) { |
237 | m_end = false; | 267 | m_end = false; |
238 | m_current= cur; | 268 | m_current= cur; |
239 | } | 269 | } |
240 | } | 270 | } |
241 | template <class T> | 271 | template <class T> |
242 | uint ORecordListIterator<T>::count()const { | 272 | uint ORecordListIterator<T>::count()const { |
243 | return m_uids.count(); | 273 | return m_uids.count(); |
244 | } | 274 | } |
245 | template <class T> | 275 | template <class T> |
246 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 276 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
247 | const Base* acc ) | 277 | const Base* acc ) |
248 | : m_ids( ids ), m_acc( acc ) | 278 | : m_ids( ids ), m_acc( acc ) |
249 | { | 279 | { |
250 | } | 280 | } |
251 | template <class T> | 281 | template <class T> |
252 | ORecordList<T>::~ORecordList() { | 282 | ORecordList<T>::~ORecordList() { |
253 | /* nothing to do here */ | 283 | /* nothing to do here */ |
254 | } | 284 | } |
255 | template <class T> | 285 | template <class T> |
256 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { | 286 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { |
257 | Iterator it( m_ids, m_acc ); | 287 | Iterator it( m_ids, m_acc ); |
258 | return it; | 288 | return it; |
259 | } | 289 | } |
260 | template <class T> | 290 | template <class T> |
261 | typename ORecordList<T>::Iterator ORecordList<T>::end() { | 291 | typename ORecordList<T>::Iterator ORecordList<T>::end() { |
262 | Iterator it( m_ids, m_acc ); | 292 | Iterator it( m_ids, m_acc ); |
263 | it.m_end = true; | 293 | it.m_end = true; |
264 | it.m_current = m_ids.count(); | 294 | it.m_current = m_ids.count(); |
265 | 295 | ||
266 | return it; | 296 | return it; |
267 | } | 297 | } |
268 | template <class T> | 298 | template <class T> |
269 | uint ORecordList<T>::count()const { | 299 | uint ORecordList<T>::count()const { |
270 | return m_ids.count(); | 300 | return m_ids.count(); |
271 | } | 301 | } |
272 | template <class T> | 302 | template <class T> |
273 | T ORecordList<T>::operator[]( uint i ) { | 303 | T ORecordList<T>::operator[]( uint i ) { |
274 | if ( i >= m_ids.count() ) | 304 | if ( i >= m_ids.count() ) |
275 | return T(); | 305 | return T(); |
276 | /* forward */ | 306 | /* forward */ |
277 | return m_acc->find( m_ids[i], m_ids, i ); | 307 | return m_acc->find( m_ids[i], m_ids, i ); |
278 | } | 308 | } |
279 | template <class T> | 309 | template <class T> |
280 | int ORecordList<T>::uidAt( uint i ) { | 310 | int ORecordList<T>::uidAt( uint i ) { |
281 | return m_ids[i]; | 311 | return m_ids[i]; |
282 | } | 312 | } |
283 | 313 | ||
284 | template <class T> | 314 | template <class T> |
285 | bool ORecordList<T>::remove( int uid ) { | 315 | bool ORecordList<T>::remove( int uid ) { |
286 | QArray<int> copy( m_ids.count() ); | 316 | QArray<int> copy( m_ids.count() ); |
287 | int counter = 0; | 317 | int counter = 0; |
288 | bool ret_val = false; | 318 | bool ret_val = false; |
289 | 319 | ||
290 | for (uint i = 0; i < m_ids.count(); i++){ | 320 | for (uint i = 0; i < m_ids.count(); i++){ |
291 | if ( m_ids[i] != uid ){ | 321 | if ( m_ids[i] != uid ){ |
292 | copy[counter++] = m_ids[i]; | 322 | copy[counter++] = m_ids[i]; |
293 | 323 | ||
294 | }else | 324 | }else |
295 | ret_val = true; | 325 | ret_val = true; |
296 | } | 326 | } |
297 | 327 | ||
298 | copy.resize( counter ); | 328 | copy.resize( counter ); |
299 | m_ids = copy; | 329 | m_ids = copy; |
300 | 330 | ||
301 | 331 | ||
302 | return ret_val; | 332 | return ret_val; |
303 | } | 333 | } |
304 | 334 | ||
305 | 335 | } | |
306 | #endif | 336 | #endif |
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index 189bf94..3eb0026 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp | |||
@@ -1,214 +1,242 @@ | |||
1 | 1 | /* | |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
2 | #include <qobject.h> | 29 | #include <qobject.h> |
3 | #include <qshared.h> | 30 | #include <qshared.h> |
4 | 31 | ||
5 | 32 | ||
6 | 33 | ||
7 | #include <qpe/palmtopuidgen.h> | 34 | #include <qpe/palmtopuidgen.h> |
8 | #include <qpe/stringutil.h> | 35 | #include <qpe/stringutil.h> |
9 | #include <qpe/palmtoprecord.h> | 36 | #include <qpe/palmtoprecord.h> |
10 | #include <qpe/stringutil.h> | 37 | #include <qpe/stringutil.h> |
11 | #include <qpe/categories.h> | 38 | #include <qpe/categories.h> |
12 | #include <qpe/categoryselect.h> | 39 | #include <qpe/categoryselect.h> |
13 | 40 | ||
14 | 41 | ||
15 | #include "opimstate.h" | 42 | #include <opie2/opimstate.h> |
16 | #include "orecur.h" | 43 | #include <opie2/orecur.h> |
17 | #include "opimmaintainer.h" | 44 | #include <opie2/opimmaintainer.h> |
18 | #include "opimnotifymanager.h" | 45 | #include <opie2/opimnotifymanager.h> |
19 | #include "opimresolver.h" | 46 | #include <opie2/opimresolver.h> |
20 | 47 | ||
21 | #include "otodo.h" | 48 | #include <opie2/otodo.h> |
22 | 49 | ||
50 | namespace Opie { | ||
23 | 51 | ||
24 | struct OTodo::OTodoData : public QShared { | 52 | struct OTodo::OTodoData : public QShared { |
25 | OTodoData() : QShared() { | 53 | OTodoData() : QShared() { |
26 | recur = 0; | 54 | recur = 0; |
27 | state = 0; | 55 | state = 0; |
28 | maintainer = 0; | 56 | maintainer = 0; |
29 | notifiers = 0; | 57 | notifiers = 0; |
30 | }; | 58 | }; |
31 | ~OTodoData() { | 59 | ~OTodoData() { |
32 | delete recur; | 60 | delete recur; |
33 | delete maintainer; | 61 | delete maintainer; |
34 | delete notifiers; | 62 | delete notifiers; |
35 | } | 63 | } |
36 | 64 | ||
37 | QDate date; | 65 | QDate date; |
38 | bool isCompleted:1; | 66 | bool isCompleted:1; |
39 | bool hasDate:1; | 67 | bool hasDate:1; |
40 | int priority; | 68 | int priority; |
41 | QString desc; | 69 | QString desc; |
42 | QString sum; | 70 | QString sum; |
43 | QMap<QString, QString> extra; | 71 | QMap<QString, QString> extra; |
44 | ushort prog; | 72 | ushort prog; |
45 | OPimState *state; | 73 | OPimState *state; |
46 | ORecur *recur; | 74 | ORecur *recur; |
47 | OPimMaintainer *maintainer; | 75 | OPimMaintainer *maintainer; |
48 | QDate start; | 76 | QDate start; |
49 | QDate completed; | 77 | QDate completed; |
50 | OPimNotifyManager *notifiers; | 78 | OPimNotifyManager *notifiers; |
51 | }; | 79 | }; |
52 | 80 | ||
53 | OTodo::OTodo(const OTodo &event ) | 81 | OTodo::OTodo(const OTodo &event ) |
54 | : OPimRecord( event ), data( event.data ) | 82 | : OPimRecord( event ), data( event.data ) |
55 | { | 83 | { |
56 | data->ref(); | 84 | data->ref(); |
57 | // qWarning("ref up"); | 85 | // qWarning("ref up"); |
58 | } | 86 | } |
59 | OTodo::~OTodo() { | 87 | OTodo::~OTodo() { |
60 | 88 | ||
61 | // qWarning("~OTodo " ); | 89 | // qWarning("~OTodo " ); |
62 | if ( data->deref() ) { | 90 | if ( data->deref() ) { |
63 | // qWarning("OTodo::dereffing"); | 91 | // qWarning("OTodo::dereffing"); |
64 | delete data; | 92 | delete data; |
65 | data = 0l; | 93 | data = 0l; |
66 | } | 94 | } |
67 | } | 95 | } |
68 | OTodo::OTodo(bool completed, int priority, | 96 | OTodo::OTodo(bool completed, int priority, |
69 | const QArray<int> &category, | 97 | const QArray<int> &category, |
70 | const QString& summary, | 98 | const QString& summary, |
71 | const QString &description, | 99 | const QString &description, |
72 | ushort progress, | 100 | ushort progress, |
73 | bool hasDate, QDate date, int uid ) | 101 | bool hasDate, QDate date, int uid ) |
74 | : OPimRecord( uid ) | 102 | : OPimRecord( uid ) |
75 | { | 103 | { |
76 | // qWarning("OTodoData " + summary); | 104 | // qWarning("OTodoData " + summary); |
77 | setCategories( category ); | 105 | setCategories( category ); |
78 | 106 | ||
79 | data = new OTodoData; | 107 | data = new OTodoData; |
80 | 108 | ||
81 | data->date = date; | 109 | data->date = date; |
82 | data->isCompleted = completed; | 110 | data->isCompleted = completed; |
83 | data->hasDate = hasDate; | 111 | data->hasDate = hasDate; |
84 | data->priority = priority; | 112 | data->priority = priority; |
85 | data->sum = summary; | 113 | data->sum = summary; |
86 | data->prog = progress; | 114 | data->prog = progress; |
87 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 115 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
88 | } | 116 | } |
89 | OTodo::OTodo(bool completed, int priority, | 117 | OTodo::OTodo(bool completed, int priority, |
90 | const QStringList &category, | 118 | const QStringList &category, |
91 | const QString& summary, | 119 | const QString& summary, |
92 | const QString &description, | 120 | const QString &description, |
93 | ushort progress, | 121 | ushort progress, |
94 | bool hasDate, QDate date, int uid ) | 122 | bool hasDate, QDate date, int uid ) |
95 | : OPimRecord( uid ) | 123 | : OPimRecord( uid ) |
96 | { | 124 | { |
97 | // qWarning("OTodoData" + summary); | 125 | // qWarning("OTodoData" + summary); |
98 | setCategories( idsFromString( category.join(";") ) ); | 126 | setCategories( idsFromString( category.join(";") ) ); |
99 | 127 | ||
100 | data = new OTodoData; | 128 | data = new OTodoData; |
101 | 129 | ||
102 | data->date = date; | 130 | data->date = date; |
103 | data->isCompleted = completed; | 131 | data->isCompleted = completed; |
104 | data->hasDate = hasDate; | 132 | data->hasDate = hasDate; |
105 | data->priority = priority; | 133 | data->priority = priority; |
106 | data->sum = summary; | 134 | data->sum = summary; |
107 | data->prog = progress; | 135 | data->prog = progress; |
108 | data->desc = Qtopia::simplifyMultiLineSpace(description ); | 136 | data->desc = Qtopia::simplifyMultiLineSpace(description ); |
109 | } | 137 | } |
110 | bool OTodo::match( const QRegExp ®Exp )const | 138 | bool OTodo::match( const QRegExp ®Exp )const |
111 | { | 139 | { |
112 | if( QString::number( data->priority ).find( regExp ) != -1 ){ | 140 | if( QString::number( data->priority ).find( regExp ) != -1 ){ |
113 | setLastHitField( Priority ); | 141 | setLastHitField( Priority ); |
114 | return true; | 142 | return true; |
115 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ | 143 | }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ |
116 | setLastHitField( HasDate ); | 144 | setLastHitField( HasDate ); |
117 | return true; | 145 | return true; |
118 | }else if(data->desc.find( regExp ) != -1 ){ | 146 | }else if(data->desc.find( regExp ) != -1 ){ |
119 | setLastHitField( Description ); | 147 | setLastHitField( Description ); |
120 | return true; | 148 | return true; |
121 | }else if(data->sum.find( regExp ) != -1 ) { | 149 | }else if(data->sum.find( regExp ) != -1 ) { |
122 | setLastHitField( Summary ); | 150 | setLastHitField( Summary ); |
123 | return true; | 151 | return true; |
124 | } | 152 | } |
125 | return false; | 153 | return false; |
126 | } | 154 | } |
127 | bool OTodo::isCompleted() const | 155 | bool OTodo::isCompleted() const |
128 | { | 156 | { |
129 | return data->isCompleted; | 157 | return data->isCompleted; |
130 | } | 158 | } |
131 | bool OTodo::hasDueDate() const | 159 | bool OTodo::hasDueDate() const |
132 | { | 160 | { |
133 | return data->hasDate; | 161 | return data->hasDate; |
134 | } | 162 | } |
135 | bool OTodo::hasStartDate()const { | 163 | bool OTodo::hasStartDate()const { |
136 | return data->start.isValid(); | 164 | return data->start.isValid(); |
137 | } | 165 | } |
138 | bool OTodo::hasCompletedDate()const { | 166 | bool OTodo::hasCompletedDate()const { |
139 | return data->completed.isValid(); | 167 | return data->completed.isValid(); |
140 | } | 168 | } |
141 | int OTodo::priority()const | 169 | int OTodo::priority()const |
142 | { | 170 | { |
143 | return data->priority; | 171 | return data->priority; |
144 | } | 172 | } |
145 | QString OTodo::summary() const | 173 | QString OTodo::summary() const |
146 | { | 174 | { |
147 | return data->sum; | 175 | return data->sum; |
148 | } | 176 | } |
149 | ushort OTodo::progress() const | 177 | ushort OTodo::progress() const |
150 | { | 178 | { |
151 | return data->prog; | 179 | return data->prog; |
152 | } | 180 | } |
153 | QDate OTodo::dueDate()const | 181 | QDate OTodo::dueDate()const |
154 | { | 182 | { |
155 | return data->date; | 183 | return data->date; |
156 | } | 184 | } |
157 | QDate OTodo::startDate()const { | 185 | QDate OTodo::startDate()const { |
158 | return data->start; | 186 | return data->start; |
159 | } | 187 | } |
160 | QDate OTodo::completedDate()const { | 188 | QDate OTodo::completedDate()const { |
161 | return data->completed; | 189 | return data->completed; |
162 | } | 190 | } |
163 | QString OTodo::description()const | 191 | QString OTodo::description()const |
164 | { | 192 | { |
165 | return data->desc; | 193 | return data->desc; |
166 | } | 194 | } |
167 | bool OTodo::hasState() const{ | 195 | bool OTodo::hasState() const{ |
168 | if (!data->state ) return false; | 196 | if (!data->state ) return false; |
169 | return ( data->state->state() != OPimState::Undefined ); | 197 | return ( data->state->state() != OPimState::Undefined ); |
170 | } | 198 | } |
171 | OPimState OTodo::state()const { | 199 | OPimState OTodo::state()const { |
172 | if (!data->state ) { | 200 | if (!data->state ) { |
173 | OPimState state; | 201 | OPimState state; |
174 | return state; | 202 | return state; |
175 | } | 203 | } |
176 | 204 | ||
177 | return (*data->state); | 205 | return (*data->state); |
178 | } | 206 | } |
179 | bool OTodo::hasRecurrence()const { | 207 | bool OTodo::hasRecurrence()const { |
180 | if (!data->recur) return false; | 208 | if (!data->recur) return false; |
181 | return data->recur->doesRecur(); | 209 | return data->recur->doesRecur(); |
182 | } | 210 | } |
183 | ORecur OTodo::recurrence()const { | 211 | ORecur OTodo::recurrence()const { |
184 | if (!data->recur) return ORecur(); | 212 | if (!data->recur) return ORecur(); |
185 | 213 | ||
186 | return (*data->recur); | 214 | return (*data->recur); |
187 | } | 215 | } |
188 | bool OTodo::hasMaintainer()const { | 216 | bool OTodo::hasMaintainer()const { |
189 | if (!data->maintainer) return false; | 217 | if (!data->maintainer) return false; |
190 | 218 | ||
191 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); | 219 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); |
192 | } | 220 | } |
193 | OPimMaintainer OTodo::maintainer()const { | 221 | OPimMaintainer OTodo::maintainer()const { |
194 | if (!data->maintainer) return OPimMaintainer(); | 222 | if (!data->maintainer) return OPimMaintainer(); |
195 | 223 | ||
196 | return (*data->maintainer); | 224 | return (*data->maintainer); |
197 | } | 225 | } |
198 | void OTodo::setCompleted( bool completed ) | 226 | void OTodo::setCompleted( bool completed ) |
199 | { | 227 | { |
200 | changeOrModify(); | 228 | changeOrModify(); |
201 | data->isCompleted = completed; | 229 | data->isCompleted = completed; |
202 | } | 230 | } |
203 | void OTodo::setHasDueDate( bool hasDate ) | 231 | void OTodo::setHasDueDate( bool hasDate ) |
204 | { | 232 | { |
205 | changeOrModify(); | 233 | changeOrModify(); |
206 | data->hasDate = hasDate; | 234 | data->hasDate = hasDate; |
207 | } | 235 | } |
208 | void OTodo::setDescription(const QString &desc ) | 236 | void OTodo::setDescription(const QString &desc ) |
209 | { | 237 | { |
210 | // qWarning( "desc " + desc ); | 238 | // qWarning( "desc " + desc ); |
211 | changeOrModify(); | 239 | changeOrModify(); |
212 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); | 240 | data->desc = Qtopia::simplifyMultiLineSpace(desc ); |
213 | } | 241 | } |
214 | void OTodo::setSummary( const QString& sum ) | 242 | void OTodo::setSummary( const QString& sum ) |
@@ -329,192 +357,194 @@ QString OTodo::toRichText() const | |||
329 | text += "#00FF00"; | 357 | text += "#00FF00"; |
330 | 358 | ||
331 | text += "\">" + dd.toString() + "</font><br>"; | 359 | text += "\">" + dd.toString() + "</font><br>"; |
332 | } | 360 | } |
333 | 361 | ||
334 | // categories | 362 | // categories |
335 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 363 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
336 | text += categoryNames( "Todo List" ).join(", "); | 364 | text += categoryNames( "Todo List" ).join(", "); |
337 | text += "<br>"; | 365 | text += "<br>"; |
338 | 366 | ||
339 | return text; | 367 | return text; |
340 | } | 368 | } |
341 | bool OTodo::hasNotifiers()const { | 369 | bool OTodo::hasNotifiers()const { |
342 | if (!data->notifiers) return false; | 370 | if (!data->notifiers) return false; |
343 | return !data->notifiers->isEmpty(); | 371 | return !data->notifiers->isEmpty(); |
344 | } | 372 | } |
345 | OPimNotifyManager& OTodo::notifiers() { | 373 | OPimNotifyManager& OTodo::notifiers() { |
346 | if (!data->notifiers ) | 374 | if (!data->notifiers ) |
347 | data->notifiers = new OPimNotifyManager; | 375 | data->notifiers = new OPimNotifyManager; |
348 | return (*data->notifiers); | 376 | return (*data->notifiers); |
349 | } | 377 | } |
350 | const OPimNotifyManager& OTodo::notifiers()const{ | 378 | const OPimNotifyManager& OTodo::notifiers()const{ |
351 | if (!data->notifiers ) | 379 | if (!data->notifiers ) |
352 | data->notifiers = new OPimNotifyManager; | 380 | data->notifiers = new OPimNotifyManager; |
353 | 381 | ||
354 | return (*data->notifiers); | 382 | return (*data->notifiers); |
355 | } | 383 | } |
356 | 384 | ||
357 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 385 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
358 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 386 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
359 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 387 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
360 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 388 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
361 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 389 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
362 | return priority() < toDoEvent.priority(); | 390 | return priority() < toDoEvent.priority(); |
363 | }else{ | 391 | }else{ |
364 | return dueDate() < toDoEvent.dueDate(); | 392 | return dueDate() < toDoEvent.dueDate(); |
365 | } | 393 | } |
366 | } | 394 | } |
367 | return false; | 395 | return false; |
368 | } | 396 | } |
369 | bool OTodo::operator<=(const OTodo &toDoEvent )const | 397 | bool OTodo::operator<=(const OTodo &toDoEvent )const |
370 | { | 398 | { |
371 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 399 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
372 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; | 400 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; |
373 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 401 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
374 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 402 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
375 | return priority() <= toDoEvent.priority(); | 403 | return priority() <= toDoEvent.priority(); |
376 | }else{ | 404 | }else{ |
377 | return dueDate() <= toDoEvent.dueDate(); | 405 | return dueDate() <= toDoEvent.dueDate(); |
378 | } | 406 | } |
379 | } | 407 | } |
380 | return true; | 408 | return true; |
381 | } | 409 | } |
382 | bool OTodo::operator>(const OTodo &toDoEvent )const | 410 | bool OTodo::operator>(const OTodo &toDoEvent )const |
383 | { | 411 | { |
384 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; | 412 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; |
385 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 413 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
386 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 414 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
387 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 415 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
388 | return priority() > toDoEvent.priority(); | 416 | return priority() > toDoEvent.priority(); |
389 | }else{ | 417 | }else{ |
390 | return dueDate() > toDoEvent.dueDate(); | 418 | return dueDate() > toDoEvent.dueDate(); |
391 | } | 419 | } |
392 | } | 420 | } |
393 | return false; | 421 | return false; |
394 | } | 422 | } |
395 | bool OTodo::operator>=(const OTodo &toDoEvent )const | 423 | bool OTodo::operator>=(const OTodo &toDoEvent )const |
396 | { | 424 | { |
397 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 425 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
398 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 426 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
399 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 427 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
400 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 428 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
401 | return priority() > toDoEvent.priority(); | 429 | return priority() > toDoEvent.priority(); |
402 | }else{ | 430 | }else{ |
403 | return dueDate() > toDoEvent.dueDate(); | 431 | return dueDate() > toDoEvent.dueDate(); |
404 | } | 432 | } |
405 | } | 433 | } |
406 | return true; | 434 | return true; |
407 | } | 435 | } |
408 | bool OTodo::operator==(const OTodo &toDoEvent )const | 436 | bool OTodo::operator==(const OTodo &toDoEvent )const |
409 | { | 437 | { |
410 | if ( data->priority != toDoEvent.data->priority ) return false; | 438 | if ( data->priority != toDoEvent.data->priority ) return false; |
411 | if ( data->priority != toDoEvent.data->prog ) return false; | 439 | if ( data->priority != toDoEvent.data->prog ) return false; |
412 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 440 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
413 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 441 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
414 | if ( data->date != toDoEvent.data->date ) return false; | 442 | if ( data->date != toDoEvent.data->date ) return false; |
415 | if ( data->sum != toDoEvent.data->sum ) return false; | 443 | if ( data->sum != toDoEvent.data->sum ) return false; |
416 | if ( data->desc != toDoEvent.data->desc ) return false; | 444 | if ( data->desc != toDoEvent.data->desc ) return false; |
417 | if ( data->maintainer != toDoEvent.data->maintainer ) | 445 | if ( data->maintainer != toDoEvent.data->maintainer ) |
418 | return false; | 446 | return false; |
419 | 447 | ||
420 | return OPimRecord::operator==( toDoEvent ); | 448 | return OPimRecord::operator==( toDoEvent ); |
421 | } | 449 | } |
422 | void OTodo::deref() { | 450 | void OTodo::deref() { |
423 | 451 | ||
424 | // qWarning("deref in ToDoEvent"); | 452 | // qWarning("deref in ToDoEvent"); |
425 | if ( data->deref() ) { | 453 | if ( data->deref() ) { |
426 | // qWarning("deleting"); | 454 | // qWarning("deleting"); |
427 | delete data; | 455 | delete data; |
428 | data= 0; | 456 | data= 0; |
429 | } | 457 | } |
430 | } | 458 | } |
431 | OTodo &OTodo::operator=(const OTodo &item ) | 459 | OTodo &OTodo::operator=(const OTodo &item ) |
432 | { | 460 | { |
433 | if ( this == &item ) return *this; | 461 | if ( this == &item ) return *this; |
434 | 462 | ||
435 | OPimRecord::operator=( item ); | 463 | OPimRecord::operator=( item ); |
436 | //qWarning("operator= ref "); | 464 | //qWarning("operator= ref "); |
437 | item.data->ref(); | 465 | item.data->ref(); |
438 | deref(); | 466 | deref(); |
439 | data = item.data; | 467 | data = item.data; |
440 | 468 | ||
441 | return *this; | 469 | return *this; |
442 | } | 470 | } |
443 | 471 | ||
444 | QMap<int, QString> OTodo::toMap() const { | 472 | QMap<int, QString> OTodo::toMap() const { |
445 | QMap<int, QString> map; | 473 | QMap<int, QString> map; |
446 | 474 | ||
447 | map.insert( Uid, QString::number( uid() ) ); | 475 | map.insert( Uid, QString::number( uid() ) ); |
448 | map.insert( Category, idsToString( categories() ) ); | 476 | map.insert( Category, idsToString( categories() ) ); |
449 | map.insert( HasDate, QString::number( data->hasDate ) ); | 477 | map.insert( HasDate, QString::number( data->hasDate ) ); |
450 | map.insert( Completed, QString::number( data->isCompleted ) ); | 478 | map.insert( Completed, QString::number( data->isCompleted ) ); |
451 | map.insert( Description, data->desc ); | 479 | map.insert( Description, data->desc ); |
452 | map.insert( Summary, data->sum ); | 480 | map.insert( Summary, data->sum ); |
453 | map.insert( Priority, QString::number( data->priority ) ); | 481 | map.insert( Priority, QString::number( data->priority ) ); |
454 | map.insert( DateDay, QString::number( data->date.day() ) ); | 482 | map.insert( DateDay, QString::number( data->date.day() ) ); |
455 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 483 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
456 | map.insert( DateYear, QString::number( data->date.year() ) ); | 484 | map.insert( DateYear, QString::number( data->date.year() ) ); |
457 | map.insert( Progress, QString::number( data->prog ) ); | 485 | map.insert( Progress, QString::number( data->prog ) ); |
458 | // map.insert( CrossReference, crossToString() ); | 486 | // map.insert( CrossReference, crossToString() ); |
459 | /* FIXME!!! map.insert( State, ); | 487 | /* FIXME!!! map.insert( State, ); |
460 | map.insert( Recurrence, ); | 488 | map.insert( Recurrence, ); |
461 | map.insert( Reminders, ); | 489 | map.insert( Reminders, ); |
462 | map. | 490 | map. |
463 | */ | 491 | */ |
464 | return map; | 492 | return map; |
465 | } | 493 | } |
466 | 494 | ||
467 | /** | 495 | /** |
468 | * change or modify looks at the ref count and either | 496 | * change or modify looks at the ref count and either |
469 | * creates a new QShared Object or it can modify it | 497 | * creates a new QShared Object or it can modify it |
470 | * right in place | 498 | * right in place |
471 | */ | 499 | */ |
472 | void OTodo::changeOrModify() { | 500 | void OTodo::changeOrModify() { |
473 | if ( data->count != 1 ) { | 501 | if ( data->count != 1 ) { |
474 | qWarning("changeOrModify"); | 502 | qWarning("changeOrModify"); |
475 | data->deref(); | 503 | data->deref(); |
476 | OTodoData* d2 = new OTodoData(); | 504 | OTodoData* d2 = new OTodoData(); |
477 | copy(data, d2 ); | 505 | copy(data, d2 ); |
478 | data = d2; | 506 | data = d2; |
479 | } | 507 | } |
480 | } | 508 | } |
481 | // WATCHOUT | 509 | // WATCHOUT |
482 | /* | 510 | /* |
483 | * if you add something to the Data struct | 511 | * if you add something to the Data struct |
484 | * be sure to copy it here | 512 | * be sure to copy it here |
485 | */ | 513 | */ |
486 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 514 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
487 | dest->date = src->date; | 515 | dest->date = src->date; |
488 | dest->isCompleted = src->isCompleted; | 516 | dest->isCompleted = src->isCompleted; |
489 | dest->hasDate = src->hasDate; | 517 | dest->hasDate = src->hasDate; |
490 | dest->priority = src->priority; | 518 | dest->priority = src->priority; |
491 | dest->desc = src->desc; | 519 | dest->desc = src->desc; |
492 | dest->sum = src->sum; | 520 | dest->sum = src->sum; |
493 | dest->extra = src->extra; | 521 | dest->extra = src->extra; |
494 | dest->prog = src->prog; | 522 | dest->prog = src->prog; |
495 | 523 | ||
496 | if (src->state ) | 524 | if (src->state ) |
497 | dest->state = new OPimState( *src->state ); | 525 | dest->state = new OPimState( *src->state ); |
498 | 526 | ||
499 | if (src->recur ) | 527 | if (src->recur ) |
500 | dest->recur = new ORecur( *src->recur ); | 528 | dest->recur = new ORecur( *src->recur ); |
501 | 529 | ||
502 | if (src->maintainer ) | 530 | if (src->maintainer ) |
503 | dest->maintainer = new OPimMaintainer( *src->maintainer ) | 531 | dest->maintainer = new OPimMaintainer( *src->maintainer ) |
504 | ; | 532 | ; |
505 | dest->start = src->start; | 533 | dest->start = src->start; |
506 | dest->completed = src->completed; | 534 | dest->completed = src->completed; |
507 | 535 | ||
508 | if (src->notifiers ) | 536 | if (src->notifiers ) |
509 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); | 537 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); |
510 | } | 538 | } |
511 | QString OTodo::type() const { | 539 | QString OTodo::type() const { |
512 | return QString::fromLatin1("OTodo"); | 540 | return QString::fromLatin1("OTodo"); |
513 | } | 541 | } |
514 | QString OTodo::recordField(int /*id*/ )const { | 542 | QString OTodo::recordField(int /*id*/ )const { |
515 | return QString::null; | 543 | return QString::null; |
516 | } | 544 | } |
517 | 545 | ||
518 | int OTodo::rtti(){ | 546 | int OTodo::rtti(){ |
519 | return OPimResolver::TodoList; | 547 | return OPimResolver::TodoList; |
520 | } | 548 | } |
549 | |||
550 | } | ||
diff --git a/libopie2/opiepim/otodo.h b/libopie2/opiepim/otodo.h index 6df98b9..61add04 100644 --- a/libopie2/opiepim/otodo.h +++ b/libopie2/opiepim/otodo.h | |||
@@ -1,285 +1,315 @@ | |||
1 | 1 | /* | |
2 | This file is part of the Opie Project | ||
3 | Copyright (C) The Main Author <main-author@whereever.org> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
2 | #ifndef OPIE_TODO_EVENT_H | 29 | #ifndef OPIE_TODO_EVENT_H |
3 | #define OPIE_TODO_EVENT_H | 30 | #define OPIE_TODO_EVENT_H |
4 | 31 | ||
5 | 32 | ||
6 | #include <qarray.h> | 33 | #include <qarray.h> |
7 | #include <qmap.h> | 34 | #include <qmap.h> |
8 | #include <qregexp.h> | 35 | #include <qregexp.h> |
9 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
10 | #include <qdatetime.h> | 37 | #include <qdatetime.h> |
11 | #include <qvaluelist.h> | 38 | #include <qvaluelist.h> |
12 | 39 | ||
13 | #include <qpe/recordfields.h> | 40 | #include <qpe/recordfields.h> |
14 | #include <qpe/palmtopuidgen.h> | 41 | #include <qpe/palmtopuidgen.h> |
15 | 42 | ||
16 | #include <opie/opimrecord.h> | 43 | #include <opie2/opimrecord.h> |
44 | |||
17 | 45 | ||
46 | namespace Opie { | ||
18 | 47 | ||
19 | class OPimState; | 48 | class OPimState; |
20 | class ORecur; | 49 | class ORecur; |
21 | class OPimMaintainer; | 50 | class OPimMaintainer; |
22 | class OPimNotifyManager; | 51 | class OPimNotifyManager; |
23 | class OTodo : public OPimRecord { | 52 | class OTodo : public OPimRecord { |
24 | public: | 53 | public: |
25 | typedef QValueList<OTodo> ValueList; | 54 | typedef QValueList<OTodo> ValueList; |
26 | enum RecordFields { | 55 | enum RecordFields { |
27 | Uid = Qtopia::UID_ID, | 56 | Uid = Qtopia::UID_ID, |
28 | Category = Qtopia::CATEGORY_ID, | 57 | Category = Qtopia::CATEGORY_ID, |
29 | HasDate, | 58 | HasDate, |
30 | Completed, | 59 | Completed, |
31 | Description, | 60 | Description, |
32 | Summary, | 61 | Summary, |
33 | Priority, | 62 | Priority, |
34 | DateDay, | 63 | DateDay, |
35 | DateMonth, | 64 | DateMonth, |
36 | DateYear, | 65 | DateYear, |
37 | Progress, | 66 | Progress, |
38 | CrossReference, | 67 | CrossReference, |
39 | State, | 68 | State, |
40 | Recurrence, | 69 | Recurrence, |
41 | Alarms, | 70 | Alarms, |
42 | Reminders, | 71 | Reminders, |
43 | Notifiers, | 72 | Notifiers, |
44 | Maintainer, | 73 | Maintainer, |
45 | StartDate, | 74 | StartDate, |
46 | CompletedDate | 75 | CompletedDate |
47 | }; | 76 | }; |
48 | public: | 77 | public: |
49 | // priorities from Very low to very high | 78 | // priorities from Very low to very high |
50 | enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; | 79 | enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; |
51 | 80 | ||
52 | /* Constructs a new ToDoEvent | 81 | /* Constructs a new ToDoEvent |
53 | @param completed Is the TodoEvent completed | 82 | @param completed Is the TodoEvent completed |
54 | @param priority What is the priority of this ToDoEvent | 83 | @param priority What is the priority of this ToDoEvent |
55 | @param category Which category does it belong( uid ) | 84 | @param category Which category does it belong( uid ) |
56 | @param summary A small summary of the todo | 85 | @param summary A small summary of the todo |
57 | @param description What is this ToDoEvent about | 86 | @param description What is this ToDoEvent about |
58 | @param hasDate Does this Event got a deadline | 87 | @param hasDate Does this Event got a deadline |
59 | @param date what is the deadline? | 88 | @param date what is the deadline? |
60 | @param uid what is the UUID of this Event | 89 | @param uid what is the UUID of this Event |
61 | **/ | 90 | **/ |
62 | OTodo( bool completed = false, int priority = Normal, | 91 | OTodo( bool completed = false, int priority = Normal, |
63 | const QStringList &category = QStringList(), | 92 | const QStringList &category = QStringList(), |
64 | const QString &summary = QString::null , | 93 | const QString &summary = QString::null , |
65 | const QString &description = QString::null, | 94 | const QString &description = QString::null, |
66 | ushort progress = 0, | 95 | ushort progress = 0, |
67 | bool hasDate = false, QDate date = QDate::currentDate(), | 96 | bool hasDate = false, QDate date = QDate::currentDate(), |
68 | int uid = 0 /*empty*/ ); | 97 | int uid = 0 /*empty*/ ); |
69 | 98 | ||
70 | OTodo( bool completed, int priority, | 99 | OTodo( bool completed, int priority, |
71 | const QArray<int>& category, | 100 | const QArray<int>& category, |
72 | const QString& summary = QString::null, | 101 | const QString& summary = QString::null, |
73 | const QString& description = QString::null, | 102 | const QString& description = QString::null, |
74 | ushort progress = 0, | 103 | ushort progress = 0, |
75 | bool hasDate = false, QDate date = QDate::currentDate(), | 104 | bool hasDate = false, QDate date = QDate::currentDate(), |
76 | int uid = 0 /* empty */ ); | 105 | int uid = 0 /* empty */ ); |
77 | 106 | ||
78 | /** Copy c'tor | 107 | /** Copy c'tor |
79 | * | 108 | * |
80 | */ | 109 | */ |
81 | OTodo(const OTodo & ); | 110 | OTodo(const OTodo & ); |
82 | 111 | ||
83 | /** | 112 | /** |
84 | *destructor | 113 | *destructor |
85 | */ | 114 | */ |
86 | ~OTodo(); | 115 | ~OTodo(); |
87 | 116 | ||
88 | /** | 117 | /** |
89 | * Is this event completed? | 118 | * Is this event completed? |
90 | */ | 119 | */ |
91 | bool isCompleted() const; | 120 | bool isCompleted() const; |
92 | 121 | ||
93 | /** | 122 | /** |
94 | * Does this Event have a deadline | 123 | * Does this Event have a deadline |
95 | */ | 124 | */ |
96 | bool hasDueDate() const; | 125 | bool hasDueDate() const; |
97 | bool hasStartDate()const; | 126 | bool hasStartDate()const; |
98 | bool hasCompletedDate()const; | 127 | bool hasCompletedDate()const; |
99 | 128 | ||
100 | /** | 129 | /** |
101 | * What is the priority? | 130 | * What is the priority? |
102 | */ | 131 | */ |
103 | int priority()const ; | 132 | int priority()const ; |
104 | 133 | ||
105 | /** | 134 | /** |
106 | * progress as ushort 0, 20, 40, 60, 80 or 100% | 135 | * progress as ushort 0, 20, 40, 60, 80 or 100% |
107 | */ | 136 | */ |
108 | ushort progress() const; | 137 | ushort progress() const; |
109 | 138 | ||
110 | /** | 139 | /** |
111 | * The due Date | 140 | * The due Date |
112 | */ | 141 | */ |
113 | QDate dueDate()const; | 142 | QDate dueDate()const; |
114 | 143 | ||
115 | /** | 144 | /** |
116 | * When did it start? | 145 | * When did it start? |
117 | */ | 146 | */ |
118 | QDate startDate()const; | 147 | QDate startDate()const; |
119 | 148 | ||
120 | /** | 149 | /** |
121 | * When was it completed? | 150 | * When was it completed? |
122 | */ | 151 | */ |
123 | QDate completedDate()const; | 152 | QDate completedDate()const; |
124 | 153 | ||
125 | /** | 154 | /** |
126 | * does it have a state? | 155 | * does it have a state? |
127 | */ | 156 | */ |
128 | bool hasState()const; | 157 | bool hasState()const; |
129 | 158 | ||
130 | /** | 159 | /** |
131 | * What is the state of this OTodo? | 160 | * What is the state of this OTodo? |
132 | */ | 161 | */ |
133 | OPimState state()const; | 162 | OPimState state()const; |
134 | 163 | ||
135 | /** | 164 | /** |
136 | * has recurrence? | 165 | * has recurrence? |
137 | */ | 166 | */ |
138 | bool hasRecurrence()const; | 167 | bool hasRecurrence()const; |
139 | 168 | ||
140 | /** | 169 | /** |
141 | * the recurrance of this | 170 | * the recurrance of this |
142 | */ | 171 | */ |
143 | ORecur recurrence()const; | 172 | ORecur recurrence()const; |
144 | 173 | ||
145 | /** | 174 | /** |
146 | * does this OTodo have a maintainer? | 175 | * does this OTodo have a maintainer? |
147 | */ | 176 | */ |
148 | bool hasMaintainer()const; | 177 | bool hasMaintainer()const; |
149 | 178 | ||
150 | /** | 179 | /** |
151 | * the Maintainer of this OTodo | 180 | * the Maintainer of this OTodo |
152 | */ | 181 | */ |
153 | OPimMaintainer maintainer()const; | 182 | OPimMaintainer maintainer()const; |
154 | 183 | ||
155 | /** | 184 | /** |
156 | * The description of the todo | 185 | * The description of the todo |
157 | */ | 186 | */ |
158 | QString description()const; | 187 | QString description()const; |
159 | 188 | ||
160 | /** | 189 | /** |
161 | * A small summary of the todo | 190 | * A small summary of the todo |
162 | */ | 191 | */ |
163 | QString summary() const; | 192 | QString summary() const; |
164 | 193 | ||
165 | /** | 194 | /** |
166 | * @reimplemented | 195 | * @reimplemented |
167 | * Return this todoevent in a RichText formatted QString | 196 | * Return this todoevent in a RichText formatted QString |
168 | */ | 197 | */ |
169 | QString toRichText() const; | 198 | QString toRichText() const; |
170 | 199 | ||
171 | bool hasNotifiers()const; | 200 | bool hasNotifiers()const; |
172 | /* | 201 | /* |
173 | * FIXME check if the sharing is still fine!! -zecke | 202 | * FIXME check if the sharing is still fine!! -zecke |
174 | * ### CHECK If API is fine | 203 | * ### CHECK If API is fine |
175 | */ | 204 | */ |
176 | /** | 205 | /** |
177 | * return a reference to our notifiers... | 206 | * return a reference to our notifiers... |
178 | */ | 207 | */ |
179 | OPimNotifyManager ¬ifiers(); | 208 | OPimNotifyManager ¬ifiers(); |
180 | 209 | ||
181 | /** | 210 | /** |
182 | * | 211 | * |
183 | */ | 212 | */ |
184 | const OPimNotifyManager ¬ifiers()const; | 213 | const OPimNotifyManager ¬ifiers()const; |
185 | 214 | ||
186 | /** | 215 | /** |
187 | * reimplementations | 216 | * reimplementations |
188 | */ | 217 | */ |
189 | QString type()const; | 218 | QString type()const; |
190 | QString toShortText()const; | 219 | QString toShortText()const; |
191 | QString recordField(int id )const; | 220 | QString recordField(int id )const; |
192 | 221 | ||
193 | /** | 222 | /** |
194 | * toMap puts all data into the map. int relates | 223 | * toMap puts all data into the map. int relates |
195 | * to ToDoEvent RecordFields enum | 224 | * to ToDoEvent RecordFields enum |
196 | */ | 225 | */ |
197 | QMap<int, QString> toMap()const; | 226 | QMap<int, QString> toMap()const; |
198 | 227 | ||
199 | /** | 228 | /** |
200 | * Set if this Todo is completed | 229 | * Set if this Todo is completed |
201 | */ | 230 | */ |
202 | void setCompleted(bool completed ); | 231 | void setCompleted(bool completed ); |
203 | 232 | ||
204 | /** | 233 | /** |
205 | * set if this todo got an end data | 234 | * set if this todo got an end data |
206 | */ | 235 | */ |
207 | void setHasDueDate( bool hasDate ); | 236 | void setHasDueDate( bool hasDate ); |
208 | // FIXME we do not have these for start, completed | 237 | // FIXME we do not have these for start, completed |
209 | // cause we'll use the isNull() of QDate for figuring | 238 | // cause we'll use the isNull() of QDate for figuring |
210 | // out if it's has a date... | 239 | // out if it's has a date... |
211 | // decide what to do here? -zecke | 240 | // decide what to do here? -zecke |
212 | 241 | ||
213 | /** | 242 | /** |
214 | * Set the priority of the Todo | 243 | * Set the priority of the Todo |
215 | */ | 244 | */ |
216 | void setPriority(int priority ); | 245 | void setPriority(int priority ); |
217 | 246 | ||
218 | /** | 247 | /** |
219 | * Set the progress. | 248 | * Set the progress. |
220 | */ | 249 | */ |
221 | void setProgress( ushort progress ); | 250 | void setProgress( ushort progress ); |
222 | 251 | ||
223 | /** | 252 | /** |
224 | * set the end date | 253 | * set the end date |
225 | */ | 254 | */ |
226 | void setDueDate( const QDate& date ); | 255 | void setDueDate( const QDate& date ); |
227 | 256 | ||
228 | /** | 257 | /** |
229 | * set the start date | 258 | * set the start date |
230 | */ | 259 | */ |
231 | void setStartDate( const QDate& date ); | 260 | void setStartDate( const QDate& date ); |
232 | 261 | ||
233 | /** | 262 | /** |
234 | * set the completed date | 263 | * set the completed date |
235 | */ | 264 | */ |
236 | void setCompletedDate( const QDate& date ); | 265 | void setCompletedDate( const QDate& date ); |
237 | 266 | ||
238 | void setRecurrence( const ORecur& ); | 267 | void setRecurrence( const ORecur& ); |
239 | 268 | ||
240 | void setDescription(const QString& ); | 269 | void setDescription(const QString& ); |
241 | void setSummary(const QString& ); | 270 | void setSummary(const QString& ); |
242 | 271 | ||
243 | /** | 272 | /** |
244 | * set the state of a Todo | 273 | * set the state of a Todo |
245 | * @param state State what the todo should take | 274 | * @param state State what the todo should take |
246 | */ | 275 | */ |
247 | void setState( const OPimState& state); | 276 | void setState( const OPimState& state); |
248 | 277 | ||
249 | /** | 278 | /** |
250 | * set the Maintainer Mode | 279 | * set the Maintainer Mode |
251 | */ | 280 | */ |
252 | void setMaintainer( const OPimMaintainer& ); | 281 | void setMaintainer( const OPimMaintainer& ); |
253 | 282 | ||
254 | bool isOverdue(); | 283 | bool isOverdue(); |
255 | 284 | ||
256 | 285 | ||
257 | virtual bool match( const QRegExp &r )const; | 286 | virtual bool match( const QRegExp &r )const; |
258 | 287 | ||
259 | bool operator<(const OTodo &toDoEvent )const; | 288 | bool operator<(const OTodo &toDoEvent )const; |
260 | bool operator<=(const OTodo &toDoEvent )const; | 289 | bool operator<=(const OTodo &toDoEvent )const; |
261 | bool operator!=(const OTodo &toDoEvent )const; | 290 | bool operator!=(const OTodo &toDoEvent )const; |
262 | bool operator>(const OTodo &toDoEvent )const; | 291 | bool operator>(const OTodo &toDoEvent )const; |
263 | bool operator>=(const OTodo &toDoEvent)const; | 292 | bool operator>=(const OTodo &toDoEvent)const; |
264 | bool operator==(const OTodo &toDoEvent )const; | 293 | bool operator==(const OTodo &toDoEvent )const; |
265 | OTodo &operator=(const OTodo &toDoEvent ); | 294 | OTodo &operator=(const OTodo &toDoEvent ); |
266 | 295 | ||
267 | static int rtti(); | 296 | static int rtti(); |
268 | 297 | ||
269 | private: | 298 | private: |
270 | class OTodoPrivate; | 299 | class OTodoPrivate; |
271 | struct OTodoData; | 300 | struct OTodoData; |
272 | 301 | ||
273 | void deref(); | 302 | void deref(); |
274 | inline void changeOrModify(); | 303 | inline void changeOrModify(); |
275 | void copy( OTodoData* src, OTodoData* dest ); | 304 | void copy( OTodoData* src, OTodoData* dest ); |
276 | OTodoPrivate *d; | 305 | OTodoPrivate *d; |
277 | OTodoData *data; | 306 | OTodoData *data; |
278 | 307 | ||
279 | }; | 308 | }; |
280 | inline bool OTodo::operator!=(const OTodo &toDoEvent )const { | 309 | inline bool OTodo::operator!=(const OTodo &toDoEvent )const { |
281 | return !(*this == toDoEvent); | 310 | return !(*this == toDoEvent); |
282 | } | 311 | } |
283 | 312 | ||
313 | } | ||
284 | 314 | ||
285 | #endif | 315 | #endif |
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp index 2739e26..10ed743 100644 --- a/libopie2/opiepim/ui/opimmainwindow.cpp +++ b/libopie2/opiepim/ui/opimmainwindow.cpp | |||
@@ -1,150 +1,181 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qapplication.h> | 29 | #include <qapplication.h> |
2 | #include <qdatetime.h> | 30 | #include <qdatetime.h> |
3 | #include <qcopchannel_qws.h> | 31 | #include <qcopchannel_qws.h> |
4 | 32 | ||
5 | #include <qpe/sound.h> | 33 | #include <qpe/sound.h> |
6 | #include <qpe/qcopenvelope_qws.h> | 34 | #include <qpe/qcopenvelope_qws.h> |
7 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
8 | 36 | ||
9 | #include "opimresolver.h" | 37 | #include <opie2/opimresolver.h> |
10 | #include "opimmainwindow.h" | 38 | #include "opimmainwindow.h" |
11 | 39 | ||
40 | namespace Opie { | ||
12 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | 41 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, |
13 | const char* name, WFlags flag ) | 42 | const char* name, WFlags flag ) |
14 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { | 43 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { |
15 | 44 | ||
16 | /* | 45 | /* |
17 | * let's generate our QCopChannel | 46 | * let's generate our QCopChannel |
18 | */ | 47 | */ |
19 | m_str = QString("QPE/"+m_service).local8Bit(); | 48 | m_str = QString("QPE/"+m_service).local8Bit(); |
20 | m_channel= new QCopChannel(m_str, this ); | 49 | m_channel= new QCopChannel(m_str, this ); |
21 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), | 50 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), |
22 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 51 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
23 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), | 52 | connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), |
24 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 53 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
25 | 54 | ||
26 | /* connect flush and reload */ | 55 | /* connect flush and reload */ |
27 | connect(qApp, SIGNAL(flush() ), | 56 | connect(qApp, SIGNAL(flush() ), |
28 | this, SLOT(flush() ) ); | 57 | this, SLOT(flush() ) ); |
29 | connect(qApp, SIGNAL(reload() ), | 58 | connect(qApp, SIGNAL(reload() ), |
30 | this, SLOT(reload() ) ); | 59 | this, SLOT(reload() ) ); |
31 | } | 60 | } |
32 | OPimMainWindow::~OPimMainWindow() { | 61 | OPimMainWindow::~OPimMainWindow() { |
33 | delete m_channel; | 62 | delete m_channel; |
34 | } | 63 | } |
35 | QCopChannel* OPimMainWindow::channel() { | 64 | QCopChannel* OPimMainWindow::channel() { |
36 | return m_channel; | 65 | return m_channel; |
37 | } | 66 | } |
38 | void OPimMainWindow::doSetDocument( const QString& ) { | 67 | void OPimMainWindow::doSetDocument( const QString& ) { |
39 | 68 | ||
40 | } | 69 | } |
41 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { | 70 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { |
42 | bool needShow = false; | 71 | bool needShow = false; |
43 | /* | 72 | /* |
44 | * create demands to create | 73 | * create demands to create |
45 | * a new record... | 74 | * a new record... |
46 | */ | 75 | */ |
47 | QDataStream stream(array, IO_ReadOnly); | 76 | QDataStream stream(array, IO_ReadOnly); |
48 | if ( cmd == "create()" ) { | 77 | if ( cmd == "create()" ) { |
49 | raise(); | 78 | raise(); |
50 | int uid = create(); | 79 | int uid = create(); |
51 | QCopEnvelope e(m_str, "created(int)" ); | 80 | QCopEnvelope e(m_str, "created(int)" ); |
52 | e << uid; | 81 | e << uid; |
53 | needShow = true; | 82 | needShow = true; |
54 | }else if ( cmd == "remove(int)" ) { | 83 | }else if ( cmd == "remove(int)" ) { |
55 | int uid; | 84 | int uid; |
56 | stream >> uid; | 85 | stream >> uid; |
57 | bool rem = remove( uid ); | 86 | bool rem = remove( uid ); |
58 | QCopEnvelope e(m_str, "removed(bool)" ); | 87 | QCopEnvelope e(m_str, "removed(bool)" ); |
59 | e << rem; | 88 | e << rem; |
60 | needShow = true; | 89 | needShow = true; |
61 | }else if ( cmd == "beam(int)" ) { | 90 | }else if ( cmd == "beam(int)" ) { |
62 | int uid; | 91 | int uid; |
63 | stream >> uid; | 92 | stream >> uid; |
64 | beam( uid); | 93 | beam( uid); |
65 | }else if ( cmd == "show(int)" ) { | 94 | }else if ( cmd == "show(int)" ) { |
66 | raise(); | 95 | raise(); |
67 | int uid; | 96 | int uid; |
68 | stream >> uid; | 97 | stream >> uid; |
69 | show( uid ); | 98 | show( uid ); |
70 | needShow = true; | 99 | needShow = true; |
71 | }else if ( cmd == "edit(int)" ) { | 100 | }else if ( cmd == "edit(int)" ) { |
72 | raise(); | 101 | raise(); |
73 | int uid; | 102 | int uid; |
74 | stream >> uid; | 103 | stream >> uid; |
75 | edit( uid ); | 104 | edit( uid ); |
76 | }else if ( cmd == "add(int,QByteArray)" ) { | 105 | }else if ( cmd == "add(int,QByteArray)" ) { |
77 | int rtti; | 106 | int rtti; |
78 | QByteArray array; | 107 | QByteArray array; |
79 | stream >> rtti; | 108 | stream >> rtti; |
80 | stream >> array; | 109 | stream >> array; |
81 | m_fallBack = record(rtti, array ); | 110 | m_fallBack = record(rtti, array ); |
82 | if (!m_fallBack) return; | 111 | if (!m_fallBack) return; |
83 | add( *m_fallBack ); | 112 | add( *m_fallBack ); |
84 | delete m_fallBack; | 113 | delete m_fallBack; |
85 | }else if ( cmd == "alarm(QDateTime,int)" ) { | 114 | }else if ( cmd == "alarm(QDateTime,int)" ) { |
86 | raise(); | 115 | raise(); |
87 | QDateTime dt; int uid; | 116 | QDateTime dt; int uid; |
88 | stream >> dt; | 117 | stream >> dt; |
89 | stream >> uid; | 118 | stream >> uid; |
90 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); | 119 | qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); |
91 | QDateTime current = QDateTime::currentDateTime(); | 120 | QDateTime current = QDateTime::currentDateTime(); |
92 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) | 121 | if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) |
93 | return; | 122 | return; |
94 | doAlarm( dt, uid ); | 123 | doAlarm( dt, uid ); |
95 | needShow = true; | 124 | needShow = true; |
96 | } | 125 | } |
97 | 126 | ||
98 | if (needShow ) | 127 | if (needShow ) |
99 | QPEApplication::setKeepRunning(); | 128 | QPEApplication::setKeepRunning(); |
100 | } | 129 | } |
101 | /* implement the url scripting here */ | 130 | /* implement the url scripting here */ |
102 | void OPimMainWindow::setDocument( const QString& str) { | 131 | void OPimMainWindow::setDocument( const QString& str) { |
103 | doSetDocument( str ); | 132 | doSetDocument( str ); |
104 | } | 133 | } |
105 | /* | 134 | /* |
106 | * we now try to get the array demarshalled | 135 | * we now try to get the array demarshalled |
107 | * check if the rtti matches this one | 136 | * check if the rtti matches this one |
108 | */ | 137 | */ |
109 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { | 138 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { |
110 | if ( service() != rtti ) | 139 | if ( service() != rtti ) |
111 | return 0l; | 140 | return 0l; |
112 | 141 | ||
113 | OPimRecord* record = OPimResolver::self()->record( rtti ); | 142 | OPimRecord* record = OPimResolver::self()->record( rtti ); |
114 | QDataStream str(array, IO_ReadOnly ); | 143 | QDataStream str(array, IO_ReadOnly ); |
115 | if ( !record || !record->loadFromStream(str) ) { | 144 | if ( !record || !record->loadFromStream(str) ) { |
116 | delete record; | 145 | delete record; |
117 | record = 0l; | 146 | record = 0l; |
118 | } | 147 | } |
119 | 148 | ||
120 | return record; | 149 | return record; |
121 | } | 150 | } |
122 | /* | 151 | /* |
123 | * get the rtti for the service | 152 | * get the rtti for the service |
124 | */ | 153 | */ |
125 | int OPimMainWindow::service() { | 154 | int OPimMainWindow::service() { |
126 | if ( m_rtti == -1 ) | 155 | if ( m_rtti == -1 ) |
127 | m_rtti = OPimResolver::self()->serviceId( m_service ); | 156 | m_rtti = OPimResolver::self()->serviceId( m_service ); |
128 | 157 | ||
129 | return m_rtti; | 158 | return m_rtti; |
130 | } | 159 | } |
131 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { | 160 | void OPimMainWindow::doAlarm( const QDateTime&, int ) { |
132 | 161 | ||
133 | } | 162 | } |
134 | void OPimMainWindow::startAlarm(int count ) { | 163 | void OPimMainWindow::startAlarm(int count ) { |
135 | m_alarmCount = count; | 164 | m_alarmCount = count; |
136 | m_playedCount = 0; | 165 | m_playedCount = 0; |
137 | Sound::soundAlarm(); | 166 | Sound::soundAlarm(); |
138 | m_timerId = startTimer( 5000 ); | 167 | m_timerId = startTimer( 5000 ); |
139 | } | 168 | } |
140 | void OPimMainWindow::killAlarm() { | 169 | void OPimMainWindow::killAlarm() { |
141 | killTimer( m_timerId ); | 170 | killTimer( m_timerId ); |
142 | } | 171 | } |
143 | void OPimMainWindow::timerEvent( QTimerEvent* e) { | 172 | void OPimMainWindow::timerEvent( QTimerEvent* e) { |
144 | if ( m_playedCount <m_alarmCount ) { | 173 | if ( m_playedCount <m_alarmCount ) { |
145 | m_playedCount++; | 174 | m_playedCount++; |
146 | Sound::soundAlarm(); | 175 | Sound::soundAlarm(); |
147 | }else { | 176 | }else { |
148 | killTimer( e->timerId() ); | 177 | killTimer( e->timerId() ); |
149 | } | 178 | } |
150 | } | 179 | } |
180 | |||
181 | } | ||
diff --git a/libopie2/opiepim/ui/opimmainwindow.h b/libopie2/opiepim/ui/opimmainwindow.h index 855d364..abad630 100644 --- a/libopie2/opiepim/ui/opimmainwindow.h +++ b/libopie2/opiepim/ui/opimmainwindow.h | |||
@@ -1,99 +1,129 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #ifndef OPIE_PIM_MAINWINDOW_H | 29 | #ifndef OPIE_PIM_MAINWINDOW_H |
2 | #define OPIE_PIM_MAINWINDOW_H | 30 | #define OPIE_PIM_MAINWINDOW_H |
3 | 31 | ||
4 | #include <qmainwindow.h> | 32 | #include <qmainwindow.h> |
5 | 33 | ||
6 | #include <opie/opimrecord.h> | 34 | #include <opie2/opimrecord.h> |
35 | class QCopChannel; | ||
36 | class QDateTime; | ||
7 | 37 | ||
38 | namespace Opie { | ||
8 | /** | 39 | /** |
9 | * This is a common Opie PIM MainWindow | 40 | * This is a common Opie PIM MainWindow |
10 | * it takes care of the QCOP internals | 41 | * it takes care of the QCOP internals |
11 | * and implements some functions | 42 | * and implements some functions |
12 | * for the URL scripting schema | 43 | * for the URL scripting schema |
13 | */ | 44 | */ |
14 | /* | 45 | /* |
15 | * due Qt and Templates with signal and slots | 46 | * due Qt and Templates with signal and slots |
16 | * do not work that good :( | 47 | * do not work that good :( |
17 | * (Ok how to moc a template ;) ) | 48 | * (Ok how to moc a template ;) ) |
18 | * We will have the mainwindow which calls a struct which | 49 | * We will have the mainwindow which calls a struct which |
19 | * is normally reimplemented as a template ;) | 50 | * is normally reimplemented as a template ;) |
20 | */ | 51 | */ |
21 | 52 | ||
22 | class QCopChannel; | ||
23 | class QDateTime; | ||
24 | class OPimMainWindow : public QMainWindow { | 53 | class OPimMainWindow : public QMainWindow { |
25 | Q_OBJECT | 54 | Q_OBJECT |
26 | public: | 55 | public: |
27 | enum TransPort { BlueTooth=0, | 56 | enum TransPort { BlueTooth=0, |
28 | IrDa }; | 57 | IrDa }; |
29 | 58 | ||
30 | OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, | 59 | OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, |
31 | WFlags f = WType_TopLevel); | 60 | WFlags f = WType_TopLevel); |
32 | virtual ~OPimMainWindow(); | 61 | virtual ~OPimMainWindow(); |
33 | 62 | ||
34 | 63 | ||
35 | protected slots: | 64 | protected slots: |
36 | /* | 65 | /* |
37 | * called when a setDocument | 66 | * called when a setDocument |
38 | * couldn't be handled by this window | 67 | * couldn't be handled by this window |
39 | */ | 68 | */ |
40 | virtual void doSetDocument( const QString& ); | 69 | virtual void doSetDocument( const QString& ); |
41 | /* for syncing */ | 70 | /* for syncing */ |
42 | virtual void flush() = 0; | 71 | virtual void flush() = 0; |
43 | virtual void reload() = 0; | 72 | virtual void reload() = 0; |
44 | 73 | ||
45 | /** create a new Records and return the uid */ | 74 | /** create a new Records and return the uid */ |
46 | virtual int create() = 0; | 75 | virtual int create() = 0; |
47 | /** remove a record with UID == uid */ | 76 | /** remove a record with UID == uid */ |
48 | virtual bool remove( int uid ) = 0; | 77 | virtual bool remove( int uid ) = 0; |
49 | /** beam the record with UID = uid */ | 78 | /** beam the record with UID = uid */ |
50 | virtual void beam( int uid ) = 0; | 79 | virtual void beam( int uid ) = 0; |
51 | 80 | ||
52 | /** show the record with UID == uid */ | 81 | /** show the record with UID == uid */ |
53 | virtual void show( int uid ) = 0; | 82 | virtual void show( int uid ) = 0; |
54 | /** edit the record */ | 83 | /** edit the record */ |
55 | virtual void edit( int uid ) = 0; | 84 | virtual void edit( int uid ) = 0; |
56 | 85 | ||
57 | /** make a copy of it! */ | 86 | /** make a copy of it! */ |
58 | virtual void add( const OPimRecord& ) = 0; | 87 | virtual void add( const OPimRecord& ) = 0; |
59 | 88 | ||
60 | virtual void doAlarm( const QDateTime&, int uid ); | 89 | virtual void doAlarm( const QDateTime&, int uid ); |
61 | 90 | ||
62 | QCopChannel* channel(); | 91 | QCopChannel* channel(); |
63 | 92 | ||
64 | protected: | 93 | protected: |
65 | /** | 94 | /** |
66 | * start to play soundAlarm() | 95 | * start to play soundAlarm() |
67 | * @param count How many times the alarm is played | 96 | * @param count How many times the alarm is played |
68 | */ | 97 | */ |
69 | void startAlarm(int count = 10); | 98 | void startAlarm(int count = 10); |
70 | void killAlarm(); | 99 | void killAlarm(); |
71 | void timerEvent( QTimerEvent* ); | 100 | void timerEvent( QTimerEvent* ); |
72 | 101 | ||
73 | private slots: | 102 | private slots: |
74 | void appMessage( const QCString&, const QByteArray& ); | 103 | void appMessage( const QCString&, const QByteArray& ); |
75 | void setDocument( const QString& ); | 104 | void setDocument( const QString& ); |
76 | 105 | ||
77 | 106 | ||
78 | private: | 107 | private: |
79 | class Private; | 108 | class Private; |
80 | Private* d; | 109 | Private* d; |
81 | 110 | ||
82 | int m_rtti; | 111 | int m_rtti; |
83 | QCopChannel* m_channel; | 112 | QCopChannel* m_channel; |
84 | QString m_service; | 113 | QString m_service; |
85 | QCString m_str; | 114 | QCString m_str; |
86 | OPimRecord* m_fallBack; | 115 | OPimRecord* m_fallBack; |
87 | int m_alarmCount; | 116 | int m_alarmCount; |
88 | int m_playedCount; | 117 | int m_playedCount; |
89 | int m_timerId; | 118 | int m_timerId; |
90 | /* I would love to do this as a template | 119 | /* I would love to do this as a template |
91 | * but can't think of a right way | 120 | * but can't think of a right way |
92 | * because I need signal and slots -zecke | 121 | * because I need signal and slots -zecke |
93 | */ | 122 | */ |
94 | virtual OPimRecord* record( int rtti, const QByteArray& ) ; | 123 | virtual OPimRecord* record( int rtti, const QByteArray& ) ; |
95 | int service(); | 124 | int service(); |
96 | }; | 125 | }; |
97 | 126 | ||
127 | } | ||
98 | 128 | ||
99 | #endif | 129 | #endif |
diff --git a/libopie2/opiepim/ui/ui.pro b/libopie2/opiepim/ui/ui.pro new file mode 100644 index 0000000..db19bca --- a/dev/null +++ b/libopie2/opiepim/ui/ui.pro | |||
@@ -0,0 +1,3 @@ | |||
1 | HEADERS += ui/opimmainwindow.h | ||
2 | |||
3 | SOURCES += ui/opimmainwindow.cpp | ||