summaryrefslogtreecommitdiff
authoreilers <eilers>2003-01-13 15:49:31 (UTC)
committer eilers <eilers>2003-01-13 15:49:31 (UTC)
commit6bae3504f8eacd604bc6d543d3eb09f996221dcc (patch) (unidiff)
tree14032f862c724319b7b538e054cd53c11994bb4d
parent01f7b3b512bbb729ac44808748365699748f3d4c (diff)
downloadopie-6bae3504f8eacd604bc6d543d3eb09f996221dcc.zip
opie-6bae3504f8eacd604bc6d543d3eb09f996221dcc.tar.gz
opie-6bae3504f8eacd604bc6d543d3eb09f996221dcc.tar.bz2
Fixing crash when businesscard.vcf is missing..
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.cpp13
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp13
2 files changed, 22 insertions, 4 deletions
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp
index ca9e410..1dc6b48 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.cpp
+++ b/libopie/pim/ocontactaccessbackend_vcard.cpp
@@ -1,108 +1,117 @@
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.6 2003/01/13 15:49:31 eilers
21 * Fixing crash when businesscard.vcf is missing..
22 *
20 * Revision 1.5 2002/12/07 13:26:22 eilers 23 * Revision 1.5 2002/12/07 13:26:22 eilers
21 * Fixing bug in storing anniversary.. 24 * Fixing bug in storing anniversary..
22 * 25 *
23 * Revision 1.4 2002/11/13 14:14:51 eilers 26 * Revision 1.4 2002/11/13 14:14:51 eilers
24 * Added sorted for Contacts.. 27 * Added sorted for Contacts..
25 * 28 *
26 * Revision 1.3 2002/11/11 16:41:09 kergoth 29 * Revision 1.3 2002/11/11 16:41:09 kergoth
27 * no default arguments in implementation 30 * no default arguments in implementation
28 * 31 *
29 * Revision 1.2 2002/11/10 15:41:53 eilers 32 * Revision 1.2 2002/11/10 15:41:53 eilers
30 * Bugfixes.. 33 * Bugfixes..
31 * 34 *
32 * Revision 1.1 2002/11/09 14:34:52 eilers 35 * Revision 1.1 2002/11/09 14:34:52 eilers
33 * Added VCard Backend. 36 * Added VCard Backend.
34 * 37 *
35 */ 38 */
36#include "ocontactaccessbackend_vcard.h" 39#include "ocontactaccessbackend_vcard.h"
37#include "../../library/backend/vobject_p.h" 40#include "../../library/backend/vobject_p.h"
38#include "../../library/backend/qfiledirect_p.h" 41#include "../../library/backend/qfiledirect_p.h"
39 42
40#include <qpe/timeconversion.h> 43#include <qpe/timeconversion.h>
41 44
42#include <qfile.h> 45#include <qfile.h>
43 46
44OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): 47OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ):
45 m_dirty( false ), 48 m_dirty( false ),
46 m_file( filename ) 49 m_file( filename )
47{ 50{
48 load(); 51 load();
49} 52}
50 53
51 54
52bool OContactAccessBackend_VCard::load () 55bool OContactAccessBackend_VCard::load ()
53{ 56{
54 m_map.clear(); 57 m_map.clear();
55 m_dirty = false; 58 m_dirty = false;
56 59
57 VObject* obj = 0l; 60 VObject* obj = 0l;
58 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 61
59 if ( !obj ) 62 if ( QFile( m_file ).exists() ){
63 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
64 if ( !obj )
65 return false;
66 }else{
67 qWarning("File \"%s\" not found !", m_file.latin1() );
60 return false; 68 return false;
69 }
61 70
62 while ( obj ) { 71 while ( obj ) {
63 OContact con = parseVObject( obj ); 72 OContact con = parseVObject( obj );
64 /* 73 /*
65 * if uid is 0 assign a new one 74 * if uid is 0 assign a new one
66 * this at least happens on 75 * this at least happens on
67 * Nokia6210 76 * Nokia6210
68 */ 77 */
69 if ( con.uid() == 0 ){ 78 if ( con.uid() == 0 ){
70 con.setUid( 1 ); 79 con.setUid( 1 );
71 qWarning("assigned new uid %d",con.uid() ); 80 qWarning("assigned new uid %d",con.uid() );
72 } 81 }
73 82
74 m_map.insert( con.uid(), con ); 83 m_map.insert( con.uid(), con );
75 84
76 VObject *t = obj; 85 VObject *t = obj;
77 obj = nextVObjectInList(obj); 86 obj = nextVObjectInList(obj);
78 cleanVObject( t ); 87 cleanVObject( t );
79 } 88 }
80 89
81 return true; 90 return true;
82 91
83} 92}
84bool OContactAccessBackend_VCard::reload() 93bool OContactAccessBackend_VCard::reload()
85{ 94{
86 return load(); 95 return load();
87} 96}
88bool OContactAccessBackend_VCard::save() 97bool OContactAccessBackend_VCard::save()
89{ 98{
90 if (!m_dirty ) 99 if (!m_dirty )
91 return true; 100 return true;
92 101
93 QFileDirect file( m_file ); 102 QFileDirect file( m_file );
94 if (!file.open(IO_WriteOnly ) ) 103 if (!file.open(IO_WriteOnly ) )
95 return false; 104 return false;
96 105
97 VObject *obj; 106 VObject *obj;
98 obj = newVObject( VCCalProp ); 107 obj = newVObject( VCCalProp );
99 addPropValue( obj, VCVersionProp, "1.0" ); 108 addPropValue( obj, VCVersionProp, "1.0" );
100 109
101 VObject *vo; 110 VObject *vo;
102 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 111 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
103 vo = createVObject( *it ); 112 vo = createVObject( *it );
104 writeVObject( file.directHandle() , vo ); 113 writeVObject( file.directHandle() , vo );
105 cleanVObject( vo ); 114 cleanVObject( vo );
106 } 115 }
107 cleanStrTbl(); 116 cleanStrTbl();
108 117
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
index ca9e410..1dc6b48 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp
@@ -1,108 +1,117 @@
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.6 2003/01/13 15:49:31 eilers
21 * Fixing crash when businesscard.vcf is missing..
22 *
20 * Revision 1.5 2002/12/07 13:26:22 eilers 23 * Revision 1.5 2002/12/07 13:26:22 eilers
21 * Fixing bug in storing anniversary.. 24 * Fixing bug in storing anniversary..
22 * 25 *
23 * Revision 1.4 2002/11/13 14:14:51 eilers 26 * Revision 1.4 2002/11/13 14:14:51 eilers
24 * Added sorted for Contacts.. 27 * Added sorted for Contacts..
25 * 28 *
26 * Revision 1.3 2002/11/11 16:41:09 kergoth 29 * Revision 1.3 2002/11/11 16:41:09 kergoth
27 * no default arguments in implementation 30 * no default arguments in implementation
28 * 31 *
29 * Revision 1.2 2002/11/10 15:41:53 eilers 32 * Revision 1.2 2002/11/10 15:41:53 eilers
30 * Bugfixes.. 33 * Bugfixes..
31 * 34 *
32 * Revision 1.1 2002/11/09 14:34:52 eilers 35 * Revision 1.1 2002/11/09 14:34:52 eilers
33 * Added VCard Backend. 36 * Added VCard Backend.
34 * 37 *
35 */ 38 */
36#include "ocontactaccessbackend_vcard.h" 39#include "ocontactaccessbackend_vcard.h"
37#include "../../library/backend/vobject_p.h" 40#include "../../library/backend/vobject_p.h"
38#include "../../library/backend/qfiledirect_p.h" 41#include "../../library/backend/qfiledirect_p.h"
39 42
40#include <qpe/timeconversion.h> 43#include <qpe/timeconversion.h>
41 44
42#include <qfile.h> 45#include <qfile.h>
43 46
44OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): 47OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ):
45 m_dirty( false ), 48 m_dirty( false ),
46 m_file( filename ) 49 m_file( filename )
47{ 50{
48 load(); 51 load();
49} 52}
50 53
51 54
52bool OContactAccessBackend_VCard::load () 55bool OContactAccessBackend_VCard::load ()
53{ 56{
54 m_map.clear(); 57 m_map.clear();
55 m_dirty = false; 58 m_dirty = false;
56 59
57 VObject* obj = 0l; 60 VObject* obj = 0l;
58 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 61
59 if ( !obj ) 62 if ( QFile( m_file ).exists() ){
63 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
64 if ( !obj )
65 return false;
66 }else{
67 qWarning("File \"%s\" not found !", m_file.latin1() );
60 return false; 68 return false;
69 }
61 70
62 while ( obj ) { 71 while ( obj ) {
63 OContact con = parseVObject( obj ); 72 OContact con = parseVObject( obj );
64 /* 73 /*
65 * if uid is 0 assign a new one 74 * if uid is 0 assign a new one
66 * this at least happens on 75 * this at least happens on
67 * Nokia6210 76 * Nokia6210
68 */ 77 */
69 if ( con.uid() == 0 ){ 78 if ( con.uid() == 0 ){
70 con.setUid( 1 ); 79 con.setUid( 1 );
71 qWarning("assigned new uid %d",con.uid() ); 80 qWarning("assigned new uid %d",con.uid() );
72 } 81 }
73 82
74 m_map.insert( con.uid(), con ); 83 m_map.insert( con.uid(), con );
75 84
76 VObject *t = obj; 85 VObject *t = obj;
77 obj = nextVObjectInList(obj); 86 obj = nextVObjectInList(obj);
78 cleanVObject( t ); 87 cleanVObject( t );
79 } 88 }
80 89
81 return true; 90 return true;
82 91
83} 92}
84bool OContactAccessBackend_VCard::reload() 93bool OContactAccessBackend_VCard::reload()
85{ 94{
86 return load(); 95 return load();
87} 96}
88bool OContactAccessBackend_VCard::save() 97bool OContactAccessBackend_VCard::save()
89{ 98{
90 if (!m_dirty ) 99 if (!m_dirty )
91 return true; 100 return true;
92 101
93 QFileDirect file( m_file ); 102 QFileDirect file( m_file );
94 if (!file.open(IO_WriteOnly ) ) 103 if (!file.open(IO_WriteOnly ) )
95 return false; 104 return false;
96 105
97 VObject *obj; 106 VObject *obj;
98 obj = newVObject( VCCalProp ); 107 obj = newVObject( VCCalProp );
99 addPropValue( obj, VCVersionProp, "1.0" ); 108 addPropValue( obj, VCVersionProp, "1.0" );
100 109
101 VObject *vo; 110 VObject *vo;
102 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ 111 for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
103 vo = createVObject( *it ); 112 vo = createVObject( *it );
104 writeVObject( file.directHandle() , vo ); 113 writeVObject( file.directHandle() , vo );
105 cleanVObject( vo ); 114 cleanVObject( vo );
106 } 115 }
107 cleanStrTbl(); 116 cleanStrTbl();
108 117