summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-06-30 15:06:11 (UTC)
committer zautrix <zautrix>2005-06-30 15:06:11 (UTC)
commitd401e425af46703a89eb80802606edeea06c9538 (patch) (unidiff)
treee32a98c44e340a6af6706fa99544cba648aa19f1 /korganizer
parentaf48ba51eeb7a766ca7b458d2287e55c121388cf (diff)
downloadkdepimpi-d401e425af46703a89eb80802606edeea06c9538.zip
kdepimpi-d401e425af46703a89eb80802606edeea06c9538.tar.gz
kdepimpi-d401e425af46703a89eb80802606edeea06c9538.tar.bz2
desk fixes
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp2
-rw-r--r--korganizer/journalentry.cpp8
-rw-r--r--korganizer/kodaymatrix.cpp3
-rw-r--r--korganizer/koeditorgeneral.cpp6
-rw-r--r--korganizer/koprefs.cpp14
5 files changed, 21 insertions, 12 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 214b829..d0de233 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1062,3073 +1062,3075 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
1062 switch( mode ) { 1062 switch( mode ) {
1063 case SYNC_PREF_LOCAL: 1063 case SYNC_PREF_LOCAL:
1064 if ( lastSync > remoteMod ) 1064 if ( lastSync > remoteMod )
1065 return 1; 1065 return 1;
1066 if ( lastSync > localMod ) 1066 if ( lastSync > localMod )
1067 return 2; 1067 return 2;
1068 return 1; 1068 return 1;
1069 break; 1069 break;
1070 case SYNC_PREF_REMOTE: 1070 case SYNC_PREF_REMOTE:
1071 if ( lastSync > localMod ) 1071 if ( lastSync > localMod )
1072 return 2; 1072 return 2;
1073 if ( lastSync > remoteMod ) 1073 if ( lastSync > remoteMod )
1074 return 1; 1074 return 1;
1075 return 2; 1075 return 2;
1076 break; 1076 break;
1077 case SYNC_PREF_NEWEST: 1077 case SYNC_PREF_NEWEST:
1078 if ( localMod >= remoteMod ) 1078 if ( localMod >= remoteMod )
1079 return 1; 1079 return 1;
1080 else 1080 else
1081 return 2; 1081 return 2;
1082 break; 1082 break;
1083 case SYNC_PREF_ASK: 1083 case SYNC_PREF_ASK:
1084 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1084 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1085 if ( lastSync > remoteMod && lastSync > localMod) 1085 if ( lastSync > remoteMod && lastSync > localMod)
1086 return 0; 1086 return 0;
1087 if ( lastSync > remoteMod ) 1087 if ( lastSync > remoteMod )
1088 return 1; 1088 return 1;
1089 if ( lastSync > localMod ) 1089 if ( lastSync > localMod )
1090 return 2; 1090 return 2;
1091 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1091 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1092 localIsNew = localMod >= remoteMod; 1092 localIsNew = localMod >= remoteMod;
1093 if ( localIsNew ) 1093 if ( localIsNew )
1094 getEventViewerDialog()->setColorMode( 1 ); 1094 getEventViewerDialog()->setColorMode( 1 );
1095 else 1095 else
1096 getEventViewerDialog()->setColorMode( 2 ); 1096 getEventViewerDialog()->setColorMode( 2 );
1097 getEventViewerDialog()->setIncidence(local); 1097 getEventViewerDialog()->setIncidence(local);
1098 if ( localIsNew ) 1098 if ( localIsNew )
1099 getEventViewerDialog()->setColorMode( 2 ); 1099 getEventViewerDialog()->setColorMode( 2 );
1100 else 1100 else
1101 getEventViewerDialog()->setColorMode( 1 ); 1101 getEventViewerDialog()->setColorMode( 1 );
1102 getEventViewerDialog()->addIncidence(remote); 1102 getEventViewerDialog()->addIncidence(remote);
1103 getEventViewerDialog()->setColorMode( 0 ); 1103 getEventViewerDialog()->setColorMode( 0 );
1104 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1104 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1105 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1105 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1106 getEventViewerDialog()->showMe(); 1106 getEventViewerDialog()->showMe();
1107 result = getEventViewerDialog()->executeS( localIsNew ); 1107 result = getEventViewerDialog()->executeS( localIsNew );
1108 return result; 1108 return result;
1109 1109
1110 break; 1110 break;
1111 case SYNC_PREF_FORCE_LOCAL: 1111 case SYNC_PREF_FORCE_LOCAL:
1112 return 1; 1112 return 1;
1113 break; 1113 break;
1114 case SYNC_PREF_FORCE_REMOTE: 1114 case SYNC_PREF_FORCE_REMOTE:
1115 return 2; 1115 return 2;
1116 break; 1116 break;
1117 1117
1118 default: 1118 default:
1119 // SYNC_PREF_TAKE_BOTH not implemented 1119 // SYNC_PREF_TAKE_BOTH not implemented
1120 break; 1120 break;
1121 } 1121 }
1122 return 0; 1122 return 0;
1123} 1123}
1124Event* CalendarView::getLastSyncEvent() 1124Event* CalendarView::getLastSyncEvent()
1125{ 1125{
1126 Event* lse; 1126 Event* lse;
1127 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1127 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1128 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1128 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1129 if (!lse) { 1129 if (!lse) {
1130 lse = new Event(); 1130 lse = new Event();
1131 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1131 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1132 QString sum = ""; 1132 QString sum = "";
1133 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1133 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1134 sum = "E: "; 1134 sum = "E: ";
1135 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1135 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1136 lse->setDtStart( mLastCalendarSync ); 1136 lse->setDtStart( mLastCalendarSync );
1137 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1137 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1138 lse->setCategories( i18n("SyncEvent") ); 1138 lse->setCategories( i18n("SyncEvent") );
1139 lse->setReadOnly( true ); 1139 lse->setReadOnly( true );
1140 mCalendar->addEvent( lse ); 1140 mCalendar->addEvent( lse );
1141 } 1141 }
1142 1142
1143 return lse; 1143 return lse;
1144 1144
1145} 1145}
1146 1146
1147// we check, if the to delete event has a id for a profile 1147// we check, if the to delete event has a id for a profile
1148// if yes, we set this id in the profile to delete 1148// if yes, we set this id in the profile to delete
1149void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1149void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1150{ 1150{
1151 if ( lastSync.count() == 0 ) { 1151 if ( lastSync.count() == 0 ) {
1152 //qDebug(" lastSync.count() == 0"); 1152 //qDebug(" lastSync.count() == 0");
1153 return; 1153 return;
1154 } 1154 }
1155 if ( toDelete->typeID() == journalID ) 1155 if ( toDelete->typeID() == journalID )
1156 return; 1156 return;
1157 1157
1158 Event* eve = lastSync.first(); 1158 Event* eve = lastSync.first();
1159 1159
1160 while ( eve ) { 1160 while ( eve ) {
1161 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1161 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1162 if ( !id.isEmpty() ) { 1162 if ( !id.isEmpty() ) {
1163 QString des = eve->description(); 1163 QString des = eve->description();
1164 QString pref = "e"; 1164 QString pref = "e";
1165 if ( toDelete->typeID() == todoID ) 1165 if ( toDelete->typeID() == todoID )
1166 pref = "t"; 1166 pref = "t";
1167 des += pref+ id + ","; 1167 des += pref+ id + ",";
1168 eve->setReadOnly( false ); 1168 eve->setReadOnly( false );
1169 eve->setDescription( des ); 1169 eve->setDescription( des );
1170 //qDebug("setdes %s ", des.latin1()); 1170 //qDebug("setdes %s ", des.latin1());
1171 eve->setReadOnly( true ); 1171 eve->setReadOnly( true );
1172 } 1172 }
1173 eve = lastSync.next(); 1173 eve = lastSync.next();
1174 } 1174 }
1175 1175
1176} 1176}
1177void CalendarView::checkExternalId( Incidence * inc ) 1177void CalendarView::checkExternalId( Incidence * inc )
1178{ 1178{
1179 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1179 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1180 checkExternSyncEvent( lastSync, inc ); 1180 checkExternSyncEvent( lastSync, inc );
1181 1181
1182} 1182}
1183bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1183bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1184{ 1184{
1185 bool syncOK = true; 1185 bool syncOK = true;
1186 int addedEvent = 0; 1186 int addedEvent = 0;
1187 int addedEventR = 0; 1187 int addedEventR = 0;
1188 int deletedEventR = 0; 1188 int deletedEventR = 0;
1189 int deletedEventL = 0; 1189 int deletedEventL = 0;
1190 int changedLocal = 0; 1190 int changedLocal = 0;
1191 int changedRemote = 0; 1191 int changedRemote = 0;
1192 int filteredIN = 0; 1192 int filteredIN = 0;
1193 int filteredOUT = 0; 1193 int filteredOUT = 0;
1194 //QPtrList<Event> el = local->rawEvents(); 1194 //QPtrList<Event> el = local->rawEvents();
1195 Event* eventR; 1195 Event* eventR;
1196 QString uid; 1196 QString uid;
1197 int take; 1197 int take;
1198 Event* eventL; 1198 Event* eventL;
1199 Event* eventRSync; 1199 Event* eventRSync;
1200 Event* eventLSync; 1200 Event* eventLSync;
1201 clearAllViews(); 1201 clearAllViews();
1202 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1202 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1203 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1203 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1204 bool fullDateRange = false; 1204 bool fullDateRange = false;
1205 local->resetTempSyncStat(); 1205 local->resetTempSyncStat();
1206 mLastCalendarSync = QDateTime::currentDateTime(); 1206 mLastCalendarSync = QDateTime::currentDateTime();
1207 if ( mSyncManager->syncWithDesktop() ) { 1207 if ( mSyncManager->syncWithDesktop() ) {
1208 remote->resetPilotStat(1); 1208 remote->resetPilotStat(1);
1209 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1209 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1210 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1210 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1211 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1211 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1212 } else { 1212 } else {
1213 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1213 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1214 } 1214 }
1215 } 1215 }
1216 QDateTime modifiedCalendar = mLastCalendarSync; 1216 QDateTime modifiedCalendar = mLastCalendarSync;
1217 eventLSync = getLastSyncEvent(); 1217 eventLSync = getLastSyncEvent();
1218 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1218 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1219 if ( eventR ) { 1219 if ( eventR ) {
1220 eventRSync = (Event*) eventR->clone(); 1220 eventRSync = (Event*) eventR->clone();
1221 remote->deleteEvent(eventR ); 1221 remote->deleteEvent(eventR );
1222 1222
1223 } else { 1223 } else {
1224 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1224 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1225 eventRSync = (Event*)eventLSync->clone(); 1225 eventRSync = (Event*)eventLSync->clone();
1226 } else { 1226 } else {
1227 fullDateRange = true; 1227 fullDateRange = true;
1228 eventRSync = new Event(); 1228 eventRSync = new Event();
1229 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1229 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1230 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1230 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1231 eventRSync->setDtStart( mLastCalendarSync ); 1231 eventRSync->setDtStart( mLastCalendarSync );
1232 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1232 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1233 eventRSync->setCategories( i18n("SyncEvent") ); 1233 eventRSync->setCategories( i18n("SyncEvent") );
1234 } 1234 }
1235 } 1235 }
1236 if ( eventLSync->dtStart() == mLastCalendarSync ) 1236 if ( eventLSync->dtStart() == mLastCalendarSync )
1237 fullDateRange = true; 1237 fullDateRange = true;
1238 1238
1239 if ( ! fullDateRange ) { 1239 if ( ! fullDateRange ) {
1240 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1240 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1241 1241
1242 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1242 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1243 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1243 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1244 fullDateRange = true; 1244 fullDateRange = true;
1245 } 1245 }
1246 } 1246 }
1247 if ( mSyncManager->syncWithDesktop() ) { 1247 if ( mSyncManager->syncWithDesktop() ) {
1248 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1248 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1249 } 1249 }
1250 if ( fullDateRange ) 1250 if ( fullDateRange )
1251 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1251 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1252 else 1252 else
1253 mLastCalendarSync = eventLSync->dtStart(); 1253 mLastCalendarSync = eventLSync->dtStart();
1254 // for resyncing if own file has changed 1254 // for resyncing if own file has changed
1255 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1255 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1256 mLastCalendarSync = loadedFileVersion; 1256 mLastCalendarSync = loadedFileVersion;
1257 //qDebug("setting mLastCalendarSync "); 1257 //qDebug("setting mLastCalendarSync ");
1258 } 1258 }
1259 //qDebug("*************************** "); 1259 //qDebug("*************************** ");
1260 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1260 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1261 QPtrList<Incidence> er = remote->rawIncidences(); 1261 QPtrList<Incidence> er = remote->rawIncidences();
1262 Incidence* inR = er.first(); 1262 Incidence* inR = er.first();
1263 Incidence* inL; 1263 Incidence* inL;
1264 QProgressBar bar( er.count(),0 ); 1264 QProgressBar bar( er.count(),0 );
1265 bar.setCaption (i18n("Syncing - close to abort!") ); 1265 bar.setCaption (i18n("Syncing - close to abort!") );
1266 1266
1267 // ************** setting up filter ************* 1267 // ************** setting up filter *************
1268 CalFilter *filterIN = 0; 1268 CalFilter *filterIN = 0;
1269 CalFilter *filterOUT = 0; 1269 CalFilter *filterOUT = 0;
1270 CalFilter *filter = mFilters.first(); 1270 CalFilter *filter = mFilters.first();
1271 while(filter) { 1271 while(filter) {
1272 if ( filter->name() == mSyncManager->mFilterInCal ) 1272 if ( filter->name() == mSyncManager->mFilterInCal )
1273 filterIN = filter; 1273 filterIN = filter;
1274 if ( filter->name() == mSyncManager->mFilterOutCal ) 1274 if ( filter->name() == mSyncManager->mFilterOutCal )
1275 filterOUT = filter; 1275 filterOUT = filter;
1276 filter = mFilters.next(); 1276 filter = mFilters.next();
1277 } 1277 }
1278 int w = 300; 1278 int w = 300;
1279 if ( QApplication::desktop()->width() < 320 ) 1279 if ( QApplication::desktop()->width() < 320 )
1280 w = 220; 1280 w = 220;
1281 int h = bar.sizeHint().height() ; 1281 int h = bar.sizeHint().height() ;
1282 int dw = QApplication::desktop()->width(); 1282 int dw = QApplication::desktop()->width();
1283 int dh = QApplication::desktop()->height(); 1283 int dh = QApplication::desktop()->height();
1284 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1284 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1285 bar.show(); 1285 bar.show();
1286 int modulo = (er.count()/10)+1; 1286 int modulo = (er.count()/10)+1;
1287 int incCounter = 0; 1287 int incCounter = 0;
1288 while ( inR ) { 1288 while ( inR ) {
1289 if ( ! bar.isVisible() ) 1289 if ( ! bar.isVisible() )
1290 return false; 1290 return false;
1291 if ( incCounter % modulo == 0 ) 1291 if ( incCounter % modulo == 0 )
1292 bar.setProgress( incCounter ); 1292 bar.setProgress( incCounter );
1293 ++incCounter; 1293 ++incCounter;
1294 uid = inR->uid(); 1294 uid = inR->uid();
1295 bool skipIncidence = false; 1295 bool skipIncidence = false;
1296 if ( uid.left(15) == QString("last-syncEvent-") ) 1296 if ( uid.left(15) == QString("last-syncEvent-") )
1297 skipIncidence = true; 1297 skipIncidence = true;
1298 QString idS; 1298 QString idS;
1299 qApp->processEvents(); 1299 qApp->processEvents();
1300 if ( !skipIncidence ) { 1300 if ( !skipIncidence ) {
1301 inL = local->incidence( uid ); 1301 inL = local->incidence( uid );
1302 if ( inL ) { // maybe conflict - same uid in both calendars 1302 if ( inL ) { // maybe conflict - same uid in both calendars
1303 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1303 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1304 //qDebug("take %d %s ", take, inL->summary().latin1()); 1304 //qDebug("take %d %s ", take, inL->summary().latin1());
1305 if ( take == 3 ) 1305 if ( take == 3 )
1306 return false; 1306 return false;
1307 if ( take == 1 ) {// take local ********************** 1307 if ( take == 1 ) {// take local **********************
1308 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1308 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1309 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1309 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1310 else 1310 else
1311 idS = inR->IDStr(); 1311 idS = inR->IDStr();
1312 remote->deleteIncidence( inR ); 1312 remote->deleteIncidence( inR );
1313 inR = inL->clone(); 1313 inR = inL->clone();
1314 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1314 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1315 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1315 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1316 inR->setIDStr( idS ); 1316 inR->setIDStr( idS );
1317 remote->addIncidence( inR ); 1317 remote->addIncidence( inR );
1318 if ( mSyncManager->syncWithDesktop() ) 1318 if ( mSyncManager->syncWithDesktop() )
1319 inR->setPilotId( 2 ); 1319 inR->setPilotId( 2 );
1320 ++changedRemote; 1320 ++changedRemote;
1321 } else {// take remote ********************** 1321 } else {// take remote **********************
1322 idS = inL->IDStr(); 1322 idS = inL->IDStr();
1323 int pid = inL->pilotId(); 1323 int pid = inL->pilotId();
1324 local->deleteIncidence( inL ); 1324 local->deleteIncidence( inL );
1325 inL = inR->clone(); 1325 inL = inR->clone();
1326 if ( mSyncManager->syncWithDesktop() ) 1326 if ( mSyncManager->syncWithDesktop() )
1327 inL->setPilotId( pid ); 1327 inL->setPilotId( pid );
1328 inL->setIDStr( idS ); 1328 inL->setIDStr( idS );
1329 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1329 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1330 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1330 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1331 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1331 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1332 } 1332 }
1333 local->addIncidence( inL ); 1333 local->addIncidence( inL );
1334 ++changedLocal; 1334 ++changedLocal;
1335 } 1335 }
1336 } 1336 }
1337 } else { // no conflict ********** add or delete remote 1337 } else { // no conflict ********** add or delete remote
1338 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1338 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1339 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1339 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1340 QString des = eventLSync->description(); 1340 QString des = eventLSync->description();
1341 QString pref = "e"; 1341 QString pref = "e";
1342 if ( inR->typeID() == todoID ) 1342 if ( inR->typeID() == todoID )
1343 pref = "t"; 1343 pref = "t";
1344 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1344 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1345 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1345 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1346 //remote->deleteIncidence( inR ); 1346 //remote->deleteIncidence( inR );
1347 ++deletedEventR; 1347 ++deletedEventR;
1348 } else { 1348 } else {
1349 inR->setLastModified( modifiedCalendar ); 1349 inR->setLastModified( modifiedCalendar );
1350 inL = inR->clone(); 1350 inL = inR->clone();
1351 inL->setIDStr( ":" ); 1351 inL->setIDStr( ":" );
1352 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1352 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1353 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1353 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1354 local->addIncidence( inL ); 1354 local->addIncidence( inL );
1355 ++addedEvent; 1355 ++addedEvent;
1356 1356
1357 } 1357 }
1358 } else { 1358 } else {
1359 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1359 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1360 inR->setLastModified( modifiedCalendar ); 1360 inR->setLastModified( modifiedCalendar );
1361 inL = inR->clone(); 1361 inL = inR->clone();
1362 inL->setIDStr( ":" ); 1362 inL->setIDStr( ":" );
1363 local->addIncidence( inL ); 1363 local->addIncidence( inL );
1364 ++addedEvent; 1364 ++addedEvent;
1365 1365
1366 } else { 1366 } else {
1367 checkExternSyncEvent(eventRSyncSharp, inR); 1367 checkExternSyncEvent(eventRSyncSharp, inR);
1368 remote->deleteIncidence( inR ); 1368 remote->deleteIncidence( inR );
1369 ++deletedEventR; 1369 ++deletedEventR;
1370 } 1370 }
1371 } 1371 }
1372 } else { 1372 } else {
1373 ++filteredIN; 1373 ++filteredIN;
1374 } 1374 }
1375 } 1375 }
1376 } 1376 }
1377 inR = er.next(); 1377 inR = er.next();
1378 } 1378 }
1379 QPtrList<Incidence> el = local->rawIncidences(); 1379 QPtrList<Incidence> el = local->rawIncidences();
1380 inL = el.first(); 1380 inL = el.first();
1381 modulo = (el.count()/10)+1; 1381 modulo = (el.count()/10)+1;
1382 bar.setCaption (i18n("Add / remove events") ); 1382 bar.setCaption (i18n("Add / remove events") );
1383 bar.setTotalSteps ( el.count() ) ; 1383 bar.setTotalSteps ( el.count() ) ;
1384 bar.show(); 1384 bar.show();
1385 incCounter = 0; 1385 incCounter = 0;
1386 1386
1387 while ( inL ) { 1387 while ( inL ) {
1388 1388
1389 qApp->processEvents(); 1389 qApp->processEvents();
1390 if ( ! bar.isVisible() ) 1390 if ( ! bar.isVisible() )
1391 return false; 1391 return false;
1392 if ( incCounter % modulo == 0 ) 1392 if ( incCounter % modulo == 0 )
1393 bar.setProgress( incCounter ); 1393 bar.setProgress( incCounter );
1394 ++incCounter; 1394 ++incCounter;
1395 uid = inL->uid(); 1395 uid = inL->uid();
1396 bool skipIncidence = false; 1396 bool skipIncidence = false;
1397 if ( uid.left(15) == QString("last-syncEvent-") ) 1397 if ( uid.left(15) == QString("last-syncEvent-") )
1398 skipIncidence = true; 1398 skipIncidence = true;
1399 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1399 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1400 skipIncidence = true; 1400 skipIncidence = true;
1401 if ( !skipIncidence ) { 1401 if ( !skipIncidence ) {
1402 inR = remote->incidence( uid ); 1402 inR = remote->incidence( uid );
1403 if ( ! inR ) { 1403 if ( ! inR ) {
1404 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1404 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1405 // no conflict ********** add or delete local 1405 // no conflict ********** add or delete local
1406 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1406 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1407 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1407 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1408 checkExternSyncEvent(eventLSyncSharp, inL); 1408 checkExternSyncEvent(eventLSyncSharp, inL);
1409 local->deleteIncidence( inL ); 1409 local->deleteIncidence( inL );
1410 ++deletedEventL; 1410 ++deletedEventL;
1411 } else { 1411 } else {
1412 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1412 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1413 inL->removeID(mCurrentSyncDevice ); 1413 inL->removeID(mCurrentSyncDevice );
1414 ++addedEventR; 1414 ++addedEventR;
1415 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1415 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1416 inL->setLastModified( modifiedCalendar ); 1416 inL->setLastModified( modifiedCalendar );
1417 inR = inL->clone(); 1417 inR = inL->clone();
1418 inR->setIDStr( ":" ); 1418 inR->setIDStr( ":" );
1419 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1419 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1420 remote->addIncidence( inR ); 1420 remote->addIncidence( inR );
1421 } 1421 }
1422 } 1422 }
1423 } else { 1423 } else {
1424 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1424 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1425 checkExternSyncEvent(eventLSyncSharp, inL); 1425 checkExternSyncEvent(eventLSyncSharp, inL);
1426 local->deleteIncidence( inL ); 1426 local->deleteIncidence( inL );
1427 ++deletedEventL; 1427 ++deletedEventL;
1428 } else { 1428 } else {
1429 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1429 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1430 ++addedEventR; 1430 ++addedEventR;
1431 inL->setLastModified( modifiedCalendar ); 1431 inL->setLastModified( modifiedCalendar );
1432 inR = inL->clone(); 1432 inR = inL->clone();
1433 inR->setIDStr( ":" ); 1433 inR->setIDStr( ":" );
1434 remote->addIncidence( inR ); 1434 remote->addIncidence( inR );
1435 } 1435 }
1436 } 1436 }
1437 } 1437 }
1438 } else { 1438 } else {
1439 ++filteredOUT; 1439 ++filteredOUT;
1440 } 1440 }
1441 } 1441 }
1442 } 1442 }
1443 inL = el.next(); 1443 inL = el.next();
1444 } 1444 }
1445 int delFut = 0; 1445 int delFut = 0;
1446 int remRem = 0; 1446 int remRem = 0;
1447 if ( mSyncManager->mWriteBackInFuture ) { 1447 if ( mSyncManager->mWriteBackInFuture ) {
1448 er = remote->rawIncidences(); 1448 er = remote->rawIncidences();
1449 remRem = er.count(); 1449 remRem = er.count();
1450 inR = er.first(); 1450 inR = er.first();
1451 QDateTime dt; 1451 QDateTime dt;
1452 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1452 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1453 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1453 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1454 while ( inR ) { 1454 while ( inR ) {
1455 if ( inR->typeID() == todoID ) { 1455 if ( inR->typeID() == todoID ) {
1456 Todo * t = (Todo*)inR; 1456 Todo * t = (Todo*)inR;
1457 if ( t->hasDueDate() ) 1457 if ( t->hasDueDate() )
1458 dt = t->dtDue(); 1458 dt = t->dtDue();
1459 else 1459 else
1460 dt = cur.addSecs( 62 ); 1460 dt = cur.addSecs( 62 );
1461 } 1461 }
1462 else if (inR->typeID() == eventID ) { 1462 else if (inR->typeID() == eventID ) {
1463 bool ok; 1463 bool ok;
1464 dt = inR->getNextOccurence( cur, &ok ); 1464 dt = inR->getNextOccurence( cur, &ok );
1465 if ( !ok ) 1465 if ( !ok )
1466 dt = cur.addSecs( -62 ); 1466 dt = cur.addSecs( -62 );
1467 } 1467 }
1468 else 1468 else
1469 dt = inR->dtStart(); 1469 dt = inR->dtStart();
1470 if ( dt < cur || dt > end ) { 1470 if ( dt < cur || dt > end ) {
1471 remote->deleteIncidence( inR ); 1471 remote->deleteIncidence( inR );
1472 ++delFut; 1472 ++delFut;
1473 } 1473 }
1474 inR = er.next(); 1474 inR = er.next();
1475 } 1475 }
1476 } 1476 }
1477 bar.hide(); 1477 bar.hide();
1478 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1478 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1479 eventLSync->setReadOnly( false ); 1479 eventLSync->setReadOnly( false );
1480 eventLSync->setDtStart( mLastCalendarSync ); 1480 eventLSync->setDtStart( mLastCalendarSync );
1481 eventRSync->setDtStart( mLastCalendarSync ); 1481 eventRSync->setDtStart( mLastCalendarSync );
1482 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1482 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1483 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1483 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1484 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1484 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1485 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1485 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1486 eventLSync->setReadOnly( true ); 1486 eventLSync->setReadOnly( true );
1487 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1487 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1488 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1488 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1489 remote->addEvent( eventRSync ); 1489 remote->addEvent( eventRSync );
1490 else 1490 else
1491 delete eventRSync; 1491 delete eventRSync;
1492 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1492 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1493 QString mes; 1493 QString mes;
1494 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 ); 1494 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 );
1495 QString delmess; 1495 QString delmess;
1496 if ( delFut ) { 1496 if ( delFut ) {
1497 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); 1497 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);
1498 mes += delmess; 1498 mes += delmess;
1499 } 1499 }
1500 mes = i18n("Local calendar changed!\n") +mes; 1500 mes = i18n("Local calendar changed!\n") +mes;
1501 mCalendar->checkAlarmForIncidence( 0, true ); 1501 mCalendar->checkAlarmForIncidence( 0, true );
1502 qDebug( mes ); 1502 qDebug( mes );
1503 if ( mSyncManager->mShowSyncSummary ) { 1503 if ( mSyncManager->mShowSyncSummary ) {
1504 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1504 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1505 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1505 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1506 qDebug("KO: WB cancelled "); 1506 qDebug("KO: WB cancelled ");
1507 mSyncManager->mWriteBackFile = false; 1507 mSyncManager->mWriteBackFile = false;
1508 return syncOK; 1508 return syncOK;
1509 } 1509 }
1510 } 1510 }
1511 return syncOK; 1511 return syncOK;
1512} 1512}
1513 1513
1514void CalendarView::setSyncDevice( QString s ) 1514void CalendarView::setSyncDevice( QString s )
1515{ 1515{
1516 mCurrentSyncDevice= s; 1516 mCurrentSyncDevice= s;
1517} 1517}
1518void CalendarView::setSyncName( QString s ) 1518void CalendarView::setSyncName( QString s )
1519{ 1519{
1520 mCurrentSyncName= s; 1520 mCurrentSyncName= s;
1521} 1521}
1522bool CalendarView::syncCalendar(QString filename, int mode) 1522bool CalendarView::syncCalendar(QString filename, int mode)
1523{ 1523{
1524 //qDebug("syncCalendar %s ", filename.latin1()); 1524 //qDebug("syncCalendar %s ", filename.latin1());
1525 mGlobalSyncMode = SYNC_MODE_NORMAL; 1525 mGlobalSyncMode = SYNC_MODE_NORMAL;
1526 CalendarLocal* calendar = new CalendarLocal(); 1526 CalendarLocal* calendar = new CalendarLocal();
1527 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1527 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1528 FileStorage* storage = new FileStorage( calendar ); 1528 FileStorage* storage = new FileStorage( calendar );
1529 bool syncOK = false; 1529 bool syncOK = false;
1530 storage->setFileName( filename ); 1530 storage->setFileName( filename );
1531 // qDebug("loading ... "); 1531 // qDebug("loading ... ");
1532 if ( storage->load() ) { 1532 if ( storage->load() ) {
1533 getEventViewerDialog()->setSyncMode( true ); 1533 getEventViewerDialog()->setSyncMode( true );
1534 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1534 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1535 getEventViewerDialog()->setSyncMode( false ); 1535 getEventViewerDialog()->setSyncMode( false );
1536 if ( syncOK ) { 1536 if ( syncOK ) {
1537 if ( mSyncManager->mWriteBackFile ) 1537 if ( mSyncManager->mWriteBackFile )
1538 { 1538 {
1539 storage->setSaveFormat( new ICalFormat() ); 1539 storage->setSaveFormat( new ICalFormat() );
1540 storage->save(); 1540 storage->save();
1541 } 1541 }
1542 } 1542 }
1543 setModified( true ); 1543 setModified( true );
1544 } 1544 }
1545 delete storage; 1545 delete storage;
1546 delete calendar; 1546 delete calendar;
1547 if ( syncOK ) 1547 if ( syncOK )
1548 updateView(); 1548 updateView();
1549 return syncOK; 1549 return syncOK;
1550} 1550}
1551 1551
1552void CalendarView::syncExternal( int mode ) 1552void CalendarView::syncExternal( int mode )
1553{ 1553{
1554 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1554 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1555 1555
1556 qApp->processEvents(); 1556 qApp->processEvents();
1557 CalendarLocal* calendar = new CalendarLocal(); 1557 CalendarLocal* calendar = new CalendarLocal();
1558 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1558 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1559 bool syncOK = false; 1559 bool syncOK = false;
1560 bool loadSuccess = false; 1560 bool loadSuccess = false;
1561 PhoneFormat* phoneFormat = 0; 1561 PhoneFormat* phoneFormat = 0;
1562 emit tempDisableBR(true); 1562 emit tempDisableBR(true);
1563#ifndef DESKTOP_VERSION 1563#ifndef DESKTOP_VERSION
1564 SharpFormat* sharpFormat = 0; 1564 SharpFormat* sharpFormat = 0;
1565 if ( mode == 0 ) { // sharp 1565 if ( mode == 0 ) { // sharp
1566 sharpFormat = new SharpFormat () ; 1566 sharpFormat = new SharpFormat () ;
1567 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1567 loadSuccess = sharpFormat->load( calendar, mCalendar );
1568 1568
1569 } else 1569 } else
1570#endif 1570#endif
1571 if ( mode == 1 ) { // phone 1571 if ( mode == 1 ) { // phone
1572 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1572 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1573 mSyncManager->mPhoneDevice, 1573 mSyncManager->mPhoneDevice,
1574 mSyncManager->mPhoneConnection, 1574 mSyncManager->mPhoneConnection,
1575 mSyncManager->mPhoneModel); 1575 mSyncManager->mPhoneModel);
1576 loadSuccess = phoneFormat->load( calendar,mCalendar); 1576 loadSuccess = phoneFormat->load( calendar,mCalendar);
1577 1577
1578 } else { 1578 } else {
1579 emit tempDisableBR(false); 1579 emit tempDisableBR(false);
1580 return; 1580 return;
1581 } 1581 }
1582 if ( loadSuccess ) { 1582 if ( loadSuccess ) {
1583 getEventViewerDialog()->setSyncMode( true ); 1583 getEventViewerDialog()->setSyncMode( true );
1584 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1584 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1585 getEventViewerDialog()->setSyncMode( false ); 1585 getEventViewerDialog()->setSyncMode( false );
1586 qApp->processEvents(); 1586 qApp->processEvents();
1587 if ( syncOK ) { 1587 if ( syncOK ) {
1588 if ( mSyncManager->mWriteBackFile ) 1588 if ( mSyncManager->mWriteBackFile )
1589 { 1589 {
1590 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1590 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1591 Incidence* inc = iL.first(); 1591 Incidence* inc = iL.first();
1592 if ( phoneFormat ) { 1592 if ( phoneFormat ) {
1593 while ( inc ) { 1593 while ( inc ) {
1594 inc->removeID(mCurrentSyncDevice); 1594 inc->removeID(mCurrentSyncDevice);
1595 inc = iL.next(); 1595 inc = iL.next();
1596 } 1596 }
1597 } 1597 }
1598#ifndef DESKTOP_VERSION 1598#ifndef DESKTOP_VERSION
1599 if ( sharpFormat ) 1599 if ( sharpFormat )
1600 sharpFormat->save(calendar); 1600 sharpFormat->save(calendar);
1601#endif 1601#endif
1602 if ( phoneFormat ) 1602 if ( phoneFormat )
1603 phoneFormat->save(calendar); 1603 phoneFormat->save(calendar);
1604 iL = calendar->rawIncidences(); 1604 iL = calendar->rawIncidences();
1605 inc = iL.first(); 1605 inc = iL.first();
1606 Incidence* loc; 1606 Incidence* loc;
1607 while ( inc ) { 1607 while ( inc ) {
1608 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1608 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1609 loc = mCalendar->incidence(inc->uid() ); 1609 loc = mCalendar->incidence(inc->uid() );
1610 if ( loc ) { 1610 if ( loc ) {
1611 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1611 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1612 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1612 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1613 } 1613 }
1614 } 1614 }
1615 inc = iL.next(); 1615 inc = iL.next();
1616 } 1616 }
1617 Incidence* lse = getLastSyncEvent(); 1617 Incidence* lse = getLastSyncEvent();
1618 if ( lse ) { 1618 if ( lse ) {
1619 lse->setReadOnly( false ); 1619 lse->setReadOnly( false );
1620 lse->setDescription( "" ); 1620 lse->setDescription( "" );
1621 lse->setReadOnly( true ); 1621 lse->setReadOnly( true );
1622 } 1622 }
1623 } 1623 }
1624 } else { 1624 } else {
1625 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1625 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1626 } 1626 }
1627 setModified( true ); 1627 setModified( true );
1628 } else { 1628 } else {
1629 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1629 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1630 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1630 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1631 question, i18n("Ok")) ; 1631 question, i18n("Ok")) ;
1632 1632
1633 } 1633 }
1634 delete calendar; 1634 delete calendar;
1635 updateView(); 1635 updateView();
1636 emit tempDisableBR(false); 1636 emit tempDisableBR(false);
1637 return ;//syncOK; 1637 return ;//syncOK;
1638 1638
1639} 1639}
1640 1640
1641bool CalendarView::importBday() 1641bool CalendarView::importBday()
1642{ 1642{
1643#ifndef KORG_NOKABC 1643#ifndef KORG_NOKABC
1644 1644
1645#ifdef DESKTOP_VERSION 1645#ifdef DESKTOP_VERSION
1646 int curCal = mCalendar->defaultCalendar(); 1646 int curCal = mCalendar->defaultCalendar();
1647 int bd = mCalEditView->getBirtdayID(); 1647 int bd = mCalEditView->getBirtdayID();
1648 if ( bd == 0 ) 1648 if ( bd == 0 )
1649 return false; 1649 return false;
1650 mCalendar->setDefaultCalendar( bd ); 1650 mCalendar->setDefaultCalendar( bd );
1651 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1651 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1652 KABC::AddressBook::Iterator it; 1652 KABC::AddressBook::Iterator it;
1653 int count = 0; 1653 int count = 0;
1654 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1654 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1655 ++count; 1655 ++count;
1656 } 1656 }
1657 QProgressBar bar(count,0 ); 1657 QProgressBar bar(count,0 );
1658 int w = 300; 1658 int w = 300;
1659 if ( QApplication::desktop()->width() < 320 ) 1659 if ( QApplication::desktop()->width() < 320 )
1660 w = 220; 1660 w = 220;
1661 int h = bar.sizeHint().height() ; 1661 int h = bar.sizeHint().height() ;
1662 int dw = QApplication::desktop()->width(); 1662 int dw = QApplication::desktop()->width();
1663 int dh = QApplication::desktop()->height(); 1663 int dh = QApplication::desktop()->height();
1664 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1664 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1665 bar.show(); 1665 bar.show();
1666 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1666 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1667 qApp->processEvents(); 1667 qApp->processEvents();
1668 count = 0; 1668 count = 0;
1669 int addCount = 0; 1669 int addCount = 0;
1670 KCal::Attendee* a = 0; 1670 KCal::Attendee* a = 0;
1671 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1671 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1672 if ( ! bar.isVisible() ) 1672 if ( ! bar.isVisible() )
1673 return false; 1673 return false;
1674 bar.setProgress( count++ ); 1674 bar.setProgress( count++ );
1675 qApp->processEvents(); 1675 qApp->processEvents();
1676 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1676 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1677 if ( (*it).birthday().date().isValid() ){ 1677 if ( (*it).birthday().date().isValid() ){
1678 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1678 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1679 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1679 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1680 ++addCount; 1680 ++addCount;
1681 } 1681 }
1682 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1682 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1683 if ( anni.isValid() ){ 1683 if ( anni.isValid() ){
1684 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1684 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1685 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1685 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1686 ++addCount; 1686 ++addCount;
1687 } 1687 }
1688 } 1688 }
1689 mCalendar->setDefaultCalendar( curCal ); 1689 mCalendar->setDefaultCalendar( curCal );
1690 updateView(); 1690 updateView();
1691 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1691 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1692#else //DESKTOP_VERSION 1692#else //DESKTOP_VERSION
1693 1693
1694 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1694 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1695 // the result should now arrive through method insertBirthdays 1695 // the result should now arrive through method insertBirthdays
1696 1696
1697#endif //DESKTOP_VERSION 1697#endif //DESKTOP_VERSION
1698 1698
1699#endif //KORG_NOKABC 1699#endif //KORG_NOKABC
1700 1700
1701 1701
1702 return true; 1702 return true;
1703} 1703}
1704 1704
1705// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1705// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1706void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1706void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1707 const QStringList& anniversaryList, const QStringList& realNameList, 1707 const QStringList& anniversaryList, const QStringList& realNameList,
1708 const QStringList& emailList, const QStringList& assembledNameList, 1708 const QStringList& emailList, const QStringList& assembledNameList,
1709 const QStringList& uidList) 1709 const QStringList& uidList)
1710{ 1710{
1711 1711
1712 //qDebug("KO::CalendarView::insertBirthdays"); 1712 //qDebug("KO::CalendarView::insertBirthdays");
1713 if (uid == this->name()) 1713 if (uid == this->name())
1714 { 1714 {
1715 int curCal = mCalendar->defaultCalendar(); 1715 int curCal = mCalendar->defaultCalendar();
1716 int bd = mCalEditView->getBirtdayID(); 1716 int bd = mCalEditView->getBirtdayID();
1717 if ( bd == 0 ) 1717 if ( bd == 0 )
1718 return; 1718 return;
1719 mCalendar->setDefaultCalendar( bd ); 1719 mCalendar->setDefaultCalendar( bd );
1720 1720
1721 1721
1722 int count = birthdayList.count(); 1722 int count = birthdayList.count();
1723 int addCount = 0; 1723 int addCount = 0;
1724 KCal::Attendee* a = 0; 1724 KCal::Attendee* a = 0;
1725 1725
1726 //qDebug("CalView 1 %i", count); 1726 //qDebug("CalView 1 %i", count);
1727 1727
1728 QProgressBar bar(count,0 ); 1728 QProgressBar bar(count,0 );
1729 int w = 300; 1729 int w = 300;
1730 if ( QApplication::desktop()->width() < 320 ) 1730 if ( QApplication::desktop()->width() < 320 )
1731 w = 220; 1731 w = 220;
1732 int h = bar.sizeHint().height() ; 1732 int h = bar.sizeHint().height() ;
1733 int dw = QApplication::desktop()->width(); 1733 int dw = QApplication::desktop()->width();
1734 int dh = QApplication::desktop()->height(); 1734 int dh = QApplication::desktop()->height();
1735 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1735 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1736 bar.show(); 1736 bar.show();
1737 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1737 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1738 qApp->processEvents(); 1738 qApp->processEvents();
1739 1739
1740 QDate birthday; 1740 QDate birthday;
1741 QDate anniversary; 1741 QDate anniversary;
1742 QString realName; 1742 QString realName;
1743 QString email; 1743 QString email;
1744 QString assembledName; 1744 QString assembledName;
1745 QString uid; 1745 QString uid;
1746 bool ok = true; 1746 bool ok = true;
1747 for ( int i = 0; i < count; i++) 1747 for ( int i = 0; i < count; i++)
1748 { 1748 {
1749 if ( ! bar.isVisible() ) 1749 if ( ! bar.isVisible() )
1750 return; 1750 return;
1751 bar.setProgress( i ); 1751 bar.setProgress( i );
1752 qApp->processEvents(); 1752 qApp->processEvents();
1753 1753
1754 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1754 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1755 if (!ok) { 1755 if (!ok) {
1756 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1756 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1757 } 1757 }
1758 1758
1759 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1759 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1760 if (!ok) { 1760 if (!ok) {
1761 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1761 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1762 } 1762 }
1763 realName = realNameList[i]; 1763 realName = realNameList[i];
1764 email = emailList[i]; 1764 email = emailList[i];
1765 assembledName = assembledNameList[i]; 1765 assembledName = assembledNameList[i];
1766 uid = uidList[i]; 1766 uid = uidList[i];
1767 //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() ); 1767 //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() );
1768 1768
1769 if ( birthday.isValid() ){ 1769 if ( birthday.isValid() ){
1770 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1770 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1771 KCal::Attendee::ReqParticipant,uid) ; 1771 KCal::Attendee::ReqParticipant,uid) ;
1772 if ( addAnniversary( birthday, assembledName, a, true ) ) 1772 if ( addAnniversary( birthday, assembledName, a, true ) )
1773 ++addCount; 1773 ++addCount;
1774 } 1774 }
1775 1775
1776 if ( anniversary.isValid() ){ 1776 if ( anniversary.isValid() ){
1777 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1777 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1778 KCal::Attendee::ReqParticipant,uid) ; 1778 KCal::Attendee::ReqParticipant,uid) ;
1779 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1779 if ( addAnniversary( anniversary, assembledName, a, false ) )
1780 ++addCount; 1780 ++addCount;
1781 } 1781 }
1782 } 1782 }
1783 1783
1784 mCalendar->setDefaultCalendar( curCal ); 1784 mCalendar->setDefaultCalendar( curCal );
1785 updateView(); 1785 updateView();
1786 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1786 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1787 1787
1788 } 1788 }
1789 1789
1790} 1790}
1791 1791
1792 1792
1793 1793
1794bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1794bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1795{ 1795{
1796 //qDebug("addAnni "); 1796 //qDebug("addAnni ");
1797 Event * ev = new Event(); 1797 Event * ev = new Event();
1798 ev->setOrganizer(KOPrefs::instance()->email()); 1798 ev->setOrganizer(KOPrefs::instance()->email());
1799 if ( a ) { 1799 if ( a ) {
1800 ev->addAttendee( a ); 1800 ev->addAttendee( a );
1801 } 1801 }
1802 QString kind; 1802 QString kind;
1803 if ( birthday ) { 1803 if ( birthday ) {
1804 kind = i18n( "Birthday" ); 1804 kind = i18n( "Birthday" );
1805 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1805 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1806 } 1806 }
1807 else { 1807 else {
1808 kind = i18n( "Anniversary" ); 1808 kind = i18n( "Anniversary" );
1809 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1809 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1810 } 1810 }
1811 ev->setCategories( kind ); 1811 ev->setCategories( kind );
1812 ev->setDtStart( QDateTime(date) ); 1812 ev->setDtStart( QDateTime(date) );
1813 ev->setDtEnd( QDateTime(date) ); 1813 ev->setDtEnd( QDateTime(date) );
1814 ev->setFloats( true ); 1814 ev->setFloats( true );
1815 Recurrence * rec = ev->recurrence(); 1815 Recurrence * rec = ev->recurrence();
1816 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1816 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1817 rec->addYearlyNum( date.month() ); 1817 rec->addYearlyNum( date.month() );
1818 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1818 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1819 delete ev; 1819 delete ev;
1820 return false; 1820 return false;
1821 } 1821 }
1822 return true; 1822 return true;
1823 1823
1824} 1824}
1825bool CalendarView::importQtopia( const QString &categories, 1825bool CalendarView::importQtopia( const QString &categories,
1826 const QString &datebook, 1826 const QString &datebook,
1827 const QString &todolist ) 1827 const QString &todolist )
1828{ 1828{
1829 1829
1830 QtopiaFormat qtopiaFormat; 1830 QtopiaFormat qtopiaFormat;
1831 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1831 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1832 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1832 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1833 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1833 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1834 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1834 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1835 1835
1836 updateView(); 1836 updateView();
1837 return true; 1837 return true;
1838 1838
1839#if 0 1839#if 0
1840 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1840 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1841 mCurrentSyncDevice = "qtopia-XML"; 1841 mCurrentSyncDevice = "qtopia-XML";
1842 if ( mSyncManager->mAskForPreferences ) 1842 if ( mSyncManager->mAskForPreferences )
1843 edit_sync_options(); 1843 edit_sync_options();
1844 qApp->processEvents(); 1844 qApp->processEvents();
1845 CalendarLocal* calendar = new CalendarLocal(); 1845 CalendarLocal* calendar = new CalendarLocal();
1846 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1846 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1847 bool syncOK = false; 1847 bool syncOK = false;
1848 QtopiaFormat qtopiaFormat; 1848 QtopiaFormat qtopiaFormat;
1849 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1849 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1850 bool loadOk = true; 1850 bool loadOk = true;
1851 if ( !categories.isEmpty() ) 1851 if ( !categories.isEmpty() )
1852 loadOk = qtopiaFormat.load( calendar, categories ); 1852 loadOk = qtopiaFormat.load( calendar, categories );
1853 if ( loadOk && !datebook.isEmpty() ) 1853 if ( loadOk && !datebook.isEmpty() )
1854 loadOk = qtopiaFormat.load( calendar, datebook ); 1854 loadOk = qtopiaFormat.load( calendar, datebook );
1855 if ( loadOk && !todolist.isEmpty() ) 1855 if ( loadOk && !todolist.isEmpty() )
1856 loadOk = qtopiaFormat.load( calendar, todolist ); 1856 loadOk = qtopiaFormat.load( calendar, todolist );
1857 1857
1858 if ( loadOk ) { 1858 if ( loadOk ) {
1859 getEventViewerDialog()->setSyncMode( true ); 1859 getEventViewerDialog()->setSyncMode( true );
1860 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1860 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1861 getEventViewerDialog()->setSyncMode( false ); 1861 getEventViewerDialog()->setSyncMode( false );
1862 qApp->processEvents(); 1862 qApp->processEvents();
1863 if ( syncOK ) { 1863 if ( syncOK ) {
1864 if ( mSyncManager->mWriteBackFile ) 1864 if ( mSyncManager->mWriteBackFile )
1865 { 1865 {
1866 // write back XML file 1866 // write back XML file
1867 1867
1868 } 1868 }
1869 setModified( true ); 1869 setModified( true );
1870 } 1870 }
1871 } else { 1871 } else {
1872 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1872 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1873 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1873 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1874 question, i18n("Ok")) ; 1874 question, i18n("Ok")) ;
1875 } 1875 }
1876 delete calendar; 1876 delete calendar;
1877 updateView(); 1877 updateView();
1878 return syncOK; 1878 return syncOK;
1879 1879
1880 1880
1881#endif 1881#endif
1882 1882
1883} 1883}
1884 1884
1885void CalendarView::setSyncEventsReadOnly() 1885void CalendarView::setSyncEventsReadOnly()
1886{ 1886{
1887 mCalendar->setSyncEventsReadOnly(); 1887 mCalendar->setSyncEventsReadOnly();
1888} 1888}
1889 1889
1890bool CalendarView::loadCalendars() 1890bool CalendarView::loadCalendars()
1891{ 1891{
1892 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1892 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1893 KopiCalendarFile * cal = calendars.first(); 1893 KopiCalendarFile * cal = calendars.first();
1894 mCalendar->setDefaultCalendar( 1 ); 1894 mCalendar->setDefaultCalendar( 1 );
1895 openCalendar( MainWindow::defaultFileName(), false ); 1895 openCalendar( MainWindow::defaultFileName(), false );
1896 cal = calendars.next(); 1896 cal = calendars.next();
1897 while ( cal ) { 1897 while ( cal ) {
1898 addCalendar( cal ); 1898 addCalendar( cal );
1899 cal = calendars.next(); 1899 cal = calendars.next();
1900 } 1900 }
1901 restoreCalendarSettings(); 1901 restoreCalendarSettings();
1902 return true; 1902 return true;
1903} 1903}
1904bool CalendarView::restoreCalendarSettings() 1904bool CalendarView::restoreCalendarSettings()
1905{ 1905{
1906 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1906 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1907 KopiCalendarFile * cal = calendars.first(); 1907 KopiCalendarFile * cal = calendars.first();
1908 while ( cal ) { 1908 while ( cal ) {
1909 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 1909 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
1910 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 1910 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
1911 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 1911 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
1912 if ( cal->isStandard ) 1912 if ( cal->isStandard )
1913 mCalendar->setDefaultCalendar( cal->mCalNumber ); 1913 mCalendar->setDefaultCalendar( cal->mCalNumber );
1914 cal = calendars.next(); 1914 cal = calendars.next();
1915 } 1915 }
1916 setSyncEventsReadOnly(); 1916 setSyncEventsReadOnly();
1917 mCalendar->reInitAlarmSettings(); 1917 mCalendar->reInitAlarmSettings();
1918 updateUnmanagedViews(); 1918 updateUnmanagedViews();
1919 updateView(); 1919 updateView();
1920 return true; 1920 return true;
1921} 1921}
1922void CalendarView::addCalendarId( int id ) 1922void CalendarView::addCalendarId( int id )
1923{ 1923{
1924 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 1924 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
1925 addCalendar( cal ); 1925 addCalendar( cal );
1926} 1926}
1927bool CalendarView::addCalendar( KopiCalendarFile * cal ) 1927bool CalendarView::addCalendar( KopiCalendarFile * cal )
1928{ 1928{
1929 cal->mErrorOnLoad = false; 1929 cal->mErrorOnLoad = false;
1930 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 1930 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
1931 cal->mLoadDt = QDateTime::currentDateTime(); 1931 cal->mLoadDt = QDateTime::currentDateTime();
1932 return true; 1932 return true;
1933 } 1933 }
1934 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); 1934 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() );
1935 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); 1935 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName));
1936 cal->mErrorOnLoad = true; 1936 cal->mErrorOnLoad = true;
1937 return false; 1937 return false;
1938} 1938}
1939bool CalendarView::openCalendar(QString filename, bool merge) 1939bool CalendarView::openCalendar(QString filename, bool merge)
1940{ 1940{
1941 1941
1942 if (filename.isEmpty()) { 1942 if (filename.isEmpty()) {
1943 return false; 1943 return false;
1944 } 1944 }
1945 1945
1946 if (!QFile::exists(filename)) { 1946 if (!QFile::exists(filename)) {
1947 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1947 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1948 return false; 1948 return false;
1949 } 1949 }
1950 1950
1951 globalFlagBlockAgenda = 1; 1951 globalFlagBlockAgenda = 1;
1952 clearAllViews(); 1952 clearAllViews();
1953 if (!merge) { 1953 if (!merge) {
1954 mViewManager->setDocumentId( filename ); 1954 mViewManager->setDocumentId( filename );
1955 mCalendar->close(); 1955 mCalendar->close();
1956 } 1956 }
1957 mStorage->setFileName( filename ); 1957 mStorage->setFileName( filename );
1958 1958
1959 if ( mStorage->load() ) { 1959 if ( mStorage->load() ) {
1960 if ( merge ) ;//setModified( true ); 1960 if ( merge ) ;//setModified( true );
1961 else { 1961 else {
1962 //setModified( true ); 1962 //setModified( true );
1963 mViewManager->setDocumentId( filename ); 1963 mViewManager->setDocumentId( filename );
1964 mDialogManager->setDocumentId( filename ); 1964 mDialogManager->setDocumentId( filename );
1965 mTodoList->setDocumentId( filename ); 1965 mTodoList->setDocumentId( filename );
1966 } 1966 }
1967 globalFlagBlockAgenda = 2; 1967 globalFlagBlockAgenda = 2;
1968 // if ( getLastSyncEvent() ) 1968 // if ( getLastSyncEvent() )
1969 // getLastSyncEvent()->setReadOnly( true ); 1969 // getLastSyncEvent()->setReadOnly( true );
1970 mCalendar->reInitAlarmSettings(); 1970 mCalendar->reInitAlarmSettings();
1971 setSyncEventsReadOnly(); 1971 setSyncEventsReadOnly();
1972 updateUnmanagedViews(); 1972 updateUnmanagedViews();
1973 updateView(); 1973 updateView();
1974 if ( filename != MainWindow::defaultFileName() ) { 1974 if ( filename != MainWindow::defaultFileName() ) {
1975 saveCalendar( MainWindow::defaultFileName() ); 1975 saveCalendar( MainWindow::defaultFileName() );
1976 } else { 1976 } else {
1977 QFileInfo finf ( MainWindow::defaultFileName()); 1977 QFileInfo finf ( MainWindow::defaultFileName());
1978 if ( finf.exists() ) { 1978 if ( finf.exists() ) {
1979 setLoadedFileVersion( finf.lastModified () ); 1979 setLoadedFileVersion( finf.lastModified () );
1980 } 1980 }
1981 } 1981 }
1982 return true; 1982 return true;
1983 } else { 1983 } else {
1984 // while failing to load, the calendar object could 1984 // while failing to load, the calendar object could
1985 // have become partially populated. Clear it out. 1985 // have become partially populated. Clear it out.
1986 if ( !merge ) { 1986 if ( !merge ) {
1987 mCalendar->close(); 1987 mCalendar->close();
1988 mViewManager->setDocumentId( filename ); 1988 mViewManager->setDocumentId( filename );
1989 mDialogManager->setDocumentId( filename ); 1989 mDialogManager->setDocumentId( filename );
1990 mTodoList->setDocumentId( filename ); 1990 mTodoList->setDocumentId( filename );
1991 } 1991 }
1992 1992
1993 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1993 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1994 1994
1995 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1995 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1996 globalFlagBlockAgenda = 2; 1996 globalFlagBlockAgenda = 2;
1997 mCalendar->reInitAlarmSettings(); 1997 mCalendar->reInitAlarmSettings();
1998 setSyncEventsReadOnly(); 1998 setSyncEventsReadOnly();
1999 updateUnmanagedViews(); 1999 updateUnmanagedViews();
2000 updateView(); 2000 updateView();
2001 } 2001 }
2002 return false; 2002 return false;
2003} 2003}
2004void CalendarView::showOpenError() 2004void CalendarView::showOpenError()
2005{ 2005{
2006 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2006 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2007} 2007}
2008void CalendarView::setLoadedFileVersion(QDateTime dt) 2008void CalendarView::setLoadedFileVersion(QDateTime dt)
2009{ 2009{
2010 loadedFileVersion = dt; 2010 loadedFileVersion = dt;
2011} 2011}
2012bool CalendarView::checkFileChanged(QString fn) 2012bool CalendarView::checkFileChanged(QString fn)
2013{ 2013{
2014 QFileInfo finf ( fn ); 2014 QFileInfo finf ( fn );
2015 if ( !finf.exists() ) 2015 if ( !finf.exists() )
2016 return true; 2016 return true;
2017 QDateTime dt = finf.lastModified (); 2017 QDateTime dt = finf.lastModified ();
2018 if ( dt <= loadedFileVersion ) 2018 if ( dt <= loadedFileVersion )
2019 return false; 2019 return false;
2020 return true; 2020 return true;
2021 2021
2022} 2022}
2023void CalendarView::watchSavedFile() 2023void CalendarView::watchSavedFile()
2024{ 2024{
2025 QFileInfo finf ( MainWindow::defaultFileName()); 2025 QFileInfo finf ( MainWindow::defaultFileName());
2026 if ( !finf.exists() ) 2026 if ( !finf.exists() )
2027 return; 2027 return;
2028 QDateTime dt = finf.lastModified (); 2028 QDateTime dt = finf.lastModified ();
2029 if ( dt < loadedFileVersion ) { 2029 if ( dt < loadedFileVersion ) {
2030 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2030 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2031 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2031 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2032 return; 2032 return;
2033 } 2033 }
2034 loadedFileVersion = dt; 2034 loadedFileVersion = dt;
2035} 2035}
2036bool CalendarView::checkAllFileVersions() 2036bool CalendarView::checkAllFileVersions()
2037{ 2037{
2038 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2038 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2039 KopiCalendarFile * cal = calendars.first(); 2039 KopiCalendarFile * cal = calendars.first();
2040 mCalendar->setDefaultCalendar( 1 ); 2040 mCalendar->setDefaultCalendar( 1 );
2041 mCalendar->setDefaultCalendarEnabledOnly(); 2041 mCalendar->setDefaultCalendarEnabledOnly();
2042 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2042 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2043 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2043 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2044 restoreCalendarSettings(); 2044 restoreCalendarSettings();
2045 return false; 2045 return false;
2046 } 2046 }
2047 } 2047 }
2048 cal = calendars.next(); 2048 cal = calendars.next();
2049 QDateTime storeTemp = loadedFileVersion; 2049 QDateTime storeTemp = loadedFileVersion;
2050 while ( cal ) { 2050 while ( cal ) {
2051 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2051 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2052 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2052 mCalendar->setDefaultCalendar( cal->mCalNumber );
2053 mCalendar->setDefaultCalendarEnabledOnly(); 2053 mCalendar->setDefaultCalendarEnabledOnly();
2054 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2054 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2055 if ( !checkFileVersion(cal->mFileName )) { 2055 if ( !checkFileVersion(cal->mFileName )) {
2056 loadedFileVersion = storeTemp; 2056 loadedFileVersion = storeTemp;
2057 restoreCalendarSettings(); 2057 restoreCalendarSettings();
2058 return false; 2058 return false;
2059 } 2059 }
2060 } 2060 }
2061 cal = calendars.next(); 2061 cal = calendars.next();
2062 } 2062 }
2063 loadedFileVersion = storeTemp; 2063 loadedFileVersion = storeTemp;
2064 return true; 2064 return true;
2065} 2065}
2066bool CalendarView::checkFileVersion(QString fn) 2066bool CalendarView::checkFileVersion(QString fn)
2067{ 2067{
2068 QFileInfo finf ( fn ); 2068 QFileInfo finf ( fn );
2069 if ( !finf.exists() ) 2069 if ( !finf.exists() )
2070 return true; 2070 return true;
2071 QDateTime dt = finf.lastModified (); 2071 QDateTime dt = finf.lastModified ();
2072 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2072 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2073 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2073 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2074 if ( dt <= loadedFileVersion ) 2074 if ( dt <= loadedFileVersion )
2075 return true; 2075 return true;
2076 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on 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(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2076 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on 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(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2077 i18n("KO/Pi Warning"),i18n("Overwrite"), 2077 i18n("KO/Pi Warning"),i18n("Overwrite"),
2078 i18n("Sync+save")); 2078 i18n("Sync+save"));
2079 2079
2080 if ( km == KMessageBox::Cancel ) 2080 if ( km == KMessageBox::Cancel )
2081 return false; 2081 return false;
2082 if ( km == KMessageBox::Yes ) 2082 if ( km == KMessageBox::Yes )
2083 return true; 2083 return true;
2084 2084
2085 setSyncDevice("deleteaftersync" ); 2085 setSyncDevice("deleteaftersync" );
2086 mSyncManager->mAskForPreferences = true; 2086 mSyncManager->mAskForPreferences = true;
2087 mSyncManager->mSyncAlgoPrefs = 3; 2087 mSyncManager->mSyncAlgoPrefs = 3;
2088 mSyncManager->mWriteBackFile = false; 2088 mSyncManager->mWriteBackFile = false;
2089 mSyncManager->mWriteBackExistingOnly = false; 2089 mSyncManager->mWriteBackExistingOnly = false;
2090 mSyncManager->mShowSyncSummary = false; 2090 mSyncManager->mShowSyncSummary = false;
2091 syncCalendar( fn, 3 ); 2091 syncCalendar( fn, 3 );
2092 Event * e = getLastSyncEvent(); 2092 Event * e = getLastSyncEvent();
2093 if ( e ) 2093 if ( e )
2094 mCalendar->deleteEvent( e ); 2094 mCalendar->deleteEvent( e );
2095 return true; 2095 return true;
2096} 2096}
2097bool CalendarView::saveCalendars() 2097bool CalendarView::saveCalendars()
2098{ 2098{
2099 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2099 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2100 KopiCalendarFile * cal = calendars.first(); 2100 KopiCalendarFile * cal = calendars.first();
2101 mCalendar->setDefaultCalendar( 1 ); 2101 mCalendar->setDefaultCalendar( 1 );
2102 mCalendar->setDefaultCalendarEnabledOnly(); 2102 mCalendar->setDefaultCalendarEnabledOnly();
2103 saveCalendar( MainWindow::defaultFileName() ); 2103 saveCalendar( MainWindow::defaultFileName() );
2104 cal = calendars.next(); 2104 cal = calendars.next();
2105 while ( cal ) { 2105 while ( cal ) {
2106 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2106 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2107 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2107 mCalendar->setDefaultCalendar( cal->mCalNumber );
2108 mCalendar->setDefaultCalendarEnabledOnly(); 2108 mCalendar->setDefaultCalendarEnabledOnly();
2109 if ( saveCalendar( cal->mFileName ) ) 2109 if ( saveCalendar( cal->mFileName ) )
2110 cal->mLoadDt = QDateTime::currentDateTime(); 2110 cal->mLoadDt = QDateTime::currentDateTime();
2111 } 2111 }
2112 cal = calendars.next(); 2112 cal = calendars.next();
2113 } 2113 }
2114 restoreCalendarSettings(); 2114 restoreCalendarSettings();
2115 return true; 2115 return true;
2116} 2116}
2117bool CalendarView::saveCalendar( QString filename ) 2117bool CalendarView::saveCalendar( QString filename )
2118{ 2118{
2119 2119
2120 // Store back all unsaved data into calendar object 2120 // Store back all unsaved data into calendar object
2121 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2121 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2122 if ( mViewManager->currentView() ) 2122 if ( mViewManager->currentView() )
2123 mViewManager->currentView()->flushView(); 2123 mViewManager->currentView()->flushView();
2124 2124
2125 2125
2126 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2126 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2127 mStorage->setSaveFormat( new ICalFormat() ); 2127 mStorage->setSaveFormat( new ICalFormat() );
2128 mStorage->setFileName( filename ); 2128 mStorage->setFileName( filename );
2129 bool success; 2129 bool success;
2130 success = mStorage->save(); 2130 success = mStorage->save();
2131 if ( !success ) { 2131 if ( !success ) {
2132 return false; 2132 return false;
2133 } 2133 }
2134 if ( filename == MainWindow::defaultFileName() ) { 2134 if ( filename == MainWindow::defaultFileName() ) {
2135 setLoadedFileVersion( lfv ); 2135 setLoadedFileVersion( lfv );
2136 watchSavedFile(); 2136 watchSavedFile();
2137 } 2137 }
2138 return true; 2138 return true;
2139} 2139}
2140 2140
2141void CalendarView::closeCalendar() 2141void CalendarView::closeCalendar()
2142{ 2142{
2143 2143
2144 // child windows no longer valid 2144 // child windows no longer valid
2145 clearAllViews(); 2145 clearAllViews();
2146 emit closingDown(); 2146 emit closingDown();
2147 2147
2148 mCalendar->close(); 2148 mCalendar->close();
2149 setModified(false); 2149 setModified(false);
2150 updateView(); 2150 updateView();
2151} 2151}
2152 2152
2153void CalendarView::archiveCalendar() 2153void CalendarView::archiveCalendar()
2154{ 2154{
2155 mDialogManager->showArchiveDialog(); 2155 mDialogManager->showArchiveDialog();
2156} 2156}
2157 2157
2158 2158
2159void CalendarView::readSettings() 2159void CalendarView::readSettings()
2160{ 2160{
2161 2161
2162 2162
2163 // mViewManager->showAgendaView(); 2163 // mViewManager->showAgendaView();
2164 QString str; 2164 QString str;
2165 //qDebug("CalendarView::readSettings() "); 2165 //qDebug("CalendarView::readSettings() ");
2166 // read settings from the KConfig, supplying reasonable 2166 // read settings from the KConfig, supplying reasonable
2167 // defaults where none are to be found 2167 // defaults where none are to be found
2168 KConfig *config = KOGlobals::config(); 2168 KConfig *config = KOGlobals::config();
2169#ifndef KORG_NOSPLITTER 2169#ifndef KORG_NOSPLITTER
2170 config->setGroup("KOrganizer Geometry"); 2170 config->setGroup("KOrganizer Geometry");
2171 2171
2172 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2172 QValueList<int> sizes = config->readIntListEntry("Separator1");
2173 if (sizes.count() != 2) { 2173 if (sizes.count() != 2) {
2174 sizes << mDateNavigator->minimumSizeHint().width(); 2174 sizes << mDateNavigator->minimumSizeHint().width();
2175 sizes << 300; 2175 sizes << 300;
2176 } 2176 }
2177 mPanner->setSizes(sizes); 2177 mPanner->setSizes(sizes);
2178 2178
2179 sizes = config->readIntListEntry("Separator2"); 2179 sizes = config->readIntListEntry("Separator2");
2180 if ( ( mResourceView && sizes.count() == 4 ) || 2180 if ( ( mResourceView && sizes.count() == 4 ) ||
2181 ( !mResourceView && sizes.count() == 3 ) ) { 2181 ( !mResourceView && sizes.count() == 3 ) ) {
2182 mLeftSplitter->setSizes(sizes); 2182 mLeftSplitter->setSizes(sizes);
2183 } 2183 }
2184#endif 2184#endif
2185 globalFlagBlockAgenda = 1; 2185 globalFlagBlockAgenda = 1;
2186 mViewManager->showAgendaView(); 2186 mViewManager->showAgendaView();
2187 //mViewManager->readSettings( config ); 2187 //mViewManager->readSettings( config );
2188 mTodoList->restoreLayout(config,QString("Todo Layout")); 2188 mTodoList->restoreLayout(config,QString("Todo Layout"));
2189 readFilterSettings(config); 2189 readFilterSettings(config);
2190 2190
2191#ifdef DESKTOP_VERSION 2191#ifdef DESKTOP_VERSION
2192 config->setGroup("WidgetLayout"); 2192 config->setGroup("WidgetLayout");
2193 QStringList list; 2193 QStringList list;
2194 list = config->readListEntry("MainLayout"); 2194 list = config->readListEntry("MainLayout");
2195 int x,y,w,h; 2195 int x,y,w,h;
2196 if ( ! list.isEmpty() ) { 2196 if ( ! list.isEmpty() ) {
2197 x = list[0].toInt(); 2197 x = list[0].toInt();
2198 y = list[1].toInt(); 2198 y = list[1].toInt();
2199 w = list[2].toInt(); 2199 w = list[2].toInt();
2200 h = list[3].toInt(); 2200 h = list[3].toInt();
2201 KApplication::testCoords( &x,&y,&w,&h ); 2201 KApplication::testCoords( &x,&y,&w,&h );
2202 topLevelWidget()->setGeometry(x,y,w,h); 2202 topLevelWidget()->setGeometry(x,y,w,h);
2203 2203
2204 } else { 2204 } else {
2205 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2205 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2206 } 2206 }
2207 list = config->readListEntry("EditEventLayout"); 2207 list = config->readListEntry("EditEventLayout");
2208 if ( ! list.isEmpty() ) { 2208 if ( ! list.isEmpty() ) {
2209 x = list[0].toInt(); 2209 x = list[0].toInt();
2210 y = list[1].toInt(); 2210 y = list[1].toInt();
2211 w = list[2].toInt(); 2211 w = list[2].toInt();
2212 h = list[3].toInt(); 2212 h = list[3].toInt();
2213 KApplication::testCoords( &x,&y,&w,&h ); 2213 KApplication::testCoords( &x,&y,&w,&h );
2214 mEventEditor->setGeometry(x,y,w,h); 2214 mEventEditor->setGeometry(x,y,w,h);
2215 2215
2216 } 2216 }
2217 list = config->readListEntry("EditTodoLayout"); 2217 list = config->readListEntry("EditTodoLayout");
2218 if ( ! list.isEmpty() ) { 2218 if ( ! list.isEmpty() ) {
2219 x = list[0].toInt(); 2219 x = list[0].toInt();
2220 y = list[1].toInt(); 2220 y = list[1].toInt();
2221 w = list[2].toInt(); 2221 w = list[2].toInt();
2222 h = list[3].toInt(); 2222 h = list[3].toInt();
2223 KApplication::testCoords( &x,&y,&w,&h ); 2223 KApplication::testCoords( &x,&y,&w,&h );
2224 mTodoEditor->setGeometry(x,y,w,h); 2224 mTodoEditor->setGeometry(x,y,w,h);
2225 2225
2226 } 2226 }
2227 list = config->readListEntry("ViewerLayout"); 2227 list = config->readListEntry("ViewerLayout");
2228 if ( ! list.isEmpty() ) { 2228 if ( ! list.isEmpty() ) {
2229 x = list[0].toInt(); 2229 x = list[0].toInt();
2230 y = list[1].toInt(); 2230 y = list[1].toInt();
2231 w = list[2].toInt(); 2231 w = list[2].toInt();
2232 h = list[3].toInt(); 2232 h = list[3].toInt();
2233 KApplication::testCoords( &x,&y,&w,&h ); 2233 KApplication::testCoords( &x,&y,&w,&h );
2234 getEventViewerDialog()->setGeometry(x,y,w,h); 2234 getEventViewerDialog()->setGeometry(x,y,w,h);
2235 } 2235 }
2236#endif 2236#endif
2237 config->setGroup( "Views" ); 2237 config->setGroup( "Views" );
2238 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2238 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2239 2239
2240 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2240 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2241 2241
2242 int resetval = 0; 2242 int resetval = 0;
2243 int maxVal = 0; 2243 int maxVal = 0;
2244 if (sizes.count() != 3) { 2244 if (sizes.count() != 3) {
2245 if ( KOPrefs::instance()->mVerticalScreen ) { 2245 if ( KOPrefs::instance()->mVerticalScreen ) {
2246 resetval = mDateNavigator->sizeHint().width()+2; 2246 resetval = mDateNavigator->sizeHint().width()+2;
2247 } else { 2247 } else {
2248 resetval = mDateNavigator->sizeHint().height()+2; 2248 resetval = mDateNavigator->sizeHint().height()+2;
2249 } 2249 }
2250 } 2250 }
2251 if ( resetval ) { 2251 if ( resetval ) {
2252 sizes.clear(); 2252 sizes.clear();
2253 if ( KOPrefs::instance()->mVerticalScreen ) { 2253 if ( KOPrefs::instance()->mVerticalScreen ) {
2254 maxVal = QApplication::desktop()->width() -10; 2254 maxVal = QApplication::desktop()->width() -10;
2255 } else { 2255 } else {
2256 maxVal = QApplication::desktop()->height()-10; 2256 maxVal = QApplication::desktop()->height()-10;
2257 } 2257 }
2258 sizes << resetval; 2258 sizes << resetval;
2259 if ( maxVal < resetval + resetval) 2259 if ( maxVal < resetval + resetval)
2260 resetval = maxVal - resetval; 2260 resetval = maxVal - resetval;
2261 sizes << resetval; 2261 sizes << resetval;
2262 sizes << 100; 2262 sizes << 100;
2263 } 2263 }
2264 mLeftFrame->setSizes(sizes); 2264 mLeftFrame->setSizes(sizes);
2265 sizes = config->readIntListEntry("Main Splitter Frame"); 2265 sizes = config->readIntListEntry("Main Splitter Frame");
2266 resetval = 0; 2266 resetval = 0;
2267 maxVal = 0; 2267 maxVal = 0;
2268 if (sizes.count() != 2) { 2268 if (sizes.count() != 2) {
2269 if ( !KOPrefs::instance()->mVerticalScreen ) { 2269 if ( !KOPrefs::instance()->mVerticalScreen ) {
2270 resetval = mDateNavigator->sizeHint().width()+2; 2270 resetval = mDateNavigator->sizeHint().width()+2;
2271 } else { 2271 } else {
2272 resetval = mDateNavigator->sizeHint().height()+2; 2272 resetval = mDateNavigator->sizeHint().height()+2;
2273 } 2273 }
2274 } 2274 }
2275 if ( resetval ) { 2275 if ( resetval ) {
2276 sizes.clear(); 2276 sizes.clear();
2277 if ( !KOPrefs::instance()->mVerticalScreen ) { 2277 if ( !KOPrefs::instance()->mVerticalScreen ) {
2278 maxVal = QApplication::desktop()->width() -10; 2278 maxVal = QApplication::desktop()->width() -10;
2279 } else { 2279 } else {
2280 maxVal = QApplication::desktop()->height()-10; 2280 maxVal = QApplication::desktop()->height()-10;
2281 } 2281 }
2282 sizes << resetval; 2282 sizes << resetval;
2283 if ( maxVal < resetval + resetval) 2283 if ( maxVal < resetval + resetval)
2284 resetval = maxVal - resetval; 2284 resetval = maxVal - resetval;
2285 sizes << resetval; 2285 sizes << resetval;
2286 } 2286 }
2287 mMainFrame->setSizes(sizes); 2287 mMainFrame->setSizes(sizes);
2288 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2288 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2289 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2289 else if ( dateCount == 7 ) mNavigator->selectWeek();
2290 else mNavigator->selectDates( dateCount ); 2290 else mNavigator->selectDates( dateCount );
2291 // mViewManager->readSettings( config ); 2291 // mViewManager->readSettings( config );
2292 updateConfig(); 2292 updateConfig();
2293 globalFlagBlockAgenda = 2; 2293 globalFlagBlockAgenda = 2;
2294 mViewManager->readSettings( config ); 2294 mViewManager->readSettings( config );
2295 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2295 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2296} 2296}
2297 2297
2298 2298
2299void CalendarView::writeSettings() 2299void CalendarView::writeSettings()
2300{ 2300{
2301 // kdDebug() << "CalendarView::writeSettings" << endl; 2301 // kdDebug() << "CalendarView::writeSettings" << endl;
2302 2302
2303 KConfig *config = KOGlobals::config(); 2303 KConfig *config = KOGlobals::config();
2304 2304
2305 mViewManager->writeSettings( config ); 2305 mViewManager->writeSettings( config );
2306 mTodoList->saveLayout(config,QString("Todo Layout")); 2306 mTodoList->saveLayout(config,QString("Todo Layout"));
2307 mDialogManager->writeSettings( config ); 2307 mDialogManager->writeSettings( config );
2308 //KOPrefs::instance()->usrWriteConfig(); 2308 //KOPrefs::instance()->usrWriteConfig();
2309 KOPrefs::instance()->writeConfig(); 2309 KOPrefs::instance()->writeConfig();
2310 2310
2311 writeFilterSettings(config); 2311 writeFilterSettings(config);
2312 config->setGroup( "AppRun" ); 2312 config->setGroup( "AppRun" );
2313 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2313 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2314 int days = dt.daysTo( QDate::currentDate() ); 2314 int days = dt.daysTo( QDate::currentDate() );
2315 dt = dt.addDays( days ); 2315 dt = dt.addDays( days );
2316 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2316 int secs = dt.secsTo( QDateTime::currentDateTime() );
2317 config->writeEntry( "LatestProgramStopDays", days ); 2317 config->writeEntry( "LatestProgramStopDays", days );
2318 config->writeEntry( "LatestProgramStopSecs", secs ); 2318 config->writeEntry( "LatestProgramStopSecs", secs );
2319 //qDebug("KO: Writing stop time: %d ", secs); 2319 //qDebug("KO: Writing stop time: %d ", secs);
2320 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2320 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2321 //QDateTime latest = dt.addSecs ( secs ); 2321 //QDateTime latest = dt.addSecs ( secs );
2322 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2322 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2323 config->setGroup( "Views" ); 2323 config->setGroup( "Views" );
2324 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2324 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2325 2325
2326#if 0 2326#if 0
2327 qDebug("********************* "); 2327 qDebug("********************* ");
2328 qDebug("Testcode secsto "); 2328 qDebug("Testcode secsto ");
2329 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2329 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2330 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2330 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2331 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2331 int secsto = dt_nodaylight.secsTo( dt_daylight );
2332 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2332 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2333 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2333 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2334 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2334 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2335 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2335 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2336 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2336 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2337 qDebug("********************* testcode end"); 2337 qDebug("********************* testcode end");
2338 2338
2339#endif 2339#endif
2340 2340
2341 QValueList<int> listINT = mLeftFrame->sizes(); 2341 QValueList<int> listINT = mLeftFrame->sizes();
2342 config->writeEntry("Left Splitter Frame",listINT); 2342 config->writeEntry("Left Splitter Frame",listINT);
2343 QValueList<int> listINT2 = mMainFrame->sizes(); 2343 QValueList<int> listINT2 = mMainFrame->sizes();
2344 config->writeEntry("Main Splitter Frame",listINT2); 2344 config->writeEntry("Main Splitter Frame",listINT2);
2345#ifdef DESKTOP_VERSION 2345#ifdef DESKTOP_VERSION
2346 config->setGroup("WidgetLayout"); 2346 config->setGroup("WidgetLayout");
2347 QStringList list ;//= config->readListEntry("MainLayout"); 2347 QStringList list ;//= config->readListEntry("MainLayout");
2348 int x,y,w,h; 2348 int x,y,w,h;
2349 QWidget* wid; 2349 QWidget* wid;
2350 wid = topLevelWidget(); 2350 wid = topLevelWidget();
2351 x = wid->geometry().x(); 2351 x = wid->geometry().x();
2352 y = wid->geometry().y(); 2352 y = wid->geometry().y();
2353 w = wid->width(); 2353 w = wid->width();
2354 h = wid->height(); 2354 h = wid->height();
2355 list.clear(); 2355 list.clear();
2356 list << QString::number( x ); 2356 list << QString::number( x );
2357 list << QString::number( y ); 2357 list << QString::number( y );
2358 list << QString::number( w ); 2358 list << QString::number( w );
2359 list << QString::number( h ); 2359 list << QString::number( h );
2360 config->writeEntry("MainLayout",list ); 2360 config->writeEntry("MainLayout",list );
2361 2361
2362 wid = mEventEditor; 2362 wid = mEventEditor;
2363 x = wid->geometry().x(); 2363 x = wid->geometry().x();
2364 y = wid->geometry().y(); 2364 y = wid->geometry().y();
2365 w = wid->width(); 2365 w = wid->width();
2366 h = wid->height(); 2366 h = wid->height();
2367 list.clear(); 2367 list.clear();
2368 list << QString::number( x ); 2368 list << QString::number( x );
2369 list << QString::number( y ); 2369 list << QString::number( y );
2370 list << QString::number( w ); 2370 list << QString::number( w );
2371 list << QString::number( h ); 2371 list << QString::number( h );
2372 config->writeEntry("EditEventLayout",list ); 2372 config->writeEntry("EditEventLayout",list );
2373 2373
2374 wid = mTodoEditor; 2374 wid = mTodoEditor;
2375 x = wid->geometry().x(); 2375 x = wid->geometry().x();
2376 y = wid->geometry().y(); 2376 y = wid->geometry().y();
2377 w = wid->width(); 2377 w = wid->width();
2378 h = wid->height(); 2378 h = wid->height();
2379 list.clear(); 2379 list.clear();
2380 list << QString::number( x ); 2380 list << QString::number( x );
2381 list << QString::number( y ); 2381 list << QString::number( y );
2382 list << QString::number( w ); 2382 list << QString::number( w );
2383 list << QString::number( h ); 2383 list << QString::number( h );
2384 config->writeEntry("EditTodoLayout",list ); 2384 config->writeEntry("EditTodoLayout",list );
2385 wid = getEventViewerDialog(); 2385 wid = getEventViewerDialog();
2386 x = wid->geometry().x(); 2386 x = wid->geometry().x();
2387 y = wid->geometry().y(); 2387 y = wid->geometry().y();
2388 w = wid->width(); 2388 w = wid->width();
2389 h = wid->height(); 2389 h = wid->height();
2390 list.clear(); 2390 list.clear();
2391 list << QString::number( x ); 2391 list << QString::number( x );
2392 list << QString::number( y ); 2392 list << QString::number( y );
2393 list << QString::number( w ); 2393 list << QString::number( w );
2394 list << QString::number( h ); 2394 list << QString::number( h );
2395 config->writeEntry("ViewerLayout",list ); 2395 config->writeEntry("ViewerLayout",list );
2396 wid = mDialogManager->getSearchDialog(); 2396 wid = mDialogManager->getSearchDialog();
2397 if ( wid ) { 2397 if ( wid ) {
2398 x = wid->geometry().x(); 2398 x = wid->geometry().x();
2399 y = wid->geometry().y(); 2399 y = wid->geometry().y();
2400 w = wid->width(); 2400 w = wid->width();
2401 h = wid->height(); 2401 h = wid->height();
2402 list.clear(); 2402 list.clear();
2403 list << QString::number( x ); 2403 list << QString::number( x );
2404 list << QString::number( y ); 2404 list << QString::number( y );
2405 list << QString::number( w ); 2405 list << QString::number( w );
2406 list << QString::number( h ); 2406 list << QString::number( h );
2407 config->writeEntry("SearchLayout",list ); 2407 config->writeEntry("SearchLayout",list );
2408 } 2408 }
2409#endif 2409#endif
2410 2410
2411 2411
2412 config->sync(); 2412 config->sync();
2413} 2413}
2414 2414
2415void CalendarView::readFilterSettings(KConfig *config) 2415void CalendarView::readFilterSettings(KConfig *config)
2416{ 2416{
2417 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2417 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2418 2418
2419 mFilters.clear(); 2419 mFilters.clear();
2420 2420
2421 config->setGroup("General"); 2421 config->setGroup("General");
2422 QStringList filterList = config->readListEntry("CalendarFilters"); 2422 QStringList filterList = config->readListEntry("CalendarFilters");
2423 2423
2424 QStringList::ConstIterator it = filterList.begin(); 2424 QStringList::ConstIterator it = filterList.begin();
2425 QStringList::ConstIterator end = filterList.end(); 2425 QStringList::ConstIterator end = filterList.end();
2426 while(it != end) { 2426 while(it != end) {
2427 // kdDebug() << " filter: " << (*it) << endl; 2427 // kdDebug() << " filter: " << (*it) << endl;
2428 2428
2429 CalFilter *filter; 2429 CalFilter *filter;
2430 filter = new CalFilter(*it); 2430 filter = new CalFilter(*it);
2431 config->setGroup("Filter_" + (*it).utf8()); 2431 config->setGroup("Filter_" + (*it).utf8());
2432 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2432 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2433 filter->setCriteria(config->readNumEntry("Criteria",0)); 2433 filter->setCriteria(config->readNumEntry("Criteria",0));
2434 filter->setCategoryList(config->readListEntry("CategoryList")); 2434 filter->setCategoryList(config->readListEntry("CategoryList"));
2435 mFilters.append(filter); 2435 mFilters.append(filter);
2436 2436
2437 ++it; 2437 ++it;
2438 } 2438 }
2439 2439
2440 if (mFilters.count() == 0) { 2440 if (mFilters.count() == 0) {
2441 CalFilter *filter = new CalFilter(i18n("Default")); 2441 CalFilter *filter = new CalFilter(i18n("Default"));
2442 mFilters.append(filter); 2442 mFilters.append(filter);
2443 } 2443 }
2444 mFilterView->updateFilters(); 2444 mFilterView->updateFilters();
2445 config->setGroup("FilterView"); 2445 config->setGroup("FilterView");
2446 2446
2447 mFilterView->blockSignals(true); 2447 mFilterView->blockSignals(true);
2448 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2448 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2449 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2449 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2450 mFilterView->blockSignals(false); 2450 mFilterView->blockSignals(false);
2451 // We do it manually to avoid it being done twice by the above calls 2451 // We do it manually to avoid it being done twice by the above calls
2452 updateFilter(); 2452 updateFilter();
2453} 2453}
2454 2454
2455void CalendarView::writeFilterSettings(KConfig *config) 2455void CalendarView::writeFilterSettings(KConfig *config)
2456{ 2456{
2457 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2457 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2458 2458
2459 QStringList filterList; 2459 QStringList filterList;
2460 2460
2461 CalFilter *filter = mFilters.first(); 2461 CalFilter *filter = mFilters.first();
2462 while(filter) { 2462 while(filter) {
2463 // kdDebug() << " fn: " << filter->name() << endl; 2463 // kdDebug() << " fn: " << filter->name() << endl;
2464 filterList << filter->name(); 2464 filterList << filter->name();
2465 config->setGroup("Filter_" + filter->name().utf8()); 2465 config->setGroup("Filter_" + filter->name().utf8());
2466 config->writeEntry("Criteria",filter->criteria()); 2466 config->writeEntry("Criteria",filter->criteria());
2467 config->writeEntry("CategoryList",filter->categoryList()); 2467 config->writeEntry("CategoryList",filter->categoryList());
2468 filter = mFilters.next(); 2468 filter = mFilters.next();
2469 } 2469 }
2470 config->setGroup("General"); 2470 config->setGroup("General");
2471 config->writeEntry("CalendarFilters",filterList); 2471 config->writeEntry("CalendarFilters",filterList);
2472 2472
2473 config->setGroup("FilterView"); 2473 config->setGroup("FilterView");
2474 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2474 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2475 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2475 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2476} 2476}
2477 2477
2478 2478
2479void CalendarView::goToday() 2479void CalendarView::goToday()
2480{ 2480{
2481 if ( mViewManager->currentView()->isMonthView() ) 2481 if ( mViewManager->currentView()->isMonthView() )
2482 mNavigator->selectTodayMonth(); 2482 mNavigator->selectTodayMonth();
2483 else 2483 else
2484 mNavigator->selectToday(); 2484 mNavigator->selectToday();
2485} 2485}
2486 2486
2487void CalendarView::goNext() 2487void CalendarView::goNext()
2488{ 2488{
2489 mNavigator->selectNext(); 2489 mNavigator->selectNext();
2490} 2490}
2491 2491
2492void CalendarView::goPrevious() 2492void CalendarView::goPrevious()
2493{ 2493{
2494 mNavigator->selectPrevious(); 2494 mNavigator->selectPrevious();
2495} 2495}
2496void CalendarView::goNextMonth() 2496void CalendarView::goNextMonth()
2497{ 2497{
2498 mNavigator->selectNextMonth(); 2498 mNavigator->selectNextMonth();
2499} 2499}
2500 2500
2501void CalendarView::goPreviousMonth() 2501void CalendarView::goPreviousMonth()
2502{ 2502{
2503 mNavigator->selectPreviousMonth(); 2503 mNavigator->selectPreviousMonth();
2504} 2504}
2505 2505
2506void CalendarView::updateConfig() 2506void CalendarView::updateConfig()
2507{ 2507{
2508 if ( KOPrefs::instance()->mUseAppColors ) 2508 if ( KOPrefs::instance()->mUseAppColors )
2509 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2509 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2510 emit configChanged(); 2510 emit configChanged();
2511 mTodoList->updateConfig(); 2511 mTodoList->updateConfig();
2512 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2512 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2513 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2513 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2514 // To make the "fill window" configurations work 2514 // To make the "fill window" configurations work
2515 //mViewManager->raiseCurrentView(); 2515 //mViewManager->raiseCurrentView();
2516} 2516}
2517 2517
2518 2518
2519void CalendarView::eventChanged(Event *event) 2519void CalendarView::eventChanged(Event *event)
2520{ 2520{
2521 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2521 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2522 //updateUnmanagedViews(); 2522 //updateUnmanagedViews();
2523} 2523}
2524 2524
2525void CalendarView::eventAdded(Event *event) 2525void CalendarView::eventAdded(Event *event)
2526{ 2526{
2527 changeEventDisplay(event,KOGlobals::EVENTADDED); 2527 changeEventDisplay(event,KOGlobals::EVENTADDED);
2528} 2528}
2529 2529
2530void CalendarView::eventToBeDeleted(Event *) 2530void CalendarView::eventToBeDeleted(Event *)
2531{ 2531{
2532 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2532 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2533} 2533}
2534 2534
2535void CalendarView::eventDeleted() 2535void CalendarView::eventDeleted()
2536{ 2536{
2537 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2537 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2538} 2538}
2539void CalendarView::changeTodoDisplay(Todo *which, int action) 2539void CalendarView::changeTodoDisplay(Todo *which, int action)
2540{ 2540{
2541 changeIncidenceDisplay((Incidence *)which, action); 2541 changeIncidenceDisplay((Incidence *)which, action);
2542 mDateNavigator->updateView(); //LR 2542 mDateNavigator->updateView(); //LR
2543 //mDialogManager->updateSearchDialog(); 2543 //mDialogManager->updateSearchDialog();
2544 2544
2545 if (which) { 2545 if (which) {
2546 mViewManager->updateWNview(); 2546 mViewManager->updateWNview();
2547 //mTodoList->updateView(); 2547 //mTodoList->updateView();
2548 } 2548 }
2549 2549
2550} 2550}
2551 2551
2552void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2552void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2553{ 2553{
2554 updateUnmanagedViews(); 2554 updateUnmanagedViews();
2555 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2555 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2556 if ( action == KOGlobals::EVENTDELETED ) { //delete 2556 if ( action == KOGlobals::EVENTDELETED ) { //delete
2557 mCalendar->checkAlarmForIncidence( 0, true ); 2557 mCalendar->checkAlarmForIncidence( 0, true );
2558 if ( mEventViewerDialog ) 2558 if ( mEventViewerDialog )
2559 mEventViewerDialog->hide(); 2559 mEventViewerDialog->hide();
2560 } 2560 }
2561 else 2561 else
2562 mCalendar->checkAlarmForIncidence( which , false ); 2562 mCalendar->checkAlarmForIncidence( which , false );
2563} 2563}
2564 2564
2565// most of the changeEventDisplays() right now just call the view's 2565// most of the changeEventDisplays() right now just call the view's
2566// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2566// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2567void CalendarView::changeEventDisplay(Event *which, int action) 2567void CalendarView::changeEventDisplay(Event *which, int action)
2568{ 2568{
2569 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2569 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2570 changeIncidenceDisplay((Incidence *)which, action); 2570 changeIncidenceDisplay((Incidence *)which, action);
2571 mDateNavigator->updateView(); 2571 mDateNavigator->updateView();
2572 //mDialogManager->updateSearchDialog(); 2572 //mDialogManager->updateSearchDialog();
2573 2573
2574 if (which) { 2574 if (which) {
2575 // If there is an event view visible update the display 2575 // If there is an event view visible update the display
2576 mViewManager->currentView()->changeEventDisplay(which,action); 2576 mViewManager->currentView()->changeEventDisplay(which,action);
2577 // TODO: check, if update needed 2577 // TODO: check, if update needed
2578 // if (which->getTodoStatus()) { 2578 // if (which->getTodoStatus()) {
2579 mTodoList->updateView(); 2579 mTodoList->updateView();
2580 // } 2580 // }
2581 } else { 2581 } else {
2582 mViewManager->currentView()->updateView(); 2582 mViewManager->currentView()->updateView();
2583 } 2583 }
2584} 2584}
2585 2585
2586 2586
2587void CalendarView::updateTodoViews() 2587void CalendarView::updateTodoViews()
2588{ 2588{
2589 mTodoList->updateView(); 2589 mTodoList->updateView();
2590 mViewManager->currentView()->updateView(); 2590 mViewManager->currentView()->updateView();
2591 2591
2592} 2592}
2593 2593
2594 2594
2595void CalendarView::updateView(const QDate &start, const QDate &end) 2595void CalendarView::updateView(const QDate &start, const QDate &end)
2596{ 2596{
2597#ifdef DESKTOP_VERSION 2597#ifdef DESKTOP_VERSION
2598 mDateScrollBar->blockSignals( true );
2598 mDateScrollBar->setValue( start.dayOfYear()-1); 2599 mDateScrollBar->setValue( start.dayOfYear()-1);
2600 mDateScrollBar->blockSignals( false );
2599#endif 2601#endif
2600 mTodoList->updateView(); 2602 mTodoList->updateView();
2601 mViewManager->updateView(start, end); 2603 mViewManager->updateView(start, end);
2602 //mDateNavigator->updateView(); 2604 //mDateNavigator->updateView();
2603} 2605}
2604 2606
2605void CalendarView::clearAllViews() 2607void CalendarView::clearAllViews()
2606{ 2608{
2607 mTodoList->clearList(); 2609 mTodoList->clearList();
2608 mViewManager->clearAllViews(); 2610 mViewManager->clearAllViews();
2609 SearchDialog * sd = mDialogManager->getSearchDialog(); 2611 SearchDialog * sd = mDialogManager->getSearchDialog();
2610 if ( sd ) { 2612 if ( sd ) {
2611 KOListView* kol = sd->listview(); 2613 KOListView* kol = sd->listview();
2612 if ( kol ) 2614 if ( kol )
2613 kol->clearList(); 2615 kol->clearList();
2614 } 2616 }
2615} 2617}
2616void CalendarView::updateView() 2618void CalendarView::updateView()
2617{ 2619{
2618 DateList tmpList = mNavigator->selectedDates(); 2620 DateList tmpList = mNavigator->selectedDates();
2619 2621
2620 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2622 if ( KOPrefs::instance()->mHideNonStartedTodos )
2621 mTodoList->updateView(); 2623 mTodoList->updateView();
2622 // We assume that the navigator only selects consecutive days. 2624 // We assume that the navigator only selects consecutive days.
2623 updateView( tmpList.first(), tmpList.last() ); 2625 updateView( tmpList.first(), tmpList.last() );
2624} 2626}
2625 2627
2626void CalendarView::updateUnmanagedViews() 2628void CalendarView::updateUnmanagedViews()
2627{ 2629{
2628 mDateNavigator->updateDayMatrix(); 2630 mDateNavigator->updateDayMatrix();
2629} 2631}
2630 2632
2631int CalendarView::msgItemDelete(const QString name) 2633int CalendarView::msgItemDelete(const QString name)
2632{ 2634{
2633 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2635 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2634 i18n("This item will be\npermanently deleted."), 2636 i18n("This item will be\npermanently deleted."),
2635 i18n("KO/Pi Confirmation"),i18n("Delete")); 2637 i18n("KO/Pi Confirmation"),i18n("Delete"));
2636} 2638}
2637 2639
2638 2640
2639void CalendarView::edit_cut() 2641void CalendarView::edit_cut()
2640{ 2642{
2641 Event *anEvent=0; 2643 Event *anEvent=0;
2642 2644
2643 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2645 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2644 2646
2645 if (mViewManager->currentView()->isEventView()) { 2647 if (mViewManager->currentView()->isEventView()) {
2646 if ( incidence && incidence->typeID() == eventID ) { 2648 if ( incidence && incidence->typeID() == eventID ) {
2647 anEvent = static_cast<Event *>(incidence); 2649 anEvent = static_cast<Event *>(incidence);
2648 } 2650 }
2649 } 2651 }
2650 2652
2651 if (!anEvent) { 2653 if (!anEvent) {
2652 KNotifyClient::beep(); 2654 KNotifyClient::beep();
2653 return; 2655 return;
2654 } 2656 }
2655 DndFactory factory( mCalendar ); 2657 DndFactory factory( mCalendar );
2656 factory.cutIncidence(anEvent); 2658 factory.cutIncidence(anEvent);
2657 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2659 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2658} 2660}
2659 2661
2660void CalendarView::edit_copy() 2662void CalendarView::edit_copy()
2661{ 2663{
2662 Event *anEvent=0; 2664 Event *anEvent=0;
2663 2665
2664 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2666 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2665 2667
2666 if (mViewManager->currentView()->isEventView()) { 2668 if (mViewManager->currentView()->isEventView()) {
2667 if ( incidence && incidence->typeID() == eventID ) { 2669 if ( incidence && incidence->typeID() == eventID ) {
2668 anEvent = static_cast<Event *>(incidence); 2670 anEvent = static_cast<Event *>(incidence);
2669 } 2671 }
2670 } 2672 }
2671 2673
2672 if (!anEvent) { 2674 if (!anEvent) {
2673 KNotifyClient::beep(); 2675 KNotifyClient::beep();
2674 return; 2676 return;
2675 } 2677 }
2676 DndFactory factory( mCalendar ); 2678 DndFactory factory( mCalendar );
2677 factory.copyIncidence(anEvent); 2679 factory.copyIncidence(anEvent);
2678} 2680}
2679 2681
2680void CalendarView::edit_paste() 2682void CalendarView::edit_paste()
2681{ 2683{
2682 QDate date = mNavigator->selectedDates().first(); 2684 QDate date = mNavigator->selectedDates().first();
2683 2685
2684 DndFactory factory( mCalendar ); 2686 DndFactory factory( mCalendar );
2685 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2687 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2686 2688
2687 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2689 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2688} 2690}
2689void CalendarView::edit_global_options() 2691void CalendarView::edit_global_options()
2690{ 2692{
2691 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2693 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2692 emit save(); 2694 emit save();
2693 emit saveStopTimer(); 2695 emit saveStopTimer();
2694 mDialogManager->showGlobalOptionsDialog(); 2696 mDialogManager->showGlobalOptionsDialog();
2695 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2697 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2696 emit saveStopTimer(); 2698 emit saveStopTimer();
2697 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2699 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2698 i18n("Timezone settings"),i18n("Reload"))) { 2700 i18n("Timezone settings"),i18n("Reload"))) {
2699 qDebug("KO: TZ reload cancelled "); 2701 qDebug("KO: TZ reload cancelled ");
2700 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2702 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2701 return; 2703 return;
2702 } 2704 }
2703 qDebug("KO: Timezone change "); 2705 qDebug("KO: Timezone change ");
2704 loadCalendars(); 2706 loadCalendars();
2705 setModified(true); 2707 setModified(true);
2706 } 2708 }
2707 else 2709 else
2708 qDebug("KO: No tz change "); 2710 qDebug("KO: No tz change ");
2709} 2711}
2710void CalendarView::edit_options() 2712void CalendarView::edit_options()
2711{ 2713{
2712 mDialogManager->showOptionsDialog(); 2714 mDialogManager->showOptionsDialog();
2713} 2715}
2714 2716
2715 2717
2716void CalendarView::slotSelectPickerDate( QDate d) 2718void CalendarView::slotSelectPickerDate( QDate d)
2717{ 2719{
2718 mDateFrame->hide(); 2720 mDateFrame->hide();
2719 if ( mDatePickerMode == 1 ) { 2721 if ( mDatePickerMode == 1 ) {
2720 mNavigator->slotDaySelect( d ); 2722 mNavigator->slotDaySelect( d );
2721 } else if ( mDatePickerMode == 2 ) { 2723 } else if ( mDatePickerMode == 2 ) {
2722 if ( mMoveIncidence->typeID() == todoID ) { 2724 if ( mMoveIncidence->typeID() == todoID ) {
2723 Todo * to = (Todo *) mMoveIncidence; 2725 Todo * to = (Todo *) mMoveIncidence;
2724 QTime tim; 2726 QTime tim;
2725 int len = 0; 2727 int len = 0;
2726 if ( to->hasStartDate() && to->hasDueDate() ) 2728 if ( to->hasStartDate() && to->hasDueDate() )
2727 len = to->dtStart().secsTo( to->dtDue()); 2729 len = to->dtStart().secsTo( to->dtDue());
2728 if ( to->hasDueDate() ) 2730 if ( to->hasDueDate() )
2729 tim = to->dtDue().time(); 2731 tim = to->dtDue().time();
2730 else { 2732 else {
2731 tim = QTime ( 0,0,0 ); 2733 tim = QTime ( 0,0,0 );
2732 to->setFloats( true ); 2734 to->setFloats( true );
2733 to->setHasDueDate( true ); 2735 to->setHasDueDate( true );
2734 } 2736 }
2735 QDateTime dt ( d,tim ); 2737 QDateTime dt ( d,tim );
2736 to->setDtDue( dt ); 2738 to->setDtDue( dt );
2737 2739
2738 if ( to->hasStartDate() ) { 2740 if ( to->hasStartDate() ) {
2739 if ( len>0 ) 2741 if ( len>0 )
2740 to->setDtStart(to->dtDue().addSecs( -len )); 2742 to->setDtStart(to->dtDue().addSecs( -len ));
2741 else 2743 else
2742 if (to->dtStart() > to->dtDue() ) 2744 if (to->dtStart() > to->dtDue() )
2743 to->setDtStart(to->dtDue().addDays( -3 )); 2745 to->setDtStart(to->dtDue().addDays( -3 ));
2744 } 2746 }
2745 2747
2746 todoChanged( to ); 2748 todoChanged( to );
2747 } else { 2749 } else {
2748 if ( mMoveIncidence->doesRecur() ) { 2750 if ( mMoveIncidence->doesRecur() ) {
2749#if 0 2751#if 0
2750 // PENDING implement this 2752 // PENDING implement this
2751 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2753 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2752 mCalendar()->addIncidence( newInc ); 2754 mCalendar()->addIncidence( newInc );
2753 if ( mMoveIncidence->typeID() == todoID ) 2755 if ( mMoveIncidence->typeID() == todoID )
2754 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2756 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2755 else 2757 else
2756 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2758 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2757 mMoveIncidence = newInc; 2759 mMoveIncidence = newInc;
2758 2760
2759#endif 2761#endif
2760 } 2762 }
2761 QTime tim = mMoveIncidence->dtStart().time(); 2763 QTime tim = mMoveIncidence->dtStart().time();
2762 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2764 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2763 QDateTime dt ( d,tim ); 2765 QDateTime dt ( d,tim );
2764 mMoveIncidence->setDtStart( dt ); 2766 mMoveIncidence->setDtStart( dt );
2765 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2767 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2766 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2768 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2767 } 2769 }
2768 2770
2769 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2771 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2770 } 2772 }
2771} 2773}
2772 2774
2773void CalendarView::removeCategories() 2775void CalendarView::removeCategories()
2774{ 2776{
2775 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2777 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2776 QStringList catList = KOPrefs::instance()->mCustomCategories; 2778 QStringList catList = KOPrefs::instance()->mCustomCategories;
2777 QStringList catIncList; 2779 QStringList catIncList;
2778 QStringList newCatList; 2780 QStringList newCatList;
2779 Incidence* inc = incList.first(); 2781 Incidence* inc = incList.first();
2780 int i; 2782 int i;
2781 int count = 0; 2783 int count = 0;
2782 while ( inc ) { 2784 while ( inc ) {
2783 newCatList.clear(); 2785 newCatList.clear();
2784 catIncList = inc->categories() ; 2786 catIncList = inc->categories() ;
2785 for( i = 0; i< catIncList.count(); ++i ) { 2787 for( i = 0; i< catIncList.count(); ++i ) {
2786 if ( catList.contains (catIncList[i])) 2788 if ( catList.contains (catIncList[i]))
2787 newCatList.append( catIncList[i] ); 2789 newCatList.append( catIncList[i] );
2788 } 2790 }
2789 newCatList.sort(); 2791 newCatList.sort();
2790 inc->setCategories( newCatList.join(",") ); 2792 inc->setCategories( newCatList.join(",") );
2791 inc = incList.next(); 2793 inc = incList.next();
2792 } 2794 }
2793} 2795}
2794 2796
2795int CalendarView::addCategories() 2797int CalendarView::addCategories()
2796{ 2798{
2797 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2799 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2798 QStringList catList = KOPrefs::instance()->mCustomCategories; 2800 QStringList catList = KOPrefs::instance()->mCustomCategories;
2799 QStringList catIncList; 2801 QStringList catIncList;
2800 Incidence* inc = incList.first(); 2802 Incidence* inc = incList.first();
2801 int i; 2803 int i;
2802 int count = 0; 2804 int count = 0;
2803 while ( inc ) { 2805 while ( inc ) {
2804 catIncList = inc->categories() ; 2806 catIncList = inc->categories() ;
2805 for( i = 0; i< catIncList.count(); ++i ) { 2807 for( i = 0; i< catIncList.count(); ++i ) {
2806 if ( !catList.contains (catIncList[i])) { 2808 if ( !catList.contains (catIncList[i])) {
2807 catList.append( catIncList[i] ); 2809 catList.append( catIncList[i] );
2808 //qDebug("add cat %s ", catIncList[i].latin1()); 2810 //qDebug("add cat %s ", catIncList[i].latin1());
2809 ++count; 2811 ++count;
2810 } 2812 }
2811 } 2813 }
2812 inc = incList.next(); 2814 inc = incList.next();
2813 } 2815 }
2814 catList.sort(); 2816 catList.sort();
2815 KOPrefs::instance()->mCustomCategories = catList; 2817 KOPrefs::instance()->mCustomCategories = catList;
2816 return count; 2818 return count;
2817} 2819}
2818 2820
2819void CalendarView::manageCategories() 2821void CalendarView::manageCategories()
2820{ 2822{
2821 KOCatPrefs* cp = new KOCatPrefs(); 2823 KOCatPrefs* cp = new KOCatPrefs();
2822 cp->show(); 2824 cp->show();
2823 int w =cp->sizeHint().width() ; 2825 int w =cp->sizeHint().width() ;
2824 int h = cp->sizeHint().height() ; 2826 int h = cp->sizeHint().height() ;
2825 int dw = QApplication::desktop()->width(); 2827 int dw = QApplication::desktop()->width();
2826 int dh = QApplication::desktop()->height(); 2828 int dh = QApplication::desktop()->height();
2827 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2829 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2828 if ( !cp->exec() ) { 2830 if ( !cp->exec() ) {
2829 delete cp; 2831 delete cp;
2830 return; 2832 return;
2831 } 2833 }
2832 int count = 0; 2834 int count = 0;
2833 if ( cp->addCat() ) { 2835 if ( cp->addCat() ) {
2834 count = addCategories(); 2836 count = addCategories();
2835 if ( count ) { 2837 if ( count ) {
2836 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2838 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2837 writeSettings(); 2839 writeSettings();
2838 } else 2840 } else
2839 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2841 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2840 } else { 2842 } else {
2841 removeCategories(); 2843 removeCategories();
2842 updateView(); 2844 updateView();
2843 } 2845 }
2844 delete cp; 2846 delete cp;
2845} 2847}
2846 2848
2847void CalendarView::beamIncidence(Incidence * Inc) 2849void CalendarView::beamIncidence(Incidence * Inc)
2848{ 2850{
2849 QPtrList<Incidence> delSel ; 2851 QPtrList<Incidence> delSel ;
2850 delSel.append(Inc); 2852 delSel.append(Inc);
2851 beamIncidenceList( delSel ); 2853 beamIncidenceList( delSel );
2852} 2854}
2853void CalendarView::beamCalendar() 2855void CalendarView::beamCalendar()
2854{ 2856{
2855 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2857 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2856 //qDebug("beamCalendar() "); 2858 //qDebug("beamCalendar() ");
2857 beamIncidenceList( delSel ); 2859 beamIncidenceList( delSel );
2858} 2860}
2859void CalendarView::beamFilteredCalendar() 2861void CalendarView::beamFilteredCalendar()
2860{ 2862{
2861 QPtrList<Incidence> delSel = mCalendar->incidences(); 2863 QPtrList<Incidence> delSel = mCalendar->incidences();
2862 //qDebug("beamFilteredCalendar() "); 2864 //qDebug("beamFilteredCalendar() ");
2863 beamIncidenceList( delSel ); 2865 beamIncidenceList( delSel );
2864} 2866}
2865void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2867void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2866{ 2868{
2867 2869
2868 KOBeamPrefs beamDialog; 2870 KOBeamPrefs beamDialog;
2869 if ( beamDialog.exec () == QDialog::Rejected ) 2871 if ( beamDialog.exec () == QDialog::Rejected )
2870 return; 2872 return;
2871#ifdef DESKTOP_VERSION 2873#ifdef DESKTOP_VERSION
2872 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2874 QString fn = locateLocal( "tmp", "kopibeamfile" );
2873#else 2875#else
2874 QString fn = "/tmp/kopibeamfile"; 2876 QString fn = "/tmp/kopibeamfile";
2875#endif 2877#endif
2876 QString mes; 2878 QString mes;
2877 bool createbup = true; 2879 bool createbup = true;
2878 if ( createbup ) { 2880 if ( createbup ) {
2879 QString description = "\n"; 2881 QString description = "\n";
2880 CalendarLocal* cal = new CalendarLocal(); 2882 CalendarLocal* cal = new CalendarLocal();
2881 if ( beamDialog.beamLocal() ) 2883 if ( beamDialog.beamLocal() )
2882 cal->setLocalTime(); 2884 cal->setLocalTime();
2883 else 2885 else
2884 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2886 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2885 Incidence *incidence = delSel.first(); 2887 Incidence *incidence = delSel.first();
2886 bool addText = false; 2888 bool addText = false;
2887 if ( delSel.count() < 10 ) 2889 if ( delSel.count() < 10 )
2888 addText = true; 2890 addText = true;
2889 else { 2891 else {
2890 description.sprintf(i18n(" %d items?"),delSel.count() ); 2892 description.sprintf(i18n(" %d items?"),delSel.count() );
2891 } 2893 }
2892 while ( incidence ) { 2894 while ( incidence ) {
2893 Incidence *in = incidence->clone(); 2895 Incidence *in = incidence->clone();
2894 if ( ! in->summary().isEmpty() ) { 2896 if ( ! in->summary().isEmpty() ) {
2895 in->setDescription(""); 2897 in->setDescription("");
2896 } else { 2898 } else {
2897 in->setSummary( in->description().left(20)); 2899 in->setSummary( in->description().left(20));
2898 in->setDescription(""); 2900 in->setDescription("");
2899 } 2901 }
2900 if ( addText ) 2902 if ( addText )
2901 description += in->summary() + "\n"; 2903 description += in->summary() + "\n";
2902 cal->addIncidence( in ); 2904 cal->addIncidence( in );
2903 incidence = delSel.next(); 2905 incidence = delSel.next();
2904 } 2906 }
2905 if ( beamDialog.beamVcal() ) { 2907 if ( beamDialog.beamVcal() ) {
2906 fn += ".vcs"; 2908 fn += ".vcs";
2907 FileStorage storage( cal, fn, new VCalFormat ); 2909 FileStorage storage( cal, fn, new VCalFormat );
2908 storage.save(); 2910 storage.save();
2909 } else { 2911 } else {
2910 fn += ".ics"; 2912 fn += ".ics";
2911 FileStorage storage( cal, fn, new ICalFormat( ) ); 2913 FileStorage storage( cal, fn, new ICalFormat( ) );
2912 storage.save(); 2914 storage.save();
2913 } 2915 }
2914 delete cal; 2916 delete cal;
2915 mes = i18n("KO/Pi: Ready for beaming"); 2917 mes = i18n("KO/Pi: Ready for beaming");
2916 topLevelWidget()->setCaption(mes); 2918 topLevelWidget()->setCaption(mes);
2917 KApplication::convert2latin1( fn ); 2919 KApplication::convert2latin1( fn );
2918#ifndef DESKTOP_VERSION 2920#ifndef DESKTOP_VERSION
2919 Ir *ir = new Ir( this ); 2921 Ir *ir = new Ir( this );
2920 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2922 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2921 ir->send( fn, description, "text/x-vCalendar" ); 2923 ir->send( fn, description, "text/x-vCalendar" );
2922#endif 2924#endif
2923 } 2925 }
2924} 2926}
2925void CalendarView::beamDone( Ir *ir ) 2927void CalendarView::beamDone( Ir *ir )
2926{ 2928{
2927#ifndef DESKTOP_VERSION 2929#ifndef DESKTOP_VERSION
2928 delete ir; 2930 delete ir;
2929#endif 2931#endif
2930 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2932 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2931 topLevelWidget()->raise(); 2933 topLevelWidget()->raise();
2932} 2934}
2933 2935
2934void CalendarView::moveIncidence(Incidence * inc ) 2936void CalendarView::moveIncidence(Incidence * inc )
2935{ 2937{
2936 if ( !inc ) return; 2938 if ( !inc ) return;
2937 showDatePickerPopup(); 2939 showDatePickerPopup();
2938 mDatePickerMode = 2; 2940 mDatePickerMode = 2;
2939 mMoveIncidence = inc ; 2941 mMoveIncidence = inc ;
2940 QDate da; 2942 QDate da;
2941 if ( mMoveIncidence->typeID() == todoID ) { 2943 if ( mMoveIncidence->typeID() == todoID ) {
2942 Todo * to = (Todo *) mMoveIncidence; 2944 Todo * to = (Todo *) mMoveIncidence;
2943 if ( to->hasDueDate() ) 2945 if ( to->hasDueDate() )
2944 da = to->dtDue().date(); 2946 da = to->dtDue().date();
2945 else 2947 else
2946 da = QDate::currentDate(); 2948 da = QDate::currentDate();
2947 } else { 2949 } else {
2948 da = mMoveIncidence->dtStart().date(); 2950 da = mMoveIncidence->dtStart().date();
2949 } 2951 }
2950 //PENDING set date for recurring incidence to date of recurrence 2952 //PENDING set date for recurring incidence to date of recurrence
2951 //mMoveIncidenceOldDate; 2953 //mMoveIncidenceOldDate;
2952 mDatePicker->setDate( da ); 2954 mDatePicker->setDate( da );
2953} 2955}
2954void CalendarView::showDatePickerPopup() 2956void CalendarView::showDatePickerPopup()
2955{ 2957{
2956 if ( mDateFrame->isVisible() ) 2958 if ( mDateFrame->isVisible() )
2957 mDateFrame->hide(); 2959 mDateFrame->hide();
2958 else { 2960 else {
2959 int offX = 0, offY = 0; 2961 int offX = 0, offY = 0;
2960#ifdef DESKTOP_VERSION 2962#ifdef DESKTOP_VERSION
2961 int w =mDatePicker->sizeHint().width() ; 2963 int w =mDatePicker->sizeHint().width() ;
2962 int h = mDatePicker->sizeHint().height() ; 2964 int h = mDatePicker->sizeHint().height() ;
2963 int dw = topLevelWidget()->width(); 2965 int dw = topLevelWidget()->width();
2964 int dh = topLevelWidget()->height(); 2966 int dh = topLevelWidget()->height();
2965 offX = topLevelWidget()->x(); 2967 offX = topLevelWidget()->x();
2966 offY = topLevelWidget()->y(); 2968 offY = topLevelWidget()->y();
2967#else 2969#else
2968 int w =mDatePicker->sizeHint().width() ; 2970 int w =mDatePicker->sizeHint().width() ;
2969 int h = mDatePicker->sizeHint().height() ; 2971 int h = mDatePicker->sizeHint().height() ;
2970 int dw = QApplication::desktop()->width(); 2972 int dw = QApplication::desktop()->width();
2971 int dh = QApplication::desktop()->height(); 2973 int dh = QApplication::desktop()->height();
2972#endif 2974#endif
2973 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 2975 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
2974 mDateFrame->show(); 2976 mDateFrame->show();
2975 } 2977 }
2976} 2978}
2977void CalendarView::showDatePicker( ) 2979void CalendarView::showDatePicker( )
2978{ 2980{
2979 showDatePickerPopup(); 2981 showDatePickerPopup();
2980 mDatePickerMode = 1; 2982 mDatePickerMode = 1;
2981 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2983 mDatePicker->setDate( mNavigator->selectedDates().first() );
2982} 2984}
2983 2985
2984void CalendarView::showEventEditor() 2986void CalendarView::showEventEditor()
2985{ 2987{
2986#ifdef DESKTOP_VERSION 2988#ifdef DESKTOP_VERSION
2987 int x,y,w,h; 2989 int x,y,w,h;
2988 x = mEventEditor->geometry().x(); 2990 x = mEventEditor->geometry().x();
2989 y = mEventEditor->geometry().y(); 2991 y = mEventEditor->geometry().y();
2990 w = mEventEditor->width(); 2992 w = mEventEditor->width();
2991 h = mEventEditor->height(); 2993 h = mEventEditor->height();
2992 mEventEditor->show(); 2994 mEventEditor->show();
2993 mEventEditor->setGeometry(x,y,w,h); 2995 mEventEditor->setGeometry(x,y,w,h);
2994#else 2996#else
2995 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2997 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2996 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2998 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2997 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2999 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2998 qApp->processEvents(); 3000 qApp->processEvents();
2999 delete mEventEditor; 3001 delete mEventEditor;
3000 mEventEditor = mDialogManager->getEventEditor(); 3002 mEventEditor = mDialogManager->getEventEditor();
3001 topLevelWidget()->setCaption( i18n("") ); 3003 topLevelWidget()->setCaption( i18n("") );
3002 } 3004 }
3003 mEventEditor->showMaximized(); 3005 mEventEditor->showMaximized();
3004#endif 3006#endif
3005} 3007}
3006void CalendarView::showTodoEditor() 3008void CalendarView::showTodoEditor()
3007{ 3009{
3008#ifdef DESKTOP_VERSION 3010#ifdef DESKTOP_VERSION
3009 int x,y,w,h; 3011 int x,y,w,h;
3010 x = mTodoEditor->geometry().x(); 3012 x = mTodoEditor->geometry().x();
3011 y = mTodoEditor->geometry().y(); 3013 y = mTodoEditor->geometry().y();
3012 w = mTodoEditor->width(); 3014 w = mTodoEditor->width();
3013 h = mTodoEditor->height(); 3015 h = mTodoEditor->height();
3014 mTodoEditor->show(); 3016 mTodoEditor->show();
3015 mTodoEditor->setGeometry(x,y,w,h); 3017 mTodoEditor->setGeometry(x,y,w,h);
3016#else 3018#else
3017 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3019 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3018 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3020 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3019 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3021 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3020 qApp->processEvents(); 3022 qApp->processEvents();
3021 delete mTodoEditor; 3023 delete mTodoEditor;
3022 mTodoEditor = mDialogManager->getTodoEditor(); 3024 mTodoEditor = mDialogManager->getTodoEditor();
3023 topLevelWidget()->setCaption( i18n("") ); 3025 topLevelWidget()->setCaption( i18n("") );
3024 } 3026 }
3025 mTodoEditor->showMaximized(); 3027 mTodoEditor->showMaximized();
3026#endif 3028#endif
3027} 3029}
3028 3030
3029void CalendarView::cloneIncidence() 3031void CalendarView::cloneIncidence()
3030{ 3032{
3031 Incidence *incidence = currentSelection(); 3033 Incidence *incidence = currentSelection();
3032 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3034 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3033 if ( incidence ) { 3035 if ( incidence ) {
3034 cloneIncidence(incidence); 3036 cloneIncidence(incidence);
3035 } 3037 }
3036} 3038}
3037void CalendarView::moveIncidence() 3039void CalendarView::moveIncidence()
3038{ 3040{
3039 Incidence *incidence = currentSelection(); 3041 Incidence *incidence = currentSelection();
3040 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3042 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3041 if ( incidence ) { 3043 if ( incidence ) {
3042 moveIncidence(incidence); 3044 moveIncidence(incidence);
3043 } 3045 }
3044} 3046}
3045void CalendarView::beamIncidence() 3047void CalendarView::beamIncidence()
3046{ 3048{
3047 Incidence *incidence = currentSelection(); 3049 Incidence *incidence = currentSelection();
3048 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3050 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3049 if ( incidence ) { 3051 if ( incidence ) {
3050 beamIncidence(incidence); 3052 beamIncidence(incidence);
3051 } 3053 }
3052} 3054}
3053void CalendarView::toggleCancelIncidence() 3055void CalendarView::toggleCancelIncidence()
3054{ 3056{
3055 Incidence *incidence = currentSelection(); 3057 Incidence *incidence = currentSelection();
3056 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3058 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3057 if ( incidence ) { 3059 if ( incidence ) {
3058 cancelIncidence(incidence); 3060 cancelIncidence(incidence);
3059 } 3061 }
3060} 3062}
3061 3063
3062 3064
3063void CalendarView::cancelIncidence(Incidence * inc ) 3065void CalendarView::cancelIncidence(Incidence * inc )
3064{ 3066{
3065 inc->setCancelled( ! inc->cancelled() ); 3067 inc->setCancelled( ! inc->cancelled() );
3066 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3068 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3067 updateView(); 3069 updateView();
3068} 3070}
3069void CalendarView::cloneIncidence(Incidence * orgInc ) 3071void CalendarView::cloneIncidence(Incidence * orgInc )
3070{ 3072{
3071 Incidence * newInc = orgInc->clone(); 3073 Incidence * newInc = orgInc->clone();
3072 newInc->recreate(); 3074 newInc->recreate();
3073 3075
3074 if ( newInc->typeID() == todoID ) { 3076 if ( newInc->typeID() == todoID ) {
3075 Todo* t = (Todo*) newInc; 3077 Todo* t = (Todo*) newInc;
3076 bool cloneSub = false; 3078 bool cloneSub = false;
3077 if ( orgInc->relations().count() ) { 3079 if ( orgInc->relations().count() ) {
3078 int result = KMessageBox::warningYesNoCancel(this, 3080 int result = KMessageBox::warningYesNoCancel(this,
3079 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ), 3081 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ),
3080 i18n("Todo has subtodos"), 3082 i18n("Todo has subtodos"),
3081 i18n("Yes"), 3083 i18n("Yes"),
3082 i18n("No")); 3084 i18n("No"));
3083 3085
3084 if ( result == KMessageBox::Cancel ) { 3086 if ( result == KMessageBox::Cancel ) {
3085 delete t; 3087 delete t;
3086 return; 3088 return;
3087 } 3089 }
3088 if (result == KMessageBox::Yes) cloneSub = true; 3090 if (result == KMessageBox::Yes) cloneSub = true;
3089 } 3091 }
3090 showTodoEditor(); 3092 showTodoEditor();
3091 mTodoEditor->editTodo( t ); 3093 mTodoEditor->editTodo( t );
3092 if ( mTodoEditor->exec() ) { 3094 if ( mTodoEditor->exec() ) {
3093 if ( cloneSub ) { 3095 if ( cloneSub ) {
3094 orgInc->cloneRelations( t ); 3096 orgInc->cloneRelations( t );
3095 mCalendar->addIncidenceBranch( t ); 3097 mCalendar->addIncidenceBranch( t );
3096 updateView(); 3098 updateView();
3097 3099
3098 } else { 3100 } else {
3099 mCalendar->addTodo( t ); 3101 mCalendar->addTodo( t );
3100 updateView(); 3102 updateView();
3101 } 3103 }
3102 } else { 3104 } else {
3103 delete t; 3105 delete t;
3104 } 3106 }
3105 } 3107 }
3106 else { 3108 else {
3107 Event* e = (Event*) newInc; 3109 Event* e = (Event*) newInc;
3108 showEventEditor(); 3110 showEventEditor();
3109 mEventEditor->editEvent( e ); 3111 mEventEditor->editEvent( e );
3110 if ( mEventEditor->exec() ) { 3112 if ( mEventEditor->exec() ) {
3111 mCalendar->addEvent( e ); 3113 mCalendar->addEvent( e );
3112 updateView(); 3114 updateView();
3113 } else { 3115 } else {
3114 delete e; 3116 delete e;
3115 } 3117 }
3116 } 3118 }
3117 setActiveWindow(); 3119 setActiveWindow();
3118} 3120}
3119 3121
3120void CalendarView::newEvent() 3122void CalendarView::newEvent()
3121{ 3123{
3122 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3124 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3123 KOAgendaView *aView = mViewManager->agendaView(); 3125 KOAgendaView *aView = mViewManager->agendaView();
3124 if (aView) { 3126 if (aView) {
3125 if (aView->selectionStart().isValid()) { 3127 if (aView->selectionStart().isValid()) {
3126 if (aView->selectedIsAllDay()) { 3128 if (aView->selectedIsAllDay()) {
3127 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3129 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3128 } else { 3130 } else {
3129 newEvent(aView->selectionStart(),aView->selectionEnd()); 3131 newEvent(aView->selectionStart(),aView->selectionEnd());
3130 } 3132 }
3131 return; 3133 return;
3132 } 3134 }
3133 } 3135 }
3134 3136
3135 QDate date = mNavigator->selectedDates().first(); 3137 QDate date = mNavigator->selectedDates().first();
3136 QDateTime current = QDateTime::currentDateTime(); 3138 QDateTime current = QDateTime::currentDateTime();
3137 if ( date <= current.date() ) { 3139 if ( date <= current.date() ) {
3138 int hour = current.time().hour() +1; 3140 int hour = current.time().hour() +1;
3139 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3141 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3140 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3142 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3141 } else 3143 } else
3142 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3144 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3143 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3145 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3144 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3146 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3145} 3147}
3146 3148
3147void CalendarView::newEvent(QDateTime fh) 3149void CalendarView::newEvent(QDateTime fh)
3148{ 3150{
3149 newEvent(fh, 3151 newEvent(fh,
3150 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3152 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3151} 3153}
3152 3154
3153void CalendarView::newEvent(QDate dt) 3155void CalendarView::newEvent(QDate dt)
3154{ 3156{
3155 newEvent(QDateTime(dt, QTime(0,0,0)), 3157 newEvent(QDateTime(dt, QTime(0,0,0)),
3156 QDateTime(dt, QTime(0,0,0)), true); 3158 QDateTime(dt, QTime(0,0,0)), true);
3157} 3159}
3158void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3160void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3159{ 3161{
3160 newEvent(fromHint, toHint, false); 3162 newEvent(fromHint, toHint, false);
3161} 3163}
3162void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3164void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3163{ 3165{
3164 3166
3165 showEventEditor(); 3167 showEventEditor();
3166 mEventEditor->newEvent(fromHint,toHint,allDay); 3168 mEventEditor->newEvent(fromHint,toHint,allDay);
3167 if ( mFilterView->filtersEnabled() ) { 3169 if ( mFilterView->filtersEnabled() ) {
3168 CalFilter *filter = mFilterView->selectedFilter(); 3170 CalFilter *filter = mFilterView->selectedFilter();
3169 if (filter && filter->showCategories()) { 3171 if (filter && filter->showCategories()) {
3170 mEventEditor->setCategories(filter->categoryList().join(",") ); 3172 mEventEditor->setCategories(filter->categoryList().join(",") );
3171 } 3173 }
3172 if ( filter ) 3174 if ( filter )
3173 mEventEditor->setSecrecy( filter->getSecrecy() ); 3175 mEventEditor->setSecrecy( filter->getSecrecy() );
3174 } 3176 }
3175 mEventEditor->exec(); 3177 mEventEditor->exec();
3176 setActiveWindow(); 3178 setActiveWindow();
3177} 3179}
3178void CalendarView::todoAdded(Todo * t) 3180void CalendarView::todoAdded(Todo * t)
3179{ 3181{
3180 3182
3181 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3183 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3182 updateTodoViews(); 3184 updateTodoViews();
3183} 3185}
3184void CalendarView::todoChanged(Todo * t) 3186void CalendarView::todoChanged(Todo * t)
3185{ 3187{
3186 emit todoModified( t, 4 ); 3188 emit todoModified( t, 4 );
3187 // updateTodoViews(); 3189 // updateTodoViews();
3188} 3190}
3189void CalendarView::todoToBeDeleted(Todo *) 3191void CalendarView::todoToBeDeleted(Todo *)
3190{ 3192{
3191 //qDebug("todoToBeDeleted(Todo *) "); 3193 //qDebug("todoToBeDeleted(Todo *) ");
3192 updateTodoViews(); 3194 updateTodoViews();
3193} 3195}
3194void CalendarView::todoDeleted() 3196void CalendarView::todoDeleted()
3195{ 3197{
3196 //qDebug(" todoDeleted()"); 3198 //qDebug(" todoDeleted()");
3197 updateTodoViews(); 3199 updateTodoViews();
3198} 3200}
3199 3201
3200 3202
3201void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3203void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3202{ 3204{
3203 showTodoEditor(); 3205 showTodoEditor();
3204 mTodoEditor->newTodo(dt,0,allday); 3206 mTodoEditor->newTodo(dt,0,allday);
3205 if ( mFilterView->filtersEnabled() ) { 3207 if ( mFilterView->filtersEnabled() ) {
3206 CalFilter *filter = mFilterView->selectedFilter(); 3208 CalFilter *filter = mFilterView->selectedFilter();
3207 if (filter && filter->showCategories()) { 3209 if (filter && filter->showCategories()) {
3208 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3210 mTodoEditor->setCategories(filter->categoryList().join(",") );
3209 } 3211 }
3210 if ( filter ) 3212 if ( filter )
3211 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3213 mTodoEditor->setSecrecy( filter->getSecrecy() );
3212 } 3214 }
3213 mTodoEditor->exec(); 3215 mTodoEditor->exec();
3214 setActiveWindow(); 3216 setActiveWindow();
3215} 3217}
3216 3218
3217void CalendarView::newTodo() 3219void CalendarView::newTodo()
3218{ 3220{
3219 newTodoDateTime( QDateTime(),true ); 3221 newTodoDateTime( QDateTime(),true );
3220} 3222}
3221 3223
3222void CalendarView::newSubTodo() 3224void CalendarView::newSubTodo()
3223{ 3225{
3224 Todo *todo = selectedTodo(); 3226 Todo *todo = selectedTodo();
3225 if ( todo ) newSubTodo( todo ); 3227 if ( todo ) newSubTodo( todo );
3226} 3228}
3227 3229
3228void CalendarView::newSubTodo(Todo *parentEvent) 3230void CalendarView::newSubTodo(Todo *parentEvent)
3229{ 3231{
3230 3232
3231 showTodoEditor(); 3233 showTodoEditor();
3232 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3234 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3233 mTodoEditor->exec(); 3235 mTodoEditor->exec();
3234 setActiveWindow(); 3236 setActiveWindow();
3235} 3237}
3236 3238
3237void CalendarView::newFloatingEvent() 3239void CalendarView::newFloatingEvent()
3238{ 3240{
3239 DateList tmpList = mNavigator->selectedDates(); 3241 DateList tmpList = mNavigator->selectedDates();
3240 QDate date = tmpList.first(); 3242 QDate date = tmpList.first();
3241 3243
3242 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3244 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3243 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3245 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3244} 3246}
3245 3247
3246 3248
3247void CalendarView::editEvent( Event *event ) 3249void CalendarView::editEvent( Event *event )
3248{ 3250{
3249 3251
3250 if ( !event ) return; 3252 if ( !event ) return;
3251 if ( event->isReadOnly() ) { 3253 if ( event->isReadOnly() ) {
3252 showEvent( event ); 3254 showEvent( event );
3253 return; 3255 return;
3254 } 3256 }
3255 showEventEditor(); 3257 showEventEditor();
3256 mEventEditor->editEvent( event , mFlagEditDescription); 3258 mEventEditor->editEvent( event , mFlagEditDescription);
3257 mEventEditor->exec(); 3259 mEventEditor->exec();
3258 setActiveWindow(); 3260 setActiveWindow();
3259 3261
3260} 3262}
3261void CalendarView::editJournal( Journal *jour ) 3263void CalendarView::editJournal( Journal *jour )
3262{ 3264{
3263 if ( !jour ) return; 3265 if ( !jour ) return;
3264 mDialogManager->hideSearchDialog(); 3266 mDialogManager->hideSearchDialog();
3265 mViewManager->showJournalView(); 3267 mViewManager->showJournalView();
3266 mNavigator->slotDaySelect( jour->dtStart().date() ); 3268 mNavigator->slotDaySelect( jour->dtStart().date() );
3267} 3269}
3268void CalendarView::editTodo( Todo *todo ) 3270void CalendarView::editTodo( Todo *todo )
3269{ 3271{
3270 if ( !todo ) return; 3272 if ( !todo ) return;
3271 3273
3272 if ( todo->isReadOnly() ) { 3274 if ( todo->isReadOnly() ) {
3273 showTodo( todo ); 3275 showTodo( todo );
3274 return; 3276 return;
3275 } 3277 }
3276 showTodoEditor(); 3278 showTodoEditor();
3277 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3279 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3278 mTodoEditor->exec(); 3280 mTodoEditor->exec();
3279 setActiveWindow(); 3281 setActiveWindow();
3280 3282
3281} 3283}
3282 3284
3283KOEventViewerDialog* CalendarView::getEventViewerDialog() 3285KOEventViewerDialog* CalendarView::getEventViewerDialog()
3284{ 3286{
3285 if ( !mEventViewerDialog ) { 3287 if ( !mEventViewerDialog ) {
3286 mEventViewerDialog = new KOEventViewerDialog(0); 3288 mEventViewerDialog = new KOEventViewerDialog(0);
3287 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3289 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3288 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3290 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3289 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3291 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3290 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3292 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3291 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3293 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3292 viewManager(), SLOT( showAgendaView( bool ) ) ); 3294 viewManager(), SLOT( showAgendaView( bool ) ) );
3293 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3295 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3294 this, SLOT( slotViewerClosed() ) ); 3296 this, SLOT( slotViewerClosed() ) );
3295 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3297 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3296 this, SLOT( todoChanged(Todo *) ) ); 3298 this, SLOT( todoChanged(Todo *) ) );
3297 mEventViewerDialog->resize( 640, 480 ); 3299 mEventViewerDialog->resize( 640, 480 );
3298 3300
3299 } 3301 }
3300 return mEventViewerDialog; 3302 return mEventViewerDialog;
3301} 3303}
3302void CalendarView::showEvent(Event *event) 3304void CalendarView::showEvent(Event *event)
3303{ 3305{
3304 getEventViewerDialog()->setEvent(event); 3306 getEventViewerDialog()->setEvent(event);
3305 getEventViewerDialog()->showMe(); 3307 getEventViewerDialog()->showMe();
3306} 3308}
3307 3309
3308void CalendarView::showTodo(Todo *event) 3310void CalendarView::showTodo(Todo *event)
3309{ 3311{
3310 getEventViewerDialog()->setTodo(event); 3312 getEventViewerDialog()->setTodo(event);
3311 getEventViewerDialog()->showMe(); 3313 getEventViewerDialog()->showMe();
3312} 3314}
3313void CalendarView::showJournal( Journal *jour ) 3315void CalendarView::showJournal( Journal *jour )
3314{ 3316{
3315 getEventViewerDialog()->setJournal(jour); 3317 getEventViewerDialog()->setJournal(jour);
3316 getEventViewerDialog()->showMe(); 3318 getEventViewerDialog()->showMe();
3317 3319
3318} 3320}
3319// void CalendarView::todoModified (Todo *event, int changed) 3321// void CalendarView::todoModified (Todo *event, int changed)
3320// { 3322// {
3321// // if (mDialogList.find (event) != mDialogList.end ()) { 3323// // if (mDialogList.find (event) != mDialogList.end ()) {
3322// // kdDebug() << "Todo modified and open" << endl; 3324// // kdDebug() << "Todo modified and open" << endl;
3323// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3325// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3324// // temp->modified (changed); 3326// // temp->modified (changed);
3325 3327
3326// // } 3328// // }
3327 3329
3328// mViewManager->updateView(); 3330// mViewManager->updateView();
3329// } 3331// }
3330 3332
3331void CalendarView::appointment_show() 3333void CalendarView::appointment_show()
3332{ 3334{
3333 Event *anEvent = 0; 3335 Event *anEvent = 0;
3334 3336
3335 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3337 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3336 3338
3337 if (mViewManager->currentView()->isEventView()) { 3339 if (mViewManager->currentView()->isEventView()) {
3338 if ( incidence && incidence->typeID() == eventID ) { 3340 if ( incidence && incidence->typeID() == eventID ) {
3339 anEvent = static_cast<Event *>(incidence); 3341 anEvent = static_cast<Event *>(incidence);
3340 } 3342 }
3341 } 3343 }
3342 3344
3343 if (!anEvent) { 3345 if (!anEvent) {
3344 KNotifyClient::beep(); 3346 KNotifyClient::beep();
3345 return; 3347 return;
3346 } 3348 }
3347 3349
3348 showEvent(anEvent); 3350 showEvent(anEvent);
3349} 3351}
3350 3352
3351void CalendarView::appointment_edit() 3353void CalendarView::appointment_edit()
3352{ 3354{
3353 Event *anEvent = 0; 3355 Event *anEvent = 0;
3354 3356
3355 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3357 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3356 3358
3357 if (mViewManager->currentView()->isEventView()) { 3359 if (mViewManager->currentView()->isEventView()) {
3358 if ( incidence && incidence->typeID() == eventID ) { 3360 if ( incidence && incidence->typeID() == eventID ) {
3359 anEvent = static_cast<Event *>(incidence); 3361 anEvent = static_cast<Event *>(incidence);
3360 } 3362 }
3361 } 3363 }
3362 3364
3363 if (!anEvent) { 3365 if (!anEvent) {
3364 KNotifyClient::beep(); 3366 KNotifyClient::beep();
3365 return; 3367 return;
3366 } 3368 }
3367 3369
3368 editEvent(anEvent); 3370 editEvent(anEvent);
3369} 3371}
3370 3372
3371void CalendarView::appointment_delete() 3373void CalendarView::appointment_delete()
3372{ 3374{
3373 Event *anEvent = 0; 3375 Event *anEvent = 0;
3374 3376
3375 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3377 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3376 3378
3377 if (mViewManager->currentView()->isEventView()) { 3379 if (mViewManager->currentView()->isEventView()) {
3378 if ( incidence && incidence->typeID() == eventID ) { 3380 if ( incidence && incidence->typeID() == eventID ) {
3379 anEvent = static_cast<Event *>(incidence); 3381 anEvent = static_cast<Event *>(incidence);
3380 } 3382 }
3381 } 3383 }
3382 3384
3383 if (!anEvent) { 3385 if (!anEvent) {
3384 KNotifyClient::beep(); 3386 KNotifyClient::beep();
3385 return; 3387 return;
3386 } 3388 }
3387 3389
3388 deleteEvent(anEvent); 3390 deleteEvent(anEvent);
3389} 3391}
3390 3392
3391void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3393void CalendarView::todo_resub( Todo * parent, Todo * sub )
3392{ 3394{
3393 if (!sub) return; 3395 if (!sub) return;
3394 if ( sub->relatedTo() == parent ) 3396 if ( sub->relatedTo() == parent )
3395 return; 3397 return;
3396 sub->setRelatedTo(parent); 3398 sub->setRelatedTo(parent);
3397 sub->updated(); 3399 sub->updated();
3398 setModified(true); 3400 setModified(true);
3399 updateView(); 3401 updateView();
3400} 3402}
3401void CalendarView::todo_unsub(Todo *anTodo ) 3403void CalendarView::todo_unsub(Todo *anTodo )
3402{ 3404{
3403 todo_resub( 0, anTodo ); 3405 todo_resub( 0, anTodo );
3404} 3406}
3405 3407
3406void CalendarView::deleteTodo(Todo *todo) 3408void CalendarView::deleteTodo(Todo *todo)
3407{ 3409{
3408 if (!todo) { 3410 if (!todo) {
3409 KNotifyClient::beep(); 3411 KNotifyClient::beep();
3410 return; 3412 return;
3411 } 3413 }
3412 if (KOPrefs::instance()->mConfirm) { 3414 if (KOPrefs::instance()->mConfirm) {
3413 QString text = todo->summary().left(20); 3415 QString text = todo->summary().left(20);
3414 if (!todo->relations().isEmpty()) { 3416 if (!todo->relations().isEmpty()) {
3415 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3417 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3416 3418
3417 } 3419 }
3418 switch (msgItemDelete(text)) { 3420 switch (msgItemDelete(text)) {
3419 case KMessageBox::Continue: // OK 3421 case KMessageBox::Continue: // OK
3420 bool deleteT = false; 3422 bool deleteT = false;
3421 if (!todo->relations().isEmpty()) { 3423 if (!todo->relations().isEmpty()) {
3422 deleteT = removeCompletedSubTodos( todo ); 3424 deleteT = removeCompletedSubTodos( todo );
3423 } 3425 }
3424 // deleteT == true: todo already deleted in removeCompletedSubTodos 3426 // deleteT == true: todo already deleted in removeCompletedSubTodos
3425 if ( !deleteT ) { 3427 if ( !deleteT ) {
3426 checkExternalId( todo ); 3428 checkExternalId( todo );
3427 calendar()->deleteTodo(todo); 3429 calendar()->deleteTodo(todo);
3428 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3430 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3429 updateView(); 3431 updateView();
3430 } 3432 }
3431 break; 3433 break;
3432 } // switch 3434 } // switch
3433 } else { 3435 } else {
3434 checkExternalId( todo ); 3436 checkExternalId( todo );
3435 mCalendar->deleteTodo(todo); 3437 mCalendar->deleteTodo(todo);
3436 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3438 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3437 updateView(); 3439 updateView();
3438 } 3440 }
3439 3441
3440 emit updateSearchDialog(); 3442 emit updateSearchDialog();
3441} 3443}
3442void CalendarView::deleteJournal(Journal *jour) 3444void CalendarView::deleteJournal(Journal *jour)
3443{ 3445{
3444 if (!jour) { 3446 if (!jour) {
3445 KNotifyClient::beep(); 3447 KNotifyClient::beep();
3446 return; 3448 return;
3447 } 3449 }
3448 if (KOPrefs::instance()->mConfirm) { 3450 if (KOPrefs::instance()->mConfirm) {
3449 switch (msgItemDelete( jour->description().left(20))) { 3451 switch (msgItemDelete( jour->description().left(20))) {
3450 case KMessageBox::Continue: // OK 3452 case KMessageBox::Continue: // OK
3451 calendar()->deleteJournal(jour); 3453 calendar()->deleteJournal(jour);
3452 updateView(); 3454 updateView();
3453 break; 3455 break;
3454 } // switch 3456 } // switch
3455 } else { 3457 } else {
3456 calendar()->deleteJournal(jour);; 3458 calendar()->deleteJournal(jour);;
3457 updateView(); 3459 updateView();
3458 } 3460 }
3459 emit updateSearchDialog(); 3461 emit updateSearchDialog();
3460} 3462}
3461 3463
3462void CalendarView::deleteEvent(Event *anEvent) 3464void CalendarView::deleteEvent(Event *anEvent)
3463{ 3465{
3464 if (!anEvent) { 3466 if (!anEvent) {
3465 KNotifyClient::beep(); 3467 KNotifyClient::beep();
3466 return; 3468 return;
3467 } 3469 }
3468 3470
3469 if (anEvent->recurrence()->doesRecur()) { 3471 if (anEvent->recurrence()->doesRecur()) {
3470 QDate itemDate = mViewManager->currentSelectionDate(); 3472 QDate itemDate = mViewManager->currentSelectionDate();
3471 int km; 3473 int km;
3472 if (!itemDate.isValid()) { 3474 if (!itemDate.isValid()) {
3473 //kdDebug() << "Date Not Valid" << endl; 3475 //kdDebug() << "Date Not Valid" << endl;
3474 if (KOPrefs::instance()->mConfirm) { 3476 if (KOPrefs::instance()->mConfirm) {
3475 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3477 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3476 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3478 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3477 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3479 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3478 if ( km == KMessageBox::Continue ) 3480 if ( km == KMessageBox::Continue )
3479 km = KMessageBox::No; // No = all below 3481 km = KMessageBox::No; // No = all below
3480 } else 3482 } else
3481 km = KMessageBox::No; 3483 km = KMessageBox::No;
3482 } else { 3484 } else {
3483 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 3485 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
3484 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3486 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3485 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3487 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3486 i18n("KO/Pi Confirmation"),i18n("Current"), 3488 i18n("KO/Pi Confirmation"),i18n("Current"),
3487 i18n("All")); 3489 i18n("All"));
3488 } 3490 }
3489 switch(km) { 3491 switch(km) {
3490 3492
3491 case KMessageBox::No: // Continue // all 3493 case KMessageBox::No: // Continue // all
3492 //qDebug("KMessageBox::No "); 3494 //qDebug("KMessageBox::No ");
3493 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3495 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3494 schedule(Scheduler::Cancel,anEvent); 3496 schedule(Scheduler::Cancel,anEvent);
3495 3497
3496 checkExternalId( anEvent); 3498 checkExternalId( anEvent);
3497 mCalendar->deleteEvent(anEvent); 3499 mCalendar->deleteEvent(anEvent);
3498 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3500 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3499 break; 3501 break;
3500 3502
3501 // Disabled because it does not work 3503 // Disabled because it does not work
3502 //#if 0 3504 //#if 0
3503 case KMessageBox::Yes: // just this one 3505 case KMessageBox::Yes: // just this one
3504 //QDate qd = mNavigator->selectedDates().first(); 3506 //QDate qd = mNavigator->selectedDates().first();
3505 //if (!qd.isValid()) { 3507 //if (!qd.isValid()) {
3506 // kdDebug() << "no date selected, or invalid date" << endl; 3508 // kdDebug() << "no date selected, or invalid date" << endl;
3507 // KNotifyClient::beep(); 3509 // KNotifyClient::beep();
3508 // return; 3510 // return;
3509 //} 3511 //}
3510 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3512 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3511 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3513 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3512 anEvent->addExDate(itemDate); 3514 anEvent->addExDate(itemDate);
3513 int duration = anEvent->recurrence()->duration(); 3515 int duration = anEvent->recurrence()->duration();
3514 if ( duration > 0 ) { 3516 if ( duration > 0 ) {
3515 anEvent->recurrence()->setDuration( duration - 1 ); 3517 anEvent->recurrence()->setDuration( duration - 1 );
3516 } 3518 }
3517 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3519 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3518 } 3520 }
3519 break; 3521 break;
3520 //#endif 3522 //#endif
3521 } // switch 3523 } // switch
3522 } else { 3524 } else {
3523 if (KOPrefs::instance()->mConfirm) { 3525 if (KOPrefs::instance()->mConfirm) {
3524 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3526 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3525 i18n("\nAre you sure you want\nto delete this event?"), 3527 i18n("\nAre you sure you want\nto delete this event?"),
3526 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3528 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3527 case KMessageBox::Continue: // OK 3529 case KMessageBox::Continue: // OK
3528 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3530 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3529 schedule(Scheduler::Cancel,anEvent); 3531 schedule(Scheduler::Cancel,anEvent);
3530 checkExternalId( anEvent); 3532 checkExternalId( anEvent);
3531 mCalendar->deleteEvent(anEvent); 3533 mCalendar->deleteEvent(anEvent);
3532 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3534 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3533 break; 3535 break;
3534 } // switch 3536 } // switch
3535 } else { 3537 } else {
3536 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3538 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3537 schedule(Scheduler::Cancel,anEvent); 3539 schedule(Scheduler::Cancel,anEvent);
3538 checkExternalId( anEvent); 3540 checkExternalId( anEvent);
3539 mCalendar->deleteEvent(anEvent); 3541 mCalendar->deleteEvent(anEvent);
3540 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3542 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3541 } 3543 }
3542 } // if-else 3544 } // if-else
3543 emit updateSearchDialog(); 3545 emit updateSearchDialog();
3544} 3546}
3545 3547
3546bool CalendarView::deleteEvent(const QString &uid) 3548bool CalendarView::deleteEvent(const QString &uid)
3547{ 3549{
3548 Event *ev = mCalendar->event(uid); 3550 Event *ev = mCalendar->event(uid);
3549 if (ev) { 3551 if (ev) {
3550 deleteEvent(ev); 3552 deleteEvent(ev);
3551 return true; 3553 return true;
3552 } else { 3554 } else {
3553 return false; 3555 return false;
3554 } 3556 }
3555} 3557}
3556 3558
3557/*****************************************************************************/ 3559/*****************************************************************************/
3558 3560
3559void CalendarView::action_mail() 3561void CalendarView::action_mail()
3560{ 3562{
3561#ifndef KORG_NOMAIL 3563#ifndef KORG_NOMAIL
3562 KOMailClient mailClient; 3564 KOMailClient mailClient;
3563 3565
3564 Incidence *incidence = currentSelection(); 3566 Incidence *incidence = currentSelection();
3565 3567
3566 if (!incidence) { 3568 if (!incidence) {
3567 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3569 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3568 return; 3570 return;
3569 } 3571 }
3570 if(incidence->attendeeCount() == 0 ) { 3572 if(incidence->attendeeCount() == 0 ) {
3571 KMessageBox::sorry(this, 3573 KMessageBox::sorry(this,
3572 i18n("Can't generate mail:\nNo attendees defined.\n")); 3574 i18n("Can't generate mail:\nNo attendees defined.\n"));
3573 return; 3575 return;
3574 } 3576 }
3575 3577
3576 CalendarLocal cal_tmp; 3578 CalendarLocal cal_tmp;
3577 Event *event = 0; 3579 Event *event = 0;
3578 Event *ev = 0; 3580 Event *ev = 0;
3579 if ( incidence && incidence->typeID() == eventID ) { 3581 if ( incidence && incidence->typeID() == eventID ) {
3580 event = static_cast<Event *>(incidence); 3582 event = static_cast<Event *>(incidence);
3581 ev = new Event(*event); 3583 ev = new Event(*event);
3582 cal_tmp.addEvent(ev); 3584 cal_tmp.addEvent(ev);
3583 } 3585 }
3584 ICalFormat mForm(); 3586 ICalFormat mForm();
3585 QString attachment = mForm.toString( &cal_tmp ); 3587 QString attachment = mForm.toString( &cal_tmp );
3586 if (ev) delete(ev); 3588 if (ev) delete(ev);
3587 3589
3588 mailClient.mailAttendees(currentSelection(), attachment); 3590 mailClient.mailAttendees(currentSelection(), attachment);
3589 3591
3590#endif 3592#endif
3591 3593
3592#if 0 3594#if 0
3593 Event *anEvent = 0; 3595 Event *anEvent = 0;
3594 if (mViewManager->currentView()->isEventView()) { 3596 if (mViewManager->currentView()->isEventView()) {
3595 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3597 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3596 } 3598 }
3597 3599
3598 if (!anEvent) { 3600 if (!anEvent) {
3599 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3601 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3600 return; 3602 return;
3601 } 3603 }
3602 if(anEvent->attendeeCount() == 0 ) { 3604 if(anEvent->attendeeCount() == 0 ) {
3603 KMessageBox::sorry(this, 3605 KMessageBox::sorry(this,
3604 i18n("Can't generate mail:\nNo attendees defined.\n")); 3606 i18n("Can't generate mail:\nNo attendees defined.\n"));
3605 return; 3607 return;
3606 } 3608 }
3607 3609
3608 mailobject.emailEvent(anEvent); 3610 mailobject.emailEvent(anEvent);
3609#endif 3611#endif
3610} 3612}
3611 3613
3612 3614
3613void CalendarView::schedule_publish(Incidence *incidence) 3615void CalendarView::schedule_publish(Incidence *incidence)
3614{ 3616{
3615 Event *event = 0; 3617 Event *event = 0;
3616 Todo *todo = 0; 3618 Todo *todo = 0;
3617 3619
3618 if (incidence == 0) { 3620 if (incidence == 0) {
3619 incidence = mViewManager->currentView()->selectedIncidences().first(); 3621 incidence = mViewManager->currentView()->selectedIncidences().first();
3620 if (incidence == 0) { 3622 if (incidence == 0) {
3621 incidence = mTodoList->selectedIncidences().first(); 3623 incidence = mTodoList->selectedIncidences().first();
3622 } 3624 }
3623 } 3625 }
3624 if ( incidence && incidence->typeID() == eventID ) { 3626 if ( incidence && incidence->typeID() == eventID ) {
3625 event = static_cast<Event *>(incidence); 3627 event = static_cast<Event *>(incidence);
3626 } else { 3628 } else {
3627 if ( incidence && incidence->typeID() == todoID ) { 3629 if ( incidence && incidence->typeID() == todoID ) {
3628 todo = static_cast<Todo *>(incidence); 3630 todo = static_cast<Todo *>(incidence);
3629 } 3631 }
3630 } 3632 }
3631 3633
3632 if (!event && !todo) { 3634 if (!event && !todo) {
3633 KMessageBox::sorry(this,i18n("No event selected.")); 3635 KMessageBox::sorry(this,i18n("No event selected."));
3634 return; 3636 return;
3635 } 3637 }
3636 3638
3637 PublishDialog *publishdlg = new PublishDialog(); 3639 PublishDialog *publishdlg = new PublishDialog();
3638 if (incidence->attendeeCount()>0) { 3640 if (incidence->attendeeCount()>0) {
3639 QPtrList<Attendee> attendees = incidence->attendees(); 3641 QPtrList<Attendee> attendees = incidence->attendees();
3640 attendees.first(); 3642 attendees.first();
3641 while ( attendees.current()!=0 ) { 3643 while ( attendees.current()!=0 ) {
3642 publishdlg->addAttendee(attendees.current()); 3644 publishdlg->addAttendee(attendees.current());
3643 attendees.next(); 3645 attendees.next();
3644 } 3646 }
3645 } 3647 }
3646 bool send = true; 3648 bool send = true;
3647 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3649 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3648 if ( publishdlg->exec() != QDialog::Accepted ) 3650 if ( publishdlg->exec() != QDialog::Accepted )
3649 send = false; 3651 send = false;
3650 } 3652 }
3651 if ( send ) { 3653 if ( send ) {
3652 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3654 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3653 if ( event ) { 3655 if ( event ) {
3654 Event *ev = new Event(*event); 3656 Event *ev = new Event(*event);
3655 ev->registerObserver(0); 3657 ev->registerObserver(0);
3656 ev->clearAttendees(); 3658 ev->clearAttendees();
3657 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3659 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3658 delete(ev); 3660 delete(ev);
3659 } 3661 }
3660 } else { 3662 } else {
3661 if ( todo ) { 3663 if ( todo ) {
3662 Todo *ev = new Todo(*todo); 3664 Todo *ev = new Todo(*todo);
3663 ev->registerObserver(0); 3665 ev->registerObserver(0);
3664 ev->clearAttendees(); 3666 ev->clearAttendees();
3665 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3667 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3666 delete(ev); 3668 delete(ev);
3667 } 3669 }
3668 } 3670 }
3669 } 3671 }
3670 } 3672 }
3671 delete publishdlg; 3673 delete publishdlg;
3672} 3674}
3673 3675
3674void CalendarView::schedule_request(Incidence *incidence) 3676void CalendarView::schedule_request(Incidence *incidence)
3675{ 3677{
3676 schedule(Scheduler::Request,incidence); 3678 schedule(Scheduler::Request,incidence);
3677} 3679}
3678 3680
3679void CalendarView::schedule_refresh(Incidence *incidence) 3681void CalendarView::schedule_refresh(Incidence *incidence)
3680{ 3682{
3681 schedule(Scheduler::Refresh,incidence); 3683 schedule(Scheduler::Refresh,incidence);
3682} 3684}
3683 3685
3684void CalendarView::schedule_cancel(Incidence *incidence) 3686void CalendarView::schedule_cancel(Incidence *incidence)
3685{ 3687{
3686 schedule(Scheduler::Cancel,incidence); 3688 schedule(Scheduler::Cancel,incidence);
3687} 3689}
3688 3690
3689void CalendarView::schedule_add(Incidence *incidence) 3691void CalendarView::schedule_add(Incidence *incidence)
3690{ 3692{
3691 schedule(Scheduler::Add,incidence); 3693 schedule(Scheduler::Add,incidence);
3692} 3694}
3693 3695
3694void CalendarView::schedule_reply(Incidence *incidence) 3696void CalendarView::schedule_reply(Incidence *incidence)
3695{ 3697{
3696 schedule(Scheduler::Reply,incidence); 3698 schedule(Scheduler::Reply,incidence);
3697} 3699}
3698 3700
3699void CalendarView::schedule_counter(Incidence *incidence) 3701void CalendarView::schedule_counter(Incidence *incidence)
3700{ 3702{
3701 schedule(Scheduler::Counter,incidence); 3703 schedule(Scheduler::Counter,incidence);
3702} 3704}
3703 3705
3704void CalendarView::schedule_declinecounter(Incidence *incidence) 3706void CalendarView::schedule_declinecounter(Incidence *incidence)
3705{ 3707{
3706 schedule(Scheduler::Declinecounter,incidence); 3708 schedule(Scheduler::Declinecounter,incidence);
3707} 3709}
3708 3710
3709void CalendarView::schedule_publish_freebusy(int daysToPublish) 3711void CalendarView::schedule_publish_freebusy(int daysToPublish)
3710{ 3712{
3711 QDateTime start = QDateTime::currentDateTime(); 3713 QDateTime start = QDateTime::currentDateTime();
3712 QDateTime end = start.addDays(daysToPublish); 3714 QDateTime end = start.addDays(daysToPublish);
3713 3715
3714 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3716 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3715 freebusy->setOrganizer(KOPrefs::instance()->email()); 3717 freebusy->setOrganizer(KOPrefs::instance()->email());
3716 3718
3717 3719
3718 PublishDialog *publishdlg = new PublishDialog(); 3720 PublishDialog *publishdlg = new PublishDialog();
3719 if ( publishdlg->exec() == QDialog::Accepted ) { 3721 if ( publishdlg->exec() == QDialog::Accepted ) {
3720 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3722 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3721 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3723 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3722 delete(freebusy); 3724 delete(freebusy);
3723 } 3725 }
3724 } 3726 }
3725 delete publishdlg; 3727 delete publishdlg;
3726} 3728}
3727 3729
3728void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3730void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3729{ 3731{
3730 Event *event = 0; 3732 Event *event = 0;
3731 Todo *todo = 0; 3733 Todo *todo = 0;
3732 3734
3733 if (incidence == 0) { 3735 if (incidence == 0) {
3734 incidence = mViewManager->currentView()->selectedIncidences().first(); 3736 incidence = mViewManager->currentView()->selectedIncidences().first();
3735 if (incidence == 0) { 3737 if (incidence == 0) {
3736 incidence = mTodoList->selectedIncidences().first(); 3738 incidence = mTodoList->selectedIncidences().first();
3737 } 3739 }
3738 } 3740 }
3739 if ( incidence && incidence->typeID() == eventID ) { 3741 if ( incidence && incidence->typeID() == eventID ) {
3740 event = static_cast<Event *>(incidence); 3742 event = static_cast<Event *>(incidence);
3741 } 3743 }
3742 if ( incidence && incidence->typeID() == todoID ) { 3744 if ( incidence && incidence->typeID() == todoID ) {
3743 todo = static_cast<Todo *>(incidence); 3745 todo = static_cast<Todo *>(incidence);
3744 } 3746 }
3745 3747
3746 if (!event && !todo) { 3748 if (!event && !todo) {
3747 KMessageBox::sorry(this,i18n("No event selected.")); 3749 KMessageBox::sorry(this,i18n("No event selected."));
3748 return; 3750 return;
3749 } 3751 }
3750 3752
3751 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3753 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3752 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3754 KMessageBox::sorry(this,i18n("The event has no attendees."));
3753 return; 3755 return;
3754 } 3756 }
3755 3757
3756 Event *ev = 0; 3758 Event *ev = 0;
3757 if (event) ev = new Event(*event); 3759 if (event) ev = new Event(*event);
3758 Todo *to = 0; 3760 Todo *to = 0;
3759 if (todo) to = new Todo(*todo); 3761 if (todo) to = new Todo(*todo);
3760 3762
3761 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3763 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3762 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3764 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3763 if (!me) { 3765 if (!me) {
3764 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3766 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3765 return; 3767 return;
3766 } 3768 }
3767 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3769 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3768 StatusDialog *statdlg = new StatusDialog(this); 3770 StatusDialog *statdlg = new StatusDialog(this);
3769 if (!statdlg->exec()==QDialog::Accepted) return; 3771 if (!statdlg->exec()==QDialog::Accepted) return;
3770 me->setStatus( statdlg->status() ); 3772 me->setStatus( statdlg->status() );
3771 delete(statdlg); 3773 delete(statdlg);
3772 } 3774 }
3773 Attendee *menew = new Attendee(*me); 3775 Attendee *menew = new Attendee(*me);
3774 if (ev) { 3776 if (ev) {
3775 ev->clearAttendees(); 3777 ev->clearAttendees();
3776 ev->addAttendee(menew,false); 3778 ev->addAttendee(menew,false);
3777 } else { 3779 } else {
3778 if (to) { 3780 if (to) {
3779 todo->clearAttendees(); 3781 todo->clearAttendees();
3780 todo->addAttendee(menew,false); 3782 todo->addAttendee(menew,false);
3781 } 3783 }
3782 } 3784 }
3783 } 3785 }
3784 3786
3785 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3787 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3786 if (ev) { 3788 if (ev) {
3787 if ( !dlg->addMessage(ev,method) ) delete(ev); 3789 if ( !dlg->addMessage(ev,method) ) delete(ev);
3788 } else { 3790 } else {
3789 if (to) { 3791 if (to) {
3790 if ( !dlg->addMessage(to,method) ) delete(to); 3792 if ( !dlg->addMessage(to,method) ) delete(to);
3791 } 3793 }
3792 } 3794 }
3793} 3795}
3794 3796
3795void CalendarView::openAddressbook() 3797void CalendarView::openAddressbook()
3796{ 3798{
3797 KRun::runCommand("kaddressbook"); 3799 KRun::runCommand("kaddressbook");
3798} 3800}
3799 3801
3800void CalendarView::setModified(bool modified) 3802void CalendarView::setModified(bool modified)
3801{ 3803{
3802 if ( modified ) 3804 if ( modified )
3803 emit signalmodified(); 3805 emit signalmodified();
3804 if (mModified != modified) { 3806 if (mModified != modified) {
3805 mModified = modified; 3807 mModified = modified;
3806 emit modifiedChanged(mModified); 3808 emit modifiedChanged(mModified);
3807 } 3809 }
3808} 3810}
3809 3811
3810bool CalendarView::isReadOnly() 3812bool CalendarView::isReadOnly()
3811{ 3813{
3812 return mReadOnly; 3814 return mReadOnly;
3813} 3815}
3814 3816
3815void CalendarView::setReadOnly(bool readOnly) 3817void CalendarView::setReadOnly(bool readOnly)
3816{ 3818{
3817 if (mReadOnly != readOnly) { 3819 if (mReadOnly != readOnly) {
3818 mReadOnly = readOnly; 3820 mReadOnly = readOnly;
3819 emit readOnlyChanged(mReadOnly); 3821 emit readOnlyChanged(mReadOnly);
3820 } 3822 }
3821} 3823}
3822 3824
3823bool CalendarView::isModified() 3825bool CalendarView::isModified()
3824{ 3826{
3825 return mModified; 3827 return mModified;
3826} 3828}
3827void CalendarView::slotprintSelInc() 3829void CalendarView::slotprintSelInc()
3828{ 3830{
3829 if ( currentSelection() == 0 ) { 3831 if ( currentSelection() == 0 ) {
3830 KMessageBox::sorry(this,i18n("There is nothing selected!")); 3832 KMessageBox::sorry(this,i18n("There is nothing selected!"));
3831 return; 3833 return;
3832 } 3834 }
3833 showIncidence(); 3835 showIncidence();
3834 getEventViewerDialog()->print(); 3836 getEventViewerDialog()->print();
3835 3837
3836} 3838}
3837void CalendarView::printSetup() 3839void CalendarView::printSetup()
3838{ 3840{
3839#ifndef KORG_NOPRINTER 3841#ifndef KORG_NOPRINTER
3840 createPrinter(); 3842 createPrinter();
3841 3843
3842 mCalPrinter->setupPrinter(); 3844 mCalPrinter->setupPrinter();
3843#endif 3845#endif
3844} 3846}
3845 3847
3846void CalendarView::print() 3848void CalendarView::print()
3847{ 3849{
3848#ifndef KORG_NOPRINTER 3850#ifndef KORG_NOPRINTER
3849 createPrinter(); 3851 createPrinter();
3850 3852
3851 DateList tmpDateList = mNavigator->selectedDates(); 3853 DateList tmpDateList = mNavigator->selectedDates();
3852 mCalPrinter->print(CalPrinter::Month, 3854 mCalPrinter->print(CalPrinter::Month,
3853 tmpDateList.first(), tmpDateList.last()); 3855 tmpDateList.first(), tmpDateList.last());
3854#endif 3856#endif
3855} 3857}
3856 3858
3857void CalendarView::printPreview() 3859void CalendarView::printPreview()
3858{ 3860{
3859#ifndef KORG_NOPRINTER 3861#ifndef KORG_NOPRINTER
3860 kdDebug() << "CalendarView::printPreview()" << endl; 3862 kdDebug() << "CalendarView::printPreview()" << endl;
3861 3863
3862 createPrinter(); 3864 createPrinter();
3863 3865
3864 DateList tmpDateList = mNavigator->selectedDates(); 3866 DateList tmpDateList = mNavigator->selectedDates();
3865 3867
3866 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3868 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3867 tmpDateList.last()); 3869 tmpDateList.last());
3868#endif 3870#endif
3869} 3871}
3870 3872
3871void CalendarView::exportICalendar() 3873void CalendarView::exportICalendar()
3872{ 3874{
3873 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3875 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3874 3876
3875 // Force correct extension 3877 // Force correct extension
3876 if (filename.right(4) != ".ics") filename += ".ics"; 3878 if (filename.right(4) != ".ics") filename += ".ics";
3877 3879
3878 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3880 FileStorage storage( mCalendar, filename, new ICalFormat() );
3879 storage.save(); 3881 storage.save();
3880} 3882}
3881 3883
3882bool CalendarView::exportVCalendar( QString filename ) 3884bool CalendarView::exportVCalendar( QString filename )
3883{ 3885{
3884 if (mCalendar->journals().count() > 0) { 3886 if (mCalendar->journals().count() > 0) {
3885 int result = KMessageBox::warningContinueCancel(this, 3887 int result = KMessageBox::warningContinueCancel(this,
3886 i18n("The journal entries can not be\nexported to a vCalendar file."), 3888 i18n("The journal entries can not be\nexported to a vCalendar file."),
3887 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3889 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3888 true); 3890 true);
3889 if (result != KMessageBox::Continue) return false; 3891 if (result != KMessageBox::Continue) return false;
3890 } 3892 }
3891 3893
3892 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3894 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3893 3895
3894 // Force correct extension 3896 // Force correct extension
3895 if (filename.right(4) != ".vcs") filename += ".vcs"; 3897 if (filename.right(4) != ".vcs") filename += ".vcs";
3896 3898
3897 FileStorage storage( mCalendar, filename, new VCalFormat ); 3899 FileStorage storage( mCalendar, filename, new VCalFormat );
3898 return storage.save(); 3900 return storage.save();
3899 3901
3900} 3902}
3901 3903
3902void CalendarView::eventUpdated(Incidence *) 3904void CalendarView::eventUpdated(Incidence *)
3903{ 3905{
3904 setModified(); 3906 setModified();
3905 // Don't call updateView here. The code, which has caused the update of the 3907 // Don't call updateView here. The code, which has caused the update of the
3906 // event is responsible for updating the view. 3908 // event is responsible for updating the view.
3907 // updateView(); 3909 // updateView();
3908} 3910}
3909 3911
3910void CalendarView::adaptNavigationUnits() 3912void CalendarView::adaptNavigationUnits()
3911{ 3913{
3912 if (mViewManager->currentView()->isEventView()) { 3914 if (mViewManager->currentView()->isEventView()) {
3913 int days = mViewManager->currentView()->currentDateCount(); 3915 int days = mViewManager->currentView()->currentDateCount();
3914 if (days == 1) { 3916 if (days == 1) {
3915 emit changeNavStringPrev(i18n("&Previous Day")); 3917 emit changeNavStringPrev(i18n("&Previous Day"));
3916 emit changeNavStringNext(i18n("&Next Day")); 3918 emit changeNavStringNext(i18n("&Next Day"));
3917 } else { 3919 } else {
3918 emit changeNavStringPrev(i18n("&Previous Week")); 3920 emit changeNavStringPrev(i18n("&Previous Week"));
3919 emit changeNavStringNext(i18n("&Next Week")); 3921 emit changeNavStringNext(i18n("&Next Week"));
3920 } 3922 }
3921 } 3923 }
3922} 3924}
3923 3925
3924void CalendarView::processMainViewSelection( Incidence *incidence ) 3926void CalendarView::processMainViewSelection( Incidence *incidence )
3925{ 3927{
3926 if ( incidence ) mTodoList->clearSelection(); 3928 if ( incidence ) mTodoList->clearSelection();
3927 processIncidenceSelection( incidence ); 3929 processIncidenceSelection( incidence );
3928} 3930}
3929 3931
3930void CalendarView::processTodoListSelection( Incidence *incidence ) 3932void CalendarView::processTodoListSelection( Incidence *incidence )
3931{ 3933{
3932 if ( incidence && mViewManager->currentView() ) { 3934 if ( incidence && mViewManager->currentView() ) {
3933 mViewManager->currentView()->clearSelection(); 3935 mViewManager->currentView()->clearSelection();
3934 } 3936 }
3935 processIncidenceSelection( incidence ); 3937 processIncidenceSelection( incidence );
3936} 3938}
3937 3939
3938void CalendarView::processIncidenceSelection( Incidence *incidence ) 3940void CalendarView::processIncidenceSelection( Incidence *incidence )
3939{ 3941{
3940 if ( incidence == mSelectedIncidence ) return; 3942 if ( incidence == mSelectedIncidence ) return;
3941 3943
3942 mSelectedIncidence = incidence; 3944 mSelectedIncidence = incidence;
3943 3945
3944 emit incidenceSelected( mSelectedIncidence ); 3946 emit incidenceSelected( mSelectedIncidence );
3945 3947
3946 if ( incidence && incidence->typeID() == eventID ) { 3948 if ( incidence && incidence->typeID() == eventID ) {
3947 Event *event = static_cast<Event *>( incidence ); 3949 Event *event = static_cast<Event *>( incidence );
3948 if ( event->organizer() == KOPrefs::instance()->email() ) { 3950 if ( event->organizer() == KOPrefs::instance()->email() ) {
3949 emit organizerEventsSelected( true ); 3951 emit organizerEventsSelected( true );
3950 } else { 3952 } else {
3951 emit organizerEventsSelected(false); 3953 emit organizerEventsSelected(false);
3952 } 3954 }
3953 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3955 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3954 KOPrefs::instance()->email() ) ) { 3956 KOPrefs::instance()->email() ) ) {
3955 emit groupEventsSelected( true ); 3957 emit groupEventsSelected( true );
3956 } else { 3958 } else {
3957 emit groupEventsSelected(false); 3959 emit groupEventsSelected(false);
3958 } 3960 }
3959 return; 3961 return;
3960 } else { 3962 } else {
3961 if ( incidence && incidence->typeID() == todoID ) { 3963 if ( incidence && incidence->typeID() == todoID ) {
3962 emit todoSelected( true ); 3964 emit todoSelected( true );
3963 Todo *event = static_cast<Todo *>( incidence ); 3965 Todo *event = static_cast<Todo *>( incidence );
3964 if ( event->organizer() == KOPrefs::instance()->email() ) { 3966 if ( event->organizer() == KOPrefs::instance()->email() ) {
3965 emit organizerEventsSelected( true ); 3967 emit organizerEventsSelected( true );
3966 } else { 3968 } else {
3967 emit organizerEventsSelected(false); 3969 emit organizerEventsSelected(false);
3968 } 3970 }
3969 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3971 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3970 KOPrefs::instance()->email() ) ) { 3972 KOPrefs::instance()->email() ) ) {
3971 emit groupEventsSelected( true ); 3973 emit groupEventsSelected( true );
3972 } else { 3974 } else {
3973 emit groupEventsSelected(false); 3975 emit groupEventsSelected(false);
3974 } 3976 }
3975 return; 3977 return;
3976 } else { 3978 } else {
3977 emit todoSelected( false ); 3979 emit todoSelected( false );
3978 emit organizerEventsSelected(false); 3980 emit organizerEventsSelected(false);
3979 emit groupEventsSelected(false); 3981 emit groupEventsSelected(false);
3980 } 3982 }
3981 return; 3983 return;
3982 } 3984 }
3983 3985
3984 /* if ( incidence && incidence->typeID() == todoID ) { 3986 /* if ( incidence && incidence->typeID() == todoID ) {
3985 emit todoSelected( true ); 3987 emit todoSelected( true );
3986 } else { 3988 } else {
3987 emit todoSelected( false ); 3989 emit todoSelected( false );
3988 }*/ 3990 }*/
3989} 3991}
3990 3992
3991 3993
3992void CalendarView::checkClipboard() 3994void CalendarView::checkClipboard()
3993{ 3995{
3994#ifndef KORG_NODND 3996#ifndef KORG_NODND
3995 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3997 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3996 emit pasteEnabled(true); 3998 emit pasteEnabled(true);
3997 } else { 3999 } else {
3998 emit pasteEnabled(false); 4000 emit pasteEnabled(false);
3999 } 4001 }
4000#endif 4002#endif
4001} 4003}
4002 4004
4003void CalendarView::showDates(const DateList &selectedDates) 4005void CalendarView::showDates(const DateList &selectedDates)
4004{ 4006{
4005 // kdDebug() << "CalendarView::selectDates()" << endl; 4007 // kdDebug() << "CalendarView::selectDates()" << endl;
4006 4008
4007 4009
4008 if ( !mBlockShowDates ) { 4010 if ( !mBlockShowDates ) {
4009 if ( mViewManager->currentView() ) { 4011 if ( mViewManager->currentView() ) {
4010 updateView( selectedDates.first(), selectedDates.last() ); 4012 updateView( selectedDates.first(), selectedDates.last() );
4011 } else { 4013 } else {
4012 mViewManager->showAgendaView(); 4014 mViewManager->showAgendaView();
4013 } 4015 }
4014 } 4016 }
4015 4017
4016 QDate date = selectedDates.first(); 4018 QDate date = selectedDates.first();
4017 if ( ! date.isValid() ) { 4019 if ( ! date.isValid() ) {
4018 topLevelWidget()->setCaption(""); 4020 topLevelWidget()->setCaption("");
4019 return; 4021 return;
4020 } 4022 }
4021 4023
4022 QString selDates; 4024 QString selDates;
4023 selDates = KGlobal::locale()->formatDate( date, true); 4025 selDates = KGlobal::locale()->formatDate( date, true);
4024 if (selectedDates.first() < selectedDates.last() ) 4026 if (selectedDates.first() < selectedDates.last() )
4025 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 4027 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
4026 else { 4028 else {
4027 QString addString; 4029 QString addString;
4028 if ( date == QDateTime::currentDateTime().date() ) 4030 if ( date == QDateTime::currentDateTime().date() )
4029 addString = i18n("Today"); 4031 addString = i18n("Today");
4030 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 4032 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
4031 addString = i18n("Tomorrow"); 4033 addString = i18n("Tomorrow");
4032 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 4034 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
4033 addString = i18n("Yesterday"); 4035 addString = i18n("Yesterday");
4034 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 4036 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
4035 addString = i18n("Day before yesterday"); 4037 addString = i18n("Day before yesterday");
4036 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 4038 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
4037 addString = i18n("Day after tomorrow"); 4039 addString = i18n("Day after tomorrow");
4038 if ( !addString.isEmpty() ) { 4040 if ( !addString.isEmpty() ) {
4039 topLevelWidget()->setCaption( addString+", " + selDates ); 4041 topLevelWidget()->setCaption( addString+", " + selDates );
4040 return; 4042 return;
4041 } 4043 }
4042 } 4044 }
4043 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 4045 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
4044 4046
4045} 4047}
4046 4048
4047QPtrList<CalFilter> CalendarView::filters() 4049QPtrList<CalFilter> CalendarView::filters()
4048{ 4050{
4049 return mFilters; 4051 return mFilters;
4050 4052
4051} 4053}
4052void CalendarView::editFilters() 4054void CalendarView::editFilters()
4053{ 4055{
4054 // kdDebug() << "CalendarView::editFilters()" << endl; 4056 // kdDebug() << "CalendarView::editFilters()" << endl;
4055 4057
4056 CalFilter *filter = mFilters.first(); 4058 CalFilter *filter = mFilters.first();
4057 while(filter) { 4059 while(filter) {
4058 filter = mFilters.next(); 4060 filter = mFilters.next();
4059 } 4061 }
4060 4062
4061 mDialogManager->showFilterEditDialog(&mFilters); 4063 mDialogManager->showFilterEditDialog(&mFilters);
4062 updateFilter(); 4064 updateFilter();
4063} 4065}
4064void CalendarView::toggleFilter() 4066void CalendarView::toggleFilter()
4065{ 4067{
4066 if ( mLeftFrame->isHidden() ) { 4068 if ( mLeftFrame->isHidden() ) {
4067 toggleExpand(); 4069 toggleExpand();
4068 showFilter( true ); 4070 showFilter( true );
4069 } else 4071 } else
4070 showFilter(! mCalEditView->isVisible()); 4072 showFilter(! mCalEditView->isVisible());
4071} 4073}
4072 4074
4073KOFilterView *CalendarView::filterView() 4075KOFilterView *CalendarView::filterView()
4074{ 4076{
4075 return mFilterView; 4077 return mFilterView;
4076} 4078}
4077void CalendarView::selectFilter( int fil ) 4079void CalendarView::selectFilter( int fil )
4078{ 4080{
4079 mFilterView->setSelectedFilter( fil ); 4081 mFilterView->setSelectedFilter( fil );
4080 updateUnmanagedViews(); 4082 updateUnmanagedViews();
4081} 4083}
4082void CalendarView::showFilter(bool visible) 4084void CalendarView::showFilter(bool visible)
4083{ 4085{
4084#if 1 4086#if 1
4085 if (visible) { 4087 if (visible) {
4086 mCalEditView->readConfig(); 4088 mCalEditView->readConfig();
4087 mCalEditView->show(); 4089 mCalEditView->show();
4088 QValueList<int> sizes; 4090 QValueList<int> sizes;
4089 sizes = mLeftFrame->sizes(); 4091 sizes = mLeftFrame->sizes();
4090 if ( sizes.count() == 4 && sizes[3] < 20 ) { 4092 if ( sizes.count() == 4 && sizes[3] < 20 ) {
4091 sizes.clear(); 4093 sizes.clear();
4092 sizes << 100; 4094 sizes << 100;
4093 sizes << 0; 4095 sizes << 0;
4094 sizes << 0; 4096 sizes << 0;
4095 sizes << 100; 4097 sizes << 100;
4096 mLeftFrame->setSizes(sizes); 4098 mLeftFrame->setSizes(sizes);
4097 } 4099 }
4098#if 0 4100#if 0
4099 sizes = mLeftFrame->sizes(); 4101 sizes = mLeftFrame->sizes();
4100 int ccc = 0; 4102 int ccc = 0;
4101 while ( ccc < sizes.count()) { 4103 while ( ccc < sizes.count()) {
4102 qDebug("size %d %d ", ccc, sizes[ccc]); 4104 qDebug("size %d %d ", ccc, sizes[ccc]);
4103 ++ccc; 4105 ++ccc;
4104 } 4106 }
4105#endif 4107#endif
4106 4108
4107 } 4109 }
4108 else { 4110 else {
4109 mCalEditView->hide(); 4111 mCalEditView->hide();
4110 } 4112 }
4111#else 4113#else
4112 if (visible) mFilterView->show(); 4114 if (visible) mFilterView->show();
4113 else mFilterView->hide(); 4115 else mFilterView->hide();
4114#endif 4116#endif
4115} 4117}
4116void CalendarView::toggleFilerEnabled( ) 4118void CalendarView::toggleFilerEnabled( )
4117{ 4119{
4118 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 4120 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
4119 if ( !mFilterView->filtersEnabled() ) 4121 if ( !mFilterView->filtersEnabled() )
4120 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 4122 topLevelWidget()->setCaption( i18n("Filter disabled ") );
4121 updateUnmanagedViews(); 4123 updateUnmanagedViews();
4122 4124
4123} 4125}
4124void CalendarView::updateFilter() 4126void CalendarView::updateFilter()
4125{ 4127{
4126 CalFilter *filter = mFilterView->selectedFilter(); 4128 CalFilter *filter = mFilterView->selectedFilter();
4127 if (filter) { 4129 if (filter) {
4128 QString mess; 4130 QString mess;
4129 if (mFilterView->filtersEnabled()) { 4131 if (mFilterView->filtersEnabled()) {
4130 mess = i18n("Filter selected: ")+filter->name(); 4132 mess = i18n("Filter selected: ")+filter->name();
4131 filter->setEnabled(true); 4133 filter->setEnabled(true);
4132 } 4134 }
4133 else filter->setEnabled(false); 4135 else filter->setEnabled(false);
4134 mCalendar->setFilter(filter); 4136 mCalendar->setFilter(filter);
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index ca8d5f7..3c38f34 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -1,283 +1,289 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24// 24//
25// Journal Entry 25// Journal Entry
26 26
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qvbox.h> 29#include <qvbox.h>
30#include <qfile.h> 30#include <qfile.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qtextcodec.h> 33#include <qtextcodec.h>
34#include <qpixmap.h> 34#include <qpixmap.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qapplication.h> 36#include <qapplication.h>
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <kglobal.h> 39#include <kglobal.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <ktextedit.h> 41#include <ktextedit.h>
42#include <kfiledialog.h> 42#include <kfiledialog.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44#include "koprefs.h" 44#include "koprefs.h"
45#include <klineedit.h> 45#include <klineedit.h>
46 46
47#include <libkcal/journal.h> 47#include <libkcal/journal.h>
48#include <libkcal/calendarresources.h> 48#include <libkcal/calendarresources.h>
49#include <libkcal/resourcecalendar.h> 49#include <libkcal/resourcecalendar.h>
50#include <kresources/resourceselectdialog.h> 50#include <kresources/resourceselectdialog.h>
51 51
52#include "journalentry.h" 52#include "journalentry.h"
53//#include "journalentry.moc" 53//#include "journalentry.moc"
54#ifndef DESKTOP_VERSION 54#ifndef DESKTOP_VERSION
55#include <qpe/qpeapplication.h> 55#include <qpe/qpeapplication.h>
56#endif 56#endif
57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
58 QFrame(parent) 58 QFrame(parent)
59{ 59{
60 heiHint = QApplication::desktop()->height() / 5 ; 60
61 int fac = 5;
62 heiHint = QApplication::desktop()->height();
63 if ( heiHint > 800 )
64 fac += 2;
65 heiHint = heiHint / fac;
66
61 showOnlyMode = false; 67 showOnlyMode = false;
62 mCalendar = calendar; 68 mCalendar = calendar;
63 mJournal = 0; 69 mJournal = 0;
64 visibleMode = true; 70 visibleMode = true;
65 QHBox * vb = new QHBox ( this ); 71 QHBox * vb = new QHBox ( this );
66 QPixmap iconp; 72 QPixmap iconp;
67 73
68 QPushButton * toggleJournal = new QPushButton( vb ); 74 QPushButton * toggleJournal = new QPushButton( vb );
69 iconp = SmallIcon("1updownarrow"); 75 iconp = SmallIcon("1updownarrow");
70 toggleJournal->setPixmap (iconp ) ; 76 toggleJournal->setPixmap (iconp ) ;
71 new QLabel(" "+i18n("Title: "),vb); 77 new QLabel(" "+i18n("Title: "),vb);
72 mTitle = new KLineEdit ( vb ); 78 mTitle = new KLineEdit ( vb );
73 mTitleLabel = new QLabel(i18n("Title"),vb); 79 mTitleLabel = new QLabel(i18n("Title"),vb);
74 mTitleLabel->setMargin(0); 80 mTitleLabel->setMargin(0);
75 mTitleLabel->setAlignment(AlignCenter); 81 mTitleLabel->setAlignment(AlignCenter);
76 QPushButton * loadTemplate = new QPushButton( vb ); 82 QPushButton * loadTemplate = new QPushButton( vb );
77 QPushButton * saveTemplate = new QPushButton( vb ); 83 QPushButton * saveTemplate = new QPushButton( vb );
78 if ( QApplication::desktop()->width() < 321 ) 84 if ( QApplication::desktop()->width() < 321 )
79 iconp = SmallIcon("fileexport16"); 85 iconp = SmallIcon("fileexport16");
80 else 86 else
81 iconp = SmallIcon("fileexport"); 87 iconp = SmallIcon("fileexport");
82 saveTemplate->setPixmap (iconp ) ; 88 saveTemplate->setPixmap (iconp ) ;
83 int size = saveTemplate->sizeHint().height(); 89 int size = saveTemplate->sizeHint().height();
84 if ( QApplication::desktop()->width() < 321 ) 90 if ( QApplication::desktop()->width() < 321 )
85 iconp = SmallIcon("fileimport16"); 91 iconp = SmallIcon("fileimport16");
86 else 92 else
87 iconp = SmallIcon("fileimport"); 93 iconp = SmallIcon("fileimport");
88 loadTemplate->setPixmap (iconp ) ; 94 loadTemplate->setPixmap (iconp ) ;
89 loadTemplate->setFixedSize( size, size ); 95 loadTemplate->setFixedSize( size, size );
90 saveTemplate->setFixedSize( size, size ); 96 saveTemplate->setFixedSize( size, size );
91 toggleJournal->setFixedSize( size , size ); 97 toggleJournal->setFixedSize( size , size );
92 mEditor = new KTextEdit(this); 98 mEditor = new KTextEdit(this);
93#ifndef DESKTOP_VERSION 99#ifndef DESKTOP_VERSION
94 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 100 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
95#endif 101#endif
96 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 102 mEditor->setWordWrap( KTextEdit::WidgetWidth );
97 QBoxLayout *topLayout = new QVBoxLayout(this); 103 QBoxLayout *topLayout = new QVBoxLayout(this);
98 topLayout->addWidget(vb); 104 topLayout->addWidget(vb);
99 topLayout->addWidget(mEditor); 105 topLayout->addWidget(mEditor);
100 mEditor->installEventFilter(this); 106 mEditor->installEventFilter(this);
101 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 107 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
102 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 108 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
103 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 109 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
104} 110}
105 111
106JournalEntry::~JournalEntry() 112JournalEntry::~JournalEntry()
107{ 113{
108 //qDebug("JournalEntry::~JournalEntry() "); 114 //qDebug("JournalEntry::~JournalEntry() ");
109} 115}
110QSize JournalEntry::sizeHint() const 116QSize JournalEntry::sizeHint() const
111{ 117{
112 return QSize ( 240, heiHint ); 118 return QSize ( 240, heiHint );
113} 119}
114void JournalEntry::slotSaveTemplate() 120void JournalEntry::slotSaveTemplate()
115{ 121{
116 QString fileName =locateLocal( "templates", "journals" ); 122 QString fileName =locateLocal( "templates", "journals" );
117 QDir t_dir; 123 QDir t_dir;
118 if ( !t_dir.exists(fileName) ) 124 if ( !t_dir.exists(fileName) )
119 t_dir.mkdir ( fileName ); 125 t_dir.mkdir ( fileName );
120 fileName += "/journal"; 126 fileName += "/journal";
121 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); 127 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this );
122 if ( fileName.length() == 0 ) 128 if ( fileName.length() == 0 )
123 return; 129 return;
124 130
125 QFile fileIn( fileName ); 131 QFile fileIn( fileName );
126 if (!fileIn.open( IO_WriteOnly ) ) { 132 if (!fileIn.open( IO_WriteOnly ) ) {
127 KMessageBox::error( this, i18n("Error saving template file\n '%1'.") 133 KMessageBox::error( this, i18n("Error saving template file\n '%1'.")
128 .arg( fileName ) ); 134 .arg( fileName ) );
129 return; 135 return;
130 } 136 }
131 // QString text; 137 // QString text;
132 QTextStream tsIn( &fileIn ); 138 QTextStream tsIn( &fileIn );
133 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 139 tsIn.setCodec( QTextCodec::codecForName("utf8") );
134 tsIn << mEditor->text(); 140 tsIn << mEditor->text();
135 fileIn.close(); 141 fileIn.close();
136} 142}
137void JournalEntry::slotLoadTemplate() 143void JournalEntry::slotLoadTemplate()
138{ 144{
139 QString fileName =locateLocal( "templates", "journals" ); 145 QString fileName =locateLocal( "templates", "journals" );
140 QDir t_dir; 146 QDir t_dir;
141 if ( !t_dir.exists(fileName) ) 147 if ( !t_dir.exists(fileName) )
142 t_dir.mkdir ( fileName ); 148 t_dir.mkdir ( fileName );
143 fileName += "/journal"; 149 fileName += "/journal";
144 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 150 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
145 if ( fileName.length() == 0 ) 151 if ( fileName.length() == 0 )
146 return; 152 return;
147 QFile fileIn( fileName ); 153 QFile fileIn( fileName );
148 if (!fileIn.open( IO_ReadOnly ) ) { 154 if (!fileIn.open( IO_ReadOnly ) ) {
149 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 155 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
150 .arg( fileName ) ); 156 .arg( fileName ) );
151 return; 157 return;
152 } 158 }
153 QTextStream tsIn( &fileIn ); 159 QTextStream tsIn( &fileIn );
154 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 160 tsIn.setCodec( QTextCodec::codecForName("utf8") );
155 QString text = tsIn.read(); 161 QString text = tsIn.read();
156 fileIn.close(); 162 fileIn.close();
157 int line, col; 163 int line, col;
158 mEditor->getCursorPosition (& line, & col ); 164 mEditor->getCursorPosition (& line, & col );
159 mEditor-> insertAt ( text, line, col, true ); 165 mEditor-> insertAt ( text, line, col, true );
160 //mEditor->setIgnoreMark( true ); 166 //mEditor->setIgnoreMark( true );
161} 167}
162void JournalEntry::setDate(const QDate &date) 168void JournalEntry::setDate(const QDate &date)
163{ 169{
164 showOnlyMode = false; 170 showOnlyMode = false;
165 writeJournal(); 171 writeJournal();
166 mDate = date; 172 mDate = date;
167 int id = mCalendar->defaultCalendar(); 173 int id = mCalendar->defaultCalendar();
168 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 174 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
169 mTitleLabel->setText( " (" + calname +")"); 175 mTitleLabel->setText( " (" + calname +")");
170} 176}
171 177
172void JournalEntry::toggleShowJournal() 178void JournalEntry::toggleShowJournal()
173{ 179{
174 if (!mEditor->text().isEmpty() || !mTitle->text().isEmpty()) 180 if (!mEditor->text().isEmpty() || !mTitle->text().isEmpty())
175 flushEntry(); 181 flushEntry();
176 if ( showOnlyMode ) 182 if ( showOnlyMode )
177 emit showJournalOnly( 0 ); 183 emit showJournalOnly( 0 );
178 else { 184 else {
179 // we have to protect mJournal from deleting if mJournal has empty text 185 // we have to protect mJournal from deleting if mJournal has empty text
180 visibleMode = false; // set to true via :setShowOnly() 186 visibleMode = false; // set to true via :setShowOnly()
181 emit showJournalOnly( mJournal ); 187 emit showJournalOnly( mJournal );
182 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) ); 188 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) );
183 } 189 }
184} 190}
185void JournalEntry::setVisibleOn() 191void JournalEntry::setVisibleOn()
186{ 192{
187 visibleMode = true; 193 visibleMode = true;
188} 194}
189void JournalEntry::setShowOnly() 195void JournalEntry::setShowOnly()
190{ 196{
191 showOnlyMode = true; 197 showOnlyMode = true;
192 if ( mTitle->text().isEmpty() ) 198 if ( mTitle->text().isEmpty() )
193 mTitle->setFocus(); 199 mTitle->setFocus();
194 else 200 else
195 mEditor->setFocus(); 201 mEditor->setFocus();
196} 202}
197void JournalEntry::setJournal(Journal *journal) 203void JournalEntry::setJournal(Journal *journal)
198{ 204{
199 writeJournal(); 205 writeJournal();
200 206
201 mJournal = journal; 207 mJournal = journal;
202 if ( journal->isReadOnly() ) 208 if ( journal->isReadOnly() )
203 mTitle->setText(mJournal->summary()+" ("+i18n("readonly")+")"); 209 mTitle->setText(mJournal->summary()+" ("+i18n("readonly")+")");
204 else 210 else
205 mTitle->setText(mJournal->summary()); 211 mTitle->setText(mJournal->summary());
206 mEditor->setText(mJournal->description()); 212 mEditor->setText(mJournal->description());
207 mTitle->setReadOnly (journal->isReadOnly() ); 213 mTitle->setReadOnly (journal->isReadOnly() );
208 mEditor->setReadOnly ( journal->isReadOnly() ); 214 mEditor->setReadOnly ( journal->isReadOnly() );
209 int id = mJournal->calID(); 215 int id = mJournal->calID();
210 216
211 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 217 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
212 mTitleLabel->setText( " (" + calname +")"); 218 mTitleLabel->setText( " (" + calname +")");
213 219
214} 220}
215 221
216Journal *JournalEntry::journal() const 222Journal *JournalEntry::journal() const
217{ 223{
218 return mJournal; 224 return mJournal;
219} 225}
220 226
221 227
222void JournalEntry::clear() 228void JournalEntry::clear()
223{ 229{
224 mJournal = 0; 230 mJournal = 0;
225 mEditor->setText(""); 231 mEditor->setText("");
226 mTitle->setText(""); 232 mTitle->setText("");
227} 233}
228 234
229bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 235bool JournalEntry::eventFilter( QObject *o, QEvent *e )
230{ 236{
231// kdDebug() << "JournalEntry::event received " << e->type() << endl; 237// kdDebug() << "JournalEntry::event received " << e->type() << endl;
232 238
233 if ( e->type() == QEvent::FocusOut ) { 239 if ( e->type() == QEvent::FocusOut ) {
234 writeJournal(); 240 writeJournal();
235 } 241 }
236 if ( e->type() == QEvent::KeyPress ) { 242 if ( e->type() == QEvent::KeyPress ) {
237 QKeyEvent * k = (QKeyEvent *) e; 243 QKeyEvent * k = (QKeyEvent *) e;
238 if ( k->state() == Qt::ControlButton ) { 244 if ( k->state() == Qt::ControlButton ) {
239 k->ignore(); 245 k->ignore();
240 //return true; 246 //return true;
241 } 247 }
242 } 248 }
243 249
244 return QFrame::eventFilter( o, e ); // standard event processing 250 return QFrame::eventFilter( o, e ); // standard event processing
245} 251}
246 252
247void JournalEntry::writeJournal() 253void JournalEntry::writeJournal()
248{ 254{
249 if ( !visibleMode ) return; 255 if ( !visibleMode ) return;
250 if (mEditor->text().isEmpty() && mTitle->text().isEmpty()) { 256 if (mEditor->text().isEmpty() && mTitle->text().isEmpty()) {
251 if ( mJournal ) { 257 if ( mJournal ) {
252 Journal* j = mJournal; 258 Journal* j = mJournal;
253 mJournal = 0; 259 mJournal = 0;
254 bool conf = KOPrefs::instance()->mConfirm; 260 bool conf = KOPrefs::instance()->mConfirm;
255 KOPrefs::instance()->mConfirm = false; 261 KOPrefs::instance()->mConfirm = false;
256 emit deleteJournal(j); 262 emit deleteJournal(j);
257 KOPrefs::instance()->mConfirm = conf; 263 KOPrefs::instance()->mConfirm = conf;
258 } 264 }
259 return; 265 return;
260 } 266 }
261 267
262// kdDebug() << "JournalEntry::writeJournal()..." << endl; 268// kdDebug() << "JournalEntry::writeJournal()..." << endl;
263 269
264 if (!mJournal) { 270 if (!mJournal) {
265 mJournal = new Journal; 271 mJournal = new Journal;
266 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 272 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
267 mCalendar->addJournal(mJournal); 273 mCalendar->addJournal(mJournal);
268 } 274 }
269 if ( mJournal->description() != mEditor->text() ) 275 if ( mJournal->description() != mEditor->text() )
270 mJournal->setDescription(mEditor->text()); 276 mJournal->setDescription(mEditor->text());
271 if ( mJournal->summary() != mTitle->text() ) 277 if ( mJournal->summary() != mTitle->text() )
272 mJournal->setSummary(mTitle->text()); 278 mJournal->setSummary(mTitle->text());
273} 279}
274 280
275void JournalEntry::flushEntry() 281void JournalEntry::flushEntry()
276{ 282{
277 writeJournal(); 283 writeJournal();
278} 284}
279void JournalEntry::keyPressEvent ( QKeyEvent * e ) 285void JournalEntry::keyPressEvent ( QKeyEvent * e )
280{ 286{
281 e->ignore(); 287 e->ignore();
282 288
283} 289}
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 067c34c..ec1154a 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,1216 +1,1217 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program 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 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) 106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 )
107 107
108 108
109{ 109{
110 mLastView = -1; 110 mLastView = -1;
111 oldW = 0; 111 oldW = 0;
112 oldH = 0; 112 oldH = 0;
113 myPix.resize( 150, 120 ); 113 myPix.resize( 150, 120 );
114 mRedrawNeeded = true; 114 mRedrawNeeded = true;
115 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 115 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
116 mPendingUpdateBeforeRepaint = false; 116 mPendingUpdateBeforeRepaint = false;
117 mouseDown = false; 117 mouseDown = false;
118 // initialize dynamic arrays 118 // initialize dynamic arrays
119 bDays.resize ( NUMDAYS ); 119 bDays.resize ( NUMDAYS );
120 pDays.resize ( NUMDAYS ); 120 pDays.resize ( NUMDAYS );
121 hDays.resize ( NUMDAYS ); 121 hDays.resize ( NUMDAYS );
122 eDays.resize ( NUMDAYS ); 122 eDays.resize ( NUMDAYS );
123 days = new QDate[NUMDAYS]; 123 days = new QDate[NUMDAYS];
124 daylbls = new QString[NUMDAYS]; 124 daylbls = new QString[NUMDAYS];
125 //events = new int[NUMDAYS]; 125 //events = new int[NUMDAYS];
126 mToolTip = new DynamicTip(this); 126 mToolTip = new DynamicTip(this);
127 127
128 // set default values used for drawing the matrix 128 // set default values used for drawing the matrix
129 mDefaultBackColor = palette().active().base(); 129 mDefaultBackColor = palette().active().base();
130 mDefaultTextColor = palette().active().foreground(); 130 mDefaultTextColor = palette().active().foreground();
131 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 131 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
132 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 132 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
133 mSelectedDaysColor = QColor("white"); 133 mSelectedDaysColor = QColor("white");
134 mTodayMarginWidth = 2; 134 mTodayMarginWidth = 2;
135 mSelEnd = mSelStart = NOSELECTION; 135 mSelEnd = mSelStart = NOSELECTION;
136 136
137 setAcceptDrops(true); 137 setAcceptDrops(true);
138 //setFont( QFont("Arial", 10) ); 138 //setFont( QFont("Arial", 10) );
139 139
140 mUpdateTimer = new QTimer( this ); 140 mUpdateTimer = new QTimer( this );
141 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 141 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
142 mRepaintTimer = new QTimer( this ); 142 mRepaintTimer = new QTimer( this );
143 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 143 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
144 mDayChanged = false; 144 mDayChanged = false;
145 updateView(); 145 updateView();
146} 146}
147QString KODayMatrix::getWhatsThisText( QPoint p ) 147QString KODayMatrix::getWhatsThisText( QPoint p )
148{ 148{
149 149
150 int tmp = getDayIndexFrom(p.x(), p.y()); 150 int tmp = getDayIndexFrom(p.x(), p.y());
151 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 151 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
152 return QString(); 152 return QString();
153 QDate mDate = days[tmp]; 153 QDate mDate = days[tmp];
154 QPtrList<Event> eventlist = mCalendar->events(mDate); 154 QPtrList<Event> eventlist = mCalendar->events(mDate);
155 Event *event; 155 Event *event;
156 QStringList mToolTip; 156 QStringList mToolTip;
157 for(event=eventlist.first();event != 0;event=eventlist.next()) { 157 for(event=eventlist.first();event != 0;event=eventlist.next()) {
158 QString mToolTipText; 158 QString mToolTipText;
159 QString text; 159 QString text;
160 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 160 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
161 if (event->isMultiDay()) { 161 if (event->isMultiDay()) {
162 QString prefix = "<->";multiday = 2; 162 QString prefix = "<->";multiday = 2;
163 QString time; 163 QString time;
164 if ( event->doesRecur() ) { 164 if ( event->doesRecur() ) {
165 if ( event->recursOn( mDate) ) { 165 if ( event->recursOn( mDate) ) {
166 prefix ="->" ;multiday = 1; 166 prefix ="->" ;multiday = 1;
167 } 167 }
168 else { 168 else {
169 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 169 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
170 if ( event->recursOn( mDate.addDays( -days)) ) { 170 if ( event->recursOn( mDate.addDays( -days)) ) {
171 prefix ="<-" ;multiday = 3; 171 prefix ="<-" ;multiday = 3;
172 } 172 }
173 } 173 }
174 } else { 174 } else {
175 if (mDate == event->dtStart().date()) { 175 if (mDate == event->dtStart().date()) {
176 prefix ="->" ;multiday = 1; 176 prefix ="->" ;multiday = 1;
177 } else if (mDate == event->dtEnd().date()) { 177 } else if (mDate == event->dtEnd().date()) {
178 prefix ="<-" ;multiday = 3; 178 prefix ="<-" ;multiday = 3;
179 } 179 }
180 } 180 }
181 if ( !event->doesFloat() ) { 181 if ( !event->doesFloat() ) {
182 if ( mDate == event->dtStart().date () ) 182 if ( mDate == event->dtStart().date () )
183 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 183 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
184 else if ( mDate == event->dtEnd().date () ) 184 else if ( mDate == event->dtEnd().date () )
185 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 185 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
186 186
187 } 187 }
188 text = time + event->summary(); 188 text = time + event->summary();
189 mToolTipText += prefix + text; 189 mToolTipText += prefix + text;
190 } else { 190 } else {
191 if (event->doesFloat()) { 191 if (event->doesFloat()) {
192 text = event->summary(); 192 text = event->summary();
193 mToolTipText += text; 193 mToolTipText += text;
194 } 194 }
195 else { 195 else {
196 text = KGlobal::locale()->formatTime(event->dtStart().time()); 196 text = KGlobal::locale()->formatTime(event->dtStart().time());
197 text += " " + event->summary(); 197 text += " " + event->summary();
198 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 198 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
199 } 199 }
200 } 200 }
201 if ( !event->location().isEmpty() ) 201 if ( !event->location().isEmpty() )
202 mToolTipText += " (" + event->location() + ")"; 202 mToolTipText += " (" + event->location() + ")";
203 //qDebug("TTT: %s ", mToolTipText.latin1()); 203 //qDebug("TTT: %s ", mToolTipText.latin1());
204 mToolTip.append( deTag( mToolTipText ) ); 204 mToolTip.append( deTag( mToolTipText ) );
205 } 205 }
206 mToolTip.sort(); 206 mToolTip.sort();
207 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { 207 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
208 QPtrList<Todo> todolist = mCalendar->todos(mDate); 208 QPtrList<Todo> todolist = mCalendar->todos(mDate);
209 Todo *todo; 209 Todo *todo;
210 for(todo=todolist.first();todo != 0;todo=todolist.next()) { 210 for(todo=todolist.first();todo != 0;todo=todolist.next()) {
211 QString mToolTipText; 211 QString mToolTipText;
212 if ( !todo->doesFloat() ) 212 if ( !todo->doesFloat() )
213 mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; 213 mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" ";
214 mToolTipText += todo->summary(); 214 mToolTipText += todo->summary();
215 if ( !todo->location().isEmpty() ) 215 if ( !todo->location().isEmpty() )
216 mToolTipText += " (" + todo->location() + ")"; 216 mToolTipText += " (" + todo->location() + ")";
217 mToolTipText = deTag( mToolTipText); 217 mToolTipText = deTag( mToolTipText);
218 mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; 218 mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText;
219 mToolTip.append( mToolTipText ); 219 mToolTip.append( mToolTipText );
220 } 220 }
221 } 221 }
222 if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { 222 if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
223 QPtrList<Journal> j_list = mCalendar->journals4Date( mDate ); 223 QPtrList<Journal> j_list = mCalendar->journals4Date( mDate );
224 Journal *j = j_list.first(); 224 Journal *j = j_list.first();
225 while ( j ) { 225 while ( j ) {
226 QString mToolTipText; 226 QString mToolTipText;
227 if ( !j->summary().isEmpty() ) { 227 if ( !j->summary().isEmpty() ) {
228 mToolTipText = j->summary().left(30); 228 mToolTipText = j->summary().left(30);
229 if ( j->summary().length() > 30 ) 229 if ( j->summary().length() > 30 )
230 mToolTipText += " ..."; 230 mToolTipText += " ...";
231 } else { 231 } else {
232 mToolTipText = j->description().left(25); 232 mToolTipText = j->description().left(25);
233 if ( j->description().length() > 25 ) 233 if ( j->description().length() > 25 )
234 mToolTipText += " ..."; 234 mToolTipText += " ...";
235 mToolTipText = deTag( mToolTipText); 235 mToolTipText = deTag( mToolTipText);
236 } 236 }
237 mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; 237 mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText;
238 mToolTip.append( mToolTipText ); 238 mToolTip.append( mToolTipText );
239 j = j_list.next(); 239 j = j_list.next();
240 } 240 }
241 } 241 }
242 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 242 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
243} 243}
244 244
245 245
246QString KODayMatrix::deTag( QString mToolTipText ) 246QString KODayMatrix::deTag( QString mToolTipText )
247{ 247{
248 248
249#if QT_VERSION >= 0x030000 249#if QT_VERSION >= 0x030000
250 mToolTipText.replace( '<' , "&lt;" ); 250 mToolTipText.replace( '<' , "&lt;" );
251 mToolTipText.replace( '>' , "&gt;" ); 251 mToolTipText.replace( '>' , "&gt;" );
252#else 252#else
253 if ( mToolTipText.find ('<') >= 0 ) { 253 if ( mToolTipText.find ('<') >= 0 ) {
254 mToolTipText.replace( QRegExp("<") , "&lt;" ); 254 mToolTipText.replace( QRegExp("<") , "&lt;" );
255 } 255 }
256 if ( mToolTipText.find ('>') >= 0 ) { 256 if ( mToolTipText.find ('>') >= 0 ) {
257 mToolTipText.replace( QRegExp(">") , "&gt;" ); 257 mToolTipText.replace( QRegExp(">") , "&gt;" );
258 } 258 }
259#endif 259#endif
260 return mToolTipText; 260 return mToolTipText;
261} 261}
262void KODayMatrix::setCalendar( Calendar *cal ) 262void KODayMatrix::setCalendar( Calendar *cal )
263{ 263{
264 mCalendar = cal; 264 mCalendar = cal;
265 265
266 setAcceptDrops( mCalendar ); 266 setAcceptDrops( mCalendar );
267 267
268 updateEvents(); 268 updateEvents();
269} 269}
270 270
271QColor KODayMatrix::getShadedColor(QColor color) 271QColor KODayMatrix::getShadedColor(QColor color)
272{ 272{
273 QColor shaded; 273 QColor shaded;
274 int h=0; 274 int h=0;
275 int s=0; 275 int s=0;
276 int v=0; 276 int v=0;
277 color.hsv(&h,&s,&v); 277 color.hsv(&h,&s,&v);
278 s = s/4; 278 s = s/4;
279 v = 192+v/4; 279 v = 192+v/4;
280 shaded.setHsv(h,s,v); 280 shaded.setHsv(h,s,v);
281 281
282 return shaded; 282 return shaded;
283} 283}
284 284
285KODayMatrix::~KODayMatrix() 285KODayMatrix::~KODayMatrix()
286{ 286{
287#if QT_VERSION >= 0x030000 287#if QT_VERSION >= 0x030000
288 288
289#else 289#else
290 delete mKODaymatrixWhatsThis; 290 delete mKODaymatrixWhatsThis;
291#endif 291#endif
292 292
293 // delete mKODaymatrixWhatsThis; 293 // delete mKODaymatrixWhatsThis;
294 delete [] days; 294 delete [] days;
295 delete [] daylbls; 295 delete [] daylbls;
296 //delete [] events; 296 //delete [] events;
297 delete mToolTip; 297 delete mToolTip;
298} 298}
299 299
300/* 300/*
301void KODayMatrix::setStartDate(QDate start) 301void KODayMatrix::setStartDate(QDate start)
302{ 302{
303 updateView(start); 303 updateView(start);
304} 304}
305*/ 305*/
306 306
307void KODayMatrix::addSelectedDaysTo(DateList& selDays) 307void KODayMatrix::addSelectedDaysTo(DateList& selDays)
308{ 308{
309 309
310 if (mSelStart == NOSELECTION) { 310 if (mSelStart == NOSELECTION) {
311 return; 311 return;
312 } 312 }
313 313
314 //cope with selection being out of matrix limits at top (< 0) 314 //cope with selection being out of matrix limits at top (< 0)
315 int i0 = mSelStart; 315 int i0 = mSelStart;
316 if (i0 < 0) { 316 if (i0 < 0) {
317 for (int i = i0; i < 0; i++) { 317 for (int i = i0; i < 0; i++) {
318 selDays.append(days[0].addDays(i)); 318 selDays.append(days[0].addDays(i));
319 } 319 }
320 i0 = 0; 320 i0 = 0;
321 } 321 }
322 322
323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 323 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
324 if (mSelEnd > NUMDAYS-1) { 324 if (mSelEnd > NUMDAYS-1) {
325 for (int i = i0; i <= NUMDAYS-1; i++) { 325 for (int i = i0; i <= NUMDAYS-1; i++) {
326 selDays.append(days[i]); 326 selDays.append(days[i]);
327 } 327 }
328 for (int i = NUMDAYS; i < mSelEnd; i++) { 328 for (int i = NUMDAYS; i < mSelEnd; i++) {
329 selDays.append(days[0].addDays(i)); 329 selDays.append(days[0].addDays(i));
330 } 330 }
331 331
332 // apply normal routine to selection being entirely within matrix limits 332 // apply normal routine to selection being entirely within matrix limits
333 } else { 333 } else {
334 for (int i = i0; i <= mSelEnd; i++) { 334 for (int i = i0; i <= mSelEnd; i++) {
335 selDays.append(days[i]); 335 selDays.append(days[i]);
336 } 336 }
337 } 337 }
338} 338}
339 339
340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 340bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
341{ 341{
342 mRedrawNeeded = true; 342 mRedrawNeeded = true;
343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); 343 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
344 mSelStart = startdate.daysTo(start); 344 mSelStart = startdate.daysTo(start);
345 if ( mSelStart < 0 ) 345 if ( mSelStart < 0 )
346 mSelStart = 0; 346 mSelStart = 0;
347 mSelEnd = startdate.daysTo(end); 347 mSelEnd = startdate.daysTo(end);
348 if ( mSelEnd > NUMDAYS-1 ) 348 if ( mSelEnd > NUMDAYS-1 )
349 mSelEnd = NUMDAYS-1; 349 mSelEnd = NUMDAYS-1;
350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { 350 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
351 clearSelection(); 351 clearSelection();
352 if ( noSel ) 352 if ( noSel )
353 return false; 353 return false;
354 } 354 }
355 355
356 return true; 356 return true;
357} 357}
358void KODayMatrix::clearSelection() 358void KODayMatrix::clearSelection()
359{ 359{
360 mSelEnd = mSelStart = NOSELECTION; 360 mSelEnd = mSelStart = NOSELECTION;
361} 361}
362 362
363 363
364void KODayMatrix::recalculateToday() 364void KODayMatrix::recalculateToday()
365{ 365{
366 today = -1; 366 today = -1;
367 for (int i=0; i<NUMDAYS; i++) { 367 for (int i=0; i<NUMDAYS; i++) {
368 //events[i] = 0; 368 //events[i] = 0;
369 days[i] = startdate.addDays(i); 369 days[i] = startdate.addDays(i);
370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 370 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
371 371
372 // if today is in the currently displayed month, hilight today 372 // if today is in the currently displayed month, hilight today
373 if (days[i].year() == QDate::currentDate().year() && 373 if (days[i].year() == QDate::currentDate().year() &&
374 days[i].month() == QDate::currentDate().month() && 374 days[i].month() == QDate::currentDate().month() &&
375 days[i].day() == QDate::currentDate().day()) { 375 days[i].day() == QDate::currentDate().day()) {
376 today = i; 376 today = i;
377 } 377 }
378 } 378 }
379 // qDebug(QString("Today is visible at %1.").arg(today)); 379 // qDebug(QString("Today is visible at %1.").arg(today));
380} 380}
381 381
382void KODayMatrix::updateView() 382void KODayMatrix::updateView()
383{ 383{
384 updateView(startdate); 384 updateView(startdate);
385} 385}
386void KODayMatrix::repaintViewTimed() 386void KODayMatrix::repaintViewTimed()
387{ 387{
388 mRedrawNeeded = true; 388 mRedrawNeeded = true;
389 // bDays.fill( false); 389 // bDays.fill( false);
390 //pDays.fill( false); 390 //pDays.fill( false);
391 //hDays.fill( false); 391 //hDays.fill( false);
392 //eDays.fill( false); 392 //eDays.fill( false);
393 mRepaintTimer->stop(); 393 mRepaintTimer->stop();
394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 394 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
395 int i; 395 int i;
396 for(i = 0; i < NUMDAYS; i++) { 396 for(i = 0; i < NUMDAYS; i++) {
397 if ( ( (i+startDay) % 7 == 0 ) ) { 397 if ( ( (i+startDay) % 7 == 0 ) ) {
398 pDays.setBit(i); 398 pDays.setBit(i);
399 } 399 }
400 } 400 }
401 repaint(false); 401 repaint(false);
402} 402}
403void KODayMatrix::computeEvent(Event *event, int i ) 403void KODayMatrix::computeEvent(Event *event, int i )
404{ 404{
405 QString holiStr = mHolidays[i]; 405 QString holiStr = mHolidays[i];
406 if ( event->isHoliday()) { 406 if ( event->isHoliday()) {
407 pDays.setBit(i); 407 pDays.setBit(i);
408 hDays.setBit(i); 408 hDays.setBit(i);
409 if ( !holiStr.isEmpty() ) 409 if ( !holiStr.isEmpty() )
410 holiStr += "\n"; 410 holiStr += "\n";
411 holiStr += event->summary(); 411 holiStr += event->summary();
412 if ( !event->location().isEmpty() ) 412 if ( !event->location().isEmpty() )
413 holiStr += " (" + event->location() + ")"; 413 holiStr += " (" + event->location() + ")";
414 mHolidays[i] =holiStr ; 414 mHolidays[i] =holiStr ;
415 eDays.setBit(i); 415 eDays.setBit(i);
416 } 416 }
417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { 417 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) {
418 if ( event->isBirthday()) { 418 if ( event->isBirthday()) {
419 pDays.setBit(i); 419 pDays.setBit(i);
420 if ( !holiStr.isEmpty() ) 420 if ( !holiStr.isEmpty() )
421 holiStr += "\n"; 421 holiStr += "\n";
422 holiStr += i18n("Birthday") + ": "+event->summary(); 422 holiStr += i18n("Birthday") + ": "+event->summary();
423 if ( !event->location().isEmpty() ) 423 if ( !event->location().isEmpty() )
424 holiStr += " (" + event->location() + ")"; 424 holiStr += " (" + event->location() + ")";
425 bDays.setBit(i); 425 bDays.setBit(i);
426 mHolidays[i] =holiStr ; 426 mHolidays[i] =holiStr ;
427 } 427 }
428 } 428 }
429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) 429 if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW )
430 eDays.setBit(i); 430 eDays.setBit(i);
431} 431}
432void KODayMatrix::updateViewTimed() 432void KODayMatrix::updateViewTimed()
433{ 433{
434 mUpdateTimer->stop(); 434 mUpdateTimer->stop();
435 if ( !mCalendar ) { 435 if ( !mCalendar ) {
436 qDebug("NOT CAL "); 436 qDebug("NOT CAL ");
437 return; 437 return;
438 } 438 }
439#if 1 439#if 1
440 440
441 441
442 int i; 442 int i;
443 int timeSpan = NUMDAYS-1; 443 int timeSpan = NUMDAYS-1;
444 QPtrList<Event> events = mCalendar->events(); 444 QPtrList<Event> events = mCalendar->events();
445 Event *event; 445 Event *event;
446 QDateTime dt; 446 QDateTime dt;
447 bool ok; 447 bool ok;
448 bDays.fill( false); 448 bDays.fill( false);
449 pDays.fill( false); 449 pDays.fill( false);
450 hDays.fill( false); 450 hDays.fill( false);
451 eDays.fill( false); 451 eDays.fill( false);
452 mHolidays.clear(); 452 mHolidays.clear();
453 QDate mStartDate = days[0]; 453 QDate mStartDate = days[0];
454 QDate endDate = mStartDate.addDays( timeSpan ); 454 QDate endDate = mStartDate.addDays( timeSpan );
455 for( event = events.first(); event; event = events.next() ) { // for event 455 for( event = events.first(); event; event = events.next() ) { // for event
456 ushort recurType = event->recurrence()->doesRecur(); 456 ushort recurType = event->recurrence()->doesRecur();
457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 457 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 458 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
459 continue; 459 continue;
460 } 460 }
461 if ( event->doesRecur() ) { 461 if ( event->doesRecur() ) {
462 bool last; 462 bool last;
463 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 463 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
464 QDateTime incidenceEnd; 464 QDateTime incidenceEnd;
465 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 465 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
466 bool invalid = false; 466 bool invalid = false;
467 while( true ) { 467 while( true ) {
468 if ( incidenceStart.isValid() ) { 468 if ( incidenceStart.isValid() ) {
469 incidenceEnd = incidenceStart.addDays( eventlen ); 469 incidenceEnd = incidenceStart.addDays( eventlen );
470 int st = incidenceStart.date().daysTo( endDate ); 470 int st = incidenceStart.date().daysTo( endDate );
471 if ( st >= 0 ) { // start before timeend 471 if ( st >= 0 ) { // start before timeend
472 int end = mStartDate.daysTo( incidenceEnd.date() ); 472 int end = mStartDate.daysTo( incidenceEnd.date() );
473 if ( end >= 0 ) { // end after timestart --- got one! 473 if ( end >= 0 ) { // end after timestart --- got one!
474 //normalize 474 //normalize
475 st = timeSpan - st; 475 st = timeSpan - st;
476 if ( st < 0 ) st = 0; 476 if ( st < 0 ) st = 0;
477 if ( end > timeSpan ) end = timeSpan; 477 if ( end > timeSpan ) end = timeSpan;
478 int iii; 478 int iii;
479 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 479 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
480 for ( iii = st;iii<= end;++iii) { 480 for ( iii = st;iii<= end;++iii) {
481 computeEvent( event, iii ); 481 computeEvent( event, iii );
482 } 482 }
483 } 483 }
484 } 484 }
485 } else { 485 } else {
486 if ( invalid ) 486 if ( invalid )
487 break; 487 break;
488 invalid = true; 488 invalid = true;
489 //qDebug("invalid %s", event->summary().latin1()); 489 //qDebug("invalid %s", event->summary().latin1());
490 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 490 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
491 } 491 }
492 if ( last ) 492 if ( last )
493 break; 493 break;
494 bool ok; 494 bool ok;
495 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 495 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
496 if ( ! ok ) 496 if ( ! ok )
497 break; 497 break;
498 if ( incidenceStart.date() > endDate ) 498 if ( incidenceStart.date() > endDate )
499 break; 499 break;
500 } 500 }
501 } else { // no recur 501 } else { // no recur
502 int st = event->dtStart().date().daysTo( endDate ); 502 int st = event->dtStart().date().daysTo( endDate );
503 if ( st >= 0 ) { // start before timeend 503 if ( st >= 0 ) { // start before timeend
504 int end = mStartDate.daysTo( event->dtEnd().date() ); 504 int end = mStartDate.daysTo( event->dtEnd().date() );
505 if ( end >= 0 ) { // end after timestart --- got one! 505 if ( end >= 0 ) { // end after timestart --- got one!
506 //normalize 506 //normalize
507 st = timeSpan - st; 507 st = timeSpan - st;
508 if ( st < 0 ) st = 0; 508 if ( st < 0 ) st = 0;
509 if ( end > timeSpan ) end = timeSpan; 509 if ( end > timeSpan ) end = timeSpan;
510 int iii; 510 int iii;
511 for ( iii = st;iii<= end;++iii) 511 for ( iii = st;iii<= end;++iii)
512 computeEvent( event, iii ); 512 computeEvent( event, iii );
513 } 513 }
514 } 514 }
515 } 515 }
516 } 516 }
517 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday 517 int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday
518 for(i = 0; i < NUMDAYS; i++) { 518 for(i = 0; i < NUMDAYS; i++) {
519 if ( ( (i+startDay) % 7 == 0 ) ) { 519 if ( ( (i+startDay) % 7 == 0 ) ) {
520 pDays.setBit(i); 520 pDays.setBit(i);
521 } 521 }
522 } 522 }
523 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { 523 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) {
524 bDays.fill( false); 524 bDays.fill( false);
525 // insert due todos 525 // insert due todos
526 QPtrList<Todo> todos = mCalendar->todos( ); 526 QPtrList<Todo> todos = mCalendar->todos( );
527 Todo *todo; 527 Todo *todo;
528 for(todo = todos.first(); todo; todo = todos.next()) { 528 for(todo = todos.first(); todo; todo = todos.next()) {
529 //insertTodo( todo ); 529 //insertTodo( todo );
530 if ( todo->hasDueDate() ) { 530 if ( todo->hasDueDate() ) {
531 int day = mStartDate.daysTo( todo->dtDue().date() ); 531 int day = mStartDate.daysTo( todo->dtDue().date() );
532 if ( day >= 0 && day < timeSpan + 1) { 532 if ( day >= 0 && day < timeSpan + 1) {
533 int i = day; 533 int i = day;
534 QString holiStr = mHolidays[i]; 534 QString holiStr = mHolidays[i];
535 pDays.setBit(i); 535 pDays.setBit(i);
536 if ( !holiStr.isEmpty() ) 536 if ( !holiStr.isEmpty() )
537 holiStr += "\n"; 537 holiStr += "\n";
538 holiStr += i18n("Todo") + ": "+todo->summary(); 538 holiStr += i18n("Todo") + ": "+todo->summary();
539 if ( !todo->location().isEmpty() ) 539 if ( !todo->location().isEmpty() )
540 holiStr += " (" + todo->location() + ")"; 540 holiStr += " (" + todo->location() + ")";
541 bDays.setBit(i); 541 bDays.setBit(i);
542 mHolidays[i] =holiStr ; 542 mHolidays[i] =holiStr ;
543 eDays.setBit(i); 543 eDays.setBit(i);
544 } 544 }
545 } 545 }
546 } 546 }
547 } 547 }
548 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { 548 if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) {
549 bDays.fill( false); 549 bDays.fill( false);
550 // insert due todos 550 // insert due todos
551 QPtrList<Journal> todos = mCalendar->journals( ); 551 QPtrList<Journal> todos = mCalendar->journals( );
552 Journal *todo; 552 Journal *todo;
553 for(todo = todos.first(); todo; todo = todos.next()) { 553 for(todo = todos.first(); todo; todo = todos.next()) {
554 int day = mStartDate.daysTo( todo->dtStart().date() ); 554 int day = mStartDate.daysTo( todo->dtStart().date() );
555 if ( day >= 0 && day < timeSpan + 1) { 555 if ( day >= 0 && day < timeSpan + 1) {
556 int i = day; 556 int i = day;
557 QString holiStr = mHolidays[i]; 557 QString holiStr = mHolidays[i];
558 pDays.setBit(i); 558 pDays.setBit(i);
559 if ( !holiStr.isEmpty() ) 559 if ( !holiStr.isEmpty() )
560 holiStr += "\n"; 560 holiStr += "\n";
561 holiStr += i18n("Journal: ")+todo->summary().left(25); 561 holiStr += i18n("Journal: ")+todo->summary().left(25);
562 if ( todo->summary().length() > 25 ) 562 if ( todo->summary().length() > 25 )
563 holiStr +="..."; 563 holiStr +="...";
564 bDays.setBit(i); 564 bDays.setBit(i);
565 mHolidays[i] =holiStr ; 565 mHolidays[i] =holiStr ;
566 eDays.setBit(i); 566 eDays.setBit(i);
567 567
568 } 568 }
569 } 569 }
570 } 570 }
571#else 571#else
572 //qDebug("KODayMatrix::updateViewTimed "); 572 //qDebug("KODayMatrix::updateViewTimed ");
573 for(int i = 0; i < NUMDAYS; i++) { 573 for(int i = 0; i < NUMDAYS; i++) {
574 // if events are set for the day then remember to draw it bold 574 // if events are set for the day then remember to draw it bold
575 QPtrList<Event> eventlist = mCalendar->events(days[i]); 575 QPtrList<Event> eventlist = mCalendar->events(days[i]);
576 Event *event; 576 Event *event;
577 int numEvents = eventlist.count(); 577 int numEvents = eventlist.count();
578 QString holiStr = ""; 578 QString holiStr = "";
579 bDays.clearBit(i); 579 bDays.clearBit(i);
580 hDays.clearBit(i); 580 hDays.clearBit(i);
581 eDays.clearBit(i); 581 eDays.clearBit(i);
582 for(event=eventlist.first();event != 0;event=eventlist.next()) { 582 for(event=eventlist.first();event != 0;event=eventlist.next()) {
583 ushort recurType = event->recurrence()->doesRecur(); 583 ushort recurType = event->recurrence()->doesRecur();
584 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 584 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
585 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 585 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
586 numEvents--; 586 numEvents--;
587 } 587 }
588 if ( event->isHoliday()) { 588 if ( event->isHoliday()) {
589 hDays.setBit(i); 589 hDays.setBit(i);
590 if ( !holiStr.isEmpty() ) 590 if ( !holiStr.isEmpty() )
591 holiStr += "\n"; 591 holiStr += "\n";
592 holiStr += event->summary(); 592 holiStr += event->summary();
593 if ( !event->location().isEmpty() ) 593 if ( !event->location().isEmpty() )
594 holiStr += " (" + event->location() + ")"; 594 holiStr += " (" + event->location() + ")";
595 } 595 }
596 if ( event->isBirthday()) { 596 if ( event->isBirthday()) {
597 if ( !holiStr.isEmpty() ) 597 if ( !holiStr.isEmpty() )
598 holiStr += "\n"; 598 holiStr += "\n";
599 holiStr += i18n("Birthday") + ": "+event->summary(); 599 holiStr += i18n("Birthday") + ": "+event->summary();
600 if ( !event->location().isEmpty() ) 600 if ( !event->location().isEmpty() )
601 holiStr += " (" + event->location() + ")"; 601 holiStr += " (" + event->location() + ")";
602 bDays.setBit(i); 602 bDays.setBit(i);
603 } 603 }
604 } 604 }
605 if ( numEvents ) 605 if ( numEvents )
606 eDays.setBit(i); 606 eDays.setBit(i);
607 //if it is a holy day then draw it red. Sundays are consider holidays, too 607 //if it is a holy day then draw it red. Sundays are consider holidays, too
608 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 608 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
609 !holiStr.isEmpty()) { 609 !holiStr.isEmpty()) {
610 mHolidays[i] = holiStr; 610 mHolidays[i] = holiStr;
611 } else { 611 } else {
612 mHolidays[i] = QString::null; 612 mHolidays[i] = QString::null;
613 } 613 }
614 } 614 }
615#endif 615#endif
616 mRedrawNeeded = true; 616 mRedrawNeeded = true;
617 if ( ! mPendingUpdateBeforeRepaint ) 617 if ( ! mPendingUpdateBeforeRepaint )
618 repaint(false); 618 repaint(false);
619} 619}
620void KODayMatrix::updateView(QDate actdate) 620void KODayMatrix::updateView(QDate actdate)
621{ 621{
622 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) 622 if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView )
623 mRedrawNeeded = true; 623 mRedrawNeeded = true;
624 mLastView = KOPrefs::instance()->mCurrentDisplayedView; 624 mLastView = KOPrefs::instance()->mCurrentDisplayedView;
625 if ( ! actdate.isValid() ) { 625 if ( ! actdate.isValid() ) {
626 //qDebug("date not valid "); 626 //qDebug("date not valid ");
627 return; 627 return;
628 } 628 }
629 mDayChanged = false; 629 mDayChanged = false;
630 //flag to indicate if the starting day of the matrix has changed by this call 630 //flag to indicate if the starting day of the matrix has changed by this call
631 //mDayChanged = false; 631 //mDayChanged = false;
632 // if a new startdate is to be set then apply Cornelius's calculation 632 // if a new startdate is to be set then apply Cornelius's calculation
633 // of the first day to be shown 633 // of the first day to be shown
634 if (actdate != startdate) { 634 if (actdate != startdate) {
635 // reset index of selection according to shift of starting date from startdate to actdate 635 // reset index of selection according to shift of starting date from startdate to actdate
636 if (mSelStart != NOSELECTION) { 636 if (mSelStart != NOSELECTION) {
637 int tmp = actdate.daysTo(startdate); 637 int tmp = actdate.daysTo(startdate);
638 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 638 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
639 // shift selection if new one would be visible at least partly ! 639 // shift selection if new one would be visible at least partly !
640 640
641 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 641 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
642 // nested if is required for next X display pushed from a different month - correction required 642 // nested if is required for next X display pushed from a different month - correction required
643 // otherwise, for month forward and backward, it must be avoided 643 // otherwise, for month forward and backward, it must be avoided
644 if( mSelStart > NUMDAYS || mSelStart < 0 ) 644 if( mSelStart > NUMDAYS || mSelStart < 0 )
645 mSelStart = mSelStart + tmp; 645 mSelStart = mSelStart + tmp;
646 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 646 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
647 mSelEnd = mSelEnd + tmp; 647 mSelEnd = mSelEnd + tmp;
648 } 648 }
649 } 649 }
650 startdate = actdate; 650 startdate = actdate;
651 mDayChanged = true; 651 mDayChanged = true;
652 recalculateToday(); 652 recalculateToday();
653 mRedrawNeeded = true; 653 mRedrawNeeded = true;
654 } 654 }
655 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 655 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
656 if ( !isVisible() ) { 656 if ( !isVisible() ) {
657 mPendingUpdateBeforeRepaint = true; 657 mPendingUpdateBeforeRepaint = true;
658 } else { 658 } else {
659#ifdef DESKTOP_VERSION 659#ifdef DESKTOP_VERSION
660 //mRepaintTimer->start( 100 ); 660 //mRepaintTimer->start( 100 );
661 //updateViewTimed(); 661 //updateViewTimed();
662 mUpdateTimer->start( 50 ); 662 mUpdateTimer->start( 50 );
663#else 663#else
664 mRepaintTimer->start( 350 ); 664 mRepaintTimer->start( 350 );
665 mUpdateTimer->start( 800 ); 665 mUpdateTimer->start( 800 );
666#endif 666#endif
667 } 667 }
668} 668}
669void KODayMatrix::updateEvents() 669void KODayMatrix::updateEvents()
670{ 670{
671 if ( !mCalendar ) return; 671 if ( !mCalendar ) return;
672 672
673 for( int i = 0; i < NUMDAYS; i++ ) { 673 for( int i = 0; i < NUMDAYS; i++ ) {
674 // if events are set for the day then remember to draw it bold 674 // if events are set for the day then remember to draw it bold
675 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 675 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
676 int numEvents = eventlist.count(); 676 int numEvents = eventlist.count();
677 Event *event; 677 Event *event;
678 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 678 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
679 ushort recurType = event->doesRecur(); 679 ushort recurType = event->doesRecur();
680 680
681 if ( ( recurType == Recurrence::rDaily && 681 if ( ( recurType == Recurrence::rDaily &&
682 !KOPrefs::instance()->mDailyRecur ) || 682 !KOPrefs::instance()->mDailyRecur ) ||
683 ( recurType == Recurrence::rWeekly && 683 ( recurType == Recurrence::rWeekly &&
684 !KOPrefs::instance()->mWeeklyRecur ) ) { 684 !KOPrefs::instance()->mWeeklyRecur ) ) {
685 numEvents--; 685 numEvents--;
686 } 686 }
687 } 687 }
688 if ( numEvents ) 688 if ( numEvents )
689 eDays.setBit(i); 689 eDays.setBit(i);
690 else 690 else
691 eDays.clearBit(i); 691 eDays.clearBit(i);
692 } 692 }
693} 693}
694 694
695const QDate& KODayMatrix::getDate(int offset) 695const QDate& KODayMatrix::getDate(int offset)
696{ 696{
697 if (offset < 0 || offset > NUMDAYS-1) { 697 if (offset < 0 || offset > NUMDAYS-1) {
698 qDebug("Wrong offset2 %d", offset); 698 qDebug("Wrong offset2 %d", offset);
699 return days[0]; 699 return days[0];
700 } 700 }
701 return days[offset]; 701 return days[offset];
702} 702}
703 703
704QString KODayMatrix::getHolidayLabel(int offset) 704QString KODayMatrix::getHolidayLabel(int offset)
705{ 705{
706 if (offset < 0 || offset > NUMDAYS-1) { 706 if (offset < 0 || offset > NUMDAYS-1) {
707 qDebug("Wrong offset1 %d", offset); 707 qDebug("Wrong offset1 %d", offset);
708 return QString(); 708 return QString();
709 } 709 }
710 return mHolidays[offset]; 710 return mHolidays[offset];
711} 711}
712 712
713int KODayMatrix::getDayIndexFrom(int x, int y) 713int KODayMatrix::getDayIndexFrom(int x, int y)
714{ 714{
715 int colModulo = (width()-2) % 7; 715 int colModulo = (width()-2) % 7;
716 int rowModulo = (height()-2) % 6; 716 int rowModulo = (height()-2) % 6;
717#if 0 717#if 0
718 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 718 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
719 6 - x/daysize.width() : x/daysize.width()); 719 6 - x/daysize.width() : x/daysize.width());
720#endif 720#endif
721 int xVal = (x-colModulo/2-2)/daysize.width(); 721 int xVal = (x-colModulo/2-2)/daysize.width();
722 int yVal = (y-rowModulo/2-2)/daysize.height(); 722 int yVal = (y-rowModulo/2-2)/daysize.height();
723 723
724 724
725 return 7*(yVal) + xVal; 725 return 7*(yVal) + xVal;
726 726
727} 727}
728 728
729// ---------------------------------------------------------------------------- 729// ----------------------------------------------------------------------------
730// M O U S E E V E N T H A N D L I N G 730// M O U S E E V E N T H A N D L I N G
731// ---------------------------------------------------------------------------- 731// ----------------------------------------------------------------------------
732 732
733void KODayMatrix::mousePressEvent (QMouseEvent* e) 733void KODayMatrix::mousePressEvent (QMouseEvent* e)
734{ 734{
735 735
736 if ( e->button() == LeftButton ) 736 if ( e->button() == LeftButton )
737 mouseDown = true; 737 mouseDown = true;
738 mSelStart = getDayIndexFrom(e->x(), e->y()); 738 mSelStart = getDayIndexFrom(e->x(), e->y());
739 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 739 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
740 mSelInit = mSelStart; 740 mSelInit = mSelStart;
741 mSelEnd = mSelStart; 741 mSelEnd = mSelStart;
742 mRedrawNeeded = true; 742 mRedrawNeeded = true;
743 repaint(false); 743 repaint(false);
744} 744}
745 745
746void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 746void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
747{ 747{
748 mRedrawNeeded = true; 748 mRedrawNeeded = true;
749 if ( e->button() == LeftButton ) 749 if ( e->button() == LeftButton )
750 if ( ! mouseDown ) { 750 if ( ! mouseDown ) {
751 return; 751 return;
752 } 752 }
753 else 753 else
754 mouseDown = false; 754 mouseDown = false;
755 int tmp = getDayIndexFrom(e->x(), e->y()); 755 int tmp = getDayIndexFrom(e->x(), e->y());
756 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 756 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
757 757
758 if (mSelInit > tmp) { 758 if (mSelInit > tmp) {
759 mSelEnd = mSelInit; 759 mSelEnd = mSelInit;
760 if (tmp != mSelStart) { 760 if (tmp != mSelStart) {
761 mSelStart = tmp; 761 mSelStart = tmp;
762 repaint(false); 762 repaint(false);
763 } 763 }
764 } else { 764 } else {
765 mSelStart = mSelInit; 765 mSelStart = mSelInit;
766 766
767 //repaint only if selection has changed 767 //repaint only if selection has changed
768 if (tmp != mSelEnd) { 768 if (tmp != mSelEnd) {
769 mSelEnd = tmp; 769 mSelEnd = tmp;
770 repaint(false); 770 repaint(false);
771 } 771 }
772 } 772 }
773 773
774 DateList daylist; 774 DateList daylist;
775 if ( mSelStart < 0 ) 775 if ( mSelStart < 0 )
776 mSelStart = 0; 776 mSelStart = 0;
777 for (int i = mSelStart; i <= mSelEnd; i++) { 777 for (int i = mSelStart; i <= mSelEnd; i++) {
778 daylist.append(days[i]); 778 daylist.append(days[i]);
779 } 779 }
780 emit selected((const DateList)daylist); 780 emit selected((const DateList)daylist);
781 781
782} 782}
783 783
784void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 784void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
785{ 785{
786 if ( ! mouseDown ) { 786 if ( ! mouseDown ) {
787 return; 787 return;
788 } 788 }
789 mRedrawNeeded = true; 789 mRedrawNeeded = true;
790 int tmp = getDayIndexFrom(e->x(), e->y()); 790 int tmp = getDayIndexFrom(e->x(), e->y());
791 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 791 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
792 792
793 if (mSelInit > tmp) { 793 if (mSelInit > tmp) {
794 mSelEnd = mSelInit; 794 mSelEnd = mSelInit;
795 if (tmp != mSelStart) { 795 if (tmp != mSelStart) {
796 mSelStart = tmp; 796 mSelStart = tmp;
797 repaint(false); 797 repaint(false);
798 } 798 }
799 } else { 799 } else {
800 mSelStart = mSelInit; 800 mSelStart = mSelInit;
801 801
802 //repaint only if selection has changed 802 //repaint only if selection has changed
803 if (tmp != mSelEnd) { 803 if (tmp != mSelEnd) {
804 mSelEnd = tmp; 804 mSelEnd = tmp;
805 repaint(false); 805 repaint(false);
806 } 806 }
807 } 807 }
808} 808}
809 809
810// ---------------------------------------------------------------------------- 810// ----------------------------------------------------------------------------
811// D R A G ' N D R O P H A N D L I N G 811// D R A G ' N D R O P H A N D L I N G
812// ---------------------------------------------------------------------------- 812// ----------------------------------------------------------------------------
813 813
814void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 814void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
815{ 815{
816#ifndef KORG_NODND 816#ifndef KORG_NODND
817 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 817 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
818 e->ignore(); 818 e->ignore();
819 return; 819 return;
820 } 820 }
821 821
822 // some visual feedback 822 // some visual feedback
823// oldPalette = palette(); 823// oldPalette = palette();
824// setPalette(my_HilitePalette); 824// setPalette(my_HilitePalette);
825// update(); 825// update();
826#endif 826#endif
827} 827}
828 828
829void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 829void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
830{ 830{
831#ifndef KORG_NODND 831#ifndef KORG_NODND
832 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 832 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
833 e->ignore(); 833 e->ignore();
834 return; 834 return;
835 } 835 }
836 836
837 e->accept(); 837 e->accept();
838#endif 838#endif
839} 839}
840 840
841void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 841void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
842{ 842{
843#ifndef KORG_NODND 843#ifndef KORG_NODND
844// setPalette(oldPalette); 844// setPalette(oldPalette);
845// update(); 845// update();
846#endif 846#endif
847} 847}
848 848
849void KODayMatrix::dropEvent(QDropEvent *e) 849void KODayMatrix::dropEvent(QDropEvent *e)
850{ 850{
851#ifndef KORG_NODND 851#ifndef KORG_NODND
852// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 852// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
853 853
854 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 854 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
855 e->ignore(); 855 e->ignore();
856 return; 856 return;
857 } 857 }
858 858
859 DndFactory factory( mCalendar ); 859 DndFactory factory( mCalendar );
860 Event *event = factory.createDrop(e); 860 Event *event = factory.createDrop(e);
861 861
862 if (event) { 862 if (event) {
863 e->acceptAction(); 863 e->acceptAction();
864 864
865 Event *existingEvent = mCalendar->event(event->uid()); 865 Event *existingEvent = mCalendar->event(event->uid());
866 866
867 if(existingEvent) { 867 if(existingEvent) {
868 // uniquify event 868 // uniquify event
869 event->recreate(); 869 event->recreate();
870/* 870/*
871 KMessageBox::sorry(this, 871 KMessageBox::sorry(this,
872 i18n("Event already exists in this calendar."), 872 i18n("Event already exists in this calendar."),
873 i18n("Drop Event")); 873 i18n("Drop Event"));
874 delete event; 874 delete event;
875 return; 875 return;
876*/ 876*/
877 } 877 }
878// kdDebug() << "Drop new Event" << endl; 878// kdDebug() << "Drop new Event" << endl;
879 // Adjust date 879 // Adjust date
880 QDateTime start = event->dtStart(); 880 QDateTime start = event->dtStart();
881 QDateTime end = event->dtEnd(); 881 QDateTime end = event->dtEnd();
882 int duration = start.daysTo(end); 882 int duration = start.daysTo(end);
883 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 883 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
884 884
885 start.setDate(days[idx]); 885 start.setDate(days[idx]);
886 end.setDate(days[idx].addDays(duration)); 886 end.setDate(days[idx].addDays(duration));
887 887
888 event->setDtStart(start); 888 event->setDtStart(start);
889 event->setDtEnd(end); 889 event->setDtEnd(end);
890 mCalendar->addEvent(event); 890 mCalendar->addEvent(event);
891 891
892 emit eventDropped(event); 892 emit eventDropped(event);
893 } else { 893 } else {
894// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 894// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
895 e->ignore(); 895 e->ignore();
896 } 896 }
897#endif 897#endif
898} 898}
899 899
900// ---------------------------------------------------------------------------- 900// ----------------------------------------------------------------------------
901// P A I N T E V E N T H A N D L I N G 901// P A I N T E V E N T H A N D L I N G
902// ---------------------------------------------------------------------------- 902// ----------------------------------------------------------------------------
903 903
904void KODayMatrix::paintEvent(QPaintEvent * pevent) 904void KODayMatrix::paintEvent(QPaintEvent * pevent)
905{ 905{
906 906
907 if ( width() <= 0 || height() <= 0 ) 907 if ( width() <= 0 || height() <= 0 )
908 return; 908 return;
909 if ( mPendingUpdateBeforeRepaint ) { 909 if ( mPendingUpdateBeforeRepaint ) {
910 updateViewTimed(); 910 updateViewTimed();
911 mPendingUpdateBeforeRepaint = false; 911 mPendingUpdateBeforeRepaint = false;
912 } 912 }
913#if 0 913#if 0
914 if ( myPix.width() != width() || myPix.height()!=height() ) { 914 if ( myPix.width() != width() || myPix.height()!=height() ) {
915 myPix.resize(size() ); 915 myPix.resize(size() );
916 mRedrawNeeded = true; 916 mRedrawNeeded = true;
917 } 917 }
918#endif 918#endif
919 if ( oldW != width() || oldH !=height() ) 919 if ( oldW != width() || oldH !=height() )
920 mRedrawNeeded = true; 920 mRedrawNeeded = true;
921 921
922 oldH = height() ; 922 oldH = height() ;
923 oldW = width(); 923 oldW = width();
924 if ( myPix.width() < width() || myPix.height() < height() ) { 924 if ( myPix.width() < width() || myPix.height() < height() ) {
925 myPix.resize(size() ); 925 myPix.resize(size() );
926 mRedrawNeeded = true; 926 mRedrawNeeded = true;
927 927
928 } 928 }
929 929
930 if ( mRedrawNeeded ) { 930 if ( mRedrawNeeded ) {
931 //qDebug("REDRAW "); 931 //qDebug("REDRAW ");
932 QPainter p(&myPix); 932 QPainter p(&myPix);
933 p.setFont(font()); 933 p.setFont(font());
934 934
935 935
936 int dheight = daysize.height(); 936 int dheight = daysize.height();
937 int dwidth = daysize.width(); 937 int dwidth = daysize.width();
938 int row,col; 938 int row,col;
939 int selw, selh; 939 int selw, selh;
940 int xyOff = frameWidth(); 940 int xyOff = frameWidth();
941 int colModulo = (width()-2) % 7; 941 int colModulo = (width()-2) % 7;
942 int rowModulo = (height()-2) % 6; 942 int rowModulo = (height()-2) % 6;
943 //qDebug("col %d row %d ",colModulo,rowModulo ); 943 //qDebug("col %d row %d ",colModulo,rowModulo );
944 944
945 bool isRTL = KOGlobals::self()->reverseLayout(); 945 bool isRTL = KOGlobals::self()->reverseLayout();
946 946
947 // draw background and topleft frame 947 // draw background and topleft frame
948 p.fillRect(0,0,width(),height(), mDefaultBackColor); 948 p.fillRect(0,0,width(),height(), mDefaultBackColor);
949 //p.setPen(mDefaultTextColor); 949 //p.setPen(mDefaultTextColor);
950 //p.drawRect(0, 0, width(), height()); 950 //p.drawRect(0, 0, width(), height());
951 int mSelStartT = mSelStart; 951 int mSelStartT = mSelStart;
952 int mSelEndT = mSelEnd; 952 int mSelEndT = mSelEnd;
953 if ( mSelEndT >= NUMDAYS ) 953 if ( mSelEndT >= NUMDAYS )
954 mSelEndT = NUMDAYS-1; 954 mSelEndT = NUMDAYS-1;
955 // draw selected days with highlighted background color 955 // draw selected days with highlighted background color
956 if (mSelStart != NOSELECTION) { 956 if (mSelStart != NOSELECTION) {
957 bool skip = false; 957 bool skip = false;
958 if ( ! mouseDown ) { 958 if ( ! mouseDown ) {
959 int mo = days[20].month(); 959 int mo = days[20].month();
960 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 960 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
961 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 961 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
962 int startMo = days[mSelStartT].month(); 962 int startMo = days[mSelStartT].month();
963 int endMo = days[mSelEndT].month(); 963 int endMo = days[mSelEndT].month();
964 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 964 if ( startMo == 12 && mo == 1 && endMo <= 2 )
965 startMo = 1; 965 startMo = 1;
966 if ( endMo == 1 && mo == 12 ) 966 if ( endMo == 1 && mo == 12 )
967 endMo = 12; 967 endMo = 12;
968 if ( mo == 12 && startMo == 1 ) 968 if ( mo == 12 && startMo == 1 )
969 startMo = 13; 969 startMo = 13;
970 if ( (startMo > mo || endMo < mo) ) { 970 if ( (startMo > mo || endMo < mo) ) {
971 skip = true; 971 skip = true;
972 } else { 972 } else {
973 if ( days[mSelStartT].month() != mo ) { 973 if ( days[mSelStartT].month() != mo ) {
974 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 974 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
975 mSelStartT += add +1; 975 mSelStartT += add +1;
976 } 976 }
977 if ( days[mSelEndT].month() != mo ) { 977 if ( days[mSelEndT].month() != mo ) {
978 int sub = days[mSelEndT].day(); 978 int sub = days[mSelEndT].day();
979 mSelEndT -= sub ; 979 mSelEndT -= sub ;
980 } 980 }
981 } 981 }
982 } 982 }
983 //qDebug("SKIP %d ", skip); 983 //qDebug("SKIP %d ", skip);
984 if ( ! skip ) { 984 if ( ! skip ) {
985 row = mSelStartT/7; 985 row = mSelStartT/7;
986 col = mSelStartT -row*7; 986 col = mSelStartT -row*7;
987 QColor selcol = KOPrefs::instance()->mHighlightColor; 987 QColor selcol = KOPrefs::instance()->mHighlightColor;
988 int addCol = 0; 988 int addCol = 0;
989 int addRow = 0; 989 int addRow = 0;
990 int addRow2 = 0; 990 int addRow2 = 0;
991 int addCol2 = 0; 991 int addCol2 = 0;
992 if (row == mSelEndT/7) { 992 if (row == mSelEndT/7) {
993 if ( rowModulo ) { 993 if ( rowModulo ) {
994 if ( row >= 6 - rowModulo ) 994 if ( row >= 6 - rowModulo )
995 addRow = row - 5 + rowModulo; 995 addRow = row - 5 + rowModulo;
996 } 996 }
997 if ( colModulo ) { 997 if ( colModulo ) {
998 int colt1 = mSelEndT%7; 998 int colt1 = mSelEndT%7;
999 //qDebug("colt1 %d ", colt1 ); 999 //qDebug("colt1 %d ", colt1 );
1000 if ( colt1 >= 7 - colModulo ) 1000 if ( colt1 >= 7 - colModulo )
1001 addCol = colt1 - 7 + colModulo+1; 1001 addCol = colt1 - 7 + colModulo+1;
1002 int colt = mSelStartT%7; 1002 int colt = mSelStartT%7;
1003 if ( colt >= 7 - colModulo ) 1003 if ( colt >= 7 - colModulo )
1004 addCol2 = colt - 7 + colModulo; 1004 addCol2 = colt - 7 + colModulo;
1005 addCol -= addCol2; 1005 addCol -= addCol2;
1006 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 1006 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
1007 } 1007 }
1008 // Single row selection 1008 // Single row selection
1009 //if ( row == 0) 1009 //if ( row == 0)
1010 // addRow = 1; 1010 // addRow = 1;
1011 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 1011 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
1012 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 1012 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
1013 } else { 1013 } else {
1014 // draw first row to the right 1014 // draw first row to the right
1015 if ( colModulo ) { 1015 if ( colModulo ) {
1016 if ( col >= 7 - colModulo ) 1016 if ( col >= 7 - colModulo )
1017 addCol2 = col - 7 + colModulo; 1017 addCol2 = col - 7 + colModulo;
1018 } 1018 }
1019 if ( rowModulo ) { 1019 if ( rowModulo ) {
1020 if ( row >= 6 - rowModulo ) 1020 if ( row >= 6 - rowModulo )
1021 addRow = row - 5 + rowModulo; 1021 addRow = row - 5 + rowModulo;
1022 } 1022 }
1023 //if ( row == 0) 1023 //if ( row == 0)
1024 // addRow = 1; 1024 // addRow = 1;
1025 int drawWid = width()-(col*dwidth+1+addCol2)-1; 1025 int drawWid = width()-(col*dwidth+1+addCol2)-1;
1026 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, 1026 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid,
1027 dheight+1, selcol); 1027 dheight+1, selcol);
1028 // draw full block till last line 1028 // draw full block till last line
1029 selh = mSelEndT/7-row; 1029 selh = mSelEndT/7-row;
1030 addRow = 0; 1030 addRow = 0;
1031 if ( rowModulo ) { 1031 if ( rowModulo ) {
1032 if ( mSelEndT/7 >= 6 - rowModulo ) 1032 if ( mSelEndT/7 >= 6 - rowModulo )
1033 addRow = mSelEndT/7 - 5 + rowModulo; 1033 addRow = mSelEndT/7 - 5 + rowModulo;
1034 } 1034 }
1035 //qDebug("%d %d %d ",selh, row, addRow ); 1035 //qDebug("%d %d %d ",selh, row, addRow );
1036 int addrow2 = addRow-selh+1; 1036 int addrow2 = addRow-selh+1;
1037 if ( addrow2 < 0 ) 1037 if ( addrow2 < 0 )
1038 addrow2 = 0; 1038 addrow2 = 0;
1039 if (selh > 1) { 1039 if (selh > 1) {
1040 p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 1040 p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
1041 } 1041 }
1042 // draw last block from left to mSelEndT 1042 // draw last block from left to mSelEndT
1043 selw = mSelEndT-7*(mSelEndT/7)+1; 1043 selw = mSelEndT-7*(mSelEndT/7)+1;
1044 //qDebug("esl %d ",selw ); 1044 //qDebug("esl %d ",selw );
1045 int add = 0; 1045 int add = 0;
1046 if ( colModulo ) { 1046 if ( colModulo ) {
1047 add = 7 - colModulo; 1047 add = 7 - colModulo;
1048 if ( selw > add ) 1048 if ( selw > add )
1049 add = selw - add; 1049 add = selw - add;
1050 else 1050 else
1051 add = 0; 1051 add = 0;
1052 } 1052 }
1053 //qDebug("add %d ", add); 1053 //qDebug("add %d ", add);
1054 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 1054 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
1055 selw*dwidth+add, dheight+1, selcol); 1055 selw*dwidth+add, dheight+1, selcol);
1056 } 1056 }
1057 } 1057 }
1058 } 1058 }
1059 1059
1060 // iterate over all days in the matrix and draw the day label in appropriate colors 1060 // iterate over all days in the matrix and draw the day label in appropriate colors
1061 QColor actcol = mDefaultTextColorShaded; 1061 QColor actcol = mDefaultTextColorShaded;
1062 p.setPen(actcol); 1062 p.setPen(actcol);
1063 QPen tmppen; 1063 QPen tmppen;
1064 for(int i = 0; i < NUMDAYS; i++) { 1064 for(int i = 0; i < NUMDAYS; i++) {
1065 row = i/7; 1065 row = i/7;
1066 col = isRTL ? 6-(i-row*7) : i-row*7; 1066 col = isRTL ? 6-(i-row*7) : i-row*7;
1067 1067
1068 // if it is the first day of a month switch color from normal to shaded and vice versa 1068 // if it is the first day of a month switch color from normal to shaded and vice versa
1069 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 1069 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
1070 if (actcol == mDefaultTextColorShaded) { 1070 if (actcol == mDefaultTextColorShaded) {
1071 actcol = mDefaultTextColor; 1071 actcol = mDefaultTextColor;
1072 } else { 1072 } else {
1073 actcol = mDefaultTextColorShaded; 1073 actcol = mDefaultTextColorShaded;
1074 } 1074 }
1075 p.setPen(actcol); 1075 p.setPen(actcol);
1076 } 1076 }
1077 if (actcol == mDefaultTextColorShaded) { 1077 if (actcol == mDefaultTextColorShaded) {
1078 if ( ! mouseDown ) { 1078 if ( ! mouseDown ) {
1079 continue; 1079 continue;
1080 } 1080 }
1081 } 1081 }
1082 //Reset pen color after selected days block 1082 //Reset pen color after selected days block
1083 if (i == mSelEndT+1) { 1083 if (i == mSelEndT+1) {
1084 p.setPen(actcol); 1084 p.setPen(actcol);
1085 } 1085 }
1086 1086
1087 // if today then draw rectangle around day 1087 // if today then draw rectangle around day
1088 if (today == i) { 1088 if (today == i) {
1089 tmppen = p.pen(); 1089 tmppen = p.pen();
1090 QPen mTodayPen(p.pen()); 1090 QPen mTodayPen(p.pen());
1091 if ( daysize.width() < 20 ) 1091 if ( daysize.width() < 20 )
1092 mTodayPen.setWidth(1); 1092 mTodayPen.setWidth(1);
1093 else 1093 else
1094 mTodayPen.setWidth(mTodayMarginWidth); 1094 mTodayPen.setWidth(mTodayMarginWidth);
1095 //draw red rectangle for holidays 1095 //draw red rectangle for holidays
1096 if (pDays.testBit(i)) { 1096 if (pDays.testBit(i)) {
1097 if (actcol == mDefaultTextColor) { 1097 if (actcol == mDefaultTextColor) {
1098 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 1098 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
1099 } else { 1099 } else {
1100 mTodayPen.setColor(mHolidayColorShaded); 1100 mTodayPen.setColor(mHolidayColorShaded);
1101 } 1101 }
1102 } 1102 }
1103 //draw gray rectangle for today if in selection 1103 //draw gray rectangle for today if in selection
1104 if (i >= mSelStartT && i <= mSelEndT) { 1104 if (i >= mSelStartT && i <= mSelEndT) {
1105 QColor grey("grey"); 1105 QColor grey("grey");
1106 mTodayPen.setColor(grey); 1106 mTodayPen.setColor(grey);
1107 } 1107 }
1108 p.setPen(mTodayPen); 1108 p.setPen(mTodayPen);
1109 1109
1110 1110
1111 int addCol = 0; 1111 int addCol = 0;
1112 int addRow = 0; 1112 int addRow = 0;
1113 if (rowModulo) { 1113 if (rowModulo) {
1114 if ( row >= 6 - rowModulo ) 1114 if ( row >= 6 - rowModulo )
1115 addRow = row - 5 + rowModulo; 1115 addRow = row - 5 + rowModulo;
1116 } 1116 }
1117 if ( colModulo ) { 1117 if ( colModulo ) {
1118 if ( col >= 7 - colModulo ) 1118 if ( col >= 7 - colModulo )
1119 addCol = col - 6 + colModulo-1; 1119 addCol = col - 6 + colModulo-1;
1120 } 1120 }
1121 1121
1122 addCol += 1; 1122 addCol += 1;
1123 if ( row == 0 ) 1123 if ( row == 0 )
1124 addRow = 1; 1124 addRow = 1;
1125 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); 1125 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1);
1126 p.setPen(tmppen); 1126 p.setPen(tmppen);
1127 } 1127 }
1128 1128
1129 // if any events are on that day then draw it using a bold font 1129 // if any events are on that day then draw it using a bold font
1130 if ( eDays.testBit(i) ) { 1130 if ( eDays.testBit(i) ) {
1131 QFont myFont = font(); 1131 QFont myFont = font();
1132 myFont.setBold(true); 1132 myFont.setBold(true);
1133 p.setFont(myFont); 1133 p.setFont(myFont);
1134 } 1134 }
1135 1135
1136 // if it is a holiday then use the default holiday color 1136 // if it is a holiday then use the default holiday color
1137 if ( pDays.testBit(i)) { 1137 if ( pDays.testBit(i)) {
1138 if ( bDays.testBit(i) ) { 1138 if ( bDays.testBit(i) ) {
1139 if ( hDays.testBit(i) ) 1139 if ( hDays.testBit(i) )
1140 p.setPen(QColor(0,200,0)); 1140 p.setPen(QColor(0,200,0));
1141 else 1141 else
1142 p.setPen(QColor(Qt::blue)); 1142 p.setPen(QColor(Qt::blue));
1143 } else { 1143 } else {
1144 if (actcol == mDefaultTextColor ) { 1144 if (actcol == mDefaultTextColor ) {
1145 p.setPen(KOPrefs::instance()->mHolidayColor); 1145 p.setPen(KOPrefs::instance()->mHolidayColor);
1146 } else { 1146 } else {
1147 p.setPen(mHolidayColorShaded); 1147 p.setPen(mHolidayColorShaded);
1148 } 1148 }
1149 } 1149 }
1150 } 1150 }
1151 1151
1152 // draw selected days with special color 1152 // draw selected days with special color
1153 // DO NOT specially highlight holidays in selection ! 1153 // DO NOT specially highlight holidays in selection !
1154 if (i >= mSelStartT && i <= mSelEndT) { 1154 if (i >= mSelStartT && i <= mSelEndT) {
1155 ;//p.setPen(mSelectedDaysColor); 1155 ;//p.setPen(mSelectedDaysColor);
1156 } 1156 }
1157 1157
1158 int addCol = 0; 1158 int addCol = 0;
1159 int addRow = 0; 1159 int addRow = 0;
1160 if ( colModulo ) { 1160 if ( colModulo ) {
1161 if ( col >= 7 - colModulo ) 1161 if ( col >= 7 - colModulo )
1162 addCol = col - 7 + colModulo; 1162 addCol = col - 7 + colModulo;
1163 } 1163 }
1164 if ( rowModulo ) { 1164 if ( rowModulo ) {
1165 if ( row >= 6 - rowModulo ) 1165 if ( row >= 6 - rowModulo )
1166 addRow = row - 5 + rowModulo; 1166 addRow = row - 5 + rowModulo;
1167 } 1167 }
1168 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 1168 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
1169 ++addCol;//++addCol; 1169 ++addCol;//++addCol;
1170 if ( row == 0) 1170 if ( row == 0)
1171 addRow = 1; 1171 addRow = 1;
1172 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 1172 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
1173 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 1173 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
1174 1174
1175 // reset color to actual color 1175 // reset color to actual color
1176 if (pDays.testBit(i)) { 1176 if (pDays.testBit(i)) {
1177 p.setPen(actcol); 1177 p.setPen(actcol);
1178 } 1178 }
1179 // reset bold font to plain font 1179 // reset bold font to plain font
1180 if ( eDays.testBit(i)) { 1180 if ( eDays.testBit(i)) {
1181 QFont myFont = font(); 1181 QFont myFont = font();
1182 myFont.setBold(false); 1182 myFont.setBold(false);
1183 p.setFont(myFont); 1183 p.setFont(myFont);
1184 } 1184 }
1185 } 1185 }
1186 p.setPen(mDefaultTextColor); 1186 p.setPen(mDefaultTextColor);
1187 p.drawRect(0, 0, width(), height()); 1187 p.drawRect(0, 0, width(), height());
1188 } else { 1188 } else {
1189 //qDebug("NO redraw "); 1189 //qDebug("NO redraw ");
1190 } 1190 }
1191 1191
1192 bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP); 1192 bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP);
1193 mRedrawNeeded = false; 1193 mRedrawNeeded = false;
1194} 1194}
1195 1195
1196// ---------------------------------------------------------------------------- 1196// ----------------------------------------------------------------------------
1197// R E SI Z E E V E N T H A N D L I N G 1197// R E SI Z E E V E N T H A N D L I N G
1198// ---------------------------------------------------------------------------- 1198// ----------------------------------------------------------------------------
1199 1199
1200void KODayMatrix::resizeEvent(QResizeEvent *) 1200void KODayMatrix::resizeEvent(QResizeEvent * e)
1201{ 1201{
1202 QRect sz = frameRect(); 1202 QRect sz = frameRect();
1203 daysize.setHeight(sz.height()*7 / NUMDAYS); 1203 daysize.setHeight(sz.height()*7 / NUMDAYS);
1204 daysize.setWidth(sz.width() / 7); 1204 daysize.setWidth(sz.width() / 7);
1205 QFrame::resizeEvent( e );
1205} 1206}
1206 1207
1207QSize KODayMatrix::sizeHint() const 1208QSize KODayMatrix::sizeHint() const
1208{ 1209{
1209 1210
1210 QFontMetrics fm ( font() ); 1211 QFontMetrics fm ( font() );
1211 int wid = fm.width( "30") *7+3; 1212 int wid = fm.width( "30") *7+3;
1212 int hei = fm.height() * 6+3; 1213 int hei = fm.height() * 6+3;
1213 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 1214 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
1214 return QSize ( wid, hei ); 1215 return QSize ( wid, hei );
1215 1216
1216} 1217}
diff --git a/korganizer/koeditorgeneral.cpp b/korganizer/koeditorgeneral.cpp
index 2fbcd42..e07bc53 100644
--- a/korganizer/koeditorgeneral.cpp
+++ b/korganizer/koeditorgeneral.cpp
@@ -1,569 +1,569 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qwidget.h> 24#include <qwidget.h>
25#include <qtooltip.h> 25#include <qtooltip.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qbuttongroup.h> 28#include <qbuttongroup.h>
29#include <qvgroupbox.h> 29#include <qvgroupbox.h>
30#include <qwidgetstack.h> 30#include <qwidgetstack.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qregexp.h> 34#include <qregexp.h>
35 35
36 36
37#include <kglobal.h> 37#include <kglobal.h>
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kiconloader.h> 40#include <kiconloader.h>
41#include <kmessagebox.h> 41#include <kmessagebox.h>
42#include <kfiledialog.h> 42#include <kfiledialog.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44 44
45#include <libkcal/todo.h> 45#include <libkcal/todo.h>
46#include <libkcal/event.h> 46#include <libkcal/event.h>
47#include <libkdepim/categoryselectdialog.h> 47#include <libkdepim/categoryselectdialog.h>
48#include <libkdepim/kdateedit.h> 48#include <libkdepim/kdateedit.h>
49 49
50#include "koprefs.h" 50#include "koprefs.h"
51#include "koglobals.h" 51#include "koglobals.h"
52 52
53#include "koeditorgeneral.h" 53#include "koeditorgeneral.h"
54#include "kolocationbox.h" 54#include "kolocationbox.h"
55#ifndef DESKTOP_VERSION 55#ifndef DESKTOP_VERSION
56#include <qpe/qpeapplication.h> 56#include <qpe/qpeapplication.h>
57#else 57#else
58#include <qapplication.h> 58#include <qapplication.h>
59#endif 59#endif
60 60
61KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) : 61KOEditorGeneral::KOEditorGeneral(QObject* parent, const char* name) :
62 QObject( parent, name) 62 QObject( parent, name)
63{ 63{
64 mNextFocus = 0; 64 mNextFocus = 0;
65} 65}
66 66
67KOEditorGeneral::~KOEditorGeneral() 67KOEditorGeneral::~KOEditorGeneral()
68{ 68{
69} 69}
70 70
71void KOEditorGeneral::initHeader(QWidget *parent,QBoxLayout *topLayout) 71void KOEditorGeneral::initHeader(QWidget *parent,QBoxLayout *topLayout)
72{ 72{
73 QGridLayout *headerLayout = new QGridLayout(topLayout); 73 QGridLayout *headerLayout = new QGridLayout(topLayout);
74 74
75#if 0 75#if 0
76 mOwnerLabel = new QLabel(i18n("Owner:"),parent); 76 mOwnerLabel = new QLabel(i18n("Owner:"),parent);
77 headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1); 77 headerLayout->addMultiCellWidget(mOwnerLabel,0,0,0,1);
78#endif 78#endif
79 79
80 QLabel *summaryLabel = new QLabel(i18n("Summary:"),parent); 80 QLabel *summaryLabel = new QLabel(i18n("Summary:"),parent);
81 headerLayout->addWidget(summaryLabel,1,0); 81 headerLayout->addWidget(summaryLabel,1,0);
82 82
83 mSummaryEdit = new KOLocationBox(TRUE,parent, 10); 83 mSummaryEdit = new KOLocationBox(TRUE,parent, 10);
84 mSummaryEdit->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) ); 84 mSummaryEdit->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) );
85 //mSummaryEdit->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5 ,(QSizePolicy::SizeType)3 ,FALSE) ); 85 //mSummaryEdit->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5 ,(QSizePolicy::SizeType)3 ,FALSE) );
86 //qDebug("h %d %d ", summaryLabel->sizeHint().height(),mSummaryEdit->sizeHint().height() ); 86 //qDebug("h %d %d ", summaryLabel->sizeHint().height(),mSummaryEdit->sizeHint().height() );
87 int hei = (summaryLabel->sizeHint().height() + mSummaryEdit->sizeHint().height())/2; 87 int hei = (summaryLabel->sizeHint().height() + mSummaryEdit->sizeHint().height())/2;
88 if ( QApplication::desktop()->width() > 320 ) 88 if ( QApplication::desktop()->width() > 320 )
89 mSummaryEdit->setMaximumHeight( hei +6 ); 89 mSummaryEdit->setMaximumHeight( hei +6 );
90 //qDebug("%d %d %d %d %d %d ", QSizePolicy::Fixed , QSizePolicy::Minimum , QSizePolicy:: Maximum , QSizePolicy:: Preferred , QSizePolicy:: MinimumExpanding , QSizePolicy::Expanding ); 90 //qDebug("%d %d %d %d %d %d ", QSizePolicy::Fixed , QSizePolicy::Minimum , QSizePolicy:: Maximum , QSizePolicy:: Preferred , QSizePolicy:: MinimumExpanding , QSizePolicy::Expanding );
91 // SizeType { Fixed = 0, Minimum = MayGrow, Maximum = MayShrink, Preferred = MayGrow|MayShrink, MinimumExpanding = Minimum|ExpMask, Expanding = MinimumExpanding|MayShrink } 91 // SizeType { Fixed = 0, Minimum = MayGrow, Maximum = MayShrink, Preferred = MayGrow|MayShrink, MinimumExpanding = Minimum|ExpMask, Expanding = MinimumExpanding|MayShrink }
92 // mSummaryEdit = new QLineEdit(parent); 92 // mSummaryEdit = new QLineEdit(parent);
93 headerLayout->addWidget(mSummaryEdit,1,1); 93 headerLayout->addWidget(mSummaryEdit,1,1);
94 connect ( mSummaryEdit->lineEdit(), SIGNAL ( returnPressed() ), this, SIGNAL (allAccepted () ) ); 94 connect ( mSummaryEdit->lineEdit(), SIGNAL ( returnPressed() ), this, SIGNAL (allAccepted () ) );
95 95
96 QLabel *locationLabel = new QLabel(i18n("Location:"),parent); 96 QLabel *locationLabel = new QLabel(i18n("Location:"),parent);
97 if ( QApplication::desktop()->height() < 320 ) 97 if ( QApplication::desktop()->height() < 320 )
98 headerLayout->addWidget(locationLabel,1,2); 98 headerLayout->addWidget(locationLabel,1,2);
99 else 99 else
100 headerLayout->addWidget(locationLabel,2,0); 100 headerLayout->addWidget(locationLabel,2,0);
101 101
102 mLocationEdit = new KOLocationBox(TRUE,parent,10); 102 mLocationEdit = new KOLocationBox(TRUE,parent,10);
103 mLocationEdit->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) ); 103 mLocationEdit->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) );
104 if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->height() > 240 ) 104 if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->height() > 240 )
105 mLocationEdit->setMaximumHeight( hei + 6); 105 mLocationEdit->setMaximumHeight( hei + 6);
106 106
107 // mLocationEdit = new QLineEdit(parent); 107 // mLocationEdit = new QLineEdit(parent);
108 connect ( mLocationEdit->lineEdit(), SIGNAL ( returnPressed() ), this, SIGNAL (allAccepted () ) ); 108 connect ( mLocationEdit->lineEdit(), SIGNAL ( returnPressed() ), this, SIGNAL (allAccepted () ) );
109 if ( QApplication::desktop()->height() < 320 ) { 109 if ( QApplication::desktop()->height() < 320 ) {
110 headerLayout->addWidget(mLocationEdit,1,3); 110 headerLayout->addWidget(mLocationEdit,1,3);
111 headerLayout->setColStretch( 1, 10); 111 headerLayout->setColStretch( 1, 10);
112 headerLayout->setColStretch( 3, 10); 112 headerLayout->setColStretch( 3, 10);
113 } 113 }
114 else { 114 else {
115 headerLayout->addWidget(mLocationEdit,2,1); 115 headerLayout->addWidget(mLocationEdit,2,1);
116 headerLayout->setColStretch( 1, 10); 116 headerLayout->setColStretch( 1, 10);
117 } 117 }
118} 118}
119void KOEditorGeneral::setFocusOn( int i ) 119void KOEditorGeneral::setFocusOn( int i )
120{ 120{
121 mNextFocus = i; 121 mNextFocus = i;
122 QTimer::singleShot( 0, this, SLOT ( slotSetFocusOn() )); 122 QTimer::singleShot( 0, this, SLOT ( slotSetFocusOn() ));
123} 123}
124void KOEditorGeneral::slotSetFocusOn() 124void KOEditorGeneral::slotSetFocusOn()
125{ 125{
126 mNextFocus; 126 mNextFocus;
127 if ( mNextFocus == 1 ) { 127 if ( mNextFocus == 1 ) {
128 mDescriptionEdit->setFocus(); 128 mDescriptionEdit->setFocus();
129 mDescriptionEdit->setCursorPosition( mDescriptionEdit->numLines (), 333); 129 mDescriptionEdit->setCursorPosition( mDescriptionEdit->numLines (), 333);
130 } 130 }
131 if ( mNextFocus == 2 ) { 131 if ( mNextFocus == 2 ) {
132 mSummaryEdit->setFocus(); 132 mSummaryEdit->setFocus();
133 } 133 }
134} 134}
135void KOEditorGeneral::editCategories() 135void KOEditorGeneral::editCategories()
136{ 136{
137 // qDebug("KOEditorGeneral::editCategories() "); 137 // qDebug("KOEditorGeneral::editCategories() ");
138 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 ); 138 KPIM::CategorySelectDialog* csd = new KPIM::CategorySelectDialog( KOPrefs::instance(), 0 );
139 connect(csd,SIGNAL(categoriesSelected(const QString &)), this ,SLOT(setCategories(const QString &))); 139 connect(csd,SIGNAL(categoriesSelected(const QString &)), this ,SLOT(setCategories(const QString &)));
140 //KOGlobals::fitDialogToScreen( csd ); 140 //KOGlobals::fitDialogToScreen( csd );
141 csd->setColorEnabled(); 141 csd->setColorEnabled();
142 csd->setSelected( QStringList::split (",", mCategoriesLabel->text()) ); 142 csd->setSelected( QStringList::split (",", mCategoriesLabel->text()) );
143 csd->exec(); 143 csd->exec();
144 delete csd; 144 delete csd;
145} 145}
146 146
147void KOEditorGeneral::showCatPopup() 147void KOEditorGeneral::showCatPopup()
148{ 148{
149 mCatPopup->clear(); 149 mCatPopup->clear();
150 QStringList checkedCategories = QStringList::split (",", mCategoriesLabel->text()); 150 QStringList checkedCategories = QStringList::split (",", mCategoriesLabel->text());
151 int index = 0; 151 int index = 0;
152 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 152 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
153 it != KOPrefs::instance()->mCustomCategories.end (); 153 it != KOPrefs::instance()->mCustomCategories.end ();
154 ++it) { 154 ++it) {
155 mCatPopup->insertItem (*it, index ); 155 mCatPopup->insertItem (*it, index );
156 //mCategory[index] = *it; 156 //mCategory[index] = *it;
157 if (checkedCategories.find (*it) != checkedCategories.end ()) mCatPopup->setItemChecked (index, true); 157 if (checkedCategories.find (*it) != checkedCategories.end ()) mCatPopup->setItemChecked (index, true);
158 ++index; 158 ++index;
159 } 159 }
160} 160}
161void KOEditorGeneral::selectedCatPopup( int index ) 161void KOEditorGeneral::selectedCatPopup( int index )
162{ 162{
163 QStringList categories = QStringList::split (",", mCategoriesLabel->text()); 163 QStringList categories = QStringList::split (",", mCategoriesLabel->text());
164 QString colcat = categories.first(); 164 QString colcat = categories.first();
165 if (categories.find (KOPrefs::instance()->mCustomCategories[index]) != categories.end ()) 165 if (categories.find (KOPrefs::instance()->mCustomCategories[index]) != categories.end ())
166 categories.remove (KOPrefs::instance()->mCustomCategories[index]); 166 categories.remove (KOPrefs::instance()->mCustomCategories[index]);
167 else 167 else
168 categories.insert (categories.end(), KOPrefs::instance()->mCustomCategories[index]); 168 categories.insert (categories.end(), KOPrefs::instance()->mCustomCategories[index]);
169 categories.sort (); 169 categories.sort ();
170 if ( !colcat.isEmpty() ) { 170 if ( !colcat.isEmpty() ) {
171 if ( categories.find ( colcat ) != categories.end () ) { 171 if ( categories.find ( colcat ) != categories.end () ) {
172 categories.remove( colcat ); 172 categories.remove( colcat );
173 categories.prepend( colcat ); 173 categories.prepend( colcat );
174 } 174 }
175 } 175 }
176 setCategories( categories.join(",") ); 176 setCategories( categories.join(",") );
177} 177}
178 178
179void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout) 179void KOEditorGeneral::initCategories(QWidget *parent, QBoxLayout *topLayout)
180{ 180{
181 QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout ); 181 QBoxLayout *categoriesLayout = new QHBoxLayout( topLayout );
182 mCatPopup = new QPopupMenu ( parent ); 182 mCatPopup = new QPopupMenu ( parent );
183 mCatPopup->setCheckable (true); 183 mCatPopup->setCheckable (true);
184 connect(mCatPopup,SIGNAL(aboutToShow () ), this ,SLOT(showCatPopup())); 184 connect(mCatPopup,SIGNAL(aboutToShow () ), this ,SLOT(showCatPopup()));
185 connect(mCatPopup,SIGNAL( activated ( int ) ), this ,SLOT(selectedCatPopup( int ))); 185 connect(mCatPopup,SIGNAL( activated ( int ) ), this ,SLOT(selectedCatPopup( int )));
186 mCategoriesButton = new QPushButton(parent); 186 mCategoriesButton = new QPushButton(parent);
187 mCategoriesButton->setText(i18n("Categories")); 187 mCategoriesButton->setText(i18n("Categories..."));
188 connect(mCategoriesButton,SIGNAL(clicked()),this, SLOT(editCategories() ));
188 //connect(mCategoriesButton,SIGNAL(clicked()),this, SLOT(editCategories() )); 189 //connect(mCategoriesButton,SIGNAL(clicked()),this, SLOT(editCategories() ));
189 categoriesLayout->addWidget(mCategoriesButton); 190 categoriesLayout->addWidget(mCategoriesButton);
190 mCategoriesButton->setPopup( mCatPopup );
191 mCategoriesLabel = new QPushButton(parent);//new QLabel(parent); 191 mCategoriesLabel = new QPushButton(parent);//new QLabel(parent);
192 mCategoriesLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) ); 192 mCategoriesLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::MinimumExpanding ,FALSE) );
193 connect(mCategoriesLabel,SIGNAL(clicked()),this, SLOT(editCategories() )); 193 mCategoriesLabel->setPopup( mCatPopup );
194 //mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken); 194 //mCategoriesLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken);
195 categoriesLayout->addWidget(mCategoriesLabel,1); 195 categoriesLayout->addWidget(mCategoriesLabel,1);
196} 196}
197 197
198void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout) 198void KOEditorGeneral::initSecrecy(QWidget *parent, QBoxLayout *topLayout)
199{ 199{
200 QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout ); 200 QBoxLayout *secrecyLayout = new QHBoxLayout( topLayout );
201 201
202 QLabel *secrecyLabel = new QLabel(i18n("Access:"),parent); 202 QLabel *secrecyLabel = new QLabel(i18n("Access:"),parent);
203 mCancelBox = new QCheckBox ( i18n("Cancelled"), parent); 203 mCancelBox = new QCheckBox ( i18n("Cancelled"), parent);
204 secrecyLayout->addWidget(mCancelBox); 204 secrecyLayout->addWidget(mCancelBox);
205 secrecyLayout->addWidget(secrecyLabel); 205 secrecyLayout->addWidget(secrecyLabel);
206 206
207 mSecrecyCombo = new QComboBox(parent); 207 mSecrecyCombo = new QComboBox(parent);
208 mSecrecyCombo->insertStringList(Incidence::secrecyList()); 208 mSecrecyCombo->insertStringList(Incidence::secrecyList());
209 secrecyLayout->addWidget(mSecrecyCombo); 209 secrecyLayout->addWidget(mSecrecyCombo);
210} 210}
211 211
212void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout) 212void KOEditorGeneral::initDescription(QWidget *parent,QBoxLayout *topLayout)
213{ 213{
214 mDescriptionEdit = new KTextEdit(parent); 214 mDescriptionEdit = new KTextEdit(parent);
215 mDescriptionEdit->setFont(KOPrefs::instance()->mEditBoxFont ); 215 mDescriptionEdit->setFont(KOPrefs::instance()->mEditBoxFont );
216 mDescriptionEdit->append(""); 216 mDescriptionEdit->append("");
217 mDescriptionEdit->setReadOnly(false); 217 mDescriptionEdit->setReadOnly(false);
218 mDescriptionEdit->setOverwriteMode(false); 218 mDescriptionEdit->setOverwriteMode(false);
219 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth ); 219 mDescriptionEdit->setWordWrap( KTextEdit::WidgetWidth );
220 topLayout->addWidget(mDescriptionEdit); 220 topLayout->addWidget(mDescriptionEdit);
221#ifndef DESKTOP_VERSION 221#ifndef DESKTOP_VERSION
222 QPEApplication::setStylusOperation( mDescriptionEdit, QPEApplication::RightOnHold ); 222 QPEApplication::setStylusOperation( mDescriptionEdit, QPEApplication::RightOnHold );
223#endif 223#endif
224 224
225} 225}
226 226
227void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout) 227void KOEditorGeneral::initAlarm(QWidget *parent,QBoxLayout *topLayout)
228{ 228{
229 QBoxLayout *alarmLayout = new QHBoxLayout(topLayout); 229 QBoxLayout *alarmLayout = new QHBoxLayout(topLayout);
230 230
231 //mAlarmBell = new QLabel(parent); 231 //mAlarmBell = new QLabel(parent);
232 //mAlarmBell->setPixmap(SmallIcon("bell")); 232 //mAlarmBell->setPixmap(SmallIcon("bell"));
233 //alarmLayout->addWidget(mAlarmBell); 233 //alarmLayout->addWidget(mAlarmBell);
234 if ( QApplication::desktop()->width() < 320 ) 234 if ( QApplication::desktop()->width() < 320 )
235 mAlarmButton = new QCheckBox(i18n("Rem."),parent); 235 mAlarmButton = new QCheckBox(i18n("Rem."),parent);
236 else 236 else
237 mAlarmButton = new QCheckBox(i18n("Reminder:"),parent); 237 mAlarmButton = new QCheckBox(i18n("Reminder:"),parent);
238 238
239 connect(mAlarmButton, SIGNAL(toggled(bool)), SLOT(enableAlarmEdit(bool))); 239 connect(mAlarmButton, SIGNAL(toggled(bool)), SLOT(enableAlarmEdit(bool)));
240 alarmLayout->addWidget(mAlarmButton); 240 alarmLayout->addWidget(mAlarmButton);
241 241
242 mAlarmTimeEdit = new QSpinBox ( 0, 9999, 1, parent, "mAlarmTimeEdit " ) ; 242 mAlarmTimeEdit = new QSpinBox ( 0, 9999, 1, parent, "mAlarmTimeEdit " ) ;
243 mAlarmTimeEdit->setButtonSymbols( QSpinBox::PlusMinus ); 243 mAlarmTimeEdit->setButtonSymbols( QSpinBox::PlusMinus );
244 alarmLayout->addWidget(mAlarmTimeEdit); 244 alarmLayout->addWidget(mAlarmTimeEdit);
245 mAlarmIncrCombo = new QComboBox(false, parent); 245 mAlarmIncrCombo = new QComboBox(false, parent);
246 if ( QApplication::desktop()->width() < 320 ) { 246 if ( QApplication::desktop()->width() < 320 ) {
247 mAlarmIncrCombo->insertItem(i18n("min")); 247 mAlarmIncrCombo->insertItem(i18n("min"));
248 mAlarmIncrCombo->insertItem(i18n("hou")); 248 mAlarmIncrCombo->insertItem(i18n("hou"));
249 mAlarmIncrCombo->insertItem(i18n("day")); 249 mAlarmIncrCombo->insertItem(i18n("day"));
250 mAlarmTimeEdit->setMaximumWidth( mAlarmTimeEdit->sizeHint().width() ); 250 mAlarmTimeEdit->setMaximumWidth( mAlarmTimeEdit->sizeHint().width() );
251 mAlarmIncrCombo->setMaximumWidth( mAlarmIncrCombo->sizeHint().width() ); 251 mAlarmIncrCombo->setMaximumWidth( mAlarmIncrCombo->sizeHint().width() );
252 } else { 252 } else {
253 mAlarmIncrCombo->insertItem(i18n("minute(s)")); 253 mAlarmIncrCombo->insertItem(i18n("minute(s)"));
254 mAlarmIncrCombo->insertItem(i18n("hour(s)")); 254 mAlarmIncrCombo->insertItem(i18n("hour(s)"));
255 mAlarmIncrCombo->insertItem(i18n("day(s)")); 255 mAlarmIncrCombo->insertItem(i18n("day(s)"));
256 } 256 }
257 257
258 // mAlarmIncrCombo->setMinimumHeight(20); 258 // mAlarmIncrCombo->setMinimumHeight(20);
259 alarmLayout->addWidget(mAlarmIncrCombo); 259 alarmLayout->addWidget(mAlarmIncrCombo);
260 mAlarmSoundButton = new QPushButton(parent); 260 mAlarmSoundButton = new QPushButton(parent);
261 mAlarmSoundButton->setPixmap(SmallIcon("playsound")); 261 mAlarmSoundButton->setPixmap(SmallIcon("playsound"));
262 mAlarmSoundButton->setToggleButton(true); 262 mAlarmSoundButton->setToggleButton(true);
263 QToolTip::add(mAlarmSoundButton, i18n("No sound set")); 263 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
264 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound())); 264 connect(mAlarmSoundButton, SIGNAL(clicked()), SLOT(pickAlarmSound()));
265 alarmLayout->addWidget(mAlarmSoundButton); 265 alarmLayout->addWidget(mAlarmSoundButton);
266 266
267 mAlarmProgramButton = new QPushButton(parent); 267 mAlarmProgramButton = new QPushButton(parent);
268 mAlarmProgramButton->setPixmap(SmallIcon("run")); 268 mAlarmProgramButton->setPixmap(SmallIcon("run"));
269 mAlarmProgramButton->setToggleButton(true); 269 mAlarmProgramButton->setToggleButton(true);
270 QToolTip::add(mAlarmProgramButton, i18n("No program set")); 270 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
271 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram())); 271 connect(mAlarmProgramButton, SIGNAL(clicked()), SLOT(pickAlarmProgram()));
272 alarmLayout->addWidget(mAlarmProgramButton); 272 alarmLayout->addWidget(mAlarmProgramButton);
273 mAlarmSoundButton->setMaximumWidth( mAlarmSoundButton->sizeHint().width() + 4 ); 273 mAlarmSoundButton->setMaximumWidth( mAlarmSoundButton->sizeHint().width() + 4 );
274 mAlarmProgramButton->setMaximumWidth(mAlarmProgramButton->sizeHint().width() + 4 ); 274 mAlarmProgramButton->setMaximumWidth(mAlarmProgramButton->sizeHint().width() + 4 );
275 // if ( KOPrefs::instance()->mCompactDialogs ) { 275 // if ( KOPrefs::instance()->mCompactDialogs ) {
276 // mAlarmSoundButton->hide(); 276 // mAlarmSoundButton->hide();
277 // mAlarmProgramButton->hide(); 277 // mAlarmProgramButton->hide();
278 // } 278 // }
279} 279}
280 280
281void KOEditorGeneral::pickAlarmSound() 281void KOEditorGeneral::pickAlarmSound()
282{ 282{
283 283
284 //qDebug("KOEditorGeneral::pickAlarmSound() %d",mAlarmSoundButton->isOn() ); 284 //qDebug("KOEditorGeneral::pickAlarmSound() %d",mAlarmSoundButton->isOn() );
285 285
286 bool oldState = mAlarmSoundButton->isOn(); 286 bool oldState = mAlarmSoundButton->isOn();
287 287
288 QString fileName(KFileDialog::getOpenFileName(mAlarmSound, 288 QString fileName(KFileDialog::getOpenFileName(mAlarmSound,
289 i18n("*.wav|Wav Files"), 0)); 289 i18n("*.wav|Wav Files"), 0));
290 if (!fileName.isEmpty()) { 290 if (!fileName.isEmpty()) {
291 mAlarmSound = fileName; 291 mAlarmSound = fileName;
292 QToolTip::remove(mAlarmSoundButton); 292 QToolTip::remove(mAlarmSoundButton);
293 QString dispStr = i18n("Playing '%1'").arg(fileName); 293 QString dispStr = i18n("Playing '%1'").arg(fileName);
294 QToolTip::add(mAlarmSoundButton, dispStr); 294 QToolTip::add(mAlarmSoundButton, dispStr);
295 mAlarmProgramButton->setOn(false); 295 mAlarmProgramButton->setOn(false);
296 mAlarmSoundButton->setOn(true); 296 mAlarmSoundButton->setOn(true);
297 QToolTip::add(mAlarmProgramButton, i18n("No program set")); 297 QToolTip::add(mAlarmProgramButton, i18n("No program set"));
298 } else { 298 } else {
299 mAlarmProgramButton->setOn(oldState); 299 mAlarmProgramButton->setOn(oldState);
300 mAlarmSoundButton->setOn(!oldState); 300 mAlarmSoundButton->setOn(!oldState);
301 301
302 302
303 } 303 }
304 304
305 if (mAlarmProgramButton->isOn()) 305 if (mAlarmProgramButton->isOn())
306 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Proc.Al.: ") + getFittingPath(mAlarmProgram) ); 306 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Proc.Al.: ") + getFittingPath(mAlarmProgram) );
307 if ( mAlarmSoundButton->isOn()) 307 if ( mAlarmSoundButton->isOn())
308 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Audio Al.: ") + getFittingPath(mAlarmSound) ); 308 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Audio Al.: ") + getFittingPath(mAlarmSound) );
309 309
310} 310}
311 311
312void KOEditorGeneral::pickAlarmProgram() 312void KOEditorGeneral::pickAlarmProgram()
313{ 313{
314 bool oldState = mAlarmProgramButton->isOn(); 314 bool oldState = mAlarmProgramButton->isOn();
315 315
316 QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm: ") , 0)); 316 QString fileName(KFileDialog::getOpenFileName(mAlarmProgram,i18n("Procedure Alarm: ") , 0));
317 if (!fileName.isEmpty()) { 317 if (!fileName.isEmpty()) {
318 mAlarmProgram = fileName; 318 mAlarmProgram = fileName;
319 QToolTip::remove(mAlarmProgramButton); 319 QToolTip::remove(mAlarmProgramButton);
320 QString dispStr = i18n("Running '%1'").arg(fileName); 320 QString dispStr = i18n("Running '%1'").arg(fileName);
321 QToolTip::add(mAlarmProgramButton, dispStr); 321 QToolTip::add(mAlarmProgramButton, dispStr);
322 mAlarmSoundButton->setOn(false); 322 mAlarmSoundButton->setOn(false);
323 mAlarmProgramButton->setOn(true); 323 mAlarmProgramButton->setOn(true);
324 QToolTip::add(mAlarmSoundButton, i18n("No sound set")); 324 QToolTip::add(mAlarmSoundButton, i18n("No sound set"));
325 } else { 325 } else {
326 mAlarmProgramButton->setOn(!oldState); 326 mAlarmProgramButton->setOn(!oldState);
327 mAlarmSoundButton->setOn(oldState); 327 mAlarmSoundButton->setOn(oldState);
328 } 328 }
329 329
330 if (mAlarmProgramButton->isOn()) 330 if (mAlarmProgramButton->isOn())
331 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Proc.Al.: ") + getFittingPath(mAlarmProgram) ); 331 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Proc.Al.: ") + getFittingPath(mAlarmProgram) );
332 if ( mAlarmSoundButton->isOn()) 332 if ( mAlarmSoundButton->isOn())
333 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Audio Al.: ") + getFittingPath(mAlarmSound) ); 333 ((QWidget*)parent())->topLevelWidget()->setCaption(i18n("Audio Al.: ") + getFittingPath(mAlarmSound) );
334 334
335} 335}
336 336
337 337
338QString KOEditorGeneral::getFittingPath( const QString s ) 338QString KOEditorGeneral::getFittingPath( const QString s )
339{ 339{
340 int maxlen = 50; 340 int maxlen = 50;
341 if ( QApplication::desktop()->width() < 640 ) { 341 if ( QApplication::desktop()->width() < 640 ) {
342 if ( QApplication::desktop()->width() < 320 ) 342 if ( QApplication::desktop()->width() < 320 )
343 maxlen = 22; 343 maxlen = 22;
344 else 344 else
345 maxlen = 35; 345 maxlen = 35;
346 } 346 }
347 if ( s.length() > maxlen ) { 347 if ( s.length() > maxlen ) {
348 return "..."+s.right(maxlen -3); 348 return "..."+s.right(maxlen -3);
349 } 349 }
350 return s; 350 return s;
351} 351}
352 352
353void KOEditorGeneral::enableAlarmEdit(bool enable) 353void KOEditorGeneral::enableAlarmEdit(bool enable)
354{ 354{
355 if ( enable ) { 355 if ( enable ) {
356 if (!mAlarmProgramButton->isOn() && !mAlarmSoundButton->isOn()) { 356 if (!mAlarmProgramButton->isOn() && !mAlarmSoundButton->isOn()) {
357 mAlarmSoundButton->setOn( true ); 357 mAlarmSoundButton->setOn( true );
358 if ( mAlarmSound.isEmpty() ) 358 if ( mAlarmSound.isEmpty() )
359 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile; 359 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
360 else { 360 else {
361 if ( ! QFile::exists( mAlarmSound ) ) 361 if ( ! QFile::exists( mAlarmSound ) )
362 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile; 362 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
363 } 363 }
364 } 364 }
365 } 365 }
366 ((QWidget*)parent())->topLevelWidget()->setCaption(mAlarmMessage); 366 ((QWidget*)parent())->topLevelWidget()->setCaption(mAlarmMessage);
367 mAlarmTimeEdit->setEnabled(enable); 367 mAlarmTimeEdit->setEnabled(enable);
368 mAlarmSoundButton->setEnabled(enable); 368 mAlarmSoundButton->setEnabled(enable);
369 mAlarmProgramButton->setEnabled(enable); 369 mAlarmProgramButton->setEnabled(enable);
370 mAlarmIncrCombo->setEnabled(enable); 370 mAlarmIncrCombo->setEnabled(enable);
371} 371}
372 372
373void KOEditorGeneral::disableAlarmEdit(bool disable) 373void KOEditorGeneral::disableAlarmEdit(bool disable)
374{ 374{
375 enableAlarmEdit( !disable ); 375 enableAlarmEdit( !disable );
376} 376}
377 377
378void KOEditorGeneral::enableAlarm( bool enable ) 378void KOEditorGeneral::enableAlarm( bool enable )
379{ 379{
380 enableAlarmEdit( enable ); 380 enableAlarmEdit( enable );
381} 381}
382 382
383void KOEditorGeneral::alarmDisable(bool disable) 383void KOEditorGeneral::alarmDisable(bool disable)
384{ 384{
385 if (!disable) { 385 if (!disable) {
386 //mAlarmBell->setEnabled(true); 386 //mAlarmBell->setEnabled(true);
387 mAlarmButton->setEnabled(true); 387 mAlarmButton->setEnabled(true);
388 } else { 388 } else {
389 //mAlarmBell->setEnabled(false); 389 //mAlarmBell->setEnabled(false);
390 mAlarmButton->setEnabled(false); 390 mAlarmButton->setEnabled(false);
391 mAlarmButton->setChecked(false); 391 mAlarmButton->setChecked(false);
392 mAlarmTimeEdit->setEnabled(false); 392 mAlarmTimeEdit->setEnabled(false);
393 mAlarmSoundButton->setEnabled(false); 393 mAlarmSoundButton->setEnabled(false);
394 mAlarmProgramButton->setEnabled(false); 394 mAlarmProgramButton->setEnabled(false);
395 mAlarmIncrCombo->setEnabled(false); 395 mAlarmIncrCombo->setEnabled(false);
396 } 396 }
397} 397}
398 398
399void KOEditorGeneral::setCategories(const QString &str) 399void KOEditorGeneral::setCategories(const QString &str)
400{ 400{
401 QString tt = str; 401 QString tt = str;
402 QToolTip::add( mCategoriesLabel, i18n("<b>Click here to edit categories: </b>") +"<em>"+tt.replace( QRegExp(","),", ")+"</em>"); 402 QToolTip::add( mCategoriesLabel, i18n("<b>Click here to edit categories: </b>") +"<em>"+tt.replace( QRegExp(","),", ")+"</em>");
403 mCategoriesLabel->setText(str); 403 mCategoriesLabel->setText(str);
404} 404}
405 405
406void KOEditorGeneral::setDefaults(bool allDay) 406void KOEditorGeneral::setDefaults(bool allDay)
407{ 407{
408#if 0 408#if 0
409 mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName()); 409 mOwnerLabel->setText(i18n("Owner: ") + KOPrefs::instance()->fullName());
410#endif 410#endif
411 411
412 mAlarmMessage = i18n("Edit new item"); 412 mAlarmMessage = i18n("Edit new item");
413 enableAlarmEdit( !allDay ); 413 enableAlarmEdit( !allDay );
414 414
415 // TODO: Implement a KPrefsComboItem to solve this in a clean way. 415 // TODO: Implement a KPrefsComboItem to solve this in a clean way.
416 int alarmTime; 416 int alarmTime;
417 int a[] = { 1,5,10,15,30,60,180, 1440 }; 417 int a[] = { 1,5,10,15,30,60,180, 1440 };
418 int index = KOPrefs::instance()->mAlarmTime; 418 int index = KOPrefs::instance()->mAlarmTime;
419 if (index < 0 || index > 7) { 419 if (index < 0 || index > 7) {
420 alarmTime = 15; 420 alarmTime = 15;
421 } else { 421 } else {
422 alarmTime = a[index]; 422 alarmTime = a[index];
423 } 423 }
424 mAlarmButton ->setChecked( false ); 424 mAlarmButton ->setChecked( false );
425 mAlarmTimeEdit->setValue(alarmTime); 425 mAlarmTimeEdit->setValue(alarmTime);
426 mAlarmIncrCombo->setCurrentItem(0); 426 mAlarmIncrCombo->setCurrentItem(0);
427 enableAlarmEdit( false ); 427 enableAlarmEdit( false );
428 //alarmDisable (false); 428 //alarmDisable (false);
429 mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic); 429 mSecrecyCombo->setCurrentItem(Incidence::SecrecyPublic);
430 mCancelBox->setChecked( false ); 430 mCancelBox->setChecked( false );
431 mSummaryEdit->setEditText(""); 431 mSummaryEdit->setEditText("");
432 mLocationEdit->setEditText(""); 432 mLocationEdit->setEditText("");
433 mDescriptionEdit->setText(""); 433 mDescriptionEdit->setText("");
434 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile; 434 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
435 setCategories(""); 435 setCategories("");
436} 436}
437void KOEditorGeneral::setSecrecy( int num ) 437void KOEditorGeneral::setSecrecy( int num )
438{ 438{
439 mSecrecyCombo->setCurrentItem(num); 439 mSecrecyCombo->setCurrentItem(num);
440} 440}
441void KOEditorGeneral::readIncidence(Incidence *event) 441void KOEditorGeneral::readIncidence(Incidence *event)
442{ 442{
443 443
444 mAlarmMessage = event->summary(); 444 mAlarmMessage = event->summary();
445 if ( ! event->location().isEmpty() ) 445 if ( ! event->location().isEmpty() )
446 mAlarmMessage += " ("+event->location()+")"; 446 mAlarmMessage += " ("+event->location()+")";
447 mAlarmIncrCombo->setCurrentItem(0); 447 mAlarmIncrCombo->setCurrentItem(0);
448 mSummaryEdit->setEditText(event->summary()); 448 mSummaryEdit->setEditText(event->summary());
449 mLocationEdit->setEditText(event->location()); 449 mLocationEdit->setEditText(event->location());
450 mDescriptionEdit->setText(event->description()); 450 mDescriptionEdit->setText(event->description());
451 451
452#if 0 452#if 0
453 // organizer information 453 // organizer information
454 mOwnerLabel->setText(i18n("Owner: ") + event->organizer()); 454 mOwnerLabel->setText(i18n("Owner: ") + event->organizer());
455#endif 455#endif
456 456
457 enableAlarmEdit( event->isAlarmEnabled() ); 457 enableAlarmEdit( event->isAlarmEnabled() );
458 //qDebug("KOEditorGeneral::readIncidence(Incidence *event) "); 458 //qDebug("KOEditorGeneral::readIncidence(Incidence *event) ");
459 if(!event->isAlarmEnabled()) { 459 if(!event->isAlarmEnabled()) {
460 // TODO: Implement a KPrefsComboItem to solve this in a clean way. 460 // TODO: Implement a KPrefsComboItem to solve this in a clean way.
461 int alarmTime; 461 int alarmTime;
462 int a[] = { 1,5,10,15,30,60,180, 1440 }; 462 int a[] = { 1,5,10,15,30,60,180, 1440 };
463 int index = KOPrefs::instance()->mAlarmTime; 463 int index = KOPrefs::instance()->mAlarmTime;
464 if (index < 0 || index > 7) { 464 if (index < 0 || index > 7) {
465 alarmTime = 15; 465 alarmTime = 15;
466 } else { 466 } else {
467 alarmTime = a[index]; 467 alarmTime = a[index];
468 } 468 }
469 mAlarmTimeEdit->setValue(alarmTime); 469 mAlarmTimeEdit->setValue(alarmTime);
470 } 470 }
471 mAlarmButton->setChecked( event->isAlarmEnabled() ); 471 mAlarmButton->setChecked( event->isAlarmEnabled() );
472 mSecrecyCombo->setCurrentItem(event->secrecy()); 472 mSecrecyCombo->setCurrentItem(event->secrecy());
473 mCancelBox->setChecked( event->cancelled() ); 473 mCancelBox->setChecked( event->cancelled() );
474 mAlarmProgramButton->setOn(false); 474 mAlarmProgramButton->setOn(false);
475 mAlarmSoundButton->setOn(false); 475 mAlarmSoundButton->setOn(false);
476 476
477 // set up alarm stuff 477 // set up alarm stuff
478 QPtrList<Alarm> alarms = event->alarms(); 478 QPtrList<Alarm> alarms = event->alarms();
479 Alarm* alarm; 479 Alarm* alarm;
480 mAlarmIncrCombo->setCurrentItem(0); 480 mAlarmIncrCombo->setCurrentItem(0);
481 for ( alarm = alarms.first(); alarm; alarm = alarms.next() ) { 481 for ( alarm = alarms.first(); alarm; alarm = alarms.next() ) {
482 int offset; 482 int offset;
483 if ( alarm->hasTime() ) { 483 if ( alarm->hasTime() ) {
484 QDateTime t = alarm->time(); 484 QDateTime t = alarm->time();
485 offset = event->dtStart().secsTo( t ); 485 offset = event->dtStart().secsTo( t );
486 } else { 486 } else {
487 offset = alarm->startOffset().asSeconds(); 487 offset = alarm->startOffset().asSeconds();
488 } 488 }
489 if ( offset != 0 ) { 489 if ( offset != 0 ) {
490 offset = offset / -60; // make minutes 490 offset = offset / -60; // make minutes
491 if (offset % 60 == 0) { // divides evenly into hours? 491 if (offset % 60 == 0) { // divides evenly into hours?
492 offset = offset / 60; 492 offset = offset / 60;
493 mAlarmIncrCombo->setCurrentItem(1); 493 mAlarmIncrCombo->setCurrentItem(1);
494 if (offset % 24 == 0) { // divides evenly into days? 494 if (offset % 24 == 0) { // divides evenly into days?
495 offset = offset / 24; 495 offset = offset / 24;
496 mAlarmIncrCombo->setCurrentItem(2); 496 mAlarmIncrCombo->setCurrentItem(2);
497 } 497 }
498 } 498 }
499 } 499 }
500 mAlarmTimeEdit->setValue( offset ); 500 mAlarmTimeEdit->setValue( offset );
501 if (alarm->type() == Alarm::Procedure) { 501 if (alarm->type() == Alarm::Procedure) {
502 502
503 mAlarmProgram = alarm->programFile(); 503 mAlarmProgram = alarm->programFile();
504 mAlarmProgramButton->setOn(true); 504 mAlarmProgramButton->setOn(true);
505 QString dispStr = i18n("Running '%1'").arg(mAlarmProgram); 505 QString dispStr = i18n("Running '%1'").arg(mAlarmProgram);
506 QToolTip::add(mAlarmProgramButton, dispStr); 506 QToolTip::add(mAlarmProgramButton, dispStr);
507 } 507 }
508 else if (alarm->type() == Alarm::Audio) { 508 else if (alarm->type() == Alarm::Audio) {
509 mAlarmSound = alarm->audioFile(); 509 mAlarmSound = alarm->audioFile();
510 if ( ! QFile::exists( mAlarmSound ) ) 510 if ( ! QFile::exists( mAlarmSound ) )
511 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile; 511 mAlarmSound = KOPrefs::instance()->mDefaultAlarmFile;
512 mAlarmSoundButton->setOn(true); 512 mAlarmSoundButton->setOn(true);
513 QString dispStr = i18n("Playing '%1'").arg(mAlarmSound); 513 QString dispStr = i18n("Playing '%1'").arg(mAlarmSound);
514 QToolTip::add(mAlarmSoundButton, dispStr); 514 QToolTip::add(mAlarmSoundButton, dispStr);
515 } 515 }
516 mAlarmButton->setChecked(alarm->enabled()); 516 mAlarmButton->setChecked(alarm->enabled());
517 enableAlarmEdit( alarm->enabled() ); 517 enableAlarmEdit( alarm->enabled() );
518 //qDebug("nableAlarmEdit( alarm->enabled() )********* "); 518 //qDebug("nableAlarmEdit( alarm->enabled() )********* ");
519 // TODO: Deal with multiple alarms 519 // TODO: Deal with multiple alarms
520 break; // For now, stop after the first alarm 520 break; // For now, stop after the first alarm
521 } 521 }
522 522
523 setCategories(event->categoriesStr()); 523 setCategories(event->categoriesStr());
524} 524}
525 525
526void KOEditorGeneral::writeIncidence(Incidence *event) 526void KOEditorGeneral::writeIncidence(Incidence *event)
527{ 527{
528 // kdDebug() << "KOEditorGeneral::writeEvent()" << endl; 528 // kdDebug() << "KOEditorGeneral::writeEvent()" << endl;
529 mLocationEdit->save(KOLocationBox::LOCATION); 529 mLocationEdit->save(KOLocationBox::LOCATION);
530 event->setSummary(mSummaryEdit->currentText()); 530 event->setSummary(mSummaryEdit->currentText());
531 event->setLocation(mLocationEdit->currentText()); 531 event->setLocation(mLocationEdit->currentText());
532 event->setDescription(mDescriptionEdit->text()); 532 event->setDescription(mDescriptionEdit->text());
533 event->setCategories(mCategoriesLabel->text()); 533 event->setCategories(mCategoriesLabel->text());
534 event->setSecrecy(mSecrecyCombo->currentItem()); 534 event->setSecrecy(mSecrecyCombo->currentItem());
535 event->setCancelled(mCancelBox->isChecked() );; 535 event->setCancelled(mCancelBox->isChecked() );;
536 // alarm stuff 536 // alarm stuff
537 if (mAlarmButton->isChecked()) { 537 if (mAlarmButton->isChecked()) {
538 if (event->alarms().count() == 0) 538 if (event->alarms().count() == 0)
539 event->newAlarm(); 539 event->newAlarm();
540 QPtrList<Alarm> alarms = event->alarms(); 540 QPtrList<Alarm> alarms = event->alarms();
541 Alarm *alarm; 541 Alarm *alarm;
542 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) { 542 for (alarm = alarms.first(); alarm; alarm = alarms.next() ) {
543 alarm->setEnabled(true); 543 alarm->setEnabled(true);
544 int j = mAlarmTimeEdit->value()* -60; 544 int j = mAlarmTimeEdit->value()* -60;
545 if (mAlarmIncrCombo->currentItem() == 1) 545 if (mAlarmIncrCombo->currentItem() == 1)
546 j = j * 60; 546 j = j * 60;
547 else if (mAlarmIncrCombo->currentItem() == 2) 547 else if (mAlarmIncrCombo->currentItem() == 2)
548 j = j * (60 * 24); 548 j = j * (60 * 24);
549 alarm->setStartOffset( j ); 549 alarm->setStartOffset( j );
550 550
551 if (!mAlarmProgram.isEmpty() && mAlarmProgramButton->isOn()) { 551 if (!mAlarmProgram.isEmpty() && mAlarmProgramButton->isOn()) {
552 alarm->setProcedureAlarm(mAlarmProgram); 552 alarm->setProcedureAlarm(mAlarmProgram);
553 } 553 }
554 else if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn()) 554 else if (!mAlarmSound.isEmpty() && mAlarmSoundButton->isOn())
555 alarm->setAudioAlarm(mAlarmSound); 555 alarm->setAudioAlarm(mAlarmSound);
556 else 556 else
557 alarm->setType(Alarm::Invalid); 557 alarm->setType(Alarm::Invalid);
558 //alarm->setAudioAlarm("default"); 558 //alarm->setAudioAlarm("default");
559 // TODO: Deal with multiple alarms 559 // TODO: Deal with multiple alarms
560 break; // For now, stop after the first alarm 560 break; // For now, stop after the first alarm
561 } 561 }
562 } else { 562 } else {
563 Alarm* alarm = event->alarms().first(); 563 Alarm* alarm = event->alarms().first();
564 if ( alarm ) { 564 if ( alarm ) {
565 alarm->setEnabled(false); 565 alarm->setEnabled(false);
566 alarm->setType(Alarm::Invalid); 566 alarm->setType(Alarm::Invalid);
567 } 567 }
568 } 568 }
569} 569}
diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp
index 9db2040..02d7aae 100644
--- a/korganizer/koprefs.cpp
+++ b/korganizer/koprefs.cpp
@@ -1,603 +1,603 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <time.h> 24#include <time.h>
25#ifndef _WIN32_ 25#ifndef _WIN32_
26#include <unistd.h> 26#include <unistd.h>
27#endif 27#endif
28#include <qdir.h> 28#include <qdir.h>
29#include <qtextstream.h> 29#include <qtextstream.h>
30#include <qtextcodec.h> 30#include <qtextcodec.h>
31#include <qstring.h> 31#include <qstring.h>
32#include <qregexp.h> 32#include <qregexp.h>
33#include <qfont.h> 33#include <qfont.h>
34#include <qcolor.h> 34#include <qcolor.h>
35#include <qstringlist.h> 35#include <qstringlist.h>
36#include <stdlib.h> 36#include <stdlib.h>
37 37
38#include <kglobal.h> 38#include <kglobal.h>
39#include <kglobalsettings.h> 39#include <kglobalsettings.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <klocale.h> 41#include <klocale.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kemailsettings.h> 43#include <kemailsettings.h>
44#include <kstaticdeleter.h> 44#include <kstaticdeleter.h>
45#include <libkdepim/kpimglobalprefs.h> 45#include <libkdepim/kpimglobalprefs.h>
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48#include "mainwindow.h" 48#include "mainwindow.h"
49 49
50KOPrefs *KOPrefs::mInstance = 0; 50KOPrefs *KOPrefs::mInstance = 0;
51static KStaticDeleter<KOPrefs> insd; 51static KStaticDeleter<KOPrefs> insd;
52 52
53KOPrefs::KOPrefs() : 53KOPrefs::KOPrefs() :
54 KPimPrefs("korganizerrc") 54 KPimPrefs("korganizerrc")
55{ 55{
56 mCategoryColors.setAutoDelete(true); 56 mCategoryColors.setAutoDelete(true);
57 fillMailDefaults(); 57 fillMailDefaults();
58 mDefaultCategoryColor = QColor(175,210,255);//196,196,196); 58 mDefaultCategoryColor = QColor(175,210,255);//196,196,196);
59 QColor defaultHolidayColor = QColor(255,0,0); 59 QColor defaultHolidayColor = QColor(255,0,0);
60 QColor defaultHighlightColor = QColor(129,112,255);//64,64,255); 60 QColor defaultHighlightColor = QColor(129,112,255);//64,64,255);
61 QColor defaultAgendaBgColor = QColor(239,241,169);//128,128,128); 61 QColor defaultAgendaBgColor = QColor(239,241,169);//128,128,128);
62 QColor defaultWorkingHoursColor = QColor(170,223,150);//160,160,160); 62 QColor defaultWorkingHoursColor = QColor(170,223,150);//160,160,160);
63 QColor defaultTodoDueTodayColor = QColor(255,220,100); 63 QColor defaultTodoDueTodayColor = QColor(255,220,100);
64 QColor defaultTodoOverdueColor = QColor(255,153,125); 64 QColor defaultTodoOverdueColor = QColor(255,153,125);
65 QColor defaultTodoRunColor = QColor(99,194,30); 65 QColor defaultTodoRunColor = QColor(99,194,30);
66 KPrefs::setCurrentGroup("General"); 66 KPrefs::setCurrentGroup("General");
67 addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false); 67 addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false);
68 addItemBool("ShowIconNewTodo",&mShowIconNewTodo,true); 68 addItemBool("ShowIconNewTodo",&mShowIconNewTodo,true);
69 addItemBool("ShowIconNewEvent",&mShowIconNewEvent,true); 69 addItemBool("ShowIconNewEvent",&mShowIconNewEvent,true);
70 addItemBool("ShowIconSearch",&mShowIconSearch,true); 70 addItemBool("ShowIconSearch",&mShowIconSearch,true);
71 addItemBool("ShowIconList",&mShowIconList,true); 71 addItemBool("ShowIconList",&mShowIconList,true);
72 addItemBool("ShowIconDay1",&mShowIconDay1,true); 72 addItemBool("ShowIconDay1",&mShowIconDay1,true);
73 addItemBool("ShowIconDay5",&mShowIconDay5,true); 73 addItemBool("ShowIconDay5",&mShowIconDay5,true);
74 addItemBool("ShowIconDay6",&mShowIconDay6,true); 74 addItemBool("ShowIconDay6",&mShowIconDay6,true);
75 addItemBool("ShowIconDay7",&mShowIconDay7,true); 75 addItemBool("ShowIconDay7",&mShowIconDay7,true);
76 addItemBool("ShowIconMonth",&mShowIconMonth,true); 76 addItemBool("ShowIconMonth",&mShowIconMonth,true);
77 addItemBool("ShowIconTodoview",&mShowIconTodoview,true); 77 addItemBool("ShowIconTodoview",&mShowIconTodoview,true);
78 addItemBool("ShowIconBackFast",&mShowIconBackFast,true); 78 addItemBool("ShowIconBackFast",&mShowIconBackFast,true);
79 addItemBool("ShowIconBack",&mShowIconBack,true); 79 addItemBool("ShowIconBack",&mShowIconBack,true);
80 addItemBool("ShowIconToday",&mShowIconToday,true); 80 addItemBool("ShowIconToday",&mShowIconToday,true);
81 addItemBool("ShowIconForward",&mShowIconForward,true); 81 addItemBool("ShowIconForward",&mShowIconForward,true);
82 addItemBool("ShowIconForwardFast",&mShowIconForwardFast,true); 82 addItemBool("ShowIconForwardFast",&mShowIconForwardFast,true);
83 addItemBool("ShowIconWhatsThis",&mShowIconWhatsThis,true); 83 addItemBool("ShowIconWhatsThis",&mShowIconWhatsThis,true);
84 addItemBool("ShowIconWeekNum",&mShowIconWeekNum,true); 84 addItemBool("ShowIconWeekNum",&mShowIconWeekNum,true);
85 addItemBool("ShowIconNextDays",&mShowIconNextDays,true); 85 addItemBool("ShowIconNextDays",&mShowIconNextDays,true);
86 addItemBool("ShowIconNext",&mShowIconNext,true); 86 addItemBool("ShowIconNext",&mShowIconNext,true);
87 addItemBool("ShowIconJournal",&mShowIconJournal,true); 87 addItemBool("ShowIconJournal",&mShowIconJournal,true);
88 addItemBool("ShowIconStretch",&mShowIconStretch,true); 88 addItemBool("ShowIconStretch",&mShowIconStretch,true);
89 addItemBool("ShowIconFilter",&mShowIconFilter,false); 89 addItemBool("ShowIconFilter",&mShowIconFilter,false);
90 addItemBool("ShowIconOnetoolbar",&mShowIconOnetoolbar,true); 90 addItemBool("ShowIconOnetoolbar",&mShowIconOnetoolbar,true);
91 91
92 bool addIcons = false; 92 bool addIcons = false;
93#ifdef DESKTOP_VERSION 93#ifdef DESKTOP_VERSION
94 addIcons = true; 94 addIcons = true;
95#endif 95#endif
96 addItemBool("ShowIconNavigator",&mShowIconNavigator,addIcons); 96 addItemBool("ShowIconNavigator",&mShowIconNavigator,addIcons);
97 addItemBool("ShowIconAllday",&mShowIconAllday,addIcons); 97 addItemBool("ShowIconAllday",&mShowIconAllday,addIcons);
98 addItemBool("ShowIconFilterview",&mShowIconFilterview,addIcons); 98 addItemBool("ShowIconFilterview",&mShowIconFilterview,addIcons);
99 addItemBool("ShowIconToggleFull",&mShowIconToggleFull,addIcons); 99 addItemBool("ShowIconToggleFull",&mShowIconToggleFull,addIcons);
100 100
101 addItemInt("LastLoadedLanguage",&mOldLanguage,0); 101 addItemInt("LastLoadedLanguage",&mOldLanguage,0);
102 102
103 addItemBool("AskForQuit",&mAskForQuit,false); 103 addItemBool("AskForQuit",&mAskForQuit,false);
104 104
105#ifndef DESKTOP_VERSION 105#ifndef DESKTOP_VERSION
106 addItemBool("ShowFullMenu",&mShowFullMenu,false); 106 addItemBool("ShowFullMenu",&mShowFullMenu,false);
107#else 107#else
108 addItemBool("ShowFullMenu",&mShowFullMenu,true); 108 addItemBool("ShowFullMenu",&mShowFullMenu,true);
109#endif 109#endif
110 addItemBool("ToolBarHor",&mToolBarHor, true ); 110 addItemBool("ToolBarHor",&mToolBarHor, true );
111 addItemBool("ToolBarUp",&mToolBarUp, false ); 111 addItemBool("ToolBarUp",&mToolBarUp, false );
112 addItemBool("ToolBarHorV",&mToolBarHorV, true ); 112 addItemBool("ToolBarHorV",&mToolBarHorV, true );
113 addItemBool("ToolBarUpV",&mToolBarUpV, false ); 113 addItemBool("ToolBarUpV",&mToolBarUpV, false );
114 addItemBool("ToolBarHorN",&mToolBarHorN, true ); 114 addItemBool("ToolBarHorN",&mToolBarHorN, true );
115 addItemBool("ToolBarUpN",&mToolBarUpN, false ); 115 addItemBool("ToolBarUpN",&mToolBarUpN, false );
116 addItemBool("ToolBarHorF",&mToolBarHorF, true ); 116 addItemBool("ToolBarHorF",&mToolBarHorF, true );
117 addItemBool("ToolBarUpF",&mToolBarUpF, false ); 117 addItemBool("ToolBarUpF",&mToolBarUpF, false );
118 addItemBool("ToolBarMiniIcons",&mToolBarMiniIcons, false ); 118 addItemBool("ToolBarMiniIcons",&mToolBarMiniIcons, false );
119 addItemInt("Whats Next Days",&mWhatsNextDays,3); 119 addItemInt("Whats Next Days",&mWhatsNextDays,3);
120 addItemInt("Whats Next Prios",&mWhatsNextPrios,1); 120 addItemInt("Whats Next Prios",&mWhatsNextPrios,1);
121 121
122 addItemBool("ShowTodoInAgenda",&mShowTodoInAgenda,true); 122 addItemBool("ShowTodoInAgenda",&mShowTodoInAgenda,true);
123 addItemBool("ShowCompletedTodoInAgenda",&mShowCompletedTodoInAgenda,true); 123 addItemBool("ShowCompletedTodoInAgenda",&mShowCompletedTodoInAgenda,true);
124 addItemBool("ShowTimeInAgenda",&mShowTimeInAgenda,true); 124 addItemBool("ShowTimeInAgenda",&mShowTimeInAgenda,true);
125 addItemBool("HideNonStartedTodos",&mHideNonStartedTodos,false); 125 addItemBool("HideNonStartedTodos",&mHideNonStartedTodos,false);
126 addItemBool("ShowCompletedTodo",&mShowCompletedTodo,true); 126 addItemBool("ShowCompletedTodo",&mShowCompletedTodo,true);
127 addItemInt("AllDay Size",&mAllDaySize,28); 127 addItemInt("AllDay Size",&mAllDaySize,28);
128 QString defAlarm = KGlobal::iconLoader()->iconPath()+"koalarm.wav"; 128 QString defAlarm = KGlobal::iconLoader()->iconPath()+"koalarm.wav";
129 addItemString("DefaultAlarmFile",&mDefaultAlarmFile,defAlarm ); 129 addItemString("DefaultAlarmFile",&mDefaultAlarmFile,defAlarm );
130 130
131 addItemStringList("LocationDefaults",&mLocationDefaults ); 131 addItemStringList("LocationDefaults",&mLocationDefaults );
132 addItemStringList("EventSummary User",&mEventSummaryUser); 132 addItemStringList("EventSummary User",&mEventSummaryUser);
133 addItemStringList("TodoSummary User",&mTodoSummaryUser); 133 addItemStringList("TodoSummary User",&mTodoSummaryUser);
134 134
135 addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false); 135 addItemBool("Enable Group Scheduling",&mEnableGroupScheduling,false);
136 addItemBool("Enable Project View",&mEnableProjectView,false); 136 addItemBool("Enable Project View",&mEnableProjectView,false);
137 addItemBool("Auto Save",&mAutoSave,false); 137 addItemBool("Auto Save",&mAutoSave,false);
138 addItemInt("Auto Save Interval",&mAutoSaveInterval,3); 138 addItemInt("Auto Save Interval",&mAutoSaveInterval,3);
139 addItemBool("Confirm Deletes",&mConfirm,true); 139 addItemBool("Confirm Deletes",&mConfirm,true);
140 addItemString("Archive File",&mArchiveFile); 140 addItemString("Archive File",&mArchiveFile);
141 addItemString("Html Export File",&mHtmlExportFile, 141 addItemString("Html Export File",&mHtmlExportFile,
142 QDir::homeDirPath() + "/" + i18n("Default export file", "calendar.html")); 142 QDir::homeDirPath() + "/" + i18n("Default export file", "calendar.html"));
143 addItemBool("Html With Save",&mHtmlWithSave,false); 143 addItemBool("Html With Save",&mHtmlWithSave,false);
144 144
145 KPrefs::setCurrentGroup("Personal Settings"); 145 KPrefs::setCurrentGroup("Personal Settings");
146 146
147 addItemInt("Mail Client",&mMailClient,MailClientKMail); 147 addItemInt("Mail Client",&mMailClient,MailClientKMail);
148 addItemBool("Use Control Center Email",&mEmailControlCenter,false); 148 addItemBool("Use Control Center Email",&mEmailControlCenter,false);
149 addItemBool("Bcc",&mBcc,false); 149 addItemBool("Bcc",&mBcc,false);
150 150
151 KPrefs::setCurrentGroup("Time & Date"); 151 KPrefs::setCurrentGroup("Time & Date");
152 152
153 153
154 addItemInt("Default Start Time",&mStartTime,10); 154 addItemInt("Default Start Time",&mStartTime,10);
155 addItemInt("Default Duration",&mDefaultDuration,2); 155 addItemInt("Default Duration",&mDefaultDuration,2);
156 addItemInt("Default Alarm Time",&mAlarmTime,3); 156 addItemInt("Default Alarm Time",&mAlarmTime,3);
157 KPrefs::setCurrentGroup("AlarmSettings"); 157 KPrefs::setCurrentGroup("AlarmSettings");
158 addItemInt("AlarmPlayBeeps",&mAlarmPlayBeeps,20); 158 addItemInt("AlarmPlayBeeps",&mAlarmPlayBeeps,20);
159 addItemInt("AlarmSuspendTime",&mAlarmSuspendTime,7); 159 addItemInt("AlarmSuspendTime",&mAlarmSuspendTime,7);
160 addItemInt("AlarmSuspendCount",&mAlarmSuspendCount,5); 160 addItemInt("AlarmSuspendCount",&mAlarmSuspendCount,5);
161 addItemInt("AlarmBeepInterval",&mAlarmBeepInterval,3); 161 addItemInt("AlarmBeepInterval",&mAlarmBeepInterval,3);
162 162
163 163
164 KPrefs::setCurrentGroup("Calendar"); 164 KPrefs::setCurrentGroup("Calendar");
165 165
166 addItemInt("Default Calendar Format",&mDefaultFormat,FormatICalendar); 166 addItemInt("Default Calendar Format",&mDefaultFormat,FormatICalendar);
167 167
168 KPrefs::setCurrentGroup("Fonts"); 168 KPrefs::setCurrentGroup("Fonts");
169 // qDebug(" KPrefs::setCurrentGroup(Fonts); "); 169 // qDebug(" KPrefs::setCurrentGroup(Fonts); ");
170 QFont fon = KGlobalSettings::generalFont(); 170 QFont fon = KGlobalSettings::generalFont();
171 addItemFont("TimeBar Font",&mTimeBarFont,fon ); 171 addItemFont("TimeBar Font",&mTimeBarFont,fon );
172 addItemFont("MonthView Font",&mMonthViewFont,fon); 172 addItemFont("MonthView Font",&mMonthViewFont,fon);
173 addItemFont("AgendaView Font",&mAgendaViewFont,fon); 173 addItemFont("AgendaView Font",&mAgendaViewFont,fon);
174 addItemFont("MarcusBains Font",&mMarcusBainsFont,fon); 174 addItemFont("MarcusBains Font",&mMarcusBainsFont,fon);
175 addItemFont("TimeLabels Font",&mTimeLabelsFont,fon); 175 addItemFont("TimeLabels Font",&mTimeLabelsFont,fon);
176 addItemFont("TodoView Font",&mTodoViewFont,fon); 176 addItemFont("TodoView Font",&mTodoViewFont,fon);
177 addItemFont("ListView Font",&mListViewFont,fon); 177 addItemFont("ListView Font",&mListViewFont,fon);
178 addItemFont("DateNavigator Font",&mDateNavigatorFont,fon); 178 addItemFont("DateNavigator Font",&mDateNavigatorFont,fon);
179 addItemFont("EditBox Font",&mEditBoxFont,fon); 179 addItemFont("EditBox Font",&mEditBoxFont,fon);
180 addItemFont("JournalView Font",&mJornalViewFont,fon); 180 addItemFont("JournalView Font",&mJornalViewFont,fon);
181 addItemFont("WhatsNextView Font",&mWhatsNextFont,fon); 181 addItemFont("WhatsNextView Font",&mWhatsNextFont,fon);
182 addItemFont("EventView Font",&mEventViewFont,fon); 182 addItemFont("EventView Font",&mEventViewFont,fon);
183 183
184 KPrefs::setCurrentGroup("RemoteSyncing"); 184 KPrefs::setCurrentGroup("RemoteSyncing");
185 addItemString("ActiveSyncPort",&mActiveSyncPort,"9197" ); 185 addItemString("ActiveSyncPort",&mActiveSyncPort,"9197" );
186 addItemString("ActiveSyncIP",&mActiveSyncIP,"192.168.0.40" ); 186 addItemString("ActiveSyncIP",&mActiveSyncIP,"192.168.0.40" );
187 addItemBool("ShowSyncEvents",&mShowSyncEvents,false); 187 addItemBool("ShowSyncEvents",&mShowSyncEvents,false);
188 addItemInt("LastSyncTime",&mLastSyncTime,0); 188 addItemInt("LastSyncTime",&mLastSyncTime,0);
189 189
190#ifdef _WIN32_ 190#ifdef _WIN32_
191 QString hdp= locateLocal("data","korganizer")+"\\\\"; 191 QString hdp= locateLocal("data","korganizer")+"\\\\";
192#else 192#else
193 QString hdp= locateLocal("data","korganizer")+"/"; 193 QString hdp= locateLocal("data","korganizer")+"/";
194#endif 194#endif
195 195
196 KPrefs::setCurrentGroup("LoadSaveFileNames"); 196 KPrefs::setCurrentGroup("LoadSaveFileNames");
197 197
198 addItemString("LastImportFile", &mLastImportFile ,hdp +"import.ics" ); 198 addItemString("LastImportFile", &mLastImportFile ,hdp +"import.ics" );
199 addItemString("LastVcalFile", &mLastVcalFile ,hdp +"export.vcs" ); 199 addItemString("LastVcalFile", &mLastVcalFile ,hdp +"export.vcs" );
200 addItemString("LastSaveFile", &mLastSaveFile ,hdp +"mybackup.ics" ); 200 addItemString("LastSaveFile", &mLastSaveFile ,hdp +"mybackup.ics" );
201 addItemString("LastLoadFile", &mLastLoadFile ,hdp +"mybackup.ics" ); 201 addItemString("LastLoadFile", &mLastLoadFile ,hdp +"mybackup.ics" );
202 202
203 203
204 KPrefs::setCurrentGroup("Locale"); 204 KPrefs::setCurrentGroup("Locale");
205 addItemBool("ShortDateInViewer",&mShortDateInViewer,false); 205 addItemBool("ShortDateInViewer",&mShortDateInViewer,false);
206 206
207 207
208 KPrefs::setCurrentGroup("Colors"); 208 KPrefs::setCurrentGroup("Colors");
209 addItemColor("Holiday Color",&mHolidayColor,defaultHolidayColor); 209 addItemColor("Holiday Color",&mHolidayColor,defaultHolidayColor);
210 addItemColor("Highlight Color",&mHighlightColor,defaultHighlightColor); 210 addItemColor("Highlight Color",&mHighlightColor,defaultHighlightColor);
211 addItemColor("Event Color",&mEventColor,mDefaultCategoryColor); 211 addItemColor("Event Color",&mEventColor,mDefaultCategoryColor);
212 addItemColor("Todo done Color",&mTodoDoneColor,QColor(111,255,115) ); 212 addItemColor("Todo done Color",&mTodoDoneColor,QColor(111,255,115) );
213 addItemColor("Agenda Background Color",&mAgendaBgColor,defaultAgendaBgColor); 213 addItemColor("Agenda Background Color",&mAgendaBgColor,defaultAgendaBgColor);
214 addItemColor("WorkingHours Color",&mWorkingHoursColor,defaultWorkingHoursColor); 214 addItemColor("WorkingHours Color",&mWorkingHoursColor,defaultWorkingHoursColor);
215 addItemColor("Todo due today Color",&mTodoDueTodayColor,defaultTodoDueTodayColor); 215 addItemColor("Todo due today Color",&mTodoDueTodayColor,defaultTodoDueTodayColor);
216 addItemColor("Todo overdue Color",&mTodoOverdueColor,defaultTodoOverdueColor); 216 addItemColor("Todo overdue Color",&mTodoOverdueColor,defaultTodoOverdueColor);
217 addItemColor("Todo running Color",&mTodoRunColor,defaultTodoRunColor); 217 addItemColor("Todo running Color",&mTodoRunColor,defaultTodoRunColor);
218 addItemColor("MonthViewEvenColor",&mMonthViewEvenColor,QColor( 160,160,255 )); 218 addItemColor("MonthViewEvenColor",&mMonthViewEvenColor,QColor( 160,160,255 ));
219 addItemColor("MonthViewOddColor",&mMonthViewOddColor,QColor( 160,255,160 )); 219 addItemColor("MonthViewOddColor",&mMonthViewOddColor,QColor( 160,255,160 ));
220 addItemColor("MonthViewHolidayColor",&mMonthViewHolidayColor,QColor( 255,160,160 )); 220 addItemColor("MonthViewHolidayColor",&mMonthViewHolidayColor,QColor( 255,160,160 ));
221 addItemBool("MonthViewUsesDayColors",&mMonthViewUsesDayColors,true); 221 addItemBool("MonthViewUsesDayColors",&mMonthViewUsesDayColors,true);
222 addItemBool("MonthViewSatSunTog",&mMonthViewSatSunTog,true); 222 addItemBool("MonthViewSatSunTog",&mMonthViewSatSunTog,true);
223 addItemBool("MonthViewWeek",&mMonthViewWeek,false); 223 addItemBool("MonthViewWeek",&mMonthViewWeek,false);
224 addItemBool("HightlightDateTimeEdit",&mHightlightDateTimeEdit,false); 224 addItemBool("HightlightDateTimeEdit",&mHightlightDateTimeEdit,false);
225 addItemColor("AppColor1",&mAppColor1,QColor( 130,170,255 )); 225 addItemColor("AppColor1",&mAppColor1,QColor( 130,170,255 ));
226 addItemColor("AppColor2",&mAppColor2,QColor( 174,216,255 )); 226 addItemColor("AppColor2",&mAppColor2,QColor( 174,216,255 ));
227 addItemBool("UseAppColors",&mUseAppColors,false); 227 addItemBool("UseAppColors",&mUseAppColors,false);
228 228
229 229
230 230
231 KPrefs::setCurrentGroup("Views"); 231 KPrefs::setCurrentGroup("Views");
232 addItemBool("Block Popup Menu",&mBlockPopupMenu,true); 232 addItemBool("Block Popup Menu",&mBlockPopupMenu,true);
233 addItemBool("Show Date Navigator",&mShowDateNavigator,true); 233 addItemBool("Show Date Navigator",&mShowDateNavigator,true);
234 addItemInt("Hour Size",&mHourSize,8); 234 addItemInt("Hour Size",&mHourSize,8);
235 addItemBool("Show Daily Recurrences",&mDailyRecur,true); 235 addItemBool("Show Daily Recurrences",&mDailyRecur,true);
236 addItemBool("Show Weekly Recurrences",&mWeeklyRecur,true); 236 addItemBool("Show Weekly Recurrences",&mWeeklyRecur,true);
237 addItemBool("Show Month Daily Recurrences",&mMonthDailyRecur,true); 237 addItemBool("Show Month Daily Recurrences",&mMonthDailyRecur,true);
238 addItemBool("Show Month Weekly Recurrences",&mMonthWeeklyRecur,true); 238 addItemBool("Show Month Weekly Recurrences",&mMonthWeeklyRecur,true);
239 addItemBool("ShowShortMonthName",&mMonthShowShort,false); 239 addItemBool("ShowShortMonthName",&mMonthShowShort,false);
240 addItemBool("ShowIconsInMonthCell",&mMonthShowIcons,true); 240 addItemBool("ShowIconsInMonthCell",&mMonthShowIcons,true);
241 addItemBool("ShowTimesInMonthCell",&mMonthShowTimes,true); 241 addItemBool("ShowTimesInMonthCell",&mMonthShowTimes,true);
242#ifdef DESKTOP_VERION 242#ifdef DESKTOP_VERION
243 addItemBool("Enable ToolTips",&mEnableToolTips,true); 243 addItemBool("Enable ToolTips",&mEnableToolTips,true);
244#else 244#else
245 addItemBool("Enable ToolTips",&mEnableToolTips,false); 245 addItemBool("Enable ToolTips",&mEnableToolTips,false);
246#endif 246#endif
247 addItemBool("Enable MonthView ScrollBars",&mEnableMonthScroll,false); 247 addItemBool("Enable MonthView ScrollBars",&mEnableMonthScroll,false);
248 addItemBool("Marcus Bains shows seconds",&mMarcusBainsShowSeconds,false); 248 addItemBool("Marcus Bains shows seconds",&mMarcusBainsShowSeconds,false);
249 addItemBool("Show Marcus Bains",&mMarcusBainsEnabled,true); 249 addItemBool("Show Marcus Bains",&mMarcusBainsEnabled,true);
250 addItemBool("EditOnDoubleClick",&mEditOnDoubleClick,true); 250 addItemBool("EditOnDoubleClick",&mEditOnDoubleClick,true);
251 addItemBool("ViewChangeHoldFullscreen",&mViewChangeHoldFullscreen,true); 251 addItemBool("ViewChangeHoldFullscreen",&mViewChangeHoldFullscreen,true);
252 addItemBool("ViewChangeHoldNonFullscreen",&mViewChangeHoldNonFullscreen,false); 252 addItemBool("ViewChangeHoldNonFullscreen",&mViewChangeHoldNonFullscreen,false);
253 addItemBool("CenterOnCurrentTime",&mCenterOnCurrentTime,false); 253 addItemBool("CenterOnCurrentTime",&mCenterOnCurrentTime,false);
254 addItemBool("SetTimeToDayStartAt",&mSetTimeToDayStartAt,true); 254 addItemBool("SetTimeToDayStartAt",&mSetTimeToDayStartAt,true);
255 addItemBool("HighlightCurrentDay",&mHighlightCurrentDay,true); 255 addItemBool("HighlightCurrentDay",&mHighlightCurrentDay,true);
256 addItemBool("WNViewShowsParents",&mWNViewShowsParents,true);; 256 addItemBool("WNViewShowsParents",&mWNViewShowsParents,true);;
257 addItemBool("WNViewShowsPast",&mWNViewShowsPast,true); 257 addItemBool("WNViewShowsPast",&mWNViewShowsPast,true);
258 addItemBool("WNViewShowLocation",&mWNViewShowLocation,false); 258 addItemBool("WNViewShowLocation",&mWNViewShowLocation,false);
259 addItemBool("UseHighlightLightColor",&mUseHighlightLightColor,false); 259 addItemBool("UseHighlightLightColor",&mUseHighlightLightColor,false);
260 addItemBool("ListViewMonthTimespan",&mListViewMonthTimespan,true); 260 addItemBool("ListViewMonthTimespan",&mListViewMonthTimespan,true);
261 addItemBool("TodoViewUsesCatColors",&mTodoViewUsesCatColors,false); 261 addItemBool("TodoViewUsesCatColors",&mTodoViewUsesCatColors,false);
262 addItemBool("TodoViewShowsPercentage",&mTodoViewShowsPercentage,false); 262 addItemBool("TodoViewShowsPercentage",&mTodoViewShowsPercentage,false);
263 addItemBool("TodoViewUsesSmallFont",&mTodoViewUsesSmallFont,true); 263 addItemBool("TodoViewUsesSmallFont",&mTodoViewUsesSmallFont,true);
264 addItemBool("MonthViewUsesBigFont",&mMonthViewUsesBigFont,true); 264 addItemBool("MonthViewUsesBigFont",&mMonthViewUsesBigFont,true);
265 addItemBool("TodoViewUsesForegroundColor",&mTodoViewUsesForegroundColor,false); 265 addItemBool("TodoViewUsesForegroundColor",&mTodoViewUsesForegroundColor,false);
266 addItemBool("MonthViewUsesForegroundColor",&mMonthViewUsesForegroundColor,false); 266 addItemBool("MonthViewUsesForegroundColor",&mMonthViewUsesForegroundColor,false);
267#ifdef DESKTOP_VERSION 267#ifdef DESKTOP_VERSION
268 addItemBool("UseInternalAlarmNotification",&mUseInternalAlarmNotification,true); 268 addItemBool("UseInternalAlarmNotification",&mUseInternalAlarmNotification,true);
269#else 269#else
270 addItemBool("UseInternalAlarmNotification",&mUseInternalAlarmNotification,false); 270 addItemBool("UseInternalAlarmNotification",&mUseInternalAlarmNotification,false);
271#endif 271#endif
272 addItemInt("Day Begins",&mDayBegins,7); 272 addItemInt("Day Begins",&mDayBegins,7);
273 addItemInt("Working Hours Start",&mWorkingHoursStart,8); 273 addItemInt("Working Hours Start",&mWorkingHoursStart,8);
274 addItemInt("Working Hours End",&mWorkingHoursEnd,17); 274 addItemInt("Working Hours End",&mWorkingHoursEnd,17);
275 addItemBool("Exclude Holidays",&mExcludeHolidays,true); 275 addItemBool("Exclude Holidays",&mExcludeHolidays,true);
276 addItemBool("Exclude Saturdays",&mExcludeSaturdays,true); 276 addItemBool("Exclude Saturdays",&mExcludeSaturdays,true);
277 277
278 addItemBool("Month View Uses Category Color",&mMonthViewUsesCategoryColor,false); 278 addItemBool("Month View Uses Category Color",&mMonthViewUsesCategoryColor,false);
279 addItemBool("Full View Month",&mFullViewMonth,true); 279 addItemBool("Full View Month",&mFullViewMonth,true);
280 addItemBool("Full View Todo",&mFullViewTodo,true); 280 addItemBool("Full View Todo",&mFullViewTodo,true);
281 addItemBool("Quick Todo",&mEnableQuickTodo,false); 281 addItemBool("Quick Todo",&mEnableQuickTodo,false);
282 282
283 addItemInt("Next X Days",&mNextXDays,3); 283 addItemInt("Next X Days",&mNextXDays,3);
284 284
285 KPrefs::setCurrentGroup("Printer"); 285 KPrefs::setCurrentGroup("Printer");
286 286
287 KPrefs::setCurrentGroup("Layout"); 287 KPrefs::setCurrentGroup("Layout");
288 288
289 addItemBool("CompactDialogs",&mCompactDialogs,false); 289 addItemBool("CompactDialogs",&mCompactDialogs,false);
290 addItemBool("VerticalScreen",&mVerticalScreen,true); 290 addItemBool("VerticalScreen",&mVerticalScreen,true);
291 291
292 KPrefs::setCurrentGroup("KOrganizer Plugins"); 292 KPrefs::setCurrentGroup("KOrganizer Plugins");
293 293
294 addItemStringList("SelectedPlugins",&mSelectedPlugins,"holidays"); 294 addItemStringList("SelectedPlugins",&mSelectedPlugins,"holidays");
295 295
296 KPrefs::setCurrentGroup("Group Scheduling"); 296 KPrefs::setCurrentGroup("Group Scheduling");
297 297
298 addItemInt("IMIPScheduler",&mIMIPScheduler,IMIPKMail); 298 addItemInt("IMIPScheduler",&mIMIPScheduler,IMIPKMail);
299 addItemInt("IMIPSend",&mIMIPSend,IMIPdirectsend); 299 addItemInt("IMIPSend",&mIMIPSend,IMIPdirectsend);
300 addItemStringList("AdditionalMails",&mAdditionalMails,""); 300 addItemStringList("AdditionalMails",&mAdditionalMails,"");
301 addItemInt("IMIP auto refresh",&mIMIPAutoRefresh,neverAuto); 301 addItemInt("IMIP auto refresh",&mIMIPAutoRefresh,neverAuto);
302 addItemInt("IMIP auto insert request",&mIMIPAutoInsertRequest,neverAuto); 302 addItemInt("IMIP auto insert request",&mIMIPAutoInsertRequest,neverAuto);
303 addItemInt("IMIP auto insert reply",&mIMIPAutoInsertReply,neverAuto); 303 addItemInt("IMIP auto insert reply",&mIMIPAutoInsertReply,neverAuto);
304 addItemInt("IMIP auto FreeBusy",&mIMIPAutoFreeBusy,neverAuto); 304 addItemInt("IMIP auto FreeBusy",&mIMIPAutoFreeBusy,neverAuto);
305 addItemInt("IMIP auto save FreeBusy",&mIMIPAutoFreeBusyReply,neverAuto); 305 addItemInt("IMIP auto save FreeBusy",&mIMIPAutoFreeBusyReply,neverAuto);
306 306
307 KPrefs::setCurrentGroup( "Editors" ); 307 KPrefs::setCurrentGroup( "Editors" );
308 308
309 addItemStringList( "EventTemplates", &mEventTemplates ); 309 addItemStringList( "EventTemplates", &mEventTemplates );
310 addItemStringList( "TodoTemplates", &mTodoTemplates ); 310 addItemStringList( "TodoTemplates", &mTodoTemplates );
311 311
312 addItemInt("DestinationPolicy",&mDestination,standardDestination); 312 addItemInt("DestinationPolicy",&mDestination,standardDestination);
313 313
314 KPrefs::setCurrentGroup( "ViewOptions" ); 314 KPrefs::setCurrentGroup( "ViewOptions" );
315 addItemBool("EVshowDetails",&mEVshowDetails,true); 315 addItemBool("EVshowDetails",&mEVshowDetails,true);
316 addItemBool("EVshowCreated",&mEVshowCreated,true); 316 addItemBool("EVshowCreated",&mEVshowCreated,true);
317 addItemBool("EVshowChanged",&mEVshowChanged,true); 317 addItemBool("EVshowChanged",&mEVshowChanged,true);
318 addItemBool("WTshowDetails",&mWTshowDetails,false); 318 addItemBool("WTshowDetails",&mWTshowDetails,false);
319 addItemBool("WTshowCreated",&mWTshowCreated,false); 319 addItemBool("WTshowCreated",&mWTshowCreated,false);
320 addItemBool("WTshowChanged",&mWTshowChanged,false); 320 addItemBool("WTshowChanged",&mWTshowChanged,false);
321 mCalendars.setAutoDelete( true ); 321 mCalendars.setAutoDelete( true );
322} 322}
323 323
324 324
325KOPrefs::~KOPrefs() 325KOPrefs::~KOPrefs()
326{ 326{
327 if (mInstance == this) 327 if (mInstance == this)
328 mInstance = insd.setObject(0); 328 mInstance = insd.setObject(0);
329 mCalendars.setAutoDelete( true ); 329 mCalendars.setAutoDelete( true );
330 mCalendars.clear(); 330 mCalendars.clear();
331 //qDebug("KOPrefs::~KOPrefs() "); 331 //qDebug("KOPrefs::~KOPrefs() ");
332} 332}
333 333
334 334
335KOPrefs *KOPrefs::instance() 335KOPrefs *KOPrefs::instance()
336{ 336{
337 if (!mInstance) { 337 if (!mInstance) {
338 mInstance = insd.setObject(new KOPrefs()); 338 mInstance = insd.setObject(new KOPrefs());
339 mInstance->readConfig(); 339 mInstance->readConfig();
340 } 340 }
341 341
342 return mInstance; 342 return mInstance;
343} 343}
344 344
345void KOPrefs::usrSetDefaults() 345void KOPrefs::usrSetDefaults()
346{ 346{
347 347
348} 348}
349 349
350void KOPrefs::fillMailDefaults() 350void KOPrefs::fillMailDefaults()
351{ 351{
352 if (mName.isEmpty()) mName = i18n("Anonymous"); 352 if (mName.isEmpty()) mName = i18n("Anonymous");
353 if (mEmail.isEmpty()) mEmail = i18n("nobody@nowhere"); 353 if (mEmail.isEmpty()) mEmail = i18n("nobody@nowhere");
354} 354}
355 355
356void KOPrefs::setTimeZoneIdDefault() 356void KOPrefs::setTimeZoneIdDefault()
357{ 357{
358 ; 358 ;
359} 359}
360 360
361void KOPrefs::setAllDefaults() 361void KOPrefs::setAllDefaults()
362{ 362{
363 setCategoryDefaults(); 363 setCategoryDefaults();
364 mEventSummaryUser = getDefaultList() ; 364 mEventSummaryUser = getDefaultList() ;
365 mTodoSummaryUser = getDefaultList() ; 365 mTodoSummaryUser = getDefaultList() ;
366 mLocationDefaults = getLocationDefaultList(); 366 mLocationDefaults = getLocationDefaultList();
367} 367}
368 368
369void KOPrefs::setCategoryDefaults() 369void KOPrefs::setCategoryDefaults()
370{ 370{
371 mCustomCategories.clear(); 371 mCustomCategories.clear();
372 mCustomCategories = getDefaultList(); 372 mCustomCategories = getDefaultList();
373 373
374 QStringList::Iterator it; 374 QStringList::Iterator it;
375 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { 375 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) {
376 setCategoryColor(*it,mDefaultCategoryColor); 376 setCategoryColor(*it,mDefaultCategoryColor);
377 } 377 }
378} 378}
379QStringList KOPrefs::getLocationDefaultList() 379QStringList KOPrefs::getLocationDefaultList()
380{ 380{
381 QStringList retval ; 381 QStringList retval ;
382 retval << i18n("Home") << i18n("Office") << i18n("Library") << i18n("School") << i18n("Doctor") << i18n("Beach") 382 retval << i18n("Home") << i18n("Office") << i18n("Library") << i18n("School") << i18n("Doctor") << i18n("Beach")
383 << i18n("University") << i18n("Restaurant") << i18n("Bar") << i18n("Conference room") 383 << i18n("University") << i18n("Restaurant") << i18n("Bar") << i18n("Conference room")
384 << i18n("Cinema") << i18n("Lake") << i18n("Kindergarten") 384 << i18n("Cinema") << i18n("Lake") << i18n("Kindergarten")
385 << i18n("Germany") << i18n("Sweden") << i18n("Forest") << i18n("Desert") << i18n("Kitchen") ; 385 << i18n("Germany") << i18n("Sweden") << i18n("Forest") << i18n("Desert") << i18n("Kitchen") ;
386 // << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") 386 // << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("") << i18n("")
387 387
388 retval.sort(); 388 retval.sort();
389 return retval; 389 return retval;
390} 390}
391QStringList KOPrefs::getDefaultList() 391QStringList KOPrefs::getDefaultList()
392{ 392{
393 QStringList retval ; 393 QStringList retval ;
394 retval << i18n("Anniversary") << i18n("Appointment") << i18n("Birthday") << i18n("Business") << i18n("Cinema") << i18n("Customer") 394 retval << i18n("Anniversary") << i18n("Appointment") << i18n("Birthday") << i18n("Business") << i18n("Customer")
395 << i18n("Break") 395 << i18n("Break")
396 << i18n("Family") << i18n("Favorites") << i18n("Fishing")<< i18n("Flight") << i18n("Gifts") 396 << i18n("Family") << i18n("Favorites") << i18n("Fishing") << i18n("Gifts")
397 << i18n("Holiday") << i18n("Holiday Cards")<< i18n("Hot Contacts") << i18n("Key Customer") 397 << i18n("Holiday") << i18n("Holiday Cards")<< i18n("Hot Contacts")
398 << i18n("Meeting") << i18n("Miscellaneous") << i18n("Partner") << i18n("Personal") 398 << i18n("Meeting") << i18n("Miscellaneous") << i18n("Partner") << i18n("Personal")
399 << i18n("PHB") << i18n("Phone Calls") << i18n("School") << i18n("Shopping") 399 << i18n("PHB") << i18n("Phone Calls") << i18n("Shopping")
400 << i18n("Sports") << i18n("Talk") << i18n("Travel") << i18n("TV")<< i18n("University") 400 << i18n("Sports") << i18n("Talk") << i18n("Travel") << i18n("TV")
401 << i18n("Vacation") << i18n("VIP") << i18n("SyncEvent") ; 401 << i18n("Vacation") ;
402 retval.sort(); 402 retval.sort();
403 //qDebug("cat %s ", retval.join("-").latin1()); 403 //qDebug("cat %s ", retval.join("-").latin1());
404 return retval; 404 return retval;
405} 405}
406// << i18n("Business Travel") << i18n("Education") << i18n("Hiking") << i18n("Hunting") << i18n("Recurring") << i18n("Personal Travel") << i18n("Speach") << i18n("Festival") << i18n("Competition")<< i18n("Party")<< i18n("Projects")<< i18n("Kids") << i18n("Special Occasion")<< i18n("Breakfast")<< i18n("Dinner") << i18n("Lunch") 406// << i18n("Business Travel") << i18n("Education") << i18n("Hiking") << i18n("Hunting") << i18n("Recurring") << i18n("Personal Travel") << i18n("Speach") << i18n("Festival") << i18n("Competition")<< i18n("Party")<< i18n("Projects")<< i18n("Kids") << i18n("Special Occasion")<< i18n("Breakfast")<< i18n("Dinner") << i18n("Lunch")<< i18n("University")<< i18n("School")<< i18n("Flight")<< i18n("Key Customer") << i18n("VIP") << i18n("SyncEvent") << i18n("Cinema")
407void KOPrefs::usrReadConfig() 407void KOPrefs::usrReadConfig()
408{ 408{
409 config()->setGroup("General"); 409 config()->setGroup("General");
410 410
411 //qDebug("KOPrefs::usrReadConfig() "); 411 //qDebug("KOPrefs::usrReadConfig() ");
412 mCustomCategories = config()->readListEntry("Custom Categories"); 412 mCustomCategories = config()->readListEntry("Custom Categories");
413 mOldLoadedLanguage = mOldLanguage ; 413 mOldLoadedLanguage = mOldLanguage ;
414 mOldLanguage = KPimGlobalPrefs::instance()->mPreferredLanguage; 414 mOldLanguage = KPimGlobalPrefs::instance()->mPreferredLanguage;
415 if (mLocationDefaults.isEmpty()) { 415 if (mLocationDefaults.isEmpty()) {
416 mLocationDefaults = getLocationDefaultList(); 416 mLocationDefaults = getLocationDefaultList();
417 } 417 }
418 418
419 if (mEventSummaryUser.isEmpty()) { 419 if (mEventSummaryUser.isEmpty()) {
420 mEventSummaryUser = getDefaultList() ; 420 mEventSummaryUser = getDefaultList() ;
421 } 421 }
422 if (mTodoSummaryUser.isEmpty()) { 422 if (mTodoSummaryUser.isEmpty()) {
423 mTodoSummaryUser = getDefaultList() ; 423 mTodoSummaryUser = getDefaultList() ;
424 } 424 }
425 425
426 if (mCustomCategories.isEmpty()) setCategoryDefaults(); 426 if (mCustomCategories.isEmpty()) setCategoryDefaults();
427 427
428 config()->setGroup("Personal Settings"); 428 config()->setGroup("Personal Settings");
429 mName = config()->readEntry("user_name",""); 429 mName = config()->readEntry("user_name","");
430 mEmail = config()->readEntry("user_email",""); 430 mEmail = config()->readEntry("user_email","");
431 fillMailDefaults(); 431 fillMailDefaults();
432 432
433 config()->setGroup("Category Colors"); 433 config()->setGroup("Category Colors");
434 QStringList::Iterator it; 434 QStringList::Iterator it;
435 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) { 435 for (it = mCustomCategories.begin();it != mCustomCategories.end();++it ) {
436 setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor)); 436 setCategoryColor(*it,config()->readColorEntry(*it,&mDefaultCategoryColor));
437 437
438 } 438 }
439 KConfig fc (locateLocal("config","kopicalendarrc")); 439 KConfig fc (locateLocal("config","kopicalendarrc"));
440 fc.setGroup("CC"); 440 fc.setGroup("CC");
441 int numCals = fc.readNumEntry("NumberCalendars",0 ); 441 int numCals = fc.readNumEntry("NumberCalendars",0 );
442 mNextAvailableCalendar = 1; 442 mNextAvailableCalendar = 1;
443 if ( numCals == 0 ) { 443 if ( numCals == 0 ) {
444 KopiCalendarFile *kkf = getNewCalendar(); 444 KopiCalendarFile *kkf = getNewCalendar();
445 kkf->isStandard = true; 445 kkf->isStandard = true;
446 kkf->mName = i18n("Standard"); 446 kkf->mName = i18n("Standard");
447 kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" ); 447 kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" );
448 } 448 }
449 while ( mNextAvailableCalendar <= numCals ) { 449 while ( mNextAvailableCalendar <= numCals ) {
450 //qDebug("Read cal #%d ", mNextAvailableCalendar ); 450 //qDebug("Read cal #%d ", mNextAvailableCalendar );
451 QString prefix = "Cal_" +QString::number( mNextAvailableCalendar ); 451 QString prefix = "Cal_" +QString::number( mNextAvailableCalendar );
452 KopiCalendarFile *kkf = getNewCalendar(); 452 KopiCalendarFile *kkf = getNewCalendar();
453 kkf->isStandard = fc.readBoolEntry( prefix+"_isStandard", false ); 453 kkf->isStandard = fc.readBoolEntry( prefix+"_isStandard", false );
454 kkf->isEnabled = fc.readBoolEntry( prefix+"_isEnabled", true); 454 kkf->isEnabled = fc.readBoolEntry( prefix+"_isEnabled", true);
455 kkf->isAlarmEnabled = fc.readBoolEntry( prefix+"_isAlarmEnabled", true); 455 kkf->isAlarmEnabled = fc.readBoolEntry( prefix+"_isAlarmEnabled", true);
456 kkf->isReadOnly = fc.readBoolEntry( prefix+"_isReadOnly", false); 456 kkf->isReadOnly = fc.readBoolEntry( prefix+"_isReadOnly", false);
457 kkf->mName = fc.readEntry( prefix+"_Name", "Calendar"); 457 kkf->mName = fc.readEntry( prefix+"_Name", "Calendar");
458 kkf->mFileName = fc.readEntry( prefix+"_FileName", kkf->mFileName); 458 kkf->mFileName = fc.readEntry( prefix+"_FileName", kkf->mFileName);
459 kkf->mDefaultColor = fc.readColorEntry( prefix+"_Color",&mEventColor); 459 kkf->mDefaultColor = fc.readColorEntry( prefix+"_Color",&mEventColor);
460 if ( kkf->mCalNumber == 1 ) { 460 if ( kkf->mCalNumber == 1 ) {
461 kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" ); 461 kkf->mFileName = locateLocal( "data", "korganizer/mycalendar.ics" );
462 } 462 }
463 //qDebug("NAME %s %s", kkf->mName.latin1(), i18n("Birthdays").latin1() ); 463 //qDebug("NAME %s %s", kkf->mName.latin1(), i18n("Birthdays").latin1() );
464 if ( kkf->mName == i18n("Birthdays") ) { 464 if ( kkf->mName == i18n("Birthdays") ) {
465 kkf->mFileName = locateLocal( "data", "korganizer/birthdays.ics" ); 465 kkf->mFileName = locateLocal( "data", "korganizer/birthdays.ics" );
466 } 466 }
467 } 467 }
468 468
469 KPimPrefs::usrReadConfig(); 469 KPimPrefs::usrReadConfig();
470} 470}
471 471
472KopiCalendarFile * KOPrefs::getCalendar( int num ) 472KopiCalendarFile * KOPrefs::getCalendar( int num )
473{ 473{
474 return mDefCalColors[num-1]; 474 return mDefCalColors[num-1];
475} 475}
476 476
477KopiCalendarFile * KOPrefs::getNewCalendar() 477KopiCalendarFile * KOPrefs::getNewCalendar()
478{ 478{
479 KopiCalendarFile * kkf = new KopiCalendarFile(); 479 KopiCalendarFile * kkf = new KopiCalendarFile();
480 kkf->mCalNumber = mNextAvailableCalendar; 480 kkf->mCalNumber = mNextAvailableCalendar;
481 mDefCalColors.resize( mNextAvailableCalendar ); 481 mDefCalColors.resize( mNextAvailableCalendar );
482 mDefCalColors[mNextAvailableCalendar-1] = kkf; 482 mDefCalColors[mNextAvailableCalendar-1] = kkf;
483 ++mNextAvailableCalendar; 483 ++mNextAvailableCalendar;
484 kkf->mDefaultColor = mEventColor; 484 kkf->mDefaultColor = mEventColor;
485 kkf->mName = i18n("New Calendar"); 485 kkf->mName = i18n("New Calendar");
486 mCalendars.append( kkf ); 486 mCalendars.append( kkf );
487 return kkf; 487 return kkf;
488} 488}
489void KOPrefs::deleteCalendar( int num ) 489void KOPrefs::deleteCalendar( int num )
490{ 490{
491 KopiCalendarFile * kkf = mCalendars.first(); 491 KopiCalendarFile * kkf = mCalendars.first();
492 while ( kkf ) { 492 while ( kkf ) {
493 if ( kkf->mCalNumber == num ) { 493 if ( kkf->mCalNumber == num ) {
494 qDebug("KOPrefs::deleteCalendar %d ", num ); 494 qDebug("KOPrefs::deleteCalendar %d ", num );
495 mCalendars.remove( kkf ); 495 mCalendars.remove( kkf );
496 delete kkf; 496 delete kkf;
497 return; 497 return;
498 } 498 }
499 kkf = mCalendars.next(); 499 kkf = mCalendars.next();
500 } 500 }
501} 501}
502QString KOPrefs::calName( int calNum) const 502QString KOPrefs::calName( int calNum) const
503{ 503{
504 return (mDefCalColors[calNum-1])->mName; 504 return (mDefCalColors[calNum-1])->mName;
505} 505}
506QColor KOPrefs::defaultColor( int calNum ) const 506QColor KOPrefs::defaultColor( int calNum ) const
507{ 507{
508 if ( calNum == 1 ) return mEventColor; 508 if ( calNum == 1 ) return mEventColor;
509 return (mDefCalColors[calNum-1])->mDefaultColor; 509 return (mDefCalColors[calNum-1])->mDefaultColor;
510} 510}
511void KOPrefs::usrWriteConfig() 511void KOPrefs::usrWriteConfig()
512{ 512{
513 config()->setGroup("General"); 513 config()->setGroup("General");
514 config()->writeEntry("Custom Categories",mCustomCategories); 514 config()->writeEntry("Custom Categories",mCustomCategories);
515 515
516 config()->setGroup("Personal Settings"); 516 config()->setGroup("Personal Settings");
517 config()->writeEntry("user_name",mName); 517 config()->writeEntry("user_name",mName);
518 config()->writeEntry("user_email",mEmail); 518 config()->writeEntry("user_email",mEmail);
519 519
520 config()->setGroup("Category Colors"); 520 config()->setGroup("Category Colors");
521 QDictIterator<QColor> it(mCategoryColors); 521 QDictIterator<QColor> it(mCategoryColors);
522 while (it.current()) { 522 while (it.current()) {
523 config()->writeEntry(it.currentKey(),*(it.current())); 523 config()->writeEntry(it.currentKey(),*(it.current()));
524 ++it; 524 ++it;
525 } 525 }
526 KConfig fc (locateLocal("config","kopicalendarrc")); 526 KConfig fc (locateLocal("config","kopicalendarrc"));
527 fc.setGroup("CC"); 527 fc.setGroup("CC");
528 fc.writeEntry("NumberCalendars",mCalendars.count()); 528 fc.writeEntry("NumberCalendars",mCalendars.count());
529 int numCal = 1; 529 int numCal = 1;
530 int writeCal = 0; 530 int writeCal = 0;
531 while ( numCal < mNextAvailableCalendar ) { 531 while ( numCal < mNextAvailableCalendar ) {
532 KopiCalendarFile * kkf = mCalendars.first(); 532 KopiCalendarFile * kkf = mCalendars.first();
533 while ( kkf ) { 533 while ( kkf ) {
534 //qDebug("cal num %d %d ", kkf->mCalNumber, numCal); 534 //qDebug("cal num %d %d ", kkf->mCalNumber, numCal);
535 if ( kkf->mCalNumber == numCal ) { 535 if ( kkf->mCalNumber == numCal ) {
536 ++writeCal; 536 ++writeCal;
537 //qDebug("Write calendar %d %d ", numCal , writeCal); 537 //qDebug("Write calendar %d %d ", numCal , writeCal);
538 QString prefix = "Cal_" + QString::number( writeCal ); 538 QString prefix = "Cal_" + QString::number( writeCal );
539 fc.writeEntry( prefix+"_isStandard", kkf->isStandard ); 539 fc.writeEntry( prefix+"_isStandard", kkf->isStandard );
540 fc.writeEntry( prefix+"_isEnabled", kkf->isEnabled ); 540 fc.writeEntry( prefix+"_isEnabled", kkf->isEnabled );
541 fc.writeEntry( prefix+"_isAlarmEnabled", kkf->isAlarmEnabled ); 541 fc.writeEntry( prefix+"_isAlarmEnabled", kkf->isAlarmEnabled );
542 fc.writeEntry( prefix+"_isReadOnly", kkf->isReadOnly ); 542 fc.writeEntry( prefix+"_isReadOnly", kkf->isReadOnly );
543 fc.writeEntry( prefix+"_Name", kkf->mName); 543 fc.writeEntry( prefix+"_Name", kkf->mName);
544 fc.writeEntry( prefix+"_FileName", kkf->mFileName); 544 fc.writeEntry( prefix+"_FileName", kkf->mFileName);
545 fc.writeEntry( prefix+"_Color",kkf->mDefaultColor); 545 fc.writeEntry( prefix+"_Color",kkf->mDefaultColor);
546 } 546 }
547 kkf = mCalendars.next(); 547 kkf = mCalendars.next();
548 } 548 }
549 ++numCal; 549 ++numCal;
550 } 550 }
551 fc.sync(); 551 fc.sync();
552 KPimPrefs::usrWriteConfig(); 552 KPimPrefs::usrWriteConfig();
553} 553}
554 554
555void KOPrefs::setCategoryColor(QString cat,const QColor & color) 555void KOPrefs::setCategoryColor(QString cat,const QColor & color)
556{ 556{
557 mCategoryColors.replace(cat,new QColor(color)); 557 mCategoryColors.replace(cat,new QColor(color));
558} 558}
559 559
560QColor *KOPrefs::categoryColor(QString cat) 560QColor *KOPrefs::categoryColor(QString cat)
561{ 561{
562 QColor *color = 0; 562 QColor *color = 0;
563 563
564 if (!cat.isEmpty()) color = mCategoryColors[cat]; 564 if (!cat.isEmpty()) color = mCategoryColors[cat];
565 565
566 if (color) return color; 566 if (color) return color;
567 else return &mDefaultCategoryColor; 567 else return &mDefaultCategoryColor;
568} 568}
569 569
570void KOPrefs::setFullName(const QString &name) 570void KOPrefs::setFullName(const QString &name)
571{ 571{
572 mName = name; 572 mName = name;
573} 573}
574 574
575void KOPrefs::setEmail(const QString &email) 575void KOPrefs::setEmail(const QString &email)
576{ 576{
577 //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() ); 577 //qDebug(" KOPrefs::setEmai*********** %s",email.latin1() );
578 mEmail = email; 578 mEmail = email;
579} 579}
580 580
581QString KOPrefs::fullName() 581QString KOPrefs::fullName()
582{ 582{
583 if (mEmailControlCenter) { 583 if (mEmailControlCenter) {
584 KEMailSettings settings; 584 KEMailSettings settings;
585 return settings.getSetting(KEMailSettings::RealName); 585 return settings.getSetting(KEMailSettings::RealName);
586 } else { 586 } else {
587 return mName; 587 return mName;
588 } 588 }
589} 589}
590 590
591QString KOPrefs::email() 591QString KOPrefs::email()
592{ 592{
593 if (mEmailControlCenter) { 593 if (mEmailControlCenter) {
594 KEMailSettings settings; 594 KEMailSettings settings;
595 return settings.getSetting(KEMailSettings::EmailAddress); 595 return settings.getSetting(KEMailSettings::EmailAddress);
596 } else { 596 } else {
597 return mEmail; 597 return mEmail;
598 } 598 }
599} 599}
600KConfig* KOPrefs::getConfig() 600KConfig* KOPrefs::getConfig()
601{ 601{
602 return config(); 602 return config();
603} 603}