-rw-r--r-- | korganizer/calendarview.cpp | 4 | ||||
-rw-r--r-- | libkcal/calendar.h | 2 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 11 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 2 |
4 files changed, 14 insertions, 5 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 538325e..9571f16 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -953,1647 +953,1647 @@ void CalendarView::checkAlarms() | |||
953 | nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Norbert") ); | 953 | nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Norbert") ); |
954 | Todo * workNorbert11 = nt; | 954 | Todo * workNorbert11 = nt; |
955 | workNorbert11->setRelatedTo( sub1 ); | 955 | workNorbert11->setRelatedTo( sub1 ); |
956 | 956 | ||
957 | nt = new Todo; | 957 | nt = new Todo; |
958 | mCalendar->addTodo( nt ); | 958 | mCalendar->addTodo( nt ); |
959 | nt->setSummary( "Work on 1"); | 959 | nt->setSummary( "Work on 1"); |
960 | nt->setPriority( 1 ); | 960 | nt->setPriority( 1 ); |
961 | nt->setDescription( "This is a test description of Work Project_1" ); | 961 | nt->setDescription( "This is a test description of Work Project_1" ); |
962 | nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1") ); | 962 | nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1") ); |
963 | nt->setPercentComplete( 20 ); | 963 | nt->setPercentComplete( 20 ); |
964 | 964 | ||
965 | Todo * sub2 = nt; | 965 | Todo * sub2 = nt; |
966 | sub2->setRelatedTo( root1 ); | 966 | sub2->setRelatedTo( root1 ); |
967 | 967 | ||
968 | 968 | ||
969 | nt = new Todo; | 969 | nt = new Todo; |
970 | mCalendar->addTodo( nt ); | 970 | mCalendar->addTodo( nt ); |
971 | nt->setSummary( "Work on 1: Lutz"); | 971 | nt->setSummary( "Work on 1: Lutz"); |
972 | nt->setPriority( 1 ); | 972 | nt->setPriority( 1 ); |
973 | nt->setDescription( "This todo counts the actual work of a person on a project" ); | 973 | nt->setDescription( "This todo counts the actual work of a person on a project" ); |
974 | nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Lutz") ); | 974 | nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Lutz") ); |
975 | nt->setPercentComplete( 20 ); | 975 | nt->setPercentComplete( 20 ); |
976 | Todo * workLutz12 = nt; | 976 | Todo * workLutz12 = nt; |
977 | workLutz12->setRelatedTo( sub2 ); | 977 | workLutz12->setRelatedTo( sub2 ); |
978 | 978 | ||
979 | nt = new Todo; | 979 | nt = new Todo; |
980 | mCalendar->addTodo( nt ); | 980 | mCalendar->addTodo( nt ); |
981 | nt->setSummary( "Work on 1: Norbert"); | 981 | nt->setSummary( "Work on 1: Norbert"); |
982 | nt->setPriority( 1 ); | 982 | nt->setPriority( 1 ); |
983 | nt->setDescription( "This todo counts the actual work of a person on a project" ); | 983 | nt->setDescription( "This todo counts the actual work of a person on a project" ); |
984 | nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Norbert") ); | 984 | nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Norbert") ); |
985 | nt->setPercentComplete( 20 ); | 985 | nt->setPercentComplete( 20 ); |
986 | Todo * workNorbert12 = nt; | 986 | Todo * workNorbert12 = nt; |
987 | workNorbert12->setRelatedTo( sub2 ); | 987 | workNorbert12->setRelatedTo( sub2 ); |
988 | 988 | ||
989 | int secLenRunning = 7200; | 989 | int secLenRunning = 7200; |
990 | int secLenPausing = 3600 * 3; | 990 | int secLenPausing = 3600 * 3; |
991 | int dayInterval = 1; | 991 | int dayInterval = 1; |
992 | //createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, dayInterval ); | 992 | //createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, dayInterval ); |
993 | createRunningDate4Todo( root1, start, end, secLenRunning*24, secLenPausing, 14 ); | 993 | createRunningDate4Todo( root1, start, end, secLenRunning*24, secLenPausing, 14 ); |
994 | createRunningDate4Todo( sub1, start.addSecs( secLenRunning ), start.addDays( 10 ), secLenRunning*4, secLenPausing, 1); | 994 | createRunningDate4Todo( sub1, start.addSecs( secLenRunning ), start.addDays( 10 ), secLenRunning*4, secLenPausing, 1); |
995 | createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*4, secLenPausing, 3); | 995 | createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*4, secLenPausing, 3); |
996 | createRunningDate4Todo( workLutz11, start, start.addDays( 8 ), secLenRunning, secLenPausing, 0); | 996 | createRunningDate4Todo( workLutz11, start, start.addDays( 8 ), secLenRunning, secLenPausing, 0); |
997 | createRunningDate4Todo( workNorbert11, start, start.addDays( 8 ), secLenRunning*2, secLenPausing, 1); | 997 | createRunningDate4Todo( workNorbert11, start, start.addDays( 8 ), secLenRunning*2, secLenPausing, 1); |
998 | createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning*5, secLenPausing, 3); | 998 | createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning*5, secLenPausing, 3); |
999 | createRunningDate4Todo( workNorbert12, start.addDays( 8 ), end, secLenRunning, secLenPausing*3, 0); | 999 | createRunningDate4Todo( workNorbert12, start.addDays( 8 ), end, secLenRunning, secLenPausing*3, 0); |
1000 | 1000 | ||
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | { | 1003 | { |
1004 | Todo * root1 = new Todo; | 1004 | Todo * root1 = new Todo; |
1005 | mCalendar->addTodo( root1 ); | 1005 | mCalendar->addTodo( root1 ); |
1006 | root1->setSummary( "Project2"); | 1006 | root1->setSummary( "Project2"); |
1007 | root1->setPriority( 1 ); | 1007 | root1->setPriority( 1 ); |
1008 | root1->setDescription( "This is a test description of a root Project 2" ); | 1008 | root1->setDescription( "This is a test description of a root Project 2" ); |
1009 | root1->setPercentComplete( 20 ); | 1009 | root1->setPercentComplete( 20 ); |
1010 | root1->setCategories( QString( "Cat_Pro2") ); | 1010 | root1->setCategories( QString( "Cat_Pro2") ); |
1011 | updateView(); | 1011 | updateView(); |
1012 | QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) ); | 1012 | QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) ); |
1013 | QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) ); | 1013 | QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) ); |
1014 | int secLenRunning = 7200; | 1014 | int secLenRunning = 7200; |
1015 | int secLenPausing = 3600 * 3; | 1015 | int secLenPausing = 3600 * 3; |
1016 | int dayInterval = 1; | 1016 | int dayInterval = 1; |
1017 | 1017 | ||
1018 | nt = new Todo; | 1018 | nt = new Todo; |
1019 | mCalendar->addTodo( nt ); | 1019 | mCalendar->addTodo( nt ); |
1020 | nt->setSummary( "Planning Project2"); | 1020 | nt->setSummary( "Planning Project2"); |
1021 | nt->setPriority( 1 ); | 1021 | nt->setPriority( 1 ); |
1022 | nt->setDescription( "This is a test description of Planning_Project_2" ); | 1022 | nt->setDescription( "This is a test description of Planning_Project_2" ); |
1023 | nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2") ); | 1023 | nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2") ); |
1024 | nt->setPercentComplete( 20 ); | 1024 | nt->setPercentComplete( 20 ); |
1025 | 1025 | ||
1026 | 1026 | ||
1027 | Todo * sub1 = nt; | 1027 | Todo * sub1 = nt; |
1028 | sub1->setRelatedTo( root1 ); | 1028 | sub1->setRelatedTo( root1 ); |
1029 | 1029 | ||
1030 | nt = new Todo; | 1030 | nt = new Todo; |
1031 | mCalendar->addTodo( nt ); | 1031 | mCalendar->addTodo( nt ); |
1032 | nt->setSummary( "Planning Project2: Lutz"); | 1032 | nt->setSummary( "Planning Project2: Lutz"); |
1033 | nt->setPriority( 1 ); | 1033 | nt->setPriority( 1 ); |
1034 | nt->setDescription( "This todo counts the actual work of a person on a project" ); | 1034 | nt->setDescription( "This todo counts the actual work of a person on a project" ); |
1035 | nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Lutz") ); | 1035 | nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Lutz") ); |
1036 | nt->setPercentComplete( 20 ); | 1036 | nt->setPercentComplete( 20 ); |
1037 | Todo * workLutz11 = nt; | 1037 | Todo * workLutz11 = nt; |
1038 | workLutz11->setRelatedTo( sub1 ); | 1038 | workLutz11->setRelatedTo( sub1 ); |
1039 | 1039 | ||
1040 | nt = new Todo; | 1040 | nt = new Todo; |
1041 | mCalendar->addTodo( nt ); | 1041 | mCalendar->addTodo( nt ); |
1042 | nt->setSummary( "Planning Project2: Norbert"); | 1042 | nt->setSummary( "Planning Project2: Norbert"); |
1043 | nt->setPriority( 1 ); | 1043 | nt->setPriority( 1 ); |
1044 | nt->setDescription( "This todo counts the actual work of a person on a project" ); | 1044 | nt->setDescription( "This todo counts the actual work of a person on a project" ); |
1045 | nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Norbert") ); | 1045 | nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Norbert") ); |
1046 | nt->setPercentComplete( 20 ); | 1046 | nt->setPercentComplete( 20 ); |
1047 | Todo * workNorbert11 = nt; | 1047 | Todo * workNorbert11 = nt; |
1048 | workNorbert11->setRelatedTo( sub1 ); | 1048 | workNorbert11->setRelatedTo( sub1 ); |
1049 | 1049 | ||
1050 | nt = new Todo; | 1050 | nt = new Todo; |
1051 | mCalendar->addTodo( nt ); | 1051 | mCalendar->addTodo( nt ); |
1052 | nt->setSummary( "Work on 2"); | 1052 | nt->setSummary( "Work on 2"); |
1053 | nt->setPriority( 1 ); | 1053 | nt->setPriority( 1 ); |
1054 | nt->setDescription( "This is a test description of Work Project_2" ); | 1054 | nt->setDescription( "This is a test description of Work Project_2" ); |
1055 | nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2") ); | 1055 | nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2") ); |
1056 | nt->setPercentComplete( 20 ); | 1056 | nt->setPercentComplete( 20 ); |
1057 | 1057 | ||
1058 | Todo * sub2 = nt; | 1058 | Todo * sub2 = nt; |
1059 | sub2->setRelatedTo( root1 ); | 1059 | sub2->setRelatedTo( root1 ); |
1060 | 1060 | ||
1061 | 1061 | ||
1062 | nt = new Todo; | 1062 | nt = new Todo; |
1063 | mCalendar->addTodo( nt ); | 1063 | mCalendar->addTodo( nt ); |
1064 | nt->setSummary( "Work on 2: Lutz"); | 1064 | nt->setSummary( "Work on 2: Lutz"); |
1065 | nt->setPriority( 1 ); | 1065 | nt->setPriority( 1 ); |
1066 | nt->setDescription( "This todo counts the actual work of a person on a project" ); | 1066 | nt->setDescription( "This todo counts the actual work of a person on a project" ); |
1067 | nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Lutz") ); | 1067 | nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Lutz") ); |
1068 | nt->setPercentComplete( 20 ); | 1068 | nt->setPercentComplete( 20 ); |
1069 | Todo * workLutz12 = nt; | 1069 | Todo * workLutz12 = nt; |
1070 | workLutz12->setRelatedTo( sub2 ); | 1070 | workLutz12->setRelatedTo( sub2 ); |
1071 | 1071 | ||
1072 | nt = new Todo; | 1072 | nt = new Todo; |
1073 | mCalendar->addTodo( nt ); | 1073 | mCalendar->addTodo( nt ); |
1074 | nt->setSummary( "Work on 2: Norbert"); | 1074 | nt->setSummary( "Work on 2: Norbert"); |
1075 | nt->setPriority( 1 ); | 1075 | nt->setPriority( 1 ); |
1076 | nt->setDescription( "This todo counts the actual work of a person on a project" ); | 1076 | nt->setDescription( "This todo counts the actual work of a person on a project" ); |
1077 | nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Norbert") ); | 1077 | nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Norbert") ); |
1078 | nt->setPercentComplete( 20 ); | 1078 | nt->setPercentComplete( 20 ); |
1079 | Todo * workNorbert12 = nt; | 1079 | Todo * workNorbert12 = nt; |
1080 | workNorbert12->setRelatedTo( sub2 ); | 1080 | workNorbert12->setRelatedTo( sub2 ); |
1081 | createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, 10 ); | 1081 | createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, 10 ); |
1082 | createRunningDate4Todo( sub1, start.addSecs( secLenRunning*3 ), start.addDays( 20 ), secLenRunning*2, secLenPausing, 2); | 1082 | createRunningDate4Todo( sub1, start.addSecs( secLenRunning*3 ), start.addDays( 20 ), secLenRunning*2, secLenPausing, 2); |
1083 | createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*3, secLenPausing, 7); | 1083 | createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*3, secLenPausing, 7); |
1084 | createRunningDate4Todo( workLutz11, start, start.addDays( 18 ), secLenRunning/2, secLenPausing*5, 0); | 1084 | createRunningDate4Todo( workLutz11, start, start.addDays( 18 ), secLenRunning/2, secLenPausing*5, 0); |
1085 | createRunningDate4Todo( workNorbert11, start.addDays( 8 ), start.addDays( 18 ), secLenRunning*5, secLenPausing*5, 1); | 1085 | createRunningDate4Todo( workNorbert11, start.addDays( 8 ), start.addDays( 18 ), secLenRunning*5, secLenPausing*5, 1); |
1086 | createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning, secLenPausing*8, 0); | 1086 | createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning, secLenPausing*8, 0); |
1087 | createRunningDate4Todo( workNorbert12, start.addDays( 28 ), end, secLenRunning/8, secLenPausing*6, 0); | 1087 | createRunningDate4Todo( workNorbert12, start.addDays( 28 ), end, secLenRunning/8, secLenPausing*6, 0); |
1088 | } | 1088 | } |
1089 | updateView(); | 1089 | updateView(); |
1090 | #endif | 1090 | #endif |
1091 | 1091 | ||
1092 | } | 1092 | } |
1093 | void CalendarView::createRunningDate4Todo( Todo * runT, QDateTime start , QDateTime end, int secLenRunning, int secLenPausing,int dayInterval ) | 1093 | void CalendarView::createRunningDate4Todo( Todo * runT, QDateTime start , QDateTime end, int secLenRunning, int secLenPausing,int dayInterval ) |
1094 | { | 1094 | { |
1095 | static int ccc = 0; | 1095 | static int ccc = 0; |
1096 | ++ccc; | 1096 | ++ccc; |
1097 | QDateTime t_start = start; | 1097 | QDateTime t_start = start; |
1098 | runT->setPriority( 5 ); | 1098 | runT->setPriority( 5 ); |
1099 | runT->setPercentComplete( 0 ); | 1099 | runT->setPercentComplete( 0 ); |
1100 | int count = 0; | 1100 | int count = 0; |
1101 | int prio = 5; | 1101 | int prio = 5; |
1102 | int complete = 0; | 1102 | int complete = 0; |
1103 | while ( t_start < end ) { | 1103 | while ( t_start < end ) { |
1104 | ++count; | 1104 | ++count; |
1105 | if ( count > ccc ) { | 1105 | if ( count > ccc ) { |
1106 | count = 0; | 1106 | count = 0; |
1107 | --prio; | 1107 | --prio; |
1108 | if ( prio == 0 ) prio = 5; | 1108 | if ( prio == 0 ) prio = 5; |
1109 | complete += 20; | 1109 | complete += 20; |
1110 | if ( complete > 100 ) complete = 0; | 1110 | if ( complete > 100 ) complete = 0; |
1111 | runT->setPriority( prio ); | 1111 | runT->setPriority( prio ); |
1112 | runT->setPercentComplete( complete ); | 1112 | runT->setPercentComplete( complete ); |
1113 | } | 1113 | } |
1114 | runT->setRunning( true ); | 1114 | runT->setRunning( true ); |
1115 | runT->saveRunningInfo( "Additional tt comment: running on "+ t_start.toString(), t_start, t_start.addSecs( secLenRunning ) ); | 1115 | runT->saveRunningInfo( "Additional tt comment: running on "+ t_start.toString(), t_start, t_start.addSecs( secLenRunning ) ); |
1116 | if ( dayInterval ) | 1116 | if ( dayInterval ) |
1117 | t_start = t_start.addDays( dayInterval ); | 1117 | t_start = t_start.addDays( dayInterval ); |
1118 | else { | 1118 | else { |
1119 | t_start = t_start.addSecs( secLenRunning + secLenPausing ); | 1119 | t_start = t_start.addSecs( secLenRunning + secLenPausing ); |
1120 | } | 1120 | } |
1121 | } | 1121 | } |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | void CalendarView::showDay( QDate d ) | 1124 | void CalendarView::showDay( QDate d ) |
1125 | { | 1125 | { |
1126 | dateNavigator()->blockSignals( true ); | 1126 | dateNavigator()->blockSignals( true ); |
1127 | dateNavigator()->selectDate( d ); | 1127 | dateNavigator()->selectDate( d ); |
1128 | dateNavigator()->blockSignals( false ); | 1128 | dateNavigator()->blockSignals( false ); |
1129 | mViewManager->showDayView(); | 1129 | mViewManager->showDayView(); |
1130 | //dateNavigator()->selectDate( d ); | 1130 | //dateNavigator()->selectDate( d ); |
1131 | } | 1131 | } |
1132 | void CalendarView::timerAlarm() | 1132 | void CalendarView::timerAlarm() |
1133 | { | 1133 | { |
1134 | //qDebug("CalendarView::timerAlarm() "); | 1134 | //qDebug("CalendarView::timerAlarm() "); |
1135 | computeAlarm(mAlarmNotification ); | 1135 | computeAlarm(mAlarmNotification ); |
1136 | } | 1136 | } |
1137 | 1137 | ||
1138 | void CalendarView::suspendAlarm() | 1138 | void CalendarView::suspendAlarm() |
1139 | { | 1139 | { |
1140 | //qDebug(" CalendarView::suspendAlarm() "); | 1140 | //qDebug(" CalendarView::suspendAlarm() "); |
1141 | computeAlarm(mSuspendAlarmNotification ); | 1141 | computeAlarm(mSuspendAlarmNotification ); |
1142 | 1142 | ||
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | void CalendarView::startAlarm( QString mess , QString filename) | 1145 | void CalendarView::startAlarm( QString mess , QString filename) |
1146 | { | 1146 | { |
1147 | 1147 | ||
1148 | topLevelWidget()->showNormal(); | 1148 | topLevelWidget()->showNormal(); |
1149 | topLevelWidget()->setActiveWindow(); | 1149 | topLevelWidget()->setActiveWindow(); |
1150 | topLevelWidget()->raise(); | 1150 | topLevelWidget()->raise(); |
1151 | 1151 | ||
1152 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); | 1152 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); |
1153 | QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); | 1153 | QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); |
1154 | 1154 | ||
1155 | } | 1155 | } |
1156 | 1156 | ||
1157 | void CalendarView::checkNextTimerAlarm() | 1157 | void CalendarView::checkNextTimerAlarm() |
1158 | { | 1158 | { |
1159 | mCalendar->checkAlarmForIncidence( 0, true ); | 1159 | mCalendar->checkAlarmForIncidence( 0, true ); |
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | void CalendarView::computeAlarm( QString msg ) | 1162 | void CalendarView::computeAlarm( QString msg ) |
1163 | { | 1163 | { |
1164 | 1164 | ||
1165 | QString mess = msg; | 1165 | QString mess = msg; |
1166 | QString mAlarmMessage = mess.mid( 9 ); | 1166 | QString mAlarmMessage = mess.mid( 9 ); |
1167 | QString filename = MainWindow::resourcePath(); | 1167 | QString filename = MainWindow::resourcePath(); |
1168 | filename += "koalarm.wav"; | 1168 | filename += "koalarm.wav"; |
1169 | QString tempfilename; | 1169 | QString tempfilename; |
1170 | if ( mess.left( 13 ) == "suspend_alarm") { | 1170 | if ( mess.left( 13 ) == "suspend_alarm") { |
1171 | bool error = false; | 1171 | bool error = false; |
1172 | int len = mess.mid( 13 ).find("+++"); | 1172 | int len = mess.mid( 13 ).find("+++"); |
1173 | if ( len < 2 ) | 1173 | if ( len < 2 ) |
1174 | error = true; | 1174 | error = true; |
1175 | else { | 1175 | else { |
1176 | tempfilename = mess.mid( 13, len ); | 1176 | tempfilename = mess.mid( 13, len ); |
1177 | if ( !QFile::exists( tempfilename ) ) | 1177 | if ( !QFile::exists( tempfilename ) ) |
1178 | error = true; | 1178 | error = true; |
1179 | } | 1179 | } |
1180 | if ( ! error ) { | 1180 | if ( ! error ) { |
1181 | filename = tempfilename; | 1181 | filename = tempfilename; |
1182 | } | 1182 | } |
1183 | mAlarmMessage = mess.mid( 13+len+3 ); | 1183 | mAlarmMessage = mess.mid( 13+len+3 ); |
1184 | //qDebug("suspend file %s ",tempfilename.latin1() ); | 1184 | //qDebug("suspend file %s ",tempfilename.latin1() ); |
1185 | startAlarm( mAlarmMessage, filename); | 1185 | startAlarm( mAlarmMessage, filename); |
1186 | return; | 1186 | return; |
1187 | } | 1187 | } |
1188 | if ( mess.left( 11 ) == "timer_alarm") { | 1188 | if ( mess.left( 11 ) == "timer_alarm") { |
1189 | //mTimerTime = 0; | 1189 | //mTimerTime = 0; |
1190 | startAlarm( mess.mid( 11 ), filename ); | 1190 | startAlarm( mess.mid( 11 ), filename ); |
1191 | return; | 1191 | return; |
1192 | } | 1192 | } |
1193 | if ( mess.left( 10 ) == "proc_alarm") { | 1193 | if ( mess.left( 10 ) == "proc_alarm") { |
1194 | bool error = false; | 1194 | bool error = false; |
1195 | int len = mess.mid( 10 ).find("+++"); | 1195 | int len = mess.mid( 10 ).find("+++"); |
1196 | if ( len < 2 ) | 1196 | if ( len < 2 ) |
1197 | error = true; | 1197 | error = true; |
1198 | else { | 1198 | else { |
1199 | tempfilename = mess.mid( 10, len ); | 1199 | tempfilename = mess.mid( 10, len ); |
1200 | if ( !QFile::exists( tempfilename ) ) | 1200 | if ( !QFile::exists( tempfilename ) ) |
1201 | error = true; | 1201 | error = true; |
1202 | } | 1202 | } |
1203 | if ( error ) { | 1203 | if ( error ) { |
1204 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; | 1204 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; |
1205 | mAlarmMessage += mess.mid( 10+len+3+9 ); | 1205 | mAlarmMessage += mess.mid( 10+len+3+9 ); |
1206 | } else { | 1206 | } else { |
1207 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); | 1207 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); |
1208 | //qDebug("-----system command %s ",tempfilename.latin1() ); | 1208 | //qDebug("-----system command %s ",tempfilename.latin1() ); |
1209 | #ifndef _WIN32_ | 1209 | #ifndef _WIN32_ |
1210 | if ( vfork () == 0 ) { | 1210 | if ( vfork () == 0 ) { |
1211 | execl ( tempfilename.latin1(), 0 ); | 1211 | execl ( tempfilename.latin1(), 0 ); |
1212 | return; | 1212 | return; |
1213 | } | 1213 | } |
1214 | #else | 1214 | #else |
1215 | QProcess* p = new QProcess(); | 1215 | QProcess* p = new QProcess(); |
1216 | p->addArgument( tempfilename.latin1() ); | 1216 | p->addArgument( tempfilename.latin1() ); |
1217 | p->start(); | 1217 | p->start(); |
1218 | return; | 1218 | return; |
1219 | #endif | 1219 | #endif |
1220 | 1220 | ||
1221 | return; | 1221 | return; |
1222 | } | 1222 | } |
1223 | 1223 | ||
1224 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); | 1224 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); |
1225 | } | 1225 | } |
1226 | if ( mess.left( 11 ) == "audio_alarm") { | 1226 | if ( mess.left( 11 ) == "audio_alarm") { |
1227 | bool error = false; | 1227 | bool error = false; |
1228 | int len = mess.mid( 11 ).find("+++"); | 1228 | int len = mess.mid( 11 ).find("+++"); |
1229 | if ( len < 2 ) | 1229 | if ( len < 2 ) |
1230 | error = true; | 1230 | error = true; |
1231 | else { | 1231 | else { |
1232 | tempfilename = mess.mid( 11, len ); | 1232 | tempfilename = mess.mid( 11, len ); |
1233 | if ( !QFile::exists( tempfilename ) ) | 1233 | if ( !QFile::exists( tempfilename ) ) |
1234 | error = true; | 1234 | error = true; |
1235 | } | 1235 | } |
1236 | if ( ! error ) { | 1236 | if ( ! error ) { |
1237 | filename = tempfilename; | 1237 | filename = tempfilename; |
1238 | } | 1238 | } |
1239 | mAlarmMessage = mess.mid( 11+len+3+9 ); | 1239 | mAlarmMessage = mess.mid( 11+len+3+9 ); |
1240 | //qDebug("audio file command %s ",tempfilename.latin1() ); | 1240 | //qDebug("audio file command %s ",tempfilename.latin1() ); |
1241 | } | 1241 | } |
1242 | if ( mess.left( 9 ) == "cal_alarm") { | 1242 | if ( mess.left( 9 ) == "cal_alarm") { |
1243 | mAlarmMessage = mess.mid( 9 ) ; | 1243 | mAlarmMessage = mess.mid( 9 ) ; |
1244 | } | 1244 | } |
1245 | 1245 | ||
1246 | startAlarm( mAlarmMessage, filename ); | 1246 | startAlarm( mAlarmMessage, filename ); |
1247 | 1247 | ||
1248 | 1248 | ||
1249 | } | 1249 | } |
1250 | 1250 | ||
1251 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | 1251 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) |
1252 | { | 1252 | { |
1253 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1253 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1254 | 1254 | ||
1255 | mSuspendAlarmNotification = noti; | 1255 | mSuspendAlarmNotification = noti; |
1256 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 1256 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; |
1257 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); | 1257 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); |
1258 | mSuspendTimer->start( ms , true ); | 1258 | mSuspendTimer->start( ms , true ); |
1259 | #ifdef DESKTOP_VERSION | 1259 | #ifdef DESKTOP_VERSION |
1260 | if ( QApplication::desktop()->width() < 1024 ) { | 1260 | if ( QApplication::desktop()->width() < 1024 ) { |
1261 | QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; | 1261 | QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; |
1262 | //qDebug("nextsuspendalarm = \n%s ",mess.latin1() ); | 1262 | //qDebug("nextsuspendalarm = \n%s ",mess.latin1() ); |
1263 | QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm"; | 1263 | QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm"; |
1264 | QFile file( fn ); | 1264 | QFile file( fn ); |
1265 | if (!file.open( IO_WriteOnly ) ) { | 1265 | if (!file.open( IO_WriteOnly ) ) { |
1266 | qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); | 1266 | qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); |
1267 | } else { | 1267 | } else { |
1268 | QTextStream ts( &file ); | 1268 | QTextStream ts( &file ); |
1269 | ts << mess; | 1269 | ts << mess; |
1270 | file.close(); | 1270 | file.close(); |
1271 | } | 1271 | } |
1272 | } | 1272 | } |
1273 | #endif | 1273 | #endif |
1274 | 1274 | ||
1275 | } | 1275 | } |
1276 | 1276 | ||
1277 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 1277 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
1278 | { | 1278 | { |
1279 | mNextAlarmDateTime = qdt; | 1279 | mNextAlarmDateTime = qdt; |
1280 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1280 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1281 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 1281 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
1282 | #ifndef DESKTOP_VERSION | 1282 | #ifndef DESKTOP_VERSION |
1283 | AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); | 1283 | AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); |
1284 | #endif | 1284 | #endif |
1285 | return; | 1285 | return; |
1286 | } | 1286 | } |
1287 | #ifdef DESKTOP_VERSION | 1287 | #ifdef DESKTOP_VERSION |
1288 | if ( QApplication::desktop()->width() < 1024 ) { | 1288 | if ( QApplication::desktop()->width() < 1024 ) { |
1289 | QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; | 1289 | QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti; |
1290 | //qDebug("nextalarm = \n%s ",mess.latin1() ); | 1290 | //qDebug("nextalarm = \n%s ",mess.latin1() ); |
1291 | QString fn = QDir::homeDirPath() + "/.kopi_next_alarm"; | 1291 | QString fn = QDir::homeDirPath() + "/.kopi_next_alarm"; |
1292 | QFile file( fn ); | 1292 | QFile file( fn ); |
1293 | if (!file.open( IO_WriteOnly ) ) { | 1293 | if (!file.open( IO_WriteOnly ) ) { |
1294 | qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); | 1294 | qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1()); |
1295 | } else { | 1295 | } else { |
1296 | QTextStream ts( &file ); | 1296 | QTextStream ts( &file ); |
1297 | ts << mess; | 1297 | ts << mess; |
1298 | file.close(); | 1298 | file.close(); |
1299 | } | 1299 | } |
1300 | } | 1300 | } |
1301 | #endif | 1301 | #endif |
1302 | int maxSec; | 1302 | int maxSec; |
1303 | //maxSec = 5; //testing only | 1303 | //maxSec = 5; //testing only |
1304 | maxSec = 86400+3600; // one day+1hour | 1304 | maxSec = 86400+3600; // one day+1hour |
1305 | mAlarmNotification = noti; | 1305 | mAlarmNotification = noti; |
1306 | int sec = QDateTime::currentDateTime().secsTo( qdt ); | 1306 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
1307 | if ( sec > maxSec ) { | 1307 | if ( sec > maxSec ) { |
1308 | mRecheckAlarmTimer->start( maxSec * 1000 ); | 1308 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
1309 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | 1309 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); |
1310 | return; | 1310 | return; |
1311 | } else { | 1311 | } else { |
1312 | mRecheckAlarmTimer->stop(); | 1312 | mRecheckAlarmTimer->stop(); |
1313 | } | 1313 | } |
1314 | //qDebug("Alarm timer started with secs: %d ", sec); | 1314 | //qDebug("Alarm timer started with secs: %d ", sec); |
1315 | mAlarmTimer->start( sec * 1000 , true ); | 1315 | mAlarmTimer->start( sec * 1000 , true ); |
1316 | 1316 | ||
1317 | } | 1317 | } |
1318 | // called by mRecheckAlarmTimer to get next alarm | 1318 | // called by mRecheckAlarmTimer to get next alarm |
1319 | // we need this, because a QTimer has only a max range of 25 days | 1319 | // we need this, because a QTimer has only a max range of 25 days |
1320 | void CalendarView::recheckTimerAlarm() | 1320 | void CalendarView::recheckTimerAlarm() |
1321 | { | 1321 | { |
1322 | mAlarmTimer->stop(); | 1322 | mAlarmTimer->stop(); |
1323 | mRecheckAlarmTimer->stop(); | 1323 | mRecheckAlarmTimer->stop(); |
1324 | mCalendar->checkAlarmForIncidence( 0, true ); | 1324 | mCalendar->checkAlarmForIncidence( 0, true ); |
1325 | } | 1325 | } |
1326 | #ifndef DESKTOP_VERSION | 1326 | #ifndef DESKTOP_VERSION |
1327 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 1327 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
1328 | #else | 1328 | #else |
1329 | void CalendarView::removeAlarm(const QDateTime &, const QString & ) | 1329 | void CalendarView::removeAlarm(const QDateTime &, const QString & ) |
1330 | #endif | 1330 | #endif |
1331 | { | 1331 | { |
1332 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1332 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1333 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 1333 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
1334 | #ifndef DESKTOP_VERSION | 1334 | #ifndef DESKTOP_VERSION |
1335 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); | 1335 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); |
1336 | #endif | 1336 | #endif |
1337 | return; | 1337 | return; |
1338 | } | 1338 | } |
1339 | mAlarmTimer->stop(); | 1339 | mAlarmTimer->stop(); |
1340 | } | 1340 | } |
1341 | void CalendarView::selectWeekNum ( int num ) | 1341 | void CalendarView::selectWeekNum ( int num ) |
1342 | { | 1342 | { |
1343 | dateNavigator()->blockSignals( true ); | 1343 | dateNavigator()->blockSignals( true ); |
1344 | dateNavigator()->selectWeek( num ); | 1344 | dateNavigator()->selectWeek( num ); |
1345 | dateNavigator()->blockSignals( false ); | 1345 | dateNavigator()->blockSignals( false ); |
1346 | mViewManager->showWeekView(); | 1346 | mViewManager->showWeekView(); |
1347 | } | 1347 | } |
1348 | KOViewManager *CalendarView::viewManager() | 1348 | KOViewManager *CalendarView::viewManager() |
1349 | { | 1349 | { |
1350 | return mViewManager; | 1350 | return mViewManager; |
1351 | } | 1351 | } |
1352 | 1352 | ||
1353 | KODialogManager *CalendarView::dialogManager() | 1353 | KODialogManager *CalendarView::dialogManager() |
1354 | { | 1354 | { |
1355 | return mDialogManager; | 1355 | return mDialogManager; |
1356 | } | 1356 | } |
1357 | 1357 | ||
1358 | QDate CalendarView::startDate() | 1358 | QDate CalendarView::startDate() |
1359 | { | 1359 | { |
1360 | DateList dates = mNavigator->selectedDates(); | 1360 | DateList dates = mNavigator->selectedDates(); |
1361 | 1361 | ||
1362 | return dates.first(); | 1362 | return dates.first(); |
1363 | } | 1363 | } |
1364 | 1364 | ||
1365 | QDate CalendarView::endDate() | 1365 | QDate CalendarView::endDate() |
1366 | { | 1366 | { |
1367 | DateList dates = mNavigator->selectedDates(); | 1367 | DateList dates = mNavigator->selectedDates(); |
1368 | 1368 | ||
1369 | return dates.last(); | 1369 | return dates.last(); |
1370 | } | 1370 | } |
1371 | 1371 | ||
1372 | 1372 | ||
1373 | void CalendarView::createPrinter() | 1373 | void CalendarView::createPrinter() |
1374 | { | 1374 | { |
1375 | #ifndef KORG_NOPRINTER | 1375 | #ifndef KORG_NOPRINTER |
1376 | if (!mCalPrinter) { | 1376 | if (!mCalPrinter) { |
1377 | mCalPrinter = new CalPrinter(this, mCalendar); | 1377 | mCalPrinter = new CalPrinter(this, mCalendar); |
1378 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); | 1378 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); |
1379 | } | 1379 | } |
1380 | #endif | 1380 | #endif |
1381 | } | 1381 | } |
1382 | 1382 | ||
1383 | 1383 | ||
1384 | //KOPrefs::instance()->mWriteBackFile | 1384 | //KOPrefs::instance()->mWriteBackFile |
1385 | //KOPrefs::instance()->mWriteBackExistingOnly | 1385 | //KOPrefs::instance()->mWriteBackExistingOnly |
1386 | 1386 | ||
1387 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 1387 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
1388 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 1388 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
1389 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 1389 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
1390 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 1390 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
1391 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 1391 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
1392 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 1392 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
1393 | 1393 | ||
1394 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 1394 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
1395 | { | 1395 | { |
1396 | 1396 | ||
1397 | // 0 equal | 1397 | // 0 equal |
1398 | // 1 take local | 1398 | // 1 take local |
1399 | // 2 take remote | 1399 | // 2 take remote |
1400 | // 3 cancel | 1400 | // 3 cancel |
1401 | QDateTime lastSync = mLastCalendarSync; | 1401 | QDateTime lastSync = mLastCalendarSync; |
1402 | QDateTime localMod = local->lastModified(); | 1402 | QDateTime localMod = local->lastModified(); |
1403 | QDateTime remoteMod = remote->lastModified(); | 1403 | QDateTime remoteMod = remote->lastModified(); |
1404 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1404 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1405 | bool remCh, locCh; | 1405 | bool remCh, locCh; |
1406 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 1406 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
1407 | //if ( remCh ) | 1407 | //if ( remCh ) |
1408 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 1408 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
1409 | locCh = ( localMod > mLastCalendarSync ); | 1409 | locCh = ( localMod > mLastCalendarSync ); |
1410 | if ( !remCh && ! locCh ) { | 1410 | if ( !remCh && ! locCh ) { |
1411 | //qDebug("both not changed "); | 1411 | //qDebug("both not changed "); |
1412 | lastSync = localMod.addDays(1); | 1412 | lastSync = localMod.addDays(1); |
1413 | if ( mode <= SYNC_PREF_ASK ) | 1413 | if ( mode <= SYNC_PREF_ASK ) |
1414 | return 0; | 1414 | return 0; |
1415 | } else { | 1415 | } else { |
1416 | if ( locCh ) { | 1416 | if ( locCh ) { |
1417 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); | 1417 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); |
1418 | lastSync = localMod.addDays( -1 ); | 1418 | lastSync = localMod.addDays( -1 ); |
1419 | if ( !remCh ) | 1419 | if ( !remCh ) |
1420 | remoteMod = ( lastSync.addDays( -1 ) ); | 1420 | remoteMod = ( lastSync.addDays( -1 ) ); |
1421 | } else { | 1421 | } else { |
1422 | //qDebug(" not loc changed "); | 1422 | //qDebug(" not loc changed "); |
1423 | lastSync = localMod.addDays( 1 ); | 1423 | lastSync = localMod.addDays( 1 ); |
1424 | if ( remCh ) | 1424 | if ( remCh ) |
1425 | remoteMod =( lastSync.addDays( 1 ) ); | 1425 | remoteMod =( lastSync.addDays( 1 ) ); |
1426 | 1426 | ||
1427 | } | 1427 | } |
1428 | } | 1428 | } |
1429 | full = true; | 1429 | full = true; |
1430 | if ( mode < SYNC_PREF_ASK ) | 1430 | if ( mode < SYNC_PREF_ASK ) |
1431 | mode = SYNC_PREF_ASK; | 1431 | mode = SYNC_PREF_ASK; |
1432 | } else { | 1432 | } else { |
1433 | if ( localMod == remoteMod ) | 1433 | if ( localMod == remoteMod ) |
1434 | // if ( local->revision() == remote->revision() ) | 1434 | // if ( local->revision() == remote->revision() ) |
1435 | return 0; | 1435 | return 0; |
1436 | 1436 | ||
1437 | } | 1437 | } |
1438 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 1438 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
1439 | 1439 | ||
1440 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); | 1440 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); |
1441 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); | 1441 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); |
1442 | //full = true; //debug only | 1442 | //full = true; //debug only |
1443 | if ( full ) { | 1443 | if ( full ) { |
1444 | bool equ = false; | 1444 | bool equ = false; |
1445 | if ( local->typeID() == eventID ) { | 1445 | if ( local->typeID() == eventID ) { |
1446 | equ = (*((Event*) local) == *((Event*) remote)); | 1446 | equ = (*((Event*) local) == *((Event*) remote)); |
1447 | } | 1447 | } |
1448 | else if ( local->typeID() == todoID ) | 1448 | else if ( local->typeID() == todoID ) |
1449 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 1449 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
1450 | else if ( local->typeID() == journalID ) | 1450 | else if ( local->typeID() == journalID ) |
1451 | equ = (*((Journal*) local) == *((Journal*) remote)); | 1451 | equ = (*((Journal*) local) == *((Journal*) remote)); |
1452 | if ( equ ) { | 1452 | if ( equ ) { |
1453 | //qDebug("equal "); | 1453 | //qDebug("equal "); |
1454 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1454 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1455 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 1455 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
1456 | } | 1456 | } |
1457 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 1457 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
1458 | return 0; | 1458 | return 0; |
1459 | 1459 | ||
1460 | }//else //debug only | 1460 | }//else //debug only |
1461 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 1461 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
1462 | } | 1462 | } |
1463 | int result; | 1463 | int result; |
1464 | bool localIsNew; | 1464 | bool localIsNew; |
1465 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); | 1465 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); |
1466 | 1466 | ||
1467 | 1467 | ||
1468 | // ************************************************ | 1468 | // ************************************************ |
1469 | // ************************************************ | 1469 | // ************************************************ |
1470 | // ************************************************ | 1470 | // ************************************************ |
1471 | // We may have that lastSync > remoteMod AND lastSync > localMod | 1471 | // We may have that lastSync > remoteMod AND lastSync > localMod |
1472 | // BUT remoteMod != localMod | 1472 | // BUT remoteMod != localMod |
1473 | 1473 | ||
1474 | 1474 | ||
1475 | if ( full && mode < SYNC_PREF_NEWEST ) | 1475 | if ( full && mode < SYNC_PREF_NEWEST ) |
1476 | mode = SYNC_PREF_ASK; | 1476 | mode = SYNC_PREF_ASK; |
1477 | 1477 | ||
1478 | switch( mode ) { | 1478 | switch( mode ) { |
1479 | case SYNC_PREF_LOCAL: | 1479 | case SYNC_PREF_LOCAL: |
1480 | if ( lastSync > remoteMod ) | 1480 | if ( lastSync > remoteMod ) |
1481 | return 1; | 1481 | return 1; |
1482 | if ( lastSync > localMod ) | 1482 | if ( lastSync > localMod ) |
1483 | return 2; | 1483 | return 2; |
1484 | return 1; | 1484 | return 1; |
1485 | break; | 1485 | break; |
1486 | case SYNC_PREF_REMOTE: | 1486 | case SYNC_PREF_REMOTE: |
1487 | if ( lastSync > localMod ) | 1487 | if ( lastSync > localMod ) |
1488 | return 2; | 1488 | return 2; |
1489 | if ( lastSync > remoteMod ) | 1489 | if ( lastSync > remoteMod ) |
1490 | return 1; | 1490 | return 1; |
1491 | return 2; | 1491 | return 2; |
1492 | break; | 1492 | break; |
1493 | case SYNC_PREF_NEWEST: | 1493 | case SYNC_PREF_NEWEST: |
1494 | if ( localMod >= remoteMod ) | 1494 | if ( localMod >= remoteMod ) |
1495 | return 1; | 1495 | return 1; |
1496 | else | 1496 | else |
1497 | return 2; | 1497 | return 2; |
1498 | break; | 1498 | break; |
1499 | case SYNC_PREF_ASK: | 1499 | case SYNC_PREF_ASK: |
1500 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1500 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1501 | if ( lastSync > remoteMod && lastSync > localMod) | 1501 | if ( lastSync > remoteMod && lastSync > localMod) |
1502 | return 0; | 1502 | return 0; |
1503 | if ( lastSync > remoteMod ) | 1503 | if ( lastSync > remoteMod ) |
1504 | return 1; | 1504 | return 1; |
1505 | if ( lastSync > localMod ) | 1505 | if ( lastSync > localMod ) |
1506 | return 2; | 1506 | return 2; |
1507 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1507 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1508 | localIsNew = localMod >= remoteMod; | 1508 | localIsNew = localMod >= remoteMod; |
1509 | if ( localIsNew ) | 1509 | if ( localIsNew ) |
1510 | getEventViewerDialog()->setColorMode( 1 ); | 1510 | getEventViewerDialog()->setColorMode( 1 ); |
1511 | else | 1511 | else |
1512 | getEventViewerDialog()->setColorMode( 2 ); | 1512 | getEventViewerDialog()->setColorMode( 2 ); |
1513 | getEventViewerDialog()->setIncidence(local); | 1513 | getEventViewerDialog()->setIncidence(local); |
1514 | if ( localIsNew ) | 1514 | if ( localIsNew ) |
1515 | getEventViewerDialog()->setColorMode( 2 ); | 1515 | getEventViewerDialog()->setColorMode( 2 ); |
1516 | else | 1516 | else |
1517 | getEventViewerDialog()->setColorMode( 1 ); | 1517 | getEventViewerDialog()->setColorMode( 1 ); |
1518 | getEventViewerDialog()->addIncidence(remote); | 1518 | getEventViewerDialog()->addIncidence(remote); |
1519 | getEventViewerDialog()->setColorMode( 0 ); | 1519 | getEventViewerDialog()->setColorMode( 0 ); |
1520 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 1520 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
1521 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 1521 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
1522 | getEventViewerDialog()->showMe(); | 1522 | getEventViewerDialog()->showMe(); |
1523 | result = getEventViewerDialog()->executeS( localIsNew ); | 1523 | result = getEventViewerDialog()->executeS( localIsNew ); |
1524 | return result; | 1524 | return result; |
1525 | 1525 | ||
1526 | break; | 1526 | break; |
1527 | case SYNC_PREF_FORCE_LOCAL: | 1527 | case SYNC_PREF_FORCE_LOCAL: |
1528 | return 1; | 1528 | return 1; |
1529 | break; | 1529 | break; |
1530 | case SYNC_PREF_FORCE_REMOTE: | 1530 | case SYNC_PREF_FORCE_REMOTE: |
1531 | return 2; | 1531 | return 2; |
1532 | break; | 1532 | break; |
1533 | 1533 | ||
1534 | default: | 1534 | default: |
1535 | // SYNC_PREF_TAKE_BOTH not implemented | 1535 | // SYNC_PREF_TAKE_BOTH not implemented |
1536 | break; | 1536 | break; |
1537 | } | 1537 | } |
1538 | return 0; | 1538 | return 0; |
1539 | } | 1539 | } |
1540 | Event* CalendarView::getLastSyncEvent() | 1540 | Event* CalendarView::getLastSyncEvent() |
1541 | { | 1541 | { |
1542 | Event* lse; | 1542 | Event* lse; |
1543 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 1543 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
1544 | mCalendar->setSyncEventsEnabled(); | 1544 | mCalendar->setSyncEventsEnabled(); |
1545 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 1545 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
1546 | if (!lse) { | 1546 | if (!lse) { |
1547 | qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() ); | 1547 | qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() ); |
1548 | lse = new Event(); | 1548 | lse = new Event(); |
1549 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 1549 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
1550 | QString sum = ""; | 1550 | QString sum = ""; |
1551 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 1551 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
1552 | sum = "E: "; | 1552 | sum = "E: "; |
1553 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 1553 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
1554 | lse->setDtStart( mLastCalendarSync ); | 1554 | lse->setDtStart( mLastCalendarSync ); |
1555 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1555 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1556 | lse->setCategories( i18n("SyncEvent") ); | 1556 | lse->setCategories( i18n("SyncEvent") ); |
1557 | lse->setReadOnly( true ); | 1557 | lse->setReadOnly( true ); |
1558 | lse->setCalID( 1 ); | 1558 | lse->setCalID( 1 ); |
1559 | mCalendar->addEvent( lse ); | 1559 | mCalendar->addEvent( lse ); |
1560 | } else | 1560 | } else |
1561 | qDebug("KO: Last Syncevent on local found"); | 1561 | qDebug("KO: Last Syncevent on local found"); |
1562 | 1562 | ||
1563 | return lse; | 1563 | return lse; |
1564 | 1564 | ||
1565 | } | 1565 | } |
1566 | 1566 | ||
1567 | // we check, if the to delete event has a id for a profile | 1567 | // we check, if the to delete event has a id for a profile |
1568 | // if yes, we set this id in the profile to delete | 1568 | // if yes, we set this id in the profile to delete |
1569 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 1569 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
1570 | { | 1570 | { |
1571 | if ( lastSync.count() == 0 ) { | 1571 | if ( lastSync.count() == 0 ) { |
1572 | //qDebug(" lastSync.count() == 0"); | 1572 | //qDebug(" lastSync.count() == 0"); |
1573 | return; | 1573 | return; |
1574 | } | 1574 | } |
1575 | if ( toDelete->typeID() == journalID ) | 1575 | if ( toDelete->typeID() == journalID ) |
1576 | return; | 1576 | return; |
1577 | 1577 | ||
1578 | Event* eve = lastSync.first(); | 1578 | Event* eve = lastSync.first(); |
1579 | 1579 | ||
1580 | while ( eve ) { | 1580 | while ( eve ) { |
1581 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 1581 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
1582 | if ( !id.isEmpty() ) { | 1582 | if ( !id.isEmpty() ) { |
1583 | QString des = eve->description(); | 1583 | QString des = eve->description(); |
1584 | QString pref = "e"; | 1584 | QString pref = "e"; |
1585 | if ( toDelete->typeID() == todoID ) | 1585 | if ( toDelete->typeID() == todoID ) |
1586 | pref = "t"; | 1586 | pref = "t"; |
1587 | des += pref+ id + ","; | 1587 | des += pref+ id + ","; |
1588 | eve->setReadOnly( false ); | 1588 | eve->setReadOnly( false ); |
1589 | eve->setDescription( des ); | 1589 | eve->setDescription( des ); |
1590 | //qDebug("setdes %s ", des.latin1()); | 1590 | //qDebug("setdes %s ", des.latin1()); |
1591 | eve->setReadOnly( true ); | 1591 | eve->setReadOnly( true ); |
1592 | } | 1592 | } |
1593 | eve = lastSync.next(); | 1593 | eve = lastSync.next(); |
1594 | } | 1594 | } |
1595 | 1595 | ||
1596 | } | 1596 | } |
1597 | void CalendarView::checkExternalId( Incidence * inc ) | 1597 | void CalendarView::checkExternalId( Incidence * inc ) |
1598 | { | 1598 | { |
1599 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 1599 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
1600 | checkExternSyncEvent( lastSync, inc ); | 1600 | checkExternSyncEvent( lastSync, inc ); |
1601 | 1601 | ||
1602 | } | 1602 | } |
1603 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 1603 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
1604 | { | 1604 | { |
1605 | bool syncOK = true; | 1605 | bool syncOK = true; |
1606 | int addedEvent = 0; | 1606 | int addedEvent = 0; |
1607 | int addedEventR = 0; | 1607 | int addedEventR = 0; |
1608 | int deletedEventR = 0; | 1608 | int deletedEventR = 0; |
1609 | int deletedEventL = 0; | 1609 | int deletedEventL = 0; |
1610 | int changedLocal = 0; | 1610 | int changedLocal = 0; |
1611 | int changedRemote = 0; | 1611 | int changedRemote = 0; |
1612 | int filteredIN = 0; | 1612 | int filteredIN = 0; |
1613 | int filteredOUT = 0; | 1613 | int filteredOUT = 0; |
1614 | //QPtrList<Event> el = local->rawEvents(); | 1614 | //QPtrList<Event> el = local->rawEvents(); |
1615 | Event* eventR; | 1615 | Event* eventR; |
1616 | QString uid; | 1616 | QString uid; |
1617 | int take; | 1617 | int take; |
1618 | Event* eventRSync; | 1618 | Event* eventRSync; |
1619 | Event* eventLSync; | 1619 | Event* eventLSync; |
1620 | clearAllViews(); | 1620 | clearAllViews(); |
1621 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 1621 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
1622 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 1622 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
1623 | bool fullDateRange = false; | 1623 | bool fullDateRange = false; |
1624 | local->resetTempSyncStat(); | 1624 | local->resetTempSyncStat(); |
1625 | mLastCalendarSync = QDateTime::currentDateTime(); | 1625 | mLastCalendarSync = QDateTime::currentDateTime(); |
1626 | if ( mSyncManager->syncWithDesktop() ) { | 1626 | if ( mSyncManager->syncWithDesktop() ) { |
1627 | remote->resetPilotStat(1); | 1627 | remote->resetPilotStat(1); |
1628 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1628 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1629 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; | 1629 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; |
1630 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); | 1630 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); |
1631 | } else { | 1631 | } else { |
1632 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 1632 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
1633 | } | 1633 | } |
1634 | } | 1634 | } |
1635 | QDateTime modifiedCalendar = mLastCalendarSync; | 1635 | QDateTime modifiedCalendar = mLastCalendarSync; |
1636 | eventLSync = getLastSyncEvent(); | 1636 | eventLSync = getLastSyncEvent(); |
1637 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 1637 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
1638 | if ( eventR ) { | 1638 | if ( eventR ) { |
1639 | qDebug("KO: Last-syncEvent on remote found "); | 1639 | qDebug("KO: Last-syncEvent on remote found "); |
1640 | eventRSync = (Event*) eventR->clone(); | 1640 | eventRSync = (Event*) eventR->clone(); |
1641 | remote->deleteEvent(eventR ); | 1641 | remote->deleteEvent(eventR ); |
1642 | 1642 | ||
1643 | } else { | 1643 | } else { |
1644 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { | 1644 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { |
1645 | eventRSync = (Event*)eventLSync->clone(); | 1645 | eventRSync = (Event*)eventLSync->clone(); |
1646 | } else { | 1646 | } else { |
1647 | fullDateRange = true; | 1647 | fullDateRange = true; |
1648 | eventRSync = new Event(); | 1648 | eventRSync = new Event(); |
1649 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 1649 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
1650 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 1650 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
1651 | eventRSync->setDtStart( mLastCalendarSync ); | 1651 | eventRSync->setDtStart( mLastCalendarSync ); |
1652 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1652 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1653 | eventRSync->setCategories( i18n("SyncEvent") ); | 1653 | eventRSync->setCategories( i18n("SyncEvent") ); |
1654 | } | 1654 | } |
1655 | } | 1655 | } |
1656 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 1656 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
1657 | fullDateRange = true; | 1657 | fullDateRange = true; |
1658 | 1658 | ||
1659 | if ( ! fullDateRange ) { | 1659 | if ( ! fullDateRange ) { |
1660 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 1660 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
1661 | 1661 | ||
1662 | qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 1662 | qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
1663 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 1663 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
1664 | fullDateRange = true; | 1664 | fullDateRange = true; |
1665 | } | 1665 | } |
1666 | } | 1666 | } |
1667 | if ( mSyncManager->syncWithDesktop() ) { | 1667 | if ( mSyncManager->syncWithDesktop() ) { |
1668 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); | 1668 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); |
1669 | } | 1669 | } |
1670 | if ( fullDateRange ) | 1670 | if ( fullDateRange ) |
1671 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 1671 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
1672 | else | 1672 | else |
1673 | mLastCalendarSync = eventLSync->dtStart(); | 1673 | mLastCalendarSync = eventLSync->dtStart(); |
1674 | // for resyncing if own file has changed | 1674 | // for resyncing if own file has changed |
1675 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 1675 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
1676 | mLastCalendarSync = loadedFileVersion; | 1676 | mLastCalendarSync = loadedFileVersion; |
1677 | //qDebug("setting mLastCalendarSync "); | 1677 | //qDebug("setting mLastCalendarSync "); |
1678 | } | 1678 | } |
1679 | //qDebug("*************************** "); | 1679 | //qDebug("*************************** "); |
1680 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); | 1680 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); |
1681 | QPtrList<Incidence> er = remote->rawIncidences(); | 1681 | QPtrList<Incidence> er = remote->rawIncidences(); |
1682 | Incidence* inR = er.first(); | 1682 | Incidence* inR = er.first(); |
1683 | Incidence* inL; | 1683 | Incidence* inL; |
1684 | QProgressBar bar( er.count(),0 ); | 1684 | QProgressBar bar( er.count(),0 ); |
1685 | bar.setCaption (i18n("Syncing - close to abort!") ); | 1685 | bar.setCaption (i18n("Syncing - close to abort!") ); |
1686 | 1686 | ||
1687 | // ************** setting up filter ************* | 1687 | // ************** setting up filter ************* |
1688 | CalFilter *filterIN = 0; | 1688 | CalFilter *filterIN = 0; |
1689 | CalFilter *filterOUT = 0; | 1689 | CalFilter *filterOUT = 0; |
1690 | CalFilter *filter = mFilters.first(); | 1690 | CalFilter *filter = mFilters.first(); |
1691 | while(filter) { | 1691 | while(filter) { |
1692 | if ( filter->name() == mSyncManager->mFilterInCal ) | 1692 | if ( filter->name() == mSyncManager->mFilterInCal ) |
1693 | filterIN = filter; | 1693 | filterIN = filter; |
1694 | if ( filter->name() == mSyncManager->mFilterOutCal ) | 1694 | if ( filter->name() == mSyncManager->mFilterOutCal ) |
1695 | filterOUT = filter; | 1695 | filterOUT = filter; |
1696 | filter = mFilters.next(); | 1696 | filter = mFilters.next(); |
1697 | } | 1697 | } |
1698 | int w = 300; | 1698 | int w = 300; |
1699 | if ( QApplication::desktop()->width() < 320 ) | 1699 | if ( QApplication::desktop()->width() < 320 ) |
1700 | w = 220; | 1700 | w = 220; |
1701 | int h = bar.sizeHint().height() ; | 1701 | int h = bar.sizeHint().height() ; |
1702 | int dw = QApplication::desktop()->width(); | 1702 | int dw = QApplication::desktop()->width(); |
1703 | int dh = QApplication::desktop()->height(); | 1703 | int dh = QApplication::desktop()->height(); |
1704 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1704 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1705 | bar.show(); | 1705 | bar.show(); |
1706 | int modulo = (er.count()/10)+1; | 1706 | int modulo = (er.count()/10)+1; |
1707 | int incCounter = 0; | 1707 | int incCounter = 0; |
1708 | while ( inR ) { | 1708 | while ( inR ) { |
1709 | if ( ! bar.isVisible() ) | 1709 | if ( ! bar.isVisible() ) |
1710 | return false; | 1710 | return false; |
1711 | if ( incCounter % modulo == 0 ) | 1711 | if ( incCounter % modulo == 0 ) |
1712 | bar.setProgress( incCounter ); | 1712 | bar.setProgress( incCounter ); |
1713 | ++incCounter; | 1713 | ++incCounter; |
1714 | uid = inR->uid(); | 1714 | uid = inR->uid(); |
1715 | bool skipIncidence = false; | 1715 | bool skipIncidence = false; |
1716 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1716 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1717 | skipIncidence = true; | 1717 | skipIncidence = true; |
1718 | QString idS; | 1718 | QString idS; |
1719 | qApp->processEvents(); | 1719 | qApp->processEvents(); |
1720 | if ( !skipIncidence ) { | 1720 | if ( !skipIncidence ) { |
1721 | inL = local->incidenceForUid( uid , false ); | 1721 | inL = local->incidenceForUid( uid , false , true ); |
1722 | if ( inL ) { // maybe conflict - same uid in both calendars | 1722 | if ( inL ) { // maybe conflict - same uid in both calendars |
1723 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1723 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1724 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1724 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1725 | if ( take == 3 ) | 1725 | if ( take == 3 ) |
1726 | return false; | 1726 | return false; |
1727 | if ( take == 1 ) {// take local ********************** | 1727 | if ( take == 1 ) {// take local ********************** |
1728 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1728 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1729 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1729 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1730 | else | 1730 | else |
1731 | idS = inR->IDStr(); | 1731 | idS = inR->IDStr(); |
1732 | int calID = inR->calID(); | 1732 | int calID = inR->calID(); |
1733 | remote->deleteIncidence( inR ); | 1733 | remote->deleteIncidence( inR ); |
1734 | inR = inL->clone(); | 1734 | inR = inL->clone(); |
1735 | inR->setCalID( calID ); | 1735 | inR->setCalID( calID ); |
1736 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1736 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1737 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1737 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1738 | inR->setIDStr( idS ); | 1738 | inR->setIDStr( idS ); |
1739 | remote->addIncidence( inR ); | 1739 | remote->addIncidence( inR ); |
1740 | if ( mSyncManager->syncWithDesktop() ) | 1740 | if ( mSyncManager->syncWithDesktop() ) |
1741 | inR->setPilotId( 2 ); | 1741 | inR->setPilotId( 2 ); |
1742 | ++changedRemote; | 1742 | ++changedRemote; |
1743 | } else {// take remote ********************** | 1743 | } else {// take remote ********************** |
1744 | if ( !inL->isReadOnly() ) { | 1744 | if ( !inL->isReadOnly() ) { |
1745 | idS = inL->IDStr(); | 1745 | idS = inL->IDStr(); |
1746 | int pid = inL->pilotId(); | 1746 | int pid = inL->pilotId(); |
1747 | int calID = inL->calID(); | 1747 | int calID = inL->calID(); |
1748 | local->deleteIncidence( inL ); | 1748 | local->deleteIncidence( inL ); |
1749 | inL = inR->clone(); | 1749 | inL = inR->clone(); |
1750 | inL->setCalID( calID ); | 1750 | inL->setCalID( calID ); |
1751 | if ( mSyncManager->syncWithDesktop() ) | 1751 | if ( mSyncManager->syncWithDesktop() ) |
1752 | inL->setPilotId( pid ); | 1752 | inL->setPilotId( pid ); |
1753 | inL->setIDStr( idS ); | 1753 | inL->setIDStr( idS ); |
1754 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1754 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1755 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1755 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1756 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1756 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1757 | } | 1757 | } |
1758 | local->addIncidence( inL ); | 1758 | local->addIncidence( inL ); |
1759 | ++changedLocal; | 1759 | ++changedLocal; |
1760 | } | 1760 | } |
1761 | } | 1761 | } |
1762 | } | 1762 | } |
1763 | } else { // no conflict ********** add or delete remote | 1763 | } else { // no conflict ********** add or delete remote |
1764 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1764 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1765 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1765 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1766 | QString des = eventLSync->description(); | 1766 | QString des = eventLSync->description(); |
1767 | QString pref = "e"; | 1767 | QString pref = "e"; |
1768 | if ( inR->typeID() == todoID ) | 1768 | if ( inR->typeID() == todoID ) |
1769 | pref = "t"; | 1769 | pref = "t"; |
1770 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1770 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1771 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1771 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1772 | //remote->deleteIncidence( inR ); | 1772 | //remote->deleteIncidence( inR ); |
1773 | ++deletedEventR; | 1773 | ++deletedEventR; |
1774 | } else { | 1774 | } else { |
1775 | inR->setLastModified( modifiedCalendar ); | 1775 | inR->setLastModified( modifiedCalendar ); |
1776 | inL = inR->clone(); | 1776 | inL = inR->clone(); |
1777 | inL->setIDStr( ":" ); | 1777 | inL->setIDStr( ":" ); |
1778 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1778 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1779 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1779 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1780 | 1780 | ||
1781 | inL->setCalID( 0 );// add to default cal | 1781 | inL->setCalID( 0 );// add to default cal |
1782 | local->addIncidence( inL ); | 1782 | local->addIncidence( inL ); |
1783 | ++addedEvent; | 1783 | ++addedEvent; |
1784 | 1784 | ||
1785 | } | 1785 | } |
1786 | } else { | 1786 | } else { |
1787 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1787 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1788 | inR->setLastModified( modifiedCalendar ); | 1788 | inR->setLastModified( modifiedCalendar ); |
1789 | inL = inR->clone(); | 1789 | inL = inR->clone(); |
1790 | inL->setIDStr( ":" ); | 1790 | inL->setIDStr( ":" ); |
1791 | inL->setCalID( 0 );// add to default cal | 1791 | inL->setCalID( 0 );// add to default cal |
1792 | local->addIncidence( inL ); | 1792 | local->addIncidence( inL ); |
1793 | ++addedEvent; | 1793 | ++addedEvent; |
1794 | 1794 | ||
1795 | } else { | 1795 | } else { |
1796 | checkExternSyncEvent(eventRSyncSharp, inR); | 1796 | checkExternSyncEvent(eventRSyncSharp, inR); |
1797 | remote->deleteIncidence( inR ); | 1797 | remote->deleteIncidence( inR ); |
1798 | ++deletedEventR; | 1798 | ++deletedEventR; |
1799 | } | 1799 | } |
1800 | } | 1800 | } |
1801 | } else { | 1801 | } else { |
1802 | ++filteredIN; | 1802 | ++filteredIN; |
1803 | } | 1803 | } |
1804 | } | 1804 | } |
1805 | } | 1805 | } |
1806 | inR = er.next(); | 1806 | inR = er.next(); |
1807 | } | 1807 | } |
1808 | QPtrList<Incidence> el = local->rawIncidences(); | 1808 | QPtrList<Incidence> el = local->rawIncidences(); |
1809 | inL = el.first(); | 1809 | inL = el.first(); |
1810 | modulo = (el.count()/10)+1; | 1810 | modulo = (el.count()/10)+1; |
1811 | bar.setCaption (i18n("Add / remove events") ); | 1811 | bar.setCaption (i18n("Add / remove events") ); |
1812 | bar.setTotalSteps ( el.count() ) ; | 1812 | bar.setTotalSteps ( el.count() ) ; |
1813 | bar.show(); | 1813 | bar.show(); |
1814 | incCounter = 0; | 1814 | incCounter = 0; |
1815 | 1815 | ||
1816 | while ( inL ) { | 1816 | while ( inL ) { |
1817 | 1817 | ||
1818 | qApp->processEvents(); | 1818 | qApp->processEvents(); |
1819 | if ( ! bar.isVisible() ) | 1819 | if ( ! bar.isVisible() ) |
1820 | return false; | 1820 | return false; |
1821 | if ( incCounter % modulo == 0 ) | 1821 | if ( incCounter % modulo == 0 ) |
1822 | bar.setProgress( incCounter ); | 1822 | bar.setProgress( incCounter ); |
1823 | ++incCounter; | 1823 | ++incCounter; |
1824 | uid = inL->uid(); | 1824 | uid = inL->uid(); |
1825 | bool skipIncidence = false; | 1825 | bool skipIncidence = false; |
1826 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1826 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1827 | skipIncidence = true; | 1827 | skipIncidence = true; |
1828 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) | 1828 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) |
1829 | skipIncidence = true; | 1829 | skipIncidence = true; |
1830 | if ( !skipIncidence ) { | 1830 | if ( !skipIncidence ) { |
1831 | inR = remote->incidenceForUid( uid , true ); | 1831 | inR = remote->incidenceForUid( uid , true, true ); |
1832 | if ( ! inR ) { | 1832 | if ( ! inR ) { |
1833 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ | 1833 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ |
1834 | // no conflict ********** add or delete local | 1834 | // no conflict ********** add or delete local |
1835 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1835 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1836 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1836 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1837 | checkExternSyncEvent(eventLSyncSharp, inL); | 1837 | checkExternSyncEvent(eventLSyncSharp, inL); |
1838 | local->deleteIncidence( inL ); | 1838 | local->deleteIncidence( inL ); |
1839 | ++deletedEventL; | 1839 | ++deletedEventL; |
1840 | } else { | 1840 | } else { |
1841 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1841 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1842 | inL->removeID(mCurrentSyncDevice ); | 1842 | inL->removeID(mCurrentSyncDevice ); |
1843 | ++addedEventR; | 1843 | ++addedEventR; |
1844 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1844 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1845 | inL->setLastModified( modifiedCalendar ); | 1845 | inL->setLastModified( modifiedCalendar ); |
1846 | inR = inL->clone(); | 1846 | inR = inL->clone(); |
1847 | inR->setIDStr( ":" ); | 1847 | inR->setIDStr( ":" ); |
1848 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1848 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1849 | inR->setCalID( 0 );// add to default cal | 1849 | inR->setCalID( 0 );// add to default cal |
1850 | remote->addIncidence( inR ); | 1850 | remote->addIncidence( inR ); |
1851 | } | 1851 | } |
1852 | } | 1852 | } |
1853 | } else { | 1853 | } else { |
1854 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1854 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1855 | checkExternSyncEvent(eventLSyncSharp, inL); | 1855 | checkExternSyncEvent(eventLSyncSharp, inL); |
1856 | local->deleteIncidence( inL ); | 1856 | local->deleteIncidence( inL ); |
1857 | ++deletedEventL; | 1857 | ++deletedEventL; |
1858 | } else { | 1858 | } else { |
1859 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1859 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1860 | ++addedEventR; | 1860 | ++addedEventR; |
1861 | inL->setLastModified( modifiedCalendar ); | 1861 | inL->setLastModified( modifiedCalendar ); |
1862 | inR = inL->clone(); | 1862 | inR = inL->clone(); |
1863 | inR->setIDStr( ":" ); | 1863 | inR->setIDStr( ":" ); |
1864 | inR->setCalID( 0 );// add to default cal | 1864 | inR->setCalID( 0 );// add to default cal |
1865 | remote->addIncidence( inR ); | 1865 | remote->addIncidence( inR ); |
1866 | } | 1866 | } |
1867 | } | 1867 | } |
1868 | } | 1868 | } |
1869 | } else { | 1869 | } else { |
1870 | ++filteredOUT; | 1870 | ++filteredOUT; |
1871 | } | 1871 | } |
1872 | } | 1872 | } |
1873 | } | 1873 | } |
1874 | inL = el.next(); | 1874 | inL = el.next(); |
1875 | } | 1875 | } |
1876 | int delFut = 0; | 1876 | int delFut = 0; |
1877 | int remRem = 0; | 1877 | int remRem = 0; |
1878 | if ( mSyncManager->mWriteBackInFuture ) { | 1878 | if ( mSyncManager->mWriteBackInFuture ) { |
1879 | er = remote->rawIncidences(); | 1879 | er = remote->rawIncidences(); |
1880 | remRem = er.count(); | 1880 | remRem = er.count(); |
1881 | inR = er.first(); | 1881 | inR = er.first(); |
1882 | QDateTime dt; | 1882 | QDateTime dt; |
1883 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); | 1883 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); |
1884 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); | 1884 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); |
1885 | while ( inR ) { | 1885 | while ( inR ) { |
1886 | if ( inR->typeID() == todoID ) { | 1886 | if ( inR->typeID() == todoID ) { |
1887 | Todo * t = (Todo*)inR; | 1887 | Todo * t = (Todo*)inR; |
1888 | if ( t->hasDueDate() ) | 1888 | if ( t->hasDueDate() ) |
1889 | dt = t->dtDue(); | 1889 | dt = t->dtDue(); |
1890 | else | 1890 | else |
1891 | dt = cur.addSecs( 62 ); | 1891 | dt = cur.addSecs( 62 ); |
1892 | } | 1892 | } |
1893 | else if (inR->typeID() == eventID ) { | 1893 | else if (inR->typeID() == eventID ) { |
1894 | bool ok; | 1894 | bool ok; |
1895 | dt = inR->getNextOccurence( cur, &ok ); | 1895 | dt = inR->getNextOccurence( cur, &ok ); |
1896 | if ( !ok ) | 1896 | if ( !ok ) |
1897 | dt = cur.addSecs( -62 ); | 1897 | dt = cur.addSecs( -62 ); |
1898 | } | 1898 | } |
1899 | else | 1899 | else |
1900 | dt = inR->dtStart(); | 1900 | dt = inR->dtStart(); |
1901 | if ( dt < cur || dt > end ) { | 1901 | if ( dt < cur || dt > end ) { |
1902 | remote->deleteIncidence( inR ); | 1902 | remote->deleteIncidence( inR ); |
1903 | ++delFut; | 1903 | ++delFut; |
1904 | } | 1904 | } |
1905 | inR = er.next(); | 1905 | inR = er.next(); |
1906 | } | 1906 | } |
1907 | } | 1907 | } |
1908 | bar.hide(); | 1908 | bar.hide(); |
1909 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1909 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1910 | if ( mMultiResourceSync ) { | 1910 | if ( mMultiResourceSync ) { |
1911 | remote->removeSyncInfo( "" ); //all | 1911 | remote->removeSyncInfo( "" ); //all |
1912 | qDebug("KO: Remoing all sync info on remote "); | 1912 | qDebug("KO: Remoing all sync info on remote "); |
1913 | } else { | 1913 | } else { |
1914 | eventLSync->setReadOnly( false ); | 1914 | eventLSync->setReadOnly( false ); |
1915 | eventLSync->setDtStart( mLastCalendarSync ); | 1915 | eventLSync->setDtStart( mLastCalendarSync ); |
1916 | eventRSync->setDtStart( mLastCalendarSync ); | 1916 | eventRSync->setDtStart( mLastCalendarSync ); |
1917 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1917 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1918 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1918 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1919 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1919 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1920 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1920 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1921 | eventLSync->setReadOnly( true ); | 1921 | eventLSync->setReadOnly( true ); |
1922 | } | 1922 | } |
1923 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); | 1923 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); |
1924 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... | 1924 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... |
1925 | remote->addEvent( eventRSync ); | 1925 | remote->addEvent( eventRSync ); |
1926 | else | 1926 | else |
1927 | delete eventRSync; | 1927 | delete eventRSync; |
1928 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); | 1928 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); |
1929 | QString mes; | 1929 | QString mes; |
1930 | 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); | 1930 | 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 %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); |
1931 | QString delmess; | 1931 | QString delmess; |
1932 | if ( delFut ) { | 1932 | if ( delFut ) { |
1933 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); | 1933 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); |
1934 | mes += delmess; | 1934 | mes += delmess; |
1935 | } | 1935 | } |
1936 | mes = i18n("Local calendar changed!\n") +mes; | 1936 | mes = i18n("Local calendar changed!\n") +mes; |
1937 | mCalendar->checkAlarmForIncidence( 0, true ); | 1937 | mCalendar->checkAlarmForIncidence( 0, true ); |
1938 | qDebug( mes ); | 1938 | qDebug( mes ); |
1939 | if ( mSyncManager->mShowSyncSummary ) { | 1939 | if ( mSyncManager->mShowSyncSummary ) { |
1940 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 1940 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
1941 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { | 1941 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { |
1942 | qDebug("KO: WB cancelled "); | 1942 | qDebug("KO: WB cancelled "); |
1943 | mSyncManager->mWriteBackFile = false; | 1943 | mSyncManager->mWriteBackFile = false; |
1944 | return syncOK; | 1944 | return syncOK; |
1945 | } | 1945 | } |
1946 | } | 1946 | } |
1947 | return syncOK; | 1947 | return syncOK; |
1948 | } | 1948 | } |
1949 | 1949 | ||
1950 | void CalendarView::setSyncDevice( QString s ) | 1950 | void CalendarView::setSyncDevice( QString s ) |
1951 | { | 1951 | { |
1952 | mCurrentSyncDevice= s; | 1952 | mCurrentSyncDevice= s; |
1953 | } | 1953 | } |
1954 | void CalendarView::setSyncName( QString s ) | 1954 | void CalendarView::setSyncName( QString s ) |
1955 | { | 1955 | { |
1956 | mCurrentSyncName= s; | 1956 | mCurrentSyncName= s; |
1957 | } | 1957 | } |
1958 | bool CalendarView::syncCalendar(QString filename, int mode) | 1958 | bool CalendarView::syncCalendar(QString filename, int mode) |
1959 | { | 1959 | { |
1960 | //qDebug("syncCalendar %s ", filename.latin1()); | 1960 | //qDebug("syncCalendar %s ", filename.latin1()); |
1961 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1961 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1962 | CalendarLocal* calendar = new CalendarLocal(); | 1962 | CalendarLocal* calendar = new CalendarLocal(); |
1963 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1963 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1964 | FileStorage* storage = new FileStorage( calendar ); | 1964 | FileStorage* storage = new FileStorage( calendar ); |
1965 | bool syncOK = false; | 1965 | bool syncOK = false; |
1966 | storage->setFileName( filename ); | 1966 | storage->setFileName( filename ); |
1967 | // qDebug("loading ... "); | 1967 | // qDebug("loading ... "); |
1968 | if ( storage->load() ) { | 1968 | if ( storage->load() ) { |
1969 | getEventViewerDialog()->setSyncMode( true ); | 1969 | getEventViewerDialog()->setSyncMode( true ); |
1970 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1970 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1971 | getEventViewerDialog()->setSyncMode( false ); | 1971 | getEventViewerDialog()->setSyncMode( false ); |
1972 | if ( syncOK ) { | 1972 | if ( syncOK ) { |
1973 | if ( mSyncManager->mWriteBackFile ) | 1973 | if ( mSyncManager->mWriteBackFile ) |
1974 | { | 1974 | { |
1975 | storage->setSaveFormat( new ICalFormat() ); | 1975 | storage->setSaveFormat( new ICalFormat() ); |
1976 | storage->save(); | 1976 | storage->save(); |
1977 | } | 1977 | } |
1978 | } | 1978 | } |
1979 | setModified( true ); | 1979 | setModified( true ); |
1980 | } | 1980 | } |
1981 | delete storage; | 1981 | delete storage; |
1982 | delete calendar; | 1982 | delete calendar; |
1983 | if ( syncOK ) | 1983 | if ( syncOK ) |
1984 | updateView(); | 1984 | updateView(); |
1985 | return syncOK; | 1985 | return syncOK; |
1986 | } | 1986 | } |
1987 | 1987 | ||
1988 | void CalendarView::syncExternal( int mode ) | 1988 | void CalendarView::syncExternal( int mode ) |
1989 | { | 1989 | { |
1990 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1990 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1991 | qApp->processEvents(); | 1991 | qApp->processEvents(); |
1992 | CalendarLocal* calendar = new CalendarLocal(); | 1992 | CalendarLocal* calendar = new CalendarLocal(); |
1993 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1993 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1994 | bool syncOK = false; | 1994 | bool syncOK = false; |
1995 | bool loadSuccess = false; | 1995 | bool loadSuccess = false; |
1996 | PhoneFormat* phoneFormat = 0; | 1996 | PhoneFormat* phoneFormat = 0; |
1997 | emit tempDisableBR(true); | 1997 | emit tempDisableBR(true); |
1998 | #ifndef DESKTOP_VERSION | 1998 | #ifndef DESKTOP_VERSION |
1999 | SharpFormat* sharpFormat = 0; | 1999 | SharpFormat* sharpFormat = 0; |
2000 | if ( mode == 0 ) { // sharp | 2000 | if ( mode == 0 ) { // sharp |
2001 | sharpFormat = new SharpFormat () ; | 2001 | sharpFormat = new SharpFormat () ; |
2002 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 2002 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
2003 | 2003 | ||
2004 | } else | 2004 | } else |
2005 | #endif | 2005 | #endif |
2006 | if ( mode == 1 ) { // phone | 2006 | if ( mode == 1 ) { // phone |
2007 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 2007 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
2008 | mSyncManager->mPhoneDevice, | 2008 | mSyncManager->mPhoneDevice, |
2009 | mSyncManager->mPhoneConnection, | 2009 | mSyncManager->mPhoneConnection, |
2010 | mSyncManager->mPhoneModel); | 2010 | mSyncManager->mPhoneModel); |
2011 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 2011 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
2012 | 2012 | ||
2013 | } else { | 2013 | } else { |
2014 | emit tempDisableBR(false); | 2014 | emit tempDisableBR(false); |
2015 | return; | 2015 | return; |
2016 | } | 2016 | } |
2017 | if ( loadSuccess ) { | 2017 | if ( loadSuccess ) { |
2018 | getEventViewerDialog()->setSyncMode( true ); | 2018 | getEventViewerDialog()->setSyncMode( true ); |
2019 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 2019 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
2020 | getEventViewerDialog()->setSyncMode( false ); | 2020 | getEventViewerDialog()->setSyncMode( false ); |
2021 | qApp->processEvents(); | 2021 | qApp->processEvents(); |
2022 | if ( syncOK ) { | 2022 | if ( syncOK ) { |
2023 | if ( mSyncManager->mWriteBackFile ) | 2023 | if ( mSyncManager->mWriteBackFile ) |
2024 | { | 2024 | { |
2025 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 2025 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
2026 | Incidence* inc = iL.first(); | 2026 | Incidence* inc = iL.first(); |
2027 | if ( phoneFormat ) { | 2027 | if ( phoneFormat ) { |
2028 | while ( inc ) { | 2028 | while ( inc ) { |
2029 | inc->removeID(mCurrentSyncDevice); | 2029 | inc->removeID(mCurrentSyncDevice); |
2030 | inc = iL.next(); | 2030 | inc = iL.next(); |
2031 | } | 2031 | } |
2032 | } | 2032 | } |
2033 | #ifndef DESKTOP_VERSION | 2033 | #ifndef DESKTOP_VERSION |
2034 | if ( sharpFormat ) | 2034 | if ( sharpFormat ) |
2035 | sharpFormat->save(calendar); | 2035 | sharpFormat->save(calendar); |
2036 | #endif | 2036 | #endif |
2037 | if ( phoneFormat ) | 2037 | if ( phoneFormat ) |
2038 | phoneFormat->save(calendar); | 2038 | phoneFormat->save(calendar); |
2039 | iL = calendar->rawIncidences(); | 2039 | iL = calendar->rawIncidences(); |
2040 | inc = iL.first(); | 2040 | inc = iL.first(); |
2041 | Incidence* loc; | 2041 | Incidence* loc; |
2042 | while ( inc ) { | 2042 | while ( inc ) { |
2043 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 2043 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
2044 | loc = mCalendar->incidence(inc->uid() ); | 2044 | loc = mCalendar->incidence(inc->uid() ); |
2045 | if ( loc ) { | 2045 | if ( loc ) { |
2046 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 2046 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
2047 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 2047 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
2048 | } | 2048 | } |
2049 | } | 2049 | } |
2050 | inc = iL.next(); | 2050 | inc = iL.next(); |
2051 | } | 2051 | } |
2052 | Incidence* lse = getLastSyncEvent(); | 2052 | Incidence* lse = getLastSyncEvent(); |
2053 | if ( lse ) { | 2053 | if ( lse ) { |
2054 | lse->setReadOnly( false ); | 2054 | lse->setReadOnly( false ); |
2055 | lse->setDescription( "" ); | 2055 | lse->setDescription( "" ); |
2056 | lse->setReadOnly( true ); | 2056 | lse->setReadOnly( true ); |
2057 | } | 2057 | } |
2058 | } | 2058 | } |
2059 | } else { | 2059 | } else { |
2060 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 2060 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
2061 | } | 2061 | } |
2062 | setModified( true ); | 2062 | setModified( true ); |
2063 | } else { | 2063 | } else { |
2064 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 2064 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
2065 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 2065 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
2066 | question, i18n("Ok")) ; | 2066 | question, i18n("Ok")) ; |
2067 | 2067 | ||
2068 | } | 2068 | } |
2069 | delete calendar; | 2069 | delete calendar; |
2070 | updateView(); | 2070 | updateView(); |
2071 | emit tempDisableBR(false); | 2071 | emit tempDisableBR(false); |
2072 | return ;//syncOK; | 2072 | return ;//syncOK; |
2073 | 2073 | ||
2074 | } | 2074 | } |
2075 | 2075 | ||
2076 | bool CalendarView::importBday() | 2076 | bool CalendarView::importBday() |
2077 | { | 2077 | { |
2078 | #ifndef KORG_NOKABC | 2078 | #ifndef KORG_NOKABC |
2079 | 2079 | ||
2080 | #ifdef DESKTOP_VERSION | 2080 | #ifdef DESKTOP_VERSION |
2081 | int curCal = mCalendar->defaultCalendar(); | 2081 | int curCal = mCalendar->defaultCalendar(); |
2082 | int bd = mCalEditView->getBirtdayID(); | 2082 | int bd = mCalEditView->getBirtdayID(); |
2083 | if ( bd == 0 ) | 2083 | if ( bd == 0 ) |
2084 | return false; | 2084 | return false; |
2085 | mCalendar->setDefaultCalendar( bd ); | 2085 | mCalendar->setDefaultCalendar( bd ); |
2086 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 2086 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
2087 | KABC::AddressBook::Iterator it; | 2087 | KABC::AddressBook::Iterator it; |
2088 | int count = 0; | 2088 | int count = 0; |
2089 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 2089 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
2090 | ++count; | 2090 | ++count; |
2091 | } | 2091 | } |
2092 | QProgressBar bar(count,0 ); | 2092 | QProgressBar bar(count,0 ); |
2093 | int w = 300; | 2093 | int w = 300; |
2094 | if ( QApplication::desktop()->width() < 320 ) | 2094 | if ( QApplication::desktop()->width() < 320 ) |
2095 | w = 220; | 2095 | w = 220; |
2096 | int h = bar.sizeHint().height() ; | 2096 | int h = bar.sizeHint().height() ; |
2097 | int dw = QApplication::desktop()->width(); | 2097 | int dw = QApplication::desktop()->width(); |
2098 | int dh = QApplication::desktop()->height(); | 2098 | int dh = QApplication::desktop()->height(); |
2099 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2099 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2100 | bar.show(); | 2100 | bar.show(); |
2101 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 2101 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
2102 | qApp->processEvents(); | 2102 | qApp->processEvents(); |
2103 | count = 0; | 2103 | count = 0; |
2104 | int addCount = 0; | 2104 | int addCount = 0; |
2105 | KCal::Attendee* a = 0; | 2105 | KCal::Attendee* a = 0; |
2106 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 2106 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
2107 | if ( ! bar.isVisible() ) | 2107 | if ( ! bar.isVisible() ) |
2108 | return false; | 2108 | return false; |
2109 | bar.setProgress( count++ ); | 2109 | bar.setProgress( count++ ); |
2110 | qApp->processEvents(); | 2110 | qApp->processEvents(); |
2111 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 2111 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
2112 | if ( (*it).birthday().date().isValid() ){ | 2112 | if ( (*it).birthday().date().isValid() ){ |
2113 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 2113 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
2114 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 2114 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
2115 | ++addCount; | 2115 | ++addCount; |
2116 | } | 2116 | } |
2117 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 2117 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
2118 | if ( anni.isValid() ){ | 2118 | if ( anni.isValid() ){ |
2119 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 2119 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
2120 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 2120 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
2121 | ++addCount; | 2121 | ++addCount; |
2122 | } | 2122 | } |
2123 | } | 2123 | } |
2124 | mCalendar->setDefaultCalendar( curCal ); | 2124 | mCalendar->setDefaultCalendar( curCal ); |
2125 | updateView(); | 2125 | updateView(); |
2126 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 2126 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
2127 | #else //DESKTOP_VERSION | 2127 | #else //DESKTOP_VERSION |
2128 | 2128 | ||
2129 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); | 2129 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); |
2130 | // the result should now arrive through method insertBirthdays | 2130 | // the result should now arrive through method insertBirthdays |
2131 | 2131 | ||
2132 | #endif //DESKTOP_VERSION | 2132 | #endif //DESKTOP_VERSION |
2133 | 2133 | ||
2134 | #endif //KORG_NOKABC | 2134 | #endif //KORG_NOKABC |
2135 | 2135 | ||
2136 | 2136 | ||
2137 | return true; | 2137 | return true; |
2138 | } | 2138 | } |
2139 | 2139 | ||
2140 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI | 2140 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI |
2141 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, | 2141 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, |
2142 | const QStringList& anniversaryList, const QStringList& realNameList, | 2142 | const QStringList& anniversaryList, const QStringList& realNameList, |
2143 | const QStringList& emailList, const QStringList& assembledNameList, | 2143 | const QStringList& emailList, const QStringList& assembledNameList, |
2144 | const QStringList& uidList) | 2144 | const QStringList& uidList) |
2145 | { | 2145 | { |
2146 | 2146 | ||
2147 | //qDebug("KO::CalendarView::insertBirthdays"); | 2147 | //qDebug("KO::CalendarView::insertBirthdays"); |
2148 | if (uid == this->name()) | 2148 | if (uid == this->name()) |
2149 | { | 2149 | { |
2150 | int curCal = mCalendar->defaultCalendar(); | 2150 | int curCal = mCalendar->defaultCalendar(); |
2151 | int bd = mCalEditView->getBirtdayID(); | 2151 | int bd = mCalEditView->getBirtdayID(); |
2152 | if ( bd == 0 ) | 2152 | if ( bd == 0 ) |
2153 | return; | 2153 | return; |
2154 | mCalendar->setDefaultCalendar( bd ); | 2154 | mCalendar->setDefaultCalendar( bd ); |
2155 | 2155 | ||
2156 | 2156 | ||
2157 | int count = birthdayList.count(); | 2157 | int count = birthdayList.count(); |
2158 | int addCount = 0; | 2158 | int addCount = 0; |
2159 | KCal::Attendee* a = 0; | 2159 | KCal::Attendee* a = 0; |
2160 | 2160 | ||
2161 | //qDebug("CalView 1 %i", count); | 2161 | //qDebug("CalView 1 %i", count); |
2162 | 2162 | ||
2163 | QProgressBar bar(count,0 ); | 2163 | QProgressBar bar(count,0 ); |
2164 | int w = 300; | 2164 | int w = 300; |
2165 | if ( QApplication::desktop()->width() < 320 ) | 2165 | if ( QApplication::desktop()->width() < 320 ) |
2166 | w = 220; | 2166 | w = 220; |
2167 | int h = bar.sizeHint().height() ; | 2167 | int h = bar.sizeHint().height() ; |
2168 | int dw = QApplication::desktop()->width(); | 2168 | int dw = QApplication::desktop()->width(); |
2169 | int dh = QApplication::desktop()->height(); | 2169 | int dh = QApplication::desktop()->height(); |
2170 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2170 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2171 | bar.show(); | 2171 | bar.show(); |
2172 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); | 2172 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); |
2173 | qApp->processEvents(); | 2173 | qApp->processEvents(); |
2174 | 2174 | ||
2175 | QDate birthday; | 2175 | QDate birthday; |
2176 | QDate anniversary; | 2176 | QDate anniversary; |
2177 | QString realName; | 2177 | QString realName; |
2178 | QString email; | 2178 | QString email; |
2179 | QString assembledName; | 2179 | QString assembledName; |
2180 | QString uid; | 2180 | QString uid; |
2181 | bool ok = true; | 2181 | bool ok = true; |
2182 | for ( int i = 0; i < count; i++) | 2182 | for ( int i = 0; i < count; i++) |
2183 | { | 2183 | { |
2184 | if ( ! bar.isVisible() ) | 2184 | if ( ! bar.isVisible() ) |
2185 | return; | 2185 | return; |
2186 | bar.setProgress( i ); | 2186 | bar.setProgress( i ); |
2187 | qApp->processEvents(); | 2187 | qApp->processEvents(); |
2188 | 2188 | ||
2189 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); | 2189 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); |
2190 | if (!ok) { | 2190 | if (!ok) { |
2191 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); | 2191 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); |
2192 | } | 2192 | } |
2193 | 2193 | ||
2194 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); | 2194 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); |
2195 | if (!ok) { | 2195 | if (!ok) { |
2196 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); | 2196 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); |
2197 | } | 2197 | } |
2198 | realName = realNameList[i]; | 2198 | realName = realNameList[i]; |
2199 | email = emailList[i]; | 2199 | email = emailList[i]; |
2200 | assembledName = assembledNameList[i]; | 2200 | assembledName = assembledNameList[i]; |
2201 | uid = uidList[i]; | 2201 | uid = uidList[i]; |
2202 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); | 2202 | //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); |
2203 | 2203 | ||
2204 | if ( birthday.isValid() ){ | 2204 | if ( birthday.isValid() ){ |
2205 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 2205 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
2206 | KCal::Attendee::ReqParticipant,uid) ; | 2206 | KCal::Attendee::ReqParticipant,uid) ; |
2207 | if ( addAnniversary( birthday, assembledName, a, true ) ) | 2207 | if ( addAnniversary( birthday, assembledName, a, true ) ) |
2208 | ++addCount; | 2208 | ++addCount; |
2209 | } | 2209 | } |
2210 | 2210 | ||
2211 | if ( anniversary.isValid() ){ | 2211 | if ( anniversary.isValid() ){ |
2212 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 2212 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
2213 | KCal::Attendee::ReqParticipant,uid) ; | 2213 | KCal::Attendee::ReqParticipant,uid) ; |
2214 | if ( addAnniversary( anniversary, assembledName, a, false ) ) | 2214 | if ( addAnniversary( anniversary, assembledName, a, false ) ) |
2215 | ++addCount; | 2215 | ++addCount; |
2216 | } | 2216 | } |
2217 | } | 2217 | } |
2218 | 2218 | ||
2219 | mCalendar->setDefaultCalendar( curCal ); | 2219 | mCalendar->setDefaultCalendar( curCal ); |
2220 | updateView(); | 2220 | updateView(); |
2221 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 2221 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
2222 | 2222 | ||
2223 | } | 2223 | } |
2224 | 2224 | ||
2225 | } | 2225 | } |
2226 | 2226 | ||
2227 | 2227 | ||
2228 | 2228 | ||
2229 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 2229 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
2230 | { | 2230 | { |
2231 | //qDebug("addAnni "); | 2231 | //qDebug("addAnni "); |
2232 | Event * ev = new Event(); | 2232 | Event * ev = new Event(); |
2233 | ev->setOrganizer(KOPrefs::instance()->email()); | 2233 | ev->setOrganizer(KOPrefs::instance()->email()); |
2234 | if ( a ) { | 2234 | if ( a ) { |
2235 | ev->addAttendee( a ); | 2235 | ev->addAttendee( a ); |
2236 | } | 2236 | } |
2237 | QString kind; | 2237 | QString kind; |
2238 | if ( birthday ) { | 2238 | if ( birthday ) { |
2239 | kind = i18n( "Birthday" ); | 2239 | kind = i18n( "Birthday" ); |
2240 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); | 2240 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); |
2241 | } | 2241 | } |
2242 | else { | 2242 | else { |
2243 | kind = i18n( "Anniversary" ); | 2243 | kind = i18n( "Anniversary" ); |
2244 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); | 2244 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); |
2245 | } | 2245 | } |
2246 | ev->setCategories( kind ); | 2246 | ev->setCategories( kind ); |
2247 | ev->setDtStart( QDateTime(date) ); | 2247 | ev->setDtStart( QDateTime(date) ); |
2248 | ev->setDtEnd( QDateTime(date) ); | 2248 | ev->setDtEnd( QDateTime(date) ); |
2249 | ev->setFloats( true ); | 2249 | ev->setFloats( true ); |
2250 | Recurrence * rec = ev->recurrence(); | 2250 | Recurrence * rec = ev->recurrence(); |
2251 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 2251 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
2252 | rec->addYearlyNum( date.month() ); | 2252 | rec->addYearlyNum( date.month() ); |
2253 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 2253 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
2254 | delete ev; | 2254 | delete ev; |
2255 | return false; | 2255 | return false; |
2256 | } | 2256 | } |
2257 | return true; | 2257 | return true; |
2258 | 2258 | ||
2259 | } | 2259 | } |
2260 | bool CalendarView::importQtopia( const QString &categories, | 2260 | bool CalendarView::importQtopia( const QString &categories, |
2261 | const QString &datebook, | 2261 | const QString &datebook, |
2262 | const QString &todolist ) | 2262 | const QString &todolist ) |
2263 | { | 2263 | { |
2264 | 2264 | ||
2265 | QtopiaFormat qtopiaFormat; | 2265 | QtopiaFormat qtopiaFormat; |
2266 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 2266 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
2267 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 2267 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
2268 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 2268 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
2269 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 2269 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
2270 | 2270 | ||
2271 | updateView(); | 2271 | updateView(); |
2272 | return true; | 2272 | return true; |
2273 | 2273 | ||
2274 | #if 0 | 2274 | #if 0 |
2275 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 2275 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
2276 | mCurrentSyncDevice = "qtopia-XML"; | 2276 | mCurrentSyncDevice = "qtopia-XML"; |
2277 | if ( mSyncManager->mAskForPreferences ) | 2277 | if ( mSyncManager->mAskForPreferences ) |
2278 | edit_sync_options(); | 2278 | edit_sync_options(); |
2279 | qApp->processEvents(); | 2279 | qApp->processEvents(); |
2280 | CalendarLocal* calendar = new CalendarLocal(); | 2280 | CalendarLocal* calendar = new CalendarLocal(); |
2281 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 2281 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
2282 | bool syncOK = false; | 2282 | bool syncOK = false; |
2283 | QtopiaFormat qtopiaFormat; | 2283 | QtopiaFormat qtopiaFormat; |
2284 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 2284 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
2285 | bool loadOk = true; | 2285 | bool loadOk = true; |
2286 | if ( !categories.isEmpty() ) | 2286 | if ( !categories.isEmpty() ) |
2287 | loadOk = qtopiaFormat.load( calendar, categories ); | 2287 | loadOk = qtopiaFormat.load( calendar, categories ); |
2288 | if ( loadOk && !datebook.isEmpty() ) | 2288 | if ( loadOk && !datebook.isEmpty() ) |
2289 | loadOk = qtopiaFormat.load( calendar, datebook ); | 2289 | loadOk = qtopiaFormat.load( calendar, datebook ); |
2290 | if ( loadOk && !todolist.isEmpty() ) | 2290 | if ( loadOk && !todolist.isEmpty() ) |
2291 | loadOk = qtopiaFormat.load( calendar, todolist ); | 2291 | loadOk = qtopiaFormat.load( calendar, todolist ); |
2292 | 2292 | ||
2293 | if ( loadOk ) { | 2293 | if ( loadOk ) { |
2294 | getEventViewerDialog()->setSyncMode( true ); | 2294 | getEventViewerDialog()->setSyncMode( true ); |
2295 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 2295 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
2296 | getEventViewerDialog()->setSyncMode( false ); | 2296 | getEventViewerDialog()->setSyncMode( false ); |
2297 | qApp->processEvents(); | 2297 | qApp->processEvents(); |
2298 | if ( syncOK ) { | 2298 | if ( syncOK ) { |
2299 | if ( mSyncManager->mWriteBackFile ) | 2299 | if ( mSyncManager->mWriteBackFile ) |
2300 | { | 2300 | { |
2301 | // write back XML file | 2301 | // write back XML file |
2302 | 2302 | ||
2303 | } | 2303 | } |
2304 | setModified( true ); | 2304 | setModified( true ); |
2305 | } | 2305 | } |
2306 | } else { | 2306 | } else { |
2307 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 2307 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
2308 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 2308 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
2309 | question, i18n("Ok")) ; | 2309 | question, i18n("Ok")) ; |
2310 | } | 2310 | } |
2311 | delete calendar; | 2311 | delete calendar; |
2312 | updateView(); | 2312 | updateView(); |
2313 | return syncOK; | 2313 | return syncOK; |
2314 | 2314 | ||
2315 | 2315 | ||
2316 | #endif | 2316 | #endif |
2317 | 2317 | ||
2318 | } | 2318 | } |
2319 | 2319 | ||
2320 | void CalendarView::setSyncEventsReadOnly() | 2320 | void CalendarView::setSyncEventsReadOnly() |
2321 | { | 2321 | { |
2322 | mCalendar->setSyncEventsReadOnly(); | 2322 | mCalendar->setSyncEventsReadOnly(); |
2323 | } | 2323 | } |
2324 | 2324 | ||
2325 | bool CalendarView::loadCalendars() | 2325 | bool CalendarView::loadCalendars() |
2326 | { | 2326 | { |
2327 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2327 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2328 | KopiCalendarFile * cal = calendars.first(); | 2328 | KopiCalendarFile * cal = calendars.first(); |
2329 | mCalendar->setDefaultCalendar( 1 ); | 2329 | mCalendar->setDefaultCalendar( 1 ); |
2330 | openCalendar( MainWindow::defaultFileName(), false ); | 2330 | openCalendar( MainWindow::defaultFileName(), false ); |
2331 | cal = calendars.next(); | 2331 | cal = calendars.next(); |
2332 | while ( cal ) { | 2332 | while ( cal ) { |
2333 | addCalendar( cal ); | 2333 | addCalendar( cal ); |
2334 | cal = calendars.next(); | 2334 | cal = calendars.next(); |
2335 | } | 2335 | } |
2336 | restoreCalendarSettings(); | 2336 | restoreCalendarSettings(); |
2337 | return true; | 2337 | return true; |
2338 | } | 2338 | } |
2339 | bool CalendarView::restoreCalendarSettings() | 2339 | bool CalendarView::restoreCalendarSettings() |
2340 | { | 2340 | { |
2341 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2341 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2342 | KopiCalendarFile * cal = calendars.first(); | 2342 | KopiCalendarFile * cal = calendars.first(); |
2343 | while ( cal ) { | 2343 | while ( cal ) { |
2344 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); | 2344 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); |
2345 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); | 2345 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); |
2346 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); | 2346 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); |
2347 | if ( cal->isStandard ) | 2347 | if ( cal->isStandard ) |
2348 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2348 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2349 | cal = calendars.next(); | 2349 | cal = calendars.next(); |
2350 | } | 2350 | } |
2351 | setSyncEventsReadOnly(); | 2351 | setSyncEventsReadOnly(); |
2352 | mCalendar->reInitAlarmSettings(); | 2352 | mCalendar->reInitAlarmSettings(); |
2353 | updateUnmanagedViews(); | 2353 | updateUnmanagedViews(); |
2354 | updateView(); | 2354 | updateView(); |
2355 | return true; | 2355 | return true; |
2356 | } | 2356 | } |
2357 | void CalendarView::addCalendarId( int id ) | 2357 | void CalendarView::addCalendarId( int id ) |
2358 | { | 2358 | { |
2359 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); | 2359 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); |
2360 | if ( cal ) | 2360 | if ( cal ) |
2361 | addCalendar( cal ); | 2361 | addCalendar( cal ); |
2362 | } | 2362 | } |
2363 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) | 2363 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) |
2364 | { | 2364 | { |
2365 | cal->mErrorOnLoad = false; | 2365 | cal->mErrorOnLoad = false; |
2366 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { | 2366 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { |
2367 | cal->mLoadDt = QDateTime::currentDateTime(); | 2367 | cal->mLoadDt = QDateTime::currentDateTime(); |
2368 | return true; | 2368 | return true; |
2369 | } | 2369 | } |
2370 | qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); | 2370 | qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); |
2371 | cal->mErrorOnLoad = true; | 2371 | cal->mErrorOnLoad = true; |
2372 | return false; | 2372 | return false; |
2373 | } | 2373 | } |
2374 | bool CalendarView::openCalendar(QString filename, bool merge) | 2374 | bool CalendarView::openCalendar(QString filename, bool merge) |
2375 | { | 2375 | { |
2376 | 2376 | ||
2377 | if (filename.isEmpty()) { | 2377 | if (filename.isEmpty()) { |
2378 | return false; | 2378 | return false; |
2379 | } | 2379 | } |
2380 | 2380 | ||
2381 | if (!QFile::exists(filename)) { | 2381 | if (!QFile::exists(filename)) { |
2382 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 2382 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
2383 | return false; | 2383 | return false; |
2384 | } | 2384 | } |
2385 | 2385 | ||
2386 | globalFlagBlockAgenda = 1; | 2386 | globalFlagBlockAgenda = 1; |
2387 | clearAllViews(); | 2387 | clearAllViews(); |
2388 | if (!merge) { | 2388 | if (!merge) { |
2389 | mViewManager->setDocumentId( filename ); | 2389 | mViewManager->setDocumentId( filename ); |
2390 | mCalendar->close(); | 2390 | mCalendar->close(); |
2391 | } | 2391 | } |
2392 | mStorage->setFileName( filename ); | 2392 | mStorage->setFileName( filename ); |
2393 | 2393 | ||
2394 | if ( mStorage->load() ) { | 2394 | if ( mStorage->load() ) { |
2395 | if ( merge ) ;//setModified( true ); | 2395 | if ( merge ) ;//setModified( true ); |
2396 | else { | 2396 | else { |
2397 | //setModified( true ); | 2397 | //setModified( true ); |
2398 | mViewManager->setDocumentId( filename ); | 2398 | mViewManager->setDocumentId( filename ); |
2399 | mDialogManager->setDocumentId( filename ); | 2399 | mDialogManager->setDocumentId( filename ); |
2400 | mTodoList->setDocumentId( filename ); | 2400 | mTodoList->setDocumentId( filename ); |
2401 | } | 2401 | } |
2402 | globalFlagBlockAgenda = 2; | 2402 | globalFlagBlockAgenda = 2; |
2403 | // if ( getLastSyncEvent() ) | 2403 | // if ( getLastSyncEvent() ) |
2404 | // getLastSyncEvent()->setReadOnly( true ); | 2404 | // getLastSyncEvent()->setReadOnly( true ); |
2405 | mCalendar->reInitAlarmSettings(); | 2405 | mCalendar->reInitAlarmSettings(); |
2406 | setSyncEventsReadOnly(); | 2406 | setSyncEventsReadOnly(); |
2407 | //updateUnmanagedViews(); | 2407 | //updateUnmanagedViews(); |
2408 | //updateView(); | 2408 | //updateView(); |
2409 | if ( filename != MainWindow::defaultFileName() ) { | 2409 | if ( filename != MainWindow::defaultFileName() ) { |
2410 | saveCalendar( MainWindow::defaultFileName() ); | 2410 | saveCalendar( MainWindow::defaultFileName() ); |
2411 | } else { | 2411 | } else { |
2412 | QFileInfo finf ( MainWindow::defaultFileName()); | 2412 | QFileInfo finf ( MainWindow::defaultFileName()); |
2413 | if ( finf.exists() ) { | 2413 | if ( finf.exists() ) { |
2414 | setLoadedFileVersion( finf.lastModified () ); | 2414 | setLoadedFileVersion( finf.lastModified () ); |
2415 | } | 2415 | } |
2416 | } | 2416 | } |
2417 | return true; | 2417 | return true; |
2418 | } else { | 2418 | } else { |
2419 | // while failing to load, the calendar object could | 2419 | // while failing to load, the calendar object could |
2420 | // have become partially populated. Clear it out. | 2420 | // have become partially populated. Clear it out. |
2421 | if ( !merge ) { | 2421 | if ( !merge ) { |
2422 | mCalendar->close(); | 2422 | mCalendar->close(); |
2423 | mViewManager->setDocumentId( filename ); | 2423 | mViewManager->setDocumentId( filename ); |
2424 | mDialogManager->setDocumentId( filename ); | 2424 | mDialogManager->setDocumentId( filename ); |
2425 | mTodoList->setDocumentId( filename ); | 2425 | mTodoList->setDocumentId( filename ); |
2426 | } | 2426 | } |
2427 | 2427 | ||
2428 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 2428 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
2429 | 2429 | ||
2430 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 2430 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
2431 | globalFlagBlockAgenda = 2; | 2431 | globalFlagBlockAgenda = 2; |
2432 | mCalendar->reInitAlarmSettings(); | 2432 | mCalendar->reInitAlarmSettings(); |
2433 | setSyncEventsReadOnly(); | 2433 | setSyncEventsReadOnly(); |
2434 | updateUnmanagedViews(); | 2434 | updateUnmanagedViews(); |
2435 | updateView(); | 2435 | updateView(); |
2436 | } | 2436 | } |
2437 | return false; | 2437 | return false; |
2438 | } | 2438 | } |
2439 | void CalendarView::mergeFile( QString fn ) | 2439 | void CalendarView::mergeFile( QString fn ) |
2440 | { | 2440 | { |
2441 | clearAllViews(); | 2441 | clearAllViews(); |
2442 | mCalendar->mergeCalendarFile( fn ); | 2442 | mCalendar->mergeCalendarFile( fn ); |
2443 | mCalendar->reInitAlarmSettings(); | 2443 | mCalendar->reInitAlarmSettings(); |
2444 | setSyncEventsReadOnly(); | 2444 | setSyncEventsReadOnly(); |
2445 | updateUnmanagedViews(); | 2445 | updateUnmanagedViews(); |
2446 | updateView(); | 2446 | updateView(); |
2447 | } | 2447 | } |
2448 | void CalendarView::mergeFileResource( QString fn ,QString resource ) | 2448 | void CalendarView::mergeFileResource( QString fn ,QString resource ) |
2449 | { | 2449 | { |
2450 | 2450 | ||
2451 | if ( resource == "ALL" ) { | 2451 | if ( resource == "ALL" ) { |
2452 | mergeFile( fn ); | 2452 | mergeFile( fn ); |
2453 | return; | 2453 | return; |
2454 | } | 2454 | } |
2455 | 2455 | ||
2456 | int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); | 2456 | int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); |
2457 | if ( !exclusiveResource ) { | 2457 | if ( !exclusiveResource ) { |
2458 | qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); | 2458 | qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); |
2459 | return; | 2459 | return; |
2460 | } | 2460 | } |
2461 | clearAllViews(); | 2461 | clearAllViews(); |
2462 | mCalendar->setCalendarRemove( exclusiveResource ); | 2462 | mCalendar->setCalendarRemove( exclusiveResource ); |
2463 | int def = mCalendar->defaultCalendar(); | 2463 | int def = mCalendar->defaultCalendar(); |
2464 | mCalendar->setDefaultCalendar(exclusiveResource); | 2464 | mCalendar->setDefaultCalendar(exclusiveResource); |
2465 | if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { | 2465 | if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { |
2466 | qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); | 2466 | qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); |
2467 | } | 2467 | } |
2468 | mCalendar->setDefaultCalendar( def ); | 2468 | mCalendar->setDefaultCalendar( def ); |
2469 | mCalendar->reInitAlarmSettings(); | 2469 | mCalendar->reInitAlarmSettings(); |
2470 | setSyncEventsReadOnly(); | 2470 | setSyncEventsReadOnly(); |
2471 | updateUnmanagedViews(); | 2471 | updateUnmanagedViews(); |
2472 | updateView(); | 2472 | updateView(); |
2473 | } | 2473 | } |
2474 | void CalendarView::showOpenError() | 2474 | void CalendarView::showOpenError() |
2475 | { | 2475 | { |
2476 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 2476 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
2477 | } | 2477 | } |
2478 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 2478 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
2479 | { | 2479 | { |
2480 | loadedFileVersion = dt; | 2480 | loadedFileVersion = dt; |
2481 | } | 2481 | } |
2482 | bool CalendarView::checkFileChanged(QString fn) | 2482 | bool CalendarView::checkFileChanged(QString fn) |
2483 | { | 2483 | { |
2484 | QFileInfo finf ( fn ); | 2484 | QFileInfo finf ( fn ); |
2485 | if ( !finf.exists() ) | 2485 | if ( !finf.exists() ) |
2486 | return true; | 2486 | return true; |
2487 | QDateTime dt = finf.lastModified (); | 2487 | QDateTime dt = finf.lastModified (); |
2488 | if ( dt <= loadedFileVersion ) | 2488 | if ( dt <= loadedFileVersion ) |
2489 | return false; | 2489 | return false; |
2490 | return true; | 2490 | return true; |
2491 | 2491 | ||
2492 | } | 2492 | } |
2493 | void CalendarView::watchSavedFile() | 2493 | void CalendarView::watchSavedFile() |
2494 | { | 2494 | { |
2495 | QFileInfo finf ( MainWindow::defaultFileName()); | 2495 | QFileInfo finf ( MainWindow::defaultFileName()); |
2496 | if ( !finf.exists() ) | 2496 | if ( !finf.exists() ) |
2497 | return; | 2497 | return; |
2498 | QDateTime dt = finf.lastModified (); | 2498 | QDateTime dt = finf.lastModified (); |
2499 | if ( dt < loadedFileVersion ) { | 2499 | if ( dt < loadedFileVersion ) { |
2500 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 2500 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
2501 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 2501 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
2502 | return; | 2502 | return; |
2503 | } | 2503 | } |
2504 | loadedFileVersion = dt; | 2504 | loadedFileVersion = dt; |
2505 | } | 2505 | } |
2506 | bool CalendarView::checkAllFileVersions() | 2506 | bool CalendarView::checkAllFileVersions() |
2507 | { | 2507 | { |
2508 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2508 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2509 | KopiCalendarFile * cal = calendars.first(); | 2509 | KopiCalendarFile * cal = calendars.first(); |
2510 | mCalendar->setDefaultCalendar( 1 ); | 2510 | mCalendar->setDefaultCalendar( 1 ); |
2511 | mCalendar->setDefaultCalendarEnabledOnly(); | 2511 | mCalendar->setDefaultCalendarEnabledOnly(); |
2512 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { | 2512 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
2513 | if ( !checkFileVersion(MainWindow::defaultFileName())) { | 2513 | if ( !checkFileVersion(MainWindow::defaultFileName())) { |
2514 | restoreCalendarSettings(); | 2514 | restoreCalendarSettings(); |
2515 | return false; | 2515 | return false; |
2516 | } | 2516 | } |
2517 | } | 2517 | } |
2518 | cal = calendars.next(); | 2518 | cal = calendars.next(); |
2519 | QDateTime storeTemp = loadedFileVersion; | 2519 | QDateTime storeTemp = loadedFileVersion; |
2520 | while ( cal ) { | 2520 | while ( cal ) { |
2521 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { | 2521 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
2522 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2522 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2523 | mCalendar->setDefaultCalendarEnabledOnly(); | 2523 | mCalendar->setDefaultCalendarEnabledOnly(); |
2524 | loadedFileVersion = cal->mLoadDt.addSecs( 15 ); | 2524 | loadedFileVersion = cal->mLoadDt.addSecs( 15 ); |
2525 | if ( !checkFileVersion(cal->mFileName )) { | 2525 | if ( !checkFileVersion(cal->mFileName )) { |
2526 | loadedFileVersion = storeTemp; | 2526 | loadedFileVersion = storeTemp; |
2527 | restoreCalendarSettings(); | 2527 | restoreCalendarSettings(); |
2528 | return false; | 2528 | return false; |
2529 | } | 2529 | } |
2530 | } | 2530 | } |
2531 | cal = calendars.next(); | 2531 | cal = calendars.next(); |
2532 | } | 2532 | } |
2533 | loadedFileVersion = storeTemp; | 2533 | loadedFileVersion = storeTemp; |
2534 | return true; | 2534 | return true; |
2535 | } | 2535 | } |
2536 | bool CalendarView::checkFileVersion(QString fn) | 2536 | bool CalendarView::checkFileVersion(QString fn) |
2537 | { | 2537 | { |
2538 | QFileInfo finf ( fn ); | 2538 | QFileInfo finf ( fn ); |
2539 | if ( !finf.exists() ) | 2539 | if ( !finf.exists() ) |
2540 | return true; | 2540 | return true; |
2541 | QDateTime dt = finf.lastModified (); | 2541 | QDateTime dt = finf.lastModified (); |
2542 | //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); | 2542 | //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); |
2543 | //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); | 2543 | //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); |
2544 | if ( dt <= loadedFileVersion ) | 2544 | if ( dt <= loadedFileVersion ) |
2545 | return true; | 2545 | return true; |
2546 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , | 2546 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , |
2547 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 2547 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
2548 | i18n("Sync+save")); | 2548 | i18n("Sync+save")); |
2549 | 2549 | ||
2550 | if ( km == KMessageBox::Cancel ) | 2550 | if ( km == KMessageBox::Cancel ) |
2551 | return false; | 2551 | return false; |
2552 | if ( km == KMessageBox::Yes ) | 2552 | if ( km == KMessageBox::Yes ) |
2553 | return true; | 2553 | return true; |
2554 | 2554 | ||
2555 | setSyncDevice("deleteaftersync" ); | 2555 | setSyncDevice("deleteaftersync" ); |
2556 | mSyncManager->mAskForPreferences = true; | 2556 | mSyncManager->mAskForPreferences = true; |
2557 | mSyncManager->mSyncAlgoPrefs = 3; | 2557 | mSyncManager->mSyncAlgoPrefs = 3; |
2558 | mSyncManager->mWriteBackFile = false; | 2558 | mSyncManager->mWriteBackFile = false; |
2559 | mSyncManager->mWriteBackExistingOnly = false; | 2559 | mSyncManager->mWriteBackExistingOnly = false; |
2560 | mSyncManager->mShowSyncSummary = false; | 2560 | mSyncManager->mShowSyncSummary = false; |
2561 | mMultiResourceSync = false; | 2561 | mMultiResourceSync = false; |
2562 | syncCalendar( fn, 3 ); | 2562 | syncCalendar( fn, 3 ); |
2563 | Event * e = getLastSyncEvent(); | 2563 | Event * e = getLastSyncEvent(); |
2564 | if ( e ) | 2564 | if ( e ) |
2565 | mCalendar->deleteEvent( e ); | 2565 | mCalendar->deleteEvent( e ); |
2566 | return true; | 2566 | return true; |
2567 | } | 2567 | } |
2568 | bool CalendarView::saveCalendars() | 2568 | bool CalendarView::saveCalendars() |
2569 | { | 2569 | { |
2570 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2570 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2571 | KopiCalendarFile * cal = calendars.first(); | 2571 | KopiCalendarFile * cal = calendars.first(); |
2572 | mCalendar->setDefaultCalendar( 1 ); | 2572 | mCalendar->setDefaultCalendar( 1 ); |
2573 | mCalendar->setDefaultCalendarEnabledOnly(); | 2573 | mCalendar->setDefaultCalendarEnabledOnly(); |
2574 | QString saveError; | 2574 | QString saveError; |
2575 | if ( !saveCalendar( MainWindow::defaultFileName() ) ) | 2575 | if ( !saveCalendar( MainWindow::defaultFileName() ) ) |
2576 | saveError = cal->mName +"\n"; | 2576 | saveError = cal->mName +"\n"; |
2577 | cal = calendars.next(); | 2577 | cal = calendars.next(); |
2578 | while ( cal ) { | 2578 | while ( cal ) { |
2579 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { | 2579 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
2580 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2580 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2581 | mCalendar->setDefaultCalendarEnabledOnly(); | 2581 | mCalendar->setDefaultCalendarEnabledOnly(); |
2582 | if ( saveCalendar( cal->mFileName ) ) | 2582 | if ( saveCalendar( cal->mFileName ) ) |
2583 | cal->mLoadDt = QDateTime::currentDateTime(); | 2583 | cal->mLoadDt = QDateTime::currentDateTime(); |
2584 | else | 2584 | else |
2585 | saveError += cal->mName + "\n"; | 2585 | saveError += cal->mName + "\n"; |
2586 | } | 2586 | } |
2587 | cal = calendars.next(); | 2587 | cal = calendars.next(); |
2588 | } | 2588 | } |
2589 | restoreCalendarSettings(); | 2589 | restoreCalendarSettings(); |
2590 | //saveError = "test error"; | 2590 | //saveError = "test error"; |
2591 | if ( !saveError.isEmpty() ) { | 2591 | if ( !saveError.isEmpty() ) { |
2592 | saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError; | 2592 | saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError; |
2593 | KMessageBox::error(this, saveError, i18n("Error saving data")); | 2593 | KMessageBox::error(this, saveError, i18n("Error saving data")); |
2594 | return false; | 2594 | return false; |
2595 | } | 2595 | } |
2596 | return true; | 2596 | return true; |
2597 | } | 2597 | } |
2598 | bool CalendarView::saveCalendarResource(QString filename, QString resource) | 2598 | bool CalendarView::saveCalendarResource(QString filename, QString resource) |
2599 | { | 2599 | { |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 66836a1..f301768 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,384 +1,384 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@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 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | virtual bool mergeCalendarFile( QString name ) = 0; | 79 | virtual bool mergeCalendarFile( QString name ) = 0; |
80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; | 80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates , bool enabledOnly = false ) = 0; |
81 | virtual void setSyncEventsReadOnly() = 0; | 81 | virtual void setSyncEventsReadOnly() = 0; |
82 | virtual void setSyncEventsEnabled() = 0; | 82 | virtual void setSyncEventsEnabled() = 0; |
83 | virtual void stopAllTodos() = 0; | 83 | virtual void stopAllTodos() = 0; |
84 | virtual void clearUndo( Incidence * newUndo ); | 84 | virtual void clearUndo( Incidence * newUndo ); |
85 | 85 | ||
86 | /** | 86 | /** |
87 | Sync changes in memory to persistant storage. | 87 | Sync changes in memory to persistant storage. |
88 | */ | 88 | */ |
89 | virtual void save() = 0; | 89 | virtual void save() = 0; |
90 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 90 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
91 | virtual void removeSyncInfo( QString syncProfile) = 0; | 91 | virtual void removeSyncInfo( QString syncProfile) = 0; |
92 | virtual bool isSaving() { return false; } | 92 | virtual bool isSaving() { return false; } |
93 | 93 | ||
94 | /** | 94 | /** |
95 | Return the owner of the calendar's full name. | 95 | Return the owner of the calendar's full name. |
96 | */ | 96 | */ |
97 | const QString &getOwner() const; | 97 | const QString &getOwner() const; |
98 | /** | 98 | /** |
99 | Set the owner of the calendar. Should be owner's full name. | 99 | Set the owner of the calendar. Should be owner's full name. |
100 | */ | 100 | */ |
101 | void setOwner( const QString &os ); | 101 | void setOwner( const QString &os ); |
102 | /** | 102 | /** |
103 | Return the email address of the calendar owner. | 103 | Return the email address of the calendar owner. |
104 | */ | 104 | */ |
105 | const QString &getEmail(); | 105 | const QString &getEmail(); |
106 | /** | 106 | /** |
107 | Set the email address of the calendar owner. | 107 | Set the email address of the calendar owner. |
108 | */ | 108 | */ |
109 | void setEmail( const QString & ); | 109 | void setEmail( const QString & ); |
110 | 110 | ||
111 | /** | 111 | /** |
112 | Set time zone from a timezone string (e.g. -2:00) | 112 | Set time zone from a timezone string (e.g. -2:00) |
113 | */ | 113 | */ |
114 | void setTimeZone( const QString &tz ); | 114 | void setTimeZone( const QString &tz ); |
115 | /** | 115 | /** |
116 | Set time zone from a minutes value (e.g. -60) | 116 | Set time zone from a minutes value (e.g. -60) |
117 | */ | 117 | */ |
118 | void setTimeZone( int tz ); | 118 | void setTimeZone( int tz ); |
119 | /** | 119 | /** |
120 | Return time zone as offest in minutes. | 120 | Return time zone as offest in minutes. |
121 | */ | 121 | */ |
122 | int getTimeZone() const; | 122 | int getTimeZone() const; |
123 | /** | 123 | /** |
124 | Compute an ISO 8601 format string from the time zone. | 124 | Compute an ISO 8601 format string from the time zone. |
125 | */ | 125 | */ |
126 | QString getTimeZoneStr() const; | 126 | QString getTimeZoneStr() const; |
127 | /** | 127 | /** |
128 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 128 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
129 | values). | 129 | values). |
130 | */ | 130 | */ |
131 | void setTimeZoneId( const QString & ); | 131 | void setTimeZoneId( const QString & ); |
132 | /** | 132 | /** |
133 | Return time zone id. | 133 | Return time zone id. |
134 | */ | 134 | */ |
135 | QString timeZoneId() const; | 135 | QString timeZoneId() const; |
136 | /** | 136 | /** |
137 | Use local time, not UTC or a time zone. | 137 | Use local time, not UTC or a time zone. |
138 | */ | 138 | */ |
139 | void setLocalTime(); | 139 | void setLocalTime(); |
140 | /** | 140 | /** |
141 | Return whether local time is being used. | 141 | Return whether local time is being used. |
142 | */ | 142 | */ |
143 | bool isLocalTime() const; | 143 | bool isLocalTime() const; |
144 | 144 | ||
145 | /** | 145 | /** |
146 | Add an incidence to calendar. | 146 | Add an incidence to calendar. |
147 | 147 | ||
148 | @return true on success, false on error. | 148 | @return true on success, false on error. |
149 | */ | 149 | */ |
150 | virtual bool addIncidence( Incidence * ); | 150 | virtual bool addIncidence( Incidence * ); |
151 | 151 | ||
152 | // Adds an incidence and all relatedto incidences to the cal | 152 | // Adds an incidence and all relatedto incidences to the cal |
153 | void addIncidenceBranch( Incidence * ); | 153 | void addIncidenceBranch( Incidence * ); |
154 | /** | 154 | /** |
155 | Return filtered list of all incidences of this calendar. | 155 | Return filtered list of all incidences of this calendar. |
156 | */ | 156 | */ |
157 | virtual QPtrList<Incidence> incidences(); | 157 | virtual QPtrList<Incidence> incidences(); |
158 | 158 | ||
159 | /** | 159 | /** |
160 | Return unfiltered list of all incidences of this calendar. | 160 | Return unfiltered list of all incidences of this calendar. |
161 | */ | 161 | */ |
162 | virtual QPtrList<Incidence> rawIncidences(); | 162 | virtual QPtrList<Incidence> rawIncidences(); |
163 | 163 | ||
164 | /** | 164 | /** |
165 | Adds a Event to this calendar object. | 165 | Adds a Event to this calendar object. |
166 | @param anEvent a pointer to the event to add | 166 | @param anEvent a pointer to the event to add |
167 | 167 | ||
168 | @return true on success, false on error. | 168 | @return true on success, false on error. |
169 | */ | 169 | */ |
170 | virtual bool addEventNoDup( Event *event ) = 0; | 170 | virtual bool addEventNoDup( Event *event ) = 0; |
171 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 171 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
172 | virtual bool addEvent( Event *anEvent ) = 0; | 172 | virtual bool addEvent( Event *anEvent ) = 0; |
173 | /** | 173 | /** |
174 | Delete event from calendar. | 174 | Delete event from calendar. |
175 | */ | 175 | */ |
176 | virtual void deleteEvent( Event * ) = 0; | 176 | virtual void deleteEvent( Event * ) = 0; |
177 | /** | 177 | /** |
178 | Retrieves an event on the basis of the unique string ID. | 178 | Retrieves an event on the basis of the unique string ID. |
179 | */ | 179 | */ |
180 | virtual Event *event( const QString &UniqueStr ) = 0; | 180 | virtual Event *event( const QString &UniqueStr ) = 0; |
181 | virtual Event *event( QString, QString ) = 0; | 181 | virtual Event *event( QString, QString ) = 0; |
182 | /** | 182 | /** |
183 | Builds and then returns a list of all events that match for the | 183 | Builds and then returns a list of all events that match for the |
184 | date specified. useful for dayView, etc. etc. | 184 | date specified. useful for dayView, etc. etc. |
185 | The calendar filter is applied. | 185 | The calendar filter is applied. |
186 | */ | 186 | */ |
187 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 187 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
188 | /** | 188 | /** |
189 | Get events, which occur on the given date. | 189 | Get events, which occur on the given date. |
190 | The calendar filter is applied. | 190 | The calendar filter is applied. |
191 | */ | 191 | */ |
192 | QPtrList<Event> events( const QDateTime &qdt ); | 192 | QPtrList<Event> events( const QDateTime &qdt ); |
193 | /** | 193 | /** |
194 | Get events in a range of dates. If inclusive is set to true, only events | 194 | Get events in a range of dates. If inclusive is set to true, only events |
195 | are returned, which are completely included in the range. | 195 | are returned, which are completely included in the range. |
196 | The calendar filter is applied. | 196 | The calendar filter is applied. |
197 | */ | 197 | */ |
198 | QPtrList<Event> events( const QDate &start, const QDate &end, | 198 | QPtrList<Event> events( const QDate &start, const QDate &end, |
199 | bool inclusive = false); | 199 | bool inclusive = false); |
200 | /** | 200 | /** |
201 | Return filtered list of all events in calendar. | 201 | Return filtered list of all events in calendar. |
202 | */ | 202 | */ |
203 | virtual QPtrList<Event> events(); | 203 | virtual QPtrList<Event> events(); |
204 | /** | 204 | /** |
205 | Return unfiltered list of all events in calendar. | 205 | Return unfiltered list of all events in calendar. |
206 | */ | 206 | */ |
207 | virtual QPtrList<Event> rawEvents() = 0; | 207 | virtual QPtrList<Event> rawEvents() = 0; |
208 | 208 | ||
209 | /** | 209 | /** |
210 | Add a todo to the todolist. | 210 | Add a todo to the todolist. |
211 | 211 | ||
212 | @return true on success, false on error. | 212 | @return true on success, false on error. |
213 | */ | 213 | */ |
214 | virtual bool addTodo( Todo *todo ) = 0; | 214 | virtual bool addTodo( Todo *todo ) = 0; |
215 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 215 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
216 | /** | 216 | /** |
217 | Remove a todo from the todolist. | 217 | Remove a todo from the todolist. |
218 | */ | 218 | */ |
219 | virtual void deleteTodo( Todo * ) = 0; | 219 | virtual void deleteTodo( Todo * ) = 0; |
220 | virtual void deleteJournal( Journal * ) = 0; | 220 | virtual void deleteJournal( Journal * ) = 0; |
221 | /** | 221 | /** |
222 | Return filterd list of todos. | 222 | Return filterd list of todos. |
223 | */ | 223 | */ |
224 | virtual QPtrList<Todo> todos(); | 224 | virtual QPtrList<Todo> todos(); |
225 | /** | 225 | /** |
226 | Searches todolist for an event with this unique string identifier, | 226 | Searches todolist for an event with this unique string identifier, |
227 | returns a pointer or null. | 227 | returns a pointer or null. |
228 | */ | 228 | */ |
229 | virtual Todo *todo( const QString &uid ) = 0; | 229 | virtual Todo *todo( const QString &uid ) = 0; |
230 | virtual Todo *todo( QString, QString ) = 0; | 230 | virtual Todo *todo( QString, QString ) = 0; |
231 | /** | 231 | /** |
232 | Returns list of todos due on the specified date. | 232 | Returns list of todos due on the specified date. |
233 | */ | 233 | */ |
234 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 234 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
235 | /** | 235 | /** |
236 | Return unfiltered list of todos. | 236 | Return unfiltered list of todos. |
237 | */ | 237 | */ |
238 | virtual QPtrList<Todo> rawTodos() = 0; | 238 | virtual QPtrList<Todo> rawTodos() = 0; |
239 | 239 | ||
240 | /** | 240 | /** |
241 | Add a Journal entry to calendar. | 241 | Add a Journal entry to calendar. |
242 | 242 | ||
243 | @return true on success, false on error. | 243 | @return true on success, false on error. |
244 | */ | 244 | */ |
245 | virtual bool addJournal( Journal * ) = 0; | 245 | virtual bool addJournal( Journal * ) = 0; |
246 | /** | 246 | /** |
247 | Return Journal for given date. | 247 | Return Journal for given date. |
248 | */ | 248 | */ |
249 | virtual Journal *journal( const QDate & ) = 0; | 249 | virtual Journal *journal( const QDate & ) = 0; |
250 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; | 250 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; |
251 | /** | 251 | /** |
252 | Return Journal with given UID. | 252 | Return Journal with given UID. |
253 | */ | 253 | */ |
254 | virtual Journal *journal( const QString &UID ) = 0; | 254 | virtual Journal *journal( const QString &UID ) = 0; |
255 | /** | 255 | /** |
256 | Return list of all Journal entries. | 256 | Return list of all Journal entries. |
257 | */ | 257 | */ |
258 | virtual QPtrList<Journal> journals() = 0; | 258 | virtual QPtrList<Journal> journals() = 0; |
259 | 259 | ||
260 | /** | 260 | /** |
261 | Searches all incidence types for an incidence with this unique | 261 | Searches all incidence types for an incidence with this unique |
262 | string identifier, returns a pointer or null. | 262 | string identifier, returns a pointer or null. |
263 | */ | 263 | */ |
264 | Incidence* incidence( const QString&UID ); | 264 | Incidence* incidence( const QString&UID ); |
265 | 265 | ||
266 | /** | 266 | /** |
267 | Setup relations for an incidence. | 267 | Setup relations for an incidence. |
268 | */ | 268 | */ |
269 | virtual void setupRelations( Incidence * ); | 269 | virtual void setupRelations( Incidence * ); |
270 | /** | 270 | /** |
271 | Remove all relations to an incidence | 271 | Remove all relations to an incidence |
272 | */ | 272 | */ |
273 | virtual void removeRelations( Incidence * ); | 273 | virtual void removeRelations( Incidence * ); |
274 | 274 | ||
275 | /** | 275 | /** |
276 | Set calendar filter, which filters events for the events() functions. | 276 | Set calendar filter, which filters events for the events() functions. |
277 | The Filter object is owned by the caller. | 277 | The Filter object is owned by the caller. |
278 | */ | 278 | */ |
279 | void setFilter( CalFilter * ); | 279 | void setFilter( CalFilter * ); |
280 | /** | 280 | /** |
281 | Return calendar filter. | 281 | Return calendar filter. |
282 | */ | 282 | */ |
283 | CalFilter *filter(); | 283 | CalFilter *filter(); |
284 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 284 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
285 | virtual QString nextSummary( ) const = 0; | 285 | virtual QString nextSummary( ) const = 0; |
286 | virtual void reInitAlarmSettings() = 0; | 286 | virtual void reInitAlarmSettings() = 0; |
287 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 287 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
288 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 288 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
289 | /** | 289 | /** |
290 | Return all alarms, which ocur in the given time interval. | 290 | Return all alarms, which ocur in the given time interval. |
291 | */ | 291 | */ |
292 | virtual Alarm::List alarms( const QDateTime &from, | 292 | virtual Alarm::List alarms( const QDateTime &from, |
293 | const QDateTime &to ) = 0; | 293 | const QDateTime &to ) = 0; |
294 | 294 | ||
295 | class Observer { | 295 | class Observer { |
296 | public: | 296 | public: |
297 | virtual void calendarModified( bool, Calendar * ) = 0; | 297 | virtual void calendarModified( bool, Calendar * ) = 0; |
298 | }; | 298 | }; |
299 | 299 | ||
300 | void registerObserver( Observer * ); | 300 | void registerObserver( Observer * ); |
301 | 301 | ||
302 | void setModified( bool ); | 302 | void setModified( bool ); |
303 | 303 | ||
304 | /** | 304 | /** |
305 | Set product id returned by loadedProductId(). This function is only | 305 | Set product id returned by loadedProductId(). This function is only |
306 | useful for the calendar loading code. | 306 | useful for the calendar loading code. |
307 | */ | 307 | */ |
308 | void setLoadedProductId( const QString & ); | 308 | void setLoadedProductId( const QString & ); |
309 | /** | 309 | /** |
310 | Return product id taken from file that has been loaded. Returns | 310 | Return product id taken from file that has been loaded. Returns |
311 | QString::null, if no calendar has been loaded. | 311 | QString::null, if no calendar has been loaded. |
312 | */ | 312 | */ |
313 | QString loadedProductId(); | 313 | QString loadedProductId(); |
314 | int defaultCalendar(); | 314 | int defaultCalendar(); |
315 | void setDontDeleteIncidencesOnClose (); | 315 | void setDontDeleteIncidencesOnClose (); |
316 | public slots: | 316 | public slots: |
317 | void setDefaultCalendar( int ); | 317 | void setDefaultCalendar( int ); |
318 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 318 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
319 | virtual void setAllCalendarEnabled( bool enable ) = 0; | 319 | virtual void setAllCalendarEnabled( bool enable ) = 0; |
320 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 320 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
321 | virtual void setReadOnly( int id, bool enable ) = 0; | 321 | virtual void setReadOnly( int id, bool enable ) = 0; |
322 | virtual void setDefaultCalendarEnabledOnly() = 0; | 322 | virtual void setDefaultCalendarEnabledOnly() = 0; |
323 | virtual void setCalendarRemove( int id ) = 0; | 323 | virtual void setCalendarRemove( int id ) = 0; |
324 | virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; | 324 | virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0; |
325 | 325 | ||
326 | signals: | 326 | signals: |
327 | void calendarChanged(); | 327 | void calendarChanged(); |
328 | void calendarSaved(); | 328 | void calendarSaved(); |
329 | void calendarLoaded(); | 329 | void calendarLoaded(); |
330 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 330 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
331 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 331 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
332 | 332 | ||
333 | protected: | 333 | protected: |
334 | /** | 334 | /** |
335 | Get unfiltered events, which occur on the given date. | 335 | Get unfiltered events, which occur on the given date. |
336 | */ | 336 | */ |
337 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 337 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
338 | /** | 338 | /** |
339 | Get unfiltered events, which occur on the given date. | 339 | Get unfiltered events, which occur on the given date. |
340 | */ | 340 | */ |
341 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 341 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
342 | bool sorted = false ) = 0; | 342 | bool sorted = false ) = 0; |
343 | /** | 343 | /** |
344 | Get events in a range of dates. If inclusive is set to true, only events | 344 | Get events in a range of dates. If inclusive is set to true, only events |
345 | are returned, which are completely included in the range. | 345 | are returned, which are completely included in the range. |
346 | */ | 346 | */ |
347 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 347 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
348 | bool inclusive = false ) = 0; | 348 | bool inclusive = false ) = 0; |
349 | 349 | ||
350 | Incidence *mNextAlarmIncidence; | 350 | Incidence *mNextAlarmIncidence; |
351 | Incidence *mUndoIncidence; | 351 | Incidence *mUndoIncidence; |
352 | int mDefaultCalendar; | 352 | int mDefaultCalendar; |
353 | bool mDeleteIncidencesOnClose; | 353 | bool mDeleteIncidencesOnClose; |
354 | 354 | ||
355 | private: | 355 | private: |
356 | void init(); | 356 | void init(); |
357 | 357 | ||
358 | QString mOwner; // who the calendar belongs to | 358 | QString mOwner; // who the calendar belongs to |
359 | QString mOwnerEmail; // email address of the owner | 359 | QString mOwnerEmail; // email address of the owner |
360 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 360 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
361 | bool mLocalTime; // use local time, not UTC or a time zone | 361 | bool mLocalTime; // use local time, not UTC or a time zone |
362 | 362 | ||
363 | 363 | ||
364 | CalFilter *mFilter; | 364 | CalFilter *mFilter; |
365 | CalFilter *mDefaultFilter; | 365 | CalFilter *mDefaultFilter; |
366 | 366 | ||
367 | 367 | ||
368 | QString mTimeZoneId; | 368 | QString mTimeZoneId; |
369 | 369 | ||
370 | Observer *mObserver; | 370 | Observer *mObserver; |
371 | bool mNewObserver; | 371 | bool mNewObserver; |
372 | 372 | ||
373 | bool mModified; | 373 | bool mModified; |
374 | 374 | ||
375 | QString mLoadedProductId; | 375 | QString mLoadedProductId; |
376 | 376 | ||
377 | // This list is used to put together related todos | 377 | // This list is used to put together related todos |
378 | QDict<Incidence> mOrphans; | 378 | QDict<Incidence> mOrphans; |
379 | QDict<Incidence> mOrphanUids; | 379 | QDict<Incidence> mOrphanUids; |
380 | }; | 380 | }; |
381 | 381 | ||
382 | } | 382 | } |
383 | 383 | ||
384 | #endif | 384 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index b02f706..ad8ace3 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,883 +1,892 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | registerObserver( 0 ); | 68 | registerObserver( 0 ); |
69 | if ( mDeleteIncidencesOnClose ) | 69 | if ( mDeleteIncidencesOnClose ) |
70 | close(); | 70 | close(); |
71 | } | 71 | } |
72 | bool CalendarLocal::mergeCalendarFile( QString name ) | 72 | bool CalendarLocal::mergeCalendarFile( QString name ) |
73 | { | 73 | { |
74 | CalendarLocal calendar( timeZoneId() ); | 74 | CalendarLocal calendar( timeZoneId() ); |
75 | calendar.setDefaultCalendar( 1 ); | 75 | calendar.setDefaultCalendar( 1 ); |
76 | if ( calendar.load( name ) ) { | 76 | if ( calendar.load( name ) ) { |
77 | mergeCalendar( &calendar ); | 77 | mergeCalendar( &calendar ); |
78 | return true; | 78 | return true; |
79 | } | 79 | } |
80 | return false; | 80 | return false; |
81 | } | 81 | } |
82 | 82 | ||
83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) | 83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly ) |
84 | { | 84 | { |
85 | Todo *todo;; | 85 | Todo *todo;; |
86 | Incidence *retVal = 0; | 86 | Incidence *retVal = 0; |
87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
88 | if ( todo->uid() == uid ) { | 88 | if ( todo->uid() == uid ) { |
89 | if ( enabledOnly ) | ||
90 | if ( !todo->calEnabled() ) | ||
91 | continue; | ||
89 | if ( doNotCheckDuplicates ) return todo; | 92 | if ( doNotCheckDuplicates ) return todo; |
90 | if ( retVal ) { | 93 | if ( retVal ) { |
91 | if ( retVal->calID() > todo->calID() ) { | 94 | if ( retVal->calID() > todo->calID() ) { |
92 | retVal = todo; | 95 | retVal = todo; |
93 | } | 96 | } |
94 | } else { | 97 | } else { |
95 | retVal = todo; | 98 | retVal = todo; |
96 | } | 99 | } |
97 | } | 100 | } |
98 | } | 101 | } |
99 | if ( retVal ) return retVal; | 102 | if ( retVal ) return retVal; |
100 | Event *event; | 103 | Event *event; |
101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 104 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
102 | if ( event->uid() == uid ) { | 105 | if ( event->uid() == uid ) { |
106 | if ( enabledOnly ) | ||
107 | if ( !event->calEnabled() ) | ||
108 | continue; | ||
103 | if ( doNotCheckDuplicates ) return event; | 109 | if ( doNotCheckDuplicates ) return event; |
104 | if ( retVal ) { | 110 | if ( retVal ) { |
105 | if ( retVal->calID() > event->calID() ) { | 111 | if ( retVal->calID() > event->calID() ) { |
106 | retVal = event; | 112 | retVal = event; |
107 | } | 113 | } |
108 | } else { | 114 | } else { |
109 | retVal = event; | 115 | retVal = event; |
110 | } | 116 | } |
111 | } | 117 | } |
112 | } | 118 | } |
113 | if ( retVal ) return retVal; | 119 | if ( retVal ) return retVal; |
114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 120 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
115 | if ( it->uid() == uid ) { | 121 | if ( it->uid() == uid ) { |
122 | if ( enabledOnly ) | ||
123 | if ( !it->calEnabled() ) | ||
124 | continue; | ||
116 | if ( doNotCheckDuplicates ) return it; | 125 | if ( doNotCheckDuplicates ) return it; |
117 | if ( retVal ) { | 126 | if ( retVal ) { |
118 | if ( retVal->calID() > it->calID() ) { | 127 | if ( retVal->calID() > it->calID() ) { |
119 | retVal = it; | 128 | retVal = it; |
120 | } | 129 | } |
121 | } else { | 130 | } else { |
122 | retVal = it; | 131 | retVal = it; |
123 | } | 132 | } |
124 | } | 133 | } |
125 | return retVal; | 134 | return retVal; |
126 | } | 135 | } |
127 | 136 | ||
128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 137 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
129 | { | 138 | { |
130 | // 1 look for raw inc in local | 139 | // 1 look for raw inc in local |
131 | // if inc not in remote, delete in local | 140 | // if inc not in remote, delete in local |
132 | // 2 look for raw inc in remote | 141 | // 2 look for raw inc in remote |
133 | // if inc in local, replace it | 142 | // if inc in local, replace it |
134 | // if not in local, add it to default calendar | 143 | // if not in local, add it to default calendar |
135 | QPtrList<Incidence> localInc = rawIncidences(); | 144 | QPtrList<Incidence> localInc = rawIncidences(); |
136 | Incidence* inL = localInc.first(); | 145 | Incidence* inL = localInc.first(); |
137 | while ( inL ) { | 146 | while ( inL ) { |
138 | if ( ! inL->isReadOnly () ) | 147 | if ( ! inL->isReadOnly () ) |
139 | if ( !remote->incidenceForUid( inL->uid(), true )) | 148 | if ( !remote->incidenceForUid( inL->uid(), true )) |
140 | deleteIncidence( inL ); | 149 | deleteIncidence( inL ); |
141 | inL = localInc.next(); | 150 | inL = localInc.next(); |
142 | } | 151 | } |
143 | QPtrList<Incidence> er = remote->rawIncidences(); | 152 | QPtrList<Incidence> er = remote->rawIncidences(); |
144 | Incidence* inR = er.first(); | 153 | Incidence* inR = er.first(); |
145 | while ( inR ) { | 154 | while ( inR ) { |
146 | inL = incidenceForUid( inR->uid(),false ); | 155 | inL = incidenceForUid( inR->uid(),false ); |
147 | if ( inL ) { | 156 | if ( inL ) { |
148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 157 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
149 | int calID = inL->calID(); | 158 | int calID = inL->calID(); |
150 | deleteIncidence( inL ); | 159 | deleteIncidence( inL ); |
151 | inL = inR->clone(); | 160 | inL = inR->clone(); |
152 | inL->setCalID_block( calID ); | 161 | inL->setCalID_block( calID ); |
153 | addIncidence( inL ); | 162 | addIncidence( inL ); |
154 | } | 163 | } |
155 | } else { | 164 | } else { |
156 | inL = inR->clone(); | 165 | inL = inR->clone(); |
157 | inL->setCalID_block( 0 );// add to default cal | 166 | inL->setCalID_block( 0 );// add to default cal |
158 | addIncidence( inL ); | 167 | addIncidence( inL ); |
159 | } | 168 | } |
160 | inR = er.next(); | 169 | inR = er.next(); |
161 | } | 170 | } |
162 | return true; | 171 | return true; |
163 | } | 172 | } |
164 | 173 | ||
165 | 174 | ||
166 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 175 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
167 | { | 176 | { |
168 | CalendarLocal calendar( timeZoneId() ); | 177 | CalendarLocal calendar( timeZoneId() ); |
169 | calendar.setDefaultCalendar( id ); | 178 | calendar.setDefaultCalendar( id ); |
170 | if ( calendar.load( name ) ) { | 179 | if ( calendar.load( name ) ) { |
171 | addCalendar( &calendar ); | 180 | addCalendar( &calendar ); |
172 | return true; | 181 | return true; |
173 | } | 182 | } |
174 | return false; | 183 | return false; |
175 | } | 184 | } |
176 | void CalendarLocal::setSyncEventsEnabled() | 185 | void CalendarLocal::setSyncEventsEnabled() |
177 | { | 186 | { |
178 | Event * ev; | 187 | Event * ev; |
179 | ev = mEventList.first(); | 188 | ev = mEventList.first(); |
180 | while ( ev ) { | 189 | while ( ev ) { |
181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 190 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
182 | ev->setCalEnabled( true ); | 191 | ev->setCalEnabled( true ); |
183 | ev = mEventList.next(); | 192 | ev = mEventList.next(); |
184 | } | 193 | } |
185 | } | 194 | } |
186 | void CalendarLocal::setSyncEventsReadOnly() | 195 | void CalendarLocal::setSyncEventsReadOnly() |
187 | { | 196 | { |
188 | Event * ev; | 197 | Event * ev; |
189 | ev = mEventList.first(); | 198 | ev = mEventList.first(); |
190 | while ( ev ) { | 199 | while ( ev ) { |
191 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | 200 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { |
192 | ev->setReadOnly( true ); | 201 | ev->setReadOnly( true ); |
193 | } | 202 | } |
194 | ev = mEventList.next(); | 203 | ev = mEventList.next(); |
195 | } | 204 | } |
196 | } | 205 | } |
197 | 206 | ||
198 | void CalendarLocal::addCalendar( Calendar* cal ) | 207 | void CalendarLocal::addCalendar( Calendar* cal ) |
199 | { | 208 | { |
200 | cal->setDontDeleteIncidencesOnClose(); | 209 | cal->setDontDeleteIncidencesOnClose(); |
201 | setSyncEventsEnabled(); | 210 | setSyncEventsEnabled(); |
202 | { | 211 | { |
203 | QPtrList<Event> EventList = cal->rawEvents(); | 212 | QPtrList<Event> EventList = cal->rawEvents(); |
204 | QPtrList<Event> el; | 213 | QPtrList<Event> el; |
205 | Event * ev = EventList.first(); | 214 | Event * ev = EventList.first(); |
206 | while ( ev ) { | 215 | while ( ev ) { |
207 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { | 216 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { |
208 | Event * se = event( ev->uid() ); | 217 | Event * se = event( ev->uid() ); |
209 | if ( se ) | 218 | if ( se ) |
210 | el.append( se ); | 219 | el.append( se ); |
211 | ev->setCalID_block( 1 ); | 220 | ev->setCalID_block( 1 ); |
212 | } | 221 | } |
213 | ev->unRegisterObserver( cal ); | 222 | ev->unRegisterObserver( cal ); |
214 | ev->registerObserver( this ); | 223 | ev->registerObserver( this ); |
215 | mEventList.append( ev ); | 224 | mEventList.append( ev ); |
216 | ev = EventList.next(); | 225 | ev = EventList.next(); |
217 | } | 226 | } |
218 | for ( ev = el.first(); ev; ev = el.next() ) { | 227 | for ( ev = el.first(); ev; ev = el.next() ) { |
219 | deleteIncidence ( ev ); | 228 | deleteIncidence ( ev ); |
220 | } | 229 | } |
221 | } | 230 | } |
222 | { | 231 | { |
223 | 232 | ||
224 | QPtrList<Todo> TodoList = cal->rawTodos(); | 233 | QPtrList<Todo> TodoList = cal->rawTodos(); |
225 | Todo * ev = TodoList.first(); | 234 | Todo * ev = TodoList.first(); |
226 | while ( ev ) { | 235 | while ( ev ) { |
227 | QString rel = ev->relatedToUid(); | 236 | QString rel = ev->relatedToUid(); |
228 | if ( !rel.isEmpty() ){ | 237 | if ( !rel.isEmpty() ){ |
229 | ev->setRelatedTo ( 0 ); | 238 | ev->setRelatedTo ( 0 ); |
230 | ev->setRelatedToUid( rel ); | 239 | ev->setRelatedToUid( rel ); |
231 | } | 240 | } |
232 | ev = TodoList.next(); | 241 | ev = TodoList.next(); |
233 | } | 242 | } |
234 | //TodoList = cal->rawTodos(); | 243 | //TodoList = cal->rawTodos(); |
235 | ev = TodoList.first(); | 244 | ev = TodoList.first(); |
236 | while ( ev ) { | 245 | while ( ev ) { |
237 | ev->unRegisterObserver( cal ); | 246 | ev->unRegisterObserver( cal ); |
238 | ev->registerObserver( this ); | 247 | ev->registerObserver( this ); |
239 | mTodoList.append( ev ); | 248 | mTodoList.append( ev ); |
240 | setupRelations( ev ); | 249 | setupRelations( ev ); |
241 | ev = TodoList.next(); | 250 | ev = TodoList.next(); |
242 | } | 251 | } |
243 | } | 252 | } |
244 | { | 253 | { |
245 | QPtrList<Journal> JournalList = cal->journals(); | 254 | QPtrList<Journal> JournalList = cal->journals(); |
246 | Journal * ev = JournalList.first(); | 255 | Journal * ev = JournalList.first(); |
247 | while ( ev ) { | 256 | while ( ev ) { |
248 | ev->unRegisterObserver( cal ); | 257 | ev->unRegisterObserver( cal ); |
249 | ev->registerObserver( this ); | 258 | ev->registerObserver( this ); |
250 | mJournalList.append( ev ); | 259 | mJournalList.append( ev ); |
251 | ev = JournalList.next(); | 260 | ev = JournalList.next(); |
252 | } | 261 | } |
253 | } | 262 | } |
254 | setModified( true ); | 263 | setModified( true ); |
255 | } | 264 | } |
256 | bool CalendarLocal::load( const QString &fileName ) | 265 | bool CalendarLocal::load( const QString &fileName ) |
257 | { | 266 | { |
258 | FileStorage storage( this, fileName ); | 267 | FileStorage storage( this, fileName ); |
259 | return storage.load(); | 268 | return storage.load(); |
260 | } | 269 | } |
261 | 270 | ||
262 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 271 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
263 | { | 272 | { |
264 | FileStorage storage( this, fileName, format ); | 273 | FileStorage storage( this, fileName, format ); |
265 | return storage.save(); | 274 | return storage.save(); |
266 | } | 275 | } |
267 | 276 | ||
268 | void CalendarLocal::stopAllTodos() | 277 | void CalendarLocal::stopAllTodos() |
269 | { | 278 | { |
270 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 279 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
271 | it->setRunning( false ); | 280 | it->setRunning( false ); |
272 | 281 | ||
273 | } | 282 | } |
274 | void CalendarLocal::close() | 283 | void CalendarLocal::close() |
275 | { | 284 | { |
276 | 285 | ||
277 | Todo * i; | 286 | Todo * i; |
278 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 287 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
279 | 288 | ||
280 | mEventList.setAutoDelete( true ); | 289 | mEventList.setAutoDelete( true ); |
281 | mTodoList.setAutoDelete( true ); | 290 | mTodoList.setAutoDelete( true ); |
282 | mJournalList.setAutoDelete( true ); | 291 | mJournalList.setAutoDelete( true ); |
283 | 292 | ||
284 | mEventList.clear(); | 293 | mEventList.clear(); |
285 | mTodoList.clear(); | 294 | mTodoList.clear(); |
286 | mJournalList.clear(); | 295 | mJournalList.clear(); |
287 | 296 | ||
288 | mEventList.setAutoDelete( false ); | 297 | mEventList.setAutoDelete( false ); |
289 | mTodoList.setAutoDelete( false ); | 298 | mTodoList.setAutoDelete( false ); |
290 | mJournalList.setAutoDelete( false ); | 299 | mJournalList.setAutoDelete( false ); |
291 | 300 | ||
292 | setModified( false ); | 301 | setModified( false ); |
293 | } | 302 | } |
294 | 303 | ||
295 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 304 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
296 | { | 305 | { |
297 | QString cat; | 306 | QString cat; |
298 | bool isBirthday = true; | 307 | bool isBirthday = true; |
299 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 308 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
300 | isBirthday = false; | 309 | isBirthday = false; |
301 | cat = i18n( "Anniversary" ); | 310 | cat = i18n( "Anniversary" ); |
302 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 311 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
303 | isBirthday = true; | 312 | isBirthday = true; |
304 | cat = i18n( "Birthday" ); | 313 | cat = i18n( "Birthday" ); |
305 | } else { | 314 | } else { |
306 | qDebug("addAnniversaryNoDup called without fitting category! "); | 315 | qDebug("addAnniversaryNoDup called without fitting category! "); |
307 | return false; | 316 | return false; |
308 | } | 317 | } |
309 | Event * eve; | 318 | Event * eve; |
310 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 319 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
311 | if ( !(eve->categories().contains( cat ) )) | 320 | if ( !(eve->categories().contains( cat ) )) |
312 | continue; | 321 | continue; |
313 | // now we have an event with fitting category | 322 | // now we have an event with fitting category |
314 | if ( eve->dtStart().date() != event->dtStart().date() ) | 323 | if ( eve->dtStart().date() != event->dtStart().date() ) |
315 | continue; | 324 | continue; |
316 | // now we have an event with fitting category+date | 325 | // now we have an event with fitting category+date |
317 | if ( eve->summary() != event->summary() ) | 326 | if ( eve->summary() != event->summary() ) |
318 | continue; | 327 | continue; |
319 | // now we have an event with fitting category+date+summary | 328 | // now we have an event with fitting category+date+summary |
320 | return false; | 329 | return false; |
321 | } | 330 | } |
322 | return addEvent( event ); | 331 | return addEvent( event ); |
323 | 332 | ||
324 | } | 333 | } |
325 | bool CalendarLocal::addEventNoDup( Event *event ) | 334 | bool CalendarLocal::addEventNoDup( Event *event ) |
326 | { | 335 | { |
327 | Event * eve; | 336 | Event * eve; |
328 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 337 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
329 | if ( *eve == *event ) { | 338 | if ( *eve == *event ) { |
330 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 339 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
331 | return false; | 340 | return false; |
332 | } | 341 | } |
333 | } | 342 | } |
334 | return addEvent( event ); | 343 | return addEvent( event ); |
335 | } | 344 | } |
336 | 345 | ||
337 | bool CalendarLocal::addEvent( Event *event ) | 346 | bool CalendarLocal::addEvent( Event *event ) |
338 | { | 347 | { |
339 | insertEvent( event ); | 348 | insertEvent( event ); |
340 | 349 | ||
341 | event->registerObserver( this ); | 350 | event->registerObserver( this ); |
342 | 351 | ||
343 | setModified( true ); | 352 | setModified( true ); |
344 | if ( event->calID() == 0 ) | 353 | if ( event->calID() == 0 ) |
345 | event->setCalID_block( mDefaultCalendar ); | 354 | event->setCalID_block( mDefaultCalendar ); |
346 | event->setCalEnabled( true ); | 355 | event->setCalEnabled( true ); |
347 | 356 | ||
348 | return true; | 357 | return true; |
349 | } | 358 | } |
350 | 359 | ||
351 | void CalendarLocal::deleteEvent( Event *event ) | 360 | void CalendarLocal::deleteEvent( Event *event ) |
352 | { | 361 | { |
353 | clearUndo(event); | 362 | clearUndo(event); |
354 | if ( mEventList.removeRef( event ) ) { | 363 | if ( mEventList.removeRef( event ) ) { |
355 | setModified( true ); | 364 | setModified( true ); |
356 | } | 365 | } |
357 | } | 366 | } |
358 | 367 | ||
359 | 368 | ||
360 | Event *CalendarLocal::event( const QString &uid ) | 369 | Event *CalendarLocal::event( const QString &uid ) |
361 | { | 370 | { |
362 | Event *event; | 371 | Event *event; |
363 | Event *retVal = 0; | 372 | Event *retVal = 0; |
364 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 373 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
365 | if ( event->calEnabled() && event->uid() == uid ) { | 374 | if ( event->calEnabled() && event->uid() == uid ) { |
366 | if ( retVal ) { | 375 | if ( retVal ) { |
367 | if ( retVal->calID() > event->calID() ) { | 376 | if ( retVal->calID() > event->calID() ) { |
368 | retVal = event; | 377 | retVal = event; |
369 | } | 378 | } |
370 | } else { | 379 | } else { |
371 | retVal = event; | 380 | retVal = event; |
372 | } | 381 | } |
373 | } | 382 | } |
374 | } | 383 | } |
375 | return retVal; | 384 | return retVal; |
376 | } | 385 | } |
377 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 386 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
378 | { | 387 | { |
379 | Todo * eve; | 388 | Todo * eve; |
380 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 389 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
381 | if ( *eve == *todo ) { | 390 | if ( *eve == *todo ) { |
382 | //qDebug("duplicate todo found! not inserted! "); | 391 | //qDebug("duplicate todo found! not inserted! "); |
383 | return false; | 392 | return false; |
384 | } | 393 | } |
385 | } | 394 | } |
386 | return addTodo( todo ); | 395 | return addTodo( todo ); |
387 | } | 396 | } |
388 | bool CalendarLocal::addTodo( Todo *todo ) | 397 | bool CalendarLocal::addTodo( Todo *todo ) |
389 | { | 398 | { |
390 | mTodoList.append( todo ); | 399 | mTodoList.append( todo ); |
391 | 400 | ||
392 | todo->registerObserver( this ); | 401 | todo->registerObserver( this ); |
393 | 402 | ||
394 | // Set up subtask relations | 403 | // Set up subtask relations |
395 | setupRelations( todo ); | 404 | setupRelations( todo ); |
396 | 405 | ||
397 | setModified( true ); | 406 | setModified( true ); |
398 | if ( todo->calID() == 0 ) | 407 | if ( todo->calID() == 0 ) |
399 | todo->setCalID_block( mDefaultCalendar ); | 408 | todo->setCalID_block( mDefaultCalendar ); |
400 | todo->setCalEnabled( true ); | 409 | todo->setCalEnabled( true ); |
401 | return true; | 410 | return true; |
402 | } | 411 | } |
403 | 412 | ||
404 | void CalendarLocal::deleteTodo( Todo *todo ) | 413 | void CalendarLocal::deleteTodo( Todo *todo ) |
405 | { | 414 | { |
406 | // Handle orphaned children | 415 | // Handle orphaned children |
407 | removeRelations( todo ); | 416 | removeRelations( todo ); |
408 | clearUndo(todo); | 417 | clearUndo(todo); |
409 | 418 | ||
410 | if ( mTodoList.removeRef( todo ) ) { | 419 | if ( mTodoList.removeRef( todo ) ) { |
411 | setModified( true ); | 420 | setModified( true ); |
412 | } | 421 | } |
413 | } | 422 | } |
414 | 423 | ||
415 | QPtrList<Todo> CalendarLocal::rawTodos() | 424 | QPtrList<Todo> CalendarLocal::rawTodos() |
416 | { | 425 | { |
417 | QPtrList<Todo> el; | 426 | QPtrList<Todo> el; |
418 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 427 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
419 | if ( it->calEnabled() ) el.append( it ); | 428 | if ( it->calEnabled() ) el.append( it ); |
420 | return el; | 429 | return el; |
421 | } | 430 | } |
422 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 431 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
423 | { | 432 | { |
424 | Todo *todo; | 433 | Todo *todo; |
425 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 434 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
426 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 435 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
427 | } | 436 | } |
428 | 437 | ||
429 | return 0; | 438 | return 0; |
430 | } | 439 | } |
431 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 440 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
432 | { | 441 | { |
433 | QPtrList<Incidence> all = rawIncidences() ; | 442 | QPtrList<Incidence> all = rawIncidences() ; |
434 | Incidence *inc; | 443 | Incidence *inc; |
435 | for ( inc = all.first(); inc; inc = all.next() ) { | 444 | for ( inc = all.first(); inc; inc = all.next() ) { |
436 | inc->removeID( syncProfile ); | 445 | inc->removeID( syncProfile ); |
437 | } | 446 | } |
438 | if ( syncProfile.isEmpty() ) { | 447 | if ( syncProfile.isEmpty() ) { |
439 | QPtrList<Event> el; | 448 | QPtrList<Event> el; |
440 | Event *todo; | 449 | Event *todo; |
441 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 450 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
442 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 451 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
443 | el.append( todo ); | 452 | el.append( todo ); |
444 | } | 453 | } |
445 | for ( todo = el.first(); todo; todo = el.next() ) { | 454 | for ( todo = el.first(); todo; todo = el.next() ) { |
446 | deleteIncidence ( todo ); | 455 | deleteIncidence ( todo ); |
447 | } | 456 | } |
448 | } else { | 457 | } else { |
449 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 458 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
450 | if ( lse ) | 459 | if ( lse ) |
451 | deleteIncidence ( lse ); | 460 | deleteIncidence ( lse ); |
452 | } | 461 | } |
453 | } | 462 | } |
454 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 463 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
455 | { | 464 | { |
456 | QPtrList<Event> el; | 465 | QPtrList<Event> el; |
457 | Event *todo; | 466 | Event *todo; |
458 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 467 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
459 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 468 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
460 | if ( todo->summary().left(3) == "E: " ) | 469 | if ( todo->summary().left(3) == "E: " ) |
461 | el.append( todo ); | 470 | el.append( todo ); |
462 | } | 471 | } |
463 | 472 | ||
464 | return el; | 473 | return el; |
465 | 474 | ||
466 | } | 475 | } |
467 | Event *CalendarLocal::event( QString syncProf, QString id ) | 476 | Event *CalendarLocal::event( QString syncProf, QString id ) |
468 | { | 477 | { |
469 | Event *todo; | 478 | Event *todo; |
470 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 479 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
471 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 480 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
472 | } | 481 | } |
473 | 482 | ||
474 | return 0; | 483 | return 0; |
475 | } | 484 | } |
476 | Todo *CalendarLocal::todo( const QString &uid ) | 485 | Todo *CalendarLocal::todo( const QString &uid ) |
477 | { | 486 | { |
478 | Todo *todo; | 487 | Todo *todo; |
479 | Todo *retVal = 0; | 488 | Todo *retVal = 0; |
480 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 489 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
481 | if ( todo->calEnabled() && todo->uid() == uid ) { | 490 | if ( todo->calEnabled() && todo->uid() == uid ) { |
482 | if ( retVal ) { | 491 | if ( retVal ) { |
483 | if ( retVal->calID() > todo->calID() ) { | 492 | if ( retVal->calID() > todo->calID() ) { |
484 | retVal = todo; | 493 | retVal = todo; |
485 | } | 494 | } |
486 | } else { | 495 | } else { |
487 | retVal = todo; | 496 | retVal = todo; |
488 | } | 497 | } |
489 | } | 498 | } |
490 | } | 499 | } |
491 | return retVal; | 500 | return retVal; |
492 | } | 501 | } |
493 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) | 502 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) |
494 | { | 503 | { |
495 | events = 0; | 504 | events = 0; |
496 | todos = 0; | 505 | todos = 0; |
497 | journals = 0; | 506 | journals = 0; |
498 | { | 507 | { |
499 | Todo *todo; | 508 | Todo *todo; |
500 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 509 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
501 | if ( todo->calID() == calId ) | 510 | if ( todo->calID() == calId ) |
502 | ++todos; | 511 | ++todos; |
503 | } | 512 | } |
504 | } | 513 | } |
505 | { | 514 | { |
506 | Event *todo; | 515 | Event *todo; |
507 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 516 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
508 | if ( todo->calID() == calId ) | 517 | if ( todo->calID() == calId ) |
509 | ++events; | 518 | ++events; |
510 | 519 | ||
511 | } | 520 | } |
512 | } | 521 | } |
513 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 522 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
514 | if ( it->calID() == calId ) ++journals; | 523 | if ( it->calID() == calId ) ++journals; |
515 | 524 | ||
516 | } | 525 | } |
517 | QString CalendarLocal::nextSummary() const | 526 | QString CalendarLocal::nextSummary() const |
518 | { | 527 | { |
519 | return mNextSummary; | 528 | return mNextSummary; |
520 | } | 529 | } |
521 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 530 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
522 | { | 531 | { |
523 | return mNextAlarmEventDateTime; | 532 | return mNextAlarmEventDateTime; |
524 | } | 533 | } |
525 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 534 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
526 | { | 535 | { |
527 | //mNextAlarmIncidence | 536 | //mNextAlarmIncidence |
528 | //mNextAlarmDateTime | 537 | //mNextAlarmDateTime |
529 | //return mNextSummary; | 538 | //return mNextSummary; |
530 | //return mNextAlarmEventDateTime; | 539 | //return mNextAlarmEventDateTime; |
531 | bool newNextAlarm = false; | 540 | bool newNextAlarm = false; |
532 | bool computeNextAlarm = false; | 541 | bool computeNextAlarm = false; |
533 | bool ok; | 542 | bool ok; |
534 | int offset; | 543 | int offset; |
535 | QDateTime nextA; | 544 | QDateTime nextA; |
536 | // QString nextSum; | 545 | // QString nextSum; |
537 | //QDateTime nextEvent; | 546 | //QDateTime nextEvent; |
538 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 547 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
539 | computeNextAlarm = true; | 548 | computeNextAlarm = true; |
540 | } else { | 549 | } else { |
541 | if ( ! deleted ) { | 550 | if ( ! deleted ) { |
542 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 551 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
543 | if ( ok ) { | 552 | if ( ok ) { |
544 | if ( nextA < mNextAlarmDateTime ) { | 553 | if ( nextA < mNextAlarmDateTime ) { |
545 | deRegisterAlarm(); | 554 | deRegisterAlarm(); |
546 | mNextAlarmDateTime = nextA; | 555 | mNextAlarmDateTime = nextA; |
547 | mNextSummary = incidence->summary(); | 556 | mNextSummary = incidence->summary(); |
548 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 557 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
549 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 558 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
550 | newNextAlarm = true; | 559 | newNextAlarm = true; |
551 | mNextAlarmIncidence = incidence; | 560 | mNextAlarmIncidence = incidence; |
552 | } else { | 561 | } else { |
553 | if ( incidence == mNextAlarmIncidence ) { | 562 | if ( incidence == mNextAlarmIncidence ) { |
554 | computeNextAlarm = true; | 563 | computeNextAlarm = true; |
555 | } | 564 | } |
556 | } | 565 | } |
557 | } else { | 566 | } else { |
558 | if ( mNextAlarmIncidence == incidence ) { | 567 | if ( mNextAlarmIncidence == incidence ) { |
559 | computeNextAlarm = true; | 568 | computeNextAlarm = true; |
560 | } | 569 | } |
561 | } | 570 | } |
562 | } else { // deleted | 571 | } else { // deleted |
563 | if ( incidence == mNextAlarmIncidence ) { | 572 | if ( incidence == mNextAlarmIncidence ) { |
564 | computeNextAlarm = true; | 573 | computeNextAlarm = true; |
565 | } | 574 | } |
566 | } | 575 | } |
567 | } | 576 | } |
568 | if ( computeNextAlarm ) { | 577 | if ( computeNextAlarm ) { |
569 | deRegisterAlarm(); | 578 | deRegisterAlarm(); |
570 | nextA = nextAlarm( 1000 ); | 579 | nextA = nextAlarm( 1000 ); |
571 | if (! mNextAlarmIncidence ) { | 580 | if (! mNextAlarmIncidence ) { |
572 | return; | 581 | return; |
573 | } | 582 | } |
574 | newNextAlarm = true; | 583 | newNextAlarm = true; |
575 | } | 584 | } |
576 | if ( newNextAlarm ) | 585 | if ( newNextAlarm ) |
577 | registerAlarm(); | 586 | registerAlarm(); |
578 | } | 587 | } |
579 | QString CalendarLocal:: getAlarmNotification() | 588 | QString CalendarLocal:: getAlarmNotification() |
580 | { | 589 | { |
581 | QString ret; | 590 | QString ret; |
582 | // this should not happen | 591 | // this should not happen |
583 | if (! mNextAlarmIncidence ) | 592 | if (! mNextAlarmIncidence ) |
584 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 593 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
585 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 594 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
586 | if ( alarm->type() == Alarm::Procedure ) { | 595 | if ( alarm->type() == Alarm::Procedure ) { |
587 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 596 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
588 | } else { | 597 | } else { |
589 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 598 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
590 | } | 599 | } |
591 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 600 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
592 | if ( mNextSummary.length() > 25 ) | 601 | if ( mNextSummary.length() > 25 ) |
593 | ret += "\n" + mNextSummary.mid(25, 25 ); | 602 | ret += "\n" + mNextSummary.mid(25, 25 ); |
594 | ret+= "\n"+mNextAlarmEventDateTimeString; | 603 | ret+= "\n"+mNextAlarmEventDateTimeString; |
595 | return ret; | 604 | return ret; |
596 | } | 605 | } |
597 | void CalendarLocal::registerAlarm() | 606 | void CalendarLocal::registerAlarm() |
598 | { | 607 | { |
599 | mLastAlarmNotificationString = getAlarmNotification(); | 608 | mLastAlarmNotificationString = getAlarmNotification(); |
600 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 609 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
601 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 610 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
602 | // #ifndef DESKTOP_VERSION | 611 | // #ifndef DESKTOP_VERSION |
603 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 612 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
604 | // #endif | 613 | // #endif |
605 | } | 614 | } |
606 | void CalendarLocal::deRegisterAlarm() | 615 | void CalendarLocal::deRegisterAlarm() |
607 | { | 616 | { |
608 | if ( mLastAlarmNotificationString.isNull() ) | 617 | if ( mLastAlarmNotificationString.isNull() ) |
609 | return; | 618 | return; |
610 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 619 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
611 | 620 | ||
612 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 621 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
613 | mNextAlarmEventDateTime = QDateTime(); | 622 | mNextAlarmEventDateTime = QDateTime(); |
614 | // #ifndef DESKTOP_VERSION | 623 | // #ifndef DESKTOP_VERSION |
615 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 624 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
616 | // #endif | 625 | // #endif |
617 | } | 626 | } |
618 | 627 | ||
619 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 628 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
620 | { | 629 | { |
621 | QPtrList<Todo> todos; | 630 | QPtrList<Todo> todos; |
622 | 631 | ||
623 | Todo *todo; | 632 | Todo *todo; |
624 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 633 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
625 | if ( !todo->calEnabled() ) continue; | 634 | if ( !todo->calEnabled() ) continue; |
626 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 635 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
627 | todos.append( todo ); | 636 | todos.append( todo ); |
628 | } | 637 | } |
629 | } | 638 | } |
630 | 639 | ||
631 | filter()->apply( &todos ); | 640 | filter()->apply( &todos ); |
632 | return todos; | 641 | return todos; |
633 | } | 642 | } |
634 | void CalendarLocal::reInitAlarmSettings() | 643 | void CalendarLocal::reInitAlarmSettings() |
635 | { | 644 | { |
636 | if ( !mNextAlarmIncidence ) { | 645 | if ( !mNextAlarmIncidence ) { |
637 | nextAlarm( 1000 ); | 646 | nextAlarm( 1000 ); |
638 | } | 647 | } |
639 | deRegisterAlarm(); | 648 | deRegisterAlarm(); |
640 | mNextAlarmIncidence = 0; | 649 | mNextAlarmIncidence = 0; |
641 | checkAlarmForIncidence( 0, false ); | 650 | checkAlarmForIncidence( 0, false ); |
642 | 651 | ||
643 | } | 652 | } |
644 | 653 | ||
645 | 654 | ||
646 | 655 | ||
647 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 656 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
648 | { | 657 | { |
649 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 658 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
650 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 659 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
651 | QDateTime next; | 660 | QDateTime next; |
652 | Event *e; | 661 | Event *e; |
653 | bool ok; | 662 | bool ok; |
654 | bool found = false; | 663 | bool found = false; |
655 | int offset; | 664 | int offset; |
656 | mNextAlarmIncidence = 0; | 665 | mNextAlarmIncidence = 0; |
657 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 666 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
658 | if ( !e->calEnabled() ) continue; | 667 | if ( !e->calEnabled() ) continue; |
659 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 668 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
660 | if ( ok ) { | 669 | if ( ok ) { |
661 | if ( next < nextA ) { | 670 | if ( next < nextA ) { |
662 | nextA = next; | 671 | nextA = next; |
663 | found = true; | 672 | found = true; |
664 | mNextSummary = e->summary(); | 673 | mNextSummary = e->summary(); |
665 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 674 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
666 | mNextAlarmIncidence = (Incidence *) e; | 675 | mNextAlarmIncidence = (Incidence *) e; |
667 | } | 676 | } |
668 | } | 677 | } |
669 | } | 678 | } |
670 | Todo *t; | 679 | Todo *t; |
671 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 680 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
672 | if ( !t->calEnabled() ) continue; | 681 | if ( !t->calEnabled() ) continue; |
673 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 682 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
674 | if ( ok ) { | 683 | if ( ok ) { |
675 | if ( next < nextA ) { | 684 | if ( next < nextA ) { |
676 | nextA = next; | 685 | nextA = next; |
677 | found = true; | 686 | found = true; |
678 | mNextSummary = t->summary(); | 687 | mNextSummary = t->summary(); |
679 | mNextAlarmEventDateTime = next.addSecs(offset ); | 688 | mNextAlarmEventDateTime = next.addSecs(offset ); |
680 | mNextAlarmIncidence = (Incidence *) t; | 689 | mNextAlarmIncidence = (Incidence *) t; |
681 | } | 690 | } |
682 | } | 691 | } |
683 | } | 692 | } |
684 | if ( mNextAlarmIncidence ) { | 693 | if ( mNextAlarmIncidence ) { |
685 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 694 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
686 | mNextAlarmDateTime = nextA; | 695 | mNextAlarmDateTime = nextA; |
687 | } | 696 | } |
688 | return nextA; | 697 | return nextA; |
689 | } | 698 | } |
690 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 699 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
691 | { | 700 | { |
692 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 701 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
693 | } | 702 | } |
694 | 703 | ||
695 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 704 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
696 | { | 705 | { |
697 | 706 | ||
698 | Alarm::List alarms; | 707 | Alarm::List alarms; |
699 | 708 | ||
700 | Event *e; | 709 | Event *e; |
701 | 710 | ||
702 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 711 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
703 | if ( !e->calEnabled() ) continue; | 712 | if ( !e->calEnabled() ) continue; |
704 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 713 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
705 | else appendAlarms( alarms, e, from, to ); | 714 | else appendAlarms( alarms, e, from, to ); |
706 | } | 715 | } |
707 | 716 | ||
708 | Todo *t; | 717 | Todo *t; |
709 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 718 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
710 | if ( !t->calEnabled() ) continue; | 719 | if ( !t->calEnabled() ) continue; |
711 | appendAlarms( alarms, t, from, to ); | 720 | appendAlarms( alarms, t, from, to ); |
712 | } | 721 | } |
713 | 722 | ||
714 | return alarms; | 723 | return alarms; |
715 | } | 724 | } |
716 | 725 | ||
717 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 726 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
718 | const QDateTime &from, const QDateTime &to ) | 727 | const QDateTime &from, const QDateTime &to ) |
719 | { | 728 | { |
720 | QPtrList<Alarm> alarmList = incidence->alarms(); | 729 | QPtrList<Alarm> alarmList = incidence->alarms(); |
721 | Alarm *alarm; | 730 | Alarm *alarm; |
722 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 731 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
723 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 732 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
724 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 733 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
725 | if ( alarm->enabled() ) { | 734 | if ( alarm->enabled() ) { |
726 | if ( alarm->time() >= from && alarm->time() <= to ) { | 735 | if ( alarm->time() >= from && alarm->time() <= to ) { |
727 | alarms.append( alarm ); | 736 | alarms.append( alarm ); |
728 | } | 737 | } |
729 | } | 738 | } |
730 | } | 739 | } |
731 | } | 740 | } |
732 | 741 | ||
733 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 742 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
734 | Incidence *incidence, | 743 | Incidence *incidence, |
735 | const QDateTime &from, | 744 | const QDateTime &from, |
736 | const QDateTime &to ) | 745 | const QDateTime &to ) |
737 | { | 746 | { |
738 | 747 | ||
739 | QPtrList<Alarm> alarmList = incidence->alarms(); | 748 | QPtrList<Alarm> alarmList = incidence->alarms(); |
740 | Alarm *alarm; | 749 | Alarm *alarm; |
741 | QDateTime qdt; | 750 | QDateTime qdt; |
742 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 751 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
743 | if (incidence->recursOn(from.date())) { | 752 | if (incidence->recursOn(from.date())) { |
744 | qdt.setTime(alarm->time().time()); | 753 | qdt.setTime(alarm->time().time()); |
745 | qdt.setDate(from.date()); | 754 | qdt.setDate(from.date()); |
746 | } | 755 | } |
747 | else qdt = alarm->time(); | 756 | else qdt = alarm->time(); |
748 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 757 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
749 | if ( alarm->enabled() ) { | 758 | if ( alarm->enabled() ) { |
750 | if ( qdt >= from && qdt <= to ) { | 759 | if ( qdt >= from && qdt <= to ) { |
751 | alarms.append( alarm ); | 760 | alarms.append( alarm ); |
752 | } | 761 | } |
753 | } | 762 | } |
754 | } | 763 | } |
755 | } | 764 | } |
756 | 765 | ||
757 | 766 | ||
758 | /****************************** PROTECTED METHODS ****************************/ | 767 | /****************************** PROTECTED METHODS ****************************/ |
759 | 768 | ||
760 | // after changes are made to an event, this should be called. | 769 | // after changes are made to an event, this should be called. |
761 | void CalendarLocal::update( IncidenceBase *incidence ) | 770 | void CalendarLocal::update( IncidenceBase *incidence ) |
762 | { | 771 | { |
763 | incidence->setSyncStatus( Event::SYNCMOD ); | 772 | incidence->setSyncStatus( Event::SYNCMOD ); |
764 | incidence->setLastModified( QDateTime::currentDateTime() ); | 773 | incidence->setLastModified( QDateTime::currentDateTime() ); |
765 | // we should probably update the revision number here, | 774 | // we should probably update the revision number here, |
766 | // or internally in the Event itself when certain things change. | 775 | // or internally in the Event itself when certain things change. |
767 | // need to verify with ical documentation. | 776 | // need to verify with ical documentation. |
768 | 777 | ||
769 | setModified( true ); | 778 | setModified( true ); |
770 | } | 779 | } |
771 | 780 | ||
772 | void CalendarLocal::insertEvent( Event *event ) | 781 | void CalendarLocal::insertEvent( Event *event ) |
773 | { | 782 | { |
774 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 783 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
775 | } | 784 | } |
776 | 785 | ||
777 | 786 | ||
778 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 787 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
779 | { | 788 | { |
780 | QPtrList<Event> eventList; | 789 | QPtrList<Event> eventList; |
781 | 790 | ||
782 | Event *event; | 791 | Event *event; |
783 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 792 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
784 | if ( !event->calEnabled() ) continue; | 793 | if ( !event->calEnabled() ) continue; |
785 | if ( event->doesRecur() ) { | 794 | if ( event->doesRecur() ) { |
786 | if ( event->isMultiDay() ) { | 795 | if ( event->isMultiDay() ) { |
787 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 796 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
788 | int i; | 797 | int i; |
789 | for ( i = 0; i <= extraDays; i++ ) { | 798 | for ( i = 0; i <= extraDays; i++ ) { |
790 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 799 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
791 | eventList.append( event ); | 800 | eventList.append( event ); |
792 | break; | 801 | break; |
793 | } | 802 | } |
794 | } | 803 | } |
795 | } else { | 804 | } else { |
796 | if ( event->recursOn( qd ) ) | 805 | if ( event->recursOn( qd ) ) |
797 | eventList.append( event ); | 806 | eventList.append( event ); |
798 | } | 807 | } |
799 | } else { | 808 | } else { |
800 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 809 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
801 | eventList.append( event ); | 810 | eventList.append( event ); |
802 | } | 811 | } |
803 | } | 812 | } |
804 | } | 813 | } |
805 | 814 | ||
806 | if ( !sorted ) { | 815 | if ( !sorted ) { |
807 | return eventList; | 816 | return eventList; |
808 | } | 817 | } |
809 | 818 | ||
810 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 819 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
811 | // now, we have to sort it based on dtStart.time() | 820 | // now, we have to sort it based on dtStart.time() |
812 | QPtrList<Event> eventListSorted; | 821 | QPtrList<Event> eventListSorted; |
813 | Event *sortEvent; | 822 | Event *sortEvent; |
814 | for ( event = eventList.first(); event; event = eventList.next() ) { | 823 | for ( event = eventList.first(); event; event = eventList.next() ) { |
815 | sortEvent = eventListSorted.first(); | 824 | sortEvent = eventListSorted.first(); |
816 | int i = 0; | 825 | int i = 0; |
817 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 826 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
818 | { | 827 | { |
819 | i++; | 828 | i++; |
820 | sortEvent = eventListSorted.next(); | 829 | sortEvent = eventListSorted.next(); |
821 | } | 830 | } |
822 | eventListSorted.insert( i, event ); | 831 | eventListSorted.insert( i, event ); |
823 | } | 832 | } |
824 | return eventListSorted; | 833 | return eventListSorted; |
825 | } | 834 | } |
826 | 835 | ||
827 | 836 | ||
828 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 837 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
829 | bool inclusive ) | 838 | bool inclusive ) |
830 | { | 839 | { |
831 | Event *event = 0; | 840 | Event *event = 0; |
832 | 841 | ||
833 | QPtrList<Event> eventList; | 842 | QPtrList<Event> eventList; |
834 | 843 | ||
835 | // Get non-recurring events | 844 | // Get non-recurring events |
836 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 845 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
837 | if ( !event->calEnabled() ) continue; | 846 | if ( !event->calEnabled() ) continue; |
838 | if ( event->doesRecur() ) { | 847 | if ( event->doesRecur() ) { |
839 | QDate rStart = event->dtStart().date(); | 848 | QDate rStart = event->dtStart().date(); |
840 | bool found = false; | 849 | bool found = false; |
841 | if ( inclusive ) { | 850 | if ( inclusive ) { |
842 | if ( rStart >= start && rStart <= end ) { | 851 | if ( rStart >= start && rStart <= end ) { |
843 | // Start date of event is in range. Now check for end date. | 852 | // Start date of event is in range. Now check for end date. |
844 | // if duration is negative, event recurs forever, so do not include it. | 853 | // if duration is negative, event recurs forever, so do not include it. |
845 | if ( event->recurrence()->duration() == 0 ) { // End date set | 854 | if ( event->recurrence()->duration() == 0 ) { // End date set |
846 | QDate rEnd = event->recurrence()->endDate(); | 855 | QDate rEnd = event->recurrence()->endDate(); |
847 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 856 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
848 | found = true; | 857 | found = true; |
849 | } | 858 | } |
850 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 859 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
851 | // TODO: Calculate end date from duration. Should be done in Event | 860 | // TODO: Calculate end date from duration. Should be done in Event |
852 | // For now exclude all events with a duration. | 861 | // For now exclude all events with a duration. |
853 | } | 862 | } |
854 | } | 863 | } |
855 | } else { | 864 | } else { |
856 | bool founOne; | 865 | bool founOne; |
857 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 866 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
858 | if ( founOne ) { | 867 | if ( founOne ) { |
859 | if ( next <= end ) { | 868 | if ( next <= end ) { |
860 | found = true; | 869 | found = true; |
861 | } | 870 | } |
862 | } | 871 | } |
863 | 872 | ||
864 | /* | 873 | /* |
865 | // crap !!! | 874 | // crap !!! |
866 | if ( rStart <= end ) { // Start date not after range | 875 | if ( rStart <= end ) { // Start date not after range |
867 | if ( rStart >= start ) { // Start date within range | 876 | if ( rStart >= start ) { // Start date within range |
868 | found = true; | 877 | found = true; |
869 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 878 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
870 | found = true; | 879 | found = true; |
871 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 880 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
872 | QDate rEnd = event->recurrence()->endDate(); | 881 | QDate rEnd = event->recurrence()->endDate(); |
873 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 882 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
874 | found = true; | 883 | found = true; |
875 | } | 884 | } |
876 | } else { // Duration set | 885 | } else { // Duration set |
877 | // TODO: Calculate end date from duration. Should be done in Event | 886 | // TODO: Calculate end date from duration. Should be done in Event |
878 | // For now include all events with a duration. | 887 | // For now include all events with a duration. |
879 | found = true; | 888 | found = true; |
880 | } | 889 | } |
881 | } | 890 | } |
882 | */ | 891 | */ |
883 | 892 | ||
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index b70f0c9..b611704 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,233 +1,233 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | bool mergeCalendarFile( QString name ); | 48 | bool mergeCalendarFile( QString name ); |
49 | bool mergeCalendar( Calendar* cal ); | 49 | bool mergeCalendar( Calendar* cal ); |
50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); | 50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly = false ); |
51 | void setSyncEventsReadOnly(); | 51 | void setSyncEventsReadOnly(); |
52 | void setSyncEventsEnabled(); | 52 | void setSyncEventsEnabled(); |
53 | void stopAllTodos(); | 53 | void stopAllTodos(); |
54 | /** | 54 | /** |
55 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 55 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
56 | calendar. Any information already present is lost. | 56 | calendar. Any information already present is lost. |
57 | @return true, if successfull, false on error. | 57 | @return true, if successfull, false on error. |
58 | @param fileName the name of the calendar on disk. | 58 | @param fileName the name of the calendar on disk. |
59 | */ | 59 | */ |
60 | bool load( const QString &fileName ); | 60 | bool load( const QString &fileName ); |
61 | /** | 61 | /** |
62 | Writes out the calendar to disk in the specified \a format. | 62 | Writes out the calendar to disk in the specified \a format. |
63 | CalendarLocal takes ownership of the CalFormat object. | 63 | CalendarLocal takes ownership of the CalFormat object. |
64 | @return true, if successfull, false on error. | 64 | @return true, if successfull, false on error. |
65 | @param fileName the name of the file | 65 | @param fileName the name of the file |
66 | */ | 66 | */ |
67 | bool save( const QString &fileName, CalFormat *format = 0 ); | 67 | bool save( const QString &fileName, CalFormat *format = 0 ); |
68 | 68 | ||
69 | /** | 69 | /** |
70 | Clears out the current calendar, freeing all used memory etc. etc. | 70 | Clears out the current calendar, freeing all used memory etc. etc. |
71 | */ | 71 | */ |
72 | void close(); | 72 | void close(); |
73 | 73 | ||
74 | void save() {} | 74 | void save() {} |
75 | 75 | ||
76 | /** | 76 | /** |
77 | Add Event to calendar. | 77 | Add Event to calendar. |
78 | */ | 78 | */ |
79 | void removeSyncInfo( QString syncProfile); | 79 | void removeSyncInfo( QString syncProfile); |
80 | bool addAnniversaryNoDup( Event *event ); | 80 | bool addAnniversaryNoDup( Event *event ); |
81 | bool addEventNoDup( Event *event ); | 81 | bool addEventNoDup( Event *event ); |
82 | bool addEvent( Event *event ); | 82 | bool addEvent( Event *event ); |
83 | /** | 83 | /** |
84 | Deletes an event from this calendar. | 84 | Deletes an event from this calendar. |
85 | */ | 85 | */ |
86 | void deleteEvent( Event *event ); | 86 | void deleteEvent( Event *event ); |
87 | 87 | ||
88 | /** | 88 | /** |
89 | Retrieves an event on the basis of the unique string ID. | 89 | Retrieves an event on the basis of the unique string ID. |
90 | */ | 90 | */ |
91 | Event *event( const QString &uid ); | 91 | Event *event( const QString &uid ); |
92 | /** | 92 | /** |
93 | Return unfiltered list of all events in calendar. | 93 | Return unfiltered list of all events in calendar. |
94 | */ | 94 | */ |
95 | QPtrList<Event> rawEvents(); | 95 | QPtrList<Event> rawEvents(); |
96 | QPtrList<Event> getExternLastSyncEvents(); | 96 | QPtrList<Event> getExternLastSyncEvents(); |
97 | /** | 97 | /** |
98 | Add a todo to the todolist. | 98 | Add a todo to the todolist. |
99 | */ | 99 | */ |
100 | bool addTodo( Todo *todo ); | 100 | bool addTodo( Todo *todo ); |
101 | bool addTodoNoDup( Todo *todo ); | 101 | bool addTodoNoDup( Todo *todo ); |
102 | /** | 102 | /** |
103 | Remove a todo from the todolist. | 103 | Remove a todo from the todolist. |
104 | */ | 104 | */ |
105 | void deleteTodo( Todo * ); | 105 | void deleteTodo( Todo * ); |
106 | /** | 106 | /** |
107 | Searches todolist for an event with this unique string identifier, | 107 | Searches todolist for an event with this unique string identifier, |
108 | returns a pointer or null. | 108 | returns a pointer or null. |
109 | */ | 109 | */ |
110 | Todo *todo( const QString &uid ); | 110 | Todo *todo( const QString &uid ); |
111 | /** | 111 | /** |
112 | Return list of all todos. | 112 | Return list of all todos. |
113 | */ | 113 | */ |
114 | QPtrList<Todo> rawTodos(); | 114 | QPtrList<Todo> rawTodos(); |
115 | /** | 115 | /** |
116 | Returns list of todos due on the specified date. | 116 | Returns list of todos due on the specified date. |
117 | */ | 117 | */ |
118 | QPtrList<Todo> todos( const QDate &date ); | 118 | QPtrList<Todo> todos( const QDate &date ); |
119 | /** | 119 | /** |
120 | Return list of all todos. | 120 | Return list of all todos. |
121 | 121 | ||
122 | Workaround because compiler does not recognize function of base class. | 122 | Workaround because compiler does not recognize function of base class. |
123 | */ | 123 | */ |
124 | QPtrList<Todo> todos() { return Calendar::todos(); } | 124 | QPtrList<Todo> todos() { return Calendar::todos(); } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | Add a Journal entry to calendar. | 127 | Add a Journal entry to calendar. |
128 | */ | 128 | */ |
129 | bool addJournal( Journal * ); | 129 | bool addJournal( Journal * ); |
130 | /** | 130 | /** |
131 | Remove a Journal from the calendar. | 131 | Remove a Journal from the calendar. |
132 | */ | 132 | */ |
133 | void deleteJournal( Journal * ); | 133 | void deleteJournal( Journal * ); |
134 | /** | 134 | /** |
135 | Return Journal for given date. | 135 | Return Journal for given date. |
136 | */ | 136 | */ |
137 | Journal *journal( const QDate & ); | 137 | Journal *journal( const QDate & ); |
138 | QPtrList<Journal> journals4Date( const QDate & ); | 138 | QPtrList<Journal> journals4Date( const QDate & ); |
139 | /** | 139 | /** |
140 | Return Journal with given UID. | 140 | Return Journal with given UID. |
141 | */ | 141 | */ |
142 | Journal *journal( const QString &uid ); | 142 | Journal *journal( const QString &uid ); |
143 | /** | 143 | /** |
144 | Return list of all Journals stored in calendar. | 144 | Return list of all Journals stored in calendar. |
145 | */ | 145 | */ |
146 | QPtrList<Journal> journals(); | 146 | QPtrList<Journal> journals(); |
147 | 147 | ||
148 | /** | 148 | /** |
149 | Return all alarms, which ocur in the given time interval. | 149 | Return all alarms, which ocur in the given time interval. |
150 | */ | 150 | */ |
151 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 151 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
152 | 152 | ||
153 | /** | 153 | /** |
154 | Return all alarms, which ocur before given date. | 154 | Return all alarms, which ocur before given date. |
155 | */ | 155 | */ |
156 | Alarm::List alarmsTo( const QDateTime &to ); | 156 | Alarm::List alarmsTo( const QDateTime &to ); |
157 | 157 | ||
158 | QDateTime nextAlarm( int daysTo ) ; | 158 | QDateTime nextAlarm( int daysTo ) ; |
159 | QDateTime nextAlarmEventDateTime() const; | 159 | QDateTime nextAlarmEventDateTime() const; |
160 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 160 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
161 | void registerAlarm(); | 161 | void registerAlarm(); |
162 | void deRegisterAlarm(); | 162 | void deRegisterAlarm(); |
163 | QString getAlarmNotification(); | 163 | QString getAlarmNotification(); |
164 | QString nextSummary() const ; | 164 | QString nextSummary() const ; |
165 | /** | 165 | /** |
166 | This method should be called whenever a Event is modified directly | 166 | This method should be called whenever a Event is modified directly |
167 | via it's pointer. It makes sure that the calendar is internally | 167 | via it's pointer. It makes sure that the calendar is internally |
168 | consistent. | 168 | consistent. |
169 | */ | 169 | */ |
170 | void update( IncidenceBase *incidence ); | 170 | void update( IncidenceBase *incidence ); |
171 | 171 | ||
172 | /** | 172 | /** |
173 | Builds and then returns a list of all events that match for the | 173 | Builds and then returns a list of all events that match for the |
174 | date specified. useful for dayView, etc. etc. | 174 | date specified. useful for dayView, etc. etc. |
175 | */ | 175 | */ |
176 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 176 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
177 | /** | 177 | /** |
178 | Get unfiltered events for date \a qdt. | 178 | Get unfiltered events for date \a qdt. |
179 | */ | 179 | */ |
180 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 180 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
181 | /** | 181 | /** |
182 | Get unfiltered events in a range of dates. If inclusive is set to true, | 182 | Get unfiltered events in a range of dates. If inclusive is set to true, |
183 | only events are returned, which are completely included in the range. | 183 | only events are returned, which are completely included in the range. |
184 | */ | 184 | */ |
185 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 185 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
186 | bool inclusive = false ); | 186 | bool inclusive = false ); |
187 | Todo *todo( QString, QString ); | 187 | Todo *todo( QString, QString ); |
188 | Event *event( QString, QString ); | 188 | Event *event( QString, QString ); |
189 | void getIncidenceCount( int calId, int& events, int & todos, int & journals); | 189 | void getIncidenceCount( int calId, int& events, int & todos, int & journals); |
190 | 190 | ||
191 | public slots: | 191 | public slots: |
192 | void setCalendarEnabled( int id, bool enable ); | 192 | void setCalendarEnabled( int id, bool enable ); |
193 | void setAlarmEnabled( int id, bool enable ); | 193 | void setAlarmEnabled( int id, bool enable ); |
194 | void setReadOnly( int id, bool enable ); | 194 | void setReadOnly( int id, bool enable ); |
195 | void setDefaultCalendarEnabledOnly(); | 195 | void setDefaultCalendarEnabledOnly(); |
196 | void setCalendarRemove( int id ); | 196 | void setCalendarRemove( int id ); |
197 | void setAllCalendarEnabled( bool enable ); | 197 | void setAllCalendarEnabled( bool enable ); |
198 | 198 | ||
199 | protected: | 199 | protected: |
200 | 200 | ||
201 | // Event* mNextAlarmEvent; | 201 | // Event* mNextAlarmEvent; |
202 | QString mNextSummary; | 202 | QString mNextSummary; |
203 | QString mNextAlarmEventDateTimeString; | 203 | QString mNextAlarmEventDateTimeString; |
204 | QString mLastAlarmNotificationString; | 204 | QString mLastAlarmNotificationString; |
205 | QDateTime mNextAlarmEventDateTime; | 205 | QDateTime mNextAlarmEventDateTime; |
206 | QDateTime mNextAlarmDateTime; | 206 | QDateTime mNextAlarmDateTime; |
207 | void reInitAlarmSettings(); | 207 | void reInitAlarmSettings(); |
208 | 208 | ||
209 | /** Notification function of IncidenceBase::Observer. */ | 209 | /** Notification function of IncidenceBase::Observer. */ |
210 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 210 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
211 | 211 | ||
212 | /** inserts an event into its "proper place" in the calendar. */ | 212 | /** inserts an event into its "proper place" in the calendar. */ |
213 | void insertEvent( Event *event ); | 213 | void insertEvent( Event *event ); |
214 | 214 | ||
215 | /** Append alarms of incidence in interval to list of alarms. */ | 215 | /** Append alarms of incidence in interval to list of alarms. */ |
216 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 216 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
217 | const QDateTime &from, const QDateTime &to ); | 217 | const QDateTime &from, const QDateTime &to ); |
218 | 218 | ||
219 | /** Append alarms of recurring events in interval to list of alarms. */ | 219 | /** Append alarms of recurring events in interval to list of alarms. */ |
220 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 220 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
221 | const QDateTime &from, const QDateTime &to ); | 221 | const QDateTime &from, const QDateTime &to ); |
222 | 222 | ||
223 | private: | 223 | private: |
224 | void init(); | 224 | void init(); |
225 | 225 | ||
226 | QPtrList<Event> mEventList; | 226 | QPtrList<Event> mEventList; |
227 | QPtrList<Todo> mTodoList; | 227 | QPtrList<Todo> mTodoList; |
228 | QPtrList<Journal> mJournalList; | 228 | QPtrList<Journal> mJournalList; |
229 | }; | 229 | }; |
230 | 230 | ||
231 | } | 231 | } |
232 | 232 | ||
233 | #endif | 233 | #endif |