summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.cpp11
-rw-r--r--libopie/pim/opimaccessbackend.h16
-rw-r--r--libopie/pim/opimaccesstemplate.h25
-rw-r--r--libopie/pim/opimcache.h6
-rw-r--r--libopie/pim/opimmainwindow.cpp36
-rw-r--r--libopie/pim/opimmainwindow.h26
-rw-r--r--libopie/pim/opimrecord.cpp82
-rw-r--r--libopie/pim/opimrecord.h12
-rw-r--r--libopie/pim/opimresolver.cpp198
-rw-r--r--libopie/pim/opimresolver.h52
-rw-r--r--libopie/pim/otemplatebase.h63
-rw-r--r--libopie/pim/otodo.cpp3
-rw-r--r--libopie/pim/otodoaccess.cpp32
-rw-r--r--libopie/pim/otodoaccess.h13
-rw-r--r--libopie/pim/otodoaccessxml.cpp43
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h16
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp43
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h25
-rw-r--r--libopie2/opiepim/core/opimcache.h6
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp82
-rw-r--r--libopie2/opiepim/core/opimrecord.h12
-rw-r--r--libopie2/opiepim/core/opimresolver.cpp198
-rw-r--r--libopie2/opiepim/core/opimresolver.h52
-rw-r--r--libopie2/opiepim/core/otemplatebase.h63
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp32
-rw-r--r--libopie2/opiepim/core/otodoaccess.h13
-rw-r--r--libopie2/opiepim/ocontact.cpp11
-rw-r--r--libopie2/opiepim/otodo.cpp3
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.cpp36
-rw-r--r--libopie2/opiepim/ui/opimmainwindow.h26
30 files changed, 1072 insertions, 164 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index 6aec62e..38cba72 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -1,216 +1,217 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
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 "opimresolver.h"
25 26
26#include <qpe/stringutil.h> 27#include <qpe/stringutil.h>
27#include <qpe/timeconversion.h> 28#include <qpe/timeconversion.h>
28#include <qpe/timestring.h> 29#include <qpe/timestring.h>
29 30
30#include <qobject.h> 31#include <qobject.h>
31#include <qregexp.h> 32#include <qregexp.h>
32#include <qstylesheet.h> 33#include <qstylesheet.h>
33#include <qfileinfo.h> 34#include <qfileinfo.h>
34#include <qmap.h> 35#include <qmap.h>
35 36
36#include <stdio.h> 37#include <stdio.h>
37 38
38/*! 39/*!
39 \class Contact contact.h 40 \class Contact contact.h
40 \brief The Contact class holds the data of an address book entry. 41 \brief The Contact class holds the data of an address book entry.
41 42
42 This data includes information the name of the person, contact 43 This data includes information the name of the person, contact
43 information, and business information such as deparment and job title. 44 information, and business information such as deparment and job title.
44 45
45 \ingroup qtopiaemb 46 \ingroup qtopiaemb
46 \ingroup qtopiadesktop 47 \ingroup qtopiadesktop
47*/ 48*/
48 49
49 50
50/*! 51/*!
51 Creates a new, empty contact. 52 Creates a new, empty contact.
52*/ 53*/
53OContact::OContact() 54OContact::OContact()
54 : OPimRecord(), mMap(), d( 0 ) 55 : OPimRecord(), mMap(), d( 0 )
55{ 56{
56} 57}
57 58
58/*! 59/*!
59 \internal 60 \internal
60 Creates a new contact. The properties of the contact are 61 Creates a new contact. The properties of the contact are
61 set from \a fromMap. 62 set from \a fromMap.
62*/ 63*/
63OContact::OContact( const QMap<int, QString> &fromMap ) : 64OContact::OContact( const QMap<int, QString> &fromMap ) :
64 OPimRecord(), mMap( fromMap ), d( 0 ) 65 OPimRecord(), mMap( fromMap ), d( 0 )
65{ 66{
66 QString cats = mMap[ Qtopia::AddressCategory ]; 67 QString cats = mMap[ Qtopia::AddressCategory ];
67 if ( !cats.isEmpty() ) 68 if ( !cats.isEmpty() )
68 setCategories( idsFromString( cats ) ); 69 setCategories( idsFromString( cats ) );
69 70
70 QString uidStr = find( Qtopia::AddressUid ); 71 QString uidStr = find( Qtopia::AddressUid );
71 72
72 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ 73 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
73 qWarning( "Invalid UID found. Generate new one.." ); 74 qWarning( "Invalid UID found. Generate new one.." );
74 setUid( uidGen().generate() ); 75 setUid( uidGen().generate() );
75 }else 76 }else
76 setUid( uidStr.toInt() ); 77 setUid( uidStr.toInt() );
77 78
78// if ( !uidStr.isEmpty() ) 79// if ( !uidStr.isEmpty() )
79 // setUid( uidStr.toInt() ); 80 // setUid( uidStr.toInt() );
80} 81}
81 82
82/*! 83/*!
83 Destroys a contact. 84 Destroys a contact.
84*/ 85*/
85OContact::~OContact() 86OContact::~OContact()
86{ 87{
87} 88}
88 89
89/*! \fn void OContact::setTitle( const QString &str ) 90/*! \fn void OContact::setTitle( const QString &str )
90 Sets the title of the contact to \a str. 91 Sets the title of the contact to \a str.
91*/ 92*/
92 93
93/*! \fn void OContact::setFirstName( const QString &str ) 94/*! \fn void OContact::setFirstName( const QString &str )
94 Sets the first name of the contact to \a str. 95 Sets the first name of the contact to \a str.
95*/ 96*/
96 97
97/*! \fn void OContact::setMiddleName( const QString &str ) 98/*! \fn void OContact::setMiddleName( const QString &str )
98 Sets the middle name of the contact to \a str. 99 Sets the middle name of the contact to \a str.
99*/ 100*/
100 101
101/*! \fn void OContact::setLastName( const QString &str ) 102/*! \fn void OContact::setLastName( const QString &str )
102 Sets the last name of the contact to \a str. 103 Sets the last name of the contact to \a str.
103*/ 104*/
104 105
105/*! \fn void OContact::setSuffix( const QString &str ) 106/*! \fn void OContact::setSuffix( const QString &str )
106 Sets the suffix of the contact to \a str. 107 Sets the suffix of the contact to \a str.
107*/ 108*/
108 109
109/*! \fn void OContact::setFileAs( const QString &str ) 110/*! \fn void OContact::setFileAs( const QString &str )
110 Sets the contact to filed as \a str. 111 Sets the contact to filed as \a str.
111*/ 112*/
112 113
113/*! \fn void OContact::setDefaultEmail( const QString &str ) 114/*! \fn void OContact::setDefaultEmail( const QString &str )
114 Sets the default email of the contact to \a str. 115 Sets the default email of the contact to \a str.
115*/ 116*/
116 117
117/*! \fn void OContact::setHomeStreet( const QString &str ) 118/*! \fn void OContact::setHomeStreet( const QString &str )
118 Sets the home street address of the contact to \a str. 119 Sets the home street address of the contact to \a str.
119*/ 120*/
120 121
121/*! \fn void OContact::setHomeCity( const QString &str ) 122/*! \fn void OContact::setHomeCity( const QString &str )
122 Sets the home city of the contact to \a str. 123 Sets the home city of the contact to \a str.
123*/ 124*/
124 125
125/*! \fn void OContact::setHomeState( const QString &str ) 126/*! \fn void OContact::setHomeState( const QString &str )
126 Sets the home state of the contact to \a str. 127 Sets the home state of the contact to \a str.
127*/ 128*/
128 129
129/*! \fn void OContact::setHomeZip( const QString &str ) 130/*! \fn void OContact::setHomeZip( const QString &str )
130 Sets the home zip code of the contact to \a str. 131 Sets the home zip code of the contact to \a str.
131*/ 132*/
132 133
133/*! \fn void OContact::setHomeCountry( const QString &str ) 134/*! \fn void OContact::setHomeCountry( const QString &str )
134 Sets the home country of the contact to \a str. 135 Sets the home country of the contact to \a str.
135*/ 136*/
136 137
137/*! \fn void OContact::setHomePhone( const QString &str ) 138/*! \fn void OContact::setHomePhone( const QString &str )
138 Sets the home phone number of the contact to \a str. 139 Sets the home phone number of the contact to \a str.
139*/ 140*/
140 141
141/*! \fn void OContact::setHomeFax( const QString &str ) 142/*! \fn void OContact::setHomeFax( const QString &str )
142 Sets the home fax number of the contact to \a str. 143 Sets the home fax number of the contact to \a str.
143*/ 144*/
144 145
145/*! \fn void OContact::setHomeMobile( const QString &str ) 146/*! \fn void OContact::setHomeMobile( const QString &str )
146 Sets the home mobile phone number of the contact to \a str. 147 Sets the home mobile phone number of the contact to \a str.
147*/ 148*/
148 149
149/*! \fn void OContact::setHomeWebpage( const QString &str ) 150/*! \fn void OContact::setHomeWebpage( const QString &str )
150 Sets the home webpage of the contact to \a str. 151 Sets the home webpage of the contact to \a str.
151*/ 152*/
152 153
153/*! \fn void OContact::setCompany( const QString &str ) 154/*! \fn void OContact::setCompany( const QString &str )
154 Sets the company for contact to \a str. 155 Sets the company for contact to \a str.
155*/ 156*/
156 157
157/*! \fn void OContact::setJobTitle( const QString &str ) 158/*! \fn void OContact::setJobTitle( const QString &str )
158 Sets the job title of the contact to \a str. 159 Sets the job title of the contact to \a str.
159*/ 160*/
160 161
161/*! \fn void OContact::setDepartment( const QString &str ) 162/*! \fn void OContact::setDepartment( const QString &str )
162 Sets the department for contact to \a str. 163 Sets the department for contact to \a str.
163*/ 164*/
164 165
165/*! \fn void OContact::setOffice( const QString &str ) 166/*! \fn void OContact::setOffice( const QString &str )
166 Sets the office for contact to \a str. 167 Sets the office for contact to \a str.
167*/ 168*/
168 169
169/*! \fn void OContact::setBusinessStreet( const QString &str ) 170/*! \fn void OContact::setBusinessStreet( const QString &str )
170 Sets the business street address of the contact to \a str. 171 Sets the business street address of the contact to \a str.
171*/ 172*/
172 173
173/*! \fn void OContact::setBusinessCity( const QString &str ) 174/*! \fn void OContact::setBusinessCity( const QString &str )
174 Sets the business city of the contact to \a str. 175 Sets the business city of the contact to \a str.
175*/ 176*/
176 177
177/*! \fn void OContact::setBusinessState( const QString &str ) 178/*! \fn void OContact::setBusinessState( const QString &str )
178 Sets the business state of the contact to \a str. 179 Sets the business state of the contact to \a str.
179*/ 180*/
180 181
181/*! \fn void OContact::setBusinessZip( const QString &str ) 182/*! \fn void OContact::setBusinessZip( const QString &str )
182 Sets the business zip code of the contact to \a str. 183 Sets the business zip code of the contact to \a str.
183*/ 184*/
184 185
185/*! \fn void OContact::setBusinessCountry( const QString &str ) 186/*! \fn void OContact::setBusinessCountry( const QString &str )
186 Sets the business country of the contact to \a str. 187 Sets the business country of the contact to \a str.
187*/ 188*/
188 189
189/*! \fn void OContact::setBusinessPhone( const QString &str ) 190/*! \fn void OContact::setBusinessPhone( const QString &str )
190 Sets the business phone number of the contact to \a str. 191 Sets the business phone number of the contact to \a str.
191*/ 192*/
192 193
193/*! \fn void OContact::setBusinessFax( const QString &str ) 194/*! \fn void OContact::setBusinessFax( const QString &str )
194 Sets the business fax number of the contact to \a str. 195 Sets the business fax number of the contact to \a str.
195*/ 196*/
196 197
197/*! \fn void OContact::setBusinessMobile( const QString &str ) 198/*! \fn void OContact::setBusinessMobile( const QString &str )
198 Sets the business mobile phone number of the contact to \a str. 199 Sets the business mobile phone number of the contact to \a str.
199*/ 200*/
200 201
201/*! \fn void OContact::setBusinessPager( const QString &str ) 202/*! \fn void OContact::setBusinessPager( const QString &str )
202 Sets the business pager number of the contact to \a str. 203 Sets the business pager number of the contact to \a str.
203*/ 204*/
204 205
205/*! \fn void OContact::setBusinessWebpage( const QString &str ) 206/*! \fn void OContact::setBusinessWebpage( const QString &str )
206 Sets the business webpage of the contact to \a str. 207 Sets the business webpage of the contact to \a str.
207*/ 208*/
208 209
209/*! \fn void OContact::setProfession( const QString &str ) 210/*! \fn void OContact::setProfession( const QString &str )
210 Sets the profession of the contact to \a str. 211 Sets the profession of the contact to \a str.
211*/ 212*/
212 213
213/*! \fn void OContact::setAssistant( const QString &str ) 214/*! \fn void OContact::setAssistant( const QString &str )
214 Sets the assistant of the contact to \a str. 215 Sets the assistant of the contact to \a str.
215*/ 216*/
216 217
@@ -640,470 +641,470 @@ QString OContact::find( int key ) const
640} 641}
641 642
642/*! 643/*!
643 \internal 644 \internal
644*/ 645*/
645QString OContact::displayAddress( const QString &street, 646QString OContact::displayAddress( const QString &street,
646 const QString &city, 647 const QString &city,
647 const QString &state, 648 const QString &state,
648 const QString &zip, 649 const QString &zip,
649 const QString &country ) const 650 const QString &country ) const
650{ 651{
651 QString s = street; 652 QString s = street;
652 if ( !street.isEmpty() ) 653 if ( !street.isEmpty() )
653 s+= "\n"; 654 s+= "\n";
654 s += city; 655 s += city;
655 if ( !city.isEmpty() && !state.isEmpty() ) 656 if ( !city.isEmpty() && !state.isEmpty() )
656 s += ", "; 657 s += ", ";
657 s += state; 658 s += state;
658 if ( !state.isEmpty() && !zip.isEmpty() ) 659 if ( !state.isEmpty() && !zip.isEmpty() )
659 s += " "; 660 s += " ";
660 s += zip; 661 s += zip;
661 if ( !country.isEmpty() && !s.isEmpty() ) 662 if ( !country.isEmpty() && !s.isEmpty() )
662 s += "\n"; 663 s += "\n";
663 s += country; 664 s += country;
664 return s; 665 return s;
665} 666}
666 667
667/*! 668/*!
668 \internal 669 \internal
669*/ 670*/
670QString OContact::displayBusinessAddress() const 671QString OContact::displayBusinessAddress() const
671{ 672{
672 return displayAddress( businessStreet(), businessCity(), 673 return displayAddress( businessStreet(), businessCity(),
673 businessState(), businessZip(), 674 businessState(), businessZip(),
674 businessCountry() ); 675 businessCountry() );
675} 676}
676 677
677/*! 678/*!
678 \internal 679 \internal
679*/ 680*/
680QString OContact::displayHomeAddress() const 681QString OContact::displayHomeAddress() const
681{ 682{
682 return displayAddress( homeStreet(), homeCity(), 683 return displayAddress( homeStreet(), homeCity(),
683 homeState(), homeZip(), 684 homeState(), homeZip(),
684 homeCountry() ); 685 homeCountry() );
685} 686}
686 687
687/*! 688/*!
688 Returns the full name of the contact 689 Returns the full name of the contact
689*/ 690*/
690QString OContact::fullName() const 691QString OContact::fullName() const
691{ 692{
692 QString title = find( Qtopia::Title ); 693 QString title = find( Qtopia::Title );
693 QString firstName = find( Qtopia::FirstName ); 694 QString firstName = find( Qtopia::FirstName );
694 QString middleName = find( Qtopia::MiddleName ); 695 QString middleName = find( Qtopia::MiddleName );
695 QString lastName = find( Qtopia::LastName ); 696 QString lastName = find( Qtopia::LastName );
696 QString suffix = find( Qtopia::Suffix ); 697 QString suffix = find( Qtopia::Suffix );
697 698
698 QString name = title; 699 QString name = title;
699 if ( !firstName.isEmpty() ) { 700 if ( !firstName.isEmpty() ) {
700 if ( !name.isEmpty() ) 701 if ( !name.isEmpty() )
701 name += " "; 702 name += " ";
702 name += firstName; 703 name += firstName;
703 } 704 }
704 if ( !middleName.isEmpty() ) { 705 if ( !middleName.isEmpty() ) {
705 if ( !name.isEmpty() ) 706 if ( !name.isEmpty() )
706 name += " "; 707 name += " ";
707 name += middleName; 708 name += middleName;
708 } 709 }
709 if ( !lastName.isEmpty() ) { 710 if ( !lastName.isEmpty() ) {
710 if ( !name.isEmpty() ) 711 if ( !name.isEmpty() )
711 name += " "; 712 name += " ";
712 name += lastName; 713 name += lastName;
713 } 714 }
714 if ( !suffix.isEmpty() ) { 715 if ( !suffix.isEmpty() ) {
715 if ( !name.isEmpty() ) 716 if ( !name.isEmpty() )
716 name += " "; 717 name += " ";
717 name += suffix; 718 name += suffix;
718 } 719 }
719 return name.simplifyWhiteSpace(); 720 return name.simplifyWhiteSpace();
720} 721}
721 722
722/*! 723/*!
723 Returns a list of the names of the children of the contact. 724 Returns a list of the names of the children of the contact.
724*/ 725*/
725QStringList OContact::childrenList() const 726QStringList OContact::childrenList() const
726{ 727{
727 return QStringList::split( " ", find( Qtopia::Children ) ); 728 return QStringList::split( " ", find( Qtopia::Children ) );
728} 729}
729 730
730/*! \fn void OContact::insertEmail( const QString &email ) 731/*! \fn void OContact::insertEmail( const QString &email )
731 732
732 Insert \a email into the email list. Ensures \a email can only be added 733 Insert \a email into the email list. Ensures \a email can only be added
733 once. If there is no default email address set, it sets it to the \a email. 734 once. If there is no default email address set, it sets it to the \a email.
734*/ 735*/
735 736
736/*! \fn void OContact::removeEmail( const QString &email ) 737/*! \fn void OContact::removeEmail( const QString &email )
737 738
738 Removes the \a email from the email list. If the default email was \a email, 739 Removes the \a email from the email list. If the default email was \a email,
739 then the default email address is assigned to the first email in the 740 then the default email address is assigned to the first email in the
740 email list 741 email list
741*/ 742*/
742 743
743/*! \fn void OContact::clearEmails() 744/*! \fn void OContact::clearEmails()
744 745
745 Clears the email list. 746 Clears the email list.
746 */ 747 */
747 748
748/*! \fn void OContact::insertEmails( const QStringList &emailList ) 749/*! \fn void OContact::insertEmails( const QStringList &emailList )
749 750
750 Appends the \a emailList to the exiting email list 751 Appends the \a emailList to the exiting email list
751 */ 752 */
752 753
753/*! 754/*!
754 Returns a list of email addresses belonging to the contact, including 755 Returns a list of email addresses belonging to the contact, including
755 the default email address. 756 the default email address.
756*/ 757*/
757QStringList OContact::emailList() const 758QStringList OContact::emailList() const
758{ 759{
759 QString emailStr = emails(); 760 QString emailStr = emails();
760 761
761 QStringList r; 762 QStringList r;
762 if ( !emailStr.isEmpty() ) { 763 if ( !emailStr.isEmpty() ) {
763 qDebug(" emailstr "); 764 qDebug(" emailstr ");
764 QStringList l = QStringList::split( emailSeparator(), emailStr ); 765 QStringList l = QStringList::split( emailSeparator(), emailStr );
765 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 766 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
766 r += (*it).simplifyWhiteSpace(); 767 r += (*it).simplifyWhiteSpace();
767 } 768 }
768 769
769 return r; 770 return r;
770} 771}
771 772
772/*! 773/*!
773 \overload 774 \overload
774 775
775 Generates the string for the contact to be filed as from the first, 776 Generates the string for the contact to be filed as from the first,
776 middle and last name of the contact. 777 middle and last name of the contact.
777*/ 778*/
778void OContact::setFileAs() 779void OContact::setFileAs()
779{ 780{
780 QString lastName, firstName, middleName, fileas; 781 QString lastName, firstName, middleName, fileas;
781 782
782 lastName = find( Qtopia::LastName ); 783 lastName = find( Qtopia::LastName );
783 firstName = find( Qtopia::FirstName ); 784 firstName = find( Qtopia::FirstName );
784 middleName = find( Qtopia::MiddleName ); 785 middleName = find( Qtopia::MiddleName );
785 if ( !lastName.isEmpty() && !firstName.isEmpty() 786 if ( !lastName.isEmpty() && !firstName.isEmpty()
786 && !middleName.isEmpty() ) 787 && !middleName.isEmpty() )
787 fileas = lastName + ", " + firstName + " " + middleName; 788 fileas = lastName + ", " + firstName + " " + middleName;
788 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 789 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
789 fileas = lastName + ", " + firstName; 790 fileas = lastName + ", " + firstName;
790 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 791 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
791 !middleName.isEmpty() ) 792 !middleName.isEmpty() )
792 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 793 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
793 + middleName + ( middleName.isEmpty() ? "" : " " ) 794 + middleName + ( middleName.isEmpty() ? "" : " " )
794 + lastName; 795 + lastName;
795 796
796 replace( Qtopia::FileAs, fileas ); 797 replace( Qtopia::FileAs, fileas );
797} 798}
798 799
799/*! 800/*!
800 \internal 801 \internal
801 Appends the contact information to \a buf. 802 Appends the contact information to \a buf.
802*/ 803*/
803void OContact::save( QString &buf ) const 804void OContact::save( QString &buf ) const
804{ 805{
805 static const QStringList SLFIELDS = fields(); 806 static const QStringList SLFIELDS = fields();
806 // I'm expecting "<Contact " in front of this... 807 // I'm expecting "<Contact " in front of this...
807 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 808 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
808 it != mMap.end(); ++it ) { 809 it != mMap.end(); ++it ) {
809 const QString &value = it.data(); 810 const QString &value = it.data();
810 int key = it.key(); 811 int key = it.key();
811 if ( !value.isEmpty() ) { 812 if ( !value.isEmpty() ) {
812 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) 813 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
813 continue; 814 continue;
814 815
815 key -= Qtopia::AddressCategory+1; 816 key -= Qtopia::AddressCategory+1;
816 buf += SLFIELDS[key]; 817 buf += SLFIELDS[key];
817 buf += "=\"" + Qtopia::escapeString(value) + "\" "; 818 buf += "=\"" + Qtopia::escapeString(value) + "\" ";
818 } 819 }
819 } 820 }
820 buf += customToXml(); 821 buf += customToXml();
821 if ( categories().count() > 0 ) 822 if ( categories().count() > 0 )
822 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 823 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
823 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 824 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
824 // You need to close this yourself 825 // You need to close this yourself
825} 826}
826 827
827 828
828/*! 829/*!
829 \internal 830 \internal
830 Returns the list of fields belonging to a contact 831 Returns the list of fields belonging to a contact
831 Never change order of this list ! It has to be regarding 832 Never change order of this list ! It has to be regarding
832 enum AddressBookFields !! 833 enum AddressBookFields !!
833*/ 834*/
834QStringList OContact::fields() 835QStringList OContact::fields()
835{ 836{
836 QStringList list; 837 QStringList list;
837 838
838 list.append( "Title" ); // Not Used! 839 list.append( "Title" ); // Not Used!
839 list.append( "FirstName" ); 840 list.append( "FirstName" );
840 list.append( "MiddleName" ); 841 list.append( "MiddleName" );
841 list.append( "LastName" ); 842 list.append( "LastName" );
842 list.append( "Suffix" ); 843 list.append( "Suffix" );
843 list.append( "FileAs" ); 844 list.append( "FileAs" );
844 845
845 list.append( "JobTitle" ); 846 list.append( "JobTitle" );
846 list.append( "Department" ); 847 list.append( "Department" );
847 list.append( "Company" ); 848 list.append( "Company" );
848 list.append( "BusinessPhone" ); 849 list.append( "BusinessPhone" );
849 list.append( "BusinessFax" ); 850 list.append( "BusinessFax" );
850 list.append( "BusinessMobile" ); 851 list.append( "BusinessMobile" );
851 852
852 list.append( "DefaultEmail" ); 853 list.append( "DefaultEmail" );
853 list.append( "Emails" ); 854 list.append( "Emails" );
854 855
855 list.append( "HomePhone" ); 856 list.append( "HomePhone" );
856 list.append( "HomeFax" ); 857 list.append( "HomeFax" );
857 list.append( "HomeMobile" ); 858 list.append( "HomeMobile" );
858 859
859 list.append( "BusinessStreet" ); 860 list.append( "BusinessStreet" );
860 list.append( "BusinessCity" ); 861 list.append( "BusinessCity" );
861 list.append( "BusinessState" ); 862 list.append( "BusinessState" );
862 list.append( "BusinessZip" ); 863 list.append( "BusinessZip" );
863 list.append( "BusinessCountry" ); 864 list.append( "BusinessCountry" );
864 list.append( "BusinessPager" ); 865 list.append( "BusinessPager" );
865 list.append( "BusinessWebPage" ); 866 list.append( "BusinessWebPage" );
866 867
867 list.append( "Office" ); 868 list.append( "Office" );
868 list.append( "Profession" ); 869 list.append( "Profession" );
869 list.append( "Assistant" ); 870 list.append( "Assistant" );
870 list.append( "Manager" ); 871 list.append( "Manager" );
871 872
872 list.append( "HomeStreet" ); 873 list.append( "HomeStreet" );
873 list.append( "HomeCity" ); 874 list.append( "HomeCity" );
874 list.append( "HomeState" ); 875 list.append( "HomeState" );
875 list.append( "HomeZip" ); 876 list.append( "HomeZip" );
876 list.append( "HomeCountry" ); 877 list.append( "HomeCountry" );
877 list.append( "HomeWebPage" ); 878 list.append( "HomeWebPage" );
878 879
879 list.append( "Spouse" ); 880 list.append( "Spouse" );
880 list.append( "Gender" ); 881 list.append( "Gender" );
881 list.append( "Birthday" ); 882 list.append( "Birthday" );
882 list.append( "Anniversary" ); 883 list.append( "Anniversary" );
883 list.append( "Nickname" ); 884 list.append( "Nickname" );
884 list.append( "Children" ); 885 list.append( "Children" );
885 886
886 list.append( "Notes" ); 887 list.append( "Notes" );
887 list.append( "Groups" ); 888 list.append( "Groups" );
888 889
889 return list; 890 return list;
890} 891}
891 892
892 893
893/*! 894/*!
894 Sets the list of email address for contact to those contained in \a str. 895 Sets the list of email address for contact to those contained in \a str.
895 Email address should be separated by ';'s. 896 Email address should be separated by ';'s.
896*/ 897*/
897void OContact::setEmails( const QString &str ) 898void OContact::setEmails( const QString &str )
898{ 899{
899 replace( Qtopia::Emails, str ); 900 replace( Qtopia::Emails, str );
900 if ( str.isEmpty() ) 901 if ( str.isEmpty() )
901 setDefaultEmail( QString::null ); 902 setDefaultEmail( QString::null );
902} 903}
903 904
904/*! 905/*!
905 Sets the list of children for the contact to those contained in \a str. 906 Sets the list of children for the contact to those contained in \a str.
906*/ 907*/
907void OContact::setChildren( const QString &str ) 908void OContact::setChildren( const QString &str )
908{ 909{
909 replace( Qtopia::Children, str ); 910 replace( Qtopia::Children, str );
910} 911}
911 912
912/*! 913/*!
913 Returns TRUE if the contact matches the regular expression \a regexp. 914 Returns TRUE if the contact matches the regular expression \a regexp.
914 Otherwise returns FALSE. 915 Otherwise returns FALSE.
915*/ 916*/
916bool OContact::match( const QString &regexp ) const 917bool OContact::match( const QString &regexp ) const
917{ 918{
918 return match(QRegExp(regexp)); 919 return match(QRegExp(regexp));
919} 920}
920 921
921/*! 922/*!
922 \overload 923 \overload
923 Returns TRUE if the contact matches the regular expression \a regexp. 924 Returns TRUE if the contact matches the regular expression \a regexp.
924 Otherwise returns FALSE. 925 Otherwise returns FALSE.
925*/ 926*/
926bool OContact::match( const QRegExp &r ) const 927bool OContact::match( const QRegExp &r ) const
927{ 928{
928 bool match; 929 bool match;
929 match = false; 930 match = false;
930 QMap<int, QString>::ConstIterator it; 931 QMap<int, QString>::ConstIterator it;
931 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 932 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
932 if ( (*it).find( r ) > -1 ) { 933 if ( (*it).find( r ) > -1 ) {
933 match = true; 934 match = true;
934 break; 935 break;
935 } 936 }
936 } 937 }
937 return match; 938 return match;
938} 939}
939 940
940 941
941QString OContact::toShortText() const 942QString OContact::toShortText() const
942{ 943{
943 return ( fullName() ); 944 return ( fullName() );
944} 945}
945QString OContact::type() const 946QString OContact::type() const
946{ 947{
947 return QString::fromLatin1( "OContact" ); 948 return QString::fromLatin1( "OContact" );
948} 949}
949 950
950// Definition is missing ! (se) 951// Definition is missing ! (se)
951QMap<QString,QString> OContact::toExtraMap() const 952QMap<QString,QString> OContact::toExtraMap() const
952{ 953{
953 qWarning ("Function not implemented: OContact::toExtraMap()"); 954 qWarning ("Function not implemented: OContact::toExtraMap()");
954 QMap <QString,QString> useless; 955 QMap <QString,QString> useless;
955 return useless; 956 return useless;
956} 957}
957 958
958class QString OContact::recordField( int pos ) const 959class QString OContact::recordField( int pos ) const
959{ 960{
960 QStringList SLFIELDS = fields(); // ?? why this ? (se) 961 QStringList SLFIELDS = fields(); // ?? why this ? (se)
961 return SLFIELDS[pos]; 962 return SLFIELDS[pos];
962} 963}
963 964
964// In future releases, we should store birthday and anniversary 965// In future releases, we should store birthday and anniversary
965// internally as QDate instead of QString ! 966// internally as QDate instead of QString !
966// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 967// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
967 968
968/*! \fn void OContact::setBirthday( const QDate& date ) 969/*! \fn void OContact::setBirthday( const QDate& date )
969 Sets the birthday for the contact to \a date. If date is null 970 Sets the birthday for the contact to \a date. If date is null
970 the current stored date will be removed. 971 the current stored date will be removed.
971*/ 972*/
972void OContact::setBirthday( const QDate &v ) 973void OContact::setBirthday( const QDate &v )
973{ 974{
974 if ( v.isNull() ){ 975 if ( v.isNull() ){
975 qWarning( "Remove Birthday"); 976 qWarning( "Remove Birthday");
976 replace( Qtopia::Birthday, QString::null ); 977 replace( Qtopia::Birthday, QString::null );
977 return; 978 return;
978 } 979 }
979 980
980 if ( v.isValid() ) 981 if ( v.isValid() )
981 replace( Qtopia::Birthday, TimeConversion::toString( v ) ); 982 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
982 983
983} 984}
984 985
985 986
986/*! \fn void OContact::setAnniversary( const QDate &date ) 987/*! \fn void OContact::setAnniversary( const QDate &date )
987 Sets the anniversary of the contact to \a date. If date is 988 Sets the anniversary of the contact to \a date. If date is
988 null, the current stored date will be removed. 989 null, the current stored date will be removed.
989*/ 990*/
990void OContact::setAnniversary( const QDate &v ) 991void OContact::setAnniversary( const QDate &v )
991{ 992{
992 if ( v.isNull() ){ 993 if ( v.isNull() ){
993 qWarning( "Remove Anniversary"); 994 qWarning( "Remove Anniversary");
994 replace( Qtopia::Anniversary, QString::null ); 995 replace( Qtopia::Anniversary, QString::null );
995 return; 996 return;
996 } 997 }
997 998
998 if ( v.isValid() ) 999 if ( v.isValid() )
999 replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); 1000 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
1000} 1001}
1001 1002
1002/*! \fn QDate OContact::birthday() const 1003/*! \fn QDate OContact::birthday() const
1003 Returns the birthday of the contact. 1004 Returns the birthday of the contact.
1004*/ 1005*/
1005QDate OContact::birthday() const 1006QDate OContact::birthday() const
1006{ 1007{
1007 QString str = find( Qtopia::Birthday ); 1008 QString str = find( Qtopia::Birthday );
1008 qWarning ("Birthday %s", str.latin1() ); 1009 qWarning ("Birthday %s", str.latin1() );
1009 if ( !str.isEmpty() ) 1010 if ( !str.isEmpty() )
1010 return TimeConversion::fromString ( str ); 1011 return TimeConversion::fromString ( str );
1011 else 1012 else
1012 return QDate(); 1013 return QDate();
1013} 1014}
1014 1015
1015 1016
1016/*! \fn QDate OContact::anniversary() const 1017/*! \fn QDate OContact::anniversary() const
1017 Returns the anniversary of the contact. 1018 Returns the anniversary of the contact.
1018*/ 1019*/
1019QDate OContact::anniversary() const 1020QDate OContact::anniversary() const
1020{ 1021{
1021 QDate empty; 1022 QDate empty;
1022 QString str = find( Qtopia::Anniversary ); 1023 QString str = find( Qtopia::Anniversary );
1023 qWarning ("Anniversary %s", str.latin1() ); 1024 qWarning ("Anniversary %s", str.latin1() );
1024 if ( !str.isEmpty() ) 1025 if ( !str.isEmpty() )
1025 return TimeConversion::fromString ( str ); 1026 return TimeConversion::fromString ( str );
1026 else 1027 else
1027 return empty; 1028 return empty;
1028} 1029}
1029 1030
1030 1031
1031void OContact::insertEmail( const QString &v ) 1032void OContact::insertEmail( const QString &v )
1032{ 1033{
1033 //qDebug("insertEmail %s", v.latin1()); 1034 //qDebug("insertEmail %s", v.latin1());
1034 QString e = v.simplifyWhiteSpace(); 1035 QString e = v.simplifyWhiteSpace();
1035 QString def = defaultEmail(); 1036 QString def = defaultEmail();
1036 1037
1037 // if no default, set it as the default email and don't insert 1038 // if no default, set it as the default email and don't insert
1038 if ( def.isEmpty() ) { 1039 if ( def.isEmpty() ) {
1039 setDefaultEmail( e ); // will insert into the list for us 1040 setDefaultEmail( e ); // will insert into the list for us
1040 return; 1041 return;
1041 } 1042 }
1042 1043
1043 // otherwise, insert assuming doesn't already exist 1044 // otherwise, insert assuming doesn't already exist
1044 QString emailsStr = find( Qtopia::Emails ); 1045 QString emailsStr = find( Qtopia::Emails );
1045 if ( emailsStr.contains( e )) 1046 if ( emailsStr.contains( e ))
1046 return; 1047 return;
1047 if ( !emailsStr.isEmpty() ) 1048 if ( !emailsStr.isEmpty() )
1048 emailsStr += emailSeparator(); 1049 emailsStr += emailSeparator();
1049 emailsStr += e; 1050 emailsStr += e;
1050 replace( Qtopia::Emails, emailsStr ); 1051 replace( Qtopia::Emails, emailsStr );
1051} 1052}
1052 1053
1053void OContact::removeEmail( const QString &v ) 1054void OContact::removeEmail( const QString &v )
1054{ 1055{
1055 QString e = v.simplifyWhiteSpace(); 1056 QString e = v.simplifyWhiteSpace();
1056 QString def = defaultEmail(); 1057 QString def = defaultEmail();
1057 QString emailsStr = find( Qtopia::Emails ); 1058 QString emailsStr = find( Qtopia::Emails );
1058 QStringList emails = emailList(); 1059 QStringList emails = emailList();
1059 1060
1060 // otherwise, must first contain it 1061 // otherwise, must first contain it
1061 if ( !emailsStr.contains( e ) ) 1062 if ( !emailsStr.contains( e ) )
1062 return; 1063 return;
1063 1064
1064 // remove it 1065 // remove it
1065 //qDebug(" removing email from list %s", e.latin1()); 1066 //qDebug(" removing email from list %s", e.latin1());
1066 emails.remove( e ); 1067 emails.remove( e );
1067 // reset the string 1068 // reset the string
1068 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1069 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1069 replace( Qtopia::Emails, emailsStr ); 1070 replace( Qtopia::Emails, emailsStr );
1070 1071
1071 // if default, then replace the default email with the first one 1072 // if default, then replace the default email with the first one
1072 if ( def == e ) { 1073 if ( def == e ) {
1073 //qDebug("removeEmail is default; setting new default"); 1074 //qDebug("removeEmail is default; setting new default");
1074 if ( !emails.count() ) 1075 if ( !emails.count() )
1075 clearEmails(); 1076 clearEmails();
1076 else // setDefaultEmail will remove e from the list 1077 else // setDefaultEmail will remove e from the list
1077 setDefaultEmail( emails.first() ); 1078 setDefaultEmail( emails.first() );
1078 } 1079 }
1079} 1080}
1080void OContact::clearEmails() 1081void OContact::clearEmails()
1081{ 1082{
1082 mMap.remove( Qtopia::DefaultEmail ); 1083 mMap.remove( Qtopia::DefaultEmail );
1083 mMap.remove( Qtopia::Emails ); 1084 mMap.remove( Qtopia::Emails );
1084} 1085}
1085void OContact::setDefaultEmail( const QString &v ) 1086void OContact::setDefaultEmail( const QString &v )
1086{ 1087{
1087 QString e = v.simplifyWhiteSpace(); 1088 QString e = v.simplifyWhiteSpace();
1088 1089
1089 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1090 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1090 replace( Qtopia::DefaultEmail, e ); 1091 replace( Qtopia::DefaultEmail, e );
1091 1092
1092 if ( !e.isEmpty() ) 1093 if ( !e.isEmpty() )
1093 insertEmail( e ); 1094 insertEmail( e );
1094 1095
1095} 1096}
1096 1097
1097void OContact::insertEmails( const QStringList &v ) 1098void OContact::insertEmails( const QStringList &v )
1098{ 1099{
1099 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1100 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1100 insertEmail( *it ); 1101 insertEmail( *it );
1101} 1102}
1102int OContact::rtti() { 1103int OContact::rtti() {
1103 return 2; 1104 return OPimResolver::AddressBook;
1104} 1105}
1105void OContact::setUid( int i ) 1106void OContact::setUid( int i )
1106{ 1107{
1107 OPimRecord::setUid(i); 1108 OPimRecord::setUid(i);
1108 replace( Qtopia::AddressUid , QString::number(i)); 1109 replace( Qtopia::AddressUid , QString::number(i));
1109} 1110}
diff --git a/libopie/pim/opimaccessbackend.h b/libopie/pim/opimaccessbackend.h
index 4f00bc9..e268f4f 100644
--- a/libopie/pim/opimaccessbackend.h
+++ b/libopie/pim/opimaccessbackend.h
@@ -1,141 +1,153 @@
1#ifndef OPIE_PIM_ACCESS_BACKEND 1#ifndef OPIE_PIM_ACCESS_BACKEND
2#define OPIE_PIM_ACCESS_BACKEND 2#define OPIE_PIM_ACCESS_BACKEND
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include <opie/otemplatebase.h> 6#include <opie/otemplatebase.h>
7#include <opie/opimrecord.h> 7#include <opie/opimrecord.h>
8 8
9 9
10/** 10/**
11 * OPimAccessBackend is the base class 11 * OPimAccessBackend is the base class
12 * for all private backends 12 * for all private backends
13 * it operates on OPimRecord as the base class 13 * it operates on OPimRecord as the base class
14 * and it's responsible for fast manipulating 14 * and it's responsible for fast manipulating
15 * the resource the implementation takes care 15 * the resource the implementation takes care
16 * of 16 * of
17 */ 17 */
18template <class T = OPimRecord> 18template <class T = OPimRecord>
19class OPimAccessBackend { 19class OPimAccessBackend {
20public: 20public:
21 typedef OTemplateBase<T> Frontend; 21 typedef OTemplateBase<T> Frontend;
22 OPimAccessBackend(); 22
23 /** The access hint from the frontend */
24 OPimAccessBackend(int access = 0);
23 virtual ~OPimAccessBackend(); 25 virtual ~OPimAccessBackend();
24 26
25 /** 27 /**
26 * load the resource 28 * load the resource
27 */ 29 */
28 virtual bool load() = 0; 30 virtual bool load() = 0;
29 31
30 /** 32 /**
31 * reload the resource 33 * reload the resource
32 */ 34 */
33 virtual bool reload() = 0; 35 virtual bool reload() = 0;
34 36
35 /** 37 /**
36 * save the resource and 38 * save the resource and
37 * all it's changes 39 * all it's changes
38 */ 40 */
39 virtual bool save() = 0; 41 virtual bool save() = 0;
40 42
41 /** 43 /**
42 * return an array of 44 * return an array of
43 * all available uids 45 * all available uids
44 */ 46 */
45 virtual QArray<int> allRecords()const = 0; 47 virtual QArray<int> allRecords()const = 0;
46 48
47 /** 49 /**
48 * queryByExample for T with the SortOrder 50 * queryByExample for T with the SortOrder
49 * sort 51 * sort
50 */ 52 */
51 virtual QArray<int> queryByExample( const T& t, int sort ) = 0; 53 virtual QArray<int> queryByExample( const T& t, int sort ) = 0;
52 54
53 /** 55 /**
54 * find the OPimRecord with uid @param uid 56 * find the OPimRecord with uid @param uid
55 * returns T and T.isEmpty() if nothing was found 57 * returns T and T.isEmpty() if nothing was found
56 */ 58 */
57 virtual T find(int uid )const = 0; 59 virtual T find(int uid )const = 0;
58 60
59 virtual T find(int uid, const QArray<int>& items, 61 virtual T find(int uid, const QArray<int>& items,
60 uint current, typename Frontend::CacheDirection )const ; 62 uint current, typename Frontend::CacheDirection )const ;
61 /** 63 /**
62 * clear the back end 64 * clear the back end
63 */ 65 */
64 virtual void clear() = 0; 66 virtual void clear() = 0;
65 67
66 /** 68 /**
67 * add T 69 * add T
68 */ 70 */
69 virtual bool add( const T& t ) = 0; 71 virtual bool add( const T& t ) = 0;
70 72
71 /** 73 /**
72 * remove 74 * remove
73 */ 75 */
74 virtual bool remove( int uid ) = 0; 76 virtual bool remove( int uid ) = 0;
75 77
76 /** 78 /**
77 * replace a record with T.uid() 79 * replace a record with T.uid()
78 */ 80 */
79 virtual bool replace( const T& t ) = 0; 81 virtual bool replace( const T& t ) = 0;
80 82
81 /* 83 /*
82 * setTheFrontEnd!!! 84 * setTheFrontEnd!!!
83 */ 85 */
84 void setFrontend( Frontend* front ); 86 void setFrontend( Frontend* front );
85 87
86 /** 88 /**
87 * set the read ahead count 89 * set the read ahead count
88 */ 90 */
89 void setReadAhead( uint count ); 91 void setReadAhead( uint count );
90protected: 92protected:
93 int access()const;
91 void cache( const T& t )const; 94 void cache( const T& t )const;
92 95
93 /** 96 /**
94 * use a prime number here! 97 * use a prime number here!
95 */ 98 */
96 void setSaneCacheSize( int ); 99 void setSaneCacheSize( int );
97 100
98 uint readAhead()const; 101 uint readAhead()const;
99 102
100private: 103private:
104 class Private;
105 Private* d;
101 Frontend* m_front; 106 Frontend* m_front;
102 uint m_read; 107 uint m_read;
108 int m_acc;
103 109
104}; 110};
105 111
106template <class T> 112template <class T>
107OPimAccessBackend<T>::OPimAccessBackend() { 113OPimAccessBackend<T>::OPimAccessBackend(int acc)
114 : m_acc( acc )
115{
108 m_front = 0l; 116 m_front = 0l;
109} 117}
110template <class T> 118template <class T>
111OPimAccessBackend<T>::~OPimAccessBackend() { 119OPimAccessBackend<T>::~OPimAccessBackend() {
112 120
113} 121}
114template <class T> 122template <class T>
115void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { 123void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
116 m_front = fr; 124 m_front = fr;
117} 125}
118template <class T> 126template <class T>
119void OPimAccessBackend<T>::cache( const T& t )const { 127void OPimAccessBackend<T>::cache( const T& t )const {
120 if (m_front ) 128 if (m_front )
121 m_front->cache( t ); 129 m_front->cache( t );
122} 130}
123template <class T> 131template <class T>
124void OPimAccessBackend<T>::setSaneCacheSize( int size) { 132void OPimAccessBackend<T>::setSaneCacheSize( int size) {
125 if (m_front ) 133 if (m_front )
126 m_front->setSaneCacheSize( size ); 134 m_front->setSaneCacheSize( size );
127} 135}
128template <class T> 136template <class T>
129T OPimAccessBackend<T>::find( int uid, const QArray<int>&, 137T OPimAccessBackend<T>::find( int uid, const QArray<int>&,
130 uint, typename Frontend::CacheDirection )const { 138 uint, typename Frontend::CacheDirection )const {
131 return find( uid ); 139 return find( uid );
132} 140}
133template <class T> 141template <class T>
134void OPimAccessBackend<T>::setReadAhead( uint count ) { 142void OPimAccessBackend<T>::setReadAhead( uint count ) {
135 m_read = count; 143 m_read = count;
136} 144}
137template <class T> 145template <class T>
138uint OPimAccessBackend<T>::readAhead()const { 146uint OPimAccessBackend<T>::readAhead()const {
139 return m_read; 147 return m_read;
140} 148}
149template <class T>
150int OPimAccessBackend<T>::access()const {
151 return m_acc;
152}
141#endif 153#endif
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h
index 8cf81c8..259e2c1 100644
--- a/libopie/pim/opimaccesstemplate.h
+++ b/libopie/pim/opimaccesstemplate.h
@@ -1,269 +1,286 @@
1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
2#define OPIE_PIM_ACCESS_TEMPLATE_H 2#define OPIE_PIM_ACCESS_TEMPLATE_H
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include <opie/opimrecord.h> 6#include <opie/opimrecord.h>
7#include <opie/opimaccessbackend.h> 7#include <opie/opimaccessbackend.h>
8#include <opie/orecordlist.h> 8#include <opie/orecordlist.h>
9 9
10#include "opimcache.h" 10#include "opimcache.h"
11#include "otemplatebase.h" 11#include "otemplatebase.h"
12 12
13/** 13/**
14 * Thats the frontend to our OPIE PIM 14 * Thats the frontend to our OPIE PIM
15 * Library. Either you want to use it's 15 * Library. Either you want to use it's
16 * interface or you want to implement 16 * interface or you want to implement
17 * your own Access lib 17 * your own Access lib
18 * Just create a OPimRecord and inherit from 18 * Just create a OPimRecord and inherit from
19 * the plugins 19 * the plugins
20 */ 20 */
21 21
22template <class T = OPimRecord > 22template <class T = OPimRecord >
23class OPimAccessTemplate : public OTemplateBase<T> { 23class OPimAccessTemplate : public OTemplateBase<T> {
24public: 24public:
25 enum Access {
26 Random = 0,
27 SortedAccess
28 };
25 typedef ORecordList<T> List; 29 typedef ORecordList<T> List;
26 typedef OPimAccessBackend<T> BackEnd; 30 typedef OPimAccessBackend<T> BackEnd;
27 typedef OPimCache<T> Cache; 31 typedef OPimCache<T> Cache;
28 32
29 /** 33 /**
30 * c'tor BackEnd 34 * c'tor BackEnd
35 * enum Access a small hint on how to handle the backend
31 */ 36 */
32 OPimAccessTemplate( BackEnd* end); 37 OPimAccessTemplate( BackEnd* end);
38
33 virtual ~OPimAccessTemplate(); 39 virtual ~OPimAccessTemplate();
34 40
35 /** 41 /**
36 * load from the backend 42 * load from the backend
37 */ 43 */
38 virtual bool load(); 44 bool load();
39 45
40 /** Reload database. 46 /** Reload database.
41 * You should execute this function if the external database 47 * You should execute this function if the external database
42 * was changed. 48 * was changed.
43 * This function will load the external database and afterwards 49 * This function will load the external database and afterwards
44 * rejoin the local changes. Therefore the local database will be set consistent. 50 * rejoin the local changes. Therefore the local database will be set consistent.
45 */ 51 */
46 virtual bool reload(); 52 virtual bool reload();
47 53
48 /** Save contacts database. 54 /** Save contacts database.
49 * Save is more a "commit". After calling this function, all changes are public available. 55 * Save is more a "commit". After calling this function, all changes are public available.
50 * @return true if successful 56 * @return true if successful
51 */ 57 */
52 virtual bool save(); 58 bool save();
53 59
54 /** 60 /**
55 * if the resource was changed externally 61 * if the resource was changed externally
56 * You should use the signal handling instead of polling possible changes ! 62 * You should use the signal handling instead of polling possible changes !
57 * zecke: Do you implement a signal for otodoaccess ? 63 * zecke: Do you implement a signal for otodoaccess ?
58 */ 64 */
59 bool wasChangedExternally()const; 65 bool wasChangedExternally()const;
60 66
61 /** 67 /**
62 * return a List of records 68 * return a List of records
63 * you can iterate over them 69 * you can iterate over them
64 */ 70 */
65 virtual List allRecords()const; 71 virtual List allRecords()const;
66 72
67 /** 73 /**
68 * queryByExample. 74 * queryByExample.
69 * @see otodoaccess, ocontactaccess 75 * @see otodoaccess, ocontactaccess
70 */ 76 */
71 virtual List queryByExample( const T& t, int querySettings ); 77 virtual List queryByExample( const T& t, int querySettings );
72 78
73 /** 79 /**
74 * find the OPimRecord uid 80 * find the OPimRecord uid
75 */ 81 */
76 virtual T find( int uid )const; 82 virtual T find( int uid )const;
77 83
78 /** 84 /**
79 * read ahead cache find method ;) 85 * read ahead cache find method ;)
80 */ 86 */
81 virtual T find( int uid, const QArray<int>&, 87 virtual T find( int uid, const QArray<int>&,
82 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 88 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
83 89
84 /* invalidate cache here */ 90 /* invalidate cache here */
85 /** 91 /**
86 * clears the backend and invalidates the backend 92 * clears the backend and invalidates the backend
87 */ 93 */
88 virtual void clear() ; 94 void clear() ;
89 95
90 /** 96 /**
91 * add T to the backend 97 * add T to the backend
92 * @param t The item to add. 98 * @param t The item to add.
93 * @return <i>true</i> if added successfully. 99 * @return <i>true</i> if added successfully.
94 */ 100 */
95 virtual bool add( const T& t ) ; 101 virtual bool add( const T& t ) ;
96 bool add( const OPimRecord& ); 102 bool add( const OPimRecord& );
97 103
98 /* only the uid matters */ 104 /* only the uid matters */
99 /** 105 /**
100 * remove T from the backend 106 * remove T from the backend
101 * @param t The item to remove 107 * @param t The item to remove
102 * @return <i>true</i> if successful. 108 * @return <i>true</i> if successful.
103 */ 109 */
104 virtual bool remove( const T& t ); 110 virtual bool remove( const T& t );
105 111
106 /** 112 /**
107 * remove the OPimRecord with uid 113 * remove the OPimRecord with uid
108 * @param uid The ID of the item to remove 114 * @param uid The ID of the item to remove
109 * @return <i>true</i> if successful. 115 * @return <i>true</i> if successful.
110 */ 116 */
111 virtual bool remove( int uid ); 117 bool remove( int uid );
118 bool remove( const OPimRecord& );
112 119
113 /** 120 /**
114 * replace T from backend 121 * replace T from backend
115 * @param t The item to replace 122 * @param t The item to replace
116 * @return <i>true</i> if successful. 123 * @return <i>true</i> if successful.
117 */ 124 */
118 virtual bool replace( const T& t) ; 125 virtual bool replace( const T& t) ;
119 126
120 void setReadAhead( uint count ); 127 void setReadAhead( uint count );
121 /** 128 /**
122 * @internal 129 * @internal
123 */ 130 */
124 void cache( const T& )const; 131 void cache( const T& )const;
125 void setSaneCacheSize( int ); 132 void setSaneCacheSize( int );
133
134 QArray<int> records()const;
126protected: 135protected:
127 /** 136 /**
128 * invalidate the cache 137 * invalidate the cache
129 */ 138 */
130 void invalidateCache(); 139 void invalidateCache();
131 140
132 void setBackEnd( BackEnd* end ); 141 void setBackEnd( BackEnd* end );
133 /** 142 /**
134 * returns the backend 143 * returns the backend
135 */ 144 */
136 BackEnd* backEnd(); 145 BackEnd* backEnd();
137 BackEnd* m_backEnd; 146 BackEnd* m_backEnd;
138 Cache m_cache; 147 Cache m_cache;
139 148
140}; 149};
141 150
142template <class T> 151template <class T>
143OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 152OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
144 : OTemplateBase<T>(), m_backEnd( end ) 153 : OTemplateBase<T>(), m_backEnd( end )
145{ 154{
146 if (end ) 155 if (end )
147 end->setFrontend( this ); 156 end->setFrontend( this );
148} 157}
149template <class T> 158template <class T>
150OPimAccessTemplate<T>::~OPimAccessTemplate() { 159OPimAccessTemplate<T>::~OPimAccessTemplate() {
151 qWarning("~OPimAccessTemplate<T>"); 160 qWarning("~OPimAccessTemplate<T>");
152 delete m_backEnd; 161 delete m_backEnd;
153} 162}
154template <class T> 163template <class T>
155bool OPimAccessTemplate<T>::load() { 164bool OPimAccessTemplate<T>::load() {
156 invalidateCache(); 165 invalidateCache();
157 return m_backEnd->load(); 166 return m_backEnd->load();
158} 167}
159template <class T> 168template <class T>
160bool OPimAccessTemplate<T>::reload() { 169bool OPimAccessTemplate<T>::reload() {
161 invalidateCache(); // zecke: I think this should be added (se) 170 invalidateCache(); // zecke: I think this should be added (se)
162 return m_backEnd->reload(); 171 return m_backEnd->reload();
163} 172}
164template <class T> 173template <class T>
165bool OPimAccessTemplate<T>::save() { 174bool OPimAccessTemplate<T>::save() {
166 return m_backEnd->save(); 175 return m_backEnd->save();
167} 176}
168template <class T> 177template <class T>
169typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 178typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
170 QArray<int> ints = m_backEnd->allRecords(); 179 QArray<int> ints = m_backEnd->allRecords();
171 List lis(ints, this ); 180 List lis(ints, this );
172 return lis; 181 return lis;
173} 182}
174template <class T> 183template <class T>
184QArray<int> OPimAccessTemplate<T>::records()const {
185 return m_backEnd->allRecords();
186}
187template <class T>
175typename OPimAccessTemplate<T>::List 188typename OPimAccessTemplate<T>::List
176OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { 189OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) {
177 QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); 190 QArray<int> ints = m_backEnd->queryByExample( t, sortOrder );
178 191
179 List lis(ints, this ); 192 List lis(ints, this );
180 return lis; 193 return lis;
181} 194}
182template <class T> 195template <class T>
183T OPimAccessTemplate<T>::find( int uid ) const{ 196T OPimAccessTemplate<T>::find( int uid ) const{
184 T t = m_backEnd->find( uid ); 197 T t = m_backEnd->find( uid );
185 cache( t ); 198 cache( t );
186 return t; 199 return t;
187} 200}
188template <class T> 201template <class T>
189T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 202T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
190 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 203 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
191 /* 204 /*
192 * better do T.isEmpty() 205 * better do T.isEmpty()
193 * after a find this way we would 206 * after a find this way we would
194 * avoid two finds in QCache... 207 * avoid two finds in QCache...
195 */ 208 */
196 // qWarning("find it now %d", uid ); 209 // qWarning("find it now %d", uid );
197 if (m_cache.contains( uid ) ) { 210 if (m_cache.contains( uid ) ) {
198 return m_cache.find( uid ); 211 return m_cache.find( uid );
199 } 212 }
200 213
201 T t = m_backEnd->find( uid, ar, current, dir ); 214 T t = m_backEnd->find( uid, ar, current, dir );
202 cache( t ); 215 cache( t );
203 return t; 216 return t;
204} 217}
205template <class T> 218template <class T>
206void OPimAccessTemplate<T>::clear() { 219void OPimAccessTemplate<T>::clear() {
207 invalidateCache(); 220 invalidateCache();
208 m_backEnd->clear(); 221 m_backEnd->clear();
209} 222}
210template <class T> 223template <class T>
211bool OPimAccessTemplate<T>::add( const T& t ) { 224bool OPimAccessTemplate<T>::add( const T& t ) {
212 cache( t ); 225 cache( t );
213 return m_backEnd->add( t ); 226 return m_backEnd->add( t );
214} 227}
215template <class T> 228template <class T>
216bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 229bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
217 /* same type */ 230 /* same type */
218 if ( rec.rtti() == T::rtti() ) { 231 if ( rec.rtti() == T::rtti() ) {
219 const T &t = static_cast<const T&>(rec); 232 const T &t = static_cast<const T&>(rec);
220 return add(t); 233 return add(t);
221 } 234 }
222 return false; 235 return false;
223} 236}
224template <class T> 237template <class T>
225bool OPimAccessTemplate<T>::remove( const T& t ) { 238bool OPimAccessTemplate<T>::remove( const T& t ) {
226 return remove( t.uid() ); 239 return remove( t.uid() );
227} 240}
228template <class T> 241template <class T>
229bool OPimAccessTemplate<T>::remove( int uid ) { 242bool OPimAccessTemplate<T>::remove( int uid ) {
230 m_cache.remove( uid ); 243 m_cache.remove( uid );
231 return m_backEnd->remove( uid ); 244 return m_backEnd->remove( uid );
232} 245}
233template <class T> 246template <class T>
247bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
248 return remove( rec.uid() );
249}
250template <class T>
234bool OPimAccessTemplate<T>::replace( const T& t ) { 251bool OPimAccessTemplate<T>::replace( const T& t ) {
235 m_cache.replace( t ); 252 m_cache.replace( t );
236 return m_backEnd->replace( t ); 253 return m_backEnd->replace( t );
237} 254}
238template <class T> 255template <class T>
239void OPimAccessTemplate<T>::invalidateCache() { 256void OPimAccessTemplate<T>::invalidateCache() {
240 m_cache.invalidate(); 257 m_cache.invalidate();
241} 258}
242template <class T> 259template <class T>
243typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 260typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
244 return m_backEnd; 261 return m_backEnd;
245} 262}
246template <class T> 263template <class T>
247bool OPimAccessTemplate<T>::wasChangedExternally()const { 264bool OPimAccessTemplate<T>::wasChangedExternally()const {
248 return false; 265 return false;
249} 266}
250template <class T> 267template <class T>
251void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 268void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
252 m_backEnd = end; 269 m_backEnd = end;
253 if (m_backEnd ) 270 if (m_backEnd )
254 m_backEnd->setFrontend( this ); 271 m_backEnd->setFrontend( this );
255} 272}
256template <class T> 273template <class T>
257void OPimAccessTemplate<T>::cache( const T& t ) const{ 274void OPimAccessTemplate<T>::cache( const T& t ) const{
258 /* hacky we need to work around the const*/ 275 /* hacky we need to work around the const*/
259 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 276 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
260} 277}
261template <class T> 278template <class T>
262void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 279void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
263 m_cache.setSize( size ); 280 m_cache.setSize( size );
264} 281}
265template <class T> 282template <class T>
266void OPimAccessTemplate<T>::setReadAhead( uint count ) { 283void OPimAccessTemplate<T>::setReadAhead( uint count ) {
267 m_backEnd->setReadAhead( count ); 284 m_backEnd->setReadAhead( count );
268} 285}
269#endif 286#endif
diff --git a/libopie/pim/opimcache.h b/libopie/pim/opimcache.h
index 839550c..73414e5 100644
--- a/libopie/pim/opimcache.h
+++ b/libopie/pim/opimcache.h
@@ -1,119 +1,125 @@
1#ifndef OPIE_PIM_CACHE_H 1#ifndef OPIE_PIM_CACHE_H
2#define OPIE_PIM_CACHE_H 2#define OPIE_PIM_CACHE_H
3 3
4#include <qintcache.h> 4#include <qintcache.h>
5 5
6#include "opimrecord.h" 6#include "opimrecord.h"
7 7
8template <class T = OPimRecord> 8template <class T = OPimRecord>
9class OPimCacheItem { 9class OPimCacheItem {
10public: 10public:
11 OPimCacheItem( const T& t = T() ); 11 OPimCacheItem( const T& t = T() );
12 OPimCacheItem( const OPimCacheItem& );
12 ~OPimCacheItem(); 13 ~OPimCacheItem();
13 14
15 OPimCacheItem &operator=( const OPimCacheItem& );
16
14 T record()const; 17 T record()const;
15 void setRecord( const T& ); 18 void setRecord( const T& );
16private: 19private:
17 T m_t; 20 T m_t;
18}; 21};
19 22
20/** 23/**
21 * OPimCache for caching the items 24 * OPimCache for caching the items
22 * We support adding, removing 25 * We support adding, removing
23 * and finding 26 * and finding
24 */ 27 */
25template <class T = OPimRecord> 28template <class T = OPimRecord>
26class OPimCache { 29class OPimCache {
27public: 30public:
28 typedef OPimCacheItem<T> Item; 31 typedef OPimCacheItem<T> Item;
29 OPimCache(); 32 OPimCache();
33 OPimCache( const OPimCache& );
30 ~OPimCache(); 34 ~OPimCache();
31 35
36 OPimCache &operator=( const OPimCache& );
37
32 bool contains(int uid)const; 38 bool contains(int uid)const;
33 void invalidate(); 39 void invalidate();
34 void setSize( int size ); 40 void setSize( int size );
35 41
36 T find(int uid )const; 42 T find(int uid )const;
37 void add( const T& ); 43 void add( const T& );
38 void remove( int uid ); 44 void remove( int uid );
39 void replace( const T& ); 45 void replace( const T& );
40 46
41private: 47private:
42 QIntCache<Item> m_cache; 48 QIntCache<Item> m_cache;
43}; 49};
44 50
45// Implementation 51// Implementation
46template <class T> 52template <class T>
47OPimCacheItem<T>::OPimCacheItem( const T& t ) 53OPimCacheItem<T>::OPimCacheItem( const T& t )
48 : m_t(t) { 54 : m_t(t) {
49} 55}
50template <class T> 56template <class T>
51OPimCacheItem<T>::~OPimCacheItem() { 57OPimCacheItem<T>::~OPimCacheItem() {
52 58
53} 59}
54template <class T> 60template <class T>
55T OPimCacheItem<T>::record()const { 61T OPimCacheItem<T>::record()const {
56 return m_t; 62 return m_t;
57} 63}
58template <class T> 64template <class T>
59void OPimCacheItem<T>::setRecord( const T& t ) { 65void OPimCacheItem<T>::setRecord( const T& t ) {
60 m_t = t; 66 m_t = t;
61} 67}
62// Cache 68// Cache
63template <class T> 69template <class T>
64OPimCache<T>::OPimCache() 70OPimCache<T>::OPimCache()
65 : m_cache(100, 53 ) 71 : m_cache(100, 53 )
66{ 72{
67 m_cache.setAutoDelete( TRUE ); 73 m_cache.setAutoDelete( TRUE );
68} 74}
69template <class T> 75template <class T>
70OPimCache<T>::~OPimCache() { 76OPimCache<T>::~OPimCache() {
71 77
72} 78}
73template <class T> 79template <class T>
74bool OPimCache<T>::contains(int uid )const { 80bool OPimCache<T>::contains(int uid )const {
75 Item* it = m_cache.find( uid, FALSE ); 81 Item* it = m_cache.find( uid, FALSE );
76 if (!it) 82 if (!it)
77 return false; 83 return false;
78 return true; 84 return true;
79} 85}
80template <class T> 86template <class T>
81void OPimCache<T>::invalidate() { 87void OPimCache<T>::invalidate() {
82 m_cache.clear(); 88 m_cache.clear();
83} 89}
84template <class T> 90template <class T>
85void OPimCache<T>::setSize( int size ) { 91void OPimCache<T>::setSize( int size ) {
86 m_cache.setMaxCost( size ); 92 m_cache.setMaxCost( size );
87} 93}
88template <class T> 94template <class T>
89T OPimCache<T>::find(int uid )const { 95T OPimCache<T>::find(int uid )const {
90 Item *it = m_cache.find( uid ); 96 Item *it = m_cache.find( uid );
91 if (it) 97 if (it)
92 return it->record(); 98 return it->record();
93 return T(); 99 return T();
94} 100}
95template <class T> 101template <class T>
96void OPimCache<T>::add( const T& t ) { 102void OPimCache<T>::add( const T& t ) {
97 Item* it = 0l; 103 Item* it = 0l;
98 it = m_cache.find(t.uid(), FALSE ); 104 it = m_cache.find(t.uid(), FALSE );
99 105
100 if (it ) 106 if (it )
101 it->setRecord( t ); 107 it->setRecord( t );
102 108
103 it = new Item( t ); 109 it = new Item( t );
104 if (!m_cache.insert( t.uid(), it ) ) 110 if (!m_cache.insert( t.uid(), it ) )
105 delete it; 111 delete it;
106} 112}
107template <class T> 113template <class T>
108void OPimCache<T>::remove( int uid ) { 114void OPimCache<T>::remove( int uid ) {
109 m_cache.remove( uid ); 115 m_cache.remove( uid );
110} 116}
111template <class T> 117template <class T>
112void OPimCache<T>::replace( const T& t) { 118void OPimCache<T>::replace( const T& t) {
113 Item *it = m_cache.find( t.uid() ); 119 Item *it = m_cache.find( t.uid() );
114 if ( it ) { 120 if ( it ) {
115 it->setRecord( t ); 121 it->setRecord( t );
116 } 122 }
117} 123}
118 124
119#endif 125#endif
diff --git a/libopie/pim/opimmainwindow.cpp b/libopie/pim/opimmainwindow.cpp
index 92be2fd..7e57f3a 100644
--- a/libopie/pim/opimmainwindow.cpp
+++ b/libopie/pim/opimmainwindow.cpp
@@ -1,71 +1,105 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <qcopchannel_qws.h> 2#include <qcopchannel_qws.h>
3 3
4#include <qpe/qcopenvelope_qws.h> 4#include <qpe/qcopenvelope_qws.h>
5 5
6#include "opimresolver.h"
6#include "opimmainwindow.h" 7#include "opimmainwindow.h"
7 8
8OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, 9OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent,
9 const char* name, WFlags flag ) 10 const char* name, WFlags flag )
10 : QMainWindow( parent, name, flag ), m_service( service ), m_fallBack(0l) { 11 : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) {
11 12
12 /* 13 /*
13 * let's generate our QCopChannel 14 * let's generate our QCopChannel
14 */ 15 */
15 m_str = QString("QPE/"+m_service).local8Bit(); 16 m_str = QString("QPE/"+m_service).local8Bit();
16 m_channel= new QCopChannel(m_str, this ); 17 m_channel= new QCopChannel(m_str, this );
17 connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), 18 connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ),
18 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); 19 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
19 20
20 /* connect flush and reload */ 21 /* connect flush and reload */
21 connect(qApp, SIGNAL(flush() ), 22 connect(qApp, SIGNAL(flush() ),
22 this, SLOT(flush() ) ); 23 this, SLOT(flush() ) );
23 connect(qApp, SIGNAL(reload() ), 24 connect(qApp, SIGNAL(reload() ),
24 this, SLOT(reload() ) ); 25 this, SLOT(reload() ) );
25} 26}
26OPimMainWindow::~OPimMainWindow() { 27OPimMainWindow::~OPimMainWindow() {
27 delete m_channel; 28 delete m_channel;
28} 29}
29QCopChannel* OPimMainWindow::channel() { 30QCopChannel* OPimMainWindow::channel() {
30 return m_channel; 31 return m_channel;
31} 32}
33void OPimMainWindow::doSetDocument( const QString& ) {
34
35}
32void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { 36void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
33 /* 37 /*
34 * create demands to create 38 * create demands to create
35 * a new record... 39 * a new record...
36 */ 40 */
37 QDataStream stream(array, IO_ReadOnly); 41 QDataStream stream(array, IO_ReadOnly);
38 if ( cmd == "create()" ) { 42 if ( cmd == "create()" ) {
39 int uid = create(); 43 int uid = create();
40 QCopEnvelope e(m_str, "created(int)" ); 44 QCopEnvelope e(m_str, "created(int)" );
41 e << uid; 45 e << uid;
42 }else if ( cmd == "remove(int)" ) { 46 }else if ( cmd == "remove(int)" ) {
43 int uid; 47 int uid;
44 stream >> uid; 48 stream >> uid;
45 bool rem = remove( uid ); 49 bool rem = remove( uid );
46 QCopEnvelope e(m_str, "removed(bool)" ); 50 QCopEnvelope e(m_str, "removed(bool)" );
47 e << rem; 51 e << rem;
48 }else if ( cmd == "beam(int,int)" ) { 52 }else if ( cmd == "beam(int,int)" ) {
49 int uid, trans; 53 int uid, trans;
50 stream >> uid; 54 stream >> uid;
51 stream >> trans; 55 stream >> trans;
52 beam( uid, trans ); 56 beam( uid, trans );
53 }else if ( cmd == "show(int)" ) { 57 }else if ( cmd == "show(int)" ) {
54 int uid; 58 int uid;
55 stream >> uid; 59 stream >> uid;
56 show( uid ); 60 show( uid );
57 }else if ( cmd == "edit(int)" ) { 61 }else if ( cmd == "edit(int)" ) {
58 int uid; 62 int uid;
59 stream >> uid; 63 stream >> uid;
60 edit( uid ); 64 edit( uid );
61 }else if ( cmd == "add(int,QByteArray)" ) { 65 }else if ( cmd == "add(int,QByteArray)" ) {
62 int rtti; 66 int rtti;
63 QByteArray array; 67 QByteArray array;
64 stream >> rtti; 68 stream >> rtti;
65 stream >> array; 69 stream >> array;
66 m_fallBack = record(rtti, array ); 70 m_fallBack = record(rtti, array );
67 if (!m_fallBack) return; 71 if (!m_fallBack) return;
68 add( *m_fallBack ); 72 add( *m_fallBack );
69 delete m_fallBack; 73 delete m_fallBack;
70 } 74 }
71} 75}
76/* implement the url scripting here */
77void OPimMainWindow::setDocument( const QString& str) {
78 doSetDocument( str );
79}
80/*
81 * we now try to get the array demarshalled
82 * check if the rtti matches this one
83 */
84OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) {
85 if ( service() != rtti )
86 return 0l;
87
88 OPimRecord* record = OPimResolver::self()->record( rtti );
89 QDataStream str(array, IO_ReadOnly );
90 if ( !record || !record->loadFromStream(str) ) {
91 delete record;
92 record = 0l;
93 }
94
95 return record;
96}
97/*
98 * get the rtti for the service
99 */
100int OPimMainWindow::service() {
101 if ( m_rtti == -1 )
102 m_rtti = OPimResolver::self()->serviceId( m_service );
103
104 return m_rtti;
105}
diff --git a/libopie/pim/opimmainwindow.h b/libopie/pim/opimmainwindow.h
index 94100bd..34b8a71 100644
--- a/libopie/pim/opimmainwindow.h
+++ b/libopie/pim/opimmainwindow.h
@@ -1,79 +1,89 @@
1#ifndef OPIE_PIM_MAINWINDOW_H 1#ifndef OPIE_PIM_MAINWINDOW_H
2#define OPIE_PIM_MAINWINDOW_H 2#define OPIE_PIM_MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5 5
6#include <opie/opimrecord.h> 6#include <opie/opimrecord.h>
7 7
8/** 8/**
9 * This is a common Opie PIM MainWindow 9 * This is a common Opie PIM MainWindow
10 * it takes care of the QCOP internals 10 * it takes care of the QCOP internals
11 * and implements some functions 11 * and implements some functions
12 * for the URL scripting schema 12 * for the URL scripting schema
13 */ 13 */
14/* 14/*
15 * due Qt and Templates with signal and slots 15 * due Qt and Templates with signal and slots
16 * do not work that good :( 16 * do not work that good :(
17 * (Ok how to moc a template ;) ) 17 * (Ok how to moc a template ;) )
18 * We will have the mainwindow which calls a struct which 18 * We will have the mainwindow which calls a struct which
19 * is normally reimplemented as a template ;) 19 * is normally reimplemented as a template ;)
20 */ 20 */
21 21
22class QCopChannel; 22class QCopChannel;
23class OPimMainWindow : public QMainWindow { 23class OPimMainWindow : public QMainWindow {
24 Q_OBJECT 24 Q_OBJECT
25public: 25public:
26 enum TransPort { BlueTooth=0, 26 enum TransPort { BlueTooth=0,
27 IrDa }; 27 IrDa };
28 28
29 OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, 29 OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0,
30 WFlags f = WType_TopLevel); 30 WFlags f = WType_TopLevel);
31 virtual ~OPimMainWindow(); 31 virtual ~OPimMainWindow();
32 32
33 33
34protected slots: 34protected slots:
35 /*
36 * called when a setDocument
37 * couldn't be handled by this window
38 */
39 virtual void doSetDocument( const QString& );
35 /* for syncing */ 40 /* for syncing */
36 virtual void flush() = 0; 41 virtual void flush() = 0;
37 virtual void reload() = 0; 42 virtual void reload() = 0;
38 43
39 /** create a new Records and return the uid */ 44 /** create a new Records and return the uid */
40 virtual int create() = 0; 45 virtual int create() = 0;
41 /** remove a record with UID == uid */ 46 /** remove a record with UID == uid */
42 virtual bool remove( int uid ) = 0; 47 virtual bool remove( int uid ) = 0;
43 /** beam the record with UID = uid */ 48 /** beam the record with UID = uid */
44 virtual void beam( int uid , int transport = IrDa) = 0; 49 virtual void beam( int uid , int transport = IrDa) = 0;
45 50
46 /** show the record with UID == uid */ 51 /** show the record with UID == uid */
47 virtual void show( int uid ) = 0; 52 virtual void show( int uid ) = 0;
48 /** edit the record */ 53 /** edit the record */
49 virtual void edit( int uid ) = 0; 54 virtual void edit( int uid ) = 0;
50 55
51 /** make a copy of it! */ 56 /** make a copy of it! */
52 virtual void add( const OPimRecord& ) = 0; 57 virtual void add( const OPimRecord& ) = 0;
53 58
54 /* I would love to do this as a template 59
55 * but can't think of a right way
56 * because I need signal and slots -zecke
57 */
58 /*
59 * the only pointer in the whole PIM API :(
60 */
61 virtual OPimRecord* record( int rtti, const QByteArray& ) = 0;
62 QCopChannel* channel(); 60 QCopChannel* channel();
63 61
64private slots: 62private slots:
65 void appMessage( const QCString&, const QByteArray& ); 63 void appMessage( const QCString&, const QByteArray& );
64 void setDocument( const QString& );
66 65
67 66
68private: 67private:
69 class Private; 68 class Private;
70 Private* d; 69 Private* d;
71 70
71 int m_rtti;
72 QCopChannel* m_channel; 72 QCopChannel* m_channel;
73 QString m_service; 73 QString m_service;
74 QCString m_str; 74 QCString m_str;
75 OPimRecord* m_fallBack; 75 OPimRecord* m_fallBack;
76
77 /* I would love to do this as a template
78 * but can't think of a right way
79 * because I need signal and slots -zecke
80 */
81 /*
82 * the only pointer in the whole PIM API :(
83 */
84 virtual OPimRecord* record( int rtti, const QByteArray& ) ;
85 int service();
76}; 86};
77 87
78 88
79#endif 89#endif
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp
index 49b5bf9..ac0f4a9 100644
--- a/libopie/pim/opimrecord.cpp
+++ b/libopie/pim/opimrecord.cpp
@@ -1,84 +1,166 @@
1#include <qarray.h>
2
1#include <qpe/categories.h> 3#include <qpe/categories.h>
2#include <qpe/categoryselect.h> 4#include <qpe/categoryselect.h>
3 5
4#include "opimrecord.h" 6#include "opimrecord.h"
5 7
6Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 8Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
7 9
8 10
9OPimRecord::OPimRecord( int uid ) 11OPimRecord::OPimRecord( int uid )
10 : Qtopia::Record() { 12 : Qtopia::Record() {
11 13
12 setUid( uid ); 14 setUid( uid );
13} 15}
14OPimRecord::~OPimRecord() { 16OPimRecord::~OPimRecord() {
15} 17}
16OPimRecord::OPimRecord( const OPimRecord& rec ) 18OPimRecord::OPimRecord( const OPimRecord& rec )
17 : Qtopia::Record( rec ) 19 : Qtopia::Record( rec )
18{ 20{
19 (*this) = rec; 21 (*this) = rec;
20} 22}
21 23
22OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { 24OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
23 Qtopia::Record::operator=( rec ); 25 Qtopia::Record::operator=( rec );
24 m_xrefman = rec.m_xrefman; 26 m_xrefman = rec.m_xrefman;
25 27
26 return *this; 28 return *this;
27} 29}
28/* 30/*
29 * category names 31 * category names
30 */ 32 */
31QStringList OPimRecord::categoryNames()const { 33QStringList OPimRecord::categoryNames()const {
32 QStringList list; 34 QStringList list;
33 QArray<int> cats = categories(); 35 QArray<int> cats = categories();
34 Categories catDB; 36 Categories catDB;
35 catDB.load( categoryFileName() ); 37 catDB.load( categoryFileName() );
36 38
37 for (uint i = 0; i < cats.count(); i++ ) { 39 for (uint i = 0; i < cats.count(); i++ ) {
38 list << catDB.label("Todo List", cats[i] ); 40 list << catDB.label("Todo List", cats[i] );
39 } 41 }
40 42
41 return list; 43 return list;
42} 44}
43void OPimRecord::setCategoryNames( const QStringList& ) { 45void OPimRecord::setCategoryNames( const QStringList& ) {
44 46
45} 47}
46void OPimRecord::addCategoryName( const QString& ) { 48void OPimRecord::addCategoryName( const QString& ) {
47 Categories catDB; 49 Categories catDB;
48 catDB.load( categoryFileName() ); 50 catDB.load( categoryFileName() );
49 51
50 52
51} 53}
52bool OPimRecord::isEmpty()const { 54bool OPimRecord::isEmpty()const {
53 return ( uid() == 0 ); 55 return ( uid() == 0 );
54} 56}
55/*QString OPimRecord::crossToString()const { 57/*QString OPimRecord::crossToString()const {
56 QString str; 58 QString str;
57 QMap<QString, QArray<int> >::ConstIterator it; 59 QMap<QString, QArray<int> >::ConstIterator it;
58 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 60 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
59 QArray<int> id = it.data(); 61 QArray<int> id = it.data();
60 for ( uint i = 0; i < id.size(); ++i ) { 62 for ( uint i = 0; i < id.size(); ++i ) {
61 str += it.key() + "," + QString::number( i ) + ";"; 63 str += it.key() + "," + QString::number( i ) + ";";
62 } 64 }
63 } 65 }
64 str = str.remove( str.length()-1, 1); // strip the ; 66 str = str.remove( str.length()-1, 1); // strip the ;
65 //qWarning("IDS " + str ); 67 //qWarning("IDS " + str );
66 68
67 return str; 69 return str;
68 }*/ 70 }*/
69/* if uid = 1 assign a new one */ 71/* if uid = 1 assign a new one */
70void OPimRecord::setUid( int uid ) { 72void OPimRecord::setUid( int uid ) {
71 if ( uid == 1) 73 if ( uid == 1)
72 uid = uidGen().generate(); 74 uid = uidGen().generate();
73 75
74 Qtopia::Record::setUid( uid ); 76 Qtopia::Record::setUid( uid );
75}; 77};
76Qtopia::UidGen &OPimRecord::uidGen() { 78Qtopia::UidGen &OPimRecord::uidGen() {
77 return m_uidGen; 79 return m_uidGen;
78} 80}
79OPimXRefManager &OPimRecord::xrefmanager() { 81OPimXRefManager &OPimRecord::xrefmanager() {
80 return m_xrefman; 82 return m_xrefman;
81} 83}
82int OPimRecord::rtti(){ 84int OPimRecord::rtti(){
83 return 0; 85 return 0;
84} 86}
87
88/**
89 * now let's put our data into the stream
90 */
91/*
92 * First read UID
93 * Categories
94 * XRef
95 */
96bool OPimRecord::loadFromStream( QDataStream& stream ) {
97 int Int;
98 uint UInt;
99 stream >> Int;
100 setUid(Int);
101
102 /** Categories */
103 stream >> UInt;
104 QArray<int> array(UInt);
105 for (uint i = 0; i < UInt; i++ ) {
106 stream >> array[i];
107 }
108 setCategories( array );
109
110 /*
111 * now we do the X-Ref stuff
112 */
113 OPimXRef xref;
114 stream >> UInt;
115 for ( uint i = 0; i < UInt; i++ ) {
116 xref.setPartner( OPimXRef::One, partner( stream ) );
117 xref.setPartner( OPimXRef::Two, partner( stream ) );
118 m_xrefman.add( xref );
119 }
120
121 return true;
122}
123bool OPimRecord::saveToStream( QDataStream& stream )const {
124 /** UIDs */
125
126 stream << uid();
127
128 /** Categories */
129 stream << categories().count();
130 for ( uint i = 0; i < categories().count(); i++ ) {
131 stream << categories()[i];
132 }
133
134 /*
135 * first the XRef count
136 * then the xrefs
137 */
138 stream << m_xrefman.list().count();
139 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
140 it != m_xrefman.list().end(); ++it ) {
141 flush( (*it).partner( OPimXRef::One), stream );
142 flush( (*it).partner( OPimXRef::Two), stream );
143 }
144 return true;
145}
146void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{
147 str << par.service();
148 str << par.uid();
149 str << par.field();
150}
151OPimXRefPartner OPimRecord::partner( QDataStream& stream ) {
152 OPimXRefPartner par;
153 QString str;
154 int i;
155
156 stream >> str;
157 par.setService( str );
158
159 stream >> i;
160 par.setUid( i );
161
162 stream >> i ;
163 par.setField( i );
164
165 return par;
166}
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h
index ec99a13..665530f 100644
--- a/libopie/pim/opimrecord.h
+++ b/libopie/pim/opimrecord.h
@@ -1,122 +1,134 @@
1#ifndef OPIE_PIM_RECORD_H 1#ifndef OPIE_PIM_RECORD_H
2#define OPIE_PIM_RECORD_H 2#define OPIE_PIM_RECORD_H
3 3
4#include <qdatastream.h>
4#include <qmap.h> 5#include <qmap.h>
5#include <qstring.h> 6#include <qstring.h>
6#include <qstringlist.h> 7#include <qstringlist.h>
7 8
8#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
9 10
10#include <opie/opimxrefmanager.h> 11#include <opie/opimxrefmanager.h>
11 12
12/** 13/**
13 * This is the base class for 14 * This is the base class for
14 * all PIM Records 15 * all PIM Records
15 * 16 *
16 */ 17 */
17class OPimRecord : public Qtopia::Record { 18class OPimRecord : public Qtopia::Record {
18public: 19public:
19 /** 20 /**
20 * c'tor 21 * c'tor
21 * uid of 0 isEmpty 22 * uid of 0 isEmpty
22 * uid of 1 will be assigned a new one 23 * uid of 1 will be assigned a new one
23 */ 24 */
24 OPimRecord(int uid = 0); 25 OPimRecord(int uid = 0);
25 ~OPimRecord(); 26 ~OPimRecord();
26 27
27 /** 28 /**
28 * copy c'tor 29 * copy c'tor
29 */ 30 */
30 OPimRecord( const OPimRecord& rec ); 31 OPimRecord( const OPimRecord& rec );
31 32
32 /** 33 /**
33 * copy operator 34 * copy operator
34 */ 35 */
35 OPimRecord &operator=( const OPimRecord& ); 36 OPimRecord &operator=( const OPimRecord& );
36 37
37 /** 38 /**
38 * category names resolved 39 * category names resolved
39 */ 40 */
40 QStringList categoryNames()const; 41 QStringList categoryNames()const;
41 42
42 /** 43 /**
43 * set category names they will be resolved 44 * set category names they will be resolved
44 */ 45 */
45 void setCategoryNames( const QStringList& ); 46 void setCategoryNames( const QStringList& );
46 47
47 /** 48 /**
48 * addCategoryName adds a name 49 * addCategoryName adds a name
49 * to the internal category list 50 * to the internal category list
50 */ 51 */
51 void addCategoryName( const QString& ); 52 void addCategoryName( const QString& );
52 53
53 /** 54 /**
54 * if a Record isEmpty 55 * if a Record isEmpty
55 * it's empty if it's 0 56 * it's empty if it's 0
56 */ 57 */
57 virtual bool isEmpty()const; 58 virtual bool isEmpty()const;
58 59
59 /** 60 /**
60 * toRichText summary 61 * toRichText summary
61 */ 62 */
62 virtual QString toRichText()const = 0; 63 virtual QString toRichText()const = 0;
63 64
64 /** 65 /**
65 * a small one line summary 66 * a small one line summary
66 */ 67 */
67 virtual QString toShortText()const = 0; 68 virtual QString toShortText()const = 0;
68 69
69 /** 70 /**
70 * the name of the Record 71 * the name of the Record
71 */ 72 */
72 virtual QString type()const = 0; 73 virtual QString type()const = 0;
73 74
74 /** 75 /**
75 * converts the internal structure to a map 76 * converts the internal structure to a map
76 */ 77 */
77 virtual QMap<int, QString> toMap()const = 0; 78 virtual QMap<int, QString> toMap()const = 0;
78 79
79 /** 80 /**
80 * key value representation of extra items 81 * key value representation of extra items
81 */ 82 */
82 virtual QMap<QString, QString> toExtraMap()const = 0; 83 virtual QMap<QString, QString> toExtraMap()const = 0;
83 84
84 /** 85 /**
85 * the name for a recordField 86 * the name for a recordField
86 */ 87 */
87 virtual QString recordField(int)const = 0; 88 virtual QString recordField(int)const = 0;
88 89
89 /** 90 /**
90 * returns a reference of the 91 * returns a reference of the
91 * Cross Reference Manager 92 * Cross Reference Manager
92 * Partner 'One' is THIS PIM RECORD! 93 * Partner 'One' is THIS PIM RECORD!
93 * 'Two' is the Partner where we link to 94 * 'Two' is the Partner where we link to
94 */ 95 */
95 OPimXRefManager& xrefmanager(); 96 OPimXRefManager& xrefmanager();
96 97
97 /** 98 /**
98 * set the uid 99 * set the uid
99 */ 100 */
100 virtual void setUid( int uid ); 101 virtual void setUid( int uid );
101 102
102 /* 103 /*
103 * used inside the Templates for casting 104 * used inside the Templates for casting
104 * REIMPLEMENT in your .... 105 * REIMPLEMENT in your ....
105 */ 106 */
106 static int rtti(); 107 static int rtti();
107 108
109 /**
110 * some marshalling and de marshalling code
111 * saves the OPimRecord
112 * to and from a DataStream
113 */
114 virtual bool loadFromStream(QDataStream& );
115 virtual bool saveToStream( QDataStream& stream )const;
116
108protected: 117protected:
109 Qtopia::UidGen &uidGen(); 118 Qtopia::UidGen &uidGen();
110// QString crossToString()const; 119// QString crossToString()const;
111 120
112private: 121private:
113 class OPimRecordPrivate; 122 class OPimRecordPrivate;
114 OPimRecordPrivate *d; 123 OPimRecordPrivate *d;
115 OPimXRefManager m_xrefman; 124 OPimXRefManager m_xrefman;
116 static Qtopia::UidGen m_uidGen; 125 static Qtopia::UidGen m_uidGen;
117 126
127private:
128 void flush( const OPimXRefPartner&, QDataStream& stream )const;
129 OPimXRefPartner partner( QDataStream& );
118}; 130};
119 131
120 132
121 133
122#endif 134#endif
diff --git a/libopie/pim/opimresolver.cpp b/libopie/pim/opimresolver.cpp
new file mode 100644
index 0000000..4ebbd6e
--- a/dev/null
+++ b/libopie/pim/opimresolver.cpp
@@ -0,0 +1,198 @@
1#include <qcopchannel_qws.h>
2
3#include <qpe/qcopenvelope_qws.h>
4
5#include "otodoaccess.h"
6#include "ocontactaccess.h"
7
8//#include "opimfactory.h"
9#include "opimresolver.h"
10
11OPimResolver* OPimResolver::m_self = 0l;
12
13OPimResolver::OPimResolver() {
14 /* the built in channels */
15 m_builtIns << "Todolist" << "Addressbook" << "Datebook";
16}
17OPimResolver* OPimResolver::self() {
18 if (!m_self)
19 m_self = new OPimResolver();
20
21 return m_self;
22}
23
24/*
25 * FIXME use a cache here too
26 */
27OPimRecord* OPimResolver::record( const QString& service, int uid ) {
28 OPimRecord* rec = 0l;
29 OPimBase* base = backend( service );
30
31 if ( base )
32 rec = base->record( uid );
33 delete base;
34
35 return rec;
36}
37OPimRecord* OPimResolver::record( const QString& service ) {
38 return record( serviceId( service ) );
39}
40OPimRecord* OPimResolver::record( int rtti ) {
41 OPimRecord* rec = 0l;
42 switch( rtti ) {
43 case 1: /* todolist */
44 rec = new OTodo();
45 case 2: /* contact */
46 rec = new OContact();
47 default:
48 break;
49 }
50 /*
51 * FIXME resolve externally
52 */
53 if (!rec ) {
54 ;
55 }
56 return 0l;
57}
58bool OPimResolver::isBuiltIn( const QString& str) const{
59 return m_builtIns.contains( str );
60}
61QCString OPimResolver::qcopChannel( enum BuiltIn& built)const {
62 QCString str("QPE/");
63 switch( built ) {
64 case TodoList:
65 str += "Todolist";
66 break;
67 case DateBook:
68 str += "Datebook";
69 break;
70 case AddressBook:
71 str += "Addressbook";
72 break;
73 default:
74 break;
75 }
76
77 return str;
78}
79QCString OPimResolver::qcopChannel( const QString& service )const {
80 QCString str("QPE/");
81 str += service.latin1();
82 return str;
83}
84/*
85 * Implement services!!
86 * FIXME
87 */
88QCString OPimResolver::applicationChannel( enum BuiltIn& built)const {
89 QCString str("QPE/Application/");
90 switch( built ) {
91 case TodoList:
92 str += "todolist";
93 break;
94 case DateBook:
95 str += "datebook";
96 break;
97 case AddressBook:
98 str += "addressbook";
99 break;
100 }
101
102 return str;
103}
104QCString OPimResolver::applicationChannel( const QString& service )const {
105 QCString str("QPE/Application/");
106
107 if ( isBuiltIn( service ) ) {
108 if ( service == "Todolist" )
109 str += "todolist";
110 else if ( service == "Datebook" )
111 str += "datebook";
112 else if ( service == "Addressbook" )
113 str += "addressbook";
114 }else
115 ; // FIXME for additional stuff
116
117 return str;
118}
119QStringList OPimResolver::services()const {
120 return m_builtIns;
121}
122QString OPimResolver::serviceName( int rtti ) const{
123 QString str;
124 switch ( rtti ) {
125 case TodoList:
126 str = "Todolist";
127 break;
128 case DateBook:
129 str = "Datebook";
130 break;
131 case AddressBook:
132 str = "Addressbook";
133 break;
134 default:
135 break;
136 }
137 return str;
138 // FIXME me for 3rd party
139}
140int OPimResolver::serviceId( const QString& service ) {
141 int rtti = 0;
142 if ( service == "Todolist" )
143 rtti = TodoList;
144 else if ( service == "Datebook" )
145 rtti = DateBook;
146 else if ( service == "Addressbook" )
147 rtti = AddressBook;
148
149 return rtti;
150}
151/**
152 * check if the 'service' is registered and if so we'll
153 */
154bool OPimResolver::add( const QString& service, const OPimRecord& rec) {
155 if ( QCopChannel::isRegistered( applicationChannel( service ) ) ) {
156 QByteArray data;
157 QDataStream arg(data, IO_WriteOnly );
158 if ( rec.saveToStream( arg ) ) {
159 QCopEnvelope env( applicationChannel( service ), "add(int,QByteArray)" );
160 env << rec.rtti();
161 env << data;
162 }else
163 return false;
164 }else{
165 OPimBase* base = backend( service );
166 if (!base ) return false;
167
168 base->load();
169 base->add( rec );
170 base->save();
171 delete base;
172 }
173
174 return true;
175}
176OPimBase* OPimResolver::backend( const QString& service ) {
177 return backend( serviceId( service ) );
178}
179OPimBase* OPimResolver::backend( int rtti ) {
180 OPimBase* base = 0l;
181 switch( rtti ) {
182 case TodoList:
183 base = new OTodoAccess();
184 break;
185 case DateBook:
186 break;
187 case AddressBook:
188 base = new OContactAccess("Resolver");
189 break;
190 default:
191 break;
192 }
193 // FIXME for 3rd party
194 if (!base )
195 ;
196
197 return base;
198}
diff --git a/libopie/pim/opimresolver.h b/libopie/pim/opimresolver.h
index 86ae3eb..1ce1619 100644
--- a/libopie/pim/opimresolver.h
+++ b/libopie/pim/opimresolver.h
@@ -1,56 +1,90 @@
1#ifndef OPIE_PIM_RESOLVER 1#ifndef OPIE_PIM_RESOLVER
2#define OPIE_PIM_RESOLVER 2#define OPIE_PIM_RESOLVER
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7#include <opie/otemplatebase.h>
8
7/** 9/**
8 * OPimResolver is a MetaClass to access 10 * OPimResolver is a MetaClass to access
9 * available backends read only. 11 * available backends read only.
10 * It will be used to resolve uids + app names 12 * It will be used to resolve uids + app names
11 * to full informations 13 * to full informations
12 * to traverse through a list of alarms, reminders 14 * to traverse through a list of alarms, reminders
13 * to get access to built in PIM functionality 15 * to get access to built in PIM functionality
14 * and to more stuff 16 * and to more stuff
15 * THE PERFORMANCE will depend on THE BACKEND 17 * THE PERFORMANCE will depend on THE BACKEND
16 * USING XML is a waste of memory!!!!! 18 * USING XML is a waste of memory!!!!!
17 */ 19 */
18class OPimResolver : public QObject { 20class OPimResolver {
19public: 21public:
20 enum BuiltIn { TodoList = 0, 22 enum BuiltIn { TodoList = 0,
21 DateBook, 23 DateBook,
22 AddressBook 24 AddressBook
23 }; 25 };
24 static OPimResolver* self(); 26 static OPimResolver* self();
25 27
26 28
27 /* 29 /**
28 * return a record for a uid 30 * return a record for a uid
29 * and an app 31 * and an service
32 * You've THE OWNERSHIP NOW!
30 */ 33 */
31 OPimRecord &record( const QString& service, int uid ); 34 OPimRecord *record( const QString& service, int uid );
32 35
33 /** 36 /**
34 * return the QCopChannel for service 37 * return the QCopChannel for service
35 * When we will use Qtopia Services it will be used here 38 * When we will use Qtopia Services it will be used here
36 */ 39 */
37 QString qcopChannel( enum BuiltIn& )const; 40 QCString qcopChannel( enum BuiltIn& )const;
38 QString qcopChannel( const QString& service ); 41 QCString qcopChannel( const QString& service )const;
42
43 /**
44 * The Application channel (QPE/Application/name)
45 */
46 QCString applicationChannel( enum BuiltIn& )const;
47 QCString applicationChannel( const QString& service )const;
39 48
40 /** 49 /**
41 * return a list of available services 50 * return a list of available services
42 */ 51 */
43 QStringList services()const; 52 QStringList services()const;
44 53 inline QString serviceName(int rrti )const;
54 int serviceId( const QString& Service);
45 /** 55 /**
46 * add a record to a service... ;) 56 * add a record to a service... ;)
47 */ 57 */
48 bool add( const QString& service, const OPimRecord& ); 58 bool add( const QString& service, const OPimRecord& );
49 59
60
61 /**
62 * record returns an empty record for a given service.
63 * Be sure to delete it!!!
64 *
65 */
66 OPimRecord* record( const QString& service );
67 OPimRecord* record( int rtti );
68
69 /**
70 * you can cast to your
71 */
72 OPimBase* backend( const QString& service );
73 OPimBase* backend( int rtti );
50private: 74private:
51 OPimResolver(); 75 OPimResolver();
52 OPimRecord *m_last; 76 void loadData();
77 inline bool isBuiltIn( const QString& )const;
78 OPimRecord* recordExtern( const QString&, int );
79 OPimRecord* recordExtern( const QString& );
80
81 static OPimResolver* m_self;
82 struct Data;
83 class Private;
53 84
54}: 85 Data* data;
86 Private* d;
87 QStringList m_builtIns;
88};
55 89
56#endif 90#endif
diff --git a/libopie/pim/otemplatebase.h b/libopie/pim/otemplatebase.h
index b855919..29fb6ec 100644
--- a/libopie/pim/otemplatebase.h
+++ b/libopie/pim/otemplatebase.h
@@ -1,32 +1,91 @@
1#ifndef OPIE_TEMPLATE_BASE_H 1#ifndef OPIE_TEMPLATE_BASE_H
2#define OPIE_TEMPLATE_BASE_H 2#define OPIE_TEMPLATE_BASE_H
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include "opimrecord.h" 6#include <opie/opimrecord.h>
7
7 8
8/** 9/**
10 * Templates do not have a base class, This is why
11 * we've this class
12 * this is here to give us the possibility
13 * to have a common base class
14 * You may not want to use that interface internaly
15 * POOR mans interface
16 */
17struct OPimBase {
18 /**
19 * return the rtti
20 */
21 virtual int rtti()= 0;
22 virtual OPimRecord* record()const = 0;
23 virtual OPimRecord* record(int uid)const = 0;
24 virtual bool add( const OPimRecord& ) = 0;
25 virtual bool remove( int uid ) = 0;
26 virtual bool remove( const OPimRecord& ) = 0;
27 virtual void clear() = 0;
28 virtual bool load() = 0;
29 virtual bool save() = 0;
30 virtual QArray<int> records()const = 0;
31 /*
32 * ADD editing here?
33 * -zecke
34 */
35
36};
37/**
9 * internal template base 38 * internal template base
39 * T needs to implement the copy c'tor!!!
10 */ 40 */
11template <class T = OPimRecord> 41template <class T = OPimRecord>
12class OTemplateBase { 42class OTemplateBase : public OPimBase {
13public: 43public:
14 enum CacheDirection { Forward=0, Reverse }; 44 enum CacheDirection { Forward=0, Reverse };
15 OTemplateBase() { 45 OTemplateBase() {
16 }; 46 };
17 virtual ~OTemplateBase() { 47 virtual ~OTemplateBase() {
18 } 48 }
19 virtual T find( int uid )const = 0; 49 virtual T find( int uid )const = 0;
20 50
21 /** 51 /**
22 * read ahead find 52 * read ahead find
23 */ 53 */
24 virtual T find( int uid, const QArray<int>& items, 54 virtual T find( int uid, const QArray<int>& items,
25 uint current, CacheDirection dir = Forward )const = 0; 55 uint current, CacheDirection dir = Forward )const = 0;
26 virtual void cache( const T& )const = 0; 56 virtual void cache( const T& )const = 0;
27 virtual void setSaneCacheSize( int ) = 0; 57 virtual void setSaneCacheSize( int ) = 0;
28 58
59 /* reimplement of OPimBase */
60 int rtti();
61 OPimRecord* record()const;
62 OPimRecord* record(int uid )const;
63 static T* rec();
29}; 64};
30 65
66/*
67 * implementation
68 */
69template <class T>
70int
71OTemplateBase<T>::rtti() {
72 return T::rtti();
73}
74template <class T>
75OPimRecord* OTemplateBase<T>::record()const {
76 T* t = new T;
77 return t;
78}
79template <class T>
80OPimRecord* OTemplateBase<T>::record(int uid )const {
81 T t2 = find(uid );
82 T* t1 = new T(t2);
83
84 return t1;
85};
86template <class T>
87T* OTemplateBase<T>::rec() {
88 return new T;
89}
31 90
32#endif 91#endif
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index ece624a..cde2b3d 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,210 +1,211 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 18#include "opimnotifymanager.h"
19#include "opimresolver.h"
19 20
20#include "otodo.h" 21#include "otodo.h"
21 22
22 23
23struct OTodo::OTodoData : public QShared { 24struct OTodo::OTodoData : public QShared {
24 OTodoData() : QShared() { 25 OTodoData() : QShared() {
25 }; 26 };
26 27
27 QDate date; 28 QDate date;
28 bool isCompleted:1; 29 bool isCompleted:1;
29 bool hasDate:1; 30 bool hasDate:1;
30 int priority; 31 int priority;
31 QString desc; 32 QString desc;
32 QString sum; 33 QString sum;
33 QMap<QString, QString> extra; 34 QMap<QString, QString> extra;
34 ushort prog; 35 ushort prog;
35 OPimState state; 36 OPimState state;
36 ORecur recur; 37 ORecur recur;
37 OPimMaintainer maintainer; 38 OPimMaintainer maintainer;
38 QDate start; 39 QDate start;
39 QDate completed; 40 QDate completed;
40 OPimNotifyManager notifiers; 41 OPimNotifyManager notifiers;
41}; 42};
42 43
43OTodo::OTodo(const OTodo &event ) 44OTodo::OTodo(const OTodo &event )
44 : OPimRecord( event ), data( event.data ) 45 : OPimRecord( event ), data( event.data )
45{ 46{
46 data->ref(); 47 data->ref();
47// qWarning("ref up"); 48// qWarning("ref up");
48} 49}
49OTodo::~OTodo() { 50OTodo::~OTodo() {
50 51
51// qWarning("~OTodo " ); 52// qWarning("~OTodo " );
52 if ( data->deref() ) { 53 if ( data->deref() ) {
53// qWarning("OTodo::dereffing"); 54// qWarning("OTodo::dereffing");
54 delete data; 55 delete data;
55 data = 0l; 56 data = 0l;
56 } 57 }
57} 58}
58OTodo::OTodo(bool completed, int priority, 59OTodo::OTodo(bool completed, int priority,
59 const QArray<int> &category, 60 const QArray<int> &category,
60 const QString& summary, 61 const QString& summary,
61 const QString &description, 62 const QString &description,
62 ushort progress, 63 ushort progress,
63 bool hasDate, QDate date, int uid ) 64 bool hasDate, QDate date, int uid )
64 : OPimRecord( uid ) 65 : OPimRecord( uid )
65{ 66{
66// qWarning("OTodoData " + summary); 67// qWarning("OTodoData " + summary);
67 setCategories( category ); 68 setCategories( category );
68 69
69 data = new OTodoData; 70 data = new OTodoData;
70 71
71 data->date = date; 72 data->date = date;
72 data->isCompleted = completed; 73 data->isCompleted = completed;
73 data->hasDate = hasDate; 74 data->hasDate = hasDate;
74 data->priority = priority; 75 data->priority = priority;
75 data->sum = summary; 76 data->sum = summary;
76 data->prog = progress; 77 data->prog = progress;
77 data->desc = Qtopia::simplifyMultiLineSpace(description ); 78 data->desc = Qtopia::simplifyMultiLineSpace(description );
78} 79}
79OTodo::OTodo(bool completed, int priority, 80OTodo::OTodo(bool completed, int priority,
80 const QStringList &category, 81 const QStringList &category,
81 const QString& summary, 82 const QString& summary,
82 const QString &description, 83 const QString &description,
83 ushort progress, 84 ushort progress,
84 bool hasDate, QDate date, int uid ) 85 bool hasDate, QDate date, int uid )
85 : OPimRecord( uid ) 86 : OPimRecord( uid )
86{ 87{
87// qWarning("OTodoData" + summary); 88// qWarning("OTodoData" + summary);
88 setCategories( idsFromString( category.join(";") ) ); 89 setCategories( idsFromString( category.join(";") ) );
89 90
90 data = new OTodoData; 91 data = new OTodoData;
91 92
92 data->date = date; 93 data->date = date;
93 data->isCompleted = completed; 94 data->isCompleted = completed;
94 data->hasDate = hasDate; 95 data->hasDate = hasDate;
95 data->priority = priority; 96 data->priority = priority;
96 data->sum = summary; 97 data->sum = summary;
97 data->prog = progress; 98 data->prog = progress;
98 data->desc = Qtopia::simplifyMultiLineSpace(description ); 99 data->desc = Qtopia::simplifyMultiLineSpace(description );
99} 100}
100bool OTodo::match( const QRegExp &regExp )const 101bool OTodo::match( const QRegExp &regExp )const
101{ 102{
102 if( QString::number( data->priority ).find( regExp ) != -1 ){ 103 if( QString::number( data->priority ).find( regExp ) != -1 ){
103 return true; 104 return true;
104 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 105 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
105 return true; 106 return true;
106 }else if(data->desc.find( regExp ) != -1 ){ 107 }else if(data->desc.find( regExp ) != -1 ){
107 return true; 108 return true;
108 }else if(data->sum.find( regExp ) != -1 ) { 109 }else if(data->sum.find( regExp ) != -1 ) {
109 return true; 110 return true;
110 } 111 }
111 return false; 112 return false;
112} 113}
113bool OTodo::isCompleted() const 114bool OTodo::isCompleted() const
114{ 115{
115 return data->isCompleted; 116 return data->isCompleted;
116} 117}
117bool OTodo::hasDueDate() const 118bool OTodo::hasDueDate() const
118{ 119{
119 return data->hasDate; 120 return data->hasDate;
120} 121}
121bool OTodo::hasStartDate()const { 122bool OTodo::hasStartDate()const {
122 return data->start.isValid(); 123 return data->start.isValid();
123} 124}
124bool OTodo::hasCompletedDate()const { 125bool OTodo::hasCompletedDate()const {
125 return data->completed.isValid(); 126 return data->completed.isValid();
126} 127}
127int OTodo::priority()const 128int OTodo::priority()const
128{ 129{
129 return data->priority; 130 return data->priority;
130} 131}
131QString OTodo::summary() const 132QString OTodo::summary() const
132{ 133{
133 return data->sum; 134 return data->sum;
134} 135}
135ushort OTodo::progress() const 136ushort OTodo::progress() const
136{ 137{
137 return data->prog; 138 return data->prog;
138} 139}
139QDate OTodo::dueDate()const 140QDate OTodo::dueDate()const
140{ 141{
141 return data->date; 142 return data->date;
142} 143}
143QDate OTodo::startDate()const { 144QDate OTodo::startDate()const {
144 return data->start; 145 return data->start;
145} 146}
146QDate OTodo::completedDate()const { 147QDate OTodo::completedDate()const {
147 return data->completed; 148 return data->completed;
148} 149}
149QString OTodo::description()const 150QString OTodo::description()const
150{ 151{
151 return data->desc; 152 return data->desc;
152} 153}
153OPimState OTodo::state()const { 154OPimState OTodo::state()const {
154 return data->state; 155 return data->state;
155} 156}
156ORecur OTodo::recurrence()const { 157ORecur OTodo::recurrence()const {
157 return data->recur; 158 return data->recur;
158} 159}
159OPimMaintainer OTodo::maintainer()const { 160OPimMaintainer OTodo::maintainer()const {
160 return data->maintainer; 161 return data->maintainer;
161} 162}
162void OTodo::setCompleted( bool completed ) 163void OTodo::setCompleted( bool completed )
163{ 164{
164 changeOrModify(); 165 changeOrModify();
165 data->isCompleted = completed; 166 data->isCompleted = completed;
166} 167}
167void OTodo::setHasDueDate( bool hasDate ) 168void OTodo::setHasDueDate( bool hasDate )
168{ 169{
169 changeOrModify(); 170 changeOrModify();
170 data->hasDate = hasDate; 171 data->hasDate = hasDate;
171} 172}
172void OTodo::setDescription(const QString &desc ) 173void OTodo::setDescription(const QString &desc )
173{ 174{
174// qWarning( "desc " + desc ); 175// qWarning( "desc " + desc );
175 changeOrModify(); 176 changeOrModify();
176 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 177 data->desc = Qtopia::simplifyMultiLineSpace(desc );
177} 178}
178void OTodo::setSummary( const QString& sum ) 179void OTodo::setSummary( const QString& sum )
179{ 180{
180 changeOrModify(); 181 changeOrModify();
181 data->sum = sum; 182 data->sum = sum;
182} 183}
183void OTodo::setPriority(int prio ) 184void OTodo::setPriority(int prio )
184{ 185{
185 changeOrModify(); 186 changeOrModify();
186 data->priority = prio; 187 data->priority = prio;
187} 188}
188void OTodo::setDueDate( const QDate& date ) 189void OTodo::setDueDate( const QDate& date )
189{ 190{
190 changeOrModify(); 191 changeOrModify();
191 data->date = date; 192 data->date = date;
192} 193}
193void OTodo::setStartDate( const QDate& date ) { 194void OTodo::setStartDate( const QDate& date ) {
194 changeOrModify(); 195 changeOrModify();
195 data->start = date; 196 data->start = date;
196} 197}
197void OTodo::setCompletedDate( const QDate& date ) { 198void OTodo::setCompletedDate( const QDate& date ) {
198 changeOrModify(); 199 changeOrModify();
199 data->completed = date; 200 data->completed = date;
200} 201}
201void OTodo::setState( const OPimState& state ) { 202void OTodo::setState( const OPimState& state ) {
202 changeOrModify(); 203 changeOrModify();
203 data->state = state; 204 data->state = state;
204} 205}
205void OTodo::setRecurrence( const ORecur& rec) { 206void OTodo::setRecurrence( const ORecur& rec) {
206 changeOrModify(); 207 changeOrModify();
207 data->recur = rec; 208 data->recur = rec;
208} 209}
209void OTodo::setMaintainer( const OPimMaintainer& pim ) { 210void OTodo::setMaintainer( const OPimMaintainer& pim ) {
210 changeOrModify(); 211 changeOrModify();
@@ -228,194 +229,194 @@ QString OTodo::toShortText() const {
228 Returns a richt text string 229 Returns a richt text string
229*/ 230*/
230QString OTodo::toRichText() const 231QString OTodo::toRichText() const
231{ 232{
232 QString text; 233 QString text;
233 QStringList catlist; 234 QStringList catlist;
234 235
235 // Description of the todo 236 // Description of the todo
236 if ( !summary().isEmpty() ) { 237 if ( !summary().isEmpty() ) {
237 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 238 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
238 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 239 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
239 } 240 }
240 if( !description().isEmpty() ){ 241 if( !description().isEmpty() ){
241 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 242 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
242 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 243 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
243 } 244 }
244 text += "<br><br><br>"; 245 text += "<br><br><br>";
245 246
246 text += "<b>" + QObject::tr( "Priority:") +" </b>" 247 text += "<b>" + QObject::tr( "Priority:") +" </b>"
247 + QString::number( priority() ) + " <br>"; 248 + QString::number( priority() ) + " <br>";
248 text += "<b>" + QObject::tr( "Progress:") + " </b>" 249 text += "<b>" + QObject::tr( "Progress:") + " </b>"
249 + QString::number( progress() ) + " %<br>"; 250 + QString::number( progress() ) + " %<br>";
250 if (hasDueDate() ){ 251 if (hasDueDate() ){
251 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 252 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
252 text += dueDate().toString(); 253 text += dueDate().toString();
253 text += "<br>"; 254 text += "<br>";
254 } 255 }
255 256
256 text += "<b>" + QObject::tr( "Category:") + "</b> "; 257 text += "<b>" + QObject::tr( "Category:") + "</b> ";
257 text += categoryNames().join(", "); 258 text += categoryNames().join(", ");
258 text += "<br>"; 259 text += "<br>";
259 260
260 return text; 261 return text;
261} 262}
262OPimNotifyManager& OTodo::notifiers() { 263OPimNotifyManager& OTodo::notifiers() {
263 return data->notifiers; 264 return data->notifiers;
264} 265}
265 266
266bool OTodo::operator<( const OTodo &toDoEvent )const{ 267bool OTodo::operator<( const OTodo &toDoEvent )const{
267 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 268 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
268 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 269 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
269 if( hasDueDate() && toDoEvent.hasDueDate() ){ 270 if( hasDueDate() && toDoEvent.hasDueDate() ){
270 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 271 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
271 return priority() < toDoEvent.priority(); 272 return priority() < toDoEvent.priority();
272 }else{ 273 }else{
273 return dueDate() < toDoEvent.dueDate(); 274 return dueDate() < toDoEvent.dueDate();
274 } 275 }
275 } 276 }
276 return false; 277 return false;
277} 278}
278bool OTodo::operator<=(const OTodo &toDoEvent )const 279bool OTodo::operator<=(const OTodo &toDoEvent )const
279{ 280{
280 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 281 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
281 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 282 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
282 if( hasDueDate() && toDoEvent.hasDueDate() ){ 283 if( hasDueDate() && toDoEvent.hasDueDate() ){
283 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 284 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
284 return priority() <= toDoEvent.priority(); 285 return priority() <= toDoEvent.priority();
285 }else{ 286 }else{
286 return dueDate() <= toDoEvent.dueDate(); 287 return dueDate() <= toDoEvent.dueDate();
287 } 288 }
288 } 289 }
289 return true; 290 return true;
290} 291}
291bool OTodo::operator>(const OTodo &toDoEvent )const 292bool OTodo::operator>(const OTodo &toDoEvent )const
292{ 293{
293 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 294 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
294 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 295 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
295 if( hasDueDate() && toDoEvent.hasDueDate() ){ 296 if( hasDueDate() && toDoEvent.hasDueDate() ){
296 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 297 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
297 return priority() > toDoEvent.priority(); 298 return priority() > toDoEvent.priority();
298 }else{ 299 }else{
299 return dueDate() > toDoEvent.dueDate(); 300 return dueDate() > toDoEvent.dueDate();
300 } 301 }
301 } 302 }
302 return false; 303 return false;
303} 304}
304bool OTodo::operator>=(const OTodo &toDoEvent )const 305bool OTodo::operator>=(const OTodo &toDoEvent )const
305{ 306{
306 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 307 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
307 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 308 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
308 if( hasDueDate() && toDoEvent.hasDueDate() ){ 309 if( hasDueDate() && toDoEvent.hasDueDate() ){
309 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 310 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
310 return priority() > toDoEvent.priority(); 311 return priority() > toDoEvent.priority();
311 }else{ 312 }else{
312 return dueDate() > toDoEvent.dueDate(); 313 return dueDate() > toDoEvent.dueDate();
313 } 314 }
314 } 315 }
315 return true; 316 return true;
316} 317}
317bool OTodo::operator==(const OTodo &toDoEvent )const 318bool OTodo::operator==(const OTodo &toDoEvent )const
318{ 319{
319 if ( data->priority != toDoEvent.data->priority ) return false; 320 if ( data->priority != toDoEvent.data->priority ) return false;
320 if ( data->priority != toDoEvent.data->prog ) return false; 321 if ( data->priority != toDoEvent.data->prog ) return false;
321 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 322 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
322 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 323 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
323 if ( data->date != toDoEvent.data->date ) return false; 324 if ( data->date != toDoEvent.data->date ) return false;
324 if ( data->sum != toDoEvent.data->sum ) return false; 325 if ( data->sum != toDoEvent.data->sum ) return false;
325 if ( data->desc != toDoEvent.data->desc ) return false; 326 if ( data->desc != toDoEvent.data->desc ) return false;
326 if ( data->maintainer != toDoEvent.data->maintainer ) 327 if ( data->maintainer != toDoEvent.data->maintainer )
327 return false; 328 return false;
328 329
329 return OPimRecord::operator==( toDoEvent ); 330 return OPimRecord::operator==( toDoEvent );
330} 331}
331void OTodo::deref() { 332void OTodo::deref() {
332 333
333// qWarning("deref in ToDoEvent"); 334// qWarning("deref in ToDoEvent");
334 if ( data->deref() ) { 335 if ( data->deref() ) {
335// qWarning("deleting"); 336// qWarning("deleting");
336 delete data; 337 delete data;
337 data= 0; 338 data= 0;
338 } 339 }
339} 340}
340OTodo &OTodo::operator=(const OTodo &item ) 341OTodo &OTodo::operator=(const OTodo &item )
341{ 342{
342 OPimRecord::operator=( item ); 343 OPimRecord::operator=( item );
343 //qWarning("operator= ref "); 344 //qWarning("operator= ref ");
344 item.data->ref(); 345 item.data->ref();
345 deref(); 346 deref();
346 data = item.data; 347 data = item.data;
347 348
348 return *this; 349 return *this;
349} 350}
350 351
351QMap<int, QString> OTodo::toMap() const { 352QMap<int, QString> OTodo::toMap() const {
352 QMap<int, QString> map; 353 QMap<int, QString> map;
353 354
354 map.insert( Uid, QString::number( uid() ) ); 355 map.insert( Uid, QString::number( uid() ) );
355 map.insert( Category, idsToString( categories() ) ); 356 map.insert( Category, idsToString( categories() ) );
356 map.insert( HasDate, QString::number( data->hasDate ) ); 357 map.insert( HasDate, QString::number( data->hasDate ) );
357 map.insert( Completed, QString::number( data->isCompleted ) ); 358 map.insert( Completed, QString::number( data->isCompleted ) );
358 map.insert( Description, data->desc ); 359 map.insert( Description, data->desc );
359 map.insert( Summary, data->sum ); 360 map.insert( Summary, data->sum );
360 map.insert( Priority, QString::number( data->priority ) ); 361 map.insert( Priority, QString::number( data->priority ) );
361 map.insert( DateDay, QString::number( data->date.day() ) ); 362 map.insert( DateDay, QString::number( data->date.day() ) );
362 map.insert( DateMonth, QString::number( data->date.month() ) ); 363 map.insert( DateMonth, QString::number( data->date.month() ) );
363 map.insert( DateYear, QString::number( data->date.year() ) ); 364 map.insert( DateYear, QString::number( data->date.year() ) );
364 map.insert( Progress, QString::number( data->prog ) ); 365 map.insert( Progress, QString::number( data->prog ) );
365// map.insert( CrossReference, crossToString() ); 366// map.insert( CrossReference, crossToString() );
366 /* FIXME!!! map.insert( State, ); 367 /* FIXME!!! map.insert( State, );
367 map.insert( Recurrence, ); 368 map.insert( Recurrence, );
368 map.insert( Reminders, ); 369 map.insert( Reminders, );
369 map. 370 map.
370 */ 371 */
371 return map; 372 return map;
372} 373}
373 374
374QMap<QString, QString> OTodo::toExtraMap()const { 375QMap<QString, QString> OTodo::toExtraMap()const {
375 return data->extra; 376 return data->extra;
376} 377}
377/** 378/**
378 * change or modify looks at the ref count and either 379 * change or modify looks at the ref count and either
379 * creates a new QShared Object or it can modify it 380 * creates a new QShared Object or it can modify it
380 * right in place 381 * right in place
381 */ 382 */
382void OTodo::changeOrModify() { 383void OTodo::changeOrModify() {
383 if ( data->count != 1 ) { 384 if ( data->count != 1 ) {
384 qWarning("changeOrModify"); 385 qWarning("changeOrModify");
385 data->deref(); 386 data->deref();
386 OTodoData* d2 = new OTodoData(); 387 OTodoData* d2 = new OTodoData();
387 copy(data, d2 ); 388 copy(data, d2 );
388 data = d2; 389 data = d2;
389 } 390 }
390} 391}
391// WATCHOUT 392// WATCHOUT
392/* 393/*
393 * if you add something to the Data struct 394 * if you add something to the Data struct
394 * be sure to copy it here 395 * be sure to copy it here
395 */ 396 */
396void OTodo::copy( OTodoData* src, OTodoData* dest ) { 397void OTodo::copy( OTodoData* src, OTodoData* dest ) {
397 dest->date = src->date; 398 dest->date = src->date;
398 dest->isCompleted = src->isCompleted; 399 dest->isCompleted = src->isCompleted;
399 dest->hasDate = src->hasDate; 400 dest->hasDate = src->hasDate;
400 dest->priority = src->priority; 401 dest->priority = src->priority;
401 dest->desc = src->desc; 402 dest->desc = src->desc;
402 dest->sum = src->sum; 403 dest->sum = src->sum;
403 dest->extra = src->extra; 404 dest->extra = src->extra;
404 dest->prog = src->prog; 405 dest->prog = src->prog;
405 dest->state = src->state; 406 dest->state = src->state;
406 dest->recur = src->recur; 407 dest->recur = src->recur;
407 dest->maintainer = src->maintainer; 408 dest->maintainer = src->maintainer;
408 dest->start = src->start; 409 dest->start = src->start;
409 dest->completed = src->completed; 410 dest->completed = src->completed;
410 dest->notifiers = src->notifiers; 411 dest->notifiers = src->notifiers;
411} 412}
412QString OTodo::type() const { 413QString OTodo::type() const {
413 return QString::fromLatin1("OTodo"); 414 return QString::fromLatin1("OTodo");
414} 415}
415QString OTodo::recordField(int /*id*/ )const { 416QString OTodo::recordField(int /*id*/ )const {
416 return QString::null; 417 return QString::null;
417} 418}
418 419
419int OTodo::rtti(){ 420int OTodo::rtti(){
420 return 1; 421 return OPimResolver::TodoList;
421} 422}
diff --git a/libopie/pim/otodoaccess.cpp b/libopie/pim/otodoaccess.cpp
index d860411..5e89a1b 100644
--- a/libopie/pim/otodoaccess.cpp
+++ b/libopie/pim/otodoaccess.cpp
@@ -1,86 +1,56 @@
1#include <qdatetime.h> 1#include <qdatetime.h>
2 2
3#include <qpe/alarmserver.h> 3#include <qpe/alarmserver.h>
4 4
5// #include "otodoaccesssql.h" 5// #include "otodoaccesssql.h"
6#include "otodoaccess.h" 6#include "otodoaccess.h"
7#include "obackendfactory.h" 7#include "obackendfactory.h"
8 8
9OTodoAccess::OTodoAccess( OTodoAccessBackend* end ) 9OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access )
10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) 10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end )
11{ 11{
12// if (end == 0l ) 12// if (end == 0l )
13// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); 13// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null);
14 14
15 // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben ! 15 // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben !
16 if (end == 0l ) 16 if (end == 0l )
17 m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); 17 m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null);
18 18
19 setBackEnd( m_todoBackEnd ); 19 setBackEnd( m_todoBackEnd );
20} 20}
21OTodoAccess::~OTodoAccess() { 21OTodoAccess::~OTodoAccess() {
22// qWarning("~OTodoAccess"); 22// qWarning("~OTodoAccess");
23} 23}
24void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { 24void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) {
25 QValueList<OTodo>::ConstIterator it; 25 QValueList<OTodo>::ConstIterator it;
26 for ( it = list.begin(); it != list.end(); ++it ) { 26 for ( it = list.begin(); it != list.end(); ++it ) {
27 replace( (*it) ); 27 replace( (*it) );
28 } 28 }
29} 29}
30OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 30OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
31 const QDate& end, 31 const QDate& end,
32 bool includeNoDates ) { 32 bool includeNoDates ) {
33 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 33 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
34 34
35 List lis( ints, this ); 35 List lis( ints, this );
36 return lis; 36 return lis;
37} 37}
38OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 38OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
39 bool includeNoDates ) { 39 bool includeNoDates ) {
40 return effectiveToDos( start, QDate::currentDate(), 40 return effectiveToDos( start, QDate::currentDate(),
41 includeNoDates ); 41 includeNoDates );
42} 42}
43OTodoAccess::List OTodoAccess::overDue() { 43OTodoAccess::List OTodoAccess::overDue() {
44 List lis( m_todoBackEnd->overDue(), this ); 44 List lis( m_todoBackEnd->overDue(), this );
45 return lis; 45 return lis;
46} 46}
47void OTodoAccess::addAlarm( const OTodo& event) {
48/* FIXME use the new notifier architecture
49 if (!event.hasAlarmDateTime() )
50 return;
51
52 QDateTime now = QDateTime::currentDateTime();
53 QDateTime schedule = event.alarmDateTime();
54
55 if ( schedule > now ){
56 AlarmServer::addAlarm( schedule,
57 "QPE/Application/todolist",
58 "alarm(QDateTime,int)", event.uid() );
59
60 }
61*/
62}
63void OTodoAccess::delAlarm( int uid) {
64
65 QDateTime schedule; // Create null DateTime
66
67 // I hope this will remove all scheduled alarms
68 // with the given uid !?
69 // If not: I have to rethink how to remove already
70 // scheduled events... (se)
71 // it should be fine -zecke
72// qWarning("Removing alarm for event with uid %d", uid );
73 AlarmServer::deleteAlarm( schedule ,
74 "QPE/Application/todolist",
75 "alarm(QDateTime,int)", uid );
76}
77/* sort order */ 47/* sort order */
78OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 48OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
79 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, 49 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
80 filter, cat ); 50 filter, cat );
81 OTodoAccess::List list( ints, this ); 51 OTodoAccess::List list( ints, this );
82 return list; 52 return list;
83} 53}
84void OTodoAccess::removeAllCompleted() { 54void OTodoAccess::removeAllCompleted() {
85 m_todoBackEnd->removeAllCompleted(); 55 m_todoBackEnd->removeAllCompleted();
86} 56}
diff --git a/libopie/pim/otodoaccess.h b/libopie/pim/otodoaccess.h
index c079155..2bb87dc 100644
--- a/libopie/pim/otodoaccess.h
+++ b/libopie/pim/otodoaccess.h
@@ -1,98 +1,87 @@
1#ifndef OPIE_TODO_ACCESS_H 1#ifndef OPIE_TODO_ACCESS_H
2#define OPIE_TODO_ACCESS_H 2#define OPIE_TODO_ACCESS_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7#include "otodo.h" 7#include "otodo.h"
8#include "otodoaccessbackend.h" 8#include "otodoaccessbackend.h"
9#include "opimaccesstemplate.h" 9#include "opimaccesstemplate.h"
10 10
11 11
12/** 12/**
13 * OTodoAccess 13 * OTodoAccess
14 * the class to get access to 14 * the class to get access to
15 * the todolist 15 * the todolist
16 */ 16 */
17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { 17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 enum SortOrder { Completed = 0, 20 enum SortOrder { Completed = 0,
21 Priority, 21 Priority,
22 Description, 22 Description,
23 Deadline }; 23 Deadline };
24 enum SortFilter{ Category =1, 24 enum SortFilter{ Category =1,
25 OnlyOverDue= 2, 25 OnlyOverDue= 2,
26 DoNotShowCompleted =4 }; 26 DoNotShowCompleted =4 };
27 /** 27 /**
28 * if you use 0l 28 * if you use 0l
29 * the default resource will be 29 * the default resource will be
30 * picked up 30 * picked up
31 */ 31 */
32 OTodoAccess( OTodoAccessBackend* = 0l); 32 OTodoAccess( OTodoAccessBackend* = 0l, enum Access acc = Random );
33 ~OTodoAccess(); 33 ~OTodoAccess();
34 34
35 35
36 /* our functions here */ 36 /* our functions here */
37 /** 37 /**
38 * include todos from start to end 38 * include todos from start to end
39 * includeNoDates whether or not to include 39 * includeNoDates whether or not to include
40 * events with no dates 40 * events with no dates
41 */ 41 */
42 List effectiveToDos( const QDate& start, 42 List effectiveToDos( const QDate& start,
43 const QDate& end, 43 const QDate& end,
44 bool includeNoDates = true ); 44 bool includeNoDates = true );
45 45
46 /** 46 /**
47 * start 47 * start
48 * end date taken from the currentDate() 48 * end date taken from the currentDate()
49 */ 49 */
50 List effectiveToDos( const QDate& start, 50 List effectiveToDos( const QDate& start,
51 bool includeNoDates = true ); 51 bool includeNoDates = true );
52 52
53 53
54 /** 54 /**
55 * return overdue OTodos 55 * return overdue OTodos
56 */ 56 */
57 List overDue(); 57 List overDue();
58 58
59 /** 59 /**
60 * 60 *
61 */ 61 */
62 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); 62 List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
63 63
64 /** 64 /**
65 * merge a list of OTodos into 65 * merge a list of OTodos into
66 * the resource 66 * the resource
67 */ 67 */
68 void mergeWith( const QValueList<OTodo>& ); 68 void mergeWith( const QValueList<OTodo>& );
69 69
70 /** 70 /**
71 * delete all already completed items 71 * delete all already completed items
72 */ 72 */
73 void removeAllCompleted(); 73 void removeAllCompleted();
74 74
75signals: 75signals:
76 /** 76 /**
77 * if the OTodoAccess was changed 77 * if the OTodoAccess was changed
78 */ 78 */
79 void signalChanged( const OTodoAccess* ); 79 void signalChanged( const OTodoAccess* );
80private: 80private:
81 /**
82 * add an Alarm to the AlarmServer
83 */
84 void addAlarm( const OTodo& );
85
86 /**
87 * delete an alarm with the uid from
88 * the alarm server
89 */
90 void delAlarm( int uid );
91
92 int m_cat; 81 int m_cat;
93 OTodoAccessBackend* m_todoBackEnd; 82 OTodoAccessBackend* m_todoBackEnd;
94 class OTodoAccessPrivate; 83 class OTodoAccessPrivate;
95 OTodoAccessPrivate* d; 84 OTodoAccessPrivate* d;
96}; 85};
97 86
98#endif 87#endif
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index b2dfe80..21f93a0 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -1,325 +1,354 @@
1#include <errno.h>
2#include <fcntl.h>
3
4#include <sys/mman.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7
8#include <unistd.h>
9
10
1#include <qfile.h> 11#include <qfile.h>
2#include <qvector.h> 12#include <qvector.h>
3 13
4#include <qpe/global.h> 14#include <qpe/global.h>
5#include <qpe/stringutil.h> 15#include <qpe/stringutil.h>
6#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
7 17
8#include <opie/xmltree.h> 18#include <opie/xmltree.h>
9 19
10#include "otodoaccessxml.h" 20#include "otodoaccessxml.h"
11 21
12OTodoAccessXML::OTodoAccessXML( const QString& appName, 22OTodoAccessXML::OTodoAccessXML( const QString& appName,
13 const QString& fileName ) 23 const QString& fileName )
14 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 24 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
15{ 25{
16 if (!fileName.isEmpty() ) 26 if (!fileName.isEmpty() )
17 m_file = fileName; 27 m_file = fileName;
18 else 28 else
19 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 29 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
20} 30}
21OTodoAccessXML::~OTodoAccessXML() { 31OTodoAccessXML::~OTodoAccessXML() {
22 32
23} 33}
24bool OTodoAccessXML::load() { 34bool OTodoAccessXML::load() {
25 m_opened = true; 35 m_opened = true;
26 m_changed = false; 36 m_changed = false;
27 /* initialize dict */ 37 /* initialize dict */
28 /* 38 /*
29 * UPDATE dict if you change anything!!! 39 * UPDATE dict if you change anything!!!
30 */ 40 */
31 QAsciiDict<int> dict(21); 41 QAsciiDict<int> dict(21);
32 dict.setAutoDelete( TRUE ); 42 dict.setAutoDelete( TRUE );
33 dict.insert("Categories" , new int(OTodo::Category) ); 43 dict.insert("Categories" , new int(OTodo::Category) );
34 dict.insert("Uid" , new int(OTodo::Uid) ); 44 dict.insert("Uid" , new int(OTodo::Uid) );
35 dict.insert("HasDate" , new int(OTodo::HasDate) ); 45 dict.insert("HasDate" , new int(OTodo::HasDate) );
36 dict.insert("Completed" , new int(OTodo::Completed) ); 46 dict.insert("Completed" , new int(OTodo::Completed) );
37 dict.insert("Description" , new int(OTodo::Description) ); 47 dict.insert("Description" , new int(OTodo::Description) );
38 dict.insert("Summary" , new int(OTodo::Summary) ); 48 dict.insert("Summary" , new int(OTodo::Summary) );
39 dict.insert("Priority" , new int(OTodo::Priority) ); 49 dict.insert("Priority" , new int(OTodo::Priority) );
40 dict.insert("DateDay" , new int(OTodo::DateDay) ); 50 dict.insert("DateDay" , new int(OTodo::DateDay) );
41 dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 51 dict.insert("DateMonth" , new int(OTodo::DateMonth) );
42 dict.insert("DateYear" , new int(OTodo::DateYear) ); 52 dict.insert("DateYear" , new int(OTodo::DateYear) );
43 dict.insert("Progress" , new int(OTodo::Progress) ); 53 dict.insert("Progress" , new int(OTodo::Progress) );
44 dict.insert("Completed", new int(OTodo::Completed) ); 54 dict.insert("Completed", new int(OTodo::Completed) );
45 dict.insert("CrossReference", new int(OTodo::CrossReference) ); 55 dict.insert("CrossReference", new int(OTodo::CrossReference) );
46 dict.insert("State", new int(OTodo::State) ); 56 dict.insert("State", new int(OTodo::State) );
47 dict.insert("Recurrence", new int(OTodo::Recurrence) ); 57 dict.insert("Recurrence", new int(OTodo::Recurrence) );
48 dict.insert("Alarms", new int(OTodo::Alarms) ); 58 dict.insert("Alarms", new int(OTodo::Alarms) );
49 dict.insert("Reminders", new int(OTodo::Reminders) ); 59 dict.insert("Reminders", new int(OTodo::Reminders) );
50 dict.insert("Notifiers", new int(OTodo::Notifiers) ); 60 dict.insert("Notifiers", new int(OTodo::Notifiers) );
51 dict.insert("Maintainer", new int(OTodo::Maintainer) ); 61 dict.insert("Maintainer", new int(OTodo::Maintainer) );
52 62
53 // here the custom XML parser from TT it's GPL 63 // here the custom XML parser from TT it's GPL
54 // but we want to push OpiePIM... to TT..... 64 // but we want to push OpiePIM... to TT.....
55 QFile f(m_file ); 65 // mmap part from zecke :)
56 if (!f.open(IO_ReadOnly) ) 66 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
67 struct stat attribut;
68 if ( fd < 0 ) return false;
69
70 if ( fstat(fd, &attribut ) == -1 ) {
71 ::close( fd );
57 return false; 72 return false;
73 }
74 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
75 if ( map_addr == ( (caddr_t)-1) ) {
76 ::close(fd );
77 return false;
78 }
79 /* advise the kernel who we want to read it */
80 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
81 /* we do not the file any more */
82 ::close( fd );
58 83
59 QByteArray ba = f.readAll(); 84 char* dt = (char*)map_addr;
60 f.close(); 85 int len = attribut.st_size;
61 char* dt = ba.data();
62 int len = ba.size();
63 int i = 0; 86 int i = 0;
64 char *point; 87 char *point;
65 const char* collectionString = "<Task "; 88 const char* collectionString = "<Task ";
89 int strLen = strlen(collectionString);
66 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { 90 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
67 i = point -dt; 91 i = point -dt;
68 i+= strlen(collectionString); 92 i+= strLen;
93 qWarning("Found a start at %d %d", i, (point-dt) );
94
69 OTodo ev; 95 OTodo ev;
70 m_year = m_month = m_day = 0; 96 m_year = m_month = m_day = 0;
71 97
72 while ( TRUE ) { 98 while ( TRUE ) {
73 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 99 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
74 ++i; 100 ++i;
75 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 101 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
76 break; 102 break;
77 103
78 // we have another attribute, read it. 104 // we have another attribute, read it.
79 int j = i; 105 int j = i;
80 while ( j < len && dt[j] != '=' ) 106 while ( j < len && dt[j] != '=' )
81 ++j; 107 ++j;
82 QCString attr( dt+i, j-i+1); 108 QCString attr( dt+i, j-i+1);
83 109
84 i = ++j; // skip = 110 i = ++j; // skip =
85 111
86 // find the start of quotes 112 // find the start of quotes
87 while ( i < len && dt[i] != '"' ) 113 while ( i < len && dt[i] != '"' )
88 ++i; 114 ++i;
89 j = ++i; 115 j = ++i;
90 116
91 bool haveUtf = FALSE; 117 bool haveUtf = FALSE;
92 bool haveEnt = FALSE; 118 bool haveEnt = FALSE;
93 while ( j < len && dt[j] != '"' ) { 119 while ( j < len && dt[j] != '"' ) {
94 if ( ((unsigned char)dt[j]) > 0x7f ) 120 if ( ((unsigned char)dt[j]) > 0x7f )
95 haveUtf = TRUE; 121 haveUtf = TRUE;
96 if ( dt[j] == '&' ) 122 if ( dt[j] == '&' )
97 haveEnt = TRUE; 123 haveEnt = TRUE;
98 ++j; 124 ++j;
99 } 125 }
100 if ( i == j ) { 126 if ( i == j ) {
101 // empty value 127 // empty value
102 i = j + 1; 128 i = j + 1;
103 continue; 129 continue;
104 } 130 }
105 131
106 QCString value( dt+i, j-i+1 ); 132 QCString value( dt+i, j-i+1 );
107 i = j + 1; 133 i = j + 1;
108 134
109 QString str = (haveUtf ? QString::fromUtf8( value ) 135 QString str = (haveUtf ? QString::fromUtf8( value )
110 : QString::fromLatin1( value ) ); 136 : QString::fromLatin1( value ) );
111 if ( haveEnt ) 137 if ( haveEnt )
112 str = Qtopia::plainString( str ); 138 str = Qtopia::plainString( str );
113 139
114 /* 140 /*
115 * add key + value 141 * add key + value
116 */ 142 */
117 todo( &dict, ev, attr, str ); 143 todo( &dict, ev, attr, str );
118 144
119 } 145 }
120 /* 146 /*
121 * now add it 147 * now add it
122 */ 148 */
149 qWarning("End at %d", i );
123 if (m_events.contains( ev.uid() ) || ev.uid() == 0) { 150 if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
124 ev.setUid( 1 ); 151 ev.setUid( 1 );
125 m_changed = true; 152 m_changed = true;
126 } 153 }
127 if ( ev.hasDueDate() ) { 154 if ( ev.hasDueDate() ) {
128 ev.setDueDate( QDate(m_year, m_month, m_day) ); 155 ev.setDueDate( QDate(m_year, m_month, m_day) );
129 } 156 }
130 m_events.insert(ev.uid(), ev ); 157 m_events.insert(ev.uid(), ev );
131 m_year = m_month = m_day = -1; 158 m_year = m_month = m_day = -1;
132 } 159 }
133 160
161 munmap(map_addr, attribut.st_size );
162
134 qWarning("counts %d records loaded!", m_events.count() ); 163 qWarning("counts %d records loaded!", m_events.count() );
135 return true; 164 return true;
136} 165}
137bool OTodoAccessXML::reload() { 166bool OTodoAccessXML::reload() {
138 return load(); 167 return load();
139} 168}
140bool OTodoAccessXML::save() { 169bool OTodoAccessXML::save() {
141// qWarning("saving"); 170// qWarning("saving");
142 if (!m_opened || !m_changed ) { 171 if (!m_opened || !m_changed ) {
143// qWarning("not saving"); 172// qWarning("not saving");
144 return true; 173 return true;
145 } 174 }
146 QString strNewFile = m_file + ".new"; 175 QString strNewFile = m_file + ".new";
147 QFile f( strNewFile ); 176 QFile f( strNewFile );
148 if (!f.open( IO_WriteOnly|IO_Raw ) ) 177 if (!f.open( IO_WriteOnly|IO_Raw ) )
149 return false; 178 return false;
150 179
151 int written; 180 int written;
152 QString out; 181 QString out;
153 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 182 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
154 183
155 // for all todos 184 // for all todos
156 QMap<int, OTodo>::Iterator it; 185 QMap<int, OTodo>::Iterator it;
157 for (it = m_events.begin(); it != m_events.end(); ++it ) { 186 for (it = m_events.begin(); it != m_events.end(); ++it ) {
158 out+= "<Task " + toString( (*it) ) + " />\n"; 187 out+= "<Task " + toString( (*it) ) + " />\n";
159 QCString cstr = out.utf8(); 188 QCString cstr = out.utf8();
160 written = f.writeBlock( cstr.data(), cstr.length() ); 189 written = f.writeBlock( cstr.data(), cstr.length() );
161 190
162 /* less written then we wanted */ 191 /* less written then we wanted */
163 if ( written != (int)cstr.length() ) { 192 if ( written != (int)cstr.length() ) {
164 f.close(); 193 f.close();
165 QFile::remove( strNewFile ); 194 QFile::remove( strNewFile );
166 return false; 195 return false;
167 } 196 }
168 out = QString::null; 197 out = QString::null;
169 } 198 }
170 199
171 out += "</Tasks>"; 200 out += "</Tasks>";
172 QCString cstr = out.utf8(); 201 QCString cstr = out.utf8();
173 written = f.writeBlock( cstr.data(), cstr.length() ); 202 written = f.writeBlock( cstr.data(), cstr.length() );
174 203
175 if ( written != (int)cstr.length() ) { 204 if ( written != (int)cstr.length() ) {
176 f.close(); 205 f.close();
177 QFile::remove( strNewFile ); 206 QFile::remove( strNewFile );
178 return false; 207 return false;
179 } 208 }
180 /* flush before renaming */ 209 /* flush before renaming */
181 f.close(); 210 f.close();
182 211
183 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 212 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
184// qWarning("error renaming"); 213// qWarning("error renaming");
185 QFile::remove( strNewFile ); 214 QFile::remove( strNewFile );
186 } 215 }
187 216
188 m_changed = false; 217 m_changed = false;
189 return true; 218 return true;
190} 219}
191QArray<int> OTodoAccessXML::allRecords()const { 220QArray<int> OTodoAccessXML::allRecords()const {
192 QArray<int> ids( m_events.count() ); 221 QArray<int> ids( m_events.count() );
193 QMap<int, OTodo>::ConstIterator it; 222 QMap<int, OTodo>::ConstIterator it;
194 int i = 0; 223 int i = 0;
195 224
196 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 225 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
197 ids[i] = it.key(); 226 ids[i] = it.key();
198 i++; 227 i++;
199 } 228 }
200 return ids; 229 return ids;
201} 230}
202QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) { 231QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) {
203 QArray<int> ids(0); 232 QArray<int> ids(0);
204 return ids; 233 return ids;
205} 234}
206OTodo OTodoAccessXML::find( int uid )const { 235OTodo OTodoAccessXML::find( int uid )const {
207 OTodo todo; 236 OTodo todo;
208 todo.setUid( 0 ); // isEmpty() 237 todo.setUid( 0 ); // isEmpty()
209 QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); 238 QMap<int, OTodo>::ConstIterator it = m_events.find( uid );
210 if ( it != m_events.end() ) 239 if ( it != m_events.end() )
211 todo = it.data(); 240 todo = it.data();
212 241
213 return todo; 242 return todo;
214} 243}
215void OTodoAccessXML::clear() { 244void OTodoAccessXML::clear() {
216 if (m_opened ) 245 if (m_opened )
217 m_changed = true; 246 m_changed = true;
218 247
219 m_events.clear(); 248 m_events.clear();
220} 249}
221bool OTodoAccessXML::add( const OTodo& todo ) { 250bool OTodoAccessXML::add( const OTodo& todo ) {
222// qWarning("add"); 251// qWarning("add");
223 m_changed = true; 252 m_changed = true;
224 m_events.insert( todo.uid(), todo ); 253 m_events.insert( todo.uid(), todo );
225 254
226 return true; 255 return true;
227} 256}
228bool OTodoAccessXML::remove( int uid ) { 257bool OTodoAccessXML::remove( int uid ) {
229 m_changed = true; 258 m_changed = true;
230 m_events.remove( uid ); 259 m_events.remove( uid );
231 260
232 return true; 261 return true;
233} 262}
234bool OTodoAccessXML::replace( const OTodo& todo) { 263bool OTodoAccessXML::replace( const OTodo& todo) {
235 m_changed = true; 264 m_changed = true;
236 m_events.replace( todo.uid(), todo ); 265 m_events.replace( todo.uid(), todo );
237 266
238 return true; 267 return true;
239} 268}
240QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, 269QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start,
241 const QDate& end, 270 const QDate& end,
242 bool includeNoDates ) { 271 bool includeNoDates ) {
243 QArray<int> ids( m_events.count() ); 272 QArray<int> ids( m_events.count() );
244 QMap<int, OTodo>::Iterator it; 273 QMap<int, OTodo>::Iterator it;
245 274
246 int i = 0; 275 int i = 0;
247 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 276 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
248 if ( !it.data().hasDueDate() ) { 277 if ( !it.data().hasDueDate() ) {
249 if ( includeNoDates ) { 278 if ( includeNoDates ) {
250 ids[i] = it.key(); 279 ids[i] = it.key();
251 i++; 280 i++;
252 } 281 }
253 }else if ( it.data().dueDate() >= start && 282 }else if ( it.data().dueDate() >= start &&
254 it.data().dueDate() <= end ) { 283 it.data().dueDate() <= end ) {
255 ids[i] = it.key(); 284 ids[i] = it.key();
256 i++; 285 i++;
257 } 286 }
258 } 287 }
259 ids.resize( i ); 288 ids.resize( i );
260 return ids; 289 return ids;
261} 290}
262QArray<int> OTodoAccessXML::overDue() { 291QArray<int> OTodoAccessXML::overDue() {
263 QArray<int> ids( m_events.count() ); 292 QArray<int> ids( m_events.count() );
264 int i = 0; 293 int i = 0;
265 294
266 QMap<int, OTodo>::Iterator it; 295 QMap<int, OTodo>::Iterator it;
267 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 296 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
268 if ( it.data().isOverdue() ) { 297 if ( it.data().isOverdue() ) {
269 ids[i] = it.key(); 298 ids[i] = it.key();
270 i++; 299 i++;
271 } 300 }
272 } 301 }
273 ids.resize( i ); 302 ids.resize( i );
274 return ids; 303 return ids;
275} 304}
276 305
277 306
278/* private */ 307/* private */
279void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, 308void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
280 const QCString& attr, const QString& val) { 309 const QCString& attr, const QString& val) {
281// qWarning("parse to do from XMLElement" ); 310// qWarning("parse to do from XMLElement" );
282 311
283 int *find=0; 312 int *find=0;
284 313
285 find = (*dict)[ attr.data() ]; 314 find = (*dict)[ attr.data() ];
286 if (!find ) { 315 if (!find ) {
287// qWarning("Unknown option" + it.key() ); 316// qWarning("Unknown option" + it.key() );
288 ev.setCustomField( attr, val ); 317 ev.setCustomField( attr, val );
289 return; 318 return;
290 } 319 }
291 320
292 switch( *find ) { 321 switch( *find ) {
293 case OTodo::Uid: 322 case OTodo::Uid:
294 ev.setUid( val.toInt() ); 323 ev.setUid( val.toInt() );
295 break; 324 break;
296 case OTodo::Category: 325 case OTodo::Category:
297 ev.setCategories( ev.idsFromString( val ) ); 326 ev.setCategories( ev.idsFromString( val ) );
298 break; 327 break;
299 case OTodo::HasDate: 328 case OTodo::HasDate:
300 ev.setHasDueDate( val.toInt() ); 329 ev.setHasDueDate( val.toInt() );
301 break; 330 break;
302 case OTodo::Completed: 331 case OTodo::Completed:
303 ev.setCompleted( val.toInt() ); 332 ev.setCompleted( val.toInt() );
304 break; 333 break;
305 case OTodo::Description: 334 case OTodo::Description:
306 ev.setDescription( val ); 335 ev.setDescription( val );
307 break; 336 break;
308 case OTodo::Summary: 337 case OTodo::Summary:
309 ev.setSummary( val ); 338 ev.setSummary( val );
310 break; 339 break;
311 case OTodo::Priority: 340 case OTodo::Priority:
312 ev.setPriority( val.toInt() ); 341 ev.setPriority( val.toInt() );
313 break; 342 break;
314 case OTodo::DateDay: 343 case OTodo::DateDay:
315 m_day = val.toInt(); 344 m_day = val.toInt();
316 break; 345 break;
317 case OTodo::DateMonth: 346 case OTodo::DateMonth:
318 m_month = val.toInt(); 347 m_month = val.toInt();
319 break; 348 break;
320 case OTodo::DateYear: 349 case OTodo::DateYear:
321 m_year = val.toInt(); 350 m_year = val.toInt();
322 break; 351 break;
323 case OTodo::Progress: 352 case OTodo::Progress:
324 ev.setProgress( val.toInt() ); 353 ev.setProgress( val.toInt() );
325 break; 354 break;
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index 4f00bc9..e268f4f 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -1,141 +1,153 @@
1#ifndef OPIE_PIM_ACCESS_BACKEND 1#ifndef OPIE_PIM_ACCESS_BACKEND
2#define OPIE_PIM_ACCESS_BACKEND 2#define OPIE_PIM_ACCESS_BACKEND
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include <opie/otemplatebase.h> 6#include <opie/otemplatebase.h>
7#include <opie/opimrecord.h> 7#include <opie/opimrecord.h>
8 8
9 9
10/** 10/**
11 * OPimAccessBackend is the base class 11 * OPimAccessBackend is the base class
12 * for all private backends 12 * for all private backends
13 * it operates on OPimRecord as the base class 13 * it operates on OPimRecord as the base class
14 * and it's responsible for fast manipulating 14 * and it's responsible for fast manipulating
15 * the resource the implementation takes care 15 * the resource the implementation takes care
16 * of 16 * of
17 */ 17 */
18template <class T = OPimRecord> 18template <class T = OPimRecord>
19class OPimAccessBackend { 19class OPimAccessBackend {
20public: 20public:
21 typedef OTemplateBase<T> Frontend; 21 typedef OTemplateBase<T> Frontend;
22 OPimAccessBackend(); 22
23 /** The access hint from the frontend */
24 OPimAccessBackend(int access = 0);
23 virtual ~OPimAccessBackend(); 25 virtual ~OPimAccessBackend();
24 26
25 /** 27 /**
26 * load the resource 28 * load the resource
27 */ 29 */
28 virtual bool load() = 0; 30 virtual bool load() = 0;
29 31
30 /** 32 /**
31 * reload the resource 33 * reload the resource
32 */ 34 */
33 virtual bool reload() = 0; 35 virtual bool reload() = 0;
34 36
35 /** 37 /**
36 * save the resource and 38 * save the resource and
37 * all it's changes 39 * all it's changes
38 */ 40 */
39 virtual bool save() = 0; 41 virtual bool save() = 0;
40 42
41 /** 43 /**
42 * return an array of 44 * return an array of
43 * all available uids 45 * all available uids
44 */ 46 */
45 virtual QArray<int> allRecords()const = 0; 47 virtual QArray<int> allRecords()const = 0;
46 48
47 /** 49 /**
48 * queryByExample for T with the SortOrder 50 * queryByExample for T with the SortOrder
49 * sort 51 * sort
50 */ 52 */
51 virtual QArray<int> queryByExample( const T& t, int sort ) = 0; 53 virtual QArray<int> queryByExample( const T& t, int sort ) = 0;
52 54
53 /** 55 /**
54 * find the OPimRecord with uid @param uid 56 * find the OPimRecord with uid @param uid
55 * returns T and T.isEmpty() if nothing was found 57 * returns T and T.isEmpty() if nothing was found
56 */ 58 */
57 virtual T find(int uid )const = 0; 59 virtual T find(int uid )const = 0;
58 60
59 virtual T find(int uid, const QArray<int>& items, 61 virtual T find(int uid, const QArray<int>& items,
60 uint current, typename Frontend::CacheDirection )const ; 62 uint current, typename Frontend::CacheDirection )const ;
61 /** 63 /**
62 * clear the back end 64 * clear the back end
63 */ 65 */
64 virtual void clear() = 0; 66 virtual void clear() = 0;
65 67
66 /** 68 /**
67 * add T 69 * add T
68 */ 70 */
69 virtual bool add( const T& t ) = 0; 71 virtual bool add( const T& t ) = 0;
70 72
71 /** 73 /**
72 * remove 74 * remove
73 */ 75 */
74 virtual bool remove( int uid ) = 0; 76 virtual bool remove( int uid ) = 0;
75 77
76 /** 78 /**
77 * replace a record with T.uid() 79 * replace a record with T.uid()
78 */ 80 */
79 virtual bool replace( const T& t ) = 0; 81 virtual bool replace( const T& t ) = 0;
80 82
81 /* 83 /*
82 * setTheFrontEnd!!! 84 * setTheFrontEnd!!!
83 */ 85 */
84 void setFrontend( Frontend* front ); 86 void setFrontend( Frontend* front );
85 87
86 /** 88 /**
87 * set the read ahead count 89 * set the read ahead count
88 */ 90 */
89 void setReadAhead( uint count ); 91 void setReadAhead( uint count );
90protected: 92protected:
93 int access()const;
91 void cache( const T& t )const; 94 void cache( const T& t )const;
92 95
93 /** 96 /**
94 * use a prime number here! 97 * use a prime number here!
95 */ 98 */
96 void setSaneCacheSize( int ); 99 void setSaneCacheSize( int );
97 100
98 uint readAhead()const; 101 uint readAhead()const;
99 102
100private: 103private:
104 class Private;
105 Private* d;
101 Frontend* m_front; 106 Frontend* m_front;
102 uint m_read; 107 uint m_read;
108 int m_acc;
103 109
104}; 110};
105 111
106template <class T> 112template <class T>
107OPimAccessBackend<T>::OPimAccessBackend() { 113OPimAccessBackend<T>::OPimAccessBackend(int acc)
114 : m_acc( acc )
115{
108 m_front = 0l; 116 m_front = 0l;
109} 117}
110template <class T> 118template <class T>
111OPimAccessBackend<T>::~OPimAccessBackend() { 119OPimAccessBackend<T>::~OPimAccessBackend() {
112 120
113} 121}
114template <class T> 122template <class T>
115void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { 123void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
116 m_front = fr; 124 m_front = fr;
117} 125}
118template <class T> 126template <class T>
119void OPimAccessBackend<T>::cache( const T& t )const { 127void OPimAccessBackend<T>::cache( const T& t )const {
120 if (m_front ) 128 if (m_front )
121 m_front->cache( t ); 129 m_front->cache( t );
122} 130}
123template <class T> 131template <class T>
124void OPimAccessBackend<T>::setSaneCacheSize( int size) { 132void OPimAccessBackend<T>::setSaneCacheSize( int size) {
125 if (m_front ) 133 if (m_front )
126 m_front->setSaneCacheSize( size ); 134 m_front->setSaneCacheSize( size );
127} 135}
128template <class T> 136template <class T>
129T OPimAccessBackend<T>::find( int uid, const QArray<int>&, 137T OPimAccessBackend<T>::find( int uid, const QArray<int>&,
130 uint, typename Frontend::CacheDirection )const { 138 uint, typename Frontend::CacheDirection )const {
131 return find( uid ); 139 return find( uid );
132} 140}
133template <class T> 141template <class T>
134void OPimAccessBackend<T>::setReadAhead( uint count ) { 142void OPimAccessBackend<T>::setReadAhead( uint count ) {
135 m_read = count; 143 m_read = count;
136} 144}
137template <class T> 145template <class T>
138uint OPimAccessBackend<T>::readAhead()const { 146uint OPimAccessBackend<T>::readAhead()const {
139 return m_read; 147 return m_read;
140} 148}
149template <class T>
150int OPimAccessBackend<T>::access()const {
151 return m_acc;
152}
141#endif 153#endif
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index b2dfe80..21f93a0 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -1,325 +1,354 @@
1#include <errno.h>
2#include <fcntl.h>
3
4#include <sys/mman.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7
8#include <unistd.h>
9
10
1#include <qfile.h> 11#include <qfile.h>
2#include <qvector.h> 12#include <qvector.h>
3 13
4#include <qpe/global.h> 14#include <qpe/global.h>
5#include <qpe/stringutil.h> 15#include <qpe/stringutil.h>
6#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
7 17
8#include <opie/xmltree.h> 18#include <opie/xmltree.h>
9 19
10#include "otodoaccessxml.h" 20#include "otodoaccessxml.h"
11 21
12OTodoAccessXML::OTodoAccessXML( const QString& appName, 22OTodoAccessXML::OTodoAccessXML( const QString& appName,
13 const QString& fileName ) 23 const QString& fileName )
14 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 24 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
15{ 25{
16 if (!fileName.isEmpty() ) 26 if (!fileName.isEmpty() )
17 m_file = fileName; 27 m_file = fileName;
18 else 28 else
19 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 29 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
20} 30}
21OTodoAccessXML::~OTodoAccessXML() { 31OTodoAccessXML::~OTodoAccessXML() {
22 32
23} 33}
24bool OTodoAccessXML::load() { 34bool OTodoAccessXML::load() {
25 m_opened = true; 35 m_opened = true;
26 m_changed = false; 36 m_changed = false;
27 /* initialize dict */ 37 /* initialize dict */
28 /* 38 /*
29 * UPDATE dict if you change anything!!! 39 * UPDATE dict if you change anything!!!
30 */ 40 */
31 QAsciiDict<int> dict(21); 41 QAsciiDict<int> dict(21);
32 dict.setAutoDelete( TRUE ); 42 dict.setAutoDelete( TRUE );
33 dict.insert("Categories" , new int(OTodo::Category) ); 43 dict.insert("Categories" , new int(OTodo::Category) );
34 dict.insert("Uid" , new int(OTodo::Uid) ); 44 dict.insert("Uid" , new int(OTodo::Uid) );
35 dict.insert("HasDate" , new int(OTodo::HasDate) ); 45 dict.insert("HasDate" , new int(OTodo::HasDate) );
36 dict.insert("Completed" , new int(OTodo::Completed) ); 46 dict.insert("Completed" , new int(OTodo::Completed) );
37 dict.insert("Description" , new int(OTodo::Description) ); 47 dict.insert("Description" , new int(OTodo::Description) );
38 dict.insert("Summary" , new int(OTodo::Summary) ); 48 dict.insert("Summary" , new int(OTodo::Summary) );
39 dict.insert("Priority" , new int(OTodo::Priority) ); 49 dict.insert("Priority" , new int(OTodo::Priority) );
40 dict.insert("DateDay" , new int(OTodo::DateDay) ); 50 dict.insert("DateDay" , new int(OTodo::DateDay) );
41 dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 51 dict.insert("DateMonth" , new int(OTodo::DateMonth) );
42 dict.insert("DateYear" , new int(OTodo::DateYear) ); 52 dict.insert("DateYear" , new int(OTodo::DateYear) );
43 dict.insert("Progress" , new int(OTodo::Progress) ); 53 dict.insert("Progress" , new int(OTodo::Progress) );
44 dict.insert("Completed", new int(OTodo::Completed) ); 54 dict.insert("Completed", new int(OTodo::Completed) );
45 dict.insert("CrossReference", new int(OTodo::CrossReference) ); 55 dict.insert("CrossReference", new int(OTodo::CrossReference) );
46 dict.insert("State", new int(OTodo::State) ); 56 dict.insert("State", new int(OTodo::State) );
47 dict.insert("Recurrence", new int(OTodo::Recurrence) ); 57 dict.insert("Recurrence", new int(OTodo::Recurrence) );
48 dict.insert("Alarms", new int(OTodo::Alarms) ); 58 dict.insert("Alarms", new int(OTodo::Alarms) );
49 dict.insert("Reminders", new int(OTodo::Reminders) ); 59 dict.insert("Reminders", new int(OTodo::Reminders) );
50 dict.insert("Notifiers", new int(OTodo::Notifiers) ); 60 dict.insert("Notifiers", new int(OTodo::Notifiers) );
51 dict.insert("Maintainer", new int(OTodo::Maintainer) ); 61 dict.insert("Maintainer", new int(OTodo::Maintainer) );
52 62
53 // here the custom XML parser from TT it's GPL 63 // here the custom XML parser from TT it's GPL
54 // but we want to push OpiePIM... to TT..... 64 // but we want to push OpiePIM... to TT.....
55 QFile f(m_file ); 65 // mmap part from zecke :)
56 if (!f.open(IO_ReadOnly) ) 66 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
67 struct stat attribut;
68 if ( fd < 0 ) return false;
69
70 if ( fstat(fd, &attribut ) == -1 ) {
71 ::close( fd );
57 return false; 72 return false;
73 }
74 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
75 if ( map_addr == ( (caddr_t)-1) ) {
76 ::close(fd );
77 return false;
78 }
79 /* advise the kernel who we want to read it */
80 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
81 /* we do not the file any more */
82 ::close( fd );
58 83
59 QByteArray ba = f.readAll(); 84 char* dt = (char*)map_addr;
60 f.close(); 85 int len = attribut.st_size;
61 char* dt = ba.data();
62 int len = ba.size();
63 int i = 0; 86 int i = 0;
64 char *point; 87 char *point;
65 const char* collectionString = "<Task "; 88 const char* collectionString = "<Task ";
89 int strLen = strlen(collectionString);
66 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { 90 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
67 i = point -dt; 91 i = point -dt;
68 i+= strlen(collectionString); 92 i+= strLen;
93 qWarning("Found a start at %d %d", i, (point-dt) );
94
69 OTodo ev; 95 OTodo ev;
70 m_year = m_month = m_day = 0; 96 m_year = m_month = m_day = 0;
71 97
72 while ( TRUE ) { 98 while ( TRUE ) {
73 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 99 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
74 ++i; 100 ++i;
75 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 101 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
76 break; 102 break;
77 103
78 // we have another attribute, read it. 104 // we have another attribute, read it.
79 int j = i; 105 int j = i;
80 while ( j < len && dt[j] != '=' ) 106 while ( j < len && dt[j] != '=' )
81 ++j; 107 ++j;
82 QCString attr( dt+i, j-i+1); 108 QCString attr( dt+i, j-i+1);
83 109
84 i = ++j; // skip = 110 i = ++j; // skip =
85 111
86 // find the start of quotes 112 // find the start of quotes
87 while ( i < len && dt[i] != '"' ) 113 while ( i < len && dt[i] != '"' )
88 ++i; 114 ++i;
89 j = ++i; 115 j = ++i;
90 116
91 bool haveUtf = FALSE; 117 bool haveUtf = FALSE;
92 bool haveEnt = FALSE; 118 bool haveEnt = FALSE;
93 while ( j < len && dt[j] != '"' ) { 119 while ( j < len && dt[j] != '"' ) {
94 if ( ((unsigned char)dt[j]) > 0x7f ) 120 if ( ((unsigned char)dt[j]) > 0x7f )
95 haveUtf = TRUE; 121 haveUtf = TRUE;
96 if ( dt[j] == '&' ) 122 if ( dt[j] == '&' )
97 haveEnt = TRUE; 123 haveEnt = TRUE;
98 ++j; 124 ++j;
99 } 125 }
100 if ( i == j ) { 126 if ( i == j ) {
101 // empty value 127 // empty value
102 i = j + 1; 128 i = j + 1;
103 continue; 129 continue;
104 } 130 }
105 131
106 QCString value( dt+i, j-i+1 ); 132 QCString value( dt+i, j-i+1 );
107 i = j + 1; 133 i = j + 1;
108 134
109 QString str = (haveUtf ? QString::fromUtf8( value ) 135 QString str = (haveUtf ? QString::fromUtf8( value )
110 : QString::fromLatin1( value ) ); 136 : QString::fromLatin1( value ) );
111 if ( haveEnt ) 137 if ( haveEnt )
112 str = Qtopia::plainString( str ); 138 str = Qtopia::plainString( str );
113 139
114 /* 140 /*
115 * add key + value 141 * add key + value
116 */ 142 */
117 todo( &dict, ev, attr, str ); 143 todo( &dict, ev, attr, str );
118 144
119 } 145 }
120 /* 146 /*
121 * now add it 147 * now add it
122 */ 148 */
149 qWarning("End at %d", i );
123 if (m_events.contains( ev.uid() ) || ev.uid() == 0) { 150 if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
124 ev.setUid( 1 ); 151 ev.setUid( 1 );
125 m_changed = true; 152 m_changed = true;
126 } 153 }
127 if ( ev.hasDueDate() ) { 154 if ( ev.hasDueDate() ) {
128 ev.setDueDate( QDate(m_year, m_month, m_day) ); 155 ev.setDueDate( QDate(m_year, m_month, m_day) );
129 } 156 }
130 m_events.insert(ev.uid(), ev ); 157 m_events.insert(ev.uid(), ev );
131 m_year = m_month = m_day = -1; 158 m_year = m_month = m_day = -1;
132 } 159 }
133 160
161 munmap(map_addr, attribut.st_size );
162
134 qWarning("counts %d records loaded!", m_events.count() ); 163 qWarning("counts %d records loaded!", m_events.count() );
135 return true; 164 return true;
136} 165}
137bool OTodoAccessXML::reload() { 166bool OTodoAccessXML::reload() {
138 return load(); 167 return load();
139} 168}
140bool OTodoAccessXML::save() { 169bool OTodoAccessXML::save() {
141// qWarning("saving"); 170// qWarning("saving");
142 if (!m_opened || !m_changed ) { 171 if (!m_opened || !m_changed ) {
143// qWarning("not saving"); 172// qWarning("not saving");
144 return true; 173 return true;
145 } 174 }
146 QString strNewFile = m_file + ".new"; 175 QString strNewFile = m_file + ".new";
147 QFile f( strNewFile ); 176 QFile f( strNewFile );
148 if (!f.open( IO_WriteOnly|IO_Raw ) ) 177 if (!f.open( IO_WriteOnly|IO_Raw ) )
149 return false; 178 return false;
150 179
151 int written; 180 int written;
152 QString out; 181 QString out;
153 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 182 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
154 183
155 // for all todos 184 // for all todos
156 QMap<int, OTodo>::Iterator it; 185 QMap<int, OTodo>::Iterator it;
157 for (it = m_events.begin(); it != m_events.end(); ++it ) { 186 for (it = m_events.begin(); it != m_events.end(); ++it ) {
158 out+= "<Task " + toString( (*it) ) + " />\n"; 187 out+= "<Task " + toString( (*it) ) + " />\n";
159 QCString cstr = out.utf8(); 188 QCString cstr = out.utf8();
160 written = f.writeBlock( cstr.data(), cstr.length() ); 189 written = f.writeBlock( cstr.data(), cstr.length() );
161 190
162 /* less written then we wanted */ 191 /* less written then we wanted */
163 if ( written != (int)cstr.length() ) { 192 if ( written != (int)cstr.length() ) {
164 f.close(); 193 f.close();
165 QFile::remove( strNewFile ); 194 QFile::remove( strNewFile );
166 return false; 195 return false;
167 } 196 }
168 out = QString::null; 197 out = QString::null;
169 } 198 }
170 199
171 out += "</Tasks>"; 200 out += "</Tasks>";
172 QCString cstr = out.utf8(); 201 QCString cstr = out.utf8();
173 written = f.writeBlock( cstr.data(), cstr.length() ); 202 written = f.writeBlock( cstr.data(), cstr.length() );
174 203
175 if ( written != (int)cstr.length() ) { 204 if ( written != (int)cstr.length() ) {
176 f.close(); 205 f.close();
177 QFile::remove( strNewFile ); 206 QFile::remove( strNewFile );
178 return false; 207 return false;
179 } 208 }
180 /* flush before renaming */ 209 /* flush before renaming */
181 f.close(); 210 f.close();
182 211
183 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 212 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
184// qWarning("error renaming"); 213// qWarning("error renaming");
185 QFile::remove( strNewFile ); 214 QFile::remove( strNewFile );
186 } 215 }
187 216
188 m_changed = false; 217 m_changed = false;
189 return true; 218 return true;
190} 219}
191QArray<int> OTodoAccessXML::allRecords()const { 220QArray<int> OTodoAccessXML::allRecords()const {
192 QArray<int> ids( m_events.count() ); 221 QArray<int> ids( m_events.count() );
193 QMap<int, OTodo>::ConstIterator it; 222 QMap<int, OTodo>::ConstIterator it;
194 int i = 0; 223 int i = 0;
195 224
196 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 225 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
197 ids[i] = it.key(); 226 ids[i] = it.key();
198 i++; 227 i++;
199 } 228 }
200 return ids; 229 return ids;
201} 230}
202QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) { 231QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) {
203 QArray<int> ids(0); 232 QArray<int> ids(0);
204 return ids; 233 return ids;
205} 234}
206OTodo OTodoAccessXML::find( int uid )const { 235OTodo OTodoAccessXML::find( int uid )const {
207 OTodo todo; 236 OTodo todo;
208 todo.setUid( 0 ); // isEmpty() 237 todo.setUid( 0 ); // isEmpty()
209 QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); 238 QMap<int, OTodo>::ConstIterator it = m_events.find( uid );
210 if ( it != m_events.end() ) 239 if ( it != m_events.end() )
211 todo = it.data(); 240 todo = it.data();
212 241
213 return todo; 242 return todo;
214} 243}
215void OTodoAccessXML::clear() { 244void OTodoAccessXML::clear() {
216 if (m_opened ) 245 if (m_opened )
217 m_changed = true; 246 m_changed = true;
218 247
219 m_events.clear(); 248 m_events.clear();
220} 249}
221bool OTodoAccessXML::add( const OTodo& todo ) { 250bool OTodoAccessXML::add( const OTodo& todo ) {
222// qWarning("add"); 251// qWarning("add");
223 m_changed = true; 252 m_changed = true;
224 m_events.insert( todo.uid(), todo ); 253 m_events.insert( todo.uid(), todo );
225 254
226 return true; 255 return true;
227} 256}
228bool OTodoAccessXML::remove( int uid ) { 257bool OTodoAccessXML::remove( int uid ) {
229 m_changed = true; 258 m_changed = true;
230 m_events.remove( uid ); 259 m_events.remove( uid );
231 260
232 return true; 261 return true;
233} 262}
234bool OTodoAccessXML::replace( const OTodo& todo) { 263bool OTodoAccessXML::replace( const OTodo& todo) {
235 m_changed = true; 264 m_changed = true;
236 m_events.replace( todo.uid(), todo ); 265 m_events.replace( todo.uid(), todo );
237 266
238 return true; 267 return true;
239} 268}
240QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, 269QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start,
241 const QDate& end, 270 const QDate& end,
242 bool includeNoDates ) { 271 bool includeNoDates ) {
243 QArray<int> ids( m_events.count() ); 272 QArray<int> ids( m_events.count() );
244 QMap<int, OTodo>::Iterator it; 273 QMap<int, OTodo>::Iterator it;
245 274
246 int i = 0; 275 int i = 0;
247 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 276 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
248 if ( !it.data().hasDueDate() ) { 277 if ( !it.data().hasDueDate() ) {
249 if ( includeNoDates ) { 278 if ( includeNoDates ) {
250 ids[i] = it.key(); 279 ids[i] = it.key();
251 i++; 280 i++;
252 } 281 }
253 }else if ( it.data().dueDate() >= start && 282 }else if ( it.data().dueDate() >= start &&
254 it.data().dueDate() <= end ) { 283 it.data().dueDate() <= end ) {
255 ids[i] = it.key(); 284 ids[i] = it.key();
256 i++; 285 i++;
257 } 286 }
258 } 287 }
259 ids.resize( i ); 288 ids.resize( i );
260 return ids; 289 return ids;
261} 290}
262QArray<int> OTodoAccessXML::overDue() { 291QArray<int> OTodoAccessXML::overDue() {
263 QArray<int> ids( m_events.count() ); 292 QArray<int> ids( m_events.count() );
264 int i = 0; 293 int i = 0;
265 294
266 QMap<int, OTodo>::Iterator it; 295 QMap<int, OTodo>::Iterator it;
267 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 296 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
268 if ( it.data().isOverdue() ) { 297 if ( it.data().isOverdue() ) {
269 ids[i] = it.key(); 298 ids[i] = it.key();
270 i++; 299 i++;
271 } 300 }
272 } 301 }
273 ids.resize( i ); 302 ids.resize( i );
274 return ids; 303 return ids;
275} 304}
276 305
277 306
278/* private */ 307/* private */
279void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, 308void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
280 const QCString& attr, const QString& val) { 309 const QCString& attr, const QString& val) {
281// qWarning("parse to do from XMLElement" ); 310// qWarning("parse to do from XMLElement" );
282 311
283 int *find=0; 312 int *find=0;
284 313
285 find = (*dict)[ attr.data() ]; 314 find = (*dict)[ attr.data() ];
286 if (!find ) { 315 if (!find ) {
287// qWarning("Unknown option" + it.key() ); 316// qWarning("Unknown option" + it.key() );
288 ev.setCustomField( attr, val ); 317 ev.setCustomField( attr, val );
289 return; 318 return;
290 } 319 }
291 320
292 switch( *find ) { 321 switch( *find ) {
293 case OTodo::Uid: 322 case OTodo::Uid:
294 ev.setUid( val.toInt() ); 323 ev.setUid( val.toInt() );
295 break; 324 break;
296 case OTodo::Category: 325 case OTodo::Category:
297 ev.setCategories( ev.idsFromString( val ) ); 326 ev.setCategories( ev.idsFromString( val ) );
298 break; 327 break;
299 case OTodo::HasDate: 328 case OTodo::HasDate:
300 ev.setHasDueDate( val.toInt() ); 329 ev.setHasDueDate( val.toInt() );
301 break; 330 break;
302 case OTodo::Completed: 331 case OTodo::Completed:
303 ev.setCompleted( val.toInt() ); 332 ev.setCompleted( val.toInt() );
304 break; 333 break;
305 case OTodo::Description: 334 case OTodo::Description:
306 ev.setDescription( val ); 335 ev.setDescription( val );
307 break; 336 break;
308 case OTodo::Summary: 337 case OTodo::Summary:
309 ev.setSummary( val ); 338 ev.setSummary( val );
310 break; 339 break;
311 case OTodo::Priority: 340 case OTodo::Priority:
312 ev.setPriority( val.toInt() ); 341 ev.setPriority( val.toInt() );
313 break; 342 break;
314 case OTodo::DateDay: 343 case OTodo::DateDay:
315 m_day = val.toInt(); 344 m_day = val.toInt();
316 break; 345 break;
317 case OTodo::DateMonth: 346 case OTodo::DateMonth:
318 m_month = val.toInt(); 347 m_month = val.toInt();
319 break; 348 break;
320 case OTodo::DateYear: 349 case OTodo::DateYear:
321 m_year = val.toInt(); 350 m_year = val.toInt();
322 break; 351 break;
323 case OTodo::Progress: 352 case OTodo::Progress:
324 ev.setProgress( val.toInt() ); 353 ev.setProgress( val.toInt() );
325 break; 354 break;
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 8cf81c8..259e2c1 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,269 +1,286 @@
1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
2#define OPIE_PIM_ACCESS_TEMPLATE_H 2#define OPIE_PIM_ACCESS_TEMPLATE_H
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include <opie/opimrecord.h> 6#include <opie/opimrecord.h>
7#include <opie/opimaccessbackend.h> 7#include <opie/opimaccessbackend.h>
8#include <opie/orecordlist.h> 8#include <opie/orecordlist.h>
9 9
10#include "opimcache.h" 10#include "opimcache.h"
11#include "otemplatebase.h" 11#include "otemplatebase.h"
12 12
13/** 13/**
14 * Thats the frontend to our OPIE PIM 14 * Thats the frontend to our OPIE PIM
15 * Library. Either you want to use it's 15 * Library. Either you want to use it's
16 * interface or you want to implement 16 * interface or you want to implement
17 * your own Access lib 17 * your own Access lib
18 * Just create a OPimRecord and inherit from 18 * Just create a OPimRecord and inherit from
19 * the plugins 19 * the plugins
20 */ 20 */
21 21
22template <class T = OPimRecord > 22template <class T = OPimRecord >
23class OPimAccessTemplate : public OTemplateBase<T> { 23class OPimAccessTemplate : public OTemplateBase<T> {
24public: 24public:
25 enum Access {
26 Random = 0,
27 SortedAccess
28 };
25 typedef ORecordList<T> List; 29 typedef ORecordList<T> List;
26 typedef OPimAccessBackend<T> BackEnd; 30 typedef OPimAccessBackend<T> BackEnd;
27 typedef OPimCache<T> Cache; 31 typedef OPimCache<T> Cache;
28 32
29 /** 33 /**
30 * c'tor BackEnd 34 * c'tor BackEnd
35 * enum Access a small hint on how to handle the backend
31 */ 36 */
32 OPimAccessTemplate( BackEnd* end); 37 OPimAccessTemplate( BackEnd* end);
38
33 virtual ~OPimAccessTemplate(); 39 virtual ~OPimAccessTemplate();
34 40
35 /** 41 /**
36 * load from the backend 42 * load from the backend
37 */ 43 */
38 virtual bool load(); 44 bool load();
39 45
40 /** Reload database. 46 /** Reload database.
41 * You should execute this function if the external database 47 * You should execute this function if the external database
42 * was changed. 48 * was changed.
43 * This function will load the external database and afterwards 49 * This function will load the external database and afterwards
44 * rejoin the local changes. Therefore the local database will be set consistent. 50 * rejoin the local changes. Therefore the local database will be set consistent.
45 */ 51 */
46 virtual bool reload(); 52 virtual bool reload();
47 53
48 /** Save contacts database. 54 /** Save contacts database.
49 * Save is more a "commit". After calling this function, all changes are public available. 55 * Save is more a "commit". After calling this function, all changes are public available.
50 * @return true if successful 56 * @return true if successful
51 */ 57 */
52 virtual bool save(); 58 bool save();
53 59
54 /** 60 /**
55 * if the resource was changed externally 61 * if the resource was changed externally
56 * You should use the signal handling instead of polling possible changes ! 62 * You should use the signal handling instead of polling possible changes !
57 * zecke: Do you implement a signal for otodoaccess ? 63 * zecke: Do you implement a signal for otodoaccess ?
58 */ 64 */
59 bool wasChangedExternally()const; 65 bool wasChangedExternally()const;
60 66
61 /** 67 /**
62 * return a List of records 68 * return a List of records
63 * you can iterate over them 69 * you can iterate over them
64 */ 70 */
65 virtual List allRecords()const; 71 virtual List allRecords()const;
66 72
67 /** 73 /**
68 * queryByExample. 74 * queryByExample.
69 * @see otodoaccess, ocontactaccess 75 * @see otodoaccess, ocontactaccess
70 */ 76 */
71 virtual List queryByExample( const T& t, int querySettings ); 77 virtual List queryByExample( const T& t, int querySettings );
72 78
73 /** 79 /**
74 * find the OPimRecord uid 80 * find the OPimRecord uid
75 */ 81 */
76 virtual T find( int uid )const; 82 virtual T find( int uid )const;
77 83
78 /** 84 /**
79 * read ahead cache find method ;) 85 * read ahead cache find method ;)
80 */ 86 */
81 virtual T find( int uid, const QArray<int>&, 87 virtual T find( int uid, const QArray<int>&,
82 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 88 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
83 89
84 /* invalidate cache here */ 90 /* invalidate cache here */
85 /** 91 /**
86 * clears the backend and invalidates the backend 92 * clears the backend and invalidates the backend
87 */ 93 */
88 virtual void clear() ; 94 void clear() ;
89 95
90 /** 96 /**
91 * add T to the backend 97 * add T to the backend
92 * @param t The item to add. 98 * @param t The item to add.
93 * @return <i>true</i> if added successfully. 99 * @return <i>true</i> if added successfully.
94 */ 100 */
95 virtual bool add( const T& t ) ; 101 virtual bool add( const T& t ) ;
96 bool add( const OPimRecord& ); 102 bool add( const OPimRecord& );
97 103
98 /* only the uid matters */ 104 /* only the uid matters */
99 /** 105 /**
100 * remove T from the backend 106 * remove T from the backend
101 * @param t The item to remove 107 * @param t The item to remove
102 * @return <i>true</i> if successful. 108 * @return <i>true</i> if successful.
103 */ 109 */
104 virtual bool remove( const T& t ); 110 virtual bool remove( const T& t );
105 111
106 /** 112 /**
107 * remove the OPimRecord with uid 113 * remove the OPimRecord with uid
108 * @param uid The ID of the item to remove 114 * @param uid The ID of the item to remove
109 * @return <i>true</i> if successful. 115 * @return <i>true</i> if successful.
110 */ 116 */
111 virtual bool remove( int uid ); 117 bool remove( int uid );
118 bool remove( const OPimRecord& );
112 119
113 /** 120 /**
114 * replace T from backend 121 * replace T from backend
115 * @param t The item to replace 122 * @param t The item to replace
116 * @return <i>true</i> if successful. 123 * @return <i>true</i> if successful.
117 */ 124 */
118 virtual bool replace( const T& t) ; 125 virtual bool replace( const T& t) ;
119 126
120 void setReadAhead( uint count ); 127 void setReadAhead( uint count );
121 /** 128 /**
122 * @internal 129 * @internal
123 */ 130 */
124 void cache( const T& )const; 131 void cache( const T& )const;
125 void setSaneCacheSize( int ); 132 void setSaneCacheSize( int );
133
134 QArray<int> records()const;
126protected: 135protected:
127 /** 136 /**
128 * invalidate the cache 137 * invalidate the cache
129 */ 138 */
130 void invalidateCache(); 139 void invalidateCache();
131 140
132 void setBackEnd( BackEnd* end ); 141 void setBackEnd( BackEnd* end );
133 /** 142 /**
134 * returns the backend 143 * returns the backend
135 */ 144 */
136 BackEnd* backEnd(); 145 BackEnd* backEnd();
137 BackEnd* m_backEnd; 146 BackEnd* m_backEnd;
138 Cache m_cache; 147 Cache m_cache;
139 148
140}; 149};
141 150
142template <class T> 151template <class T>
143OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 152OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
144 : OTemplateBase<T>(), m_backEnd( end ) 153 : OTemplateBase<T>(), m_backEnd( end )
145{ 154{
146 if (end ) 155 if (end )
147 end->setFrontend( this ); 156 end->setFrontend( this );
148} 157}
149template <class T> 158template <class T>
150OPimAccessTemplate<T>::~OPimAccessTemplate() { 159OPimAccessTemplate<T>::~OPimAccessTemplate() {
151 qWarning("~OPimAccessTemplate<T>"); 160 qWarning("~OPimAccessTemplate<T>");
152 delete m_backEnd; 161 delete m_backEnd;
153} 162}
154template <class T> 163template <class T>
155bool OPimAccessTemplate<T>::load() { 164bool OPimAccessTemplate<T>::load() {
156 invalidateCache(); 165 invalidateCache();
157 return m_backEnd->load(); 166 return m_backEnd->load();
158} 167}
159template <class T> 168template <class T>
160bool OPimAccessTemplate<T>::reload() { 169bool OPimAccessTemplate<T>::reload() {
161 invalidateCache(); // zecke: I think this should be added (se) 170 invalidateCache(); // zecke: I think this should be added (se)
162 return m_backEnd->reload(); 171 return m_backEnd->reload();
163} 172}
164template <class T> 173template <class T>
165bool OPimAccessTemplate<T>::save() { 174bool OPimAccessTemplate<T>::save() {
166 return m_backEnd->save(); 175 return m_backEnd->save();
167} 176}
168template <class T> 177template <class T>
169typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 178typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
170 QArray<int> ints = m_backEnd->allRecords(); 179 QArray<int> ints = m_backEnd->allRecords();
171 List lis(ints, this ); 180 List lis(ints, this );
172 return lis; 181 return lis;
173} 182}
174template <class T> 183template <class T>
184QArray<int> OPimAccessTemplate<T>::records()const {
185 return m_backEnd->allRecords();
186}
187template <class T>
175typename OPimAccessTemplate<T>::List 188typename OPimAccessTemplate<T>::List
176OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { 189OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) {
177 QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); 190 QArray<int> ints = m_backEnd->queryByExample( t, sortOrder );
178 191
179 List lis(ints, this ); 192 List lis(ints, this );
180 return lis; 193 return lis;
181} 194}
182template <class T> 195template <class T>
183T OPimAccessTemplate<T>::find( int uid ) const{ 196T OPimAccessTemplate<T>::find( int uid ) const{
184 T t = m_backEnd->find( uid ); 197 T t = m_backEnd->find( uid );
185 cache( t ); 198 cache( t );
186 return t; 199 return t;
187} 200}
188template <class T> 201template <class T>
189T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 202T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
190 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 203 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
191 /* 204 /*
192 * better do T.isEmpty() 205 * better do T.isEmpty()
193 * after a find this way we would 206 * after a find this way we would
194 * avoid two finds in QCache... 207 * avoid two finds in QCache...
195 */ 208 */
196 // qWarning("find it now %d", uid ); 209 // qWarning("find it now %d", uid );
197 if (m_cache.contains( uid ) ) { 210 if (m_cache.contains( uid ) ) {
198 return m_cache.find( uid ); 211 return m_cache.find( uid );
199 } 212 }
200 213
201 T t = m_backEnd->find( uid, ar, current, dir ); 214 T t = m_backEnd->find( uid, ar, current, dir );
202 cache( t ); 215 cache( t );
203 return t; 216 return t;
204} 217}
205template <class T> 218template <class T>
206void OPimAccessTemplate<T>::clear() { 219void OPimAccessTemplate<T>::clear() {
207 invalidateCache(); 220 invalidateCache();
208 m_backEnd->clear(); 221 m_backEnd->clear();
209} 222}
210template <class T> 223template <class T>
211bool OPimAccessTemplate<T>::add( const T& t ) { 224bool OPimAccessTemplate<T>::add( const T& t ) {
212 cache( t ); 225 cache( t );
213 return m_backEnd->add( t ); 226 return m_backEnd->add( t );
214} 227}
215template <class T> 228template <class T>
216bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 229bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
217 /* same type */ 230 /* same type */
218 if ( rec.rtti() == T::rtti() ) { 231 if ( rec.rtti() == T::rtti() ) {
219 const T &t = static_cast<const T&>(rec); 232 const T &t = static_cast<const T&>(rec);
220 return add(t); 233 return add(t);
221 } 234 }
222 return false; 235 return false;
223} 236}
224template <class T> 237template <class T>
225bool OPimAccessTemplate<T>::remove( const T& t ) { 238bool OPimAccessTemplate<T>::remove( const T& t ) {
226 return remove( t.uid() ); 239 return remove( t.uid() );
227} 240}
228template <class T> 241template <class T>
229bool OPimAccessTemplate<T>::remove( int uid ) { 242bool OPimAccessTemplate<T>::remove( int uid ) {
230 m_cache.remove( uid ); 243 m_cache.remove( uid );
231 return m_backEnd->remove( uid ); 244 return m_backEnd->remove( uid );
232} 245}
233template <class T> 246template <class T>
247bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
248 return remove( rec.uid() );
249}
250template <class T>
234bool OPimAccessTemplate<T>::replace( const T& t ) { 251bool OPimAccessTemplate<T>::replace( const T& t ) {
235 m_cache.replace( t ); 252 m_cache.replace( t );
236 return m_backEnd->replace( t ); 253 return m_backEnd->replace( t );
237} 254}
238template <class T> 255template <class T>
239void OPimAccessTemplate<T>::invalidateCache() { 256void OPimAccessTemplate<T>::invalidateCache() {
240 m_cache.invalidate(); 257 m_cache.invalidate();
241} 258}
242template <class T> 259template <class T>
243typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 260typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
244 return m_backEnd; 261 return m_backEnd;
245} 262}
246template <class T> 263template <class T>
247bool OPimAccessTemplate<T>::wasChangedExternally()const { 264bool OPimAccessTemplate<T>::wasChangedExternally()const {
248 return false; 265 return false;
249} 266}
250template <class T> 267template <class T>
251void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 268void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
252 m_backEnd = end; 269 m_backEnd = end;
253 if (m_backEnd ) 270 if (m_backEnd )
254 m_backEnd->setFrontend( this ); 271 m_backEnd->setFrontend( this );
255} 272}
256template <class T> 273template <class T>
257void OPimAccessTemplate<T>::cache( const T& t ) const{ 274void OPimAccessTemplate<T>::cache( const T& t ) const{
258 /* hacky we need to work around the const*/ 275 /* hacky we need to work around the const*/
259 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 276 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
260} 277}
261template <class T> 278template <class T>
262void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 279void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
263 m_cache.setSize( size ); 280 m_cache.setSize( size );
264} 281}
265template <class T> 282template <class T>
266void OPimAccessTemplate<T>::setReadAhead( uint count ) { 283void OPimAccessTemplate<T>::setReadAhead( uint count ) {
267 m_backEnd->setReadAhead( count ); 284 m_backEnd->setReadAhead( count );
268} 285}
269#endif 286#endif
diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h
index 839550c..73414e5 100644
--- a/libopie2/opiepim/core/opimcache.h
+++ b/libopie2/opiepim/core/opimcache.h
@@ -1,119 +1,125 @@
1#ifndef OPIE_PIM_CACHE_H 1#ifndef OPIE_PIM_CACHE_H
2#define OPIE_PIM_CACHE_H 2#define OPIE_PIM_CACHE_H
3 3
4#include <qintcache.h> 4#include <qintcache.h>
5 5
6#include "opimrecord.h" 6#include "opimrecord.h"
7 7
8template <class T = OPimRecord> 8template <class T = OPimRecord>
9class OPimCacheItem { 9class OPimCacheItem {
10public: 10public:
11 OPimCacheItem( const T& t = T() ); 11 OPimCacheItem( const T& t = T() );
12 OPimCacheItem( const OPimCacheItem& );
12 ~OPimCacheItem(); 13 ~OPimCacheItem();
13 14
15 OPimCacheItem &operator=( const OPimCacheItem& );
16
14 T record()const; 17 T record()const;
15 void setRecord( const T& ); 18 void setRecord( const T& );
16private: 19private:
17 T m_t; 20 T m_t;
18}; 21};
19 22
20/** 23/**
21 * OPimCache for caching the items 24 * OPimCache for caching the items
22 * We support adding, removing 25 * We support adding, removing
23 * and finding 26 * and finding
24 */ 27 */
25template <class T = OPimRecord> 28template <class T = OPimRecord>
26class OPimCache { 29class OPimCache {
27public: 30public:
28 typedef OPimCacheItem<T> Item; 31 typedef OPimCacheItem<T> Item;
29 OPimCache(); 32 OPimCache();
33 OPimCache( const OPimCache& );
30 ~OPimCache(); 34 ~OPimCache();
31 35
36 OPimCache &operator=( const OPimCache& );
37
32 bool contains(int uid)const; 38 bool contains(int uid)const;
33 void invalidate(); 39 void invalidate();
34 void setSize( int size ); 40 void setSize( int size );
35 41
36 T find(int uid )const; 42 T find(int uid )const;
37 void add( const T& ); 43 void add( const T& );
38 void remove( int uid ); 44 void remove( int uid );
39 void replace( const T& ); 45 void replace( const T& );
40 46
41private: 47private:
42 QIntCache<Item> m_cache; 48 QIntCache<Item> m_cache;
43}; 49};
44 50
45// Implementation 51// Implementation
46template <class T> 52template <class T>
47OPimCacheItem<T>::OPimCacheItem( const T& t ) 53OPimCacheItem<T>::OPimCacheItem( const T& t )
48 : m_t(t) { 54 : m_t(t) {
49} 55}
50template <class T> 56template <class T>
51OPimCacheItem<T>::~OPimCacheItem() { 57OPimCacheItem<T>::~OPimCacheItem() {
52 58
53} 59}
54template <class T> 60template <class T>
55T OPimCacheItem<T>::record()const { 61T OPimCacheItem<T>::record()const {
56 return m_t; 62 return m_t;
57} 63}
58template <class T> 64template <class T>
59void OPimCacheItem<T>::setRecord( const T& t ) { 65void OPimCacheItem<T>::setRecord( const T& t ) {
60 m_t = t; 66 m_t = t;
61} 67}
62// Cache 68// Cache
63template <class T> 69template <class T>
64OPimCache<T>::OPimCache() 70OPimCache<T>::OPimCache()
65 : m_cache(100, 53 ) 71 : m_cache(100, 53 )
66{ 72{
67 m_cache.setAutoDelete( TRUE ); 73 m_cache.setAutoDelete( TRUE );
68} 74}
69template <class T> 75template <class T>
70OPimCache<T>::~OPimCache() { 76OPimCache<T>::~OPimCache() {
71 77
72} 78}
73template <class T> 79template <class T>
74bool OPimCache<T>::contains(int uid )const { 80bool OPimCache<T>::contains(int uid )const {
75 Item* it = m_cache.find( uid, FALSE ); 81 Item* it = m_cache.find( uid, FALSE );
76 if (!it) 82 if (!it)
77 return false; 83 return false;
78 return true; 84 return true;
79} 85}
80template <class T> 86template <class T>
81void OPimCache<T>::invalidate() { 87void OPimCache<T>::invalidate() {
82 m_cache.clear(); 88 m_cache.clear();
83} 89}
84template <class T> 90template <class T>
85void OPimCache<T>::setSize( int size ) { 91void OPimCache<T>::setSize( int size ) {
86 m_cache.setMaxCost( size ); 92 m_cache.setMaxCost( size );
87} 93}
88template <class T> 94template <class T>
89T OPimCache<T>::find(int uid )const { 95T OPimCache<T>::find(int uid )const {
90 Item *it = m_cache.find( uid ); 96 Item *it = m_cache.find( uid );
91 if (it) 97 if (it)
92 return it->record(); 98 return it->record();
93 return T(); 99 return T();
94} 100}
95template <class T> 101template <class T>
96void OPimCache<T>::add( const T& t ) { 102void OPimCache<T>::add( const T& t ) {
97 Item* it = 0l; 103 Item* it = 0l;
98 it = m_cache.find(t.uid(), FALSE ); 104 it = m_cache.find(t.uid(), FALSE );
99 105
100 if (it ) 106 if (it )
101 it->setRecord( t ); 107 it->setRecord( t );
102 108
103 it = new Item( t ); 109 it = new Item( t );
104 if (!m_cache.insert( t.uid(), it ) ) 110 if (!m_cache.insert( t.uid(), it ) )
105 delete it; 111 delete it;
106} 112}
107template <class T> 113template <class T>
108void OPimCache<T>::remove( int uid ) { 114void OPimCache<T>::remove( int uid ) {
109 m_cache.remove( uid ); 115 m_cache.remove( uid );
110} 116}
111template <class T> 117template <class T>
112void OPimCache<T>::replace( const T& t) { 118void OPimCache<T>::replace( const T& t) {
113 Item *it = m_cache.find( t.uid() ); 119 Item *it = m_cache.find( t.uid() );
114 if ( it ) { 120 if ( it ) {
115 it->setRecord( t ); 121 it->setRecord( t );
116 } 122 }
117} 123}
118 124
119#endif 125#endif
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index 49b5bf9..ac0f4a9 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -1,84 +1,166 @@
1#include <qarray.h>
2
1#include <qpe/categories.h> 3#include <qpe/categories.h>
2#include <qpe/categoryselect.h> 4#include <qpe/categoryselect.h>
3 5
4#include "opimrecord.h" 6#include "opimrecord.h"
5 7
6Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 8Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
7 9
8 10
9OPimRecord::OPimRecord( int uid ) 11OPimRecord::OPimRecord( int uid )
10 : Qtopia::Record() { 12 : Qtopia::Record() {
11 13
12 setUid( uid ); 14 setUid( uid );
13} 15}
14OPimRecord::~OPimRecord() { 16OPimRecord::~OPimRecord() {
15} 17}
16OPimRecord::OPimRecord( const OPimRecord& rec ) 18OPimRecord::OPimRecord( const OPimRecord& rec )
17 : Qtopia::Record( rec ) 19 : Qtopia::Record( rec )
18{ 20{
19 (*this) = rec; 21 (*this) = rec;
20} 22}
21 23
22OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { 24OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
23 Qtopia::Record::operator=( rec ); 25 Qtopia::Record::operator=( rec );
24 m_xrefman = rec.m_xrefman; 26 m_xrefman = rec.m_xrefman;
25 27
26 return *this; 28 return *this;
27} 29}
28/* 30/*
29 * category names 31 * category names
30 */ 32 */
31QStringList OPimRecord::categoryNames()const { 33QStringList OPimRecord::categoryNames()const {
32 QStringList list; 34 QStringList list;
33 QArray<int> cats = categories(); 35 QArray<int> cats = categories();
34 Categories catDB; 36 Categories catDB;
35 catDB.load( categoryFileName() ); 37 catDB.load( categoryFileName() );
36 38
37 for (uint i = 0; i < cats.count(); i++ ) { 39 for (uint i = 0; i < cats.count(); i++ ) {
38 list << catDB.label("Todo List", cats[i] ); 40 list << catDB.label("Todo List", cats[i] );
39 } 41 }
40 42
41 return list; 43 return list;
42} 44}
43void OPimRecord::setCategoryNames( const QStringList& ) { 45void OPimRecord::setCategoryNames( const QStringList& ) {
44 46
45} 47}
46void OPimRecord::addCategoryName( const QString& ) { 48void OPimRecord::addCategoryName( const QString& ) {
47 Categories catDB; 49 Categories catDB;
48 catDB.load( categoryFileName() ); 50 catDB.load( categoryFileName() );
49 51
50 52
51} 53}
52bool OPimRecord::isEmpty()const { 54bool OPimRecord::isEmpty()const {
53 return ( uid() == 0 ); 55 return ( uid() == 0 );
54} 56}
55/*QString OPimRecord::crossToString()const { 57/*QString OPimRecord::crossToString()const {
56 QString str; 58 QString str;
57 QMap<QString, QArray<int> >::ConstIterator it; 59 QMap<QString, QArray<int> >::ConstIterator it;
58 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 60 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
59 QArray<int> id = it.data(); 61 QArray<int> id = it.data();
60 for ( uint i = 0; i < id.size(); ++i ) { 62 for ( uint i = 0; i < id.size(); ++i ) {
61 str += it.key() + "," + QString::number( i ) + ";"; 63 str += it.key() + "," + QString::number( i ) + ";";
62 } 64 }
63 } 65 }
64 str = str.remove( str.length()-1, 1); // strip the ; 66 str = str.remove( str.length()-1, 1); // strip the ;
65 //qWarning("IDS " + str ); 67 //qWarning("IDS " + str );
66 68
67 return str; 69 return str;
68 }*/ 70 }*/
69/* if uid = 1 assign a new one */ 71/* if uid = 1 assign a new one */
70void OPimRecord::setUid( int uid ) { 72void OPimRecord::setUid( int uid ) {
71 if ( uid == 1) 73 if ( uid == 1)
72 uid = uidGen().generate(); 74 uid = uidGen().generate();
73 75
74 Qtopia::Record::setUid( uid ); 76 Qtopia::Record::setUid( uid );
75}; 77};
76Qtopia::UidGen &OPimRecord::uidGen() { 78Qtopia::UidGen &OPimRecord::uidGen() {
77 return m_uidGen; 79 return m_uidGen;
78} 80}
79OPimXRefManager &OPimRecord::xrefmanager() { 81OPimXRefManager &OPimRecord::xrefmanager() {
80 return m_xrefman; 82 return m_xrefman;
81} 83}
82int OPimRecord::rtti(){ 84int OPimRecord::rtti(){
83 return 0; 85 return 0;
84} 86}
87
88/**
89 * now let's put our data into the stream
90 */
91/*
92 * First read UID
93 * Categories
94 * XRef
95 */
96bool OPimRecord::loadFromStream( QDataStream& stream ) {
97 int Int;
98 uint UInt;
99 stream >> Int;
100 setUid(Int);
101
102 /** Categories */
103 stream >> UInt;
104 QArray<int> array(UInt);
105 for (uint i = 0; i < UInt; i++ ) {
106 stream >> array[i];
107 }
108 setCategories( array );
109
110 /*
111 * now we do the X-Ref stuff
112 */
113 OPimXRef xref;
114 stream >> UInt;
115 for ( uint i = 0; i < UInt; i++ ) {
116 xref.setPartner( OPimXRef::One, partner( stream ) );
117 xref.setPartner( OPimXRef::Two, partner( stream ) );
118 m_xrefman.add( xref );
119 }
120
121 return true;
122}
123bool OPimRecord::saveToStream( QDataStream& stream )const {
124 /** UIDs */
125
126 stream << uid();
127
128 /** Categories */
129 stream << categories().count();
130 for ( uint i = 0; i < categories().count(); i++ ) {
131 stream << categories()[i];
132 }
133
134 /*
135 * first the XRef count
136 * then the xrefs
137 */
138 stream << m_xrefman.list().count();
139 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
140 it != m_xrefman.list().end(); ++it ) {
141 flush( (*it).partner( OPimXRef::One), stream );
142 flush( (*it).partner( OPimXRef::Two), stream );
143 }
144 return true;
145}
146void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{
147 str << par.service();
148 str << par.uid();
149 str << par.field();
150}
151OPimXRefPartner OPimRecord::partner( QDataStream& stream ) {
152 OPimXRefPartner par;
153 QString str;
154 int i;
155
156 stream >> str;
157 par.setService( str );
158
159 stream >> i;
160 par.setUid( i );
161
162 stream >> i ;
163 par.setField( i );
164
165 return par;
166}
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index ec99a13..665530f 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -1,122 +1,134 @@
1#ifndef OPIE_PIM_RECORD_H 1#ifndef OPIE_PIM_RECORD_H
2#define OPIE_PIM_RECORD_H 2#define OPIE_PIM_RECORD_H
3 3
4#include <qdatastream.h>
4#include <qmap.h> 5#include <qmap.h>
5#include <qstring.h> 6#include <qstring.h>
6#include <qstringlist.h> 7#include <qstringlist.h>
7 8
8#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
9 10
10#include <opie/opimxrefmanager.h> 11#include <opie/opimxrefmanager.h>
11 12
12/** 13/**
13 * This is the base class for 14 * This is the base class for
14 * all PIM Records 15 * all PIM Records
15 * 16 *
16 */ 17 */
17class OPimRecord : public Qtopia::Record { 18class OPimRecord : public Qtopia::Record {
18public: 19public:
19 /** 20 /**
20 * c'tor 21 * c'tor
21 * uid of 0 isEmpty 22 * uid of 0 isEmpty
22 * uid of 1 will be assigned a new one 23 * uid of 1 will be assigned a new one
23 */ 24 */
24 OPimRecord(int uid = 0); 25 OPimRecord(int uid = 0);
25 ~OPimRecord(); 26 ~OPimRecord();
26 27
27 /** 28 /**
28 * copy c'tor 29 * copy c'tor
29 */ 30 */
30 OPimRecord( const OPimRecord& rec ); 31 OPimRecord( const OPimRecord& rec );
31 32
32 /** 33 /**
33 * copy operator 34 * copy operator
34 */ 35 */
35 OPimRecord &operator=( const OPimRecord& ); 36 OPimRecord &operator=( const OPimRecord& );
36 37
37 /** 38 /**
38 * category names resolved 39 * category names resolved
39 */ 40 */
40 QStringList categoryNames()const; 41 QStringList categoryNames()const;
41 42
42 /** 43 /**
43 * set category names they will be resolved 44 * set category names they will be resolved
44 */ 45 */
45 void setCategoryNames( const QStringList& ); 46 void setCategoryNames( const QStringList& );
46 47
47 /** 48 /**
48 * addCategoryName adds a name 49 * addCategoryName adds a name
49 * to the internal category list 50 * to the internal category list
50 */ 51 */
51 void addCategoryName( const QString& ); 52 void addCategoryName( const QString& );
52 53
53 /** 54 /**
54 * if a Record isEmpty 55 * if a Record isEmpty
55 * it's empty if it's 0 56 * it's empty if it's 0
56 */ 57 */
57 virtual bool isEmpty()const; 58 virtual bool isEmpty()const;
58 59
59 /** 60 /**
60 * toRichText summary 61 * toRichText summary
61 */ 62 */
62 virtual QString toRichText()const = 0; 63 virtual QString toRichText()const = 0;
63 64
64 /** 65 /**
65 * a small one line summary 66 * a small one line summary
66 */ 67 */
67 virtual QString toShortText()const = 0; 68 virtual QString toShortText()const = 0;
68 69
69 /** 70 /**
70 * the name of the Record 71 * the name of the Record
71 */ 72 */
72 virtual QString type()const = 0; 73 virtual QString type()const = 0;
73 74
74 /** 75 /**
75 * converts the internal structure to a map 76 * converts the internal structure to a map
76 */ 77 */
77 virtual QMap<int, QString> toMap()const = 0; 78 virtual QMap<int, QString> toMap()const = 0;
78 79
79 /** 80 /**
80 * key value representation of extra items 81 * key value representation of extra items
81 */ 82 */
82 virtual QMap<QString, QString> toExtraMap()const = 0; 83 virtual QMap<QString, QString> toExtraMap()const = 0;
83 84
84 /** 85 /**
85 * the name for a recordField 86 * the name for a recordField
86 */ 87 */
87 virtual QString recordField(int)const = 0; 88 virtual QString recordField(int)const = 0;
88 89
89 /** 90 /**
90 * returns a reference of the 91 * returns a reference of the
91 * Cross Reference Manager 92 * Cross Reference Manager
92 * Partner 'One' is THIS PIM RECORD! 93 * Partner 'One' is THIS PIM RECORD!
93 * 'Two' is the Partner where we link to 94 * 'Two' is the Partner where we link to
94 */ 95 */
95 OPimXRefManager& xrefmanager(); 96 OPimXRefManager& xrefmanager();
96 97
97 /** 98 /**
98 * set the uid 99 * set the uid
99 */ 100 */
100 virtual void setUid( int uid ); 101 virtual void setUid( int uid );
101 102
102 /* 103 /*
103 * used inside the Templates for casting 104 * used inside the Templates for casting
104 * REIMPLEMENT in your .... 105 * REIMPLEMENT in your ....
105 */ 106 */
106 static int rtti(); 107 static int rtti();
107 108
109 /**
110 * some marshalling and de marshalling code
111 * saves the OPimRecord
112 * to and from a DataStream
113 */
114 virtual bool loadFromStream(QDataStream& );
115 virtual bool saveToStream( QDataStream& stream )const;
116
108protected: 117protected:
109 Qtopia::UidGen &uidGen(); 118 Qtopia::UidGen &uidGen();
110// QString crossToString()const; 119// QString crossToString()const;
111 120
112private: 121private:
113 class OPimRecordPrivate; 122 class OPimRecordPrivate;
114 OPimRecordPrivate *d; 123 OPimRecordPrivate *d;
115 OPimXRefManager m_xrefman; 124 OPimXRefManager m_xrefman;
116 static Qtopia::UidGen m_uidGen; 125 static Qtopia::UidGen m_uidGen;
117 126
127private:
128 void flush( const OPimXRefPartner&, QDataStream& stream )const;
129 OPimXRefPartner partner( QDataStream& );
118}; 130};
119 131
120 132
121 133
122#endif 134#endif
diff --git a/libopie2/opiepim/core/opimresolver.cpp b/libopie2/opiepim/core/opimresolver.cpp
new file mode 100644
index 0000000..4ebbd6e
--- a/dev/null
+++ b/libopie2/opiepim/core/opimresolver.cpp
@@ -0,0 +1,198 @@
1#include <qcopchannel_qws.h>
2
3#include <qpe/qcopenvelope_qws.h>
4
5#include "otodoaccess.h"
6#include "ocontactaccess.h"
7
8//#include "opimfactory.h"
9#include "opimresolver.h"
10
11OPimResolver* OPimResolver::m_self = 0l;
12
13OPimResolver::OPimResolver() {
14 /* the built in channels */
15 m_builtIns << "Todolist" << "Addressbook" << "Datebook";
16}
17OPimResolver* OPimResolver::self() {
18 if (!m_self)
19 m_self = new OPimResolver();
20
21 return m_self;
22}
23
24/*
25 * FIXME use a cache here too
26 */
27OPimRecord* OPimResolver::record( const QString& service, int uid ) {
28 OPimRecord* rec = 0l;
29 OPimBase* base = backend( service );
30
31 if ( base )
32 rec = base->record( uid );
33 delete base;
34
35 return rec;
36}
37OPimRecord* OPimResolver::record( const QString& service ) {
38 return record( serviceId( service ) );
39}
40OPimRecord* OPimResolver::record( int rtti ) {
41 OPimRecord* rec = 0l;
42 switch( rtti ) {
43 case 1: /* todolist */
44 rec = new OTodo();
45 case 2: /* contact */
46 rec = new OContact();
47 default:
48 break;
49 }
50 /*
51 * FIXME resolve externally
52 */
53 if (!rec ) {
54 ;
55 }
56 return 0l;
57}
58bool OPimResolver::isBuiltIn( const QString& str) const{
59 return m_builtIns.contains( str );
60}
61QCString OPimResolver::qcopChannel( enum BuiltIn& built)const {
62 QCString str("QPE/");
63 switch( built ) {
64 case TodoList:
65 str += "Todolist";
66 break;
67 case DateBook:
68 str += "Datebook";
69 break;
70 case AddressBook:
71 str += "Addressbook";
72 break;
73 default:
74 break;
75 }
76
77 return str;
78}
79QCString OPimResolver::qcopChannel( const QString& service )const {
80 QCString str("QPE/");
81 str += service.latin1();
82 return str;
83}
84/*
85 * Implement services!!
86 * FIXME
87 */
88QCString OPimResolver::applicationChannel( enum BuiltIn& built)const {
89 QCString str("QPE/Application/");
90 switch( built ) {
91 case TodoList:
92 str += "todolist";
93 break;
94 case DateBook:
95 str += "datebook";
96 break;
97 case AddressBook:
98 str += "addressbook";
99 break;
100 }
101
102 return str;
103}
104QCString OPimResolver::applicationChannel( const QString& service )const {
105 QCString str("QPE/Application/");
106
107 if ( isBuiltIn( service ) ) {
108 if ( service == "Todolist" )
109 str += "todolist";
110 else if ( service == "Datebook" )
111 str += "datebook";
112 else if ( service == "Addressbook" )
113 str += "addressbook";
114 }else
115 ; // FIXME for additional stuff
116
117 return str;
118}
119QStringList OPimResolver::services()const {
120 return m_builtIns;
121}
122QString OPimResolver::serviceName( int rtti ) const{
123 QString str;
124 switch ( rtti ) {
125 case TodoList:
126 str = "Todolist";
127 break;
128 case DateBook:
129 str = "Datebook";
130 break;
131 case AddressBook:
132 str = "Addressbook";
133 break;
134 default:
135 break;
136 }
137 return str;
138 // FIXME me for 3rd party
139}
140int OPimResolver::serviceId( const QString& service ) {
141 int rtti = 0;
142 if ( service == "Todolist" )
143 rtti = TodoList;
144 else if ( service == "Datebook" )
145 rtti = DateBook;
146 else if ( service == "Addressbook" )
147 rtti = AddressBook;
148
149 return rtti;
150}
151/**
152 * check if the 'service' is registered and if so we'll
153 */
154bool OPimResolver::add( const QString& service, const OPimRecord& rec) {
155 if ( QCopChannel::isRegistered( applicationChannel( service ) ) ) {
156 QByteArray data;
157 QDataStream arg(data, IO_WriteOnly );
158 if ( rec.saveToStream( arg ) ) {
159 QCopEnvelope env( applicationChannel( service ), "add(int,QByteArray)" );
160 env << rec.rtti();
161 env << data;
162 }else
163 return false;
164 }else{
165 OPimBase* base = backend( service );
166 if (!base ) return false;
167
168 base->load();
169 base->add( rec );
170 base->save();
171 delete base;
172 }
173
174 return true;
175}
176OPimBase* OPimResolver::backend( const QString& service ) {
177 return backend( serviceId( service ) );
178}
179OPimBase* OPimResolver::backend( int rtti ) {
180 OPimBase* base = 0l;
181 switch( rtti ) {
182 case TodoList:
183 base = new OTodoAccess();
184 break;
185 case DateBook:
186 break;
187 case AddressBook:
188 base = new OContactAccess("Resolver");
189 break;
190 default:
191 break;
192 }
193 // FIXME for 3rd party
194 if (!base )
195 ;
196
197 return base;
198}
diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h
index 86ae3eb..1ce1619 100644
--- a/libopie2/opiepim/core/opimresolver.h
+++ b/libopie2/opiepim/core/opimresolver.h
@@ -1,56 +1,90 @@
1#ifndef OPIE_PIM_RESOLVER 1#ifndef OPIE_PIM_RESOLVER
2#define OPIE_PIM_RESOLVER 2#define OPIE_PIM_RESOLVER
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7#include <opie/otemplatebase.h>
8
7/** 9/**
8 * OPimResolver is a MetaClass to access 10 * OPimResolver is a MetaClass to access
9 * available backends read only. 11 * available backends read only.
10 * It will be used to resolve uids + app names 12 * It will be used to resolve uids + app names
11 * to full informations 13 * to full informations
12 * to traverse through a list of alarms, reminders 14 * to traverse through a list of alarms, reminders
13 * to get access to built in PIM functionality 15 * to get access to built in PIM functionality
14 * and to more stuff 16 * and to more stuff
15 * THE PERFORMANCE will depend on THE BACKEND 17 * THE PERFORMANCE will depend on THE BACKEND
16 * USING XML is a waste of memory!!!!! 18 * USING XML is a waste of memory!!!!!
17 */ 19 */
18class OPimResolver : public QObject { 20class OPimResolver {
19public: 21public:
20 enum BuiltIn { TodoList = 0, 22 enum BuiltIn { TodoList = 0,
21 DateBook, 23 DateBook,
22 AddressBook 24 AddressBook
23 }; 25 };
24 static OPimResolver* self(); 26 static OPimResolver* self();
25 27
26 28
27 /* 29 /**
28 * return a record for a uid 30 * return a record for a uid
29 * and an app 31 * and an service
32 * You've THE OWNERSHIP NOW!
30 */ 33 */
31 OPimRecord &record( const QString& service, int uid ); 34 OPimRecord *record( const QString& service, int uid );
32 35
33 /** 36 /**
34 * return the QCopChannel for service 37 * return the QCopChannel for service
35 * When we will use Qtopia Services it will be used here 38 * When we will use Qtopia Services it will be used here
36 */ 39 */
37 QString qcopChannel( enum BuiltIn& )const; 40 QCString qcopChannel( enum BuiltIn& )const;
38 QString qcopChannel( const QString& service ); 41 QCString qcopChannel( const QString& service )const;
42
43 /**
44 * The Application channel (QPE/Application/name)
45 */
46 QCString applicationChannel( enum BuiltIn& )const;
47 QCString applicationChannel( const QString& service )const;
39 48
40 /** 49 /**
41 * return a list of available services 50 * return a list of available services
42 */ 51 */
43 QStringList services()const; 52 QStringList services()const;
44 53 inline QString serviceName(int rrti )const;
54 int serviceId( const QString& Service);
45 /** 55 /**
46 * add a record to a service... ;) 56 * add a record to a service... ;)
47 */ 57 */
48 bool add( const QString& service, const OPimRecord& ); 58 bool add( const QString& service, const OPimRecord& );
49 59
60
61 /**
62 * record returns an empty record for a given service.
63 * Be sure to delete it!!!
64 *
65 */
66 OPimRecord* record( const QString& service );
67 OPimRecord* record( int rtti );
68
69 /**
70 * you can cast to your
71 */
72 OPimBase* backend( const QString& service );
73 OPimBase* backend( int rtti );
50private: 74private:
51 OPimResolver(); 75 OPimResolver();
52 OPimRecord *m_last; 76 void loadData();
77 inline bool isBuiltIn( const QString& )const;
78 OPimRecord* recordExtern( const QString&, int );
79 OPimRecord* recordExtern( const QString& );
80
81 static OPimResolver* m_self;
82 struct Data;
83 class Private;
53 84
54}: 85 Data* data;
86 Private* d;
87 QStringList m_builtIns;
88};
55 89
56#endif 90#endif
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h
index b855919..29fb6ec 100644
--- a/libopie2/opiepim/core/otemplatebase.h
+++ b/libopie2/opiepim/core/otemplatebase.h
@@ -1,32 +1,91 @@
1#ifndef OPIE_TEMPLATE_BASE_H 1#ifndef OPIE_TEMPLATE_BASE_H
2#define OPIE_TEMPLATE_BASE_H 2#define OPIE_TEMPLATE_BASE_H
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include "opimrecord.h" 6#include <opie/opimrecord.h>
7
7 8
8/** 9/**
10 * Templates do not have a base class, This is why
11 * we've this class
12 * this is here to give us the possibility
13 * to have a common base class
14 * You may not want to use that interface internaly
15 * POOR mans interface
16 */
17struct OPimBase {
18 /**
19 * return the rtti
20 */
21 virtual int rtti()= 0;
22 virtual OPimRecord* record()const = 0;
23 virtual OPimRecord* record(int uid)const = 0;
24 virtual bool add( const OPimRecord& ) = 0;
25 virtual bool remove( int uid ) = 0;
26 virtual bool remove( const OPimRecord& ) = 0;
27 virtual void clear() = 0;
28 virtual bool load() = 0;
29 virtual bool save() = 0;
30 virtual QArray<int> records()const = 0;
31 /*
32 * ADD editing here?
33 * -zecke
34 */
35
36};
37/**
9 * internal template base 38 * internal template base
39 * T needs to implement the copy c'tor!!!
10 */ 40 */
11template <class T = OPimRecord> 41template <class T = OPimRecord>
12class OTemplateBase { 42class OTemplateBase : public OPimBase {
13public: 43public:
14 enum CacheDirection { Forward=0, Reverse }; 44 enum CacheDirection { Forward=0, Reverse };
15 OTemplateBase() { 45 OTemplateBase() {
16 }; 46 };
17 virtual ~OTemplateBase() { 47 virtual ~OTemplateBase() {
18 } 48 }
19 virtual T find( int uid )const = 0; 49 virtual T find( int uid )const = 0;
20 50
21 /** 51 /**
22 * read ahead find 52 * read ahead find
23 */ 53 */
24 virtual T find( int uid, const QArray<int>& items, 54 virtual T find( int uid, const QArray<int>& items,
25 uint current, CacheDirection dir = Forward )const = 0; 55 uint current, CacheDirection dir = Forward )const = 0;
26 virtual void cache( const T& )const = 0; 56 virtual void cache( const T& )const = 0;
27 virtual void setSaneCacheSize( int ) = 0; 57 virtual void setSaneCacheSize( int ) = 0;
28 58
59 /* reimplement of OPimBase */
60 int rtti();
61 OPimRecord* record()const;
62 OPimRecord* record(int uid )const;
63 static T* rec();
29}; 64};
30 65
66/*
67 * implementation
68 */
69template <class T>
70int
71OTemplateBase<T>::rtti() {
72 return T::rtti();
73}
74template <class T>
75OPimRecord* OTemplateBase<T>::record()const {
76 T* t = new T;
77 return t;
78}
79template <class T>
80OPimRecord* OTemplateBase<T>::record(int uid )const {
81 T t2 = find(uid );
82 T* t1 = new T(t2);
83
84 return t1;
85};
86template <class T>
87T* OTemplateBase<T>::rec() {
88 return new T;
89}
31 90
32#endif 91#endif
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp
index d860411..5e89a1b 100644
--- a/libopie2/opiepim/core/otodoaccess.cpp
+++ b/libopie2/opiepim/core/otodoaccess.cpp
@@ -1,86 +1,56 @@
1#include <qdatetime.h> 1#include <qdatetime.h>
2 2
3#include <qpe/alarmserver.h> 3#include <qpe/alarmserver.h>
4 4
5// #include "otodoaccesssql.h" 5// #include "otodoaccesssql.h"
6#include "otodoaccess.h" 6#include "otodoaccess.h"
7#include "obackendfactory.h" 7#include "obackendfactory.h"
8 8
9OTodoAccess::OTodoAccess( OTodoAccessBackend* end ) 9OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access )
10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) 10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end )
11{ 11{
12// if (end == 0l ) 12// if (end == 0l )
13// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); 13// m_todoBackEnd = new OTodoAccessBackendSQL( QString::null);
14 14
15 // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben ! 15 // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben !
16 if (end == 0l ) 16 if (end == 0l )
17 m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); 17 m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null);
18 18
19 setBackEnd( m_todoBackEnd ); 19 setBackEnd( m_todoBackEnd );
20} 20}
21OTodoAccess::~OTodoAccess() { 21OTodoAccess::~OTodoAccess() {
22// qWarning("~OTodoAccess"); 22// qWarning("~OTodoAccess");
23} 23}
24void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { 24void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) {
25 QValueList<OTodo>::ConstIterator it; 25 QValueList<OTodo>::ConstIterator it;
26 for ( it = list.begin(); it != list.end(); ++it ) { 26 for ( it = list.begin(); it != list.end(); ++it ) {
27 replace( (*it) ); 27 replace( (*it) );
28 } 28 }
29} 29}
30OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 30OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
31 const QDate& end, 31 const QDate& end,
32 bool includeNoDates ) { 32 bool includeNoDates ) {
33 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 33 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
34 34
35 List lis( ints, this ); 35 List lis( ints, this );
36 return lis; 36 return lis;
37} 37}
38OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 38OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
39 bool includeNoDates ) { 39 bool includeNoDates ) {
40 return effectiveToDos( start, QDate::currentDate(), 40 return effectiveToDos( start, QDate::currentDate(),
41 includeNoDates ); 41 includeNoDates );
42} 42}
43OTodoAccess::List OTodoAccess::overDue() { 43OTodoAccess::List OTodoAccess::overDue() {
44 List lis( m_todoBackEnd->overDue(), this ); 44 List lis( m_todoBackEnd->overDue(), this );
45 return lis; 45 return lis;
46} 46}
47void OTodoAccess::addAlarm( const OTodo& event) {
48/* FIXME use the new notifier architecture
49 if (!event.hasAlarmDateTime() )
50 return;
51
52 QDateTime now = QDateTime::currentDateTime();
53 QDateTime schedule = event.alarmDateTime();
54
55 if ( schedule > now ){
56 AlarmServer::addAlarm( schedule,
57 "QPE/Application/todolist",
58 "alarm(QDateTime,int)", event.uid() );
59
60 }
61*/
62}
63void OTodoAccess::delAlarm( int uid) {
64
65 QDateTime schedule; // Create null DateTime
66
67 // I hope this will remove all scheduled alarms
68 // with the given uid !?
69 // If not: I have to rethink how to remove already
70 // scheduled events... (se)
71 // it should be fine -zecke
72// qWarning("Removing alarm for event with uid %d", uid );
73 AlarmServer::deleteAlarm( schedule ,
74 "QPE/Application/todolist",
75 "alarm(QDateTime,int)", uid );
76}
77/* sort order */ 47/* sort order */
78OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 48OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
79 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, 49 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
80 filter, cat ); 50 filter, cat );
81 OTodoAccess::List list( ints, this ); 51 OTodoAccess::List list( ints, this );
82 return list; 52 return list;
83} 53}
84void OTodoAccess::removeAllCompleted() { 54void OTodoAccess::removeAllCompleted() {
85 m_todoBackEnd->removeAllCompleted(); 55 m_todoBackEnd->removeAllCompleted();
86} 56}
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h
index c079155..2bb87dc 100644
--- a/libopie2/opiepim/core/otodoaccess.h
+++ b/libopie2/opiepim/core/otodoaccess.h
@@ -1,98 +1,87 @@
1#ifndef OPIE_TODO_ACCESS_H 1#ifndef OPIE_TODO_ACCESS_H
2#define OPIE_TODO_ACCESS_H 2#define OPIE_TODO_ACCESS_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7#include "otodo.h" 7#include "otodo.h"
8#include "otodoaccessbackend.h" 8#include "otodoaccessbackend.h"
9#include "opimaccesstemplate.h" 9#include "opimaccesstemplate.h"
10 10
11 11
12/** 12/**
13 * OTodoAccess 13 * OTodoAccess
14 * the class to get access to 14 * the class to get access to
15 * the todolist 15 * the todolist
16 */ 16 */
17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { 17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 enum SortOrder { Completed = 0, 20 enum SortOrder { Completed = 0,
21 Priority, 21 Priority,
22 Description, 22 Description,
23 Deadline }; 23 Deadline };
24 enum SortFilter{ Category =1, 24 enum SortFilter{ Category =1,
25 OnlyOverDue= 2, 25 OnlyOverDue= 2,
26 DoNotShowCompleted =4 }; 26 DoNotShowCompleted =4 };
27 /** 27 /**
28 * if you use 0l 28 * if you use 0l
29 * the default resource will be 29 * the default resource will be
30 * picked up 30 * picked up
31 */ 31 */
32 OTodoAccess( OTodoAccessBackend* = 0l); 32 OTodoAccess( OTodoAccessBackend* = 0l, enum Access acc = Random );
33 ~OTodoAccess(); 33 ~OTodoAccess();
34 34
35 35
36 /* our functions here */ 36 /* our functions here */
37 /** 37 /**
38 * include todos from start to end 38 * include todos from start to end
39 * includeNoDates whether or not to include 39 * includeNoDates whether or not to include
40 * events with no dates 40 * events with no dates
41 */ 41 */
42 List effectiveToDos( const QDate& start, 42 List effectiveToDos( const QDate& start,
43 const QDate& end, 43 const QDate& end,
44 bool includeNoDates = true ); 44 bool includeNoDates = true );
45 45
46 /** 46 /**
47 * start 47 * start
48 * end date taken from the currentDate() 48 * end date taken from the currentDate()
49 */ 49 */
50 List effectiveToDos( const QDate& start, 50 List effectiveToDos( const QDate& start,
51 bool includeNoDates = true ); 51 bool includeNoDates = true );
52 52
53 53
54 /** 54 /**
55 * return overdue OTodos 55 * return overdue OTodos
56 */ 56 */
57 List overDue(); 57 List overDue();
58 58
59 /** 59 /**
60 * 60 *
61 */ 61 */
62 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); 62 List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
63 63
64 /** 64 /**
65 * merge a list of OTodos into 65 * merge a list of OTodos into
66 * the resource 66 * the resource
67 */ 67 */
68 void mergeWith( const QValueList<OTodo>& ); 68 void mergeWith( const QValueList<OTodo>& );
69 69
70 /** 70 /**
71 * delete all already completed items 71 * delete all already completed items
72 */ 72 */
73 void removeAllCompleted(); 73 void removeAllCompleted();
74 74
75signals: 75signals:
76 /** 76 /**
77 * if the OTodoAccess was changed 77 * if the OTodoAccess was changed
78 */ 78 */
79 void signalChanged( const OTodoAccess* ); 79 void signalChanged( const OTodoAccess* );
80private: 80private:
81 /**
82 * add an Alarm to the AlarmServer
83 */
84 void addAlarm( const OTodo& );
85
86 /**
87 * delete an alarm with the uid from
88 * the alarm server
89 */
90 void delAlarm( int uid );
91
92 int m_cat; 81 int m_cat;
93 OTodoAccessBackend* m_todoBackEnd; 82 OTodoAccessBackend* m_todoBackEnd;
94 class OTodoAccessPrivate; 83 class OTodoAccessPrivate;
95 OTodoAccessPrivate* d; 84 OTodoAccessPrivate* d;
96}; 85};
97 86
98#endif 87#endif
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index 6aec62e..38cba72 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -1,216 +1,217 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
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 "opimresolver.h"
25 26
26#include <qpe/stringutil.h> 27#include <qpe/stringutil.h>
27#include <qpe/timeconversion.h> 28#include <qpe/timeconversion.h>
28#include <qpe/timestring.h> 29#include <qpe/timestring.h>
29 30
30#include <qobject.h> 31#include <qobject.h>
31#include <qregexp.h> 32#include <qregexp.h>
32#include <qstylesheet.h> 33#include <qstylesheet.h>
33#include <qfileinfo.h> 34#include <qfileinfo.h>
34#include <qmap.h> 35#include <qmap.h>
35 36
36#include <stdio.h> 37#include <stdio.h>
37 38
38/*! 39/*!
39 \class Contact contact.h 40 \class Contact contact.h
40 \brief The Contact class holds the data of an address book entry. 41 \brief The Contact class holds the data of an address book entry.
41 42
42 This data includes information the name of the person, contact 43 This data includes information the name of the person, contact
43 information, and business information such as deparment and job title. 44 information, and business information such as deparment and job title.
44 45
45 \ingroup qtopiaemb 46 \ingroup qtopiaemb
46 \ingroup qtopiadesktop 47 \ingroup qtopiadesktop
47*/ 48*/
48 49
49 50
50/*! 51/*!
51 Creates a new, empty contact. 52 Creates a new, empty contact.
52*/ 53*/
53OContact::OContact() 54OContact::OContact()
54 : OPimRecord(), mMap(), d( 0 ) 55 : OPimRecord(), mMap(), d( 0 )
55{ 56{
56} 57}
57 58
58/*! 59/*!
59 \internal 60 \internal
60 Creates a new contact. The properties of the contact are 61 Creates a new contact. The properties of the contact are
61 set from \a fromMap. 62 set from \a fromMap.
62*/ 63*/
63OContact::OContact( const QMap<int, QString> &fromMap ) : 64OContact::OContact( const QMap<int, QString> &fromMap ) :
64 OPimRecord(), mMap( fromMap ), d( 0 ) 65 OPimRecord(), mMap( fromMap ), d( 0 )
65{ 66{
66 QString cats = mMap[ Qtopia::AddressCategory ]; 67 QString cats = mMap[ Qtopia::AddressCategory ];
67 if ( !cats.isEmpty() ) 68 if ( !cats.isEmpty() )
68 setCategories( idsFromString( cats ) ); 69 setCategories( idsFromString( cats ) );
69 70
70 QString uidStr = find( Qtopia::AddressUid ); 71 QString uidStr = find( Qtopia::AddressUid );
71 72
72 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ 73 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
73 qWarning( "Invalid UID found. Generate new one.." ); 74 qWarning( "Invalid UID found. Generate new one.." );
74 setUid( uidGen().generate() ); 75 setUid( uidGen().generate() );
75 }else 76 }else
76 setUid( uidStr.toInt() ); 77 setUid( uidStr.toInt() );
77 78
78// if ( !uidStr.isEmpty() ) 79// if ( !uidStr.isEmpty() )
79 // setUid( uidStr.toInt() ); 80 // setUid( uidStr.toInt() );
80} 81}
81 82
82/*! 83/*!
83 Destroys a contact. 84 Destroys a contact.
84*/ 85*/
85OContact::~OContact() 86OContact::~OContact()
86{ 87{
87} 88}
88 89
89/*! \fn void OContact::setTitle( const QString &str ) 90/*! \fn void OContact::setTitle( const QString &str )
90 Sets the title of the contact to \a str. 91 Sets the title of the contact to \a str.
91*/ 92*/
92 93
93/*! \fn void OContact::setFirstName( const QString &str ) 94/*! \fn void OContact::setFirstName( const QString &str )
94 Sets the first name of the contact to \a str. 95 Sets the first name of the contact to \a str.
95*/ 96*/
96 97
97/*! \fn void OContact::setMiddleName( const QString &str ) 98/*! \fn void OContact::setMiddleName( const QString &str )
98 Sets the middle name of the contact to \a str. 99 Sets the middle name of the contact to \a str.
99*/ 100*/
100 101
101/*! \fn void OContact::setLastName( const QString &str ) 102/*! \fn void OContact::setLastName( const QString &str )
102 Sets the last name of the contact to \a str. 103 Sets the last name of the contact to \a str.
103*/ 104*/
104 105
105/*! \fn void OContact::setSuffix( const QString &str ) 106/*! \fn void OContact::setSuffix( const QString &str )
106 Sets the suffix of the contact to \a str. 107 Sets the suffix of the contact to \a str.
107*/ 108*/
108 109
109/*! \fn void OContact::setFileAs( const QString &str ) 110/*! \fn void OContact::setFileAs( const QString &str )
110 Sets the contact to filed as \a str. 111 Sets the contact to filed as \a str.
111*/ 112*/
112 113
113/*! \fn void OContact::setDefaultEmail( const QString &str ) 114/*! \fn void OContact::setDefaultEmail( const QString &str )
114 Sets the default email of the contact to \a str. 115 Sets the default email of the contact to \a str.
115*/ 116*/
116 117
117/*! \fn void OContact::setHomeStreet( const QString &str ) 118/*! \fn void OContact::setHomeStreet( const QString &str )
118 Sets the home street address of the contact to \a str. 119 Sets the home street address of the contact to \a str.
119*/ 120*/
120 121
121/*! \fn void OContact::setHomeCity( const QString &str ) 122/*! \fn void OContact::setHomeCity( const QString &str )
122 Sets the home city of the contact to \a str. 123 Sets the home city of the contact to \a str.
123*/ 124*/
124 125
125/*! \fn void OContact::setHomeState( const QString &str ) 126/*! \fn void OContact::setHomeState( const QString &str )
126 Sets the home state of the contact to \a str. 127 Sets the home state of the contact to \a str.
127*/ 128*/
128 129
129/*! \fn void OContact::setHomeZip( const QString &str ) 130/*! \fn void OContact::setHomeZip( const QString &str )
130 Sets the home zip code of the contact to \a str. 131 Sets the home zip code of the contact to \a str.
131*/ 132*/
132 133
133/*! \fn void OContact::setHomeCountry( const QString &str ) 134/*! \fn void OContact::setHomeCountry( const QString &str )
134 Sets the home country of the contact to \a str. 135 Sets the home country of the contact to \a str.
135*/ 136*/
136 137
137/*! \fn void OContact::setHomePhone( const QString &str ) 138/*! \fn void OContact::setHomePhone( const QString &str )
138 Sets the home phone number of the contact to \a str. 139 Sets the home phone number of the contact to \a str.
139*/ 140*/
140 141
141/*! \fn void OContact::setHomeFax( const QString &str ) 142/*! \fn void OContact::setHomeFax( const QString &str )
142 Sets the home fax number of the contact to \a str. 143 Sets the home fax number of the contact to \a str.
143*/ 144*/
144 145
145/*! \fn void OContact::setHomeMobile( const QString &str ) 146/*! \fn void OContact::setHomeMobile( const QString &str )
146 Sets the home mobile phone number of the contact to \a str. 147 Sets the home mobile phone number of the contact to \a str.
147*/ 148*/
148 149
149/*! \fn void OContact::setHomeWebpage( const QString &str ) 150/*! \fn void OContact::setHomeWebpage( const QString &str )
150 Sets the home webpage of the contact to \a str. 151 Sets the home webpage of the contact to \a str.
151*/ 152*/
152 153
153/*! \fn void OContact::setCompany( const QString &str ) 154/*! \fn void OContact::setCompany( const QString &str )
154 Sets the company for contact to \a str. 155 Sets the company for contact to \a str.
155*/ 156*/
156 157
157/*! \fn void OContact::setJobTitle( const QString &str ) 158/*! \fn void OContact::setJobTitle( const QString &str )
158 Sets the job title of the contact to \a str. 159 Sets the job title of the contact to \a str.
159*/ 160*/
160 161
161/*! \fn void OContact::setDepartment( const QString &str ) 162/*! \fn void OContact::setDepartment( const QString &str )
162 Sets the department for contact to \a str. 163 Sets the department for contact to \a str.
163*/ 164*/
164 165
165/*! \fn void OContact::setOffice( const QString &str ) 166/*! \fn void OContact::setOffice( const QString &str )
166 Sets the office for contact to \a str. 167 Sets the office for contact to \a str.
167*/ 168*/
168 169
169/*! \fn void OContact::setBusinessStreet( const QString &str ) 170/*! \fn void OContact::setBusinessStreet( const QString &str )
170 Sets the business street address of the contact to \a str. 171 Sets the business street address of the contact to \a str.
171*/ 172*/
172 173
173/*! \fn void OContact::setBusinessCity( const QString &str ) 174/*! \fn void OContact::setBusinessCity( const QString &str )
174 Sets the business city of the contact to \a str. 175 Sets the business city of the contact to \a str.
175*/ 176*/
176 177
177/*! \fn void OContact::setBusinessState( const QString &str ) 178/*! \fn void OContact::setBusinessState( const QString &str )
178 Sets the business state of the contact to \a str. 179 Sets the business state of the contact to \a str.
179*/ 180*/
180 181
181/*! \fn void OContact::setBusinessZip( const QString &str ) 182/*! \fn void OContact::setBusinessZip( const QString &str )
182 Sets the business zip code of the contact to \a str. 183 Sets the business zip code of the contact to \a str.
183*/ 184*/
184 185
185/*! \fn void OContact::setBusinessCountry( const QString &str ) 186/*! \fn void OContact::setBusinessCountry( const QString &str )
186 Sets the business country of the contact to \a str. 187 Sets the business country of the contact to \a str.
187*/ 188*/
188 189
189/*! \fn void OContact::setBusinessPhone( const QString &str ) 190/*! \fn void OContact::setBusinessPhone( const QString &str )
190 Sets the business phone number of the contact to \a str. 191 Sets the business phone number of the contact to \a str.
191*/ 192*/
192 193
193/*! \fn void OContact::setBusinessFax( const QString &str ) 194/*! \fn void OContact::setBusinessFax( const QString &str )
194 Sets the business fax number of the contact to \a str. 195 Sets the business fax number of the contact to \a str.
195*/ 196*/
196 197
197/*! \fn void OContact::setBusinessMobile( const QString &str ) 198/*! \fn void OContact::setBusinessMobile( const QString &str )
198 Sets the business mobile phone number of the contact to \a str. 199 Sets the business mobile phone number of the contact to \a str.
199*/ 200*/
200 201
201/*! \fn void OContact::setBusinessPager( const QString &str ) 202/*! \fn void OContact::setBusinessPager( const QString &str )
202 Sets the business pager number of the contact to \a str. 203 Sets the business pager number of the contact to \a str.
203*/ 204*/
204 205
205/*! \fn void OContact::setBusinessWebpage( const QString &str ) 206/*! \fn void OContact::setBusinessWebpage( const QString &str )
206 Sets the business webpage of the contact to \a str. 207 Sets the business webpage of the contact to \a str.
207*/ 208*/
208 209
209/*! \fn void OContact::setProfession( const QString &str ) 210/*! \fn void OContact::setProfession( const QString &str )
210 Sets the profession of the contact to \a str. 211 Sets the profession of the contact to \a str.
211*/ 212*/
212 213
213/*! \fn void OContact::setAssistant( const QString &str ) 214/*! \fn void OContact::setAssistant( const QString &str )
214 Sets the assistant of the contact to \a str. 215 Sets the assistant of the contact to \a str.
215*/ 216*/
216 217
@@ -640,470 +641,470 @@ QString OContact::find( int key ) const
640} 641}
641 642
642/*! 643/*!
643 \internal 644 \internal
644*/ 645*/
645QString OContact::displayAddress( const QString &street, 646QString OContact::displayAddress( const QString &street,
646 const QString &city, 647 const QString &city,
647 const QString &state, 648 const QString &state,
648 const QString &zip, 649 const QString &zip,
649 const QString &country ) const 650 const QString &country ) const
650{ 651{
651 QString s = street; 652 QString s = street;
652 if ( !street.isEmpty() ) 653 if ( !street.isEmpty() )
653 s+= "\n"; 654 s+= "\n";
654 s += city; 655 s += city;
655 if ( !city.isEmpty() && !state.isEmpty() ) 656 if ( !city.isEmpty() && !state.isEmpty() )
656 s += ", "; 657 s += ", ";
657 s += state; 658 s += state;
658 if ( !state.isEmpty() && !zip.isEmpty() ) 659 if ( !state.isEmpty() && !zip.isEmpty() )
659 s += " "; 660 s += " ";
660 s += zip; 661 s += zip;
661 if ( !country.isEmpty() && !s.isEmpty() ) 662 if ( !country.isEmpty() && !s.isEmpty() )
662 s += "\n"; 663 s += "\n";
663 s += country; 664 s += country;
664 return s; 665 return s;
665} 666}
666 667
667/*! 668/*!
668 \internal 669 \internal
669*/ 670*/
670QString OContact::displayBusinessAddress() const 671QString OContact::displayBusinessAddress() const
671{ 672{
672 return displayAddress( businessStreet(), businessCity(), 673 return displayAddress( businessStreet(), businessCity(),
673 businessState(), businessZip(), 674 businessState(), businessZip(),
674 businessCountry() ); 675 businessCountry() );
675} 676}
676 677
677/*! 678/*!
678 \internal 679 \internal
679*/ 680*/
680QString OContact::displayHomeAddress() const 681QString OContact::displayHomeAddress() const
681{ 682{
682 return displayAddress( homeStreet(), homeCity(), 683 return displayAddress( homeStreet(), homeCity(),
683 homeState(), homeZip(), 684 homeState(), homeZip(),
684 homeCountry() ); 685 homeCountry() );
685} 686}
686 687
687/*! 688/*!
688 Returns the full name of the contact 689 Returns the full name of the contact
689*/ 690*/
690QString OContact::fullName() const 691QString OContact::fullName() const
691{ 692{
692 QString title = find( Qtopia::Title ); 693 QString title = find( Qtopia::Title );
693 QString firstName = find( Qtopia::FirstName ); 694 QString firstName = find( Qtopia::FirstName );
694 QString middleName = find( Qtopia::MiddleName ); 695 QString middleName = find( Qtopia::MiddleName );
695 QString lastName = find( Qtopia::LastName ); 696 QString lastName = find( Qtopia::LastName );
696 QString suffix = find( Qtopia::Suffix ); 697 QString suffix = find( Qtopia::Suffix );
697 698
698 QString name = title; 699 QString name = title;
699 if ( !firstName.isEmpty() ) { 700 if ( !firstName.isEmpty() ) {
700 if ( !name.isEmpty() ) 701 if ( !name.isEmpty() )
701 name += " "; 702 name += " ";
702 name += firstName; 703 name += firstName;
703 } 704 }
704 if ( !middleName.isEmpty() ) { 705 if ( !middleName.isEmpty() ) {
705 if ( !name.isEmpty() ) 706 if ( !name.isEmpty() )
706 name += " "; 707 name += " ";
707 name += middleName; 708 name += middleName;
708 } 709 }
709 if ( !lastName.isEmpty() ) { 710 if ( !lastName.isEmpty() ) {
710 if ( !name.isEmpty() ) 711 if ( !name.isEmpty() )
711 name += " "; 712 name += " ";
712 name += lastName; 713 name += lastName;
713 } 714 }
714 if ( !suffix.isEmpty() ) { 715 if ( !suffix.isEmpty() ) {
715 if ( !name.isEmpty() ) 716 if ( !name.isEmpty() )
716 name += " "; 717 name += " ";
717 name += suffix; 718 name += suffix;
718 } 719 }
719 return name.simplifyWhiteSpace(); 720 return name.simplifyWhiteSpace();
720} 721}
721 722
722/*! 723/*!
723 Returns a list of the names of the children of the contact. 724 Returns a list of the names of the children of the contact.
724*/ 725*/
725QStringList OContact::childrenList() const 726QStringList OContact::childrenList() const
726{ 727{
727 return QStringList::split( " ", find( Qtopia::Children ) ); 728 return QStringList::split( " ", find( Qtopia::Children ) );
728} 729}
729 730
730/*! \fn void OContact::insertEmail( const QString &email ) 731/*! \fn void OContact::insertEmail( const QString &email )
731 732
732 Insert \a email into the email list. Ensures \a email can only be added 733 Insert \a email into the email list. Ensures \a email can only be added
733 once. If there is no default email address set, it sets it to the \a email. 734 once. If there is no default email address set, it sets it to the \a email.
734*/ 735*/
735 736
736/*! \fn void OContact::removeEmail( const QString &email ) 737/*! \fn void OContact::removeEmail( const QString &email )
737 738
738 Removes the \a email from the email list. If the default email was \a email, 739 Removes the \a email from the email list. If the default email was \a email,
739 then the default email address is assigned to the first email in the 740 then the default email address is assigned to the first email in the
740 email list 741 email list
741*/ 742*/
742 743
743/*! \fn void OContact::clearEmails() 744/*! \fn void OContact::clearEmails()
744 745
745 Clears the email list. 746 Clears the email list.
746 */ 747 */
747 748
748/*! \fn void OContact::insertEmails( const QStringList &emailList ) 749/*! \fn void OContact::insertEmails( const QStringList &emailList )
749 750
750 Appends the \a emailList to the exiting email list 751 Appends the \a emailList to the exiting email list
751 */ 752 */
752 753
753/*! 754/*!
754 Returns a list of email addresses belonging to the contact, including 755 Returns a list of email addresses belonging to the contact, including
755 the default email address. 756 the default email address.
756*/ 757*/
757QStringList OContact::emailList() const 758QStringList OContact::emailList() const
758{ 759{
759 QString emailStr = emails(); 760 QString emailStr = emails();
760 761
761 QStringList r; 762 QStringList r;
762 if ( !emailStr.isEmpty() ) { 763 if ( !emailStr.isEmpty() ) {
763 qDebug(" emailstr "); 764 qDebug(" emailstr ");
764 QStringList l = QStringList::split( emailSeparator(), emailStr ); 765 QStringList l = QStringList::split( emailSeparator(), emailStr );
765 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 766 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
766 r += (*it).simplifyWhiteSpace(); 767 r += (*it).simplifyWhiteSpace();
767 } 768 }
768 769
769 return r; 770 return r;
770} 771}
771 772
772/*! 773/*!
773 \overload 774 \overload
774 775
775 Generates the string for the contact to be filed as from the first, 776 Generates the string for the contact to be filed as from the first,
776 middle and last name of the contact. 777 middle and last name of the contact.
777*/ 778*/
778void OContact::setFileAs() 779void OContact::setFileAs()
779{ 780{
780 QString lastName, firstName, middleName, fileas; 781 QString lastName, firstName, middleName, fileas;
781 782
782 lastName = find( Qtopia::LastName ); 783 lastName = find( Qtopia::LastName );
783 firstName = find( Qtopia::FirstName ); 784 firstName = find( Qtopia::FirstName );
784 middleName = find( Qtopia::MiddleName ); 785 middleName = find( Qtopia::MiddleName );
785 if ( !lastName.isEmpty() && !firstName.isEmpty() 786 if ( !lastName.isEmpty() && !firstName.isEmpty()
786 && !middleName.isEmpty() ) 787 && !middleName.isEmpty() )
787 fileas = lastName + ", " + firstName + " " + middleName; 788 fileas = lastName + ", " + firstName + " " + middleName;
788 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 789 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
789 fileas = lastName + ", " + firstName; 790 fileas = lastName + ", " + firstName;
790 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 791 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
791 !middleName.isEmpty() ) 792 !middleName.isEmpty() )
792 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 793 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
793 + middleName + ( middleName.isEmpty() ? "" : " " ) 794 + middleName + ( middleName.isEmpty() ? "" : " " )
794 + lastName; 795 + lastName;
795 796
796 replace( Qtopia::FileAs, fileas ); 797 replace( Qtopia::FileAs, fileas );
797} 798}
798 799
799/*! 800/*!
800 \internal 801 \internal
801 Appends the contact information to \a buf. 802 Appends the contact information to \a buf.
802*/ 803*/
803void OContact::save( QString &buf ) const 804void OContact::save( QString &buf ) const
804{ 805{
805 static const QStringList SLFIELDS = fields(); 806 static const QStringList SLFIELDS = fields();
806 // I'm expecting "<Contact " in front of this... 807 // I'm expecting "<Contact " in front of this...
807 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 808 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
808 it != mMap.end(); ++it ) { 809 it != mMap.end(); ++it ) {
809 const QString &value = it.data(); 810 const QString &value = it.data();
810 int key = it.key(); 811 int key = it.key();
811 if ( !value.isEmpty() ) { 812 if ( !value.isEmpty() ) {
812 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) 813 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
813 continue; 814 continue;
814 815
815 key -= Qtopia::AddressCategory+1; 816 key -= Qtopia::AddressCategory+1;
816 buf += SLFIELDS[key]; 817 buf += SLFIELDS[key];
817 buf += "=\"" + Qtopia::escapeString(value) + "\" "; 818 buf += "=\"" + Qtopia::escapeString(value) + "\" ";
818 } 819 }
819 } 820 }
820 buf += customToXml(); 821 buf += customToXml();
821 if ( categories().count() > 0 ) 822 if ( categories().count() > 0 )
822 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 823 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
823 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 824 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
824 // You need to close this yourself 825 // You need to close this yourself
825} 826}
826 827
827 828
828/*! 829/*!
829 \internal 830 \internal
830 Returns the list of fields belonging to a contact 831 Returns the list of fields belonging to a contact
831 Never change order of this list ! It has to be regarding 832 Never change order of this list ! It has to be regarding
832 enum AddressBookFields !! 833 enum AddressBookFields !!
833*/ 834*/
834QStringList OContact::fields() 835QStringList OContact::fields()
835{ 836{
836 QStringList list; 837 QStringList list;
837 838
838 list.append( "Title" ); // Not Used! 839 list.append( "Title" ); // Not Used!
839 list.append( "FirstName" ); 840 list.append( "FirstName" );
840 list.append( "MiddleName" ); 841 list.append( "MiddleName" );
841 list.append( "LastName" ); 842 list.append( "LastName" );
842 list.append( "Suffix" ); 843 list.append( "Suffix" );
843 list.append( "FileAs" ); 844 list.append( "FileAs" );
844 845
845 list.append( "JobTitle" ); 846 list.append( "JobTitle" );
846 list.append( "Department" ); 847 list.append( "Department" );
847 list.append( "Company" ); 848 list.append( "Company" );
848 list.append( "BusinessPhone" ); 849 list.append( "BusinessPhone" );
849 list.append( "BusinessFax" ); 850 list.append( "BusinessFax" );
850 list.append( "BusinessMobile" ); 851 list.append( "BusinessMobile" );
851 852
852 list.append( "DefaultEmail" ); 853 list.append( "DefaultEmail" );
853 list.append( "Emails" ); 854 list.append( "Emails" );
854 855
855 list.append( "HomePhone" ); 856 list.append( "HomePhone" );
856 list.append( "HomeFax" ); 857 list.append( "HomeFax" );
857 list.append( "HomeMobile" ); 858 list.append( "HomeMobile" );
858 859
859 list.append( "BusinessStreet" ); 860 list.append( "BusinessStreet" );
860 list.append( "BusinessCity" ); 861 list.append( "BusinessCity" );
861 list.append( "BusinessState" ); 862 list.append( "BusinessState" );
862 list.append( "BusinessZip" ); 863 list.append( "BusinessZip" );
863 list.append( "BusinessCountry" ); 864 list.append( "BusinessCountry" );
864 list.append( "BusinessPager" ); 865 list.append( "BusinessPager" );
865 list.append( "BusinessWebPage" ); 866 list.append( "BusinessWebPage" );
866 867
867 list.append( "Office" ); 868 list.append( "Office" );
868 list.append( "Profession" ); 869 list.append( "Profession" );
869 list.append( "Assistant" ); 870 list.append( "Assistant" );
870 list.append( "Manager" ); 871 list.append( "Manager" );
871 872
872 list.append( "HomeStreet" ); 873 list.append( "HomeStreet" );
873 list.append( "HomeCity" ); 874 list.append( "HomeCity" );
874 list.append( "HomeState" ); 875 list.append( "HomeState" );
875 list.append( "HomeZip" ); 876 list.append( "HomeZip" );
876 list.append( "HomeCountry" ); 877 list.append( "HomeCountry" );
877 list.append( "HomeWebPage" ); 878 list.append( "HomeWebPage" );
878 879
879 list.append( "Spouse" ); 880 list.append( "Spouse" );
880 list.append( "Gender" ); 881 list.append( "Gender" );
881 list.append( "Birthday" ); 882 list.append( "Birthday" );
882 list.append( "Anniversary" ); 883 list.append( "Anniversary" );
883 list.append( "Nickname" ); 884 list.append( "Nickname" );
884 list.append( "Children" ); 885 list.append( "Children" );
885 886
886 list.append( "Notes" ); 887 list.append( "Notes" );
887 list.append( "Groups" ); 888 list.append( "Groups" );
888 889
889 return list; 890 return list;
890} 891}
891 892
892 893
893/*! 894/*!
894 Sets the list of email address for contact to those contained in \a str. 895 Sets the list of email address for contact to those contained in \a str.
895 Email address should be separated by ';'s. 896 Email address should be separated by ';'s.
896*/ 897*/
897void OContact::setEmails( const QString &str ) 898void OContact::setEmails( const QString &str )
898{ 899{
899 replace( Qtopia::Emails, str ); 900 replace( Qtopia::Emails, str );
900 if ( str.isEmpty() ) 901 if ( str.isEmpty() )
901 setDefaultEmail( QString::null ); 902 setDefaultEmail( QString::null );
902} 903}
903 904
904/*! 905/*!
905 Sets the list of children for the contact to those contained in \a str. 906 Sets the list of children for the contact to those contained in \a str.
906*/ 907*/
907void OContact::setChildren( const QString &str ) 908void OContact::setChildren( const QString &str )
908{ 909{
909 replace( Qtopia::Children, str ); 910 replace( Qtopia::Children, str );
910} 911}
911 912
912/*! 913/*!
913 Returns TRUE if the contact matches the regular expression \a regexp. 914 Returns TRUE if the contact matches the regular expression \a regexp.
914 Otherwise returns FALSE. 915 Otherwise returns FALSE.
915*/ 916*/
916bool OContact::match( const QString &regexp ) const 917bool OContact::match( const QString &regexp ) const
917{ 918{
918 return match(QRegExp(regexp)); 919 return match(QRegExp(regexp));
919} 920}
920 921
921/*! 922/*!
922 \overload 923 \overload
923 Returns TRUE if the contact matches the regular expression \a regexp. 924 Returns TRUE if the contact matches the regular expression \a regexp.
924 Otherwise returns FALSE. 925 Otherwise returns FALSE.
925*/ 926*/
926bool OContact::match( const QRegExp &r ) const 927bool OContact::match( const QRegExp &r ) const
927{ 928{
928 bool match; 929 bool match;
929 match = false; 930 match = false;
930 QMap<int, QString>::ConstIterator it; 931 QMap<int, QString>::ConstIterator it;
931 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 932 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
932 if ( (*it).find( r ) > -1 ) { 933 if ( (*it).find( r ) > -1 ) {
933 match = true; 934 match = true;
934 break; 935 break;
935 } 936 }
936 } 937 }
937 return match; 938 return match;
938} 939}
939 940
940 941
941QString OContact::toShortText() const 942QString OContact::toShortText() const
942{ 943{
943 return ( fullName() ); 944 return ( fullName() );
944} 945}
945QString OContact::type() const 946QString OContact::type() const
946{ 947{
947 return QString::fromLatin1( "OContact" ); 948 return QString::fromLatin1( "OContact" );
948} 949}
949 950
950// Definition is missing ! (se) 951// Definition is missing ! (se)
951QMap<QString,QString> OContact::toExtraMap() const 952QMap<QString,QString> OContact::toExtraMap() const
952{ 953{
953 qWarning ("Function not implemented: OContact::toExtraMap()"); 954 qWarning ("Function not implemented: OContact::toExtraMap()");
954 QMap <QString,QString> useless; 955 QMap <QString,QString> useless;
955 return useless; 956 return useless;
956} 957}
957 958
958class QString OContact::recordField( int pos ) const 959class QString OContact::recordField( int pos ) const
959{ 960{
960 QStringList SLFIELDS = fields(); // ?? why this ? (se) 961 QStringList SLFIELDS = fields(); // ?? why this ? (se)
961 return SLFIELDS[pos]; 962 return SLFIELDS[pos];
962} 963}
963 964
964// In future releases, we should store birthday and anniversary 965// In future releases, we should store birthday and anniversary
965// internally as QDate instead of QString ! 966// internally as QDate instead of QString !
966// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 967// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
967 968
968/*! \fn void OContact::setBirthday( const QDate& date ) 969/*! \fn void OContact::setBirthday( const QDate& date )
969 Sets the birthday for the contact to \a date. If date is null 970 Sets the birthday for the contact to \a date. If date is null
970 the current stored date will be removed. 971 the current stored date will be removed.
971*/ 972*/
972void OContact::setBirthday( const QDate &v ) 973void OContact::setBirthday( const QDate &v )
973{ 974{
974 if ( v.isNull() ){ 975 if ( v.isNull() ){
975 qWarning( "Remove Birthday"); 976 qWarning( "Remove Birthday");
976 replace( Qtopia::Birthday, QString::null ); 977 replace( Qtopia::Birthday, QString::null );
977 return; 978 return;
978 } 979 }
979 980
980 if ( v.isValid() ) 981 if ( v.isValid() )
981 replace( Qtopia::Birthday, TimeConversion::toString( v ) ); 982 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
982 983
983} 984}
984 985
985 986
986/*! \fn void OContact::setAnniversary( const QDate &date ) 987/*! \fn void OContact::setAnniversary( const QDate &date )
987 Sets the anniversary of the contact to \a date. If date is 988 Sets the anniversary of the contact to \a date. If date is
988 null, the current stored date will be removed. 989 null, the current stored date will be removed.
989*/ 990*/
990void OContact::setAnniversary( const QDate &v ) 991void OContact::setAnniversary( const QDate &v )
991{ 992{
992 if ( v.isNull() ){ 993 if ( v.isNull() ){
993 qWarning( "Remove Anniversary"); 994 qWarning( "Remove Anniversary");
994 replace( Qtopia::Anniversary, QString::null ); 995 replace( Qtopia::Anniversary, QString::null );
995 return; 996 return;
996 } 997 }
997 998
998 if ( v.isValid() ) 999 if ( v.isValid() )
999 replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); 1000 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
1000} 1001}
1001 1002
1002/*! \fn QDate OContact::birthday() const 1003/*! \fn QDate OContact::birthday() const
1003 Returns the birthday of the contact. 1004 Returns the birthday of the contact.
1004*/ 1005*/
1005QDate OContact::birthday() const 1006QDate OContact::birthday() const
1006{ 1007{
1007 QString str = find( Qtopia::Birthday ); 1008 QString str = find( Qtopia::Birthday );
1008 qWarning ("Birthday %s", str.latin1() ); 1009 qWarning ("Birthday %s", str.latin1() );
1009 if ( !str.isEmpty() ) 1010 if ( !str.isEmpty() )
1010 return TimeConversion::fromString ( str ); 1011 return TimeConversion::fromString ( str );
1011 else 1012 else
1012 return QDate(); 1013 return QDate();
1013} 1014}
1014 1015
1015 1016
1016/*! \fn QDate OContact::anniversary() const 1017/*! \fn QDate OContact::anniversary() const
1017 Returns the anniversary of the contact. 1018 Returns the anniversary of the contact.
1018*/ 1019*/
1019QDate OContact::anniversary() const 1020QDate OContact::anniversary() const
1020{ 1021{
1021 QDate empty; 1022 QDate empty;
1022 QString str = find( Qtopia::Anniversary ); 1023 QString str = find( Qtopia::Anniversary );
1023 qWarning ("Anniversary %s", str.latin1() ); 1024 qWarning ("Anniversary %s", str.latin1() );
1024 if ( !str.isEmpty() ) 1025 if ( !str.isEmpty() )
1025 return TimeConversion::fromString ( str ); 1026 return TimeConversion::fromString ( str );
1026 else 1027 else
1027 return empty; 1028 return empty;
1028} 1029}
1029 1030
1030 1031
1031void OContact::insertEmail( const QString &v ) 1032void OContact::insertEmail( const QString &v )
1032{ 1033{
1033 //qDebug("insertEmail %s", v.latin1()); 1034 //qDebug("insertEmail %s", v.latin1());
1034 QString e = v.simplifyWhiteSpace(); 1035 QString e = v.simplifyWhiteSpace();
1035 QString def = defaultEmail(); 1036 QString def = defaultEmail();
1036 1037
1037 // if no default, set it as the default email and don't insert 1038 // if no default, set it as the default email and don't insert
1038 if ( def.isEmpty() ) { 1039 if ( def.isEmpty() ) {
1039 setDefaultEmail( e ); // will insert into the list for us 1040 setDefaultEmail( e ); // will insert into the list for us
1040 return; 1041 return;
1041 } 1042 }
1042 1043
1043 // otherwise, insert assuming doesn't already exist 1044 // otherwise, insert assuming doesn't already exist
1044 QString emailsStr = find( Qtopia::Emails ); 1045 QString emailsStr = find( Qtopia::Emails );
1045 if ( emailsStr.contains( e )) 1046 if ( emailsStr.contains( e ))
1046 return; 1047 return;
1047 if ( !emailsStr.isEmpty() ) 1048 if ( !emailsStr.isEmpty() )
1048 emailsStr += emailSeparator(); 1049 emailsStr += emailSeparator();
1049 emailsStr += e; 1050 emailsStr += e;
1050 replace( Qtopia::Emails, emailsStr ); 1051 replace( Qtopia::Emails, emailsStr );
1051} 1052}
1052 1053
1053void OContact::removeEmail( const QString &v ) 1054void OContact::removeEmail( const QString &v )
1054{ 1055{
1055 QString e = v.simplifyWhiteSpace(); 1056 QString e = v.simplifyWhiteSpace();
1056 QString def = defaultEmail(); 1057 QString def = defaultEmail();
1057 QString emailsStr = find( Qtopia::Emails ); 1058 QString emailsStr = find( Qtopia::Emails );
1058 QStringList emails = emailList(); 1059 QStringList emails = emailList();
1059 1060
1060 // otherwise, must first contain it 1061 // otherwise, must first contain it
1061 if ( !emailsStr.contains( e ) ) 1062 if ( !emailsStr.contains( e ) )
1062 return; 1063 return;
1063 1064
1064 // remove it 1065 // remove it
1065 //qDebug(" removing email from list %s", e.latin1()); 1066 //qDebug(" removing email from list %s", e.latin1());
1066 emails.remove( e ); 1067 emails.remove( e );
1067 // reset the string 1068 // reset the string
1068 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1069 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1069 replace( Qtopia::Emails, emailsStr ); 1070 replace( Qtopia::Emails, emailsStr );
1070 1071
1071 // if default, then replace the default email with the first one 1072 // if default, then replace the default email with the first one
1072 if ( def == e ) { 1073 if ( def == e ) {
1073 //qDebug("removeEmail is default; setting new default"); 1074 //qDebug("removeEmail is default; setting new default");
1074 if ( !emails.count() ) 1075 if ( !emails.count() )
1075 clearEmails(); 1076 clearEmails();
1076 else // setDefaultEmail will remove e from the list 1077 else // setDefaultEmail will remove e from the list
1077 setDefaultEmail( emails.first() ); 1078 setDefaultEmail( emails.first() );
1078 } 1079 }
1079} 1080}
1080void OContact::clearEmails() 1081void OContact::clearEmails()
1081{ 1082{
1082 mMap.remove( Qtopia::DefaultEmail ); 1083 mMap.remove( Qtopia::DefaultEmail );
1083 mMap.remove( Qtopia::Emails ); 1084 mMap.remove( Qtopia::Emails );
1084} 1085}
1085void OContact::setDefaultEmail( const QString &v ) 1086void OContact::setDefaultEmail( const QString &v )
1086{ 1087{
1087 QString e = v.simplifyWhiteSpace(); 1088 QString e = v.simplifyWhiteSpace();
1088 1089
1089 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1090 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1090 replace( Qtopia::DefaultEmail, e ); 1091 replace( Qtopia::DefaultEmail, e );
1091 1092
1092 if ( !e.isEmpty() ) 1093 if ( !e.isEmpty() )
1093 insertEmail( e ); 1094 insertEmail( e );
1094 1095
1095} 1096}
1096 1097
1097void OContact::insertEmails( const QStringList &v ) 1098void OContact::insertEmails( const QStringList &v )
1098{ 1099{
1099 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1100 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1100 insertEmail( *it ); 1101 insertEmail( *it );
1101} 1102}
1102int OContact::rtti() { 1103int OContact::rtti() {
1103 return 2; 1104 return OPimResolver::AddressBook;
1104} 1105}
1105void OContact::setUid( int i ) 1106void OContact::setUid( int i )
1106{ 1107{
1107 OPimRecord::setUid(i); 1108 OPimRecord::setUid(i);
1108 replace( Qtopia::AddressUid , QString::number(i)); 1109 replace( Qtopia::AddressUid , QString::number(i));
1109} 1110}
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp
index ece624a..cde2b3d 100644
--- a/libopie2/opiepim/otodo.cpp
+++ b/libopie2/opiepim/otodo.cpp
@@ -1,210 +1,211 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 18#include "opimnotifymanager.h"
19#include "opimresolver.h"
19 20
20#include "otodo.h" 21#include "otodo.h"
21 22
22 23
23struct OTodo::OTodoData : public QShared { 24struct OTodo::OTodoData : public QShared {
24 OTodoData() : QShared() { 25 OTodoData() : QShared() {
25 }; 26 };
26 27
27 QDate date; 28 QDate date;
28 bool isCompleted:1; 29 bool isCompleted:1;
29 bool hasDate:1; 30 bool hasDate:1;
30 int priority; 31 int priority;
31 QString desc; 32 QString desc;
32 QString sum; 33 QString sum;
33 QMap<QString, QString> extra; 34 QMap<QString, QString> extra;
34 ushort prog; 35 ushort prog;
35 OPimState state; 36 OPimState state;
36 ORecur recur; 37 ORecur recur;
37 OPimMaintainer maintainer; 38 OPimMaintainer maintainer;
38 QDate start; 39 QDate start;
39 QDate completed; 40 QDate completed;
40 OPimNotifyManager notifiers; 41 OPimNotifyManager notifiers;
41}; 42};
42 43
43OTodo::OTodo(const OTodo &event ) 44OTodo::OTodo(const OTodo &event )
44 : OPimRecord( event ), data( event.data ) 45 : OPimRecord( event ), data( event.data )
45{ 46{
46 data->ref(); 47 data->ref();
47// qWarning("ref up"); 48// qWarning("ref up");
48} 49}
49OTodo::~OTodo() { 50OTodo::~OTodo() {
50 51
51// qWarning("~OTodo " ); 52// qWarning("~OTodo " );
52 if ( data->deref() ) { 53 if ( data->deref() ) {
53// qWarning("OTodo::dereffing"); 54// qWarning("OTodo::dereffing");
54 delete data; 55 delete data;
55 data = 0l; 56 data = 0l;
56 } 57 }
57} 58}
58OTodo::OTodo(bool completed, int priority, 59OTodo::OTodo(bool completed, int priority,
59 const QArray<int> &category, 60 const QArray<int> &category,
60 const QString& summary, 61 const QString& summary,
61 const QString &description, 62 const QString &description,
62 ushort progress, 63 ushort progress,
63 bool hasDate, QDate date, int uid ) 64 bool hasDate, QDate date, int uid )
64 : OPimRecord( uid ) 65 : OPimRecord( uid )
65{ 66{
66// qWarning("OTodoData " + summary); 67// qWarning("OTodoData " + summary);
67 setCategories( category ); 68 setCategories( category );
68 69
69 data = new OTodoData; 70 data = new OTodoData;
70 71
71 data->date = date; 72 data->date = date;
72 data->isCompleted = completed; 73 data->isCompleted = completed;
73 data->hasDate = hasDate; 74 data->hasDate = hasDate;
74 data->priority = priority; 75 data->priority = priority;
75 data->sum = summary; 76 data->sum = summary;
76 data->prog = progress; 77 data->prog = progress;
77 data->desc = Qtopia::simplifyMultiLineSpace(description ); 78 data->desc = Qtopia::simplifyMultiLineSpace(description );
78} 79}
79OTodo::OTodo(bool completed, int priority, 80OTodo::OTodo(bool completed, int priority,
80 const QStringList &category, 81 const QStringList &category,
81 const QString& summary, 82 const QString& summary,
82 const QString &description, 83 const QString &description,
83 ushort progress, 84 ushort progress,
84 bool hasDate, QDate date, int uid ) 85 bool hasDate, QDate date, int uid )
85 : OPimRecord( uid ) 86 : OPimRecord( uid )
86{ 87{
87// qWarning("OTodoData" + summary); 88// qWarning("OTodoData" + summary);
88 setCategories( idsFromString( category.join(";") ) ); 89 setCategories( idsFromString( category.join(";") ) );
89 90
90 data = new OTodoData; 91 data = new OTodoData;
91 92
92 data->date = date; 93 data->date = date;
93 data->isCompleted = completed; 94 data->isCompleted = completed;
94 data->hasDate = hasDate; 95 data->hasDate = hasDate;
95 data->priority = priority; 96 data->priority = priority;
96 data->sum = summary; 97 data->sum = summary;
97 data->prog = progress; 98 data->prog = progress;
98 data->desc = Qtopia::simplifyMultiLineSpace(description ); 99 data->desc = Qtopia::simplifyMultiLineSpace(description );
99} 100}
100bool OTodo::match( const QRegExp &regExp )const 101bool OTodo::match( const QRegExp &regExp )const
101{ 102{
102 if( QString::number( data->priority ).find( regExp ) != -1 ){ 103 if( QString::number( data->priority ).find( regExp ) != -1 ){
103 return true; 104 return true;
104 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 105 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
105 return true; 106 return true;
106 }else if(data->desc.find( regExp ) != -1 ){ 107 }else if(data->desc.find( regExp ) != -1 ){
107 return true; 108 return true;
108 }else if(data->sum.find( regExp ) != -1 ) { 109 }else if(data->sum.find( regExp ) != -1 ) {
109 return true; 110 return true;
110 } 111 }
111 return false; 112 return false;
112} 113}
113bool OTodo::isCompleted() const 114bool OTodo::isCompleted() const
114{ 115{
115 return data->isCompleted; 116 return data->isCompleted;
116} 117}
117bool OTodo::hasDueDate() const 118bool OTodo::hasDueDate() const
118{ 119{
119 return data->hasDate; 120 return data->hasDate;
120} 121}
121bool OTodo::hasStartDate()const { 122bool OTodo::hasStartDate()const {
122 return data->start.isValid(); 123 return data->start.isValid();
123} 124}
124bool OTodo::hasCompletedDate()const { 125bool OTodo::hasCompletedDate()const {
125 return data->completed.isValid(); 126 return data->completed.isValid();
126} 127}
127int OTodo::priority()const 128int OTodo::priority()const
128{ 129{
129 return data->priority; 130 return data->priority;
130} 131}
131QString OTodo::summary() const 132QString OTodo::summary() const
132{ 133{
133 return data->sum; 134 return data->sum;
134} 135}
135ushort OTodo::progress() const 136ushort OTodo::progress() const
136{ 137{
137 return data->prog; 138 return data->prog;
138} 139}
139QDate OTodo::dueDate()const 140QDate OTodo::dueDate()const
140{ 141{
141 return data->date; 142 return data->date;
142} 143}
143QDate OTodo::startDate()const { 144QDate OTodo::startDate()const {
144 return data->start; 145 return data->start;
145} 146}
146QDate OTodo::completedDate()const { 147QDate OTodo::completedDate()const {
147 return data->completed; 148 return data->completed;
148} 149}
149QString OTodo::description()const 150QString OTodo::description()const
150{ 151{
151 return data->desc; 152 return data->desc;
152} 153}
153OPimState OTodo::state()const { 154OPimState OTodo::state()const {
154 return data->state; 155 return data->state;
155} 156}
156ORecur OTodo::recurrence()const { 157ORecur OTodo::recurrence()const {
157 return data->recur; 158 return data->recur;
158} 159}
159OPimMaintainer OTodo::maintainer()const { 160OPimMaintainer OTodo::maintainer()const {
160 return data->maintainer; 161 return data->maintainer;
161} 162}
162void OTodo::setCompleted( bool completed ) 163void OTodo::setCompleted( bool completed )
163{ 164{
164 changeOrModify(); 165 changeOrModify();
165 data->isCompleted = completed; 166 data->isCompleted = completed;
166} 167}
167void OTodo::setHasDueDate( bool hasDate ) 168void OTodo::setHasDueDate( bool hasDate )
168{ 169{
169 changeOrModify(); 170 changeOrModify();
170 data->hasDate = hasDate; 171 data->hasDate = hasDate;
171} 172}
172void OTodo::setDescription(const QString &desc ) 173void OTodo::setDescription(const QString &desc )
173{ 174{
174// qWarning( "desc " + desc ); 175// qWarning( "desc " + desc );
175 changeOrModify(); 176 changeOrModify();
176 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 177 data->desc = Qtopia::simplifyMultiLineSpace(desc );
177} 178}
178void OTodo::setSummary( const QString& sum ) 179void OTodo::setSummary( const QString& sum )
179{ 180{
180 changeOrModify(); 181 changeOrModify();
181 data->sum = sum; 182 data->sum = sum;
182} 183}
183void OTodo::setPriority(int prio ) 184void OTodo::setPriority(int prio )
184{ 185{
185 changeOrModify(); 186 changeOrModify();
186 data->priority = prio; 187 data->priority = prio;
187} 188}
188void OTodo::setDueDate( const QDate& date ) 189void OTodo::setDueDate( const QDate& date )
189{ 190{
190 changeOrModify(); 191 changeOrModify();
191 data->date = date; 192 data->date = date;
192} 193}
193void OTodo::setStartDate( const QDate& date ) { 194void OTodo::setStartDate( const QDate& date ) {
194 changeOrModify(); 195 changeOrModify();
195 data->start = date; 196 data->start = date;
196} 197}
197void OTodo::setCompletedDate( const QDate& date ) { 198void OTodo::setCompletedDate( const QDate& date ) {
198 changeOrModify(); 199 changeOrModify();
199 data->completed = date; 200 data->completed = date;
200} 201}
201void OTodo::setState( const OPimState& state ) { 202void OTodo::setState( const OPimState& state ) {
202 changeOrModify(); 203 changeOrModify();
203 data->state = state; 204 data->state = state;
204} 205}
205void OTodo::setRecurrence( const ORecur& rec) { 206void OTodo::setRecurrence( const ORecur& rec) {
206 changeOrModify(); 207 changeOrModify();
207 data->recur = rec; 208 data->recur = rec;
208} 209}
209void OTodo::setMaintainer( const OPimMaintainer& pim ) { 210void OTodo::setMaintainer( const OPimMaintainer& pim ) {
210 changeOrModify(); 211 changeOrModify();
@@ -228,194 +229,194 @@ QString OTodo::toShortText() const {
228 Returns a richt text string 229 Returns a richt text string
229*/ 230*/
230QString OTodo::toRichText() const 231QString OTodo::toRichText() const
231{ 232{
232 QString text; 233 QString text;
233 QStringList catlist; 234 QStringList catlist;
234 235
235 // Description of the todo 236 // Description of the todo
236 if ( !summary().isEmpty() ) { 237 if ( !summary().isEmpty() ) {
237 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 238 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
238 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 239 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
239 } 240 }
240 if( !description().isEmpty() ){ 241 if( !description().isEmpty() ){
241 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 242 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
242 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 243 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
243 } 244 }
244 text += "<br><br><br>"; 245 text += "<br><br><br>";
245 246
246 text += "<b>" + QObject::tr( "Priority:") +" </b>" 247 text += "<b>" + QObject::tr( "Priority:") +" </b>"
247 + QString::number( priority() ) + " <br>"; 248 + QString::number( priority() ) + " <br>";
248 text += "<b>" + QObject::tr( "Progress:") + " </b>" 249 text += "<b>" + QObject::tr( "Progress:") + " </b>"
249 + QString::number( progress() ) + " %<br>"; 250 + QString::number( progress() ) + " %<br>";
250 if (hasDueDate() ){ 251 if (hasDueDate() ){
251 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 252 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
252 text += dueDate().toString(); 253 text += dueDate().toString();
253 text += "<br>"; 254 text += "<br>";
254 } 255 }
255 256
256 text += "<b>" + QObject::tr( "Category:") + "</b> "; 257 text += "<b>" + QObject::tr( "Category:") + "</b> ";
257 text += categoryNames().join(", "); 258 text += categoryNames().join(", ");
258 text += "<br>"; 259 text += "<br>";
259 260
260 return text; 261 return text;
261} 262}
262OPimNotifyManager& OTodo::notifiers() { 263OPimNotifyManager& OTodo::notifiers() {
263 return data->notifiers; 264 return data->notifiers;
264} 265}
265 266
266bool OTodo::operator<( const OTodo &toDoEvent )const{ 267bool OTodo::operator<( const OTodo &toDoEvent )const{
267 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 268 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
268 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 269 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
269 if( hasDueDate() && toDoEvent.hasDueDate() ){ 270 if( hasDueDate() && toDoEvent.hasDueDate() ){
270 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 271 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
271 return priority() < toDoEvent.priority(); 272 return priority() < toDoEvent.priority();
272 }else{ 273 }else{
273 return dueDate() < toDoEvent.dueDate(); 274 return dueDate() < toDoEvent.dueDate();
274 } 275 }
275 } 276 }
276 return false; 277 return false;
277} 278}
278bool OTodo::operator<=(const OTodo &toDoEvent )const 279bool OTodo::operator<=(const OTodo &toDoEvent )const
279{ 280{
280 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 281 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
281 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 282 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
282 if( hasDueDate() && toDoEvent.hasDueDate() ){ 283 if( hasDueDate() && toDoEvent.hasDueDate() ){
283 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 284 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
284 return priority() <= toDoEvent.priority(); 285 return priority() <= toDoEvent.priority();
285 }else{ 286 }else{
286 return dueDate() <= toDoEvent.dueDate(); 287 return dueDate() <= toDoEvent.dueDate();
287 } 288 }
288 } 289 }
289 return true; 290 return true;
290} 291}
291bool OTodo::operator>(const OTodo &toDoEvent )const 292bool OTodo::operator>(const OTodo &toDoEvent )const
292{ 293{
293 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 294 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
294 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 295 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
295 if( hasDueDate() && toDoEvent.hasDueDate() ){ 296 if( hasDueDate() && toDoEvent.hasDueDate() ){
296 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 297 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
297 return priority() > toDoEvent.priority(); 298 return priority() > toDoEvent.priority();
298 }else{ 299 }else{
299 return dueDate() > toDoEvent.dueDate(); 300 return dueDate() > toDoEvent.dueDate();
300 } 301 }
301 } 302 }
302 return false; 303 return false;
303} 304}
304bool OTodo::operator>=(const OTodo &toDoEvent )const 305bool OTodo::operator>=(const OTodo &toDoEvent )const
305{ 306{
306 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 307 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
307 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 308 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
308 if( hasDueDate() && toDoEvent.hasDueDate() ){ 309 if( hasDueDate() && toDoEvent.hasDueDate() ){
309 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 310 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
310 return priority() > toDoEvent.priority(); 311 return priority() > toDoEvent.priority();
311 }else{ 312 }else{
312 return dueDate() > toDoEvent.dueDate(); 313 return dueDate() > toDoEvent.dueDate();
313 } 314 }
314 } 315 }
315 return true; 316 return true;
316} 317}
317bool OTodo::operator==(const OTodo &toDoEvent )const 318bool OTodo::operator==(const OTodo &toDoEvent )const
318{ 319{
319 if ( data->priority != toDoEvent.data->priority ) return false; 320 if ( data->priority != toDoEvent.data->priority ) return false;
320 if ( data->priority != toDoEvent.data->prog ) return false; 321 if ( data->priority != toDoEvent.data->prog ) return false;
321 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 322 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
322 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 323 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
323 if ( data->date != toDoEvent.data->date ) return false; 324 if ( data->date != toDoEvent.data->date ) return false;
324 if ( data->sum != toDoEvent.data->sum ) return false; 325 if ( data->sum != toDoEvent.data->sum ) return false;
325 if ( data->desc != toDoEvent.data->desc ) return false; 326 if ( data->desc != toDoEvent.data->desc ) return false;
326 if ( data->maintainer != toDoEvent.data->maintainer ) 327 if ( data->maintainer != toDoEvent.data->maintainer )
327 return false; 328 return false;
328 329
329 return OPimRecord::operator==( toDoEvent ); 330 return OPimRecord::operator==( toDoEvent );
330} 331}
331void OTodo::deref() { 332void OTodo::deref() {
332 333
333// qWarning("deref in ToDoEvent"); 334// qWarning("deref in ToDoEvent");
334 if ( data->deref() ) { 335 if ( data->deref() ) {
335// qWarning("deleting"); 336// qWarning("deleting");
336 delete data; 337 delete data;
337 data= 0; 338 data= 0;
338 } 339 }
339} 340}
340OTodo &OTodo::operator=(const OTodo &item ) 341OTodo &OTodo::operator=(const OTodo &item )
341{ 342{
342 OPimRecord::operator=( item ); 343 OPimRecord::operator=( item );
343 //qWarning("operator= ref "); 344 //qWarning("operator= ref ");
344 item.data->ref(); 345 item.data->ref();
345 deref(); 346 deref();
346 data = item.data; 347 data = item.data;
347 348
348 return *this; 349 return *this;
349} 350}
350 351
351QMap<int, QString> OTodo::toMap() const { 352QMap<int, QString> OTodo::toMap() const {
352 QMap<int, QString> map; 353 QMap<int, QString> map;
353 354
354 map.insert( Uid, QString::number( uid() ) ); 355 map.insert( Uid, QString::number( uid() ) );
355 map.insert( Category, idsToString( categories() ) ); 356 map.insert( Category, idsToString( categories() ) );
356 map.insert( HasDate, QString::number( data->hasDate ) ); 357 map.insert( HasDate, QString::number( data->hasDate ) );
357 map.insert( Completed, QString::number( data->isCompleted ) ); 358 map.insert( Completed, QString::number( data->isCompleted ) );
358 map.insert( Description, data->desc ); 359 map.insert( Description, data->desc );
359 map.insert( Summary, data->sum ); 360 map.insert( Summary, data->sum );
360 map.insert( Priority, QString::number( data->priority ) ); 361 map.insert( Priority, QString::number( data->priority ) );
361 map.insert( DateDay, QString::number( data->date.day() ) ); 362 map.insert( DateDay, QString::number( data->date.day() ) );
362 map.insert( DateMonth, QString::number( data->date.month() ) ); 363 map.insert( DateMonth, QString::number( data->date.month() ) );
363 map.insert( DateYear, QString::number( data->date.year() ) ); 364 map.insert( DateYear, QString::number( data->date.year() ) );
364 map.insert( Progress, QString::number( data->prog ) ); 365 map.insert( Progress, QString::number( data->prog ) );
365// map.insert( CrossReference, crossToString() ); 366// map.insert( CrossReference, crossToString() );
366 /* FIXME!!! map.insert( State, ); 367 /* FIXME!!! map.insert( State, );
367 map.insert( Recurrence, ); 368 map.insert( Recurrence, );
368 map.insert( Reminders, ); 369 map.insert( Reminders, );
369 map. 370 map.
370 */ 371 */
371 return map; 372 return map;
372} 373}
373 374
374QMap<QString, QString> OTodo::toExtraMap()const { 375QMap<QString, QString> OTodo::toExtraMap()const {
375 return data->extra; 376 return data->extra;
376} 377}
377/** 378/**
378 * change or modify looks at the ref count and either 379 * change or modify looks at the ref count and either
379 * creates a new QShared Object or it can modify it 380 * creates a new QShared Object or it can modify it
380 * right in place 381 * right in place
381 */ 382 */
382void OTodo::changeOrModify() { 383void OTodo::changeOrModify() {
383 if ( data->count != 1 ) { 384 if ( data->count != 1 ) {
384 qWarning("changeOrModify"); 385 qWarning("changeOrModify");
385 data->deref(); 386 data->deref();
386 OTodoData* d2 = new OTodoData(); 387 OTodoData* d2 = new OTodoData();
387 copy(data, d2 ); 388 copy(data, d2 );
388 data = d2; 389 data = d2;
389 } 390 }
390} 391}
391// WATCHOUT 392// WATCHOUT
392/* 393/*
393 * if you add something to the Data struct 394 * if you add something to the Data struct
394 * be sure to copy it here 395 * be sure to copy it here
395 */ 396 */
396void OTodo::copy( OTodoData* src, OTodoData* dest ) { 397void OTodo::copy( OTodoData* src, OTodoData* dest ) {
397 dest->date = src->date; 398 dest->date = src->date;
398 dest->isCompleted = src->isCompleted; 399 dest->isCompleted = src->isCompleted;
399 dest->hasDate = src->hasDate; 400 dest->hasDate = src->hasDate;
400 dest->priority = src->priority; 401 dest->priority = src->priority;
401 dest->desc = src->desc; 402 dest->desc = src->desc;
402 dest->sum = src->sum; 403 dest->sum = src->sum;
403 dest->extra = src->extra; 404 dest->extra = src->extra;
404 dest->prog = src->prog; 405 dest->prog = src->prog;
405 dest->state = src->state; 406 dest->state = src->state;
406 dest->recur = src->recur; 407 dest->recur = src->recur;
407 dest->maintainer = src->maintainer; 408 dest->maintainer = src->maintainer;
408 dest->start = src->start; 409 dest->start = src->start;
409 dest->completed = src->completed; 410 dest->completed = src->completed;
410 dest->notifiers = src->notifiers; 411 dest->notifiers = src->notifiers;
411} 412}
412QString OTodo::type() const { 413QString OTodo::type() const {
413 return QString::fromLatin1("OTodo"); 414 return QString::fromLatin1("OTodo");
414} 415}
415QString OTodo::recordField(int /*id*/ )const { 416QString OTodo::recordField(int /*id*/ )const {
416 return QString::null; 417 return QString::null;
417} 418}
418 419
419int OTodo::rtti(){ 420int OTodo::rtti(){
420 return 1; 421 return OPimResolver::TodoList;
421} 422}
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp
index 92be2fd..7e57f3a 100644
--- a/libopie2/opiepim/ui/opimmainwindow.cpp
+++ b/libopie2/opiepim/ui/opimmainwindow.cpp
@@ -1,71 +1,105 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <qcopchannel_qws.h> 2#include <qcopchannel_qws.h>
3 3
4#include <qpe/qcopenvelope_qws.h> 4#include <qpe/qcopenvelope_qws.h>
5 5
6#include "opimresolver.h"
6#include "opimmainwindow.h" 7#include "opimmainwindow.h"
7 8
8OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, 9OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent,
9 const char* name, WFlags flag ) 10 const char* name, WFlags flag )
10 : QMainWindow( parent, name, flag ), m_service( service ), m_fallBack(0l) { 11 : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) {
11 12
12 /* 13 /*
13 * let's generate our QCopChannel 14 * let's generate our QCopChannel
14 */ 15 */
15 m_str = QString("QPE/"+m_service).local8Bit(); 16 m_str = QString("QPE/"+m_service).local8Bit();
16 m_channel= new QCopChannel(m_str, this ); 17 m_channel= new QCopChannel(m_str, this );
17 connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), 18 connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ),
18 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); 19 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
19 20
20 /* connect flush and reload */ 21 /* connect flush and reload */
21 connect(qApp, SIGNAL(flush() ), 22 connect(qApp, SIGNAL(flush() ),
22 this, SLOT(flush() ) ); 23 this, SLOT(flush() ) );
23 connect(qApp, SIGNAL(reload() ), 24 connect(qApp, SIGNAL(reload() ),
24 this, SLOT(reload() ) ); 25 this, SLOT(reload() ) );
25} 26}
26OPimMainWindow::~OPimMainWindow() { 27OPimMainWindow::~OPimMainWindow() {
27 delete m_channel; 28 delete m_channel;
28} 29}
29QCopChannel* OPimMainWindow::channel() { 30QCopChannel* OPimMainWindow::channel() {
30 return m_channel; 31 return m_channel;
31} 32}
33void OPimMainWindow::doSetDocument( const QString& ) {
34
35}
32void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { 36void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) {
33 /* 37 /*
34 * create demands to create 38 * create demands to create
35 * a new record... 39 * a new record...
36 */ 40 */
37 QDataStream stream(array, IO_ReadOnly); 41 QDataStream stream(array, IO_ReadOnly);
38 if ( cmd == "create()" ) { 42 if ( cmd == "create()" ) {
39 int uid = create(); 43 int uid = create();
40 QCopEnvelope e(m_str, "created(int)" ); 44 QCopEnvelope e(m_str, "created(int)" );
41 e << uid; 45 e << uid;
42 }else if ( cmd == "remove(int)" ) { 46 }else if ( cmd == "remove(int)" ) {
43 int uid; 47 int uid;
44 stream >> uid; 48 stream >> uid;
45 bool rem = remove( uid ); 49 bool rem = remove( uid );
46 QCopEnvelope e(m_str, "removed(bool)" ); 50 QCopEnvelope e(m_str, "removed(bool)" );
47 e << rem; 51 e << rem;
48 }else if ( cmd == "beam(int,int)" ) { 52 }else if ( cmd == "beam(int,int)" ) {
49 int uid, trans; 53 int uid, trans;
50 stream >> uid; 54 stream >> uid;
51 stream >> trans; 55 stream >> trans;
52 beam( uid, trans ); 56 beam( uid, trans );
53 }else if ( cmd == "show(int)" ) { 57 }else if ( cmd == "show(int)" ) {
54 int uid; 58 int uid;
55 stream >> uid; 59 stream >> uid;
56 show( uid ); 60 show( uid );
57 }else if ( cmd == "edit(int)" ) { 61 }else if ( cmd == "edit(int)" ) {
58 int uid; 62 int uid;
59 stream >> uid; 63 stream >> uid;
60 edit( uid ); 64 edit( uid );
61 }else if ( cmd == "add(int,QByteArray)" ) { 65 }else if ( cmd == "add(int,QByteArray)" ) {
62 int rtti; 66 int rtti;
63 QByteArray array; 67 QByteArray array;
64 stream >> rtti; 68 stream >> rtti;
65 stream >> array; 69 stream >> array;
66 m_fallBack = record(rtti, array ); 70 m_fallBack = record(rtti, array );
67 if (!m_fallBack) return; 71 if (!m_fallBack) return;
68 add( *m_fallBack ); 72 add( *m_fallBack );
69 delete m_fallBack; 73 delete m_fallBack;
70 } 74 }
71} 75}
76/* implement the url scripting here */
77void OPimMainWindow::setDocument( const QString& str) {
78 doSetDocument( str );
79}
80/*
81 * we now try to get the array demarshalled
82 * check if the rtti matches this one
83 */
84OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) {
85 if ( service() != rtti )
86 return 0l;
87
88 OPimRecord* record = OPimResolver::self()->record( rtti );
89 QDataStream str(array, IO_ReadOnly );
90 if ( !record || !record->loadFromStream(str) ) {
91 delete record;
92 record = 0l;
93 }
94
95 return record;
96}
97/*
98 * get the rtti for the service
99 */
100int OPimMainWindow::service() {
101 if ( m_rtti == -1 )
102 m_rtti = OPimResolver::self()->serviceId( m_service );
103
104 return m_rtti;
105}
diff --git a/libopie2/opiepim/ui/opimmainwindow.h b/libopie2/opiepim/ui/opimmainwindow.h
index 94100bd..34b8a71 100644
--- a/libopie2/opiepim/ui/opimmainwindow.h
+++ b/libopie2/opiepim/ui/opimmainwindow.h
@@ -1,79 +1,89 @@
1#ifndef OPIE_PIM_MAINWINDOW_H 1#ifndef OPIE_PIM_MAINWINDOW_H
2#define OPIE_PIM_MAINWINDOW_H 2#define OPIE_PIM_MAINWINDOW_H
3 3
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5 5
6#include <opie/opimrecord.h> 6#include <opie/opimrecord.h>
7 7
8/** 8/**
9 * This is a common Opie PIM MainWindow 9 * This is a common Opie PIM MainWindow
10 * it takes care of the QCOP internals 10 * it takes care of the QCOP internals
11 * and implements some functions 11 * and implements some functions
12 * for the URL scripting schema 12 * for the URL scripting schema
13 */ 13 */
14/* 14/*
15 * due Qt and Templates with signal and slots 15 * due Qt and Templates with signal and slots
16 * do not work that good :( 16 * do not work that good :(
17 * (Ok how to moc a template ;) ) 17 * (Ok how to moc a template ;) )
18 * We will have the mainwindow which calls a struct which 18 * We will have the mainwindow which calls a struct which
19 * is normally reimplemented as a template ;) 19 * is normally reimplemented as a template ;)
20 */ 20 */
21 21
22class QCopChannel; 22class QCopChannel;
23class OPimMainWindow : public QMainWindow { 23class OPimMainWindow : public QMainWindow {
24 Q_OBJECT 24 Q_OBJECT
25public: 25public:
26 enum TransPort { BlueTooth=0, 26 enum TransPort { BlueTooth=0,
27 IrDa }; 27 IrDa };
28 28
29 OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, 29 OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0,
30 WFlags f = WType_TopLevel); 30 WFlags f = WType_TopLevel);
31 virtual ~OPimMainWindow(); 31 virtual ~OPimMainWindow();
32 32
33 33
34protected slots: 34protected slots:
35 /*
36 * called when a setDocument
37 * couldn't be handled by this window
38 */
39 virtual void doSetDocument( const QString& );
35 /* for syncing */ 40 /* for syncing */
36 virtual void flush() = 0; 41 virtual void flush() = 0;
37 virtual void reload() = 0; 42 virtual void reload() = 0;
38 43
39 /** create a new Records and return the uid */ 44 /** create a new Records and return the uid */
40 virtual int create() = 0; 45 virtual int create() = 0;
41 /** remove a record with UID == uid */ 46 /** remove a record with UID == uid */
42 virtual bool remove( int uid ) = 0; 47 virtual bool remove( int uid ) = 0;
43 /** beam the record with UID = uid */ 48 /** beam the record with UID = uid */
44 virtual void beam( int uid , int transport = IrDa) = 0; 49 virtual void beam( int uid , int transport = IrDa) = 0;
45 50
46 /** show the record with UID == uid */ 51 /** show the record with UID == uid */
47 virtual void show( int uid ) = 0; 52 virtual void show( int uid ) = 0;
48 /** edit the record */ 53 /** edit the record */
49 virtual void edit( int uid ) = 0; 54 virtual void edit( int uid ) = 0;
50 55
51 /** make a copy of it! */ 56 /** make a copy of it! */
52 virtual void add( const OPimRecord& ) = 0; 57 virtual void add( const OPimRecord& ) = 0;
53 58
54 /* I would love to do this as a template 59
55 * but can't think of a right way
56 * because I need signal and slots -zecke
57 */
58 /*
59 * the only pointer in the whole PIM API :(
60 */
61 virtual OPimRecord* record( int rtti, const QByteArray& ) = 0;
62 QCopChannel* channel(); 60 QCopChannel* channel();
63 61
64private slots: 62private slots:
65 void appMessage( const QCString&, const QByteArray& ); 63 void appMessage( const QCString&, const QByteArray& );
64 void setDocument( const QString& );
66 65
67 66
68private: 67private:
69 class Private; 68 class Private;
70 Private* d; 69 Private* d;
71 70
71 int m_rtti;
72 QCopChannel* m_channel; 72 QCopChannel* m_channel;
73 QString m_service; 73 QString m_service;
74 QCString m_str; 74 QCString m_str;
75 OPimRecord* m_fallBack; 75 OPimRecord* m_fallBack;
76
77 /* I would love to do this as a template
78 * but can't think of a right way
79 * because I need signal and slots -zecke
80 */
81 /*
82 * the only pointer in the whole PIM API :(
83 */
84 virtual OPimRecord* record( int rtti, const QByteArray& ) ;
85 int service();
76}; 86};
77 87
78 88
79#endif 89#endif