summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp460
-rw-r--r--kaddressbook/kabcore.h24
-rw-r--r--kaddressbook/kabprefs.h18
3 files changed, 496 insertions, 6 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 32dd43a..49c3b19 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -23,24 +23,25 @@
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include "kabcore.h" 31#include "kabcore.h"
32 32
33#include <stdaddressbook.h> 33#include <stdaddressbook.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kfiledialog.h>
35 36
36#ifndef KAB_EMBEDDED 37#ifndef KAB_EMBEDDED
37#include <qclipboard.h> 38#include <qclipboard.h>
38#include <qdir.h> 39#include <qdir.h>
39#include <qfile.h> 40#include <qfile.h>
40#include <qapplicaton.h> 41#include <qapplicaton.h>
41#include <qlayout.h> 42#include <qlayout.h>
42#include <qregexp.h> 43#include <qregexp.h>
43#include <qvbox.h> 44#include <qvbox.h>
44#include <kabc/addresseelist.h> 45#include <kabc/addresseelist.h>
45#include <kabc/errorhandler.h> 46#include <kabc/errorhandler.h>
46#include <kabc/resource.h> 47#include <kabc/resource.h>
@@ -133,41 +134,47 @@ $Id$
133#include "details/detailsviewcontainer.h" 134#include "details/detailsviewcontainer.h"
134#include "kabprefs.h" 135#include "kabprefs.h"
135#include "xxportmanager.h" 136#include "xxportmanager.h"
136#include "incsearchwidget.h" 137#include "incsearchwidget.h"
137#include "jumpbuttonbar.h" 138#include "jumpbuttonbar.h"
138#include "extensionmanager.h" 139#include "extensionmanager.h"
139#include "addresseeconfig.h" 140#include "addresseeconfig.h"
140#include <kcmultidialog.h> 141#include <kcmultidialog.h>
141 142
142#ifdef _WIN32_ 143#ifdef _WIN32_
143 144
144#include "kaimportoldialog.h" 145#include "kaimportoldialog.h"
146#else
147#include <unistd.h>
145#endif 148#endif
149// sync includes
150#include <libkdepim/ksyncprofile.h>
151
146 152
147bool pasteWithNewUid = true; 153bool pasteWithNewUid = true;
148 154
149#ifdef KAB_EMBEDDED 155#ifdef KAB_EMBEDDED
150KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 156KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
151 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 157 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
152 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 158 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
153 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 159 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
154#else //KAB_EMBEDDED 160#else //KAB_EMBEDDED
155KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 161KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
156 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 162 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
157 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 163 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
158 mReadWrite( readWrite ), mModified( false ) 164 mReadWrite( readWrite ), mModified( false )
159#endif //KAB_EMBEDDED 165#endif //KAB_EMBEDDED
160{ 166{
161 167
168 mBlockSaveFlag = false;
162 mExtensionBarSplitter = 0; 169 mExtensionBarSplitter = 0;
163 mIsPart = !parent->inherits( "KAddressBookMain" ); 170 mIsPart = !parent->inherits( "KAddressBookMain" );
164 171
165 mAddressBook = KABC::StdAddressBook::self(); 172 mAddressBook = KABC::StdAddressBook::self();
166 KABC::StdAddressBook::setAutomaticSave( false ); 173 KABC::StdAddressBook::setAutomaticSave( false );
167 174
168#ifndef KAB_EMBEDDED 175#ifndef KAB_EMBEDDED
169 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 176 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
170#endif //KAB_EMBEDDED 177#endif //KAB_EMBEDDED
171 178
172 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 179 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
173 SLOT( addressBookChanged() ) ); 180 SLOT( addressBookChanged() ) );
@@ -1052,44 +1059,48 @@ void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1052 editContact( uid ); 1059 editContact( uid );
1053 } 1060 }
1054 else 1061 else
1055 { 1062 {
1056 setDetailsVisible( true ); 1063 setDetailsVisible( true );
1057 mActionDetails->setChecked(true); 1064 mActionDetails->setChecked(true);
1058 } 1065 }
1059 1066
1060} 1067}
1061 1068
1062void KABCore::save() 1069void KABCore::save()
1063{ 1070{
1071 if (mBlockSaveFlag)
1072 return;
1073 mBlockSaveFlag = true;
1064 if ( !mModified ) 1074 if ( !mModified )
1065 return; 1075 return;
1066 QString text = i18n( "There was an error while attempting to save\n the " 1076 QString text = i18n( "There was an error while attempting to save\n the "
1067 "address book. Please check that some \nother application is " 1077 "address book. Please check that some \nother application is "
1068 "not using it. " ); 1078 "not using it. " );
1069 statusMessage(i18n("Saving addressbook ... ")); 1079 statusMessage(i18n("Saving addressbook ... "));
1070#ifndef KAB_EMBEDDED 1080#ifndef KAB_EMBEDDED
1071 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1081 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1072 if ( !b || !b->save() ) { 1082 if ( !b || !b->save() ) {
1073 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1083 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1074 } 1084 }
1075#else //KAB_EMBEDDED 1085#else //KAB_EMBEDDED
1076 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1086 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1077 if ( !b || !b->save() ) { 1087 if ( !b || !b->save() ) {
1078 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1088 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1079 } 1089 }
1080#endif //KAB_EMBEDDED 1090#endif //KAB_EMBEDDED
1081 1091
1082 statusMessage(i18n("Addressbook saved!")); 1092 statusMessage(i18n("Addressbook saved!"));
1083 setModified( false ); 1093 setModified( false );
1094 mBlockSaveFlag = false;
1084} 1095}
1085 1096
1086void KABCore::statusMessage(QString mess , int time ) 1097void KABCore::statusMessage(QString mess , int time )
1087{ 1098{
1088 //topLevelWidget()->setCaption( mess ); 1099 //topLevelWidget()->setCaption( mess );
1089 // pending setting timer to revome message 1100 // pending setting timer to revome message
1090} 1101}
1091void KABCore::undo() 1102void KABCore::undo()
1092{ 1103{
1093 UndoStack::instance()->undo(); 1104 UndoStack::instance()->undo();
1094 1105
1095 // Refresh the view 1106 // Refresh the view
@@ -1427,25 +1438,25 @@ void KABCore::initGUI()
1427 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1438 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1428 1439
1429 mXXPortManager = new XXPortManager( this, this ); 1440 mXXPortManager = new XXPortManager( this, this );
1430 1441
1431#else //KAB_EMBEDDED 1442#else //KAB_EMBEDDED
1432 //US initialize viewMenu before settingup viewmanager. 1443 //US initialize viewMenu before settingup viewmanager.
1433 // Viewmanager needs this menu to plugin submenues. 1444 // Viewmanager needs this menu to plugin submenues.
1434 viewMenu = new QPopupMenu( this ); 1445 viewMenu = new QPopupMenu( this );
1435 settingsMenu = new QPopupMenu( this ); 1446 settingsMenu = new QPopupMenu( this );
1436 //filterMenu = new QPopupMenu( this ); 1447 //filterMenu = new QPopupMenu( this );
1437 ImportMenu = new QPopupMenu( this ); 1448 ImportMenu = new QPopupMenu( this );
1438 ExportMenu = new QPopupMenu( this ); 1449 ExportMenu = new QPopupMenu( this );
1439 1450 syncMenu = new QPopupMenu( this );
1440 changeMenu= new QPopupMenu( this ); 1451 changeMenu= new QPopupMenu( this );
1441 1452
1442//US since we have no splitter for the embedded system, setup 1453//US since we have no splitter for the embedded system, setup
1443// a layout with two frames. One left and one right. 1454// a layout with two frames. One left and one right.
1444 1455
1445 QBoxLayout *topLayout; 1456 QBoxLayout *topLayout;
1446 1457
1447 // = new QHBoxLayout( this ); 1458 // = new QHBoxLayout( this );
1448// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1459// QBoxLayout *topLayout = (QBoxLayout*)layout();
1449 1460
1450// QWidget *mainBox = new QWidget( this ); 1461// QWidget *mainBox = new QWidget( this );
1451// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1462// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
@@ -1745,42 +1756,44 @@ void KABCore::addActionsManually()
1745 1756
1746 KToolBar* tb = mMainWindow->toolBar(); 1757 KToolBar* tb = mMainWindow->toolBar();
1747 1758
1748#ifdef DESKTOP_VERSION 1759#ifdef DESKTOP_VERSION
1749 QMenuBar* mb = mMainWindow->menuBar(); 1760 QMenuBar* mb = mMainWindow->menuBar();
1750 1761
1751 //US setup menubar. 1762 //US setup menubar.
1752 //Disable the following block if you do not want to have a menubar. 1763 //Disable the following block if you do not want to have a menubar.
1753 mb->insertItem( "&File", fileMenu ); 1764 mb->insertItem( "&File", fileMenu );
1754 mb->insertItem( "&Edit", editMenu ); 1765 mb->insertItem( "&Edit", editMenu );
1755 mb->insertItem( "&View", viewMenu ); 1766 mb->insertItem( "&View", viewMenu );
1756 mb->insertItem( "&Settings", settingsMenu ); 1767 mb->insertItem( "&Settings", settingsMenu );
1768 mb->insertItem( i18n("Synchronize"), syncMenu );
1757 mb->insertItem( "&Change selected", changeMenu ); 1769 mb->insertItem( "&Change selected", changeMenu );
1758 mb->insertItem( "&Help", helpMenu ); 1770 mb->insertItem( "&Help", helpMenu );
1759 mIncSearchWidget = new IncSearchWidget( tb ); 1771 mIncSearchWidget = new IncSearchWidget( tb );
1760 // tb->insertWidget(-1, 0, mIncSearchWidget); 1772 // tb->insertWidget(-1, 0, mIncSearchWidget);
1761 1773
1762#else 1774#else
1763 //US setup toolbar 1775 //US setup toolbar
1764 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1776 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1765 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1777 QPopupMenu *popupBarTB = new QPopupMenu( this );
1766 menuBarTB->insertItem( "ME", popupBarTB); 1778 menuBarTB->insertItem( "ME", popupBarTB);
1767 tb->insertWidget(-1, 0, menuBarTB); 1779 tb->insertWidget(-1, 0, menuBarTB);
1768 mIncSearchWidget = new IncSearchWidget( tb ); 1780 mIncSearchWidget = new IncSearchWidget( tb );
1769 1781
1770 tb->enableMoving(false); 1782 tb->enableMoving(false);
1771 popupBarTB->insertItem( "&File", fileMenu ); 1783 popupBarTB->insertItem( "&File", fileMenu );
1772 popupBarTB->insertItem( "&Edit", editMenu ); 1784 popupBarTB->insertItem( "&Edit", editMenu );
1773 popupBarTB->insertItem( "&View", viewMenu ); 1785 popupBarTB->insertItem( "&View", viewMenu );
1774 popupBarTB->insertItem( "&Settings", settingsMenu ); 1786 popupBarTB->insertItem( "&Settings", settingsMenu );
1787 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1775 mViewManager->getFilterAction()->plug ( popupBarTB); 1788 mViewManager->getFilterAction()->plug ( popupBarTB);
1776 popupBarTB->insertItem( "&Change selected", changeMenu ); 1789 popupBarTB->insertItem( "&Change selected", changeMenu );
1777 popupBarTB->insertItem( "&Help", helpMenu ); 1790 popupBarTB->insertItem( "&Help", helpMenu );
1778 if (QApplication::desktop()->width() > 320 ) { 1791 if (QApplication::desktop()->width() > 320 ) {
1779 // mViewManager->getFilterAction()->plug ( tb); 1792 // mViewManager->getFilterAction()->plug ( tb);
1780 } 1793 }
1781#endif 1794#endif
1782 // mActionQuit->plug ( mMainWindow->toolBar()); 1795 // mActionQuit->plug ( mMainWindow->toolBar());
1783 1796
1784 1797
1785 1798
1786 //US Now connect the actions with the menue entries. 1799 //US Now connect the actions with the menue entries.
@@ -1874,24 +1887,28 @@ void KABCore::addActionsManually()
1874/*US 1887/*US
1875 mIncSearchWidget = new IncSearchWidget( tb ); 1888 mIncSearchWidget = new IncSearchWidget( tb );
1876 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1889 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1877 SLOT( incrementalSearch( const QString& ) ) ); 1890 SLOT( incrementalSearch( const QString& ) ) );
1878 1891
1879 mJumpButtonBar = new JumpButtonBar( this, this ); 1892 mJumpButtonBar = new JumpButtonBar( this, this );
1880 1893
1881//US topLayout->addWidget( mJumpButtonBar ); 1894//US topLayout->addWidget( mJumpButtonBar );
1882 this->layout()->add( mJumpButtonBar ); 1895 this->layout()->add( mJumpButtonBar );
1883*/ 1896*/
1884 1897
1885#endif //KAB_EMBEDDED 1898#endif //KAB_EMBEDDED
1899
1900 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) );
1901 fillSyncMenu();
1902
1886} 1903}
1887void KABCore::showLicence() 1904void KABCore::showLicence()
1888{ 1905{
1889 KApplication::showLicence(); 1906 KApplication::showLicence();
1890} 1907}
1891void KABCore::removeVoice() 1908void KABCore::removeVoice()
1892{ 1909{
1893 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 ) 1910 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 )
1894 return; 1911 return;
1895 KABC::Addressee::List list = mViewManager->selectedAddressees(); 1912 KABC::Addressee::List list = mViewManager->selectedAddressees();
1896 KABC::Addressee::List::Iterator it; 1913 KABC::Addressee::List::Iterator it;
1897 for ( it = list.begin(); it != list.end(); ++it ) { 1914 for ( it = list.begin(); it != list.end(); ++it ) {
@@ -2075,17 +2092,452 @@ void KABCore::requestForDetails(const QString& sourceChannel, const QString& ses
2075 mActionDetails->setChecked(true); 2092 mActionDetails->setChecked(true);
2076 } 2093 }
2077 } 2094 }
2078} 2095}
2079 2096
2080 2097
2081void KABCore::faq() 2098void KABCore::faq()
2082{ 2099{
2083 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2100 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2084} 2101}
2085 2102
2086 2103
2104void KABCore::fillSyncMenu()
2105{
2106 if ( syncMenu->count() )
2107 syncMenu->clear();
2108 syncMenu->insertItem( i18n("Configure..."), 0 );
2109 syncMenu->insertSeparator();
2110 syncMenu->insertItem( i18n("Multiple sync"), 1 );
2111 syncMenu->insertSeparator();
2112 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2113 config.setGroup("General");
2114 QStringList prof = config.readListEntry("SyncProfileNames");
2115 KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
2116 if ( prof.count() < 3 ) {
2117 prof.clear();
2118 prof << i18n("Sharp_DTM");
2119 prof << i18n("Local_file");
2120 prof << i18n("Last_file");
2121 KSyncProfile* temp = new KSyncProfile ();
2122 temp->setName( prof[0] );
2123 temp->writeConfig(&config);
2124 temp->setName( prof[1] );
2125 temp->writeConfig(&config);
2126 temp->setName( prof[2] );
2127 temp->writeConfig(&config);
2128 config.setGroup("General");
2129 config.writeEntry("SyncProfileNames",prof);
2130 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
2131 config.sync();
2132 delete temp;
2133 }
2134 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
2135 KABPrefs::instance()->mSyncProfileNames = prof;
2136 int i;
2137 for ( i = 0; i < prof.count(); ++i ) {
2138
2139 syncMenu->insertItem( prof[i], 1000+i );
2140 if ( i == 2 )
2141 syncMenu->insertSeparator();
2142 }
2143 QDir app_dir;
2144 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
2145 syncMenu->setItemEnabled( false , 1000 );
2146 }
2147 //probaly useless
2148 //mView->setupExternSyncProfiles();
2149}
2150void KABCore::slotSyncMenu( int action )
2151{
2152 //qDebug("syncaction %d ", action);
2153 if ( action == 0 ) {
2087 2154
2155 // seems to be a Qt2 event handling bug
2156 // syncmenu.clear causes a segfault at first time
2157 // when we call it after the main event loop, it is ok
2158 // same behaviour when calling OM/Pi via QCOP for the first time
2159 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
2160 //confSync();
2088 2161
2089#ifndef KAB_EMBEDDED 2162 return;
2090#include "kabcore.moc" 2163 }
2091#endif //KAB_EMBEDDED 2164 if ( action == 1 ) {
2165 multiSync( true );
2166 return;
2167 }
2168
2169 if (mBlockSaveFlag)
2170 return;
2171 mBlockSaveFlag = true;
2172 mCurrentSyncProfile = action - 1000 ;
2173 mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ;
2174 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ;
2175 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2176 KSyncProfile* temp = new KSyncProfile ();
2177 temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2178 temp->readConfig(&config);
2179 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2180 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2181 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2182 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2183 KABPrefs::instance()->mWriteBackInFuture = 0;
2184 if ( temp->getWriteBackFuture() )
2185 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2186 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2187 if ( action == 1000 ) {
2188 syncSharp();
2189
2190 } else if ( action == 1001 ) {
2191 syncLocalFile();
2192
2193 } else if ( action == 1002 ) {
2194 quickSyncLocalFile();
2195
2196 } else if ( action >= 1003 ) {
2197 if ( temp->getIsLocalFileSync() ) {
2198 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
2199 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
2200 } else {
2201 if ( temp->getIsPhoneSync() ) {
2202 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2203 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2204 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2205 syncPhone();
2206 } else
2207 syncRemote( temp );
2208
2209 }
2210 }
2211 delete temp;
2212 mBlockSaveFlag = false;
2213}
2214
2215void KABCore::syncLocalFile()
2216{
2217
2218 QString fn =KABPrefs::instance()->mLastSyncedLocalFile;
2219
2220 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2221 if ( fn == "" )
2222 return;
2223 if ( syncWithFile( fn, false ) ) {
2224 qDebug("syncLocalFile() successful ");
2225 }
2226
2227}
2228bool KABCore::syncWithFile( QString fn , bool quick )
2229{
2230 bool ret = false;
2231 QFileInfo info;
2232 info.setFile( fn );
2233 QString mess;
2234 bool loadbup = true;
2235 if ( !info. exists() ) {
2236 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2237 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2238 mess );
2239 return ret;
2240 }
2241 int result = 0;
2242 if ( !quick ) {
2243 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2244 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2245 mess,
2246 i18n("Sync"), i18n("Cancel"), 0,
2247 0, 1 );
2248 if ( result )
2249 return false;
2250 }
2251 if ( KABPrefs::instance()->mAskForPreferences )
2252 edit_sync_options();
2253 if ( result == 0 ) {
2254 //qDebug("Now sycing ... ");
2255 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) )
2256 setCaption( i18n("Synchronization successful") );
2257 else
2258 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2259 if ( ! quick )
2260 KABPrefs::instance()->mLastSyncedLocalFile = fn;
2261 setModified();
2262 }
2263 return ret;
2264}
2265void KABCore::quickSyncLocalFile()
2266{
2267
2268 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2269 qDebug("quick syncLocalFile() successful ");
2270
2271 }
2272}
2273void KABCore::multiSync( bool askforPrefs )
2274{
2275 if (mBlockSaveFlag)
2276 return;
2277 mBlockSaveFlag = true;
2278 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
2279 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2280 question,
2281 i18n("Yes"), i18n("No"),
2282 0, 0 ) != 0 ) {
2283 mBlockSaveFlag = false;
2284 setCaption(i18n("Aborted! Nothing synced!"));
2285 return;
2286 }
2287 mCurrentSyncDevice = i18n("Multiple profiles") ;
2288 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs;
2289 if ( askforPrefs ) {
2290 edit_sync_options();
2291 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs;
2292 }
2293 setCaption(i18n("Multiple sync started.") );
2294 qApp->processEvents();
2295 int num = ringSync() ;
2296 if ( num > 1 )
2297 ringSync();
2298 mBlockSaveFlag = false;
2299 if ( num )
2300 save();
2301 if ( num )
2302 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
2303 else
2304 setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
2305 return;
2306}
2307int KABCore::ringSync()
2308{
2309 int syncedProfiles = 0;
2310 int i;
2311 QTime timer;
2312 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2313 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames;
2314 KSyncProfile* temp = new KSyncProfile ();
2315 KABPrefs::instance()->mAskForPreferences = false;
2316 for ( i = 0; i < syncProfileNames.count(); ++i ) {
2317 mCurrentSyncProfile = i;
2318 temp->setName(syncProfileNames[mCurrentSyncProfile]);
2319 temp->readConfig(&config);
2320 if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) {
2321 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
2322 ++syncedProfiles;
2323 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2324 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2325 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2326 KABPrefs::instance()->mWriteBackInFuture = 0;
2327 if ( temp->getWriteBackFuture() )
2328 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2329 KABPrefs::instance()->mShowSyncSummary = false;
2330 mCurrentSyncDevice = syncProfileNames[i] ;
2331 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName;
2332 if ( i == 0 ) {
2333 syncSharp();
2334 } else {
2335 if ( temp->getIsLocalFileSync() ) {
2336 if ( syncWithFile( temp->getRemoteFileName( ), true ) )
2337 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName();
2338 } else {
2339 if ( temp->getIsPhoneSync() ) {
2340 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2341 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2342 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2343 syncPhone();
2344 } else
2345 syncRemote( temp, false );
2346
2347 }
2348 }
2349 timer.start();
2350 setCaption(i18n("Multiple sync in progress ... please wait!") );
2351 while ( timer.elapsed () < 2000 ) {
2352 qApp->processEvents();
2353#ifndef _WIN32_
2354 sleep (1);
2355#endif
2356 }
2357
2358 }
2359
2360 }
2361 delete temp;
2362 return syncedProfiles;
2363}
2364
2365void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2366{
2367 QString question;
2368 if ( ask ) {
2369 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2370 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2371 question,
2372 i18n("Yes"), i18n("No"),
2373 0, 0 ) != 0 )
2374 return;
2375 }
2376 QString command = prof->getPreSyncCommand();
2377 int fi;
2378 if ( (fi = command.find("$PWD$")) > 0 ) {
2379 QString pwd = getPassword();
2380 command = command.left( fi )+ pwd + command.mid( fi+5 );
2381
2382 }
2383 int maxlen = 30;
2384 if ( QApplication::desktop()->width() > 320 )
2385 maxlen += 25;
2386 setCaption ( i18n( "Copy remote file to local machine..." ) );
2387 int fileSize = 0;
2388 int result = system ( command );
2389 // 0 : okay
2390 // 256: no such file or dir
2391 //
2392 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2393 if ( result != 0 ) {
2394 int len = maxlen;
2395 while ( len < command.length() ) {
2396 command.insert( len , "\n" );
2397 len += maxlen +2;
2398 }
2399 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) ;
2400 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2401 question,
2402 i18n("Okay!")) ;
2403 setCaption ("KO/Pi");
2404 return;
2405 }
2406 setCaption ( i18n( "Copying succeed." ) );
2407 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2408 if ( syncWithFile( prof->getLocalTempFile(), true ) ) {
2409// Event* e = mView->getLastSyncEvent();
2410// e->setReadOnly( false );
2411// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2412// e->setReadOnly( true );
2413 if ( KABPrefs::instance()->mWriteBackFile ) {
2414 command = prof->getPostSyncCommand();
2415 int fi;
2416 if ( (fi = command.find("$PWD$")) > 0 ) {
2417 QString pwd = getPassword();
2418 command = command.left( fi )+ pwd + command.mid( fi+5 );
2419
2420 }
2421 setCaption ( i18n( "Writing back file ..." ) );
2422 result = system ( command );
2423 qDebug("KO: Writing back file result: %d ", result);
2424 if ( result != 0 ) {
2425 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2426 return;
2427 } else {
2428 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2429 }
2430 }
2431 }
2432 return;
2433}
2434#include <qpushbutton.h>
2435#include <qradiobutton.h>
2436#include <qbuttongroup.h>
2437void KABCore::edit_sync_options()
2438{
2439 //mDialogManager->showSyncOptions();
2440 //KABPrefs::instance()->mSyncAlgoPrefs
2441 QDialog dia( this, "dia", true );
2442 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2443 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2444 QVBoxLayout lay ( &dia );
2445 lay.setSpacing( 2 );
2446 lay.setMargin( 3 );
2447 lay.addWidget(&gr);
2448 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2449 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2450 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2451 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2452 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2453 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2454 //QRadioButton both( i18n("Take both on conflict"), &gr );
2455 QPushButton pb ( "OK", &dia);
2456 lay.addWidget( &pb );
2457 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2458 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2459 case 0:
2460 loc.setChecked( true);
2461 break;
2462 case 1:
2463 rem.setChecked( true );
2464 break;
2465 case 2:
2466 newest.setChecked( true);
2467 break;
2468 case 3:
2469 ask.setChecked( true);
2470 break;
2471 case 4:
2472 f_loc.setChecked( true);
2473 break;
2474 case 5:
2475 f_rem.setChecked( true);
2476 break;
2477 case 6:
2478 // both.setChecked( true);
2479 break;
2480 default:
2481 break;
2482 }
2483 if ( dia.exec() ) {
2484 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2485 }
2486
2487
2488}
2489QString KABCore::getPassword( )
2490{
2491 QString retfile = "";
2492 QDialog dia ( this, "input-dialog", true );
2493 QLineEdit lab ( &dia );
2494 lab.setEchoMode( QLineEdit::Password );
2495 QVBoxLayout lay( &dia );
2496 lay.setMargin(7);
2497 lay.setSpacing(7);
2498 lay.addWidget( &lab);
2499 dia.setFixedSize( 230,50 );
2500 dia.setCaption( i18n("Enter password") );
2501 QPushButton pb ( "OK", &dia);
2502 lay.addWidget( &pb );
2503 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2504 dia.show();
2505 int res = dia.exec();
2506 if ( res )
2507 retfile = lab.text();
2508 dia.hide();
2509 qApp->processEvents();
2510 return retfile;
2511
2512}
2513
2514bool KABCore::syncAB(QString filename, int mode)
2515{
2516
2517}
2518
2519
2520void KABCore::confSync()
2521{
2522 //mView->confSync();
2523 qDebug("pending KABCore::confSync() ");
2524 fillSyncMenu();
2525}
2526void KABCore::syncSharp()
2527{
2528 if ( mModified )
2529 save();
2530 qDebug("pending syncSharp() ");
2531 //mView->syncSharp();
2532 mModified = true ;
2533
2534}
2535void KABCore::syncPhone()
2536{
2537 if ( mModified )
2538 save();
2539 qDebug("pending syncPhone(); ");
2540 //mView->syncPhone();
2541 setModified();
2542
2543}
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index 39d043f..10ce8f4 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -48,24 +48,25 @@ class KAddressBookMain;
48//US class QAction; 48//US class QAction;
49#endif //KAB_EMBEDDED 49#endif //KAB_EMBEDDED
50class KCMultiDialog; 50class KCMultiDialog;
51class KXMLGUIClient; 51class KXMLGUIClient;
52class ExtensionManager; 52class ExtensionManager;
53class XXPortManager; 53class XXPortManager;
54class JumpButtonBar; 54class JumpButtonBar;
55class IncSearchWidget; 55class IncSearchWidget;
56class KDGanttMinimizeSplitter; 56class KDGanttMinimizeSplitter;
57class KAction; 57class KAction;
58class KActionCollection; 58class KActionCollection;
59class KToggleAction; 59class KToggleAction;
60class KSyncProfile;
60 61
61class QAction; 62class QAction;
62class QMenuBar; 63class QMenuBar;
63class QSplitter; 64class QSplitter;
64class ViewContainer; 65class ViewContainer;
65class ViewManager; 66class ViewManager;
66class AddresseeEditorDialog; 67class AddresseeEditorDialog;
67class Ir; 68class Ir;
68 69
69class KABCore : public QWidget 70class KABCore : public QWidget
70{ 71{
71 Q_OBJECT 72 Q_OBJECT
@@ -331,24 +332,25 @@ class KABCore : public QWidget
331 void addGUIClient( KXMLGUIClient *client ); 332 void addGUIClient( KXMLGUIClient *client );
332 333
333 void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); 334 void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid);
334 void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); 335 void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid);
335 336
336 337
337 signals: 338 signals:
338 void contactSelected( const QString &name ); 339 void contactSelected( const QString &name );
339 void contactSelected( const QPixmap &pixmap ); 340 void contactSelected( const QPixmap &pixmap );
340 public slots: 341 public slots:
341 void setDetailsVisible( bool visible ); 342 void setDetailsVisible( bool visible );
342 void setDetailsToState(); 343 void setDetailsToState();
344 void slotSyncMenu( int );
343 private slots: 345 private slots:
344 void setJumpButtonBarVisible( bool visible ); 346 void setJumpButtonBarVisible( bool visible );
345 void importFromOL(); 347 void importFromOL();
346 void extensionModified( const KABC::Addressee::List &list ); 348 void extensionModified( const KABC::Addressee::List &list );
347 void extensionChanged( int id ); 349 void extensionChanged( int id );
348 void clipboardDataChanged(); 350 void clipboardDataChanged();
349 void updateActionMenu(); 351 void updateActionMenu();
350 void configureKeyBindings(); 352 void configureKeyBindings();
351 void removeVoice(); 353 void removeVoice();
352#ifdef KAB_EMBEDDED 354#ifdef KAB_EMBEDDED
353 void configureResources(); 355 void configureResources();
354#endif //KAB_EMBEDDED 356#endif //KAB_EMBEDDED
@@ -423,34 +425,54 @@ class KABCore : public QWidget
423 KAction *mActionWhoAmI; 425 KAction *mActionWhoAmI;
424 KAction *mActionCategories; 426 KAction *mActionCategories;
425 KAction *mActionAboutKAddressbook; 427 KAction *mActionAboutKAddressbook;
426 KAction *mActionLicence; 428 KAction *mActionLicence;
427 KAction *mActionFaq; 429 KAction *mActionFaq;
428 430
429 KAction *mActionDeleteView; 431 KAction *mActionDeleteView;
430 432
431 QPopupMenu *viewMenu; 433 QPopupMenu *viewMenu;
432 QPopupMenu *filterMenu; 434 QPopupMenu *filterMenu;
433 QPopupMenu *settingsMenu; 435 QPopupMenu *settingsMenu;
434 QPopupMenu *changeMenu; 436 QPopupMenu *changeMenu;
435
436//US QAction *mActionSave; 437//US QAction *mActionSave;
437 QPopupMenu *ImportMenu; 438 QPopupMenu *ImportMenu;
438 QPopupMenu *ExportMenu; 439 QPopupMenu *ExportMenu;
439 //LR additional methods 440 //LR additional methods
440 KAction *mActionRemoveVoice; 441 KAction *mActionRemoveVoice;
441 KAction * mActionImportOL; 442 KAction * mActionImportOL;
442 443
443#ifndef KAB_EMBEDDED 444#ifndef KAB_EMBEDDED
444 KAddressBookService *mAddressBookService; 445 KAddressBookService *mAddressBookService;
445#endif //KAB_EMBEDDED 446#endif //KAB_EMBEDDED
446 447
447 class KABCorePrivate; 448 class KABCorePrivate;
448 KABCorePrivate *d; 449 KABCorePrivate *d;
450 bool mBlockSaveFlag;
449 451
450#ifdef KAB_EMBEDDED 452#ifdef KAB_EMBEDDED
451 KAddressBookMain *mMainWindow; // should be the same like mGUIClient 453 KAddressBookMain *mMainWindow; // should be the same like mGUIClient
452#endif //KAB_EMBEDDED 454#endif //KAB_EMBEDDED
455 // LR *******************************
456 // sync stuff!
457 QPopupMenu *syncMenu;
458 void fillSyncMenu();
459 void confSync();
460 QString mCurrentSyncDevice;
461 QString mCurrentSyncName;
462 void quickSyncLocalFile();
463 bool syncWithFile( QString fn , bool quick );
464 void KABCore::syncLocalFile();
465 void KABCore::syncPhone();
466 void KABCore::syncSharp();
467 void multiSync( bool askforPrefs );
468 int mCurrentSyncProfile ;
469 void syncRemote( KSyncProfile* prof, bool ask = true);
470 void edit_sync_options();
471 bool syncAB(QString filename, int mode);
472 int ringSync();
473 QString getPassword( );
474 // *********************
453 475
454}; 476};
455 477
456#endif 478#endif
diff --git a/kaddressbook/kabprefs.h b/kaddressbook/kabprefs.h
index e4f359c..9926aa0 100644
--- a/kaddressbook/kabprefs.h
+++ b/kaddressbook/kabprefs.h
@@ -73,20 +73,36 @@ class KABPrefs : public KPimPrefs
73 // Extensions stuff 73 // Extensions stuff
74 int mCurrentExtension; 74 int mCurrentExtension;
75 QStringList mActiveExtensions; 75 QStringList mActiveExtensions;
76 76
77 // Views stuff 77 // Views stuff
78 QString mCurrentView; 78 QString mCurrentView;
79 QStringList mViewNames; 79 QStringList mViewNames;
80 80
81 // Filter 81 // Filter
82 int mCurrentFilter; 82 int mCurrentFilter;
83 83
84 void setCategoryDefaults(); 84 void setCategoryDefaults();
85 85 // sync stuff
86 QString mLocalMachineName;
87 QStringList mExternSyncProfiles;
88 QStringList mSyncProfileNames;
89 bool mAskForPreferences;
90 bool mShowSyncSummary;
91 bool mShowSyncEvents;
92 bool mShowTodoInAgenda;
93 bool mWriteBackExistingOnly;
94 int mSyncAlgoPrefs;
95 int mRingSyncAlgoPrefs;
96 bool mWriteBackFile;
97 int mWriteBackInFuture;
98 QString mPhoneDevice;
99 QString mPhoneConnection;
100 QString mPhoneModel;
101 QString mLastSyncedLocalFile; // save!
86 private: 102 private:
87 KABPrefs(); 103 KABPrefs();
88 104
89 static KABPrefs *sInstance; 105 static KABPrefs *sInstance;
90}; 106};
91 107
92#endif 108#endif