summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-11-25 19:44:15 (UTC)
committer zautrix <zautrix>2005-11-25 19:44:15 (UTC)
commit7a439999b9fa2bd7ad76e195cdf95bf5211952cb (patch) (unidiff)
tree88c7e5771ed955004b6ef3b74c339e6b44b8a7ad
parent231e6f8215bbc4f7e301965f8f3c650e44586ec9 (diff)
downloadkdepimpi-7a439999b9fa2bd7ad76e195cdf95bf5211952cb.zip
kdepimpi-7a439999b9fa2bd7ad76e195cdf95bf5211952cb.tar.gz
kdepimpi-7a439999b9fa2bd7ad76e195cdf95bf5211952cb.tar.bz2
sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koprefs.cpp8
-rw-r--r--libkdepim/ksyncmanager.cpp13
2 files changed, 18 insertions, 3 deletions
diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp
index 31ef338..9147af3 100644
--- a/korganizer/koprefs.cpp
+++ b/korganizer/koprefs.cpp
@@ -443,192 +443,200 @@ void KOPrefs::usrReadConfig()
443 config()->setGroup("Personal Settings"); 443 config()->setGroup("Personal Settings");
444 mName = config()->readEntry("user_name",""); 444 mName = config()->readEntry("user_name","");
445 mEmail = config()->readEntry("user_email",""); 445 mEmail = config()->readEntry("user_email","");
446 fillMailDefaults(); 446 fillMailDefaults();
447 447
448 config()->setGroup("Category Colors"); 448 config()->setGroup("Category Colors");
449 QStringList::Iterator it; 449 QStringList::Iterator it;
450 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { 450 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) {
451 setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor)); 451 setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor));
452 452
453 } 453 }
454 KConfig fc (locateLocal("config","kopicalendarrc")); 454 KConfig fc (locateLocal("config","kopicalendarrc"));
455 fc.setGroup("CC"); 455 fc.setGroup("CC");
456 int numCals = fc.readNumEntry("NumberCalendars",0 ); 456 int numCals = fc.readNumEntry("NumberCalendars",0 );
457 mNextAvailableCalendar = 1; 457 mNextAvailableCalendar = 1;
458 if ( numCals == 0 ) { 458 if ( numCals == 0 ) {
459 KopiCalendarFile *kkf = getNewCalendar(); 459 KopiCalendarFile *kkf = getNewCalendar();
460 kkf->isStandard = true; 460 kkf->isStandard = true;
461 kkf->mName = i18n("Standard"); 461 kkf->mName = i18n("Standard");
462 kkf->mFileName = QDir::convertSeparators( locateLocal( "data", "korganizer/mycalendar.ics" ) ); 462 kkf->mFileName = QDir::convertSeparators( locateLocal( "data", "korganizer/mycalendar.ics" ) );
463 } 463 }
464 while ( mNextAvailableCalendar <= numCals ) { 464 while ( mNextAvailableCalendar <= numCals ) {
465 //qDebug("Read cal #%d ", mNextAvailableCalendar ); 465 //qDebug("Read cal #%d ", mNextAvailableCalendar );
466 QString prefix = "Cal_" +QString::number( mNextAvailableCalendar ); 466 QString prefix = "Cal_" +QString::number( mNextAvailableCalendar );
467 KopiCalendarFile *kkf = getNewCalendar(); 467 KopiCalendarFile *kkf = getNewCalendar();
468 kkf->isStandard = fc.readBoolEntry( prefix+"_isStandard", false ); 468 kkf->isStandard = fc.readBoolEntry( prefix+"_isStandard", false );
469 kkf->isEnabled = fc.readBoolEntry( prefix+"_isEnabled", true); 469 kkf->isEnabled = fc.readBoolEntry( prefix+"_isEnabled", true);
470 kkf->isRelative = fc.readBoolEntry( prefix+"_isRelative", false ); 470 kkf->isRelative = fc.readBoolEntry( prefix+"_isRelative", false );
471 kkf->isAlarmEnabled = fc.readBoolEntry( prefix+"_isAlarmEnabled", true); 471 kkf->isAlarmEnabled = fc.readBoolEntry( prefix+"_isAlarmEnabled", true);
472 kkf->isReadOnly = fc.readBoolEntry( prefix+"_isReadOnly", false); 472 kkf->isReadOnly = fc.readBoolEntry( prefix+"_isReadOnly", false);
473 kkf->mName = fc.readEntry( prefix+"_Name", "Calendar"); 473 kkf->mName = fc.readEntry( prefix+"_Name", "Calendar");
474 kkf->mFileName = QDir::convertSeparators( fc.readEntry( prefix+"_FileName", kkf->mFileName) ); 474 kkf->mFileName = QDir::convertSeparators( fc.readEntry( prefix+"_FileName", kkf->mFileName) );
475 kkf->mSavedFileName = QDir::convertSeparators( fc.readEntry( prefix+"_SavedFileName", kkf->mFileName) ); 475 kkf->mSavedFileName = QDir::convertSeparators( fc.readEntry( prefix+"_SavedFileName", kkf->mFileName) );
476 kkf->mDefaultColor = fc.readColorEntry( prefix+"_Color",&mEventColor); 476 kkf->mDefaultColor = fc.readColorEntry( prefix+"_Color",&mEventColor);
477 if ( kkf->mCalNumber == 1 ) { 477 if ( kkf->mCalNumber == 1 ) {
478 kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" ); 478 kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" );
479 } 479 }
480 //qDebug("NAME %s %s", kkf->mName.latin1(), i18n("Birthdays").latin1() ); 480 //qDebug("NAME %s %s", kkf->mName.latin1(), i18n("Birthdays").latin1() );
481 if ( kkf->mName == i18n("Birthdays") ) { 481 if ( kkf->mName == i18n("Birthdays") ) {
482 kkf->mFileName = locateLocal( "data", "korganizer/birthdays.ics" ); 482 kkf->mFileName = locateLocal( "data", "korganizer/birthdays.ics" );
483 } 483 }
484 if ( kkf->isRelative ) 484 if ( kkf->isRelative )
485 kkf->mFileName = QDir::convertSeparators( KGlobalSettings::calendarDir() + kkf->mSavedFileName ); 485 kkf->mFileName = QDir::convertSeparators( KGlobalSettings::calendarDir() + kkf->mSavedFileName );
486 } 486 }
487 487
488 KPimPrefs::usrReadConfig(); 488 KPimPrefs::usrReadConfig();
489} 489}
490 490
491KopiCalendarFile * KOPrefs::getCalendar( int num ) 491KopiCalendarFile * KOPrefs::getCalendar( int num )
492{ 492{
493 return mDefCalColors[num-1]; 493 return mDefCalColors[num-1];
494} 494}
495 495
496KopiCalendarFile * KOPrefs::getNewCalendar() 496KopiCalendarFile * KOPrefs::getNewCalendar()
497{ 497{
498 KopiCalendarFile * kkf = new KopiCalendarFile(); 498 KopiCalendarFile * kkf = new KopiCalendarFile();
499 kkf->mCalNumber = mNextAvailableCalendar; 499 kkf->mCalNumber = mNextAvailableCalendar;
500 mDefCalColors.resize( mNextAvailableCalendar ); 500 mDefCalColors.resize( mNextAvailableCalendar );
501 mDefCalColors[mNextAvailableCalendar-1] = kkf; 501 mDefCalColors[mNextAvailableCalendar-1] = kkf;
502 ++mNextAvailableCalendar; 502 ++mNextAvailableCalendar;
503 kkf->mDefaultColor = mEventColor; 503 kkf->mDefaultColor = mEventColor;
504 kkf->mName = i18n("New Calendar"); 504 kkf->mName = i18n("New Calendar");
505 mCalendars.append( kkf ); 505 mCalendars.append( kkf );
506 return kkf; 506 return kkf;
507} 507}
508void KOPrefs::deleteCalendar( int num ) 508void KOPrefs::deleteCalendar( int num )
509{ 509{
510 KopiCalendarFile * kkf = mCalendars.first(); 510 KopiCalendarFile * kkf = mCalendars.first();
511 while ( kkf ) { 511 while ( kkf ) {
512 if ( kkf->mCalNumber == num ) { 512 if ( kkf->mCalNumber == num ) {
513 qDebug("KOPrefs::deleteCalendar %d ", num ); 513 qDebug("KOPrefs::deleteCalendar %d ", num );
514 mCalendars.remove( kkf ); 514 mCalendars.remove( kkf );
515 delete kkf; 515 delete kkf;
516 return; 516 return;
517 } 517 }
518 kkf = mCalendars.next(); 518 kkf = mCalendars.next();
519 } 519 }
520} 520}
521int KOPrefs::getCalendarID( const QString & name ) 521int KOPrefs::getCalendarID( const QString & name )
522{ 522{
523 KopiCalendarFile * kkf = mCalendars.first(); 523 KopiCalendarFile * kkf = mCalendars.first();
524 while ( kkf ) { 524 while ( kkf ) {
525 if ( name == kkf->mName) 525 if ( name == kkf->mName)
526 return kkf->mCalNumber; 526 return kkf->mCalNumber;
527 kkf = mCalendars.next(); 527 kkf = mCalendars.next();
528 } 528 }
529 return 1; 529 return 1;
530} 530}
531int KOPrefs::getFuzzyCalendarID( const QString & name ) 531int KOPrefs::getFuzzyCalendarID( const QString & name )
532{ 532{
533 KopiCalendarFile * kkf = mCalendars.first(); 533 KopiCalendarFile * kkf = mCalendars.first();
534 while ( kkf ) { 534 while ( kkf ) {
535 if ( name.lower() == kkf->mName.lower()) 535 if ( name.lower() == kkf->mName.lower())
536 return kkf->mCalNumber; 536 return kkf->mCalNumber;
537 kkf = mCalendars.next(); 537 kkf = mCalendars.next();
538 } 538 }
539 QString name2 = name;
540 name2.replace (QRegExp ("_")," " );
541 kkf = mCalendars.first();
542 while ( kkf ) {
543 if ( name2.lower() == kkf->mName.lower())
544 return kkf->mCalNumber;
545 kkf = mCalendars.next();
546 }
539 return 0; 547 return 0;
540} 548}
541QString KOPrefs::calName( int calNum) const 549QString KOPrefs::calName( int calNum) const
542{ 550{
543 return (mDefCalColors[calNum-1])->mName; 551 return (mDefCalColors[calNum-1])->mName;
544} 552}
545QColor KOPrefs::defaultColor( int calNum ) const 553QColor KOPrefs::defaultColor( int calNum ) const
546{ 554{
547 if ( calNum == 1 ) return mEventColor; 555 if ( calNum == 1 ) return mEventColor;
548 return (mDefCalColors[calNum-1])->mDefaultColor; 556 return (mDefCalColors[calNum-1])->mDefaultColor;
549} 557}
550void KOPrefs::usrWriteConfig() 558void KOPrefs::usrWriteConfig()
551{ 559{
552 config()->setGroup("General"); 560 config()->setGroup("General");
553 config()->writeEntry("Custom Categories",mCustomCategories); 561 config()->writeEntry("Custom Categories",mCustomCategories);
554 562
555 config()->setGroup("Personal Settings"); 563 config()->setGroup("Personal Settings");
556 config()->writeEntry("user_name",mName); 564 config()->writeEntry("user_name",mName);
557 config()->writeEntry("user_email",mEmail); 565 config()->writeEntry("user_email",mEmail);
558 566
559 config()->setGroup("Category Colors"); 567 config()->setGroup("Category Colors");
560 QDictIterator<QColor> it(mCategoryColors); 568 QDictIterator<QColor> it(mCategoryColors);
561 while (it.current()) { 569 while (it.current()) {
562 config()->writeEntry(it.currentKey(),*(it.current())); 570 config()->writeEntry(it.currentKey(),*(it.current()));
563 ++it; 571 ++it;
564 } 572 }
565 KConfig fc (locateLocal("config","kopicalendarrc")); 573 KConfig fc (locateLocal("config","kopicalendarrc"));
566 fc.setGroup("CC"); 574 fc.setGroup("CC");
567 fc.deleteGroup( "CC"); 575 fc.deleteGroup( "CC");
568 fc.setGroup("CC"); 576 fc.setGroup("CC");
569 fc.writeEntry("NumberCalendars",mCalendars.count()); 577 fc.writeEntry("NumberCalendars",mCalendars.count());
570 int numCal = 1; 578 int numCal = 1;
571 int writeCal = 0; 579 int writeCal = 0;
572 while ( numCal < mNextAvailableCalendar ) { 580 while ( numCal < mNextAvailableCalendar ) {
573 KopiCalendarFile * kkf = mCalendars.first(); 581 KopiCalendarFile * kkf = mCalendars.first();
574 while ( kkf ) { 582 while ( kkf ) {
575 //qDebug("cal num %d %d ", kkf->mCalNumber, numCal); 583 //qDebug("cal num %d %d ", kkf->mCalNumber, numCal);
576 if ( kkf->mCalNumber == numCal ) { 584 if ( kkf->mCalNumber == numCal ) {
577 ++writeCal; 585 ++writeCal;
578 //qDebug("Write calendar %d %d ", numCal , writeCal); 586 //qDebug("Write calendar %d %d ", numCal , writeCal);
579 QString prefix = "Cal_" + QString::number( writeCal ); 587 QString prefix = "Cal_" + QString::number( writeCal );
580 fc.writeEntry( prefix+"_isStandard", kkf->isStandard ); 588 fc.writeEntry( prefix+"_isStandard", kkf->isStandard );
581 fc.writeEntry( prefix+"_isEnabled", kkf->isEnabled ); 589 fc.writeEntry( prefix+"_isEnabled", kkf->isEnabled );
582 fc.writeEntry( prefix+"_isAlarmEnabled", kkf->isAlarmEnabled ); 590 fc.writeEntry( prefix+"_isAlarmEnabled", kkf->isAlarmEnabled );
583 fc.writeEntry( prefix+"_isReadOnly", kkf->isReadOnly ); 591 fc.writeEntry( prefix+"_isReadOnly", kkf->isReadOnly );
584 fc.writeEntry( prefix+"_isRelative", kkf->isRelative ); 592 fc.writeEntry( prefix+"_isRelative", kkf->isRelative );
585 fc.writeEntry( prefix+"_Name", kkf->mName); 593 fc.writeEntry( prefix+"_Name", kkf->mName);
586 fc.writeEntry( prefix+"_FileName", kkf->mFileName); 594 fc.writeEntry( prefix+"_FileName", kkf->mFileName);
587 fc.writeEntry( prefix+"_SavedFileName", kkf->mSavedFileName); 595 fc.writeEntry( prefix+"_SavedFileName", kkf->mSavedFileName);
588 fc.writeEntry( prefix+"_Color",kkf->mDefaultColor); 596 fc.writeEntry( prefix+"_Color",kkf->mDefaultColor);
589 } 597 }
590 kkf = mCalendars.next(); 598 kkf = mCalendars.next();
591 } 599 }
592 ++numCal; 600 ++numCal;
593 } 601 }
594 fc.sync(); 602 fc.sync();
595 KPimPrefs::usrWriteConfig(); 603 KPimPrefs::usrWriteConfig();
596} 604}
597 605
598void KOPrefs::setCategoryColor(QString cat,const QColor & color) 606void KOPrefs::setCategoryColor(QString cat,const QColor & color)
599{ 607{
600 mCategoryColors.replace(cat,new QColor(color)); 608 mCategoryColors.replace(cat,new QColor(color));
601} 609}
602 610
603QColor *KOPrefs::categoryColor(QString cat) 611QColor *KOPrefs::categoryColor(QString cat)
604{ 612{
605 QColor *color = 0; 613 QColor *color = 0;
606 614
607 if (!cat.isEmpty()) color = mCategoryColors[cat]; 615 if (!cat.isEmpty()) color = mCategoryColors[cat];
608 616
609 if (color) return color; 617 if (color) return color;
610 else return &mDefaultCategoryColor; 618 else return &mDefaultCategoryColor;
611} 619}
612 620
613void KOPrefs::setFullName(const QString &name) 621void KOPrefs::setFullName(const QString &name)
614{ 622{
615 mName = name; 623 mName = name;
616} 624}
617 625
618void KOPrefs::setEmail(const QString &email) 626void KOPrefs::setEmail(const QString &email)
619{ 627{
620 //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() ); 628 //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() );
621 mEmail = email; 629 mEmail = email;
622} 630}
623 631
624QString KOPrefs::fullName() 632QString KOPrefs::fullName()
625{ 633{
626 if (mEmailControlCenter) { 634 if (mEmailControlCenter) {
627 KEMailSettings settings; 635 KEMailSettings settings;
628 return settings.getSetting(KEMailSettings::RealName); 636 return settings.getSetting(KEMailSettings::RealName);
629 } else { 637 } else {
630 return mName; 638 return mName;
631 } 639 }
632} 640}
633 641
634QString KOPrefs::email() 642QString KOPrefs::email()
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 61a9899..795cd30 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1047,220 +1047,225 @@ bool KSyncManager::syncExternalApplication(QString resource)
1047 if ( !edit_sync_options()) { 1047 if ( !edit_sync_options()) {
1048 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1048 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1049 return false; 1049 return false;
1050 } 1050 }
1051 1051
1052 qDebug("KSM::Sync extern %s", resource.latin1()); 1052 qDebug("KSM::Sync extern %s", resource.latin1());
1053 1053
1054 bool syncOK = mImplementation->syncExternal(this, resource); 1054 bool syncOK = mImplementation->syncExternal(this, resource);
1055 1055
1056 return syncOK; 1056 return syncOK;
1057 1057
1058} 1058}
1059 1059
1060void KSyncManager::syncPhone() 1060void KSyncManager::syncPhone()
1061{ 1061{
1062 1062
1063 syncExternalApplication("phone"); 1063 syncExternalApplication("phone");
1064 1064
1065} 1065}
1066 1066
1067void KSyncManager::showProgressBar(int percentage, QString caption, int total) 1067void KSyncManager::showProgressBar(int percentage, QString caption, int total)
1068{ 1068{
1069 if (!bar->isVisible()) 1069 if (!bar->isVisible())
1070 { 1070 {
1071 int w = 300; 1071 int w = 300;
1072 if ( QApplication::desktop()->width() < 320 ) 1072 if ( QApplication::desktop()->width() < 320 )
1073 w = 220; 1073 w = 220;
1074 int h = bar->sizeHint().height() ; 1074 int h = bar->sizeHint().height() ;
1075 int dw = QApplication::desktop()->width(); 1075 int dw = QApplication::desktop()->width();
1076 int dh = QApplication::desktop()->height(); 1076 int dh = QApplication::desktop()->height();
1077 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1077 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1078 bar->setCaption (caption); 1078 bar->setCaption (caption);
1079 bar->setTotalSteps ( total ) ; 1079 bar->setTotalSteps ( total ) ;
1080 bar->show(); 1080 bar->show();
1081 } 1081 }
1082 bar->raise(); 1082 bar->raise();
1083 bar->setProgress( percentage ); 1083 bar->setProgress( percentage );
1084 qApp->processEvents(); 1084 qApp->processEvents();
1085} 1085}
1086 1086
1087void KSyncManager::hideProgressBar() 1087void KSyncManager::hideProgressBar()
1088{ 1088{
1089 bar->hide(); 1089 bar->hide();
1090 qApp->processEvents(); 1090 qApp->processEvents();
1091} 1091}
1092 1092
1093bool KSyncManager::isProgressBarCanceled() 1093bool KSyncManager::isProgressBarCanceled()
1094{ 1094{
1095 return !bar->isVisible(); 1095 return !bar->isVisible();
1096} 1096}
1097 1097
1098QString KSyncManager::syncFileName() 1098QString KSyncManager::syncFileName()
1099{ 1099{
1100 1100
1101 QString fn = "tempfile"; 1101 QString fn = "tempfile";
1102 switch(mTargetApp) 1102 switch(mTargetApp)
1103 { 1103 {
1104 case (KAPI): 1104 case (KAPI):
1105 fn = "tempsyncab.vcf"; 1105 fn = "tempsyncab.vcf";
1106 break; 1106 break;
1107 case (KOPI): 1107 case (KOPI):
1108 fn = "tempsynccal.ics"; 1108 fn = "tempsynccal.ics";
1109 break; 1109 break;
1110 case (PWMPI): 1110 case (PWMPI):
1111 fn = "tempsyncpw.pwm"; 1111 fn = "tempsyncpw.pwm";
1112 break; 1112 break;
1113 default: 1113 default:
1114 break; 1114 break;
1115 } 1115 }
1116#ifdef DESKTOP_VERSION 1116#ifdef DESKTOP_VERSION
1117 return locateLocal( "tmp", fn ); 1117 return locateLocal( "tmp", fn );
1118#else 1118#else
1119 return (QString( "/tmp/" )+ fn ); 1119 return (QString( "/tmp/" )+ fn );
1120#endif 1120#endif
1121} 1121}
1122 1122
1123void KSyncManager::syncPi() 1123void KSyncManager::syncPi()
1124{ 1124{
1125 mIsKapiFile = true; 1125 mIsKapiFile = true;
1126 mPisyncFinished = false; 1126 mPisyncFinished = false;
1127 qApp->processEvents(); 1127 qApp->processEvents();
1128 if ( mAskForPreferences ) 1128 if ( mAskForPreferences )
1129 if ( !edit_pisync_options()) { 1129 if ( !edit_pisync_options()) {
1130 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1130 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1131 mPisyncFinished = true; 1131 mPisyncFinished = true;
1132 return; 1132 return;
1133 } 1133 }
1134 bool ok; 1134 bool ok;
1135 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1135 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1136 if ( ! ok ) { 1136 if ( ! ok ) {
1137 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1137 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1138 mPisyncFinished = true; 1138 mPisyncFinished = true;
1139 return; 1139 return;
1140 } 1140 }
1141 mCurrentResourceLocal = ""; 1141 mCurrentResourceLocal = "";
1142 mCurrentResourceRemote = ""; 1142 mCurrentResourceRemote = "";
1143 qDebug ( "KSM: sync pi %d",mSpecificResources.count() );
1143 if ( mSpecificResources.count() ) { 1144 if ( mSpecificResources.count() ) {
1144 int lastSyncRes = mSpecificResources.count()/2; 1145 int lastSyncRes = mSpecificResources.count()/2;
1145 int ccc = mSpecificResources.count()-1; 1146 int ccc = mSpecificResources.count()-1;
1146 while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { 1147 while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) {
1147 --ccc; 1148 --ccc;
1148 --lastSyncRes; 1149 --lastSyncRes;
1150 qDebug ( "KSM: sync pi %d",ccc );
1149 } 1151 }
1150 int startLocal = 0; 1152 int startLocal = 0;
1151 int startRemote = mSpecificResources.count()/2; 1153 int startRemote = mSpecificResources.count()/2;
1152 emit multiResourceSyncStart( true ); 1154 emit multiResourceSyncStart( true );
1153 while ( startLocal < mSpecificResources.count()/2 ) { 1155 while ( startLocal < mSpecificResources.count()/2 ) {
1154 if ( startLocal+1 >= lastSyncRes ) 1156 if ( startLocal+1 >= lastSyncRes )
1155 emit multiResourceSyncStart( false ); 1157 emit multiResourceSyncStart( false );
1156 mPisyncFinished = false; 1158 mPisyncFinished = false;
1157 mCurrentResourceLocal = mSpecificResources[ startLocal ]; 1159 mCurrentResourceLocal = mSpecificResources[ startLocal ];
1158 mCurrentResourceRemote = mSpecificResources[ startRemote ]; 1160 mCurrentResourceRemote = mSpecificResources[ startRemote ];
1161 qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() );
1159 if ( !mCurrentResourceRemote.isEmpty() ) { 1162 if ( !mCurrentResourceRemote.isEmpty() ) {
1160 qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); 1163 qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() );
1161 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1164 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1162 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1165 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1163 commandSocket->readFile( syncFileName() ); 1166 commandSocket->readFile( syncFileName() );
1164 while ( !mPisyncFinished ) { 1167 while ( !mPisyncFinished ) {
1165 //qDebug("waiting "); 1168 //qDebug("waiting ");
1166 qApp->processEvents(); 1169 qApp->processEvents();
1167 } 1170 }
1168 } 1171 }
1172 ++startRemote;
1169 ++startLocal; 1173 ++startLocal;
1170 } 1174 }
1175 mPisyncFinished = true;
1171 } else { 1176 } else {
1172 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1177 KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1173 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1178 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1174 commandSocket->readFile( syncFileName() ); 1179 commandSocket->readFile( syncFileName() );
1175 } 1180 }
1176} 1181}
1177 1182
1178void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1183void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1179{ 1184{
1180 //enum { success, errorW, errorR, quiet }; 1185 //enum { success, errorW, errorR, quiet };
1181 1186
1182 1187
1183 1188
1184 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || 1189 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW ||
1185 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { 1190 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) {
1186 if ( state == KCommandSocket::errorPW ) 1191 if ( state == KCommandSocket::errorPW )
1187 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); 1192 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") );
1188 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) 1193 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO )
1189 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1194 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1190 else if ( state == KCommandSocket::errorCA ) 1195 else if ( state == KCommandSocket::errorCA )
1191 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); 1196 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") );
1192 else if ( state == KCommandSocket::errorFI ) 1197 else if ( state == KCommandSocket::errorFI )
1193 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); 1198 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") );
1194 else if ( state == KCommandSocket::errorED ) 1199 else if ( state == KCommandSocket::errorED )
1195 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); 1200 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") );
1196 else if ( state == KCommandSocket::errorUN ) 1201 else if ( state == KCommandSocket::errorUN )
1197 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); 1202 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") );
1198 delete s; 1203 delete s;
1199 if ( state == KCommandSocket::errorR ) { 1204 if ( state == KCommandSocket::errorR ) {
1200 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); 1205 KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
1201 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1206 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1202 commandSocket->sendStop(); 1207 commandSocket->sendStop();
1203 } 1208 }
1204 mPisyncFinished = true; 1209 mPisyncFinished = true;
1205 return; 1210 return;
1206 1211
1207 } else if ( state == KCommandSocket::errorW ) { 1212 } else if ( state == KCommandSocket::errorW ) {
1208 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1213 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1209 mPisyncFinished = true; 1214 mPisyncFinished = true;
1210 1215
1211 } else if ( state == KCommandSocket::successR ) { 1216 } else if ( state == KCommandSocket::successR ) {
1212 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1217 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1213 1218
1214 } else if ( state == KCommandSocket::successW ) { 1219 } else if ( state == KCommandSocket::successW ) {
1215 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 1220 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
1216 mPisyncFinished = true; 1221 mPisyncFinished = true;
1217 } else if ( state == KCommandSocket::quiet ){ 1222 } else if ( state == KCommandSocket::quiet ){
1218 qDebug("KSS: quiet "); 1223 qDebug("KSS: quiet ");
1219 mPisyncFinished = true; 1224 mPisyncFinished = true;
1220 } else { 1225 } else {
1221 qDebug("KSS: Error: unknown state: %d ", state); 1226 qDebug("KSS: Error: unknown state: %d ", state);
1222 mPisyncFinished = true; 1227 mPisyncFinished = true;
1223 } 1228 }
1224 1229
1225 delete s; 1230 delete s;
1226} 1231}
1227 1232
1228void KSyncManager::readFileFromSocket() 1233void KSyncManager::readFileFromSocket()
1229{ 1234{
1230 QString fileName = syncFileName(); 1235 QString fileName = syncFileName();
1231 bool syncOK = true; 1236 bool syncOK = true;
1232 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1237 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1233 if ( ! syncWithFile( fileName , true ) ) { 1238 if ( ! syncWithFile( fileName , true ) ) {
1234 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1239 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1235 syncOK = false; 1240 syncOK = false;
1236 } 1241 }
1237 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1242 KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1238 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1243 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1239 if ( mWriteBackFile && syncOK ) { 1244 if ( mWriteBackFile && syncOK ) {
1240 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); 1245 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1241 commandSocket->writeFile( fileName ); 1246 commandSocket->writeFile( fileName );
1242 } 1247 }
1243 else { 1248 else {
1244 commandSocket->sendStop(); 1249 commandSocket->sendStop();
1245 if ( syncOK ) 1250 if ( syncOK )
1246 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1251 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1247 mPisyncFinished = true; 1252 mPisyncFinished = true;
1248 } 1253 }
1249} 1254}
1250 1255
1251KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1256KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1252{ 1257{
1253 mPassWord = pw; 1258 mPassWord = pw;
1254 mSocket = 0; 1259 mSocket = 0;
1255 mSyncActionDialog = 0; 1260 mSyncActionDialog = 0;
1256 blockRC = false; 1261 blockRC = false;
1257 mErrorMessage = 0; 1262 mErrorMessage = 0;
1258} 1263}
1259 1264
1260void KServerSocket::newConnection ( int socket ) 1265void KServerSocket::newConnection ( int socket )
1261{ 1266{
1262 // qDebug("KServerSocket:New connection %d ", socket); 1267 // qDebug("KServerSocket:New connection %d ", socket);
1263 if ( mSocket ) { 1268 if ( mSocket ) {
1264 qDebug("KSS::newConnection Socket deleted! "); 1269 qDebug("KSS::newConnection Socket deleted! ");
1265 delete mSocket; 1270 delete mSocket;
1266 mSocket = 0; 1271 mSocket = 0;
@@ -1423,294 +1428,296 @@ void KServerSocket::send_file()
1423 } else 1428 } else
1424 mSyncActionDialog->setFixedSize( 230, 120); 1429 mSyncActionDialog->setFixedSize( 230, 120);
1425 mSyncActionDialog->show(); 1430 mSyncActionDialog->show();
1426 mSyncActionDialog->raise(); 1431 mSyncActionDialog->raise();
1427 emit request_file(mResource); 1432 emit request_file(mResource);
1428 emit request_file(); 1433 emit request_file();
1429 qApp->processEvents(); 1434 qApp->processEvents();
1430 QString fileName = mFileName; 1435 QString fileName = mFileName;
1431 QFile file( fileName ); 1436 QFile file( fileName );
1432 if (!file.open( IO_ReadOnly ) ) { 1437 if (!file.open( IO_ReadOnly ) ) {
1433 mErrorMessage = 0; 1438 mErrorMessage = 0;
1434 end_connect(); 1439 end_connect();
1435 error_connect("ERROR_FI\r\n\r\n"); 1440 error_connect("ERROR_FI\r\n\r\n");
1436 return ; 1441 return ;
1437 } 1442 }
1438 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1443 mSyncActionDialog->setCaption( i18n("Sending file...") );
1439 QTextStream ts( &file ); 1444 QTextStream ts( &file );
1440 ts.setEncoding( QTextStream::Latin1 ); 1445 ts.setEncoding( QTextStream::Latin1 );
1441 1446
1442 QTextStream os( mSocket ); 1447 QTextStream os( mSocket );
1443 os.setEncoding( QTextStream::Latin1 ); 1448 os.setEncoding( QTextStream::Latin1 );
1444 while ( ! ts.atEnd() ) { 1449 while ( ! ts.atEnd() ) {
1445 os << ts.readLine() << "\r\n"; 1450 os << ts.readLine() << "\r\n";
1446 } 1451 }
1447 os << "\r\n"; 1452 os << "\r\n";
1448 //os << ts.read(); 1453 //os << ts.read();
1449 file.close(); 1454 file.close();
1450 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1455 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1451 mSocket->close(); 1456 mSocket->close();
1452 if ( mSocket->state() == QSocket::Idle ) 1457 if ( mSocket->state() == QSocket::Idle )
1453 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1458 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1454} 1459}
1455void KServerSocket::get_file() 1460void KServerSocket::get_file()
1456{ 1461{
1457 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1462 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1458 1463
1459 piTime.start(); 1464 piTime.start();
1460 piFileString = ""; 1465 piFileString = "";
1461 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1466 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1462} 1467}
1463 1468
1464 1469
1465void KServerSocket::readBackFileFromSocket() 1470void KServerSocket::readBackFileFromSocket()
1466{ 1471{
1467 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1472 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1468 while ( mSocket->canReadLine () ) { 1473 while ( mSocket->canReadLine () ) {
1469 piTime.restart(); 1474 piTime.restart();
1470 QString line = mSocket->readLine (); 1475 QString line = mSocket->readLine ();
1471 piFileString += line; 1476 piFileString += line;
1472 //qDebug("readline: %s ", line.latin1()); 1477 //qDebug("readline: %s ", line.latin1());
1473 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1478 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1474 1479
1475 } 1480 }
1476 if ( piTime.elapsed () < 3000 ) { 1481 if ( piTime.elapsed () < 3000 ) {
1477 // wait for more 1482 // wait for more
1478 //qDebug("waitformore "); 1483 //qDebug("waitformore ");
1479 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1484 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1480 return; 1485 return;
1481 } 1486 }
1482 QString fileName = mFileName; 1487 QString fileName = mFileName;
1483 QFile file ( fileName ); 1488 QFile file ( fileName );
1484 if (!file.open( IO_WriteOnly ) ) { 1489 if (!file.open( IO_WriteOnly ) ) {
1485 delete mSyncActionDialog; 1490 delete mSyncActionDialog;
1486 mSyncActionDialog = 0; 1491 mSyncActionDialog = 0;
1487 qDebug("KSS:Error open read back file "); 1492 qDebug("KSS:Error open read back file ");
1488 piFileString = ""; 1493 piFileString = "";
1489 emit file_received( false, mResource); 1494 emit file_received( false, mResource);
1490 emit file_received( false); 1495 emit file_received( false);
1491 blockRC = false; 1496 blockRC = false;
1492 return ; 1497 return ;
1493 1498
1494 } 1499 }
1495 1500
1496 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1501 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1497 QTextStream ts ( &file ); 1502 QTextStream ts ( &file );
1498 ts.setEncoding( QTextStream::Latin1 ); 1503 ts.setEncoding( QTextStream::Latin1 );
1499 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1504 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1500 ts << piFileString; 1505 ts << piFileString;
1501 mSocket->close(); 1506 mSocket->close();
1502 if ( mSocket->state() == QSocket::Idle ) 1507 if ( mSocket->state() == QSocket::Idle )
1503 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1508 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1504 file.close(); 1509 file.close();
1505 piFileString = ""; 1510 piFileString = "";
1506 emit file_received( true, mResource ); 1511 emit file_received( true, mResource );
1507 emit file_received( true); 1512 emit file_received( true);
1508 delete mSyncActionDialog; 1513 delete mSyncActionDialog;
1509 mSyncActionDialog = 0; 1514 mSyncActionDialog = 0;
1510 blockRC = false; 1515 blockRC = false;
1511 1516
1512} 1517}
1513 1518
1514KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) 1519KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
1515{ 1520{
1516 mRemoteResource = remres; 1521 mRemoteResource = remres;
1517 if ( mRemoteResource.isEmpty() ) 1522 if ( mRemoteResource.isEmpty() )
1518 mRemoteResource = "ALL"; 1523 mRemoteResource = "ALL";
1524 else
1525 mRemoteResource.replace (QRegExp (" "),"_" );
1519 mPassWord = password; 1526 mPassWord = password;
1520 mSocket = 0; 1527 mSocket = 0;
1521 mFirst = false; 1528 mFirst = false;
1522 mFirstLine = true; 1529 mFirstLine = true;
1523 mPort = port; 1530 mPort = port;
1524 mHost = host; 1531 mHost = host;
1525 tlw = cap; 1532 tlw = cap;
1526 mRetVal = quiet; 1533 mRetVal = quiet;
1527 mTimerSocket = new QTimer ( this ); 1534 mTimerSocket = new QTimer ( this );
1528 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); 1535 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1529 mConnectProgress.setCaption( i18n("Pi-Sync") ); 1536 mConnectProgress.setCaption( i18n("Pi-Sync") );
1530 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); 1537 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1531 mConnectCount = -1; 1538 mConnectCount = -1;
1532} 1539}
1533void KCommandSocket::sendFileRequest() 1540void KCommandSocket::sendFileRequest()
1534{ 1541{
1535 if ( tlw ) 1542 if ( tlw )
1536 tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); 1543 tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
1537 mConnectProgress.hide(); 1544 mConnectProgress.hide();
1538 mConnectCount = 300;mConnectMax = 300; 1545 mConnectCount = 300;mConnectMax = 300;
1539 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); 1546 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
1540 mTimerSocket->start( 100, true ); 1547 mTimerSocket->start( 100, true );
1541 QTextStream os( mSocket ); 1548 QTextStream os( mSocket );
1542 os.setEncoding( QTextStream::Latin1 ); 1549 os.setEncoding( QTextStream::Latin1 );
1543 1550
1544 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1551 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1545 os << "GET " << mPassWord << curDt << mRemoteResource << "\r\n\r\n"; 1552 os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n";
1546} 1553}
1547 1554
1548void KCommandSocket::readFile( QString fn ) 1555void KCommandSocket::readFile( QString fn )
1549{ 1556{
1550 if ( !mSocket ) { 1557 if ( !mSocket ) {
1551 mSocket = new QSocket( this ); 1558 mSocket = new QSocket( this );
1552 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1559 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1553 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1560 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1554 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); 1561 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
1555 } 1562 }
1556 mFileString = ""; 1563 mFileString = "";
1557 mFileName = fn; 1564 mFileName = fn;
1558 mFirst = true; 1565 mFirst = true;
1559 if ( tlw ) 1566 if ( tlw )
1560 tlw->setCaption( i18n("Trying to connect to remote...") ); 1567 tlw->setCaption( i18n("Trying to connect to remote...") );
1561 mConnectCount = 30;mConnectMax = 30; 1568 mConnectCount = 30;mConnectMax = 30;
1562 mTimerSocket->start( 1000, true ); 1569 mTimerSocket->start( 1000, true );
1563 mSocket->connectToHost( mHost, mPort ); 1570 mSocket->connectToHost( mHost, mPort );
1564 qDebug("KSS: Waiting for connection"); 1571 qDebug("KSS: Waiting for connection");
1565} 1572}
1566void KCommandSocket::updateConnectDialog() 1573void KCommandSocket::updateConnectDialog()
1567{ 1574{
1568 1575
1569 if ( mConnectCount == mConnectMax ) { 1576 if ( mConnectCount == mConnectMax ) {
1570 //qDebug("MAXX %d", mConnectMax); 1577 //qDebug("MAXX %d", mConnectMax);
1571 mConnectProgress.setTotalSteps ( 30 ); 1578 mConnectProgress.setTotalSteps ( 30 );
1572 mConnectProgress.show(); 1579 mConnectProgress.show();
1573 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); 1580 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
1574 } 1581 }
1575 //qDebug("updateConnectDialog() %d", mConnectCount); 1582 //qDebug("updateConnectDialog() %d", mConnectCount);
1576 mConnectProgress.raise(); 1583 mConnectProgress.raise();
1577 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); 1584 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
1578 --mConnectCount; 1585 --mConnectCount;
1579 if ( mConnectCount > 0 ) 1586 if ( mConnectCount > 0 )
1580 mTimerSocket->start( 1000, true ); 1587 mTimerSocket->start( 1000, true );
1581 else 1588 else
1582 deleteSocket(); 1589 deleteSocket();
1583 1590
1584} 1591}
1585void KCommandSocket::writeFile( QString fileName ) 1592void KCommandSocket::writeFile( QString fileName )
1586{ 1593{
1587 if ( !mSocket ) { 1594 if ( !mSocket ) {
1588 mSocket = new QSocket( this ); 1595 mSocket = new QSocket( this );
1589 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1596 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1590 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1597 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1591 } 1598 }
1592 mFileName = fileName ; 1599 mFileName = fileName ;
1593 mConnectCount = 30;mConnectMax = 30; 1600 mConnectCount = 30;mConnectMax = 30;
1594 mTimerSocket->start( 1000, true ); 1601 mTimerSocket->start( 1000, true );
1595 mSocket->connectToHost( mHost, mPort ); 1602 mSocket->connectToHost( mHost, mPort );
1596} 1603}
1597void KCommandSocket::writeFileToSocket() 1604void KCommandSocket::writeFileToSocket()
1598{ 1605{
1599 mTimerSocket->stop(); 1606 mTimerSocket->stop();
1600 QFile file2( mFileName ); 1607 QFile file2( mFileName );
1601 if (!file2.open( IO_ReadOnly ) ) { 1608 if (!file2.open( IO_ReadOnly ) ) {
1602 mConnectProgress.hide(); 1609 mConnectProgress.hide();
1603 mConnectCount = -1; 1610 mConnectCount = -1;
1604 mRetVal= errorW; 1611 mRetVal= errorW;
1605 mSocket->close(); 1612 mSocket->close();
1606 if ( mSocket->state() == QSocket::Idle ) 1613 if ( mSocket->state() == QSocket::Idle )
1607 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1614 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1608 return ; 1615 return ;
1609 } 1616 }
1610 mConnectProgress.setTotalSteps ( file2.size() ); 1617 mConnectProgress.setTotalSteps ( file2.size() );
1611 mConnectProgress.show(); 1618 mConnectProgress.show();
1612 int count = 0; 1619 int count = 0;
1613 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1620 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1614 mConnectProgress.setProgress( count ); 1621 mConnectProgress.setProgress( count );
1615 mConnectProgress.blockSignals( true ); 1622 mConnectProgress.blockSignals( true );
1616 QTextStream ts2( &file2 ); 1623 QTextStream ts2( &file2 );
1617 ts2.setEncoding( QTextStream::Latin1 ); 1624 ts2.setEncoding( QTextStream::Latin1 );
1618 QTextStream os2( mSocket ); 1625 QTextStream os2( mSocket );
1619 os2.setEncoding( QTextStream::Latin1 ); 1626 os2.setEncoding( QTextStream::Latin1 );
1620 os2 << "PUT " << mPassWord << mRemoteResource << "\r\n\r\n";; 1627 os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";;
1621 int byteCount = 0; 1628 int byteCount = 0;
1622 int byteMax = file2.size()/53; 1629 int byteMax = file2.size()/53;
1623 while ( ! ts2.atEnd() ) { 1630 while ( ! ts2.atEnd() ) {
1624 qApp->processEvents(); 1631 qApp->processEvents();
1625 if ( byteCount > byteMax ) { 1632 if ( byteCount > byteMax ) {
1626 byteCount = 0; 1633 byteCount = 0;
1627 mConnectProgress.setProgress( count ); 1634 mConnectProgress.setProgress( count );
1628 } 1635 }
1629 QString temp = ts2.readLine(); 1636 QString temp = ts2.readLine();
1630 count += temp.length(); 1637 count += temp.length();
1631 byteCount += temp.length(); 1638 byteCount += temp.length();
1632 os2 << temp << "\r\n"; 1639 os2 << temp << "\r\n";
1633 } 1640 }
1634 file2.close(); 1641 file2.close();
1635 mConnectProgress.hide(); 1642 mConnectProgress.hide();
1636 mConnectCount = -1; 1643 mConnectCount = -1;
1637 os2 << "\r\n"; 1644 os2 << "\r\n";
1638 mRetVal= successW; 1645 mRetVal= successW;
1639 mSocket->close(); 1646 mSocket->close();
1640 if ( mSocket->state() == QSocket::Idle ) 1647 if ( mSocket->state() == QSocket::Idle )
1641 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1648 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1642 mConnectProgress.blockSignals( false ); 1649 mConnectProgress.blockSignals( false );
1643} 1650}
1644void KCommandSocket::sendStop() 1651void KCommandSocket::sendStop()
1645{ 1652{
1646 if ( !mSocket ) { 1653 if ( !mSocket ) {
1647 mSocket = new QSocket( this ); 1654 mSocket = new QSocket( this );
1648 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1655 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1649 } 1656 }
1650 mSocket->connectToHost( mHost, mPort ); 1657 mSocket->connectToHost( mHost, mPort );
1651 QTextStream os2( mSocket ); 1658 QTextStream os2( mSocket );
1652 os2.setEncoding( QTextStream::Latin1 ); 1659 os2.setEncoding( QTextStream::Latin1 );
1653 os2 << "STOP\r\n\r\n"; 1660 os2 << "STOP\r\n\r\n";
1654 mSocket->close(); 1661 mSocket->close();
1655 if ( mSocket->state() == QSocket::Idle ) 1662 if ( mSocket->state() == QSocket::Idle )
1656 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1663 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1657} 1664}
1658 1665
1659void KCommandSocket::startReadFileFromSocket() 1666void KCommandSocket::startReadFileFromSocket()
1660{ 1667{
1661 if ( ! mFirst ) 1668 if ( ! mFirst )
1662 return; 1669 return;
1663 mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); 1670 mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
1664 mFirst = false; 1671 mFirst = false;
1665 mFileString = ""; 1672 mFileString = "";
1666 mTime.start(); 1673 mTime.start();
1667 mFirstLine = true; 1674 mFirstLine = true;
1668 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1675 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1669 1676
1670} 1677}
1671void KCommandSocket::readFileFromSocket() 1678void KCommandSocket::readFileFromSocket()
1672{ 1679{
1673 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1680 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1674 while ( mSocket->canReadLine () ) { 1681 while ( mSocket->canReadLine () ) {
1675 mTime.restart(); 1682 mTime.restart();
1676 QString line = mSocket->readLine (); 1683 QString line = mSocket->readLine ();
1677 if ( mFirstLine ) { 1684 if ( mFirstLine ) {
1678 mFirstLine = false; 1685 mFirstLine = false;
1679 if ( line.left( 6 ) == "ERROR_" ) { 1686 if ( line.left( 6 ) == "ERROR_" ) {
1680 mTimerSocket->stop(); 1687 mTimerSocket->stop();
1681 mConnectCount = -1; 1688 mConnectCount = -1;
1682 if ( line.left( 8 ) == "ERROR_PW" ) { 1689 if ( line.left( 8 ) == "ERROR_PW" ) {
1683 mRetVal = errorPW; 1690 mRetVal = errorPW;
1684 deleteSocket(); 1691 deleteSocket();
1685 return ; 1692 return ;
1686 } 1693 }
1687 if ( line.left( 8 ) == "ERROR_CA" ) { 1694 if ( line.left( 8 ) == "ERROR_CA" ) {
1688 mRetVal = errorCA; 1695 mRetVal = errorCA;
1689 deleteSocket(); 1696 deleteSocket();
1690 return ; 1697 return ;
1691 } 1698 }
1692 if ( line.left( 8 ) == "ERROR_FI" ) { 1699 if ( line.left( 8 ) == "ERROR_FI" ) {
1693 mRetVal = errorFI; 1700 mRetVal = errorFI;
1694 deleteSocket(); 1701 deleteSocket();
1695 return ; 1702 return ;
1696 } 1703 }
1697 if ( line.left( 8 ) == "ERROR_ED" ) { 1704 if ( line.left( 8 ) == "ERROR_ED" ) {
1698 mRetVal = errorED; 1705 mRetVal = errorED;
1699 deleteSocket(); 1706 deleteSocket();
1700 return ; 1707 return ;
1701 } 1708 }
1702 mRetVal = errorUN; 1709 mRetVal = errorUN;
1703 deleteSocket(); 1710 deleteSocket();
1704 return ; 1711 return ;
1705 } 1712 }
1706 } 1713 }
1707 mFileString += line; 1714 mFileString += line;
1708 //qDebug("readline: %s ", line.latin1()); 1715 //qDebug("readline: %s ", line.latin1());
1709 } 1716 }
1710 if ( mTime.elapsed () < 3000 ) { 1717 if ( mTime.elapsed () < 3000 ) {
1711 // wait for more 1718 // wait for more
1712 //qDebug("waitformore "); 1719 //qDebug("waitformore ");
1713 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1720 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1714 return; 1721 return;
1715 } 1722 }
1716 mTimerSocket->stop(); 1723 mTimerSocket->stop();