Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index f24523f..270bef3 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -1,175 +1,180 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.10 2003/04/13 18:07:10 zecke | ||
21 | * More API doc | ||
22 | * QString -> const QString& | ||
23 | * QString = 0l -> QString::null | ||
24 | * | ||
20 | * Revision 1.9 2003/03/21 10:33:09 eilers | 25 | * Revision 1.9 2003/03/21 10:33:09 eilers |
21 | * Merged speed optimized xml backend for contacts to main. | 26 | * Merged speed optimized xml backend for contacts to main. |
22 | * Added QDateTime to querybyexample. For instance, it is now possible to get | 27 | * Added QDateTime to querybyexample. For instance, it is now possible to get |
23 | * all Birthdays/Anniversaries between two dates. This should be used | 28 | * all Birthdays/Anniversaries between two dates. This should be used |
24 | * to show all birthdays in the datebook.. | 29 | * to show all birthdays in the datebook.. |
25 | * This change is sourcecode backward compatible but you have to upgrade | 30 | * This change is sourcecode backward compatible but you have to upgrade |
26 | * the binaries for today-addressbook. | 31 | * the binaries for today-addressbook. |
27 | * | 32 | * |
28 | * Revision 1.8 2003/02/21 16:52:49 zecke | 33 | * Revision 1.8 2003/02/21 16:52:49 zecke |
29 | * -Remove old Todo classes they're deprecated and today I already using the | 34 | * -Remove old Todo classes they're deprecated and today I already using the |
30 | * new API | 35 | * new API |
31 | * -Guard against self assignment in OTodo | 36 | * -Guard against self assignment in OTodo |
32 | * -Add test apps for OPIM | 37 | * -Add test apps for OPIM |
33 | * -Opiefied Event classes | 38 | * -Opiefied Event classes |
34 | * -Added TimeZone handling and pinning of TimeZones to OEvent | 39 | * -Added TimeZone handling and pinning of TimeZones to OEvent |
35 | * -Adjust ORecur and the widget to better timezone behaviour | 40 | * -Adjust ORecur and the widget to better timezone behaviour |
36 | * | 41 | * |
37 | * Revision 1.7 2003/02/16 22:25:46 zecke | 42 | * Revision 1.7 2003/02/16 22:25:46 zecke |
38 | * 0000276 Fix for that bug.. or better temp workaround | 43 | * 0000276 Fix for that bug.. or better temp workaround |
39 | * A Preferred Number is HOME|VOICE | 44 | * A Preferred Number is HOME|VOICE |
40 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test | 45 | * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test |
41 | * triggers both | 46 | * triggers both |
42 | * and the cell phone number overrides the other entries.. | 47 | * and the cell phone number overrides the other entries.. |
43 | * | 48 | * |
44 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the | 49 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the |
45 | * number | 50 | * number |
46 | * | 51 | * |
47 | * The right and final fix would be to reorder the if statement to make it | 52 | * The right and final fix would be to reorder the if statement to make it |
48 | * if else based and the less common thing put to the bottom | 53 | * if else based and the less common thing put to the bottom |
49 | * | 54 | * |
50 | * OTodoAccessVcal fix the date for beaming | 55 | * OTodoAccessVcal fix the date for beaming |
51 | * | 56 | * |
52 | * Revision 1.6 2003/01/13 15:49:31 eilers | 57 | * Revision 1.6 2003/01/13 15:49:31 eilers |
53 | * Fixing crash when businesscard.vcf is missing.. | 58 | * Fixing crash when businesscard.vcf is missing.. |
54 | * | 59 | * |
55 | * Revision 1.5 2002/12/07 13:26:22 eilers | 60 | * Revision 1.5 2002/12/07 13:26:22 eilers |
56 | * Fixing bug in storing anniversary.. | 61 | * Fixing bug in storing anniversary.. |
57 | * | 62 | * |
58 | * Revision 1.4 2002/11/13 14:14:51 eilers | 63 | * Revision 1.4 2002/11/13 14:14:51 eilers |
59 | * Added sorted for Contacts.. | 64 | * Added sorted for Contacts.. |
60 | * | 65 | * |
61 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 66 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
62 | * no default arguments in implementation | 67 | * no default arguments in implementation |
63 | * | 68 | * |
64 | * Revision 1.2 2002/11/10 15:41:53 eilers | 69 | * Revision 1.2 2002/11/10 15:41:53 eilers |
65 | * Bugfixes.. | 70 | * Bugfixes.. |
66 | * | 71 | * |
67 | * Revision 1.1 2002/11/09 14:34:52 eilers | 72 | * Revision 1.1 2002/11/09 14:34:52 eilers |
68 | * Added VCard Backend. | 73 | * Added VCard Backend. |
69 | * | 74 | * |
70 | */ | 75 | */ |
71 | #include "ocontactaccessbackend_vcard.h" | 76 | #include "ocontactaccessbackend_vcard.h" |
72 | #include "../../library/backend/vobject_p.h" | 77 | #include "../../library/backend/vobject_p.h" |
73 | #include "../../library/backend/qfiledirect_p.h" | 78 | #include "../../library/backend/qfiledirect_p.h" |
74 | 79 | ||
75 | #include <qpe/timeconversion.h> | 80 | #include <qpe/timeconversion.h> |
76 | 81 | ||
77 | #include <qfile.h> | 82 | #include <qfile.h> |
78 | 83 | ||
79 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 84 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( const QString& , const QString& filename ): |
80 | m_dirty( false ), | 85 | m_dirty( false ), |
81 | m_file( filename ) | 86 | m_file( filename ) |
82 | { | 87 | { |
83 | load(); | 88 | load(); |
84 | } | 89 | } |
85 | 90 | ||
86 | 91 | ||
87 | bool OContactAccessBackend_VCard::load () | 92 | bool OContactAccessBackend_VCard::load () |
88 | { | 93 | { |
89 | m_map.clear(); | 94 | m_map.clear(); |
90 | m_dirty = false; | 95 | m_dirty = false; |
91 | 96 | ||
92 | VObject* obj = 0l; | 97 | VObject* obj = 0l; |
93 | 98 | ||
94 | if ( QFile::exists(m_file) ){ | 99 | if ( QFile::exists(m_file) ){ |
95 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 100 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); |
96 | if ( !obj ) | 101 | if ( !obj ) |
97 | return false; | 102 | return false; |
98 | }else{ | 103 | }else{ |
99 | qWarning("File \"%s\" not found !", m_file.latin1() ); | 104 | qWarning("File \"%s\" not found !", m_file.latin1() ); |
100 | return false; | 105 | return false; |
101 | } | 106 | } |
102 | 107 | ||
103 | while ( obj ) { | 108 | while ( obj ) { |
104 | OContact con = parseVObject( obj ); | 109 | OContact con = parseVObject( obj ); |
105 | /* | 110 | /* |
106 | * if uid is 0 assign a new one | 111 | * if uid is 0 assign a new one |
107 | * this at least happens on | 112 | * this at least happens on |
108 | * Nokia6210 | 113 | * Nokia6210 |
109 | */ | 114 | */ |
110 | if ( con.uid() == 0 ){ | 115 | if ( con.uid() == 0 ){ |
111 | con.setUid( 1 ); | 116 | con.setUid( 1 ); |
112 | qWarning("assigned new uid %d",con.uid() ); | 117 | qWarning("assigned new uid %d",con.uid() ); |
113 | } | 118 | } |
114 | 119 | ||
115 | m_map.insert( con.uid(), con ); | 120 | m_map.insert( con.uid(), con ); |
116 | 121 | ||
117 | VObject *t = obj; | 122 | VObject *t = obj; |
118 | obj = nextVObjectInList(obj); | 123 | obj = nextVObjectInList(obj); |
119 | cleanVObject( t ); | 124 | cleanVObject( t ); |
120 | } | 125 | } |
121 | 126 | ||
122 | return true; | 127 | return true; |
123 | 128 | ||
124 | } | 129 | } |
125 | bool OContactAccessBackend_VCard::reload() | 130 | bool OContactAccessBackend_VCard::reload() |
126 | { | 131 | { |
127 | return load(); | 132 | return load(); |
128 | } | 133 | } |
129 | bool OContactAccessBackend_VCard::save() | 134 | bool OContactAccessBackend_VCard::save() |
130 | { | 135 | { |
131 | if (!m_dirty ) | 136 | if (!m_dirty ) |
132 | return true; | 137 | return true; |
133 | 138 | ||
134 | QFileDirect file( m_file ); | 139 | QFileDirect file( m_file ); |
135 | if (!file.open(IO_WriteOnly ) ) | 140 | if (!file.open(IO_WriteOnly ) ) |
136 | return false; | 141 | return false; |
137 | 142 | ||
138 | VObject *obj; | 143 | VObject *obj; |
139 | obj = newVObject( VCCalProp ); | 144 | obj = newVObject( VCCalProp ); |
140 | addPropValue( obj, VCVersionProp, "1.0" ); | 145 | addPropValue( obj, VCVersionProp, "1.0" ); |
141 | 146 | ||
142 | VObject *vo; | 147 | VObject *vo; |
143 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 148 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
144 | vo = createVObject( *it ); | 149 | vo = createVObject( *it ); |
145 | writeVObject( file.directHandle() , vo ); | 150 | writeVObject( file.directHandle() , vo ); |
146 | cleanVObject( vo ); | 151 | cleanVObject( vo ); |
147 | } | 152 | } |
148 | cleanStrTbl(); | 153 | cleanStrTbl(); |
149 | 154 | ||
150 | m_dirty = false; | 155 | m_dirty = false; |
151 | return true; | 156 | return true; |
152 | 157 | ||
153 | 158 | ||
154 | } | 159 | } |
155 | void OContactAccessBackend_VCard::clear () | 160 | void OContactAccessBackend_VCard::clear () |
156 | { | 161 | { |
157 | m_map.clear(); | 162 | m_map.clear(); |
158 | m_dirty = true; // ??? sure ? (se) | 163 | m_dirty = true; // ??? sure ? (se) |
159 | } | 164 | } |
160 | 165 | ||
161 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 166 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
162 | { | 167 | { |
163 | m_map.insert( newcontact.uid(), newcontact ); | 168 | m_map.insert( newcontact.uid(), newcontact ); |
164 | m_dirty = true; | 169 | m_dirty = true; |
165 | return true; | 170 | return true; |
166 | } | 171 | } |
167 | 172 | ||
168 | bool OContactAccessBackend_VCard::remove ( int uid ) | 173 | bool OContactAccessBackend_VCard::remove ( int uid ) |
169 | { | 174 | { |
170 | m_map.remove( uid ); | 175 | m_map.remove( uid ); |
171 | m_dirty = true; | 176 | m_dirty = true; |
172 | return true; | 177 | return true; |
173 | } | 178 | } |
174 | 179 | ||
175 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 180 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) |