summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index b569f8b..ffa6a7d 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -8,55 +8,60 @@
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#include <opie2/ocontactaccessbackend_vcard.h>
33#include "../../../../library/backend/vobject_p.h"
34#include "../../../../library/backend/qfiledirect_p.h"
35 32
33
34#include "vobject_p.h"
35
36/* OPIE */
37#include <opie2/ocontactaccessbackend_vcard.h>
36#include <qpe/timeconversion.h> 38#include <qpe/timeconversion.h>
37 39
40//FIXME: Hack to allow direct access to FILE* fh. Rewrite this!
41#define protected public
38#include <qfile.h> 42#include <qfile.h>
43#undef protected
39 44
40namespace Opie { 45namespace Opie {
41 46
42OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): 47OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ):
43 m_dirty( false ), 48 m_dirty( false ),
44 m_file( filename ) 49 m_file( filename )
45{ 50{
46 load(); 51 load();
47} 52}
48 53
49 54
50bool OPimContactAccessBackend_VCard::load () 55bool OPimContactAccessBackend_VCard::load ()
51{ 56{
52 m_map.clear(); 57 m_map.clear();
53 m_dirty = false; 58 m_dirty = false;
54 59
55 VObject* obj = 0l; 60 VObject* obj = 0l;
56 61
57 if ( QFile::exists(m_file) ){ 62 if ( QFile::exists(m_file) ){
58 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 63 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
59 if ( !obj ) 64 if ( !obj )
60 return false; 65 return false;
61 }else{ 66 }else{
62 qWarning("File \"%s\" not found !", m_file.latin1() ); 67 qWarning("File \"%s\" not found !", m_file.latin1() );
@@ -73,60 +78,60 @@ bool OPimContactAccessBackend_VCard::load ()
73 if ( con.uid() == 0 ){ 78 if ( con.uid() == 0 ){
74 con.setUid( 1 ); 79 con.setUid( 1 );
75 qWarning("assigned new uid %d",con.uid() ); 80 qWarning("assigned new uid %d",con.uid() );
76 } 81 }
77 82
78 m_map.insert( con.uid(), con ); 83 m_map.insert( con.uid(), con );
79 84
80 VObject *t = obj; 85 VObject *t = obj;
81 obj = nextVObjectInList(obj); 86 obj = nextVObjectInList(obj);
82 cleanVObject( t ); 87 cleanVObject( t );
83 } 88 }
84 89
85 return true; 90 return true;
86 91
87} 92}
88bool OPimContactAccessBackend_VCard::reload() 93bool OPimContactAccessBackend_VCard::reload()
89{ 94{
90 return load(); 95 return load();
91} 96}
92bool OPimContactAccessBackend_VCard::save() 97bool OPimContactAccessBackend_VCard::save()
93{ 98{
94 if (!m_dirty ) 99 if (!m_dirty )
95 return true; 100 return true;
96 101
97 QFileDirect file( m_file ); 102 QFile file( m_file );
98 if (!file.open(IO_WriteOnly ) ) 103 if (!file.open(IO_WriteOnly ) )
99 return false; 104 return false;
100 105
101 VObject *obj; 106 VObject *obj;
102 obj = newVObject( VCCalProp ); 107 obj = newVObject( VCCalProp );
103 addPropValue( obj, VCVersionProp, "1.0" ); 108 addPropValue( obj, VCVersionProp, "1.0" );
104 109
105 VObject *vo; 110 VObject *vo;
106 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 111 for(QMap<int, OPimContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
107 vo = createVObject( *it ); 112 vo = createVObject( *it );
108 writeVObject( file.directHandle() , vo ); 113 writeVObject( file.fh, vo ); //FIXME: HACK!!!
109 cleanVObject( vo ); 114 cleanVObject( vo );
110 } 115 }
111 cleanStrTbl(); 116 cleanStrTbl();
112 deleteVObject( obj ); 117 deleteVObject( obj );
113 118
114 m_dirty = false; 119 m_dirty = false;
115 return true; 120 return true;
116 121
117 122
118} 123}
119void OPimContactAccessBackend_VCard::clear () 124void OPimContactAccessBackend_VCard::clear ()
120{ 125{
121 m_map.clear(); 126 m_map.clear();
122 m_dirty = true; // ??? sure ? (se) 127 m_dirty = true; // ??? sure ? (se)
123} 128}
124 129
125bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact ) 130bool OPimContactAccessBackend_VCard::add ( const OPimContact& newcontact )
126{ 131{
127 m_map.insert( newcontact.uid(), newcontact ); 132 m_map.insert( newcontact.uid(), newcontact );
128 m_dirty = true; 133 m_dirty = true;
129 return true; 134 return true;
130} 135}
131 136
132bool OPimContactAccessBackend_VCard::remove ( int uid ) 137bool OPimContactAccessBackend_VCard::remove ( int uid )