summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-01-29 23:23:11 (UTC)
committer zautrix <zautrix>2005-01-29 23:23:11 (UTC)
commitd94b52aa95cc52aa1bef7c9cd99f43c725ed8042 (patch) (unidiff)
tree9443dfbc790a76e5d707ce762e075cdb21096f50
parent74c808f288bf81bc68c92a377ce64953603c2d40 (diff)
downloadkdepimpi-d94b52aa95cc52aa1bef7c9cd99f43c725ed8042.zip
kdepimpi-d94b52aa95cc52aa1bef7c9cd99f43c725ed8042.tar.gz
kdepimpi-d94b52aa95cc52aa1bef7c9cd99f43c725ed8042.tar.bz2
todo dnd
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp8
-rw-r--r--korganizer/korganizer.pro4
-rw-r--r--korganizer/kotodoview.cpp61
-rw-r--r--korganizer/kotodoview.h11
-rw-r--r--libkcal/dndfactory.cpp186
-rw-r--r--libkcal/dndfactory.h56
-rw-r--r--libkcal/dndfactory_dummy.h62
-rw-r--r--libkcal/libkcal.pro2
8 files changed, 332 insertions, 58 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 0c39590..74aefb7 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -766,2249 +766,2249 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
766 mode = SYNC_PREF_ASK; 766 mode = SYNC_PREF_ASK;
767 } else { 767 } else {
768 if ( localMod == remoteMod ) 768 if ( localMod == remoteMod )
769 // if ( local->revision() == remote->revision() ) 769 // if ( local->revision() == remote->revision() )
770 return 0; 770 return 0;
771 771
772 } 772 }
773 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 773 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
774 774
775 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 775 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
776 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 776 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
777 //full = true; //debug only 777 //full = true; //debug only
778 if ( full ) { 778 if ( full ) {
779 bool equ = false; 779 bool equ = false;
780 if ( local->type() == "Event" ) { 780 if ( local->type() == "Event" ) {
781 equ = (*((Event*) local) == *((Event*) remote)); 781 equ = (*((Event*) local) == *((Event*) remote));
782 } 782 }
783 else if ( local->type() =="Todo" ) 783 else if ( local->type() =="Todo" )
784 equ = (*((Todo*) local) == (*(Todo*) remote)); 784 equ = (*((Todo*) local) == (*(Todo*) remote));
785 else if ( local->type() =="Journal" ) 785 else if ( local->type() =="Journal" )
786 equ = (*((Journal*) local) == *((Journal*) remote)); 786 equ = (*((Journal*) local) == *((Journal*) remote));
787 if ( equ ) { 787 if ( equ ) {
788 //qDebug("equal "); 788 //qDebug("equal ");
789 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 789 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
790 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 790 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
791 } 791 }
792 if ( mode < SYNC_PREF_FORCE_LOCAL ) 792 if ( mode < SYNC_PREF_FORCE_LOCAL )
793 return 0; 793 return 0;
794 794
795 }//else //debug only 795 }//else //debug only
796 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 796 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
797 } 797 }
798 int result; 798 int result;
799 bool localIsNew; 799 bool localIsNew;
800 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 800 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
801 801
802 if ( full && mode < SYNC_PREF_NEWEST ) 802 if ( full && mode < SYNC_PREF_NEWEST )
803 mode = SYNC_PREF_ASK; 803 mode = SYNC_PREF_ASK;
804 804
805 switch( mode ) { 805 switch( mode ) {
806 case SYNC_PREF_LOCAL: 806 case SYNC_PREF_LOCAL:
807 if ( lastSync > remoteMod ) 807 if ( lastSync > remoteMod )
808 return 1; 808 return 1;
809 if ( lastSync > localMod ) 809 if ( lastSync > localMod )
810 return 2; 810 return 2;
811 return 1; 811 return 1;
812 break; 812 break;
813 case SYNC_PREF_REMOTE: 813 case SYNC_PREF_REMOTE:
814 if ( lastSync > remoteMod ) 814 if ( lastSync > remoteMod )
815 return 1; 815 return 1;
816 if ( lastSync > localMod ) 816 if ( lastSync > localMod )
817 return 2; 817 return 2;
818 return 2; 818 return 2;
819 break; 819 break;
820 case SYNC_PREF_NEWEST: 820 case SYNC_PREF_NEWEST:
821 if ( localMod > remoteMod ) 821 if ( localMod > remoteMod )
822 return 1; 822 return 1;
823 else 823 else
824 return 2; 824 return 2;
825 break; 825 break;
826 case SYNC_PREF_ASK: 826 case SYNC_PREF_ASK:
827 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 827 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
828 if ( lastSync > remoteMod ) 828 if ( lastSync > remoteMod )
829 return 1; 829 return 1;
830 if ( lastSync > localMod ) 830 if ( lastSync > localMod )
831 return 2; 831 return 2;
832 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 832 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
833 localIsNew = localMod >= remoteMod; 833 localIsNew = localMod >= remoteMod;
834 if ( localIsNew ) 834 if ( localIsNew )
835 getEventViewerDialog()->setColorMode( 1 ); 835 getEventViewerDialog()->setColorMode( 1 );
836 else 836 else
837 getEventViewerDialog()->setColorMode( 2 ); 837 getEventViewerDialog()->setColorMode( 2 );
838 getEventViewerDialog()->setIncidence(local); 838 getEventViewerDialog()->setIncidence(local);
839 if ( localIsNew ) 839 if ( localIsNew )
840 getEventViewerDialog()->setColorMode( 2 ); 840 getEventViewerDialog()->setColorMode( 2 );
841 else 841 else
842 getEventViewerDialog()->setColorMode( 1 ); 842 getEventViewerDialog()->setColorMode( 1 );
843 getEventViewerDialog()->addIncidence(remote); 843 getEventViewerDialog()->addIncidence(remote);
844 getEventViewerDialog()->setColorMode( 0 ); 844 getEventViewerDialog()->setColorMode( 0 );
845 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 845 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
846 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 846 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
847 getEventViewerDialog()->showMe(); 847 getEventViewerDialog()->showMe();
848 result = getEventViewerDialog()->executeS( localIsNew ); 848 result = getEventViewerDialog()->executeS( localIsNew );
849 return result; 849 return result;
850 850
851 break; 851 break;
852 case SYNC_PREF_FORCE_LOCAL: 852 case SYNC_PREF_FORCE_LOCAL:
853 return 1; 853 return 1;
854 break; 854 break;
855 case SYNC_PREF_FORCE_REMOTE: 855 case SYNC_PREF_FORCE_REMOTE:
856 return 2; 856 return 2;
857 break; 857 break;
858 858
859 default: 859 default:
860 // SYNC_PREF_TAKE_BOTH not implemented 860 // SYNC_PREF_TAKE_BOTH not implemented
861 break; 861 break;
862 } 862 }
863 return 0; 863 return 0;
864} 864}
865Event* CalendarView::getLastSyncEvent() 865Event* CalendarView::getLastSyncEvent()
866{ 866{
867 Event* lse; 867 Event* lse;
868 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 868 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
869 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 869 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
870 if (!lse) { 870 if (!lse) {
871 lse = new Event(); 871 lse = new Event();
872 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 872 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
873 QString sum = ""; 873 QString sum = "";
874 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 874 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
875 sum = "E: "; 875 sum = "E: ";
876 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 876 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
877 lse->setDtStart( mLastCalendarSync ); 877 lse->setDtStart( mLastCalendarSync );
878 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 878 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
879 lse->setCategories( i18n("SyncEvent") ); 879 lse->setCategories( i18n("SyncEvent") );
880 lse->setReadOnly( true ); 880 lse->setReadOnly( true );
881 mCalendar->addEvent( lse ); 881 mCalendar->addEvent( lse );
882 } 882 }
883 883
884 return lse; 884 return lse;
885 885
886} 886}
887 887
888// we check, if the to delete event has a id for a profile 888// we check, if the to delete event has a id for a profile
889// if yes, we set this id in the profile to delete 889// if yes, we set this id in the profile to delete
890void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 890void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
891{ 891{
892 if ( lastSync.count() == 0 ) { 892 if ( lastSync.count() == 0 ) {
893 //qDebug(" lastSync.count() == 0"); 893 //qDebug(" lastSync.count() == 0");
894 return; 894 return;
895 } 895 }
896 if ( toDelete->type() == "Journal" ) 896 if ( toDelete->type() == "Journal" )
897 return; 897 return;
898 898
899 Event* eve = lastSync.first(); 899 Event* eve = lastSync.first();
900 900
901 while ( eve ) { 901 while ( eve ) {
902 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 902 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
903 if ( !id.isEmpty() ) { 903 if ( !id.isEmpty() ) {
904 QString des = eve->description(); 904 QString des = eve->description();
905 QString pref = "e"; 905 QString pref = "e";
906 if ( toDelete->type() == "Todo" ) 906 if ( toDelete->type() == "Todo" )
907 pref = "t"; 907 pref = "t";
908 des += pref+ id + ","; 908 des += pref+ id + ",";
909 eve->setReadOnly( false ); 909 eve->setReadOnly( false );
910 eve->setDescription( des ); 910 eve->setDescription( des );
911 //qDebug("setdes %s ", des.latin1()); 911 //qDebug("setdes %s ", des.latin1());
912 eve->setReadOnly( true ); 912 eve->setReadOnly( true );
913 } 913 }
914 eve = lastSync.next(); 914 eve = lastSync.next();
915 } 915 }
916 916
917} 917}
918void CalendarView::checkExternalId( Incidence * inc ) 918void CalendarView::checkExternalId( Incidence * inc )
919{ 919{
920 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 920 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
921 checkExternSyncEvent( lastSync, inc ); 921 checkExternSyncEvent( lastSync, inc );
922 922
923} 923}
924bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 924bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
925{ 925{
926 bool syncOK = true; 926 bool syncOK = true;
927 int addedEvent = 0; 927 int addedEvent = 0;
928 int addedEventR = 0; 928 int addedEventR = 0;
929 int deletedEventR = 0; 929 int deletedEventR = 0;
930 int deletedEventL = 0; 930 int deletedEventL = 0;
931 int changedLocal = 0; 931 int changedLocal = 0;
932 int changedRemote = 0; 932 int changedRemote = 0;
933 int filteredIN = 0; 933 int filteredIN = 0;
934 int filteredOUT = 0; 934 int filteredOUT = 0;
935 //QPtrList<Event> el = local->rawEvents(); 935 //QPtrList<Event> el = local->rawEvents();
936 Event* eventR; 936 Event* eventR;
937 QString uid; 937 QString uid;
938 int take; 938 int take;
939 Event* eventL; 939 Event* eventL;
940 Event* eventRSync; 940 Event* eventRSync;
941 Event* eventLSync; 941 Event* eventLSync;
942 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 942 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
943 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 943 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
944 bool fullDateRange = false; 944 bool fullDateRange = false;
945 local->resetTempSyncStat(); 945 local->resetTempSyncStat();
946 mLastCalendarSync = QDateTime::currentDateTime(); 946 mLastCalendarSync = QDateTime::currentDateTime();
947 if ( mSyncManager->syncWithDesktop() ) { 947 if ( mSyncManager->syncWithDesktop() ) {
948 remote->resetPilotStat(1); 948 remote->resetPilotStat(1);
949 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 949 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
950 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 950 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
951 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 951 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
952 } else { 952 } else {
953 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 953 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
954 } 954 }
955 } 955 }
956 QDateTime modifiedCalendar = mLastCalendarSync; 956 QDateTime modifiedCalendar = mLastCalendarSync;
957 eventLSync = getLastSyncEvent(); 957 eventLSync = getLastSyncEvent();
958 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 958 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
959 if ( eventR ) { 959 if ( eventR ) {
960 eventRSync = (Event*) eventR->clone(); 960 eventRSync = (Event*) eventR->clone();
961 remote->deleteEvent(eventR ); 961 remote->deleteEvent(eventR );
962 962
963 } else { 963 } else {
964 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 964 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
965 eventRSync = (Event*)eventLSync->clone(); 965 eventRSync = (Event*)eventLSync->clone();
966 } else { 966 } else {
967 fullDateRange = true; 967 fullDateRange = true;
968 eventRSync = new Event(); 968 eventRSync = new Event();
969 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 969 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
970 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 970 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
971 eventRSync->setDtStart( mLastCalendarSync ); 971 eventRSync->setDtStart( mLastCalendarSync );
972 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 972 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
973 eventRSync->setCategories( i18n("SyncEvent") ); 973 eventRSync->setCategories( i18n("SyncEvent") );
974 } 974 }
975 } 975 }
976 if ( eventLSync->dtStart() == mLastCalendarSync ) 976 if ( eventLSync->dtStart() == mLastCalendarSync )
977 fullDateRange = true; 977 fullDateRange = true;
978 978
979 if ( ! fullDateRange ) { 979 if ( ! fullDateRange ) {
980 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 980 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
981 981
982 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 982 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
983 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 983 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
984 fullDateRange = true; 984 fullDateRange = true;
985 } 985 }
986 } 986 }
987 if ( mSyncManager->syncWithDesktop() ) { 987 if ( mSyncManager->syncWithDesktop() ) {
988 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 988 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
989 } 989 }
990 if ( fullDateRange ) 990 if ( fullDateRange )
991 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 991 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
992 else 992 else
993 mLastCalendarSync = eventLSync->dtStart(); 993 mLastCalendarSync = eventLSync->dtStart();
994 // for resyncing if own file has changed 994 // for resyncing if own file has changed
995 if ( mCurrentSyncDevice == "deleteaftersync" ) { 995 if ( mCurrentSyncDevice == "deleteaftersync" ) {
996 mLastCalendarSync = loadedFileVersion; 996 mLastCalendarSync = loadedFileVersion;
997 //qDebug("setting mLastCalendarSync "); 997 //qDebug("setting mLastCalendarSync ");
998 } 998 }
999 //qDebug("*************************** "); 999 //qDebug("*************************** ");
1000 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1000 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1001 QPtrList<Incidence> er = remote->rawIncidences(); 1001 QPtrList<Incidence> er = remote->rawIncidences();
1002 Incidence* inR = er.first(); 1002 Incidence* inR = er.first();
1003 Incidence* inL; 1003 Incidence* inL;
1004 QProgressBar bar( er.count(),0 ); 1004 QProgressBar bar( er.count(),0 );
1005 bar.setCaption (i18n("Syncing - close to abort!") ); 1005 bar.setCaption (i18n("Syncing - close to abort!") );
1006 1006
1007 // ************** setting up filter ************* 1007 // ************** setting up filter *************
1008 CalFilter *filterIN = 0; 1008 CalFilter *filterIN = 0;
1009 CalFilter *filterOUT = 0; 1009 CalFilter *filterOUT = 0;
1010 CalFilter *filter = mFilters.first(); 1010 CalFilter *filter = mFilters.first();
1011 while(filter) { 1011 while(filter) {
1012 if ( filter->name() == mSyncManager->mFilterInCal ) 1012 if ( filter->name() == mSyncManager->mFilterInCal )
1013 filterIN = filter; 1013 filterIN = filter;
1014 if ( filter->name() == mSyncManager->mFilterOutCal ) 1014 if ( filter->name() == mSyncManager->mFilterOutCal )
1015 filterOUT = filter; 1015 filterOUT = filter;
1016 filter = mFilters.next(); 1016 filter = mFilters.next();
1017 } 1017 }
1018 int w = 300; 1018 int w = 300;
1019 if ( QApplication::desktop()->width() < 320 ) 1019 if ( QApplication::desktop()->width() < 320 )
1020 w = 220; 1020 w = 220;
1021 int h = bar.sizeHint().height() ; 1021 int h = bar.sizeHint().height() ;
1022 int dw = QApplication::desktop()->width(); 1022 int dw = QApplication::desktop()->width();
1023 int dh = QApplication::desktop()->height(); 1023 int dh = QApplication::desktop()->height();
1024 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1024 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1025 bar.show(); 1025 bar.show();
1026 int modulo = (er.count()/10)+1; 1026 int modulo = (er.count()/10)+1;
1027 int incCounter = 0; 1027 int incCounter = 0;
1028 while ( inR ) { 1028 while ( inR ) {
1029 if ( ! bar.isVisible() ) 1029 if ( ! bar.isVisible() )
1030 return false; 1030 return false;
1031 if ( incCounter % modulo == 0 ) 1031 if ( incCounter % modulo == 0 )
1032 bar.setProgress( incCounter ); 1032 bar.setProgress( incCounter );
1033 ++incCounter; 1033 ++incCounter;
1034 uid = inR->uid(); 1034 uid = inR->uid();
1035 bool skipIncidence = false; 1035 bool skipIncidence = false;
1036 if ( uid.left(15) == QString("last-syncEvent-") ) 1036 if ( uid.left(15) == QString("last-syncEvent-") )
1037 skipIncidence = true; 1037 skipIncidence = true;
1038 QString idS; 1038 QString idS;
1039 qApp->processEvents(); 1039 qApp->processEvents();
1040 if ( !skipIncidence ) { 1040 if ( !skipIncidence ) {
1041 inL = local->incidence( uid ); 1041 inL = local->incidence( uid );
1042 if ( inL ) { // maybe conflict - same uid in both calendars 1042 if ( inL ) { // maybe conflict - same uid in both calendars
1043 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1043 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1044 //qDebug("take %d %s ", take, inL->summary().latin1()); 1044 //qDebug("take %d %s ", take, inL->summary().latin1());
1045 if ( take == 3 ) 1045 if ( take == 3 )
1046 return false; 1046 return false;
1047 if ( take == 1 ) {// take local ********************** 1047 if ( take == 1 ) {// take local **********************
1048 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1048 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1049 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1049 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1050 else 1050 else
1051 idS = inR->IDStr(); 1051 idS = inR->IDStr();
1052 remote->deleteIncidence( inR ); 1052 remote->deleteIncidence( inR );
1053 inR = inL->clone(); 1053 inR = inL->clone();
1054 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1054 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1055 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1055 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1056 inR->setIDStr( idS ); 1056 inR->setIDStr( idS );
1057 remote->addIncidence( inR ); 1057 remote->addIncidence( inR );
1058 if ( mSyncManager->syncWithDesktop() ) 1058 if ( mSyncManager->syncWithDesktop() )
1059 inR->setPilotId( 2 ); 1059 inR->setPilotId( 2 );
1060 ++changedRemote; 1060 ++changedRemote;
1061 } else {// take remote ********************** 1061 } else {// take remote **********************
1062 idS = inL->IDStr(); 1062 idS = inL->IDStr();
1063 int pid = inL->pilotId(); 1063 int pid = inL->pilotId();
1064 local->deleteIncidence( inL ); 1064 local->deleteIncidence( inL );
1065 inL = inR->clone(); 1065 inL = inR->clone();
1066 if ( mSyncManager->syncWithDesktop() ) 1066 if ( mSyncManager->syncWithDesktop() )
1067 inL->setPilotId( pid ); 1067 inL->setPilotId( pid );
1068 inL->setIDStr( idS ); 1068 inL->setIDStr( idS );
1069 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1069 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1070 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1070 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1071 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1071 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1072 } 1072 }
1073 local->addIncidence( inL ); 1073 local->addIncidence( inL );
1074 ++changedLocal; 1074 ++changedLocal;
1075 } 1075 }
1076 } 1076 }
1077 } else { // no conflict ********** add or delete remote 1077 } else { // no conflict ********** add or delete remote
1078 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1078 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1079 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1079 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1080 QString des = eventLSync->description(); 1080 QString des = eventLSync->description();
1081 QString pref = "e"; 1081 QString pref = "e";
1082 if ( inR->type() == "Todo" ) 1082 if ( inR->type() == "Todo" )
1083 pref = "t"; 1083 pref = "t";
1084 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1084 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1085 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1085 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1086 //remote->deleteIncidence( inR ); 1086 //remote->deleteIncidence( inR );
1087 ++deletedEventR; 1087 ++deletedEventR;
1088 } else { 1088 } else {
1089 inR->setLastModified( modifiedCalendar ); 1089 inR->setLastModified( modifiedCalendar );
1090 inL = inR->clone(); 1090 inL = inR->clone();
1091 inL->setIDStr( ":" ); 1091 inL->setIDStr( ":" );
1092 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1092 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1093 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1093 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1094 local->addIncidence( inL ); 1094 local->addIncidence( inL );
1095 ++addedEvent; 1095 ++addedEvent;
1096 1096
1097 } 1097 }
1098 } else { 1098 } else {
1099 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1099 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1100 inR->setLastModified( modifiedCalendar ); 1100 inR->setLastModified( modifiedCalendar );
1101 inL = inR->clone(); 1101 inL = inR->clone();
1102 inL->setIDStr( ":" ); 1102 inL->setIDStr( ":" );
1103 local->addIncidence( inL ); 1103 local->addIncidence( inL );
1104 ++addedEvent; 1104 ++addedEvent;
1105 1105
1106 } else { 1106 } else {
1107 checkExternSyncEvent(eventRSyncSharp, inR); 1107 checkExternSyncEvent(eventRSyncSharp, inR);
1108 remote->deleteIncidence( inR ); 1108 remote->deleteIncidence( inR );
1109 ++deletedEventR; 1109 ++deletedEventR;
1110 } 1110 }
1111 } 1111 }
1112 } else { 1112 } else {
1113 ++filteredIN; 1113 ++filteredIN;
1114 } 1114 }
1115 } 1115 }
1116 } 1116 }
1117 inR = er.next(); 1117 inR = er.next();
1118 } 1118 }
1119 QPtrList<Incidence> el = local->rawIncidences(); 1119 QPtrList<Incidence> el = local->rawIncidences();
1120 inL = el.first(); 1120 inL = el.first();
1121 modulo = (el.count()/10)+1; 1121 modulo = (el.count()/10)+1;
1122 bar.setCaption (i18n("Add / remove events") ); 1122 bar.setCaption (i18n("Add / remove events") );
1123 bar.setTotalSteps ( el.count() ) ; 1123 bar.setTotalSteps ( el.count() ) ;
1124 bar.show(); 1124 bar.show();
1125 incCounter = 0; 1125 incCounter = 0;
1126 1126
1127 while ( inL ) { 1127 while ( inL ) {
1128 1128
1129 qApp->processEvents(); 1129 qApp->processEvents();
1130 if ( ! bar.isVisible() ) 1130 if ( ! bar.isVisible() )
1131 return false; 1131 return false;
1132 if ( incCounter % modulo == 0 ) 1132 if ( incCounter % modulo == 0 )
1133 bar.setProgress( incCounter ); 1133 bar.setProgress( incCounter );
1134 ++incCounter; 1134 ++incCounter;
1135 uid = inL->uid(); 1135 uid = inL->uid();
1136 bool skipIncidence = false; 1136 bool skipIncidence = false;
1137 if ( uid.left(15) == QString("last-syncEvent-") ) 1137 if ( uid.left(15) == QString("last-syncEvent-") )
1138 skipIncidence = true; 1138 skipIncidence = true;
1139 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1139 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1140 skipIncidence = true; 1140 skipIncidence = true;
1141 if ( !skipIncidence ) { 1141 if ( !skipIncidence ) {
1142 inR = remote->incidence( uid ); 1142 inR = remote->incidence( uid );
1143 if ( ! inR ) { 1143 if ( ! inR ) {
1144 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1144 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1145 // no conflict ********** add or delete local 1145 // no conflict ********** add or delete local
1146 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1146 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1147 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1147 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1148 checkExternSyncEvent(eventLSyncSharp, inL); 1148 checkExternSyncEvent(eventLSyncSharp, inL);
1149 local->deleteIncidence( inL ); 1149 local->deleteIncidence( inL );
1150 ++deletedEventL; 1150 ++deletedEventL;
1151 } else { 1151 } else {
1152 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1152 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1153 inL->removeID(mCurrentSyncDevice ); 1153 inL->removeID(mCurrentSyncDevice );
1154 ++addedEventR; 1154 ++addedEventR;
1155 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1155 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1156 inL->setLastModified( modifiedCalendar ); 1156 inL->setLastModified( modifiedCalendar );
1157 inR = inL->clone(); 1157 inR = inL->clone();
1158 inR->setIDStr( ":" ); 1158 inR->setIDStr( ":" );
1159 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1159 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1160 remote->addIncidence( inR ); 1160 remote->addIncidence( inR );
1161 } 1161 }
1162 } 1162 }
1163 } else { 1163 } else {
1164 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1164 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1165 checkExternSyncEvent(eventLSyncSharp, inL); 1165 checkExternSyncEvent(eventLSyncSharp, inL);
1166 local->deleteIncidence( inL ); 1166 local->deleteIncidence( inL );
1167 ++deletedEventL; 1167 ++deletedEventL;
1168 } else { 1168 } else {
1169 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1169 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1170 ++addedEventR; 1170 ++addedEventR;
1171 inL->setLastModified( modifiedCalendar ); 1171 inL->setLastModified( modifiedCalendar );
1172 inR = inL->clone(); 1172 inR = inL->clone();
1173 inR->setIDStr( ":" ); 1173 inR->setIDStr( ":" );
1174 remote->addIncidence( inR ); 1174 remote->addIncidence( inR );
1175 } 1175 }
1176 } 1176 }
1177 } 1177 }
1178 } else { 1178 } else {
1179 ++filteredOUT; 1179 ++filteredOUT;
1180 } 1180 }
1181 } 1181 }
1182 } 1182 }
1183 inL = el.next(); 1183 inL = el.next();
1184 } 1184 }
1185 int delFut = 0; 1185 int delFut = 0;
1186 int remRem = 0; 1186 int remRem = 0;
1187 if ( mSyncManager->mWriteBackInFuture ) { 1187 if ( mSyncManager->mWriteBackInFuture ) {
1188 er = remote->rawIncidences(); 1188 er = remote->rawIncidences();
1189 remRem = er.count(); 1189 remRem = er.count();
1190 inR = er.first(); 1190 inR = er.first();
1191 QDateTime dt; 1191 QDateTime dt;
1192 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1192 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1193 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1193 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1194 while ( inR ) { 1194 while ( inR ) {
1195 if ( inR->type() == "Todo" ) { 1195 if ( inR->type() == "Todo" ) {
1196 Todo * t = (Todo*)inR; 1196 Todo * t = (Todo*)inR;
1197 if ( t->hasDueDate() ) 1197 if ( t->hasDueDate() )
1198 dt = t->dtDue(); 1198 dt = t->dtDue();
1199 else 1199 else
1200 dt = cur.addSecs( 62 ); 1200 dt = cur.addSecs( 62 );
1201 } 1201 }
1202 else if (inR->type() == "Event" ) { 1202 else if (inR->type() == "Event" ) {
1203 bool ok; 1203 bool ok;
1204 dt = inR->getNextOccurence( cur, &ok ); 1204 dt = inR->getNextOccurence( cur, &ok );
1205 if ( !ok ) 1205 if ( !ok )
1206 dt = cur.addSecs( -62 ); 1206 dt = cur.addSecs( -62 );
1207 } 1207 }
1208 else 1208 else
1209 dt = inR->dtStart(); 1209 dt = inR->dtStart();
1210 if ( dt < cur || dt > end ) { 1210 if ( dt < cur || dt > end ) {
1211 remote->deleteIncidence( inR ); 1211 remote->deleteIncidence( inR );
1212 ++delFut; 1212 ++delFut;
1213 } 1213 }
1214 inR = er.next(); 1214 inR = er.next();
1215 } 1215 }
1216 } 1216 }
1217 bar.hide(); 1217 bar.hide();
1218 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1218 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1219 eventLSync->setReadOnly( false ); 1219 eventLSync->setReadOnly( false );
1220 eventLSync->setDtStart( mLastCalendarSync ); 1220 eventLSync->setDtStart( mLastCalendarSync );
1221 eventRSync->setDtStart( mLastCalendarSync ); 1221 eventRSync->setDtStart( mLastCalendarSync );
1222 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1222 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1223 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1223 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1224 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1224 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1225 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1225 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1226 eventLSync->setReadOnly( true ); 1226 eventLSync->setReadOnly( true );
1227 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1227 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1228 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1228 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1229 remote->addEvent( eventRSync ); 1229 remote->addEvent( eventRSync );
1230 else 1230 else
1231 delete eventRSync; 1231 delete eventRSync;
1232 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1232 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1233 QString mes; 1233 QString mes;
1234 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 ); 1234 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 );
1235 QString delmess; 1235 QString delmess;
1236 if ( delFut ) { 1236 if ( delFut ) {
1237 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); 1237 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);
1238 mes += delmess; 1238 mes += delmess;
1239 } 1239 }
1240 mes = i18n("Local calendar changed!\n") +mes; 1240 mes = i18n("Local calendar changed!\n") +mes;
1241 mCalendar->checkAlarmForIncidence( 0, true ); 1241 mCalendar->checkAlarmForIncidence( 0, true );
1242 qDebug( mes ); 1242 qDebug( mes );
1243 if ( mSyncManager->mShowSyncSummary ) { 1243 if ( mSyncManager->mShowSyncSummary ) {
1244 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1244 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1245 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1245 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1246 qDebug("KO: WB cancelled "); 1246 qDebug("KO: WB cancelled ");
1247 return false; 1247 return false;
1248 } 1248 }
1249 } 1249 }
1250 return syncOK; 1250 return syncOK;
1251} 1251}
1252 1252
1253void CalendarView::setSyncDevice( QString s ) 1253void CalendarView::setSyncDevice( QString s )
1254{ 1254{
1255 mCurrentSyncDevice= s; 1255 mCurrentSyncDevice= s;
1256} 1256}
1257void CalendarView::setSyncName( QString s ) 1257void CalendarView::setSyncName( QString s )
1258{ 1258{
1259 mCurrentSyncName= s; 1259 mCurrentSyncName= s;
1260} 1260}
1261bool CalendarView::syncCalendar(QString filename, int mode) 1261bool CalendarView::syncCalendar(QString filename, int mode)
1262{ 1262{
1263 //qDebug("syncCalendar %s ", filename.latin1()); 1263 //qDebug("syncCalendar %s ", filename.latin1());
1264 mGlobalSyncMode = SYNC_MODE_NORMAL; 1264 mGlobalSyncMode = SYNC_MODE_NORMAL;
1265 CalendarLocal* calendar = new CalendarLocal(); 1265 CalendarLocal* calendar = new CalendarLocal();
1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1267 FileStorage* storage = new FileStorage( calendar ); 1267 FileStorage* storage = new FileStorage( calendar );
1268 bool syncOK = false; 1268 bool syncOK = false;
1269 storage->setFileName( filename ); 1269 storage->setFileName( filename );
1270 // qDebug("loading ... "); 1270 // qDebug("loading ... ");
1271 if ( storage->load() ) { 1271 if ( storage->load() ) {
1272 getEventViewerDialog()->setSyncMode( true ); 1272 getEventViewerDialog()->setSyncMode( true );
1273 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1273 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1274 getEventViewerDialog()->setSyncMode( false ); 1274 getEventViewerDialog()->setSyncMode( false );
1275 if ( syncOK ) { 1275 if ( syncOK ) {
1276 if ( mSyncManager->mWriteBackFile ) 1276 if ( mSyncManager->mWriteBackFile )
1277 { 1277 {
1278 storage->setSaveFormat( new ICalFormat() ); 1278 storage->setSaveFormat( new ICalFormat() );
1279 storage->save(); 1279 storage->save();
1280 } 1280 }
1281 } 1281 }
1282 setModified( true ); 1282 setModified( true );
1283 } 1283 }
1284 delete storage; 1284 delete storage;
1285 delete calendar; 1285 delete calendar;
1286 if ( syncOK ) 1286 if ( syncOK )
1287 updateView(); 1287 updateView();
1288 return syncOK; 1288 return syncOK;
1289} 1289}
1290 1290
1291void CalendarView::syncExternal( int mode ) 1291void CalendarView::syncExternal( int mode )
1292{ 1292{
1293 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1293 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1294 1294
1295 qApp->processEvents(); 1295 qApp->processEvents();
1296 CalendarLocal* calendar = new CalendarLocal(); 1296 CalendarLocal* calendar = new CalendarLocal();
1297 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1297 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1298 bool syncOK = false; 1298 bool syncOK = false;
1299 bool loadSuccess = false; 1299 bool loadSuccess = false;
1300 PhoneFormat* phoneFormat = 0; 1300 PhoneFormat* phoneFormat = 0;
1301 emit tempDisableBR(true); 1301 emit tempDisableBR(true);
1302#ifndef DESKTOP_VERSION 1302#ifndef DESKTOP_VERSION
1303 SharpFormat* sharpFormat = 0; 1303 SharpFormat* sharpFormat = 0;
1304 if ( mode == 0 ) { // sharp 1304 if ( mode == 0 ) { // sharp
1305 sharpFormat = new SharpFormat () ; 1305 sharpFormat = new SharpFormat () ;
1306 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1306 loadSuccess = sharpFormat->load( calendar, mCalendar );
1307 1307
1308 } else 1308 } else
1309#endif 1309#endif
1310 if ( mode == 1 ) { // phone 1310 if ( mode == 1 ) { // phone
1311 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1311 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1312 mSyncManager->mPhoneDevice, 1312 mSyncManager->mPhoneDevice,
1313 mSyncManager->mPhoneConnection, 1313 mSyncManager->mPhoneConnection,
1314 mSyncManager->mPhoneModel); 1314 mSyncManager->mPhoneModel);
1315 loadSuccess = phoneFormat->load( calendar,mCalendar); 1315 loadSuccess = phoneFormat->load( calendar,mCalendar);
1316 1316
1317 } else { 1317 } else {
1318 emit tempDisableBR(false); 1318 emit tempDisableBR(false);
1319 return; 1319 return;
1320 } 1320 }
1321 if ( loadSuccess ) { 1321 if ( loadSuccess ) {
1322 getEventViewerDialog()->setSyncMode( true ); 1322 getEventViewerDialog()->setSyncMode( true );
1323 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1323 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1324 getEventViewerDialog()->setSyncMode( false ); 1324 getEventViewerDialog()->setSyncMode( false );
1325 qApp->processEvents(); 1325 qApp->processEvents();
1326 if ( syncOK ) { 1326 if ( syncOK ) {
1327 if ( mSyncManager->mWriteBackFile ) 1327 if ( mSyncManager->mWriteBackFile )
1328 { 1328 {
1329 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1329 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1330 Incidence* inc = iL.first(); 1330 Incidence* inc = iL.first();
1331 if ( phoneFormat ) { 1331 if ( phoneFormat ) {
1332 while ( inc ) { 1332 while ( inc ) {
1333 inc->removeID(mCurrentSyncDevice); 1333 inc->removeID(mCurrentSyncDevice);
1334 inc = iL.next(); 1334 inc = iL.next();
1335 } 1335 }
1336 } 1336 }
1337#ifndef DESKTOP_VERSION 1337#ifndef DESKTOP_VERSION
1338 if ( sharpFormat ) 1338 if ( sharpFormat )
1339 sharpFormat->save(calendar); 1339 sharpFormat->save(calendar);
1340#endif 1340#endif
1341 if ( phoneFormat ) 1341 if ( phoneFormat )
1342 phoneFormat->save(calendar); 1342 phoneFormat->save(calendar);
1343 iL = calendar->rawIncidences(); 1343 iL = calendar->rawIncidences();
1344 inc = iL.first(); 1344 inc = iL.first();
1345 Incidence* loc; 1345 Incidence* loc;
1346 while ( inc ) { 1346 while ( inc ) {
1347 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1347 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1348 loc = mCalendar->incidence(inc->uid() ); 1348 loc = mCalendar->incidence(inc->uid() );
1349 if ( loc ) { 1349 if ( loc ) {
1350 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1350 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1351 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1351 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1352 } 1352 }
1353 } 1353 }
1354 inc = iL.next(); 1354 inc = iL.next();
1355 } 1355 }
1356 Incidence* lse = getLastSyncEvent(); 1356 Incidence* lse = getLastSyncEvent();
1357 if ( lse ) { 1357 if ( lse ) {
1358 lse->setReadOnly( false ); 1358 lse->setReadOnly( false );
1359 lse->setDescription( "" ); 1359 lse->setDescription( "" );
1360 lse->setReadOnly( true ); 1360 lse->setReadOnly( true );
1361 } 1361 }
1362 } 1362 }
1363 } else { 1363 } else {
1364 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1364 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1365 } 1365 }
1366 setModified( true ); 1366 setModified( true );
1367 } else { 1367 } else {
1368 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1368 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1369 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1369 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1370 question, i18n("Ok")) ; 1370 question, i18n("Ok")) ;
1371 1371
1372 } 1372 }
1373 delete calendar; 1373 delete calendar;
1374 updateView(); 1374 updateView();
1375 emit tempDisableBR(false); 1375 emit tempDisableBR(false);
1376 return ;//syncOK; 1376 return ;//syncOK;
1377 1377
1378} 1378}
1379 1379
1380bool CalendarView::importBday() 1380bool CalendarView::importBday()
1381{ 1381{
1382#ifndef KORG_NOKABC 1382#ifndef KORG_NOKABC
1383 1383
1384#ifdef DESKTOP_VERSION 1384#ifdef DESKTOP_VERSION
1385 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1385 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1386 KABC::AddressBook::Iterator it; 1386 KABC::AddressBook::Iterator it;
1387 int count = 0; 1387 int count = 0;
1388 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1388 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1389 ++count; 1389 ++count;
1390 } 1390 }
1391 QProgressBar bar(count,0 ); 1391 QProgressBar bar(count,0 );
1392 int w = 300; 1392 int w = 300;
1393 if ( QApplication::desktop()->width() < 320 ) 1393 if ( QApplication::desktop()->width() < 320 )
1394 w = 220; 1394 w = 220;
1395 int h = bar.sizeHint().height() ; 1395 int h = bar.sizeHint().height() ;
1396 int dw = QApplication::desktop()->width(); 1396 int dw = QApplication::desktop()->width();
1397 int dh = QApplication::desktop()->height(); 1397 int dh = QApplication::desktop()->height();
1398 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1398 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1399 bar.show(); 1399 bar.show();
1400 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1400 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1401 qApp->processEvents(); 1401 qApp->processEvents();
1402 count = 0; 1402 count = 0;
1403 int addCount = 0; 1403 int addCount = 0;
1404 KCal::Attendee* a = 0; 1404 KCal::Attendee* a = 0;
1405 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1405 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1406 if ( ! bar.isVisible() ) 1406 if ( ! bar.isVisible() )
1407 return false; 1407 return false;
1408 bar.setProgress( count++ ); 1408 bar.setProgress( count++ );
1409 qApp->processEvents(); 1409 qApp->processEvents();
1410 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1410 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1411 if ( (*it).birthday().date().isValid() ){ 1411 if ( (*it).birthday().date().isValid() ){
1412 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1412 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1413 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1413 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1414 ++addCount; 1414 ++addCount;
1415 } 1415 }
1416 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1416 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1417 if ( anni.isValid() ){ 1417 if ( anni.isValid() ){
1418 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1418 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1419 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1419 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1420 ++addCount; 1420 ++addCount;
1421 } 1421 }
1422 } 1422 }
1423 updateView(); 1423 updateView();
1424 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1424 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1425#else //DESKTOP_VERSION 1425#else //DESKTOP_VERSION
1426 1426
1427 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1427 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1428 // the result should now arrive through method insertBirthdays 1428 // the result should now arrive through method insertBirthdays
1429 1429
1430#endif //DESKTOP_VERSION 1430#endif //DESKTOP_VERSION
1431 1431
1432#endif //KORG_NOKABC 1432#endif //KORG_NOKABC
1433 1433
1434 1434
1435 return true; 1435 return true;
1436} 1436}
1437 1437
1438// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1438// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1439void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1439void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1440 const QStringList& anniversaryList, const QStringList& realNameList, 1440 const QStringList& anniversaryList, const QStringList& realNameList,
1441 const QStringList& emailList, const QStringList& assembledNameList, 1441 const QStringList& emailList, const QStringList& assembledNameList,
1442 const QStringList& uidList) 1442 const QStringList& uidList)
1443{ 1443{
1444 //qDebug("KO::CalendarView::insertBirthdays"); 1444 //qDebug("KO::CalendarView::insertBirthdays");
1445 if (uid == this->name()) 1445 if (uid == this->name())
1446 { 1446 {
1447 int count = birthdayList.count(); 1447 int count = birthdayList.count();
1448 int addCount = 0; 1448 int addCount = 0;
1449 KCal::Attendee* a = 0; 1449 KCal::Attendee* a = 0;
1450 1450
1451 //qDebug("CalView 1 %i", count); 1451 //qDebug("CalView 1 %i", count);
1452 1452
1453 QProgressBar bar(count,0 ); 1453 QProgressBar bar(count,0 );
1454 int w = 300; 1454 int w = 300;
1455 if ( QApplication::desktop()->width() < 320 ) 1455 if ( QApplication::desktop()->width() < 320 )
1456 w = 220; 1456 w = 220;
1457 int h = bar.sizeHint().height() ; 1457 int h = bar.sizeHint().height() ;
1458 int dw = QApplication::desktop()->width(); 1458 int dw = QApplication::desktop()->width();
1459 int dh = QApplication::desktop()->height(); 1459 int dh = QApplication::desktop()->height();
1460 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1460 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1461 bar.show(); 1461 bar.show();
1462 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1462 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1463 qApp->processEvents(); 1463 qApp->processEvents();
1464 1464
1465 QDate birthday; 1465 QDate birthday;
1466 QDate anniversary; 1466 QDate anniversary;
1467 QString realName; 1467 QString realName;
1468 QString email; 1468 QString email;
1469 QString assembledName; 1469 QString assembledName;
1470 QString uid; 1470 QString uid;
1471 bool ok = true; 1471 bool ok = true;
1472 for ( int i = 0; i < count; i++) 1472 for ( int i = 0; i < count; i++)
1473 { 1473 {
1474 if ( ! bar.isVisible() ) 1474 if ( ! bar.isVisible() )
1475 return; 1475 return;
1476 bar.setProgress( i ); 1476 bar.setProgress( i );
1477 qApp->processEvents(); 1477 qApp->processEvents();
1478 1478
1479 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1479 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1480 if (!ok) { 1480 if (!ok) {
1481 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1481 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1482 } 1482 }
1483 1483
1484 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1484 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1485 if (!ok) { 1485 if (!ok) {
1486 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1486 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1487 } 1487 }
1488 realName = realNameList[i]; 1488 realName = realNameList[i];
1489 email = emailList[i]; 1489 email = emailList[i];
1490 assembledName = assembledNameList[i]; 1490 assembledName = assembledNameList[i];
1491 uid = uidList[i]; 1491 uid = uidList[i];
1492 //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() ); 1492 //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() );
1493 1493
1494 if ( birthday.isValid() ){ 1494 if ( birthday.isValid() ){
1495 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1495 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1496 KCal::Attendee::ReqParticipant,uid) ; 1496 KCal::Attendee::ReqParticipant,uid) ;
1497 if ( addAnniversary( birthday, assembledName, a, true ) ) 1497 if ( addAnniversary( birthday, assembledName, a, true ) )
1498 ++addCount; 1498 ++addCount;
1499 } 1499 }
1500 1500
1501 if ( anniversary.isValid() ){ 1501 if ( anniversary.isValid() ){
1502 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1502 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1503 KCal::Attendee::ReqParticipant,uid) ; 1503 KCal::Attendee::ReqParticipant,uid) ;
1504 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1504 if ( addAnniversary( anniversary, assembledName, a, false ) )
1505 ++addCount; 1505 ++addCount;
1506 } 1506 }
1507 } 1507 }
1508 1508
1509 updateView(); 1509 updateView();
1510 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1510 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1511 1511
1512 } 1512 }
1513 1513
1514} 1514}
1515 1515
1516 1516
1517 1517
1518bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1518bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1519{ 1519{
1520 //qDebug("addAnni "); 1520 //qDebug("addAnni ");
1521 Event * ev = new Event(); 1521 Event * ev = new Event();
1522 if ( a ) { 1522 if ( a ) {
1523 ev->addAttendee( a ); 1523 ev->addAttendee( a );
1524 } 1524 }
1525 QString kind; 1525 QString kind;
1526 if ( birthday ) { 1526 if ( birthday ) {
1527 kind = i18n( "Birthday" ); 1527 kind = i18n( "Birthday" );
1528 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1528 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1529 } 1529 }
1530 else { 1530 else {
1531 kind = i18n( "Anniversary" ); 1531 kind = i18n( "Anniversary" );
1532 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1532 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1533 } 1533 }
1534 ev->setOrganizer(a->email()); 1534 //ev->setOrganizer(a->email());
1535 ev->setCategories( kind ); 1535 ev->setCategories( kind );
1536 ev->setDtStart( QDateTime(date) ); 1536 ev->setDtStart( QDateTime(date) );
1537 ev->setDtEnd( QDateTime(date) ); 1537 ev->setDtEnd( QDateTime(date) );
1538 ev->setFloats( true ); 1538 ev->setFloats( true );
1539 Recurrence * rec = ev->recurrence(); 1539 Recurrence * rec = ev->recurrence();
1540 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1540 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1541 rec->addYearlyNum( date.month() ); 1541 rec->addYearlyNum( date.month() );
1542 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1542 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1543 delete ev; 1543 delete ev;
1544 return false; 1544 return false;
1545 } 1545 }
1546 return true; 1546 return true;
1547 1547
1548} 1548}
1549bool CalendarView::importQtopia( const QString &categories, 1549bool CalendarView::importQtopia( const QString &categories,
1550 const QString &datebook, 1550 const QString &datebook,
1551 const QString &todolist ) 1551 const QString &todolist )
1552{ 1552{
1553 1553
1554 QtopiaFormat qtopiaFormat; 1554 QtopiaFormat qtopiaFormat;
1555 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1555 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1556 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1556 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1557 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1557 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1558 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1558 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1559 1559
1560 updateView(); 1560 updateView();
1561 return true; 1561 return true;
1562 1562
1563#if 0 1563#if 0
1564 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1564 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1565 mCurrentSyncDevice = "qtopia-XML"; 1565 mCurrentSyncDevice = "qtopia-XML";
1566 if ( mSyncManager->mAskForPreferences ) 1566 if ( mSyncManager->mAskForPreferences )
1567 edit_sync_options(); 1567 edit_sync_options();
1568 qApp->processEvents(); 1568 qApp->processEvents();
1569 CalendarLocal* calendar = new CalendarLocal(); 1569 CalendarLocal* calendar = new CalendarLocal();
1570 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1570 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1571 bool syncOK = false; 1571 bool syncOK = false;
1572 QtopiaFormat qtopiaFormat; 1572 QtopiaFormat qtopiaFormat;
1573 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1573 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1574 bool loadOk = true; 1574 bool loadOk = true;
1575 if ( !categories.isEmpty() ) 1575 if ( !categories.isEmpty() )
1576 loadOk = qtopiaFormat.load( calendar, categories ); 1576 loadOk = qtopiaFormat.load( calendar, categories );
1577 if ( loadOk && !datebook.isEmpty() ) 1577 if ( loadOk && !datebook.isEmpty() )
1578 loadOk = qtopiaFormat.load( calendar, datebook ); 1578 loadOk = qtopiaFormat.load( calendar, datebook );
1579 if ( loadOk && !todolist.isEmpty() ) 1579 if ( loadOk && !todolist.isEmpty() )
1580 loadOk = qtopiaFormat.load( calendar, todolist ); 1580 loadOk = qtopiaFormat.load( calendar, todolist );
1581 1581
1582 if ( loadOk ) { 1582 if ( loadOk ) {
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 // write back XML file 1590 // write back XML file
1591 1591
1592 } 1592 }
1593 setModified( true ); 1593 setModified( true );
1594 } 1594 }
1595 } else { 1595 } else {
1596 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1596 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1597 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1597 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1598 question, i18n("Ok")) ; 1598 question, i18n("Ok")) ;
1599 } 1599 }
1600 delete calendar; 1600 delete calendar;
1601 updateView(); 1601 updateView();
1602 return syncOK; 1602 return syncOK;
1603 1603
1604 1604
1605#endif 1605#endif
1606 1606
1607} 1607}
1608 1608
1609void CalendarView::setSyncEventsReadOnly() 1609void CalendarView::setSyncEventsReadOnly()
1610{ 1610{
1611 Event * ev; 1611 Event * ev;
1612 QPtrList<Event> eL = mCalendar->rawEvents(); 1612 QPtrList<Event> eL = mCalendar->rawEvents();
1613 ev = eL.first(); 1613 ev = eL.first();
1614 while ( ev ) { 1614 while ( ev ) {
1615 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1615 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1616 ev->setReadOnly( true ); 1616 ev->setReadOnly( true );
1617 ev = eL.next(); 1617 ev = eL.next();
1618 } 1618 }
1619} 1619}
1620bool CalendarView::openCalendar(QString filename, bool merge) 1620bool CalendarView::openCalendar(QString filename, bool merge)
1621{ 1621{
1622 1622
1623 if (filename.isEmpty()) { 1623 if (filename.isEmpty()) {
1624 return false; 1624 return false;
1625 } 1625 }
1626 1626
1627 if (!QFile::exists(filename)) { 1627 if (!QFile::exists(filename)) {
1628 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1628 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1629 return false; 1629 return false;
1630 } 1630 }
1631 1631
1632 globalFlagBlockAgenda = 1; 1632 globalFlagBlockAgenda = 1;
1633 if (!merge) mCalendar->close(); 1633 if (!merge) mCalendar->close();
1634 1634
1635 mStorage->setFileName( filename ); 1635 mStorage->setFileName( filename );
1636 1636
1637 if ( mStorage->load() ) { 1637 if ( mStorage->load() ) {
1638 if ( merge ) ;//setModified( true ); 1638 if ( merge ) ;//setModified( true );
1639 else { 1639 else {
1640 //setModified( true ); 1640 //setModified( true );
1641 mViewManager->setDocumentId( filename ); 1641 mViewManager->setDocumentId( filename );
1642 mDialogManager->setDocumentId( filename ); 1642 mDialogManager->setDocumentId( filename );
1643 mTodoList->setDocumentId( filename ); 1643 mTodoList->setDocumentId( filename );
1644 } 1644 }
1645 globalFlagBlockAgenda = 2; 1645 globalFlagBlockAgenda = 2;
1646 // if ( getLastSyncEvent() ) 1646 // if ( getLastSyncEvent() )
1647 // getLastSyncEvent()->setReadOnly( true ); 1647 // getLastSyncEvent()->setReadOnly( true );
1648 mCalendar->reInitAlarmSettings(); 1648 mCalendar->reInitAlarmSettings();
1649 setSyncEventsReadOnly(); 1649 setSyncEventsReadOnly();
1650 updateUnmanagedViews(); 1650 updateUnmanagedViews();
1651 updateView(); 1651 updateView();
1652 if ( filename != MainWindow::defaultFileName() ) { 1652 if ( filename != MainWindow::defaultFileName() ) {
1653 saveCalendar( MainWindow::defaultFileName() ); 1653 saveCalendar( MainWindow::defaultFileName() );
1654 } else { 1654 } else {
1655 QFileInfo finf ( MainWindow::defaultFileName()); 1655 QFileInfo finf ( MainWindow::defaultFileName());
1656 if ( finf.exists() ) { 1656 if ( finf.exists() ) {
1657 setLoadedFileVersion( finf.lastModified () ); 1657 setLoadedFileVersion( finf.lastModified () );
1658 } 1658 }
1659 } 1659 }
1660 return true; 1660 return true;
1661 } else { 1661 } else {
1662 // while failing to load, the calendar object could 1662 // while failing to load, the calendar object could
1663 // have become partially populated. Clear it out. 1663 // have become partially populated. Clear it out.
1664 if ( !merge ) { 1664 if ( !merge ) {
1665 mCalendar->close(); 1665 mCalendar->close();
1666 mViewManager->setDocumentId( filename ); 1666 mViewManager->setDocumentId( filename );
1667 mDialogManager->setDocumentId( filename ); 1667 mDialogManager->setDocumentId( filename );
1668 mTodoList->setDocumentId( filename ); 1668 mTodoList->setDocumentId( filename );
1669 } 1669 }
1670 1670
1671 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1671 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1672 1672
1673 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1673 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1674 globalFlagBlockAgenda = 2; 1674 globalFlagBlockAgenda = 2;
1675 mCalendar->reInitAlarmSettings(); 1675 mCalendar->reInitAlarmSettings();
1676 setSyncEventsReadOnly(); 1676 setSyncEventsReadOnly();
1677 updateUnmanagedViews(); 1677 updateUnmanagedViews();
1678 updateView(); 1678 updateView();
1679 } 1679 }
1680 return false; 1680 return false;
1681} 1681}
1682void CalendarView::showOpenError() 1682void CalendarView::showOpenError()
1683{ 1683{
1684 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1684 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1685} 1685}
1686void CalendarView::setLoadedFileVersion(QDateTime dt) 1686void CalendarView::setLoadedFileVersion(QDateTime dt)
1687{ 1687{
1688 loadedFileVersion = dt; 1688 loadedFileVersion = dt;
1689} 1689}
1690bool CalendarView::checkFileChanged(QString fn) 1690bool CalendarView::checkFileChanged(QString fn)
1691{ 1691{
1692 QFileInfo finf ( fn ); 1692 QFileInfo finf ( fn );
1693 if ( !finf.exists() ) 1693 if ( !finf.exists() )
1694 return true; 1694 return true;
1695 QDateTime dt = finf.lastModified (); 1695 QDateTime dt = finf.lastModified ();
1696 if ( dt <= loadedFileVersion ) 1696 if ( dt <= loadedFileVersion )
1697 return false; 1697 return false;
1698 return true; 1698 return true;
1699 1699
1700} 1700}
1701void CalendarView::watchSavedFile() 1701void CalendarView::watchSavedFile()
1702{ 1702{
1703 QFileInfo finf ( MainWindow::defaultFileName()); 1703 QFileInfo finf ( MainWindow::defaultFileName());
1704 if ( !finf.exists() ) 1704 if ( !finf.exists() )
1705 return; 1705 return;
1706 QDateTime dt = finf.lastModified (); 1706 QDateTime dt = finf.lastModified ();
1707 if ( dt < loadedFileVersion ) { 1707 if ( dt < loadedFileVersion ) {
1708 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1708 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1709 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1709 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1710 return; 1710 return;
1711 } 1711 }
1712 loadedFileVersion = dt; 1712 loadedFileVersion = dt;
1713} 1713}
1714 1714
1715bool CalendarView::checkFileVersion(QString fn) 1715bool CalendarView::checkFileVersion(QString fn)
1716{ 1716{
1717 QFileInfo finf ( fn ); 1717 QFileInfo finf ( fn );
1718 if ( !finf.exists() ) 1718 if ( !finf.exists() )
1719 return true; 1719 return true;
1720 QDateTime dt = finf.lastModified (); 1720 QDateTime dt = finf.lastModified ();
1721 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1721 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1722 //qDebug("file on disk version %s",dt.toString().latin1()); 1722 //qDebug("file on disk version %s",dt.toString().latin1());
1723 if ( dt <= loadedFileVersion ) 1723 if ( dt <= loadedFileVersion )
1724 return true; 1724 return true;
1725 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1725 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1726 i18n("KO/Pi Warning"),i18n("Overwrite"), 1726 i18n("KO/Pi Warning"),i18n("Overwrite"),
1727 i18n("Sync+save")); 1727 i18n("Sync+save"));
1728 1728
1729 if ( km == KMessageBox::Cancel ) 1729 if ( km == KMessageBox::Cancel )
1730 return false; 1730 return false;
1731 if ( km == KMessageBox::Yes ) 1731 if ( km == KMessageBox::Yes )
1732 return true; 1732 return true;
1733 1733
1734 setSyncDevice("deleteaftersync" ); 1734 setSyncDevice("deleteaftersync" );
1735 mSyncManager->mAskForPreferences = true; 1735 mSyncManager->mAskForPreferences = true;
1736 mSyncManager->mSyncAlgoPrefs = 3; 1736 mSyncManager->mSyncAlgoPrefs = 3;
1737 mSyncManager->mWriteBackFile = false; 1737 mSyncManager->mWriteBackFile = false;
1738 mSyncManager->mWriteBackExistingOnly = false; 1738 mSyncManager->mWriteBackExistingOnly = false;
1739 mSyncManager->mShowSyncSummary = false; 1739 mSyncManager->mShowSyncSummary = false;
1740 syncCalendar( fn, 3 ); 1740 syncCalendar( fn, 3 );
1741 Event * e = getLastSyncEvent(); 1741 Event * e = getLastSyncEvent();
1742 mCalendar->deleteEvent ( e ); 1742 mCalendar->deleteEvent ( e );
1743 updateView(); 1743 updateView();
1744 return true; 1744 return true;
1745} 1745}
1746 1746
1747bool CalendarView::saveCalendar( QString filename ) 1747bool CalendarView::saveCalendar( QString filename )
1748{ 1748{
1749 1749
1750 // Store back all unsaved data into calendar object 1750 // Store back all unsaved data into calendar object
1751 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1751 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1752 if ( mViewManager->currentView() ) 1752 if ( mViewManager->currentView() )
1753 mViewManager->currentView()->flushView(); 1753 mViewManager->currentView()->flushView();
1754 1754
1755 1755
1756 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1756 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1757 mStorage->setSaveFormat( new ICalFormat() ); 1757 mStorage->setSaveFormat( new ICalFormat() );
1758 mStorage->setFileName( filename ); 1758 mStorage->setFileName( filename );
1759 bool success; 1759 bool success;
1760 success = mStorage->save(); 1760 success = mStorage->save();
1761 if ( !success ) { 1761 if ( !success ) {
1762 return false; 1762 return false;
1763 } 1763 }
1764 if ( filename == MainWindow::defaultFileName() ) { 1764 if ( filename == MainWindow::defaultFileName() ) {
1765 setLoadedFileVersion( lfv ); 1765 setLoadedFileVersion( lfv );
1766 watchSavedFile(); 1766 watchSavedFile();
1767 } 1767 }
1768 return true; 1768 return true;
1769} 1769}
1770 1770
1771void CalendarView::closeCalendar() 1771void CalendarView::closeCalendar()
1772{ 1772{
1773 1773
1774 // child windows no longer valid 1774 // child windows no longer valid
1775 emit closingDown(); 1775 emit closingDown();
1776 1776
1777 mCalendar->close(); 1777 mCalendar->close();
1778 setModified(false); 1778 setModified(false);
1779 updateView(); 1779 updateView();
1780} 1780}
1781 1781
1782void CalendarView::archiveCalendar() 1782void CalendarView::archiveCalendar()
1783{ 1783{
1784 mDialogManager->showArchiveDialog(); 1784 mDialogManager->showArchiveDialog();
1785} 1785}
1786 1786
1787 1787
1788void CalendarView::readSettings() 1788void CalendarView::readSettings()
1789{ 1789{
1790 1790
1791 1791
1792 // mViewManager->showAgendaView(); 1792 // mViewManager->showAgendaView();
1793 QString str; 1793 QString str;
1794 //qDebug("CalendarView::readSettings() "); 1794 //qDebug("CalendarView::readSettings() ");
1795 // read settings from the KConfig, supplying reasonable 1795 // read settings from the KConfig, supplying reasonable
1796 // defaults where none are to be found 1796 // defaults where none are to be found
1797 KConfig *config = KOGlobals::config(); 1797 KConfig *config = KOGlobals::config();
1798#ifndef KORG_NOSPLITTER 1798#ifndef KORG_NOSPLITTER
1799 config->setGroup("KOrganizer Geometry"); 1799 config->setGroup("KOrganizer Geometry");
1800 1800
1801 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1801 QValueList<int> sizes = config->readIntListEntry("Separator1");
1802 if (sizes.count() != 2) { 1802 if (sizes.count() != 2) {
1803 sizes << mDateNavigator->minimumSizeHint().width(); 1803 sizes << mDateNavigator->minimumSizeHint().width();
1804 sizes << 300; 1804 sizes << 300;
1805 } 1805 }
1806 mPanner->setSizes(sizes); 1806 mPanner->setSizes(sizes);
1807 1807
1808 sizes = config->readIntListEntry("Separator2"); 1808 sizes = config->readIntListEntry("Separator2");
1809 if ( ( mResourceView && sizes.count() == 4 ) || 1809 if ( ( mResourceView && sizes.count() == 4 ) ||
1810 ( !mResourceView && sizes.count() == 3 ) ) { 1810 ( !mResourceView && sizes.count() == 3 ) ) {
1811 mLeftSplitter->setSizes(sizes); 1811 mLeftSplitter->setSizes(sizes);
1812 } 1812 }
1813#endif 1813#endif
1814 globalFlagBlockAgenda = 1; 1814 globalFlagBlockAgenda = 1;
1815 mViewManager->showAgendaView(); 1815 mViewManager->showAgendaView();
1816 //mViewManager->readSettings( config ); 1816 //mViewManager->readSettings( config );
1817 mTodoList->restoreLayout(config,QString("Todo Layout")); 1817 mTodoList->restoreLayout(config,QString("Todo Layout"));
1818 readFilterSettings(config); 1818 readFilterSettings(config);
1819 config->setGroup( "Views" ); 1819 config->setGroup( "Views" );
1820 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1820 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1821 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1821 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1822 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1822 else if ( dateCount == 7 ) mNavigator->selectWeek();
1823 else mNavigator->selectDates( dateCount ); 1823 else mNavigator->selectDates( dateCount );
1824 // mViewManager->readSettings( config ); 1824 // mViewManager->readSettings( config );
1825 updateConfig(); 1825 updateConfig();
1826 globalFlagBlockAgenda = 2; 1826 globalFlagBlockAgenda = 2;
1827 mViewManager->readSettings( config ); 1827 mViewManager->readSettings( config );
1828#ifdef DESKTOP_VERSION 1828#ifdef DESKTOP_VERSION
1829 config->setGroup("WidgetLayout"); 1829 config->setGroup("WidgetLayout");
1830 QStringList list; 1830 QStringList list;
1831 list = config->readListEntry("MainLayout"); 1831 list = config->readListEntry("MainLayout");
1832 int x,y,w,h; 1832 int x,y,w,h;
1833 if ( ! list.isEmpty() ) { 1833 if ( ! list.isEmpty() ) {
1834 x = list[0].toInt(); 1834 x = list[0].toInt();
1835 y = list[1].toInt(); 1835 y = list[1].toInt();
1836 w = list[2].toInt(); 1836 w = list[2].toInt();
1837 h = list[3].toInt(); 1837 h = list[3].toInt();
1838 topLevelWidget()->setGeometry(x,y,w,h); 1838 topLevelWidget()->setGeometry(x,y,w,h);
1839 1839
1840 } else { 1840 } else {
1841 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1841 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1842 } 1842 }
1843 list = config->readListEntry("EditEventLayout"); 1843 list = config->readListEntry("EditEventLayout");
1844 if ( ! list.isEmpty() ) { 1844 if ( ! list.isEmpty() ) {
1845 x = list[0].toInt(); 1845 x = list[0].toInt();
1846 y = list[1].toInt(); 1846 y = list[1].toInt();
1847 w = list[2].toInt(); 1847 w = list[2].toInt();
1848 h = list[3].toInt(); 1848 h = list[3].toInt();
1849 mEventEditor->setGeometry(x,y,w,h); 1849 mEventEditor->setGeometry(x,y,w,h);
1850 1850
1851 } 1851 }
1852 list = config->readListEntry("EditTodoLayout"); 1852 list = config->readListEntry("EditTodoLayout");
1853 if ( ! list.isEmpty() ) { 1853 if ( ! list.isEmpty() ) {
1854 x = list[0].toInt(); 1854 x = list[0].toInt();
1855 y = list[1].toInt(); 1855 y = list[1].toInt();
1856 w = list[2].toInt(); 1856 w = list[2].toInt();
1857 h = list[3].toInt(); 1857 h = list[3].toInt();
1858 mTodoEditor->setGeometry(x,y,w,h); 1858 mTodoEditor->setGeometry(x,y,w,h);
1859 1859
1860 } 1860 }
1861 list = config->readListEntry("ViewerLayout"); 1861 list = config->readListEntry("ViewerLayout");
1862 if ( ! list.isEmpty() ) { 1862 if ( ! list.isEmpty() ) {
1863 x = list[0].toInt(); 1863 x = list[0].toInt();
1864 y = list[1].toInt(); 1864 y = list[1].toInt();
1865 w = list[2].toInt(); 1865 w = list[2].toInt();
1866 h = list[3].toInt(); 1866 h = list[3].toInt();
1867 getEventViewerDialog()->setGeometry(x,y,w,h); 1867 getEventViewerDialog()->setGeometry(x,y,w,h);
1868 } 1868 }
1869#endif 1869#endif
1870 1870
1871} 1871}
1872 1872
1873 1873
1874void CalendarView::writeSettings() 1874void CalendarView::writeSettings()
1875{ 1875{
1876 // kdDebug() << "CalendarView::writeSettings" << endl; 1876 // kdDebug() << "CalendarView::writeSettings" << endl;
1877 1877
1878 KConfig *config = KOGlobals::config(); 1878 KConfig *config = KOGlobals::config();
1879 1879
1880#ifndef KORG_NOSPLITTER 1880#ifndef KORG_NOSPLITTER
1881 config->setGroup("KOrganizer Geometry"); 1881 config->setGroup("KOrganizer Geometry");
1882 1882
1883 QValueList<int> list = mPanner->sizes(); 1883 QValueList<int> list = mPanner->sizes();
1884 config->writeEntry("Separator1",list); 1884 config->writeEntry("Separator1",list);
1885 1885
1886 list = mLeftSplitter->sizes(); 1886 list = mLeftSplitter->sizes();
1887 config->writeEntry("Separator2",list); 1887 config->writeEntry("Separator2",list);
1888#endif 1888#endif
1889 1889
1890 mViewManager->writeSettings( config ); 1890 mViewManager->writeSettings( config );
1891 mTodoList->saveLayout(config,QString("Todo Layout")); 1891 mTodoList->saveLayout(config,QString("Todo Layout"));
1892 mDialogManager->writeSettings( config ); 1892 mDialogManager->writeSettings( config );
1893 //KOPrefs::instance()->usrWriteConfig(); 1893 //KOPrefs::instance()->usrWriteConfig();
1894 KOPrefs::instance()->writeConfig(); 1894 KOPrefs::instance()->writeConfig();
1895 1895
1896 writeFilterSettings(config); 1896 writeFilterSettings(config);
1897 1897
1898 config->setGroup( "Views" ); 1898 config->setGroup( "Views" );
1899 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1899 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1900 1900
1901#ifdef DESKTOP_VERSION 1901#ifdef DESKTOP_VERSION
1902 config->setGroup("WidgetLayout"); 1902 config->setGroup("WidgetLayout");
1903 QStringList list ;//= config->readListEntry("MainLayout"); 1903 QStringList list ;//= config->readListEntry("MainLayout");
1904 int x,y,w,h; 1904 int x,y,w,h;
1905 QWidget* wid; 1905 QWidget* wid;
1906 wid = topLevelWidget(); 1906 wid = topLevelWidget();
1907 x = wid->geometry().x(); 1907 x = wid->geometry().x();
1908 y = wid->geometry().y(); 1908 y = wid->geometry().y();
1909 w = wid->width(); 1909 w = wid->width();
1910 h = wid->height(); 1910 h = wid->height();
1911 list.clear(); 1911 list.clear();
1912 list << QString::number( x ); 1912 list << QString::number( x );
1913 list << QString::number( y ); 1913 list << QString::number( y );
1914 list << QString::number( w ); 1914 list << QString::number( w );
1915 list << QString::number( h ); 1915 list << QString::number( h );
1916 config->writeEntry("MainLayout",list ); 1916 config->writeEntry("MainLayout",list );
1917 1917
1918 wid = mEventEditor; 1918 wid = mEventEditor;
1919 x = wid->geometry().x(); 1919 x = wid->geometry().x();
1920 y = wid->geometry().y(); 1920 y = wid->geometry().y();
1921 w = wid->width(); 1921 w = wid->width();
1922 h = wid->height(); 1922 h = wid->height();
1923 list.clear(); 1923 list.clear();
1924 list << QString::number( x ); 1924 list << QString::number( x );
1925 list << QString::number( y ); 1925 list << QString::number( y );
1926 list << QString::number( w ); 1926 list << QString::number( w );
1927 list << QString::number( h ); 1927 list << QString::number( h );
1928 config->writeEntry("EditEventLayout",list ); 1928 config->writeEntry("EditEventLayout",list );
1929 1929
1930 wid = mTodoEditor; 1930 wid = mTodoEditor;
1931 x = wid->geometry().x(); 1931 x = wid->geometry().x();
1932 y = wid->geometry().y(); 1932 y = wid->geometry().y();
1933 w = wid->width(); 1933 w = wid->width();
1934 h = wid->height(); 1934 h = wid->height();
1935 list.clear(); 1935 list.clear();
1936 list << QString::number( x ); 1936 list << QString::number( x );
1937 list << QString::number( y ); 1937 list << QString::number( y );
1938 list << QString::number( w ); 1938 list << QString::number( w );
1939 list << QString::number( h ); 1939 list << QString::number( h );
1940 config->writeEntry("EditTodoLayout",list ); 1940 config->writeEntry("EditTodoLayout",list );
1941 wid = getEventViewerDialog(); 1941 wid = getEventViewerDialog();
1942 x = wid->geometry().x(); 1942 x = wid->geometry().x();
1943 y = wid->geometry().y(); 1943 y = wid->geometry().y();
1944 w = wid->width(); 1944 w = wid->width();
1945 h = wid->height(); 1945 h = wid->height();
1946 list.clear(); 1946 list.clear();
1947 list << QString::number( x ); 1947 list << QString::number( x );
1948 list << QString::number( y ); 1948 list << QString::number( y );
1949 list << QString::number( w ); 1949 list << QString::number( w );
1950 list << QString::number( h ); 1950 list << QString::number( h );
1951 config->writeEntry("ViewerLayout",list ); 1951 config->writeEntry("ViewerLayout",list );
1952 wid = mDialogManager->getSearchDialog(); 1952 wid = mDialogManager->getSearchDialog();
1953 if ( wid ) { 1953 if ( wid ) {
1954 x = wid->geometry().x(); 1954 x = wid->geometry().x();
1955 y = wid->geometry().y(); 1955 y = wid->geometry().y();
1956 w = wid->width(); 1956 w = wid->width();
1957 h = wid->height(); 1957 h = wid->height();
1958 list.clear(); 1958 list.clear();
1959 list << QString::number( x ); 1959 list << QString::number( x );
1960 list << QString::number( y ); 1960 list << QString::number( y );
1961 list << QString::number( w ); 1961 list << QString::number( w );
1962 list << QString::number( h ); 1962 list << QString::number( h );
1963 config->writeEntry("SearchLayout",list ); 1963 config->writeEntry("SearchLayout",list );
1964 } 1964 }
1965#endif 1965#endif
1966 1966
1967 1967
1968 config->sync(); 1968 config->sync();
1969} 1969}
1970 1970
1971void CalendarView::readFilterSettings(KConfig *config) 1971void CalendarView::readFilterSettings(KConfig *config)
1972{ 1972{
1973 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1973 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1974 1974
1975 mFilters.clear(); 1975 mFilters.clear();
1976 1976
1977 config->setGroup("General"); 1977 config->setGroup("General");
1978 QStringList filterList = config->readListEntry("CalendarFilters"); 1978 QStringList filterList = config->readListEntry("CalendarFilters");
1979 1979
1980 QStringList::ConstIterator it = filterList.begin(); 1980 QStringList::ConstIterator it = filterList.begin();
1981 QStringList::ConstIterator end = filterList.end(); 1981 QStringList::ConstIterator end = filterList.end();
1982 while(it != end) { 1982 while(it != end) {
1983 // kdDebug() << " filter: " << (*it) << endl; 1983 // kdDebug() << " filter: " << (*it) << endl;
1984 1984
1985 CalFilter *filter; 1985 CalFilter *filter;
1986 filter = new CalFilter(*it); 1986 filter = new CalFilter(*it);
1987 config->setGroup("Filter_" + (*it)); 1987 config->setGroup("Filter_" + (*it));
1988 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1988 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1989 filter->setCriteria(config->readNumEntry("Criteria",0)); 1989 filter->setCriteria(config->readNumEntry("Criteria",0));
1990 filter->setCategoryList(config->readListEntry("CategoryList")); 1990 filter->setCategoryList(config->readListEntry("CategoryList"));
1991 mFilters.append(filter); 1991 mFilters.append(filter);
1992 1992
1993 ++it; 1993 ++it;
1994 } 1994 }
1995 1995
1996 if (mFilters.count() == 0) { 1996 if (mFilters.count() == 0) {
1997 CalFilter *filter = new CalFilter(i18n("Default")); 1997 CalFilter *filter = new CalFilter(i18n("Default"));
1998 mFilters.append(filter); 1998 mFilters.append(filter);
1999 } 1999 }
2000 mFilterView->updateFilters(); 2000 mFilterView->updateFilters();
2001 config->setGroup("FilterView"); 2001 config->setGroup("FilterView");
2002 2002
2003 mFilterView->blockSignals(true); 2003 mFilterView->blockSignals(true);
2004 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2004 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2005 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2005 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2006 mFilterView->blockSignals(false); 2006 mFilterView->blockSignals(false);
2007 // We do it manually to avoid it being done twice by the above calls 2007 // We do it manually to avoid it being done twice by the above calls
2008 updateFilter(); 2008 updateFilter();
2009} 2009}
2010 2010
2011void CalendarView::writeFilterSettings(KConfig *config) 2011void CalendarView::writeFilterSettings(KConfig *config)
2012{ 2012{
2013 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2013 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2014 2014
2015 QStringList filterList; 2015 QStringList filterList;
2016 2016
2017 CalFilter *filter = mFilters.first(); 2017 CalFilter *filter = mFilters.first();
2018 while(filter) { 2018 while(filter) {
2019 // kdDebug() << " fn: " << filter->name() << endl; 2019 // kdDebug() << " fn: " << filter->name() << endl;
2020 filterList << filter->name(); 2020 filterList << filter->name();
2021 config->setGroup("Filter_" + filter->name()); 2021 config->setGroup("Filter_" + filter->name());
2022 config->writeEntry("Criteria",filter->criteria()); 2022 config->writeEntry("Criteria",filter->criteria());
2023 config->writeEntry("CategoryList",filter->categoryList()); 2023 config->writeEntry("CategoryList",filter->categoryList());
2024 filter = mFilters.next(); 2024 filter = mFilters.next();
2025 } 2025 }
2026 config->setGroup("General"); 2026 config->setGroup("General");
2027 config->writeEntry("CalendarFilters",filterList); 2027 config->writeEntry("CalendarFilters",filterList);
2028 2028
2029 config->setGroup("FilterView"); 2029 config->setGroup("FilterView");
2030 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2030 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2031 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2031 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2032} 2032}
2033 2033
2034 2034
2035void CalendarView::goToday() 2035void CalendarView::goToday()
2036{ 2036{
2037 if ( mViewManager->currentView()->isMonthView() ) 2037 if ( mViewManager->currentView()->isMonthView() )
2038 mNavigator->selectTodayMonth(); 2038 mNavigator->selectTodayMonth();
2039 else 2039 else
2040 mNavigator->selectToday(); 2040 mNavigator->selectToday();
2041} 2041}
2042 2042
2043void CalendarView::goNext() 2043void CalendarView::goNext()
2044{ 2044{
2045 mNavigator->selectNext(); 2045 mNavigator->selectNext();
2046} 2046}
2047 2047
2048void CalendarView::goPrevious() 2048void CalendarView::goPrevious()
2049{ 2049{
2050 mNavigator->selectPrevious(); 2050 mNavigator->selectPrevious();
2051} 2051}
2052void CalendarView::goNextMonth() 2052void CalendarView::goNextMonth()
2053{ 2053{
2054 mNavigator->selectNextMonth(); 2054 mNavigator->selectNextMonth();
2055} 2055}
2056 2056
2057void CalendarView::goPreviousMonth() 2057void CalendarView::goPreviousMonth()
2058{ 2058{
2059 mNavigator->selectPreviousMonth(); 2059 mNavigator->selectPreviousMonth();
2060} 2060}
2061void CalendarView::writeLocale() 2061void CalendarView::writeLocale()
2062{ 2062{
2063 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2063 //KPimGlobalPrefs::instance()->setGlobalConfig();
2064#if 0 2064#if 0
2065 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2065 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2066 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2066 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2067 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2067 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2068 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2068 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2069 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2069 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2070 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2070 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2071 dummy = KOPrefs::instance()->mUserDateFormatShort; 2071 dummy = KOPrefs::instance()->mUserDateFormatShort;
2072 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2072 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2073 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2073 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2074 KOPrefs::instance()->mDaylightsavingStart, 2074 KOPrefs::instance()->mDaylightsavingStart,
2075 KOPrefs::instance()->mDaylightsavingEnd ); 2075 KOPrefs::instance()->mDaylightsavingEnd );
2076 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2076 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2077#endif 2077#endif
2078} 2078}
2079void CalendarView::updateConfig() 2079void CalendarView::updateConfig()
2080{ 2080{
2081 writeLocale(); 2081 writeLocale();
2082 if ( KOPrefs::instance()->mUseAppColors ) 2082 if ( KOPrefs::instance()->mUseAppColors )
2083 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2083 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2084 emit configChanged(); 2084 emit configChanged();
2085 mTodoList->updateConfig(); 2085 mTodoList->updateConfig();
2086 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2086 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2087 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2087 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2088 // To make the "fill window" configurations work 2088 // To make the "fill window" configurations work
2089 //mViewManager->raiseCurrentView(); 2089 //mViewManager->raiseCurrentView();
2090} 2090}
2091 2091
2092 2092
2093void CalendarView::eventChanged(Event *event) 2093void CalendarView::eventChanged(Event *event)
2094{ 2094{
2095 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2095 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2096 //updateUnmanagedViews(); 2096 //updateUnmanagedViews();
2097} 2097}
2098 2098
2099void CalendarView::eventAdded(Event *event) 2099void CalendarView::eventAdded(Event *event)
2100{ 2100{
2101 changeEventDisplay(event,KOGlobals::EVENTADDED); 2101 changeEventDisplay(event,KOGlobals::EVENTADDED);
2102} 2102}
2103 2103
2104void CalendarView::eventToBeDeleted(Event *) 2104void CalendarView::eventToBeDeleted(Event *)
2105{ 2105{
2106 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2106 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2107} 2107}
2108 2108
2109void CalendarView::eventDeleted() 2109void CalendarView::eventDeleted()
2110{ 2110{
2111 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2111 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2112} 2112}
2113void CalendarView::changeTodoDisplay(Todo *which, int action) 2113void CalendarView::changeTodoDisplay(Todo *which, int action)
2114{ 2114{
2115 changeIncidenceDisplay((Incidence *)which, action); 2115 changeIncidenceDisplay((Incidence *)which, action);
2116 mDateNavigator->updateView(); //LR 2116 mDateNavigator->updateView(); //LR
2117 //mDialogManager->updateSearchDialog(); 2117 //mDialogManager->updateSearchDialog();
2118 2118
2119 if (which) { 2119 if (which) {
2120 mViewManager->updateWNview(); 2120 mViewManager->updateWNview();
2121 //mTodoList->updateView(); 2121 //mTodoList->updateView();
2122 } 2122 }
2123 2123
2124} 2124}
2125 2125
2126void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2126void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2127{ 2127{
2128 updateUnmanagedViews(); 2128 updateUnmanagedViews();
2129 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2129 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2130 if ( action == KOGlobals::EVENTDELETED ) { //delete 2130 if ( action == KOGlobals::EVENTDELETED ) { //delete
2131 mCalendar->checkAlarmForIncidence( 0, true ); 2131 mCalendar->checkAlarmForIncidence( 0, true );
2132 if ( mEventViewerDialog ) 2132 if ( mEventViewerDialog )
2133 mEventViewerDialog->hide(); 2133 mEventViewerDialog->hide();
2134 } 2134 }
2135 else 2135 else
2136 mCalendar->checkAlarmForIncidence( which , false ); 2136 mCalendar->checkAlarmForIncidence( which , false );
2137} 2137}
2138 2138
2139// most of the changeEventDisplays() right now just call the view's 2139// most of the changeEventDisplays() right now just call the view's
2140// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2140// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2141void CalendarView::changeEventDisplay(Event *which, int action) 2141void CalendarView::changeEventDisplay(Event *which, int action)
2142{ 2142{
2143 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2143 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2144 changeIncidenceDisplay((Incidence *)which, action); 2144 changeIncidenceDisplay((Incidence *)which, action);
2145 mDateNavigator->updateView(); 2145 mDateNavigator->updateView();
2146 //mDialogManager->updateSearchDialog(); 2146 //mDialogManager->updateSearchDialog();
2147 2147
2148 if (which) { 2148 if (which) {
2149 // If there is an event view visible update the display 2149 // If there is an event view visible update the display
2150 mViewManager->currentView()->changeEventDisplay(which,action); 2150 mViewManager->currentView()->changeEventDisplay(which,action);
2151 // TODO: check, if update needed 2151 // TODO: check, if update needed
2152 // if (which->getTodoStatus()) { 2152 // if (which->getTodoStatus()) {
2153 mTodoList->updateView(); 2153 mTodoList->updateView();
2154 // } 2154 // }
2155 } else { 2155 } else {
2156 mViewManager->currentView()->updateView(); 2156 mViewManager->currentView()->updateView();
2157 } 2157 }
2158} 2158}
2159 2159
2160 2160
2161void CalendarView::updateTodoViews() 2161void CalendarView::updateTodoViews()
2162{ 2162{
2163 2163
2164 mTodoList->updateView(); 2164 mTodoList->updateView();
2165 mViewManager->currentView()->updateView(); 2165 mViewManager->currentView()->updateView();
2166 2166
2167} 2167}
2168 2168
2169 2169
2170void CalendarView::updateView(const QDate &start, const QDate &end) 2170void CalendarView::updateView(const QDate &start, const QDate &end)
2171{ 2171{
2172 mTodoList->updateView(); 2172 mTodoList->updateView();
2173 mViewManager->updateView(start, end); 2173 mViewManager->updateView(start, end);
2174 //mDateNavigator->updateView(); 2174 //mDateNavigator->updateView();
2175} 2175}
2176 2176
2177void CalendarView::updateView() 2177void CalendarView::updateView()
2178{ 2178{
2179 DateList tmpList = mNavigator->selectedDates(); 2179 DateList tmpList = mNavigator->selectedDates();
2180 2180
2181 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2181 if ( KOPrefs::instance()->mHideNonStartedTodos )
2182 mTodoList->updateView(); 2182 mTodoList->updateView();
2183 // We assume that the navigator only selects consecutive days. 2183 // We assume that the navigator only selects consecutive days.
2184 updateView( tmpList.first(), tmpList.last() ); 2184 updateView( tmpList.first(), tmpList.last() );
2185} 2185}
2186 2186
2187void CalendarView::updateUnmanagedViews() 2187void CalendarView::updateUnmanagedViews()
2188{ 2188{
2189 mDateNavigator->updateDayMatrix(); 2189 mDateNavigator->updateDayMatrix();
2190} 2190}
2191 2191
2192int CalendarView::msgItemDelete(const QString name) 2192int CalendarView::msgItemDelete(const QString name)
2193{ 2193{
2194 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2194 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2195 i18n("This item will be\npermanently deleted."), 2195 i18n("This item will be\npermanently deleted."),
2196 i18n("KO/Pi Confirmation"),i18n("Delete")); 2196 i18n("KO/Pi Confirmation"),i18n("Delete"));
2197} 2197}
2198 2198
2199 2199
2200void CalendarView::edit_cut() 2200void CalendarView::edit_cut()
2201{ 2201{
2202 Event *anEvent=0; 2202 Event *anEvent=0;
2203 2203
2204 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2204 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2205 2205
2206 if (mViewManager->currentView()->isEventView()) { 2206 if (mViewManager->currentView()->isEventView()) {
2207 if ( incidence && incidence->type() == "Event" ) { 2207 if ( incidence && incidence->type() == "Event" ) {
2208 anEvent = static_cast<Event *>(incidence); 2208 anEvent = static_cast<Event *>(incidence);
2209 } 2209 }
2210 } 2210 }
2211 2211
2212 if (!anEvent) { 2212 if (!anEvent) {
2213 KNotifyClient::beep(); 2213 KNotifyClient::beep();
2214 return; 2214 return;
2215 } 2215 }
2216 DndFactory factory( mCalendar ); 2216 DndFactory factory( mCalendar );
2217 factory.cutEvent(anEvent); 2217 factory.cutIncidence(anEvent);
2218 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2218 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2219} 2219}
2220 2220
2221void CalendarView::edit_copy() 2221void CalendarView::edit_copy()
2222{ 2222{
2223 Event *anEvent=0; 2223 Event *anEvent=0;
2224 2224
2225 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2225 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2226 2226
2227 if (mViewManager->currentView()->isEventView()) { 2227 if (mViewManager->currentView()->isEventView()) {
2228 if ( incidence && incidence->type() == "Event" ) { 2228 if ( incidence && incidence->type() == "Event" ) {
2229 anEvent = static_cast<Event *>(incidence); 2229 anEvent = static_cast<Event *>(incidence);
2230 } 2230 }
2231 } 2231 }
2232 2232
2233 if (!anEvent) { 2233 if (!anEvent) {
2234 KNotifyClient::beep(); 2234 KNotifyClient::beep();
2235 return; 2235 return;
2236 } 2236 }
2237 DndFactory factory( mCalendar ); 2237 DndFactory factory( mCalendar );
2238 factory.copyEvent(anEvent); 2238 factory.copyIncidence(anEvent);
2239} 2239}
2240 2240
2241void CalendarView::edit_paste() 2241void CalendarView::edit_paste()
2242{ 2242{
2243 QDate date = mNavigator->selectedDates().first(); 2243 QDate date = mNavigator->selectedDates().first();
2244 2244
2245 DndFactory factory( mCalendar ); 2245 DndFactory factory( mCalendar );
2246 Event *pastedEvent = factory.pasteEvent( date ); 2246 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2247 2247
2248 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2248 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2249} 2249}
2250 2250
2251void CalendarView::edit_options() 2251void CalendarView::edit_options()
2252{ 2252{
2253 mDialogManager->showOptionsDialog(); 2253 mDialogManager->showOptionsDialog();
2254 //writeSettings(); 2254 //writeSettings();
2255} 2255}
2256 2256
2257 2257
2258void CalendarView::slotSelectPickerDate( QDate d) 2258void CalendarView::slotSelectPickerDate( QDate d)
2259{ 2259{
2260 mDateFrame->hide(); 2260 mDateFrame->hide();
2261 if ( mDatePickerMode == 1 ) { 2261 if ( mDatePickerMode == 1 ) {
2262 mNavigator->slotDaySelect( d ); 2262 mNavigator->slotDaySelect( d );
2263 } else if ( mDatePickerMode == 2 ) { 2263 } else if ( mDatePickerMode == 2 ) {
2264 if ( mMoveIncidence->type() == "Todo" ) { 2264 if ( mMoveIncidence->type() == "Todo" ) {
2265 Todo * to = (Todo *) mMoveIncidence; 2265 Todo * to = (Todo *) mMoveIncidence;
2266 QTime tim; 2266 QTime tim;
2267 if ( to->hasDueDate() ) 2267 if ( to->hasDueDate() )
2268 tim = to->dtDue().time(); 2268 tim = to->dtDue().time();
2269 else { 2269 else {
2270 tim = QTime ( 0,0,0 ); 2270 tim = QTime ( 0,0,0 );
2271 to->setFloats( true ); 2271 to->setFloats( true );
2272 to->setHasDueDate( true ); 2272 to->setHasDueDate( true );
2273 } 2273 }
2274 QDateTime dt ( d,tim ); 2274 QDateTime dt ( d,tim );
2275 to->setDtDue( dt ); 2275 to->setDtDue( dt );
2276 todoChanged( to ); 2276 todoChanged( to );
2277 } else { 2277 } else {
2278 if ( mMoveIncidence->doesRecur() ) { 2278 if ( mMoveIncidence->doesRecur() ) {
2279#if 0 2279#if 0
2280 // PENDING implement this 2280 // PENDING implement this
2281 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2281 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2282 mCalendar()->addIncidence( newInc ); 2282 mCalendar()->addIncidence( newInc );
2283 if ( mMoveIncidence->type() == "Todo" ) 2283 if ( mMoveIncidence->type() == "Todo" )
2284 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2284 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2285 else 2285 else
2286 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2286 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2287 mMoveIncidence = newInc; 2287 mMoveIncidence = newInc;
2288 2288
2289#endif 2289#endif
2290 } 2290 }
2291 QTime tim = mMoveIncidence->dtStart().time(); 2291 QTime tim = mMoveIncidence->dtStart().time();
2292 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2292 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2293 QDateTime dt ( d,tim ); 2293 QDateTime dt ( d,tim );
2294 mMoveIncidence->setDtStart( dt ); 2294 mMoveIncidence->setDtStart( dt );
2295 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2295 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2296 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2296 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2297 } 2297 }
2298 2298
2299 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2299 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2300 } 2300 }
2301} 2301}
2302 2302
2303void CalendarView::removeCategories() 2303void CalendarView::removeCategories()
2304{ 2304{
2305 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2305 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2306 QStringList catList = KOPrefs::instance()->mCustomCategories; 2306 QStringList catList = KOPrefs::instance()->mCustomCategories;
2307 QStringList catIncList; 2307 QStringList catIncList;
2308 QStringList newCatList; 2308 QStringList newCatList;
2309 Incidence* inc = incList.first(); 2309 Incidence* inc = incList.first();
2310 int i; 2310 int i;
2311 int count = 0; 2311 int count = 0;
2312 while ( inc ) { 2312 while ( inc ) {
2313 newCatList.clear(); 2313 newCatList.clear();
2314 catIncList = inc->categories() ; 2314 catIncList = inc->categories() ;
2315 for( i = 0; i< catIncList.count(); ++i ) { 2315 for( i = 0; i< catIncList.count(); ++i ) {
2316 if ( catList.contains (catIncList[i])) 2316 if ( catList.contains (catIncList[i]))
2317 newCatList.append( catIncList[i] ); 2317 newCatList.append( catIncList[i] );
2318 } 2318 }
2319 newCatList.sort(); 2319 newCatList.sort();
2320 inc->setCategories( newCatList.join(",") ); 2320 inc->setCategories( newCatList.join(",") );
2321 inc = incList.next(); 2321 inc = incList.next();
2322 } 2322 }
2323} 2323}
2324 2324
2325int CalendarView::addCategories() 2325int CalendarView::addCategories()
2326{ 2326{
2327 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2327 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2328 QStringList catList = KOPrefs::instance()->mCustomCategories; 2328 QStringList catList = KOPrefs::instance()->mCustomCategories;
2329 QStringList catIncList; 2329 QStringList catIncList;
2330 Incidence* inc = incList.first(); 2330 Incidence* inc = incList.first();
2331 int i; 2331 int i;
2332 int count = 0; 2332 int count = 0;
2333 while ( inc ) { 2333 while ( inc ) {
2334 catIncList = inc->categories() ; 2334 catIncList = inc->categories() ;
2335 for( i = 0; i< catIncList.count(); ++i ) { 2335 for( i = 0; i< catIncList.count(); ++i ) {
2336 if ( !catList.contains (catIncList[i])) { 2336 if ( !catList.contains (catIncList[i])) {
2337 catList.append( catIncList[i] ); 2337 catList.append( catIncList[i] );
2338 //qDebug("add cat %s ", catIncList[i].latin1()); 2338 //qDebug("add cat %s ", catIncList[i].latin1());
2339 ++count; 2339 ++count;
2340 } 2340 }
2341 } 2341 }
2342 inc = incList.next(); 2342 inc = incList.next();
2343 } 2343 }
2344 catList.sort(); 2344 catList.sort();
2345 KOPrefs::instance()->mCustomCategories = catList; 2345 KOPrefs::instance()->mCustomCategories = catList;
2346 return count; 2346 return count;
2347} 2347}
2348 2348
2349void CalendarView::manageCategories() 2349void CalendarView::manageCategories()
2350{ 2350{
2351 KOCatPrefs* cp = new KOCatPrefs(); 2351 KOCatPrefs* cp = new KOCatPrefs();
2352 cp->show(); 2352 cp->show();
2353 int w =cp->sizeHint().width() ; 2353 int w =cp->sizeHint().width() ;
2354 int h = cp->sizeHint().height() ; 2354 int h = cp->sizeHint().height() ;
2355 int dw = QApplication::desktop()->width(); 2355 int dw = QApplication::desktop()->width();
2356 int dh = QApplication::desktop()->height(); 2356 int dh = QApplication::desktop()->height();
2357 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2357 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2358 if ( !cp->exec() ) { 2358 if ( !cp->exec() ) {
2359 delete cp; 2359 delete cp;
2360 return; 2360 return;
2361 } 2361 }
2362 int count = 0; 2362 int count = 0;
2363 if ( cp->addCat() ) { 2363 if ( cp->addCat() ) {
2364 count = addCategories(); 2364 count = addCategories();
2365 if ( count ) { 2365 if ( count ) {
2366 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2366 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2367 writeSettings(); 2367 writeSettings();
2368 } else 2368 } else
2369 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2369 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2370 } else { 2370 } else {
2371 removeCategories(); 2371 removeCategories();
2372 updateView(); 2372 updateView();
2373 } 2373 }
2374 delete cp; 2374 delete cp;
2375} 2375}
2376 2376
2377void CalendarView::beamIncidence(Incidence * Inc) 2377void CalendarView::beamIncidence(Incidence * Inc)
2378{ 2378{
2379 QPtrList<Incidence> delSel ; 2379 QPtrList<Incidence> delSel ;
2380 delSel.append(Inc); 2380 delSel.append(Inc);
2381 beamIncidenceList( delSel ); 2381 beamIncidenceList( delSel );
2382} 2382}
2383void CalendarView::beamCalendar() 2383void CalendarView::beamCalendar()
2384{ 2384{
2385 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2385 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2386 //qDebug("beamCalendar() "); 2386 //qDebug("beamCalendar() ");
2387 beamIncidenceList( delSel ); 2387 beamIncidenceList( delSel );
2388} 2388}
2389void CalendarView::beamFilteredCalendar() 2389void CalendarView::beamFilteredCalendar()
2390{ 2390{
2391 QPtrList<Incidence> delSel = mCalendar->incidences(); 2391 QPtrList<Incidence> delSel = mCalendar->incidences();
2392 //qDebug("beamFilteredCalendar() "); 2392 //qDebug("beamFilteredCalendar() ");
2393 beamIncidenceList( delSel ); 2393 beamIncidenceList( delSel );
2394} 2394}
2395void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2395void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2396{ 2396{
2397 if ( beamDialog->exec () == QDialog::Rejected ) 2397 if ( beamDialog->exec () == QDialog::Rejected )
2398 return; 2398 return;
2399#ifdef DESKTOP_VERSION 2399#ifdef DESKTOP_VERSION
2400 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2400 QString fn = locateLocal( "tmp", "kopibeamfile" );
2401#else 2401#else
2402 QString fn = "/tmp/kopibeamfile"; 2402 QString fn = "/tmp/kopibeamfile";
2403#endif 2403#endif
2404 QString mes; 2404 QString mes;
2405 bool createbup = true; 2405 bool createbup = true;
2406 if ( createbup ) { 2406 if ( createbup ) {
2407 QString description = "\n"; 2407 QString description = "\n";
2408 CalendarLocal* cal = new CalendarLocal(); 2408 CalendarLocal* cal = new CalendarLocal();
2409 if ( beamDialog->beamLocal() ) 2409 if ( beamDialog->beamLocal() )
2410 cal->setLocalTime(); 2410 cal->setLocalTime();
2411 else 2411 else
2412 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2412 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2413 Incidence *incidence = delSel.first(); 2413 Incidence *incidence = delSel.first();
2414 bool addText = false; 2414 bool addText = false;
2415 if ( delSel.count() < 10 ) 2415 if ( delSel.count() < 10 )
2416 addText = true; 2416 addText = true;
2417 else { 2417 else {
2418 description.sprintf(i18n(" %d items?"),delSel.count() ); 2418 description.sprintf(i18n(" %d items?"),delSel.count() );
2419 } 2419 }
2420 while ( incidence ) { 2420 while ( incidence ) {
2421 Incidence *in = incidence->clone(); 2421 Incidence *in = incidence->clone();
2422 if ( ! in->summary().isEmpty() ) { 2422 if ( ! in->summary().isEmpty() ) {
2423 in->setDescription(""); 2423 in->setDescription("");
2424 } else { 2424 } else {
2425 in->setSummary( in->description().left(20)); 2425 in->setSummary( in->description().left(20));
2426 in->setDescription(""); 2426 in->setDescription("");
2427 } 2427 }
2428 if ( addText ) 2428 if ( addText )
2429 description += in->summary() + "\n"; 2429 description += in->summary() + "\n";
2430 cal->addIncidence( in ); 2430 cal->addIncidence( in );
2431 incidence = delSel.next(); 2431 incidence = delSel.next();
2432 } 2432 }
2433 if ( beamDialog->beamVcal() ) { 2433 if ( beamDialog->beamVcal() ) {
2434 fn += ".vcs"; 2434 fn += ".vcs";
2435 FileStorage storage( cal, fn, new VCalFormat ); 2435 FileStorage storage( cal, fn, new VCalFormat );
2436 storage.save(); 2436 storage.save();
2437 } else { 2437 } else {
2438 fn += ".ics"; 2438 fn += ".ics";
2439 FileStorage storage( cal, fn, new ICalFormat( ) ); 2439 FileStorage storage( cal, fn, new ICalFormat( ) );
2440 storage.save(); 2440 storage.save();
2441 } 2441 }
2442 delete cal; 2442 delete cal;
2443 mes = i18n("KO/Pi: Ready for beaming"); 2443 mes = i18n("KO/Pi: Ready for beaming");
2444 topLevelWidget()->setCaption(mes); 2444 topLevelWidget()->setCaption(mes);
2445 KApplication::convert2latin1( fn ); 2445 KApplication::convert2latin1( fn );
2446#ifndef DESKTOP_VERSION 2446#ifndef DESKTOP_VERSION
2447 Ir *ir = new Ir( this ); 2447 Ir *ir = new Ir( this );
2448 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2448 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2449 ir->send( fn, description, "text/x-vCalendar" ); 2449 ir->send( fn, description, "text/x-vCalendar" );
2450#endif 2450#endif
2451 } 2451 }
2452} 2452}
2453void CalendarView::beamDone( Ir *ir ) 2453void CalendarView::beamDone( Ir *ir )
2454{ 2454{
2455#ifndef DESKTOP_VERSION 2455#ifndef DESKTOP_VERSION
2456 delete ir; 2456 delete ir;
2457#endif 2457#endif
2458 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2458 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2459 topLevelWidget()->raise(); 2459 topLevelWidget()->raise();
2460} 2460}
2461 2461
2462void CalendarView::moveIncidence(Incidence * inc ) 2462void CalendarView::moveIncidence(Incidence * inc )
2463{ 2463{
2464 if ( !inc ) return; 2464 if ( !inc ) return;
2465 // qDebug("showDatePickerForIncidence( ) "); 2465 // qDebug("showDatePickerForIncidence( ) ");
2466 if ( mDateFrame->isVisible() ) 2466 if ( mDateFrame->isVisible() )
2467 mDateFrame->hide(); 2467 mDateFrame->hide();
2468 else { 2468 else {
2469 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ; 2469 int w =mDatePicker->sizeHint().width()+2*mDateFrame->lineWidth() ;
2470 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ; 2470 int h = mDatePicker->sizeHint().height()+2*mDateFrame->lineWidth() ;
2471 int dw = QApplication::desktop()->width(); 2471 int dw = QApplication::desktop()->width();
2472 int dh = QApplication::desktop()->height(); 2472 int dh = QApplication::desktop()->height();
2473 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2473 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2474 mDateFrame->show(); 2474 mDateFrame->show();
2475 } 2475 }
2476 mDatePickerMode = 2; 2476 mDatePickerMode = 2;
2477 mMoveIncidence = inc ; 2477 mMoveIncidence = inc ;
2478 QDate da; 2478 QDate da;
2479 if ( mMoveIncidence->type() == "Todo" ) { 2479 if ( mMoveIncidence->type() == "Todo" ) {
2480 Todo * to = (Todo *) mMoveIncidence; 2480 Todo * to = (Todo *) mMoveIncidence;
2481 if ( to->hasDueDate() ) 2481 if ( to->hasDueDate() )
2482 da = to->dtDue().date(); 2482 da = to->dtDue().date();
2483 else 2483 else
2484 da = QDate::currentDate(); 2484 da = QDate::currentDate();
2485 } else { 2485 } else {
2486 da = mMoveIncidence->dtStart().date(); 2486 da = mMoveIncidence->dtStart().date();
2487 } 2487 }
2488 //PENDING set date for recurring incidence to date of recurrence 2488 //PENDING set date for recurring incidence to date of recurrence
2489 //mMoveIncidenceOldDate; 2489 //mMoveIncidenceOldDate;
2490 mDatePicker->setDate( da ); 2490 mDatePicker->setDate( da );
2491} 2491}
2492void CalendarView::showDatePicker( ) 2492void CalendarView::showDatePicker( )
2493{ 2493{
2494 //qDebug("CalendarView::showDatePicker( ) "); 2494 //qDebug("CalendarView::showDatePicker( ) ");
2495 if ( mDateFrame->isVisible() ) 2495 if ( mDateFrame->isVisible() )
2496 mDateFrame->hide(); 2496 mDateFrame->hide();
2497 else { 2497 else {
2498 int w =mDatePicker->sizeHint().width() ; 2498 int w =mDatePicker->sizeHint().width() ;
2499 int h = mDatePicker->sizeHint().height() ; 2499 int h = mDatePicker->sizeHint().height() ;
2500 int dw = QApplication::desktop()->width(); 2500 int dw = QApplication::desktop()->width();
2501 int dh = QApplication::desktop()->height(); 2501 int dh = QApplication::desktop()->height();
2502 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2502 mDateFrame->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2503 mDateFrame->show(); 2503 mDateFrame->show();
2504 } 2504 }
2505 mDatePickerMode = 1; 2505 mDatePickerMode = 1;
2506 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2506 mDatePicker->setDate( mNavigator->selectedDates().first() );
2507} 2507}
2508 2508
2509void CalendarView::showEventEditor() 2509void CalendarView::showEventEditor()
2510{ 2510{
2511#ifdef DESKTOP_VERSION 2511#ifdef DESKTOP_VERSION
2512 mEventEditor->show(); 2512 mEventEditor->show();
2513#else 2513#else
2514 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2514 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2515 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2515 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2516 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2516 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2517 qApp->processEvents(); 2517 qApp->processEvents();
2518 delete mEventEditor; 2518 delete mEventEditor;
2519 mEventEditor = mDialogManager->getEventEditor(); 2519 mEventEditor = mDialogManager->getEventEditor();
2520 topLevelWidget()->setCaption( i18n("") ); 2520 topLevelWidget()->setCaption( i18n("") );
2521 } 2521 }
2522 mEventEditor->showMaximized(); 2522 mEventEditor->showMaximized();
2523#endif 2523#endif
2524} 2524}
2525void CalendarView::showTodoEditor() 2525void CalendarView::showTodoEditor()
2526{ 2526{
2527#ifdef DESKTOP_VERSION 2527#ifdef DESKTOP_VERSION
2528 mTodoEditor->show(); 2528 mTodoEditor->show();
2529#else 2529#else
2530 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 2530 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
2531 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2531 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2532 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 2532 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
2533 qApp->processEvents(); 2533 qApp->processEvents();
2534 delete mTodoEditor; 2534 delete mTodoEditor;
2535 mTodoEditor = mDialogManager->getTodoEditor(); 2535 mTodoEditor = mDialogManager->getTodoEditor();
2536 topLevelWidget()->setCaption( i18n("") ); 2536 topLevelWidget()->setCaption( i18n("") );
2537 } 2537 }
2538 mTodoEditor->showMaximized(); 2538 mTodoEditor->showMaximized();
2539#endif 2539#endif
2540} 2540}
2541 2541
2542void CalendarView::cloneIncidence() 2542void CalendarView::cloneIncidence()
2543{ 2543{
2544 Incidence *incidence = currentSelection(); 2544 Incidence *incidence = currentSelection();
2545 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2545 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2546 if ( incidence ) { 2546 if ( incidence ) {
2547 cloneIncidence(incidence); 2547 cloneIncidence(incidence);
2548 } 2548 }
2549} 2549}
2550void CalendarView::moveIncidence() 2550void CalendarView::moveIncidence()
2551{ 2551{
2552 Incidence *incidence = currentSelection(); 2552 Incidence *incidence = currentSelection();
2553 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2553 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2554 if ( incidence ) { 2554 if ( incidence ) {
2555 moveIncidence(incidence); 2555 moveIncidence(incidence);
2556 } 2556 }
2557} 2557}
2558void CalendarView::beamIncidence() 2558void CalendarView::beamIncidence()
2559{ 2559{
2560 Incidence *incidence = currentSelection(); 2560 Incidence *incidence = currentSelection();
2561 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2561 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2562 if ( incidence ) { 2562 if ( incidence ) {
2563 beamIncidence(incidence); 2563 beamIncidence(incidence);
2564 } 2564 }
2565} 2565}
2566void CalendarView::toggleCancelIncidence() 2566void CalendarView::toggleCancelIncidence()
2567{ 2567{
2568 Incidence *incidence = currentSelection(); 2568 Incidence *incidence = currentSelection();
2569 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2569 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2570 if ( incidence ) { 2570 if ( incidence ) {
2571 cancelIncidence(incidence); 2571 cancelIncidence(incidence);
2572 } 2572 }
2573} 2573}
2574 2574
2575 2575
2576void CalendarView::cancelIncidence(Incidence * inc ) 2576void CalendarView::cancelIncidence(Incidence * inc )
2577{ 2577{
2578 inc->setCancelled( ! inc->cancelled() ); 2578 inc->setCancelled( ! inc->cancelled() );
2579 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2579 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2580 updateView(); 2580 updateView();
2581} 2581}
2582void CalendarView::cloneIncidence(Incidence * orgInc ) 2582void CalendarView::cloneIncidence(Incidence * orgInc )
2583{ 2583{
2584 Incidence * newInc = orgInc->clone(); 2584 Incidence * newInc = orgInc->clone();
2585 newInc->recreate(); 2585 newInc->recreate();
2586 2586
2587 if ( newInc->type() == "Todo" ) { 2587 if ( newInc->type() == "Todo" ) {
2588 Todo* t = (Todo*) newInc; 2588 Todo* t = (Todo*) newInc;
2589 showTodoEditor(); 2589 showTodoEditor();
2590 mTodoEditor->editTodo( t ); 2590 mTodoEditor->editTodo( t );
2591 if ( mTodoEditor->exec() ) { 2591 if ( mTodoEditor->exec() ) {
2592 mCalendar->addTodo( t ); 2592 mCalendar->addTodo( t );
2593 updateView(); 2593 updateView();
2594 } else { 2594 } else {
2595 delete t; 2595 delete t;
2596 } 2596 }
2597 } 2597 }
2598 else { 2598 else {
2599 Event* e = (Event*) newInc; 2599 Event* e = (Event*) newInc;
2600 showEventEditor(); 2600 showEventEditor();
2601 mEventEditor->editEvent( e ); 2601 mEventEditor->editEvent( e );
2602 if ( mEventEditor->exec() ) { 2602 if ( mEventEditor->exec() ) {
2603 mCalendar->addEvent( e ); 2603 mCalendar->addEvent( e );
2604 updateView(); 2604 updateView();
2605 } else { 2605 } else {
2606 delete e; 2606 delete e;
2607 } 2607 }
2608 } 2608 }
2609} 2609}
2610 2610
2611void CalendarView::newEvent() 2611void CalendarView::newEvent()
2612{ 2612{
2613 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2613 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2614 KOAgendaView *aView = mViewManager->agendaView(); 2614 KOAgendaView *aView = mViewManager->agendaView();
2615 if (aView) { 2615 if (aView) {
2616 if (aView->selectionStart().isValid()) { 2616 if (aView->selectionStart().isValid()) {
2617 if (aView->selectedIsAllDay()) { 2617 if (aView->selectedIsAllDay()) {
2618 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2618 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2619 } else { 2619 } else {
2620 newEvent(aView->selectionStart(),aView->selectionEnd()); 2620 newEvent(aView->selectionStart(),aView->selectionEnd());
2621 } 2621 }
2622 return; 2622 return;
2623 } 2623 }
2624 } 2624 }
2625 2625
2626 QDate date = mNavigator->selectedDates().first(); 2626 QDate date = mNavigator->selectedDates().first();
2627 QDateTime current = QDateTime::currentDateTime(); 2627 QDateTime current = QDateTime::currentDateTime();
2628 if ( date <= current.date() ) { 2628 if ( date <= current.date() ) {
2629 int hour = current.time().hour() +1; 2629 int hour = current.time().hour() +1;
2630 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2630 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2631 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2631 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2632 } else 2632 } else
2633 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2633 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2634 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2634 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2635 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2635 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2636} 2636}
2637 2637
2638void CalendarView::newEvent(QDateTime fh) 2638void CalendarView::newEvent(QDateTime fh)
2639{ 2639{
2640 newEvent(fh, 2640 newEvent(fh,
2641 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2641 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2642} 2642}
2643 2643
2644void CalendarView::newEvent(QDate dt) 2644void CalendarView::newEvent(QDate dt)
2645{ 2645{
2646 newEvent(QDateTime(dt, QTime(0,0,0)), 2646 newEvent(QDateTime(dt, QTime(0,0,0)),
2647 QDateTime(dt, QTime(0,0,0)), true); 2647 QDateTime(dt, QTime(0,0,0)), true);
2648} 2648}
2649void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 2649void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
2650{ 2650{
2651 newEvent(fromHint, toHint, false); 2651 newEvent(fromHint, toHint, false);
2652} 2652}
2653void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2653void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2654{ 2654{
2655 2655
2656 showEventEditor(); 2656 showEventEditor();
2657 mEventEditor->newEvent(fromHint,toHint,allDay); 2657 mEventEditor->newEvent(fromHint,toHint,allDay);
2658 if ( mFilterView->filtersEnabled() ) { 2658 if ( mFilterView->filtersEnabled() ) {
2659 CalFilter *filter = mFilterView->selectedFilter(); 2659 CalFilter *filter = mFilterView->selectedFilter();
2660 if (filter && filter->showCategories()) { 2660 if (filter && filter->showCategories()) {
2661 mEventEditor->setCategories(filter->categoryList().join(",") ); 2661 mEventEditor->setCategories(filter->categoryList().join(",") );
2662 } 2662 }
2663 if ( filter ) 2663 if ( filter )
2664 mEventEditor->setSecrecy( filter->getSecrecy() ); 2664 mEventEditor->setSecrecy( filter->getSecrecy() );
2665 } 2665 }
2666} 2666}
2667void CalendarView::todoAdded(Todo * t) 2667void CalendarView::todoAdded(Todo * t)
2668{ 2668{
2669 2669
2670 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2670 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2671 updateTodoViews(); 2671 updateTodoViews();
2672} 2672}
2673void CalendarView::todoChanged(Todo * t) 2673void CalendarView::todoChanged(Todo * t)
2674{ 2674{
2675 emit todoModified( t, 4 ); 2675 emit todoModified( t, 4 );
2676 // updateTodoViews(); 2676 // updateTodoViews();
2677} 2677}
2678void CalendarView::todoToBeDeleted(Todo *) 2678void CalendarView::todoToBeDeleted(Todo *)
2679{ 2679{
2680 //qDebug("todoToBeDeleted(Todo *) "); 2680 //qDebug("todoToBeDeleted(Todo *) ");
2681 updateTodoViews(); 2681 updateTodoViews();
2682} 2682}
2683void CalendarView::todoDeleted() 2683void CalendarView::todoDeleted()
2684{ 2684{
2685 //qDebug(" todoDeleted()"); 2685 //qDebug(" todoDeleted()");
2686 updateTodoViews(); 2686 updateTodoViews();
2687} 2687}
2688 2688
2689 2689
2690void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 2690void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
2691{ 2691{
2692 showTodoEditor(); 2692 showTodoEditor();
2693 mTodoEditor->newTodo(dt,0,allday); 2693 mTodoEditor->newTodo(dt,0,allday);
2694 if ( mFilterView->filtersEnabled() ) { 2694 if ( mFilterView->filtersEnabled() ) {
2695 CalFilter *filter = mFilterView->selectedFilter(); 2695 CalFilter *filter = mFilterView->selectedFilter();
2696 if (filter && filter->showCategories()) { 2696 if (filter && filter->showCategories()) {
2697 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2697 mTodoEditor->setCategories(filter->categoryList().join(",") );
2698 } 2698 }
2699 if ( filter ) 2699 if ( filter )
2700 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2700 mTodoEditor->setSecrecy( filter->getSecrecy() );
2701 } 2701 }
2702} 2702}
2703 2703
2704void CalendarView::newTodo() 2704void CalendarView::newTodo()
2705{ 2705{
2706 newTodoDateTime( QDateTime(),true ); 2706 newTodoDateTime( QDateTime(),true );
2707} 2707}
2708 2708
2709void CalendarView::newSubTodo() 2709void CalendarView::newSubTodo()
2710{ 2710{
2711 Todo *todo = selectedTodo(); 2711 Todo *todo = selectedTodo();
2712 if ( todo ) newSubTodo( todo ); 2712 if ( todo ) newSubTodo( todo );
2713} 2713}
2714 2714
2715void CalendarView::newSubTodo(Todo *parentEvent) 2715void CalendarView::newSubTodo(Todo *parentEvent)
2716{ 2716{
2717 2717
2718 showTodoEditor(); 2718 showTodoEditor();
2719 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 2719 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
2720} 2720}
2721 2721
2722void CalendarView::newFloatingEvent() 2722void CalendarView::newFloatingEvent()
2723{ 2723{
2724 DateList tmpList = mNavigator->selectedDates(); 2724 DateList tmpList = mNavigator->selectedDates();
2725 QDate date = tmpList.first(); 2725 QDate date = tmpList.first();
2726 2726
2727 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2727 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2728 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2728 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2729} 2729}
2730 2730
2731 2731
2732void CalendarView::editEvent( Event *event ) 2732void CalendarView::editEvent( Event *event )
2733{ 2733{
2734 2734
2735 if ( !event ) return; 2735 if ( !event ) return;
2736 if ( event->isReadOnly() ) { 2736 if ( event->isReadOnly() ) {
2737 showEvent( event ); 2737 showEvent( event );
2738 return; 2738 return;
2739 } 2739 }
2740 showEventEditor(); 2740 showEventEditor();
2741 mEventEditor->editEvent( event , mFlagEditDescription); 2741 mEventEditor->editEvent( event , mFlagEditDescription);
2742} 2742}
2743void CalendarView::editJournal( Journal *jour ) 2743void CalendarView::editJournal( Journal *jour )
2744{ 2744{
2745 if ( !jour ) return; 2745 if ( !jour ) return;
2746 mDialogManager->hideSearchDialog(); 2746 mDialogManager->hideSearchDialog();
2747 mViewManager->showJournalView(); 2747 mViewManager->showJournalView();
2748 mNavigator->slotDaySelect( jour->dtStart().date() ); 2748 mNavigator->slotDaySelect( jour->dtStart().date() );
2749} 2749}
2750void CalendarView::editTodo( Todo *todo ) 2750void CalendarView::editTodo( Todo *todo )
2751{ 2751{
2752 if ( !todo ) return; 2752 if ( !todo ) return;
2753 2753
2754 if ( todo->isReadOnly() ) { 2754 if ( todo->isReadOnly() ) {
2755 showTodo( todo ); 2755 showTodo( todo );
2756 return; 2756 return;
2757 } 2757 }
2758 showTodoEditor(); 2758 showTodoEditor();
2759 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2759 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2760 2760
2761} 2761}
2762 2762
2763KOEventViewerDialog* CalendarView::getEventViewerDialog() 2763KOEventViewerDialog* CalendarView::getEventViewerDialog()
2764{ 2764{
2765 if ( !mEventViewerDialog ) { 2765 if ( !mEventViewerDialog ) {
2766 mEventViewerDialog = new KOEventViewerDialog(this); 2766 mEventViewerDialog = new KOEventViewerDialog(this);
2767 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2767 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2768 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2768 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2769 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2769 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2770 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2770 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2771 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2771 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2772 viewManager(), SLOT( showAgendaView( bool ) ) ); 2772 viewManager(), SLOT( showAgendaView( bool ) ) );
2773 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 2773 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
2774 this, SLOT( todoChanged(Todo *) ) ); 2774 this, SLOT( todoChanged(Todo *) ) );
2775 mEventViewerDialog->resize( 640, 480 ); 2775 mEventViewerDialog->resize( 640, 480 );
2776 2776
2777 } 2777 }
2778 return mEventViewerDialog; 2778 return mEventViewerDialog;
2779} 2779}
2780void CalendarView::showEvent(Event *event) 2780void CalendarView::showEvent(Event *event)
2781{ 2781{
2782 getEventViewerDialog()->setEvent(event); 2782 getEventViewerDialog()->setEvent(event);
2783 getEventViewerDialog()->showMe(); 2783 getEventViewerDialog()->showMe();
2784} 2784}
2785 2785
2786void CalendarView::showTodo(Todo *event) 2786void CalendarView::showTodo(Todo *event)
2787{ 2787{
2788 getEventViewerDialog()->setTodo(event); 2788 getEventViewerDialog()->setTodo(event);
2789 getEventViewerDialog()->showMe(); 2789 getEventViewerDialog()->showMe();
2790} 2790}
2791void CalendarView::showJournal( Journal *jour ) 2791void CalendarView::showJournal( Journal *jour )
2792{ 2792{
2793 getEventViewerDialog()->setJournal(jour); 2793 getEventViewerDialog()->setJournal(jour);
2794 getEventViewerDialog()->showMe(); 2794 getEventViewerDialog()->showMe();
2795 2795
2796} 2796}
2797// void CalendarView::todoModified (Todo *event, int changed) 2797// void CalendarView::todoModified (Todo *event, int changed)
2798// { 2798// {
2799// // if (mDialogList.find (event) != mDialogList.end ()) { 2799// // if (mDialogList.find (event) != mDialogList.end ()) {
2800// // kdDebug() << "Todo modified and open" << endl; 2800// // kdDebug() << "Todo modified and open" << endl;
2801// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2801// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2802// // temp->modified (changed); 2802// // temp->modified (changed);
2803 2803
2804// // } 2804// // }
2805 2805
2806// mViewManager->updateView(); 2806// mViewManager->updateView();
2807// } 2807// }
2808 2808
2809void CalendarView::appointment_show() 2809void CalendarView::appointment_show()
2810{ 2810{
2811 Event *anEvent = 0; 2811 Event *anEvent = 0;
2812 2812
2813 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2813 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2814 2814
2815 if (mViewManager->currentView()->isEventView()) { 2815 if (mViewManager->currentView()->isEventView()) {
2816 if ( incidence && incidence->type() == "Event" ) { 2816 if ( incidence && incidence->type() == "Event" ) {
2817 anEvent = static_cast<Event *>(incidence); 2817 anEvent = static_cast<Event *>(incidence);
2818 } 2818 }
2819 } 2819 }
2820 2820
2821 if (!anEvent) { 2821 if (!anEvent) {
2822 KNotifyClient::beep(); 2822 KNotifyClient::beep();
2823 return; 2823 return;
2824 } 2824 }
2825 2825
2826 showEvent(anEvent); 2826 showEvent(anEvent);
2827} 2827}
2828 2828
2829void CalendarView::appointment_edit() 2829void CalendarView::appointment_edit()
2830{ 2830{
2831 Event *anEvent = 0; 2831 Event *anEvent = 0;
2832 2832
2833 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2833 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2834 2834
2835 if (mViewManager->currentView()->isEventView()) { 2835 if (mViewManager->currentView()->isEventView()) {
2836 if ( incidence && incidence->type() == "Event" ) { 2836 if ( incidence && incidence->type() == "Event" ) {
2837 anEvent = static_cast<Event *>(incidence); 2837 anEvent = static_cast<Event *>(incidence);
2838 } 2838 }
2839 } 2839 }
2840 2840
2841 if (!anEvent) { 2841 if (!anEvent) {
2842 KNotifyClient::beep(); 2842 KNotifyClient::beep();
2843 return; 2843 return;
2844 } 2844 }
2845 2845
2846 editEvent(anEvent); 2846 editEvent(anEvent);
2847} 2847}
2848 2848
2849void CalendarView::appointment_delete() 2849void CalendarView::appointment_delete()
2850{ 2850{
2851 Event *anEvent = 0; 2851 Event *anEvent = 0;
2852 2852
2853 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2853 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2854 2854
2855 if (mViewManager->currentView()->isEventView()) { 2855 if (mViewManager->currentView()->isEventView()) {
2856 if ( incidence && incidence->type() == "Event" ) { 2856 if ( incidence && incidence->type() == "Event" ) {
2857 anEvent = static_cast<Event *>(incidence); 2857 anEvent = static_cast<Event *>(incidence);
2858 } 2858 }
2859 } 2859 }
2860 2860
2861 if (!anEvent) { 2861 if (!anEvent) {
2862 KNotifyClient::beep(); 2862 KNotifyClient::beep();
2863 return; 2863 return;
2864 } 2864 }
2865 2865
2866 deleteEvent(anEvent); 2866 deleteEvent(anEvent);
2867} 2867}
2868 2868
2869void CalendarView::todo_resub( Todo * parent, Todo * sub ) 2869void CalendarView::todo_resub( Todo * parent, Todo * sub )
2870{ 2870{
2871 if (!sub) return; 2871 if (!sub) return;
2872 if (!parent) return; 2872 if (!parent) return;
2873 if ( sub->relatedTo() ) 2873 if ( sub->relatedTo() )
2874 sub->relatedTo()->removeRelation(sub); 2874 sub->relatedTo()->removeRelation(sub);
2875 sub->setRelatedTo(parent); 2875 sub->setRelatedTo(parent);
2876 sub->setRelatedToUid(parent->uid()); 2876 sub->setRelatedToUid(parent->uid());
2877 parent->addRelation(sub); 2877 parent->addRelation(sub);
2878 sub->updated(); 2878 sub->updated();
2879 parent->updated(); 2879 parent->updated();
2880 setModified(true); 2880 setModified(true);
2881 updateView(); 2881 updateView();
2882} 2882}
2883void CalendarView::todo_unsub(Todo *anTodo ) 2883void CalendarView::todo_unsub(Todo *anTodo )
2884{ 2884{
2885 // Todo *anTodo = selectedTodo(); 2885 // Todo *anTodo = selectedTodo();
2886 if (!anTodo) return; 2886 if (!anTodo) return;
2887 if (!anTodo->relatedTo()) return; 2887 if (!anTodo->relatedTo()) return;
2888 anTodo->relatedTo()->removeRelation(anTodo); 2888 anTodo->relatedTo()->removeRelation(anTodo);
2889 anTodo->setRelatedTo(0); 2889 anTodo->setRelatedTo(0);
2890 anTodo->updated(); 2890 anTodo->updated();
2891 anTodo->setRelatedToUid(""); 2891 anTodo->setRelatedToUid("");
2892 setModified(true); 2892 setModified(true);
2893 updateView(); 2893 updateView();
2894} 2894}
2895 2895
2896void CalendarView::deleteTodo(Todo *todo) 2896void CalendarView::deleteTodo(Todo *todo)
2897{ 2897{
2898 if (!todo) { 2898 if (!todo) {
2899 KNotifyClient::beep(); 2899 KNotifyClient::beep();
2900 return; 2900 return;
2901 } 2901 }
2902 if (KOPrefs::instance()->mConfirm) { 2902 if (KOPrefs::instance()->mConfirm) {
2903 QString text = todo->summary().left(20); 2903 QString text = todo->summary().left(20);
2904 if (!todo->relations().isEmpty()) { 2904 if (!todo->relations().isEmpty()) {
2905 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 2905 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
2906 2906
2907 } 2907 }
2908 switch (msgItemDelete(text)) { 2908 switch (msgItemDelete(text)) {
2909 case KMessageBox::Continue: // OK 2909 case KMessageBox::Continue: // OK
2910 bool deleteT = false; 2910 bool deleteT = false;
2911 if (!todo->relations().isEmpty()) { 2911 if (!todo->relations().isEmpty()) {
2912 deleteT = removeCompletedSubTodos( todo ); 2912 deleteT = removeCompletedSubTodos( todo );
2913 } 2913 }
2914 // deleteT == true: todo already deleted in removeCompletedSubTodos 2914 // deleteT == true: todo already deleted in removeCompletedSubTodos
2915 if ( !deleteT ) { 2915 if ( !deleteT ) {
2916 checkExternalId( todo ); 2916 checkExternalId( todo );
2917 calendar()->deleteTodo(todo); 2917 calendar()->deleteTodo(todo);
2918 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2918 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2919 updateView(); 2919 updateView();
2920 } 2920 }
2921 break; 2921 break;
2922 } // switch 2922 } // switch
2923 } else { 2923 } else {
2924 checkExternalId( todo ); 2924 checkExternalId( todo );
2925 mCalendar->deleteTodo(todo); 2925 mCalendar->deleteTodo(todo);
2926 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 2926 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
2927 updateView(); 2927 updateView();
2928 } 2928 }
2929 2929
2930 emit updateSearchDialog(); 2930 emit updateSearchDialog();
2931} 2931}
2932void CalendarView::deleteJournal(Journal *jour) 2932void CalendarView::deleteJournal(Journal *jour)
2933{ 2933{
2934 if (!jour) { 2934 if (!jour) {
2935 KNotifyClient::beep(); 2935 KNotifyClient::beep();
2936 return; 2936 return;
2937 } 2937 }
2938 if (KOPrefs::instance()->mConfirm) { 2938 if (KOPrefs::instance()->mConfirm) {
2939 switch (msgItemDelete( jour->description().left(20))) { 2939 switch (msgItemDelete( jour->description().left(20))) {
2940 case KMessageBox::Continue: // OK 2940 case KMessageBox::Continue: // OK
2941 calendar()->deleteJournal(jour); 2941 calendar()->deleteJournal(jour);
2942 updateView(); 2942 updateView();
2943 break; 2943 break;
2944 } // switch 2944 } // switch
2945 } else { 2945 } else {
2946 calendar()->deleteJournal(jour);; 2946 calendar()->deleteJournal(jour);;
2947 updateView(); 2947 updateView();
2948 } 2948 }
2949 emit updateSearchDialog(); 2949 emit updateSearchDialog();
2950} 2950}
2951 2951
2952void CalendarView::deleteEvent(Event *anEvent) 2952void CalendarView::deleteEvent(Event *anEvent)
2953{ 2953{
2954 if (!anEvent) { 2954 if (!anEvent) {
2955 KNotifyClient::beep(); 2955 KNotifyClient::beep();
2956 return; 2956 return;
2957 } 2957 }
2958 2958
2959 if (anEvent->recurrence()->doesRecur()) { 2959 if (anEvent->recurrence()->doesRecur()) {
2960 QDate itemDate = mViewManager->currentSelectionDate(); 2960 QDate itemDate = mViewManager->currentSelectionDate();
2961 int km; 2961 int km;
2962 if (!itemDate.isValid()) { 2962 if (!itemDate.isValid()) {
2963 //kdDebug() << "Date Not Valid" << endl; 2963 //kdDebug() << "Date Not Valid" << endl;
2964 if (KOPrefs::instance()->mConfirm) { 2964 if (KOPrefs::instance()->mConfirm) {
2965 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 2965 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
2966 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 2966 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
2967 i18n("KO/Pi Confirmation"),i18n("Delete All")); 2967 i18n("KO/Pi Confirmation"),i18n("Delete All"));
2968 if ( km == KMessageBox::Continue ) 2968 if ( km == KMessageBox::Continue )
2969 km = KMessageBox::No; // No = all below 2969 km = KMessageBox::No; // No = all below
2970 } else 2970 } else
2971 km = KMessageBox::No; 2971 km = KMessageBox::No;
2972 } else { 2972 } else {
2973 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 2973 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
2974 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 2974 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
2975 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 2975 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
2976 i18n("KO/Pi Confirmation"),i18n("Current"), 2976 i18n("KO/Pi Confirmation"),i18n("Current"),
2977 i18n("All")); 2977 i18n("All"));
2978 } 2978 }
2979 switch(km) { 2979 switch(km) {
2980 2980
2981 case KMessageBox::No: // Continue // all 2981 case KMessageBox::No: // Continue // all
2982 //qDebug("KMessageBox::No "); 2982 //qDebug("KMessageBox::No ");
2983 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 2983 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
2984 schedule(Scheduler::Cancel,anEvent); 2984 schedule(Scheduler::Cancel,anEvent);
2985 2985
2986 checkExternalId( anEvent); 2986 checkExternalId( anEvent);
2987 mCalendar->deleteEvent(anEvent); 2987 mCalendar->deleteEvent(anEvent);
2988 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 2988 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
2989 break; 2989 break;
2990 2990
2991 // Disabled because it does not work 2991 // Disabled because it does not work
2992 //#if 0 2992 //#if 0
2993 case KMessageBox::Yes: // just this one 2993 case KMessageBox::Yes: // just this one
2994 //QDate qd = mNavigator->selectedDates().first(); 2994 //QDate qd = mNavigator->selectedDates().first();
2995 //if (!qd.isValid()) { 2995 //if (!qd.isValid()) {
2996 // kdDebug() << "no date selected, or invalid date" << endl; 2996 // kdDebug() << "no date selected, or invalid date" << endl;
2997 // KNotifyClient::beep(); 2997 // KNotifyClient::beep();
2998 // return; 2998 // return;
2999 //} 2999 //}
3000 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3000 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3001 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3001 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3002 anEvent->addExDate(itemDate); 3002 anEvent->addExDate(itemDate);
3003 int duration = anEvent->recurrence()->duration(); 3003 int duration = anEvent->recurrence()->duration();
3004 if ( duration > 0 ) { 3004 if ( duration > 0 ) {
3005 anEvent->recurrence()->setDuration( duration - 1 ); 3005 anEvent->recurrence()->setDuration( duration - 1 );
3006 } 3006 }
3007 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3007 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3008 } 3008 }
3009 break; 3009 break;
3010 //#endif 3010 //#endif
3011 } // switch 3011 } // switch
3012 } else { 3012 } else {
3013 if (KOPrefs::instance()->mConfirm) { 3013 if (KOPrefs::instance()->mConfirm) {
3014 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3014 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
diff --git a/korganizer/korganizer.pro b/korganizer/korganizer.pro
index 4d67dca..3c7a1fb 100644
--- a/korganizer/korganizer.pro
+++ b/korganizer/korganizer.pro
@@ -1,191 +1,191 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG += qt warn_off 2 CONFIG += qt warn_off
3 TARGET = kopi 3 TARGET = kopi
4OBJECTS_DIR = _obj/ 4OBJECTS_DIR = _obj/
5MOC_DIR = _moc 5MOC_DIR = _moc
6DESTDIR= ../bin 6DESTDIR= ../bin
7 7
8include( ../variables.pri ) 8include( ../variables.pri )
9 9
10INCLUDEPATH += ../microkde ../ interfaces ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim 10INCLUDEPATH += ../microkde ../ interfaces ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim
11#../qtcompat 11#../qtcompat
12DEFINES += KORG_NODND KORG_NOPLUGINS KORG_NOARCHIVE KORG_NOMAIL 12DEFINES += KORG_NOPLUGINS KORG_NOARCHIVE KORG_NOMAIL
13DEFINES += KORG_NODCOP KORG_NOKALARMD KORG_NORESOURCEVIEW KORG_NOSPLITTER 13DEFINES += KORG_NODCOP KORG_NOKALARMD KORG_NORESOURCEVIEW KORG_NOSPLITTER
14#KORG_NOPRINTER KORG_NOKABC 14#KORG_NOPRINTER KORG_NOKABC KORG_NODND
15DEFINES += KORG_NOLVALTERNATION 15DEFINES += KORG_NOLVALTERNATION
16DEFINES += DESKTOP_VERSION 16DEFINES += DESKTOP_VERSION
17unix : { 17unix : {
18LIBS += ../bin/libmicrokdepim.so 18LIBS += ../bin/libmicrokdepim.so
19LIBS += ../bin/libmicrokcal.so 19LIBS += ../bin/libmicrokcal.so
20LIBS += ../bin/libmicrokde.so 20LIBS += ../bin/libmicrokde.so
21LIBS += ../bin/libmicrokabc.so 21LIBS += ../bin/libmicrokabc.so
22#LIBS += -lbluetooth 22#LIBS += -lbluetooth
23#LIBS += -lsdp 23#LIBS += -lsdp
24 24
25#LIBS += -lldap 25#LIBS += -lldap
26OBJECTS_DIR = obj/unix 26OBJECTS_DIR = obj/unix
27MOC_DIR = moc/unix 27MOC_DIR = moc/unix
28} 28}
29win32: { 29win32: {
30RC_FILE = winicons.rc 30RC_FILE = winicons.rc
31DEFINES += _WIN32_ 31DEFINES += _WIN32_
32LIBS += ../bin/microkdepim.lib 32LIBS += ../bin/microkdepim.lib
33LIBS += ../bin/microkcal.lib 33LIBS += ../bin/microkcal.lib
34LIBS += ../bin/microkde.lib 34LIBS += ../bin/microkde.lib
35LIBS += ../bin/microkabc.lib 35LIBS += ../bin/microkabc.lib
36LIBS += ../libical/lib/ical.lib 36LIBS += ../libical/lib/ical.lib
37LIBS += ../libical/lib/icalss.lib 37LIBS += ../libical/lib/icalss.lib
38#LIBS += atls.lib 38#LIBS += atls.lib
39QMAKE_LINK += /NODEFAULTLIB:LIBC 39QMAKE_LINK += /NODEFAULTLIB:LIBC
40#QMAKE_LINK += /NODEFAULTLIB:MSVCRT 40#QMAKE_LINK += /NODEFAULTLIB:MSVCRT
41#QMAKE_LINK += /NODEFAULTLIB:uafxcw.lib 41#QMAKE_LINK += /NODEFAULTLIB:uafxcw.lib
42OBJECTS_DIR = obj/win 42OBJECTS_DIR = obj/win
43MOC_DIR = moc/win 43MOC_DIR = moc/win
44#olimport section 44#olimport section
45#blabla: { 45#blabla: {
46LIBS += mfc71u.lib 46LIBS += mfc71u.lib
47DEFINES += _OL_IMPORT_ 47DEFINES += _OL_IMPORT_
48 48
49HEADERS += ../outport/msoutl9.h \ 49HEADERS += ../outport/msoutl9.h \
50 koimportoldialog.h 50 koimportoldialog.h
51SOURCES += ../outport/msoutl9.cpp \ 51SOURCES += ../outport/msoutl9.cpp \
52 koimportoldialog.cpp 52 koimportoldialog.cpp
53#} 53#}
54#olimport section end 54#olimport section end
55 55
56} 56}
57 57
58 58
59INTERFACES = kofilterview_base.ui 59INTERFACES = kofilterview_base.ui
60#filteredit_base.ui 60#filteredit_base.ui
61 61
62# kdateedit.h \ 62# kdateedit.h \
63 63
64HEADERS += \ 64HEADERS += \
65 filteredit_base.h \ 65 filteredit_base.h \
66 alarmclient.h \ 66 alarmclient.h \
67 calendarview.h \ 67 calendarview.h \
68 customlistviewitem.h \ 68 customlistviewitem.h \
69 datenavigator.h \ 69 datenavigator.h \
70 docprefs.h \ 70 docprefs.h \
71 filtereditdialog.h \ 71 filtereditdialog.h \
72 incomingdialog.h \ 72 incomingdialog.h \
73 incomingdialog_base.h \ 73 incomingdialog_base.h \
74 interfaces/korganizer/baseview.h \ 74 interfaces/korganizer/baseview.h \
75 interfaces/korganizer/calendarviewbase.h \ 75 interfaces/korganizer/calendarviewbase.h \
76 journalentry.h \ 76 journalentry.h \
77 kdatenavigator.h \ 77 kdatenavigator.h \
78 koagenda.h \ 78 koagenda.h \
79 koagendaitem.h \ 79 koagendaitem.h \
80 koagendaview.h \ 80 koagendaview.h \
81 kocounterdialog.h \ 81 kocounterdialog.h \
82 kodaymatrix.h \ 82 kodaymatrix.h \
83 kodialogmanager.h \ 83 kodialogmanager.h \
84 koeditordetails.h \ 84 koeditordetails.h \
85 koeditorgeneral.h \ 85 koeditorgeneral.h \
86 koeditorgeneralevent.h \ 86 koeditorgeneralevent.h \
87 koeditorgeneraltodo.h \ 87 koeditorgeneraltodo.h \
88 koeditorrecurrence.h \ 88 koeditorrecurrence.h \
89 koeventeditor.h \ 89 koeventeditor.h \
90 koeventpopupmenu.h \ 90 koeventpopupmenu.h \
91 koeventview.h \ 91 koeventview.h \
92 koeventviewer.h \ 92 koeventviewer.h \
93 koeventviewerdialog.h \ 93 koeventviewerdialog.h \
94 kofilterview.h \ 94 kofilterview.h \
95 koglobals.h \ 95 koglobals.h \
96 koincidenceeditor.h \ 96 koincidenceeditor.h \
97 kojournalview.h \ 97 kojournalview.h \
98 kolistview.h \ 98 kolistview.h \
99 kolocationbox.h \ 99 kolocationbox.h \
100 komonthview.h \ 100 komonthview.h \
101 koprefs.h \ 101 koprefs.h \
102 koprefsdialog.h \ 102 koprefsdialog.h \
103 kotimespanview.h \ 103 kotimespanview.h \
104 kotodoeditor.h \ 104 kotodoeditor.h \
105 kotodoview.h \ 105 kotodoview.h \
106 kotodoviewitem.h \ 106 kotodoviewitem.h \
107 koviewmanager.h \ 107 koviewmanager.h \
108 kowhatsnextview.h \ 108 kowhatsnextview.h \
109 ktimeedit.h \ 109 ktimeedit.h \
110 lineview.h \ 110 lineview.h \
111 mainwindow.h \ 111 mainwindow.h \
112 navigatorbar.h \ 112 navigatorbar.h \
113 outgoingdialog.h \ 113 outgoingdialog.h \
114 outgoingdialog_base.h \ 114 outgoingdialog_base.h \
115 publishdialog.h \ 115 publishdialog.h \
116 publishdialog_base.h \ 116 publishdialog_base.h \
117 savetemplatedialog.h \ 117 savetemplatedialog.h \
118 searchdialog.h \ 118 searchdialog.h \
119 simplealarmclient.h \ 119 simplealarmclient.h \
120 statusdialog.h \ 120 statusdialog.h \
121 timeline.h \ 121 timeline.h \
122 timespanview.h \ 122 timespanview.h \
123 version.h \ 123 version.h \
124 ../kalarmd/alarmdialog.h \ 124 ../kalarmd/alarmdialog.h \
125 125
126 126
127SOURCES += \ 127SOURCES += \
128filteredit_base.cpp \ 128filteredit_base.cpp \
129 calendarview.cpp \ 129 calendarview.cpp \
130 datenavigator.cpp \ 130 datenavigator.cpp \
131 docprefs.cpp \ 131 docprefs.cpp \
132 filtereditdialog.cpp \ 132 filtereditdialog.cpp \
133 incomingdialog.cpp \ 133 incomingdialog.cpp \
134 incomingdialog_base.cpp \ 134 incomingdialog_base.cpp \
135 journalentry.cpp \ 135 journalentry.cpp \
136 kdatenavigator.cpp \ 136 kdatenavigator.cpp \
137 koagenda.cpp \ 137 koagenda.cpp \
138 koagendaitem.cpp \ 138 koagendaitem.cpp \
139 koagendaview.cpp \ 139 koagendaview.cpp \
140 kocounterdialog.cpp \ 140 kocounterdialog.cpp \
141 kodaymatrix.cpp \ 141 kodaymatrix.cpp \
142 kodialogmanager.cpp \ 142 kodialogmanager.cpp \
143 koeditordetails.cpp \ 143 koeditordetails.cpp \
144 koeditorgeneral.cpp \ 144 koeditorgeneral.cpp \
145 koeditorgeneralevent.cpp \ 145 koeditorgeneralevent.cpp \
146 koeditorgeneraltodo.cpp \ 146 koeditorgeneraltodo.cpp \
147 koeditorrecurrence.cpp \ 147 koeditorrecurrence.cpp \
148 koeventeditor.cpp \ 148 koeventeditor.cpp \
149 koeventpopupmenu.cpp \ 149 koeventpopupmenu.cpp \
150 koeventview.cpp \ 150 koeventview.cpp \
151 koeventviewer.cpp \ 151 koeventviewer.cpp \
152 koeventviewerdialog.cpp \ 152 koeventviewerdialog.cpp \
153 kofilterview.cpp \ 153 kofilterview.cpp \
154 koglobals.cpp \ 154 koglobals.cpp \
155 koincidenceeditor.cpp \ 155 koincidenceeditor.cpp \
156 kojournalview.cpp \ 156 kojournalview.cpp \
157 kolistview.cpp \ 157 kolistview.cpp \
158 kolocationbox.cpp \ 158 kolocationbox.cpp \
159 komonthview.cpp \ 159 komonthview.cpp \
160 koprefs.cpp \ 160 koprefs.cpp \
161 koprefsdialog.cpp \ 161 koprefsdialog.cpp \
162 kotimespanview.cpp \ 162 kotimespanview.cpp \
163 kotodoeditor.cpp \ 163 kotodoeditor.cpp \
164 kotodoview.cpp \ 164 kotodoview.cpp \
165 kotodoviewitem.cpp \ 165 kotodoviewitem.cpp \
166 koviewmanager.cpp \ 166 koviewmanager.cpp \
167 kowhatsnextview.cpp \ 167 kowhatsnextview.cpp \
168 ktimeedit.cpp \ 168 ktimeedit.cpp \
169 lineview.cpp \ 169 lineview.cpp \
170 main.cpp \ 170 main.cpp \
171 mainwindow.cpp \ 171 mainwindow.cpp \
172 navigatorbar.cpp \ 172 navigatorbar.cpp \
173 outgoingdialog.cpp \ 173 outgoingdialog.cpp \
174 outgoingdialog_base.cpp \ 174 outgoingdialog_base.cpp \
175 publishdialog.cpp \ 175 publishdialog.cpp \
176 publishdialog_base.cpp \ 176 publishdialog_base.cpp \
177 savetemplatedialog.cpp \ 177 savetemplatedialog.cpp \
178 searchdialog.cpp \ 178 searchdialog.cpp \
179 simplealarmclient.cpp \ 179 simplealarmclient.cpp \
180 statusdialog.cpp \ 180 statusdialog.cpp \
181 timeline.cpp \ 181 timeline.cpp \
182 timespanview.cpp \ 182 timespanview.cpp \
183 ../kalarmd/alarmdialog.cpp 183 ../kalarmd/alarmdialog.cpp
184 184
185HEADERS += calprintbase.h calprinter.h calprintplugins.h cellitem.h 185HEADERS += calprintbase.h calprinter.h calprintplugins.h cellitem.h
186INTERFACES += calprintdayconfig_base.ui \ 186INTERFACES += calprintdayconfig_base.ui \
187 calprintmonthconfig_base.ui \ 187 calprintmonthconfig_base.ui \
188 calprinttodoconfig_base.ui \ 188 calprinttodoconfig_base.ui \
189 calprintweekconfig_base.ui 189 calprintweekconfig_base.ui
190SOURCES += calprintbase.cpp calprinter.cpp calprintplugins.cpp cellitem.cpp 190SOURCES += calprintbase.cpp calprinter.cpp calprintplugins.cpp cellitem.cpp
191 191
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index 1fb480d..8c1953d 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1218 +1,1227 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,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 <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27 27
28#include <qvbox.h> 28#include <qvbox.h>
29#include <kdebug.h> 29#include <kdebug.h>
30#include "koprefs.h" 30#include "koprefs.h"
31#include <klocale.h> 31#include <klocale.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <kiconloader.h> 33#include <kiconloader.h>
34#include <kmessagebox.h> 34#include <kmessagebox.h>
35 35
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/vcaldrag.h> 37#include <libkcal/vcaldrag.h>
38#include <libkcal/calfilter.h> 38#include <libkcal/calfilter.h>
39#include <libkcal/dndfactory.h> 39#include <libkcal/dndfactory.h>
40#include <libkcal/calendarresources.h> 40#include <libkcal/calendarresources.h>
41#include <libkcal/resourcecalendar.h> 41#include <libkcal/resourcecalendar.h>
42#include <kresources/resourceselectdialog.h> 42#include <kresources/resourceselectdialog.h>
43#ifndef DESKTOP_VERSION 43#ifndef DESKTOP_VERSION
44#include <qpe/qpeapplication.h> 44#include <qpe/qpeapplication.h>
45#else 45#else
46#include <qapplication.h> 46#include <qapplication.h>
47#endif 47#endif
48#ifndef KORG_NOPRINTER 48#ifndef KORG_NOPRINTER
49#include "calprinter.h" 49#include "calprinter.h"
50#endif 50#endif
51#include "docprefs.h" 51#include "docprefs.h"
52 52
53#include "kotodoview.h" 53#include "kotodoview.h"
54using namespace KOrg; 54using namespace KOrg;
55 55
56KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 56KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
57 const char *name) : 57 const char *name) :
58 KListView(parent,name) 58 KListView(parent,name)
59{ 59{
60 mName = QString ( name ); 60 mName = QString ( name );
61 mCalendar = calendar; 61 mCalendar = calendar;
62#ifndef DESKTOP_VERSION 62#ifndef DESKTOP_VERSION
63 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 63 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
64#endif 64#endif
65 mOldCurrent = 0; 65 mOldCurrent = 0;
66 mMousePressed = false; 66 mMousePressed = false;
67 67
68 setAcceptDrops(true); 68 setAcceptDrops(true);
69 viewport()->setAcceptDrops(true); 69 viewport()->setAcceptDrops(true);
70 int size = 16; 70 int size = 16;
71 if (qApp->desktop()->width() < 300 ) 71 if (qApp->desktop()->width() < 300 )
72 size = 12; 72 size = 12;
73 setTreeStepSize( size + 6 ); 73 setTreeStepSize( size + 6 );
74 74
75} 75}
76 76
77void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 77void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
78{ 78{
79#ifndef KORG_NODND 79#ifndef KORG_NODND
80// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 80// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
81 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 81 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
82 !QTextDrag::canDecode( e ) ) { 82 !QTextDrag::canDecode( e ) ) {
83 e->ignore(); 83 e->ignore();
84 return; 84 return;
85 } 85 }
86 86
87 mOldCurrent = currentItem(); 87 mOldCurrent = currentItem();
88#endif 88#endif
89} 89}
90 90
91 91
92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 92void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
93{ 93{
94#ifndef KORG_NODND 94#ifndef KORG_NODND
95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 95// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
96 96
97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 97 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
98 !QTextDrag::canDecode( e ) ) { 98 !QTextDrag::canDecode( e ) ) {
99 e->ignore(); 99 e->ignore();
100 return; 100 return;
101 } 101 }
102 102
103 e->accept(); 103 e->accept();
104#endif 104#endif
105} 105}
106 106
107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 107void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
108{ 108{
109#ifndef KORG_NODND 109#ifndef KORG_NODND
110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 110// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
111 111
112 setCurrentItem(mOldCurrent); 112 setCurrentItem(mOldCurrent);
113 setSelected(mOldCurrent,true); 113 setSelected(mOldCurrent,true);
114#endif 114#endif
115} 115}
116 116
117void KOTodoListView::contentsDropEvent(QDropEvent *e) 117void KOTodoListView::contentsDropEvent(QDropEvent *e)
118{ 118{
119#ifndef KORG_NODND 119#ifndef KORG_NODND
120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 120// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
121 121
122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 122 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
123 !QTextDrag::canDecode( e ) ) { 123 !QTextDrag::canDecode( e ) ) {
124 e->ignore(); 124 e->ignore();
125 return; 125 return;
126 } 126 }
127 127
128 DndFactory factory( mCalendar ); 128 DndFactory factory( mCalendar );
129 Todo *todo = factory.createDropTodo(e); 129 Todo *todo = factory.createDropTodo(e);
130 130
131 if (todo) { 131 if (todo) {
132 e->acceptAction(); 132 e->acceptAction();
133 133
134 KOTodoViewItem *destination = 134 KOTodoViewItem *destination =
135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 135 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
136 Todo *destinationEvent = 0; 136 Todo *destinationEvent = 0;
137 if (destination) destinationEvent = destination->todo(); 137 if (destination) destinationEvent = destination->todo();
138 138
139 Todo *existingTodo = mCalendar->todo(todo->uid()); 139 Todo *existingTodo = mCalendar->todo(todo->uid());
140 140
141 if(existingTodo) { 141 if(existingTodo) {
142// kdDebug() << "Drop existing Todo" << endl;
143 Incidence *to = destinationEvent; 142 Incidence *to = destinationEvent;
144 while(to) { 143 while(to) {
145 if (to->uid() == todo->uid()) { 144 if (to->uid() == todo->uid()) {
146 KMessageBox::sorry(this, 145 KMessageBox::sorry(this,
147 i18n("Cannot move To-Do to itself or a child of itself"), 146 i18n("Cannot move To-Do to itself\nor a child of itself"),
148 i18n("Drop To-Do")); 147 i18n("Drop To-Do"));
149 delete todo; 148 delete todo;
150 return; 149 return;
151 } 150 }
152 to = to->relatedTo(); 151 to = to->relatedTo();
153 } 152 }
154 existingTodo->setRelatedTo(destinationEvent); 153 internalDrop = true;
155 emit todoDropped(todo); 154 if ( destinationEvent )
155 reparentTodoSignal( destinationEvent, existingTodo );
156 else
157 unparentTodoSignal(existingTodo);
156 delete todo; 158 delete todo;
157 } else { 159 } else {
158// kdDebug() << "Drop new Todo" << endl;
159 todo->setRelatedTo(destinationEvent);
160 mCalendar->addTodo(todo); 160 mCalendar->addTodo(todo);
161 161 emit todoDropped(todo, KOGlobals::EVENTADDED);
162 emit todoDropped(todo); 162 if ( destinationEvent )
163 reparentTodoSignal( destinationEvent, todo );
163 } 164 }
164 } 165 }
165 else { 166 else {
166 QString text; 167 QString text;
167 if (QTextDrag::decode(e,text)) { 168 if (QTextDrag::decode(e,text)) {
168 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 169 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
169 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 170 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
170 kdDebug() << "Dropped : " << text << endl; 171 qDebug("Dropped : " + text);
171 QStringList emails = QStringList::split(",",text); 172 QStringList emails = QStringList::split(",",text);
172 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 173 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
173 kdDebug() << " Email: " << (*it) << endl;
174 int pos = (*it).find("<"); 174 int pos = (*it).find("<");
175 QString name = (*it).left(pos); 175 QString name = (*it).left(pos);
176 QString email = (*it).mid(pos); 176 QString email = (*it).mid(pos);
177 if (!email.isEmpty() && todoi) { 177 if (!email.isEmpty() && todoi) {
178 todoi->todo()->addAttendee(new Attendee(name,email)); 178 todoi->todo()->addAttendee(new Attendee(name,email));
179 } 179 }
180 } 180 }
181 } 181 }
182 else { 182 else {
183 kdDebug() << "KOTodoListView::contentsDropEvent(): Todo from drop not decodable" << endl; 183 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
184 e->ignore(); 184 e->ignore();
185 } 185 }
186 } 186 }
187#endif 187#endif
188} 188}
189 189
190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 190void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
191{ 191{
192 QListView::contentsMousePressEvent(e);
193#ifndef KORG_NODND 192#ifndef KORG_NODND
194 QPoint p(contentsToViewport(e->pos())); 193 QPoint p(contentsToViewport(e->pos()));
195 QListViewItem *i = itemAt(p); 194 QListViewItem *i = itemAt(p);
195 mMousePressed = false;
196 if (i) { 196 if (i) {
197 // if the user clicked into the root decoration of the item, don't 197 // if the user clicked into the root decoration of the item, don't
198 // try to start a drag! 198 // try to start a drag!
199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 199 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 200 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
201 itemMargin() || 201 itemMargin() ||
202 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 202 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
203 if (e->button()==Qt::LeftButton) { 203 if (e->button()==Qt::LeftButton) {
204 mPressPos = e->pos(); 204 mPressPos = e->pos();
205 mMousePressed = true; 205 mMousePressed = true;
206 } 206 }
207 } 207 }
208 } 208 }
209#endif 209#endif
210 QListView::contentsMousePressEvent(e);
210} 211}
211 212
212void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 213void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
213{ 214{
214 215
215#ifndef KORG_NODND 216#ifndef KORG_NODND
216// kdDebug() << "KOTodoListView::contentsMouseMoveEvent()" << endl;
217 QListView::contentsMouseMoveEvent(e); 217 QListView::contentsMouseMoveEvent(e);
218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 218 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
219 QApplication::startDragDistance()) { 219 QApplication::startDragDistance()) {
220 mMousePressed = false; 220 mMousePressed = false;
221 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 221 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
222 if (item) { 222 if (item) {
223// kdDebug() << "Start Drag for item " << item->text(0) << endl;
224 DndFactory factory( mCalendar ); 223 DndFactory factory( mCalendar );
225 ICalDrag *vd = factory.createDragTodo( 224 ICalDrag *vd = factory.createDrag(
226 ((KOTodoViewItem *)item)->todo(),viewport()); 225 ((KOTodoViewItem *)item)->todo(),viewport());
226 internalDrop = false;
227 // we cannot do any senseful here, because the DnD is still broken in Qt
227 if (vd->drag()) { 228 if (vd->drag()) {
228 kdDebug() << "KOTodoListView::contentsMouseMoveEvent(): Delete drag source" << endl; 229 if ( !internalDrop ) {
230 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
231 qDebug("Dnd: External move: Delete drag source ");
232 } else
233 qDebug("Dnd: Internal move ");
234
235 } else {
236 if ( !internalDrop ) {
237 qDebug("Dnd: External Copy");
238 } else
239 qDebug("DnD: Internal copy: Copy pending");
229 } 240 }
230/*
231 QString source = fullPath(item);
232 if ( QFile::exists(source) ) {
233 QUriDrag* ud = new QUriDrag(viewport());
234 ud->setFilenames( source );
235 if ( ud->drag() )
236 QMessageBox::information( this, "Drag source",
237 QString("Delete ")+source, "Not implemented" );
238*/
239 } 241 }
240 } 242 }
241#endif 243#endif
242} 244}
243void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 245void KOTodoListView::keyPressEvent ( QKeyEvent * e )
244{ 246{
245 247
246 QListViewItem* cn; 248 QListViewItem* cn;
247 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 249 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
248 cn = currentItem(); 250 cn = currentItem();
249 if ( cn ) { 251 if ( cn ) {
250 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 252 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
251 if ( ci ){ 253 if ( ci ){
252 if ( e->state() == ShiftButton ) 254 if ( e->state() == ShiftButton )
253 ci->setOn( false ); 255 ci->setOn( false );
254 else 256 else
255 ci->setOn( true ); 257 ci->setOn( true );
256 cn = cn->nextSibling(); 258 cn = cn->nextSibling();
257 if ( cn ) { 259 if ( cn ) {
258 setCurrentItem ( cn ); 260 setCurrentItem ( cn );
259 ensureItemVisible ( cn ); 261 ensureItemVisible ( cn );
260 } 262 }
261 263
262 } 264 }
263 } 265 }
264 266
265 return; 267 return;
266 } 268 }
267 269
268 // qDebug("KOTodoListView::keyPressEvent "); 270 // qDebug("KOTodoListView::keyPressEvent ");
269 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 271 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
270 switch ( e->key() ) { 272 switch ( e->key() ) {
271 case Qt::Key_Down: 273 case Qt::Key_Down:
272 case Qt::Key_Up: 274 case Qt::Key_Up:
273 QListView::keyPressEvent ( e ); 275 QListView::keyPressEvent ( e );
274 break; 276 break;
275 case Qt::Key_Left: 277 case Qt::Key_Left:
276 case Qt::Key_Right: 278 case Qt::Key_Right:
277 QListView::keyPressEvent ( e ); 279 QListView::keyPressEvent ( e );
278 e->accept(); 280 e->accept();
279 return; 281 return;
280 break; 282 break;
281 default: 283 default:
282 e->ignore(); 284 e->ignore();
283 break; 285 break;
284 } 286 }
285 return; 287 return;
286 } 288 }
287 e->ignore(); 289 e->ignore();
288} 290}
289void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 291void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
290{ 292{
291 QListView::contentsMouseReleaseEvent(e); 293 QListView::contentsMouseReleaseEvent(e);
292 mMousePressed = false; 294 mMousePressed = false;
293} 295}
294 296
295void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 297void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
296{ 298{
297 if (!e) return; 299 if (!e) return;
298 300
299 QPoint vp = contentsToViewport(e->pos()); 301 QPoint vp = contentsToViewport(e->pos());
300 302
301 QListViewItem *item = itemAt(vp); 303 QListViewItem *item = itemAt(vp);
302 304
303 emit double_Clicked(item); 305 emit double_Clicked(item);
304 if (!item) return; 306 if (!item) return;
305 307
306 emit doubleClicked(item,vp,0); 308 emit doubleClicked(item,vp,0);
307} 309}
308 310
309///////////////////////////////////////////////////////////////////////////// 311/////////////////////////////////////////////////////////////////////////////
310 312
311KOQuickTodo::KOQuickTodo(QWidget *parent) : 313KOQuickTodo::KOQuickTodo(QWidget *parent) :
312 QLineEdit(parent) 314 QLineEdit(parent)
313{ 315{
314 setText(i18n("Click to add a new Todo")); 316 setText(i18n("Click to add a new Todo"));
315} 317}
316 318
317void KOQuickTodo::focusInEvent(QFocusEvent *ev) 319void KOQuickTodo::focusInEvent(QFocusEvent *ev)
318{ 320{
319 if ( text()==i18n("Click to add a new Todo") ) 321 if ( text()==i18n("Click to add a new Todo") )
320 setText(""); 322 setText("");
321 QLineEdit::focusInEvent(ev); 323 QLineEdit::focusInEvent(ev);
322} 324}
323 325
324void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 326void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
325{ 327{
326 setText(i18n("Click to add a new Todo")); 328 setText(i18n("Click to add a new Todo"));
327 QLineEdit::focusOutEvent(ev); 329 QLineEdit::focusOutEvent(ev);
328} 330}
329 331
330///////////////////////////////////////////////////////////////////////////// 332/////////////////////////////////////////////////////////////////////////////
331 333
332KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 334KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
333 KOrg::BaseView(calendar,parent,name) 335 KOrg::BaseView(calendar,parent,name)
334{ 336{
335 mNavigator = 0; 337 mNavigator = 0;
336 QBoxLayout *topLayout = new QVBoxLayout(this); 338 QBoxLayout *topLayout = new QVBoxLayout(this);
337 mName = QString ( name ); 339 mName = QString ( name );
338 mBlockUpdate = false; 340 mBlockUpdate = false;
339 mQuickAdd = new KOQuickTodo(this); 341 mQuickAdd = new KOQuickTodo(this);
340 topLayout->addWidget(mQuickAdd); 342 topLayout->addWidget(mQuickAdd);
341 343
342 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 344 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
343 345
344 mTodoListView = new KOTodoListView(calendar,this, name ); 346 mTodoListView = new KOTodoListView(calendar,this, name );
345 topLayout->addWidget(mTodoListView); 347 topLayout->addWidget(mTodoListView);
346 //mTodoListView->header()->setMaximumHeight(30); 348 //mTodoListView->header()->setMaximumHeight(30);
347 mTodoListView->setRootIsDecorated(true); 349 mTodoListView->setRootIsDecorated(true);
348 mTodoListView->setAllColumnsShowFocus(true); 350 mTodoListView->setAllColumnsShowFocus(true);
349 351
350 mTodoListView->setShowSortIndicator(true); 352 mTodoListView->setShowSortIndicator(true);
351 353
352 mTodoListView->addColumn(i18n("Todo")); 354 mTodoListView->addColumn(i18n("Todo"));
353 mTodoListView->addColumn(i18n("Prio")); 355 mTodoListView->addColumn(i18n("Prio"));
354 mTodoListView->setColumnAlignment(1,AlignHCenter); 356 mTodoListView->setColumnAlignment(1,AlignHCenter);
355 mTodoListView->addColumn(i18n("Complete")); 357 mTodoListView->addColumn(i18n("Complete"));
356 mTodoListView->setColumnAlignment(2,AlignCenter); 358 mTodoListView->setColumnAlignment(2,AlignCenter);
357 359
358 mTodoListView->addColumn(i18n("Due Date")); 360 mTodoListView->addColumn(i18n("Due Date"));
359 mTodoListView->setColumnAlignment(3,AlignLeft); 361 mTodoListView->setColumnAlignment(3,AlignLeft);
360 mTodoListView->addColumn(i18n("Due Time")); 362 mTodoListView->addColumn(i18n("Due Time"));
361 mTodoListView->setColumnAlignment(4,AlignHCenter); 363 mTodoListView->setColumnAlignment(4,AlignHCenter);
362 364
363 mTodoListView->addColumn(i18n("Start Date")); 365 mTodoListView->addColumn(i18n("Start Date"));
364 mTodoListView->setColumnAlignment(5,AlignLeft); 366 mTodoListView->setColumnAlignment(5,AlignLeft);
365 mTodoListView->addColumn(i18n("Start Time")); 367 mTodoListView->addColumn(i18n("Start Time"));
366 mTodoListView->setColumnAlignment(6,AlignHCenter); 368 mTodoListView->setColumnAlignment(6,AlignHCenter);
367 369
368 mTodoListView->addColumn(i18n("Cancelled")); 370 mTodoListView->addColumn(i18n("Cancelled"));
369 mTodoListView->addColumn(i18n("Categories")); 371 mTodoListView->addColumn(i18n("Categories"));
370#if 0 372#if 0
371 mTodoListView->addColumn(i18n("Sort Id")); 373 mTodoListView->addColumn(i18n("Sort Id"));
372 mTodoListView->setColumnAlignment(4,AlignHCenter); 374 mTodoListView->setColumnAlignment(4,AlignHCenter);
373#endif 375#endif
374 376
375 mTodoListView->setMinimumHeight( 60 ); 377 mTodoListView->setMinimumHeight( 60 );
376 mTodoListView->setItemsRenameable( true ); 378 mTodoListView->setItemsRenameable( true );
377 mTodoListView->setRenameable( 0 ); 379 mTodoListView->setRenameable( 0 );
378 mTodoListView->setColumnWidth( 0, 120 ); 380 mTodoListView->setColumnWidth( 0, 120 );
379 mTodoListView->setColumnWidthMode(0, QListView::Manual); 381 mTodoListView->setColumnWidthMode(0, QListView::Manual);
380 mTodoListView->setColumnWidthMode(1, QListView::Manual); 382 mTodoListView->setColumnWidthMode(1, QListView::Manual);
381 mTodoListView->setColumnWidthMode(2, QListView::Manual); 383 mTodoListView->setColumnWidthMode(2, QListView::Manual);
382 mTodoListView->setColumnWidthMode(3, QListView::Manual); 384 mTodoListView->setColumnWidthMode(3, QListView::Manual);
383 mTodoListView->setColumnWidthMode(4, QListView::Manual); 385 mTodoListView->setColumnWidthMode(4, QListView::Manual);
384 mTodoListView->setColumnWidthMode(5, QListView::Manual); 386 mTodoListView->setColumnWidthMode(5, QListView::Manual);
385 mTodoListView->setColumnWidthMode(6, QListView::Manual); 387 mTodoListView->setColumnWidthMode(6, QListView::Manual);
386 mTodoListView->setColumnWidthMode(7, QListView::Manual); 388 mTodoListView->setColumnWidthMode(7, QListView::Manual);
387 mTodoListView->setColumnWidthMode(8, QListView::Manual); 389 mTodoListView->setColumnWidthMode(8, QListView::Manual);
388 390
389 391
390 mPriorityPopupMenu = new QPopupMenu(this); 392 mPriorityPopupMenu = new QPopupMenu(this);
391 for (int i = 1; i <= 5; i++) { 393 for (int i = 1; i <= 5; i++) {
392 QString label = QString ("%1").arg (i); 394 QString label = QString ("%1").arg (i);
393 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 395 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
394 } 396 }
395 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 397 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
396 398
397 mPercentageCompletedPopupMenu = new QPopupMenu(this); 399 mPercentageCompletedPopupMenu = new QPopupMenu(this);
398 for (int i = 0; i <= 100; i+=20) { 400 for (int i = 0; i <= 100; i+=20) {
399 QString label = QString ("%1 %").arg (i); 401 QString label = QString ("%1 %").arg (i);
400 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 402 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
401 } 403 }
402 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 404 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
403 405
404 406
405 407
406 mItemPopupMenu = new QPopupMenu(this); 408 mItemPopupMenu = new QPopupMenu(this);
407 mItemPopupMenu->insertItem(i18n("Show..."), this, 409 mItemPopupMenu->insertItem(i18n("Show..."), this,
408 SLOT (showTodo())); 410 SLOT (showTodo()));
409 mItemPopupMenu->insertItem(i18n("Edit..."), this, 411 mItemPopupMenu->insertItem(i18n("Edit..."), this,
410 SLOT (editTodo())); 412 SLOT (editTodo()));
411 mItemPopupMenu->insertItem( i18n("Delete"), this, 413 mItemPopupMenu->insertItem( i18n("Delete"), this,
412 SLOT (deleteTodo())); 414 SLOT (deleteTodo()));
413 mItemPopupMenu->insertItem( i18n("Clone..."), this, 415 mItemPopupMenu->insertItem( i18n("Clone..."), this,
414 SLOT (cloneTodo())); 416 SLOT (cloneTodo()));
415 mItemPopupMenu->insertItem( i18n("Move..."), this, 417 mItemPopupMenu->insertItem( i18n("Move..."), this,
416 SLOT (moveTodo())); 418 SLOT (moveTodo()));
417 mItemPopupMenu->insertItem( i18n("Beam..."), this, 419 mItemPopupMenu->insertItem( i18n("Beam..."), this,
418 SLOT (beamTodo())); 420 SLOT (beamTodo()));
419 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 421 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
420 SLOT (cancelTodo())); 422 SLOT (cancelTodo()));
421 mItemPopupMenu->insertSeparator(); 423 mItemPopupMenu->insertSeparator();
422 424
423 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 425 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
424 SLOT (newTodo())); 426 SLOT (newTodo()));
425 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 427 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
426 SLOT (newSubTodo())); 428 SLOT (newSubTodo()));
427 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 429 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
428 SLOT (unparentTodo()),0,21); 430 SLOT (unparentTodo()),0,21);
429 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 431 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
430 SLOT (reparentTodo()),0,22); 432 SLOT (reparentTodo()),0,22);
431 mItemPopupMenu->insertSeparator(); 433 mItemPopupMenu->insertSeparator();
432#if 0 434#if 0
433 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 435 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
434 this, SLOT( purgeCompleted() ) ); 436 this, SLOT( purgeCompleted() ) );
435 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 437 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
436 this, SLOT( toggleCompleted() ),0, 33 ); 438 this, SLOT( toggleCompleted() ),0, 33 );
437 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 439 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
438 this, SLOT( toggleQuickTodo() ),0, 34 ); 440 this, SLOT( toggleQuickTodo() ),0, 34 );
439 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 441 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
440 this, SLOT( toggleRunning() ),0, 35 ); 442 this, SLOT( toggleRunning() ),0, 35 );
441 443
442#endif 444#endif
443 mPopupMenu = new QPopupMenu(this); 445 mPopupMenu = new QPopupMenu(this);
444 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 446 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
445 SLOT (newTodo()),0,1); 447 SLOT (newTodo()),0,1);
446 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 448 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
447 this, SLOT(purgeCompleted()),0,2); 449 this, SLOT(purgeCompleted()),0,2);
448 mPopupMenu->insertItem(i18n("Show Completed"), 450 mPopupMenu->insertItem(i18n("Show Completed"),
449 this, SLOT( toggleCompleted() ),0,3 ); 451 this, SLOT( toggleCompleted() ),0,3 );
450 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 452 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
451 this, SLOT( toggleQuickTodo() ),0,4 ); 453 this, SLOT( toggleQuickTodo() ),0,4 );
452 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 454 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
453 this, SLOT( toggleRunning() ),0,5 ); 455 this, SLOT( toggleRunning() ),0,5 );
454 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 456 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
455 this, SLOT( setAllOpen() ),0,6 ); 457 this, SLOT( setAllOpen() ),0,6 );
456 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 458 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
457 this, SLOT( setAllClose() ),0,7 ); 459 this, SLOT( setAllClose() ),0,7 );
458 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 460 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
459 this, SLOT( setAllFlat() ),0,8 ); 461 this, SLOT( setAllFlat() ),0,8 );
460 mDocPrefs = new DocPrefs( name ); 462 mDocPrefs = new DocPrefs( name );
461 463
462 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 464 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
463 mPopupMenu->setCheckable( true ); 465 mPopupMenu->setCheckable( true );
464 mItemPopupMenu->setCheckable( true ); 466 mItemPopupMenu->setCheckable( true );
465 467
466 468
467 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 469 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
468 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 470 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
469 471
470 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 472 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
471 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 473 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
472 474
473 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 475 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
474 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 476 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
475 477
476 478
477 // Double clicking conflicts with opening/closing the subtree 479 // Double clicking conflicts with opening/closing the subtree
478 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 480 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
479 SLOT( editItem( QListViewItem *) ) ); 481 SLOT( editItem( QListViewItem *) ) );
480 /* 482 /*
481 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 483 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
482 const QPoint &,int ) ), 484 const QPoint &,int ) ),
483 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 485 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
484 */ 486 */
485 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 487 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
486 const QPoint &,int ) ), 488 const QPoint &,int ) ),
487 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 489 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
488 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 490 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
489 SLOT( itemClicked( QListViewItem * ) ) ); 491 SLOT( itemClicked( QListViewItem * ) ) );
490 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 492 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
491 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 493 SLOT( itemDoubleClicked( QListViewItem * ) ) );
492 connect( mTodoListView, SIGNAL( todoDropped( Todo * ) ), 494 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
493 SLOT( updateView() ) ); 495 SLOT( updateView() ) );
496 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
497 SLOT( todoModified(Todo *, int) ) );
494 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 498 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
495 SLOT( itemStateChanged( QListViewItem * ) ) ); 499 SLOT( itemStateChanged( QListViewItem * ) ) );
496 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 500 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
497 SLOT( itemStateChanged( QListViewItem * ) ) ); 501 SLOT( itemStateChanged( QListViewItem * ) ) );
498 502
499#if 0 503#if 0
500 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 504 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
501 SLOT(selectionChanged(QListViewItem *))); 505 SLOT(selectionChanged(QListViewItem *)));
502 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 506 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
503 SLOT(selectionChanged(QListViewItem *))); 507 SLOT(selectionChanged(QListViewItem *)));
504 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 508 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
505 SLOT(selectionChanged(QListViewItem *))); 509 SLOT(selectionChanged(QListViewItem *)));
506#endif 510#endif
511
512 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
513 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
514 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
515
507 connect( mTodoListView, SIGNAL(selectionChanged() ), 516 connect( mTodoListView, SIGNAL(selectionChanged() ),
508 SLOT( processSelectionChange() ) ); 517 SLOT( processSelectionChange() ) );
509 connect( mQuickAdd, SIGNAL( returnPressed () ), 518 connect( mQuickAdd, SIGNAL( returnPressed () ),
510 SLOT( addQuickTodo() ) ); 519 SLOT( addQuickTodo() ) );
511 520
512} 521}
513 522
514KOTodoView::~KOTodoView() 523KOTodoView::~KOTodoView()
515{ 524{
516 delete mDocPrefs; 525 delete mDocPrefs;
517} 526}
518 527
519void KOTodoView::jumpToDate () 528void KOTodoView::jumpToDate ()
520{ 529{
521 // if (mActiveItem) { 530 // if (mActiveItem) {
522// mActiveItem->todo()); 531// mActiveItem->todo());
523// if ( mActiveItem->todo()->hasDueDate() ) 532// if ( mActiveItem->todo()->hasDueDate() )
524// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 533// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
525} 534}
526 535
527void KOTodoView::updateView() 536void KOTodoView::updateView()
528{ 537{
529 pendingSubtodo = 0; 538 pendingSubtodo = 0;
530 if ( mBlockUpdate ) { 539 if ( mBlockUpdate ) {
531 //qDebug("blocked "); 540 //qDebug("blocked ");
532 return; 541 return;
533 } 542 }
534 if ( isFlatDisplay ) { 543 if ( isFlatDisplay ) {
535 setAllFlat(); 544 setAllFlat();
536 return; 545 return;
537 } 546 }
538 //qDebug("update "); 547 //qDebug("update ");
539// kdDebug() << "KOTodoView::updateView()" << endl; 548// kdDebug() << "KOTodoView::updateView()" << endl;
540 QFont fo = KOPrefs::instance()->mTodoViewFont; 549 QFont fo = KOPrefs::instance()->mTodoViewFont;
541 mTodoListView->clear(); 550 mTodoListView->clear();
542 if ( mName == "todolistsmall" ) { 551 if ( mName == "todolistsmall" ) {
543 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 552 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
544 int ps = fo.pointSize() -2; 553 int ps = fo.pointSize() -2;
545 if ( ps > 12 ) 554 if ( ps > 12 )
546 ps -= 2; 555 ps -= 2;
547 fo.setPointSize( ps ); 556 fo.setPointSize( ps );
548 } 557 }
549 } 558 }
550 559
551 mTodoListView->setFont( fo ); 560 mTodoListView->setFont( fo );
552 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 561 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
553 //mTodoListView->header()->setMaximumHeight(fm.height()); 562 //mTodoListView->header()->setMaximumHeight(fm.height());
554 QPtrList<Todo> todoList = calendar()->todos(); 563 QPtrList<Todo> todoList = calendar()->todos();
555 564
556/* 565/*
557 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 566 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
558 Event *t; 567 Event *t;
559 for(t = todoList.first(); t; t = todoList.next()) { 568 for(t = todoList.first(); t; t = todoList.next()) {
560 kdDebug() << " " << t->getSummary() << endl; 569 kdDebug() << " " << t->getSummary() << endl;
561 570
562 if (t->getRelatedTo()) { 571 if (t->getRelatedTo()) {
563 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 572 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
564 } 573 }
565 574
566 QPtrList<Event> l = t->getRelations(); 575 QPtrList<Event> l = t->getRelations();
567 Event *c; 576 Event *c;
568 for(c=l.first();c;c=l.next()) { 577 for(c=l.first();c;c=l.next()) {
569 kdDebug() << " - relation: " << c->getSummary() << endl; 578 kdDebug() << " - relation: " << c->getSummary() << endl;
570 } 579 }
571 } 580 }
572*/ 581*/
573 582
574 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 583 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
575 // specific order of events. That means that we have to generate parent items 584 // specific order of events. That means that we have to generate parent items
576 // recursively for proper hierarchical display of Todos. 585 // recursively for proper hierarchical display of Todos.
577 mTodoMap.clear(); 586 mTodoMap.clear();
578 Todo *todo; 587 Todo *todo;
579 todo = todoList.first();// todo; todo = todoList.next()) { 588 todo = todoList.first();// todo; todo = todoList.next()) {
580 while ( todo ) { 589 while ( todo ) {
581 bool next = true; 590 bool next = true;
582 // qDebug("todo %s ", todo->summary().latin1()); 591 // qDebug("todo %s ", todo->summary().latin1());
583 Incidence *incidence = todo->relatedTo(); 592 Incidence *incidence = todo->relatedTo();
584 while ( incidence ) { 593 while ( incidence ) {
585 if ( incidence->type() == "Todo") { 594 if ( incidence->type() == "Todo") {
586 //qDebug("related %s ",incidence->summary().latin1() ); 595 //qDebug("related %s ",incidence->summary().latin1() );
587 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 596 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
588 //qDebug("related not found "); 597 //qDebug("related not found ");
589 todoList.remove( ); 598 todoList.remove( );
590 todo = todoList.current(); 599 todo = todoList.current();
591 next = false; 600 next = false;
592 incidence = 0; 601 incidence = 0;
593 602
594 } else { 603 } else {
595 //qDebug("related found "); 604 //qDebug("related found ");
596 incidence = incidence->relatedTo(); 605 incidence = incidence->relatedTo();
597 } 606 }
598 } else 607 } else
599 incidence = 0; 608 incidence = 0;
600 } 609 }
601 if ( next ) 610 if ( next )
602 todo = todoList.next(); 611 todo = todoList.next();
603 } 612 }
604// qDebug("again .... "); 613// qDebug("again .... ");
605// for(todo = todoList.first(); todo; todo = todoList.next()) { 614// for(todo = todoList.first(); todo; todo = todoList.next()) {
606 615
607// qDebug("yytodo %s ", todo->summary().latin1()); 616// qDebug("yytodo %s ", todo->summary().latin1());
608// } 617// }
609 //qDebug("for "); 618 //qDebug("for ");
610 for(todo = todoList.first(); todo; todo = todoList.next()) { 619 for(todo = todoList.first(); todo; todo = todoList.next()) {
611 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 620 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
612 { 621 {
613 insertTodoItem(todo); 622 insertTodoItem(todo);
614 } 623 }
615 } 624 }
616 //qDebug("for end "); 625 //qDebug("for end ");
617 // Restore opened/closed state 626 // Restore opened/closed state
618 mTodoListView->blockSignals( true ); 627 mTodoListView->blockSignals( true );
619 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 628 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
620 mTodoListView->blockSignals( false ); 629 mTodoListView->blockSignals( false );
621 mTodoListView->setFocus(); 630 mTodoListView->setFocus();
622 processSelectionChange(); 631 processSelectionChange();
623} 632}
624 633
625bool KOTodoView::checkTodo( Todo * todo ) 634bool KOTodoView::checkTodo( Todo * todo )
626{ 635{
627 636
628 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 637 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
629 return false; 638 return false;
630 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 639 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
631 if ( todo->hasStartDate() ) 640 if ( todo->hasStartDate() )
632 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 641 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
633 return false; 642 return false;
634 if ( todo->hasDueDate() ) 643 if ( todo->hasDueDate() )
635 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 644 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
636 return false; 645 return false;
637 } 646 }
638 return true; 647 return true;
639} 648}
640 649
641void KOTodoView::restoreItemState( QListViewItem *item ) 650void KOTodoView::restoreItemState( QListViewItem *item )
642{ 651{
643 pendingSubtodo = 0; 652 pendingSubtodo = 0;
644 while( item ) { 653 while( item ) {
645 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 654 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
646 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 655 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
647 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 656 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
648 item = item->nextSibling(); 657 item = item->nextSibling();
649 } 658 }
650} 659}
651 660
652 661
653QMap<Todo *,KOTodoViewItem *>::ConstIterator 662QMap<Todo *,KOTodoViewItem *>::ConstIterator
654 KOTodoView::insertTodoItem(Todo *todo) 663 KOTodoView::insertTodoItem(Todo *todo)
655{ 664{
656 665
657// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 666// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
658 // TODO: Check, if dynmaic cast is necessary 667 // TODO: Check, if dynmaic cast is necessary
659 668
660 pendingSubtodo = 0; 669 pendingSubtodo = 0;
661 Incidence *incidence = todo->relatedTo(); 670 Incidence *incidence = todo->relatedTo();
662 if (incidence && incidence->type() == "Todo") { 671 if (incidence && incidence->type() == "Todo") {
663 Todo *relatedTodo = static_cast<Todo *>(incidence); 672 Todo *relatedTodo = static_cast<Todo *>(incidence);
664 673
665// kdDebug() << " has Related" << endl; 674// kdDebug() << " has Related" << endl;
666 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 675 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
667 itemIterator = mTodoMap.find(relatedTodo); 676 itemIterator = mTodoMap.find(relatedTodo);
668 if (itemIterator == mTodoMap.end()) { 677 if (itemIterator == mTodoMap.end()) {
669// kdDebug() << " related not yet in list" << endl; 678// kdDebug() << " related not yet in list" << endl;
670 itemIterator = insertTodoItem (relatedTodo); 679 itemIterator = insertTodoItem (relatedTodo);
671 } 680 }
672 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 681 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
673 // and one into the map. Sure finding is more easy but why? -zecke 682 // and one into the map. Sure finding is more easy but why? -zecke
674 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 683 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
675 return mTodoMap.insert(todo,todoItem); 684 return mTodoMap.insert(todo,todoItem);
676 } else { 685 } else {
677// kdDebug() << " no Related" << endl; 686// kdDebug() << " no Related" << endl;
678 // see above -zecke 687 // see above -zecke
679 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 688 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
680 return mTodoMap.insert(todo,todoItem); 689 return mTodoMap.insert(todo,todoItem);
681 } 690 }
682} 691}
683 692
684 693
685void KOTodoView::updateConfig() 694void KOTodoView::updateConfig()
686{ 695{
687 updateView(); 696 updateView();
688 mTodoListView->repaintContents(); 697 mTodoListView->repaintContents();
689} 698}
690 699
691QPtrList<Incidence> KOTodoView::selectedIncidences() 700QPtrList<Incidence> KOTodoView::selectedIncidences()
692{ 701{
693 QPtrList<Incidence> selected; 702 QPtrList<Incidence> selected;
694 703
695 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 704 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
696// if (!item) item = mActiveItem; 705// if (!item) item = mActiveItem;
697 if (item) selected.append(item->todo()); 706 if (item) selected.append(item->todo());
698 707
699 return selected; 708 return selected;
700} 709}
701 710
702QPtrList<Todo> KOTodoView::selectedTodos() 711QPtrList<Todo> KOTodoView::selectedTodos()
703{ 712{
704 QPtrList<Todo> selected; 713 QPtrList<Todo> selected;
705 714
706 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 715 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
707// if (!item) item = mActiveItem; 716// if (!item) item = mActiveItem;
708 if (item) selected.append(item->todo()); 717 if (item) selected.append(item->todo());
709 718
710 return selected; 719 return selected;
711} 720}
712 721
713void KOTodoView::changeEventDisplay(Event *, int) 722void KOTodoView::changeEventDisplay(Event *, int)
714{ 723{
715 updateView(); 724 updateView();
716} 725}
717 726
718void KOTodoView::showDates(const QDate &, const QDate &) 727void KOTodoView::showDates(const QDate &, const QDate &)
719{ 728{
720} 729}
721 730
722void KOTodoView::showEvents(QPtrList<Event>) 731void KOTodoView::showEvents(QPtrList<Event>)
723{ 732{
724 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 733 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
725} 734}
726 735
727void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 736void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
728 const QDate &td) 737 const QDate &td)
729{ 738{
730#ifndef KORG_NOPRINTER 739#ifndef KORG_NOPRINTER
731 calPrinter->preview(CalPrinter::Todolist, fd, td); 740 calPrinter->preview(CalPrinter::Todolist, fd, td);
732#endif 741#endif
733} 742}
734 743
735void KOTodoView::editItem(QListViewItem *item ) 744void KOTodoView::editItem(QListViewItem *item )
736{ 745{
737 // qDebug("editItem(QListViewItem *item ) "); 746 // qDebug("editItem(QListViewItem *item ) ");
738 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 747 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
739} 748}
740 749
741void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 750void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
742{ 751{
743 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 752 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
744} 753}
745 754
746void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column) 755void KOTodoView::popupMenu(QListViewItem *item,const QPoint &,int column)
747{ 756{
748 pendingSubtodo = 0; 757 pendingSubtodo = 0;
749 mActiveItem = (KOTodoViewItem *)item; 758 mActiveItem = (KOTodoViewItem *)item;
750 if (item) { 759 if (item) {
751 switch (column){ 760 switch (column){
752 case 1: 761 case 1:
753 mPriorityPopupMenu->popup(QCursor::pos ()); break; 762 mPriorityPopupMenu->popup(QCursor::pos ()); break;
754 case 2: 763 case 2:
755 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 764 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
756 case 3: 765 case 3:
757 moveTodo(); 766 moveTodo();
758 break; 767 break;
759 case 8: 768 case 8:
760 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 769 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
761 default: 770 default:
762 mItemPopupMenu->popup(QCursor::pos()); 771 mItemPopupMenu->popup(QCursor::pos());
763 } 772 }
764 } else mPopupMenu->popup(QCursor::pos()); 773 } else mPopupMenu->popup(QCursor::pos());
765} 774}
766void KOTodoView::newTodo() 775void KOTodoView::newTodo()
767{ 776{
768 emit newTodoSignal(); 777 emit newTodoSignal();
769} 778}
770 779
771void KOTodoView::newSubTodo() 780void KOTodoView::newSubTodo()
772{ 781{
773 if (mActiveItem) { 782 if (mActiveItem) {
774 emit newSubTodoSignal(mActiveItem->todo()); 783 emit newSubTodoSignal(mActiveItem->todo());
775 } 784 }
776} 785}
777void KOTodoView::unparentTodo() 786void KOTodoView::unparentTodo()
778{ 787{
779 if (mActiveItem) { 788 if (mActiveItem) {
780 emit unparentTodoSignal(mActiveItem->todo()); 789 emit unparentTodoSignal(mActiveItem->todo());
781 } 790 }
782} 791}
783 792
784void KOTodoView::reparentTodo() 793void KOTodoView::reparentTodo()
785{ 794{
786 if (mActiveItem) { 795 if (mActiveItem) {
787 qDebug("KOTodoView::reparentTodo() "); 796 qDebug("KOTodoView::reparentTodo() ");
788 topLevelWidget()->setCaption(i18n("Click on new parent item")); 797 topLevelWidget()->setCaption(i18n("Click on new parent item"));
789 pendingSubtodo = mActiveItem; 798 pendingSubtodo = mActiveItem;
790 } 799 }
791} 800}
792void KOTodoView::editTodo() 801void KOTodoView::editTodo()
793{ 802{
794 if (mActiveItem) { 803 if (mActiveItem) {
795 emit editTodoSignal(mActiveItem->todo()); 804 emit editTodoSignal(mActiveItem->todo());
796 } 805 }
797} 806}
798void KOTodoView::cloneTodo() 807void KOTodoView::cloneTodo()
799{ 808{
800 if (mActiveItem) { 809 if (mActiveItem) {
801 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 810 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
802 } 811 }
803} 812}
804void KOTodoView::cancelTodo() 813void KOTodoView::cancelTodo()
805{ 814{
806 if (mActiveItem) { 815 if (mActiveItem) {
807 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 816 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
808 } 817 }
809} 818}
810void KOTodoView::moveTodo() 819void KOTodoView::moveTodo()
811{ 820{
812 if (mActiveItem) { 821 if (mActiveItem) {
813 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 822 emit moveTodoSignal((Incidence*)mActiveItem->todo());
814 } 823 }
815} 824}
816void KOTodoView::beamTodo() 825void KOTodoView::beamTodo()
817{ 826{
818 if (mActiveItem) { 827 if (mActiveItem) {
819 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 828 emit beamTodoSignal((Incidence*)mActiveItem->todo());
820 } 829 }
821} 830}
822 831
823 832
824void KOTodoView::showTodo() 833void KOTodoView::showTodo()
825{ 834{
826 if (mActiveItem) { 835 if (mActiveItem) {
827 emit showTodoSignal(mActiveItem->todo()); 836 emit showTodoSignal(mActiveItem->todo());
828 } 837 }
829} 838}
830 839
831void KOTodoView::deleteTodo() 840void KOTodoView::deleteTodo()
832{ 841{
833 if (mActiveItem) { 842 if (mActiveItem) {
834 emit deleteTodoSignal(mActiveItem->todo()); 843 emit deleteTodoSignal(mActiveItem->todo());
835 } 844 }
836} 845}
837 846
838void KOTodoView::setNewPriority(int index) 847void KOTodoView::setNewPriority(int index)
839{ 848{
840 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 849 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
841 mActiveItem->todo()->setPriority(mPriority[index]); 850 mActiveItem->todo()->setPriority(mPriority[index]);
842 mActiveItem->construct(); 851 mActiveItem->construct();
843 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 852 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
844 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 853 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
845 } 854 }
846} 855}
847 856
848void KOTodoView::setNewPercentage(int index) 857void KOTodoView::setNewPercentage(int index)
849{ 858{
850 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 859 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
851 if (mPercentage[index] == 100) { 860 if (mPercentage[index] == 100) {
852 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 861 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
853 } else { 862 } else {
854 mActiveItem->todo()->setCompleted(false); 863 mActiveItem->todo()->setCompleted(false);
855 } 864 }
856 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 865 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
857 mActiveItem->construct(); 866 mActiveItem->construct();
858 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 867 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
859 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 868 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
860 } 869 }
861} 870}
862 871
863 872
864QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 873QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
865{ 874{
866 QPopupMenu* tempMenu = new QPopupMenu (this); 875 QPopupMenu* tempMenu = new QPopupMenu (this);
867 QStringList checkedCategories = todoItem->todo()->categories (); 876 QStringList checkedCategories = todoItem->todo()->categories ();
868 877
869 tempMenu->setCheckable (true); 878 tempMenu->setCheckable (true);
870 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 879 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
871 it != KOPrefs::instance()->mCustomCategories.end (); 880 it != KOPrefs::instance()->mCustomCategories.end ();
872 ++it) { 881 ++it) {
873 int index = tempMenu->insertItem (*it); 882 int index = tempMenu->insertItem (*it);
874 mCategory[index] = *it; 883 mCategory[index] = *it;
875 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 884 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
876 } 885 }
877 886
878 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 887 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
879 return tempMenu; 888 return tempMenu;
880 889
881 890
882} 891}
883void KOTodoView::changedCategories(int index) 892void KOTodoView::changedCategories(int index)
884{ 893{
885 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 894 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
886 QStringList categories = mActiveItem->todo()->categories (); 895 QStringList categories = mActiveItem->todo()->categories ();
887 if (categories.find (mCategory[index]) != categories.end ()) 896 if (categories.find (mCategory[index]) != categories.end ())
888 categories.remove (mCategory[index]); 897 categories.remove (mCategory[index]);
889 else 898 else
890 categories.insert (categories.end(), mCategory[index]); 899 categories.insert (categories.end(), mCategory[index]);
891 categories.sort (); 900 categories.sort ();
892 mActiveItem->todo()->setCategories (categories); 901 mActiveItem->todo()->setCategories (categories);
893 mActiveItem->construct(); 902 mActiveItem->construct();
894 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 903 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
895 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 904 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
896 } 905 }
897} 906}
898void KOTodoView::itemDoubleClicked(QListViewItem *item) 907void KOTodoView::itemDoubleClicked(QListViewItem *item)
899{ 908{
900 if ( pendingSubtodo != 0 ) { 909 if ( pendingSubtodo != 0 ) {
901 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 910 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
902 } 911 }
903 pendingSubtodo = 0; 912 pendingSubtodo = 0;
904 if (!item) { 913 if (!item) {
905 newTodo(); 914 newTodo();
906 return; 915 return;
907 } 916 }
908 if ( KOPrefs::instance()->mEditOnDoubleClick ) 917 if ( KOPrefs::instance()->mEditOnDoubleClick )
909 editItem( item ); 918 editItem( item );
910 else 919 else
911 showItem( item , QPoint(), 0 ); 920 showItem( item , QPoint(), 0 );
912} 921}
913void KOTodoView::itemClicked(QListViewItem *item) 922void KOTodoView::itemClicked(QListViewItem *item)
914{ 923{
915 924
916 if (!item) { 925 if (!item) {
917 if ( pendingSubtodo != 0 ) { 926 if ( pendingSubtodo != 0 ) {
918 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 927 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
919 } 928 }
920 pendingSubtodo = 0; 929 pendingSubtodo = 0;
921 return; 930 return;
922 } 931 }
923 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 932 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
924 if ( pendingSubtodo != 0 ) { 933 if ( pendingSubtodo != 0 ) {
925 bool allowReparent = true; 934 bool allowReparent = true;
926 QListViewItem *par = item; 935 QListViewItem *par = item;
927 while ( par ) { 936 while ( par ) {
928 if ( par == pendingSubtodo ) { 937 if ( par == pendingSubtodo ) {
929 allowReparent = false; 938 allowReparent = false;
930 break; 939 break;
931 } 940 }
932 par = par->parent(); 941 par = par->parent();
933 } 942 }
934 if ( !allowReparent ) { 943 if ( !allowReparent ) {
935 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 944 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
936 qDebug("Recursive reparenting not possible "); 945 qDebug("Recursive reparenting not possible ");
937 pendingSubtodo = 0; 946 pendingSubtodo = 0;
938 } else { 947 } else {
939 Todo* newParent = todoItem->todo(); 948 Todo* newParent = todoItem->todo();
940 Todo* newSub = pendingSubtodo->todo(); 949 Todo* newSub = pendingSubtodo->todo();
941 pendingSubtodo = 0; 950 pendingSubtodo = 0;
942 emit reparentTodoSignal( newParent,newSub ); 951 emit reparentTodoSignal( newParent,newSub );
943 return; 952 return;
944 } 953 }
945 } 954 }
946 int completed = todoItem->todo()->isCompleted(); // Completed or not? 955 int completed = todoItem->todo()->isCompleted(); // Completed or not?
947 956
948 if (todoItem->isOn()) { 957 if (todoItem->isOn()) {
949 if (!completed) { 958 if (!completed) {
950 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 959 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
951 } 960 }
952 } else { 961 } else {
953 if (completed) { 962 if (completed) {
954 todoItem->todo()->setCompleted(false); 963 todoItem->todo()->setCompleted(false);
955 } 964 }
956 } 965 }
957} 966}
958 967
959void KOTodoView::setDocumentId( const QString &id ) 968void KOTodoView::setDocumentId( const QString &id )
960{ 969{
961 kdDebug() << "KOTodoView::setDocumentId()" << endl; 970 kdDebug() << "KOTodoView::setDocumentId()" << endl;
962 971
963 mDocPrefs->setDoc( id ); 972 mDocPrefs->setDoc( id );
964} 973}
965 974
966void KOTodoView::itemStateChanged( QListViewItem *item ) 975void KOTodoView::itemStateChanged( QListViewItem *item )
967{ 976{
968 if (!item) return; 977 if (!item) return;
969 978
970 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 979 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
971 980
972// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 981// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
973 982
974 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 983 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
975} 984}
976 985
977void KOTodoView::saveLayout(KConfig *config, const QString &group) const 986void KOTodoView::saveLayout(KConfig *config, const QString &group) const
978{ 987{
979 mTodoListView->saveLayout(config,group); 988 mTodoListView->saveLayout(config,group);
980} 989}
981 990
982void KOTodoView::restoreLayout(KConfig *config, const QString &group) 991void KOTodoView::restoreLayout(KConfig *config, const QString &group)
983{ 992{
984 mTodoListView->restoreLayout(config,group); 993 mTodoListView->restoreLayout(config,group);
985} 994}
986 995
987void KOTodoView::processSelectionChange() 996void KOTodoView::processSelectionChange()
988{ 997{
989// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 998// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
990 999
991 KOTodoViewItem *item = 1000 KOTodoViewItem *item =
992 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1001 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
993 1002
994 if ( !item ) { 1003 if ( !item ) {
995 emit incidenceSelected( 0 ); 1004 emit incidenceSelected( 0 );
996 } else { 1005 } else {
997 emit incidenceSelected( item->todo() ); 1006 emit incidenceSelected( item->todo() );
998 } 1007 }
999} 1008}
1000 1009
1001void KOTodoView::modified(bool b) 1010void KOTodoView::modified(bool b)
1002{ 1011{
1003 emit isModified(b); 1012 emit isModified(b);
1004} 1013}
1005void KOTodoView::setTodoModified( Todo* todo ) 1014void KOTodoView::setTodoModified( Todo* todo )
1006{ 1015{
1007 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1016 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1008} 1017}
1009void KOTodoView::clearSelection() 1018void KOTodoView::clearSelection()
1010{ 1019{
1011 mTodoListView->selectAll( false ); 1020 mTodoListView->selectAll( false );
1012} 1021}
1013void KOTodoView::setAllOpen() 1022void KOTodoView::setAllOpen()
1014{ 1023{
1015 if ( isFlatDisplay ) { 1024 if ( isFlatDisplay ) {
1016 isFlatDisplay = false; 1025 isFlatDisplay = false;
1017 mPopupMenu->setItemChecked( 8,false ); 1026 mPopupMenu->setItemChecked( 8,false );
1018 updateView(); 1027 updateView();
1019 } 1028 }
1020 setOpen(mTodoListView->firstChild(), true); 1029 setOpen(mTodoListView->firstChild(), true);
1021} 1030}
1022void KOTodoView::setAllClose() 1031void KOTodoView::setAllClose()
1023{ 1032{
1024 if ( isFlatDisplay ) { 1033 if ( isFlatDisplay ) {
1025 isFlatDisplay = false; 1034 isFlatDisplay = false;
1026 mPopupMenu->setItemChecked( 8,false ); 1035 mPopupMenu->setItemChecked( 8,false );
1027 updateView(); 1036 updateView();
1028 } 1037 }
1029 setOpen(mTodoListView->firstChild(), false); 1038 setOpen(mTodoListView->firstChild(), false);
1030} 1039}
1031void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1040void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1032{ 1041{
1033 1042
1034 while ( item ) { 1043 while ( item ) {
1035 setOpen( item->firstChild(), setOpenI ); 1044 setOpen( item->firstChild(), setOpenI );
1036 item->setOpen( setOpenI ); 1045 item->setOpen( setOpenI );
1037 item = item->nextSibling(); 1046 item = item->nextSibling();
1038 } 1047 }
1039} 1048}
1040 1049
1041void KOTodoView::setAllFlat() 1050void KOTodoView::setAllFlat()
1042{ 1051{
1043 if ( isFlatDisplay ) { 1052 if ( isFlatDisplay ) {
1044 isFlatDisplay = false; 1053 isFlatDisplay = false;
1045 mPopupMenu->setItemChecked( 8,false ); 1054 mPopupMenu->setItemChecked( 8,false );
1046 updateView(); 1055 updateView();
1047 return; 1056 return;
1048 } 1057 }
1049 pendingSubtodo = 0; 1058 pendingSubtodo = 0;
1050 if ( mBlockUpdate ) { 1059 if ( mBlockUpdate ) {
1051 return; 1060 return;
1052 } 1061 }
1053 mPopupMenu->setItemChecked( 8,true ); 1062 mPopupMenu->setItemChecked( 8,true );
1054 isFlatDisplay = true; 1063 isFlatDisplay = true;
1055 QPtrList<Todo> todoList = calendar()->todos(); 1064 QPtrList<Todo> todoList = calendar()->todos();
1056 mTodoMap.clear(); 1065 mTodoMap.clear();
1057 mTodoListView->clear(); 1066 mTodoListView->clear();
1058 Todo *todo; 1067 Todo *todo;
1059 for(todo = todoList.first(); todo; todo = todoList.next()) { 1068 for(todo = todoList.first(); todo; todo = todoList.next()) {
1060 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1069 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1061 mTodoMap.insert(todo,todoItem); 1070 mTodoMap.insert(todo,todoItem);
1062 } 1071 }
1063 mTodoListView->setFocus(); 1072 mTodoListView->setFocus();
1064 processSelectionChange(); 1073 processSelectionChange();
1065} 1074}
1066 1075
1067void KOTodoView::purgeCompleted() 1076void KOTodoView::purgeCompleted()
1068{ 1077{
1069 emit purgeCompletedSignal(); 1078 emit purgeCompletedSignal();
1070} 1079}
1071void KOTodoView::toggleQuickTodo() 1080void KOTodoView::toggleQuickTodo()
1072{ 1081{
1073 if ( mQuickAdd->isVisible() ) { 1082 if ( mQuickAdd->isVisible() ) {
1074 mQuickAdd->hide(); 1083 mQuickAdd->hide();
1075 KOPrefs::instance()->mEnableQuickTodo = false; 1084 KOPrefs::instance()->mEnableQuickTodo = false;
1076 } 1085 }
1077 else { 1086 else {
1078 mQuickAdd->show(); 1087 mQuickAdd->show();
1079 KOPrefs::instance()->mEnableQuickTodo = true; 1088 KOPrefs::instance()->mEnableQuickTodo = true;
1080 } 1089 }
1081 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1090 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1082 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1091 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1083} 1092}
1084 1093
1085void KOTodoView::toggleRunning() 1094void KOTodoView::toggleRunning()
1086{ 1095{
1087 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1096 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1088 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1097 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1089 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1098 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1090 updateView(); 1099 updateView();
1091} 1100}
1092 1101
1093void KOTodoView::toggleCompleted() 1102void KOTodoView::toggleCompleted()
1094{ 1103{
1095 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1104 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1096 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1105 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1097 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1106 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1098 updateView(); 1107 updateView();
1099} 1108}
1100 1109
1101void KOTodoView::addQuickTodo() 1110void KOTodoView::addQuickTodo()
1102{ 1111{
1103 Todo *todo = new Todo(); 1112 Todo *todo = new Todo();
1104 todo->setSummary(mQuickAdd->text()); 1113 todo->setSummary(mQuickAdd->text());
1105 todo->setOrganizer(KOPrefs::instance()->email()); 1114 todo->setOrganizer(KOPrefs::instance()->email());
1106 CalFilter * cf = mCalendar->filter(); 1115 CalFilter * cf = mCalendar->filter();
1107 if ( cf ) { 1116 if ( cf ) {
1108 if ( cf->isEnabled()&& cf->showCategories()) { 1117 if ( cf->isEnabled()&& cf->showCategories()) {
1109 todo->setCategories(cf->categoryList()); 1118 todo->setCategories(cf->categoryList());
1110 } 1119 }
1111 if ( cf->isEnabled() ) 1120 if ( cf->isEnabled() )
1112 todo->setSecrecy( cf->getSecrecy()); 1121 todo->setSecrecy( cf->getSecrecy());
1113 } 1122 }
1114 mCalendar->addTodo(todo); 1123 mCalendar->addTodo(todo);
1115 mQuickAdd->setText(""); 1124 mQuickAdd->setText("");
1116 todoModified (todo, KOGlobals::EVENTADDED ); 1125 todoModified (todo, KOGlobals::EVENTADDED );
1117 updateView(); 1126 updateView();
1118} 1127}
1119void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1128void KOTodoView::keyPressEvent ( QKeyEvent * e )
1120{ 1129{
1121 // e->ignore(); 1130 // e->ignore();
1122 //return; 1131 //return;
1123 //qDebug("KOTodoView::keyPressEvent "); 1132 //qDebug("KOTodoView::keyPressEvent ");
1124 switch ( e->key() ) { 1133 switch ( e->key() ) {
1125 case Qt::Key_Down: 1134 case Qt::Key_Down:
1126 case Qt::Key_Up: 1135 case Qt::Key_Up:
1127 QWidget::keyPressEvent ( e ); 1136 QWidget::keyPressEvent ( e );
1128 break; 1137 break;
1129 1138
1130 case Qt::Key_Q: 1139 case Qt::Key_Q:
1131 toggleQuickTodo(); 1140 toggleQuickTodo();
1132 break; 1141 break;
1133 case Qt::Key_U: 1142 case Qt::Key_U:
1134 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1143 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1135 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1144 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1136 unparentTodo(); 1145 unparentTodo();
1137 e->accept(); 1146 e->accept();
1138 } else 1147 } else
1139 e->ignore(); 1148 e->ignore();
1140 break; 1149 break;
1141 case Qt::Key_S: 1150 case Qt::Key_S:
1142 if ( e->state() == Qt::ControlButton ) { 1151 if ( e->state() == Qt::ControlButton ) {
1143 e->ignore(); 1152 e->ignore();
1144 break; 1153 break;
1145 } 1154 }
1146 if ( e->state() == Qt::ShiftButton ) { 1155 if ( e->state() == Qt::ShiftButton ) {
1147 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1156 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1148 reparentTodo(); 1157 reparentTodo();
1149 e->accept(); 1158 e->accept();
1150 } else 1159 } else
1151 e->ignore(); 1160 e->ignore();
1152 break; 1161 break;
1153 case Qt::Key_P: 1162 case Qt::Key_P:
1154 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1163 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1155 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1164 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1156 if ( pendingSubtodo ) 1165 if ( pendingSubtodo )
1157 itemClicked(mActiveItem); 1166 itemClicked(mActiveItem);
1158 e->accept(); 1167 e->accept();
1159 } else 1168 } else
1160 e->ignore(); 1169 e->ignore();
1161 break; 1170 break;
1162 case Qt::Key_Escape: 1171 case Qt::Key_Escape:
1163 if ( pendingSubtodo ) { 1172 if ( pendingSubtodo ) {
1164 itemClicked(0); 1173 itemClicked(0);
1165 e->accept(); 1174 e->accept();
1166 } else 1175 } else
1167 e->ignore(); 1176 e->ignore();
1168 break; 1177 break;
1169 default: 1178 default:
1170 e->ignore(); 1179 e->ignore();
1171 } 1180 }
1172 1181
1173 if ( true ) { 1182 if ( true ) {
1174 if ( e->key() == Qt::Key_I ) { 1183 if ( e->key() == Qt::Key_I ) {
1175 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1184 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1176 if ( cn ) { 1185 if ( cn ) {
1177 mActiveItem = cn; 1186 mActiveItem = cn;
1178 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1187 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1179 if ( ci ){ 1188 if ( ci ){
1180 showTodo(); 1189 showTodo();
1181 cn = (KOTodoViewItem*)cn->itemBelow(); 1190 cn = (KOTodoViewItem*)cn->itemBelow();
1182 if ( cn ) { 1191 if ( cn ) {
1183 mTodoListView->setCurrentItem ( cn ); 1192 mTodoListView->setCurrentItem ( cn );
1184 mTodoListView->ensureItemVisible ( cn ); 1193 mTodoListView->ensureItemVisible ( cn );
1185 } 1194 }
1186 1195
1187 } 1196 }
1188 } 1197 }
1189 e->accept(); 1198 e->accept();
1190 1199
1191 } 1200 }
1192 1201
1193 } 1202 }
1194 1203
1195} 1204}
1196void KOTodoView::updateTodo( Todo * t, int type ) 1205void KOTodoView::updateTodo( Todo * t, int type )
1197{ 1206{
1198 if ( mBlockUpdate) 1207 if ( mBlockUpdate)
1199 return; 1208 return;
1200 1209
1201 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1210 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1202 itemIterator = mTodoMap.find(t); 1211 itemIterator = mTodoMap.find(t);
1203 if (itemIterator != mTodoMap.end()) { 1212 if (itemIterator != mTodoMap.end()) {
1204 (*itemIterator)->construct(); 1213 (*itemIterator)->construct();
1205 } else { 1214 } else {
1206 if ( type == KOGlobals::EVENTADDED ) { 1215 if ( type == KOGlobals::EVENTADDED ) {
1207 insertTodoItem( t ); 1216 insertTodoItem( t );
1208 } 1217 }
1209 } 1218 }
1210 1219
1211} 1220}
1212 1221
1213void KOTodoView::todoModified(Todo * t , int p ) 1222void KOTodoView::todoModified(Todo * t , int p )
1214{ 1223{
1215 mBlockUpdate = true; 1224 mBlockUpdate = true;
1216 emit todoModifiedSignal ( t, p ); 1225 emit todoModifiedSignal ( t, p );
1217 mBlockUpdate = false; 1226 mBlockUpdate = false;
1218} 1227}
diff --git a/korganizer/kotodoview.h b/korganizer/kotodoview.h
index f11518d..68e29bb 100644
--- a/korganizer/kotodoview.h
+++ b/korganizer/kotodoview.h
@@ -1,244 +1,247 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000, 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000, 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#ifndef KOTODOVIEW_H 23#ifndef KOTODOVIEW_H
24#define KOTODOVIEW_H 24#define KOTODOVIEW_H
25 25
26#include <qfont.h> 26#include <qfont.h>
27#include <qfontmetrics.h> 27#include <qfontmetrics.h>
28#include <qlineedit.h> 28#include <qlineedit.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30#include <qstrlist.h> 30#include <qstrlist.h>
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qmap.h> 34#include <qmap.h>
35#include <qlistview.h> 35#include <qlistview.h>
36#include <klistview.h> 36#include <klistview.h>
37 37
38#include <libkcal/calendar.h> 38#include <libkcal/calendar.h>
39#include <libkcal/todo.h> 39#include <libkcal/todo.h>
40 40
41#include <korganizer/baseview.h> 41#include <korganizer/baseview.h>
42 42
43#include "kotodoviewitem.h" 43#include "kotodoviewitem.h"
44#include "koprefs.h" 44#include "koprefs.h"
45#include "koglobals.h" 45#include "koglobals.h"
46#include "datenavigator.h" 46#include "datenavigator.h"
47 47
48class QDragEnterEvent; 48class QDragEnterEvent;
49class QDragMoveEvent; 49class QDragMoveEvent;
50class QDragLeaveEvent; 50class QDragLeaveEvent;
51class QDropEvent; 51class QDropEvent;
52 52
53class DocPrefs; 53class DocPrefs;
54 54
55class KOTodoListView : public KListView 55class KOTodoListView : public KListView
56{ 56{
57 Q_OBJECT 57 Q_OBJECT
58 public: 58 public:
59 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0); 59 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0);
60 virtual ~KOTodoListView() {} 60 virtual ~KOTodoListView() {}
61 61
62 signals: 62 signals:
63 void todoDropped(Todo *); 63 void todoDropped(Todo *, int);
64 void double_Clicked(QListViewItem *item); 64 void double_Clicked(QListViewItem *item);
65 65 void reparentTodoSignal( Todo *,Todo * );
66 void unparentTodoSignal(Todo *);
67 void deleteTodo( Todo * );
66 protected: 68 protected:
67 void contentsDragEnterEvent(QDragEnterEvent *); 69 void contentsDragEnterEvent(QDragEnterEvent *);
68 void contentsDragMoveEvent(QDragMoveEvent *); 70 void contentsDragMoveEvent(QDragMoveEvent *);
69 void contentsDragLeaveEvent(QDragLeaveEvent *); 71 void contentsDragLeaveEvent(QDragLeaveEvent *);
70 void contentsDropEvent(QDropEvent *); 72 void contentsDropEvent(QDropEvent *);
71 73
72 void contentsMousePressEvent(QMouseEvent *); 74 void contentsMousePressEvent(QMouseEvent *);
73 void contentsMouseMoveEvent(QMouseEvent *); 75 void contentsMouseMoveEvent(QMouseEvent *);
74 void contentsMouseReleaseEvent(QMouseEvent *); 76 void contentsMouseReleaseEvent(QMouseEvent *);
75 void contentsMouseDoubleClickEvent(QMouseEvent *); 77 void contentsMouseDoubleClickEvent(QMouseEvent *);
76 78
77 private: 79 private:
80 bool internalDrop;
78 QString mName; 81 QString mName;
79 Calendar *mCalendar; 82 Calendar *mCalendar;
80 QPoint mPressPos; 83 QPoint mPressPos;
81 bool mMousePressed; 84 bool mMousePressed;
82 QListViewItem *mOldCurrent; 85 QListViewItem *mOldCurrent;
83 void keyPressEvent ( QKeyEvent * ) ; 86 void keyPressEvent ( QKeyEvent * ) ;
84}; 87};
85 88
86 89
87/** 90/**
88 This is the line-edit on top of the todoview for fast addition of new todos 91 This is the line-edit on top of the todoview for fast addition of new todos
89*/ 92*/
90class KOQuickTodo : public QLineEdit 93class KOQuickTodo : public QLineEdit
91{ 94{
92 public: 95 public:
93 KOQuickTodo(QWidget *parent=0); 96 KOQuickTodo(QWidget *parent=0);
94 protected: 97 protected:
95 void focusInEvent(QFocusEvent *ev); 98 void focusInEvent(QFocusEvent *ev);
96 void focusOutEvent(QFocusEvent *ev); 99 void focusOutEvent(QFocusEvent *ev);
97}; 100};
98 101
99 102
100/** 103/**
101 This class provides a multi-column list view of todo events. 104 This class provides a multi-column list view of todo events.
102 105
103 @short multi-column list view of todo events. 106 @short multi-column list view of todo events.
104 @author Cornelius Schumacher <schumacher@kde.org> 107 @author Cornelius Schumacher <schumacher@kde.org>
105*/ 108*/
106class KOTodoView : public KOrg::BaseView 109class KOTodoView : public KOrg::BaseView
107{ 110{
108 Q_OBJECT 111 Q_OBJECT
109 public: 112 public:
110 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 ); 113 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 );
111 ~KOTodoView(); 114 ~KOTodoView();
112 115
113 QPtrList<Incidence> selectedIncidences(); 116 QPtrList<Incidence> selectedIncidences();
114 QPtrList<Todo> selectedTodos(); 117 QPtrList<Todo> selectedTodos();
115 118
116 DateList selectedDates() 119 DateList selectedDates()
117 {DateList q; 120 {DateList q;
118 return q;} 121 return q;}
119 122
120 /** Return number of shown dates. TodoView does not show dates, */ 123 /** Return number of shown dates. TodoView does not show dates, */
121 int currentDateCount() { return 0; } 124 int currentDateCount() { return 0; }
122 125
123 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td); 126 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td);
124 127
125 void setDocumentId( const QString & ); 128 void setDocumentId( const QString & );
126 129
127 void saveLayout(KConfig *config, const QString &group) const; 130 void saveLayout(KConfig *config, const QString &group) const;
128 void restoreLayout(KConfig *config, const QString &group); 131 void restoreLayout(KConfig *config, const QString &group);
129 /** Create a popup menu to set categories */ 132 /** Create a popup menu to set categories */
130 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem); 133 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem);
131 void setNavigator( DateNavigator* nav ) {mNavigator = nav;} 134 void setNavigator( DateNavigator* nav ) {mNavigator = nav;}
132 135
133 public slots: 136 public slots:
134 void updateView(); 137 void updateView();
135 void updateConfig(); 138 void updateConfig();
136 139
137 void changeEventDisplay(Event *, int); 140 void changeEventDisplay(Event *, int);
138 141
139 void showDates(const QDate &start, const QDate &end); 142 void showDates(const QDate &start, const QDate &end);
140 void showEvents(QPtrList<Event> eventList); 143 void showEvents(QPtrList<Event> eventList);
141 144
142 void clearSelection(); 145 void clearSelection();
143 void jumpToDate (); 146 void jumpToDate ();
144 147
145 void editItem(QListViewItem *item); 148 void editItem(QListViewItem *item);
146 void showItem(QListViewItem *item,const QPoint &,int); 149 void showItem(QListViewItem *item,const QPoint &,int);
147 void popupMenu(QListViewItem *item,const QPoint &,int); 150 void popupMenu(QListViewItem *item,const QPoint &,int);
148 void newTodo(); 151 void newTodo();
149 void newSubTodo(); 152 void newSubTodo();
150 void unparentTodo(); 153 void unparentTodo();
151 void reparentTodo(); 154 void reparentTodo();
152 void showTodo(); 155 void showTodo();
153 void editTodo(); 156 void editTodo();
154 void cloneTodo(); 157 void cloneTodo();
155 void cancelTodo(); 158 void cancelTodo();
156 void moveTodo(); 159 void moveTodo();
157 void beamTodo(); 160 void beamTodo();
158 void deleteTodo(); 161 void deleteTodo();
159 162
160 void setNewPriority(int); 163 void setNewPriority(int);
161 void setNewPercentage(int); 164 void setNewPercentage(int);
162 void changedCategories(int); 165 void changedCategories(int);
163 166
164 void setAllOpen(); 167 void setAllOpen();
165 void setAllClose(); 168 void setAllClose();
166 void setAllFlat(); 169 void setAllFlat();
167 170
168 void purgeCompleted(); 171 void purgeCompleted();
169 void toggleCompleted(); 172 void toggleCompleted();
170 void toggleRunning(); 173 void toggleRunning();
171 void toggleQuickTodo(); 174 void toggleQuickTodo();
172 void updateTodo( Todo *, int ); 175 void updateTodo( Todo *, int );
173 176
174 void itemClicked(QListViewItem *); 177 void itemClicked(QListViewItem *);
175 void itemStateChanged(QListViewItem *); 178 void itemStateChanged(QListViewItem *);
176 void modified(bool); 179 void modified(bool);
177 void itemDoubleClicked(QListViewItem *item); 180 void itemDoubleClicked(QListViewItem *item);
178 181
179 signals: 182 signals:
180 void newTodoSignal(); 183 void newTodoSignal();
181 void newSubTodoSignal(Todo *); 184 void newSubTodoSignal(Todo *);
182 void unparentTodoSignal(Todo *); 185 void unparentTodoSignal(Todo *);
183 void reparentTodoSignal( Todo *,Todo * ); 186 void reparentTodoSignal( Todo *,Todo * );
184 void showTodoSignal(Todo *); 187 void showTodoSignal(Todo *);
185 188
186 void editTodoSignal(Todo *); 189 void editTodoSignal(Todo *);
187 void deleteTodoSignal(Todo *); 190 void deleteTodoSignal(Todo *);
188 void todoModifiedSignal (Todo *, int); 191 void todoModifiedSignal (Todo *, int);
189 192
190 void isModified(bool); 193 void isModified(bool);
191 void cloneTodoSignal( Incidence * ); 194 void cloneTodoSignal( Incidence * );
192 void cancelTodoSignal( Incidence * ); 195 void cancelTodoSignal( Incidence * );
193 void moveTodoSignal( Incidence * ); 196 void moveTodoSignal( Incidence * );
194 void beamTodoSignal( Incidence * ); 197 void beamTodoSignal( Incidence * );
195 void purgeCompletedSignal(); 198 void purgeCompletedSignal();
196 199
197 protected slots: 200 protected slots:
198 void processSelectionChange(); 201 void processSelectionChange();
199 void addQuickTodo(); 202 void addQuickTodo();
203 void setTodoModified( Todo* );
204 void todoModified(Todo *, int );
200 205
201 private: 206 private:
202 /* 207 /*
203 * the TodoEditor approach is rather unscaling in the long 208 * the TodoEditor approach is rather unscaling in the long
204 * run. 209 * run.
205 * Korganizer keeps it in memory and we need to update 210 * Korganizer keeps it in memory and we need to update
206 * 1. make KOTodoViewItem a QObject again? 211 * 1. make KOTodoViewItem a QObject again?
207 * 2. add a public method for setting one todo modified? 212 * 2. add a public method for setting one todo modified?
208 * 3. add a private method for setting a todo modified + friend here? 213 * 3. add a private method for setting a todo modified + friend here?
209 * -- zecke 2002-07-08 214 * -- zecke 2002-07-08
210 */ 215 */
211 friend class KOTodoViewItem; 216 friend class KOTodoViewItem;
212 void setTodoModified( Todo* );
213 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo); 217 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo);
214 void restoreItemState( QListViewItem * ); 218 void restoreItemState( QListViewItem * );
215 219
216 bool checkTodo( Todo * ); 220 bool checkTodo( Todo * );
217 bool isFlatDisplay; 221 bool isFlatDisplay;
218 void setOpen( QListViewItem*, bool setOpen); 222 void setOpen( QListViewItem*, bool setOpen);
219 KOTodoListView *mTodoListView; 223 KOTodoListView *mTodoListView;
220 QPopupMenu *mItemPopupMenu; 224 QPopupMenu *mItemPopupMenu;
221 QPopupMenu *mPopupMenu; 225 QPopupMenu *mPopupMenu;
222 QPopupMenu *mPriorityPopupMenu; 226 QPopupMenu *mPriorityPopupMenu;
223 QPopupMenu *mPercentageCompletedPopupMenu; 227 QPopupMenu *mPercentageCompletedPopupMenu;
224 QPopupMenu *mCategoryPopupMenu; 228 QPopupMenu *mCategoryPopupMenu;
225 229
226 QMap<int, int> mPercentage; 230 QMap<int, int> mPercentage;
227 QMap<int, int> mPriority; 231 QMap<int, int> mPriority;
228 QMap<int, QString> mCategory; 232 QMap<int, QString> mCategory;
229 KOTodoViewItem *mActiveItem; 233 KOTodoViewItem *mActiveItem;
230 234
231 QMap<Todo *,KOTodoViewItem *> mTodoMap; 235 QMap<Todo *,KOTodoViewItem *> mTodoMap;
232 QString mName; 236 QString mName;
233 237
234 DocPrefs *mDocPrefs; 238 DocPrefs *mDocPrefs;
235 QString mCurrentDoc; 239 QString mCurrentDoc;
236 KOQuickTodo *mQuickAdd; 240 KOQuickTodo *mQuickAdd;
237 bool mBlockUpdate; 241 bool mBlockUpdate;
238 void todoModified(Todo *, int );
239 void keyPressEvent ( QKeyEvent * ) ; 242 void keyPressEvent ( QKeyEvent * ) ;
240 KOTodoViewItem * pendingSubtodo; 243 KOTodoViewItem * pendingSubtodo;
241 DateNavigator* mNavigator; 244 DateNavigator* mNavigator;
242}; 245};
243 246
244#endif 247#endif
diff --git a/libkcal/dndfactory.cpp b/libkcal/dndfactory.cpp
new file mode 100644
index 0000000..cdcfae4
--- a/dev/null
+++ b/libkcal/dndfactory.cpp
@@ -0,0 +1,186 @@
1/*
2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brwon
4 Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
21*/
22
23#include <qapplication.h>
24#include <qclipboard.h>
25
26#include <kiconloader.h>
27#include <kdebug.h>
28#include <kmessagebox.h>
29#include <klocale.h>
30
31#include "vcaldrag.h"
32#include "icaldrag.h"
33#include "calendar.h"
34#include "vcalformat.h"
35#include "icalformat.h"
36#include "calendarlocal.h"
37
38#include "dndfactory.h"
39
40using namespace KCal;
41
42DndFactory::DndFactory( Calendar *cal ) :
43 mCalendar( cal )
44{
45}
46
47ICalDrag *DndFactory::createDrag( Incidence *incidence, QWidget *owner )
48{
49 CalendarLocal cal( mCalendar->timeZoneId() );
50 Incidence *i = incidence->clone();
51 cal.addIncidence( i );
52
53 ICalDrag *icd = new ICalDrag( &cal, owner );
54 if ( i->type() == "Event" )
55 icd->setPixmap( BarIcon( "appointment" ) );
56 else if ( i->type() == "Todo" )
57 icd->setPixmap( BarIcon( "todo" ) );
58
59 return icd;
60}
61
62Event *DndFactory::createDrop(QDropEvent *de)
63{
64 kdDebug(5800) << "DndFactory::createDrop()" << endl;
65
66 CalendarLocal cal( mCalendar->timeZoneId() );
67
68 if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) {
69 de->accept();
70
71 QPtrList<Event> events = cal.events();
72 if ( !events.isEmpty() ) {
73 Event *event = new Event( *events.first() );
74 return event;
75 }
76 }
77
78 return 0;
79}
80
81Todo *DndFactory::createDropTodo(QDropEvent *de)
82{
83 kdDebug(5800) << "VCalFormat::createDropTodo()" << endl;
84
85 CalendarLocal cal( mCalendar->timeZoneId() );
86
87 if ( ICalDrag::decode( de, &cal ) || VCalDrag::decode( de, &cal ) ) {
88 de->accept();
89
90 QPtrList<Todo> todos = cal.todos();
91 if ( !todos.isEmpty() ) {
92 Todo *todo = new Todo( *todos.first() );
93 return todo;
94 }
95 }
96
97 return 0;
98}
99
100
101void DndFactory::cutIncidence( Incidence *selectedInc )
102{
103 if ( copyIncidence( selectedInc ) ) {
104 mCalendar->deleteIncidence( selectedInc );
105 }
106}
107
108bool DndFactory::copyIncidence( Incidence *selectedInc )
109{
110 if ( !selectedInc )
111 return false;
112 QClipboard *cb = QApplication::clipboard();
113
114 CalendarLocal cal( mCalendar->timeZoneId() );
115 Incidence *inc = selectedInc->clone();
116 cal.addIncidence( inc );
117 cb->setData( new ICalDrag( &cal ) );
118
119 return true;
120}
121
122Incidence *DndFactory::pasteIncidence(const QDate &newDate, const QTime *newTime)
123{
124// kdDebug(5800) << "DnDFactory::pasteEvent()" << endl;
125
126 CalendarLocal cal( mCalendar->timeZoneId() );
127
128 QClipboard *cb = QApplication::clipboard();
129
130 if ( !ICalDrag::decode( cb->data(), &cal ) &&
131 !VCalDrag::decode( cb->data(), &cal ) ) {
132 kdDebug(5800) << "Can't parse clipboard" << endl;
133 return 0;
134 }
135
136 QPtrList<Incidence> incList = cal.incidences();
137 Incidence *inc = incList.first();
138
139 if ( !incList.isEmpty() && inc ) {
140 inc = inc->clone();
141
142 inc->recreate();
143
144 if ( inc->type() == "Event" ) {
145
146 Event *anEvent = static_cast<Event*>( inc );
147 // Calculate length of event
148 int daysOffset = anEvent->dtStart().date().daysTo(
149 anEvent->dtEnd().date() );
150 // new end date if event starts at the same time on the new day
151 QDateTime endDate( newDate.addDays(daysOffset), anEvent->dtEnd().time() );
152
153 if ( newTime ) {
154 // additional offset for new time of day
155 int addSecsOffset( anEvent->dtStart().time().secsTo( *newTime ));
156 endDate=endDate.addSecs( addSecsOffset );
157 anEvent->setDtStart( QDateTime( newDate, *newTime ) );
158 } else {
159 anEvent->setDtStart( QDateTime( newDate, anEvent->dtStart().time() ) );
160 }
161 anEvent->setDtEnd( endDate );
162
163 } else if ( inc->type() == "Todo" ) {
164 Todo *anTodo = static_cast<Todo*>( inc );
165 if ( newTime ) {
166 anTodo->setDtDue( QDateTime( newDate, *newTime ) );
167 } else {
168 anTodo->setDtDue( QDateTime( newDate, anTodo->dtDue().time() ) );
169 }
170 } else if ( inc->type() == "Journal" ) {
171 Journal *anJournal = static_cast<Journal*>( inc );
172 if ( newTime ) {
173 anJournal->setDtStart( QDateTime( newDate, *newTime ) );
174 } else {
175 anJournal->setDtStart( QDateTime( newDate ) );
176 }
177 } else {
178 kdDebug(5850) << "Trying to paste unknown incidence of type " << inc->type() << endl;
179 }
180
181 return inc;
182
183 }
184
185 return 0;
186}
diff --git a/libkcal/dndfactory.h b/libkcal/dndfactory.h
index 6b73f34..7e2ca04 100644
--- a/libkcal/dndfactory.h
+++ b/libkcal/dndfactory.h
@@ -1,62 +1,74 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3
3 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
6 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 7
6 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
10 12
11 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 16 Library General Public License for more details.
15 17
16 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
20*/ 22*/
21 23
22// $Id$
23
24#ifndef KCAL_DNDFACTORY_H 24#ifndef KCAL_DNDFACTORY_H
25#define KCAL_DNDFACTORY_H 25#define KCAL_DNDFACTORY_H
26 26
27#include "vcalformat.h" 27//#include "libkcal_export.h"
28
29class QDropEvent;
30 28
31namespace KCal { 29namespace KCal {
32 30
31class ICalDrag;
32class Event;
33class Todo;
34class Calendar;
35#define LIBKCAL_EXPORT
36
33/** 37/**
34 This class implements functions to create Drag and Drop objects used for 38 This class implements functions to create Drag and Drop objects used for
35 Drag-and-Drop and Copy-and-Paste. 39 Drag-and-Drop and Copy-and-Paste.
36 40
37 @short vCalendar Drag-and-Drop object factory. 41 @short vCalendar/iCalendar Drag-and-Drop object factory.
38*/ 42*/
39class DndFactory { 43class LIBKCAL_EXPORT DndFactory
44{
40 public: 45 public:
41 DndFactory( Calendar * ) {} 46 DndFactory( Calendar * );
47
48 /**
49 Create a drag object.
50 */
51 ICalDrag *createDrag( Incidence *incidence, QWidget *owner );
42 52
43 /** create an object to be used with the Xdnd Drag And Drop protocol. */
44 ICalDrag *createDrag(Event *, QWidget *) { return 0; }
45 /** create an object to be used with the Xdnd Drag And Drop protocol. */
46 ICalDrag *createDragTodo(Todo *, QWidget *) { return 0; }
47 /** Create Todo object from drop event */ 53 /** Create Todo object from drop event */
48 Todo *createDropTodo(QDropEvent *) { return 0; } 54 Todo *createDropTodo(QDropEvent *de);
49 /** Create Event object from drop event */ 55 /** Create Event object from drop event */
50 Event *createDrop(QDropEvent *) { return 0; } 56 Event *createDrop(QDropEvent *de);
51 57
52 /** cut event to clipboard */ 58 /** cut incidence to clipboard */
53 void cutEvent(Event *) {} 59 void cutIncidence( Incidence * );
54 /** cut, copy, and paste operations follow. */ 60 /** copy the incidence to clipboard */
55 bool copyEvent(Event *) { return false; } 61 bool copyIncidence( Incidence * );
56 /** pastes the event and returns a pointer to the new event pasted. */ 62 /** pastes the event or todo and returns a pointer to the new incidence pasted. */
57 Event *pasteEvent(const QDate &, const QTime *newTime = 0) { return 0; } 63 Incidence *pasteIncidence( const QDate &, const QTime *newTime = 0 );
64
65 private:
66 Calendar *mCalendar;
67
68 class Private;
69 Private *d;
58}; 70};
59 71
60} 72}
61 73
62#endif 74#endif
diff --git a/libkcal/dndfactory_dummy.h b/libkcal/dndfactory_dummy.h
new file mode 100644
index 0000000..6b73f34
--- a/dev/null
+++ b/libkcal/dndfactory_dummy.h
@@ -0,0 +1,62 @@
1/*
2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22// $Id$
23
24#ifndef KCAL_DNDFACTORY_H
25#define KCAL_DNDFACTORY_H
26
27#include "vcalformat.h"
28
29class QDropEvent;
30
31namespace KCal {
32
33/**
34 This class implements functions to create Drag and Drop objects used for
35 Drag-and-Drop and Copy-and-Paste.
36
37 @short vCalendar Drag-and-Drop object factory.
38*/
39class DndFactory {
40 public:
41 DndFactory( Calendar * ) {}
42
43 /** create an object to be used with the Xdnd Drag And Drop protocol. */
44 ICalDrag *createDrag(Event *, QWidget *) { return 0; }
45 /** create an object to be used with the Xdnd Drag And Drop protocol. */
46 ICalDrag *createDragTodo(Todo *, QWidget *) { return 0; }
47 /** Create Todo object from drop event */
48 Todo *createDropTodo(QDropEvent *) { return 0; }
49 /** Create Event object from drop event */
50 Event *createDrop(QDropEvent *) { return 0; }
51
52 /** cut event to clipboard */
53 void cutEvent(Event *) {}
54 /** cut, copy, and paste operations follow. */
55 bool copyEvent(Event *) { return false; }
56 /** pastes the event and returns a pointer to the new event pasted. */
57 Event *pasteEvent(const QDate &, const QTime *newTime = 0) { return 0; }
58};
59
60}
61
62#endif
diff --git a/libkcal/libkcal.pro b/libkcal/libkcal.pro
index 171c726..33c63c3 100644
--- a/libkcal/libkcal.pro
+++ b/libkcal/libkcal.pro
@@ -1,106 +1,108 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG += qt warn_on 2 CONFIG += qt warn_on
3 TARGET = microkcal 3 TARGET = microkcal
4 4
5include( ../variables.pri ) 5include( ../variables.pri )
6 6
7INCLUDEPATH += ../libkdepim ../microkde versit ../microkde/kdecore 7INCLUDEPATH += ../libkdepim ../microkde versit ../microkde/kdecore
8#../qtcompat 8#../qtcompat
9INCLUDEPATH += ../libical/src/libical 9INCLUDEPATH += ../libical/src/libical
10INCLUDEPATH += ../libical/src/libicalss 10INCLUDEPATH += ../libical/src/libicalss
11DESTDIR = ../bin 11DESTDIR = ../bin
12DEFINES += DESKTOP_VERSION 12DEFINES += DESKTOP_VERSION
13unix: { 13unix: {
14LIBS += ../libical/lib/libical.a 14LIBS += ../libical/lib/libical.a
15LIBS += ../libical/lib/libicalss.a 15LIBS += ../libical/lib/libicalss.a
16OBJECTS_DIR = obj/unix 16OBJECTS_DIR = obj/unix
17MOC_DIR = moc/unix 17MOC_DIR = moc/unix
18} 18}
19win32: { 19win32: {
20DEFINES += _WIN32_ 20DEFINES += _WIN32_
21 21
22LIBS += ../libical/lib/ical.lib 22LIBS += ../libical/lib/ical.lib
23LIBS += ../libical/lib/icalss.lib 23LIBS += ../libical/lib/icalss.lib
24OBJECTS_DIR = obj/win 24OBJECTS_DIR = obj/win
25MOC_DIR = moc/win 25MOC_DIR = moc/win
26 26
27} 27}
28 28
29INTERFACES = \ 29INTERFACES = \
30 30
31HEADERS = \ 31HEADERS = \
32 alarm.h \ 32 alarm.h \
33 attachment.h \ 33 attachment.h \
34 attendee.h \ 34 attendee.h \
35 calendar.h \ 35 calendar.h \
36 calendarlocal.h \ 36 calendarlocal.h \
37 calfilter.h \ 37 calfilter.h \
38 calformat.h \ 38 calformat.h \
39 calstorage.h \ 39 calstorage.h \
40 compat.h \ 40 compat.h \
41 customproperties.h \ 41 customproperties.h \
42 dummyscheduler.h \ 42 dummyscheduler.h \
43kincidenceformatter.h \ 43kincidenceformatter.h \
44 duration.h \ 44 duration.h \
45 event.h \ 45 event.h \
46 exceptions.h \ 46 exceptions.h \
47 filestorage.h \ 47 filestorage.h \
48 freebusy.h \ 48 freebusy.h \
49 icaldrag.h \ 49 icaldrag.h \
50 icalformat.h \ 50 icalformat.h \
51 icalformatimpl.h \ 51 icalformatimpl.h \
52 imipscheduler.h \ 52 imipscheduler.h \
53 incidence.h \ 53 incidence.h \
54 incidencebase.h \ 54 incidencebase.h \
55 journal.h \ 55 journal.h \
56 period.h \ 56 period.h \
57 person.h \ 57 person.h \
58 qtopiaformat.h \ 58 qtopiaformat.h \
59 recurrence.h \ 59 recurrence.h \
60 scheduler.h \ 60 scheduler.h \
61 todo.h \ 61 todo.h \
62dndfactory.h \
62 vcaldrag.h \ 63 vcaldrag.h \
63 vcalformat.h \ 64 vcalformat.h \
64 versit/port.h \ 65 versit/port.h \
65 versit/vcc.h \ 66 versit/vcc.h \
66 versit/vobject.h \ 67 versit/vobject.h \
67 phoneformat.h \ 68 phoneformat.h \
68 69
69 70
70 71
71SOURCES = \ 72SOURCES = \
72 alarm.cpp \ 73 alarm.cpp \
73 attachment.cpp \ 74 attachment.cpp \
74 attendee.cpp \ 75 attendee.cpp \
75 calendar.cpp \ 76 calendar.cpp \
76 calendarlocal.cpp \ 77 calendarlocal.cpp \
77 calfilter.cpp \ 78 calfilter.cpp \
78 calformat.cpp \ 79 calformat.cpp \
79 compat.cpp \ 80 compat.cpp \
80 customproperties.cpp \ 81 customproperties.cpp \
81 dummyscheduler.cpp \ 82 dummyscheduler.cpp \
82 kincidenceformatter.cpp \ 83 kincidenceformatter.cpp \
83 duration.cpp \ 84 duration.cpp \
84 event.cpp \ 85 event.cpp \
85 exceptions.cpp \ 86 exceptions.cpp \
86 filestorage.cpp \ 87 filestorage.cpp \
87 freebusy.cpp \ 88 freebusy.cpp \
88 icaldrag.cpp \ 89 icaldrag.cpp \
89 icalformat.cpp \ 90 icalformat.cpp \
90 icalformatimpl.cpp \ 91 icalformatimpl.cpp \
91 imipscheduler.cpp \ 92 imipscheduler.cpp \
92 incidence.cpp \ 93 incidence.cpp \
93 incidencebase.cpp \ 94 incidencebase.cpp \
94 journal.cpp \ 95 journal.cpp \
95 period.cpp \ 96 period.cpp \
96 person.cpp \ 97 person.cpp \
97 qtopiaformat.cpp \ 98 qtopiaformat.cpp \
98 recurrence.cpp \ 99 recurrence.cpp \
99 scheduler.cpp \ 100 scheduler.cpp \
100 todo.cpp \ 101 todo.cpp \
102dndfactory.cpp \
101 vcaldrag.cpp \ 103 vcaldrag.cpp \
102 vcalformat.cpp \ 104 vcalformat.cpp \
103 versit/vcc.c \ 105 versit/vcc.c \
104 versit/vobject.c \ 106 versit/vobject.c \
105 phoneformat.cpp \ 107 phoneformat.cpp \
106 108