-rw-r--r-- | libopie2/opiepim/backend/opimaccessbackend.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 43 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 25 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimcache.h | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.cpp | 82 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 12 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimresolver.cpp | 198 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimresolver.h | 52 | ||||
-rw-r--r-- | libopie2/opiepim/core/otemplatebase.h | 63 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 32 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.h | 13 | ||||
-rw-r--r-- | libopie2/opiepim/ocontact.cpp | 11 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiepim/ui/opimmainwindow.cpp | 36 | ||||
-rw-r--r-- | libopie2/opiepim/ui/opimmainwindow.h | 26 |
15 files changed, 536 insertions, 82 deletions
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h index 4f00bc9..e268f4f 100644 --- a/libopie2/opiepim/backend/opimaccessbackend.h +++ b/libopie2/opiepim/backend/opimaccessbackend.h | |||
@@ -10,25 +10,27 @@ | |||
10 | /** | 10 | /** |
11 | * OPimAccessBackend is the base class | 11 | * OPimAccessBackend is the base class |
12 | * for all private backends | 12 | * for all private backends |
13 | * it operates on OPimRecord as the base class | 13 | * it operates on OPimRecord as the base class |
14 | * and it's responsible for fast manipulating | 14 | * and it's responsible for fast manipulating |
15 | * the resource the implementation takes care | 15 | * the resource the implementation takes care |
16 | * of | 16 | * of |
17 | */ | 17 | */ |
18 | template <class T = OPimRecord> | 18 | template <class T = OPimRecord> |
19 | class OPimAccessBackend { | 19 | class OPimAccessBackend { |
20 | public: | 20 | public: |
21 | typedef OTemplateBase<T> Frontend; | 21 | typedef OTemplateBase<T> Frontend; |
22 | OPimAccessBackend(); | 22 | |
23 | /** The access hint from the frontend */ | ||
24 | OPimAccessBackend(int access = 0); | ||
23 | virtual ~OPimAccessBackend(); | 25 | virtual ~OPimAccessBackend(); |
24 | 26 | ||
25 | /** | 27 | /** |
26 | * load the resource | 28 | * load the resource |
27 | */ | 29 | */ |
28 | virtual bool load() = 0; | 30 | virtual bool load() = 0; |
29 | 31 | ||
30 | /** | 32 | /** |
31 | * reload the resource | 33 | * reload the resource |
32 | */ | 34 | */ |
33 | virtual bool reload() = 0; | 35 | virtual bool reload() = 0; |
34 | 36 | ||
@@ -79,41 +81,47 @@ public: | |||
79 | virtual bool replace( const T& t ) = 0; | 81 | virtual bool replace( const T& t ) = 0; |
80 | 82 | ||
81 | /* | 83 | /* |
82 | * setTheFrontEnd!!! | 84 | * setTheFrontEnd!!! |
83 | */ | 85 | */ |
84 | void setFrontend( Frontend* front ); | 86 | void setFrontend( Frontend* front ); |
85 | 87 | ||
86 | /** | 88 | /** |
87 | * set the read ahead count | 89 | * set the read ahead count |
88 | */ | 90 | */ |
89 | void setReadAhead( uint count ); | 91 | void setReadAhead( uint count ); |
90 | protected: | 92 | protected: |
93 | int access()const; | ||
91 | void cache( const T& t )const; | 94 | void cache( const T& t )const; |
92 | 95 | ||
93 | /** | 96 | /** |
94 | * use a prime number here! | 97 | * use a prime number here! |
95 | */ | 98 | */ |
96 | void setSaneCacheSize( int ); | 99 | void setSaneCacheSize( int ); |
97 | 100 | ||
98 | uint readAhead()const; | 101 | uint readAhead()const; |
99 | 102 | ||
100 | private: | 103 | private: |
104 | class Private; | ||
105 | Private* d; | ||
101 | Frontend* m_front; | 106 | Frontend* m_front; |
102 | uint m_read; | 107 | uint m_read; |
108 | int m_acc; | ||
103 | 109 | ||
104 | }; | 110 | }; |
105 | 111 | ||
106 | template <class T> | 112 | template <class T> |
107 | OPimAccessBackend<T>::OPimAccessBackend() { | 113 | OPimAccessBackend<T>::OPimAccessBackend(int acc) |
114 | : m_acc( acc ) | ||
115 | { | ||
108 | m_front = 0l; | 116 | m_front = 0l; |
109 | } | 117 | } |
110 | template <class T> | 118 | template <class T> |
111 | OPimAccessBackend<T>::~OPimAccessBackend() { | 119 | OPimAccessBackend<T>::~OPimAccessBackend() { |
112 | 120 | ||
113 | } | 121 | } |
114 | template <class T> | 122 | template <class T> |
115 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { | 123 | void OPimAccessBackend<T>::setFrontend( Frontend* fr ) { |
116 | m_front = fr; | 124 | m_front = fr; |
117 | } | 125 | } |
118 | template <class T> | 126 | template <class T> |
119 | void OPimAccessBackend<T>::cache( const T& t )const { | 127 | void OPimAccessBackend<T>::cache( const T& t )const { |
@@ -129,13 +137,17 @@ template <class T> | |||
129 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, | 137 | T OPimAccessBackend<T>::find( int uid, const QArray<int>&, |
130 | uint, typename Frontend::CacheDirection )const { | 138 | uint, typename Frontend::CacheDirection )const { |
131 | return find( uid ); | 139 | return find( uid ); |
132 | } | 140 | } |
133 | template <class T> | 141 | template <class T> |
134 | void OPimAccessBackend<T>::setReadAhead( uint count ) { | 142 | void OPimAccessBackend<T>::setReadAhead( uint count ) { |
135 | m_read = count; | 143 | m_read = count; |
136 | } | 144 | } |
137 | template <class T> | 145 | template <class T> |
138 | uint OPimAccessBackend<T>::readAhead()const { | 146 | uint OPimAccessBackend<T>::readAhead()const { |
139 | return m_read; | 147 | return m_read; |
140 | } | 148 | } |
149 | template <class T> | ||
150 | int OPimAccessBackend<T>::access()const { | ||
151 | return m_acc; | ||
152 | } | ||
141 | #endif | 153 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index b2dfe80..21f93a0 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -1,12 +1,22 @@ | |||
1 | #include <errno.h> | ||
2 | #include <fcntl.h> | ||
3 | |||
4 | #include <sys/mman.h> | ||
5 | #include <sys/stat.h> | ||
6 | #include <sys/types.h> | ||
7 | |||
8 | #include <unistd.h> | ||
9 | |||
10 | |||
1 | #include <qfile.h> | 11 | #include <qfile.h> |
2 | #include <qvector.h> | 12 | #include <qvector.h> |
3 | 13 | ||
4 | #include <qpe/global.h> | 14 | #include <qpe/global.h> |
5 | #include <qpe/stringutil.h> | 15 | #include <qpe/stringutil.h> |
6 | #include <qpe/timeconversion.h> | 16 | #include <qpe/timeconversion.h> |
7 | 17 | ||
8 | #include <opie/xmltree.h> | 18 | #include <opie/xmltree.h> |
9 | 19 | ||
10 | #include "otodoaccessxml.h" | 20 | #include "otodoaccessxml.h" |
11 | 21 | ||
12 | OTodoAccessXML::OTodoAccessXML( const QString& appName, | 22 | OTodoAccessXML::OTodoAccessXML( const QString& appName, |
@@ -43,38 +53,54 @@ bool OTodoAccessXML::load() { | |||
43 | dict.insert("Progress" , new int(OTodo::Progress) ); | 53 | dict.insert("Progress" , new int(OTodo::Progress) ); |
44 | dict.insert("Completed", new int(OTodo::Completed) ); | 54 | dict.insert("Completed", new int(OTodo::Completed) ); |
45 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 55 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
46 | dict.insert("State", new int(OTodo::State) ); | 56 | dict.insert("State", new int(OTodo::State) ); |
47 | dict.insert("Recurrence", new int(OTodo::Recurrence) ); | 57 | dict.insert("Recurrence", new int(OTodo::Recurrence) ); |
48 | dict.insert("Alarms", new int(OTodo::Alarms) ); | 58 | dict.insert("Alarms", new int(OTodo::Alarms) ); |
49 | dict.insert("Reminders", new int(OTodo::Reminders) ); | 59 | dict.insert("Reminders", new int(OTodo::Reminders) ); |
50 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); | 60 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); |
51 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); | 61 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); |
52 | 62 | ||
53 | // here the custom XML parser from TT it's GPL | 63 | // here the custom XML parser from TT it's GPL |
54 | // but we want to push OpiePIM... to TT..... | 64 | // but we want to push OpiePIM... to TT..... |
55 | QFile f(m_file ); | 65 | // mmap part from zecke :) |
56 | if (!f.open(IO_ReadOnly) ) | 66 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); |
67 | struct stat attribut; | ||
68 | if ( fd < 0 ) return false; | ||
69 | |||
70 | if ( fstat(fd, &attribut ) == -1 ) { | ||
71 | ::close( fd ); | ||
57 | return false; | 72 | return false; |
73 | } | ||
74 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | ||
75 | if ( map_addr == ( (caddr_t)-1) ) { | ||
76 | ::close(fd ); | ||
77 | return false; | ||
78 | } | ||
79 | /* advise the kernel who we want to read it */ | ||
80 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); | ||
81 | /* we do not the file any more */ | ||
82 | ::close( fd ); | ||
58 | 83 | ||
59 | QByteArray ba = f.readAll(); | 84 | char* dt = (char*)map_addr; |
60 | f.close(); | 85 | int len = attribut.st_size; |
61 | char* dt = ba.data(); | ||
62 | int len = ba.size(); | ||
63 | int i = 0; | 86 | int i = 0; |
64 | char *point; | 87 | char *point; |
65 | const char* collectionString = "<Task "; | 88 | const char* collectionString = "<Task "; |
89 | int strLen = strlen(collectionString); | ||
66 | while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { | 90 | while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { |
67 | i = point -dt; | 91 | i = point -dt; |
68 | i+= strlen(collectionString); | 92 | i+= strLen; |
93 | qWarning("Found a start at %d %d", i, (point-dt) ); | ||
94 | |||
69 | OTodo ev; | 95 | OTodo ev; |
70 | m_year = m_month = m_day = 0; | 96 | m_year = m_month = m_day = 0; |
71 | 97 | ||
72 | while ( TRUE ) { | 98 | while ( TRUE ) { |
73 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) | 99 | while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) |
74 | ++i; | 100 | ++i; |
75 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 101 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
76 | break; | 102 | break; |
77 | 103 | ||
78 | // we have another attribute, read it. | 104 | // we have another attribute, read it. |
79 | int j = i; | 105 | int j = i; |
80 | while ( j < len && dt[j] != '=' ) | 106 | while ( j < len && dt[j] != '=' ) |
@@ -111,35 +137,38 @@ bool OTodoAccessXML::load() { | |||
111 | if ( haveEnt ) | 137 | if ( haveEnt ) |
112 | str = Qtopia::plainString( str ); | 138 | str = Qtopia::plainString( str ); |
113 | 139 | ||
114 | /* | 140 | /* |
115 | * add key + value | 141 | * add key + value |
116 | */ | 142 | */ |
117 | todo( &dict, ev, attr, str ); | 143 | todo( &dict, ev, attr, str ); |
118 | 144 | ||
119 | } | 145 | } |
120 | /* | 146 | /* |
121 | * now add it | 147 | * now add it |
122 | */ | 148 | */ |
149 | qWarning("End at %d", i ); | ||
123 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { | 150 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { |
124 | ev.setUid( 1 ); | 151 | ev.setUid( 1 ); |
125 | m_changed = true; | 152 | m_changed = true; |
126 | } | 153 | } |
127 | if ( ev.hasDueDate() ) { | 154 | if ( ev.hasDueDate() ) { |
128 | ev.setDueDate( QDate(m_year, m_month, m_day) ); | 155 | ev.setDueDate( QDate(m_year, m_month, m_day) ); |
129 | } | 156 | } |
130 | m_events.insert(ev.uid(), ev ); | 157 | m_events.insert(ev.uid(), ev ); |
131 | m_year = m_month = m_day = -1; | 158 | m_year = m_month = m_day = -1; |
132 | } | 159 | } |
133 | 160 | ||
161 | munmap(map_addr, attribut.st_size ); | ||
162 | |||
134 | qWarning("counts %d records loaded!", m_events.count() ); | 163 | qWarning("counts %d records loaded!", m_events.count() ); |
135 | return true; | 164 | return true; |
136 | } | 165 | } |
137 | bool OTodoAccessXML::reload() { | 166 | bool OTodoAccessXML::reload() { |
138 | return load(); | 167 | return load(); |
139 | } | 168 | } |
140 | bool OTodoAccessXML::save() { | 169 | bool OTodoAccessXML::save() { |
141 | // qWarning("saving"); | 170 | // qWarning("saving"); |
142 | if (!m_opened || !m_changed ) { | 171 | if (!m_opened || !m_changed ) { |
143 | // qWarning("not saving"); | 172 | // qWarning("not saving"); |
144 | return true; | 173 | return true; |
145 | } | 174 | } |
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 8cf81c8..259e2c1 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -13,52 +13,58 @@ | |||
13 | /** | 13 | /** |
14 | * Thats the frontend to our OPIE PIM | 14 | * Thats the frontend to our OPIE PIM |
15 | * Library. Either you want to use it's | 15 | * Library. Either you want to use it's |
16 | * interface or you want to implement | 16 | * interface or you want to implement |
17 | * your own Access lib | 17 | * your own Access lib |
18 | * Just create a OPimRecord and inherit from | 18 | * Just create a OPimRecord and inherit from |
19 | * the plugins | 19 | * the plugins |
20 | */ | 20 | */ |
21 | 21 | ||
22 | template <class T = OPimRecord > | 22 | template <class T = OPimRecord > |
23 | class OPimAccessTemplate : public OTemplateBase<T> { | 23 | class OPimAccessTemplate : public OTemplateBase<T> { |
24 | public: | 24 | public: |
25 | enum Access { | ||
26 | Random = 0, | ||
27 | SortedAccess | ||
28 | }; | ||
25 | typedef ORecordList<T> List; | 29 | typedef ORecordList<T> List; |
26 | typedef OPimAccessBackend<T> BackEnd; | 30 | typedef OPimAccessBackend<T> BackEnd; |
27 | typedef OPimCache<T> Cache; | 31 | typedef OPimCache<T> Cache; |
28 | 32 | ||
29 | /** | 33 | /** |
30 | * c'tor BackEnd | 34 | * c'tor BackEnd |
35 | * enum Access a small hint on how to handle the backend | ||
31 | */ | 36 | */ |
32 | OPimAccessTemplate( BackEnd* end); | 37 | OPimAccessTemplate( BackEnd* end); |
38 | |||
33 | virtual ~OPimAccessTemplate(); | 39 | virtual ~OPimAccessTemplate(); |
34 | 40 | ||
35 | /** | 41 | /** |
36 | * load from the backend | 42 | * load from the backend |
37 | */ | 43 | */ |
38 | virtual bool load(); | 44 | bool load(); |
39 | 45 | ||
40 | /** Reload database. | 46 | /** Reload database. |
41 | * You should execute this function if the external database | 47 | * You should execute this function if the external database |
42 | * was changed. | 48 | * was changed. |
43 | * This function will load the external database and afterwards | 49 | * This function will load the external database and afterwards |
44 | * rejoin the local changes. Therefore the local database will be set consistent. | 50 | * rejoin the local changes. Therefore the local database will be set consistent. |
45 | */ | 51 | */ |
46 | virtual bool reload(); | 52 | virtual bool reload(); |
47 | 53 | ||
48 | /** Save contacts database. | 54 | /** Save contacts database. |
49 | * Save is more a "commit". After calling this function, all changes are public available. | 55 | * Save is more a "commit". After calling this function, all changes are public available. |
50 | * @return true if successful | 56 | * @return true if successful |
51 | */ | 57 | */ |
52 | virtual bool save(); | 58 | bool save(); |
53 | 59 | ||
54 | /** | 60 | /** |
55 | * if the resource was changed externally | 61 | * if the resource was changed externally |
56 | * You should use the signal handling instead of polling possible changes ! | 62 | * You should use the signal handling instead of polling possible changes ! |
57 | * zecke: Do you implement a signal for otodoaccess ? | 63 | * zecke: Do you implement a signal for otodoaccess ? |
58 | */ | 64 | */ |
59 | bool wasChangedExternally()const; | 65 | bool wasChangedExternally()const; |
60 | 66 | ||
61 | /** | 67 | /** |
62 | * return a List of records | 68 | * return a List of records |
63 | * you can iterate over them | 69 | * you can iterate over them |
64 | */ | 70 | */ |
@@ -76,62 +82,65 @@ public: | |||
76 | virtual T find( int uid )const; | 82 | virtual T find( int uid )const; |
77 | 83 | ||
78 | /** | 84 | /** |
79 | * read ahead cache find method ;) | 85 | * read ahead cache find method ;) |
80 | */ | 86 | */ |
81 | virtual T find( int uid, const QArray<int>&, | 87 | virtual T find( int uid, const QArray<int>&, |
82 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; | 88 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; |
83 | 89 | ||
84 | /* invalidate cache here */ | 90 | /* invalidate cache here */ |
85 | /** | 91 | /** |
86 | * clears the backend and invalidates the backend | 92 | * clears the backend and invalidates the backend |
87 | */ | 93 | */ |
88 | virtual void clear() ; | 94 | void clear() ; |
89 | 95 | ||
90 | /** | 96 | /** |
91 | * add T to the backend | 97 | * add T to the backend |
92 | * @param t The item to add. | 98 | * @param t The item to add. |
93 | * @return <i>true</i> if added successfully. | 99 | * @return <i>true</i> if added successfully. |
94 | */ | 100 | */ |
95 | virtual bool add( const T& t ) ; | 101 | virtual bool add( const T& t ) ; |
96 | bool add( const OPimRecord& ); | 102 | bool add( const OPimRecord& ); |
97 | 103 | ||
98 | /* only the uid matters */ | 104 | /* only the uid matters */ |
99 | /** | 105 | /** |
100 | * remove T from the backend | 106 | * remove T from the backend |
101 | * @param t The item to remove | 107 | * @param t The item to remove |
102 | * @return <i>true</i> if successful. | 108 | * @return <i>true</i> if successful. |
103 | */ | 109 | */ |
104 | virtual bool remove( const T& t ); | 110 | virtual bool remove( const T& t ); |
105 | 111 | ||
106 | /** | 112 | /** |
107 | * remove the OPimRecord with uid | 113 | * remove the OPimRecord with uid |
108 | * @param uid The ID of the item to remove | 114 | * @param uid The ID of the item to remove |
109 | * @return <i>true</i> if successful. | 115 | * @return <i>true</i> if successful. |
110 | */ | 116 | */ |
111 | virtual bool remove( int uid ); | 117 | bool remove( int uid ); |
118 | bool remove( const OPimRecord& ); | ||
112 | 119 | ||
113 | /** | 120 | /** |
114 | * replace T from backend | 121 | * replace T from backend |
115 | * @param t The item to replace | 122 | * @param t The item to replace |
116 | * @return <i>true</i> if successful. | 123 | * @return <i>true</i> if successful. |
117 | */ | 124 | */ |
118 | virtual bool replace( const T& t) ; | 125 | virtual bool replace( const T& t) ; |
119 | 126 | ||
120 | void setReadAhead( uint count ); | 127 | void setReadAhead( uint count ); |
121 | /** | 128 | /** |
122 | * @internal | 129 | * @internal |
123 | */ | 130 | */ |
124 | void cache( const T& )const; | 131 | void cache( const T& )const; |
125 | void setSaneCacheSize( int ); | 132 | void setSaneCacheSize( int ); |
133 | |||
134 | QArray<int> records()const; | ||
126 | protected: | 135 | protected: |
127 | /** | 136 | /** |
128 | * invalidate the cache | 137 | * invalidate the cache |
129 | */ | 138 | */ |
130 | void invalidateCache(); | 139 | void invalidateCache(); |
131 | 140 | ||
132 | void setBackEnd( BackEnd* end ); | 141 | void setBackEnd( BackEnd* end ); |
133 | /** | 142 | /** |
134 | * returns the backend | 143 | * returns the backend |
135 | */ | 144 | */ |
136 | BackEnd* backEnd(); | 145 | BackEnd* backEnd(); |
137 | BackEnd* m_backEnd; | 146 | BackEnd* m_backEnd; |
@@ -163,24 +172,28 @@ bool OPimAccessTemplate<T>::reload() { | |||
163 | } | 172 | } |
164 | template <class T> | 173 | template <class T> |
165 | bool OPimAccessTemplate<T>::save() { | 174 | bool OPimAccessTemplate<T>::save() { |
166 | return m_backEnd->save(); | 175 | return m_backEnd->save(); |
167 | } | 176 | } |
168 | template <class T> | 177 | template <class T> |
169 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 178 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
170 | QArray<int> ints = m_backEnd->allRecords(); | 179 | QArray<int> ints = m_backEnd->allRecords(); |
171 | List lis(ints, this ); | 180 | List lis(ints, this ); |
172 | return lis; | 181 | return lis; |
173 | } | 182 | } |
174 | template <class T> | 183 | template <class T> |
184 | QArray<int> OPimAccessTemplate<T>::records()const { | ||
185 | return m_backEnd->allRecords(); | ||
186 | } | ||
187 | template <class T> | ||
175 | typename OPimAccessTemplate<T>::List | 188 | typename OPimAccessTemplate<T>::List |
176 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { | 189 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { |
177 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); | 190 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); |
178 | 191 | ||
179 | List lis(ints, this ); | 192 | List lis(ints, this ); |
180 | return lis; | 193 | return lis; |
181 | } | 194 | } |
182 | template <class T> | 195 | template <class T> |
183 | T OPimAccessTemplate<T>::find( int uid ) const{ | 196 | T OPimAccessTemplate<T>::find( int uid ) const{ |
184 | T t = m_backEnd->find( uid ); | 197 | T t = m_backEnd->find( uid ); |
185 | cache( t ); | 198 | cache( t ); |
186 | return t; | 199 | return t; |
@@ -222,24 +235,28 @@ bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | |||
222 | return false; | 235 | return false; |
223 | } | 236 | } |
224 | template <class T> | 237 | template <class T> |
225 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 238 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
226 | return remove( t.uid() ); | 239 | return remove( t.uid() ); |
227 | } | 240 | } |
228 | template <class T> | 241 | template <class T> |
229 | bool OPimAccessTemplate<T>::remove( int uid ) { | 242 | bool OPimAccessTemplate<T>::remove( int uid ) { |
230 | m_cache.remove( uid ); | 243 | m_cache.remove( uid ); |
231 | return m_backEnd->remove( uid ); | 244 | return m_backEnd->remove( uid ); |
232 | } | 245 | } |
233 | template <class T> | 246 | template <class T> |
247 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | ||
248 | return remove( rec.uid() ); | ||
249 | } | ||
250 | template <class T> | ||
234 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 251 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
235 | m_cache.replace( t ); | 252 | m_cache.replace( t ); |
236 | return m_backEnd->replace( t ); | 253 | return m_backEnd->replace( t ); |
237 | } | 254 | } |
238 | template <class T> | 255 | template <class T> |
239 | void OPimAccessTemplate<T>::invalidateCache() { | 256 | void OPimAccessTemplate<T>::invalidateCache() { |
240 | m_cache.invalidate(); | 257 | m_cache.invalidate(); |
241 | } | 258 | } |
242 | template <class T> | 259 | template <class T> |
243 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 260 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
244 | return m_backEnd; | 261 | return m_backEnd; |
245 | } | 262 | } |
diff --git a/libopie2/opiepim/core/opimcache.h b/libopie2/opiepim/core/opimcache.h index 839550c..73414e5 100644 --- a/libopie2/opiepim/core/opimcache.h +++ b/libopie2/opiepim/core/opimcache.h | |||
@@ -1,43 +1,49 @@ | |||
1 | #ifndef OPIE_PIM_CACHE_H | 1 | #ifndef OPIE_PIM_CACHE_H |
2 | #define OPIE_PIM_CACHE_H | 2 | #define OPIE_PIM_CACHE_H |
3 | 3 | ||
4 | #include <qintcache.h> | 4 | #include <qintcache.h> |
5 | 5 | ||
6 | #include "opimrecord.h" | 6 | #include "opimrecord.h" |
7 | 7 | ||
8 | template <class T = OPimRecord> | 8 | template <class T = OPimRecord> |
9 | class OPimCacheItem { | 9 | class OPimCacheItem { |
10 | public: | 10 | public: |
11 | OPimCacheItem( const T& t = T() ); | 11 | OPimCacheItem( const T& t = T() ); |
12 | OPimCacheItem( const OPimCacheItem& ); | ||
12 | ~OPimCacheItem(); | 13 | ~OPimCacheItem(); |
13 | 14 | ||
15 | OPimCacheItem &operator=( const OPimCacheItem& ); | ||
16 | |||
14 | T record()const; | 17 | T record()const; |
15 | void setRecord( const T& ); | 18 | void setRecord( const T& ); |
16 | private: | 19 | private: |
17 | T m_t; | 20 | T m_t; |
18 | }; | 21 | }; |
19 | 22 | ||
20 | /** | 23 | /** |
21 | * OPimCache for caching the items | 24 | * OPimCache for caching the items |
22 | * We support adding, removing | 25 | * We support adding, removing |
23 | * and finding | 26 | * and finding |
24 | */ | 27 | */ |
25 | template <class T = OPimRecord> | 28 | template <class T = OPimRecord> |
26 | class OPimCache { | 29 | class OPimCache { |
27 | public: | 30 | public: |
28 | typedef OPimCacheItem<T> Item; | 31 | typedef OPimCacheItem<T> Item; |
29 | OPimCache(); | 32 | OPimCache(); |
33 | OPimCache( const OPimCache& ); | ||
30 | ~OPimCache(); | 34 | ~OPimCache(); |
31 | 35 | ||
36 | OPimCache &operator=( const OPimCache& ); | ||
37 | |||
32 | bool contains(int uid)const; | 38 | bool contains(int uid)const; |
33 | void invalidate(); | 39 | void invalidate(); |
34 | void setSize( int size ); | 40 | void setSize( int size ); |
35 | 41 | ||
36 | T find(int uid )const; | 42 | T find(int uid )const; |
37 | void add( const T& ); | 43 | void add( const T& ); |
38 | void remove( int uid ); | 44 | void remove( int uid ); |
39 | void replace( const T& ); | 45 | void replace( const T& ); |
40 | 46 | ||
41 | private: | 47 | private: |
42 | QIntCache<Item> m_cache; | 48 | QIntCache<Item> m_cache; |
43 | }; | 49 | }; |
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp index 49b5bf9..ac0f4a9 100644 --- a/libopie2/opiepim/core/opimrecord.cpp +++ b/libopie2/opiepim/core/opimrecord.cpp | |||
@@ -1,12 +1,14 @@ | |||
1 | #include <qarray.h> | ||
2 | |||
1 | #include <qpe/categories.h> | 3 | #include <qpe/categories.h> |
2 | #include <qpe/categoryselect.h> | 4 | #include <qpe/categoryselect.h> |
3 | 5 | ||
4 | #include "opimrecord.h" | 6 | #include "opimrecord.h" |
5 | 7 | ||
6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | 8 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); |
7 | 9 | ||
8 | 10 | ||
9 | OPimRecord::OPimRecord( int uid ) | 11 | OPimRecord::OPimRecord( int uid ) |
10 | : Qtopia::Record() { | 12 | : Qtopia::Record() { |
11 | 13 | ||
12 | setUid( uid ); | 14 | setUid( uid ); |
@@ -73,12 +75,92 @@ void OPimRecord::setUid( int uid ) { | |||
73 | 75 | ||
74 | Qtopia::Record::setUid( uid ); | 76 | Qtopia::Record::setUid( uid ); |
75 | }; | 77 | }; |
76 | Qtopia::UidGen &OPimRecord::uidGen() { | 78 | Qtopia::UidGen &OPimRecord::uidGen() { |
77 | return m_uidGen; | 79 | return m_uidGen; |
78 | } | 80 | } |
79 | OPimXRefManager &OPimRecord::xrefmanager() { | 81 | OPimXRefManager &OPimRecord::xrefmanager() { |
80 | return m_xrefman; | 82 | return m_xrefman; |
81 | } | 83 | } |
82 | int OPimRecord::rtti(){ | 84 | int OPimRecord::rtti(){ |
83 | return 0; | 85 | return 0; |
84 | } | 86 | } |
87 | |||
88 | /** | ||
89 | * now let's put our data into the stream | ||
90 | */ | ||
91 | /* | ||
92 | * First read UID | ||
93 | * Categories | ||
94 | * XRef | ||
95 | */ | ||
96 | bool OPimRecord::loadFromStream( QDataStream& stream ) { | ||
97 | int Int; | ||
98 | uint UInt; | ||
99 | stream >> Int; | ||
100 | setUid(Int); | ||
101 | |||
102 | /** Categories */ | ||
103 | stream >> UInt; | ||
104 | QArray<int> array(UInt); | ||
105 | for (uint i = 0; i < UInt; i++ ) { | ||
106 | stream >> array[i]; | ||
107 | } | ||
108 | setCategories( array ); | ||
109 | |||
110 | /* | ||
111 | * now we do the X-Ref stuff | ||
112 | */ | ||
113 | OPimXRef xref; | ||
114 | stream >> UInt; | ||
115 | for ( uint i = 0; i < UInt; i++ ) { | ||
116 | xref.setPartner( OPimXRef::One, partner( stream ) ); | ||
117 | xref.setPartner( OPimXRef::Two, partner( stream ) ); | ||
118 | m_xrefman.add( xref ); | ||
119 | } | ||
120 | |||
121 | return true; | ||
122 | } | ||
123 | bool OPimRecord::saveToStream( QDataStream& stream )const { | ||
124 | /** UIDs */ | ||
125 | |||
126 | stream << uid(); | ||
127 | |||
128 | /** Categories */ | ||
129 | stream << categories().count(); | ||
130 | for ( uint i = 0; i < categories().count(); i++ ) { | ||
131 | stream << categories()[i]; | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * first the XRef count | ||
136 | * then the xrefs | ||
137 | */ | ||
138 | stream << m_xrefman.list().count(); | ||
139 | for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); | ||
140 | it != m_xrefman.list().end(); ++it ) { | ||
141 | flush( (*it).partner( OPimXRef::One), stream ); | ||
142 | flush( (*it).partner( OPimXRef::Two), stream ); | ||
143 | } | ||
144 | return true; | ||
145 | } | ||
146 | void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ | ||
147 | str << par.service(); | ||
148 | str << par.uid(); | ||
149 | str << par.field(); | ||
150 | } | ||
151 | OPimXRefPartner OPimRecord::partner( QDataStream& stream ) { | ||
152 | OPimXRefPartner par; | ||
153 | QString str; | ||
154 | int i; | ||
155 | |||
156 | stream >> str; | ||
157 | par.setService( str ); | ||
158 | |||
159 | stream >> i; | ||
160 | par.setUid( i ); | ||
161 | |||
162 | stream >> i ; | ||
163 | par.setField( i ); | ||
164 | |||
165 | return par; | ||
166 | } | ||
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h index ec99a13..665530f 100644 --- a/libopie2/opiepim/core/opimrecord.h +++ b/libopie2/opiepim/core/opimrecord.h | |||
@@ -1,15 +1,16 @@ | |||
1 | #ifndef OPIE_PIM_RECORD_H | 1 | #ifndef OPIE_PIM_RECORD_H |
2 | #define OPIE_PIM_RECORD_H | 2 | #define OPIE_PIM_RECORD_H |
3 | 3 | ||
4 | #include <qdatastream.h> | ||
4 | #include <qmap.h> | 5 | #include <qmap.h> |
5 | #include <qstring.h> | 6 | #include <qstring.h> |
6 | #include <qstringlist.h> | 7 | #include <qstringlist.h> |
7 | 8 | ||
8 | #include <qpe/palmtoprecord.h> | 9 | #include <qpe/palmtoprecord.h> |
9 | 10 | ||
10 | #include <opie/opimxrefmanager.h> | 11 | #include <opie/opimxrefmanager.h> |
11 | 12 | ||
12 | /** | 13 | /** |
13 | * This is the base class for | 14 | * This is the base class for |
14 | * all PIM Records | 15 | * all PIM Records |
15 | * | 16 | * |
@@ -96,27 +97,38 @@ public: | |||
96 | 97 | ||
97 | /** | 98 | /** |
98 | * set the uid | 99 | * set the uid |
99 | */ | 100 | */ |
100 | virtual void setUid( int uid ); | 101 | virtual void setUid( int uid ); |
101 | 102 | ||
102 | /* | 103 | /* |
103 | * used inside the Templates for casting | 104 | * used inside the Templates for casting |
104 | * REIMPLEMENT in your .... | 105 | * REIMPLEMENT in your .... |
105 | */ | 106 | */ |
106 | static int rtti(); | 107 | static int rtti(); |
107 | 108 | ||
109 | /** | ||
110 | * some marshalling and de marshalling code | ||
111 | * saves the OPimRecord | ||
112 | * to and from a DataStream | ||
113 | */ | ||
114 | virtual bool loadFromStream(QDataStream& ); | ||
115 | virtual bool saveToStream( QDataStream& stream )const; | ||
116 | |||
108 | protected: | 117 | protected: |
109 | Qtopia::UidGen &uidGen(); | 118 | Qtopia::UidGen &uidGen(); |
110 | // QString crossToString()const; | 119 | // QString crossToString()const; |
111 | 120 | ||
112 | private: | 121 | private: |
113 | class OPimRecordPrivate; | 122 | class OPimRecordPrivate; |
114 | OPimRecordPrivate *d; | 123 | OPimRecordPrivate *d; |
115 | OPimXRefManager m_xrefman; | 124 | OPimXRefManager m_xrefman; |
116 | static Qtopia::UidGen m_uidGen; | 125 | static Qtopia::UidGen m_uidGen; |
117 | 126 | ||
127 | private: | ||
128 | void flush( const OPimXRefPartner&, QDataStream& stream )const; | ||
129 | OPimXRefPartner partner( QDataStream& ); | ||
118 | }; | 130 | }; |
119 | 131 | ||
120 | 132 | ||
121 | 133 | ||
122 | #endif | 134 | #endif |
diff --git a/libopie2/opiepim/core/opimresolver.cpp b/libopie2/opiepim/core/opimresolver.cpp new file mode 100644 index 0000000..4ebbd6e --- a/dev/null +++ b/libopie2/opiepim/core/opimresolver.cpp | |||
@@ -0,0 +1,198 @@ | |||
1 | #include <qcopchannel_qws.h> | ||
2 | |||
3 | #include <qpe/qcopenvelope_qws.h> | ||
4 | |||
5 | #include "otodoaccess.h" | ||
6 | #include "ocontactaccess.h" | ||
7 | |||
8 | //#include "opimfactory.h" | ||
9 | #include "opimresolver.h" | ||
10 | |||
11 | OPimResolver* OPimResolver::m_self = 0l; | ||
12 | |||
13 | OPimResolver::OPimResolver() { | ||
14 | /* the built in channels */ | ||
15 | m_builtIns << "Todolist" << "Addressbook" << "Datebook"; | ||
16 | } | ||
17 | OPimResolver* OPimResolver::self() { | ||
18 | if (!m_self) | ||
19 | m_self = new OPimResolver(); | ||
20 | |||
21 | return m_self; | ||
22 | } | ||
23 | |||
24 | /* | ||
25 | * FIXME use a cache here too | ||
26 | */ | ||
27 | OPimRecord* OPimResolver::record( const QString& service, int uid ) { | ||
28 | OPimRecord* rec = 0l; | ||
29 | OPimBase* base = backend( service ); | ||
30 | |||
31 | if ( base ) | ||
32 | rec = base->record( uid ); | ||
33 | delete base; | ||
34 | |||
35 | return rec; | ||
36 | } | ||
37 | OPimRecord* OPimResolver::record( const QString& service ) { | ||
38 | return record( serviceId( service ) ); | ||
39 | } | ||
40 | OPimRecord* OPimResolver::record( int rtti ) { | ||
41 | OPimRecord* rec = 0l; | ||
42 | switch( rtti ) { | ||
43 | case 1: /* todolist */ | ||
44 | rec = new OTodo(); | ||
45 | case 2: /* contact */ | ||
46 | rec = new OContact(); | ||
47 | default: | ||
48 | break; | ||
49 | } | ||
50 | /* | ||
51 | * FIXME resolve externally | ||
52 | */ | ||
53 | if (!rec ) { | ||
54 | ; | ||
55 | } | ||
56 | return 0l; | ||
57 | } | ||
58 | bool OPimResolver::isBuiltIn( const QString& str) const{ | ||
59 | return m_builtIns.contains( str ); | ||
60 | } | ||
61 | QCString OPimResolver::qcopChannel( enum BuiltIn& built)const { | ||
62 | QCString str("QPE/"); | ||
63 | switch( built ) { | ||
64 | case TodoList: | ||
65 | str += "Todolist"; | ||
66 | break; | ||
67 | case DateBook: | ||
68 | str += "Datebook"; | ||
69 | break; | ||
70 | case AddressBook: | ||
71 | str += "Addressbook"; | ||
72 | break; | ||
73 | default: | ||
74 | break; | ||
75 | } | ||
76 | |||
77 | return str; | ||
78 | } | ||
79 | QCString OPimResolver::qcopChannel( const QString& service )const { | ||
80 | QCString str("QPE/"); | ||
81 | str += service.latin1(); | ||
82 | return str; | ||
83 | } | ||
84 | /* | ||
85 | * Implement services!! | ||
86 | * FIXME | ||
87 | */ | ||
88 | QCString OPimResolver::applicationChannel( enum BuiltIn& built)const { | ||
89 | QCString str("QPE/Application/"); | ||
90 | switch( built ) { | ||
91 | case TodoList: | ||
92 | str += "todolist"; | ||
93 | break; | ||
94 | case DateBook: | ||
95 | str += "datebook"; | ||
96 | break; | ||
97 | case AddressBook: | ||
98 | str += "addressbook"; | ||
99 | break; | ||
100 | } | ||
101 | |||
102 | return str; | ||
103 | } | ||
104 | QCString OPimResolver::applicationChannel( const QString& service )const { | ||
105 | QCString str("QPE/Application/"); | ||
106 | |||
107 | if ( isBuiltIn( service ) ) { | ||
108 | if ( service == "Todolist" ) | ||
109 | str += "todolist"; | ||
110 | else if ( service == "Datebook" ) | ||
111 | str += "datebook"; | ||
112 | else if ( service == "Addressbook" ) | ||
113 | str += "addressbook"; | ||
114 | }else | ||
115 | ; // FIXME for additional stuff | ||
116 | |||
117 | return str; | ||
118 | } | ||
119 | QStringList OPimResolver::services()const { | ||
120 | return m_builtIns; | ||
121 | } | ||
122 | QString OPimResolver::serviceName( int rtti ) const{ | ||
123 | QString str; | ||
124 | switch ( rtti ) { | ||
125 | case TodoList: | ||
126 | str = "Todolist"; | ||
127 | break; | ||
128 | case DateBook: | ||
129 | str = "Datebook"; | ||
130 | break; | ||
131 | case AddressBook: | ||
132 | str = "Addressbook"; | ||
133 | break; | ||
134 | default: | ||
135 | break; | ||
136 | } | ||
137 | return str; | ||
138 | // FIXME me for 3rd party | ||
139 | } | ||
140 | int OPimResolver::serviceId( const QString& service ) { | ||
141 | int rtti = 0; | ||
142 | if ( service == "Todolist" ) | ||
143 | rtti = TodoList; | ||
144 | else if ( service == "Datebook" ) | ||
145 | rtti = DateBook; | ||
146 | else if ( service == "Addressbook" ) | ||
147 | rtti = AddressBook; | ||
148 | |||
149 | return rtti; | ||
150 | } | ||
151 | /** | ||
152 | * check if the 'service' is registered and if so we'll | ||
153 | */ | ||
154 | bool OPimResolver::add( const QString& service, const OPimRecord& rec) { | ||
155 | if ( QCopChannel::isRegistered( applicationChannel( service ) ) ) { | ||
156 | QByteArray data; | ||
157 | QDataStream arg(data, IO_WriteOnly ); | ||
158 | if ( rec.saveToStream( arg ) ) { | ||
159 | QCopEnvelope env( applicationChannel( service ), "add(int,QByteArray)" ); | ||
160 | env << rec.rtti(); | ||
161 | env << data; | ||
162 | }else | ||
163 | return false; | ||
164 | }else{ | ||
165 | OPimBase* base = backend( service ); | ||
166 | if (!base ) return false; | ||
167 | |||
168 | base->load(); | ||
169 | base->add( rec ); | ||
170 | base->save(); | ||
171 | delete base; | ||
172 | } | ||
173 | |||
174 | return true; | ||
175 | } | ||
176 | OPimBase* OPimResolver::backend( const QString& service ) { | ||
177 | return backend( serviceId( service ) ); | ||
178 | } | ||
179 | OPimBase* OPimResolver::backend( int rtti ) { | ||
180 | OPimBase* base = 0l; | ||
181 | switch( rtti ) { | ||
182 | case TodoList: | ||
183 | base = new OTodoAccess(); | ||
184 | break; | ||
185 | case DateBook: | ||
186 | break; | ||
187 | case AddressBook: | ||
188 | base = new OContactAccess("Resolver"); | ||
189 | break; | ||
190 | default: | ||
191 | break; | ||
192 | } | ||
193 | // FIXME for 3rd party | ||
194 | if (!base ) | ||
195 | ; | ||
196 | |||
197 | return base; | ||
198 | } | ||
diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h index 86ae3eb..1ce1619 100644 --- a/libopie2/opiepim/core/opimresolver.h +++ b/libopie2/opiepim/core/opimresolver.h | |||
@@ -1,56 +1,90 @@ | |||
1 | #ifndef OPIE_PIM_RESOLVER | 1 | #ifndef OPIE_PIM_RESOLVER |
2 | #define OPIE_PIM_RESOLVER | 2 | #define OPIE_PIM_RESOLVER |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | 6 | ||
7 | #include <opie/otemplatebase.h> | ||
8 | |||
7 | /** | 9 | /** |
8 | * OPimResolver is a MetaClass to access | 10 | * OPimResolver is a MetaClass to access |
9 | * available backends read only. | 11 | * available backends read only. |
10 | * It will be used to resolve uids + app names | 12 | * It will be used to resolve uids + app names |
11 | * to full informations | 13 | * to full informations |
12 | * to traverse through a list of alarms, reminders | 14 | * to traverse through a list of alarms, reminders |
13 | * to get access to built in PIM functionality | 15 | * to get access to built in PIM functionality |
14 | * and to more stuff | 16 | * and to more stuff |
15 | * THE PERFORMANCE will depend on THE BACKEND | 17 | * THE PERFORMANCE will depend on THE BACKEND |
16 | * USING XML is a waste of memory!!!!! | 18 | * USING XML is a waste of memory!!!!! |
17 | */ | 19 | */ |
18 | class OPimResolver : public QObject { | 20 | class OPimResolver { |
19 | public: | 21 | public: |
20 | enum BuiltIn { TodoList = 0, | 22 | enum BuiltIn { TodoList = 0, |
21 | DateBook, | 23 | DateBook, |
22 | AddressBook | 24 | AddressBook |
23 | }; | 25 | }; |
24 | static OPimResolver* self(); | 26 | static OPimResolver* self(); |
25 | 27 | ||
26 | 28 | ||
27 | /* | 29 | /** |
28 | * return a record for a uid | 30 | * return a record for a uid |
29 | * and an app | 31 | * and an service |
32 | * You've THE OWNERSHIP NOW! | ||
30 | */ | 33 | */ |
31 | OPimRecord &record( const QString& service, int uid ); | 34 | OPimRecord *record( const QString& service, int uid ); |
32 | 35 | ||
33 | /** | 36 | /** |
34 | * return the QCopChannel for service | 37 | * return the QCopChannel for service |
35 | * When we will use Qtopia Services it will be used here | 38 | * When we will use Qtopia Services it will be used here |
36 | */ | 39 | */ |
37 | QString qcopChannel( enum BuiltIn& )const; | 40 | QCString qcopChannel( enum BuiltIn& )const; |
38 | QString qcopChannel( const QString& service ); | 41 | QCString qcopChannel( const QString& service )const; |
42 | |||
43 | /** | ||
44 | * The Application channel (QPE/Application/name) | ||
45 | */ | ||
46 | QCString applicationChannel( enum BuiltIn& )const; | ||
47 | QCString applicationChannel( const QString& service )const; | ||
39 | 48 | ||
40 | /** | 49 | /** |
41 | * return a list of available services | 50 | * return a list of available services |
42 | */ | 51 | */ |
43 | QStringList services()const; | 52 | QStringList services()const; |
44 | 53 | inline QString serviceName(int rrti )const; | |
54 | int serviceId( const QString& Service); | ||
45 | /** | 55 | /** |
46 | * add a record to a service... ;) | 56 | * add a record to a service... ;) |
47 | */ | 57 | */ |
48 | bool add( const QString& service, const OPimRecord& ); | 58 | bool add( const QString& service, const OPimRecord& ); |
49 | 59 | ||
60 | |||
61 | /** | ||
62 | * record returns an empty record for a given service. | ||
63 | * Be sure to delete it!!! | ||
64 | * | ||
65 | */ | ||
66 | OPimRecord* record( const QString& service ); | ||
67 | OPimRecord* record( int rtti ); | ||
68 | |||
69 | /** | ||
70 | * you can cast to your | ||
71 | */ | ||
72 | OPimBase* backend( const QString& service ); | ||
73 | OPimBase* backend( int rtti ); | ||
50 | private: | 74 | private: |
51 | OPimResolver(); | 75 | OPimResolver(); |
52 | OPimRecord *m_last; | 76 | void loadData(); |
77 | inline bool isBuiltIn( const QString& )const; | ||
78 | OPimRecord* recordExtern( const QString&, int ); | ||
79 | OPimRecord* recordExtern( const QString& ); | ||
80 | |||
81 | static OPimResolver* m_self; | ||
82 | struct Data; | ||
83 | class Private; | ||
53 | 84 | ||
54 | }: | 85 | Data* data; |
86 | Private* d; | ||
87 | QStringList m_builtIns; | ||
88 | }; | ||
55 | 89 | ||
56 | #endif | 90 | #endif |
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h index b855919..29fb6ec 100644 --- a/libopie2/opiepim/core/otemplatebase.h +++ b/libopie2/opiepim/core/otemplatebase.h | |||
@@ -1,32 +1,91 @@ | |||
1 | #ifndef OPIE_TEMPLATE_BASE_H | 1 | #ifndef OPIE_TEMPLATE_BASE_H |
2 | #define OPIE_TEMPLATE_BASE_H | 2 | #define OPIE_TEMPLATE_BASE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include "opimrecord.h" | 6 | #include <opie/opimrecord.h> |
7 | |||
7 | 8 | ||
8 | /** | 9 | /** |
10 | * Templates do not have a base class, This is why | ||
11 | * we've this class | ||
12 | * this is here to give us the possibility | ||
13 | * to have a common base class | ||
14 | * You may not want to use that interface internaly | ||
15 | * POOR mans interface | ||
16 | */ | ||
17 | struct OPimBase { | ||
18 | /** | ||
19 | * return the rtti | ||
20 | */ | ||
21 | virtual int rtti()= 0; | ||
22 | virtual OPimRecord* record()const = 0; | ||
23 | virtual OPimRecord* record(int uid)const = 0; | ||
24 | virtual bool add( const OPimRecord& ) = 0; | ||
25 | virtual bool remove( int uid ) = 0; | ||
26 | virtual bool remove( const OPimRecord& ) = 0; | ||
27 | virtual void clear() = 0; | ||
28 | virtual bool load() = 0; | ||
29 | virtual bool save() = 0; | ||
30 | virtual QArray<int> records()const = 0; | ||
31 | /* | ||
32 | * ADD editing here? | ||
33 | * -zecke | ||
34 | */ | ||
35 | |||
36 | }; | ||
37 | /** | ||
9 | * internal template base | 38 | * internal template base |
39 | * T needs to implement the copy c'tor!!! | ||
10 | */ | 40 | */ |
11 | template <class T = OPimRecord> | 41 | template <class T = OPimRecord> |
12 | class OTemplateBase { | 42 | class OTemplateBase : public OPimBase { |
13 | public: | 43 | public: |
14 | enum CacheDirection { Forward=0, Reverse }; | 44 | enum CacheDirection { Forward=0, Reverse }; |
15 | OTemplateBase() { | 45 | OTemplateBase() { |
16 | }; | 46 | }; |
17 | virtual ~OTemplateBase() { | 47 | virtual ~OTemplateBase() { |
18 | } | 48 | } |
19 | virtual T find( int uid )const = 0; | 49 | virtual T find( int uid )const = 0; |
20 | 50 | ||
21 | /** | 51 | /** |
22 | * read ahead find | 52 | * read ahead find |
23 | */ | 53 | */ |
24 | virtual T find( int uid, const QArray<int>& items, | 54 | virtual T find( int uid, const QArray<int>& items, |
25 | uint current, CacheDirection dir = Forward )const = 0; | 55 | uint current, CacheDirection dir = Forward )const = 0; |
26 | virtual void cache( const T& )const = 0; | 56 | virtual void cache( const T& )const = 0; |
27 | virtual void setSaneCacheSize( int ) = 0; | 57 | virtual void setSaneCacheSize( int ) = 0; |
28 | 58 | ||
59 | /* reimplement of OPimBase */ | ||
60 | int rtti(); | ||
61 | OPimRecord* record()const; | ||
62 | OPimRecord* record(int uid )const; | ||
63 | static T* rec(); | ||
29 | }; | 64 | }; |
30 | 65 | ||
66 | /* | ||
67 | * implementation | ||
68 | */ | ||
69 | template <class T> | ||
70 | int | ||
71 | OTemplateBase<T>::rtti() { | ||
72 | return T::rtti(); | ||
73 | } | ||
74 | template <class T> | ||
75 | OPimRecord* OTemplateBase<T>::record()const { | ||
76 | T* t = new T; | ||
77 | return t; | ||
78 | } | ||
79 | template <class T> | ||
80 | OPimRecord* OTemplateBase<T>::record(int uid )const { | ||
81 | T t2 = find(uid ); | ||
82 | T* t1 = new T(t2); | ||
83 | |||
84 | return t1; | ||
85 | }; | ||
86 | template <class T> | ||
87 | T* OTemplateBase<T>::rec() { | ||
88 | return new T; | ||
89 | } | ||
31 | 90 | ||
32 | #endif | 91 | #endif |
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index d860411..5e89a1b 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp | |||
@@ -1,21 +1,21 @@ | |||
1 | #include <qdatetime.h> | 1 | #include <qdatetime.h> |
2 | 2 | ||
3 | #include <qpe/alarmserver.h> | 3 | #include <qpe/alarmserver.h> |
4 | 4 | ||
5 | // #include "otodoaccesssql.h" | 5 | // #include "otodoaccesssql.h" |
6 | #include "otodoaccess.h" | 6 | #include "otodoaccess.h" |
7 | #include "obackendfactory.h" | 7 | #include "obackendfactory.h" |
8 | 8 | ||
9 | OTodoAccess::OTodoAccess( OTodoAccessBackend* end ) | 9 | OTodoAccess::OTodoAccess( OTodoAccessBackend* end, enum Access ) |
10 | : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) | 10 | : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) |
11 | { | 11 | { |
12 | // if (end == 0l ) | 12 | // if (end == 0l ) |
13 | // m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); | 13 | // m_todoBackEnd = new OTodoAccessBackendSQL( QString::null); |
14 | 14 | ||
15 | // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben ! | 15 | // Zecke: Du musst hier noch für das XML-Backend einen Appnamen übergeben ! |
16 | if (end == 0l ) | 16 | if (end == 0l ) |
17 | m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); | 17 | m_todoBackEnd = OBackendFactory<OTodoAccessBackend>::Default ("todo", QString::null); |
18 | 18 | ||
19 | setBackEnd( m_todoBackEnd ); | 19 | setBackEnd( m_todoBackEnd ); |
20 | } | 20 | } |
21 | OTodoAccess::~OTodoAccess() { | 21 | OTodoAccess::~OTodoAccess() { |
@@ -35,52 +35,22 @@ OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, | |||
35 | List lis( ints, this ); | 35 | List lis( ints, this ); |
36 | return lis; | 36 | return lis; |
37 | } | 37 | } |
38 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, | 38 | OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, |
39 | bool includeNoDates ) { | 39 | bool includeNoDates ) { |
40 | return effectiveToDos( start, QDate::currentDate(), | 40 | return effectiveToDos( start, QDate::currentDate(), |
41 | includeNoDates ); | 41 | includeNoDates ); |
42 | } | 42 | } |
43 | OTodoAccess::List OTodoAccess::overDue() { | 43 | OTodoAccess::List OTodoAccess::overDue() { |
44 | List lis( m_todoBackEnd->overDue(), this ); | 44 | List lis( m_todoBackEnd->overDue(), this ); |
45 | return lis; | 45 | return lis; |
46 | } | 46 | } |
47 | void OTodoAccess::addAlarm( const OTodo& event) { | ||
48 | /* FIXME use the new notifier architecture | ||
49 | if (!event.hasAlarmDateTime() ) | ||
50 | return; | ||
51 | |||
52 | QDateTime now = QDateTime::currentDateTime(); | ||
53 | QDateTime schedule = event.alarmDateTime(); | ||
54 | |||
55 | if ( schedule > now ){ | ||
56 | AlarmServer::addAlarm( schedule, | ||
57 | "QPE/Application/todolist", | ||
58 | "alarm(QDateTime,int)", event.uid() ); | ||
59 | |||
60 | } | ||
61 | */ | ||
62 | } | ||
63 | void OTodoAccess::delAlarm( int uid) { | ||
64 | |||
65 | QDateTime schedule; // Create null DateTime | ||
66 | |||
67 | // I hope this will remove all scheduled alarms | ||
68 | // with the given uid !? | ||
69 | // If not: I have to rethink how to remove already | ||
70 | // scheduled events... (se) | ||
71 | // it should be fine -zecke | ||
72 | // qWarning("Removing alarm for event with uid %d", uid ); | ||
73 | AlarmServer::deleteAlarm( schedule , | ||
74 | "QPE/Application/todolist", | ||
75 | "alarm(QDateTime,int)", uid ); | ||
76 | } | ||
77 | /* sort order */ | 47 | /* sort order */ |
78 | OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { | 48 | OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { |
79 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, | 49 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, |
80 | filter, cat ); | 50 | filter, cat ); |
81 | OTodoAccess::List list( ints, this ); | 51 | OTodoAccess::List list( ints, this ); |
82 | return list; | 52 | return list; |
83 | } | 53 | } |
84 | void OTodoAccess::removeAllCompleted() { | 54 | void OTodoAccess::removeAllCompleted() { |
85 | m_todoBackEnd->removeAllCompleted(); | 55 | m_todoBackEnd->removeAllCompleted(); |
86 | } | 56 | } |
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index c079155..2bb87dc 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h | |||
@@ -20,25 +20,25 @@ public: | |||
20 | enum SortOrder { Completed = 0, | 20 | enum SortOrder { Completed = 0, |
21 | Priority, | 21 | Priority, |
22 | Description, | 22 | Description, |
23 | Deadline }; | 23 | Deadline }; |
24 | enum SortFilter{ Category =1, | 24 | enum SortFilter{ Category =1, |
25 | OnlyOverDue= 2, | 25 | OnlyOverDue= 2, |
26 | DoNotShowCompleted =4 }; | 26 | DoNotShowCompleted =4 }; |
27 | /** | 27 | /** |
28 | * if you use 0l | 28 | * if you use 0l |
29 | * the default resource will be | 29 | * the default resource will be |
30 | * picked up | 30 | * picked up |
31 | */ | 31 | */ |
32 | OTodoAccess( OTodoAccessBackend* = 0l); | 32 | OTodoAccess( OTodoAccessBackend* = 0l, enum Access acc = Random ); |
33 | ~OTodoAccess(); | 33 | ~OTodoAccess(); |
34 | 34 | ||
35 | 35 | ||
36 | /* our functions here */ | 36 | /* our functions here */ |
37 | /** | 37 | /** |
38 | * include todos from start to end | 38 | * include todos from start to end |
39 | * includeNoDates whether or not to include | 39 | * includeNoDates whether or not to include |
40 | * events with no dates | 40 | * events with no dates |
41 | */ | 41 | */ |
42 | List effectiveToDos( const QDate& start, | 42 | List effectiveToDos( const QDate& start, |
43 | const QDate& end, | 43 | const QDate& end, |
44 | bool includeNoDates = true ); | 44 | bool includeNoDates = true ); |
@@ -69,30 +69,19 @@ public: | |||
69 | 69 | ||
70 | /** | 70 | /** |
71 | * delete all already completed items | 71 | * delete all already completed items |
72 | */ | 72 | */ |
73 | void removeAllCompleted(); | 73 | void removeAllCompleted(); |
74 | 74 | ||
75 | signals: | 75 | signals: |
76 | /** | 76 | /** |
77 | * if the OTodoAccess was changed | 77 | * if the OTodoAccess was changed |
78 | */ | 78 | */ |
79 | void signalChanged( const OTodoAccess* ); | 79 | void signalChanged( const OTodoAccess* ); |
80 | private: | 80 | private: |
81 | /** | ||
82 | * add an Alarm to the AlarmServer | ||
83 | */ | ||
84 | void addAlarm( const OTodo& ); | ||
85 | |||
86 | /** | ||
87 | * delete an alarm with the uid from | ||
88 | * the alarm server | ||
89 | */ | ||
90 | void delAlarm( int uid ); | ||
91 | |||
92 | int m_cat; | 81 | int m_cat; |
93 | OTodoAccessBackend* m_todoBackEnd; | 82 | OTodoAccessBackend* m_todoBackEnd; |
94 | class OTodoAccessPrivate; | 83 | class OTodoAccessPrivate; |
95 | OTodoAccessPrivate* d; | 84 | OTodoAccessPrivate* d; |
96 | }; | 85 | }; |
97 | 86 | ||
98 | #endif | 87 | #endif |
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp index 6aec62e..38cba72 100644 --- a/libopie2/opiepim/ocontact.cpp +++ b/libopie2/opiepim/ocontact.cpp | |||
@@ -13,24 +13,25 @@ | |||
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #define QTOPIA_INTERNAL_CONTACT_MRE | 22 | #define QTOPIA_INTERNAL_CONTACT_MRE |
23 | 23 | ||
24 | #include "ocontact.h" | 24 | #include "ocontact.h" |
25 | #include "opimresolver.h" | ||
25 | 26 | ||
26 | #include <qpe/stringutil.h> | 27 | #include <qpe/stringutil.h> |
27 | #include <qpe/timeconversion.h> | 28 | #include <qpe/timeconversion.h> |
28 | #include <qpe/timestring.h> | 29 | #include <qpe/timestring.h> |
29 | 30 | ||
30 | #include <qobject.h> | 31 | #include <qobject.h> |
31 | #include <qregexp.h> | 32 | #include <qregexp.h> |
32 | #include <qstylesheet.h> | 33 | #include <qstylesheet.h> |
33 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
34 | #include <qmap.h> | 35 | #include <qmap.h> |
35 | 36 | ||
36 | #include <stdio.h> | 37 | #include <stdio.h> |
@@ -820,25 +821,25 @@ void OContact::save( QString &buf ) const | |||
820 | buf += customToXml(); | 821 | buf += customToXml(); |
821 | if ( categories().count() > 0 ) | 822 | if ( categories().count() > 0 ) |
822 | buf += "Categories=\"" + idsToString( categories() ) + "\" "; | 823 | buf += "Categories=\"" + idsToString( categories() ) + "\" "; |
823 | buf += "Uid=\"" + QString::number( uid() ) + "\" "; | 824 | buf += "Uid=\"" + QString::number( uid() ) + "\" "; |
824 | // You need to close this yourself | 825 | // You need to close this yourself |
825 | } | 826 | } |
826 | 827 | ||
827 | 828 | ||
828 | /*! | 829 | /*! |
829 | \internal | 830 | \internal |
830 | Returns the list of fields belonging to a contact | 831 | Returns the list of fields belonging to a contact |
831 | Never change order of this list ! It has to be regarding | 832 | Never change order of this list ! It has to be regarding |
832 | enum AddressBookFields !! | 833 | enum AddressBookFields !! |
833 | */ | 834 | */ |
834 | QStringList OContact::fields() | 835 | QStringList OContact::fields() |
835 | { | 836 | { |
836 | QStringList list; | 837 | QStringList list; |
837 | 838 | ||
838 | list.append( "Title" ); // Not Used! | 839 | list.append( "Title" ); // Not Used! |
839 | list.append( "FirstName" ); | 840 | list.append( "FirstName" ); |
840 | list.append( "MiddleName" ); | 841 | list.append( "MiddleName" ); |
841 | list.append( "LastName" ); | 842 | list.append( "LastName" ); |
842 | list.append( "Suffix" ); | 843 | list.append( "Suffix" ); |
843 | list.append( "FileAs" ); | 844 | list.append( "FileAs" ); |
844 | 845 | ||
@@ -1091,19 +1092,19 @@ void OContact::setDefaultEmail( const QString &v ) | |||
1091 | 1092 | ||
1092 | if ( !e.isEmpty() ) | 1093 | if ( !e.isEmpty() ) |
1093 | insertEmail( e ); | 1094 | insertEmail( e ); |
1094 | 1095 | ||
1095 | } | 1096 | } |
1096 | 1097 | ||
1097 | void OContact::insertEmails( const QStringList &v ) | 1098 | void OContact::insertEmails( const QStringList &v ) |
1098 | { | 1099 | { |
1099 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) | 1100 | for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) |
1100 | insertEmail( *it ); | 1101 | insertEmail( *it ); |
1101 | } | 1102 | } |
1102 | int OContact::rtti() { | 1103 | int OContact::rtti() { |
1103 | return 2; | 1104 | return OPimResolver::AddressBook; |
1104 | } | 1105 | } |
1105 | void OContact::setUid( int i ) | 1106 | void OContact::setUid( int i ) |
1106 | { | 1107 | { |
1107 | OPimRecord::setUid(i); | 1108 | OPimRecord::setUid(i); |
1108 | replace( Qtopia::AddressUid , QString::number(i)); | 1109 | replace( Qtopia::AddressUid , QString::number(i)); |
1109 | } | 1110 | } |
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index ece624a..cde2b3d 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp | |||
@@ -7,24 +7,25 @@ | |||
7 | #include <qpe/palmtopuidgen.h> | 7 | #include <qpe/palmtopuidgen.h> |
8 | #include <qpe/stringutil.h> | 8 | #include <qpe/stringutil.h> |
9 | #include <qpe/palmtoprecord.h> | 9 | #include <qpe/palmtoprecord.h> |
10 | #include <qpe/stringutil.h> | 10 | #include <qpe/stringutil.h> |
11 | #include <qpe/categories.h> | 11 | #include <qpe/categories.h> |
12 | #include <qpe/categoryselect.h> | 12 | #include <qpe/categoryselect.h> |
13 | 13 | ||
14 | 14 | ||
15 | #include "opimstate.h" | 15 | #include "opimstate.h" |
16 | #include "orecur.h" | 16 | #include "orecur.h" |
17 | #include "opimmaintainer.h" | 17 | #include "opimmaintainer.h" |
18 | #include "opimnotifymanager.h" | 18 | #include "opimnotifymanager.h" |
19 | #include "opimresolver.h" | ||
19 | 20 | ||
20 | #include "otodo.h" | 21 | #include "otodo.h" |
21 | 22 | ||
22 | 23 | ||
23 | struct OTodo::OTodoData : public QShared { | 24 | struct OTodo::OTodoData : public QShared { |
24 | OTodoData() : QShared() { | 25 | OTodoData() : QShared() { |
25 | }; | 26 | }; |
26 | 27 | ||
27 | QDate date; | 28 | QDate date; |
28 | bool isCompleted:1; | 29 | bool isCompleted:1; |
29 | bool hasDate:1; | 30 | bool hasDate:1; |
30 | int priority; | 31 | int priority; |
@@ -408,14 +409,14 @@ void OTodo::copy( OTodoData* src, OTodoData* dest ) { | |||
408 | dest->start = src->start; | 409 | dest->start = src->start; |
409 | dest->completed = src->completed; | 410 | dest->completed = src->completed; |
410 | dest->notifiers = src->notifiers; | 411 | dest->notifiers = src->notifiers; |
411 | } | 412 | } |
412 | QString OTodo::type() const { | 413 | QString OTodo::type() const { |
413 | return QString::fromLatin1("OTodo"); | 414 | return QString::fromLatin1("OTodo"); |
414 | } | 415 | } |
415 | QString OTodo::recordField(int /*id*/ )const { | 416 | QString OTodo::recordField(int /*id*/ )const { |
416 | return QString::null; | 417 | return QString::null; |
417 | } | 418 | } |
418 | 419 | ||
419 | int OTodo::rtti(){ | 420 | int OTodo::rtti(){ |
420 | return 1; | 421 | return OPimResolver::TodoList; |
421 | } | 422 | } |
diff --git a/libopie2/opiepim/ui/opimmainwindow.cpp b/libopie2/opiepim/ui/opimmainwindow.cpp index 92be2fd..7e57f3a 100644 --- a/libopie2/opiepim/ui/opimmainwindow.cpp +++ b/libopie2/opiepim/ui/opimmainwindow.cpp | |||
@@ -1,43 +1,47 @@ | |||
1 | #include <qapplication.h> | 1 | #include <qapplication.h> |
2 | #include <qcopchannel_qws.h> | 2 | #include <qcopchannel_qws.h> |
3 | 3 | ||
4 | #include <qpe/qcopenvelope_qws.h> | 4 | #include <qpe/qcopenvelope_qws.h> |
5 | 5 | ||
6 | #include "opimresolver.h" | ||
6 | #include "opimmainwindow.h" | 7 | #include "opimmainwindow.h" |
7 | 8 | ||
8 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, | 9 | OPimMainWindow::OPimMainWindow( const QString& service, QWidget* parent, |
9 | const char* name, WFlags flag ) | 10 | const char* name, WFlags flag ) |
10 | : QMainWindow( parent, name, flag ), m_service( service ), m_fallBack(0l) { | 11 | : QMainWindow( parent, name, flag ), m_rtti(-1), m_service( service ), m_fallBack(0l) { |
11 | 12 | ||
12 | /* | 13 | /* |
13 | * let's generate our QCopChannel | 14 | * let's generate our QCopChannel |
14 | */ | 15 | */ |
15 | m_str = QString("QPE/"+m_service).local8Bit(); | 16 | m_str = QString("QPE/"+m_service).local8Bit(); |
16 | m_channel= new QCopChannel(m_str, this ); | 17 | m_channel= new QCopChannel(m_str, this ); |
17 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), | 18 | connect(m_channel, SIGNAL(received(const QCString&, const QByteArray& ) ), |
18 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 19 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
19 | 20 | ||
20 | /* connect flush and reload */ | 21 | /* connect flush and reload */ |
21 | connect(qApp, SIGNAL(flush() ), | 22 | connect(qApp, SIGNAL(flush() ), |
22 | this, SLOT(flush() ) ); | 23 | this, SLOT(flush() ) ); |
23 | connect(qApp, SIGNAL(reload() ), | 24 | connect(qApp, SIGNAL(reload() ), |
24 | this, SLOT(reload() ) ); | 25 | this, SLOT(reload() ) ); |
25 | } | 26 | } |
26 | OPimMainWindow::~OPimMainWindow() { | 27 | OPimMainWindow::~OPimMainWindow() { |
27 | delete m_channel; | 28 | delete m_channel; |
28 | } | 29 | } |
29 | QCopChannel* OPimMainWindow::channel() { | 30 | QCopChannel* OPimMainWindow::channel() { |
30 | return m_channel; | 31 | return m_channel; |
31 | } | 32 | } |
33 | void OPimMainWindow::doSetDocument( const QString& ) { | ||
34 | |||
35 | } | ||
32 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { | 36 | void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) { |
33 | /* | 37 | /* |
34 | * create demands to create | 38 | * create demands to create |
35 | * a new record... | 39 | * a new record... |
36 | */ | 40 | */ |
37 | QDataStream stream(array, IO_ReadOnly); | 41 | QDataStream stream(array, IO_ReadOnly); |
38 | if ( cmd == "create()" ) { | 42 | if ( cmd == "create()" ) { |
39 | int uid = create(); | 43 | int uid = create(); |
40 | QCopEnvelope e(m_str, "created(int)" ); | 44 | QCopEnvelope e(m_str, "created(int)" ); |
41 | e << uid; | 45 | e << uid; |
42 | }else if ( cmd == "remove(int)" ) { | 46 | }else if ( cmd == "remove(int)" ) { |
43 | int uid; | 47 | int uid; |
@@ -60,12 +64,42 @@ void OPimMainWindow::appMessage( const QCString& cmd, const QByteArray& array ) | |||
60 | edit( uid ); | 64 | edit( uid ); |
61 | }else if ( cmd == "add(int,QByteArray)" ) { | 65 | }else if ( cmd == "add(int,QByteArray)" ) { |
62 | int rtti; | 66 | int rtti; |
63 | QByteArray array; | 67 | QByteArray array; |
64 | stream >> rtti; | 68 | stream >> rtti; |
65 | stream >> array; | 69 | stream >> array; |
66 | m_fallBack = record(rtti, array ); | 70 | m_fallBack = record(rtti, array ); |
67 | if (!m_fallBack) return; | 71 | if (!m_fallBack) return; |
68 | add( *m_fallBack ); | 72 | add( *m_fallBack ); |
69 | delete m_fallBack; | 73 | delete m_fallBack; |
70 | } | 74 | } |
71 | } | 75 | } |
76 | /* implement the url scripting here */ | ||
77 | void OPimMainWindow::setDocument( const QString& str) { | ||
78 | doSetDocument( str ); | ||
79 | } | ||
80 | /* | ||
81 | * we now try to get the array demarshalled | ||
82 | * check if the rtti matches this one | ||
83 | */ | ||
84 | OPimRecord* OPimMainWindow::record( int rtti, const QByteArray& array ) { | ||
85 | if ( service() != rtti ) | ||
86 | return 0l; | ||
87 | |||
88 | OPimRecord* record = OPimResolver::self()->record( rtti ); | ||
89 | QDataStream str(array, IO_ReadOnly ); | ||
90 | if ( !record || !record->loadFromStream(str) ) { | ||
91 | delete record; | ||
92 | record = 0l; | ||
93 | } | ||
94 | |||
95 | return record; | ||
96 | } | ||
97 | /* | ||
98 | * get the rtti for the service | ||
99 | */ | ||
100 | int OPimMainWindow::service() { | ||
101 | if ( m_rtti == -1 ) | ||
102 | m_rtti = OPimResolver::self()->serviceId( m_service ); | ||
103 | |||
104 | return m_rtti; | ||
105 | } | ||
diff --git a/libopie2/opiepim/ui/opimmainwindow.h b/libopie2/opiepim/ui/opimmainwindow.h index 94100bd..34b8a71 100644 --- a/libopie2/opiepim/ui/opimmainwindow.h +++ b/libopie2/opiepim/ui/opimmainwindow.h | |||
@@ -23,57 +23,67 @@ class QCopChannel; | |||
23 | class OPimMainWindow : public QMainWindow { | 23 | class OPimMainWindow : public QMainWindow { |
24 | Q_OBJECT | 24 | Q_OBJECT |
25 | public: | 25 | public: |
26 | enum TransPort { BlueTooth=0, | 26 | enum TransPort { BlueTooth=0, |
27 | IrDa }; | 27 | IrDa }; |
28 | 28 | ||
29 | OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, | 29 | OPimMainWindow( const QString& service, QWidget *parent = 0, const char* name = 0, |
30 | WFlags f = WType_TopLevel); | 30 | WFlags f = WType_TopLevel); |
31 | virtual ~OPimMainWindow(); | 31 | virtual ~OPimMainWindow(); |
32 | 32 | ||
33 | 33 | ||
34 | protected slots: | 34 | protected slots: |
35 | /* | ||
36 | * called when a setDocument | ||
37 | * couldn't be handled by this window | ||
38 | */ | ||
39 | virtual void doSetDocument( const QString& ); | ||
35 | /* for syncing */ | 40 | /* for syncing */ |
36 | virtual void flush() = 0; | 41 | virtual void flush() = 0; |
37 | virtual void reload() = 0; | 42 | virtual void reload() = 0; |
38 | 43 | ||
39 | /** create a new Records and return the uid */ | 44 | /** create a new Records and return the uid */ |
40 | virtual int create() = 0; | 45 | virtual int create() = 0; |
41 | /** remove a record with UID == uid */ | 46 | /** remove a record with UID == uid */ |
42 | virtual bool remove( int uid ) = 0; | 47 | virtual bool remove( int uid ) = 0; |
43 | /** beam the record with UID = uid */ | 48 | /** beam the record with UID = uid */ |
44 | virtual void beam( int uid , int transport = IrDa) = 0; | 49 | virtual void beam( int uid , int transport = IrDa) = 0; |
45 | 50 | ||
46 | /** show the record with UID == uid */ | 51 | /** show the record with UID == uid */ |
47 | virtual void show( int uid ) = 0; | 52 | virtual void show( int uid ) = 0; |
48 | /** edit the record */ | 53 | /** edit the record */ |
49 | virtual void edit( int uid ) = 0; | 54 | virtual void edit( int uid ) = 0; |
50 | 55 | ||
51 | /** make a copy of it! */ | 56 | /** make a copy of it! */ |
52 | virtual void add( const OPimRecord& ) = 0; | 57 | virtual void add( const OPimRecord& ) = 0; |
53 | 58 | ||
54 | /* I would love to do this as a template | 59 | |
55 | * but can't think of a right way | ||
56 | * because I need signal and slots -zecke | ||
57 | */ | ||
58 | /* | ||
59 | * the only pointer in the whole PIM API :( | ||
60 | */ | ||
61 | virtual OPimRecord* record( int rtti, const QByteArray& ) = 0; | ||
62 | QCopChannel* channel(); | 60 | QCopChannel* channel(); |
63 | 61 | ||
64 | private slots: | 62 | private slots: |
65 | void appMessage( const QCString&, const QByteArray& ); | 63 | void appMessage( const QCString&, const QByteArray& ); |
64 | void setDocument( const QString& ); | ||
66 | 65 | ||
67 | 66 | ||
68 | private: | 67 | private: |
69 | class Private; | 68 | class Private; |
70 | Private* d; | 69 | Private* d; |
71 | 70 | ||
71 | int m_rtti; | ||
72 | QCopChannel* m_channel; | 72 | QCopChannel* m_channel; |
73 | QString m_service; | 73 | QString m_service; |
74 | QCString m_str; | 74 | QCString m_str; |
75 | OPimRecord* m_fallBack; | 75 | OPimRecord* m_fallBack; |
76 | |||
77 | /* I would love to do this as a template | ||
78 | * but can't think of a right way | ||
79 | * because I need signal and slots -zecke | ||
80 | */ | ||
81 | /* | ||
82 | * the only pointer in the whole PIM API :( | ||
83 | */ | ||
84 | virtual OPimRecord* record( int rtti, const QByteArray& ) ; | ||
85 | int service(); | ||
76 | }; | 86 | }; |
77 | 87 | ||
78 | 88 | ||
79 | #endif | 89 | #endif |