summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/ocontactaccess.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/ocontactaccess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 7a3d7cb..2602493 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -1,164 +1,164 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * ===================================================================== 30 * =====================================================================
31 * ToDo: XML-Backend: Automatic reload if something was changed... 31 * ToDo: XML-Backend: Automatic reload if something was changed...
32 * 32 *
33 * 33 *
34 */ 34 */
35 35
36#include "ocontactaccess.h" 36#include "ocontactaccess.h"
37#include "obackendfactory.h" 37#include "obackendfactory.h"
38 38
39/* OPIE */ 39/* OPIE */
40#include <opie2/ocontactaccessbackend_xml.h> 40#include <opie2/ocontactaccessbackend_xml.h>
41#include <opie2/opimresolver.h> 41#include <opie2/opimresolver.h>
42#include <opie2/opimglobal.h> 42#include <opie2/opimglobal.h>
43#include <opie2/odebug.h> 43#include <opie2/odebug.h>
44 44
45//#include <qpe/qcopenvelope_qws.h> 45//#include <qpe/qcopenvelope_qws.h>
46#include <qpe/global.h> 46#include <qpe/global.h>
47 47
48/* QT */ 48/* QT */
49#include <qasciidict.h> 49#include <qasciidict.h>
50#include <qdatetime.h> 50#include <qdatetime.h>
51#include <qfile.h> 51#include <qfile.h>
52#include <qregexp.h> 52#include <qregexp.h>
53#include <qlist.h> 53#include <qlist.h>
54#include <qcopchannel_qws.h> 54#include <qcopchannel_qws.h>
55 55
56/* STD */ 56/* STD */
57#include <errno.h> 57#include <errno.h>
58#include <fcntl.h> 58#include <fcntl.h>
59#include <unistd.h> 59#include <unistd.h>
60#include <stdlib.h> 60#include <stdlib.h>
61 61
62 62
63namespace Opie { 63namespace Opie {
64 64
65OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 65OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
66 OPimContactAccessBackend* end, bool autosync ): 66 OPimContactAccessBackend* end, bool autosync ):
67 OPimAccessTemplate<OPimContact>( end ) 67 OPimAccessTemplate<OPimContact>( end )
68{ 68{
69 /* take care of the backend. If there is no one defined, we 69 /* take care of the backend. If there is no one defined, we
70 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 70 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
71 */ 71 */
72 if( end == 0 ) { 72 if( end == 0 ) {
73 owarn << "Using BackendFactory !" << oendl; 73 owarn << "Using BackendFactory !" << oendl;
74 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); 74 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
75 } 75 }
76 // Set backend locally and in template 76 // Set backend locally and in template
77 m_backEnd = end; 77 m_backEnd = end;
78 OPimAccessTemplate<OPimContact>::setBackEnd (end); 78 OPimAccessTemplate<OPimContact>::setBackEnd (end);
79 79
80 80
81 /* Connect signal of external db change to function */ 81 /* Connect signal of external db change to function */
82 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); 82 QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this );
83 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), 83 connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)),
84 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 84 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
85 if ( autosync ){ 85 if ( autosync ){
86 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); 86 QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this );
87 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), 87 connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)),
88 this, SLOT(copMessage(const QCString&,const QByteArray&)) ); 88 this, SLOT(copMessage(const QCString&,const QByteArray&)) );
89 } 89 }
90 90
91 91
92} 92}
93OPimContactAccess::~OPimContactAccess () 93OPimContactAccess::~OPimContactAccess ()
94{ 94{
95 /* The user may forget to save the changed database, therefore try to 95 /* The user may forget to save the changed database, therefore try to
96 * do it for him.. 96 * do it for him..
97 */ 97 */
98 save(); 98 save();
99 // delete m_backEnd; is done by template.. 99 // delete m_backEnd; is done by template..
100} 100}
101 101
102 102
103bool OPimContactAccess::save () 103bool OPimContactAccess::save ()
104{ 104{
105 /* If the database was changed externally, we could not save the 105 /* If the database was changed externally, we could not save the
106 * Data. This will remove added items which is unacceptable ! 106 * Data. This will remove added items which is unacceptable !
107 * Therefore: Reload database and merge the data... 107 * Therefore: Reload database and merge the data...
108 */ 108 */
109 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) 109 if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() )
110 reload(); 110 reload();
111 111
112 bool status = OPimAccessTemplate<OPimContact>::save(); 112 bool status = OPimAccessTemplate<OPimContact>::save();
113 if ( !status ) return false; 113 if ( !status ) return false;
114 114
115 /* Now tell everyone that new data is available. 115 /* Now tell everyone that new data is available.
116 */ 116 */
117 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); 117 QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" );
118 118
119 return true; 119 return true;
120} 120}
121 121
122const uint OPimContactAccess::querySettings() 122const uint OPimContactAccess::querySettings()
123{ 123{
124 return ( m_backEnd->querySettings() ); 124 return ( m_backEnd->querySettings() );
125} 125}
126 126
127bool OPimContactAccess::hasQuerySettings ( int querySettings ) const 127bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
128{ 128{
129 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 129 return ( m_backEnd->hasQuerySettings ( querySettings ) );
130} 130}
131OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 131OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
132{ 132{
133 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); 133 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
134 return ( OPimRecordList<OPimContact>(matchingContacts, this) ); 134 return ( OPimRecordList<OPimContact>(matchingContacts, this) );
135} 135}
136 136
137 137
138bool OPimContactAccess::wasChangedExternally()const 138bool OPimContactAccess::wasChangedExternally()const
139{ 139{
140 return ( m_backEnd->wasChangedExternally() ); 140 return ( m_backEnd->wasChangedExternally() );
141} 141}
142 142
143 143
144void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) 144void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
145{ 145{
146 if ( msg == "addressbookUpdated()" ){ 146 if ( msg == "addressbookUpdated()" ){
147 owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl; 147 owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl;
148 emit signalChanged ( this ); 148 emit signalChanged ( this );
149 } else if ( msg == "flush()" ) { 149 } else if ( msg == "flush()" ) {
150 owarn << "OPimContactAccess: Received flush()" << oendl; 150 owarn << "OPimContactAccess: Received flush()" << oendl;
151 save (); 151 save ();
152 } else if ( msg == "reload()" ) { 152 } else if ( msg == "reload()" ) {
153 owarn << "OPimContactAccess: Received reload()" << oendl; 153 owarn << "OPimContactAccess: Received reload()" << oendl;
154 reload (); 154 reload ();
155 emit signalChanged ( this ); 155 emit signalChanged ( this );
156 } 156 }
157} 157}
158 158
159int OPimContactAccess::rtti() const 159int OPimContactAccess::rtti() const
160{ 160{
161 return OPimResolver::AddressBook; 161 return OPimResolver::AddressBook;
162} 162}
163 163
164} 164}