summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp236
-rw-r--r--korganizer/mainwindow.h13
2 files changed, 78 insertions, 171 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index da73caf..bce2a54 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -53,50 +53,48 @@
53#include "kfiledialog.h" 53#include "kfiledialog.h"
54#include "koglobals.h" 54#include "koglobals.h"
55#include "kglobal.h" 55#include "kglobal.h"
56#include "klocale.h" 56#include "klocale.h"
57#include "kconfig.h" 57#include "kconfig.h"
58#include "simplealarmclient.h" 58#include "simplealarmclient.h"
59#include "externalapphandler.h" 59#include "externalapphandler.h"
60 60
61using namespace KCal; 61using namespace KCal;
62#ifndef _WIN32_ 62#ifndef _WIN32_
63#include <unistd.h> 63#include <unistd.h>
64#else 64#else
65#include "koimportoldialog.h" 65#include "koimportoldialog.h"
66#endif 66#endif
67#include "mainwindow.h" 67#include "mainwindow.h"
68 68
69int globalFlagBlockStartup; 69int globalFlagBlockStartup;
70MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : 70MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
71 QMainWindow( parent, name ) 71 QMainWindow( parent, name )
72{ 72{
73 mPassWordPiSync = "abc"; 73 mPassWordPiSync = "abc";
74#ifdef DESKTOP_VERSION 74#ifdef DESKTOP_VERSION
75 setFont( QFont("Arial"), 14 ); 75 setFont( QFont("Arial"), 14 );
76#endif 76#endif
77 mCommandSocket = 0;
78 mCommandSocketFinish = 0;
79 mSyncActionDialog = 0; 77 mSyncActionDialog = 0;
80 mServerSocket = 0; 78 mServerSocket = 0;
81 mClosed = false; 79 mClosed = false;
82 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc"; 80 //QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
83 QString confFile = locateLocal("config","korganizerrc"); 81 QString confFile = locateLocal("config","korganizerrc");
84 QFileInfo finf ( confFile ); 82 QFileInfo finf ( confFile );
85 bool showWarning = !finf.exists(); 83 bool showWarning = !finf.exists();
86 setIcon(SmallIcon( "ko24" ) ); 84 setIcon(SmallIcon( "ko24" ) );
87 mBlockAtStartup = true; 85 mBlockAtStartup = true;
88 mFlagKeyPressed = false; 86 mFlagKeyPressed = false;
89 setCaption("KOrganizer/Pi"); 87 setCaption("KOrganizer/Pi");
90 KOPrefs *p = KOPrefs::instance(); 88 KOPrefs *p = KOPrefs::instance();
91 KPimGlobalPrefs::instance()->setGlobalConfig(); 89 KPimGlobalPrefs::instance()->setGlobalConfig();
92 // if ( QApplication::desktop()->height() > 480 ) { 90 // if ( QApplication::desktop()->height() > 480 ) {
93// if ( p->mHourSize == 4 ) 91// if ( p->mHourSize == 4 )
94// p->mHourSize = 6; 92// p->mHourSize = 6;
95// } 93// }
96 if ( p->mHourSize > 18 ) 94 if ( p->mHourSize > 18 )
97 p->mHourSize = 18; 95 p->mHourSize = 18;
98 QMainWindow::ToolBarDock tbd; 96 QMainWindow::ToolBarDock tbd;
99 if ( p->mToolBarHor ) { 97 if ( p->mToolBarHor ) {
100 if ( p->mToolBarUp ) 98 if ( p->mToolBarUp )
101 tbd = Bottom; 99 tbd = Bottom;
102 else 100 else
@@ -1921,166 +1919,63 @@ void MainWindow::enableQuick()
1921 passWordPiSync = lepw.text(); 1919 passWordPiSync = lepw.text();
1922 qApp->processEvents(); 1920 qApp->processEvents();
1923 KOPrefs::instance()->mPassiveSyncPort = retfile; 1921 KOPrefs::instance()->mPassiveSyncPort = retfile;
1924 bool ok; 1922 bool ok;
1925 Q_UINT16 port = retfile.toUInt(&ok); 1923 Q_UINT16 port = retfile.toUInt(&ok);
1926 if ( ! ok ) { 1924 if ( ! ok ) {
1927 KMessageBox::information( this, i18n("No valid port")); 1925 KMessageBox::information( this, i18n("No valid port"));
1928 return; 1926 return;
1929 } 1927 }
1930 qDebug("port %d ", port); 1928 qDebug("port %d ", port);
1931 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); 1929 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 );
1932 mServerSocket->setFileName( defaultFileName() ); 1930 mServerSocket->setFileName( defaultFileName() );
1933 qDebug("connected "); 1931 qDebug("connected ");
1934 if ( !mServerSocket->ok() ) { 1932 if ( !mServerSocket->ok() ) {
1935 qWarning("Failed to bind to port %d", port); 1933 qWarning("Failed to bind to port %d", port);
1936 delete mServerSocket; 1934 delete mServerSocket;
1937 mServerSocket = 0; 1935 mServerSocket = 0;
1938 return; 1936 return;
1939 } 1937 }
1940 connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) ); 1938 connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) );
1941 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) ); 1939 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) );
1942 // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); 1940 // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
1943 //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); 1941 //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
1944} 1942}
1945void MainWindow::sendFile(QSocket* socket) 1943
1946{
1947 setCaption( i18n("Received request for file") );
1948 qDebug("MainWindow::sendFile(QSocket* s) ");
1949 if ( mSyncActionDialog )
1950 delete mSyncActionDialog;
1951 mSyncActionDialog = new QDialog ( this, "input-dialog", true );
1952 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING"));
1953 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog );
1954 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1955 lay->addWidget( label);
1956 lay->setMargin(7);
1957 lay->setSpacing(7);
1958 mSyncActionDialog->setFixedSize( 200,100 );
1959 mSyncActionDialog->show();
1960 qDebug("saving ... ");
1961 save();
1962 qApp->processEvents();
1963 QString fileName = defaultFileName();
1964 QFile file( fileName );
1965 if (!file.open( IO_ReadOnly ) ) {
1966 setCaption( i18n("Error open file") );
1967 delete mSyncActionDialog;
1968 mSyncActionDialog = 0;
1969 qDebug("error open cal file ");
1970 return ;
1971
1972 }
1973 setCaption( i18n("Sending file...") );
1974 QTextStream ts( &file );
1975 ts.setCodec( QTextCodec::codecForName("utf8") );
1976 QTextStream os( socket );
1977 os.setCodec( QTextCodec::codecForName("utf8") );
1978 //os.setEncoding( QTextStream::UnicodeUTF8 );
1979 while ( ! ts.atEnd() ) {
1980 os << ts.readLine() << "\n";
1981 }
1982 //os << ts.read();
1983 socket->close();
1984 file.close();
1985 setCaption( i18n("File sent. Waiting to get back synced file") );
1986 qDebug("file sent ");
1987}
1988void MainWindow::getFile( bool success ) 1944void MainWindow::getFile( bool success )
1989{ 1945{
1990 if ( ! success ) { 1946 if ( ! success ) {
1991 setCaption( i18n("Error receiving file. Nothing changed!") ); 1947 setCaption( i18n("Error receiving file. Nothing changed!") );
1992 return; 1948 return;
1993 } 1949 }
1994 // pending adjust time for watchSavedFile() 1950 // pending adjust time for watchSavedFile()
1995 //mView->watchSavedFile(); 1951 //mView->watchSavedFile();
1996 mView->openCalendar( defaultFileName() ); 1952 mView->openCalendar( defaultFileName() );
1997 setCaption( i18n("Pi-Sync successful!") ); 1953 setCaption( i18n("Pi-Sync successful!") );
1998 1954
1999
2000#if 0
2001 setCaption( i18n("Receiving synced file...") );
2002
2003 piTime.start();
2004 piSocket = socket;
2005 piFileString = "";
2006 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
2007#endif
2008
2009} 1955}
2010void MainWindow::readBackFileFromSocket()
2011{
2012 qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
2013 while ( piSocket->canReadLine () ) {
2014 piTime.restart();
2015 QString line = piSocket->readLine ();
2016 piFileString += line;
2017 qDebug("readline: %s ", line.latin1());
2018 setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
2019 1956
2020 }
2021 if ( piTime.elapsed () < 3000 ) {
2022 // wait for more
2023 qDebug("waitformore ");
2024 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
2025 return;
2026 }
2027 QString fileName = defaultFileName();
2028 QFile file ( fileName );
2029 if (!file.open( IO_WriteOnly ) ) {
2030 setCaption( i18n("Error open file for writing!") );
2031 delete mSyncActionDialog;
2032 mSyncActionDialog = 0;
2033 qDebug("error open cal file ");
2034 piFileString = "";
2035 return ;
2036
2037 }
2038
2039 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2040 QTextStream ts ( &file );
2041 ts.setCodec( QTextCodec::codecForName("utf8") );
2042 qDebug("finish ");
2043 setCaption( i18n("Writing file to disk...") );
2044 ts << piFileString;
2045 setCaption( i18n("File received - reloading calendar...") );
2046 piSocket->close();
2047 file.close();
2048 mView->watchSavedFile();
2049 mView->openCalendar( defaultFileName() );
2050 setCaption( i18n("Pi-Sync successful!") );
2051 delete mSyncActionDialog;
2052 mSyncActionDialog = 0;
2053 piFileString = "";
2054 1957
2055
2056}
2057void MainWindow::endConnect()
2058{
2059 setCaption( i18n("No file received - syncing successful") );
2060 delete mSyncActionDialog;
2061 mSyncActionDialog = 0;
2062}
2063void MainWindow::performQuick() 1958void MainWindow::performQuick()
2064{ 1959{
2065 1960
2066 setCaption( i18n("Please input connection settings") ); 1961 setCaption( i18n("Please input connection settings") );
2067 QString retfile = ""; 1962 QString retfile = "";
2068 QDialog dia ( this, "input-dialog", true ); 1963 QDialog dia ( this, "input-dialog", true );
2069 QLineEdit lab ( &dia ); 1964 QLineEdit lab ( &dia );
2070 QVBoxLayout lay( &dia ); 1965 QVBoxLayout lay( &dia );
2071 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); 1966 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia );
2072 lay.addWidget( &label); 1967 lay.addWidget( &label);
2073 lab.setText( KOPrefs::instance()->mActiveSyncIP ); 1968 lab.setText( KOPrefs::instance()->mActiveSyncIP );
2074 lay.setMargin(7); 1969 lay.setMargin(7);
2075 lay.setSpacing(7); 1970 lay.setSpacing(7);
2076 lay.addWidget( &lab); 1971 lay.addWidget( &lab);
2077 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); 1972 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia );
2078 lay.addWidget( &label2); 1973 lay.addWidget( &label2);
2079 QLineEdit lab2 ( &dia ); 1974 QLineEdit lab2 ( &dia );
2080 lab2.setText( KOPrefs::instance()->mActiveSyncPort ); 1975 lab2.setText( KOPrefs::instance()->mActiveSyncPort );
2081 lay.addWidget( &lab2); 1976 lay.addWidget( &lab2);
2082 1977
2083 QLineEdit lepw ( &dia ); 1978 QLineEdit lepw ( &dia );
2084 lepw.setText( mPassWordPiSync ); 1979 lepw.setText( mPassWordPiSync );
2085 QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); 1980 QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia );
2086 lay.addWidget( &label3); 1981 lay.addWidget( &label3);
@@ -2094,153 +1989,126 @@ void MainWindow::performQuick()
2094 dia.show(); 1989 dia.show();
2095 int res = dia.exec(); 1990 int res = dia.exec();
2096 if ( !res ) { 1991 if ( !res ) {
2097 setCaption( i18n("Syncing cancelled!") ); 1992 setCaption( i18n("Syncing cancelled!") );
2098 return; 1993 return;
2099 } 1994 }
2100 mPassWordPiSync = lepw.text(); 1995 mPassWordPiSync = lepw.text();
2101 dia.hide(); 1996 dia.hide();
2102 KOPrefs::instance()->mActiveSyncPort = lab2.text(); 1997 KOPrefs::instance()->mActiveSyncPort = lab2.text();
2103 KOPrefs::instance()->mActiveSyncIP = lab.text(); 1998 KOPrefs::instance()->mActiveSyncIP = lab.text();
2104 qApp->processEvents(); 1999 qApp->processEvents();
2105 performQuickQuick(); 2000 performQuickQuick();
2106} 2001}
2107 2002
2108void MainWindow::performQuickQuick() 2003void MainWindow::performQuickQuick()
2109{ 2004{
2110 // setCaption( i18n("") ); 2005 // setCaption( i18n("") );
2111 2006
2112 bool ok; 2007 bool ok;
2113 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); 2008 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
2114 if ( ! ok ) { 2009 if ( ! ok ) {
2115 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 2010 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2116 return; 2011 return;
2117 } 2012 }
2118 mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); 2013 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
2119 connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) ); 2014 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocket(KCommandSocket*,bool)) );
2120 setCaption( i18n("Sending request for remote file ...") ); 2015 setCaption( i18n("Sending request for remote file ...") );
2121 QString fileName; 2016 QString fileName;
2122#ifdef _WIN32_ 2017#ifdef _WIN32_
2123 fileName = defaultFileName() +"sync"; 2018 fileName = defaultFileName() +"sync";
2124#else 2019#else
2125 fileName = "/tmp/kopitempfile.ics"; 2020 fileName = "/tmp/kopitempfile.ics";
2126#endif 2021#endif
2127 mCommandSocket->readFile( fileName ); 2022 commandSocket->readFile( fileName );
2128} 2023}
2129void MainWindow::deleteCommandSocket( bool success) 2024void MainWindow::deleteCommandSocket(KCommandSocket*s, bool success)
2130{ 2025{
2131 if ( ! success ) { 2026 if ( ! success ) {
2132 setCaption( i18n("ERROR:Receiving remote file failed.") ); 2027 setCaption( i18n("ERROR:Receiving remote file failed.") );
2028 delete s;
2133 // pending : send stop 2029 // pending : send stop
2134 return; 2030 return;
2135 2031
2136 } 2032 }
2137 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 2033 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
2138 delete mCommandSocket; 2034 qDebug("MainWindow::deleteCommandSocket ");
2035 delete s;
2139} 2036}
2140void MainWindow::deleteCommandSocketFinish() 2037void MainWindow::deleteCommandSocketFinish(KCommandSocket* s, bool success )
2141{ 2038{
2142 if ( ! mCommandSocketFinish) 2039 if ( ! success ) {
2143 return; 2040 setCaption( i18n("ERROR:Writing back file failed.") );
2144 // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); 2041 } else {
2145 qDebug("MainWindow::deletemCommandSocketFinish() "); 2042 qDebug("Syncing succesful! ");
2146 delete mCommandSocketFinish; 2043 setCaption( i18n("Pi-Sync succesful!") );
2147 mCommandSocketFinish = 0; 2044 }
2045 qDebug("MainWindow::deleteCommandSocketFinish ");
2046 delete s;
2148} 2047}
2149void MainWindow::readFileFromSocket() 2048void MainWindow::readFileFromSocket()
2150{ 2049{
2151 // mTimerCommandSocket->stop(); 2050 // mTimerCommandSocket->stop();
2152 setCaption( i18n("Receiving remote file ...") ); 2051 setCaption( i18n("Receiving remote file ...") );
2153 qDebug("MainWindow::readFileFromSocket() "); 2052 qDebug("MainWindow::readFileFromSocket() ");
2154 QString fileName; 2053 QString fileName;
2155#ifdef _WIN32_ 2054#ifdef _WIN32_
2156 fileName = defaultFileName() +"sync"; 2055 fileName = defaultFileName() +"sync";
2157#else 2056#else
2158 fileName = "/tmp/kopitempfile.ics"; 2057 fileName = "/tmp/kopitempfile.ics";
2159#endif 2058#endif
2160 2059
2161 setCaption( i18n("Remote file saved to temp file.") ); 2060 setCaption( i18n("Remote file saved to temp file.") );
2162 //mCommandSocket = 0; 2061 //mCommandSocket = 0;
2163 mCurrentSyncProfile = 2 ; // last file 2062 mCurrentSyncProfile = 2 ; // last file
2164 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); 2063 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
2165 mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); 2064 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
2166 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2065 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2167 KSyncProfile* temp = new KSyncProfile (); 2066 KSyncProfile* temp = new KSyncProfile ();
2168 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2067 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2169 temp->readConfig(&config); 2068 temp->readConfig(&config);
2170 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2069 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2171 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2070 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2172 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2071 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2173 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2072 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2174 KOPrefs::instance()->mWriteBackInFuture = 0; 2073 KOPrefs::instance()->mWriteBackInFuture = 0;
2175 if ( temp->getWriteBackFuture() ) 2074 if ( temp->getWriteBackFuture() )
2176 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2075 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2177 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2076 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2178 delete temp; 2077 delete temp;
2179 setCaption( i18n("Remote file saved to temp file.") ); 2078 setCaption( i18n("Remote file saved to temp file.") );
2180 if ( ! syncWithFile( fileName , true ) ) { 2079 if ( ! syncWithFile( fileName , true ) ) {
2181 setCaption( i18n("Syncing failed.") ); 2080 setCaption( i18n("Syncing failed.") );
2182 qDebug("Syncing failed "); 2081 qDebug("Syncing failed ");
2183 return; 2082 return;
2184 } 2083 }
2185 2084
2186 if ( !mCommandSocketFinish ) { 2085 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this );
2187 mCommandSocketFinish = new QSocket( this ); 2086 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocketFinish(KCommandSocket*,bool)) );
2188 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); 2087 if ( KOPrefs::instance()->mWriteBackFile )
2189 } 2088 commandSocket->writeFile( fileName );
2190 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); 2089 else
2191 2090 commandSocket->sendStop();
2192 QString host = KOPrefs::instance()->mActiveSyncIP;
2193 QFile file2( fileName );
2194 if (!file2.open( IO_ReadOnly ) ) {
2195 setCaption( i18n("Error: Cannot open temp file for read.") );
2196 qDebug("error open cal file ");
2197 return ;
2198
2199 }
2200 QTextStream ts2( &file2 );
2201 ts2.setCodec( QTextCodec::codecForName("utf8") );
2202 QTextStream os2( mCommandSocketFinish );
2203 os2.setCodec( QTextCodec::codecForName("utf8") );
2204 //os.setEncoding( QTextStream::UnicodeUTF8 );
2205 if ( KOPrefs::instance()->mWriteBackFile ) {
2206 setCaption( i18n("Sending back synced file...") );
2207 os2 << "PUT " << mPassWordPiSync << "\r\n";;
2208 while ( ! ts2.atEnd() ) {
2209 os2 << ts2.readLine() << "\n";
2210 }
2211 } else {
2212 os2 << "STOP\r\n";
2213 }
2214 mCommandSocketFinish->close();
2215 if ( mCommandSocketFinish->state() == QSocket::Idle )
2216 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
2217 file2.close();
2218 qDebug("Syncing succesful! ");
2219 setCaption( i18n("Pi-Sync succesful!") );
2220
2221 // KMessageBox::information( 0, i18n(" Pi-Sync succesful! "));
2222
2223} 2091}
2224 2092
2225void MainWindow::syncLocalFile() 2093void MainWindow::syncLocalFile()
2226{ 2094{
2227 2095
2228 QString fn =KOPrefs::instance()->mLastSyncedLocalFile; 2096 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
2229 2097
2230 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2098 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2231 if ( fn == "" ) 2099 if ( fn == "" )
2232 return; 2100 return;
2233 //mView->setSyncDevice("local-file" ); 2101 //mView->setSyncDevice("local-file" );
2234 if ( syncWithFile( fn, false ) ) { 2102 if ( syncWithFile( fn, false ) ) {
2235 // Event* e = mView->getLastSyncEvent(); 2103 // Event* e = mView->getLastSyncEvent();
2236// e->setReadOnly( false ); 2104// e->setReadOnly( false );
2237// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2105// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2238// e->setReadOnly( true ); 2106// e->setReadOnly( true );
2239 } 2107 }
2240 2108
2241} 2109}
2242 2110
2243bool MainWindow::syncWithFile( QString fn , bool quick ) 2111bool MainWindow::syncWithFile( QString fn , bool quick )
2244{ 2112{
2245 bool ret = false; 2113 bool ret = false;
2246 QFileInfo info; 2114 QFileInfo info;
@@ -2539,53 +2407,58 @@ void KServerSocket::readClient()
2539 } 2407 }
2540 qDebug("KServerSocket readClient()"); 2408 qDebug("KServerSocket readClient()");
2541 if ( mSocket->canReadLine() ) { 2409 if ( mSocket->canReadLine() ) {
2542 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); 2410 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() );
2543 qDebug("KServerSocket socket->canReadLine()"); 2411 qDebug("KServerSocket socket->canReadLine()");
2544 if ( tokens[0] == "GET" ) { 2412 if ( tokens[0] == "GET" ) {
2545 if ( tokens[1] == mPassWord ) 2413 if ( tokens[1] == mPassWord )
2546 //emit sendFile( mSocket ); 2414 //emit sendFile( mSocket );
2547 send_file(); 2415 send_file();
2548 else { 2416 else {
2549 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); 2417 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
2550 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 2418 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
2551 } 2419 }
2552 } 2420 }
2553 if ( tokens[0] == "PUT" ) { 2421 if ( tokens[0] == "PUT" ) {
2554 if ( tokens[1] == mPassWord ) 2422 if ( tokens[1] == mPassWord )
2555 //emit getFile( mSocket ); 2423 //emit getFile( mSocket );
2556 get_file(); 2424 get_file();
2557 else { 2425 else {
2558 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); 2426 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
2559 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 2427 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
2560 } 2428 }
2561 } 2429 }
2562 if ( tokens[0] == "STOP" ) { 2430 if ( tokens[0] == "STOP" ) {
2563 emit endConnect(); 2431 //emit endConnect();
2432 end_connect();
2564 } 2433 }
2565 } 2434 }
2566} 2435}
2567 2436void KServerSocket::end_connect()
2437{
2438 delete mSyncActionDialog;
2439 mSyncActionDialog = 0;
2440}
2568void KServerSocket::send_file() 2441void KServerSocket::send_file()
2569{ 2442{
2570 qDebug("MainWindow::sendFile(QSocket* s) "); 2443 qDebug("MainWindow::sendFile(QSocket* s) ");
2571 if ( mSyncActionDialog ) 2444 if ( mSyncActionDialog )
2572 delete mSyncActionDialog; 2445 delete mSyncActionDialog;
2573 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 2446 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
2574 mSyncActionDialog->setCaption(i18n("Received sync request")); 2447 mSyncActionDialog->setCaption(i18n("Received sync request"));
2575 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog ); 2448 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog );
2576 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 2449 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
2577 lay->addWidget( label); 2450 lay->addWidget( label);
2578 lay->setMargin(7); 2451 lay->setMargin(7);
2579 lay->setSpacing(7); 2452 lay->setSpacing(7);
2580 mSyncActionDialog->setFixedSize( 230, 120); 2453 mSyncActionDialog->setFixedSize( 230, 120);
2581 mSyncActionDialog->show(); 2454 mSyncActionDialog->show();
2582 qDebug("KSS::saving ... "); 2455 qDebug("KSS::saving ... ");
2583 emit saveFile(); 2456 emit saveFile();
2584 qApp->processEvents(); 2457 qApp->processEvents();
2585 QString fileName = mFileName; 2458 QString fileName = mFileName;
2586 QFile file( fileName ); 2459 QFile file( fileName );
2587 if (!file.open( IO_ReadOnly ) ) { 2460 if (!file.open( IO_ReadOnly ) ) {
2588 delete mSyncActionDialog; 2461 delete mSyncActionDialog;
2589 mSyncActionDialog = 0; 2462 mSyncActionDialog = 0;
2590 qDebug("KSS::error open file "); 2463 qDebug("KSS::error open file ");
2591 mSocket->close(); 2464 mSocket->close();
@@ -2674,52 +2547,90 @@ KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host,
2674 mPort = port; 2547 mPort = port;
2675 mHost = host; 2548 mHost = host;
2676 2549
2677 mRetVal = false; 2550 mRetVal = false;
2678 mTimerSocket = new QTimer ( this ); 2551 mTimerSocket = new QTimer ( this );
2679 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 2552 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
2680} 2553}
2681void KCommandSocket::readFile( QString fn ) 2554void KCommandSocket::readFile( QString fn )
2682{ 2555{
2683 if ( !mSocket ) { 2556 if ( !mSocket ) {
2684 mSocket = new QSocket( this ); 2557 mSocket = new QSocket( this );
2685 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 2558 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
2686 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 2559 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2687 } 2560 }
2688 mFileString = ""; 2561 mFileString = "";
2689 mFileName = fn; 2562 mFileName = fn;
2690 mFirst = true; 2563 mFirst = true;
2691 mSocket->connectToHost( mHost, mPort ); 2564 mSocket->connectToHost( mHost, mPort );
2692 QTextStream os( mSocket ); 2565 QTextStream os( mSocket );
2693 os.setEncoding( QTextStream::UnicodeUTF8 ); 2566 os.setEncoding( QTextStream::UnicodeUTF8 );
2694 os << "GET " << mPassWord << "\r\n"; 2567 os << "GET " << mPassWord << "\r\n";
2695 mTimerSocket->start( 10000 ); 2568 mTimerSocket->start( 10000 );
2696} 2569}
2697 2570
2698void KCommandSocket::writeFile( QString ) 2571void KCommandSocket::writeFile( QString fileName )
2699{ 2572{
2573 QFile file2( fileName );
2574 if (!file2.open( IO_ReadOnly ) ) {
2575 mRetVal= false;
2576 deleteSocket();
2577 return ;
2578
2579 }
2580 if ( !mSocket ) {
2581 mSocket = new QSocket( this );
2582 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2583 }
2584 QTextStream ts2( &file2 );
2585 ts2.setCodec( QTextCodec::codecForName("utf8") );
2586 QTextStream os2( mSocket );
2587 os2.setCodec( QTextCodec::codecForName("utf8") );
2588 os2 << "PUT " << mPassWord << "\r\n";;
2589 while ( ! ts2.atEnd() ) {
2590 os2 << ts2.readLine() << "\n";
2591 }
2592 mSocket->close();
2593 if ( mSocket->state() == QSocket::Idle )
2594 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
2595 file2.close();
2596}
2700 2597
2598void KCommandSocket::sendStop()
2599{
2600 if ( !mSocket ) {
2601 mSocket = new QSocket( this );
2602 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2603 }
2604 QTextStream os2( mSocket );
2605 os2.setCodec( QTextCodec::codecForName("utf8") );
2606 os2 << "STOP\r\n";
2607 mRetVal= true;
2608 mSocket->close();
2609 if ( mSocket->state() == QSocket::Idle )
2610 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
2701} 2611}
2612
2702void KCommandSocket::startReadFileFromSocket() 2613void KCommandSocket::startReadFileFromSocket()
2703{ 2614{
2704 if ( ! mFirst ) 2615 if ( ! mFirst )
2705 return; 2616 return;
2706 mFirst = false; 2617 mFirst = false;
2707 mTimerSocket->stop(); 2618 mTimerSocket->stop();
2708 mFileString = ""; 2619 mFileString = "";
2709 mTime.start(); 2620 mTime.start();
2710 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 2621 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
2711 2622
2712} 2623}
2713void KCommandSocket::readFileFromSocket() 2624void KCommandSocket::readFileFromSocket()
2714{ 2625{
2715 qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 2626 qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
2716 while ( mSocket->canReadLine () ) { 2627 while ( mSocket->canReadLine () ) {
2717 mTime.restart(); 2628 mTime.restart();
2718 QString line = mSocket->readLine (); 2629 QString line = mSocket->readLine ();
2719 mFileString += line; 2630 mFileString += line;
2720 qDebug("readline: %s ", line.latin1()); 2631 qDebug("readline: %s ", line.latin1());
2721 } 2632 }
2722 if ( mTime.elapsed () < 3000 ) { 2633 if ( mTime.elapsed () < 3000 ) {
2723 // wait for more 2634 // wait for more
2724 qDebug("waitformore "); 2635 qDebug("waitformore ");
2725 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 2636 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
@@ -2731,37 +2642,36 @@ void KCommandSocket::readFileFromSocket()
2731 mFileString = ""; 2642 mFileString = "";
2732 mRetVal = false; 2643 mRetVal = false;
2733 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 2644 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
2734 deleteSocket(); 2645 deleteSocket();
2735 return ; 2646 return ;
2736 2647
2737 } 2648 }
2738 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 2649 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2739 QTextStream ts ( &file ); 2650 QTextStream ts ( &file );
2740 ts.setCodec( QTextCodec::codecForName("utf8") ); 2651 ts.setCodec( QTextCodec::codecForName("utf8") );
2741 qDebug("finish "); 2652 qDebug("finish ");
2742 ts << mFileString; 2653 ts << mFileString;
2743 file.close(); 2654 file.close();
2744 mFileString = ""; 2655 mFileString = "";
2745 mRetVal = true; 2656 mRetVal = true;
2746 mSocket->close(); 2657 mSocket->close();
2747 // if state is not idle, deleteSocket(); is called via 2658 // if state is not idle, deleteSocket(); is called via
2748 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 2659 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2749 if ( mSocket->state() == QSocket::Idle ) 2660 if ( mSocket->state() == QSocket::Idle )
2750 deleteSocket(); 2661 deleteSocket();
2751} 2662}
2752 2663
2753void KCommandSocket::deleteSocket() 2664void KCommandSocket::deleteSocket()
2754{ 2665{
2755 if ( !mSocket)
2756 return;
2757 if ( mTimerSocket->isActive () ) { 2666 if ( mTimerSocket->isActive () ) {
2758 mTimerSocket->stop(); 2667 mTimerSocket->stop();
2759 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 2668 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
2760 mRetVal = false; 2669 mRetVal = false;
2761 } 2670 }
2762 qDebug("KCommandSocket::deleteSocket() %d", mRetVal); 2671 qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
2763 delete mSocket; 2672 if ( mSocket)
2673 delete mSocket;
2764 mSocket = 0; 2674 mSocket = 0;
2765 emit commandFinished( mRetVal ); 2675 emit commandFinished( this, mRetVal );
2766} 2676}
2767 2677
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 8b76067..5a67765 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -28,68 +28,70 @@ class QPEToolBar;
28class KServerSocket : public QServerSocket 28class KServerSocket : public QServerSocket
29{ 29{
30 Q_OBJECT 30 Q_OBJECT
31 31
32public: 32public:
33 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 33 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
34 34
35 void newConnection ( int socket ) ; 35 void newConnection ( int socket ) ;
36 void setFileName( QString fn ) {mFileName = fn;}; 36 void setFileName( QString fn ) {mFileName = fn;};
37 37
38signals: 38signals:
39 //void sendFile(QSocket*); 39 //void sendFile(QSocket*);
40 //void getFile(QSocket*); 40 //void getFile(QSocket*);
41 void file_received( bool ); 41 void file_received( bool );
42 //void file_sent(); 42 //void file_sent();
43 void saveFile(); 43 void saveFile();
44 void endConnect(); 44 void endConnect();
45private slots: 45private slots:
46 void discardClient(); 46 void discardClient();
47 void readClient(); 47 void readClient();
48 void readBackFileFromSocket(); 48 void readBackFileFromSocket();
49 private : 49 private :
50 void send_file(); 50 void send_file();
51 void get_file(); 51 void get_file();
52 void end_connect();
52 QDialog* mSyncActionDialog; 53 QDialog* mSyncActionDialog;
53 QSocket* mSocket; 54 QSocket* mSocket;
54 QString mPassWord; 55 QString mPassWord;
55 QString mFileName; 56 QString mFileName;
56 QTime piTime; 57 QTime piTime;
57 QString piFileString; 58 QString piFileString;
58}; 59};
59 60
60class KCommandSocket : public QObject 61class KCommandSocket : public QObject
61{ 62{
62 Q_OBJECT 63 Q_OBJECT
63 64
64public: 65public:
65 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); 66 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
66 void readFile( QString ); 67 void readFile( QString );
67 void writeFile( QString ); 68 void writeFile( QString );
69 void sendStop();
68 70
69 71
70signals: 72signals:
71 void commandFinished( bool ); 73 void commandFinished( KCommandSocket*, bool );
72private slots: 74private slots:
73 void startReadFileFromSocket(); 75 void startReadFileFromSocket();
74 void readFileFromSocket(); 76 void readFileFromSocket();
75 void deleteSocket(); 77 void deleteSocket();
76 private : 78 private :
77 QSocket* mSocket; 79 QSocket* mSocket;
78 QString mPassWord; 80 QString mPassWord;
79 Q_UINT16 mPort; 81 Q_UINT16 mPort;
80 QString mHost; 82 QString mHost;
81 QString mFileName; 83 QString mFileName;
82 QTimer* mTimerSocket; 84 QTimer* mTimerSocket;
83 bool mRetVal; 85 bool mRetVal;
84 QTime mTime; 86 QTime mTime;
85 QString mFileString; 87 QString mFileString;
86 bool mFirst; 88 bool mFirst;
87}; 89};
88 90
89namespace KCal { 91namespace KCal {
90class CalendarLocal; 92class CalendarLocal;
91} 93}
92 94
93using namespace KCal; 95using namespace KCal;
94 96
95class MainWindow : public QMainWindow 97class MainWindow : public QMainWindow
@@ -139,61 +141,56 @@ class MainWindow : public QMainWindow
139 void exportVCalendar(); 141 void exportVCalendar();
140 void fillFilterMenu(); 142 void fillFilterMenu();
141 void selectFilter( int ); 143 void selectFilter( int );
142 144
143 void slotSyncMenu( int ); 145 void slotSyncMenu( int );
144 void syncSSH(); 146 void syncSSH();
145 void confSync(); 147 void confSync();
146 void syncSharp(); 148 void syncSharp();
147 void syncPhone(); 149 void syncPhone();
148 void syncLocalFile(); 150 void syncLocalFile();
149 bool syncWithFile( QString, bool ); 151 bool syncWithFile( QString, bool );
150 void quickSyncLocalFile(); 152 void quickSyncLocalFile();
151 153
152 154
153 protected: 155 protected:
154 void displayText( QString, QString); 156 void displayText( QString, QString);
155 void displayFile( QString, QString); 157 void displayFile( QString, QString);
156 158
157 void enableIncidenceActions( bool ); 159 void enableIncidenceActions( bool );
158 160
159 private slots: 161 private slots:
160 QSocket* piSocket; 162 QSocket* piSocket;
161 QString piFileString; 163 QString piFileString;
162 QTime piTime; 164 QTime piTime;
163 void deleteCommandSocket(bool); 165 void deleteCommandSocket(KCommandSocket* s, bool success);
164 void deleteCommandSocketFinish(); 166 void deleteCommandSocketFinish(KCommandSocket* s, bool success);
165 void fillSyncMenu(); 167 void fillSyncMenu();
166 void sendFile(QSocket* s);
167 void getFile( bool ); 168 void getFile( bool );
168 void readFileFromSocket(); 169 void readFileFromSocket();
169 void readBackFileFromSocket();
170 void endConnect();
171 private: 170 private:
172 //QTimer* mTimerCommandSocket; 171 //QTimer* mTimerCommandSocket;
173 QString mPassWordPiSync; 172 QString mPassWordPiSync;
174 KCommandSocket* mCommandSocket;
175 QSocket* mCommandSocketFinish;
176 KServerSocket * mServerSocket; 173 KServerSocket * mServerSocket;
177 bool mClosed; 174 bool mClosed;
178 void saveOnClose(); 175 void saveOnClose();
179 int mCurrentSyncProfile; 176 int mCurrentSyncProfile;
180 void enableQuick(); 177 void enableQuick();
181 void performQuick(); 178 void performQuick();
182 void performQuickQuick(); 179 void performQuickQuick();
183 void syncRemote( KSyncProfile* , bool ask = true); 180 void syncRemote( KSyncProfile* , bool ask = true);
184 bool mFlagKeyPressed; 181 bool mFlagKeyPressed;
185 bool mBlockAtStartup; 182 bool mBlockAtStartup;
186 QPEToolBar *iconToolBar; 183 QPEToolBar *iconToolBar;
187 void initActions(); 184 void initActions();
188 void setDefaultPreferences(); 185 void setDefaultPreferences();
189 void keyPressEvent ( QKeyEvent * ) ; 186 void keyPressEvent ( QKeyEvent * ) ;
190 void keyReleaseEvent ( QKeyEvent * ) ; 187 void keyReleaseEvent ( QKeyEvent * ) ;
191 QPopupMenu *configureToolBarMenu; 188 QPopupMenu *configureToolBarMenu;
192 QPopupMenu *selectFilterMenu; 189 QPopupMenu *selectFilterMenu;
193 QPopupMenu *configureAgendaMenu, *syncMenu; 190 QPopupMenu *configureAgendaMenu, *syncMenu;
194 CalendarLocal *mCalendar; 191 CalendarLocal *mCalendar;
195 CalendarView *mView; 192 CalendarView *mView;
196 QString getPassword(); 193 QString getPassword();
197 QAction *mNewSubTodoAction; 194 QAction *mNewSubTodoAction;
198 195
199 QAction *mShowAction; 196 QAction *mShowAction;