summaryrefslogtreecommitdiff
path: root/libopie2
authoralwin <alwin>2004-02-20 02:06:52 (UTC)
committer alwin <alwin>2004-02-20 02:06:52 (UTC)
commit55f4d502486e01927356908223622e435c975f7e (patch) (unidiff)
tree824b5c1e8992564677c4f39473bc108a32a2cf2a /libopie2
parent060b4fc7a3fd5c1b5f745167fe084f7486719b7e (diff)
downloadopie-55f4d502486e01927356908223622e435c975f7e.zip
opie-55f4d502486e01927356908223622e435c975f7e.tar.gz
opie-55f4d502486e01927356908223622e435c975f7e.tar.bz2
moved the opie pim stuff to libopie2 - pim. Tried to resort them, may be someone should take a look for a better file order. but now all applications can start using libopiepim2 instead of libopie1-pim-stuff.
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/backends.pro31
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h118
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend.h82
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp77
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.h62
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp125
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.h77
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp135
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.h118
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp38
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.h35
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp67
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.h33
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp41
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.h33
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h36
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.cpp33
-rw-r--r--libopie2/opiepim/backend/otodoaccessbackend.h35
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp41
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h34
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp35
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.h34
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp45
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h33
-rw-r--r--libopie2/opiepim/core/core.pro21
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp80
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h105
-rw-r--r--libopie2/opiepim/core/oconversion.cpp47
-rw-r--r--libopie2/opiepim/core/oconversion.h50
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp35
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h33
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h43
-rw-r--r--libopie2/opiepim/core/opimcache.h33
-rw-r--r--libopie2/opiepim/core/opimmaintainer.cpp34
-rw-r--r--libopie2/opiepim/core/opimmaintainer.h31
-rw-r--r--libopie2/opiepim/core/opimnotify.cpp33
-rw-r--r--libopie2/opiepim/core/opimnotify.h32
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp37
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.h33
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp33
-rw-r--r--libopie2/opiepim/core/opimrecord.h33
-rw-r--r--libopie2/opiepim/core/opimresolver.cpp38
-rw-r--r--libopie2/opiepim/core/opimresolver.h33
-rw-r--r--libopie2/opiepim/core/opimstate.cpp31
-rw-r--r--libopie2/opiepim/core/opimstate.h31
-rw-r--r--libopie2/opiepim/core/opimxref.cpp34
-rw-r--r--libopie2/opiepim/core/opimxref.h34
-rw-r--r--libopie2/opiepim/core/opimxrefmanager.cpp33
-rw-r--r--libopie2/opiepim/core/opimxrefmanager.h33
-rw-r--r--libopie2/opiepim/core/opimxrefpartner.cpp34
-rw-r--r--libopie2/opiepim/core/opimxrefpartner.h30
-rw-r--r--libopie2/opiepim/core/orecur.cpp36
-rw-r--r--libopie2/opiepim/core/orecur.h31
-rw-r--r--libopie2/opiepim/core/otemplatebase.h33
-rw-r--r--libopie2/opiepim/core/otimezone.cpp37
-rw-r--r--libopie2/opiepim/core/otimezone.h33
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp37
-rw-r--r--libopie2/opiepim/core/otodoaccess.h37
-rw-r--r--libopie2/opiepim/ocontact.cpp37
-rw-r--r--libopie2/opiepim/ocontact.h51
-rw-r--r--libopie2/opiepim/ocontactfields.cpp35
-rw-r--r--libopie2/opiepim/ocontactfields.h33
-rw-r--r--libopie2/opiepim/oevent.cpp40
-rw-r--r--libopie2/opiepim/oevent.h36
-rw-r--r--libopie2/opiepim/opiepim.pro10
-rw-r--r--libopie2/opiepim/orecordlist.h36
-rw-r--r--libopie2/opiepim/otodo.cpp44
-rw-r--r--libopie2/opiepim/otodo.h34
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.cpp33
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.h36
-rw-r--r--libopie2/opiepim/ui/ui.pro3
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 @@
1SOURCES += 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
15HEADERS += 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
51namespace Opie {
52
98class OBackendPrivate; 53class 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 */
115template<class T> 70template<class T>
116class OBackendFactory 71class 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
47namespace 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 */
75class OContactAccessBackend: public OPimAccessBackend<OContact> { 58class 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
124private: 107private:
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,180 +1,169 @@
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 */
84namespace { 73namespace 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.
@@ -375,192 +364,194 @@ namespace {
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
460namespace Opie {
461
471OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, 462OContactAccessBackend_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
495OContactAccessBackend_SQL::~OContactAccessBackend_SQL () 486OContactAccessBackend_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
501bool OContactAccessBackend_SQL::load () 492bool 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
518bool OContactAccessBackend_SQL::reload() 509bool OContactAccessBackend_SQL::reload()
519{ 510{
520 return load(); 511 return load();
521} 512}
522 513
523bool OContactAccessBackend_SQL::save() 514bool 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
529void OContactAccessBackend_SQL::clear () 520void 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
537bool OContactAccessBackend_SQL::wasChangedExternally() 528bool OContactAccessBackend_SQL::wasChangedExternally()
538{ 529{
539 return false; 530 return false;
540} 531}
541 532
542QArray<int> OContactAccessBackend_SQL::allRecords() const 533QArray<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
553bool OContactAccessBackend_SQL::add ( const OContact &newcontact ) 544bool 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}
@@ -847,96 +838,98 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
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
855QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const 846QMap<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
918QMap<QString, QString> OContactAccessBackend_SQL::requestCustom( int uid ) const 909QMap<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 */
39class OSQLDriver; 43class OSQLDriver;
40class OSQLResult; 44class OSQLResult;
41class OSQLResultItem; 45class OSQLResultItem;
42 46
47namespace 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 */
49class OContactAccessBackend_SQL : public OContactAccessBackend { 55class 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,194 +1,137 @@
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
40namespace Opie {
41
99OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): 42OContactAccessBackend_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
107bool OContactAccessBackend_VCard::load () 50bool 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}
145bool OContactAccessBackend_VCard::reload() 88bool OContactAccessBackend_VCard::reload()
146{ 89{
147 return load(); 90 return load();
148} 91}
149bool OContactAccessBackend_VCard::save() 92bool 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}
176void OContactAccessBackend_VCard::clear () 119void 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
182bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) 125bool 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
189bool OContactAccessBackend_VCard::remove ( int uid ) 132bool 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}
@@ -551,96 +494,98 @@ VObject* OContactAccessBackend_VCard::createVObject( const OContact &c )
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
593QString OContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const 536QString 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
607QDate OContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) 550QDate 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
632VObject* OContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) 575VObject* 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
640VObject* OContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) 583VObject* 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
53class VObject; 39class VObject;
54 40
41namespace 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 */
60class OContactAccessBackend_VCard : public OContactAccessBackend { 47class 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
83private: 70private:
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,222 +1,152 @@
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
124using namespace Opie; 53using namespace Opie;
125 54
126 55
56namespace Opie {
127OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): 57OContactAccessBackend_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
151bool OContactAccessBackend_XML::save() 81bool 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
221bool OContactAccessBackend_XML::load () 151bool OContactAccessBackend_XML::load ()
222{ 152{
@@ -725,96 +655,97 @@ bool OContactAccessBackend_XML::load( const QString filename, bool isJournal )
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
786void OContactAccessBackend_XML::updateJournal( const OContact& cnt, 716void 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
814void OContactAccessBackend_XML::removeJournal() 744void 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
42namespace 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 */
103class OContactAccessBackend_XML : public OContactAccessBackend { 49class 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
35using namespace Opie;
6 36
7namespace { 37namespace {
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
152namespace Opie {
153
122ODateBookAccessBackend::ODateBookAccessBackend() 154ODateBookAccessBackend::ODateBookAccessBackend()
123 : OPimAccessBackend<OEvent>() 155 : OPimAccessBackend<OEvent>()
124{ 156{
125 157
126} 158}
127ODateBookAccessBackend::~ODateBookAccessBackend() { 159ODateBookAccessBackend::~ODateBookAccessBackend() {
128 160
129} 161}
130OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from, 162OEffectiveEvent::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}
143OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) { 175OEffectiveEvent::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
158OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, 190OEffectiveEvent::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
169OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { 201OEffectiveEvent::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
37namespace 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 */
14class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { 43class ODateBookAccessBackend : public OPimAccessBackend<OEvent> {
15public: 44public:
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
84private: 113private:
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,148 +1,145 @@
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
49namespace Opie {
53 50
54 51
55ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 52ODateBookAccessBackend_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
71ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { 68ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() {
72 if( m_driver ) 69 if( m_driver )
73 delete m_driver; 70 delete m_driver;
74} 71}
75 72
76void ODateBookAccessBackend_SQL::initFields() 73void 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
111bool ODateBookAccessBackend_SQL::load() 108bool 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
141void ODateBookAccessBackend_SQL::update() 138void 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();
@@ -272,96 +269,98 @@ bool ODateBookAccessBackend_SQL::remove( int uid )
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
278bool ODateBookAccessBackend_SQL::replace( const OEvent& ev ) 275bool 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
284QArray<int> ODateBookAccessBackend_SQL::rawEvents()const 281QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
285{ 282{
286 return allRecords(); 283 return allRecords();
287} 284}
288 285
289QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 286QArray<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
302QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const 299QArray<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
315OEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() 312OEvent::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}
327OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() 324OEvent::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
340QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 337QArray<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
348QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const 345QArray<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
9class OSQLDriver; 37class OSQLDriver;
10 38
39namespace 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 */
17class ODateBookAccessBackend_SQL : public ODateBookAccessBackend { 46class ODateBookAccessBackend_SQL : public ODateBookAccessBackend {
18public: 47public:
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
43private: 72private:
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,264 +1,295 @@
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
53using namespace Opie;
24 54
25namespace { 55namespace {
26 // FROM TT again 56 // FROM TT again
27char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 57char *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
52namespace { 82namespace {
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
199namespace Opie {
169ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , 200ODateBookAccessBackend_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}
175ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { 206ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() {
176} 207}
177bool ODateBookAccessBackend_XML::load() { 208bool ODateBookAccessBackend_XML::load() {
178 return loadFile(); 209 return loadFile();
179} 210}
180bool ODateBookAccessBackend_XML::reload() { 211bool ODateBookAccessBackend_XML::reload() {
181 clear(); 212 clear();
182 return load(); 213 return load();
183} 214}
184bool ODateBookAccessBackend_XML::save() { 215bool 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}
233QArray<int> ODateBookAccessBackend_XML::allRecords()const { 264QArray<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}
249QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) { 280QArray<int> ODateBookAccessBackend_XML::queryByExample(const OEvent&, int, const QDateTime& ) {
250 return QArray<int>(); 281 return QArray<int>();
251} 282}
252void ODateBookAccessBackend_XML::clear() { 283void 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}
257OEvent ODateBookAccessBackend_XML::find( int uid ) const{ 288OEvent 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}
263bool ODateBookAccessBackend_XML::add( const OEvent& ev ) { 294bool ODateBookAccessBackend_XML::add( const OEvent& ev ) {
264 m_changed = true; 295 m_changed = true;
@@ -517,96 +548,98 @@ void ODateBookAccessBackend_XML::setField( OEvent& e, int id, const QString& val
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}
595QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const 626QArray<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
36namespace 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 */
14class ODateBookAccessBackend_XML : public ODateBookAccessBackend { 43class ODateBookAccessBackend_XML : public ODateBookAccessBackend {
15public: 44public:
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
40private: 69private:
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
39namespace Opie {
11class OPimAccessBackendPrivate; 40class 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 */
20template <class T = OPimRecord> 49template <class T = OPimRecord>
21class OPimAccessBackend { 50class OPimAccessBackend {
22public: 51public:
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 );
100protected: 129protected:
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
111private: 140private:
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
119template <class T> 148template <class T>
120OPimAccessBackend<T>::OPimAccessBackend(int acc) 149OPimAccessBackend<T>::OPimAccessBackend(int acc)
121 : m_acc( acc ) 150 : m_acc( acc )
122{ 151{
123 m_front = 0l; 152 m_front = 0l;
124} 153}
125template <class T> 154template <class T>
126OPimAccessBackend<T>::~OPimAccessBackend() { 155OPimAccessBackend<T>::~OPimAccessBackend() {
127 156
128} 157}
129template <class T> 158template <class T>
130void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { 159void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
131 m_front = fr; 160 m_front = fr;
132} 161}
133template <class T> 162template <class T>
134void OPimAccessBackend<T>::cache( const T& t )const { 163void 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}
138template <class T> 167template <class T>
139void OPimAccessBackend<T>::setSaneCacheSize( int size) { 168void 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}
143template <class T> 172template <class T>
144T OPimAccessBackend<T>::find( int uid, const QArray<int>&, 173T 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}
148template <class T> 177template <class T>
149void OPimAccessBackend<T>::setReadAhead( uint count ) { 178void OPimAccessBackend<T>::setReadAhead( uint count ) {
150 m_read = count; 179 m_read = count;
151} 180}
152template <class T> 181template <class T>
153uint OPimAccessBackend<T>::readAhead()const { 182uint OPimAccessBackend<T>::readAhead()const {
154 return m_read; 183 return m_read;
155} 184}
156template <class T> 185template <class T>
157int OPimAccessBackend<T>::access()const { 186int 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
32namespace Opie {
4OTodoAccessBackend::OTodoAccessBackend() 33OTodoAccessBackend::OTodoAccessBackend()
5 : OPimAccessBackend<OTodo>() 34 : OPimAccessBackend<OTodo>()
6{ 35{
7} 36}
8OTodoAccessBackend::~OTodoAccessBackend() { 37OTodoAccessBackend::~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
37namespace Opie {
9class OTodoAccessBackend : public OPimAccessBackend<OTodo> { 38class OTodoAccessBackend : public OPimAccessBackend<OTodo> {
10public: 39public:
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
22private: 51private:
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,111 +1,140 @@
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
44using 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 */
24namespace { 53namespace {
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:
@@ -205,192 +234,194 @@ namespace {
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
331namespace Opie {
301OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) 332OTodoAccessBackendSQL::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
313OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ 344OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
314 if( m_driver ) 345 if( m_driver )
315 delete m_driver; 346 delete m_driver;
316} 347}
317 348
318bool OTodoAccessBackendSQL::load(){ 349bool 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}
328bool OTodoAccessBackendSQL::reload(){ 359bool OTodoAccessBackendSQL::reload(){
329 return load(); 360 return load();
330} 361}
331 362
332bool OTodoAccessBackendSQL::save(){ 363bool 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}
335QArray<int> OTodoAccessBackendSQL::allRecords()const { 366QArray<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}
341QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ 372QArray<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}
345OTodo OTodoAccessBackendSQL::find(int uid ) const{ 376OTodo 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}
350OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 381OTodo 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}
384void OTodoAccessBackendSQL::clear() { 415void 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}
390bool OTodoAccessBackendSQL::add( const OTodo& t) { 421bool 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();
@@ -598,96 +629,98 @@ void OTodoAccessBackendSQL::fillDict() {
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 */
620void OTodoAccessBackendSQL::update()const { 651void 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}
629QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 660QArray<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
644QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 675QArray<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}
672QBitArray OTodoAccessBackendSQL::supports()const { 703QBitArray OTodoAccessBackendSQL::supports()const {
673 704
674 return sup(); 705 return sup();
675} 706}
676 707
677QBitArray OTodoAccessBackendSQL::sup() const{ 708QBitArray 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
690void OTodoAccessBackendSQL::removeAllCompleted(){ 721void 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
8class OSQLDriver; 36class OSQLDriver;
9class OSQLResult; 37class OSQLResult;
10class OSQLResultItem; 38class OSQLResultItem;
39
40namespace Opie {
41
11class OTodoAccessBackendSQL : public OTodoAccessBackend { 42class OTodoAccessBackendSQL : public OTodoAccessBackend {
12public: 43public:
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
39private: 70private:
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
37using namespace Opie;
8 38
9namespace { 39namespace {
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
140namespace Opie {
110OTodoAccessVCal::OTodoAccessVCal( const QString& path ) 141OTodoAccessVCal::OTodoAccessVCal( const QString& path )
111 : m_dirty(false), m_file( path ) 142 : m_dirty(false), m_file( path )
112{ 143{
113} 144}
114OTodoAccessVCal::~OTodoAccessVCal() { 145OTodoAccessVCal::~OTodoAccessVCal() {
115} 146}
116bool OTodoAccessVCal::load() { 147bool 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}
144bool OTodoAccessVCal::reload() { 175bool OTodoAccessVCal::reload() {
145 return load(); 176 return load();
146} 177}
147bool OTodoAccessVCal::save() { 178bool 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}
170void OTodoAccessVCal::clear() { 201void OTodoAccessVCal::clear() {
171 m_map.clear(); 202 m_map.clear();
172 m_dirty = true; 203 m_dirty = true;
173} 204}
174bool OTodoAccessVCal::add( const OTodo& to ) { 205bool 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}
179bool OTodoAccessVCal::remove( int uid ) { 210bool 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}
184void OTodoAccessVCal::removeAllCompleted() { 215void 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}
190bool OTodoAccessVCal::replace( const OTodo& to ) { 221bool 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}
195OTodo OTodoAccessVCal::find(int uid )const { 226OTodo OTodoAccessVCal::find(int uid )const {
196 return m_map[uid]; 227 return m_map[uid];
197} 228}
198QArray<int> OTodoAccessVCal::sorted( bool, int, int, int ) { 229QArray<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}
202QArray<int> OTodoAccessVCal::allRecords()const { 233QArray<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}
212QArray<int> OTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { 243QArray<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}
216QArray<int> OTodoAccessVCal::queryByExample( const OTodo&, int, const QDateTime& ) { 247QArray<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}
220QArray<int> OTodoAccessVCal::effectiveToDos( const QDate& , 251QArray<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}
226QArray<int> OTodoAccessVCal::overDue() { 257QArray<int> OTodoAccessVCal::overDue() {
227 QArray<int> ar(0); 258 QArray<int> ar(0);
228 return ar; 259 return ar;
229} 260}
230QBitArray OTodoAccessVCal::supports()const { 261QBitArray OTodoAccessVCal::supports()const {
231 static QBitArray ar = sup(); 262 static QBitArray ar = sup();
232 263
233 return ar; 264 return ar;
234} 265}
235QBitArray OTodoAccessVCal::sup() { 266QBitArray 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
34namespace Opie {
5 35
6class OTodoAccessVCal : public OTodoAccessBackend { 36class OTodoAccessVCal : public OTodoAccessBackend {
7public: 37public:
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
33private: 63private:
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,164 +1,195 @@
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
53using namespace Opie;
24 54
25namespace { 55namespace {
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
44char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 74char *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
99namespace Opie {
69 100
70OTodoAccessXML::OTodoAccessXML( const QString& appName, 101OTodoAccessXML::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}
79OTodoAccessXML::~OTodoAccessXML() { 110OTodoAccessXML::~OTodoAccessXML() {
80 111
81} 112}
82bool OTodoAccessXML::load() { 113bool 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);
@@ -781,96 +812,98 @@ public:
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
788QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, 819QArray<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};
838void OTodoAccessXML::removeAllCompleted() { 869void 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}
846QBitArray OTodoAccessXML::supports()const { 877QBitArray OTodoAccessXML::supports()const {
847 static QBitArray ar = sup(); 878 static QBitArray ar = sup();
848 return ar; 879 return ar;
849} 880}
850QBitArray OTodoAccessXML::sup() { 881QBitArray 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}
861QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const 892QArray<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
9namespace Opie { 37namespace Opie {
10 class XMLElement; 38 class XMLElement;
11};
12 39
13class OTodoAccessXML : public OTodoAccessBackend { 40class OTodoAccessXML : public OTodoAccessBackend {
14public: 41public:
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;
44private: 71private:
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 @@
1HEADERS += 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
13SOURCES += 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
56namespace Opie {
75 57
76OContactAccess::OContactAccess ( const QString appname, const QString , 58OContactAccess::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}
104OContactAccess::~OContactAccess () 86OContactAccess::~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
114bool OContactAccess::save () 96bool 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
133const uint OContactAccess::querySettings() 115const uint OContactAccess::querySettings()
134{ 116{
135 return ( m_backEnd->querySettings() ); 117 return ( m_backEnd->querySettings() );
136} 118}
137 119
138bool OContactAccess::hasQuerySettings ( int querySettings ) const 120bool OContactAccess::hasQuerySettings ( int querySettings ) const
139{ 121{
140 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 122 return ( m_backEnd->hasQuerySettings ( querySettings ) );
141} 123}
142ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 124ORecordList<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
149bool OContactAccess::wasChangedExternally()const 131bool OContactAccess::wasChangedExternally()const
150{ 132{
151 return ( m_backEnd->wasChangedExternally() ); 133 return ( m_backEnd->wasChangedExternally() );
152} 134}
153 135
154 136
155void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) 137void 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
48namespace 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 */
96class OContactAccess: public QObject, public OPimAccessTemplate<OContact> 58class 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
34namespace Opie {
35
18QString OConversion::dateToString( const QDate &d ) 36QString 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
36QDate OConversion::dateFromString( const QString& s ) 54QDate 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}
77QString OConversion::dateTimeToString( const QDateTime& dt ) { 95QString 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}
98QDateTime OConversion::dateTimeFromString( const QString& str) { 116QDateTime 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 */ 37namespace Opie {
38
27class OConversion 39class OConversion
28{ 40{
29public: 41public:
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
41private: 53private:
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
32namespace 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 */
11ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) 40ODateBookAccess::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}
20ODateBookAccess::~ODateBookAccess() { 49ODateBookAccess::~ODateBookAccess() {
21} 50}
22 51
23/** 52/**
24 * @return all events available 53 * @return all events available
25 */ 54 */
26ODateBookAccess::List ODateBookAccess::rawEvents()const { 55ODateBookAccess::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 */
36ODateBookAccess::List ODateBookAccess::rawRepeats()const { 65ODateBookAccess::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 */
46ODateBookAccess::List ODateBookAccess::nonRepeats()const { 75ODateBookAccess::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 */
58OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { 87OEffectiveEvent::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 */
64OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { 93OEffectiveEvent::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 */
73OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { 102OEffectiveEvent::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 */
79OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { 108OEffectiveEvent::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
37namespace 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 */
18class ODateBookAccess : public OPimAccessTemplate<OEvent> { 47class ODateBookAccess : public OPimAccessTemplate<OEvent> {
19public: 48public:
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
38private: 67private:
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,107 +1,137 @@
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
41namespace Opie {
12 42
13class OPimAccessTemplatePrivate; 43class 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
23template <class T = OPimRecord > 53template <class T = OPimRecord >
24class OPimAccessTemplate : public OTemplateBase<T> { 54class OPimAccessTemplate : public OTemplateBase<T> {
25public: 55public:
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 */
@@ -206,97 +236,100 @@ OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime
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}
211template <class T> 241template <class T>
212T OPimAccessTemplate<T>::find( int uid ) const{ 242T 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}
217template <class T> 247template <class T>
218T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 248T 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}
234template <class T> 264template <class T>
235void OPimAccessTemplate<T>::clear() { 265void OPimAccessTemplate<T>::clear() {
236 invalidateCache(); 266 invalidateCache();
237 m_backEnd->clear(); 267 m_backEnd->clear();
238} 268}
239template <class T> 269template <class T>
240bool OPimAccessTemplate<T>::add( const T& t ) { 270bool 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}
244template <class T> 274template <class T>
245bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 275bool 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}
253template <class T> 283template <class T>
254bool OPimAccessTemplate<T>::remove( const T& t ) { 284bool OPimAccessTemplate<T>::remove( const T& t ) {
255 return remove( t.uid() ); 285 return remove( t.uid() );
256} 286}
257template <class T> 287template <class T>
258bool OPimAccessTemplate<T>::remove( int uid ) { 288bool 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}
262template <class T> 292template <class T>
263bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 293bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
264 return remove( rec.uid() ); 294 return remove( rec.uid() );
265} 295}
266template <class T> 296template <class T>
267bool OPimAccessTemplate<T>::replace( const T& t ) { 297bool 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}
271template <class T> 301template <class T>
272void OPimAccessTemplate<T>::invalidateCache() { 302void OPimAccessTemplate<T>::invalidateCache() {
273 m_cache.invalidate(); 303 m_cache.invalidate();
274} 304}
275template <class T> 305template <class T>
276typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 306typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
277 return m_backEnd; 307 return m_backEnd;
278} 308}
279template <class T> 309template <class T>
280bool OPimAccessTemplate<T>::wasChangedExternally()const { 310bool OPimAccessTemplate<T>::wasChangedExternally()const {
281 return false; 311 return false;
282} 312}
283template <class T> 313template <class T>
284void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 314void 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}
289template <class T> 319template <class T>
290void OPimAccessTemplate<T>::cache( const T& t ) const{ 320void 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}
294template <class T> 324template <class T>
295void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 325void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
296 m_cache.setSize( size ); 326 m_cache.setSize( size );
297} 327}
298template <class T> 328template <class T>
299void OPimAccessTemplate<T>::setReadAhead( uint count ) { 329void 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
36namespace Opie {
8class OPimCacheItemPrivate; 37class OPimCacheItemPrivate;
9 38
10template <class T = OPimRecord> 39template <class T = OPimRecord>
11class OPimCacheItem { 40class OPimCacheItem {
12public: 41public:
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& );
21private: 50private:
22 T m_t; 51 T m_t;
23 OPimCacheItemPrivate *d; 52 OPimCacheItemPrivate *d;
24}; 53};
25 54
26 55
27class OPimCachePrivate; 56class 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 */
33template <class T = OPimRecord> 62template <class T = OPimRecord>
34class OPimCache { 63class OPimCache {
35public: 64public:
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
52private: 81private:
53 QIntCache<Item> m_cache; 82 QIntCache<Item> m_cache;
54 OPimCachePrivate* d; 83 OPimCachePrivate* d;
55}; 84};
56 85
57// Implementation 86// Implementation
58template <class T> 87template <class T>
59OPimCacheItem<T>::OPimCacheItem( const T& t ) 88OPimCacheItem<T>::OPimCacheItem( const T& t )
60 : m_t(t) { 89 : m_t(t) {
61} 90}
62template <class T> 91template <class T>
63OPimCacheItem<T>::~OPimCacheItem() { 92OPimCacheItem<T>::~OPimCacheItem() {
64 93
65} 94}
66template <class T> 95template <class T>
67T OPimCacheItem<T>::record()const { 96T OPimCacheItem<T>::record()const {
68 return m_t; 97 return m_t;
69} 98}
70template <class T> 99template <class T>
71void OPimCacheItem<T>::setRecord( const T& t ) { 100void OPimCacheItem<T>::setRecord( const T& t ) {
72 m_t = t; 101 m_t = t;
73} 102}
74// Cache 103// Cache
75template <class T> 104template <class T>
76OPimCache<T>::OPimCache() 105OPimCache<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}
81template <class T> 110template <class T>
82OPimCache<T>::~OPimCache() { 111OPimCache<T>::~OPimCache() {
83 112
84} 113}
85template <class T> 114template <class T>
86bool OPimCache<T>::contains(int uid )const { 115bool 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}
92template <class T> 121template <class T>
93void OPimCache<T>::invalidate() { 122void OPimCache<T>::invalidate() {
94 m_cache.clear(); 123 m_cache.clear();
95} 124}
96template <class T> 125template <class T>
97void OPimCache<T>::setSize( int size ) { 126void OPimCache<T>::setSize( int size ) {
98 m_cache.setMaxCost( size ); 127 m_cache.setMaxCost( size );
99} 128}
100template <class T> 129template <class T>
101T OPimCache<T>::find(int uid )const { 130T 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}
107template <class T> 136template <class T>
108void OPimCache<T>::add( const T& t ) { 137void 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}
119template <class T> 148template <class T>
120void OPimCache<T>::remove( int uid ) { 149void OPimCache<T>::remove( int uid ) {
121 m_cache.remove( uid ); 150 m_cache.remove( uid );
122} 151}
123template <class T> 152template <class T>
124void OPimCache<T>::replace( const T& t) { 153void 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
32namespace Opie {
3OPimMaintainer::OPimMaintainer( int mode, int uid ) 33OPimMaintainer::OPimMaintainer( int mode, int uid )
4 : m_mode(mode), m_uid(uid ) 34 : m_mode(mode), m_uid(uid )
5{} 35{}
6OPimMaintainer::~OPimMaintainer() { 36OPimMaintainer::~OPimMaintainer() {
7} 37}
8OPimMaintainer::OPimMaintainer( const OPimMaintainer& main ) { 38OPimMaintainer::OPimMaintainer( const OPimMaintainer& main ) {
9 *this = main; 39 *this = main;
10} 40}
11OPimMaintainer &OPimMaintainer::operator=( const OPimMaintainer& main ) { 41OPimMaintainer &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}
17bool OPimMaintainer::operator==( const OPimMaintainer& main ) { 47bool 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}
23bool OPimMaintainer::operator!=( const OPimMaintainer& main ) { 53bool OPimMaintainer::operator!=( const OPimMaintainer& main ) {
24 return !(*this == main ); 54 return !(*this == main );
25} 55}
26int OPimMaintainer::mode()const { 56int OPimMaintainer::mode()const {
27 return m_mode; 57 return m_mode;
28} 58}
29int OPimMaintainer::uid()const { 59int OPimMaintainer::uid()const {
30 return m_uid; 60 return m_uid;
31} 61}
32void OPimMaintainer::setMode( int mo) { 62void OPimMaintainer::setMode( int mo) {
33 m_mode = mo; 63 m_mode = mo;
34} 64}
35void OPimMaintainer::setUid( int uid ) { 65void 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
34namespace Opie {
6/** 35/**
7 * Who maintains what? 36 * Who maintains what?
8 */ 37 */
9class OPimMaintainer { 38class OPimMaintainer {
10public: 39public:
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
32private: 61private:
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,99 +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#include <qshared.h> 29#include <qshared.h>
2 30
3#include "opimnotify.h" 31#include <opie2/opimnotify.h>
32
33namespace Opie {
4 34
5struct OPimNotify::Data : public QShared { 35struct 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
15OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) { 45OPimNotify::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}
21OPimNotify::OPimNotify( const OPimNotify& noti) 51OPimNotify::OPimNotify( const OPimNotify& noti)
22 : data( noti.data ) 52 : data( noti.data )
23{ 53{
24 data->ref(); 54 data->ref();
25} 55}
26OPimNotify::~OPimNotify() { 56OPimNotify::~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
33OPimNotify &OPimNotify::operator=( const OPimNotify& noti) { 63OPimNotify &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}
40bool OPimNotify::operator==( const OPimNotify& noti ) { 70bool 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}
49QDateTime OPimNotify::dateTime()const { 79QDateTime OPimNotify::dateTime()const {
50 return data->start; 80 return data->start;
51} 81}
52QString OPimNotify::service()const { 82QString OPimNotify::service()const {
53 return data->application; 83 return data->application;
54} 84}
55int OPimNotify::parent()const { 85int OPimNotify::parent()const {
56 return data->parent; 86 return data->parent;
57} 87}
58int OPimNotify::duration()const { 88int OPimNotify::duration()const {
59 return data->dur; 89 return data->dur;
60} 90}
61QDateTime OPimNotify::endTime()const { 91QDateTime 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}
64void OPimNotify::setDateTime( const QDateTime& time ) { 94void OPimNotify::setDateTime( const QDateTime& time ) {
65 copyIntern(); 95 copyIntern();
66 data->start = time; 96 data->start = time;
67} 97}
68void OPimNotify::setDuration( int dur ) { 98void OPimNotify::setDuration( int dur ) {
69 copyIntern(); 99 copyIntern();
70 data->dur = dur; 100 data->dur = dur;
71} 101}
72void OPimNotify::setParent( int uid ) { 102void OPimNotify::setParent( int uid ) {
73 copyIntern(); 103 copyIntern();
74 data->parent = uid; 104 data->parent = uid;
75} 105}
76void OPimNotify::setService( const QString& str ) { 106void OPimNotify::setService( const QString& str ) {
77 copyIntern(); 107 copyIntern();
78 data->application = str; 108 data->application = str;
79} 109}
80void OPimNotify::copyIntern() { 110void 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}
91void OPimNotify::deref() { 121void 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/***********************************************************/
99struct OPimAlarm::Data : public QShared { 129struct OPimAlarm::Data : public QShared {
@@ -132,96 +162,97 @@ OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al)
132 return *this; 162 return *this;
133} 163}
134bool OPimAlarm::operator==( const OPimAlarm& al) { 164bool 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}
141QString OPimAlarm::type()const { 171QString OPimAlarm::type()const {
142 return QString::fromLatin1("OPimAlarm"); 172 return QString::fromLatin1("OPimAlarm");
143} 173}
144int OPimAlarm::sound()const { 174int OPimAlarm::sound()const {
145 return data->sound; 175 return data->sound;
146} 176}
147QString OPimAlarm::file()const { 177QString OPimAlarm::file()const {
148 return data->file; 178 return data->file;
149} 179}
150void OPimAlarm::setSound( int snd) { 180void OPimAlarm::setSound( int snd) {
151 copyIntern(); 181 copyIntern();
152 data->sound = snd; 182 data->sound = snd;
153} 183}
154void OPimAlarm::setFile( const QString& sound ) { 184void OPimAlarm::setFile( const QString& sound ) {
155 copyIntern(); 185 copyIntern();
156 data->file = sound; 186 data->file = sound;
157} 187}
158void OPimAlarm::deref() { 188void 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}
164void OPimAlarm::copyIntern() { 194void 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/************************/
174struct OPimReminder::Data : public QShared { 204struct 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};
180OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent ) 210OPimReminder::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}
186OPimReminder::OPimReminder( const OPimReminder& rem ) 216OPimReminder::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}
191OPimReminder& OPimReminder::operator=( const OPimReminder& rem) { 221OPimReminder& 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}
200bool OPimReminder::operator==( const OPimReminder& rem) { 230bool 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}
205QString OPimReminder::type()const { 235QString OPimReminder::type()const {
206 return QString::fromLatin1("OPimReminder"); 236 return QString::fromLatin1("OPimReminder");
207} 237}
208int OPimReminder::recordUid()const { 238int OPimReminder::recordUid()const {
209 return data->record; 239 return data->record;
210} 240}
211void OPimReminder::setRecordUid( int uid ) { 241void OPimReminder::setRecordUid( int uid ) {
212 copyIntern(); 242 copyIntern();
213 data->record = uid; 243 data->record = uid;
214} 244}
215void OPimReminder::deref() { 245void 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}
221void OPimReminder::copyIntern() { 251void 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
36namespace 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 */
20class OPimNotify { 50class OPimNotify {
21public: 51public:
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
57private: 87private:
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 */
73class OPimAlarm : public OPimNotify { 103class OPimAlarm : public OPimNotify {
74public: 104public:
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
91private: 121private:
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 */
108class OPimReminder : public OPimNotify { 138class OPimReminder : public OPimNotify {
109public: 139public:
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
134private: 164private:
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
35namespace Opie {
36
7OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) 37OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al)
8 : m_rem( rem ), m_al( al ) 38 : m_rem( rem ), m_al( al )
9{} 39{}
10OPimNotifyManager::~OPimNotifyManager() { 40OPimNotifyManager::~OPimNotifyManager() {
11} 41}
12/* use static_cast and type instead of dynamic... */ 42/* use static_cast and type instead of dynamic... */
13void OPimNotifyManager::add( const OPimNotify& noti) { 43void 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}
22void OPimNotifyManager::remove( const OPimNotify& noti) { 52void 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}
31void OPimNotifyManager::replace( const OPimNotify& noti) { 61void 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}
42OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { 72OPimNotifyManager::Reminders OPimNotifyManager::reminders()const {
43 return m_rem; 73 return m_rem;
44} 74}
45OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { 75OPimNotifyManager::Alarms OPimNotifyManager::alarms()const {
46 return m_al; 76 return m_al;
47} 77}
48OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const { 78OPimAlarm 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
64void OPimNotifyManager::setAlarms( const Alarms& al) { 94void OPimNotifyManager::setAlarms( const Alarms& al) {
65 m_al = al; 95 m_al = al;
66} 96}
67void OPimNotifyManager::setReminders( const Reminders& rem) { 97void 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 */
78void OPimNotifyManager::registerNotify( const OPimNotify& ) { 108void 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 */
87void OPimNotifyManager::deregister( const OPimNotify& ) { 117void OPimNotifyManager::deregister( const OPimNotify& ) {
88 118
89} 119}
90 120
91bool OPimNotifyManager::isEmpty()const { 121bool 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..
98QString OPimNotifyManager::alarmsToString() const 128QString 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}
122QString OPimNotifyManager::remindersToString() const 152QString 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
139void OPimNotifyManager::alarmsFromString( const QString& str ) 169void 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
153void OPimNotifyManager::remindersFromString( const QString& str ) 183void 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
36namespace Opie {
8/** 37/**
9 * The notify manager keeps track of the Notifiers.... 38 * The notify manager keeps track of the Notifiers....
10 */ 39 */
11class OPimNotifyManager { 40class OPimNotifyManager {
12public: 41public:
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
82private: 111private:
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
36namespace Opie {
8Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 37Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
9 38
10 39
11OPimRecord::OPimRecord( int uid ) 40OPimRecord::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}
17OPimRecord::~OPimRecord() { 46OPimRecord::~OPimRecord() {
18} 47}
19OPimRecord::OPimRecord( const OPimRecord& rec ) 48OPimRecord::OPimRecord( const OPimRecord& rec )
20 : Qtopia::Record( rec ) 49 : Qtopia::Record( rec )
21{ 50{
22 (*this) = rec; 51 (*this) = rec;
23} 52}
24 53
25OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { 54OPimRecord &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 */
37QStringList OPimRecord::categoryNames( const QString& appname ) const { 66QStringList 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}
49void OPimRecord::setCategoryNames( const QStringList& ) { 78void OPimRecord::setCategoryNames( const QStringList& ) {
50 79
51} 80}
52void OPimRecord::addCategoryName( const QString& ) { 81void OPimRecord::addCategoryName( const QString& ) {
53 Categories catDB; 82 Categories catDB;
54 catDB.load( categoryFileName() ); 83 catDB.load( categoryFileName() );
55 84
56 85
57} 86}
58bool OPimRecord::isEmpty()const { 87bool 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 */
76void OPimRecord::setUid( int uid ) { 105void 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};
82Qtopia::UidGen &OPimRecord::uidGen() { 111Qtopia::UidGen &OPimRecord::uidGen() {
83 return m_uidGen; 112 return m_uidGen;
84} 113}
85OPimXRefManager &OPimRecord::xrefmanager() { 114OPimXRefManager &OPimRecord::xrefmanager() {
86 return m_xrefman; 115 return m_xrefman;
87} 116}
88int OPimRecord::rtti(){ 117int 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 */
100bool OPimRecord::loadFromStream( QDataStream& stream ) { 129bool 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}
127bool OPimRecord::saveToStream( QDataStream& stream )const { 156bool 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}
150void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ 179void 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}
155OPimXRefPartner OPimRecord::partner( QDataStream& stream ) { 184OPimXRefPartner 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}
171void OPimRecord::setLastHitField( int lastHit )const { 200void OPimRecord::setLastHitField( int lastHit )const {
172 m_lastHit = lastHit; 201 m_lastHit = lastHit;
173} 202}
174int OPimRecord::lastHitField()const{ 203int OPimRecord::lastHitField()const{
175 return m_lastHit; 204 return m_lastHit;
176} 205}
177QMap<QString, QString> OPimRecord::toExtraMap()const { 206QMap<QString, QString> OPimRecord::toExtraMap()const {
178 return customMap; 207 return customMap;
179} 208}
180void OPimRecord::setExtraMap( const QMap<QString, QString>& map) { 209void 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
46namespace 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 */
23class OPimRecord : public Qtopia::Record { 52class OPimRecord : public Qtopia::Record {
24public: 53public:
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 &regexp ) const 112 virtual bool match( const QString &regexp ) 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
138protected: 167protected:
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
145private: 174private:
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
151private: 180private:
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
39namespace Opie {
10 40
11OPimResolver* OPimResolver::m_self = 0l; 41OPimResolver* OPimResolver::m_self = 0l;
12 42
13OPimResolver::OPimResolver() { 43OPimResolver::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}
17OPimResolver* OPimResolver::self() { 47OPimResolver* 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 */
27OPimRecord* OPimResolver::record( const QString& service, int uid ) { 57OPimRecord* 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}
37OPimRecord* OPimResolver::record( const QString& service ) { 67OPimRecord* OPimResolver::record( const QString& service ) {
38 return record( serviceId( service ) ); 68 return record( serviceId( service ) );
39} 69}
40OPimRecord* OPimResolver::record( int rtti ) { 70OPimRecord* 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}
58bool OPimResolver::isBuiltIn( const QString& str) const{ 88bool OPimResolver::isBuiltIn( const QString& str) const{
59 return m_builtIns.contains( str ); 89 return m_builtIns.contains( str );
60} 90}
61QCString OPimResolver::qcopChannel( enum BuiltIn& built)const { 91QCString 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}
79QCString OPimResolver::qcopChannel( const QString& service )const { 109QCString 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 */
88QCString OPimResolver::applicationChannel( enum BuiltIn& built)const { 118QCString 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}
104QCString OPimResolver::applicationChannel( const QString& service )const { 134QCString 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}
119QStringList OPimResolver::services()const { 149QStringList OPimResolver::services()const {
120 return m_builtIns; 150 return m_builtIns;
121} 151}
122QString OPimResolver::serviceName( int rtti ) const{ 152QString 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}
140int OPimResolver::serviceId( const QString& service ) { 170int 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 */
154bool OPimResolver::add( const QString& service, const OPimRecord& rec) { 184bool 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}
176OPimBase* OPimResolver::backend( const QString& service ) { 206OPimBase* OPimResolver::backend( const QString& service ) {
177 return backend( serviceId( service ) ); 207 return backend( serviceId( service ) );
178} 208}
179OPimBase* OPimResolver::backend( int rtti ) { 209OPimBase* 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
37namespace 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 */
20class OPimResolver { 49class OPimResolver {
21public: 50public:
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 );
74private: 103private:
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
33namespace 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 */
10struct OPimState::Data : public QShared { 39struct 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
16OPimState::OPimState( int state ) { 45OPimState::OPimState( int state ) {
17 data = new Data; 46 data = new Data;
18 data->state = state; 47 data->state = state;
19} 48}
20OPimState::OPimState( const OPimState& st) : 49OPimState::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}
25OPimState::~OPimState() { 54OPimState::~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}
31bool OPimState::operator==( const OPimState& st) { 60bool 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}
36OPimState &OPimState::operator=( const OPimState& st) { 65OPimState &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}
43void OPimState::setState( int st) { 72void OPimState::setState( int st) {
44 copyInternally(); 73 copyInternally();
45 data->state = st; 74 data->state = st;
46} 75}
47int OPimState::state()const { 76int OPimState::state()const {
48 return data->state; 77 return data->state;
49} 78}
50void OPimState::deref() { 79void 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}
56void OPimState::copyInternally() { 85void 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
34namespace 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 */
17class OPimState { 46class OPimState {
18public: 47public:
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;
34private: 63private:
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
31namespace Opie {
2 32
3OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two ) 33OPimXRef::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}
9OPimXRef::OPimXRef() 39OPimXRef::OPimXRef()
10 : m_partners(2) 40 : m_partners(2)
11{ 41{
12 42
13} 43}
14OPimXRef::OPimXRef( const OPimXRef& ref) { 44OPimXRef::OPimXRef( const OPimXRef& ref) {
15 *this = ref; 45 *this = ref;
16} 46}
17OPimXRef::~OPimXRef() { 47OPimXRef::~OPimXRef() {
18} 48}
19OPimXRef &OPimXRef::operator=( const OPimXRef& ref) { 49OPimXRef &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}
25bool OPimXRef::operator==( const OPimXRef& oper ) { 55bool 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}
30OPimXRefPartner OPimXRef::partner( enum Partners par) const{ 60OPimXRefPartner OPimXRef::partner( enum Partners par) const{
31 return m_partners[par]; 61 return m_partners[par];
32} 62}
33void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) { 63void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) {
34 m_partners[par] = part; 64 m_partners[par] = part;
35} 65}
36bool OPimXRef::containsString( const QString& string ) const{ 66bool 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}
42bool OPimXRef::containsUid( int uid ) const{ 72bool 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
38namespace 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 */
13class OPimXRef { 43class OPimXRef {
14public: 44public:
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
32private: 62private:
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
31namespace Opie {
3 32
4OPimXRefManager::OPimXRefManager() { 33OPimXRefManager::OPimXRefManager() {
5} 34}
6OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) { 35OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) {
7 m_list = ref.m_list; 36 m_list = ref.m_list;
8} 37}
9OPimXRefManager::~OPimXRefManager() { 38OPimXRefManager::~OPimXRefManager() {
10} 39}
11OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) { 40OPimXRefManager &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}
15bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) { 44bool 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}
20void OPimXRefManager::add( const OPimXRef& ref) { 49void OPimXRefManager::add( const OPimXRef& ref) {
21 m_list.append( ref ); 50 m_list.append( ref );
22} 51}
23void OPimXRefManager::remove( const OPimXRef& ref) { 52void OPimXRefManager::remove( const OPimXRef& ref) {
24 m_list.remove( ref ); 53 m_list.remove( ref );
25} 54}
26void OPimXRefManager::replace( const OPimXRef& ref) { 55void 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}
30void OPimXRefManager::clear() { 59void OPimXRefManager::clear() {
31 m_list.clear(); 60 m_list.clear();
32} 61}
33QStringList OPimXRefManager::apps()const { 62QStringList 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}
47OPimXRef::ValueList OPimXRefManager::list()const { 76OPimXRef::ValueList OPimXRefManager::list()const {
48 return m_list; 77 return m_list;
49} 78}
50OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{ 79OPimXRef::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}
61OPimXRef::ValueList OPimXRefManager::list( int uid )const { 90OPimXRef::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
36namespace 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 */
14class OPimXRefManager { 43class OPimXRefManager {
15public: 44public:
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
37private: 66private:
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
31namespace Opie {
2 32
3OPimXRefPartner::OPimXRefPartner( const QString& appName, 33OPimXRefPartner::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}
7OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) { 37OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) {
8 *this = ref; 38 *this = ref;
9} 39}
10OPimXRefPartner::~OPimXRefPartner() { 40OPimXRefPartner::~OPimXRefPartner() {
11} 41}
12OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) { 42OPimXRefPartner &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}
19bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) { 49bool 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}
26QString OPimXRefPartner::service()const { 56QString OPimXRefPartner::service()const {
27 return m_app; 57 return m_app;
28} 58}
29int OPimXRefPartner::uid()const { 59int OPimXRefPartner::uid()const {
30 return m_uid; 60 return m_uid;
31} 61}
32int OPimXRefPartner::field()const { 62int OPimXRefPartner::field()const {
33 return m_field; 63 return m_field;
34} 64}
35void OPimXRefPartner::setService( const QString& appName ) { 65void OPimXRefPartner::setService( const QString& appName ) {
36 m_app = appName; 66 m_app = appName;
37} 67}
38void OPimXRefPartner::setUid( int uid ) { 68void OPimXRefPartner::setUid( int uid ) {
39 m_uid = uid; 69 m_uid = uid;
40} 70}
41void OPimXRefPartner::setField( int field ) { 71void 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
34namespace 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 */
13class OPimXRefPartner { 42class OPimXRefPartner {
14public: 43public:
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 );
30private: 59private:
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,105 +1,135 @@
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
39namespace Opie {
10struct ORecur::Data : public QShared { 40struct 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
34ORecur::ORecur() { 64ORecur::ORecur() {
35 data = new Data; 65 data = new Data;
36} 66}
37 67
38ORecur::ORecur( const QMap<int, QString>& map ) 68ORecur::ORecur( const QMap<int, QString>& map )
39{ 69{
40 ORecur(); 70 ORecur();
41 fromMap( map ); 71 fromMap( map );
42} 72}
43 73
44 74
45ORecur::ORecur( const ORecur& rec) 75ORecur::ORecur( const ORecur& rec)
46 : data( rec.data ) 76 : data( rec.data )
47{ 77{
48 data->ref(); 78 data->ref();
49} 79}
50ORecur::~ORecur() { 80ORecur::~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}
56void ORecur::deref() { 86void 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}
62bool ORecur::operator==( const ORecur& )const { 92bool ORecur::operator==( const ORecur& )const {
63 return false; 93 return false;
64} 94}
65ORecur &ORecur::operator=( const ORecur& re) { 95ORecur &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}
74bool ORecur::doesRecur()const { 104bool 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 */
81bool ORecur::doesRecur( const QDate& date ) { 111bool 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!
94bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { 124bool 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}
102bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { 132bool 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;
@@ -498,96 +528,98 @@ QString ORecur::rTypeString() const
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
521QMap<QString, ORecur::RepeatType> ORecur::rTypeValueConvertMap() const 551QMap<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
536QMap<int, QString> ORecur::toMap() const 566QMap<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
568void ORecur::fromMap( const QMap<int, QString>& map ) 598void 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
40namespace Opie {
15/** 41/**
16 * Class to handle Recurrencies.. 42 * Class to handle Recurrencies..
17 */ 43 */
18 44
19class ORecur { 45class ORecur {
20public: 46public:
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;
91private: 117private:
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
37namespace 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 */
17class OPimBasePrivate; 46class OPimBasePrivate;
18struct OPimBase { 47struct 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 */
36private: 65private:
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 */
44class OTemplateBasePrivate; 73class OTemplateBasePrivate;
45template <class T = OPimRecord> 74template <class T = OPimRecord>
46class OTemplateBase : public OPimBase { 75class OTemplateBase : public OPimBase {
47public: 76public:
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
69private: 98private:
70 OTemplateBasePrivate *d; 99 OTemplateBasePrivate *d;
71}; 100};
72 101
73/* 102/*
74 * implementation 103 * implementation
75 */ 104 */
76template <class T> 105template <class T>
77int 106int
78OTemplateBase<T>::rtti() { 107OTemplateBase<T>::rtti() {
79 return T::rtti(); 108 return T::rtti();
80} 109}
81template <class T> 110template <class T>
82OPimRecord* OTemplateBase<T>::record()const { 111OPimRecord* OTemplateBase<T>::record()const {
83 T* t = new T; 112 T* t = new T;
84 return t; 113 return t;
85} 114}
86template <class T> 115template <class T>
87OPimRecord* OTemplateBase<T>::record(int uid )const { 116OPimRecord* 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};
93template <class T> 122template <class T>
94T* OTemplateBase<T>::rec() { 123T* 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
8namespace { 37namespace 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
92namespace Opie {
62OTimeZone::OTimeZone( const ZoneName& zone ) 93OTimeZone::OTimeZone( const ZoneName& zone )
63 : m_name(zone) { 94 : m_name(zone) {
64} 95}
65OTimeZone::~OTimeZone() { 96OTimeZone::~OTimeZone() {
66} 97}
67 98
68bool OTimeZone::isValid()const { 99bool 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 */
76QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) { 107QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) {
77 return OTimeZone::current().toDateTime( dt, *this ); 108 return OTimeZone::current().toDateTime( dt, *this );
78} 109}
79QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) { 110QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) {
80 return OTimeZone::utc().toDateTime( dt, *this ); 111 return OTimeZone::utc().toDateTime( dt, *this );
81} 112}
82QDateTime OTimeZone::fromUTCDateTime( time_t t) { 113QDateTime OTimeZone::fromUTCDateTime( time_t t) {
83 return utcTime( t ); 114 return utcTime( t );
84} 115}
85QDateTime OTimeZone::toDateTime( time_t t) { 116QDateTime 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 */
92QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) { 123QDateTime 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}
97time_t OTimeZone::fromDateTime( const QDateTime& time ) { 128time_t OTimeZone::fromDateTime( const QDateTime& time ) {
98 return to_Time_t( time, m_name ); 129 return to_Time_t( time, m_name );
99} 130}
100time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) { 131time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) {
101 return to_Time_t( time, "UTC" ); 132 return to_Time_t( time, "UTC" );
102} 133}
103OTimeZone OTimeZone::current() { 134OTimeZone 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}
108OTimeZone OTimeZone::utc() { 139OTimeZone OTimeZone::utc() {
109 return OTimeZone("UTC"); 140 return OTimeZone("UTC");
110} 141}
111QString OTimeZone::timeZone()const { 142QString 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
36namespace 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 */
13class OTimeZone { 44class 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
37namespace Opie {
9OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access ) 38OTodoAccess::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}
21OTodoAccess::~OTodoAccess() { 50OTodoAccess::~OTodoAccess() {
22// qWarning("~OTodoAccess"); 51// qWarning("~OTodoAccess");
23} 52}
24void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { 53void 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}
30OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 59OTodoAccess::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}
38OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 67OTodoAccess::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}
43OTodoAccess::List OTodoAccess::overDue() { 72OTodoAccess::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 */
48OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 77OTodoAccess::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}
54void OTodoAccess::removeAllCompleted() { 83void OTodoAccess::removeAllCompleted() {
55 m_todoBackEnd->removeAllCompleted(); 84 m_todoBackEnd->removeAllCompleted();
56} 85}
57QBitArray OTodoAccess::backendSupport( const QString& ) const{ 86QBitArray OTodoAccess::backendSupport( const QString& ) const{
58 return m_todoBackEnd->supports(); 87 return m_todoBackEnd->supports();
59} 88}
60bool OTodoAccess::backendSupports( int attr, const QString& ar) const{ 89bool 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
39namespace 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 */
17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { 46class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
18 Q_OBJECT 47 Q_OBJECT
19public: 48public:
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;
90signals: 119signals:
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 );
98private: 127private:
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,145 +1,175 @@
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
79namespace Opie {
50/*! 80/*!
51 Creates a new, empty contact. 81 Creates a new, empty contact.
52*/ 82*/
53OContact::OContact() 83OContact::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*/
63OContact::OContact( const QMap<int, QString> &fromMap ) : 93OContact::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*/
85OContact::~OContact() 115OContact::~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 )
@@ -1112,96 +1142,97 @@ QDate OContact::birthday() const
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*/
1117QDate OContact::anniversary() const 1147QDate 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
1129void OContact::insertEmail( const QString &v ) 1159void 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
1151void OContact::removeEmail( const QString &v ) 1181void 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}
1178void OContact::clearEmails() 1208void 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}
1183void OContact::setDefaultEmail( const QString &v ) 1213void 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
1195void OContact::insertEmails( const QStringList &v ) 1225void 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}
1200int OContact::rtti() { 1230int OContact::rtti() {
1201 return OPimResolver::AddressBook; 1231 return OPimResolver::AddressBook;
1202} 1232}
1203void OContact::setUid( int i ) 1233void 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,130 +1,140 @@
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
31QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; 40QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
32// MOC_SKIP_END 41// MOC_SKIP_END
33#endif 42#endif
34 43
44namespace Opie {
35class OContactPrivate; 45class 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 */
44class QPC_EXPORT OContact : public OPimRecord 54class QPC_EXPORT OContact : public OPimRecord
45{ 55{
46 friend class DataSet; 56 friend class DataSet;
47public: 57public:
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 &regexp ) const; 129 virtual bool match( const QRegExp &regexp ) 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 ); }
@@ -143,98 +153,99 @@ public:
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
218private: 228private:
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,107 +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 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
40namespace 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*/
16QStringList OContactFields::personalfields( bool sorted, bool translated ) 45QStringList 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*/
50QStringList OContactFields::detailsfields( bool sorted, bool translated ) 79QStringList 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*/
79QStringList OContactFields::phonefields( bool sorted, bool translated ) 108QStringList 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
@@ -382,96 +411,98 @@ QMap<QString, int> OContactFields::untrFieldsToId()
382 return ret_map; 411 return ret_map;
383} 412}
384 413
385 414
386OContactFields::OContactFields(): 415OContactFields::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
397OContactFields::~OContactFields(){ 426OContactFields::~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
410void OContactFields::saveToRecord( OContact &cnt ){ 439void 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
422void OContactFields::loadFromRecord( const OContact &cnt ){ 451void 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
441void OContactFields::setFieldOrder( int num, int index ){ 470void 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
454int OContactFields::getFieldOrder( int num, int defIndex ){ 483int 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
4class QStringList; 32class 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
41namespace Opie {
13class OContactFields{ 42class 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,108 +1,138 @@
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
42namespace Opie {
13 43
14int OCalendarHelper::week( const QDate& date) { 44int 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}
26int OCalendarHelper::ocurrence( const QDate& date) { 56int 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}
31int OCalendarHelper::dayOfWeek( char day ) { 61int 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}
40int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { 70int 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
45struct OEvent::Data : public QShared { 75struct 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
71OEvent::OEvent( int uid ) 101OEvent::OEvent( int uid )
72 : OPimRecord( uid ) { 102 : OPimRecord( uid ) {
73 data = new Data; 103 data = new Data;
74} 104}
75OEvent::OEvent( const OEvent& ev) 105OEvent::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
81OEvent::OEvent( const QMap<int, QString> map ) 111OEvent::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
89OEvent::~OEvent() { 119OEvent::~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}
95OEvent& OEvent::operator=( const OEvent& ev) { 125OEvent& 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}
106QString OEvent::description()const { 136QString OEvent::description()const {
107 return data->description; 137 return data->description;
108} 138}
@@ -622,96 +652,98 @@ void OEffectiveEvent::setEffectiveDates( const QDate& from,
622 652
623 data->startDate = from; 653 data->startDate = from;
624 data->endDate = to; 654 data->endDate = to;
625} 655}
626QString OEffectiveEvent::description()const { 656QString OEffectiveEvent::description()const {
627 return data->event.description(); 657 return data->event.description();
628} 658}
629QString OEffectiveEvent::location()const { 659QString OEffectiveEvent::location()const {
630 return data->event.location(); 660 return data->event.location();
631} 661}
632QString OEffectiveEvent::note()const { 662QString OEffectiveEvent::note()const {
633 return data->event.note(); 663 return data->event.note();
634} 664}
635OEvent OEffectiveEvent::event()const { 665OEvent OEffectiveEvent::event()const {
636 return data->event; 666 return data->event;
637} 667}
638QTime OEffectiveEvent::startTime()const { 668QTime OEffectiveEvent::startTime()const {
639 return data->start; 669 return data->start;
640} 670}
641QTime OEffectiveEvent::endTime()const { 671QTime OEffectiveEvent::endTime()const {
642 return data->end; 672 return data->end;
643} 673}
644QDate OEffectiveEvent::date()const { 674QDate OEffectiveEvent::date()const {
645 return data->date; 675 return data->date;
646} 676}
647int OEffectiveEvent::length()const { 677int 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}
651int OEffectiveEvent::size()const { 681int 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}
656QDate OEffectiveEvent::startDate()const { 686QDate 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}
664QDate OEffectiveEvent::endDate()const { 694QDate 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}
672void OEffectiveEvent::deref() { 702void 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}
678void OEffectiveEvent::changeOrModify() { 708void 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}
692bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ 722bool 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}
700bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ 730bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
701 return (data->date <= e.date() ); 731 return (data->date <= e.date() );
702} 732}
703bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { 733bool 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}
709bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { 739bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
710 return !(*this == e ); 740 return !(*this == e );
711} 741}
712bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { 742bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
713 return !(*this <= e ); 743 return !(*this <= e );
714} 744}
715bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { 745bool 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,111 +1,140 @@
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
44namespace Opie {
16struct OCalendarHelper { 45struct 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
31class OPimNotifyManager; 60class OPimNotifyManager;
32class ORecur; 61class 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 */
39class OEvent : public OPimRecord { 68class OEvent : public OPimRecord {
40public: 69public:
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 &notifiers()const; 124 OPimNotifyManager &notifiers()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;
@@ -140,97 +169,100 @@ public:
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*/
165private: 194private:
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 */
178class OEffectiveEvent { 207class OEffectiveEvent {
179public: 208public:
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
227private: 256private:
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 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = 4HEADERS = ocontact.h ocontactfields.h opimrecord.h otodo.h opimnotify.h opimnotifymanager.h oevent.h
5 5
6SOURCES = 6SOURCES = ocontact.cpp ocontactfields.cpp opimrecord.cpp otodo.cpp opimnotify.cpp \
7 opimnotifymanager.cpp oevent.cpp
7INTERFACES = 8INTERFACES =
8TARGET = opiepim2 9TARGET = opiepim2
9VERSION = 1.8.2 10VERSION = 1.8.2
10INCLUDEPATH += $(OPIEDIR)/include 11INCLUDEPATH += $(OPIEDIR)/include
11DEPENDPATH += $(OPIEDIR)/include 12DEPENDPATH += $(OPIEDIR)/include
12 13
14include ( core/core.pro )
15include ( core/backends/backends.pro )
16include ( ui/ui.pro )
17
13MOC_DIR = moc 18MOC_DIR = moc
14OBJECTS_DIR = obj 19OBJECTS_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
21contains( platform, x11 ) { 26contains( platform, x11 ) {
22 LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 27 LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
23} 28}
24 29
30LIBS += -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,104 +1,134 @@
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
38namespace Opie {
9 39
10class ORecordListIteratorPrivate; 40class 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 */
18template <class T> class ORecordList; 48template <class T> class ORecordList;
19template <class T = OPimRecord> 49template <class T = OPimRecord>
20class ORecordListIterator { 50class ORecordListIterator {
21 friend class ORecordList<T>; 51 friend class ORecordList<T>;
22public: 52public:
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
66private: 96private:
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
78class ORecordListPrivate; 108class 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 */
83template <class T = OPimRecord > 113template <class T = OPimRecord >
84class ORecordList { 114class ORecordList {
85public: 115public:
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 }
94ORecordList( const QArray<int>& ids, 124ORecordList( 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
@@ -209,98 +239,98 @@ bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
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}
216template <class T> 246template <class T>
217bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 247bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
218 return !(*this == it ); 248 return !(*this == it );
219} 249}
220template <class T> 250template <class T>
221ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, 251ORecordListIterator<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}
230template <class T> 260template <class T>
231uint ORecordListIterator<T>::current()const { 261uint ORecordListIterator<T>::current()const {
232 return m_current; 262 return m_current;
233} 263}
234template <class T> 264template <class T>
235void ORecordListIterator<T>::setCurrent( uint cur ) { 265void 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}
241template <class T> 271template <class T>
242uint ORecordListIterator<T>::count()const { 272uint ORecordListIterator<T>::count()const {
243 return m_uids.count(); 273 return m_uids.count();
244} 274}
245template <class T> 275template <class T>
246ORecordList<T>::ORecordList( const QArray<int>& ids, 276ORecordList<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}
251template <class T> 281template <class T>
252ORecordList<T>::~ORecordList() { 282ORecordList<T>::~ORecordList() {
253/* nothing to do here */ 283/* nothing to do here */
254} 284}
255template <class T> 285template <class T>
256typename ORecordList<T>::Iterator ORecordList<T>::begin() { 286typename 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}
260template <class T> 290template <class T>
261typename ORecordList<T>::Iterator ORecordList<T>::end() { 291typename 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}
268template <class T> 298template <class T>
269uint ORecordList<T>::count()const { 299uint ORecordList<T>::count()const {
270return m_ids.count(); 300return m_ids.count();
271} 301}
272template <class T> 302template <class T>
273T ORecordList<T>::operator[]( uint i ) { 303T 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}
279template <class T> 309template <class T>
280int ORecordList<T>::uidAt( uint i ) { 310int ORecordList<T>::uidAt( uint i ) {
281 return m_ids[i]; 311 return m_ids[i];
282} 312}
283 313
284template <class T> 314template <class T>
285bool ORecordList<T>::remove( int uid ) { 315bool 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,118 +1,146 @@
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
50namespace Opie {
23 51
24struct OTodo::OTodoData : public QShared { 52struct 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
53OTodo::OTodo(const OTodo &event ) 81OTodo::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}
59OTodo::~OTodo() { 87OTodo::~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}
68OTodo::OTodo(bool completed, int priority, 96OTodo::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}
89OTodo::OTodo(bool completed, int priority, 117OTodo::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}
110bool OTodo::match( const QRegExp &regExp )const 138bool OTodo::match( const QRegExp &regExp )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 ){
@@ -425,96 +453,98 @@ void OTodo::deref() {
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}
431OTodo &OTodo::operator=(const OTodo &item ) 459OTodo &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
444QMap<int, QString> OTodo::toMap() const { 472QMap<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 */
472void OTodo::changeOrModify() { 500void 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 */
486void OTodo::copy( OTodoData* src, OTodoData* dest ) { 514void 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}
511QString OTodo::type() const { 539QString OTodo::type() const {
512 return QString::fromLatin1("OTodo"); 540 return QString::fromLatin1("OTodo");
513} 541}
514QString OTodo::recordField(int /*id*/ )const { 542QString OTodo::recordField(int /*id*/ )const {
515 return QString::null; 543 return QString::null;
516} 544}
517 545
518int OTodo::rtti(){ 546int 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,113 +1,142 @@
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
46namespace Opie {
18 47
19class OPimState; 48class OPimState;
20class ORecur; 49class ORecur;
21class OPimMaintainer; 50class OPimMaintainer;
22class OPimNotifyManager; 51class OPimNotifyManager;
23class OTodo : public OPimRecord { 52class OTodo : public OPimRecord {
24public: 53public:
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;
@@ -188,98 +217,99 @@ public:
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};
280inline bool OTodo::operator!=(const OTodo &toDoEvent )const { 309inline 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
40namespace Opie {
12OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, 41OPimMainWindow::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}
32OPimMainWindow::~OPimMainWindow() { 61OPimMainWindow::~OPimMainWindow() {
33 delete m_channel; 62 delete m_channel;
34} 63}
35QCopChannel* OPimMainWindow::channel() { 64QCopChannel* OPimMainWindow::channel() {
36 return m_channel; 65 return m_channel;
37} 66}
38void OPimMainWindow::doSetDocument( const QString& ) { 67void OPimMainWindow::doSetDocument( const QString& ) {
39 68
40} 69}
41void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { 70void 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 */
102void OPimMainWindow::setDocument( const QString& str) { 131void 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 */
109OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { 138OPimRecord* 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 */
125int OPimMainWindow::service() { 154int 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}
131void OPimMainWindow::doAlarm( const QDateTime&, int ) { 160void OPimMainWindow::doAlarm( const QDateTime&, int ) {
132 161
133} 162}
134void OPimMainWindow::startAlarm(int count ) { 163void 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}
140void OPimMainWindow::killAlarm() { 169void OPimMainWindow::killAlarm() {
141 killTimer( m_timerId ); 170 killTimer( m_timerId );
142} 171}
143void OPimMainWindow::timerEvent( QTimerEvent* e) { 172void 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>
35class QCopChannel;
36class QDateTime;
7 37
38namespace 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
22class QCopChannel;
23class QDateTime;
24class OPimMainWindow : public QMainWindow { 53class OPimMainWindow : public QMainWindow {
25 Q_OBJECT 54 Q_OBJECT
26public: 55public:
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
35protected slots: 64protected 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
64protected: 93protected:
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
73private slots: 102private 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
78private: 107private:
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 @@
1HEADERS += ui/opimmainwindow.h
2
3SOURCES += ui/opimmainwindow.cpp