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