summaryrefslogtreecommitdiff
authorar <ar>2004-06-01 22:21:23 (UTC)
committer ar <ar>2004-06-01 22:21:23 (UTC)
commitd4fe7d53ddf8f3e7ae046a511f0dc061f30d45ce (patch) (unidiff)
tree4bab082304716df1ec924ef040161e3cf9c10366
parentbaed1d5ab8589aef14440009bc4e7380bcc5a741 (diff)
downloadopie-d4fe7d53ddf8f3e7ae046a511f0dc061f30d45ce.zip
opie-d4fe7d53ddf8f3e7ae046a511f0dc061f30d45ce.tar.gz
opie-d4fe7d53ddf8f3e7ae046a511f0dc061f30d45ce.tar.bz2
- convert to odebug framework
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/obackendfactory.h242
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp36
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp117
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h17
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp4
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp4
-rw-r--r--libopie2/opiepim/core/opimrecordlist.h5
7 files changed, 218 insertions, 207 deletions
diff --git a/libopie2/opiepim/backend/obackendfactory.h b/libopie2/opiepim/backend/obackendfactory.h
index 6f46652..3680ded 100644
--- a/libopie2/opiepim/backend/obackendfactory.h
+++ b/libopie2/opiepim/backend/obackendfactory.h
@@ -1,224 +1,230 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: Use plugins 31 * ToDo: Use plugins
32 * ===================================================================== 32 * =====================================================================
33 */ 33 */
34#ifndef OPIE_BACKENDFACTORY_H_ 34#ifndef OPIE_BACKENDFACTORY_H_
35#define OPIE_BACKENDFACTORY_H_ 35#define OPIE_BACKENDFACTORY_H_
36 36
37#include <qstring.h> 37/* OPIE */
38#include <qasciidict.h>
39#include <qpe/config.h>
40
41#include <opie2/opimaccessbackend.h> 38#include <opie2/opimaccessbackend.h>
42#include <opie2/opimglobal.h> 39#include <opie2/opimglobal.h>
43#include <opie2/otodoaccessxml.h> 40#include <opie2/otodoaccessxml.h>
44#include <opie2/otodoaccessvcal.h> 41#include <opie2/otodoaccessvcal.h>
45#include <opie2/ocontactaccessbackend_xml.h> 42#include <opie2/ocontactaccessbackend_xml.h>
46#include <opie2/ocontactaccessbackend_vcard.h> 43#include <opie2/ocontactaccessbackend_vcard.h>
47#include <opie2/odatebookaccessbackend_xml.h> 44#include <opie2/odatebookaccessbackend_xml.h>
45#include <opie2/odebug.h>
48 46
49#ifdef __USE_SQL 47#ifdef __USE_SQL
50#include <opie2/otodoaccesssql.h> 48#include <opie2/otodoaccesssql.h>
51#include <opie2/ocontactaccessbackend_sql.h> 49#include <opie2/ocontactaccessbackend_sql.h>
52#include <opie2/odatebookaccessbackend_sql.h> 50#include <opie2/odatebookaccessbackend_sql.h>
53#endif 51#endif
54 52
53#include <qpe/config.h>
54
55/* QT */
56#include <qstring.h>
57#include <qasciidict.h>
58
59
60
55using namespace Opie; 61using namespace Opie;
56using namespace Opie::Pim; 62using namespace Opie::Pim;
57 63
58namespace Opie { 64namespace Opie {
59 65
60class OBackendPrivate; 66class OBackendPrivate;
61 67
62/** 68/**
63 * This class is our factory. It will give us the default implementations 69 * This class is our factory. It will give us the default implementations
64 * of at least Todolist, Contacts and Datebook. In the future this class will 70 * of at least Todolist, Contacts and Datebook. In the future this class will
65 * allow users to switch the backend with ( XML->SQLite ) without the need 71 * allow users to switch the backend with ( XML->SQLite ) without the need
66 * to recompile.# 72 * to recompile.#
67 * This class - as the whole PIM Api - is making use of templates 73 * This class - as the whole PIM Api - is making use of templates
68 * 74 *
69 * <pre> 75 * <pre>
70 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default( OPimGlobal::TODOLIST, QString::null ); 76 * OPimTodoAccessBackend* backend = OBackEndFactory<OPimTodoAccessBackend>::Default( OPimGlobal::TODOLIST, QString::null );
71 * backend->load(); 77 * backend->load();
72 * </pre> 78 * </pre>
73 * 79 *
74 * @author Stefan Eilers 80 * @author Stefan Eilers
75 * @version 0.1 81 * @version 0.1
76 */ 82 */
77template<class T> 83template<class T>
78class OBackendFactory 84class OBackendFactory
79{ 85{
80 public: 86 public:
81 OBackendFactory() {}; 87 OBackendFactory() {};
82 88
83 /** 89 /**
84 * Returns a selected backend implementation 90 * Returns a selected backend implementation
85 * @param type the type of the backend 91 * @param type the type of the backend
86 * @param database the type of the used database 92 * @param database the type of the used database
87 * @param appName The name of your application. It will be passed on to the backend. 93 * @param appName The name of your application. It will be passed on to the backend.
88 * @param filename Filename of the database file if you don't want to access the default 94 * @param filename Filename of the database file if you don't want to access the default
89 * @see OPimGlobal() 95 * @see OPimGlobal()
90 */ 96 */
91 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database, 97 static T* create( OPimGlobal::PimType type, OPimGlobal::DatabaseStyle database,
92 const QString& appName, const QString& filename = QString::null ){ 98 const QString& appName, const QString& filename = QString::null ){
93 qWarning("Selected backend for %d is: %d", type, database ); 99 owarn << "Selected backend for " << type << " is: " << database << oendl;
94 // If we should use the dafult database style, we have to request it 100 // If we should use the dafult database style, we have to request it
95 OPimGlobal::DatabaseStyle use_database = database; 101 OPimGlobal::DatabaseStyle use_database = database;
96 if ( use_database == OPimGlobal::DEFAULT ){ 102 if ( use_database == OPimGlobal::DEFAULT ){
97 use_database = defaultDB( type ); 103 use_database = defaultDB( type );
98 } 104 }
99 105
100 switch ( type ){ 106 switch ( type ){
101 case OPimGlobal::TODOLIST: 107 case OPimGlobal::TODOLIST:
102 108
103 switch ( use_database ){ 109 switch ( use_database ){
104 default: // Use SQL if something weird is given. 110 default: // Use SQL if something weird is given.
105 // Fall through !! 111 // Fall through !!
106 case OPimGlobal::SQL: 112 case OPimGlobal::SQL:
107#ifdef __USE_SQL 113#ifdef __USE_SQL
108 return (T*) new OPimTodoAccessBackendSQL( filename ); 114 return (T*) new OPimTodoAccessBackendSQL( filename );
109 break; 115 break;
110#else 116#else
111 qWarning ("OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!"); 117 owarn << "OBackendFactory:: sql Backend for TODO not implemented! Using XML instead!" << oendl;
112 // Fall through !! 118 // Fall through !!
113#endif 119#endif
114 case OPimGlobal::XML: 120 case OPimGlobal::XML:
115 return (T*) new OPimTodoAccessXML( appName, filename ); 121 return (T*) new OPimTodoAccessXML( appName, filename );
116 break; 122 break;
117 case OPimGlobal::VCARD: 123 case OPimGlobal::VCARD:
118 return (T*) new OPimTodoAccessVCal( filename ); 124 return (T*) new OPimTodoAccessVCal( filename );
119 break; 125 break;
120 } 126 }
121 case OPimGlobal::CONTACTLIST: 127 case OPimGlobal::CONTACTLIST:
122 switch ( use_database ){ 128 switch ( use_database ){
123 default: // Use SQL if something weird is given. 129 default: // Use SQL if something weird is given.
124 // Fall through !! 130 // Fall through !!
125 case OPimGlobal::SQL: 131 case OPimGlobal::SQL:
126#ifdef __USE_SQL 132#ifdef __USE_SQL
127 return (T*) new OPimContactAccessBackend_SQL( appName, filename ); 133 return (T*) new OPimContactAccessBackend_SQL( appName, filename );
128 break; 134 break;
129#else 135#else
130 qWarning ("OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!"); 136 owarn << "OBackendFactory:: sql Backend for CONTACT not implemented! Using XML instead!" << oendl;
131 // Fall through !! 137 // Fall through !!
132#endif 138#endif
133 case OPimGlobal::XML: 139 case OPimGlobal::XML:
134 return (T*) new OPimContactAccessBackend_XML( appName, filename ); 140 return (T*) new OPimContactAccessBackend_XML( appName, filename );
135 break; 141 break;
136 case OPimGlobal::VCARD: 142 case OPimGlobal::VCARD:
137 return (T*) new OPimContactAccessBackend_VCard( appName, filename ); 143 return (T*) new OPimContactAccessBackend_VCard( appName, filename );
138 break; 144 break;
139 } 145 }
140 case OPimGlobal::DATEBOOK: 146 case OPimGlobal::DATEBOOK:
141 switch ( use_database ){ 147 switch ( use_database ){
142 default: // Use SQL if something weird is given. 148 default: // Use SQL if something weird is given.
143 // Fall through !! 149 // Fall through !!
144 case OPimGlobal::SQL: 150 case OPimGlobal::SQL:
145#ifdef __USE_SQL 151#ifdef __USE_SQL
146 return (T*) new ODateBookAccessBackend_SQL( appName, filename ); 152 return (T*) new ODateBookAccessBackend_SQL( appName, filename );
147 break; 153 break;
148#else 154#else
149 qWarning("OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!"); 155 owarn << "OBackendFactory:: sql Backend for DATEBOOK not implemented! Using XML instead!" << oendl;
150 // Fall through !! 156 // Fall through !!
151#endif 157#endif
152 case OPimGlobal::XML: 158 case OPimGlobal::XML:
153 return (T*) new ODateBookAccessBackend_XML( appName, filename ); 159 return (T*) new ODateBookAccessBackend_XML( appName, filename );
154 break; 160 break;
155 case OPimGlobal::VCARD: 161 case OPimGlobal::VCARD:
156 qWarning("OBackendFactory:: VCal Backend for DATEBOOK not implemented!"); 162 owarn << "OBackendFactory:: VCal Backend for DATEBOOK not implemented!" << oendl;
157 return (T*) NULL; 163 return (T*) NULL;
158 break; 164 break;
159 } 165 }
160 default: 166 default:
161 return (T*) NULL; 167 return (T*) NULL;
162 } 168 }
163 169
164 } 170 }
165 171
166 /** 172 /**
167 * Returns the style of the default database which is used to contact PIM data. 173 * Returns the style of the default database which is used to contact PIM data.
168 * @param type the type of the backend 174 * @param type the type of the backend
169 * @see OPimGlobal() 175 * @see OPimGlobal()
170 */ 176 */
171 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){ 177 static OPimGlobal::DatabaseStyle defaultDB( OPimGlobal::PimType type ){
172 QString group_name; 178 QString group_name;
173 switch ( type ){ 179 switch ( type ){
174 case OPimGlobal::TODOLIST: 180 case OPimGlobal::TODOLIST:
175 group_name = "todo"; 181 group_name = "todo";
176 break; 182 break;
177 case OPimGlobal::CONTACTLIST: 183 case OPimGlobal::CONTACTLIST:
178 group_name = "contact"; 184 group_name = "contact";
179 break; 185 break;
180 case OPimGlobal::DATEBOOK: 186 case OPimGlobal::DATEBOOK:
181 group_name = "datebook"; 187 group_name = "datebook";
182 break; 188 break;
183 default: 189 default:
184 group_name = "unknown"; 190 group_name = "unknown";
185 } 191 }
186 192
187 Config config( "pimaccess" ); 193 Config config( "pimaccess" );
188 config.setGroup ( group_name ); 194 config.setGroup ( group_name );
189 QString db_String = config.readEntry( "usebackend", "xml" ); 195 QString db_String = config.readEntry( "usebackend", "xml" );
190 196
191 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle ); 197 QAsciiDict<int> dictDbTypes( OPimGlobal::_END_DatabaseStyle );
192 dictDbTypes.setAutoDelete( TRUE ); 198 dictDbTypes.setAutoDelete( TRUE );
193 199
194 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) ); 200 dictDbTypes.insert( "xml", new int (OPimGlobal::XML) );
195 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) ); 201 dictDbTypes.insert( "sql", new int (OPimGlobal::SQL) );
196 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) ); 202 dictDbTypes.insert( "vcard", new int (OPimGlobal::VCARD) );
197 203
198 int* db_find = dictDbTypes[ db_String ]; 204 int* db_find = dictDbTypes[ db_String ];
199 205
200 if ( !db_find ) 206 if ( !db_find )
201 return OPimGlobal::UNKNOWN; 207 return OPimGlobal::UNKNOWN;
202 208
203 return (OPimGlobal::DatabaseStyle) *db_find; 209 return (OPimGlobal::DatabaseStyle) *db_find;
204 } 210 }
205 211
206 212
207 /** 213 /**
208 * Returns the default backend implementation for backendName. Which one is used, is defined 214 * Returns the default backend implementation for backendName. Which one is used, is defined
209 * by the configfile "pimaccess.conf". 215 * by the configfile "pimaccess.conf".
210 * @param type The type of the backend (@see OPimGlobal()) 216 * @param type The type of the backend (@see OPimGlobal())
211 * @param appName The name of your application. It will be passed on to the backend 217 * @param appName The name of your application. It will be passed on to the backend
212 * @see OPimGlobal() 218 * @see OPimGlobal()
213 */ 219 */
214 static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){ 220 static T* defaultBackend( OPimGlobal::PimType type, const QString& appName ){
215 return create( type, OPimGlobal::DEFAULT, appName ); 221 return create( type, OPimGlobal::DEFAULT, appName );
216 } 222 }
217 private: 223 private:
218 OBackendPrivate* d; 224 OBackendPrivate* d;
219 225
220}; 226};
221 227
222} 228}
223 229
224#endif 230#endif
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 5ffcb11..00d62ee 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -44,342 +44,340 @@
44#include <qasciidict.h> 44#include <qasciidict.h>
45#include <qfile.h> 45#include <qfile.h>
46#include <qfileinfo.h> 46#include <qfileinfo.h>
47#include <qregexp.h> 47#include <qregexp.h>
48#include <qarray.h> 48#include <qarray.h>
49#include <qmap.h> 49#include <qmap.h>
50 50
51/* STD */ 51/* STD */
52#include <stdlib.h> 52#include <stdlib.h>
53#include <errno.h> 53#include <errno.h>
54 54
55using namespace Opie::Core; 55using namespace Opie::Core;
56 56
57 57
58namespace Opie { 58namespace Opie {
59OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ): 59OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ):
60 m_changed( false ) 60 m_changed( false )
61{ 61{
62 // Just m_contactlist should call delete if an entry 62 // Just m_contactlist should call delete if an entry
63 // is removed. 63 // is removed.
64 m_contactList.setAutoDelete( true ); 64 m_contactList.setAutoDelete( true );
65 m_uidToContact.setAutoDelete( false ); 65 m_uidToContact.setAutoDelete( false );
66 66
67 m_appName = appname; 67 m_appName = appname;
68 68
69 /* Set journalfile name ... */ 69 /* Set journalfile name ... */
70 m_journalName = getenv("HOME"); 70 m_journalName = getenv("HOME");
71 m_journalName +="/.abjournal" + appname; 71 m_journalName +="/.abjournal" + appname;
72 72
73 /* Expecting to access the default filename if nothing else is set */ 73 /* Expecting to access the default filename if nothing else is set */
74 if ( filename.isEmpty() ){ 74 if ( filename.isEmpty() ){
75 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 75 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
76 } else 76 } else
77 m_fileName = filename; 77 m_fileName = filename;
78 78
79 /* Load Database now */ 79 /* Load Database now */
80 load (); 80 load ();
81} 81}
82 82
83bool OPimContactAccessBackend_XML::save() 83bool OPimContactAccessBackend_XML::save()
84{ 84{
85 85
86 if ( !m_changed ) 86 if ( !m_changed )
87 return true; 87 return true;
88 88
89 QString strNewFile = m_fileName + ".new"; 89 QString strNewFile = m_fileName + ".new";
90 QFile f( strNewFile ); 90 QFile f( strNewFile );
91 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 91 if ( !f.open( IO_WriteOnly|IO_Raw ) )
92 return false; 92 return false;
93 93
94 int total_written; 94 int total_written;
95 int idx_offset = 0; 95 int idx_offset = 0;
96 QString out; 96 QString out;
97 97
98 // Write Header 98 // Write Header
99 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 99 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
100 " <Groups>\n" 100 " <Groups>\n"
101 " </Groups>\n" 101 " </Groups>\n"
102 " <Contacts>\n"; 102 " <Contacts>\n";
103 QCString cstr = out.utf8(); 103 QCString cstr = out.utf8();
104 f.writeBlock( cstr.data(), cstr.length() ); 104 f.writeBlock( cstr.data(), cstr.length() );
105 idx_offset += cstr.length(); 105 idx_offset += cstr.length();
106 out = ""; 106 out = "";
107 107
108 // Write all contacts 108 // Write all contacts
109 QListIterator<OPimContact> it( m_contactList ); 109 QListIterator<OPimContact> it( m_contactList );
110 for ( ; it.current(); ++it ) { 110 for ( ; it.current(); ++it ) {
111 // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl; 111 // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl;
112 out += "<Contact "; 112 out += "<Contact ";
113 (*it)->save( out ); 113 (*it)->save( out );
114 out += "/>\n"; 114 out += "/>\n";
115 cstr = out.utf8(); 115 cstr = out.utf8();
116 total_written = f.writeBlock( cstr.data(), cstr.length() ); 116 total_written = f.writeBlock( cstr.data(), cstr.length() );
117 idx_offset += cstr.length(); 117 idx_offset += cstr.length();
118 if ( total_written != int(cstr.length()) ) { 118 if ( total_written != int(cstr.length()) ) {
119 f.close(); 119 f.close();
120 QFile::remove( strNewFile ); 120 QFile::remove( strNewFile );
121 return false; 121 return false;
122 } 122 }
123 out = ""; 123 out = "";
124 } 124 }
125 out += " </Contacts>\n</AddressBook>\n"; 125 out += " </Contacts>\n</AddressBook>\n";
126 126
127 // Write Footer 127 // Write Footer
128 cstr = out.utf8(); 128 cstr = out.utf8();
129 total_written = f.writeBlock( cstr.data(), cstr.length() ); 129 total_written = f.writeBlock( cstr.data(), cstr.length() );
130 if ( total_written != int( cstr.length() ) ) { 130 if ( total_written != int( cstr.length() ) ) {
131 f.close(); 131 f.close();
132 QFile::remove( strNewFile ); 132 QFile::remove( strNewFile );
133 return false; 133 return false;
134 } 134 }
135 f.close(); 135 f.close();
136 136
137 // move the file over, I'm just going to use the system call 137 // move the file over, I'm just going to use the system call
138 // because, I don't feel like using QDir. 138 // because, I don't feel like using QDir.
139 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 139 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
140 qWarning( "problem renaming file %s to %s, errno: %d", 140 owarn << "problem renaming file " << strNewFile << " to " << m_journalName
141 strNewFile.latin1(), m_journalName.latin1(), errno ); 141 << ", errno: " << errno << oendl;
142 // remove the tmp file... 142 // remove the tmp file...
143 QFile::remove( strNewFile ); 143 QFile::remove( strNewFile );
144 } 144 }
145 145
146 /* The journalfile should be removed now... */ 146 /* The journalfile should be removed now... */
147 removeJournal(); 147 removeJournal();
148 148
149 m_changed = false; 149 m_changed = false;
150 return true; 150 return true;
151} 151}
152 152
153bool OPimContactAccessBackend_XML::load () 153bool OPimContactAccessBackend_XML::load ()
154{ 154{
155 m_contactList.clear(); 155 m_contactList.clear();
156 m_uidToContact.clear(); 156 m_uidToContact.clear();
157 157
158 /* Load XML-File and journal if it exists */ 158 /* Load XML-File and journal if it exists */
159 if ( !load ( m_fileName, false ) ) 159 if ( !load ( m_fileName, false ) )
160 return false; 160 return false;
161 /* The returncode of the journalfile is ignored due to the 161 /* The returncode of the journalfile is ignored due to the
162 * fact that it does not exist when this class is instantiated ! 162 * fact that it does not exist when this class is instantiated !
163 * But there may such a file exist, if the application crashed. 163 * But there may such a file exist, if the application crashed.
164 * Therefore we try to load it to get the changes before the # 164 * Therefore we try to load it to get the changes before the #
165 * crash happened... 165 * crash happened...
166 */ 166 */
167 load (m_journalName, true); 167 load (m_journalName, true);
168 168
169 return true; 169 return true;
170} 170}
171 171
172void OPimContactAccessBackend_XML::clear () 172void OPimContactAccessBackend_XML::clear ()
173{ 173{
174 m_contactList.clear(); 174 m_contactList.clear();
175 m_uidToContact.clear(); 175 m_uidToContact.clear();
176 176
177 m_changed = false; 177 m_changed = false;
178} 178}
179 179
180bool OPimContactAccessBackend_XML::wasChangedExternally() 180bool OPimContactAccessBackend_XML::wasChangedExternally()
181{ 181{
182 QFileInfo fi( m_fileName ); 182 QFileInfo fi( m_fileName );
183 183
184 QDateTime lastmod = fi.lastModified (); 184 QDateTime lastmod = fi.lastModified ();
185 185
186 return (lastmod != m_readtime); 186 return (lastmod != m_readtime);
187} 187}
188 188
189QArray<int> OPimContactAccessBackend_XML::allRecords() const 189QArray<int> OPimContactAccessBackend_XML::allRecords() const
190{ 190{
191 QArray<int> uid_list( m_contactList.count() ); 191 QArray<int> uid_list( m_contactList.count() );
192 192
193 uint counter = 0; 193 uint counter = 0;
194 QListIterator<OPimContact> it( m_contactList ); 194 QListIterator<OPimContact> it( m_contactList );
195 for( ; it.current(); ++it ){ 195 for( ; it.current(); ++it ){
196 uid_list[counter++] = (*it)->uid(); 196 uid_list[counter++] = (*it)->uid();
197 } 197 }
198 198
199 return ( uid_list ); 199 return ( uid_list );
200} 200}
201 201
202OPimContact OPimContactAccessBackend_XML::find ( int uid ) const 202OPimContact OPimContactAccessBackend_XML::find ( int uid ) const
203{ 203{
204 OPimContact foundContact; //Create empty contact 204 OPimContact foundContact; //Create empty contact
205 205
206 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) ); 206 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) );
207 207
208 if ( found ){ 208 if ( found ){
209 foundContact = *found; 209 foundContact = *found;
210 } 210 }
211 211
212 return ( foundContact ); 212 return ( foundContact );
213} 213}
214 214
215QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, 215QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings,
216 const QDateTime& d ) 216 const QDateTime& d )
217{ 217{
218 218
219 QArray<int> m_currentQuery( m_contactList.count() ); 219 QArray<int> m_currentQuery( m_contactList.count() );
220 QListIterator<OPimContact> it( m_contactList ); 220 QListIterator<OPimContact> it( m_contactList );
221 uint arraycounter = 0; 221 uint arraycounter = 0;
222 222
223 for( ; it.current(); ++it ){ 223 for( ; it.current(); ++it ){
224 /* Search all fields and compare them with query object. Store them into list 224 /* Search all fields and compare them with query object. Store them into list
225 * if all fields matches. 225 * if all fields matches.
226 */ 226 */
227 QDate* queryDate = 0l; 227 QDate* queryDate = 0l;
228 QDate* checkDate = 0l; 228 QDate* checkDate = 0l;
229 bool allcorrect = true; 229 bool allcorrect = true;
230 for ( int i = 0; i < Qtopia::Groups; i++ ) { 230 for ( int i = 0; i < Qtopia::Groups; i++ ) {
231 // Birthday and anniversary are special nonstring fields and should 231 // Birthday and anniversary are special nonstring fields and should
232 // be handled specially 232 // be handled specially
233 switch ( i ){ 233 switch ( i ){
234 case Qtopia::Birthday: 234 case Qtopia::Birthday:
235 queryDate = new QDate( query.birthday() ); 235 queryDate = new QDate( query.birthday() );
236 checkDate = new QDate( (*it)->birthday() ); 236 checkDate = new QDate( (*it)->birthday() );
237 // fall through 237 // fall through
238 case Qtopia::Anniversary: 238 case Qtopia::Anniversary:
239 if ( queryDate == 0l ){ 239 if ( queryDate == 0l ){
240 queryDate = new QDate( query.anniversary() ); 240 queryDate = new QDate( query.anniversary() );
241 checkDate = new QDate( (*it)->anniversary() ); 241 checkDate = new QDate( (*it)->anniversary() );
242 } 242 }
243 243
244 if ( queryDate->isValid() ){ 244 if ( queryDate->isValid() ){
245 if( checkDate->isValid() ){ 245 if( checkDate->isValid() ){
246 if ( settings & OPimContactAccess::DateYear ){ 246 if ( settings & OPimContactAccess::DateYear ){
247 if ( queryDate->year() != checkDate->year() ) 247 if ( queryDate->year() != checkDate->year() )
248 allcorrect = false; 248 allcorrect = false;
249 } 249 }
250 if ( settings & OPimContactAccess::DateMonth ){ 250 if ( settings & OPimContactAccess::DateMonth ){
251 if ( queryDate->month() != checkDate->month() ) 251 if ( queryDate->month() != checkDate->month() )
252 allcorrect = false; 252 allcorrect = false;
253 } 253 }
254 if ( settings & OPimContactAccess::DateDay ){ 254 if ( settings & OPimContactAccess::DateDay ){
255 if ( queryDate->day() != checkDate->day() ) 255 if ( queryDate->day() != checkDate->day() )
256 allcorrect = false; 256 allcorrect = false;
257 } 257 }
258 if ( settings & OPimContactAccess::DateDiff ) { 258 if ( settings & OPimContactAccess::DateDiff ) {
259 QDate current; 259 QDate current;
260 // If we get an additional date, we 260 // If we get an additional date, we
261 // will take this date instead of 261 // will take this date instead of
262 // the current one.. 262 // the current one..
263 if ( !d.date().isValid() ) 263 if ( !d.date().isValid() )
264 current = QDate::currentDate(); 264 current = QDate::currentDate();
265 else 265 else
266 current = d.date(); 266 current = d.date();
267 267
268 // We have to equalize the year, otherwise 268 // We have to equalize the year, otherwise
269 // the search will fail.. 269 // the search will fail..
270 checkDate->setYMD( current.year(), 270 checkDate->setYMD( current.year(),
271 checkDate->month(), 271 checkDate->month(),
272 checkDate->day() ); 272 checkDate->day() );
273 if ( *checkDate < current ) 273 if ( *checkDate < current )
274 checkDate->setYMD( current.year()+1, 274 checkDate->setYMD( current.year()+1,
275 checkDate->month(), 275 checkDate->month(),
276 checkDate->day() ); 276 checkDate->day() );
277 277
278 // Check whether the birthday/anniversary date is between 278 // Check whether the birthday/anniversary date is between
279 // the current/given date and the maximum date 279 // the current/given date and the maximum date
280 // ( maximum time range ) ! 280 // ( maximum time range ) !
281 qWarning("Checking if %s is between %s and %s ! ", 281 owarn << "Checking if " << checkDate->toString() << " is between " << current.toString()
282 checkDate->toString().latin1(), 282 << " and " << queryDate->toString() << " ! " << oendl;
283 current.toString().latin1(),
284 queryDate->toString().latin1() );
285 if ( current.daysTo( *queryDate ) >= 0 ){ 283 if ( current.daysTo( *queryDate ) >= 0 ){
286 if ( !( ( *checkDate >= current ) && 284 if ( !( ( *checkDate >= current ) &&
287 ( *checkDate <= *queryDate ) ) ){ 285 ( *checkDate <= *queryDate ) ) ){
288 allcorrect = false; 286 allcorrect = false;
289 qWarning (" Nope!.."); 287 owarn << " Nope!.." << oendl;
290 } 288 }
291 } 289 }
292 } 290 }
293 } else{ 291 } else{
294 // checkDate is invalid. Therefore this entry is always rejected 292 // checkDate is invalid. Therefore this entry is always rejected
295 allcorrect = false; 293 allcorrect = false;
296 } 294 }
297 } 295 }
298 296
299 delete queryDate; 297 delete queryDate;
300 queryDate = 0l; 298 queryDate = 0l;
301 delete checkDate; 299 delete checkDate;
302 checkDate = 0l; 300 checkDate = 0l;
303 break; 301 break;
304 default: 302 default:
305 /* Just compare fields which are not empty in the query object */ 303 /* Just compare fields which are not empty in the query object */
306 if ( !query.field(i).isEmpty() ){ 304 if ( !query.field(i).isEmpty() ){
307 switch ( settings & ~( OPimContactAccess::IgnoreCase 305 switch ( settings & ~( OPimContactAccess::IgnoreCase
308 | OPimContactAccess::DateDiff 306 | OPimContactAccess::DateDiff
309 | OPimContactAccess::DateYear 307 | OPimContactAccess::DateYear
310 | OPimContactAccess::DateMonth 308 | OPimContactAccess::DateMonth
311 | OPimContactAccess::DateDay 309 | OPimContactAccess::DateDay
312 | OPimContactAccess::MatchOne 310 | OPimContactAccess::MatchOne
313 ) ){ 311 ) ){
314 312
315 case OPimContactAccess::RegExp:{ 313 case OPimContactAccess::RegExp:{
316 QRegExp expr ( query.field(i), 314 QRegExp expr ( query.field(i),
317 !(settings & OPimContactAccess::IgnoreCase), 315 !(settings & OPimContactAccess::IgnoreCase),
318 false ); 316 false );
319 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 317 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
320 allcorrect = false; 318 allcorrect = false;
321 } 319 }
322 break; 320 break;
323 case OPimContactAccess::WildCards:{ 321 case OPimContactAccess::WildCards:{
324 QRegExp expr ( query.field(i), 322 QRegExp expr ( query.field(i),
325 !(settings & OPimContactAccess::IgnoreCase), 323 !(settings & OPimContactAccess::IgnoreCase),
326 true ); 324 true );
327 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 325 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
328 allcorrect = false; 326 allcorrect = false;
329 } 327 }
330 break; 328 break;
331 case OPimContactAccess::ExactMatch:{ 329 case OPimContactAccess::ExactMatch:{
332 if (settings & OPimContactAccess::IgnoreCase){ 330 if (settings & OPimContactAccess::IgnoreCase){
333 if ( query.field(i).upper() != 331 if ( query.field(i).upper() !=
334 (*it)->field(i).upper() ) 332 (*it)->field(i).upper() )
335 allcorrect = false; 333 allcorrect = false;
336 }else{ 334 }else{
337 if ( query.field(i) != (*it)->field(i) ) 335 if ( query.field(i) != (*it)->field(i) )
338 allcorrect = false; 336 allcorrect = false;
339 } 337 }
340 } 338 }
341 break; 339 break;
342 } 340 }
343 } 341 }
344 } 342 }
345 } 343 }
346 if ( allcorrect ){ 344 if ( allcorrect ){
347 m_currentQuery[arraycounter++] = (*it)->uid(); 345 m_currentQuery[arraycounter++] = (*it)->uid();
348 } 346 }
349 } 347 }
350 348
351 // Shrink to fit.. 349 // Shrink to fit..
352 m_currentQuery.resize(arraycounter); 350 m_currentQuery.resize(arraycounter);
353 351
354 return m_currentQuery; 352 return m_currentQuery;
355} 353}
356 354
357QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const 355QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
358{ 356{
359 QArray<int> m_currentQuery( m_contactList.count() ); 357 QArray<int> m_currentQuery( m_contactList.count() );
360 QListIterator<OPimContact> it( m_contactList ); 358 QListIterator<OPimContact> it( m_contactList );
361 uint arraycounter = 0; 359 uint arraycounter = 0;
362 360
363 for( ; it.current(); ++it ){ 361 for( ; it.current(); ++it ){
364 if ( (*it)->match( r ) ){ 362 if ( (*it)->match( r ) ){
365 m_currentQuery[arraycounter++] = (*it)->uid(); 363 m_currentQuery[arraycounter++] = (*it)->uid();
366 } 364 }
367 365
368 } 366 }
369 // Shrink to fit.. 367 // Shrink to fit..
370 m_currentQuery.resize(arraycounter); 368 m_currentQuery.resize(arraycounter);
371 369
372 return m_currentQuery; 370 return m_currentQuery;
373} 371}
374 372
375const uint OPimContactAccessBackend_XML::querySettings() 373const uint OPimContactAccessBackend_XML::querySettings()
376{ 374{
377 return ( OPimContactAccess::WildCards 375 return ( OPimContactAccess::WildCards
378 | OPimContactAccess::IgnoreCase 376 | OPimContactAccess::IgnoreCase
379 | OPimContactAccess::RegExp 377 | OPimContactAccess::RegExp
380 | OPimContactAccess::ExactMatch 378 | OPimContactAccess::ExactMatch
381 | OPimContactAccess::DateDiff 379 | OPimContactAccess::DateDiff
382 | OPimContactAccess::DateYear 380 | OPimContactAccess::DateYear
383 | OPimContactAccess::DateMonth 381 | OPimContactAccess::DateMonth
384 | OPimContactAccess::DateDay 382 | OPimContactAccess::DateDay
385 ); 383 );
@@ -514,241 +512,239 @@ bool OPimContactAccessBackend_XML::reload(){
514 /* Reload is the same as load in this implementation */ 512 /* Reload is the same as load in this implementation */
515 return ( load() ); 513 return ( load() );
516} 514}
517 515
518void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact ) 516void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact )
519{ 517{
520 OPimContact* contRef = new OPimContact( newcontact ); 518 OPimContact* contRef = new OPimContact( newcontact );
521 519
522 m_contactList.append ( contRef ); 520 m_contactList.append ( contRef );
523 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); 521 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
524} 522}
525 523
526/* This function loads the xml-database and the journalfile */ 524/* This function loads the xml-database and the journalfile */
527bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal ) 525bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal )
528{ 526{
529 527
530 /* We use the time of the last read to check if the file was 528 /* We use the time of the last read to check if the file was
531 * changed externally. 529 * changed externally.
532 */ 530 */
533 if ( !isJournal ){ 531 if ( !isJournal ){
534 QFileInfo fi( filename ); 532 QFileInfo fi( filename );
535 m_readtime = fi.lastModified (); 533 m_readtime = fi.lastModified ();
536 } 534 }
537 535
538 const int JOURNALACTION = Qtopia::Notes + 1; 536 const int JOURNALACTION = Qtopia::Notes + 1;
539 const int JOURNALROW = JOURNALACTION + 1; 537 const int JOURNALROW = JOURNALACTION + 1;
540 538
541 bool foundAction = false; 539 bool foundAction = false;
542 journal_action action = ACTION_ADD; 540 journal_action action = ACTION_ADD;
543 int journalKey = 0; 541 int journalKey = 0;
544 QMap<int, QString> contactMap; 542 QMap<int, QString> contactMap;
545 QMap<QString, QString> customMap; 543 QMap<QString, QString> customMap;
546 QMap<QString, QString>::Iterator customIt; 544 QMap<QString, QString>::Iterator customIt;
547 QAsciiDict<int> dict( 47 ); 545 QAsciiDict<int> dict( 47 );
548 546
549 dict.setAutoDelete( TRUE ); 547 dict.setAutoDelete( TRUE );
550 dict.insert( "Uid", new int(Qtopia::AddressUid) ); 548 dict.insert( "Uid", new int(Qtopia::AddressUid) );
551 dict.insert( "Title", new int(Qtopia::Title) ); 549 dict.insert( "Title", new int(Qtopia::Title) );
552 dict.insert( "FirstName", new int(Qtopia::FirstName) ); 550 dict.insert( "FirstName", new int(Qtopia::FirstName) );
553 dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); 551 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
554 dict.insert( "LastName", new int(Qtopia::LastName) ); 552 dict.insert( "LastName", new int(Qtopia::LastName) );
555 dict.insert( "Suffix", new int(Qtopia::Suffix) ); 553 dict.insert( "Suffix", new int(Qtopia::Suffix) );
556 dict.insert( "FileAs", new int(Qtopia::FileAs) ); 554 dict.insert( "FileAs", new int(Qtopia::FileAs) );
557 dict.insert( "Categories", new int(Qtopia::AddressCategory) ); 555 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
558 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); 556 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
559 dict.insert( "Emails", new int(Qtopia::Emails) ); 557 dict.insert( "Emails", new int(Qtopia::Emails) );
560 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); 558 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
561 dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); 559 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
562 dict.insert( "HomeState", new int(Qtopia::HomeState) ); 560 dict.insert( "HomeState", new int(Qtopia::HomeState) );
563 dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); 561 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
564 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); 562 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
565 dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); 563 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
566 dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); 564 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
567 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); 565 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
568 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); 566 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
569 dict.insert( "Company", new int(Qtopia::Company) ); 567 dict.insert( "Company", new int(Qtopia::Company) );
570 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); 568 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
571 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); 569 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
572 dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); 570 dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
573 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); 571 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
574 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); 572 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
575 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); 573 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
576 dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); 574 dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
577 dict.insert( "Department", new int(Qtopia::Department) ); 575 dict.insert( "Department", new int(Qtopia::Department) );
578 dict.insert( "Office", new int(Qtopia::Office) ); 576 dict.insert( "Office", new int(Qtopia::Office) );
579 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); 577 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
580 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); 578 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
581 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); 579 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
582 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); 580 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
583 dict.insert( "Profession", new int(Qtopia::Profession) ); 581 dict.insert( "Profession", new int(Qtopia::Profession) );
584 dict.insert( "Assistant", new int(Qtopia::Assistant) ); 582 dict.insert( "Assistant", new int(Qtopia::Assistant) );
585 dict.insert( "Manager", new int(Qtopia::Manager) ); 583 dict.insert( "Manager", new int(Qtopia::Manager) );
586 dict.insert( "Spouse", new int(Qtopia::Spouse) ); 584 dict.insert( "Spouse", new int(Qtopia::Spouse) );
587 dict.insert( "Children", new int(Qtopia::Children) ); 585 dict.insert( "Children", new int(Qtopia::Children) );
588 dict.insert( "Gender", new int(Qtopia::Gender) ); 586 dict.insert( "Gender", new int(Qtopia::Gender) );
589 dict.insert( "Birthday", new int(Qtopia::Birthday) ); 587 dict.insert( "Birthday", new int(Qtopia::Birthday) );
590 dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); 588 dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
591 dict.insert( "Nickname", new int(Qtopia::Nickname) ); 589 dict.insert( "Nickname", new int(Qtopia::Nickname) );
592 dict.insert( "Notes", new int(Qtopia::Notes) ); 590 dict.insert( "Notes", new int(Qtopia::Notes) );
593 dict.insert( "action", new int(JOURNALACTION) ); 591 dict.insert( "action", new int(JOURNALACTION) );
594 dict.insert( "actionrow", new int(JOURNALROW) ); 592 dict.insert( "actionrow", new int(JOURNALROW) );
595 593
596 //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl; 594 //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl;
597 595
598 XMLElement *root = XMLElement::load( filename ); 596 XMLElement *root = XMLElement::load( filename );
599 if(root != 0l ){ // start parsing 597 if(root != 0l ){ // start parsing
600 /* Parse all XML-Elements and put the data into the 598 /* Parse all XML-Elements and put the data into the
601 * Contact-Class 599 * Contact-Class
602 */ 600 */
603 XMLElement *element = root->firstChild(); 601 XMLElement *element = root->firstChild();
604 //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl; 602 //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl;
605 element = element->firstChild(); 603 element = element->firstChild();
606 604
607 /* Search Tag "Contacts" which is the parent of all Contacts */ 605 /* Search Tag "Contacts" which is the parent of all Contacts */
608 while( element && !isJournal ){ 606 while( element && !isJournal ){
609 if( element->tagName() != QString::fromLatin1("Contacts") ){ 607 if( element->tagName() != QString::fromLatin1("Contacts") ){
610 //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s", 608 //owarn << "OPimContactDefBack::Searching for Tag \"Contacts\"! Found: "
611 // element->tagName().latin1()); 609 // << element->tagName() << oendl;
612 element = element->nextChild(); 610 element = element->nextChild();
613 } else { 611 } else {
614 element = element->firstChild(); 612 element = element->firstChild();
615 break; 613 break;
616 } 614 }
617 } 615 }
618 /* Parse all Contacts and ignore unknown tags */ 616 /* Parse all Contacts and ignore unknown tags */
619 while( element ){ 617 while( element ){
620 if( element->tagName() != QString::fromLatin1("Contact") ){ 618 if( element->tagName() != QString::fromLatin1("Contact") ){
621 //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s", 619 //owarn << "OPimContactDefBack::Searching for Tag \"Contact\"! Found: "
622 // element->tagName().latin1()); 620 // << element->tagName() << oendl;
623 element = element->nextChild(); 621 element = element->nextChild();
624 continue; 622 continue;
625 } 623 }
626 /* Found alement with tagname "contact", now parse and store all 624 /* Found alement with tagname "contact", now parse and store all
627 * attributes contained 625 * attributes contained
628 */ 626 */
629 //qWarning("OPimContactDefBack::load element tagName() : %s", 627 //owarn << "OPimContactDefBack::load element tagName() : "
630 // element->tagName().latin1() ); 628 // << element->tagName() << oendl;
631 QString dummy; 629 QString dummy;
632 foundAction = false; 630 foundAction = false;
633 631
634 XMLElement::AttributeMap aMap = element->attributes(); 632 XMLElement::AttributeMap aMap = element->attributes();
635 XMLElement::AttributeMap::Iterator it; 633 XMLElement::AttributeMap::Iterator it;
636 contactMap.clear(); 634 contactMap.clear();
637 customMap.clear(); 635 customMap.clear();
638 for( it = aMap.begin(); it != aMap.end(); ++it ){ 636 for( it = aMap.begin(); it != aMap.end(); ++it ){
639 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); 637 // owarn << "Read Attribute: " << it.key() << "=" << it.data() << oendl;
640 638
641 int *find = dict[ it.key() ]; 639 int *find = dict[ it.key() ];
642 /* Unknown attributes will be stored as "Custom" elements */ 640 /* Unknown attributes will be stored as "Custom" elements */
643 if ( !find ) { 641 if ( !find ) {
644 // owarn << "Attribute " << it.key() << " not known." << oendl; 642 // owarn << "Attribute " << it.key() << " not known." << oendl;
645 //contact.setCustomField(it.key(), it.data()); 643 //contact.setCustomField(it.key(), it.data());
646 customMap.insert( it.key(), it.data() ); 644 customMap.insert( it.key(), it.data() );
647 continue; 645 continue;
648 } 646 }
649 647
650 /* Check if special conversion is needed and add attribute 648 /* Check if special conversion is needed and add attribute
651 * into Contact class 649 * into Contact class
652 */ 650 */
653 switch( *find ) { 651 switch( *find ) {
654 /* 652 /*
655 case Qtopia::AddressUid: 653 case Qtopia::AddressUid:
656 contact.setUid( it.data().toInt() ); 654 contact.setUid( it.data().toInt() );
657 break; 655 break;
658 case Qtopia::AddressCategory: 656 case Qtopia::AddressCategory:
659 contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); 657 contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
660 break; 658 break;
661 */ 659 */
662 case JOURNALACTION: 660 case JOURNALACTION:
663 action = journal_action(it.data().toInt()); 661 action = journal_action(it.data().toInt());
664 foundAction = true; 662 foundAction = true;
665 qWarning ("ODefBack(journal)::ACTION found: %d", action); 663 owarn << "ODefBack(journal)::ACTION found: " << action << oendl;
666 break; 664 break;
667 case JOURNALROW: 665 case JOURNALROW:
668 journalKey = it.data().toInt(); 666 journalKey = it.data().toInt();
669 break; 667 break;
670 default: // no conversion needed add them to the map 668 default: // no conversion needed add them to the map
671 contactMap.insert( *find, it.data() ); 669 contactMap.insert( *find, it.data() );
672 break; 670 break;
673 } 671 }
674 } 672 }
675 /* now generate the Contact contact */ 673 /* now generate the Contact contact */
676 OPimContact contact( contactMap ); 674 OPimContact contact( contactMap );
677 675
678 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { 676 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
679 contact.setCustomField( customIt.key(), customIt.data() ); 677 contact.setCustomField( customIt.key(), customIt.data() );
680 } 678 }
681 679
682 if (foundAction){ 680 if (foundAction){
683 foundAction = false; 681 foundAction = false;
684 switch ( action ) { 682 switch ( action ) {
685 case ACTION_ADD: 683 case ACTION_ADD:
686 addContact_p (contact); 684 addContact_p (contact);
687 break; 685 break;
688 case ACTION_REMOVE: 686 case ACTION_REMOVE:
689 if ( !remove (contact.uid()) ) 687 if ( !remove (contact.uid()) )
690 qWarning ("ODefBack(journal)::Unable to remove uid: %d", 688 owarn << "ODefBack(journal)::Unable to remove uid: " << contact.uid() << oendl;
691 contact.uid() );
692 break; 689 break;
693 case ACTION_REPLACE: 690 case ACTION_REPLACE:
694 if ( !replace ( contact ) ) 691 if ( !replace ( contact ) )
695 qWarning ("ODefBack(journal)::Unable to replace uid: %d", 692 owarn << "ODefBack(journal)::Unable to replace uid: " << contact.uid() << oendl;
696 contact.uid() );
697 break; 693 break;
698 default: 694 default:
699 qWarning ("Unknown action: ignored !"); 695 owarn << "Unknown action: ignored !" << oendl;
700 break; 696 break;
701 } 697 }
702 }else{ 698 }else{
703 /* Add contact to list */ 699 /* Add contact to list */
704 addContact_p (contact); 700 addContact_p (contact);
705 } 701 }
706 702
707 /* Move to next element */ 703 /* Move to next element */
708 element = element->nextChild(); 704 element = element->nextChild();
709 } 705 }
710 }else { 706 }else {
711 owarn << "ODefBack::could not load" << oendl; 707 owarn << "ODefBack::could not load" << oendl;
712 } 708 }
713 delete root; 709 delete root;
714 owarn << "returning from loading" << oendl; 710 owarn << "returning from loading" << oendl;
715 return true; 711 return true;
716} 712}
717 713
718 714
719void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt, 715void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt,
720 journal_action action ) 716 journal_action action )
721{ 717{
722 QFile f( m_journalName ); 718 QFile f( m_journalName );
723 bool created = !f.exists(); 719 bool created = !f.exists();
724 if ( !f.open(IO_WriteOnly|IO_Append) ) 720 if ( !f.open(IO_WriteOnly|IO_Append) )
725 return; 721 return;
726 722
727 QString buf; 723 QString buf;
728 QCString str; 724 QCString str;
729 725
730 // if the file was created, we have to set the Tag "<CONTACTS>" to 726 // if the file was created, we have to set the Tag "<CONTACTS>" to
731 // get a XML-File which is readable by our parser. 727 // get a XML-File which is readable by our parser.
732 // This is just a cheat, but better than rewrite the parser. 728 // This is just a cheat, but better than rewrite the parser.
733 if ( created ){ 729 if ( created ){
734 buf = "<Contacts>"; 730 buf = "<Contacts>";
735 QCString cstr = buf.utf8(); 731 QCString cstr = buf.utf8();
736 f.writeBlock( cstr.data(), cstr.length() ); 732 f.writeBlock( cstr.data(), cstr.length() );
737 } 733 }
738 734
739 buf = "<Contact "; 735 buf = "<Contact ";
740 cnt.save( buf ); 736 cnt.save( buf );
741 buf += " action=\"" + QString::number( (int)action ) + "\" "; 737 buf += " action=\"" + QString::number( (int)action ) + "\" ";
742 buf += "/>\n"; 738 buf += "/>\n";
743 QCString cstr = buf.utf8(); 739 QCString cstr = buf.utf8();
744 f.writeBlock( cstr.data(), cstr.length() ); 740 f.writeBlock( cstr.data(), cstr.length() );
745} 741}
746 742
747void OPimContactAccessBackend_XML::removeJournal() 743void OPimContactAccessBackend_XML::removeJournal()
748{ 744{
749 QFile f ( m_journalName ); 745 QFile f ( m_journalName );
750 if ( f.exists() ) 746 if ( f.exists() )
751 f.remove(); 747 f.remove();
752} 748}
753 749
754} 750}
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index a372267..7a3d7cb 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,159 +1,164 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: XML-Backend: Automatic reload if something was changed... 31 * ToDo: XML-Backend: Automatic reload if something was changed...
32 * 32 *
33 * 33 *
34 */ 34 */
35 35
36#include "ocontactaccess.h" 36#include "ocontactaccess.h"
37#include "obackendfactory.h" 37#include "obackendfactory.h"
38 38
39/* OPIE */
40#include <opie2/ocontactaccessbackend_xml.h>
41#include <opie2/opimresolver.h>
42#include <opie2/opimglobal.h>
43#include <opie2/odebug.h>
44
45//#include <qpe/qcopenvelope_qws.h>
46#include <qpe/global.h>
47
48/* QT */
39#include <qasciidict.h> 49#include <qasciidict.h>
40#include <qdatetime.h> 50#include <qdatetime.h>
41#include <qfile.h> 51#include <qfile.h>
42#include <qregexp.h> 52#include <qregexp.h>
43#include <qlist.h> 53#include <qlist.h>
44#include <qcopchannel_qws.h> 54#include <qcopchannel_qws.h>
45 55
46//#include <qpe/qcopenvelope_qws.h> 56/* STD */
47#include <qpe/global.h>
48
49#include <errno.h> 57#include <errno.h>
50#include <fcntl.h> 58#include <fcntl.h>
51#include <unistd.h> 59#include <unistd.h>
52#include <stdlib.h> 60#include <stdlib.h>
53 61
54#include <opie2/ocontactaccessbackend_xml.h>
55#include <opie2/opimresolver.h>
56#include <opie2/opimglobal.h>
57 62
58namespace Opie { 63namespace Opie {
59 64
60OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 65OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
61 OPimContactAccessBackend* end, bool autosync ): 66 OPimContactAccessBackend* end, bool autosync ):
62 OPimAccessTemplate<OPimContact>( end ) 67 OPimAccessTemplate<OPimContact>( end )
63{ 68{
64 /* take care of the backend. If there is no one defined, we 69 /* take care of the backend. If there is no one defined, we
65 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 70 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
66 */ 71 */
67 if( end == 0 ) { 72 if( end == 0 ) {
68 qWarning ("Using BackendFactory !"); 73 owarn << "Using BackendFactory !" << oendl;
69 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); 74 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
70 } 75 }
71 // Set backend locally and in template 76 // Set backend locally and in template
72 m_backEnd = end; 77 m_backEnd = end;
73 OPimAccessTemplate<OPimContact>::setBackEnd (end); 78 OPimAccessTemplate<OPimContact>::setBackEnd (end);
74 79
75 80
76 /* Connect signal of external db change to function */ 81 /* Connect signal of external db change to function */
77 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 82 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
78 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), 83 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
79 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 84 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
80 if ( autosync ){ 85 if ( autosync ){
81 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 86 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
82 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), 87 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
83 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 88 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
84 } 89 }
85 90
86 91
87} 92}
88OPimContactAccess::~OPimContactAccess () 93OPimContactAccess::~OPimContactAccess ()
89{ 94{
90 /* The user may forget to save the changed database, therefore try to 95 /* The user may forget to save the changed database, therefore try to
91 * do it for him.. 96 * do it for him..
92 */ 97 */
93 save(); 98 save();
94 // delete m_backEnd; is done by template.. 99 // delete m_backEnd; is done by template..
95} 100}
96 101
97 102
98bool OPimContactAccess::save () 103bool OPimContactAccess::save ()
99{ 104{
100 /* If the database was changed externally, we could not save the 105 /* If the database was changed externally, we could not save the
101 * Data. This will remove added items which is unacceptable ! 106 * Data. This will remove added items which is unacceptable !
102 * Therefore: Reload database and merge the data... 107 * Therefore: Reload database and merge the data...
103 */ 108 */
104 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) 109 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() )
105 reload(); 110 reload();
106 111
107 bool status = OPimAccessTemplate<OPimContact>::save(); 112 bool status = OPimAccessTemplate<OPimContact>::save();
108 if ( !status ) return false; 113 if ( !status ) return false;
109 114
110 /* Now tell everyone that new data is available. 115 /* Now tell everyone that new data is available.
111 */ 116 */
112 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); 117 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
113 118
114 return true; 119 return true;
115} 120}
116 121
117const uint OPimContactAccess::querySettings() 122const uint OPimContactAccess::querySettings()
118{ 123{
119 return ( m_backEnd->querySettings() ); 124 return ( m_backEnd->querySettings() );
120} 125}
121 126
122bool OPimContactAccess::hasQuerySettings ( int querySettings ) const 127bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
123{ 128{
124 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 129 return ( m_backEnd->hasQuerySettings ( querySettings ) );
125} 130}
126OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 131OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
127{ 132{
128 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); 133 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
129 return ( OPimRecordList<OPimContact>(matchingContacts, this) ); 134 return ( OPimRecordList<OPimContact>(matchingContacts, this) );
130} 135}
131 136
132 137
133bool OPimContactAccess::wasChangedExternally()const 138bool OPimContactAccess::wasChangedExternally()const
134{ 139{
135 return ( m_backEnd->wasChangedExternally() ); 140 return ( m_backEnd->wasChangedExternally() );
136} 141}
137 142
138 143
139void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) 144void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
140{ 145{
141 if ( msg == "addressbookUpdated()" ){ 146 if ( msg == "addressbookUpdated()" ){
142 qWarning ("OPimContactAccess: Received addressbokUpdated()"); 147 owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl;
143 emit signalChanged ( this ); 148 emit signalChanged ( this );
144 } else if ( msg == "flush()" ) { 149 } else if ( msg == "flush()" ) {
145 qWarning ("OPimContactAccess: Received flush()"); 150 owarn << "OPimContactAccess: Received flush()" << oendl;
146 save (); 151 save ();
147 } else if ( msg == "reload()" ) { 152 } else if ( msg == "reload()" ) {
148 qWarning ("OPimContactAccess: Received reload()"); 153 owarn << "OPimContactAccess: Received reload()" << oendl;
149 reload (); 154 reload ();
150 emit signalChanged ( this ); 155 emit signalChanged ( this );
151 } 156 }
152} 157}
153 158
154int OPimContactAccess::rtti() const 159int OPimContactAccess::rtti() const
155{ 160{
156 return OPimResolver::AddressBook; 161 return OPimResolver::AddressBook;
157} 162}
158 163
159} 164}
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index e438980..55d600a 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,357 +1,360 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Holger Freyther <zecke@handhelds.org> 3 Copyright (C) Holger Freyther <zecke@handhelds.org>
4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
6 .=l. 6 .=l.
7 .>+-= 7 .>+-=
8 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
9.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
11.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
12 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
13 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
14 .%`+i> _;_. 14 .%`+i> _;_.
15 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
17 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
21++= -. .` .: details. 21++= -. .` .: details.
22 : = ...= . :.=- 22 : = ...= . :.=-
23 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
24 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
25 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
31#define OPIE_PIM_ACCESS_TEMPLATE_H 31#define OPIE_PIM_ACCESS_TEMPLATE_H
32 32
33#include <qarray.h> 33/* OPIE */
34
35#include <opie2/opimrecord.h> 34#include <opie2/opimrecord.h>
36#include <opie2/opimaccessbackend.h> 35#include <opie2/opimaccessbackend.h>
37#include <opie2/opimrecordlist.h> 36#include <opie2/opimrecordlist.h>
38 37
39#include <opie2/opimcache.h> 38#include <opie2/opimcache.h>
40#include <opie2/opimtemplatebase.h> 39#include <opie2/opimtemplatebase.h>
40#include <opie2/odebug.h>
41
42/* QT */
43#include <qarray.h>
41 44
42namespace Opie { 45namespace Opie {
43 46
44class OPimAccessTemplatePrivate; 47class OPimAccessTemplatePrivate;
45/** 48/**
46 * Thats the frontend to our OPIE PIM 49 * Thats the frontend to our OPIE PIM
47 * Library. Either you want to use it's 50 * Library. Either you want to use it's
48 * interface or you want to implement 51 * interface or you want to implement
49 * your own Access lib 52 * your own Access lib
50 * Just create a OPimRecord and inherit from 53 * Just create a OPimRecord and inherit from
51 * the templates 54 * the templates
52 */ 55 */
53 56
54template <class T = OPimRecord > 57template <class T = OPimRecord >
55class OPimAccessTemplate : public OTemplateBase<T> { 58class OPimAccessTemplate : public OTemplateBase<T> {
56public: 59public:
57 enum Access { 60 enum Access {
58 Random = 0, 61 Random = 0,
59 SortedAccess 62 SortedAccess
60 }; 63 };
61 typedef OPimRecordList<T> List; 64 typedef OPimRecordList<T> List;
62 typedef OPimAccessBackend<T> BackEnd; 65 typedef OPimAccessBackend<T> BackEnd;
63 typedef OPimCache<T> Cache; 66 typedef OPimCache<T> Cache;
64 67
65 /** 68 /**
66 * c'tor BackEnd 69 * c'tor BackEnd
67 * enum Access a small hint on how to handle the backend 70 * enum Access a small hint on how to handle the backend
68 */ 71 */
69 OPimAccessTemplate( BackEnd* end); 72 OPimAccessTemplate( BackEnd* end);
70 73
71 virtual ~OPimAccessTemplate(); 74 virtual ~OPimAccessTemplate();
72 75
73 /** 76 /**
74 * load from the backend 77 * load from the backend
75 */ 78 */
76 bool load(); 79 bool load();
77 80
78 /** Reload database. 81 /** Reload database.
79 * You should execute this function if the external database 82 * You should execute this function if the external database
80 * was changed. 83 * was changed.
81 * This function will load the external database and afterwards 84 * This function will load the external database and afterwards
82 * rejoin the local changes. Therefore the local database will be set consistent. 85 * rejoin the local changes. Therefore the local database will be set consistent.
83 */ 86 */
84 virtual bool reload(); 87 virtual bool reload();
85 88
86 /** Save contacts database. 89 /** Save contacts database.
87 * Save is more a "commit". After calling this function, all changes are public available. 90 * Save is more a "commit". After calling this function, all changes are public available.
88 * @return true if successful 91 * @return true if successful
89 */ 92 */
90 bool save(); 93 bool save();
91 94
92 /** 95 /**
93 * if the resource was changed externally 96 * if the resource was changed externally
94 * You should use the signal handling instead of polling possible changes ! 97 * You should use the signal handling instead of polling possible changes !
95 * zecke: Do you implement a signal for otodoaccess ? 98 * zecke: Do you implement a signal for otodoaccess ?
96 */ 99 */
97 bool wasChangedExternally()const; 100 bool wasChangedExternally()const;
98 101
99 /** 102 /**
100 * return a List of records 103 * return a List of records
101 * you can iterate over them 104 * you can iterate over them
102 */ 105 */
103 virtual List allRecords()const; 106 virtual List allRecords()const;
104 107
105 /** 108 /**
106 * return a List of records 109 * return a List of records
107 * that match the regex 110 * that match the regex
108 */ 111 */
109 virtual List matchRegexp( const QRegExp &r ) const; 112 virtual List matchRegexp( const QRegExp &r ) const;
110 113
111 /** 114 /**
112 * queryByExample. 115 * queryByExample.
113 * @see otodoaccess, ocontactaccess 116 * @see otodoaccess, ocontactaccess
114 */ 117 */
115 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); 118 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
116 119
117 /** 120 /**
118 * find the OPimRecord uid 121 * find the OPimRecord uid
119 */ 122 */
120 virtual T find( int uid )const; 123 virtual T find( int uid )const;
121 124
122 /** 125 /**
123 * read ahead cache find method ;) 126 * read ahead cache find method ;)
124 */ 127 */
125 virtual T find( int uid, const QArray<int>&, 128 virtual T find( int uid, const QArray<int>&,
126 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 129 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
127 130
128 /* invalidate cache here */ 131 /* invalidate cache here */
129 /** 132 /**
130 * clears the backend and invalidates the backend 133 * clears the backend and invalidates the backend
131 */ 134 */
132 void clear() ; 135 void clear() ;
133 136
134 /** 137 /**
135 * add T to the backend 138 * add T to the backend
136 * @param t The item to add. 139 * @param t The item to add.
137 * @return <i>true</i> if added successfully. 140 * @return <i>true</i> if added successfully.
138 */ 141 */
139 virtual bool add( const T& t ) ; 142 virtual bool add( const T& t ) ;
140 bool add( const OPimRecord& ); 143 bool add( const OPimRecord& );
141 // Needed for real generic access (eilers) 144 // Needed for real generic access (eilers)
142 // Info: Take this if you are working with OPimRecord, which is a generic base class, and 145 // Info: Take this if you are working with OPimRecord, which is a generic base class, and
143 // you need to add it into any database, you cannot generate a reference to 146 // you need to add it into any database, you cannot generate a reference to
144 // it and casting may be not approriate, too. 147 // it and casting may be not approriate, too.
145 // But take care that the accessing database is compatible to the real type of OPimRecord !! 148 // But take care that the accessing database is compatible to the real type of OPimRecord !!
146 bool add( const OPimRecord* ); 149 bool add( const OPimRecord* );
147 150
148 151
149 /* only the uid matters */ 152 /* only the uid matters */
150 /** 153 /**
151 * remove T from the backend 154 * remove T from the backend
152 * @param t The item to remove 155 * @param t The item to remove
153 * @return <i>true</i> if successful. 156 * @return <i>true</i> if successful.
154 */ 157 */
155 virtual bool remove( const T& t ); 158 virtual bool remove( const T& t );
156 159
157 /** 160 /**
158 * remove the OPimRecord with uid 161 * remove the OPimRecord with uid
159 * @param uid The ID of the item to remove 162 * @param uid The ID of the item to remove
160 * @return <i>true</i> if successful. 163 * @return <i>true</i> if successful.
161 */ 164 */
162 bool remove( int uid ); 165 bool remove( int uid );
163 bool remove( const OPimRecord& ); 166 bool remove( const OPimRecord& );
164 167
165 /** 168 /**
166 * replace T from backend 169 * replace T from backend
167 * @param t The item to replace 170 * @param t The item to replace
168 * @return <i>true</i> if successful. 171 * @return <i>true</i> if successful.
169 */ 172 */
170 virtual bool replace( const T& t) ; 173 virtual bool replace( const T& t) ;
171 174
172 void setReadAhead( uint count ); 175 void setReadAhead( uint count );
173 /** 176 /**
174 * @internal 177 * @internal
175 */ 178 */
176 void cache( const T& )const; 179 void cache( const T& )const;
177 void setSaneCacheSize( int ); 180 void setSaneCacheSize( int );
178 181
179 QArray<int> records()const; 182 QArray<int> records()const;
180protected: 183protected:
181 /** 184 /**
182 * invalidate the cache 185 * invalidate the cache
183 */ 186 */
184 void invalidateCache(); 187 void invalidateCache();
185 188
186 void setBackEnd( BackEnd* end ); 189 void setBackEnd( BackEnd* end );
187 /** 190 /**
188 * returns the backend 191 * returns the backend
189 */ 192 */
190 BackEnd* backEnd(); 193 BackEnd* backEnd();
191 BackEnd* m_backEnd; 194 BackEnd* m_backEnd;
192 Cache m_cache; 195 Cache m_cache;
193 196
194private: 197private:
195 OPimAccessTemplatePrivate *d; 198 OPimAccessTemplatePrivate *d;
196 199
197}; 200};
198 201
199template <class T> 202template <class T>
200OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 203OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
201 : OTemplateBase<T>(), m_backEnd( end ) 204 : OTemplateBase<T>(), m_backEnd( end )
202{ 205{
203 if (end ) 206 if (end )
204 end->setFrontend( this ); 207 end->setFrontend( this );
205} 208}
206template <class T> 209template <class T>
207OPimAccessTemplate<T>::~OPimAccessTemplate() { 210OPimAccessTemplate<T>::~OPimAccessTemplate() {
208 qWarning("~OPimAccessTemplate<T>"); 211 owarn << "~OPimAccessTemplate<T>" << oendl;
209 delete m_backEnd; 212 delete m_backEnd;
210} 213}
211template <class T> 214template <class T>
212bool OPimAccessTemplate<T>::load() { 215bool OPimAccessTemplate<T>::load() {
213 invalidateCache(); 216 invalidateCache();
214 return m_backEnd->load(); 217 return m_backEnd->load();
215} 218}
216template <class T> 219template <class T>
217bool OPimAccessTemplate<T>::reload() { 220bool OPimAccessTemplate<T>::reload() {
218 invalidateCache(); // zecke: I think this should be added (se) 221 invalidateCache(); // zecke: I think this should be added (se)
219 return m_backEnd->reload(); 222 return m_backEnd->reload();
220} 223}
221template <class T> 224template <class T>
222bool OPimAccessTemplate<T>::save() { 225bool OPimAccessTemplate<T>::save() {
223 return m_backEnd->save(); 226 return m_backEnd->save();
224} 227}
225template <class T> 228template <class T>
226typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 229typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
227 QArray<int> ints = m_backEnd->allRecords(); 230 QArray<int> ints = m_backEnd->allRecords();
228 List lis(ints, this ); 231 List lis(ints, this );
229 return lis; 232 return lis;
230} 233}
231template <class T> 234template <class T>
232typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { 235typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
233 QArray<int> ints = m_backEnd->matchRegexp( r ); 236 QArray<int> ints = m_backEnd->matchRegexp( r );
234 List lis(ints, this ); 237 List lis(ints, this );
235 return lis; 238 return lis;
236} 239}
237template <class T> 240template <class T>
238QArray<int> OPimAccessTemplate<T>::records()const { 241QArray<int> OPimAccessTemplate<T>::records()const {
239 return m_backEnd->allRecords(); 242 return m_backEnd->allRecords();
240} 243}
241template <class T> 244template <class T>
242typename OPimAccessTemplate<T>::List 245typename OPimAccessTemplate<T>::List
243OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 246OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
244 QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); 247 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
245 248
246 List lis(ints, this ); 249 List lis(ints, this );
247 return lis; 250 return lis;
248} 251}
249template <class T> 252template <class T>
250T OPimAccessTemplate<T>::find( int uid ) const{ 253T OPimAccessTemplate<T>::find( int uid ) const{
251 T t = m_backEnd->find( uid ); 254 T t = m_backEnd->find( uid );
252 cache( t ); 255 cache( t );
253 return t; 256 return t;
254} 257}
255template <class T> 258template <class T>
256T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 259T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
257 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 260 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
258 /* 261 /*
259 * better do T.isEmpty() 262 * better do T.isEmpty()
260 * after a find this way we would 263 * after a find this way we would
261 * avoid two finds in QCache... 264 * avoid two finds in QCache...
262 */ 265 */
263 // qWarning("find it now %d", uid ); 266 // owarn << "find it now " << uid << oendl;
264 if (m_cache.contains( uid ) ) { 267 if (m_cache.contains( uid ) ) {
265 return m_cache.find( uid ); 268 return m_cache.find( uid );
266 } 269 }
267 270
268 T t = m_backEnd->find( uid, ar, current, dir ); 271 T t = m_backEnd->find( uid, ar, current, dir );
269 cache( t ); 272 cache( t );
270 return t; 273 return t;
271} 274}
272template <class T> 275template <class T>
273void OPimAccessTemplate<T>::clear() { 276void OPimAccessTemplate<T>::clear() {
274 invalidateCache(); 277 invalidateCache();
275 m_backEnd->clear(); 278 m_backEnd->clear();
276} 279}
277template <class T> 280template <class T>
278bool OPimAccessTemplate<T>::add( const T& t ) { 281bool OPimAccessTemplate<T>::add( const T& t ) {
279 cache( t ); 282 cache( t );
280 return m_backEnd->add( t ); 283 return m_backEnd->add( t );
281} 284}
282 285
283template <class T> 286template <class T>
284bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 287bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
285 /* same type */ 288 /* same type */
286 T tempInstance; 289 T tempInstance;
287 if ( rec.rtti() == tempInstance.rtti() ) { 290 if ( rec.rtti() == tempInstance.rtti() ) {
288 const T& t = static_cast<const T&>(rec); 291 const T& t = static_cast<const T&>(rec);
289 return add(t); 292 return add(t);
290 } 293 }
291 return false; 294 return false;
292} 295}
293 296
294template <class T> 297template <class T>
295bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { 298bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
296 /* same type, but pointer */ 299 /* same type, but pointer */
297 T tempInstance; 300 T tempInstance;
298 if ( rec -> rtti() == tempInstance.rtti() ) { 301 if ( rec -> rtti() == tempInstance.rtti() ) {
299 const T* t = static_cast<const T*>(rec); 302 const T* t = static_cast<const T*>(rec);
300 return add( *t ); 303 return add( *t );
301 } 304 }
302 return false; 305 return false;
303} 306}
304 307
305template <class T> 308template <class T>
306bool OPimAccessTemplate<T>::remove( const T& t ) { 309bool OPimAccessTemplate<T>::remove( const T& t ) {
307 return remove( t.uid() ); 310 return remove( t.uid() );
308} 311}
309template <class T> 312template <class T>
310bool OPimAccessTemplate<T>::remove( int uid ) { 313bool OPimAccessTemplate<T>::remove( int uid ) {
311 m_cache.remove( uid ); 314 m_cache.remove( uid );
312 return m_backEnd->remove( uid ); 315 return m_backEnd->remove( uid );
313} 316}
314template <class T> 317template <class T>
315bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 318bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
316 return remove( rec.uid() ); 319 return remove( rec.uid() );
317} 320}
318template <class T> 321template <class T>
319bool OPimAccessTemplate<T>::replace( const T& t ) { 322bool OPimAccessTemplate<T>::replace( const T& t ) {
320 m_cache.replace( t ); 323 m_cache.replace( t );
321 return m_backEnd->replace( t ); 324 return m_backEnd->replace( t );
322} 325}
323template <class T> 326template <class T>
324void OPimAccessTemplate<T>::invalidateCache() { 327void OPimAccessTemplate<T>::invalidateCache() {
325 m_cache.invalidate(); 328 m_cache.invalidate();
326} 329}
327template <class T> 330template <class T>
328typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 331typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
329 return m_backEnd; 332 return m_backEnd;
330} 333}
331template <class T> 334template <class T>
332bool OPimAccessTemplate<T>::wasChangedExternally()const { 335bool OPimAccessTemplate<T>::wasChangedExternally()const {
333 return false; 336 return false;
334} 337}
335template <class T> 338template <class T>
336void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 339void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
337 m_backEnd = end; 340 m_backEnd = end;
338 if (m_backEnd ) 341 if (m_backEnd )
339 m_backEnd->setFrontend( this ); 342 m_backEnd->setFrontend( this );
340} 343}
341template <class T> 344template <class T>
342void OPimAccessTemplate<T>::cache( const T& t ) const{ 345void OPimAccessTemplate<T>::cache( const T& t ) const{
343 /* hacky we need to work around the const*/ 346 /* hacky we need to work around the const*/
344 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 347 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
345} 348}
346template <class T> 349template <class T>
347void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 350void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
348 m_cache.setSize( size ); 351 m_cache.setSize( size );
349} 352}
350template <class T> 353template <class T>
351void OPimAccessTemplate<T>::setReadAhead( uint count ) { 354void OPimAccessTemplate<T>::setReadAhead( uint count ) {
352 m_backEnd->setReadAhead( count ); 355 m_backEnd->setReadAhead( count );
353} 356}
354 357
355} 358}
356 359
357#endif 360#endif
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index 48a74d0..36e9a93 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -1080,208 +1080,208 @@ void OPimContact::setEmails( const QString &str )
1080 Sets the list of children for the contact to those contained in \a str. 1080 Sets the list of children for the contact to those contained in \a str.
1081*/ 1081*/
1082void OPimContact::setChildren( const QString &str ) 1082void OPimContact::setChildren( const QString &str )
1083{ 1083{
1084 replace( Qtopia::Children, str ); 1084 replace( Qtopia::Children, str );
1085} 1085}
1086 1086
1087/*! 1087/*!
1088 \overload 1088 \overload
1089 Returns TRUE if the contact matches the regular expression \a regexp. 1089 Returns TRUE if the contact matches the regular expression \a regexp.
1090 Otherwise returns FALSE. 1090 Otherwise returns FALSE.
1091*/ 1091*/
1092bool OPimContact::match( const QRegExp &r ) const 1092bool OPimContact::match( const QRegExp &r ) const
1093{ 1093{
1094 setLastHitField( -1 ); 1094 setLastHitField( -1 );
1095 bool match; 1095 bool match;
1096 match = false; 1096 match = false;
1097 QMap<int, QString>::ConstIterator it; 1097 QMap<int, QString>::ConstIterator it;
1098 for ( it = mMap.begin(); it != mMap.end(); ++it ) 1098 for ( it = mMap.begin(); it != mMap.end(); ++it )
1099 { 1099 {
1100 if ( ( *it ).find( r ) > -1 ) 1100 if ( ( *it ).find( r ) > -1 )
1101 { 1101 {
1102 setLastHitField( it.key() ); 1102 setLastHitField( it.key() );
1103 match = true; 1103 match = true;
1104 break; 1104 break;
1105 } 1105 }
1106 } 1106 }
1107 return match; 1107 return match;
1108} 1108}
1109 1109
1110 1110
1111QString OPimContact::toShortText() const 1111QString OPimContact::toShortText() const
1112{ 1112{
1113 return ( fullName() ); 1113 return ( fullName() );
1114} 1114}
1115 1115
1116 1116
1117QString OPimContact::type() const 1117QString OPimContact::type() const
1118{ 1118{
1119 return QString::fromLatin1( "OPimContact" ); 1119 return QString::fromLatin1( "OPimContact" );
1120} 1120}
1121 1121
1122 1122
1123class QString OPimContact::recordField( int pos ) const 1123class QString OPimContact::recordField( int pos ) const
1124{ 1124{
1125 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1125 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1126 return SLFIELDS[ pos ]; 1126 return SLFIELDS[ pos ];
1127} 1127}
1128 1128
1129// In future releases, we should store birthday and anniversary 1129// In future releases, we should store birthday and anniversary
1130// internally as QDate instead of QString ! 1130// internally as QDate instead of QString !
1131// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1131// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1132 1132
1133/*! \fn void OPimContact::setBirthday( const QDate& date ) 1133/*! \fn void OPimContact::setBirthday( const QDate& date )
1134 Sets the birthday for the contact to \a date. If date is null 1134 Sets the birthday for the contact to \a date. If date is null
1135 the current stored date will be removed. 1135 the current stored date will be removed.
1136*/ 1136*/
1137void OPimContact::setBirthday( const QDate &v ) 1137void OPimContact::setBirthday( const QDate &v )
1138{ 1138{
1139 if ( v.isNull() ) 1139 if ( v.isNull() )
1140 { 1140 {
1141 owarn << "Remove Birthday" << oendl; 1141 owarn << "Remove Birthday" << oendl;
1142 replace( Qtopia::Birthday, QString::null ); 1142 replace( Qtopia::Birthday, QString::null );
1143 return ; 1143 return ;
1144 } 1144 }
1145 1145
1146 if ( v.isValid() ) 1146 if ( v.isValid() )
1147 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) ); 1147 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
1148 1148
1149} 1149}
1150 1150
1151 1151
1152/*! \fn void OPimContact::setAnniversary( const QDate &date ) 1152/*! \fn void OPimContact::setAnniversary( const QDate &date )
1153 Sets the anniversary of the contact to \a date. If date is 1153 Sets the anniversary of the contact to \a date. If date is
1154 null, the current stored date will be removed. 1154 null, the current stored date will be removed.
1155*/ 1155*/
1156void OPimContact::setAnniversary( const QDate &v ) 1156void OPimContact::setAnniversary( const QDate &v )
1157{ 1157{
1158 if ( v.isNull() ) 1158 if ( v.isNull() )
1159 { 1159 {
1160 owarn << "Remove Anniversary" << oendl; 1160 owarn << "Remove Anniversary" << oendl;
1161 replace( Qtopia::Anniversary, QString::null ); 1161 replace( Qtopia::Anniversary, QString::null );
1162 return ; 1162 return ;
1163 } 1163 }
1164 1164
1165 if ( v.isValid() ) 1165 if ( v.isValid() )
1166 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) ); 1166 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
1167} 1167}
1168 1168
1169 1169
1170/*! \fn QDate OPimContact::birthday() const 1170/*! \fn QDate OPimContact::birthday() const
1171 Returns the birthday of the contact. 1171 Returns the birthday of the contact.
1172*/ 1172*/
1173QDate OPimContact::birthday() const 1173QDate OPimContact::birthday() const
1174{ 1174{
1175 QString str = find( Qtopia::Birthday ); 1175 QString str = find( Qtopia::Birthday );
1176 // qWarning ("Birthday %s", str.latin1() ); 1176 // owarn << "Birthday " << str << oendl;
1177 if ( !str.isEmpty() ) 1177 if ( !str.isEmpty() )
1178 return OPimDateConversion::dateFromString ( str ); 1178 return OPimDateConversion::dateFromString ( str );
1179 else 1179 else
1180 return QDate(); 1180 return QDate();
1181} 1181}
1182 1182
1183 1183
1184/*! \fn QDate OPimContact::anniversary() const 1184/*! \fn QDate OPimContact::anniversary() const
1185 Returns the anniversary of the contact. 1185 Returns the anniversary of the contact.
1186*/ 1186*/
1187QDate OPimContact::anniversary() const 1187QDate OPimContact::anniversary() const
1188{ 1188{
1189 QDate empty; 1189 QDate empty;
1190 QString str = find( Qtopia::Anniversary ); 1190 QString str = find( Qtopia::Anniversary );
1191 // qWarning ("Anniversary %s", str.latin1() ); 1191 // owarn << "Anniversary " << str << oendl;
1192 if ( !str.isEmpty() ) 1192 if ( !str.isEmpty() )
1193 return OPimDateConversion::dateFromString ( str ); 1193 return OPimDateConversion::dateFromString ( str );
1194 else 1194 else
1195 return empty; 1195 return empty;
1196} 1196}
1197 1197
1198 1198
1199void OPimContact::insertEmail( const QString &v ) 1199void OPimContact::insertEmail( const QString &v )
1200{ 1200{
1201 //odebug << "insertEmail " << v << "" << oendl; 1201 //odebug << "insertEmail " << v << "" << oendl;
1202 QString e = v.simplifyWhiteSpace(); 1202 QString e = v.simplifyWhiteSpace();
1203 QString def = defaultEmail(); 1203 QString def = defaultEmail();
1204 1204
1205 // if no default, set it as the default email and don't insert 1205 // if no default, set it as the default email and don't insert
1206 if ( def.isEmpty() ) 1206 if ( def.isEmpty() )
1207 { 1207 {
1208 setDefaultEmail( e ); // will insert into the list for us 1208 setDefaultEmail( e ); // will insert into the list for us
1209 return ; 1209 return ;
1210 } 1210 }
1211 1211
1212 // otherwise, insert assuming doesn't already exist 1212 // otherwise, insert assuming doesn't already exist
1213 QString emailsStr = find( Qtopia::Emails ); 1213 QString emailsStr = find( Qtopia::Emails );
1214 if ( emailsStr.contains( e ) ) 1214 if ( emailsStr.contains( e ) )
1215 return ; 1215 return ;
1216 if ( !emailsStr.isEmpty() ) 1216 if ( !emailsStr.isEmpty() )
1217 emailsStr += emailSeparator(); 1217 emailsStr += emailSeparator();
1218 emailsStr += e; 1218 emailsStr += e;
1219 replace( Qtopia::Emails, emailsStr ); 1219 replace( Qtopia::Emails, emailsStr );
1220} 1220}
1221 1221
1222 1222
1223 void OPimContact::removeEmail( const QString &v ) 1223 void OPimContact::removeEmail( const QString &v )
1224{ 1224{
1225 QString e = v.simplifyWhiteSpace(); 1225 QString e = v.simplifyWhiteSpace();
1226 QString def = defaultEmail(); 1226 QString def = defaultEmail();
1227 QString emailsStr = find( Qtopia::Emails ); 1227 QString emailsStr = find( Qtopia::Emails );
1228 QStringList emails = emailList(); 1228 QStringList emails = emailList();
1229 1229
1230 // otherwise, must first contain it 1230 // otherwise, must first contain it
1231 if ( !emailsStr.contains( e ) ) 1231 if ( !emailsStr.contains( e ) )
1232 return ; 1232 return ;
1233 1233
1234 // remove it 1234 // remove it
1235 //odebug << " removing email from list " << e << "" << oendl; 1235 //odebug << " removing email from list " << e << "" << oendl;
1236 emails.remove( e ); 1236 emails.remove( e );
1237 // reset the string 1237 // reset the string
1238 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator 1238 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
1239 replace( Qtopia::Emails, emailsStr ); 1239 replace( Qtopia::Emails, emailsStr );
1240 1240
1241 // if default, then replace the default email with the first one 1241 // if default, then replace the default email with the first one
1242 if ( def == e ) 1242 if ( def == e )
1243 { 1243 {
1244 //odebug << "removeEmail is default; setting new default" << oendl; 1244 //odebug << "removeEmail is default; setting new default" << oendl;
1245 if ( !emails.count() ) 1245 if ( !emails.count() )
1246 clearEmails(); 1246 clearEmails();
1247 else // setDefaultEmail will remove e from the list 1247 else // setDefaultEmail will remove e from the list
1248 setDefaultEmail( emails.first() ); 1248 setDefaultEmail( emails.first() );
1249 } 1249 }
1250} 1250}
1251 1251
1252 1252
1253void OPimContact::clearEmails() 1253void OPimContact::clearEmails()
1254{ 1254{
1255 mMap.remove( Qtopia::DefaultEmail ); 1255 mMap.remove( Qtopia::DefaultEmail );
1256 mMap.remove( Qtopia::Emails ); 1256 mMap.remove( Qtopia::Emails );
1257} 1257}
1258 1258
1259 1259
1260void OPimContact::setDefaultEmail( const QString &v ) 1260void OPimContact::setDefaultEmail( const QString &v )
1261{ 1261{
1262 QString e = v.simplifyWhiteSpace(); 1262 QString e = v.simplifyWhiteSpace();
1263 1263
1264 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl; 1264 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl;
1265 replace( Qtopia::DefaultEmail, e ); 1265 replace( Qtopia::DefaultEmail, e );
1266 1266
1267 if ( !e.isEmpty() ) 1267 if ( !e.isEmpty() )
1268 insertEmail( e ); 1268 insertEmail( e );
1269 1269
1270} 1270}
1271 1271
1272 1272
1273void OPimContact::insertEmails( const QStringList &v ) 1273void OPimContact::insertEmails( const QStringList &v )
1274{ 1274{
1275 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1275 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1276 insertEmail( *it ); 1276 insertEmail( *it );
1277} 1277}
1278 1278
1279 1279
1280int OPimContact::rtti() const 1280int OPimContact::rtti() const
1281{ 1281{
1282 return OPimResolver::AddressBook; 1282 return OPimResolver::AddressBook;
1283} 1283}
1284 1284
1285 1285
1286void OPimContact::setUid( int i ) 1286void OPimContact::setUid( int i )
1287{ 1287{
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp
index 0f863aa..516dc79 100644
--- a/libopie2/opiepim/core/opimnotifymanager.cpp
+++ b/libopie2/opiepim/core/opimnotifymanager.cpp
@@ -134,117 +134,117 @@ void OPimNotifyManager::setAlarms( const Alarms& al )
134 134
135void OPimNotifyManager::setReminders( const Reminders& rem ) 135void OPimNotifyManager::setReminders( const Reminders& rem )
136{ 136{
137 m_rem = rem; 137 m_rem = rem;
138} 138}
139 139
140 140
141/* FIXME!!! */ 141/* FIXME!!! */
142/** 142/**
143 * The idea is to check if the provider for our service 143 * The idea is to check if the provider for our service
144 * is online 144 * is online
145 * if it is we will use QCOP 145 * if it is we will use QCOP
146 * if not the Factory to get the backend... 146 * if not the Factory to get the backend...
147 * Qtopia1.6 services would be kewl to have here.... 147 * Qtopia1.6 services would be kewl to have here....
148 */ 148 */
149void OPimNotifyManager::registerNotify( const OPimNotify& ) 149void OPimNotifyManager::registerNotify( const OPimNotify& )
150{ 150{
151} 151}
152 152
153 153
154/* FIXME!!! */ 154/* FIXME!!! */
155/** 155/**
156 * same as above... 156 * same as above...
157 * Also implement Url model 157 * Also implement Url model
158 * have a MainWindow.... 158 * have a MainWindow....
159 */ 159 */
160void OPimNotifyManager::deregister( const OPimNotify& ) 160void OPimNotifyManager::deregister( const OPimNotify& )
161{ 161{
162} 162}
163 163
164 164
165bool OPimNotifyManager::isEmpty() const 165bool OPimNotifyManager::isEmpty() const
166{ 166{
167 owarn << "is Empty called on OPimNotifyManager " << m_rem.count() << " " << m_al.count() << "" << oendl; 167 owarn << "is Empty called on OPimNotifyManager " << m_rem.count() << " " << m_al.count() << "" << oendl;
168 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; 168 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
169 else return false; 169 else return false;
170} 170}
171 171
172 172
173// Taken from otodoaccessxml.. code duplication bad. any alternative? 173// Taken from otodoaccessxml.. code duplication bad. any alternative?
174QString OPimNotifyManager::alarmsToString() const 174QString OPimNotifyManager::alarmsToString() const
175{ 175{
176 QString str; 176 QString str;
177 177
178 OPimNotifyManager::Alarms alarms = m_al; 178 OPimNotifyManager::Alarms alarms = m_al;
179 if ( !alarms.isEmpty() ) 179 if ( !alarms.isEmpty() )
180 { 180 {
181 QStringList als; 181 QStringList als;
182 OPimNotifyManager::Alarms::Iterator it = alarms.begin(); 182 OPimNotifyManager::Alarms::Iterator it = alarms.begin();
183 for ( ; it != alarms.end(); ++it ) 183 for ( ; it != alarms.end(); ++it )
184 { 184 {
185 /* only if time is valid */ 185 /* only if time is valid */
186 if ( ( *it ).dateTime().isValid() ) 186 if ( ( *it ).dateTime().isValid() )
187 { 187 {
188 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() ) 188 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() )
189 + ":" + QString::number( ( *it ).duration() ) 189 + ":" + QString::number( ( *it ).duration() )
190 + ":" + QString::number( ( *it ).sound() ) 190 + ":" + QString::number( ( *it ).sound() )
191 + ":"; 191 + ":";
192 } 192 }
193 } 193 }
194 // now write the list 194 // now write the list
195 owarn << "als: " << als.join( "____________" ) << "" << oendl; 195 owarn << "als: " << als.join( "____________" ) << "" << oendl;
196 str = als.join( ";" ); 196 str = als.join( ";" );
197 } 197 }
198 198
199 return str; 199 return str;
200} 200}
201 201
202 202
203QString OPimNotifyManager::remindersToString() const 203QString OPimNotifyManager::remindersToString() const
204{ 204{
205 QString str; 205 QString str;
206 206
207 OPimNotifyManager::Reminders reminders = m_rem; 207 OPimNotifyManager::Reminders reminders = m_rem;
208 if ( !reminders.isEmpty() ) 208 if ( !reminders.isEmpty() )
209 { 209 {
210 OPimNotifyManager::Reminders::Iterator it = reminders.begin(); 210 OPimNotifyManager::Reminders::Iterator it = reminders.begin();
211 QStringList records; 211 QStringList records;
212 for ( ; it != reminders.end(); ++it ) 212 for ( ; it != reminders.end(); ++it )
213 { 213 {
214 records << QString::number( ( *it ).recordUid() ); 214 records << QString::number( ( *it ).recordUid() );
215 } 215 }
216 str = records.join( ";" ); 216 str = records.join( ";" );
217 } 217 }
218 218
219 return str; 219 return str;
220} 220}
221 221
222 222
223void OPimNotifyManager::alarmsFromString( const QString& str ) 223void OPimNotifyManager::alarmsFromString( const QString& str )
224{ 224{
225 QStringList als = QStringList::split( ";", str ); 225 QStringList als = QStringList::split( ";", str );
226 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it ) 226 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it )
227 { 227 {
228 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty 228 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty
229 owarn << "alarm: " << alarm.join( "___" ) << "" << oendl; 229 owarn << "alarm: " << alarm.join( "___" ) << "" << oendl;
230 qWarning( "alarm[0]: %s %s", alarm[ 0 ].latin1(), 230 owarn << "alarm[0]: " << alarm[ 0 ] << " "
231 OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString().latin1() ); 231 << OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString() << oendl;
232 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ), 232 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ),
233 alarm[ 1 ].toInt() ); 233 alarm[ 1 ].toInt() );
234 add( al ); 234 add( al );
235 } 235 }
236} 236}
237 237
238 238
239void OPimNotifyManager::remindersFromString( const QString& str ) 239void OPimNotifyManager::remindersFromString( const QString& str )
240{ 240{
241 241
242 QStringList rems = QStringList::split( ";", str ); 242 QStringList rems = QStringList::split( ";", str );
243 for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) 243 for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it )
244 { 244 {
245 OPimReminder rem( ( *it ).toInt() ); 245 OPimReminder rem( ( *it ).toInt() );
246 add( rem ); 246 add( rem );
247 } 247 }
248 248
249} 249}
250} 250}
diff --git a/libopie2/opiepim/core/opimrecordlist.h b/libopie2/opiepim/core/opimrecordlist.h
index b23138d..1d5027f 100644
--- a/libopie2/opiepim/core/opimrecordlist.h
+++ b/libopie2/opiepim/core/opimrecordlist.h
@@ -1,314 +1,315 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#ifndef ORECORDLIST_H 30#ifndef ORECORDLIST_H
31#define ORECORDLIST_H 31#define ORECORDLIST_H
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimtemplatebase.h> 34#include <opie2/opimtemplatebase.h>
35#include <opie2/opimrecord.h> 35#include <opie2/opimrecord.h>
36//#include <opie2/odebug.h>
36 37
37/* QT */ 38/* QT */
38#include <qarray.h> 39#include <qarray.h>
39 40
40namespace Opie 41namespace Opie
41{ 42{
42 43
43class OPimRecordListIteratorPrivate; 44class OPimRecordListIteratorPrivate;
44/** 45/**
45 * Our List Iterator 46 * Our List Iterator
46 * it behaves like STL or Qt 47 * it behaves like STL or Qt
47 * 48 *
48 * for(it = list.begin(); it != list.end(); ++it ) 49 * for(it = list.begin(); it != list.end(); ++it )
49 * doSomeCoolStuff( (*it) ); 50 * doSomeCoolStuff( (*it) );
50 */ 51 */
51template <class T> class OPimRecordList; 52template <class T> class OPimRecordList;
52template <class T = OPimRecord> 53template <class T = OPimRecord>
53class OPimRecordListIterator 54class OPimRecordListIterator
54{ 55{
55 friend class OPimRecordList<T>; 56 friend class OPimRecordList<T>;
56 57
57 public: 58 public:
58 typedef OTemplateBase<T> Base; 59 typedef OTemplateBase<T> Base;
59 60
60 /** 61 /**
61 * The c'tor used internally from 62 * The c'tor used internally from
62 * OPimRecordList 63 * OPimRecordList
63 */ 64 */
64 OPimRecordListIterator( const QArray<int>, const Base* ); 65 OPimRecordListIterator( const QArray<int>, const Base* );
65 66
66 /** 67 /**
67 * The standard c'tor 68 * The standard c'tor
68 */ 69 */
69 OPimRecordListIterator(); 70 OPimRecordListIterator();
70 ~OPimRecordListIterator(); 71 ~OPimRecordListIterator();
71 72
72 OPimRecordListIterator( const OPimRecordListIterator& ); 73 OPimRecordListIterator( const OPimRecordListIterator& );
73 OPimRecordListIterator &operator=( const OPimRecordListIterator& ); 74 OPimRecordListIterator &operator=( const OPimRecordListIterator& );
74 75
75 /** 76 /**
76 * a * operator ;) 77 * a * operator ;)
77 * use it like this T = (*it); 78 * use it like this T = (*it);
78 */ 79 */
79 T operator*(); 80 T operator*();
80 OPimRecordListIterator &operator++(); 81 OPimRecordListIterator &operator++();
81 OPimRecordListIterator &operator--(); 82 OPimRecordListIterator &operator--();
82 83
83 bool operator==( const OPimRecordListIterator& it ); 84 bool operator==( const OPimRecordListIterator& it );
84 bool operator!=( const OPimRecordListIterator& it ); 85 bool operator!=( const OPimRecordListIterator& it );
85 86
86 /** 87 /**
87 * the current item 88 * the current item
88 */ 89 */
89 uint current() const; 90 uint current() const;
90 91
91 /** 92 /**
92 * the number of items 93 * the number of items
93 */ 94 */
94 uint count() const; 95 uint count() const;
95 96
96 /** 97 /**
97 * sets the current item 98 * sets the current item
98 */ 99 */
99 void setCurrent( uint cur ); 100 void setCurrent( uint cur );
100 101
101 private: 102 private:
102 QArray<int> m_uids; 103 QArray<int> m_uids;
103 uint m_current; 104 uint m_current;
104 const Base* m_temp; 105 const Base* m_temp;
105 bool m_end : 1; 106 bool m_end : 1;
106 T m_record; 107 T m_record;
107 bool m_direction : 1; 108 bool m_direction : 1;
108 109
109 /* d pointer for future versions */ 110 /* d pointer for future versions */
110 OPimRecordListIteratorPrivate *d; 111 OPimRecordListIteratorPrivate *d;
111}; 112};
112 113
113 114
114class OPimRecordListPrivate; 115class OPimRecordListPrivate;
115/** 116/**
116 * The recordlist used as a return type 117 * The recordlist used as a return type
117 * from OPimAccessTemplate 118 * from OPimAccessTemplate
118 */ 119 */
119template <class T = OPimRecord > 120template <class T = OPimRecord >
120class OPimRecordList 121class OPimRecordList
121{ 122{
122 public: 123 public:
123 typedef OTemplateBase<T> Base; 124 typedef OTemplateBase<T> Base;
124 typedef OPimRecordListIterator<T> Iterator; 125 typedef OPimRecordListIterator<T> Iterator;
125 126
126 /** 127 /**
127 * c'tor 128 * c'tor
128 */ 129 */
129 OPimRecordList () 130 OPimRecordList ()
130 {} 131 {}
131 OPimRecordList( const QArray<int>& ids, 132 OPimRecordList( const QArray<int>& ids,
132 const Base* ); 133 const Base* );
133 ~OPimRecordList(); 134 ~OPimRecordList();
134 135
135 /** 136 /**
136 * the first iterator 137 * the first iterator
137 */ 138 */
138 Iterator begin(); 139 Iterator begin();
139 140
140 /** 141 /**
141 * the end 142 * the end
142 */ 143 */
143 Iterator end(); 144 Iterator end();
144 145
145 /** 146 /**
146 * the number of items in the list 147 * the number of items in the list
147 */ 148 */
148 uint count() const; 149 uint count() const;
149 150
150 T operator[] ( uint i ); 151 T operator[] ( uint i );
151 int uidAt( uint i ); 152 int uidAt( uint i );
152 153
153 /** 154 /**
154 * Remove the contact with given uid 155 * Remove the contact with given uid
155 */ 156 */
156 bool remove( int uid ); 157 bool remove( int uid );
157 158
158 /* 159 /*
159 ConstIterator begin()const; 160 ConstIterator begin()const;
160 ConstIterator end()const; 161 ConstIterator end()const;
161 */ 162 */
162 private: 163 private:
163 QArray<int> m_ids; 164 QArray<int> m_ids;
164 const Base* m_acc; 165 const Base* m_acc;
165 OPimRecordListPrivate *d; 166 OPimRecordListPrivate *d;
166}; 167};
167 168
168 169
169/* ok now implement it */ 170/* ok now implement it */
170template <class T> 171template <class T>
171OPimRecordListIterator<T>::OPimRecordListIterator() 172OPimRecordListIterator<T>::OPimRecordListIterator()
172{ 173{
173 m_current = 0; 174 m_current = 0;
174 m_temp = 0l; 175 m_temp = 0l;
175 m_end = true; 176 m_end = true;
176 m_record = T(); 177 m_record = T();
177 /* forward */ 178 /* forward */
178 m_direction = TRUE; 179 m_direction = TRUE;
179} 180}
180 181
181 182
182template <class T> 183template <class T>
183OPimRecordListIterator<T>::~OPimRecordListIterator() 184OPimRecordListIterator<T>::~OPimRecordListIterator()
184{ 185{
185 /* nothing to delete */ 186 /* nothing to delete */
186} 187}
187 188
188 189
189template <class T> 190template <class T>
190OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it ) 191OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it )
191{ 192{
192 // qWarning("OPimRecordListIterator copy c'tor"); 193 //owarn << "OPimRecordListIterator copy c'tor" << oendl;
193 m_uids = it.m_uids; 194 m_uids = it.m_uids;
194 m_current = it.m_current; 195 m_current = it.m_current;
195 m_temp = it.m_temp; 196 m_temp = it.m_temp;
196 m_end = it.m_end; 197 m_end = it.m_end;
197 m_record = it.m_record; 198 m_record = it.m_record;
198 m_direction = it.m_direction; 199 m_direction = it.m_direction;
199} 200}
200 201
201 202
202template <class T> 203template <class T>
203OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator=( const OPimRecordListIterator<T>& it ) 204OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator=( const OPimRecordListIterator<T>& it )
204{ 205{
205 m_uids = it.m_uids; 206 m_uids = it.m_uids;
206 m_current = it.m_current; 207 m_current = it.m_current;
207 m_temp = it.m_temp; 208 m_temp = it.m_temp;
208 m_end = it.m_end; 209 m_end = it.m_end;
209 m_record = it.m_record; 210 m_record = it.m_record;
210 211
211 return *this; 212 return *this;
212} 213}
213 214
214 215
215template <class T> 216template <class T>
216T OPimRecordListIterator<T>::operator*() 217T OPimRecordListIterator<T>::operator*()
217{ 218{
218 //qWarning("operator* %d %d", m_current, m_uids[m_current] ); 219 //owarn << "operator* " << m_current << " " << m_uids[m_current] << oendl;
219 if ( !m_end ) 220 if ( !m_end )
220 m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current, 221 m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current,
221 m_direction ? Base::Forward : 222 m_direction ? Base::Forward :
222 Base::Reverse ); 223 Base::Reverse );
223 else 224 else
224 m_record = T(); 225 m_record = T();
225 226
226 return m_record; 227 return m_record;
227} 228}
228 229
229 230
230template <class T> 231template <class T>
231OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator++() 232OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator++()
232{ 233{
233 m_direction = true; 234 m_direction = true;
234 if ( m_current < m_uids.count() ) 235 if ( m_current < m_uids.count() )
235 { 236 {
236 m_end = false; 237 m_end = false;
237 ++m_current; 238 ++m_current;
238 } 239 }
239 else 240 else
240 m_end = true; 241 m_end = true;
241 242
242 return *this; 243 return *this;
243} 244}
244 245
245 246
246template <class T> 247template <class T>
247OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator--() 248OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator--()
248{ 249{
249 m_direction = false; 250 m_direction = false;
250 if ( m_current > 0 ) 251 if ( m_current > 0 )
251 { 252 {
252 --m_current; 253 --m_current;
253 m_end = false; 254 m_end = false;
254 } 255 }
255 else 256 else
256 m_end = true; 257 m_end = true;
257 258
258 return *this; 259 return *this;
259} 260}
260 261
261 262
262template <class T> 263template <class T>
263bool OPimRecordListIterator<T>::operator==( const OPimRecordListIterator<T>& it ) 264bool OPimRecordListIterator<T>::operator==( const OPimRecordListIterator<T>& it )
264{ 265{
265 266
266 /* if both are at we're the same.... */ 267 /* if both are at we're the same.... */
267 if ( m_end == it.m_end ) return true; 268 if ( m_end == it.m_end ) return true;
268 269
269 if ( m_uids != it.m_uids ) return false; 270 if ( m_uids != it.m_uids ) return false;
270 if ( m_current != it.m_current ) return false; 271 if ( m_current != it.m_current ) return false;
271 if ( m_temp != it.m_temp ) return false; 272 if ( m_temp != it.m_temp ) return false;
272 273
273 return true; 274 return true;
274} 275}
275 276
276 277
277template <class T> 278template <class T>
278bool OPimRecordListIterator<T>::operator!=( const OPimRecordListIterator<T>& it ) 279bool OPimRecordListIterator<T>::operator!=( const OPimRecordListIterator<T>& it )
279{ 280{
280 return !( *this == it ); 281 return !( *this == it );
281} 282}
282 283
283 284
284template <class T> 285template <class T>
285OPimRecordListIterator<T>::OPimRecordListIterator( const QArray<int> uids, 286OPimRecordListIterator<T>::OPimRecordListIterator( const QArray<int> uids,
286 const Base* t ) 287 const Base* t )
287 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), 288 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ),
288 m_direction( false ) 289 m_direction( false )
289{ 290{
290 /* if the list is empty we're already at the end of the list */ 291 /* if the list is empty we're already at the end of the list */
291 if ( uids.count() == 0 ) 292 if ( uids.count() == 0 )
292 m_end = true; 293 m_end = true;
293} 294}
294 295
295 296
296template <class T> 297template <class T>
297uint OPimRecordListIterator<T>::current() const 298uint OPimRecordListIterator<T>::current() const
298{ 299{
299 return m_current; 300 return m_current;
300} 301}
301 302
302 303
303template <class T> 304template <class T>
304void OPimRecordListIterator<T>::setCurrent( uint cur ) 305void OPimRecordListIterator<T>::setCurrent( uint cur )
305{ 306{
306 if ( cur < m_uids.count() ) 307 if ( cur < m_uids.count() )
307 { 308 {
308 m_end = false; 309 m_end = false;
309 m_current = cur; 310 m_current = cur;
310 } 311 }
311} 312}
312template <class T> 313template <class T>
313uint OPimRecordListIterator<T>::count() const 314uint OPimRecordListIterator<T>::count() const
314{ 315{