author | zecke <zecke> | 2002-04-15 20:53:57 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-15 20:53:57 (UTC) |
commit | e010d922ac415558e5efd35e69e39e45908b5501 (patch) (unidiff) | |
tree | 7b6dac3a82613fdefb15c818541891f577ecf48d | |
parent | 15244683bb97d303d0d3b6104b46a9b429aaed85 (diff) | |
download | opie-e010d922ac415558e5efd35e69e39e45908b5501.zip opie-e010d922ac415558e5efd35e69e39e45908b5501.tar.gz opie-e010d922ac415558e5efd35e69e39e45908b5501.tar.bz2 |
updates?
too much to remember
-rw-r--r-- | libopie/ofontmenu.cc | 34 | ||||
-rw-r--r-- | libopie/ofontmenu.h | 6 | ||||
-rw-r--r-- | libopie/tododb.cpp | 20 | ||||
-rw-r--r-- | libopie/tododb.h | 4 | ||||
-rw-r--r-- | libopie/todoevent.cpp | 2 |
5 files changed, 63 insertions, 3 deletions
diff --git a/libopie/ofontmenu.cc b/libopie/ofontmenu.cc index 2acae1c..52ff3ee 100644 --- a/libopie/ofontmenu.cc +++ b/libopie/ofontmenu.cc | |||
@@ -1,78 +1,112 @@ | |||
1 | 1 | ||
2 | |||
3 | #include <qpe/config.h> | ||
2 | #include "ofontmenu.h" | 4 | #include "ofontmenu.h" |
3 | 5 | ||
4 | 6 | ||
5 | 7 | ||
6 | OFontMenu::OFontMenu(QWidget *parent, const char *name, const QList<QWidget> &list ) | 8 | OFontMenu::OFontMenu(QWidget *parent, const char *name, const QList<QWidget> &list ) |
7 | : QPopupMenu( parent, name ) | 9 | : QPopupMenu( parent, name ) |
8 | { | 10 | { |
9 | m_list = list; | 11 | m_list = list; |
12 | m_wids.setAutoDelete( TRUE ); | ||
13 | |||
10 | insertItem(tr("Large"), this, SLOT(slotLarge() ), | 14 | insertItem(tr("Large"), this, SLOT(slotLarge() ), |
11 | 0, 10); | 15 | 0, 10); |
12 | insertItem(tr("Medium"), this, SLOT(slotMedium() ), | 16 | insertItem(tr("Medium"), this, SLOT(slotMedium() ), |
13 | 0, 11 ); | 17 | 0, 11 ); |
14 | insertItem(tr("Small"), this, SLOT(slotSmall() ), | 18 | insertItem(tr("Small"), this, SLOT(slotSmall() ), |
15 | 0, 12 ); | 19 | 0, 12 ); |
16 | setCheckable( true ); | 20 | setCheckable( true ); |
21 | m_size=10; | ||
22 | } | ||
23 | void OFontMenu::save(Config *cfg ) | ||
24 | { | ||
25 | cfg->setGroup("OFontMenu" ); | ||
26 | cfg->writeEntry("size", m_size ); | ||
27 | } | ||
28 | void OFontMenu::restore(Config *cfg ) | ||
29 | { | ||
30 | cfg->setGroup("OFontMeny" ); | ||
31 | m_size = cfg->readNumEntry("size" ); | ||
32 | setItemChecked(10, false ); | ||
33 | setItemChecked(11, false ); | ||
34 | setItemChecked(12, false ); | ||
35 | switch( m_size ){ | ||
36 | case 8: | ||
37 | setItemChecked(12, true ); | ||
38 | break; | ||
39 | case 14: | ||
40 | setItemChecked(10, true ); | ||
41 | break; | ||
42 | case 10:// fall through | ||
43 | default: | ||
44 | setItemChecked(11, true ); | ||
45 | m_size = 10; | ||
46 | break; | ||
47 | } | ||
48 | setFontSize( m_size ); | ||
17 | } | 49 | } |
18 | void OFontMenu::setWidgets(const QList<QWidget> &list ) | 50 | void OFontMenu::setWidgets(const QList<QWidget> &list ) |
19 | { | 51 | { |
20 | m_list = list; | 52 | m_list = list; |
21 | } | 53 | } |
22 | void OFontMenu::addWidget( QWidget *wid ) | 54 | void OFontMenu::addWidget( QWidget *wid ) |
23 | { | 55 | { |
24 | m_list.append(wid ); | 56 | m_list.append(wid ); |
25 | } | 57 | } |
26 | void OFontMenu::removeWidget( QWidget *wid ) | 58 | void OFontMenu::removeWidget( QWidget *wid ) |
27 | { | 59 | { |
28 | m_list.remove( wid ); | 60 | m_list.remove( wid ); |
29 | } | 61 | } |
30 | const QList<QWidget> &OFontMenu::widgets()const | 62 | const QList<QWidget> &OFontMenu::widgets()const |
31 | { | 63 | { |
32 | return m_list; | 64 | return m_list; |
33 | } | 65 | } |
34 | void OFontMenu::forceSize(QWidget *wid, int size ) | 66 | void OFontMenu::forceSize(QWidget *wid, int size ) |
35 | { | 67 | { |
36 | WidSize *widz = new WidSize; | 68 | WidSize *widz = new WidSize; |
37 | widz->wid = wid; | 69 | widz->wid = wid; |
38 | widz->size = size; | 70 | widz->size = size; |
39 | m_wids.append( widz ); | 71 | m_wids.append( widz ); |
40 | } | 72 | } |
41 | void OFontMenu::slotSmall() | 73 | void OFontMenu::slotSmall() |
42 | { | 74 | { |
43 | setItemChecked(10, false ); | 75 | setItemChecked(10, false ); |
44 | setItemChecked(11, false ); | 76 | setItemChecked(11, false ); |
45 | setItemChecked(12, true ); | 77 | setItemChecked(12, true ); |
46 | setFontSize( 8 ); | 78 | setFontSize( 8 ); |
47 | } | 79 | } |
48 | void OFontMenu::slotMedium() | 80 | void OFontMenu::slotMedium() |
49 | { | 81 | { |
50 | setItemChecked(10, false ); | 82 | setItemChecked(10, false ); |
51 | setItemChecked(11, true ); | 83 | setItemChecked(11, true ); |
52 | setItemChecked(12, false ); | 84 | setItemChecked(12, false ); |
53 | setFontSize(10 ); | 85 | setFontSize(10 ); |
54 | } | 86 | } |
55 | void OFontMenu::slotLarge() | 87 | void OFontMenu::slotLarge() |
56 | { | 88 | { |
57 | setItemChecked(10, true ); | 89 | setItemChecked(10, true ); |
58 | setItemChecked(11, false ); | 90 | setItemChecked(11, false ); |
59 | setItemChecked(12, false ); | 91 | setItemChecked(12, false ); |
60 | setFontSize(14 ); | 92 | setFontSize(14 ); |
61 | } | 93 | } |
62 | void OFontMenu::setFontSize(int size ) | 94 | void OFontMenu::setFontSize(int size ) |
63 | { | 95 | { |
96 | m_size = size; | ||
64 | QWidget *wid; | 97 | QWidget *wid; |
65 | for(wid = m_list.first(); wid !=0; wid = m_list.next() ){ | 98 | for(wid = m_list.first(); wid !=0; wid = m_list.next() ){ |
66 | QFont font = wid->font(); | 99 | QFont font = wid->font(); |
67 | font.setPointSize( size ); | 100 | font.setPointSize( size ); |
68 | wid->setFont( font ); | 101 | wid->setFont( font ); |
69 | } | 102 | } |
70 | if(!m_wids.isEmpty() ){ | 103 | if(!m_wids.isEmpty() ){ |
71 | WidSize *wids; | 104 | WidSize *wids; |
72 | for( wids = m_wids.first(); wids != 0; wids = m_wids.next() ){ | 105 | for( wids = m_wids.first(); wids != 0; wids = m_wids.next() ){ |
73 | QFont font = wids->wid->font(); | 106 | QFont font = wids->wid->font(); |
74 | font.setPointSize( wids->size ); | 107 | font.setPointSize( wids->size ); |
75 | wids->wid->setFont( font ); | 108 | wids->wid->setFont( font ); |
76 | } | 109 | } |
77 | } | 110 | } |
111 | emit fontChanged(size ); | ||
78 | } | 112 | } |
diff --git a/libopie/ofontmenu.h b/libopie/ofontmenu.h index 37a628e..609f240 100644 --- a/libopie/ofontmenu.h +++ b/libopie/ofontmenu.h | |||
@@ -1,77 +1,83 @@ | |||
1 | 1 | ||
2 | /* | 2 | /* |
3 | 3 | ||
4 | =. This file is part of the OPIE Project | 4 | =. This file is part of the OPIE Project |
5 | .=l. Copyright (c) 2002 zekce <zecke@handhelds.org> | 5 | .=l. Copyright (c) 2002 zekce <zecke@handhelds.org> |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This library is free software; you can | 7 | _;:, .> :=|. This library is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This library is distributed in the hope that | 14 | .i_,=:_. -<s. This library is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | #ifndef ofontmenu_h | 34 | #ifndef ofontmenu_h |
35 | #define ofontmenu_h | 35 | #define ofontmenu_h |
36 | 36 | ||
37 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
38 | #include <qlist.h> | 38 | #include <qlist.h> |
39 | 39 | ||
40 | 40 | ||
41 | namespace { | 41 | namespace { |
42 | struct WidSize { | 42 | struct WidSize { |
43 | QWidget *wid; | 43 | QWidget *wid; |
44 | int size; | 44 | int size; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | }; | 47 | }; |
48 | 48 | ||
49 | // if i would be on kde this would be a KActionMenu... | 49 | // if i would be on kde this would be a KActionMenu... |
50 | class Config; | ||
50 | class OFontMenu : public QPopupMenu { | 51 | class OFontMenu : public QPopupMenu { |
51 | Q_OBJECT | 52 | Q_OBJECT |
52 | public: | 53 | public: |
53 | OFontMenu(QWidget *parent, const char* name, const QList<QWidget> &list ); | 54 | OFontMenu(QWidget *parent, const char* name, const QList<QWidget> &list ); |
55 | void save(Config *cfg ); | ||
56 | void restore(Config *cfg ); | ||
54 | void setWidgets(const QList<QWidget> &list ); | 57 | void setWidgets(const QList<QWidget> &list ); |
55 | void addWidget(QWidget *wid ); | 58 | void addWidget(QWidget *wid ); |
56 | void forceSize(QWidget *wid, int size ); | 59 | void forceSize(QWidget *wid, int size ); |
57 | void removeWidget(QWidget *wid ); | 60 | void removeWidget(QWidget *wid ); |
58 | const QList<QWidget> &widgets()const; | 61 | const QList<QWidget> &widgets()const; |
59 | 62 | ||
63 | signals: | ||
64 | void fontChanged(int size ); | ||
60 | private: | 65 | private: |
61 | QList<QWidget> m_list; | 66 | QList<QWidget> m_list; |
62 | QList<WidSize> m_wids; | 67 | QList<WidSize> m_wids; |
68 | int m_size; | ||
63 | class OFontMenuPrivate; | 69 | class OFontMenuPrivate; |
64 | OFontMenuPrivate *d; | 70 | OFontMenuPrivate *d; |
65 | private slots: | 71 | private slots: |
66 | virtual void slotSmall(); | 72 | virtual void slotSmall(); |
67 | virtual void slotMedium(); | 73 | virtual void slotMedium(); |
68 | virtual void slotLarge(); | 74 | virtual void slotLarge(); |
69 | void setFontSize(int size ); | 75 | void setFontSize(int size ); |
70 | }; | 76 | }; |
71 | 77 | ||
72 | #endif | 78 | #endif |
73 | 79 | ||
74 | 80 | ||
75 | 81 | ||
76 | 82 | ||
77 | 83 | ||
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index 3f6dc30..4d6711d 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -104,124 +104,144 @@ public: | |||
104 | //description | 104 | //description |
105 | dummy = element->attribute("Description" ); | 105 | dummy = element->attribute("Description" ); |
106 | event.setDescription( dummy ); | 106 | event.setDescription( dummy ); |
107 | // category | 107 | // category |
108 | dummy = element->attribute("Categories" ); | 108 | dummy = element->attribute("Categories" ); |
109 | QStringList ids = QStringList::split(";", dummy ); | 109 | QStringList ids = QStringList::split(";", dummy ); |
110 | event.setCategories( ids ); | 110 | event.setCategories( ids ); |
111 | 111 | ||
112 | //uid | 112 | //uid |
113 | dummy = element->attribute("Uid" ); | 113 | dummy = element->attribute("Uid" ); |
114 | dumInt = dummy.toInt(&ok ); | 114 | dumInt = dummy.toInt(&ok ); |
115 | if(ok ) event.setUid( dumInt ); | 115 | if(ok ) event.setUid( dumInt ); |
116 | m_todos.append( event ); | 116 | m_todos.append( event ); |
117 | element = element->nextChild(); // next element | 117 | element = element->nextChild(); // next element |
118 | } | 118 | } |
119 | //} | 119 | //} |
120 | }else { | 120 | }else { |
121 | qWarning("could not load" ); | 121 | qWarning("could not load" ); |
122 | } | 122 | } |
123 | delete root; | 123 | delete root; |
124 | qWarning("returning" ); | 124 | qWarning("returning" ); |
125 | return m_todos; | 125 | return m_todos; |
126 | } | 126 | } |
127 | }; | 127 | }; |
128 | 128 | ||
129 | } | 129 | } |
130 | 130 | ||
131 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ | 131 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ |
132 | m_fileName = fileName; | 132 | m_fileName = fileName; |
133 | if( fileName.isEmpty() && res == 0 ){ | 133 | if( fileName.isEmpty() && res == 0 ){ |
134 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); | 134 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); |
135 | res = new FileToDoResource(); | 135 | res = new FileToDoResource(); |
136 | //qWarning("%s", m_fileName.latin1() ); | 136 | //qWarning("%s", m_fileName.latin1() ); |
137 | }else if(res == 0 ){ // let's create a ToDoResource for xml | 137 | }else if(res == 0 ){ // let's create a ToDoResource for xml |
138 | res = new FileToDoResource(); | 138 | res = new FileToDoResource(); |
139 | } | 139 | } |
140 | m_res = res; | 140 | m_res = res; |
141 | load(); | 141 | load(); |
142 | } | 142 | } |
143 | ToDoResource* ToDoDB::resource(){ | 143 | ToDoResource* ToDoDB::resource(){ |
144 | return m_res; | 144 | return m_res; |
145 | }; | 145 | }; |
146 | void ToDoDB::setResource( ToDoResource *res ) | 146 | void ToDoDB::setResource( ToDoResource *res ) |
147 | { | 147 | { |
148 | delete m_res; | 148 | delete m_res; |
149 | m_res = res; | 149 | m_res = res; |
150 | } | 150 | } |
151 | ToDoDB::~ToDoDB() | 151 | ToDoDB::~ToDoDB() |
152 | { | 152 | { |
153 | delete m_res; | 153 | delete m_res; |
154 | } | 154 | } |
155 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, | 155 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, |
156 | bool all ) | 156 | bool all ) |
157 | { | 157 | { |
158 | QValueList<ToDoEvent> events; | 158 | QValueList<ToDoEvent> events; |
159 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 159 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
160 | if( (*it).hasDate() ){ | 160 | if( (*it).hasDate() ){ |
161 | if( (*it).date() >= from && (*it).date() <= to ) | 161 | if( (*it).date() >= from && (*it).date() <= to ) |
162 | events.append( (*it) ); | 162 | events.append( (*it) ); |
163 | }else if( all ){ | 163 | }else if( all ){ |
164 | events.append( (*it) ); | 164 | events.append( (*it) ); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | return events; | 167 | return events; |
168 | } | 168 | } |
169 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, | 169 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, |
170 | bool all) | 170 | bool all) |
171 | { | 171 | { |
172 | return effectiveToDos( from, QDate::currentDate(), all ); | 172 | return effectiveToDos( from, QDate::currentDate(), all ); |
173 | } | 173 | } |
174 | QValueList<ToDoEvent> ToDoDB::overDue() | 174 | QValueList<ToDoEvent> ToDoDB::overDue() |
175 | { | 175 | { |
176 | QValueList<ToDoEvent> events; | 176 | QValueList<ToDoEvent> events; |
177 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 177 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
178 | if( (*it).isOverdue() ) | 178 | if( (*it).isOverdue() ) |
179 | events.append((*it) ); | 179 | events.append((*it) ); |
180 | } | 180 | } |
181 | return events; | 181 | return events; |
182 | } | 182 | } |
183 | QValueList<ToDoEvent> ToDoDB::rawToDos() | 183 | QValueList<ToDoEvent> ToDoDB::rawToDos() |
184 | { | 184 | { |
185 | return m_todos; | 185 | return m_todos; |
186 | } | 186 | } |
187 | void ToDoDB::addEvent( const ToDoEvent &event ) | 187 | void ToDoDB::addEvent( const ToDoEvent &event ) |
188 | { | 188 | { |
189 | m_todos.append( event ); | 189 | m_todos.append( event ); |
190 | } | 190 | } |
191 | void ToDoDB::editEvent( const ToDoEvent &event ) | 191 | void ToDoDB::editEvent( const ToDoEvent &event ) |
192 | { | 192 | { |
193 | m_todos.remove( event ); | 193 | m_todos.remove( event ); |
194 | m_todos.append( event ); | 194 | m_todos.append( event ); |
195 | } | 195 | } |
196 | void ToDoDB::removeEvent( const ToDoEvent &event ) | 196 | void ToDoDB::removeEvent( const ToDoEvent &event ) |
197 | { | 197 | { |
198 | m_todos.remove( event ); | 198 | m_todos.remove( event ); |
199 | } | 199 | } |
200 | void ToDoDB::replaceEvent(const ToDoEvent &event ) | ||
201 | { | ||
202 | QValueList<ToDoEvent>::Iterator it; | ||
203 | int uid = event.uid(); | ||
204 | // == is not overloaded as we would like :( so let's search for the uid | ||
205 | for(it = m_todos.begin(); it != m_todos.end(); ++it ){ | ||
206 | if( (*it).uid() == uid ){ | ||
207 | m_todos.remove( (*it) ); | ||
208 | break; // should save us the iterate is now borked | ||
209 | } | ||
210 | } | ||
211 | m_todos.append(event); | ||
212 | } | ||
200 | void ToDoDB::reload() | 213 | void ToDoDB::reload() |
201 | { | 214 | { |
202 | load(); | 215 | load(); |
203 | } | 216 | } |
217 | void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events ) | ||
218 | { | ||
219 | QValueList<ToDoEvent>::ConstIterator it; | ||
220 | for( it = events.begin(); it != events.end(); ++it ){ | ||
221 | replaceEvent( (*it) ); | ||
222 | } | ||
223 | } | ||
204 | void ToDoDB::setFileName(const QString &file ) | 224 | void ToDoDB::setFileName(const QString &file ) |
205 | { | 225 | { |
206 | m_fileName =file; | 226 | m_fileName =file; |
207 | } | 227 | } |
208 | QString ToDoDB::fileName()const | 228 | QString ToDoDB::fileName()const |
209 | { | 229 | { |
210 | return m_fileName; | 230 | return m_fileName; |
211 | } | 231 | } |
212 | void ToDoDB::load() | 232 | void ToDoDB::load() |
213 | { | 233 | { |
214 | m_todos = m_res->load( m_fileName ); | 234 | m_todos = m_res->load( m_fileName ); |
215 | } | 235 | } |
216 | bool ToDoDB::save() | 236 | bool ToDoDB::save() |
217 | { | 237 | { |
218 | return m_res->save( m_fileName, m_todos ); | 238 | return m_res->save( m_fileName, m_todos ); |
219 | } | 239 | } |
220 | 240 | ||
221 | 241 | ||
222 | 242 | ||
223 | 243 | ||
224 | 244 | ||
225 | 245 | ||
226 | 246 | ||
227 | 247 | ||
diff --git a/libopie/tododb.h b/libopie/tododb.h index e77a0f4..7fd9f96 100644 --- a/libopie/tododb.h +++ b/libopie/tododb.h | |||
@@ -1,44 +1,46 @@ | |||
1 | 1 | ||
2 | #ifndef tododb_h | 2 | #ifndef tododb_h |
3 | #define tododb_h | 3 | #define tododb_h |
4 | 4 | ||
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | 6 | ||
7 | #include <opie/todoevent.h> | 7 | #include <opie/todoevent.h> |
8 | 8 | ||
9 | class ToDoResource; | 9 | class ToDoResource; |
10 | class ToDoDB | 10 | class ToDoDB |
11 | { | 11 | { |
12 | public: | 12 | public: |
13 | // if no argument is supplied pick the default book | 13 | // if no argument is supplied pick the default book |
14 | ToDoDB(const QString &fileName = QString::null, ToDoResource* resource= 0 ); | 14 | ToDoDB(const QString &fileName = QString::null, ToDoResource* resource= 0 ); |
15 | ~ToDoDB(); | 15 | ~ToDoDB(); |
16 | QValueList<ToDoEvent> effectiveToDos(const QDate &from, | 16 | QValueList<ToDoEvent> effectiveToDos(const QDate &from, |
17 | const QDate &to, | 17 | const QDate &to, |
18 | bool includeNoDates = true); | 18 | bool includeNoDates = true); |
19 | QValueList<ToDoEvent> effectiveToDos(const QDate &start, bool includeNoDates = true ); | 19 | QValueList<ToDoEvent> effectiveToDos(const QDate &start, bool includeNoDates = true ); |
20 | QValueList<ToDoEvent> rawToDos(); // all events | 20 | QValueList<ToDoEvent> rawToDos(); // all events |
21 | QValueList<ToDoEvent> overDue(); | 21 | QValueList<ToDoEvent> overDue(); |
22 | 22 | ||
23 | void addEvent(const ToDoEvent &event ); | 23 | void addEvent(const ToDoEvent &event ); |
24 | void editEvent(const ToDoEvent &editEvent ); | 24 | void editEvent(const ToDoEvent &editEvent ); |
25 | void removeEvent(const ToDoEvent &event); | 25 | void removeEvent(const ToDoEvent &event); |
26 | 26 | void replaceEvent(const ToDoEvent &event ); | |
27 | // QValueList<ToDoEvents will overwrite existing ones no smart code at all ;) | ||
28 | void mergeWith(const QValueList<ToDoEvent>& ); | ||
27 | void reload(); | 29 | void reload(); |
28 | void setFileName(const QString & ); | 30 | void setFileName(const QString & ); |
29 | QString fileName()const; | 31 | QString fileName()const; |
30 | bool save(); | 32 | bool save(); |
31 | ToDoResource *resource(); | 33 | ToDoResource *resource(); |
32 | void setResource(ToDoResource* res); | 34 | void setResource(ToDoResource* res); |
33 | 35 | ||
34 | private: | 36 | private: |
35 | class ToDoDBPrivate; | 37 | class ToDoDBPrivate; |
36 | ToDoDBPrivate *d; | 38 | ToDoDBPrivate *d; |
37 | QString m_fileName; | 39 | QString m_fileName; |
38 | ToDoResource *m_res; | 40 | ToDoResource *m_res; |
39 | QValueList<ToDoEvent> m_todos; | 41 | QValueList<ToDoEvent> m_todos; |
40 | void load(); | 42 | void load(); |
41 | }; | 43 | }; |
42 | 44 | ||
43 | 45 | ||
44 | #endif | 46 | #endif |
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp index 28b2e98..a5dba4f 100644 --- a/libopie/todoevent.cpp +++ b/libopie/todoevent.cpp | |||
@@ -1,169 +1,167 @@ | |||
1 | 1 | ||
2 | #include <opie/todoevent.h> | 2 | #include <opie/todoevent.h> |
3 | #include <qpe/palmtopuidgen.h> | 3 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/stringutil.h> | 4 | #include <qpe/stringutil.h> |
5 | #include <qpe/palmtoprecord.h> | 5 | #include <qpe/palmtoprecord.h> |
6 | 6 | ||
7 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) | 7 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) |
8 | { | 8 | { |
9 | *this = event; | 9 | *this = event; |
10 | } | 10 | } |
11 | 11 | ||
12 | ToDoEvent::ToDoEvent(bool completed, int priority, const QStringList &category, | 12 | ToDoEvent::ToDoEvent(bool completed, int priority, const QStringList &category, |
13 | const QString &description, bool hasDate, QDate date, int uid ) | 13 | const QString &description, bool hasDate, QDate date, int uid ) |
14 | { | 14 | { |
15 | qWarning("todoEvent c'tor" ); | ||
16 | m_date = date; | 15 | m_date = date; |
17 | m_isCompleted = completed; | 16 | m_isCompleted = completed; |
18 | m_hasDate = hasDate; | 17 | m_hasDate = hasDate; |
19 | m_priority = priority; | 18 | m_priority = priority; |
20 | m_category = category; | 19 | m_category = category; |
21 | m_desc = Qtopia::simplifyMultiLineSpace(description ); | 20 | m_desc = Qtopia::simplifyMultiLineSpace(description ); |
22 | if (uid == -1 ) { | 21 | if (uid == -1 ) { |
23 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); | 22 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); |
24 | uid = uidgen->generate(); | 23 | uid = uidgen->generate(); |
25 | delete uidgen; | 24 | delete uidgen; |
26 | }// generate the ids | 25 | }// generate the ids |
27 | m_uid = uid; | 26 | m_uid = uid; |
28 | } | 27 | } |
29 | QArray<int> ToDoEvent::categories()const | 28 | QArray<int> ToDoEvent::categories()const |
30 | { | 29 | { |
31 | QArray<int> array(m_category.count() ); // currently the datebook can be only in one category | 30 | QArray<int> array(m_category.count() ); // currently the datebook can be only in one category |
32 | array = Qtopia::Record::idsFromString( m_category.join(";") ); | 31 | array = Qtopia::Record::idsFromString( m_category.join(";") ); |
33 | return array; | 32 | return array; |
34 | } | 33 | } |
35 | bool ToDoEvent::match( const QRegExp ®Exp )const | 34 | bool ToDoEvent::match( const QRegExp ®Exp )const |
36 | { | 35 | { |
37 | if( QString::number( m_priority ).find( regExp ) != -1 ){ | 36 | if( QString::number( m_priority ).find( regExp ) != -1 ){ |
38 | return true; | 37 | return true; |
39 | }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ | 38 | }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ |
40 | return true; | 39 | return true; |
41 | }else if(m_desc.find( regExp ) != -1 ){ | 40 | }else if(m_desc.find( regExp ) != -1 ){ |
42 | return true; | 41 | return true; |
43 | } | 42 | } |
44 | return false; | 43 | return false; |
45 | } | 44 | } |
46 | bool ToDoEvent::isCompleted() const | 45 | bool ToDoEvent::isCompleted() const |
47 | { | 46 | { |
48 | return m_isCompleted; | 47 | return m_isCompleted; |
49 | } | 48 | } |
50 | bool ToDoEvent::hasDate() const | 49 | bool ToDoEvent::hasDate() const |
51 | { | 50 | { |
52 | return m_hasDate; | 51 | return m_hasDate; |
53 | } | 52 | } |
54 | int ToDoEvent::priority()const | 53 | int ToDoEvent::priority()const |
55 | { | 54 | { |
56 | return m_priority; | 55 | return m_priority; |
57 | } | 56 | } |
58 | QStringList ToDoEvent::allCategories()const | 57 | QStringList ToDoEvent::allCategories()const |
59 | { | 58 | { |
60 | return m_category; | 59 | return m_category; |
61 | } | 60 | } |
62 | void ToDoEvent::insertCategory(const QString &str ) | 61 | void ToDoEvent::insertCategory(const QString &str ) |
63 | { | 62 | { |
64 | m_category.append( str ); | 63 | m_category.append( str ); |
65 | } | 64 | } |
66 | void ToDoEvent::clearCategories() | 65 | void ToDoEvent::clearCategories() |
67 | { | 66 | { |
68 | m_category.clear(); | 67 | m_category.clear(); |
69 | } | 68 | } |
70 | void ToDoEvent::setCategories(const QStringList &list ) | 69 | void ToDoEvent::setCategories(const QStringList &list ) |
71 | { | 70 | { |
72 | m_category = list; | 71 | m_category = list; |
73 | qWarning("todoevent: %s", list.join(";" ).latin1() ); | ||
74 | } | 72 | } |
75 | QDate ToDoEvent::date()const | 73 | QDate ToDoEvent::date()const |
76 | { | 74 | { |
77 | return m_date; | 75 | return m_date; |
78 | } | 76 | } |
79 | 77 | ||
80 | QString ToDoEvent::description()const | 78 | QString ToDoEvent::description()const |
81 | { | 79 | { |
82 | return m_desc; | 80 | return m_desc; |
83 | } | 81 | } |
84 | void ToDoEvent::setCompleted( bool completed ) | 82 | void ToDoEvent::setCompleted( bool completed ) |
85 | { | 83 | { |
86 | m_isCompleted = completed; | 84 | m_isCompleted = completed; |
87 | } | 85 | } |
88 | void ToDoEvent::setHasDate( bool hasDate ) | 86 | void ToDoEvent::setHasDate( bool hasDate ) |
89 | { | 87 | { |
90 | m_hasDate = hasDate; | 88 | m_hasDate = hasDate; |
91 | } | 89 | } |
92 | void ToDoEvent::setDescription(const QString &desc ) | 90 | void ToDoEvent::setDescription(const QString &desc ) |
93 | { | 91 | { |
94 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); | 92 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); |
95 | } | 93 | } |
96 | void ToDoEvent::setCategory( const QString &cat ) | 94 | void ToDoEvent::setCategory( const QString &cat ) |
97 | { | 95 | { |
98 | qWarning("setCategory %s", cat.latin1() ); | 96 | qWarning("setCategory %s", cat.latin1() ); |
99 | m_category.clear(); | 97 | m_category.clear(); |
100 | m_category << cat; | 98 | m_category << cat; |
101 | } | 99 | } |
102 | void ToDoEvent::setPriority(int prio ) | 100 | void ToDoEvent::setPriority(int prio ) |
103 | { | 101 | { |
104 | m_priority = prio; | 102 | m_priority = prio; |
105 | } | 103 | } |
106 | void ToDoEvent::setDate( QDate date ) | 104 | void ToDoEvent::setDate( QDate date ) |
107 | { | 105 | { |
108 | m_date = date; | 106 | m_date = date; |
109 | } | 107 | } |
110 | bool ToDoEvent::isOverdue( ) | 108 | bool ToDoEvent::isOverdue( ) |
111 | { | 109 | { |
112 | if( m_hasDate ) | 110 | if( m_hasDate ) |
113 | return QDate::currentDate() > m_date; | 111 | return QDate::currentDate() > m_date; |
114 | return false; | 112 | return false; |
115 | } | 113 | } |
116 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ | 114 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ |
117 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 115 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
118 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 116 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
119 | if( hasDate() && toDoEvent.hasDate() ){ | 117 | if( hasDate() && toDoEvent.hasDate() ){ |
120 | if( date() == toDoEvent.date() ){ // let's the priority decide | 118 | if( date() == toDoEvent.date() ){ // let's the priority decide |
121 | return priority() < toDoEvent.priority(); | 119 | return priority() < toDoEvent.priority(); |
122 | }else{ | 120 | }else{ |
123 | return date() < toDoEvent.date(); | 121 | return date() < toDoEvent.date(); |
124 | } | 122 | } |
125 | } | 123 | } |
126 | return false; | 124 | return false; |
127 | } | 125 | } |
128 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const | 126 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const |
129 | { | 127 | { |
130 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 128 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
131 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 129 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
132 | if( hasDate() && toDoEvent.hasDate() ){ | 130 | if( hasDate() && toDoEvent.hasDate() ){ |
133 | if( date() == toDoEvent.date() ){ // let's the priority decide | 131 | if( date() == toDoEvent.date() ){ // let's the priority decide |
134 | return priority() <= toDoEvent.priority(); | 132 | return priority() <= toDoEvent.priority(); |
135 | }else{ | 133 | }else{ |
136 | return date() <= toDoEvent.date(); | 134 | return date() <= toDoEvent.date(); |
137 | } | 135 | } |
138 | } | 136 | } |
139 | return true; | 137 | return true; |
140 | } | 138 | } |
141 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const | 139 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const |
142 | { | 140 | { |
143 | if( !hasDate() && !toDoEvent.hasDate() ) return false; | 141 | if( !hasDate() && !toDoEvent.hasDate() ) return false; |
144 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 142 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
145 | if( hasDate() && toDoEvent.hasDate() ){ | 143 | if( hasDate() && toDoEvent.hasDate() ){ |
146 | if( date() == toDoEvent.date() ){ // let's the priority decide | 144 | if( date() == toDoEvent.date() ){ // let's the priority decide |
147 | return priority() > toDoEvent.priority(); | 145 | return priority() > toDoEvent.priority(); |
148 | }else{ | 146 | }else{ |
149 | return date() > toDoEvent.date(); | 147 | return date() > toDoEvent.date(); |
150 | } | 148 | } |
151 | } | 149 | } |
152 | return false; | 150 | return false; |
153 | } | 151 | } |
154 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const | 152 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const |
155 | { | 153 | { |
156 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 154 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
157 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 155 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
158 | if( hasDate() && toDoEvent.hasDate() ){ | 156 | if( hasDate() && toDoEvent.hasDate() ){ |
159 | if( date() == toDoEvent.date() ){ // let's the priority decide | 157 | if( date() == toDoEvent.date() ){ // let's the priority decide |
160 | return priority() > toDoEvent.priority(); | 158 | return priority() > toDoEvent.priority(); |
161 | }else{ | 159 | }else{ |
162 | return date() > toDoEvent.date(); | 160 | return date() > toDoEvent.date(); |
163 | } | 161 | } |
164 | } | 162 | } |
165 | return true; | 163 | return true; |
166 | } | 164 | } |
167 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const | 165 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const |
168 | { | 166 | { |
169 | if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_desc ) | 167 | if( m_date == toDoEvent.m_date && m_isCompleted == toDoEvent.m_isCompleted && m_hasDate == toDoEvent.m_hasDate && m_priority == toDoEvent.m_priority && m_category == toDoEvent.m_category && m_desc == toDoEvent.m_desc ) |