Diffstat (limited to 'noncore/unsupported/libopie/pim/ocontactaccess.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/libopie/pim/ocontactaccess.cpp | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/ocontactaccess.cpp b/noncore/unsupported/libopie/pim/ocontactaccess.cpp new file mode 100644 index 0000000..63b93ee --- a/dev/null +++ b/noncore/unsupported/libopie/pim/ocontactaccess.cpp | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Class to manage the Contacts. | ||
3 | * | ||
4 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | ||
5 | * | ||
6 | * ===================================================================== | ||
7 | *This program is free software; you can redistribute it and/or | ||
8 | *modify it under the terms of the GNU Library General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2 of the License, or (at your option) any later version. | ||
11 | * ===================================================================== | ||
12 | * Info: This class could just work with a change in the header-file | ||
13 | * of the Contact class ! Therefore our libopie only compiles | ||
14 | * with our version of libqpe | ||
15 | * ===================================================================== | ||
16 | * ToDo: XML-Backend: Automatic reload if something was changed... | ||
17 | * | ||
18 | * | ||
19 | * ===================================================================== | ||
20 | * Version: $Id$ | ||
21 | * ===================================================================== | ||
22 | * History: | ||
23 | * $Log$ | ||
24 | * Revision 1.1 2004/11/16 21:46:07 mickeyl | ||
25 | * libopie1 goes into unsupported | ||
26 | * | ||
27 | * Revision 1.9 2004/03/02 12:14:22 alwin | ||
28 | * run the optimize_connect script | ||
29 | * the whole cvs is tagged with "before_optimize_connect" if there are problems you | ||
30 | * can check the diff (but it had compiled and run here) | ||
31 | * | ||
32 | * Revision 1.8 2003/05/08 13:55:09 tille | ||
33 | * search stuff | ||
34 | * and match, toRichText & toShortText in oevent | ||
35 | * | ||
36 | * Revision 1.7 2002/11/13 14:14:51 eilers | ||
37 | * Added sorted for Contacts.. | ||
38 | * | ||
39 | * Revision 1.6 2002/11/01 15:10:42 eilers | ||
40 | * Added regExp-search in database for all fields in a contact. | ||
41 | * | ||
42 | * Revision 1.5 2002/10/16 10:52:40 eilers | ||
43 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
44 | * | ||
45 | * Revision 1.4 2002/10/14 16:21:54 eilers | ||
46 | * Some minor interface updates | ||
47 | * | ||
48 | * Revision 1.3 2002/10/07 17:34:24 eilers | ||
49 | * added OBackendFactory for advanced backend access | ||
50 | * | ||
51 | * Revision 1.2 2002/10/02 16:18:11 eilers | ||
52 | * debugged and seems to work almost perfectly .. | ||
53 | * | ||
54 | * Revision 1.1 2002/09/27 17:11:44 eilers | ||
55 | * Added API for accessing the Contact-Database ! It is compiling, but | ||
56 | * please do not expect that anything is working ! | ||
57 | * I will debug that stuff in the next time .. | ||
58 | * Please read README_COMPILE for compiling ! | ||
59 | * | ||
60 | * | ||
61 | */ | ||
62 | |||
63 | #include "ocontactaccess.h" | ||
64 | #include "obackendfactory.h" | ||
65 | |||
66 | #include <qasciidict.h> | ||
67 | #include <qdatetime.h> | ||
68 | #include <qfile.h> | ||
69 | #include <qregexp.h> | ||
70 | #include <qlist.h> | ||
71 | #include <qcopchannel_qws.h> | ||
72 | |||
73 | //#include <qpe/qcopenvelope_qws.h> | ||
74 | #include <qpe/global.h> | ||
75 | |||
76 | #include <errno.h> | ||
77 | #include <fcntl.h> | ||
78 | #include <unistd.h> | ||
79 | #include <stdlib.h> | ||
80 | |||
81 | #include "ocontactaccessbackend_xml.h" | ||
82 | |||
83 | |||
84 | OContactAccess::OContactAccess ( const QString appname, const QString , | ||
85 | OContactAccessBackend* end, bool autosync ): | ||
86 | OPimAccessTemplate<OContact>( end ) | ||
87 | { | ||
88 | /* take care of the backend. If there is no one defined, we | ||
89 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | ||
90 | */ | ||
91 | if( end == 0 ) { | ||
92 | qWarning ("Using BackendFactory !"); | ||
93 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); | ||
94 | } | ||
95 | // Set backend locally and in template | ||
96 | m_backEnd = end; | ||
97 | OPimAccessTemplate<OContact>::setBackEnd (end); | ||
98 | |||
99 | |||
100 | /* Connect signal of external db change to function */ | ||
101 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); | ||
102 | connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), | ||
103 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); | ||
104 | if ( autosync ){ | ||
105 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); | ||
106 | connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), | ||
107 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); | ||
108 | } | ||
109 | |||
110 | |||
111 | } | ||
112 | OContactAccess::~OContactAccess () | ||
113 | { | ||
114 | /* The user may forget to save the changed database, therefore try to | ||
115 | * do it for him.. | ||
116 | */ | ||
117 | save(); | ||
118 | // delete m_backEnd; is done by template.. | ||
119 | } | ||
120 | |||
121 | |||
122 | bool OContactAccess::save () | ||
123 | { | ||
124 | /* If the database was changed externally, we could not save the | ||
125 | * Data. This will remove added items which is unacceptable ! | ||
126 | * Therefore: Reload database and merge the data... | ||
127 | */ | ||
128 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) | ||
129 | reload(); | ||
130 | |||
131 | bool status = OPimAccessTemplate<OContact>::save(); | ||
132 | if ( !status ) return false; | ||
133 | |||
134 | /* Now tell everyone that new data is available. | ||
135 | */ | ||
136 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | ||
137 | |||
138 | return true; | ||
139 | } | ||
140 | |||
141 | const uint OContactAccess::querySettings() | ||
142 | { | ||
143 | return ( m_backEnd->querySettings() ); | ||
144 | } | ||
145 | |||
146 | bool OContactAccess::hasQuerySettings ( int querySettings ) const | ||
147 | { | ||
148 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | ||
149 | } | ||
150 | ORecordList<OContact> OContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const | ||
151 | { | ||
152 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); | ||
153 | return ( ORecordList<OContact>(matchingContacts, this) ); | ||
154 | } | ||
155 | |||
156 | |||
157 | bool OContactAccess::wasChangedExternally()const | ||
158 | { | ||
159 | return ( m_backEnd->wasChangedExternally() ); | ||
160 | } | ||
161 | |||
162 | |||
163 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) | ||
164 | { | ||
165 | if ( msg == "addressbookUpdated()" ){ | ||
166 | qWarning ("OContactAccess: Received addressbokUpdated()"); | ||
167 | emit signalChanged ( this ); | ||
168 | } else if ( msg == "flush()" ) { | ||
169 | qWarning ("OContactAccess: Received flush()"); | ||
170 | save (); | ||
171 | } else if ( msg == "reload()" ) { | ||
172 | qWarning ("OContactAccess: Received reload()"); | ||
173 | reload (); | ||
174 | emit signalChanged ( this ); | ||
175 | } | ||
176 | } | ||