-rw-r--r-- | libkcal/incidence.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 549014e..39c14f5 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,158 +1,165 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = 0;//new Recurrence(this); | 36 | mRecurrence = 0;//new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 43 | mHoliday = false; |
44 | mBirthday = false; | 44 | mBirthday = false; |
45 | mAnniversary = false; | 45 | mAnniversary = false; |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 50 | { |
51 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
62 | mAttachments = i.mAttachments; | 62 | QPtrListIterator<Attachment> itat( i.mAttachments ); |
63 | Attachment *at; | ||
64 | while( (at = itat.current()) ) { | ||
65 | Attachment *a = new Attachment( *at ); | ||
66 | mAttachments.append( a ); | ||
67 | ++itat; | ||
68 | } | ||
69 | mAttachments.setAutoDelete( true ); | ||
63 | mResources = i.mResources; | 70 | mResources = i.mResources; |
64 | mSecrecy = i.mSecrecy; | 71 | mSecrecy = i.mSecrecy; |
65 | mPriority = i.mPriority; | 72 | mPriority = i.mPriority; |
66 | mLocation = i.mLocation; | 73 | mLocation = i.mLocation; |
67 | mCancelled = i.mCancelled; | 74 | mCancelled = i.mCancelled; |
68 | mHasStartDate = i.mHasStartDate; | 75 | mHasStartDate = i.mHasStartDate; |
69 | QPtrListIterator<Alarm> it( i.mAlarms ); | 76 | QPtrListIterator<Alarm> it( i.mAlarms ); |
70 | const Alarm *a; | 77 | const Alarm *a; |
71 | while( (a = it.current()) ) { | 78 | while( (a = it.current()) ) { |
72 | Alarm *b = new Alarm( *a ); | 79 | Alarm *b = new Alarm( *a ); |
73 | b->setParent( this ); | 80 | b->setParent( this ); |
74 | mAlarms.append( b ); | 81 | mAlarms.append( b ); |
75 | 82 | ||
76 | ++it; | 83 | ++it; |
77 | } | 84 | } |
78 | mAlarms.setAutoDelete(true); | 85 | mAlarms.setAutoDelete(true); |
79 | mHasRecurrenceID = i.mHasRecurrenceID; | 86 | mHasRecurrenceID = i.mHasRecurrenceID; |
80 | mRecurrenceID = i.mRecurrenceID; | 87 | mRecurrenceID = i.mRecurrenceID; |
81 | if ( i.mRecurrence ) | 88 | if ( i.mRecurrence ) |
82 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 89 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
83 | else | 90 | else |
84 | mRecurrence = 0; | 91 | mRecurrence = 0; |
85 | mHoliday = i.mHoliday ; | 92 | mHoliday = i.mHoliday ; |
86 | mBirthday = i.mBirthday; | 93 | mBirthday = i.mBirthday; |
87 | mAnniversary = i.mAnniversary; | 94 | mAnniversary = i.mAnniversary; |
88 | } | 95 | } |
89 | 96 | ||
90 | Incidence::~Incidence() | 97 | Incidence::~Incidence() |
91 | { | 98 | { |
92 | 99 | ||
93 | Incidence *ev; | 100 | Incidence *ev; |
94 | QPtrList<Incidence> Relations = relations(); | 101 | QPtrList<Incidence> Relations = relations(); |
95 | for (ev=Relations.first();ev;ev=Relations.next()) { | 102 | for (ev=Relations.first();ev;ev=Relations.next()) { |
96 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 103 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
97 | } | 104 | } |
98 | if (relatedTo()) relatedTo()->removeRelation(this); | 105 | if (relatedTo()) relatedTo()->removeRelation(this); |
99 | if ( mRecurrence ) | 106 | if ( mRecurrence ) |
100 | delete mRecurrence; | 107 | delete mRecurrence; |
101 | 108 | ||
102 | } | 109 | } |
103 | QString Incidence::durationText() | 110 | QString Incidence::durationText() |
104 | { | 111 | { |
105 | return "---"; | 112 | return "---"; |
106 | } | 113 | } |
107 | QString Incidence::durationText4Time( int offset ) | 114 | QString Incidence::durationText4Time( int offset ) |
108 | { | 115 | { |
109 | int min = offset/60; | 116 | int min = offset/60; |
110 | int hours = min /60; | 117 | int hours = min /60; |
111 | min = min % 60; | 118 | min = min % 60; |
112 | int days = hours /24; | 119 | int days = hours /24; |
113 | hours = hours % 24; | 120 | hours = hours % 24; |
114 | 121 | ||
115 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { | 122 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { |
116 | if ( days == 1 ) | 123 | if ( days == 1 ) |
117 | return "1" + i18n(" day"); | 124 | return "1" + i18n(" day"); |
118 | else | 125 | else |
119 | return QString::number( days )+ i18n(" days"); | 126 | return QString::number( days )+ i18n(" days"); |
120 | 127 | ||
121 | } | 128 | } |
122 | QString message = QString::number ( hours ) +":"; | 129 | QString message = QString::number ( hours ) +":"; |
123 | if ( min < 10 ) message += "0"; | 130 | if ( min < 10 ) message += "0"; |
124 | message += QString::number ( min ); | 131 | message += QString::number ( min ); |
125 | if ( days > 0 ) { | 132 | if ( days > 0 ) { |
126 | if ( days == 1 ) | 133 | if ( days == 1 ) |
127 | message = "1" + i18n(" day") + " "+message; | 134 | message = "1" + i18n(" day") + " "+message; |
128 | else | 135 | else |
129 | message = QString::number( days )+ i18n(" days") + " "+message; | 136 | message = QString::number( days )+ i18n(" days") + " "+message; |
130 | } | 137 | } |
131 | return message; | 138 | return message; |
132 | } | 139 | } |
133 | bool Incidence::isHoliday() const | 140 | bool Incidence::isHoliday() const |
134 | { | 141 | { |
135 | return mHoliday; | 142 | return mHoliday; |
136 | } | 143 | } |
137 | bool Incidence::isBirthday() const | 144 | bool Incidence::isBirthday() const |
138 | { | 145 | { |
139 | 146 | ||
140 | return mBirthday ; | 147 | return mBirthday ; |
141 | } | 148 | } |
142 | bool Incidence::isAnniversary() const | 149 | bool Incidence::isAnniversary() const |
143 | { | 150 | { |
144 | return mAnniversary ; | 151 | return mAnniversary ; |
145 | 152 | ||
146 | } | 153 | } |
147 | 154 | ||
148 | bool Incidence::hasRecurrenceID() const | 155 | bool Incidence::hasRecurrenceID() const |
149 | { | 156 | { |
150 | return mHasRecurrenceID; | 157 | return mHasRecurrenceID; |
151 | } | 158 | } |
152 | 159 | ||
153 | void Incidence::setHasRecurrenceID( bool b ) | 160 | void Incidence::setHasRecurrenceID( bool b ) |
154 | { | 161 | { |
155 | mHasRecurrenceID = b; | 162 | mHasRecurrenceID = b; |
156 | } | 163 | } |
157 | 164 | ||
158 | void Incidence::setRecurrenceID(QDateTime d) | 165 | void Incidence::setRecurrenceID(QDateTime d) |
@@ -664,182 +671,183 @@ int Incidence::priority() const | |||
664 | { | 671 | { |
665 | return mPriority; | 672 | return mPriority; |
666 | } | 673 | } |
667 | 674 | ||
668 | void Incidence::setSecrecy(int sec) | 675 | void Incidence::setSecrecy(int sec) |
669 | { | 676 | { |
670 | if (mReadOnly) return; | 677 | if (mReadOnly) return; |
671 | mSecrecy = sec; | 678 | mSecrecy = sec; |
672 | updated(); | 679 | updated(); |
673 | } | 680 | } |
674 | 681 | ||
675 | int Incidence::secrecy() const | 682 | int Incidence::secrecy() const |
676 | { | 683 | { |
677 | return mSecrecy; | 684 | return mSecrecy; |
678 | } | 685 | } |
679 | 686 | ||
680 | QString Incidence::secrecyStr() const | 687 | QString Incidence::secrecyStr() const |
681 | { | 688 | { |
682 | return secrecyName(mSecrecy); | 689 | return secrecyName(mSecrecy); |
683 | } | 690 | } |
684 | 691 | ||
685 | QString Incidence::secrecyName(int secrecy) | 692 | QString Incidence::secrecyName(int secrecy) |
686 | { | 693 | { |
687 | switch (secrecy) { | 694 | switch (secrecy) { |
688 | case SecrecyPublic: | 695 | case SecrecyPublic: |
689 | return i18n("Public"); | 696 | return i18n("Public"); |
690 | break; | 697 | break; |
691 | case SecrecyPrivate: | 698 | case SecrecyPrivate: |
692 | return i18n("Private"); | 699 | return i18n("Private"); |
693 | break; | 700 | break; |
694 | case SecrecyConfidential: | 701 | case SecrecyConfidential: |
695 | return i18n("Confidential"); | 702 | return i18n("Confidential"); |
696 | break; | 703 | break; |
697 | default: | 704 | default: |
698 | return i18n("Undefined"); | 705 | return i18n("Undefined"); |
699 | break; | 706 | break; |
700 | } | 707 | } |
701 | } | 708 | } |
702 | 709 | ||
703 | QStringList Incidence::secrecyList() | 710 | QStringList Incidence::secrecyList() |
704 | { | 711 | { |
705 | QStringList list; | 712 | QStringList list; |
706 | list << secrecyName(SecrecyPublic); | 713 | list << secrecyName(SecrecyPublic); |
707 | list << secrecyName(SecrecyPrivate); | 714 | list << secrecyName(SecrecyPrivate); |
708 | list << secrecyName(SecrecyConfidential); | 715 | list << secrecyName(SecrecyConfidential); |
709 | 716 | ||
710 | return list; | 717 | return list; |
711 | } | 718 | } |
712 | 719 | ||
713 | 720 | ||
714 | QPtrList<Alarm> Incidence::alarms() const | 721 | QPtrList<Alarm> Incidence::alarms() const |
715 | { | 722 | { |
716 | return mAlarms; | 723 | return mAlarms; |
717 | } | 724 | } |
718 | 725 | ||
719 | Alarm* Incidence::newAlarm() | 726 | Alarm* Incidence::newAlarm() |
720 | { | 727 | { |
721 | Alarm* alarm = new Alarm(this); | 728 | Alarm* alarm = new Alarm(this); |
722 | mAlarms.append(alarm); | 729 | mAlarms.append(alarm); |
723 | // updated(); | 730 | // updated(); |
724 | return alarm; | 731 | return alarm; |
725 | } | 732 | } |
726 | 733 | ||
727 | void Incidence::addAlarm(Alarm *alarm) | 734 | void Incidence::addAlarm(Alarm *alarm) |
728 | { | 735 | { |
729 | mAlarms.append(alarm); | 736 | mAlarms.append(alarm); |
730 | updated(); | 737 | updated(); |
731 | } | 738 | } |
732 | 739 | ||
733 | void Incidence::removeAlarm(Alarm *alarm) | 740 | void Incidence::removeAlarm(Alarm *alarm) |
734 | { | 741 | { |
735 | mAlarms.removeRef(alarm); | 742 | mAlarms.removeRef(alarm); |
736 | updated(); | 743 | updated(); |
737 | } | 744 | } |
738 | 745 | ||
739 | void Incidence::clearAlarms() | 746 | void Incidence::clearAlarms() |
740 | { | 747 | { |
741 | mAlarms.clear(); | 748 | mAlarms.clear(); |
742 | updated(); | 749 | updated(); |
743 | } | 750 | } |
744 | 751 | ||
745 | bool Incidence::isAlarmEnabled() const | 752 | bool Incidence::isAlarmEnabled() const |
746 | { | 753 | { |
747 | Alarm* alarm; | 754 | Alarm* alarm; |
748 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 755 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
749 | if (alarm->enabled()) | 756 | if (alarm->enabled()) |
750 | return true; | 757 | return true; |
751 | } | 758 | } |
752 | return false; | 759 | return false; |
753 | } | 760 | } |
754 | #include <stdlib.h> | 761 | #include <stdlib.h> |
755 | Recurrence *Incidence::recurrence() | 762 | Recurrence *Incidence::recurrence() |
756 | { | 763 | { |
757 | if ( ! mRecurrence ) { | 764 | if ( ! mRecurrence ) { |
758 | mRecurrence = new Recurrence(this); | 765 | mRecurrence = new Recurrence(this); |
759 | mRecurrence->setRecurStart( dtStart() ); | 766 | mRecurrence->setRecurStart( dtStart() ); |
767 | mRecurrence->setRecurReadOnly( isReadOnly()); | ||
760 | //qDebug("creating new recurence "); | 768 | //qDebug("creating new recurence "); |
761 | //abort(); | 769 | //abort(); |
762 | } | 770 | } |
763 | return mRecurrence; | 771 | return mRecurrence; |
764 | } | 772 | } |
765 | void Incidence::setRecurrence( Recurrence * r) | 773 | void Incidence::setRecurrence( Recurrence * r) |
766 | { | 774 | { |
767 | if ( mRecurrence ) | 775 | if ( mRecurrence ) |
768 | delete mRecurrence; | 776 | delete mRecurrence; |
769 | mRecurrence = r; | 777 | mRecurrence = r; |
770 | } | 778 | } |
771 | 779 | ||
772 | void Incidence::setLocation(const QString &location) | 780 | void Incidence::setLocation(const QString &location) |
773 | { | 781 | { |
774 | if (mReadOnly) return; | 782 | if (mReadOnly) return; |
775 | mLocation = location; | 783 | mLocation = location; |
776 | updated(); | 784 | updated(); |
777 | } | 785 | } |
778 | 786 | ||
779 | QString Incidence::location() const | 787 | QString Incidence::location() const |
780 | { | 788 | { |
781 | return mLocation; | 789 | return mLocation; |
782 | } | 790 | } |
783 | QString Incidence::recurrenceText() const | 791 | QString Incidence::recurrenceText() const |
784 | { | 792 | { |
785 | if ( mRecurrence ) return mRecurrence->recurrenceText(); | 793 | if ( mRecurrence ) return mRecurrence->recurrenceText(); |
786 | return i18n("No"); | 794 | return i18n("No"); |
787 | } | 795 | } |
788 | 796 | ||
789 | ushort Incidence::doesRecur() const | 797 | ushort Incidence::doesRecur() const |
790 | { | 798 | { |
791 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 799 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
792 | else return Recurrence::rNone; | 800 | else return Recurrence::rNone; |
793 | } | 801 | } |
794 | 802 | ||
795 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 803 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
796 | { | 804 | { |
797 | QDateTime incidenceStart = dt; | 805 | QDateTime incidenceStart = dt; |
798 | *ok = false; | 806 | *ok = false; |
799 | if ( doesRecur() ) { | 807 | if ( doesRecur() ) { |
800 | bool last; | 808 | bool last; |
801 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); | 809 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); |
802 | int count = 0; | 810 | int count = 0; |
803 | if ( !last ) { | 811 | if ( !last ) { |
804 | while ( !last ) { | 812 | while ( !last ) { |
805 | ++count; | 813 | ++count; |
806 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); | 814 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); |
807 | if ( recursOn( incidenceStart.date() ) ) { | 815 | if ( recursOn( incidenceStart.date() ) ) { |
808 | last = true; // exit while llop | 816 | last = true; // exit while llop |
809 | } else { | 817 | } else { |
810 | if ( last ) { // no alarm on last recurrence | 818 | if ( last ) { // no alarm on last recurrence |
811 | return QDateTime (); | 819 | return QDateTime (); |
812 | } | 820 | } |
813 | int year = incidenceStart.date().year(); | 821 | int year = incidenceStart.date().year(); |
814 | // workaround for bug in recurrence | 822 | // workaround for bug in recurrence |
815 | if ( count == 100 || year < 1000 || year > 5000 ) { | 823 | if ( count == 100 || year < 1000 || year > 5000 ) { |
816 | return QDateTime (); | 824 | return QDateTime (); |
817 | } | 825 | } |
818 | incidenceStart = incidenceStart.addSecs( 1 ); | 826 | incidenceStart = incidenceStart.addSecs( 1 ); |
819 | } | 827 | } |
820 | } | 828 | } |
821 | } else { | 829 | } else { |
822 | return QDateTime (); | 830 | return QDateTime (); |
823 | } | 831 | } |
824 | } else { | 832 | } else { |
825 | if ( hasStartDate () ) { | 833 | if ( hasStartDate () ) { |
826 | incidenceStart = dtStart(); | 834 | incidenceStart = dtStart(); |
827 | } | 835 | } |
828 | if ( typeID() == todoID ) { | 836 | if ( typeID() == todoID ) { |
829 | if ( ((Todo*)this)->hasDueDate() ) | 837 | if ( ((Todo*)this)->hasDueDate() ) |
830 | incidenceStart = ((Todo*)this)->dtDue(); | 838 | incidenceStart = ((Todo*)this)->dtDue(); |
831 | } | 839 | } |
832 | } | 840 | } |
833 | if ( incidenceStart > dt ) | 841 | if ( incidenceStart > dt ) |
834 | *ok = true; | 842 | *ok = true; |
835 | return incidenceStart; | 843 | return incidenceStart; |
836 | } | 844 | } |
837 | QDateTime Incidence::dtStart() const | 845 | QDateTime Incidence::dtStart() const |
838 | { | 846 | { |
839 | if ( doesRecur() ) { | 847 | if ( doesRecur() ) { |
840 | if ( typeID() == todoID ) { | 848 | if ( typeID() == todoID ) { |
841 | ((Todo*)this)->checkSetCompletedFalse(); | 849 | ((Todo*)this)->checkSetCompletedFalse(); |
842 | } | 850 | } |
843 | } | 851 | } |
844 | return mDtStart; | 852 | return mDtStart; |
845 | } | 853 | } |