author | ulf69 <ulf69> | 2004-10-01 05:22:45 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-01 05:22:45 (UTC) |
commit | ae6aaaf2ec81317d275ebaabba2de188279b58cd (patch) (side-by-side diff) | |
tree | f773df13a4e4f9fa5c6c54d01786e2de561ae661 | |
parent | 11c2acda0533e579512cf416de870328a79e66e8 (diff) | |
download | kdepimpi-ae6aaaf2ec81317d275ebaabba2de188279b58cd.zip kdepimpi-ae6aaaf2ec81317d275ebaabba2de188279b58cd.tar.gz kdepimpi-ae6aaaf2ec81317d275ebaabba2de188279b58cd.tar.bz2 |
moved the global sync stuff from kabcore into a new class ksyncmanaager which
can be used from all types of applications, like kapi, kopi and pwmpi
-rw-r--r-- | kaddressbook/kabcore.cpp | 507 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 38 | ||||
-rw-r--r-- | kaddressbook/kabprefs.h | 18 | ||||
-rw-r--r-- | libkdepim/kpimprefs.h | 21 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 274 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 75 | ||||
-rw-r--r-- | libkdepim/libkdepimE.pro | 2 |
7 files changed, 332 insertions, 603 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index df634d0..f222234 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -65,303 +65,305 @@ $Id$ #include <kaboutdata.h> #include <libkdepim/categoryselectdialog.h> #include "addresseeutil.h" #include "addresseeeditordialog.h" #include "extensionmanager.h" #include "kstdaction.h" #include "kaddressbookservice.h" #include "ldapsearchdialog.h" #include "printing/printingwizard.h" #else // KAB_EMBEDDED #include <kapplication.h> #include "KDGanttMinimizeSplitter.h" #include "kaddressbookmain.h" #include "kactioncollection.h" #include "addresseedialog.h" //US #include <addresseeview.h> #include <qapp.h> #include <qmenubar.h> //#include <qtoolbar.h> #include <qmessagebox.h> #include <kdebug.h> #include <kiconloader.h> // needed for SmallIcon #include <kresources/kcmkresources.h> #include <ktoolbar.h> //#include <qlabel.h> #ifndef DESKTOP_VERSION #include <qpe/ir.h> #include <qpe/qpemenubar.h> #include <qtopia/qcopenvelope_qws.h> #else #include <qmenubar.h> #endif #endif // KAB_EMBEDDED #include "kcmconfigs/kcmkabconfig.h" #include "kcmconfigs/kcmkdepimconfig.h" #include "kpimglobalprefs.h" #include "externalapphandler.h" #include <kresources/selectdialog.h> #include <kmessagebox.h> #include <picture.h> #include <resource.h> //US#include <qsplitter.h> #include <qmap.h> #include <qdir.h> #include <qfile.h> #include <qvbox.h> #include <qlayout.h> #include <qclipboard.h> #include <qtextstream.h> #include <libkdepim/categoryselectdialog.h> #include <kabc/vcardconverter.h> #include "addresseeutil.h" #include "undocmds.h" #include "addresseeeditordialog.h" #include "viewmanager.h" #include "details/detailsviewcontainer.h" #include "kabprefs.h" #include "xxportmanager.h" #include "incsearchwidget.h" #include "jumpbuttonbar.h" #include "extensionmanager.h" #include "addresseeconfig.h" #include <kcmultidialog.h> #ifdef _WIN32_ #include "kaimportoldialog.h" #else #include <unistd.h> #endif // sync includes #include <libkdepim/ksyncprofile.h> #include <libkdepim/ksyncprefsdialog.h> bool pasteWithNewUid = true; #ifdef KAB_EMBEDDED KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) - : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), + : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ mReadWrite( readWrite ), mModified( false ), mMainWindow(client) #else //KAB_EMBEDDED KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) - : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), + : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), mReadWrite( readWrite ), mModified( false ) #endif //KAB_EMBEDDED { - - mBlockSaveFlag = false; + // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); + // syncManager->setBlockSave(false); mExtensionBarSplitter = 0; mIsPart = !parent->inherits( "KAddressBookMain" ); mAddressBook = KABC::StdAddressBook::self(); KABC::StdAddressBook::setAutomaticSave( false ); #ifndef KAB_EMBEDDED mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); #endif //KAB_EMBEDDED connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), SLOT( addressBookChanged() ) ); #if 0 // LP moved to addressbook init method mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, "X-Department", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, "X-Profession", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, "X-AssistantsName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, "X-ManagersName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, "X-SpousesName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, "X-Office", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, "X-IMAddress", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, "X-Anniversary", "KADDRESSBOOK" ); //US added this field to become compatible with Opie/qtopia addressbook // values can be "female" or "male" or "". An empty field represents undefined. mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, "X-FreeBusyUrl", "KADDRESSBOOK" ); #endif initGUI(); mIncSearchWidget->setFocus(); connect( mViewManager, SIGNAL( selected( const QString& ) ), SLOT( setContactSelected( const QString& ) ) ); connect( mViewManager, SIGNAL( executed( const QString& ) ), SLOT( executeContact( const QString& ) ) ); connect( mViewManager, SIGNAL( deleteRequest( ) ), SLOT( deleteContacts( ) ) ); connect( mViewManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); connect( mXXPortManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); connect( mIncSearchWidget, SIGNAL( fieldChanged() ), mJumpButtonBar, SLOT( recreateButtons() ) ); connect( mDetails, SIGNAL( sendEmail( const QString& ) ), SLOT( sendMail( const QString& ) ) ); connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 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&))); #ifndef KAB_EMBEDDED connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), mXXPortManager, SLOT( importVCard( const KURL& ) ) ); connect( mDetails, SIGNAL( browse( const QString& ) ), SLOT( browse( const QString& ) ) ); mAddressBookService = new KAddressBookService( this ); #endif //KAB_EMBEDDED mEditorDialog = 0; createAddresseeEditorDialog( this ); setModified( false ); } KABCore::~KABCore() { // save(); //saveSettings(); //KABPrefs::instance()->writeConfig(); delete AddresseeConfig::instance(); mAddressBook = 0; KABC::StdAddressBook::close(); + + delete syncManager; } void KABCore::restoreSettings() { mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; bool state; if (mMultipleViewsAtOnce) state = KABPrefs::instance()->mDetailsPageVisible; else state = false; mActionDetails->setChecked( state ); setDetailsVisible( state ); state = KABPrefs::instance()->mJumpButtonBarVisible; mActionJumpBar->setChecked( state ); setJumpButtonBarVisible( state ); /*US QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; if ( splitterSize.count() == 0 ) { splitterSize.append( width() / 2 ); splitterSize.append( width() / 2 ); } mMiniSplitter->setSizes( splitterSize ); if ( mExtensionBarSplitter ) { splitterSize = KABPrefs::instance()->mExtensionsSplitter; if ( splitterSize.count() == 0 ) { splitterSize.append( width() / 2 ); splitterSize.append( width() / 2 ); } mExtensionBarSplitter->setSizes( splitterSize ); } */ mViewManager->restoreSettings(); mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); mExtensionManager->restoreSettings(); #ifdef DESKTOP_VERSION int wid = width(); if ( wid < 10 ) wid = 400; #else int wid = QApplication::desktop()->width(); if ( wid < 640 ) wid = QApplication::desktop()->height(); #endif QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; if ( true /*splitterSize.count() == 0*/ ) { splitterSize.append( wid / 2 ); splitterSize.append( wid / 2 ); } mMiniSplitter->setSizes( splitterSize ); if ( mExtensionBarSplitter ) { //splitterSize = KABPrefs::instance()->mExtensionsSplitter; if ( true /*splitterSize.count() == 0*/ ) { splitterSize.append( wid / 2 ); splitterSize.append( wid / 2 ); } mExtensionBarSplitter->setSizes( splitterSize ); } } void KABCore::saveSettings() { KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); if ( mExtensionBarSplitter ) KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); #ifndef KAB_EMBEDDED KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); #endif //KAB_EMBEDDED mExtensionManager->saveSettings(); mViewManager->saveSettings(); KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); } KABC::AddressBook *KABCore::addressBook() const { return mAddressBook; } KConfig *KABCore::config() { #ifndef KAB_EMBEDDED return KABPrefs::instance()->config(); #else //KAB_EMBEDDED @@ -981,216 +983,216 @@ void KABCore::addEmail( QString aStr ) addr.setNameFromString( fullName ); addr.insertEmail( email, true ); mAddressBook->insertAddressee( addr ); mViewManager->refreshView( addr.uid() ); editContact( addr.uid() ); } #else //KAB_EMBEDDED qDebug("KABCore::addEmail finsih method"); #endif //KAB_EMBEDDED } void KABCore::importVCard( const KURL &url, bool showPreview ) { mXXPortManager->importVCard( url, showPreview ); } void KABCore::importFromOL() { #ifdef _WIN32_ KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); idgl->exec(); KABC::Addressee::List list = idgl->getAddressList(); if ( list.count() > 0 ) { KABC::Addressee::List listNew; KABC::Addressee::List listExisting; KABC::Addressee::List::Iterator it; KABC::AddressBook::Iterator iter; for ( it = list.begin(); it != list.end(); ++it ) { if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) listNew.append( (*it) ); else listExisting.append( (*it) ); } if ( listExisting.count() > 0 ) KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); if ( listNew.count() > 0 ) { pasteWithNewUid = false; pasteContacts( listNew ); pasteWithNewUid = true; } } delete idgl; #endif } void KABCore::importVCard( const QString &vCard, bool showPreview ) { mXXPortManager->importVCard( vCard, showPreview ); } //US added a second method without defaultparameter void KABCore::editContact2() { editContact( QString::null ); } void KABCore::editContact( const QString &uid ) { if ( mExtensionManager->isQuickEditVisible() ) return; // First, locate the contact entry QString localUID = uid; if ( localUID.isNull() ) { QStringList uidList = mViewManager->selectedUids(); if ( uidList.count() > 0 ) localUID = *( uidList.at( 0 ) ); } KABC::Addressee addr = mAddressBook->findByUid( localUID ); if ( !addr.isEmpty() ) { mEditorDialog->setAddressee( addr ); KApplication::execDialog ( mEditorDialog ); } } /** Shows or edits the detail view for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) { if ( mMultipleViewsAtOnce ) { editContact( uid ); } else { setDetailsVisible( true ); mActionDetails->setChecked(true); } } void KABCore::save() { - if (mBlockSaveFlag) + if (syncManager->blockSave()) return; - mBlockSaveFlag = true; + syncManager->setBlockSave(true); if ( !mModified ) return; QString text = i18n( "There was an error while attempting to save\n the " "address book. Please check that some \nother application is " "not using it. " ); statusMessage(i18n("Saving addressbook ... ")); #ifndef KAB_EMBEDDED KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); if ( !b || !b->save() ) { KMessageBox::error( this, text, i18n( "Unable to Save" ) ); } #else //KAB_EMBEDDED KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); if ( !b || !b->save() ) { QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); } #endif //KAB_EMBEDDED statusMessage(i18n("Addressbook saved!")); setModified( false ); - mBlockSaveFlag = false; + syncManager->setBlockSave(false); } void KABCore::statusMessage(QString mess , int time ) { //topLevelWidget()->setCaption( mess ); // pending setting timer to revome message } void KABCore::undo() { UndoStack::instance()->undo(); // Refresh the view mViewManager->refreshView(); } void KABCore::redo() { RedoStack::instance()->redo(); // Refresh the view mViewManager->refreshView(); } void KABCore::setJumpButtonBarVisible( bool visible ) { if (mMultipleViewsAtOnce) { if ( visible ) mJumpButtonBar->show(); else mJumpButtonBar->hide(); } else { // show the jumpbar only if "the details are hidden" == "viewmanager are shown" if (mViewManager->isVisible()) { if ( visible ) mJumpButtonBar->show(); else mJumpButtonBar->hide(); } else { mJumpButtonBar->hide(); } } } void KABCore::setDetailsToState() { setDetailsVisible( mActionDetails->isChecked() ); } void KABCore::setDetailsVisible( bool visible ) { if (visible && mDetails->isHidden()) { KABC::Addressee::List addrList = mViewManager->selectedAddressees(); if ( addrList.count() > 0 ) mDetails->setAddressee( addrList[ 0 ] ); } // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between // the listview and the detailview. We do that by changing the splitbar size. if (mMultipleViewsAtOnce) { if ( visible ) mDetails->show(); else mDetails->hide(); } else { if ( visible ) { mViewManager->hide(); mDetails->show(); } else { mViewManager->show(); mDetails->hide(); } setJumpButtonBarVisible( !visible ); } } void KABCore::extensionChanged( int id ) { //change the details view only for non desktop systems #ifndef DESKTOP_VERSION if (id == 0) @@ -1443,192 +1445,195 @@ void KABCore::initGUI() #else //KAB_EMBEDDED //US initialize viewMenu before settingup viewmanager. // Viewmanager needs this menu to plugin submenues. viewMenu = new QPopupMenu( this ); settingsMenu = new QPopupMenu( this ); //filterMenu = new QPopupMenu( this ); ImportMenu = new QPopupMenu( this ); ExportMenu = new QPopupMenu( this ); syncMenu = new QPopupMenu( this ); changeMenu= new QPopupMenu( this ); //US since we have no splitter for the embedded system, setup // a layout with two frames. One left and one right. QBoxLayout *topLayout; // = new QHBoxLayout( this ); // QBoxLayout *topLayout = (QBoxLayout*)layout(); // QWidget *mainBox = new QWidget( this ); // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); #ifdef DESKTOP_VERSION topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); topLayout->addWidget(mMiniSplitter ); mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); mViewManager = new ViewManager( this, mExtensionBarSplitter ); mDetails = new ViewContainer( mMiniSplitter ); mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); #else if ( QApplication::desktop()->width() > 480 ) { topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); } else { topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); } topLayout->addWidget(mMiniSplitter ); mViewManager = new ViewManager( this, mMiniSplitter ); mDetails = new ViewContainer( mMiniSplitter ); mExtensionManager = new ExtensionManager( this, mMiniSplitter ); #endif //eh->hide(); // topLayout->addWidget(mExtensionManager ); /*US #ifndef KAB_NOSPLITTER QHBoxLayout *topLayout = new QHBoxLayout( this ); //US topLayout->setSpacing( KDialogBase::spacingHint() ); topLayout->setSpacing( 10 ); mDetailsSplitter = new QSplitter( this ); QVBox *viewSpace = new QVBox( mDetailsSplitter ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( mDetailsSplitter ); topLayout->addWidget( mDetailsSplitter ); topLayout->setStretchFactor( mDetailsSplitter, 100 ); #else //KAB_NOSPLITTER QHBoxLayout *topLayout = new QHBoxLayout( this ); //US topLayout->setSpacing( KDialogBase::spacingHint() ); topLayout->setSpacing( 10 ); // mDetailsSplitter = new QSplitter( this ); QVBox *viewSpace = new QVBox( this ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( this ); topLayout->addWidget( viewSpace ); // topLayout->setStretchFactor( mDetailsSplitter, 100 ); topLayout->addWidget( mDetails ); #endif //KAB_NOSPLITTER */ + syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); + syncManager->setBlockSave(false); + #endif //KAB_EMBEDDED initActions(); #ifdef KAB_EMBEDDED addActionsManually(); //US make sure the export and import menues are initialized before creating the xxPortManager. mXXPortManager = new XXPortManager( this, this ); // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); // mActionQuit->plug ( mMainWindow->toolBar()); //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); // mIncSearchWidget->hide(); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); mJumpButtonBar = new JumpButtonBar( this, this ); topLayout->addWidget( mJumpButtonBar ); //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); // mMainWindow->getIconToolBar()->raise(); #endif //KAB_EMBEDDED } void KABCore::initActions() { //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); #ifndef KAB_EMBEDDED connect( QApplication::clipboard(), SIGNAL( dataChanged() ), SLOT( clipboardDataChanged() ) ); #endif //KAB_EMBEDDED // file menu if ( mIsPart ) { mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, SLOT( sendMail() ), actionCollection(), "kaddressbook_mail" ); mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, SLOT( print() ), actionCollection(), "kaddressbook_print" ); } else { mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); } mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, SLOT( save() ), actionCollection(), "file_sync" ); mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, SLOT( newContact() ), actionCollection(), "file_new_contact" ); mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, this, SLOT( mailVCard() ), actionCollection(), "file_mail_vcard"); mActionBeamVCard = 0; mActionBeam = 0; #ifndef DESKTOP_VERSION if ( Ir::supported() ) { mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, SLOT( beamVCard() ), actionCollection(), "kaddressbook_beam_vcard" ); mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, SLOT( beamMySelf() ), actionCollection(), "kaddressbook_beam_myself" ); } #endif mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, this, SLOT( editContact2() ), actionCollection(), "file_properties" ); #ifdef KAB_EMBEDDED // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, mMainWindow, SLOT( exit() ), actionCollection(), "quit" ); #endif //KAB_EMBEDDED // edit menu if ( mIsPart ) { mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, SLOT( copyContacts() ), actionCollection(), "kaddressbook_copy" ); mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, SLOT( cutContacts() ), actionCollection(), "kaddressbook_cut" ); @@ -1805,194 +1810,194 @@ void KABCore::addActionsManually() mActionNewContact->plug( fileMenu ); mActionNewContact->plug( tb ); mActionEditAddressee->plug( fileMenu ); if ((KGlobal::getDesktopSize() > KGlobal::Small ) || (!KABPrefs::instance()->mMultipleViewsAtOnce )) mActionEditAddressee->plug( tb ); fileMenu->insertSeparator(); mActionSave->plug( fileMenu ); fileMenu->insertItem( "&Import", ImportMenu ); fileMenu->insertItem( "&Export", ExportMenu ); fileMenu->insertSeparator(); mActionMailVCard->plug( fileMenu ); #ifndef DESKTOP_VERSION if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); if ( Ir::supported() ) mActionBeam->plug(fileMenu ); #endif fileMenu->insertSeparator(); mActionQuit->plug( fileMenu ); #ifdef _WIN32_ mActionImportOL->plug( ImportMenu ); #endif // edit menu mActionUndo->plug( editMenu ); mActionRedo->plug( editMenu ); editMenu->insertSeparator(); mActionCut->plug( editMenu ); mActionCopy->plug( editMenu ); mActionPaste->plug( editMenu ); mActionDelete->plug( editMenu ); editMenu->insertSeparator(); mActionSelectAll->plug( editMenu ); mActionRemoveVoice->plug( changeMenu ); // settings menu //US special menuentry to configure the addressbook resources. On KDE // you do that through the control center !!! mActionConfigResources->plug( settingsMenu ); settingsMenu->insertSeparator(); mActionConfigKAddressbook->plug( settingsMenu ); if ( mIsPart ) { mActionConfigShortcuts->plug( settingsMenu ); mActionConfigureToolbars->plug( settingsMenu ); } else { mActionKeyBindings->plug( settingsMenu ); } settingsMenu->insertSeparator(); mActionJumpBar->plug( settingsMenu ); mActionDetails->plug( settingsMenu ); if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) mActionDetails->plug( tb ); settingsMenu->insertSeparator(); mActionWhoAmI->plug( settingsMenu ); mActionCategories->plug( settingsMenu ); mActionLicence->plug( helpMenu ); mActionFaq->plug( helpMenu ); mActionAboutKAddressbook->plug( helpMenu ); if (KGlobal::getDesktopSize() > KGlobal::Small ) { mActionSave->plug( tb ); mViewManager->getFilterAction()->plug ( tb); if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { mActionUndo->plug( tb ); mActionDelete->plug( tb ); mActionRedo->plug( tb ); } } //mActionQuit->plug ( tb ); // tb->insertWidget(-1, 0, mIncSearchWidget, 6); //US link the searchwidget first to this. // The real linkage to the toolbar happens later. //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); //US tb->insertItem( mIncSearchWidget ); /*US mIncSearchWidget = new IncSearchWidget( tb ); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); mJumpButtonBar = new JumpButtonBar( this, this ); //US topLayout->addWidget( mJumpButtonBar ); this->layout()->add( mJumpButtonBar ); */ #endif //KAB_EMBEDDED - connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); - fillSyncMenu(); + connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); + syncManager->fillSyncMenu(); } void KABCore::showLicence() { KApplication::showLicence(); } void KABCore::removeVoice() { 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 ) return; KABC::Addressee::List list = mViewManager->selectedAddressees(); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found if ((*phoneIt).type() - PhoneNumber::Voice ) { (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); (*it).insertPhoneNumber( (*phoneIt) ); found = true; } } } if ( found ) contactModified((*it) ); } } void KABCore::clipboardDataChanged() { if ( mReadWrite ) mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); } void KABCore::updateActionMenu() { UndoStack *undo = UndoStack::instance(); RedoStack *redo = RedoStack::instance(); if ( undo->isEmpty() ) mActionUndo->setText( i18n( "Undo" ) ); else mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); mActionUndo->setEnabled( !undo->isEmpty() ); if ( !redo->top() ) mActionRedo->setText( i18n( "Redo" ) ); else mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); mActionRedo->setEnabled( !redo->isEmpty() ); } void KABCore::configureKeyBindings() { #ifndef KAB_EMBEDDED KKeyDialog::configure( actionCollection(), true ); #else //KAB_EMBEDDED qDebug("KABCore::configureKeyBindings() not implemented"); #endif //KAB_EMBEDDED } #ifdef KAB_EMBEDDED void KABCore::configureResources() { KRES::KCMKResources dlg( this, "" , 0 ); if ( !dlg.exec() ) return; KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); } #endif //KAB_EMBEDDED /* this method will be called through the QCop interface from Ko/Pi to select addresses * for the attendees list of an event. */ void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) { QStringList nameList; QStringList emailList; QStringList uidList; KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); uint i=0; for (i=0; i < list.count(); i++) { nameList.append(list[i].realName()); @@ -2008,753 +2013,354 @@ void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QSt */ void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) { qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); QString foundUid = QString::null; if ( ! uid.isEmpty() ) { Addressee adrr = mAddressBook->findByUid( uid ); if ( !adrr.isEmpty() ) { foundUid = uid; } if ( email == "sendbacklist" ) { //qDebug("ssssssssssssssssssssssend "); QStringList nameList; QStringList emailList; QStringList uidList; nameList.append(adrr.realName()); emailList = adrr.emails(); uidList.append( adrr.preferredEmail()); bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); return; } } if ( email == "sendbacklist" ) return; if (foundUid.isEmpty()) { //find the uid of the person first Addressee::List namelist; Addressee::List emaillist; if (!name.isEmpty()) namelist = mAddressBook->findByName( name ); if (!email.isEmpty()) emaillist = mAddressBook->findByEmail( email ); qDebug("count %d %d ", namelist.count(),emaillist.count() ); //check if we have a match in Namelist and Emaillist if ((namelist.count() == 0) && (emaillist.count() > 0)) { foundUid = emaillist[0].uid(); } else if ((namelist.count() > 0) && (emaillist.count() == 0)) foundUid = namelist[0].uid(); else { for (int i = 0; i < namelist.count(); i++) { for (int j = 0; j < emaillist.count(); j++) { if (namelist[i] == emaillist[j]) { foundUid = namelist[i].uid(); } } } } } else { foundUid = uid; } if (!foundUid.isEmpty()) { // raise Ka/Pi if it is in the background #ifndef DESKTOP_VERSION #ifndef KORG_NODCOP //QCopEnvelope e("QPE/Application/kapi", "raise()"); #endif #endif mMainWindow->showMaximized(); mMainWindow-> raise(); mViewManager->setSelected( "", false); mViewManager->refreshView( "" ); mViewManager->setSelected( foundUid, true ); mViewManager->refreshView( foundUid ); if ( !mMultipleViewsAtOnce ) { setDetailsVisible( true ); mActionDetails->setChecked(true); } } } void KABCore::faq() { KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); } - -void KABCore::fillSyncMenu() -{ - if ( syncMenu->count() ) - syncMenu->clear(); - syncMenu->insertItem( i18n("Configure..."), 0 ); - syncMenu->insertSeparator(); - syncMenu->insertItem( i18n("Multiple sync"), 1 ); - syncMenu->insertSeparator(); - KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - config.setGroup("General"); - QStringList prof = config.readListEntry("SyncProfileNames"); - KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); - if ( prof.count() < 3 ) { - prof.clear(); - prof << i18n("Sharp_DTM"); - prof << i18n("Local_file"); - prof << i18n("Last_file"); - KSyncProfile* temp = new KSyncProfile (); - temp->setName( prof[0] ); - temp->writeConfig(&config); - temp->setName( prof[1] ); - temp->writeConfig(&config); - temp->setName( prof[2] ); - temp->writeConfig(&config); - config.setGroup("General"); - config.writeEntry("SyncProfileNames",prof); - config.writeEntry("ExternSyncProfiles","Sharp_DTM"); - config.sync(); - delete temp; - } - KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); - KABPrefs::instance()->mSyncProfileNames = prof; - int i; - for ( i = 0; i < prof.count(); ++i ) { - - syncMenu->insertItem( prof[i], 1000+i ); - if ( i == 2 ) - syncMenu->insertSeparator(); - } - QDir app_dir; - if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { - syncMenu->setItemEnabled( false , 1000 ); - } - //probaly useless - //mView->setupExternSyncProfiles(); -} -void KABCore::slotSyncMenu( int action ) -{ - //qDebug("syncaction %d ", action); - if ( action == 0 ) { - - // seems to be a Qt2 event handling bug - // syncmenu.clear causes a segfault at first time - // when we call it after the main event loop, it is ok - // same behaviour when calling OM/Pi via QCOP for the first time - QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); - //confSync(); - - return; - } - if ( action == 1 ) { - multiSync( true ); - return; - } - - if (mBlockSaveFlag) - return; - mBlockSaveFlag = true; - mCurrentSyncProfile = action - 1000 ; - mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; - mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; - KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - KSyncProfile* temp = new KSyncProfile (); - temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); - temp->readConfig(&config); - KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); - KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); - KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); - KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); - KABPrefs::instance()->mWriteBackInFuture = 0; - if ( temp->getWriteBackFuture() ) - KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); - KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); - if ( action == 1000 ) { - syncSharp(); - - } else if ( action == 1001 ) { - syncLocalFile(); - - } else if ( action == 1002 ) { - quickSyncLocalFile(); - - } else if ( action >= 1003 ) { - if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); - } else { - if ( temp->getIsPhoneSync() ) { - KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; - KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); - KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); - syncPhone(); - } else - syncRemote( temp ); - - } - } - delete temp; - mBlockSaveFlag = false; -} - -void KABCore::syncLocalFile() -{ - - QString fn =KABPrefs::instance()->mLastSyncedLocalFile; - - fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); - if ( fn == "" ) - return; - if ( syncWithFile( fn, false ) ) { - qDebug("syncLocalFile() successful "); - } - -} -bool KABCore::syncWithFile( QString fn , bool quick ) -{ - bool ret = false; - QFileInfo info; - info.setFile( fn ); - QString mess; - bool loadbup = true; - if ( !info. exists() ) { - mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); - int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), - mess ); - return ret; - } - int result = 0; - if ( !quick ) { - mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); - result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), - mess, - i18n("Sync"), i18n("Cancel"), 0, - 0, 1 ); - if ( result ) - return false; - } - if ( KABPrefs::instance()->mAskForPreferences ) - edit_sync_options(); - if ( result == 0 ) { - //qDebug("Now sycing ... "); - if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) - setCaption( i18n("Synchronization successful") ); - else - setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); - if ( ! quick ) - KABPrefs::instance()->mLastSyncedLocalFile = fn; - setModified(); - } - return ret; -} -void KABCore::quickSyncLocalFile() -{ - - if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { - qDebug("quick syncLocalFile() successful "); - - } -} -void KABCore::multiSync( bool askforPrefs ) -{ - if (mBlockSaveFlag) - return; - mBlockSaveFlag = true; - QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); - if ( QMessageBox::information( this, i18n("KO/Pi Sync"), - question, - i18n("Yes"), i18n("No"), - 0, 0 ) != 0 ) { - mBlockSaveFlag = false; - setCaption(i18n("Aborted! Nothing synced!")); - return; - } - mCurrentSyncDevice = i18n("Multiple profiles") ; - KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; - if ( askforPrefs ) { - edit_sync_options(); - KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; - } - setCaption(i18n("Multiple sync started.") ); - qApp->processEvents(); - int num = ringSync() ; - if ( num > 1 ) - ringSync(); - mBlockSaveFlag = false; - if ( num ) - save(); - if ( num ) - setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); - else - setCaption(i18n("Nothing synced! No profiles defined for multisync!")); - return; -} -int KABCore::ringSync() -{ - int syncedProfiles = 0; - int i; - QTime timer; - KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; - KSyncProfile* temp = new KSyncProfile (); - KABPrefs::instance()->mAskForPreferences = false; - for ( i = 0; i < syncProfileNames.count(); ++i ) { - mCurrentSyncProfile = i; - temp->setName(syncProfileNames[mCurrentSyncProfile]); - temp->readConfig(&config); - if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { - setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); - ++syncedProfiles; - // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); - KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); - KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); - KABPrefs::instance()->mWriteBackInFuture = 0; - if ( temp->getWriteBackFuture() ) - KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); - KABPrefs::instance()->mShowSyncSummary = false; - mCurrentSyncDevice = syncProfileNames[i] ; - mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; - if ( i == 0 ) { - syncSharp(); - } else { - if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); - } else { - if ( temp->getIsPhoneSync() ) { - KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; - KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); - KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); - syncPhone(); - } else - syncRemote( temp, false ); - - } - } - timer.start(); - setCaption(i18n("Multiple sync in progress ... please wait!") ); - while ( timer.elapsed () < 2000 ) { - qApp->processEvents(); -#ifndef _WIN32_ - sleep (1); -#endif - } - - } - - } - delete temp; - return syncedProfiles; -} - -void KABCore::syncRemote( KSyncProfile* prof, bool ask) -{ - QString question; - if ( ask ) { - question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; - if ( QMessageBox::information( this, i18n("KO/Pi Sync"), - question, - i18n("Yes"), i18n("No"), - 0, 0 ) != 0 ) - return; - } - QString command = prof->getPreSyncCommandAB(); - int fi; - if ( (fi = command.find("$PWD$")) > 0 ) { - QString pwd = getPassword(); - command = command.left( fi )+ pwd + command.mid( fi+5 ); - - } - int maxlen = 30; - if ( QApplication::desktop()->width() > 320 ) - maxlen += 25; - setCaption ( i18n( "Copy remote file to local machine..." ) ); - int fileSize = 0; - int result = system ( command ); - // 0 : okay - // 256: no such file or dir - // - qDebug("KO: Remote copy result(0 = okay): %d ",result ); - if ( result != 0 ) { - int len = maxlen; - while ( len < command.length() ) { - command.insert( len , "\n" ); - len += maxlen +2; - } - question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; - QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), - question, - i18n("Okay!")) ; - setCaption ("KO/Pi"); - return; - } - setCaption ( i18n( "Copying succeed." ) ); - //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); - if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { -// Event* e = mView->getLastSyncEvent(); -// e->setReadOnly( false ); -// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); -// e->setReadOnly( true ); - if ( KABPrefs::instance()->mWriteBackFile ) { - command = prof->getPostSyncCommandAB(); - int fi; - if ( (fi = command.find("$PWD$")) > 0 ) { - QString pwd = getPassword(); - command = command.left( fi )+ pwd + command.mid( fi+5 ); - - } - setCaption ( i18n( "Writing back file ..." ) ); - result = system ( command ); - qDebug("KO: Writing back file result: %d ", result); - if ( result != 0 ) { - setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); - return; - } else { - setCaption ( i18n( "Syncronization sucessfully completed" ) ); - } - } - } - return; -} -#include <qpushbutton.h> -#include <qradiobutton.h> -#include <qbuttongroup.h> -void KABCore::edit_sync_options() -{ - //mDialogManager->showSyncOptions(); - //KABPrefs::instance()->mSyncAlgoPrefs - QDialog dia( this, "dia", true ); - dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); - QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); - QVBoxLayout lay ( &dia ); - lay.setSpacing( 2 ); - lay.setMargin( 3 ); - lay.addWidget(&gr); - QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); - QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); - QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); - QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); - QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); - QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); - //QRadioButton both( i18n("Take both on conflict"), &gr ); - QPushButton pb ( "OK", &dia); - lay.addWidget( &pb ); - connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); - switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { - case 0: - loc.setChecked( true); - break; - case 1: - rem.setChecked( true ); - break; - case 2: - newest.setChecked( true); - break; - case 3: - ask.setChecked( true); - break; - case 4: - f_loc.setChecked( true); - break; - case 5: - f_rem.setChecked( true); - break; - case 6: - // both.setChecked( true); - break; - default: - break; - } - if ( dia.exec() ) { - KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; - } - - -} -QString KABCore::getPassword( ) -{ - QString retfile = ""; - QDialog dia ( this, "input-dialog", true ); - QLineEdit lab ( &dia ); - lab.setEchoMode( QLineEdit::Password ); - QVBoxLayout lay( &dia ); - lay.setMargin(7); - lay.setSpacing(7); - lay.addWidget( &lab); - dia.setFixedSize( 230,50 ); - dia.setCaption( i18n("Enter password") ); - QPushButton pb ( "OK", &dia); - lay.addWidget( &pb ); - connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); - dia.show(); - int res = dia.exec(); - if ( res ) - retfile = lab.text(); - dia.hide(); - qApp->processEvents(); - return retfile; - -} #include <libkcal/syncdefines.h> KABC::Addressee KABCore::getLastSyncAddressee() { Addressee lse; + QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); + //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); if (lse.isEmpty()) { qDebug("Creating new last-syncAddressee "); lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); QString sum = ""; if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) sum = "E: "; lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); lse.setRevision( mLastAddressbookSync ); lse.setCategories( i18n("SyncEvent") ); mAddressBook->insertAddressee( lse ); } return lse; } int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) { //void setZaurusId(int id); // int zaurusId() const; // void setZaurusUid(int id); // int zaurusUid() const; // void setZaurusStat(int id); // int zaurusStat() const; // 0 equal // 1 take local // 2 take remote // 3 cancel QDateTime lastSync = mLastAddressbookSync; QDateTime localMod = local->revision(); QDateTime remoteMod = remote->revision(); + + QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { bool remCh, locCh; remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); locCh = ( localMod > mLastAddressbookSync ); if ( !remCh && ! locCh ) { //qDebug("both not changed "); lastSync = localMod.addDays(1); if ( mode <= SYNC_PREF_ASK ) return 0; } else { if ( locCh ) { //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); lastSync = localMod.addDays( -1 ); if ( !remCh ) remoteMod =( lastSync.addDays( -1 ) ); } else { //qDebug(" not loc changed "); lastSync = localMod.addDays( 1 ); if ( remCh ) remoteMod =( lastSync.addDays( 1 ) ); } } full = true; if ( mode < SYNC_PREF_ASK ) mode = SYNC_PREF_ASK; } else { if ( localMod == remoteMod ) return 0; } // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); //full = true; //debug only if ( full ) { bool equ = ( (*local) == (*remote) ); if ( equ ) { //qDebug("equal "); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); } if ( mode < SYNC_PREF_FORCE_LOCAL ) return 0; }//else //debug only //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); } int result; bool localIsNew; //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); if ( full && mode < SYNC_PREF_NEWEST ) mode = SYNC_PREF_ASK; switch( mode ) { case SYNC_PREF_LOCAL: if ( lastSync > remoteMod ) return 1; if ( lastSync > localMod ) return 2; return 1; break; case SYNC_PREF_REMOTE: if ( lastSync > remoteMod ) return 1; if ( lastSync > localMod ) return 2; return 2; break; case SYNC_PREF_NEWEST: if ( localMod > remoteMod ) return 1; else return 2; break; case SYNC_PREF_ASK: //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); if ( lastSync > remoteMod ) return 1; if ( lastSync > localMod ) return 2; localIsNew = localMod >= remoteMod; //qDebug("conflict! ************************************** "); { KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); result = acd.executeD(localIsNew); return result; } break; case SYNC_PREF_FORCE_LOCAL: return 1; break; case SYNC_PREF_FORCE_REMOTE: return 2; break; default: // SYNC_PREF_TAKE_BOTH not implemented break; } return 0; } + + bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) { bool syncOK = true; int addedAddressee = 0; int addedAddresseeR = 0; int deletedAddresseeR = 0; int deletedAddresseeL = 0; int changedLocal = 0; int changedRemote = 0; + + QString mCurrentSyncName = syncManager->getCurrentSyncName(); + QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); + //QPtrList<Addressee> el = local->rawAddressees(); Addressee addresseeR; QString uid; int take; Addressee addresseeL; Addressee addresseeRSync; Addressee addresseeLSync; // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); bool fullDateRange = false; local->resetTempSyncStat(); mLastAddressbookSync = QDateTime::currentDateTime(); QDateTime modifiedCalendar = mLastAddressbookSync;; addresseeLSync = getLastSyncAddressee(); qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); if ( !addresseeR.isEmpty() ) { addresseeRSync = addresseeR; remote->removeAddressee(addresseeR ); } else { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { addresseeRSync = addresseeLSync ; } else { qDebug("FULLDATE 1"); fullDateRange = true; Addressee newAdd; addresseeRSync = newAdd; addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setCategories( i18n("SyncAddressee") ); } } if ( addresseeLSync.revision() == mLastAddressbookSync ) { qDebug("FULLDATE 2"); fullDateRange = true; } if ( ! fullDateRange ) { if ( addresseeLSync.revision() != addresseeRSync.revision() ) { // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); fullDateRange = true; qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); } } // fullDateRange = true; // debug only! if ( fullDateRange ) mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); else mLastAddressbookSync = addresseeLSync.revision(); // for resyncing if own file has changed // PENDING fixme later when implemented #if 0 if ( mCurrentSyncDevice == "deleteaftersync" ) { mLastAddressbookSync = loadedFileVersion; qDebug("setting mLastAddressbookSync "); } #endif //qDebug("*************************** "); // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); QStringList er = remote->uidList(); Addressee inR ;//= er.first(); Addressee inL; QProgressBar bar( er.count(),0 ); bar.setCaption (i18n("Syncing - close to abort!") ); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); int modulo = (er.count()/10)+1; int incCounter = 0; while ( incCounter < er.count()) { if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); uid = er[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; QString idS,OidS; qApp->processEvents(); if ( !skipIncidence ) { inL = local->findByUid( uid ); inR = remote->findByUid( uid ); //inL.setResource( 0 ); //inR.setResource( 0 ); if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars @@ -2828,241 +2434,236 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); remote->removeAddressee( inR ); ++deletedAddresseeR; } } } } ++incCounter; } er.clear(); QStringList el = local->uidList(); modulo = (el.count()/10)+1; bar.setCaption (i18n("Add / remove addressees") ); bar.setTotalSteps ( el.count() ) ; bar.show(); incCounter = 0; while ( incCounter < el.count()) { qApp->processEvents(); if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); uid = el[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; if ( !skipIncidence ) { inL = local->findByUid( uid ); inR = remote->findByUid( uid ); if ( inR.isEmpty() ) { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { inL.removeID(mCurrentSyncDevice ); ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } else { if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } } } ++incCounter; } el.clear(); bar.hide(); mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); // get rid of micro seconds QTime t = mLastAddressbookSync.time(); mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); addresseeLSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); addresseeRSync.setNote( "" ) ; addresseeLSync.setNote( "" ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) remote->insertAddressee( addresseeRSync, false ); local->insertAddressee( addresseeLSync, false ); QString mes; mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); if ( KABPrefs::instance()->mShowSyncSummary ) { KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); } qDebug( mes ); return syncOK; } -bool KABCore::syncAB(QString filename, int mode) + +//this is a overwritten callbackmethods from the syncinterface +bool KABCore::sync(KSyncManager* manager, QString filename, int mode) { //pending prepare addresseeview for output //pending detect, if remote file has REV field. if not switch to external sync mGlobalSyncMode = SYNC_MODE_NORMAL; + QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); + AddressBook abLocal(filename,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; isXML = true; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); } else { Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); if ( ! lse.isEmpty() ) { if ( lse.familyName().left(4) == "!E: " ) external = true; } else { bool found = false; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { if ( (*it).revision().date().year() > 2003 ) { found = true; break; } } external = ! found; } if ( external ) { qDebug("Setting vcf mode to external "); mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { (*it).setID( mCurrentSyncDevice, (*it).uid() ); (*it).computeCsum( mCurrentSyncDevice ); } } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( KABPrefs::instance()->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); abLocal.saveAB(); if ( isXML ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; #if 0 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { getEventViewerDialog()->setSyncMode( true ); syncOK = synchronizeCalendar( mCalendar, calendar, mode ); getEventViewerDialog()->setSyncMode( false ); if ( syncOK ) { if ( KOPrefs::instance()->mWriteBackFile ) { storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); storage->save(); } } setModified(); } #endif } -void KABCore::confSync() -{ - static KSyncPrefsDialog* sp = 0; - if ( ! sp ) { - sp = new KSyncPrefsDialog( this, "syncprefs", true ); - } - sp->usrReadConfig(); -#ifndef DESKTOP_VERSION - sp->showMaximized(); -#else - sp->show(); -#endif - sp->exec(); - KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); - KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); - fillSyncMenu(); -} -void KABCore::syncSharp() -{ - if ( ! syncExternal("sharp") ) - qDebug("ERROR sync sharp ");; -} -bool KABCore::syncExternal(QString resource) + +//this is a overwritten callbackmethods from the syncinterface +bool KABCore::syncExternal(KSyncManager* manager, QString resource) { - if ( mModified ) - save(); - if ( KABPrefs::instance()->mAskForPreferences ) - edit_sync_options(); - qDebug("syncSharp() "); + QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); + AddressBook abLocal( resource,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); + qDebug("KABCore::syncExternal: why do we acces here KABPrefs and not somehow KSyncProfile? "); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, KABPrefs::instance()->mSyncAlgoPrefs ); if ( syncOK ) { if ( KABPrefs::instance()->mWriteBackFile ) { abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } -void KABCore::syncPhone() + +//called by the syncmanager to indicate that the work has to marked as dirty. +void KABCore::sync_setModified() { - if ( mModified ) - save(); - qDebug("pending syncPhone(); "); - //mView->syncPhone(); setModified(); +} +//called by the syncmanager to ask if the dirty flag is set. +bool KABCore::sync_isModified() +{ + return mModified; } + + +//called by the syncmanager to indicate that the work has to be saved. +void KABCore::sync_save() +{ + save(); +} + + + diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index e89bf41..ef61d6d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -1,166 +1,167 @@ /* This file is part of KAddressbook. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KABCORE_H #define KABCORE_H #include <kabc/field.h> #ifndef KAB_EMBEDDED #endif //KAB_EMBEDDED #include <qdict.h> #include <qwidget.h> #include <qpopupmenu.h> +#include <ksyncmanager.h> namespace KABC { class AddressBook; } #ifndef KAB_EMBEDDED class KAboutData; class KConfig; class KAddressBookService; class LDAPSearchDialog; #else //KAB_EMBEDDED class KAddressBookMain; //US class QAction; #endif //KAB_EMBEDDED class KCMultiDialog; class KXMLGUIClient; class ExtensionManager; class XXPortManager; class JumpButtonBar; class IncSearchWidget; class KDGanttMinimizeSplitter; class KAction; class KActionCollection; class KToggleAction; class KSyncProfile; class QAction; class QMenuBar; class QSplitter; class ViewContainer; class ViewManager; class AddresseeEditorDialog; class Ir; -class KABCore : public QWidget +class KABCore : public QWidget, public KSyncInterface { Q_OBJECT public: KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 ); ~KABCore(); #ifdef KAB_EMBEDDED //US added functionality QPopupMenu* getViewMenu() {return viewMenu;} QPopupMenu* getFilterMenu() {return filterMenu;} QPopupMenu* getSettingsMenu() {return settingsMenu;} void addActionsManually(); #endif //KAB_EMBEDDED /** Restores the global settings. */ void restoreSettings(); /** Saves the global settings. */ void saveSettings(); /** Returns a pointer to the StdAddressBook of the application. */ KABC::AddressBook *addressBook() const; /** Returns a pointer to the KConfig object of the application. */ static KConfig *config(); /** Returns a pointer to the global KActionCollection object. So other classes can register their actions easily. */ KActionCollection *actionCollection() const; /** Returns the current search field of the Incremental Search Widget. */ KABC::Field *currentSearchField() const; /** Returns the uid list of the currently selected contacts. */ QStringList selectedUIDs() const; /** Displays the ResourceSelectDialog and returns the selected resource or a null pointer if no resource was selected by the user. */ KABC::Resource *requestResource( QWidget *parent ); #ifndef KAB_EMBEDDED static KAboutData *createAboutData(); #endif //KAB_EMBEDDED #ifdef KAB_EMBEDDED inline QPopupMenu* getImportMenu() { return ImportMenu;} inline QPopupMenu* getExportMenu() { return ExportMenu;} #endif //KAB_EMBEDDED public slots: #ifdef KAB_EMBEDDED void createAboutData(); #endif //KAB_EMBEDDED void statusMessage(QString, int time = 0 ); void showLicence(); void faq(); /** Is called whenever a contact is selected in the view. */ void setContactSelected( const QString &uid ); /** Opens the preferred mail composer with all selected contacts as arguments. */ void sendMail(); /** Opens the preferred mail composer with the given contacts as arguments. */ void sendMail( const QString& email ); @@ -248,238 +249,233 @@ class KABCore : public QWidget Marks the address book as modified. */ void setModified(); /** Marks the address book as modified without refreshing the view. */ void setModifiedWOrefresh(); /** Marks the address book as modified concerning the argument. */ void setModified( bool modified ); /** Returns whether the address book is modified. */ bool modified() const; /** Called whenever an contact is modified in the contact editor dialog or the quick edit. */ void contactModified( const KABC::Addressee &addr ); /** DCOP METHODS. */ void addEmail( QString addr ); void importVCard( const KURL& url, bool showPreview ); void importVCard( const QString& vCard, bool showPreview ); void newContact(); QString getNameByPhone( const QString& phone ); /** END DCOP METHODS */ /** Saves the contents of the AddressBook back to disk. */ void save(); /** Undos the last command using the undo stack. */ void undo(); /** Redos the last command that was undone, using the redo stack. */ void redo(); /** Shows the edit dialog for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ void editContact( const QString &uid /*US = QString::null*/ ); //US added a second method without defaultparameter void editContact2(); /** Shows or edits the detail view for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ void executeContact( const QString &uid /*US = QString::null*/ ); /** Launches the configuration dialog. */ void openConfigDialog(); /** Launches the ldap search dialog. */ void openLDAPDialog(); /** Creates a KAddressBookPrinter, which will display the print dialog and do the printing. */ void print(); /** Registers a new GUI client, so plugins can register its actions. */ void addGUIClient( KXMLGUIClient *client ); void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); signals: void contactSelected( const QString &name ); void contactSelected( const QPixmap &pixmap ); public slots: void setDetailsVisible( bool visible ); void setDetailsToState(); - void slotSyncMenu( int ); + // void slotSyncMenu( int ); private slots: void setJumpButtonBarVisible( bool visible ); void importFromOL(); void extensionModified( const KABC::Addressee::List &list ); void extensionChanged( int id ); void clipboardDataChanged(); void updateActionMenu(); void configureKeyBindings(); void removeVoice(); #ifdef KAB_EMBEDDED void configureResources(); #endif //KAB_EMBEDDED void slotEditorDestroyed( const QString &uid ); void configurationChanged(); void addressBookChanged(); private: void initGUI(); void initActions(); AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, const char *name = 0 ); KXMLGUIClient *mGUIClient; KABC::AddressBook *mAddressBook; ViewManager *mViewManager; // QSplitter *mDetailsSplitter; KDGanttMinimizeSplitter *mExtensionBarSplitter; ViewContainer *mDetails; KDGanttMinimizeSplitter* mMiniSplitter; XXPortManager *mXXPortManager; JumpButtonBar *mJumpButtonBar; IncSearchWidget *mIncSearchWidget; ExtensionManager *mExtensionManager; KCMultiDialog *mConfigureDialog; #ifndef KAB_EMBEDDED LDAPSearchDialog *mLdapSearchDialog; #endif //KAB_EMBEDDED // QDict<AddresseeEditorDialog> mEditorDict; AddresseeEditorDialog *mEditorDialog; bool mReadWrite; bool mModified; bool mIsPart; bool mMultipleViewsAtOnce; //US file menu KAction *mActionMail; KAction *mActionBeam; KAction* mActionPrint; KAction* mActionNewContact; KAction *mActionSave; KAction *mActionEditAddressee; KAction *mActionMailVCard; KAction *mActionBeamVCard; KAction *mActionQuit; //US edit menu KAction *mActionCopy; KAction *mActionCut; KAction *mActionPaste; KAction *mActionSelectAll; KAction *mActionUndo; KAction *mActionRedo; KAction *mActionDelete; //US settings menu KAction *mActionConfigResources; KAction *mActionConfigKAddressbook; KAction *mActionConfigShortcuts; KAction *mActionConfigureToolbars; KAction *mActionKeyBindings; KToggleAction *mActionJumpBar; KToggleAction *mActionDetails; KAction *mActionWhoAmI; KAction *mActionCategories; KAction *mActionAboutKAddressbook; KAction *mActionLicence; KAction *mActionFaq; KAction *mActionDeleteView; QPopupMenu *viewMenu; QPopupMenu *filterMenu; QPopupMenu *settingsMenu; QPopupMenu *changeMenu; //US QAction *mActionSave; QPopupMenu *ImportMenu; QPopupMenu *ExportMenu; //LR additional methods KAction *mActionRemoveVoice; KAction * mActionImportOL; #ifndef KAB_EMBEDDED KAddressBookService *mAddressBookService; #endif //KAB_EMBEDDED class KABCorePrivate; KABCorePrivate *d; - bool mBlockSaveFlag; + //US bool mBlockSaveFlag; #ifdef KAB_EMBEDDED KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED + + //this are the overwritten callbackmethods from the syncinterface + virtual bool sync(KSyncManager* manager, QString filename, int mode); + virtual bool syncExternal(KSyncManager* manager, QString resource); + + //called by the syncmanager to indicate that the work has to marked as dirty. + virtual void sync_setModified(); + //called by the syncmanager to ask if the dirty flag is set. + virtual bool KABCore::sync_isModified(); + //called by the syncmanager to indicate that the work has to be saved. + virtual void sync_save(); + // LR ******************************* // sync stuff! QPopupMenu *syncMenu; - void fillSyncMenu(); - QString mCurrentSyncDevice; - QString mCurrentSyncName; - void quickSyncLocalFile(); - bool syncWithFile( QString fn , bool quick ); - void syncLocalFile(); - void syncPhone(); - void syncSharp(); - bool syncExternal(QString); - void multiSync( bool askforPrefs ); - int mCurrentSyncProfile ; - void syncRemote( KSyncProfile* prof, bool ask = true); - void edit_sync_options(); - bool syncAB(QString filename, int mode); - int ringSync(); - QString getPassword( ); + KSyncManager* syncManager; int mGlobalSyncMode; bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); KABC::Addressee getLastSyncAddressee(); QDateTime mLastAddressbookSync; int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); - public slots: - void confSync(); // ********************* }; #endif diff --git a/kaddressbook/kabprefs.h b/kaddressbook/kabprefs.h index 9926aa0..e4f359c 100644 --- a/kaddressbook/kabprefs.h +++ b/kaddressbook/kabprefs.h @@ -1,108 +1,92 @@ /* This file is part of KAddressBook. Copyright (c) 2002 Mike Pilone <mpilone@slac.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KABPREFS_H #define KABPREFS_H #include <qstringlist.h> #include <libkdepim/kpimprefs.h> class KConfig; class KABPrefs : public KPimPrefs { public: virtual ~KABPrefs(); static KABPrefs *instance(); // General bool mHonorSingleClick; bool mAutomaticNameParsing; int mCurrentIncSearchField; #ifdef KAB_EMBEDDED // US introduce a nonconst way to return the config object. KConfig* getConfig(); bool mToolBarHor; bool mToolBarUp; bool mAskForQuit; /** Set preferences to default values */ // void usrSetDefaults(); /** Read preferences from config file */ // void usrReadConfig(); /** Write preferences to config file */ // void usrWriteConfig(); #endif //KAB_EMBEDDED // GUI bool mJumpButtonBarVisible; bool mDetailsPageVisible; bool mMultipleViewsAtOnce; bool mSearchWithReturn; QValueList<int> mExtensionsSplitter; QValueList<int> mDetailsSplitter; // Extensions stuff int mCurrentExtension; QStringList mActiveExtensions; // Views stuff QString mCurrentView; QStringList mViewNames; // Filter int mCurrentFilter; void setCategoryDefaults(); - // sync stuff - QString mLocalMachineName; - QStringList mExternSyncProfiles; - QStringList mSyncProfileNames; - bool mAskForPreferences; - bool mShowSyncSummary; - bool mShowSyncEvents; - bool mShowTodoInAgenda; - bool mWriteBackExistingOnly; - int mSyncAlgoPrefs; - int mRingSyncAlgoPrefs; - bool mWriteBackFile; - int mWriteBackInFuture; - QString mPhoneDevice; - QString mPhoneConnection; - QString mPhoneModel; - QString mLastSyncedLocalFile; // save! + private: KABPrefs(); static KABPrefs *sInstance; }; #endif diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h index 860665b..01c57a3 100644 --- a/libkdepim/kpimprefs.h +++ b/libkdepim/kpimprefs.h @@ -1,64 +1,85 @@ /* This file is part of libkdepim. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KPIMPREFS_H #define KPIMPREFS_H #include <qstringlist.h> #include "kprefs.h" class KPimPrefs : public KPrefs { public: KPimPrefs( const QString &name = QString::null ); virtual ~KPimPrefs(); /** Set preferences to default values */ void usrSetDefaults(); /** Read preferences from config file */ void usrReadConfig(); /** Write preferences to config file */ void usrWriteConfig(); public: QStringList mCustomCategories; + // sync stuff + QString mLocalMachineName; + QStringList mExternSyncProfiles; + QStringList mSyncProfileNames; + bool mAskForPreferences; + bool mShowSyncSummary; + bool mShowSyncEvents; + bool mShowTodoInAgenda; + bool mWriteBackExistingOnly; + int mSyncAlgoPrefs; + int mRingSyncAlgoPrefs; + bool mWriteBackFile; + int mWriteBackInFuture; + QString mPhoneDevice; + QString mPhoneConnection; + QString mPhoneModel; + QString mLastSyncedLocalFile; // save! + protected: virtual void setCategoryDefaults(); + + + }; #endif diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 52e3bd9..87f200a 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -1,455 +1,529 @@ /* This file is part of KDE-Pim/Pi. Copyright (c) 2004 Ulf Schenk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #include "ksyncmanager.h" +#include <stdlib.h> -KSyncManager::KSyncManager(TargetApp ta, QPopupMenu* syncmenu) - : mSyncMenu(syncmenu), mTargetApp(ta) +#ifndef _WIN32_ +#include <unistd.h> +#endif + + +#include "ksyncprofile.h" +#include "ksyncprefsdialog.h" +#include "kpimprefs.h" + +#include <qdir.h> +#include <qpopupmenu.h> +#include <qpushbutton.h> +#include <qradiobutton.h> +#include <qbuttongroup.h> +#include <qtimer.h> +#include <qmessagebox.h> +#include <qapplication.h> +#include <qlineedit.h> +#include <qdialog.h> +#include <qlayout.h> + +#include <klocale.h> +#include <kglobal.h> +#include <kconfig.h> +#include <kfiledialog.h> + +KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) + : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu) { } KSyncManager::~KSyncManager() { } -void KABCore::fillSyncMenu() +void KSyncManager::fillSyncMenu() { if ( mSyncMenu->count() ) - msyncMenu->clear(); + mSyncMenu->clear(); mSyncMenu->insertItem( i18n("Configure..."), 0 ); mSyncMenu->insertSeparator(); mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); mSyncMenu->insertSeparator(); KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); config.setGroup("General"); QStringList prof = config.readListEntry("SyncProfileNames"); - //US KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); + mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); if ( prof.count() < 3 ) { prof.clear(); prof << i18n("Sharp_DTM"); prof << i18n("Local_file"); prof << i18n("Last_file"); KSyncProfile* temp = new KSyncProfile (); temp->setName( prof[0] ); temp->writeConfig(&config); temp->setName( prof[1] ); temp->writeConfig(&config); temp->setName( prof[2] ); temp->writeConfig(&config); config.setGroup("General"); config.writeEntry("SyncProfileNames",prof); config.writeEntry("ExternSyncProfiles","Sharp_DTM"); config.sync(); delete temp; } - /*US - KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); - KABPrefs::instance()->mSyncProfileNames = prof; - */ - int i; + mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); + mPrefs->mSyncProfileNames = prof; + unsigned int i; for ( i = 0; i < prof.count(); ++i ) { mSyncMenu->insertItem( prof[i], 1000+i ); if ( i == 2 ) mSyncMenu->insertSeparator(); } QDir app_dir; if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { mSyncMenu->setItemEnabled( false , 1000 ); } //probaly useless //mView->setupExternSyncProfiles(); } -void KABCore::slotSyncMenu( int action ) + +void KSyncManager::slotSyncMenu( int action ) { //qDebug("syncaction %d ", action); if ( action == 0 ) { // seems to be a Qt2 event handling bug // syncmenu.clear causes a segfault at first time // when we call it after the main event loop, it is ok // same behaviour when calling OM/Pi via QCOP for the first time QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); //confSync(); return; } if ( action == 1 ) { multiSync( true ); return; } - if (mBlockSaveFlag) + if (blockSave()) return; - mBlockSaveFlag = true; + + setBlockSave(true); + mCurrentSyncProfile = action - 1000 ; - //US mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; - //US mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; + mCurrentSyncDevice = mPrefs->mSyncProfileNames[mCurrentSyncProfile] ; + mCurrentSyncName = mPrefs->mLocalMachineName ; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); KSyncProfile* temp = new KSyncProfile (); - //US temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); + temp->setName(mPrefs->mSyncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); - /*US - KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); - KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); - KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); - KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); - KABPrefs::instance()->mWriteBackInFuture = 0; + mPrefs->mAskForPreferences = temp->getAskForPreferences(); + mPrefs->mSyncAlgoPrefs = temp->getSyncPrefs(); + mPrefs->mWriteBackFile = temp->getWriteBackFile(); + mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); + mPrefs->mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) - KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); - KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); - */ + mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); + mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync(); if ( action == 1000 ) { syncSharp(); } else if ( action == 1001 ) { syncLocalFile(); } else if ( action == 1002 ) { quickSyncLocalFile(); } else if ( action >= 1003 ) { if ( temp->getIsLocalFileSync() ) { - /*US if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); - */ + if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); + } else { if ( temp->getIsPhoneSync() ) { - /* - KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; - KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); - KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); - */ + mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; + mPrefs->mPhoneConnection = temp->getPhoneConnection( ); + mPrefs->mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp ); } } delete temp; - mBlockSaveFlag = false; + setBlockSave(false); } -void KABCore::syncLocalFile() +void KSyncManager::syncLocalFile() { - QString fn =KABPrefs::instance()->mLastSyncedLocalFile; + QString fn =mPrefs->mLastSyncedLocalFile; - fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); + fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), mParent ); if ( fn == "" ) return; if ( syncWithFile( fn, false ) ) { qDebug("syncLocalFile() successful "); } } -bool KABCore::syncWithFile( QString fn , bool quick ) +bool KSyncManager::syncWithFile( QString fn , bool quick ) { bool ret = false; QFileInfo info; info.setFile( fn ); QString mess; bool loadbup = true; if ( !info. exists() ) { mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); - int result = QMessageBox::warning( this, i18n("Warning!"), + int result = QMessageBox::warning( mParent, i18n("Warning!"), mess ); return ret; } int result = 0; if ( !quick ) { mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); - result = QMessageBox::warning( this, i18n("Warning!"), + result = QMessageBox::warning( mParent, i18n("Warning!"), mess, i18n("Sync"), i18n("Cancel"), 0, 0, 1 ); if ( result ) return false; } - if ( KABPrefs::instance()->mAskForPreferences ) + if ( mPrefs->mAskForPreferences ) edit_sync_options(); if ( result == 0 ) { //qDebug("Now sycing ... "); - if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) - setCaption( i18n("Synchronization successful") ); + if ( ret = mImplementation->sync( this, fn, mPrefs->mSyncAlgoPrefs ) ) + mParent->setCaption( i18n("Synchronization successful") ); else - setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); + mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); if ( ! quick ) - KABPrefs::instance()->mLastSyncedLocalFile = fn; - setModified(); + mPrefs->mLastSyncedLocalFile = fn; + mImplementation->sync_setModified(); } return ret; } -void KABCore::quickSyncLocalFile() +void KSyncManager::quickSyncLocalFile() { - if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { + if ( syncWithFile( mPrefs->mLastSyncedLocalFile, false ) ) { qDebug("quick syncLocalFile() successful "); } } -void KABCore::multiSync( bool askforPrefs ) +void KSyncManager::multiSync( bool askforPrefs ) { - if (mBlockSaveFlag) + if (blockSave()) return; - mBlockSaveFlag = true; + setBlockSave(true); QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); - if ( QMessageBox::information( this, i18n("KO/Pi Sync"), + if ( QMessageBox::information( mParent, i18n("Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) { - mBlockSaveFlag = false; - setCaption(i18n("Aborted! Nothing synced!")); + setBlockSave(false); + mParent->setCaption(i18n("Aborted! Nothing synced!")); return; } mCurrentSyncDevice = i18n("Multiple profiles") ; - KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; + mPrefs->mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; if ( askforPrefs ) { edit_sync_options(); - KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; + mPrefs->mRingSyncAlgoPrefs = mPrefs->mSyncAlgoPrefs; } - setCaption(i18n("Multiple sync started.") ); + mParent->setCaption(i18n("Multiple sync started.") ); qApp->processEvents(); int num = ringSync() ; if ( num > 1 ) ringSync(); - mBlockSaveFlag = false; + setBlockSave(false); if ( num ) - save(); + mImplementation->sync_save(); if ( num ) - setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); + mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); else - setCaption(i18n("Nothing synced! No profiles defined for multisync!")); + mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); return; } -int KABCore::ringSync() +int KSyncManager::ringSync() { int syncedProfiles = 0; - int i; + unsigned int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; + QStringList syncProfileNames = mPrefs->mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); - KABPrefs::instance()->mAskForPreferences = false; + mPrefs->mAskForPreferences = false; for ( i = 0; i < syncProfileNames.count(); ++i ) { mCurrentSyncProfile = i; temp->setName(syncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { - setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); + mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); ++syncedProfiles; - // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); - KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); - KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); - KABPrefs::instance()->mWriteBackInFuture = 0; + // mPrefs->mAskForPreferences = temp->getAskForPreferences(); + mPrefs->mWriteBackFile = temp->getWriteBackFile(); + mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); + mPrefs->mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) - KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); - KABPrefs::instance()->mShowSyncSummary = false; + mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); + mPrefs->mShowSyncSummary = false; mCurrentSyncDevice = syncProfileNames[i] ; - mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; + mCurrentSyncName = mPrefs->mLocalMachineName; if ( i == 0 ) { syncSharp(); } else { if ( temp->getIsLocalFileSync() ) { if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); + mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); } else { if ( temp->getIsPhoneSync() ) { - KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; - KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); - KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); + mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; + mPrefs->mPhoneConnection = temp->getPhoneConnection( ); + mPrefs->mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp, false ); } } timer.start(); - setCaption(i18n("Multiple sync in progress ... please wait!") ); + mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); while ( timer.elapsed () < 2000 ) { qApp->processEvents(); #ifndef _WIN32_ sleep (1); #endif } } } delete temp; return syncedProfiles; } -void KABCore::syncRemote( KSyncProfile* prof, bool ask) +void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) { QString question; if ( ask ) { question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; - if ( QMessageBox::information( this, i18n("KO/Pi Sync"), + if ( QMessageBox::information( mParent, i18n("Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) return; } QString command = prof->getPreSyncCommandAB(); int fi; if ( (fi = command.find("$PWD$")) > 0 ) { QString pwd = getPassword(); command = command.left( fi )+ pwd + command.mid( fi+5 ); } int maxlen = 30; if ( QApplication::desktop()->width() > 320 ) maxlen += 25; - setCaption ( i18n( "Copy remote file to local machine..." ) ); + mParent->setCaption ( i18n( "Copy remote file to local machine..." ) ); int fileSize = 0; int result = system ( command ); // 0 : okay // 256: no such file or dir // qDebug("KO: Remote copy result(0 = okay): %d ",result ); if ( result != 0 ) { - int len = maxlen; + unsigned int len = maxlen; while ( len < command.length() ) { command.insert( len , "\n" ); len += maxlen +2; } question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; - QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), + QMessageBox::information( mParent, i18n("Sync - ERROR"), question, i18n("Okay!")) ; - setCaption ("KO/Pi"); + mParent->setCaption (""); return; } - setCaption ( i18n( "Copying succeed." ) ); + mParent->setCaption ( i18n( "Copying succeed." ) ); //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { // Event* e = mView->getLastSyncEvent(); // e->setReadOnly( false ); // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); // e->setReadOnly( true ); - if ( KABPrefs::instance()->mWriteBackFile ) { + if ( mPrefs->mWriteBackFile ) { command = prof->getPostSyncCommandAB(); int fi; if ( (fi = command.find("$PWD$")) > 0 ) { QString pwd = getPassword(); command = command.left( fi )+ pwd + command.mid( fi+5 ); } - setCaption ( i18n( "Writing back file ..." ) ); + mParent->setCaption ( i18n( "Writing back file ..." ) ); result = system ( command ); - qDebug("KO: Writing back file result: %d ", result); + qDebug("Writing back file result: %d ", result); if ( result != 0 ) { - setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); + mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); return; } else { - setCaption ( i18n( "Syncronization sucessfully completed" ) ); + mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) ); } } } return; } -#include <qpushbutton.h> -#include <qradiobutton.h> -#include <qbuttongroup.h> -void KABCore::edit_sync_options() + +void KSyncManager::edit_sync_options() { //mDialogManager->showSyncOptions(); - //KABPrefs::instance()->mSyncAlgoPrefs - QDialog dia( this, "dia", true ); + //mPrefs->mSyncAlgoPrefs + QDialog dia( mParent, "dia", true ); dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); QVBoxLayout lay ( &dia ); lay.setSpacing( 2 ); lay.setMargin( 3 ); lay.addWidget(&gr); QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); //QRadioButton both( i18n("Take both on conflict"), &gr ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); - switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { + switch ( mPrefs->mSyncAlgoPrefs ) { case 0: loc.setChecked( true); break; case 1: rem.setChecked( true ); break; case 2: newest.setChecked( true); break; case 3: ask.setChecked( true); break; case 4: f_loc.setChecked( true); break; case 5: f_rem.setChecked( true); break; case 6: // both.setChecked( true); break; default: break; } if ( dia.exec() ) { - KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; + mPrefs->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; } } -QString KABCore::getPassword( ) +QString KSyncManager::getPassword( ) { QString retfile = ""; - QDialog dia ( this, "input-dialog", true ); + QDialog dia ( mParent, "input-dialog", true ); QLineEdit lab ( &dia ); lab.setEchoMode( QLineEdit::Password ); QVBoxLayout lay( &dia ); lay.setMargin(7); lay.setSpacing(7); lay.addWidget( &lab); dia.setFixedSize( 230,50 ); dia.setCaption( i18n("Enter password") ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.show(); int res = dia.exec(); if ( res ) retfile = lab.text(); dia.hide(); qApp->processEvents(); return retfile; } + + +void KSyncManager::confSync() +{ + static KSyncPrefsDialog* sp = 0; + if ( ! sp ) { + sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); + } + sp->usrReadConfig(); +#ifndef DESKTOP_VERSION + sp->showMaximized(); +#else + sp->show(); +#endif + sp->exec(); + mPrefs->mSyncProfileNames = sp->getSyncProfileNames(); + mPrefs->mLocalMachineName = sp->getLocalMachineName (); + fillSyncMenu(); +} + +void KSyncManager::syncSharp() +{ + if ( ! syncExternalApplication("sharp") ) + qDebug("ERROR sync sharp ");; +} + +bool KSyncManager::syncExternalApplication(QString resource) +{ + if ( mImplementation->sync_isModified() ) + mImplementation->sync_save(); + + if ( mPrefs->mAskForPreferences ) + edit_sync_options(); + + qDebug("sync %s", resource.latin1()); + + bool syncOK = mImplementation->syncExternal(this, resource); + + return syncOK; + +} + +void KSyncManager::syncPhone() +{ + if ( mImplementation->sync_isModified() ) + mImplementation->sync_save(); + + qDebug("pending syncPhone(); "); + //mView->syncPhone(); + mImplementation->sync_setModified(); + +} diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index d7c2a02..389a005 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -1,68 +1,119 @@ /* This file is part of KDE-Pim/Pi. Copyright (c) 2004 Ulf Schenk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id$ */ #ifndef _KSYNCMANAGER_H #define _KSYNCMANAGER_H +#include <qobject.h> #include <qstring.h> class QPopupMenu; class KSyncProfile; +class KPimPrefs; +class QWidget; +class KSyncManager; +class KSyncInterface; - - -class KSyncManager +class KSyncManager : public QObject { + Q_OBJECT public: - KSyncManager(TargetApp ta, QPopupMenu* syncmenu); - ~KSyncManager() ; - enum TargetApp { KOPI = 0, KAPI = 1, PWMPI = 2 }; - private: + + KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); + ~KSyncManager() ; + + bool blockSave() { return mBlockSaveFlag; } + void setBlockSave(bool sa) { mBlockSaveFlag = sa; } + void fillSyncMenu(); - void syncLocalFile(); - bool syncWithFile( QString fn , bool quick ); + + QString getCurrentSyncDevice() { return mCurrentSyncDevice; } + QString getCurrentSyncName() { return mCurrentSyncName; } + + public slots: + void slotSyncMenu( int ); + + private: + // LR ******************************* + // sync stuff! + QString mCurrentSyncDevice; + QString mCurrentSyncName; void quickSyncLocalFile(); + bool syncWithFile( QString fn , bool quick ); + void syncLocalFile(); + void syncPhone(); + void syncSharp(); + bool syncExternalApplication(QString); void multiSync( bool askforPrefs ); - int ringSync(); - void syncRemote( KSyncProfile* prof, bool ask); + int mCurrentSyncProfile ; + void syncRemote( KSyncProfile* prof, bool ask = true); void edit_sync_options(); + int ringSync(); QString getPassword(); + private slots: + void confSync(); + // ********************* + private: - QPopupMenu* mSyncMenu; + bool mBlockSaveFlag; + + + QWidget* mParent; + KSyncInterface* mImplementation; TargetApp mTargetApp; + KPimPrefs* mPrefs; + QPopupMenu* mSyncMenu; + +}; + + +class KSyncInterface +{ + public: + virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; + virtual bool syncExternal(KSyncManager* manager, QString resource) = 0; + + //called by the syncmanager to indicate that the work has to be marked as dirty. + virtual void sync_setModified() = 0; + //called by the syncmanager to ask if the dirty flag is set. + virtual bool sync_isModified() = 0; + + //called by the syncmanager to indicate that the work has to be saved. + virtual void sync_save() = 0; }; + #endif diff --git a/libkdepim/libkdepimE.pro b/libkdepim/libkdepimE.pro index 2a30ee8..156e247 100644 --- a/libkdepim/libkdepimE.pro +++ b/libkdepim/libkdepimE.pro @@ -1,53 +1,55 @@ TEMPLATE = lib CONFIG += qt warn_on TARGET = microkdepim INCLUDEPATH += . $(KDEPIMDIR) $(KDEPIMDIR)/microkde $(KDEPIMDIR)/qtcompat $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kdeui $(QPEDIR)/include LIBS += -lmicrokde #LIBS += -lmicrokcal LIBS += -L$(QPEDIR)/lib OBJECTS_DIR = obj/$(PLATFORM) MOC_DIR = moc/$(PLATFORM) DESTDIR=$(QPEDIR)/lib INTERFACES = \ HEADERS = \ categoryeditdialog.h \ categoryeditdialog_base.h \ categoryselectdialog.h \ categoryselectdialog_base.h \ externalapphandler.h \ kdateedit.h \ kdatepicker.h \ kinputdialog.h \ kpimprefs.h \ kpimglobalprefs.h \ kprefsdialog.h \ kprefswidget.h \ + ksyncmanager.h \ ksyncprofile.h \ ksyncprefsdialog.h \ kcmconfigs/kcmkdepimconfig.h \ kcmconfigs/kdepimconfigwidget.h SOURCES = \ categoryeditdialog.cpp \ categoryeditdialog_base.cpp \ categoryselectdialog.cpp \ categoryselectdialog_base.cpp \ externalapphandler.cpp \ kdateedit.cpp \ kinputdialog.cpp \ kdatepicker.cpp \ kpimprefs.cpp \ kpimglobalprefs.cpp \ kprefsdialog.cpp \ kprefswidget.cpp \ + ksyncmanager.cpp \ ksyncprofile.cpp \ ksyncprefsdialog.cpp \ kcmconfigs/kcmkdepimconfig.cpp \ kcmconfigs/kdepimconfigwidget.cpp |