summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-26 22:56:24 (UTC)
committer zautrix <zautrix>2004-10-26 22:56:24 (UTC)
commit00d623c9391a9bdaeb142f443f1dd09861317608 (patch) (unidiff)
tree941b77a6da7a5db84ed9f4c00ab18918231cb643
parent6385f303bef3cbcd19d097a7b05c30e144d5dd6e (diff)
downloadkdepimpi-00d623c9391a9bdaeb142f443f1dd09861317608.zip
kdepimpi-00d623c9391a9bdaeb142f443f1dd09861317608.tar.gz
kdepimpi-00d623c9391a9bdaeb142f443f1dd09861317608.tar.bz2
added external time for pisync - kdesync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp11
-rw-r--r--libkdepim/ksyncmanager.cpp16
-rw-r--r--libkdepim/ksyncmanager.h1
3 files changed, 24 insertions, 4 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a08f243..326db88 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -833,195 +833,202 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
833 result = getEventViewerDialog()->executeS( localIsNew ); 833 result = getEventViewerDialog()->executeS( localIsNew );
834 return result; 834 return result;
835 835
836 break; 836 break;
837 case SYNC_PREF_FORCE_LOCAL: 837 case SYNC_PREF_FORCE_LOCAL:
838 return 1; 838 return 1;
839 break; 839 break;
840 case SYNC_PREF_FORCE_REMOTE: 840 case SYNC_PREF_FORCE_REMOTE:
841 return 2; 841 return 2;
842 break; 842 break;
843 843
844 default: 844 default:
845 // SYNC_PREF_TAKE_BOTH not implemented 845 // SYNC_PREF_TAKE_BOTH not implemented
846 break; 846 break;
847 } 847 }
848 return 0; 848 return 0;
849} 849}
850Event* CalendarView::getLastSyncEvent() 850Event* CalendarView::getLastSyncEvent()
851{ 851{
852 Event* lse; 852 Event* lse;
853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 853 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 854 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
855 if (!lse) { 855 if (!lse) {
856 lse = new Event(); 856 lse = new Event();
857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 857 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
858 QString sum = ""; 858 QString sum = "";
859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 859 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
860 sum = "E: "; 860 sum = "E: ";
861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 861 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
862 lse->setDtStart( mLastCalendarSync ); 862 lse->setDtStart( mLastCalendarSync );
863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 863 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
864 lse->setCategories( i18n("SyncEvent") ); 864 lse->setCategories( i18n("SyncEvent") );
865 lse->setReadOnly( true ); 865 lse->setReadOnly( true );
866 mCalendar->addEvent( lse ); 866 mCalendar->addEvent( lse );
867 } 867 }
868 868
869 return lse; 869 return lse;
870 870
871} 871}
872 872
873// we check, if the to delete event has a id for a profile 873// we check, if the to delete event has a id for a profile
874// if yes, we set this id in the profile to delete 874// if yes, we set this id in the profile to delete
875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 875void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
876{ 876{
877 if ( lastSync.count() == 0 ) { 877 if ( lastSync.count() == 0 ) {
878 //qDebug(" lastSync.count() == 0"); 878 //qDebug(" lastSync.count() == 0");
879 return; 879 return;
880 } 880 }
881 if ( toDelete->type() == "Journal" ) 881 if ( toDelete->type() == "Journal" )
882 return; 882 return;
883 883
884 Event* eve = lastSync.first(); 884 Event* eve = lastSync.first();
885 885
886 while ( eve ) { 886 while ( eve ) {
887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 887 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
888 if ( !id.isEmpty() ) { 888 if ( !id.isEmpty() ) {
889 QString des = eve->description(); 889 QString des = eve->description();
890 QString pref = "e"; 890 QString pref = "e";
891 if ( toDelete->type() == "Todo" ) 891 if ( toDelete->type() == "Todo" )
892 pref = "t"; 892 pref = "t";
893 des += pref+ id + ","; 893 des += pref+ id + ",";
894 eve->setReadOnly( false ); 894 eve->setReadOnly( false );
895 eve->setDescription( des ); 895 eve->setDescription( des );
896 //qDebug("setdes %s ", des.latin1()); 896 //qDebug("setdes %s ", des.latin1());
897 eve->setReadOnly( true ); 897 eve->setReadOnly( true );
898 } 898 }
899 eve = lastSync.next(); 899 eve = lastSync.next();
900 } 900 }
901 901
902} 902}
903void CalendarView::checkExternalId( Incidence * inc ) 903void CalendarView::checkExternalId( Incidence * inc )
904{ 904{
905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 905 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
906 checkExternSyncEvent( lastSync, inc ); 906 checkExternSyncEvent( lastSync, inc );
907 907
908} 908}
909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 909bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
910{ 910{
911 bool syncOK = true; 911 bool syncOK = true;
912 int addedEvent = 0; 912 int addedEvent = 0;
913 int addedEventR = 0; 913 int addedEventR = 0;
914 int deletedEventR = 0; 914 int deletedEventR = 0;
915 int deletedEventL = 0; 915 int deletedEventL = 0;
916 int changedLocal = 0; 916 int changedLocal = 0;
917 int changedRemote = 0; 917 int changedRemote = 0;
918 //QPtrList<Event> el = local->rawEvents(); 918 //QPtrList<Event> el = local->rawEvents();
919 Event* eventR; 919 Event* eventR;
920 QString uid; 920 QString uid;
921 int take; 921 int take;
922 Event* eventL; 922 Event* eventL;
923 Event* eventRSync; 923 Event* eventRSync;
924 Event* eventLSync; 924 Event* eventLSync;
925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 925 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 926 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
927 bool fullDateRange = false; 927 bool fullDateRange = false;
928 local->resetTempSyncStat(); 928 local->resetTempSyncStat();
929 if ( mSyncKDE )
930 remote->resetPilotStat(1);
931 mLastCalendarSync = QDateTime::currentDateTime(); 929 mLastCalendarSync = QDateTime::currentDateTime();
930 if ( mSyncKDE ) {
931 remote->resetPilotStat(1);
932 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
933 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
934 qDebug("using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
935 } else {
936 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime ");
937 }
938 }
932 QDateTime modifiedCalendar = mLastCalendarSync;; 939 QDateTime modifiedCalendar = mLastCalendarSync;;
933 eventLSync = getLastSyncEvent(); 940 eventLSync = getLastSyncEvent();
934 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 941 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
935 if ( eventR ) { 942 if ( eventR ) {
936 eventRSync = (Event*) eventR->clone(); 943 eventRSync = (Event*) eventR->clone();
937 remote->deleteEvent(eventR ); 944 remote->deleteEvent(eventR );
938 945
939 } else { 946 } else {
940 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) { 947 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncKDE) {
941 eventRSync = (Event*)eventLSync->clone(); 948 eventRSync = (Event*)eventLSync->clone();
942 } else { 949 } else {
943 fullDateRange = true; 950 fullDateRange = true;
944 eventRSync = new Event(); 951 eventRSync = new Event();
945 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 952 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
946 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 953 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
947 eventRSync->setDtStart( mLastCalendarSync ); 954 eventRSync->setDtStart( mLastCalendarSync );
948 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 955 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
949 eventRSync->setCategories( i18n("SyncEvent") ); 956 eventRSync->setCategories( i18n("SyncEvent") );
950 } 957 }
951 } 958 }
952 if ( eventLSync->dtStart() == mLastCalendarSync ) 959 if ( eventLSync->dtStart() == mLastCalendarSync )
953 fullDateRange = true; 960 fullDateRange = true;
954 961
955 if ( ! fullDateRange ) { 962 if ( ! fullDateRange ) {
956 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 963 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
957 964
958 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 965 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
959 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 966 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
960 fullDateRange = true; 967 fullDateRange = true;
961 } 968 }
962 } 969 }
963 if ( mSyncKDE ) { 970 if ( mSyncKDE ) {
964 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync ); 971 fullDateRange = ( eventLSync->dtStart() == mLastCalendarSync );
965 } 972 }
966 if ( fullDateRange ) 973 if ( fullDateRange )
967 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 974 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
968 else 975 else
969 mLastCalendarSync = eventLSync->dtStart(); 976 mLastCalendarSync = eventLSync->dtStart();
970 // for resyncing if own file has changed 977 // for resyncing if own file has changed
971 if ( mCurrentSyncDevice == "deleteaftersync" ) { 978 if ( mCurrentSyncDevice == "deleteaftersync" ) {
972 mLastCalendarSync = loadedFileVersion; 979 mLastCalendarSync = loadedFileVersion;
973 //qDebug("setting mLastCalendarSync "); 980 //qDebug("setting mLastCalendarSync ");
974 } 981 }
975 //qDebug("*************************** "); 982 //qDebug("*************************** ");
976 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 983 qDebug("mLastCalendarSync %s full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
977 QPtrList<Incidence> er = remote->rawIncidences(); 984 QPtrList<Incidence> er = remote->rawIncidences();
978 Incidence* inR = er.first(); 985 Incidence* inR = er.first();
979 Incidence* inL; 986 Incidence* inL;
980 QProgressBar bar( er.count(),0 ); 987 QProgressBar bar( er.count(),0 );
981 bar.setCaption (i18n("Syncing - close to abort!") ); 988 bar.setCaption (i18n("Syncing - close to abort!") );
982 989
983 int w = 300; 990 int w = 300;
984 if ( QApplication::desktop()->width() < 320 ) 991 if ( QApplication::desktop()->width() < 320 )
985 w = 220; 992 w = 220;
986 int h = bar.sizeHint().height() ; 993 int h = bar.sizeHint().height() ;
987 int dw = QApplication::desktop()->width(); 994 int dw = QApplication::desktop()->width();
988 int dh = QApplication::desktop()->height(); 995 int dh = QApplication::desktop()->height();
989 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 996 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
990 bar.show(); 997 bar.show();
991 int modulo = (er.count()/10)+1; 998 int modulo = (er.count()/10)+1;
992 int incCounter = 0; 999 int incCounter = 0;
993 while ( inR ) { 1000 while ( inR ) {
994 if ( ! bar.isVisible() ) 1001 if ( ! bar.isVisible() )
995 return false; 1002 return false;
996 if ( incCounter % modulo == 0 ) 1003 if ( incCounter % modulo == 0 )
997 bar.setProgress( incCounter ); 1004 bar.setProgress( incCounter );
998 ++incCounter; 1005 ++incCounter;
999 uid = inR->uid(); 1006 uid = inR->uid();
1000 bool skipIncidence = false; 1007 bool skipIncidence = false;
1001 if ( uid.left(15) == QString("last-syncEvent-") ) 1008 if ( uid.left(15) == QString("last-syncEvent-") )
1002 skipIncidence = true; 1009 skipIncidence = true;
1003 QString idS; 1010 QString idS;
1004 qApp->processEvents(); 1011 qApp->processEvents();
1005 if ( !skipIncidence ) { 1012 if ( !skipIncidence ) {
1006 inL = local->incidence( uid ); 1013 inL = local->incidence( uid );
1007 if ( inL ) { // maybe conflict - same uid in both calendars 1014 if ( inL ) { // maybe conflict - same uid in both calendars
1008 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1015 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1009 //qDebug("take %d %s ", take, inL->summary().latin1()); 1016 //qDebug("take %d %s ", take, inL->summary().latin1());
1010 if ( take == 3 ) 1017 if ( take == 3 )
1011 return false; 1018 return false;
1012 if ( take == 1 ) {// take local 1019 if ( take == 1 ) {// take local
1013 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1020 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1014 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1021 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1015 else 1022 else
1016 idS = inR->IDStr(); 1023 idS = inR->IDStr();
1017 remote->deleteIncidence( inR ); 1024 remote->deleteIncidence( inR );
1018 inR = inL->clone(); 1025 inR = inL->clone();
1019 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1026 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1020 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1027 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1021 inR->setIDStr( idS ); 1028 inR->setIDStr( idS );
1022 remote->addIncidence( inR ); 1029 remote->addIncidence( inR );
1023 if ( mSyncKDE ) 1030 if ( mSyncKDE )
1024 inR->setPilotId( 2 ); 1031 inR->setPilotId( 2 );
1025 ++changedRemote; 1032 ++changedRemote;
1026 } else { 1033 } else {
1027 idS = inL->IDStr(); 1034 idS = inL->IDStr();
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index feb184b..e09050e 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,153 +1,156 @@
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#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58QDateTime KSyncManager::mRequestedSyncEvent;
59
60
58KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
59 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) 62 : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
60{ 63{
61 mServerSocket = 0; 64 mServerSocket = 0;
62 bar = new QProgressBar ( 1, 0 ); 65 bar = new QProgressBar ( 1, 0 );
63 bar->setCaption (""); 66 bar->setCaption ("");
64 67
65 int w = 300; 68 int w = 300;
66 if ( QApplication::desktop()->width() < 320 ) 69 if ( QApplication::desktop()->width() < 320 )
67 w = 220; 70 w = 220;
68 int h = bar->sizeHint().height() ; 71 int h = bar->sizeHint().height() ;
69 int dw = QApplication::desktop()->width(); 72 int dw = QApplication::desktop()->width();
70 int dh = QApplication::desktop()->height(); 73 int dh = QApplication::desktop()->height();
71 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 74 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
72 if ( mPrefs->mPassiveSyncAutoStart ) 75 if ( mPrefs->mPassiveSyncAutoStart )
73 enableQuick( false ); 76 enableQuick( false );
74 77
75} 78}
76 79
77KSyncManager::~KSyncManager() 80KSyncManager::~KSyncManager()
78{ 81{
79 delete bar; 82 delete bar;
80} 83}
81 84
82 85
83void KSyncManager::fillSyncMenu() 86void KSyncManager::fillSyncMenu()
84{ 87{
85 if ( mSyncMenu->count() ) 88 if ( mSyncMenu->count() )
86 mSyncMenu->clear(); 89 mSyncMenu->clear();
87 90
88 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 91 mSyncMenu->insertItem( i18n("Configure..."), 0 );
89 mSyncMenu->insertSeparator(); 92 mSyncMenu->insertSeparator();
90 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
91 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
92 clearMenu->insertItem( i18n("For all profiles"), 1 ); 95 clearMenu->insertItem( i18n("For all profiles"), 1 );
93 clearMenu->insertSeparator(); 96 clearMenu->insertSeparator();
94 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
95 mSyncMenu->insertSeparator(); 98 mSyncMenu->insertSeparator();
96 if ( mServerSocket == 0 ) { 99 if ( mServerSocket == 0 ) {
97 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
98 } else { 101 } else {
99 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
100 } 103 }
101 mSyncMenu->insertSeparator(); 104 mSyncMenu->insertSeparator();
102 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
103 mSyncMenu->insertSeparator(); 106 mSyncMenu->insertSeparator();
104 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
105 config.setGroup("General"); 108 config.setGroup("General");
106 QStringList prof = config.readListEntry("SyncProfileNames"); 109 QStringList prof = config.readListEntry("SyncProfileNames");
107 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 110 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
108 if ( prof.count() < 2 ) { 111 if ( prof.count() < 2 ) {
109 prof.clear(); 112 prof.clear();
110 QString externalName; 113 QString externalName;
111#ifdef DESKTOP_VERSION 114#ifdef DESKTOP_VERSION
112#ifdef _WIN32_ 115#ifdef _WIN32_
113 externalName = "OutLook(not_implemented)"; 116 externalName = "OutLook(not_implemented)";
114#else 117#else
115 externalName = "KDE_Desktop"; 118 externalName = "KDE_Desktop";
116#endif 119#endif
117#else 120#else
118 externalName = "Sharp_DTM"; 121 externalName = "Sharp_DTM";
119#endif 122#endif
120 prof << externalName; 123 prof << externalName;
121 prof << i18n("Local_file"); 124 prof << i18n("Local_file");
122 prof << i18n("Last_file"); 125 prof << i18n("Last_file");
123 KSyncProfile* temp = new KSyncProfile (); 126 KSyncProfile* temp = new KSyncProfile ();
124 temp->setName( prof[0] ); 127 temp->setName( prof[0] );
125 temp->writeConfig(&config); 128 temp->writeConfig(&config);
126 temp->setName( prof[1] ); 129 temp->setName( prof[1] );
127 temp->writeConfig(&config); 130 temp->writeConfig(&config);
128 temp->setName( prof[2] ); 131 temp->setName( prof[2] );
129 temp->writeConfig(&config); 132 temp->writeConfig(&config);
130 config.setGroup("General"); 133 config.setGroup("General");
131 config.writeEntry("SyncProfileNames",prof); 134 config.writeEntry("SyncProfileNames",prof);
132 config.writeEntry("ExternSyncProfiles",externalName); 135 config.writeEntry("ExternSyncProfiles",externalName);
133 config.sync(); 136 config.sync();
134 delete temp; 137 delete temp;
135 } 138 }
136 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
137 mSyncProfileNames = prof; 140 mSyncProfileNames = prof;
138 unsigned int i; 141 unsigned int i;
139 for ( i = 0; i < prof.count(); ++i ) { 142 for ( i = 0; i < prof.count(); ++i ) {
140 mSyncMenu->insertItem( prof[i], 1000+i ); 143 mSyncMenu->insertItem( prof[i], 1000+i );
141 clearMenu->insertItem( prof[i], 1000+i ); 144 clearMenu->insertItem( prof[i], 1000+i );
142 if ( i == 2 ) 145 if ( i == 2 )
143 mSyncMenu->insertSeparator(); 146 mSyncMenu->insertSeparator();
144 } 147 }
145 QDir app_dir; 148 QDir app_dir;
146 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
147 if ( mTargetApp == PWMPI) { 150 if ( mTargetApp == PWMPI) {
148 mSyncMenu->removeItem( 1000 ); 151 mSyncMenu->removeItem( 1000 );
149 clearMenu->removeItem( 1000 ); 152 clearMenu->removeItem( 1000 );
150 } 153 }
151#ifndef DESKTOP_VERSION 154#ifndef DESKTOP_VERSION
152 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
153 mSyncMenu->removeItem( 1000 ); 156 mSyncMenu->removeItem( 1000 );
@@ -1018,349 +1021,358 @@ void KSyncManager::syncPi()
1018} 1021}
1019 1022
1020void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1023void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1021{ 1024{
1022 //enum { success, errorW, errorR, quiet }; 1025 //enum { success, errorW, errorR, quiet };
1023 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1026 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1024 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1027 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1025 delete s; 1028 delete s;
1026 if ( state == KCommandSocket::errorR ) { 1029 if ( state == KCommandSocket::errorR ) {
1027 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1030 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1028 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1031 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1029 commandSocket->sendStop(); 1032 commandSocket->sendStop();
1030 } 1033 }
1031 mPisyncFinished = true; 1034 mPisyncFinished = true;
1032 return; 1035 return;
1033 1036
1034 } else if ( state == KCommandSocket::errorW ) { 1037 } else if ( state == KCommandSocket::errorW ) {
1035 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1038 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1036 mPisyncFinished = true; 1039 mPisyncFinished = true;
1037 1040
1038 } else if ( state == KCommandSocket::successR ) { 1041 } else if ( state == KCommandSocket::successR ) {
1039 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1042 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1040 1043
1041 } else if ( state == KCommandSocket::successW ) { 1044 } else if ( state == KCommandSocket::successW ) {
1042 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1045 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1043 mPisyncFinished = true; 1046 mPisyncFinished = true;
1044 } 1047 }
1045 1048
1046 delete s; 1049 delete s;
1047} 1050}
1048 1051
1049void KSyncManager::readFileFromSocket() 1052void KSyncManager::readFileFromSocket()
1050{ 1053{
1051 QString fileName = syncFileName(); 1054 QString fileName = syncFileName();
1052 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1055 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1053 if ( ! syncWithFile( fileName , true ) ) { 1056 if ( ! syncWithFile( fileName , true ) ) {
1054 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1057 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1055 mPisyncFinished = true; 1058 mPisyncFinished = true;
1056 return; 1059 return;
1057 } 1060 }
1058 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1061 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1059 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1062 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1060 if ( mWriteBackFile ) 1063 if ( mWriteBackFile )
1061 commandSocket->writeFile( fileName ); 1064 commandSocket->writeFile( fileName );
1062 else { 1065 else {
1063 commandSocket->sendStop(); 1066 commandSocket->sendStop();
1064 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1067 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1065 mPisyncFinished = true; 1068 mPisyncFinished = true;
1066 } 1069 }
1067} 1070}
1068 1071
1069KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1072KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1070{ 1073{
1071 mPassWord = pw; 1074 mPassWord = pw;
1072 mSocket = 0; 1075 mSocket = 0;
1073 mSyncActionDialog = 0; 1076 mSyncActionDialog = 0;
1074 blockRC = false; 1077 blockRC = false;
1075}; 1078};
1076 1079
1077void KServerSocket::newConnection ( int socket ) 1080void KServerSocket::newConnection ( int socket )
1078{ 1081{
1079 // qDebug("KServerSocket:New connection %d ", socket); 1082 // qDebug("KServerSocket:New connection %d ", socket);
1080 if ( mSocket ) { 1083 if ( mSocket ) {
1081 qDebug("KServerSocket::newConnection Socket deleted! "); 1084 qDebug("KServerSocket::newConnection Socket deleted! ");
1082 delete mSocket; 1085 delete mSocket;
1083 mSocket = 0; 1086 mSocket = 0;
1084 } 1087 }
1085 mSocket = new QSocket( this ); 1088 mSocket = new QSocket( this );
1086 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1089 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1087 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1090 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1088 mSocket->setSocket( socket ); 1091 mSocket->setSocket( socket );
1089} 1092}
1090 1093
1091void KServerSocket::discardClient() 1094void KServerSocket::discardClient()
1092{ 1095{
1093 //qDebug(" KServerSocket::discardClient()"); 1096 //qDebug(" KServerSocket::discardClient()");
1094 if ( mSocket ) { 1097 if ( mSocket ) {
1095 delete mSocket; 1098 delete mSocket;
1096 mSocket = 0; 1099 mSocket = 0;
1097 } 1100 }
1098 //emit endConnect(); 1101 //emit endConnect();
1099} 1102}
1100void KServerSocket::readClient() 1103void KServerSocket::readClient()
1101{ 1104{
1102 if ( blockRC ) 1105 if ( blockRC )
1103 return; 1106 return;
1104 if ( mSocket == 0 ) { 1107 if ( mSocket == 0 ) {
1105 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1108 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1106 return; 1109 return;
1107 } 1110 }
1108 //qDebug("KServerSocket::readClient()"); 1111 //qDebug("KServerSocket::readClient()");
1109 if ( mSocket->canReadLine() ) { 1112 if ( mSocket->canReadLine() ) {
1110 QString line = mSocket->readLine(); 1113 QString line = mSocket->readLine();
1111 //qDebug("KServerSocket readline: %s ", line.latin1()); 1114 //qDebug("KServerSocket readline: %s ", line.latin1());
1112 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1115 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1113 if ( tokens[0] == "GET" ) { 1116 if ( tokens[0] == "GET" ) {
1114 if ( tokens[1] == mPassWord ) 1117 if ( tokens[1] == mPassWord ) {
1115 //emit sendFile( mSocket ); 1118 //emit sendFile( mSocket );
1119 bool ok = false;
1120 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1121 if ( ok )
1122 KSyncManager::mRequestedSyncEvent = dt;
1123 else
1124 KSyncManager::mRequestedSyncEvent = QDateTime();
1116 send_file(); 1125 send_file();
1126 }
1117 else { 1127 else {
1118 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1128 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1119 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1129 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1120 } 1130 }
1121 } 1131 }
1122 if ( tokens[0] == "PUT" ) { 1132 if ( tokens[0] == "PUT" ) {
1123 if ( tokens[1] == mPassWord ) { 1133 if ( tokens[1] == mPassWord ) {
1124 //emit getFile( mSocket ); 1134 //emit getFile( mSocket );
1125 blockRC = true; 1135 blockRC = true;
1126 get_file(); 1136 get_file();
1127 } 1137 }
1128 else { 1138 else {
1129 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1139 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1130 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1140 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1131 } 1141 }
1132 } 1142 }
1133 if ( tokens[0] == "STOP" ) { 1143 if ( tokens[0] == "STOP" ) {
1134 //emit endConnect(); 1144 //emit endConnect();
1135 end_connect(); 1145 end_connect();
1136 } 1146 }
1137 } 1147 }
1138} 1148}
1139void KServerSocket::end_connect() 1149void KServerSocket::end_connect()
1140{ 1150{
1141 delete mSyncActionDialog; 1151 delete mSyncActionDialog;
1142 mSyncActionDialog = 0; 1152 mSyncActionDialog = 0;
1143} 1153}
1144void KServerSocket::send_file() 1154void KServerSocket::send_file()
1145{ 1155{
1146 //qDebug("MainWindow::sendFile(QSocket* s) "); 1156 //qDebug("MainWindow::sendFile(QSocket* s) ");
1147 if ( mSyncActionDialog ) 1157 if ( mSyncActionDialog )
1148 delete mSyncActionDialog; 1158 delete mSyncActionDialog;
1149 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1159 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1150 mSyncActionDialog->setCaption(i18n("Received sync request")); 1160 mSyncActionDialog->setCaption(i18n("Received sync request"));
1151 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1161 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1152 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1162 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1153 lay->addWidget( label); 1163 lay->addWidget( label);
1154 lay->setMargin(7); 1164 lay->setMargin(7);
1155 lay->setSpacing(7); 1165 lay->setSpacing(7);
1156 mSyncActionDialog->setFixedSize( 230, 120); 1166 mSyncActionDialog->setFixedSize( 230, 120);
1157 mSyncActionDialog->show(); 1167 mSyncActionDialog->show();
1158 mSyncActionDialog->raise(); 1168 mSyncActionDialog->raise();
1159 emit request_file(); 1169 emit request_file();
1160 qApp->processEvents(); 1170 qApp->processEvents();
1161 QString fileName = mFileName; 1171 QString fileName = mFileName;
1162 QFile file( fileName ); 1172 QFile file( fileName );
1163 if (!file.open( IO_ReadOnly ) ) { 1173 if (!file.open( IO_ReadOnly ) ) {
1164 delete mSyncActionDialog; 1174 delete mSyncActionDialog;
1165 mSyncActionDialog = 0; 1175 mSyncActionDialog = 0;
1166 qDebug("KSS::error open file "); 1176 qDebug("KSS::error open file ");
1167 mSocket->close(); 1177 mSocket->close();
1168 if ( mSocket->state() == QSocket::Idle ) 1178 if ( mSocket->state() == QSocket::Idle )
1169 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1179 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1170 return ; 1180 return ;
1171 1181
1172 } 1182 }
1173 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1183 mSyncActionDialog->setCaption( i18n("Sending file...") );
1174 QTextStream ts( &file ); 1184 QTextStream ts( &file );
1175 ts.setEncoding( QTextStream::Latin1 ); 1185 ts.setEncoding( QTextStream::Latin1 );
1176 1186
1177 QTextStream os( mSocket ); 1187 QTextStream os( mSocket );
1178 os.setEncoding( QTextStream::Latin1 ); 1188 os.setEncoding( QTextStream::Latin1 );
1179 while ( ! ts.atEnd() ) { 1189 while ( ! ts.atEnd() ) {
1180 os << ts.readLine() << "\r\n"; 1190 os << ts.readLine() << "\r\n";
1181 } 1191 }
1182 //os << ts.read(); 1192 //os << ts.read();
1183 file.close(); 1193 file.close();
1184 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1194 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1185 mSocket->close(); 1195 mSocket->close();
1186 if ( mSocket->state() == QSocket::Idle ) 1196 if ( mSocket->state() == QSocket::Idle )
1187 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1197 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1188} 1198}
1189void KServerSocket::get_file() 1199void KServerSocket::get_file()
1190{ 1200{
1191 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1201 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1192 1202
1193 piTime.start(); 1203 piTime.start();
1194 piFileString = ""; 1204 piFileString = "";
1195 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1205 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1196} 1206}
1197 1207
1198 1208
1199void KServerSocket::readBackFileFromSocket() 1209void KServerSocket::readBackFileFromSocket()
1200{ 1210{
1201 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1211 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1202 while ( mSocket->canReadLine () ) { 1212 while ( mSocket->canReadLine () ) {
1203 piTime.restart(); 1213 piTime.restart();
1204 QString line = mSocket->readLine (); 1214 QString line = mSocket->readLine ();
1205 piFileString += line; 1215 piFileString += line;
1206 //qDebug("readline: %s ", line.latin1()); 1216 //qDebug("readline: %s ", line.latin1());
1207 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1217 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1208 1218
1209 } 1219 }
1210 if ( piTime.elapsed () < 3000 ) { 1220 if ( piTime.elapsed () < 3000 ) {
1211 // wait for more 1221 // wait for more
1212 //qDebug("waitformore "); 1222 //qDebug("waitformore ");
1213 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1223 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1214 return; 1224 return;
1215 } 1225 }
1216 QString fileName = mFileName; 1226 QString fileName = mFileName;
1217 QFile file ( fileName ); 1227 QFile file ( fileName );
1218 if (!file.open( IO_WriteOnly ) ) { 1228 if (!file.open( IO_WriteOnly ) ) {
1219 delete mSyncActionDialog; 1229 delete mSyncActionDialog;
1220 mSyncActionDialog = 0; 1230 mSyncActionDialog = 0;
1221 qDebug("KSS:Error open read back file "); 1231 qDebug("KSS:Error open read back file ");
1222 piFileString = ""; 1232 piFileString = "";
1223 emit file_received( false ); 1233 emit file_received( false );
1224 blockRC = false; 1234 blockRC = false;
1225 return ; 1235 return ;
1226 1236
1227 } 1237 }
1228 1238
1229 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1239 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1230 QTextStream ts ( &file ); 1240 QTextStream ts ( &file );
1231 ts.setEncoding( QTextStream::Latin1 ); 1241 ts.setEncoding( QTextStream::Latin1 );
1232 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1242 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1233 ts << piFileString; 1243 ts << piFileString;
1234 mSocket->close(); 1244 mSocket->close();
1235 if ( mSocket->state() == QSocket::Idle ) 1245 if ( mSocket->state() == QSocket::Idle )
1236 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1246 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1237 file.close(); 1247 file.close();
1238 piFileString = ""; 1248 piFileString = "";
1239 emit file_received( true ); 1249 emit file_received( true );
1240 delete mSyncActionDialog; 1250 delete mSyncActionDialog;
1241 mSyncActionDialog = 0; 1251 mSyncActionDialog = 0;
1242 blockRC = false; 1252 blockRC = false;
1243 1253
1244} 1254}
1245 1255
1246KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1256KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1247{ 1257{
1248 mPassWord = password; 1258 mPassWord = password;
1249 mSocket = 0; 1259 mSocket = 0;
1250 mPort = port; 1260 mPort = port;
1251 mHost = host; 1261 mHost = host;
1252 1262
1253 mRetVal = quiet; 1263 mRetVal = quiet;
1254 mTimerSocket = new QTimer ( this ); 1264 mTimerSocket = new QTimer ( this );
1255 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1265 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1256} 1266}
1257void KCommandSocket::readFile( QString fn ) 1267void KCommandSocket::readFile( QString fn )
1258{ 1268{
1259 if ( !mSocket ) { 1269 if ( !mSocket ) {
1260 mSocket = new QSocket( this ); 1270 mSocket = new QSocket( this );
1261 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1271 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1262 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1272 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1263 } 1273 }
1264 mFileString = ""; 1274 mFileString = "";
1265 mFileName = fn; 1275 mFileName = fn;
1266 mFirst = true; 1276 mFirst = true;
1267 mSocket->connectToHost( mHost, mPort ); 1277 mSocket->connectToHost( mHost, mPort );
1268 QTextStream os( mSocket ); 1278 QTextStream os( mSocket );
1269 os.setEncoding( QTextStream::Latin1 ); 1279 os.setEncoding( QTextStream::Latin1 );
1270 os << "GET " << mPassWord << "\r\n"; 1280
1281 QString curDt = KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1282 os << "GET " << mPassWord << curDt <<"\r\n";
1271 mTimerSocket->start( 20000 ); 1283 mTimerSocket->start( 20000 );
1272} 1284}
1273 1285
1274void KCommandSocket::writeFile( QString fileName ) 1286void KCommandSocket::writeFile( QString fileName )
1275{ 1287{
1276 if ( !mSocket ) { 1288 if ( !mSocket ) {
1277 mSocket = new QSocket( this ); 1289 mSocket = new QSocket( this );
1278 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1290 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1279 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1291 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1280 } 1292 }
1281 mFileName = fileName ; 1293 mFileName = fileName ;
1282 mSocket->connectToHost( mHost, mPort ); 1294 mSocket->connectToHost( mHost, mPort );
1283} 1295}
1284void KCommandSocket::writeFileToSocket() 1296void KCommandSocket::writeFileToSocket()
1285{ 1297{
1286 QFile file2( mFileName ); 1298 QFile file2( mFileName );
1287 if (!file2.open( IO_ReadOnly ) ) { 1299 if (!file2.open( IO_ReadOnly ) ) {
1288 mRetVal= errorW; 1300 mRetVal= errorW;
1289 mSocket->close(); 1301 mSocket->close();
1290 if ( mSocket->state() == QSocket::Idle ) 1302 if ( mSocket->state() == QSocket::Idle )
1291 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1303 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1292 return ; 1304 return ;
1293 } 1305 }
1294 QTextStream ts2( &file2 ); 1306 QTextStream ts2( &file2 );
1295 ts2.setEncoding( QTextStream::Latin1 ); 1307 ts2.setEncoding( QTextStream::Latin1 );
1296 QTextStream os2( mSocket ); 1308 QTextStream os2( mSocket );
1297 os2.setEncoding( QTextStream::Latin1 ); 1309 os2.setEncoding( QTextStream::Latin1 );
1298 os2 << "PUT " << mPassWord << "\r\n";; 1310 os2 << "PUT " << mPassWord << "\r\n";;
1299 while ( ! ts2.atEnd() ) { 1311 while ( ! ts2.atEnd() ) {
1300 os2 << ts2.readLine() << "\r\n"; 1312 os2 << ts2.readLine() << "\r\n";
1301 } 1313 }
1302 mRetVal= successW; 1314 mRetVal= successW;
1303 file2.close(); 1315 file2.close();
1304 mSocket->close(); 1316 mSocket->close();
1305 if ( mSocket->state() == QSocket::Idle ) 1317 if ( mSocket->state() == QSocket::Idle )
1306 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1318 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1307} 1319}
1308void KCommandSocket::sendStop() 1320void KCommandSocket::sendStop()
1309{ 1321{
1310 if ( !mSocket ) { 1322 if ( !mSocket ) {
1311 mSocket = new QSocket( this ); 1323 mSocket = new QSocket( this );
1312 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1324 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1313 } 1325 }
1314 mSocket->connectToHost( mHost, mPort ); 1326 mSocket->connectToHost( mHost, mPort );
1315 QTextStream os2( mSocket ); 1327 QTextStream os2( mSocket );
1316 os2.setEncoding( QTextStream::Latin1 ); 1328 os2.setEncoding( QTextStream::Latin1 );
1317 os2 << "STOP\r\n"; 1329 os2 << "STOP\r\n";
1318 mSocket->close(); 1330 mSocket->close();
1319 if ( mSocket->state() == QSocket::Idle ) 1331 if ( mSocket->state() == QSocket::Idle )
1320 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1332 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1321} 1333}
1322 1334
1323void KCommandSocket::startReadFileFromSocket() 1335void KCommandSocket::startReadFileFromSocket()
1324{ 1336{
1325 if ( ! mFirst ) 1337 if ( ! mFirst )
1326 return; 1338 return;
1327 mFirst = false; 1339 mFirst = false;
1328 mTimerSocket->stop(); 1340 mTimerSocket->stop();
1329 mFileString = ""; 1341 mFileString = "";
1330 mTime.start(); 1342 mTime.start();
1331 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1343 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1332 1344
1333} 1345}
1334void KCommandSocket::readFileFromSocket() 1346void KCommandSocket::readFileFromSocket()
1335{ 1347{
1336 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1348 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1337 while ( mSocket->canReadLine () ) { 1349 while ( mSocket->canReadLine () ) {
1338 mTime.restart(); 1350 mTime.restart();
1339 QString line = mSocket->readLine (); 1351 QString line = mSocket->readLine ();
1340 mFileString += line; 1352 mFileString += line;
1341 //qDebug("readline: %s ", line.latin1()); 1353 //qDebug("readline: %s ", line.latin1());
1342 } 1354 }
1343 if ( mTime.elapsed () < 3000 ) { 1355 if ( mTime.elapsed () < 3000 ) {
1344 // wait for more 1356 // wait for more
1345 //qDebug("waitformore "); 1357 //qDebug("waitformore ");
1346 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1358 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1347 return; 1359 return;
1348 } 1360 }
1349 QString fileName = mFileName; 1361 QString fileName = mFileName;
1350 QFile file ( fileName ); 1362 QFile file ( fileName );
1351 if (!file.open( IO_WriteOnly ) ) { 1363 if (!file.open( IO_WriteOnly ) ) {
1352 mFileString = ""; 1364 mFileString = "";
1353 mRetVal = errorR; 1365 mRetVal = errorR;
1354 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1366 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1355 deleteSocket(); 1367 deleteSocket();
1356 return ; 1368 return ;
1357 1369
1358 } 1370 }
1359 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1371 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1360 QTextStream ts ( &file ); 1372 QTextStream ts ( &file );
1361 ts.setEncoding( QTextStream::Latin1 ); 1373 ts.setEncoding( QTextStream::Latin1 );
1362 ts << mFileString; 1374 ts << mFileString;
1363 file.close(); 1375 file.close();
1364 mFileString = ""; 1376 mFileString = "";
1365 mRetVal = successR; 1377 mRetVal = successR;
1366 mSocket->close(); 1378 mSocket->close();
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index aa32e28..2af891b 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -53,161 +53,162 @@ class KServerSocket : public QServerSocket
53 void request_file(); 53 void request_file();
54 void saveFile(); 54 void saveFile();
55 void endConnect(); 55 void endConnect();
56 private slots: 56 private slots:
57 void discardClient(); 57 void discardClient();
58 void readClient(); 58 void readClient();
59 void readBackFileFromSocket(); 59 void readBackFileFromSocket();
60 private : 60 private :
61 bool blockRC; 61 bool blockRC;
62 void send_file(); 62 void send_file();
63 void get_file(); 63 void get_file();
64 void end_connect(); 64 void end_connect();
65 QDialog* mSyncActionDialog; 65 QDialog* mSyncActionDialog;
66 QSocket* mSocket; 66 QSocket* mSocket;
67 QString mPassWord; 67 QString mPassWord;
68 QString mFileName; 68 QString mFileName;
69 QTime piTime; 69 QTime piTime;
70 QString piFileString; 70 QString piFileString;
71}; 71};
72 72
73class KCommandSocket : public QObject 73class KCommandSocket : public QObject
74{ 74{
75 Q_OBJECT 75 Q_OBJECT
76 public: 76 public:
77 enum state { successR, errorR, successW, errorW, errorTO, quiet }; 77 enum state { successR, errorR, successW, errorW, errorTO, quiet };
78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 78 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
79 void readFile( QString ); 79 void readFile( QString );
80 void writeFile( QString ); 80 void writeFile( QString );
81 void sendStop(); 81 void sendStop();
82 82
83 signals: 83 signals:
84 void commandFinished( KCommandSocket*, int ); 84 void commandFinished( KCommandSocket*, int );
85 private slots: 85 private slots:
86 void startReadFileFromSocket(); 86 void startReadFileFromSocket();
87 void readFileFromSocket(); 87 void readFileFromSocket();
88 void deleteSocket(); 88 void deleteSocket();
89 void writeFileToSocket(); 89 void writeFileToSocket();
90 private : 90 private :
91 QSocket* mSocket; 91 QSocket* mSocket;
92 QString mPassWord; 92 QString mPassWord;
93 Q_UINT16 mPort; 93 Q_UINT16 mPort;
94 QString mHost; 94 QString mHost;
95 QString mFileName; 95 QString mFileName;
96 QTimer* mTimerSocket; 96 QTimer* mTimerSocket;
97 int mRetVal; 97 int mRetVal;
98 QTime mTime; 98 QTime mTime;
99 QString mFileString; 99 QString mFileString;
100 bool mFirst; 100 bool mFirst;
101}; 101};
102 102
103 103
104class KSyncManager : public QObject 104class KSyncManager : public QObject
105{ 105{
106 Q_OBJECT 106 Q_OBJECT
107 107
108 public: 108 public:
109 enum TargetApp { 109 enum TargetApp {
110 KOPI = 0, 110 KOPI = 0,
111 KAPI = 1, 111 KAPI = 1,
112 PWMPI = 2 }; 112 PWMPI = 2 };
113 113
114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); 114 KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu);
115 ~KSyncManager() ; 115 ~KSyncManager() ;
116 116
117 void multiSync( bool askforPrefs ); 117 void multiSync( bool askforPrefs );
118 bool blockSave() { return mBlockSaveFlag; } 118 bool blockSave() { return mBlockSaveFlag; }
119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; } 119 void setBlockSave(bool sa) { mBlockSaveFlag = sa; }
120 void setDefaultFileName( QString s) { mDefFileName = s ;} 120 void setDefaultFileName( QString s) { mDefFileName = s ;}
121 QString defaultFileName() { return mDefFileName ;} 121 QString defaultFileName() { return mDefFileName ;}
122 QString syncFileName(); 122 QString syncFileName();
123 void enableQuick( bool ask = true); 123 void enableQuick( bool ask = true);
124 124
125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; } 125 QString getCurrentSyncDevice() { return mCurrentSyncDevice; }
126 QString getCurrentSyncName() { return mCurrentSyncName; } 126 QString getCurrentSyncName() { return mCurrentSyncName; }
127 127
128 void showProgressBar(int percentage, QString caption = QString::null, int total=100); 128 void showProgressBar(int percentage, QString caption = QString::null, int total=100);
129 void hideProgressBar(); 129 void hideProgressBar();
130 bool isProgressBarCanceled(); 130 bool isProgressBarCanceled();
131 131
132 // sync stuff 132 // sync stuff
133 QString mLocalMachineName; 133 QString mLocalMachineName;
134 QStringList mExternSyncProfiles; 134 QStringList mExternSyncProfiles;
135 QStringList mSyncProfileNames; 135 QStringList mSyncProfileNames;
136 bool mAskForPreferences; 136 bool mAskForPreferences;
137 bool mShowSyncSummary; 137 bool mShowSyncSummary;
138 bool mIsKapiFile; 138 bool mIsKapiFile;
139 bool mWriteBackExistingOnly; 139 bool mWriteBackExistingOnly;
140 int mSyncAlgoPrefs; 140 int mSyncAlgoPrefs;
141 bool mWriteBackFile; 141 bool mWriteBackFile;
142 int mWriteBackInFuture; 142 int mWriteBackInFuture;
143 QString mPhoneDevice; 143 QString mPhoneDevice;
144 QString mPhoneConnection; 144 QString mPhoneConnection;
145 QString mPhoneModel; 145 QString mPhoneModel;
146 QString mPassWordPiSync; 146 QString mPassWordPiSync;
147 QString mActiveSyncPort; 147 QString mActiveSyncPort;
148 QString mActiveSyncIP ; 148 QString mActiveSyncIP ;
149 static QDateTime mRequestedSyncEvent;
149 150
150 signals: 151 signals:
151 void save(); 152 void save();
152 void request_file(); 153 void request_file();
153 void getFile( bool ); 154 void getFile( bool );
154 155
155 public slots: 156 public slots:
156 void slotSyncMenu( int ); 157 void slotSyncMenu( int );
157 void slotClearMenu( int action ); 158 void slotClearMenu( int action );
158 void deleteCommandSocket(KCommandSocket*s, int state); 159 void deleteCommandSocket(KCommandSocket*s, int state);
159 void readFileFromSocket(); 160 void readFileFromSocket();
160 void fillSyncMenu(); 161 void fillSyncMenu();
161 162
162 private: 163 private:
163 void syncPi(); 164 void syncPi();
164 KServerSocket * mServerSocket; 165 KServerSocket * mServerSocket;
165 KPimPrefs* mPrefs; 166 KPimPrefs* mPrefs;
166 QString mDefFileName; 167 QString mDefFileName;
167 QString mCurrentSyncDevice; 168 QString mCurrentSyncDevice;
168 QString mCurrentSyncName; 169 QString mCurrentSyncName;
169 void quickSyncLocalFile(); 170 void quickSyncLocalFile();
170 bool syncWithFile( QString fn , bool quick ); 171 bool syncWithFile( QString fn , bool quick );
171 void syncLocalFile(); 172 void syncLocalFile();
172 void syncPhone(); 173 void syncPhone();
173 void syncSharp(); 174 void syncSharp();
174 void syncKDE(); 175 void syncKDE();
175 bool syncExternalApplication(QString); 176 bool syncExternalApplication(QString);
176 int mCurrentSyncProfile ; 177 int mCurrentSyncProfile ;
177 void syncRemote( KSyncProfile* prof, bool ask = true); 178 void syncRemote( KSyncProfile* prof, bool ask = true);
178 bool edit_sync_options(); 179 bool edit_sync_options();
179 bool edit_pisync_options(); 180 bool edit_pisync_options();
180 int ringSync(); 181 int ringSync();
181 QString getPassword( ); 182 QString getPassword( );
182 bool mPisyncFinished; 183 bool mPisyncFinished;
183 bool mBlockSaveFlag; 184 bool mBlockSaveFlag;
184 QWidget* mParent; 185 QWidget* mParent;
185 KSyncInterface* mImplementation; 186 KSyncInterface* mImplementation;
186 TargetApp mTargetApp; 187 TargetApp mTargetApp;
187 QPopupMenu* mSyncMenu; 188 QPopupMenu* mSyncMenu;
188 QProgressBar* bar; 189 QProgressBar* bar;
189 190
190private slots: 191private slots:
191 void confSync(); 192 void confSync();
192 193
193 194
194}; 195};
195 196
196 197
197class KSyncInterface 198class KSyncInterface
198{ 199{
199 public : 200 public :
200 virtual void removeSyncInfo( QString syncProfile) = 0; 201 virtual void removeSyncInfo( QString syncProfile) = 0;
201 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; 202 virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0;
202 virtual bool syncExternal(KSyncManager* manager, QString resource) 203 virtual bool syncExternal(KSyncManager* manager, QString resource)
203 { 204 {
204 // empty implementation, because some syncable applications do not 205 // empty implementation, because some syncable applications do not
205 // have an external(sharpdtm) syncmode, like pwmanager. 206 // have an external(sharpdtm) syncmode, like pwmanager.
206 return false; 207 return false;
207 } 208 }
208 209
209 210
210}; 211};
211 212
212 213
213#endif 214#endif