summaryrefslogtreecommitdiffabout
path: root/kaddressbook/xxportobject.cpp
Unidiff
Diffstat (limited to 'kaddressbook/xxportobject.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxportobject.cpp85
1 files changed, 44 insertions, 41 deletions
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
index 67e8406..bd9d986 100644
--- a/kaddressbook/xxportobject.cpp
+++ b/kaddressbook/xxportobject.cpp
@@ -8,48 +8,49 @@
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qmap.h> 31#include <qmap.h>
32#include <qfile.h>
32#include <qsignalmapper.h> 33#include <qsignalmapper.h>
33 34
34#include <kaction.h> 35#include <kaction.h>
35#include <kmessagebox.h> 36#include <kmessagebox.h>
36#include <factory.h> 37#include <factory.h>
37 38
38#include "kabcore.h" 39#include "kabcore.h"
39#include "addressee.h" 40#include "addressee.h"
40#include "tmpaddressbook.h" 41#include "tmpaddressbook.h"
41#include "xxportobject.h" 42#include "xxportobject.h"
42 43
43 44
44class XXPortObject::XXPortObjectPrivate 45class XXPortObject::XXPortObjectPrivate
45{ 46{
46 public: 47 public:
47 QSignalMapper *mExportMapper; 48 QSignalMapper *mExportMapper;
48 QSignalMapper *mImportMapper; 49 QSignalMapper *mImportMapper;
49}; 50};
50 51
51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent, 52XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
52 const char *name ) 53 const char *name )
53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ), 54 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
54 d( new XXPortObjectPrivate ) 55 d( new XXPortObjectPrivate )
55{ 56{
@@ -155,92 +156,94 @@ void XXPortObject::slotImportActivated( const QString &data )
155 *******************************************************************/ 156 *******************************************************************/
156 157
157 158
158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, 159XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent,
159 const char *name ) 160 const char *name )
160 : XXPortObject( ab, parent, name ), mFactory(0) 161 : XXPortObject( ab, parent, name ), mFactory(0)
161{ 162{
162 mFactory = KRES::Factory::self( "tmpcontact" ); 163 mFactory = KRES::Factory::self( "tmpcontact" );
163} 164}
164 165
165XXPortResourceObject::~XXPortResourceObject() 166XXPortResourceObject::~XXPortResourceObject()
166{ 167{
167 //do not delete the factory. It is a singleton, and selfcontained 168 //do not delete the factory. It is a singleton, and selfcontained
168} 169}
169 170
170bool XXPortResourceObject::isAvailable() 171bool XXPortResourceObject::isAvailable()
171{ 172{
172 return (mFactory != 0); 173 return (mFactory != 0);
173} 174}
174 175
175 176
176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName ) 177bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName )
177{ 178{
178 //create new resource 179 //create new resource
179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 )); 180 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
180 181
181 if (mResource == 0) 182 if (mResource == 0)
182 return false; 183 return false;
183 184
184 if (fileName != QString::null) 185 if (fileName != QString::null) {
185 mResource->setFileName( fileName ); 186 mResource->setFileName( fileName );
186 187 } else
187 188 return false;
188 KABC::TmpAddressBook tmpAB; 189
189 190
190 bool res = tmpAB.addResource( mResource ); 191 KABC::TmpAddressBook tmpAB;
191 if (res == false) 192
192 { 193 bool res = tmpAB.addResource( mResource );
193 delete mResource; 194 if (res == false)
194 return false; 195 {
195 } 196 delete mResource;
196 197 return false;
197 res = tmpAB.load(); 198 }
198 if (res == false) 199 if ( QFile::exists ( fileName ) ) {
199 { 200 res = tmpAB.load();
200 //removeResource deletes also the resource object, if the linkcount is 0 201 if (res == false)
201 tmpAB.removeResource( mResource ); 202 {
202 return false; 203 //removeResource deletes also the resource object, if the linkcount is 0
203 } 204 tmpAB.removeResource( mResource );
204 205 return false;
205 206 }
206 //Now check if the file has already entries, and ask the user if he wants to delete them first. 207
207 if (tmpAB.begin() != tmpAB.end()) 208
208 { 209 //Now check if the file has already entries, and ask the user if he wants to delete them first.
209 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 210 if (tmpAB.begin() != tmpAB.end())
210 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 211 {
211 // Clean the database.. 212 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
212 tmpAB.clear(); 213 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
214 // Clean the database..
215 tmpAB.clear();
216 }
217 }
213 } 218 }
214 }
215 219
220 KABC::Addressee::List::ConstIterator it;
221 for ( it = list.begin(); it != list.end(); ++it ) {
222 tmpAB.insertAddressee(*it);
223 }
216 224
217 KABC::Addressee::List::ConstIterator it; 225 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
218 for ( it = list.begin(); it != list.end(); ++it ) {
219 tmpAB.insertAddressee(*it);
220 }
221
222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
223 226
224 res = false; 227 res = false;
225 if (ticket != 0) 228 if (ticket != 0)
226 res = tmpAB.save( ticket ); 229 res = tmpAB.save( ticket );
227 230
228 //removeResource deletes also the resource object, if the linkcount is 0 231 //removeResource deletes also the resource object, if the linkcount is 0
229 tmpAB.removeResource( mResource ); 232 tmpAB.removeResource( mResource );
230 233
231 return res; 234 return res;
232} 235}
233 236
234 237
235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const 238KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const
236{ 239{
237 240
238 241
239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 )); 242 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
240 243
241 if (mResource == 0) 244 if (mResource == 0)
242 return KABC::AddresseeList(); 245 return KABC::AddresseeList();
243 246
244 KABC::AddresseeList adrlst; 247 KABC::AddresseeList adrlst;
245 248
246 if (fileName != QString::null) 249 if (fileName != QString::null)