summaryrefslogtreecommitdiff
authorar <ar>2004-06-01 21:38:07 (UTC)
committer ar <ar>2004-06-01 21:38:07 (UTC)
commitbaed1d5ab8589aef14440009bc4e7380bcc5a741 (patch) (unidiff)
treec636e892c5eec0df2b36d16cb601a7da41a2ef0f
parent4438393d8eef624565e840b798429071829adea8 (diff)
downloadopie-baed1d5ab8589aef14440009bc4e7380bcc5a741.zip
opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.gz
opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.bz2
- convert to odebug framework
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiedb/osqlbackendmanager.cpp12
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp78
-rw-r--r--libopie2/opiemm/osoundsystem.cpp6
-rw-r--r--libopie2/opienet/onetwork.cpp11
-rw-r--r--libopie2/opienet/ostation.cpp8
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp1326
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp894
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp1182
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp579
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp170
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp444
-rw-r--r--libopie2/opiepim/backend/otodoaccessvcal.cpp20
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp191
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp20
-rw-r--r--libopie2/opiepim/core/opimcontactfields.cpp22
-rw-r--r--libopie2/opiepim/core/opimdateconversion.cpp12
-rw-r--r--libopie2/opiepim/core/opimevent.cpp24
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp7
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp2
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp5
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp22
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp2
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.cpp19
23 files changed, 2560 insertions, 2496 deletions
diff --git a/libopie2/opiedb/osqlbackendmanager.cpp b/libopie2/opiedb/osqlbackendmanager.cpp
index fc18e07..bbfbf3d 100644
--- a/libopie2/opiedb/osqlbackendmanager.cpp
+++ b/libopie2/opiedb/osqlbackendmanager.cpp
@@ -1,106 +1,112 @@
1
2#include "osqlbackendmanager.h"
3
4/* OPIE */
5#include <opie2/odebug.h>
6
7/* QT */
1#include <qdir.h> 8#include <qdir.h>
2#include <qmap.h> 9#include <qmap.h>
3 10
4#include "osqlbackendmanager.h"
5 11
6/** 12/**
7 * \todo FIXME CONFIG!!! 13 * \todo FIXME CONFIG!!!
8 */ 14 */
9 15
10namespace { 16namespace {
11 class Config { 17 class Config {
12 typedef QMap<QString, QString> List; 18 typedef QMap<QString, QString> List;
13 public: 19 public:
14 Config( const QString& fileName ); 20 Config( const QString& fileName );
15 /** 21 /**
16 * Quite simple layout in nature 22 * Quite simple layout in nature
17 * BeginFile 23 * BeginFile
18 * Key = Value 24 * Key = Value
19 */ 25 */
20 bool load(); 26 bool load();
21 QString value( const QString& key ); 27 QString value( const QString& key );
22 private: 28 private:
23 List m_list; 29 List m_list;
24 QString m_fileName; 30 QString m_fileName;
25 }; 31 };
26 Config::Config( const QString& fileName ) 32 Config::Config( const QString& fileName )
27 : m_fileName( fileName ) { 33 : m_fileName( fileName ) {
28 } 34 }
29 35
30 bool Config::load() { 36 bool Config::load() {
31 if (!QFile::exists( m_fileName ) ) 37 if (!QFile::exists( m_fileName ) )
32 return false; 38 return false;
33 QFile file( m_fileName ); 39 QFile file( m_fileName );
34 if (!file.open(IO_ReadOnly ) ) 40 if (!file.open(IO_ReadOnly ) )
35 return false; 41 return false;
36 QStringList list = QStringList::split( '\n', file.readAll() ); 42 QStringList list = QStringList::split( '\n', file.readAll() );
37 QStringList::Iterator it; 43 QStringList::Iterator it;
38 QString line; 44 QString line;
39 for (it = list.begin(); it != list.end(); ++it ) { 45 for (it = list.begin(); it != list.end(); ++it ) {
40 line = (*it).stripWhiteSpace(); 46 line = (*it).stripWhiteSpace();
41 qWarning("Anonymous::Config:" + line ); 47 owarn << "Anonymous::Config:" + line << oendl;
42 QStringList test = QStringList::split(' ', line ); 48 QStringList test = QStringList::split(' ', line );
43 m_list.insert( test[0], test[2] ); 49 m_list.insert( test[0], test[2] );
44 } 50 }
45 return true; 51 return true;
46 } 52 }
47 QString Config::value( const QString& key ) { 53 QString Config::value( const QString& key ) {
48 return m_list[key]; 54 return m_list[key];
49 } 55 }
50}; 56};
51 57
52 58
53using namespace Opie::DB; 59using namespace Opie::DB;
54 60
55OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) 61OSQLBackEndManager::OSQLBackEndManager( const QStringList& path )
56 :m_path( path ) 62 :m_path( path )
57{ 63{
58} 64}
59OSQLBackEndManager::~OSQLBackEndManager() { 65OSQLBackEndManager::~OSQLBackEndManager() {
60} 66}
61/** 67/**
62 * scan dirs 68 * scan dirs
63 */ 69 */
64OSQLBackEnd::ValueList OSQLBackEndManager::scan() { 70OSQLBackEnd::ValueList OSQLBackEndManager::scan() {
65 OSQLBackEnd::ValueList list; 71 OSQLBackEnd::ValueList list;
66 if (!m_path.isEmpty() ) { 72 if (!m_path.isEmpty() ) {
67 QStringList::Iterator it; 73 QStringList::Iterator it;
68 for ( it = m_path.begin(); it != m_path.end(); ++it ) { 74 for ( it = m_path.begin(); it != m_path.end(); ++it ) {
69 list += scanDir( (*it) ); 75 list += scanDir( (*it) );
70 } 76 }
71 } 77 }
72 return list; 78 return list;
73} 79}
74/** 80/**
75 * scan a specified dir for *.osql 81 * scan a specified dir for *.osql
76 */ 82 */
77OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { 83OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) {
78 OSQLBackEnd::ValueList list; 84 OSQLBackEnd::ValueList list;
79 QDir dir( dirName ); 85 QDir dir( dirName );
80 if (dir.exists() ) { 86 if (dir.exists() ) {
81 QStringList files = dir.entryList( "*.osql" ); 87 QStringList files = dir.entryList( "*.osql" );
82 QStringList::Iterator it; 88 QStringList::Iterator it;
83 for ( it = files.begin(); it != files.end(); ++it ) { 89 for ( it = files.begin(); it != files.end(); ++it ) {
84 list.append( file2backend( (*it) ) ); 90 list.append( file2backend( (*it) ) );
85 } 91 }
86 } 92 }
87 return list; 93 return list;
88} 94}
89 95
90/** 96/**
91 * read a config file and convert it to a OSQLBackEnd 97 * read a config file and convert it to a OSQLBackEnd
92 */ 98 */
93OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { 99OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) {
94 OSQLBackEnd end; 100 OSQLBackEnd end;
95 qWarning("fileName: " + file ); 101 owarn << "fileName: " + file << oendl;
96 Config cfg( file ); 102 Config cfg( file );
97 if (cfg.load() ) { 103 if (cfg.load() ) {
98 end.setName( cfg.value( "Name") ); 104 end.setName( cfg.value( "Name") );
99 end.setVendor( cfg.value("Vendor") ); 105 end.setVendor( cfg.value("Vendor") );
100 end.setLicense( cfg.value("License") ); 106 end.setLicense( cfg.value("License") );
101 end.setLibrary( cfg.value("Library").local8Bit() ); 107 end.setLibrary( cfg.value("Library").local8Bit() );
102 end.setDefault( cfg.value("Default").toInt() ); 108 end.setDefault( cfg.value("Default").toInt() );
103 end.setPreference( cfg.value("Preference").toInt() ); 109 end.setPreference( cfg.value("Preference").toInt() );
104 } 110 }
105 return end; 111 return end;
106} 112}
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index 588fc8f..69eddfe 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -1,238 +1,238 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 =. 4 =.
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#include "osqlquery.h" 31#include "osqlquery.h"
32#include "osqlitedriver.h" 32#include "osqlitedriver.h"
33 33
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35 35
36#include <stdlib.h> 36#include <stdlib.h>
37#include <stdio.h> 37#include <stdio.h>
38 38
39// fromLocal8Bit() does not work as expected. Thus it 39// fromLocal8Bit() does not work as expected. Thus it
40// is replaced by fromLatin1() (eilers) 40// is replaced by fromLatin1() (eilers)
41#define __BUGGY_LOCAL8BIT_ 41#define __BUGGY_LOCAL8BIT_
42 42
43namespace Opie { 43namespace Opie {
44namespace DB { 44namespace DB {
45namespace Internal { 45namespace Internal {
46 46
47namespace { 47namespace {
48 struct Query { 48 struct Query {
49 OSQLError::ValueList errors; 49 OSQLError::ValueList errors;
50 OSQLResultItem::ValueList items; 50 OSQLResultItem::ValueList items;
51 OSQLiteDriver *driver; 51 OSQLiteDriver *driver;
52 }; 52 };
53} 53}
54 54
55 55
56OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) 56OSQLiteDriver::OSQLiteDriver( QLibrary *lib )
57 : OSQLDriver( lib ) 57 : OSQLDriver( lib )
58{ 58{
59 m_sqlite = 0l; 59 m_sqlite = 0l;
60} 60}
61 61
62 62
63OSQLiteDriver::~OSQLiteDriver() { 63OSQLiteDriver::~OSQLiteDriver() {
64 close(); 64 close();
65} 65}
66 66
67 67
68QString OSQLiteDriver::id()const { 68QString OSQLiteDriver::id()const {
69 return QString::fromLatin1("SQLite"); 69 return QString::fromLatin1("SQLite");
70} 70}
71 71
72void OSQLiteDriver::setUserName( const QString& ) {} 72void OSQLiteDriver::setUserName( const QString& ) {}
73 73
74 74
75void OSQLiteDriver::setPassword( const QString& ) {} 75void OSQLiteDriver::setPassword( const QString& ) {}
76 76
77 77
78void OSQLiteDriver::setUrl( const QString& url ) { 78void OSQLiteDriver::setUrl( const QString& url ) {
79 m_url = url; 79 m_url = url;
80} 80}
81 81
82 82
83void OSQLiteDriver::setOptions( const QStringList& ) { 83void OSQLiteDriver::setOptions( const QStringList& ) {
84} 84}
85 85
86/* 86/*
87 * Functions to patch a regex search into sqlite 87 * Functions to patch a regex search into sqlite
88 */ 88 */
89int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){ 89int sqliteRlikeCompare(const char *zPattern, const char *zString, sqregex *reg){
90 int res; 90 int res;
91 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){ 91 if (reg->regex_raw == NULL || (strcmp (zPattern, reg->regex_raw) != 0)){
92 if (reg->regex_raw != NULL) { 92 if (reg->regex_raw != NULL) {
93 free(reg->regex_raw); 93 free(reg->regex_raw);
94 regfree(&reg->regex_c); 94 regfree(&reg->regex_c);
95 } 95 }
96 reg->regex_raw = (char *)malloc(strlen(zPattern)+1); 96 reg->regex_raw = (char *)malloc(strlen(zPattern)+1);
97 strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1); 97 strncpy(reg->regex_raw, zPattern, strlen(zPattern)+1);
98 res = regcomp(&reg->regex_c, zPattern, REG_EXTENDED); 98 res = regcomp(&reg->regex_c, zPattern, REG_EXTENDED);
99 if ( res != 0 ) { 99 if ( res != 0 ) {
100 printf("Regcomp failed with code %u on string %s\n",res,zPattern); 100 printf("Regcomp failed with code %u on string %s\n",res,zPattern);
101 free(reg->regex_raw); 101 free(reg->regex_raw);
102 reg->regex_raw=NULL; 102 reg->regex_raw=NULL;
103 return 0; 103 return 0;
104 } 104 }
105 } 105 }
106 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0); 106 res = (regexec(&reg->regex_c, zString, 0, NULL, 0)==0);
107 return res; 107 return res;
108} 108}
109 109
110void rlikeFunc(sqlite_func *context, int arg, const char **argv){ 110void rlikeFunc(sqlite_func *context, int arg, const char **argv){
111 if( argv[0]==0 || argv[1]==0 ){ 111 if( argv[0]==0 || argv[1]==0 ){
112 printf("One of arguments Null!!\n"); 112 printf("One of arguments Null!!\n");
113 return; 113 return;
114 } 114 }
115 sqlite_set_result_int(context, 115 sqlite_set_result_int(context,
116 sqliteRlikeCompare((const char*)argv[0], 116 sqliteRlikeCompare((const char*)argv[0],
117 (const char*)argv[1], (sqregex *)sqlite_user_data(context) )); 117 (const char*)argv[1], (sqregex *)sqlite_user_data(context) ));
118} 118}
119 119
120/* 120/*
121 * try to open a db specified via setUrl 121 * try to open a db specified via setUrl
122 * and options 122 * and options
123 */ 123 */
124bool OSQLiteDriver::open() { 124bool OSQLiteDriver::open() {
125 char *error; 125 char *error;
126 126
127 qDebug("OSQLiteDriver::open: about to open"); 127 odebug << "OSQLiteDriver::open: about to open" << oendl;
128 m_sqlite = sqlite_open(m_url.local8Bit(), 128 m_sqlite = sqlite_open(m_url.local8Bit(),
129 0, 129 0,
130 &error ); 130 &error );
131 131
132 /* failed to open */ 132 /* failed to open */
133 if (m_sqlite == 0l ) { 133 if (m_sqlite == 0l ) {
134 // FIXME set the last error 134 // FIXME set the last error
135 qWarning("OSQLiteDriver::open: %s", error ); 135 owarn << "OSQLiteDriver::open: " << error << "" << oendl;
136 free( error ); 136 free( error );
137 return false; 137 return false;
138 } 138 }
139 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0) 139 if (sqlite_create_function(m_sqlite,"rlike",2,rlikeFunc,&sqreg) != 0)
140 odebug << "Unable to create user defined function!" << oendl; 140 odebug << "Unable to create user defined function!" << oendl;
141 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0) 141 if (sqlite_function_type(m_sqlite,"rlike",SQLITE_NUMERIC) != 0)
142 odebug << "Unable to set rlike function result type!" << oendl; 142 odebug << "Unable to set rlike function result type!" << oendl;
143 sqreg.regex_raw = NULL; 143 sqreg.regex_raw = NULL;
144 return true; 144 return true;
145} 145}
146 146
147 147
148/* close the db 148/* close the db
149 * sqlite closes them without 149 * sqlite closes them without
150 * telling failure or success 150 * telling failure or success
151 */ 151 */
152bool OSQLiteDriver::close() { 152bool OSQLiteDriver::close() {
153 if (m_sqlite ) 153 if (m_sqlite )
154 sqlite_close( m_sqlite ), m_sqlite=0l; 154 sqlite_close( m_sqlite ), m_sqlite=0l;
155 if (sqreg.regex_raw != NULL){ 155 if (sqreg.regex_raw != NULL){
156 odebug << "Freeing regex on close" << oendl; 156 odebug << "Freeing regex on close" << oendl;
157 free(sqreg.regex_raw); 157 free(sqreg.regex_raw);
158 sqreg.regex_raw=NULL; 158 sqreg.regex_raw=NULL;
159 regfree(&sqreg.regex_c); 159 regfree(&sqreg.regex_c);
160 } 160 }
161 return true; 161 return true;
162} 162}
163 163
164 164
165/* Query */ 165/* Query */
166OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 166OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
167 if ( !m_sqlite ) { 167 if ( !m_sqlite ) {
168 // FIXME set error code 168 // FIXME set error code
169 OSQLResult result( OSQLResult::Failure ); 169 OSQLResult result( OSQLResult::Failure );
170 return result; 170 return result;
171 } 171 }
172 Query query; 172 Query query;
173 query.driver = this; 173 query.driver = this;
174 char *err; 174 char *err;
175 /* SQLITE_OK 0 if return code > 0 == failure */ 175 /* SQLITE_OK 0 if return code > 0 == failure */
176 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { 176 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) {
177 qWarning("OSQLiteDriver::query: Error while executing %s",err); 177 owarn << "OSQLiteDriver::query: Error while executing " << err << "" << oendl;
178 free(err ); 178 free(err );
179 // FixMe Errors 179 // FixMe Errors
180 } 180 }
181 181
182 OSQLResult result(OSQLResult::Success, 182 OSQLResult result(OSQLResult::Success,
183 query.items, 183 query.items,
184 query.errors ); 184 query.errors );
185 return result; 185 return result;
186} 186}
187 187
188 188
189OSQLTable::ValueList OSQLiteDriver::tables() const { 189OSQLTable::ValueList OSQLiteDriver::tables() const {
190 190
191} 191}
192 192
193 193
194OSQLError OSQLiteDriver::lastError() { 194OSQLError OSQLiteDriver::lastError() {
195 OSQLError error; 195 OSQLError error;
196 return error; 196 return error;
197}; 197};
198 198
199 199
200/* handle a callback add the row to the global 200/* handle a callback add the row to the global
201 * OSQLResultItem 201 * OSQLResultItem
202 */ 202 */
203int OSQLiteDriver::handleCallBack( int, char**, char** ) { 203int OSQLiteDriver::handleCallBack( int, char**, char** ) {
204 return 0; 204 return 0;
205} 205}
206 206
207 207
208/* callback_handler add the values to the list*/ 208/* callback_handler add the values to the list*/
209int OSQLiteDriver::call_back( void* voi, int argc, 209int OSQLiteDriver::call_back( void* voi, int argc,
210 char** argv, char** columns) { 210 char** argv, char** columns) {
211 Query* qu = (Query*)voi; 211 Query* qu = (Query*)voi;
212 212
213 //copy them over to a OSQLResultItem 213 //copy them over to a OSQLResultItem
214 QMap<QString, QString> tableString; 214 QMap<QString, QString> tableString;
215 QMap<int, QString> tableInt; 215 QMap<int, QString> tableInt;
216 for (int i = 0; i < argc; i++ ) { 216 for (int i = 0; i < argc; i++ ) {
217 217
218#ifdef __BUGGY_LOCAL8BIT_ 218#ifdef __BUGGY_LOCAL8BIT_
219 tableInt.insert( i, QString::fromLatin1( argv[i] ) ); 219 tableInt.insert( i, QString::fromLatin1( argv[i] ) );
220 tableString.insert( QString::fromLatin1( columns[i] ), 220 tableString.insert( QString::fromLatin1( columns[i] ),
221 QString::fromLatin1( argv[i] ) ); 221 QString::fromLatin1( argv[i] ) );
222#else 222#else
223 tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); 223 tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) );
224 tableString.insert( QString::fromLocal8Bit( columns[i] ), 224 tableString.insert( QString::fromLocal8Bit( columns[i] ),
225 QString::fromLocal8Bit( argv[i] ) ); 225 QString::fromLocal8Bit( argv[i] ) );
226#endif 226#endif
227 } 227 }
228 OSQLResultItem item( tableString, tableInt ); 228 OSQLResultItem item( tableString, tableInt );
229 qu->items.append( item ); 229 qu->items.append( item );
230 230
231 return ((Query*)voi)->driver->handleCallBack( argc, 231 return ((Query*)voi)->driver->handleCallBack( argc,
232 argv, 232 argv,
233 columns ); 233 columns );
234 234
235 235
236} 236}
237 237
238}}} // namespace OPIE::DB::Internal 238}}} // namespace OPIE::DB::Internal
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp
index c00585d..2b17230 100644
--- a/libopie2/opiemm/osoundsystem.cpp
+++ b/libopie2/opiemm/osoundsystem.cpp
@@ -1,315 +1,315 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
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*/ 30*/
31 31
32#include <opie2/osoundsystem.h> 32#include <opie2/osoundsystem.h>
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34 34
35#include <errno.h> 35#include <errno.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <string.h> 37#include <string.h>
38#include <sys/ioctl.h> 38#include <sys/ioctl.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/soundcard.h> 40#include <sys/soundcard.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42 42
43 43
44using namespace Opie::Core; 44using namespace Opie::Core;
45using namespace Opie::MM; 45using namespace Opie::MM;
46/*====================================================================================== 46/*======================================================================================
47 * OSoundSystem 47 * OSoundSystem
48 *======================================================================================*/ 48 *======================================================================================*/
49 49
50OSoundSystem* OSoundSystem::_instance = 0; 50OSoundSystem* OSoundSystem::_instance = 0;
51 51
52OSoundSystem::OSoundSystem() 52OSoundSystem::OSoundSystem()
53{ 53{
54 odebug << "OSoundSystem::OSoundSystem()" << oendl; 54 odebug << "OSoundSystem::OSoundSystem()" << oendl;
55 synchronize(); 55 synchronize();
56} 56}
57 57
58void OSoundSystem::synchronize() 58void OSoundSystem::synchronize()
59{ 59{
60 // gather available interfaces by inspecting /dev 60 // gather available interfaces by inspecting /dev
61 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 61 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
62 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 62 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
63 63
64 _interfaces.clear(); 64 _interfaces.clear();
65 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); 65 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) );
66 66
67 67
68 /* 68 /*
69 69
70 QString str; 70 QString str;
71 QFile f( "/dev/sound" ); 71 QFile f( "/dev/sound" );
72 bool hasFile = f.open( IO_ReadOnly ); 72 bool hasFile = f.open( IO_ReadOnly );
73 if ( !hasFile ) 73 if ( !hasFile )
74 { 74 {
75 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; 75 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl;
76 return; 76 return;
77 } 77 }
78 QTextStream s( &f ); 78 QTextStream s( &f );
79 s.readLine(); 79 s.readLine();
80 s.readLine(); 80 s.readLine();
81 while ( !s.atEnd() ) 81 while ( !s.atEnd() )
82 { 82 {
83 s >> str; 83 s >> str;
84 str.truncate( str.find( ':' ) ); 84 str.truncate( str.find( ':' ) );
85 qDebug( "OSoundSystem: found interface '%s'", (const char*) str ); 85 odebug << "OSoundSystem: found interface '" << str << "'" << oendl;
86 OAudioInterface* iface; 86 OAudioInterface* iface;
87 iface = new OAudioInterface( this, (const char*) str ); 87 iface = new OAudioInterface( this, (const char*) str );
88 88
89 _interfaces.insert( str, iface ); 89 _interfaces.insert( str, iface );
90 s.readLine(); 90 s.readLine();
91 } 91 }
92*/ 92*/
93} 93}
94 94
95 95
96int OSoundSystem::count() const 96int OSoundSystem::count() const
97{ 97{
98 return _interfaces.count(); 98 return _interfaces.count();
99} 99}
100 100
101 101
102OSoundCard* OSoundSystem::card( const QString& iface ) const 102OSoundCard* OSoundSystem::card( const QString& iface ) const
103{ 103{
104 return _interfaces[iface]; 104 return _interfaces[iface];
105} 105}
106 106
107 107
108OSoundSystem* OSoundSystem::instance() 108OSoundSystem* OSoundSystem::instance()
109{ 109{
110 if ( !_instance ) _instance = new OSoundSystem(); 110 if ( !_instance ) _instance = new OSoundSystem();
111 return _instance; 111 return _instance;
112} 112}
113 113
114 114
115OSoundSystem::CardIterator OSoundSystem::iterator() const 115OSoundSystem::CardIterator OSoundSystem::iterator() const
116{ 116{
117 return OSoundSystem::CardIterator( _interfaces ); 117 return OSoundSystem::CardIterator( _interfaces );
118} 118}
119 119
120 120
121/*====================================================================================== 121/*======================================================================================
122 * OSoundCard 122 * OSoundCard
123 *======================================================================================*/ 123 *======================================================================================*/
124 124
125OSoundCard::OSoundCard( QObject* parent, const char* name ) 125OSoundCard::OSoundCard( QObject* parent, const char* name )
126 :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) 126 :QObject( parent, name ), _audio( 0 ), _mixer( 0 )
127{ 127{
128 odebug << "OSoundCard::OSoundCard()" << oendl; 128 odebug << "OSoundCard::OSoundCard()" << oendl;
129 init(); 129 init();
130} 130}
131 131
132 132
133OSoundCard::~OSoundCard() 133OSoundCard::~OSoundCard()
134{ 134{
135} 135}
136 136
137 137
138void OSoundCard::init() 138void OSoundCard::init()
139{ 139{
140 _audio = new OAudioInterface( this, "/dev/dsp" ); 140 _audio = new OAudioInterface( this, "/dev/dsp" );
141 _mixer = new OMixerInterface( this, "/dev/mixer" ); 141 _mixer = new OMixerInterface( this, "/dev/mixer" );
142} 142}
143 143
144 144
145/*====================================================================================== 145/*======================================================================================
146 * OAudioInterface 146 * OAudioInterface
147 *======================================================================================*/ 147 *======================================================================================*/
148 148
149OAudioInterface::OAudioInterface( QObject* parent, const char* name ) 149OAudioInterface::OAudioInterface( QObject* parent, const char* name )
150 :QObject( parent, name ), _sfd(0) 150 :QObject( parent, name ), _sfd(0)
151{ 151{
152 odebug << "OAudioInterface::OAudioInterface()" << oendl; 152 odebug << "OAudioInterface::OAudioInterface()" << oendl;
153 init(); 153 init();
154} 154}
155 155
156 156
157OAudioInterface::~OAudioInterface() 157OAudioInterface::~OAudioInterface()
158{ 158{
159} 159}
160 160
161 161
162void OAudioInterface::init() 162void OAudioInterface::init()
163{ 163{
164 164
165 165
166} 166}
167 167
168 168
169/*====================================================================================== 169/*======================================================================================
170 * OMixerInterface 170 * OMixerInterface
171 *======================================================================================*/ 171 *======================================================================================*/
172 172
173OMixerInterface::OMixerInterface( QObject* parent, const char* name ) 173OMixerInterface::OMixerInterface( QObject* parent, const char* name )
174 :QObject( parent, name ) 174 :QObject( parent, name )
175{ 175{
176 odebug << "OMixerInterface::OMixerInterface()" << oendl; 176 odebug << "OMixerInterface::OMixerInterface()" << oendl;
177 init(); 177 init();
178} 178}
179 179
180 180
181OMixerInterface::~OMixerInterface() 181OMixerInterface::~OMixerInterface()
182{ 182{
183} 183}
184 184
185 185
186void OMixerInterface::init() 186void OMixerInterface::init()
187{ 187{
188 // open the device 188 // open the device
189 _fd = ::open( name(), O_RDWR ); 189 _fd = ::open( name(), O_RDWR );
190 if ( _fd == -1 ) 190 if ( _fd == -1 )
191 { 191 {
192 owarn << "OMixerInterface::init(): Can't open mixer." << oendl; 192 owarn << "OMixerInterface::init(): Can't open mixer." << oendl;
193 return; 193 return;
194 } 194 }
195 195
196 // construct the device capabilities 196 // construct the device capabilities
197 int devmask = 0; 197 int devmask = 0;
198 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) 198 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 )
199 { 199 {
200 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); 200 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME );
201 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS ); 201 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS );
202 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE ); 202 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE );
203 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH ); 203 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH );
204 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM ); 204 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM );
205 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER ); 205 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER );
206 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE ); 206 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE );
207 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC ); 207 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC );
208 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD ); 208 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD );
209 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX ); 209 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX );
210 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM ); 210 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM );
211 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV ); 211 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV );
212 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN ); 212 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN );
213 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN ); 213 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN );
214 //odebug << "devmask available and constructed." << oendl; 214 //odebug << "devmask available and constructed." << oendl;
215 } 215 }
216 216
217 devmask = 0; 217 devmask = 0;
218 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 ) 218 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 )
219 { 219 {
220 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME ); 220 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME );
221 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS ); 221 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS );
222 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE ); 222 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE );
223 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH ); 223 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH );
224 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM ); 224 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM );
225 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER ); 225 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER );
226 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE ); 226 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE );
227 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC ); 227 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC );
228 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD ); 228 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD );
229 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX ); 229 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX );
230 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM ); 230 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM );
231 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV ); 231 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV );
232 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN ); 232 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN );
233 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN ); 233 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN );
234 //odebug << "recmask available and constructed." << oendl; 234 //odebug << "recmask available and constructed." << oendl;
235 } 235 }
236 236
237/* ChannelIterator it; 237/* ChannelIterator it;
238 for ( it = _channels.begin(); it != _channels.end(); ++it ) 238 for ( it = _channels.begin(); it != _channels.end(); ++it )
239 { 239 {
240 qDebug( "Channel %s available (bit %d)", (const char*) it.key(), it.data() ); 240 odebug << "Channel " << it.key() << " available (bit " << it.data() << ")" << oendl;
241 qDebug( " +--- Volume: %02d | %02d", volume( it.key() ) & 0xff, volume( it.key() ) >> 8 ); 241 odebug << " +--- Volume: " << volume( it.key() ) & 0xff << " | " << volume( it.key() ) >> 8 << "" << oendl;
242 } 242 }
243*/ 243*/
244} 244}
245 245
246QStringList OMixerInterface::allChannels() const 246QStringList OMixerInterface::allChannels() const
247{ 247{
248 ChannelIterator it = _channels.begin(); 248 ChannelIterator it = _channels.begin();
249 QStringList channels; 249 QStringList channels;
250 while ( it != _channels.end() ) 250 while ( it != _channels.end() )
251 { 251 {
252 channels += it.key(); 252 channels += it.key();
253 it++; 253 it++;
254 } 254 }
255 return channels; 255 return channels;
256} 256}
257 257
258 258
259QStringList OMixerInterface::recChannels() const 259QStringList OMixerInterface::recChannels() const
260{ 260{
261 owarn << "NYI" << oendl; 261 owarn << "NYI" << oendl;
262} 262}
263 263
264 264
265QStringList OMixerInterface::playChannels() const 265QStringList OMixerInterface::playChannels() const
266{ 266{
267 owarn << "NYI" << oendl; 267 owarn << "NYI" << oendl;
268} 268}
269 269
270 270
271bool OMixerInterface::hasChannel( const QString& channel ) 271bool OMixerInterface::hasChannel( const QString& channel )
272{ 272{
273 return _channels.contains( channel ); 273 return _channels.contains( channel );
274} 274}
275 275
276 276
277void OMixerInterface::setVolume( const QString& channel, int left, int right ) 277void OMixerInterface::setVolume( const QString& channel, int left, int right )
278{ 278{
279 int volume = left; 279 int volume = left;
280 volume |= ( right == -1 ) ? left << 8 : right << 8; 280 volume |= ( right == -1 ) ? left << 8 : right << 8;
281 281
282 if ( _channels.contains( channel ) ) 282 if ( _channels.contains( channel ) )
283 { 283 {
284 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); 284 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume );
285 if ( result == -1 ) 285 if ( result == -1 )
286 { 286 {
287 owarn << "Can't set volume: " << strerror( errno ) << oendl; 287 owarn << "Can't set volume: " << strerror( errno ) << oendl;
288 } 288 }
289 else 289 else
290 { 290 {
291 if ( result & 0xff != left ) 291 if ( result & 0xff != left )
292 { 292 {
293 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; 293 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl;
294 } 294 }
295 } 295 }
296 } 296 }
297} 297}
298 298
299 299
300int OMixerInterface::volume( const QString& channel ) const 300int OMixerInterface::volume( const QString& channel ) const
301{ 301{
302 int volume; 302 int volume;
303 303
304 if ( _channels.contains( channel ) ) 304 if ( _channels.contains( channel ) )
305 { 305 {
306 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) 306 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 )
307 { 307 {
308 owarn << "Can't get volume: " << strerror( errno ) << oendl; 308 owarn << "Can't get volume: " << strerror( errno ) << oendl;
309 } 309 }
310 else return volume; 310 else return volume;
311 } 311 }
312 return -1; 312 return -1;
313} 313}
314 314
315 315
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index e141097..67718ba 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -352,516 +352,519 @@ ONetworkInterface::~ONetworkInterface()
352} 352}
353 353
354 354
355bool ONetworkInterface::setPromiscuousMode( bool b ) 355bool ONetworkInterface::setPromiscuousMode( bool b )
356{ 356{
357 ioctl( SIOCGIFFLAGS ); 357 ioctl( SIOCGIFFLAGS );
358 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 358 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
359 else _ifr.ifr_flags &= (~IFF_PROMISC); 359 else _ifr.ifr_flags &= (~IFF_PROMISC);
360 return ioctl( SIOCSIFFLAGS ); 360 return ioctl( SIOCSIFFLAGS );
361} 361}
362 362
363 363
364bool ONetworkInterface::promiscuousMode() const 364bool ONetworkInterface::promiscuousMode() const
365{ 365{
366 ioctl( SIOCGIFFLAGS ); 366 ioctl( SIOCGIFFLAGS );
367 return _ifr.ifr_flags & IFF_PROMISC; 367 return _ifr.ifr_flags & IFF_PROMISC;
368} 368}
369 369
370 370
371bool ONetworkInterface::isWireless() const 371bool ONetworkInterface::isWireless() const
372{ 372{
373 return ioctl( SIOCGIWNAME ); 373 return ioctl( SIOCGIWNAME );
374} 374}
375 375
376 376
377/*====================================================================================== 377/*======================================================================================
378 * OChannelHopper 378 * OChannelHopper
379 *======================================================================================*/ 379 *======================================================================================*/
380 380
381OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 381OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
382 :QObject( 0, "Mickey's funky hopper" ), 382 :QObject( 0, "Mickey's funky hopper" ),
383 _iface( iface ), _interval( 0 ), _tid( 0 ) 383 _iface( iface ), _interval( 0 ), _tid( 0 )
384{ 384{
385 int _maxChannel = iface->channels(); 385 int _maxChannel = iface->channels();
386 // generate fancy hopping sequence honoring the device capabilities 386 // generate fancy hopping sequence honoring the device capabilities
387 if ( _maxChannel >= 1 ) _channels.append( 1 ); 387 if ( _maxChannel >= 1 ) _channels.append( 1 );
388 if ( _maxChannel >= 7 ) _channels.append( 7 ); 388 if ( _maxChannel >= 7 ) _channels.append( 7 );
389 if ( _maxChannel >= 13 ) _channels.append( 13 ); 389 if ( _maxChannel >= 13 ) _channels.append( 13 );
390 if ( _maxChannel >= 2 ) _channels.append( 2 ); 390 if ( _maxChannel >= 2 ) _channels.append( 2 );
391 if ( _maxChannel >= 8 ) _channels.append( 8 ); 391 if ( _maxChannel >= 8 ) _channels.append( 8 );
392 if ( _maxChannel >= 3 ) _channels.append( 3 ); 392 if ( _maxChannel >= 3 ) _channels.append( 3 );
393 if ( _maxChannel >= 14 ) _channels.append( 14 ); 393 if ( _maxChannel >= 14 ) _channels.append( 14 );
394 if ( _maxChannel >= 9 ) _channels.append( 9 ); 394 if ( _maxChannel >= 9 ) _channels.append( 9 );
395 if ( _maxChannel >= 4 ) _channels.append( 4 ); 395 if ( _maxChannel >= 4 ) _channels.append( 4 );
396 if ( _maxChannel >= 10 ) _channels.append( 10 ); 396 if ( _maxChannel >= 10 ) _channels.append( 10 );
397 if ( _maxChannel >= 5 ) _channels.append( 5 ); 397 if ( _maxChannel >= 5 ) _channels.append( 5 );
398 if ( _maxChannel >= 11 ) _channels.append( 11 ); 398 if ( _maxChannel >= 11 ) _channels.append( 11 );
399 if ( _maxChannel >= 6 ) _channels.append( 6 ); 399 if ( _maxChannel >= 6 ) _channels.append( 6 );
400 if ( _maxChannel >= 12 ) _channels.append( 12 ); 400 if ( _maxChannel >= 12 ) _channels.append( 12 );
401 _channel = _channels.begin(); 401 _channel = _channels.begin();
402} 402}
403 403
404 404
405OChannelHopper::~OChannelHopper() 405OChannelHopper::~OChannelHopper()
406{ 406{
407} 407}
408 408
409 409
410bool OChannelHopper::isActive() const 410bool OChannelHopper::isActive() const
411{ 411{
412 return _tid; 412 return _tid;
413} 413}
414 414
415 415
416int OChannelHopper::channel() const 416int OChannelHopper::channel() const
417{ 417{
418 return *_channel; 418 return *_channel;
419} 419}
420 420
421 421
422void OChannelHopper::timerEvent( QTimerEvent* ) 422void OChannelHopper::timerEvent( QTimerEvent* )
423{ 423{
424 _iface->setChannel( *_channel ); 424 _iface->setChannel( *_channel );
425 emit( hopped( *_channel ) ); 425 emit( hopped( *_channel ) );
426 odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; 426 odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl;
427 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 427 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
428} 428}
429 429
430 430
431void OChannelHopper::setInterval( int interval ) 431void OChannelHopper::setInterval( int interval )
432{ 432{
433 if ( interval == _interval ) 433 if ( interval == _interval )
434 return; 434 return;
435 435
436 if ( _interval ) 436 if ( _interval )
437 killTimer( _tid ); 437 killTimer( _tid );
438 438
439 _tid = 0; 439 _tid = 0;
440 _interval = interval; 440 _interval = interval;
441 441
442 if ( _interval ) 442 if ( _interval )
443 { 443 {
444 _tid = startTimer( interval ); 444 _tid = startTimer( interval );
445 } 445 }
446} 446}
447 447
448 448
449int OChannelHopper::interval() const 449int OChannelHopper::interval() const
450{ 450{
451 return _interval; 451 return _interval;
452} 452}
453 453
454 454
455/*====================================================================================== 455/*======================================================================================
456 * OWirelessNetworkInterface 456 * OWirelessNetworkInterface
457 *======================================================================================*/ 457 *======================================================================================*/
458 458
459OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 459OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
460 :ONetworkInterface( parent, name ), _hopper( 0 ) 460 :ONetworkInterface( parent, name ), _hopper( 0 )
461{ 461{
462 odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; 462 odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl;
463 init(); 463 init();
464} 464}
465 465
466 466
467OWirelessNetworkInterface::~OWirelessNetworkInterface() 467OWirelessNetworkInterface::~OWirelessNetworkInterface()
468{ 468{
469} 469}
470 470
471 471
472struct iwreq& OWirelessNetworkInterface::iwr() const 472struct iwreq& OWirelessNetworkInterface::iwr() const
473{ 473{
474 return _iwr; 474 return _iwr;
475} 475}
476 476
477 477
478void OWirelessNetworkInterface::init() 478void OWirelessNetworkInterface::init()
479{ 479{
480 odebug << "OWirelessNetworkInterface::init()" << oendl; 480 odebug << "OWirelessNetworkInterface::init()" << oendl;
481 memset( &_iwr, 0, sizeof( struct iwreq ) ); 481 memset( &_iwr, 0, sizeof( struct iwreq ) );
482 buildInformation(); 482 buildInformation();
483 buildPrivateList(); 483 buildPrivateList();
484 dumpInformation(); 484 dumpInformation();
485} 485}
486 486
487 487
488bool OWirelessNetworkInterface::isAssociated() const 488bool OWirelessNetworkInterface::isAssociated() const
489{ 489{
490 //FIXME: handle different modes 490 //FIXME: handle different modes
491 return !(associatedAP() == OMacAddress::unknown); 491 return !(associatedAP() == OMacAddress::unknown);
492} 492}
493 493
494 494
495OMacAddress OWirelessNetworkInterface::associatedAP() const 495OMacAddress OWirelessNetworkInterface::associatedAP() const
496{ 496{
497 if ( ioctl( SIOCGIWAP ) ) 497 if ( ioctl( SIOCGIWAP ) )
498 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; 498 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
499 else 499 else
500 return OMacAddress::unknown; 500 return OMacAddress::unknown;
501} 501}
502 502
503 503
504void OWirelessNetworkInterface::buildInformation() 504void OWirelessNetworkInterface::buildInformation()
505{ 505{
506 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 506 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
507 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 507 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
508 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 508 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
509 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 509 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
510 //ML: _too much_ space. This is damn shitty crap *sigh* 510 //ML: _too much_ space. This is damn shitty crap *sigh*
511 //ML: We allocate a large memory region in RAM and check whether the 511 //ML: We allocate a large memory region in RAM and check whether the
512 //ML: driver pollutes this extra space. The complaint will be made on stdout, 512 //ML: driver pollutes this extra space. The complaint will be made on stdout,
513 //ML: so please forward this... 513 //ML: so please forward this...
514 514
515 struct iwreq wrq; 515 struct iwreq wrq;
516 int len = sizeof( struct iw_range )*2; 516 int len = sizeof( struct iw_range )*2;
517 char *buffer = (char*) malloc( len ); 517 char *buffer = (char*) malloc( len );
518 //FIXME: Validate if we actually got the memory block 518 //FIXME: Validate if we actually got the memory block
519 memset( buffer, 0, len ); 519 memset( buffer, 0, len );
520 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 520 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
521 wrq.u.data.pointer = (caddr_t) buffer; 521 wrq.u.data.pointer = (caddr_t) buffer;
522 wrq.u.data.length = sizeof( struct iw_range ); 522 wrq.u.data.length = sizeof( struct iw_range );
523 wrq.u.data.flags = 0; 523 wrq.u.data.flags = 0;
524 524
525 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 525 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
526 { 526 {
527 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; 527 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl;
528 _channels.insert( 2412, 1 ); // 2.412 GHz 528 _channels.insert( 2412, 1 ); // 2.412 GHz
529 _channels.insert( 2417, 2 ); // 2.417 GHz 529 _channels.insert( 2417, 2 ); // 2.417 GHz
530 _channels.insert( 2422, 3 ); // 2.422 GHz 530 _channels.insert( 2422, 3 ); // 2.422 GHz
531 _channels.insert( 2427, 4 ); // 2.427 GHz 531 _channels.insert( 2427, 4 ); // 2.427 GHz
532 _channels.insert( 2432, 5 ); // 2.432 GHz 532 _channels.insert( 2432, 5 ); // 2.432 GHz
533 _channels.insert( 2437, 6 ); // 2.437 GHz 533 _channels.insert( 2437, 6 ); // 2.437 GHz
534 _channels.insert( 2442, 7 ); // 2.442 GHz 534 _channels.insert( 2442, 7 ); // 2.442 GHz
535 _channels.insert( 2447, 8 ); // 2.447 GHz 535 _channels.insert( 2447, 8 ); // 2.447 GHz
536 _channels.insert( 2452, 9 ); // 2.452 GHz 536 _channels.insert( 2452, 9 ); // 2.452 GHz
537 _channels.insert( 2457, 10 ); // 2.457 GHz 537 _channels.insert( 2457, 10 ); // 2.457 GHz
538 _channels.insert( 2462, 11 ); // 2.462 GHz 538 _channels.insert( 2462, 11 ); // 2.462 GHz
539 539
540 memset( &_range, 0, sizeof( struct iw_range ) ); 540 memset( &_range, 0, sizeof( struct iw_range ) );
541 } 541 }
542 else 542 else
543 { 543 {
544 // <check if the driver overwrites stuff> 544 // <check if the driver overwrites stuff>
545 int max = 0; 545 int max = 0;
546 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 546 for ( int r = sizeof( struct iw_range ); r < len; r++ )
547 if (buffer[r] != 0) 547 if (buffer[r] != 0)
548 max = r; 548 max = r;
549 if (max > 0) 549 if (max > 0)
550 { 550 {
551 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() 551 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name()
552 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; 552 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl;
553 } 553 }
554 // </check if the driver overwrites stuff> 554 // </check if the driver overwrites stuff>
555 555
556 struct iw_range range; 556 struct iw_range range;
557 memcpy( &range, buffer, sizeof range ); 557 memcpy( &range, buffer, sizeof range );
558 558
559 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; 559 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl;
560 for ( int i = 0; i < range.num_frequency; ++i ) 560 for ( int i = 0; i < range.num_frequency; ++i )
561 { 561 {
562 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 562 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
563 odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl; 563 odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl;
564 _channels.insert( freq, i+1 ); 564 _channels.insert( freq, i+1 );
565 } 565 }
566 } 566 }
567 567
568 memcpy( &_range, buffer, sizeof( struct iw_range ) ); 568 memcpy( &_range, buffer, sizeof( struct iw_range ) );
569 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; 569 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl;
570 free(buffer); 570 free(buffer);
571} 571}
572 572
573 573
574short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const 574short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const
575{ 575{
576 return _range.we_version_compiled; 576 return _range.we_version_compiled;
577} 577}
578 578
579 579
580void OWirelessNetworkInterface::buildPrivateList() 580void OWirelessNetworkInterface::buildPrivateList()
581{ 581{
582 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; 582 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl;
583 583
584 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 584 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
585 585
586 _iwr.u.data.pointer = (char*) &priv; 586 _iwr.u.data.pointer = (char*) &priv;
587 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 587 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
588 _iwr.u.data.flags = 0; 588 _iwr.u.data.flags = 0;
589 589
590 if ( !wioctl( SIOCGIWPRIV ) ) 590 if ( !wioctl( SIOCGIWPRIV ) )
591 { 591 {
592 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; 592 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl;
593 return; 593 return;
594 } 594 }
595 595
596 for ( int i = 0; i < _iwr.u.data.length; ++i ) 596 for ( int i = 0; i < _iwr.u.data.length; ++i )
597 { 597 {
598 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 598 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
599 } 599 }
600 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; 600 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl;
601} 601}
602 602
603 603
604void OWirelessNetworkInterface::dumpInformation() const 604void OWirelessNetworkInterface::dumpInformation() const
605{ 605{
606 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; 606 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl;
607 607
608 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", 608 odebug << " - driver's idea of maximum throughput is " << _range.throughput
609 _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); 609 << " bps = " << ( _range.throughput / 8 ) << " byte/s = " << ( _range.throughput / 8 / 1024 )
610 qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", 610 << " Kb/s = " << QString().sprintf("%f.2", float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 )
611 name(), _range.we_version_source, _range.we_version_compiled ); 611 << " Mb/s" << oendl;
612
613 odebug << " - driver for '" << name() << "' (V" << _range.we_version_source
614 << ") has been compiled against WE V" << _range.we_version_compiled << oendl;
612 615
613 if ( _range.we_version_compiled != WIRELESS_EXT ) 616 if ( _range.we_version_compiled != WIRELESS_EXT )
614 { 617 {
615 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; 618 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl;
616 } 619 }
617 620
618 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; 621 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl;
619} 622}
620 623
621 624
622int OWirelessNetworkInterface::channel() const 625int OWirelessNetworkInterface::channel() const
623{ 626{
624 //FIXME: When monitoring enabled, then use it 627 //FIXME: When monitoring enabled, then use it
625 //FIXME: to gather the current RF channel 628 //FIXME: to gather the current RF channel
626 //FIXME: Until then, get active channel from hopper. 629 //FIXME: Until then, get active channel from hopper.
627 if ( _hopper && _hopper->isActive() ) 630 if ( _hopper && _hopper->isActive() )
628 return _hopper->channel(); 631 return _hopper->channel();
629 632
630 if ( !wioctl( SIOCGIWFREQ ) ) 633 if ( !wioctl( SIOCGIWFREQ ) )
631 { 634 {
632 return -1; 635 return -1;
633 } 636 }
634 else 637 else
635 { 638 {
636 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 639 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
637 } 640 }
638} 641}
639 642
640 643
641void OWirelessNetworkInterface::setChannel( int c ) const 644void OWirelessNetworkInterface::setChannel( int c ) const
642{ 645{
643 if ( !c ) 646 if ( !c )
644 { 647 {
645 oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; 648 oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl;
646 return; 649 return;
647 } 650 }
648 651
649 if ( !_mon ) 652 if ( !_mon )
650 { 653 {
651 memset( &_iwr, 0, sizeof( struct iwreq ) ); 654 memset( &_iwr, 0, sizeof( struct iwreq ) );
652 _iwr.u.freq.m = c; 655 _iwr.u.freq.m = c;
653 _iwr.u.freq.e = 0; 656 _iwr.u.freq.e = 0;
654 wioctl( SIOCSIWFREQ ); 657 wioctl( SIOCSIWFREQ );
655 } 658 }
656 else 659 else
657 { 660 {
658 _mon->setChannel( c ); 661 _mon->setChannel( c );
659 } 662 }
660} 663}
661 664
662 665
663double OWirelessNetworkInterface::frequency() const 666double OWirelessNetworkInterface::frequency() const
664{ 667{
665 if ( !wioctl( SIOCGIWFREQ ) ) 668 if ( !wioctl( SIOCGIWFREQ ) )
666 { 669 {
667 return -1.0; 670 return -1.0;
668 } 671 }
669 else 672 else
670 { 673 {
671 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 674 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
672 } 675 }
673} 676}
674 677
675 678
676int OWirelessNetworkInterface::channels() const 679int OWirelessNetworkInterface::channels() const
677{ 680{
678 return _channels.count(); 681 return _channels.count();
679} 682}
680 683
681 684
682void OWirelessNetworkInterface::setChannelHopping( int interval ) 685void OWirelessNetworkInterface::setChannelHopping( int interval )
683{ 686{
684 if ( !_hopper ) _hopper = new OChannelHopper( this ); 687 if ( !_hopper ) _hopper = new OChannelHopper( this );
685 _hopper->setInterval( interval ); 688 _hopper->setInterval( interval );
686 //FIXME: When and by whom will the channel hopper be deleted? 689 //FIXME: When and by whom will the channel hopper be deleted?
687 //TODO: rely on QObject hierarchy 690 //TODO: rely on QObject hierarchy
688} 691}
689 692
690 693
691int OWirelessNetworkInterface::channelHopping() const 694int OWirelessNetworkInterface::channelHopping() const
692{ 695{
693 return _hopper->interval(); 696 return _hopper->interval();
694} 697}
695 698
696 699
697OChannelHopper* OWirelessNetworkInterface::channelHopper() const 700OChannelHopper* OWirelessNetworkInterface::channelHopper() const
698{ 701{
699 return _hopper; 702 return _hopper;
700} 703}
701 704
702 705
703void OWirelessNetworkInterface::commit() const 706void OWirelessNetworkInterface::commit() const
704{ 707{
705 wioctl( SIOCSIWCOMMIT ); 708 wioctl( SIOCSIWCOMMIT );
706} 709}
707 710
708 711
709void OWirelessNetworkInterface::setMode( const QString& newMode ) 712void OWirelessNetworkInterface::setMode( const QString& newMode )
710{ 713{
711 #ifdef FINALIZE 714 #ifdef FINALIZE
712 QString currentMode = mode(); 715 QString currentMode = mode();
713 if ( currentMode == newMode ) return; 716 if ( currentMode == newMode ) return;
714 #endif 717 #endif
715 718
716 odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; 719 odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl;
717 720
718 _iwr.u.mode = stringToMode( newMode ); 721 _iwr.u.mode = stringToMode( newMode );
719 722
720 if ( _iwr.u.mode != IW_MODE_MONITOR ) 723 if ( _iwr.u.mode != IW_MODE_MONITOR )
721 { 724 {
722 // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! 725 // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP!
723 _iwr.u.mode = stringToMode( newMode ); 726 _iwr.u.mode = stringToMode( newMode );
724 wioctl( SIOCSIWMODE ); 727 wioctl( SIOCSIWMODE );
725 728
726 // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) 729 // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now)
727 730
728 if ( mode() == "monitor" ) 731 if ( mode() == "monitor" )
729 { 732 {
730 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; 733 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl;
731 if ( _mon ) 734 if ( _mon )
732 _mon->setEnabled( false ); 735 _mon->setEnabled( false );
733 else 736 else
734 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; 737 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl;
735 } 738 }
736 739
737 } 740 }
738 else // special iwpriv fallback for monitor mode 741 else // special iwpriv fallback for monitor mode
739 { 742 {
740 if ( wioctl( SIOCSIWMODE ) ) 743 if ( wioctl( SIOCSIWMODE ) )
741 { 744 {
742 odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; 745 odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl;
743 } 746 }
744 else 747 else
745 { 748 {
746 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; 749 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl;
747 750
748 if ( _mon ) 751 if ( _mon )
749 _mon->setEnabled( true ); 752 _mon->setEnabled( true );
750 else 753 else
751 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; 754 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl;
752 } 755 }
753 } 756 }
754} 757}
755 758
756 759
757QString OWirelessNetworkInterface::mode() const 760QString OWirelessNetworkInterface::mode() const
758{ 761{
759 memset( &_iwr, 0, sizeof( struct iwreq ) ); 762 memset( &_iwr, 0, sizeof( struct iwreq ) );
760 763
761 if ( !wioctl( SIOCGIWMODE ) ) 764 if ( !wioctl( SIOCGIWMODE ) )
762 { 765 {
763 return "<unknown>"; 766 return "<unknown>";
764 } 767 }
765 768
766 odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; 769 odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl;
767 770
768 // legacy compatible monitor mode check 771 // legacy compatible monitor mode check
769 772
770 if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) 773 if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 )
771 { 774 {
772 return "monitor"; 775 return "monitor";
773 } 776 }
774 else 777 else
775 { 778 {
776 return modeToString( _iwr.u.mode ); 779 return modeToString( _iwr.u.mode );
777 } 780 }
778} 781}
779 782
780void OWirelessNetworkInterface::setNickName( const QString& nickname ) 783void OWirelessNetworkInterface::setNickName( const QString& nickname )
781{ 784{
782 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 785 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
783 _iwr.u.essid.length = nickname.length(); 786 _iwr.u.essid.length = nickname.length();
784 wioctl( SIOCSIWNICKN ); 787 wioctl( SIOCSIWNICKN );
785} 788}
786 789
787 790
788QString OWirelessNetworkInterface::nickName() const 791QString OWirelessNetworkInterface::nickName() const
789{ 792{
790 char str[IW_ESSID_MAX_SIZE]; 793 char str[IW_ESSID_MAX_SIZE];
791 _iwr.u.data.pointer = &str[0]; 794 _iwr.u.data.pointer = &str[0];
792 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 795 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
793 if ( !wioctl( SIOCGIWNICKN ) ) 796 if ( !wioctl( SIOCGIWNICKN ) )
794 { 797 {
795 return "<unknown>"; 798 return "<unknown>";
796 } 799 }
797 else 800 else
798 { 801 {
799 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 802 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
800 return str; 803 return str;
801 } 804 }
802} 805}
803 806
804 807
805void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 808void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
806{ 809{
807 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 810 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
808 if ( !priv ) 811 if ( !priv )
809 { 812 {
810 owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() 813 owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name()
811 << "' does not support private ioctl '" << call << "'" << oendl; 814 << "' does not support private ioctl '" << call << "'" << oendl;
812 return; 815 return;
813 } 816 }
814 if ( priv->numberSetArgs() != numargs ) 817 if ( priv->numberSetArgs() != numargs )
815 { 818 {
816 owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" 819 owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '"
817 << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; 820 << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl;
818 return; 821 return;
819 } 822 }
820 823
821 odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; 824 odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl;
822 memset( &_iwr, 0, sizeof _iwr ); 825 memset( &_iwr, 0, sizeof _iwr );
823 va_list argp; 826 va_list argp;
824 va_start( argp, numargs ); 827 va_start( argp, numargs );
825 for ( int i = 0; i < numargs; ++i ) 828 for ( int i = 0; i < numargs; ++i )
826 { 829 {
827 priv->setParameter( i, va_arg( argp, int ) ); 830 priv->setParameter( i, va_arg( argp, int ) );
828 } 831 }
829 va_end( argp ); 832 va_end( argp );
830 priv->invoke(); 833 priv->invoke();
831} 834}
832 835
833 836
834void OWirelessNetworkInterface::getPrivate( const QString& call ) 837void OWirelessNetworkInterface::getPrivate( const QString& call )
835{ 838{
836 oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; 839 oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl;
837} 840}
838 841
839 842
840bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 843bool OWirelessNetworkInterface::hasPrivate( const QString& call )
841{ 844{
842 return child( (const char*) call ); 845 return child( (const char*) call );
843} 846}
844 847
845 848
846QString OWirelessNetworkInterface::SSID() const 849QString OWirelessNetworkInterface::SSID() const
847{ 850{
848 char str[IW_ESSID_MAX_SIZE]; 851 char str[IW_ESSID_MAX_SIZE];
849 _iwr.u.essid.pointer = &str[0]; 852 _iwr.u.essid.pointer = &str[0];
850 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 853 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
851 if ( !wioctl( SIOCGIWESSID ) ) 854 if ( !wioctl( SIOCGIWESSID ) )
852 { 855 {
853 return "<unknown>"; 856 return "<unknown>";
854 } 857 }
855 else 858 else
856 { 859 {
857 return str; 860 return str;
858 } 861 }
859} 862}
860 863
861 864
862void OWirelessNetworkInterface::setSSID( const QString& ssid ) 865void OWirelessNetworkInterface::setSSID( const QString& ssid )
863{ 866{
864 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 867 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
865 _iwr.u.essid.length = ssid.length(); 868 _iwr.u.essid.length = ssid.length();
866 wioctl( SIOCSIWESSID ); 869 wioctl( SIOCSIWESSID );
867} 870}
diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp
index ce0995b..b5ac325 100644
--- a/libopie2/opienet/ostation.cpp
+++ b/libopie2/opienet/ostation.cpp
@@ -1,72 +1,72 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> 3              Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
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#include <opie2/ostation.h> 31#include <opie2/ostation.h>
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33 33
34 34
35using namespace Opie::Core; 35using namespace Opie::Core;
36 36
37namespace Opie { 37namespace Opie {
38namespace Net { 38namespace Net {
39/*====================================================================================== 39/*======================================================================================
40 * OStation 40 * OStation
41 *======================================================================================*/ 41 *======================================================================================*/
42 42
43OStation::OStation() 43OStation::OStation()
44{ 44{
45 odebug << "OStation::OStation()" << oendl; 45 odebug << "OStation::OStation()" << oendl;
46 46
47 type = "<unknown>"; 47 type = "<unknown>";
48 macAddress = OMacAddress::unknown; 48 macAddress = OMacAddress::unknown;
49 ssid = "<unknown>"; 49 ssid = "<unknown>";
50 channel = 0; 50 channel = 0;
51 apAddress = OMacAddress::unknown; 51 apAddress = OMacAddress::unknown;
52 52
53} 53}
54 54
55 55
56OStation::~OStation() 56OStation::~OStation()
57{ 57{
58 odebug << "OStation::~OStation()" << oendl; 58 odebug << "OStation::~OStation()" << oendl;
59} 59}
60 60
61 61
62void OStation::dump() 62void OStation::dump()
63{ 63{
64 odebug << "------- OStation::dump() ------------" << oendl; 64 odebug << "------- OStation::dump() ------------" << oendl;
65 qDebug( "type: %s", (const char*) type ); 65 odebug << "type: " << type << "" << oendl;
66 qDebug( "mac: %s", (const char*) macAddress.toString() ); 66 odebug << "mac: " << macAddress.toString() << "" << oendl;
67 qDebug( "ap: %s", (const char*) apAddress.toString() ); 67 odebug << "ap: " << apAddress.toString() << "" << oendl;
68 qDebug( "ip: %s", (const char*) ipAddress.toString() ); 68 odebug << "ip: " << ipAddress.toString() << "" << oendl;
69} 69}
70 70
71} 71}
72} 72}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index 14207be..dda23cc 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -1,852 +1,856 @@
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 * SQL Backend for the OPIE-Contact Database. 30 * SQL Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33#include "ocontactaccessbackend_sql.h" 33#include "ocontactaccessbackend_sql.h"
34 34
35#include <qarray.h> 35/* OPIE */
36#include <qdatetime.h>
37#include <qstringlist.h>
38
39#include <qpe/global.h>
40#include <qpe/recordfields.h>
41
42#include <opie2/opimcontact.h> 36#include <opie2/opimcontact.h>
43#include <opie2/opimcontactfields.h> 37#include <opie2/opimcontactfields.h>
44#include <opie2/opimdateconversion.h> 38#include <opie2/opimdateconversion.h>
45#include <opie2/osqldriver.h> 39#include <opie2/osqldriver.h>
46#include <opie2/osqlresult.h> 40#include <opie2/osqlresult.h>
47#include <opie2/osqlmanager.h> 41#include <opie2/osqlmanager.h>
48#include <opie2/osqlquery.h> 42#include <opie2/osqlquery.h>
43#include <opie2/odebug.h>
44
45#include <qpe/global.h>
46#include <qpe/recordfields.h>
47
48/* QT */
49#include <qarray.h>
50#include <qdatetime.h>
51#include <qstringlist.h>
52
49 53
50using namespace Opie; 54using namespace Opie;
51using namespace Opie::DB; 55using namespace Opie::DB;
52 56
53 57
54/* 58/*
55 * Implementation of used query types * CREATE query 59 * Implementation of used query types * CREATE query
56 * LOAD query 60 * LOAD query
57 * INSERT 61 * INSERT
58 * REMOVE 62 * REMOVE
59 * CLEAR 63 * CLEAR
60 */ 64 */
61namespace { 65namespace {
62 /** 66 /**
63 * CreateQuery for the Todolist Table 67 * CreateQuery for the Todolist Table
64 */ 68 */
65 class CreateQuery : public OSQLQuery { 69 class CreateQuery : public OSQLQuery {
66 public: 70 public:
67 CreateQuery(); 71 CreateQuery();
68 ~CreateQuery(); 72 ~CreateQuery();
69 QString query()const; 73 QString query()const;
70 }; 74 };
71 75
72 /** 76 /**
73 * Clears (delete) a Table 77 * Clears (delete) a Table
74 */ 78 */
75 class ClearQuery : public OSQLQuery { 79 class ClearQuery : public OSQLQuery {
76 public: 80 public:
77 ClearQuery(); 81 ClearQuery();
78 ~ClearQuery(); 82 ~ClearQuery();
79 QString query()const; 83 QString query()const;
80 84
81 }; 85 };
82 86
83 87
84 /** 88 /**
85 * LoadQuery 89 * LoadQuery
86 * this one queries for all uids 90 * this one queries for all uids
87 */ 91 */
88 class LoadQuery : public OSQLQuery { 92 class LoadQuery : public OSQLQuery {
89 public: 93 public:
90 LoadQuery(); 94 LoadQuery();
91 ~LoadQuery(); 95 ~LoadQuery();
92 QString query()const; 96 QString query()const;
93 }; 97 };
94 98
95 /** 99 /**
96 * inserts/adds a OPimContact to the table 100 * inserts/adds a OPimContact to the table
97 */ 101 */
98 class InsertQuery : public OSQLQuery { 102 class InsertQuery : public OSQLQuery {
99 public: 103 public:
100 InsertQuery(const OPimContact& ); 104 InsertQuery(const OPimContact& );
101 ~InsertQuery(); 105 ~InsertQuery();
102 QString query()const; 106 QString query()const;
103 private: 107 private:
104 OPimContact m_contact; 108 OPimContact m_contact;
105 }; 109 };
106 110
107 111
108 /** 112 /**
109 * removes one from the table 113 * removes one from the table
110 */ 114 */
111 class RemoveQuery : public OSQLQuery { 115 class RemoveQuery : public OSQLQuery {
112 public: 116 public:
113 RemoveQuery(int uid ); 117 RemoveQuery(int uid );
114 ~RemoveQuery(); 118 ~RemoveQuery();
115 QString query()const; 119 QString query()const;
116 private: 120 private:
117 int m_uid; 121 int m_uid;
118 }; 122 };
119 123
120 /** 124 /**
121 * a find query for noncustom elements 125 * a find query for noncustom elements
122 */ 126 */
123 class FindQuery : public OSQLQuery { 127 class FindQuery : public OSQLQuery {
124 public: 128 public:
125 FindQuery(int uid); 129 FindQuery(int uid);
126 FindQuery(const QArray<int>& ); 130 FindQuery(const QArray<int>& );
127 ~FindQuery(); 131 ~FindQuery();
128 QString query()const; 132 QString query()const;
129 private: 133 private:
130 QString single()const; 134 QString single()const;
131 QString multi()const; 135 QString multi()const;
132 QArray<int> m_uids; 136 QArray<int> m_uids;
133 int m_uid; 137 int m_uid;
134 }; 138 };
135 139
136 /** 140 /**
137 * a find query for custom elements 141 * a find query for custom elements
138 */ 142 */
139 class FindCustomQuery : public OSQLQuery { 143 class FindCustomQuery : public OSQLQuery {
140 public: 144 public:
141 FindCustomQuery(int uid); 145 FindCustomQuery(int uid);
142 FindCustomQuery(const QArray<int>& ); 146 FindCustomQuery(const QArray<int>& );
143 ~FindCustomQuery(); 147 ~FindCustomQuery();
144 QString query()const; 148 QString query()const;
145 private: 149 private:
146 QString single()const; 150 QString single()const;
147 QString multi()const; 151 QString multi()const;
148 QArray<int> m_uids; 152 QArray<int> m_uids;
149 int m_uid; 153 int m_uid;
150 }; 154 };
151 155
152 156
153 157
154 // We using two tables to store the information: 158 // We using two tables to store the information:
155 // 1. addressbook : It contains General information about the contact (non custom) 159 // 1. addressbook : It contains General information about the contact (non custom)
156 // 2. custom_data : Not official supported entries 160 // 2. custom_data : Not official supported entries
157 // All tables are connected by the uid of the contact. 161 // All tables are connected by the uid of the contact.
158 // Maybe I should add a table for meta-information ? 162 // Maybe I should add a table for meta-information ?
159 CreateQuery::CreateQuery() : OSQLQuery() {} 163 CreateQuery::CreateQuery() : OSQLQuery() {}
160 CreateQuery::~CreateQuery() {} 164 CreateQuery::~CreateQuery() {}
161 QString CreateQuery::query()const { 165 QString CreateQuery::query()const {
162 QString qu; 166 QString qu;
163 167
164 qu += "create table addressbook( uid PRIMARY KEY "; 168 qu += "create table addressbook( uid PRIMARY KEY ";
165 169
166 QStringList fieldList = OPimContactFields::untrfields( false ); 170 QStringList fieldList = OPimContactFields::untrfields( false );
167 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 171 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
168 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); 172 qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it );
169 } 173 }
170 qu += " );"; 174 qu += " );";
171 175
172 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 176 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
173 177
174 return qu; 178 return qu;
175 } 179 }
176 180
177 ClearQuery::ClearQuery() 181 ClearQuery::ClearQuery()
178 : OSQLQuery() {} 182 : OSQLQuery() {}
179 ClearQuery::~ClearQuery() {} 183 ClearQuery::~ClearQuery() {}
180 QString ClearQuery::query()const { 184 QString ClearQuery::query()const {
181 QString qu = "drop table addressbook;"; 185 QString qu = "drop table addressbook;";
182 qu += "drop table custom_data;"; 186 qu += "drop table custom_data;";
183 // qu += "drop table dates;"; 187// qu += "drop table dates;";
184 return qu; 188 return qu;
185 } 189 }
186 190
187 191
188 LoadQuery::LoadQuery() : OSQLQuery() {} 192 LoadQuery::LoadQuery() : OSQLQuery() {}
189 LoadQuery::~LoadQuery() {} 193 LoadQuery::~LoadQuery() {}
190 QString LoadQuery::query()const { 194 QString LoadQuery::query()const {
191 QString qu; 195 QString qu;
192 qu += "select uid from addressbook"; 196 qu += "select uid from addressbook";
193 197
194 return qu; 198 return qu;
195 } 199 }
196 200
197 201
198 InsertQuery::InsertQuery( const OPimContact& contact ) 202 InsertQuery::InsertQuery( const OPimContact& contact )
199 : OSQLQuery(), m_contact( contact ) { 203 : OSQLQuery(), m_contact( contact ) {
200 } 204 }
201 205
202 InsertQuery::~InsertQuery() { 206 InsertQuery::~InsertQuery() {
203 } 207 }
204 208
205 /* 209 /*
206 * converts from a OPimContact to a query 210 * converts from a OPimContact to a query
207 */ 211 */
208 QString InsertQuery::query()const{ 212 QString InsertQuery::query()const{
209 213
210 QString qu; 214 QString qu;
211 qu += "insert into addressbook VALUES( " + 215 qu += "insert into addressbook VALUES( " +
212 QString::number( m_contact.uid() ); 216 QString::number( m_contact.uid() );
213 217
214 // Get all information out of the contact-class 218 // Get all information out of the contact-class
215 // Remember: The category is stored in contactMap, too ! 219 // Remember: The category is stored in contactMap, too !
216 QMap<int, QString> contactMap = m_contact.toMap(); 220 QMap<int, QString> contactMap = m_contact.toMap();
217 221
218 QStringList fieldList = OPimContactFields::untrfields( false ); 222 QStringList fieldList = OPimContactFields::untrfields( false );
219 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 223 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
220 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 224 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
221 // Convert Column-String to Id and get value for this id.. 225 // Convert Column-String to Id and get value for this id..
222 // Hmmm.. Maybe not very cute solution.. 226 // Hmmm.. Maybe not very cute solution..
223 int id = translate[*it]; 227 int id = translate[*it];
224 switch ( id ){ 228 switch ( id ){
225 case Qtopia::Birthday: 229 case Qtopia::Birthday:
226 case Qtopia::Anniversary:{ 230 case Qtopia::Anniversary:{
227 QDate day; 231 QDate day;
228 if ( id == Qtopia::Birthday ){ 232 if ( id == Qtopia::Birthday ){
229 day = m_contact.birthday(); 233 day = m_contact.birthday();
230 } else { 234 } else {
231 day = m_contact.anniversary(); 235 day = m_contact.anniversary();
232 } 236 }
233 // These entries should stored in a special format 237 // These entries should stored in a special format
234 // year-month-day 238 // year-month-day
235 if ( day.isValid() ){ 239 if ( day.isValid() ){
236 qu += QString(",\"%1-%2-%3\"") 240 qu += QString(",\"%1-%2-%3\"")
237 .arg( QString::number( day.year() ).rightJustify( 4, '0' ) ) 241 .arg( QString::number( day.year() ).rightJustify( 4, '0' ) )
238 .arg( QString::number( day.month() ).rightJustify( 2, '0' ) ) 242 .arg( QString::number( day.month() ).rightJustify( 2, '0' ) )
239 .arg( QString::number( day.day() ).rightJustify( 2, '0' ) ); 243 .arg( QString::number( day.day() ).rightJustify( 2, '0' ) );
240 } else { 244 } else {
241 qu += ",\"\""; 245 qu += ",\"\"";
242 } 246 }
243 } 247 }
244 break; 248 break;
245 default: 249 default:
246 qu += QString( ",\"%1\"" ).arg( contactMap[id] ); 250 qu += QString( ",\"%1\"" ).arg( contactMap[id] );
247 } 251 }
248 } 252 }
249 qu += " );"; 253 qu += " );";
250 254
251 255
252 // Now add custom data.. 256 // Now add custom data..
253 int id = 0; 257 int id = 0;
254 id = 0; 258 id = 0;
255 QMap<QString, QString> customMap = m_contact.toExtraMap(); 259 QMap<QString, QString> customMap = m_contact.toExtraMap();
256 for( QMap<QString, QString>::Iterator it = customMap.begin(); 260 for( QMap<QString, QString>::Iterator it = customMap.begin();
257 it != customMap.end(); ++it ){ 261 it != customMap.end(); ++it ){
258 qu += "insert into custom_data VALUES(" 262 qu += "insert into custom_data VALUES("
259 + QString::number( m_contact.uid() ) 263 + QString::number( m_contact.uid() )
260 + "," 264 + ","
261 + QString::number( id++ ) 265 + QString::number( id++ )
262 + ",'" 266 + ",'"
263 + it.key() 267 + it.key()
264 + "'," 268 + "',"
265 + "0" // Priority for future enhancements 269 + "0" // Priority for future enhancements
266 + ",'" 270 + ",'"
267 + it.data() 271 + it.data()
268 + "');"; 272 + "');";
269 } 273 }
270 // qu += "commit;"; 274 // qu += "commit;";
271 qDebug("add %s", qu.latin1() ); 275 odebug << "add " << qu << "" << oendl;
272 return qu; 276 return qu;
273 } 277 }
274 278
275 279
276 RemoveQuery::RemoveQuery(int uid ) 280 RemoveQuery::RemoveQuery(int uid )
277 : OSQLQuery(), m_uid( uid ) {} 281 : OSQLQuery(), m_uid( uid ) {}
278 RemoveQuery::~RemoveQuery() {} 282 RemoveQuery::~RemoveQuery() {}
279 QString RemoveQuery::query()const { 283 QString RemoveQuery::query()const {
280 QString qu = "DELETE from addressbook where uid = " 284 QString qu = "DELETE from addressbook where uid = "
281 + QString::number(m_uid) + ";"; 285 + QString::number(m_uid) + ";";
282 qu += "DELETE from custom_data where uid = " 286 qu += "DELETE from custom_data where uid = "
283 + QString::number(m_uid) + ";"; 287 + QString::number(m_uid) + ";";
284 return qu; 288 return qu;
285 } 289 }
286 290
287 291
288 292
289 293
290 FindQuery::FindQuery(int uid) 294 FindQuery::FindQuery(int uid)
291 : OSQLQuery(), m_uid( uid ) { 295 : OSQLQuery(), m_uid( uid ) {
292 } 296 }
293 FindQuery::FindQuery(const QArray<int>& ints) 297 FindQuery::FindQuery(const QArray<int>& ints)
294 : OSQLQuery(), m_uids( ints ){ 298 : OSQLQuery(), m_uids( ints ){
295 } 299 }
296 FindQuery::~FindQuery() { 300 FindQuery::~FindQuery() {
297 } 301 }
298 QString FindQuery::query()const{ 302 QString FindQuery::query()const{
299 // if ( m_uids.count() == 0 ) 303// if ( m_uids.count() == 0 )
300 return single(); 304 return single();
301 } 305 }
302 /* 306 /*
303 else 307 else
304 return multi(); 308 return multi();
305 } 309 }
306 QString FindQuery::multi()const { 310 QString FindQuery::multi()const {
307 QString qu = "select uid, type, value from addressbook where"; 311 QString qu = "select uid, type, value from addressbook where";
308 for (uint i = 0; i < m_uids.count(); i++ ) { 312 for (uint i = 0; i < m_uids.count(); i++ ) {
309 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 313 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
310 } 314 }
311 qu.remove( qu.length()-2, 2 ); // Hmmmm.. 315 qu.remove( qu.length()-2, 2 ); // Hmmmm..
312 return qu; 316 return qu;
313 } 317 }
314 */ 318 */
315 QString FindQuery::single()const{ 319 QString FindQuery::single()const{
316 QString qu = "select *"; 320 QString qu = "select *";
317 qu += " from addressbook where uid = " + QString::number(m_uid); 321 qu += " from addressbook where uid = " + QString::number(m_uid);
318 322
319 // qWarning("find query: %s", qu.latin1() ); 323 // owarn << "find query: " << qu << "" << oendl;
320 return qu; 324 return qu;
321 } 325 }
322 326
323 327
324 FindCustomQuery::FindCustomQuery(int uid) 328 FindCustomQuery::FindCustomQuery(int uid)
325 : OSQLQuery(), m_uid( uid ) { 329 : OSQLQuery(), m_uid( uid ) {
326 } 330 }
327 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 331 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
328 : OSQLQuery(), m_uids( ints ){ 332 : OSQLQuery(), m_uids( ints ){
329 } 333 }
330 FindCustomQuery::~FindCustomQuery() { 334 FindCustomQuery::~FindCustomQuery() {
331 } 335 }
332 QString FindCustomQuery::query()const{ 336 QString FindCustomQuery::query()const{
333 // if ( m_uids.count() == 0 ) 337// if ( m_uids.count() == 0 )
334 return single(); 338 return single();
335 } 339 }
336 QString FindCustomQuery::single()const{ 340 QString FindCustomQuery::single()const{
337 QString qu = "select uid, type, value from custom_data where uid = "; 341 QString qu = "select uid, type, value from custom_data where uid = ";
338 qu += QString::number(m_uid); 342 qu += QString::number(m_uid);
339 return qu; 343 return qu;
340 } 344 }
341 345
342}; 346};
343 347
344 348
345/* --------------------------------------------------------------------------- */ 349/* --------------------------------------------------------------------------- */
346 350
347namespace Opie { 351namespace Opie {
348 352
349OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, 353OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */,
350 const QString& filename ): 354 const QString& filename ):
351 OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) 355 OPimContactAccessBackend(), m_changed(false), m_driver( NULL )
352{ 356{
353 qDebug("C'tor OPimContactAccessBackend_SQL starts"); 357 odebug << "C'tor OPimContactAccessBackend_SQL starts" << oendl;
354 QTime t; 358 QTime t;
355 t.start(); 359 t.start();
356 360
357 /* Expecting to access the default filename if nothing else is set */ 361 /* Expecting to access the default filename if nothing else is set */
358 if ( filename.isEmpty() ){ 362 if ( filename.isEmpty() ){
359 m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); 363 m_fileName = Global::applicationFileName( "addressbook","addressbook.db" );
360 } else 364 } else
361 m_fileName = filename; 365 m_fileName = filename;
362 366
363 // Get the standart sql-driver from the OSQLManager.. 367 // Get the standart sql-driver from the OSQLManager..
364 OSQLManager man; 368 OSQLManager man;
365 m_driver = man.standard(); 369 m_driver = man.standard();
366 m_driver->setUrl( m_fileName ); 370 m_driver->setUrl( m_fileName );
367 371
368 load(); 372 load();
369 373
370 qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); 374 odebug << "C'tor OPimContactAccessBackend_SQL ends: " << t.elapsed() << " ms" << oendl;
371} 375}
372 376
373OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () 377OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL ()
374{ 378{
375 if( m_driver ) 379 if( m_driver )
376 delete m_driver; 380 delete m_driver;
377} 381}
378 382
379bool OPimContactAccessBackend_SQL::load () 383bool OPimContactAccessBackend_SQL::load ()
380{ 384{
381 if (!m_driver->open() ) 385 if (!m_driver->open() )
382 return false; 386 return false;
383 387
384 // Don't expect that the database exists. 388 // Don't expect that the database exists.
385 // It is save here to create the table, even if it 389 // It is save here to create the table, even if it
386 // do exist. ( Is that correct for all databases ?? ) 390 // do exist. ( Is that correct for all databases ?? )
387 CreateQuery creat; 391 CreateQuery creat;
388 OSQLResult res = m_driver->query( &creat ); 392 OSQLResult res = m_driver->query( &creat );
389 393
390 update(); 394 update();
391 395
392 return true; 396 return true;
393 397
394} 398}
395 399
396bool OPimContactAccessBackend_SQL::reload() 400bool OPimContactAccessBackend_SQL::reload()
397{ 401{
398 return load(); 402 return load();
399} 403}
400 404
401bool OPimContactAccessBackend_SQL::save() 405bool OPimContactAccessBackend_SQL::save()
402{ 406{
403 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 407 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
404} 408}
405 409
406 410
407void OPimContactAccessBackend_SQL::clear () 411void OPimContactAccessBackend_SQL::clear ()
408{ 412{
409 ClearQuery cle; 413 ClearQuery cle;
410 OSQLResult res = m_driver->query( &cle ); 414 OSQLResult res = m_driver->query( &cle );
411 415
412 reload(); 416 reload();
413} 417}
414 418
415bool OPimContactAccessBackend_SQL::wasChangedExternally() 419bool OPimContactAccessBackend_SQL::wasChangedExternally()
416{ 420{
417 return false; 421 return false;
418} 422}
419 423
420QArray<int> OPimContactAccessBackend_SQL::allRecords() const 424QArray<int> OPimContactAccessBackend_SQL::allRecords() const
421{ 425{
422 426
423 // FIXME: Think about cute handling of changed tables.. 427 // FIXME: Think about cute handling of changed tables..
424 // Thus, we don't have to call update here... 428 // Thus, we don't have to call update here...
425 if ( m_changed ) 429 if ( m_changed )
426 ((OPimContactAccessBackend_SQL*)this)->update(); 430 ((OPimContactAccessBackend_SQL*)this)->update();
427 431
428 return m_uids; 432 return m_uids;
429} 433}
430 434
431bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) 435bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact )
432{ 436{
433 qDebug("add in contact SQL-Backend"); 437 odebug << "add in contact SQL-Backend" << oendl;
434 InsertQuery ins( newcontact ); 438 InsertQuery ins( newcontact );
435 OSQLResult res = m_driver->query( &ins ); 439 OSQLResult res = m_driver->query( &ins );
436 440
437 if ( res.state() == OSQLResult::Failure ) 441 if ( res.state() == OSQLResult::Failure )
438 return false; 442 return false;
439 443
440 int c = m_uids.count(); 444 int c = m_uids.count();
441 m_uids.resize( c+1 ); 445 m_uids.resize( c+1 );
442 m_uids[c] = newcontact.uid(); 446 m_uids[c] = newcontact.uid();
443 447
444 return true; 448 return true;
445} 449}
446 450
447 451
448bool OPimContactAccessBackend_SQL::remove ( int uid ) 452bool OPimContactAccessBackend_SQL::remove ( int uid )
449{ 453{
450 RemoveQuery rem( uid ); 454 RemoveQuery rem( uid );
451 OSQLResult res = m_driver->query(&rem ); 455 OSQLResult res = m_driver->query(&rem );
452 456
453 if ( res.state() == OSQLResult::Failure ) 457 if ( res.state() == OSQLResult::Failure )
454 return false; 458 return false;
455 459
456 m_changed = true; 460 m_changed = true;
457 461
458 return true; 462 return true;
459} 463}
460 464
461bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) 465bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact )
462{ 466{
463 if ( !remove( contact.uid() ) ) 467 if ( !remove( contact.uid() ) )
464 return false; 468 return false;
465 469
466 return add( contact ); 470 return add( contact );
467} 471}
468 472
469 473
470OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const 474OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
471{ 475{
472 qDebug("OPimContactAccessBackend_SQL::find()"); 476 odebug << "OPimContactAccessBackend_SQL::find()" << oendl;
473 QTime t; 477 QTime t;
474 t.start(); 478 t.start();
475 479
476 OPimContact retContact( requestNonCustom( uid ) ); 480 OPimContact retContact( requestNonCustom( uid ) );
477 retContact.setExtraMap( requestCustom( uid ) ); 481 retContact.setExtraMap( requestCustom( uid ) );
478 482
479 qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); 483 odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl;
480 return retContact; 484 return retContact;
481} 485}
482 486
483 487
484 488
485QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) 489QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd )
486{ 490{
487 QString qu = "SELECT uid FROM addressbook WHERE"; 491 QString qu = "SELECT uid FROM addressbook WHERE";
488 QString searchQuery =""; 492 QString searchQuery ="";
489 493
490 QDate startDate; 494 QDate startDate;
491 495
492 if ( qd.isValid() ) 496 if ( qd.isValid() )
493 startDate = qd.date(); 497 startDate = qd.date();
494 else 498 else
495 startDate = QDate::currentDate(); 499 startDate = QDate::currentDate();
496 500
497 501
498 QMap<int, QString> queryFields = query.toMap(); 502 QMap<int, QString> queryFields = query.toMap();
499 QStringList fieldList = OPimContactFields::untrfields( false ); 503 QStringList fieldList = OPimContactFields::untrfields( false );
500 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 504 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
501 505
502 // Convert every filled field to a SQL-Query 506 // Convert every filled field to a SQL-Query
503 // bool isAnyFieldSelected = false; 507// bool isAnyFieldSelected = false;
504 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 508 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
505 509
506 int id = translate[*it]; 510 int id = translate[*it];
507 QString queryStr = queryFields[id]; 511 QString queryStr = queryFields[id];
508 QDate* endDate = 0l; 512 QDate* endDate = 0l;
509 513
510 if ( !queryStr.isEmpty() ){ 514 if ( !queryStr.isEmpty() ){
511 // If something is alredy stored in the query, add an "AND" 515 // If something is alredy stored in the query, add an "AND"
512 // to the end of the string to prepare for the next .. 516 // to the end of the string to prepare for the next ..
513 if ( !searchQuery.isEmpty() ) 517 if ( !searchQuery.isEmpty() )
514 searchQuery += " AND"; 518 searchQuery += " AND";
515 519
516 // isAnyFieldSelected = true; 520// isAnyFieldSelected = true;
517 switch( id ){ 521 switch( id ){
518 case Qtopia::Birthday: 522 case Qtopia::Birthday:
519 endDate = new QDate( query.birthday() ); 523 endDate = new QDate( query.birthday() );
520 // Fall through ! 524 // Fall through !
521 case Qtopia::Anniversary: 525 case Qtopia::Anniversary:
522 if ( endDate == 0l ) 526 if ( endDate == 0l )
523 endDate = new QDate( query.anniversary() ); 527 endDate = new QDate( query.anniversary() );
524 528
525 if ( settings & OPimContactAccess::DateDiff ) { 529 if ( settings & OPimContactAccess::DateDiff ) {
526 searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) 530 searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" )
527 .arg( *it ) 531 .arg( *it )
528 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) 532 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) )
529 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) 533 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) )
530 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) 534 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) )
531 .arg( *it ) 535 .arg( *it )
532 .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) 536 .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) )
533 .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) 537 .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) )
534 .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; 538 .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ;
535 } 539 }
536 540
537 if ( settings & OPimContactAccess::DateYear ){ 541 if ( settings & OPimContactAccess::DateYear ){
538 if ( settings & OPimContactAccess::DateDiff ) 542 if ( settings & OPimContactAccess::DateDiff )
539 searchQuery += " AND"; 543 searchQuery += " AND";
540 544
541 searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) 545 searchQuery += QString( " (\"%1\" LIKE '%2-%')" )
542 .arg( *it ) 546 .arg( *it )
543 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); 547 .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) );
544 } 548 }
545 549
546 if ( settings & OPimContactAccess::DateMonth ){ 550 if ( settings & OPimContactAccess::DateMonth ){
547 if ( ( settings & OPimContactAccess::DateDiff ) 551 if ( ( settings & OPimContactAccess::DateDiff )
548 || ( settings & OPimContactAccess::DateYear ) ) 552 || ( settings & OPimContactAccess::DateYear ) )
549 searchQuery += " AND"; 553 searchQuery += " AND";
550 554
551 searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) 555 searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" )
552 .arg( *it ) 556 .arg( *it )
553 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); 557 .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) );
554 } 558 }
555 559
556 if ( settings & OPimContactAccess::DateDay ){ 560 if ( settings & OPimContactAccess::DateDay ){
557 if ( ( settings & OPimContactAccess::DateDiff ) 561 if ( ( settings & OPimContactAccess::DateDiff )
558 || ( settings & OPimContactAccess::DateYear ) 562 || ( settings & OPimContactAccess::DateYear )
559 || ( settings & OPimContactAccess::DateMonth ) ) 563 || ( settings & OPimContactAccess::DateMonth ) )
560 searchQuery += " AND"; 564 searchQuery += " AND";
561 565
562 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) 566 searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" )
563 .arg( *it ) 567 .arg( *it )
564 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); 568 .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) );
565 } 569 }
566 570
567 break; 571 break;
568 default: 572 default:
569 // Switching between case sensitive and insensitive... 573 // Switching between case sensitive and insensitive...
570 // LIKE is not case sensitive, GLOB is case sensitive 574 // LIKE is not case sensitive, GLOB is case sensitive
571 // Do exist a better solution to switch this ? 575 // Do exist a better solution to switch this ?
572 if ( settings & OPimContactAccess::IgnoreCase ) 576 if ( settings & OPimContactAccess::IgnoreCase )
573 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" 577 searchQuery += "(\"" + *it + "\"" + " LIKE " + "'"
574 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; 578 + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")";
575 else 579 else
576 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" 580 searchQuery += "(\"" + *it + "\"" + " GLOB " + "'"
577 + queryStr + "'" + ")"; 581 + queryStr + "'" + ")";
578 582
579 } 583 }
580 } 584 }
581 } 585 }
582 // Skip trailing "AND" 586 // Skip trailing "AND"
583 // if ( isAnyFieldSelected ) 587// if ( isAnyFieldSelected )
584 // qu = qu.left( qu.length() - 4 ); 588// qu = qu.left( qu.length() - 4 );
585 589
586 qu += searchQuery; 590 qu += searchQuery;
587 591
588 qDebug( "queryByExample query: %s", qu.latin1() ); 592 odebug << "queryByExample query: " << qu << "" << oendl;
589 593
590 // Execute query and return the received uid's 594 // Execute query and return the received uid's
591 OSQLRawQuery raw( qu ); 595 OSQLRawQuery raw( qu );
592 OSQLResult res = m_driver->query( &raw ); 596 OSQLResult res = m_driver->query( &raw );
593 if ( res.state() != OSQLResult::Success ){ 597 if ( res.state() != OSQLResult::Success ){
594 QArray<int> empty; 598 QArray<int> empty;
595 return empty; 599 return empty;
596 } 600 }
597 601
598 QArray<int> list = extractUids( res ); 602 QArray<int> list = extractUids( res );
599 603
600 return list; 604 return list;
601} 605}
602 606
603QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 607QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
604{ 608{
605#if 0 609#if 0
606 QArray<int> nix(0); 610 QArray<int> nix(0);
607 return nix; 611 return nix;
608 612
609#else 613#else
610 QString qu = "SELECT uid FROM addressbook WHERE ("; 614 QString qu = "SELECT uid FROM addressbook WHERE (";
611 QString searchlist; 615 QString searchlist;
612 616
613 QStringList fieldList = OPimContactFields::untrfields( false ); 617 QStringList fieldList = OPimContactFields::untrfields( false );
614 // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 618 // QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
615 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 619 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
616 if ( !searchlist.isEmpty() ) 620 if ( !searchlist.isEmpty() )
617 searchlist += " OR "; 621 searchlist += " OR ";
618 searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; 622 searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") ";
619 } 623 }
620
621 qu = qu + searchlist + ")";
622 624
623 qDebug( "query: %s", qu.latin1() ); 625 qu = qu + searchlist + ")";
624 626
625 OSQLRawQuery raw( qu ); 627 odebug << "query: " << qu << "" << oendl;
626 OSQLResult res = m_driver->query( &raw );
627 628
628 return extractUids( res ); 629 OSQLRawQuery raw( qu );
630 OSQLResult res = m_driver->query( &raw );
631
632 return extractUids( res );
629 633
630 634
631#endif 635#endif
632} 636}
633 637
634const uint OPimContactAccessBackend_SQL::querySettings() 638const uint OPimContactAccessBackend_SQL::querySettings()
635{ 639{
636 return OPimContactAccess::IgnoreCase 640 return OPimContactAccess::IgnoreCase
637 | OPimContactAccess::WildCards 641 | OPimContactAccess::WildCards
638 | OPimContactAccess::DateDiff 642 | OPimContactAccess::DateDiff
639 | OPimContactAccess::DateYear 643 | OPimContactAccess::DateYear
640 | OPimContactAccess::DateMonth 644 | OPimContactAccess::DateMonth
641 | OPimContactAccess::DateDay 645 | OPimContactAccess::DateDay
642 ; 646 ;
643} 647}
644 648
645bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const 649bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
646{ 650{
647 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 651 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
648 * may be added with any of the other settings. IgnoreCase should never used alone. 652 * may be added with any of the other settings. IgnoreCase should never used alone.
649 * Wildcards, RegExp, ExactMatch should never used at the same time... 653 * Wildcards, RegExp, ExactMatch should never used at the same time...
650 */ 654 */
651 655
652 // Step 1: Check whether the given settings are supported by this backend 656 // Step 1: Check whether the given settings are supported by this backend
653 if ( ( querySettings & ( 657 if ( ( querySettings & (
654 OPimContactAccess::IgnoreCase 658 OPimContactAccess::IgnoreCase
655 | OPimContactAccess::WildCards 659 | OPimContactAccess::WildCards
656 | OPimContactAccess::DateDiff 660 | OPimContactAccess::DateDiff
657 | OPimContactAccess::DateYear 661 | OPimContactAccess::DateYear
658 | OPimContactAccess::DateMonth 662 | OPimContactAccess::DateMonth
659 | OPimContactAccess::DateDay 663 | OPimContactAccess::DateDay
660 // | OPimContactAccess::RegExp 664// | OPimContactAccess::RegExp
661 // | OPimContactAccess::ExactMatch 665// | OPimContactAccess::ExactMatch
662 ) ) != querySettings ) 666 ) ) != querySettings )
663 return false; 667 return false;
664 668
665 // Step 2: Check whether the given combinations are ok.. 669 // Step 2: Check whether the given combinations are ok..
666 670
667 // IngoreCase alone is invalid 671 // IngoreCase alone is invalid
668 if ( querySettings == OPimContactAccess::IgnoreCase ) 672 if ( querySettings == OPimContactAccess::IgnoreCase )
669 return false; 673 return false;
670 674
671 // WildCards, RegExp and ExactMatch should never used at the same time 675 // WildCards, RegExp and ExactMatch should never used at the same time
672 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 676 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
673 | OPimContactAccess::DateDiff 677 | OPimContactAccess::DateDiff
674 | OPimContactAccess::DateYear 678 | OPimContactAccess::DateYear
675 | OPimContactAccess::DateMonth 679 | OPimContactAccess::DateMonth
676 | OPimContactAccess::DateDay 680 | OPimContactAccess::DateDay
677 ) 681 )
678 ){ 682 ){
679 case OPimContactAccess::RegExp: 683 case OPimContactAccess::RegExp:
680 return ( true ); 684 return ( true );
681 case OPimContactAccess::WildCards: 685 case OPimContactAccess::WildCards:
682 return ( true ); 686 return ( true );
683 case OPimContactAccess::ExactMatch: 687 case OPimContactAccess::ExactMatch:
684 return ( true ); 688 return ( true );
685 case 0: // one of the upper removed bits were set.. 689 case 0: // one of the upper removed bits were set..
686 return ( true ); 690 return ( true );
687 default: 691 default:
688 return ( false ); 692 return ( false );
689 } 693 }
690 694
691} 695}
692 696
693QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) 697QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
694{ 698{
695 QTime t; 699 QTime t;
696 t.start(); 700 t.start();
697 701
698 QString query = "SELECT uid FROM addressbook "; 702 QString query = "SELECT uid FROM addressbook ";
699 query += "ORDER BY \"Last Name\" "; 703 query += "ORDER BY \"Last Name\" ";
700 704
701 if ( !asc ) 705 if ( !asc )
702 query += "DESC"; 706 query += "DESC";
703 707
704 // qDebug("sorted query is: %s", query.latin1() ); 708 // odebug << "sorted query is: " << query << "" << oendl;
705 709
706 OSQLRawQuery raw( query ); 710 OSQLRawQuery raw( query );
707 OSQLResult res = m_driver->query( &raw ); 711 OSQLResult res = m_driver->query( &raw );
708 if ( res.state() != OSQLResult::Success ){ 712 if ( res.state() != OSQLResult::Success ){
709 QArray<int> empty; 713 QArray<int> empty;
710 return empty; 714 return empty;
711 } 715 }
712 716
713 QArray<int> list = extractUids( res ); 717 QArray<int> list = extractUids( res );
714 718
715 qDebug("sorted needed %d ms!", t.elapsed() ); 719 odebug << "sorted needed " << t.elapsed() << " ms!" << oendl;
716 return list; 720 return list;
717} 721}
718 722
719 723
720void OPimContactAccessBackend_SQL::update() 724void OPimContactAccessBackend_SQL::update()
721{ 725{
722 qDebug("Update starts"); 726 odebug << "Update starts" << oendl;
723 QTime t; 727 QTime t;
724 t.start(); 728 t.start();
725 729
726 // Now load the database set and extract the uid's 730 // Now load the database set and extract the uid's
727 // which will be held locally 731 // which will be held locally
728 732
729 LoadQuery lo; 733 LoadQuery lo;
730 OSQLResult res = m_driver->query(&lo); 734 OSQLResult res = m_driver->query(&lo);
731 if ( res.state() != OSQLResult::Success ) 735 if ( res.state() != OSQLResult::Success )
732 return; 736 return;
733 737
734 m_uids = extractUids( res ); 738 m_uids = extractUids( res );
735 739
736 m_changed = false; 740 m_changed = false;
737 741
738 qDebug("Update ends %d ms", t.elapsed() ); 742 odebug << "Update ends " << t.elapsed() << " ms" << oendl;
739} 743}
740 744
741QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const 745QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
742{ 746{
743 qDebug("extractUids"); 747 odebug << "extractUids" << oendl;
744 QTime t; 748 QTime t;
745 t.start(); 749 t.start();
746 OSQLResultItem::ValueList list = res.results(); 750 OSQLResultItem::ValueList list = res.results();
747 OSQLResultItem::ValueList::Iterator it; 751 OSQLResultItem::ValueList::Iterator it;
748 QArray<int> ints(list.count() ); 752 QArray<int> ints(list.count() );
749 qDebug(" count = %d", list.count() ); 753 odebug << " count = " << list.count() << "" << oendl;
750 754
751 int i = 0; 755 int i = 0;
752 for (it = list.begin(); it != list.end(); ++it ) { 756 for (it = list.begin(); it != list.end(); ++it ) {
753 ints[i] = (*it).data("uid").toInt(); 757 ints[i] = (*it).data("uid").toInt();
754 i++; 758 i++;
755 } 759 }
756 qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 760 odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
757 761
758 return ints; 762 return ints;
759 763
760} 764}
761 765
762QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const 766QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const
763{ 767{
764 QTime t; 768 QTime t;
765 t.start(); 769 t.start();
766 770
767 QMap<int, QString> nonCustomMap; 771 QMap<int, QString> nonCustomMap;
768 772
769 int t2needed = 0; 773 int t2needed = 0;
770 int t3needed = 0; 774 int t3needed = 0;
771 QTime t2; 775 QTime t2;
772 t2.start(); 776 t2.start();
773 FindQuery query( uid ); 777 FindQuery query( uid );
774 OSQLResult res_noncustom = m_driver->query( &query ); 778 OSQLResult res_noncustom = m_driver->query( &query );
775 t2needed = t2.elapsed(); 779 t2needed = t2.elapsed();
776 780
777 OSQLResultItem resItem = res_noncustom.first(); 781 OSQLResultItem resItem = res_noncustom.first();
778 782
779 QTime t3; 783 QTime t3;
780 t3.start(); 784 t3.start();
781 // Now loop through all columns 785 // Now loop through all columns
782 QStringList fieldList = OPimContactFields::untrfields( false ); 786 QStringList fieldList = OPimContactFields::untrfields( false );
783 QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); 787 QMap<QString, int> translate = OPimContactFields::untrFieldsToId();
784 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ 788 for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
785 // Get data for the selected column and store it with the 789 // Get data for the selected column and store it with the
786 // corresponding id into the map.. 790 // corresponding id into the map..
787 791
788 int id = translate[*it]; 792 int id = translate[*it];
789 QString value = resItem.data( (*it) ); 793 QString value = resItem.data( (*it) );
790 794
791 // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() ); 795 // odebug << "Reading " << (*it) << "... found: " << value << "" << oendl;
792 796
793 switch( id ){ 797 switch( id ){
794 case Qtopia::Birthday: 798 case Qtopia::Birthday:
795 case Qtopia::Anniversary:{ 799 case Qtopia::Anniversary:{
796 // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) 800 // Birthday and Anniversary are encoded special ( yyyy-mm-dd )
797 QStringList list = QStringList::split( '-', value ); 801 QStringList list = QStringList::split( '-', value );
798 QStringList::Iterator lit = list.begin(); 802 QStringList::Iterator lit = list.begin();
799 int year = (*lit).toInt(); 803 int year = (*lit).toInt();
800 int month = (*(++lit)).toInt(); 804 int month = (*(++lit)).toInt();
801 int day = (*(++lit)).toInt(); 805 int day = (*(++lit)).toInt();
802 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ 806 if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){
803 QDate date( year, month, day ); 807 QDate date( year, month, day );
804 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); 808 nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) );
805 } 809 }
806 } 810 }
807 break; 811 break;
808 case Qtopia::AddressCategory: 812 case Qtopia::AddressCategory:
809 qDebug("Category is: %s", value.latin1() ); 813 odebug << "Category is: " << value << "" << oendl;
810 default: 814 default:
811 nonCustomMap.insert( id, value ); 815 nonCustomMap.insert( id, value );
812 } 816 }
813 } 817 }
814 818
815 // First insert uid 819 // First insert uid
816 nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); 820 nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) );
817 t3needed = t3.elapsed(); 821 t3needed = t3.elapsed();
818 822
819 // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() ); 823 // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl;
820 qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", 824 odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed
821 t.elapsed(), t2needed, t3needed ); 825 << " ms, mapping: " << t3needed << " ms" << oendl;
822 826
823 return nonCustomMap; 827 return nonCustomMap;
824} 828}
825 829
826QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const 830QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const
827{ 831{
828 QTime t; 832 QTime t;
829 t.start(); 833 t.start();
830 834
831 QMap<QString, QString> customMap; 835 QMap<QString, QString> customMap;
832 836
833 FindCustomQuery query( uid ); 837 FindCustomQuery query( uid );
834 OSQLResult res_custom = m_driver->query( &query ); 838 OSQLResult res_custom = m_driver->query( &query );
835 839
836 if ( res_custom.state() == OSQLResult::Failure ) { 840 if ( res_custom.state() == OSQLResult::Failure ) {
837 qWarning("OSQLResult::Failure in find query !!"); 841 owarn << "OSQLResult::Failure in find query !!" << oendl;
838 QMap<QString, QString> empty; 842 QMap<QString, QString> empty;
839 return empty; 843 return empty;
840 } 844 }
841 845
842 OSQLResultItem::ValueList list = res_custom.results(); 846 OSQLResultItem::ValueList list = res_custom.results();
843 OSQLResultItem::ValueList::Iterator it = list.begin(); 847 OSQLResultItem::ValueList::Iterator it = list.begin();
844 for ( ; it != list.end(); ++it ) { 848 for ( ; it != list.end(); ++it ) {
845 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 849 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
846 } 850 }
847 851
848 qDebug("RequestCustom needed: %d ms", t.elapsed() ); 852 odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl;
849 return customMap; 853 return customMap;
850} 854}
851 855
852} 856}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index ffa6a7d..b6ea461 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -1,596 +1,598 @@
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 * VCard Backend for the OPIE-Contact Database. 30 * VCard Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33 33
34#include "vobject_p.h" 34#include "vobject_p.h"
35 35
36/* OPIE */ 36/* OPIE */
37#include <opie2/ocontactaccessbackend_vcard.h> 37#include <opie2/ocontactaccessbackend_vcard.h>
38#include <opie2/odebug.h>
39
38#include <qpe/timeconversion.h> 40#include <qpe/timeconversion.h>
39 41
40//FIXME: Hack to allow direct access to FILE* fh. Rewrite this! 42//FIXME: Hack to allow direct access to FILE* fh. Rewrite this!
41#define protected public 43#define protected public
42#include <qfile.h> 44#include <qfile.h>
43#undef protected 45#undef protected
44 46
45namespace Opie { 47namespace Opie {
46 48
47OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): 49OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ):
48 m_dirty( false ), 50 m_dirty( false ),
49 m_file( filename ) 51 m_file( filename )
50{ 52{
51 load(); 53 load();
52} 54}
53 55
54 56
55bool OPimContactAccessBackend_VCard::load () 57bool OPimContactAccessBackend_VCard::load ()
56{ 58{
57 m_map.clear(); 59 m_map.clear();
58 m_dirty = false; 60 m_dirty = false;
59 61
60 VObject* obj = 0l; 62 VObject* obj = 0l;
61 63
62 if ( QFile::exists(m_file) ){ 64 if ( QFile::exists(m_file) ){
63 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 65 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
64 if ( !obj ) 66 if ( !obj )
65 return false; 67 return false;
66 }else{ 68 }else{
67 qWarning("File \"%s\" not found !", m_file.latin1() ); 69 owarn << "File \"" << m_file << "\" not found !" << oendl;
68 return false; 70 return false;
69 } 71 }
70 72
71 while ( obj ) { 73 while ( obj ) {
72 OPimContact con = parseVObject( obj ); 74 OPimContact con = parseVObject( obj );
73 /* 75 /*
74 * if uid is 0 assign a new one 76 * if uid is 0 assign a new one
75 * this at least happens on 77 * this at least happens on
76 * Nokia6210 78 * Nokia6210
77 */ 79 */
78 if ( con.uid() == 0 ){ 80 if ( con.uid() == 0 ){
79 con.setUid( 1 ); 81 con.setUid( 1 );
80 qWarning("assigned new uid %d",con.uid() ); 82 owarn << "assigned new uid " << con.uid() << "" << oendl;
81 } 83 }
82 84
83 m_map.insert( con.uid(), con ); 85 m_map.insert( con.uid(), con );
84 86
85 VObject *t = obj; 87 VObject *t = obj;
86 obj = nextVObjectInList(obj); 88 obj = nextVObjectInList(obj);
87 cleanVObject( t ); 89 cleanVObject( t );
88 } 90 }
89 91
90 return true; 92 return true;
91 93
92} 94}
93bool OPimContactAccessBackend_VCard::reload() 95bool OPimContactAccessBackend_VCard::reload()
94{ 96{
95 return load(); 97 return load();
96} 98}
97bool OPimContactAccessBackend_VCard::save() 99bool OPimContactAccessBackend_VCard::save()
98{ 100{
99 if (!m_dirty ) 101 if (!m_dirty )
100 return true; 102 return true;
101 103
102 QFile file( m_file ); 104 QFile file( m_file );
103 if (!file.open(IO_WriteOnly ) ) 105 if (!file.open(IO_WriteOnly ) )
104 return false; 106 return false;
105 107
106 VObject *obj; 108 VObject *obj;
107 obj = newVObject( VCCalProp ); 109 obj = newVObject( VCCalProp );
108 addPropValue( obj, VCVersionProp, "1.0" ); 110 addPropValue( obj, VCVersionProp, "1.0" );
109 111
110 VObject *vo; 112 VObject *vo;
111 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 113 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
112 vo = createVObject( *it ); 114 vo = createVObject( *it );
113 writeVObject( file.fh, vo ); //FIXME: HACK!!! 115 writeVObject( file.fh, vo ); //FIXME: HACK!!!
114 cleanVObject( vo ); 116 cleanVObject( vo );
115 } 117 }
116 cleanStrTbl(); 118 cleanStrTbl();
117 deleteVObject( obj ); 119 deleteVObject( obj );
118 120
119 m_dirty = false; 121 m_dirty = false;
120 return true; 122 return true;
121 123
122 124
123} 125}
124void OPimContactAccessBackend_VCard::clear () 126void OPimContactAccessBackend_VCard::clear ()
125{ 127{
126 m_map.clear(); 128 m_map.clear();
127 m_dirty = true; // ??? sure ? (se) 129 m_dirty = true; // ??? sure ? (se)
128} 130}
129 131
130bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact ) 132bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact )
131{ 133{
132 m_map.insert( newcontact.uid(), newcontact ); 134 m_map.insert( newcontact.uid(), newcontact );
133 m_dirty = true; 135 m_dirty = true;
134 return true; 136 return true;
135} 137}
136 138
137bool OPimContactAccessBackend_VCard::remove ( int uid ) 139bool OPimContactAccessBackend_VCard::remove ( int uid )
138{ 140{
139 m_map.remove( uid ); 141 m_map.remove( uid );
140 m_dirty = true; 142 m_dirty = true;
141 return true; 143 return true;
142} 144}
143 145
144bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact ) 146bool OPimContactAccessBackend_VCard::replace ( const OPimContact &contact )
145{ 147{
146 m_map.replace( contact.uid(), contact ); 148 m_map.replace( contact.uid(), contact );
147 m_dirty = true; 149 m_dirty = true;
148 return true; 150 return true;
149} 151}
150 152
151OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const 153OPimContact OPimContactAccessBackend_VCard::find ( int uid ) const
152{ 154{
153 return m_map[uid]; 155 return m_map[uid];
154} 156}
155 157
156QArray<int> OPimContactAccessBackend_VCard::allRecords() const 158QArray<int> OPimContactAccessBackend_VCard::allRecords() const
157{ 159{
158 QArray<int> ar( m_map.count() ); 160 QArray<int> ar( m_map.count() );
159 QMap<int, OPimContact>::ConstIterator it; 161 QMap<int, OPimContact>::ConstIterator it;
160 int i = 0; 162 int i = 0;
161 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 163 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
162 ar[i] = it.key(); 164 ar[i] = it.key();
163 i++; 165 i++;
164 } 166 }
165 return ar; 167 return ar;
166} 168}
167 169
168// Not implemented 170// Not implemented
169QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& ) 171QArray<int> OPimContactAccessBackend_VCard::queryByExample ( const OPimContact&, int, const QDateTime& )
170{ 172{
171 QArray<int> ar(0); 173 QArray<int> ar(0);
172 return ar; 174 return ar;
173} 175}
174 176
175// Not implemented 177// Not implemented
176QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const 178QArray<int> OPimContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const
177{ 179{
178 QArray<int> ar(0); 180 QArray<int> ar(0);
179 return ar; 181 return ar;
180} 182}
181 183
182const uint OPimContactAccessBackend_VCard::querySettings() 184const uint OPimContactAccessBackend_VCard::querySettings()
183{ 185{
184 return 0; // No search possible 186 return 0; // No search possible
185} 187}
186 188
187bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const 189bool OPimContactAccessBackend_VCard::hasQuerySettings (uint ) const
188{ 190{
189 return false; // No search possible, therefore all settings invalid ;) 191 return false; // No search possible, therefore all settings invalid ;)
190} 192}
191 193
192bool OPimContactAccessBackend_VCard::wasChangedExternally() 194bool OPimContactAccessBackend_VCard::wasChangedExternally()
193{ 195{
194 return false; // Don't expect concurrent access 196 return false; // Don't expect concurrent access
195} 197}
196 198
197// Not implemented 199// Not implemented
198QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int ) 200QArray<int> OPimContactAccessBackend_VCard::sorted( bool , int, int, int )
199{ 201{
200 QArray<int> ar(0); 202 QArray<int> ar(0);
201 return ar; 203 return ar;
202} 204}
203 205
204// *** Private stuff *** 206// *** Private stuff ***
205 207
206 208
207OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) 209OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj )
208{ 210{
209 OPimContact c; 211 OPimContact c;
210 212
211 VObjectIterator it; 213 VObjectIterator it;
212 initPropIterator( &it, obj ); 214 initPropIterator( &it, obj );
213 while( moreIteration( &it ) ) { 215 while( moreIteration( &it ) ) {
214 VObject *o = nextVObject( &it ); 216 VObject *o = nextVObject( &it );
215 QCString name = vObjectName( o ); 217 QCString name = vObjectName( o );
216 QCString value = vObjectStringZValue( o ); 218 QCString value = vObjectStringZValue( o );
217 if ( name == VCNameProp ) { 219 if ( name == VCNameProp ) {
218 VObjectIterator nit; 220 VObjectIterator nit;
219 initPropIterator( &nit, o ); 221 initPropIterator( &nit, o );
220 while( moreIteration( &nit ) ) { 222 while( moreIteration( &nit ) ) {
221 VObject *o = nextVObject( &nit ); 223 VObject *o = nextVObject( &nit );
222 QCString name = vObjectTypeInfo( o ); 224 QCString name = vObjectTypeInfo( o );
223 QString value = vObjectStringZValue( o ); 225 QString value = vObjectStringZValue( o );
224 if ( name == VCNamePrefixesProp ) 226 if ( name == VCNamePrefixesProp )
225 c.setTitle( value ); 227 c.setTitle( value );
226 else if ( name == VCNameSuffixesProp ) 228 else if ( name == VCNameSuffixesProp )
227 c.setSuffix( value ); 229 c.setSuffix( value );
228 else if ( name == VCFamilyNameProp ) 230 else if ( name == VCFamilyNameProp )
229 c.setLastName( value ); 231 c.setLastName( value );
230 else if ( name == VCGivenNameProp ) 232 else if ( name == VCGivenNameProp )
231 c.setFirstName( value ); 233 c.setFirstName( value );
232 else if ( name == VCAdditionalNamesProp ) 234 else if ( name == VCAdditionalNamesProp )
233 c.setMiddleName( value ); 235 c.setMiddleName( value );
234 } 236 }
235 } 237 }
236 else if ( name == VCAdrProp ) { 238 else if ( name == VCAdrProp ) {
237 bool work = TRUE; // default address is work address 239 bool work = TRUE; // default address is work address
238 QString street; 240 QString street;
239 QString city; 241 QString city;
240 QString region; 242 QString region;
241 QString postal; 243 QString postal;
242 QString country; 244 QString country;
243 245
244 VObjectIterator nit; 246 VObjectIterator nit;
245 initPropIterator( &nit, o ); 247 initPropIterator( &nit, o );
246 while( moreIteration( &nit ) ) { 248 while( moreIteration( &nit ) ) {
247 VObject *o = nextVObject( &nit ); 249 VObject *o = nextVObject( &nit );
248 QCString name = vObjectName( o ); 250 QCString name = vObjectName( o );
249 QString value = vObjectStringZValue( o ); 251 QString value = vObjectStringZValue( o );
250 if ( name == VCHomeProp ) 252 if ( name == VCHomeProp )
251 work = FALSE; 253 work = FALSE;
252 else if ( name == VCWorkProp ) 254 else if ( name == VCWorkProp )
253 work = TRUE; 255 work = TRUE;
254 else if ( name == VCStreetAddressProp ) 256 else if ( name == VCStreetAddressProp )
255 street = value; 257 street = value;
256 else if ( name == VCCityProp ) 258 else if ( name == VCCityProp )
257 city = value; 259 city = value;
258 else if ( name == VCRegionProp ) 260 else if ( name == VCRegionProp )
259 region = value; 261 region = value;
260 else if ( name == VCPostalCodeProp ) 262 else if ( name == VCPostalCodeProp )
261 postal = value; 263 postal = value;
262 else if ( name == VCCountryNameProp ) 264 else if ( name == VCCountryNameProp )
263 country = value; 265 country = value;
264 } 266 }
265 if ( work ) { 267 if ( work ) {
266 c.setBusinessStreet( street ); 268 c.setBusinessStreet( street );
267 c.setBusinessCity( city ); 269 c.setBusinessCity( city );
268 c.setBusinessCountry( country ); 270 c.setBusinessCountry( country );
269 c.setBusinessZip( postal ); 271 c.setBusinessZip( postal );
270 c.setBusinessState( region ); 272 c.setBusinessState( region );
271 } else { 273 } else {
272 c.setHomeStreet( street ); 274 c.setHomeStreet( street );
273 c.setHomeCity( city ); 275 c.setHomeCity( city );
274 c.setHomeCountry( country ); 276 c.setHomeCountry( country );
275 c.setHomeZip( postal ); 277 c.setHomeZip( postal );
276 c.setHomeState( region ); 278 c.setHomeState( region );
277 } 279 }
278 } 280 }
279 else if ( name == VCTelephoneProp ) { 281 else if ( name == VCTelephoneProp ) {
280 enum { 282 enum {
281 HOME = 0x01, 283 HOME = 0x01,
282 WORK = 0x02, 284 WORK = 0x02,
283 VOICE = 0x04, 285 VOICE = 0x04,
284 CELL = 0x08, 286 CELL = 0x08,
285 FAX = 0x10, 287 FAX = 0x10,
286 PAGER = 0x20, 288 PAGER = 0x20,
287 UNKNOWN = 0x80 289 UNKNOWN = 0x80
288 }; 290 };
289 int type = 0; 291 int type = 0;
290 292
291 VObjectIterator nit; 293 VObjectIterator nit;
292 initPropIterator( &nit, o ); 294 initPropIterator( &nit, o );
293 while( moreIteration( &nit ) ) { 295 while( moreIteration( &nit ) ) {
294 VObject *o = nextVObject( &nit ); 296 VObject *o = nextVObject( &nit );
295 QCString name = vObjectTypeInfo( o ); 297 QCString name = vObjectTypeInfo( o );
296 if ( name == VCHomeProp ) 298 if ( name == VCHomeProp )
297 type |= HOME; 299 type |= HOME;
298 else if ( name == VCWorkProp ) 300 else if ( name == VCWorkProp )
299 type |= WORK; 301 type |= WORK;
300 else if ( name == VCVoiceProp ) 302 else if ( name == VCVoiceProp )
301 type |= VOICE; 303 type |= VOICE;
302 else if ( name == VCCellularProp ) 304 else if ( name == VCCellularProp )
303 type |= CELL; 305 type |= CELL;
304 else if ( name == VCFaxProp ) 306 else if ( name == VCFaxProp )
305 type |= FAX; 307 type |= FAX;
306 else if ( name == VCPagerProp ) 308 else if ( name == VCPagerProp )
307 type |= PAGER; 309 type |= PAGER;
308 else if ( name == VCPreferredProp ) 310 else if ( name == VCPreferredProp )
309 ; 311 ;
310 else 312 else
311 type |= UNKNOWN; 313 type |= UNKNOWN;
312 } 314 }
313 if ( (type & UNKNOWN) != UNKNOWN ) { 315 if ( (type & UNKNOWN) != UNKNOWN ) {
314 if ( ( type & (HOME|WORK) ) == 0 ) // default 316 if ( ( type & (HOME|WORK) ) == 0 ) // default
315 type |= HOME; 317 type |= HOME;
316 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 318 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
317 type |= VOICE; 319 type |= VOICE;
318 320
319 qWarning("value %s %d", value.data(), type ); 321 owarn << "value " << value.data() << " " << type << "" << oendl;
320 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) 322 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) )
321 c.setHomePhone( value ); 323 c.setHomePhone( value );
322 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 324 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
323 c.setHomeFax( value ); 325 c.setHomeFax( value );
324 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 326 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
325 c.setHomeMobile( value ); 327 c.setHomeMobile( value );
326 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) 328 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) )
327 c.setBusinessPhone( value ); 329 c.setBusinessPhone( value );
328 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 330 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
329 c.setBusinessFax( value ); 331 c.setBusinessFax( value );
330 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 332 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
331 c.setBusinessMobile( value ); 333 c.setBusinessMobile( value );
332 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 334 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
333 c.setBusinessPager( value ); 335 c.setBusinessPager( value );
334 } 336 }
335 } 337 }
336 else if ( name == VCEmailAddressProp ) { 338 else if ( name == VCEmailAddressProp ) {
337 QString email = vObjectStringZValue( o ); 339 QString email = vObjectStringZValue( o );
338 bool valid = TRUE; 340 bool valid = TRUE;
339 VObjectIterator nit; 341 VObjectIterator nit;
340 initPropIterator( &nit, o ); 342 initPropIterator( &nit, o );
341 while( moreIteration( &nit ) ) { 343 while( moreIteration( &nit ) ) {
342 VObject *o = nextVObject( &nit ); 344 VObject *o = nextVObject( &nit );
343 QCString name = vObjectTypeInfo( o ); 345 QCString name = vObjectTypeInfo( o );
344 if ( name != VCInternetProp && name != VCHomeProp && 346 if ( name != VCInternetProp && name != VCHomeProp &&
345 name != VCWorkProp && 347 name != VCWorkProp &&
346 name != VCPreferredProp ) 348 name != VCPreferredProp )
347 // ### preffered should map to default email 349 // ### preffered should map to default email
348 valid = FALSE; 350 valid = FALSE;
349 } 351 }
350 if ( valid ) { 352 if ( valid ) {
351 c.insertEmail( email ); 353 c.insertEmail( email );
352 } 354 }
353 } 355 }
354 else if ( name == VCURLProp ) { 356 else if ( name == VCURLProp ) {
355 VObjectIterator nit; 357 VObjectIterator nit;
356 initPropIterator( &nit, o ); 358 initPropIterator( &nit, o );
357 while( moreIteration( &nit ) ) { 359 while( moreIteration( &nit ) ) {
358 VObject *o = nextVObject( &nit ); 360 VObject *o = nextVObject( &nit );
359 QCString name = vObjectTypeInfo( o ); 361 QCString name = vObjectTypeInfo( o );
360 if ( name == VCHomeProp ) 362 if ( name == VCHomeProp )
361 c.setHomeWebpage( value ); 363 c.setHomeWebpage( value );
362 else if ( name == VCWorkProp ) 364 else if ( name == VCWorkProp )
363 c.setBusinessWebpage( value ); 365 c.setBusinessWebpage( value );
364 } 366 }
365 } 367 }
366 else if ( name == VCOrgProp ) { 368 else if ( name == VCOrgProp ) {
367 VObjectIterator nit; 369 VObjectIterator nit;
368 initPropIterator( &nit, o ); 370 initPropIterator( &nit, o );
369 while( moreIteration( &nit ) ) { 371 while( moreIteration( &nit ) ) {
370 VObject *o = nextVObject( &nit ); 372 VObject *o = nextVObject( &nit );
371 QCString name = vObjectName( o ); 373 QCString name = vObjectName( o );
372 QString value = vObjectStringZValue( o ); 374 QString value = vObjectStringZValue( o );
373 if ( name == VCOrgNameProp ) 375 if ( name == VCOrgNameProp )
374 c.setCompany( value ); 376 c.setCompany( value );
375 else if ( name == VCOrgUnitProp ) 377 else if ( name == VCOrgUnitProp )
376 c.setDepartment( value ); 378 c.setDepartment( value );
377 else if ( name == VCOrgUnit2Prop ) 379 else if ( name == VCOrgUnit2Prop )
378 c.setOffice( value ); 380 c.setOffice( value );
379 } 381 }
380 } 382 }
381 else if ( name == VCTitleProp ) { 383 else if ( name == VCTitleProp ) {
382 c.setJobTitle( value ); 384 c.setJobTitle( value );
383 } 385 }
384 else if ( name == "X-Qtopia-Profession" ) { 386 else if ( name == "X-Qtopia-Profession" ) {
385 c.setProfession( value ); 387 c.setProfession( value );
386 } 388 }
387 else if ( name == "X-Qtopia-Manager" ) { 389 else if ( name == "X-Qtopia-Manager" ) {
388 c.setManager( value ); 390 c.setManager( value );
389 } 391 }
390 else if ( name == "X-Qtopia-Assistant" ) { 392 else if ( name == "X-Qtopia-Assistant" ) {
391 c.setAssistant( value ); 393 c.setAssistant( value );
392 } 394 }
393 else if ( name == "X-Qtopia-Spouse" ) { 395 else if ( name == "X-Qtopia-Spouse" ) {
394 c.setSpouse( value ); 396 c.setSpouse( value );
395 } 397 }
396 else if ( name == "X-Qtopia-Gender" ) { 398 else if ( name == "X-Qtopia-Gender" ) {
397 c.setGender( value ); 399 c.setGender( value );
398 } 400 }
399 else if ( name == "X-Qtopia-Anniversary" ) { 401 else if ( name == "X-Qtopia-Anniversary" ) {
400 c.setAnniversary( convVCardDateToDate( value ) ); 402 c.setAnniversary( convVCardDateToDate( value ) );
401 } 403 }
402 else if ( name == "X-Qtopia-Nickname" ) { 404 else if ( name == "X-Qtopia-Nickname" ) {
403 c.setNickname( value ); 405 c.setNickname( value );
404 } 406 }
405 else if ( name == "X-Qtopia-Children" ) { 407 else if ( name == "X-Qtopia-Children" ) {
406 c.setChildren( value ); 408 c.setChildren( value );
407 } 409 }
408 else if ( name == VCBirthDateProp ) { 410 else if ( name == VCBirthDateProp ) {
409 // Reading Birthdate regarding RFC 2425 (5.8.4) 411 // Reading Birthdate regarding RFC 2425 (5.8.4)
410 c.setBirthday( convVCardDateToDate( value ) ); 412 c.setBirthday( convVCardDateToDate( value ) );
411 413
412 } 414 }
413 else if ( name == VCCommentProp ) { 415 else if ( name == VCCommentProp ) {
414 c.setNotes( value ); 416 c.setNotes( value );
415 } 417 }
416#if 0 418#if 0
417 else { 419 else {
418 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 420 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
419 VObjectIterator nit; 421 VObjectIterator nit;
420 initPropIterator( &nit, o ); 422 initPropIterator( &nit, o );
421 while( moreIteration( &nit ) ) { 423 while( moreIteration( &nit ) ) {
422 VObject *o = nextVObject( &nit ); 424 VObject *o = nextVObject( &nit );
423 QCString name = vObjectName( o ); 425 QCString name = vObjectName( o );
424 QString value = vObjectStringZValue( o ); 426 QString value = vObjectStringZValue( o );
425 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 427 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
426 } 428 }
427 } 429 }
428#endif 430#endif
429 } 431 }
430 c.setFileAs(); 432 c.setFileAs();
431 return c; 433 return c;
432} 434}
433 435
434 436
435VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c ) 437VObject* OPimContactAccessBackend_VCard::createVObject( const OPimContact &c )
436{ 438{
437 VObject *vcard = newVObject( VCCardProp ); 439 VObject *vcard = newVObject( VCCardProp );
438 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 440 safeAddPropValue( vcard, VCVersionProp, "2.1" );
439 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 441 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
440 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 442 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
441 443
442 // full name 444 // full name
443 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 445 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
444 446
445 // name properties 447 // name properties
446 VObject *name = safeAddProp( vcard, VCNameProp ); 448 VObject *name = safeAddProp( vcard, VCNameProp );
447 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 449 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
448 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 450 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
449 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 451 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
450 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 452 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
451 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 453 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
452 454
453 // home properties 455 // home properties
454 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 456 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
455 safeAddProp( home_adr, VCHomeProp ); 457 safeAddProp( home_adr, VCHomeProp );
456 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 458 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
457 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 459 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
458 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 460 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
459 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 461 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
460 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 462 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
461 463
462 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 464 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
463 safeAddProp( home_phone, VCHomeProp ); 465 safeAddProp( home_phone, VCHomeProp );
464 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 466 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
465 safeAddProp( home_phone, VCHomeProp ); 467 safeAddProp( home_phone, VCHomeProp );
466 safeAddProp( home_phone, VCCellularProp ); 468 safeAddProp( home_phone, VCCellularProp );
467 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 469 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
468 safeAddProp( home_phone, VCHomeProp ); 470 safeAddProp( home_phone, VCHomeProp );
469 safeAddProp( home_phone, VCFaxProp ); 471 safeAddProp( home_phone, VCFaxProp );
470 472
471 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 473 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
472 safeAddProp( url, VCHomeProp ); 474 safeAddProp( url, VCHomeProp );
473 475
474 // work properties 476 // work properties
475 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 477 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
476 safeAddProp( work_adr, VCWorkProp ); 478 safeAddProp( work_adr, VCWorkProp );
477 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 479 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
478 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 480 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
479 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 481 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
480 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 482 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
481 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 483 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
482 484
483 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 485 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
484 safeAddProp( work_phone, VCWorkProp ); 486 safeAddProp( work_phone, VCWorkProp );
485 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 487 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
486 safeAddProp( work_phone, VCWorkProp ); 488 safeAddProp( work_phone, VCWorkProp );
487 safeAddProp( work_phone, VCCellularProp ); 489 safeAddProp( work_phone, VCCellularProp );
488 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 490 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
489 safeAddProp( work_phone, VCWorkProp ); 491 safeAddProp( work_phone, VCWorkProp );
490 safeAddProp( work_phone, VCFaxProp ); 492 safeAddProp( work_phone, VCFaxProp );
491 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 493 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
492 safeAddProp( work_phone, VCWorkProp ); 494 safeAddProp( work_phone, VCWorkProp );
493 safeAddProp( work_phone, VCPagerProp ); 495 safeAddProp( work_phone, VCPagerProp );
494 496
495 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 497 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
496 safeAddProp( url, VCWorkProp ); 498 safeAddProp( url, VCWorkProp );
497 499
498 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 500 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
499 safeAddProp( title, VCWorkProp ); 501 safeAddProp( title, VCWorkProp );
500 502
501 503
502 QStringList emails = c.emailList(); 504 QStringList emails = c.emailList();
503 // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045 505 // emails.prepend( c.defaultEmail() ); Fix for bugreport #1045
504 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 506 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
505 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 507 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
506 safeAddProp( email, VCInternetProp ); 508 safeAddProp( email, VCInternetProp );
507 } 509 }
508 510
509 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 511 safeAddPropValue( vcard, VCNoteProp, c.notes() );
510 512
511 // Exporting Birthday regarding RFC 2425 (5.8.4) 513 // Exporting Birthday regarding RFC 2425 (5.8.4)
512 if ( c.birthday().isValid() ){ 514 if ( c.birthday().isValid() ){
513 qWarning("Exporting birthday as: %s", convDateToVCardDate( c.birthday() ).latin1() ); 515 owarn << "Exporting birthday as: " << convDateToVCardDate( c.birthday() ) << "" << oendl;
514 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) ); 516 safeAddPropValue( vcard, VCBirthDateProp, convDateToVCardDate( c.birthday() ) );
515 } 517 }
516 518
517 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 519 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
518 VObject *org = safeAddProp( vcard, VCOrgProp ); 520 VObject *org = safeAddProp( vcard, VCOrgProp );
519 safeAddPropValue( org, VCOrgNameProp, c.company() ); 521 safeAddPropValue( org, VCOrgNameProp, c.company() );
520 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 522 safeAddPropValue( org, VCOrgUnitProp, c.department() );
521 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 523 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
522 } 524 }
523 525
524 // some values we have to export as custom fields 526 // some values we have to export as custom fields
525 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 527 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
526 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 528 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
527 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 529 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
528 530
529 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 531 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
530 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 532 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
531 if ( c.anniversary().isValid() ){ 533 if ( c.anniversary().isValid() ){
532 qWarning("Exporting anniversary as: %s", convDateToVCardDate( c.anniversary() ).latin1() ); 534 owarn << "Exporting anniversary as: " << convDateToVCardDate( c.anniversary() ) << "" << oendl;
533 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) ); 535 safeAddPropValue( vcard, "X-Qtopia-Anniversary", convDateToVCardDate( c.anniversary() ) );
534 } 536 }
535 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 537 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
536 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 538 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
537 539
538 return vcard; 540 return vcard;
539} 541}
540 542
541QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const 543QString OPimContactAccessBackend_VCard::convDateToVCardDate( const QDate& d ) const
542{ 544{
543 QString str_rfc2425 = QString("%1-%2-%3") 545 QString str_rfc2425 = QString("%1-%2-%3")
544 .arg( d.year() ) 546 .arg( d.year() )
545 .arg( d.month(), 2 ) 547 .arg( d.month(), 2 )
546 .arg( d.day(), 2 ); 548 .arg( d.day(), 2 );
547 // Now replace spaces with "0"... 549 // Now replace spaces with "0"...
548 int pos = 0; 550 int pos = 0;
549 while ( ( pos = str_rfc2425.find (' ') ) > 0 ) 551 while ( ( pos = str_rfc2425.find (' ') ) > 0 )
550 str_rfc2425.replace( pos, 1, "0" ); 552 str_rfc2425.replace( pos, 1, "0" );
551 553
552 return str_rfc2425; 554 return str_rfc2425;
553} 555}
554 556
555QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr ) 557QDate OPimContactAccessBackend_VCard::convVCardDateToDate( const QString& datestr )
556{ 558{
557 int monthPos = datestr.find('-'); 559 int monthPos = datestr.find('-');
558 int dayPos = datestr.find('-', monthPos+1 ); 560 int dayPos = datestr.find('-', monthPos+1 );
559 int sep_ignore = 1; 561 int sep_ignore = 1;
560 if ( monthPos == -1 || dayPos == -1 ) { 562 if ( monthPos == -1 || dayPos == -1 ) {
561 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 563 odebug << "fromString didn't find - in str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
562 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD ) 564 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
563 if ( datestr.length() == 8 ){ 565 if ( datestr.length() == 8 ){
564 monthPos = 4; 566 monthPos = 4;
565 dayPos = 6; 567 dayPos = 6;
566 sep_ignore = 0; 568 sep_ignore = 0;
567 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 569 odebug << "Try with follwing positions str = " << datestr << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
568 } else { 570 } else {
569 return QDate(); 571 return QDate();
570 } 572 }
571 } 573 }
572 int y = datestr.left( monthPos ).toInt(); 574 int y = datestr.left( monthPos ).toInt();
573 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 575 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
574 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 576 int d = datestr.mid( dayPos + sep_ignore ).toInt();
575 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 577 odebug << "TimeConversion::fromString ymd = " << datestr << " => " << y << " " << m << " " << d << "; mpos = " << monthPos << " ypos = " << dayPos << "" << oendl;
576 QDate date ( y,m,d ); 578 QDate date ( y,m,d );
577 return date; 579 return date;
578} 580}
579 581
580VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value ) 582VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const char *prop, const QString &value )
581{ 583{
582 VObject *ret = 0; 584 VObject *ret = 0;
583 if ( o && !value.isEmpty() ) 585 if ( o && !value.isEmpty() )
584 ret = addPropValue( o, prop, value.latin1() ); 586 ret = addPropValue( o, prop, value.latin1() );
585 return ret; 587 return ret;
586} 588}
587 589
588VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) 590VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop)
589{ 591{
590 VObject *ret = 0; 592 VObject *ret = 0;
591 if ( o ) 593 if ( o )
592 ret = addProp( o, prop ); 594 ret = addProp( o, prop );
593 return ret; 595 return ret;
594} 596}
595 597
596} 598}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 7b4d81f..5ffcb11 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -1,750 +1,754 @@
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 * XML Backend for the OPIE-Contact Database. 30 * XML Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33
34/* OPIE */
33#include <opie2/ocontactaccessbackend_xml.h> 35#include <opie2/ocontactaccessbackend_xml.h>
36#include <opie2/xmltree.h>
37#include <opie2/ocontactaccessbackend.h>
38#include <opie2/ocontactaccess.h>
39#include <opie2/odebug.h>
40
41#include <qpe/global.h>
34 42
43/* QT */
35#include <qasciidict.h> 44#include <qasciidict.h>
36#include <qfile.h> 45#include <qfile.h>
37#include <qfileinfo.h> 46#include <qfileinfo.h>
38#include <qregexp.h> 47#include <qregexp.h>
39#include <qarray.h> 48#include <qarray.h>
40#include <qmap.h> 49#include <qmap.h>
41 50
42#include <qpe/global.h> 51/* STD */
43
44#include <opie2/xmltree.h>
45#include <opie2/ocontactaccessbackend.h>
46#include <opie2/ocontactaccess.h>
47
48#include <stdlib.h> 52#include <stdlib.h>
49#include <errno.h> 53#include <errno.h>
50 54
51using namespace Opie::Core; 55using namespace Opie::Core;
52 56
53 57
54namespace Opie { 58namespace Opie {
55OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ): 59OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ):
56 m_changed( false ) 60 m_changed( false )
57{ 61{
58 // Just m_contactlist should call delete if an entry 62 // Just m_contactlist should call delete if an entry
59 // is removed. 63 // is removed.
60 m_contactList.setAutoDelete( true ); 64 m_contactList.setAutoDelete( true );
61 m_uidToContact.setAutoDelete( false ); 65 m_uidToContact.setAutoDelete( false );
62 66
63 m_appName = appname; 67 m_appName = appname;
64 68
65 /* Set journalfile name ... */ 69 /* Set journalfile name ... */
66 m_journalName = getenv("HOME"); 70 m_journalName = getenv("HOME");
67 m_journalName +="/.abjournal" + appname; 71 m_journalName +="/.abjournal" + appname;
68 72
69 /* Expecting to access the default filename if nothing else is set */ 73 /* Expecting to access the default filename if nothing else is set */
70 if ( filename.isEmpty() ){ 74 if ( filename.isEmpty() ){
71 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 75 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
72 } else 76 } else
73 m_fileName = filename; 77 m_fileName = filename;
74 78
75 /* Load Database now */ 79 /* Load Database now */
76 load (); 80 load ();
77} 81}
78 82
79bool OPimContactAccessBackend_XML::save() 83bool OPimContactAccessBackend_XML::save()
80{ 84{
81 85
82 if ( !m_changed ) 86 if ( !m_changed )
83 return true; 87 return true;
84 88
85 QString strNewFile = m_fileName + ".new"; 89 QString strNewFile = m_fileName + ".new";
86 QFile f( strNewFile ); 90 QFile f( strNewFile );
87 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 91 if ( !f.open( IO_WriteOnly|IO_Raw ) )
88 return false; 92 return false;
89 93
90 int total_written; 94 int total_written;
91 int idx_offset = 0; 95 int idx_offset = 0;
92 QString out; 96 QString out;
93 97
94 // Write Header 98 // Write Header
95 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"
96 " <Groups>\n" 100 " <Groups>\n"
97 " </Groups>\n" 101 " </Groups>\n"
98 " <Contacts>\n"; 102 " <Contacts>\n";
99 QCString cstr = out.utf8(); 103 QCString cstr = out.utf8();
100 f.writeBlock( cstr.data(), cstr.length() ); 104 f.writeBlock( cstr.data(), cstr.length() );
101 idx_offset += cstr.length(); 105 idx_offset += cstr.length();
102 out = ""; 106 out = "";
103 107
104 // Write all contacts 108 // Write all contacts
105 QListIterator<OPimContact> it( m_contactList ); 109 QListIterator<OPimContact> it( m_contactList );
106 for ( ; it.current(); ++it ) { 110 for ( ; it.current(); ++it ) {
107 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); 111 // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl;
108 out += "<Contact "; 112 out += "<Contact ";
109 (*it)->save( out ); 113 (*it)->save( out );
110 out += "/>\n"; 114 out += "/>\n";
111 cstr = out.utf8(); 115 cstr = out.utf8();
112 total_written = f.writeBlock( cstr.data(), cstr.length() ); 116 total_written = f.writeBlock( cstr.data(), cstr.length() );
113 idx_offset += cstr.length(); 117 idx_offset += cstr.length();
114 if ( total_written != int(cstr.length()) ) { 118 if ( total_written != int(cstr.length()) ) {
115 f.close(); 119 f.close();
116 QFile::remove( strNewFile ); 120 QFile::remove( strNewFile );
117 return false; 121 return false;
118 } 122 }
119 out = ""; 123 out = "";
120 } 124 }
121 out += " </Contacts>\n</AddressBook>\n"; 125 out += " </Contacts>\n</AddressBook>\n";
122 126
123 // Write Footer 127 // Write Footer
124 cstr = out.utf8(); 128 cstr = out.utf8();
125 total_written = f.writeBlock( cstr.data(), cstr.length() ); 129 total_written = f.writeBlock( cstr.data(), cstr.length() );
126 if ( total_written != int( cstr.length() ) ) { 130 if ( total_written != int( cstr.length() ) ) {
127 f.close(); 131 f.close();
128 QFile::remove( strNewFile ); 132 QFile::remove( strNewFile );
129 return false; 133 return false;
130 } 134 }
131 f.close(); 135 f.close();
132 136
133 // 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
134 // because, I don't feel like using QDir. 138 // because, I don't feel like using QDir.
135 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 139 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
136 qWarning( "problem renaming file %s to %s, errno: %d", 140 qWarning( "problem renaming file %s to %s, errno: %d",
137 strNewFile.latin1(), m_journalName.latin1(), errno ); 141 strNewFile.latin1(), m_journalName.latin1(), errno );
138 // remove the tmp file... 142 // remove the tmp file...
139 QFile::remove( strNewFile ); 143 QFile::remove( strNewFile );
140 } 144 }
141 145
142 /* The journalfile should be removed now... */ 146 /* The journalfile should be removed now... */
143 removeJournal(); 147 removeJournal();
144 148
145 m_changed = false; 149 m_changed = false;
146 return true; 150 return true;
147} 151}
148 152
149bool OPimContactAccessBackend_XML::load () 153bool OPimContactAccessBackend_XML::load ()
150{ 154{
151 m_contactList.clear(); 155 m_contactList.clear();
152 m_uidToContact.clear(); 156 m_uidToContact.clear();
153 157
154 /* Load XML-File and journal if it exists */ 158 /* Load XML-File and journal if it exists */
155 if ( !load ( m_fileName, false ) ) 159 if ( !load ( m_fileName, false ) )
156 return false; 160 return false;
157 /* The returncode of the journalfile is ignored due to the 161 /* The returncode of the journalfile is ignored due to the
158 * fact that it does not exist when this class is instantiated ! 162 * fact that it does not exist when this class is instantiated !
159 * But there may such a file exist, if the application crashed. 163 * But there may such a file exist, if the application crashed.
160 * 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 #
161 * crash happened... 165 * crash happened...
162 */ 166 */
163 load (m_journalName, true); 167 load (m_journalName, true);
164 168
165 return true; 169 return true;
166} 170}
167 171
168void OPimContactAccessBackend_XML::clear () 172void OPimContactAccessBackend_XML::clear ()
169{ 173{
170 m_contactList.clear(); 174 m_contactList.clear();
171 m_uidToContact.clear(); 175 m_uidToContact.clear();
172 176
173 m_changed = false; 177 m_changed = false;
174} 178}
175 179
176bool OPimContactAccessBackend_XML::wasChangedExternally() 180bool OPimContactAccessBackend_XML::wasChangedExternally()
177{ 181{
178 QFileInfo fi( m_fileName ); 182 QFileInfo fi( m_fileName );
179 183
180 QDateTime lastmod = fi.lastModified (); 184 QDateTime lastmod = fi.lastModified ();
181 185
182 return (lastmod != m_readtime); 186 return (lastmod != m_readtime);
183} 187}
184 188
185QArray<int> OPimContactAccessBackend_XML::allRecords() const 189QArray<int> OPimContactAccessBackend_XML::allRecords() const
186{ 190{
187 QArray<int> uid_list( m_contactList.count() ); 191 QArray<int> uid_list( m_contactList.count() );
188 192
189 uint counter = 0; 193 uint counter = 0;
190 QListIterator<OPimContact> it( m_contactList ); 194 QListIterator<OPimContact> it( m_contactList );
191 for( ; it.current(); ++it ){ 195 for( ; it.current(); ++it ){
192 uid_list[counter++] = (*it)->uid(); 196 uid_list[counter++] = (*it)->uid();
193 } 197 }
194 198
195 return ( uid_list ); 199 return ( uid_list );
196} 200}
197 201
198OPimContact OPimContactAccessBackend_XML::find ( int uid ) const 202OPimContact OPimContactAccessBackend_XML::find ( int uid ) const
199{ 203{
200 OPimContact foundContact; //Create empty contact 204 OPimContact foundContact; //Create empty contact
201 205
202 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) ); 206 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) );
203 207
204 if ( found ){ 208 if ( found ){
205 foundContact = *found; 209 foundContact = *found;
206 } 210 }
207 211
208 return ( foundContact ); 212 return ( foundContact );
209} 213}
210 214
211QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, 215QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings,
212 const QDateTime& d ) 216 const QDateTime& d )
213{ 217{
214 218
215 QArray<int> m_currentQuery( m_contactList.count() ); 219 QArray<int> m_currentQuery( m_contactList.count() );
216 QListIterator<OPimContact> it( m_contactList ); 220 QListIterator<OPimContact> it( m_contactList );
217 uint arraycounter = 0; 221 uint arraycounter = 0;
218 222
219 for( ; it.current(); ++it ){ 223 for( ; it.current(); ++it ){
220 /* 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
221 * if all fields matches. 225 * if all fields matches.
222 */ 226 */
223 QDate* queryDate = 0l; 227 QDate* queryDate = 0l;
224 QDate* checkDate = 0l; 228 QDate* checkDate = 0l;
225 bool allcorrect = true; 229 bool allcorrect = true;
226 for ( int i = 0; i < Qtopia::Groups; i++ ) { 230 for ( int i = 0; i < Qtopia::Groups; i++ ) {
227 // Birthday and anniversary are special nonstring fields and should 231 // Birthday and anniversary are special nonstring fields and should
228 // be handled specially 232 // be handled specially
229 switch ( i ){ 233 switch ( i ){
230 case Qtopia::Birthday: 234 case Qtopia::Birthday:
231 queryDate = new QDate( query.birthday() ); 235 queryDate = new QDate( query.birthday() );
232 checkDate = new QDate( (*it)->birthday() ); 236 checkDate = new QDate( (*it)->birthday() );
233 // fall through 237 // fall through
234 case Qtopia::Anniversary: 238 case Qtopia::Anniversary:
235 if ( queryDate == 0l ){ 239 if ( queryDate == 0l ){
236 queryDate = new QDate( query.anniversary() ); 240 queryDate = new QDate( query.anniversary() );
237 checkDate = new QDate( (*it)->anniversary() ); 241 checkDate = new QDate( (*it)->anniversary() );
238 } 242 }
239 243
240 if ( queryDate->isValid() ){ 244 if ( queryDate->isValid() ){
241 if( checkDate->isValid() ){ 245 if( checkDate->isValid() ){
242 if ( settings & OPimContactAccess::DateYear ){ 246 if ( settings & OPimContactAccess::DateYear ){
243 if ( queryDate->year() != checkDate->year() ) 247 if ( queryDate->year() != checkDate->year() )
244 allcorrect = false; 248 allcorrect = false;
245 } 249 }
246 if ( settings & OPimContactAccess::DateMonth ){ 250 if ( settings & OPimContactAccess::DateMonth ){
247 if ( queryDate->month() != checkDate->month() ) 251 if ( queryDate->month() != checkDate->month() )
248 allcorrect = false; 252 allcorrect = false;
249 } 253 }
250 if ( settings & OPimContactAccess::DateDay ){ 254 if ( settings & OPimContactAccess::DateDay ){
251 if ( queryDate->day() != checkDate->day() ) 255 if ( queryDate->day() != checkDate->day() )
252 allcorrect = false; 256 allcorrect = false;
253 } 257 }
254 if ( settings & OPimContactAccess::DateDiff ) { 258 if ( settings & OPimContactAccess::DateDiff ) {
255 QDate current; 259 QDate current;
256 // If we get an additional date, we 260 // If we get an additional date, we
257 // will take this date instead of 261 // will take this date instead of
258 // the current one.. 262 // the current one..
259 if ( !d.date().isValid() ) 263 if ( !d.date().isValid() )
260 current = QDate::currentDate(); 264 current = QDate::currentDate();
261 else 265 else
262 current = d.date(); 266 current = d.date();
263 267
264 // We have to equalize the year, otherwise 268 // We have to equalize the year, otherwise
265 // the search will fail.. 269 // the search will fail..
266 checkDate->setYMD( current.year(), 270 checkDate->setYMD( current.year(),
267 checkDate->month(), 271 checkDate->month(),
268 checkDate->day() ); 272 checkDate->day() );
269 if ( *checkDate < current ) 273 if ( *checkDate < current )
270 checkDate->setYMD( current.year()+1, 274 checkDate->setYMD( current.year()+1,
271 checkDate->month(), 275 checkDate->month(),
272 checkDate->day() ); 276 checkDate->day() );
273 277
274 // Check whether the birthday/anniversary date is between 278 // Check whether the birthday/anniversary date is between
275 // the current/given date and the maximum date 279 // the current/given date and the maximum date
276 // ( maximum time range ) ! 280 // ( maximum time range ) !
277 qWarning("Checking if %s is between %s and %s ! ", 281 qWarning("Checking if %s is between %s and %s ! ",
278 checkDate->toString().latin1(), 282 checkDate->toString().latin1(),
279 current.toString().latin1(), 283 current.toString().latin1(),
280 queryDate->toString().latin1() ); 284 queryDate->toString().latin1() );
281 if ( current.daysTo( *queryDate ) >= 0 ){ 285 if ( current.daysTo( *queryDate ) >= 0 ){
282 if ( !( ( *checkDate >= current ) && 286 if ( !( ( *checkDate >= current ) &&
283 ( *checkDate <= *queryDate ) ) ){ 287 ( *checkDate <= *queryDate ) ) ){
284 allcorrect = false; 288 allcorrect = false;
285 qWarning (" Nope!.."); 289 qWarning (" Nope!..");
286 } 290 }
287 } 291 }
288 } 292 }
289 } else{ 293 } else{
290 // checkDate is invalid. Therefore this entry is always rejected 294 // checkDate is invalid. Therefore this entry is always rejected
291 allcorrect = false; 295 allcorrect = false;
292 } 296 }
293 } 297 }
294 298
295 delete queryDate; 299 delete queryDate;
296 queryDate = 0l; 300 queryDate = 0l;
297 delete checkDate; 301 delete checkDate;
298 checkDate = 0l; 302 checkDate = 0l;
299 break; 303 break;
300 default: 304 default:
301 /* Just compare fields which are not empty in the query object */ 305 /* Just compare fields which are not empty in the query object */
302 if ( !query.field(i).isEmpty() ){ 306 if ( !query.field(i).isEmpty() ){
303 switch ( settings & ~( OPimContactAccess::IgnoreCase 307 switch ( settings & ~( OPimContactAccess::IgnoreCase
304 | OPimContactAccess::DateDiff 308 | OPimContactAccess::DateDiff
305 | OPimContactAccess::DateYear 309 | OPimContactAccess::DateYear
306 | OPimContactAccess::DateMonth 310 | OPimContactAccess::DateMonth
307 | OPimContactAccess::DateDay 311 | OPimContactAccess::DateDay
308 | OPimContactAccess::MatchOne 312 | OPimContactAccess::MatchOne
309 ) ){ 313 ) ){
310 314
311 case OPimContactAccess::RegExp:{ 315 case OPimContactAccess::RegExp:{
312 QRegExp expr ( query.field(i), 316 QRegExp expr ( query.field(i),
313 !(settings & OPimContactAccess::IgnoreCase), 317 !(settings & OPimContactAccess::IgnoreCase),
314 false ); 318 false );
315 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 319 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
316 allcorrect = false; 320 allcorrect = false;
317 } 321 }
318 break; 322 break;
319 case OPimContactAccess::WildCards:{ 323 case OPimContactAccess::WildCards:{
320 QRegExp expr ( query.field(i), 324 QRegExp expr ( query.field(i),
321 !(settings & OPimContactAccess::IgnoreCase), 325 !(settings & OPimContactAccess::IgnoreCase),
322 true ); 326 true );
323 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 327 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
324 allcorrect = false; 328 allcorrect = false;
325 } 329 }
326 break; 330 break;
327 case OPimContactAccess::ExactMatch:{ 331 case OPimContactAccess::ExactMatch:{
328 if (settings & OPimContactAccess::IgnoreCase){ 332 if (settings & OPimContactAccess::IgnoreCase){
329 if ( query.field(i).upper() != 333 if ( query.field(i).upper() !=
330 (*it)->field(i).upper() ) 334 (*it)->field(i).upper() )
331 allcorrect = false; 335 allcorrect = false;
332 }else{ 336 }else{
333 if ( query.field(i) != (*it)->field(i) ) 337 if ( query.field(i) != (*it)->field(i) )
334 allcorrect = false; 338 allcorrect = false;
335 } 339 }
336 } 340 }
337 break; 341 break;
338 } 342 }
339 } 343 }
340 } 344 }
341 } 345 }
342 if ( allcorrect ){ 346 if ( allcorrect ){
343 m_currentQuery[arraycounter++] = (*it)->uid(); 347 m_currentQuery[arraycounter++] = (*it)->uid();
344 } 348 }
345 } 349 }
346 350
347 // Shrink to fit.. 351 // Shrink to fit..
348 m_currentQuery.resize(arraycounter); 352 m_currentQuery.resize(arraycounter);
349 353
350 return m_currentQuery; 354 return m_currentQuery;
351} 355}
352 356
353QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const 357QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
354{ 358{
355 QArray<int> m_currentQuery( m_contactList.count() ); 359 QArray<int> m_currentQuery( m_contactList.count() );
356 QListIterator<OPimContact> it( m_contactList ); 360 QListIterator<OPimContact> it( m_contactList );
357 uint arraycounter = 0; 361 uint arraycounter = 0;
358 362
359 for( ; it.current(); ++it ){ 363 for( ; it.current(); ++it ){
360 if ( (*it)->match( r ) ){ 364 if ( (*it)->match( r ) ){
361 m_currentQuery[arraycounter++] = (*it)->uid(); 365 m_currentQuery[arraycounter++] = (*it)->uid();
362 } 366 }
363 367
364 } 368 }
365 // Shrink to fit.. 369 // Shrink to fit..
366 m_currentQuery.resize(arraycounter); 370 m_currentQuery.resize(arraycounter);
367 371
368 return m_currentQuery; 372 return m_currentQuery;
369} 373}
370 374
371const uint OPimContactAccessBackend_XML::querySettings() 375const uint OPimContactAccessBackend_XML::querySettings()
372{ 376{
373 return ( OPimContactAccess::WildCards 377 return ( OPimContactAccess::WildCards
374 | OPimContactAccess::IgnoreCase 378 | OPimContactAccess::IgnoreCase
375 | OPimContactAccess::RegExp 379 | OPimContactAccess::RegExp
376 | OPimContactAccess::ExactMatch 380 | OPimContactAccess::ExactMatch
377 | OPimContactAccess::DateDiff 381 | OPimContactAccess::DateDiff
378 | OPimContactAccess::DateYear 382 | OPimContactAccess::DateYear
379 | OPimContactAccess::DateMonth 383 | OPimContactAccess::DateMonth
380 | OPimContactAccess::DateDay 384 | OPimContactAccess::DateDay
381 ); 385 );
382} 386}
383 387
384bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const 388bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
385{ 389{
386 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 390 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
387 * may be added with any of the other settings. IgnoreCase should never used alone. 391 * may be added with any of the other settings. IgnoreCase should never used alone.
388 * Wildcards, RegExp, ExactMatch should never used at the same time... 392 * Wildcards, RegExp, ExactMatch should never used at the same time...
389 */ 393 */
390 394
391 // Step 1: Check whether the given settings are supported by this backend 395 // Step 1: Check whether the given settings are supported by this backend
392 if ( ( querySettings & ( 396 if ( ( querySettings & (
393 OPimContactAccess::IgnoreCase 397 OPimContactAccess::IgnoreCase
394 | OPimContactAccess::WildCards 398 | OPimContactAccess::WildCards
395 | OPimContactAccess::DateDiff 399 | OPimContactAccess::DateDiff
396 | OPimContactAccess::DateYear 400 | OPimContactAccess::DateYear
397 | OPimContactAccess::DateMonth 401 | OPimContactAccess::DateMonth
398 | OPimContactAccess::DateDay 402 | OPimContactAccess::DateDay
399 | OPimContactAccess::RegExp 403 | OPimContactAccess::RegExp
400 | OPimContactAccess::ExactMatch 404 | OPimContactAccess::ExactMatch
401 ) ) != querySettings ) 405 ) ) != querySettings )
402 return false; 406 return false;
403 407
404 // Step 2: Check whether the given combinations are ok.. 408 // Step 2: Check whether the given combinations are ok..
405 409
406 // IngoreCase alone is invalid 410 // IngoreCase alone is invalid
407 if ( querySettings == OPimContactAccess::IgnoreCase ) 411 if ( querySettings == OPimContactAccess::IgnoreCase )
408 return false; 412 return false;
409 413
410 // WildCards, RegExp and ExactMatch should never used at the same time 414 // WildCards, RegExp and ExactMatch should never used at the same time
411 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 415 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
412 | OPimContactAccess::DateDiff 416 | OPimContactAccess::DateDiff
413 | OPimContactAccess::DateYear 417 | OPimContactAccess::DateYear
414 | OPimContactAccess::DateMonth 418 | OPimContactAccess::DateMonth
415 | OPimContactAccess::DateDay 419 | OPimContactAccess::DateDay
416 ) 420 )
417 ){ 421 ){
418 case OPimContactAccess::RegExp: 422 case OPimContactAccess::RegExp:
419 return ( true ); 423 return ( true );
420 case OPimContactAccess::WildCards: 424 case OPimContactAccess::WildCards:
421 return ( true ); 425 return ( true );
422 case OPimContactAccess::ExactMatch: 426 case OPimContactAccess::ExactMatch:
423 return ( true ); 427 return ( true );
424 case 0: // one of the upper removed bits were set.. 428 case 0: // one of the upper removed bits were set..
425 return ( true ); 429 return ( true );
426 default: 430 default:
427 return ( false ); 431 return ( false );
428 } 432 }
429} 433}
430 434
431// Currently only asc implemented.. 435// Currently only asc implemented..
432QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) 436QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
433{ 437{
434 QMap<QString, int> nameToUid; 438 QMap<QString, int> nameToUid;
435 QStringList names; 439 QStringList names;
436 QArray<int> m_currentQuery( m_contactList.count() ); 440 QArray<int> m_currentQuery( m_contactList.count() );
437 441
438 // First fill map and StringList with all Names 442 // First fill map and StringList with all Names
439 // Afterwards sort namelist and use map to fill array to return.. 443 // Afterwards sort namelist and use map to fill array to return..
440 QListIterator<OPimContact> it( m_contactList ); 444 QListIterator<OPimContact> it( m_contactList );
441 for( ; it.current(); ++it ){ 445 for( ; it.current(); ++it ){
442 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); 446 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
443 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); 447 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
444 } 448 }
445 names.sort(); 449 names.sort();
446 450
447 int i = 0; 451 int i = 0;
448 if ( asc ){ 452 if ( asc ){
449 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 453 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
450 m_currentQuery[i++] = nameToUid[ (*it) ]; 454 m_currentQuery[i++] = nameToUid[ (*it) ];
451 }else{ 455 }else{
452 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 456 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
453 m_currentQuery[i++] = nameToUid[ (*it) ]; 457 m_currentQuery[i++] = nameToUid[ (*it) ];
454 } 458 }
455 459
456 return m_currentQuery; 460 return m_currentQuery;
457 461
458} 462}
459 463
460bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact ) 464bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
461{ 465{
462 //qWarning("odefaultbackend: ACTION::ADD"); 466 //owarn << "odefaultbackend: ACTION::ADD" << oendl;
463 updateJournal (newcontact, ACTION_ADD); 467 updateJournal (newcontact, ACTION_ADD);
464 addContact_p( newcontact ); 468 addContact_p( newcontact );
465 469
466 m_changed = true; 470 m_changed = true;
467 471
468 return true; 472 return true;
469} 473}
470 474
471bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact ) 475bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
472{ 476{
473 m_changed = true; 477 m_changed = true;
474 478
475 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); 479 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
476 480
477 if ( found ) { 481 if ( found ) {
478 OPimContact* newCont = new OPimContact( contact ); 482 OPimContact* newCont = new OPimContact( contact );
479 483
480 updateJournal ( *newCont, ACTION_REPLACE); 484 updateJournal ( *newCont, ACTION_REPLACE);
481 m_contactList.removeRef ( found ); 485 m_contactList.removeRef ( found );
482 m_contactList.append ( newCont ); 486 m_contactList.append ( newCont );
483 m_uidToContact.remove( QString().setNum( contact.uid() ) ); 487 m_uidToContact.remove( QString().setNum( contact.uid() ) );
484 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); 488 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
485 489
486 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); 490 owarn << "Nur zur Sicherheit: " << contact.uid() << " == " << newCont->uid() << " ?" << oendl;
487 491
488 return true; 492 return true;
489 } else 493 } else
490 return false; 494 return false;
491} 495}
492 496
493bool OPimContactAccessBackend_XML::remove ( int uid ) 497bool OPimContactAccessBackend_XML::remove ( int uid )
494{ 498{
495 m_changed = true; 499 m_changed = true;
496 500
497 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) ); 501 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) );
498 502
499 if ( found ) { 503 if ( found ) {
500 updateJournal ( *found, ACTION_REMOVE); 504 updateJournal ( *found, ACTION_REMOVE);
501 m_contactList.removeRef ( found ); 505 m_contactList.removeRef ( found );
502 m_uidToContact.remove( QString().setNum( uid ) ); 506 m_uidToContact.remove( QString().setNum( uid ) );
503 507
504 return true; 508 return true;
505 } else 509 } else
506 return false; 510 return false;
507} 511}
508 512
509bool OPimContactAccessBackend_XML::reload(){ 513bool OPimContactAccessBackend_XML::reload(){
510 /* Reload is the same as load in this implementation */ 514 /* Reload is the same as load in this implementation */
511 return ( load() ); 515 return ( load() );
512} 516}
513 517
514void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact ) 518void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact )
515{ 519{
516 OPimContact* contRef = new OPimContact( newcontact ); 520 OPimContact* contRef = new OPimContact( newcontact );
517 521
518 m_contactList.append ( contRef ); 522 m_contactList.append ( contRef );
519 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); 523 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
520} 524}
521 525
522/* This function loads the xml-database and the journalfile */ 526/* This function loads the xml-database and the journalfile */
523bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal ) 527bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal )
524{ 528{
525 529
526 /* We use the time of the last read to check if the file was 530 /* We use the time of the last read to check if the file was
527 * changed externally. 531 * changed externally.
528 */ 532 */
529 if ( !isJournal ){ 533 if ( !isJournal ){
530 QFileInfo fi( filename ); 534 QFileInfo fi( filename );
531 m_readtime = fi.lastModified (); 535 m_readtime = fi.lastModified ();
532 } 536 }
533 537
534 const int JOURNALACTION = Qtopia::Notes + 1; 538 const int JOURNALACTION = Qtopia::Notes + 1;
535 const int JOURNALROW = JOURNALACTION + 1; 539 const int JOURNALROW = JOURNALACTION + 1;
536 540
537 bool foundAction = false; 541 bool foundAction = false;
538 journal_action action = ACTION_ADD; 542 journal_action action = ACTION_ADD;
539 int journalKey = 0; 543 int journalKey = 0;
540 QMap<int, QString> contactMap; 544 QMap<int, QString> contactMap;
541 QMap<QString, QString> customMap; 545 QMap<QString, QString> customMap;
542 QMap<QString, QString>::Iterator customIt; 546 QMap<QString, QString>::Iterator customIt;
543 QAsciiDict<int> dict( 47 ); 547 QAsciiDict<int> dict( 47 );
544 548
545 dict.setAutoDelete( TRUE ); 549 dict.setAutoDelete( TRUE );
546 dict.insert( "Uid", new int(Qtopia::AddressUid) ); 550 dict.insert( "Uid", new int(Qtopia::AddressUid) );
547 dict.insert( "Title", new int(Qtopia::Title) ); 551 dict.insert( "Title", new int(Qtopia::Title) );
548 dict.insert( "FirstName", new int(Qtopia::FirstName) ); 552 dict.insert( "FirstName", new int(Qtopia::FirstName) );
549 dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); 553 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
550 dict.insert( "LastName", new int(Qtopia::LastName) ); 554 dict.insert( "LastName", new int(Qtopia::LastName) );
551 dict.insert( "Suffix", new int(Qtopia::Suffix) ); 555 dict.insert( "Suffix", new int(Qtopia::Suffix) );
552 dict.insert( "FileAs", new int(Qtopia::FileAs) ); 556 dict.insert( "FileAs", new int(Qtopia::FileAs) );
553 dict.insert( "Categories", new int(Qtopia::AddressCategory) ); 557 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
554 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); 558 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
555 dict.insert( "Emails", new int(Qtopia::Emails) ); 559 dict.insert( "Emails", new int(Qtopia::Emails) );
556 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); 560 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
557 dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); 561 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
558 dict.insert( "HomeState", new int(Qtopia::HomeState) ); 562 dict.insert( "HomeState", new int(Qtopia::HomeState) );
559 dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); 563 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
560 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); 564 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
561 dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); 565 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
562 dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); 566 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
563 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); 567 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
564 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); 568 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
565 dict.insert( "Company", new int(Qtopia::Company) ); 569 dict.insert( "Company", new int(Qtopia::Company) );
566 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); 570 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
567 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); 571 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
568 dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); 572 dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
569 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); 573 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
570 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); 574 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
571 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); 575 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
572 dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); 576 dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
573 dict.insert( "Department", new int(Qtopia::Department) ); 577 dict.insert( "Department", new int(Qtopia::Department) );
574 dict.insert( "Office", new int(Qtopia::Office) ); 578 dict.insert( "Office", new int(Qtopia::Office) );
575 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); 579 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
576 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); 580 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
577 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); 581 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
578 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); 582 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
579 dict.insert( "Profession", new int(Qtopia::Profession) ); 583 dict.insert( "Profession", new int(Qtopia::Profession) );
580 dict.insert( "Assistant", new int(Qtopia::Assistant) ); 584 dict.insert( "Assistant", new int(Qtopia::Assistant) );
581 dict.insert( "Manager", new int(Qtopia::Manager) ); 585 dict.insert( "Manager", new int(Qtopia::Manager) );
582 dict.insert( "Spouse", new int(Qtopia::Spouse) ); 586 dict.insert( "Spouse", new int(Qtopia::Spouse) );
583 dict.insert( "Children", new int(Qtopia::Children) ); 587 dict.insert( "Children", new int(Qtopia::Children) );
584 dict.insert( "Gender", new int(Qtopia::Gender) ); 588 dict.insert( "Gender", new int(Qtopia::Gender) );
585 dict.insert( "Birthday", new int(Qtopia::Birthday) ); 589 dict.insert( "Birthday", new int(Qtopia::Birthday) );
586 dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); 590 dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
587 dict.insert( "Nickname", new int(Qtopia::Nickname) ); 591 dict.insert( "Nickname", new int(Qtopia::Nickname) );
588 dict.insert( "Notes", new int(Qtopia::Notes) ); 592 dict.insert( "Notes", new int(Qtopia::Notes) );
589 dict.insert( "action", new int(JOURNALACTION) ); 593 dict.insert( "action", new int(JOURNALACTION) );
590 dict.insert( "actionrow", new int(JOURNALROW) ); 594 dict.insert( "actionrow", new int(JOURNALROW) );
591 595
592 //qWarning( "OPimContactDefaultBackEnd::loading %s", filename.latin1() ); 596 //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl;
593 597
594 XMLElement *root = XMLElement::load( filename ); 598 XMLElement *root = XMLElement::load( filename );
595 if(root != 0l ){ // start parsing 599 if(root != 0l ){ // start parsing
596 /* Parse all XML-Elements and put the data into the 600 /* Parse all XML-Elements and put the data into the
597 * Contact-Class 601 * Contact-Class
598 */ 602 */
599 XMLElement *element = root->firstChild(); 603 XMLElement *element = root->firstChild();
600 //qWarning("OPimContactAccess::load tagName(): %s", root->tagName().latin1() ); 604 //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl;
601 element = element->firstChild(); 605 element = element->firstChild();
602 606
603 /* Search Tag "Contacts" which is the parent of all Contacts */ 607 /* Search Tag "Contacts" which is the parent of all Contacts */
604 while( element && !isJournal ){ 608 while( element && !isJournal ){
605 if( element->tagName() != QString::fromLatin1("Contacts") ){ 609 if( element->tagName() != QString::fromLatin1("Contacts") ){
606 //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s", 610 //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s",
607 // element->tagName().latin1()); 611 // element->tagName().latin1());
608 element = element->nextChild(); 612 element = element->nextChild();
609 } else { 613 } else {
610 element = element->firstChild(); 614 element = element->firstChild();
611 break; 615 break;
612 } 616 }
613 } 617 }
614 /* Parse all Contacts and ignore unknown tags */ 618 /* Parse all Contacts and ignore unknown tags */
615 while( element ){ 619 while( element ){
616 if( element->tagName() != QString::fromLatin1("Contact") ){ 620 if( element->tagName() != QString::fromLatin1("Contact") ){
617 //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s", 621 //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s",
618 // element->tagName().latin1()); 622 // element->tagName().latin1());
619 element = element->nextChild(); 623 element = element->nextChild();
620 continue; 624 continue;
621 } 625 }
622 /* Found alement with tagname "contact", now parse and store all 626 /* Found alement with tagname "contact", now parse and store all
623 * attributes contained 627 * attributes contained
624 */ 628 */
625 //qWarning("OPimContactDefBack::load element tagName() : %s", 629 //qWarning("OPimContactDefBack::load element tagName() : %s",
626 // element->tagName().latin1() ); 630 // element->tagName().latin1() );
627 QString dummy; 631 QString dummy;
628 foundAction = false; 632 foundAction = false;
629 633
630 XMLElement::AttributeMap aMap = element->attributes(); 634 XMLElement::AttributeMap aMap = element->attributes();
631 XMLElement::AttributeMap::Iterator it; 635 XMLElement::AttributeMap::Iterator it;
632 contactMap.clear(); 636 contactMap.clear();
633 customMap.clear(); 637 customMap.clear();
634 for( it = aMap.begin(); it != aMap.end(); ++it ){ 638 for( it = aMap.begin(); it != aMap.end(); ++it ){
635 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); 639 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1());
636 640
637 int *find = dict[ it.key() ]; 641 int *find = dict[ it.key() ];
638 /* Unknown attributes will be stored as "Custom" elements */ 642 /* Unknown attributes will be stored as "Custom" elements */
639 if ( !find ) { 643 if ( !find ) {
640 // qWarning("Attribute %s not known.", it.key().latin1()); 644 // owarn << "Attribute " << it.key() << " not known." << oendl;
641 //contact.setCustomField(it.key(), it.data()); 645 //contact.setCustomField(it.key(), it.data());
642 customMap.insert( it.key(), it.data() ); 646 customMap.insert( it.key(), it.data() );
643 continue; 647 continue;
644 } 648 }
645 649
646 /* Check if special conversion is needed and add attribute 650 /* Check if special conversion is needed and add attribute
647 * into Contact class 651 * into Contact class
648 */ 652 */
649 switch( *find ) { 653 switch( *find ) {
650 /* 654 /*
651 case Qtopia::AddressUid: 655 case Qtopia::AddressUid:
652 contact.setUid( it.data().toInt() ); 656 contact.setUid( it.data().toInt() );
653 break; 657 break;
654 case Qtopia::AddressCategory: 658 case Qtopia::AddressCategory:
655 contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); 659 contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
656 break; 660 break;
657 */ 661 */
658 case JOURNALACTION: 662 case JOURNALACTION:
659 action = journal_action(it.data().toInt()); 663 action = journal_action(it.data().toInt());
660 foundAction = true; 664 foundAction = true;
661 qWarning ("ODefBack(journal)::ACTION found: %d", action); 665 qWarning ("ODefBack(journal)::ACTION found: %d", action);
662 break; 666 break;
663 case JOURNALROW: 667 case JOURNALROW:
664 journalKey = it.data().toInt(); 668 journalKey = it.data().toInt();
665 break; 669 break;
666 default: // no conversion needed add them to the map 670 default: // no conversion needed add them to the map
667 contactMap.insert( *find, it.data() ); 671 contactMap.insert( *find, it.data() );
668 break; 672 break;
669 } 673 }
670 } 674 }
671 /* now generate the Contact contact */ 675 /* now generate the Contact contact */
672 OPimContact contact( contactMap ); 676 OPimContact contact( contactMap );
673 677
674 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { 678 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
675 contact.setCustomField( customIt.key(), customIt.data() ); 679 contact.setCustomField( customIt.key(), customIt.data() );
676 } 680 }
677 681
678 if (foundAction){ 682 if (foundAction){
679 foundAction = false; 683 foundAction = false;
680 switch ( action ) { 684 switch ( action ) {
681 case ACTION_ADD: 685 case ACTION_ADD:
682 addContact_p (contact); 686 addContact_p (contact);
683 break; 687 break;
684 case ACTION_REMOVE: 688 case ACTION_REMOVE:
685 if ( !remove (contact.uid()) ) 689 if ( !remove (contact.uid()) )
686 qWarning ("ODefBack(journal)::Unable to remove uid: %d", 690 qWarning ("ODefBack(journal)::Unable to remove uid: %d",
687 contact.uid() ); 691 contact.uid() );
688 break; 692 break;
689 case ACTION_REPLACE: 693 case ACTION_REPLACE:
690 if ( !replace ( contact ) ) 694 if ( !replace ( contact ) )
691 qWarning ("ODefBack(journal)::Unable to replace uid: %d", 695 qWarning ("ODefBack(journal)::Unable to replace uid: %d",
692 contact.uid() ); 696 contact.uid() );
693 break; 697 break;
694 default: 698 default:
695 qWarning ("Unknown action: ignored !"); 699 qWarning ("Unknown action: ignored !");
696 break; 700 break;
697 } 701 }
698 }else{ 702 }else{
699 /* Add contact to list */ 703 /* Add contact to list */
700 addContact_p (contact); 704 addContact_p (contact);
701 } 705 }
702 706
703 /* Move to next element */ 707 /* Move to next element */
704 element = element->nextChild(); 708 element = element->nextChild();
705 } 709 }
706 }else { 710 }else {
707 qWarning("ODefBack::could not load"); 711 owarn << "ODefBack::could not load" << oendl;
708 } 712 }
709 delete root; 713 delete root;
710 qWarning("returning from loading" ); 714 owarn << "returning from loading" << oendl;
711 return true; 715 return true;
712} 716}
713 717
714 718
715void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt, 719void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt,
716 journal_action action ) 720 journal_action action )
717{ 721{
718 QFile f( m_journalName ); 722 QFile f( m_journalName );
719 bool created = !f.exists(); 723 bool created = !f.exists();
720 if ( !f.open(IO_WriteOnly|IO_Append) ) 724 if ( !f.open(IO_WriteOnly|IO_Append) )
721 return; 725 return;
722 726
723 QString buf; 727 QString buf;
724 QCString str; 728 QCString str;
725 729
726 // if the file was created, we have to set the Tag "<CONTACTS>" to 730 // if the file was created, we have to set the Tag "<CONTACTS>" to
727 // get a XML-File which is readable by our parser. 731 // get a XML-File which is readable by our parser.
728 // This is just a cheat, but better than rewrite the parser. 732 // This is just a cheat, but better than rewrite the parser.
729 if ( created ){ 733 if ( created ){
730 buf = "<Contacts>"; 734 buf = "<Contacts>";
731 QCString cstr = buf.utf8(); 735 QCString cstr = buf.utf8();
732 f.writeBlock( cstr.data(), cstr.length() ); 736 f.writeBlock( cstr.data(), cstr.length() );
733 } 737 }
734 738
735 buf = "<Contact "; 739 buf = "<Contact ";
736 cnt.save( buf ); 740 cnt.save( buf );
737 buf += " action=\"" + QString::number( (int)action ) + "\" "; 741 buf += " action=\"" + QString::number( (int)action ) + "\" ";
738 buf += "/>\n"; 742 buf += "/>\n";
739 QCString cstr = buf.utf8(); 743 QCString cstr = buf.utf8();
740 f.writeBlock( cstr.data(), cstr.length() ); 744 f.writeBlock( cstr.data(), cstr.length() );
741} 745}
742 746
743void OPimContactAccessBackend_XML::removeJournal() 747void OPimContactAccessBackend_XML::removeJournal()
744{ 748{
745 QFile f ( m_journalName ); 749 QFile f ( m_journalName );
746 if ( f.exists() ) 750 if ( f.exists() )
747 f.remove(); 751 f.remove();
748} 752}
749 753
750} 754}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index f4f3c94..105c106 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -1,454 +1,459 @@
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 * SQL Backend for the OPIE-Calender Database. 30 * SQL Backend for the OPIE-Calender Database.
31 * 31 *
32 */ 32 */
33 33
34#include <stdio.h> 34/* OPIE */
35#include <stdlib.h>
36
37#include <qarray.h>
38#include <qstringlist.h>
39
40#include <qpe/global.h>
41
42#include <opie2/osqldriver.h> 35#include <opie2/osqldriver.h>
43#include <opie2/osqlmanager.h> 36#include <opie2/osqlmanager.h>
44#include <opie2/osqlquery.h> 37#include <opie2/osqlquery.h>
45 38
46#include <opie2/opimrecurrence.h> 39#include <opie2/opimrecurrence.h>
47#include <opie2/odatebookaccessbackend_sql.h> 40#include <opie2/odatebookaccessbackend_sql.h>
41#include <opie2/odebug.h>
42
43#include <qpe/global.h>
44
45/* QT */
46#include <qarray.h>
47#include <qstringlist.h>
48
49/* STD */
50#include <stdio.h>
51#include <stdlib.h>
52
48 53
49using namespace Opie::DB; 54using namespace Opie::DB;
50 55
51namespace { 56namespace {
52 /** 57 /**
53 * a find query for custom elements 58 * a find query for custom elements
54 */ 59 */
55 class FindCustomQuery : public OSQLQuery { 60 class FindCustomQuery : public OSQLQuery {
56 public: 61 public:
57 FindCustomQuery(int uid); 62 FindCustomQuery(int uid);
58 FindCustomQuery(const QArray<int>& ); 63 FindCustomQuery(const QArray<int>& );
59 ~FindCustomQuery(); 64 ~FindCustomQuery();
60 QString query()const; 65 QString query()const;
61 private: 66 private:
62 QString single()const; 67 QString single()const;
63 QString multi()const; 68 QString multi()const;
64 QArray<int> m_uids; 69 QArray<int> m_uids;
65 int m_uid; 70 int m_uid;
66 }; 71 };
67 72
68 FindCustomQuery::FindCustomQuery(int uid) 73 FindCustomQuery::FindCustomQuery(int uid)
69 : OSQLQuery(), m_uid( uid ) { 74 : OSQLQuery(), m_uid( uid ) {
70 } 75 }
71 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 76 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
72 : OSQLQuery(), m_uids( ints ){ 77 : OSQLQuery(), m_uids( ints ){
73 } 78 }
74 FindCustomQuery::~FindCustomQuery() { 79 FindCustomQuery::~FindCustomQuery() {
75 } 80 }
76 QString FindCustomQuery::query()const{ 81 QString FindCustomQuery::query()const{
77 // if ( m_uids.count() == 0 ) 82// if ( m_uids.count() == 0 )
78 return single(); 83 return single();
79 } 84 }
80 QString FindCustomQuery::single()const{ 85 QString FindCustomQuery::single()const{
81 QString qu = "select uid, type, value from custom_data where uid = "; 86 QString qu = "select uid, type, value from custom_data where uid = ";
82 qu += QString::number(m_uid); 87 qu += QString::number(m_uid);
83 return qu; 88 return qu;
84 } 89 }
85} 90}
86 91
87 92
88namespace Opie { 93namespace Opie {
89 94
90 95
91ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , 96ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& ,
92 const QString& fileName ) 97 const QString& fileName )
93 : ODateBookAccessBackend(), m_driver( NULL ) 98 : ODateBookAccessBackend(), m_driver( NULL )
94{ 99{
95 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; 100 m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName;
96 101
97 // Get the standart sql-driver from the OSQLManager.. 102 // Get the standart sql-driver from the OSQLManager..
98 OSQLManager man; 103 OSQLManager man;
99 m_driver = man.standard(); 104 m_driver = man.standard();
100 m_driver->setUrl( m_fileName ); 105 m_driver->setUrl( m_fileName );
101 106
102 initFields(); 107 initFields();
103 108
104 load(); 109 load();
105} 110}
106 111
107ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { 112ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() {
108 if( m_driver ) 113 if( m_driver )
109 delete m_driver; 114 delete m_driver;
110} 115}
111 116
112void ODateBookAccessBackend_SQL::initFields() 117void ODateBookAccessBackend_SQL::initFields()
113{ 118{
114 119
115 // This map contains the translation of the fieldtype id's to 120 // This map contains the translation of the fieldtype id's to
116 // the names of the table columns 121 // the names of the table columns
117 m_fieldMap.insert( OPimEvent::FUid, "uid" ); 122 m_fieldMap.insert( OPimEvent::FUid, "uid" );
118 m_fieldMap.insert( OPimEvent::FCategories, "Categories" ); 123 m_fieldMap.insert( OPimEvent::FCategories, "Categories" );
119 m_fieldMap.insert( OPimEvent::FDescription, "Description" ); 124 m_fieldMap.insert( OPimEvent::FDescription, "Description" );
120 m_fieldMap.insert( OPimEvent::FLocation, "Location" ); 125 m_fieldMap.insert( OPimEvent::FLocation, "Location" );
121 m_fieldMap.insert( OPimEvent::FType, "Type" ); 126 m_fieldMap.insert( OPimEvent::FType, "Type" );
122 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" ); 127 m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" );
123 m_fieldMap.insert( OPimEvent::FSound, "Sound" ); 128 m_fieldMap.insert( OPimEvent::FSound, "Sound" );
124 m_fieldMap.insert( OPimEvent::FRType, "RType" ); 129 m_fieldMap.insert( OPimEvent::FRType, "RType" );
125 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" ); 130 m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" );
126 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" ); 131 m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" );
127 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" ); 132 m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" );
128 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" ); 133 m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" );
129 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" ); 134 m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" );
130 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" ); 135 m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" );
131 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" ); 136 m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" );
132 m_fieldMap.insert( OPimEvent::FStart, "Start" ); 137 m_fieldMap.insert( OPimEvent::FStart, "Start" );
133 m_fieldMap.insert( OPimEvent::FEnd, "End" ); 138 m_fieldMap.insert( OPimEvent::FEnd, "End" );
134 m_fieldMap.insert( OPimEvent::FNote, "Note" ); 139 m_fieldMap.insert( OPimEvent::FNote, "Note" );
135 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" ); 140 m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" );
136 m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" ); 141 m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" );
137 m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" ); 142 m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" );
138 143
139 // Create a map that maps the column name to the id 144 // Create a map that maps the column name to the id
140 QMapConstIterator<int, QString> it; 145 QMapConstIterator<int, QString> it;
141 for ( it = m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 146 for ( it = m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
142 m_reverseFieldMap.insert( it.data(), it.key() ); 147 m_reverseFieldMap.insert( it.data(), it.key() );
143 } 148 }
144 149
145} 150}
146 151
147bool ODateBookAccessBackend_SQL::load() 152bool ODateBookAccessBackend_SQL::load()
148{ 153{
149 if (!m_driver->open() ) 154 if (!m_driver->open() )
150 return false; 155 return false;
151 156
152 // Don't expect that the database exists. 157 // Don't expect that the database exists.
153 // It is save here to create the table, even if it 158 // It is save here to create the table, even if it
154 // do exist. ( Is that correct for all databases ?? ) 159 // do exist. ( Is that correct for all databases ?? )
155 QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; 160 QString qu = "create table datebook( uid INTEGER PRIMARY KEY ";
156 161
157 QMap<int, QString>::Iterator it; 162 QMap<int, QString>::Iterator it;
158 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 163 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
159 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); 164 qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() );
160 } 165 }
161 qu += " );"; 166 qu += " );";
162 167
163 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 168 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
164 169
165 qWarning( "command: %s", qu.latin1() ); 170 owarn << "command: " << qu << "" << oendl;
166 171
167 OSQLRawQuery raw( qu ); 172 OSQLRawQuery raw( qu );
168 OSQLResult res = m_driver->query( &raw ); 173 OSQLResult res = m_driver->query( &raw );
169 if ( res.state() != OSQLResult::Success ) 174 if ( res.state() != OSQLResult::Success )
170 return false; 175 return false;
171 176
172 update(); 177 update();
173 178
174 return true; 179 return true;
175} 180}
176 181
177void ODateBookAccessBackend_SQL::update() 182void ODateBookAccessBackend_SQL::update()
178{ 183{
179 184
180 QString qu = "select uid from datebook"; 185 QString qu = "select uid from datebook";
181 OSQLRawQuery raw( qu ); 186 OSQLRawQuery raw( qu );
182 OSQLResult res = m_driver->query( &raw ); 187 OSQLResult res = m_driver->query( &raw );
183 if ( res.state() != OSQLResult::Success ){ 188 if ( res.state() != OSQLResult::Success ){
184 // m_uids.clear(); 189 // m_uids.clear();
185 return; 190 return;
186 } 191 }
187 192
188 m_uids = extractUids( res ); 193 m_uids = extractUids( res );
189 194
190} 195}
191 196
192bool ODateBookAccessBackend_SQL::reload() 197bool ODateBookAccessBackend_SQL::reload()
193{ 198{
194 return load(); 199 return load();
195} 200}
196 201
197bool ODateBookAccessBackend_SQL::save() 202bool ODateBookAccessBackend_SQL::save()
198{ 203{
199 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 204 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
200} 205}
201 206
202QArray<int> ODateBookAccessBackend_SQL::allRecords()const 207QArray<int> ODateBookAccessBackend_SQL::allRecords()const
203{ 208{
204 return m_uids; 209 return m_uids;
205} 210}
206 211
207QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) { 212QArray<int> ODateBookAccessBackend_SQL::queryByExample(const OPimEvent&, int, const QDateTime& ) {
208 return QArray<int>(); 213 return QArray<int>();
209} 214}
210 215
211void ODateBookAccessBackend_SQL::clear() 216void ODateBookAccessBackend_SQL::clear()
212{ 217{
213 QString qu = "drop table datebook;"; 218 QString qu = "drop table datebook;";
214 qu += "drop table custom_data;"; 219 qu += "drop table custom_data;";
215 220
216 OSQLRawQuery raw( qu ); 221 OSQLRawQuery raw( qu );
217 OSQLResult res = m_driver->query( &raw ); 222 OSQLResult res = m_driver->query( &raw );
218 223
219 reload(); 224 reload();
220} 225}
221 226
222 227
223OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{ 228OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
224 qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid ); 229 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " )" << oendl;
225 230
226 QString qu = "select *"; 231 QString qu = "select *";
227 qu += "from datebook where uid = " + QString::number(uid); 232 qu += "from datebook where uid = " + QString::number(uid);
228 233
229 qDebug( "Query: %s", qu.latin1() ); 234 odebug << "Query: " << qu << "" << oendl;
230 235
231 OSQLRawQuery raw( qu ); 236 OSQLRawQuery raw( qu );
232 OSQLResult res = m_driver->query( &raw ); 237 OSQLResult res = m_driver->query( &raw );
233 238
234 OSQLResultItem resItem = res.first(); 239 OSQLResultItem resItem = res.first();
235 240
236 // Create Map for date event and insert UID 241 // Create Map for date event and insert UID
237 QMap<int,QString> dateEventMap; 242 QMap<int,QString> dateEventMap;
238 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) ); 243 dateEventMap.insert( OPimEvent::FUid, QString::number( uid ) );
239 244
240 // Now insert the data out of the columns into the map. 245 // Now insert the data out of the columns into the map.
241 QMapConstIterator<int, QString> it; 246 QMapConstIterator<int, QString> it;
242 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 247 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
243 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) ); 248 dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
244 } 249 }
245 250
246 // Last step: Put map into date event, add custom map and return it 251 // Last step: Put map into date event, add custom map and return it
247 OPimEvent retDate( dateEventMap ); 252 OPimEvent retDate( dateEventMap );
248 retDate.setExtraMap( requestCustom( uid ) ); 253 retDate.setExtraMap( requestCustom( uid ) );
249 254
250 qDebug( "ODateBookAccessBackend_SQL::find( %d ) end", uid ); 255 odebug << "ODateBookAccessBackend_SQL::find( " << uid << " ) end" << oendl;
251 return retDate; 256 return retDate;
252} 257}
253 258
254// FIXME: Speed up update of uid's.. 259// FIXME: Speed up update of uid's..
255bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev ) 260bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
256{ 261{
257 QMap<int,QString> eventMap = ev.toMap(); 262 QMap<int,QString> eventMap = ev.toMap();
258 263
259 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() ); 264 QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
260 QMap<int, QString>::Iterator it; 265 QMap<int, QString>::Iterator it;
261 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ 266 for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
262 if ( !eventMap[it.key()].isEmpty() ) 267 if ( !eventMap[it.key()].isEmpty() )
263 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] ); 268 qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
264 else 269 else
265 qu += QString( ",\"\"" ); 270 qu += QString( ",\"\"" );
266 } 271 }
267 qu += " );"; 272 qu += " );";
268 273
269 // Add custom entries 274 // Add custom entries
270 int id = 0; 275 int id = 0;
271 QMap<QString, QString> customMap = ev.toExtraMap(); 276 QMap<QString, QString> customMap = ev.toExtraMap();
272 for( QMap<QString, QString>::Iterator it = customMap.begin(); 277 for( QMap<QString, QString>::Iterator it = customMap.begin();
273 it != customMap.end(); ++it ){ 278 it != customMap.end(); ++it ){
274 qu += "insert into custom_data VALUES(" 279 qu += "insert into custom_data VALUES("
275 + QString::number( ev.uid() ) 280 + QString::number( ev.uid() )
276 + "," 281 + ","
277 + QString::number( id++ ) 282 + QString::number( id++ )
278 + ",'" 283 + ",'"
279 + it.key() //.latin1() 284 + it.key() //.latin1()
280 + "'," 285 + "',"
281 + "0" // Priority for future enhancements 286 + "0" // Priority for future enhancements
282 + ",'" 287 + ",'"
283 + it.data() //.latin1() 288 + it.data() //.latin1()
284 + "');"; 289 + "');";
285 } 290 }
286 qWarning("add %s", qu.latin1() ); 291 owarn << "add " << qu << "" << oendl;
287 292
288 OSQLRawQuery raw( qu ); 293 OSQLRawQuery raw( qu );
289 OSQLResult res = m_driver->query( &raw ); 294 OSQLResult res = m_driver->query( &raw );
290 if ( res.state() != OSQLResult::Success ){ 295 if ( res.state() != OSQLResult::Success ){
291 return false; 296 return false;
292 } 297 }
293 298
294 // Update list of uid's 299 // Update list of uid's
295 update(); 300 update();
296 301
297 return true; 302 return true;
298} 303}
299 304
300// FIXME: Speed up update of uid's.. 305// FIXME: Speed up update of uid's..
301bool ODateBookAccessBackend_SQL::remove( int uid ) 306bool ODateBookAccessBackend_SQL::remove( int uid )
302{ 307{
303 QString qu = "DELETE from datebook where uid = " 308 QString qu = "DELETE from datebook where uid = "
304 + QString::number( uid ) + ";"; 309 + QString::number( uid ) + ";";
305 qu += "DELETE from custom_data where uid = " 310 qu += "DELETE from custom_data where uid = "
306 + QString::number( uid ) + ";"; 311 + QString::number( uid ) + ";";
307 312
308 OSQLRawQuery raw( qu ); 313 OSQLRawQuery raw( qu );
309 OSQLResult res = m_driver->query( &raw ); 314 OSQLResult res = m_driver->query( &raw );
310 if ( res.state() != OSQLResult::Success ){ 315 if ( res.state() != OSQLResult::Success ){
311 return false; 316 return false;
312 } 317 }
313 318
314 // Update list of uid's 319 // Update list of uid's
315 update(); 320 update();
316 321
317 return true; 322 return true;
318} 323}
319 324
320bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev ) 325bool ODateBookAccessBackend_SQL::replace( const OPimEvent& ev )
321{ 326{
322 remove( ev.uid() ); 327 remove( ev.uid() );
323 return add( ev ); 328 return add( ev );
324} 329}
325 330
326QArray<int> ODateBookAccessBackend_SQL::rawEvents()const 331QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
327{ 332{
328 return allRecords(); 333 return allRecords();
329} 334}
330 335
331QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const 336QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
332{ 337{
333 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\""; 338 QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
334 OSQLRawQuery raw( qu ); 339 OSQLRawQuery raw( qu );
335 OSQLResult res = m_driver->query( &raw ); 340 OSQLResult res = m_driver->query( &raw );
336 if ( res.state() != OSQLResult::Success ){ 341 if ( res.state() != OSQLResult::Success ){
337 QArray<int> nix; 342 QArray<int> nix;
338 return nix; 343 return nix;
339 } 344 }
340 345
341 return extractUids( res ); 346 return extractUids( res );
342} 347}
343 348
344QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const 349QArray<int> ODateBookAccessBackend_SQL::nonRepeats()const
345{ 350{
346 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\""; 351 QString qu = "select uid from datebook where RType=\"\" or RType=\"NoRepeat\"";
347 OSQLRawQuery raw( qu ); 352 OSQLRawQuery raw( qu );
348 OSQLResult res = m_driver->query( &raw ); 353 OSQLResult res = m_driver->query( &raw );
349 if ( res.state() != OSQLResult::Success ){ 354 if ( res.state() != OSQLResult::Success ){
350 QArray<int> nix; 355 QArray<int> nix;
351 return nix; 356 return nix;
352 } 357 }
353 358
354 return extractUids( res ); 359 return extractUids( res );
355} 360}
356 361
357OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats() 362OPimEvent::ValueList ODateBookAccessBackend_SQL::directNonRepeats()
358{ 363{
359 QArray<int> nonRepUids = nonRepeats(); 364 QArray<int> nonRepUids = nonRepeats();
360 OPimEvent::ValueList list; 365 OPimEvent::ValueList list;
361 366
362 for (uint i = 0; i < nonRepUids.count(); ++i ){ 367 for (uint i = 0; i < nonRepUids.count(); ++i ){
363 list.append( find( nonRepUids[i] ) ); 368 list.append( find( nonRepUids[i] ) );
364 } 369 }
365 370
366 return list; 371 return list;
367 372
368} 373}
369OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats() 374OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
370{ 375{
371 QArray<int> rawRepUids = rawRepeats(); 376 QArray<int> rawRepUids = rawRepeats();
372 OPimEvent::ValueList list; 377 OPimEvent::ValueList list;
373 378
374 for (uint i = 0; i < rawRepUids.count(); ++i ){ 379 for (uint i = 0; i < rawRepUids.count(); ++i ){
375 list.append( find( rawRepUids[i] ) ); 380 list.append( find( rawRepUids[i] ) );
376 } 381 }
377 382
378 return list; 383 return list;
379} 384}
380 385
381 386
382QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const 387QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
383{ 388{
384 389
385 QString qu = "SELECT uid FROM datebook WHERE ("; 390 QString qu = "SELECT uid FROM datebook WHERE (";
386 391
387 // Do it make sense to search other fields, too ? 392 // Do it make sense to search other fields, too ?
388 qu += " rlike(\""+ r.pattern() + "\", Location ) OR"; 393 qu += " rlike(\""+ r.pattern() + "\", Location ) OR";
389 qu += " rlike(\""+ r.pattern() + "\", Note )"; 394 qu += " rlike(\""+ r.pattern() + "\", Note )";
390
391 qu += " )";
392 395
393 qDebug( "query: %s", qu.latin1() ); 396 qu += " )";
394 397
395 OSQLRawQuery raw( qu ); 398 odebug << "query: " << qu << "" << oendl;
396 OSQLResult res = m_driver->query( &raw );
397 399
398 return extractUids( res ); 400 OSQLRawQuery raw( qu );
401 OSQLResult res = m_driver->query( &raw );
402
403 return extractUids( res );
399 404
400 405
401 406
402} 407}
403 408
404/* ===== Private Functions ========================================== */ 409/* ===== Private Functions ========================================== */
405 410
406QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const 411QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
407{ 412{
408 qWarning("extractUids"); 413 owarn << "extractUids" << oendl;
409 QTime t; 414 QTime t;
410 t.start(); 415 t.start();
411 OSQLResultItem::ValueList list = res.results(); 416 OSQLResultItem::ValueList list = res.results();
412 OSQLResultItem::ValueList::Iterator it; 417 OSQLResultItem::ValueList::Iterator it;
413 QArray<int> ints(list.count() ); 418 QArray<int> ints(list.count() );
414 qWarning(" count = %d", list.count() ); 419 owarn << " count = " << list.count() << "" << oendl;
415 420
416 int i = 0; 421 int i = 0;
417 for (it = list.begin(); it != list.end(); ++it ) { 422 for (it = list.begin(); it != list.end(); ++it ) {
418 ints[i] = (*it).data("uid").toInt(); 423 ints[i] = (*it).data("uid").toInt();
419 i++; 424 i++;
420 } 425 }
421 qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); 426 owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
422 427
423 return ints; 428 return ints;
424 429
425} 430}
426 431
427QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const 432QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
428{ 433{
429 QTime t; 434 QTime t;
430 t.start(); 435 t.start();
431 436
432 QMap<QString, QString> customMap; 437 QMap<QString, QString> customMap;
433 438
434 FindCustomQuery query( uid ); 439 FindCustomQuery query( uid );
435 OSQLResult res_custom = m_driver->query( &query ); 440 OSQLResult res_custom = m_driver->query( &query );
436 441
437 if ( res_custom.state() == OSQLResult::Failure ) { 442 if ( res_custom.state() == OSQLResult::Failure ) {
438 qWarning("OSQLResult::Failure in find query !!"); 443 owarn << "OSQLResult::Failure in find query !!" << oendl;
439 QMap<QString, QString> empty; 444 QMap<QString, QString> empty;
440 return empty; 445 return empty;
441 } 446 }
442 447
443 OSQLResultItem::ValueList list = res_custom.results(); 448 OSQLResultItem::ValueList list = res_custom.results();
444 OSQLResultItem::ValueList::Iterator it = list.begin(); 449 OSQLResultItem::ValueList::Iterator it = list.begin();
445 for ( ; it != list.end(); ++it ) { 450 for ( ; it != list.end(); ++it ) {
446 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 451 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
447 } 452 }
448 453
449 qDebug("RequestCustom needed: %d ms", t.elapsed() ); 454 odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl;
450 return customMap; 455 return customMap;
451} 456}
452 457
453 458
454} 459}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index 77c0253..2ff36e3 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -1,645 +1,651 @@
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
30/* OPIE */
31#include <opie2/opimnotifymanager.h>
32#include <opie2/opimrecurrence.h>
33#include <opie2/opimtimezone.h>
34#include <opie2/odatebookaccessbackend_xml.h>
35#include <opie2/odebug.h>
36
37#include <qtopia/global.h>
38#include <qtopia/stringutil.h>
39#include <qtopia/timeconversion.h>
40
41/* QT */
42#include <qasciidict.h>
43#include <qfile.h>
44
45/* STD */
29#include <errno.h> 46#include <errno.h>
30#include <fcntl.h> 47#include <fcntl.h>
31 48
32#include <stdio.h> 49#include <stdio.h>
33#include <stdlib.h> 50#include <stdlib.h>
34 51
35#include <sys/types.h> 52#include <sys/types.h>
36#include <sys/mman.h> 53#include <sys/mman.h>
37#include <sys/stat.h> 54#include <sys/stat.h>
38 55
39#include <unistd.h> 56#include <unistd.h>
40 57
41#include <qasciidict.h>
42#include <qfile.h>
43
44#include <qtopia/global.h>
45#include <qtopia/stringutil.h>
46#include <qtopia/timeconversion.h>
47
48#include <opie2/opimnotifymanager.h>
49#include <opie2/opimrecurrence.h>
50#include <opie2/opimtimezone.h>
51#include <opie2/odatebookaccessbackend_xml.h>
52 58
53using namespace Opie; 59using namespace Opie;
54 60
55namespace { 61namespace {
56 // FROM TT again 62 // FROM TT again
57char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 63char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
58{ 64{
59 char needleChar; 65 char needleChar;
60 char haystackChar; 66 char haystackChar;
61 if (!needle || !haystack || !hLen || !nLen) 67 if (!needle || !haystack || !hLen || !nLen)
62 return 0; 68 return 0;
63 69
64 const char* hsearch = haystack; 70 const char* hsearch = haystack;
65 71
66 if ((needleChar = *needle++) != 0) { 72 if ((needleChar = *needle++) != 0) {
67 nLen--; //(to make up for needle++) 73 nLen--; //(to make up for needle++)
68 do { 74 do {
69 do { 75 do {
70 if ((haystackChar = *hsearch++) == 0) 76 if ((haystackChar = *hsearch++) == 0)
71 return (0); 77 return (0);
72 if (hsearch >= haystack + hLen) 78 if (hsearch >= haystack + hLen)
73 return (0); 79 return (0);
74 } while (haystackChar != needleChar); 80 } while (haystackChar != needleChar);
75 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); 81 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
76 hsearch--; 82 hsearch--;
77 } 83 }
78 return ((char *)hsearch); 84 return ((char *)hsearch);
79} 85}
80} 86}
81 87
82namespace { 88namespace {
83 time_t start, end, created, rp_end; 89 time_t start, end, created, rp_end;
84 OPimRecurrence* rec; 90 OPimRecurrence* rec;
85 OPimRecurrence* recur() { 91 OPimRecurrence* recur() {
86 if (!rec) 92 if (!rec)
87 rec = new OPimRecurrence; 93 rec = new OPimRecurrence;
88 94
89 return rec; 95 return rec;
90 } 96 }
91 int alarmTime; 97 int alarmTime;
92 int snd; 98 int snd;
93 enum Attribute{ 99 enum Attribute{
94 FDescription = 0, 100 FDescription = 0,
95 FLocation, 101 FLocation,
96 FCategories, 102 FCategories,
97 FUid, 103 FUid,
98 FType, 104 FType,
99 FAlarm, 105 FAlarm,
100 FSound, 106 FSound,
101 FRType, 107 FRType,
102 FRWeekdays, 108 FRWeekdays,
103 FRPosition, 109 FRPosition,
104 FRFreq, 110 FRFreq,
105 FRHasEndDate, 111 FRHasEndDate,
106 FREndDate, 112 FREndDate,
107 FRStart, 113 FRStart,
108 FREnd, 114 FREnd,
109 FNote, 115 FNote,
110 FCreated, // Should't this be called FRCreated ? 116 FCreated, // Should't this be called FRCreated ?
111 FTimeZone, 117 FTimeZone,
112 FRecParent, 118 FRecParent,
113 FRecChildren, 119 FRecChildren,
114 FExceptions 120 FExceptions
115 }; 121 };
116 122
117 // FIXME: Use OPimEvent::toMap() here !! (eilers) 123 // FIXME: Use OPimEvent::toMap() here !! (eilers)
118 inline void save( const OPimEvent& ev, QString& buf ) { 124 inline void save( const OPimEvent& ev, QString& buf ) {
119 qWarning("Saving %d %s", ev.uid(), ev.description().latin1() ); 125 owarn << "Saving " << ev.uid() << " " << ev.description() << "" << oendl;
120 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\""; 126 buf += " description=\"" + Qtopia::escapeString(ev.description() ) + "\"";
121 if (!ev.location().isEmpty() ) 127 if (!ev.location().isEmpty() )
122 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\""; 128 buf += " location=\"" + Qtopia::escapeString(ev.location() ) + "\"";
123 129
124 buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\""; 130 buf += " categories=\""+ Qtopia::escapeString( Qtopia::Record::idsToString( ev.categories() ) ) + "\"";
125 buf += " uid=\"" + QString::number( ev.uid() ) + "\""; 131 buf += " uid=\"" + QString::number( ev.uid() ) + "\"";
126 132
127 if (ev.isAllDay() ) 133 if (ev.isAllDay() )
128 buf += " type=\"AllDay\""; // is that all ?? (eilers) 134 buf += " type=\"AllDay\""; // is that all ?? (eilers)
129 135
130 if (ev.hasNotifiers() ) { 136 if (ev.hasNotifiers() ) {
131 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first 137 OPimAlarm alarm = ev.notifiers().alarms()[0]; // take only the first
132 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60; 138 int minutes = alarm.dateTime().secsTo( ev.startDateTime() ) / 60;
133 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\""; 139 buf += " alarm=\"" + QString::number(minutes) + "\" sound=\"";
134 if ( alarm.sound() == OPimAlarm::Loud ) 140 if ( alarm.sound() == OPimAlarm::Loud )
135 buf += "loud"; 141 buf += "loud";
136 else 142 else
137 buf += "silent"; 143 buf += "silent";
138 buf += "\""; 144 buf += "\"";
139 } 145 }
140 if ( ev.hasRecurrence() ) { 146 if ( ev.hasRecurrence() ) {
141 buf += ev.recurrence().toString(); 147 buf += ev.recurrence().toString();
142 } 148 }
143 149
144 /* 150 /*
145 * fscking timezones :) well, we'll first convert 151 * fscking timezones :) well, we'll first convert
146 * the QDateTime to a QDateTime in UTC time 152 * the QDateTime to a QDateTime in UTC time
147 * and then we'll create a nice time_t 153 * and then we'll create a nice time_t
148 */ 154 */
149 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); 155 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() );
150 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OPimTimeZone::utc() ) ) ) + "\""; 156 buf += " start=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.startDateTime(), OPimTimeZone::utc() ) ) ) + "\"";
151 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OPimTimeZone::utc() ) ) ) + "\""; 157 buf += " end=\"" + QString::number( zone.fromUTCDateTime( zone.toDateTime( ev.endDateTime() , OPimTimeZone::utc() ) ) ) + "\"";
152 if (!ev.note().isEmpty() ) { 158 if (!ev.note().isEmpty() ) {
153 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\""; 159 buf += " note=\"" + Qtopia::escapeString( ev.note() ) + "\"";
154 } 160 }
155 161
156 buf += " timezone=\""; 162 buf += " timezone=\"";
157 if ( ev.timeZone().isEmpty() ) 163 if ( ev.timeZone().isEmpty() )
158 buf += "None"; 164 buf += "None";
159 else 165 else
160 buf += ev.timeZone(); 166 buf += ev.timeZone();
161 buf += "\""; 167 buf += "\"";
162 168
163 if (ev.parent() != 0 ) { 169 if (ev.parent() != 0 ) {
164 buf += " recparent=\""+QString::number(ev.parent() )+"\""; 170 buf += " recparent=\""+QString::number(ev.parent() )+"\"";
165 } 171 }
166 172
167 if (ev.children().count() != 0 ) { 173 if (ev.children().count() != 0 ) {
168 QArray<int> children = ev.children(); 174 QArray<int> children = ev.children();
169 buf += " recchildren=\""; 175 buf += " recchildren=\"";
170 for ( uint i = 0; i < children.count(); i++ ) { 176 for ( uint i = 0; i < children.count(); i++ ) {
171 if ( i != 0 ) buf += " "; 177 if ( i != 0 ) buf += " ";
172 buf += QString::number( children[i] ); 178 buf += QString::number( children[i] );
173 } 179 }
174 buf+= "\""; 180 buf+= "\"";
175 } 181 }
176 182
177 // skip custom writing 183 // skip custom writing
178 } 184 }
179 185
180 inline bool forAll( const QMap<int, OPimEvent>& list, QFile& file ) { 186 inline bool forAll( const QMap<int, OPimEvent>& list, QFile& file ) {
181 QMap<int, OPimEvent>::ConstIterator it; 187 QMap<int, OPimEvent>::ConstIterator it;
182 QString buf; 188 QString buf;
183 QCString str; 189 QCString str;
184 int total_written; 190 int total_written;
185 for ( it = list.begin(); it != list.end(); ++it ) { 191 for ( it = list.begin(); it != list.end(); ++it ) {
186 buf = "<event"; 192 buf = "<event";
187 save( it.data(), buf ); 193 save( it.data(), buf );
188 buf += " />\n"; 194 buf += " />\n";
189 str = buf.utf8(); 195 str = buf.utf8();
190 196
191 total_written = file.writeBlock(str.data(), str.length() ); 197 total_written = file.writeBlock(str.data(), str.length() );
192 if ( total_written != int(str.length() ) ) 198 if ( total_written != int(str.length() ) )
193 return false; 199 return false;
194 } 200 }
195 return true; 201 return true;
196 } 202 }
197} 203}
198 204
199namespace Opie { 205namespace Opie {
200ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& , 206ODateBookAccessBackend_XML::ODateBookAccessBackend_XML( const QString& ,
201 const QString& fileName ) 207 const QString& fileName )
202 : ODateBookAccessBackend() { 208 : ODateBookAccessBackend() {
203 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName; 209 m_name = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.xml" ) : fileName;
204 m_changed = false; 210 m_changed = false;
205} 211}
206ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() { 212ODateBookAccessBackend_XML::~ODateBookAccessBackend_XML() {
207} 213}
208bool ODateBookAccessBackend_XML::load() { 214bool ODateBookAccessBackend_XML::load() {
209 return loadFile(); 215 return loadFile();
210} 216}
211bool ODateBookAccessBackend_XML::reload() { 217bool ODateBookAccessBackend_XML::reload() {
212 clear(); 218 clear();
213 return load(); 219 return load();
214} 220}
215bool ODateBookAccessBackend_XML::save() { 221bool ODateBookAccessBackend_XML::save() {
216 if (!m_changed) return true; 222 if (!m_changed) return true;
217 223
218 int total_written; 224 int total_written;
219 QString strFileNew = m_name + ".new"; 225 QString strFileNew = m_name + ".new";
220 226
221 QFile f( strFileNew ); 227 QFile f( strFileNew );
222 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false; 228 if (!f.open( IO_WriteOnly | IO_Raw ) ) return false;
223 229
224 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); 230 QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
225 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n"; 231 buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n";
226 buf += "<events>\n"; 232 buf += "<events>\n";
227 QCString str = buf.utf8(); 233 QCString str = buf.utf8();
228 total_written = f.writeBlock( str.data(), str.length() ); 234 total_written = f.writeBlock( str.data(), str.length() );
229 if ( total_written != int(str.length() ) ) { 235 if ( total_written != int(str.length() ) ) {
230 f.close(); 236 f.close();
231 QFile::remove( strFileNew ); 237 QFile::remove( strFileNew );
232 return false; 238 return false;
233 } 239 }
234 240
235 if (!forAll( m_raw, f ) ) { 241 if (!forAll( m_raw, f ) ) {
236 f.close(); 242 f.close();
237 QFile::remove( strFileNew ); 243 QFile::remove( strFileNew );
238 return false; 244 return false;
239 } 245 }
240 if (!forAll( m_rep, f ) ) { 246 if (!forAll( m_rep, f ) ) {
241 f.close(); 247 f.close();
242 QFile::remove( strFileNew ); 248 QFile::remove( strFileNew );
243 return false; 249 return false;
244 } 250 }
245 251
246 buf = "</events>\n</DATEBOOK>\n"; 252 buf = "</events>\n</DATEBOOK>\n";
247 str = buf.utf8(); 253 str = buf.utf8();
248 total_written = f.writeBlock( str.data(), str.length() ); 254 total_written = f.writeBlock( str.data(), str.length() );
249 if ( total_written != int(str.length() ) ) { 255 if ( total_written != int(str.length() ) ) {
250 f.close(); 256 f.close();
251 QFile::remove( strFileNew ); 257 QFile::remove( strFileNew );
252 return false; 258 return false;
253 } 259 }
254 f.close(); 260 f.close();
255 261
256 if ( ::rename( strFileNew, m_name ) < 0 ) { 262 if ( ::rename( strFileNew, m_name ) < 0 ) {
257 QFile::remove( strFileNew ); 263 QFile::remove( strFileNew );
258 return false; 264 return false;
259 } 265 }
260 266
261 m_changed = false; 267 m_changed = false;
262 return true; 268 return true;
263} 269}
264QArray<int> ODateBookAccessBackend_XML::allRecords()const { 270QArray<int> ODateBookAccessBackend_XML::allRecords()const {
265 QArray<int> ints( m_raw.count()+ m_rep.count() ); 271 QArray<int> ints( m_raw.count()+ m_rep.count() );
266 uint i = 0; 272 uint i = 0;
267 QMap<int, OPimEvent>::ConstIterator it; 273 QMap<int, OPimEvent>::ConstIterator it;
268 274
269 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { 275 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
270 ints[i] = it.key(); 276 ints[i] = it.key();
271 i++; 277 i++;
272 } 278 }
273 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { 279 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
274 ints[i] = it.key(); 280 ints[i] = it.key();
275 i++; 281 i++;
276 } 282 }
277 283
278 return ints; 284 return ints;
279} 285}
280QArray<int> ODateBookAccessBackend_XML::queryByExample(const OPimEvent&, int, const QDateTime& ) { 286QArray<int> ODateBookAccessBackend_XML::queryByExample(const OPimEvent&, int, const QDateTime& ) {
281 return QArray<int>(); 287 return QArray<int>();
282} 288}
283void ODateBookAccessBackend_XML::clear() { 289void ODateBookAccessBackend_XML::clear() {
284 m_changed = true; 290 m_changed = true;
285 m_raw.clear(); 291 m_raw.clear();
286 m_rep.clear(); 292 m_rep.clear();
287} 293}
288OPimEvent ODateBookAccessBackend_XML::find( int uid ) const{ 294OPimEvent ODateBookAccessBackend_XML::find( int uid ) const{
289 if ( m_raw.contains( uid ) ) 295 if ( m_raw.contains( uid ) )
290 return m_raw[uid]; 296 return m_raw[uid];
291 else 297 else
292 return m_rep[uid]; 298 return m_rep[uid];
293} 299}
294bool ODateBookAccessBackend_XML::add( const OPimEvent& ev ) { 300bool ODateBookAccessBackend_XML::add( const OPimEvent& ev ) {
295 m_changed = true; 301 m_changed = true;
296 if (ev.hasRecurrence() ) 302 if (ev.hasRecurrence() )
297 m_rep.insert( ev.uid(), ev ); 303 m_rep.insert( ev.uid(), ev );
298 else 304 else
299 m_raw.insert( ev.uid(), ev ); 305 m_raw.insert( ev.uid(), ev );
300 306
301 return true; 307 return true;
302} 308}
303bool ODateBookAccessBackend_XML::remove( int uid ) { 309bool ODateBookAccessBackend_XML::remove( int uid ) {
304 m_changed = true; 310 m_changed = true;
305 m_rep.remove( uid ); 311 m_rep.remove( uid );
306 m_rep.remove( uid ); 312 m_rep.remove( uid );
307 313
308 return true; 314 return true;
309} 315}
310bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) { 316bool ODateBookAccessBackend_XML::replace( const OPimEvent& ev ) {
311 replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers) 317 replace( ev.uid() ); // ??? Shouldn't this be "remove( ev.uid() ) ??? (eilers)
312 return add( ev ); 318 return add( ev );
313} 319}
314QArray<int> ODateBookAccessBackend_XML::rawEvents()const { 320QArray<int> ODateBookAccessBackend_XML::rawEvents()const {
315 return allRecords(); 321 return allRecords();
316} 322}
317QArray<int> ODateBookAccessBackend_XML::rawRepeats()const { 323QArray<int> ODateBookAccessBackend_XML::rawRepeats()const {
318 QArray<int> ints( m_rep.count() ); 324 QArray<int> ints( m_rep.count() );
319 uint i = 0; 325 uint i = 0;
320 QMap<int, OPimEvent>::ConstIterator it; 326 QMap<int, OPimEvent>::ConstIterator it;
321 327
322 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) { 328 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) {
323 ints[i] = it.key(); 329 ints[i] = it.key();
324 i++; 330 i++;
325 } 331 }
326 332
327 return ints; 333 return ints;
328} 334}
329QArray<int> ODateBookAccessBackend_XML::nonRepeats()const { 335QArray<int> ODateBookAccessBackend_XML::nonRepeats()const {
330 QArray<int> ints( m_raw.count() ); 336 QArray<int> ints( m_raw.count() );
331 uint i = 0; 337 uint i = 0;
332 QMap<int, OPimEvent>::ConstIterator it; 338 QMap<int, OPimEvent>::ConstIterator it;
333 339
334 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) { 340 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) {
335 ints[i] = it.key(); 341 ints[i] = it.key();
336 i++; 342 i++;
337 } 343 }
338 344
339 return ints; 345 return ints;
340} 346}
341OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() { 347OPimEvent::ValueList ODateBookAccessBackend_XML::directNonRepeats() {
342 OPimEvent::ValueList list; 348 OPimEvent::ValueList list;
343 QMap<int, OPimEvent>::ConstIterator it; 349 QMap<int, OPimEvent>::ConstIterator it;
344 for (it = m_raw.begin(); it != m_raw.end(); ++it ) 350 for (it = m_raw.begin(); it != m_raw.end(); ++it )
345 list.append( it.data() ); 351 list.append( it.data() );
346 352
347 return list; 353 return list;
348} 354}
349OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() { 355OPimEvent::ValueList ODateBookAccessBackend_XML::directRawRepeats() {
350 OPimEvent::ValueList list; 356 OPimEvent::ValueList list;
351 QMap<int, OPimEvent>::ConstIterator it; 357 QMap<int, OPimEvent>::ConstIterator it;
352 for (it = m_rep.begin(); it != m_rep.end(); ++it ) 358 for (it = m_rep.begin(); it != m_rep.end(); ++it )
353 list.append( it.data() ); 359 list.append( it.data() );
354 360
355 return list; 361 return list;
356} 362}
357 363
358// FIXME: Use OPimEvent::fromMap() (eilers) 364// FIXME: Use OPimEvent::fromMap() (eilers)
359bool ODateBookAccessBackend_XML::loadFile() { 365bool ODateBookAccessBackend_XML::loadFile() {
360 m_changed = false; 366 m_changed = false;
361 367
362 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY ); 368 int fd = ::open( QFile::encodeName(m_name).data(), O_RDONLY );
363 if ( fd < 0 ) return false; 369 if ( fd < 0 ) return false;
364 370
365 struct stat attribute; 371 struct stat attribute;
366 if ( ::fstat(fd, &attribute ) == -1 ) { 372 if ( ::fstat(fd, &attribute ) == -1 ) {
367 ::close( fd ); 373 ::close( fd );
368 return false; 374 return false;
369 } 375 }
370 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 ); 376 void* map_addr = ::mmap(NULL, attribute.st_size, PROT_READ, MAP_SHARED, fd, 0 );
371 if ( map_addr == ( (caddr_t)-1) ) { 377 if ( map_addr == ( (caddr_t)-1) ) {
372 ::close( fd ); 378 ::close( fd );
373 return false; 379 return false;
374 } 380 }
375 381
376 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL ); 382 ::madvise( map_addr, attribute.st_size, MADV_SEQUENTIAL );
377 ::close( fd ); 383 ::close( fd );
378 384
379 QAsciiDict<int> dict(FExceptions+1); 385 QAsciiDict<int> dict(FExceptions+1);
380 dict.setAutoDelete( true ); 386 dict.setAutoDelete( true );
381 dict.insert( "description", new int(FDescription) ); 387 dict.insert( "description", new int(FDescription) );
382 dict.insert( "location", new int(FLocation) ); 388 dict.insert( "location", new int(FLocation) );
383 dict.insert( "categories", new int(FCategories) ); 389 dict.insert( "categories", new int(FCategories) );
384 dict.insert( "uid", new int(FUid) ); 390 dict.insert( "uid", new int(FUid) );
385 dict.insert( "type", new int(FType) ); 391 dict.insert( "type", new int(FType) );
386 dict.insert( "alarm", new int(FAlarm) ); 392 dict.insert( "alarm", new int(FAlarm) );
387 dict.insert( "sound", new int(FSound) ); 393 dict.insert( "sound", new int(FSound) );
388 dict.insert( "rtype", new int(FRType) ); 394 dict.insert( "rtype", new int(FRType) );
389 dict.insert( "rweekdays", new int(FRWeekdays) ); 395 dict.insert( "rweekdays", new int(FRWeekdays) );
390 dict.insert( "rposition", new int(FRPosition) ); 396 dict.insert( "rposition", new int(FRPosition) );
391 dict.insert( "rfreq", new int(FRFreq) ); 397 dict.insert( "rfreq", new int(FRFreq) );
392 dict.insert( "rhasenddate", new int(FRHasEndDate) ); 398 dict.insert( "rhasenddate", new int(FRHasEndDate) );
393 dict.insert( "enddt", new int(FREndDate) ); 399 dict.insert( "enddt", new int(FREndDate) );
394 dict.insert( "start", new int(FRStart) ); 400 dict.insert( "start", new int(FRStart) );
395 dict.insert( "end", new int(FREnd) ); 401 dict.insert( "end", new int(FREnd) );
396 dict.insert( "note", new int(FNote) ); 402 dict.insert( "note", new int(FNote) );
397 dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ?? 403 dict.insert( "created", new int(FCreated) ); // Shouldn't this be FRCreated ??
398 dict.insert( "recparent", new int(FRecParent) ); 404 dict.insert( "recparent", new int(FRecParent) );
399 dict.insert( "recchildren", new int(FRecChildren) ); 405 dict.insert( "recchildren", new int(FRecChildren) );
400 dict.insert( "exceptions", new int(FExceptions) ); 406 dict.insert( "exceptions", new int(FExceptions) );
401 dict.insert( "timezone", new int(FTimeZone) ); 407 dict.insert( "timezone", new int(FTimeZone) );
402 408
403 char* dt = (char*)map_addr; 409 char* dt = (char*)map_addr;
404 int len = attribute.st_size; 410 int len = attribute.st_size;
405 int i = 0; 411 int i = 0;
406 char* point; 412 char* point;
407 const char* collectionString = "<event "; 413 const char* collectionString = "<event ";
408 int strLen = ::strlen(collectionString); 414 int strLen = ::strlen(collectionString);
409 int *find; 415 int *find;
410 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) { 416 while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
411 i = point -dt; 417 i = point -dt;
412 i+= strLen; 418 i+= strLen;
413 419
414 alarmTime = -1; 420 alarmTime = -1;
415 snd = 0; // silent 421 snd = 0; // silent
416 422
417 OPimEvent ev; 423 OPimEvent ev;
418 rec = 0; 424 rec = 0;
419 425
420 while ( TRUE ) { 426 while ( TRUE ) {
421 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 427 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
422 ++i; 428 ++i;
423 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 429 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
424 break; 430 break;
425 431
426 432
427 // we have another attribute, read it. 433 // we have another attribute, read it.
428 int j = i; 434 int j = i;
429 while ( j < len && dt[j] != '=' ) 435 while ( j < len && dt[j] != '=' )
430 ++j; 436 ++j;
431 QCString attr( dt+i, j-i+1); 437 QCString attr( dt+i, j-i+1);
432 438
433 i = ++j; // skip = 439 i = ++j; // skip =
434 440
435 // find the start of quotes 441 // find the start of quotes
436 while ( i < len && dt[i] != '"' ) 442 while ( i < len && dt[i] != '"' )
437 ++i; 443 ++i;
438 j = ++i; 444 j = ++i;
439 445
440 bool haveUtf = FALSE; 446 bool haveUtf = FALSE;
441 bool haveEnt = FALSE; 447 bool haveEnt = FALSE;
442 while ( j < len && dt[j] != '"' ) { 448 while ( j < len && dt[j] != '"' ) {
443 if ( ((unsigned char)dt[j]) > 0x7f ) 449 if ( ((unsigned char)dt[j]) > 0x7f )
444 haveUtf = TRUE; 450 haveUtf = TRUE;
445 if ( dt[j] == '&' ) 451 if ( dt[j] == '&' )
446 haveEnt = TRUE; 452 haveEnt = TRUE;
447 ++j; 453 ++j;
448 } 454 }
449 if ( i == j ) { 455 if ( i == j ) {
450 // empty value 456 // empty value
451 i = j + 1; 457 i = j + 1;
452 continue; 458 continue;
453 } 459 }
454 460
455 QCString value( dt+i, j-i+1 ); 461 QCString value( dt+i, j-i+1 );
456 i = j + 1; 462 i = j + 1;
457 463
458 QString str = (haveUtf ? QString::fromUtf8( value ) 464 QString str = (haveUtf ? QString::fromUtf8( value )
459 : QString::fromLatin1( value ) ); 465 : QString::fromLatin1( value ) );
460 if ( haveEnt ) 466 if ( haveEnt )
461 str = Qtopia::plainString( str ); 467 str = Qtopia::plainString( str );
462 468
463 /* 469 /*
464 * add key + value 470 * add key + value
465 */ 471 */
466 find = dict[attr.data()]; 472 find = dict[attr.data()];
467 if (!find) 473 if (!find)
468 ev.setCustomField( attr, str ); 474 ev.setCustomField( attr, str );
469 else { 475 else {
470 setField( ev, *find, str ); 476 setField( ev, *find, str );
471 } 477 }
472 } 478 }
473 /* time to finalize */ 479 /* time to finalize */
474 finalizeRecord( ev ); 480 finalizeRecord( ev );
475 delete rec; 481 delete rec;
476 } 482 }
477 ::munmap(map_addr, attribute.st_size ); 483 ::munmap(map_addr, attribute.st_size );
478 m_changed = false; // changed during add 484 m_changed = false; // changed during add
479 485
480 return true; 486 return true;
481} 487}
482 488
483// FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers) 489// FIXME: Use OPimEvent::fromMap() which makes this obsolete.. (eilers)
484void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) { 490void ODateBookAccessBackend_XML::finalizeRecord( OPimEvent& ev ) {
485 /* AllDay is alway in UTC */ 491 /* AllDay is alway in UTC */
486 if ( ev.isAllDay() ) { 492 if ( ev.isAllDay() ) {
487 OPimTimeZone utc = OPimTimeZone::utc(); 493 OPimTimeZone utc = OPimTimeZone::utc();
488 ev.setStartDateTime( utc.fromUTCDateTime( start ) ); 494 ev.setStartDateTime( utc.fromUTCDateTime( start ) );
489 ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); 495 ev.setEndDateTime ( utc.fromUTCDateTime( end ) );
490 ev.setTimeZone( "UTC"); // make sure it is really utc 496 ev.setTimeZone( "UTC"); // make sure it is really utc
491 }else { 497 }else {
492 /* to current date time */ 498 /* to current date time */
493 // qWarning(" Start is %d", start ); 499 // owarn << " Start is " << start << "" << oendl;
494 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() ); 500 OPimTimeZone zone( ev.timeZone().isEmpty() ? OPimTimeZone::current() : ev.timeZone() );
495 QDateTime date = zone.toDateTime( start ); 501 QDateTime date = zone.toDateTime( start );
496 qWarning(" Start is %s", date.toString().latin1() ); 502 owarn << " Start is " << date.toString() << "" << oendl;
497 ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); 503 ev.setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
498 504
499 date = zone.toDateTime( end ); 505 date = zone.toDateTime( end );
500 ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); 506 ev.setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) );
501 } 507 }
502 if ( rec && rec->doesRecur() ) { 508 if ( rec && rec->doesRecur() ) {
503 OPimTimeZone utc = OPimTimeZone::utc(); 509 OPimTimeZone utc = OPimTimeZone::utc();
504 OPimRecurrence recu( *rec ); // call copy c'tor; 510 OPimRecurrence recu( *rec ); // call copy c'tor;
505 recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); 511 recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() );
506 recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); 512 recu.setCreatedDateTime( utc.fromUTCDateTime( created ) );
507 recu.setStart( ev.startDateTime().date() ); 513 recu.setStart( ev.startDateTime().date() );
508 ev.setRecurrence( recu ); 514 ev.setRecurrence( recu );
509 } 515 }
510 516
511 if (alarmTime != -1 ) { 517 if (alarmTime != -1 ) {
512 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); 518 QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 );
513 OPimAlarm al( snd , dt ); 519 OPimAlarm al( snd , dt );
514 ev.notifiers().add( al ); 520 ev.notifiers().add( al );
515 } 521 }
516 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { 522 if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) {
517 qWarning("already contains assign uid"); 523 owarn << "already contains assign uid" << oendl;
518 ev.setUid( 1 ); 524 ev.setUid( 1 );
519 } 525 }
520 qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); 526 owarn << "addind " << ev.uid() << " " << ev.description() << "" << oendl;
521 if ( ev.hasRecurrence() ) 527 if ( ev.hasRecurrence() )
522 m_rep.insert( ev.uid(), ev ); 528 m_rep.insert( ev.uid(), ev );
523 else 529 else
524 m_raw.insert( ev.uid(), ev ); 530 m_raw.insert( ev.uid(), ev );
525 531
526} 532}
527void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) { 533void ODateBookAccessBackend_XML::setField( OPimEvent& e, int id, const QString& value) {
528// qWarning(" setting %s", value.latin1() ); 534// owarn << " setting " << value << "" << oendl;
529 switch( id ) { 535 switch( id ) {
530 case FDescription: 536 case FDescription:
531 e.setDescription( value ); 537 e.setDescription( value );
532 break; 538 break;
533 case FLocation: 539 case FLocation:
534 e.setLocation( value ); 540 e.setLocation( value );
535 break; 541 break;
536 case FCategories: 542 case FCategories:
537 e.setCategories( e.idsFromString( value ) ); 543 e.setCategories( e.idsFromString( value ) );
538 break; 544 break;
539 case FUid: 545 case FUid:
540 e.setUid( value.toInt() ); 546 e.setUid( value.toInt() );
541 break; 547 break;
542 case FType: 548 case FType:
543 if ( value == "AllDay" ) { 549 if ( value == "AllDay" ) {
544 e.setAllDay( true ); 550 e.setAllDay( true );
545 e.setTimeZone( "UTC" ); 551 e.setTimeZone( "UTC" );
546 } 552 }
547 break; 553 break;
548 case FAlarm: 554 case FAlarm:
549 alarmTime = value.toInt(); 555 alarmTime = value.toInt();
550 break; 556 break;
551 case FSound: 557 case FSound:
552 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent; 558 snd = value == "loud" ? OPimAlarm::Loud : OPimAlarm::Silent;
553 break; 559 break;
554 // recurrence stuff 560 // recurrence stuff
555 case FRType: 561 case FRType:
556 if ( value == "Daily" ) 562 if ( value == "Daily" )
557 recur()->setType( OPimRecurrence::Daily ); 563 recur()->setType( OPimRecurrence::Daily );
558 else if ( value == "Weekly" ) 564 else if ( value == "Weekly" )
559 recur()->setType( OPimRecurrence::Weekly); 565 recur()->setType( OPimRecurrence::Weekly);
560 else if ( value == "MonthlyDay" ) 566 else if ( value == "MonthlyDay" )
561 recur()->setType( OPimRecurrence::MonthlyDay ); 567 recur()->setType( OPimRecurrence::MonthlyDay );
562 else if ( value == "MonthlyDate" ) 568 else if ( value == "MonthlyDate" )
563 recur()->setType( OPimRecurrence::MonthlyDate ); 569 recur()->setType( OPimRecurrence::MonthlyDate );
564 else if ( value == "Yearly" ) 570 else if ( value == "Yearly" )
565 recur()->setType( OPimRecurrence::Yearly ); 571 recur()->setType( OPimRecurrence::Yearly );
566 else 572 else
567 recur()->setType( OPimRecurrence::NoRepeat ); 573 recur()->setType( OPimRecurrence::NoRepeat );
568 break; 574 break;
569 case FRWeekdays: 575 case FRWeekdays:
570 recur()->setDays( value.toInt() ); 576 recur()->setDays( value.toInt() );
571 break; 577 break;
572 case FRPosition: 578 case FRPosition:
573 recur()->setPosition( value.toInt() ); 579 recur()->setPosition( value.toInt() );
574 break; 580 break;
575 case FRFreq: 581 case FRFreq:
576 recur()->setFrequency( value.toInt() ); 582 recur()->setFrequency( value.toInt() );
577 break; 583 break;
578 case FRHasEndDate: 584 case FRHasEndDate:
579 recur()->setHasEndDate( value.toInt() ); 585 recur()->setHasEndDate( value.toInt() );
580 break; 586 break;
581 case FREndDate: { 587 case FREndDate: {
582 rp_end = (time_t) value.toLong(); 588 rp_end = (time_t) value.toLong();
583 break; 589 break;
584 } 590 }
585 case FRStart: { 591 case FRStart: {
586 start = (time_t) value.toLong(); 592 start = (time_t) value.toLong();
587 break; 593 break;
588 } 594 }
589 case FREnd: { 595 case FREnd: {
590 end = ( (time_t) value.toLong() ); 596 end = ( (time_t) value.toLong() );
591 break; 597 break;
592 } 598 }
593 case FNote: 599 case FNote:
594 e.setNote( value ); 600 e.setNote( value );
595 break; 601 break;
596 case FCreated: 602 case FCreated:
597 created = value.toInt(); 603 created = value.toInt();
598 break; 604 break;
599 case FRecParent: 605 case FRecParent:
600 e.setParent( value.toInt() ); 606 e.setParent( value.toInt() );
601 break; 607 break;
602 case FRecChildren:{ 608 case FRecChildren:{
603 QStringList list = QStringList::split(' ', value ); 609 QStringList list = QStringList::split(' ', value );
604 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 610 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
605 e.addChild( (*it).toInt() ); 611 e.addChild( (*it).toInt() );
606 } 612 }
607 } 613 }
608 break; 614 break;
609 case FExceptions:{ 615 case FExceptions:{
610 QStringList list = QStringList::split(' ', value ); 616 QStringList list = QStringList::split(' ', value );
611 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 617 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
612 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() ); 618 QDate date( (*it).left(4).toInt(), (*it).mid(4, 2).toInt(), (*it).right(2).toInt() );
613 qWarning("adding exception %s", date.toString().latin1() ); 619 owarn << "adding exception " << date.toString() << "" << oendl;
614 recur()->exceptions().append( date ); 620 recur()->exceptions().append( date );
615 } 621 }
616 } 622 }
617 break; 623 break;
618 case FTimeZone: 624 case FTimeZone:
619 if ( value != "None" ) 625 if ( value != "None" )
620 e.setTimeZone( value ); 626 e.setTimeZone( value );
621 break; 627 break;
622 default: 628 default:
623 break; 629 break;
624 } 630 }
625} 631}
626QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const 632QArray<int> ODateBookAccessBackend_XML::matchRegexp( const QRegExp &r ) const
627{ 633{
628 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() ); 634 QArray<int> m_currentQuery( m_raw.count()+ m_rep.count() );
629 uint arraycounter = 0; 635 uint arraycounter = 0;
630 QMap<int, OPimEvent>::ConstIterator it; 636 QMap<int, OPimEvent>::ConstIterator it;
631 637
632 for ( it = m_raw.begin(); it != m_raw.end(); ++it ) 638 for ( it = m_raw.begin(); it != m_raw.end(); ++it )
633 if ( it.data().match( r ) ) 639 if ( it.data().match( r ) )
634 m_currentQuery[arraycounter++] = it.data().uid(); 640 m_currentQuery[arraycounter++] = it.data().uid();
635 for ( it = m_rep.begin(); it != m_rep.end(); ++it ) 641 for ( it = m_rep.begin(); it != m_rep.end(); ++it )
636 if ( it.data().match( r ) ) 642 if ( it.data().match( r ) )
637 m_currentQuery[arraycounter++] = it.data().uid(); 643 m_currentQuery[arraycounter++] = it.data().uid();
638 644
639 // Shrink to fit.. 645 // Shrink to fit..
640 m_currentQuery.resize(arraycounter); 646 m_currentQuery.resize(arraycounter);
641 647
642 return m_currentQuery; 648 return m_currentQuery;
643} 649}
644 650
645} 651}
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index 132b5a6..6f65c48 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -1,880 +1,884 @@
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) Holger Freyther (zecke@handhelds.org) 4 Copyright (C) Holger Freyther (zecke@handhelds.org)
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 30
31#include <qdatetime.h> 31/* OPIE */
32#include <qmap.h>
33#include <qstring.h>
34
35#include <qpe/global.h>
36
37#include <opie2/osqldriver.h> 32#include <opie2/osqldriver.h>
38#include <opie2/osqlresult.h> 33#include <opie2/osqlresult.h>
39#include <opie2/osqlmanager.h> 34#include <opie2/osqlmanager.h>
40#include <opie2/osqlquery.h> 35#include <opie2/osqlquery.h>
41 36
42#include <opie2/otodoaccesssql.h> 37#include <opie2/otodoaccesssql.h>
43#include <opie2/opimstate.h> 38#include <opie2/opimstate.h>
44#include <opie2/opimnotifymanager.h> 39#include <opie2/opimnotifymanager.h>
45#include <opie2/opimrecurrence.h> 40#include <opie2/opimrecurrence.h>
41#include <opie2/odebug.h>
42
43#include <qpe/global.h>
44
45/* QT */
46#include <qdatetime.h>
47#include <qmap.h>
48#include <qstring.h>
49
46 50
47using namespace Opie::DB; 51using namespace Opie::DB;
48 52
49using namespace Opie; 53using namespace Opie;
50/* 54/*
51 * first some query 55 * first some query
52 * CREATE query 56 * CREATE query
53 * LOAD query 57 * LOAD query
54 * INSERT 58 * INSERT
55 * REMOVE 59 * REMOVE
56 * CLEAR 60 * CLEAR
57 */ 61 */
58namespace { 62namespace {
59 /** 63 /**
60 * CreateQuery for the Todolist Table 64 * CreateQuery for the Todolist Table
61 */ 65 */
62 class CreateQuery : public OSQLQuery { 66 class CreateQuery : public OSQLQuery {
63 public: 67 public:
64 CreateQuery(); 68 CreateQuery();
65 ~CreateQuery(); 69 ~CreateQuery();
66 QString query()const; 70 QString query()const;
67 }; 71 };
68 72
69 /** 73 /**
70 * LoadQuery 74 * LoadQuery
71 * this one queries for all uids 75 * this one queries for all uids
72 */ 76 */
73 class LoadQuery : public OSQLQuery { 77 class LoadQuery : public OSQLQuery {
74 public: 78 public:
75 LoadQuery(); 79 LoadQuery();
76 ~LoadQuery(); 80 ~LoadQuery();
77 QString query()const; 81 QString query()const;
78 }; 82 };
79 83
80 /** 84 /**
81 * inserts/adds a OPimTodo to the table 85 * inserts/adds a OPimTodo to the table
82 */ 86 */
83 class InsertQuery : public OSQLQuery { 87 class InsertQuery : public OSQLQuery {
84 public: 88 public:
85 InsertQuery(const OPimTodo& ); 89 InsertQuery(const OPimTodo& );
86 ~InsertQuery(); 90 ~InsertQuery();
87 QString query()const; 91 QString query()const;
88 private: 92 private:
89 OPimTodo m_todo; 93 OPimTodo m_todo;
90 }; 94 };
91 95
92 /** 96 /**
93 * removes one from the table 97 * removes one from the table
94 */ 98 */
95 class RemoveQuery : public OSQLQuery { 99 class RemoveQuery : public OSQLQuery {
96 public: 100 public:
97 RemoveQuery(int uid ); 101 RemoveQuery(int uid );
98 ~RemoveQuery(); 102 ~RemoveQuery();
99 QString query()const; 103 QString query()const;
100 private: 104 private:
101 int m_uid; 105 int m_uid;
102 }; 106 };
103 107
104 /** 108 /**
105 * Clears (delete) a Table 109 * Clears (delete) a Table
106 */ 110 */
107 class ClearQuery : public OSQLQuery { 111 class ClearQuery : public OSQLQuery {
108 public: 112 public:
109 ClearQuery(); 113 ClearQuery();
110 ~ClearQuery(); 114 ~ClearQuery();
111 QString query()const; 115 QString query()const;
112 116
113 }; 117 };
114 118
115 /** 119 /**
116 * a find query 120 * a find query
117 */ 121 */
118 class FindQuery : public OSQLQuery { 122 class FindQuery : public OSQLQuery {
119 public: 123 public:
120 FindQuery(int uid); 124 FindQuery(int uid);
121 FindQuery(const QArray<int>& ); 125 FindQuery(const QArray<int>& );
122 ~FindQuery(); 126 ~FindQuery();
123 QString query()const; 127 QString query()const;
124 private: 128 private:
125 QString single()const; 129 QString single()const;
126 QString multi()const; 130 QString multi()const;
127 QArray<int> m_uids; 131 QArray<int> m_uids;
128 int m_uid; 132 int m_uid;
129 }; 133 };
130 134
131 /** 135 /**
132 * overdue query 136 * overdue query
133 */ 137 */
134 class OverDueQuery : public OSQLQuery { 138 class OverDueQuery : public OSQLQuery {
135 public: 139 public:
136 OverDueQuery(); 140 OverDueQuery();
137 ~OverDueQuery(); 141 ~OverDueQuery();
138 QString query()const; 142 QString query()const;
139 }; 143 };
140 class EffQuery : public OSQLQuery { 144 class EffQuery : public OSQLQuery {
141 public: 145 public:
142 EffQuery( const QDate&, const QDate&, bool inc ); 146 EffQuery( const QDate&, const QDate&, bool inc );
143 ~EffQuery(); 147 ~EffQuery();
144 QString query()const; 148 QString query()const;
145 private: 149 private:
146 QString with()const; 150 QString with()const;
147 QString out()const; 151 QString out()const;
148 QDate m_start; 152 QDate m_start;
149 QDate m_end; 153 QDate m_end;
150 bool m_inc :1; 154 bool m_inc :1;
151 }; 155 };
152 156
153 157
154 /** 158 /**
155 * a find query for custom elements 159 * a find query for custom elements
156 */ 160 */
157 class FindCustomQuery : public OSQLQuery { 161 class FindCustomQuery : public OSQLQuery {
158 public: 162 public:
159 FindCustomQuery(int uid); 163 FindCustomQuery(int uid);
160 FindCustomQuery(const QArray<int>& ); 164 FindCustomQuery(const QArray<int>& );
161 ~FindCustomQuery(); 165 ~FindCustomQuery();
162 QString query()const; 166 QString query()const;
163 private: 167 private:
164 QString single()const; 168 QString single()const;
165 QString multi()const; 169 QString multi()const;
166 QArray<int> m_uids; 170 QArray<int> m_uids;
167 int m_uid; 171 int m_uid;
168 }; 172 };
169 173
170 174
171 175
172 CreateQuery::CreateQuery() : OSQLQuery() {} 176 CreateQuery::CreateQuery() : OSQLQuery() {}
173 CreateQuery::~CreateQuery() {} 177 CreateQuery::~CreateQuery() {}
174 QString CreateQuery::query()const { 178 QString CreateQuery::query()const {
175 QString qu; 179 QString qu;
176 qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; 180 qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
177 qu += "description, summary, priority, DueDate, progress , state, "; 181 qu += "description, summary, priority, DueDate, progress , state, ";
178 // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) 182 // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers)
179 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; 183 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
180 qu += "reminders, alarms, maintainer, startdate, completeddate);"; 184 qu += "reminders, alarms, maintainer, startdate, completeddate);";
181 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 185 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
182 return qu; 186 return qu;
183 } 187 }
184 188
185 LoadQuery::LoadQuery() : OSQLQuery() {} 189 LoadQuery::LoadQuery() : OSQLQuery() {}
186 LoadQuery::~LoadQuery() {} 190 LoadQuery::~LoadQuery() {}
187 QString LoadQuery::query()const { 191 QString LoadQuery::query()const {
188 QString qu; 192 QString qu;
189 // We do not need "distinct" here. The primary key is always unique.. 193 // We do not need "distinct" here. The primary key is always unique..
190 //qu += "select distinct uid from todolist"; 194 //qu += "select distinct uid from todolist";
191 qu += "select uid from todolist"; 195 qu += "select uid from todolist";
192 196
193 return qu; 197 return qu;
194 } 198 }
195 199
196 InsertQuery::InsertQuery( const OPimTodo& todo ) 200 InsertQuery::InsertQuery( const OPimTodo& todo )
197 : OSQLQuery(), m_todo( todo ) { 201 : OSQLQuery(), m_todo( todo ) {
198 } 202 }
199 InsertQuery::~InsertQuery() { 203 InsertQuery::~InsertQuery() {
200 } 204 }
201 /* 205 /*
202 * converts from a OPimTodo to a query 206 * converts from a OPimTodo to a query
203 * we leave out X-Ref + Maintainer 207 * we leave out X-Ref + Maintainer
204 * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding 208 * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding
205 * decoding stuff there.. (eilers) 209 * decoding stuff there.. (eilers)
206 */ 210 */
207 QString InsertQuery::query()const{ 211 QString InsertQuery::query()const{
208 212
209 int year, month, day; 213 int year, month, day;
210 year = month = day = 0; 214 year = month = day = 0;
211 if (m_todo.hasDueDate() ) { 215 if (m_todo.hasDueDate() ) {
212 QDate date = m_todo.dueDate(); 216 QDate date = m_todo.dueDate();
213 year = date.year(); 217 year = date.year();
214 month = date.month(); 218 month = date.month();
215 day = date.day(); 219 day = date.day();
216 } 220 }
217 int sYear = 0, sMonth = 0, sDay = 0; 221 int sYear = 0, sMonth = 0, sDay = 0;
218 if( m_todo.hasStartDate() ){ 222 if( m_todo.hasStartDate() ){
219 QDate sDate = m_todo.startDate(); 223 QDate sDate = m_todo.startDate();
220 sYear = sDate.year(); 224 sYear = sDate.year();
221 sMonth= sDate.month(); 225 sMonth= sDate.month();
222 sDay = sDate.day(); 226 sDay = sDate.day();
223 } 227 }
224 228
225 int eYear = 0, eMonth = 0, eDay = 0; 229 int eYear = 0, eMonth = 0, eDay = 0;
226 if( m_todo.hasCompletedDate() ){ 230 if( m_todo.hasCompletedDate() ){
227 QDate eDate = m_todo.completedDate(); 231 QDate eDate = m_todo.completedDate();
228 eYear = eDate.year(); 232 eYear = eDate.year();
229 eMonth= eDate.month(); 233 eMonth= eDate.month();
230 eDay = eDate.day(); 234 eDay = eDate.day();
231 } 235 }
232 QString qu; 236 QString qu;
233 QMap<int, QString> recMap = m_todo.recurrence().toMap(); 237 QMap<int, QString> recMap = m_todo.recurrence().toMap();
234 qu = "insert into todolist VALUES(" 238 qu = "insert into todolist VALUES("
235 + QString::number( m_todo.uid() ) + "," 239 + QString::number( m_todo.uid() ) + ","
236 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," 240 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
237 + QString::number( m_todo.isCompleted() ) + "," 241 + QString::number( m_todo.isCompleted() ) + ","
238 + "'" + m_todo.description() + "'" + "," 242 + "'" + m_todo.description() + "'" + ","
239 + "'" + m_todo.summary() + "'" + "," 243 + "'" + m_todo.summary() + "'" + ","
240 + QString::number(m_todo.priority() ) + "," 244 + QString::number(m_todo.priority() ) + ","
241 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" 245 + "'" + QString::number(year).rightJustify( 4, '0' ) + "-"
242 + QString::number(month).rightJustify( 2, '0' ) 246 + QString::number(month).rightJustify( 2, '0' )
243 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," 247 + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + ","
244 + QString::number( m_todo.progress() ) + "," 248 + QString::number( m_todo.progress() ) + ","
245 + QString::number( m_todo.state().state() ) + "," 249 + QString::number( m_todo.state().state() ) + ","
246 + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," 250 + "'" + recMap[ OPimRecurrence::RType ] + "'" + ","
247 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," 251 + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + ","
248 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," 252 + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + ","
249 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," 253 + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + ","
250 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," 254 + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + ","
251 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," 255 + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + ","
252 + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," 256 + "'" + recMap[ OPimRecurrence::Created ] + "'" + ","
253 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; 257 + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ",";
254 258
255 if ( m_todo.hasNotifiers() ) { 259 if ( m_todo.hasNotifiers() ) {
256 OPimNotifyManager manager = m_todo.notifiers(); 260 OPimNotifyManager manager = m_todo.notifiers();
257 qu += "'" + manager.remindersToString() + "'" + "," 261 qu += "'" + manager.remindersToString() + "'" + ","
258 + "'" + manager.alarmsToString() + "'" + ","; 262 + "'" + manager.alarmsToString() + "'" + ",";
259 } 263 }
260 else{ 264 else{
261 qu += QString( "''" ) + "," 265 qu += QString( "''" ) + ","
262 + "''" + ","; 266 + "''" + ",";
263 } 267 }
264 268
265 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 269 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
266 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" 270 + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
267 + QString::number(sMonth).rightJustify( 2, '0' ) 271 + QString::number(sMonth).rightJustify( 2, '0' )
268 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," 272 + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + ","
269 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" 273 + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-"
270 + QString::number(eMonth).rightJustify( 2, '0' ) 274 + QString::number(eMonth).rightJustify( 2, '0' )
271 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" 275 + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'"
272 + "); "; 276 + "); ";
273 277
274 // Save custom Entries: 278 // Save custom Entries:
275 int id = 0; 279 int id = 0;
276 id = 0; 280 id = 0;
277 QMap<QString, QString> customMap = m_todo.toExtraMap(); 281 QMap<QString, QString> customMap = m_todo.toExtraMap();
278 for( QMap<QString, QString>::Iterator it = customMap.begin(); 282 for( QMap<QString, QString>::Iterator it = customMap.begin();
279 it != customMap.end(); ++it ){ 283 it != customMap.end(); ++it ){
280 qu += "insert into custom_data VALUES(" 284 qu += "insert into custom_data VALUES("
281 + QString::number( m_todo.uid() ) 285 + QString::number( m_todo.uid() )
282 + "," 286 + ","
283 + QString::number( id++ ) 287 + QString::number( id++ )
284 + ",'" 288 + ",'"
285 + it.key() 289 + it.key()
286 + "'," 290 + "',"
287 + "0" // Priority for future enhancements 291 + "0" // Priority for future enhancements
288 + ",'" 292 + ",'"
289 + it.data() 293 + it.data()
290 + "');"; 294 + "');";
291 } 295 }
292 296
293 297
294 qDebug("add %s", qu.latin1() ); 298 odebug << "add " << qu << "" << oendl;
295 return qu; 299 return qu;
296 } 300 }
297 301
298 RemoveQuery::RemoveQuery(int uid ) 302 RemoveQuery::RemoveQuery(int uid )
299 : OSQLQuery(), m_uid( uid ) {} 303 : OSQLQuery(), m_uid( uid ) {}
300 RemoveQuery::~RemoveQuery() {} 304 RemoveQuery::~RemoveQuery() {}
301 QString RemoveQuery::query()const { 305 QString RemoveQuery::query()const {
302 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;"; 306 QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
303 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid); 307 qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
304 return qu; 308 return qu;
305 } 309 }
306 310
307 311
308 ClearQuery::ClearQuery() 312 ClearQuery::ClearQuery()
309 : OSQLQuery() {} 313 : OSQLQuery() {}
310 ClearQuery::~ClearQuery() {} 314 ClearQuery::~ClearQuery() {}
311 QString ClearQuery::query()const { 315 QString ClearQuery::query()const {
312 QString qu = "drop table todolist"; 316 QString qu = "drop table todolist";
313 return qu; 317 return qu;
314 } 318 }
315 FindQuery::FindQuery(int uid) 319 FindQuery::FindQuery(int uid)
316 : OSQLQuery(), m_uid(uid ) { 320 : OSQLQuery(), m_uid(uid ) {
317 } 321 }
318 FindQuery::FindQuery(const QArray<int>& ints) 322 FindQuery::FindQuery(const QArray<int>& ints)
319 : OSQLQuery(), m_uids(ints){ 323 : OSQLQuery(), m_uids(ints){
320 } 324 }
321 FindQuery::~FindQuery() { 325 FindQuery::~FindQuery() {
322 } 326 }
323 QString FindQuery::query()const{ 327 QString FindQuery::query()const{
324 if (m_uids.count() == 0 ) 328 if (m_uids.count() == 0 )
325 return single(); 329 return single();
326 else 330 else
327 return multi(); 331 return multi();
328 } 332 }
329 QString FindQuery::single()const{ 333 QString FindQuery::single()const{
330 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 334 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
331 return qu; 335 return qu;
332 } 336 }
333 QString FindQuery::multi()const { 337 QString FindQuery::multi()const {
334 QString qu = "select * from todolist where "; 338 QString qu = "select * from todolist where ";
335 for (uint i = 0; i < m_uids.count(); i++ ) { 339 for (uint i = 0; i < m_uids.count(); i++ ) {
336 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 340 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
337 } 341 }
338 qu.remove( qu.length()-2, 2 ); 342 qu.remove( qu.length()-2, 2 );
339 return qu; 343 return qu;
340 } 344 }
341 345
342 OverDueQuery::OverDueQuery(): OSQLQuery() {} 346 OverDueQuery::OverDueQuery(): OSQLQuery() {}
343 OverDueQuery::~OverDueQuery() {} 347 OverDueQuery::~OverDueQuery() {}
344 QString OverDueQuery::query()const { 348 QString OverDueQuery::query()const {
345 QDate date = QDate::currentDate(); 349 QDate date = QDate::currentDate();
346 QString str; 350 QString str;
347 str = QString("select uid from todolist where DueDate ='%1-%2-%3'") 351 str = QString("select uid from todolist where DueDate ='%1-%2-%3'")
348 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 352 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
349 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 353 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
350 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); 354 .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) );
351 355
352 return str; 356 return str;
353 } 357 }
354 358
355 359
356 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 360 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
357 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 361 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
358 EffQuery::~EffQuery() {} 362 EffQuery::~EffQuery() {}
359 QString EffQuery::query()const { 363 QString EffQuery::query()const {
360 return m_inc ? with() : out(); 364 return m_inc ? with() : out();
361 } 365 }
362 QString EffQuery::with()const { 366 QString EffQuery::with()const {
363 QString str; 367 QString str;
364 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 368 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
365 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 369 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
366 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 370 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
367 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 371 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
368 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) 372 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
369 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) 373 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
370 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); 374 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
371 return str; 375 return str;
372 } 376 }
373 QString EffQuery::out()const { 377 QString EffQuery::out()const {
374 QString str; 378 QString str;
375 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 379 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
376 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) 380 .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
377 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) 381 .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
378 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) 382 .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
379 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) 383 .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
380 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) 384 .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
381 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); 385 .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
382 386
383 return str; 387 return str;
384 } 388 }
385 389
386 FindCustomQuery::FindCustomQuery(int uid) 390 FindCustomQuery::FindCustomQuery(int uid)
387 : OSQLQuery(), m_uid( uid ) { 391 : OSQLQuery(), m_uid( uid ) {
388 } 392 }
389 FindCustomQuery::FindCustomQuery(const QArray<int>& ints) 393 FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
390 : OSQLQuery(), m_uids( ints ){ 394 : OSQLQuery(), m_uids( ints ){
391 } 395 }
392 FindCustomQuery::~FindCustomQuery() { 396 FindCustomQuery::~FindCustomQuery() {
393 } 397 }
394 QString FindCustomQuery::query()const{ 398 QString FindCustomQuery::query()const{
395 return single(); // Multiple requests not supported ! 399 return single(); // Multiple requests not supported !
396 } 400 }
397 QString FindCustomQuery::single()const{ 401 QString FindCustomQuery::single()const{
398 QString qu = "select uid, type, value from custom_data where uid = "; 402 QString qu = "select uid, type, value from custom_data where uid = ";
399 qu += QString::number(m_uid); 403 qu += QString::number(m_uid);
400 return qu; 404 return qu;
401 } 405 }
402 406
403}; 407};
404 408
405 409
406namespace Opie { 410namespace Opie {
407OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) 411OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file )
408 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) 412 : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true)
409{ 413{
410 QString fi = file; 414 QString fi = file;
411 if ( fi.isEmpty() ) 415 if ( fi.isEmpty() )
412 fi = Global::applicationFileName( "todolist", "todolist.db" ); 416 fi = Global::applicationFileName( "todolist", "todolist.db" );
413 OSQLManager man; 417 OSQLManager man;
414 m_driver = man.standard(); 418 m_driver = man.standard();
415 m_driver->setUrl(fi); 419 m_driver->setUrl(fi);
416 // fillDict(); 420 // fillDict();
417} 421}
418 422
419OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ 423OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){
420 if( m_driver ) 424 if( m_driver )
421 delete m_driver; 425 delete m_driver;
422} 426}
423 427
424bool OPimTodoAccessBackendSQL::load(){ 428bool OPimTodoAccessBackendSQL::load(){
425 if (!m_driver->open() ) 429 if (!m_driver->open() )
426 return false; 430 return false;
427 431
428 CreateQuery creat; 432 CreateQuery creat;
429 OSQLResult res = m_driver->query(&creat ); 433 OSQLResult res = m_driver->query(&creat );
430 434
431 m_dirty = true; 435 m_dirty = true;
432 return true; 436 return true;
433} 437}
434bool OPimTodoAccessBackendSQL::reload(){ 438bool OPimTodoAccessBackendSQL::reload(){
435 return load(); 439 return load();
436} 440}
437 441
438bool OPimTodoAccessBackendSQL::save(){ 442bool OPimTodoAccessBackendSQL::save(){
439 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) 443 return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers)
440} 444}
441QArray<int> OPimTodoAccessBackendSQL::allRecords()const { 445QArray<int> OPimTodoAccessBackendSQL::allRecords()const {
442 if (m_dirty ) 446 if (m_dirty )
443 update(); 447 update();
444 448
445 return m_uids; 449 return m_uids;
446} 450}
447QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ 451QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){
448 QArray<int> ints(0); 452 QArray<int> ints(0);
449 return ints; 453 return ints;
450} 454}
451OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ 455OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{
452 FindQuery query( uid ); 456 FindQuery query( uid );
453 return todo( m_driver->query(&query) ); 457 return todo( m_driver->query(&query) );
454 458
455} 459}
456OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 460OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
457 uint cur, Frontend::CacheDirection dir ) const{ 461 uint cur, Frontend::CacheDirection dir ) const{
458 uint CACHE = readAhead(); 462 uint CACHE = readAhead();
459 qDebug("searching for %d", uid ); 463 odebug << "searching for " << uid << "" << oendl;
460 QArray<int> search( CACHE ); 464 QArray<int> search( CACHE );
461 uint size =0; 465 uint size =0;
462 OPimTodo to; 466 OPimTodo to;
463 467
464 // we try to cache CACHE items 468 // we try to cache CACHE items
465 switch( dir ) { 469 switch( dir ) {
466 /* forward */ 470 /* forward */
467 case 0: // FIXME: Not a good style to use magic numbers here (eilers) 471 case 0: // FIXME: Not a good style to use magic numbers here (eilers)
468 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 472 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
469 qDebug("size %d %d", size, ints[i] ); 473 odebug << "size " << size << " " << ints[i] << "" << oendl;
470 search[size] = ints[i]; 474 search[size] = ints[i];
471 size++; 475 size++;
472 } 476 }
473 break; 477 break;
474 /* reverse */ 478 /* reverse */
475 case 1: // FIXME: Not a good style to use magic numbers here (eilers) 479 case 1: // FIXME: Not a good style to use magic numbers here (eilers)
476 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 480 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
477 search[size] = ints[i]; 481 search[size] = ints[i];
478 size++; 482 size++;
479 } 483 }
480 break; 484 break;
481 } 485 }
482 search.resize( size ); 486 search.resize( size );
483 FindQuery query( search ); 487 FindQuery query( search );
484 OSQLResult res = m_driver->query( &query ); 488 OSQLResult res = m_driver->query( &query );
485 if ( res.state() != OSQLResult::Success ) 489 if ( res.state() != OSQLResult::Success )
486 return to; 490 return to;
487 491
488 return todo( res ); 492 return todo( res );
489} 493}
490void OPimTodoAccessBackendSQL::clear() { 494void OPimTodoAccessBackendSQL::clear() {
491 ClearQuery cle; 495 ClearQuery cle;
492 OSQLResult res = m_driver->query( &cle ); 496 OSQLResult res = m_driver->query( &cle );
493 CreateQuery qu; 497 CreateQuery qu;
494 res = m_driver->query(&qu); 498 res = m_driver->query(&qu);
495} 499}
496bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { 500bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) {
497 InsertQuery ins( t ); 501 InsertQuery ins( t );
498 OSQLResult res = m_driver->query( &ins ); 502 OSQLResult res = m_driver->query( &ins );
499 503
500 if ( res.state() == OSQLResult::Failure ) 504 if ( res.state() == OSQLResult::Failure )
501 return false; 505 return false;
502 int c = m_uids.count(); 506 int c = m_uids.count();
503 m_uids.resize( c+1 ); 507 m_uids.resize( c+1 );
504 m_uids[c] = t.uid(); 508 m_uids[c] = t.uid();
505 509
506 return true; 510 return true;
507} 511}
508bool OPimTodoAccessBackendSQL::remove( int uid ) { 512bool OPimTodoAccessBackendSQL::remove( int uid ) {
509 RemoveQuery rem( uid ); 513 RemoveQuery rem( uid );
510 OSQLResult res = m_driver->query(&rem ); 514 OSQLResult res = m_driver->query(&rem );
511 515
512 if ( res.state() == OSQLResult::Failure ) 516 if ( res.state() == OSQLResult::Failure )
513 return false; 517 return false;
514 518
515 m_dirty = true; 519 m_dirty = true;
516 return true; 520 return true;
517} 521}
518/* 522/*
519 * FIXME better set query 523 * FIXME better set query
520 * but we need the cache for that 524 * but we need the cache for that
521 * now we remove 525 * now we remove
522 */ 526 */
523bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { 527bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) {
524 remove( t.uid() ); 528 remove( t.uid() );
525 bool b= add(t); 529 bool b= add(t);
526 m_dirty = false; // we changed some stuff but the UID stayed the same 530 m_dirty = false; // we changed some stuff but the UID stayed the same
527 return b; 531 return b;
528} 532}
529QArray<int> OPimTodoAccessBackendSQL::overDue() { 533QArray<int> OPimTodoAccessBackendSQL::overDue() {
530 OverDueQuery qu; 534 OverDueQuery qu;
531 return uids( m_driver->query(&qu ) ); 535 return uids( m_driver->query(&qu ) );
532} 536}
533QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, 537QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
534 const QDate& t, 538 const QDate& t,
535 bool u) { 539 bool u) {
536 EffQuery ef(s, t, u ); 540 EffQuery ef(s, t, u );
537 return uids (m_driver->query(&ef) ); 541 return uids (m_driver->query(&ef) );
538} 542}
539/* 543/*
540 * 544 *
541 */ 545 */
542QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 546QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
543 int sortFilter, int cat ) { 547 int sortFilter, int cat ) {
544 qDebug("sorted %d, %d", asc, sortOrder ); 548 odebug << "sorted " << asc << ", " << sortOrder << "" << oendl;
545 QString query; 549 QString query;
546 query = "select uid from todolist WHERE "; 550 query = "select uid from todolist WHERE ";
547 551
548 /* 552 /*
549 * Sort Filter stuff 553 * Sort Filter stuff
550 * not that straight forward 554 * not that straight forward
551 * FIXME: Replace magic numbers 555 * FIXME: Replace magic numbers
552 * 556 *
553 */ 557 */
554 /* Category */ 558 /* Category */
555 if ( sortFilter & 1 ) { 559 if ( sortFilter & 1 ) {
556 QString str; 560 QString str;
557 if (cat != 0 ) str = QString::number( cat ); 561 if (cat != 0 ) str = QString::number( cat );
558 query += " categories like '%" +str+"%' AND"; 562 query += " categories like '%" +str+"%' AND";
559 } 563 }
560 /* Show only overdue */ 564 /* Show only overdue */
561 if ( sortFilter & 2 ) { 565 if ( sortFilter & 2 ) {
562 QDate date = QDate::currentDate(); 566 QDate date = QDate::currentDate();
563 QString due; 567 QString due;
564 QString base; 568 QString base;
565 base = QString("DueDate <= '%1-%2-%3' AND completed = 0") 569 base = QString("DueDate <= '%1-%2-%3' AND completed = 0")
566 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) 570 .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
567 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) 571 .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
568 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); 572 .arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
569 query += " " + base + " AND"; 573 query += " " + base + " AND";
570 } 574 }
571 /* not show completed */ 575 /* not show completed */
572 if ( sortFilter & 4 ) { 576 if ( sortFilter & 4 ) {
573 query += " completed = 0 AND"; 577 query += " completed = 0 AND";
574 }else{ 578 }else{
575 query += " ( completed = 1 OR completed = 0) AND"; 579 query += " ( completed = 1 OR completed = 0) AND";
576 } 580 }
577 /* strip the end */ 581 /* strip the end */
578 query = query.remove( query.length()-3, 3 ); 582 query = query.remove( query.length()-3, 3 );
579 583
580 584
581 /* 585 /*
582 * sort order stuff 586 * sort order stuff
583 * quite straight forward 587 * quite straight forward
584 */ 588 */
585 query += "ORDER BY "; 589 query += "ORDER BY ";
586 switch( sortOrder ) { 590 switch( sortOrder ) {
587 /* completed */ 591 /* completed */
588 case 0: 592 case 0:
589 query += "completed"; 593 query += "completed";
590 break; 594 break;
591 case 1: 595 case 1:
592 query += "priority"; 596 query += "priority";
593 break; 597 break;
594 case 2: 598 case 2:
595 query += "summary"; 599 query += "summary";
596 break; 600 break;
597 case 3: 601 case 3:
598 query += "DueDate"; 602 query += "DueDate";
599 break; 603 break;
600 } 604 }
601 605
602 if ( !asc ) { 606 if ( !asc ) {
603 qDebug("not ascending!"); 607 odebug << "not ascending!" << oendl;
604 query += " DESC"; 608 query += " DESC";
605 } 609 }
606 610
607 qDebug( query ); 611 odebug << query << oendl;
608 OSQLRawQuery raw(query ); 612 OSQLRawQuery raw(query );
609 return uids( m_driver->query(&raw) ); 613 return uids( m_driver->query(&raw) );
610} 614}
611bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 615bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
612 if ( str == "0-0-0" ) 616 if ( str == "0-0-0" )
613 return false; 617 return false;
614 else{ 618 else{
615 int day, year, month; 619 int day, year, month;
616 QStringList list = QStringList::split("-", str ); 620 QStringList list = QStringList::split("-", str );
617 year = list[0].toInt(); 621 year = list[0].toInt();
618 month = list[1].toInt(); 622 month = list[1].toInt();
619 day = list[2].toInt(); 623 day = list[2].toInt();
620 da.setYMD( year, month, day ); 624 da.setYMD( year, month, day );
621 return true; 625 return true;
622 } 626 }
623} 627}
624OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ 628OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{
625 if ( res.state() == OSQLResult::Failure ) { 629 if ( res.state() == OSQLResult::Failure ) {
626 OPimTodo to; 630 OPimTodo to;
627 return to; 631 return to;
628 } 632 }
629 633
630 OSQLResultItem::ValueList list = res.results(); 634 OSQLResultItem::ValueList list = res.results();
631 OSQLResultItem::ValueList::Iterator it = list.begin(); 635 OSQLResultItem::ValueList::Iterator it = list.begin();
632 qDebug("todo1"); 636 odebug << "todo1" << oendl;
633 OPimTodo to = todo( (*it) ); 637 OPimTodo to = todo( (*it) );
634 cache( to ); 638 cache( to );
635 ++it; 639 ++it;
636 640
637 for ( ; it != list.end(); ++it ) { 641 for ( ; it != list.end(); ++it ) {
638 qDebug("caching"); 642 odebug << "caching" << oendl;
639 cache( todo( (*it) ) ); 643 cache( todo( (*it) ) );
640 } 644 }
641 return to; 645 return to;
642} 646}
643OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 647OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
644 qDebug("todo(ResultItem)"); 648 odebug << "todo(ResultItem)" << oendl;
645 649
646 // Request information from addressbook table and create the OPimTodo-object. 650 // Request information from addressbook table and create the OPimTodo-object.
647 651
648 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 652 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
649 hasDueDate = date( dueDate, item.data("DueDate") ); 653 hasDueDate = date( dueDate, item.data("DueDate") );
650 QStringList cats = QStringList::split(";", item.data("categories") ); 654 QStringList cats = QStringList::split(";", item.data("categories") );
651 655
652 qDebug("Item is completed: %d", item.data("completed").toInt() ); 656 odebug << "Item is completed: " << item.data("completed").toInt() << "" << oendl;
653 657
654 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 658 OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
655 cats, item.data("summary"), item.data("description"), 659 cats, item.data("summary"), item.data("description"),
656 item.data("progress").toUShort(), hasDueDate, dueDate, 660 item.data("progress").toUShort(), hasDueDate, dueDate,
657 item.data("uid").toInt() ); 661 item.data("uid").toInt() );
658 662
659 bool isOk; 663 bool isOk;
660 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 664 int prioInt = QString( item.data("priority") ).toInt( &isOk );
661 if ( isOk ) 665 if ( isOk )
662 to.setPriority( prioInt ); 666 to.setPriority( prioInt );
663 667
664 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 668 bool hasStartDate = false; QDate startDate = QDate::currentDate();
665 hasStartDate = date( startDate, item.data("startdate") ); 669 hasStartDate = date( startDate, item.data("startdate") );
666 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); 670 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
667 hasCompletedDate = date( completedDate, item.data("completeddate") ); 671 hasCompletedDate = date( completedDate, item.data("completeddate") );
668 672
669 if ( hasStartDate ) 673 if ( hasStartDate )
670 to.setStartDate( startDate ); 674 to.setStartDate( startDate );
671 if ( hasCompletedDate ) 675 if ( hasCompletedDate )
672 to.setCompletedDate( completedDate ); 676 to.setCompletedDate( completedDate );
673 677
674 OPimNotifyManager& manager = to.notifiers(); 678 OPimNotifyManager& manager = to.notifiers();
675 manager.alarmsFromString( item.data("alarms") ); 679 manager.alarmsFromString( item.data("alarms") );
676 manager.remindersFromString( item.data("reminders") ); 680 manager.remindersFromString( item.data("reminders") );
677 681
678 OPimState pimState; 682 OPimState pimState;
679 pimState.setState( QString( item.data("state") ).toInt() ); 683 pimState.setState( QString( item.data("state") ).toInt() );
680 to.setState( pimState ); 684 to.setState( pimState );
681 685
682 QMap<int, QString> recMap; 686 QMap<int, QString> recMap;
683 recMap.insert( OPimRecurrence::RType , item.data("RType") ); 687 recMap.insert( OPimRecurrence::RType , item.data("RType") );
684 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); 688 recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") );
685 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); 689 recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") );
686 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); 690 recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") );
687 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); 691 recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") );
688 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); 692 recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") );
689 recMap.insert( OPimRecurrence::Created , item.data("Created") ); 693 recMap.insert( OPimRecurrence::Created , item.data("Created") );
690 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); 694 recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") );
691 695
692 OPimRecurrence recur; 696 OPimRecurrence recur;
693 recur.fromMap( recMap ); 697 recur.fromMap( recMap );
694 to.setRecurrence( recur ); 698 to.setRecurrence( recur );
695 699
696 // Finally load the custom-entries for this UID and put it into the created object 700 // Finally load the custom-entries for this UID and put it into the created object
697 to.setExtraMap( requestCustom( to.uid() ) ); 701 to.setExtraMap( requestCustom( to.uid() ) );
698 702
699 return to; 703 return to;
700} 704}
701OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { 705OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
702 FindQuery find( uid ); 706 FindQuery find( uid );
703 return todo( m_driver->query(&find) ); 707 return todo( m_driver->query(&find) );
704} 708}
705/* 709/*
706 * update the dict 710 * update the dict
707 */ 711 */
708void OPimTodoAccessBackendSQL::fillDict() { 712void OPimTodoAccessBackendSQL::fillDict() {
709 713
710#if 0 714#if 0
711 /* initialize dict */ 715 /* initialize dict */
712 /* 716 /*
713 * UPDATE dict if you change anything!!! 717 * UPDATE dict if you change anything!!!
714 * FIXME: Isn't this dict obsolete ? (eilers) 718 * FIXME: Isn't this dict obsolete ? (eilers)
715 */ 719 */
716 m_dict.setAutoDelete( TRUE ); 720 m_dict.setAutoDelete( TRUE );
717 m_dict.insert("Categories" , new int(OPimTodo::Category) ); 721 m_dict.insert("Categories" , new int(OPimTodo::Category) );
718 m_dict.insert("Uid" , new int(OPimTodo::Uid) ); 722 m_dict.insert("Uid" , new int(OPimTodo::Uid) );
719 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); 723 m_dict.insert("HasDate" , new int(OPimTodo::HasDate) );
720 m_dict.insert("Completed" , new int(OPimTodo::Completed) ); 724 m_dict.insert("Completed" , new int(OPimTodo::Completed) );
721 m_dict.insert("Description" , new int(OPimTodo::Description) ); 725 m_dict.insert("Description" , new int(OPimTodo::Description) );
722 m_dict.insert("Summary" , new int(OPimTodo::Summary) ); 726 m_dict.insert("Summary" , new int(OPimTodo::Summary) );
723 m_dict.insert("Priority" , new int(OPimTodo::Priority) ); 727 m_dict.insert("Priority" , new int(OPimTodo::Priority) );
724 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); 728 m_dict.insert("DateDay" , new int(OPimTodo::DateDay) );
725 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); 729 m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
726 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); 730 m_dict.insert("DateYear" , new int(OPimTodo::DateYear) );
727 m_dict.insert("Progress" , new int(OPimTodo::Progress) ); 731 m_dict.insert("Progress" , new int(OPimTodo::Progress) );
728 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) 732 m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers)
729 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); 733 m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
730// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) 734// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
731// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) 735// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
732 736
733#endif 737#endif
734} 738}
735/* 739/*
736 * need to be const so let's fool the 740 * need to be const so let's fool the
737 * compiler :( 741 * compiler :(
738 */ 742 */
739void OPimTodoAccessBackendSQL::update()const { 743void OPimTodoAccessBackendSQL::update()const {
740 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; 744 ((OPimTodoAccessBackendSQL*)this)->m_dirty = false;
741 LoadQuery lo; 745 LoadQuery lo;
742 OSQLResult res = m_driver->query(&lo); 746 OSQLResult res = m_driver->query(&lo);
743 if ( res.state() != OSQLResult::Success ) 747 if ( res.state() != OSQLResult::Success )
744 return; 748 return;
745 749
746 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); 750 ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res );
747} 751}
748QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 752QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
749 753
750 OSQLResultItem::ValueList list = res.results(); 754 OSQLResultItem::ValueList list = res.results();
751 OSQLResultItem::ValueList::Iterator it; 755 OSQLResultItem::ValueList::Iterator it;
752 QArray<int> ints(list.count() ); 756 QArray<int> ints(list.count() );
753 qDebug(" count = %d", list.count() ); 757 odebug << " count = " << list.count() << "" << oendl;
754 758
755 int i = 0; 759 int i = 0;
756 for (it = list.begin(); it != list.end(); ++it ) { 760 for (it = list.begin(); it != list.end(); ++it ) {
757 ints[i] = (*it).data("uid").toInt(); 761 ints[i] = (*it).data("uid").toInt();
758 i++; 762 i++;
759 } 763 }
760 return ints; 764 return ints;
761} 765}
762 766
763QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 767QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
764{ 768{
765 769
766#if 0 770#if 0
767 QArray<int> empty; 771 QArray<int> empty;
768 return empty; 772 return empty;
769 773
770#else 774#else
771 QString qu = "SELECT uid FROM todolist WHERE ("; 775 QString qu = "SELECT uid FROM todolist WHERE (";
772 776
773 // Do it make sense to search other fields, too ? 777 // Do it make sense to search other fields, too ?
774 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR"; 778 qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
775 qu += " rlike(\""+ r.pattern() + "\",\"summary\")"; 779 qu += " rlike(\""+ r.pattern() + "\",\"summary\")";
776 780
777 qu += ")"; 781 qu += ")";
778 782
779 qDebug( "query: %s", qu.latin1() ); 783 odebug << "query: " << qu << "" << oendl;
780 784
781 OSQLRawQuery raw( qu ); 785 OSQLRawQuery raw( qu );
782 OSQLResult res = m_driver->query( &raw ); 786 OSQLResult res = m_driver->query( &raw );
783 787
784 return uids( res ); 788 return uids( res );
785 789
786 790
787#endif 791#endif
788 792
789} 793}
790QBitArray OPimTodoAccessBackendSQL::supports()const { 794QBitArray OPimTodoAccessBackendSQL::supports()const {
791 795
792 return sup(); 796 return sup();
793} 797}
794 798
795QBitArray OPimTodoAccessBackendSQL::sup() const{ 799QBitArray OPimTodoAccessBackendSQL::sup() const{
796 800
797 QBitArray ar( OPimTodo::CompletedDate + 1 ); 801 QBitArray ar( OPimTodo::CompletedDate + 1 );
798 ar.fill( true ); 802 ar.fill( true );
799 ar[OPimTodo::CrossReference] = false; 803 ar[OPimTodo::CrossReference] = false;
800 ar[OPimTodo::State ] = false; 804 ar[OPimTodo::State ] = false;
801 ar[OPimTodo::Reminders] = false; 805 ar[OPimTodo::Reminders] = false;
802 ar[OPimTodo::Notifiers] = false; 806 ar[OPimTodo::Notifiers] = false;
803 ar[OPimTodo::Maintainer] = false; 807 ar[OPimTodo::Maintainer] = false;
804 808
805 return ar; 809 return ar;
806} 810}
807 811
808void OPimTodoAccessBackendSQL::removeAllCompleted(){ 812void OPimTodoAccessBackendSQL::removeAllCompleted(){
809 // First we need the uids from all entries which are 813 // First we need the uids from all entries which are
810 // completed. Then, we just have to remove them... 814 // completed. Then, we just have to remove them...
811 815
812 QString qu = "SELECT uid FROM todolist WHERE completed = 1"; 816 QString qu = "SELECT uid FROM todolist WHERE completed = 1";
813 817
814 OSQLRawQuery raw( qu ); 818 OSQLRawQuery raw( qu );
815 OSQLResult res = m_driver->query( &raw ); 819 OSQLResult res = m_driver->query( &raw );
816 820
817 QArray<int> completed_uids = uids( res ); 821 QArray<int> completed_uids = uids( res );
818 822
819 qDebug( "Number of completed: %d", completed_uids.size() ); 823 odebug << "Number of completed: " << completed_uids.size() << "" << oendl;
820 824
821 if ( completed_uids.size() == 0 ) 825 if ( completed_uids.size() == 0 )
822 return; 826 return;
823 827
824 qu = "DELETE FROM todolist WHERE ("; 828 qu = "DELETE FROM todolist WHERE (";
825 QString query; 829 QString query;
826 830
827 for ( int i = 0; i < completed_uids.size(); i++ ){ 831 for ( int i = 0; i < completed_uids.size(); i++ ){
828 if ( !query.isEmpty() ) 832 if ( !query.isEmpty() )
829 query += " OR "; 833 query += " OR ";
830 query += QString( "uid = %1" ).arg( completed_uids[i] ); 834 query += QString( "uid = %1" ).arg( completed_uids[i] );
831 } 835 }
832 qu += query + " );"; 836 qu += query + " );";
833 837
834 // Put remove of custom entries in this query to speed up.. 838 // Put remove of custom entries in this query to speed up..
835 qu += "DELETE FORM custom_data WHERE ("; 839 qu += "DELETE FORM custom_data WHERE (";
836 query = ""; 840 query = "";
837 841
838 for ( int i = 0; i < completed_uids.size(); i++ ){ 842 for ( int i = 0; i < completed_uids.size(); i++ ){
839 if ( !query.isEmpty() ) 843 if ( !query.isEmpty() )
840 query += " OR "; 844 query += " OR ";
841 query += QString( "uid = %1" ).arg( completed_uids[i] ); 845 query += QString( "uid = %1" ).arg( completed_uids[i] );
842 } 846 }
843 qu += query + " );"; 847 qu += query + " );";
844 848
845 qDebug( "query: %s", qu.latin1() ); 849 odebug << "query: " << qu << "" << oendl;
846 850
847 OSQLRawQuery raw2( qu ); 851 OSQLRawQuery raw2( qu );
848 res = m_driver->query( &raw2 ); 852 res = m_driver->query( &raw2 );
849 if ( res.state() == OSQLResult::Failure ) { 853 if ( res.state() == OSQLResult::Failure ) {
850 qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() ); 854 owarn << "OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: " << qu << "" << oendl;
851 } 855 }
852} 856}
853 857
854 858
855QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const 859QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
856{ 860{
857 QMap<QString, QString> customMap; 861 QMap<QString, QString> customMap;
858 862
859 FindCustomQuery query( uid ); 863 FindCustomQuery query( uid );
860 OSQLResult res_custom = m_driver->query( &query ); 864 OSQLResult res_custom = m_driver->query( &query );
861 865
862 if ( res_custom.state() == OSQLResult::Failure ) { 866 if ( res_custom.state() == OSQLResult::Failure ) {
863 qWarning("OSQLResult::Failure in find query !!"); 867 owarn << "OSQLResult::Failure in find query !!" << oendl;
864 QMap<QString, QString> empty; 868 QMap<QString, QString> empty;
865 return empty; 869 return empty;
866 } 870 }
867 871
868 OSQLResultItem::ValueList list = res_custom.results(); 872 OSQLResultItem::ValueList list = res_custom.results();
869 OSQLResultItem::ValueList::Iterator it = list.begin(); 873 OSQLResultItem::ValueList::Iterator it = list.begin();
870 for ( ; it != list.end(); ++it ) { 874 for ( ; it != list.end(); ++it ) {
871 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); 875 customMap.insert( (*it).data( "type" ), (*it).data( "value" ) );
872 } 876 }
873 877
874 return customMap; 878 return customMap;
875} 879}
876 880
877 881
878 882
879 883
880} 884}
diff --git a/libopie2/opiepim/backend/otodoaccessvcal.cpp b/libopie2/opiepim/backend/otodoaccessvcal.cpp
index 03d4479..14a325e 100644
--- a/libopie2/opiepim/backend/otodoaccessvcal.cpp
+++ b/libopie2/opiepim/backend/otodoaccessvcal.cpp
@@ -1,285 +1,289 @@
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/* OPIE */
31#include "vobject_p.h" 30#include "vobject_p.h"
32#include <qpe/timeconversion.h> 31
32/* OPIE */
33#include <opie2/otodoaccessvcal.h> 33#include <opie2/otodoaccessvcal.h>
34#include <opie2/odebug.h>
34 35
36#include <qpe/timeconversion.h>
37
38/* QT */
35//FIXME: Hack to allow direct access to FILE* fh. Rewrite this! 39//FIXME: Hack to allow direct access to FILE* fh. Rewrite this!
36#define protected public 40#define protected public
37#include <qfile.h> 41#include <qfile.h>
38#undef protected 42#undef protected
39 43
40using namespace Opie; 44using namespace Opie;
41 45
42namespace { 46namespace {
43 static OPimTodo eventByVObj( VObject *obj ){ 47 static OPimTodo eventByVObj( VObject *obj ){
44 OPimTodo event; 48 OPimTodo event;
45 VObject *ob; 49 VObject *ob;
46 QCString name; 50 QCString name;
47 // no uid, attendees, ... and no fun 51 // no uid, attendees, ... and no fun
48 // description 52 // description
49 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ 53 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
50 name = vObjectStringZValue( ob ); 54 name = vObjectStringZValue( ob );
51#if 0 55#if 0
52 event.setDescription( name ); 56 event.setDescription( name );
53#else 57#else
54 event.setSummary( name ); 58 event.setSummary( name );
55#endif 59#endif
56 } 60 }
57 // summary 61 // summary
58 if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) { 62 if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) {
59 name = vObjectStringZValue( ob ); 63 name = vObjectStringZValue( ob );
60#if 0 64#if 0
61 event.setSummary( name ); 65 event.setSummary( name );
62#else 66#else
63 event.setDescription( name ); 67 event.setDescription( name );
64#endif 68#endif
65 } 69 }
66 // completed 70 // completed
67 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ 71 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
68 name = vObjectStringZValue( ob ); 72 name = vObjectStringZValue( ob );
69 if( name == "COMPLETED" ){ 73 if( name == "COMPLETED" ){
70 event.setCompleted( true ); 74 event.setCompleted( true );
71 }else{ 75 }else{
72 event.setCompleted( false ); 76 event.setCompleted( false );
73 } 77 }
74 }else 78 }else
75 event.setCompleted( false ); 79 event.setCompleted( false );
76 // priority 80 // priority
77 if ((ob = isAPropertyOf(obj, VCPriorityProp))) { 81 if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
78 name = vObjectStringZValue( ob ); 82 name = vObjectStringZValue( ob );
79 bool ok; 83 bool ok;
80 event.setPriority(name.toInt(&ok) ); 84 event.setPriority(name.toInt(&ok) );
81 } 85 }
82 //due date 86 //due date
83 if((ob = isAPropertyOf(obj, VCDueProp)) ){ 87 if((ob = isAPropertyOf(obj, VCDueProp)) ){
84 event.setHasDueDate( true ); 88 event.setHasDueDate( true );
85 name = vObjectStringZValue( ob ); 89 name = vObjectStringZValue( ob );
86 event.setDueDate( TimeConversion::fromISO8601( name).date() ); 90 event.setDueDate( TimeConversion::fromISO8601( name).date() );
87 } 91 }
88 // categories 92 // categories
89 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ 93 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
90 name = vObjectStringZValue( ob ); 94 name = vObjectStringZValue( ob );
91 qWarning("Categories:%s", name.data() ); 95 owarn << "Categories:" << name.data() << "" << oendl;
92 } 96 }
93 97
94 event.setUid( 1 ); 98 event.setUid( 1 );
95 return event; 99 return event;
96 }; 100 };
97 static VObject *vobjByEvent( const OPimTodo &event ) { 101 static VObject *vobjByEvent( const OPimTodo &event ) {
98 VObject *task = newVObject( VCTodoProp ); 102 VObject *task = newVObject( VCTodoProp );
99 if( task == 0 ) 103 if( task == 0 )
100 return 0l; 104 return 0l;
101 105
102 if( event.hasDueDate() ) { 106 if( event.hasDueDate() ) {
103 QTime time(0, 0, 0); 107 QTime time(0, 0, 0);
104 QDateTime date(event.dueDate(), time ); 108 QDateTime date(event.dueDate(), time );
105 addPropValue( task, VCDueProp, 109 addPropValue( task, VCDueProp,
106 TimeConversion::toISO8601( date ) ); 110 TimeConversion::toISO8601( date ) );
107 } 111 }
108 112
109 if( event.isCompleted() ) 113 if( event.isCompleted() )
110 addPropValue( task, VCStatusProp, "COMPLETED"); 114 addPropValue( task, VCStatusProp, "COMPLETED");
111 115
112 QString string = QString::number(event.priority() ); 116 QString string = QString::number(event.priority() );
113 addPropValue( task, VCPriorityProp, string.local8Bit() ); 117 addPropValue( task, VCPriorityProp, string.local8Bit() );
114 118
115 addPropValue( task, VCCategoriesProp, 119 addPropValue( task, VCCategoriesProp,
116 event.idsToString( event.categories() ).local8Bit() ); 120 event.idsToString( event.categories() ).local8Bit() );
117 121
118#if 0 122#if 0
119 123
120 // There seems a misrepresentation between summary in otodoevent 124 // There seems a misrepresentation between summary in otodoevent
121 // and summary in vcard. 125 // and summary in vcard.
122 // The same with description.. 126 // The same with description..
123 // Description is summary and vice versa.. Argh.. (eilers) 127 // Description is summary and vice versa.. Argh.. (eilers)
124 128
125 129
126 addPropValue( task, VCDescriptionProp, 130 addPropValue( task, VCDescriptionProp,
127 event.description().local8Bit() ); 131 event.description().local8Bit() );
128 132
129 addPropValue( task, VCSummaryProp, 133 addPropValue( task, VCSummaryProp,
130 event.summary().local8Bit() ); 134 event.summary().local8Bit() );
131 135
132#else 136#else
133 addPropValue( task, VCDescriptionProp, 137 addPropValue( task, VCDescriptionProp,
134 event.summary().local8Bit() ); 138 event.summary().local8Bit() );
135 139
136 addPropValue( task, VCSummaryProp, 140 addPropValue( task, VCSummaryProp,
137 event.description().local8Bit() ); 141 event.description().local8Bit() );
138#endif 142#endif
139 return task; 143 return task;
140}; 144};
141} 145}
142 146
143namespace Opie { 147namespace Opie {
144OPimTodoAccessVCal::OPimTodoAccessVCal( const QString& path ) 148OPimTodoAccessVCal::OPimTodoAccessVCal( const QString& path )
145 : m_dirty(false), m_file( path ) 149 : m_dirty(false), m_file( path )
146{ 150{
147} 151}
148OPimTodoAccessVCal::~OPimTodoAccessVCal() { 152OPimTodoAccessVCal::~OPimTodoAccessVCal() {
149} 153}
150bool OPimTodoAccessVCal::load() { 154bool OPimTodoAccessVCal::load() {
151 m_map.clear(); 155 m_map.clear();
152 m_dirty = false; 156 m_dirty = false;
153 157
154 VObject* vcal = 0l; 158 VObject* vcal = 0l;
155 vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 159 vcal = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
156 if (!vcal ) 160 if (!vcal )
157 return false; 161 return false;
158 162
159 // Iterate over the list 163 // Iterate over the list
160 VObjectIterator it; 164 VObjectIterator it;
161 VObject* vobj; 165 VObject* vobj;
162 166
163 initPropIterator(&it, vcal); 167 initPropIterator(&it, vcal);
164 168
165 while( moreIteration( &it ) ) { 169 while( moreIteration( &it ) ) {
166 vobj = ::nextVObject( &it ); 170 vobj = ::nextVObject( &it );
167 QCString name = ::vObjectName( vobj ); 171 QCString name = ::vObjectName( vobj );
168 if( name == VCTodoProp ){ 172 if( name == VCTodoProp ){
169 OPimTodo to = eventByVObj( vobj ); 173 OPimTodo to = eventByVObj( vobj );
170 m_map.insert( to.uid(), to ); 174 m_map.insert( to.uid(), to );
171 } 175 }
172 } 176 }
173 177
174 // Should I do a delete vcal? 178 // Should I do a delete vcal?
175 179
176 return true; 180 return true;
177} 181}
178bool OPimTodoAccessVCal::reload() { 182bool OPimTodoAccessVCal::reload() {
179 return load(); 183 return load();
180} 184}
181bool OPimTodoAccessVCal::save() { 185bool OPimTodoAccessVCal::save() {
182 if (!m_dirty ) 186 if (!m_dirty )
183 return true; 187 return true;
184 188
185 QFile file( m_file ); 189 QFile file( m_file );
186 if (!file.open(IO_WriteOnly ) ) 190 if (!file.open(IO_WriteOnly ) )
187 return false; 191 return false;
188 192
189 VObject *obj; 193 VObject *obj;
190 obj = newVObject( VCCalProp ); 194 obj = newVObject( VCCalProp );
191 addPropValue( obj, VCVersionProp, "1.0" ); 195 addPropValue( obj, VCVersionProp, "1.0" );
192 VObject *vo; 196 VObject *vo;
193 for(QMap<int, OPimTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 197 for(QMap<int, OPimTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
194 vo = vobjByEvent( it.data() ); 198 vo = vobjByEvent( it.data() );
195 addVObjectProp(obj, vo ); 199 addVObjectProp(obj, vo );
196 } 200 }
197 writeVObject( file.fh, obj ); //FIXME: HACK!!! 201 writeVObject( file.fh, obj ); //FIXME: HACK!!!
198 cleanVObject( obj ); 202 cleanVObject( obj );
199 cleanStrTbl(); 203 cleanStrTbl();
200 204
201 m_dirty = false; 205 m_dirty = false;
202 return true; 206 return true;
203} 207}
204void OPimTodoAccessVCal::clear() { 208void OPimTodoAccessVCal::clear() {
205 m_map.clear(); 209 m_map.clear();
206 m_dirty = true; 210 m_dirty = true;
207} 211}
208bool OPimTodoAccessVCal::add( const OPimTodo& to ) { 212bool OPimTodoAccessVCal::add( const OPimTodo& to ) {
209 m_map.insert( to.uid(), to ); 213 m_map.insert( to.uid(), to );
210 m_dirty = true; 214 m_dirty = true;
211 return true; 215 return true;
212} 216}
213bool OPimTodoAccessVCal::remove( int uid ) { 217bool OPimTodoAccessVCal::remove( int uid ) {
214 m_map.remove( uid ); 218 m_map.remove( uid );
215 m_dirty = true; 219 m_dirty = true;
216 return true; 220 return true;
217} 221}
218void OPimTodoAccessVCal::removeAllCompleted() { 222void OPimTodoAccessVCal::removeAllCompleted() {
219 for ( QMap<int, OPimTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) { 223 for ( QMap<int, OPimTodo>::Iterator it = m_map.begin(); it != m_map.end(); ++it ) {
220 if ( (*it).isCompleted() ) 224 if ( (*it).isCompleted() )
221 m_map.remove( it ); 225 m_map.remove( it );
222 } 226 }
223} 227}
224bool OPimTodoAccessVCal::replace( const OPimTodo& to ) { 228bool OPimTodoAccessVCal::replace( const OPimTodo& to ) {
225 m_map.replace( to.uid(), to ); 229 m_map.replace( to.uid(), to );
226 m_dirty = true; 230 m_dirty = true;
227 return true; 231 return true;
228} 232}
229OPimTodo OPimTodoAccessVCal::find(int uid )const { 233OPimTodo OPimTodoAccessVCal::find(int uid )const {
230 return m_map[uid]; 234 return m_map[uid];
231} 235}
232QArray<int> OPimTodoAccessVCal::sorted( bool, int, int, int ) { 236QArray<int> OPimTodoAccessVCal::sorted( bool, int, int, int ) {
233 QArray<int> ar(0); 237 QArray<int> ar(0);
234 return ar; 238 return ar;
235} 239}
236QArray<int> OPimTodoAccessVCal::allRecords()const { 240QArray<int> OPimTodoAccessVCal::allRecords()const {
237 QArray<int> ar( m_map.count() ); 241 QArray<int> ar( m_map.count() );
238 QMap<int, OPimTodo>::ConstIterator it; 242 QMap<int, OPimTodo>::ConstIterator it;
239 int i = 0; 243 int i = 0;
240 for ( it = m_map.begin(); it != m_map.end(); ++it ) { 244 for ( it = m_map.begin(); it != m_map.end(); ++it ) {
241 ar[i] = it.key(); 245 ar[i] = it.key();
242 i++; 246 i++;
243 } 247 }
244 return ar; 248 return ar;
245} 249}
246QArray<int> OPimTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const { 250QArray<int> OPimTodoAccessVCal::matchRegexp(const QRegExp& /* r */)const {
247 QArray<int> ar(0); 251 QArray<int> ar(0);
248 return ar; 252 return ar;
249} 253}
250QArray<int> OPimTodoAccessVCal::queryByExample( const OPimTodo&, int, const QDateTime& ) { 254QArray<int> OPimTodoAccessVCal::queryByExample( const OPimTodo&, int, const QDateTime& ) {
251 QArray<int> ar(0); 255 QArray<int> ar(0);
252 return ar; 256 return ar;
253} 257}
254QArray<int> OPimTodoAccessVCal::effectiveToDos( const QDate& , 258QArray<int> OPimTodoAccessVCal::effectiveToDos( const QDate& ,
255 const QDate& , 259 const QDate& ,
256 bool ) { 260 bool ) {
257 QArray<int> ar(0); 261 QArray<int> ar(0);
258 return ar; 262 return ar;
259} 263}
260QArray<int> OPimTodoAccessVCal::overDue() { 264QArray<int> OPimTodoAccessVCal::overDue() {
261 QArray<int> ar(0); 265 QArray<int> ar(0);
262 return ar; 266 return ar;
263} 267}
264QBitArray OPimTodoAccessVCal::supports()const { 268QBitArray OPimTodoAccessVCal::supports()const {
265 static QBitArray ar = sup(); 269 static QBitArray ar = sup();
266 270
267 return ar; 271 return ar;
268} 272}
269QBitArray OPimTodoAccessVCal::sup() { 273QBitArray OPimTodoAccessVCal::sup() {
270 QBitArray ar ( OPimTodo::CompletedDate +1 ); 274 QBitArray ar ( OPimTodo::CompletedDate +1 );
271 ar.fill( true ); 275 ar.fill( true );
272 276
273 ar[OPimTodo::CrossReference] = false; 277 ar[OPimTodo::CrossReference] = false;
274 ar[OPimTodo::State ] = false; 278 ar[OPimTodo::State ] = false;
275 ar[OPimTodo::Reminders] = false; 279 ar[OPimTodo::Reminders] = false;
276 ar[OPimTodo::Notifiers] = false; 280 ar[OPimTodo::Notifiers] = false;
277 ar[OPimTodo::Maintainer] = false; 281 ar[OPimTodo::Maintainer] = false;
278 ar[OPimTodo::Progress] = false; 282 ar[OPimTodo::Progress] = false;
279 ar[OPimTodo::Alarms ] = false; 283 ar[OPimTodo::Alarms ] = false;
280 ar[OPimTodo::Recurrence] = false; 284 ar[OPimTodo::Recurrence] = false;
281 285
282 return ar; 286 return ar;
283} 287}
284 288
285} 289}
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index cce6111..3e06d88 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -1,909 +1,914 @@
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
30/* OPIE */
31#include <opie2/opimdateconversion.h>
32#include <opie2/opimstate.h>
33#include <opie2/opimtimezone.h>
34#include <opie2/opimnotifymanager.h>
35#include <opie2/opimrecurrence.h>
36#include <opie2/otodoaccessxml.h>
37#include <opie2/odebug.h>
38
39#include <qpe/global.h>
40#include <qpe/stringutil.h>
41#include <qpe/timeconversion.h>
42
43/* QT */
44#include <qfile.h>
45#include <qvector.h>
46
47/* STD */
29#include <errno.h> 48#include <errno.h>
30#include <fcntl.h> 49#include <fcntl.h>
31 50
32#include <sys/mman.h> 51#include <sys/mman.h>
33#include <sys/stat.h> 52#include <sys/stat.h>
34#include <sys/types.h> 53#include <sys/types.h>
35 54
36#include <unistd.h> 55#include <unistd.h>
37 56
38 57
39#include <qfile.h>
40#include <qvector.h>
41
42#include <qpe/global.h>
43#include <qpe/stringutil.h>
44#include <qpe/timeconversion.h>
45
46#include <opie2/opimdateconversion.h>
47#include <opie2/opimstate.h>
48#include <opie2/opimtimezone.h>
49#include <opie2/opimnotifymanager.h>
50#include <opie2/opimrecurrence.h>
51#include <opie2/otodoaccessxml.h>
52
53using namespace Opie; 58using namespace Opie;
54 59
55namespace { 60namespace {
56 time_t rp_end; 61 time_t rp_end;
57 OPimRecurrence* rec; 62 OPimRecurrence* rec;
58 OPimRecurrence *recur() { 63 OPimRecurrence *recur() {
59 if (!rec ) rec = new OPimRecurrence; 64 if (!rec ) rec = new OPimRecurrence;
60 return rec; 65 return rec;
61 } 66 }
62 int snd; 67 int snd;
63 enum MoreAttributes { 68 enum MoreAttributes {
64 FRType = OPimTodo::CompletedDate + 2, 69 FRType = OPimTodo::CompletedDate + 2,
65 FRWeekdays, 70 FRWeekdays,
66 FRPosition, 71 FRPosition,
67 FRFreq, 72 FRFreq,
68 FRHasEndDate, 73 FRHasEndDate,
69 FREndDate, 74 FREndDate,
70 FRStart, 75 FRStart,
71 FREnd 76 FREnd
72 }; 77 };
73 // FROM TT again 78 // FROM TT again
74char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 79char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
75{ 80{
76 char needleChar; 81 char needleChar;
77 char haystackChar; 82 char haystackChar;
78 if (!needle || !haystack || !hLen || !nLen) 83 if (!needle || !haystack || !hLen || !nLen)
79 return 0; 84 return 0;
80 85
81 const char* hsearch = haystack; 86 const char* hsearch = haystack;
82 87
83 if ((needleChar = *needle++) != 0) { 88 if ((needleChar = *needle++) != 0) {
84 nLen--; //(to make up for needle++) 89 nLen--; //(to make up for needle++)
85 do { 90 do {
86 do { 91 do {
87 if ((haystackChar = *hsearch++) == 0) 92 if ((haystackChar = *hsearch++) == 0)
88 return (0); 93 return (0);
89 if (hsearch >= haystack + hLen) 94 if (hsearch >= haystack + hLen)
90 return (0); 95 return (0);
91 } while (haystackChar != needleChar); 96 } while (haystackChar != needleChar);
92 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); 97 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
93 hsearch--; 98 hsearch--;
94 } 99 }
95 return ((char *)hsearch); 100 return ((char *)hsearch);
96} 101}
97} 102}
98 103
99namespace Opie { 104namespace Opie {
100 105
101OPimTodoAccessXML::OPimTodoAccessXML( const QString& appName, 106OPimTodoAccessXML::OPimTodoAccessXML( const QString& appName,
102 const QString& fileName ) 107 const QString& fileName )
103 : OPimTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 108 : OPimTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
104{ 109{
105 if (!fileName.isEmpty() ) 110 if (!fileName.isEmpty() )
106 m_file = fileName; 111 m_file = fileName;
107 else 112 else
108 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 113 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
109} 114}
110OPimTodoAccessXML::~OPimTodoAccessXML() { 115OPimTodoAccessXML::~OPimTodoAccessXML() {
111 116
112} 117}
113bool OPimTodoAccessXML::load() { 118bool OPimTodoAccessXML::load() {
114 rec = 0; 119 rec = 0;
115 m_opened = true; 120 m_opened = true;
116 m_changed = false; 121 m_changed = false;
117 /* initialize dict */ 122 /* initialize dict */
118 /* 123 /*
119 * UPDATE dict if you change anything!!! 124 * UPDATE dict if you change anything!!!
120 */ 125 */
121 QAsciiDict<int> dict(26); 126 QAsciiDict<int> dict(26);
122 dict.setAutoDelete( TRUE ); 127 dict.setAutoDelete( TRUE );
123 dict.insert("Categories" , new int(OPimTodo::Category) ); 128 dict.insert("Categories" , new int(OPimTodo::Category) );
124 dict.insert("Uid" , new int(OPimTodo::Uid) ); 129 dict.insert("Uid" , new int(OPimTodo::Uid) );
125 dict.insert("HasDate" , new int(OPimTodo::HasDate) ); 130 dict.insert("HasDate" , new int(OPimTodo::HasDate) );
126 dict.insert("Completed" , new int(OPimTodo::Completed) ); 131 dict.insert("Completed" , new int(OPimTodo::Completed) );
127 dict.insert("Description" , new int(OPimTodo::Description) ); 132 dict.insert("Description" , new int(OPimTodo::Description) );
128 dict.insert("Summary" , new int(OPimTodo::Summary) ); 133 dict.insert("Summary" , new int(OPimTodo::Summary) );
129 dict.insert("Priority" , new int(OPimTodo::Priority) ); 134 dict.insert("Priority" , new int(OPimTodo::Priority) );
130 dict.insert("DateDay" , new int(OPimTodo::DateDay) ); 135 dict.insert("DateDay" , new int(OPimTodo::DateDay) );
131 dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); 136 dict.insert("DateMonth" , new int(OPimTodo::DateMonth) );
132 dict.insert("DateYear" , new int(OPimTodo::DateYear) ); 137 dict.insert("DateYear" , new int(OPimTodo::DateYear) );
133 dict.insert("Progress" , new int(OPimTodo::Progress) ); 138 dict.insert("Progress" , new int(OPimTodo::Progress) );
134 dict.insert("CompletedDate", new int(OPimTodo::CompletedDate) ); 139 dict.insert("CompletedDate", new int(OPimTodo::CompletedDate) );
135 dict.insert("StartDate", new int(OPimTodo::StartDate) ); 140 dict.insert("StartDate", new int(OPimTodo::StartDate) );
136 dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); 141 dict.insert("CrossReference", new int(OPimTodo::CrossReference) );
137 dict.insert("State", new int(OPimTodo::State) ); 142 dict.insert("State", new int(OPimTodo::State) );
138 dict.insert("Alarms", new int(OPimTodo::Alarms) ); 143 dict.insert("Alarms", new int(OPimTodo::Alarms) );
139 dict.insert("Reminders", new int(OPimTodo::Reminders) ); 144 dict.insert("Reminders", new int(OPimTodo::Reminders) );
140 dict.insert("Notifiers", new int(OPimTodo::Notifiers) ); 145 dict.insert("Notifiers", new int(OPimTodo::Notifiers) );
141 dict.insert("Maintainer", new int(OPimTodo::Maintainer) ); 146 dict.insert("Maintainer", new int(OPimTodo::Maintainer) );
142 dict.insert("rtype", new int(FRType) ); 147 dict.insert("rtype", new int(FRType) );
143 dict.insert("rweekdays", new int(FRWeekdays) ); 148 dict.insert("rweekdays", new int(FRWeekdays) );
144 dict.insert("rposition", new int(FRPosition) ); 149 dict.insert("rposition", new int(FRPosition) );
145 dict.insert("rfreq", new int(FRFreq) ); 150 dict.insert("rfreq", new int(FRFreq) );
146 dict.insert("start", new int(FRStart) ); 151 dict.insert("start", new int(FRStart) );
147 dict.insert("rhasenddate", new int(FRHasEndDate) ); 152 dict.insert("rhasenddate", new int(FRHasEndDate) );
148 dict.insert("enddt", new int(FREndDate) ); 153 dict.insert("enddt", new int(FREndDate) );
149 154
150 // here the custom XML parser from TT it's GPL 155 // here the custom XML parser from TT it's GPL
151 // but we want to push OpiePIM... to TT..... 156 // but we want to push OpiePIM... to TT.....
152 // mmap part from zecke :) 157 // mmap part from zecke :)
153 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); 158 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
154 struct stat attribut; 159 struct stat attribut;
155 if ( fd < 0 ) return false; 160 if ( fd < 0 ) return false;
156 161
157 if ( fstat(fd, &attribut ) == -1 ) { 162 if ( fstat(fd, &attribut ) == -1 ) {
158 ::close( fd ); 163 ::close( fd );
159 return false; 164 return false;
160 } 165 }
161 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); 166 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
162 if ( map_addr == ( (caddr_t)-1) ) { 167 if ( map_addr == ( (caddr_t)-1) ) {
163 ::close(fd ); 168 ::close(fd );
164 return false; 169 return false;
165 } 170 }
166 /* advise the kernel who we want to read it */ 171 /* advise the kernel who we want to read it */
167 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); 172 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
168 /* we do not the file any more */ 173 /* we do not the file any more */
169 ::close( fd ); 174 ::close( fd );
170 175
171 char* dt = (char*)map_addr; 176 char* dt = (char*)map_addr;
172 int len = attribut.st_size; 177 int len = attribut.st_size;
173 int i = 0; 178 int i = 0;
174 char *point; 179 char *point;
175 const char* collectionString = "<Task "; 180 const char* collectionString = "<Task ";
176 int strLen = strlen(collectionString); 181 int strLen = strlen(collectionString);
177 while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { 182 while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) {
178 i = point -dt; 183 i = point -dt;
179 i+= strLen; 184 i+= strLen;
180 qWarning("Found a start at %d %d", i, (point-dt) ); 185 owarn << "Found a start at " << i << " " << (point-dt) << "" << oendl;
181 186
182 OPimTodo ev; 187 OPimTodo ev;
183 m_year = m_month = m_day = 0; 188 m_year = m_month = m_day = 0;
184 189
185 while ( TRUE ) { 190 while ( TRUE ) {
186 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 191 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
187 ++i; 192 ++i;
188 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 193 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
189 break; 194 break;
190 195
191 // we have another attribute, read it. 196 // we have another attribute, read it.
192 int j = i; 197 int j = i;
193 while ( j < len && dt[j] != '=' ) 198 while ( j < len && dt[j] != '=' )
194 ++j; 199 ++j;
195 QCString attr( dt+i, j-i+1); 200 QCString attr( dt+i, j-i+1);
196 201
197 i = ++j; // skip = 202 i = ++j; // skip =
198 203
199 // find the start of quotes 204 // find the start of quotes
200 while ( i < len && dt[i] != '"' ) 205 while ( i < len && dt[i] != '"' )
201 ++i; 206 ++i;
202 j = ++i; 207 j = ++i;
203 208
204 bool haveUtf = FALSE; 209 bool haveUtf = FALSE;
205 bool haveEnt = FALSE; 210 bool haveEnt = FALSE;
206 while ( j < len && dt[j] != '"' ) { 211 while ( j < len && dt[j] != '"' ) {
207 if ( ((unsigned char)dt[j]) > 0x7f ) 212 if ( ((unsigned char)dt[j]) > 0x7f )
208 haveUtf = TRUE; 213 haveUtf = TRUE;
209 if ( dt[j] == '&' ) 214 if ( dt[j] == '&' )
210 haveEnt = TRUE; 215 haveEnt = TRUE;
211 ++j; 216 ++j;
212 } 217 }
213 if ( i == j ) { 218 if ( i == j ) {
214 // empty value 219 // empty value
215 i = j + 1; 220 i = j + 1;
216 continue; 221 continue;
217 } 222 }
218 223
219 QCString value( dt+i, j-i+1 ); 224 QCString value( dt+i, j-i+1 );
220 i = j + 1; 225 i = j + 1;
221 226
222 QString str = (haveUtf ? QString::fromUtf8( value ) 227 QString str = (haveUtf ? QString::fromUtf8( value )
223 : QString::fromLatin1( value ) ); 228 : QString::fromLatin1( value ) );
224 if ( haveEnt ) 229 if ( haveEnt )
225 str = Qtopia::plainString( str ); 230 str = Qtopia::plainString( str );
226 231
227 /* 232 /*
228 * add key + value 233 * add key + value
229 */ 234 */
230 todo( &dict, ev, attr, str ); 235 todo( &dict, ev, attr, str );
231 236
232 } 237 }
233 /* 238 /*
234 * now add it 239 * now add it
235 */ 240 */
236 qWarning("End at %d", i ); 241 owarn << "End at " << i << "" << oendl;
237 if (m_events.contains( ev.uid() ) || ev.uid() == 0) { 242 if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
238 ev.setUid( 1 ); 243 ev.setUid( 1 );
239 m_changed = true; 244 m_changed = true;
240 } 245 }
241 if ( ev.hasDueDate() ) { 246 if ( ev.hasDueDate() ) {
242 ev.setDueDate( QDate(m_year, m_month, m_day) ); 247 ev.setDueDate( QDate(m_year, m_month, m_day) );
243 } 248 }
244 if ( rec && rec->doesRecur() ) { 249 if ( rec && rec->doesRecur() ) {
245 OPimTimeZone utc = OPimTimeZone::utc(); 250 OPimTimeZone utc = OPimTimeZone::utc();
246 OPimRecurrence recu( *rec ); // call copy c'tor 251 OPimRecurrence recu( *rec ); // call copy c'tor
247 recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); 252 recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() );
248 recu.setStart( ev.dueDate() ); 253 recu.setStart( ev.dueDate() );
249 ev.setRecurrence( recu ); 254 ev.setRecurrence( recu );
250 } 255 }
251 m_events.insert(ev.uid(), ev ); 256 m_events.insert(ev.uid(), ev );
252 m_year = m_month = m_day = -1; 257 m_year = m_month = m_day = -1;
253 delete rec; 258 delete rec;
254 rec = 0; 259 rec = 0;
255 } 260 }
256 261
257 munmap(map_addr, attribut.st_size ); 262 munmap(map_addr, attribut.st_size );
258 263
259 qWarning("counts %d records loaded!", m_events.count() ); 264 owarn << "counts " << m_events.count() << " records loaded!" << oendl;
260 return true; 265 return true;
261} 266}
262bool OPimTodoAccessXML::reload() { 267bool OPimTodoAccessXML::reload() {
263 m_events.clear(); 268 m_events.clear();
264 return load(); 269 return load();
265} 270}
266bool OPimTodoAccessXML::save() { 271bool OPimTodoAccessXML::save() {
267// qWarning("saving"); 272// owarn << "saving" << oendl;
268 if (!m_opened || !m_changed ) { 273 if (!m_opened || !m_changed ) {
269// qWarning("not saving"); 274// owarn << "not saving" << oendl;
270 return true; 275 return true;
271 } 276 }
272 QString strNewFile = m_file + ".new"; 277 QString strNewFile = m_file + ".new";
273 QFile f( strNewFile ); 278 QFile f( strNewFile );
274 if (!f.open( IO_WriteOnly|IO_Raw ) ) 279 if (!f.open( IO_WriteOnly|IO_Raw ) )
275 return false; 280 return false;
276 281
277 int written; 282 int written;
278 QString out; 283 QString out;
279 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 284 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
280 285
281 // for all todos 286 // for all todos
282 QMap<int, OPimTodo>::Iterator it; 287 QMap<int, OPimTodo>::Iterator it;
283 for (it = m_events.begin(); it != m_events.end(); ++it ) { 288 for (it = m_events.begin(); it != m_events.end(); ++it ) {
284 out+= "<Task " + toString( (*it) ) + " />\n"; 289 out+= "<Task " + toString( (*it) ) + " />\n";
285 QCString cstr = out.utf8(); 290 QCString cstr = out.utf8();
286 written = f.writeBlock( cstr.data(), cstr.length() ); 291 written = f.writeBlock( cstr.data(), cstr.length() );
287 292
288 /* less written then we wanted */ 293 /* less written then we wanted */
289 if ( written != (int)cstr.length() ) { 294 if ( written != (int)cstr.length() ) {
290 f.close(); 295 f.close();
291 QFile::remove( strNewFile ); 296 QFile::remove( strNewFile );
292 return false; 297 return false;
293 } 298 }
294 out = QString::null; 299 out = QString::null;
295 } 300 }
296 301
297 out += "</Tasks>"; 302 out += "</Tasks>";
298 QCString cstr = out.utf8(); 303 QCString cstr = out.utf8();
299 written = f.writeBlock( cstr.data(), cstr.length() ); 304 written = f.writeBlock( cstr.data(), cstr.length() );
300 305
301 if ( written != (int)cstr.length() ) { 306 if ( written != (int)cstr.length() ) {
302 f.close(); 307 f.close();
303 QFile::remove( strNewFile ); 308 QFile::remove( strNewFile );
304 return false; 309 return false;
305 } 310 }
306 /* flush before renaming */ 311 /* flush before renaming */
307 f.close(); 312 f.close();
308 313
309 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 314 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
310// qWarning("error renaming"); 315// owarn << "error renaming" << oendl;
311 QFile::remove( strNewFile ); 316 QFile::remove( strNewFile );
312 } 317 }
313 318
314 m_changed = false; 319 m_changed = false;
315 return true; 320 return true;
316} 321}
317QArray<int> OPimTodoAccessXML::allRecords()const { 322QArray<int> OPimTodoAccessXML::allRecords()const {
318 QArray<int> ids( m_events.count() ); 323 QArray<int> ids( m_events.count() );
319 QMap<int, OPimTodo>::ConstIterator it; 324 QMap<int, OPimTodo>::ConstIterator it;
320 int i = 0; 325 int i = 0;
321 326
322 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 327 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
323 ids[i] = it.key(); 328 ids[i] = it.key();
324 i++; 329 i++;
325 } 330 }
326 return ids; 331 return ids;
327} 332}
328QArray<int> OPimTodoAccessXML::queryByExample( const OPimTodo&, int, const QDateTime& ) { 333QArray<int> OPimTodoAccessXML::queryByExample( const OPimTodo&, int, const QDateTime& ) {
329 QArray<int> ids(0); 334 QArray<int> ids(0);
330 return ids; 335 return ids;
331} 336}
332OPimTodo OPimTodoAccessXML::find( int uid )const { 337OPimTodo OPimTodoAccessXML::find( int uid )const {
333 OPimTodo todo; 338 OPimTodo todo;
334 todo.setUid( 0 ); // isEmpty() 339 todo.setUid( 0 ); // isEmpty()
335 QMap<int, OPimTodo>::ConstIterator it = m_events.find( uid ); 340 QMap<int, OPimTodo>::ConstIterator it = m_events.find( uid );
336 if ( it != m_events.end() ) 341 if ( it != m_events.end() )
337 todo = it.data(); 342 todo = it.data();
338 343
339 return todo; 344 return todo;
340} 345}
341void OPimTodoAccessXML::clear() { 346void OPimTodoAccessXML::clear() {
342 if (m_opened ) 347 if (m_opened )
343 m_changed = true; 348 m_changed = true;
344 349
345 m_events.clear(); 350 m_events.clear();
346} 351}
347bool OPimTodoAccessXML::add( const OPimTodo& todo ) { 352bool OPimTodoAccessXML::add( const OPimTodo& todo ) {
348// qWarning("add"); 353// owarn << "add" << oendl;
349 m_changed = true; 354 m_changed = true;
350 m_events.insert( todo.uid(), todo ); 355 m_events.insert( todo.uid(), todo );
351 356
352 return true; 357 return true;
353} 358}
354bool OPimTodoAccessXML::remove( int uid ) { 359bool OPimTodoAccessXML::remove( int uid ) {
355 m_changed = true; 360 m_changed = true;
356 m_events.remove( uid ); 361 m_events.remove( uid );
357 362
358 return true; 363 return true;
359} 364}
360bool OPimTodoAccessXML::replace( const OPimTodo& todo) { 365bool OPimTodoAccessXML::replace( const OPimTodo& todo) {
361 m_changed = true; 366 m_changed = true;
362 m_events.replace( todo.uid(), todo ); 367 m_events.replace( todo.uid(), todo );
363 368
364 return true; 369 return true;
365} 370}
366QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start, 371QArray<int> OPimTodoAccessXML::effectiveToDos( const QDate& start,
367 const QDate& end, 372 const QDate& end,
368 bool includeNoDates ) { 373 bool includeNoDates ) {
369 QArray<int> ids( m_events.count() ); 374 QArray<int> ids( m_events.count() );
370 QMap<int, OPimTodo>::Iterator it; 375 QMap<int, OPimTodo>::Iterator it;
371 376
372 int i = 0; 377 int i = 0;
373 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 378 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
374 if ( !it.data().hasDueDate() ) { 379 if ( !it.data().hasDueDate() ) {
375 if ( includeNoDates ) { 380 if ( includeNoDates ) {
376 ids[i] = it.key(); 381 ids[i] = it.key();
377 i++; 382 i++;
378 } 383 }
379 }else if ( it.data().dueDate() >= start && 384 }else if ( it.data().dueDate() >= start &&
380 it.data().dueDate() <= end ) { 385 it.data().dueDate() <= end ) {
381 ids[i] = it.key(); 386 ids[i] = it.key();
382 i++; 387 i++;
383 } 388 }
384 } 389 }
385 ids.resize( i ); 390 ids.resize( i );
386 return ids; 391 return ids;
387} 392}
388QArray<int> OPimTodoAccessXML::overDue() { 393QArray<int> OPimTodoAccessXML::overDue() {
389 QArray<int> ids( m_events.count() ); 394 QArray<int> ids( m_events.count() );
390 int i = 0; 395 int i = 0;
391 396
392 QMap<int, OPimTodo>::Iterator it; 397 QMap<int, OPimTodo>::Iterator it;
393 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 398 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
394 if ( it.data().isOverdue() ) { 399 if ( it.data().isOverdue() ) {
395 ids[i] = it.key(); 400 ids[i] = it.key();
396 i++; 401 i++;
397 } 402 }
398 } 403 }
399 ids.resize( i ); 404 ids.resize( i );
400 return ids; 405 return ids;
401} 406}
402 407
403 408
404/* private */ 409/* private */
405void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev, 410void OPimTodoAccessXML::todo( QAsciiDict<int>* dict, OPimTodo& ev,
406 const QCString& attr, const QString& val) { 411 const QCString& attr, const QString& val) {
407// qWarning("parse to do from XMLElement" ); 412// owarn << "parse to do from XMLElement" << oendl;
408 413
409 int *find=0; 414 int *find=0;
410 415
411 find = (*dict)[ attr.data() ]; 416 find = (*dict)[ attr.data() ];
412 if (!find ) { 417 if (!find ) {
413// qWarning("Unknown option" + it.key() ); 418// owarn << "Unknown option" + it.key() << oendl;
414 ev.setCustomField( attr, val ); 419 ev.setCustomField( attr, val );
415 return; 420 return;
416 } 421 }
417 422
418 switch( *find ) { 423 switch( *find ) {
419 case OPimTodo::Uid: 424 case OPimTodo::Uid:
420 ev.setUid( val.toInt() ); 425 ev.setUid( val.toInt() );
421 break; 426 break;
422 case OPimTodo::Category: 427 case OPimTodo::Category:
423 ev.setCategories( ev.idsFromString( val ) ); 428 ev.setCategories( ev.idsFromString( val ) );
424 break; 429 break;
425 case OPimTodo::HasDate: 430 case OPimTodo::HasDate:
426 ev.setHasDueDate( val.toInt() ); 431 ev.setHasDueDate( val.toInt() );
427 break; 432 break;
428 case OPimTodo::Completed: 433 case OPimTodo::Completed:
429 ev.setCompleted( val.toInt() ); 434 ev.setCompleted( val.toInt() );
430 break; 435 break;
431 case OPimTodo::Description: 436 case OPimTodo::Description:
432 ev.setDescription( val ); 437 ev.setDescription( val );
433 break; 438 break;
434 case OPimTodo::Summary: 439 case OPimTodo::Summary:
435 ev.setSummary( val ); 440 ev.setSummary( val );
436 break; 441 break;
437 case OPimTodo::Priority: 442 case OPimTodo::Priority:
438 ev.setPriority( val.toInt() ); 443 ev.setPriority( val.toInt() );
439 break; 444 break;
440 case OPimTodo::DateDay: 445 case OPimTodo::DateDay:
441 m_day = val.toInt(); 446 m_day = val.toInt();
442 break; 447 break;
443 case OPimTodo::DateMonth: 448 case OPimTodo::DateMonth:
444 m_month = val.toInt(); 449 m_month = val.toInt();
445 break; 450 break;
446 case OPimTodo::DateYear: 451 case OPimTodo::DateYear:
447 m_year = val.toInt(); 452 m_year = val.toInt();
448 break; 453 break;
449 case OPimTodo::Progress: 454 case OPimTodo::Progress:
450 ev.setProgress( val.toInt() ); 455 ev.setProgress( val.toInt() );
451 break; 456 break;
452 case OPimTodo::CompletedDate: 457 case OPimTodo::CompletedDate:
453 ev.setCompletedDate( OPimDateConversion::dateFromString( val ) ); 458 ev.setCompletedDate( OPimDateConversion::dateFromString( val ) );
454 break; 459 break;
455 case OPimTodo::StartDate: 460 case OPimTodo::StartDate:
456 ev.setStartDate( OPimDateConversion::dateFromString( val ) ); 461 ev.setStartDate( OPimDateConversion::dateFromString( val ) );
457 break; 462 break;
458 case OPimTodo::State: 463 case OPimTodo::State:
459 ev.setState( val.toInt() ); 464 ev.setState( val.toInt() );
460 break; 465 break;
461 case OPimTodo::Alarms:{ 466 case OPimTodo::Alarms:{
462 OPimNotifyManager &manager = ev.notifiers(); 467 OPimNotifyManager &manager = ev.notifiers();
463 QStringList als = QStringList::split(";", val ); 468 QStringList als = QStringList::split(";", val );
464 for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { 469 for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) {
465 QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty 470 QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty
466 qWarning("alarm: %s", alarm.join("___").latin1() ); 471 owarn << "alarm: " << alarm.join("___") << "" << oendl;
467 qWarning("alarm[0]: %s %s", alarm[0].latin1(), OPimDateConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); 472 owarn << "alarm[0]: " << alarm[0] << " " << OPimDateConversion::dateTimeFromString( alarm[0] ).toString() << "" << oendl;
468 OPimAlarm al( alarm[2].toInt(), OPimDateConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); 473 OPimAlarm al( alarm[2].toInt(), OPimDateConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() );
469 manager.add( al ); 474 manager.add( al );
470 } 475 }
471 } 476 }
472 break; 477 break;
473 case OPimTodo::Reminders:{ 478 case OPimTodo::Reminders:{
474 OPimNotifyManager &manager = ev.notifiers(); 479 OPimNotifyManager &manager = ev.notifiers();
475 QStringList rems = QStringList::split(";", val ); 480 QStringList rems = QStringList::split(";", val );
476 for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { 481 for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) {
477 OPimReminder rem( (*it).toInt() ); 482 OPimReminder rem( (*it).toInt() );
478 manager.add( rem ); 483 manager.add( rem );
479 } 484 }
480 } 485 }
481 break; 486 break;
482 case OPimTodo::CrossReference: 487 case OPimTodo::CrossReference:
483 { 488 {
484 /* 489 /*
485 * A cross refernce looks like 490 * A cross refernce looks like
486 * appname,id;appname,id 491 * appname,id;appname,id
487 * we need to split it up 492 * we need to split it up
488 */ 493 */
489 QStringList refs = QStringList::split(';', val ); 494 QStringList refs = QStringList::split(';', val );
490 QStringList::Iterator strIt; 495 QStringList::Iterator strIt;
491 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { 496 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) {
492 int pos = (*strIt).find(','); 497 int pos = (*strIt).find(',');
493 if ( pos > -1 ) 498 if ( pos > -1 )
494 ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); 499 ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() );
495 500
496 } 501 }
497 break; 502 break;
498 } 503 }
499 /* Recurrence stuff below + post processing later */ 504 /* Recurrence stuff below + post processing later */
500 case FRType: 505 case FRType:
501 if ( val == "Daily" ) 506 if ( val == "Daily" )
502 recur()->setType( OPimRecurrence::Daily ); 507 recur()->setType( OPimRecurrence::Daily );
503 else if ( val == "Weekly" ) 508 else if ( val == "Weekly" )
504 recur()->setType( OPimRecurrence::Weekly); 509 recur()->setType( OPimRecurrence::Weekly);
505 else if ( val == "MonthlyDay" ) 510 else if ( val == "MonthlyDay" )
506 recur()->setType( OPimRecurrence::MonthlyDay ); 511 recur()->setType( OPimRecurrence::MonthlyDay );
507 else if ( val == "MonthlyDate" ) 512 else if ( val == "MonthlyDate" )
508 recur()->setType( OPimRecurrence::MonthlyDate ); 513 recur()->setType( OPimRecurrence::MonthlyDate );
509 else if ( val == "Yearly" ) 514 else if ( val == "Yearly" )
510 recur()->setType( OPimRecurrence::Yearly ); 515 recur()->setType( OPimRecurrence::Yearly );
511 else 516 else
512 recur()->setType( OPimRecurrence::NoRepeat ); 517 recur()->setType( OPimRecurrence::NoRepeat );
513 break; 518 break;
514 case FRWeekdays: 519 case FRWeekdays:
515 recur()->setDays( val.toInt() ); 520 recur()->setDays( val.toInt() );
516 break; 521 break;
517 case FRPosition: 522 case FRPosition:
518 recur()->setPosition( val.toInt() ); 523 recur()->setPosition( val.toInt() );
519 break; 524 break;
520 case FRFreq: 525 case FRFreq:
521 recur()->setFrequency( val.toInt() ); 526 recur()->setFrequency( val.toInt() );
522 break; 527 break;
523 case FRHasEndDate: 528 case FRHasEndDate:
524 recur()->setHasEndDate( val.toInt() ); 529 recur()->setHasEndDate( val.toInt() );
525 break; 530 break;
526 case FREndDate: { 531 case FREndDate: {
527 rp_end = (time_t) val.toLong(); 532 rp_end = (time_t) val.toLong();
528 break; 533 break;
529 } 534 }
530 default: 535 default:
531 ev.setCustomField( attr, val ); 536 ev.setCustomField( attr, val );
532 break; 537 break;
533 } 538 }
534} 539}
535 540
536// from PalmtopRecord... GPL ### FIXME 541// from PalmtopRecord... GPL ### FIXME
537namespace { 542namespace {
538QString customToXml(const QMap<QString, QString>& customMap ) 543QString customToXml(const QMap<QString, QString>& customMap )
539{ 544{
540 //qWarning(QString("writing custom %1").arg(customMap.count())); 545 //owarn << QString("writing custom %1").arg(customMap.count()) << oendl;
541 QString buf(" "); 546 QString buf(" ");
542 for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); 547 for ( QMap<QString, QString>::ConstIterator cit = customMap.begin();
543 cit != customMap.end(); ++cit) { 548 cit != customMap.end(); ++cit) {
544 // qWarning(".ITEM."); 549// owarn << ".ITEM." << oendl;
545 buf += cit.key(); 550 buf += cit.key();
546 buf += "=\""; 551 buf += "=\"";
547 buf += Qtopia::escapeString(cit.data()); 552 buf += Qtopia::escapeString(cit.data());
548 buf += "\" "; 553 buf += "\" ";
549 } 554 }
550 return buf; 555 return buf;
551} 556}
552 557
553 558
554} 559}
555 560
556QString OPimTodoAccessXML::toString( const OPimTodo& ev )const { 561QString OPimTodoAccessXML::toString( const OPimTodo& ev )const {
557 QString str; 562 QString str;
558 563
559 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; 564 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
560 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; 565 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
561 str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; 566 str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
562 str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; 567 str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
563 568
564 str += "Categories=\"" + toString( ev.categories() ) + "\" "; 569 str += "Categories=\"" + toString( ev.categories() ) + "\" ";
565 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; 570 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
566 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; 571 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
567 572
568 if ( ev.hasDueDate() ) { 573 if ( ev.hasDueDate() ) {
569 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; 574 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
570 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; 575 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
571 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; 576 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
572 } 577 }
573// qWarning( "Uid %d", ev.uid() ); 578// owarn << "Uid " << ev.uid() << "" << oendl;
574 str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; 579 str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
575 580
576// append the extra options 581// append the extra options
577 /* FIXME Qtopia::Record this is currently not 582 /* FIXME Qtopia::Record this is currently not
578 * possible you can set custom fields 583 * possible you can set custom fields
579 * but don' iterate over the list 584 * but don' iterate over the list
580 * I may do #define private protected 585 * I may do #define private protected
581 * for this case - cough --zecke 586 * for this case - cough --zecke
582 */ 587 */
583 /* 588 /*
584 QMap<QString, QString> extras = ev.extras(); 589 QMap<QString, QString> extras = ev.extras();
585 QMap<QString, QString>::Iterator extIt; 590 QMap<QString, QString>::Iterator extIt;
586 for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) 591 for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
587 str += extIt.key() + "=\"" + extIt.data() + "\" "; 592 str += extIt.key() + "=\"" + extIt.data() + "\" ";
588 */ 593 */
589 // cross refernce 594 // cross refernce
590 if ( ev.hasRecurrence() ) { 595 if ( ev.hasRecurrence() ) {
591 str += ev.recurrence().toString(); 596 str += ev.recurrence().toString();
592 } 597 }
593 if ( ev.hasStartDate() ) 598 if ( ev.hasStartDate() )
594 str += "StartDate=\""+ OPimDateConversion::dateToString( ev.startDate() ) +"\" "; 599 str += "StartDate=\""+ OPimDateConversion::dateToString( ev.startDate() ) +"\" ";
595 if ( ev.hasCompletedDate() ) 600 if ( ev.hasCompletedDate() )
596 str += "CompletedDate=\""+ OPimDateConversion::dateToString( ev.completedDate() ) +"\" "; 601 str += "CompletedDate=\""+ OPimDateConversion::dateToString( ev.completedDate() ) +"\" ";
597 if ( ev.hasState() ) 602 if ( ev.hasState() )
598 str += "State=\""+QString::number( ev.state().state() )+"\" "; 603 str += "State=\""+QString::number( ev.state().state() )+"\" ";
599 604
600 /* 605 /*
601 * save reminders and notifiers! 606 * save reminders and notifiers!
602 * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:.... 607 * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:....
603 */ 608 */
604 if ( ev.hasNotifiers() ) { 609 if ( ev.hasNotifiers() ) {
605 OPimNotifyManager manager = ev.notifiers(); 610 OPimNotifyManager manager = ev.notifiers();
606 OPimNotifyManager::Alarms alarms = manager.alarms(); 611 OPimNotifyManager::Alarms alarms = manager.alarms();
607 if (!alarms.isEmpty() ) { 612 if (!alarms.isEmpty() ) {
608 QStringList als; 613 QStringList als;
609 OPimNotifyManager::Alarms::Iterator it = alarms.begin(); 614 OPimNotifyManager::Alarms::Iterator it = alarms.begin();
610 for ( ; it != alarms.end(); ++it ) { 615 for ( ; it != alarms.end(); ++it ) {
611 /* only if time is valid */ 616 /* only if time is valid */
612 if ( (*it).dateTime().isValid() ) { 617 if ( (*it).dateTime().isValid() ) {
613 als << OPimDateConversion::dateTimeToString( (*it).dateTime() ) 618 als << OPimDateConversion::dateTimeToString( (*it).dateTime() )
614 + ":" + QString::number( (*it).duration() ) 619 + ":" + QString::number( (*it).duration() )
615 + ":" + QString::number( (*it).sound() ) 620 + ":" + QString::number( (*it).sound() )
616 + ":"; 621 + ":";
617 } 622 }
618 } 623 }
619 // now write the list 624 // now write the list
620 qWarning("als: %s", als.join("____________").latin1() ); 625 owarn << "als: " << als.join("____________") << "" << oendl;
621 str += "Alarms=\""+als.join(";") +"\" "; 626 str += "Alarms=\""+als.join(";") +"\" ";
622 } 627 }
623 628
624 /* 629 /*
625 * now the same for reminders but more easy. We just save the uid of the OPimEvent. 630 * now the same for reminders but more easy. We just save the uid of the OPimEvent.
626 */ 631 */
627 OPimNotifyManager::Reminders reminders = manager.reminders(); 632 OPimNotifyManager::Reminders reminders = manager.reminders();
628 if (!reminders.isEmpty() ) { 633 if (!reminders.isEmpty() ) {
629 OPimNotifyManager::Reminders::Iterator it = reminders.begin(); 634 OPimNotifyManager::Reminders::Iterator it = reminders.begin();
630 QStringList records; 635 QStringList records;
631 for ( ; it != reminders.end(); ++it ) { 636 for ( ; it != reminders.end(); ++it ) {
632 records << QString::number( (*it).recordUid() ); 637 records << QString::number( (*it).recordUid() );
633 } 638 }
634 str += "Reminders=\""+ records.join(";") +"\" "; 639 str += "Reminders=\""+ records.join(";") +"\" ";
635 } 640 }
636 } 641 }
637 str += customToXml( ev.toExtraMap() ); 642 str += customToXml( ev.toExtraMap() );
638 643
639 644
640 return str; 645 return str;
641} 646}
642QString OPimTodoAccessXML::toString( const QArray<int>& ints ) const { 647QString OPimTodoAccessXML::toString( const QArray<int>& ints ) const {
643 return Qtopia::Record::idsToString( ints ); 648 return Qtopia::Record::idsToString( ints );
644} 649}
645 650
646/* internal class for sorting 651/* internal class for sorting
647 * 652 *
648 * Inspired by todoxmlio.cpp from TT 653 * Inspired by todoxmlio.cpp from TT
649 */ 654 */
650 655
651struct OPimTodoXMLContainer { 656struct OPimTodoXMLContainer {
652 OPimTodo todo; 657 OPimTodo todo;
653}; 658};
654 659
655namespace { 660namespace {
656 inline QString string( const OPimTodo& todo) { 661 inline QString string( const OPimTodo& todo) {
657 return todo.summary().isEmpty() ? 662 return todo.summary().isEmpty() ?
658 todo.description().left(20 ) : 663 todo.description().left(20 ) :
659 todo.summary(); 664 todo.summary();
660 } 665 }
661 inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) { 666 inline int completed( const OPimTodo& todo1, const OPimTodo& todo2) {
662 int ret = 0; 667 int ret = 0;
663 if ( todo1.isCompleted() ) ret++; 668 if ( todo1.isCompleted() ) ret++;
664 if ( todo2.isCompleted() ) ret--; 669 if ( todo2.isCompleted() ) ret--;
665 return ret; 670 return ret;
666 } 671 }
667 inline int priority( const OPimTodo& t1, const OPimTodo& t2) { 672 inline int priority( const OPimTodo& t1, const OPimTodo& t2) {
668 return ( t1.priority() - t2.priority() ); 673 return ( t1.priority() - t2.priority() );
669 } 674 }
670 inline int description( const OPimTodo& t1, const OPimTodo& t2) { 675 inline int description( const OPimTodo& t1, const OPimTodo& t2) {
671 return QString::compare( string(t1), string(t2) ); 676 return QString::compare( string(t1), string(t2) );
672 } 677 }
673 inline int deadline( const OPimTodo& t1, const OPimTodo& t2) { 678 inline int deadline( const OPimTodo& t1, const OPimTodo& t2) {
674 int ret = 0; 679 int ret = 0;
675 if ( t1.hasDueDate() && 680 if ( t1.hasDueDate() &&
676 t2.hasDueDate() ) 681 t2.hasDueDate() )
677 ret = t2.dueDate().daysTo( t1.dueDate() ); 682 ret = t2.dueDate().daysTo( t1.dueDate() );
678 else if ( t1.hasDueDate() ) 683 else if ( t1.hasDueDate() )
679 ret = -1; 684 ret = -1;
680 else if ( t2.hasDueDate() ) 685 else if ( t2.hasDueDate() )
681 ret = 1; 686 ret = 1;
682 else 687 else
683 ret = 0; 688 ret = 0;
684 689
685 return ret; 690 return ret;
686 } 691 }
687 692
688}; 693};
689 694
690/* 695/*
691 * Returns: 696 * Returns:
692 * 0 if item1 == item2 697 * 0 if item1 == item2
693 * 698 *
694 * non-zero if item1 != item2 699 * non-zero if item1 != item2
695 * 700 *
696 * This function returns int rather than bool so that reimplementations 701 * This function returns int rather than bool so that reimplementations
697 * can return one of three values and use it to sort by: 702 * can return one of three values and use it to sort by:
698 * 703 *
699 * 0 if item1 == item2 704 * 0 if item1 == item2
700 * 705 *
701 * > 0 (positive integer) if item1 > item2 706 * > 0 (positive integer) if item1 > item2
702 * 707 *
703 * < 0 (negative integer) if item1 < item2 708 * < 0 (negative integer) if item1 < item2
704 * 709 *
705 */ 710 */
706class OPimTodoXMLVector : public QVector<OPimTodoXMLContainer> { 711class OPimTodoXMLVector : public QVector<OPimTodoXMLContainer> {
707public: 712public:
708 OPimTodoXMLVector(int size, bool asc, int sort) 713 OPimTodoXMLVector(int size, bool asc, int sort)
709 : QVector<OPimTodoXMLContainer>( size ) 714 : QVector<OPimTodoXMLContainer>( size )
710 { 715 {
711 setAutoDelete( true ); 716 setAutoDelete( true );
712 m_asc = asc; 717 m_asc = asc;
713 m_sort = sort; 718 m_sort = sort;
714 } 719 }
715 /* return the summary/description */ 720 /* return the summary/description */
716 QString string( const OPimTodo& todo) { 721 QString string( const OPimTodo& todo) {
717 return todo.summary().isEmpty() ? 722 return todo.summary().isEmpty() ?
718 todo.description().left(20 ) : 723 todo.description().left(20 ) :
719 todo.summary(); 724 todo.summary();
720 } 725 }
721 /** 726 /**
722 * we take the sortorder( switch on it ) 727 * we take the sortorder( switch on it )
723 * 728 *
724 */ 729 */
725 int compareItems( Item d1, Item d2 ) { 730 int compareItems( Item d1, Item d2 ) {
726 bool seComp, sePrio, seDesc, seDeadline; 731 bool seComp, sePrio, seDesc, seDeadline;
727 seComp = sePrio = seDeadline = seDesc = false; 732 seComp = sePrio = seDeadline = seDesc = false;
728 int ret =0; 733 int ret =0;
729 OPimTodoXMLContainer* con1 = (OPimTodoXMLContainer*)d1; 734 OPimTodoXMLContainer* con1 = (OPimTodoXMLContainer*)d1;
730 OPimTodoXMLContainer* con2 = (OPimTodoXMLContainer*)d2; 735 OPimTodoXMLContainer* con2 = (OPimTodoXMLContainer*)d2;
731 736
732 /* same item */ 737 /* same item */
733 if ( con1->todo.uid() == con2->todo.uid() ) 738 if ( con1->todo.uid() == con2->todo.uid() )
734 return 0; 739 return 0;
735 740
736 switch ( m_sort ) { 741 switch ( m_sort ) {
737 /* completed */ 742 /* completed */
738 case 0: { 743 case 0: {
739 ret = completed( con1->todo, con2->todo ); 744 ret = completed( con1->todo, con2->todo );
740 seComp = TRUE; 745 seComp = TRUE;
741 break; 746 break;
742 } 747 }
743 /* priority */ 748 /* priority */
744 case 1: { 749 case 1: {
745 ret = priority( con1->todo, con2->todo ); 750 ret = priority( con1->todo, con2->todo );
746 sePrio = TRUE; 751 sePrio = TRUE;
747 break; 752 break;
748 } 753 }
749 /* description */ 754 /* description */
750 case 2: { 755 case 2: {
751 ret = description( con1->todo, con2->todo ); 756 ret = description( con1->todo, con2->todo );
752 seDesc = TRUE; 757 seDesc = TRUE;
753 break; 758 break;
754 } 759 }
755 /* deadline */ 760 /* deadline */
756 case 3: { 761 case 3: {
757 ret = deadline( con1->todo, con2->todo ); 762 ret = deadline( con1->todo, con2->todo );
758 seDeadline = TRUE; 763 seDeadline = TRUE;
759 break; 764 break;
760 } 765 }
761 default: 766 default:
762 ret = 0; 767 ret = 0;
763 break; 768 break;
764 }; 769 };
765 /* 770 /*
766 * FIXME do better sorting if the first sort criteria 771 * FIXME do better sorting if the first sort criteria
767 * ret equals 0 start with complete and so on... 772 * ret equals 0 start with complete and so on...
768 */ 773 */
769 774
770 /* twist it we're not ascending*/ 775 /* twist it we're not ascending*/
771 if (!m_asc) 776 if (!m_asc)
772 ret = ret * -1; 777 ret = ret * -1;
773 778
774 if ( ret ) 779 if ( ret )
775 return ret; 780 return ret;
776 781
777 // default did not gave difference let's try it other way around 782 // default did not gave difference let's try it other way around
778 /* 783 /*
779 * General try if already checked if not test 784 * General try if already checked if not test
780 * and return 785 * and return
781 * 1.Completed 786 * 1.Completed
782 * 2.Priority 787 * 2.Priority
783 * 3.Description 788 * 3.Description
784 * 4.DueDate 789 * 4.DueDate
785 */ 790 */
786 if (!seComp ) { 791 if (!seComp ) {
787 if ( (ret = completed( con1->todo, con2->todo ) ) ) { 792 if ( (ret = completed( con1->todo, con2->todo ) ) ) {
788 if (!m_asc ) ret *= -1; 793 if (!m_asc ) ret *= -1;
789 return ret; 794 return ret;
790 } 795 }
791 } 796 }
792 if (!sePrio ) { 797 if (!sePrio ) {
793 if ( (ret = priority( con1->todo, con2->todo ) ) ) { 798 if ( (ret = priority( con1->todo, con2->todo ) ) ) {
794 if (!m_asc ) ret *= -1; 799 if (!m_asc ) ret *= -1;
795 return ret; 800 return ret;
796 } 801 }
797 } 802 }
798 if (!seDesc ) { 803 if (!seDesc ) {
799 if ( (ret = description(con1->todo, con2->todo ) ) ) { 804 if ( (ret = description(con1->todo, con2->todo ) ) ) {
800 if (!m_asc) ret *= -1; 805 if (!m_asc) ret *= -1;
801 return ret; 806 return ret;
802 } 807 }
803 } 808 }
804 if (!seDeadline) { 809 if (!seDeadline) {
805 if ( (ret = deadline( con1->todo, con2->todo ) ) ) { 810 if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
806 if (!m_asc) ret *= -1; 811 if (!m_asc) ret *= -1;
807 return ret; 812 return ret;
808 } 813 }
809 } 814 }
810 815
811 return 0; 816 return 0;
812 } 817 }
813 private: 818 private:
814 bool m_asc; 819 bool m_asc;
815 int m_sort; 820 int m_sort;
816 821
817}; 822};
818 823
819QArray<int> OPimTodoAccessXML::sorted( bool asc, int sortOrder, 824QArray<int> OPimTodoAccessXML::sorted( bool asc, int sortOrder,
820 int sortFilter, int cat ) { 825 int sortFilter, int cat ) {
821 OPimTodoXMLVector vector(m_events.count(), asc,sortOrder ); 826 OPimTodoXMLVector vector(m_events.count(), asc,sortOrder );
822 QMap<int, OPimTodo>::Iterator it; 827 QMap<int, OPimTodo>::Iterator it;
823 int item = 0; 828 int item = 0;
824 829
825 bool bCat = sortFilter & 1 ? true : false; 830 bool bCat = sortFilter & 1 ? true : false;
826 bool bOnly = sortFilter & 2 ? true : false; 831 bool bOnly = sortFilter & 2 ? true : false;
827 bool comp = sortFilter & 4 ? true : false; 832 bool comp = sortFilter & 4 ? true : false;
828 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 833 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
829 834
830 /* show category */ 835 /* show category */
831 /* -1 == unfiled */ 836 /* -1 == unfiled */
832 if ( bCat && cat == -1 ) { 837 if ( bCat && cat == -1 ) {
833 if(!(*it).categories().isEmpty() ) 838 if(!(*it).categories().isEmpty() )
834 continue; 839 continue;
835 }else if ( bCat && cat != 0) 840 }else if ( bCat && cat != 0)
836 if (!(*it).categories().contains( cat ) ) { 841 if (!(*it).categories().contains( cat ) ) {
837 continue; 842 continue;
838 } 843 }
839 /* isOverdue but we should not show overdue - why?*/ 844 /* isOverdue but we should not show overdue - why?*/
840/* if ( (*it).isOverdue() && !bOnly ) { 845/* if ( (*it).isOverdue() && !bOnly ) {
841 qWarning("item is overdue but !bOnly"); 846 owarn << "item is overdue but !bOnly" << oendl;
842 continue; 847 continue;
843 } 848 }
844*/ 849*/
845 if ( !(*it).isOverdue() && bOnly ) { 850 if ( !(*it).isOverdue() && bOnly ) {
846 continue; 851 continue;
847 } 852 }
848 853
849 if ((*it).isCompleted() && comp ) { 854 if ((*it).isCompleted() && comp ) {
850 continue; 855 continue;
851 } 856 }
852 857
853 858
854 OPimTodoXMLContainer* con = new OPimTodoXMLContainer(); 859 OPimTodoXMLContainer* con = new OPimTodoXMLContainer();
855 con->todo = (*it); 860 con->todo = (*it);
856 vector.insert(item, con ); 861 vector.insert(item, con );
857 item++; 862 item++;
858 } 863 }
859 vector.resize( item ); 864 vector.resize( item );
860 /* sort it now */ 865 /* sort it now */
861 vector.sort(); 866 vector.sort();
862 /* now get the uids */ 867 /* now get the uids */
863 QArray<int> array( vector.count() ); 868 QArray<int> array( vector.count() );
864 for (uint i= 0; i < vector.count(); i++ ) { 869 for (uint i= 0; i < vector.count(); i++ ) {
865 array[i] = ( vector.at(i) )->todo.uid(); 870 array[i] = ( vector.at(i) )->todo.uid();
866 } 871 }
867 return array; 872 return array;
868}; 873};
869void OPimTodoAccessXML::removeAllCompleted() { 874void OPimTodoAccessXML::removeAllCompleted() {
870 QMap<int, OPimTodo> events = m_events; 875 QMap<int, OPimTodo> events = m_events;
871 for ( QMap<int, OPimTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { 876 for ( QMap<int, OPimTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
872 if ( (*it).isCompleted() ) 877 if ( (*it).isCompleted() )
873 events.remove( it.key() ); 878 events.remove( it.key() );
874 } 879 }
875 m_events = events; 880 m_events = events;
876} 881}
877QBitArray OPimTodoAccessXML::supports()const { 882QBitArray OPimTodoAccessXML::supports()const {
878 static QBitArray ar = sup(); 883 static QBitArray ar = sup();
879 return ar; 884 return ar;
880} 885}
881QBitArray OPimTodoAccessXML::sup() { 886QBitArray OPimTodoAccessXML::sup() {
882 QBitArray ar( OPimTodo::CompletedDate +1 ); 887 QBitArray ar( OPimTodo::CompletedDate +1 );
883 ar.fill( true ); 888 ar.fill( true );
884 ar[OPimTodo::CrossReference] = false; 889 ar[OPimTodo::CrossReference] = false;
885 ar[OPimTodo::State ] = false; 890 ar[OPimTodo::State ] = false;
886 ar[OPimTodo::Reminders] = false; 891 ar[OPimTodo::Reminders] = false;
887 ar[OPimTodo::Notifiers] = false; 892 ar[OPimTodo::Notifiers] = false;
888 ar[OPimTodo::Maintainer] = false; 893 ar[OPimTodo::Maintainer] = false;
889 894
890 return ar; 895 return ar;
891} 896}
892QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const 897QArray<int> OPimTodoAccessXML::matchRegexp( const QRegExp &r ) const
893{ 898{
894 QArray<int> m_currentQuery( m_events.count() ); 899 QArray<int> m_currentQuery( m_events.count() );
895 uint arraycounter = 0; 900 uint arraycounter = 0;
896 901
897 QMap<int, OPimTodo>::ConstIterator it; 902 QMap<int, OPimTodo>::ConstIterator it;
898 for (it = m_events.begin(); it != m_events.end(); ++it ) { 903 for (it = m_events.begin(); it != m_events.end(); ++it ) {
899 if ( it.data().match( r ) ) 904 if ( it.data().match( r ) )
900 m_currentQuery[arraycounter++] = it.data().uid(); 905 m_currentQuery[arraycounter++] = it.data().uid();
901 906
902 } 907 }
903 // Shrink to fit.. 908 // Shrink to fit..
904 m_currentQuery.resize(arraycounter); 909 m_currentQuery.resize(arraycounter);
905 910
906 return m_currentQuery; 911 return m_currentQuery;
907} 912}
908 913
909} 914}
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index c1e06c8..48a74d0 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -1,345 +1,347 @@
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#define QTOPIA_INTERNAL_CONTACT_MRE 30#define QTOPIA_INTERNAL_CONTACT_MRE
31 31
32#include "opimcontact.h" 32#include "opimcontact.h"
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/opimresolver.h> 35#include <opie2/opimresolver.h>
36#include <opie2/opimdateconversion.h> 36#include <opie2/opimdateconversion.h>
37#include <opie2/odebug.h>
38
37#include <qpe/stringutil.h> 39#include <qpe/stringutil.h>
38#include <qpe/timestring.h> 40#include <qpe/timestring.h>
39#include <qpe/config.h> 41#include <qpe/config.h>
40 42
41/* QT */ 43/* QT */
42#include <qstylesheet.h> 44#include <qstylesheet.h>
43 45
44/* STD */ 46/* STD */
45#include <stdio.h> 47#include <stdio.h>
46 48
47/*! 49/*!
48 \class Contact contact.h 50 \class Contact contact.h
49 \brief The Contact class holds the data of an address book entry. 51 \brief The Contact class holds the data of an address book entry.
50 52
51 This data includes information the name of the person, contact 53 This data includes information the name of the person, contact
52 information, and business information such as deparment and job title. 54 information, and business information such as deparment and job title.
53 55
54 \ingroup qtopiaemb 56 \ingroup qtopiaemb
55 \ingroup qtopiadesktop 57 \ingroup qtopiadesktop
56*/ 58*/
57 59
58 60
59namespace Opie 61namespace Opie
60{ 62{
61/*! 63/*!
62 Creates a new, empty contact. 64 Creates a new, empty contact.
63*/ 65*/
64OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 ) 66OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
65{} 67{}
66 68
67/*! 69/*!
68 \internal 70 \internal
69 Creates a new contact. The properties of the contact are 71 Creates a new contact. The properties of the contact are
70 set from \a fromMap. 72 set from \a fromMap.
71*/ 73*/
72OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 ) 74OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 )
73{ 75{
74 QString cats = mMap[ Qtopia::AddressCategory ]; 76 QString cats = mMap[ Qtopia::AddressCategory ];
75 if ( !cats.isEmpty() ) 77 if ( !cats.isEmpty() )
76 setCategories( idsFromString( cats ) ); 78 setCategories( idsFromString( cats ) );
77 79
78 QString uidStr = find( Qtopia::AddressUid ); 80 QString uidStr = find( Qtopia::AddressUid );
79 81
80 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) 82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
81 { 83 {
82 qWarning( "Invalid UID found. Generate new one.." ); 84 owarn << "Invalid UID found. Generate new one.." << oendl;
83 setUid( uidGen().generate() ); 85 setUid( uidGen().generate() );
84 } 86 }
85 else 87 else
86 setUid( uidStr.toInt() ); 88 setUid( uidStr.toInt() );
87 89
88 // if ( !uidStr.isEmpty() ) 90 // if ( !uidStr.isEmpty() )
89 // setUid( uidStr.toInt() ); 91 // setUid( uidStr.toInt() );
90} 92}
91 93
92/*! 94/*!
93 Destroys a contact. 95 Destroys a contact.
94*/ 96*/
95OPimContact::~OPimContact() 97OPimContact::~OPimContact()
96{} 98{}
97 99
98/*! \fn void OPimContact::setTitle( const QString &str ) 100/*! \fn void OPimContact::setTitle( const QString &str )
99 Sets the title of the contact to \a str. 101 Sets the title of the contact to \a str.
100*/ 102*/
101 103
102/*! \fn void OPimContact::setFirstName( const QString &str ) 104/*! \fn void OPimContact::setFirstName( const QString &str )
103 Sets the first name of the contact to \a str. 105 Sets the first name of the contact to \a str.
104*/ 106*/
105 107
106/*! \fn void OPimContact::setMiddleName( const QString &str ) 108/*! \fn void OPimContact::setMiddleName( const QString &str )
107 Sets the middle name of the contact to \a str. 109 Sets the middle name of the contact to \a str.
108*/ 110*/
109 111
110/*! \fn void OPimContact::setLastName( const QString &str ) 112/*! \fn void OPimContact::setLastName( const QString &str )
111 Sets the last name of the contact to \a str. 113 Sets the last name of the contact to \a str.
112*/ 114*/
113 115
114/*! \fn void OPimContact::setSuffix( const QString &str ) 116/*! \fn void OPimContact::setSuffix( const QString &str )
115 Sets the suffix of the contact to \a str. 117 Sets the suffix of the contact to \a str.
116*/ 118*/
117 119
118/*! \fn void OPimContact::setFileAs( const QString &str ) 120/*! \fn void OPimContact::setFileAs( const QString &str )
119 Sets the contact to filed as \a str. 121 Sets the contact to filed as \a str.
120*/ 122*/
121 123
122/*! \fn void OPimContact::setDefaultEmail( const QString &str ) 124/*! \fn void OPimContact::setDefaultEmail( const QString &str )
123 Sets the default email of the contact to \a str. 125 Sets the default email of the contact to \a str.
124*/ 126*/
125 127
126/*! \fn void OPimContact::setHomeStreet( const QString &str ) 128/*! \fn void OPimContact::setHomeStreet( const QString &str )
127 Sets the home street address of the contact to \a str. 129 Sets the home street address of the contact to \a str.
128*/ 130*/
129 131
130/*! \fn void OPimContact::setHomeCity( const QString &str ) 132/*! \fn void OPimContact::setHomeCity( const QString &str )
131 Sets the home city of the contact to \a str. 133 Sets the home city of the contact to \a str.
132*/ 134*/
133 135
134/*! \fn void OPimContact::setHomeState( const QString &str ) 136/*! \fn void OPimContact::setHomeState( const QString &str )
135 Sets the home state of the contact to \a str. 137 Sets the home state of the contact to \a str.
136*/ 138*/
137 139
138/*! \fn void OPimContact::setHomeZip( const QString &str ) 140/*! \fn void OPimContact::setHomeZip( const QString &str )
139 Sets the home zip code of the contact to \a str. 141 Sets the home zip code of the contact to \a str.
140*/ 142*/
141 143
142/*! \fn void OPimContact::setHomeCountry( const QString &str ) 144/*! \fn void OPimContact::setHomeCountry( const QString &str )
143 Sets the home country of the contact to \a str. 145 Sets the home country of the contact to \a str.
144*/ 146*/
145 147
146/*! \fn void OPimContact::setHomePhone( const QString &str ) 148/*! \fn void OPimContact::setHomePhone( const QString &str )
147 Sets the home phone number of the contact to \a str. 149 Sets the home phone number of the contact to \a str.
148*/ 150*/
149 151
150/*! \fn void OPimContact::setHomeFax( const QString &str ) 152/*! \fn void OPimContact::setHomeFax( const QString &str )
151 Sets the home fax number of the contact to \a str. 153 Sets the home fax number of the contact to \a str.
152*/ 154*/
153 155
154/*! \fn void OPimContact::setHomeMobile( const QString &str ) 156/*! \fn void OPimContact::setHomeMobile( const QString &str )
155 Sets the home mobile phone number of the contact to \a str. 157 Sets the home mobile phone number of the contact to \a str.
156*/ 158*/
157 159
158/*! \fn void OPimContact::setHomeWebpage( const QString &str ) 160/*! \fn void OPimContact::setHomeWebpage( const QString &str )
159 Sets the home webpage of the contact to \a str. 161 Sets the home webpage of the contact to \a str.
160*/ 162*/
161 163
162/*! \fn void OPimContact::setCompany( const QString &str ) 164/*! \fn void OPimContact::setCompany( const QString &str )
163 Sets the company for contact to \a str. 165 Sets the company for contact to \a str.
164*/ 166*/
165 167
166/*! \fn void OPimContact::setJobTitle( const QString &str ) 168/*! \fn void OPimContact::setJobTitle( const QString &str )
167 Sets the job title of the contact to \a str. 169 Sets the job title of the contact to \a str.
168*/ 170*/
169 171
170/*! \fn void OPimContact::setDepartment( const QString &str ) 172/*! \fn void OPimContact::setDepartment( const QString &str )
171 Sets the department for contact to \a str. 173 Sets the department for contact to \a str.
172*/ 174*/
173 175
174/*! \fn void OPimContact::setOffice( const QString &str ) 176/*! \fn void OPimContact::setOffice( const QString &str )
175 Sets the office for contact to \a str. 177 Sets the office for contact to \a str.
176*/ 178*/
177 179
178/*! \fn void OPimContact::setBusinessStreet( const QString &str ) 180/*! \fn void OPimContact::setBusinessStreet( const QString &str )
179 Sets the business street address of the contact to \a str. 181 Sets the business street address of the contact to \a str.
180*/ 182*/
181 183
182/*! \fn void OPimContact::setBusinessCity( const QString &str ) 184/*! \fn void OPimContact::setBusinessCity( const QString &str )
183 Sets the business city of the contact to \a str. 185 Sets the business city of the contact to \a str.
184*/ 186*/
185 187
186/*! \fn void OPimContact::setBusinessState( const QString &str ) 188/*! \fn void OPimContact::setBusinessState( const QString &str )
187 Sets the business state of the contact to \a str. 189 Sets the business state of the contact to \a str.
188*/ 190*/
189 191
190/*! \fn void OPimContact::setBusinessZip( const QString &str ) 192/*! \fn void OPimContact::setBusinessZip( const QString &str )
191 Sets the business zip code of the contact to \a str. 193 Sets the business zip code of the contact to \a str.
192*/ 194*/
193 195
194/*! \fn void OPimContact::setBusinessCountry( const QString &str ) 196/*! \fn void OPimContact::setBusinessCountry( const QString &str )
195 Sets the business country of the contact to \a str. 197 Sets the business country of the contact to \a str.
196*/ 198*/
197 199
198/*! \fn void OPimContact::setBusinessPhone( const QString &str ) 200/*! \fn void OPimContact::setBusinessPhone( const QString &str )
199 Sets the business phone number of the contact to \a str. 201 Sets the business phone number of the contact to \a str.
200*/ 202*/
201 203
202/*! \fn void OPimContact::setBusinessFax( const QString &str ) 204/*! \fn void OPimContact::setBusinessFax( const QString &str )
203 Sets the business fax number of the contact to \a str. 205 Sets the business fax number of the contact to \a str.
204*/ 206*/
205 207
206/*! \fn void OPimContact::setBusinessMobile( const QString &str ) 208/*! \fn void OPimContact::setBusinessMobile( const QString &str )
207 Sets the business mobile phone number of the contact to \a str. 209 Sets the business mobile phone number of the contact to \a str.
208*/ 210*/
209 211
210/*! \fn void OPimContact::setBusinessPager( const QString &str ) 212/*! \fn void OPimContact::setBusinessPager( const QString &str )
211 Sets the business pager number of the contact to \a str. 213 Sets the business pager number of the contact to \a str.
212*/ 214*/
213 215
214/*! \fn void OPimContact::setBusinessWebpage( const QString &str ) 216/*! \fn void OPimContact::setBusinessWebpage( const QString &str )
215 Sets the business webpage of the contact to \a str. 217 Sets the business webpage of the contact to \a str.
216*/ 218*/
217 219
218/*! \fn void OPimContact::setProfession( const QString &str ) 220/*! \fn void OPimContact::setProfession( const QString &str )
219 Sets the profession of the contact to \a str. 221 Sets the profession of the contact to \a str.
220*/ 222*/
221 223
222/*! \fn void OPimContact::setAssistant( const QString &str ) 224/*! \fn void OPimContact::setAssistant( const QString &str )
223 Sets the assistant of the contact to \a str. 225 Sets the assistant of the contact to \a str.
224*/ 226*/
225 227
226/*! \fn void OPimContact::setManager( const QString &str ) 228/*! \fn void OPimContact::setManager( const QString &str )
227 Sets the manager of the contact to \a str. 229 Sets the manager of the contact to \a str.
228*/ 230*/
229 231
230/*! \fn void OPimContact::setSpouse( const QString &str ) 232/*! \fn void OPimContact::setSpouse( const QString &str )
231 Sets the spouse of the contact to \a str. 233 Sets the spouse of the contact to \a str.
232*/ 234*/
233 235
234/*! \fn void OPimContact::setGender( const QString &str ) 236/*! \fn void OPimContact::setGender( const QString &str )
235 Sets the gender of the contact to \a str. 237 Sets the gender of the contact to \a str.
236*/ 238*/
237 239
238/*! \fn void OPimContact::setNickname( const QString &str ) 240/*! \fn void OPimContact::setNickname( const QString &str )
239 Sets the nickname of the contact to \a str. 241 Sets the nickname of the contact to \a str.
240*/ 242*/
241 243
242/*! \fn void OPimContact::setNotes( const QString &str ) 244/*! \fn void OPimContact::setNotes( const QString &str )
243 Sets the notes about the contact to \a str. 245 Sets the notes about the contact to \a str.
244*/ 246*/
245 247
246/*! \fn QString OPimContact::title() const 248/*! \fn QString OPimContact::title() const
247 Returns the title of the contact. 249 Returns the title of the contact.
248*/ 250*/
249 251
250/*! \fn QString OPimContact::firstName() const 252/*! \fn QString OPimContact::firstName() const
251 Returns the first name of the contact. 253 Returns the first name of the contact.
252*/ 254*/
253 255
254/*! \fn QString OPimContact::middleName() const 256/*! \fn QString OPimContact::middleName() const
255 Returns the middle name of the contact. 257 Returns the middle name of the contact.
256*/ 258*/
257 259
258/*! \fn QString OPimContact::lastName() const 260/*! \fn QString OPimContact::lastName() const
259 Returns the last name of the contact. 261 Returns the last name of the contact.
260*/ 262*/
261 263
262/*! \fn QString OPimContact::suffix() const 264/*! \fn QString OPimContact::suffix() const
263 Returns the suffix of the contact. 265 Returns the suffix of the contact.
264*/ 266*/
265 267
266/*! \fn QString OPimContact::fileAs() const 268/*! \fn QString OPimContact::fileAs() const
267 Returns the string the contact is filed as. 269 Returns the string the contact is filed as.
268*/ 270*/
269 271
270/*! \fn QString OPimContact::defaultEmail() const 272/*! \fn QString OPimContact::defaultEmail() const
271 Returns the default email address of the contact. 273 Returns the default email address of the contact.
272*/ 274*/
273 275
274/*! \fn QString OPimContact::emails() const 276/*! \fn QString OPimContact::emails() const
275 Returns the list of email address for a contact separated by ';'s in a single 277 Returns the list of email address for a contact separated by ';'s in a single
276 string. 278 string.
277*/ 279*/
278 280
279/*! \fn QString OPimContact::homeStreet() const 281/*! \fn QString OPimContact::homeStreet() const
280 Returns the home street address of the contact. 282 Returns the home street address of the contact.
281*/ 283*/
282 284
283/*! \fn QString OPimContact::homeCity() const 285/*! \fn QString OPimContact::homeCity() const
284 Returns the home city of the contact. 286 Returns the home city of the contact.
285*/ 287*/
286 288
287/*! \fn QString OPimContact::homeState() const 289/*! \fn QString OPimContact::homeState() const
288 Returns the home state of the contact. 290 Returns the home state of the contact.
289*/ 291*/
290 292
291/*! \fn QString OPimContact::homeZip() const 293/*! \fn QString OPimContact::homeZip() const
292 Returns the home zip of the contact. 294 Returns the home zip of the contact.
293*/ 295*/
294 296
295/*! \fn QString OPimContact::homeCountry() const 297/*! \fn QString OPimContact::homeCountry() const
296 Returns the home country of the contact. 298 Returns the home country of the contact.
297*/ 299*/
298 300
299/*! \fn QString OPimContact::homePhone() const 301/*! \fn QString OPimContact::homePhone() const
300 Returns the home phone number of the contact. 302 Returns the home phone number of the contact.
301*/ 303*/
302 304
303/*! \fn QString OPimContact::homeFax() const 305/*! \fn QString OPimContact::homeFax() const
304 Returns the home fax number of the contact. 306 Returns the home fax number of the contact.
305*/ 307*/
306 308
307/*! \fn QString OPimContact::homeMobile() const 309/*! \fn QString OPimContact::homeMobile() const
308 Returns the home mobile number of the contact. 310 Returns the home mobile number of the contact.
309*/ 311*/
310 312
311/*! \fn QString OPimContact::homeWebpage() const 313/*! \fn QString OPimContact::homeWebpage() const
312 Returns the home webpage of the contact. 314 Returns the home webpage of the contact.
313*/ 315*/
314 316
315/*! \fn QString OPimContact::company() const 317/*! \fn QString OPimContact::company() const
316 Returns the company for the contact. 318 Returns the company for the contact.
317*/ 319*/
318 320
319/*! \fn QString OPimContact::department() const 321/*! \fn QString OPimContact::department() const
320 Returns the department for the contact. 322 Returns the department for the contact.
321*/ 323*/
322 324
323/*! \fn QString OPimContact::office() const 325/*! \fn QString OPimContact::office() const
324 Returns the office for the contact. 326 Returns the office for the contact.
325*/ 327*/
326 328
327/*! \fn QString OPimContact::jobTitle() const 329/*! \fn QString OPimContact::jobTitle() const
328 Returns the job title of the contact. 330 Returns the job title of the contact.
329*/ 331*/
330 332
331/*! \fn QString OPimContact::profession() const 333/*! \fn QString OPimContact::profession() const
332 Returns the profession of the contact. 334 Returns the profession of the contact.
333*/ 335*/
334 336
335/*! \fn QString OPimContact::assistant() const 337/*! \fn QString OPimContact::assistant() const
336 Returns the assistant of the contact. 338 Returns the assistant of the contact.
337*/ 339*/
338 340
339/*! \fn QString OPimContact::manager() const 341/*! \fn QString OPimContact::manager() const
340 Returns the manager of the contact. 342 Returns the manager of the contact.
341*/ 343*/
342 344
343/*! \fn QString OPimContact::businessStreet() const 345/*! \fn QString OPimContact::businessStreet() const
344 Returns the business street address of the contact. 346 Returns the business street address of the contact.
345*/ 347*/
@@ -678,612 +680,612 @@ QString OPimContact::toRichText() const
678 if ( !str.isEmpty() ) 680 if ( !str.isEmpty() )
679 { 681 {
680 text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>" 682 text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>"
681 + Qtopia::escapeString( str ); 683 + Qtopia::escapeString( str );
682 marker = true; 684 marker = true;
683 } 685 }
684 str = homeFax(); 686 str = homeFax();
685 if ( !str.isEmpty() ) 687 if ( !str.isEmpty() )
686 { 688 {
687 text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr( "Home Fax: " ) + "</b>" 689 text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr( "Home Fax: " ) + "</b>"
688 + Qtopia::escapeString( str ); 690 + Qtopia::escapeString( str );
689 marker = true; 691 marker = true;
690 } 692 }
691 str = homeMobile(); 693 str = homeMobile();
692 if ( !str.isEmpty() ) 694 if ( !str.isEmpty() )
693 { 695 {
694 text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>" 696 text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>"
695 + Qtopia::escapeString( str ); 697 + Qtopia::escapeString( str );
696 marker = true; 698 marker = true;
697 } 699 }
698 700
699 if ( marker ) 701 if ( marker )
700 text += "<br><hr>"; 702 text += "<br><hr>";
701 703
702 // the rest... 704 // the rest...
703 str = emails(); 705 str = emails();
704 if ( !str.isEmpty() && ( str != defEmail ) ) 706 if ( !str.isEmpty() && ( str != defEmail ) )
705 text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>" 707 text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>"
706 + Qtopia::escapeString( str ); 708 + Qtopia::escapeString( str );
707 str = profession(); 709 str = profession();
708 if ( !str.isEmpty() ) 710 if ( !str.isEmpty() )
709 text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>" 711 text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>"
710 + Qtopia::escapeString( str ); 712 + Qtopia::escapeString( str );
711 str = assistant(); 713 str = assistant();
712 if ( !str.isEmpty() ) 714 if ( !str.isEmpty() )
713 text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>" 715 text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>"
714 + Qtopia::escapeString( str ); 716 + Qtopia::escapeString( str );
715 str = manager(); 717 str = manager();
716 if ( !str.isEmpty() ) 718 if ( !str.isEmpty() )
717 text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>" 719 text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>"
718 + Qtopia::escapeString( str ); 720 + Qtopia::escapeString( str );
719 str = gender(); 721 str = gender();
720 if ( !str.isEmpty() && str.toInt() != 0 ) 722 if ( !str.isEmpty() && str.toInt() != 0 )
721 { 723 {
722 text += "<br>"; 724 text += "<br>";
723 if ( str.toInt() == 1 ) 725 if ( str.toInt() == 1 )
724 str = QObject::tr( "Male" ); 726 str = QObject::tr( "Male" );
725 else if ( str.toInt() == 2 ) 727 else if ( str.toInt() == 2 )
726 str = QObject::tr( "Female" ); 728 str = QObject::tr( "Female" );
727 text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str; 729 text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str;
728 } 730 }
729 str = spouse(); 731 str = spouse();
730 if ( !str.isEmpty() ) 732 if ( !str.isEmpty() )
731 text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>" 733 text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>"
732 + Qtopia::escapeString( str ); 734 + Qtopia::escapeString( str );
733 if ( birthday().isValid() ) 735 if ( birthday().isValid() )
734 { 736 {
735 str = TimeString::numberDateString( birthday() ); 737 str = TimeString::numberDateString( birthday() );
736 text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>" 738 text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>"
737 + Qtopia::escapeString( str ); 739 + Qtopia::escapeString( str );
738 } 740 }
739 if ( anniversary().isValid() ) 741 if ( anniversary().isValid() )
740 { 742 {
741 str = TimeString::numberDateString( anniversary() ); 743 str = TimeString::numberDateString( anniversary() );
742 text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>" 744 text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>"
743 + Qtopia::escapeString( str ); 745 + Qtopia::escapeString( str );
744 } 746 }
745 str = children(); 747 str = children();
746 if ( !str.isEmpty() ) 748 if ( !str.isEmpty() )
747 text += "<br><b>" + QObject::tr( "Children: " ) + "</b>" 749 text += "<br><b>" + QObject::tr( "Children: " ) + "</b>"
748 + Qtopia::escapeString( str ); 750 + Qtopia::escapeString( str );
749 751
750 str = nickname(); 752 str = nickname();
751 if ( !str.isEmpty() ) 753 if ( !str.isEmpty() )
752 text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>" 754 text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>"
753 + Qtopia::escapeString( str ); 755 + Qtopia::escapeString( str );
754 756
755 // categories 757 // categories
756 if ( categoryNames( "Contacts" ).count() ) 758 if ( categoryNames( "Contacts" ).count() )
757 { 759 {
758 text += "<br><b>" + QObject::tr( "Category:" ) + "</b> "; 760 text += "<br><b>" + QObject::tr( "Category:" ) + "</b> ";
759 text += categoryNames( "Contacts" ).join( ", " ); 761 text += categoryNames( "Contacts" ).join( ", " );
760 } 762 }
761 763
762 // notes last 764 // notes last
763 if ( !( value = notes() ).isEmpty() ) 765 if ( !( value = notes() ).isEmpty() )
764 { 766 {
765 text += "<br><hr><b>" + QObject::tr( "Notes:" ) + "</b> "; 767 text += "<br><hr><b>" + QObject::tr( "Notes:" ) + "</b> ";
766 QRegExp reg( "\n" ); 768 QRegExp reg( "\n" );
767 769
768 //QString tmp = Qtopia::escapeString(value); 770 //QString tmp = Qtopia::escapeString(value);
769 QString tmp = QStyleSheet::convertFromPlainText( value ); 771 QString tmp = QStyleSheet::convertFromPlainText( value );
770 //tmp.replace( reg, "<br>" ); 772 //tmp.replace( reg, "<br>" );
771 text += "<br>" + tmp + "<br>"; 773 text += "<br>" + tmp + "<br>";
772 } 774 }
773 return text; 775 return text;
774} 776}
775 777
776/*! 778/*!
777 \internal 779 \internal
778*/ 780*/
779void OPimContact::insert( int key, const QString &v ) 781void OPimContact::insert( int key, const QString &v )
780{ 782{
781 QString value = v.stripWhiteSpace(); 783 QString value = v.stripWhiteSpace();
782 if ( value.isEmpty() ) 784 if ( value.isEmpty() )
783 mMap.remove( key ); 785 mMap.remove( key );
784 else 786 else
785 mMap.insert( key, value ); 787 mMap.insert( key, value );
786} 788}
787 789
788/*! 790/*!
789 \internal 791 \internal
790*/ 792*/
791void OPimContact::replace( int key, const QString & v ) 793void OPimContact::replace( int key, const QString & v )
792{ 794{
793 QString value = v.stripWhiteSpace(); 795 QString value = v.stripWhiteSpace();
794 if ( value.isEmpty() ) 796 if ( value.isEmpty() )
795 mMap.remove( key ); 797 mMap.remove( key );
796 else 798 else
797 mMap.replace( key, value ); 799 mMap.replace( key, value );
798} 800}
799 801
800/*! 802/*!
801 \internal 803 \internal
802*/ 804*/
803QString OPimContact::find( int key ) const 805QString OPimContact::find( int key ) const
804{ 806{
805 return mMap[ key ]; 807 return mMap[ key ];
806} 808}
807 809
808/*! 810/*!
809 \internal 811 \internal
810*/ 812*/
811QString OPimContact::displayAddress( const QString &street, 813QString OPimContact::displayAddress( const QString &street,
812 const QString &city, 814 const QString &city,
813 const QString &state, 815 const QString &state,
814 const QString &zip, 816 const QString &zip,
815 const QString &country ) const 817 const QString &country ) const
816{ 818{
817 QString s = street; 819 QString s = street;
818 if ( !street.isEmpty() ) 820 if ( !street.isEmpty() )
819 s += "\n"; 821 s += "\n";
820 s += city; 822 s += city;
821 if ( !city.isEmpty() && !state.isEmpty() ) 823 if ( !city.isEmpty() && !state.isEmpty() )
822 s += ", "; 824 s += ", ";
823 s += state; 825 s += state;
824 if ( !state.isEmpty() && !zip.isEmpty() ) 826 if ( !state.isEmpty() && !zip.isEmpty() )
825 s += " "; 827 s += " ";
826 s += zip; 828 s += zip;
827 if ( !country.isEmpty() && !s.isEmpty() ) 829 if ( !country.isEmpty() && !s.isEmpty() )
828 s += "\n"; 830 s += "\n";
829 s += country; 831 s += country;
830 return s; 832 return s;
831} 833}
832 834
833/*! 835/*!
834 \internal 836 \internal
835*/ 837*/
836QString OPimContact::displayBusinessAddress() const 838QString OPimContact::displayBusinessAddress() const
837{ 839{
838 return displayAddress( businessStreet(), businessCity(), 840 return displayAddress( businessStreet(), businessCity(),
839 businessState(), businessZip(), 841 businessState(), businessZip(),
840 businessCountry() ); 842 businessCountry() );
841} 843}
842 844
843/*! 845/*!
844 \internal 846 \internal
845*/ 847*/
846QString OPimContact::displayHomeAddress() const 848QString OPimContact::displayHomeAddress() const
847{ 849{
848 return displayAddress( homeStreet(), homeCity(), 850 return displayAddress( homeStreet(), homeCity(),
849 homeState(), homeZip(), 851 homeState(), homeZip(),
850 homeCountry() ); 852 homeCountry() );
851} 853}
852 854
853/*! 855/*!
854 Returns the full name of the contact 856 Returns the full name of the contact
855*/ 857*/
856QString OPimContact::fullName() const 858QString OPimContact::fullName() const
857{ 859{
858 QString title = find( Qtopia::Title ); 860 QString title = find( Qtopia::Title );
859 QString firstName = find( Qtopia::FirstName ); 861 QString firstName = find( Qtopia::FirstName );
860 QString middleName = find( Qtopia::MiddleName ); 862 QString middleName = find( Qtopia::MiddleName );
861 QString lastName = find( Qtopia::LastName ); 863 QString lastName = find( Qtopia::LastName );
862 QString suffix = find( Qtopia::Suffix ); 864 QString suffix = find( Qtopia::Suffix );
863 865
864 QString name = title; 866 QString name = title;
865 if ( !firstName.isEmpty() ) 867 if ( !firstName.isEmpty() )
866 { 868 {
867 if ( !name.isEmpty() ) 869 if ( !name.isEmpty() )
868 name += " "; 870 name += " ";
869 name += firstName; 871 name += firstName;
870 } 872 }
871 if ( !middleName.isEmpty() ) 873 if ( !middleName.isEmpty() )
872 { 874 {
873 if ( !name.isEmpty() ) 875 if ( !name.isEmpty() )
874 name += " "; 876 name += " ";
875 name += middleName; 877 name += middleName;
876 } 878 }
877 if ( !lastName.isEmpty() ) 879 if ( !lastName.isEmpty() )
878 { 880 {
879 if ( !name.isEmpty() ) 881 if ( !name.isEmpty() )
880 name += " "; 882 name += " ";
881 name += lastName; 883 name += lastName;
882 } 884 }
883 if ( !suffix.isEmpty() ) 885 if ( !suffix.isEmpty() )
884 { 886 {
885 if ( !name.isEmpty() ) 887 if ( !name.isEmpty() )
886 name += " "; 888 name += " ";
887 name += suffix; 889 name += suffix;
888 } 890 }
889 return name.simplifyWhiteSpace(); 891 return name.simplifyWhiteSpace();
890} 892}
891 893
892/*! 894/*!
893 Returns a list of the names of the children of the contact. 895 Returns a list of the names of the children of the contact.
894*/ 896*/
895QStringList OPimContact::childrenList() const 897QStringList OPimContact::childrenList() const
896{ 898{
897 return QStringList::split( " ", find( Qtopia::Children ) ); 899 return QStringList::split( " ", find( Qtopia::Children ) );
898} 900}
899 901
900/*! \fn void OPimContact::insertEmail( const QString &email ) 902/*! \fn void OPimContact::insertEmail( const QString &email )
901 903
902 Insert \a email into the email list. Ensures \a email can only be added 904 Insert \a email into the email list. Ensures \a email can only be added
903 once. If there is no default email address set, it sets it to the \a email. 905 once. If there is no default email address set, it sets it to the \a email.
904*/ 906*/
905 907
906/*! \fn void OPimContact::removeEmail( const QString &email ) 908/*! \fn void OPimContact::removeEmail( const QString &email )
907 909
908 Removes the \a email from the email list. If the default email was \a email, 910 Removes the \a email from the email list. If the default email was \a email,
909 then the default email address is assigned to the first email in the 911 then the default email address is assigned to the first email in the
910 email list 912 email list
911*/ 913*/
912 914
913/*! \fn void OPimContact::clearEmails() 915/*! \fn void OPimContact::clearEmails()
914 916
915 Clears the email list. 917 Clears the email list.
916 */ 918 */
917 919
918/*! \fn void OPimContact::insertEmails( const QStringList &emailList ) 920/*! \fn void OPimContact::insertEmails( const QStringList &emailList )
919 921
920 Appends the \a emailList to the exiting email list 922 Appends the \a emailList to the exiting email list
921 */ 923 */
922 924
923/*! 925/*!
924 Returns a list of email addresses belonging to the contact, including 926 Returns a list of email addresses belonging to the contact, including
925 the default email address. 927 the default email address.
926*/ 928*/
927QStringList OPimContact::emailList() const 929QStringList OPimContact::emailList() const
928{ 930{
929 QString emailStr = emails(); 931 QString emailStr = emails();
930 932
931 QStringList r; 933 QStringList r;
932 if ( !emailStr.isEmpty() ) 934 if ( !emailStr.isEmpty() )
933 { 935 {
934 qDebug( " emailstr " ); 936 odebug << " emailstr " << oendl;
935 QStringList l = QStringList::split( emailSeparator(), emailStr ); 937 QStringList l = QStringList::split( emailSeparator(), emailStr );
936 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 938 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
937 r += ( *it ).simplifyWhiteSpace(); 939 r += ( *it ).simplifyWhiteSpace();
938 } 940 }
939 941
940 return r; 942 return r;
941} 943}
942 944
943/*! 945/*!
944 \overload 946 \overload
945 947
946 Generates the string for the contact to be filed as from the first, 948 Generates the string for the contact to be filed as from the first,
947 middle and last name of the contact. 949 middle and last name of the contact.
948*/ 950*/
949void OPimContact::setFileAs() 951void OPimContact::setFileAs()
950{ 952{
951 QString lastName, firstName, middleName, fileas; 953 QString lastName, firstName, middleName, fileas;
952 954
953 lastName = find( Qtopia::LastName ); 955 lastName = find( Qtopia::LastName );
954 firstName = find( Qtopia::FirstName ); 956 firstName = find( Qtopia::FirstName );
955 middleName = find( Qtopia::MiddleName ); 957 middleName = find( Qtopia::MiddleName );
956 if ( !lastName.isEmpty() && !firstName.isEmpty() 958 if ( !lastName.isEmpty() && !firstName.isEmpty()
957 && !middleName.isEmpty() ) 959 && !middleName.isEmpty() )
958 fileas = lastName + ", " + firstName + " " + middleName; 960 fileas = lastName + ", " + firstName + " " + middleName;
959 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 961 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
960 fileas = lastName + ", " + firstName; 962 fileas = lastName + ", " + firstName;
961 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 963 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
962 !middleName.isEmpty() ) 964 !middleName.isEmpty() )
963 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 965 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
964 + middleName + ( middleName.isEmpty() ? "" : " " ) 966 + middleName + ( middleName.isEmpty() ? "" : " " )
965 + lastName; 967 + lastName;
966 968
967 replace( Qtopia::FileAs, fileas ); 969 replace( Qtopia::FileAs, fileas );
968} 970}
969 971
970/*! 972/*!
971 \internal 973 \internal
972 Appends the contact information to \a buf. 974 Appends the contact information to \a buf.
973*/ 975*/
974void OPimContact::save( QString &buf ) const 976void OPimContact::save( QString &buf ) const
975{ 977{
976 static const QStringList SLFIELDS = fields(); 978 static const QStringList SLFIELDS = fields();
977 // I'm expecting "<Contact " in front of this... 979 // I'm expecting "<Contact " in front of this...
978 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 980 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
979 it != mMap.end(); ++it ) 981 it != mMap.end(); ++it )
980 { 982 {
981 const QString &value = it.data(); 983 const QString &value = it.data();
982 int key = it.key(); 984 int key = it.key();
983 if ( !value.isEmpty() ) 985 if ( !value.isEmpty() )
984 { 986 {
985 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid ) 987 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid )
986 continue; 988 continue;
987 989
988 key -= Qtopia::AddressCategory + 1; 990 key -= Qtopia::AddressCategory + 1;
989 buf += SLFIELDS[ key ]; 991 buf += SLFIELDS[ key ];
990 buf += "=\"" + Qtopia::escapeString( value ) + "\" "; 992 buf += "=\"" + Qtopia::escapeString( value ) + "\" ";
991 } 993 }
992 } 994 }
993 buf += customToXml(); 995 buf += customToXml();
994 if ( categories().count() > 0 ) 996 if ( categories().count() > 0 )
995 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 997 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
996 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 998 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
997 // You need to close this yourself 999 // You need to close this yourself
998} 1000}
999 1001
1000 1002
1001/*! 1003/*!
1002 \internal 1004 \internal
1003 Returns the list of fields belonging to a contact 1005 Returns the list of fields belonging to a contact
1004 Never change order of this list ! It has to be regarding 1006 Never change order of this list ! It has to be regarding
1005 enum AddressBookFields !! 1007 enum AddressBookFields !!
1006*/ 1008*/
1007QStringList OPimContact::fields() 1009QStringList OPimContact::fields()
1008{ 1010{
1009 QStringList list; 1011 QStringList list;
1010 1012
1011 list.append( "Title" ); // Not Used! 1013 list.append( "Title" ); // Not Used!
1012 list.append( "FirstName" ); 1014 list.append( "FirstName" );
1013 list.append( "MiddleName" ); 1015 list.append( "MiddleName" );
1014 list.append( "LastName" ); 1016 list.append( "LastName" );
1015 list.append( "Suffix" ); 1017 list.append( "Suffix" );
1016 list.append( "FileAs" ); 1018 list.append( "FileAs" );
1017 1019
1018 list.append( "JobTitle" ); 1020 list.append( "JobTitle" );
1019 list.append( "Department" ); 1021 list.append( "Department" );
1020 list.append( "Company" ); 1022 list.append( "Company" );
1021 list.append( "BusinessPhone" ); 1023 list.append( "BusinessPhone" );
1022 list.append( "BusinessFax" ); 1024 list.append( "BusinessFax" );
1023 list.append( "BusinessMobile" ); 1025 list.append( "BusinessMobile" );
1024 1026
1025 list.append( "DefaultEmail" ); 1027 list.append( "DefaultEmail" );
1026 list.append( "Emails" ); 1028 list.append( "Emails" );
1027 1029
1028 list.append( "HomePhone" ); 1030 list.append( "HomePhone" );
1029 list.append( "HomeFax" ); 1031 list.append( "HomeFax" );
1030 list.append( "HomeMobile" ); 1032 list.append( "HomeMobile" );
1031 1033
1032 list.append( "BusinessStreet" ); 1034 list.append( "BusinessStreet" );
1033 list.append( "BusinessCity" ); 1035 list.append( "BusinessCity" );
1034 list.append( "BusinessState" ); 1036 list.append( "BusinessState" );
1035 list.append( "BusinessZip" ); 1037 list.append( "BusinessZip" );
1036 list.append( "BusinessCountry" ); 1038 list.append( "BusinessCountry" );
1037 list.append( "BusinessPager" ); 1039 list.append( "BusinessPager" );
1038 list.append( "BusinessWebPage" ); 1040 list.append( "BusinessWebPage" );
1039 1041
1040 list.append( "Office" ); 1042 list.append( "Office" );
1041 list.append( "Profession" ); 1043 list.append( "Profession" );
1042 list.append( "Assistant" ); 1044 list.append( "Assistant" );
1043 list.append( "Manager" ); 1045 list.append( "Manager" );
1044 1046
1045 list.append( "HomeStreet" ); 1047 list.append( "HomeStreet" );
1046 list.append( "HomeCity" ); 1048 list.append( "HomeCity" );
1047 list.append( "HomeState" ); 1049 list.append( "HomeState" );
1048 list.append( "HomeZip" ); 1050 list.append( "HomeZip" );
1049 list.append( "HomeCountry" ); 1051 list.append( "HomeCountry" );
1050 list.append( "HomeWebPage" ); 1052 list.append( "HomeWebPage" );
1051 1053
1052 list.append( "Spouse" ); 1054 list.append( "Spouse" );
1053 list.append( "Gender" ); 1055 list.append( "Gender" );
1054 list.append( "Birthday" ); 1056 list.append( "Birthday" );
1055 list.append( "Anniversary" ); 1057 list.append( "Anniversary" );
1056 list.append( "Nickname" ); 1058 list.append( "Nickname" );
1057 list.append( "Children" ); 1059 list.append( "Children" );
1058 1060
1059 list.append( "Notes" ); 1061 list.append( "Notes" );
1060 list.append( "Groups" ); 1062 list.append( "Groups" );
1061 1063
1062 return list; 1064 return list;
1063} 1065}
1064 1066
1065 1067
1066/*! 1068/*!
1067 Sets the list of email address for contact to those contained in \a str. 1069 Sets the list of email address for contact to those contained in \a str.
1068 Email address should be separated by ';'s. 1070 Email address should be separated by ';'s.
1069*/ 1071*/
1070void OPimContact::setEmails( const QString &str ) 1072void OPimContact::setEmails( const QString &str )
1071{ 1073{
1072 replace( Qtopia::Emails, str ); 1074 replace( Qtopia::Emails, str );
1073 if ( str.isEmpty() ) 1075 if ( str.isEmpty() )
1074 setDefaultEmail( QString::null ); 1076 setDefaultEmail( QString::null );
1075} 1077}
1076 1078
1077/*! 1079/*!
1078 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.
1079*/ 1081*/
1080void OPimContact::setChildren( const QString &str ) 1082void OPimContact::setChildren( const QString &str )
1081{ 1083{
1082 replace( Qtopia::Children, str ); 1084 replace( Qtopia::Children, str );
1083} 1085}
1084 1086
1085/*! 1087/*!
1086 \overload 1088 \overload
1087 Returns TRUE if the contact matches the regular expression \a regexp. 1089 Returns TRUE if the contact matches the regular expression \a regexp.
1088 Otherwise returns FALSE. 1090 Otherwise returns FALSE.
1089*/ 1091*/
1090bool OPimContact::match( const QRegExp &r ) const 1092bool OPimContact::match( const QRegExp &r ) const
1091{ 1093{
1092 setLastHitField( -1 ); 1094 setLastHitField( -1 );
1093 bool match; 1095 bool match;
1094 match = false; 1096 match = false;
1095 QMap<int, QString>::ConstIterator it; 1097 QMap<int, QString>::ConstIterator it;
1096 for ( it = mMap.begin(); it != mMap.end(); ++it ) 1098 for ( it = mMap.begin(); it != mMap.end(); ++it )
1097 { 1099 {
1098 if ( ( *it ).find( r ) > -1 ) 1100 if ( ( *it ).find( r ) > -1 )
1099 { 1101 {
1100 setLastHitField( it.key() ); 1102 setLastHitField( it.key() );
1101 match = true; 1103 match = true;
1102 break; 1104 break;
1103 } 1105 }
1104 } 1106 }
1105 return match; 1107 return match;
1106} 1108}
1107 1109
1108 1110
1109QString OPimContact::toShortText() const 1111QString OPimContact::toShortText() const
1110{ 1112{
1111 return ( fullName() ); 1113 return ( fullName() );
1112} 1114}
1113 1115
1114 1116
1115QString OPimContact::type() const 1117QString OPimContact::type() const
1116{ 1118{
1117 return QString::fromLatin1( "OPimContact" ); 1119 return QString::fromLatin1( "OPimContact" );
1118} 1120}
1119 1121
1120 1122
1121class QString OPimContact::recordField( int pos ) const 1123class QString OPimContact::recordField( int pos ) const
1122{ 1124{
1123 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1125 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1124 return SLFIELDS[ pos ]; 1126 return SLFIELDS[ pos ];
1125} 1127}
1126 1128
1127// In future releases, we should store birthday and anniversary 1129// In future releases, we should store birthday and anniversary
1128// internally as QDate instead of QString ! 1130// internally as QDate instead of QString !
1129// 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)
1130 1132
1131/*! \fn void OPimContact::setBirthday( const QDate& date ) 1133/*! \fn void OPimContact::setBirthday( const QDate& date )
1132 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
1133 the current stored date will be removed. 1135 the current stored date will be removed.
1134*/ 1136*/
1135void OPimContact::setBirthday( const QDate &v ) 1137void OPimContact::setBirthday( const QDate &v )
1136{ 1138{
1137 if ( v.isNull() ) 1139 if ( v.isNull() )
1138 { 1140 {
1139 qWarning( "Remove Birthday" ); 1141 owarn << "Remove Birthday" << oendl;
1140 replace( Qtopia::Birthday, QString::null ); 1142 replace( Qtopia::Birthday, QString::null );
1141 return ; 1143 return ;
1142 } 1144 }
1143 1145
1144 if ( v.isValid() ) 1146 if ( v.isValid() )
1145 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) ); 1147 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
1146 1148
1147} 1149}
1148 1150
1149 1151
1150/*! \fn void OPimContact::setAnniversary( const QDate &date ) 1152/*! \fn void OPimContact::setAnniversary( const QDate &date )
1151 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
1152 null, the current stored date will be removed. 1154 null, the current stored date will be removed.
1153*/ 1155*/
1154void OPimContact::setAnniversary( const QDate &v ) 1156void OPimContact::setAnniversary( const QDate &v )
1155{ 1157{
1156 if ( v.isNull() ) 1158 if ( v.isNull() )
1157 { 1159 {
1158 qWarning( "Remove Anniversary" ); 1160 owarn << "Remove Anniversary" << oendl;
1159 replace( Qtopia::Anniversary, QString::null ); 1161 replace( Qtopia::Anniversary, QString::null );
1160 return ; 1162 return ;
1161 } 1163 }
1162 1164
1163 if ( v.isValid() ) 1165 if ( v.isValid() )
1164 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) ); 1166 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
1165} 1167}
1166 1168
1167 1169
1168/*! \fn QDate OPimContact::birthday() const 1170/*! \fn QDate OPimContact::birthday() const
1169 Returns the birthday of the contact. 1171 Returns the birthday of the contact.
1170*/ 1172*/
1171QDate OPimContact::birthday() const 1173QDate OPimContact::birthday() const
1172{ 1174{
1173 QString str = find( Qtopia::Birthday ); 1175 QString str = find( Qtopia::Birthday );
1174 // qWarning ("Birthday %s", str.latin1() ); 1176 // qWarning ("Birthday %s", str.latin1() );
1175 if ( !str.isEmpty() ) 1177 if ( !str.isEmpty() )
1176 return OPimDateConversion::dateFromString ( str ); 1178 return OPimDateConversion::dateFromString ( str );
1177 else 1179 else
1178 return QDate(); 1180 return QDate();
1179} 1181}
1180 1182
1181 1183
1182/*! \fn QDate OPimContact::anniversary() const 1184/*! \fn QDate OPimContact::anniversary() const
1183 Returns the anniversary of the contact. 1185 Returns the anniversary of the contact.
1184*/ 1186*/
1185QDate OPimContact::anniversary() const 1187QDate OPimContact::anniversary() const
1186{ 1188{
1187 QDate empty; 1189 QDate empty;
1188 QString str = find( Qtopia::Anniversary ); 1190 QString str = find( Qtopia::Anniversary );
1189 // qWarning ("Anniversary %s", str.latin1() ); 1191 // qWarning ("Anniversary %s", str.latin1() );
1190 if ( !str.isEmpty() ) 1192 if ( !str.isEmpty() )
1191 return OPimDateConversion::dateFromString ( str ); 1193 return OPimDateConversion::dateFromString ( str );
1192 else 1194 else
1193 return empty; 1195 return empty;
1194} 1196}
1195 1197
1196 1198
1197void OPimContact::insertEmail( const QString &v ) 1199void OPimContact::insertEmail( const QString &v )
1198{ 1200{
1199 //qDebug("insertEmail %s", v.latin1()); 1201 //odebug << "insertEmail " << v << "" << oendl;
1200 QString e = v.simplifyWhiteSpace(); 1202 QString e = v.simplifyWhiteSpace();
1201 QString def = defaultEmail(); 1203 QString def = defaultEmail();
1202 1204
1203 // 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
1204 if ( def.isEmpty() ) 1206 if ( def.isEmpty() )
1205 { 1207 {
1206 setDefaultEmail( e ); // will insert into the list for us 1208 setDefaultEmail( e ); // will insert into the list for us
1207 return ; 1209 return ;
1208 } 1210 }
1209 1211
1210 // otherwise, insert assuming doesn't already exist 1212 // otherwise, insert assuming doesn't already exist
1211 QString emailsStr = find( Qtopia::Emails ); 1213 QString emailsStr = find( Qtopia::Emails );
1212 if ( emailsStr.contains( e ) ) 1214 if ( emailsStr.contains( e ) )
1213 return ; 1215 return ;
1214 if ( !emailsStr.isEmpty() ) 1216 if ( !emailsStr.isEmpty() )
1215 emailsStr += emailSeparator(); 1217 emailsStr += emailSeparator();
1216 emailsStr += e; 1218 emailsStr += e;
1217 replace( Qtopia::Emails, emailsStr ); 1219 replace( Qtopia::Emails, emailsStr );
1218} 1220}
1219 1221
1220 1222
1221 void OPimContact::removeEmail( const QString &v ) 1223 void OPimContact::removeEmail( const QString &v )
1222{ 1224{
1223 QString e = v.simplifyWhiteSpace(); 1225 QString e = v.simplifyWhiteSpace();
1224 QString def = defaultEmail(); 1226 QString def = defaultEmail();
1225 QString emailsStr = find( Qtopia::Emails ); 1227 QString emailsStr = find( Qtopia::Emails );
1226 QStringList emails = emailList(); 1228 QStringList emails = emailList();
1227 1229
1228 // otherwise, must first contain it 1230 // otherwise, must first contain it
1229 if ( !emailsStr.contains( e ) ) 1231 if ( !emailsStr.contains( e ) )
1230 return ; 1232 return ;
1231 1233
1232 // remove it 1234 // remove it
1233 //qDebug(" removing email from list %s", e.latin1()); 1235 //odebug << " removing email from list " << e << "" << oendl;
1234 emails.remove( e ); 1236 emails.remove( e );
1235 // reset the string 1237 // reset the string
1236 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator 1238 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
1237 replace( Qtopia::Emails, emailsStr ); 1239 replace( Qtopia::Emails, emailsStr );
1238 1240
1239 // if default, then replace the default email with the first one 1241 // if default, then replace the default email with the first one
1240 if ( def == e ) 1242 if ( def == e )
1241 { 1243 {
1242 //qDebug("removeEmail is default; setting new default"); 1244 //odebug << "removeEmail is default; setting new default" << oendl;
1243 if ( !emails.count() ) 1245 if ( !emails.count() )
1244 clearEmails(); 1246 clearEmails();
1245 else // setDefaultEmail will remove e from the list 1247 else // setDefaultEmail will remove e from the list
1246 setDefaultEmail( emails.first() ); 1248 setDefaultEmail( emails.first() );
1247 } 1249 }
1248} 1250}
1249 1251
1250 1252
1251void OPimContact::clearEmails() 1253void OPimContact::clearEmails()
1252{ 1254{
1253 mMap.remove( Qtopia::DefaultEmail ); 1255 mMap.remove( Qtopia::DefaultEmail );
1254 mMap.remove( Qtopia::Emails ); 1256 mMap.remove( Qtopia::Emails );
1255} 1257}
1256 1258
1257 1259
1258void OPimContact::setDefaultEmail( const QString &v ) 1260void OPimContact::setDefaultEmail( const QString &v )
1259{ 1261{
1260 QString e = v.simplifyWhiteSpace(); 1262 QString e = v.simplifyWhiteSpace();
1261 1263
1262 //qDebug("OPimContact::setDefaultEmail %s", e.latin1()); 1264 //odebug << "OPimContact::setDefaultEmail " << e << "" << oendl;
1263 replace( Qtopia::DefaultEmail, e ); 1265 replace( Qtopia::DefaultEmail, e );
1264 1266
1265 if ( !e.isEmpty() ) 1267 if ( !e.isEmpty() )
1266 insertEmail( e ); 1268 insertEmail( e );
1267 1269
1268} 1270}
1269 1271
1270 1272
1271void OPimContact::insertEmails( const QStringList &v ) 1273void OPimContact::insertEmails( const QStringList &v )
1272{ 1274{
1273 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1275 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1274 insertEmail( *it ); 1276 insertEmail( *it );
1275} 1277}
1276 1278
1277 1279
1278int OPimContact::rtti() const 1280int OPimContact::rtti() const
1279{ 1281{
1280 return OPimResolver::AddressBook; 1282 return OPimResolver::AddressBook;
1281} 1283}
1282 1284
1283 1285
1284void OPimContact::setUid( int i ) 1286void OPimContact::setUid( int i )
1285{ 1287{
1286 OPimRecord::setUid( i ); 1288 OPimRecord::setUid( i );
1287 replace( Qtopia::AddressUid , QString::number( i ) ); 1289 replace( Qtopia::AddressUid , QString::number( i ) );
1288} 1290}
1289} 1291}
diff --git a/libopie2/opiepim/core/opimcontactfields.cpp b/libopie2/opiepim/core/opimcontactfields.cpp
index 120beb6..5d45d1f 100644
--- a/libopie2/opiepim/core/opimcontactfields.cpp
+++ b/libopie2/opiepim/core/opimcontactfields.cpp
@@ -1,516 +1,518 @@
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#include "opimcontactfields.h" 30#include "opimcontactfields.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimcontact.h> 33#include <opie2/opimcontact.h>
34#include <opie2/odebug.h>
35
34#include <qpe/config.h> 36#include <qpe/config.h>
35 37
36/* QT */ 38/* QT */
37#include <qobject.h> 39#include <qobject.h>
38 40
39 41
40namespace Opie 42namespace Opie
41{ 43{
42/*! 44/*!
43 \internal 45 \internal
44 Returns a list of personal field names for a contact. 46 Returns a list of personal field names for a contact.
45*/ 47*/
46QStringList OPimContactFields::personalfields( bool sorted, bool translated ) 48QStringList OPimContactFields::personalfields( bool sorted, bool translated )
47{ 49{
48 QStringList list; 50 QStringList list;
49 QMap<int, QString> mapIdToStr; 51 QMap<int, QString> mapIdToStr;
50 if ( translated ) 52 if ( translated )
51 mapIdToStr = idToTrFields(); 53 mapIdToStr = idToTrFields();
52 else 54 else
53 mapIdToStr = idToUntrFields(); 55 mapIdToStr = idToUntrFields();
54 56
55 list.append( mapIdToStr[ Qtopia::AddressUid ] ); 57 list.append( mapIdToStr[ Qtopia::AddressUid ] );
56 list.append( mapIdToStr[ Qtopia::AddressCategory ] ); 58 list.append( mapIdToStr[ Qtopia::AddressCategory ] );
57 59
58 list.append( mapIdToStr[ Qtopia::Title ] ); 60 list.append( mapIdToStr[ Qtopia::Title ] );
59 list.append( mapIdToStr[ Qtopia::FirstName ] ); 61 list.append( mapIdToStr[ Qtopia::FirstName ] );
60 list.append( mapIdToStr[ Qtopia::MiddleName ] ); 62 list.append( mapIdToStr[ Qtopia::MiddleName ] );
61 list.append( mapIdToStr[ Qtopia::LastName ] ); 63 list.append( mapIdToStr[ Qtopia::LastName ] );
62 list.append( mapIdToStr[ Qtopia::Suffix ] ); 64 list.append( mapIdToStr[ Qtopia::Suffix ] );
63 list.append( mapIdToStr[ Qtopia::FileAs ] ); 65 list.append( mapIdToStr[ Qtopia::FileAs ] );
64 66
65 list.append( mapIdToStr[ Qtopia::JobTitle ] ); 67 list.append( mapIdToStr[ Qtopia::JobTitle ] );
66 list.append( mapIdToStr[ Qtopia::Department ] ); 68 list.append( mapIdToStr[ Qtopia::Department ] );
67 list.append( mapIdToStr[ Qtopia::Company ] ); 69 list.append( mapIdToStr[ Qtopia::Company ] );
68 70
69 list.append( mapIdToStr[ Qtopia::Notes ] ); 71 list.append( mapIdToStr[ Qtopia::Notes ] );
70 list.append( mapIdToStr[ Qtopia::Groups ] ); 72 list.append( mapIdToStr[ Qtopia::Groups ] );
71 73
72 if ( sorted ) list.sort(); 74 if ( sorted ) list.sort();
73 return list; 75 return list;
74} 76}
75 77
76/*! 78/*!
77 \internal 79 \internal
78 Returns a list of details field names for a contact. 80 Returns a list of details field names for a contact.
79*/ 81*/
80QStringList OPimContactFields::detailsfields( bool sorted, bool translated ) 82QStringList OPimContactFields::detailsfields( bool sorted, bool translated )
81{ 83{
82 QStringList list; 84 QStringList list;
83 QMap<int, QString> mapIdToStr; 85 QMap<int, QString> mapIdToStr;
84 if ( translated ) 86 if ( translated )
85 mapIdToStr = idToTrFields(); 87 mapIdToStr = idToTrFields();
86 else 88 else
87 mapIdToStr = idToUntrFields(); 89 mapIdToStr = idToUntrFields();
88 90
89 list.append( mapIdToStr[ Qtopia::Office ] ); 91 list.append( mapIdToStr[ Qtopia::Office ] );
90 list.append( mapIdToStr[ Qtopia::Profession ] ); 92 list.append( mapIdToStr[ Qtopia::Profession ] );
91 list.append( mapIdToStr[ Qtopia::Assistant ] ); 93 list.append( mapIdToStr[ Qtopia::Assistant ] );
92 list.append( mapIdToStr[ Qtopia::Manager ] ); 94 list.append( mapIdToStr[ Qtopia::Manager ] );
93 95
94 list.append( mapIdToStr[ Qtopia::Spouse ] ); 96 list.append( mapIdToStr[ Qtopia::Spouse ] );
95 list.append( mapIdToStr[ Qtopia::Gender ] ); 97 list.append( mapIdToStr[ Qtopia::Gender ] );
96 list.append( mapIdToStr[ Qtopia::Birthday ] ); 98 list.append( mapIdToStr[ Qtopia::Birthday ] );
97 list.append( mapIdToStr[ Qtopia::Anniversary ] ); 99 list.append( mapIdToStr[ Qtopia::Anniversary ] );
98 list.append( mapIdToStr[ Qtopia::Nickname ] ); 100 list.append( mapIdToStr[ Qtopia::Nickname ] );
99 list.append( mapIdToStr[ Qtopia::Children ] ); 101 list.append( mapIdToStr[ Qtopia::Children ] );
100 102
101 if ( sorted ) list.sort(); 103 if ( sorted ) list.sort();
102 return list; 104 return list;
103} 105}
104 106
105/*! 107/*!
106 \internal 108 \internal
107 Returns a list of phone field names for a contact. 109 Returns a list of phone field names for a contact.
108*/ 110*/
109QStringList OPimContactFields::phonefields( bool sorted, bool translated ) 111QStringList OPimContactFields::phonefields( bool sorted, bool translated )
110{ 112{
111 QStringList list; 113 QStringList list;
112 QMap<int, QString> mapIdToStr; 114 QMap<int, QString> mapIdToStr;
113 if ( translated ) 115 if ( translated )
114 mapIdToStr = idToTrFields(); 116 mapIdToStr = idToTrFields();
115 else 117 else
116 mapIdToStr = idToUntrFields(); 118 mapIdToStr = idToUntrFields();
117 119
118 list.append( mapIdToStr[ Qtopia::BusinessPhone ] ); 120 list.append( mapIdToStr[ Qtopia::BusinessPhone ] );
119 list.append( mapIdToStr[ Qtopia::BusinessFax ] ); 121 list.append( mapIdToStr[ Qtopia::BusinessFax ] );
120 list.append( mapIdToStr[ Qtopia::BusinessMobile ] ); 122 list.append( mapIdToStr[ Qtopia::BusinessMobile ] );
121 list.append( mapIdToStr[ Qtopia::BusinessPager ] ); 123 list.append( mapIdToStr[ Qtopia::BusinessPager ] );
122 list.append( mapIdToStr[ Qtopia::BusinessWebPage ] ); 124 list.append( mapIdToStr[ Qtopia::BusinessWebPage ] );
123 125
124 list.append( mapIdToStr[ Qtopia::DefaultEmail ] ); 126 list.append( mapIdToStr[ Qtopia::DefaultEmail ] );
125 list.append( mapIdToStr[ Qtopia::Emails ] ); 127 list.append( mapIdToStr[ Qtopia::Emails ] );
126 128
127 list.append( mapIdToStr[ Qtopia::HomePhone ] ); 129 list.append( mapIdToStr[ Qtopia::HomePhone ] );
128 list.append( mapIdToStr[ Qtopia::HomeFax ] ); 130 list.append( mapIdToStr[ Qtopia::HomeFax ] );
129 list.append( mapIdToStr[ Qtopia::HomeMobile ] ); 131 list.append( mapIdToStr[ Qtopia::HomeMobile ] );
130 // list.append( mapIdToStr[Qtopia::HomePager] ); 132 // list.append( mapIdToStr[Qtopia::HomePager] );
131 list.append( mapIdToStr[ Qtopia::HomeWebPage ] ); 133 list.append( mapIdToStr[ Qtopia::HomeWebPage ] );
132 134
133 if ( sorted ) list.sort(); 135 if ( sorted ) list.sort();
134 136
135 return list; 137 return list;
136} 138}
137 139
138/*! 140/*!
139 \internal 141 \internal
140 Returns a list of field names for a contact. 142 Returns a list of field names for a contact.
141*/ 143*/
142QStringList OPimContactFields::fields( bool sorted, bool translated ) 144QStringList OPimContactFields::fields( bool sorted, bool translated )
143{ 145{
144 QStringList list; 146 QStringList list;
145 QMap<int, QString> mapIdToStr; 147 QMap<int, QString> mapIdToStr;
146 if ( translated ) 148 if ( translated )
147 mapIdToStr = idToTrFields(); 149 mapIdToStr = idToTrFields();
148 else 150 else
149 mapIdToStr = idToUntrFields(); 151 mapIdToStr = idToUntrFields();
150 152
151 list += personalfields( sorted, translated ); 153 list += personalfields( sorted, translated );
152 154
153 list += phonefields( sorted, translated ); 155 list += phonefields( sorted, translated );
154 156
155 list.append( mapIdToStr[ Qtopia::BusinessStreet ] ); 157 list.append( mapIdToStr[ Qtopia::BusinessStreet ] );
156 list.append( mapIdToStr[ Qtopia::BusinessCity ] ); 158 list.append( mapIdToStr[ Qtopia::BusinessCity ] );
157 list.append( mapIdToStr[ Qtopia::BusinessState ] ); 159 list.append( mapIdToStr[ Qtopia::BusinessState ] );
158 list.append( mapIdToStr[ Qtopia::BusinessZip ] ); 160 list.append( mapIdToStr[ Qtopia::BusinessZip ] );
159 list.append( mapIdToStr[ Qtopia::BusinessCountry ] ); 161 list.append( mapIdToStr[ Qtopia::BusinessCountry ] );
160 162
161 list.append( mapIdToStr[ Qtopia::HomeStreet ] ); 163 list.append( mapIdToStr[ Qtopia::HomeStreet ] );
162 list.append( mapIdToStr[ Qtopia::HomeCity ] ); 164 list.append( mapIdToStr[ Qtopia::HomeCity ] );
163 list.append( mapIdToStr[ Qtopia::HomeState ] ); 165 list.append( mapIdToStr[ Qtopia::HomeState ] );
164 list.append( mapIdToStr[ Qtopia::HomeZip ] ); 166 list.append( mapIdToStr[ Qtopia::HomeZip ] );
165 list.append( mapIdToStr[ Qtopia::HomeCountry ] ); 167 list.append( mapIdToStr[ Qtopia::HomeCountry ] );
166 168
167 list += detailsfields( sorted, translated ); 169 list += detailsfields( sorted, translated );
168 170
169 if ( sorted ) list.sort(); 171 if ( sorted ) list.sort();
170 172
171 return list; 173 return list;
172} 174}
173 175
174 176
175/*! 177/*!
176 \internal 178 \internal
177 Returns an untranslated list of personal field names for a contact. 179 Returns an untranslated list of personal field names for a contact.
178*/ 180*/
179QStringList OPimContactFields::untrpersonalfields( bool sorted ) 181QStringList OPimContactFields::untrpersonalfields( bool sorted )
180{ 182{
181 return personalfields( sorted, false ); 183 return personalfields( sorted, false );
182} 184}
183 185
184 186
185/*! 187/*!
186 \internal 188 \internal
187 Returns a translated list of personal field names for a contact. 189 Returns a translated list of personal field names for a contact.
188*/ 190*/
189QStringList OPimContactFields::trpersonalfields( bool sorted ) 191QStringList OPimContactFields::trpersonalfields( bool sorted )
190{ 192{
191 return personalfields( sorted, true ); 193 return personalfields( sorted, true );
192} 194}
193 195
194 196
195/*! 197/*!
196 \internal 198 \internal
197 Returns an untranslated list of details field names for a contact. 199 Returns an untranslated list of details field names for a contact.
198*/ 200*/
199QStringList OPimContactFields::untrdetailsfields( bool sorted ) 201QStringList OPimContactFields::untrdetailsfields( bool sorted )
200{ 202{
201 return detailsfields( sorted, false ); 203 return detailsfields( sorted, false );
202} 204}
203 205
204 206
205/*! 207/*!
206 \internal 208 \internal
207 Returns a translated list of details field names for a contact. 209 Returns a translated list of details field names for a contact.
208*/ 210*/
209QStringList OPimContactFields::trdetailsfields( bool sorted ) 211QStringList OPimContactFields::trdetailsfields( bool sorted )
210{ 212{
211 return detailsfields( sorted, true ); 213 return detailsfields( sorted, true );
212} 214}
213 215
214 216
215/*! 217/*!
216 \internal 218 \internal
217 Returns a translated list of phone field names for a contact. 219 Returns a translated list of phone field names for a contact.
218*/ 220*/
219QStringList OPimContactFields::trphonefields( bool sorted ) 221QStringList OPimContactFields::trphonefields( bool sorted )
220{ 222{
221 return phonefields( sorted, true ); 223 return phonefields( sorted, true );
222} 224}
223 225
224/*! 226/*!
225 \internal 227 \internal
226 Returns an untranslated list of phone field names for a contact. 228 Returns an untranslated list of phone field names for a contact.
227*/ 229*/
228QStringList OPimContactFields::untrphonefields( bool sorted ) 230QStringList OPimContactFields::untrphonefields( bool sorted )
229{ 231{
230 return phonefields( sorted, false ); 232 return phonefields( sorted, false );
231} 233}
232 234
233 235
234/*! 236/*!
235 \internal 237 \internal
236 Returns a translated list of field names for a contact. 238 Returns a translated list of field names for a contact.
237*/ 239*/
238QStringList OPimContactFields::trfields( bool sorted ) 240QStringList OPimContactFields::trfields( bool sorted )
239{ 241{
240 return fields( sorted, true ); 242 return fields( sorted, true );
241} 243}
242 244
243/*! 245/*!
244 \internal 246 \internal
245 Returns an untranslated list of field names for a contact. 247 Returns an untranslated list of field names for a contact.
246*/ 248*/
247QStringList OPimContactFields::untrfields( bool sorted ) 249QStringList OPimContactFields::untrfields( bool sorted )
248{ 250{
249 return fields( sorted, false ); 251 return fields( sorted, false );
250} 252}
251 253
252QMap<int, QString> OPimContactFields::idToTrFields() 254QMap<int, QString> OPimContactFields::idToTrFields()
253{ 255{
254 QMap<int, QString> ret_map; 256 QMap<int, QString> ret_map;
255 257
256 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) ); 258 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) );
257 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) ); 259 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) );
258 260
259 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title" ) ); 261 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title" ) );
260 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); 262 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) );
261 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); 263 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) );
262 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); 264 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) );
263 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ) ); 265 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ) );
264 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); 266 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) );
265 267
266 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); 268 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) );
267 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); 269 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) );
268 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); 270 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) );
269 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); 271 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) );
270 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); 272 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) );
271 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ) ); 273 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ) );
272 274
273 // email 275 // email
274 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) ); 276 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) );
275 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) ); 277 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) );
276 278
277 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) ); 279 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) );
278 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) ); 280 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) );
279 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) ); 281 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) );
280 282
281 // business 283 // business
282 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) ); 284 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) );
283 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) ); 285 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) );
284 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) ); 286 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) );
285 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) ); 287 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) );
286 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) ); 288 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) );
287 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) ); 289 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) );
288 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) ); 290 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) );
289 291
290 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) ); 292 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) );
291 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) ); 293 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) );
292 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) ); 294 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) );
293 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) ); 295 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) );
294 296
295 // home 297 // home
296 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) ); 298 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) );
297 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) ); 299 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) );
298 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) ); 300 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) );
299 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) ); 301 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) );
300 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) ); 302 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) );
301 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) ); 303 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) );
302 304
303 //personal 305 //personal
304 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) ); 306 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) );
305 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) ); 307 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) );
306 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) ); 308 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) );
307 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) ); 309 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) );
308 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) ); 310 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) );
309 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) ); 311 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) );
310 312
311 // other 313 // other
312 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) ); 314 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) );
313 315
314 316
315 return ret_map; 317 return ret_map;
316} 318}
317 319
318QMap<int, QString> OPimContactFields::idToUntrFields() 320QMap<int, QString> OPimContactFields::idToUntrFields()
319{ 321{
320 QMap<int, QString> ret_map; 322 QMap<int, QString> ret_map;
321 323
322 ret_map.insert( Qtopia::AddressUid, "User Id" ); 324 ret_map.insert( Qtopia::AddressUid, "User Id" );
323 ret_map.insert( Qtopia::AddressCategory, "Categories" ); 325 ret_map.insert( Qtopia::AddressCategory, "Categories" );
324 326
325 ret_map.insert( Qtopia::Title, "Name Title" ); 327 ret_map.insert( Qtopia::Title, "Name Title" );
326 ret_map.insert( Qtopia::FirstName, "First Name" ); 328 ret_map.insert( Qtopia::FirstName, "First Name" );
327 ret_map.insert( Qtopia::MiddleName, "Middle Name" ); 329 ret_map.insert( Qtopia::MiddleName, "Middle Name" );
328 ret_map.insert( Qtopia::LastName, "Last Name" ); 330 ret_map.insert( Qtopia::LastName, "Last Name" );
329 ret_map.insert( Qtopia::Suffix, "Suffix" ); 331 ret_map.insert( Qtopia::Suffix, "Suffix" );
330 ret_map.insert( Qtopia::FileAs, "File As" ); 332 ret_map.insert( Qtopia::FileAs, "File As" );
331 333
332 ret_map.insert( Qtopia::JobTitle, "Job Title" ); 334 ret_map.insert( Qtopia::JobTitle, "Job Title" );
333 ret_map.insert( Qtopia::Department, "Department" ); 335 ret_map.insert( Qtopia::Department, "Department" );
334 ret_map.insert( Qtopia::Company, "Company" ); 336 ret_map.insert( Qtopia::Company, "Company" );
335 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); 337 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" );
336 ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); 338 ret_map.insert( Qtopia::BusinessFax, "Business Fax" );
337 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); 339 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" );
338 340
339 // email 341 // email
340 ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); 342 ret_map.insert( Qtopia::DefaultEmail, "Default Email" );
341 ret_map.insert( Qtopia::Emails, "Emails" ); 343 ret_map.insert( Qtopia::Emails, "Emails" );
342 344
343 ret_map.insert( Qtopia::HomePhone, "Home Phone" ); 345 ret_map.insert( Qtopia::HomePhone, "Home Phone" );
344 ret_map.insert( Qtopia::HomeFax, "Home Fax" ); 346 ret_map.insert( Qtopia::HomeFax, "Home Fax" );
345 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); 347 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" );
346 348
347 // business 349 // business
348 ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); 350 ret_map.insert( Qtopia::BusinessStreet, "Business Street" );
349 ret_map.insert( Qtopia::BusinessCity, "Business City" ); 351 ret_map.insert( Qtopia::BusinessCity, "Business City" );
350 ret_map.insert( Qtopia::BusinessState, "Business State" ); 352 ret_map.insert( Qtopia::BusinessState, "Business State" );
351 ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); 353 ret_map.insert( Qtopia::BusinessZip, "Business Zip" );
352 ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); 354 ret_map.insert( Qtopia::BusinessCountry, "Business Country" );
353 ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); 355 ret_map.insert( Qtopia::BusinessPager, "Business Pager" );
354 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); 356 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" );
355 357
356 ret_map.insert( Qtopia::Office, "Office" ); 358 ret_map.insert( Qtopia::Office, "Office" );
357 ret_map.insert( Qtopia::Profession, "Profession" ); 359 ret_map.insert( Qtopia::Profession, "Profession" );
358 ret_map.insert( Qtopia::Assistant, "Assistant" ); 360 ret_map.insert( Qtopia::Assistant, "Assistant" );
359 ret_map.insert( Qtopia::Manager, "Manager" ); 361 ret_map.insert( Qtopia::Manager, "Manager" );
360 362
361 // home 363 // home
362 ret_map.insert( Qtopia::HomeStreet, "Home Street" ); 364 ret_map.insert( Qtopia::HomeStreet, "Home Street" );
363 ret_map.insert( Qtopia::HomeCity, "Home City" ); 365 ret_map.insert( Qtopia::HomeCity, "Home City" );
364 ret_map.insert( Qtopia::HomeState, "Home State" ); 366 ret_map.insert( Qtopia::HomeState, "Home State" );
365 ret_map.insert( Qtopia::HomeZip, "Home Zip" ); 367 ret_map.insert( Qtopia::HomeZip, "Home Zip" );
366 ret_map.insert( Qtopia::HomeCountry, "Home Country" ); 368 ret_map.insert( Qtopia::HomeCountry, "Home Country" );
367 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); 369 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" );
368 370
369 //personal 371 //personal
370 ret_map.insert( Qtopia::Spouse, "Spouse" ); 372 ret_map.insert( Qtopia::Spouse, "Spouse" );
371 ret_map.insert( Qtopia::Gender, "Gender" ); 373 ret_map.insert( Qtopia::Gender, "Gender" );
372 ret_map.insert( Qtopia::Birthday, "Birthday" ); 374 ret_map.insert( Qtopia::Birthday, "Birthday" );
373 ret_map.insert( Qtopia::Anniversary, "Anniversary" ); 375 ret_map.insert( Qtopia::Anniversary, "Anniversary" );
374 ret_map.insert( Qtopia::Nickname, "Nickname" ); 376 ret_map.insert( Qtopia::Nickname, "Nickname" );
375 ret_map.insert( Qtopia::Children, "Children" ); 377 ret_map.insert( Qtopia::Children, "Children" );
376 378
377 // other 379 // other
378 ret_map.insert( Qtopia::Notes, "Notes" ); 380 ret_map.insert( Qtopia::Notes, "Notes" );
379 ret_map.insert( Qtopia::Groups, "Groups" ); 381 ret_map.insert( Qtopia::Groups, "Groups" );
380 382
381 383
382 return ret_map; 384 return ret_map;
383} 385}
384 386
385QMap<QString, int> OPimContactFields::trFieldsToId() 387QMap<QString, int> OPimContactFields::trFieldsToId()
386{ 388{
387 QMap<int, QString> idtostr = idToTrFields(); 389 QMap<int, QString> idtostr = idToTrFields();
388 QMap<QString, int> ret_map; 390 QMap<QString, int> ret_map;
389 391
390 392
391 QMap<int, QString>::Iterator it; 393 QMap<int, QString>::Iterator it;
392 for ( it = idtostr.begin(); it != idtostr.end(); ++it ) 394 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
393 ret_map.insert( *it, it.key() ); 395 ret_map.insert( *it, it.key() );
394 396
395 397
396 return ret_map; 398 return ret_map;
397} 399}
398 400
399/* ======================================================================= */ 401/* ======================================================================= */
400 402
401QMap<QString, int> OPimContactFields::untrFieldsToId() 403QMap<QString, int> OPimContactFields::untrFieldsToId()
402{ 404{
403 QMap<int, QString> idtostr = idToUntrFields(); 405 QMap<int, QString> idtostr = idToUntrFields();
404 QMap<QString, int> ret_map; 406 QMap<QString, int> ret_map;
405 407
406 408
407 QMap<int, QString>::Iterator it; 409 QMap<int, QString>::Iterator it;
408 for ( it = idtostr.begin(); it != idtostr.end(); ++it ) 410 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
409 ret_map.insert( *it, it.key() ); 411 ret_map.insert( *it, it.key() );
410 412
411 413
412 return ret_map; 414 return ret_map;
413} 415}
414 416
415 417
416OPimContactFields::OPimContactFields() : 418OPimContactFields::OPimContactFields() :
417 fieldOrder( DEFAULT_FIELD_ORDER ), 419 fieldOrder( DEFAULT_FIELD_ORDER ),
418 changedFieldOrder( false ) 420 changedFieldOrder( false )
419{ 421{
420 // Get the global field order from the config file and 422 // Get the global field order from the config file and
421 // use it as a start pattern 423 // use it as a start pattern
422 Config cfg ( "AddressBook" ); 424 Config cfg ( "AddressBook" );
423 cfg.setGroup( "ContactFieldOrder" ); 425 cfg.setGroup( "ContactFieldOrder" );
424 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); 426 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER );
425} 427}
426 428
427OPimContactFields::~OPimContactFields() 429OPimContactFields::~OPimContactFields()
428{ 430{
429 431
430 // We will store the fieldorder into the config file 432 // We will store the fieldorder into the config file
431 // to reuse it for the future.. 433 // to reuse it for the future..
432 if ( changedFieldOrder ) 434 if ( changedFieldOrder )
433 { 435 {
434 Config cfg ( "AddressBook" ); 436 Config cfg ( "AddressBook" );
435 cfg.setGroup( "ContactFieldOrder" ); 437 cfg.setGroup( "ContactFieldOrder" );
436 cfg.writeEntry( "General", globalFieldOrder ); 438 cfg.writeEntry( "General", globalFieldOrder );
437 } 439 }
438} 440}
439 441
440 442
441 443
442void OPimContactFields::saveToRecord( OPimContact &cnt ) 444void OPimContactFields::saveToRecord( OPimContact &cnt )
443{ 445{
444 446
445 qDebug( "ocontactfields saveToRecord: >%s<", fieldOrder.latin1() ); 447 odebug << "ocontactfields saveToRecord: >" << fieldOrder << "<" << oendl;
446 448
447 // Store fieldorder into this contact. 449 // Store fieldorder into this contact.
448 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); 450 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder );
449 451
450 globalFieldOrder = fieldOrder; 452 globalFieldOrder = fieldOrder;
451 changedFieldOrder = true; 453 changedFieldOrder = true;
452 454
453} 455}
454 456
455void OPimContactFields::loadFromRecord( const OPimContact &cnt ) 457void OPimContactFields::loadFromRecord( const OPimContact &cnt )
456{ 458{
457 qDebug( "ocontactfields loadFromRecord" ); 459 odebug << "ocontactfields loadFromRecord" << oendl;
458 qDebug( "loading >%s<", cnt.fullName().latin1() ); 460 odebug << "loading >" << cnt.fullName() << "<" << oendl;
459 461
460 // Get fieldorder for this contact. If none is defined, 462 // Get fieldorder for this contact. If none is defined,
461 // we will use the global one from the config file.. 463 // we will use the global one from the config file..
462 464
463 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); 465 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME );
464 466
465 qDebug( "fieldOrder from contact>%s<", fieldOrder.latin1() ); 467 odebug << "fieldOrder from contact>" << fieldOrder << "<" << oendl;
466 468
467 if ( fieldOrder.isEmpty() ) 469 if ( fieldOrder.isEmpty() )
468 { 470 {
469 fieldOrder = globalFieldOrder; 471 fieldOrder = globalFieldOrder;
470 } 472 }
471 473
472 474
473 qDebug( "effective fieldOrder in loadFromRecord >%s<", fieldOrder.latin1() ); 475 odebug << "effective fieldOrder in loadFromRecord >" << fieldOrder << "<" << oendl;
474} 476}
475 477
476void OPimContactFields::setFieldOrder( int num, int index ) 478void OPimContactFields::setFieldOrder( int num, int index )
477{ 479{
478 qDebug( "qcontactfields setfieldorder pos %i -> %i", num, index ); 480 odebug << "qcontactfields setfieldorder pos " << num << " -> " << index << "" << oendl;
479 481
480 fieldOrder[ num ] = QString::number( index, 16 ) [ 0 ]; 482 fieldOrder[ num ] = QString::number( index, 16 ) [ 0 ];
481 483
482 // We will store this new fieldorder globally to 484 // We will store this new fieldorder globally to
483 // remember it for contacts which have none 485 // remember it for contacts which have none
484 globalFieldOrder = fieldOrder; 486 globalFieldOrder = fieldOrder;
485 changedFieldOrder = true; 487 changedFieldOrder = true;
486 488
487 qDebug( "fieldOrder >%s<", fieldOrder.latin1() ); 489 odebug << "fieldOrder >" << fieldOrder << "<" << oendl;
488} 490}
489 491
490int OPimContactFields::getFieldOrder( int num, int defIndex ) 492int OPimContactFields::getFieldOrder( int num, int defIndex )
491{ 493{
492 qDebug( "ocontactfields getFieldOrder" ); 494 odebug << "ocontactfields getFieldOrder" << oendl;
493 qDebug( "fieldOrder >%s<", fieldOrder.latin1() ); 495 odebug << "fieldOrder >" << fieldOrder << "<" << oendl;
494 496
495 // Get index of combo as char.. 497 // Get index of combo as char..
496 QChar poschar = fieldOrder[ num ]; 498 QChar poschar = fieldOrder[ num ];
497 499
498 bool ok; 500 bool ok;
499 int ret = 0; 501 int ret = 0;
500 // Convert char to number.. 502 // Convert char to number..
501 if ( !( poschar == QChar::null ) ) 503 if ( !( poschar == QChar::null ) )
502 ret = QString( poschar ).toInt( &ok, 16 ); 504 ret = QString( poschar ).toInt( &ok, 16 );
503 else 505 else
504 ok = false; 506 ok = false;
505 507
506 // Return default value if index for 508 // Return default value if index for
507 // num was not set or if anything else happened.. 509 // num was not set or if anything else happened..
508 if ( !ok ) ret = defIndex; 510 if ( !ok ) ret = defIndex;
509 511
510 qDebug( "returning >%i<", ret ); 512 odebug << "returning >" << ret << "<" << oendl;
511 513
512 return ret; 514 return ret;
513 515
514} 516}
515 517
516} 518}
diff --git a/libopie2/opiepim/core/opimdateconversion.cpp b/libopie2/opiepim/core/opimdateconversion.cpp
index 8bf891b..c93e178 100644
--- a/libopie2/opiepim/core/opimdateconversion.cpp
+++ b/libopie2/opiepim/core/opimdateconversion.cpp
@@ -1,143 +1,145 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 3 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
4 .=l. 4 .=l.
5 .>+-= 5 .>+-=
6_;:, .> :=|. This program is free software; you can 6_;:, .> :=|. This program is free software; you can
7.> <`_, > . <= redistribute it and/or modify it under 7.> <`_, > . <= redistribute it and/or modify it under
8:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 8:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
9.="- .-=="i, .._ License as published by the Free Software 9.="- .-=="i, .._ License as published by the Free Software
10- . .-<_> .<> Foundation; either version 2 of the License, 10- . .-<_> .<> Foundation; either version 2 of the License,
11 ._= =} : or (at your option) any later version. 11 ._= =} : or (at your option) any later version.
12 .%`+i> _;_. 12 .%`+i> _;_.
13 .i_,=:_. -<s. This program is distributed in the hope that 13 .i_,=:_. -<s. This program is distributed in the hope that
14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
15 : .. .:, . . . without even the implied warranty of 15 : .. .:, . . . without even the implied warranty of
16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.= = ; Library General Public License for more 18..}^=.= = ; Library General Public License for more
19++= -. .` .: details. 19++= -. .` .: details.
20: = ...= . :.=- 20: = ...= . :.=-
21-. .:....=;==+<; You should have received a copy of the GNU 21-. .:....=;==+<; You should have received a copy of the GNU
22 -_. . . )=. = Library General Public License along with 22 -_. . . )=. = Library General Public License along with
23 -- :-=` this library; see the file COPYING.LIB. 23 -- :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27*/ 27*/
28 28
29/* OPIE */ 29/* OPIE */
30#include <opie2/opimdateconversion.h> 30#include <opie2/opimdateconversion.h>
31#include <opie2/odebug.h>
32
31#include <qpe/timeconversion.h> 33#include <qpe/timeconversion.h>
32 34
33namespace Opie 35namespace Opie
34{ 36{
35 37
36QString OPimDateConversion::dateToString( const QDate &d ) 38QString OPimDateConversion::dateToString( const QDate &d )
37{ 39{
38 if ( d.isNull() || !d.isValid() ) 40 if ( d.isNull() || !d.isValid() )
39 return QString::null; 41 return QString::null;
40 42
41 // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 43 // ISO format in year, month, day (YYYYMMDD); e.g. 20021231
42 QString year = QString::number( d.year() ); 44 QString year = QString::number( d.year() );
43 QString month = QString::number( d.month() ); 45 QString month = QString::number( d.month() );
44 month = month.rightJustify( 2, '0' ); 46 month = month.rightJustify( 2, '0' );
45 QString day = QString::number( d.day() ); 47 QString day = QString::number( d.day() );
46 day = day.rightJustify( 2, '0' ); 48 day = day.rightJustify( 2, '0' );
47 49
48 QString str = year + month + day; 50 QString str = year + month + day;
49 //qDebug( "\tPimContact dateToStr = %s", str.latin1() ); 51 //odebug << "\tPimContact dateToStr = " << str << "" << oendl;
50 52
51 return str; 53 return str;
52} 54}
53 55
54 56
55QDate OPimDateConversion::dateFromString( const QString& s ) 57QDate OPimDateConversion::dateFromString( const QString& s )
56{ 58{
57 QDate date; 59 QDate date;
58 60
59 if ( s.isEmpty() ) 61 if ( s.isEmpty() )
60 return date; 62 return date;
61 63
62 // Be backward compatible to old Opie format: 64 // Be backward compatible to old Opie format:
63 // Try to load old format. If it fails, try new ISO-Format! 65 // Try to load old format. If it fails, try new ISO-Format!
64 date = TimeConversion::fromString ( s ); 66 date = TimeConversion::fromString ( s );
65 if ( date.isValid() ) 67 if ( date.isValid() )
66 return date; 68 return date;
67 69
68 // Read ISO-Format (YYYYMMDD) 70 // Read ISO-Format (YYYYMMDD)
69 int year = s.mid( 0, 4 ).toInt(); 71 int year = s.mid( 0, 4 ).toInt();
70 int month = s.mid( 4, 2 ).toInt(); 72 int month = s.mid( 4, 2 ).toInt();
71 int day = s.mid( 6, 2 ).toInt(); 73 int day = s.mid( 6, 2 ).toInt();
72 74
73 // do some quick sanity checking -eilers 75 // do some quick sanity checking -eilers
74 // but we isValid() again? -zecke 76 // but we isValid() again? -zecke
75 if ( year < 1900 || year > 3000 ) 77 if ( year < 1900 || year > 3000 )
76 { 78 {
77 qWarning( "PimContact year is not in range" ); 79 owarn << "PimContact year is not in range" << oendl;
78 return date; 80 return date;
79 } 81 }
80 if ( month < 0 || month > 12 ) 82 if ( month < 0 || month > 12 )
81 { 83 {
82 qWarning( "PimContact month is not in range" ); 84 owarn << "PimContact month is not in range" << oendl;
83 return date; 85 return date;
84 } 86 }
85 if ( day < 0 || day > 31 ) 87 if ( day < 0 || day > 31 )
86 { 88 {
87 qWarning( "PimContact day is not in range" ); 89 owarn << "PimContact day is not in range" << oendl;
88 return date; 90 return date;
89 } 91 }
90 92
91 date.setYMD( year, month, day ); 93 date.setYMD( year, month, day );
92 if ( !date.isValid() ) 94 if ( !date.isValid() )
93 { 95 {
94 qWarning( "PimContact date is not valid" ); 96 owarn << "PimContact date is not valid" << oendl;
95 return date; 97 return date;
96 } 98 }
97 99
98 return date; 100 return date;
99} 101}
100 102
101 103
102QString OPimDateConversion::dateTimeToString( const QDateTime& dt ) 104QString OPimDateConversion::dateTimeToString( const QDateTime& dt )
103{ 105{
104 if ( !dt.isValid() || dt.isNull() ) 106 if ( !dt.isValid() || dt.isNull() )
105 return QString::null; 107 return QString::null;
106 108
107 QString year = QString::number( dt.date().year() ); 109 QString year = QString::number( dt.date().year() );
108 QString month = QString::number( dt.date().month() ); 110 QString month = QString::number( dt.date().month() );
109 QString day = QString::number( dt.date().day() ); 111 QString day = QString::number( dt.date().day() );
110 112
111 QString hour = QString::number( dt.time().hour() ); 113 QString hour = QString::number( dt.time().hour() );
112 QString min = QString::number( dt.time().minute() ); 114 QString min = QString::number( dt.time().minute() );
113 QString sec = QString::number( dt.time().second() ); 115 QString sec = QString::number( dt.time().second() );
114 116
115 month = month.rightJustify( 2, '0' ); 117 month = month.rightJustify( 2, '0' );
116 day = day. rightJustify( 2, '0' ); 118 day = day. rightJustify( 2, '0' );
117 hour = hour. rightJustify( 2, '0' ); 119 hour = hour. rightJustify( 2, '0' );
118 min = min. rightJustify( 2, '0' ); 120 min = min. rightJustify( 2, '0' );
119 sec = sec. rightJustify( 2, '0' ); 121 sec = sec. rightJustify( 2, '0' );
120 122
121 return day + month + year + hour + min + sec; 123 return day + month + year + hour + min + sec;
122} 124}
123 125
124 126
125QDateTime OPimDateConversion::dateTimeFromString( const QString& str ) 127QDateTime OPimDateConversion::dateTimeFromString( const QString& str )
126{ 128{
127 129
128 if ( str.isEmpty() ) 130 if ( str.isEmpty() )
129 return QDateTime(); 131 return QDateTime();
130 int day = str.mid( 0, 2 ).toInt(); 132 int day = str.mid( 0, 2 ).toInt();
131 int month = str.mid( 2, 2 ).toInt(); 133 int month = str.mid( 2, 2 ).toInt();
132 int year = str.mid( 4, 4 ).toInt(); 134 int year = str.mid( 4, 4 ).toInt();
133 int hour = str.mid( 8, 2 ).toInt(); 135 int hour = str.mid( 8, 2 ).toInt();
134 int min = str.mid( 10, 2 ).toInt(); 136 int min = str.mid( 10, 2 ).toInt();
135 int sec = str.mid( 12, 2 ).toInt(); 137 int sec = str.mid( 12, 2 ).toInt();
136 138
137 QDate date( year, month, day ); 139 QDate date( year, month, day );
138 QTime time( hour, min, sec ); 140 QTime time( hour, min, sec );
139 QDateTime dt( date, time ); 141 QDateTime dt( date, time );
140 return dt; 142 return dt;
141} 143}
142 144
143} 145}
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 9d46651..8752fce 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -1,291 +1,293 @@
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#include "opimevent.h" 30#include "opimevent.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimrecurrence.h> 33#include <opie2/opimrecurrence.h>
34#include <opie2/opimresolver.h> 34#include <opie2/opimresolver.h>
35#include <opie2/opimnotifymanager.h> 35#include <opie2/opimnotifymanager.h>
36#include <opie2/odebug.h>
37
36#include <qpe/categories.h> 38#include <qpe/categories.h>
37#include <qpe/stringutil.h> 39#include <qpe/stringutil.h>
38 40
39/* QT */ 41/* QT */
40 42
41namespace Opie 43namespace Opie
42{ 44{
43 45
44int OCalendarHelper::week( const QDate& date ) 46int OCalendarHelper::week( const QDate& date )
45{ 47{
46 // Calculates the week this date is in within that 48 // Calculates the week this date is in within that
47 // month. Equals the "row" is is in in the month view 49 // month. Equals the "row" is is in in the month view
48 int week = 1; 50 int week = 1;
49 QDate tmp( date.year(), date.month(), 1 ); 51 QDate tmp( date.year(), date.month(), 1 );
50 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 52 if ( date.dayOfWeek() < tmp.dayOfWeek() )
51 ++week; 53 ++week;
52 54
53 week += ( date.day() - 1 ) / 7; 55 week += ( date.day() - 1 ) / 7;
54 56
55 return week; 57 return week;
56} 58}
57 59
58 60
59int OCalendarHelper::ocurrence( const QDate& date ) 61int OCalendarHelper::ocurrence( const QDate& date )
60{ 62{
61 // calculates the number of occurrances of this day of the 63 // calculates the number of occurrances of this day of the
62 // week till the given date (e.g 3rd Wednesday of the month) 64 // week till the given date (e.g 3rd Wednesday of the month)
63 return ( date.day() - 1 ) / 7 + 1; 65 return ( date.day() - 1 ) / 7 + 1;
64} 66}
65 67
66 68
67int OCalendarHelper::dayOfWeek( char day ) 69int OCalendarHelper::dayOfWeek( char day )
68{ 70{
69 int dayOfWeek = 1; 71 int dayOfWeek = 1;
70 char i = OPimRecurrence::MON; 72 char i = OPimRecurrence::MON;
71 while ( !( i & day ) && i <= OPimRecurrence::SUN ) 73 while ( !( i & day ) && i <= OPimRecurrence::SUN )
72 { 74 {
73 i <<= 1; 75 i <<= 1;
74 ++dayOfWeek; 76 ++dayOfWeek;
75 } 77 }
76 return dayOfWeek; 78 return dayOfWeek;
77} 79}
78 80
79 81
80int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) 82int OCalendarHelper::monthDiff( const QDate& first, const QDate& second )
81{ 83{
82 return ( second.year() - first.year() ) * 12 + 84 return ( second.year() - first.year() ) * 12 +
83 second.month() - first.month(); 85 second.month() - first.month();
84} 86}
85 87
86 88
87struct OPimEvent::Data : public QShared 89struct OPimEvent::Data : public QShared
88{ 90{
89 Data() : QShared() 91 Data() : QShared()
90 { 92 {
91 child = 0; 93 child = 0;
92 recur = 0; 94 recur = 0;
93 manager = 0; 95 manager = 0;
94 isAllDay = false; 96 isAllDay = false;
95 parent = 0; 97 parent = 0;
96 } 98 }
97 ~Data() 99 ~Data()
98 { 100 {
99 delete manager; 101 delete manager;
100 delete recur; 102 delete recur;
101 } 103 }
102 QString description; 104 QString description;
103 QString location; 105 QString location;
104 OPimNotifyManager* manager; 106 OPimNotifyManager* manager;
105 OPimRecurrence* recur; 107 OPimRecurrence* recur;
106 QString note; 108 QString note;
107 QDateTime created; 109 QDateTime created;
108 QDateTime start; 110 QDateTime start;
109 QDateTime end; 111 QDateTime end;
110bool isAllDay : 1; 112bool isAllDay : 1;
111 QString timezone; 113 QString timezone;
112 QArray<int>* child; 114 QArray<int>* child;
113 int parent; 115 int parent;
114}; 116};
115 117
116 118
117OPimEvent::OPimEvent( int uid ) 119OPimEvent::OPimEvent( int uid )
118 : OPimRecord( uid ) 120 : OPimRecord( uid )
119{ 121{
120 data = new Data; 122 data = new Data;
121} 123}
122 124
123 125
124OPimEvent::OPimEvent( const OPimEvent& ev ) 126OPimEvent::OPimEvent( const OPimEvent& ev )
125 : OPimRecord( ev ), data( ev.data ) 127 : OPimRecord( ev ), data( ev.data )
126{ 128{
127 data->ref(); 129 data->ref();
128} 130}
129 131
130 132
131OPimEvent::OPimEvent( const QMap<int, QString> map ) 133OPimEvent::OPimEvent( const QMap<int, QString> map )
132 : OPimRecord( 0 ) 134 : OPimRecord( 0 )
133{ 135{
134 data = new Data; 136 data = new Data;
135 137
136 fromMap( map ); 138 fromMap( map );
137} 139}
138 140
139 141
140OPimEvent::~OPimEvent() 142OPimEvent::~OPimEvent()
141{ 143{
142 if ( data->deref() ) 144 if ( data->deref() )
143 { 145 {
144 delete data; 146 delete data;
145 data = 0; 147 data = 0;
146 } 148 }
147} 149}
148 150
149 151
150OPimEvent& OPimEvent::operator=( const OPimEvent& ev ) 152OPimEvent& OPimEvent::operator=( const OPimEvent& ev )
151{ 153{
152 if ( this == &ev ) return * this; 154 if ( this == &ev ) return * this;
153 155
154 OPimRecord::operator=( ev ); 156 OPimRecord::operator=( ev );
155 ev.data->ref(); 157 ev.data->ref();
156 deref(); 158 deref();
157 data = ev.data; 159 data = ev.data;
158 160
159 161
160 return *this; 162 return *this;
161} 163}
162 164
163 165
164QString OPimEvent::description() const 166QString OPimEvent::description() const
165{ 167{
166 return data->description; 168 return data->description;
167} 169}
168 170
169 171
170void OPimEvent::setDescription( const QString& description ) 172void OPimEvent::setDescription( const QString& description )
171{ 173{
172 changeOrModify(); 174 changeOrModify();
173 data->description = description; 175 data->description = description;
174} 176}
175 177
176 178
177void OPimEvent::setLocation( const QString& loc ) 179void OPimEvent::setLocation( const QString& loc )
178{ 180{
179 changeOrModify(); 181 changeOrModify();
180 data->location = loc; 182 data->location = loc;
181} 183}
182 184
183 185
184QString OPimEvent::location() const 186QString OPimEvent::location() const
185{ 187{
186 return data->location; 188 return data->location;
187} 189}
188 190
189 191
190OPimNotifyManager &OPimEvent::notifiers() const 192OPimNotifyManager &OPimEvent::notifiers() const
191{ 193{
192 // I hope we can skip the changeOrModify here 194 // I hope we can skip the changeOrModify here
193 // the notifier should take care of it 195 // the notifier should take care of it
194 // and OPimNotify is shared too 196 // and OPimNotify is shared too
195 if ( !data->manager ) 197 if ( !data->manager )
196 data->manager = new OPimNotifyManager; 198 data->manager = new OPimNotifyManager;
197 199
198 return *data->manager; 200 return *data->manager;
199} 201}
200 202
201 203
202bool OPimEvent::hasNotifiers() const 204bool OPimEvent::hasNotifiers() const
203{ 205{
204 if ( !data->manager ) 206 if ( !data->manager )
205 return false; 207 return false;
206 if ( data->manager->reminders().isEmpty() && 208 if ( data->manager->reminders().isEmpty() &&
207 data->manager->alarms().isEmpty() ) 209 data->manager->alarms().isEmpty() )
208 return false; 210 return false;
209 211
210 return true; 212 return true;
211} 213}
212 214
213 215
214OPimRecurrence OPimEvent::recurrence() const 216OPimRecurrence OPimEvent::recurrence() const
215{ 217{
216 if ( !data->recur ) 218 if ( !data->recur )
217 data->recur = new OPimRecurrence; 219 data->recur = new OPimRecurrence;
218 220
219 return *data->recur; 221 return *data->recur;
220} 222}
221 223
222 224
223void OPimEvent::setRecurrence( const OPimRecurrence& rec ) 225void OPimEvent::setRecurrence( const OPimRecurrence& rec )
224{ 226{
225 changeOrModify(); 227 changeOrModify();
226 if ( data->recur ) 228 if ( data->recur )
227 ( *data->recur ) = rec; 229 ( *data->recur ) = rec;
228 else 230 else
229 data->recur = new OPimRecurrence( rec ); 231 data->recur = new OPimRecurrence( rec );
230} 232}
231 233
232 234
233bool OPimEvent::hasRecurrence() const 235bool OPimEvent::hasRecurrence() const
234{ 236{
235 if ( !data->recur ) return false; 237 if ( !data->recur ) return false;
236 return data->recur->doesRecur(); 238 return data->recur->doesRecur();
237} 239}
238 240
239 241
240QString OPimEvent::note() const 242QString OPimEvent::note() const
241{ 243{
242 return data->note; 244 return data->note;
243} 245}
244 246
245 247
246void OPimEvent::setNote( const QString& note ) 248void OPimEvent::setNote( const QString& note )
247{ 249{
248 changeOrModify(); 250 changeOrModify();
249 data->note = note; 251 data->note = note;
250} 252}
251 253
252 254
253QDateTime OPimEvent::createdDateTime() const 255QDateTime OPimEvent::createdDateTime() const
254{ 256{
255 return data->created; 257 return data->created;
256} 258}
257 259
258 260
259void OPimEvent::setCreatedDateTime( const QDateTime& time ) 261void OPimEvent::setCreatedDateTime( const QDateTime& time )
260{ 262{
261 changeOrModify(); 263 changeOrModify();
262 data->created = time; 264 data->created = time;
263} 265}
264 266
265 267
266QDateTime OPimEvent::startDateTime() const 268QDateTime OPimEvent::startDateTime() const
267{ 269{
268 if ( data->isAllDay ) 270 if ( data->isAllDay )
269 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) ); 271 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) );
270 return data->start; 272 return data->start;
271} 273}
272 274
273 275
274QDateTime OPimEvent::startDateTimeInZone() const 276QDateTime OPimEvent::startDateTimeInZone() const
275{ 277{
276 /* if no timezone, or all day event or if the current and this timeZone match... */ 278 /* if no timezone, or all day event or if the current and this timeZone match... */
277 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime(); 279 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime();
278 280
279 OPimTimeZone zone( data->timezone ); 281 OPimTimeZone zone( data->timezone );
280 return zone.toDateTime( data->start, OPimTimeZone::current() ); 282 return zone.toDateTime( data->start, OPimTimeZone::current() );
281} 283}
282 284
283 285
284void OPimEvent::setStartDateTime( const QDateTime& dt ) 286void OPimEvent::setStartDateTime( const QDateTime& dt )
285{ 287{
286 changeOrModify(); 288 changeOrModify();
287 data->start = dt; 289 data->start = dt;
288} 290}
289 291
290 292
291QDateTime OPimEvent::endDateTime() const 293QDateTime OPimEvent::endDateTime() const
@@ -302,623 +304,623 @@ QDateTime OPimEvent::endDateTime() const
302 304
303QDateTime OPimEvent::endDateTimeInZone() const 305QDateTime OPimEvent::endDateTimeInZone() const
304{ 306{
305 /* if no timezone, or all day event or if the current and this timeZone match... */ 307 /* if no timezone, or all day event or if the current and this timeZone match... */
306 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime(); 308 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime();
307 309
308 OPimTimeZone zone( data->timezone ); 310 OPimTimeZone zone( data->timezone );
309 return zone.toDateTime( data->end, OPimTimeZone::current() ); 311 return zone.toDateTime( data->end, OPimTimeZone::current() );
310} 312}
311 313
312 314
313void OPimEvent::setEndDateTime( const QDateTime& dt ) 315void OPimEvent::setEndDateTime( const QDateTime& dt )
314{ 316{
315 changeOrModify(); 317 changeOrModify();
316 data->end = dt; 318 data->end = dt;
317} 319}
318 320
319 321
320bool OPimEvent::isMultipleDay() const 322bool OPimEvent::isMultipleDay() const
321{ 323{
322 return data->end.date().day() - data->start.date().day(); 324 return data->end.date().day() - data->start.date().day();
323} 325}
324 326
325 327
326bool OPimEvent::isAllDay() const 328bool OPimEvent::isAllDay() const
327{ 329{
328 return data->isAllDay; 330 return data->isAllDay;
329} 331}
330 332
331 333
332void OPimEvent::setAllDay( bool allDay ) 334void OPimEvent::setAllDay( bool allDay )
333{ 335{
334 changeOrModify(); 336 changeOrModify();
335 data->isAllDay = allDay; 337 data->isAllDay = allDay;
336 if ( allDay ) data->timezone = "UTC"; 338 if ( allDay ) data->timezone = "UTC";
337} 339}
338 340
339 341
340void OPimEvent::setTimeZone( const QString& tz ) 342void OPimEvent::setTimeZone( const QString& tz )
341{ 343{
342 changeOrModify(); 344 changeOrModify();
343 data->timezone = tz; 345 data->timezone = tz;
344} 346}
345 347
346 348
347QString OPimEvent::timeZone() const 349QString OPimEvent::timeZone() const
348{ 350{
349 if ( data->isAllDay ) return QString::fromLatin1( "UTC" ); 351 if ( data->isAllDay ) return QString::fromLatin1( "UTC" );
350 return data->timezone; 352 return data->timezone;
351} 353}
352 354
353 355
354bool OPimEvent::match( const QRegExp& re ) const 356bool OPimEvent::match( const QRegExp& re ) const
355{ 357{
356 if ( re.match( data->description ) != -1 ) 358 if ( re.match( data->description ) != -1 )
357 { 359 {
358 setLastHitField( Qtopia::DatebookDescription ); 360 setLastHitField( Qtopia::DatebookDescription );
359 return true; 361 return true;
360 } 362 }
361 if ( re.match( data->note ) != -1 ) 363 if ( re.match( data->note ) != -1 )
362 { 364 {
363 setLastHitField( Qtopia::Note ); 365 setLastHitField( Qtopia::Note );
364 return true; 366 return true;
365 } 367 }
366 if ( re.match( data->location ) != -1 ) 368 if ( re.match( data->location ) != -1 )
367 { 369 {
368 setLastHitField( Qtopia::Location ); 370 setLastHitField( Qtopia::Location );
369 return true; 371 return true;
370 } 372 }
371 if ( re.match( data->start.toString() ) != -1 ) 373 if ( re.match( data->start.toString() ) != -1 )
372 { 374 {
373 setLastHitField( Qtopia::StartDateTime ); 375 setLastHitField( Qtopia::StartDateTime );
374 return true; 376 return true;
375 } 377 }
376 if ( re.match( data->end.toString() ) != -1 ) 378 if ( re.match( data->end.toString() ) != -1 )
377 { 379 {
378 setLastHitField( Qtopia::EndDateTime ); 380 setLastHitField( Qtopia::EndDateTime );
379 return true; 381 return true;
380 } 382 }
381 return false; 383 return false;
382} 384}
383 385
384 386
385QString OPimEvent::toRichText() const 387QString OPimEvent::toRichText() const
386{ 388{
387 QString text, value; 389 QString text, value;
388 390
389 // description 391 // description
390 text += "<b><h3><img src=\"datebook/DateBook\">"; 392 text += "<b><h3><img src=\"datebook/DateBook\">";
391 if ( !description().isEmpty() ) 393 if ( !description().isEmpty() )
392 { 394 {
393 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" ); 395 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
394 } 396 }
395 text += "</h3></b><br><hr><br>"; 397 text += "</h3></b><br><hr><br>";
396 398
397 // location 399 // location
398 if ( !( value = location() ).isEmpty() ) 400 if ( !( value = location() ).isEmpty() )
399 { 401 {
400 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 402 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
401 text += Qtopia::escapeString( value ) + "<br>"; 403 text += Qtopia::escapeString( value ) + "<br>";
402 } 404 }
403 405
404 // all day event 406 // all day event
405 if ( isAllDay() ) 407 if ( isAllDay() )
406 { 408 {
407 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 409 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
408 } 410 }
409 // multiple day event 411 // multiple day event
410 else if ( isMultipleDay () ) 412 else if ( isMultipleDay () )
411 { 413 {
412 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 414 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
413 } 415 }
414 // start & end times 416 // start & end times
415 else 417 else
416 { 418 {
417 // start time 419 // start time
418 if ( startDateTime().isValid() ) 420 if ( startDateTime().isValid() )
419 { 421 {
420 text += "<b>" + QObject::tr( "Start:" ) + "</b> "; 422 text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
421 text += Qtopia::escapeString( startDateTime().toString() ). 423 text += Qtopia::escapeString( startDateTime().toString() ).
422 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 424 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
423 } 425 }
424 426
425 // end time 427 // end time
426 if ( endDateTime().isValid() ) 428 if ( endDateTime().isValid() )
427 { 429 {
428 text += "<b>" + QObject::tr( "End:" ) + "</b> "; 430 text += "<b>" + QObject::tr( "End:" ) + "</b> ";
429 text += Qtopia::escapeString( endDateTime().toString() ). 431 text += Qtopia::escapeString( endDateTime().toString() ).
430 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 432 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
431 } 433 }
432 } 434 }
433 435
434 // categories 436 // categories
435 if ( categoryNames( "Calendar" ).count() ) 437 if ( categoryNames( "Calendar" ).count() )
436 { 438 {
437 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 439 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
438 text += categoryNames( "Calendar" ).join( ", " ); 440 text += categoryNames( "Calendar" ).join( ", " );
439 text += "<br>"; 441 text += "<br>";
440 } 442 }
441 443
442 //notes 444 //notes
443 if ( !note().isEmpty() ) 445 if ( !note().isEmpty() )
444 { 446 {
445 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>"; 447 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
446 text += note(); 448 text += note();
447 // text += Qtopia::escapeString(note() ). 449 // text += Qtopia::escapeString(note() ).
448 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 450 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
449 } 451 }
450 return text; 452 return text;
451} 453}
452 454
453 455
454QString OPimEvent::toShortText() const 456QString OPimEvent::toShortText() const
455{ 457{
456 QString text; 458 QString text;
457 text += QString::number( startDateTime().date().day() ); 459 text += QString::number( startDateTime().date().day() );
458 text += "."; 460 text += ".";
459 text += QString::number( startDateTime().date().month() ); 461 text += QString::number( startDateTime().date().month() );
460 text += "."; 462 text += ".";
461 text += QString::number( startDateTime().date().year() ); 463 text += QString::number( startDateTime().date().year() );
462 text += " "; 464 text += " ";
463 text += QString::number( startDateTime().time().hour() ); 465 text += QString::number( startDateTime().time().hour() );
464 text += ":"; 466 text += ":";
465 text += QString::number( startDateTime().time().minute() ); 467 text += QString::number( startDateTime().time().minute() );
466 text += " - "; 468 text += " - ";
467 text += description(); 469 text += description();
468 return text; 470 return text;
469} 471}
470 472
471 473
472QString OPimEvent::type() const 474QString OPimEvent::type() const
473{ 475{
474 return QString::fromLatin1( "OPimEvent" ); 476 return QString::fromLatin1( "OPimEvent" );
475} 477}
476 478
477 479
478QString OPimEvent::recordField( int /*id */ ) const 480QString OPimEvent::recordField( int /*id */ ) const
479{ 481{
480 return QString::null; 482 return QString::null;
481} 483}
482 484
483 485
484int OPimEvent::rtti() const 486int OPimEvent::rtti() const
485{ 487{
486 return OPimResolver::DateBook; 488 return OPimResolver::DateBook;
487} 489}
488 490
489 491
490bool OPimEvent::loadFromStream( QDataStream& ) 492bool OPimEvent::loadFromStream( QDataStream& )
491{ 493{
492 return true; 494 return true;
493} 495}
494 496
495 497
496bool OPimEvent::saveToStream( QDataStream& ) const 498bool OPimEvent::saveToStream( QDataStream& ) const
497{ 499{
498 return true; 500 return true;
499} 501}
500 502
501 503
502void OPimEvent::changeOrModify() 504void OPimEvent::changeOrModify()
503{ 505{
504 if ( data->count != 1 ) 506 if ( data->count != 1 )
505 { 507 {
506 data->deref(); 508 data->deref();
507 Data* d2 = new Data; 509 Data* d2 = new Data;
508 d2->description = data->description; 510 d2->description = data->description;
509 d2->location = data->location; 511 d2->location = data->location;
510 512
511 if ( data->manager ) 513 if ( data->manager )
512 d2->manager = new OPimNotifyManager( *data->manager ); 514 d2->manager = new OPimNotifyManager( *data->manager );
513 515
514 if ( data->recur ) 516 if ( data->recur )
515 d2->recur = new OPimRecurrence( *data->recur ); 517 d2->recur = new OPimRecurrence( *data->recur );
516 518
517 d2->note = data->note; 519 d2->note = data->note;
518 d2->created = data->created; 520 d2->created = data->created;
519 d2->start = data->start; 521 d2->start = data->start;
520 d2->end = data->end; 522 d2->end = data->end;
521 d2->isAllDay = data->isAllDay; 523 d2->isAllDay = data->isAllDay;
522 d2->timezone = data->timezone; 524 d2->timezone = data->timezone;
523 d2->parent = data->parent; 525 d2->parent = data->parent;
524 526
525 if ( data->child ) 527 if ( data->child )
526 { 528 {
527 d2->child = new QArray<int>( *data->child ); 529 d2->child = new QArray<int>( *data->child );
528 d2->child->detach(); 530 d2->child->detach();
529 } 531 }
530 532
531 data = d2; 533 data = d2;
532 } 534 }
533} 535}
534 536
535 537
536void OPimEvent::deref() 538void OPimEvent::deref()
537{ 539{
538 if ( data->deref() ) 540 if ( data->deref() )
539 { 541 {
540 delete data; 542 delete data;
541 data = 0; 543 data = 0;
542 } 544 }
543} 545}
544// Exporting Event data to map. Using the same 546// Exporting Event data to map. Using the same
545// encoding as ODateBookAccessBackend_xml does.. 547// encoding as ODateBookAccessBackend_xml does..
546// Thus, we could remove the stuff there and use this 548// Thus, we could remove the stuff there and use this
547// for it and for all other places.. 549// for it and for all other places..
548// Encoding should happen at one place, only ! (eilers) 550// Encoding should happen at one place, only ! (eilers)
549QMap<int, QString> OPimEvent::toMap() const 551QMap<int, QString> OPimEvent::toMap() const
550{ 552{
551 QMap<int, QString> retMap; 553 QMap<int, QString> retMap;
552 554
553 retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); 555 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
554 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); 556 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
555 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); 557 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
556 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); 558 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
557 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); 559 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
558 if ( notifiers().alarms().count() ){ 560 if ( notifiers().alarms().count() ){
559 // Currently we just support one alarm.. (eilers) 561 // Currently we just support one alarm.. (eilers)
560 OPimAlarm alarm = notifiers().alarms() [ 0 ]; 562 OPimAlarm alarm = notifiers().alarms() [ 0 ];
561 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 563 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
562 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); 564 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
563 } 565 }
564 566
565 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); 567 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
566 retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) ); 568 retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) );
567 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) ); 569 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) );
568 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); 570 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
569 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); 571 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
570 if ( parent() ) 572 if ( parent() )
571 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); 573 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
572 if ( children().count() ) 574 if ( children().count() )
573 { 575 {
574 QArray<int> childr = children(); 576 QArray<int> childr = children();
575 QString buf; 577 QString buf;
576 for ( uint i = 0; i < childr.count(); i++ ) 578 for ( uint i = 0; i < childr.count(); i++ )
577 { 579 {
578 if ( i != 0 ) buf += " "; 580 if ( i != 0 ) buf += " ";
579 buf += QString::number( childr[ i ] ); 581 buf += QString::number( childr[ i ] );
580 } 582 }
581 retMap.insert( OPimEvent::FRecChildren, buf ); 583 retMap.insert( OPimEvent::FRecChildren, buf );
582 } 584 }
583 585
584 // Add recurrence stuff 586 // Add recurrence stuff
585 if ( hasRecurrence() ) 587 if ( hasRecurrence() )
586 { 588 {
587 OPimRecurrence recur = recurrence(); 589 OPimRecurrence recur = recurrence();
588 QMap<int, QString> recFields = recur.toMap(); 590 QMap<int, QString> recFields = recur.toMap();
589 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 591 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
590 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); 592 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] );
591 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); 593 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] );
592 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); 594 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] );
593 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); 595 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] );
594 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); 596 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] );
595 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); 597 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] );
596 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); 598 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] );
597 } 599 }
598 else 600 else
599 { 601 {
600 OPimRecurrence recur = recurrence(); 602 OPimRecurrence recur = recurrence();
601 QMap<int, QString> recFields = recur.toMap(); 603 QMap<int, QString> recFields = recur.toMap();
602 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 604 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
603 } 605 }
604 606
605 return retMap; 607 return retMap;
606} 608}
607 609
608 610
609void OPimEvent::fromMap( const QMap<int, QString>& map ) 611void OPimEvent::fromMap( const QMap<int, QString>& map )
610{ 612{
611 613
612 // We just want to set the UID if it is really stored. 614 // We just want to set the UID if it is really stored.
613 if ( !map[ OPimEvent::FUid ].isEmpty() ) 615 if ( !map[ OPimEvent::FUid ].isEmpty() )
614 setUid( map[ OPimEvent::FUid ].toInt() ); 616 setUid( map[ OPimEvent::FUid ].toInt() );
615 617
616 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); 618 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
617 setDescription( map[ OPimEvent::FDescription ] ); 619 setDescription( map[ OPimEvent::FDescription ] );
618 setLocation( map[ OPimEvent::FLocation ] ); 620 setLocation( map[ OPimEvent::FLocation ] );
619 621
620 if ( map[ OPimEvent::FType ] == "AllDay" ) 622 if ( map[ OPimEvent::FType ] == "AllDay" )
621 setAllDay( true ); 623 setAllDay( true );
622 else 624 else
623 setAllDay( false ); 625 setAllDay( false );
624 626
625 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) 627 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
626 { 628 {
627 setTimeZone( map[ OPimEvent::FTimeZone ] ); 629 setTimeZone( map[ OPimEvent::FTimeZone ] );
628 } 630 }
629 631
630 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); 632 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
631 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); 633 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
632 634
633 /* AllDay is always in UTC */ 635 /* AllDay is always in UTC */
634 if ( isAllDay() ) 636 if ( isAllDay() )
635 { 637 {
636 OPimTimeZone utc = OPimTimeZone::utc(); 638 OPimTimeZone utc = OPimTimeZone::utc();
637 setStartDateTime( utc.fromUTCDateTime( start ) ); 639 setStartDateTime( utc.fromUTCDateTime( start ) );
638 setEndDateTime ( utc.fromUTCDateTime( end ) ); 640 setEndDateTime ( utc.fromUTCDateTime( end ) );
639 setTimeZone( "UTC" ); // make sure it is really utc 641 setTimeZone( "UTC" ); // make sure it is really utc
640 } 642 }
641 else 643 else
642 { 644 {
643 /* to current date time */ 645 /* to current date time */
644 // qWarning(" Start is %d", start ); 646 // owarn << " Start is " << start << "" << oendl;
645 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); 647 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
646 QDateTime date = zone.toDateTime( start ); 648 QDateTime date = zone.toDateTime( start );
647 qWarning( " Start is %s", date.toString().latin1() ); 649 owarn << " Start is " << date.toString() << "" << oendl;
648 setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); 650 setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
649 651
650 date = zone.toDateTime( end ); 652 date = zone.toDateTime( end );
651 setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); 653 setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) );
652 } 654 }
653 655
654 int alarmTime = -1; 656 int alarmTime = -1;
655 if ( !map[ OPimEvent::FAlarm ].isEmpty() ) 657 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
656 alarmTime = map[ OPimEvent::FAlarm ].toInt(); 658 alarmTime = map[ OPimEvent::FAlarm ].toInt();
657 659
658 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); 660 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
659 if ( ( alarmTime != -1 ) ) 661 if ( ( alarmTime != -1 ) )
660 { 662 {
661 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); 663 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
662 OPimAlarm al( sound , dt ); 664 OPimAlarm al( sound , dt );
663 notifiers().add( al ); 665 notifiers().add( al );
664 } 666 }
665 667
666 668
667 if ( !map[ OPimEvent::FNote ].isEmpty() ) 669 if ( !map[ OPimEvent::FNote ].isEmpty() )
668 setNote( map[ OPimEvent::FNote ] ); 670 setNote( map[ OPimEvent::FNote ] );
669 671
670 if ( !map[ OPimEvent::FRecParent ].isEmpty() ) 672 if ( !map[ OPimEvent::FRecParent ].isEmpty() )
671 setParent( map[ OPimEvent::FRecParent ].toInt() ); 673 setParent( map[ OPimEvent::FRecParent ].toInt() );
672 674
673 if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) 675 if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
674 { 676 {
675 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); 677 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
676 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 678 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
677 { 679 {
678 addChild( ( *it ).toInt() ); 680 addChild( ( *it ).toInt() );
679 } 681 }
680 } 682 }
681 683
682 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. 684 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap..
683 if ( !map[ OPimEvent::FRType ].isEmpty() ) 685 if ( !map[ OPimEvent::FRType ].isEmpty() )
684 { 686 {
685 QMap<int, QString> recFields; 687 QMap<int, QString> recFields;
686 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); 688 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] );
687 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); 689 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] );
688 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); 690 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] );
689 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); 691 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] );
690 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); 692 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] );
691 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); 693 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] );
692 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); 694 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] );
693 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); 695 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] );
694 OPimRecurrence recur( recFields ); 696 OPimRecurrence recur( recFields );
695 setRecurrence( recur ); 697 setRecurrence( recur );
696 } 698 }
697 699
698} 700}
699 701
700 702
701int OPimEvent::parent() const 703int OPimEvent::parent() const
702{ 704{
703 return data->parent; 705 return data->parent;
704} 706}
705 707
706 708
707void OPimEvent::setParent( int uid ) 709void OPimEvent::setParent( int uid )
708{ 710{
709 changeOrModify(); 711 changeOrModify();
710 data->parent = uid; 712 data->parent = uid;
711} 713}
712 714
713 715
714QArray<int> OPimEvent::children() const 716QArray<int> OPimEvent::children() const
715{ 717{
716 if ( !data->child ) return QArray<int>(); 718 if ( !data->child ) return QArray<int>();
717 else 719 else
718 return data->child->copy(); 720 return data->child->copy();
719} 721}
720 722
721 723
722void OPimEvent::setChildren( const QArray<int>& arr ) 724void OPimEvent::setChildren( const QArray<int>& arr )
723{ 725{
724 changeOrModify(); 726 changeOrModify();
725 if ( data->child ) delete data->child; 727 if ( data->child ) delete data->child;
726 728
727 data->child = new QArray<int>( arr ); 729 data->child = new QArray<int>( arr );
728 data->child->detach(); 730 data->child->detach();
729} 731}
730 732
731 733
732void OPimEvent::addChild( int uid ) 734void OPimEvent::addChild( int uid )
733{ 735{
734 changeOrModify(); 736 changeOrModify();
735 if ( !data->child ) 737 if ( !data->child )
736 { 738 {
737 data->child = new QArray<int>( 1 ); 739 data->child = new QArray<int>( 1 );
738 ( *data->child ) [ 0 ] = uid; 740 ( *data->child ) [ 0 ] = uid;
739 } 741 }
740 else 742 else
741 { 743 {
742 int count = data->child->count(); 744 int count = data->child->count();
743 data->child->resize( count + 1 ); 745 data->child->resize( count + 1 );
744 ( *data->child ) [ count ] = uid; 746 ( *data->child ) [ count ] = uid;
745 } 747 }
746} 748}
747 749
748 750
749void OPimEvent::removeChild( int uid ) 751void OPimEvent::removeChild( int uid )
750{ 752{
751 if ( !data->child || !data->child->contains( uid ) ) return ; 753 if ( !data->child || !data->child->contains( uid ) ) return ;
752 changeOrModify(); 754 changeOrModify();
753 QArray<int> newAr( data->child->count() - 1 ); 755 QArray<int> newAr( data->child->count() - 1 );
754 int j = 0; 756 int j = 0;
755 uint count = data->child->count(); 757 uint count = data->child->count();
756 for ( uint i = 0; i < count; i++ ) 758 for ( uint i = 0; i < count; i++ )
757 { 759 {
758 if ( ( *data->child ) [ i ] != uid ) 760 if ( ( *data->child ) [ i ] != uid )
759 { 761 {
760 newAr[ j ] = ( *data->child ) [ i ]; 762 newAr[ j ] = ( *data->child ) [ i ];
761 j++; 763 j++;
762 } 764 }
763 } 765 }
764 ( *data->child ) = newAr; 766 ( *data->child ) = newAr;
765} 767}
766 768
767 769
768struct OEffectiveEvent::Data : public QShared 770struct OEffectiveEvent::Data : public QShared
769{ 771{
770 Data() : QShared() 772 Data() : QShared()
771 {} 773 {}
772 OPimEvent event; 774 OPimEvent event;
773 QDate date; 775 QDate date;
774 QTime start, end; 776 QTime start, end;
775 QDate startDate, endDate; 777 QDate startDate, endDate;
776bool dates : 1; 778bool dates : 1;
777}; 779};
778 780
779 781
780OEffectiveEvent::OEffectiveEvent() 782OEffectiveEvent::OEffectiveEvent()
781{ 783{
782 data = new Data; 784 data = new Data;
783 data->date = QDate::currentDate(); 785 data->date = QDate::currentDate();
784 data->start = data->end = QTime::currentTime(); 786 data->start = data->end = QTime::currentTime();
785 data->dates = false; 787 data->dates = false;
786} 788}
787 789
788 790
789OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate, 791OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate,
790 Position pos ) 792 Position pos )
791{ 793{
792 data = new Data; 794 data = new Data;
793 data->event = ev; 795 data->event = ev;
794 data->date = startDate; 796 data->date = startDate;
795 if ( pos & Start ) 797 if ( pos & Start )
796 data->start = ev.startDateTime().time(); 798 data->start = ev.startDateTime().time();
797 else 799 else
798 data->start = QTime( 0, 0, 0 ); 800 data->start = QTime( 0, 0, 0 );
799 801
800 if ( pos & End ) 802 if ( pos & End )
801 data->end = ev.endDateTime().time(); 803 data->end = ev.endDateTime().time();
802 else 804 else
803 data->end = QTime( 23, 59, 59 ); 805 data->end = QTime( 23, 59, 59 );
804 806
805 data->dates = false; 807 data->dates = false;
806} 808}
807 809
808 810
809OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev ) 811OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev )
810{ 812{
811 data = ev.data; 813 data = ev.data;
812 data->ref(); 814 data->ref();
813} 815}
814 816
815 817
816OEffectiveEvent::~OEffectiveEvent() 818OEffectiveEvent::~OEffectiveEvent()
817{ 819{
818 if ( data->deref() ) 820 if ( data->deref() )
819 { 821 {
820 delete data; 822 delete data;
821 data = 0; 823 data = 0;
822 } 824 }
823} 825}
824 826
825 827
826OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) 828OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev )
827{ 829{
828 if ( *this == ev ) return * this; 830 if ( *this == ev ) return * this;
829 831
830 ev.data->ref(); 832 ev.data->ref();
831 deref(); 833 deref();
832 data = ev.data; 834 data = ev.data;
833 835
834 return *this; 836 return *this;
835} 837}
836 838
837 839
838void OEffectiveEvent::setStartTime( const QTime& ti ) 840void OEffectiveEvent::setStartTime( const QTime& ti )
839{ 841{
840 changeOrModify(); 842 changeOrModify();
841 data->start = ti; 843 data->start = ti;
842} 844}
843 845
844 846
845void OEffectiveEvent::setEndTime( const QTime& en ) 847void OEffectiveEvent::setEndTime( const QTime& en )
846{ 848{
847 changeOrModify(); 849 changeOrModify();
848 data->end = en; 850 data->end = en;
849} 851}
850 852
851 853
852void OEffectiveEvent::setEvent( const OPimEvent& ev ) 854void OEffectiveEvent::setEvent( const OPimEvent& ev )
853{ 855{
854 changeOrModify(); 856 changeOrModify();
855 data->event = ev; 857 data->event = ev;
856} 858}
857 859
858 860
859void OEffectiveEvent::setDate( const QDate& da ) 861void OEffectiveEvent::setDate( const QDate& da )
860{ 862{
861 changeOrModify(); 863 changeOrModify();
862 data->date = da; 864 data->date = da;
863} 865}
864 866
865 867
866void OEffectiveEvent::setEffectiveDates( const QDate& from, 868void OEffectiveEvent::setEffectiveDates( const QDate& from,
867 const QDate& to ) 869 const QDate& to )
868{ 870{
869 if ( !from.isValid() ) 871 if ( !from.isValid() )
870 { 872 {
871 data->dates = false; 873 data->dates = false;
872 return ; 874 return ;
873 } 875 }
874 876
875 data->startDate = from; 877 data->startDate = from;
876 data->endDate = to; 878 data->endDate = to;
877} 879}
878 880
879 881
880QString OEffectiveEvent::description() const 882QString OEffectiveEvent::description() const
881{ 883{
882 return data->event.description(); 884 return data->event.description();
883} 885}
884 886
885 887
886QString OEffectiveEvent::location() const 888QString OEffectiveEvent::location() const
887{ 889{
888 return data->event.location(); 890 return data->event.location();
889} 891}
890 892
891 893
892QString OEffectiveEvent::note() const 894QString OEffectiveEvent::note() const
893{ 895{
894 return data->event.note(); 896 return data->event.note();
895} 897}
896 898
897 899
898OPimEvent OEffectiveEvent::event() const 900OPimEvent OEffectiveEvent::event() const
899{ 901{
900 return data->event; 902 return data->event;
901} 903}
902 904
903 905
904QTime OEffectiveEvent::startTime() const 906QTime OEffectiveEvent::startTime() const
905{ 907{
906 return data->start; 908 return data->start;
907} 909}
908 910
909 911
910QTime OEffectiveEvent::endTime() const 912QTime OEffectiveEvent::endTime() const
911{ 913{
912 return data->end; 914 return data->end;
913} 915}
914 916
915 917
916QDate OEffectiveEvent::date() const 918QDate OEffectiveEvent::date() const
917{ 919{
918 return data->date; 920 return data->date;
919} 921}
920 922
921 923
922int OEffectiveEvent::length() const 924int OEffectiveEvent::length() const
923{ 925{
924 return ( data->end.hour() * 60 - data->start.hour() * 60 ) 926 return ( data->end.hour() * 60 - data->start.hour() * 60 )
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp
index 573340a..0f863aa 100644
--- a/libopie2/opiepim/core/opimnotifymanager.cpp
+++ b/libopie2/opiepim/core/opimnotifymanager.cpp
@@ -1,249 +1,250 @@
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#include "opimnotifymanager.h" 30#include "opimnotifymanager.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimdateconversion.h> 33#include <opie2/opimdateconversion.h>
34#include <opie2/odebug.h>
34 35
35/* QT */ 36/* QT */
36#include <qstringlist.h> 37#include <qstringlist.h>
37 38
38namespace Opie 39namespace Opie
39{ 40{
40 41
41OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al ) 42OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al )
42 : m_rem( rem ), m_al( al ) 43 : m_rem( rem ), m_al( al )
43{} 44{}
44 45
45 46
46OPimNotifyManager::~OPimNotifyManager() 47OPimNotifyManager::~OPimNotifyManager()
47{} 48{}
48 49
49 50
50/* use static_cast and type instead of dynamic... */ 51/* use static_cast and type instead of dynamic... */
51void OPimNotifyManager::add( const OPimNotify& noti ) 52void OPimNotifyManager::add( const OPimNotify& noti )
52{ 53{
53 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) 54 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) )
54 { 55 {
55 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 56 const OPimReminder & rem = static_cast<const OPimReminder&>( noti );
56 m_rem.append( rem ); 57 m_rem.append( rem );
57 } 58 }
58 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 59 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) )
59 { 60 {
60 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 61 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
61 m_al.append( al ); 62 m_al.append( al );
62 } 63 }
63} 64}
64 65
65 66
66void OPimNotifyManager::remove( const OPimNotify& noti ) 67void OPimNotifyManager::remove( const OPimNotify& noti )
67{ 68{
68 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) 69 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) )
69 { 70 {
70 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 71 const OPimReminder & rem = static_cast<const OPimReminder&>( noti );
71 m_rem.remove( rem ); 72 m_rem.remove( rem );
72 } 73 }
73 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 74 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) )
74 { 75 {
75 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 76 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
76 m_al.remove( al ); 77 m_al.remove( al );
77 } 78 }
78} 79}
79 80
80 81
81void OPimNotifyManager::replace( const OPimNotify& noti ) 82void OPimNotifyManager::replace( const OPimNotify& noti )
82{ 83{
83 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) ) 84 if ( noti.type() == QString::fromLatin1( "OPimReminder" ) )
84 { 85 {
85 const OPimReminder & rem = static_cast<const OPimReminder&>( noti ); 86 const OPimReminder & rem = static_cast<const OPimReminder&>( noti );
86 m_rem.remove( rem ); 87 m_rem.remove( rem );
87 m_rem.append( rem ); 88 m_rem.append( rem );
88 } 89 }
89 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) ) 90 else if ( noti.type() == QString::fromLatin1( "OPimAlarm" ) )
90 { 91 {
91 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti ); 92 const OPimAlarm & al = static_cast<const OPimAlarm&>( noti );
92 m_al.remove( al ); 93 m_al.remove( al );
93 m_al.append( al ); 94 m_al.append( al );
94 } 95 }
95} 96}
96 97
97 98
98OPimNotifyManager::Reminders OPimNotifyManager::reminders() const 99OPimNotifyManager::Reminders OPimNotifyManager::reminders() const
99{ 100{
100 return m_rem; 101 return m_rem;
101} 102}
102 103
103 104
104OPimNotifyManager::Alarms OPimNotifyManager::alarms() const 105OPimNotifyManager::Alarms OPimNotifyManager::alarms() const
105{ 106{
106 return m_al; 107 return m_al;
107} 108}
108 109
109 110
110OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const 111OPimAlarm OPimNotifyManager::alarmAtDateTime( const QDateTime& when, bool& found ) const
111{ 112{
112 Alarms::ConstIterator it; 113 Alarms::ConstIterator it;
113 found = true; 114 found = true;
114 115
115 for ( it = m_al.begin(); it != m_al.end(); ++it ) 116 for ( it = m_al.begin(); it != m_al.end(); ++it )
116 { 117 {
117 if ( ( *it ).dateTime() == when ) 118 if ( ( *it ).dateTime() == when )
118 return ( *it ); 119 return ( *it );
119 } 120 }
120 121
121 // Fall through if nothing could be found 122 // Fall through if nothing could be found
122 found = false; 123 found = false;
123 OPimAlarm empty; 124 OPimAlarm empty;
124 return empty; 125 return empty;
125} 126}
126 127
127 128
128void OPimNotifyManager::setAlarms( const Alarms& al ) 129void OPimNotifyManager::setAlarms( const Alarms& al )
129{ 130{
130 m_al = al; 131 m_al = al;
131} 132}
132 133
133 134
134void OPimNotifyManager::setReminders( const Reminders& rem ) 135void OPimNotifyManager::setReminders( const Reminders& rem )
135{ 136{
136 m_rem = rem; 137 m_rem = rem;
137} 138}
138 139
139 140
140/* FIXME!!! */ 141/* FIXME!!! */
141/** 142/**
142 * The idea is to check if the provider for our service 143 * The idea is to check if the provider for our service
143 * is online 144 * is online
144 * if it is we will use QCOP 145 * if it is we will use QCOP
145 * if not the Factory to get the backend... 146 * if not the Factory to get the backend...
146 * Qtopia1.6 services would be kewl to have here.... 147 * Qtopia1.6 services would be kewl to have here....
147 */ 148 */
148void OPimNotifyManager::registerNotify( const OPimNotify& ) 149void OPimNotifyManager::registerNotify( const OPimNotify& )
149{ 150{
150} 151}
151 152
152 153
153/* FIXME!!! */ 154/* FIXME!!! */
154/** 155/**
155 * same as above... 156 * same as above...
156 * Also implement Url model 157 * Also implement Url model
157 * have a MainWindow.... 158 * have a MainWindow....
158 */ 159 */
159void OPimNotifyManager::deregister( const OPimNotify& ) 160void OPimNotifyManager::deregister( const OPimNotify& )
160{ 161{
161} 162}
162 163
163 164
164bool OPimNotifyManager::isEmpty() const 165bool OPimNotifyManager::isEmpty() const
165{ 166{
166 qWarning( "is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); 167 owarn << "is Empty called on OPimNotifyManager " << m_rem.count() << " " << m_al.count() << "" << oendl;
167 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; 168 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
168 else return false; 169 else return false;
169} 170}
170 171
171 172
172// Taken from otodoaccessxml.. code duplication bad. any alternative? 173// Taken from otodoaccessxml.. code duplication bad. any alternative?
173QString OPimNotifyManager::alarmsToString() const 174QString OPimNotifyManager::alarmsToString() const
174{ 175{
175 QString str; 176 QString str;
176 177
177 OPimNotifyManager::Alarms alarms = m_al; 178 OPimNotifyManager::Alarms alarms = m_al;
178 if ( !alarms.isEmpty() ) 179 if ( !alarms.isEmpty() )
179 { 180 {
180 QStringList als; 181 QStringList als;
181 OPimNotifyManager::Alarms::Iterator it = alarms.begin(); 182 OPimNotifyManager::Alarms::Iterator it = alarms.begin();
182 for ( ; it != alarms.end(); ++it ) 183 for ( ; it != alarms.end(); ++it )
183 { 184 {
184 /* only if time is valid */ 185 /* only if time is valid */
185 if ( ( *it ).dateTime().isValid() ) 186 if ( ( *it ).dateTime().isValid() )
186 { 187 {
187 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() ) 188 als << OPimDateConversion::dateTimeToString( ( *it ).dateTime() )
188 + ":" + QString::number( ( *it ).duration() ) 189 + ":" + QString::number( ( *it ).duration() )
189 + ":" + QString::number( ( *it ).sound() ) 190 + ":" + QString::number( ( *it ).sound() )
190 + ":"; 191 + ":";
191 } 192 }
192 } 193 }
193 // now write the list 194 // now write the list
194 qWarning( "als: %s", als.join( "____________" ).latin1() ); 195 owarn << "als: " << als.join( "____________" ) << "" << oendl;
195 str = als.join( ";" ); 196 str = als.join( ";" );
196 } 197 }
197 198
198 return str; 199 return str;
199} 200}
200 201
201 202
202QString OPimNotifyManager::remindersToString() const 203QString OPimNotifyManager::remindersToString() const
203{ 204{
204 QString str; 205 QString str;
205 206
206 OPimNotifyManager::Reminders reminders = m_rem; 207 OPimNotifyManager::Reminders reminders = m_rem;
207 if ( !reminders.isEmpty() ) 208 if ( !reminders.isEmpty() )
208 { 209 {
209 OPimNotifyManager::Reminders::Iterator it = reminders.begin(); 210 OPimNotifyManager::Reminders::Iterator it = reminders.begin();
210 QStringList records; 211 QStringList records;
211 for ( ; it != reminders.end(); ++it ) 212 for ( ; it != reminders.end(); ++it )
212 { 213 {
213 records << QString::number( ( *it ).recordUid() ); 214 records << QString::number( ( *it ).recordUid() );
214 } 215 }
215 str = records.join( ";" ); 216 str = records.join( ";" );
216 } 217 }
217 218
218 return str; 219 return str;
219} 220}
220 221
221 222
222void OPimNotifyManager::alarmsFromString( const QString& str ) 223void OPimNotifyManager::alarmsFromString( const QString& str )
223{ 224{
224 QStringList als = QStringList::split( ";", str ); 225 QStringList als = QStringList::split( ";", str );
225 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it ) 226 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it )
226 { 227 {
227 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty 228 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty
228 qWarning( "alarm: %s", alarm.join( "___" ).latin1() ); 229 owarn << "alarm: " << alarm.join( "___" ) << "" << oendl;
229 qWarning( "alarm[0]: %s %s", alarm[ 0 ].latin1(), 230 qWarning( "alarm[0]: %s %s", alarm[ 0 ].latin1(),
230 OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString().latin1() ); 231 OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString().latin1() );
231 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ), 232 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ),
232 alarm[ 1 ].toInt() ); 233 alarm[ 1 ].toInt() );
233 add( al ); 234 add( al );
234 } 235 }
235} 236}
236 237
237 238
238void OPimNotifyManager::remindersFromString( const QString& str ) 239void OPimNotifyManager::remindersFromString( const QString& str )
239{ 240{
240 241
241 QStringList rems = QStringList::split( ";", str ); 242 QStringList rems = QStringList::split( ";", str );
242 for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) 243 for ( QStringList::Iterator it = rems.begin(); it != rems.end(); ++it )
243 { 244 {
244 OPimReminder rem( ( *it ).toInt() ); 245 OPimReminder rem( ( *it ).toInt() );
245 add( rem ); 246 add( rem );
246 } 247 }
247 248
248} 249}
249} 250}
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index c783092..6546d99 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -1,273 +1,273 @@
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#include "opimrecord.h" 30#include "opimrecord.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <qpe/categories.h> 33#include <qpe/categories.h>
34#include <qpe/categoryselect.h> 34#include <qpe/categoryselect.h>
35 35
36/* QT */ 36/* QT */
37 37
38namespace Opie 38namespace Opie
39{ 39{
40Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 40Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
41 41
42 42
43OPimRecord::OPimRecord( int uid ) 43OPimRecord::OPimRecord( int uid )
44 : Qtopia::Record() 44 : Qtopia::Record()
45{ 45{
46 46
47 m_lastHit = -1; 47 m_lastHit = -1;
48 setUid( uid ); 48 setUid( uid );
49} 49}
50 50
51 51
52OPimRecord::~OPimRecord() 52OPimRecord::~OPimRecord()
53{} 53{}
54 54
55 55
56OPimRecord::OPimRecord( const OPimRecord& rec ) 56OPimRecord::OPimRecord( const OPimRecord& rec )
57 : Qtopia::Record( rec ) 57 : Qtopia::Record( rec )
58{ 58{
59 ( *this ) = rec; 59 ( *this ) = rec;
60} 60}
61 61
62 62
63OPimRecord &OPimRecord::operator=( const OPimRecord& rec ) 63OPimRecord &OPimRecord::operator=( const OPimRecord& rec )
64{ 64{
65 if ( this == &rec ) return * this; 65 if ( this == &rec ) return * this;
66 66
67 Qtopia::Record::operator=( rec ); 67 Qtopia::Record::operator=( rec );
68 m_xrefman = rec.m_xrefman; 68 m_xrefman = rec.m_xrefman;
69 m_lastHit = rec.m_lastHit; 69 m_lastHit = rec.m_lastHit;
70 70
71 return *this; 71 return *this;
72} 72}
73 73
74 74
75/* 75/*
76 * category names 76 * category names
77 */ 77 */
78QStringList OPimRecord::categoryNames( const QString& appname ) const 78QStringList OPimRecord::categoryNames( const QString& appname ) const
79{ 79{
80 QStringList list; 80 QStringList list;
81 QArray<int> cats = categories(); 81 QArray<int> cats = categories();
82 Categories catDB; 82 Categories catDB;
83 catDB.load( categoryFileName() ); 83 catDB.load( categoryFileName() );
84 84
85 for ( uint i = 0; i < cats.count(); i++ ) 85 for ( uint i = 0; i < cats.count(); i++ )
86 { 86 {
87 list << catDB.label( appname, cats[ i ] ); 87 list << catDB.label( appname, cats[ i ] );
88 } 88 }
89 89
90 return list; 90 return list;
91} 91}
92 92
93 93
94void OPimRecord::setCategoryNames( const QStringList& ) 94void OPimRecord::setCategoryNames( const QStringList& )
95{ 95{
96} 96}
97 97
98 98
99void OPimRecord::addCategoryName( const QString& ) 99void OPimRecord::addCategoryName( const QString& )
100{ 100{
101 Categories catDB; 101 Categories catDB;
102 catDB.load( categoryFileName() ); 102 catDB.load( categoryFileName() );
103 103
104 104
105} 105}
106 106
107 107
108bool OPimRecord::isEmpty() const 108bool OPimRecord::isEmpty() const
109{ 109{
110 return ( uid() == 0 ); 110 return ( uid() == 0 );
111} 111}
112 112
113 113
114/*QString OPimRecord::crossToString()const { 114/*QString OPimRecord::crossToString()const {
115 QString str; 115 QString str;
116 QMap<QString, QArray<int> >::ConstIterator it; 116 QMap<QString, QArray<int> >::ConstIterator it;
117 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 117 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
118 QArray<int> id = it.data(); 118 QArray<int> id = it.data();
119 for ( uint i = 0; i < id.size(); ++i ) { 119 for ( uint i = 0; i < id.size(); ++i ) {
120 str += it.key() + "," + QString::number( i ) + ";"; 120 str += it.key() + "," + QString::number( i ) + ";";
121 } 121 }
122 } 122 }
123 str = str.remove( str.length()-1, 1); // strip the ; 123 str = str.remove( str.length()-1, 1); // strip the ;
124 //qWarning("IDS " + str ); 124 //owarn << "IDS " + str << oendl;
125 125
126 return str; 126 return str;
127 }*/ 127 }*/
128/* if uid = 1 assign a new one */ 128/* if uid = 1 assign a new one */
129void OPimRecord::setUid( int uid ) 129void OPimRecord::setUid( int uid )
130{ 130{
131 if ( uid == 1 ) 131 if ( uid == 1 )
132 uid = uidGen().generate(); 132 uid = uidGen().generate();
133 133
134 Qtopia::Record::setUid( uid ); 134 Qtopia::Record::setUid( uid );
135}; 135};
136 136
137 137
138Qtopia::UidGen &OPimRecord::uidGen() 138Qtopia::UidGen &OPimRecord::uidGen()
139{ 139{
140 return m_uidGen; 140 return m_uidGen;
141} 141}
142 142
143 143
144OPimXRefManager &OPimRecord::xrefmanager() 144OPimXRefManager &OPimRecord::xrefmanager()
145{ 145{
146 return m_xrefman; 146 return m_xrefman;
147} 147}
148 148
149 149
150int OPimRecord::rtti() const 150int OPimRecord::rtti() const
151{ 151{
152 return 0; 152 return 0;
153} 153}
154 154
155/** 155/**
156 * now let's put our data into the stream 156 * now let's put our data into the stream
157 */ 157 */
158/* 158/*
159 * First read UID 159 * First read UID
160 * Categories 160 * Categories
161 * XRef 161 * XRef
162 */ 162 */
163bool OPimRecord::loadFromStream( QDataStream& stream ) 163bool OPimRecord::loadFromStream( QDataStream& stream )
164{ 164{
165 int Int; 165 int Int;
166 uint UInt; 166 uint UInt;
167 stream >> Int; 167 stream >> Int;
168 setUid( Int ); 168 setUid( Int );
169 169
170 /** Categories */ 170 /** Categories */
171 stream >> UInt; 171 stream >> UInt;
172 QArray<int> array( UInt ); 172 QArray<int> array( UInt );
173 for ( uint i = 0; i < UInt; i++ ) 173 for ( uint i = 0; i < UInt; i++ )
174 { 174 {
175 stream >> array[ i ]; 175 stream >> array[ i ];
176 } 176 }
177 setCategories( array ); 177 setCategories( array );
178 178
179 /* 179 /*
180 * now we do the X-Ref stuff 180 * now we do the X-Ref stuff
181 */ 181 */
182 OPimXRef xref; 182 OPimXRef xref;
183 stream >> UInt; 183 stream >> UInt;
184 for ( uint i = 0; i < UInt; i++ ) 184 for ( uint i = 0; i < UInt; i++ )
185 { 185 {
186 xref.setPartner( OPimXRef::One, partner( stream ) ); 186 xref.setPartner( OPimXRef::One, partner( stream ) );
187 xref.setPartner( OPimXRef::Two, partner( stream ) ); 187 xref.setPartner( OPimXRef::Two, partner( stream ) );
188 m_xrefman.add( xref ); 188 m_xrefman.add( xref );
189 } 189 }
190 190
191 return true; 191 return true;
192} 192}
193 193
194 194
195bool OPimRecord::saveToStream( QDataStream& stream ) const 195bool OPimRecord::saveToStream( QDataStream& stream ) const
196{ 196{
197 /** UIDs */ 197 /** UIDs */
198 198
199 stream << uid(); 199 stream << uid();
200 200
201 /** Categories */ 201 /** Categories */
202 stream << categories().count(); 202 stream << categories().count();
203 for ( uint i = 0; i < categories().count(); i++ ) 203 for ( uint i = 0; i < categories().count(); i++ )
204 { 204 {
205 stream << categories() [ i ]; 205 stream << categories() [ i ];
206 } 206 }
207 207
208 /* 208 /*
209 * first the XRef count 209 * first the XRef count
210 * then the xrefs 210 * then the xrefs
211 */ 211 */
212 stream << m_xrefman.list().count(); 212 stream << m_xrefman.list().count();
213 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); 213 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
214 it != m_xrefman.list().end(); ++it ) 214 it != m_xrefman.list().end(); ++it )
215 { 215 {
216 flush( ( *it ).partner( OPimXRef::One ), stream ); 216 flush( ( *it ).partner( OPimXRef::One ), stream );
217 flush( ( *it ).partner( OPimXRef::Two ), stream ); 217 flush( ( *it ).partner( OPimXRef::Two ), stream );
218 } 218 }
219 return true; 219 return true;
220} 220}
221 221
222 222
223void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const 223void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const
224{ 224{
225 str << par.service(); 225 str << par.service();
226 str << par.uid(); 226 str << par.uid();
227 str << par.field(); 227 str << par.field();
228} 228}
229 229
230 230
231OPimXRefPartner OPimRecord::partner( QDataStream& stream ) 231OPimXRefPartner OPimRecord::partner( QDataStream& stream )
232{ 232{
233 OPimXRefPartner par; 233 OPimXRefPartner par;
234 QString str; 234 QString str;
235 int i; 235 int i;
236 236
237 stream >> str; 237 stream >> str;
238 par.setService( str ); 238 par.setService( str );
239 239
240 stream >> i; 240 stream >> i;
241 par.setUid( i ); 241 par.setUid( i );
242 242
243 stream >> i ; 243 stream >> i ;
244 par.setField( i ); 244 par.setField( i );
245 245
246 return par; 246 return par;
247} 247}
248 248
249 249
250void OPimRecord::setLastHitField( int lastHit ) const 250void OPimRecord::setLastHitField( int lastHit ) const
251{ 251{
252 m_lastHit = lastHit; 252 m_lastHit = lastHit;
253} 253}
254 254
255 255
256int OPimRecord::lastHitField() const 256int OPimRecord::lastHitField() const
257{ 257{
258 return m_lastHit; 258 return m_lastHit;
259} 259}
260 260
261 261
262QMap<QString, QString> OPimRecord::toExtraMap() const 262QMap<QString, QString> OPimRecord::toExtraMap() const
263{ 263{
264 return customMap; 264 return customMap;
265} 265}
266 266
267 267
268void OPimRecord::setExtraMap( const QMap<QString, QString>& map ) 268void OPimRecord::setExtraMap( const QMap<QString, QString>& map )
269{ 269{
270 customMap = map; 270 customMap = map;
271} 271}
272 272
273} 273}
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index be21b1b..fefceb5 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -1,188 +1,191 @@
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#include "opimtimezone.h" 30#include "opimtimezone.h"
31 31
32/* OPIE */
33#include <opie2/odebug.h>
34
32/* STD */ 35/* STD */
33#include <stdio.h> 36#include <stdio.h>
34#include <stdlib.h> 37#include <stdlib.h>
35#include <sys/types.h> 38#include <sys/types.h>
36 39
37namespace Opie 40namespace Opie
38{ 41{
39 42
40QDateTime utcTime( time_t t ) 43QDateTime utcTime( time_t t )
41{ 44{
42 tm * broken = ::gmtime( &t ); 45 tm * broken = ::gmtime( &t );
43 QDateTime ret; 46 QDateTime ret;
44 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); 47 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) );
45 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); 48 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
46 return ret; 49 return ret;
47} 50}
48QDateTime utcTime( time_t t, const QString& zone ) 51QDateTime utcTime( time_t t, const QString& zone )
49{ 52{
50 QCString org = ::getenv( "TZ" ); 53 QCString org = ::getenv( "TZ" );
51#ifndef Q_OS_MACX // Following line causes bus errors on Mac 54#ifndef Q_OS_MACX // Following line causes bus errors on Mac
52 55
53 ::setenv( "TZ", zone.latin1(), true ); 56 ::setenv( "TZ", zone.latin1(), true );
54 ::tzset(); 57 ::tzset();
55 58
56 tm* broken = ::localtime( &t ); 59 tm* broken = ::localtime( &t );
57 ::setenv( "TZ", org, true ); 60 ::setenv( "TZ", org, true );
58#else 61#else
59#warning "Need a replacement for MacOSX!!" 62#warning "Need a replacement for MacOSX!!"
60 63
61 tm* broken = ::localtime( &t ); 64 tm* broken = ::localtime( &t );
62#endif 65#endif
63 66
64 QDateTime ret; 67 QDateTime ret;
65 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); 68 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) );
66 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); 69 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
67 70
68 return ret; 71 return ret;
69} 72}
70time_t to_Time_t( const QDateTime& utc, const QString& str ) 73time_t to_Time_t( const QDateTime& utc, const QString& str )
71{ 74{
72 QDate d = utc.date(); 75 QDate d = utc.date();
73 QTime t = utc.time(); 76 QTime t = utc.time();
74 77
75 tm broken; 78 tm broken;
76 broken.tm_year = d.year() - 1900; 79 broken.tm_year = d.year() - 1900;
77 broken.tm_mon = d.month() - 1; 80 broken.tm_mon = d.month() - 1;
78 broken.tm_mday = d.day(); 81 broken.tm_mday = d.day();
79 broken.tm_hour = t.hour(); 82 broken.tm_hour = t.hour();
80 broken.tm_min = t.minute(); 83 broken.tm_min = t.minute();
81 broken.tm_sec = t.second(); 84 broken.tm_sec = t.second();
82 85
83 QCString org = ::getenv( "TZ" ); 86 QCString org = ::getenv( "TZ" );
84#ifndef Q_OS_MACX // Following line causes bus errors on Mac 87#ifndef Q_OS_MACX // Following line causes bus errors on Mac
85 88
86 ::setenv( "TZ", str.latin1(), true ); 89 ::setenv( "TZ", str.latin1(), true );
87 ::tzset(); 90 ::tzset();
88 91
89 time_t ti = ::mktime( &broken ); 92 time_t ti = ::mktime( &broken );
90 ::setenv( "TZ", org, true ); 93 ::setenv( "TZ", org, true );
91#else 94#else
92#warning "Need a replacement for MacOSX!!" 95#warning "Need a replacement for MacOSX!!"
93 96
94 time_t ti = ::mktime( &broken ); 97 time_t ti = ::mktime( &broken );
95#endif 98#endif
96 99
97 return ti; 100 return ti;
98} 101}
99} 102}
100 103
101namespace Opie 104namespace Opie
102{ 105{
103OPimTimeZone::OPimTimeZone( const ZoneName& zone ) 106OPimTimeZone::OPimTimeZone( const ZoneName& zone )
104 : m_name( zone ) 107 : m_name( zone )
105{} 108{}
106 109
107 110
108OPimTimeZone::~OPimTimeZone() 111OPimTimeZone::~OPimTimeZone()
109{} 112{}
110 113
111 114
112bool OPimTimeZone::isValid() const 115bool OPimTimeZone::isValid() const
113{ 116{
114 return !m_name.isEmpty(); 117 return !m_name.isEmpty();
115} 118}
116 119
117/* 120/*
118 * we will get the current timezone 121 * we will get the current timezone
119 * and ask it to convert to the timezone date 122 * and ask it to convert to the timezone date
120 */ 123 */
121QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt ) 124QDateTime OPimTimeZone::toLocalDateTime( const QDateTime& dt )
122{ 125{
123 return OPimTimeZone::current().toDateTime( dt, *this ); 126 return OPimTimeZone::current().toDateTime( dt, *this );
124} 127}
125 128
126 129
127QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt ) 130QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt )
128{ 131{
129 return OPimTimeZone::utc().toDateTime( dt, *this ); 132 return OPimTimeZone::utc().toDateTime( dt, *this );
130} 133}
131 134
132 135
133QDateTime OPimTimeZone::fromUTCDateTime( time_t t ) 136QDateTime OPimTimeZone::fromUTCDateTime( time_t t )
134{ 137{
135 return utcTime( t ); 138 return utcTime( t );
136} 139}
137 140
138 141
139QDateTime OPimTimeZone::toDateTime( time_t t ) 142QDateTime OPimTimeZone::toDateTime( time_t t )
140{ 143{
141 return utcTime( t, m_name ); 144 return utcTime( t, m_name );
142} 145}
143 146
144 147
145/* 148/*
146 * convert dt to utc using zone.m_name 149 * convert dt to utc using zone.m_name
147 * convert utc -> timeZoneDT using this->m_name 150 * convert utc -> timeZoneDT using this->m_name
148 */ 151 */
149QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone ) 152QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone )
150{ 153{
151 time_t utc = to_Time_t( dt, zone.m_name ); 154 time_t utc = to_Time_t( dt, zone.m_name );
152 qWarning( "%d %s", utc, zone.m_name.latin1() ); 155 owarn << "" << utc << " " << zone.m_name << "" << oendl;
153 return utcTime( utc, m_name ); 156 return utcTime( utc, m_name );
154} 157}
155 158
156 159
157time_t OPimTimeZone::fromDateTime( const QDateTime& time ) 160time_t OPimTimeZone::fromDateTime( const QDateTime& time )
158{ 161{
159 return to_Time_t( time, m_name ); 162 return to_Time_t( time, m_name );
160} 163}
161 164
162 165
163time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time ) 166time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time )
164{ 167{
165 return to_Time_t( time, "UTC" ); 168 return to_Time_t( time, "UTC" );
166} 169}
167 170
168 171
169OPimTimeZone OPimTimeZone::current() 172OPimTimeZone OPimTimeZone::current()
170{ 173{
171 QCString str = ::getenv( "TZ" ); 174 QCString str = ::getenv( "TZ" );
172 OPimTimeZone zone( str ); 175 OPimTimeZone zone( str );
173 return zone; 176 return zone;
174} 177}
175 178
176 179
177OPimTimeZone OPimTimeZone::utc() 180OPimTimeZone OPimTimeZone::utc()
178{ 181{
179 return OPimTimeZone( "UTC" ); 182 return OPimTimeZone( "UTC" );
180} 183}
181 184
182 185
183QString OPimTimeZone::timeZone() const 186QString OPimTimeZone::timeZone() const
184{ 187{
185 return m_name; 188 return m_name;
186} 189}
187 190
188} 191}
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp
index 47433e0..27b36a6 100644
--- a/libopie2/opiepim/core/opimtodo.cpp
+++ b/libopie2/opiepim/core/opimtodo.cpp
@@ -1,711 +1,713 @@
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#include "opimtodo.h" 30#include "opimtodo.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimstate.h> 33#include <opie2/opimstate.h>
34#include <opie2/opimrecurrence.h> 34#include <opie2/opimrecurrence.h>
35#include <opie2/opimmaintainer.h> 35#include <opie2/opimmaintainer.h>
36#include <opie2/opimnotifymanager.h> 36#include <opie2/opimnotifymanager.h>
37#include <opie2/opimresolver.h> 37#include <opie2/opimresolver.h>
38#include <opie2/odebug.h>
39
38#include <qpe/palmtopuidgen.h> 40#include <qpe/palmtopuidgen.h>
39#include <qpe/palmtoprecord.h> 41#include <qpe/palmtoprecord.h>
40#include <qpe/categories.h> 42#include <qpe/categories.h>
41#include <qpe/categoryselect.h> 43#include <qpe/categoryselect.h>
42#include <qpe/stringutil.h> 44#include <qpe/stringutil.h>
43 45
44/* QT */ 46/* QT */
45#include <qobject.h> 47#include <qobject.h>
46#include <qshared.h> 48#include <qshared.h>
47 49
48namespace Opie 50namespace Opie
49{ 51{
50 52
51struct OPimTodo::OPimTodoData : public QShared 53struct OPimTodo::OPimTodoData : public QShared
52{ 54{
53 OPimTodoData() : QShared() 55 OPimTodoData() : QShared()
54 { 56 {
55 recur = 0; 57 recur = 0;
56 state = 0; 58 state = 0;
57 maintainer = 0; 59 maintainer = 0;
58 notifiers = 0; 60 notifiers = 0;
59 }; 61 };
60 ~OPimTodoData() 62 ~OPimTodoData()
61 { 63 {
62 delete recur; 64 delete recur;
63 delete maintainer; 65 delete maintainer;
64 delete notifiers; 66 delete notifiers;
65 } 67 }
66 68
67 QDate date; 69 QDate date;
68 bool isCompleted: 1; 70 bool isCompleted: 1;
69 bool hasDate: 1; 71 bool hasDate: 1;
70 int priority; 72 int priority;
71 QString desc; 73 QString desc;
72 QString sum; 74 QString sum;
73 QMap<QString, QString> extra; 75 QMap<QString, QString> extra;
74 ushort prog; 76 ushort prog;
75 OPimState *state; 77 OPimState *state;
76 OPimRecurrence *recur; 78 OPimRecurrence *recur;
77 OPimMaintainer *maintainer; 79 OPimMaintainer *maintainer;
78 QDate start; 80 QDate start;
79 QDate completed; 81 QDate completed;
80 OPimNotifyManager *notifiers; 82 OPimNotifyManager *notifiers;
81}; 83};
82 84
83 85
84OPimTodo::OPimTodo( const OPimTodo &event ) 86OPimTodo::OPimTodo( const OPimTodo &event )
85 : OPimRecord( event ), data( event.data ) 87 : OPimRecord( event ), data( event.data )
86{ 88{
87 data->ref(); 89 data->ref();
88 // qWarning("ref up"); 90 // owarn << "ref up" << oendl;
89} 91}
90 92
91 93
92OPimTodo::~OPimTodo() 94OPimTodo::~OPimTodo()
93{ 95{
94 96
95 // qWarning("~OPimTodo " ); 97 // owarn << "~OPimTodo " << oendl;
96 if ( data->deref() ) 98 if ( data->deref() )
97 { 99 {
98 // qWarning("OPimTodo::dereffing"); 100 // owarn << "OPimTodo::dereffing" << oendl;
99 delete data; 101 delete data;
100 data = 0l; 102 data = 0l;
101 } 103 }
102} 104}
103 105
104 106
105OPimTodo::OPimTodo( bool completed, int priority, 107OPimTodo::OPimTodo( bool completed, int priority,
106 const QArray<int> &category, 108 const QArray<int> &category,
107 const QString& summary, 109 const QString& summary,
108 const QString &description, 110 const QString &description,
109 ushort progress, 111 ushort progress,
110 bool hasDate, QDate date, int uid ) 112 bool hasDate, QDate date, int uid )
111 : OPimRecord( uid ) 113 : OPimRecord( uid )
112{ 114{
113 // qWarning("OPimTodoData " + summary); 115 // owarn << "OPimTodoData " + summary << oendl;
114 setCategories( category ); 116 setCategories( category );
115 117
116 data = new OPimTodoData; 118 data = new OPimTodoData;
117 119
118 data->date = date; 120 data->date = date;
119 data->isCompleted = completed; 121 data->isCompleted = completed;
120 data->hasDate = hasDate; 122 data->hasDate = hasDate;
121 data->priority = priority; 123 data->priority = priority;
122 data->sum = summary; 124 data->sum = summary;
123 data->prog = progress; 125 data->prog = progress;
124 data->desc = Qtopia::simplifyMultiLineSpace( description ); 126 data->desc = Qtopia::simplifyMultiLineSpace( description );
125} 127}
126 128
127 129
128OPimTodo::OPimTodo( bool completed, int priority, 130OPimTodo::OPimTodo( bool completed, int priority,
129 const QStringList &category, 131 const QStringList &category,
130 const QString& summary, 132 const QString& summary,
131 const QString &description, 133 const QString &description,
132 ushort progress, 134 ushort progress,
133 bool hasDate, QDate date, int uid ) 135 bool hasDate, QDate date, int uid )
134 : OPimRecord( uid ) 136 : OPimRecord( uid )
135{ 137{
136 // qWarning("OPimTodoData" + summary); 138 // owarn << "OPimTodoData" + summary << oendl;
137 setCategories( idsFromString( category.join( ";" ) ) ); 139 setCategories( idsFromString( category.join( ";" ) ) );
138 140
139 data = new OPimTodoData; 141 data = new OPimTodoData;
140 142
141 data->date = date; 143 data->date = date;
142 data->isCompleted = completed; 144 data->isCompleted = completed;
143 data->hasDate = hasDate; 145 data->hasDate = hasDate;
144 data->priority = priority; 146 data->priority = priority;
145 data->sum = summary; 147 data->sum = summary;
146 data->prog = progress; 148 data->prog = progress;
147 data->desc = Qtopia::simplifyMultiLineSpace( description ); 149 data->desc = Qtopia::simplifyMultiLineSpace( description );
148} 150}
149 151
150 152
151bool OPimTodo::match( const QRegExp &regExp ) const 153bool OPimTodo::match( const QRegExp &regExp ) const
152{ 154{
153 if ( QString::number( data->priority ).find( regExp ) != -1 ) 155 if ( QString::number( data->priority ).find( regExp ) != -1 )
154 { 156 {
155 setLastHitField( Priority ); 157 setLastHitField( Priority );
156 return true; 158 return true;
157 } 159 }
158 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) 160 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 )
159 { 161 {
160 setLastHitField( HasDate ); 162 setLastHitField( HasDate );
161 return true; 163 return true;
162 } 164 }
163 else if ( data->desc.find( regExp ) != -1 ) 165 else if ( data->desc.find( regExp ) != -1 )
164 { 166 {
165 setLastHitField( Description ); 167 setLastHitField( Description );
166 return true; 168 return true;
167 } 169 }
168 else if ( data->sum.find( regExp ) != -1 ) 170 else if ( data->sum.find( regExp ) != -1 )
169 { 171 {
170 setLastHitField( Summary ); 172 setLastHitField( Summary );
171 return true; 173 return true;
172 } 174 }
173 return false; 175 return false;
174} 176}
175 177
176 178
177bool OPimTodo::isCompleted() const 179bool OPimTodo::isCompleted() const
178{ 180{
179 return data->isCompleted; 181 return data->isCompleted;
180} 182}
181 183
182 184
183bool OPimTodo::hasDueDate() const 185bool OPimTodo::hasDueDate() const
184{ 186{
185 return data->hasDate; 187 return data->hasDate;
186} 188}
187 189
188 190
189bool OPimTodo::hasStartDate() const 191bool OPimTodo::hasStartDate() const
190{ 192{
191 return data->start.isValid(); 193 return data->start.isValid();
192} 194}
193 195
194 196
195bool OPimTodo::hasCompletedDate() const 197bool OPimTodo::hasCompletedDate() const
196{ 198{
197 return data->completed.isValid(); 199 return data->completed.isValid();
198} 200}
199 201
200 202
201int OPimTodo::priority() const 203int OPimTodo::priority() const
202{ 204{
203 return data->priority; 205 return data->priority;
204} 206}
205 207
206 208
207QString OPimTodo::summary() const 209QString OPimTodo::summary() const
208{ 210{
209 return data->sum; 211 return data->sum;
210} 212}
211 213
212 214
213ushort OPimTodo::progress() const 215ushort OPimTodo::progress() const
214{ 216{
215 return data->prog; 217 return data->prog;
216} 218}
217 219
218 220
219QDate OPimTodo::dueDate() const 221QDate OPimTodo::dueDate() const
220{ 222{
221 return data->date; 223 return data->date;
222} 224}
223 225
224 226
225QDate OPimTodo::startDate() const 227QDate OPimTodo::startDate() const
226{ 228{
227 return data->start; 229 return data->start;
228} 230}
229 231
230 232
231QDate OPimTodo::completedDate() const 233QDate OPimTodo::completedDate() const
232{ 234{
233 return data->completed; 235 return data->completed;
234} 236}
235 237
236 238
237QString OPimTodo::description() const 239QString OPimTodo::description() const
238{ 240{
239 return data->desc; 241 return data->desc;
240} 242}
241 243
242 244
243bool OPimTodo::hasState() const 245bool OPimTodo::hasState() const
244{ 246{
245 if ( !data->state ) return false; 247 if ( !data->state ) return false;
246 return ( data->state->state() != OPimState::Undefined ); 248 return ( data->state->state() != OPimState::Undefined );
247} 249}
248 250
249 251
250OPimState OPimTodo::state() const 252OPimState OPimTodo::state() const
251{ 253{
252 if ( !data->state ) 254 if ( !data->state )
253 { 255 {
254 OPimState state; 256 OPimState state;
255 return state; 257 return state;
256 } 258 }
257 259
258 return ( *data->state ); 260 return ( *data->state );
259} 261}
260 262
261 263
262bool OPimTodo::hasRecurrence() const 264bool OPimTodo::hasRecurrence() const
263{ 265{
264 if ( !data->recur ) return false; 266 if ( !data->recur ) return false;
265 return data->recur->doesRecur(); 267 return data->recur->doesRecur();
266} 268}
267 269
268 270
269OPimRecurrence OPimTodo::recurrence() const 271OPimRecurrence OPimTodo::recurrence() const
270{ 272{
271 if ( !data->recur ) return OPimRecurrence(); 273 if ( !data->recur ) return OPimRecurrence();
272 274
273 return ( *data->recur ); 275 return ( *data->recur );
274} 276}
275 277
276 278
277bool OPimTodo::hasMaintainer() const 279bool OPimTodo::hasMaintainer() const
278{ 280{
279 if ( !data->maintainer ) return false; 281 if ( !data->maintainer ) return false;
280 282
281 return ( data->maintainer->mode() != OPimMaintainer::Undefined ); 283 return ( data->maintainer->mode() != OPimMaintainer::Undefined );
282} 284}
283 285
284 286
285OPimMaintainer OPimTodo::maintainer() const 287OPimMaintainer OPimTodo::maintainer() const
286{ 288{
287 if ( !data->maintainer ) return OPimMaintainer(); 289 if ( !data->maintainer ) return OPimMaintainer();
288 290
289 return ( *data->maintainer ); 291 return ( *data->maintainer );
290} 292}
291 293
292 294
293void OPimTodo::setCompleted( bool completed ) 295void OPimTodo::setCompleted( bool completed )
294{ 296{
295 changeOrModify(); 297 changeOrModify();
296 data->isCompleted = completed; 298 data->isCompleted = completed;
297} 299}
298 300
299 301
300void OPimTodo::setHasDueDate( bool hasDate ) 302void OPimTodo::setHasDueDate( bool hasDate )
301{ 303{
302 changeOrModify(); 304 changeOrModify();
303 data->hasDate = hasDate; 305 data->hasDate = hasDate;
304} 306}
305 307
306 308
307void OPimTodo::setDescription( const QString &desc ) 309void OPimTodo::setDescription( const QString &desc )
308{ 310{
309 // qWarning( "desc " + desc ); 311 // owarn << "desc " + desc << oendl;
310 changeOrModify(); 312 changeOrModify();
311 data->desc = Qtopia::simplifyMultiLineSpace( desc ); 313 data->desc = Qtopia::simplifyMultiLineSpace( desc );
312} 314}
313 315
314 316
315void OPimTodo::setSummary( const QString& sum ) 317void OPimTodo::setSummary( const QString& sum )
316{ 318{
317 changeOrModify(); 319 changeOrModify();
318 data->sum = sum; 320 data->sum = sum;
319} 321}
320 322
321 323
322void OPimTodo::setPriority( int prio ) 324void OPimTodo::setPriority( int prio )
323{ 325{
324 changeOrModify(); 326 changeOrModify();
325 data->priority = prio; 327 data->priority = prio;
326} 328}
327 329
328 330
329void OPimTodo::setDueDate( const QDate& date ) 331void OPimTodo::setDueDate( const QDate& date )
330{ 332{
331 changeOrModify(); 333 changeOrModify();
332 data->date = date; 334 data->date = date;
333} 335}
334 336
335 337
336void OPimTodo::setStartDate( const QDate& date ) 338void OPimTodo::setStartDate( const QDate& date )
337{ 339{
338 changeOrModify(); 340 changeOrModify();
339 data->start = date; 341 data->start = date;
340} 342}
341 343
342 344
343void OPimTodo::setCompletedDate( const QDate& date ) 345void OPimTodo::setCompletedDate( const QDate& date )
344{ 346{
345 changeOrModify(); 347 changeOrModify();
346 data->completed = date; 348 data->completed = date;
347} 349}
348 350
349 351
350void OPimTodo::setState( const OPimState& state ) 352void OPimTodo::setState( const OPimState& state )
351{ 353{
352 changeOrModify(); 354 changeOrModify();
353 if ( data->state ) 355 if ( data->state )
354 ( *data->state ) = state; 356 ( *data->state ) = state;
355 else 357 else
356 data->state = new OPimState( state ); 358 data->state = new OPimState( state );
357} 359}
358 360
359 361
360void OPimTodo::setRecurrence( const OPimRecurrence& rec ) 362void OPimTodo::setRecurrence( const OPimRecurrence& rec )
361{ 363{
362 changeOrModify(); 364 changeOrModify();
363 if ( data->recur ) 365 if ( data->recur )
364 ( *data->recur ) = rec; 366 ( *data->recur ) = rec;
365 else 367 else
366 data->recur = new OPimRecurrence( rec ); 368 data->recur = new OPimRecurrence( rec );
367} 369}
368 370
369 371
370void OPimTodo::setMaintainer( const OPimMaintainer& pim ) 372void OPimTodo::setMaintainer( const OPimMaintainer& pim )
371{ 373{
372 changeOrModify(); 374 changeOrModify();
373 375
374 if ( data->maintainer ) 376 if ( data->maintainer )
375 ( *data->maintainer ) = pim; 377 ( *data->maintainer ) = pim;
376 else 378 else
377 data->maintainer = new OPimMaintainer( pim ); 379 data->maintainer = new OPimMaintainer( pim );
378} 380}
379 381
380 382
381bool OPimTodo::isOverdue( ) 383bool OPimTodo::isOverdue( )
382{ 384{
383 if ( data->hasDate && !data->isCompleted ) 385 if ( data->hasDate && !data->isCompleted )
384 return QDate::currentDate() > data->date; 386 return QDate::currentDate() > data->date;
385 return false; 387 return false;
386} 388}
387 389
388 390
389void OPimTodo::setProgress( ushort progress ) 391void OPimTodo::setProgress( ushort progress )
390{ 392{
391 changeOrModify(); 393 changeOrModify();
392 data->prog = progress; 394 data->prog = progress;
393} 395}
394 396
395 397
396QString OPimTodo::toShortText() const 398QString OPimTodo::toShortText() const
397{ 399{
398 return summary(); 400 return summary();
399} 401}
400 402
401 403
402/*! 404/*!
403 Returns a richt text string 405 Returns a richt text string
404*/ 406*/
405QString OPimTodo::toRichText() const 407QString OPimTodo::toRichText() const
406{ 408{
407 QString text; 409 QString text;
408 QStringList catlist; 410 QStringList catlist;
409 411
410 // summary 412 // summary
411 text += "<b><h3><img src=\"todo/TodoList\"> "; 413 text += "<b><h3><img src=\"todo/TodoList\"> ";
412 if ( !summary().isEmpty() ) 414 if ( !summary().isEmpty() )
413 { 415 {
414 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); 416 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" );
415 } 417 }
416 text += "</h3></b><br><hr><br>"; 418 text += "</h3></b><br><hr><br>";
417 419
418 // description 420 // description
419 if ( !description().isEmpty() ) 421 if ( !description().isEmpty() )
420 { 422 {
421 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 423 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
422 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 424 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
423 } 425 }
424 426
425 // priority 427 // priority
426 int priorityval = priority(); 428 int priorityval = priority();
427 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" + 429 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" +
428 QString::number( priorityval ) + "\"> "; 430 QString::number( priorityval ) + "\"> ";
429 431
430 switch ( priorityval ) 432 switch ( priorityval )
431 { 433 {
432 case 1 : text += QObject::tr( "Very high" ); 434 case 1 : text += QObject::tr( "Very high" );
433 break; 435 break;
434 case 2 : text += QObject::tr( "High" ); 436 case 2 : text += QObject::tr( "High" );
435 break; 437 break;
436 case 3 : text += QObject::tr( "Normal" ); 438 case 3 : text += QObject::tr( "Normal" );
437 break; 439 break;
438 case 4 : text += QObject::tr( "Low" ); 440 case 4 : text += QObject::tr( "Low" );
439 break; 441 break;
440 case 5 : text += QObject::tr( "Very low" ); 442 case 5 : text += QObject::tr( "Very low" );
441 break; 443 break;
442 }; 444 };
443 text += "<br>"; 445 text += "<br>";
444 446
445 // progress 447 // progress
446 text += "<b>" + QObject::tr( "Progress:" ) + " </b>" 448 text += "<b>" + QObject::tr( "Progress:" ) + " </b>"
447 + QString::number( progress() ) + " %<br>"; 449 + QString::number( progress() ) + " %<br>";
448 450
449 // due date 451 // due date
450 if ( hasDueDate() ) 452 if ( hasDueDate() )
451 { 453 {
452 QDate dd = dueDate(); 454 QDate dd = dueDate();
453 int off = QDate::currentDate().daysTo( dd ); 455 int off = QDate::currentDate().daysTo( dd );
454 456
455 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; 457 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
456 if ( off < 0 ) 458 if ( off < 0 )
457 text += "#FF0000"; 459 text += "#FF0000";
458 else if ( off == 0 ) 460 else if ( off == 0 )
459 text += "#FFFF00"; 461 text += "#FFFF00";
460 else if ( off > 0 ) 462 else if ( off > 0 )
461 text += "#00FF00"; 463 text += "#00FF00";
462 464
463 text += "\">" + dd.toString() + "</font><br>"; 465 text += "\">" + dd.toString() + "</font><br>";
464 } 466 }
465 467
466 // categories 468 // categories
467 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 469 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
468 text += categoryNames( "Todo List" ).join( ", " ); 470 text += categoryNames( "Todo List" ).join( ", " );
469 text += "<br>"; 471 text += "<br>";
470 472
471 return text; 473 return text;
472} 474}
473 475
474 476
475bool OPimTodo::hasNotifiers() const 477bool OPimTodo::hasNotifiers() const
476{ 478{
477 if ( !data->notifiers ) return false; 479 if ( !data->notifiers ) return false;
478 return !data->notifiers->isEmpty(); 480 return !data->notifiers->isEmpty();
479} 481}
480 482
481 483
482OPimNotifyManager& OPimTodo::notifiers() 484OPimNotifyManager& OPimTodo::notifiers()
483{ 485{
484 if ( !data->notifiers ) 486 if ( !data->notifiers )
485 data->notifiers = new OPimNotifyManager; 487 data->notifiers = new OPimNotifyManager;
486 return ( *data->notifiers ); 488 return ( *data->notifiers );
487} 489}
488 490
489 491
490const OPimNotifyManager& OPimTodo::notifiers() const 492const OPimNotifyManager& OPimTodo::notifiers() const
491{ 493{
492 if ( !data->notifiers ) 494 if ( !data->notifiers )
493 data->notifiers = new OPimNotifyManager; 495 data->notifiers = new OPimNotifyManager;
494 496
495 return ( *data->notifiers ); 497 return ( *data->notifiers );
496} 498}
497 499
498 500
499bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const 501bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const
500{ 502{
501 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 503 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
502 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 504 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
503 if ( hasDueDate() && toDoEvent.hasDueDate() ) 505 if ( hasDueDate() && toDoEvent.hasDueDate() )
504 { 506 {
505 if ( dueDate() == toDoEvent.dueDate() ) 507 if ( dueDate() == toDoEvent.dueDate() )
506 { // let's the priority decide 508 { // let's the priority decide
507 return priority() < toDoEvent.priority(); 509 return priority() < toDoEvent.priority();
508 } 510 }
509 else 511 else
510 { 512 {
511 return dueDate() < toDoEvent.dueDate(); 513 return dueDate() < toDoEvent.dueDate();
512 } 514 }
513 } 515 }
514 return false; 516 return false;
515} 517}
516 518
517 519
518bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const 520bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const
519{ 521{
520 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 522 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
521 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 523 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
522 if ( hasDueDate() && toDoEvent.hasDueDate() ) 524 if ( hasDueDate() && toDoEvent.hasDueDate() )
523 { 525 {
524 if ( dueDate() == toDoEvent.dueDate() ) 526 if ( dueDate() == toDoEvent.dueDate() )
525 { // let's the priority decide 527 { // let's the priority decide
526 return priority() <= toDoEvent.priority(); 528 return priority() <= toDoEvent.priority();
527 } 529 }
528 else 530 else
529 { 531 {
530 return dueDate() <= toDoEvent.dueDate(); 532 return dueDate() <= toDoEvent.dueDate();
531 } 533 }
532 } 534 }
533 return true; 535 return true;
534} 536}
535 537
536 538
537bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const 539bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const
538{ 540{
539 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 541 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
540 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 542 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
541 if ( hasDueDate() && toDoEvent.hasDueDate() ) 543 if ( hasDueDate() && toDoEvent.hasDueDate() )
542 { 544 {
543 if ( dueDate() == toDoEvent.dueDate() ) 545 if ( dueDate() == toDoEvent.dueDate() )
544 { // let's the priority decide 546 { // let's the priority decide
545 return priority() > toDoEvent.priority(); 547 return priority() > toDoEvent.priority();
546 } 548 }
547 else 549 else
548 { 550 {
549 return dueDate() > toDoEvent.dueDate(); 551 return dueDate() > toDoEvent.dueDate();
550 } 552 }
551 } 553 }
552 return false; 554 return false;
553} 555}
554 556
555 557
556bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const 558bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const
557{ 559{
558 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 560 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
559 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 561 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
560 if ( hasDueDate() && toDoEvent.hasDueDate() ) 562 if ( hasDueDate() && toDoEvent.hasDueDate() )
561 { 563 {
562 if ( dueDate() == toDoEvent.dueDate() ) 564 if ( dueDate() == toDoEvent.dueDate() )
563 { // let's the priority decide 565 { // let's the priority decide
564 return priority() > toDoEvent.priority(); 566 return priority() > toDoEvent.priority();
565 } 567 }
566 else 568 else
567 { 569 {
568 return dueDate() > toDoEvent.dueDate(); 570 return dueDate() > toDoEvent.dueDate();
569 } 571 }
570 } 572 }
571 return true; 573 return true;
572} 574}
573 575
574 576
575bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const 577bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
576{ 578{
577 if ( data->priority != toDoEvent.data->priority ) return false; 579 if ( data->priority != toDoEvent.data->priority ) return false;
578 if ( data->priority != toDoEvent.data->prog ) return false; 580 if ( data->priority != toDoEvent.data->prog ) return false;
579 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 581 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
580 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 582 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
581 if ( data->date != toDoEvent.data->date ) return false; 583 if ( data->date != toDoEvent.data->date ) return false;
582 if ( data->sum != toDoEvent.data->sum ) return false; 584 if ( data->sum != toDoEvent.data->sum ) return false;
583 if ( data->desc != toDoEvent.data->desc ) return false; 585 if ( data->desc != toDoEvent.data->desc ) return false;
584 if ( data->maintainer != toDoEvent.data->maintainer ) 586 if ( data->maintainer != toDoEvent.data->maintainer )
585 return false; 587 return false;
586 588
587 return OPimRecord::operator==( toDoEvent ); 589 return OPimRecord::operator==( toDoEvent );
588} 590}
589 591
590 592
591void OPimTodo::deref() 593void OPimTodo::deref()
592{ 594{
593 595
594 // qWarning("deref in ToDoEvent"); 596 // owarn << "deref in ToDoEvent" << oendl;
595 if ( data->deref() ) 597 if ( data->deref() )
596 { 598 {
597 // qWarning("deleting"); 599 // owarn << "deleting" << oendl;
598 delete data; 600 delete data;
599 data = 0; 601 data = 0;
600 } 602 }
601} 603}
602 604
603 605
604OPimTodo &OPimTodo::operator=( const OPimTodo &item ) 606OPimTodo &OPimTodo::operator=( const OPimTodo &item )
605{ 607{
606 if ( this == &item ) return * this; 608 if ( this == &item ) return * this;
607 609
608 OPimRecord::operator=( item ); 610 OPimRecord::operator=( item );
609 //qWarning("operator= ref "); 611 //owarn << "operator= ref " << oendl;
610 item.data->ref(); 612 item.data->ref();
611 deref(); 613 deref();
612 data = item.data; 614 data = item.data;
613 615
614 return *this; 616 return *this;
615} 617}
616 618
617 619
618QMap<int, QString> OPimTodo::toMap() const 620QMap<int, QString> OPimTodo::toMap() const
619{ 621{
620 QMap<int, QString> map; 622 QMap<int, QString> map;
621 623
622 map.insert( Uid, QString::number( uid() ) ); 624 map.insert( Uid, QString::number( uid() ) );
623 map.insert( Category, idsToString( categories() ) ); 625 map.insert( Category, idsToString( categories() ) );
624 map.insert( HasDate, QString::number( data->hasDate ) ); 626 map.insert( HasDate, QString::number( data->hasDate ) );
625 map.insert( Completed, QString::number( data->isCompleted ) ); 627 map.insert( Completed, QString::number( data->isCompleted ) );
626 map.insert( Description, data->desc ); 628 map.insert( Description, data->desc );
627 map.insert( Summary, data->sum ); 629 map.insert( Summary, data->sum );
628 map.insert( Priority, QString::number( data->priority ) ); 630 map.insert( Priority, QString::number( data->priority ) );
629 map.insert( DateDay, QString::number( data->date.day() ) ); 631 map.insert( DateDay, QString::number( data->date.day() ) );
630 map.insert( DateMonth, QString::number( data->date.month() ) ); 632 map.insert( DateMonth, QString::number( data->date.month() ) );
631 map.insert( DateYear, QString::number( data->date.year() ) ); 633 map.insert( DateYear, QString::number( data->date.year() ) );
632 map.insert( Progress, QString::number( data->prog ) ); 634 map.insert( Progress, QString::number( data->prog ) );
633 // map.insert( CrossReference, crossToString() ); 635 // map.insert( CrossReference, crossToString() );
634 /* FIXME!!! map.insert( State, ); 636 /* FIXME!!! map.insert( State, );
635 map.insert( Recurrence, ); 637 map.insert( Recurrence, );
636 map.insert( Reminders, ); 638 map.insert( Reminders, );
637 map. 639 map.
638 */ 640 */
639 return map; 641 return map;
640} 642}
641 643
642 644
643/** 645/**
644 * change or modify looks at the ref count and either 646 * change or modify looks at the ref count and either
645 * creates a new QShared Object or it can modify it 647 * creates a new QShared Object or it can modify it
646 * right in place 648 * right in place
647 */ 649 */
648void OPimTodo::changeOrModify() 650void OPimTodo::changeOrModify()
649{ 651{
650 if ( data->count != 1 ) 652 if ( data->count != 1 )
651 { 653 {
652 qWarning( "changeOrModify" ); 654 owarn << "changeOrModify" << oendl;
653 data->deref(); 655 data->deref();
654 OPimTodoData* d2 = new OPimTodoData(); 656 OPimTodoData* d2 = new OPimTodoData();
655 copy( data, d2 ); 657 copy( data, d2 );
656 data = d2; 658 data = d2;
657 } 659 }
658} 660}
659 661
660 662
661// WATCHOUT 663// WATCHOUT
662/* 664/*
663 * if you add something to the Data struct 665 * if you add something to the Data struct
664 * be sure to copy it here 666 * be sure to copy it here
665 */ 667 */
666void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) 668void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest )
667{ 669{
668 dest->date = src->date; 670 dest->date = src->date;
669 dest->isCompleted = src->isCompleted; 671 dest->isCompleted = src->isCompleted;
670 dest->hasDate = src->hasDate; 672 dest->hasDate = src->hasDate;
671 dest->priority = src->priority; 673 dest->priority = src->priority;
672 dest->desc = src->desc; 674 dest->desc = src->desc;
673 dest->sum = src->sum; 675 dest->sum = src->sum;
674 dest->extra = src->extra; 676 dest->extra = src->extra;
675 dest->prog = src->prog; 677 dest->prog = src->prog;
676 678
677 if ( src->state ) 679 if ( src->state )
678 dest->state = new OPimState( *src->state ); 680 dest->state = new OPimState( *src->state );
679 681
680 if ( src->recur ) 682 if ( src->recur )
681 dest->recur = new OPimRecurrence( *src->recur ); 683 dest->recur = new OPimRecurrence( *src->recur );
682 684
683 if ( src->maintainer ) 685 if ( src->maintainer )
684 dest->maintainer = new OPimMaintainer( *src->maintainer ) 686 dest->maintainer = new OPimMaintainer( *src->maintainer )
685 ; 687 ;
686 dest->start = src->start; 688 dest->start = src->start;
687 dest->completed = src->completed; 689 dest->completed = src->completed;
688 690
689 if ( src->notifiers ) 691 if ( src->notifiers )
690 dest->notifiers = new OPimNotifyManager( *src->notifiers ); 692 dest->notifiers = new OPimNotifyManager( *src->notifiers );
691} 693}
692 694
693 695
694QString OPimTodo::type() const 696QString OPimTodo::type() const
695{ 697{
696 return QString::fromLatin1( "OPimTodo" ); 698 return QString::fromLatin1( "OPimTodo" );
697} 699}
698 700
699 701
700QString OPimTodo::recordField( int /*id*/ ) const 702QString OPimTodo::recordField( int /*id*/ ) const
701{ 703{
702 return QString::null; 704 return QString::null;
703} 705}
704 706
705 707
706int OPimTodo::rtti() const 708int OPimTodo::rtti() const
707{ 709{
708 return OPimResolver::TodoList; 710 return OPimResolver::TodoList;
709} 711}
710 712
711} 713}
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp
index c4adbbd..26a68a0 100644
--- a/libopie2/opiepim/core/otodoaccess.cpp
+++ b/libopie2/opiepim/core/otodoaccess.cpp
@@ -1,101 +1,101 @@
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#include <qdatetime.h> 29#include <qdatetime.h>
30 30
31#include <qpe/alarmserver.h> 31#include <qpe/alarmserver.h>
32 32
33// #include "otodoaccesssql.h" 33// #include "otodoaccesssql.h"
34#include <opie2/otodoaccess.h> 34#include <opie2/otodoaccess.h>
35#include <opie2/obackendfactory.h> 35#include <opie2/obackendfactory.h>
36#include <opie2/opimresolver.h> 36#include <opie2/opimresolver.h>
37#include <opie2/opimglobal.h> 37#include <opie2/opimglobal.h>
38 38
39namespace Opie { 39namespace Opie {
40OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) 40OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
41 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) 41 : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end )
42{ 42{
43// if (end == 0l ) 43// if (end == 0l )
44// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); 44// m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null);
45 45
46 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! 46 // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben !
47 if (end == 0l ) 47 if (end == 0l )
48 m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend (OPimGlobal::TODOLIST, QString::null); 48 m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::defaultBackend (OPimGlobal::TODOLIST, QString::null);
49 49
50 setBackEnd( m_todoBackEnd ); 50 setBackEnd( m_todoBackEnd );
51} 51}
52OPimTodoAccess::~OPimTodoAccess() { 52OPimTodoAccess::~OPimTodoAccess() {
53// qWarning("~OPimTodoAccess"); 53// owarn << "~OPimTodoAccess" << oendl;
54} 54}
55void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { 55void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) {
56 QValueList<OPimTodo>::ConstIterator it; 56 QValueList<OPimTodo>::ConstIterator it;
57 for ( it = list.begin(); it != list.end(); ++it ) { 57 for ( it = list.begin(); it != list.end(); ++it ) {
58 replace( (*it) ); 58 replace( (*it) );
59 } 59 }
60} 60}
61OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 61OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
62 const QDate& end, 62 const QDate& end,
63 bool includeNoDates ) { 63 bool includeNoDates ) {
64 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 64 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
65 65
66 List lis( ints, this ); 66 List lis( ints, this );
67 return lis; 67 return lis;
68} 68}
69OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 69OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
70 bool includeNoDates ) { 70 bool includeNoDates ) {
71 return effectiveToDos( start, QDate::currentDate(), 71 return effectiveToDos( start, QDate::currentDate(),
72 includeNoDates ); 72 includeNoDates );
73} 73}
74OPimTodoAccess::List OPimTodoAccess::overDue() { 74OPimTodoAccess::List OPimTodoAccess::overDue() {
75 List lis( m_todoBackEnd->overDue(), this ); 75 List lis( m_todoBackEnd->overDue(), this );
76 return lis; 76 return lis;
77} 77}
78/* sort order */ 78/* sort order */
79OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 79OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
80 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, 80 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
81 filter, cat ); 81 filter, cat );
82 OPimTodoAccess::List list( ints, this ); 82 OPimTodoAccess::List list( ints, this );
83 return list; 83 return list;
84} 84}
85void OPimTodoAccess::removeAllCompleted() { 85void OPimTodoAccess::removeAllCompleted() {
86 m_todoBackEnd->removeAllCompleted(); 86 m_todoBackEnd->removeAllCompleted();
87} 87}
88QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ 88QBitArray OPimTodoAccess::backendSupport( const QString& ) const{
89 return m_todoBackEnd->supports(); 89 return m_todoBackEnd->supports();
90} 90}
91bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ 91bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{
92 return backendSupport(ar).testBit( attr ); 92 return backendSupport(ar).testBit( attr );
93} 93}
94 94
95 95
96int OPimTodoAccess::rtti() const 96int OPimTodoAccess::rtti() const
97{ 97{
98 return OPimResolver::TodoList; 98 return OPimResolver::TodoList;
99} 99}
100 100
101} 101}
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp
index 40dc297..8ce2062 100644
--- a/libopie2/opiepim/ui/opimmainwindow.cpp
+++ b/libopie2/opiepim/ui/opimmainwindow.cpp
@@ -1,181 +1,188 @@
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#include <qapplication.h> 29
30#include <qdatetime.h> 30#include "opimmainwindow.h"
31#include <qcopchannel_qws.h> 31
32/* OPIE */
33#include <opie2/opimresolver.h>
34#include <opie2/odebug.h>
32 35
33#include <qpe/sound.h> 36#include <qpe/sound.h>
34#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
35#include <qpe/qpeapplication.h> 38#include <qpe/qpeapplication.h>
36 39
37#include <opie2/opimresolver.h> 40/* QT */
38#include "opimmainwindow.h" 41#include <qapplication.h>
42#include <qdatetime.h>
43#include <qcopchannel_qws.h>
44
45
39 46
40namespace Opie { 47namespace Opie {
41OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, 48OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent,
42 const char* name, WFlags flag ) 49 const char* name, WFlags flag )
43 : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { 50 : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) {
44 51
45 /* 52 /*
46 * let's generate our QCopChannel 53 * let's generate our QCopChannel
47 */ 54 */
48 m_str = QString("QPE/"+m_service).local8Bit(); 55 m_str = QString("QPE/"+m_service).local8Bit();
49 m_channel= new QCopChannel(m_str, this ); 56 m_channel= new QCopChannel(m_str, this );
50 connect(m_channel, SIGNAL(received(const QCString&,const QByteArray&) ), 57 connect(m_channel, SIGNAL(received(const QCString&,const QByteArray&) ),
51 this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); 58 this, SLOT( appMessage(const QCString&,const QByteArray&) ) );
52 connect(qApp, SIGNAL(appMessage(const QCString&,const QByteArray&) ), 59 connect(qApp, SIGNAL(appMessage(const QCString&,const QByteArray&) ),
53 this, SLOT( appMessage(const QCString&,const QByteArray&) ) ); 60 this, SLOT( appMessage(const QCString&,const QByteArray&) ) );
54 61
55 /* connect flush and reload */ 62 /* connect flush and reload */
56 connect(qApp, SIGNAL(flush() ), 63 connect(qApp, SIGNAL(flush() ),
57 this, SLOT(flush() ) ); 64 this, SLOT(flush() ) );
58 connect(qApp, SIGNAL(reload() ), 65 connect(qApp, SIGNAL(reload() ),
59 this, SLOT(reload() ) ); 66 this, SLOT(reload() ) );
60} 67}
61OPimMainWindow::~OPimMainWindow() { 68OPimMainWindow::~OPimMainWindow() {
62 delete m_channel; 69 delete m_channel;
63} 70}
64QCopChannel* OPimMainWindow::channel() { 71QCopChannel* OPimMainWindow::channel() {
65 return m_channel; 72 return m_channel;
66} 73}
67void OPimMainWindow::doSetDocument( const QString& ) { 74void OPimMainWindow::doSetDocument( const QString& ) {
68 75
69} 76}
70void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { 77void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
71 bool needShow = false; 78 bool needShow = false;
72 /* 79 /*
73 * create demands to create 80 * create demands to create
74 * a new record... 81 * a new record...
75 */ 82 */
76 QDataStream stream(array, IO_ReadOnly); 83 QDataStream stream(array, IO_ReadOnly);
77 if ( cmd == "create()" ) { 84 if ( cmd == "create()" ) {
78 raise(); 85 raise();
79 int uid = create(); 86 int uid = create();
80 QCopEnvelope e(m_str, "created(int)" ); 87 QCopEnvelope e(m_str, "created(int)" );
81 e << uid; 88 e << uid;
82 needShow = true; 89 needShow = true;
83 }else if ( cmd == "remove(int)" ) { 90 }else if ( cmd == "remove(int)" ) {
84 int uid; 91 int uid;
85 stream >> uid; 92 stream >> uid;
86 bool rem = remove( uid ); 93 bool rem = remove( uid );
87 QCopEnvelope e(m_str, "removed(bool)" ); 94 QCopEnvelope e(m_str, "removed(bool)" );
88 e << rem; 95 e << rem;
89 needShow = true; 96 needShow = true;
90 }else if ( cmd == "beam(int)" ) { 97 }else if ( cmd == "beam(int)" ) {
91 int uid; 98 int uid;
92 stream >> uid; 99 stream >> uid;
93 beam( uid); 100 beam( uid);
94 }else if ( cmd == "show(int)" ) { 101 }else if ( cmd == "show(int)" ) {
95 raise(); 102 raise();
96 int uid; 103 int uid;
97 stream >> uid; 104 stream >> uid;
98 show( uid ); 105 show( uid );
99 needShow = true; 106 needShow = true;
100 }else if ( cmd == "edit(int)" ) { 107 }else if ( cmd == "edit(int)" ) {
101 raise(); 108 raise();
102 int uid; 109 int uid;
103 stream >> uid; 110 stream >> uid;
104 edit( uid ); 111 edit( uid );
105 }else if ( cmd == "add(int,QByteArray)" ) { 112 }else if ( cmd == "add(int,QByteArray)" ) {
106 int rtti; 113 int rtti;
107 QByteArray array; 114 QByteArray array;
108 stream >> rtti; 115 stream >> rtti;
109 stream >> array; 116 stream >> array;
110 m_fallBack = record(rtti, array ); 117 m_fallBack = record(rtti, array );
111 if (!m_fallBack) return; 118 if (!m_fallBack) return;
112 add( *m_fallBack ); 119 add( *m_fallBack );
113 delete m_fallBack; 120 delete m_fallBack;
114 }else if ( cmd == "alarm(QDateTime,int)" ) { 121 }else if ( cmd == "alarm(QDateTime,int)" ) {
115 raise(); 122 raise();
116 QDateTime dt; int uid; 123 QDateTime dt; int uid;
117 stream >> dt; 124 stream >> dt;
118 stream >> uid; 125 stream >> uid;
119 qWarning(" Date: %s Uid: %d", dt.toString().latin1(), uid ); 126 owarn << " Date: " << dt.toString() << " Uid: " << uid << "" << oendl;
120 QDateTime current = QDateTime::currentDateTime(); 127 QDateTime current = QDateTime::currentDateTime();
121 if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() ) 128 if ( current.time().hour() != dt.time().hour() && current.time().minute() != dt.time().minute() )
122 return; 129 return;
123 doAlarm( dt, uid ); 130 doAlarm( dt, uid );
124 needShow = true; 131 needShow = true;
125 } 132 }
126 133
127 if (needShow ) 134 if (needShow )
128 QPEApplication::setKeepRunning(); 135 QPEApplication::setKeepRunning();
129} 136}
130/* implement the url scripting here */ 137/* implement the url scripting here */
131void OPimMainWindow::setDocument( const QString& str) { 138void OPimMainWindow::setDocument( const QString& str) {
132 doSetDocument( str ); 139 doSetDocument( str );
133} 140}
134/* 141/*
135 * we now try to get the array demarshalled 142 * we now try to get the array demarshalled
136 * check if the rtti matches this one 143 * check if the rtti matches this one
137 */ 144 */
138OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { 145OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) {
139 if ( service() != rtti ) 146 if ( service() != rtti )
140 return 0l; 147 return 0l;
141 148
142 OPimRecord* record = OPimResolver::self()->record( rtti ); 149 OPimRecord* record = OPimResolver::self()->record( rtti );
143 QDataStream str(array, IO_ReadOnly ); 150 QDataStream str(array, IO_ReadOnly );
144 if ( !record || !record->loadFromStream(str) ) { 151 if ( !record || !record->loadFromStream(str) ) {
145 delete record; 152 delete record;
146 record = 0l; 153 record = 0l;
147 } 154 }
148 155
149 return record; 156 return record;
150} 157}
151/* 158/*
152 * get the rtti for the service 159 * get the rtti for the service
153 */ 160 */
154int OPimMainWindow::service() { 161int OPimMainWindow::service() {
155 if ( m_rtti == -1 ) 162 if ( m_rtti == -1 )
156 m_rtti = OPimResolver::self()->serviceId( m_service ); 163 m_rtti = OPimResolver::self()->serviceId( m_service );
157 164
158 return m_rtti; 165 return m_rtti;
159} 166}
160void OPimMainWindow::doAlarm( const QDateTime&, int ) { 167void OPimMainWindow::doAlarm( const QDateTime&, int ) {
161 168
162} 169}
163void OPimMainWindow::startAlarm(int count ) { 170void OPimMainWindow::startAlarm(int count ) {
164 m_alarmCount = count; 171 m_alarmCount = count;
165 m_playedCount = 0; 172 m_playedCount = 0;
166 Sound::soundAlarm(); 173 Sound::soundAlarm();
167 m_timerId = startTimer( 5000 ); 174 m_timerId = startTimer( 5000 );
168} 175}
169void OPimMainWindow::killAlarm() { 176void OPimMainWindow::killAlarm() {
170 killTimer( m_timerId ); 177 killTimer( m_timerId );
171} 178}
172void OPimMainWindow::timerEvent( QTimerEvent* e) { 179void OPimMainWindow::timerEvent( QTimerEvent* e) {
173 if ( m_playedCount <m_alarmCount ) { 180 if ( m_playedCount <m_alarmCount ) {
174 m_playedCount++; 181 m_playedCount++;
175 Sound::soundAlarm(); 182 Sound::soundAlarm();
176 }else { 183 }else {
177 killTimer( e->timerId() ); 184 killTimer( e->timerId() );
178 } 185 }
179} 186}
180 187
181} 188}