summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccess.cpp8
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp8
2 files changed, 14 insertions, 2 deletions
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp
index 2d808f7..8a8ff08 100644
--- a/libopie/pim/ocontactaccess.cpp
+++ b/libopie/pim/ocontactaccess.cpp
@@ -1,174 +1,180 @@
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.2 2002/10/02 16:18:11 eilers
25 * debugged and seems to work almost perfectly ..
26 *
24 * Revision 1.1 2002/09/27 17:11:44 eilers 27 * Revision 1.1 2002/09/27 17:11:44 eilers
25 * Added API for accessing the Contact-Database ! It is compiling, but 28 * Added API for accessing the Contact-Database ! It is compiling, but
26 * please do not expect that anything is working ! 29 * please do not expect that anything is working !
27 * I will debug that stuff in the next time .. 30 * I will debug that stuff in the next time ..
28 * Please read README_COMPILE for compiling ! 31 * Please read README_COMPILE for compiling !
29 * 32 *
30 * 33 *
31 */ 34 */
32 35
33#include "ocontactaccess.h" 36#include "ocontactaccess.h"
34 37
35#include <qasciidict.h> 38#include <qasciidict.h>
36#include <qdatetime.h> 39#include <qdatetime.h>
37#include <qfile.h> 40#include <qfile.h>
38#include <qregexp.h> 41#include <qregexp.h>
39#include <qlist.h> 42#include <qlist.h>
40#include <qcopchannel_qws.h> 43#include <qcopchannel_qws.h>
41 44
42//#include <qpe/qcopenvelope_qws.h> 45//#include <qpe/qcopenvelope_qws.h>
43#include <qpe/global.h> 46#include <qpe/global.h>
44 47
45#include <errno.h> 48#include <errno.h>
46#include <fcntl.h> 49#include <fcntl.h>
47#include <unistd.h> 50#include <unistd.h>
48#include <stdlib.h> 51#include <stdlib.h>
49 52
50#include "ocontactaccessbackend_xml.h" 53#include "ocontactaccessbackend_xml.h"
51 54
52 55
53OContactAccess::OContactAccess ( const QString appname, const QString filename, 56OContactAccess::OContactAccess ( const QString appname, const QString filename,
54 OContactAccessBackend* end, bool autosync ): 57 OContactAccessBackend* end, bool autosync ):
55 OPimAccessTemplate<OContact>( end ), 58 OPimAccessTemplate<OContact>( end ),
56 m_changed ( false ) 59 m_changed ( false )
57{ 60{
58 /* take care of the backend. If there is no one defined, we 61 /* take care of the backend. If there is no one defined, we
59 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 62 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
60 */ 63 */
61 if( end == 0 ) { 64 if( end == 0 ) {
62 end = new OContactAccessBackend_XML( appname, filename ); 65 end = new OContactAccessBackend_XML( appname, filename );
63 } 66 }
67 // Set backend locally and in template
64 m_backEnd = end; 68 m_backEnd = end;
69 OPimAccessTemplate<OContact>::setBackEnd (end);
70
65 71
66 /* Connect signal of external db change to function */ 72 /* Connect signal of external db change to function */
67 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 73 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
68 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), 74 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)),
69 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 75 this, SLOT(copMessage( const QCString &, const QByteArray &)) );
70 if ( autosync ){ 76 if ( autosync ){
71 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 77 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
72 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), 78 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)),
73 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 79 this, SLOT(copMessage( const QCString &, const QByteArray &)) );
74 } 80 }
75 81
76 82
77} 83}
78OContactAccess::~OContactAccess () 84OContactAccess::~OContactAccess ()
79{ 85{
80 /* The user may forget to save the changed database, therefore try to 86 /* The user may forget to save the changed database, therefore try to
81 * do it for him.. 87 * do it for him..
82 */ 88 */
83 if ( m_changed ) 89 if ( m_changed )
84 save(); 90 save();
85 delete m_backEnd; 91 // delete m_backEnd; is done by template..
86} 92}
87 93
88bool OContactAccess::load() 94bool OContactAccess::load()
89{ 95{
90 return ( m_backEnd->load() ); 96 return ( m_backEnd->load() );
91} 97}
92 98
93bool OContactAccess::save () 99bool OContactAccess::save ()
94{ 100{
95 /* If the database was changed externally, we could not save the 101 /* If the database was changed externally, we could not save the
96 * Data. This will remove added items which is unacceptable ! 102 * Data. This will remove added items which is unacceptable !
97 * Therefore: Reload database and merge the data... 103 * Therefore: Reload database and merge the data...
98 */ 104 */
99 if ( m_backEnd->wasChangedExternally() ) 105 if ( m_backEnd->wasChangedExternally() )
100 reload(); 106 reload();
101 107
102 if ( m_changed ){ 108 if ( m_changed ){
103 bool status = m_backEnd->save(); 109 bool status = m_backEnd->save();
104 if ( !status ) return false; 110 if ( !status ) return false;
105 111
106 m_changed = false; 112 m_changed = false;
107 /* Now tell everyone that new data is available. 113 /* Now tell everyone that new data is available.
108 */ 114 */
109 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); 115 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
110 116
111 } 117 }
112 118
113 return true; 119 return true;
114} 120}
115 121
116const uint OContactAccess::querySettings() 122const uint OContactAccess::querySettings()
117{ 123{
118 return ( m_backEnd->querySettings() ); 124 return ( m_backEnd->querySettings() );
119} 125}
120 126
121bool OContactAccess::hasQuerySettings ( int querySettings ) const 127bool OContactAccess::hasQuerySettings ( int querySettings ) const
122{ 128{
123 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 129 return ( m_backEnd->hasQuerySettings ( querySettings ) );
124} 130}
125 131
126bool OContactAccess::add ( const OContact& newcontact ) 132bool OContactAccess::add ( const OContact& newcontact )
127{ 133{
128 m_changed = true; 134 m_changed = true;
129 return ( m_backEnd->add ( newcontact ) ); 135 return ( m_backEnd->add ( newcontact ) );
130} 136}
131 137
132bool OContactAccess::replace ( const OContact& contact ) 138bool OContactAccess::replace ( const OContact& contact )
133{ 139{
134 m_changed = true; 140 m_changed = true;
135 return ( m_backEnd->replace ( contact ) ); 141 return ( m_backEnd->replace ( contact ) );
136} 142}
137 143
138bool OContactAccess::remove ( const OContact& t ) 144bool OContactAccess::remove ( const OContact& t )
139{ 145{
140 m_changed = true; 146 m_changed = true;
141 return ( m_backEnd->remove ( t.uid() ) ); 147 return ( m_backEnd->remove ( t.uid() ) );
142} 148}
143 149
144bool OContactAccess::remove ( int uid ) 150bool OContactAccess::remove ( int uid )
145{ 151{
146 m_changed = true; 152 m_changed = true;
147 return ( m_backEnd->remove ( uid ) ); 153 return ( m_backEnd->remove ( uid ) );
148} 154}
149 155
150bool OContactAccess::wasChangedExternally()const 156bool OContactAccess::wasChangedExternally()const
151{ 157{
152 return ( m_backEnd->wasChangedExternally() ); 158 return ( m_backEnd->wasChangedExternally() );
153} 159}
154 160
155 161
156bool OContactAccess::reload() 162bool OContactAccess::reload()
157{ 163{
158 return ( m_backEnd->reload() ); 164 return ( m_backEnd->reload() );
159} 165}
160 166
161void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) 167void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
162{ 168{
163 if ( msg == "addressbookUpdated()" ){ 169 if ( msg == "addressbookUpdated()" ){
164 qWarning ("OContactAccess: Received addressbokUpdated()"); 170 qWarning ("OContactAccess: Received addressbokUpdated()");
165 emit signalChanged ( this ); 171 emit signalChanged ( this );
166 } else if ( msg == "flush()" ) { 172 } else if ( msg == "flush()" ) {
167 qWarning ("OContactAccess: Received flush()"); 173 qWarning ("OContactAccess: Received flush()");
168 save (); 174 save ();
169 } else if ( msg == "reload()" ) { 175 } else if ( msg == "reload()" ) {
170 qWarning ("OContactAccess: Received reload()"); 176 qWarning ("OContactAccess: Received reload()");
171 reload (); 177 reload ();
172 emit signalChanged ( this ); 178 emit signalChanged ( this );
173 } 179 }
174} 180}
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 2d808f7..8a8ff08 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,174 +1,180 @@
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.2 2002/10/02 16:18:11 eilers
25 * debugged and seems to work almost perfectly ..
26 *
24 * Revision 1.1 2002/09/27 17:11:44 eilers 27 * Revision 1.1 2002/09/27 17:11:44 eilers
25 * Added API for accessing the Contact-Database ! It is compiling, but 28 * Added API for accessing the Contact-Database ! It is compiling, but
26 * please do not expect that anything is working ! 29 * please do not expect that anything is working !
27 * I will debug that stuff in the next time .. 30 * I will debug that stuff in the next time ..
28 * Please read README_COMPILE for compiling ! 31 * Please read README_COMPILE for compiling !
29 * 32 *
30 * 33 *
31 */ 34 */
32 35
33#include "ocontactaccess.h" 36#include "ocontactaccess.h"
34 37
35#include <qasciidict.h> 38#include <qasciidict.h>
36#include <qdatetime.h> 39#include <qdatetime.h>
37#include <qfile.h> 40#include <qfile.h>
38#include <qregexp.h> 41#include <qregexp.h>
39#include <qlist.h> 42#include <qlist.h>
40#include <qcopchannel_qws.h> 43#include <qcopchannel_qws.h>
41 44
42//#include <qpe/qcopenvelope_qws.h> 45//#include <qpe/qcopenvelope_qws.h>
43#include <qpe/global.h> 46#include <qpe/global.h>
44 47
45#include <errno.h> 48#include <errno.h>
46#include <fcntl.h> 49#include <fcntl.h>
47#include <unistd.h> 50#include <unistd.h>
48#include <stdlib.h> 51#include <stdlib.h>
49 52
50#include "ocontactaccessbackend_xml.h" 53#include "ocontactaccessbackend_xml.h"
51 54
52 55
53OContactAccess::OContactAccess ( const QString appname, const QString filename, 56OContactAccess::OContactAccess ( const QString appname, const QString filename,
54 OContactAccessBackend* end, bool autosync ): 57 OContactAccessBackend* end, bool autosync ):
55 OPimAccessTemplate<OContact>( end ), 58 OPimAccessTemplate<OContact>( end ),
56 m_changed ( false ) 59 m_changed ( false )
57{ 60{
58 /* take care of the backend. If there is no one defined, we 61 /* take care of the backend. If there is no one defined, we
59 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 62 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
60 */ 63 */
61 if( end == 0 ) { 64 if( end == 0 ) {
62 end = new OContactAccessBackend_XML( appname, filename ); 65 end = new OContactAccessBackend_XML( appname, filename );
63 } 66 }
67 // Set backend locally and in template
64 m_backEnd = end; 68 m_backEnd = end;
69 OPimAccessTemplate<OContact>::setBackEnd (end);
70
65 71
66 /* Connect signal of external db change to function */ 72 /* Connect signal of external db change to function */
67 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 73 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
68 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)), 74 connect( dbchannel, SIGNAL(received(const QCString &, const QByteArray &)),
69 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 75 this, SLOT(copMessage( const QCString &, const QByteArray &)) );
70 if ( autosync ){ 76 if ( autosync ){
71 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 77 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
72 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)), 78 connect( syncchannel, SIGNAL(received(const QCString &, const QByteArray &)),
73 this, SLOT(copMessage( const QCString &, const QByteArray &)) ); 79 this, SLOT(copMessage( const QCString &, const QByteArray &)) );
74 } 80 }
75 81
76 82
77} 83}
78OContactAccess::~OContactAccess () 84OContactAccess::~OContactAccess ()
79{ 85{
80 /* The user may forget to save the changed database, therefore try to 86 /* The user may forget to save the changed database, therefore try to
81 * do it for him.. 87 * do it for him..
82 */ 88 */
83 if ( m_changed ) 89 if ( m_changed )
84 save(); 90 save();
85 delete m_backEnd; 91 // delete m_backEnd; is done by template..
86} 92}
87 93
88bool OContactAccess::load() 94bool OContactAccess::load()
89{ 95{
90 return ( m_backEnd->load() ); 96 return ( m_backEnd->load() );
91} 97}
92 98
93bool OContactAccess::save () 99bool OContactAccess::save ()
94{ 100{
95 /* If the database was changed externally, we could not save the 101 /* If the database was changed externally, we could not save the
96 * Data. This will remove added items which is unacceptable ! 102 * Data. This will remove added items which is unacceptable !
97 * Therefore: Reload database and merge the data... 103 * Therefore: Reload database and merge the data...
98 */ 104 */
99 if ( m_backEnd->wasChangedExternally() ) 105 if ( m_backEnd->wasChangedExternally() )
100 reload(); 106 reload();
101 107
102 if ( m_changed ){ 108 if ( m_changed ){
103 bool status = m_backEnd->save(); 109 bool status = m_backEnd->save();
104 if ( !status ) return false; 110 if ( !status ) return false;
105 111
106 m_changed = false; 112 m_changed = false;
107 /* Now tell everyone that new data is available. 113 /* Now tell everyone that new data is available.
108 */ 114 */
109 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); 115 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
110 116
111 } 117 }
112 118
113 return true; 119 return true;
114} 120}
115 121
116const uint OContactAccess::querySettings() 122const uint OContactAccess::querySettings()
117{ 123{
118 return ( m_backEnd->querySettings() ); 124 return ( m_backEnd->querySettings() );
119} 125}
120 126
121bool OContactAccess::hasQuerySettings ( int querySettings ) const 127bool OContactAccess::hasQuerySettings ( int querySettings ) const
122{ 128{
123 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 129 return ( m_backEnd->hasQuerySettings ( querySettings ) );
124} 130}
125 131
126bool OContactAccess::add ( const OContact& newcontact ) 132bool OContactAccess::add ( const OContact& newcontact )
127{ 133{
128 m_changed = true; 134 m_changed = true;
129 return ( m_backEnd->add ( newcontact ) ); 135 return ( m_backEnd->add ( newcontact ) );
130} 136}
131 137
132bool OContactAccess::replace ( const OContact& contact ) 138bool OContactAccess::replace ( const OContact& contact )
133{ 139{
134 m_changed = true; 140 m_changed = true;
135 return ( m_backEnd->replace ( contact ) ); 141 return ( m_backEnd->replace ( contact ) );
136} 142}
137 143
138bool OContactAccess::remove ( const OContact& t ) 144bool OContactAccess::remove ( const OContact& t )
139{ 145{
140 m_changed = true; 146 m_changed = true;
141 return ( m_backEnd->remove ( t.uid() ) ); 147 return ( m_backEnd->remove ( t.uid() ) );
142} 148}
143 149
144bool OContactAccess::remove ( int uid ) 150bool OContactAccess::remove ( int uid )
145{ 151{
146 m_changed = true; 152 m_changed = true;
147 return ( m_backEnd->remove ( uid ) ); 153 return ( m_backEnd->remove ( uid ) );
148} 154}
149 155
150bool OContactAccess::wasChangedExternally()const 156bool OContactAccess::wasChangedExternally()const
151{ 157{
152 return ( m_backEnd->wasChangedExternally() ); 158 return ( m_backEnd->wasChangedExternally() );
153} 159}
154 160
155 161
156bool OContactAccess::reload() 162bool OContactAccess::reload()
157{ 163{
158 return ( m_backEnd->reload() ); 164 return ( m_backEnd->reload() );
159} 165}
160 166
161void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) 167void OContactAccess::copMessage( const QCString &msg, const QByteArray & )
162{ 168{
163 if ( msg == "addressbookUpdated()" ){ 169 if ( msg == "addressbookUpdated()" ){
164 qWarning ("OContactAccess: Received addressbokUpdated()"); 170 qWarning ("OContactAccess: Received addressbokUpdated()");
165 emit signalChanged ( this ); 171 emit signalChanged ( this );
166 } else if ( msg == "flush()" ) { 172 } else if ( msg == "flush()" ) {
167 qWarning ("OContactAccess: Received flush()"); 173 qWarning ("OContactAccess: Received flush()");
168 save (); 174 save ();
169 } else if ( msg == "reload()" ) { 175 } else if ( msg == "reload()" ) {
170 qWarning ("OContactAccess: Received reload()"); 176 qWarning ("OContactAccess: Received reload()");
171 reload (); 177 reload ();
172 emit signalChanged ( this ); 178 emit signalChanged ( this );
173 } 179 }
174} 180}