summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxportobject.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
index 4351753..67e8406 100644
--- a/kaddressbook/xxportobject.cpp
+++ b/kaddressbook/xxportobject.cpp
@@ -1,273 +1,273 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
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 <qsignalmapper.h> 32#include <qsignalmapper.h>
33 33
34#include <kaction.h> 34#include <kaction.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36#include <factory.h> 36#include <factory.h>
37 37
38#include "kabcore.h" 38#include "kabcore.h"
39#include "addressee.h" 39#include "addressee.h"
40#include "tmpaddressbook.h" 40#include "tmpaddressbook.h"
41#include "xxportobject.h" 41#include "xxportobject.h"
42 42
43 43
44class XXPortObject::XXPortObjectPrivate 44class XXPortObject::XXPortObjectPrivate
45{ 45{
46 public: 46 public:
47 QSignalMapper *mExportMapper; 47 QSignalMapper *mExportMapper;
48 QSignalMapper *mImportMapper; 48 QSignalMapper *mImportMapper;
49}; 49};
50 50
51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent, 51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
52 const char *name ) 52 const char *name )
53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ), 53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
54 d( new XXPortObjectPrivate ) 54 d( new XXPortObjectPrivate )
55{ 55{
56 d->mExportMapper = new QSignalMapper( this ); 56 d->mExportMapper = new QSignalMapper( this );
57 d->mImportMapper = new QSignalMapper( this ); 57 d->mImportMapper = new QSignalMapper( this );
58 58
59 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ), 59 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ),
60 SLOT( slotExportActivated( const QString& ) ) ); 60 SLOT( slotExportActivated( const QString& ) ) );
61 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ), 61 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ),
62 SLOT( slotImportActivated( const QString& ) ) ); 62 SLOT( slotImportActivated( const QString& ) ) );
63} 63}
64 64
65XXPortObject::~XXPortObject() 65XXPortObject::~XXPortObject()
66{ 66{
67 delete d; 67 delete d;
68 d = 0; 68 d = 0;
69} 69}
70 70
71bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& ) 71bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& )
72{ 72{
73 // do nothing 73 // do nothing
74 return false; 74 return false;
75} 75}
76 76
77KABC::AddresseeList XXPortObject::importContacts( const QString& ) const 77KABC::AddresseeList XXPortObject::importContacts( const QString& ) const
78{ 78{
79 // do nothing 79 // do nothing
80 return KABC::AddresseeList(); 80 return KABC::AddresseeList();
81} 81}
82 82
83void XXPortObject::createImportAction( const QString &label, const QString &data ) 83void XXPortObject::createImportAction( const QString &label, const QString &data )
84{ 84{
85#ifdef KAB_EMBEDDED 85#ifdef KAB_EMBEDDED
86 KABCore* kabcore = (KABCore*)mParentWidget; 86 KABCore* kabcore = (KABCore*)mParentWidget;
87#endif //KAB_EMBEDDED 87#endif //KAB_EMBEDDED
88 88
89 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 89 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
90#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
91 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 91 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() );
92#else //KAB_EMBEDDED 92#else //KAB_EMBEDDED
93 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() ); 93 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
94#endif //KAB_EMBEDDED 94#endif //KAB_EMBEDDED
95 95
96 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 96 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
97 97
98#ifndef KAB_EMBEDDED 98#ifndef KAB_EMBEDDED
99 setXMLFile( identifier() + "_xxportui.rc" ); 99 setXMLFile( identifier() + "_xxportui.rc" );
100#endif //KAB_EMBEDDED 100#endif //KAB_EMBEDDED
101 101
102#ifdef KAB_EMBEDDED 102#ifdef KAB_EMBEDDED
103 action->plug((QWidget*)kabcore->getImportMenu()); 103 action->plug((QWidget*)kabcore->getImportMenu());
104#endif //KAB_EMBEDDED 104#endif //KAB_EMBEDDED
105 105
106} 106}
107 107
108void XXPortObject::createExportAction( const QString &label, const QString &data ) 108void XXPortObject::createExportAction( const QString &label, const QString &data )
109{ 109{
110#ifdef KAB_EMBEDDED 110#ifdef KAB_EMBEDDED
111 KABCore* kabcore = (KABCore*)mParentWidget; 111 KABCore* kabcore = (KABCore*)mParentWidget;
112#endif //KAB_EMBEDDED 112#endif //KAB_EMBEDDED
113 113
114 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 114 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
115#ifndef KAB_EMBEDDED 115#ifndef KAB_EMBEDDED
116 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 116 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() );
117#else //KAB_EMBEDDED 117#else //KAB_EMBEDDED
118 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() ); 118 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
119#endif //KAB_EMBEDDED 119#endif //KAB_EMBEDDED
120 120
121 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 121 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
122 122
123#ifndef KAB_EMBEDDED 123#ifndef KAB_EMBEDDED
124 setXMLFile( identifier() + "_xxportui.rc" ); 124 setXMLFile( identifier() + "_xxportui.rc" );
125#endif //KAB_EMBEDDED 125#endif //KAB_EMBEDDED
126 126
127#ifdef KAB_EMBEDDED 127#ifdef KAB_EMBEDDED
128 action->plug((QWidget*)kabcore->getExportMenu()); 128 action->plug((QWidget*)kabcore->getExportMenu());
129#endif //KAB_EMBEDDED 129#endif //KAB_EMBEDDED
130 130
131} 131}
132 132
133KABC::AddressBook *XXPortObject::addressBook() const 133KABC::AddressBook *XXPortObject::addressBook() const
134{ 134{
135 return mAddressBook; 135 return mAddressBook;
136} 136}
137 137
138QWidget *XXPortObject::parentWidget() const 138QWidget *XXPortObject::parentWidget() const
139{ 139{
140 return mParentWidget; 140 return mParentWidget;
141} 141}
142 142
143void XXPortObject::slotExportActivated( const QString &data ) 143void XXPortObject::slotExportActivated( const QString &data )
144{ 144{
145 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 145 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
146} 146}
147 147
148void XXPortObject::slotImportActivated( const QString &data ) 148void XXPortObject::slotImportActivated( const QString &data )
149{ 149{
150 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 150 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
151} 151}
152 152
153/******************************************************************** 153/********************************************************************
154 * 154 *
155 *******************************************************************/ 155 *******************************************************************/
156 156
157 157
158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, 158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent,
159 const char *name ) 159 const char *name )
160 : XXPortObject( ab, parent, name ), mFactory(0) 160 : XXPortObject( ab, parent, name ), mFactory(0)
161{ 161{
162 mFactory = KRES::Factory::self( "tmpcontact" ); 162 mFactory = KRES::Factory::self( "tmpcontact" );
163} 163}
164 164
165XXPortResourceObject::~XXPortResourceObject() 165XXPortResourceObject::~XXPortResourceObject()
166{ 166{
167 //do not delete the factory. It is a singleton, and selfcontained 167 //do not delete the factory. It is a singleton, and selfcontained
168} 168}
169 169
170bool XXPortResourceObject::isAvailable() 170bool XXPortResourceObject::isAvailable()
171{ 171{
172 return (mFactory != 0); 172 return (mFactory != 0);
173} 173}
174 174
175 175
176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName ) 176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName )
177{ 177{
178 //create new resource 178 //create new resource
179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false )); 179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
180 180
181 if (mResource == 0) 181 if (mResource == 0)
182 return false; 182 return false;
183 183
184 if (fileName != QString::null) 184 if (fileName != QString::null)
185 mResource->setFileName( fileName ); 185 mResource->setFileName( fileName );
186 186
187 187
188 KABC::TmpAddressBook tmpAB; 188 KABC::TmpAddressBook tmpAB;
189 189
190 bool res = tmpAB.addResource( mResource ); 190 bool res = tmpAB.addResource( mResource );
191 if (res == false) 191 if (res == false)
192 { 192 {
193 delete mResource; 193 delete mResource;
194 return false; 194 return false;
195 } 195 }
196 196
197 res = tmpAB.load(); 197 res = tmpAB.load();
198 if (res == false) 198 if (res == false)
199 { 199 {
200 //removeResource deletes also the resource object, if the linkcount is 0 200 //removeResource deletes also the resource object, if the linkcount is 0
201 tmpAB.removeResource( mResource ); 201 tmpAB.removeResource( mResource );
202 return false; 202 return false;
203 } 203 }
204 204
205 205
206 //Now check if the file has already entries, and ask the user if he wants to delete them first. 206 //Now check if the file has already entries, and ask the user if he wants to delete them first.
207 if (tmpAB.begin() != tmpAB.end()) 207 if (tmpAB.begin() != tmpAB.end())
208 { 208 {
209 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 209 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
210 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 210 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
211 // Clean the database.. 211 // Clean the database..
212 tmpAB.clear(); 212 tmpAB.clear();
213 } 213 }
214 } 214 }
215 215
216 216
217 KABC::Addressee::List::ConstIterator it; 217 KABC::Addressee::List::ConstIterator it;
218 for ( it = list.begin(); it != list.end(); ++it ) { 218 for ( it = list.begin(); it != list.end(); ++it ) {
219 tmpAB.insertAddressee(*it); 219 tmpAB.insertAddressee(*it);
220 } 220 }
221 221
222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource); 222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
223 223
224 res = false; 224 res = false;
225 if (ticket != 0) 225 if (ticket != 0)
226 res = tmpAB.save( ticket ); 226 res = tmpAB.save( ticket );
227 227
228 //removeResource deletes also the resource object, if the linkcount is 0 228 //removeResource deletes also the resource object, if the linkcount is 0
229 tmpAB.removeResource( mResource ); 229 tmpAB.removeResource( mResource );
230 230
231 return res; 231 return res;
232} 232}
233 233
234 234
235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const 235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const
236{ 236{
237 237
238 238
239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false )); 239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
240 240
241 if (mResource == 0) 241 if (mResource == 0)
242 return KABC::AddresseeList(); 242 return KABC::AddresseeList();
243 243
244 KABC::AddresseeList adrlst; 244 KABC::AddresseeList adrlst;
245 245
246 if (fileName != QString::null) 246 if (fileName != QString::null)
247 mResource->setFileName( fileName ); 247 mResource->setFileName( fileName );
248 248
249 249
250 KABC::TmpAddressBook tmpAB; 250 KABC::TmpAddressBook tmpAB;
251 251
252 bool res = tmpAB.addResource( mResource ); 252 bool res = tmpAB.addResource( mResource );
253 if (res == false) 253 if (res == false)
254 { 254 {
255 delete mResource; 255 delete mResource;
256 return KABC::AddresseeList(); 256 return KABC::AddresseeList();
257 } 257 }
258 258
259 res = tmpAB.load(); 259 res = tmpAB.load();
260 260
261 adrlst = tmpAB.allAddressees(); 261 adrlst = tmpAB.allAddressees();
262 262
263 //remove resource deletes also the Resourceobject, if the linkcount is 0 263 //remove resource deletes also the Resourceobject, if the linkcount is 0
264 tmpAB.removeResource( mResource ); 264 tmpAB.removeResource( mResource );
265 265
266 return adrlst; 266 return adrlst;
267} 267}
268 268
269 269
270 270
271#ifndef KAB_EMBEDDED 271#ifndef KAB_EMBEDDED
272#include "xxportobject.moc" 272#include "xxportobject.moc"
273#endif //KAB_EMBEDDED 273#endif //KAB_EMBEDDED