-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 0 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimstate.cpp | 64 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimstate.h | 44 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 9 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.h | 2 |
5 files changed, 119 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h index dbb94ed..d9ccad4 100644 --- a/libopie2/opiepim/core/opimrecord.h +++ b/libopie2/opiepim/core/opimrecord.h | |||
diff --git a/libopie2/opiepim/core/opimstate.cpp b/libopie2/opiepim/core/opimstate.cpp new file mode 100644 index 0000000..6fb2feb --- a/dev/null +++ b/libopie2/opiepim/core/opimstate.cpp | |||
@@ -0,0 +1,64 @@ | |||
1 | #include <qshared.h> | ||
2 | |||
3 | #include "opimstate.h" | ||
4 | |||
5 | /* | ||
6 | * for one int this does not make | ||
7 | * much sense but never the less | ||
8 | * we will do it for the future | ||
9 | */ | ||
10 | struct OPimState::Data : public QShared { | ||
11 | Data() : QShared(),state(Undefined) { | ||
12 | } | ||
13 | int state; | ||
14 | }; | ||
15 | |||
16 | OPimState::OPimState( int state ) { | ||
17 | data = new Data; | ||
18 | data->state = state; | ||
19 | } | ||
20 | OPimState::OPimState( const OPimState& st) : | ||
21 | data( st.data ) { | ||
22 | /* ref up */ | ||
23 | data->ref(); | ||
24 | } | ||
25 | OPimState::~OPimState() { | ||
26 | if ( data->deref() ) { | ||
27 | delete data ; | ||
28 | data = 0; | ||
29 | } | ||
30 | } | ||
31 | bool OPimState::operator==( const OPimState& st) { | ||
32 | if ( data->state == st.data->state ) return true; | ||
33 | |||
34 | return false; | ||
35 | } | ||
36 | OPimState &OPimState::operator=( const OPimState& st) { | ||
37 | st.data->ref(); | ||
38 | deref(); | ||
39 | data = st.data; | ||
40 | |||
41 | return *this; | ||
42 | } | ||
43 | void OPimState::setState( int st) { | ||
44 | copyInternally(); | ||
45 | data->state = st; | ||
46 | } | ||
47 | int OPimState::state()const { | ||
48 | return data->state; | ||
49 | } | ||
50 | void OPimState::deref() { | ||
51 | if ( data->deref() ) { | ||
52 | delete data; | ||
53 | data = 0l; | ||
54 | } | ||
55 | } | ||
56 | void OPimState::copyInternally() { | ||
57 | /* we need to change it */ | ||
58 | if ( data->count != 1 ) { | ||
59 | data->deref(); | ||
60 | Data* d2 = new Data; | ||
61 | d2->state = data->state; | ||
62 | data = d2; | ||
63 | } | ||
64 | } | ||
diff --git a/libopie2/opiepim/core/opimstate.h b/libopie2/opiepim/core/opimstate.h new file mode 100644 index 0000000..731181e --- a/dev/null +++ b/libopie2/opiepim/core/opimstate.h | |||
@@ -0,0 +1,44 @@ | |||
1 | #ifndef OPIE_PIM_STATE_H | ||
2 | #define OPIE_PIM_STATE_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | |||
6 | /** | ||
7 | * The State of a Task | ||
8 | * This class encapsules the state of a todo | ||
9 | * and it's shared too | ||
10 | */ | ||
11 | /* | ||
12 | * in c a simple struct would be enough ;) | ||
13 | * g_new_state(); | ||
14 | * g_do_some_thing( state_t* ); | ||
15 | * ;) | ||
16 | */ | ||
17 | class OPimState { | ||
18 | public: | ||
19 | enum State { | ||
20 | Started = 0, | ||
21 | Postponed, | ||
22 | Finished, | ||
23 | NotStarted, | ||
24 | Undefined | ||
25 | }; | ||
26 | OPimState( int state = Undefined ); | ||
27 | OPimState( const OPimState& ); | ||
28 | ~OPimState(); | ||
29 | |||
30 | bool operator==( const OPimState& ); | ||
31 | OPimState &operator=( const OPimState& ); | ||
32 | void setState( int state); | ||
33 | int state()const; | ||
34 | private: | ||
35 | void deref(); | ||
36 | inline void copyInternally(); | ||
37 | struct Data; | ||
38 | Data* data; | ||
39 | class Private; | ||
40 | Private *d; | ||
41 | }; | ||
42 | |||
43 | |||
44 | #endif | ||
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index 6c81f8f..257d4fd 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -18,12 +18,13 @@ struct ORecur::Data : public QShared { | |||
18 | ORecur::RepeatType type; | 18 | ORecur::RepeatType type; |
19 | int freq; | 19 | int freq; |
20 | int pos; | 20 | int pos; |
21 | bool hasEnd : 1; | 21 | bool hasEnd : 1; |
22 | time_t end; | 22 | time_t end; |
23 | time_t create; | 23 | time_t create; |
24 | int rep; | ||
24 | }; | 25 | }; |
25 | 26 | ||
26 | 27 | ||
27 | ORecur::ORecur() { | 28 | ORecur::ORecur() { |
28 | data = new Data; | 29 | data = new Data; |
29 | } | 30 | } |
@@ -75,12 +76,15 @@ QDate ORecur::endDate()const { | |||
75 | time_t ORecur::endDateUTC()const { | 76 | time_t ORecur::endDateUTC()const { |
76 | return data->end; | 77 | return data->end; |
77 | } | 78 | } |
78 | time_t ORecur::createTime()const { | 79 | time_t ORecur::createTime()const { |
79 | return data->create; | 80 | return data->create; |
80 | } | 81 | } |
82 | int ORecur::repetition()const { | ||
83 | return data->rep; | ||
84 | } | ||
81 | void ORecur::setType( const RepeatType& z) { | 85 | void ORecur::setType( const RepeatType& z) { |
82 | checkOrModify(); | 86 | checkOrModify(); |
83 | data->type = z; | 87 | data->type = z; |
84 | } | 88 | } |
85 | void ORecur::setFrequency( int freq ) { | 89 | void ORecur::setFrequency( int freq ) { |
86 | checkOrModify(); | 90 | checkOrModify(); |
@@ -107,21 +111,26 @@ void ORecur::setCreateTime( time_t t) { | |||
107 | data->create = t; | 111 | data->create = t; |
108 | } | 112 | } |
109 | void ORecur::setHasEndDate( bool b) { | 113 | void ORecur::setHasEndDate( bool b) { |
110 | checkOrModify(); | 114 | checkOrModify(); |
111 | data->hasEnd = b; | 115 | data->hasEnd = b; |
112 | } | 116 | } |
117 | void ORecur::setRepitition( int rep ) { | ||
118 | checkOrModify(); | ||
119 | data->rep = rep; | ||
120 | } | ||
113 | void ORecur::checkOrModify() { | 121 | void ORecur::checkOrModify() { |
114 | if ( data->count != 1 ) { | 122 | if ( data->count != 1 ) { |
115 | data->deref(); | 123 | data->deref(); |
116 | Data* d2 = new Data; | 124 | Data* d2 = new Data; |
117 | d2->days = data->days; | 125 | d2->days = data->days; |
118 | d2->type = data->type; | 126 | d2->type = data->type; |
119 | d2->freq = data->freq; | 127 | d2->freq = data->freq; |
120 | d2->pos = data->pos; | 128 | d2->pos = data->pos; |
121 | d2->hasEnd = data->hasEnd; | 129 | d2->hasEnd = data->hasEnd; |
122 | d2->end = data->end; | 130 | d2->end = data->end; |
123 | d2->create = data->create; | 131 | d2->create = data->create; |
132 | d2->rep = data->rep; | ||
124 | data = d2; | 133 | data = d2; |
125 | } | 134 | } |
126 | } | 135 | } |
127 | 136 | ||
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h index 89258f8..d24d72d 100644 --- a/libopie2/opiepim/core/orecur.h +++ b/libopie2/opiepim/core/orecur.h | |||
@@ -28,21 +28,23 @@ public: | |||
28 | int position()const; | 28 | int position()const; |
29 | char days()const; | 29 | char days()const; |
30 | bool hasEndDate()const; | 30 | bool hasEndDate()const; |
31 | QDate endDate()const; | 31 | QDate endDate()const; |
32 | time_t endDateUTC()const; | 32 | time_t endDateUTC()const; |
33 | time_t createTime()const; | 33 | time_t createTime()const; |
34 | int repetition()const; | ||
34 | 35 | ||
35 | void setType( const RepeatType& ); | 36 | void setType( const RepeatType& ); |
36 | void setFrequency( int freq ); | 37 | void setFrequency( int freq ); |
37 | void setPosition( int pos ); | 38 | void setPosition( int pos ); |
38 | void setDays( char c); | 39 | void setDays( char c); |
39 | void setEndDate( const QDate& dt ); | 40 | void setEndDate( const QDate& dt ); |
40 | void setEndDateUTC( time_t ); | 41 | void setEndDateUTC( time_t ); |
41 | void setCreateTime( time_t ); | 42 | void setCreateTime( time_t ); |
42 | void setHasEndDate( bool b ); | 43 | void setHasEndDate( bool b ); |
44 | void setRepitition(int ); | ||
43 | private: | 45 | private: |
44 | void deref(); | 46 | void deref(); |
45 | inline void checkOrModify(); | 47 | inline void checkOrModify(); |
46 | 48 | ||
47 | 49 | ||
48 | class Data; | 50 | class Data; |