summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 8e2f956..10cb2a2 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1927,514 +1927,516 @@ void MainWindow::enableQuick()
1927 Q_UINT16 port = retfile.toUInt(&ok); 1927 Q_UINT16 port = retfile.toUInt(&ok);
1928 if ( ! ok ) { 1928 if ( ! ok ) {
1929 KMessageBox::information( this, i18n("No valid port")); 1929 KMessageBox::information( this, i18n("No valid port"));
1930 return; 1930 return;
1931 } 1931 }
1932 qDebug("port %d ", port); 1932 qDebug("port %d ", port);
1933 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); 1933 mServerSocket = new KServerSocket ( passWordPiSync, port ,1 );
1934 qDebug("connected "); 1934 qDebug("connected ");
1935 if ( !mServerSocket->ok() ) { 1935 if ( !mServerSocket->ok() ) {
1936 qWarning("Failed to bind to port %d", port); 1936 qWarning("Failed to bind to port %d", port);
1937 delete mServerSocket; 1937 delete mServerSocket;
1938 mServerSocket = 0; 1938 mServerSocket = 0;
1939 return; 1939 return;
1940 } 1940 }
1941 connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); 1941 connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
1942 connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); 1942 connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
1943} 1943}
1944void MainWindow::sendFile(QSocket* socket) 1944void MainWindow::sendFile(QSocket* socket)
1945{ 1945{
1946 setCaption( i18n("Received request for file") ); 1946 setCaption( i18n("Received request for file") );
1947 qDebug("MainWindow::sendFile(QSocket* s) "); 1947 qDebug("MainWindow::sendFile(QSocket* s) ");
1948 if ( mSyncActionDialog ) 1948 if ( mSyncActionDialog )
1949 delete mSyncActionDialog; 1949 delete mSyncActionDialog;
1950 mSyncActionDialog = new QDialog ( this, "input-dialog", true ); 1950 mSyncActionDialog = new QDialog ( this, "input-dialog", true );
1951 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING")); 1951 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING"));
1952 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog ); 1952 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog );
1953 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1953 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1954 lay->addWidget( label); 1954 lay->addWidget( label);
1955 lay->setMargin(7); 1955 lay->setMargin(7);
1956 lay->setSpacing(7); 1956 lay->setSpacing(7);
1957 mSyncActionDialog->setFixedSize( 200,100 ); 1957 mSyncActionDialog->setFixedSize( 200,100 );
1958 mSyncActionDialog->show(); 1958 mSyncActionDialog->show();
1959 qDebug("saving ... "); 1959 qDebug("saving ... ");
1960 save(); 1960 save();
1961 qApp->processEvents(); 1961 qApp->processEvents();
1962 QString fileName = defaultFileName(); 1962 QString fileName = defaultFileName();
1963 QFile file( fileName ); 1963 QFile file( fileName );
1964 if (!file.open( IO_ReadOnly ) ) { 1964 if (!file.open( IO_ReadOnly ) ) {
1965 setCaption( i18n("Error open file") ); 1965 setCaption( i18n("Error open file") );
1966 delete mSyncActionDialog; 1966 delete mSyncActionDialog;
1967 mSyncActionDialog = 0; 1967 mSyncActionDialog = 0;
1968 qDebug("error open cal file "); 1968 qDebug("error open cal file ");
1969 return ; 1969 return ;
1970 1970
1971 } 1971 }
1972 setCaption( i18n("Sending file...") ); 1972 setCaption( i18n("Sending file...") );
1973 QTextStream ts( &file ); 1973 QTextStream ts( &file );
1974 ts.setCodec( QTextCodec::codecForName("utf8") ); 1974 ts.setCodec( QTextCodec::codecForName("utf8") );
1975 QTextStream os( socket ); 1975 QTextStream os( socket );
1976 os.setCodec( QTextCodec::codecForName("utf8") ); 1976 os.setCodec( QTextCodec::codecForName("utf8") );
1977 //os.setEncoding( QTextStream::UnicodeUTF8 ); 1977 //os.setEncoding( QTextStream::UnicodeUTF8 );
1978 while ( ! ts.atEnd() ) { 1978 while ( ! ts.atEnd() ) {
1979 os << ts.readLine() << "\n"; 1979 os << ts.readLine() << "\n";
1980 } 1980 }
1981 //os << ts.read(); 1981 //os << ts.read();
1982 socket->close(); 1982 socket->close();
1983 file.close(); 1983 file.close();
1984 setCaption( i18n("File sent. Waiting to get back synced file") ); 1984 setCaption( i18n("File sent. Waiting to get back synced file") );
1985 qDebug("file sent "); 1985 qDebug("file sent ");
1986} 1986}
1987void MainWindow::getFile(QSocket* socket) 1987void MainWindow::getFile(QSocket* socket)
1988{ 1988{
1989 setCaption( i18n("Receiving synced file...") ); 1989 setCaption( i18n("Receiving synced file...") );
1990 1990
1991 piTime.start(); 1991 piTime.start();
1992 piSocket = socket; 1992 piSocket = socket;
1993 piFileString = ""; 1993 piFileString = "";
1994 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1994 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1995 1995
1996 1996
1997} 1997}
1998void MainWindow::readBackFileFromSocket() 1998void MainWindow::readBackFileFromSocket()
1999{ 1999{
2000 qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 2000 qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
2001 while ( piSocket->canReadLine () ) { 2001 while ( piSocket->canReadLine () ) {
2002 piTime.restart(); 2002 piTime.restart();
2003 QString line = piSocket->readLine (); 2003 QString line = piSocket->readLine ();
2004 piFileString += line; 2004 piFileString += line;
2005 qDebug("readline: %s ", line.latin1()); 2005 qDebug("readline: %s ", line.latin1());
2006 setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 2006 setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
2007 2007
2008 } 2008 }
2009 if ( piTime.elapsed () < 3000 ) { 2009 if ( piTime.elapsed () < 3000 ) {
2010 // wait for more 2010 // wait for more
2011 qDebug("waitformore "); 2011 qDebug("waitformore ");
2012 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 2012 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
2013 return; 2013 return;
2014 } 2014 }
2015 QString fileName = defaultFileName(); 2015 QString fileName = defaultFileName();
2016 QFile file ( fileName ); 2016 QFile file ( fileName );
2017 if (!file.open( IO_WriteOnly ) ) { 2017 if (!file.open( IO_WriteOnly ) ) {
2018 setCaption( i18n("Error open file for writing!") ); 2018 setCaption( i18n("Error open file for writing!") );
2019 delete mSyncActionDialog; 2019 delete mSyncActionDialog;
2020 mSyncActionDialog = 0; 2020 mSyncActionDialog = 0;
2021 qDebug("error open cal file "); 2021 qDebug("error open cal file ");
2022 piFileString = ""; 2022 piFileString = "";
2023 return ; 2023 return ;
2024 2024
2025 } 2025 }
2026 2026
2027 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 2027 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2028 QTextStream ts ( &file ); 2028 QTextStream ts ( &file );
2029 ts.setCodec( QTextCodec::codecForName("utf8") ); 2029 ts.setCodec( QTextCodec::codecForName("utf8") );
2030 qDebug("finish "); 2030 qDebug("finish ");
2031 setCaption( i18n("Writing file to disk...") ); 2031 setCaption( i18n("Writing file to disk...") );
2032 ts << piFileString; 2032 ts << piFileString;
2033 setCaption( i18n("File received - reloading calendar...") ); 2033 setCaption( i18n("File received - reloading calendar...") );
2034 piSocket->close(); 2034 piSocket->close();
2035 file.close(); 2035 file.close();
2036 mView->watchSavedFile(); 2036 mView->watchSavedFile();
2037 mView->openCalendar( defaultFileName() ); 2037 mView->openCalendar( defaultFileName() );
2038 setCaption( i18n("Pi-Sync successful!") ); 2038 setCaption( i18n("Pi-Sync successful!") );
2039 delete mSyncActionDialog; 2039 delete mSyncActionDialog;
2040 mSyncActionDialog = 0; 2040 mSyncActionDialog = 0;
2041 piFileString = ""; 2041 piFileString = "";
2042 2042
2043 2043
2044} 2044}
2045void MainWindow::endConnect() 2045void MainWindow::endConnect()
2046{ 2046{
2047 setCaption( i18n("No file received - syncing successful") ); 2047 setCaption( i18n("No file received - syncing successful") );
2048 delete mSyncActionDialog; 2048 delete mSyncActionDialog;
2049 mSyncActionDialog = 0; 2049 mSyncActionDialog = 0;
2050} 2050}
2051void MainWindow::performQuick() 2051void MainWindow::performQuick()
2052{ 2052{
2053 2053
2054 setCaption( i18n("Please input connection settings") ); 2054 setCaption( i18n("Please input connection settings") );
2055 QString retfile = ""; 2055 QString retfile = "";
2056 QDialog dia ( this, "input-dialog", true ); 2056 QDialog dia ( this, "input-dialog", true );
2057 QLineEdit lab ( &dia ); 2057 QLineEdit lab ( &dia );
2058 QVBoxLayout lay( &dia ); 2058 QVBoxLayout lay( &dia );
2059 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); 2059 QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia );
2060 lay.addWidget( &label); 2060 lay.addWidget( &label);
2061 lab.setText( KOPrefs::instance()->mActiveSyncIP ); 2061 lab.setText( KOPrefs::instance()->mActiveSyncIP );
2062 lay.setMargin(7); 2062 lay.setMargin(7);
2063 lay.setSpacing(7); 2063 lay.setSpacing(7);
2064 lay.addWidget( &lab); 2064 lay.addWidget( &lab);
2065 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); 2065 QLabel label2 ( i18n("Port number (Default: 9197)"), &dia );
2066 lay.addWidget( &label2); 2066 lay.addWidget( &label2);
2067 QLineEdit lab2 ( &dia ); 2067 QLineEdit lab2 ( &dia );
2068 lab2.setText( KOPrefs::instance()->mActiveSyncPort ); 2068 lab2.setText( KOPrefs::instance()->mActiveSyncPort );
2069 lay.addWidget( &lab2); 2069 lay.addWidget( &lab2);
2070 2070
2071 QLineEdit lepw ( &dia ); 2071 QLineEdit lepw ( &dia );
2072 lepw.setText( mPassWordPiSync ); 2072 lepw.setText( mPassWordPiSync );
2073 QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); 2073 QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia );
2074 lay.addWidget( &label3); 2074 lay.addWidget( &label3);
2075 lay.addWidget( &lepw); 2075 lay.addWidget( &lepw);
2076 2076
2077 dia.setFixedSize( 230,200 ); 2077 dia.setFixedSize( 230,200 );
2078 dia.setCaption( i18n("Enter port for Pi-Sync ") ); 2078 dia.setCaption( i18n("Enter port for Pi-Sync ") );
2079 QPushButton pb ( "OK", &dia); 2079 QPushButton pb ( "OK", &dia);
2080 lay.addWidget( &pb ); 2080 lay.addWidget( &pb );
2081 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2081 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2082 dia.show(); 2082 dia.show();
2083 int res = dia.exec(); 2083 int res = dia.exec();
2084 if ( !res ) { 2084 if ( !res ) {
2085 setCaption( i18n("Syncing cancelled!") ); 2085 setCaption( i18n("Syncing cancelled!") );
2086 return; 2086 return;
2087 } 2087 }
2088 mPassWordPiSync = lepw.text(); 2088 mPassWordPiSync = lepw.text();
2089 dia.hide(); 2089 dia.hide();
2090 KOPrefs::instance()->mActiveSyncPort = lab2.text(); 2090 KOPrefs::instance()->mActiveSyncPort = lab2.text();
2091 KOPrefs::instance()->mActiveSyncIP = lab.text(); 2091 KOPrefs::instance()->mActiveSyncIP = lab.text();
2092 qApp->processEvents(); 2092 qApp->processEvents();
2093 performQuickQuick(); 2093 performQuickQuick();
2094} 2094}
2095 2095
2096void MainWindow::performQuickQuick() 2096void MainWindow::performQuickQuick()
2097{ 2097{
2098 // setCaption( i18n("") ); 2098 // setCaption( i18n("") );
2099 2099
2100 bool ok; 2100 bool ok;
2101 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); 2101 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
2102 if ( ! ok ) { 2102 if ( ! ok ) {
2103 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 2103 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2104 return; 2104 return;
2105 } 2105 }
2106 if ( !mCommandSocket ) { 2106 if ( !mCommandSocket ) {
2107 mCommandSocket = new QSocket( this ); 2107 mCommandSocket = new QSocket( this );
2108 // delete mCommandSocket; 2108 // delete mCommandSocket;
2109 //mCommandSocket = new QSocket( this ); 2109 //mCommandSocket = new QSocket( this );
2110 connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); 2110 connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) );
2111 connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) ); 2111 connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) );
2112 } 2112 }
2113 QString host = KOPrefs::instance()->mActiveSyncIP; 2113 QString host = KOPrefs::instance()->mActiveSyncIP;
2114 mCommandSocket->connectToHost( host, port ); 2114 mCommandSocket->connectToHost( host, port );
2115 QTextStream os( mCommandSocket ); 2115 QTextStream os( mCommandSocket );
2116 os.setEncoding( QTextStream::UnicodeUTF8 ); 2116 os.setEncoding( QTextStream::UnicodeUTF8 );
2117 os << "GET " << mPassWordPiSync << "\r\n"; 2117 os << "GET " << mPassWordPiSync << "\r\n";
2118 setCaption( i18n("Sending request for remote file ...") ); 2118 setCaption( i18n("Sending request for remote file ...") );
2119 mTimerCommandSocket->start( 15000 ); 2119 mTimerCommandSocket->start( 10000 );
2120 2120
2121} 2121}
2122void MainWindow::deleteCommandSocket() 2122void MainWindow::deleteCommandSocket()
2123{ 2123{
2124 if ( !mCommandSocket) 2124 if ( !mCommandSocket)
2125 return; 2125 return;
2126 if ( mTimerCommandSocket->isActive () ) { 2126 if ( mTimerCommandSocket->isActive () ) {
2127 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out ")); 2127 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
2128 mTimerCommandSocket->stop(); 2128 mTimerCommandSocket->stop();
2129 } 2129 }
2130 //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocket "));
2130 qDebug("MainWindow::deletemCommandSocket() "); 2131 qDebug("MainWindow::deletemCommandSocket() ");
2131 delete mCommandSocket; 2132 delete mCommandSocket;
2132 mCommandSocket = 0; 2133 mCommandSocket = 0;
2133} 2134}
2134void MainWindow::deleteCommandSocketFinish() 2135void MainWindow::deleteCommandSocketFinish()
2135{ 2136{
2136 if ( ! mCommandSocketFinish) 2137 if ( ! mCommandSocketFinish)
2137 return; 2138 return;
2138 //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); 2139 // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() "));
2139 qDebug("MainWindow::deletemCommandSocketFinish() "); 2140 qDebug("MainWindow::deletemCommandSocketFinish() ");
2140 delete mCommandSocketFinish; 2141 delete mCommandSocketFinish;
2141 mCommandSocketFinish = 0; 2142 mCommandSocketFinish = 0;
2142} 2143}
2143void MainWindow::readFileFromSocket() 2144void MainWindow::readFileFromSocket()
2144{ 2145{
2145 mTimerCommandSocket->stop(); 2146 mTimerCommandSocket->stop();
2146 setCaption( i18n("Receiving remote file ...") ); 2147 setCaption( i18n("Receiving remote file ...") );
2147 qDebug("MainWindow::readFileFromSocket() "); 2148 qDebug("MainWindow::readFileFromSocket() ");
2148 QString fileName; 2149 QString fileName;
2149#ifdef _WIN32_ 2150#ifdef _WIN32_
2150 fileName = defaultFileName() +"sync"; 2151 fileName = defaultFileName() +"sync";
2151#else 2152#else
2152 fileName = "/tmp/kopitempfile.ics"; 2153 fileName = "/tmp/kopitempfile.ics";
2153#endif 2154#endif
2154 QFile file( fileName ); 2155 QFile file( fileName );
2155 if (!file.open( IO_WriteOnly ) ) { 2156 if (!file.open( IO_WriteOnly ) ) {
2156 setCaption( i18n("Error: Cannot open temp file for write.") ); 2157 setCaption( i18n("Error: Cannot open temp file for write.") );
2157 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 2158 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
2158 return ; 2159 return ;
2159 } 2160 }
2160 2161
2161 //QTextStream os2( mCommandSocket ); 2162 //QTextStream os2( mCommandSocket );
2162 //os2.setEncoding( QTextStream::UnicodeUTF8 ); 2163 //os2.setEncoding( QTextStream::UnicodeUTF8 );
2163 2164
2164 QTextStream ts( &file ); 2165 QTextStream ts( &file );
2165 ts.setCodec( QTextCodec::codecForName("utf8") ); 2166 ts.setCodec( QTextCodec::codecForName("utf8") );
2166 bool first = true; 2167 bool first = true;
2167 while ( mCommandSocket->canReadLine () || first) { 2168 while ( mCommandSocket->canReadLine () || first) {
2168 first = false; 2169 first = false;
2169 while ( mCommandSocket->canReadLine () ) { 2170 while ( mCommandSocket->canReadLine () ) {
2170 ts << mCommandSocket->readLine (); 2171 ts << mCommandSocket->readLine ();
2171 } 2172 }
2172 QTime ti; 2173 QTime ti;
2173 ti.start(); 2174 ti.start();
2174 while ( ti.elapsed () < 5000 && !mCommandSocket->canReadLine () ) { 2175 while ( ti.elapsed () < 3000 && !mCommandSocket->canReadLine () ) {
2175 qApp->processEvents(); 2176 qApp->processEvents();
2176 qDebug("waiting2 %d ",ti.elapsed () ); 2177 qDebug("waiting2 %d ",ti.elapsed () );
2177 if ( !mCommandSocket->canReadLine () ) 2178 if ( !mCommandSocket->canReadLine () )
2178 mCommandSocket->waitForMore ( 100 ); 2179 mCommandSocket->waitForMore ( 100 );
2179 } 2180 }
2180 //mCommandSocket->waitForMore ( 5000 ); 2181 //mCommandSocket->waitForMore ( 5000 );
2181 } 2182 }
2182 file.close(); 2183 file.close();
2183 mCommandSocket->close(); 2184 mCommandSocket->close();
2184 if ( mCommandSocket->state() == QSocket::Idle ) 2185 if ( mCommandSocket->state() == QSocket::Idle )
2185 deleteCommandSocket(); 2186 deleteCommandSocket();
2186 // pending: deleting after signal SIGNAL(delayedCloseFinished()) 2187 // pending: deleting after signal SIGNAL(delayedCloseFinished())
2187 //delete mCommandSocket; 2188 //delete mCommandSocket;
2188 setCaption( i18n("Remote file saved to temp file.") ); 2189 setCaption( i18n("Remote file saved to temp file.") );
2189 //mCommandSocket = 0; 2190 //mCommandSocket = 0;
2190 mCurrentSyncProfile = 2 ; // last file 2191 mCurrentSyncProfile = 2 ; // last file
2191 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); 2192 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
2192 mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); 2193 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
2193 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2194 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2194 KSyncProfile* temp = new KSyncProfile (); 2195 KSyncProfile* temp = new KSyncProfile ();
2195 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2196 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2196 temp->readConfig(&config); 2197 temp->readConfig(&config);
2197 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2198 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2198 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2199 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2199 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2200 KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2200 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2201 KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2201 KOPrefs::instance()->mWriteBackInFuture = 0; 2202 KOPrefs::instance()->mWriteBackInFuture = 0;
2202 if ( temp->getWriteBackFuture() ) 2203 if ( temp->getWriteBackFuture() )
2203 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2204 KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2204 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2205 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2205 delete temp; 2206 delete temp;
2206 setCaption( i18n("Remote file saved to temp file.") ); 2207 setCaption( i18n("Remote file saved to temp file.") );
2207 if ( ! syncWithFile( fileName , true ) ) { 2208 if ( ! syncWithFile( fileName , true ) ) {
2208 setCaption( i18n("Syncing failed.") ); 2209 setCaption( i18n("Syncing failed.") );
2209 qDebug("Syncing failed "); 2210 qDebug("Syncing failed ");
2210 return; 2211 return;
2211 } 2212 }
2212 2213
2213 if ( !mCommandSocketFinish ) { 2214 if ( !mCommandSocketFinish ) {
2214 mCommandSocketFinish = new QSocket( this ); 2215 mCommandSocketFinish = new QSocket( this );
2215 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); 2216 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) );
2216 } 2217 }
2217 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); 2218 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
2218 2219
2219 // pending connect signals connected () and error to new slots 2220 // pending connect signals connected () and error to new slots
2220 QString host = KOPrefs::instance()->mActiveSyncIP; 2221 QString host = KOPrefs::instance()->mActiveSyncIP;
2221 QFile file2( fileName ); 2222 QFile file2( fileName );
2222 if (!file2.open( IO_ReadOnly ) ) { 2223 if (!file2.open( IO_ReadOnly ) ) {
2223 setCaption( i18n("Error: Cannot open temp file for read.") ); 2224 setCaption( i18n("Error: Cannot open temp file for read.") );
2224 qDebug("error open cal file "); 2225 qDebug("error open cal file ");
2225 return ; 2226 return ;
2226 2227
2227 } 2228 }
2228 setCaption( i18n("Sending back synced file...") );
2229 QTextStream ts2( &file2 ); 2229 QTextStream ts2( &file2 );
2230 ts2.setCodec( QTextCodec::codecForName("utf8") ); 2230 ts2.setCodec( QTextCodec::codecForName("utf8") );
2231 QTextStream os2( mCommandSocketFinish ); 2231 QTextStream os2( mCommandSocketFinish );
2232 os2.setCodec( QTextCodec::codecForName("utf8") ); 2232 os2.setCodec( QTextCodec::codecForName("utf8") );
2233 //os.setEncoding( QTextStream::UnicodeUTF8 ); 2233 //os.setEncoding( QTextStream::UnicodeUTF8 );
2234 if ( KOPrefs::instance()->mWriteBackFile ) { 2234 if ( KOPrefs::instance()->mWriteBackFile ) {
2235 setCaption( i18n("Sending back synced file...") );
2235 os2 << "PUT " << mPassWordPiSync << "\r\n";; 2236 os2 << "PUT " << mPassWordPiSync << "\r\n";;
2236 while ( ! ts2.atEnd() ) { 2237 while ( ! ts2.atEnd() ) {
2237 os2 << ts2.readLine() << "\n"; 2238 os2 << ts2.readLine() << "\n";
2238 } 2239 }
2239 } else { 2240 } else {
2240 os2 << "STOP\r\n"; 2241 os2 << "STOP\r\n";
2241 } 2242 }
2242 mCommandSocketFinish->close(); 2243 mCommandSocketFinish->close();
2243 if ( mCommandSocketFinish->state() == QSocket::Idle ) 2244 if ( mCommandSocketFinish->state() == QSocket::Idle )
2244 deleteCommandSocketFinish(); 2245 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
2245 file.close(); 2246 file.close();
2246 qDebug("Syncing succesful! "); 2247 qDebug("Syncing succesful! ");
2247 setCaption( i18n("Pi-Sync succesful!") ); 2248 setCaption( i18n("Pi-Sync succesful!") );
2248 2249
2250 // KMessageBox::information( 0, i18n(" Pi-Sync succesful! "));
2249 2251
2250} 2252}
2251 2253
2252void MainWindow::syncLocalFile() 2254void MainWindow::syncLocalFile()
2253{ 2255{
2254 2256
2255 QString fn =KOPrefs::instance()->mLastSyncedLocalFile; 2257 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
2256 2258
2257 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2259 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2258 if ( fn == "" ) 2260 if ( fn == "" )
2259 return; 2261 return;
2260 //mView->setSyncDevice("local-file" ); 2262 //mView->setSyncDevice("local-file" );
2261 if ( syncWithFile( fn, false ) ) { 2263 if ( syncWithFile( fn, false ) ) {
2262 // Event* e = mView->getLastSyncEvent(); 2264 // Event* e = mView->getLastSyncEvent();
2263// e->setReadOnly( false ); 2265// e->setReadOnly( false );
2264// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2266// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2265// e->setReadOnly( true ); 2267// e->setReadOnly( true );
2266 } 2268 }
2267 2269
2268} 2270}
2269 2271
2270bool MainWindow::syncWithFile( QString fn , bool quick ) 2272bool MainWindow::syncWithFile( QString fn , bool quick )
2271{ 2273{
2272 bool ret = false; 2274 bool ret = false;
2273 QFileInfo info; 2275 QFileInfo info;
2274 info.setFile( fn ); 2276 info.setFile( fn );
2275 QString mess; 2277 QString mess;
2276 bool loadbup = true; 2278 bool loadbup = true;
2277 if ( !info. exists() ) { 2279 if ( !info. exists() ) {
2278 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 2280 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2279 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2281 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2280 mess ); 2282 mess );
2281 return ret; 2283 return ret;
2282 } 2284 }
2283 int result = 0; 2285 int result = 0;
2284 if ( !quick ) { 2286 if ( !quick ) {
2285 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2287 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2286 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2288 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2287 mess, 2289 mess,
2288 i18n("Sync"), i18n("Cancel"), 0, 2290 i18n("Sync"), i18n("Cancel"), 0,
2289 0, 1 ); 2291 0, 1 );
2290 if ( result ) 2292 if ( result )
2291 return false; 2293 return false;
2292 } 2294 }
2293 if ( KOPrefs::instance()->mAskForPreferences ) 2295 if ( KOPrefs::instance()->mAskForPreferences )
2294 mView->edit_sync_options(); 2296 mView->edit_sync_options();
2295 if ( result == 0 ) { 2297 if ( result == 0 ) {
2296 //qDebug("Now sycing ... "); 2298 //qDebug("Now sycing ... ");
2297 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) ) 2299 if ( ret = mView->syncCalendar( fn, KOPrefs::instance()->mSyncAlgoPrefs ) )
2298 setCaption( i18n("Synchronization successful") ); 2300 setCaption( i18n("Synchronization successful") );
2299 else 2301 else
2300 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 2302 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2301 if ( ! quick ) 2303 if ( ! quick )
2302 KOPrefs::instance()->mLastSyncedLocalFile = fn; 2304 KOPrefs::instance()->mLastSyncedLocalFile = fn;
2303 slotModifiedChanged( true ); 2305 slotModifiedChanged( true );
2304 } 2306 }
2305 return ret; 2307 return ret;
2306} 2308}
2307void MainWindow::quickSyncLocalFile() 2309void MainWindow::quickSyncLocalFile()
2308{ 2310{
2309 //mView->setSyncDevice("local-file" ); 2311 //mView->setSyncDevice("local-file" );
2310 //qDebug("quickSyncLocalFile() "); 2312 //qDebug("quickSyncLocalFile() ");
2311 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) { 2313 if ( syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2312 // Event* e = mView->getLastSyncEvent(); 2314 // Event* e = mView->getLastSyncEvent();
2313// e->setReadOnly( false ); 2315// e->setReadOnly( false );
2314// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2316// e->setLocation( i18n("Quick with file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2315// e->setReadOnly( true ); 2317// e->setReadOnly( true );
2316 2318
2317 } 2319 }
2318} 2320}
2319 2321
2320void MainWindow::confSync() 2322void MainWindow::confSync()
2321{ 2323{
2322 mView->confSync(); 2324 mView->confSync();
2323 fillSyncMenu(); 2325 fillSyncMenu();
2324} 2326}
2325void MainWindow::syncRemote( KSyncProfile* prof, bool ask) 2327void MainWindow::syncRemote( KSyncProfile* prof, bool ask)
2326{ 2328{
2327 QString question; 2329 QString question;
2328 if ( ask ) { 2330 if ( ask ) {
2329 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 2331 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2330 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2332 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2331 question, 2333 question,
2332 i18n("Yes"), i18n("No"), 2334 i18n("Yes"), i18n("No"),
2333 0, 0 ) != 0 ) 2335 0, 0 ) != 0 )
2334 return; 2336 return;
2335 } 2337 }
2336 QString command = prof->getPreSyncCommand(); 2338 QString command = prof->getPreSyncCommand();
2337 int fi; 2339 int fi;
2338 if ( (fi = command.find("$PWD$")) > 0 ) { 2340 if ( (fi = command.find("$PWD$")) > 0 ) {
2339 QString pwd = getPassword(); 2341 QString pwd = getPassword();
2340 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2342 command = command.left( fi )+ pwd + command.mid( fi+5 );
2341 2343
2342 } 2344 }
2343 int maxlen = 30; 2345 int maxlen = 30;
2344 if ( QApplication::desktop()->width() > 320 ) 2346 if ( QApplication::desktop()->width() > 320 )
2345 maxlen += 25; 2347 maxlen += 25;
2346 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2348 setCaption ( i18n( "Copy remote file to local machine..." ) );
2347 int fileSize = 0; 2349 int fileSize = 0;
2348 int result = system ( command ); 2350 int result = system ( command );
2349 // 0 : okay 2351 // 0 : okay
2350 // 256: no such file or dir 2352 // 256: no such file or dir
2351 // 2353 //
2352 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2354 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2353 if ( result != 0 ) { 2355 if ( result != 0 ) {
2354 int len = maxlen; 2356 int len = maxlen;
2355 while ( len < command.length() ) { 2357 while ( len < command.length() ) {
2356 command.insert( len , "\n" ); 2358 command.insert( len , "\n" );
2357 len += maxlen +2; 2359 len += maxlen +2;
2358 } 2360 }
2359 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2361 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2360 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2362 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2361 question, 2363 question,
2362 i18n("Okay!")) ; 2364 i18n("Okay!")) ;
2363 setCaption ("KO/Pi"); 2365 setCaption ("KO/Pi");
2364 return; 2366 return;
2365 } 2367 }
2366 setCaption ( i18n( "Copying succeed." ) ); 2368 setCaption ( i18n( "Copying succeed." ) );
2367 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2369 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2368 if ( syncWithFile( prof->getLocalTempFile(), true ) ) { 2370 if ( syncWithFile( prof->getLocalTempFile(), true ) ) {
2369// Event* e = mView->getLastSyncEvent(); 2371// Event* e = mView->getLastSyncEvent();
2370// e->setReadOnly( false ); 2372// e->setReadOnly( false );
2371// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2373// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2372// e->setReadOnly( true ); 2374// e->setReadOnly( true );
2373 if ( KOPrefs::instance()->mWriteBackFile ) { 2375 if ( KOPrefs::instance()->mWriteBackFile ) {
2374 command = prof->getPostSyncCommand(); 2376 command = prof->getPostSyncCommand();
2375 int fi; 2377 int fi;
2376 if ( (fi = command.find("$PWD$")) > 0 ) { 2378 if ( (fi = command.find("$PWD$")) > 0 ) {
2377 QString pwd = getPassword(); 2379 QString pwd = getPassword();
2378 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2380 command = command.left( fi )+ pwd + command.mid( fi+5 );
2379 2381
2380 } 2382 }
2381 setCaption ( i18n( "Writing back file ..." ) ); 2383 setCaption ( i18n( "Writing back file ..." ) );
2382 result = system ( command ); 2384 result = system ( command );
2383 qDebug("KO: Writing back file result: %d ", result); 2385 qDebug("KO: Writing back file result: %d ", result);
2384 if ( result != 0 ) { 2386 if ( result != 0 ) {
2385 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2387 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2386 return; 2388 return;
2387 } else { 2389 } else {
2388 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2390 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2389 } 2391 }
2390 } 2392 }
2391 } 2393 }
2392 return; 2394 return;
2393} 2395}
2394void MainWindow::syncSSH() 2396void MainWindow::syncSSH()
2395{ 2397{
2396 // not used anymore 2398 // not used anymore
2397 QTime timer; 2399 QTime timer;
2398 timer.start(); 2400 timer.start();
2399 //qDebug("MainWindow::syncssh() "); 2401 //qDebug("MainWindow::syncssh() ");
2400 KOPrefs *p = KOPrefs::instance(); 2402 KOPrefs *p = KOPrefs::instance();
2401 QString localFile = p->mLocalTempFile; 2403 QString localFile = p->mLocalTempFile;
2402 QString remoteIP = p->mRemoteIP; 2404 QString remoteIP = p->mRemoteIP;
2403 QString remoteUser = p->mRemoteUser; 2405 QString remoteUser = p->mRemoteUser;
2404 QString remoteFile = p->mRemoteFile; 2406 QString remoteFile = p->mRemoteFile;
2405 if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 ) 2407 if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 )
2406 remoteUser += ":" + p->mRemotePassWd; 2408 remoteUser += ":" + p->mRemotePassWd;
2407 2409
2408 QString question = i18n("Do you really want\nto remote sync?\n \n") + 2410 QString question = i18n("Do you really want\nto remote sync?\n \n") +
2409 i18n("IP: " ) +remoteIP +"\n" + 2411 i18n("IP: " ) +remoteIP +"\n" +
2410 i18n("User: " ) + remoteUser +"\n" ; 2412 i18n("User: " ) + remoteUser +"\n" ;
2411 int maxlen = 30; 2413 int maxlen = 30;
2412 if ( QApplication::desktop()->width() > 320 ) 2414 if ( QApplication::desktop()->width() > 320 )
2413 maxlen += 25; 2415 maxlen += 25;
2414 if ( remoteFile.length() > maxlen ) 2416 if ( remoteFile.length() > maxlen )
2415 question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n"; 2417 question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n";
2416 else 2418 else
2417 question += i18n("Remote file:\n " ) + remoteFile +"\n"; 2419 question += i18n("Remote file:\n " ) + remoteFile +"\n";
2418 if ( localFile.length() > maxlen ) 2420 if ( localFile.length() > maxlen )
2419 question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n"; 2421 question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n";
2420 else 2422 else
2421 question += i18n("Local temp file:\n " ) + localFile +"\n"; 2423 question += i18n("Local temp file:\n " ) + localFile +"\n";
2422 2424
2423 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2425 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2424 question, 2426 question,
2425 i18n("Yes"), i18n("No"), 2427 i18n("Yes"), i18n("No"),
2426 0, 0 ) != 0 ) 2428 0, 0 ) != 0 )
2427 return; 2429 return;
2428 // if ( !p->mUsePassWd ) { 2430 // if ( !p->mUsePassWd ) {
2429 // QString pass = getPassword(); 2431 // QString pass = getPassword();
2430 // if ( pass.length() > 0 ) 2432 // if ( pass.length() > 0 )
2431 // remoteUser += ":" + pass; 2433 // remoteUser += ":" + pass;
2432 // } 2434 // }
2433 QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile; 2435 QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile;
2434 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2436 setCaption ( i18n( "Copy remote file to local machine..." ) );
2435 int fileSize = 0; 2437 int fileSize = 0;
2436 int result = system ( command ); 2438 int result = system ( command );
2437 // 0 : okay 2439 // 0 : okay
2438 // 256: no such file or dir 2440 // 256: no such file or dir
2439 // 2441 //
2440 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2442 qDebug("KO: Remote copy result(0 = okay): %d ",result );