-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 4 | ||||
-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, 121 insertions, 2 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 | |||
@@ -11,3 +11,3 @@ | |||
11 | /** | 11 | /** |
12 | * This is the base class for | 12 | * This is the base class for |
13 | * all PIM Records | 13 | * all PIM Records |
@@ -112,3 +112,3 @@ public: | |||
112 | void setRelations( const QString&, QArray<int> ids ); | 112 | void setRelations( const QString&, QArray<int> ids ); |
113 | 113 | ||
114 | /** | 114 | /** |
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 | |||
@@ -23,2 +23,3 @@ struct ORecur::Data : public QShared { | |||
23 | time_t create; | 23 | time_t create; |
24 | int rep; | ||
24 | }; | 25 | }; |
@@ -80,2 +81,5 @@ time_t ORecur::createTime()const { | |||
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) { |
@@ -112,2 +116,6 @@ void ORecur::setHasEndDate( bool b) { | |||
112 | } | 116 | } |
117 | void ORecur::setRepitition( int rep ) { | ||
118 | checkOrModify(); | ||
119 | data->rep = rep; | ||
120 | } | ||
113 | void ORecur::checkOrModify() { | 121 | void ORecur::checkOrModify() { |
@@ -123,2 +131,3 @@ void ORecur::checkOrModify() { | |||
123 | d2->create = data->create; | 131 | d2->create = data->create; |
132 | d2->rep = data->rep; | ||
124 | data = d2; | 133 | data = d2; |
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 | |||
@@ -33,2 +33,3 @@ public: | |||
33 | time_t createTime()const; | 33 | time_t createTime()const; |
34 | int repetition()const; | ||
34 | 35 | ||
@@ -42,2 +43,3 @@ public: | |||
42 | void setHasEndDate( bool b ); | 43 | void setHasEndDate( bool b ); |
44 | void setRepitition(int ); | ||
43 | private: | 45 | private: |