-rw-r--r-- | libopie/oprocess.h | 2 | ||||
-rw-r--r-- | libopie/tododb.cpp | 8 | ||||
-rw-r--r-- | libopie/todoevent.cpp | 21 | ||||
-rw-r--r-- | libopie/todoevent.h | 11 |
4 files changed, 37 insertions, 5 deletions
diff --git a/libopie/oprocess.h b/libopie/oprocess.h index ce3c87d..fd726b4 100644 --- a/libopie/oprocess.h +++ b/libopie/oprocess.h | |||
@@ -1,283 +1,283 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) | 2 | Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | // | 19 | // |
20 | // KPROCESS -- A class for handling child processes in KDE without | 20 | // KPROCESS -- A class for handling child processes in KDE without |
21 | // having to take care of Un*x specific implementation details | 21 | // having to take care of Un*x specific implementation details |
22 | // | 22 | // |
23 | // version 0.3.1, Jan 8th 1998 | 23 | // version 0.3.1, Jan 8th 1998 |
24 | // | 24 | // |
25 | // (C) Christian Czezatke | 25 | // (C) Christian Czezatke |
26 | // e9025461@student.tuwien.ac.at | 26 | // e9025461@student.tuwien.ac.at |
27 | // Ported by Holger Freyther | 27 | // Ported by Holger Freyther to the Open Palmtop Integrated Environment |
28 | // | 28 | // |
29 | 29 | ||
30 | #ifndef __kprocess_h__ | 30 | #ifndef __kprocess_h__ |
31 | #define __kprocess_h__ | 31 | #define __kprocess_h__ |
32 | 32 | ||
33 | #include <sys/types.h> // for pid_t | 33 | #include <sys/types.h> // for pid_t |
34 | #include <sys/wait.h> | 34 | #include <sys/wait.h> |
35 | #include <signal.h> | 35 | #include <signal.h> |
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | #include <qvaluelist.h> | 37 | #include <qvaluelist.h> |
38 | #include <qcstring.h> | 38 | #include <qcstring.h> |
39 | #include <qobject.h> | 39 | #include <qobject.h> |
40 | 40 | ||
41 | class QSocketNotifier; | 41 | class QSocketNotifier; |
42 | class OProcessPrivate; | 42 | class OProcessPrivate; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Child process invocation, monitoring and control. | 45 | * Child process invocation, monitoring and control. |
46 | * | 46 | * |
47 | * @sect General usage and features | 47 | * @sect General usage and features |
48 | * | 48 | * |
49 | *This class allows a KDE application to start child processes without having | 49 | *This class allows a KDE application to start child processes without having |
50 | *to worry about UN*X signal handling issues and zombie process reaping. | 50 | *to worry about UN*X signal handling issues and zombie process reaping. |
51 | * | 51 | * |
52 | *@see KProcIO | 52 | *@see KProcIO |
53 | * | 53 | * |
54 | *Basically, this class distinguishes three different ways of running | 54 | *Basically, this class distinguishes three different ways of running |
55 | *child processes: | 55 | *child processes: |
56 | * | 56 | * |
57 | *@li OProcess::DontCare -- The child process is invoked and both the child | 57 | *@li OProcess::DontCare -- The child process is invoked and both the child |
58 | *process and the parent process continue concurrently. | 58 | *process and the parent process continue concurrently. |
59 | * | 59 | * |
60 | *Starting a DontCare child process means that the application is | 60 | *Starting a DontCare child process means that the application is |
61 | *not interested in any notification to determine whether the | 61 | *not interested in any notification to determine whether the |
62 | *child process has already exited or not. | 62 | *child process has already exited or not. |
63 | * | 63 | * |
64 | *@li OProcess::NotifyOnExit -- The child process is invoked and both the | 64 | *@li OProcess::NotifyOnExit -- The child process is invoked and both the |
65 | *child and the parent process run concurrently. | 65 | *child and the parent process run concurrently. |
66 | * | 66 | * |
67 | *When the child process exits, the OProcess instance | 67 | *When the child process exits, the OProcess instance |
68 | *corresponding to it emits the Qt signal @ref processExited(). | 68 | *corresponding to it emits the Qt signal @ref processExited(). |
69 | * | 69 | * |
70 | *Since this signal is @em not emitted from within a UN*X | 70 | *Since this signal is @em not emitted from within a UN*X |
71 | *signal handler, arbitrary function calls can be made. | 71 | *signal handler, arbitrary function calls can be made. |
72 | * | 72 | * |
73 | *Be aware: When the OProcess objects gets destructed, the child | 73 | *Be aware: When the OProcess objects gets destructed, the child |
74 | *process will be killed if it is still running! | 74 | *process will be killed if it is still running! |
75 | *This means in particular, that you cannot use a OProcess on the stack | 75 | *This means in particular, that you cannot use a OProcess on the stack |
76 | *with OProcess::NotifyOnExit. | 76 | *with OProcess::NotifyOnExit. |
77 | * | 77 | * |
78 | *@li OProcess::Block -- The child process starts and the parent process | 78 | *@li OProcess::Block -- The child process starts and the parent process |
79 | *is suspended until the child process exits. (@em Really not recommended | 79 | *is suspended until the child process exits. (@em Really not recommended |
80 | *for programs with a GUI.) | 80 | *for programs with a GUI.) |
81 | * | 81 | * |
82 | *OProcess also provides several functions for determining the exit status | 82 | *OProcess also provides several functions for determining the exit status |
83 | *and the pid of the child process it represents. | 83 | *and the pid of the child process it represents. |
84 | * | 84 | * |
85 | *Furthermore it is possible to supply command-line arguments to the process | 85 | *Furthermore it is possible to supply command-line arguments to the process |
86 | *in a clean fashion (no null -- terminated stringlists and such...) | 86 | *in a clean fashion (no null -- terminated stringlists and such...) |
87 | * | 87 | * |
88 | *A small usage example: | 88 | *A small usage example: |
89 | *<pre> | 89 | *<pre> |
90 | *OProcess *proc = new OProcess; | 90 | *OProcess *proc = new OProcess; |
91 | * | 91 | * |
92 | **proc << "my_executable"; | 92 | **proc << "my_executable"; |
93 | **proc << "These" << "are" << "the" << "command" << "line" << "args"; | 93 | **proc << "These" << "are" << "the" << "command" << "line" << "args"; |
94 | *QApplication::connect(proc, SIGNAL(processExited(OProcess *)), | 94 | *QApplication::connect(proc, SIGNAL(processExited(OProcess *)), |
95 | * pointer_to_my_object, SLOT(my_objects_slot(OProcess *))); | 95 | * pointer_to_my_object, SLOT(my_objects_slot(OProcess *))); |
96 | *proc->start(); | 96 | *proc->start(); |
97 | *</pre> | 97 | *</pre> |
98 | * | 98 | * |
99 | *This will start "my_executable" with the commandline arguments "These"... | 99 | *This will start "my_executable" with the commandline arguments "These"... |
100 | * | 100 | * |
101 | *When the child process exits, the respective Qt signal will be emitted. | 101 | *When the child process exits, the respective Qt signal will be emitted. |
102 | * | 102 | * |
103 | *@sect Communication with the child process | 103 | *@sect Communication with the child process |
104 | * | 104 | * |
105 | *OProcess supports communication with the child process through | 105 | *OProcess supports communication with the child process through |
106 | *stdin/stdout/stderr. | 106 | *stdin/stdout/stderr. |
107 | * | 107 | * |
108 | *The following functions are provided for getting data from the child | 108 | *The following functions are provided for getting data from the child |
109 | *process or sending data to the child's stdin (For more information, | 109 | *process or sending data to the child's stdin (For more information, |
110 | *have a look at the documentation of each function): | 110 | *have a look at the documentation of each function): |
111 | * | 111 | * |
112 | *@li bool @ref writeStdin(char *buffer, int buflen); | 112 | *@li bool @ref writeStdin(char *buffer, int buflen); |
113 | *@li -- Transmit data to the child process's stdin. | 113 | *@li -- Transmit data to the child process's stdin. |
114 | * | 114 | * |
115 | *@li bool @ref closeStdin(); | 115 | *@li bool @ref closeStdin(); |
116 | *@li -- Closes the child process's stdin (which causes it to see an feof(stdin)). | 116 | *@li -- Closes the child process's stdin (which causes it to see an feof(stdin)). |
117 | *Returns false if you try to close stdin for a process that has been started | 117 | *Returns false if you try to close stdin for a process that has been started |
118 | *without a communication channel to stdin. | 118 | *without a communication channel to stdin. |
119 | * | 119 | * |
120 | *@li bool @ref closeStdout(); | 120 | *@li bool @ref closeStdout(); |
121 | *@li -- Closes the child process's stdout. | 121 | *@li -- Closes the child process's stdout. |
122 | *Returns false if you try to close stdout for a process that has been started | 122 | *Returns false if you try to close stdout for a process that has been started |
123 | *without a communication channel to stdout. | 123 | *without a communication channel to stdout. |
124 | * | 124 | * |
125 | *@li bool @ref closeStderr(); | 125 | *@li bool @ref closeStderr(); |
126 | *@li -- Closes the child process's stderr. | 126 | *@li -- Closes the child process's stderr. |
127 | *Returns false if you try to close stderr for a process that has been started | 127 | *Returns false if you try to close stderr for a process that has been started |
128 | *without a communication channel to stderr. | 128 | *without a communication channel to stderr. |
129 | * | 129 | * |
130 | * | 130 | * |
131 | *@sect QT signals: | 131 | *@sect QT signals: |
132 | * | 132 | * |
133 | *@li void @ref receivedStdout(OProcess *proc, char *buffer, int buflen); | 133 | *@li void @ref receivedStdout(OProcess *proc, char *buffer, int buflen); |
134 | *@li void @ref receivedStderr(OProcess *proc, char *buffer, int buflen); | 134 | *@li void @ref receivedStderr(OProcess *proc, char *buffer, int buflen); |
135 | *@li -- Indicates that new data has arrived from either the | 135 | *@li -- Indicates that new data has arrived from either the |
136 | *child process's stdout or stderr. | 136 | *child process's stdout or stderr. |
137 | * | 137 | * |
138 | *@li void @ref wroteStdin(OProcess *proc); | 138 | *@li void @ref wroteStdin(OProcess *proc); |
139 | *@li -- Indicates that all data that has been sent to the child process | 139 | *@li -- Indicates that all data that has been sent to the child process |
140 | *by a prior call to @ref writeStdin() has actually been transmitted to the | 140 | *by a prior call to @ref writeStdin() has actually been transmitted to the |
141 | *client . | 141 | *client . |
142 | * | 142 | * |
143 | *@author Christian Czezakte e9025461@student.tuwien.ac.at | 143 | *@author Christian Czezakte e9025461@student.tuwien.ac.at |
144 | * | 144 | * |
145 | * | 145 | * |
146 | **/ | 146 | **/ |
147 | class OProcess : public QObject | 147 | class OProcess : public QObject |
148 | { | 148 | { |
149 | Q_OBJECT | 149 | Q_OBJECT |
150 | 150 | ||
151 | public: | 151 | public: |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * Modes in which the communication channel can be opened. | 154 | * Modes in which the communication channel can be opened. |
155 | * | 155 | * |
156 | * If communication for more than one channel is required, | 156 | * If communication for more than one channel is required, |
157 | * the values have to be or'ed together, for example to get | 157 | * the values have to be or'ed together, for example to get |
158 | * communication with stdout as well as with stdin, you would | 158 | * communication with stdout as well as with stdin, you would |
159 | * specify @p Stdin @p | @p Stdout | 159 | * specify @p Stdin @p | @p Stdout |
160 | * | 160 | * |
161 | * If @p NoRead is specified in conjunction with @p Stdout, | 161 | * If @p NoRead is specified in conjunction with @p Stdout, |
162 | * no data is actually read from @p Stdout but only | 162 | * no data is actually read from @p Stdout but only |
163 | * the signal @ref childOutput(int fd) is emitted. | 163 | * the signal @ref childOutput(int fd) is emitted. |
164 | */ | 164 | */ |
165 | enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4, | 165 | enum Communication { NoCommunication = 0, Stdin = 1, Stdout = 2, Stderr = 4, |
166 | AllOutput = 6, All = 7, | 166 | AllOutput = 6, All = 7, |
167 | NoRead }; | 167 | NoRead }; |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * Run-modes for a child process. | 170 | * Run-modes for a child process. |
171 | */ | 171 | */ |
172 | enum RunMode { | 172 | enum RunMode { |
173 | /** | 173 | /** |
174 | * The application does not receive notifications from the subprocess when | 174 | * The application does not receive notifications from the subprocess when |
175 | * it is finished or aborted. | 175 | * it is finished or aborted. |
176 | */ | 176 | */ |
177 | DontCare, | 177 | DontCare, |
178 | /** | 178 | /** |
179 | * The application is notified when the subprocess dies. | 179 | * The application is notified when the subprocess dies. |
180 | */ | 180 | */ |
181 | NotifyOnExit, | 181 | NotifyOnExit, |
182 | /** | 182 | /** |
183 | * The application is suspended until the started process is finished. | 183 | * The application is suspended until the started process is finished. |
184 | */ | 184 | */ |
185 | Block }; | 185 | Block }; |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Constructor | 188 | * Constructor |
189 | */ | 189 | */ |
190 | OProcess(); | 190 | OProcess(); |
191 | 191 | ||
192 | /** | 192 | /** |
193 | *Destructor: | 193 | *Destructor: |
194 | * | 194 | * |
195 | * If the process is running when the destructor for this class | 195 | * If the process is running when the destructor for this class |
196 | * is called, the child process is killed with a SIGKILL, but | 196 | * is called, the child process is killed with a SIGKILL, but |
197 | * only if the run mode is not of type @p DontCare. | 197 | * only if the run mode is not of type @p DontCare. |
198 | * Processes started as @p DontCare keep running anyway. | 198 | * Processes started as @p DontCare keep running anyway. |
199 | */ | 199 | */ |
200 | virtual ~OProcess(); | 200 | virtual ~OProcess(); |
201 | 201 | ||
202 | /** | 202 | /** |
203 | @deprecated | 203 | @deprecated |
204 | 204 | ||
205 | The use of this function is now deprecated. -- Please use the | 205 | The use of this function is now deprecated. -- Please use the |
206 | "operator<<" instead of "setExecutable". | 206 | "operator<<" instead of "setExecutable". |
207 | 207 | ||
208 | Sets the executable to be started with this OProcess object. | 208 | Sets the executable to be started with this OProcess object. |
209 | Returns false if the process is currently running (in that | 209 | Returns false if the process is currently running (in that |
210 | case the executable remains unchanged.) | 210 | case the executable remains unchanged.) |
211 | 211 | ||
212 | @see operator<< | 212 | @see operator<< |
213 | 213 | ||
214 | */ | 214 | */ |
215 | bool setExecutable(const QString& proc); | 215 | bool setExecutable(const QString& proc); |
216 | 216 | ||
217 | 217 | ||
218 | /** | 218 | /** |
219 | * Sets the executable and the command line argument list for this process. | 219 | * Sets the executable and the command line argument list for this process. |
220 | * | 220 | * |
221 | * For example, doing an "ls -l /usr/local/bin" can be achieved by: | 221 | * For example, doing an "ls -l /usr/local/bin" can be achieved by: |
222 | * <pre> | 222 | * <pre> |
223 | * OProcess p; | 223 | * OProcess p; |
224 | * ... | 224 | * ... |
225 | * p << "ls" << "-l" << "/usr/local/bin" | 225 | * p << "ls" << "-l" << "/usr/local/bin" |
226 | * </pre> | 226 | * </pre> |
227 | * | 227 | * |
228 | **/ | 228 | **/ |
229 | OProcess &operator<<(const QString& arg); | 229 | OProcess &operator<<(const QString& arg); |
230 | /** | 230 | /** |
231 | * Similar to previous method, takes a char *, supposed to be in locale 8 bit already. | 231 | * Similar to previous method, takes a char *, supposed to be in locale 8 bit already. |
232 | */ | 232 | */ |
233 | OProcess &operator<<(const char * arg); | 233 | OProcess &operator<<(const char * arg); |
234 | /** | 234 | /** |
235 | * Similar to previous method, takes a QCString, supposed to be in locale 8 bit already. | 235 | * Similar to previous method, takes a QCString, supposed to be in locale 8 bit already. |
236 | */ | 236 | */ |
237 | OProcess &operator<<(const QCString & arg); | 237 | OProcess &operator<<(const QCString & arg); |
238 | 238 | ||
239 | /** | 239 | /** |
240 | * Sets the executable and the command line argument list for this process, | 240 | * Sets the executable and the command line argument list for this process, |
241 | * in a single method call, or add a list of arguments. | 241 | * in a single method call, or add a list of arguments. |
242 | **/ | 242 | **/ |
243 | OProcess &operator<<(const QStringList& args); | 243 | OProcess &operator<<(const QStringList& args); |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * Clear a command line argument list that has been set by using | 246 | * Clear a command line argument list that has been set by using |
247 | * the "operator<<". | 247 | * the "operator<<". |
248 | */ | 248 | */ |
249 | void clearArguments(); | 249 | void clearArguments(); |
250 | 250 | ||
251 | /** | 251 | /** |
252 | * Starts the process. | 252 | * Starts the process. |
253 | * For a detailed description of the | 253 | * For a detailed description of the |
254 | * various run modes and communication semantics, have a look at the | 254 | * various run modes and communication semantics, have a look at the |
255 | * general description of the OProcess class. | 255 | * general description of the OProcess class. |
256 | * | 256 | * |
257 | * The following problems could cause this function to | 257 | * The following problems could cause this function to |
258 | * return false: | 258 | * return false: |
259 | * | 259 | * |
260 | * @li The process is already running. | 260 | * @li The process is already running. |
261 | * @li The command line argument list is empty. | 261 | * @li The command line argument list is empty. |
262 | * @li The starting of the process failed (could not fork). | 262 | * @li The starting of the process failed (could not fork). |
263 | * @li The executable was not found. | 263 | * @li The executable was not found. |
264 | * | 264 | * |
265 | * @param comm Specifies which communication links should be | 265 | * @param comm Specifies which communication links should be |
266 | * established to the child process (stdin/stdout/stderr). By default, | 266 | * established to the child process (stdin/stdout/stderr). By default, |
267 | * no communication takes place and the respective communication | 267 | * no communication takes place and the respective communication |
268 | * signals will never get emitted. | 268 | * signals will never get emitted. |
269 | * | 269 | * |
270 | * @return true on success, false on error | 270 | * @return true on success, false on error |
271 | * (see above for error conditions) | 271 | * (see above for error conditions) |
272 | **/ | 272 | **/ |
273 | virtual bool start(RunMode runmode = NotifyOnExit, | 273 | virtual bool start(RunMode runmode = NotifyOnExit, |
274 | Communication comm = NoCommunication); | 274 | Communication comm = NoCommunication); |
275 | 275 | ||
276 | /** | 276 | /** |
277 | * Stop the process (by sending it a signal). | 277 | * Stop the process (by sending it a signal). |
278 | * | 278 | * |
279 | * @param signoThe signal to send. The default is SIGTERM. | 279 | * @param signoThe signal to send. The default is SIGTERM. |
280 | * @return @p true if the signal was delivered successfully. | 280 | * @return @p true if the signal was delivered successfully. |
281 | */ | 281 | */ |
282 | virtual bool kill(int signo = SIGTERM); | 282 | virtual bool kill(int signo = SIGTERM); |
283 | 283 | ||
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index 6b10ec2..1e40c40 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -1,258 +1,266 @@ | |||
1 | 1 | ||
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <opie/tododb.h> | 3 | #include <opie/tododb.h> |
4 | #include <opie/xmltree.h> | 4 | #include <opie/xmltree.h> |
5 | #include <opie/todoresource.h> | 5 | #include <opie/todoresource.h> |
6 | #include <qpe/palmtoprecord.h> | 6 | #include <qpe/palmtoprecord.h> |
7 | #include <qpe/global.h> | 7 | #include <qpe/global.h> |
8 | 8 | ||
9 | using namespace Opie; | 9 | using namespace Opie; |
10 | 10 | ||
11 | namespace { | 11 | namespace { |
12 | 12 | ||
13 | class FileToDoResource : public ToDoResource { | 13 | class FileToDoResource : public ToDoResource { |
14 | public: | 14 | public: |
15 | FileToDoResource() {}; | 15 | FileToDoResource() {}; |
16 | // FIXME better parsing | 16 | // FIXME better parsing |
17 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ | 17 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ |
18 | // prepare the XML | 18 | // prepare the XML |
19 | XMLElement *tasks = new XMLElement( ); | 19 | XMLElement *tasks = new XMLElement( ); |
20 | tasks->setTagName("Tasks" ); | 20 | tasks->setTagName("Tasks" ); |
21 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ | 21 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ |
22 | XMLElement::AttributeMap map; | 22 | XMLElement::AttributeMap map; |
23 | XMLElement *task = new XMLElement(); | 23 | XMLElement *task = new XMLElement(); |
24 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); | 24 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); |
25 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); | 25 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); |
26 | map.insert( "Priority", QString::number( (*it).priority() ) ); | 26 | map.insert( "Priority", QString::number( (*it).priority() ) ); |
27 | map.insert( "Progress", QString::number( (*it).progress() ) ); | ||
27 | map.insert( "Summary", (*it).summary() ); | 28 | map.insert( "Summary", (*it).summary() ); |
28 | QArray<int> arrat = (*it).categories(); | 29 | QArray<int> arrat = (*it).categories(); |
29 | QString attr; | 30 | QString attr; |
30 | for(uint i=0; i < arrat.count(); i++ ){ | 31 | for(uint i=0; i < arrat.count(); i++ ){ |
31 | attr.append(QString::number(arrat[i])+";" ); | 32 | attr.append(QString::number(arrat[i])+";" ); |
32 | } | 33 | } |
33 | if(!attr.isEmpty() ) // remove the last ; | 34 | if(!attr.isEmpty() ) // remove the last ; |
34 | attr.remove(attr.length()-1, 1 ); | 35 | attr.remove(attr.length()-1, 1 ); |
35 | map.insert( "Categories", attr ); | 36 | map.insert( "Categories", attr ); |
36 | //else | 37 | //else |
37 | //map.insert( "Categories", QString::null ); | 38 | //map.insert( "Categories", QString::null ); |
38 | map.insert( "Description", (*it).description() ); | 39 | map.insert( "Description", (*it).description() ); |
39 | if( (*it).hasDate() ){ | 40 | if( (*it).hasDate() ){ |
40 | map.insert("DateYear", QString::number( (*it).date().year() ) ); | 41 | map.insert("DateYear", QString::number( (*it).date().year() ) ); |
41 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); | 42 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); |
42 | map.insert("DateDay", QString::number( (*it).date().day() ) ); | 43 | map.insert("DateDay", QString::number( (*it).date().day() ) ); |
43 | } | 44 | } |
44 | map.insert("Uid", QString::number( (*it).uid() ) ); | 45 | map.insert("Uid", QString::number( (*it).uid() ) ); |
45 | task->setTagName("Task" ); | 46 | task->setTagName("Task" ); |
46 | task->setAttributes( map ); | 47 | task->setAttributes( map ); |
47 | tasks->appendChild(task); | 48 | tasks->appendChild(task); |
48 | } | 49 | } |
49 | QFile file( name); | 50 | QFile file( name); |
50 | if( file.open(IO_WriteOnly ) ){ | 51 | if( file.open(IO_WriteOnly ) ){ |
51 | QTextStream stream(&file ); | 52 | QTextStream stream(&file ); |
52 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | 53 | stream.setEncoding( QTextStream::UnicodeUTF8 ); |
53 | stream << "<!DOCTYPE Tasks>" << endl; | 54 | stream << "<!DOCTYPE Tasks>" << endl; |
54 | tasks->save(stream ); | 55 | tasks->save(stream ); |
55 | delete tasks; | 56 | delete tasks; |
56 | stream << "</Tasks>" << endl; | 57 | stream << "</Tasks>" << endl; |
57 | file.close(); | 58 | file.close(); |
58 | return true; | 59 | return true; |
59 | } | 60 | } |
60 | return false; | 61 | return false; |
61 | } | 62 | } |
62 | QValueList<ToDoEvent> load( const QString &name ){ | 63 | QValueList<ToDoEvent> load( const QString &name ){ |
63 | qWarning("loading tododb" ); | 64 | qWarning("loading tododb" ); |
64 | QValueList<ToDoEvent> m_todos; | 65 | QValueList<ToDoEvent> m_todos; |
65 | XMLElement *root = XMLElement::load( name ); | 66 | XMLElement *root = XMLElement::load( name ); |
66 | if(root != 0l ){ // start parsing | 67 | if(root != 0l ){ // start parsing |
67 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); | 68 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); |
68 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start | 69 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start |
69 | XMLElement *element = root->firstChild(); | 70 | XMLElement *element = root->firstChild(); |
70 | element = element->firstChild(); | 71 | element = element->firstChild(); |
71 | while( element ){ | 72 | while( element ){ |
72 | if( element->tagName() != QString::fromLatin1("Task") ){ | 73 | if( element->tagName() != QString::fromLatin1("Task") ){ |
73 | element = element->nextChild(); | 74 | element = element->nextChild(); |
74 | continue; | 75 | continue; |
75 | } | 76 | } |
76 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); | 77 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); |
77 | QString dummy; | 78 | QString dummy; |
78 | ToDoEvent event; | 79 | ToDoEvent event; |
79 | bool ok; | 80 | bool ok; |
80 | int dumInt; | 81 | int dumInt; |
81 | // completed | 82 | // completed |
82 | dummy = element->attribute("Completed" ); | 83 | dummy = element->attribute("Completed" ); |
83 | dumInt = dummy.toInt(&ok ); | 84 | dumInt = dummy.toInt(&ok ); |
84 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); | 85 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); |
86 | // progress | ||
87 | dummy = element->attribute("Progress" ); | ||
88 | { | ||
89 | ushort dumShort = dummy.toUShort(&ok); | ||
90 | event.setProgress( dumShort ); | ||
91 | |||
92 | } | ||
85 | // hasDate | 93 | // hasDate |
86 | dummy = element->attribute("HasDate" ); | 94 | dummy = element->attribute("HasDate" ); |
87 | dumInt = dummy.toInt(&ok ); | 95 | dumInt = dummy.toInt(&ok ); |
88 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); | 96 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); |
89 | // set the date | 97 | // set the date |
90 | bool hasDa = dumInt; | 98 | bool hasDa = dumInt; |
91 | if ( hasDa ) { //parse the date | 99 | if ( hasDa ) { //parse the date |
92 | int year, day, month = 0; | 100 | int year, day, month = 0; |
93 | year = day = month; | 101 | year = day = month; |
94 | // year | 102 | // year |
95 | dummy = element->attribute("DateYear" ); | 103 | dummy = element->attribute("DateYear" ); |
96 | dumInt = dummy.toInt(&ok ); | 104 | dumInt = dummy.toInt(&ok ); |
97 | if( ok ) year = dumInt; | 105 | if( ok ) year = dumInt; |
98 | // month | 106 | // month |
99 | dummy = element->attribute("DateMonth" ); | 107 | dummy = element->attribute("DateMonth" ); |
100 | dumInt = dummy.toInt(&ok ); | 108 | dumInt = dummy.toInt(&ok ); |
101 | if(ok ) month = dumInt; | 109 | if(ok ) month = dumInt; |
102 | dummy = element->attribute("DateDay" ); | 110 | dummy = element->attribute("DateDay" ); |
103 | dumInt = dummy.toInt(&ok ); | 111 | dumInt = dummy.toInt(&ok ); |
104 | if(ok ) day = dumInt; | 112 | if(ok ) day = dumInt; |
105 | // set the date | 113 | // set the date |
106 | QDate date( year, month, day ); | 114 | QDate date( year, month, day ); |
107 | event.setDate( date); | 115 | event.setDate( date); |
108 | } | 116 | } |
109 | dummy = element->attribute("Priority" ); | 117 | dummy = element->attribute("Priority" ); |
110 | dumInt = dummy.toInt(&ok ); | 118 | dumInt = dummy.toInt(&ok ); |
111 | if(!ok ) dumInt = ToDoEvent::NORMAL; | 119 | if(!ok ) dumInt = ToDoEvent::NORMAL; |
112 | event.setPriority( dumInt ); | 120 | event.setPriority( dumInt ); |
113 | //description | 121 | //description |
114 | dummy = element->attribute("Description" ); | 122 | dummy = element->attribute("Description" ); |
115 | event.setDescription( dummy ); | 123 | event.setDescription( dummy ); |
116 | dummy = element->attribute("Summary" ); | 124 | dummy = element->attribute("Summary" ); |
117 | event.setSummary( dummy ); | 125 | event.setSummary( dummy ); |
118 | // category | 126 | // category |
119 | dummy = element->attribute("Categories" ); | 127 | dummy = element->attribute("Categories" ); |
120 | QStringList ids = QStringList::split(";", dummy ); | 128 | QStringList ids = QStringList::split(";", dummy ); |
121 | event.setCategories( ids ); | 129 | event.setCategories( ids ); |
122 | 130 | ||
123 | //uid | 131 | //uid |
124 | dummy = element->attribute("Uid" ); | 132 | dummy = element->attribute("Uid" ); |
125 | dumInt = dummy.toInt(&ok ); | 133 | dumInt = dummy.toInt(&ok ); |
126 | if(ok ) event.setUid( dumInt ); | 134 | if(ok ) event.setUid( dumInt ); |
127 | m_todos.append( event ); | 135 | m_todos.append( event ); |
128 | element = element->nextChild(); // next element | 136 | element = element->nextChild(); // next element |
129 | } | 137 | } |
130 | //} | 138 | //} |
131 | }else { | 139 | }else { |
132 | qWarning("could not load" ); | 140 | qWarning("could not load" ); |
133 | } | 141 | } |
134 | delete root; | 142 | delete root; |
135 | qWarning("returning" ); | 143 | qWarning("returning" ); |
136 | return m_todos; | 144 | return m_todos; |
137 | } | 145 | } |
138 | }; | 146 | }; |
139 | 147 | ||
140 | } | 148 | } |
141 | 149 | ||
142 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ | 150 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ |
143 | m_fileName = fileName; | 151 | m_fileName = fileName; |
144 | if( fileName.isEmpty() && res == 0 ){ | 152 | if( fileName.isEmpty() && res == 0 ){ |
145 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); | 153 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); |
146 | res = new FileToDoResource(); | 154 | res = new FileToDoResource(); |
147 | //qWarning("%s", m_fileName.latin1() ); | 155 | //qWarning("%s", m_fileName.latin1() ); |
148 | }else if(res == 0 ){ // let's create a ToDoResource for xml | 156 | }else if(res == 0 ){ // let's create a ToDoResource for xml |
149 | res = new FileToDoResource(); | 157 | res = new FileToDoResource(); |
150 | } | 158 | } |
151 | m_res = res; | 159 | m_res = res; |
152 | load(); | 160 | load(); |
153 | } | 161 | } |
154 | ToDoResource* ToDoDB::resource(){ | 162 | ToDoResource* ToDoDB::resource(){ |
155 | return m_res; | 163 | return m_res; |
156 | }; | 164 | }; |
157 | void ToDoDB::setResource( ToDoResource *res ) | 165 | void ToDoDB::setResource( ToDoResource *res ) |
158 | { | 166 | { |
159 | delete m_res; | 167 | delete m_res; |
160 | m_res = res; | 168 | m_res = res; |
161 | } | 169 | } |
162 | ToDoDB::~ToDoDB() | 170 | ToDoDB::~ToDoDB() |
163 | { | 171 | { |
164 | delete m_res; | 172 | delete m_res; |
165 | } | 173 | } |
166 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, | 174 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, |
167 | bool all ) | 175 | bool all ) |
168 | { | 176 | { |
169 | QValueList<ToDoEvent> events; | 177 | QValueList<ToDoEvent> events; |
170 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 178 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
171 | if( (*it).hasDate() ){ | 179 | if( (*it).hasDate() ){ |
172 | if( (*it).date() >= from && (*it).date() <= to ) | 180 | if( (*it).date() >= from && (*it).date() <= to ) |
173 | events.append( (*it) ); | 181 | events.append( (*it) ); |
174 | }else if( all ){ | 182 | }else if( all ){ |
175 | events.append( (*it) ); | 183 | events.append( (*it) ); |
176 | } | 184 | } |
177 | } | 185 | } |
178 | return events; | 186 | return events; |
179 | } | 187 | } |
180 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, | 188 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, |
181 | bool all) | 189 | bool all) |
182 | { | 190 | { |
183 | return effectiveToDos( from, QDate::currentDate(), all ); | 191 | return effectiveToDos( from, QDate::currentDate(), all ); |
184 | } | 192 | } |
185 | QValueList<ToDoEvent> ToDoDB::overDue() | 193 | QValueList<ToDoEvent> ToDoDB::overDue() |
186 | { | 194 | { |
187 | QValueList<ToDoEvent> events; | 195 | QValueList<ToDoEvent> events; |
188 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 196 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
189 | if( (*it).isOverdue() ) | 197 | if( (*it).isOverdue() ) |
190 | events.append((*it) ); | 198 | events.append((*it) ); |
191 | } | 199 | } |
192 | return events; | 200 | return events; |
193 | } | 201 | } |
194 | QValueList<ToDoEvent> ToDoDB::rawToDos() | 202 | QValueList<ToDoEvent> ToDoDB::rawToDos() |
195 | { | 203 | { |
196 | return m_todos; | 204 | return m_todos; |
197 | } | 205 | } |
198 | void ToDoDB::addEvent( const ToDoEvent &event ) | 206 | void ToDoDB::addEvent( const ToDoEvent &event ) |
199 | { | 207 | { |
200 | m_todos.append( event ); | 208 | m_todos.append( event ); |
201 | } | 209 | } |
202 | void ToDoDB::editEvent( const ToDoEvent &event ) | 210 | void ToDoDB::editEvent( const ToDoEvent &event ) |
203 | { | 211 | { |
204 | m_todos.remove( event ); | 212 | m_todos.remove( event ); |
205 | m_todos.append( event ); | 213 | m_todos.append( event ); |
206 | } | 214 | } |
207 | void ToDoDB::removeEvent( const ToDoEvent &event ) | 215 | void ToDoDB::removeEvent( const ToDoEvent &event ) |
208 | { | 216 | { |
209 | m_todos.remove( event ); | 217 | m_todos.remove( event ); |
210 | } | 218 | } |
211 | void ToDoDB::replaceEvent(const ToDoEvent &event ) | 219 | void ToDoDB::replaceEvent(const ToDoEvent &event ) |
212 | { | 220 | { |
213 | QValueList<ToDoEvent>::Iterator it; | 221 | QValueList<ToDoEvent>::Iterator it; |
214 | int uid = event.uid(); | 222 | int uid = event.uid(); |
215 | // == is not overloaded as we would like :( so let's search for the uid | 223 | // == is not overloaded as we would like :( so let's search for the uid |
216 | for(it = m_todos.begin(); it != m_todos.end(); ++it ){ | 224 | for(it = m_todos.begin(); it != m_todos.end(); ++it ){ |
217 | if( (*it).uid() == uid ){ | 225 | if( (*it).uid() == uid ){ |
218 | m_todos.remove( (*it) ); | 226 | m_todos.remove( (*it) ); |
219 | break; // should save us the iterate is now borked | 227 | break; // should save us the iterate is now borked |
220 | } | 228 | } |
221 | } | 229 | } |
222 | m_todos.append(event); | 230 | m_todos.append(event); |
223 | } | 231 | } |
224 | void ToDoDB::reload() | 232 | void ToDoDB::reload() |
225 | { | 233 | { |
226 | load(); | 234 | load(); |
227 | } | 235 | } |
228 | void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events ) | 236 | void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events ) |
229 | { | 237 | { |
230 | QValueList<ToDoEvent>::ConstIterator it; | 238 | QValueList<ToDoEvent>::ConstIterator it; |
231 | for( it = events.begin(); it != events.end(); ++it ){ | 239 | for( it = events.begin(); it != events.end(); ++it ){ |
232 | replaceEvent( (*it) ); | 240 | replaceEvent( (*it) ); |
233 | } | 241 | } |
234 | } | 242 | } |
235 | void ToDoDB::setFileName(const QString &file ) | 243 | void ToDoDB::setFileName(const QString &file ) |
236 | { | 244 | { |
237 | m_fileName =file; | 245 | m_fileName =file; |
238 | } | 246 | } |
239 | QString ToDoDB::fileName()const | 247 | QString ToDoDB::fileName()const |
240 | { | 248 | { |
241 | return m_fileName; | 249 | return m_fileName; |
242 | } | 250 | } |
243 | void ToDoDB::load() | 251 | void ToDoDB::load() |
244 | { | 252 | { |
245 | m_todos = m_res->load( m_fileName ); | 253 | m_todos = m_res->load( m_fileName ); |
246 | } | 254 | } |
247 | bool ToDoDB::save() | 255 | bool ToDoDB::save() |
248 | { | 256 | { |
249 | return m_res->save( m_fileName, m_todos ); | 257 | return m_res->save( m_fileName, m_todos ); |
250 | } | 258 | } |
251 | 259 | ||
252 | 260 | ||
253 | 261 | ||
254 | 262 | ||
255 | 263 | ||
256 | 264 | ||
257 | 265 | ||
258 | 266 | ||
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp index fb7073c..b35ac9d 100644 --- a/libopie/todoevent.cpp +++ b/libopie/todoevent.cpp | |||
@@ -1,269 +1,282 @@ | |||
1 | 1 | ||
2 | #include <opie/todoevent.h> | 2 | #include <opie/todoevent.h> |
3 | 3 | ||
4 | 4 | ||
5 | #include <qpe/palmtopuidgen.h> | 5 | #include <qpe/palmtopuidgen.h> |
6 | #include <qpe/stringutil.h> | 6 | #include <qpe/stringutil.h> |
7 | #include <qpe/palmtoprecord.h> | 7 | #include <qpe/palmtoprecord.h> |
8 | 8 | ||
9 | #include <qpe/stringutil.h> | 9 | #include <qpe/stringutil.h> |
10 | #include <qpe/categories.h> | 10 | #include <qpe/categories.h> |
11 | #include <qpe/categoryselect.h> | 11 | #include <qpe/categoryselect.h> |
12 | 12 | ||
13 | #include <qobject.h> | 13 | #include <qobject.h> |
14 | 14 | ||
15 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) | 15 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) |
16 | { | 16 | { |
17 | *this = event; | 17 | *this = event; |
18 | } | 18 | } |
19 | 19 | ||
20 | ToDoEvent::ToDoEvent(bool completed, int priority, | 20 | ToDoEvent::ToDoEvent(bool completed, int priority, |
21 | const QStringList &category, | 21 | const QStringList &category, |
22 | const QString& summary, | 22 | const QString& summary, |
23 | const QString &description, | 23 | const QString &description, |
24 | ushort progress, | ||
24 | bool hasDate, QDate date, int uid ) | 25 | bool hasDate, QDate date, int uid ) |
25 | { | 26 | { |
26 | m_date = date; | 27 | m_date = date; |
27 | m_isCompleted = completed; | 28 | m_isCompleted = completed; |
28 | m_hasDate = hasDate; | 29 | m_hasDate = hasDate; |
29 | m_priority = priority; | 30 | m_priority = priority; |
30 | m_category = category; | 31 | m_category = category; |
31 | m_sum = summary; | 32 | m_sum = summary; |
33 | m_prog = progress; | ||
32 | m_desc = Qtopia::simplifyMultiLineSpace(description ); | 34 | m_desc = Qtopia::simplifyMultiLineSpace(description ); |
33 | if (uid == -1 ) { | 35 | if (uid == -1 ) { |
34 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); | 36 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); |
35 | uid = uidgen->generate(); | 37 | uid = uidgen->generate(); |
36 | delete uidgen; | 38 | delete uidgen; |
37 | }// generate the ids | 39 | }// generate the ids |
38 | m_uid = uid; | 40 | m_uid = uid; |
39 | } | 41 | } |
40 | QArray<int> ToDoEvent::categories()const | 42 | QArray<int> ToDoEvent::categories()const |
41 | { | 43 | { |
42 | QArray<int> array(m_category.count() ); // currently the datebook can be only in one category | 44 | QArray<int> array(m_category.count() ); // currently the datebook can be only in one category |
43 | array = Qtopia::Record::idsFromString( m_category.join(";") ); | 45 | array = Qtopia::Record::idsFromString( m_category.join(";") ); |
44 | return array; | 46 | return array; |
45 | } | 47 | } |
46 | bool ToDoEvent::match( const QRegExp ®Exp )const | 48 | bool ToDoEvent::match( const QRegExp ®Exp )const |
47 | { | 49 | { |
48 | if( QString::number( m_priority ).find( regExp ) != -1 ){ | 50 | if( QString::number( m_priority ).find( regExp ) != -1 ){ |
49 | return true; | 51 | return true; |
50 | }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ | 52 | }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ |
51 | return true; | 53 | return true; |
52 | }else if(m_desc.find( regExp ) != -1 ){ | 54 | }else if(m_desc.find( regExp ) != -1 ){ |
53 | return true; | 55 | return true; |
54 | } | 56 | } |
55 | return false; | 57 | return false; |
56 | } | 58 | } |
57 | bool ToDoEvent::isCompleted() const | 59 | bool ToDoEvent::isCompleted() const |
58 | { | 60 | { |
59 | return m_isCompleted; | 61 | return m_isCompleted; |
60 | } | 62 | } |
61 | bool ToDoEvent::hasDate() const | 63 | bool ToDoEvent::hasDate() const |
62 | { | 64 | { |
63 | return m_hasDate; | 65 | return m_hasDate; |
64 | } | 66 | } |
65 | int ToDoEvent::priority()const | 67 | int ToDoEvent::priority()const |
66 | { | 68 | { |
67 | return m_priority; | 69 | return m_priority; |
68 | } | 70 | } |
69 | QStringList ToDoEvent::allCategories()const | 71 | QStringList ToDoEvent::allCategories()const |
70 | { | 72 | { |
71 | return m_category; | 73 | return m_category; |
72 | } | 74 | } |
73 | QString ToDoEvent::extra(const QString& )const | 75 | QString ToDoEvent::extra(const QString& )const |
74 | { | 76 | { |
75 | return QString::null; | 77 | return QString::null; |
76 | } | 78 | } |
77 | QString ToDoEvent::summary() const | 79 | QString ToDoEvent::summary() const |
78 | { | 80 | { |
79 | return m_sum; | 81 | return m_sum; |
80 | } | 82 | } |
83 | ushort ToDoEvent::progress() const | ||
84 | { | ||
85 | return m_prog; | ||
86 | } | ||
81 | void ToDoEvent::insertCategory(const QString &str ) | 87 | void ToDoEvent::insertCategory(const QString &str ) |
82 | { | 88 | { |
83 | m_category.append( str ); | 89 | m_category.append( str ); |
84 | } | 90 | } |
85 | void ToDoEvent::clearCategories() | 91 | void ToDoEvent::clearCategories() |
86 | { | 92 | { |
87 | m_category.clear(); | 93 | m_category.clear(); |
88 | } | 94 | } |
89 | void ToDoEvent::setCategories(const QStringList &list ) | 95 | void ToDoEvent::setCategories(const QStringList &list ) |
90 | { | 96 | { |
91 | m_category = list; | 97 | m_category = list; |
92 | } | 98 | } |
93 | QDate ToDoEvent::date()const | 99 | QDate ToDoEvent::date()const |
94 | { | 100 | { |
95 | return m_date; | 101 | return m_date; |
96 | } | 102 | } |
97 | 103 | ||
98 | QString ToDoEvent::description()const | 104 | QString ToDoEvent::description()const |
99 | { | 105 | { |
100 | return m_desc; | 106 | return m_desc; |
101 | } | 107 | } |
102 | void ToDoEvent::setCompleted( bool completed ) | 108 | void ToDoEvent::setCompleted( bool completed ) |
103 | { | 109 | { |
104 | m_isCompleted = completed; | 110 | m_isCompleted = completed; |
105 | } | 111 | } |
106 | void ToDoEvent::setHasDate( bool hasDate ) | 112 | void ToDoEvent::setHasDate( bool hasDate ) |
107 | { | 113 | { |
108 | m_hasDate = hasDate; | 114 | m_hasDate = hasDate; |
109 | } | 115 | } |
110 | void ToDoEvent::setDescription(const QString &desc ) | 116 | void ToDoEvent::setDescription(const QString &desc ) |
111 | { | 117 | { |
112 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); | 118 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); |
113 | } | 119 | } |
114 | void ToDoEvent::setExtra( const QString&, const QString& ) | 120 | void ToDoEvent::setExtra( const QString&, const QString& ) |
115 | { | 121 | { |
116 | 122 | ||
117 | } | 123 | } |
118 | void ToDoEvent::setSummary( const QString& sum ) | 124 | void ToDoEvent::setSummary( const QString& sum ) |
119 | { | 125 | { |
120 | m_sum = sum; | 126 | m_sum = sum; |
121 | } | 127 | } |
122 | void ToDoEvent::setCategory( const QString &cat ) | 128 | void ToDoEvent::setCategory( const QString &cat ) |
123 | { | 129 | { |
124 | qWarning("setCategory %s", cat.latin1() ); | 130 | qWarning("setCategory %s", cat.latin1() ); |
125 | m_category.clear(); | 131 | m_category.clear(); |
126 | m_category << cat; | 132 | m_category << cat; |
127 | } | 133 | } |
128 | void ToDoEvent::setPriority(int prio ) | 134 | void ToDoEvent::setPriority(int prio ) |
129 | { | 135 | { |
130 | m_priority = prio; | 136 | m_priority = prio; |
131 | } | 137 | } |
132 | void ToDoEvent::setDate( QDate date ) | 138 | void ToDoEvent::setDate( QDate date ) |
133 | { | 139 | { |
134 | m_date = date; | 140 | m_date = date; |
135 | } | 141 | } |
136 | bool ToDoEvent::isOverdue( ) | 142 | bool ToDoEvent::isOverdue( ) |
137 | { | 143 | { |
138 | if( m_hasDate ) | 144 | if( m_hasDate ) |
139 | return QDate::currentDate() > m_date; | 145 | return QDate::currentDate() > m_date; |
140 | return false; | 146 | return false; |
141 | } | 147 | } |
142 | 148 | void ToDoEvent::setProgress(ushort progress ) | |
149 | { | ||
150 | m_prog = progress; | ||
151 | } | ||
143 | /*! | 152 | /*! |
144 | Returns a richt text string | 153 | Returns a richt text string |
145 | */ | 154 | */ |
146 | QString ToDoEvent::richText() const | 155 | QString ToDoEvent::richText() const |
147 | { | 156 | { |
148 | QString text; | 157 | QString text; |
149 | QStringList catlist; | 158 | QStringList catlist; |
150 | 159 | ||
151 | // Description of the todo | 160 | // Description of the todo |
152 | if ( !description().isEmpty() ){ | 161 | if ( !description().isEmpty() ){ |
153 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; | 162 | text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; |
154 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; | 163 | text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; |
155 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | 164 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; |
156 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; | 165 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br><br><br>"; |
157 | } | 166 | } |
158 | text += "<b>" + QObject::tr( "Priority:") +" </b>" | 167 | text += "<b>" + QObject::tr( "Priority:") +" </b>" |
159 | + QString::number( priority() ) + "<br>"; | 168 | + QString::number( priority() ) + " <br>"; |
169 | text += "<b>" + QObject::tr( "Progress:") + " </b>" | ||
170 | + QString::number( progress() ) + " %<br>"; | ||
160 | if (hasDate() ){ | 171 | if (hasDate() ){ |
161 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; | 172 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; |
162 | text += date().toString(); | 173 | text += date().toString(); |
163 | text += "<br>"; | 174 | text += "<br>"; |
164 | } | 175 | } |
165 | 176 | ||
166 | // Open database of all categories and get the list of | 177 | // Open database of all categories and get the list of |
167 | // the categories this todoevent belongs to. | 178 | // the categories this todoevent belongs to. |
168 | // Then print them... | 179 | // Then print them... |
169 | // I am not sure whether there is no better way doing this !? | 180 | // I am not sure whether there is no better way doing this !? |
170 | Categories catdb; | 181 | Categories catdb; |
171 | bool firstloop = true; | 182 | bool firstloop = true; |
172 | catdb.load( categoryFileName() ); | 183 | catdb.load( categoryFileName() ); |
173 | catlist = allCategories(); | 184 | catlist = allCategories(); |
174 | 185 | ||
175 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 186 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
176 | for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) { | 187 | for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) { |
177 | if (!firstloop){ | 188 | if (!firstloop){ |
178 | text += ", "; | 189 | text += ", "; |
179 | } | 190 | } |
180 | firstloop = false; | 191 | firstloop = false; |
181 | text += catdb.label ("todo", (*it).toInt()); | 192 | text += catdb.label ("todo", (*it).toInt()); |
182 | } | 193 | } |
183 | text += "<br>"; | 194 | text += "<br>"; |
184 | return text; | 195 | return text; |
185 | } | 196 | } |
186 | 197 | ||
187 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ | 198 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ |
188 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 199 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
189 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 200 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
190 | if( hasDate() && toDoEvent.hasDate() ){ | 201 | if( hasDate() && toDoEvent.hasDate() ){ |
191 | if( date() == toDoEvent.date() ){ // let's the priority decide | 202 | if( date() == toDoEvent.date() ){ // let's the priority decide |
192 | return priority() < toDoEvent.priority(); | 203 | return priority() < toDoEvent.priority(); |
193 | }else{ | 204 | }else{ |
194 | return date() < toDoEvent.date(); | 205 | return date() < toDoEvent.date(); |
195 | } | 206 | } |
196 | } | 207 | } |
197 | return false; | 208 | return false; |
198 | } | 209 | } |
199 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const | 210 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const |
200 | { | 211 | { |
201 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 212 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
202 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 213 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
203 | if( hasDate() && toDoEvent.hasDate() ){ | 214 | if( hasDate() && toDoEvent.hasDate() ){ |
204 | if( date() == toDoEvent.date() ){ // let's the priority decide | 215 | if( date() == toDoEvent.date() ){ // let's the priority decide |
205 | return priority() <= toDoEvent.priority(); | 216 | return priority() <= toDoEvent.priority(); |
206 | }else{ | 217 | }else{ |
207 | return date() <= toDoEvent.date(); | 218 | return date() <= toDoEvent.date(); |
208 | } | 219 | } |
209 | } | 220 | } |
210 | return true; | 221 | return true; |
211 | } | 222 | } |
212 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const | 223 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const |
213 | { | 224 | { |
214 | if( !hasDate() && !toDoEvent.hasDate() ) return false; | 225 | if( !hasDate() && !toDoEvent.hasDate() ) return false; |
215 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 226 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
216 | if( hasDate() && toDoEvent.hasDate() ){ | 227 | if( hasDate() && toDoEvent.hasDate() ){ |
217 | if( date() == toDoEvent.date() ){ // let's the priority decide | 228 | if( date() == toDoEvent.date() ){ // let's the priority decide |
218 | return priority() > toDoEvent.priority(); | 229 | return priority() > toDoEvent.priority(); |
219 | }else{ | 230 | }else{ |
220 | return date() > toDoEvent.date(); | 231 | return date() > toDoEvent.date(); |
221 | } | 232 | } |
222 | } | 233 | } |
223 | return false; | 234 | return false; |
224 | } | 235 | } |
225 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const | 236 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const |
226 | { | 237 | { |
227 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 238 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
228 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 239 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
229 | if( hasDate() && toDoEvent.hasDate() ){ | 240 | if( hasDate() && toDoEvent.hasDate() ){ |
230 | if( date() == toDoEvent.date() ){ // let's the priority decide | 241 | if( date() == toDoEvent.date() ){ // let's the priority decide |
231 | return priority() > toDoEvent.priority(); | 242 | return priority() > toDoEvent.priority(); |
232 | }else{ | 243 | }else{ |
233 | return date() > toDoEvent.date(); | 244 | return date() > toDoEvent.date(); |
234 | } | 245 | } |
235 | } | 246 | } |
236 | return true; | 247 | return true; |
237 | } | 248 | } |
238 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const | 249 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const |
239 | { | 250 | { |
240 | if( m_priority == toDoEvent.m_priority && | 251 | if( m_priority == toDoEvent.m_priority && |
252 | m_priority == toDoEvent.m_prog && | ||
241 | m_isCompleted == toDoEvent.m_isCompleted && | 253 | m_isCompleted == toDoEvent.m_isCompleted && |
242 | m_hasDate == toDoEvent.m_hasDate && | 254 | m_hasDate == toDoEvent.m_hasDate && |
243 | m_date == toDoEvent.m_date && | 255 | m_date == toDoEvent.m_date && |
244 | m_category == toDoEvent.m_category && | 256 | m_category == toDoEvent.m_category && |
245 | m_sum == toDoEvent.m_sum && | 257 | m_sum == toDoEvent.m_sum && |
246 | m_desc == toDoEvent.m_desc ) | 258 | m_desc == toDoEvent.m_desc ) |
247 | return true; | 259 | return true; |
248 | return false; | 260 | return false; |
249 | } | 261 | } |
250 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) | 262 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) |
251 | { | 263 | { |
252 | m_date = item.m_date; | 264 | m_date = item.m_date; |
253 | m_isCompleted = item.m_isCompleted; | 265 | m_isCompleted = item.m_isCompleted; |
254 | m_hasDate = item.m_hasDate; | 266 | m_hasDate = item.m_hasDate; |
255 | m_priority = item.m_priority; | 267 | m_priority = item.m_priority; |
256 | m_category = item.m_category; | 268 | m_category = item.m_category; |
257 | m_desc = item.m_desc; | 269 | m_desc = item.m_desc; |
258 | m_uid = item.m_uid; | 270 | m_uid = item.m_uid; |
259 | m_sum = item.m_sum; | 271 | m_sum = item.m_sum; |
272 | m_prog = item.m_prog; | ||
260 | return *this; | 273 | return *this; |
261 | } | 274 | } |
262 | 275 | ||
263 | 276 | ||
264 | 277 | ||
265 | 278 | ||
266 | 279 | ||
267 | 280 | ||
268 | 281 | ||
269 | 282 | ||
diff --git a/libopie/todoevent.h b/libopie/todoevent.h index 7454241..de4623f 100644 --- a/libopie/todoevent.h +++ b/libopie/todoevent.h | |||
@@ -1,151 +1,162 @@ | |||
1 | 1 | ||
2 | #ifndef todoevent_h | 2 | #ifndef todoevent_h |
3 | #define todoevent_h | 3 | #define todoevent_h |
4 | 4 | ||
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qregexp.h> | 6 | #include <qregexp.h> |
7 | #include <qstringlist.h> | 7 | #include <qstringlist.h> |
8 | #include <qdatetime.h> | 8 | #include <qdatetime.h> |
9 | 9 | ||
10 | class ToDoEvent { | 10 | class ToDoEvent { |
11 | friend class ToDoDB; | 11 | friend class ToDoDB; |
12 | public: | 12 | public: |
13 | // priorities from Very low to very high | 13 | // priorities from Very low to very high |
14 | enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; | 14 | enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; |
15 | /* Constructs a new ToDoEvent | 15 | /* Constructs a new ToDoEvent |
16 | @param completed Is the TodoEvent completed | 16 | @param completed Is the TodoEvent completed |
17 | @param priority What is the priority of this ToDoEvent | 17 | @param priority What is the priority of this ToDoEvent |
18 | @param category Which category does it belong( uid ) | 18 | @param category Which category does it belong( uid ) |
19 | @param summary A small summary of the todo | 19 | @param summary A small summary of the todo |
20 | @param description What is this ToDoEvent about | 20 | @param description What is this ToDoEvent about |
21 | @param hasDate Does this Event got a deadline | 21 | @param hasDate Does this Event got a deadline |
22 | @param date what is the deadline? | 22 | @param date what is the deadline? |
23 | @param uid what is the UUID of this Event | 23 | @param uid what is the UUID of this Event |
24 | **/ | 24 | **/ |
25 | ToDoEvent( bool completed = false, int priority = NORMAL, | 25 | ToDoEvent( bool completed = false, int priority = NORMAL, |
26 | const QStringList &category = QStringList(), | 26 | const QStringList &category = QStringList(), |
27 | const QString &summary = QString::null , | 27 | const QString &summary = QString::null , |
28 | const QString &description = QString::null, | 28 | const QString &description = QString::null, |
29 | ushort progress = 0, | ||
29 | bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); | 30 | bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); |
30 | /* Copy c'tor | 31 | /* Copy c'tor |
31 | 32 | ||
32 | **/ | 33 | **/ |
33 | ToDoEvent(const ToDoEvent & ); | 34 | ToDoEvent(const ToDoEvent & ); |
34 | 35 | ||
35 | /* | 36 | /* |
36 | Is this event completed? | 37 | Is this event completed? |
37 | **/ | 38 | **/ |
38 | bool isCompleted() const; | 39 | bool isCompleted() const; |
39 | 40 | ||
40 | /* | 41 | /* |
41 | Does this Event have a deadline | 42 | Does this Event have a deadline |
42 | **/ | 43 | **/ |
43 | bool hasDate() const; | 44 | bool hasDate() const; |
44 | 45 | ||
45 | /* | 46 | /* |
46 | What is the priority? | 47 | What is the priority? |
47 | **/ | 48 | **/ |
48 | int priority()const ; | 49 | int priority()const ; |
49 | 50 | ||
51 | /** | ||
52 | * progress as ushort 0, 20, 40, 60, 80 or 100% | ||
53 | */ | ||
54 | ushort progress() const; | ||
50 | /* | 55 | /* |
51 | All category numbers as QString in a List | 56 | All category numbers as QString in a List |
52 | **/ | 57 | **/ |
53 | QStringList allCategories()const; | 58 | QStringList allCategories()const; |
54 | 59 | ||
55 | /* | 60 | /* |
56 | * Same as above but with QArray<int> | 61 | * Same as above but with QArray<int> |
57 | */ | 62 | */ |
58 | QArray<int> categories() const; | 63 | QArray<int> categories() const; |
59 | 64 | ||
60 | /** | 65 | /** |
61 | * The end Date | 66 | * The end Date |
62 | */ | 67 | */ |
63 | QDate date()const; | 68 | QDate date()const; |
64 | 69 | ||
65 | /** | 70 | /** |
66 | * The description of the todo | 71 | * The description of the todo |
67 | */ | 72 | */ |
68 | QString description()const; | 73 | QString description()const; |
69 | 74 | ||
70 | /** | 75 | /** |
71 | * A small summary of the todo | 76 | * A small summary of the todo |
72 | */ | 77 | */ |
73 | QString summary() const; | 78 | QString summary() const; |
74 | 79 | ||
75 | /** | 80 | /** |
76 | * Return this todoevent in a RichText formatted QString | 81 | * Return this todoevent in a RichText formatted QString |
77 | */ | 82 | */ |
78 | QString richText() const; | 83 | QString richText() const; |
79 | 84 | ||
80 | /** | 85 | /** |
81 | * Returns the UID of the Todo | 86 | * Returns the UID of the Todo |
82 | */ | 87 | */ |
83 | int uid()const { return m_uid;}; | 88 | int uid()const { return m_uid;}; |
84 | 89 | ||
85 | 90 | ||
86 | QString extra(const QString& )const; | 91 | QString extra(const QString& )const; |
87 | /** | 92 | /** |
88 | * Set if this Todo is completed | 93 | * Set if this Todo is completed |
89 | */ | 94 | */ |
90 | void setCompleted(bool completed ); | 95 | void setCompleted(bool completed ); |
91 | 96 | ||
92 | /** | 97 | /** |
93 | * set if this todo got an end data | 98 | * set if this todo got an end data |
94 | */ | 99 | */ |
95 | void setHasDate( bool hasDate ); | 100 | void setHasDate( bool hasDate ); |
96 | // if the category doesn't exist we will create it | 101 | // if the category doesn't exist we will create it |
97 | // this sets the the Category after this call category will be the only category | 102 | // this sets the the Category after this call category will be the only category |
98 | void setCategory( const QString &category ); | 103 | void setCategory( const QString &category ); |
99 | // adds a category to the Categories of this event | 104 | // adds a category to the Categories of this event |
100 | void insertCategory(const QString &category ); | 105 | void insertCategory(const QString &category ); |
101 | 106 | ||
102 | /** | 107 | /** |
103 | * Removes this event from all categories | 108 | * Removes this event from all categories |
104 | */ | 109 | */ |
105 | void clearCategories(); | 110 | void clearCategories(); |
106 | 111 | ||
107 | /** | 112 | /** |
108 | * This todo belongs to xxx categories | 113 | * This todo belongs to xxx categories |
109 | */ | 114 | */ |
110 | void setCategories(const QStringList& ); | 115 | void setCategories(const QStringList& ); |
111 | 116 | ||
112 | /** | 117 | /** |
113 | * Set the priority of the Todo | 118 | * Set the priority of the Todo |
114 | */ | 119 | */ |
115 | void setPriority(int priority ); | 120 | void setPriority(int priority ); |
116 | 121 | ||
117 | /** | 122 | /** |
123 | * Set the progress. | ||
124 | */ | ||
125 | void setProgress( ushort progress ); | ||
126 | |||
127 | /** | ||
118 | * set the end date | 128 | * set the end date |
119 | */ | 129 | */ |
120 | void setDate( QDate date ); | 130 | void setDate( QDate date ); |
121 | void setDescription(const QString& ); | 131 | void setDescription(const QString& ); |
122 | void setSummary(const QString& ); | 132 | void setSummary(const QString& ); |
123 | void setExtra( const QString&, const QString& ); | 133 | void setExtra( const QString&, const QString& ); |
124 | bool isOverdue(); | 134 | bool isOverdue(); |
125 | 135 | ||
126 | bool match( const QRegExp &r )const; | 136 | bool match( const QRegExp &r )const; |
127 | 137 | ||
128 | void setUid(int id) {m_uid = id; }; | 138 | void setUid(int id) {m_uid = id; }; |
129 | bool operator<(const ToDoEvent &toDoEvent )const; | 139 | bool operator<(const ToDoEvent &toDoEvent )const; |
130 | bool operator<=(const ToDoEvent &toDoEvent )const; | 140 | bool operator<=(const ToDoEvent &toDoEvent )const; |
131 | bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; | 141 | bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; |
132 | bool operator>(const ToDoEvent &toDoEvent )const; | 142 | bool operator>(const ToDoEvent &toDoEvent )const; |
133 | bool operator>=(const ToDoEvent &toDoEvent)const; | 143 | bool operator>=(const ToDoEvent &toDoEvent)const; |
134 | bool operator==(const ToDoEvent &toDoEvent )const; | 144 | bool operator==(const ToDoEvent &toDoEvent )const; |
135 | ToDoEvent &operator=(const ToDoEvent &toDoEvent ); | 145 | ToDoEvent &operator=(const ToDoEvent &toDoEvent ); |
136 | private: | 146 | private: |
137 | class ToDoEventPrivate; | 147 | class ToDoEventPrivate; |
138 | ToDoEventPrivate *d; | 148 | ToDoEventPrivate *d; |
139 | QDate m_date; | 149 | QDate m_date; |
140 | bool m_isCompleted:1; | 150 | bool m_isCompleted:1; |
141 | bool m_hasDate:1; | 151 | bool m_hasDate:1; |
142 | int m_priority; | 152 | int m_priority; |
143 | QStringList m_category; | 153 | QStringList m_category; |
144 | QString m_desc; | 154 | QString m_desc; |
145 | QString m_sum; | 155 | QString m_sum; |
146 | QMap<QString, QString> m_extra; | 156 | QMap<QString, QString> m_extra; |
147 | int m_uid; | 157 | int m_uid; |
158 | ushort m_prog; | ||
148 | }; | 159 | }; |
149 | 160 | ||
150 | 161 | ||
151 | #endif | 162 | #endif |