summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 11eeabc..980e436 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -292,63 +292,115 @@ KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const
292 292
293 293
294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
295 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); 295 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)));
296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); 296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&)));
297 297
298 298
299#ifndef KAB_EMBEDDED 299#ifndef KAB_EMBEDDED
300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
301 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 301 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
302 302
303 connect( mDetails, SIGNAL( browse( const QString& ) ), 303 connect( mDetails, SIGNAL( browse( const QString& ) ),
304 SLOT( browse( const QString& ) ) ); 304 SLOT( browse( const QString& ) ) );
305 305
306 306
307 mAddressBookService = new KAddressBookService( this ); 307 mAddressBookService = new KAddressBookService( this );
308 308
309#endif //KAB_EMBEDDED 309#endif //KAB_EMBEDDED
310 310
311 mMessageTimer = new QTimer( this ); 311 mMessageTimer = new QTimer( this );
312 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); 312 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) );
313 mEditorDialog = 0; 313 mEditorDialog = 0;
314 createAddresseeEditorDialog( this ); 314 createAddresseeEditorDialog( this );
315 setModified( false ); 315 setModified( false );
316 mBRdisabled = 0;
317#ifndef DESKTOP_VERSION
318 infrared = 0;
319#endif
320 toggleBeamReceive( );
316} 321}
317 322
318KABCore::~KABCore() 323KABCore::~KABCore()
319{ 324{
320 // save(); 325 // save();
321 //saveSettings(); 326 //saveSettings();
322 //KABPrefs::instance()->writeConfig(); 327 //KABPrefs::instance()->writeConfig();
323 delete AddresseeConfig::instance(); 328 delete AddresseeConfig::instance();
324 mAddressBook = 0; 329 mAddressBook = 0;
325 KABC::StdAddressBook::close(); 330 KABC::StdAddressBook::close();
326 331
327 delete syncManager; 332 delete syncManager;
333 if ( infrared )
334 delete infrared;
335}
336void KABCore::receive( const QCString& cmsg, const QByteArray& data )
337{
338 qDebug("KA: QCOP message received: %s ", cmsg.data() );
339 if ( cmsg == "setDocument(QString)" ) {
340 QDataStream stream( data, IO_ReadOnly );
341 QString fileName;
342 stream >> fileName;
343 recieve( fileName );
344 return;
345 }
346}
347void KABCore::toggleBeamReceive( )
348{
349 if ( mBRdisabled )
350 return;
351#ifndef DESKTOP_VERSION
352 if ( infrared ) {
353 qDebug("AB disable BeamReceive ");
354 delete infrared;
355 infrared = 0;
356 mActionBR->setChecked(false);
357 return;
358 }
359 qDebug("AB enable BeamReceive ");
360 mActionBR->setChecked(true);
328 361
362 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ;
363 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& )));
364#endif
329} 365}
330 366
367
368void KABCore::disableBR(bool b)
369{
370 if ( b ) {
371 if ( infrared ) {
372 toggleBeamReceive( );
373 mBRdisabled = true;
374 }
375 } else {
376 if ( mBRdisabled ) {
377 mBRdisabled = false;
378 toggleBeamReceive( );
379 }
380 }
381
382}
331void KABCore::recieve( QString fn ) 383void KABCore::recieve( QString fn )
332{ 384{
333 //qDebug("KABCore::recieve "); 385 //qDebug("KABCore::recieve ");
334 int count = mAddressBook->importFromFile( fn, true ); 386 int count = mAddressBook->importFromFile( fn, true );
335 mViewManager->refreshView(); 387 mViewManager->refreshView();
336 message(i18n("%1 contact(s) received!").arg( count )); 388 message(i18n("%1 contact(s) received!").arg( count ));
337 topLevelWidget()->showMaximized(); 389 topLevelWidget()->showMaximized();
338 topLevelWidget()->raise(); 390 topLevelWidget()->raise();
339} 391}
340void KABCore::restoreSettings() 392void KABCore::restoreSettings()
341{ 393{
342 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 394 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
343 395
344 bool state; 396 bool state;
345 397
346 if (mMultipleViewsAtOnce) 398 if (mMultipleViewsAtOnce)
347 state = KABPrefs::instance()->mDetailsPageVisible; 399 state = KABPrefs::instance()->mDetailsPageVisible;
348 else 400 else
349 state = false; 401 state = false;
350 402
351 mActionDetails->setChecked( state ); 403 mActionDetails->setChecked( state );
352 setDetailsVisible( state ); 404 setDetailsVisible( state );
353 405
354 state = KABPrefs::instance()->mJumpButtonBarVisible; 406 state = KABPrefs::instance()->mJumpButtonBarVisible;
@@ -1763,48 +1815,54 @@ void KABCore::initActions()
1763 "kaddressbook_configure" ); 1815 "kaddressbook_configure" );
1764 1816
1765 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1817 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1766 this, SLOT( configureKeyBindings() ), actionCollection(), 1818 this, SLOT( configureKeyBindings() ), actionCollection(),
1767 "kaddressbook_configure_shortcuts" ); 1819 "kaddressbook_configure_shortcuts" );
1768#ifdef KAB_EMBEDDED 1820#ifdef KAB_EMBEDDED
1769 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1821 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1770 mActionConfigureToolbars->setEnabled( false ); 1822 mActionConfigureToolbars->setEnabled( false );
1771#endif //KAB_EMBEDDED 1823#endif //KAB_EMBEDDED
1772 1824
1773 } else { 1825 } else {
1774 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1826 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1775 1827
1776 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1828 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1777 } 1829 }
1778 1830
1779 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1831 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1780 actionCollection(), "options_show_jump_bar" ); 1832 actionCollection(), "options_show_jump_bar" );
1781 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1833 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1782 1834
1783 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1835 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1784 actionCollection(), "options_show_details" ); 1836 actionCollection(), "options_show_details" );
1785 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1837 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1786 1838
1839
1840 mActionBR = new KToggleAction( i18n( "Beam receice enabled" ), "beam", 0, this,
1841 SLOT( toggleBeamReceive() ), actionCollection(),
1842 "kaddressbook_beam_rec" );
1843
1844
1787 // misc 1845 // misc
1788 // only enable LDAP lookup if we can handle the protocol 1846 // only enable LDAP lookup if we can handle the protocol
1789#ifndef KAB_EMBEDDED 1847#ifndef KAB_EMBEDDED
1790 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1848 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1791 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1849 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1792 this, SLOT( openLDAPDialog() ), actionCollection(), 1850 this, SLOT( openLDAPDialog() ), actionCollection(),
1793 "ldap_lookup" ); 1851 "ldap_lookup" );
1794 } 1852 }
1795#else //KAB_EMBEDDED 1853#else //KAB_EMBEDDED
1796 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1854 //qDebug("KABCore::initActions() LDAP has to be implemented");
1797#endif //KAB_EMBEDDED 1855#endif //KAB_EMBEDDED
1798 1856
1799 1857
1800 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1858 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1801 SLOT( setWhoAmI() ), actionCollection(), 1859 SLOT( setWhoAmI() ), actionCollection(),
1802 "set_personal" ); 1860 "set_personal" );
1803 1861
1804 1862
1805 1863
1806 1864
1807 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1865 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1808 SLOT( setCategories() ), actionCollection(), 1866 SLOT( setCategories() ), actionCollection(),
1809 "edit_set_categories" ); 1867 "edit_set_categories" );
1810 1868
@@ -1933,48 +1991,50 @@ void KABCore::addActionsManually()
1933 mActionRemoveVoice->plug( changeMenu ); 1991 mActionRemoveVoice->plug( changeMenu );
1934 // settings menu 1992 // settings menu
1935//US special menuentry to configure the addressbook resources. On KDE 1993//US special menuentry to configure the addressbook resources. On KDE
1936// you do that through the control center !!! 1994// you do that through the control center !!!
1937 mActionConfigResources->plug( settingsMenu ); 1995 mActionConfigResources->plug( settingsMenu );
1938 settingsMenu->insertSeparator(); 1996 settingsMenu->insertSeparator();
1939 1997
1940 mActionConfigKAddressbook->plug( settingsMenu ); 1998 mActionConfigKAddressbook->plug( settingsMenu );
1941 1999
1942 if ( mIsPart ) { 2000 if ( mIsPart ) {
1943 mActionConfigShortcuts->plug( settingsMenu ); 2001 mActionConfigShortcuts->plug( settingsMenu );
1944 mActionConfigureToolbars->plug( settingsMenu ); 2002 mActionConfigureToolbars->plug( settingsMenu );
1945 2003
1946 } else { 2004 } else {
1947 mActionKeyBindings->plug( settingsMenu ); 2005 mActionKeyBindings->plug( settingsMenu );
1948 } 2006 }
1949 2007
1950 settingsMenu->insertSeparator(); 2008 settingsMenu->insertSeparator();
1951 2009
1952 mActionJumpBar->plug( settingsMenu ); 2010 mActionJumpBar->plug( settingsMenu );
1953 mActionDetails->plug( settingsMenu ); 2011 mActionDetails->plug( settingsMenu );
1954 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 2012 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
1955 mActionDetails->plug( tb ); 2013 mActionDetails->plug( tb );
1956 settingsMenu->insertSeparator(); 2014 settingsMenu->insertSeparator();
2015 mActionBR->plug(settingsMenu );
2016 settingsMenu->insertSeparator();
1957 2017
1958 mActionWhoAmI->plug( settingsMenu ); 2018 mActionWhoAmI->plug( settingsMenu );
1959 mActionCategories->plug( settingsMenu ); 2019 mActionCategories->plug( settingsMenu );
1960 2020
1961 2021
1962 mActionWN->plug( helpMenu ); 2022 mActionWN->plug( helpMenu );
1963 mActionSyncHowto->plug( helpMenu ); 2023 mActionSyncHowto->plug( helpMenu );
1964 mActionLicence->plug( helpMenu ); 2024 mActionLicence->plug( helpMenu );
1965 mActionFaq->plug( helpMenu ); 2025 mActionFaq->plug( helpMenu );
1966 mActionAboutKAddressbook->plug( helpMenu ); 2026 mActionAboutKAddressbook->plug( helpMenu );
1967 2027
1968 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 2028 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
1969 2029
1970 mActionSave->plug( tb ); 2030 mActionSave->plug( tb );
1971 mViewManager->getFilterAction()->plug ( tb); 2031 mViewManager->getFilterAction()->plug ( tb);
1972 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 2032 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
1973 mActionUndo->plug( tb ); 2033 mActionUndo->plug( tb );
1974 mActionDelete->plug( tb ); 2034 mActionDelete->plug( tb );
1975 mActionRedo->plug( tb ); 2035 mActionRedo->plug( tb );
1976 } 2036 }
1977 } 2037 }
1978 //mActionQuit->plug ( tb ); 2038 //mActionQuit->plug ( tb );
1979 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 2039 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
1980 2040
@@ -2726,68 +2786,70 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2726 qDebug("Saving remote AB "); 2786 qDebug("Saving remote AB ");
2727 if ( ! abLocal.saveAB()) 2787 if ( ! abLocal.saveAB())
2728 qDebug("Error writing back AB to file "); 2788 qDebug("Error writing back AB to file ");
2729 if ( isXML ) { 2789 if ( isXML ) {
2730 // afterwrite processing 2790 // afterwrite processing
2731 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2791 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2732 } 2792 }
2733 } 2793 }
2734 } 2794 }
2735 setModified(); 2795 setModified();
2736 2796
2737 } 2797 }
2738 if ( syncOK ) 2798 if ( syncOK )
2739 mViewManager->refreshView(); 2799 mViewManager->refreshView();
2740 return syncOK; 2800 return syncOK;
2741 2801
2742} 2802}
2743 2803
2744 2804
2745//this is a overwritten callbackmethods from the syncinterface 2805//this is a overwritten callbackmethods from the syncinterface
2746bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2806bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2747{ 2807{
2748 if ( resource == "phone" ) 2808 if ( resource == "phone" )
2749 return syncPhone(); 2809 return syncPhone();
2810 disableBR( true );
2750 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2811 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2751 2812
2752 AddressBook abLocal( resource,"syncContact"); 2813 AddressBook abLocal( resource,"syncContact");
2753 bool syncOK = false; 2814 bool syncOK = false;
2754 if ( abLocal.load() ) { 2815 if ( abLocal.load() ) {
2755 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2816 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2756 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2817 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2757 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2818 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2758 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2819 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2759 if ( syncOK ) { 2820 if ( syncOK ) {
2760 if ( syncManager->mWriteBackFile ) { 2821 if ( syncManager->mWriteBackFile ) {
2761 abLocal.removeSyncAddressees( false ); 2822 abLocal.removeSyncAddressees( false );
2762 abLocal.saveAB(); 2823 abLocal.saveAB();
2763 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2824 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2764 } 2825 }
2765 } 2826 }
2766 setModified(); 2827 setModified();
2767 } 2828 }
2768 if ( syncOK ) 2829 if ( syncOK )
2769 mViewManager->refreshView(); 2830 mViewManager->refreshView();
2831 disableBR( false );
2770 return syncOK; 2832 return syncOK;
2771 2833
2772} 2834}
2773void KABCore::message( QString m ) 2835void KABCore::message( QString m )
2774{ 2836{
2775 topLevelWidget()->setCaption( m ); 2837 topLevelWidget()->setCaption( m );
2776 mMessageTimer->start( 15000, true ); 2838 mMessageTimer->start( 15000, true );
2777} 2839}
2778bool KABCore::syncPhone() 2840bool KABCore::syncPhone()
2779{ 2841{
2780 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2842 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2781 QString fileName = getPhoneFile(); 2843 QString fileName = getPhoneFile();
2782 if ( !PhoneAccess::readFromPhone( fileName) ) { 2844 if ( !PhoneAccess::readFromPhone( fileName) ) {
2783 message(i18n("Phone access failed!")); 2845 message(i18n("Phone access failed!"));
2784 return false; 2846 return false;
2785 } 2847 }
2786 AddressBook abLocal( fileName,"syncContact"); 2848 AddressBook abLocal( fileName,"syncContact");
2787 bool syncOK = false; 2849 bool syncOK = false;
2788 { 2850 {
2789 abLocal.importFromFile( fileName ); 2851 abLocal.importFromFile( fileName );
2790 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2852 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2791 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2853 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2792 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2854 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2793 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2855 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );