summaryrefslogtreecommitdiffabout
path: root/libkdepim
Unidiff
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kpimprefs.cpp9
-rw-r--r--libkdepim/kpimprefs.h3
-rw-r--r--libkdepim/ksyncmanager.cpp166
-rw-r--r--libkdepim/ksyncmanager.h3
4 files changed, 103 insertions, 78 deletions
diff --git a/libkdepim/kpimprefs.cpp b/libkdepim/kpimprefs.cpp
index 0a2f5f1..c21ebaa 100644
--- a/libkdepim/kpimprefs.cpp
+++ b/libkdepim/kpimprefs.cpp
@@ -1,75 +1,82 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
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 <kglobal.h> 31#include <kglobal.h>
32#include <kconfig.h> 32#include <kconfig.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <kdebug.h> 34#include <kdebug.h>
35 35
36#include "kpimprefs.h" 36#include "kpimprefs.h"
37 37
38KPimPrefs::KPimPrefs( const QString &name ) : 38KPimPrefs::KPimPrefs( const QString &name ) :
39 KPrefs( name ) 39 KPrefs( name )
40{ 40{
41 config()->setGroup("General"); 41#ifdef _WIN32_
42 QString hdp= locateLocal("data","korganizer")+"\\\\";
43#else
44 QString hdp= locateLocal("data","korganizer")+"/";
45#endif
46 config()->setGroup("SyncOptions");
42 addItemString("PassiveSyncPort",&mPassiveSyncPort,"9197" ); 47 addItemString("PassiveSyncPort",&mPassiveSyncPort,"9197" );
43 addItemString("PassiveSyncPw",&mPassiveSyncPw,"abc" ); 48 addItemString("PassiveSyncPw",&mPassiveSyncPw,"abc" );
49 addItemString("LastSyncedLocalFile", &mLastSyncedLocalFile ,hdp +"lastsync.ics" );
50 addItemInt("RingSyncAlgoPrefs",&mRingSyncAlgoPrefs,3);
44} 51}
45 52
46KPimPrefs::~KPimPrefs() 53KPimPrefs::~KPimPrefs()
47{ 54{
48} 55}
49 56
50void KPimPrefs::usrSetDefaults() 57void KPimPrefs::usrSetDefaults()
51{ 58{
52 setCategoryDefaults(); 59 setCategoryDefaults();
53} 60}
54 61
55void KPimPrefs::usrReadConfig() 62void KPimPrefs::usrReadConfig()
56{ 63{
57 kdDebug(5300) << "KPimPrefs::usrReadConfig()" << endl; 64 kdDebug(5300) << "KPimPrefs::usrReadConfig()" << endl;
58 65
59 config()->setGroup("General"); 66 config()->setGroup("General");
60 mCustomCategories = config()->readListEntry("Custom Categories"); 67 mCustomCategories = config()->readListEntry("Custom Categories");
61 if (mCustomCategories.isEmpty()) setCategoryDefaults(); 68 if (mCustomCategories.isEmpty()) setCategoryDefaults();
62} 69}
63 70
64 71
65void KPimPrefs::usrWriteConfig() 72void KPimPrefs::usrWriteConfig()
66{ 73{
67 config()->setGroup("General"); 74 config()->setGroup("General");
68 config()->writeEntry("Custom Categories",mCustomCategories); 75 config()->writeEntry("Custom Categories",mCustomCategories);
69} 76}
70 77
71void KPimPrefs::setCategoryDefaults() 78void KPimPrefs::setCategoryDefaults()
72{ 79{
73 // empty implementation 80 // empty implementation
74} 81}
75 82
diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h
index fde8093..9346f7d 100644
--- a/libkdepim/kpimprefs.h
+++ b/libkdepim/kpimprefs.h
@@ -1,70 +1,71 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
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#ifndef KPIMPREFS_H 31#ifndef KPIMPREFS_H
32#define KPIMPREFS_H 32#define KPIMPREFS_H
33 33
34#include <qstringlist.h> 34#include <qstringlist.h>
35 35
36#include "kprefs.h" 36#include "kprefs.h"
37 37
38class KPimPrefs : public KPrefs 38class KPimPrefs : public KPrefs
39{ 39{
40 public: 40 public:
41 41
42 KPimPrefs( const QString &name = QString::null ); 42 KPimPrefs( const QString &name = QString::null );
43 43
44 virtual ~KPimPrefs(); 44 virtual ~KPimPrefs();
45 45
46 /** Set preferences to default values */ 46 /** Set preferences to default values */
47 void usrSetDefaults(); 47 void usrSetDefaults();
48 48
49 /** Read preferences from config file */ 49 /** Read preferences from config file */
50 void usrReadConfig(); 50 void usrReadConfig();
51 51
52 /** Write preferences to config file */ 52 /** Write preferences to config file */
53 void usrWriteConfig(); 53 void usrWriteConfig();
54 54
55 55
56 public: 56 public:
57 QStringList mCustomCategories; 57 QStringList mCustomCategories;
58 QString mPassiveSyncPort; 58 QString mPassiveSyncPort;
59 QString mPassiveSyncPw; 59 QString mPassiveSyncPw;
60 60 int mRingSyncAlgoPrefs;
61 QString mLastSyncedLocalFile;
61 62
62 63
63 protected: 64 protected:
64 virtual void setCategoryDefaults(); 65 virtual void setCategoryDefaults();
65 66
66 67
67 68
68}; 69};
69 70
70#endif 71#endif
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index fad9a76..568c2a9 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,865 +1,884 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51 51
52#include <klocale.h> 52#include <klocale.h>
53#include <kglobal.h> 53#include <kglobal.h>
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//LR ok 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 prof << i18n("Sharp_DTM"); 102 prof << i18n("Sharp_DTM");
103 prof << i18n("Local_file"); 103 prof << i18n("Local_file");
104 prof << i18n("Last_file");
104 KSyncProfile* temp = new KSyncProfile (); 105 KSyncProfile* temp = new KSyncProfile ();
105 temp->setName( prof[0] ); 106 temp->setName( prof[0] );
106 temp->writeConfig(&config); 107 temp->writeConfig(&config);
107 temp->setName( prof[1] ); 108 temp->setName( prof[1] );
108 temp->writeConfig(&config); 109 temp->writeConfig(&config);
110 temp->setName( prof[2] );
111 temp->writeConfig(&config);
109 config.setGroup("General"); 112 config.setGroup("General");
110 config.writeEntry("SyncProfileNames",prof); 113 config.writeEntry("SyncProfileNames",prof);
111 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 114 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
112 config.sync(); 115 config.sync();
113 delete temp; 116 delete temp;
114 } 117 }
115 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 118 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
116 mSyncProfileNames = prof; 119 mSyncProfileNames = prof;
117 unsigned int i; 120 unsigned int i;
118 for ( i = 0; i < prof.count(); ++i ) { 121 for ( i = 0; i < prof.count(); ++i ) {
119 mSyncMenu->insertItem( prof[i], 1000+i ); 122 mSyncMenu->insertItem( prof[i], 1000+i );
120 if ( i == 2 ) 123 if ( i == 2 )
121 mSyncMenu->insertSeparator(); 124 mSyncMenu->insertSeparator();
122 } 125 }
123 QDir app_dir; 126 QDir app_dir;
124 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 127 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
125 if ( mTargetApp == PWMPI) { 128 if ( mTargetApp == PWMPI) {
126 mSyncMenu->removeItem( 1000 ); 129 mSyncMenu->removeItem( 1000 );
127 } 130 }
128 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 131 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
129 mSyncMenu->setItemEnabled( 1000, false ); 132 mSyncMenu->removeItem( 1000 );
130 } 133 }
134 mSyncMenu->removeItem( 1002 );
131} 135}
132 136
133void KSyncManager::slotSyncMenu( int action ) 137void KSyncManager::slotSyncMenu( int action )
134{ 138{
135 //qDebug("syncaction %d ", action); 139 //qDebug("syncaction %d ", action);
136 if ( action == 0 ) { 140 if ( action == 0 ) {
137 141
138 // seems to be a Qt2 event handling bug 142 // seems to be a Qt2 event handling bug
139 // syncmenu.clear causes a segfault at first time 143 // syncmenu.clear causes a segfault at first time
140 // when we call it after the main event loop, it is ok 144 // when we call it after the main event loop, it is ok
141 // same behaviour when calling OM/Pi via QCOP for the first time 145 // same behaviour when calling OM/Pi via QCOP for the first time
142 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 146 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
143 //confSync(); 147 //confSync();
144 148
145 return; 149 return;
146 } 150 }
147 if ( action == 1 ) { 151 if ( action == 1 ) {
148 multiSync( true ); 152 multiSync( true );
149 return; 153 return;
150 } 154 }
151 if ( action == 2 ) { 155 if ( action == 2 ) {
152 enableQuick(); 156 enableQuick();
153 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 157 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
154 return; 158 return;
155 } 159 }
156 if ( action == 3 ) { 160 if ( action == 3 ) {
157 delete mServerSocket; 161 delete mServerSocket;
158 mServerSocket = 0; 162 mServerSocket = 0;
159 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 163 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
160 return; 164 return;
161 } 165 }
162 166
163 if (blockSave()) 167 if (blockSave())
164 return; 168 return;
165 169
166 setBlockSave(true); 170 setBlockSave(true);
167 171
168 mCurrentSyncProfile = action - 1000 ; 172 mCurrentSyncProfile = action - 1000 ;
169 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 173 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
170 mCurrentSyncName = mLocalMachineName ; 174 mCurrentSyncName = mLocalMachineName ;
171 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 175 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
172 KSyncProfile* temp = new KSyncProfile (); 176 KSyncProfile* temp = new KSyncProfile ();
173 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 177 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
174 temp->readConfig(&config); 178 temp->readConfig(&config);
175 mAskForPreferences = temp->getAskForPreferences(); 179 mAskForPreferences = temp->getAskForPreferences();
176 mSyncAlgoPrefs = temp->getSyncPrefs(); 180 mSyncAlgoPrefs = temp->getSyncPrefs();
177 mWriteBackFile = temp->getWriteBackFile(); 181 mWriteBackFile = temp->getWriteBackFile();
178 mWriteBackExistingOnly = temp->getWriteBackExisting(); 182 mWriteBackExistingOnly = temp->getWriteBackExisting();
179 mWriteBackInFuture = 0; 183 mWriteBackInFuture = 0;
180 if ( temp->getWriteBackFuture() ) 184 if ( temp->getWriteBackFuture() )
181 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 185 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
182 mShowSyncSummary = temp->getShowSummaryAfterSync(); 186 mShowSyncSummary = temp->getShowSummaryAfterSync();
183 if ( action == 1000 ) { 187 if ( action == 1000 ) {
184 syncSharp(); 188 syncSharp();
185 189
186 } else if ( action == 1001 ) { 190 } else if ( action == 1001 ) {
187 syncLocalFile(); 191 syncLocalFile();
188 192
189 } else if ( action == 1002 ) { 193 } else if ( action == 1002 ) {
190 quickSyncLocalFile(); 194 quickSyncLocalFile();
191 195
192 } else if ( action >= 1003 ) { 196 } else if ( action >= 1003 ) {
193 if ( temp->getIsLocalFileSync() ) { 197 if ( temp->getIsLocalFileSync() ) {
194 switch(mTargetApp) 198 switch(mTargetApp)
195 { 199 {
196 case (KAPI): 200 case (KAPI):
197 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 201 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
198 mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 202 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
199 break; 203 break;
200 case (KOPI): 204 case (KOPI):
201 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 205 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
202 mLastSyncedLocalFile = temp->getRemoteFileName(); 206 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
203 break; 207 break;
204 case (PWMPI): 208 case (PWMPI):
205 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 209 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
206 mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 210 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
207 break; 211 break;
208 default: 212 default:
209 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 213 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
210 break; 214 break;
211 215
212 } 216 }
213 } else { 217 } else {
214 if ( temp->getIsPhoneSync() ) { 218 if ( temp->getIsPhoneSync() ) {
215 mPhoneDevice = temp->getPhoneDevice( ) ; 219 mPhoneDevice = temp->getPhoneDevice( ) ;
216 mPhoneConnection = temp->getPhoneConnection( ); 220 mPhoneConnection = temp->getPhoneConnection( );
217 mPhoneModel = temp->getPhoneModel( ); 221 mPhoneModel = temp->getPhoneModel( );
218 syncPhone(); 222 syncPhone();
219 } else if ( temp->getIsPiSync() ) { 223 } else if ( temp->getIsPiSync() ) {
220 if ( mTargetApp == KAPI ) { 224 if ( mTargetApp == KAPI ) {
221 mPassWordPiSync = temp->getRemotePwAB(); 225 mPassWordPiSync = temp->getRemotePwAB();
222 mActiveSyncPort = temp->getRemotePortAB(); 226 mActiveSyncPort = temp->getRemotePortAB();
223 mActiveSyncIP = temp->getRemoteIPAB(); 227 mActiveSyncIP = temp->getRemoteIPAB();
224 } else if ( mTargetApp == KOPI ) { 228 } else if ( mTargetApp == KOPI ) {
225 mPassWordPiSync = temp->getRemotePw(); 229 mPassWordPiSync = temp->getRemotePw();
226 mActiveSyncPort = temp->getRemotePort(); 230 mActiveSyncPort = temp->getRemotePort();
227 mActiveSyncIP = temp->getRemoteIP(); 231 mActiveSyncIP = temp->getRemoteIP();
228 } else { 232 } else {
229 mPassWordPiSync = temp->getRemotePwPWM(); 233 mPassWordPiSync = temp->getRemotePwPWM();
230 mActiveSyncPort = temp->getRemotePortPWM(); 234 mActiveSyncPort = temp->getRemotePortPWM();
231 mActiveSyncIP = temp->getRemoteIPPWM(); 235 mActiveSyncIP = temp->getRemoteIPPWM();
232 } 236 }
233 syncPi(); 237 syncPi();
234 } else 238 } else
235 syncRemote( temp ); 239 syncRemote( temp );
236 240
237 } 241 }
238 } 242 }
239 delete temp; 243 delete temp;
240 setBlockSave(false); 244 setBlockSave(false);
241} 245}
246
242void KSyncManager::enableQuick() 247void KSyncManager::enableQuick()
243{ 248{
244 QDialog dia ( 0, "input-dialog", true ); 249 QDialog dia ( 0, "input-dialog", true );
245 QLineEdit lab ( &dia ); 250 QLineEdit lab ( &dia );
246 QVBoxLayout lay( &dia ); 251 QVBoxLayout lay( &dia );
247 lab.setText( mPrefs->mPassiveSyncPort ); 252 lab.setText( mPrefs->mPassiveSyncPort );
248 lay.setMargin(7); 253 lay.setMargin(7);
249 lay.setSpacing(7); 254 lay.setSpacing(7);
250 int po = 9197+mTargetApp; 255 int po = 9197+mTargetApp;
251 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 256 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
252 lay.addWidget( &label); 257 lay.addWidget( &label);
253 lay.addWidget( &lab); 258 lay.addWidget( &lab);
254 259
255 QLineEdit lepw ( &dia ); 260 QLineEdit lepw ( &dia );
256 lepw.setText( mPrefs->mPassiveSyncPw ); 261 lepw.setText( mPrefs->mPassiveSyncPw );
257 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 262 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
258 lay.addWidget( &label2); 263 lay.addWidget( &label2);
259 lay.addWidget( &lepw); 264 lay.addWidget( &lepw);
260 dia.setFixedSize( 230,80 ); 265 dia.setFixedSize( 230,80 );
261 dia.setCaption( i18n("Enter port for Pi-Sync") ); 266 dia.setCaption( i18n("Enter port for Pi-Sync") );
262 QPushButton pb ( "OK", &dia); 267 QPushButton pb ( "OK", &dia);
263 lay.addWidget( &pb ); 268 lay.addWidget( &pb );
264 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 269 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
265 dia.show(); 270 dia.show();
266 if ( ! dia.exec() ) 271 if ( ! dia.exec() )
267 return; 272 return;
268 dia.hide(); 273 dia.hide();
269 qApp->processEvents(); 274 qApp->processEvents();
270 mPrefs->mPassiveSyncPw = lepw.text(); 275 mPrefs->mPassiveSyncPw = lepw.text();
271 mPrefs->mPassiveSyncPort = lab.text(); 276 mPrefs->mPassiveSyncPort = lab.text();
272 bool ok; 277 bool ok;
273 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 278 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
274 if ( ! ok ) { 279 if ( ! ok ) {
275 KMessageBox::information( 0, i18n("No valid port")); 280 KMessageBox::information( 0, i18n("No valid port"));
276 return; 281 return;
277 } 282 }
278 //qDebug("port %d ", port); 283 //qDebug("port %d ", port);
279 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 284 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
280 mServerSocket->setFileName( defaultFileName() ); 285 mServerSocket->setFileName( defaultFileName() );
281 //qDebug("connected "); 286 //qDebug("connected ");
282 if ( !mServerSocket->ok() ) { 287 if ( !mServerSocket->ok() ) {
283 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 288 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
284 delete mServerSocket; 289 delete mServerSocket;
285 mServerSocket = 0; 290 mServerSocket = 0;
286 return; 291 return;
287 } 292 }
288 //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) );
289 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 293 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
290 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 294 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
291} 295}
292 296
293void KSyncManager::syncLocalFile() 297void KSyncManager::syncLocalFile()
294{ 298{
295 299
296 QString fn =mLastSyncedLocalFile; 300 QString fn =mPrefs->mLastSyncedLocalFile;
297 QString ext; 301 QString ext;
298 302
299 switch(mTargetApp) 303 switch(mTargetApp)
300 { 304 {
301 case (KAPI): 305 case (KAPI):
302 ext = "(*.vcf)"; 306 ext = "(*.vcf)";
303 break; 307 break;
304 case (KOPI): 308 case (KOPI):
305 ext = "(*.ics/*.vcs)"; 309 ext = "(*.ics/*.vcs)";
306 break; 310 break;
307 case (PWMPI): 311 case (PWMPI):
308 ext = "(*.pwm)"; 312 ext = "(*.pwm)";
309 break; 313 break;
310 default: 314 default:
311 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 315 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
312 break; 316 break;
313 317
314 } 318 }
315 319
316 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 320 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
317 if ( fn == "" ) 321 if ( fn == "" )
318 return; 322 return;
319 if ( syncWithFile( fn, false ) ) { 323 if ( syncWithFile( fn, false ) ) {
320 qDebug("syncLocalFile() successful "); 324 qDebug("syncLocalFile() successful ");
321 } 325 }
322 326
323} 327}
328
324bool KSyncManager::syncWithFile( QString fn , bool quick ) 329bool KSyncManager::syncWithFile( QString fn , bool quick )
325{ 330{
326 bool ret = false; 331 bool ret = false;
327 QFileInfo info; 332 QFileInfo info;
328 info.setFile( fn ); 333 info.setFile( fn );
329 QString mess; 334 QString mess;
330 bool loadbup = true; 335 bool loadbup = true;
331 if ( !info. exists() ) { 336 if ( !info. exists() ) {
332 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 337 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
333 int result = QMessageBox::warning( mParent, i18n("Warning!"), 338 int result = QMessageBox::warning( mParent, i18n("Warning!"),
334 mess ); 339 mess );
335 return ret; 340 return ret;
336 } 341 }
337 int result = 0; 342 int result = 0;
338 if ( !quick ) { 343 if ( !quick ) {
339 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 344 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
340 result = QMessageBox::warning( mParent, i18n("Warning!"), 345 result = QMessageBox::warning( mParent, i18n("Warning!"),
341 mess, 346 mess,
342 i18n("Sync"), i18n("Cancel"), 0, 347 i18n("Sync"), i18n("Cancel"), 0,
343 0, 1 ); 348 0, 1 );
344 if ( result ) 349 if ( result )
345 return false; 350 return false;
346 } 351 }
347 if ( mAskForPreferences ) 352 if ( mAskForPreferences )
348 edit_sync_options(); 353 edit_sync_options();
349 if ( result == 0 ) { 354 if ( result == 0 ) {
350 //qDebug("Now sycing ... "); 355 //qDebug("Now sycing ... ");
351 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 356 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
352 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 357 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
353 else 358 else
354 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 359 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
355 if ( ! quick ) 360 if ( ! quick )
356 mLastSyncedLocalFile = fn; 361 mPrefs->mLastSyncedLocalFile = fn;
357 } 362 }
358 return ret; 363 return ret;
359} 364}
365
360void KSyncManager::quickSyncLocalFile() 366void KSyncManager::quickSyncLocalFile()
361{ 367{
362 368
363 if ( syncWithFile( mLastSyncedLocalFile, false ) ) { 369 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, false ) ) {
364 qDebug("quick syncLocalFile() successful "); 370 qDebug("quick syncLocalFile() successful ");
365 371
366 } 372 }
367} 373}
374
368void KSyncManager::multiSync( bool askforPrefs ) 375void KSyncManager::multiSync( bool askforPrefs )
369{ 376{
370 if (blockSave()) 377 if (blockSave())
371 return; 378 return;
372 setBlockSave(true); 379 setBlockSave(true);
373 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 380 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
374 if ( QMessageBox::information( mParent, i18n("Sync"), 381 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
375 question, 382 question,
376 i18n("Yes"), i18n("No"), 383 i18n("Yes"), i18n("No"),
377 0, 0 ) != 0 ) { 384 0, 0 ) != 0 ) {
378 setBlockSave(false); 385 setBlockSave(false);
379 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 386 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
380 return; 387 return;
381 } 388 }
382 mCurrentSyncDevice = i18n("Multiple profiles") ; 389 mCurrentSyncDevice = i18n("Multiple profiles") ;
383 mSyncAlgoPrefs = mRingSyncAlgoPrefs; 390 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
384 if ( askforPrefs ) { 391 if ( askforPrefs ) {
385 edit_sync_options(); 392 edit_sync_options();
386 mRingSyncAlgoPrefs = mSyncAlgoPrefs; 393 mRingSyncAlgoPrefs = mSyncAlgoPrefs;
387 } 394 }
388 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 395 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
389 qApp->processEvents(); 396 qApp->processEvents();
390 int num = ringSync() ; 397 int num = ringSync() ;
391 if ( num > 1 ) 398 if ( num > 1 )
392 ringSync(); 399 ringSync();
393 setBlockSave(false); 400 setBlockSave(false);
394 if ( num ) 401 if ( num )
395 emit save(); 402 emit save();
396 if ( num ) 403 if ( num )
397 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 404 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
398 else 405 else
399 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 406 mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
400 return; 407 return;
401} 408}
409
402int KSyncManager::ringSync() 410int KSyncManager::ringSync()
403{ 411{
404 int syncedProfiles = 0; 412 int syncedProfiles = 0;
405 unsigned int i; 413 unsigned int i;
406 QTime timer; 414 QTime timer;
407 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 415 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
408 QStringList syncProfileNames = mSyncProfileNames; 416 QStringList syncProfileNames = mSyncProfileNames;
409 KSyncProfile* temp = new KSyncProfile (); 417 KSyncProfile* temp = new KSyncProfile ();
410 mAskForPreferences = false; 418 mAskForPreferences = false;
411 for ( i = 0; i < syncProfileNames.count(); ++i ) { 419 for ( i = 0; i < syncProfileNames.count(); ++i ) {
412 mCurrentSyncProfile = i; 420 mCurrentSyncProfile = i;
413 temp->setName(syncProfileNames[mCurrentSyncProfile]); 421 temp->setName(syncProfileNames[mCurrentSyncProfile]);
414 temp->readConfig(&config); 422 temp->readConfig(&config);
415 423
416 QString includeInRingSync; 424 QString includeInRingSync;
417 switch(mTargetApp) 425 switch(mTargetApp)
418 { 426 {
419 case (KAPI): 427 case (KAPI):
420 includeInRingSync = temp->getIncludeInRingSyncAB(); 428 includeInRingSync = temp->getIncludeInRingSyncAB();
421 break; 429 break;
422 case (KOPI): 430 case (KOPI):
423 includeInRingSync = temp->getIncludeInRingSync(); 431 includeInRingSync = temp->getIncludeInRingSync();
424 break; 432 break;
425 case (PWMPI): 433 case (PWMPI):
426 includeInRingSync = temp->getIncludeInRingSyncPWM(); 434 includeInRingSync = temp->getIncludeInRingSyncPWM();
427 break; 435 break;
428 default: 436 default:
429 qDebug("KSyncManager::ringSync: invalid apptype selected"); 437 qDebug("KSyncManager::ringSync: invalid apptype selected");
430 break; 438 break;
431 439
432 } 440 }
433 441
434 442
435 if ( includeInRingSync && ( i < 1 || i > 2 )) { 443 if ( includeInRingSync && ( i < 1 || i > 2 )) {
436 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 444 mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
437 ++syncedProfiles; 445 ++syncedProfiles;
438 // mAskForPreferences = temp->getAskForPreferences(); 446 // mAskForPreferences = temp->getAskForPreferences();
439 mWriteBackFile = temp->getWriteBackFile(); 447 mWriteBackFile = temp->getWriteBackFile();
440 mWriteBackExistingOnly = temp->getWriteBackExisting(); 448 mWriteBackExistingOnly = temp->getWriteBackExisting();
441 mWriteBackInFuture = 0; 449 mWriteBackInFuture = 0;
442 if ( temp->getWriteBackFuture() ) 450 if ( temp->getWriteBackFuture() )
443 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 451 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
444 mShowSyncSummary = false; 452 mShowSyncSummary = false;
445 mCurrentSyncDevice = syncProfileNames[i] ; 453 mCurrentSyncDevice = syncProfileNames[i] ;
446 mCurrentSyncName = mLocalMachineName; 454 mCurrentSyncName = mLocalMachineName;
447 if ( i == 0 ) { 455 if ( i == 0 ) {
448 syncSharp(); 456 syncSharp();
449 } else { 457 } else {
450 if ( temp->getIsLocalFileSync() ) { 458 if ( temp->getIsLocalFileSync() ) {
451 switch(mTargetApp) 459 switch(mTargetApp)
452 { 460 {
453 case (KAPI): 461 case (KAPI):
454 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 462 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
455 mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 463 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
456 break; 464 break;
457 case (KOPI): 465 case (KOPI):
458 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 466 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
459 mLastSyncedLocalFile = temp->getRemoteFileName(); 467 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
460 break; 468 break;
461 case (PWMPI): 469 case (PWMPI):
462 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 470 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
463 mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 471 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
464 break; 472 break;
465 default: 473 default:
466 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 474 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
467 break; 475 break;
468 } 476 }
469 } else { 477 } else {
470 if ( temp->getIsPhoneSync() ) { 478 if ( temp->getIsPhoneSync() ) {
471 mPhoneDevice = temp->getPhoneDevice( ) ; 479 mPhoneDevice = temp->getPhoneDevice( ) ;
472 mPhoneConnection = temp->getPhoneConnection( ); 480 mPhoneConnection = temp->getPhoneConnection( );
473 mPhoneModel = temp->getPhoneModel( ); 481 mPhoneModel = temp->getPhoneModel( );
474 syncPhone(); 482 syncPhone();
483 } else if ( temp->getIsPiSync() ) {
484 if ( mTargetApp == KAPI ) {
485 mPassWordPiSync = temp->getRemotePwAB();
486 mActiveSyncPort = temp->getRemotePortAB();
487 mActiveSyncIP = temp->getRemoteIPAB();
488 } else if ( mTargetApp == KOPI ) {
489 mPassWordPiSync = temp->getRemotePw();
490 mActiveSyncPort = temp->getRemotePort();
491 mActiveSyncIP = temp->getRemoteIP();
492 } else {
493 mPassWordPiSync = temp->getRemotePwPWM();
494 mActiveSyncPort = temp->getRemotePortPWM();
495 mActiveSyncIP = temp->getRemoteIPPWM();
496 }
497 syncPi();
475 } else 498 } else
476 syncRemote( temp, false ); 499 syncRemote( temp, false );
477 500
478 } 501 }
479 } 502 }
480 timer.start(); 503 timer.start();
481 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); 504 mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") );
482 while ( timer.elapsed () < 2000 ) { 505 while ( timer.elapsed () < 2000 ) {
483 qApp->processEvents(); 506 qApp->processEvents();
484#ifndef _WIN32_ 507#ifndef _WIN32_
485 sleep (1); 508 sleep (1);
486#endif 509#endif
487 } 510 }
488 511
489 } 512 }
490 513
491 } 514 }
492 delete temp; 515 delete temp;
493 return syncedProfiles; 516 return syncedProfiles;
494} 517}
495 518
496void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) 519void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
497{ 520{
498 QString question; 521 QString question;
499 if ( ask ) { 522 if ( ask ) {
500 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 523 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
501 if ( QMessageBox::information( mParent, i18n("Sync"), 524 if ( QMessageBox::information( mParent, i18n("Sync"),
502 question, 525 question,
503 i18n("Yes"), i18n("No"), 526 i18n("Yes"), i18n("No"),
504 0, 0 ) != 0 ) 527 0, 0 ) != 0 )
505 return; 528 return;
506 } 529 }
507 530
508 QString preCommand; 531 QString preCommand;
509 QString localTempFile; 532 QString localTempFile;
510 QString postCommand; 533 QString postCommand;
511 534
512 switch(mTargetApp) 535 switch(mTargetApp)
513 { 536 {
514 case (KAPI): 537 case (KAPI):
515 preCommand = prof->getPreSyncCommandAB(); 538 preCommand = prof->getPreSyncCommandAB();
516 postCommand = prof->getPostSyncCommandAB(); 539 postCommand = prof->getPostSyncCommandAB();
517 localTempFile = prof->getLocalTempFileAB(); 540 localTempFile = prof->getLocalTempFileAB();
518 break; 541 break;
519 case (KOPI): 542 case (KOPI):
520 preCommand = prof->getPreSyncCommand(); 543 preCommand = prof->getPreSyncCommand();
521 postCommand = prof->getPostSyncCommand(); 544 postCommand = prof->getPostSyncCommand();
522 localTempFile = prof->getLocalTempFile(); 545 localTempFile = prof->getLocalTempFile();
523 break; 546 break;
524 case (PWMPI): 547 case (PWMPI):
525 preCommand = prof->getPreSyncCommandPWM(); 548 preCommand = prof->getPreSyncCommandPWM();
526 postCommand = prof->getPostSyncCommandPWM(); 549 postCommand = prof->getPostSyncCommandPWM();
527 localTempFile = prof->getLocalTempFilePWM(); 550 localTempFile = prof->getLocalTempFilePWM();
528 break; 551 break;
529 default: 552 default:
530 qDebug("KSyncManager::syncRemote: invalid apptype selected"); 553 qDebug("KSyncManager::syncRemote: invalid apptype selected");
531 break; 554 break;
532 } 555 }
533 556
534 557
535 int fi; 558 int fi;
536 if ( (fi = preCommand.find("$PWD$")) > 0 ) { 559 if ( (fi = preCommand.find("$PWD$")) > 0 ) {
537 QString pwd = getPassword(); 560 QString pwd = getPassword();
538 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); 561 preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
539 562
540 } 563 }
541 int maxlen = 30; 564 int maxlen = 30;
542 if ( QApplication::desktop()->width() > 320 ) 565 if ( QApplication::desktop()->width() > 320 )
543 maxlen += 25; 566 maxlen += 25;
544 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); 567 mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) );
545 int fileSize = 0; 568 int fileSize = 0;
546 int result = system ( preCommand ); 569 int result = system ( preCommand );
547 // 0 : okay 570 // 0 : okay
548 // 256: no such file or dir 571 // 256: no such file or dir
549 // 572 //
550 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 573 qDebug("KO: Remote copy result(0 = okay): %d ",result );
551 if ( result != 0 ) { 574 if ( result != 0 ) {
552 unsigned int len = maxlen; 575 unsigned int len = maxlen;
553 while ( len < preCommand.length() ) { 576 while ( len < preCommand.length() ) {
554 preCommand.insert( len , "\n" ); 577 preCommand.insert( len , "\n" );
555 len += maxlen +2; 578 len += maxlen +2;
556 } 579 }
557 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 (preCommand) ; 580 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 (preCommand) ;
558 QMessageBox::information( mParent, i18n("Sync - ERROR"), 581 QMessageBox::information( mParent, i18n("Sync - ERROR"),
559 question, 582 question,
560 i18n("Okay!")) ; 583 i18n("Okay!")) ;
561 mParent->topLevelWidget()->setCaption (""); 584 mParent->topLevelWidget()->setCaption ("KDE-Pim");
562 return; 585 return;
563 } 586 }
564 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); 587 mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) );
565 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 588 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
566 589
567
568
569 if ( syncWithFile( localTempFile, true ) ) { 590 if ( syncWithFile( localTempFile, true ) ) {
570// Event* e = mView->getLastSyncEvent(); 591
571// e->setReadOnly( false );
572// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
573// e->setReadOnly( true );
574 if ( mWriteBackFile ) { 592 if ( mWriteBackFile ) {
575 int fi; 593 int fi;
576 if ( (fi = postCommand.find("$PWD$")) > 0 ) { 594 if ( (fi = postCommand.find("$PWD$")) > 0 ) {
577 QString pwd = getPassword(); 595 QString pwd = getPassword();
578 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); 596 postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
579 597
580 } 598 }
581 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); 599 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
582 result = system ( postCommand ); 600 result = system ( postCommand );
583 qDebug("Writing back file result: %d ", result); 601 qDebug("Writing back file result: %d ", result);
584 if ( result != 0 ) { 602 if ( result != 0 ) {
585 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 603 mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
586 return; 604 return;
587 } else { 605 } else {
588 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); 606 mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
589 } 607 }
590 } 608 }
591 } 609 }
592 return; 610 return;
593} 611}
594 612
595void KSyncManager::edit_sync_options() 613void KSyncManager::edit_sync_options()
596{ 614{
597 //mDialogManager->showSyncOptions(); 615 //mDialogManager->showSyncOptions();
598 //mSyncAlgoPrefs 616 //mSyncAlgoPrefs
599 QDialog dia( mParent, "dia", true ); 617 QDialog dia( mParent, "dia", true );
600 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 618 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
601 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 619 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
602 QVBoxLayout lay ( &dia ); 620 QVBoxLayout lay ( &dia );
603 lay.setSpacing( 2 ); 621 lay.setSpacing( 2 );
604 lay.setMargin( 3 ); 622 lay.setMargin( 3 );
605 lay.addWidget(&gr); 623 lay.addWidget(&gr);
606 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 624 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
607 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 625 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
608 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 626 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
609 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 627 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
610 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 628 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
611 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 629 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
612 //QRadioButton both( i18n("Take both on conflict"), &gr ); 630 //QRadioButton both( i18n("Take both on conflict"), &gr );
613 QPushButton pb ( "OK", &dia); 631 QPushButton pb ( "OK", &dia);
614 lay.addWidget( &pb ); 632 lay.addWidget( &pb );
615 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 633 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
616 switch ( mSyncAlgoPrefs ) { 634 switch ( mSyncAlgoPrefs ) {
617 case 0: 635 case 0:
618 loc.setChecked( true); 636 loc.setChecked( true);
619 break; 637 break;
620 case 1: 638 case 1:
621 rem.setChecked( true ); 639 rem.setChecked( true );
622 break; 640 break;
623 case 2: 641 case 2:
624 newest.setChecked( true); 642 newest.setChecked( true);
625 break; 643 break;
626 case 3: 644 case 3:
627 ask.setChecked( true); 645 ask.setChecked( true);
628 break; 646 break;
629 case 4: 647 case 4:
630 f_loc.setChecked( true); 648 f_loc.setChecked( true);
631 break; 649 break;
632 case 5: 650 case 5:
633 f_rem.setChecked( true); 651 f_rem.setChecked( true);
634 break; 652 break;
635 case 6: 653 case 6:
636 // both.setChecked( true); 654 // both.setChecked( true);
637 break; 655 break;
638 default: 656 default:
639 break; 657 break;
640 } 658 }
641 if ( dia.exec() ) { 659 if ( dia.exec() ) {
642 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 660 mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
643 } 661 }
644 662
645 663
646} 664}
665
647QString KSyncManager::getPassword( ) 666QString KSyncManager::getPassword( )
648{ 667{
649 QString retfile = ""; 668 QString retfile = "";
650 QDialog dia ( mParent, "input-dialog", true ); 669 QDialog dia ( mParent, "input-dialog", true );
651 QLineEdit lab ( &dia ); 670 QLineEdit lab ( &dia );
652 lab.setEchoMode( QLineEdit::Password ); 671 lab.setEchoMode( QLineEdit::Password );
653 QVBoxLayout lay( &dia ); 672 QVBoxLayout lay( &dia );
654 lay.setMargin(7); 673 lay.setMargin(7);
655 lay.setSpacing(7); 674 lay.setSpacing(7);
656 lay.addWidget( &lab); 675 lay.addWidget( &lab);
657 dia.setFixedSize( 230,50 ); 676 dia.setFixedSize( 230,50 );
658 dia.setCaption( i18n("Enter password") ); 677 dia.setCaption( i18n("Enter password") );
659 QPushButton pb ( "OK", &dia); 678 QPushButton pb ( "OK", &dia);
660 lay.addWidget( &pb ); 679 lay.addWidget( &pb );
661 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 680 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
662 dia.show(); 681 dia.show();
663 int res = dia.exec(); 682 int res = dia.exec();
664 if ( res ) 683 if ( res )
665 retfile = lab.text(); 684 retfile = lab.text();
666 dia.hide(); 685 dia.hide();
667 qApp->processEvents(); 686 qApp->processEvents();
668 return retfile; 687 return retfile;
669 688
670} 689}
671 690
672 691
673void KSyncManager::confSync() 692void KSyncManager::confSync()
674{ 693{
675 static KSyncPrefsDialog* sp = 0; 694 static KSyncPrefsDialog* sp = 0;
676 if ( ! sp ) { 695 if ( ! sp ) {
677 sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); 696 sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
678 } 697 }
679 sp->usrReadConfig(); 698 sp->usrReadConfig();
680#ifndef DESKTOP_VERSION 699#ifndef DESKTOP_VERSION
681 sp->showMaximized(); 700 sp->showMaximized();
682#else 701#else
683 sp->show(); 702 sp->show();
684#endif 703#endif
685 sp->exec(); 704 sp->exec();
686 mSyncProfileNames = sp->getSyncProfileNames(); 705 mSyncProfileNames = sp->getSyncProfileNames();
687 mLocalMachineName = sp->getLocalMachineName (); 706 mLocalMachineName = sp->getLocalMachineName ();
688 fillSyncMenu(); 707 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
689} 708}
690 709
691void KSyncManager::syncSharp() 710void KSyncManager::syncSharp()
692{ 711{
712
693 if ( ! syncExternalApplication("sharp") ) 713 if ( ! syncExternalApplication("sharp") )
694 qDebug("ERROR sync sharp ");; 714 qDebug("ERROR sync sharp ");;
695} 715}
696 716
697bool KSyncManager::syncExternalApplication(QString resource) 717bool KSyncManager::syncExternalApplication(QString resource)
698{ 718{
699 719
700 emit save(); 720 emit save();
701 721
702 if ( mAskForPreferences ) 722 if ( mAskForPreferences )
703 edit_sync_options(); 723 edit_sync_options();
704 724
705 qDebug("sync %s", resource.latin1()); 725 qDebug("sync %s", resource.latin1());
706 726
707 bool syncOK = mImplementation->syncExternal(this, resource); 727 bool syncOK = mImplementation->syncExternal(this, resource);
708 728
709 return syncOK; 729 return syncOK;
710 730
711} 731}
712 732
713void KSyncManager::syncPhone() 733void KSyncManager::syncPhone()
714{ 734{
715 emit save();
716 735
717 qDebug("pending syncPhone(); "); 736 syncExternalApplication("phone");
718 //mView->syncPhone();
719 737
720} 738}
721 739
722void KSyncManager::showProgressBar(int percentage, QString caption, int total) 740void KSyncManager::showProgressBar(int percentage, QString caption, int total)
723{ 741{
724 if (!bar->isVisible()) 742 if (!bar->isVisible())
725 { 743 {
726 bar->setCaption (caption); 744 bar->setCaption (caption);
727 bar->setTotalSteps ( total ) ; 745 bar->setTotalSteps ( total ) ;
728 746
729 bar->show(); 747 bar->show();
730 } 748 }
731 749
732 bar->setProgress( percentage ); 750 bar->setProgress( percentage );
733} 751}
734 752
735void KSyncManager::hideProgressBar() 753void KSyncManager::hideProgressBar()
736{ 754{
737 bar->hide(); 755 bar->hide();
738} 756}
739 757
740bool KSyncManager::isProgressBarCanceled() 758bool KSyncManager::isProgressBarCanceled()
741{ 759{
742 return !bar->isVisible(); 760 return !bar->isVisible();
743} 761}
744 762
745QString KSyncManager::syncFileName() 763QString KSyncManager::syncFileName()
746{ 764{
747 765
748 QString fn = "tempfile"; 766 QString fn = "tempfile";
749 switch(mTargetApp) 767 switch(mTargetApp)
750 { 768 {
751 case (KAPI): 769 case (KAPI):
752 fn = "tempsyncab.vcf"; 770 fn = "tempsyncab.vcf";
753 break; 771 break;
754 case (KOPI): 772 case (KOPI):
755 fn = "tempsynccal.ics"; 773 fn = "tempsynccal.ics";
756 break; 774 break;
757 case (PWMPI): 775 case (PWMPI):
758 fn = "tempsyncpw.pwm"; 776 fn = "tempsyncpw.pwm";
759 break; 777 break;
760 default: 778 default:
761 break; 779 break;
762 } 780 }
763#ifdef _WIN32_ 781#ifdef _WIN32_
764 return locateLocal( "tmp", fn ); 782 return locateLocal( "tmp", fn );
765#else 783#else
766 return (QString( "/tmp/" )+ fn ); 784 return (QString( "/tmp/" )+ fn );
767#endif 785#endif
768} 786}
769 787
788
770void KSyncManager::syncPi() 789void KSyncManager::syncPi()
771{ 790{
772 qApp->processEvents(); 791 qApp->processEvents();
773 bool ok; 792 bool ok;
774 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 793 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
775 if ( ! ok ) { 794 if ( ! ok ) {
776 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 795 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
777 return; 796 return;
778 } 797 }
779 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 798 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
780 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 799 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
781 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 800 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
782 commandSocket->readFile( syncFileName() ); 801 commandSocket->readFile( syncFileName() );
783} 802}
784 803
785void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 804void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
786{ 805{
787 qDebug("MainWindow::deleteCommandSocket %d", state); 806 qDebug("MainWindow::deleteCommandSocket %d", state);
788 807
789 //enum { success, errorW, errorR, quiet }; 808 //enum { success, errorW, errorR, quiet };
790 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 809 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
791 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 810 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
792 delete s; 811 delete s;
793 if ( state == KCommandSocket::errorR ) { 812 if ( state == KCommandSocket::errorR ) {
794 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 813 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
795 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 814 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
796 commandSocket->sendStop(); 815 commandSocket->sendStop();
797 } 816 }
798 return; 817 return;
799 818
800 } else if ( state == KCommandSocket::errorW ) { 819 } else if ( state == KCommandSocket::errorW ) {
801 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 820 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
802 821
803 } else if ( state == KCommandSocket::successR ) { 822 } else if ( state == KCommandSocket::successR ) {
804 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 823 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
805 824
806 } else if ( state == KCommandSocket::successW ) { 825 } else if ( state == KCommandSocket::successW ) {
807 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 826 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
808 } 827 }
809 828
810 delete s; 829 delete s;
811} 830}
812 831
813void KSyncManager::readFileFromSocket() 832void KSyncManager::readFileFromSocket()
814{ 833{
815 QString fileName = syncFileName(); 834 QString fileName = syncFileName();
816 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 835 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
817 if ( ! syncWithFile( fileName , true ) ) { 836 if ( ! syncWithFile( fileName , true ) ) {
818 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 837 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
819 qDebug("Syncing failed "); 838 qDebug("Syncing failed ");
820 return; 839 return;
821 } 840 }
822 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 841 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
823 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 842 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
824 if ( mWriteBackFile ) 843 if ( mWriteBackFile )
825 commandSocket->writeFile( fileName ); 844 commandSocket->writeFile( fileName );
826 else { 845 else {
827 commandSocket->sendStop(); 846 commandSocket->sendStop();
828 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 847 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
829 } 848 }
830} 849}
831 850
832KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 851KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
833{ 852{
834 mPassWord = pw; 853 mPassWord = pw;
835 mSocket = 0; 854 mSocket = 0;
836 mSyncActionDialog = 0; 855 mSyncActionDialog = 0;
837 blockRC = false; 856 blockRC = false;
838}; 857};
839 858
840void KServerSocket::newConnection ( int socket ) 859void KServerSocket::newConnection ( int socket )
841{ 860{
842 // qDebug("KServerSocket:New connection %d ", socket); 861 // qDebug("KServerSocket:New connection %d ", socket);
843 if ( mSocket ) { 862 if ( mSocket ) {
844 qDebug("KServerSocket::newConnection Socket deleted! "); 863 qDebug("KServerSocket::newConnection Socket deleted! ");
845 delete mSocket; 864 delete mSocket;
846 mSocket = 0; 865 mSocket = 0;
847 } 866 }
848 mSocket = new QSocket( this ); 867 mSocket = new QSocket( this );
849 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 868 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
850 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 869 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
851 mSocket->setSocket( socket ); 870 mSocket->setSocket( socket );
852} 871}
853 872
854void KServerSocket::discardClient() 873void KServerSocket::discardClient()
855{ 874{
856 //qDebug(" KServerSocket::discardClient()"); 875 //qDebug(" KServerSocket::discardClient()");
857 if ( mSocket ) { 876 if ( mSocket ) {
858 delete mSocket; 877 delete mSocket;
859 mSocket = 0; 878 mSocket = 0;
860 } 879 }
861 //emit endConnect(); 880 //emit endConnect();
862} 881}
863void KServerSocket::readClient() 882void KServerSocket::readClient()
864{ 883{
865 if ( blockRC ) 884 if ( blockRC )
@@ -1060,97 +1079,96 @@ void KCommandSocket::writeFileToSocket()
1060 QTextStream os2( mSocket ); 1079 QTextStream os2( mSocket );
1061 os2.setEncoding( QTextStream::Latin1 ); 1080 os2.setEncoding( QTextStream::Latin1 );
1062 os2 << "PUT " << mPassWord << "\r\n";; 1081 os2 << "PUT " << mPassWord << "\r\n";;
1063 while ( ! ts2.atEnd() ) { 1082 while ( ! ts2.atEnd() ) {
1064 os2 << ts2.readLine() << "\n"; 1083 os2 << ts2.readLine() << "\n";
1065 } 1084 }
1066 mRetVal= successW; 1085 mRetVal= successW;
1067 file2.close(); 1086 file2.close();
1068 mSocket->close(); 1087 mSocket->close();
1069 if ( mSocket->state() == QSocket::Idle ) 1088 if ( mSocket->state() == QSocket::Idle )
1070 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1089 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1071} 1090}
1072void KCommandSocket::sendStop() 1091void KCommandSocket::sendStop()
1073{ 1092{
1074 if ( !mSocket ) { 1093 if ( !mSocket ) {
1075 mSocket = new QSocket( this ); 1094 mSocket = new QSocket( this );
1076 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1095 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1077 } 1096 }
1078 mSocket->connectToHost( mHost, mPort ); 1097 mSocket->connectToHost( mHost, mPort );
1079 QTextStream os2( mSocket ); 1098 QTextStream os2( mSocket );
1080 os2.setEncoding( QTextStream::Latin1 ); 1099 os2.setEncoding( QTextStream::Latin1 );
1081 os2 << "STOP\r\n"; 1100 os2 << "STOP\r\n";
1082 mSocket->close(); 1101 mSocket->close();
1083 if ( mSocket->state() == QSocket::Idle ) 1102 if ( mSocket->state() == QSocket::Idle )
1084 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1103 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1085} 1104}
1086 1105
1087void KCommandSocket::startReadFileFromSocket() 1106void KCommandSocket::startReadFileFromSocket()
1088{ 1107{
1089 if ( ! mFirst ) 1108 if ( ! mFirst )
1090 return; 1109 return;
1091 mFirst = false; 1110 mFirst = false;
1092 mTimerSocket->stop(); 1111 mTimerSocket->stop();
1093 mFileString = ""; 1112 mFileString = "";
1094 mTime.start(); 1113 mTime.start();
1095 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1114 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1096 1115
1097} 1116}
1098void KCommandSocket::readFileFromSocket() 1117void KCommandSocket::readFileFromSocket()
1099{ 1118{
1100 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1119 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1101 while ( mSocket->canReadLine () ) { 1120 while ( mSocket->canReadLine () ) {
1102 mTime.restart(); 1121 mTime.restart();
1103 QString line = mSocket->readLine (); 1122 QString line = mSocket->readLine ();
1104 mFileString += line; 1123 mFileString += line;
1105 //qDebug("readline: %s ", line.latin1()); 1124 //qDebug("readline: %s ", line.latin1());
1106 } 1125 }
1107 if ( mTime.elapsed () < 3000 ) { 1126 if ( mTime.elapsed () < 3000 ) {
1108 // wait for more 1127 // wait for more
1109 //qDebug("waitformore "); 1128 //qDebug("waitformore ");
1110 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1129 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1111 return; 1130 return;
1112 } 1131 }
1113 QString fileName = mFileName; 1132 QString fileName = mFileName;
1114 QFile file ( fileName ); 1133 QFile file ( fileName );
1115 if (!file.open( IO_WriteOnly ) ) { 1134 if (!file.open( IO_WriteOnly ) ) {
1116 mFileString = ""; 1135 mFileString = "";
1117 mRetVal = errorR; 1136 mRetVal = errorR;
1118 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 1137 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
1119 deleteSocket(); 1138 deleteSocket();
1120 return ; 1139 return ;
1121 1140
1122 } 1141 }
1123 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1142 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1124 QTextStream ts ( &file ); 1143 QTextStream ts ( &file );
1125 ts.setEncoding( QTextStream::Latin1 ); 1144 ts.setEncoding( QTextStream::Latin1 );
1126 ts << mFileString; 1145 ts << mFileString;
1127 file.close(); 1146 file.close();
1128 mFileString = ""; 1147 mFileString = "";
1129 mRetVal = successR; 1148 mRetVal = successR;
1130 mSocket->close(); 1149 mSocket->close();
1131 // if state is not idle, deleteSocket(); is called via 1150 // if state is not idle, deleteSocket(); is called via
1132 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1151 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1133 if ( mSocket->state() == QSocket::Idle ) 1152 if ( mSocket->state() == QSocket::Idle )
1134 deleteSocket(); 1153 deleteSocket();
1135} 1154}
1136 1155
1137void KCommandSocket::deleteSocket() 1156void KCommandSocket::deleteSocket()
1138{ 1157{
1139 if ( mTimerSocket->isActive () ) { 1158 if ( mTimerSocket->isActive () ) {
1140 mTimerSocket->stop(); 1159 mTimerSocket->stop();
1141 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1160 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1142 mRetVal = errorTO; 1161 mRetVal = errorTO;
1143 if ( mSocket ) { 1162 if ( mSocket ) {
1144 mSocket->close(); 1163 mSocket->close();
1145 if ( mSocket->state() == QSocket::Idle ) 1164 if ( mSocket->state() == QSocket::Idle )
1146 deleteSocket(); 1165 deleteSocket();
1147 return; 1166 return;
1148 } 1167 }
1149 } 1168 }
1150 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1169 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1151 if ( mSocket) 1170 if ( mSocket)
1152 delete mSocket; 1171 delete mSocket;
1153 mSocket = 0; 1172 mSocket = 0;
1154 emit commandFinished( this, mRetVal ); 1173 emit commandFinished( this, mRetVal );
1155} 1174}
1156
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 25892d8..7027894 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -24,204 +24,203 @@ $Id$
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qsocket.h> 27#include <qsocket.h>
28#include <qdatetime.h> 28#include <qdatetime.h>
29#include <qserversocket.h> 29#include <qserversocket.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qregexp.h> 31#include <qregexp.h>
32 32
33class QPopupMenu; 33class QPopupMenu;
34class KSyncProfile; 34class KSyncProfile;
35class KPimPrefs; 35class KPimPrefs;
36class QWidget; 36class QWidget;
37class KSyncManager; 37class KSyncManager;
38class KSyncInterface; 38class KSyncInterface;
39class QProgressBar; 39class QProgressBar;
40 40
41 41
42class KServerSocket : public QServerSocket 42class KServerSocket : public QServerSocket
43{ 43{
44 Q_OBJECT 44 Q_OBJECT
45 45
46public: 46public:
47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
48 48
49 void newConnection ( int socket ) ; 49 void newConnection ( int socket ) ;
50 void setFileName( QString fn ) {mFileName = fn;}; 50 void setFileName( QString fn ) {mFileName = fn;};
51 51
52signals: 52signals:
53 void file_received( bool ); 53 void file_received( bool );
54 void request_file(); 54 void request_file();
55 void saveFile(); 55 void saveFile();
56 void endConnect(); 56 void endConnect();
57private slots: 57private slots:
58 void discardClient(); 58 void discardClient();
59 void readClient(); 59 void readClient();
60 void readBackFileFromSocket(); 60 void readBackFileFromSocket();
61 private : 61 private :
62 bool blockRC; 62 bool blockRC;
63 void send_file(); 63 void send_file();
64 void get_file(); 64 void get_file();
65 void end_connect(); 65 void end_connect();
66 QDialog* mSyncActionDialog; 66 QDialog* mSyncActionDialog;
67 QSocket* mSocket; 67 QSocket* mSocket;
68 QString mPassWord; 68 QString mPassWord;
69 QString mFileName; 69 QString mFileName;
70 QTime piTime; 70 QTime piTime;
71 QString piFileString; 71 QString piFileString;
72}; 72};
73 73
74class KCommandSocket : public QObject 74class KCommandSocket : public QObject
75{ 75{
76 Q_OBJECT 76 Q_OBJECT
77public: 77public:
78 enum state { successR, errorR, successW, errorW, errorTO, quiet }; 78 enum state { successR, errorR, successW, errorW, errorTO, quiet };
79 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 79 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
80 void readFile( QString ); 80 void readFile( QString );
81 void writeFile( QString ); 81 void writeFile( QString );
82 void sendStop(); 82 void sendStop();
83 83
84 84
85signals: 85signals:
86 void commandFinished( KCommandSocket*, int ); 86 void commandFinished( KCommandSocket*, int );
87private slots: 87private slots:
88 void startReadFileFromSocket(); 88 void startReadFileFromSocket();
89 void readFileFromSocket(); 89 void readFileFromSocket();
90 void deleteSocket(); 90 void deleteSocket();
91 void writeFileToSocket(); 91 void writeFileToSocket();
92 private : 92 private :
93 QSocket* mSocket; 93 QSocket* mSocket;
94 QString mPassWord; 94 QString mPassWord;
95 Q_UINT16 mPort; 95 Q_UINT16 mPort;
96 QString mHost; 96 QString mHost;
97 QString mFileName; 97 QString mFileName;
98 QTimer* mTimerSocket; 98 QTimer* mTimerSocket;
99 int mRetVal; 99 int mRetVal;
100 QTime mTime; 100 QTime mTime;
101 QString mFileString; 101 QString mFileString;
102 bool mFirst; 102 bool mFirst;
103}; 103};
104 104
105 105
106class KSyncManager : public QObject 106class KSyncManager : public QObject
107{ 107{
108 Q_OBJECT 108 Q_OBJECT
109 109
110 public: 110 public:
111 enum TargetApp { 111 enum TargetApp {
112 KOPI = 0, 112 KOPI = 0,
113 KAPI = 1, 113 KAPI = 1,
114 PWMPI = 2 }; 114 PWMPI = 2 };
115 115
116 116
117 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 117 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
118 ~KSyncManager() ; 118 ~KSyncManager() ;
119 119
120 void multiSync( bool askforPrefs );
120 bool blockSave() { return mBlockSaveFlag; } 121 bool blockSave() { return mBlockSaveFlag; }
121 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 122 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
122 void setDefaultFileName( QString s) { mDefFileName = s ;} 123 void setDefaultFileName( QString s) { mDefFileName = s ;}
123 QString defaultFileName() { return mDefFileName ;} 124 QString defaultFileName() { return mDefFileName ;}
124 QString syncFileName(); 125 QString syncFileName();
125 void fillSyncMenu(); 126 void fillSyncMenu();
126 127
127 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 128 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
128 QString getCurrentSyncName() { return mCurrentSyncName; } 129 QString getCurrentSyncName() { return mCurrentSyncName; }
129 130
130 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 131 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
131 void hideProgressBar(); 132 void hideProgressBar();
132 bool isProgressBarCanceled(); 133 bool isProgressBarCanceled();
133 134
134 // sync stuff 135 // sync stuff
135 QString mLocalMachineName; 136 QString mLocalMachineName;
136 QStringList mExternSyncProfiles; 137 QStringList mExternSyncProfiles;
137 QStringList mSyncProfileNames; 138 QStringList mSyncProfileNames;
138 bool mAskForPreferences; 139 bool mAskForPreferences;
139 bool mShowSyncSummary; 140 bool mShowSyncSummary;
140 bool mShowSyncEvents; 141 bool mShowSyncEvents;
141 bool mShowTodoInAgenda; 142 bool mShowTodoInAgenda;
142 bool mWriteBackExistingOnly; 143 bool mWriteBackExistingOnly;
143 int mSyncAlgoPrefs; 144 int mSyncAlgoPrefs;
144 int mRingSyncAlgoPrefs; 145 int mRingSyncAlgoPrefs;
145 bool mWriteBackFile; 146 bool mWriteBackFile;
146 int mWriteBackInFuture; 147 int mWriteBackInFuture;
147 QString mPhoneDevice; 148 QString mPhoneDevice;
148 QString mPhoneConnection; 149 QString mPhoneConnection;
149 QString mPhoneModel; 150 QString mPhoneModel;
150 QString mLastSyncedLocalFile; // save!
151 QString mPassWordPiSync; 151 QString mPassWordPiSync;
152 QString mActiveSyncPort; 152 QString mActiveSyncPort;
153 QString mActiveSyncIP ; 153 QString mActiveSyncIP ;
154 154
155 signals: 155 signals:
156 void save(); 156 void save();
157 void request_file(); 157 void request_file();
158 void getFile( bool ); 158 void getFile( bool );
159 159
160 public slots: 160 public slots:
161 void slotSyncMenu( int ); 161 void slotSyncMenu( int );
162 void deleteCommandSocket(KCommandSocket*s, int state); 162 void deleteCommandSocket(KCommandSocket*s, int state);
163 void readFileFromSocket(); 163 void readFileFromSocket();
164 164
165 private: 165 private:
166 // LR ******************************* 166 // LR *******************************
167 // sync stuff! 167 // sync stuff!
168 void syncPi(); 168 void syncPi();
169 KServerSocket * mServerSocket; 169 KServerSocket * mServerSocket;
170 void enableQuick(); 170 void enableQuick();
171 KPimPrefs* mPrefs; 171 KPimPrefs* mPrefs;
172 QString mDefFileName; 172 QString mDefFileName;
173 QString mCurrentSyncDevice; 173 QString mCurrentSyncDevice;
174 QString mCurrentSyncName; 174 QString mCurrentSyncName;
175 void quickSyncLocalFile(); 175 void quickSyncLocalFile();
176 bool syncWithFile( QString fn , bool quick ); 176 bool syncWithFile( QString fn , bool quick );
177 void syncLocalFile(); 177 void syncLocalFile();
178 void syncPhone(); 178 void syncPhone();
179 void syncSharp(); 179 void syncSharp();
180 bool syncExternalApplication(QString); 180 bool syncExternalApplication(QString);
181 void multiSync( bool askforPrefs );
182 int mCurrentSyncProfile ; 181 int mCurrentSyncProfile ;
183 void syncRemote( KSyncProfile* prof, bool ask = true); 182 void syncRemote( KSyncProfile* prof, bool ask = true);
184 void edit_sync_options(); 183 void edit_sync_options();
185 int ringSync(); 184 int ringSync();
186 QString getPassword( ); 185 QString getPassword( );
187 186
188 private slots: 187 private slots:
189 void confSync(); 188 void confSync();
190 // ********************* 189 // *********************
191 190
192 private: 191 private:
193 bool mBlockSaveFlag; 192 bool mBlockSaveFlag;
194 193
195 194
196 QWidget* mParent; 195 QWidget* mParent;
197 KSyncInterface* mImplementation; 196 KSyncInterface* mImplementation;
198 TargetApp mTargetApp; 197 TargetApp mTargetApp;
199 QPopupMenu* mSyncMenu; 198 QPopupMenu* mSyncMenu;
200 199
201 QProgressBar* bar; 200 QProgressBar* bar;
202 201
203 202
204 203
205 204
206 205
207}; 206};
208 207
209 208
210class KSyncInterface 209class KSyncInterface
211{ 210{
212 211
213 212
214 public : 213 public :
215 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 214 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
216 215
217 virtual bool syncExternal(KSyncManager* manager, QString resource) 216 virtual bool syncExternal(KSyncManager* manager, QString resource)
218 { 217 {
219 // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. 218 // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager.
220 return false; 219 return false;
221 } 220 }
222 221
223 222
224}; 223};
225 224
226 225
227#endif 226#endif