summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxportmanager.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp
index 7cb67ed..405f7ec 100644
--- a/kaddressbook/xxportmanager.cpp
+++ b/kaddressbook/xxportmanager.cpp
@@ -1,256 +1,263 @@
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 <qlayout.h> 31#include <qlayout.h>
32#include <qlist.h> 32#include <qlist.h>
33 33
34#include <kabc/addressbook.h> 34#include <kabc/addressbook.h>
35#include <kabc/resource.h> 35#include <kabc/resource.h>
36#include <kdebug.h> 36#include <kdebug.h>
37#include <kdialogbase.h> 37#include <kdialogbase.h>
38#include <klocale.h> 38#include <klocale.h>
39#include <kmessagebox.h> 39#include <kmessagebox.h>
40 40
41#ifndef KAB_EMBEDDED 41#ifndef KAB_EMBEDDED
42#include <ktrader.h> 42#include <ktrader.h>
43#else //KAB_EMBEDDED 43#else //KAB_EMBEDDED
44extern "C" 44extern "C"
45{ 45{
46 void* init_microkaddrbk_csv_xxport(); 46 void* init_microkaddrbk_csv_xxport();
47 void* init_microkaddrbk_kde2_xxport(); 47 void* init_microkaddrbk_kde2_xxport();
48 void* init_microkaddrbk_vcard_xxport(); 48 void* init_microkaddrbk_vcard_xxport();
49 // void* init_microkaddrbk_opie_xxport(); 49 // void* init_microkaddrbk_opie_xxport();
50 void* init_microkaddrbk_qtopia_xxport(); 50 void* init_microkaddrbk_qtopia_xxport();
51 void* init_microkaddrbk_sharpdtm_xxport(); 51 void* init_microkaddrbk_sharpdtm_xxport();
52} 52}
53#endif //KAB_EMBEDDED 53#endif //KAB_EMBEDDED
54 54
55#include <addresseeview.h> 55#include <addresseeview.h>
56 56
57#include "kabcore.h" 57#include "kabcore.h"
58#include "undocmds.h" 58#include "undocmds.h"
59#include "xxportselectdialog.h" 59#include "xxportselectdialog.h"
60 60
61#include "xxportmanager.h" 61#include "xxportmanager.h"
62#include "nameeditdialog.h"
62 63
63KURL XXPortManager::importURL = KURL(); 64KURL XXPortManager::importURL = KURL();
64QString XXPortManager::importData = QString::null; 65QString XXPortManager::importData = QString::null;
65 66
66class PreviewDialog : public KDialogBase 67class PreviewDialog : public KDialogBase
67{ 68{
68 public: 69 public:
69 PreviewDialog( const KABC::Addressee &addr, 70 PreviewDialog( const KABC::Addressee &addr,
70 QWidget *parent, const char *name = 0 ); 71 QWidget *parent, const char *name = 0 );
71}; 72};
72 73
73XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name ) 74XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name )
74 : QObject( parent, name ), mCore( core ), mShowPreview( false ) 75 : QObject( parent, name ), mCore( core ), mShowPreview( false )
75{ 76{
76 loadPlugins(); 77 loadPlugins();
77} 78}
78 79
79XXPortManager::~XXPortManager() 80XXPortManager::~XXPortManager()
80{ 81{
81} 82}
82 83
83void XXPortManager::restoreSettings() 84void XXPortManager::restoreSettings()
84{ 85{
85} 86}
86 87
87void XXPortManager::saveSettings() 88void XXPortManager::saveSettings()
88{ 89{
89} 90}
90 91
91void XXPortManager::importVCard( const KURL &url ) 92void XXPortManager::importVCard( const KURL &url )
92{ 93{
93 importVCard( url, false ); 94 importVCard( url, false );
94} 95}
95 96
96void XXPortManager::importVCard( const KURL &url, bool showPreview ) 97void XXPortManager::importVCard( const KURL &url, bool showPreview )
97{ 98{
98 importURL = url; 99 importURL = url;
99 mShowPreview = showPreview; 100 mShowPreview = showPreview;
100 slotImport( "vcard", "<empty>" ); 101 slotImport( "vcard", "<empty>" );
101 mShowPreview = false; 102 mShowPreview = false;
102 importURL = KURL(); 103 importURL = KURL();
103} 104}
104 105
105void XXPortManager::importVCard( const QString &vCard, bool showPreview ) 106void XXPortManager::importVCard( const QString &vCard, bool showPreview )
106{ 107{
107 importData = vCard; 108 importData = vCard;
108 mShowPreview = showPreview; 109 mShowPreview = showPreview;
109 slotImport( "vcard", "<empty>" ); 110 slotImport( "vcard", "<empty>" );
110 mShowPreview = false; 111 mShowPreview = false;
111 importData = ""; 112 importData = "";
112} 113}
113 114
114void XXPortManager::slotImport( const QString &identifier, const QString &data ) 115void XXPortManager::slotImport( const QString &identifier, const QString &data )
115{ 116{
116 XXPortObject *obj = mXXPortObjects[ identifier ]; 117 XXPortObject *obj = mXXPortObjects[ identifier ];
117 if ( !obj ) { 118 if ( !obj ) {
118 KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); 119 KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
119 return; 120 return;
120 } 121 }
121 122
122 KABC::Resource *resource = mCore->requestResource( mCore ); 123 KABC::Resource *resource = mCore->requestResource( mCore );
123 if ( !resource ) 124 if ( !resource )
124 return; 125 return;
125 126
126 KABC::AddresseeList list = obj->importContacts( data ); 127 KABC::AddresseeList list = obj->importContacts( data );
127 bool useUndo = ( list.count() < 25 ); 128 bool useUndo = ( list.count() < 25 );
128#ifdef DESKTOP_VERSION 129#ifdef DESKTOP_VERSION
129 useUndo = true; 130 useUndo = true;
130#endif 131#endif
131 mShowPreview = true; 132 mShowPreview = true;
132 KABC::AddresseeList::Iterator it; 133 KABC::AddresseeList::Iterator it;
133 bool imported = false; 134 bool imported = false;
134 int count = 0; 135 int count = 0;
136
137 KConfig config( locateLocal("config", "kabcrc") );
138 config.setGroup( "General" );
139 int FormattedNameType = config.readNumEntry( "FormattedNameType", 1 );
140
141
135 for ( it = list.begin(); it != list.end(); ++it ) { 142 for ( it = list.begin(); it != list.end(); ++it ) {
136 if ( mShowPreview ) { 143 if ( mShowPreview ) {
137 PreviewDialog dlg( *it, mCore ); 144 PreviewDialog dlg( *it, mCore );
138 connect( &dlg, SIGNAL( closeClicked() ), this, SLOT ( noPreview()) ); 145 connect( &dlg, SIGNAL( closeClicked() ), this, SLOT ( noPreview()) );
139 if ( !dlg.exec() ) { 146 if ( !dlg.exec() ) {
140 if ( mShowPreview ) 147 if ( mShowPreview )
141 continue; 148 continue;
142 } 149 }
143 } 150 }
144
145 (*it).setResource( resource ); 151 (*it).setResource( resource );
152 if ( (*it).formattedName().isEmpty() )
153 (*it).setFormattedName( NameEditDialog::formattedName( (*it), FormattedNameType ) );
146 if ( useUndo ) { 154 if ( useUndo ) {
155 ++count;
147 // We use a PwNewCommand so the user can undo it. 156 // We use a PwNewCommand so the user can undo it.
148 PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); 157 PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it );
149 UndoStack::instance()->push( command ); 158 UndoStack::instance()->push( command );
150 RedoStack::instance()->clear(); 159 RedoStack::instance()->clear();
151 } else { 160 } else {
152 ++count; 161 ++count;
153 mCore->addressBook()->insertAddressee( (*it), true, true ); 162 mCore->addressBook()->insertAddressee( (*it), true, true );
154 } 163 }
155 imported = true; 164 imported = true;
156 } 165 }
157
158 if ( imported ) { 166 if ( imported ) {
159 KMessageBox::information( mCore, i18n( "%1 contacts\nsuccessfully\nimported.").arg( count) ); 167 KMessageBox::information( mCore, i18n( "%1 contacts\nsuccessfully\nimported.").arg( count) );
160
161 emit modified(); 168 emit modified();
162 } 169 }
163} 170}
164void XXPortManager::noPreview() 171void XXPortManager::noPreview()
165{ 172{
166 mShowPreview = false; 173 mShowPreview = false;
167} 174}
168void XXPortManager::slotExport( const QString &identifier, const QString &data ) 175void XXPortManager::slotExport( const QString &identifier, const QString &data )
169{ 176{
170 XXPortObject *obj = mXXPortObjects[ identifier ]; 177 XXPortObject *obj = mXXPortObjects[ identifier ];
171 if ( !obj ) { 178 if ( !obj ) {
172 KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) ); 179 KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
173 return; 180 return;
174 } 181 }
175 182
176 KABC::AddresseeList addrList; 183 KABC::AddresseeList addrList;
177 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore ); 184 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore );
178 if ( dlg.exec() ) 185 if ( dlg.exec() )
179 addrList = dlg.contacts(); 186 addrList = dlg.contacts();
180 else 187 else
181 return; 188 return;
182 if ( !obj->exportContacts( addrList, data ) ) 189 if ( !obj->exportContacts( addrList, data ) )
183 KMessageBox::error( mCore, i18n( "Unable to export contacts." ) ); 190 KMessageBox::error( mCore, i18n( "Unable to export contacts." ) );
184 else 191 else
185 KMessageBox::information( mCore, i18n( "contacts successfully exported." ) ); 192 KMessageBox::information( mCore, i18n( "contacts successfully exported." ) );
186} 193}
187 194
188void XXPortManager::loadPlugins() 195void XXPortManager::loadPlugins()
189{ 196{
190 mXXPortObjects.clear(); 197 mXXPortObjects.clear();
191 198
192#ifndef KAB_EMBEDDED 199#ifndef KAB_EMBEDDED
193 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" ); 200 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" );
194 KTrader::OfferList::ConstIterator it; 201 KTrader::OfferList::ConstIterator it;
195 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 202 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
196 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) ) 203 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) )
197 continue; 204 continue;
198 205
199 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); 206 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
200 if ( !factory ) { 207 if ( !factory ) {
201 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl; 208 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl;
202 continue; 209 continue;
203 } 210 }
204 211
205 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory ); 212 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory );
206 213
207 if ( !xxportFactory ) { 214 if ( !xxportFactory ) {
208 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl; 215 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl;
209 continue; 216 continue;
210 } 217 }
211 218
212#else //KAB_EMBEDDED 219#else //KAB_EMBEDDED
213 QList<XXPortFactory> factorylist; 220 QList<XXPortFactory> factorylist;
214 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport())); 221 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_csv_xxport()));
215 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport())); 222 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_kde2_xxport()));
216 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport())); 223 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_vcard_xxport()));
217 //US factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport())); 224 //US factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_opie_xxport()));
218 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport())); 225 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_qtopia_xxport()));
219 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport())); 226 factorylist.append(static_cast<XXPortFactory*>(init_microkaddrbk_sharpdtm_xxport()));
220 227
221 QListIterator<XXPortFactory> it(factorylist); 228 QListIterator<XXPortFactory> it(factorylist);
222 for ( ; it.current(); ++it ) 229 for ( ; it.current(); ++it )
223 { 230 {
224 XXPortFactory *xxportFactory = it.current(); 231 XXPortFactory *xxportFactory = it.current();
225#endif //KAB_EMBEDDED 232#endif //KAB_EMBEDDED
226 233
227 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore ); 234 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
228 if ( obj ) { 235 if ( obj ) {
229 mCore->addGUIClient( obj ); 236 mCore->addGUIClient( obj );
230 mXXPortObjects.insert( obj->identifier(), obj ); 237 mXXPortObjects.insert( obj->identifier(), obj );
231 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ), 238 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
232 this, SLOT( slotExport( const QString&, const QString& ) ) ); 239 this, SLOT( slotExport( const QString&, const QString& ) ) );
233 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ), 240 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
234 this, SLOT( slotImport( const QString&, const QString& ) ) ); 241 this, SLOT( slotImport( const QString&, const QString& ) ) );
235 } 242 }
236 } 243 }
237} 244}
238 245
239 246
240PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, 247PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent,
241 const char *name ) 248 const char *name )
242 : KDialogBase( Plain, i18n( "Import this contact?" ), Ok | User1| User2, Ok, parent, 249 : KDialogBase( Plain, i18n( "Import this contact?" ), Ok | User1| User2, Ok, parent,
243 name, true, true ,i18n( "Import all!" ),i18n( "No" ) ) 250 name, true, true ,i18n( "Import all!" ),i18n( "No" ) )
244{ 251{
245 QWidget *page = plainPage(); 252 QWidget *page = plainPage();
246 QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() ); 253 QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() );
247 connect( this, SIGNAL( user1Clicked() ), this, SLOT ( slotClose() ) ); 254 connect( this, SIGNAL( user1Clicked() ), this, SLOT ( slotClose() ) );
248 connect( this, SIGNAL( user2Clicked() ), this, SLOT ( slotCancel() ) ); 255 connect( this, SIGNAL( user2Clicked() ), this, SLOT ( slotCancel() ) );
249 256
250 KABC::AddresseeView *view = new KABC::AddresseeView( page ); 257 KABC::AddresseeView *view = new KABC::AddresseeView( page );
251 view->setAddressee( addr ); 258 view->setAddressee( addr );
252 layout->addWidget( view ); 259 layout->addWidget( view );
253#ifdef DESKTOP_VERSION 260#ifdef DESKTOP_VERSION
254 resize( 640, 480 ); 261 resize( 640, 480 );
255#else 262#else
256 showMaximized(); 263 showMaximized();