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