Diffstat (limited to 'libopie2/opiepim/core/ocontactaccess.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h new file mode 100644 index 0000000..54f7f07 --- a/dev/null +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -0,0 +1,197 @@ | |||
1 | /* | ||
2 | * Class to manage the Contacts. | ||
3 | * | ||
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * Copyright (c) 2002 by Holger Freyther (zecke@handhelds.org) | ||
6 | * | ||
7 | * ===================================================================== | ||
8 | *This program is free software; you can redistribute it and/or | ||
9 | *modify it under the terms of the GNU Library General Public | ||
10 | * License as published by the Free Software Foundation; | ||
11 | * either version 2 of the License, or (at your option) any later | ||
12 | * version. | ||
13 | * ===================================================================== | ||
14 | * ToDo: Define enum for query settings | ||
15 | * ===================================================================== | ||
16 | * Version: $Id$ | ||
17 | * ===================================================================== | ||
18 | * History: | ||
19 | * $Log$ | ||
20 | * Revision 1.1 2002/09/27 17:11:44 eilers | ||
21 | * Added API for accessing the Contact-Database ! It is compiling, but | ||
22 | * please do not expect that anything is working ! | ||
23 | * I will debug that stuff in the next time .. | ||
24 | * Please read README_COMPILE for compiling ! | ||
25 | * | ||
26 | * ===================================================================== | ||
27 | */ | ||
28 | #ifndef _OCONTACTACCESS_H | ||
29 | #define _OCONTACTACCESS_H | ||
30 | |||
31 | #include <qobject.h> | ||
32 | |||
33 | #include <qpe/qcopenvelope_qws.h> | ||
34 | |||
35 | #include <qvaluelist.h> | ||
36 | #include <qfileinfo.h> | ||
37 | |||
38 | #include "ocontact.h" | ||
39 | #include "ocontactaccessbackend.h" | ||
40 | #include "opimaccesstemplate.h" | ||
41 | |||
42 | /** Class to access the contacts database. | ||
43 | * This is just a frontend for the real database handling which is | ||
44 | * done by the backend. | ||
45 | */ | ||
46 | class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | ||
47 | { | ||
48 | Q_OBJECT | ||
49 | |||
50 | |||
51 | /* class Iterator{ | ||
52 | friend OContactAccess; | ||
53 | public: | ||
54 | Iterator(); | ||
55 | Iterator ( const Iterator& copy ); | ||
56 | |||
57 | bool operator== ( const Iterator& it ); | ||
58 | bool operator!= ( const Iterator& it ); | ||
59 | Iterator& operator= ( const Iterator& it ); | ||
60 | Iterator& operator++ (); // prefix | ||
61 | Iterator operator++ ( int ); // postfix | ||
62 | Iterator& operator-- (); // prefix | ||
63 | Iterator operator-- ( int ); // postfix | ||
64 | Contact operator*() const; | ||
65 | Contact operator->() const; | ||
66 | |||
67 | Iterator begin(); | ||
68 | Iterator end(); | ||
69 | |||
70 | uint count() const; | ||
71 | |||
72 | private: | ||
73 | QValueList<int> m_uids; | ||
74 | int m_cur_position; | ||
75 | bool m_end_reached; | ||
76 | OContactAccess *m_db; | ||
77 | |||
78 | }; | ||
79 | |||
80 | */ | ||
81 | |||
82 | public: | ||
83 | /** Create Database with contacts (addressbook). | ||
84 | * @param appname Name of application which wants access to the database | ||
85 | * (i.e. "todolist") | ||
86 | * @param filename The name of the database file. If not set, the default one | ||
87 | * is used. | ||
88 | * @param backend Pointer to an alternative Backend. If not set, we will use | ||
89 | * the default backend. | ||
90 | * @param handlesync If <b>true</b> the database stores the current state | ||
91 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | ||
92 | * which are used before and after synchronisation. If the application wants | ||
93 | * to react itself, it should be disabled by setting it to <b>false</b> | ||
94 | * @see OContactBackend | ||
95 | */ | ||
96 | OContactAccess (const QString appname, const QString filename = 0l, | ||
97 | OContactAccessBackend* backend = 0l, bool handlesync = true); | ||
98 | ~OContactAccess (); | ||
99 | |||
100 | /** Constants for query. | ||
101 | * Use this constants to set the query parameters. | ||
102 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | ||
103 | * @see queryByExample() | ||
104 | * - why not enum - zecke? | ||
105 | * -> Had some implementation problems .. Will use enum soon ! .. (se) | ||
106 | */ | ||
107 | static const int query_WildCards = 0x0001; | ||
108 | static const int query_IgnoreCase = 0x0002; | ||
109 | static const int query_RegExp = 0x0004; | ||
110 | static const int query_ExactMatch = 0x0008; | ||
111 | |||
112 | /** Return all possible settings. | ||
113 | * @return All settings provided by the current backend | ||
114 | * (i.e.: query_WildCards & query_IgnoreCase) | ||
115 | */ | ||
116 | const uint querySettings(); | ||
117 | |||
118 | /** Check whether settings are correct. | ||
119 | * @return <i>true</i> if the given settings are correct and possible. | ||
120 | */ | ||
121 | bool hasQuerySettings ( int querySettings ) const; | ||
122 | |||
123 | /** Add Contact to database. | ||
124 | * @param newcontact The contact to add. | ||
125 | * @return <i>true</i> if added successfully. | ||
126 | */ | ||
127 | bool add (const OContact& newcontact); | ||
128 | |||
129 | /** Replace contact. | ||
130 | * Replaces given contact with contact with the user id <i>uid</i>. | ||
131 | * @param uid The user ID | ||
132 | * @param contact The new contact | ||
133 | * @return <i>true</i> if successful. | ||
134 | */ | ||
135 | bool replace ( const OContact& contact ); | ||
136 | |||
137 | /** Remove contact. | ||
138 | * Removes contact with the user id <i>uid</i>. | ||
139 | * @param The contact to remove | ||
140 | * @return <i>true</i> if successful. | ||
141 | */ | ||
142 | bool remove ( const OContact& t ); | ||
143 | |||
144 | /** Remove contact. | ||
145 | * Removes contact with the user id <i>uid</i>. | ||
146 | * @param The user id of the contact to remove | ||
147 | * @return <i>true</i> if successful. | ||
148 | */ | ||
149 | bool remove ( int uid ); | ||
150 | |||
151 | /** Load Database * | ||
152 | */ | ||
153 | bool load(); | ||
154 | |||
155 | /** | ||
156 | * if the resource was changed externally. | ||
157 | * You should use the signal instead of polling possible changes ! | ||
158 | */ | ||
159 | bool wasChangedExternally()const; | ||
160 | |||
161 | /** Reload database. | ||
162 | * You should execute this function if the external database | ||
163 | * was changed. | ||
164 | * This function will load the external database and afterwards | ||
165 | * rejoin the local changes. Therefore the local database will be set consistent. | ||
166 | */ | ||
167 | bool reload(); | ||
168 | |||
169 | /** Save contacts database. | ||
170 | * Save is more a "commit". After calling this function, all changes are public available. | ||
171 | * @return true if successful | ||
172 | */ | ||
173 | bool save(); | ||
174 | |||
175 | signals: | ||
176 | /* Signal is emitted if the database was changed. Therefore | ||
177 | * we may need to reload to stay consistent. | ||
178 | * @param which Pointer to the database who created this event. This pointer | ||
179 | * is useful if an application has to handle multiple databases at the same time. | ||
180 | * @see reload() | ||
181 | */ | ||
182 | void signalChanged ( const OContactAccess *which ); | ||
183 | |||
184 | |||
185 | private: | ||
186 | // class OContactAccessPrivate; | ||
187 | // OContactAccessPrivate* d; | ||
188 | OContactAccessBackend *m_backEnd; | ||
189 | bool m_loading:1; | ||
190 | bool m_changed; | ||
191 | |||
192 | private slots: | ||
193 | void copMessage( const QCString &msg, const QByteArray &data ); | ||
194 | |||
195 | |||
196 | }; | ||
197 | #endif | ||