author | mickeyl <mickeyl> | 2004-11-16 19:14:18 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-11-16 19:14:18 (UTC) |
commit | ea3945a9bd8f9830f70b1efa133f9df13b19362f (patch) (unidiff) | |
tree | f2ea22cc50e9aa8aa73ee7dea148f41c563c9666 /noncore/unsupported/libopie/pim/opimrecord.cpp | |
parent | 1c6f490e8541626f68422e0a3a7c7281d7f5b7d3 (diff) | |
download | opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.zip opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.gz opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.bz2 |
libopie1 goes into unsupported
Diffstat (limited to 'noncore/unsupported/libopie/pim/opimrecord.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/libopie/pim/opimrecord.cpp | 182 |
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 | |||
8 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | ||
9 | |||
10 | |||
11 | OPimRecord::OPimRecord( int uid ) | ||
12 | : Qtopia::Record() { | ||
13 | |||
14 | m_lastHit = -1; | ||
15 | setUid( uid ); | ||
16 | } | ||
17 | OPimRecord::~OPimRecord() { | ||
18 | } | ||
19 | OPimRecord::OPimRecord( const OPimRecord& rec ) | ||
20 | : Qtopia::Record( rec ) | ||
21 | { | ||
22 | (*this) = rec; | ||
23 | } | ||
24 | |||
25 | OPimRecord &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 | */ | ||
37 | QStringList 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 | } | ||
49 | void OPimRecord::setCategoryNames( const QStringList& ) { | ||
50 | |||
51 | } | ||
52 | void OPimRecord::addCategoryName( const QString& ) { | ||
53 | Categories catDB; | ||
54 | catDB.load( categoryFileName() ); | ||
55 | |||
56 | |||
57 | } | ||
58 | bool 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 */ | ||
76 | void OPimRecord::setUid( int uid ) { | ||
77 | if ( uid == 1) | ||
78 | uid = uidGen().generate(); | ||
79 | |||
80 | Qtopia::Record::setUid( uid ); | ||
81 | }; | ||
82 | Qtopia::UidGen &OPimRecord::uidGen() { | ||
83 | return m_uidGen; | ||
84 | } | ||
85 | OPimXRefManager &OPimRecord::xrefmanager() { | ||
86 | return m_xrefman; | ||
87 | } | ||
88 | int 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 | */ | ||
100 | bool 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 | } | ||
127 | bool 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 | } | ||
150 | void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ | ||
151 | str << par.service(); | ||
152 | str << par.uid(); | ||
153 | str << par.field(); | ||
154 | } | ||
155 | OPimXRefPartner 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 | } | ||
171 | void OPimRecord::setLastHitField( int lastHit )const { | ||
172 | m_lastHit = lastHit; | ||
173 | } | ||
174 | int OPimRecord::lastHitField()const{ | ||
175 | return m_lastHit; | ||
176 | } | ||
177 | QMap<QString, QString> OPimRecord::toExtraMap()const { | ||
178 | return customMap; | ||
179 | } | ||
180 | void OPimRecord::setExtraMap( const QMap<QString, QString>& map) { | ||
181 | customMap = map; | ||
182 | } | ||