summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp52
1 files changed, 30 insertions, 22 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 9526f23..d393660 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -204,49 +204,50 @@ class KABFormatPrefs : public QDialog
204 QDialog( parent, name, true ) 204 QDialog( parent, name, true )
205 { 205 {
206 setCaption( i18n("Set formatted name") ); 206 setCaption( i18n("Set formatted name") );
207 QVBoxLayout* lay = new QVBoxLayout( this ); 207 QVBoxLayout* lay = new QVBoxLayout( this );
208 lay->setSpacing( 3 ); 208 lay->setSpacing( 3 );
209 lay->setMargin( 3 ); 209 lay->setMargin( 3 );
210 QLabel * lab = new QLabel( i18n("You can set the formatted name\nfor a list of contacts in one go."), this ); 210 QLabel * lab = new QLabel( i18n("You can set the formatted name\nfor a list of contacts in one go."), this );
211 lay->addWidget( lab ); 211 lay->addWidget( lab );
212 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Set formatted name to:"), this ); 212 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Set formatted name to:"), this );
213 lay->addWidget( format ); 213 lay->addWidget( format );
214 format->setExclusive ( true ) ; 214 format->setExclusive ( true ) ;
215 simple = new QRadioButton(i18n("Simple: James Bond"), format ); 215 simple = new QRadioButton(i18n("Simple: James Bond"), format );
216 full = new QRadioButton(i18n("Full: Mr. James 007 Bond I"), format ); 216 full = new QRadioButton(i18n("Full: Mr. James 007 Bond I"), format );
217 reverse = new QRadioButton(i18n("Reverse: Bond, James"), format ); 217 reverse = new QRadioButton(i18n("Reverse: Bond, James"), format );
218 company = new QRadioButton(i18n("Organization: MI6"), format ); 218 company = new QRadioButton(i18n("Organization: MI6"), format );
219 simple->setChecked( true ); 219 simple->setChecked( true );
220 setCompany = new QCheckBox(i18n("Set formatted name to\norganization, if name empty"), this); 220 setCompany = new QCheckBox(i18n("Set formatted name to\norganization, if name empty"), this);
221 lay->addWidget( setCompany ); 221 lay->addWidget( setCompany );
222 QPushButton * ok = new QPushButton( i18n("Select contact list"), this ); 222 QPushButton * ok = new QPushButton( i18n("Select contact list"), this );
223 lay->addWidget( ok ); 223 lay->addWidget( ok );
224 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 224 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
225 lay->addWidget( cancel ); 225 lay->addWidget( cancel );
226 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 226 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
227 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 227 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
228 resize( 200, 200 ); 228 //resize( 200, 200 );
229
229 } 230 }
230public: 231public:
231 QRadioButton* simple, *full, *reverse, *company; 232 QRadioButton* simple, *full, *reverse, *company;
232 QCheckBox* setCompany; 233 QCheckBox* setCompany;
233}; 234};
234 235
235 236
236 237
237class KAex2phonePrefs : public QDialog 238class KAex2phonePrefs : public QDialog
238{ 239{
239 public: 240 public:
240 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 241 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
241 QDialog( parent, name, true ) 242 QDialog( parent, name, true )
242 { 243 {
243 setCaption( i18n("Export to phone options") ); 244 setCaption( i18n("Export to phone options") );
244 QVBoxLayout* lay = new QVBoxLayout( this ); 245 QVBoxLayout* lay = new QVBoxLayout( this );
245 lay->setSpacing( 3 ); 246 lay->setSpacing( 3 );
246 lay->setMargin( 3 ); 247 lay->setMargin( 3 );
247 QLabel *lab; 248 QLabel *lab;
248 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 249 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
249 lab->setAlignment (AlignHCenter ); 250 lab->setAlignment (AlignHCenter );
250 QHBox* temphb; 251 QHBox* temphb;
251 temphb = new QHBox( this ); 252 temphb = new QHBox( this );
252 new QLabel( i18n("I/O device: "), temphb ); 253 new QLabel( i18n("I/O device: "), temphb );
@@ -1352,49 +1353,50 @@ void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1352{ 1353{
1353 if ( mMultipleViewsAtOnce ) 1354 if ( mMultipleViewsAtOnce )
1354 { 1355 {
1355 editContact( uid ); 1356 editContact( uid );
1356 } 1357 }
1357 else 1358 else
1358 { 1359 {
1359 setDetailsVisible( true ); 1360 setDetailsVisible( true );
1360 mActionDetails->setChecked(true); 1361 mActionDetails->setChecked(true);
1361 } 1362 }
1362 1363
1363} 1364}
1364 1365
1365void KABCore::save() 1366void KABCore::save()
1366{ 1367{
1367 if (syncManager->blockSave()) 1368 if (syncManager->blockSave())
1368 return; 1369 return;
1369 if ( !mModified ) 1370 if ( !mModified )
1370 return; 1371 return;
1371 1372
1372 syncManager->setBlockSave(true); 1373 syncManager->setBlockSave(true);
1373 QString text = i18n( "There was an error while attempting to save\n the " 1374 QString text = i18n( "There was an error while attempting to save\n the "
1374 "address book. Please check that some \nother application is " 1375 "address book. Please check that some \nother application is "
1375 "not using it. " ); 1376 "not using it. " );
1376 message(i18n("Saving addressbook ... ")); 1377 message(i18n("Saving ... please wait! "));
1378 qApp->processEvents();
1377#ifndef KAB_EMBEDDED 1379#ifndef KAB_EMBEDDED
1378 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1380 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1379 if ( !b || !b->save() ) { 1381 if ( !b || !b->save() ) {
1380 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1382 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1381 } 1383 }
1382#else //KAB_EMBEDDED 1384#else //KAB_EMBEDDED
1383 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1385 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1384 if ( !b || !b->save() ) { 1386 if ( !b || !b->save() ) {
1385 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1387 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1386 } 1388 }
1387#endif //KAB_EMBEDDED 1389#endif //KAB_EMBEDDED
1388 1390
1389 message(i18n("Addressbook saved!")); 1391 message(i18n("Addressbook saved!"));
1390 setModified( false ); 1392 setModified( false );
1391 syncManager->setBlockSave(false); 1393 syncManager->setBlockSave(false);
1392} 1394}
1393 1395
1394 1396
1395void KABCore::undo() 1397void KABCore::undo()
1396{ 1398{
1397 UndoStack::instance()->undo(); 1399 UndoStack::instance()->undo();
1398 1400
1399 // Refresh the view 1401 // Refresh the view
1400 mViewManager->refreshView(); 1402 mViewManager->refreshView();
@@ -2342,73 +2344,79 @@ void KABCore::manageCategories( )
2342} 2344}
2343void KABCore::removeVoice() 2345void KABCore::removeVoice()
2344{ 2346{
2345 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) 2347 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No )
2346 return; 2348 return;
2347 KABC::Addressee::List list; 2349 KABC::Addressee::List list;
2348 XXPortSelectDialog dlg( this, false, this ); 2350 XXPortSelectDialog dlg( this, false, this );
2349 if ( dlg.exec() ) 2351 if ( dlg.exec() )
2350 list = dlg.contacts(); 2352 list = dlg.contacts();
2351 else 2353 else
2352 return; 2354 return;
2353 KABC::Addressee::List::Iterator it; 2355 KABC::Addressee::List::Iterator it;
2354 for ( it = list.begin(); it != list.end(); ++it ) { 2356 for ( it = list.begin(); it != list.end(); ++it ) {
2355 if ( (*it).removeVoice() ) 2357 if ( (*it).removeVoice() )
2356 addrModified((*it), false ); 2358 addrModified((*it), false );
2357 } 2359 }
2358} 2360}
2359 2361
2360void KABCore::setFormattedName() 2362void KABCore::setFormattedName()
2361{ 2363{
2362 KABFormatPrefs setpref; 2364 KABFormatPrefs setpref;
2363 if ( !setpref.exec() ) { 2365 if ( !setpref.exec() ) {
2364 return; 2366 return;
2365 } 2367 }
2366 KABC::Addressee::List list;
2367 XXPortSelectDialog dlg( this, false, this ); 2368 XXPortSelectDialog dlg( this, false, this );
2368 if ( dlg.exec() ) 2369 if ( !dlg.exec() )
2369 list = dlg.contacts();
2370 else
2371 return; 2370 return;
2372 KABC::Addressee::List::Iterator it; 2371 mAddressBook->setUntagged();
2373 for ( it = list.begin(); it != list.end(); ++it ) { 2372 dlg.tagSelected();
2374 QString fName; 2373 int count = 0;
2375 if ( setpref.simple->isChecked() ) 2374 KABC::AddressBook::Iterator it;
2376 fName = NameEditDialog::formattedName( (*it), NameEditDialog::SimpleName ); 2375 for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2377 else if ( setpref.full->isChecked() ) 2376 if ( (*it).tagged() ) {
2378 fName = NameEditDialog::formattedName( (*it), NameEditDialog::FullName ); 2377 message(i18n("Changing contact #%1").arg( ++count ) );
2379 else if ( setpref.reverse->isChecked() ) 2378 qApp->processEvents();
2380 fName = NameEditDialog::formattedName( (*it), NameEditDialog::ReverseName ); 2379 QString fName;
2381 else 2380 if ( setpref.simple->isChecked() )
2382 fName = (*it).organization(); 2381 fName = NameEditDialog::formattedName( (*it), NameEditDialog::SimpleName );
2383 if ( setpref.setCompany->isChecked() ) 2382 else if ( setpref.full->isChecked() )
2384 if ( fName.isEmpty() || fName =="," ) 2383 fName = NameEditDialog::formattedName( (*it), NameEditDialog::FullName );
2384 else if ( setpref.reverse->isChecked() )
2385 fName = NameEditDialog::formattedName( (*it), NameEditDialog::ReverseName );
2386 else
2385 fName = (*it).organization(); 2387 fName = (*it).organization();
2386 (*it).setFormattedName( fName ); 2388 if ( setpref.setCompany->isChecked() )
2387 addrModified((*it),false ); 2389 if ( fName.isEmpty() || fName =="," )
2390 fName = (*it).organization();
2391 (*it).setFormattedName( fName );
2392 }
2388 } 2393 }
2394 message(i18n("Refreshing view...") );
2395 mViewManager->refreshView( "" );
2389 Addressee add; 2396 Addressee add;
2390 mDetails->setAddressee( add ); 2397 mDetails->setAddressee( add );
2398 message(i18n("Setting formatted name completed!") );
2391} 2399}
2392 2400
2393void KABCore::clipboardDataChanged() 2401void KABCore::clipboardDataChanged()
2394{ 2402{
2395 2403
2396 if ( mReadWrite ) 2404 if ( mReadWrite )
2397 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2405 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2398 2406
2399} 2407}
2400 2408
2401void KABCore::updateActionMenu() 2409void KABCore::updateActionMenu()
2402{ 2410{
2403 UndoStack *undo = UndoStack::instance(); 2411 UndoStack *undo = UndoStack::instance();
2404 RedoStack *redo = RedoStack::instance(); 2412 RedoStack *redo = RedoStack::instance();
2405 2413
2406 if ( undo->isEmpty() ) 2414 if ( undo->isEmpty() )
2407 mActionUndo->setText( i18n( "Undo" ) ); 2415 mActionUndo->setText( i18n( "Undo" ) );
2408 else 2416 else
2409 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2417 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2410 2418
2411 mActionUndo->setEnabled( !undo->isEmpty() ); 2419 mActionUndo->setEnabled( !undo->isEmpty() );
2412 2420
2413 if ( !redo->top() ) 2421 if ( !redo->top() )
2414 mActionRedo->setText( i18n( "Redo" ) ); 2422 mActionRedo->setText( i18n( "Redo" ) );
@@ -3185,49 +3193,49 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
3185 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 3193 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
3186 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 3194 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
3187 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 3195 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
3188 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 3196 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
3189 if ( syncOK ) { 3197 if ( syncOK ) {
3190 if ( syncManager->mWriteBackFile ) { 3198 if ( syncManager->mWriteBackFile ) {
3191 abLocal.removeSyncAddressees( false ); 3199 abLocal.removeSyncAddressees( false );
3192 abLocal.saveAB(); 3200 abLocal.saveAB();
3193 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 3201 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
3194 } 3202 }
3195 } else 3203 } else
3196 message( i18n("Sync cancelled or failed.") ); 3204 message( i18n("Sync cancelled or failed.") );
3197 setModified(); 3205 setModified();
3198 } 3206 }
3199 abLocal.removeResources(); 3207 abLocal.removeResources();
3200 if ( syncOK ) 3208 if ( syncOK )
3201 mViewManager->refreshView(); 3209 mViewManager->refreshView();
3202 disableBR( false ); 3210 disableBR( false );
3203 return syncOK; 3211 return syncOK;
3204 3212
3205} 3213}
3206void KABCore::message( QString m ) 3214void KABCore::message( QString m )
3207{ 3215{
3208 topLevelWidget()->setCaption( m ); 3216 topLevelWidget()->setCaption( m );
3209 mMessageTimer->start( 15000, true ); 3217 mMessageTimer->start( 20000, true );
3210} 3218}
3211bool KABCore::syncPhone() 3219bool KABCore::syncPhone()
3212{ 3220{
3213 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3221 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3214 QString fileName = getPhoneFile(); 3222 QString fileName = getPhoneFile();
3215 if ( !PhoneAccess::readFromPhone( fileName) ) { 3223 if ( !PhoneAccess::readFromPhone( fileName) ) {
3216 message(i18n("Phone access failed!")); 3224 message(i18n("Phone access failed!"));
3217 return false; 3225 return false;
3218 } 3226 }
3219 AddressBook abLocal( fileName,"syncContact"); 3227 AddressBook abLocal( fileName,"syncContact");
3220 bool syncOK = false; 3228 bool syncOK = false;
3221 { 3229 {
3222 abLocal.importFromFile( fileName ); 3230 abLocal.importFromFile( fileName );
3223 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 3231 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
3224 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 3232 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
3225 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 3233 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
3226 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 3234 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
3227 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 3235 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
3228 if ( syncOK ) { 3236 if ( syncOK ) {
3229 if ( syncManager->mWriteBackFile ) { 3237 if ( syncManager->mWriteBackFile ) {
3230 abLocal.removeSyncAddressees( true ); 3238 abLocal.removeSyncAddressees( true );
3231 abLocal.saveABphone( fileName ); 3239 abLocal.saveABphone( fileName );
3232 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 3240 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
3233 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 3241 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );