-rw-r--r-- | libopie/pim/opimrecord.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
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 +1,3 @@ | |||
1 | #include <qarray.h> | ||
2 | |||
1 | #include <qpe/categories.h> | 3 | #include <qpe/categories.h> |
@@ -84 +86,81 @@ int OPimRecord::rtti(){ | |||
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 | */ | ||
96 | bool 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 | } | ||
123 | bool 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 | } | ||
146 | void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ | ||
147 | str << par.service(); | ||
148 | str << par.uid(); | ||
149 | str << par.field(); | ||
150 | } | ||
151 | OPimXRefPartner 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 | } | ||