change KTTSD to Jovie
[kdepim.git] / incidenceeditor-ng / incidencerecurrence.h
blobe14fbe6d19ff6fa66b7be2532879f445d3805331
1 /*
2 Copyright (c) 2010 Bertjan Broeksema <broeksema@kde.org>
3 Copyright (C) 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
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 the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
21 #ifndef INCIDENCEEDITOR_INCIDENCERECURRENCE_H
22 #define INCIDENCEEDITOR_INCIDENCERECURRENCE_H
24 #include "incidenceeditor-ng.h"
26 #include <KLocalizedString>
28 namespace Ui {
29 class EventOrTodoDesktop;
30 class EventOrTodoMore;
33 namespace IncidenceEditorNG {
35 class IncidenceDateTime;
37 /// Keep this in sync with the values in mUi->mRecurrenceTypeCombo
38 enum RecurrenceType {
39 RecurrenceTypeNone = 0,
40 RecurrenceTypeDaily,
41 RecurrenceTypeWeekly,
42 RecurrenceTypeMonthly,
43 RecurrenceTypeYearly,
44 RecurrenceTypeUnknown // keep this one at the end always
47 class INCIDENCEEDITORS_NG_EXPORT IncidenceRecurrence : public IncidenceEditor
49 Q_OBJECT
50 public:
51 #ifdef KDEPIM_MOBILE_UI
52 IncidenceRecurrence( IncidenceDateTime *dateTime, Ui::EventOrTodoMore *ui );
53 #else
54 IncidenceRecurrence( IncidenceDateTime *dateTime, Ui::EventOrTodoDesktop *ui );
55 #endif
57 virtual void load( const KCalCore::Incidence::Ptr &incidence );
58 virtual void save( const KCalCore::Incidence::Ptr &incidence );
59 virtual bool isDirty() const;
61 RecurrenceType currentRecurrenceType() const;
63 Q_SIGNALS:
64 void recurrenceChanged( IncidenceEditorNG::RecurrenceType type );
66 private Q_SLOTS:
67 void addException();
68 void fillCombos();
69 void handleDateTimeToggle();
70 void handleEndAfterOccurrencesChange( int currentValue );
71 void handleExceptionDateChange( const QDate &currentDate );
72 void handleFrequencyChange();
73 void handleRecurrenceTypeChange( int currentIndex );
74 void removeExceptions();
75 void updateRemoveExceptionButton();
76 void updateWeekDays( const QDate &newStartDate );
78 private:
79 KLocalizedString subsOrdinal( const KLocalizedString &text, int number ) const;
80 /**
81 * Return the day in the month/year on which the event recurs, starting at the
82 * beginning/end. Both return a positive number.
84 short dayOfMonthFromStart() const;
85 short dayOfMonthFromEnd() const;
86 short dayOfYearFromStart() const; // We don't need from end for year
87 int duration() const;
89 /** Returns the week number (1-5) of the month in which the start date occurs. */
90 short monthWeekFromStart() const;
91 short monthWeekFromEnd() const;
93 /** DO NOT USE THIS METHOD DIRECTLY
94 use subsOrdinal() instead for i18n * */
95 QString numberToString( int number ) const;
96 void selectMonthlyItem( KCalCore::Recurrence *recurrence, ushort recurenceType );
97 void selectYearlyItem( KCalCore::Recurrence *recurrence, ushort recurenceType );
98 void setDefaults();
99 void setDuration( int duration );
100 void setExceptionDates( const KCalCore::DateList &dates );
101 void setFrequency( int freq );
102 void toggleRecurrenceWidgets( bool enable );
103 /** Returns an array with the weekday on which the event occurs set to 1 */
104 QBitArray weekday() const;
107 * Return how many times the weekday represented by @param date occurs in
108 * the month of @param date.
110 int weekdayCountForMonth( const QDate &date ) const;
112 private:
113 #ifdef KDEPIM_MOBILE_UI
114 Ui::EventOrTodoMore *mUi;
115 #else
116 Ui::EventOrTodoDesktop *mUi;
117 #endif
118 QDate mCurrentDate;
119 IncidenceDateTime *mDateTime;
120 KCalCore::DateList mExceptionDates;
122 // So we can easily detect if the user changed the type,
123 // without going through complicated recurrence logic:
124 int mMonthlyInitialType;
125 int mYearlyInitialType;
130 #endif