-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 82 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.cpp | 90 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 117 |
3 files changed, 289 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h new file mode 100644 index 0000000..f2a241d --- a/dev/null +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -0,0 +1,82 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | ||
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | ||
3 | |||
4 | #include <qarray.h> | ||
5 | |||
6 | #include <opie/opimrecord.h> | ||
7 | #include <opie/opimaccessbackend.h> | ||
8 | #include <opie/orecordlist.h> | ||
9 | |||
10 | template <class T = OPimRecord > | ||
11 | class OPimAccessTemplate { | ||
12 | public: | ||
13 | typedef ORecordList<T> List; | ||
14 | typedef OPimAccessBackend<T> BackEnd; | ||
15 | OPimAccessTemplate( BackEnd* end) | ||
16 | : m_backEnd( end ) { | ||
17 | } | ||
18 | ~OPimAccessTemplate() { | ||
19 | delete m_backEnd; | ||
20 | } | ||
21 | virtual void load() { | ||
22 | m_backEnd->load(); | ||
23 | } | ||
24 | virtual void reload() { | ||
25 | m_backEnd->reload(); | ||
26 | } | ||
27 | virtual void save() { | ||
28 | m_backEnd->save(); | ||
29 | } | ||
30 | |||
31 | /* | ||
32 | *do array to Records conversion | ||
33 | * QArray<int> ids | ||
34 | */ | ||
35 | virtual List allRecords()const { | ||
36 | QArray<int> ints = m_backEnd->allRecords(); | ||
37 | |||
38 | List lis( ints, this ); | ||
39 | return lis; | ||
40 | } | ||
41 | virtual List queryByExample( const T& t, int sortOrder ) { | ||
42 | QArray<int> ints = m_backEnd->query( t, sortOrder ); | ||
43 | List lis( ints, this ); | ||
44 | |||
45 | return lis; | ||
46 | } | ||
47 | /* implement QCache here */ | ||
48 | virtual T find( int uid ) { | ||
49 | T t = m_backEnd->find( uid ); | ||
50 | return t; | ||
51 | } | ||
52 | |||
53 | /* invalidate cache here */ | ||
54 | virtual void clear() { | ||
55 | invalidateCache(); | ||
56 | m_backEnd->clear(); | ||
57 | } | ||
58 | virtual bool add( const T& t ) { | ||
59 | return m_backEnd->add( t ); | ||
60 | } | ||
61 | |||
62 | /* only the uid matters */ | ||
63 | virtual bool remove( const T& t ) { | ||
64 | /* remove from cache */ | ||
65 | return m_backEnd->remove( t.uid() ); | ||
66 | } | ||
67 | virtual bool remove( int uid ) { | ||
68 | /* remove from cache */ | ||
69 | return m_backEnd->remove(uid); | ||
70 | } | ||
71 | virtual bool replace( const T& t) { | ||
72 | return m_backEnd->replace( t ); | ||
73 | } | ||
74 | protected: | ||
75 | void invalidateCache() { | ||
76 | |||
77 | } | ||
78 | BackEnd* m_backEnd; | ||
79 | |||
80 | }; | ||
81 | |||
82 | #endif | ||
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp new file mode 100644 index 0000000..95de1df --- a/dev/null +++ b/libopie2/opiepim/core/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 | } | ||
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h new file mode 100644 index 0000000..a0e0413 --- a/dev/null +++ b/libopie2/opiepim/core/opimrecord.h | |||
@@ -0,0 +1,117 @@ | |||
1 | #ifndef OPIE_PIM_RECORD_H | ||
2 | #define OPIE_PIM_RECORD_H | ||
3 | |||
4 | #include <qmap.h> | ||
5 | #include <qstring.h> | ||
6 | #include <qstringlist.h> | ||
7 | |||
8 | #include <qpe/palmtoprecord.h> | ||
9 | |||
10 | class OPimRecord : public Qtopia::Record { | ||
11 | public: | ||
12 | /** | ||
13 | * uid of 0 isEmpty | ||
14 | * uid of 1 will be assigned a new one | ||
15 | */ | ||
16 | OPimRecord(int uid = 0); | ||
17 | ~OPimRecord(); | ||
18 | |||
19 | /** | ||
20 | * copy c'tor | ||
21 | */ | ||
22 | OPimRecord( OPimRecord& rec ); | ||
23 | |||
24 | /** | ||
25 | * copy operator | ||
26 | */ | ||
27 | OPimRecord &operator=( const OPimRecord& ); | ||
28 | |||
29 | /** | ||
30 | * category names resolved | ||
31 | */ | ||
32 | QStringList categoryNames()const; | ||
33 | |||
34 | /** | ||
35 | * set category names they will be resolved | ||
36 | */ | ||
37 | void setCategoryName( const QStringList& ); | ||
38 | |||
39 | /** | ||
40 | * addCategoryName adds a name | ||
41 | * to the internal category list | ||
42 | */ | ||
43 | void addCategoryName( const QString& ); | ||
44 | |||
45 | /** | ||
46 | * if a Record isEmpty | ||
47 | */ | ||
48 | virtual bool isEmpty()const; | ||
49 | |||
50 | /** | ||
51 | * toRichText summary | ||
52 | */ | ||
53 | virtual QString toRichText()const = 0; | ||
54 | |||
55 | /** | ||
56 | * a small one line summary | ||
57 | */ | ||
58 | virtual QString toShortText()const = 0; | ||
59 | |||
60 | /** | ||
61 | * the name of the Record | ||
62 | */ | ||
63 | virtual QString type()const = 0; | ||
64 | |||
65 | /** | ||
66 | * converts the internal structure to a map | ||
67 | */ | ||
68 | virtual QMap<int, QString> toMap()const = 0; | ||
69 | |||
70 | /** | ||
71 | * key value representation of extra items | ||
72 | */ | ||
73 | virtual QMap<QString, QString> toExtraMap()const = 0; | ||
74 | |||
75 | /** | ||
76 | * the name for a recordField | ||
77 | */ | ||
78 | virtual QString recordField(int)const = 0; | ||
79 | |||
80 | /** | ||
81 | * the related apps names | ||
82 | */ | ||
83 | QStringList relatedApps()const; | ||
84 | |||
85 | /** | ||
86 | * the realtions between an app | ||
87 | */ | ||
88 | QArray<int> relations( const QString& app )const; | ||
89 | |||
90 | /** | ||
91 | * | ||
92 | */ | ||
93 | void clearRelation( const QString& app ); | ||
94 | |||
95 | /** | ||
96 | * | ||
97 | */ | ||
98 | void addRelation( const QString& app, int id ); | ||
99 | |||
100 | /** | ||
101 | * | ||
102 | */ | ||
103 | void setRelations( const QString&, QArray<int> ids ); | ||
104 | |||
105 | protected: | ||
106 | QString crossToString()const; | ||
107 | |||
108 | private: | ||
109 | class OPimRecordPrivate; | ||
110 | OPimRecordPrivate *d; | ||
111 | QMap<QString, QArray<int> > m_relations; | ||
112 | |||
113 | }; | ||
114 | |||
115 | |||
116 | |||
117 | #endif | ||