author | zecke <zecke> | 2003-04-13 18:07:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-04-13 18:07:10 (UTC) |
commit | 6f610544d3db6198c90105b70fab1cc84f5a1fbd (patch) (unidiff) | |
tree | 964d18f0a4cca7383a31810aa922876751c4a22c | |
parent | 0b311079ff19798866291034663757103c6ba935 (diff) | |
download | opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.zip opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.tar.gz opie-6f610544d3db6198c90105b70fab1cc84f5a1fbd.tar.bz2 |
More API doc
QString -> const QString&
QString = 0l -> QString::null
26 files changed, 630 insertions, 246 deletions
diff --git a/libopie/pim/obackendfactory.h b/libopie/pim/obackendfactory.h index 3a73210..ad6cf5a 100644 --- a/libopie/pim/obackendfactory.h +++ b/libopie/pim/obackendfactory.h | |||
@@ -1,126 +1,150 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage Backends. | 2 | * Class to manage Backends. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; | 9 | * License as published by the Free Software Foundation; |
10 | * either version 2 of the License, or (at your option) any later | 10 | * either version 2 of the License, or (at your option) any later |
11 | * version. | 11 | * version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: Use plugins | 13 | * ToDo: Use plugins |
14 | * ===================================================================== | 14 | * ===================================================================== |
15 | * Version: $Id$ | 15 | * Version: $Id$ |
16 | * ===================================================================== | 16 | * ===================================================================== |
17 | * History: | 17 | * History: |
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.6 2003/04/13 18:07:10 zecke | ||
20 | * More API doc | ||
21 | * QString -> const QString& | ||
22 | * QString = 0l -> QString::null | ||
23 | * | ||
19 | * Revision 1.5 2003/02/21 23:31:52 zecke | 24 | * Revision 1.5 2003/02/21 23:31:52 zecke |
20 | * Add XML datebookresource | 25 | * Add XML datebookresource |
21 | * -clean up todoaccessxml header | 26 | * -clean up todoaccessxml header |
22 | * -implement some more stuff in the oeven tester | 27 | * -implement some more stuff in the oeven tester |
23 | * -extend DefaultFactory to not crash and to use datebook | 28 | * -extend DefaultFactory to not crash and to use datebook |
24 | * | 29 | * |
25 | * -reading of OEvents is working nicely.. saving will be added | 30 | * -reading of OEvents is working nicely.. saving will be added |
26 | * tomorrow | 31 | * tomorrow |
27 | * -fix spelling in ODateBookAcces | 32 | * -fix spelling in ODateBookAcces |
28 | * | 33 | * |
29 | * Revision 1.4 2002/10/14 15:55:18 eilers | 34 | * Revision 1.4 2002/10/14 15:55:18 eilers |
30 | * Redeactivate SQL.. ;) | 35 | * Redeactivate SQL.. ;) |
31 | * | 36 | * |
32 | * Revision 1.3 2002/10/10 17:08:58 zecke | 37 | * Revision 1.3 2002/10/10 17:08:58 zecke |
33 | * The Cache is finally in place | 38 | * The Cache is finally in place |
34 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) | 39 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) |
35 | * 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.... | 40 | * 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.... |
36 | * I still have to fully implement read ahead | 41 | * I still have to fully implement read ahead |
37 | * This change is bic but sc | 42 | * This change is bic but sc |
38 | * | 43 | * |
39 | * Revision 1.2 2002/10/08 09:27:36 eilers | 44 | * Revision 1.2 2002/10/08 09:27:36 eilers |
40 | * Fixed libopie.pro to include the new pim-API. | 45 | * Fixed libopie.pro to include the new pim-API. |
41 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | 46 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to |
42 | * compile itself would need to install libsqlite, libopiesql... | 47 | * compile itself would need to install libsqlite, libopiesql... |
43 | * Therefore, the backend currently uses XML only.. | 48 | * Therefore, the backend currently uses XML only.. |
44 | * | 49 | * |
45 | * Revision 1.1 2002/10/07 17:35:01 eilers | 50 | * Revision 1.1 2002/10/07 17:35:01 eilers |
46 | * added OBackendFactory for advanced backend access | 51 | * added OBackendFactory for advanced backend access |
47 | * | 52 | * |
48 | * | 53 | * |
49 | * ===================================================================== | 54 | * ===================================================================== |
50 | */ | 55 | */ |
51 | #ifndef OPIE_BACKENDFACTORY_H_ | 56 | #ifndef OPIE_BACKENDFACTORY_H_ |
52 | #define OPIE_BACKENDFACTORY_H_ | 57 | #define OPIE_BACKENDFACTORY_H_ |
53 | 58 | ||
54 | #include <qstring.h> | 59 | #include <qstring.h> |
55 | #include <qasciidict.h> | 60 | #include <qasciidict.h> |
56 | #include <qpe/config.h> | 61 | #include <qpe/config.h> |
57 | 62 | ||
58 | #include "otodoaccessxml.h" | 63 | #include "otodoaccessxml.h" |
59 | #include "ocontactaccessbackend_xml.h" | 64 | #include "ocontactaccessbackend_xml.h" |
60 | #include "odatebookaccessbackend_xml.h" | 65 | #include "odatebookaccessbackend_xml.h" |
61 | 66 | ||
62 | #ifdef __USE_SQL | 67 | #ifdef __USE_SQL |
63 | #include "otodoaccesssql.h" | 68 | #include "otodoaccesssql.h" |
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | 71 | /** | |
72 | * This class is our factory. It will give us the default implementations | ||
73 | * of at least Todolist, Contacts and Datebook. In the future this class will | ||
74 | * allow users to switch the backend with ( XML->SQLite ) without the need | ||
75 | * to recompile.# | ||
76 | * This class as the whole PIM Api is making use of templates | ||
77 | * | ||
78 | * <pre> | ||
79 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | ||
80 | * backend->load(); | ||
81 | * </pre> | ||
82 | * | ||
83 | * @author Stefan Eilers | ||
84 | * @version 0.1 | ||
85 | */ | ||
67 | template<class T> | 86 | template<class T> |
68 | class OBackendFactory | 87 | class OBackendFactory |
69 | { | 88 | { |
70 | public: | 89 | public: |
71 | OBackendFactory() {}; | 90 | OBackendFactory() {}; |
72 | 91 | ||
73 | enum BACKENDS { | 92 | enum BACKENDS { |
74 | TODO, | 93 | TODO, |
75 | CONTACT, | 94 | CONTACT, |
76 | DATE | 95 | DATE |
77 | }; | 96 | }; |
78 | 97 | ||
98 | /** | ||
99 | * Returns a backend implementation for backendName | ||
100 | * @param backendName the type of the backend | ||
101 | * @param appName will be passed on to the backend | ||
102 | */ | ||
79 | static T* Default( const QString backendName, const QString& appName ){ | 103 | static T* Default( const QString backendName, const QString& appName ){ |
80 | 104 | ||
81 | // __asm__("int3"); | 105 | // __asm__("int3"); |
82 | 106 | ||
83 | Config config( "pimaccess" ); | 107 | Config config( "pimaccess" ); |
84 | config.setGroup ( backendName ); | 108 | config.setGroup ( backendName ); |
85 | QString backend = config.readEntry( "usebackend" ); | 109 | QString backend = config.readEntry( "usebackend" ); |
86 | 110 | ||
87 | QAsciiDict<int> dict ( 3 ); | 111 | QAsciiDict<int> dict ( 3 ); |
88 | dict.setAutoDelete ( TRUE ); | 112 | dict.setAutoDelete ( TRUE ); |
89 | 113 | ||
90 | dict.insert( "todo", new int (TODO) ); | 114 | dict.insert( "todo", new int (TODO) ); |
91 | dict.insert( "contact", new int (CONTACT) ); | 115 | dict.insert( "contact", new int (CONTACT) ); |
92 | dict.insert( "datebook", new int(DATE) ); | 116 | dict.insert( "datebook", new int(DATE) ); |
93 | 117 | ||
94 | qWarning ("TODO is: %d", TODO); | 118 | qWarning ("TODO is: %d", TODO); |
95 | qWarning ("CONTACT is: %d", CONTACT); | 119 | qWarning ("CONTACT is: %d", CONTACT); |
96 | 120 | ||
97 | int *find = dict[ backendName ]; | 121 | int *find = dict[ backendName ]; |
98 | if (!find ) return 0; | 122 | if (!find ) return 0; |
99 | 123 | ||
100 | switch ( *find ){ | 124 | switch ( *find ){ |
101 | case TODO: | 125 | case TODO: |
102 | #ifdef __USE_SQL | 126 | #ifdef __USE_SQL |
103 | if ( backend == "sql" ) | 127 | if ( backend == "sql" ) |
104 | return (T*) new OTodoAccessBackendSQL(""); | 128 | return (T*) new OTodoAccessBackendSQL(""); |
105 | #else | 129 | #else |
106 | if ( backend == "sql" ) | 130 | if ( backend == "sql" ) |
107 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 131 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
108 | #endif | 132 | #endif |
109 | 133 | ||
110 | return (T*) new OTodoAccessXML( appName ); | 134 | return (T*) new OTodoAccessXML( appName ); |
111 | case CONTACT: | 135 | case CONTACT: |
112 | if ( backend == "sql" ) | 136 | if ( backend == "sql" ) |
113 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 137 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
114 | 138 | ||
115 | return (T*) new OContactAccessBackend_XML( appName ); | 139 | return (T*) new OContactAccessBackend_XML( appName ); |
116 | case DATE: | 140 | case DATE: |
117 | if ( backend == "sql" ) | 141 | if ( backend == "sql" ) |
118 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 142 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
119 | 143 | ||
120 | return (T*) new ODateBookAccessBackend_XML( appName ); | 144 | return (T*) new ODateBookAccessBackend_XML( appName ); |
121 | default: | 145 | default: |
122 | return NULL; | 146 | return NULL; |
123 | } | 147 | } |
124 | 148 | ||
125 | 149 | ||
126 | } | 150 | } |
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h index 1fd1c75..25fa0e7 100644 --- a/libopie/pim/ocontact.h +++ b/libopie/pim/ocontact.h | |||
@@ -1,86 +1,93 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of the Qtopia Environment. | 5 | ** This file is part of the Qtopia Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #ifndef __OCONTACT_H__ | 22 | #ifndef __OCONTACT_H__ |
23 | #define __OCONTACT_H__ | 23 | #define __OCONTACT_H__ |
24 | 24 | ||
25 | #include <opie/opimrecord.h> | 25 | #include <opie/opimrecord.h> |
26 | #include <qpe/recordfields.h> | 26 | #include <qpe/recordfields.h> |
27 | 27 | ||
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | 30 | ||
31 | #if defined(QPC_TEMPLATEDLL) | 31 | #if defined(QPC_TEMPLATEDLL) |
32 | // MOC_SKIP_BEGIN | 32 | // MOC_SKIP_BEGIN |
33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; | 33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
34 | // MOC_SKIP_END | 34 | // MOC_SKIP_END |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | class ContactPrivate; | 37 | class ContactPrivate; |
38 | 38 | ||
39 | /** | ||
40 | * OContact class represents a specialised PIM Record for contacts. | ||
41 | * It does store all kind of persopn related information. | ||
42 | * | ||
43 | * @short Contact Container | ||
44 | * @author TT, Stefan Eiler, Holger Freyther | ||
45 | */ | ||
39 | class QPC_EXPORT OContact : public OPimRecord | 46 | class QPC_EXPORT OContact : public OPimRecord |
40 | { | 47 | { |
41 | friend class DataSet; | 48 | friend class DataSet; |
42 | public: | 49 | public: |
43 | OContact(); | 50 | OContact(); |
44 | OContact( const QMap<int, QString> &fromMap ); | 51 | OContact( const QMap<int, QString> &fromMap ); |
45 | virtual ~OContact(); | 52 | virtual ~OContact(); |
46 | 53 | ||
47 | /* | 54 | /* |
48 | * do we need to inline them | 55 | * do we need to inline them |
49 | * if yes do we need to inline them this way? | 56 | * if yes do we need to inline them this way? |
50 | * -zecke | 57 | * -zecke |
51 | */ | 58 | */ |
52 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 59 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
53 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 60 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
54 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 61 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
55 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 62 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
56 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 63 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
57 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 64 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
58 | void setFileAs(); | 65 | void setFileAs(); |
59 | 66 | ||
60 | // default email address | 67 | // default email address |
61 | void setDefaultEmail( const QString &v ); | 68 | void setDefaultEmail( const QString &v ); |
62 | // inserts email to list and ensure's doesn't already exist | 69 | // inserts email to list and ensure's doesn't already exist |
63 | void insertEmail( const QString &v ); | 70 | void insertEmail( const QString &v ); |
64 | void removeEmail( const QString &v ); | 71 | void removeEmail( const QString &v ); |
65 | void clearEmails(); | 72 | void clearEmails(); |
66 | void insertEmails( const QStringList &v ); | 73 | void insertEmails( const QStringList &v ); |
67 | 74 | ||
68 | // home | 75 | // home |
69 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 76 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
70 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 77 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
71 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 78 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
72 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 79 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
73 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 80 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
74 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 81 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
75 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 82 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
76 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 83 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
77 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 84 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
78 | 85 | ||
79 | // business | 86 | // business |
80 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 87 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
81 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 88 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
82 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 89 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
83 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 90 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
84 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 91 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
85 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 92 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
86 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 93 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h index 32b2dcb..d7ceaf2 100644 --- a/libopie/pim/ocontactaccess.h +++ b/libopie/pim/ocontactaccess.h | |||
@@ -1,150 +1,160 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage the Contacts. | 2 | * Class to manage the Contacts. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; | 10 | * License as published by the Free Software Foundation; |
11 | * either version 2 of the License, or (at your option) any later | 11 | * either version 2 of the License, or (at your option) any later |
12 | * version. | 12 | * version. |
13 | * ===================================================================== | 13 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 14 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.7 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.6 2003/01/02 14:27:12 eilers | 25 | * Revision 1.6 2003/01/02 14:27:12 eilers |
21 | * Improved query by example: Search by date is possible.. First step | 26 | * Improved query by example: Search by date is possible.. First step |
22 | * for a today plugin for birthdays.. | 27 | * for a today plugin for birthdays.. |
23 | * | 28 | * |
24 | * Revision 1.5 2002/11/13 14:14:51 eilers | 29 | * Revision 1.5 2002/11/13 14:14:51 eilers |
25 | * Added sorted for Contacts.. | 30 | * Added sorted for Contacts.. |
26 | * | 31 | * |
27 | * Revision 1.4 2002/11/01 15:10:42 eilers | 32 | * Revision 1.4 2002/11/01 15:10:42 eilers |
28 | * Added regExp-search in database for all fields in a contact. | 33 | * Added regExp-search in database for all fields in a contact. |
29 | * | 34 | * |
30 | * Revision 1.3 2002/10/16 10:52:40 eilers | 35 | * Revision 1.3 2002/10/16 10:52:40 eilers |
31 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 36 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
32 | * | 37 | * |
33 | * Revision 1.2 2002/10/14 16:21:54 eilers | 38 | * Revision 1.2 2002/10/14 16:21:54 eilers |
34 | * Some minor interface updates | 39 | * Some minor interface updates |
35 | * | 40 | * |
36 | * Revision 1.1 2002/09/27 17:11:44 eilers | 41 | * Revision 1.1 2002/09/27 17:11:44 eilers |
37 | * Added API for accessing the Contact-Database ! It is compiling, but | 42 | * Added API for accessing the Contact-Database ! It is compiling, but |
38 | * please do not expect that anything is working ! | 43 | * please do not expect that anything is working ! |
39 | * I will debug that stuff in the next time .. | 44 | * I will debug that stuff in the next time .. |
40 | * Please read README_COMPILE for compiling ! | 45 | * Please read README_COMPILE for compiling ! |
41 | * | 46 | * |
42 | * ===================================================================== | 47 | * ===================================================================== |
43 | */ | 48 | */ |
44 | #ifndef _OCONTACTACCESS_H | 49 | #ifndef _OCONTACTACCESS_H |
45 | #define _OCONTACTACCESS_H | 50 | #define _OCONTACTACCESS_H |
46 | 51 | ||
47 | #include <qobject.h> | 52 | #include <qobject.h> |
48 | 53 | ||
49 | #include <qpe/qcopenvelope_qws.h> | 54 | #include <qpe/qcopenvelope_qws.h> |
50 | 55 | ||
51 | #include <qvaluelist.h> | 56 | #include <qvaluelist.h> |
52 | #include <qfileinfo.h> | 57 | #include <qfileinfo.h> |
53 | 58 | ||
54 | #include "ocontact.h" | 59 | #include "ocontact.h" |
55 | #include "ocontactaccessbackend.h" | 60 | #include "ocontactaccessbackend.h" |
56 | #include "opimaccesstemplate.h" | 61 | #include "opimaccesstemplate.h" |
57 | 62 | ||
58 | /** Class to access the contacts database. | 63 | /** |
64 | * Class to access the contacts database. | ||
59 | * This is just a frontend for the real database handling which is | 65 | * This is just a frontend for the real database handling which is |
60 | * done by the backend. | 66 | * done by the backend. |
67 | * This class is used to access the Contacts on a system. This class as any OPIE PIM | ||
68 | * class is backend independent. | ||
69 | |||
61 | * @see OPimAccessTemplate | 70 | * @see OPimAccessTemplate |
62 | */ | 71 | */ |
63 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 72 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
64 | { | 73 | { |
65 | Q_OBJECT | 74 | Q_OBJECT |
66 | 75 | ||
67 | public: | 76 | public: |
68 | /** Create Database with contacts (addressbook). | 77 | /** |
78 | * Create Database with contacts (addressbook). | ||
69 | * @param appname Name of application which wants access to the database | 79 | * @param appname Name of application which wants access to the database |
70 | * (i.e. "todolist") | 80 | * (i.e. "todolist") |
71 | * @param filename The name of the database file. If not set, the default one | 81 | * @param filename The name of the database file. If not set, the default one |
72 | * is used. | 82 | * is used. |
73 | * @param backend Pointer to an alternative Backend. If not set, we will use | 83 | * @param backend Pointer to an alternative Backend. If not set, we will use |
74 | * the default backend. | 84 | * the default backend. |
75 | * @param handlesync If <b>true</b> the database stores the current state | 85 | * @param handlesync If <b>true</b> the database stores the current state |
76 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 86 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
77 | * which are used before and after synchronisation. If the application wants | 87 | * which are used before and after synchronisation. If the application wants |
78 | * to react itself, it should be disabled by setting it to <b>false</b> | 88 | * to react itself, it should be disabled by setting it to <b>false</b> |
79 | * @see OContactAccessBackend | 89 | * @see OContactAccessBackend |
80 | */ | 90 | */ |
81 | OContactAccess (const QString appname, const QString filename = 0l, | 91 | OContactAccess (const QString appname, const QString filename = 0l, |
82 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 92 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
83 | ~OContactAccess (); | 93 | ~OContactAccess (); |
84 | 94 | ||
85 | /** Constants for query. | 95 | /** Constants for query. |
86 | * Use this constants to set the query parameters. | 96 | * Use this constants to set the query parameters. |
87 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 97 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
88 | * @see queryByExample() | 98 | * @see queryByExample() |
89 | */ | 99 | */ |
90 | enum QuerySettings { | 100 | enum QuerySettings { |
91 | WildCards = 0x0001, | 101 | WildCards = 0x0001, |
92 | IgnoreCase = 0x0002, | 102 | IgnoreCase = 0x0002, |
93 | RegExp = 0x0004, | 103 | RegExp = 0x0004, |
94 | ExactMatch = 0x0008, | 104 | ExactMatch = 0x0008, |
95 | MatchOne = 0x0010, // Only one Entry must match | 105 | MatchOne = 0x0010, // Only one Entry must match |
96 | DateDiff = 0x0020, // Find all entries from today until given date | 106 | DateDiff = 0x0020, // Find all entries from today until given date |
97 | DateYear = 0x0040, // The year matches | 107 | DateYear = 0x0040, // The year matches |
98 | DateMonth = 0x0080, // The month matches | 108 | DateMonth = 0x0080, // The month matches |
99 | DateDay = 0x0100, // The day matches | 109 | DateDay = 0x0100, // The day matches |
100 | }; | 110 | }; |
101 | 111 | ||
102 | 112 | ||
103 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; | 113 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; |
104 | 114 | ||
105 | /** Return all Contacts in a sorted manner. | 115 | /** Return all Contacts in a sorted manner. |
106 | * @param ascending true: Sorted in acending order. | 116 | * @param ascending true: Sorted in acending order. |
107 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | 117 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess |
108 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | 118 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess |
109 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | 119 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess |
110 | */ | 120 | */ |
111 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | 121 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; |
112 | 122 | ||
113 | /** Return all possible settings. | 123 | /** Return all possible settings. |
114 | * @return All settings provided by the current backend | 124 | * @return All settings provided by the current backend |
115 | * (i.e.: query_WildCards & query_IgnoreCase) | 125 | * (i.e.: query_WildCards & query_IgnoreCase) |
116 | */ | 126 | */ |
117 | const uint querySettings(); | 127 | const uint querySettings(); |
118 | 128 | ||
119 | /** Check whether settings are correct. | 129 | /** Check whether settings are correct. |
120 | * @return <i>true</i> if the given settings are correct and possible. | 130 | * @return <i>true</i> if the given settings are correct and possible. |
121 | */ | 131 | */ |
122 | bool hasQuerySettings ( int querySettings ) const; | 132 | bool hasQuerySettings ( int querySettings ) const; |
123 | 133 | ||
124 | /** | 134 | /** |
125 | * if the resource was changed externally. | 135 | * if the resource was changed externally. |
126 | * You should use the signal instead of polling possible changes ! | 136 | * You should use the signal instead of polling possible changes ! |
127 | */ | 137 | */ |
128 | bool wasChangedExternally()const; | 138 | bool wasChangedExternally()const; |
129 | 139 | ||
130 | 140 | ||
131 | /** Save contacts database. | 141 | /** Save contacts database. |
132 | * Save is more a "commit". After calling this function, all changes are public available. | 142 | * Save is more a "commit". After calling this function, all changes are public available. |
133 | * @return true if successful | 143 | * @return true if successful |
134 | */ | 144 | */ |
135 | bool save(); | 145 | bool save(); |
136 | 146 | ||
137 | signals: | 147 | signals: |
138 | /* Signal is emitted if the database was changed. Therefore | 148 | /* Signal is emitted if the database was changed. Therefore |
139 | * we may need to reload to stay consistent. | 149 | * we may need to reload to stay consistent. |
140 | * @param which Pointer to the database who created this event. This pointer | 150 | * @param which Pointer to the database who created this event. This pointer |
141 | * is useful if an application has to handle multiple databases at the same time. | 151 | * is useful if an application has to handle multiple databases at the same time. |
142 | * @see reload() | 152 | * @see reload() |
143 | */ | 153 | */ |
144 | void signalChanged ( const OContactAccess *which ); | 154 | void signalChanged ( const OContactAccess *which ); |
145 | 155 | ||
146 | 156 | ||
147 | private: | 157 | private: |
148 | // class OContactAccessPrivate; | 158 | // class OContactAccessPrivate; |
149 | // OContactAccessPrivate* d; | 159 | // OContactAccessPrivate* d; |
150 | OContactAccessBackend *m_backEnd; | 160 | OContactAccessBackend *m_backEnd; |
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h index 821f5bf..ebeb42d 100644 --- a/libopie/pim/ocontactaccessbackend.h +++ b/libopie/pim/ocontactaccessbackend.h | |||
@@ -1,85 +1,107 @@ | |||
1 | /** | 1 | /** |
2 | * The class responsible for managing a backend. | 2 | * The class responsible for managing a backend. |
3 | * The implementation of this abstract class contains | 3 | * The implementation of this abstract class contains |
4 | * the complete database handling. | 4 | * the complete database handling. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
8 | * | 8 | * |
9 | * ===================================================================== | 9 | * ===================================================================== |
10 | *This program is free software; you can redistribute it and/or | 10 | *This program is free software; you can redistribute it and/or |
11 | *modify it under the terms of the GNU Library General Public | 11 | *modify it under the terms of the GNU Library General Public |
12 | * License as published by the Free Software Foundation; | 12 | * License as published by the Free Software Foundation; |
13 | * either version 2 of the License, or (at your option) any later | 13 | * either version 2 of the License, or (at your option) any later |
14 | * version. | 14 | * version. |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: Define enum for query settings | 16 | * ToDo: Define enum for query settings |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * Version: $Id$ | 18 | * Version: $Id$ |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
23 | * More API doc | ||
24 | * QString -> const QString& | ||
25 | * QString = 0l -> QString::null | ||
26 | * | ||
22 | * Revision 1.4 2002/11/13 14:14:51 eilers | 27 | * Revision 1.4 2002/11/13 14:14:51 eilers |
23 | * Added sorted for Contacts.. | 28 | * Added sorted for Contacts.. |
24 | * | 29 | * |
25 | * Revision 1.3 2002/11/01 15:10:42 eilers | 30 | * Revision 1.3 2002/11/01 15:10:42 eilers |
26 | * Added regExp-search in database for all fields in a contact. | 31 | * Added regExp-search in database for all fields in a contact. |
27 | * | 32 | * |
28 | * Revision 1.2 2002/10/07 17:34:24 eilers | 33 | * Revision 1.2 2002/10/07 17:34:24 eilers |
29 | * added OBackendFactory for advanced backend access | 34 | * added OBackendFactory for advanced backend access |
30 | * | 35 | * |
31 | * Revision 1.1 2002/09/27 17:11:44 eilers | 36 | * Revision 1.1 2002/09/27 17:11:44 eilers |
32 | * Added API for accessing the Contact-Database ! It is compiling, but | 37 | * Added API for accessing the Contact-Database ! It is compiling, but |
33 | * please do not expect that anything is working ! | 38 | * please do not expect that anything is working ! |
34 | * I will debug that stuff in the next time .. | 39 | * I will debug that stuff in the next time .. |
35 | * Please read README_COMPILE for compiling ! | 40 | * Please read README_COMPILE for compiling ! |
36 | * | 41 | * |
37 | * ===================================================================== | 42 | * ===================================================================== |
38 | * | 43 | * |
39 | */ | 44 | */ |
40 | 45 | ||
41 | #ifndef _OCONTACTACCESSBACKEND_H_ | 46 | #ifndef _OCONTACTACCESSBACKEND_H_ |
42 | #define _OCONTACTACCESSBACKEND_H_ | 47 | #define _OCONTACTACCESSBACKEND_H_ |
43 | 48 | ||
44 | #include "ocontact.h" | 49 | #include "ocontact.h" |
45 | #include "opimaccessbackend.h" | 50 | #include "opimaccessbackend.h" |
46 | 51 | ||
47 | #include "qregexp.h" | 52 | #include <qregexp.h> |
48 | 53 | ||
54 | /** | ||
55 | * This class represents the interface of all Contact Backends. | ||
56 | * Derivates of this class will be used to access the contacts. | ||
57 | * As implementation currently XML and vCard exist. This class needs to be implemented | ||
58 | * if you want to provide your own storage. | ||
59 | * In all queries a list of uids is passed on instead of loading the actual record! | ||
60 | * | ||
61 | * @see OContactAccessBackend_VCard | ||
62 | * @see OContactAccessBackend_XML | ||
63 | */ | ||
49 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 64 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
50 | public: | 65 | public: |
51 | OContactAccessBackend() {} | 66 | OContactAccessBackend() {} |
52 | virtual ~OContactAccessBackend() {} | 67 | virtual ~OContactAccessBackend() {} |
53 | 68 | ||
54 | 69 | ||
55 | /** Return if database was changed externally. | 70 | /** |
71 | * Return if database was changed externally. | ||
56 | * 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. |
57 | * It is used to prevent to overwrite the current database content | 73 | * It is used to prevent to overwrite the current database content |
58 | * if the file was already changed by something else ! | 74 | * if the file was already changed by something else ! |
59 | * If this happens, we have to reload before save our data. | 75 | * If this happens, we have to reload before save our data. |
60 | * 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 |
61 | * management system themselve, therefore this function should always return false in | 77 | * management system themselve, therefore this function should always return false in |
62 | * this case. It is not our problem to handle this conflict ... | 78 | * this case. It is not our problem to handle this conflict ... |
63 | * @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 |
64 | * 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 |
65 | * in this situation. | 81 | * in this situation. |
66 | */ | 82 | */ |
67 | virtual bool wasChangedExternally() = 0; | 83 | virtual bool wasChangedExternally() = 0; |
68 | 84 | ||
69 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 85 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
70 | 86 | ||
71 | /** Return all possible settings. | 87 | /** |
88 | * Return all possible settings. | ||
72 | * @return All settings provided by the current backend | 89 | * @return All settings provided by the current backend |
73 | * (i.e.: query_WildCards & query_IgnoreCase) | 90 | * (i.e.: query_WildCards & query_IgnoreCase) |
74 | */ | 91 | */ |
75 | virtual const uint querySettings() = 0; | 92 | virtual const uint querySettings() = 0; |
76 | 93 | ||
77 | /** Check whether settings are correct. | 94 | /** |
95 | * Check whether settings are correct. | ||
78 | * @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. |
79 | */ | 97 | */ |
80 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 98 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
81 | 99 | ||
82 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | 100 | /** |
101 | * FIXME!!! | ||
102 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category | ||
103 | */ | ||
104 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | ||
83 | 105 | ||
84 | }; | 106 | }; |
85 | #endif | 107 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp index f24523f..270bef3 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.cpp +++ b/libopie/pim/ocontactaccessbackend_vcard.cpp | |||
@@ -1,127 +1,132 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.10 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.9 2003/03/21 10:33:09 eilers | 25 | * Revision 1.9 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 28 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 29 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 30 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 31 | * the binaries for today-addressbook. |
27 | * | 32 | * |
28 | * Revision 1.8 2003/02/21 16:52:49 zecke | 33 | * Revision 1.8 2003/02/21 16:52:49 zecke |
29 | * -Remove old Todo classes they're deprecated and today I already using the | 34 | * -Remove old Todo classes they're deprecated and today I already using the |
30 | * new API | 35 | * new API |
31 | * -Guard against self assignment in OTodo | 36 | * -Guard against self assignment in OTodo |
32 | * -Add test apps for OPIM | 37 | * -Add test apps for OPIM |
33 | * -Opiefied Event classes | 38 | * -Opiefied Event classes |
34 | * -Added TimeZone handling and pinning of TimeZones to OEvent | 39 | * -Added TimeZone handling and pinning of TimeZones to OEvent |
35 | * -Adjust ORecur and the widget to better timezone behaviour | 40 | * -Adjust ORecur and the widget to better timezone behaviour |
36 | * | 41 | * |
37 | * Revision 1.7 2003/02/16 22:25:46 zecke | 42 | * Revision 1.7 2003/02/16 22:25:46 zecke |
38 | * 0000276 Fix for that bug.. or better temp workaround | 43 | * 0000276 Fix for that bug.. or better temp workaround |
39 | * A Preferred Number is HOME|VOICE | 44 | * A Preferred Number is HOME|VOICE |
40 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test | 45 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test |
41 | * triggers both | 46 | * triggers both |
42 | * and the cell phone number overrides the other entries.. | 47 | * and the cell phone number overrides the other entries.. |
43 | * | 48 | * |
44 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the | 49 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the |
45 | * number | 50 | * number |
46 | * | 51 | * |
47 | * The right and final fix would be to reorder the if statement to make it | 52 | * The right and final fix would be to reorder the if statement to make it |
48 | * if else based and the less common thing put to the bottom | 53 | * if else based and the less common thing put to the bottom |
49 | * | 54 | * |
50 | * OTodoAccessVcal fix the date for beaming | 55 | * OTodoAccessVcal fix the date for beaming |
51 | * | 56 | * |
52 | * Revision 1.6 2003/01/13 15:49:31 eilers | 57 | * Revision 1.6 2003/01/13 15:49:31 eilers |
53 | * Fixing crash when businesscard.vcf is missing.. | 58 | * Fixing crash when businesscard.vcf is missing.. |
54 | * | 59 | * |
55 | * Revision 1.5 2002/12/07 13:26:22 eilers | 60 | * Revision 1.5 2002/12/07 13:26:22 eilers |
56 | * Fixing bug in storing anniversary.. | 61 | * Fixing bug in storing anniversary.. |
57 | * | 62 | * |
58 | * Revision 1.4 2002/11/13 14:14:51 eilers | 63 | * Revision 1.4 2002/11/13 14:14:51 eilers |
59 | * Added sorted for Contacts.. | 64 | * Added sorted for Contacts.. |
60 | * | 65 | * |
61 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 66 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
62 | * no default arguments in implementation | 67 | * no default arguments in implementation |
63 | * | 68 | * |
64 | * Revision 1.2 2002/11/10 15:41:53 eilers | 69 | * Revision 1.2 2002/11/10 15:41:53 eilers |
65 | * Bugfixes.. | 70 | * Bugfixes.. |
66 | * | 71 | * |
67 | * Revision 1.1 2002/11/09 14:34:52 eilers | 72 | * Revision 1.1 2002/11/09 14:34:52 eilers |
68 | * Added VCard Backend. | 73 | * Added VCard Backend. |
69 | * | 74 | * |
70 | */ | 75 | */ |
71 | #include "ocontactaccessbackend_vcard.h" | 76 | #include "ocontactaccessbackend_vcard.h" |
72 | #include "../../library/backend/vobject_p.h" | 77 | #include "../../library/backend/vobject_p.h" |
73 | #include "../../library/backend/qfiledirect_p.h" | 78 | #include "../../library/backend/qfiledirect_p.h" |
74 | 79 | ||
75 | #include <qpe/timeconversion.h> | 80 | #include <qpe/timeconversion.h> |
76 | 81 | ||
77 | #include <qfile.h> | 82 | #include <qfile.h> |
78 | 83 | ||
79 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 84 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): |
80 | m_dirty( false ), | 85 | m_dirty( false ), |
81 | m_file( filename ) | 86 | m_file( filename ) |
82 | { | 87 | { |
83 | load(); | 88 | load(); |
84 | } | 89 | } |
85 | 90 | ||
86 | 91 | ||
87 | bool OContactAccessBackend_VCard::load () | 92 | bool OContactAccessBackend_VCard::load () |
88 | { | 93 | { |
89 | m_map.clear(); | 94 | m_map.clear(); |
90 | m_dirty = false; | 95 | m_dirty = false; |
91 | 96 | ||
92 | VObject* obj = 0l; | 97 | VObject* obj = 0l; |
93 | 98 | ||
94 | if ( QFile::exists(m_file) ){ | 99 | if ( QFile::exists(m_file) ){ |
95 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 100 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
96 | if ( !obj ) | 101 | if ( !obj ) |
97 | return false; | 102 | return false; |
98 | }else{ | 103 | }else{ |
99 | qWarning("File \"%s\" not found !", m_file.latin1() ); | 104 | qWarning("File \"%s\" not found !", m_file.latin1() ); |
100 | return false; | 105 | return false; |
101 | } | 106 | } |
102 | 107 | ||
103 | while ( obj ) { | 108 | while ( obj ) { |
104 | OContact con = parseVObject( obj ); | 109 | OContact con = parseVObject( obj ); |
105 | /* | 110 | /* |
106 | * if uid is 0 assign a new one | 111 | * if uid is 0 assign a new one |
107 | * this at least happens on | 112 | * this at least happens on |
108 | * Nokia6210 | 113 | * Nokia6210 |
109 | */ | 114 | */ |
110 | if ( con.uid() == 0 ){ | 115 | if ( con.uid() == 0 ){ |
111 | con.setUid( 1 ); | 116 | con.setUid( 1 ); |
112 | qWarning("assigned new uid %d",con.uid() ); | 117 | qWarning("assigned new uid %d",con.uid() ); |
113 | } | 118 | } |
114 | 119 | ||
115 | m_map.insert( con.uid(), con ); | 120 | m_map.insert( con.uid(), con ); |
116 | 121 | ||
117 | VObject *t = obj; | 122 | VObject *t = obj; |
118 | obj = nextVObjectInList(obj); | 123 | obj = nextVObjectInList(obj); |
119 | cleanVObject( t ); | 124 | cleanVObject( t ); |
120 | } | 125 | } |
121 | 126 | ||
122 | return true; | 127 | return true; |
123 | 128 | ||
124 | } | 129 | } |
125 | bool OContactAccessBackend_VCard::reload() | 130 | bool OContactAccessBackend_VCard::reload() |
126 | { | 131 | { |
127 | return load(); | 132 | return load(); |
diff --git a/libopie/pim/ocontactaccessbackend_vcard.h b/libopie/pim/ocontactaccessbackend_vcard.h index 93e2da3..712d769 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.h +++ b/libopie/pim/ocontactaccessbackend_vcard.h | |||
@@ -1,86 +1,96 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 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 | * | ||
20 | * Revision 1.5 2003/03/21 10:33:09 eilers | 25 | * Revision 1.5 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 28 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 29 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 30 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 31 | * the binaries for today-addressbook. |
27 | * | 32 | * |
28 | * Revision 1.4 2002/12/07 13:26:22 eilers | 33 | * Revision 1.4 2002/12/07 13:26:22 eilers |
29 | * Fixing bug in storing anniversary.. | 34 | * Fixing bug in storing anniversary.. |
30 | * | 35 | * |
31 | * Revision 1.3 2002/11/13 14:14:51 eilers | 36 | * Revision 1.3 2002/11/13 14:14:51 eilers |
32 | * Added sorted for Contacts.. | 37 | * Added sorted for Contacts.. |
33 | * | 38 | * |
34 | * Revision 1.2 2002/11/10 15:41:53 eilers | 39 | * Revision 1.2 2002/11/10 15:41:53 eilers |
35 | * Bugfixes.. | 40 | * Bugfixes.. |
36 | * | 41 | * |
37 | * Revision 1.1 2002/11/09 14:34:52 eilers | 42 | * Revision 1.1 2002/11/09 14:34:52 eilers |
38 | * Added VCard Backend. | 43 | * Added VCard Backend. |
39 | * | 44 | * |
40 | */ | 45 | */ |
41 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ | 46 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ |
42 | #define __OCONTACTACCESSBACKEND_VCARD_H_ | 47 | #define __OCONTACTACCESSBACKEND_VCARD_H_ |
43 | 48 | ||
44 | #include <opie/ocontact.h> | 49 | #include <opie/ocontact.h> |
45 | 50 | ||
46 | #include "ocontactaccessbackend.h" | 51 | #include "ocontactaccessbackend.h" |
47 | 52 | ||
48 | class VObject; | 53 | class VObject; |
49 | 54 | ||
55 | /** | ||
56 | * This is the vCard 2.1 implementation of the Contact Storage | ||
57 | * @see OContactAccessBackend_XML | ||
58 | * @see OPimAccessBackend | ||
59 | */ | ||
50 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 60 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
51 | public: | 61 | public: |
52 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); | 62 | OContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null ); |
53 | 63 | ||
54 | bool load (); | 64 | bool load (); |
55 | bool reload(); | 65 | bool reload(); |
56 | bool save(); | 66 | bool save(); |
57 | void clear (); | 67 | void clear (); |
58 | 68 | ||
59 | bool add ( const OContact& newcontact ); | 69 | bool add ( const OContact& newcontact ); |
60 | bool remove ( int uid ); | 70 | bool remove ( int uid ); |
61 | bool replace ( const OContact& contact ); | 71 | bool replace ( const OContact& contact ); |
62 | 72 | ||
63 | OContact find ( int uid ) const; | 73 | OContact find ( int uid ) const; |
64 | QArray<int> allRecords() const; | 74 | QArray<int> allRecords() const; |
65 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 75 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
66 | QArray<int> matchRegexp( const QRegExp &r ) const; | 76 | QArray<int> matchRegexp( const QRegExp &r ) const; |
67 | 77 | ||
68 | const uint querySettings(); | 78 | const uint querySettings(); |
69 | bool hasQuerySettings (uint querySettings) const; | 79 | bool hasQuerySettings (uint querySettings) const; |
70 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 80 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
71 | bool wasChangedExternally(); | 81 | bool wasChangedExternally(); |
72 | 82 | ||
73 | private: | 83 | private: |
74 | OContact parseVObject( VObject* obj ); | 84 | OContact parseVObject( VObject* obj ); |
75 | VObject* createVObject( const OContact& c ); | 85 | VObject* createVObject( const OContact& c ); |
76 | QString convDateToVCardDate( const QDate& c ) const; | 86 | QString convDateToVCardDate( const QDate& c ) const; |
77 | QDate convVCardDateToDate( const QString& datestr ); | 87 | QDate convVCardDateToDate( const QString& datestr ); |
78 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 88 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
79 | VObject *safeAddProp( VObject* o, const char* prop); | 89 | VObject *safeAddProp( VObject* o, const char* prop); |
80 | 90 | ||
81 | bool m_dirty : 1; | 91 | bool m_dirty : 1; |
82 | QString m_file; | 92 | QString m_file; |
83 | QMap<int, OContact> m_map; | 93 | QMap<int, OContact> m_map; |
84 | }; | 94 | }; |
85 | 95 | ||
86 | #endif | 96 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp index c5a7820..661cd51 100644 --- a/libopie/pim/ocontactaccessbackend_xml.cpp +++ b/libopie/pim/ocontactaccessbackend_xml.cpp | |||
@@ -1,784 +1,789 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 25 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
21 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | 26 | * g++ compliance fix: default arguments belong into the declaration, but not the definition |
22 | * | 27 | * |
23 | * Revision 1.3 2003/03/21 12:26:28 eilers | 28 | * Revision 1.3 2003/03/21 12:26:28 eilers |
24 | * Fixing small bug: If we search a birthday from today to today, it returned | 29 | * Fixing small bug: If we search a birthday from today to today, it returned |
25 | * every contact .. | 30 | * every contact .. |
26 | * | 31 | * |
27 | * Revision 1.2 2003/03/21 10:33:09 eilers | 32 | * Revision 1.2 2003/03/21 10:33:09 eilers |
28 | * Merged speed optimized xml backend for contacts to main. | 33 | * Merged speed optimized xml backend for contacts to main. |
29 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 34 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
30 | * all Birthdays/Anniversaries between two dates. This should be used | 35 | * all Birthdays/Anniversaries between two dates. This should be used |
31 | * to show all birthdays in the datebook.. | 36 | * to show all birthdays in the datebook.. |
32 | * This change is sourcecode backward compatible but you have to upgrade | 37 | * This change is sourcecode backward compatible but you have to upgrade |
33 | * the binaries for today-addressbook. | 38 | * the binaries for today-addressbook. |
34 | * | 39 | * |
35 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 40 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
36 | * Speed optimization. Removed the sequential search loops. | 41 | * Speed optimization. Removed the sequential search loops. |
37 | * | 42 | * |
38 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 43 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
39 | * Writing offsets to debug output.. | 44 | * Writing offsets to debug output.. |
40 | * | 45 | * |
41 | * Revision 1.1 2003/02/09 15:05:01 eilers | 46 | * Revision 1.1 2003/02/09 15:05:01 eilers |
42 | * Nothing happened.. Just some cleanup before I will start.. | 47 | * Nothing happened.. Just some cleanup before I will start.. |
43 | * | 48 | * |
44 | * Revision 1.12 2003/01/03 16:58:03 eilers | 49 | * Revision 1.12 2003/01/03 16:58:03 eilers |
45 | * Reenable debug output | 50 | * Reenable debug output |
46 | * | 51 | * |
47 | * Revision 1.11 2003/01/03 12:31:28 eilers | 52 | * Revision 1.11 2003/01/03 12:31:28 eilers |
48 | * Bugfix for calculating data diffs.. | 53 | * Bugfix for calculating data diffs.. |
49 | * | 54 | * |
50 | * Revision 1.10 2003/01/02 14:27:12 eilers | 55 | * Revision 1.10 2003/01/02 14:27:12 eilers |
51 | * Improved query by example: Search by date is possible.. First step | 56 | * Improved query by example: Search by date is possible.. First step |
52 | * for a today plugin for birthdays.. | 57 | * for a today plugin for birthdays.. |
53 | * | 58 | * |
54 | * Revision 1.9 2002/12/08 12:48:57 eilers | 59 | * Revision 1.9 2002/12/08 12:48:57 eilers |
55 | * Moved journal-enum from ocontact into i the xml-backend.. | 60 | * Moved journal-enum from ocontact into i the xml-backend.. |
56 | * | 61 | * |
57 | * Revision 1.8 2002/11/14 17:04:24 eilers | 62 | * Revision 1.8 2002/11/14 17:04:24 eilers |
58 | * Sorting will now work if fullname is identical on some entries | 63 | * Sorting will now work if fullname is identical on some entries |
59 | * | 64 | * |
60 | * Revision 1.7 2002/11/13 15:02:46 eilers | 65 | * Revision 1.7 2002/11/13 15:02:46 eilers |
61 | * Small Bug in sorted fixed | 66 | * Small Bug in sorted fixed |
62 | * | 67 | * |
63 | * Revision 1.6 2002/11/13 14:14:51 eilers | 68 | * Revision 1.6 2002/11/13 14:14:51 eilers |
64 | * Added sorted for Contacts.. | 69 | * Added sorted for Contacts.. |
65 | * | 70 | * |
66 | * Revision 1.5 2002/11/01 15:10:42 eilers | 71 | * Revision 1.5 2002/11/01 15:10:42 eilers |
67 | * Added regExp-search in database for all fields in a contact. | 72 | * Added regExp-search in database for all fields in a contact. |
68 | * | 73 | * |
69 | * Revision 1.4 2002/10/16 10:52:40 eilers | 74 | * Revision 1.4 2002/10/16 10:52:40 eilers |
70 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 75 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
71 | * | 76 | * |
72 | * Revision 1.3 2002/10/14 16:21:54 eilers | 77 | * Revision 1.3 2002/10/14 16:21:54 eilers |
73 | * Some minor interface updates | 78 | * Some minor interface updates |
74 | * | 79 | * |
75 | * Revision 1.2 2002/10/07 17:34:24 eilers | 80 | * Revision 1.2 2002/10/07 17:34:24 eilers |
76 | * added OBackendFactory for advanced backend access | 81 | * added OBackendFactory for advanced backend access |
77 | * | 82 | * |
78 | * Revision 1.1 2002/09/27 17:11:44 eilers | 83 | * Revision 1.1 2002/09/27 17:11:44 eilers |
79 | * Added API for accessing the Contact-Database ! It is compiling, but | 84 | * Added API for accessing the Contact-Database ! It is compiling, but |
80 | * please do not expect that anything is working ! | 85 | * please do not expect that anything is working ! |
81 | * I will debug that stuff in the next time .. | 86 | * I will debug that stuff in the next time .. |
82 | * Please read README_COMPILE for compiling ! | 87 | * Please read README_COMPILE for compiling ! |
83 | * | 88 | * |
84 | * | 89 | * |
85 | */ | 90 | */ |
86 | 91 | ||
87 | #include "ocontactaccessbackend_xml.h" | 92 | #include "ocontactaccessbackend_xml.h" |
88 | 93 | ||
89 | #include <qasciidict.h> | 94 | #include <qasciidict.h> |
90 | #include <qdatetime.h> | 95 | #include <qdatetime.h> |
91 | #include <qfile.h> | 96 | #include <qfile.h> |
92 | #include <qfileinfo.h> | 97 | #include <qfileinfo.h> |
93 | #include <qregexp.h> | 98 | #include <qregexp.h> |
94 | #include <qarray.h> | 99 | #include <qarray.h> |
95 | #include <qmap.h> | 100 | #include <qmap.h> |
96 | #include <qdatetime.h> | 101 | #include <qdatetime.h> |
97 | 102 | ||
98 | #include <qpe/global.h> | 103 | #include <qpe/global.h> |
99 | 104 | ||
100 | #include <opie/xmltree.h> | 105 | #include <opie/xmltree.h> |
101 | #include "ocontactaccessbackend.h" | 106 | #include "ocontactaccessbackend.h" |
102 | #include "ocontactaccess.h" | 107 | #include "ocontactaccess.h" |
103 | 108 | ||
104 | #include <stdlib.h> | 109 | #include <stdlib.h> |
105 | #include <errno.h> | 110 | #include <errno.h> |
106 | 111 | ||
107 | using namespace Opie; | 112 | using namespace Opie; |
108 | 113 | ||
109 | 114 | ||
110 | OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename ): | 115 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): |
111 | m_changed( false ) | 116 | m_changed( false ) |
112 | { | 117 | { |
113 | // Just m_contactlist should call delete if an entry | 118 | // Just m_contactlist should call delete if an entry |
114 | // is removed. | 119 | // is removed. |
115 | m_contactList.setAutoDelete( true ); | 120 | m_contactList.setAutoDelete( true ); |
116 | m_uidToContact.setAutoDelete( false ); | 121 | m_uidToContact.setAutoDelete( false ); |
117 | 122 | ||
118 | m_appName = appname; | 123 | m_appName = appname; |
119 | 124 | ||
120 | /* Set journalfile name ... */ | 125 | /* Set journalfile name ... */ |
121 | m_journalName = getenv("HOME"); | 126 | m_journalName = getenv("HOME"); |
122 | m_journalName +="/.abjournal" + appname; | 127 | m_journalName +="/.abjournal" + appname; |
123 | 128 | ||
124 | /* Expecting to access the default filename if nothing else is set */ | 129 | /* Expecting to access the default filename if nothing else is set */ |
125 | if ( filename.isEmpty() ){ | 130 | if ( filename.isEmpty() ){ |
126 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 131 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
127 | } else | 132 | } else |
128 | m_fileName = filename; | 133 | m_fileName = filename; |
129 | 134 | ||
130 | /* Load Database now */ | 135 | /* Load Database now */ |
131 | load (); | 136 | load (); |
132 | } | 137 | } |
133 | 138 | ||
134 | bool OContactAccessBackend_XML::save() | 139 | bool OContactAccessBackend_XML::save() |
135 | { | 140 | { |
136 | 141 | ||
137 | if ( !m_changed ) | 142 | if ( !m_changed ) |
138 | return true; | 143 | return true; |
139 | 144 | ||
140 | QString strNewFile = m_fileName + ".new"; | 145 | QString strNewFile = m_fileName + ".new"; |
141 | QFile f( strNewFile ); | 146 | QFile f( strNewFile ); |
142 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 147 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
143 | return false; | 148 | return false; |
144 | 149 | ||
145 | int total_written; | 150 | int total_written; |
146 | int idx_offset = 0; | 151 | int idx_offset = 0; |
147 | QString out; | 152 | QString out; |
148 | 153 | ||
149 | // Write Header | 154 | // Write Header |
150 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 155 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
151 | " <Groups>\n" | 156 | " <Groups>\n" |
152 | " </Groups>\n" | 157 | " </Groups>\n" |
153 | " <Contacts>\n"; | 158 | " <Contacts>\n"; |
154 | QCString cstr = out.utf8(); | 159 | QCString cstr = out.utf8(); |
155 | f.writeBlock( cstr.data(), cstr.length() ); | 160 | f.writeBlock( cstr.data(), cstr.length() ); |
156 | idx_offset += cstr.length(); | 161 | idx_offset += cstr.length(); |
157 | out = ""; | 162 | out = ""; |
158 | 163 | ||
159 | // Write all contacts | 164 | // Write all contacts |
160 | QListIterator<OContact> it( m_contactList ); | 165 | QListIterator<OContact> it( m_contactList ); |
161 | for ( ; it.current(); ++it ) { | 166 | for ( ; it.current(); ++it ) { |
162 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); | 167 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); |
163 | out += "<Contact "; | 168 | out += "<Contact "; |
164 | (*it)->save( out ); | 169 | (*it)->save( out ); |
165 | out += "/>\n"; | 170 | out += "/>\n"; |
166 | cstr = out.utf8(); | 171 | cstr = out.utf8(); |
167 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 172 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
168 | idx_offset += cstr.length(); | 173 | idx_offset += cstr.length(); |
169 | if ( total_written != int(cstr.length()) ) { | 174 | if ( total_written != int(cstr.length()) ) { |
170 | f.close(); | 175 | f.close(); |
171 | QFile::remove( strNewFile ); | 176 | QFile::remove( strNewFile ); |
172 | return false; | 177 | return false; |
173 | } | 178 | } |
174 | out = ""; | 179 | out = ""; |
175 | } | 180 | } |
176 | out += " </Contacts>\n</AddressBook>\n"; | 181 | out += " </Contacts>\n</AddressBook>\n"; |
177 | 182 | ||
178 | // Write Footer | 183 | // Write Footer |
179 | cstr = out.utf8(); | 184 | cstr = out.utf8(); |
180 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 185 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
181 | if ( total_written != int( cstr.length() ) ) { | 186 | if ( total_written != int( cstr.length() ) ) { |
182 | f.close(); | 187 | f.close(); |
183 | QFile::remove( strNewFile ); | 188 | QFile::remove( strNewFile ); |
184 | return false; | 189 | return false; |
185 | } | 190 | } |
186 | f.close(); | 191 | f.close(); |
187 | 192 | ||
188 | // move the file over, I'm just going to use the system call | 193 | // move the file over, I'm just going to use the system call |
189 | // because, I don't feel like using QDir. | 194 | // because, I don't feel like using QDir. |
190 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 195 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
191 | qWarning( "problem renaming file %s to %s, errno: %d", | 196 | qWarning( "problem renaming file %s to %s, errno: %d", |
192 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 197 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
193 | // remove the tmp file... | 198 | // remove the tmp file... |
194 | QFile::remove( strNewFile ); | 199 | QFile::remove( strNewFile ); |
195 | } | 200 | } |
196 | 201 | ||
197 | /* The journalfile should be removed now... */ | 202 | /* The journalfile should be removed now... */ |
198 | removeJournal(); | 203 | removeJournal(); |
199 | 204 | ||
200 | m_changed = false; | 205 | m_changed = false; |
201 | return true; | 206 | return true; |
202 | } | 207 | } |
203 | 208 | ||
204 | bool OContactAccessBackend_XML::load () | 209 | bool OContactAccessBackend_XML::load () |
205 | { | 210 | { |
206 | m_contactList.clear(); | 211 | m_contactList.clear(); |
207 | m_uidToContact.clear(); | 212 | m_uidToContact.clear(); |
208 | 213 | ||
209 | /* Load XML-File and journal if it exists */ | 214 | /* Load XML-File and journal if it exists */ |
210 | if ( !load ( m_fileName, false ) ) | 215 | if ( !load ( m_fileName, false ) ) |
211 | return false; | 216 | return false; |
212 | /* The returncode of the journalfile is ignored due to the | 217 | /* The returncode of the journalfile is ignored due to the |
213 | * fact that it does not exist when this class is instantiated ! | 218 | * fact that it does not exist when this class is instantiated ! |
214 | * But there may such a file exist, if the application crashed. | 219 | * But there may such a file exist, if the application crashed. |
215 | * Therefore we try to load it to get the changes before the # | 220 | * Therefore we try to load it to get the changes before the # |
216 | * crash happened... | 221 | * crash happened... |
217 | */ | 222 | */ |
218 | load (m_journalName, true); | 223 | load (m_journalName, true); |
219 | 224 | ||
220 | return true; | 225 | return true; |
221 | } | 226 | } |
222 | 227 | ||
223 | void OContactAccessBackend_XML::clear () | 228 | void OContactAccessBackend_XML::clear () |
224 | { | 229 | { |
225 | m_contactList.clear(); | 230 | m_contactList.clear(); |
226 | m_uidToContact.clear(); | 231 | m_uidToContact.clear(); |
227 | 232 | ||
228 | m_changed = false; | 233 | m_changed = false; |
229 | } | 234 | } |
230 | 235 | ||
231 | bool OContactAccessBackend_XML::wasChangedExternally() | 236 | bool OContactAccessBackend_XML::wasChangedExternally() |
232 | { | 237 | { |
233 | QFileInfo fi( m_fileName ); | 238 | QFileInfo fi( m_fileName ); |
234 | 239 | ||
235 | QDateTime lastmod = fi.lastModified (); | 240 | QDateTime lastmod = fi.lastModified (); |
236 | 241 | ||
237 | return (lastmod != m_readtime); | 242 | return (lastmod != m_readtime); |
238 | } | 243 | } |
239 | 244 | ||
240 | QArray<int> OContactAccessBackend_XML::allRecords() const | 245 | QArray<int> OContactAccessBackend_XML::allRecords() const |
241 | { | 246 | { |
242 | QArray<int> uid_list( m_contactList.count() ); | 247 | QArray<int> uid_list( m_contactList.count() ); |
243 | 248 | ||
244 | uint counter = 0; | 249 | uint counter = 0; |
245 | QListIterator<OContact> it( m_contactList ); | 250 | QListIterator<OContact> it( m_contactList ); |
246 | for( ; it.current(); ++it ){ | 251 | for( ; it.current(); ++it ){ |
247 | uid_list[counter++] = (*it)->uid(); | 252 | uid_list[counter++] = (*it)->uid(); |
248 | } | 253 | } |
249 | 254 | ||
250 | return ( uid_list ); | 255 | return ( uid_list ); |
251 | } | 256 | } |
252 | 257 | ||
253 | OContact OContactAccessBackend_XML::find ( int uid ) const | 258 | OContact OContactAccessBackend_XML::find ( int uid ) const |
254 | { | 259 | { |
255 | OContact foundContact; //Create empty contact | 260 | OContact foundContact; //Create empty contact |
256 | 261 | ||
257 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); | 262 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); |
258 | 263 | ||
259 | if ( found ){ | 264 | if ( found ){ |
260 | foundContact = *found; | 265 | foundContact = *found; |
261 | } | 266 | } |
262 | 267 | ||
263 | return ( foundContact ); | 268 | return ( foundContact ); |
264 | } | 269 | } |
265 | 270 | ||
266 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 271 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
267 | const QDateTime& d ) | 272 | const QDateTime& d ) |
268 | { | 273 | { |
269 | 274 | ||
270 | QArray<int> m_currentQuery( m_contactList.count() ); | 275 | QArray<int> m_currentQuery( m_contactList.count() ); |
271 | QListIterator<OContact> it( m_contactList ); | 276 | QListIterator<OContact> it( m_contactList ); |
272 | uint arraycounter = 0; | 277 | uint arraycounter = 0; |
273 | 278 | ||
274 | for( ; it.current(); ++it ){ | 279 | for( ; it.current(); ++it ){ |
275 | /* Search all fields and compare them with query object. Store them into list | 280 | /* Search all fields and compare them with query object. Store them into list |
276 | * if all fields matches. | 281 | * if all fields matches. |
277 | */ | 282 | */ |
278 | QDate* queryDate = 0l; | 283 | QDate* queryDate = 0l; |
279 | QDate* checkDate = 0l; | 284 | QDate* checkDate = 0l; |
280 | bool allcorrect = true; | 285 | bool allcorrect = true; |
281 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 286 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
282 | // Birthday and anniversary are special nonstring fields and should | 287 | // Birthday and anniversary are special nonstring fields and should |
283 | // be handled specially | 288 | // be handled specially |
284 | switch ( i ){ | 289 | switch ( i ){ |
285 | case Qtopia::Birthday: | 290 | case Qtopia::Birthday: |
286 | queryDate = new QDate( query.birthday() ); | 291 | queryDate = new QDate( query.birthday() ); |
287 | checkDate = new QDate( (*it)->birthday() ); | 292 | checkDate = new QDate( (*it)->birthday() ); |
288 | case Qtopia::Anniversary: | 293 | case Qtopia::Anniversary: |
289 | if ( queryDate == 0l ){ | 294 | if ( queryDate == 0l ){ |
290 | queryDate = new QDate( query.anniversary() ); | 295 | queryDate = new QDate( query.anniversary() ); |
291 | checkDate = new QDate( (*it)->anniversary() ); | 296 | checkDate = new QDate( (*it)->anniversary() ); |
292 | } | 297 | } |
293 | 298 | ||
294 | if ( queryDate->isValid() ){ | 299 | if ( queryDate->isValid() ){ |
295 | if( checkDate->isValid() ){ | 300 | if( checkDate->isValid() ){ |
296 | if ( settings & OContactAccess::DateYear ){ | 301 | if ( settings & OContactAccess::DateYear ){ |
297 | if ( queryDate->year() != checkDate->year() ) | 302 | if ( queryDate->year() != checkDate->year() ) |
298 | allcorrect = false; | 303 | allcorrect = false; |
299 | } | 304 | } |
300 | if ( settings & OContactAccess::DateMonth ){ | 305 | if ( settings & OContactAccess::DateMonth ){ |
301 | if ( queryDate->month() != checkDate->month() ) | 306 | if ( queryDate->month() != checkDate->month() ) |
302 | allcorrect = false; | 307 | allcorrect = false; |
303 | } | 308 | } |
304 | if ( settings & OContactAccess::DateDay ){ | 309 | if ( settings & OContactAccess::DateDay ){ |
305 | if ( queryDate->day() != checkDate->day() ) | 310 | if ( queryDate->day() != checkDate->day() ) |
306 | allcorrect = false; | 311 | allcorrect = false; |
307 | } | 312 | } |
308 | if ( settings & OContactAccess::DateDiff ) { | 313 | if ( settings & OContactAccess::DateDiff ) { |
309 | QDate current; | 314 | QDate current; |
310 | // If we get an additional date, we | 315 | // If we get an additional date, we |
311 | // will take this date instead of | 316 | // will take this date instead of |
312 | // the current one.. | 317 | // the current one.. |
313 | if ( !d.date().isValid() ) | 318 | if ( !d.date().isValid() ) |
314 | current = QDate::currentDate(); | 319 | current = QDate::currentDate(); |
315 | else | 320 | else |
316 | current = d.date(); | 321 | current = d.date(); |
317 | 322 | ||
318 | // We have to equalize the year, otherwise | 323 | // We have to equalize the year, otherwise |
319 | // the search will fail.. | 324 | // the search will fail.. |
320 | checkDate->setYMD( current.year(), | 325 | checkDate->setYMD( current.year(), |
321 | checkDate->month(), | 326 | checkDate->month(), |
322 | checkDate->day() ); | 327 | checkDate->day() ); |
323 | if ( *checkDate < current ) | 328 | if ( *checkDate < current ) |
324 | checkDate->setYMD( current.year()+1, | 329 | checkDate->setYMD( current.year()+1, |
325 | checkDate->month(), | 330 | checkDate->month(), |
326 | checkDate->day() ); | 331 | checkDate->day() ); |
327 | 332 | ||
328 | // Check whether the birthday/anniversary date is between | 333 | // Check whether the birthday/anniversary date is between |
329 | // the current/given date and the maximum date | 334 | // the current/given date and the maximum date |
330 | // ( maximum time range ) ! | 335 | // ( maximum time range ) ! |
331 | qWarning("Checking if %s is between %s and %s ! ", | 336 | qWarning("Checking if %s is between %s and %s ! ", |
332 | checkDate->toString().latin1(), | 337 | checkDate->toString().latin1(), |
333 | current.toString().latin1(), | 338 | current.toString().latin1(), |
334 | queryDate->toString().latin1() ); | 339 | queryDate->toString().latin1() ); |
335 | if ( current.daysTo( *queryDate ) >= 0 ){ | 340 | if ( current.daysTo( *queryDate ) >= 0 ){ |
336 | if ( !( ( *checkDate >= current ) && | 341 | if ( !( ( *checkDate >= current ) && |
337 | ( *checkDate <= *queryDate ) ) ){ | 342 | ( *checkDate <= *queryDate ) ) ){ |
338 | allcorrect = false; | 343 | allcorrect = false; |
339 | qWarning (" Nope!.."); | 344 | qWarning (" Nope!.."); |
340 | } | 345 | } |
341 | } | 346 | } |
342 | } | 347 | } |
343 | } else{ | 348 | } else{ |
344 | // checkDate is invalid. Therefore this entry is always rejected | 349 | // checkDate is invalid. Therefore this entry is always rejected |
345 | allcorrect = false; | 350 | allcorrect = false; |
346 | } | 351 | } |
347 | } | 352 | } |
348 | 353 | ||
349 | delete queryDate; | 354 | delete queryDate; |
350 | queryDate = 0l; | 355 | queryDate = 0l; |
351 | delete checkDate; | 356 | delete checkDate; |
352 | checkDate = 0l; | 357 | checkDate = 0l; |
353 | break; | 358 | break; |
354 | default: | 359 | default: |
355 | /* Just compare fields which are not empty in the query object */ | 360 | /* Just compare fields which are not empty in the query object */ |
356 | if ( !query.field(i).isEmpty() ){ | 361 | if ( !query.field(i).isEmpty() ){ |
357 | switch ( settings & ~( OContactAccess::IgnoreCase | 362 | switch ( settings & ~( OContactAccess::IgnoreCase |
358 | | OContactAccess::DateDiff | 363 | | OContactAccess::DateDiff |
359 | | OContactAccess::DateYear | 364 | | OContactAccess::DateYear |
360 | | OContactAccess::DateMonth | 365 | | OContactAccess::DateMonth |
361 | | OContactAccess::DateDay | 366 | | OContactAccess::DateDay |
362 | | OContactAccess::MatchOne | 367 | | OContactAccess::MatchOne |
363 | ) ){ | 368 | ) ){ |
364 | 369 | ||
365 | case OContactAccess::RegExp:{ | 370 | case OContactAccess::RegExp:{ |
366 | QRegExp expr ( query.field(i), | 371 | QRegExp expr ( query.field(i), |
367 | !(settings & OContactAccess::IgnoreCase), | 372 | !(settings & OContactAccess::IgnoreCase), |
368 | false ); | 373 | false ); |
369 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 374 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
370 | allcorrect = false; | 375 | allcorrect = false; |
371 | } | 376 | } |
372 | break; | 377 | break; |
373 | case OContactAccess::WildCards:{ | 378 | case OContactAccess::WildCards:{ |
374 | QRegExp expr ( query.field(i), | 379 | QRegExp expr ( query.field(i), |
375 | !(settings & OContactAccess::IgnoreCase), | 380 | !(settings & OContactAccess::IgnoreCase), |
376 | true ); | 381 | true ); |
377 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 382 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
378 | allcorrect = false; | 383 | allcorrect = false; |
379 | } | 384 | } |
380 | break; | 385 | break; |
381 | case OContactAccess::ExactMatch:{ | 386 | case OContactAccess::ExactMatch:{ |
382 | if (settings & OContactAccess::IgnoreCase){ | 387 | if (settings & OContactAccess::IgnoreCase){ |
383 | if ( query.field(i).upper() != | 388 | if ( query.field(i).upper() != |
384 | (*it)->field(i).upper() ) | 389 | (*it)->field(i).upper() ) |
385 | allcorrect = false; | 390 | allcorrect = false; |
386 | }else{ | 391 | }else{ |
387 | if ( query.field(i) != (*it)->field(i) ) | 392 | if ( query.field(i) != (*it)->field(i) ) |
388 | allcorrect = false; | 393 | allcorrect = false; |
389 | } | 394 | } |
390 | } | 395 | } |
391 | break; | 396 | break; |
392 | } | 397 | } |
393 | } | 398 | } |
394 | } | 399 | } |
395 | } | 400 | } |
396 | if ( allcorrect ){ | 401 | if ( allcorrect ){ |
397 | m_currentQuery[arraycounter++] = (*it)->uid(); | 402 | m_currentQuery[arraycounter++] = (*it)->uid(); |
398 | } | 403 | } |
399 | } | 404 | } |
400 | 405 | ||
401 | // Shrink to fit.. | 406 | // Shrink to fit.. |
402 | m_currentQuery.resize(arraycounter); | 407 | m_currentQuery.resize(arraycounter); |
403 | 408 | ||
404 | return m_currentQuery; | 409 | return m_currentQuery; |
405 | } | 410 | } |
406 | 411 | ||
407 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 412 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
408 | { | 413 | { |
409 | QArray<int> m_currentQuery( m_contactList.count() ); | 414 | QArray<int> m_currentQuery( m_contactList.count() ); |
410 | QListIterator<OContact> it( m_contactList ); | 415 | QListIterator<OContact> it( m_contactList ); |
411 | uint arraycounter = 0; | 416 | uint arraycounter = 0; |
412 | 417 | ||
413 | for( ; it.current(); ++it ){ | 418 | for( ; it.current(); ++it ){ |
414 | if ( (*it)->match( r ) ){ | 419 | if ( (*it)->match( r ) ){ |
415 | m_currentQuery[arraycounter++] = (*it)->uid(); | 420 | m_currentQuery[arraycounter++] = (*it)->uid(); |
416 | } | 421 | } |
417 | 422 | ||
418 | } | 423 | } |
419 | // Shrink to fit.. | 424 | // Shrink to fit.. |
420 | m_currentQuery.resize(arraycounter); | 425 | m_currentQuery.resize(arraycounter); |
421 | 426 | ||
422 | return m_currentQuery; | 427 | return m_currentQuery; |
423 | } | 428 | } |
424 | 429 | ||
425 | const uint OContactAccessBackend_XML::querySettings() | 430 | const uint OContactAccessBackend_XML::querySettings() |
426 | { | 431 | { |
427 | return ( OContactAccess::WildCards | 432 | return ( OContactAccess::WildCards |
428 | | OContactAccess::IgnoreCase | 433 | | OContactAccess::IgnoreCase |
429 | | OContactAccess::RegExp | 434 | | OContactAccess::RegExp |
430 | | OContactAccess::ExactMatch | 435 | | OContactAccess::ExactMatch |
431 | | OContactAccess::DateDiff | 436 | | OContactAccess::DateDiff |
432 | | OContactAccess::DateYear | 437 | | OContactAccess::DateYear |
433 | | OContactAccess::DateMonth | 438 | | OContactAccess::DateMonth |
434 | | OContactAccess::DateDay | 439 | | OContactAccess::DateDay |
435 | ); | 440 | ); |
436 | } | 441 | } |
437 | 442 | ||
438 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | 443 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const |
439 | { | 444 | { |
440 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 445 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
441 | * may be added with any of the other settings. IgnoreCase should never used alone. | 446 | * may be added with any of the other settings. IgnoreCase should never used alone. |
442 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 447 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
443 | */ | 448 | */ |
444 | 449 | ||
445 | if ( querySettings == OContactAccess::IgnoreCase ) | 450 | if ( querySettings == OContactAccess::IgnoreCase ) |
446 | return false; | 451 | return false; |
447 | 452 | ||
448 | switch ( querySettings & ~( OContactAccess::IgnoreCase | 453 | switch ( querySettings & ~( OContactAccess::IgnoreCase |
449 | | OContactAccess::DateDiff | 454 | | OContactAccess::DateDiff |
450 | | OContactAccess::DateYear | 455 | | OContactAccess::DateYear |
451 | | OContactAccess::DateMonth | 456 | | OContactAccess::DateMonth |
452 | | OContactAccess::DateDay | 457 | | OContactAccess::DateDay |
453 | ) | 458 | ) |
454 | ){ | 459 | ){ |
455 | case OContactAccess::RegExp: | 460 | case OContactAccess::RegExp: |
456 | return ( true ); | 461 | return ( true ); |
457 | case OContactAccess::WildCards: | 462 | case OContactAccess::WildCards: |
458 | return ( true ); | 463 | return ( true ); |
459 | case OContactAccess::ExactMatch: | 464 | case OContactAccess::ExactMatch: |
460 | return ( true ); | 465 | return ( true ); |
461 | default: | 466 | default: |
462 | return ( false ); | 467 | return ( false ); |
463 | } | 468 | } |
464 | } | 469 | } |
465 | 470 | ||
466 | // Currently only asc implemented.. | 471 | // Currently only asc implemented.. |
467 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 472 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
468 | { | 473 | { |
469 | QMap<QString, int> nameToUid; | 474 | QMap<QString, int> nameToUid; |
470 | QStringList names; | 475 | QStringList names; |
471 | QArray<int> m_currentQuery( m_contactList.count() ); | 476 | QArray<int> m_currentQuery( m_contactList.count() ); |
472 | 477 | ||
473 | // First fill map and StringList with all Names | 478 | // First fill map and StringList with all Names |
474 | // Afterwards sort namelist and use map to fill array to return.. | 479 | // Afterwards sort namelist and use map to fill array to return.. |
475 | QListIterator<OContact> it( m_contactList ); | 480 | QListIterator<OContact> it( m_contactList ); |
476 | for( ; it.current(); ++it ){ | 481 | for( ; it.current(); ++it ){ |
477 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); | 482 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); |
478 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); | 483 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); |
479 | } | 484 | } |
480 | names.sort(); | 485 | names.sort(); |
481 | 486 | ||
482 | int i = 0; | 487 | int i = 0; |
483 | if ( asc ){ | 488 | if ( asc ){ |
484 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | 489 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) |
485 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 490 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
486 | }else{ | 491 | }else{ |
487 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) | 492 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) |
488 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 493 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
489 | } | 494 | } |
490 | 495 | ||
491 | return m_currentQuery; | 496 | return m_currentQuery; |
492 | 497 | ||
493 | } | 498 | } |
494 | 499 | ||
495 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | 500 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) |
496 | { | 501 | { |
497 | //qWarning("odefaultbackend: ACTION::ADD"); | 502 | //qWarning("odefaultbackend: ACTION::ADD"); |
498 | updateJournal (newcontact, ACTION_ADD); | 503 | updateJournal (newcontact, ACTION_ADD); |
499 | addContact_p( newcontact ); | 504 | addContact_p( newcontact ); |
500 | 505 | ||
501 | m_changed = true; | 506 | m_changed = true; |
502 | 507 | ||
503 | return true; | 508 | return true; |
504 | } | 509 | } |
505 | 510 | ||
506 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) | 511 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) |
507 | { | 512 | { |
508 | m_changed = true; | 513 | m_changed = true; |
509 | 514 | ||
510 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); | 515 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); |
511 | 516 | ||
512 | if ( found ) { | 517 | if ( found ) { |
513 | OContact* newCont = new OContact( contact ); | 518 | OContact* newCont = new OContact( contact ); |
514 | 519 | ||
515 | updateJournal ( *newCont, ACTION_REPLACE); | 520 | updateJournal ( *newCont, ACTION_REPLACE); |
516 | m_contactList.removeRef ( found ); | 521 | m_contactList.removeRef ( found ); |
517 | m_contactList.append ( newCont ); | 522 | m_contactList.append ( newCont ); |
518 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); | 523 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); |
519 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); | 524 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); |
520 | 525 | ||
521 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); | 526 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); |
522 | 527 | ||
523 | return true; | 528 | return true; |
524 | } else | 529 | } else |
525 | return false; | 530 | return false; |
526 | } | 531 | } |
527 | 532 | ||
528 | bool OContactAccessBackend_XML::remove ( int uid ) | 533 | bool OContactAccessBackend_XML::remove ( int uid ) |
529 | { | 534 | { |
530 | m_changed = true; | 535 | m_changed = true; |
531 | 536 | ||
532 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); | 537 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); |
533 | 538 | ||
534 | if ( found ) { | 539 | if ( found ) { |
535 | updateJournal ( *found, ACTION_REMOVE); | 540 | updateJournal ( *found, ACTION_REMOVE); |
536 | m_contactList.removeRef ( found ); | 541 | m_contactList.removeRef ( found ); |
537 | m_uidToContact.remove( QString().setNum( uid ) ); | 542 | m_uidToContact.remove( QString().setNum( uid ) ); |
538 | 543 | ||
539 | return true; | 544 | return true; |
540 | } else | 545 | } else |
541 | return false; | 546 | return false; |
542 | } | 547 | } |
543 | 548 | ||
544 | bool OContactAccessBackend_XML::reload(){ | 549 | bool OContactAccessBackend_XML::reload(){ |
545 | /* Reload is the same as load in this implementation */ | 550 | /* Reload is the same as load in this implementation */ |
546 | return ( load() ); | 551 | return ( load() ); |
547 | } | 552 | } |
548 | 553 | ||
549 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | 554 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) |
550 | { | 555 | { |
551 | OContact* contRef = new OContact( newcontact ); | 556 | OContact* contRef = new OContact( newcontact ); |
552 | 557 | ||
553 | m_contactList.append ( contRef ); | 558 | m_contactList.append ( contRef ); |
554 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); | 559 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); |
555 | } | 560 | } |
556 | 561 | ||
557 | /* This function loads the xml-database and the journalfile */ | 562 | /* This function loads the xml-database and the journalfile */ |
558 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 563 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
559 | { | 564 | { |
560 | 565 | ||
561 | /* We use the time of the last read to check if the file was | 566 | /* We use the time of the last read to check if the file was |
562 | * changed externally. | 567 | * changed externally. |
563 | */ | 568 | */ |
564 | if ( !isJournal ){ | 569 | if ( !isJournal ){ |
565 | QFileInfo fi( filename ); | 570 | QFileInfo fi( filename ); |
566 | m_readtime = fi.lastModified (); | 571 | m_readtime = fi.lastModified (); |
567 | } | 572 | } |
568 | 573 | ||
569 | const int JOURNALACTION = Qtopia::Notes + 1; | 574 | const int JOURNALACTION = Qtopia::Notes + 1; |
570 | const int JOURNALROW = JOURNALACTION + 1; | 575 | const int JOURNALROW = JOURNALACTION + 1; |
571 | 576 | ||
572 | bool foundAction = false; | 577 | bool foundAction = false; |
573 | journal_action action = ACTION_ADD; | 578 | journal_action action = ACTION_ADD; |
574 | int journalKey = 0; | 579 | int journalKey = 0; |
575 | QMap<int, QString> contactMap; | 580 | QMap<int, QString> contactMap; |
576 | QMap<QString, QString> customMap; | 581 | QMap<QString, QString> customMap; |
577 | QMap<QString, QString>::Iterator customIt; | 582 | QMap<QString, QString>::Iterator customIt; |
578 | QAsciiDict<int> dict( 47 ); | 583 | QAsciiDict<int> dict( 47 ); |
579 | 584 | ||
580 | dict.setAutoDelete( TRUE ); | 585 | dict.setAutoDelete( TRUE ); |
581 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 586 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
582 | dict.insert( "Title", new int(Qtopia::Title) ); | 587 | dict.insert( "Title", new int(Qtopia::Title) ); |
583 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 588 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
584 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 589 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
585 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 590 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
586 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 591 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
587 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 592 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
588 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 593 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
589 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 594 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
590 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 595 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
591 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 596 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
592 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 597 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
593 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 598 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
594 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 599 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
595 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 600 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
596 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 601 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
597 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 602 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
598 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 603 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
599 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 604 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
600 | dict.insert( "Company", new int(Qtopia::Company) ); | 605 | dict.insert( "Company", new int(Qtopia::Company) ); |
601 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 606 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
602 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 607 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
603 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 608 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
604 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 609 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
605 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 610 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
606 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 611 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
607 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 612 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
608 | dict.insert( "Department", new int(Qtopia::Department) ); | 613 | dict.insert( "Department", new int(Qtopia::Department) ); |
609 | dict.insert( "Office", new int(Qtopia::Office) ); | 614 | dict.insert( "Office", new int(Qtopia::Office) ); |
610 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 615 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
611 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 616 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
612 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 617 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
613 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 618 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
614 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 619 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
615 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 620 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
616 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 621 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
617 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 622 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
618 | dict.insert( "Children", new int(Qtopia::Children) ); | 623 | dict.insert( "Children", new int(Qtopia::Children) ); |
619 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 624 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
620 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 625 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
621 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 626 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
622 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 627 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
623 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 628 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
624 | dict.insert( "action", new int(JOURNALACTION) ); | 629 | dict.insert( "action", new int(JOURNALACTION) ); |
625 | dict.insert( "actionrow", new int(JOURNALROW) ); | 630 | dict.insert( "actionrow", new int(JOURNALROW) ); |
626 | 631 | ||
627 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 632 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
628 | 633 | ||
629 | XMLElement *root = XMLElement::load( filename ); | 634 | XMLElement *root = XMLElement::load( filename ); |
630 | if(root != 0l ){ // start parsing | 635 | if(root != 0l ){ // start parsing |
631 | /* Parse all XML-Elements and put the data into the | 636 | /* Parse all XML-Elements and put the data into the |
632 | * Contact-Class | 637 | * Contact-Class |
633 | */ | 638 | */ |
634 | XMLElement *element = root->firstChild(); | 639 | XMLElement *element = root->firstChild(); |
635 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 640 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
636 | element = element->firstChild(); | 641 | element = element->firstChild(); |
637 | 642 | ||
638 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 643 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
639 | while( element && !isJournal ){ | 644 | while( element && !isJournal ){ |
640 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 645 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
641 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 646 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
642 | // element->tagName().latin1()); | 647 | // element->tagName().latin1()); |
643 | element = element->nextChild(); | 648 | element = element->nextChild(); |
644 | } else { | 649 | } else { |
645 | element = element->firstChild(); | 650 | element = element->firstChild(); |
646 | break; | 651 | break; |
647 | } | 652 | } |
648 | } | 653 | } |
649 | /* Parse all Contacts and ignore unknown tags */ | 654 | /* Parse all Contacts and ignore unknown tags */ |
650 | while( element ){ | 655 | while( element ){ |
651 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 656 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
652 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 657 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
653 | // element->tagName().latin1()); | 658 | // element->tagName().latin1()); |
654 | element = element->nextChild(); | 659 | element = element->nextChild(); |
655 | continue; | 660 | continue; |
656 | } | 661 | } |
657 | /* Found alement with tagname "contact", now parse and store all | 662 | /* Found alement with tagname "contact", now parse and store all |
658 | * attributes contained | 663 | * attributes contained |
659 | */ | 664 | */ |
660 | //qWarning("OContactDefBack::load element tagName() : %s", | 665 | //qWarning("OContactDefBack::load element tagName() : %s", |
661 | // element->tagName().latin1() ); | 666 | // element->tagName().latin1() ); |
662 | QString dummy; | 667 | QString dummy; |
663 | foundAction = false; | 668 | foundAction = false; |
664 | 669 | ||
665 | XMLElement::AttributeMap aMap = element->attributes(); | 670 | XMLElement::AttributeMap aMap = element->attributes(); |
666 | XMLElement::AttributeMap::Iterator it; | 671 | XMLElement::AttributeMap::Iterator it; |
667 | contactMap.clear(); | 672 | contactMap.clear(); |
668 | customMap.clear(); | 673 | customMap.clear(); |
669 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 674 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
670 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 675 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
671 | 676 | ||
672 | int *find = dict[ it.key() ]; | 677 | int *find = dict[ it.key() ]; |
673 | /* Unknown attributes will be stored as "Custom" elements */ | 678 | /* Unknown attributes will be stored as "Custom" elements */ |
674 | if ( !find ) { | 679 | if ( !find ) { |
675 | qWarning("Attribute %s not known.", it.key().latin1()); | 680 | qWarning("Attribute %s not known.", it.key().latin1()); |
676 | //contact.setCustomField(it.key(), it.data()); | 681 | //contact.setCustomField(it.key(), it.data()); |
677 | customMap.insert( it.key(), it.data() ); | 682 | customMap.insert( it.key(), it.data() ); |
678 | continue; | 683 | continue; |
679 | } | 684 | } |
680 | 685 | ||
681 | /* Check if special conversion is needed and add attribute | 686 | /* Check if special conversion is needed and add attribute |
682 | * into Contact class | 687 | * into Contact class |
683 | */ | 688 | */ |
684 | switch( *find ) { | 689 | switch( *find ) { |
685 | /* | 690 | /* |
686 | case Qtopia::AddressUid: | 691 | case Qtopia::AddressUid: |
687 | contact.setUid( it.data().toInt() ); | 692 | contact.setUid( it.data().toInt() ); |
688 | break; | 693 | break; |
689 | case Qtopia::AddressCategory: | 694 | case Qtopia::AddressCategory: |
690 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 695 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
691 | break; | 696 | break; |
692 | */ | 697 | */ |
693 | case JOURNALACTION: | 698 | case JOURNALACTION: |
694 | action = journal_action(it.data().toInt()); | 699 | action = journal_action(it.data().toInt()); |
695 | foundAction = true; | 700 | foundAction = true; |
696 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 701 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
697 | break; | 702 | break; |
698 | case JOURNALROW: | 703 | case JOURNALROW: |
699 | journalKey = it.data().toInt(); | 704 | journalKey = it.data().toInt(); |
700 | break; | 705 | break; |
701 | default: // no conversion needed add them to the map | 706 | default: // no conversion needed add them to the map |
702 | contactMap.insert( *find, it.data() ); | 707 | contactMap.insert( *find, it.data() ); |
703 | break; | 708 | break; |
704 | } | 709 | } |
705 | } | 710 | } |
706 | /* now generate the Contact contact */ | 711 | /* now generate the Contact contact */ |
707 | OContact contact( contactMap ); | 712 | OContact contact( contactMap ); |
708 | 713 | ||
709 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 714 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
710 | contact.setCustomField( customIt.key(), customIt.data() ); | 715 | contact.setCustomField( customIt.key(), customIt.data() ); |
711 | } | 716 | } |
712 | 717 | ||
713 | if (foundAction){ | 718 | if (foundAction){ |
714 | foundAction = false; | 719 | foundAction = false; |
715 | switch ( action ) { | 720 | switch ( action ) { |
716 | case ACTION_ADD: | 721 | case ACTION_ADD: |
717 | addContact_p (contact); | 722 | addContact_p (contact); |
718 | break; | 723 | break; |
719 | case ACTION_REMOVE: | 724 | case ACTION_REMOVE: |
720 | if ( !remove (contact.uid()) ) | 725 | if ( !remove (contact.uid()) ) |
721 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 726 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
722 | contact.uid() ); | 727 | contact.uid() ); |
723 | break; | 728 | break; |
724 | case ACTION_REPLACE: | 729 | case ACTION_REPLACE: |
725 | if ( !replace ( contact ) ) | 730 | if ( !replace ( contact ) ) |
726 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 731 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
727 | contact.uid() ); | 732 | contact.uid() ); |
728 | break; | 733 | break; |
729 | default: | 734 | default: |
730 | qWarning ("Unknown action: ignored !"); | 735 | qWarning ("Unknown action: ignored !"); |
731 | break; | 736 | break; |
732 | } | 737 | } |
733 | }else{ | 738 | }else{ |
734 | /* Add contact to list */ | 739 | /* Add contact to list */ |
735 | addContact_p (contact); | 740 | addContact_p (contact); |
736 | } | 741 | } |
737 | 742 | ||
738 | /* Move to next element */ | 743 | /* Move to next element */ |
739 | element = element->nextChild(); | 744 | element = element->nextChild(); |
740 | } | 745 | } |
741 | }else { | 746 | }else { |
742 | qWarning("ODefBack::could not load"); | 747 | qWarning("ODefBack::could not load"); |
743 | } | 748 | } |
744 | delete root; | 749 | delete root; |
745 | qWarning("returning from loading" ); | 750 | qWarning("returning from loading" ); |
746 | return true; | 751 | return true; |
747 | } | 752 | } |
748 | 753 | ||
749 | 754 | ||
750 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 755 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
751 | journal_action action ) | 756 | journal_action action ) |
752 | { | 757 | { |
753 | QFile f( m_journalName ); | 758 | QFile f( m_journalName ); |
754 | bool created = !f.exists(); | 759 | bool created = !f.exists(); |
755 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 760 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
756 | return; | 761 | return; |
757 | 762 | ||
758 | QString buf; | 763 | QString buf; |
759 | QCString str; | 764 | QCString str; |
760 | 765 | ||
761 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 766 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
762 | // get a XML-File which is readable by our parser. | 767 | // get a XML-File which is readable by our parser. |
763 | // This is just a cheat, but better than rewrite the parser. | 768 | // This is just a cheat, but better than rewrite the parser. |
764 | if ( created ){ | 769 | if ( created ){ |
765 | buf = "<Contacts>"; | 770 | buf = "<Contacts>"; |
766 | QCString cstr = buf.utf8(); | 771 | QCString cstr = buf.utf8(); |
767 | f.writeBlock( cstr.data(), cstr.length() ); | 772 | f.writeBlock( cstr.data(), cstr.length() ); |
768 | } | 773 | } |
769 | 774 | ||
770 | buf = "<Contact "; | 775 | buf = "<Contact "; |
771 | cnt.save( buf ); | 776 | cnt.save( buf ); |
772 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 777 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
773 | buf += "/>\n"; | 778 | buf += "/>\n"; |
774 | QCString cstr = buf.utf8(); | 779 | QCString cstr = buf.utf8(); |
775 | f.writeBlock( cstr.data(), cstr.length() ); | 780 | f.writeBlock( cstr.data(), cstr.length() ); |
776 | } | 781 | } |
777 | 782 | ||
778 | void OContactAccessBackend_XML::removeJournal() | 783 | void OContactAccessBackend_XML::removeJournal() |
779 | { | 784 | { |
780 | QFile f ( m_journalName ); | 785 | QFile f ( m_journalName ); |
781 | if ( f.exists() ) | 786 | if ( f.exists() ) |
782 | f.remove(); | 787 | f.remove(); |
783 | } | 788 | } |
784 | 789 | ||
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h index 4d6a7ef..7b5365b 100644 --- a/libopie/pim/ocontactaccessbackend_xml.h +++ b/libopie/pim/ocontactaccessbackend_xml.h | |||
@@ -1,144 +1,154 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.14 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.13 2003/03/21 10:33:09 eilers | 25 | * Revision 1.13 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 28 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 29 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 30 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 31 | * the binaries for today-addressbook. |
27 | * | 32 | * |
28 | * Revision 1.12.2.2 2003/02/11 12:17:28 eilers | 33 | * Revision 1.12.2.2 2003/02/11 12:17:28 eilers |
29 | * Speed optimization. Removed the sequential search loops. | 34 | * Speed optimization. Removed the sequential search loops. |
30 | * | 35 | * |
31 | * Revision 1.12.2.1 2003/02/09 15:05:01 eilers | 36 | * Revision 1.12.2.1 2003/02/09 15:05:01 eilers |
32 | * Nothing happened.. Just some cleanup before I will start.. | 37 | * Nothing happened.. Just some cleanup before I will start.. |
33 | * | 38 | * |
34 | * Revision 1.12 2003/01/03 16:58:03 eilers | 39 | * Revision 1.12 2003/01/03 16:58:03 eilers |
35 | * Reenable debug output | 40 | * Reenable debug output |
36 | * | 41 | * |
37 | * Revision 1.11 2003/01/03 12:31:28 eilers | 42 | * Revision 1.11 2003/01/03 12:31:28 eilers |
38 | * Bugfix for calculating data diffs.. | 43 | * Bugfix for calculating data diffs.. |
39 | * | 44 | * |
40 | * Revision 1.10 2003/01/02 14:27:12 eilers | 45 | * Revision 1.10 2003/01/02 14:27:12 eilers |
41 | * Improved query by example: Search by date is possible.. First step | 46 | * Improved query by example: Search by date is possible.. First step |
42 | * for a today plugin for birthdays.. | 47 | * for a today plugin for birthdays.. |
43 | * | 48 | * |
44 | * Revision 1.9 2002/12/08 12:48:57 eilers | 49 | * Revision 1.9 2002/12/08 12:48:57 eilers |
45 | * Moved journal-enum from ocontact into i the xml-backend.. | 50 | * Moved journal-enum from ocontact into i the xml-backend.. |
46 | * | 51 | * |
47 | * Revision 1.8 2002/11/14 17:04:24 eilers | 52 | * Revision 1.8 2002/11/14 17:04:24 eilers |
48 | * Sorting will now work if fullname is identical on some entries | 53 | * Sorting will now work if fullname is identical on some entries |
49 | * | 54 | * |
50 | * Revision 1.7 2002/11/13 15:02:46 eilers | 55 | * Revision 1.7 2002/11/13 15:02:46 eilers |
51 | * Small Bug in sorted fixed | 56 | * Small Bug in sorted fixed |
52 | * | 57 | * |
53 | * Revision 1.6 2002/11/13 14:14:51 eilers | 58 | * Revision 1.6 2002/11/13 14:14:51 eilers |
54 | * Added sorted for Contacts.. | 59 | * Added sorted for Contacts.. |
55 | * | 60 | * |
56 | * Revision 1.5 2002/11/01 15:10:42 eilers | 61 | * Revision 1.5 2002/11/01 15:10:42 eilers |
57 | * Added regExp-search in database for all fields in a contact. | 62 | * Added regExp-search in database for all fields in a contact. |
58 | * | 63 | * |
59 | * Revision 1.4 2002/10/16 10:52:40 eilers | 64 | * Revision 1.4 2002/10/16 10:52:40 eilers |
60 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 65 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
61 | * | 66 | * |
62 | * Revision 1.3 2002/10/14 16:21:54 eilers | 67 | * Revision 1.3 2002/10/14 16:21:54 eilers |
63 | * Some minor interface updates | 68 | * Some minor interface updates |
64 | * | 69 | * |
65 | * Revision 1.2 2002/10/07 17:34:24 eilers | 70 | * Revision 1.2 2002/10/07 17:34:24 eilers |
66 | * added OBackendFactory for advanced backend access | 71 | * added OBackendFactory for advanced backend access |
67 | * | 72 | * |
68 | * Revision 1.1 2002/09/27 17:11:44 eilers | 73 | * Revision 1.1 2002/09/27 17:11:44 eilers |
69 | * Added API for accessing the Contact-Database ! It is compiling, but | 74 | * Added API for accessing the Contact-Database ! It is compiling, but |
70 | * please do not expect that anything is working ! | 75 | * please do not expect that anything is working ! |
71 | * I will debug that stuff in the next time .. | 76 | * I will debug that stuff in the next time .. |
72 | * Please read README_COMPILE for compiling ! | 77 | * Please read README_COMPILE for compiling ! |
73 | * | 78 | * |
74 | * | 79 | * |
75 | */ | 80 | */ |
76 | 81 | ||
77 | #ifndef _OContactAccessBackend_XML_ | 82 | #ifndef _OContactAccessBackend_XML_ |
78 | #define _OContactAccessBackend_XML_ | 83 | #define _OContactAccessBackend_XML_ |
79 | 84 | ||
80 | #include "ocontactaccessbackend.h" | 85 | #include "ocontactaccessbackend.h" |
81 | #include "ocontactaccess.h" | 86 | #include "ocontactaccess.h" |
82 | 87 | ||
83 | #include <qlist.h> | 88 | #include <qlist.h> |
84 | #include <qdict.h> | 89 | #include <qdict.h> |
85 | 90 | ||
86 | /* the default xml implementation */ | 91 | /* the default xml implementation */ |
92 | /** | ||
93 | * This class is the XML implementation of a Contact backend | ||
94 | * it does implement everything available for OContact. | ||
95 | * @see OPimAccessBackend for more information of available methods | ||
96 | */ | ||
87 | class OContactAccessBackend_XML : public OContactAccessBackend { | 97 | class OContactAccessBackend_XML : public OContactAccessBackend { |
88 | public: | 98 | public: |
89 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ); | 99 | OContactAccessBackend_XML ( const QString& appname, const QString& filename = QString::null ); |
90 | 100 | ||
91 | bool save(); | 101 | bool save(); |
92 | 102 | ||
93 | bool load (); | 103 | bool load (); |
94 | 104 | ||
95 | void clear (); | 105 | void clear (); |
96 | 106 | ||
97 | bool wasChangedExternally(); | 107 | bool wasChangedExternally(); |
98 | 108 | ||
99 | QArray<int> allRecords() const; | 109 | QArray<int> allRecords() const; |
100 | 110 | ||
101 | OContact find ( int uid ) const; | 111 | OContact find ( int uid ) const; |
102 | 112 | ||
103 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 113 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
104 | 114 | ||
105 | QArray<int> matchRegexp( const QRegExp &r ) const; | 115 | QArray<int> matchRegexp( const QRegExp &r ) const; |
106 | 116 | ||
107 | const uint querySettings(); | 117 | const uint querySettings(); |
108 | 118 | ||
109 | bool hasQuerySettings (uint querySettings) const; | 119 | bool hasQuerySettings (uint querySettings) const; |
110 | 120 | ||
111 | // Currently only asc implemented.. | 121 | // Currently only asc implemented.. |
112 | QArray<int> sorted( bool asc, int , int , int ); | 122 | QArray<int> sorted( bool asc, int , int , int ); |
113 | bool add ( const OContact &newcontact ); | 123 | bool add ( const OContact &newcontact ); |
114 | 124 | ||
115 | bool replace ( const OContact &contact ); | 125 | bool replace ( const OContact &contact ); |
116 | 126 | ||
117 | bool remove ( int uid ); | 127 | bool remove ( int uid ); |
118 | bool reload(); | 128 | bool reload(); |
119 | 129 | ||
120 | private: | 130 | private: |
121 | 131 | ||
122 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 132 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
123 | 133 | ||
124 | void addContact_p( const OContact &newcontact ); | 134 | void addContact_p( const OContact &newcontact ); |
125 | 135 | ||
126 | /* This function loads the xml-database and the journalfile */ | 136 | /* This function loads the xml-database and the journalfile */ |
127 | bool load( const QString filename, bool isJournal ); | 137 | bool load( const QString filename, bool isJournal ); |
128 | 138 | ||
129 | 139 | ||
130 | void updateJournal( const OContact& cnt, journal_action action ); | 140 | void updateJournal( const OContact& cnt, journal_action action ); |
131 | void removeJournal(); | 141 | void removeJournal(); |
132 | 142 | ||
133 | protected: | 143 | protected: |
134 | bool m_changed; | 144 | bool m_changed; |
135 | QString m_journalName; | 145 | QString m_journalName; |
136 | QString m_fileName; | 146 | QString m_fileName; |
137 | QString m_appName; | 147 | QString m_appName; |
138 | QList<OContact> m_contactList; | 148 | QList<OContact> m_contactList; |
139 | QDateTime m_readtime; | 149 | QDateTime m_readtime; |
140 | 150 | ||
141 | QDict<OContact> m_uidToContact; | 151 | QDict<OContact> m_uidToContact; |
142 | }; | 152 | }; |
143 | 153 | ||
144 | #endif | 154 | #endif |
diff --git a/libopie/pim/odatebookaccess.cpp b/libopie/pim/odatebookaccess.cpp index 08e61ff..a3661a3 100644 --- a/libopie/pim/odatebookaccess.cpp +++ b/libopie/pim/odatebookaccess.cpp | |||
@@ -1,38 +1,66 @@ | |||
1 | #include "obackendfactory.h" | 1 | #include "obackendfactory.h" |
2 | #include "odatebookaccess.h" | 2 | #include "odatebookaccess.h" |
3 | 3 | ||
4 | /** | ||
5 | * Simple constructor | ||
6 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation | ||
7 | * will be used! | ||
8 | * @param back The backend to be used or 0 for the default backend | ||
9 | * @param ac What kind of access is intended | ||
10 | */ | ||
4 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) | 11 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) |
5 | : OPimAccessTemplate<OEvent>( back ) | 12 | : OPimAccessTemplate<OEvent>( back ) |
6 | { | 13 | { |
7 | if (!back ) | 14 | if (!back ) |
8 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); | 15 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); |
9 | 16 | ||
10 | m_backEnd = back; | 17 | m_backEnd = back; |
11 | setBackEnd( m_backEnd ); | 18 | setBackEnd( m_backEnd ); |
12 | } | 19 | } |
13 | ODateBookAccess::~ODateBookAccess() { | 20 | ODateBookAccess::~ODateBookAccess() { |
14 | } | 21 | } |
22 | |||
23 | /** | ||
24 | * @return all events available | ||
25 | */ | ||
15 | ODateBookAccess::List ODateBookAccess::rawEvents()const { | 26 | ODateBookAccess::List ODateBookAccess::rawEvents()const { |
16 | QArray<int> ints = m_backEnd->rawEvents(); | 27 | QArray<int> ints = m_backEnd->rawEvents(); |
17 | 28 | ||
18 | List lis( ints, this ); | 29 | List lis( ints, this ); |
19 | return lis; | 30 | return lis; |
20 | } | 31 | } |
32 | |||
33 | /** | ||
34 | * @return all repeating events | ||
35 | */ | ||
21 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { | 36 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { |
22 | QArray<int> ints = m_backEnd->rawRepeats(); | 37 | QArray<int> ints = m_backEnd->rawRepeats(); |
23 | 38 | ||
24 | List lis( ints, this ); | 39 | List lis( ints, this ); |
25 | return lis; | 40 | return lis; |
26 | } | 41 | } |
42 | |||
43 | /** | ||
44 | * @return all non repeating events | ||
45 | */ | ||
27 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { | 46 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { |
28 | QArray<int> ints = m_backEnd->nonRepeats(); | 47 | QArray<int> ints = m_backEnd->nonRepeats(); |
29 | 48 | ||
30 | List lis( ints, this ); | 49 | List lis( ints, this ); |
31 | return lis; | 50 | return lis; |
32 | } | 51 | } |
52 | |||
53 | /** | ||
54 | * @return dates in the time span between from and to | ||
55 | * @param from Include all events from... | ||
56 | * @param to Include all events to... | ||
57 | */ | ||
33 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) { | 58 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) { |
34 | return m_backEnd->effecticeEvents( from, to ); | 59 | return m_backEnd->effecticeEvents( from, to ); |
35 | } | 60 | } |
61 | /** | ||
62 | * @return all events at a given datetime | ||
63 | */ | ||
36 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) { | 64 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) { |
37 | return m_backEnd->effecticeEvents( start ); | 65 | return m_backEnd->effecticeEvents( start ); |
38 | } | 66 | } |
diff --git a/libopie/pim/odatebookaccess.h b/libopie/pim/odatebookaccess.h index 7047039..7c7a63f 100644 --- a/libopie/pim/odatebookaccess.h +++ b/libopie/pim/odatebookaccess.h | |||
@@ -1,32 +1,41 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_H |
2 | #define OPIE_DATE_BOOK_ACCESS_H | 2 | #define OPIE_DATE_BOOK_ACCESS_H |
3 | 3 | ||
4 | #include "odatebookaccessbackend.h" | 4 | #include "odatebookaccessbackend.h" |
5 | #include "opimaccesstemplate.h" | 5 | #include "opimaccesstemplate.h" |
6 | 6 | ||
7 | #include "oevent.h" | 7 | #include "oevent.h" |
8 | 8 | ||
9 | /** | ||
10 | * This is the object orientated datebook database. It'll use OBackendFactory | ||
11 | * to query for a backend. | ||
12 | * 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 | ||
14 | * destructing and creating the object | ||
15 | * | ||
16 | * @author Holger Freyther | ||
17 | */ | ||
9 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { | 18 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { |
10 | public: | 19 | public: |
11 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); | 20 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); |
12 | ~ODateBookAccess(); | 21 | ~ODateBookAccess(); |
13 | 22 | ||
14 | /** return all events */ | 23 | /* return all events */ |
15 | List rawEvents()const; | 24 | List rawEvents()const; |
16 | 25 | ||
17 | /** return repeating events */ | 26 | /* return repeating events */ |
18 | List rawRepeats()const; | 27 | List rawRepeats()const; |
19 | 28 | ||
20 | /** return non repeating events */ | 29 | /* return non repeating events */ |
21 | List nonRepeats()const; | 30 | List nonRepeats()const; |
22 | 31 | ||
23 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); | 32 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); |
24 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ); | 33 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ); |
25 | 34 | ||
26 | private: | 35 | private: |
27 | ODateBookAccessBackend* m_backEnd; | 36 | ODateBookAccessBackend* m_backEnd; |
28 | class Private; | 37 | class Private; |
29 | Private* d; | 38 | Private* d; |
30 | }; | 39 | }; |
31 | 40 | ||
32 | #endif | 41 | #endif |
diff --git a/libopie/pim/odatebookaccessbackend.h b/libopie/pim/odatebookaccessbackend.h index eb6e8fb..86ff298 100644 --- a/libopie/pim/odatebookaccessbackend.h +++ b/libopie/pim/odatebookaccessbackend.h | |||
@@ -1,32 +1,73 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H | 2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include "opimaccessbackend.h" | 6 | #include "opimaccessbackend.h" |
7 | #include "oevent.h" | 7 | #include "oevent.h" |
8 | 8 | ||
9 | /** | ||
10 | * This class is the interface to the storage of Events. | ||
11 | * @see OPimAccessBackend | ||
12 | * | ||
13 | */ | ||
9 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { | 14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { |
10 | public: | 15 | public: |
11 | typedef int UID; | 16 | typedef int UID; |
17 | |||
18 | /** | ||
19 | * c'tor without parameter | ||
20 | */ | ||
12 | ODateBookAccessBackend(); | 21 | ODateBookAccessBackend(); |
13 | ~ODateBookAccessBackend(); | 22 | ~ODateBookAccessBackend(); |
14 | 23 | ||
24 | /** | ||
25 | * This method should return a list of UIDs containing | ||
26 | * all events. No filter should be applied | ||
27 | * @return list of events | ||
28 | */ | ||
15 | virtual QArray<UID> rawEvents()const = 0; | 29 | virtual QArray<UID> rawEvents()const = 0; |
30 | |||
31 | /** | ||
32 | * This method should return a list of UIDs containing | ||
33 | * all repeating events. No filter should be applied | ||
34 | * @return list of repeating events | ||
35 | */ | ||
16 | virtual QArray<UID> rawRepeats()const = 0; | 36 | virtual QArray<UID> rawRepeats()const = 0; |
37 | |||
38 | /** | ||
39 | * This mthod should return a list of UIDs containing all non | ||
40 | * repeating events. No filter should be applied | ||
41 | * @return list of nonrepeating events | ||
42 | */ | ||
17 | virtual QArray<UID> nonRepeats() const = 0; | 43 | virtual QArray<UID> nonRepeats() const = 0; |
18 | 44 | ||
19 | /** | 45 | /** |
20 | * these two methods are used if you do not implement | 46 | * If you do not want to implement the effectiveEvents methods below |
21 | * effectiveEvents... | 47 | * you need to supply it with directNonRepeats. |
48 | * This method can return empty lists if effectiveEvents is implememted | ||
22 | */ | 49 | */ |
23 | virtual OEvent::ValueList directNonRepeats() = 0; | 50 | virtual OEvent::ValueList directNonRepeats() = 0; |
51 | |||
52 | /** | ||
53 | * Same as above but return raw repeats! | ||
54 | */ | ||
24 | virtual OEvent::ValueList directRawRepeats() = 0; | 55 | virtual OEvent::ValueList directRawRepeats() = 0; |
25 | 56 | ||
26 | /* is implemented by default but you can reimplement it*/ | 57 | /* is implemented by default but you can reimplement it*/ |
58 | /** | ||
59 | * 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 | ||
61 | * yourself | ||
62 | */ | ||
27 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); | 63 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); |
64 | |||
65 | /** | ||
66 | * this is an overloaded member function | ||
67 | * @see effecticeEvents | ||
68 | */ | ||
28 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); | 69 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); |
29 | 70 | ||
30 | }; | 71 | }; |
31 | 72 | ||
32 | #endif | 73 | #endif |
diff --git a/libopie/pim/odatebookaccessbackend_xml.h b/libopie/pim/odatebookaccessbackend_xml.h index 563c31f..7848f7c 100644 --- a/libopie/pim/odatebookaccessbackend_xml.h +++ b/libopie/pim/odatebookaccessbackend_xml.h | |||
@@ -1,48 +1,54 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H | 2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H |
3 | 3 | ||
4 | #include <qmap.h> | 4 | #include <qmap.h> |
5 | 5 | ||
6 | #include "odatebookaccessbackend.h" | 6 | #include "odatebookaccessbackend.h" |
7 | 7 | ||
8 | /** | ||
9 | * This is the default XML implementation for DateBoook XML storage | ||
10 | * It fully implements the interface | ||
11 | * @see ODateBookAccessBackend | ||
12 | * @see OPimAccessBackend | ||
13 | */ | ||
8 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { | 14 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { |
9 | public: | 15 | public: |
10 | ODateBookAccessBackend_XML( const QString& appName, | 16 | ODateBookAccessBackend_XML( const QString& appName, |
11 | const QString& fileName = QString::null); | 17 | const QString& fileName = QString::null); |
12 | ~ODateBookAccessBackend_XML(); | 18 | ~ODateBookAccessBackend_XML(); |
13 | 19 | ||
14 | bool load(); | 20 | bool load(); |
15 | bool reload(); | 21 | bool reload(); |
16 | bool save(); | 22 | bool save(); |
17 | 23 | ||
18 | QArray<int> allRecords()const; | 24 | QArray<int> allRecords()const; |
19 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); | 25 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); |
20 | OEvent find( int uid )const; | 26 | OEvent find( int uid )const; |
21 | void clear(); | 27 | void clear(); |
22 | bool add( const OEvent& ev ); | 28 | bool add( const OEvent& ev ); |
23 | bool remove( int uid ); | 29 | bool remove( int uid ); |
24 | bool replace( const OEvent& ev ); | 30 | bool replace( const OEvent& ev ); |
25 | 31 | ||
26 | QArray<UID> rawEvents()const; | 32 | QArray<UID> rawEvents()const; |
27 | QArray<UID> rawRepeats()const; | 33 | QArray<UID> rawRepeats()const; |
28 | QArray<UID> nonRepeats()const; | 34 | QArray<UID> nonRepeats()const; |
29 | 35 | ||
30 | OEvent::ValueList directNonRepeats(); | 36 | OEvent::ValueList directNonRepeats(); |
31 | OEvent::ValueList directRawRepeats(); | 37 | OEvent::ValueList directRawRepeats(); |
32 | 38 | ||
33 | private: | 39 | private: |
34 | bool m_changed :1 ; | 40 | bool m_changed :1 ; |
35 | bool loadFile(); | 41 | bool loadFile(); |
36 | inline void finalizeRecord( OEvent& ev ); | 42 | inline void finalizeRecord( OEvent& ev ); |
37 | inline void setField( OEvent&, int field, const QString& val ); | 43 | inline void setField( OEvent&, int field, const QString& val ); |
38 | QString m_name; | 44 | QString m_name; |
39 | QMap<int, OEvent> m_raw; | 45 | QMap<int, OEvent> m_raw; |
40 | QMap<int, OEvent> m_rep; | 46 | QMap<int, OEvent> m_rep; |
41 | 47 | ||
42 | struct Data; | 48 | struct Data; |
43 | Data* data; | 49 | Data* data; |
44 | class Private; | 50 | class Private; |
45 | Private *d; | 51 | Private *d; |
46 | }; | 52 | }; |
47 | 53 | ||
48 | #endif | 54 | #endif |
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h index 585515c..57d32d0 100644 --- a/libopie/pim/oevent.h +++ b/libopie/pim/oevent.h | |||
@@ -1,195 +1,210 @@ | |||
1 | // CONTAINS GPLed code of TT | 1 | // CONTAINS GPLed code of TT |
2 | 2 | ||
3 | #ifndef OPIE_PIM_EVENT_H | 3 | #ifndef OPIE_PIM_EVENT_H |
4 | #define OPIE_PIM_EVENT_H | 4 | #define OPIE_PIM_EVENT_H |
5 | 5 | ||
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <qvaluelist.h> | 8 | #include <qvaluelist.h> |
9 | 9 | ||
10 | #include <qpe/recordfields.h> | 10 | #include <qpe/recordfields.h> |
11 | #include <qpe/palmtopuidgen.h> | 11 | #include <qpe/palmtopuidgen.h> |
12 | 12 | ||
13 | #include "otimezone.h" | 13 | #include "otimezone.h" |
14 | #include "opimrecord.h" | 14 | #include "opimrecord.h" |
15 | 15 | ||
16 | struct OCalendarHelper { | 16 | struct OCalendarHelper { |
17 | /** calculate the week number of the date */ | 17 | /** calculate the week number of the date */ |
18 | static int week( const QDate& ); | 18 | static int week( const QDate& ); |
19 | /** calculate the occurence of week days since the start of the month */ | 19 | /** calculate the occurence of week days since the start of the month */ |
20 | static int ocurrence( const QDate& ); | 20 | static int ocurrence( const QDate& ); |
21 | 21 | ||
22 | // returns the dayOfWeek for the *first* day it finds (ignores | 22 | // returns the dayOfWeek for the *first* day it finds (ignores |
23 | // any further days!). Returns 1 (Monday) if there isn't any day found | 23 | // any further days!). Returns 1 (Monday) if there isn't any day found |
24 | static int dayOfWeek( char day ); | 24 | static int dayOfWeek( char day ); |
25 | 25 | ||
26 | /** returns the diff of month */ | 26 | /** returns the diff of month */ |
27 | static int monthDiff( const QDate& first, const QDate& second ); | 27 | static int monthDiff( const QDate& first, const QDate& second ); |
28 | 28 | ||
29 | }; | 29 | }; |
30 | 30 | ||
31 | class OPimNotifyManager; | 31 | class OPimNotifyManager; |
32 | class ORecur; | 32 | class ORecur; |
33 | |||
34 | /** | ||
35 | * This is the container for all Events. It encapsules all | ||
36 | * available information for a single Event | ||
37 | * @short container for events. | ||
38 | */ | ||
33 | class OEvent : public OPimRecord { | 39 | class OEvent : public OPimRecord { |
34 | public: | 40 | public: |
35 | typedef QValueList<OEvent> ValueList; | 41 | typedef QValueList<OEvent> ValueList; |
42 | /** | ||
43 | * RecordFields contain possible attributes | ||
44 | */ | ||
36 | enum RecordFields { | 45 | enum RecordFields { |
37 | Uid = Qtopia::UID_ID, | 46 | Uid = Qtopia::UID_ID, |
38 | Category = Qtopia::CATEGORY_ID, | 47 | Category = Qtopia::CATEGORY_ID, |
39 | Description, | 48 | Description, |
40 | Location, | 49 | Location, |
41 | Alarm, | 50 | Alarm, |
42 | Reminder, | 51 | Reminder, |
43 | Recurrence, | 52 | Recurrence, |
44 | Note, | 53 | Note, |
45 | Created, | 54 | Created, |
46 | StartDate, | 55 | StartDate, |
47 | EndDate, | 56 | EndDate, |
48 | AllDay, | 57 | AllDay, |
49 | TimeZone | 58 | TimeZone |
50 | }; | 59 | }; |
51 | 60 | ||
61 | /** | ||
62 | * Start with an Empty OEvent. UID == 0 means that it is empty | ||
63 | */ | ||
52 | OEvent(int uid = 0); | 64 | OEvent(int uid = 0); |
65 | |||
66 | /** | ||
67 | * copy c'tor | ||
68 | */ | ||
53 | OEvent( const OEvent& ); | 69 | OEvent( const OEvent& ); |
54 | ~OEvent(); | 70 | ~OEvent(); |
55 | OEvent &operator=( const OEvent& ); | 71 | OEvent &operator=( const OEvent& ); |
56 | 72 | ||
57 | QString description()const; | 73 | QString description()const; |
58 | void setDescription( const QString& description ); | 74 | void setDescription( const QString& description ); |
59 | 75 | ||
60 | QString location()const; | 76 | QString location()const; |
61 | void setLocation( const QString& loc ); | 77 | void setLocation( const QString& loc ); |
62 | 78 | ||
63 | bool hasNotifiers()const; | 79 | bool hasNotifiers()const; |
64 | OPimNotifyManager ¬ifiers()const; | 80 | OPimNotifyManager ¬ifiers()const; |
65 | 81 | ||
66 | ORecur recurrence()const; | 82 | ORecur recurrence()const; |
67 | void setRecurrence( const ORecur& ); | 83 | void setRecurrence( const ORecur& ); |
68 | bool hasRecurrence()const; | 84 | bool hasRecurrence()const; |
69 | 85 | ||
70 | QString note()const; | 86 | QString note()const; |
71 | void setNote( const QString& note ); | 87 | void setNote( const QString& note ); |
72 | 88 | ||
73 | 89 | ||
74 | QDateTime createdDateTime()const; | 90 | QDateTime createdDateTime()const; |
75 | void setCreatedDateTime( const QDateTime& dt); | 91 | void setCreatedDateTime( const QDateTime& dt); |
76 | 92 | ||
77 | /** set the date to dt. dt is the QDateTime in localtime */ | 93 | /** set the date to dt. dt is the QDateTime in localtime */ |
78 | void setStartDateTime( const QDateTime& ); | 94 | void setStartDateTime( const QDateTime& ); |
79 | /** returns the datetime in the local timeZone */ | 95 | /** returns the datetime in the local timeZone */ |
80 | QDateTime startDateTime()const; | 96 | QDateTime startDateTime()const; |
81 | 97 | ||
82 | /** returns the start datetime in the current zone */ | 98 | /** returns the start datetime in the current zone */ |
83 | QDateTime startDateTimeInZone()const; | 99 | QDateTime startDateTimeInZone()const; |
84 | 100 | ||
85 | /** in current timezone */ | 101 | /** in current timezone */ |
86 | void setEndDateTime( const QDateTime& ); | 102 | void setEndDateTime( const QDateTime& ); |
87 | /** in current timezone */ | 103 | /** in current timezone */ |
88 | QDateTime endDateTime()const; | 104 | QDateTime endDateTime()const; |
89 | QDateTime endDateTimeInZone()const; | 105 | QDateTime endDateTimeInZone()const; |
90 | 106 | ||
91 | bool isMultipleDay()const; | 107 | bool isMultipleDay()const; |
92 | bool isAllDay()const; | 108 | bool isAllDay()const; |
93 | void setAllDay( bool isAllDay ); | 109 | void setAllDay( bool isAllDay ); |
94 | 110 | ||
95 | /* pin this event to a timezone! FIXME */ | 111 | /* pin this event to a timezone! FIXME */ |
96 | void setTimeZone( const QString& timeZone ); | 112 | void setTimeZone( const QString& timeZone ); |
97 | QString timeZone()const; | 113 | QString timeZone()const; |
98 | 114 | ||
99 | 115 | ||
100 | bool match( const QRegExp& )const; | 116 | bool match( const QRegExp& )const; |
101 | 117 | ||
102 | /** For exception to recurrence here is a list of children... */ | 118 | /** For exception to recurrence here is a list of children... */ |
103 | QArray<int> children()const; | 119 | QArray<int> children()const; |
104 | void setChildren( const QArray<int>& ); | 120 | void setChildren( const QArray<int>& ); |
105 | void addChild( int uid ); | 121 | void addChild( int uid ); |
106 | void removeChild( int uid ); | 122 | void removeChild( int uid ); |
107 | 123 | ||
108 | /** return the parent OEvent */ | 124 | /** return the parent OEvent */ |
109 | int parent()const; | 125 | int parent()const; |
110 | void setParent( int uid ); | 126 | void setParent( int uid ); |
111 | 127 | ||
112 | 128 | ||
113 | /* needed reimp */ | 129 | /* needed reimp */ |
114 | QString toRichText()const; | 130 | QString toRichText()const; |
115 | QString toShortText()const; | 131 | QString toShortText()const; |
116 | QString type()const; | 132 | QString type()const; |
117 | 133 | ||
118 | QMap<int, QString> toMap()const; | 134 | QMap<int, QString> toMap()const; |
119 | QMap<QString, QString> toExtraMap()const; | 135 | QMap<QString, QString> toExtraMap()const; |
120 | QString recordField(int )const; | 136 | QString recordField(int )const; |
121 | 137 | ||
122 | static int rtti(); | 138 | static int rtti(); |
123 | 139 | ||
124 | bool loadFromStream( QDataStream& ); | 140 | bool loadFromStream( QDataStream& ); |
125 | bool saveToStream( QDataStream& )const; | 141 | bool saveToStream( QDataStream& )const; |
126 | 142 | ||
127 | /* bool operator==( const OEvent& ); | 143 | /* bool operator==( const OEvent& ); |
128 | bool operator!=( const OEvent& ); | 144 | bool operator!=( const OEvent& ); |
129 | bool operator<( const OEvent& ); | 145 | bool operator<( const OEvent& ); |
130 | bool operator<=( const OEvent& ); | 146 | bool operator<=( const OEvent& ); |
131 | bool operator>( const OEvent& ); | 147 | bool operator>( const OEvent& ); |
132 | bool operator>=(const OEvent& ); | 148 | bool operator>=(const OEvent& ); |
133 | */ | 149 | */ |
134 | private: | 150 | private: |
135 | inline void changeOrModify(); | 151 | inline void changeOrModify(); |
136 | void deref(); | 152 | void deref(); |
137 | struct Data; | 153 | struct Data; |
138 | Data* data; | 154 | Data* data; |
139 | class Private; | 155 | class Private; |
140 | Private* priv; | 156 | Private* priv; |
141 | 157 | ||
142 | }; | 158 | }; |
143 | 159 | ||
144 | /** | 160 | /** |
145 | * AN Event can span through multiple days. We split up a multiday eve | 161 | * AN Event can span through multiple days. We split up a multiday eve |
146 | */ | 162 | */ |
147 | |||
148 | class OEffectiveEvent { | 163 | class OEffectiveEvent { |
149 | public: | 164 | public: |
150 | typedef QValueList<OEffectiveEvent> ValueList; | 165 | typedef QValueList<OEffectiveEvent> ValueList; |
151 | enum Position { MidWay, Start, End, StartEnd }; | 166 | enum Position { MidWay, Start, End, StartEnd }; |
152 | // If we calculate the effective event of a multi-day event | 167 | // If we calculate the effective event of a multi-day event |
153 | // we have to figure out whether we are at the first day, | 168 | // we have to figure out whether we are at the first day, |
154 | // at the end, or anywhere else ("middle"). This is important | 169 | // at the end, or anywhere else ("middle"). This is important |
155 | // for the start/end times (00:00/23:59) | 170 | // for the start/end times (00:00/23:59) |
156 | // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- | 171 | // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- |
157 | // day event | 172 | // day event |
158 | // Start: start time -> 23:59 | 173 | // Start: start time -> 23:59 |
159 | // End: 00:00 -> end time | 174 | // End: 00:00 -> end time |
160 | // Start | End == StartEnd: for single-day events (default) | 175 | // Start | End == StartEnd: for single-day events (default) |
161 | // here we draw start time -> end time | 176 | // here we draw start time -> end time |
162 | OEffectiveEvent(); | 177 | OEffectiveEvent(); |
163 | OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd ); | 178 | OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd ); |
164 | OEffectiveEvent( const OEffectiveEvent& ); | 179 | OEffectiveEvent( const OEffectiveEvent& ); |
165 | OEffectiveEvent &operator=(const OEffectiveEvent& ); | 180 | OEffectiveEvent &operator=(const OEffectiveEvent& ); |
166 | ~OEffectiveEvent(); | 181 | ~OEffectiveEvent(); |
167 | 182 | ||
168 | void setStartTime( const QTime& ); | 183 | void setStartTime( const QTime& ); |
169 | void setEndTime( const QTime& ); | 184 | void setEndTime( const QTime& ); |
170 | void setEvent( const OEvent& ); | 185 | void setEvent( const OEvent& ); |
171 | void setDate( const QDate& ); | 186 | void setDate( const QDate& ); |
172 | 187 | ||
173 | void setEffectiveDates( const QDate& from, const QDate& to ); | 188 | void setEffectiveDates( const QDate& from, const QDate& to ); |
174 | 189 | ||
175 | QString description()const; | 190 | QString description()const; |
176 | QString location()const; | 191 | QString location()const; |
177 | QString note()const; | 192 | QString note()const; |
178 | OEvent event()const; | 193 | OEvent event()const; |
179 | QTime startTime()const; | 194 | QTime startTime()const; |
180 | QTime endTime()const; | 195 | QTime endTime()const; |
181 | QDate date()const; | 196 | QDate date()const; |
182 | 197 | ||
183 | /* return the length in hours */ | 198 | /* return the length in hours */ |
184 | int length()const; | 199 | int length()const; |
185 | int size()const; | 200 | int size()const; |
186 | 201 | ||
187 | QDate startDate()const; | 202 | QDate startDate()const; |
188 | QDate endDate()const; | 203 | QDate endDate()const; |
189 | 204 | ||
190 | bool operator<( const OEffectiveEvent &e ) const; | 205 | bool operator<( const OEffectiveEvent &e ) const; |
191 | bool operator<=( const OEffectiveEvent &e ) const; | 206 | bool operator<=( const OEffectiveEvent &e ) const; |
192 | bool operator==( const OEffectiveEvent &e ) const; | 207 | bool operator==( const OEffectiveEvent &e ) const; |
193 | bool operator!=( const OEffectiveEvent &e ) const; | 208 | bool operator!=( const OEffectiveEvent &e ) const; |
194 | bool operator>( const OEffectiveEvent &e ) const; | 209 | bool operator>( const OEffectiveEvent &e ) const; |
195 | bool operator>= ( const OEffectiveEvent &e ) const; | 210 | bool operator>= ( const OEffectiveEvent &e ) const; |
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h index 3a73210..ad6cf5a 100644 --- a/libopie2/opiepim/backend/obackendfactory.h +++ b/libopie2/opiepim/backend/obackendfactory.h | |||
@@ -1,126 +1,150 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage Backends. | 2 | * Class to manage Backends. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; | 9 | * License as published by the Free Software Foundation; |
10 | * either version 2 of the License, or (at your option) any later | 10 | * either version 2 of the License, or (at your option) any later |
11 | * version. | 11 | * version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: Use plugins | 13 | * ToDo: Use plugins |
14 | * ===================================================================== | 14 | * ===================================================================== |
15 | * Version: $Id$ | 15 | * Version: $Id$ |
16 | * ===================================================================== | 16 | * ===================================================================== |
17 | * History: | 17 | * History: |
18 | * $Log$ | 18 | * $Log$ |
19 | * Revision 1.6 2003/04/13 18:07:10 zecke | ||
20 | * More API doc | ||
21 | * QString -> const QString& | ||
22 | * QString = 0l -> QString::null | ||
23 | * | ||
19 | * Revision 1.5 2003/02/21 23:31:52 zecke | 24 | * Revision 1.5 2003/02/21 23:31:52 zecke |
20 | * Add XML datebookresource | 25 | * Add XML datebookresource |
21 | * -clean up todoaccessxml header | 26 | * -clean up todoaccessxml header |
22 | * -implement some more stuff in the oeven tester | 27 | * -implement some more stuff in the oeven tester |
23 | * -extend DefaultFactory to not crash and to use datebook | 28 | * -extend DefaultFactory to not crash and to use datebook |
24 | * | 29 | * |
25 | * -reading of OEvents is working nicely.. saving will be added | 30 | * -reading of OEvents is working nicely.. saving will be added |
26 | * tomorrow | 31 | * tomorrow |
27 | * -fix spelling in ODateBookAcces | 32 | * -fix spelling in ODateBookAcces |
28 | * | 33 | * |
29 | * Revision 1.4 2002/10/14 15:55:18 eilers | 34 | * Revision 1.4 2002/10/14 15:55:18 eilers |
30 | * Redeactivate SQL.. ;) | 35 | * Redeactivate SQL.. ;) |
31 | * | 36 | * |
32 | * Revision 1.3 2002/10/10 17:08:58 zecke | 37 | * Revision 1.3 2002/10/10 17:08:58 zecke |
33 | * The Cache is finally in place | 38 | * The Cache is finally in place |
34 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) | 39 | * I tested it with my todolist and it 'works' for 10.000 todos the hits are awesome ;) |
35 | * 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.... | 40 | * 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.... |
36 | * I still have to fully implement read ahead | 41 | * I still have to fully implement read ahead |
37 | * This change is bic but sc | 42 | * This change is bic but sc |
38 | * | 43 | * |
39 | * Revision 1.2 2002/10/08 09:27:36 eilers | 44 | * Revision 1.2 2002/10/08 09:27:36 eilers |
40 | * Fixed libopie.pro to include the new pim-API. | 45 | * Fixed libopie.pro to include the new pim-API. |
41 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to | 46 | * The SQL-Stuff is currently deactivated. Otherwise everyone who wants to |
42 | * compile itself would need to install libsqlite, libopiesql... | 47 | * compile itself would need to install libsqlite, libopiesql... |
43 | * Therefore, the backend currently uses XML only.. | 48 | * Therefore, the backend currently uses XML only.. |
44 | * | 49 | * |
45 | * Revision 1.1 2002/10/07 17:35:01 eilers | 50 | * Revision 1.1 2002/10/07 17:35:01 eilers |
46 | * added OBackendFactory for advanced backend access | 51 | * added OBackendFactory for advanced backend access |
47 | * | 52 | * |
48 | * | 53 | * |
49 | * ===================================================================== | 54 | * ===================================================================== |
50 | */ | 55 | */ |
51 | #ifndef OPIE_BACKENDFACTORY_H_ | 56 | #ifndef OPIE_BACKENDFACTORY_H_ |
52 | #define OPIE_BACKENDFACTORY_H_ | 57 | #define OPIE_BACKENDFACTORY_H_ |
53 | 58 | ||
54 | #include <qstring.h> | 59 | #include <qstring.h> |
55 | #include <qasciidict.h> | 60 | #include <qasciidict.h> |
56 | #include <qpe/config.h> | 61 | #include <qpe/config.h> |
57 | 62 | ||
58 | #include "otodoaccessxml.h" | 63 | #include "otodoaccessxml.h" |
59 | #include "ocontactaccessbackend_xml.h" | 64 | #include "ocontactaccessbackend_xml.h" |
60 | #include "odatebookaccessbackend_xml.h" | 65 | #include "odatebookaccessbackend_xml.h" |
61 | 66 | ||
62 | #ifdef __USE_SQL | 67 | #ifdef __USE_SQL |
63 | #include "otodoaccesssql.h" | 68 | #include "otodoaccesssql.h" |
64 | #endif | 69 | #endif |
65 | 70 | ||
66 | 71 | /** | |
72 | * This class is our factory. It will give us the default implementations | ||
73 | * of at least Todolist, Contacts and Datebook. In the future this class will | ||
74 | * allow users to switch the backend with ( XML->SQLite ) without the need | ||
75 | * to recompile.# | ||
76 | * This class as the whole PIM Api is making use of templates | ||
77 | * | ||
78 | * <pre> | ||
79 | * OTodoAccessBackend* backend = OBackEndFactory<OTodoAccessBackend>::Default("todo", QString::null ); | ||
80 | * backend->load(); | ||
81 | * </pre> | ||
82 | * | ||
83 | * @author Stefan Eilers | ||
84 | * @version 0.1 | ||
85 | */ | ||
67 | template<class T> | 86 | template<class T> |
68 | class OBackendFactory | 87 | class OBackendFactory |
69 | { | 88 | { |
70 | public: | 89 | public: |
71 | OBackendFactory() {}; | 90 | OBackendFactory() {}; |
72 | 91 | ||
73 | enum BACKENDS { | 92 | enum BACKENDS { |
74 | TODO, | 93 | TODO, |
75 | CONTACT, | 94 | CONTACT, |
76 | DATE | 95 | DATE |
77 | }; | 96 | }; |
78 | 97 | ||
98 | /** | ||
99 | * Returns a backend implementation for backendName | ||
100 | * @param backendName the type of the backend | ||
101 | * @param appName will be passed on to the backend | ||
102 | */ | ||
79 | static T* Default( const QString backendName, const QString& appName ){ | 103 | static T* Default( const QString backendName, const QString& appName ){ |
80 | 104 | ||
81 | // __asm__("int3"); | 105 | // __asm__("int3"); |
82 | 106 | ||
83 | Config config( "pimaccess" ); | 107 | Config config( "pimaccess" ); |
84 | config.setGroup ( backendName ); | 108 | config.setGroup ( backendName ); |
85 | QString backend = config.readEntry( "usebackend" ); | 109 | QString backend = config.readEntry( "usebackend" ); |
86 | 110 | ||
87 | QAsciiDict<int> dict ( 3 ); | 111 | QAsciiDict<int> dict ( 3 ); |
88 | dict.setAutoDelete ( TRUE ); | 112 | dict.setAutoDelete ( TRUE ); |
89 | 113 | ||
90 | dict.insert( "todo", new int (TODO) ); | 114 | dict.insert( "todo", new int (TODO) ); |
91 | dict.insert( "contact", new int (CONTACT) ); | 115 | dict.insert( "contact", new int (CONTACT) ); |
92 | dict.insert( "datebook", new int(DATE) ); | 116 | dict.insert( "datebook", new int(DATE) ); |
93 | 117 | ||
94 | qWarning ("TODO is: %d", TODO); | 118 | qWarning ("TODO is: %d", TODO); |
95 | qWarning ("CONTACT is: %d", CONTACT); | 119 | qWarning ("CONTACT is: %d", CONTACT); |
96 | 120 | ||
97 | int *find = dict[ backendName ]; | 121 | int *find = dict[ backendName ]; |
98 | if (!find ) return 0; | 122 | if (!find ) return 0; |
99 | 123 | ||
100 | switch ( *find ){ | 124 | switch ( *find ){ |
101 | case TODO: | 125 | case TODO: |
102 | #ifdef __USE_SQL | 126 | #ifdef __USE_SQL |
103 | if ( backend == "sql" ) | 127 | if ( backend == "sql" ) |
104 | return (T*) new OTodoAccessBackendSQL(""); | 128 | return (T*) new OTodoAccessBackendSQL(""); |
105 | #else | 129 | #else |
106 | if ( backend == "sql" ) | 130 | if ( backend == "sql" ) |
107 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 131 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
108 | #endif | 132 | #endif |
109 | 133 | ||
110 | return (T*) new OTodoAccessXML( appName ); | 134 | return (T*) new OTodoAccessXML( appName ); |
111 | case CONTACT: | 135 | case CONTACT: |
112 | if ( backend == "sql" ) | 136 | if ( backend == "sql" ) |
113 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 137 | qWarning ("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
114 | 138 | ||
115 | return (T*) new OContactAccessBackend_XML( appName ); | 139 | return (T*) new OContactAccessBackend_XML( appName ); |
116 | case DATE: | 140 | case DATE: |
117 | if ( backend == "sql" ) | 141 | if ( backend == "sql" ) |
118 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); | 142 | qWarning("OBackendFactory:: sql Backend not implemented! Using XML instead!"); |
119 | 143 | ||
120 | return (T*) new ODateBookAccessBackend_XML( appName ); | 144 | return (T*) new ODateBookAccessBackend_XML( appName ); |
121 | default: | 145 | default: |
122 | return NULL; | 146 | return NULL; |
123 | } | 147 | } |
124 | 148 | ||
125 | 149 | ||
126 | } | 150 | } |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index 821f5bf..ebeb42d 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -1,85 +1,107 @@ | |||
1 | /** | 1 | /** |
2 | * The class responsible for managing a backend. | 2 | * The class responsible for managing a backend. |
3 | * The implementation of this abstract class contains | 3 | * The implementation of this abstract class contains |
4 | * the complete database handling. | 4 | * the complete database handling. |
5 | * | 5 | * |
6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 6 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 7 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
8 | * | 8 | * |
9 | * ===================================================================== | 9 | * ===================================================================== |
10 | *This program is free software; you can redistribute it and/or | 10 | *This program is free software; you can redistribute it and/or |
11 | *modify it under the terms of the GNU Library General Public | 11 | *modify it under the terms of the GNU Library General Public |
12 | * License as published by the Free Software Foundation; | 12 | * License as published by the Free Software Foundation; |
13 | * either version 2 of the License, or (at your option) any later | 13 | * either version 2 of the License, or (at your option) any later |
14 | * version. | 14 | * version. |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: Define enum for query settings | 16 | * ToDo: Define enum for query settings |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * Version: $Id$ | 18 | * Version: $Id$ |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * History: | 20 | * History: |
21 | * $Log$ | 21 | * $Log$ |
22 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
23 | * More API doc | ||
24 | * QString -> const QString& | ||
25 | * QString = 0l -> QString::null | ||
26 | * | ||
22 | * Revision 1.4 2002/11/13 14:14:51 eilers | 27 | * Revision 1.4 2002/11/13 14:14:51 eilers |
23 | * Added sorted for Contacts.. | 28 | * Added sorted for Contacts.. |
24 | * | 29 | * |
25 | * Revision 1.3 2002/11/01 15:10:42 eilers | 30 | * Revision 1.3 2002/11/01 15:10:42 eilers |
26 | * Added regExp-search in database for all fields in a contact. | 31 | * Added regExp-search in database for all fields in a contact. |
27 | * | 32 | * |
28 | * Revision 1.2 2002/10/07 17:34:24 eilers | 33 | * Revision 1.2 2002/10/07 17:34:24 eilers |
29 | * added OBackendFactory for advanced backend access | 34 | * added OBackendFactory for advanced backend access |
30 | * | 35 | * |
31 | * Revision 1.1 2002/09/27 17:11:44 eilers | 36 | * Revision 1.1 2002/09/27 17:11:44 eilers |
32 | * Added API for accessing the Contact-Database ! It is compiling, but | 37 | * Added API for accessing the Contact-Database ! It is compiling, but |
33 | * please do not expect that anything is working ! | 38 | * please do not expect that anything is working ! |
34 | * I will debug that stuff in the next time .. | 39 | * I will debug that stuff in the next time .. |
35 | * Please read README_COMPILE for compiling ! | 40 | * Please read README_COMPILE for compiling ! |
36 | * | 41 | * |
37 | * ===================================================================== | 42 | * ===================================================================== |
38 | * | 43 | * |
39 | */ | 44 | */ |
40 | 45 | ||
41 | #ifndef _OCONTACTACCESSBACKEND_H_ | 46 | #ifndef _OCONTACTACCESSBACKEND_H_ |
42 | #define _OCONTACTACCESSBACKEND_H_ | 47 | #define _OCONTACTACCESSBACKEND_H_ |
43 | 48 | ||
44 | #include "ocontact.h" | 49 | #include "ocontact.h" |
45 | #include "opimaccessbackend.h" | 50 | #include "opimaccessbackend.h" |
46 | 51 | ||
47 | #include "qregexp.h" | 52 | #include <qregexp.h> |
48 | 53 | ||
54 | /** | ||
55 | * This class represents the interface of all Contact Backends. | ||
56 | * Derivates of this class will be used to access the contacts. | ||
57 | * As implementation currently XML and vCard exist. This class needs to be implemented | ||
58 | * if you want to provide your own storage. | ||
59 | * In all queries a list of uids is passed on instead of loading the actual record! | ||
60 | * | ||
61 | * @see OContactAccessBackend_VCard | ||
62 | * @see OContactAccessBackend_XML | ||
63 | */ | ||
49 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 64 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
50 | public: | 65 | public: |
51 | OContactAccessBackend() {} | 66 | OContactAccessBackend() {} |
52 | virtual ~OContactAccessBackend() {} | 67 | virtual ~OContactAccessBackend() {} |
53 | 68 | ||
54 | 69 | ||
55 | /** Return if database was changed externally. | 70 | /** |
71 | * Return if database was changed externally. | ||
56 | * 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. |
57 | * It is used to prevent to overwrite the current database content | 73 | * It is used to prevent to overwrite the current database content |
58 | * if the file was already changed by something else ! | 74 | * if the file was already changed by something else ! |
59 | * If this happens, we have to reload before save our data. | 75 | * If this happens, we have to reload before save our data. |
60 | * 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 |
61 | * management system themselve, therefore this function should always return false in | 77 | * management system themselve, therefore this function should always return false in |
62 | * this case. It is not our problem to handle this conflict ... | 78 | * this case. It is not our problem to handle this conflict ... |
63 | * @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 |
64 | * 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 |
65 | * in this situation. | 81 | * in this situation. |
66 | */ | 82 | */ |
67 | virtual bool wasChangedExternally() = 0; | 83 | virtual bool wasChangedExternally() = 0; |
68 | 84 | ||
69 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 85 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
70 | 86 | ||
71 | /** Return all possible settings. | 87 | /** |
88 | * Return all possible settings. | ||
72 | * @return All settings provided by the current backend | 89 | * @return All settings provided by the current backend |
73 | * (i.e.: query_WildCards & query_IgnoreCase) | 90 | * (i.e.: query_WildCards & query_IgnoreCase) |
74 | */ | 91 | */ |
75 | virtual const uint querySettings() = 0; | 92 | virtual const uint querySettings() = 0; |
76 | 93 | ||
77 | /** Check whether settings are correct. | 94 | /** |
95 | * Check whether settings are correct. | ||
78 | * @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. |
79 | */ | 97 | */ |
80 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 98 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
81 | 99 | ||
82 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | 100 | /** |
101 | * FIXME!!! | ||
102 | * Returns a sorted list of records either ascendinf or descending for a giving criteria and category | ||
103 | */ | ||
104 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | ||
83 | 105 | ||
84 | }; | 106 | }; |
85 | #endif | 107 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index f24523f..270bef3 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -1,127 +1,132 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.10 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.9 2003/03/21 10:33:09 eilers | 25 | * Revision 1.9 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 28 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 29 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 30 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 31 | * the binaries for today-addressbook. |
27 | * | 32 | * |
28 | * Revision 1.8 2003/02/21 16:52:49 zecke | 33 | * Revision 1.8 2003/02/21 16:52:49 zecke |
29 | * -Remove old Todo classes they're deprecated and today I already using the | 34 | * -Remove old Todo classes they're deprecated and today I already using the |
30 | * new API | 35 | * new API |
31 | * -Guard against self assignment in OTodo | 36 | * -Guard against self assignment in OTodo |
32 | * -Add test apps for OPIM | 37 | * -Add test apps for OPIM |
33 | * -Opiefied Event classes | 38 | * -Opiefied Event classes |
34 | * -Added TimeZone handling and pinning of TimeZones to OEvent | 39 | * -Added TimeZone handling and pinning of TimeZones to OEvent |
35 | * -Adjust ORecur and the widget to better timezone behaviour | 40 | * -Adjust ORecur and the widget to better timezone behaviour |
36 | * | 41 | * |
37 | * Revision 1.7 2003/02/16 22:25:46 zecke | 42 | * Revision 1.7 2003/02/16 22:25:46 zecke |
38 | * 0000276 Fix for that bug.. or better temp workaround | 43 | * 0000276 Fix for that bug.. or better temp workaround |
39 | * A Preferred Number is HOME|VOICE | 44 | * A Preferred Number is HOME|VOICE |
40 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test | 45 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test |
41 | * triggers both | 46 | * triggers both |
42 | * and the cell phone number overrides the other entries.. | 47 | * and the cell phone number overrides the other entries.. |
43 | * | 48 | * |
44 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the | 49 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the |
45 | * number | 50 | * number |
46 | * | 51 | * |
47 | * The right and final fix would be to reorder the if statement to make it | 52 | * The right and final fix would be to reorder the if statement to make it |
48 | * if else based and the less common thing put to the bottom | 53 | * if else based and the less common thing put to the bottom |
49 | * | 54 | * |
50 | * OTodoAccessVcal fix the date for beaming | 55 | * OTodoAccessVcal fix the date for beaming |
51 | * | 56 | * |
52 | * Revision 1.6 2003/01/13 15:49:31 eilers | 57 | * Revision 1.6 2003/01/13 15:49:31 eilers |
53 | * Fixing crash when businesscard.vcf is missing.. | 58 | * Fixing crash when businesscard.vcf is missing.. |
54 | * | 59 | * |
55 | * Revision 1.5 2002/12/07 13:26:22 eilers | 60 | * Revision 1.5 2002/12/07 13:26:22 eilers |
56 | * Fixing bug in storing anniversary.. | 61 | * Fixing bug in storing anniversary.. |
57 | * | 62 | * |
58 | * Revision 1.4 2002/11/13 14:14:51 eilers | 63 | * Revision 1.4 2002/11/13 14:14:51 eilers |
59 | * Added sorted for Contacts.. | 64 | * Added sorted for Contacts.. |
60 | * | 65 | * |
61 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 66 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
62 | * no default arguments in implementation | 67 | * no default arguments in implementation |
63 | * | 68 | * |
64 | * Revision 1.2 2002/11/10 15:41:53 eilers | 69 | * Revision 1.2 2002/11/10 15:41:53 eilers |
65 | * Bugfixes.. | 70 | * Bugfixes.. |
66 | * | 71 | * |
67 | * Revision 1.1 2002/11/09 14:34:52 eilers | 72 | * Revision 1.1 2002/11/09 14:34:52 eilers |
68 | * Added VCard Backend. | 73 | * Added VCard Backend. |
69 | * | 74 | * |
70 | */ | 75 | */ |
71 | #include "ocontactaccessbackend_vcard.h" | 76 | #include "ocontactaccessbackend_vcard.h" |
72 | #include "../../library/backend/vobject_p.h" | 77 | #include "../../library/backend/vobject_p.h" |
73 | #include "../../library/backend/qfiledirect_p.h" | 78 | #include "../../library/backend/qfiledirect_p.h" |
74 | 79 | ||
75 | #include <qpe/timeconversion.h> | 80 | #include <qpe/timeconversion.h> |
76 | 81 | ||
77 | #include <qfile.h> | 82 | #include <qfile.h> |
78 | 83 | ||
79 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 84 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): |
80 | m_dirty( false ), | 85 | m_dirty( false ), |
81 | m_file( filename ) | 86 | m_file( filename ) |
82 | { | 87 | { |
83 | load(); | 88 | load(); |
84 | } | 89 | } |
85 | 90 | ||
86 | 91 | ||
87 | bool OContactAccessBackend_VCard::load () | 92 | bool OContactAccessBackend_VCard::load () |
88 | { | 93 | { |
89 | m_map.clear(); | 94 | m_map.clear(); |
90 | m_dirty = false; | 95 | m_dirty = false; |
91 | 96 | ||
92 | VObject* obj = 0l; | 97 | VObject* obj = 0l; |
93 | 98 | ||
94 | if ( QFile::exists(m_file) ){ | 99 | if ( QFile::exists(m_file) ){ |
95 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 100 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
96 | if ( !obj ) | 101 | if ( !obj ) |
97 | return false; | 102 | return false; |
98 | }else{ | 103 | }else{ |
99 | qWarning("File \"%s\" not found !", m_file.latin1() ); | 104 | qWarning("File \"%s\" not found !", m_file.latin1() ); |
100 | return false; | 105 | return false; |
101 | } | 106 | } |
102 | 107 | ||
103 | while ( obj ) { | 108 | while ( obj ) { |
104 | OContact con = parseVObject( obj ); | 109 | OContact con = parseVObject( obj ); |
105 | /* | 110 | /* |
106 | * if uid is 0 assign a new one | 111 | * if uid is 0 assign a new one |
107 | * this at least happens on | 112 | * this at least happens on |
108 | * Nokia6210 | 113 | * Nokia6210 |
109 | */ | 114 | */ |
110 | if ( con.uid() == 0 ){ | 115 | if ( con.uid() == 0 ){ |
111 | con.setUid( 1 ); | 116 | con.setUid( 1 ); |
112 | qWarning("assigned new uid %d",con.uid() ); | 117 | qWarning("assigned new uid %d",con.uid() ); |
113 | } | 118 | } |
114 | 119 | ||
115 | m_map.insert( con.uid(), con ); | 120 | m_map.insert( con.uid(), con ); |
116 | 121 | ||
117 | VObject *t = obj; | 122 | VObject *t = obj; |
118 | obj = nextVObjectInList(obj); | 123 | obj = nextVObjectInList(obj); |
119 | cleanVObject( t ); | 124 | cleanVObject( t ); |
120 | } | 125 | } |
121 | 126 | ||
122 | return true; | 127 | return true; |
123 | 128 | ||
124 | } | 129 | } |
125 | bool OContactAccessBackend_VCard::reload() | 130 | bool OContactAccessBackend_VCard::reload() |
126 | { | 131 | { |
127 | return load(); | 132 | return load(); |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h index 93e2da3..712d769 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | |||
@@ -1,86 +1,96 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 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 | * | ||
20 | * Revision 1.5 2003/03/21 10:33:09 eilers | 25 | * Revision 1.5 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 28 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 29 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 30 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 31 | * the binaries for today-addressbook. |
27 | * | 32 | * |
28 | * Revision 1.4 2002/12/07 13:26:22 eilers | 33 | * Revision 1.4 2002/12/07 13:26:22 eilers |
29 | * Fixing bug in storing anniversary.. | 34 | * Fixing bug in storing anniversary.. |
30 | * | 35 | * |
31 | * Revision 1.3 2002/11/13 14:14:51 eilers | 36 | * Revision 1.3 2002/11/13 14:14:51 eilers |
32 | * Added sorted for Contacts.. | 37 | * Added sorted for Contacts.. |
33 | * | 38 | * |
34 | * Revision 1.2 2002/11/10 15:41:53 eilers | 39 | * Revision 1.2 2002/11/10 15:41:53 eilers |
35 | * Bugfixes.. | 40 | * Bugfixes.. |
36 | * | 41 | * |
37 | * Revision 1.1 2002/11/09 14:34:52 eilers | 42 | * Revision 1.1 2002/11/09 14:34:52 eilers |
38 | * Added VCard Backend. | 43 | * Added VCard Backend. |
39 | * | 44 | * |
40 | */ | 45 | */ |
41 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ | 46 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ |
42 | #define __OCONTACTACCESSBACKEND_VCARD_H_ | 47 | #define __OCONTACTACCESSBACKEND_VCARD_H_ |
43 | 48 | ||
44 | #include <opie/ocontact.h> | 49 | #include <opie/ocontact.h> |
45 | 50 | ||
46 | #include "ocontactaccessbackend.h" | 51 | #include "ocontactaccessbackend.h" |
47 | 52 | ||
48 | class VObject; | 53 | class VObject; |
49 | 54 | ||
55 | /** | ||
56 | * This is the vCard 2.1 implementation of the Contact Storage | ||
57 | * @see OContactAccessBackend_XML | ||
58 | * @see OPimAccessBackend | ||
59 | */ | ||
50 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 60 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
51 | public: | 61 | public: |
52 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); | 62 | OContactAccessBackend_VCard ( const QString& appname, const QString& filename = QString::null ); |
53 | 63 | ||
54 | bool load (); | 64 | bool load (); |
55 | bool reload(); | 65 | bool reload(); |
56 | bool save(); | 66 | bool save(); |
57 | void clear (); | 67 | void clear (); |
58 | 68 | ||
59 | bool add ( const OContact& newcontact ); | 69 | bool add ( const OContact& newcontact ); |
60 | bool remove ( int uid ); | 70 | bool remove ( int uid ); |
61 | bool replace ( const OContact& contact ); | 71 | bool replace ( const OContact& contact ); |
62 | 72 | ||
63 | OContact find ( int uid ) const; | 73 | OContact find ( int uid ) const; |
64 | QArray<int> allRecords() const; | 74 | QArray<int> allRecords() const; |
65 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 75 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
66 | QArray<int> matchRegexp( const QRegExp &r ) const; | 76 | QArray<int> matchRegexp( const QRegExp &r ) const; |
67 | 77 | ||
68 | const uint querySettings(); | 78 | const uint querySettings(); |
69 | bool hasQuerySettings (uint querySettings) const; | 79 | bool hasQuerySettings (uint querySettings) const; |
70 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 80 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
71 | bool wasChangedExternally(); | 81 | bool wasChangedExternally(); |
72 | 82 | ||
73 | private: | 83 | private: |
74 | OContact parseVObject( VObject* obj ); | 84 | OContact parseVObject( VObject* obj ); |
75 | VObject* createVObject( const OContact& c ); | 85 | VObject* createVObject( const OContact& c ); |
76 | QString convDateToVCardDate( const QDate& c ) const; | 86 | QString convDateToVCardDate( const QDate& c ) const; |
77 | QDate convVCardDateToDate( const QString& datestr ); | 87 | QDate convVCardDateToDate( const QString& datestr ); |
78 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 88 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
79 | VObject *safeAddProp( VObject* o, const char* prop); | 89 | VObject *safeAddProp( VObject* o, const char* prop); |
80 | 90 | ||
81 | bool m_dirty : 1; | 91 | bool m_dirty : 1; |
82 | QString m_file; | 92 | QString m_file; |
83 | QMap<int, OContact> m_map; | 93 | QMap<int, OContact> m_map; |
84 | }; | 94 | }; |
85 | 95 | ||
86 | #endif | 96 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp index c5a7820..661cd51 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp | |||
@@ -1,784 +1,789 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.5 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.4 2003/03/21 14:32:54 mickeyl | 25 | * Revision 1.4 2003/03/21 14:32:54 mickeyl |
21 | * g++ compliance fix: default arguments belong into the declaration, but not the definition | 26 | * g++ compliance fix: default arguments belong into the declaration, but not the definition |
22 | * | 27 | * |
23 | * Revision 1.3 2003/03/21 12:26:28 eilers | 28 | * Revision 1.3 2003/03/21 12:26:28 eilers |
24 | * Fixing small bug: If we search a birthday from today to today, it returned | 29 | * Fixing small bug: If we search a birthday from today to today, it returned |
25 | * every contact .. | 30 | * every contact .. |
26 | * | 31 | * |
27 | * Revision 1.2 2003/03/21 10:33:09 eilers | 32 | * Revision 1.2 2003/03/21 10:33:09 eilers |
28 | * Merged speed optimized xml backend for contacts to main. | 33 | * Merged speed optimized xml backend for contacts to main. |
29 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 34 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
30 | * all Birthdays/Anniversaries between two dates. This should be used | 35 | * all Birthdays/Anniversaries between two dates. This should be used |
31 | * to show all birthdays in the datebook.. | 36 | * to show all birthdays in the datebook.. |
32 | * This change is sourcecode backward compatible but you have to upgrade | 37 | * This change is sourcecode backward compatible but you have to upgrade |
33 | * the binaries for today-addressbook. | 38 | * the binaries for today-addressbook. |
34 | * | 39 | * |
35 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers | 40 | * Revision 1.1.2.2 2003/02/11 12:17:28 eilers |
36 | * Speed optimization. Removed the sequential search loops. | 41 | * Speed optimization. Removed the sequential search loops. |
37 | * | 42 | * |
38 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers | 43 | * Revision 1.1.2.1 2003/02/10 15:31:38 eilers |
39 | * Writing offsets to debug output.. | 44 | * Writing offsets to debug output.. |
40 | * | 45 | * |
41 | * Revision 1.1 2003/02/09 15:05:01 eilers | 46 | * Revision 1.1 2003/02/09 15:05:01 eilers |
42 | * Nothing happened.. Just some cleanup before I will start.. | 47 | * Nothing happened.. Just some cleanup before I will start.. |
43 | * | 48 | * |
44 | * Revision 1.12 2003/01/03 16:58:03 eilers | 49 | * Revision 1.12 2003/01/03 16:58:03 eilers |
45 | * Reenable debug output | 50 | * Reenable debug output |
46 | * | 51 | * |
47 | * Revision 1.11 2003/01/03 12:31:28 eilers | 52 | * Revision 1.11 2003/01/03 12:31:28 eilers |
48 | * Bugfix for calculating data diffs.. | 53 | * Bugfix for calculating data diffs.. |
49 | * | 54 | * |
50 | * Revision 1.10 2003/01/02 14:27:12 eilers | 55 | * Revision 1.10 2003/01/02 14:27:12 eilers |
51 | * Improved query by example: Search by date is possible.. First step | 56 | * Improved query by example: Search by date is possible.. First step |
52 | * for a today plugin for birthdays.. | 57 | * for a today plugin for birthdays.. |
53 | * | 58 | * |
54 | * Revision 1.9 2002/12/08 12:48:57 eilers | 59 | * Revision 1.9 2002/12/08 12:48:57 eilers |
55 | * Moved journal-enum from ocontact into i the xml-backend.. | 60 | * Moved journal-enum from ocontact into i the xml-backend.. |
56 | * | 61 | * |
57 | * Revision 1.8 2002/11/14 17:04:24 eilers | 62 | * Revision 1.8 2002/11/14 17:04:24 eilers |
58 | * Sorting will now work if fullname is identical on some entries | 63 | * Sorting will now work if fullname is identical on some entries |
59 | * | 64 | * |
60 | * Revision 1.7 2002/11/13 15:02:46 eilers | 65 | * Revision 1.7 2002/11/13 15:02:46 eilers |
61 | * Small Bug in sorted fixed | 66 | * Small Bug in sorted fixed |
62 | * | 67 | * |
63 | * Revision 1.6 2002/11/13 14:14:51 eilers | 68 | * Revision 1.6 2002/11/13 14:14:51 eilers |
64 | * Added sorted for Contacts.. | 69 | * Added sorted for Contacts.. |
65 | * | 70 | * |
66 | * Revision 1.5 2002/11/01 15:10:42 eilers | 71 | * Revision 1.5 2002/11/01 15:10:42 eilers |
67 | * Added regExp-search in database for all fields in a contact. | 72 | * Added regExp-search in database for all fields in a contact. |
68 | * | 73 | * |
69 | * Revision 1.4 2002/10/16 10:52:40 eilers | 74 | * Revision 1.4 2002/10/16 10:52:40 eilers |
70 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 75 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
71 | * | 76 | * |
72 | * Revision 1.3 2002/10/14 16:21:54 eilers | 77 | * Revision 1.3 2002/10/14 16:21:54 eilers |
73 | * Some minor interface updates | 78 | * Some minor interface updates |
74 | * | 79 | * |
75 | * Revision 1.2 2002/10/07 17:34:24 eilers | 80 | * Revision 1.2 2002/10/07 17:34:24 eilers |
76 | * added OBackendFactory for advanced backend access | 81 | * added OBackendFactory for advanced backend access |
77 | * | 82 | * |
78 | * Revision 1.1 2002/09/27 17:11:44 eilers | 83 | * Revision 1.1 2002/09/27 17:11:44 eilers |
79 | * Added API for accessing the Contact-Database ! It is compiling, but | 84 | * Added API for accessing the Contact-Database ! It is compiling, but |
80 | * please do not expect that anything is working ! | 85 | * please do not expect that anything is working ! |
81 | * I will debug that stuff in the next time .. | 86 | * I will debug that stuff in the next time .. |
82 | * Please read README_COMPILE for compiling ! | 87 | * Please read README_COMPILE for compiling ! |
83 | * | 88 | * |
84 | * | 89 | * |
85 | */ | 90 | */ |
86 | 91 | ||
87 | #include "ocontactaccessbackend_xml.h" | 92 | #include "ocontactaccessbackend_xml.h" |
88 | 93 | ||
89 | #include <qasciidict.h> | 94 | #include <qasciidict.h> |
90 | #include <qdatetime.h> | 95 | #include <qdatetime.h> |
91 | #include <qfile.h> | 96 | #include <qfile.h> |
92 | #include <qfileinfo.h> | 97 | #include <qfileinfo.h> |
93 | #include <qregexp.h> | 98 | #include <qregexp.h> |
94 | #include <qarray.h> | 99 | #include <qarray.h> |
95 | #include <qmap.h> | 100 | #include <qmap.h> |
96 | #include <qdatetime.h> | 101 | #include <qdatetime.h> |
97 | 102 | ||
98 | #include <qpe/global.h> | 103 | #include <qpe/global.h> |
99 | 104 | ||
100 | #include <opie/xmltree.h> | 105 | #include <opie/xmltree.h> |
101 | #include "ocontactaccessbackend.h" | 106 | #include "ocontactaccessbackend.h" |
102 | #include "ocontactaccess.h" | 107 | #include "ocontactaccess.h" |
103 | 108 | ||
104 | #include <stdlib.h> | 109 | #include <stdlib.h> |
105 | #include <errno.h> | 110 | #include <errno.h> |
106 | 111 | ||
107 | using namespace Opie; | 112 | using namespace Opie; |
108 | 113 | ||
109 | 114 | ||
110 | OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename ): | 115 | OContactAccessBackend_XML::OContactAccessBackend_XML ( const QString& appname, const QString& filename ): |
111 | m_changed( false ) | 116 | m_changed( false ) |
112 | { | 117 | { |
113 | // Just m_contactlist should call delete if an entry | 118 | // Just m_contactlist should call delete if an entry |
114 | // is removed. | 119 | // is removed. |
115 | m_contactList.setAutoDelete( true ); | 120 | m_contactList.setAutoDelete( true ); |
116 | m_uidToContact.setAutoDelete( false ); | 121 | m_uidToContact.setAutoDelete( false ); |
117 | 122 | ||
118 | m_appName = appname; | 123 | m_appName = appname; |
119 | 124 | ||
120 | /* Set journalfile name ... */ | 125 | /* Set journalfile name ... */ |
121 | m_journalName = getenv("HOME"); | 126 | m_journalName = getenv("HOME"); |
122 | m_journalName +="/.abjournal" + appname; | 127 | m_journalName +="/.abjournal" + appname; |
123 | 128 | ||
124 | /* Expecting to access the default filename if nothing else is set */ | 129 | /* Expecting to access the default filename if nothing else is set */ |
125 | if ( filename.isEmpty() ){ | 130 | if ( filename.isEmpty() ){ |
126 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 131 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
127 | } else | 132 | } else |
128 | m_fileName = filename; | 133 | m_fileName = filename; |
129 | 134 | ||
130 | /* Load Database now */ | 135 | /* Load Database now */ |
131 | load (); | 136 | load (); |
132 | } | 137 | } |
133 | 138 | ||
134 | bool OContactAccessBackend_XML::save() | 139 | bool OContactAccessBackend_XML::save() |
135 | { | 140 | { |
136 | 141 | ||
137 | if ( !m_changed ) | 142 | if ( !m_changed ) |
138 | return true; | 143 | return true; |
139 | 144 | ||
140 | QString strNewFile = m_fileName + ".new"; | 145 | QString strNewFile = m_fileName + ".new"; |
141 | QFile f( strNewFile ); | 146 | QFile f( strNewFile ); |
142 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 147 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
143 | return false; | 148 | return false; |
144 | 149 | ||
145 | int total_written; | 150 | int total_written; |
146 | int idx_offset = 0; | 151 | int idx_offset = 0; |
147 | QString out; | 152 | QString out; |
148 | 153 | ||
149 | // Write Header | 154 | // Write Header |
150 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 155 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
151 | " <Groups>\n" | 156 | " <Groups>\n" |
152 | " </Groups>\n" | 157 | " </Groups>\n" |
153 | " <Contacts>\n"; | 158 | " <Contacts>\n"; |
154 | QCString cstr = out.utf8(); | 159 | QCString cstr = out.utf8(); |
155 | f.writeBlock( cstr.data(), cstr.length() ); | 160 | f.writeBlock( cstr.data(), cstr.length() ); |
156 | idx_offset += cstr.length(); | 161 | idx_offset += cstr.length(); |
157 | out = ""; | 162 | out = ""; |
158 | 163 | ||
159 | // Write all contacts | 164 | // Write all contacts |
160 | QListIterator<OContact> it( m_contactList ); | 165 | QListIterator<OContact> it( m_contactList ); |
161 | for ( ; it.current(); ++it ) { | 166 | for ( ; it.current(); ++it ) { |
162 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); | 167 | qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); |
163 | out += "<Contact "; | 168 | out += "<Contact "; |
164 | (*it)->save( out ); | 169 | (*it)->save( out ); |
165 | out += "/>\n"; | 170 | out += "/>\n"; |
166 | cstr = out.utf8(); | 171 | cstr = out.utf8(); |
167 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 172 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
168 | idx_offset += cstr.length(); | 173 | idx_offset += cstr.length(); |
169 | if ( total_written != int(cstr.length()) ) { | 174 | if ( total_written != int(cstr.length()) ) { |
170 | f.close(); | 175 | f.close(); |
171 | QFile::remove( strNewFile ); | 176 | QFile::remove( strNewFile ); |
172 | return false; | 177 | return false; |
173 | } | 178 | } |
174 | out = ""; | 179 | out = ""; |
175 | } | 180 | } |
176 | out += " </Contacts>\n</AddressBook>\n"; | 181 | out += " </Contacts>\n</AddressBook>\n"; |
177 | 182 | ||
178 | // Write Footer | 183 | // Write Footer |
179 | cstr = out.utf8(); | 184 | cstr = out.utf8(); |
180 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | 185 | total_written = f.writeBlock( cstr.data(), cstr.length() ); |
181 | if ( total_written != int( cstr.length() ) ) { | 186 | if ( total_written != int( cstr.length() ) ) { |
182 | f.close(); | 187 | f.close(); |
183 | QFile::remove( strNewFile ); | 188 | QFile::remove( strNewFile ); |
184 | return false; | 189 | return false; |
185 | } | 190 | } |
186 | f.close(); | 191 | f.close(); |
187 | 192 | ||
188 | // move the file over, I'm just going to use the system call | 193 | // move the file over, I'm just going to use the system call |
189 | // because, I don't feel like using QDir. | 194 | // because, I don't feel like using QDir. |
190 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { | 195 | if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { |
191 | qWarning( "problem renaming file %s to %s, errno: %d", | 196 | qWarning( "problem renaming file %s to %s, errno: %d", |
192 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 197 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
193 | // remove the tmp file... | 198 | // remove the tmp file... |
194 | QFile::remove( strNewFile ); | 199 | QFile::remove( strNewFile ); |
195 | } | 200 | } |
196 | 201 | ||
197 | /* The journalfile should be removed now... */ | 202 | /* The journalfile should be removed now... */ |
198 | removeJournal(); | 203 | removeJournal(); |
199 | 204 | ||
200 | m_changed = false; | 205 | m_changed = false; |
201 | return true; | 206 | return true; |
202 | } | 207 | } |
203 | 208 | ||
204 | bool OContactAccessBackend_XML::load () | 209 | bool OContactAccessBackend_XML::load () |
205 | { | 210 | { |
206 | m_contactList.clear(); | 211 | m_contactList.clear(); |
207 | m_uidToContact.clear(); | 212 | m_uidToContact.clear(); |
208 | 213 | ||
209 | /* Load XML-File and journal if it exists */ | 214 | /* Load XML-File and journal if it exists */ |
210 | if ( !load ( m_fileName, false ) ) | 215 | if ( !load ( m_fileName, false ) ) |
211 | return false; | 216 | return false; |
212 | /* The returncode of the journalfile is ignored due to the | 217 | /* The returncode of the journalfile is ignored due to the |
213 | * fact that it does not exist when this class is instantiated ! | 218 | * fact that it does not exist when this class is instantiated ! |
214 | * But there may such a file exist, if the application crashed. | 219 | * But there may such a file exist, if the application crashed. |
215 | * Therefore we try to load it to get the changes before the # | 220 | * Therefore we try to load it to get the changes before the # |
216 | * crash happened... | 221 | * crash happened... |
217 | */ | 222 | */ |
218 | load (m_journalName, true); | 223 | load (m_journalName, true); |
219 | 224 | ||
220 | return true; | 225 | return true; |
221 | } | 226 | } |
222 | 227 | ||
223 | void OContactAccessBackend_XML::clear () | 228 | void OContactAccessBackend_XML::clear () |
224 | { | 229 | { |
225 | m_contactList.clear(); | 230 | m_contactList.clear(); |
226 | m_uidToContact.clear(); | 231 | m_uidToContact.clear(); |
227 | 232 | ||
228 | m_changed = false; | 233 | m_changed = false; |
229 | } | 234 | } |
230 | 235 | ||
231 | bool OContactAccessBackend_XML::wasChangedExternally() | 236 | bool OContactAccessBackend_XML::wasChangedExternally() |
232 | { | 237 | { |
233 | QFileInfo fi( m_fileName ); | 238 | QFileInfo fi( m_fileName ); |
234 | 239 | ||
235 | QDateTime lastmod = fi.lastModified (); | 240 | QDateTime lastmod = fi.lastModified (); |
236 | 241 | ||
237 | return (lastmod != m_readtime); | 242 | return (lastmod != m_readtime); |
238 | } | 243 | } |
239 | 244 | ||
240 | QArray<int> OContactAccessBackend_XML::allRecords() const | 245 | QArray<int> OContactAccessBackend_XML::allRecords() const |
241 | { | 246 | { |
242 | QArray<int> uid_list( m_contactList.count() ); | 247 | QArray<int> uid_list( m_contactList.count() ); |
243 | 248 | ||
244 | uint counter = 0; | 249 | uint counter = 0; |
245 | QListIterator<OContact> it( m_contactList ); | 250 | QListIterator<OContact> it( m_contactList ); |
246 | for( ; it.current(); ++it ){ | 251 | for( ; it.current(); ++it ){ |
247 | uid_list[counter++] = (*it)->uid(); | 252 | uid_list[counter++] = (*it)->uid(); |
248 | } | 253 | } |
249 | 254 | ||
250 | return ( uid_list ); | 255 | return ( uid_list ); |
251 | } | 256 | } |
252 | 257 | ||
253 | OContact OContactAccessBackend_XML::find ( int uid ) const | 258 | OContact OContactAccessBackend_XML::find ( int uid ) const |
254 | { | 259 | { |
255 | OContact foundContact; //Create empty contact | 260 | OContact foundContact; //Create empty contact |
256 | 261 | ||
257 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); | 262 | OContact* found = m_uidToContact.find( QString().setNum( uid ) ); |
258 | 263 | ||
259 | if ( found ){ | 264 | if ( found ){ |
260 | foundContact = *found; | 265 | foundContact = *found; |
261 | } | 266 | } |
262 | 267 | ||
263 | return ( foundContact ); | 268 | return ( foundContact ); |
264 | } | 269 | } |
265 | 270 | ||
266 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 271 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, |
267 | const QDateTime& d ) | 272 | const QDateTime& d ) |
268 | { | 273 | { |
269 | 274 | ||
270 | QArray<int> m_currentQuery( m_contactList.count() ); | 275 | QArray<int> m_currentQuery( m_contactList.count() ); |
271 | QListIterator<OContact> it( m_contactList ); | 276 | QListIterator<OContact> it( m_contactList ); |
272 | uint arraycounter = 0; | 277 | uint arraycounter = 0; |
273 | 278 | ||
274 | for( ; it.current(); ++it ){ | 279 | for( ; it.current(); ++it ){ |
275 | /* Search all fields and compare them with query object. Store them into list | 280 | /* Search all fields and compare them with query object. Store them into list |
276 | * if all fields matches. | 281 | * if all fields matches. |
277 | */ | 282 | */ |
278 | QDate* queryDate = 0l; | 283 | QDate* queryDate = 0l; |
279 | QDate* checkDate = 0l; | 284 | QDate* checkDate = 0l; |
280 | bool allcorrect = true; | 285 | bool allcorrect = true; |
281 | for ( int i = 0; i < Qtopia::Groups; i++ ) { | 286 | for ( int i = 0; i < Qtopia::Groups; i++ ) { |
282 | // Birthday and anniversary are special nonstring fields and should | 287 | // Birthday and anniversary are special nonstring fields and should |
283 | // be handled specially | 288 | // be handled specially |
284 | switch ( i ){ | 289 | switch ( i ){ |
285 | case Qtopia::Birthday: | 290 | case Qtopia::Birthday: |
286 | queryDate = new QDate( query.birthday() ); | 291 | queryDate = new QDate( query.birthday() ); |
287 | checkDate = new QDate( (*it)->birthday() ); | 292 | checkDate = new QDate( (*it)->birthday() ); |
288 | case Qtopia::Anniversary: | 293 | case Qtopia::Anniversary: |
289 | if ( queryDate == 0l ){ | 294 | if ( queryDate == 0l ){ |
290 | queryDate = new QDate( query.anniversary() ); | 295 | queryDate = new QDate( query.anniversary() ); |
291 | checkDate = new QDate( (*it)->anniversary() ); | 296 | checkDate = new QDate( (*it)->anniversary() ); |
292 | } | 297 | } |
293 | 298 | ||
294 | if ( queryDate->isValid() ){ | 299 | if ( queryDate->isValid() ){ |
295 | if( checkDate->isValid() ){ | 300 | if( checkDate->isValid() ){ |
296 | if ( settings & OContactAccess::DateYear ){ | 301 | if ( settings & OContactAccess::DateYear ){ |
297 | if ( queryDate->year() != checkDate->year() ) | 302 | if ( queryDate->year() != checkDate->year() ) |
298 | allcorrect = false; | 303 | allcorrect = false; |
299 | } | 304 | } |
300 | if ( settings & OContactAccess::DateMonth ){ | 305 | if ( settings & OContactAccess::DateMonth ){ |
301 | if ( queryDate->month() != checkDate->month() ) | 306 | if ( queryDate->month() != checkDate->month() ) |
302 | allcorrect = false; | 307 | allcorrect = false; |
303 | } | 308 | } |
304 | if ( settings & OContactAccess::DateDay ){ | 309 | if ( settings & OContactAccess::DateDay ){ |
305 | if ( queryDate->day() != checkDate->day() ) | 310 | if ( queryDate->day() != checkDate->day() ) |
306 | allcorrect = false; | 311 | allcorrect = false; |
307 | } | 312 | } |
308 | if ( settings & OContactAccess::DateDiff ) { | 313 | if ( settings & OContactAccess::DateDiff ) { |
309 | QDate current; | 314 | QDate current; |
310 | // If we get an additional date, we | 315 | // If we get an additional date, we |
311 | // will take this date instead of | 316 | // will take this date instead of |
312 | // the current one.. | 317 | // the current one.. |
313 | if ( !d.date().isValid() ) | 318 | if ( !d.date().isValid() ) |
314 | current = QDate::currentDate(); | 319 | current = QDate::currentDate(); |
315 | else | 320 | else |
316 | current = d.date(); | 321 | current = d.date(); |
317 | 322 | ||
318 | // We have to equalize the year, otherwise | 323 | // We have to equalize the year, otherwise |
319 | // the search will fail.. | 324 | // the search will fail.. |
320 | checkDate->setYMD( current.year(), | 325 | checkDate->setYMD( current.year(), |
321 | checkDate->month(), | 326 | checkDate->month(), |
322 | checkDate->day() ); | 327 | checkDate->day() ); |
323 | if ( *checkDate < current ) | 328 | if ( *checkDate < current ) |
324 | checkDate->setYMD( current.year()+1, | 329 | checkDate->setYMD( current.year()+1, |
325 | checkDate->month(), | 330 | checkDate->month(), |
326 | checkDate->day() ); | 331 | checkDate->day() ); |
327 | 332 | ||
328 | // Check whether the birthday/anniversary date is between | 333 | // Check whether the birthday/anniversary date is between |
329 | // the current/given date and the maximum date | 334 | // the current/given date and the maximum date |
330 | // ( maximum time range ) ! | 335 | // ( maximum time range ) ! |
331 | qWarning("Checking if %s is between %s and %s ! ", | 336 | qWarning("Checking if %s is between %s and %s ! ", |
332 | checkDate->toString().latin1(), | 337 | checkDate->toString().latin1(), |
333 | current.toString().latin1(), | 338 | current.toString().latin1(), |
334 | queryDate->toString().latin1() ); | 339 | queryDate->toString().latin1() ); |
335 | if ( current.daysTo( *queryDate ) >= 0 ){ | 340 | if ( current.daysTo( *queryDate ) >= 0 ){ |
336 | if ( !( ( *checkDate >= current ) && | 341 | if ( !( ( *checkDate >= current ) && |
337 | ( *checkDate <= *queryDate ) ) ){ | 342 | ( *checkDate <= *queryDate ) ) ){ |
338 | allcorrect = false; | 343 | allcorrect = false; |
339 | qWarning (" Nope!.."); | 344 | qWarning (" Nope!.."); |
340 | } | 345 | } |
341 | } | 346 | } |
342 | } | 347 | } |
343 | } else{ | 348 | } else{ |
344 | // checkDate is invalid. Therefore this entry is always rejected | 349 | // checkDate is invalid. Therefore this entry is always rejected |
345 | allcorrect = false; | 350 | allcorrect = false; |
346 | } | 351 | } |
347 | } | 352 | } |
348 | 353 | ||
349 | delete queryDate; | 354 | delete queryDate; |
350 | queryDate = 0l; | 355 | queryDate = 0l; |
351 | delete checkDate; | 356 | delete checkDate; |
352 | checkDate = 0l; | 357 | checkDate = 0l; |
353 | break; | 358 | break; |
354 | default: | 359 | default: |
355 | /* Just compare fields which are not empty in the query object */ | 360 | /* Just compare fields which are not empty in the query object */ |
356 | if ( !query.field(i).isEmpty() ){ | 361 | if ( !query.field(i).isEmpty() ){ |
357 | switch ( settings & ~( OContactAccess::IgnoreCase | 362 | switch ( settings & ~( OContactAccess::IgnoreCase |
358 | | OContactAccess::DateDiff | 363 | | OContactAccess::DateDiff |
359 | | OContactAccess::DateYear | 364 | | OContactAccess::DateYear |
360 | | OContactAccess::DateMonth | 365 | | OContactAccess::DateMonth |
361 | | OContactAccess::DateDay | 366 | | OContactAccess::DateDay |
362 | | OContactAccess::MatchOne | 367 | | OContactAccess::MatchOne |
363 | ) ){ | 368 | ) ){ |
364 | 369 | ||
365 | case OContactAccess::RegExp:{ | 370 | case OContactAccess::RegExp:{ |
366 | QRegExp expr ( query.field(i), | 371 | QRegExp expr ( query.field(i), |
367 | !(settings & OContactAccess::IgnoreCase), | 372 | !(settings & OContactAccess::IgnoreCase), |
368 | false ); | 373 | false ); |
369 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 374 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
370 | allcorrect = false; | 375 | allcorrect = false; |
371 | } | 376 | } |
372 | break; | 377 | break; |
373 | case OContactAccess::WildCards:{ | 378 | case OContactAccess::WildCards:{ |
374 | QRegExp expr ( query.field(i), | 379 | QRegExp expr ( query.field(i), |
375 | !(settings & OContactAccess::IgnoreCase), | 380 | !(settings & OContactAccess::IgnoreCase), |
376 | true ); | 381 | true ); |
377 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) | 382 | if ( expr.find ( (*it)->field(i), 0 ) == -1 ) |
378 | allcorrect = false; | 383 | allcorrect = false; |
379 | } | 384 | } |
380 | break; | 385 | break; |
381 | case OContactAccess::ExactMatch:{ | 386 | case OContactAccess::ExactMatch:{ |
382 | if (settings & OContactAccess::IgnoreCase){ | 387 | if (settings & OContactAccess::IgnoreCase){ |
383 | if ( query.field(i).upper() != | 388 | if ( query.field(i).upper() != |
384 | (*it)->field(i).upper() ) | 389 | (*it)->field(i).upper() ) |
385 | allcorrect = false; | 390 | allcorrect = false; |
386 | }else{ | 391 | }else{ |
387 | if ( query.field(i) != (*it)->field(i) ) | 392 | if ( query.field(i) != (*it)->field(i) ) |
388 | allcorrect = false; | 393 | allcorrect = false; |
389 | } | 394 | } |
390 | } | 395 | } |
391 | break; | 396 | break; |
392 | } | 397 | } |
393 | } | 398 | } |
394 | } | 399 | } |
395 | } | 400 | } |
396 | if ( allcorrect ){ | 401 | if ( allcorrect ){ |
397 | m_currentQuery[arraycounter++] = (*it)->uid(); | 402 | m_currentQuery[arraycounter++] = (*it)->uid(); |
398 | } | 403 | } |
399 | } | 404 | } |
400 | 405 | ||
401 | // Shrink to fit.. | 406 | // Shrink to fit.. |
402 | m_currentQuery.resize(arraycounter); | 407 | m_currentQuery.resize(arraycounter); |
403 | 408 | ||
404 | return m_currentQuery; | 409 | return m_currentQuery; |
405 | } | 410 | } |
406 | 411 | ||
407 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 412 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const |
408 | { | 413 | { |
409 | QArray<int> m_currentQuery( m_contactList.count() ); | 414 | QArray<int> m_currentQuery( m_contactList.count() ); |
410 | QListIterator<OContact> it( m_contactList ); | 415 | QListIterator<OContact> it( m_contactList ); |
411 | uint arraycounter = 0; | 416 | uint arraycounter = 0; |
412 | 417 | ||
413 | for( ; it.current(); ++it ){ | 418 | for( ; it.current(); ++it ){ |
414 | if ( (*it)->match( r ) ){ | 419 | if ( (*it)->match( r ) ){ |
415 | m_currentQuery[arraycounter++] = (*it)->uid(); | 420 | m_currentQuery[arraycounter++] = (*it)->uid(); |
416 | } | 421 | } |
417 | 422 | ||
418 | } | 423 | } |
419 | // Shrink to fit.. | 424 | // Shrink to fit.. |
420 | m_currentQuery.resize(arraycounter); | 425 | m_currentQuery.resize(arraycounter); |
421 | 426 | ||
422 | return m_currentQuery; | 427 | return m_currentQuery; |
423 | } | 428 | } |
424 | 429 | ||
425 | const uint OContactAccessBackend_XML::querySettings() | 430 | const uint OContactAccessBackend_XML::querySettings() |
426 | { | 431 | { |
427 | return ( OContactAccess::WildCards | 432 | return ( OContactAccess::WildCards |
428 | | OContactAccess::IgnoreCase | 433 | | OContactAccess::IgnoreCase |
429 | | OContactAccess::RegExp | 434 | | OContactAccess::RegExp |
430 | | OContactAccess::ExactMatch | 435 | | OContactAccess::ExactMatch |
431 | | OContactAccess::DateDiff | 436 | | OContactAccess::DateDiff |
432 | | OContactAccess::DateYear | 437 | | OContactAccess::DateYear |
433 | | OContactAccess::DateMonth | 438 | | OContactAccess::DateMonth |
434 | | OContactAccess::DateDay | 439 | | OContactAccess::DateDay |
435 | ); | 440 | ); |
436 | } | 441 | } |
437 | 442 | ||
438 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | 443 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const |
439 | { | 444 | { |
440 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 445 | /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
441 | * may be added with any of the other settings. IgnoreCase should never used alone. | 446 | * may be added with any of the other settings. IgnoreCase should never used alone. |
442 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 447 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
443 | */ | 448 | */ |
444 | 449 | ||
445 | if ( querySettings == OContactAccess::IgnoreCase ) | 450 | if ( querySettings == OContactAccess::IgnoreCase ) |
446 | return false; | 451 | return false; |
447 | 452 | ||
448 | switch ( querySettings & ~( OContactAccess::IgnoreCase | 453 | switch ( querySettings & ~( OContactAccess::IgnoreCase |
449 | | OContactAccess::DateDiff | 454 | | OContactAccess::DateDiff |
450 | | OContactAccess::DateYear | 455 | | OContactAccess::DateYear |
451 | | OContactAccess::DateMonth | 456 | | OContactAccess::DateMonth |
452 | | OContactAccess::DateDay | 457 | | OContactAccess::DateDay |
453 | ) | 458 | ) |
454 | ){ | 459 | ){ |
455 | case OContactAccess::RegExp: | 460 | case OContactAccess::RegExp: |
456 | return ( true ); | 461 | return ( true ); |
457 | case OContactAccess::WildCards: | 462 | case OContactAccess::WildCards: |
458 | return ( true ); | 463 | return ( true ); |
459 | case OContactAccess::ExactMatch: | 464 | case OContactAccess::ExactMatch: |
460 | return ( true ); | 465 | return ( true ); |
461 | default: | 466 | default: |
462 | return ( false ); | 467 | return ( false ); |
463 | } | 468 | } |
464 | } | 469 | } |
465 | 470 | ||
466 | // Currently only asc implemented.. | 471 | // Currently only asc implemented.. |
467 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 472 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) |
468 | { | 473 | { |
469 | QMap<QString, int> nameToUid; | 474 | QMap<QString, int> nameToUid; |
470 | QStringList names; | 475 | QStringList names; |
471 | QArray<int> m_currentQuery( m_contactList.count() ); | 476 | QArray<int> m_currentQuery( m_contactList.count() ); |
472 | 477 | ||
473 | // First fill map and StringList with all Names | 478 | // First fill map and StringList with all Names |
474 | // Afterwards sort namelist and use map to fill array to return.. | 479 | // Afterwards sort namelist and use map to fill array to return.. |
475 | QListIterator<OContact> it( m_contactList ); | 480 | QListIterator<OContact> it( m_contactList ); |
476 | for( ; it.current(); ++it ){ | 481 | for( ; it.current(); ++it ){ |
477 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); | 482 | names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); |
478 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); | 483 | nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); |
479 | } | 484 | } |
480 | names.sort(); | 485 | names.sort(); |
481 | 486 | ||
482 | int i = 0; | 487 | int i = 0; |
483 | if ( asc ){ | 488 | if ( asc ){ |
484 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | 489 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) |
485 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 490 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
486 | }else{ | 491 | }else{ |
487 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) | 492 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) |
488 | m_currentQuery[i++] = nameToUid[ (*it) ]; | 493 | m_currentQuery[i++] = nameToUid[ (*it) ]; |
489 | } | 494 | } |
490 | 495 | ||
491 | return m_currentQuery; | 496 | return m_currentQuery; |
492 | 497 | ||
493 | } | 498 | } |
494 | 499 | ||
495 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | 500 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) |
496 | { | 501 | { |
497 | //qWarning("odefaultbackend: ACTION::ADD"); | 502 | //qWarning("odefaultbackend: ACTION::ADD"); |
498 | updateJournal (newcontact, ACTION_ADD); | 503 | updateJournal (newcontact, ACTION_ADD); |
499 | addContact_p( newcontact ); | 504 | addContact_p( newcontact ); |
500 | 505 | ||
501 | m_changed = true; | 506 | m_changed = true; |
502 | 507 | ||
503 | return true; | 508 | return true; |
504 | } | 509 | } |
505 | 510 | ||
506 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) | 511 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) |
507 | { | 512 | { |
508 | m_changed = true; | 513 | m_changed = true; |
509 | 514 | ||
510 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); | 515 | OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); |
511 | 516 | ||
512 | if ( found ) { | 517 | if ( found ) { |
513 | OContact* newCont = new OContact( contact ); | 518 | OContact* newCont = new OContact( contact ); |
514 | 519 | ||
515 | updateJournal ( *newCont, ACTION_REPLACE); | 520 | updateJournal ( *newCont, ACTION_REPLACE); |
516 | m_contactList.removeRef ( found ); | 521 | m_contactList.removeRef ( found ); |
517 | m_contactList.append ( newCont ); | 522 | m_contactList.append ( newCont ); |
518 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); | 523 | m_uidToContact.remove( QString().setNum( contact.uid() ) ); |
519 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); | 524 | m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); |
520 | 525 | ||
521 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); | 526 | qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); |
522 | 527 | ||
523 | return true; | 528 | return true; |
524 | } else | 529 | } else |
525 | return false; | 530 | return false; |
526 | } | 531 | } |
527 | 532 | ||
528 | bool OContactAccessBackend_XML::remove ( int uid ) | 533 | bool OContactAccessBackend_XML::remove ( int uid ) |
529 | { | 534 | { |
530 | m_changed = true; | 535 | m_changed = true; |
531 | 536 | ||
532 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); | 537 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); |
533 | 538 | ||
534 | if ( found ) { | 539 | if ( found ) { |
535 | updateJournal ( *found, ACTION_REMOVE); | 540 | updateJournal ( *found, ACTION_REMOVE); |
536 | m_contactList.removeRef ( found ); | 541 | m_contactList.removeRef ( found ); |
537 | m_uidToContact.remove( QString().setNum( uid ) ); | 542 | m_uidToContact.remove( QString().setNum( uid ) ); |
538 | 543 | ||
539 | return true; | 544 | return true; |
540 | } else | 545 | } else |
541 | return false; | 546 | return false; |
542 | } | 547 | } |
543 | 548 | ||
544 | bool OContactAccessBackend_XML::reload(){ | 549 | bool OContactAccessBackend_XML::reload(){ |
545 | /* Reload is the same as load in this implementation */ | 550 | /* Reload is the same as load in this implementation */ |
546 | return ( load() ); | 551 | return ( load() ); |
547 | } | 552 | } |
548 | 553 | ||
549 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | 554 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) |
550 | { | 555 | { |
551 | OContact* contRef = new OContact( newcontact ); | 556 | OContact* contRef = new OContact( newcontact ); |
552 | 557 | ||
553 | m_contactList.append ( contRef ); | 558 | m_contactList.append ( contRef ); |
554 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); | 559 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); |
555 | } | 560 | } |
556 | 561 | ||
557 | /* This function loads the xml-database and the journalfile */ | 562 | /* This function loads the xml-database and the journalfile */ |
558 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 563 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
559 | { | 564 | { |
560 | 565 | ||
561 | /* We use the time of the last read to check if the file was | 566 | /* We use the time of the last read to check if the file was |
562 | * changed externally. | 567 | * changed externally. |
563 | */ | 568 | */ |
564 | if ( !isJournal ){ | 569 | if ( !isJournal ){ |
565 | QFileInfo fi( filename ); | 570 | QFileInfo fi( filename ); |
566 | m_readtime = fi.lastModified (); | 571 | m_readtime = fi.lastModified (); |
567 | } | 572 | } |
568 | 573 | ||
569 | const int JOURNALACTION = Qtopia::Notes + 1; | 574 | const int JOURNALACTION = Qtopia::Notes + 1; |
570 | const int JOURNALROW = JOURNALACTION + 1; | 575 | const int JOURNALROW = JOURNALACTION + 1; |
571 | 576 | ||
572 | bool foundAction = false; | 577 | bool foundAction = false; |
573 | journal_action action = ACTION_ADD; | 578 | journal_action action = ACTION_ADD; |
574 | int journalKey = 0; | 579 | int journalKey = 0; |
575 | QMap<int, QString> contactMap; | 580 | QMap<int, QString> contactMap; |
576 | QMap<QString, QString> customMap; | 581 | QMap<QString, QString> customMap; |
577 | QMap<QString, QString>::Iterator customIt; | 582 | QMap<QString, QString>::Iterator customIt; |
578 | QAsciiDict<int> dict( 47 ); | 583 | QAsciiDict<int> dict( 47 ); |
579 | 584 | ||
580 | dict.setAutoDelete( TRUE ); | 585 | dict.setAutoDelete( TRUE ); |
581 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 586 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
582 | dict.insert( "Title", new int(Qtopia::Title) ); | 587 | dict.insert( "Title", new int(Qtopia::Title) ); |
583 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 588 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
584 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 589 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
585 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 590 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
586 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 591 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
587 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 592 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
588 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 593 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
589 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 594 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
590 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 595 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
591 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 596 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
592 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 597 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
593 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 598 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
594 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 599 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
595 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 600 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
596 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 601 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
597 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 602 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
598 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 603 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
599 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 604 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
600 | dict.insert( "Company", new int(Qtopia::Company) ); | 605 | dict.insert( "Company", new int(Qtopia::Company) ); |
601 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 606 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
602 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 607 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
603 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 608 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
604 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 609 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
605 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 610 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
606 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 611 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
607 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 612 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
608 | dict.insert( "Department", new int(Qtopia::Department) ); | 613 | dict.insert( "Department", new int(Qtopia::Department) ); |
609 | dict.insert( "Office", new int(Qtopia::Office) ); | 614 | dict.insert( "Office", new int(Qtopia::Office) ); |
610 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 615 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
611 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 616 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
612 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 617 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
613 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 618 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
614 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 619 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
615 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 620 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
616 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 621 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
617 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 622 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
618 | dict.insert( "Children", new int(Qtopia::Children) ); | 623 | dict.insert( "Children", new int(Qtopia::Children) ); |
619 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 624 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
620 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 625 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
621 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 626 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
622 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 627 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
623 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 628 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
624 | dict.insert( "action", new int(JOURNALACTION) ); | 629 | dict.insert( "action", new int(JOURNALACTION) ); |
625 | dict.insert( "actionrow", new int(JOURNALROW) ); | 630 | dict.insert( "actionrow", new int(JOURNALROW) ); |
626 | 631 | ||
627 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 632 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
628 | 633 | ||
629 | XMLElement *root = XMLElement::load( filename ); | 634 | XMLElement *root = XMLElement::load( filename ); |
630 | if(root != 0l ){ // start parsing | 635 | if(root != 0l ){ // start parsing |
631 | /* Parse all XML-Elements and put the data into the | 636 | /* Parse all XML-Elements and put the data into the |
632 | * Contact-Class | 637 | * Contact-Class |
633 | */ | 638 | */ |
634 | XMLElement *element = root->firstChild(); | 639 | XMLElement *element = root->firstChild(); |
635 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 640 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
636 | element = element->firstChild(); | 641 | element = element->firstChild(); |
637 | 642 | ||
638 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 643 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
639 | while( element && !isJournal ){ | 644 | while( element && !isJournal ){ |
640 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 645 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
641 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 646 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
642 | // element->tagName().latin1()); | 647 | // element->tagName().latin1()); |
643 | element = element->nextChild(); | 648 | element = element->nextChild(); |
644 | } else { | 649 | } else { |
645 | element = element->firstChild(); | 650 | element = element->firstChild(); |
646 | break; | 651 | break; |
647 | } | 652 | } |
648 | } | 653 | } |
649 | /* Parse all Contacts and ignore unknown tags */ | 654 | /* Parse all Contacts and ignore unknown tags */ |
650 | while( element ){ | 655 | while( element ){ |
651 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 656 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
652 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 657 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
653 | // element->tagName().latin1()); | 658 | // element->tagName().latin1()); |
654 | element = element->nextChild(); | 659 | element = element->nextChild(); |
655 | continue; | 660 | continue; |
656 | } | 661 | } |
657 | /* Found alement with tagname "contact", now parse and store all | 662 | /* Found alement with tagname "contact", now parse and store all |
658 | * attributes contained | 663 | * attributes contained |
659 | */ | 664 | */ |
660 | //qWarning("OContactDefBack::load element tagName() : %s", | 665 | //qWarning("OContactDefBack::load element tagName() : %s", |
661 | // element->tagName().latin1() ); | 666 | // element->tagName().latin1() ); |
662 | QString dummy; | 667 | QString dummy; |
663 | foundAction = false; | 668 | foundAction = false; |
664 | 669 | ||
665 | XMLElement::AttributeMap aMap = element->attributes(); | 670 | XMLElement::AttributeMap aMap = element->attributes(); |
666 | XMLElement::AttributeMap::Iterator it; | 671 | XMLElement::AttributeMap::Iterator it; |
667 | contactMap.clear(); | 672 | contactMap.clear(); |
668 | customMap.clear(); | 673 | customMap.clear(); |
669 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 674 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
670 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 675 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
671 | 676 | ||
672 | int *find = dict[ it.key() ]; | 677 | int *find = dict[ it.key() ]; |
673 | /* Unknown attributes will be stored as "Custom" elements */ | 678 | /* Unknown attributes will be stored as "Custom" elements */ |
674 | if ( !find ) { | 679 | if ( !find ) { |
675 | qWarning("Attribute %s not known.", it.key().latin1()); | 680 | qWarning("Attribute %s not known.", it.key().latin1()); |
676 | //contact.setCustomField(it.key(), it.data()); | 681 | //contact.setCustomField(it.key(), it.data()); |
677 | customMap.insert( it.key(), it.data() ); | 682 | customMap.insert( it.key(), it.data() ); |
678 | continue; | 683 | continue; |
679 | } | 684 | } |
680 | 685 | ||
681 | /* Check if special conversion is needed and add attribute | 686 | /* Check if special conversion is needed and add attribute |
682 | * into Contact class | 687 | * into Contact class |
683 | */ | 688 | */ |
684 | switch( *find ) { | 689 | switch( *find ) { |
685 | /* | 690 | /* |
686 | case Qtopia::AddressUid: | 691 | case Qtopia::AddressUid: |
687 | contact.setUid( it.data().toInt() ); | 692 | contact.setUid( it.data().toInt() ); |
688 | break; | 693 | break; |
689 | case Qtopia::AddressCategory: | 694 | case Qtopia::AddressCategory: |
690 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 695 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
691 | break; | 696 | break; |
692 | */ | 697 | */ |
693 | case JOURNALACTION: | 698 | case JOURNALACTION: |
694 | action = journal_action(it.data().toInt()); | 699 | action = journal_action(it.data().toInt()); |
695 | foundAction = true; | 700 | foundAction = true; |
696 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 701 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
697 | break; | 702 | break; |
698 | case JOURNALROW: | 703 | case JOURNALROW: |
699 | journalKey = it.data().toInt(); | 704 | journalKey = it.data().toInt(); |
700 | break; | 705 | break; |
701 | default: // no conversion needed add them to the map | 706 | default: // no conversion needed add them to the map |
702 | contactMap.insert( *find, it.data() ); | 707 | contactMap.insert( *find, it.data() ); |
703 | break; | 708 | break; |
704 | } | 709 | } |
705 | } | 710 | } |
706 | /* now generate the Contact contact */ | 711 | /* now generate the Contact contact */ |
707 | OContact contact( contactMap ); | 712 | OContact contact( contactMap ); |
708 | 713 | ||
709 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 714 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
710 | contact.setCustomField( customIt.key(), customIt.data() ); | 715 | contact.setCustomField( customIt.key(), customIt.data() ); |
711 | } | 716 | } |
712 | 717 | ||
713 | if (foundAction){ | 718 | if (foundAction){ |
714 | foundAction = false; | 719 | foundAction = false; |
715 | switch ( action ) { | 720 | switch ( action ) { |
716 | case ACTION_ADD: | 721 | case ACTION_ADD: |
717 | addContact_p (contact); | 722 | addContact_p (contact); |
718 | break; | 723 | break; |
719 | case ACTION_REMOVE: | 724 | case ACTION_REMOVE: |
720 | if ( !remove (contact.uid()) ) | 725 | if ( !remove (contact.uid()) ) |
721 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 726 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
722 | contact.uid() ); | 727 | contact.uid() ); |
723 | break; | 728 | break; |
724 | case ACTION_REPLACE: | 729 | case ACTION_REPLACE: |
725 | if ( !replace ( contact ) ) | 730 | if ( !replace ( contact ) ) |
726 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 731 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
727 | contact.uid() ); | 732 | contact.uid() ); |
728 | break; | 733 | break; |
729 | default: | 734 | default: |
730 | qWarning ("Unknown action: ignored !"); | 735 | qWarning ("Unknown action: ignored !"); |
731 | break; | 736 | break; |
732 | } | 737 | } |
733 | }else{ | 738 | }else{ |
734 | /* Add contact to list */ | 739 | /* Add contact to list */ |
735 | addContact_p (contact); | 740 | addContact_p (contact); |
736 | } | 741 | } |
737 | 742 | ||
738 | /* Move to next element */ | 743 | /* Move to next element */ |
739 | element = element->nextChild(); | 744 | element = element->nextChild(); |
740 | } | 745 | } |
741 | }else { | 746 | }else { |
742 | qWarning("ODefBack::could not load"); | 747 | qWarning("ODefBack::could not load"); |
743 | } | 748 | } |
744 | delete root; | 749 | delete root; |
745 | qWarning("returning from loading" ); | 750 | qWarning("returning from loading" ); |
746 | return true; | 751 | return true; |
747 | } | 752 | } |
748 | 753 | ||
749 | 754 | ||
750 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 755 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
751 | journal_action action ) | 756 | journal_action action ) |
752 | { | 757 | { |
753 | QFile f( m_journalName ); | 758 | QFile f( m_journalName ); |
754 | bool created = !f.exists(); | 759 | bool created = !f.exists(); |
755 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 760 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
756 | return; | 761 | return; |
757 | 762 | ||
758 | QString buf; | 763 | QString buf; |
759 | QCString str; | 764 | QCString str; |
760 | 765 | ||
761 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 766 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
762 | // get a XML-File which is readable by our parser. | 767 | // get a XML-File which is readable by our parser. |
763 | // This is just a cheat, but better than rewrite the parser. | 768 | // This is just a cheat, but better than rewrite the parser. |
764 | if ( created ){ | 769 | if ( created ){ |
765 | buf = "<Contacts>"; | 770 | buf = "<Contacts>"; |
766 | QCString cstr = buf.utf8(); | 771 | QCString cstr = buf.utf8(); |
767 | f.writeBlock( cstr.data(), cstr.length() ); | 772 | f.writeBlock( cstr.data(), cstr.length() ); |
768 | } | 773 | } |
769 | 774 | ||
770 | buf = "<Contact "; | 775 | buf = "<Contact "; |
771 | cnt.save( buf ); | 776 | cnt.save( buf ); |
772 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 777 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
773 | buf += "/>\n"; | 778 | buf += "/>\n"; |
774 | QCString cstr = buf.utf8(); | 779 | QCString cstr = buf.utf8(); |
775 | f.writeBlock( cstr.data(), cstr.length() ); | 780 | f.writeBlock( cstr.data(), cstr.length() ); |
776 | } | 781 | } |
777 | 782 | ||
778 | void OContactAccessBackend_XML::removeJournal() | 783 | void OContactAccessBackend_XML::removeJournal() |
779 | { | 784 | { |
780 | QFile f ( m_journalName ); | 785 | QFile f ( m_journalName ); |
781 | if ( f.exists() ) | 786 | if ( f.exists() ) |
782 | f.remove(); | 787 | f.remove(); |
783 | } | 788 | } |
784 | 789 | ||
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index 4d6a7ef..7b5365b 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h | |||
@@ -1,144 +1,154 @@ | |||
1 | /* | 1 | /* |
2 | * XML Backend for the OPIE-Contact Database. | 2 | * XML Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * | 5 | * |
6 | * ===================================================================== | 6 | * ===================================================================== |
7 | *This program is free software; you can redistribute it and/or | 7 | *This program is free software; you can redistribute it and/or |
8 | *modify it under the terms of the GNU Library General Public | 8 | *modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either | 9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. | 10 | * version 2 of the License, or (at your option) any later version. |
11 | * ===================================================================== | 11 | * ===================================================================== |
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.14 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.13 2003/03/21 10:33:09 eilers | 25 | * Revision 1.13 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 28 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 29 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 30 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 31 | * the binaries for today-addressbook. |
27 | * | 32 | * |
28 | * Revision 1.12.2.2 2003/02/11 12:17:28 eilers | 33 | * Revision 1.12.2.2 2003/02/11 12:17:28 eilers |
29 | * Speed optimization. Removed the sequential search loops. | 34 | * Speed optimization. Removed the sequential search loops. |
30 | * | 35 | * |
31 | * Revision 1.12.2.1 2003/02/09 15:05:01 eilers | 36 | * Revision 1.12.2.1 2003/02/09 15:05:01 eilers |
32 | * Nothing happened.. Just some cleanup before I will start.. | 37 | * Nothing happened.. Just some cleanup before I will start.. |
33 | * | 38 | * |
34 | * Revision 1.12 2003/01/03 16:58:03 eilers | 39 | * Revision 1.12 2003/01/03 16:58:03 eilers |
35 | * Reenable debug output | 40 | * Reenable debug output |
36 | * | 41 | * |
37 | * Revision 1.11 2003/01/03 12:31:28 eilers | 42 | * Revision 1.11 2003/01/03 12:31:28 eilers |
38 | * Bugfix for calculating data diffs.. | 43 | * Bugfix for calculating data diffs.. |
39 | * | 44 | * |
40 | * Revision 1.10 2003/01/02 14:27:12 eilers | 45 | * Revision 1.10 2003/01/02 14:27:12 eilers |
41 | * Improved query by example: Search by date is possible.. First step | 46 | * Improved query by example: Search by date is possible.. First step |
42 | * for a today plugin for birthdays.. | 47 | * for a today plugin for birthdays.. |
43 | * | 48 | * |
44 | * Revision 1.9 2002/12/08 12:48:57 eilers | 49 | * Revision 1.9 2002/12/08 12:48:57 eilers |
45 | * Moved journal-enum from ocontact into i the xml-backend.. | 50 | * Moved journal-enum from ocontact into i the xml-backend.. |
46 | * | 51 | * |
47 | * Revision 1.8 2002/11/14 17:04:24 eilers | 52 | * Revision 1.8 2002/11/14 17:04:24 eilers |
48 | * Sorting will now work if fullname is identical on some entries | 53 | * Sorting will now work if fullname is identical on some entries |
49 | * | 54 | * |
50 | * Revision 1.7 2002/11/13 15:02:46 eilers | 55 | * Revision 1.7 2002/11/13 15:02:46 eilers |
51 | * Small Bug in sorted fixed | 56 | * Small Bug in sorted fixed |
52 | * | 57 | * |
53 | * Revision 1.6 2002/11/13 14:14:51 eilers | 58 | * Revision 1.6 2002/11/13 14:14:51 eilers |
54 | * Added sorted for Contacts.. | 59 | * Added sorted for Contacts.. |
55 | * | 60 | * |
56 | * Revision 1.5 2002/11/01 15:10:42 eilers | 61 | * Revision 1.5 2002/11/01 15:10:42 eilers |
57 | * Added regExp-search in database for all fields in a contact. | 62 | * Added regExp-search in database for all fields in a contact. |
58 | * | 63 | * |
59 | * Revision 1.4 2002/10/16 10:52:40 eilers | 64 | * Revision 1.4 2002/10/16 10:52:40 eilers |
60 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 65 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
61 | * | 66 | * |
62 | * Revision 1.3 2002/10/14 16:21:54 eilers | 67 | * Revision 1.3 2002/10/14 16:21:54 eilers |
63 | * Some minor interface updates | 68 | * Some minor interface updates |
64 | * | 69 | * |
65 | * Revision 1.2 2002/10/07 17:34:24 eilers | 70 | * Revision 1.2 2002/10/07 17:34:24 eilers |
66 | * added OBackendFactory for advanced backend access | 71 | * added OBackendFactory for advanced backend access |
67 | * | 72 | * |
68 | * Revision 1.1 2002/09/27 17:11:44 eilers | 73 | * Revision 1.1 2002/09/27 17:11:44 eilers |
69 | * Added API for accessing the Contact-Database ! It is compiling, but | 74 | * Added API for accessing the Contact-Database ! It is compiling, but |
70 | * please do not expect that anything is working ! | 75 | * please do not expect that anything is working ! |
71 | * I will debug that stuff in the next time .. | 76 | * I will debug that stuff in the next time .. |
72 | * Please read README_COMPILE for compiling ! | 77 | * Please read README_COMPILE for compiling ! |
73 | * | 78 | * |
74 | * | 79 | * |
75 | */ | 80 | */ |
76 | 81 | ||
77 | #ifndef _OContactAccessBackend_XML_ | 82 | #ifndef _OContactAccessBackend_XML_ |
78 | #define _OContactAccessBackend_XML_ | 83 | #define _OContactAccessBackend_XML_ |
79 | 84 | ||
80 | #include "ocontactaccessbackend.h" | 85 | #include "ocontactaccessbackend.h" |
81 | #include "ocontactaccess.h" | 86 | #include "ocontactaccess.h" |
82 | 87 | ||
83 | #include <qlist.h> | 88 | #include <qlist.h> |
84 | #include <qdict.h> | 89 | #include <qdict.h> |
85 | 90 | ||
86 | /* the default xml implementation */ | 91 | /* the default xml implementation */ |
92 | /** | ||
93 | * This class is the XML implementation of a Contact backend | ||
94 | * it does implement everything available for OContact. | ||
95 | * @see OPimAccessBackend for more information of available methods | ||
96 | */ | ||
87 | class OContactAccessBackend_XML : public OContactAccessBackend { | 97 | class OContactAccessBackend_XML : public OContactAccessBackend { |
88 | public: | 98 | public: |
89 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ); | 99 | OContactAccessBackend_XML ( const QString& appname, const QString& filename = QString::null ); |
90 | 100 | ||
91 | bool save(); | 101 | bool save(); |
92 | 102 | ||
93 | bool load (); | 103 | bool load (); |
94 | 104 | ||
95 | void clear (); | 105 | void clear (); |
96 | 106 | ||
97 | bool wasChangedExternally(); | 107 | bool wasChangedExternally(); |
98 | 108 | ||
99 | QArray<int> allRecords() const; | 109 | QArray<int> allRecords() const; |
100 | 110 | ||
101 | OContact find ( int uid ) const; | 111 | OContact find ( int uid ) const; |
102 | 112 | ||
103 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); | 113 | QArray<int> queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ); |
104 | 114 | ||
105 | QArray<int> matchRegexp( const QRegExp &r ) const; | 115 | QArray<int> matchRegexp( const QRegExp &r ) const; |
106 | 116 | ||
107 | const uint querySettings(); | 117 | const uint querySettings(); |
108 | 118 | ||
109 | bool hasQuerySettings (uint querySettings) const; | 119 | bool hasQuerySettings (uint querySettings) const; |
110 | 120 | ||
111 | // Currently only asc implemented.. | 121 | // Currently only asc implemented.. |
112 | QArray<int> sorted( bool asc, int , int , int ); | 122 | QArray<int> sorted( bool asc, int , int , int ); |
113 | bool add ( const OContact &newcontact ); | 123 | bool add ( const OContact &newcontact ); |
114 | 124 | ||
115 | bool replace ( const OContact &contact ); | 125 | bool replace ( const OContact &contact ); |
116 | 126 | ||
117 | bool remove ( int uid ); | 127 | bool remove ( int uid ); |
118 | bool reload(); | 128 | bool reload(); |
119 | 129 | ||
120 | private: | 130 | private: |
121 | 131 | ||
122 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 132 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
123 | 133 | ||
124 | void addContact_p( const OContact &newcontact ); | 134 | void addContact_p( const OContact &newcontact ); |
125 | 135 | ||
126 | /* This function loads the xml-database and the journalfile */ | 136 | /* This function loads the xml-database and the journalfile */ |
127 | bool load( const QString filename, bool isJournal ); | 137 | bool load( const QString filename, bool isJournal ); |
128 | 138 | ||
129 | 139 | ||
130 | void updateJournal( const OContact& cnt, journal_action action ); | 140 | void updateJournal( const OContact& cnt, journal_action action ); |
131 | void removeJournal(); | 141 | void removeJournal(); |
132 | 142 | ||
133 | protected: | 143 | protected: |
134 | bool m_changed; | 144 | bool m_changed; |
135 | QString m_journalName; | 145 | QString m_journalName; |
136 | QString m_fileName; | 146 | QString m_fileName; |
137 | QString m_appName; | 147 | QString m_appName; |
138 | QList<OContact> m_contactList; | 148 | QList<OContact> m_contactList; |
139 | QDateTime m_readtime; | 149 | QDateTime m_readtime; |
140 | 150 | ||
141 | QDict<OContact> m_uidToContact; | 151 | QDict<OContact> m_uidToContact; |
142 | }; | 152 | }; |
143 | 153 | ||
144 | #endif | 154 | #endif |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h index eb6e8fb..86ff298 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend.h | |||
@@ -1,32 +1,73 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H | 2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include "opimaccessbackend.h" | 6 | #include "opimaccessbackend.h" |
7 | #include "oevent.h" | 7 | #include "oevent.h" |
8 | 8 | ||
9 | /** | ||
10 | * This class is the interface to the storage of Events. | ||
11 | * @see OPimAccessBackend | ||
12 | * | ||
13 | */ | ||
9 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { | 14 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { |
10 | public: | 15 | public: |
11 | typedef int UID; | 16 | typedef int UID; |
17 | |||
18 | /** | ||
19 | * c'tor without parameter | ||
20 | */ | ||
12 | ODateBookAccessBackend(); | 21 | ODateBookAccessBackend(); |
13 | ~ODateBookAccessBackend(); | 22 | ~ODateBookAccessBackend(); |
14 | 23 | ||
24 | /** | ||
25 | * This method should return a list of UIDs containing | ||
26 | * all events. No filter should be applied | ||
27 | * @return list of events | ||
28 | */ | ||
15 | virtual QArray<UID> rawEvents()const = 0; | 29 | virtual QArray<UID> rawEvents()const = 0; |
30 | |||
31 | /** | ||
32 | * This method should return a list of UIDs containing | ||
33 | * all repeating events. No filter should be applied | ||
34 | * @return list of repeating events | ||
35 | */ | ||
16 | virtual QArray<UID> rawRepeats()const = 0; | 36 | virtual QArray<UID> rawRepeats()const = 0; |
37 | |||
38 | /** | ||
39 | * This mthod should return a list of UIDs containing all non | ||
40 | * repeating events. No filter should be applied | ||
41 | * @return list of nonrepeating events | ||
42 | */ | ||
17 | virtual QArray<UID> nonRepeats() const = 0; | 43 | virtual QArray<UID> nonRepeats() const = 0; |
18 | 44 | ||
19 | /** | 45 | /** |
20 | * these two methods are used if you do not implement | 46 | * If you do not want to implement the effectiveEvents methods below |
21 | * effectiveEvents... | 47 | * you need to supply it with directNonRepeats. |
48 | * This method can return empty lists if effectiveEvents is implememted | ||
22 | */ | 49 | */ |
23 | virtual OEvent::ValueList directNonRepeats() = 0; | 50 | virtual OEvent::ValueList directNonRepeats() = 0; |
51 | |||
52 | /** | ||
53 | * Same as above but return raw repeats! | ||
54 | */ | ||
24 | virtual OEvent::ValueList directRawRepeats() = 0; | 55 | virtual OEvent::ValueList directRawRepeats() = 0; |
25 | 56 | ||
26 | /* is implemented by default but you can reimplement it*/ | 57 | /* is implemented by default but you can reimplement it*/ |
58 | /** | ||
59 | * 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 | ||
61 | * yourself | ||
62 | */ | ||
27 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); | 63 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to ); |
64 | |||
65 | /** | ||
66 | * this is an overloaded member function | ||
67 | * @see effecticeEvents | ||
68 | */ | ||
28 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); | 69 | virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start ); |
29 | 70 | ||
30 | }; | 71 | }; |
31 | 72 | ||
32 | #endif | 73 | #endif |
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h index 563c31f..7848f7c 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.h +++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.h | |||
@@ -1,48 +1,54 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H |
2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H | 2 | #define OPIE_DATE_BOOK_ACCESS_BACKEND_XML__H |
3 | 3 | ||
4 | #include <qmap.h> | 4 | #include <qmap.h> |
5 | 5 | ||
6 | #include "odatebookaccessbackend.h" | 6 | #include "odatebookaccessbackend.h" |
7 | 7 | ||
8 | /** | ||
9 | * This is the default XML implementation for DateBoook XML storage | ||
10 | * It fully implements the interface | ||
11 | * @see ODateBookAccessBackend | ||
12 | * @see OPimAccessBackend | ||
13 | */ | ||
8 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { | 14 | class ODateBookAccessBackend_XML : public ODateBookAccessBackend { |
9 | public: | 15 | public: |
10 | ODateBookAccessBackend_XML( const QString& appName, | 16 | ODateBookAccessBackend_XML( const QString& appName, |
11 | const QString& fileName = QString::null); | 17 | const QString& fileName = QString::null); |
12 | ~ODateBookAccessBackend_XML(); | 18 | ~ODateBookAccessBackend_XML(); |
13 | 19 | ||
14 | bool load(); | 20 | bool load(); |
15 | bool reload(); | 21 | bool reload(); |
16 | bool save(); | 22 | bool save(); |
17 | 23 | ||
18 | QArray<int> allRecords()const; | 24 | QArray<int> allRecords()const; |
19 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); | 25 | QArray<int> queryByExample( const OEvent&, int, const QDateTime& d = QDateTime() ); |
20 | OEvent find( int uid )const; | 26 | OEvent find( int uid )const; |
21 | void clear(); | 27 | void clear(); |
22 | bool add( const OEvent& ev ); | 28 | bool add( const OEvent& ev ); |
23 | bool remove( int uid ); | 29 | bool remove( int uid ); |
24 | bool replace( const OEvent& ev ); | 30 | bool replace( const OEvent& ev ); |
25 | 31 | ||
26 | QArray<UID> rawEvents()const; | 32 | QArray<UID> rawEvents()const; |
27 | QArray<UID> rawRepeats()const; | 33 | QArray<UID> rawRepeats()const; |
28 | QArray<UID> nonRepeats()const; | 34 | QArray<UID> nonRepeats()const; |
29 | 35 | ||
30 | OEvent::ValueList directNonRepeats(); | 36 | OEvent::ValueList directNonRepeats(); |
31 | OEvent::ValueList directRawRepeats(); | 37 | OEvent::ValueList directRawRepeats(); |
32 | 38 | ||
33 | private: | 39 | private: |
34 | bool m_changed :1 ; | 40 | bool m_changed :1 ; |
35 | bool loadFile(); | 41 | bool loadFile(); |
36 | inline void finalizeRecord( OEvent& ev ); | 42 | inline void finalizeRecord( OEvent& ev ); |
37 | inline void setField( OEvent&, int field, const QString& val ); | 43 | inline void setField( OEvent&, int field, const QString& val ); |
38 | QString m_name; | 44 | QString m_name; |
39 | QMap<int, OEvent> m_raw; | 45 | QMap<int, OEvent> m_raw; |
40 | QMap<int, OEvent> m_rep; | 46 | QMap<int, OEvent> m_rep; |
41 | 47 | ||
42 | struct Data; | 48 | struct Data; |
43 | Data* data; | 49 | Data* data; |
44 | class Private; | 50 | class Private; |
45 | Private *d; | 51 | Private *d; |
46 | }; | 52 | }; |
47 | 53 | ||
48 | #endif | 54 | #endif |
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index 32b2dcb..d7ceaf2 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -1,150 +1,160 @@ | |||
1 | /* | 1 | /* |
2 | * Class to manage the Contacts. | 2 | * Class to manage the Contacts. |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | 5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; | 10 | * License as published by the Free Software Foundation; |
11 | * either version 2 of the License, or (at your option) any later | 11 | * either version 2 of the License, or (at your option) any later |
12 | * version. | 12 | * version. |
13 | * ===================================================================== | 13 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 14 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.7 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.6 2003/01/02 14:27:12 eilers | 25 | * Revision 1.6 2003/01/02 14:27:12 eilers |
21 | * Improved query by example: Search by date is possible.. First step | 26 | * Improved query by example: Search by date is possible.. First step |
22 | * for a today plugin for birthdays.. | 27 | * for a today plugin for birthdays.. |
23 | * | 28 | * |
24 | * Revision 1.5 2002/11/13 14:14:51 eilers | 29 | * Revision 1.5 2002/11/13 14:14:51 eilers |
25 | * Added sorted for Contacts.. | 30 | * Added sorted for Contacts.. |
26 | * | 31 | * |
27 | * Revision 1.4 2002/11/01 15:10:42 eilers | 32 | * Revision 1.4 2002/11/01 15:10:42 eilers |
28 | * Added regExp-search in database for all fields in a contact. | 33 | * Added regExp-search in database for all fields in a contact. |
29 | * | 34 | * |
30 | * Revision 1.3 2002/10/16 10:52:40 eilers | 35 | * Revision 1.3 2002/10/16 10:52:40 eilers |
31 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 36 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
32 | * | 37 | * |
33 | * Revision 1.2 2002/10/14 16:21:54 eilers | 38 | * Revision 1.2 2002/10/14 16:21:54 eilers |
34 | * Some minor interface updates | 39 | * Some minor interface updates |
35 | * | 40 | * |
36 | * Revision 1.1 2002/09/27 17:11:44 eilers | 41 | * Revision 1.1 2002/09/27 17:11:44 eilers |
37 | * Added API for accessing the Contact-Database ! It is compiling, but | 42 | * Added API for accessing the Contact-Database ! It is compiling, but |
38 | * please do not expect that anything is working ! | 43 | * please do not expect that anything is working ! |
39 | * I will debug that stuff in the next time .. | 44 | * I will debug that stuff in the next time .. |
40 | * Please read README_COMPILE for compiling ! | 45 | * Please read README_COMPILE for compiling ! |
41 | * | 46 | * |
42 | * ===================================================================== | 47 | * ===================================================================== |
43 | */ | 48 | */ |
44 | #ifndef _OCONTACTACCESS_H | 49 | #ifndef _OCONTACTACCESS_H |
45 | #define _OCONTACTACCESS_H | 50 | #define _OCONTACTACCESS_H |
46 | 51 | ||
47 | #include <qobject.h> | 52 | #include <qobject.h> |
48 | 53 | ||
49 | #include <qpe/qcopenvelope_qws.h> | 54 | #include <qpe/qcopenvelope_qws.h> |
50 | 55 | ||
51 | #include <qvaluelist.h> | 56 | #include <qvaluelist.h> |
52 | #include <qfileinfo.h> | 57 | #include <qfileinfo.h> |
53 | 58 | ||
54 | #include "ocontact.h" | 59 | #include "ocontact.h" |
55 | #include "ocontactaccessbackend.h" | 60 | #include "ocontactaccessbackend.h" |
56 | #include "opimaccesstemplate.h" | 61 | #include "opimaccesstemplate.h" |
57 | 62 | ||
58 | /** Class to access the contacts database. | 63 | /** |
64 | * Class to access the contacts database. | ||
59 | * This is just a frontend for the real database handling which is | 65 | * This is just a frontend for the real database handling which is |
60 | * done by the backend. | 66 | * done by the backend. |
67 | * This class is used to access the Contacts on a system. This class as any OPIE PIM | ||
68 | * class is backend independent. | ||
69 | |||
61 | * @see OPimAccessTemplate | 70 | * @see OPimAccessTemplate |
62 | */ | 71 | */ |
63 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 72 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
64 | { | 73 | { |
65 | Q_OBJECT | 74 | Q_OBJECT |
66 | 75 | ||
67 | public: | 76 | public: |
68 | /** Create Database with contacts (addressbook). | 77 | /** |
78 | * Create Database with contacts (addressbook). | ||
69 | * @param appname Name of application which wants access to the database | 79 | * @param appname Name of application which wants access to the database |
70 | * (i.e. "todolist") | 80 | * (i.e. "todolist") |
71 | * @param filename The name of the database file. If not set, the default one | 81 | * @param filename The name of the database file. If not set, the default one |
72 | * is used. | 82 | * is used. |
73 | * @param backend Pointer to an alternative Backend. If not set, we will use | 83 | * @param backend Pointer to an alternative Backend. If not set, we will use |
74 | * the default backend. | 84 | * the default backend. |
75 | * @param handlesync If <b>true</b> the database stores the current state | 85 | * @param handlesync If <b>true</b> the database stores the current state |
76 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 86 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
77 | * which are used before and after synchronisation. If the application wants | 87 | * which are used before and after synchronisation. If the application wants |
78 | * to react itself, it should be disabled by setting it to <b>false</b> | 88 | * to react itself, it should be disabled by setting it to <b>false</b> |
79 | * @see OContactAccessBackend | 89 | * @see OContactAccessBackend |
80 | */ | 90 | */ |
81 | OContactAccess (const QString appname, const QString filename = 0l, | 91 | OContactAccess (const QString appname, const QString filename = 0l, |
82 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 92 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
83 | ~OContactAccess (); | 93 | ~OContactAccess (); |
84 | 94 | ||
85 | /** Constants for query. | 95 | /** Constants for query. |
86 | * Use this constants to set the query parameters. | 96 | * Use this constants to set the query parameters. |
87 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 97 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
88 | * @see queryByExample() | 98 | * @see queryByExample() |
89 | */ | 99 | */ |
90 | enum QuerySettings { | 100 | enum QuerySettings { |
91 | WildCards = 0x0001, | 101 | WildCards = 0x0001, |
92 | IgnoreCase = 0x0002, | 102 | IgnoreCase = 0x0002, |
93 | RegExp = 0x0004, | 103 | RegExp = 0x0004, |
94 | ExactMatch = 0x0008, | 104 | ExactMatch = 0x0008, |
95 | MatchOne = 0x0010, // Only one Entry must match | 105 | MatchOne = 0x0010, // Only one Entry must match |
96 | DateDiff = 0x0020, // Find all entries from today until given date | 106 | DateDiff = 0x0020, // Find all entries from today until given date |
97 | DateYear = 0x0040, // The year matches | 107 | DateYear = 0x0040, // The year matches |
98 | DateMonth = 0x0080, // The month matches | 108 | DateMonth = 0x0080, // The month matches |
99 | DateDay = 0x0100, // The day matches | 109 | DateDay = 0x0100, // The day matches |
100 | }; | 110 | }; |
101 | 111 | ||
102 | 112 | ||
103 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; | 113 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; |
104 | 114 | ||
105 | /** Return all Contacts in a sorted manner. | 115 | /** Return all Contacts in a sorted manner. |
106 | * @param ascending true: Sorted in acending order. | 116 | * @param ascending true: Sorted in acending order. |
107 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | 117 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess |
108 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | 118 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess |
109 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | 119 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess |
110 | */ | 120 | */ |
111 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | 121 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; |
112 | 122 | ||
113 | /** Return all possible settings. | 123 | /** Return all possible settings. |
114 | * @return All settings provided by the current backend | 124 | * @return All settings provided by the current backend |
115 | * (i.e.: query_WildCards & query_IgnoreCase) | 125 | * (i.e.: query_WildCards & query_IgnoreCase) |
116 | */ | 126 | */ |
117 | const uint querySettings(); | 127 | const uint querySettings(); |
118 | 128 | ||
119 | /** Check whether settings are correct. | 129 | /** Check whether settings are correct. |
120 | * @return <i>true</i> if the given settings are correct and possible. | 130 | * @return <i>true</i> if the given settings are correct and possible. |
121 | */ | 131 | */ |
122 | bool hasQuerySettings ( int querySettings ) const; | 132 | bool hasQuerySettings ( int querySettings ) const; |
123 | 133 | ||
124 | /** | 134 | /** |
125 | * if the resource was changed externally. | 135 | * if the resource was changed externally. |
126 | * You should use the signal instead of polling possible changes ! | 136 | * You should use the signal instead of polling possible changes ! |
127 | */ | 137 | */ |
128 | bool wasChangedExternally()const; | 138 | bool wasChangedExternally()const; |
129 | 139 | ||
130 | 140 | ||
131 | /** Save contacts database. | 141 | /** Save contacts database. |
132 | * Save is more a "commit". After calling this function, all changes are public available. | 142 | * Save is more a "commit". After calling this function, all changes are public available. |
133 | * @return true if successful | 143 | * @return true if successful |
134 | */ | 144 | */ |
135 | bool save(); | 145 | bool save(); |
136 | 146 | ||
137 | signals: | 147 | signals: |
138 | /* Signal is emitted if the database was changed. Therefore | 148 | /* Signal is emitted if the database was changed. Therefore |
139 | * we may need to reload to stay consistent. | 149 | * we may need to reload to stay consistent. |
140 | * @param which Pointer to the database who created this event. This pointer | 150 | * @param which Pointer to the database who created this event. This pointer |
141 | * is useful if an application has to handle multiple databases at the same time. | 151 | * is useful if an application has to handle multiple databases at the same time. |
142 | * @see reload() | 152 | * @see reload() |
143 | */ | 153 | */ |
144 | void signalChanged ( const OContactAccess *which ); | 154 | void signalChanged ( const OContactAccess *which ); |
145 | 155 | ||
146 | 156 | ||
147 | private: | 157 | private: |
148 | // class OContactAccessPrivate; | 158 | // class OContactAccessPrivate; |
149 | // OContactAccessPrivate* d; | 159 | // OContactAccessPrivate* d; |
150 | OContactAccessBackend *m_backEnd; | 160 | OContactAccessBackend *m_backEnd; |
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index 08e61ff..a3661a3 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp | |||
@@ -1,38 +1,66 @@ | |||
1 | #include "obackendfactory.h" | 1 | #include "obackendfactory.h" |
2 | #include "odatebookaccess.h" | 2 | #include "odatebookaccess.h" |
3 | 3 | ||
4 | /** | ||
5 | * Simple constructor | ||
6 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation | ||
7 | * will be used! | ||
8 | * @param back The backend to be used or 0 for the default backend | ||
9 | * @param ac What kind of access is intended | ||
10 | */ | ||
4 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) | 11 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) |
5 | : OPimAccessTemplate<OEvent>( back ) | 12 | : OPimAccessTemplate<OEvent>( back ) |
6 | { | 13 | { |
7 | if (!back ) | 14 | if (!back ) |
8 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); | 15 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); |
9 | 16 | ||
10 | m_backEnd = back; | 17 | m_backEnd = back; |
11 | setBackEnd( m_backEnd ); | 18 | setBackEnd( m_backEnd ); |
12 | } | 19 | } |
13 | ODateBookAccess::~ODateBookAccess() { | 20 | ODateBookAccess::~ODateBookAccess() { |
14 | } | 21 | } |
22 | |||
23 | /** | ||
24 | * @return all events available | ||
25 | */ | ||
15 | ODateBookAccess::List ODateBookAccess::rawEvents()const { | 26 | ODateBookAccess::List ODateBookAccess::rawEvents()const { |
16 | QArray<int> ints = m_backEnd->rawEvents(); | 27 | QArray<int> ints = m_backEnd->rawEvents(); |
17 | 28 | ||
18 | List lis( ints, this ); | 29 | List lis( ints, this ); |
19 | return lis; | 30 | return lis; |
20 | } | 31 | } |
32 | |||
33 | /** | ||
34 | * @return all repeating events | ||
35 | */ | ||
21 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { | 36 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { |
22 | QArray<int> ints = m_backEnd->rawRepeats(); | 37 | QArray<int> ints = m_backEnd->rawRepeats(); |
23 | 38 | ||
24 | List lis( ints, this ); | 39 | List lis( ints, this ); |
25 | return lis; | 40 | return lis; |
26 | } | 41 | } |
42 | |||
43 | /** | ||
44 | * @return all non repeating events | ||
45 | */ | ||
27 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { | 46 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { |
28 | QArray<int> ints = m_backEnd->nonRepeats(); | 47 | QArray<int> ints = m_backEnd->nonRepeats(); |
29 | 48 | ||
30 | List lis( ints, this ); | 49 | List lis( ints, this ); |
31 | return lis; | 50 | return lis; |
32 | } | 51 | } |
52 | |||
53 | /** | ||
54 | * @return dates in the time span between from and to | ||
55 | * @param from Include all events from... | ||
56 | * @param to Include all events to... | ||
57 | */ | ||
33 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) { | 58 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) { |
34 | return m_backEnd->effecticeEvents( from, to ); | 59 | return m_backEnd->effecticeEvents( from, to ); |
35 | } | 60 | } |
61 | /** | ||
62 | * @return all events at a given datetime | ||
63 | */ | ||
36 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) { | 64 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) { |
37 | return m_backEnd->effecticeEvents( start ); | 65 | return m_backEnd->effecticeEvents( start ); |
38 | } | 66 | } |
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h index 7047039..7c7a63f 100644 --- a/libopie2/opiepim/core/odatebookaccess.h +++ b/libopie2/opiepim/core/odatebookaccess.h | |||
@@ -1,32 +1,41 @@ | |||
1 | #ifndef OPIE_DATE_BOOK_ACCESS_H | 1 | #ifndef OPIE_DATE_BOOK_ACCESS_H |
2 | #define OPIE_DATE_BOOK_ACCESS_H | 2 | #define OPIE_DATE_BOOK_ACCESS_H |
3 | 3 | ||
4 | #include "odatebookaccessbackend.h" | 4 | #include "odatebookaccessbackend.h" |
5 | #include "opimaccesstemplate.h" | 5 | #include "opimaccesstemplate.h" |
6 | 6 | ||
7 | #include "oevent.h" | 7 | #include "oevent.h" |
8 | 8 | ||
9 | /** | ||
10 | * This is the object orientated datebook database. It'll use OBackendFactory | ||
11 | * to query for a backend. | ||
12 | * 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 | ||
14 | * destructing and creating the object | ||
15 | * | ||
16 | * @author Holger Freyther | ||
17 | */ | ||
9 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { | 18 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { |
10 | public: | 19 | public: |
11 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); | 20 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); |
12 | ~ODateBookAccess(); | 21 | ~ODateBookAccess(); |
13 | 22 | ||
14 | /** return all events */ | 23 | /* return all events */ |
15 | List rawEvents()const; | 24 | List rawEvents()const; |
16 | 25 | ||
17 | /** return repeating events */ | 26 | /* return repeating events */ |
18 | List rawRepeats()const; | 27 | List rawRepeats()const; |
19 | 28 | ||
20 | /** return non repeating events */ | 29 | /* return non repeating events */ |
21 | List nonRepeats()const; | 30 | List nonRepeats()const; |
22 | 31 | ||
23 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); | 32 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ); |
24 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ); | 33 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ); |
25 | 34 | ||
26 | private: | 35 | private: |
27 | ODateBookAccessBackend* m_backEnd; | 36 | ODateBookAccessBackend* m_backEnd; |
28 | class Private; | 37 | class Private; |
29 | Private* d; | 38 | Private* d; |
30 | }; | 39 | }; |
31 | 40 | ||
32 | #endif | 41 | #endif |
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h index 1fd1c75..25fa0e7 100644 --- a/libopie2/opiepim/ocontact.h +++ b/libopie2/opiepim/ocontact.h | |||
@@ -1,86 +1,93 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of the Qtopia Environment. | 5 | ** This file is part of the Qtopia Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #ifndef __OCONTACT_H__ | 22 | #ifndef __OCONTACT_H__ |
23 | #define __OCONTACT_H__ | 23 | #define __OCONTACT_H__ |
24 | 24 | ||
25 | #include <opie/opimrecord.h> | 25 | #include <opie/opimrecord.h> |
26 | #include <qpe/recordfields.h> | 26 | #include <qpe/recordfields.h> |
27 | 27 | ||
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | 30 | ||
31 | #if defined(QPC_TEMPLATEDLL) | 31 | #if defined(QPC_TEMPLATEDLL) |
32 | // MOC_SKIP_BEGIN | 32 | // MOC_SKIP_BEGIN |
33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; | 33 | QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; |
34 | // MOC_SKIP_END | 34 | // MOC_SKIP_END |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | class ContactPrivate; | 37 | class ContactPrivate; |
38 | 38 | ||
39 | /** | ||
40 | * OContact class represents a specialised PIM Record for contacts. | ||
41 | * It does store all kind of persopn related information. | ||
42 | * | ||
43 | * @short Contact Container | ||
44 | * @author TT, Stefan Eiler, Holger Freyther | ||
45 | */ | ||
39 | class QPC_EXPORT OContact : public OPimRecord | 46 | class QPC_EXPORT OContact : public OPimRecord |
40 | { | 47 | { |
41 | friend class DataSet; | 48 | friend class DataSet; |
42 | public: | 49 | public: |
43 | OContact(); | 50 | OContact(); |
44 | OContact( const QMap<int, QString> &fromMap ); | 51 | OContact( const QMap<int, QString> &fromMap ); |
45 | virtual ~OContact(); | 52 | virtual ~OContact(); |
46 | 53 | ||
47 | /* | 54 | /* |
48 | * do we need to inline them | 55 | * do we need to inline them |
49 | * if yes do we need to inline them this way? | 56 | * if yes do we need to inline them this way? |
50 | * -zecke | 57 | * -zecke |
51 | */ | 58 | */ |
52 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } | 59 | void setTitle( const QString &v ) { replace( Qtopia::Title, v ); } |
53 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } | 60 | void setFirstName( const QString &v ) { replace( Qtopia::FirstName, v ); } |
54 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } | 61 | void setMiddleName( const QString &v ) { replace( Qtopia::MiddleName, v ); } |
55 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } | 62 | void setLastName( const QString &v ) { replace( Qtopia::LastName, v ); } |
56 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } | 63 | void setSuffix( const QString &v ) { replace( Qtopia::Suffix, v ); } |
57 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } | 64 | void setFileAs( const QString &v ) { replace( Qtopia::FileAs, v ); } |
58 | void setFileAs(); | 65 | void setFileAs(); |
59 | 66 | ||
60 | // default email address | 67 | // default email address |
61 | void setDefaultEmail( const QString &v ); | 68 | void setDefaultEmail( const QString &v ); |
62 | // inserts email to list and ensure's doesn't already exist | 69 | // inserts email to list and ensure's doesn't already exist |
63 | void insertEmail( const QString &v ); | 70 | void insertEmail( const QString &v ); |
64 | void removeEmail( const QString &v ); | 71 | void removeEmail( const QString &v ); |
65 | void clearEmails(); | 72 | void clearEmails(); |
66 | void insertEmails( const QStringList &v ); | 73 | void insertEmails( const QStringList &v ); |
67 | 74 | ||
68 | // home | 75 | // home |
69 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } | 76 | void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } |
70 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } | 77 | void setHomeCity( const QString &v ) { replace( Qtopia::HomeCity, v ); } |
71 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } | 78 | void setHomeState( const QString &v ) { replace( Qtopia::HomeState, v ); } |
72 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } | 79 | void setHomeZip( const QString &v ) { replace( Qtopia::HomeZip, v ); } |
73 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } | 80 | void setHomeCountry( const QString &v ) { replace( Qtopia::HomeCountry, v ); } |
74 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } | 81 | void setHomePhone( const QString &v ) { replace( Qtopia::HomePhone, v ); } |
75 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } | 82 | void setHomeFax( const QString &v ) { replace( Qtopia::HomeFax, v ); } |
76 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } | 83 | void setHomeMobile( const QString &v ) { replace( Qtopia::HomeMobile, v ); } |
77 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } | 84 | void setHomeWebpage( const QString &v ) { replace( Qtopia::HomeWebPage, v ); } |
78 | 85 | ||
79 | // business | 86 | // business |
80 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } | 87 | void setCompany( const QString &v ) { replace( Qtopia::Company, v ); } |
81 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } | 88 | void setBusinessStreet( const QString &v ) { replace( Qtopia::BusinessStreet, v ); } |
82 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } | 89 | void setBusinessCity( const QString &v ) { replace( Qtopia::BusinessCity, v ); } |
83 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } | 90 | void setBusinessState( const QString &v ) { replace( Qtopia::BusinessState, v ); } |
84 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } | 91 | void setBusinessZip( const QString &v ) { replace( Qtopia::BusinessZip, v ); } |
85 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } | 92 | void setBusinessCountry( const QString &v ) { replace( Qtopia::BusinessCountry, v ); } |
86 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } | 93 | void setBusinessWebpage( const QString &v ) { replace( Qtopia::BusinessWebPage, v ); } |
diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h index 585515c..57d32d0 100644 --- a/libopie2/opiepim/oevent.h +++ b/libopie2/opiepim/oevent.h | |||
@@ -1,195 +1,210 @@ | |||
1 | // CONTAINS GPLed code of TT | 1 | // CONTAINS GPLed code of TT |
2 | 2 | ||
3 | #ifndef OPIE_PIM_EVENT_H | 3 | #ifndef OPIE_PIM_EVENT_H |
4 | #define OPIE_PIM_EVENT_H | 4 | #define OPIE_PIM_EVENT_H |
5 | 5 | ||
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <qvaluelist.h> | 8 | #include <qvaluelist.h> |
9 | 9 | ||
10 | #include <qpe/recordfields.h> | 10 | #include <qpe/recordfields.h> |
11 | #include <qpe/palmtopuidgen.h> | 11 | #include <qpe/palmtopuidgen.h> |
12 | 12 | ||
13 | #include "otimezone.h" | 13 | #include "otimezone.h" |
14 | #include "opimrecord.h" | 14 | #include "opimrecord.h" |
15 | 15 | ||
16 | struct OCalendarHelper { | 16 | struct OCalendarHelper { |
17 | /** calculate the week number of the date */ | 17 | /** calculate the week number of the date */ |
18 | static int week( const QDate& ); | 18 | static int week( const QDate& ); |
19 | /** calculate the occurence of week days since the start of the month */ | 19 | /** calculate the occurence of week days since the start of the month */ |
20 | static int ocurrence( const QDate& ); | 20 | static int ocurrence( const QDate& ); |
21 | 21 | ||
22 | // returns the dayOfWeek for the *first* day it finds (ignores | 22 | // returns the dayOfWeek for the *first* day it finds (ignores |
23 | // any further days!). Returns 1 (Monday) if there isn't any day found | 23 | // any further days!). Returns 1 (Monday) if there isn't any day found |
24 | static int dayOfWeek( char day ); | 24 | static int dayOfWeek( char day ); |
25 | 25 | ||
26 | /** returns the diff of month */ | 26 | /** returns the diff of month */ |
27 | static int monthDiff( const QDate& first, const QDate& second ); | 27 | static int monthDiff( const QDate& first, const QDate& second ); |
28 | 28 | ||
29 | }; | 29 | }; |
30 | 30 | ||
31 | class OPimNotifyManager; | 31 | class OPimNotifyManager; |
32 | class ORecur; | 32 | class ORecur; |
33 | |||
34 | /** | ||
35 | * This is the container for all Events. It encapsules all | ||
36 | * available information for a single Event | ||
37 | * @short container for events. | ||
38 | */ | ||
33 | class OEvent : public OPimRecord { | 39 | class OEvent : public OPimRecord { |
34 | public: | 40 | public: |
35 | typedef QValueList<OEvent> ValueList; | 41 | typedef QValueList<OEvent> ValueList; |
42 | /** | ||
43 | * RecordFields contain possible attributes | ||
44 | */ | ||
36 | enum RecordFields { | 45 | enum RecordFields { |
37 | Uid = Qtopia::UID_ID, | 46 | Uid = Qtopia::UID_ID, |
38 | Category = Qtopia::CATEGORY_ID, | 47 | Category = Qtopia::CATEGORY_ID, |
39 | Description, | 48 | Description, |
40 | Location, | 49 | Location, |
41 | Alarm, | 50 | Alarm, |
42 | Reminder, | 51 | Reminder, |
43 | Recurrence, | 52 | Recurrence, |
44 | Note, | 53 | Note, |
45 | Created, | 54 | Created, |
46 | StartDate, | 55 | StartDate, |
47 | EndDate, | 56 | EndDate, |
48 | AllDay, | 57 | AllDay, |
49 | TimeZone | 58 | TimeZone |
50 | }; | 59 | }; |
51 | 60 | ||
61 | /** | ||
62 | * Start with an Empty OEvent. UID == 0 means that it is empty | ||
63 | */ | ||
52 | OEvent(int uid = 0); | 64 | OEvent(int uid = 0); |
65 | |||
66 | /** | ||
67 | * copy c'tor | ||
68 | */ | ||
53 | OEvent( const OEvent& ); | 69 | OEvent( const OEvent& ); |
54 | ~OEvent(); | 70 | ~OEvent(); |
55 | OEvent &operator=( const OEvent& ); | 71 | OEvent &operator=( const OEvent& ); |
56 | 72 | ||
57 | QString description()const; | 73 | QString description()const; |
58 | void setDescription( const QString& description ); | 74 | void setDescription( const QString& description ); |
59 | 75 | ||
60 | QString location()const; | 76 | QString location()const; |
61 | void setLocation( const QString& loc ); | 77 | void setLocation( const QString& loc ); |
62 | 78 | ||
63 | bool hasNotifiers()const; | 79 | bool hasNotifiers()const; |
64 | OPimNotifyManager ¬ifiers()const; | 80 | OPimNotifyManager ¬ifiers()const; |
65 | 81 | ||
66 | ORecur recurrence()const; | 82 | ORecur recurrence()const; |
67 | void setRecurrence( const ORecur& ); | 83 | void setRecurrence( const ORecur& ); |
68 | bool hasRecurrence()const; | 84 | bool hasRecurrence()const; |
69 | 85 | ||
70 | QString note()const; | 86 | QString note()const; |
71 | void setNote( const QString& note ); | 87 | void setNote( const QString& note ); |
72 | 88 | ||
73 | 89 | ||
74 | QDateTime createdDateTime()const; | 90 | QDateTime createdDateTime()const; |
75 | void setCreatedDateTime( const QDateTime& dt); | 91 | void setCreatedDateTime( const QDateTime& dt); |
76 | 92 | ||
77 | /** set the date to dt. dt is the QDateTime in localtime */ | 93 | /** set the date to dt. dt is the QDateTime in localtime */ |
78 | void setStartDateTime( const QDateTime& ); | 94 | void setStartDateTime( const QDateTime& ); |
79 | /** returns the datetime in the local timeZone */ | 95 | /** returns the datetime in the local timeZone */ |
80 | QDateTime startDateTime()const; | 96 | QDateTime startDateTime()const; |
81 | 97 | ||
82 | /** returns the start datetime in the current zone */ | 98 | /** returns the start datetime in the current zone */ |
83 | QDateTime startDateTimeInZone()const; | 99 | QDateTime startDateTimeInZone()const; |
84 | 100 | ||
85 | /** in current timezone */ | 101 | /** in current timezone */ |
86 | void setEndDateTime( const QDateTime& ); | 102 | void setEndDateTime( const QDateTime& ); |
87 | /** in current timezone */ | 103 | /** in current timezone */ |
88 | QDateTime endDateTime()const; | 104 | QDateTime endDateTime()const; |
89 | QDateTime endDateTimeInZone()const; | 105 | QDateTime endDateTimeInZone()const; |
90 | 106 | ||
91 | bool isMultipleDay()const; | 107 | bool isMultipleDay()const; |
92 | bool isAllDay()const; | 108 | bool isAllDay()const; |
93 | void setAllDay( bool isAllDay ); | 109 | void setAllDay( bool isAllDay ); |
94 | 110 | ||
95 | /* pin this event to a timezone! FIXME */ | 111 | /* pin this event to a timezone! FIXME */ |
96 | void setTimeZone( const QString& timeZone ); | 112 | void setTimeZone( const QString& timeZone ); |
97 | QString timeZone()const; | 113 | QString timeZone()const; |
98 | 114 | ||
99 | 115 | ||
100 | bool match( const QRegExp& )const; | 116 | bool match( const QRegExp& )const; |
101 | 117 | ||
102 | /** For exception to recurrence here is a list of children... */ | 118 | /** For exception to recurrence here is a list of children... */ |
103 | QArray<int> children()const; | 119 | QArray<int> children()const; |
104 | void setChildren( const QArray<int>& ); | 120 | void setChildren( const QArray<int>& ); |
105 | void addChild( int uid ); | 121 | void addChild( int uid ); |
106 | void removeChild( int uid ); | 122 | void removeChild( int uid ); |
107 | 123 | ||
108 | /** return the parent OEvent */ | 124 | /** return the parent OEvent */ |
109 | int parent()const; | 125 | int parent()const; |
110 | void setParent( int uid ); | 126 | void setParent( int uid ); |
111 | 127 | ||
112 | 128 | ||
113 | /* needed reimp */ | 129 | /* needed reimp */ |
114 | QString toRichText()const; | 130 | QString toRichText()const; |
115 | QString toShortText()const; | 131 | QString toShortText()const; |
116 | QString type()const; | 132 | QString type()const; |
117 | 133 | ||
118 | QMap<int, QString> toMap()const; | 134 | QMap<int, QString> toMap()const; |
119 | QMap<QString, QString> toExtraMap()const; | 135 | QMap<QString, QString> toExtraMap()const; |
120 | QString recordField(int )const; | 136 | QString recordField(int )const; |
121 | 137 | ||
122 | static int rtti(); | 138 | static int rtti(); |
123 | 139 | ||
124 | bool loadFromStream( QDataStream& ); | 140 | bool loadFromStream( QDataStream& ); |
125 | bool saveToStream( QDataStream& )const; | 141 | bool saveToStream( QDataStream& )const; |
126 | 142 | ||
127 | /* bool operator==( const OEvent& ); | 143 | /* bool operator==( const OEvent& ); |
128 | bool operator!=( const OEvent& ); | 144 | bool operator!=( const OEvent& ); |
129 | bool operator<( const OEvent& ); | 145 | bool operator<( const OEvent& ); |
130 | bool operator<=( const OEvent& ); | 146 | bool operator<=( const OEvent& ); |
131 | bool operator>( const OEvent& ); | 147 | bool operator>( const OEvent& ); |
132 | bool operator>=(const OEvent& ); | 148 | bool operator>=(const OEvent& ); |
133 | */ | 149 | */ |
134 | private: | 150 | private: |
135 | inline void changeOrModify(); | 151 | inline void changeOrModify(); |
136 | void deref(); | 152 | void deref(); |
137 | struct Data; | 153 | struct Data; |
138 | Data* data; | 154 | Data* data; |
139 | class Private; | 155 | class Private; |
140 | Private* priv; | 156 | Private* priv; |
141 | 157 | ||
142 | }; | 158 | }; |
143 | 159 | ||
144 | /** | 160 | /** |
145 | * AN Event can span through multiple days. We split up a multiday eve | 161 | * AN Event can span through multiple days. We split up a multiday eve |
146 | */ | 162 | */ |
147 | |||
148 | class OEffectiveEvent { | 163 | class OEffectiveEvent { |
149 | public: | 164 | public: |
150 | typedef QValueList<OEffectiveEvent> ValueList; | 165 | typedef QValueList<OEffectiveEvent> ValueList; |
151 | enum Position { MidWay, Start, End, StartEnd }; | 166 | enum Position { MidWay, Start, End, StartEnd }; |
152 | // If we calculate the effective event of a multi-day event | 167 | // If we calculate the effective event of a multi-day event |
153 | // we have to figure out whether we are at the first day, | 168 | // we have to figure out whether we are at the first day, |
154 | // at the end, or anywhere else ("middle"). This is important | 169 | // at the end, or anywhere else ("middle"). This is important |
155 | // for the start/end times (00:00/23:59) | 170 | // for the start/end times (00:00/23:59) |
156 | // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- | 171 | // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- |
157 | // day event | 172 | // day event |
158 | // Start: start time -> 23:59 | 173 | // Start: start time -> 23:59 |
159 | // End: 00:00 -> end time | 174 | // End: 00:00 -> end time |
160 | // Start | End == StartEnd: for single-day events (default) | 175 | // Start | End == StartEnd: for single-day events (default) |
161 | // here we draw start time -> end time | 176 | // here we draw start time -> end time |
162 | OEffectiveEvent(); | 177 | OEffectiveEvent(); |
163 | OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd ); | 178 | OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd ); |
164 | OEffectiveEvent( const OEffectiveEvent& ); | 179 | OEffectiveEvent( const OEffectiveEvent& ); |
165 | OEffectiveEvent &operator=(const OEffectiveEvent& ); | 180 | OEffectiveEvent &operator=(const OEffectiveEvent& ); |
166 | ~OEffectiveEvent(); | 181 | ~OEffectiveEvent(); |
167 | 182 | ||
168 | void setStartTime( const QTime& ); | 183 | void setStartTime( const QTime& ); |
169 | void setEndTime( const QTime& ); | 184 | void setEndTime( const QTime& ); |
170 | void setEvent( const OEvent& ); | 185 | void setEvent( const OEvent& ); |
171 | void setDate( const QDate& ); | 186 | void setDate( const QDate& ); |
172 | 187 | ||
173 | void setEffectiveDates( const QDate& from, const QDate& to ); | 188 | void setEffectiveDates( const QDate& from, const QDate& to ); |
174 | 189 | ||
175 | QString description()const; | 190 | QString description()const; |
176 | QString location()const; | 191 | QString location()const; |
177 | QString note()const; | 192 | QString note()const; |
178 | OEvent event()const; | 193 | OEvent event()const; |
179 | QTime startTime()const; | 194 | QTime startTime()const; |
180 | QTime endTime()const; | 195 | QTime endTime()const; |
181 | QDate date()const; | 196 | QDate date()const; |
182 | 197 | ||
183 | /* return the length in hours */ | 198 | /* return the length in hours */ |
184 | int length()const; | 199 | int length()const; |
185 | int size()const; | 200 | int size()const; |
186 | 201 | ||
187 | QDate startDate()const; | 202 | QDate startDate()const; |
188 | QDate endDate()const; | 203 | QDate endDate()const; |
189 | 204 | ||
190 | bool operator<( const OEffectiveEvent &e ) const; | 205 | bool operator<( const OEffectiveEvent &e ) const; |
191 | bool operator<=( const OEffectiveEvent &e ) const; | 206 | bool operator<=( const OEffectiveEvent &e ) const; |
192 | bool operator==( const OEffectiveEvent &e ) const; | 207 | bool operator==( const OEffectiveEvent &e ) const; |
193 | bool operator!=( const OEffectiveEvent &e ) const; | 208 | bool operator!=( const OEffectiveEvent &e ) const; |
194 | bool operator>( const OEffectiveEvent &e ) const; | 209 | bool operator>( const OEffectiveEvent &e ) const; |
195 | bool operator>= ( const OEffectiveEvent &e ) const; | 210 | bool operator>= ( const OEffectiveEvent &e ) const; |