00001 /* 00002 This file is part of the Opie Project 00003 Copyright (C) The Main Author <main-author@whereever.org> 00004 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 00005 .=l. 00006 .>+-= 00007 _;:, .> :=|. This program is free software; you can 00008 .> <`_, > . <= redistribute it and/or modify it under 00009 :`=1 )Y*s>-.-- : the terms of the GNU Library General Public 00010 .="- .-=="i, .._ License as published by the Free Software 00011 - . .-<_> .<> Foundation; either version 2 of the License, 00012 ._= =} : or (at your option) any later version. 00013 .%`+i> _;_. 00014 .i_,=:_. -<s. This program is distributed in the hope that 00015 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 00016 : .. .:, . . . without even the implied warranty of 00017 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 00018 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 00019 ..}^=.= = ; Library General Public License for more 00020 ++= -. .` .: details. 00021 : = ...= . :.=- 00022 -. .:....=;==+<; You should have received a copy of the GNU 00023 -_. . . )=. = Library General Public License along with 00024 -- :-=` this library; see the file COPYING.LIB. 00025 If not, write to the Free Software Foundation, 00026 Inc., 59 Temple Place - Suite 330, 00027 Boston, MA 02111-1307, USA. 00028 */ 00029 00030 #include "opimrecord.h" 00031 00032 /* OPIE */ 00033 #include <qpe/categories.h> 00034 #include <qpe/categoryselect.h> 00035 00036 /* QT */ 00037 00038 namespace Opie 00039 { 00040 Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 00041 00042 00043 OPimRecord::OPimRecord( int uid ) 00044 : Qtopia::Record() 00045 { 00046 00047 m_lastHit = -1; 00048 setUid( uid ); 00049 } 00050 00051 00052 OPimRecord::~OPimRecord() 00053 {} 00054 00055 00056 OPimRecord::OPimRecord( const OPimRecord& rec ) 00057 : Qtopia::Record( rec ) 00058 { 00059 ( *this ) = rec; 00060 } 00061 00062 00063 OPimRecord &OPimRecord::operator=( const OPimRecord& rec ) 00064 { 00065 if ( this == &rec ) return * this; 00066 00067 Qtopia::Record::operator=( rec ); 00068 m_xrefman = rec.m_xrefman; 00069 m_lastHit = rec.m_lastHit; 00070 00071 return *this; 00072 } 00073 00074 00075 /* 00076 * category names 00077 */ 00078 QStringList OPimRecord::categoryNames( const QString& appname ) const 00079 { 00080 QStringList list; 00081 QArray<int> cats = categories(); 00082 Categories catDB; 00083 catDB.load( categoryFileName() ); 00084 00085 for ( uint i = 0; i < cats.count(); i++ ) 00086 { 00087 list << catDB.label( appname, cats[ i ] ); 00088 } 00089 00090 return list; 00091 } 00092 00093 00094 void OPimRecord::setCategoryNames( const QStringList& ) 00095 { 00096 } 00097 00098 00099 void OPimRecord::addCategoryName( const QString& ) 00100 { 00101 Categories catDB; 00102 catDB.load( categoryFileName() ); 00103 } 00104 00105 00106 bool OPimRecord::isEmpty() const 00107 { 00108 return ( uid() == 0 ); 00109 } 00110 00111 00112 /* if uid = 1 assign a new one */ 00113 void OPimRecord::setUid( int uid ) 00114 { 00115 if ( uid == 1 ) 00116 uid = uidGen().generate(); 00117 00118 Qtopia::Record::setUid( uid ); 00119 }; 00120 00121 00122 Qtopia::UidGen &OPimRecord::uidGen() 00123 { 00124 return m_uidGen; 00125 } 00126 00127 00128 OPimXRefManager &OPimRecord::xrefmanager() 00129 { 00130 return m_xrefman; 00131 } 00132 00133 00134 int OPimRecord::rtti() const 00135 { 00136 return 0; 00137 } 00138 00142 /* 00143 * First read UID 00144 * Categories 00145 * XRef 00146 */ 00147 bool OPimRecord::loadFromStream( QDataStream& stream ) 00148 { 00149 int Int; 00150 uint UInt; 00151 stream >> Int; 00152 setUid( Int ); 00153 00155 stream >> UInt; 00156 QArray<int> array( UInt ); 00157 for ( uint i = 0; i < UInt; i++ ) 00158 { 00159 stream >> array[ i ]; 00160 } 00161 setCategories( array ); 00162 00163 /* 00164 * now we do the X-Ref stuff 00165 */ 00166 OPimXRef xref; 00167 stream >> UInt; 00168 for ( uint i = 0; i < UInt; i++ ) 00169 { 00170 xref.setPartner( OPimXRef::One, partner( stream ) ); 00171 xref.setPartner( OPimXRef::Two, partner( stream ) ); 00172 m_xrefman.add( xref ); 00173 } 00174 00175 return true; 00176 } 00177 00178 00179 bool OPimRecord::saveToStream( QDataStream& stream ) const 00180 { 00183 stream << uid(); 00184 00186 stream << categories().count(); 00187 for ( uint i = 0; i < categories().count(); i++ ) 00188 { 00189 stream << categories() [ i ]; 00190 } 00191 00192 /* 00193 * first the XRef count 00194 * then the xrefs 00195 */ 00196 stream << m_xrefman.list().count(); 00197 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); 00198 it != m_xrefman.list().end(); ++it ) 00199 { 00200 flush( ( *it ).partner( OPimXRef::One ), stream ); 00201 flush( ( *it ).partner( OPimXRef::Two ), stream ); 00202 } 00203 return true; 00204 } 00205 00206 00207 void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const 00208 { 00209 str << par.service(); 00210 str << par.uid(); 00211 str << par.field(); 00212 } 00213 00214 00215 OPimXRefPartner OPimRecord::partner( QDataStream& stream ) 00216 { 00217 OPimXRefPartner par; 00218 QString str; 00219 int i; 00220 00221 stream >> str; 00222 par.setService( str ); 00223 00224 stream >> i; 00225 par.setUid( i ); 00226 00227 stream >> i ; 00228 par.setField( i ); 00229 00230 return par; 00231 } 00232 00233 00234 void OPimRecord::setLastHitField( int lastHit ) const 00235 { 00236 m_lastHit = lastHit; 00237 } 00238 00239 00240 int OPimRecord::lastHitField() const 00241 { 00242 return m_lastHit; 00243 } 00244 00245 00246 QMap<QString, QString> OPimRecord::toExtraMap() const 00247 { 00248 return customMap; 00249 } 00250 00251 00252 void OPimRecord::setExtraMap( const QMap<QString, QString>& map ) 00253 { 00254 customMap = map; 00255 } 00256 00257 #if 0 00258 QString OPimRecord::recordAttributeTranslated( int field )const 00259 { 00260 return recordAttributeTranslated()[field]; 00261 } 00262 #endif 00263 00264 }
1.4.2