summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/ocontact.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/ocontact.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ocontact.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index cd238ef..8a0930b 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -3,97 +3,96 @@
3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file is part of the Qtopia Environment. 5** This file is part of the Qtopia Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#define QTOPIA_INTERNAL_CONTACT_MRE 22#define QTOPIA_INTERNAL_CONTACT_MRE
23 23
24#include "ocontact.h" 24#include "ocontact.h"
25#include "../../library/backend/vobject_p.h" 25#include "../../library/backend/vobject_p.h"
26#include "../../library/backend/qfiledirect_p.h" 26#include "../../library/backend/qfiledirect_p.h"
27 27
28#include <qpe/stringutil.h> 28#include <qpe/stringutil.h>
29#include <qpe/timeconversion.h> 29#include <qpe/timeconversion.h>
30#include <qpe/timestring.h> 30#include <qpe/timestring.h>
31 31
32#include <qobject.h> 32#include <qobject.h>
33#include <qregexp.h> 33#include <qregexp.h>
34#include <qstylesheet.h> 34#include <qstylesheet.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qmap.h> 36#include <qmap.h>
37 37
38#include <stdio.h> 38#include <stdio.h>
39 39
40/*! 40/*!
41 \class Contact contact.h 41 \class Contact contact.h
42 \brief The Contact class holds the data of an address book entry. 42 \brief The Contact class holds the data of an address book entry.
43 43
44 This data includes information the name of the person, contact 44 This data includes information the name of the person, contact
45 information, and business information such as deparment and job title. 45 information, and business information such as deparment and job title.
46 46
47 \ingroup qtopiaemb 47 \ingroup qtopiaemb
48 \ingroup qtopiadesktop 48 \ingroup qtopiadesktop
49*/ 49*/
50 50
51Qtopia::UidGen OContact::sUidGen( Qtopia::UidGen::Qtopia );
52 51
53/*! 52/*!
54 Creates a new, empty contact. 53 Creates a new, empty contact.
55*/ 54*/
56OContact::OContact() 55OContact::OContact()
57 : OPimRecord(), mMap(), d( 0 ) 56 : OPimRecord(), mMap(), d( 0 )
58{ 57{
59} 58}
60 59
61/*! 60/*!
62 \internal 61 \internal
63 Creates a new contact. The properties of the contact are 62 Creates a new contact. The properties of the contact are
64 set from \a fromMap. 63 set from \a fromMap.
65*/ 64*/
66OContact::OContact( const QMap<int, QString> &fromMap ) : 65OContact::OContact( const QMap<int, QString> &fromMap ) :
67 OPimRecord(), mMap( fromMap ), d( 0 ) 66 OPimRecord(), mMap( fromMap ), d( 0 )
68{ 67{
69 QString cats = mMap[ Qtopia::AddressCategory ]; 68 QString cats = mMap[ Qtopia::AddressCategory ];
70 if ( !cats.isEmpty() ) 69 if ( !cats.isEmpty() )
71 setCategories( idsFromString( cats ) ); 70 setCategories( idsFromString( cats ) );
72 71
73 QString uidStr = find( Qtopia::AddressUid ); 72 QString uidStr = find( Qtopia::AddressUid );
74 73
75 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ 74 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
76 qWarning( "Invalid UID found. Generate new one.." ); 75 qWarning( "Invalid UID found. Generate new one.." );
77 setUid( uidGen().generate() ); 76 setUid( uidGen().generate() );
78 }else 77 }else
79 setUid( uidStr.toInt() ); 78 setUid( uidStr.toInt() );
80 79
81// if ( !uidStr.isEmpty() ) 80// if ( !uidStr.isEmpty() )
82 // setUid( uidStr.toInt() ); 81 // setUid( uidStr.toInt() );
83} 82}
84 83
85/*! 84/*!
86 Destroys a contact. 85 Destroys a contact.
87*/ 86*/
88OContact::~OContact() 87OContact::~OContact()
89{ 88{
90} 89}
91 90
92/*! \fn void OContact::setTitle( const QString &str ) 91/*! \fn void OContact::setTitle( const QString &str )
93 Sets the title of the contact to \a str. 92 Sets the title of the contact to \a str.
94*/ 93*/
95 94
96/*! \fn void OContact::setFirstName( const QString &str ) 95/*! \fn void OContact::setFirstName( const QString &str )
97 Sets the first name of the contact to \a str. 96 Sets the first name of the contact to \a str.
98*/ 97*/
99 98
@@ -1425,98 +1424,100 @@ void OContact::writeVCard( const QString &filename, const QValueList<OContact> &
1425 } 1424 }
1426 1425
1427 QValueList<OContact>::ConstIterator it; 1426 QValueList<OContact>::ConstIterator it;
1428 for( it = contacts.begin(); it != contacts.end(); ++it ) { 1427 for( it = contacts.begin(); it != contacts.end(); ++it ) {
1429 VObject *obj = createVObject( *it ); 1428 VObject *obj = createVObject( *it );
1430 writeVObject(f.directHandle() , obj ); 1429 writeVObject(f.directHandle() , obj );
1431 cleanVObject( obj ); 1430 cleanVObject( obj );
1432 } 1431 }
1433 cleanStrTbl(); 1432 cleanStrTbl();
1434} 1433}
1435 1434
1436/*! 1435/*!
1437 writes \a contact as a VCard to the file \a filename. 1436 writes \a contact as a VCard to the file \a filename.
1438*/ 1437*/
1439void OContact::writeVCard( const QString &filename, const OContact &contact) 1438void OContact::writeVCard( const QString &filename, const OContact &contact)
1440{ 1439{
1441 QFileDirect f( filename.utf8().data() ); 1440 QFileDirect f( filename.utf8().data() );
1442 if ( !f.open( IO_WriteOnly ) ) { 1441 if ( !f.open( IO_WriteOnly ) ) {
1443 qWarning("Unable to open vcard write"); 1442 qWarning("Unable to open vcard write");
1444 return; 1443 return;
1445 } 1444 }
1446 1445
1447 VObject *obj = createVObject( contact ); 1446 VObject *obj = createVObject( contact );
1448 writeVObject( f.directHandle() , obj ); 1447 writeVObject( f.directHandle() , obj );
1449 cleanVObject( obj ); 1448 cleanVObject( obj );
1450 1449
1451 cleanStrTbl(); 1450 cleanStrTbl();
1452} 1451}
1453 1452
1454/*! 1453/*!
1455 Returns the set of contacts read as VCards from the file \a filename. 1454 Returns the set of contacts read as VCards from the file \a filename.
1456*/ 1455*/
1457QValueList<OContact> OContact::readVCard( const QString &filename ) 1456QValueList<OContact> OContact::readVCard( const QString &filename )
1458{ 1457{
1459 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); 1458 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() );
1460 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); 1459 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1461 1460
1462 qDebug("vobject = %p", obj ); 1461 qDebug("vobject = %p", obj );
1463 1462
1464 QValueList<OContact> contacts; 1463 QValueList<OContact> contacts;
1465 1464
1466 while ( obj ) { 1465 while ( obj ) {
1467 OContact con = parseVObject( obj ); 1466 OContact con = parseVObject( obj );
1468 /* 1467 /*
1469 * if uid is 0 assign a new one 1468 * if uid is 0 assign a new one
1470 * this at least happens on 1469 * this at least happens on
1471 * Nokia6210 1470 * Nokia6210
1472 */ 1471 */
1473 if ( con.uid() == 0 ) 1472 if ( con.uid() == 0 ){
1474 con.setUid( 1 ); 1473 con.setUid( 1 );
1474 qWarning("assigned new uid %d",con.uid() );
1475 }
1475 1476
1476 contacts.append(con ); 1477 contacts.append(con );
1477 1478
1478 VObject *t = obj; 1479 VObject *t = obj;
1479 obj = nextVObjectInList(obj); 1480 obj = nextVObjectInList(obj);
1480 cleanVObject( t ); 1481 cleanVObject( t );
1481 } 1482 }
1482 1483
1483 return contacts; 1484 return contacts;
1484} 1485}
1485 1486
1486/*! 1487/*!
1487 Returns TRUE if the contact matches the regular expression \a regexp. 1488 Returns TRUE if the contact matches the regular expression \a regexp.
1488 Otherwise returns FALSE. 1489 Otherwise returns FALSE.
1489*/ 1490*/
1490bool OContact::match( const QString &regexp ) const 1491bool OContact::match( const QString &regexp ) const
1491{ 1492{
1492 return match(QRegExp(regexp)); 1493 return match(QRegExp(regexp));
1493} 1494}
1494 1495
1495/*! 1496/*!
1496 \overload 1497 \overload
1497 Returns TRUE if the contact matches the regular expression \a regexp. 1498 Returns TRUE if the contact matches the regular expression \a regexp.
1498 Otherwise returns FALSE. 1499 Otherwise returns FALSE.
1499*/ 1500*/
1500bool OContact::match( const QRegExp &r ) const 1501bool OContact::match( const QRegExp &r ) const
1501{ 1502{
1502 bool match; 1503 bool match;
1503 match = false; 1504 match = false;
1504 QMap<int, QString>::ConstIterator it; 1505 QMap<int, QString>::ConstIterator it;
1505 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 1506 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
1506 if ( (*it).find( r ) > -1 ) { 1507 if ( (*it).find( r ) > -1 ) {
1507 match = true; 1508 match = true;
1508 break; 1509 break;
1509 } 1510 }
1510 } 1511 }
1511 return match; 1512 return match;
1512} 1513}
1513 1514
1514 1515
1515QString OContact::toShortText() const 1516QString OContact::toShortText() const
1516{ 1517{
1517 return ( fullName() ); 1518 return ( fullName() );
1518} 1519}
1519QString OContact::type() const 1520QString OContact::type() const
1520{ 1521{
1521 return QString::fromLatin1( "OContact" ); 1522 return QString::fromLatin1( "OContact" );
1522} 1523}