libopie PIM API Documentation

opimrecord.cpp

Go to the documentation of this file.
00001 #include <qarray.h>
00002 
00003 #include <qpe/categories.h>
00004 #include <qpe/categoryselect.h>
00005 
00006 #include "opimrecord.h"
00007 
00008 Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
00009 
00010 
00011 OPimRecord::OPimRecord( int uid )
00012     : Qtopia::Record() {
00013 
00014     m_lastHit = -1;
00015     setUid( uid );
00016 }
00017 OPimRecord::~OPimRecord() {
00018 }
00019 OPimRecord::OPimRecord( const OPimRecord& rec )
00020     : Qtopia::Record( rec )
00021 {
00022     (*this) = rec;
00023 }
00024 
00025 OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
00026     if ( this == &rec ) return *this;
00027 
00028     Qtopia::Record::operator=( rec );
00029     m_xrefman = rec.m_xrefman;
00030     m_lastHit = rec.m_lastHit;
00031 
00032     return  *this;
00033 }
00034 /*
00035  * category names
00036  */
00037 QStringList OPimRecord::categoryNames( const QString& appname ) const {
00038     QStringList list;
00039     QArray<int> cats = categories();
00040     Categories catDB;
00041     catDB.load( categoryFileName() );
00042 
00043     for (uint i = 0; i < cats.count(); i++ ) {
00044         list << catDB.label( appname, cats[i] );
00045     }
00046 
00047     return list;
00048 }
00049 void OPimRecord::setCategoryNames( const QStringList& ) {
00050 
00051 }
00052 void OPimRecord::addCategoryName( const QString& ) {
00053     Categories catDB;
00054     catDB.load( categoryFileName() );
00055 
00056 
00057 }
00058 bool OPimRecord::isEmpty()const {
00059     return ( uid() == 0 );
00060 }
00061 /*QString OPimRecord::crossToString()const {
00062     QString str;
00063     QMap<QString, QArray<int> >::ConstIterator it;
00064     for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
00065         QArray<int> id = it.data();
00066         for ( uint i = 0; i < id.size(); ++i ) {
00067             str += it.key() + "," + QString::number( i ) + ";";
00068         }
00069     }
00070     str = str.remove( str.length()-1, 1); // strip the ;
00071     //qWarning("IDS " + str );
00072 
00073     return str;
00074     }*/
00075 /* if uid = 1 assign a new one */
00076 void OPimRecord::setUid( int uid ) {
00077     if ( uid == 1)
00078         uid = uidGen().generate();
00079 
00080     Qtopia::Record::setUid( uid );
00081 };
00082 Qtopia::UidGen &OPimRecord::uidGen() {
00083     return m_uidGen;
00084 }
00085 OPimXRefManager &OPimRecord::xrefmanager() {
00086     return m_xrefman;
00087 }
00088 int OPimRecord::rtti(){
00089     return 0;
00090 }
00091 
00095 /*
00096  * First read UID
00097  *            Categories
00098  *            XRef
00099  */
00100 bool OPimRecord::loadFromStream( QDataStream& stream ) {
00101     int Int;
00102     uint UInt;
00103     stream >> Int;
00104     setUid(Int);
00105 
00107     stream >> UInt;
00108     QArray<int> array(UInt);
00109     for (uint i = 0; i < UInt; i++ ) {
00110         stream >> array[i];
00111     }
00112     setCategories( array );
00113 
00114     /*
00115      * now we do the X-Ref stuff
00116      */
00117     OPimXRef xref;
00118     stream >> UInt;
00119     for ( uint i = 0; i < UInt; i++ ) {
00120         xref.setPartner( OPimXRef::One, partner( stream ) );
00121         xref.setPartner( OPimXRef::Two, partner( stream ) );
00122         m_xrefman.add( xref );
00123     }
00124 
00125     return true;
00126 }
00127 bool OPimRecord::saveToStream( QDataStream& stream )const {
00130     stream << uid();
00131 
00133     stream << categories().count();
00134     for ( uint i = 0; i < categories().count(); i++ ) {
00135         stream << categories()[i];
00136     }
00137 
00138     /*
00139      * first the XRef count
00140      * then the xrefs
00141      */
00142     stream << m_xrefman.list().count();
00143     for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
00144           it != m_xrefman.list().end(); ++it ) {
00145         flush( (*it).partner( OPimXRef::One),  stream  );
00146         flush( (*it).partner( OPimXRef::Two),  stream  );
00147     }
00148     return true;
00149 }
00150 void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{
00151     str << par.service();
00152     str << par.uid();
00153     str << par.field();
00154 }
00155 OPimXRefPartner OPimRecord::partner( QDataStream& stream ) {
00156     OPimXRefPartner par;
00157     QString str;
00158     int i;
00159 
00160     stream >> str;
00161     par.setService( str );
00162 
00163     stream >> i;
00164     par.setUid( i );
00165 
00166     stream >> i ;
00167     par.setField( i );
00168 
00169     return par;
00170 }
00171 void OPimRecord::setLastHitField( int lastHit )const {
00172     m_lastHit = lastHit;
00173 }
00174 int OPimRecord::lastHitField()const{
00175     return m_lastHit;
00176 }
00177 QMap<QString, QString> OPimRecord::toExtraMap()const {
00178     return customMap;
00179 }
00180 void OPimRecord::setExtraMap( const QMap<QString, QString>& map) {
00181     customMap = map;
00182 }
KDE Logo
This file is part of the documentation for OPIE Version 1.1.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:25:21 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001