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