author | zautrix <zautrix> | 2004-10-04 22:10:20 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-04 22:10:20 (UTC) |
commit | c22811d11414872fc0525350a8a1afdae61be346 (patch) (unidiff) | |
tree | daafa0c4333022d44dafb2945ba36ff58d5c45d1 /korganizer/mainwindow.cpp | |
parent | f53ef630b9299ceae666e64da8ce022813795ed6 (diff) | |
download | kdepimpi-c22811d11414872fc0525350a8a1afdae61be346.zip kdepimpi-c22811d11414872fc0525350a8a1afdae61be346.tar.gz kdepimpi-c22811d11414872fc0525350a8a1afdae61be346.tar.bz2 |
many sync fixes
-rw-r--r-- | korganizer/mainwindow.cpp | 98 |
1 files changed, 28 insertions, 70 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index bce2a54..fe7e6d3 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp | |||
@@ -863,27 +863,24 @@ void MainWindow::initActions() | |||
863 | void MainWindow::fillSyncMenu() | 863 | void MainWindow::fillSyncMenu() |
864 | { | 864 | { |
865 | if ( syncMenu->count() ) | 865 | if ( syncMenu->count() ) |
866 | syncMenu->clear(); | 866 | syncMenu->clear(); |
867 | syncMenu->insertItem( i18n("Configure..."), 0 ); | 867 | syncMenu->insertItem( i18n("Configure..."), 0 ); |
868 | syncMenu->insertSeparator(); | 868 | syncMenu->insertSeparator(); |
869 | if ( mServerSocket == 0 ) { | 869 | if ( mServerSocket == 0 ) { |
870 | syncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 870 | syncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
871 | } else { | 871 | } else { |
872 | syncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 872 | syncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
873 | } | 873 | } |
874 | syncMenu->insertSeparator(); | 874 | syncMenu->insertSeparator(); |
875 | syncMenu->insertItem( i18n("New Pi-Sync!"), 4 ); | ||
876 | syncMenu->insertItem( i18n("Quick Pi-Sync!"), 5 ); | ||
877 | syncMenu->insertSeparator(); | ||
878 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); | 875 | syncMenu->insertItem( i18n("Multiple sync"), 1 ); |
879 | syncMenu->insertSeparator(); | 876 | syncMenu->insertSeparator(); |
880 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 877 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
881 | config.setGroup("General"); | 878 | config.setGroup("General"); |
882 | QStringList prof = config.readListEntry("SyncProfileNames"); | 879 | QStringList prof = config.readListEntry("SyncProfileNames"); |
883 | KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 880 | KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
884 | if ( prof.count() < 3 ) { | 881 | if ( prof.count() < 3 ) { |
885 | prof.clear(); | 882 | prof.clear(); |
886 | prof << i18n("Sharp_DTM"); | 883 | prof << i18n("Sharp_DTM"); |
887 | prof << i18n("Local_file"); | 884 | prof << i18n("Local_file"); |
888 | prof << i18n("Last_file"); | 885 | prof << i18n("Last_file"); |
889 | KSyncProfile* temp = new KSyncProfile (); | 886 | KSyncProfile* temp = new KSyncProfile (); |
@@ -943,25 +940,30 @@ int MainWindow::ringSync() | |||
943 | if ( i == 0 ) { | 940 | if ( i == 0 ) { |
944 | syncSharp(); | 941 | syncSharp(); |
945 | } else { | 942 | } else { |
946 | if ( temp->getIsLocalFileSync() ) { | 943 | if ( temp->getIsLocalFileSync() ) { |
947 | if ( syncWithFile( temp->getRemoteFileName( ), true ) ) | 944 | if ( syncWithFile( temp->getRemoteFileName( ), true ) ) |
948 | KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); | 945 | KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); |
949 | } else { | 946 | } else { |
950 | if ( temp->getIsPhoneSync() ) { | 947 | if ( temp->getIsPhoneSync() ) { |
951 | KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 948 | KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
952 | KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | 949 | KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); |
953 | KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | 950 | KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); |
954 | syncPhone(); | 951 | syncPhone(); |
955 | } else | 952 | } else if ( temp->getIsPiSync() ) { |
953 | mPassWordPiSync = temp->getRemotePw(); | ||
954 | KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort(); | ||
955 | KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP(); | ||
956 | syncPi(); | ||
957 | } else | ||
956 | syncRemote( temp, false ); | 958 | syncRemote( temp, false ); |
957 | 959 | ||
958 | } | 960 | } |
959 | } | 961 | } |
960 | timer.start(); | 962 | timer.start(); |
961 | setCaption(i18n("Multiple sync in progress ... please wait!") ); | 963 | setCaption(i18n("Multiple sync in progress ... please wait!") ); |
962 | while ( timer.elapsed () < 2000 ) { | 964 | while ( timer.elapsed () < 2000 ) { |
963 | qApp->processEvents(); | 965 | qApp->processEvents(); |
964 | #ifndef _WIN32_ | 966 | #ifndef _WIN32_ |
965 | sleep (1); | 967 | sleep (1); |
966 | #endif | 968 | #endif |
967 | } | 969 | } |
@@ -1027,32 +1029,24 @@ void MainWindow::slotSyncMenu( int action ) | |||
1027 | } | 1029 | } |
1028 | if ( action == 2 ) { | 1030 | if ( action == 2 ) { |
1029 | enableQuick(); | 1031 | enableQuick(); |
1030 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 1032 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
1031 | return; | 1033 | return; |
1032 | } | 1034 | } |
1033 | if ( action == 3 ) { | 1035 | if ( action == 3 ) { |
1034 | delete mServerSocket; | 1036 | delete mServerSocket; |
1035 | mServerSocket = 0; | 1037 | mServerSocket = 0; |
1036 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 1038 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
1037 | return; | 1039 | return; |
1038 | } | 1040 | } |
1039 | if ( action == 4 ) { | ||
1040 | performQuick(); | ||
1041 | return; | ||
1042 | } | ||
1043 | if ( action == 5 ) { | ||
1044 | performQuickQuick(); | ||
1045 | return; | ||
1046 | } | ||
1047 | 1041 | ||
1048 | if (mBlockSaveFlag) | 1042 | if (mBlockSaveFlag) |
1049 | return; | 1043 | return; |
1050 | mBlockSaveFlag = true; | 1044 | mBlockSaveFlag = true; |
1051 | mCurrentSyncProfile = action - 1000 ; | 1045 | mCurrentSyncProfile = action - 1000 ; |
1052 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); | 1046 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); |
1053 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); | 1047 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); |
1054 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 1048 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
1055 | KSyncProfile* temp = new KSyncProfile (); | 1049 | KSyncProfile* temp = new KSyncProfile (); |
1056 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 1050 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
1057 | temp->readConfig(&config); | 1051 | temp->readConfig(&config); |
1058 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 1052 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
@@ -1073,25 +1067,30 @@ void MainWindow::slotSyncMenu( int action ) | |||
1073 | quickSyncLocalFile(); | 1067 | quickSyncLocalFile(); |
1074 | 1068 | ||
1075 | } else if ( action >= 1003 ) { | 1069 | } else if ( action >= 1003 ) { |
1076 | if ( temp->getIsLocalFileSync() ) { | 1070 | if ( temp->getIsLocalFileSync() ) { |
1077 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 1071 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
1078 | KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); | 1072 | KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); |
1079 | } else { | 1073 | } else { |
1080 | if ( temp->getIsPhoneSync() ) { | 1074 | if ( temp->getIsPhoneSync() ) { |
1081 | KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; | 1075 | KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; |
1082 | KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); | 1076 | KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); |
1083 | KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); | 1077 | KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); |
1084 | syncPhone(); | 1078 | syncPhone(); |
1085 | } else | 1079 | } else if ( temp->getIsPiSync() ) { |
1080 | mPassWordPiSync = temp->getRemotePw(); | ||
1081 | KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort(); | ||
1082 | KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP(); | ||
1083 | syncPi(); | ||
1084 | } else | ||
1086 | syncRemote( temp ); | 1085 | syncRemote( temp ); |
1087 | 1086 | ||
1088 | } | 1087 | } |
1089 | } | 1088 | } |
1090 | delete temp; | 1089 | delete temp; |
1091 | mBlockSaveFlag = false; | 1090 | mBlockSaveFlag = false; |
1092 | } | 1091 | } |
1093 | void MainWindow::setDefaultPreferences() | 1092 | void MainWindow::setDefaultPreferences() |
1094 | { | 1093 | { |
1095 | KOPrefs *p = KOPrefs::instance(); | 1094 | KOPrefs *p = KOPrefs::instance(); |
1096 | 1095 | ||
1097 | p->mCompactDialogs = true; | 1096 | p->mCompactDialogs = true; |
@@ -1946,65 +1945,26 @@ void MainWindow::getFile( bool success ) | |||
1946 | if ( ! success ) { | 1945 | if ( ! success ) { |
1947 | setCaption( i18n("Error receiving file. Nothing changed!") ); | 1946 | setCaption( i18n("Error receiving file. Nothing changed!") ); |
1948 | return; | 1947 | return; |
1949 | } | 1948 | } |
1950 | // pending adjust time for watchSavedFile() | 1949 | // pending adjust time for watchSavedFile() |
1951 | //mView->watchSavedFile(); | 1950 | //mView->watchSavedFile(); |
1952 | mView->openCalendar( defaultFileName() ); | 1951 | mView->openCalendar( defaultFileName() ); |
1953 | setCaption( i18n("Pi-Sync successful!") ); | 1952 | setCaption( i18n("Pi-Sync successful!") ); |
1954 | 1953 | ||
1955 | } | 1954 | } |
1956 | 1955 | ||
1957 | 1956 | ||
1958 | void MainWindow::performQuick() | 1957 | void MainWindow::syncPi() |
1959 | { | 1958 | { |
1960 | |||
1961 | setCaption( i18n("Please input connection settings") ); | ||
1962 | QString retfile = ""; | ||
1963 | QDialog dia ( this, "input-dialog", true ); | ||
1964 | QLineEdit lab ( &dia ); | ||
1965 | QVBoxLayout lay( &dia ); | ||
1966 | QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); | ||
1967 | lay.addWidget( &label); | ||
1968 | lab.setText( KOPrefs::instance()->mActiveSyncIP ); | ||
1969 | lay.setMargin(7); | ||
1970 | lay.setSpacing(7); | ||
1971 | lay.addWidget( &lab); | ||
1972 | QLabel label2 ( i18n("Port number (Default: 9197)"), &dia ); | ||
1973 | lay.addWidget( &label2); | ||
1974 | QLineEdit lab2 ( &dia ); | ||
1975 | lab2.setText( KOPrefs::instance()->mActiveSyncPort ); | ||
1976 | lay.addWidget( &lab2); | ||
1977 | |||
1978 | QLineEdit lepw ( &dia ); | ||
1979 | lepw.setText( mPassWordPiSync ); | ||
1980 | QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); | ||
1981 | lay.addWidget( &label3); | ||
1982 | lay.addWidget( &lepw); | ||
1983 | |||
1984 | dia.setFixedSize( 230,200 ); | ||
1985 | dia.setCaption( i18n("Enter port for Pi-Sync ") ); | ||
1986 | QPushButton pb ( "OK", &dia); | ||
1987 | lay.addWidget( &pb ); | ||
1988 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | ||
1989 | dia.show(); | ||
1990 | int res = dia.exec(); | ||
1991 | if ( !res ) { | ||
1992 | setCaption( i18n("Syncing cancelled!") ); | ||
1993 | return; | ||
1994 | } | ||
1995 | mPassWordPiSync = lepw.text(); | ||
1996 | dia.hide(); | ||
1997 | KOPrefs::instance()->mActiveSyncPort = lab2.text(); | ||
1998 | KOPrefs::instance()->mActiveSyncIP = lab.text(); | ||
1999 | qApp->processEvents(); | 1959 | qApp->processEvents(); |
2000 | performQuickQuick(); | 1960 | performQuickQuick(); |
2001 | } | 1961 | } |
2002 | 1962 | ||
2003 | void MainWindow::performQuickQuick() | 1963 | void MainWindow::performQuickQuick() |
2004 | { | 1964 | { |
2005 | // setCaption( i18n("") ); | 1965 | // setCaption( i18n("") ); |
2006 | 1966 | ||
2007 | bool ok; | 1967 | bool ok; |
2008 | Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); | 1968 | Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); |
2009 | if ( ! ok ) { | 1969 | if ( ! ok ) { |
2010 | setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1970 | setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
@@ -2368,56 +2328,54 @@ void MainWindow::printCal() | |||
2368 | 2328 | ||
2369 | 2329 | ||
2370 | 2330 | ||
2371 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 2331 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
2372 | { | 2332 | { |
2373 | mPassWord = pw; | 2333 | mPassWord = pw; |
2374 | mSocket = 0; | 2334 | mSocket = 0; |
2375 | mSyncActionDialog = 0; | 2335 | mSyncActionDialog = 0; |
2376 | }; | 2336 | }; |
2377 | 2337 | ||
2378 | void KServerSocket::newConnection ( int socket ) | 2338 | void KServerSocket::newConnection ( int socket ) |
2379 | { | 2339 | { |
2380 | qDebug("KServerSocket:New connection %d ", socket); | 2340 | // qDebug("KServerSocket:New connection %d ", socket); |
2381 | if ( mSocket ) { | 2341 | if ( mSocket ) { |
2382 | qDebug("KServerSocket::newConnection Socket deleted! "); | 2342 | qDebug("KServerSocket::newConnection Socket deleted! "); |
2383 | delete mSocket; | 2343 | delete mSocket; |
2384 | mSocket = 0; | 2344 | mSocket = 0; |
2385 | } | 2345 | } |
2386 | mSocket = new QSocket( this ); | 2346 | mSocket = new QSocket( this ); |
2387 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 2347 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
2388 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 2348 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
2389 | mSocket->setSocket( socket ); | 2349 | mSocket->setSocket( socket ); |
2390 | } | 2350 | } |
2391 | 2351 | ||
2392 | void KServerSocket::discardClient() | 2352 | void KServerSocket::discardClient() |
2393 | { | 2353 | { |
2394 | qDebug(" KServerSocket::discardClient()"); | 2354 | //qDebug(" KServerSocket::discardClient()"); |
2395 | if ( mSocket ) { | 2355 | if ( mSocket ) { |
2396 | qDebug("delete "); | ||
2397 | delete mSocket; | 2356 | delete mSocket; |
2398 | mSocket = 0; | 2357 | mSocket = 0; |
2399 | } | 2358 | } |
2400 | //emit endConnect(); | 2359 | //emit endConnect(); |
2401 | } | 2360 | } |
2402 | void KServerSocket::readClient() | 2361 | void KServerSocket::readClient() |
2403 | { | 2362 | { |
2404 | if ( mSocket == 0 ) { | 2363 | if ( mSocket == 0 ) { |
2405 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 2364 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
2406 | return; | 2365 | return; |
2407 | } | 2366 | } |
2408 | qDebug("KServerSocket readClient()"); | 2367 | //qDebug("KServerSocket readClient()"); |
2409 | if ( mSocket->canReadLine() ) { | 2368 | if ( mSocket->canReadLine() ) { |
2410 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); | 2369 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); |
2411 | qDebug("KServerSocket socket->canReadLine()"); | ||
2412 | if ( tokens[0] == "GET" ) { | 2370 | if ( tokens[0] == "GET" ) { |
2413 | if ( tokens[1] == mPassWord ) | 2371 | if ( tokens[1] == mPassWord ) |
2414 | //emit sendFile( mSocket ); | 2372 | //emit sendFile( mSocket ); |
2415 | send_file(); | 2373 | send_file(); |
2416 | else { | 2374 | else { |
2417 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); | 2375 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); |
2418 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 2376 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
2419 | } | 2377 | } |
2420 | } | 2378 | } |
2421 | if ( tokens[0] == "PUT" ) { | 2379 | if ( tokens[0] == "PUT" ) { |
2422 | if ( tokens[1] == mPassWord ) | 2380 | if ( tokens[1] == mPassWord ) |
2423 | //emit getFile( mSocket ); | 2381 | //emit getFile( mSocket ); |
@@ -2431,25 +2389,25 @@ void KServerSocket::readClient() | |||
2431 | //emit endConnect(); | 2389 | //emit endConnect(); |
2432 | end_connect(); | 2390 | end_connect(); |
2433 | } | 2391 | } |
2434 | } | 2392 | } |
2435 | } | 2393 | } |
2436 | void KServerSocket::end_connect() | 2394 | void KServerSocket::end_connect() |
2437 | { | 2395 | { |
2438 | delete mSyncActionDialog; | 2396 | delete mSyncActionDialog; |
2439 | mSyncActionDialog = 0; | 2397 | mSyncActionDialog = 0; |
2440 | } | 2398 | } |
2441 | void KServerSocket::send_file() | 2399 | void KServerSocket::send_file() |
2442 | { | 2400 | { |
2443 | qDebug("MainWindow::sendFile(QSocket* s) "); | 2401 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
2444 | if ( mSyncActionDialog ) | 2402 | if ( mSyncActionDialog ) |
2445 | delete mSyncActionDialog; | 2403 | delete mSyncActionDialog; |
2446 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 2404 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
2447 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 2405 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
2448 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog ); | 2406 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog ); |
2449 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 2407 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
2450 | lay->addWidget( label); | 2408 | lay->addWidget( label); |
2451 | lay->setMargin(7); | 2409 | lay->setMargin(7); |
2452 | lay->setSpacing(7); | 2410 | lay->setSpacing(7); |
2453 | mSyncActionDialog->setFixedSize( 230, 120); | 2411 | mSyncActionDialog->setFixedSize( 230, 120); |
2454 | mSyncActionDialog->show(); | 2412 | mSyncActionDialog->show(); |
2455 | qDebug("KSS::saving ... "); | 2413 | qDebug("KSS::saving ... "); |
@@ -2469,73 +2427,71 @@ void KServerSocket::send_file() | |||
2469 | } | 2427 | } |
2470 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 2428 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
2471 | QTextStream ts( &file ); | 2429 | QTextStream ts( &file ); |
2472 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2430 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2473 | QTextStream os( mSocket ); | 2431 | QTextStream os( mSocket ); |
2474 | os.setCodec( QTextCodec::codecForName("utf8") ); | 2432 | os.setCodec( QTextCodec::codecForName("utf8") ); |
2475 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 2433 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
2476 | while ( ! ts.atEnd() ) { | 2434 | while ( ! ts.atEnd() ) { |
2477 | os << ts.readLine() << "\n"; | 2435 | os << ts.readLine() << "\n"; |
2478 | } | 2436 | } |
2479 | //os << ts.read(); | 2437 | //os << ts.read(); |
2480 | file.close(); | 2438 | file.close(); |
2481 | mSyncActionDialog->setCaption( i18n("Waiting to get back synced file") ); | 2439 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
2482 | qDebug("file sent "); | ||
2483 | mSocket->close(); | 2440 | mSocket->close(); |
2484 | if ( mSocket->state() == QSocket::Idle ) | 2441 | if ( mSocket->state() == QSocket::Idle ) |
2485 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 2442 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
2486 | } | 2443 | } |
2487 | void KServerSocket::get_file() | 2444 | void KServerSocket::get_file() |
2488 | { | 2445 | { |
2489 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 2446 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
2490 | 2447 | ||
2491 | piTime.start(); | 2448 | piTime.start(); |
2492 | piFileString = ""; | 2449 | piFileString = ""; |
2493 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 2450 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
2494 | } | 2451 | } |
2495 | 2452 | ||
2496 | 2453 | ||
2497 | void KServerSocket::readBackFileFromSocket() | 2454 | void KServerSocket::readBackFileFromSocket() |
2498 | { | 2455 | { |
2499 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 2456 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
2500 | while ( mSocket->canReadLine () ) { | 2457 | while ( mSocket->canReadLine () ) { |
2501 | piTime.restart(); | 2458 | piTime.restart(); |
2502 | QString line = mSocket->readLine (); | 2459 | QString line = mSocket->readLine (); |
2503 | piFileString += line; | 2460 | piFileString += line; |
2504 | qDebug("readline: %s ", line.latin1()); | 2461 | //qDebug("readline: %s ", line.latin1()); |
2505 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 2462 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
2506 | 2463 | ||
2507 | } | 2464 | } |
2508 | if ( piTime.elapsed () < 3000 ) { | 2465 | if ( piTime.elapsed () < 3000 ) { |
2509 | // wait for more | 2466 | // wait for more |
2510 | qDebug("waitformore "); | 2467 | //qDebug("waitformore "); |
2511 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 2468 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
2512 | return; | 2469 | return; |
2513 | } | 2470 | } |
2514 | QString fileName = mFileName; | 2471 | QString fileName = mFileName; |
2515 | QFile file ( fileName ); | 2472 | QFile file ( fileName ); |
2516 | if (!file.open( IO_WriteOnly ) ) { | 2473 | if (!file.open( IO_WriteOnly ) ) { |
2517 | delete mSyncActionDialog; | 2474 | delete mSyncActionDialog; |
2518 | mSyncActionDialog = 0; | 2475 | mSyncActionDialog = 0; |
2519 | qDebug("error open cal file "); | 2476 | qDebug("error open cal file "); |
2520 | piFileString = ""; | 2477 | piFileString = ""; |
2521 | emit file_received( false ); | 2478 | emit file_received( false ); |
2522 | return ; | 2479 | return ; |
2523 | 2480 | ||
2524 | } | 2481 | } |
2525 | 2482 | ||
2526 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 2483 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
2527 | QTextStream ts ( &file ); | 2484 | QTextStream ts ( &file ); |
2528 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2485 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2529 | qDebug("finish "); | ||
2530 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 2486 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
2531 | ts << piFileString; | 2487 | ts << piFileString; |
2532 | mSocket->close(); | 2488 | mSocket->close(); |
2533 | if ( mSocket->state() == QSocket::Idle ) | 2489 | if ( mSocket->state() == QSocket::Idle ) |
2534 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 2490 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
2535 | file.close(); | 2491 | file.close(); |
2536 | delete mSyncActionDialog; | 2492 | delete mSyncActionDialog; |
2537 | mSyncActionDialog = 0; | 2493 | mSyncActionDialog = 0; |
2538 | piFileString = ""; | 2494 | piFileString = ""; |
2539 | emit file_received( true ); | 2495 | emit file_received( true ); |
2540 | 2496 | ||
2541 | } | 2497 | } |
@@ -2572,106 +2528,108 @@ void KCommandSocket::writeFile( QString fileName ) | |||
2572 | { | 2528 | { |
2573 | QFile file2( fileName ); | 2529 | QFile file2( fileName ); |
2574 | if (!file2.open( IO_ReadOnly ) ) { | 2530 | if (!file2.open( IO_ReadOnly ) ) { |
2575 | mRetVal= false; | 2531 | mRetVal= false; |
2576 | deleteSocket(); | 2532 | deleteSocket(); |
2577 | return ; | 2533 | return ; |
2578 | 2534 | ||
2579 | } | 2535 | } |
2580 | if ( !mSocket ) { | 2536 | if ( !mSocket ) { |
2581 | mSocket = new QSocket( this ); | 2537 | mSocket = new QSocket( this ); |
2582 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2538 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2583 | } | 2539 | } |
2540 | mSocket->connectToHost( mHost, mPort ); | ||
2584 | QTextStream ts2( &file2 ); | 2541 | QTextStream ts2( &file2 ); |
2585 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | 2542 | ts2.setCodec( QTextCodec::codecForName("utf8") ); |
2586 | QTextStream os2( mSocket ); | 2543 | QTextStream os2( mSocket ); |
2587 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 2544 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
2588 | os2 << "PUT " << mPassWord << "\r\n";; | 2545 | os2 << "PUT " << mPassWord << "\r\n";; |
2589 | while ( ! ts2.atEnd() ) { | 2546 | while ( ! ts2.atEnd() ) { |
2590 | os2 << ts2.readLine() << "\n"; | 2547 | os2 << ts2.readLine() << "\n"; |
2591 | } | 2548 | } |
2549 | mRetVal= true; | ||
2592 | mSocket->close(); | 2550 | mSocket->close(); |
2593 | if ( mSocket->state() == QSocket::Idle ) | 2551 | if ( mSocket->state() == QSocket::Idle ) |
2594 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 2552 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
2595 | file2.close(); | 2553 | file2.close(); |
2596 | } | 2554 | } |
2597 | 2555 | ||
2598 | void KCommandSocket::sendStop() | 2556 | void KCommandSocket::sendStop() |
2599 | { | 2557 | { |
2600 | if ( !mSocket ) { | 2558 | if ( !mSocket ) { |
2601 | mSocket = new QSocket( this ); | 2559 | mSocket = new QSocket( this ); |
2602 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2560 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2603 | } | 2561 | } |
2562 | mSocket->connectToHost( mHost, mPort ); | ||
2604 | QTextStream os2( mSocket ); | 2563 | QTextStream os2( mSocket ); |
2605 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 2564 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
2606 | os2 << "STOP\r\n"; | 2565 | os2 << "STOP\r\n"; |
2607 | mRetVal= true; | 2566 | mRetVal= true; |
2608 | mSocket->close(); | 2567 | mSocket->close(); |
2609 | if ( mSocket->state() == QSocket::Idle ) | 2568 | if ( mSocket->state() == QSocket::Idle ) |
2610 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 2569 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
2611 | } | 2570 | } |
2612 | 2571 | ||
2613 | void KCommandSocket::startReadFileFromSocket() | 2572 | void KCommandSocket::startReadFileFromSocket() |
2614 | { | 2573 | { |
2615 | if ( ! mFirst ) | 2574 | if ( ! mFirst ) |
2616 | return; | 2575 | return; |
2617 | mFirst = false; | 2576 | mFirst = false; |
2618 | mTimerSocket->stop(); | 2577 | mTimerSocket->stop(); |
2619 | mFileString = ""; | 2578 | mFileString = ""; |
2620 | mTime.start(); | 2579 | mTime.start(); |
2621 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 2580 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
2622 | 2581 | ||
2623 | } | 2582 | } |
2624 | void KCommandSocket::readFileFromSocket() | 2583 | void KCommandSocket::readFileFromSocket() |
2625 | { | 2584 | { |
2626 | qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 2585 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
2627 | while ( mSocket->canReadLine () ) { | 2586 | while ( mSocket->canReadLine () ) { |
2628 | mTime.restart(); | 2587 | mTime.restart(); |
2629 | QString line = mSocket->readLine (); | 2588 | QString line = mSocket->readLine (); |
2630 | mFileString += line; | 2589 | mFileString += line; |
2631 | qDebug("readline: %s ", line.latin1()); | 2590 | //qDebug("readline: %s ", line.latin1()); |
2632 | } | 2591 | } |
2633 | if ( mTime.elapsed () < 3000 ) { | 2592 | if ( mTime.elapsed () < 3000 ) { |
2634 | // wait for more | 2593 | // wait for more |
2635 | qDebug("waitformore "); | 2594 | //qDebug("waitformore "); |
2636 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 2595 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
2637 | return; | 2596 | return; |
2638 | } | 2597 | } |
2639 | QString fileName = mFileName; | 2598 | QString fileName = mFileName; |
2640 | QFile file ( fileName ); | 2599 | QFile file ( fileName ); |
2641 | if (!file.open( IO_WriteOnly ) ) { | 2600 | if (!file.open( IO_WriteOnly ) ) { |
2642 | mFileString = ""; | 2601 | mFileString = ""; |
2643 | mRetVal = false; | 2602 | mRetVal = false; |
2644 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); | 2603 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); |
2645 | deleteSocket(); | 2604 | deleteSocket(); |
2646 | return ; | 2605 | return ; |
2647 | 2606 | ||
2648 | } | 2607 | } |
2649 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 2608 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
2650 | QTextStream ts ( &file ); | 2609 | QTextStream ts ( &file ); |
2651 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2610 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2652 | qDebug("finish "); | ||
2653 | ts << mFileString; | 2611 | ts << mFileString; |
2654 | file.close(); | 2612 | file.close(); |
2655 | mFileString = ""; | 2613 | mFileString = ""; |
2656 | mRetVal = true; | 2614 | mRetVal = true; |
2657 | mSocket->close(); | 2615 | mSocket->close(); |
2658 | // if state is not idle, deleteSocket(); is called via | 2616 | // if state is not idle, deleteSocket(); is called via |
2659 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2617 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2660 | if ( mSocket->state() == QSocket::Idle ) | 2618 | if ( mSocket->state() == QSocket::Idle ) |
2661 | deleteSocket(); | 2619 | deleteSocket(); |
2662 | } | 2620 | } |
2663 | 2621 | ||
2664 | void KCommandSocket::deleteSocket() | 2622 | void KCommandSocket::deleteSocket() |
2665 | { | 2623 | { |
2666 | if ( mTimerSocket->isActive () ) { | 2624 | if ( mTimerSocket->isActive () ) { |
2667 | mTimerSocket->stop(); | 2625 | mTimerSocket->stop(); |
2668 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 2626 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
2669 | mRetVal = false; | 2627 | mRetVal = false; |
2670 | } | 2628 | } |
2671 | qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 2629 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
2672 | if ( mSocket) | 2630 | if ( mSocket) |
2673 | delete mSocket; | 2631 | delete mSocket; |
2674 | mSocket = 0; | 2632 | mSocket = 0; |
2675 | emit commandFinished( this, mRetVal ); | 2633 | emit commandFinished( this, mRetVal ); |
2676 | } | 2634 | } |
2677 | 2635 | ||