author | zecke <zecke> | 2002-09-20 12:59:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-20 12:59:29 (UTC) |
commit | a05c10c9744020be31c3038b2de3401b5cc673fb (patch) (unidiff) | |
tree | 20d059bf00fc1199c34a60a8be4cb842ebfe4d14 /libopie/pim/opimrecord.cpp | |
parent | 7099778ab711f78cfd86dadad1b8af993e008f38 (diff) | |
download | opie-a05c10c9744020be31c3038b2de3401b5cc673fb.zip opie-a05c10c9744020be31c3038b2de3401b5cc673fb.tar.gz opie-a05c10c9744020be31c3038b2de3401b5cc673fb.tar.bz2 |
Our new common template based start for Accessing and Manipulating
the Records
The CROSS_REFERENCE branch will get ported to it.
We use templates for several reasons
They allow us to share code and to be easily extended
I've to make them not inline to save memory...
I've to port all DBs and Record related classes
-rw-r--r-- | libopie/pim/opimrecord.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp new file mode 100644 index 0000000..95de1df --- a/dev/null +++ b/libopie/pim/opimrecord.cpp | |||
@@ -0,0 +1,90 @@ | |||
1 | #include "opimrecord.h" | ||
2 | |||
3 | OPimRecord::OPimRecord( int uid ) | ||
4 | : Qtopia::Record() { | ||
5 | setUid( uid ); | ||
6 | if ( uid == 1 ) | ||
7 | assignUid(); | ||
8 | } | ||
9 | OPimRecord::~OPimRecord() { | ||
10 | } | ||
11 | OPimRecord::OPimRecord( OPimRecord& rec ) | ||
12 | : Qtopia::Record( rec ) | ||
13 | { | ||
14 | (*this) = rec; | ||
15 | } | ||
16 | |||
17 | OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { | ||
18 | /* how do I call the parent copy operator ? */ | ||
19 | setUid( rec.uid() ); | ||
20 | setCategories( rec.categories() ); | ||
21 | return *this; | ||
22 | } | ||
23 | QStringList OPimRecord::categoryNames()const { | ||
24 | QStringList list; | ||
25 | |||
26 | return list; | ||
27 | } | ||
28 | void OPimRecord::setCategoryName( const QStringList& ) { | ||
29 | |||
30 | } | ||
31 | void OPimRecord::addCategoryName( const QString& ) { | ||
32 | |||
33 | } | ||
34 | bool OPimRecord::isEmpty()const { | ||
35 | return ( uid() == 0 ); | ||
36 | } | ||
37 | QStringList OPimRecord::relatedApps()const{ | ||
38 | QStringList list; | ||
39 | QMap<QString, QArray<int> >::ConstIterator it; | ||
40 | for ( it = m_relations.begin(); it != m_relations.end(); ++it ) { | ||
41 | list << it.key(); | ||
42 | } | ||
43 | return list; | ||
44 | } | ||
45 | QArray<int> OPimRecord::relations(const QString& app )const { | ||
46 | QArray<int> tmp; | ||
47 | QMap<QString, QArray<int> >::ConstIterator it; | ||
48 | it = m_relations.find( app); | ||
49 | if ( it != m_relations.end() ) | ||
50 | tmp = it.data(); | ||
51 | return tmp; | ||
52 | } | ||
53 | void OPimRecord::clearRelation( const QString& app ) { | ||
54 | m_relations.remove( app ); | ||
55 | } | ||
56 | void OPimRecord::addRelation( const QString& app, int id ) { | ||
57 | |||
58 | QMap<QString, QArray<int> >::Iterator it; | ||
59 | QArray<int> tmp; | ||
60 | |||
61 | it = m_relations.find( app ); | ||
62 | if ( it == m_relations.end() ) { | ||
63 | tmp.resize(1 ); | ||
64 | tmp[0] = id; | ||
65 | }else{ | ||
66 | tmp = it.data(); | ||
67 | tmp.resize( tmp.size() + 1 ); | ||
68 | tmp[tmp.size() - 1] = id; | ||
69 | } | ||
70 | m_relations.replace( app, tmp ); | ||
71 | } | ||
72 | void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { | ||
73 | |||
74 | QMap<QString, QArray<int> >::Iterator it; | ||
75 | QArray<int> tmp; | ||
76 | |||
77 | it = m_relations.find( app); | ||
78 | if ( it == m_relations.end() ) { | ||
79 | tmp = ids; | ||
80 | }else{ | ||
81 | tmp = it.data(); | ||
82 | int offset = tmp.size()-1; | ||
83 | tmp.resize( tmp.size() + ids.size() ); | ||
84 | for (uint i = 0; i < ids.size(); i++ ) { | ||
85 | tmp[offset+i] = ids[i]; | ||
86 | } | ||
87 | |||
88 | } | ||
89 | m_relations.replace( app, tmp ); | ||
90 | } | ||