-rw-r--r-- | korganizer/koprefs.cpp | 8 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 13 |
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 @@ -1,646 +1,654 @@ /* This file is part of KOrganizer. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <time.h> #ifndef _WIN32_ #include <unistd.h> #endif #include <qdir.h> #include <qtextstream.h> #include <qtextcodec.h> #include <qstring.h> #include <qregexp.h> #include <qfont.h> #include <qcolor.h> #include <qstringlist.h> #include <stdlib.h> #include <kglobal.h> #include <kglobalsettings.h> #include <kconfig.h> #include <klocale.h> #include <kdebug.h> #include <kemailsettings.h> #include <kstaticdeleter.h> #include <libkdepim/kpimglobalprefs.h> #include "koprefs.h" #include "mainwindow.h" KOPrefs *KOPrefs::mInstance = 0; static KStaticDeleter<KOPrefs> insd; KOPrefs::KOPrefs() : KPimPrefs("korganizerrc") { mGlobalUpdateDisabled = false; mCategoryColors.setAutoDelete(true); fillMailDefaults(); mDefaultCategoryColor = QColor(175,210,255);//196,196,196); QColor defaultHolidayColor = QColor(255,0,0); QColor defaultHighlightColor = QColor(129,112,255);//64,64,255); QColor defaultAgendaBgColor = QColor(239,241,169);//128,128,128); QColor defaultWorkingHoursColor = QColor(170,223,150);//160,160,160); QColor defaultTodoDueTodayColor = QColor(255,220,100); QColor defaultTodoOverdueColor = QColor(255,153,125); QColor defaultTodoRunColor = QColor(99,194,30); KPrefs::setCurrentGroup("General"); addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false); addItemBool("ShowIconNewTodo",&mShowIconNewTodo,true); addItemBool("ShowIconNewEvent",&mShowIconNewEvent,true); addItemBool("ShowIconSearch",&mShowIconSearch,true); addItemBool("ShowIconList",&mShowIconList,true); addItemBool("ShowIconDay1",&mShowIconDay1,true); addItemBool("ShowIconDay5",&mShowIconDay5,true); addItemBool("ShowIconDay6",&mShowIconDay6,true); addItemBool("ShowIconDay7",&mShowIconDay7,true); addItemBool("ShowIconMonth",&mShowIconMonth,true); addItemBool("ShowIconTodoview",&mShowIconTodoview,true); addItemBool("ShowIconBackFast",&mShowIconBackFast,true); addItemBool("ShowIconBack",&mShowIconBack,true); addItemBool("ShowIconToday",&mShowIconToday,true); addItemBool("ShowIconForward",&mShowIconForward,true); addItemBool("ShowIconForwardFast",&mShowIconForwardFast,true); addItemBool("ShowIconWhatsThis",&mShowIconWhatsThis,true); addItemBool("ShowIconWeekNum",&mShowIconWeekNum,true); addItemBool("ShowIconNextDays",&mShowIconNextDays,true); addItemBool("ShowIconNext",&mShowIconNext,true); addItemBool("ShowIconJournal",&mShowIconJournal,true); addItemBool("ShowIconStretch",&mShowIconStretch,true); addItemBool("ShowIconFilter",&mShowIconFilter,false); addItemBool("ShowIconOnetoolbar",&mShowIconOnetoolbar,true); bool addIcons = false; #ifdef DESKTOP_VERSION addIcons = true; #endif addItemBool("ShowIconNavigator",&mShowIconNavigator,addIcons); addItemBool("ShowIconAllday",&mShowIconAllday,addIcons); addItemBool("ShowIconFilterview",&mShowIconFilterview,addIcons); addItemBool("ShowIconToggleFull",&mShowIconToggleFull,addIcons); addItemInt("LastLoadedLanguage",&mOldLanguage,0); addItemBool("AskForQuit",&mAskForQuit,false); #ifndef DESKTOP_VERSION addItemBool("ShowFullMenu",&mShowFullMenu,false); #else addItemBool("ShowFullMenu",&mShowFullMenu,true); #endif addItemBool("ToolBarHor",&mToolBarHor, true ); addItemBool("ToolBarUp",&mToolBarUp, false ); addItemBool("ToolBarHorV",&mToolBarHorV, true ); addItemBool("ToolBarUpV",&mToolBarUpV, false ); addItemBool("ToolBarHorN",&mToolBarHorN, true ); addItemBool("ToolBarUpN",&mToolBarUpN, false ); addItemBool("ToolBarHorF",&mToolBarHorF, true ); addItemBool("ToolBarUpF",&mToolBarUpF, false ); addItemBool("ToolBarMiniIcons",&mToolBarMiniIcons, false ); addItemBool("WhatsNextTime2Lines",&mWhatsNextTime2Lines, false ); addItemInt("Whats Next Days",&mWhatsNextDays,3); addItemInt("Whats Next Prios",&mWhatsNextPrios,1); addItemBool("ShowTodoInAgenda",&mShowTodoInAgenda,true); addItemBool("ShowCompletedTodoInAgenda",&mShowCompletedTodoInAgenda,true); addItemBool("ShowTimeInAgenda",&mShowTimeInAgenda,true); addItemBool("HideNonStartedTodos",&mHideNonStartedTodos,false); addItemBool("ShowCompletedTodo",&mShowCompletedTodo,true); addItemInt("AllDay Size",&mAllDaySize,28); QString defAlarm = KGlobal::iconLoader()->iconPath()+"koalarm.wav"; addItemString("DefaultAlarmFile",&mDefaultAlarmFile,defAlarm ); addItemStringList("LocationDefaults",&mLocationDefaults ); addItemStringList("EventSummary User",&mEventSummaryUser); addItemStringList("TodoSummary User",&mTodoSummaryUser); addItemStringList("JournalSummary User",&mJournalSummaryUser); addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false); addItemBool("Enable Project View",&mEnableProjectView,false); addItemBool("Auto Save",&mAutoSave,false); addItemInt("Auto Save Interval",&mAutoSaveInterval,3); addItemBool("Confirm Deletes",&mConfirm,true); addItemString("Archive File",&mArchiveFile); addItemString("Html Export File",&mHtmlExportFile, QDir::homeDirPath() + "/" + i18n("Default export file", "calendar.html")); addItemBool("Html With Save",&mHtmlWithSave,false); KPrefs::setCurrentGroup("Personal Settings"); addItemInt("Mail Client",&mMailClient,MailClientKMail); addItemBool("Use Control Center Email",&mEmailControlCenter,false); addItemBool("Bcc",&mBcc,false); KPrefs::setCurrentGroup("Time & Date"); addItemInt("Default Start Time",&mStartTime,10); addItemInt("Default Duration",&mDefaultDuration,2); addItemInt("Default Alarm Time",&mAlarmTime,3); KPrefs::setCurrentGroup("AlarmSettings"); addItemInt("AlarmPlayBeeps",&mAlarmPlayBeeps,20); addItemInt("AlarmSuspendTime",&mAlarmSuspendTime,7); addItemInt("AlarmSuspendCount",&mAlarmSuspendCount,5); addItemInt("AlarmBeepInterval",&mAlarmBeepInterval,3); KPrefs::setCurrentGroup("Calendar"); addItemInt("Default Calendar Format",&mDefaultFormat,FormatICalendar); KPrefs::setCurrentGroup("Fonts"); // qDebug(" KPrefs::setCurrentGroup(Fonts); "); QFont fon = KGlobalSettings::generalFont(); addItemFont("TimeBar Font",&mTimeBarFont,fon ); addItemFont("MonthView Font",&mMonthViewFont,fon); addItemFont("AgendaView Font",&mAgendaViewFont,fon); addItemFont("MarcusBains Font",&mMarcusBainsFont,fon); addItemFont("TimeLabels Font",&mTimeLabelsFont,fon); addItemFont("TodoView Font",&mTodoViewFont,fon); addItemFont("ListView Font",&mListViewFont,fon); addItemFont("DateNavigator Font",&mDateNavigatorFont,fon); addItemFont("EditBox Font",&mEditBoxFont,fon); addItemFont("JournalView Font",&mJornalViewFont,fon); addItemFont("WhatsNextView Font",&mWhatsNextFont,fon); addItemFont("EventView Font",&mEventViewFont,fon); KPrefs::setCurrentGroup("RemoteSyncing"); addItemString("ActiveSyncPort",&mActiveSyncPort,"9197" ); addItemString("ActiveSyncIP",&mActiveSyncIP,"192.168.0.40" ); addItemBool("ShowSyncEvents",&mShowSyncEvents,false); addItemInt("LastSyncTime",&mLastSyncTime,0); #ifdef _WIN32_ QString hdp= locateLocal("data","korganizer")+"\\\\"; #else QString hdp= locateLocal("data","korganizer")+"/"; #endif KPrefs::setCurrentGroup("LoadSaveFileNames"); addItemString("LastImportFile", &mLastImportFile ,hdp +"import.ics" ); addItemString("LastVcalFile", &mLastVcalFile ,hdp +"export.vcs" ); addItemString("LastSaveFile", &mLastSaveFile ,hdp +"mybackup.ics" ); addItemString("LastLoadFile", &mLastLoadFile ,hdp +"mybackup.ics" ); KPrefs::setCurrentGroup("Locale"); addItemBool("ShortDateInViewer",&mShortDateInViewer,false); KPrefs::setCurrentGroup("Colors"); addItemColor("Holiday Color",&mHolidayColor,defaultHolidayColor); addItemColor("Highlight Color",&mHighlightColor,defaultHighlightColor); addItemColor("Event Color",&mEventColor,mDefaultCategoryColor); addItemColor("Todo done Color",&mTodoDoneColor,QColor(111,255,115) ); addItemColor("Agenda Background Color",&mAgendaBgColor,defaultAgendaBgColor); addItemColor("WorkingHours Color",&mWorkingHoursColor,defaultWorkingHoursColor); addItemColor("Todo due today Color",&mTodoDueTodayColor,defaultTodoDueTodayColor); addItemColor("Todo overdue Color",&mTodoOverdueColor,defaultTodoOverdueColor); addItemColor("Todo running Color",&mTodoRunColor,defaultTodoRunColor); addItemColor("MonthViewEvenColor",&mMonthViewEvenColor,QColor( 160,160,255 )); addItemColor("MonthViewOddColor",&mMonthViewOddColor,QColor( 160,255,160 )); addItemColor("MonthViewHolidayColor",&mMonthViewHolidayColor,QColor( 255,160,160 )); addItemBool("MonthViewUsesDayColors",&mMonthViewUsesDayColors,true); addItemBool("MonthViewSatSunTog",&mMonthViewSatSunTog,true); addItemBool("MonthViewWeek",&mMonthViewWeek,false); addItemBool("HightlightDateTimeEdit",&mHightlightDateTimeEdit,false); addItemColor("AppColor1",&mAppColor1,QColor( 130,170,255 )); addItemColor("AppColor2",&mAppColor2,QColor( 174,216,255 )); addItemBool("UseAppColors",&mUseAppColors,false); KPrefs::setCurrentGroup("Conflicts"); addItemBool("EnableAutoDetect",&mDetectConflicts,true); addItemBool("CheckConflictsFree",&mIncludeFree,true); addItemBool("CheckConflictsAllDayAllDay",&mCheckConflictsAllDayAllDay,false); addItemBool("CheckConflictsAllDayNonAD",&mCheckConflictsAllDayNonAD,false); addItemBool("CheckConflictsNonADAllDay",&mCheckConflictsNonADAllDay,false); addItemBool("CheckConflictsNonADNonAD",&mCheckConflictsNonADNonAD,true); addItemString("FilterConflictEditItem", &mFilterConflictEditItem ,"nofilter" ); addItemString("FilterConflictAllItem", &mFilterConflictAllItem ,"nofilter" ); KPrefs::setCurrentGroup("Views"); addItemBool("Block Popup Menu",&mBlockPopupMenu,false); addItemBool("Show Date Navigator",&mShowDateNavigator,true); addItemInt("Hour Size",&mHourSize,8); addItemBool("Show Daily Recurrences",&mDailyRecur,true); addItemBool("ShowLongAllday",&mLongAllday,true); addItemBool("Show Weekly Recurrences",&mWeeklyRecur,true); addItemBool("Show Month Daily Recurrences",&mMonthDailyRecur,true); addItemBool("Show Month Weekly Recurrences",&mMonthWeeklyRecur,true); addItemBool("ShowShortMonthName",&mMonthShowShort,false); addItemBool("ShowIconsInMonthCell",&mMonthShowIcons,true); addItemBool("ShowTimesInMonthCell",&mMonthShowTimes,true); #ifdef DESKTOP_VERION addItemBool("Enable ToolTips",&mEnableToolTips,true); #else addItemBool("Enable ToolTips",&mEnableToolTips,false); #endif addItemBool("Enable MonthView ScrollBars",&mEnableMonthScroll,false); addItemBool("Marcus Bains shows seconds",&mMarcusBainsShowSeconds,false); addItemBool("Show Marcus Bains",&mMarcusBainsEnabled,true); addItemBool("EditOnDoubleClick",&mEditOnDoubleClick,true); addItemBool("ViewChangeHoldFullscreen",&mViewChangeHoldFullscreen,true); addItemBool("ViewChangeHoldNonFullscreen",&mViewChangeHoldNonFullscreen,false); addItemBool("CenterOnCurrentTime",&mCenterOnCurrentTime,false); addItemBool("SetTimeToDayStartAt",&mSetTimeToDayStartAt,true); addItemBool("HighlightCurrentDay",&mHighlightCurrentDay,true); addItemBool("WNViewShowsParents",&mWNViewShowsParents,true);; addItemBool("WNViewShowsPast",&mWNViewShowsPast,true); addItemBool("WNViewShowLocation",&mWNViewShowLocation,false); addItemBool("UseHighlightLightColor",&mUseHighlightLightColor,false); addItemBool("ListViewMonthTimespan",&mListViewMonthTimespan,true); addItemBool("TodoViewUsesCatColors",&mTodoViewUsesCatColors,false); addItemBool("TodoViewShowsPercentage",&mTodoViewShowsPercentage,false); addItemBool("TodoViewUsesSmallFont",&mTodoViewUsesSmallFont,true); addItemBool("MonthViewUsesBigFont",&mMonthViewUsesBigFont,true); addItemBool("MonthViewWeekRowlayout",&mMonthViewWeekRowlayout,false); addItemBool("TodoViewUsesForegroundColor",&mTodoViewUsesForegroundColor,false); addItemBool("MonthViewUsesForegroundColor",&mMonthViewUsesForegroundColor,false); #ifdef DESKTOP_VERSION addItemBool("UseInternalAlarmNotification",&mUseInternalAlarmNotification,true); #else addItemBool("UseInternalAlarmNotification",&mUseInternalAlarmNotification,false); #endif addItemInt("Day Begins",&mDayBegins,7); addItemInt("Working Hours Start",&mWorkingHoursStart,8); addItemInt("Working Hours End",&mWorkingHoursEnd,17); addItemBool("Exclude Holidays",&mExcludeHolidays,true); addItemBool("Exclude Saturdays",&mExcludeSaturdays,true); addItemBool("Month View Uses Category Color",&mMonthViewUsesCategoryColor,false); addItemBool("Full View Month",&mFullViewMonth,true); addItemBool("Full View Todo",&mFullViewTodo,true); addItemBool("Quick Todo",&mEnableQuickTodo,false); addItemInt("Next X Days",&mNextXDays,3); KPrefs::setCurrentGroup("Printer"); KPrefs::setCurrentGroup("Layout"); addItemBool("CompactDialogs",&mCompactDialogs,false); addItemBool("VerticalScreen",&mVerticalScreen,true); KPrefs::setCurrentGroup("KOrganizer Plugins"); addItemStringList("SelectedPlugins",&mSelectedPlugins,"holidays"); KPrefs::setCurrentGroup("Group Scheduling"); addItemInt("IMIPScheduler",&mIMIPScheduler,IMIPKMail); addItemInt("IMIPSend",&mIMIPSend,IMIPdirectsend); addItemStringList("AdditionalMails",&mAdditionalMails,""); addItemInt("IMIP auto refresh",&mIMIPAutoRefresh,neverAuto); addItemInt("IMIP auto insert request",&mIMIPAutoInsertRequest,neverAuto); addItemInt("IMIP auto insert reply",&mIMIPAutoInsertReply,neverAuto); addItemInt("IMIP auto FreeBusy",&mIMIPAutoFreeBusy,neverAuto); addItemInt("IMIP auto save FreeBusy",&mIMIPAutoFreeBusyReply,neverAuto); KPrefs::setCurrentGroup( "Editors" ); addItemStringList( "EventTemplates", &mEventTemplates ); addItemStringList( "TodoTemplates", &mTodoTemplates ); addItemInt("DestinationPolicy",&mDestination,standardDestination); KPrefs::setCurrentGroup( "ViewOptions" ); addItemBool("EVshowDetails",&mEVshowDetails,true); addItemBool("EVshowCreated",&mEVshowCreated,true); addItemBool("EVshowChanged",&mEVshowChanged,true); addItemBool("WTshowDetails",&mWTshowDetails,false); addItemBool("WTshowCreated",&mWTshowCreated,false); addItemBool("WTshowChanged",&mWTshowChanged,false); mCalendars.setAutoDelete( true ); } KOPrefs::~KOPrefs() { if (mInstance == this) mInstance = insd.setObject(0); mCalendars.setAutoDelete( true ); mCalendars.clear(); //qDebug("KOPrefs::~KOPrefs() "); } KOPrefs *KOPrefs::instance() { if (!mInstance) { mInstance = insd.setObject(new KOPrefs()); mInstance->readConfig(); } return mInstance; } void KOPrefs::usrSetDefaults() { } void KOPrefs::fillMailDefaults() { if (mName.isEmpty()) mName = i18n("Anonymous"); if (mEmail.isEmpty()) mEmail = i18n("nobody@nowhere"); } void KOPrefs::setTimeZoneIdDefault() { ; } void KOPrefs::setAllDefaults() { setCategoryDefaults(); mEventSummaryUser = getDefaultList() ; mTodoSummaryUser = getDefaultList() ; mJournalSummaryUser = getDefaultList() ; mLocationDefaults = getLocationDefaultList(); } void KOPrefs::setCategoryDefaults() { mCustomCategories.clear(); mCustomCategories = getDefaultList(); QStringList::Iterator it; for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { setCategoryColor(*it,mDefaultCategoryColor); } } QStringList KOPrefs::getLocationDefaultList() { QStringList retval ; retval << i18n("Home") << i18n("Office") << i18n("Library") << i18n("School") << i18n("Doctor") << i18n("Beach") << i18n("University") << i18n("Restaurant") << i18n("Bar") << i18n("Conference room") << i18n("Cinema") << i18n("Lake") << i18n("Kindergarten") << i18n("Germany") << i18n("Sweden") << i18n("Forest") << i18n("Desert") << i18n("Kitchen") ; // << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") retval.sort(); return retval; } QStringList KOPrefs::getDefaultList() { QStringList retval ; retval << i18n("Anniversary") << i18n("Appointment") << i18n("Birthday") << i18n("Business") << i18n("Customer") << i18n("Break") << i18n("Family") << i18n("Favorites") << i18n("Fishing") << i18n("Gifts") << i18n("Holiday") << i18n("Holiday Cards")<< i18n("Hot Contacts") << i18n("Meeting") << i18n("Miscellaneous") << i18n("Partner") << i18n("Personal") << i18n("PHB") << i18n("Phone Calls") << i18n("Shopping") << i18n("Sports") << i18n("Talk") << i18n("Travel") << i18n("TV") << i18n("Vacation") ; retval.sort(); //qDebug("cat %s ", retval.join("-").latin1()); return retval; } // << i18n("Business Travel") << i18n("Education") << i18n("Hiking") << i18n("Hunting") << i18n("Recurring") << i18n("Personal Travel") << i18n("Speach") << i18n("Festival") << i18n("Competition")<< i18n("Party")<< i18n("Projects")<< i18n("Kids") << i18n("Special Occasion")<< i18n("Breakfast")<< i18n("Dinner") << i18n("Lunch")<< i18n("University")<< i18n("School")<< i18n("Flight")<< i18n("Key Customer") << i18n("VIP") << i18n("SyncEvent") << i18n("Cinema") void KOPrefs::usrReadConfig() { config()->setGroup("General"); //qDebug("KOPrefs::usrReadConfig() "); mCustomCategories = config()->readListEntry("Custom Categories"); mOldLoadedLanguage = mOldLanguage ; mOldLanguage = KPimGlobalPrefs::instance()->mPreferredLanguage; if (mLocationDefaults.isEmpty()) { mLocationDefaults = getLocationDefaultList(); } if (mEventSummaryUser.isEmpty()) { mEventSummaryUser = getDefaultList() ; } if (mTodoSummaryUser.isEmpty()) { mTodoSummaryUser = getDefaultList() ; } if (mCustomCategories.isEmpty()) setCategoryDefaults(); config()->setGroup("Personal Settings"); mName = config()->readEntry("user_name",""); mEmail = config()->readEntry("user_email",""); fillMailDefaults(); config()->setGroup("Category Colors"); QStringList::Iterator it; for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor)); } KConfig fc (locateLocal("config","kopicalendarrc")); fc.setGroup("CC"); int numCals = fc.readNumEntry("NumberCalendars",0 ); mNextAvailableCalendar = 1; if ( numCals == 0 ) { KopiCalendarFile *kkf = getNewCalendar(); kkf->isStandard = true; kkf->mName = i18n("Standard"); kkf->mFileName = QDir::convertSeparators( locateLocal( "data", "korganizer/mycalendar.ics" ) ); } while ( mNextAvailableCalendar <= numCals ) { //qDebug("Read cal #%d ", mNextAvailableCalendar ); QString prefix = "Cal_" +QString::number( mNextAvailableCalendar ); KopiCalendarFile *kkf = getNewCalendar(); kkf->isStandard = fc.readBoolEntry( prefix+"_isStandard", false ); kkf->isEnabled = fc.readBoolEntry( prefix+"_isEnabled", true); kkf->isRelative = fc.readBoolEntry( prefix+"_isRelative", false ); kkf->isAlarmEnabled = fc.readBoolEntry( prefix+"_isAlarmEnabled", true); kkf->isReadOnly = fc.readBoolEntry( prefix+"_isReadOnly", false); kkf->mName = fc.readEntry( prefix+"_Name", "Calendar"); kkf->mFileName = QDir::convertSeparators( fc.readEntry( prefix+"_FileName", kkf->mFileName) ); kkf->mSavedFileName = QDir::convertSeparators( fc.readEntry( prefix+"_SavedFileName", kkf->mFileName) ); kkf->mDefaultColor = fc.readColorEntry( prefix+"_Color",&mEventColor); if ( kkf->mCalNumber == 1 ) { kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" ); } //qDebug("NAME %s %s", kkf->mName.latin1(), i18n("Birthdays").latin1() ); if ( kkf->mName == i18n("Birthdays") ) { kkf->mFileName = locateLocal( "data", "korganizer/birthdays.ics" ); } if ( kkf->isRelative ) kkf->mFileName = QDir::convertSeparators( KGlobalSettings::calendarDir() + kkf->mSavedFileName ); } KPimPrefs::usrReadConfig(); } KopiCalendarFile * KOPrefs::getCalendar( int num ) { return mDefCalColors[num-1]; } KopiCalendarFile * KOPrefs::getNewCalendar() { KopiCalendarFile * kkf = new KopiCalendarFile(); kkf->mCalNumber = mNextAvailableCalendar; mDefCalColors.resize( mNextAvailableCalendar ); mDefCalColors[mNextAvailableCalendar-1] = kkf; ++mNextAvailableCalendar; kkf->mDefaultColor = mEventColor; kkf->mName = i18n("New Calendar"); mCalendars.append( kkf ); return kkf; } void KOPrefs::deleteCalendar( int num ) { KopiCalendarFile * kkf = mCalendars.first(); while ( kkf ) { if ( kkf->mCalNumber == num ) { qDebug("KOPrefs::deleteCalendar %d ", num ); mCalendars.remove( kkf ); delete kkf; return; } kkf = mCalendars.next(); } } int KOPrefs::getCalendarID( const QString & name ) { KopiCalendarFile * kkf = mCalendars.first(); while ( kkf ) { if ( name == kkf->mName) return kkf->mCalNumber; kkf = mCalendars.next(); } return 1; } int KOPrefs::getFuzzyCalendarID( const QString & name ) { KopiCalendarFile * kkf = mCalendars.first(); while ( kkf ) { if ( name.lower() == kkf->mName.lower()) return kkf->mCalNumber; kkf = mCalendars.next(); } + QString name2 = name; + name2.replace (QRegExp ("_")," " ); + kkf = mCalendars.first(); + while ( kkf ) { + if ( name2.lower() == kkf->mName.lower()) + return kkf->mCalNumber; + kkf = mCalendars.next(); + } return 0; } QString KOPrefs::calName( int calNum) const { return (mDefCalColors[calNum-1])->mName; } QColor KOPrefs::defaultColor( int calNum ) const { if ( calNum == 1 ) return mEventColor; return (mDefCalColors[calNum-1])->mDefaultColor; } void KOPrefs::usrWriteConfig() { config()->setGroup("General"); config()->writeEntry("Custom Categories",mCustomCategories); config()->setGroup("Personal Settings"); config()->writeEntry("user_name",mName); config()->writeEntry("user_email",mEmail); config()->setGroup("Category Colors"); QDictIterator<QColor> it(mCategoryColors); while (it.current()) { config()->writeEntry(it.currentKey(),*(it.current())); ++it; } KConfig fc (locateLocal("config","kopicalendarrc")); fc.setGroup("CC"); fc.deleteGroup( "CC"); fc.setGroup("CC"); fc.writeEntry("NumberCalendars",mCalendars.count()); int numCal = 1; int writeCal = 0; while ( numCal < mNextAvailableCalendar ) { KopiCalendarFile * kkf = mCalendars.first(); while ( kkf ) { //qDebug("cal num %d %d ", kkf->mCalNumber, numCal); if ( kkf->mCalNumber == numCal ) { ++writeCal; //qDebug("Write calendar %d %d ", numCal , writeCal); QString prefix = "Cal_" + QString::number( writeCal ); fc.writeEntry( prefix+"_isStandard", kkf->isStandard ); fc.writeEntry( prefix+"_isEnabled", kkf->isEnabled ); fc.writeEntry( prefix+"_isAlarmEnabled", kkf->isAlarmEnabled ); fc.writeEntry( prefix+"_isReadOnly", kkf->isReadOnly ); fc.writeEntry( prefix+"_isRelative", kkf->isRelative ); fc.writeEntry( prefix+"_Name", kkf->mName); fc.writeEntry( prefix+"_FileName", kkf->mFileName); fc.writeEntry( prefix+"_SavedFileName", kkf->mSavedFileName); fc.writeEntry( prefix+"_Color",kkf->mDefaultColor); } kkf = mCalendars.next(); } ++numCal; } fc.sync(); KPimPrefs::usrWriteConfig(); } void KOPrefs::setCategoryColor(QString cat,const QColor & color) { mCategoryColors.replace(cat,new QColor(color)); } QColor *KOPrefs::categoryColor(QString cat) { QColor *color = 0; if (!cat.isEmpty()) color = mCategoryColors[cat]; if (color) return color; else return &mDefaultCategoryColor; } void KOPrefs::setFullName(const QString &name) { mName = name; } void KOPrefs::setEmail(const QString &email) { //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() ); mEmail = email; } QString KOPrefs::fullName() { if (mEmailControlCenter) { KEMailSettings settings; return settings.getSetting(KEMailSettings::RealName); } else { return mName; } } QString KOPrefs::email() { if (mEmailControlCenter) { KEMailSettings settings; return settings.getSetting(KEMailSettings::EmailAddress); } else { return mEmail; } } KConfig* KOPrefs::getConfig() { return config(); } diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 61a9899..795cd30 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -375,1398 +375,1405 @@ void KSyncManager::enableQuick( bool ask ) QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); syncdesktop.hide();// not implemented! #else QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); #endif lay.addWidget( &syncdesktop); #else mPrefs->mPassiveSyncWithDesktop = false; QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); syncdesktop.hide(); #endif syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.resize( 230,120 ); dia.setCaption( i18n("Enter port for Pi-Sync") ); dia.show(); #ifndef DESKTOP_VERSION int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); #endif if ( ! dia.exec() ) return; dia.hide(); qApp->processEvents(); if ( mPrefs->mPassiveSyncPw != lepw.text() ) { changed = true; mPrefs->mPassiveSyncPw = lepw.text(); } if ( mPrefs->mPassiveSyncPort != lab.text() ) { mPrefs->mPassiveSyncPort = lab.text(); changed = true; } autoStart = autostart.isChecked(); if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { changed = true; mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); } } else autoStart = mPrefs->mPassiveSyncAutoStart; if ( autoStart != mPrefs->mPassiveSyncAutoStart ) changed = true; bool ok; mPrefs->mPassiveSyncAutoStart = false; Q_UINT32 port_t = mPrefs->mPassiveSyncPort.toUInt(&ok); qDebug("%d ", port_t); if ( ! ok || port_t > 65535 ) { KMessageBox::information( 0, i18n("No valid port number:\n%1").arg ( mPrefs->mPassiveSyncPort ), i18n("Pi-Sync Port Error")); return; } Q_UINT16 port = port_t; //qDebug("port %d ", port); mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); mServerSocket->setFileName( defaultFileName() );//bbb if ( !mServerSocket->ok() ) { QTimer::singleShot( 2000, this, SLOT ( displayErrorPort() ) ); delete mServerSocket; mServerSocket = 0; return; } mPrefs->mPassiveSyncAutoStart = autoStart; if ( changed ) { mPrefs->writeConfig(); } connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); connect( mServerSocket, SIGNAL ( request_file(const QString &) ),this, SIGNAL ( request_file(const QString &) ) ); connect( mServerSocket, SIGNAL ( file_received( bool ,const QString &) ), this, SIGNAL ( getFile( bool,const QString & ) ) ); } void KSyncManager::displayErrorPort() { KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error")); } void KSyncManager::syncLocalFile() { QString fn =mPrefs->mLastSyncedLocalFile; QString ext; switch(mTargetApp) { case (KAPI): ext = "(*.vcf)"; break; case (KOPI): ext = "(*.ics/*.vcs)"; break; case (PWMPI): ext = "(*.pwm)"; break; default: qDebug("KSM::syncLocalFile: invalid apptype selected"); break; } fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); if ( fn == "" ) return; if ( syncWithFile( fn, false ) ) { qDebug("KSM::syncLocalFile() successful "); } } bool KSyncManager::syncWithFile( QString fn , bool quick ) { bool ret = false; QFileInfo info; info.setFile( fn ); QString mess; if ( !info. exists() ) { mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); QMessageBox::warning( mParent, i18n("Warning!"), mess ); return ret; } int result = 0; if ( !quick ) { mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); result = QMessageBox::warning( mParent, i18n("Warning!"), mess, i18n("Sync"), i18n("Cancel"), 0, 0, 1 ); if ( result ) return false; } if ( mAskForPreferences ) if ( !edit_sync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); return false; } if ( result == 0 ) { //qDebug("Now sycing ... "); if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ,mCurrentResourceLocal ) ) mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); else mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); if ( ! quick ) mPrefs->mLastSyncedLocalFile = fn; } return ret; } void KSyncManager::quickSyncLocalFile() { if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { qDebug("KSM::quick syncLocalFile() successful "); } } void KSyncManager::multiSync( bool askforPrefs ) { if (blockSave()) return; setBlockSave(true); mCurrentResourceLocal = ""; if ( askforPrefs ) { QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) { setBlockSave(false); mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); return; } } mCurrentSyncDevice = i18n("Multiple profiles") ; mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; if ( askforPrefs ) { if ( !edit_sync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); return; } mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; } mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); qApp->processEvents(); int num = ringSync() ; if ( num > 1 ) ringSync(); setBlockSave(false); if ( num ) emit save(); if ( num ) mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); else mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); return; } int KSyncManager::ringSync() { emit multiResourceSyncStart( false ); int syncedProfiles = 0; unsigned int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); QStringList syncProfileNames = mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); mAskForPreferences = false; mCurrentResourceLocal = ""; for ( i = 0; i < syncProfileNames.count(); ++i ) { mCurrentSyncProfile = i; temp->setName(syncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); bool includeInRingSync = false; switch(mTargetApp) { case (KAPI): includeInRingSync = temp->getIncludeInRingSyncAB(); break; case (KOPI): includeInRingSync = temp->getIncludeInRingSync(); break; case (PWMPI): includeInRingSync = temp->getIncludeInRingSyncPWM(); break; default: qDebug("KSM::ringSync: invalid apptype selected"); break; } if ( includeInRingSync && ( i < 1 || i > 2 )) { mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); ++syncedProfiles; mSyncWithDesktop = false; // mAskForPreferences = temp->getAskForPreferences(); mWriteBackFile = temp->getWriteBackFile(); mWriteBackExistingOnly = temp->getWriteBackExisting(); mIsKapiFile = temp->getIsKapiFile(); mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) { mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); mWriteBackInPast = temp->getWriteBackPastWeeks( ); } mFilterInCal = temp->getFilterInCal(); mFilterOutCal = temp->getFilterOutCal(); mFilterInAB = temp->getFilterInAB(); mFilterOutAB = temp->getFilterOutAB(); mShowSyncSummary = false; mCurrentSyncDevice = syncProfileNames[i] ; mCurrentSyncName = mLocalMachineName; if ( i == 0 ) { mIsKapiFile = false; #ifdef DESKTOP_VERSION syncKDE(); #else syncSharp(); #endif } else { if ( temp->getIsLocalFileSync() ) { switch(mTargetApp) { case (KAPI): if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); break; case (KOPI): if ( syncWithFile( temp->getRemoteFileName( ), false ) ) mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); break; case (PWMPI): if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); break; default: qDebug("KSM: invalid apptype selected"); break; } } else { if ( temp->getIsPhoneSync() ) { mPhoneDevice = temp->getPhoneDevice( ) ; mPhoneConnection = temp->getPhoneConnection( ); mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else if ( temp->getIsPiSync() || temp->getIsPiSyncSpec()) { mSpecificResources.clear(); if ( mTargetApp == KAPI ) { mPassWordPiSync = temp->getRemotePwAB(); mActiveSyncPort = temp->getRemotePortAB(); mActiveSyncIP = temp->getRemoteIPAB(); } else if ( mTargetApp == KOPI ) { mSpecificResources = QStringList::split( ":", temp->getResSpecKopi(),true ); mPassWordPiSync = temp->getRemotePw(); mActiveSyncPort = temp->getRemotePort(); mActiveSyncIP = temp->getRemoteIP(); } else { mPassWordPiSync = temp->getRemotePwPWM(); mActiveSyncPort = temp->getRemotePortPWM(); mActiveSyncIP = temp->getRemoteIPPWM(); } syncPi(); while ( !mPisyncFinished ) { //qDebug("waiting "); qApp->processEvents(); } timer.start(); while ( timer.elapsed () < 2000 ) { qApp->processEvents(); } } else syncRemote( temp, false ); } } timer.start(); mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); while ( timer.elapsed () < 2000 ) { qApp->processEvents(); #ifndef _WIN32_ sleep (1); #endif } } } delete temp; return syncedProfiles; } void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) { QString question; if ( ask ) { question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; if ( QMessageBox::information( mParent, i18n("Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) return; } QString preCommand; QString localTempFile; QString postCommand; switch(mTargetApp) { case (KAPI): preCommand = prof->getPreSyncCommandAB(); postCommand = prof->getPostSyncCommandAB(); localTempFile = prof->getLocalTempFileAB(); break; case (KOPI): preCommand = prof->getPreSyncCommand(); postCommand = prof->getPostSyncCommand(); localTempFile = prof->getLocalTempFile(); break; case (PWMPI): preCommand = prof->getPreSyncCommandPWM(); postCommand = prof->getPostSyncCommandPWM(); localTempFile = prof->getLocalTempFilePWM(); break; default: qDebug("KSM::syncRemote: invalid apptype selected"); break; } int fi; if ( (fi = preCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); } int maxlen = 30; if ( QApplication::desktop()->width() > 320 ) maxlen += 25; mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); int fileSize = 0; int result = system ( preCommand ); // 0 : okay // 256: no such file or dir // qDebug("KSM::Sync: Remote copy result(0 = okay): %d ",result ); if ( result != 0 ) { unsigned int len = maxlen; while ( len < preCommand.length() ) { preCommand.insert( len , "\n" ); len += maxlen +2; } 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 (preCommand) ; QMessageBox::information( mParent, i18n("Sync - ERROR"), question, i18n("Okay!")) ; mParent->topLevelWidget()->setCaption ("KDE-Pim"); return; } mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); if ( syncWithFile( localTempFile, true ) ) { if ( mWriteBackFile ) { int fi; if ( (fi = postCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); } mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); result = system ( postCommand ); qDebug("KSM::Sync:Writing back file result: %d ", result); if ( result != 0 ) { mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); return; } else { mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); } } } return; } bool KSyncManager::edit_pisync_options() { QDialog dia( mParent, "dia", true ); dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); QVBoxLayout lay ( &dia ); lay.setSpacing( 5 ); lay.setMargin( 3 ); QLabel lab1 ( i18n("Password for remote access:"), &dia); lay.addWidget( &lab1 ); QLineEdit le1 (&dia ); lay.addWidget( &le1 ); QLabel lab2 ( i18n("Remote IP address:"), &dia); lay.addWidget( &lab2 ); QLineEdit le2 (&dia ); lay.addWidget( &le2 ); QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia); lay.addWidget( &lab3 ); QLineEdit le3 (&dia ); lay.addWidget( &le3 ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); le1.setText( mPassWordPiSync ); le2.setText( mActiveSyncIP ); le3.setText( mActiveSyncPort ); if ( dia.exec() ) { mPassWordPiSync = le1.text(); mActiveSyncPort = le3.text(); mActiveSyncIP = le2.text(); return true; } return false; } bool KSyncManager::edit_sync_options() { QDialog dia( mParent, "dia", true ); dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); QVBoxLayout lay ( &dia ); lay.setSpacing( 2 ); lay.setMargin( 3 ); lay.addWidget(&gr); QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); //QRadioButton both( i18n("Take both on conflict"), &gr ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); switch ( mSyncAlgoPrefs ) { case 0: loc.setChecked( true); break; case 1: rem.setChecked( true ); break; case 2: newest.setChecked( true); break; case 3: ask.setChecked( true); break; case 4: f_loc.setChecked( true); break; case 5: f_rem.setChecked( true); break; case 6: // both.setChecked( true); break; default: break; } if ( dia.exec() ) { mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; return true; } return false; } QString KSyncManager::getPassword( ) { QString retfile = ""; QDialog dia ( mParent, "input-dialog", true ); QLineEdit lab ( &dia ); lab.setEchoMode( QLineEdit::Password ); QVBoxLayout lay( &dia ); lay.setMargin(7); lay.setSpacing(7); lay.addWidget( &lab); dia.setFixedSize( 230,50 ); dia.setCaption( i18n("Enter password") ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.show(); int res = dia.exec(); if ( res ) retfile = lab.text(); dia.hide(); qApp->processEvents(); return retfile; } void KSyncManager::confSync() { static KSyncPrefsDialog* sp = 0; if ( ! sp ) { sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); } sp->usrReadConfig(); #ifndef DESKTOP_VERSION sp->showMaximized(); #else sp->show(); #endif sp->exec(); QStringList oldSyncProfileNames = mSyncProfileNames; mSyncProfileNames = sp->getSyncProfileNames(); mLocalMachineName = sp->getLocalMachineName (); int ii; for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); } QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); } void KSyncManager::syncKDE() { mSyncWithDesktop = true; emit save(); switch(mTargetApp) { case (KAPI): { #ifdef DESKTOP_VERSION QString command = "kdeabdump33"; QString commandfile = "kdeabdump33"; QString commandpath = qApp->applicationDirPath () + "/"; #else QString command = "kdeabdump33"; QString commandfile = "kdeabdump33"; QString commandpath = QDir::homeDirPath ()+"/"; #endif if ( ! QFile::exists ( commandpath+commandfile ) ) command = commandfile; else command = commandpath+commandfile; QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; int result = system ( command.latin1()); qDebug("AB dump 33 command call result: %d ", result); if ( result != 0 ) { qDebug("Calling AB dump version 33 failed. Trying 34... "); commandfile = "kdeabdump34"; if ( ! QFile::exists ( commandpath+commandfile ) ) command = commandfile; else command = commandpath+commandfile; result = system ( command.latin1()); qDebug("AB dump 34 command call result: %d ", result); if ( result != 0 ) { KMessageBox::error( 0, i18n("Error accessing KDE addressbook data.\nMake sure the file\n%1kdeabdump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); return; } } if ( syncWithFile( fileName,true ) ) { if ( mWriteBackFile ) { command += " --read"; system ( command.latin1()); } } } break; case (KOPI): { #ifdef DESKTOP_VERSION QString command = "kdecaldump33"; QString commandfile = "kdecaldump33"; QString commandpath = qApp->applicationDirPath () + "/"; #else QString command = "kdecaldump33"; QString commandfile = "kdecaldump33"; QString commandpath = QDir::homeDirPath ()+"/"; #endif if ( ! QFile::exists ( commandpath+commandfile ) ) command = commandfile; else command = commandpath+commandfile; QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; int result = system ( command.latin1()); qDebug("Cal dump 33 command call result result: %d ", result); if ( result != 0 ) { qDebug("Calling CAL dump version 33 failed. Trying 34... "); commandfile = "kdecaldump34"; if ( ! QFile::exists ( commandpath+commandfile ) ) command = commandfile; else command = commandpath+commandfile; result = system ( command.latin1()); qDebug("Cal dump 34 command call result result: %d ", result); if ( result != 0 ) { KMessageBox::error( 0, i18n("Error accessing KDE calendar data.\nMake sure the file\n%1kdecaldump3x\nexists ( x = 3 or 4 ).\nSupported KDE versions are 3.3 and 3.4.\nUsed version should be auto detected.\n").arg( commandpath )); return; } } if ( syncWithFile( fileName,true ) ) { if ( mWriteBackFile ) { command += " --read"; system ( command.latin1()); } } } break; case (PWMPI): break; default: qDebug("KSM::slotSyncMenu: invalid apptype selected"); break; } } void KSyncManager::syncSharp() { if ( ! syncExternalApplication("sharp") ) qDebug("KSM::ERROR sync sharp "); } bool KSyncManager::syncExternalApplication(QString resource) { emit save(); if ( mAskForPreferences ) if ( !edit_sync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); return false; } qDebug("KSM::Sync extern %s", resource.latin1()); bool syncOK = mImplementation->syncExternal(this, resource); return syncOK; } void KSyncManager::syncPhone() { syncExternalApplication("phone"); } void KSyncManager::showProgressBar(int percentage, QString caption, int total) { if (!bar->isVisible()) { int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar->sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar->setCaption (caption); bar->setTotalSteps ( total ) ; bar->show(); } bar->raise(); bar->setProgress( percentage ); qApp->processEvents(); } void KSyncManager::hideProgressBar() { bar->hide(); qApp->processEvents(); } bool KSyncManager::isProgressBarCanceled() { return !bar->isVisible(); } QString KSyncManager::syncFileName() { QString fn = "tempfile"; switch(mTargetApp) { case (KAPI): fn = "tempsyncab.vcf"; break; case (KOPI): fn = "tempsynccal.ics"; break; case (PWMPI): fn = "tempsyncpw.pwm"; break; default: break; } #ifdef DESKTOP_VERSION return locateLocal( "tmp", fn ); #else return (QString( "/tmp/" )+ fn ); #endif } void KSyncManager::syncPi() { mIsKapiFile = true; mPisyncFinished = false; qApp->processEvents(); if ( mAskForPreferences ) if ( !edit_pisync_options()) { mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); mPisyncFinished = true; return; } bool ok; Q_UINT16 port = mActiveSyncPort.toUInt(&ok); if ( ! ok ) { mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); mPisyncFinished = true; return; } mCurrentResourceLocal = ""; mCurrentResourceRemote = ""; + qDebug ( "KSM: sync pi %d",mSpecificResources.count() ); if ( mSpecificResources.count() ) { int lastSyncRes = mSpecificResources.count()/2; int ccc = mSpecificResources.count()-1; while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { --ccc; --lastSyncRes; + qDebug ( "KSM: sync pi %d",ccc ); } int startLocal = 0; int startRemote = mSpecificResources.count()/2; emit multiResourceSyncStart( true ); while ( startLocal < mSpecificResources.count()/2 ) { if ( startLocal+1 >= lastSyncRes ) emit multiResourceSyncStart( false ); mPisyncFinished = false; mCurrentResourceLocal = mSpecificResources[ startLocal ]; - mCurrentResourceRemote = mSpecificResources[ startRemote ]; + mCurrentResourceRemote = mSpecificResources[ startRemote ]; + qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); if ( !mCurrentResourceRemote.isEmpty() ) { qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); commandSocket->readFile( syncFileName() ); while ( !mPisyncFinished ) { //qDebug("waiting "); qApp->processEvents(); } } + ++startRemote; ++startLocal; } + mPisyncFinished = true; } else { KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); commandSocket->readFile( syncFileName() ); } } void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) { //enum { success, errorW, errorR, quiet }; if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { if ( state == KCommandSocket::errorPW ) mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); else if ( state == KCommandSocket::errorCA ) mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); else if ( state == KCommandSocket::errorFI ) mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); else if ( state == KCommandSocket::errorED ) mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); else if ( state == KCommandSocket::errorUN ) mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); delete s; if ( state == KCommandSocket::errorR ) { KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); commandSocket->sendStop(); } mPisyncFinished = true; return; } else if ( state == KCommandSocket::errorW ) { mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); mPisyncFinished = true; } else if ( state == KCommandSocket::successR ) { QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); } else if ( state == KCommandSocket::successW ) { mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); mPisyncFinished = true; } else if ( state == KCommandSocket::quiet ){ qDebug("KSS: quiet "); mPisyncFinished = true; } else { qDebug("KSS: Error: unknown state: %d ", state); mPisyncFinished = true; } delete s; } void KSyncManager::readFileFromSocket() { QString fileName = syncFileName(); bool syncOK = true; mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); if ( ! syncWithFile( fileName , true ) ) { mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); syncOK = false; } KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); if ( mWriteBackFile && syncOK ) { mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); commandSocket->writeFile( fileName ); } else { commandSocket->sendStop(); if ( syncOK ) mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); mPisyncFinished = true; } } KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) { mPassWord = pw; mSocket = 0; mSyncActionDialog = 0; blockRC = false; mErrorMessage = 0; } void KServerSocket::newConnection ( int socket ) { // qDebug("KServerSocket:New connection %d ", socket); if ( mSocket ) { qDebug("KSS::newConnection Socket deleted! "); delete mSocket; mSocket = 0; } mSocket = new QSocket( this ); connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); mSocket->setSocket( socket ); } void KServerSocket::discardClient() { QTimer::singleShot( 10, this , SLOT ( deleteSocket())); } void KServerSocket::deleteSocket() { qDebug("KSS::deleteSocket"); if ( mSocket ) { delete mSocket; mSocket = 0; } if ( mErrorMessage ) QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); } void KServerSocket::readClient() { if ( blockRC ) return; if ( mSocket == 0 ) { qDebug("ERROR::KSS::readClient(): mSocket == 0 "); return; } if ( mErrorMessage ) { mErrorMessage = 999; error_connect("ERROR_ED\r\n\r\n"); return; } mResource = ""; mErrorMessage = 0; //qDebug("KServerSocket::readClient()"); if ( mSocket->canReadLine() ) { QString line = mSocket->readLine(); //qDebug("KServerSocket readline: %s ", line.latin1()); QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); if ( tokens[0] == "GET" ) { if ( tokens[1] == mPassWord ) { //emit sendFile( mSocket ); bool ok = false; QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); if ( ok ) { KSyncManager::mRequestedSyncEvent = dt; } else KSyncManager::mRequestedSyncEvent = QDateTime(); mResource =tokens[3]; send_file(); } else { mErrorMessage = 1; error_connect("ERROR_PW\r\n\r\n"); } } if ( tokens[0] == "PUT" ) { if ( tokens[1] == mPassWord ) { //emit getFile( mSocket ); blockRC = true; mResource =tokens[2]; get_file(); } else { mErrorMessage = 2; error_connect("ERROR_PW\r\n\r\n"); end_connect(); } } if ( tokens[0] == "STOP" ) { //emit endConnect(); end_connect(); } } } void KServerSocket::displayErrorMessage() { if ( mErrorMessage == 1 ) { KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); mErrorMessage = 0; } else if ( mErrorMessage == 2 ) { KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); mErrorMessage = 0; } } void KServerSocket::error_connect( QString errmess ) { QTextStream os( mSocket ); os.setEncoding( QTextStream::Latin1 ); os << errmess ; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) { QTimer::singleShot( 0, this , SLOT ( discardClient())); } } void KServerSocket::end_connect() { delete mSyncActionDialog; mSyncActionDialog = 0; } void KServerSocket::send_file() { //qDebug("MainWindow::sendFile(QSocket* s) "); if ( mSyncActionDialog ) delete mSyncActionDialog; mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); mSyncActionDialog->setCaption(i18n("Received sync request")); QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); label->setAlignment ( Qt::AlignHCenter ); QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); lay->addWidget( label); lay->setMargin(7); lay->setSpacing(7); if ( KSyncManager::mRequestedSyncEvent.isValid() ) { int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); //secs = 333; if ( secs < 0 ) secs = secs * (-1); if ( secs > 30 ) //if ( true ) { QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); QLabel* label = new QLabel( warning, mSyncActionDialog ); label->setAlignment ( Qt::AlignHCenter ); lay->addWidget( label); if ( secs > 180 ) { if ( secs > 300 ) { if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { qDebug("KSS::Sync cancelled ,cs"); mErrorMessage = 0; end_connect(); error_connect("ERROR_CA\r\n\r\n"); return ; } } QFont f = label->font(); f.setPointSize ( f.pointSize() *2 ); f. setBold (true ); QLabel* label = new QLabel( warning, mSyncActionDialog ); label->setFont( f ); warning = i18n("ADJUST\nYOUR\nCLOCKS!"); label->setText( warning ); label->setAlignment ( Qt::AlignHCenter ); lay->addWidget( label); mSyncActionDialog->setFixedSize( 230, 300); } else { mSyncActionDialog->setFixedSize( 230, 200); } } else { mSyncActionDialog->setFixedSize( 230, 120); } } else mSyncActionDialog->setFixedSize( 230, 120); mSyncActionDialog->show(); mSyncActionDialog->raise(); emit request_file(mResource); emit request_file(); qApp->processEvents(); QString fileName = mFileName; QFile file( fileName ); if (!file.open( IO_ReadOnly ) ) { mErrorMessage = 0; end_connect(); error_connect("ERROR_FI\r\n\r\n"); return ; } mSyncActionDialog->setCaption( i18n("Sending file...") ); QTextStream ts( &file ); ts.setEncoding( QTextStream::Latin1 ); QTextStream os( mSocket ); os.setEncoding( QTextStream::Latin1 ); while ( ! ts.atEnd() ) { os << ts.readLine() << "\r\n"; } os << "\r\n"; //os << ts.read(); file.close(); mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); } void KServerSocket::get_file() { mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); piTime.start(); piFileString = ""; QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); } void KServerSocket::readBackFileFromSocket() { //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); while ( mSocket->canReadLine () ) { piTime.restart(); QString line = mSocket->readLine (); piFileString += line; //qDebug("readline: %s ", line.latin1()); mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); } if ( piTime.elapsed () < 3000 ) { // wait for more //qDebug("waitformore "); QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); return; } QString fileName = mFileName; QFile file ( fileName ); if (!file.open( IO_WriteOnly ) ) { delete mSyncActionDialog; mSyncActionDialog = 0; qDebug("KSS:Error open read back file "); piFileString = ""; emit file_received( false, mResource); emit file_received( false); blockRC = false; return ; } // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts ( &file ); ts.setEncoding( QTextStream::Latin1 ); mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); ts << piFileString; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); file.close(); piFileString = ""; emit file_received( true, mResource ); emit file_received( true); delete mSyncActionDialog; mSyncActionDialog = 0; blockRC = false; } KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) { mRemoteResource = remres; if ( mRemoteResource.isEmpty() ) mRemoteResource = "ALL"; + else + mRemoteResource.replace (QRegExp (" "),"_" ); mPassWord = password; mSocket = 0; mFirst = false; mFirstLine = true; mPort = port; mHost = host; tlw = cap; mRetVal = quiet; mTimerSocket = new QTimer ( this ); connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); mConnectProgress.setCaption( i18n("Pi-Sync") ); connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); mConnectCount = -1; } void KCommandSocket::sendFileRequest() { if ( tlw ) tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); mConnectProgress.hide(); mConnectCount = 300;mConnectMax = 300; mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); mTimerSocket->start( 100, true ); QTextStream os( mSocket ); os.setEncoding( QTextStream::Latin1 ); QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); - os << "GET " << mPassWord << curDt << mRemoteResource << "\r\n\r\n"; + os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; } void KCommandSocket::readFile( QString fn ) { if ( !mSocket ) { mSocket = new QSocket( this ); connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); } mFileString = ""; mFileName = fn; mFirst = true; if ( tlw ) tlw->setCaption( i18n("Trying to connect to remote...") ); mConnectCount = 30;mConnectMax = 30; mTimerSocket->start( 1000, true ); mSocket->connectToHost( mHost, mPort ); qDebug("KSS: Waiting for connection"); } void KCommandSocket::updateConnectDialog() { if ( mConnectCount == mConnectMax ) { //qDebug("MAXX %d", mConnectMax); mConnectProgress.setTotalSteps ( 30 ); mConnectProgress.show(); mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); } //qDebug("updateConnectDialog() %d", mConnectCount); mConnectProgress.raise(); mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); --mConnectCount; if ( mConnectCount > 0 ) mTimerSocket->start( 1000, true ); else deleteSocket(); } void KCommandSocket::writeFile( QString fileName ) { if ( !mSocket ) { mSocket = new QSocket( this ); connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); } mFileName = fileName ; mConnectCount = 30;mConnectMax = 30; mTimerSocket->start( 1000, true ); mSocket->connectToHost( mHost, mPort ); } void KCommandSocket::writeFileToSocket() { mTimerSocket->stop(); QFile file2( mFileName ); if (!file2.open( IO_ReadOnly ) ) { mConnectProgress.hide(); mConnectCount = -1; mRetVal= errorW; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); return ; } mConnectProgress.setTotalSteps ( file2.size() ); mConnectProgress.show(); int count = 0; mConnectProgress.setLabelText( i18n("Sending back synced file...") ); mConnectProgress.setProgress( count ); mConnectProgress.blockSignals( true ); QTextStream ts2( &file2 ); ts2.setEncoding( QTextStream::Latin1 ); QTextStream os2( mSocket ); os2.setEncoding( QTextStream::Latin1 ); - os2 << "PUT " << mPassWord << mRemoteResource << "\r\n\r\n";; + os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; int byteCount = 0; int byteMax = file2.size()/53; while ( ! ts2.atEnd() ) { qApp->processEvents(); if ( byteCount > byteMax ) { byteCount = 0; mConnectProgress.setProgress( count ); } QString temp = ts2.readLine(); count += temp.length(); byteCount += temp.length(); os2 << temp << "\r\n"; } file2.close(); mConnectProgress.hide(); mConnectCount = -1; os2 << "\r\n"; mRetVal= successW; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); mConnectProgress.blockSignals( false ); } void KCommandSocket::sendStop() { if ( !mSocket ) { mSocket = new QSocket( this ); connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); } mSocket->connectToHost( mHost, mPort ); QTextStream os2( mSocket ); os2.setEncoding( QTextStream::Latin1 ); os2 << "STOP\r\n\r\n"; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( deleteSocket())); } void KCommandSocket::startReadFileFromSocket() { if ( ! mFirst ) return; mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); mFirst = false; mFileString = ""; mTime.start(); mFirstLine = true; QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); } void KCommandSocket::readFileFromSocket() { //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); while ( mSocket->canReadLine () ) { mTime.restart(); QString line = mSocket->readLine (); if ( mFirstLine ) { mFirstLine = false; if ( line.left( 6 ) == "ERROR_" ) { mTimerSocket->stop(); mConnectCount = -1; if ( line.left( 8 ) == "ERROR_PW" ) { mRetVal = errorPW; deleteSocket(); return ; } if ( line.left( 8 ) == "ERROR_CA" ) { mRetVal = errorCA; deleteSocket(); return ; } if ( line.left( 8 ) == "ERROR_FI" ) { mRetVal = errorFI; deleteSocket(); return ; } if ( line.left( 8 ) == "ERROR_ED" ) { mRetVal = errorED; deleteSocket(); return ; } mRetVal = errorUN; deleteSocket(); return ; } } mFileString += line; //qDebug("readline: %s ", line.latin1()); } if ( mTime.elapsed () < 3000 ) { // wait for more //qDebug("waitformore "); QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); return; } mTimerSocket->stop(); mConnectCount = -1; mConnectProgress.hide(); QString fileName = mFileName; QFile file ( fileName ); if (!file.open( IO_WriteOnly ) ) { mFileString = ""; mRetVal = errorR; qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); deleteSocket(); return ; } // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts ( &file ); ts.setEncoding( QTextStream::Latin1 ); ts << mFileString; file.close(); mFileString = ""; mRetVal = successR; mSocket->close(); // if state is not idle, deleteSocket(); is called via // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); if ( mSocket->state() == QSocket::Idle ) deleteSocket(); } void KCommandSocket::deleteSocket() { //qDebug("KCommandSocket::deleteSocket() "); mConnectProgress.hide(); if ( mConnectCount >= 0 ) { mTimerSocket->stop(); mRetVal = errorTO; qDebug("KCS::Connection to remote host timed out"); if ( mSocket ) { mSocket->close(); //if ( mSocket->state() == QSocket::Idle ) // deleteSocket(); delete mSocket; mSocket = 0; } if ( mConnectCount == 0 ) KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); else if ( tlw ) tlw->setCaption( i18n("Connection to remote host cancelled!") ); emit commandFinished( this, mRetVal ); return; } //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); if ( mSocket) delete mSocket; mSocket = 0; qDebug("commandFinished "); emit commandFinished( this, mRetVal ); } |