summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 5175f94..7ee56e4 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -54,184 +54,198 @@
54#include <kconfig.h> 54#include <kconfig.h>
55#include <kfiledialog.h> 55#include <kfiledialog.h>
56 56
57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 57KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 58 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
59{ 59{
60 mServerSocket = 0; 60 mServerSocket = 0;
61 bar = new QProgressBar ( 1, 0 ); 61 bar = new QProgressBar ( 1, 0 );
62 bar->setCaption (""); 62 bar->setCaption ("");
63 63
64 int w = 300; 64 int w = 300;
65 if ( QApplication::desktop()->width() < 320 ) 65 if ( QApplication::desktop()->width() < 320 )
66 w = 220; 66 w = 220;
67 int h = bar->sizeHint().height() ; 67 int h = bar->sizeHint().height() ;
68 int dw = QApplication::desktop()->width(); 68 int dw = QApplication::desktop()->width();
69 int dh = QApplication::desktop()->height(); 69 int dh = QApplication::desktop()->height();
70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 70 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
71 71
72} 72}
73 73
74KSyncManager::~KSyncManager() 74KSyncManager::~KSyncManager()
75{ 75{
76 delete bar; 76 delete bar;
77} 77}
78 78
79 79
80void KSyncManager::fillSyncMenu() 80void KSyncManager::fillSyncMenu()
81{ 81{
82 if ( mSyncMenu->count() ) 82 if ( mSyncMenu->count() )
83 mSyncMenu->clear(); 83 mSyncMenu->clear();
84 84
85 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 85 mSyncMenu->insertItem( i18n("Configure..."), 0 );
86 mSyncMenu->insertSeparator(); 86 mSyncMenu->insertSeparator();
87 if ( mServerSocket == 0 ) { 87 if ( mServerSocket == 0 ) {
88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 88 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
89 } else { 89 } else {
90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 90 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
91 } 91 }
92 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 93 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
94 mSyncMenu->insertSeparator(); 94 mSyncMenu->insertSeparator();
95 95
96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 96 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
97 config.setGroup("General"); 97 config.setGroup("General");
98 QStringList prof = config.readListEntry("SyncProfileNames"); 98 QStringList prof = config.readListEntry("SyncProfileNames");
99 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 99 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
100 if ( prof.count() < 2 ) { 100 if ( prof.count() < 2 ) {
101 prof.clear(); 101 prof.clear();
102#ifdef DESKTOP_VERSION
103#ifdef _WIN32_
104 prof << i18n("OutLook(not_implemented)");
105#else
106 prof << i18n("KDE_Desktop");
107#endif
108#else
102 prof << i18n("Sharp_DTM"); 109 prof << i18n("Sharp_DTM");
110#endif
103 prof << i18n("Local_file"); 111 prof << i18n("Local_file");
104 prof << i18n("Last_file"); 112 prof << i18n("Last_file");
105 KSyncProfile* temp = new KSyncProfile (); 113 KSyncProfile* temp = new KSyncProfile ();
106 temp->setName( prof[0] ); 114 temp->setName( prof[0] );
107 temp->writeConfig(&config); 115 temp->writeConfig(&config);
108 temp->setName( prof[1] ); 116 temp->setName( prof[1] );
109 temp->writeConfig(&config); 117 temp->writeConfig(&config);
110 temp->setName( prof[2] ); 118 temp->setName( prof[2] );
111 temp->writeConfig(&config); 119 temp->writeConfig(&config);
112 config.setGroup("General"); 120 config.setGroup("General");
113 config.writeEntry("SyncProfileNames",prof); 121 config.writeEntry("SyncProfileNames",prof);
114 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 122 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
115 config.sync(); 123 config.sync();
116 delete temp; 124 delete temp;
117 } 125 }
118 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 126 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
119 mSyncProfileNames = prof; 127 mSyncProfileNames = prof;
120 unsigned int i; 128 unsigned int i;
121 for ( i = 0; i < prof.count(); ++i ) { 129 for ( i = 0; i < prof.count(); ++i ) {
122 mSyncMenu->insertItem( prof[i], 1000+i ); 130 mSyncMenu->insertItem( prof[i], 1000+i );
123 if ( i == 2 ) 131 if ( i == 2 )
124 mSyncMenu->insertSeparator(); 132 mSyncMenu->insertSeparator();
125 } 133 }
126 QDir app_dir; 134 QDir app_dir;
127 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 135 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
128 if ( mTargetApp == PWMPI) { 136 if ( mTargetApp == PWMPI) {
129 mSyncMenu->removeItem( 1000 ); 137 mSyncMenu->removeItem( 1000 );
130 } 138 }
139#ifndef DESKTOP_VERSION
131 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 140 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
132 mSyncMenu->removeItem( 1000 ); 141 mSyncMenu->removeItem( 1000 );
133 } 142 }
143#endif
134 mSyncMenu->removeItem( 1002 ); 144 mSyncMenu->removeItem( 1002 );
135} 145}
136 146
137void KSyncManager::slotSyncMenu( int action ) 147void KSyncManager::slotSyncMenu( int action )
138{ 148{
139 //qDebug("syncaction %d ", action); 149 //qDebug("syncaction %d ", action);
140 if ( action == 0 ) { 150 if ( action == 0 ) {
141 151
142 // seems to be a Qt2 event handling bug 152 // seems to be a Qt2 event handling bug
143 // syncmenu.clear causes a segfault at first time 153 // syncmenu.clear causes a segfault at first time
144 // when we call it after the main event loop, it is ok 154 // when we call it after the main event loop, it is ok
145 // same behaviour when calling OM/Pi via QCOP for the first time 155 // same behaviour when calling OM/Pi via QCOP for the first time
146 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 156 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
147 //confSync(); 157 //confSync();
148 158
149 return; 159 return;
150 } 160 }
151 if ( action == 1 ) { 161 if ( action == 1 ) {
152 multiSync( true ); 162 multiSync( true );
153 return; 163 return;
154 } 164 }
155 if ( action == 2 ) { 165 if ( action == 2 ) {
156 enableQuick(); 166 enableQuick();
157 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 167 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
158 return; 168 return;
159 } 169 }
160 if ( action == 3 ) { 170 if ( action == 3 ) {
161 delete mServerSocket; 171 delete mServerSocket;
162 mServerSocket = 0; 172 mServerSocket = 0;
163 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 173 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
164 return; 174 return;
165 } 175 }
166 176
167 if (blockSave()) 177 if (blockSave())
168 return; 178 return;
169 179
170 setBlockSave(true); 180 setBlockSave(true);
171 181
172 mCurrentSyncProfile = action - 1000 ; 182 mCurrentSyncProfile = action - 1000 ;
173 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 183 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
174 mCurrentSyncName = mLocalMachineName ; 184 mCurrentSyncName = mLocalMachineName ;
175 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 185 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
176 KSyncProfile* temp = new KSyncProfile (); 186 KSyncProfile* temp = new KSyncProfile ();
177 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 187 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
178 temp->readConfig(&config); 188 temp->readConfig(&config);
179 mAskForPreferences = temp->getAskForPreferences(); 189 mAskForPreferences = temp->getAskForPreferences();
180 mSyncAlgoPrefs = temp->getSyncPrefs(); 190 mSyncAlgoPrefs = temp->getSyncPrefs();
181 mWriteBackFile = temp->getWriteBackFile(); 191 mWriteBackFile = temp->getWriteBackFile();
182 mWriteBackExistingOnly = temp->getWriteBackExisting(); 192 mWriteBackExistingOnly = temp->getWriteBackExisting();
183 mIsKapiFile = temp->getIsKapiFile(); 193 mIsKapiFile = temp->getIsKapiFile();
184 mWriteBackInFuture = 0; 194 mWriteBackInFuture = 0;
185 if ( temp->getWriteBackFuture() ) 195 if ( temp->getWriteBackFuture() )
186 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 196 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
187 mShowSyncSummary = temp->getShowSummaryAfterSync(); 197 mShowSyncSummary = temp->getShowSummaryAfterSync();
188 if ( action == 1000 ) { 198 if ( action == 1000 ) {
199#ifdef DESKTOP_VERSION
200 syncKDE();
201#else
189 syncSharp(); 202 syncSharp();
203#endif
190 204
191 } else if ( action == 1001 ) { 205 } else if ( action == 1001 ) {
192 syncLocalFile(); 206 syncLocalFile();
193 207
194 } else if ( action == 1002 ) { 208 } else if ( action == 1002 ) {
195 mWriteBackFile = false; 209 mWriteBackFile = false;
196 mAskForPreferences = false; 210 mAskForPreferences = false;
197 mShowSyncSummary = false; 211 mShowSyncSummary = false;
198 mSyncAlgoPrefs = 3; 212 mSyncAlgoPrefs = 3;
199 quickSyncLocalFile(); 213 quickSyncLocalFile();
200 214
201 } else if ( action >= 1003 ) { 215 } else if ( action >= 1003 ) {
202 if ( temp->getIsLocalFileSync() ) { 216 if ( temp->getIsLocalFileSync() ) {
203 switch(mTargetApp) 217 switch(mTargetApp)
204 { 218 {
205 case (KAPI): 219 case (KAPI):
206 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 220 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
207 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 221 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
208 break; 222 break;
209 case (KOPI): 223 case (KOPI):
210 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 224 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
211 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 225 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
212 break; 226 break;
213 case (PWMPI): 227 case (PWMPI):
214 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 228 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
215 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 229 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
216 break; 230 break;
217 default: 231 default:
218 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 232 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
219 break; 233 break;
220 234
221 } 235 }
222 } else { 236 } else {
223 if ( temp->getIsPhoneSync() ) { 237 if ( temp->getIsPhoneSync() ) {
224 mPhoneDevice = temp->getPhoneDevice( ) ; 238 mPhoneDevice = temp->getPhoneDevice( ) ;
225 mPhoneConnection = temp->getPhoneConnection( ); 239 mPhoneConnection = temp->getPhoneConnection( );
226 mPhoneModel = temp->getPhoneModel( ); 240 mPhoneModel = temp->getPhoneModel( );
227 syncPhone(); 241 syncPhone();
228 } else if ( temp->getIsPiSync() ) { 242 } else if ( temp->getIsPiSync() ) {
229 if ( mTargetApp == KAPI ) { 243 if ( mTargetApp == KAPI ) {
230 mPassWordPiSync = temp->getRemotePwAB(); 244 mPassWordPiSync = temp->getRemotePwAB();
231 mActiveSyncPort = temp->getRemotePortAB(); 245 mActiveSyncPort = temp->getRemotePortAB();
232 mActiveSyncIP = temp->getRemoteIPAB(); 246 mActiveSyncIP = temp->getRemoteIPAB();
233 } else if ( mTargetApp == KOPI ) { 247 } else if ( mTargetApp == KOPI ) {
234 mPassWordPiSync = temp->getRemotePw(); 248 mPassWordPiSync = temp->getRemotePw();
235 mActiveSyncPort = temp->getRemotePort(); 249 mActiveSyncPort = temp->getRemotePort();
236 mActiveSyncIP = temp->getRemoteIP(); 250 mActiveSyncIP = temp->getRemoteIP();
237 } else { 251 } else {
@@ -696,96 +710,126 @@ void KSyncManager::edit_sync_options()
696 } 710 }
697 711
698 712
699} 713}
700 714
701QString KSyncManager::getPassword( ) 715QString KSyncManager::getPassword( )
702{ 716{
703 QString retfile = ""; 717 QString retfile = "";
704 QDialog dia ( mParent, "input-dialog", true ); 718 QDialog dia ( mParent, "input-dialog", true );
705 QLineEdit lab ( &dia ); 719 QLineEdit lab ( &dia );
706 lab.setEchoMode( QLineEdit::Password ); 720 lab.setEchoMode( QLineEdit::Password );
707 QVBoxLayout lay( &dia ); 721 QVBoxLayout lay( &dia );
708 lay.setMargin(7); 722 lay.setMargin(7);
709 lay.setSpacing(7); 723 lay.setSpacing(7);
710 lay.addWidget( &lab); 724 lay.addWidget( &lab);
711 dia.setFixedSize( 230,50 ); 725 dia.setFixedSize( 230,50 );
712 dia.setCaption( i18n("Enter password") ); 726 dia.setCaption( i18n("Enter password") );
713 QPushButton pb ( "OK", &dia); 727 QPushButton pb ( "OK", &dia);
714 lay.addWidget( &pb ); 728 lay.addWidget( &pb );
715 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 729 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
716 dia.show(); 730 dia.show();
717 int res = dia.exec(); 731 int res = dia.exec();
718 if ( res ) 732 if ( res )
719 retfile = lab.text(); 733 retfile = lab.text();
720 dia.hide(); 734 dia.hide();
721 qApp->processEvents(); 735 qApp->processEvents();
722 return retfile; 736 return retfile;
723 737
724} 738}
725 739
726 740
727void KSyncManager::confSync() 741void KSyncManager::confSync()
728{ 742{
729 static KSyncPrefsDialog* sp = 0; 743 static KSyncPrefsDialog* sp = 0;
730 if ( ! sp ) { 744 if ( ! sp ) {
731 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 745 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
732 } 746 }
733 sp->usrReadConfig(); 747 sp->usrReadConfig();
734#ifndef DESKTOP_VERSION 748#ifndef DESKTOP_VERSION
735 sp->showMaximized(); 749 sp->showMaximized();
736#else 750#else
737 sp->show(); 751 sp->show();
738#endif 752#endif
739 sp->exec(); 753 sp->exec();
740 mSyncProfileNames = sp->getSyncProfileNames(); 754 mSyncProfileNames = sp->getSyncProfileNames();
741 mLocalMachineName = sp->getLocalMachineName (); 755 mLocalMachineName = sp->getLocalMachineName ();
742 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 756 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
743} 757}
758void KSyncManager::syncKDE()
759{
760 emit save();
761 switch(mTargetApp)
762 {
763 case (KAPI):
764
765 break;
766 case (KOPI):
767 {
768 QString command ="./kdecaldump";
769 system ( command.latin1());
770 if ( syncWithFile( "/tmp/kdedumpall.ics",true ) ) {
771 if ( mWriteBackFile ) {
772 command += " --read";
773 system ( command.latin1());
774 }
775 }
776
777 }
778 break;
779 case (PWMPI):
780
781 break;
782 default:
783 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
784 break;
785
786 }
787}
744 788
745void KSyncManager::syncSharp() 789void KSyncManager::syncSharp()
746{ 790{
747 791
748 if ( ! syncExternalApplication("sharp") ) 792 if ( ! syncExternalApplication("sharp") )
749 qDebug("ERROR sync sharp "); 793 qDebug("ERROR sync sharp ");
750} 794}
751 795
752bool KSyncManager::syncExternalApplication(QString resource) 796bool KSyncManager::syncExternalApplication(QString resource)
753{ 797{
754 798
755 emit save(); 799 emit save();
756 800
757 if ( mAskForPreferences ) 801 if ( mAskForPreferences )
758 edit_sync_options(); 802 edit_sync_options();
759 803
760 qDebug("Sync extern %s", resource.latin1()); 804 qDebug("Sync extern %s", resource.latin1());
761 805
762 bool syncOK = mImplementation->syncExternal(this, resource); 806 bool syncOK = mImplementation->syncExternal(this, resource);
763 807
764 return syncOK; 808 return syncOK;
765 809
766} 810}
767 811
768void KSyncManager::syncPhone() 812void KSyncManager::syncPhone()
769{ 813{
770 814
771 syncExternalApplication("phone"); 815 syncExternalApplication("phone");
772 816
773} 817}
774 818
775void KSyncManager::showProgressBar(int percentage, QString caption, int total) 819void KSyncManager::showProgressBar(int percentage, QString caption, int total)
776{ 820{
777 if (!bar->isVisible()) 821 if (!bar->isVisible())
778 { 822 {
779 bar->setCaption (caption); 823 bar->setCaption (caption);
780 bar->setTotalSteps ( total ) ; 824 bar->setTotalSteps ( total ) ;
781 825
782 bar->show(); 826 bar->show();
783 } 827 }
784 828
785 bar->setProgress( percentage ); 829 bar->setProgress( percentage );
786} 830}
787 831
788void KSyncManager::hideProgressBar() 832void KSyncManager::hideProgressBar()
789{ 833{
790 bar->hide(); 834 bar->hide();
791} 835}