summaryrefslogtreecommitdiff
path: root/noncore/unsupported/libopie/pim/opimrecord.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/libopie/pim/opimrecord.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/libopie/pim/opimrecord.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/opimrecord.cpp b/noncore/unsupported/libopie/pim/opimrecord.cpp
new file mode 100644
index 0000000..2365748
--- a/dev/null
+++ b/noncore/unsupported/libopie/pim/opimrecord.cpp
@@ -0,0 +1,182 @@
1#include <qarray.h>
2
3#include <qpe/categories.h>
4#include <qpe/categoryselect.h>
5
6#include "opimrecord.h"
7
8Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
9
10
11OPimRecord::OPimRecord( int uid )
12 : Qtopia::Record() {
13
14 m_lastHit = -1;
15 setUid( uid );
16}
17OPimRecord::~OPimRecord() {
18}
19OPimRecord::OPimRecord( const OPimRecord& rec )
20 : Qtopia::Record( rec )
21{
22 (*this) = rec;
23}
24
25OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
26 if ( this == &rec ) return *this;
27
28 Qtopia::Record::operator=( rec );
29 m_xrefman = rec.m_xrefman;
30 m_lastHit = rec.m_lastHit;
31
32 return *this;
33}
34/*
35 * category names
36 */
37QStringList OPimRecord::categoryNames( const QString& appname ) const {
38 QStringList list;
39 QArray<int> cats = categories();
40 Categories catDB;
41 catDB.load( categoryFileName() );
42
43 for (uint i = 0; i < cats.count(); i++ ) {
44 list << catDB.label( appname, cats[i] );
45 }
46
47 return list;
48}
49void OPimRecord::setCategoryNames( const QStringList& ) {
50
51}
52void OPimRecord::addCategoryName( const QString& ) {
53 Categories catDB;
54 catDB.load( categoryFileName() );
55
56
57}
58bool OPimRecord::isEmpty()const {
59 return ( uid() == 0 );
60}
61/*QString OPimRecord::crossToString()const {
62 QString str;
63 QMap<QString, QArray<int> >::ConstIterator it;
64 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
65 QArray<int> id = it.data();
66 for ( uint i = 0; i < id.size(); ++i ) {
67 str += it.key() + "," + QString::number( i ) + ";";
68 }
69 }
70 str = str.remove( str.length()-1, 1); // strip the ;
71 //qWarning("IDS " + str );
72
73 return str;
74 }*/
75/* if uid = 1 assign a new one */
76void OPimRecord::setUid( int uid ) {
77 if ( uid == 1)
78 uid = uidGen().generate();
79
80 Qtopia::Record::setUid( uid );
81};
82Qtopia::UidGen &OPimRecord::uidGen() {
83 return m_uidGen;
84}
85OPimXRefManager &OPimRecord::xrefmanager() {
86 return m_xrefman;
87}
88int OPimRecord::rtti(){
89 return 0;
90}
91
92/**
93 * now let's put our data into the stream
94 */
95/*
96 * First read UID
97 * Categories
98 * XRef
99 */
100bool OPimRecord::loadFromStream( QDataStream& stream ) {
101 int Int;
102 uint UInt;
103 stream >> Int;
104 setUid(Int);
105
106 /** Categories */
107 stream >> UInt;
108 QArray<int> array(UInt);
109 for (uint i = 0; i < UInt; i++ ) {
110 stream >> array[i];
111 }
112 setCategories( array );
113
114 /*
115 * now we do the X-Ref stuff
116 */
117 OPimXRef xref;
118 stream >> UInt;
119 for ( uint i = 0; i < UInt; i++ ) {
120 xref.setPartner( OPimXRef::One, partner( stream ) );
121 xref.setPartner( OPimXRef::Two, partner( stream ) );
122 m_xrefman.add( xref );
123 }
124
125 return true;
126}
127bool OPimRecord::saveToStream( QDataStream& stream )const {
128 /** UIDs */
129
130 stream << uid();
131
132 /** Categories */
133 stream << categories().count();
134 for ( uint i = 0; i < categories().count(); i++ ) {
135 stream << categories()[i];
136 }
137
138 /*
139 * first the XRef count
140 * then the xrefs
141 */
142 stream << m_xrefman.list().count();
143 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
144 it != m_xrefman.list().end(); ++it ) {
145 flush( (*it).partner( OPimXRef::One), stream );
146 flush( (*it).partner( OPimXRef::Two), stream );
147 }
148 return true;
149}
150void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{
151 str << par.service();
152 str << par.uid();
153 str << par.field();
154}
155OPimXRefPartner OPimRecord::partner( QDataStream& stream ) {
156 OPimXRefPartner par;
157 QString str;
158 int i;
159
160 stream >> str;
161 par.setService( str );
162
163 stream >> i;
164 par.setUid( i );
165
166 stream >> i ;
167 par.setField( i );
168
169 return par;
170}
171void OPimRecord::setLastHitField( int lastHit )const {
172 m_lastHit = lastHit;
173}
174int OPimRecord::lastHitField()const{
175 return m_lastHit;
176}
177QMap<QString, QString> OPimRecord::toExtraMap()const {
178 return customMap;
179}
180void OPimRecord::setExtraMap( const QMap<QString, QString>& map) {
181 customMap = map;
182}