author | eilers <eilers> | 2002-11-13 14:14:51 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-11-13 14:14:51 (UTC) |
commit | 2255284b2e80bdc2881ab9106e9afa614a08c140 (patch) (unidiff) | |
tree | 89e53028d842061371e6414ee037f96fa0fbef5e | |
parent | eaecbed44924ece119c5b41db2828b4554f263d2 (diff) | |
download | opie-2255284b2e80bdc2881ab9106e9afa614a08c140.zip opie-2255284b2e80bdc2881ab9106e9afa614a08c140.tar.gz opie-2255284b2e80bdc2881ab9106e9afa614a08c140.tar.bz2 |
Added sorted for Contacts..
-rw-r--r-- | libopie/pim/ocontactaccess.cpp | 8 | ||||
-rw-r--r-- | libopie/pim/ocontactaccess.h | 11 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend.h | 4 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.cpp | 10 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.h | 4 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.h | 32 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 10 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | 4 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.h | 32 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 8 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 11 |
12 files changed, 138 insertions, 0 deletions
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp index f868b53..9c9338e 100644 --- a/libopie/pim/ocontactaccess.cpp +++ b/libopie/pim/ocontactaccess.cpp | |||
@@ -1,71 +1,74 @@ | |||
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 | * | 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 | * Info: This class could just work with a change in the header-file | 12 | * Info: This class could just work with a change in the header-file |
13 | * of the Contact class ! Therefore our libopie only compiles | 13 | * of the Contact class ! Therefore our libopie only compiles |
14 | * with our version of libqpe | 14 | * with our version of libqpe |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: XML-Backend: Automatic reload if something was changed... | 16 | * ToDo: XML-Backend: Automatic reload if something was changed... |
17 | * | 17 | * |
18 | * | 18 | * |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * Version: $Id$ | 20 | * Version: $Id$ |
21 | * ===================================================================== | 21 | * ===================================================================== |
22 | * History: | 22 | * History: |
23 | * $Log$ | 23 | * $Log$ |
24 | * Revision 1.7 2002/11/13 14:14:51 eilers | ||
25 | * Added sorted for Contacts.. | ||
26 | * | ||
24 | * Revision 1.6 2002/11/01 15:10:42 eilers | 27 | * Revision 1.6 2002/11/01 15:10:42 eilers |
25 | * Added regExp-search in database for all fields in a contact. | 28 | * Added regExp-search in database for all fields in a contact. |
26 | * | 29 | * |
27 | * Revision 1.5 2002/10/16 10:52:40 eilers | 30 | * Revision 1.5 2002/10/16 10:52:40 eilers |
28 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 31 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
29 | * | 32 | * |
30 | * Revision 1.4 2002/10/14 16:21:54 eilers | 33 | * Revision 1.4 2002/10/14 16:21:54 eilers |
31 | * Some minor interface updates | 34 | * Some minor interface updates |
32 | * | 35 | * |
33 | * Revision 1.3 2002/10/07 17:34:24 eilers | 36 | * Revision 1.3 2002/10/07 17:34:24 eilers |
34 | * added OBackendFactory for advanced backend access | 37 | * added OBackendFactory for advanced backend access |
35 | * | 38 | * |
36 | * Revision 1.2 2002/10/02 16:18:11 eilers | 39 | * Revision 1.2 2002/10/02 16:18:11 eilers |
37 | * debugged and seems to work almost perfectly .. | 40 | * debugged and seems to work almost perfectly .. |
38 | * | 41 | * |
39 | * Revision 1.1 2002/09/27 17:11:44 eilers | 42 | * Revision 1.1 2002/09/27 17:11:44 eilers |
40 | * Added API for accessing the Contact-Database ! It is compiling, but | 43 | * Added API for accessing the Contact-Database ! It is compiling, but |
41 | * please do not expect that anything is working ! | 44 | * please do not expect that anything is working ! |
42 | * I will debug that stuff in the next time .. | 45 | * I will debug that stuff in the next time .. |
43 | * Please read README_COMPILE for compiling ! | 46 | * Please read README_COMPILE for compiling ! |
44 | * | 47 | * |
45 | * | 48 | * |
46 | */ | 49 | */ |
47 | 50 | ||
48 | #include "ocontactaccess.h" | 51 | #include "ocontactaccess.h" |
49 | #include "obackendfactory.h" | 52 | #include "obackendfactory.h" |
50 | 53 | ||
51 | #include <qasciidict.h> | 54 | #include <qasciidict.h> |
52 | #include <qdatetime.h> | 55 | #include <qdatetime.h> |
53 | #include <qfile.h> | 56 | #include <qfile.h> |
54 | #include <qregexp.h> | 57 | #include <qregexp.h> |
55 | #include <qlist.h> | 58 | #include <qlist.h> |
56 | #include <qcopchannel_qws.h> | 59 | #include <qcopchannel_qws.h> |
57 | 60 | ||
58 | //#include <qpe/qcopenvelope_qws.h> | 61 | //#include <qpe/qcopenvelope_qws.h> |
59 | #include <qpe/global.h> | 62 | #include <qpe/global.h> |
60 | 63 | ||
61 | #include <errno.h> | 64 | #include <errno.h> |
62 | #include <fcntl.h> | 65 | #include <fcntl.h> |
63 | #include <unistd.h> | 66 | #include <unistd.h> |
64 | #include <stdlib.h> | 67 | #include <stdlib.h> |
65 | 68 | ||
66 | #include "ocontactaccessbackend_xml.h" | 69 | #include "ocontactaccessbackend_xml.h" |
67 | 70 | ||
68 | 71 | ||
69 | OContactAccess::OContactAccess ( const QString appname, const QString , | 72 | OContactAccess::OContactAccess ( const QString appname, const QString , |
70 | OContactAccessBackend* end, bool autosync ): | 73 | OContactAccessBackend* end, bool autosync ): |
71 | OPimAccessTemplate<OContact>( end ) | 74 | OPimAccessTemplate<OContact>( end ) |
@@ -92,70 +95,75 @@ OContactAccess::OContactAccess ( const QString appname, const QString , | |||
92 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 95 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
93 | } | 96 | } |
94 | 97 | ||
95 | 98 | ||
96 | } | 99 | } |
97 | OContactAccess::~OContactAccess () | 100 | OContactAccess::~OContactAccess () |
98 | { | 101 | { |
99 | /* The user may forget to save the changed database, therefore try to | 102 | /* The user may forget to save the changed database, therefore try to |
100 | * do it for him.. | 103 | * do it for him.. |
101 | */ | 104 | */ |
102 | save(); | 105 | save(); |
103 | // delete m_backEnd; is done by template.. | 106 | // delete m_backEnd; is done by template.. |
104 | } | 107 | } |
105 | 108 | ||
106 | 109 | ||
107 | bool OContactAccess::save () | 110 | bool OContactAccess::save () |
108 | { | 111 | { |
109 | /* If the database was changed externally, we could not save the | 112 | /* If the database was changed externally, we could not save the |
110 | * Data. This will remove added items which is unacceptable ! | 113 | * Data. This will remove added items which is unacceptable ! |
111 | * Therefore: Reload database and merge the data... | 114 | * Therefore: Reload database and merge the data... |
112 | */ | 115 | */ |
113 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) | 116 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) |
114 | reload(); | 117 | reload(); |
115 | 118 | ||
116 | bool status = OPimAccessTemplate<OContact>::save(); | 119 | bool status = OPimAccessTemplate<OContact>::save(); |
117 | if ( !status ) return false; | 120 | if ( !status ) return false; |
118 | 121 | ||
119 | /* Now tell everyone that new data is available. | 122 | /* Now tell everyone that new data is available. |
120 | */ | 123 | */ |
121 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 124 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
122 | 125 | ||
123 | return true; | 126 | return true; |
124 | } | 127 | } |
125 | 128 | ||
126 | ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{ | 129 | ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{ |
127 | QArray<int> matchingContacts = m_backEnd -> matchRegexp( r ); | 130 | QArray<int> matchingContacts = m_backEnd -> matchRegexp( r ); |
128 | return ( ORecordList<OContact>(matchingContacts, this) ); | 131 | return ( ORecordList<OContact>(matchingContacts, this) ); |
129 | } | 132 | } |
130 | 133 | ||
131 | const uint OContactAccess::querySettings() | 134 | const uint OContactAccess::querySettings() |
132 | { | 135 | { |
133 | return ( m_backEnd->querySettings() ); | 136 | return ( m_backEnd->querySettings() ); |
134 | } | 137 | } |
135 | 138 | ||
136 | bool OContactAccess::hasQuerySettings ( int querySettings ) const | 139 | bool OContactAccess::hasQuerySettings ( int querySettings ) const |
137 | { | 140 | { |
138 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 141 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
139 | } | 142 | } |
143 | ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const | ||
144 | { | ||
145 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); | ||
146 | return ( ORecordList<OContact>(matchingContacts, this) ); | ||
147 | } | ||
140 | 148 | ||
141 | 149 | ||
142 | bool OContactAccess::wasChangedExternally()const | 150 | bool OContactAccess::wasChangedExternally()const |
143 | { | 151 | { |
144 | return ( m_backEnd->wasChangedExternally() ); | 152 | return ( m_backEnd->wasChangedExternally() ); |
145 | } | 153 | } |
146 | 154 | ||
147 | 155 | ||
148 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 156 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
149 | { | 157 | { |
150 | if ( msg == "addressbookUpdated()" ){ | 158 | if ( msg == "addressbookUpdated()" ){ |
151 | qWarning ("OContactAccess: Received addressbokUpdated()"); | 159 | qWarning ("OContactAccess: Received addressbokUpdated()"); |
152 | emit signalChanged ( this ); | 160 | emit signalChanged ( this ); |
153 | } else if ( msg == "flush()" ) { | 161 | } else if ( msg == "flush()" ) { |
154 | qWarning ("OContactAccess: Received flush()"); | 162 | qWarning ("OContactAccess: Received flush()"); |
155 | save (); | 163 | save (); |
156 | } else if ( msg == "reload()" ) { | 164 | } else if ( msg == "reload()" ) { |
157 | qWarning ("OContactAccess: Received reload()"); | 165 | qWarning ("OContactAccess: Received reload()"); |
158 | reload (); | 166 | reload (); |
159 | emit signalChanged ( this ); | 167 | emit signalChanged ( this ); |
160 | } | 168 | } |
161 | } | 169 | } |
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h index b4921d5..961968f 100644 --- a/libopie/pim/ocontactaccess.h +++ b/libopie/pim/ocontactaccess.h | |||
@@ -1,139 +1,150 @@ | |||
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.5 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.4 2002/11/01 15:10:42 eilers | 23 | * Revision 1.4 2002/11/01 15:10:42 eilers |
21 | * Added regExp-search in database for all fields in a contact. | 24 | * Added regExp-search in database for all fields in a contact. |
22 | * | 25 | * |
23 | * Revision 1.3 2002/10/16 10:52:40 eilers | 26 | * Revision 1.3 2002/10/16 10:52:40 eilers |
24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 27 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
25 | * | 28 | * |
26 | * Revision 1.2 2002/10/14 16:21:54 eilers | 29 | * Revision 1.2 2002/10/14 16:21:54 eilers |
27 | * Some minor interface updates | 30 | * Some minor interface updates |
28 | * | 31 | * |
29 | * Revision 1.1 2002/09/27 17:11:44 eilers | 32 | * Revision 1.1 2002/09/27 17:11:44 eilers |
30 | * Added API for accessing the Contact-Database ! It is compiling, but | 33 | * Added API for accessing the Contact-Database ! It is compiling, but |
31 | * please do not expect that anything is working ! | 34 | * please do not expect that anything is working ! |
32 | * I will debug that stuff in the next time .. | 35 | * I will debug that stuff in the next time .. |
33 | * Please read README_COMPILE for compiling ! | 36 | * Please read README_COMPILE for compiling ! |
34 | * | 37 | * |
35 | * ===================================================================== | 38 | * ===================================================================== |
36 | */ | 39 | */ |
37 | #ifndef _OCONTACTACCESS_H | 40 | #ifndef _OCONTACTACCESS_H |
38 | #define _OCONTACTACCESS_H | 41 | #define _OCONTACTACCESS_H |
39 | 42 | ||
40 | #include <qobject.h> | 43 | #include <qobject.h> |
41 | 44 | ||
42 | #include <qpe/qcopenvelope_qws.h> | 45 | #include <qpe/qcopenvelope_qws.h> |
43 | 46 | ||
44 | #include <qvaluelist.h> | 47 | #include <qvaluelist.h> |
45 | #include <qfileinfo.h> | 48 | #include <qfileinfo.h> |
46 | 49 | ||
47 | #include "ocontact.h" | 50 | #include "ocontact.h" |
48 | #include "ocontactaccessbackend.h" | 51 | #include "ocontactaccessbackend.h" |
49 | #include "opimaccesstemplate.h" | 52 | #include "opimaccesstemplate.h" |
50 | 53 | ||
51 | /** Class to access the contacts database. | 54 | /** Class to access the contacts database. |
52 | * This is just a frontend for the real database handling which is | 55 | * This is just a frontend for the real database handling which is |
53 | * done by the backend. | 56 | * done by the backend. |
54 | * @see OPimAccessTemplate | 57 | * @see OPimAccessTemplate |
55 | */ | 58 | */ |
56 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 59 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
57 | { | 60 | { |
58 | Q_OBJECT | 61 | Q_OBJECT |
59 | 62 | ||
60 | public: | 63 | public: |
61 | /** Create Database with contacts (addressbook). | 64 | /** Create Database with contacts (addressbook). |
62 | * @param appname Name of application which wants access to the database | 65 | * @param appname Name of application which wants access to the database |
63 | * (i.e. "todolist") | 66 | * (i.e. "todolist") |
64 | * @param filename The name of the database file. If not set, the default one | 67 | * @param filename The name of the database file. If not set, the default one |
65 | * is used. | 68 | * is used. |
66 | * @param backend Pointer to an alternative Backend. If not set, we will use | 69 | * @param backend Pointer to an alternative Backend. If not set, we will use |
67 | * the default backend. | 70 | * the default backend. |
68 | * @param handlesync If <b>true</b> the database stores the current state | 71 | * @param handlesync If <b>true</b> the database stores the current state |
69 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 72 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
70 | * which are used before and after synchronisation. If the application wants | 73 | * which are used before and after synchronisation. If the application wants |
71 | * to react itself, it should be disabled by setting it to <b>false</b> | 74 | * to react itself, it should be disabled by setting it to <b>false</b> |
72 | * @see OContactAccessBackend | 75 | * @see OContactAccessBackend |
73 | */ | 76 | */ |
74 | OContactAccess (const QString appname, const QString filename = 0l, | 77 | OContactAccess (const QString appname, const QString filename = 0l, |
75 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 78 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
76 | ~OContactAccess (); | 79 | ~OContactAccess (); |
77 | 80 | ||
78 | /** Constants for query. | 81 | /** Constants for query. |
79 | * Use this constants to set the query parameters. | 82 | * Use this constants to set the query parameters. |
80 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 83 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
81 | * @see queryByExample() | 84 | * @see queryByExample() |
82 | */ | 85 | */ |
83 | enum QuerySettings { | 86 | enum QuerySettings { |
84 | WildCards = 0x0001, | 87 | WildCards = 0x0001, |
85 | IgnoreCase = 0x0002, | 88 | IgnoreCase = 0x0002, |
86 | RegExp = 0x0004, | 89 | RegExp = 0x0004, |
87 | ExactMatch = 0x0008, | 90 | ExactMatch = 0x0008, |
88 | MatchOne = 0x0010 // Only one Entry must match | 91 | MatchOne = 0x0010 // Only one Entry must match |
89 | }; | 92 | }; |
90 | 93 | ||
91 | 94 | ||
92 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; | 95 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; |
93 | 96 | ||
97 | /** Return all Contacts in a sorted manner. | ||
98 | * @param ascending true: Sorted in acending order. | ||
99 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | ||
100 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | ||
101 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | ||
102 | */ | ||
103 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | ||
104 | |||
94 | /** Return all possible settings. | 105 | /** Return all possible settings. |
95 | * @return All settings provided by the current backend | 106 | * @return All settings provided by the current backend |
96 | * (i.e.: query_WildCards & query_IgnoreCase) | 107 | * (i.e.: query_WildCards & query_IgnoreCase) |
97 | */ | 108 | */ |
98 | const uint querySettings(); | 109 | const uint querySettings(); |
99 | 110 | ||
100 | /** Check whether settings are correct. | 111 | /** Check whether settings are correct. |
101 | * @return <i>true</i> if the given settings are correct and possible. | 112 | * @return <i>true</i> if the given settings are correct and possible. |
102 | */ | 113 | */ |
103 | bool hasQuerySettings ( int querySettings ) const; | 114 | bool hasQuerySettings ( int querySettings ) const; |
104 | 115 | ||
105 | /** | 116 | /** |
106 | * if the resource was changed externally. | 117 | * if the resource was changed externally. |
107 | * You should use the signal instead of polling possible changes ! | 118 | * You should use the signal instead of polling possible changes ! |
108 | */ | 119 | */ |
109 | bool wasChangedExternally()const; | 120 | bool wasChangedExternally()const; |
110 | 121 | ||
111 | 122 | ||
112 | /** Save contacts database. | 123 | /** Save contacts database. |
113 | * Save is more a "commit". After calling this function, all changes are public available. | 124 | * Save is more a "commit". After calling this function, all changes are public available. |
114 | * @return true if successful | 125 | * @return true if successful |
115 | */ | 126 | */ |
116 | bool save(); | 127 | bool save(); |
117 | 128 | ||
118 | signals: | 129 | signals: |
119 | /* Signal is emitted if the database was changed. Therefore | 130 | /* Signal is emitted if the database was changed. Therefore |
120 | * we may need to reload to stay consistent. | 131 | * we may need to reload to stay consistent. |
121 | * @param which Pointer to the database who created this event. This pointer | 132 | * @param which Pointer to the database who created this event. This pointer |
122 | * is useful if an application has to handle multiple databases at the same time. | 133 | * is useful if an application has to handle multiple databases at the same time. |
123 | * @see reload() | 134 | * @see reload() |
124 | */ | 135 | */ |
125 | void signalChanged ( const OContactAccess *which ); | 136 | void signalChanged ( const OContactAccess *which ); |
126 | 137 | ||
127 | 138 | ||
128 | private: | 139 | private: |
129 | // class OContactAccessPrivate; | 140 | // class OContactAccessPrivate; |
130 | // OContactAccessPrivate* d; | 141 | // OContactAccessPrivate* d; |
131 | OContactAccessBackend *m_backEnd; | 142 | OContactAccessBackend *m_backEnd; |
132 | bool m_loading:1; | 143 | bool m_loading:1; |
133 | 144 | ||
134 | private slots: | 145 | private slots: |
135 | void copMessage( const QCString &msg, const QByteArray &data ); | 146 | void copMessage( const QCString &msg, const QByteArray &data ); |
136 | 147 | ||
137 | 148 | ||
138 | }; | 149 | }; |
139 | #endif | 150 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend.h b/libopie/pim/ocontactaccessbackend.h index c898f61..821f5bf 100644 --- a/libopie/pim/ocontactaccessbackend.h +++ b/libopie/pim/ocontactaccessbackend.h | |||
@@ -1,81 +1,85 @@ | |||
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.4 2002/11/13 14:14:51 eilers | ||
23 | * Added sorted for Contacts.. | ||
24 | * | ||
22 | * Revision 1.3 2002/11/01 15:10:42 eilers | 25 | * Revision 1.3 2002/11/01 15:10:42 eilers |
23 | * Added regExp-search in database for all fields in a contact. | 26 | * Added regExp-search in database for all fields in a contact. |
24 | * | 27 | * |
25 | * Revision 1.2 2002/10/07 17:34:24 eilers | 28 | * Revision 1.2 2002/10/07 17:34:24 eilers |
26 | * added OBackendFactory for advanced backend access | 29 | * added OBackendFactory for advanced backend access |
27 | * | 30 | * |
28 | * Revision 1.1 2002/09/27 17:11:44 eilers | 31 | * Revision 1.1 2002/09/27 17:11:44 eilers |
29 | * Added API for accessing the Contact-Database ! It is compiling, but | 32 | * Added API for accessing the Contact-Database ! It is compiling, but |
30 | * please do not expect that anything is working ! | 33 | * please do not expect that anything is working ! |
31 | * I will debug that stuff in the next time .. | 34 | * I will debug that stuff in the next time .. |
32 | * Please read README_COMPILE for compiling ! | 35 | * Please read README_COMPILE for compiling ! |
33 | * | 36 | * |
34 | * ===================================================================== | 37 | * ===================================================================== |
35 | * | 38 | * |
36 | */ | 39 | */ |
37 | 40 | ||
38 | #ifndef _OCONTACTACCESSBACKEND_H_ | 41 | #ifndef _OCONTACTACCESSBACKEND_H_ |
39 | #define _OCONTACTACCESSBACKEND_H_ | 42 | #define _OCONTACTACCESSBACKEND_H_ |
40 | 43 | ||
41 | #include "ocontact.h" | 44 | #include "ocontact.h" |
42 | #include "opimaccessbackend.h" | 45 | #include "opimaccessbackend.h" |
43 | 46 | ||
44 | #include "qregexp.h" | 47 | #include "qregexp.h" |
45 | 48 | ||
46 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 49 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
47 | public: | 50 | public: |
48 | OContactAccessBackend() {} | 51 | OContactAccessBackend() {} |
49 | virtual ~OContactAccessBackend() {} | 52 | virtual ~OContactAccessBackend() {} |
50 | 53 | ||
51 | 54 | ||
52 | /** Return if database was changed externally. | 55 | /** Return if database was changed externally. |
53 | * This may just make sense on file based databases like a XML-File. | 56 | * This may just make sense on file based databases like a XML-File. |
54 | * It is used to prevent to overwrite the current database content | 57 | * It is used to prevent to overwrite the current database content |
55 | * if the file was already changed by something else ! | 58 | * if the file was already changed by something else ! |
56 | * If this happens, we have to reload before save our data. | 59 | * If this happens, we have to reload before save our data. |
57 | * If we use real databases, this should be handled by the database | 60 | * If we use real databases, this should be handled by the database |
58 | * management system themselve, therefore this function should always return false in | 61 | * management system themselve, therefore this function should always return false in |
59 | * this case. It is not our problem to handle this conflict ... | 62 | * this case. It is not our problem to handle this conflict ... |
60 | * @return <i>true</i> if the database was changed and if save without reload will | 63 | * @return <i>true</i> if the database was changed and if save without reload will |
61 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 64 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
62 | * in this situation. | 65 | * in this situation. |
63 | */ | 66 | */ |
64 | virtual bool wasChangedExternally() = 0; | 67 | virtual bool wasChangedExternally() = 0; |
65 | 68 | ||
66 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 69 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
67 | 70 | ||
68 | /** Return all possible settings. | 71 | /** Return all possible settings. |
69 | * @return All settings provided by the current backend | 72 | * @return All settings provided by the current backend |
70 | * (i.e.: query_WildCards & query_IgnoreCase) | 73 | * (i.e.: query_WildCards & query_IgnoreCase) |
71 | */ | 74 | */ |
72 | virtual const uint querySettings() = 0; | 75 | virtual const uint querySettings() = 0; |
73 | 76 | ||
74 | /** Check whether settings are correct. | 77 | /** Check whether settings are correct. |
75 | * @return <i>true</i> if the given settings are correct and possible. | 78 | * @return <i>true</i> if the given settings are correct and possible. |
76 | */ | 79 | */ |
77 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 80 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
78 | 81 | ||
82 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | ||
79 | 83 | ||
80 | }; | 84 | }; |
81 | #endif | 85 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp index faa72b4..09ae37b 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.cpp +++ b/libopie/pim/ocontactaccessbackend_vcard.cpp | |||
@@ -1,67 +1,70 @@ | |||
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.4 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 23 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
21 | * no default arguments in implementation | 24 | * no default arguments in implementation |
22 | * | 25 | * |
23 | * Revision 1.2 2002/11/10 15:41:53 eilers | 26 | * Revision 1.2 2002/11/10 15:41:53 eilers |
24 | * Bugfixes.. | 27 | * Bugfixes.. |
25 | * | 28 | * |
26 | * Revision 1.1 2002/11/09 14:34:52 eilers | 29 | * Revision 1.1 2002/11/09 14:34:52 eilers |
27 | * Added VCard Backend. | 30 | * Added VCard Backend. |
28 | * | 31 | * |
29 | */ | 32 | */ |
30 | #include "ocontactaccessbackend_vcard.h" | 33 | #include "ocontactaccessbackend_vcard.h" |
31 | #include "../../library/backend/vobject_p.h" | 34 | #include "../../library/backend/vobject_p.h" |
32 | #include "../../library/backend/qfiledirect_p.h" | 35 | #include "../../library/backend/qfiledirect_p.h" |
33 | 36 | ||
34 | #include <qpe/timeconversion.h> | 37 | #include <qpe/timeconversion.h> |
35 | 38 | ||
36 | #include <qfile.h> | 39 | #include <qfile.h> |
37 | 40 | ||
38 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 41 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): |
39 | m_dirty( false ), | 42 | m_dirty( false ), |
40 | m_file( filename ) | 43 | m_file( filename ) |
41 | { | 44 | { |
42 | load(); | 45 | load(); |
43 | } | 46 | } |
44 | 47 | ||
45 | 48 | ||
46 | bool OContactAccessBackend_VCard::load () | 49 | bool OContactAccessBackend_VCard::load () |
47 | { | 50 | { |
48 | m_map.clear(); | 51 | m_map.clear(); |
49 | m_dirty = false; | 52 | m_dirty = false; |
50 | 53 | ||
51 | VObject* obj = 0l; | 54 | VObject* obj = 0l; |
52 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 55 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
53 | if ( !obj ) | 56 | if ( !obj ) |
54 | return false; | 57 | return false; |
55 | 58 | ||
56 | while ( obj ) { | 59 | while ( obj ) { |
57 | OContact con = parseVObject( obj ); | 60 | OContact con = parseVObject( obj ); |
58 | /* | 61 | /* |
59 | * if uid is 0 assign a new one | 62 | * if uid is 0 assign a new one |
60 | * this at least happens on | 63 | * this at least happens on |
61 | * Nokia6210 | 64 | * Nokia6210 |
62 | */ | 65 | */ |
63 | if ( con.uid() == 0 ){ | 66 | if ( con.uid() == 0 ){ |
64 | con.setUid( 1 ); | 67 | con.setUid( 1 ); |
65 | qWarning("assigned new uid %d",con.uid() ); | 68 | qWarning("assigned new uid %d",con.uid() ); |
66 | } | 69 | } |
67 | 70 | ||
@@ -133,96 +136,103 @@ bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | |||
133 | } | 136 | } |
134 | 137 | ||
135 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 138 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
136 | { | 139 | { |
137 | return m_map[uid]; | 140 | return m_map[uid]; |
138 | } | 141 | } |
139 | 142 | ||
140 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 143 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
141 | { | 144 | { |
142 | QArray<int> ar( m_map.count() ); | 145 | QArray<int> ar( m_map.count() ); |
143 | QMap<int, OContact>::ConstIterator it; | 146 | QMap<int, OContact>::ConstIterator it; |
144 | int i = 0; | 147 | int i = 0; |
145 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 148 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
146 | ar[i] = it.key(); | 149 | ar[i] = it.key(); |
147 | i++; | 150 | i++; |
148 | } | 151 | } |
149 | return ar; | 152 | return ar; |
150 | } | 153 | } |
151 | 154 | ||
152 | // Not implemented | 155 | // Not implemented |
153 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) | 156 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) |
154 | { | 157 | { |
155 | QArray<int> ar(0); | 158 | QArray<int> ar(0); |
156 | return ar; | 159 | return ar; |
157 | } | 160 | } |
158 | 161 | ||
159 | // Not implemented | 162 | // Not implemented |
160 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 163 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
161 | { | 164 | { |
162 | QArray<int> ar(0); | 165 | QArray<int> ar(0); |
163 | return ar; | 166 | return ar; |
164 | } | 167 | } |
165 | 168 | ||
166 | const uint OContactAccessBackend_VCard::querySettings() | 169 | const uint OContactAccessBackend_VCard::querySettings() |
167 | { | 170 | { |
168 | return 0; // No search possible | 171 | return 0; // No search possible |
169 | } | 172 | } |
170 | 173 | ||
171 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 174 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const |
172 | { | 175 | { |
173 | return false; // No search possible, therefore all settings invalid ;) | 176 | return false; // No search possible, therefore all settings invalid ;) |
174 | } | 177 | } |
175 | 178 | ||
176 | bool OContactAccessBackend_VCard::wasChangedExternally() | 179 | bool OContactAccessBackend_VCard::wasChangedExternally() |
177 | { | 180 | { |
178 | return false; // Don't expect concurrent access | 181 | return false; // Don't expect concurrent access |
179 | } | 182 | } |
180 | 183 | ||
184 | // Not implemented | ||
185 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | ||
186 | { | ||
187 | QArray<int> ar(0); | ||
188 | return ar; | ||
189 | } | ||
190 | |||
181 | // *** Private stuff *** | 191 | // *** Private stuff *** |
182 | 192 | ||
183 | 193 | ||
184 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 194 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) |
185 | { | 195 | { |
186 | OContact c; | 196 | OContact c; |
187 | 197 | ||
188 | VObjectIterator it; | 198 | VObjectIterator it; |
189 | initPropIterator( &it, obj ); | 199 | initPropIterator( &it, obj ); |
190 | while( moreIteration( &it ) ) { | 200 | while( moreIteration( &it ) ) { |
191 | VObject *o = nextVObject( &it ); | 201 | VObject *o = nextVObject( &it ); |
192 | QCString name = vObjectName( o ); | 202 | QCString name = vObjectName( o ); |
193 | QCString value = vObjectStringZValue( o ); | 203 | QCString value = vObjectStringZValue( o ); |
194 | if ( name == VCNameProp ) { | 204 | if ( name == VCNameProp ) { |
195 | VObjectIterator nit; | 205 | VObjectIterator nit; |
196 | initPropIterator( &nit, o ); | 206 | initPropIterator( &nit, o ); |
197 | while( moreIteration( &nit ) ) { | 207 | while( moreIteration( &nit ) ) { |
198 | VObject *o = nextVObject( &nit ); | 208 | VObject *o = nextVObject( &nit ); |
199 | QCString name = vObjectTypeInfo( o ); | 209 | QCString name = vObjectTypeInfo( o ); |
200 | QString value = vObjectStringZValue( o ); | 210 | QString value = vObjectStringZValue( o ); |
201 | if ( name == VCNamePrefixesProp ) | 211 | if ( name == VCNamePrefixesProp ) |
202 | c.setTitle( value ); | 212 | c.setTitle( value ); |
203 | else if ( name == VCNameSuffixesProp ) | 213 | else if ( name == VCNameSuffixesProp ) |
204 | c.setSuffix( value ); | 214 | c.setSuffix( value ); |
205 | else if ( name == VCFamilyNameProp ) | 215 | else if ( name == VCFamilyNameProp ) |
206 | c.setLastName( value ); | 216 | c.setLastName( value ); |
207 | else if ( name == VCGivenNameProp ) | 217 | else if ( name == VCGivenNameProp ) |
208 | c.setFirstName( value ); | 218 | c.setFirstName( value ); |
209 | else if ( name == VCAdditionalNamesProp ) | 219 | else if ( name == VCAdditionalNamesProp ) |
210 | c.setMiddleName( value ); | 220 | c.setMiddleName( value ); |
211 | } | 221 | } |
212 | } | 222 | } |
213 | else if ( name == VCAdrProp ) { | 223 | else if ( name == VCAdrProp ) { |
214 | bool work = TRUE; // default address is work address | 224 | bool work = TRUE; // default address is work address |
215 | QString street; | 225 | QString street; |
216 | QString city; | 226 | QString city; |
217 | QString region; | 227 | QString region; |
218 | QString postal; | 228 | QString postal; |
219 | QString country; | 229 | QString country; |
220 | 230 | ||
221 | VObjectIterator nit; | 231 | VObjectIterator nit; |
222 | initPropIterator( &nit, o ); | 232 | initPropIterator( &nit, o ); |
223 | while( moreIteration( &nit ) ) { | 233 | while( moreIteration( &nit ) ) { |
224 | VObject *o = nextVObject( &nit ); | 234 | VObject *o = nextVObject( &nit ); |
225 | QCString name = vObjectName( o ); | 235 | QCString name = vObjectName( o ); |
226 | QString value = vObjectStringZValue( o ); | 236 | QString value = vObjectStringZValue( o ); |
227 | if ( name == VCHomeProp ) | 237 | if ( name == VCHomeProp ) |
228 | work = FALSE; | 238 | work = FALSE; |
diff --git a/libopie/pim/ocontactaccessbackend_vcard.h b/libopie/pim/ocontactaccessbackend_vcard.h index 177ec24..4437756 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.h +++ b/libopie/pim/ocontactaccessbackend_vcard.h | |||
@@ -1,70 +1,74 @@ | |||
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.3 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.2 2002/11/10 15:41:53 eilers | 23 | * Revision 1.2 2002/11/10 15:41:53 eilers |
21 | * Bugfixes.. | 24 | * Bugfixes.. |
22 | * | 25 | * |
23 | * Revision 1.1 2002/11/09 14:34:52 eilers | 26 | * Revision 1.1 2002/11/09 14:34:52 eilers |
24 | * Added VCard Backend. | 27 | * Added VCard Backend. |
25 | * | 28 | * |
26 | */ | 29 | */ |
27 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ | 30 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ |
28 | #define __OCONTACTACCESSBACKEND_VCARD_H_ | 31 | #define __OCONTACTACCESSBACKEND_VCARD_H_ |
29 | 32 | ||
30 | #include <opie/ocontact.h> | 33 | #include <opie/ocontact.h> |
31 | 34 | ||
32 | #include "ocontactaccessbackend.h" | 35 | #include "ocontactaccessbackend.h" |
33 | 36 | ||
34 | class VObject; | 37 | class VObject; |
35 | 38 | ||
36 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 39 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
37 | public: | 40 | public: |
38 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); | 41 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); |
39 | 42 | ||
40 | bool load (); | 43 | bool load (); |
41 | bool reload(); | 44 | bool reload(); |
42 | bool save(); | 45 | bool save(); |
43 | void clear (); | 46 | void clear (); |
44 | 47 | ||
45 | bool add ( const OContact& newcontact ); | 48 | bool add ( const OContact& newcontact ); |
46 | bool remove ( int uid ); | 49 | bool remove ( int uid ); |
47 | bool replace ( const OContact& contact ); | 50 | bool replace ( const OContact& contact ); |
48 | 51 | ||
49 | OContact find ( int uid ) const; | 52 | OContact find ( int uid ) const; |
50 | QArray<int> allRecords() const; | 53 | QArray<int> allRecords() const; |
51 | QArray<int> queryByExample ( const OContact &query, int settings ); | 54 | QArray<int> queryByExample ( const OContact &query, int settings ); |
52 | QArray<int> matchRegexp( const QRegExp &r ) const; | 55 | QArray<int> matchRegexp( const QRegExp &r ) const; |
53 | 56 | ||
54 | const uint querySettings(); | 57 | const uint querySettings(); |
55 | bool hasQuerySettings (uint querySettings) const; | 58 | bool hasQuerySettings (uint querySettings) const; |
59 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | ||
56 | bool wasChangedExternally(); | 60 | bool wasChangedExternally(); |
57 | 61 | ||
58 | private: | 62 | private: |
59 | OContact parseVObject( VObject* obj ); | 63 | OContact parseVObject( VObject* obj ); |
60 | VObject* createVObject( const OContact& c ); | 64 | VObject* createVObject( const OContact& c ); |
61 | QDate convVCardDateToDate( const QString& datestr ); | 65 | QDate convVCardDateToDate( const QString& datestr ); |
62 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 66 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
63 | VObject *safeAddProp( VObject* o, const char* prop); | 67 | VObject *safeAddProp( VObject* o, const char* prop); |
64 | 68 | ||
65 | bool m_dirty : 1; | 69 | bool m_dirty : 1; |
66 | QString m_file; | 70 | QString m_file; |
67 | QMap<int, OContact> m_map; | 71 | QMap<int, OContact> m_map; |
68 | }; | 72 | }; |
69 | 73 | ||
70 | #endif | 74 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h index f7e8207..8b95102 100644 --- a/libopie/pim/ocontactaccessbackend_xml.h +++ b/libopie/pim/ocontactaccessbackend_xml.h | |||
@@ -1,97 +1,101 @@ | |||
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.6 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.5 2002/11/01 15:10:42 eilers | 23 | * Revision 1.5 2002/11/01 15:10:42 eilers |
21 | * Added regExp-search in database for all fields in a contact. | 24 | * Added regExp-search in database for all fields in a contact. |
22 | * | 25 | * |
23 | * Revision 1.4 2002/10/16 10:52:40 eilers | 26 | * Revision 1.4 2002/10/16 10:52:40 eilers |
24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 27 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
25 | * | 28 | * |
26 | * Revision 1.3 2002/10/14 16:21:54 eilers | 29 | * Revision 1.3 2002/10/14 16:21:54 eilers |
27 | * Some minor interface updates | 30 | * Some minor interface updates |
28 | * | 31 | * |
29 | * Revision 1.2 2002/10/07 17:34:24 eilers | 32 | * Revision 1.2 2002/10/07 17:34:24 eilers |
30 | * added OBackendFactory for advanced backend access | 33 | * added OBackendFactory for advanced backend access |
31 | * | 34 | * |
32 | * Revision 1.1 2002/09/27 17:11:44 eilers | 35 | * Revision 1.1 2002/09/27 17:11:44 eilers |
33 | * Added API for accessing the Contact-Database ! It is compiling, but | 36 | * Added API for accessing the Contact-Database ! It is compiling, but |
34 | * please do not expect that anything is working ! | 37 | * please do not expect that anything is working ! |
35 | * I will debug that stuff in the next time .. | 38 | * I will debug that stuff in the next time .. |
36 | * Please read README_COMPILE for compiling ! | 39 | * Please read README_COMPILE for compiling ! |
37 | * | 40 | * |
38 | * | 41 | * |
39 | */ | 42 | */ |
40 | 43 | ||
41 | #ifndef _OContactAccessBackend_XML_ | 44 | #ifndef _OContactAccessBackend_XML_ |
42 | #define _OContactAccessBackend_XML_ | 45 | #define _OContactAccessBackend_XML_ |
43 | 46 | ||
44 | #include <qasciidict.h> | 47 | #include <qasciidict.h> |
45 | #include <qdatetime.h> | 48 | #include <qdatetime.h> |
46 | #include <qfile.h> | 49 | #include <qfile.h> |
47 | #include <qfileinfo.h> | 50 | #include <qfileinfo.h> |
48 | #include <qregexp.h> | 51 | #include <qregexp.h> |
49 | #include <qarray.h> | 52 | #include <qarray.h> |
53 | #include <qmap.h> | ||
50 | 54 | ||
51 | #include <qpe/global.h> | 55 | #include <qpe/global.h> |
52 | 56 | ||
53 | #include <opie/xmltree.h> | 57 | #include <opie/xmltree.h> |
54 | #include "ocontactaccessbackend.h" | 58 | #include "ocontactaccessbackend.h" |
55 | #include "ocontactaccess.h" | 59 | #include "ocontactaccess.h" |
56 | 60 | ||
57 | #include <stdlib.h> | 61 | #include <stdlib.h> |
58 | #include <errno.h> | 62 | #include <errno.h> |
59 | 63 | ||
60 | using namespace Opie; | 64 | using namespace Opie; |
61 | 65 | ||
62 | /* the default xml implementation */ | 66 | /* the default xml implementation */ |
63 | class OContactAccessBackend_XML : public OContactAccessBackend { | 67 | class OContactAccessBackend_XML : public OContactAccessBackend { |
64 | public: | 68 | public: |
65 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): | 69 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): |
66 | m_changed( false ) | 70 | m_changed( false ) |
67 | { | 71 | { |
68 | m_appName = appname; | 72 | m_appName = appname; |
69 | 73 | ||
70 | /* Set journalfile name ... */ | 74 | /* Set journalfile name ... */ |
71 | m_journalName = getenv("HOME"); | 75 | m_journalName = getenv("HOME"); |
72 | m_journalName +="/.abjournal" + appname; | 76 | m_journalName +="/.abjournal" + appname; |
73 | 77 | ||
74 | /* Expecting to access the default filename if nothing else is set */ | 78 | /* Expecting to access the default filename if nothing else is set */ |
75 | if ( filename.isEmpty() ){ | 79 | if ( filename.isEmpty() ){ |
76 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 80 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
77 | } else | 81 | } else |
78 | m_fileName = filename; | 82 | m_fileName = filename; |
79 | 83 | ||
80 | /* Load Database now */ | 84 | /* Load Database now */ |
81 | load (); | 85 | load (); |
82 | } | 86 | } |
83 | 87 | ||
84 | bool save() { | 88 | bool save() { |
85 | 89 | ||
86 | if ( !m_changed ) | 90 | if ( !m_changed ) |
87 | return true; | 91 | return true; |
88 | 92 | ||
89 | QString strNewFile = m_fileName + ".new"; | 93 | QString strNewFile = m_fileName + ".new"; |
90 | QFile f( strNewFile ); | 94 | QFile f( strNewFile ); |
91 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 95 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
92 | return false; | 96 | return false; |
93 | 97 | ||
94 | int total_written; | 98 | int total_written; |
95 | QString out; | 99 | QString out; |
96 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 100 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
97 | " <Groups>\n" | 101 | " <Groups>\n" |
@@ -256,96 +260,124 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
256 | m_currentQuery.resize(arraycounter); | 260 | m_currentQuery.resize(arraycounter); |
257 | 261 | ||
258 | return m_currentQuery; | 262 | return m_currentQuery; |
259 | } | 263 | } |
260 | 264 | ||
261 | QArray<int> matchRegexp( const QRegExp &r ) const{ | 265 | QArray<int> matchRegexp( const QRegExp &r ) const{ |
262 | QArray<int> m_currentQuery( m_contactList.count() ); | 266 | QArray<int> m_currentQuery( m_contactList.count() ); |
263 | QValueListConstIterator<OContact> it; | 267 | QValueListConstIterator<OContact> it; |
264 | uint arraycounter = 0; | 268 | uint arraycounter = 0; |
265 | 269 | ||
266 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 270 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
267 | if ( (*it).match( r ) ){ | 271 | if ( (*it).match( r ) ){ |
268 | m_currentQuery[arraycounter++] = (*it).uid(); | 272 | m_currentQuery[arraycounter++] = (*it).uid(); |
269 | } | 273 | } |
270 | 274 | ||
271 | } | 275 | } |
272 | // Shrink to fit.. | 276 | // Shrink to fit.. |
273 | m_currentQuery.resize(arraycounter); | 277 | m_currentQuery.resize(arraycounter); |
274 | 278 | ||
275 | return m_currentQuery; | 279 | return m_currentQuery; |
276 | } | 280 | } |
277 | 281 | ||
278 | const uint querySettings() | 282 | const uint querySettings() |
279 | { | 283 | { |
280 | return ( OContactAccess::WildCards | 284 | return ( OContactAccess::WildCards |
281 | & OContactAccess::IgnoreCase | 285 | & OContactAccess::IgnoreCase |
282 | & OContactAccess::RegExp | 286 | & OContactAccess::RegExp |
283 | & OContactAccess::ExactMatch ); | 287 | & OContactAccess::ExactMatch ); |
284 | } | 288 | } |
285 | 289 | ||
286 | bool hasQuerySettings (uint querySettings) const | 290 | bool hasQuerySettings (uint querySettings) const |
287 | { | 291 | { |
288 | /* OContactAccess::IgnoreCase may be added with one | 292 | /* OContactAccess::IgnoreCase may be added with one |
289 | * of the other settings, but never used alone. | 293 | * of the other settings, but never used alone. |
290 | * The other settings are just valid alone... | 294 | * The other settings are just valid alone... |
291 | */ | 295 | */ |
292 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ | 296 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ |
293 | case OContactAccess::RegExp: | 297 | case OContactAccess::RegExp: |
294 | return ( true ); | 298 | return ( true ); |
295 | case OContactAccess::WildCards: | 299 | case OContactAccess::WildCards: |
296 | return ( true ); | 300 | return ( true ); |
297 | case OContactAccess::ExactMatch: | 301 | case OContactAccess::ExactMatch: |
298 | return ( true ); | 302 | return ( true ); |
299 | default: | 303 | default: |
300 | return ( false ); | 304 | return ( false ); |
301 | } | 305 | } |
302 | } | 306 | } |
303 | 307 | ||
308 | // Currently only asc implemented.. | ||
309 | QArray<int> sorted( bool asc, int , int , int ) | ||
310 | { | ||
311 | QMap<QString, int> nameToUid; | ||
312 | QStringList names; | ||
313 | QArray<int> m_currentQuery( m_contactList.count() ); | ||
314 | |||
315 | // First fill map and StringList with all Names ( better LastNames ? ) | ||
316 | // Afterwards sort namelist and use map to fill array to return.. | ||
317 | QValueListConstIterator<OContact> it; | ||
318 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | ||
319 | names.append( (*it).lastName() ); | ||
320 | nameToUid.insert( (*it).lastName(), (*it).uid() ); | ||
321 | } | ||
322 | names.sort(); | ||
323 | |||
324 | int i = 0; | ||
325 | if ( asc ){ | ||
326 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | ||
327 | m_currentQuery[i++] = nameToUid[ (*it) ]; | ||
328 | }else{ | ||
329 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) | ||
330 | m_currentQuery[i++] = nameToUid[ (*it) ]; | ||
331 | } | ||
332 | |||
333 | return m_currentQuery; | ||
334 | |||
335 | } | ||
304 | bool add ( const OContact &newcontact ) | 336 | bool add ( const OContact &newcontact ) |
305 | { | 337 | { |
306 | //qWarning("odefaultbackend: ACTION::ADD"); | 338 | //qWarning("odefaultbackend: ACTION::ADD"); |
307 | updateJournal (newcontact, OContact::ACTION_ADD); | 339 | updateJournal (newcontact, OContact::ACTION_ADD); |
308 | addContact_p( newcontact ); | 340 | addContact_p( newcontact ); |
309 | 341 | ||
310 | m_changed = true; | 342 | m_changed = true; |
311 | 343 | ||
312 | return true; | 344 | return true; |
313 | } | 345 | } |
314 | 346 | ||
315 | bool replace ( const OContact &contact ) | 347 | bool replace ( const OContact &contact ) |
316 | { | 348 | { |
317 | m_changed = true; | 349 | m_changed = true; |
318 | 350 | ||
319 | bool found = false; | 351 | bool found = false; |
320 | 352 | ||
321 | QValueListIterator<OContact> it; | 353 | QValueListIterator<OContact> it; |
322 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 354 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
323 | if ( (*it).uid() == contact.uid() ){ | 355 | if ( (*it).uid() == contact.uid() ){ |
324 | found = true; | 356 | found = true; |
325 | break; | 357 | break; |
326 | } | 358 | } |
327 | } | 359 | } |
328 | if (found) { | 360 | if (found) { |
329 | updateJournal (contact, OContact::ACTION_REPLACE); | 361 | updateJournal (contact, OContact::ACTION_REPLACE); |
330 | m_contactList.remove (it); | 362 | m_contactList.remove (it); |
331 | m_contactList.append (contact); | 363 | m_contactList.append (contact); |
332 | return true; | 364 | return true; |
333 | } else | 365 | } else |
334 | return false; | 366 | return false; |
335 | } | 367 | } |
336 | 368 | ||
337 | bool remove ( int uid ) | 369 | bool remove ( int uid ) |
338 | { | 370 | { |
339 | m_changed = true; | 371 | m_changed = true; |
340 | 372 | ||
341 | bool found = false; | 373 | bool found = false; |
342 | QValueListIterator<OContact> it; | 374 | QValueListIterator<OContact> it; |
343 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 375 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
344 | if ((*it).uid() == uid){ | 376 | if ((*it).uid() == uid){ |
345 | found = true; | 377 | found = true; |
346 | break; | 378 | break; |
347 | } | 379 | } |
348 | } | 380 | } |
349 | if (found) { | 381 | if (found) { |
350 | updateJournal ( *it, OContact::ACTION_REMOVE); | 382 | updateJournal ( *it, OContact::ACTION_REMOVE); |
351 | m_contactList.remove (it); | 383 | m_contactList.remove (it); |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend.h b/libopie2/opiepim/backend/ocontactaccessbackend.h index c898f61..821f5bf 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend.h | |||
@@ -1,81 +1,85 @@ | |||
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.4 2002/11/13 14:14:51 eilers | ||
23 | * Added sorted for Contacts.. | ||
24 | * | ||
22 | * Revision 1.3 2002/11/01 15:10:42 eilers | 25 | * Revision 1.3 2002/11/01 15:10:42 eilers |
23 | * Added regExp-search in database for all fields in a contact. | 26 | * Added regExp-search in database for all fields in a contact. |
24 | * | 27 | * |
25 | * Revision 1.2 2002/10/07 17:34:24 eilers | 28 | * Revision 1.2 2002/10/07 17:34:24 eilers |
26 | * added OBackendFactory for advanced backend access | 29 | * added OBackendFactory for advanced backend access |
27 | * | 30 | * |
28 | * Revision 1.1 2002/09/27 17:11:44 eilers | 31 | * Revision 1.1 2002/09/27 17:11:44 eilers |
29 | * Added API for accessing the Contact-Database ! It is compiling, but | 32 | * Added API for accessing the Contact-Database ! It is compiling, but |
30 | * please do not expect that anything is working ! | 33 | * please do not expect that anything is working ! |
31 | * I will debug that stuff in the next time .. | 34 | * I will debug that stuff in the next time .. |
32 | * Please read README_COMPILE for compiling ! | 35 | * Please read README_COMPILE for compiling ! |
33 | * | 36 | * |
34 | * ===================================================================== | 37 | * ===================================================================== |
35 | * | 38 | * |
36 | */ | 39 | */ |
37 | 40 | ||
38 | #ifndef _OCONTACTACCESSBACKEND_H_ | 41 | #ifndef _OCONTACTACCESSBACKEND_H_ |
39 | #define _OCONTACTACCESSBACKEND_H_ | 42 | #define _OCONTACTACCESSBACKEND_H_ |
40 | 43 | ||
41 | #include "ocontact.h" | 44 | #include "ocontact.h" |
42 | #include "opimaccessbackend.h" | 45 | #include "opimaccessbackend.h" |
43 | 46 | ||
44 | #include "qregexp.h" | 47 | #include "qregexp.h" |
45 | 48 | ||
46 | class OContactAccessBackend: public OPimAccessBackend<OContact> { | 49 | class OContactAccessBackend: public OPimAccessBackend<OContact> { |
47 | public: | 50 | public: |
48 | OContactAccessBackend() {} | 51 | OContactAccessBackend() {} |
49 | virtual ~OContactAccessBackend() {} | 52 | virtual ~OContactAccessBackend() {} |
50 | 53 | ||
51 | 54 | ||
52 | /** Return if database was changed externally. | 55 | /** Return if database was changed externally. |
53 | * This may just make sense on file based databases like a XML-File. | 56 | * This may just make sense on file based databases like a XML-File. |
54 | * It is used to prevent to overwrite the current database content | 57 | * It is used to prevent to overwrite the current database content |
55 | * if the file was already changed by something else ! | 58 | * if the file was already changed by something else ! |
56 | * If this happens, we have to reload before save our data. | 59 | * If this happens, we have to reload before save our data. |
57 | * If we use real databases, this should be handled by the database | 60 | * If we use real databases, this should be handled by the database |
58 | * management system themselve, therefore this function should always return false in | 61 | * management system themselve, therefore this function should always return false in |
59 | * this case. It is not our problem to handle this conflict ... | 62 | * this case. It is not our problem to handle this conflict ... |
60 | * @return <i>true</i> if the database was changed and if save without reload will | 63 | * @return <i>true</i> if the database was changed and if save without reload will |
61 | * be dangerous. <i>false</i> if the database was not changed or it is save to write | 64 | * be dangerous. <i>false</i> if the database was not changed or it is save to write |
62 | * in this situation. | 65 | * in this situation. |
63 | */ | 66 | */ |
64 | virtual bool wasChangedExternally() = 0; | 67 | virtual bool wasChangedExternally() = 0; |
65 | 68 | ||
66 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; | 69 | virtual QArray<int> matchRegexp( const QRegExp &r ) const = 0; |
67 | 70 | ||
68 | /** Return all possible settings. | 71 | /** Return all possible settings. |
69 | * @return All settings provided by the current backend | 72 | * @return All settings provided by the current backend |
70 | * (i.e.: query_WildCards & query_IgnoreCase) | 73 | * (i.e.: query_WildCards & query_IgnoreCase) |
71 | */ | 74 | */ |
72 | virtual const uint querySettings() = 0; | 75 | virtual const uint querySettings() = 0; |
73 | 76 | ||
74 | /** Check whether settings are correct. | 77 | /** Check whether settings are correct. |
75 | * @return <i>true</i> if the given settings are correct and possible. | 78 | * @return <i>true</i> if the given settings are correct and possible. |
76 | */ | 79 | */ |
77 | virtual bool hasQuerySettings (uint querySettings) const = 0; | 80 | virtual bool hasQuerySettings (uint querySettings) const = 0; |
78 | 81 | ||
82 | virtual QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ) = 0; | ||
79 | 83 | ||
80 | }; | 84 | }; |
81 | #endif | 85 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index faa72b4..09ae37b 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -1,67 +1,70 @@ | |||
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.4 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 23 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
21 | * no default arguments in implementation | 24 | * no default arguments in implementation |
22 | * | 25 | * |
23 | * Revision 1.2 2002/11/10 15:41:53 eilers | 26 | * Revision 1.2 2002/11/10 15:41:53 eilers |
24 | * Bugfixes.. | 27 | * Bugfixes.. |
25 | * | 28 | * |
26 | * Revision 1.1 2002/11/09 14:34:52 eilers | 29 | * Revision 1.1 2002/11/09 14:34:52 eilers |
27 | * Added VCard Backend. | 30 | * Added VCard Backend. |
28 | * | 31 | * |
29 | */ | 32 | */ |
30 | #include "ocontactaccessbackend_vcard.h" | 33 | #include "ocontactaccessbackend_vcard.h" |
31 | #include "../../library/backend/vobject_p.h" | 34 | #include "../../library/backend/vobject_p.h" |
32 | #include "../../library/backend/qfiledirect_p.h" | 35 | #include "../../library/backend/qfiledirect_p.h" |
33 | 36 | ||
34 | #include <qpe/timeconversion.h> | 37 | #include <qpe/timeconversion.h> |
35 | 38 | ||
36 | #include <qfile.h> | 39 | #include <qfile.h> |
37 | 40 | ||
38 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 41 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): |
39 | m_dirty( false ), | 42 | m_dirty( false ), |
40 | m_file( filename ) | 43 | m_file( filename ) |
41 | { | 44 | { |
42 | load(); | 45 | load(); |
43 | } | 46 | } |
44 | 47 | ||
45 | 48 | ||
46 | bool OContactAccessBackend_VCard::load () | 49 | bool OContactAccessBackend_VCard::load () |
47 | { | 50 | { |
48 | m_map.clear(); | 51 | m_map.clear(); |
49 | m_dirty = false; | 52 | m_dirty = false; |
50 | 53 | ||
51 | VObject* obj = 0l; | 54 | VObject* obj = 0l; |
52 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 55 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
53 | if ( !obj ) | 56 | if ( !obj ) |
54 | return false; | 57 | return false; |
55 | 58 | ||
56 | while ( obj ) { | 59 | while ( obj ) { |
57 | OContact con = parseVObject( obj ); | 60 | OContact con = parseVObject( obj ); |
58 | /* | 61 | /* |
59 | * if uid is 0 assign a new one | 62 | * if uid is 0 assign a new one |
60 | * this at least happens on | 63 | * this at least happens on |
61 | * Nokia6210 | 64 | * Nokia6210 |
62 | */ | 65 | */ |
63 | if ( con.uid() == 0 ){ | 66 | if ( con.uid() == 0 ){ |
64 | con.setUid( 1 ); | 67 | con.setUid( 1 ); |
65 | qWarning("assigned new uid %d",con.uid() ); | 68 | qWarning("assigned new uid %d",con.uid() ); |
66 | } | 69 | } |
67 | 70 | ||
@@ -133,96 +136,103 @@ bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | |||
133 | } | 136 | } |
134 | 137 | ||
135 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 138 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
136 | { | 139 | { |
137 | return m_map[uid]; | 140 | return m_map[uid]; |
138 | } | 141 | } |
139 | 142 | ||
140 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 143 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
141 | { | 144 | { |
142 | QArray<int> ar( m_map.count() ); | 145 | QArray<int> ar( m_map.count() ); |
143 | QMap<int, OContact>::ConstIterator it; | 146 | QMap<int, OContact>::ConstIterator it; |
144 | int i = 0; | 147 | int i = 0; |
145 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 148 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
146 | ar[i] = it.key(); | 149 | ar[i] = it.key(); |
147 | i++; | 150 | i++; |
148 | } | 151 | } |
149 | return ar; | 152 | return ar; |
150 | } | 153 | } |
151 | 154 | ||
152 | // Not implemented | 155 | // Not implemented |
153 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) | 156 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) |
154 | { | 157 | { |
155 | QArray<int> ar(0); | 158 | QArray<int> ar(0); |
156 | return ar; | 159 | return ar; |
157 | } | 160 | } |
158 | 161 | ||
159 | // Not implemented | 162 | // Not implemented |
160 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 163 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
161 | { | 164 | { |
162 | QArray<int> ar(0); | 165 | QArray<int> ar(0); |
163 | return ar; | 166 | return ar; |
164 | } | 167 | } |
165 | 168 | ||
166 | const uint OContactAccessBackend_VCard::querySettings() | 169 | const uint OContactAccessBackend_VCard::querySettings() |
167 | { | 170 | { |
168 | return 0; // No search possible | 171 | return 0; // No search possible |
169 | } | 172 | } |
170 | 173 | ||
171 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 174 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const |
172 | { | 175 | { |
173 | return false; // No search possible, therefore all settings invalid ;) | 176 | return false; // No search possible, therefore all settings invalid ;) |
174 | } | 177 | } |
175 | 178 | ||
176 | bool OContactAccessBackend_VCard::wasChangedExternally() | 179 | bool OContactAccessBackend_VCard::wasChangedExternally() |
177 | { | 180 | { |
178 | return false; // Don't expect concurrent access | 181 | return false; // Don't expect concurrent access |
179 | } | 182 | } |
180 | 183 | ||
184 | // Not implemented | ||
185 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | ||
186 | { | ||
187 | QArray<int> ar(0); | ||
188 | return ar; | ||
189 | } | ||
190 | |||
181 | // *** Private stuff *** | 191 | // *** Private stuff *** |
182 | 192 | ||
183 | 193 | ||
184 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 194 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) |
185 | { | 195 | { |
186 | OContact c; | 196 | OContact c; |
187 | 197 | ||
188 | VObjectIterator it; | 198 | VObjectIterator it; |
189 | initPropIterator( &it, obj ); | 199 | initPropIterator( &it, obj ); |
190 | while( moreIteration( &it ) ) { | 200 | while( moreIteration( &it ) ) { |
191 | VObject *o = nextVObject( &it ); | 201 | VObject *o = nextVObject( &it ); |
192 | QCString name = vObjectName( o ); | 202 | QCString name = vObjectName( o ); |
193 | QCString value = vObjectStringZValue( o ); | 203 | QCString value = vObjectStringZValue( o ); |
194 | if ( name == VCNameProp ) { | 204 | if ( name == VCNameProp ) { |
195 | VObjectIterator nit; | 205 | VObjectIterator nit; |
196 | initPropIterator( &nit, o ); | 206 | initPropIterator( &nit, o ); |
197 | while( moreIteration( &nit ) ) { | 207 | while( moreIteration( &nit ) ) { |
198 | VObject *o = nextVObject( &nit ); | 208 | VObject *o = nextVObject( &nit ); |
199 | QCString name = vObjectTypeInfo( o ); | 209 | QCString name = vObjectTypeInfo( o ); |
200 | QString value = vObjectStringZValue( o ); | 210 | QString value = vObjectStringZValue( o ); |
201 | if ( name == VCNamePrefixesProp ) | 211 | if ( name == VCNamePrefixesProp ) |
202 | c.setTitle( value ); | 212 | c.setTitle( value ); |
203 | else if ( name == VCNameSuffixesProp ) | 213 | else if ( name == VCNameSuffixesProp ) |
204 | c.setSuffix( value ); | 214 | c.setSuffix( value ); |
205 | else if ( name == VCFamilyNameProp ) | 215 | else if ( name == VCFamilyNameProp ) |
206 | c.setLastName( value ); | 216 | c.setLastName( value ); |
207 | else if ( name == VCGivenNameProp ) | 217 | else if ( name == VCGivenNameProp ) |
208 | c.setFirstName( value ); | 218 | c.setFirstName( value ); |
209 | else if ( name == VCAdditionalNamesProp ) | 219 | else if ( name == VCAdditionalNamesProp ) |
210 | c.setMiddleName( value ); | 220 | c.setMiddleName( value ); |
211 | } | 221 | } |
212 | } | 222 | } |
213 | else if ( name == VCAdrProp ) { | 223 | else if ( name == VCAdrProp ) { |
214 | bool work = TRUE; // default address is work address | 224 | bool work = TRUE; // default address is work address |
215 | QString street; | 225 | QString street; |
216 | QString city; | 226 | QString city; |
217 | QString region; | 227 | QString region; |
218 | QString postal; | 228 | QString postal; |
219 | QString country; | 229 | QString country; |
220 | 230 | ||
221 | VObjectIterator nit; | 231 | VObjectIterator nit; |
222 | initPropIterator( &nit, o ); | 232 | initPropIterator( &nit, o ); |
223 | while( moreIteration( &nit ) ) { | 233 | while( moreIteration( &nit ) ) { |
224 | VObject *o = nextVObject( &nit ); | 234 | VObject *o = nextVObject( &nit ); |
225 | QCString name = vObjectName( o ); | 235 | QCString name = vObjectName( o ); |
226 | QString value = vObjectStringZValue( o ); | 236 | QString value = vObjectStringZValue( o ); |
227 | if ( name == VCHomeProp ) | 237 | if ( name == VCHomeProp ) |
228 | work = FALSE; | 238 | work = FALSE; |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h index 177ec24..4437756 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | |||
@@ -1,70 +1,74 @@ | |||
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.3 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.2 2002/11/10 15:41:53 eilers | 23 | * Revision 1.2 2002/11/10 15:41:53 eilers |
21 | * Bugfixes.. | 24 | * Bugfixes.. |
22 | * | 25 | * |
23 | * Revision 1.1 2002/11/09 14:34:52 eilers | 26 | * Revision 1.1 2002/11/09 14:34:52 eilers |
24 | * Added VCard Backend. | 27 | * Added VCard Backend. |
25 | * | 28 | * |
26 | */ | 29 | */ |
27 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ | 30 | #ifndef __OCONTACTACCESSBACKEND_VCARD_H_ |
28 | #define __OCONTACTACCESSBACKEND_VCARD_H_ | 31 | #define __OCONTACTACCESSBACKEND_VCARD_H_ |
29 | 32 | ||
30 | #include <opie/ocontact.h> | 33 | #include <opie/ocontact.h> |
31 | 34 | ||
32 | #include "ocontactaccessbackend.h" | 35 | #include "ocontactaccessbackend.h" |
33 | 36 | ||
34 | class VObject; | 37 | class VObject; |
35 | 38 | ||
36 | class OContactAccessBackend_VCard : public OContactAccessBackend { | 39 | class OContactAccessBackend_VCard : public OContactAccessBackend { |
37 | public: | 40 | public: |
38 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); | 41 | OContactAccessBackend_VCard ( QString appname, QString filename = 0l ); |
39 | 42 | ||
40 | bool load (); | 43 | bool load (); |
41 | bool reload(); | 44 | bool reload(); |
42 | bool save(); | 45 | bool save(); |
43 | void clear (); | 46 | void clear (); |
44 | 47 | ||
45 | bool add ( const OContact& newcontact ); | 48 | bool add ( const OContact& newcontact ); |
46 | bool remove ( int uid ); | 49 | bool remove ( int uid ); |
47 | bool replace ( const OContact& contact ); | 50 | bool replace ( const OContact& contact ); |
48 | 51 | ||
49 | OContact find ( int uid ) const; | 52 | OContact find ( int uid ) const; |
50 | QArray<int> allRecords() const; | 53 | QArray<int> allRecords() const; |
51 | QArray<int> queryByExample ( const OContact &query, int settings ); | 54 | QArray<int> queryByExample ( const OContact &query, int settings ); |
52 | QArray<int> matchRegexp( const QRegExp &r ) const; | 55 | QArray<int> matchRegexp( const QRegExp &r ) const; |
53 | 56 | ||
54 | const uint querySettings(); | 57 | const uint querySettings(); |
55 | bool hasQuerySettings (uint querySettings) const; | 58 | bool hasQuerySettings (uint querySettings) const; |
59 | QArray<int> sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | ||
56 | bool wasChangedExternally(); | 60 | bool wasChangedExternally(); |
57 | 61 | ||
58 | private: | 62 | private: |
59 | OContact parseVObject( VObject* obj ); | 63 | OContact parseVObject( VObject* obj ); |
60 | VObject* createVObject( const OContact& c ); | 64 | VObject* createVObject( const OContact& c ); |
61 | QDate convVCardDateToDate( const QString& datestr ); | 65 | QDate convVCardDateToDate( const QString& datestr ); |
62 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 66 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
63 | VObject *safeAddProp( VObject* o, const char* prop); | 67 | VObject *safeAddProp( VObject* o, const char* prop); |
64 | 68 | ||
65 | bool m_dirty : 1; | 69 | bool m_dirty : 1; |
66 | QString m_file; | 70 | QString m_file; |
67 | QMap<int, OContact> m_map; | 71 | QMap<int, OContact> m_map; |
68 | }; | 72 | }; |
69 | 73 | ||
70 | #endif | 74 | #endif |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index f7e8207..8b95102 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h | |||
@@ -1,97 +1,101 @@ | |||
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.6 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.5 2002/11/01 15:10:42 eilers | 23 | * Revision 1.5 2002/11/01 15:10:42 eilers |
21 | * Added regExp-search in database for all fields in a contact. | 24 | * Added regExp-search in database for all fields in a contact. |
22 | * | 25 | * |
23 | * Revision 1.4 2002/10/16 10:52:40 eilers | 26 | * Revision 1.4 2002/10/16 10:52:40 eilers |
24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 27 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
25 | * | 28 | * |
26 | * Revision 1.3 2002/10/14 16:21:54 eilers | 29 | * Revision 1.3 2002/10/14 16:21:54 eilers |
27 | * Some minor interface updates | 30 | * Some minor interface updates |
28 | * | 31 | * |
29 | * Revision 1.2 2002/10/07 17:34:24 eilers | 32 | * Revision 1.2 2002/10/07 17:34:24 eilers |
30 | * added OBackendFactory for advanced backend access | 33 | * added OBackendFactory for advanced backend access |
31 | * | 34 | * |
32 | * Revision 1.1 2002/09/27 17:11:44 eilers | 35 | * Revision 1.1 2002/09/27 17:11:44 eilers |
33 | * Added API for accessing the Contact-Database ! It is compiling, but | 36 | * Added API for accessing the Contact-Database ! It is compiling, but |
34 | * please do not expect that anything is working ! | 37 | * please do not expect that anything is working ! |
35 | * I will debug that stuff in the next time .. | 38 | * I will debug that stuff in the next time .. |
36 | * Please read README_COMPILE for compiling ! | 39 | * Please read README_COMPILE for compiling ! |
37 | * | 40 | * |
38 | * | 41 | * |
39 | */ | 42 | */ |
40 | 43 | ||
41 | #ifndef _OContactAccessBackend_XML_ | 44 | #ifndef _OContactAccessBackend_XML_ |
42 | #define _OContactAccessBackend_XML_ | 45 | #define _OContactAccessBackend_XML_ |
43 | 46 | ||
44 | #include <qasciidict.h> | 47 | #include <qasciidict.h> |
45 | #include <qdatetime.h> | 48 | #include <qdatetime.h> |
46 | #include <qfile.h> | 49 | #include <qfile.h> |
47 | #include <qfileinfo.h> | 50 | #include <qfileinfo.h> |
48 | #include <qregexp.h> | 51 | #include <qregexp.h> |
49 | #include <qarray.h> | 52 | #include <qarray.h> |
53 | #include <qmap.h> | ||
50 | 54 | ||
51 | #include <qpe/global.h> | 55 | #include <qpe/global.h> |
52 | 56 | ||
53 | #include <opie/xmltree.h> | 57 | #include <opie/xmltree.h> |
54 | #include "ocontactaccessbackend.h" | 58 | #include "ocontactaccessbackend.h" |
55 | #include "ocontactaccess.h" | 59 | #include "ocontactaccess.h" |
56 | 60 | ||
57 | #include <stdlib.h> | 61 | #include <stdlib.h> |
58 | #include <errno.h> | 62 | #include <errno.h> |
59 | 63 | ||
60 | using namespace Opie; | 64 | using namespace Opie; |
61 | 65 | ||
62 | /* the default xml implementation */ | 66 | /* the default xml implementation */ |
63 | class OContactAccessBackend_XML : public OContactAccessBackend { | 67 | class OContactAccessBackend_XML : public OContactAccessBackend { |
64 | public: | 68 | public: |
65 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): | 69 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): |
66 | m_changed( false ) | 70 | m_changed( false ) |
67 | { | 71 | { |
68 | m_appName = appname; | 72 | m_appName = appname; |
69 | 73 | ||
70 | /* Set journalfile name ... */ | 74 | /* Set journalfile name ... */ |
71 | m_journalName = getenv("HOME"); | 75 | m_journalName = getenv("HOME"); |
72 | m_journalName +="/.abjournal" + appname; | 76 | m_journalName +="/.abjournal" + appname; |
73 | 77 | ||
74 | /* Expecting to access the default filename if nothing else is set */ | 78 | /* Expecting to access the default filename if nothing else is set */ |
75 | if ( filename.isEmpty() ){ | 79 | if ( filename.isEmpty() ){ |
76 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); | 80 | m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); |
77 | } else | 81 | } else |
78 | m_fileName = filename; | 82 | m_fileName = filename; |
79 | 83 | ||
80 | /* Load Database now */ | 84 | /* Load Database now */ |
81 | load (); | 85 | load (); |
82 | } | 86 | } |
83 | 87 | ||
84 | bool save() { | 88 | bool save() { |
85 | 89 | ||
86 | if ( !m_changed ) | 90 | if ( !m_changed ) |
87 | return true; | 91 | return true; |
88 | 92 | ||
89 | QString strNewFile = m_fileName + ".new"; | 93 | QString strNewFile = m_fileName + ".new"; |
90 | QFile f( strNewFile ); | 94 | QFile f( strNewFile ); |
91 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 95 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
92 | return false; | 96 | return false; |
93 | 97 | ||
94 | int total_written; | 98 | int total_written; |
95 | QString out; | 99 | QString out; |
96 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 100 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
97 | " <Groups>\n" | 101 | " <Groups>\n" |
@@ -256,96 +260,124 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
256 | m_currentQuery.resize(arraycounter); | 260 | m_currentQuery.resize(arraycounter); |
257 | 261 | ||
258 | return m_currentQuery; | 262 | return m_currentQuery; |
259 | } | 263 | } |
260 | 264 | ||
261 | QArray<int> matchRegexp( const QRegExp &r ) const{ | 265 | QArray<int> matchRegexp( const QRegExp &r ) const{ |
262 | QArray<int> m_currentQuery( m_contactList.count() ); | 266 | QArray<int> m_currentQuery( m_contactList.count() ); |
263 | QValueListConstIterator<OContact> it; | 267 | QValueListConstIterator<OContact> it; |
264 | uint arraycounter = 0; | 268 | uint arraycounter = 0; |
265 | 269 | ||
266 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 270 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
267 | if ( (*it).match( r ) ){ | 271 | if ( (*it).match( r ) ){ |
268 | m_currentQuery[arraycounter++] = (*it).uid(); | 272 | m_currentQuery[arraycounter++] = (*it).uid(); |
269 | } | 273 | } |
270 | 274 | ||
271 | } | 275 | } |
272 | // Shrink to fit.. | 276 | // Shrink to fit.. |
273 | m_currentQuery.resize(arraycounter); | 277 | m_currentQuery.resize(arraycounter); |
274 | 278 | ||
275 | return m_currentQuery; | 279 | return m_currentQuery; |
276 | } | 280 | } |
277 | 281 | ||
278 | const uint querySettings() | 282 | const uint querySettings() |
279 | { | 283 | { |
280 | return ( OContactAccess::WildCards | 284 | return ( OContactAccess::WildCards |
281 | & OContactAccess::IgnoreCase | 285 | & OContactAccess::IgnoreCase |
282 | & OContactAccess::RegExp | 286 | & OContactAccess::RegExp |
283 | & OContactAccess::ExactMatch ); | 287 | & OContactAccess::ExactMatch ); |
284 | } | 288 | } |
285 | 289 | ||
286 | bool hasQuerySettings (uint querySettings) const | 290 | bool hasQuerySettings (uint querySettings) const |
287 | { | 291 | { |
288 | /* OContactAccess::IgnoreCase may be added with one | 292 | /* OContactAccess::IgnoreCase may be added with one |
289 | * of the other settings, but never used alone. | 293 | * of the other settings, but never used alone. |
290 | * The other settings are just valid alone... | 294 | * The other settings are just valid alone... |
291 | */ | 295 | */ |
292 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ | 296 | switch ( querySettings & ~OContactAccess::IgnoreCase ){ |
293 | case OContactAccess::RegExp: | 297 | case OContactAccess::RegExp: |
294 | return ( true ); | 298 | return ( true ); |
295 | case OContactAccess::WildCards: | 299 | case OContactAccess::WildCards: |
296 | return ( true ); | 300 | return ( true ); |
297 | case OContactAccess::ExactMatch: | 301 | case OContactAccess::ExactMatch: |
298 | return ( true ); | 302 | return ( true ); |
299 | default: | 303 | default: |
300 | return ( false ); | 304 | return ( false ); |
301 | } | 305 | } |
302 | } | 306 | } |
303 | 307 | ||
308 | // Currently only asc implemented.. | ||
309 | QArray<int> sorted( bool asc, int , int , int ) | ||
310 | { | ||
311 | QMap<QString, int> nameToUid; | ||
312 | QStringList names; | ||
313 | QArray<int> m_currentQuery( m_contactList.count() ); | ||
314 | |||
315 | // First fill map and StringList with all Names ( better LastNames ? ) | ||
316 | // Afterwards sort namelist and use map to fill array to return.. | ||
317 | QValueListConstIterator<OContact> it; | ||
318 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | ||
319 | names.append( (*it).lastName() ); | ||
320 | nameToUid.insert( (*it).lastName(), (*it).uid() ); | ||
321 | } | ||
322 | names.sort(); | ||
323 | |||
324 | int i = 0; | ||
325 | if ( asc ){ | ||
326 | for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) | ||
327 | m_currentQuery[i++] = nameToUid[ (*it) ]; | ||
328 | }else{ | ||
329 | for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) | ||
330 | m_currentQuery[i++] = nameToUid[ (*it) ]; | ||
331 | } | ||
332 | |||
333 | return m_currentQuery; | ||
334 | |||
335 | } | ||
304 | bool add ( const OContact &newcontact ) | 336 | bool add ( const OContact &newcontact ) |
305 | { | 337 | { |
306 | //qWarning("odefaultbackend: ACTION::ADD"); | 338 | //qWarning("odefaultbackend: ACTION::ADD"); |
307 | updateJournal (newcontact, OContact::ACTION_ADD); | 339 | updateJournal (newcontact, OContact::ACTION_ADD); |
308 | addContact_p( newcontact ); | 340 | addContact_p( newcontact ); |
309 | 341 | ||
310 | m_changed = true; | 342 | m_changed = true; |
311 | 343 | ||
312 | return true; | 344 | return true; |
313 | } | 345 | } |
314 | 346 | ||
315 | bool replace ( const OContact &contact ) | 347 | bool replace ( const OContact &contact ) |
316 | { | 348 | { |
317 | m_changed = true; | 349 | m_changed = true; |
318 | 350 | ||
319 | bool found = false; | 351 | bool found = false; |
320 | 352 | ||
321 | QValueListIterator<OContact> it; | 353 | QValueListIterator<OContact> it; |
322 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 354 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
323 | if ( (*it).uid() == contact.uid() ){ | 355 | if ( (*it).uid() == contact.uid() ){ |
324 | found = true; | 356 | found = true; |
325 | break; | 357 | break; |
326 | } | 358 | } |
327 | } | 359 | } |
328 | if (found) { | 360 | if (found) { |
329 | updateJournal (contact, OContact::ACTION_REPLACE); | 361 | updateJournal (contact, OContact::ACTION_REPLACE); |
330 | m_contactList.remove (it); | 362 | m_contactList.remove (it); |
331 | m_contactList.append (contact); | 363 | m_contactList.append (contact); |
332 | return true; | 364 | return true; |
333 | } else | 365 | } else |
334 | return false; | 366 | return false; |
335 | } | 367 | } |
336 | 368 | ||
337 | bool remove ( int uid ) | 369 | bool remove ( int uid ) |
338 | { | 370 | { |
339 | m_changed = true; | 371 | m_changed = true; |
340 | 372 | ||
341 | bool found = false; | 373 | bool found = false; |
342 | QValueListIterator<OContact> it; | 374 | QValueListIterator<OContact> it; |
343 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 375 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
344 | if ((*it).uid() == uid){ | 376 | if ((*it).uid() == uid){ |
345 | found = true; | 377 | found = true; |
346 | break; | 378 | break; |
347 | } | 379 | } |
348 | } | 380 | } |
349 | if (found) { | 381 | if (found) { |
350 | updateJournal ( *it, OContact::ACTION_REMOVE); | 382 | updateJournal ( *it, OContact::ACTION_REMOVE); |
351 | m_contactList.remove (it); | 383 | m_contactList.remove (it); |
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index f868b53..9c9338e 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp | |||
@@ -1,71 +1,74 @@ | |||
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 | * | 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 | * Info: This class could just work with a change in the header-file | 12 | * Info: This class could just work with a change in the header-file |
13 | * of the Contact class ! Therefore our libopie only compiles | 13 | * of the Contact class ! Therefore our libopie only compiles |
14 | * with our version of libqpe | 14 | * with our version of libqpe |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * ToDo: XML-Backend: Automatic reload if something was changed... | 16 | * ToDo: XML-Backend: Automatic reload if something was changed... |
17 | * | 17 | * |
18 | * | 18 | * |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * Version: $Id$ | 20 | * Version: $Id$ |
21 | * ===================================================================== | 21 | * ===================================================================== |
22 | * History: | 22 | * History: |
23 | * $Log$ | 23 | * $Log$ |
24 | * Revision 1.7 2002/11/13 14:14:51 eilers | ||
25 | * Added sorted for Contacts.. | ||
26 | * | ||
24 | * Revision 1.6 2002/11/01 15:10:42 eilers | 27 | * Revision 1.6 2002/11/01 15:10:42 eilers |
25 | * Added regExp-search in database for all fields in a contact. | 28 | * Added regExp-search in database for all fields in a contact. |
26 | * | 29 | * |
27 | * Revision 1.5 2002/10/16 10:52:40 eilers | 30 | * Revision 1.5 2002/10/16 10:52:40 eilers |
28 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 31 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
29 | * | 32 | * |
30 | * Revision 1.4 2002/10/14 16:21:54 eilers | 33 | * Revision 1.4 2002/10/14 16:21:54 eilers |
31 | * Some minor interface updates | 34 | * Some minor interface updates |
32 | * | 35 | * |
33 | * Revision 1.3 2002/10/07 17:34:24 eilers | 36 | * Revision 1.3 2002/10/07 17:34:24 eilers |
34 | * added OBackendFactory for advanced backend access | 37 | * added OBackendFactory for advanced backend access |
35 | * | 38 | * |
36 | * Revision 1.2 2002/10/02 16:18:11 eilers | 39 | * Revision 1.2 2002/10/02 16:18:11 eilers |
37 | * debugged and seems to work almost perfectly .. | 40 | * debugged and seems to work almost perfectly .. |
38 | * | 41 | * |
39 | * Revision 1.1 2002/09/27 17:11:44 eilers | 42 | * Revision 1.1 2002/09/27 17:11:44 eilers |
40 | * Added API for accessing the Contact-Database ! It is compiling, but | 43 | * Added API for accessing the Contact-Database ! It is compiling, but |
41 | * please do not expect that anything is working ! | 44 | * please do not expect that anything is working ! |
42 | * I will debug that stuff in the next time .. | 45 | * I will debug that stuff in the next time .. |
43 | * Please read README_COMPILE for compiling ! | 46 | * Please read README_COMPILE for compiling ! |
44 | * | 47 | * |
45 | * | 48 | * |
46 | */ | 49 | */ |
47 | 50 | ||
48 | #include "ocontactaccess.h" | 51 | #include "ocontactaccess.h" |
49 | #include "obackendfactory.h" | 52 | #include "obackendfactory.h" |
50 | 53 | ||
51 | #include <qasciidict.h> | 54 | #include <qasciidict.h> |
52 | #include <qdatetime.h> | 55 | #include <qdatetime.h> |
53 | #include <qfile.h> | 56 | #include <qfile.h> |
54 | #include <qregexp.h> | 57 | #include <qregexp.h> |
55 | #include <qlist.h> | 58 | #include <qlist.h> |
56 | #include <qcopchannel_qws.h> | 59 | #include <qcopchannel_qws.h> |
57 | 60 | ||
58 | //#include <qpe/qcopenvelope_qws.h> | 61 | //#include <qpe/qcopenvelope_qws.h> |
59 | #include <qpe/global.h> | 62 | #include <qpe/global.h> |
60 | 63 | ||
61 | #include <errno.h> | 64 | #include <errno.h> |
62 | #include <fcntl.h> | 65 | #include <fcntl.h> |
63 | #include <unistd.h> | 66 | #include <unistd.h> |
64 | #include <stdlib.h> | 67 | #include <stdlib.h> |
65 | 68 | ||
66 | #include "ocontactaccessbackend_xml.h" | 69 | #include "ocontactaccessbackend_xml.h" |
67 | 70 | ||
68 | 71 | ||
69 | OContactAccess::OContactAccess ( const QString appname, const QString , | 72 | OContactAccess::OContactAccess ( const QString appname, const QString , |
70 | OContactAccessBackend* end, bool autosync ): | 73 | OContactAccessBackend* end, bool autosync ): |
71 | OPimAccessTemplate<OContact>( end ) | 74 | OPimAccessTemplate<OContact>( end ) |
@@ -92,70 +95,75 @@ OContactAccess::OContactAccess ( const QString appname, const QString , | |||
92 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); | 95 | this, SLOT(copMessage( const QCString &, const QByteArray &)) ); |
93 | } | 96 | } |
94 | 97 | ||
95 | 98 | ||
96 | } | 99 | } |
97 | OContactAccess::~OContactAccess () | 100 | OContactAccess::~OContactAccess () |
98 | { | 101 | { |
99 | /* The user may forget to save the changed database, therefore try to | 102 | /* The user may forget to save the changed database, therefore try to |
100 | * do it for him.. | 103 | * do it for him.. |
101 | */ | 104 | */ |
102 | save(); | 105 | save(); |
103 | // delete m_backEnd; is done by template.. | 106 | // delete m_backEnd; is done by template.. |
104 | } | 107 | } |
105 | 108 | ||
106 | 109 | ||
107 | bool OContactAccess::save () | 110 | bool OContactAccess::save () |
108 | { | 111 | { |
109 | /* If the database was changed externally, we could not save the | 112 | /* If the database was changed externally, we could not save the |
110 | * Data. This will remove added items which is unacceptable ! | 113 | * Data. This will remove added items which is unacceptable ! |
111 | * Therefore: Reload database and merge the data... | 114 | * Therefore: Reload database and merge the data... |
112 | */ | 115 | */ |
113 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) | 116 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) |
114 | reload(); | 117 | reload(); |
115 | 118 | ||
116 | bool status = OPimAccessTemplate<OContact>::save(); | 119 | bool status = OPimAccessTemplate<OContact>::save(); |
117 | if ( !status ) return false; | 120 | if ( !status ) return false; |
118 | 121 | ||
119 | /* Now tell everyone that new data is available. | 122 | /* Now tell everyone that new data is available. |
120 | */ | 123 | */ |
121 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 124 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
122 | 125 | ||
123 | return true; | 126 | return true; |
124 | } | 127 | } |
125 | 128 | ||
126 | ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{ | 129 | ORecordList<OContact> OContactAccess::matchRegexp( const QRegExp &r ) const{ |
127 | QArray<int> matchingContacts = m_backEnd -> matchRegexp( r ); | 130 | QArray<int> matchingContacts = m_backEnd -> matchRegexp( r ); |
128 | return ( ORecordList<OContact>(matchingContacts, this) ); | 131 | return ( ORecordList<OContact>(matchingContacts, this) ); |
129 | } | 132 | } |
130 | 133 | ||
131 | const uint OContactAccess::querySettings() | 134 | const uint OContactAccess::querySettings() |
132 | { | 135 | { |
133 | return ( m_backEnd->querySettings() ); | 136 | return ( m_backEnd->querySettings() ); |
134 | } | 137 | } |
135 | 138 | ||
136 | bool OContactAccess::hasQuerySettings ( int querySettings ) const | 139 | bool OContactAccess::hasQuerySettings ( int querySettings ) const |
137 | { | 140 | { |
138 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 141 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
139 | } | 142 | } |
143 | ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const | ||
144 | { | ||
145 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); | ||
146 | return ( ORecordList<OContact>(matchingContacts, this) ); | ||
147 | } | ||
140 | 148 | ||
141 | 149 | ||
142 | bool OContactAccess::wasChangedExternally()const | 150 | bool OContactAccess::wasChangedExternally()const |
143 | { | 151 | { |
144 | return ( m_backEnd->wasChangedExternally() ); | 152 | return ( m_backEnd->wasChangedExternally() ); |
145 | } | 153 | } |
146 | 154 | ||
147 | 155 | ||
148 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 156 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
149 | { | 157 | { |
150 | if ( msg == "addressbookUpdated()" ){ | 158 | if ( msg == "addressbookUpdated()" ){ |
151 | qWarning ("OContactAccess: Received addressbokUpdated()"); | 159 | qWarning ("OContactAccess: Received addressbokUpdated()"); |
152 | emit signalChanged ( this ); | 160 | emit signalChanged ( this ); |
153 | } else if ( msg == "flush()" ) { | 161 | } else if ( msg == "flush()" ) { |
154 | qWarning ("OContactAccess: Received flush()"); | 162 | qWarning ("OContactAccess: Received flush()"); |
155 | save (); | 163 | save (); |
156 | } else if ( msg == "reload()" ) { | 164 | } else if ( msg == "reload()" ) { |
157 | qWarning ("OContactAccess: Received reload()"); | 165 | qWarning ("OContactAccess: Received reload()"); |
158 | reload (); | 166 | reload (); |
159 | emit signalChanged ( this ); | 167 | emit signalChanged ( this ); |
160 | } | 168 | } |
161 | } | 169 | } |
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index b4921d5..961968f 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -1,139 +1,150 @@ | |||
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.5 2002/11/13 14:14:51 eilers | ||
21 | * Added sorted for Contacts.. | ||
22 | * | ||
20 | * Revision 1.4 2002/11/01 15:10:42 eilers | 23 | * Revision 1.4 2002/11/01 15:10:42 eilers |
21 | * Added regExp-search in database for all fields in a contact. | 24 | * Added regExp-search in database for all fields in a contact. |
22 | * | 25 | * |
23 | * Revision 1.3 2002/10/16 10:52:40 eilers | 26 | * Revision 1.3 2002/10/16 10:52:40 eilers |
24 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | 27 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) |
25 | * | 28 | * |
26 | * Revision 1.2 2002/10/14 16:21:54 eilers | 29 | * Revision 1.2 2002/10/14 16:21:54 eilers |
27 | * Some minor interface updates | 30 | * Some minor interface updates |
28 | * | 31 | * |
29 | * Revision 1.1 2002/09/27 17:11:44 eilers | 32 | * Revision 1.1 2002/09/27 17:11:44 eilers |
30 | * Added API for accessing the Contact-Database ! It is compiling, but | 33 | * Added API for accessing the Contact-Database ! It is compiling, but |
31 | * please do not expect that anything is working ! | 34 | * please do not expect that anything is working ! |
32 | * I will debug that stuff in the next time .. | 35 | * I will debug that stuff in the next time .. |
33 | * Please read README_COMPILE for compiling ! | 36 | * Please read README_COMPILE for compiling ! |
34 | * | 37 | * |
35 | * ===================================================================== | 38 | * ===================================================================== |
36 | */ | 39 | */ |
37 | #ifndef _OCONTACTACCESS_H | 40 | #ifndef _OCONTACTACCESS_H |
38 | #define _OCONTACTACCESS_H | 41 | #define _OCONTACTACCESS_H |
39 | 42 | ||
40 | #include <qobject.h> | 43 | #include <qobject.h> |
41 | 44 | ||
42 | #include <qpe/qcopenvelope_qws.h> | 45 | #include <qpe/qcopenvelope_qws.h> |
43 | 46 | ||
44 | #include <qvaluelist.h> | 47 | #include <qvaluelist.h> |
45 | #include <qfileinfo.h> | 48 | #include <qfileinfo.h> |
46 | 49 | ||
47 | #include "ocontact.h" | 50 | #include "ocontact.h" |
48 | #include "ocontactaccessbackend.h" | 51 | #include "ocontactaccessbackend.h" |
49 | #include "opimaccesstemplate.h" | 52 | #include "opimaccesstemplate.h" |
50 | 53 | ||
51 | /** Class to access the contacts database. | 54 | /** Class to access the contacts database. |
52 | * This is just a frontend for the real database handling which is | 55 | * This is just a frontend for the real database handling which is |
53 | * done by the backend. | 56 | * done by the backend. |
54 | * @see OPimAccessTemplate | 57 | * @see OPimAccessTemplate |
55 | */ | 58 | */ |
56 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | 59 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> |
57 | { | 60 | { |
58 | Q_OBJECT | 61 | Q_OBJECT |
59 | 62 | ||
60 | public: | 63 | public: |
61 | /** Create Database with contacts (addressbook). | 64 | /** Create Database with contacts (addressbook). |
62 | * @param appname Name of application which wants access to the database | 65 | * @param appname Name of application which wants access to the database |
63 | * (i.e. "todolist") | 66 | * (i.e. "todolist") |
64 | * @param filename The name of the database file. If not set, the default one | 67 | * @param filename The name of the database file. If not set, the default one |
65 | * is used. | 68 | * is used. |
66 | * @param backend Pointer to an alternative Backend. If not set, we will use | 69 | * @param backend Pointer to an alternative Backend. If not set, we will use |
67 | * the default backend. | 70 | * the default backend. |
68 | * @param handlesync If <b>true</b> the database stores the current state | 71 | * @param handlesync If <b>true</b> the database stores the current state |
69 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 72 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
70 | * which are used before and after synchronisation. If the application wants | 73 | * which are used before and after synchronisation. If the application wants |
71 | * to react itself, it should be disabled by setting it to <b>false</b> | 74 | * to react itself, it should be disabled by setting it to <b>false</b> |
72 | * @see OContactAccessBackend | 75 | * @see OContactAccessBackend |
73 | */ | 76 | */ |
74 | OContactAccess (const QString appname, const QString filename = 0l, | 77 | OContactAccess (const QString appname, const QString filename = 0l, |
75 | OContactAccessBackend* backend = 0l, bool handlesync = true); | 78 | OContactAccessBackend* backend = 0l, bool handlesync = true); |
76 | ~OContactAccess (); | 79 | ~OContactAccess (); |
77 | 80 | ||
78 | /** Constants for query. | 81 | /** Constants for query. |
79 | * Use this constants to set the query parameters. | 82 | * Use this constants to set the query parameters. |
80 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 83 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
81 | * @see queryByExample() | 84 | * @see queryByExample() |
82 | */ | 85 | */ |
83 | enum QuerySettings { | 86 | enum QuerySettings { |
84 | WildCards = 0x0001, | 87 | WildCards = 0x0001, |
85 | IgnoreCase = 0x0002, | 88 | IgnoreCase = 0x0002, |
86 | RegExp = 0x0004, | 89 | RegExp = 0x0004, |
87 | ExactMatch = 0x0008, | 90 | ExactMatch = 0x0008, |
88 | MatchOne = 0x0010 // Only one Entry must match | 91 | MatchOne = 0x0010 // Only one Entry must match |
89 | }; | 92 | }; |
90 | 93 | ||
91 | 94 | ||
92 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; | 95 | ORecordList<OContact> matchRegexp( const QRegExp &r )const; |
93 | 96 | ||
97 | /** Return all Contacts in a sorted manner. | ||
98 | * @param ascending true: Sorted in acending order. | ||
99 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | ||
100 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | ||
101 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | ||
102 | */ | ||
103 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | ||
104 | |||
94 | /** Return all possible settings. | 105 | /** Return all possible settings. |
95 | * @return All settings provided by the current backend | 106 | * @return All settings provided by the current backend |
96 | * (i.e.: query_WildCards & query_IgnoreCase) | 107 | * (i.e.: query_WildCards & query_IgnoreCase) |
97 | */ | 108 | */ |
98 | const uint querySettings(); | 109 | const uint querySettings(); |
99 | 110 | ||
100 | /** Check whether settings are correct. | 111 | /** Check whether settings are correct. |
101 | * @return <i>true</i> if the given settings are correct and possible. | 112 | * @return <i>true</i> if the given settings are correct and possible. |
102 | */ | 113 | */ |
103 | bool hasQuerySettings ( int querySettings ) const; | 114 | bool hasQuerySettings ( int querySettings ) const; |
104 | 115 | ||
105 | /** | 116 | /** |
106 | * if the resource was changed externally. | 117 | * if the resource was changed externally. |
107 | * You should use the signal instead of polling possible changes ! | 118 | * You should use the signal instead of polling possible changes ! |
108 | */ | 119 | */ |
109 | bool wasChangedExternally()const; | 120 | bool wasChangedExternally()const; |
110 | 121 | ||
111 | 122 | ||
112 | /** Save contacts database. | 123 | /** Save contacts database. |
113 | * Save is more a "commit". After calling this function, all changes are public available. | 124 | * Save is more a "commit". After calling this function, all changes are public available. |
114 | * @return true if successful | 125 | * @return true if successful |
115 | */ | 126 | */ |
116 | bool save(); | 127 | bool save(); |
117 | 128 | ||
118 | signals: | 129 | signals: |
119 | /* Signal is emitted if the database was changed. Therefore | 130 | /* Signal is emitted if the database was changed. Therefore |
120 | * we may need to reload to stay consistent. | 131 | * we may need to reload to stay consistent. |
121 | * @param which Pointer to the database who created this event. This pointer | 132 | * @param which Pointer to the database who created this event. This pointer |
122 | * is useful if an application has to handle multiple databases at the same time. | 133 | * is useful if an application has to handle multiple databases at the same time. |
123 | * @see reload() | 134 | * @see reload() |
124 | */ | 135 | */ |
125 | void signalChanged ( const OContactAccess *which ); | 136 | void signalChanged ( const OContactAccess *which ); |
126 | 137 | ||
127 | 138 | ||
128 | private: | 139 | private: |
129 | // class OContactAccessPrivate; | 140 | // class OContactAccessPrivate; |
130 | // OContactAccessPrivate* d; | 141 | // OContactAccessPrivate* d; |
131 | OContactAccessBackend *m_backEnd; | 142 | OContactAccessBackend *m_backEnd; |
132 | bool m_loading:1; | 143 | bool m_loading:1; |
133 | 144 | ||
134 | private slots: | 145 | private slots: |
135 | void copMessage( const QCString &msg, const QByteArray &data ); | 146 | void copMessage( const QCString &msg, const QByteArray &data ); |
136 | 147 | ||
137 | 148 | ||
138 | }; | 149 | }; |
139 | #endif | 150 | #endif |