summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-12 19:26:13 (UTC)
committer zautrix <zautrix>2004-09-12 19:26:13 (UTC)
commit5b434dd78f71bcea5e6067fc8ae0faaaea313f9d (patch) (unidiff)
treeed532e602a3b503b72a46ea18d40e3a5dc97aa3f
parentbc4153a99e205f43d0144e2e910730dd1a14d402 (diff)
downloadkdepimpi-5b434dd78f71bcea5e6067fc8ae0faaaea313f9d.zip
kdepimpi-5b434dd78f71bcea5e6067fc8ae0faaaea313f9d.tar.gz
kdepimpi-5b434dd78f71bcea5e6067fc8ae0faaaea313f9d.tar.bz2
phone fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp23
-rw-r--r--libkcal/alarm.cpp16
-rw-r--r--libkcal/alarm.h2
-rw-r--r--libkcal/phoneformat.cpp58
4 files changed, 63 insertions, 36 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index cfd9290..d5d31e2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -935,511 +935,524 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
935 int changedRemote = 0; 935 int changedRemote = 0;
936 //QPtrList<Event> el = local->rawEvents(); 936 //QPtrList<Event> el = local->rawEvents();
937 Event* eventR; 937 Event* eventR;
938 QString uid; 938 QString uid;
939 int take; 939 int take;
940 Event* eventL; 940 Event* eventL;
941 Event* eventRSync; 941 Event* eventRSync;
942 Event* eventLSync; 942 Event* eventLSync;
943 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 943 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
944 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 944 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
945 bool fullDateRange = false; 945 bool fullDateRange = false;
946 local->resetTempSyncStat(); 946 local->resetTempSyncStat();
947 mLastCalendarSync = QDateTime::currentDateTime(); 947 mLastCalendarSync = QDateTime::currentDateTime();
948 QDateTime modifiedCalendar = mLastCalendarSync;; 948 QDateTime modifiedCalendar = mLastCalendarSync;;
949 eventLSync = getLastSyncEvent(); 949 eventLSync = getLastSyncEvent();
950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 950 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
951 if ( eventR ) { 951 if ( eventR ) {
952 eventRSync = (Event*) eventR->clone(); 952 eventRSync = (Event*) eventR->clone();
953 remote->deleteEvent(eventR ); 953 remote->deleteEvent(eventR );
954 954
955 } else { 955 } else {
956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 956 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
957 eventRSync = (Event*)eventLSync->clone(); 957 eventRSync = (Event*)eventLSync->clone();
958 } else { 958 } else {
959 fullDateRange = true; 959 fullDateRange = true;
960 eventRSync = new Event(); 960 eventRSync = new Event();
961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 961 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 962 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
963 eventRSync->setDtStart( mLastCalendarSync ); 963 eventRSync->setDtStart( mLastCalendarSync );
964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 964 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
965 eventRSync->setCategories( i18n("SyncEvent") ); 965 eventRSync->setCategories( i18n("SyncEvent") );
966 } 966 }
967 } 967 }
968 if ( eventLSync->dtStart() == mLastCalendarSync ) 968 if ( eventLSync->dtStart() == mLastCalendarSync )
969 fullDateRange = true; 969 fullDateRange = true;
970 970
971 if ( ! fullDateRange ) { 971 if ( ! fullDateRange ) {
972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 972 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
973 973
974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 974 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 975 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
976 fullDateRange = true; 976 fullDateRange = true;
977 } 977 }
978 } 978 }
979 if ( fullDateRange ) 979 if ( fullDateRange )
980 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 980 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
981 else 981 else
982 mLastCalendarSync = eventLSync->dtStart(); 982 mLastCalendarSync = eventLSync->dtStart();
983 // for resyncing if own file has changed 983 // for resyncing if own file has changed
984 if ( mCurrentSyncDevice == "deleteaftersync" ) { 984 if ( mCurrentSyncDevice == "deleteaftersync" ) {
985 mLastCalendarSync = loadedFileVersion; 985 mLastCalendarSync = loadedFileVersion;
986 qDebug("setting mLastCalendarSync "); 986 qDebug("setting mLastCalendarSync ");
987 } 987 }
988 //qDebug("*************************** "); 988 //qDebug("*************************** ");
989 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 989 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() );
990 QPtrList<Incidence> er = remote->rawIncidences(); 990 QPtrList<Incidence> er = remote->rawIncidences();
991 Incidence* inR = er.first(); 991 Incidence* inR = er.first();
992 Incidence* inL; 992 Incidence* inL;
993 QProgressBar bar( er.count(),0 ); 993 QProgressBar bar( er.count(),0 );
994 bar.setCaption (i18n("Syncing - close to abort!") ); 994 bar.setCaption (i18n("Syncing - close to abort!") );
995 995
996 int w = 300; 996 int w = 300;
997 if ( QApplication::desktop()->width() < 320 ) 997 if ( QApplication::desktop()->width() < 320 )
998 w = 220; 998 w = 220;
999 int h = bar.sizeHint().height() ; 999 int h = bar.sizeHint().height() ;
1000 int dw = QApplication::desktop()->width(); 1000 int dw = QApplication::desktop()->width();
1001 int dh = QApplication::desktop()->height(); 1001 int dh = QApplication::desktop()->height();
1002 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1002 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1003 bar.show(); 1003 bar.show();
1004 int modulo = (er.count()/10)+1; 1004 int modulo = (er.count()/10)+1;
1005 int incCounter = 0; 1005 int incCounter = 0;
1006 while ( inR ) { 1006 while ( inR ) {
1007 if ( ! bar.isVisible() ) 1007 if ( ! bar.isVisible() )
1008 return false; 1008 return false;
1009 if ( incCounter % modulo == 0 ) 1009 if ( incCounter % modulo == 0 )
1010 bar.setProgress( incCounter ); 1010 bar.setProgress( incCounter );
1011 ++incCounter; 1011 ++incCounter;
1012 uid = inR->uid(); 1012 uid = inR->uid();
1013 bool skipIncidence = false; 1013 bool skipIncidence = false;
1014 if ( uid.left(15) == QString("last-syncEvent-") ) 1014 if ( uid.left(15) == QString("last-syncEvent-") )
1015 skipIncidence = true; 1015 skipIncidence = true;
1016 1016
1017 qApp->processEvents(); 1017 qApp->processEvents();
1018 if ( !skipIncidence ) { 1018 if ( !skipIncidence ) {
1019 inL = local->incidence( uid ); 1019 inL = local->incidence( uid );
1020 if ( inL ) { // maybe conflict - same uid in both calendars 1020 if ( inL ) { // maybe conflict - same uid in both calendars
1021 int maxrev = inL->revision(); 1021 int maxrev = inL->revision();
1022 if ( maxrev < inR->revision() ) 1022 if ( maxrev < inR->revision() )
1023 maxrev = inR->revision(); 1023 maxrev = inR->revision();
1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1024 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1025 //qDebug("take %d %s ", take, inL->summary().latin1()); 1025 //qDebug("take %d %s ", take, inL->summary().latin1());
1026 if ( take == 3 ) 1026 if ( take == 3 )
1027 return false; 1027 return false;
1028 if ( take == 1 ) {// take local 1028 if ( take == 1 ) {// take local
1029 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1029 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1030 remote->deleteIncidence( inR ); 1030 remote->deleteIncidence( inR );
1031 if ( inL->revision() < maxrev ) 1031 if ( inL->revision() < maxrev )
1032 inL->setRevision( maxrev ); 1032 inL->setRevision( maxrev );
1033 remote->addIncidence( inL->clone() ); 1033 remote->addIncidence( inL->clone() );
1034 ++changedRemote; 1034 ++changedRemote;
1035 } else { 1035 } else {
1036 if ( inR->revision() < maxrev ) 1036 if ( inR->revision() < maxrev )
1037 inR->setRevision( maxrev ); 1037 inR->setRevision( maxrev );
1038 local->deleteIncidence( inL ); 1038 local->deleteIncidence( inL );
1039 local->addIncidence( inR->clone() ); 1039 local->addIncidence( inR->clone() );
1040 ++changedLocal; 1040 ++changedLocal;
1041 } 1041 }
1042 } 1042 }
1043 } else { // no conflict 1043 } else { // no conflict
1044 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1044 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1045 QString des = eventLSync->description(); 1045 QString des = eventLSync->description();
1046 QString pref = "e"; 1046 QString pref = "e";
1047 if ( inR->type() == "Todo" ) 1047 if ( inR->type() == "Todo" )
1048 pref = "t"; 1048 pref = "t";
1049 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1049 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1050 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1050 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1051 //remote->deleteIncidence( inR ); 1051 //remote->deleteIncidence( inR );
1052 ++deletedEventR; 1052 ++deletedEventR;
1053 } else { 1053 } else {
1054 inR->setLastModified( modifiedCalendar ); 1054 inR->setLastModified( modifiedCalendar );
1055 local->addIncidence( inR->clone() ); 1055 local->addIncidence( inR->clone() );
1056 ++addedEvent; 1056 ++addedEvent;
1057 } 1057 }
1058 } else { 1058 } else {
1059 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1059 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1060 inR->setLastModified( modifiedCalendar ); 1060 inR->setLastModified( modifiedCalendar );
1061 local->addIncidence( inR->clone() ); 1061 local->addIncidence( inR->clone() );
1062 ++addedEvent; 1062 ++addedEvent;
1063 } else { 1063 } else {
1064 checkExternSyncEvent(eventRSyncSharp, inR); 1064 checkExternSyncEvent(eventRSyncSharp, inR);
1065 remote->deleteIncidence( inR ); 1065 remote->deleteIncidence( inR );
1066 ++deletedEventR; 1066 ++deletedEventR;
1067 } 1067 }
1068 } 1068 }
1069 } 1069 }
1070 } 1070 }
1071 inR = er.next(); 1071 inR = er.next();
1072 } 1072 }
1073 QPtrList<Incidence> el = local->rawIncidences(); 1073 QPtrList<Incidence> el = local->rawIncidences();
1074 inL = el.first(); 1074 inL = el.first();
1075 modulo = (el.count()/10)+1; 1075 modulo = (el.count()/10)+1;
1076 bar.setCaption (i18n("Add / remove events") ); 1076 bar.setCaption (i18n("Add / remove events") );
1077 bar.setTotalSteps ( el.count() ) ; 1077 bar.setTotalSteps ( el.count() ) ;
1078 bar.show(); 1078 bar.show();
1079 incCounter = 0; 1079 incCounter = 0;
1080 1080
1081 while ( inL ) { 1081 while ( inL ) {
1082 1082
1083 qApp->processEvents(); 1083 qApp->processEvents();
1084 if ( ! bar.isVisible() ) 1084 if ( ! bar.isVisible() )
1085 return false; 1085 return false;
1086 if ( incCounter % modulo == 0 ) 1086 if ( incCounter % modulo == 0 )
1087 bar.setProgress( incCounter ); 1087 bar.setProgress( incCounter );
1088 ++incCounter; 1088 ++incCounter;
1089 uid = inL->uid(); 1089 uid = inL->uid();
1090 bool skipIncidence = false; 1090 bool skipIncidence = false;
1091 if ( uid.left(15) == QString("last-syncEvent-") ) 1091 if ( uid.left(15) == QString("last-syncEvent-") )
1092 skipIncidence = true; 1092 skipIncidence = true;
1093 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1093 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1094 skipIncidence = true; 1094 skipIncidence = true;
1095 if ( !skipIncidence ) { 1095 if ( !skipIncidence ) {
1096 inR = remote->incidence( uid ); 1096 inR = remote->incidence( uid );
1097 if ( ! inR ) { 1097 if ( ! inR ) {
1098 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1098 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1099 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1099 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1100 local->deleteIncidence( inL ); 1100 local->deleteIncidence( inL );
1101 ++deletedEventL; 1101 ++deletedEventL;
1102 } else { 1102 } else {
1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1104 inL->removeID(mCurrentSyncDevice ); 1104 inL->removeID(mCurrentSyncDevice );
1105 ++addedEventR; 1105 ++addedEventR;
1106 inL->setLastModified( modifiedCalendar ); 1106 inL->setLastModified( modifiedCalendar );
1107 remote->addIncidence( inL->clone() ); 1107 remote->addIncidence( inL->clone() );
1108 } 1108 }
1109 } 1109 }
1110 } else { 1110 } else {
1111 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1111 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1112 checkExternSyncEvent(eventLSyncSharp, inL); 1112 checkExternSyncEvent(eventLSyncSharp, inL);
1113 local->deleteIncidence( inL ); 1113 local->deleteIncidence( inL );
1114 ++deletedEventL; 1114 ++deletedEventL;
1115 } else { 1115 } else {
1116 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1116 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1117 ++addedEventR; 1117 ++addedEventR;
1118 inL->setLastModified( modifiedCalendar ); 1118 inL->setLastModified( modifiedCalendar );
1119 remote->addIncidence( inL->clone() ); 1119 remote->addIncidence( inL->clone() );
1120 } 1120 }
1121 } 1121 }
1122 } 1122 }
1123 } 1123 }
1124 } 1124 }
1125 inL = el.next(); 1125 inL = el.next();
1126 } 1126 }
1127 int delFut = 0;
1127 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1128 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1128 er = remote->rawIncidences(); 1129 er = remote->rawIncidences();
1129 inR = er.first(); 1130 inR = er.first();
1130 QDateTime dt; 1131 QDateTime dt;
1131 QDateTime cur = QDateTime::currentDateTime(); 1132 QDateTime cur = QDateTime::currentDateTime();
1132 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); 1133 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
1133 while ( inR ) { 1134 while ( inR ) {
1134 if ( inR->type() == "Todo" ) { 1135 if ( inR->type() == "Todo" ) {
1135 Todo * t = (Todo*)inR; 1136 Todo * t = (Todo*)inR;
1136 if ( t->hasDueDate() ) 1137 if ( t->hasDueDate() )
1137 dt = t->dtDue(); 1138 dt = t->dtDue();
1138 else 1139 else
1139 dt = cur.addSecs( 62 ); 1140 dt = cur.addSecs( 62 );
1140 } 1141 }
1141 else dt = inR->dtStart(); 1142 else if (inR->type() == "Event" ) {
1142 if ( dt < cur || dt > end ) 1143 bool ok;
1144 dt = inR->getNextOccurence( cur, &ok );
1145 if ( !ok )
1146 dt = cur.addSecs( -62 );
1147 }
1148 else
1149 dt = inR->dtStart();
1150 if ( dt < cur || dt > end ) {
1143 remote->deleteIncidence( inR ); 1151 remote->deleteIncidence( inR );
1152 ++delFut;
1153 }
1144 inR = er.next(); 1154 inR = er.next();
1145 } 1155 }
1146 } 1156 }
1147 bar.hide(); 1157 bar.hide();
1148 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1158 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1149 eventLSync->setReadOnly( false ); 1159 eventLSync->setReadOnly( false );
1150 eventLSync->setDtStart( mLastCalendarSync ); 1160 eventLSync->setDtStart( mLastCalendarSync );
1151 eventRSync->setDtStart( mLastCalendarSync ); 1161 eventRSync->setDtStart( mLastCalendarSync );
1152 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1162 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1153 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1163 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1154 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1164 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1155 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1165 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1156 eventLSync->setReadOnly( true ); 1166 eventLSync->setReadOnly( true );
1157 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1167 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1158 remote->addEvent( eventRSync ); 1168 remote->addEvent( eventRSync );
1159 QString mes; 1169 QString mes;
1160 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1170 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1171 QString delmess;
1172 if ( delFut ) {
1173 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
1174 mes += delmess;
1175 }
1161 if ( KOPrefs::instance()->mShowSyncSummary ) { 1176 if ( KOPrefs::instance()->mShowSyncSummary ) {
1162 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1177 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1163 } 1178 }
1164 qDebug( mes ); 1179 qDebug( mes );
1165 mCalendar->checkAlarmForIncidence( 0, true ); 1180 mCalendar->checkAlarmForIncidence( 0, true );
1166 return syncOK; 1181 return syncOK;
1167} 1182}
1168 1183
1169void CalendarView::setSyncDevice( QString s ) 1184void CalendarView::setSyncDevice( QString s )
1170{ 1185{
1171 mCurrentSyncDevice= s; 1186 mCurrentSyncDevice= s;
1172} 1187}
1173void CalendarView::setSyncName( QString s ) 1188void CalendarView::setSyncName( QString s )
1174{ 1189{
1175 mCurrentSyncName= s; 1190 mCurrentSyncName= s;
1176} 1191}
1177bool CalendarView::syncCalendar(QString filename, int mode) 1192bool CalendarView::syncCalendar(QString filename, int mode)
1178{ 1193{
1179 mGlobalSyncMode = SYNC_MODE_NORMAL; 1194 mGlobalSyncMode = SYNC_MODE_NORMAL;
1180 CalendarLocal* calendar = new CalendarLocal(); 1195 CalendarLocal* calendar = new CalendarLocal();
1181 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1196 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1182 FileStorage* storage = new FileStorage( calendar ); 1197 FileStorage* storage = new FileStorage( calendar );
1183 bool syncOK = false; 1198 bool syncOK = false;
1184 storage->setFileName( filename ); 1199 storage->setFileName( filename );
1185 // qDebug("loading ... "); 1200 // qDebug("loading ... ");
1186 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1201 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1187 getEventViewerDialog()->setSyncMode( true ); 1202 getEventViewerDialog()->setSyncMode( true );
1188 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1203 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1189 getEventViewerDialog()->setSyncMode( false ); 1204 getEventViewerDialog()->setSyncMode( false );
1190 if ( syncOK ) { 1205 if ( syncOK ) {
1191 if ( KOPrefs::instance()->mWriteBackFile ) 1206 if ( KOPrefs::instance()->mWriteBackFile )
1192 { 1207 {
1193 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1208 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1194 storage->save(); 1209 storage->save();
1195 } 1210 }
1196 } 1211 }
1197 setModified( true ); 1212 setModified( true );
1198 } 1213 }
1199 delete storage; 1214 delete storage;
1200 delete calendar; 1215 delete calendar;
1201 if ( syncOK ) 1216 if ( syncOK )
1202 updateView(); 1217 updateView();
1203 return syncOK; 1218 return syncOK;
1204} 1219}
1205void CalendarView::syncPhone() 1220void CalendarView::syncPhone()
1206{ 1221{
1207 syncExternal( 1 ); 1222 syncExternal( 1 );
1208} 1223}
1209void CalendarView::syncExternal( int mode ) 1224void CalendarView::syncExternal( int mode )
1210{ 1225{
1211 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1226 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1212 //mCurrentSyncDevice = "sharp-DTM"; 1227 //mCurrentSyncDevice = "sharp-DTM";
1213 if ( KOPrefs::instance()->mAskForPreferences ) 1228 if ( KOPrefs::instance()->mAskForPreferences )
1214 edit_sync_options(); 1229 edit_sync_options();
1215 qApp->processEvents(); 1230 qApp->processEvents();
1216 CalendarLocal* calendar = new CalendarLocal(); 1231 CalendarLocal* calendar = new CalendarLocal();
1217 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1232 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1218 bool syncOK = false; 1233 bool syncOK = false;
1219 bool loadSuccess = false; 1234 bool loadSuccess = false;
1220 PhoneFormat* phoneFormat = 0; 1235 PhoneFormat* phoneFormat = 0;
1221#ifndef DESKTOP_VERSION 1236#ifndef DESKTOP_VERSION
1222 SharpFormat* sharpFormat = 0; 1237 SharpFormat* sharpFormat = 0;
1223 if ( mode == 0 ) { // sharp 1238 if ( mode == 0 ) { // sharp
1224 sharpFormat = new SharpFormat () ; 1239 sharpFormat = new SharpFormat () ;
1225 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1240 loadSuccess = sharpFormat->load( calendar, mCalendar );
1226 1241
1227 } else 1242 } else
1228#endif 1243#endif
1229 if ( mode == 1 ) { // phone 1244 if ( mode == 1 ) { // phone
1230 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1245 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1231 KOPrefs::instance()->mPhoneDevice, 1246 KOPrefs::instance()->mPhoneDevice,
1232 KOPrefs::instance()->mPhoneConnection, 1247 KOPrefs::instance()->mPhoneConnection,
1233 KOPrefs::instance()->mPhoneModel); 1248 KOPrefs::instance()->mPhoneModel);
1234 loadSuccess = phoneFormat->load( calendar,mCalendar); 1249 loadSuccess = phoneFormat->load( calendar,mCalendar);
1235 1250
1236 } else 1251 } else
1237 return; 1252 return;
1238 if ( loadSuccess ) { 1253 if ( loadSuccess ) {
1239 getEventViewerDialog()->setSyncMode( true ); 1254 getEventViewerDialog()->setSyncMode( true );
1240 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1255 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1241 getEventViewerDialog()->setSyncMode( false ); 1256 getEventViewerDialog()->setSyncMode( false );
1242 qApp->processEvents(); 1257 qApp->processEvents();
1243 if ( syncOK ) { 1258 if ( syncOK ) {
1244 if ( KOPrefs::instance()->mWriteBackFile ) 1259 if ( KOPrefs::instance()->mWriteBackFile )
1245 { 1260 {
1246 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1261 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1247 Incidence* inc = iL.first(); 1262 Incidence* inc = iL.first();
1248 /* obsolete
1249 while ( inc ) { 1263 while ( inc ) {
1250 inc->setZaurusStat( inc->revision () ); 1264 inc->removeID(mCurrentSyncDevice);
1251 inc = iL.next(); 1265 inc = iL.next();
1252 } 1266 }
1253 */
1254#ifndef DESKTOP_VERSION 1267#ifndef DESKTOP_VERSION
1255 if ( sharpFormat ) 1268 if ( sharpFormat )
1256 sharpFormat->save(calendar); 1269 sharpFormat->save(calendar);
1257#endif 1270#endif
1258 if ( phoneFormat ) 1271 if ( phoneFormat )
1259 phoneFormat->save(calendar); 1272 phoneFormat->save(calendar);
1260 iL = calendar->rawIncidences(); 1273 iL = calendar->rawIncidences();
1261 inc = iL.first(); 1274 inc = iL.first();
1262 Incidence* loc; 1275 Incidence* loc;
1263 while ( inc ) { 1276 while ( inc ) {
1264 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1277 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1265 loc = mCalendar->incidence(inc->uid() ); 1278 loc = mCalendar->incidence(inc->uid() );
1266 if ( loc ) { 1279 if ( loc ) {
1267 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1280 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1268 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1281 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1269 } 1282 }
1270 } 1283 }
1271 inc = iL.next(); 1284 inc = iL.next();
1272 } 1285 }
1273 Incidence* lse = getLastSyncEvent(); 1286 Incidence* lse = getLastSyncEvent();
1274 if ( lse ) { 1287 if ( lse ) {
1275 lse->setReadOnly( false ); 1288 lse->setReadOnly( false );
1276 lse->setDescription( "" ); 1289 lse->setDescription( "" );
1277 lse->setReadOnly( true ); 1290 lse->setReadOnly( true );
1278 } 1291 }
1279 } 1292 }
1280 } 1293 }
1281 setModified( true ); 1294 setModified( true );
1282 } else { 1295 } else {
1283 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1296 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1284 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1297 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1285 question, i18n("Ok")) ; 1298 question, i18n("Ok")) ;
1286 1299
1287 } 1300 }
1288 delete calendar; 1301 delete calendar;
1289 updateView(); 1302 updateView();
1290 return ;//syncOK; 1303 return ;//syncOK;
1291 1304
1292} 1305}
1293void CalendarView::syncSharp() 1306void CalendarView::syncSharp()
1294{ 1307{
1295 syncExternal( 0 ); 1308 syncExternal( 0 );
1296 1309
1297} 1310}
1298 1311
1299 1312
1300#include <kabc/stdaddressbook.h> 1313#include <kabc/stdaddressbook.h>
1301bool CalendarView::importBday() 1314bool CalendarView::importBday()
1302{ 1315{
1303 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1316 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1304 KABC::AddressBook::Iterator it; 1317 KABC::AddressBook::Iterator it;
1305 int count = 0; 1318 int count = 0;
1306 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1319 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1307 ++count; 1320 ++count;
1308 } 1321 }
1309 QProgressBar bar(count,0 ); 1322 QProgressBar bar(count,0 );
1310 int w = 300; 1323 int w = 300;
1311 if ( QApplication::desktop()->width() < 320 ) 1324 if ( QApplication::desktop()->width() < 320 )
1312 w = 220; 1325 w = 220;
1313 int h = bar.sizeHint().height() ; 1326 int h = bar.sizeHint().height() ;
1314 int dw = QApplication::desktop()->width(); 1327 int dw = QApplication::desktop()->width();
1315 int dh = QApplication::desktop()->height(); 1328 int dh = QApplication::desktop()->height();
1316 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1329 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1317 bar.show(); 1330 bar.show();
1318 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1331 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1319 qApp->processEvents(); 1332 qApp->processEvents();
1320 count = 0; 1333 count = 0;
1321 int addCount = 0; 1334 int addCount = 0;
1322 KCal::Attendee* a = 0; 1335 KCal::Attendee* a = 0;
1323 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1336 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1324 if ( ! bar.isVisible() ) 1337 if ( ! bar.isVisible() )
1325 return false; 1338 return false;
1326 bar.setProgress( count++ ); 1339 bar.setProgress( count++ );
1327 qApp->processEvents(); 1340 qApp->processEvents();
1328 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1341 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1329 if ( (*it).birthday().date().isValid() ){ 1342 if ( (*it).birthday().date().isValid() ){
1330 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1343 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1331 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1344 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1332 ++addCount; 1345 ++addCount;
1333 } 1346 }
1334 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1347 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1335 if ( anni.isValid() ){ 1348 if ( anni.isValid() ){
1336 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1349 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1337 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1350 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1338 ++addCount; 1351 ++addCount;
1339 } 1352 }
1340 } 1353 }
1341 updateView(); 1354 updateView();
1342 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1355 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1343 return true; 1356 return true;
1344} 1357}
1345 1358
1346bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1359bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1347{ 1360{
1348 //qDebug("addAnni "); 1361 //qDebug("addAnni ");
1349 Event * ev = new Event(); 1362 Event * ev = new Event();
1350 if ( a ) { 1363 if ( a ) {
1351 ev->addAttendee( a ); 1364 ev->addAttendee( a );
1352 } 1365 }
1353 QString kind; 1366 QString kind;
1354 if ( birthday ) 1367 if ( birthday )
1355 kind = i18n( "Birthday" ); 1368 kind = i18n( "Birthday" );
1356 else 1369 else
1357 kind = i18n( "Anniversary" ); 1370 kind = i18n( "Anniversary" );
1358 ev->setSummary( name + " - " + kind ); 1371 ev->setSummary( name + " - " + kind );
1359 ev->setOrganizer( "nobody@nowhere" ); 1372 ev->setOrganizer( "nobody@nowhere" );
1360 ev->setCategories( kind ); 1373 ev->setCategories( kind );
1361 ev->setDtStart( QDateTime(date) ); 1374 ev->setDtStart( QDateTime(date) );
1362 ev->setDtEnd( QDateTime(date) ); 1375 ev->setDtEnd( QDateTime(date) );
1363 ev->setFloats( true ); 1376 ev->setFloats( true );
1364 Recurrence * rec = ev->recurrence(); 1377 Recurrence * rec = ev->recurrence();
1365 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1378 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1366 rec->addYearlyNum( date.month() ); 1379 rec->addYearlyNum( date.month() );
1367 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1380 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1368 delete ev; 1381 delete ev;
1369 return false; 1382 return false;
1370 } 1383 }
1371 return true; 1384 return true;
1372 1385
1373} 1386}
1374bool CalendarView::importQtopia( const QString &categories, 1387bool CalendarView::importQtopia( const QString &categories,
1375 const QString &datebook, 1388 const QString &datebook,
1376 const QString &todolist ) 1389 const QString &todolist )
1377{ 1390{
1378 1391
1379 QtopiaFormat qtopiaFormat; 1392 QtopiaFormat qtopiaFormat;
1380 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1393 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1381 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1394 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1382 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1395 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1383 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1396 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1384 1397
1385 updateView(); 1398 updateView();
1386 return true; 1399 return true;
1387 1400
1388#if 0 1401#if 0
1389 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1402 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1390 mCurrentSyncDevice = "qtopia-XML"; 1403 mCurrentSyncDevice = "qtopia-XML";
1391 if ( KOPrefs::instance()->mAskForPreferences ) 1404 if ( KOPrefs::instance()->mAskForPreferences )
1392 edit_sync_options(); 1405 edit_sync_options();
1393 qApp->processEvents(); 1406 qApp->processEvents();
1394 CalendarLocal* calendar = new CalendarLocal(); 1407 CalendarLocal* calendar = new CalendarLocal();
1395 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1408 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1396 bool syncOK = false; 1409 bool syncOK = false;
1397 QtopiaFormat qtopiaFormat; 1410 QtopiaFormat qtopiaFormat;
1398 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1411 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1399 bool loadOk = true; 1412 bool loadOk = true;
1400 if ( !categories.isEmpty() ) 1413 if ( !categories.isEmpty() )
1401 loadOk = qtopiaFormat.load( calendar, categories ); 1414 loadOk = qtopiaFormat.load( calendar, categories );
1402 if ( loadOk && !datebook.isEmpty() ) 1415 if ( loadOk && !datebook.isEmpty() )
1403 loadOk = qtopiaFormat.load( calendar, datebook ); 1416 loadOk = qtopiaFormat.load( calendar, datebook );
1404 if ( loadOk && !todolist.isEmpty() ) 1417 if ( loadOk && !todolist.isEmpty() )
1405 loadOk = qtopiaFormat.load( calendar, todolist ); 1418 loadOk = qtopiaFormat.load( calendar, todolist );
1406 1419
1407 if ( loadOk ) { 1420 if ( loadOk ) {
1408 getEventViewerDialog()->setSyncMode( true ); 1421 getEventViewerDialog()->setSyncMode( true );
1409 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1422 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1410 getEventViewerDialog()->setSyncMode( false ); 1423 getEventViewerDialog()->setSyncMode( false );
1411 qApp->processEvents(); 1424 qApp->processEvents();
1412 if ( syncOK ) { 1425 if ( syncOK ) {
1413 if ( KOPrefs::instance()->mWriteBackFile ) 1426 if ( KOPrefs::instance()->mWriteBackFile )
1414 { 1427 {
1415 // write back XML file 1428 // write back XML file
1416 1429
1417 } 1430 }
1418 setModified( true ); 1431 setModified( true );
1419 } 1432 }
1420 } else { 1433 } else {
1421 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1434 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1422 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1435 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1423 question, i18n("Ok")) ; 1436 question, i18n("Ok")) ;
1424 } 1437 }
1425 delete calendar; 1438 delete calendar;
1426 updateView(); 1439 updateView();
1427 return syncOK; 1440 return syncOK;
1428 1441
1429 1442
1430#endif 1443#endif
1431 1444
1432} 1445}
1433 1446
1434void CalendarView::setSyncEventsReadOnly() 1447void CalendarView::setSyncEventsReadOnly()
1435{ 1448{
1436 Event * ev; 1449 Event * ev;
1437 QPtrList<Event> eL = mCalendar->rawEvents(); 1450 QPtrList<Event> eL = mCalendar->rawEvents();
1438 ev = eL.first(); 1451 ev = eL.first();
1439 while ( ev ) { 1452 while ( ev ) {
1440 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1453 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1441 ev->setReadOnly( true ); 1454 ev->setReadOnly( true );
1442 ev = eL.next(); 1455 ev = eL.next();
1443 } 1456 }
1444} 1457}
1445bool CalendarView::openCalendar(QString filename, bool merge) 1458bool CalendarView::openCalendar(QString filename, bool merge)
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 07812c2..29e6205 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -111,297 +111,313 @@ void Alarm::setType(Alarm::Type type)
111 case Invalid: 111 case Invalid:
112 break; 112 break;
113 default: 113 default:
114 return; 114 return;
115 } 115 }
116 mType = type; 116 mType = type;
117 mParent->updated(); 117 mParent->updated();
118} 118}
119 119
120Alarm::Type Alarm::type() const 120Alarm::Type Alarm::type() const
121{ 121{
122 return mType; 122 return mType;
123} 123}
124 124
125void Alarm::setAudioAlarm(const QString &audioFile) 125void Alarm::setAudioAlarm(const QString &audioFile)
126{ 126{
127 mType = Audio; 127 mType = Audio;
128 mFile = audioFile; 128 mFile = audioFile;
129 mParent->updated(); 129 mParent->updated();
130} 130}
131 131
132void Alarm::setAudioFile(const QString &audioFile) 132void Alarm::setAudioFile(const QString &audioFile)
133{ 133{
134 if (mType == Audio) { 134 if (mType == Audio) {
135 mFile = audioFile; 135 mFile = audioFile;
136 mParent->updated(); 136 mParent->updated();
137 } 137 }
138} 138}
139 139
140QString Alarm::audioFile() const 140QString Alarm::audioFile() const
141{ 141{
142 return (mType == Audio) ? mFile : QString::null; 142 return (mType == Audio) ? mFile : QString::null;
143} 143}
144 144
145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) 145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments)
146{ 146{
147 mType = Procedure; 147 mType = Procedure;
148 mFile = programFile; 148 mFile = programFile;
149 mDescription = arguments; 149 mDescription = arguments;
150 mParent->updated(); 150 mParent->updated();
151} 151}
152 152
153void Alarm::setProgramFile(const QString &programFile) 153void Alarm::setProgramFile(const QString &programFile)
154{ 154{
155 if (mType == Procedure) { 155 if (mType == Procedure) {
156 mFile = programFile; 156 mFile = programFile;
157 mParent->updated(); 157 mParent->updated();
158 } 158 }
159} 159}
160 160
161QString Alarm::programFile() const 161QString Alarm::programFile() const
162{ 162{
163 return (mType == Procedure) ? mFile : QString::null; 163 return (mType == Procedure) ? mFile : QString::null;
164} 164}
165 165
166void Alarm::setProgramArguments(const QString &arguments) 166void Alarm::setProgramArguments(const QString &arguments)
167{ 167{
168 if (mType == Procedure) { 168 if (mType == Procedure) {
169 mDescription = arguments; 169 mDescription = arguments;
170 mParent->updated(); 170 mParent->updated();
171 } 171 }
172} 172}
173 173
174QString Alarm::programArguments() const 174QString Alarm::programArguments() const
175{ 175{
176 return (mType == Procedure) ? mDescription : QString::null; 176 return (mType == Procedure) ? mDescription : QString::null;
177} 177}
178 178
179void Alarm::setEmailAlarm(const QString &subject, const QString &text, 179void Alarm::setEmailAlarm(const QString &subject, const QString &text,
180 const QValueList<Person> &addressees, const QStringList &attachments) 180 const QValueList<Person> &addressees, const QStringList &attachments)
181{ 181{
182 mType = Email; 182 mType = Email;
183 mMailSubject = subject; 183 mMailSubject = subject;
184 mDescription = text; 184 mDescription = text;
185 mMailAddresses = addressees; 185 mMailAddresses = addressees;
186 mMailAttachFiles = attachments; 186 mMailAttachFiles = attachments;
187 mParent->updated(); 187 mParent->updated();
188} 188}
189 189
190void Alarm::setMailAddress(const Person &mailAddress) 190void Alarm::setMailAddress(const Person &mailAddress)
191{ 191{
192 if (mType == Email) { 192 if (mType == Email) {
193 mMailAddresses.clear(); 193 mMailAddresses.clear();
194 mMailAddresses += mailAddress; 194 mMailAddresses += mailAddress;
195 mParent->updated(); 195 mParent->updated();
196 } 196 }
197} 197}
198 198
199void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) 199void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses)
200{ 200{
201 if (mType == Email) { 201 if (mType == Email) {
202 mMailAddresses = mailAddresses; 202 mMailAddresses = mailAddresses;
203 mParent->updated(); 203 mParent->updated();
204 } 204 }
205} 205}
206 206
207void Alarm::addMailAddress(const Person &mailAddress) 207void Alarm::addMailAddress(const Person &mailAddress)
208{ 208{
209 if (mType == Email) { 209 if (mType == Email) {
210 mMailAddresses += mailAddress; 210 mMailAddresses += mailAddress;
211 mParent->updated(); 211 mParent->updated();
212 } 212 }
213} 213}
214 214
215QValueList<Person> Alarm::mailAddresses() const 215QValueList<Person> Alarm::mailAddresses() const
216{ 216{
217 return (mType == Email) ? mMailAddresses : QValueList<Person>(); 217 return (mType == Email) ? mMailAddresses : QValueList<Person>();
218} 218}
219 219
220void Alarm::setMailSubject(const QString &mailAlarmSubject) 220void Alarm::setMailSubject(const QString &mailAlarmSubject)
221{ 221{
222 if (mType == Email) { 222 if (mType == Email) {
223 mMailSubject = mailAlarmSubject; 223 mMailSubject = mailAlarmSubject;
224 mParent->updated(); 224 mParent->updated();
225 } 225 }
226} 226}
227 227
228QString Alarm::mailSubject() const 228QString Alarm::mailSubject() const
229{ 229{
230 return (mType == Email) ? mMailSubject : QString::null; 230 return (mType == Email) ? mMailSubject : QString::null;
231} 231}
232 232
233void Alarm::setMailAttachment(const QString &mailAttachFile) 233void Alarm::setMailAttachment(const QString &mailAttachFile)
234{ 234{
235 if (mType == Email) { 235 if (mType == Email) {
236 mMailAttachFiles.clear(); 236 mMailAttachFiles.clear();
237 mMailAttachFiles += mailAttachFile; 237 mMailAttachFiles += mailAttachFile;
238 mParent->updated(); 238 mParent->updated();
239 } 239 }
240} 240}
241 241
242void Alarm::setMailAttachments(const QStringList &mailAttachFiles) 242void Alarm::setMailAttachments(const QStringList &mailAttachFiles)
243{ 243{
244 if (mType == Email) { 244 if (mType == Email) {
245 mMailAttachFiles = mailAttachFiles; 245 mMailAttachFiles = mailAttachFiles;
246 mParent->updated(); 246 mParent->updated();
247 } 247 }
248} 248}
249 249
250void Alarm::addMailAttachment(const QString &mailAttachFile) 250void Alarm::addMailAttachment(const QString &mailAttachFile)
251{ 251{
252 if (mType == Email) { 252 if (mType == Email) {
253 mMailAttachFiles += mailAttachFile; 253 mMailAttachFiles += mailAttachFile;
254 mParent->updated(); 254 mParent->updated();
255 } 255 }
256} 256}
257 257
258QStringList Alarm::mailAttachments() const 258QStringList Alarm::mailAttachments() const
259{ 259{
260 return (mType == Email) ? mMailAttachFiles : QStringList(); 260 return (mType == Email) ? mMailAttachFiles : QStringList();
261} 261}
262 262
263void Alarm::setMailText(const QString &text) 263void Alarm::setMailText(const QString &text)
264{ 264{
265 if (mType == Email) { 265 if (mType == Email) {
266 mDescription = text; 266 mDescription = text;
267 mParent->updated(); 267 mParent->updated();
268 } 268 }
269} 269}
270 270
271QString Alarm::mailText() const 271QString Alarm::mailText() const
272{ 272{
273 return (mType == Email) ? mDescription : QString::null; 273 return (mType == Email) ? mDescription : QString::null;
274} 274}
275 275
276void Alarm::setDisplayAlarm(const QString &text) 276void Alarm::setDisplayAlarm(const QString &text)
277{ 277{
278 mType = Display; 278 mType = Display;
279 mDescription = text; 279 mDescription = text;
280 mParent->updated(); 280 mParent->updated();
281} 281}
282 282
283void Alarm::setText(const QString &text) 283void Alarm::setText(const QString &text)
284{ 284{
285 if (mType == Display) { 285 if (mType == Display) {
286 mDescription = text; 286 mDescription = text;
287 mParent->updated(); 287 mParent->updated();
288 } 288 }
289} 289}
290 290
291QString Alarm::text() const 291QString Alarm::text() const
292{ 292{
293 return (mType == Display) ? mDescription : QString::null; 293 return (mType == Display) ? mDescription : QString::null;
294} 294}
295 295
296void Alarm::setTime(const QDateTime &alarmTime) 296void Alarm::setTime(const QDateTime &alarmTime)
297{ 297{
298 mAlarmTime = alarmTime; 298 mAlarmTime = alarmTime;
299 mHasTime = true; 299 mHasTime = true;
300 300
301 mParent->updated(); 301 mParent->updated();
302} 302}
303int Alarm::offset()
304{
305 if ( hasTime() ) {
306 if (mParent->type()=="Todo") {
307 Todo *t = static_cast<Todo*>(mParent);
308 return t->dtDue().secsTo( mAlarmTime ) ;
309 } else
310 return mParent->dtStart().secsTo( mAlarmTime ) ;
311 }
312 else
313 {
314 return mOffset.asSeconds();
315 }
316
317}
318
303 319
304QDateTime Alarm::time() const 320QDateTime Alarm::time() const
305{ 321{
306 if ( hasTime() ) 322 if ( hasTime() )
307 return mAlarmTime; 323 return mAlarmTime;
308 else 324 else
309 { 325 {
310 if (mParent->type()=="Todo") { 326 if (mParent->type()=="Todo") {
311 Todo *t = static_cast<Todo*>(mParent); 327 Todo *t = static_cast<Todo*>(mParent);
312 return mOffset.end( t->dtDue() ); 328 return mOffset.end( t->dtDue() );
313 } else if (mEndOffset) { 329 } else if (mEndOffset) {
314 return mOffset.end( mParent->dtEnd() ); 330 return mOffset.end( mParent->dtEnd() );
315 } else { 331 } else {
316 return mOffset.end( mParent->dtStart() ); 332 return mOffset.end( mParent->dtStart() );
317 } 333 }
318 } 334 }
319} 335}
320 336
321bool Alarm::hasTime() const 337bool Alarm::hasTime() const
322{ 338{
323 return mHasTime; 339 return mHasTime;
324} 340}
325 341
326void Alarm::setSnoozeTime(int alarmSnoozeTime) 342void Alarm::setSnoozeTime(int alarmSnoozeTime)
327{ 343{
328 mAlarmSnoozeTime = alarmSnoozeTime; 344 mAlarmSnoozeTime = alarmSnoozeTime;
329 mParent->updated(); 345 mParent->updated();
330} 346}
331 347
332int Alarm::snoozeTime() const 348int Alarm::snoozeTime() const
333{ 349{
334 return mAlarmSnoozeTime; 350 return mAlarmSnoozeTime;
335} 351}
336 352
337void Alarm::setRepeatCount(int alarmRepeatCount) 353void Alarm::setRepeatCount(int alarmRepeatCount)
338{ 354{
339 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; 355 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl;
340 356
341 mAlarmRepeatCount = alarmRepeatCount; 357 mAlarmRepeatCount = alarmRepeatCount;
342 mParent->updated(); 358 mParent->updated();
343} 359}
344 360
345int Alarm::repeatCount() const 361int Alarm::repeatCount() const
346{ 362{
347 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; 363 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl;
348 return mAlarmRepeatCount; 364 return mAlarmRepeatCount;
349} 365}
350 366
351void Alarm::toggleAlarm() 367void Alarm::toggleAlarm()
352{ 368{
353 mAlarmEnabled = !mAlarmEnabled; 369 mAlarmEnabled = !mAlarmEnabled;
354 mParent->updated(); 370 mParent->updated();
355} 371}
356 372
357void Alarm::setEnabled(bool enable) 373void Alarm::setEnabled(bool enable)
358{ 374{
359 mAlarmEnabled = enable; 375 mAlarmEnabled = enable;
360 mParent->updated(); 376 mParent->updated();
361} 377}
362 378
363bool Alarm::enabled() const 379bool Alarm::enabled() const
364{ 380{
365 return mAlarmEnabled; 381 return mAlarmEnabled;
366} 382}
367 383
368void Alarm::setStartOffset( const Duration &offset ) 384void Alarm::setStartOffset( const Duration &offset )
369{ 385{
370 mOffset = offset; 386 mOffset = offset;
371 mEndOffset = false; 387 mEndOffset = false;
372 mHasTime = false; 388 mHasTime = false;
373 mParent->updated(); 389 mParent->updated();
374} 390}
375 391
376Duration Alarm::startOffset() const 392Duration Alarm::startOffset() const
377{ 393{
378 return (mHasTime || mEndOffset) ? 0 : mOffset; 394 return (mHasTime || mEndOffset) ? 0 : mOffset;
379} 395}
380 396
381bool Alarm::hasStartOffset() const 397bool Alarm::hasStartOffset() const
382{ 398{
383 return !mHasTime && !mEndOffset; 399 return !mHasTime && !mEndOffset;
384} 400}
385 401
386bool Alarm::hasEndOffset() const 402bool Alarm::hasEndOffset() const
387{ 403{
388 return !mHasTime && mEndOffset; 404 return !mHasTime && mEndOffset;
389} 405}
390 406
391void Alarm::setEndOffset( const Duration &offset ) 407void Alarm::setEndOffset( const Duration &offset )
392{ 408{
393 mOffset = offset; 409 mOffset = offset;
394 mEndOffset = true; 410 mEndOffset = true;
395 mHasTime = false; 411 mHasTime = false;
396 mParent->updated(); 412 mParent->updated();
397} 413}
398 414
399Duration Alarm::endOffset() const 415Duration Alarm::endOffset() const
400{ 416{
401 return (mHasTime || !mEndOffset) ? 0 : mOffset; 417 return (mHasTime || !mEndOffset) ? 0 : mOffset;
402} 418}
403 419
404void Alarm::setParent( Incidence *parent ) 420void Alarm::setParent( Incidence *parent )
405{ 421{
406 mParent = parent; 422 mParent = parent;
407} 423}
diff --git a/libkcal/alarm.h b/libkcal/alarm.h
index ae2eca3..682b626 100644
--- a/libkcal/alarm.h
+++ b/libkcal/alarm.h
@@ -1,245 +1,245 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#ifndef KCAL_ALARM_H 21#ifndef KCAL_ALARM_H
22#define KCAL_ALARM_H 22#define KCAL_ALARM_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qvaluelist.h> 25#include <qvaluelist.h>
26 26
27#include "customproperties.h" 27#include "customproperties.h"
28#include "duration.h" 28#include "duration.h"
29#include "person.h" 29#include "person.h"
30 30
31namespace KCal { 31namespace KCal {
32 32
33class Incidence; 33class Incidence;
34 34
35/** 35/**
36 This class represents an alarm notification. 36 This class represents an alarm notification.
37*/ 37*/
38class Alarm : public CustomProperties 38class Alarm : public CustomProperties
39{ 39{
40 public: 40 public:
41 enum Type { Invalid, Display, Procedure, Email, Audio }; 41 enum Type { Invalid, Display, Procedure, Email, Audio };
42 typedef QValueList<Alarm *> List; 42 typedef QValueList<Alarm *> List;
43 43
44 /** Construct a new alarm with variables initialized to "sane" values. */ 44 /** Construct a new alarm with variables initialized to "sane" values. */
45 explicit Alarm(Incidence *parent); 45 explicit Alarm(Incidence *parent);
46 /** Destruct Alarm object. */ 46 /** Destruct Alarm object. */
47 ~Alarm(); 47 ~Alarm();
48 48
49 /** Compare this alarm with another one. */ 49 /** Compare this alarm with another one. */
50 bool operator==(const Alarm &) const; 50 bool operator==(const Alarm &) const;
51 bool operator!=(const Alarm &a) const { return !operator==(a); } 51 bool operator!=(const Alarm &a) const { return !operator==(a); }
52 52
53 /** Set the type of the alarm. 53 /** Set the type of the alarm.
54 If the specified type is different from the current type of the alarm, 54 If the specified type is different from the current type of the alarm,
55 the alarm's type-specific properties are initialised to null. 55 the alarm's type-specific properties are initialised to null.
56 @param type type of alarm. 56 @param type type of alarm.
57 */ 57 */
58 void setType(Type type); 58 void setType(Type type);
59 /** Return the type of the alarm */ 59 /** Return the type of the alarm */
60 Type type() const; 60 Type type() const;
61 61 int offset();
62 /** Set the alarm to be a display alarm. 62 /** Set the alarm to be a display alarm.
63 @param text text to display when the alarm is triggered. 63 @param text text to display when the alarm is triggered.
64 */ 64 */
65 void setDisplayAlarm(const QString &text); 65 void setDisplayAlarm(const QString &text);
66 /** Set the text to be displayed when the alarm is triggered. 66 /** Set the text to be displayed when the alarm is triggered.
67 Ignored if the alarm is not a display alarm. 67 Ignored if the alarm is not a display alarm.
68 */ 68 */
69 void setText(const QString &text); 69 void setText(const QString &text);
70 /** Return the text string that displays when the alarm is triggered. */ 70 /** Return the text string that displays when the alarm is triggered. */
71 QString text() const; 71 QString text() const;
72 72
73 /** Set the alarm to be an audio alarm. 73 /** Set the alarm to be an audio alarm.
74 @param audioFile optional file to play when the alarm is triggered. 74 @param audioFile optional file to play when the alarm is triggered.
75 */ 75 */
76 void setAudioAlarm(const QString &audioFile = QString::null); 76 void setAudioAlarm(const QString &audioFile = QString::null);
77 /** Set the file to play when the audio alarm is triggered. 77 /** Set the file to play when the audio alarm is triggered.
78 Ignored if the alarm is not an audio alarm. 78 Ignored if the alarm is not an audio alarm.
79 */ 79 */
80 void setAudioFile(const QString &audioFile); 80 void setAudioFile(const QString &audioFile);
81 /** Return the name of the audio file for the alarm. 81 /** Return the name of the audio file for the alarm.
82 @return The audio file for the alarm, or QString::null if not an audio alarm. 82 @return The audio file for the alarm, or QString::null if not an audio alarm.
83 */ 83 */
84 QString audioFile() const; 84 QString audioFile() const;
85 85
86 /** Set the alarm to be a procedure alarm. 86 /** Set the alarm to be a procedure alarm.
87 @param programFile program to execute when the alarm is triggered. 87 @param programFile program to execute when the alarm is triggered.
88 @param arguments arguments to supply to programFile. 88 @param arguments arguments to supply to programFile.
89 */ 89 */
90 void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null); 90 void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null);
91 /** Set the program file to execute when the alarm is triggered. 91 /** Set the program file to execute when the alarm is triggered.
92 Ignored if the alarm is not a procedure alarm. 92 Ignored if the alarm is not a procedure alarm.
93 */ 93 */
94 void setProgramFile(const QString &programFile); 94 void setProgramFile(const QString &programFile);
95 /** Return the name of the program file to execute when the alarm is triggered. 95 /** Return the name of the program file to execute when the alarm is triggered.
96 @return the program file name, or QString::null if not a procedure alarm. 96 @return the program file name, or QString::null if not a procedure alarm.
97 */ 97 */
98 QString programFile() const; 98 QString programFile() const;
99 /** Set the arguments to the program to execute when the alarm is triggered. 99 /** Set the arguments to the program to execute when the alarm is triggered.
100 Ignored if the alarm is not a procedure alarm. 100 Ignored if the alarm is not a procedure alarm.
101 */ 101 */
102 void setProgramArguments(const QString &arguments); 102 void setProgramArguments(const QString &arguments);
103 /** Return the arguments to the program to run when the alarm is triggered. 103 /** Return the arguments to the program to run when the alarm is triggered.
104 @return the program arguments, or QString::null if not a procedure alarm. 104 @return the program arguments, or QString::null if not a procedure alarm.
105 */ 105 */
106 QString programArguments() const; 106 QString programArguments() const;
107 107
108 /** Set the alarm to be an email alarm. 108 /** Set the alarm to be an email alarm.
109 @param subject subject line of email. 109 @param subject subject line of email.
110 @param text body of email. 110 @param text body of email.
111 @param addressees email addresses of recipient(s). 111 @param addressees email addresses of recipient(s).
112 @param attachments optional names of files to attach to the email. 112 @param attachments optional names of files to attach to the email.
113 */ 113 */
114 void setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees, 114 void setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees,
115 const QStringList &attachments = QStringList()); 115 const QStringList &attachments = QStringList());
116 116
117 /** Send mail to this address when the alarm is triggered. 117 /** Send mail to this address when the alarm is triggered.
118 Ignored if the alarm is not an email alarm. 118 Ignored if the alarm is not an email alarm.
119 */ 119 */
120 void setMailAddress(const Person &mailAlarmAddress); 120 void setMailAddress(const Person &mailAlarmAddress);
121 /** Send mail to these addresses when the alarm is triggered. 121 /** Send mail to these addresses when the alarm is triggered.
122 Ignored if the alarm is not an email alarm. 122 Ignored if the alarm is not an email alarm.
123 */ 123 */
124 void setMailAddresses(const QValueList<Person> &mailAlarmAddresses); 124 void setMailAddresses(const QValueList<Person> &mailAlarmAddresses);
125 /** Add this address to the list of addresses to send mail to when the alarm is triggered. 125 /** Add this address to the list of addresses to send mail to when the alarm is triggered.
126 Ignored if the alarm is not an email alarm. 126 Ignored if the alarm is not an email alarm.
127 */ 127 */
128 void addMailAddress(const Person &mailAlarmAddress); 128 void addMailAddress(const Person &mailAlarmAddress);
129 /** return the addresses to send mail to when an alarm goes off */ 129 /** return the addresses to send mail to when an alarm goes off */
130 QValueList<Person> mailAddresses() const; 130 QValueList<Person> mailAddresses() const;
131 131
132 /** Set the subject line of the mail. 132 /** Set the subject line of the mail.
133 Ignored if the alarm is not an email alarm. 133 Ignored if the alarm is not an email alarm.
134 */ 134 */
135 void setMailSubject(const QString &mailAlarmSubject); 135 void setMailSubject(const QString &mailAlarmSubject);
136 /** return the subject line of the mail */ 136 /** return the subject line of the mail */
137 QString mailSubject() const; 137 QString mailSubject() const;
138 138
139 /** Attach this filename to the email. 139 /** Attach this filename to the email.
140 Ignored if the alarm is not an email alarm. 140 Ignored if the alarm is not an email alarm.
141 */ 141 */
142 void setMailAttachment(const QString &mailAttachFile); 142 void setMailAttachment(const QString &mailAttachFile);
143 /** Attach these filenames to the email. 143 /** Attach these filenames to the email.
144 Ignored if the alarm is not an email alarm. 144 Ignored if the alarm is not an email alarm.
145 */ 145 */
146 void setMailAttachments(const QStringList &mailAttachFiles); 146 void setMailAttachments(const QStringList &mailAttachFiles);
147 /** Add this filename to the list of files to attach to the email. 147 /** Add this filename to the list of files to attach to the email.
148 Ignored if the alarm is not an email alarm. 148 Ignored if the alarm is not an email alarm.
149 */ 149 */
150 void addMailAttachment(const QString &mailAttachFile); 150 void addMailAttachment(const QString &mailAttachFile);
151 /** return the filenames to attach to the email */ 151 /** return the filenames to attach to the email */
152 QStringList mailAttachments() const; 152 QStringList mailAttachments() const;
153 153
154 /** Set the email body text. 154 /** Set the email body text.
155 Ignored if the alarm is not an email alarm. 155 Ignored if the alarm is not an email alarm.
156 */ 156 */
157 void setMailText(const QString &text); 157 void setMailText(const QString &text);
158 /** Return the email body text. 158 /** Return the email body text.
159 @return the body text, or QString::null if not an email alarm. 159 @return the body text, or QString::null if not an email alarm.
160 */ 160 */
161 QString mailText() const; 161 QString mailText() const;
162 162
163 /** set the time to trigger an alarm */ 163 /** set the time to trigger an alarm */
164 void setTime(const QDateTime &alarmTime); 164 void setTime(const QDateTime &alarmTime);
165 /** return the date/time when an alarm goes off */ 165 /** return the date/time when an alarm goes off */
166 QDateTime time() const; 166 QDateTime time() const;
167 /** Return true, if the alarm has an explicit date/time. */ 167 /** Return true, if the alarm has an explicit date/time. */
168 bool hasTime() const; 168 bool hasTime() const;
169 169
170 /** Set offset of alarm in time relative to the start of the event. */ 170 /** Set offset of alarm in time relative to the start of the event. */
171 void setStartOffset(const Duration &); 171 void setStartOffset(const Duration &);
172 /** Return offset of alarm in time relative to the start of the event. 172 /** Return offset of alarm in time relative to the start of the event.
173 * If the alarm's time is not defined in terms of an offset relative 173 * If the alarm's time is not defined in terms of an offset relative
174 * to the start of the event, returns zero. 174 * to the start of the event, returns zero.
175 */ 175 */
176 Duration startOffset() const; 176 Duration startOffset() const;
177 /** Return whether the alarm is defined in terms of an offset relative 177 /** Return whether the alarm is defined in terms of an offset relative
178 * to the start of the event. 178 * to the start of the event.
179 */ 179 */
180 bool hasStartOffset() const; 180 bool hasStartOffset() const;
181 181
182 /** Set offset of alarm in time relative to the end of the event. */ 182 /** Set offset of alarm in time relative to the end of the event. */
183 void setEndOffset(const Duration &); 183 void setEndOffset(const Duration &);
184 /** Return offset of alarm in time relative to the end of the event. 184 /** Return offset of alarm in time relative to the end of the event.
185 * If the alarm's time is not defined in terms of an offset relative 185 * If the alarm's time is not defined in terms of an offset relative
186 * to the end of the event, returns zero. 186 * to the end of the event, returns zero.
187 */ 187 */
188 Duration endOffset() const; 188 Duration endOffset() const;
189 /** Return whether the alarm is defined in terms of an offset relative 189 /** Return whether the alarm is defined in terms of an offset relative
190 * to the end of the event. 190 * to the end of the event.
191 */ 191 */
192 bool hasEndOffset() const; 192 bool hasEndOffset() const;
193 193
194 /** Set the interval between snoozes for the alarm. 194 /** Set the interval between snoozes for the alarm.
195 @param snoozeTime the time in minutes between snoozes. 195 @param snoozeTime the time in minutes between snoozes.
196 */ 196 */
197 void setSnoozeTime(int alarmSnoozeTime); 197 void setSnoozeTime(int alarmSnoozeTime);
198 /** Get how long the alarm snooze interval is. 198 /** Get how long the alarm snooze interval is.
199 @return the number of minutes between snoozes. 199 @return the number of minutes between snoozes.
200 */ 200 */
201 int snoozeTime() const; 201 int snoozeTime() const;
202 202
203 /** set how many times an alarm is to repeat itself (w/snoozes) */ 203 /** set how many times an alarm is to repeat itself (w/snoozes) */
204 void setRepeatCount(int alarmRepeatCount); 204 void setRepeatCount(int alarmRepeatCount);
205 /** get how many times an alarm repeats */ 205 /** get how many times an alarm repeats */
206 int repeatCount() const; 206 int repeatCount() const;
207 207
208 /** toggles the value of alarm to be either on or off. 208 /** toggles the value of alarm to be either on or off.
209 set's the alarm time to be x minutes before dtStart time. */ 209 set's the alarm time to be x minutes before dtStart time. */
210 void toggleAlarm(); 210 void toggleAlarm();
211 211
212 /** set the alarm enabled status */ 212 /** set the alarm enabled status */
213 void setEnabled(bool enable); 213 void setEnabled(bool enable);
214 /** get the alarm enabled status */ 214 /** get the alarm enabled status */
215 bool enabled() const; 215 bool enabled() const;
216 216
217 /** Set the alarm's parent incidence */ 217 /** Set the alarm's parent incidence */
218 void setParent( Incidence * ); 218 void setParent( Incidence * );
219 /** get the alarm's parent incidence */ 219 /** get the alarm's parent incidence */
220 Incidence *parent() const { return mParent; } 220 Incidence *parent() const { return mParent; }
221 221
222 private: 222 private:
223 Incidence *mParent; // the incidence which this alarm belongs to 223 Incidence *mParent; // the incidence which this alarm belongs to
224 Type mType; // type of alarm 224 Type mType; // type of alarm
225 QString mDescription; // text to display/email body/procedure arguments 225 QString mDescription; // text to display/email body/procedure arguments
226 QString mFile; // procedure program to run/optional audio file to play 226 QString mFile; // procedure program to run/optional audio file to play
227 QStringList mMailAttachFiles; // filenames to attach to email 227 QStringList mMailAttachFiles; // filenames to attach to email
228 QValueList<Person> mMailAddresses; // who to mail for reminder 228 QValueList<Person> mMailAddresses; // who to mail for reminder
229 QString mMailSubject; // subject of email 229 QString mMailSubject; // subject of email
230 230
231 int mAlarmSnoozeTime; // number of minutes after alarm to 231 int mAlarmSnoozeTime; // number of minutes after alarm to
232 // snooze before ringing again 232 // snooze before ringing again
233 int mAlarmRepeatCount; // number of times for alarm to repeat 233 int mAlarmRepeatCount; // number of times for alarm to repeat
234 // after the initial time 234 // after the initial time
235 235
236 QDateTime mAlarmTime; // time at which to trigger the alarm 236 QDateTime mAlarmTime; // time at which to trigger the alarm
237 Duration mOffset; // time relative to incidence DTSTART to trigger the alarm 237 Duration mOffset; // time relative to incidence DTSTART to trigger the alarm
238 bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART 238 bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART
239 bool mHasTime; // use mAlarmTime, not mOffset 239 bool mHasTime; // use mAlarmTime, not mOffset
240 bool mAlarmEnabled; 240 bool mAlarmEnabled;
241}; 241};
242 242
243} 243}
244 244
245#endif 245#endif
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 6d0da5c..178a63e 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,637 +1,635 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> 4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38#include <kmessagebox.h> 38#include <kmessagebox.h>
39 39
40#include "calendar.h" 40#include "calendar.h"
41#include "alarm.h" 41#include "alarm.h"
42#include "recurrence.h" 42#include "recurrence.h"
43#include "calendarlocal.h" 43#include "calendarlocal.h"
44 44
45#include "phoneformat.h" 45#include "phoneformat.h"
46#include "syncdefines.h" 46#include "syncdefines.h"
47 47
48using namespace KCal; 48using namespace KCal;
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( ) { 52 PhoneParser( ) {
53 ; 53 ;
54 } 54 }
55 55
56 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 56 static QString dtToString( const QDateTime& dti, bool useTZ = false )
57 { 57 {
58 QString datestr; 58 QString datestr;
59 QString timestr; 59 QString timestr;
60 int offset = KGlobal::locale()->localTimeOffset( dti ); 60 int offset = KGlobal::locale()->localTimeOffset( dti );
61 QDateTime dt; 61 QDateTime dt;
62 if (useTZ) 62 if (useTZ)
63 dt = dti.addSecs ( -(offset*60)); 63 dt = dti.addSecs ( -(offset*60));
64 else 64 else
65 dt = dti; 65 dt = dti;
66 if(dt.date().isValid()){ 66 if(dt.date().isValid()){
67 const QDate& date = dt.date(); 67 const QDate& date = dt.date();
68 datestr.sprintf("%04d%02d%02d", 68 datestr.sprintf("%04d%02d%02d",
69 date.year(), date.month(), date.day()); 69 date.year(), date.month(), date.day());
70 } 70 }
71 if(dt.time().isValid()){ 71 if(dt.time().isValid()){
72 const QTime& time = dt.time(); 72 const QTime& time = dt.time();
73 timestr.sprintf("T%02d%02d%02d", 73 timestr.sprintf("T%02d%02d%02d",
74 time.hour(), time.minute(), time.second()); 74 time.hour(), time.minute(), time.second());
75 } 75 }
76 return datestr + timestr; 76 return datestr + timestr;
77 } 77 }
78 78
79 79
80}; 80};
81 81
82 82
83 83
84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 84PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
85{ 85{
86 mProfileName = profileName; 86 mProfileName = profileName;
87 mDevice = device; 87 mDevice = device;
88 mConnection = connection; 88 mConnection = connection;
89 mModel = model; 89 mModel = model;
90} 90}
91 91
92PhoneFormat::~PhoneFormat() 92PhoneFormat::~PhoneFormat()
93{ 93{
94} 94}
95#if 0 95#if 0
96int PhoneFormat::initDevice(GSM_StateMachine *s) 96int PhoneFormat::initDevice(GSM_StateMachine *s)
97{ 97{
98 GSM_ReadConfig(NULL, &s->Config[0], 0); 98 GSM_ReadConfig(NULL, &s->Config[0], 0);
99 s->ConfigNum = 1; 99 s->ConfigNum = 1;
100 GSM_Config *cfg = &s->Config[0]; 100 GSM_Config *cfg = &s->Config[0];
101 if ( ! mConnection.isEmpty() ) { 101 if ( ! mConnection.isEmpty() ) {
102 cfg->Connection = strdup(mConnection.latin1()); 102 cfg->Connection = strdup(mConnection.latin1());
103 cfg->DefaultConnection = false; 103 cfg->DefaultConnection = false;
104 qDebug("Connection set %s ", cfg->Connection ); 104 qDebug("Connection set %s ", cfg->Connection );
105 105
106 } 106 }
107 if ( ! mDevice.isEmpty() ) { 107 if ( ! mDevice.isEmpty() ) {
108 cfg->Device = strdup(mDevice.latin1()); 108 cfg->Device = strdup(mDevice.latin1());
109 cfg->DefaultDevice = false; 109 cfg->DefaultDevice = false;
110 qDebug("Device set %s ", cfg->Device); 110 qDebug("Device set %s ", cfg->Device);
111 111
112 } 112 }
113 if ( ! mModel.isEmpty() ) { 113 if ( ! mModel.isEmpty() ) {
114 strcpy(cfg->Model,mModel.latin1() ); 114 strcpy(cfg->Model,mModel.latin1() );
115 cfg->DefaultModel = false; 115 cfg->DefaultModel = false;
116 qDebug("Model set %s ",cfg->Model ); 116 qDebug("Model set %s ",cfg->Model );
117 } 117 }
118 int error=GSM_InitConnection(s,3); 118 int error=GSM_InitConnection(s,3);
119 return error; 119 return error;
120} 120}
121#endif 121#endif
122ulong PhoneFormat::getCsumTodo( Todo* todo ) 122ulong PhoneFormat::getCsumTodo( Todo* todo )
123{ 123{
124 QStringList attList; 124 QStringList attList;
125 if ( todo->hasDueDate() ) 125 if ( todo->hasDueDate() )
126 attList << PhoneParser::dtToString ( todo->dtDue() ); 126 attList << PhoneParser::dtToString ( todo->dtDue() );
127 attList << todo->summary(); 127 attList << todo->summary();
128 QString completedString = "no"; 128 QString completedString = "no";
129 if ( todo->isCompleted() ) 129 if ( todo->isCompleted() )
130 completedString = "yes"; 130 completedString = "yes";
131 attList << completedString; 131 attList << completedString;
132 int prio = todo->priority(); 132 int prio = todo->priority();
133 if( prio == 2 ) prio = 1; 133 if( prio == 2 ) prio = 1;
134 if (prio == 4 ) prio = 5 ; 134 if (prio == 4 ) prio = 5 ;
135 attList << QString::number( prio ); 135 attList << QString::number( prio );
136 QString alarmString = "na"; 136 QString alarmString = "na";
137 Alarm *alarm; 137 Alarm *alarm;
138 if ( todo->alarms().count() > 0 ) { 138 if ( todo->alarms().count() > 0 ) {
139 alarm = todo->alarms().first(); 139 alarm = todo->alarms().first();
140 if ( alarm->enabled() ) { 140 if ( alarm->enabled() ) {
141 alarmString = QString::number(alarm->startOffset().asSeconds() ); 141 alarmString = QString::number(alarm->offset() );
142 } 142 }
143 } 143 }
144 attList << alarmString; 144 attList << alarmString;
145 attList << todo->categoriesStr(); 145 attList << todo->categoriesStr();
146 attList << todo->secrecyStr(); 146 attList << todo->secrecyStr();
147 return PhoneFormat::getCsum(attList ); 147 return PhoneFormat::getCsum(attList );
148 148
149} 149}
150ulong PhoneFormat::getCsumEvent( Event* event ) 150ulong PhoneFormat::getCsumEvent( Event* event )
151{ 151{
152 QStringList attList; 152 QStringList attList;
153 attList << PhoneParser::dtToString ( event->dtStart() ); 153 attList << PhoneParser::dtToString ( event->dtStart() );
154 attList << PhoneParser::dtToString ( event->dtEnd() ); 154 attList << PhoneParser::dtToString ( event->dtEnd() );
155 attList << event->summary(); 155 attList << event->summary();
156 attList << event->location(); 156 attList << event->location();
157 QString alarmString = "na"; 157 QString alarmString = "na";
158 Alarm *alarm; 158 Alarm *alarm;
159 if ( event->alarms().count() > 0 ) { 159 if ( event->alarms().count() > 0 ) {
160 alarm = event->alarms().first(); 160 alarm = event->alarms().first();
161 if ( alarm->enabled() ) { 161 if ( alarm->enabled() ) {
162 alarmString = QString::number( alarm->startOffset().asSeconds() ); 162 alarmString = QString::number( alarm->offset() );
163 } 163 }
164 } 164 }
165 attList << alarmString; 165 attList << alarmString;
166 Recurrence* rec = event->recurrence(); 166 Recurrence* rec = event->recurrence();
167 QStringList list; 167 QStringList list;
168 bool writeEndDate = false; 168 bool writeEndDate = false;
169 switch ( rec->doesRecur() ) 169 switch ( rec->doesRecur() )
170 { 170 {
171 case Recurrence::rDaily: // 0 171 case Recurrence::rDaily: // 0
172 list.append( "0" ); 172 list.append( "0" );
173 list.append( QString::number( rec->frequency() ));//12 173 list.append( QString::number( rec->frequency() ));//12
174 list.append( "0" ); 174 list.append( "0" );
175 list.append( "0" ); 175 list.append( "0" );
176 writeEndDate = true; 176 writeEndDate = true;
177 break; 177 break;
178 case Recurrence::rWeekly:// 1 178 case Recurrence::rWeekly:// 1
179 list.append( "1" ); 179 list.append( "1" );
180 list.append( QString::number( rec->frequency()) );//12 180 list.append( QString::number( rec->frequency()) );//12
181 list.append( "0" ); 181 list.append( "0" );
182 { 182 {
183 int days = 0; 183 int days = 0;
184 QBitArray weekDays = rec->days(); 184 QBitArray weekDays = rec->days();
185 int i; 185 int i;
186 for( i = 1; i <= 7; ++i ) { 186 for( i = 1; i <= 7; ++i ) {
187 if ( weekDays[i-1] ) { 187 if ( weekDays[i-1] ) {
188 days += 1 << (i-1); 188 days += 1 << (i-1);
189 } 189 }
190 } 190 }
191 list.append( QString::number( days ) ); 191 list.append( QString::number( days ) );
192 } 192 }
193 //pending weekdays 193 //pending weekdays
194 writeEndDate = true; 194 writeEndDate = true;
195 195
196 break; 196 break;
197 case Recurrence::rMonthlyPos:// 2 197 case Recurrence::rMonthlyPos:// 2
198 list.append( "2" ); 198 list.append( "2" );
199 list.append( QString::number( rec->frequency()) );//12 199 list.append( QString::number( rec->frequency()) );//12
200 200
201 writeEndDate = true; 201 writeEndDate = true;
202 { 202 {
203 int count = 1; 203 int count = 1;
204 QPtrList<Recurrence::rMonthPos> rmp; 204 QPtrList<Recurrence::rMonthPos> rmp;
205 rmp = rec->monthPositions(); 205 rmp = rec->monthPositions();
206 if ( rmp.first()->negative ) 206 if ( rmp.first()->negative )
207 count = 5 - rmp.first()->rPos - 1; 207 count = 5 - rmp.first()->rPos - 1;
208 else 208 else
209 count = rmp.first()->rPos - 1; 209 count = rmp.first()->rPos - 1;
210 list.append( QString::number( count ) ); 210 list.append( QString::number( count ) );
211 211
212 } 212 }
213 213
214 list.append( "0" ); 214 list.append( "0" );
215 break; 215 break;
216 case Recurrence::rMonthlyDay:// 3 216 case Recurrence::rMonthlyDay:// 3
217 list.append( "3" ); 217 list.append( "3" );
218 list.append( QString::number( rec->frequency()) );//12 218 list.append( QString::number( rec->frequency()) );//12
219 list.append( "0" ); 219 list.append( "0" );
220 list.append( "0" ); 220 list.append( "0" );
221 writeEndDate = true; 221 writeEndDate = true;
222 break; 222 break;
223 case Recurrence::rYearlyMonth://4 223 case Recurrence::rYearlyMonth://4
224 list.append( "4" ); 224 list.append( "4" );
225 list.append( QString::number( rec->frequency()) );//12 225 list.append( QString::number( rec->frequency()) );//12
226 list.append( "0" ); 226 list.append( "0" );
227 list.append( "0" ); 227 list.append( "0" );
228 writeEndDate = true; 228 writeEndDate = true;
229 break; 229 break;
230 230
231 default: 231 default:
232 list.append( "255" ); 232 list.append( "255" );
233 list.append( QString() ); 233 list.append( QString() );
234 list.append( "0" ); 234 list.append( "0" );
235 list.append( QString() ); 235 list.append( QString() );
236 list.append( "0" ); 236 list.append( "0" );
237 list.append( "20991231T000000" ); 237 list.append( "20991231T000000" );
238 break; 238 break;
239 } 239 }
240 if ( writeEndDate ) { 240 if ( writeEndDate ) {
241 241
242 if ( rec->endDate().isValid() ) { // 15 + 16 242 if ( rec->endDate().isValid() ) { // 15 + 16
243 list.append( "1" ); 243 list.append( "1" );
244 list.append( PhoneParser::dtToString( rec->endDate()) ); 244 list.append( PhoneParser::dtToString( rec->endDate()) );
245 } else { 245 } else {
246 list.append( "0" ); 246 list.append( "0" );
247 list.append( "20991231T000000" ); 247 list.append( "20991231T000000" );
248 } 248 }
249 249
250 } 250 }
251 attList << list.join(""); 251 attList << list.join("");
252 attList << event->categoriesStr(); 252 attList << event->categoriesStr();
253 //qDebug("csum cat %s", event->categoriesStr().latin1()); 253 //qDebug("csum cat %s", event->categoriesStr().latin1());
254 254
255 attList << event->secrecyStr(); 255 attList << event->secrecyStr();
256 return PhoneFormat::getCsum(attList ); 256 return PhoneFormat::getCsum(attList );
257} 257}
258ulong PhoneFormat::getCsum( const QStringList & attList) 258ulong PhoneFormat::getCsum( const QStringList & attList)
259{ 259{
260 int max = attList.count(); 260 int max = attList.count();
261 ulong cSum = 0; 261 ulong cSum = 0;
262 int j,k,i; 262 int j,k,i;
263 int add; 263 int add;
264 for ( i = 0; i < max ; ++i ) { 264 for ( i = 0; i < max ; ++i ) {
265 QString s = attList[i]; 265 QString s = attList[i];
266 if ( ! s.isEmpty() ){ 266 if ( ! s.isEmpty() ){
267 j = s.length(); 267 j = s.length();
268 for ( k = 0; k < j; ++k ) { 268 for ( k = 0; k < j; ++k ) {
269 int mul = k +1; 269 int mul = k +1;
270 add = s[k].unicode (); 270 add = s[k].unicode ();
271 if ( k < 16 ) 271 if ( k < 16 )
272 mul = mul * mul; 272 mul = mul * mul;
273 int ii = i+1; 273 int ii = i+1;
274 add = add * mul *ii*ii*ii; 274 add = add * mul *ii*ii*ii;
275 cSum += add; 275 cSum += add;
276 } 276 }
277 } 277 }
278 278
279 } 279 }
280 QString dump = attList.join(","); 280 //QString dump = attList.join(",");
281 qDebug("csum: %d %s", cSum,dump.latin1()); 281 //qDebug("csum: %d %s", cSum,dump.latin1());
282 282
283 return cSum; 283 return cSum;
284 284
285} 285}
286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
287#include <stdlib.h> 287#include <stdlib.h>
288#define DEBUGMODE false 288#define DEBUGMODE false
289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
290{ 290{
291 291
292 QString fileName; 292 QString fileName;
293#ifdef _WIN32_ 293#ifdef _WIN32_
294 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 294 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
295#else 295#else
296 fileName = "/tmp/kdepimtemp.vcs"; 296 fileName = "/tmp/kdepimtemp.vcs";
297#endif 297#endif
298 QString command ="./kammu --backup " + fileName + " -yes" ; 298 QString command ="./kammu --backup " + fileName + " -yes" ;
299 int ret = system ( command.latin1() ); 299 int ret = system ( command.latin1() );
300 if ( ret != 0 ) { 300 if ( ret != 0 ) {
301 qDebug("Error::command returned %d", ret); 301 qDebug("Error::command returned %d", ret);
302 return false; 302 return false;
303 } 303 }
304 qDebug("Command returned %d", ret);
305 VCalFormat vfload; 304 VCalFormat vfload;
306 vfload.setLocalTime ( true ); 305 vfload.setLocalTime ( true );
307 qDebug("loading file ..."); 306 qDebug("loading file ...");
308 307
309 if ( ! vfload.load( calendar, fileName ) ) 308 if ( ! vfload.load( calendar, fileName ) )
310 return false; 309 return false;
311 QPtrList<Event> er = calendar->rawEvents(); 310 QPtrList<Event> er = calendar->rawEvents();
312 Event* ev = er.first(); 311 Event* ev = er.first();
313 qDebug("reading events... "); 312 qDebug("reading events... ");
314 while ( ev ) { 313 while ( ev ) {
315 QStringList cat = ev->categories(); 314 QStringList cat = ev->categories();
316 if ( cat.contains( "MeetingDEF" )) { 315 if ( cat.contains( "MeetingDEF" )) {
317 ev->setCategories( QStringList() ); 316 ev->setCategories( QStringList() );
318 } 317 }
319 int id = ev->pilotId(); 318 int id = ev->pilotId();
320 Event *event; 319 Event *event;
321 event = existingCal->event( mProfileName ,QString::number( id ) ); 320 event = existingCal->event( mProfileName ,QString::number( id ) );
322 if ( event ) { 321 if ( event ) {
323 event = (Event*)event->clone(); 322 event = (Event*)event->clone();
324 copyEvent( event, ev ); 323 copyEvent( event, ev );
325 calendar->deleteEvent( ev ); 324 calendar->deleteEvent( ev );
326 calendar->addEvent( event); 325 calendar->addEvent( event);
327 } 326 }
328 else 327 else
329 event = ev; 328 event = ev;
330 uint cSum; 329 uint cSum;
331 cSum = PhoneFormat::getCsumEvent( event ); 330 cSum = PhoneFormat::getCsumEvent( event );
332 event->setCsum( mProfileName, QString::number( cSum )); 331 event->setCsum( mProfileName, QString::number( cSum ));
333 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 332 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
334 event->setID( mProfileName,QString::number( id ) ); 333 event->setID( mProfileName,QString::number( id ) );
335 ev = er.next(); 334 ev = er.next();
336 } 335 }
337 { 336 {
338 qDebug("reading todos... "); 337 qDebug("reading todos... ");
339 QPtrList<Todo> tr = calendar->rawTodos(); 338 QPtrList<Todo> tr = calendar->rawTodos();
340 Todo* ev = tr.first(); 339 Todo* ev = tr.first();
341 while ( ev ) { 340 while ( ev ) {
342 341
343 QStringList cat = ev->categories(); 342 QStringList cat = ev->categories();
344 if ( cat.contains( "MeetingDEF" )) { 343 if ( cat.contains( "MeetingDEF" )) {
345 ev->setCategories( QStringList() ); 344 ev->setCategories( QStringList() );
346 } 345 }
347 int id = ev->pilotId(); 346 int id = ev->pilotId();
348 Todo *event; 347 Todo *event;
349 event = existingCal->todo( mProfileName ,QString::number( id ) ); 348 event = existingCal->todo( mProfileName ,QString::number( id ) );
350 if ( event ) { 349 if ( event ) {
351 qDebug("copy todo %s ", event->summary().latin1()); 350 //qDebug("copy todo %s ", event->summary().latin1());
352 351
353 event = (Todo*)event->clone(); 352 event = (Todo*)event->clone();
354 copyTodo( event, ev ); 353 copyTodo( event, ev );
355 calendar->deleteTodo( ev ); 354 calendar->deleteTodo( ev );
356 calendar->addTodo( event); 355 calendar->addTodo( event);
357 } 356 }
358 else 357 else
359 event = ev; 358 event = ev;
360 uint cSum; 359 uint cSum;
361 cSum = PhoneFormat::getCsumTodo( event ); 360 cSum = PhoneFormat::getCsumTodo( event );
362 event->setCsum( mProfileName, QString::number( cSum )); 361 event->setCsum( mProfileName, QString::number( cSum ));
363 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 362 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
364 event->setID( mProfileName,QString::number( id ) ); 363 event->setID( mProfileName,QString::number( id ) );
365 ev = tr.next(); 364 ev = tr.next();
366 } 365 }
367 } 366 }
368 return true; 367 return true;
369} 368}
370void PhoneFormat::copyEvent( Event* to, Event* from ) 369void PhoneFormat::copyEvent( Event* to, Event* from )
371{ 370{
372 if ( from->dtStart().isValid() ) 371 if ( from->dtStart().isValid() )
373 to->setDtStart( from->dtStart() ); 372 to->setDtStart( from->dtStart() );
374 if ( from->dtEnd().isValid() ) 373 if ( from->dtEnd().isValid() )
375 to->setDtEnd( from->dtEnd() ); 374 to->setDtEnd( from->dtEnd() );
376 if ( !from->location().isEmpty() ) 375 if ( !from->location().isEmpty() )
377 to->setLocation( from->location() ); 376 to->setLocation( from->location() );
378 if ( !from->description().isEmpty() ) 377 if ( !from->description().isEmpty() )
379 to->setDescription( from->description() ); 378 to->setDescription( from->description() );
380 if ( !from->summary().isEmpty() ) 379 if ( !from->summary().isEmpty() )
381 to->setSummary( from->summary() ); 380 to->setSummary( from->summary() );
382 381
383 QPtrListIterator<Alarm> it( from->alarms() ); 382 if ( from->alarms().count() ) {
384 if ( it.current() )
385 to->clearAlarms(); 383 to->clearAlarms();
386 const Alarm *a; 384 Alarm *a = from->alarms().first();
387 while( (a = it.current()) ) { 385 Alarm *b = to->newAlarm( );
388 Alarm *b = new Alarm( *a ); 386 b->setEnabled( a->enabled() );
389 b->setParent( to ); 387 if ( a->hasStartOffset() ) {
390 to->addAlarm( b ); 388 b->setStartOffset( a->startOffset() );
391 ++it; 389 }
390 if ( a->hasTime() )
391 b->setTime( a->time() );
392
392 } 393 }
393 QStringList cat = to->categories(); 394 QStringList cat = to->categories();
394 QStringList catFrom = from->categories(); 395 QStringList catFrom = from->categories();
395 QString nCat; 396 QString nCat;
396 int iii; 397 int iii;
397 for ( iii = 0; iii < catFrom.count();++iii ) { 398 for ( iii = 0; iii < catFrom.count();++iii ) {
398 nCat = catFrom[iii]; 399 nCat = catFrom[iii];
399 if ( !nCat.isEmpty() ) 400 if ( !nCat.isEmpty() )
400 if ( !cat.contains( nCat )) { 401 if ( !cat.contains( nCat )) {
401 cat << nCat; 402 cat << nCat;
402 } 403 }
403 } 404 }
404 to->setCategories( cat ); 405 to->setCategories( cat );
405 Recurrence * r = new Recurrence( *from->recurrence(),to); 406 Recurrence * r = new Recurrence( *from->recurrence(),to);
406 to->setRecurrence( r ) ; 407 to->setRecurrence( r ) ;
407 408
408 409
409} 410}
410void PhoneFormat::copyTodo( Todo* to, Todo* from ) 411void PhoneFormat::copyTodo( Todo* to, Todo* from )
411{ 412{
412 if ( from->dtStart().isValid() ) 413 if ( from->dtStart().isValid() )
413 to->setDtStart( from->dtStart() ); 414 to->setDtStart( from->dtStart() );
414 if ( from->dtDue().isValid() ) 415 if ( from->dtDue().isValid() )
415 to->setDtDue( from->dtDue() ); 416 to->setDtDue( from->dtDue() );
416 if ( !from->location().isEmpty() ) 417 if ( !from->location().isEmpty() )
417 to->setLocation( from->location() ); 418 to->setLocation( from->location() );
418 if ( !from->description().isEmpty() ) 419 if ( !from->description().isEmpty() )
419 to->setDescription( from->description() ); 420 to->setDescription( from->description() );
420 if ( !from->summary().isEmpty() ) 421 if ( !from->summary().isEmpty() )
421 to->setSummary( from->summary() ); 422 to->setSummary( from->summary() );
422 423
423 QPtrListIterator<Alarm> it( from->alarms() ); 424 if ( from->alarms().count() ) {
424 if ( it.current() )
425 to->clearAlarms(); 425 to->clearAlarms();
426 const Alarm *a; 426 Alarm *a = from->alarms().first();
427 while( (a = it.current()) ) { 427 Alarm *b = to->newAlarm( );
428 Alarm *b = new Alarm( *a ); 428 b->setEnabled( a->enabled() );
429 b->setParent( to ); 429 if ( a->hasStartOffset() )
430 to->addAlarm( b ); 430 b->setStartOffset( a->startOffset() );
431 ++it; 431 if ( a->hasTime() )
432 b->setTime( a->time() );
432 } 433 }
434
433 QStringList cat = to->categories(); 435 QStringList cat = to->categories();
434 QStringList catFrom = from->categories(); 436 QStringList catFrom = from->categories();
435 QString nCat; 437 QString nCat;
436 int iii; 438 int iii;
437 for ( iii = 0; iii < catFrom.count();++iii ) { 439 for ( iii = 0; iii < catFrom.count();++iii ) {
438 nCat = catFrom[iii]; 440 nCat = catFrom[iii];
439 if ( !nCat.isEmpty() ) 441 if ( !nCat.isEmpty() )
440 if ( !cat.contains( nCat )) { 442 if ( !cat.contains( nCat )) {
441 cat << nCat; 443 cat << nCat;
442 } 444 }
443 } 445 }
444 to->setCategories( cat ); 446 to->setCategories( cat );
445 if ( from->isCompleted() ) { 447 if ( from->isCompleted() ) {
446 to->setCompleted( true ); 448 to->setCompleted( true );
447 if( from->completed().isValid() ) 449 if( from->completed().isValid() )
448 to->setCompleted( from->completed() ); 450 to->setCompleted( from->completed() );
449 } else { 451 } else {
450 // set percentcomplete only, if to->isCompleted() 452 // set percentcomplete only, if to->isCompleted()
451 if ( to->isCompleted() ) 453 if ( to->isCompleted() )
452 to->setPercentComplete(from->percentComplete()); 454 to->setPercentComplete(from->percentComplete());
453 } 455 }
454 if( to->priority() == 2 && from->priority() == 1 ) 456 if( to->priority() == 2 && from->priority() == 1 )
455 ; //skip 457 ; //skip
456 else if (to->priority() == 4 && from->priority() == 5 ) 458 else if (to->priority() == 4 && from->priority() == 5 )
457 ; 459 ;
458 else 460 else
459 to->setPriority(from->priority()); 461 to->setPriority(from->priority());
460 462
461} 463}
462#include <qcstring.h> 464#include <qcstring.h>
463 465
464void PhoneFormat::afterSave( Incidence* inc) 466void PhoneFormat::afterSave( Incidence* inc)
465{ 467{
466 uint csum; 468 uint csum;
467 inc->removeID( mProfileName ); 469 inc->removeID( mProfileName );
468 if ( inc->type() == "Event") 470 if ( inc->type() == "Event")
469 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 471 csum = PhoneFormat::getCsumEvent( (Event*) inc );
470 else 472 else
471 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 473 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
472 inc->setCsum( mProfileName, QString::number( csum )); 474 inc->setCsum( mProfileName, QString::number( csum ));
473 475
474 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 476 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
475 477
476} 478}
477bool PhoneFormat::save( Calendar *calendar) 479bool PhoneFormat::save( Calendar *calendar)
478{ 480{
479 QLabel status ( i18n(" Opening device ..."), 0 ); 481 QLabel status ( i18n(" Opening device ..."), 0 );
480 int w = status.sizeHint().width()+20 ; 482 int w = status.sizeHint().width()+20 ;
481 if ( w < 200 ) w = 230; 483 if ( w < 200 ) w = 230;
482 int h = status.sizeHint().height()+20 ; 484 int h = status.sizeHint().height()+20 ;
483 int dw = QApplication::desktop()->width(); 485 int dw = QApplication::desktop()->width();
484 int dh = QApplication::desktop()->height(); 486 int dh = QApplication::desktop()->height();
485 status.setCaption(i18n("Writing to phone...") ); 487 status.setCaption(i18n("Writing to phone...") );
486 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 488 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
487 status.show(); 489 status.show();
488 status.raise(); 490 status.raise();
489 qApp->processEvents(); 491 qApp->processEvents();
490 QString message; 492 QString message;
491#ifdef _WIN32_ 493#ifdef _WIN32_
492 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 494 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs";
493#else 495#else
494 QString fileName = "/tmp/kdepimtemp.vcs"; 496 QString fileName = "/tmp/kdepimtemp.vcs";
495#endif 497#endif
496 498
497 // 1 remove events which should be deleted 499 // 1 remove events which should be deleted
498 QPtrList<Event> er = calendar->rawEvents(); 500 QPtrList<Event> er = calendar->rawEvents();
499 Event* ev = er.first(); 501 Event* ev = er.first();
500 while ( ev ) { 502 while ( ev ) {
501 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 503 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
502 calendar->deleteEvent( ev ); 504 calendar->deleteEvent( ev );
503 } else { 505 } else {
504 506
505 } 507 }
506 ev = er.next(); 508 ev = er.next();
507 } 509 }
508 // 2 remove todos which should be deleted 510 // 2 remove todos which should be deleted
509 QPtrList<Todo> tl = calendar->rawTodos(); 511 QPtrList<Todo> tl = calendar->rawTodos();
510 Todo* to = tl.first(); 512 Todo* to = tl.first();
511 while ( to ) { 513 while ( to ) {
512 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 514 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
513 calendar->deleteTodo( to ); 515 calendar->deleteTodo( to );
514 } else { 516 } else {
515 if ( to->isCompleted()) { 517 if ( to->isCompleted()) {
516 calendar->deleteTodo( to ); 518 calendar->deleteTodo( to );
517 } 519 }
518 } 520 }
519 to = tl.next(); 521 to = tl.next();
520 } 522 }
521 // 3 save file 523 // 3 save file
522 VCalFormat vfsave; 524 VCalFormat vfsave;
523 vfsave.setLocalTime ( true ); 525 vfsave.setLocalTime ( true );
524 if ( ! vfsave.save( calendar, fileName ) ) 526 if ( ! vfsave.save( calendar, fileName ) )
525 return false; 527 return false;
526 // 4 call kammu 528 // 4 call kammu
527 QString command ="./kammu --restore " + fileName ; 529 QString command ="./kammu --restore " + fileName ;
528 int ret; 530 int ret;
529 while ( (ret = system ( command.latin1())) != 0 ) { 531 while ( (ret = system ( command.latin1())) != 0 ) {
530 qDebug("Error S::command returned %d. asking users", ret); 532 qDebug("Error S::command returned %d. asking users", ret);
531 int retval = KMessageBox::warningContinueCancel(0, 533 int retval = KMessageBox::warningContinueCancel(0,
532 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); 534 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel"));
533 if ( retval != KMessageBox::Continue ) 535 if ( retval != KMessageBox::Continue )
534 return false; 536 return false;
535 } 537 }
536 if ( ret != 0 ) { 538
537 qDebug("Error S::command returned %d", ret);
538 return false;
539 }
540 // 5 reread data 539 // 5 reread data
541 message = i18n(" Rereading all data ... "); 540 message = i18n(" Rereading all data ... ");
542 status.setText ( message ); 541 status.setText ( message );
543 qApp->processEvents(); 542 qApp->processEvents();
544 CalendarLocal* calendarTemp = new CalendarLocal(); 543 CalendarLocal* calendarTemp = new CalendarLocal();
545 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 544 calendarTemp->setTimeZoneId( calendar->timeZoneId());
546 if ( ! load( calendarTemp,calendar) ){ 545 if ( ! load( calendarTemp,calendar) ){
547 qDebug("error reloading calendar "); 546 qDebug("error reloading calendar ");
548 delete calendarTemp; 547 delete calendarTemp;
549 return false; 548 return false;
550 } 549 }
551 // 6 compare data 550 // 6 compare data
552 551
553//algo 6 compare event 552//algo 6 compare event
554 er = calendar->rawEvents(); 553 er = calendar->rawEvents();
555 ev = er.first(); 554 ev = er.first();
556 message = i18n(" Comparing event # "); 555 message = i18n(" Comparing event # ");
557 QPtrList<Event> er1 = calendarTemp->rawEvents(); 556 QPtrList<Event> er1 = calendarTemp->rawEvents();
558 Event* ev1; 557 Event* ev1;
559 int procCount = 0; 558 int procCount = 0;
560 while ( ev ) { 559 while ( ev ) {
561 //qDebug("event new ID %s",ev->summary().latin1()); 560 //qDebug("event new ID %s",ev->summary().latin1());
562 status.setText ( message + QString::number ( ++procCount ) ); 561 status.setText ( message + QString::number ( ++procCount ) );
563 qApp->processEvents(); 562 qApp->processEvents();
564 uint csum; 563 uint csum;
565 csum = PhoneFormat::getCsumEvent( ev ); 564 csum = PhoneFormat::getCsumEvent( ev );
566 QString cSum = QString::number( csum ); 565 QString cSum = QString::number( csum );
567 //ev->setCsum( mProfileName, cSum ); 566 //ev->setCsum( mProfileName, cSum );
568 //qDebug("Event cSum %s ", cSum.latin1()); 567 //qDebug("Event cSum %s ", cSum.latin1());
569 ev1 = er1.first(); 568 ev1 = er1.first();
570 while ( ev1 ) { 569 while ( ev1 ) {
571 if ( ev1->getCsum( mProfileName ) == cSum ) { 570 if ( ev1->getCsum( mProfileName ) == cSum ) {
572 er1.remove( ev1 ); 571 er1.remove( ev1 );
573 afterSave( ev ); 572 afterSave( ev );
574 ev->setID(mProfileName, ev1->getID(mProfileName) ); 573 ev->setID(mProfileName, ev1->getID(mProfileName) );
575 //qDebug("Event found on phone for %s ", ev->summary().latin1()); 574 //qDebug("Event found on phone for %s ", ev->summary().latin1());
576 575
577 break; 576 break;
578 } 577 }
579 ev1 = er1.next(); 578 ev1 = er1.next();
580 } 579 }
581 if ( ! ev1 ) { 580 if ( ! ev1 ) {
582 ev->removeID(mProfileName); 581 // ev->removeID(mProfileName);
583 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 582 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
584 } 583 }
585 584
586 585
587 ev = er.next(); 586 ev = er.next();
588 } 587 }
589 //algo 6 compare todo 588 //algo 6 compare todo
590 tl = calendar->rawTodos(); 589 tl = calendar->rawTodos();
591 to = tl.first(); 590 to = tl.first();
592 procCount = 0; 591 procCount = 0;
593 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 592 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
594 Todo* to1 ; 593 Todo* to1 ;
595 message = i18n(" Comparing todo # "); 594 message = i18n(" Comparing todo # ");
596 while ( to ) { 595 while ( to ) {
597 qDebug("todo2 %d ", procCount);
598 status.setText ( message + QString::number ( ++procCount ) ); 596 status.setText ( message + QString::number ( ++procCount ) );
599 qApp->processEvents(); 597 qApp->processEvents();
600 uint csum; 598 uint csum;
601 csum = PhoneFormat::getCsumTodo( to ); 599 csum = PhoneFormat::getCsumTodo( to );
602 QString cSum = QString::number( csum ); 600 QString cSum = QString::number( csum );
603 //to->setCsum( mProfileName, cSum ); 601 //to->setCsum( mProfileName, cSum );
604 qDebug("Todo cSum %s ", cSum.latin1()); 602 //qDebug("Todo cSum %s ", cSum.latin1());
605 Todo* to1 = tl1.first(); 603 Todo* to1 = tl1.first();
606 while ( to1 ) { 604 while ( to1 ) {
607 if ( to1->getCsum( mProfileName ) == cSum ) { 605 if ( to1->getCsum( mProfileName ) == cSum ) {
608 tl1.remove( to1 ); 606 tl1.remove( to1 );
609 afterSave( to ); 607 afterSave( to );
610 to->setID(mProfileName, to1->getID(mProfileName) ); 608 to->setID(mProfileName, to1->getID(mProfileName) );
611 break; 609 break;
612 } 610 }
613 to1 = tl1.next(); 611 to1 = tl1.next();
614 } 612 }
615 if ( ! to1 ) { 613 if ( ! to1 ) {
616 to->removeID(mProfileName); 614 //to->removeID(mProfileName);
617 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 615 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
618 } 616 }
619 617
620 to = tl.next(); 618 to = tl.next();
621 } 619 }
622 delete calendarTemp; 620 delete calendarTemp;
623 return true; 621 return true;
624 622
625 623
626 624
627} 625}
628 626
629 627
630QString PhoneFormat::toString( Calendar * ) 628QString PhoneFormat::toString( Calendar * )
631{ 629{
632 return QString::null; 630 return QString::null;
633} 631}
634bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 632bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
635{ 633{
636 return false; 634 return false;
637} 635}