Diffstat (limited to 'kaddressbook/xxportmanager.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kaddressbook/xxportmanager.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp index 89a2626..7cb67ed 100644 --- a/kaddressbook/xxportmanager.cpp +++ b/kaddressbook/xxportmanager.cpp | |||
@@ -103,72 +103,89 @@ void XXPortManager::importVCard( const KURL &url, bool showPreview ) | |||
103 | } | 103 | } |
104 | 104 | ||
105 | void XXPortManager::importVCard( const QString &vCard, bool showPreview ) | 105 | void 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 | ||
114 | void XXPortManager::slotImport( const QString &identifier, const QString &data ) | 114 | void 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()) ); |
139 | if ( !dlg.exec() ) { | ||
140 | if ( mShowPreview ) | ||
133 | continue; | 141 | continue; |
134 | } | 142 | } |
143 | } | ||
135 | 144 | ||
136 | (*it).setResource( resource ); | 145 | (*it).setResource( resource ); |
146 | if ( useUndo ) { | ||
137 | // We use a PwNewCommand so the user can undo it. | 147 | // We use a PwNewCommand so the user can undo it. |
138 | PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); | 148 | PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it ); |
139 | UndoStack::instance()->push( command ); | 149 | UndoStack::instance()->push( command ); |
140 | RedoStack::instance()->clear(); | 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 | 164 | void XXPortManager::noPreview() | |
165 | { | ||
166 | mShowPreview = false; | ||
167 | } | ||
151 | void XXPortManager::slotExport( const QString &identifier, const QString &data ) | 168 | void 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 | ||
171 | void XXPortManager::loadPlugins() | 188 | void XXPortManager::loadPlugins() |
172 | { | 189 | { |
173 | mXXPortObjects.clear(); | 190 | mXXPortObjects.clear(); |
174 | 191 | ||
@@ -201,42 +218,46 @@ void XXPortManager::loadPlugins() | |||
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 | ||
223 | PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent, | 240 | PreviewDialog::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 | ||