-rw-r--r-- | library/backend/task.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/library/backend/task.cpp b/library/backend/task.cpp index e7d697d..f0a38f1 100644 --- a/library/backend/task.cpp +++ b/library/backend/task.cpp | |||
@@ -1,149 +1,150 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qpe/task.h> | 21 | #include <qpe/task.h> |
22 | #include <qregexp.h> | 22 | #include <qregexp.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qpe/recordfields.h> | 24 | #include <qpe/recordfields.h> |
25 | #include "vobject_p.h" | 25 | #include "vobject_p.h" |
26 | #include "timeconversion.h" | 26 | #include "timeconversion.h" |
27 | #include "qfiledirect_p.h" | 27 | #include "qfiledirect_p.h" |
28 | 28 | ||
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | 30 | ||
31 | using namespace Qtopia; | 31 | using namespace Qtopia; |
32 | UidGen Task::sUidGen( UidGen::Qtopia ); | 32 | UidGen Task::sUidGen( UidGen::Qtopia ); |
33 | 33 | ||
34 | Task::Task() : Record(), mDue( FALSE ), | 34 | Task::Task() : Record(), mDue( FALSE ), |
35 | mDueDate( QDate::currentDate() ), | 35 | mDueDate( QDate::currentDate() ), |
36 | mCompleted( FALSE ), mPriority( 3 ), mDesc() | 36 | mCompleted( FALSE ), mPriority( 3 ), mDesc() |
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | Task::Task( const QMap<int, QString> &m ) : Record(), mDue( FALSE ), | 40 | Task::Task( const QMap<int, QString> &m ) : Record(), mDue( FALSE ), |
41 | mDueDate( QDate::currentDate() ), mCompleted( FALSE ), mPriority( 3 ), mDesc() | 41 | mDueDate( QDate::currentDate() ), mCompleted( FALSE ), mPriority( 3 ), mDesc() |
42 | { | 42 | { |
43 | //qDebug("Task::Task fromMap"); | 43 | //qDebug("Task::Task fromMap"); |
44 | //dump( m ); | 44 | //dump( m ); |
45 | for ( QMap<int,QString>::ConstIterator it = m.begin(); it != m.end();++it ) | 45 | for ( QMap<int,QString>::ConstIterator it = m.begin(); it != m.end();++it ) |
46 | switch ( (TaskFields) it.key() ) { | 46 | switch ( (TaskFields) it.key() ) { |
47 | case HasDate: if ( *it == "1" ) mDue = TRUE; break; | 47 | case HasDate: if ( *it == "1" ) mDue = TRUE; break; |
48 | case Completed: setCompleted( *it == "1" ); break; | 48 | case Completed: setCompleted( *it == "1" ); break; |
49 | case TaskCategory: setCategories( idsFromString( *it ) ); break; | 49 | case TaskCategory: setCategories( idsFromString( *it ) ); break; |
50 | case TaskDescription: setDescription( *it ); break; | 50 | case TaskDescription: setDescription( *it ); break; |
51 | case Priority: setPriority( (*it).toInt() ); break; | 51 | case Priority: setPriority( (*it).toInt() ); break; |
52 | case Date: mDueDate = TimeConversion::fromString( (*it) ); break; | 52 | case Date: mDueDate = TimeConversion::fromString( (*it) ); break; |
53 | case TaskUid: setUid( (*it).toInt() ); break; | 53 | case TaskUid: setUid( (*it).toInt() ); break; |
54 | default: break; | ||
54 | } | 55 | } |
55 | } | 56 | } |
56 | 57 | ||
57 | Task::~Task() | 58 | Task::~Task() |
58 | { | 59 | { |
59 | } | 60 | } |
60 | 61 | ||
61 | QMap<int, QString> Task::toMap() const | 62 | QMap<int, QString> Task::toMap() const |
62 | { | 63 | { |
63 | QMap<int, QString> m; | 64 | QMap<int, QString> m; |
64 | m.insert( HasDate, hasDueDate() ? "1" : "0" ); | 65 | m.insert( HasDate, hasDueDate() ? "1" : "0" ); |
65 | m.insert( Completed, isCompleted() ? "1" : "0" ); | 66 | m.insert( Completed, isCompleted() ? "1" : "0" ); |
66 | m.insert( TaskCategory, idsToString( categories() ) ); | 67 | m.insert( TaskCategory, idsToString( categories() ) ); |
67 | m.insert( TaskDescription, description() ); | 68 | m.insert( TaskDescription, description() ); |
68 | m.insert( Priority, QString::number( priority() ) ); | 69 | m.insert( Priority, QString::number( priority() ) ); |
69 | m.insert( Date, TimeConversion::toString( dueDate() ) ); | 70 | m.insert( Date, TimeConversion::toString( dueDate() ) ); |
70 | m.insert( TaskUid, QString::number(uid()) ); | 71 | m.insert( TaskUid, QString::number(uid()) ); |
71 | 72 | ||
72 | //qDebug("Task::toMap"); | 73 | //qDebug("Task::toMap"); |
73 | //dump( m ); | 74 | //dump( m ); |
74 | return m; | 75 | return m; |
75 | } | 76 | } |
76 | 77 | ||
77 | void Task::save( QString& buf ) const | 78 | void Task::save( QString& buf ) const |
78 | { | 79 | { |
79 | buf += " Completed=\""; | 80 | buf += " Completed=\""; |
80 | // qDebug( "writing %d", complete ); | 81 | // qDebug( "writing %d", complete ); |
81 | buf += QString::number( (int)mCompleted ); | 82 | buf += QString::number( (int)mCompleted ); |
82 | buf += "\""; | 83 | buf += "\""; |
83 | buf += " HasDate=\""; | 84 | buf += " HasDate=\""; |
84 | // qDebug( "writing %d", ); | 85 | // qDebug( "writing %d", ); |
85 | buf += QString::number( (int)mDue ); | 86 | buf += QString::number( (int)mDue ); |
86 | buf += "\""; | 87 | buf += "\""; |
87 | buf += " Priority=\""; | 88 | buf += " Priority=\""; |
88 | // qDebug ("writing %d", prior ); | 89 | // qDebug ("writing %d", prior ); |
89 | buf += QString::number( mPriority ); | 90 | buf += QString::number( mPriority ); |
90 | buf += "\""; | 91 | buf += "\""; |
91 | buf += " Categories=\""; | 92 | buf += " Categories=\""; |
92 | buf += Qtopia::Record::idsToString( categories() ); | 93 | buf += Qtopia::Record::idsToString( categories() ); |
93 | buf += "\""; | 94 | buf += "\""; |
94 | buf += " Description=\""; | 95 | buf += " Description=\""; |
95 | // qDebug( "writing note %s", note.latin1() ); | 96 | // qDebug( "writing note %s", note.latin1() ); |
96 | buf += Qtopia::escapeString( mDesc ); | 97 | buf += Qtopia::escapeString( mDesc ); |
97 | buf += "\""; | 98 | buf += "\""; |
98 | if ( mDue ) { | 99 | if ( mDue ) { |
99 | // qDebug("saving ymd %d %d %d", mDueDate.year(), mDueDate.month(), | 100 | // qDebug("saving ymd %d %d %d", mDueDate.year(), mDueDate.month(), |
100 | // mDueDate.day() ); | 101 | // mDueDate.day() ); |
101 | buf += " DateYear=\""; | 102 | buf += " DateYear=\""; |
102 | buf += QString::number( mDueDate.year() ); | 103 | buf += QString::number( mDueDate.year() ); |
103 | buf += "\""; | 104 | buf += "\""; |
104 | buf += " DateMonth=\""; | 105 | buf += " DateMonth=\""; |
105 | buf += QString::number( mDueDate.month() ); | 106 | buf += QString::number( mDueDate.month() ); |
106 | buf += "\""; | 107 | buf += "\""; |
107 | buf += " DateDay=\""; | 108 | buf += " DateDay=\""; |
108 | buf += QString::number( mDueDate.day() ); | 109 | buf += QString::number( mDueDate.day() ); |
109 | buf += "\""; | 110 | buf += "\""; |
110 | } | 111 | } |
111 | buf += customToXml(); | 112 | buf += customToXml(); |
112 | // qDebug ("writing uid %d", uid() ); | 113 | // qDebug ("writing uid %d", uid() ); |
113 | buf += " Uid=\""; | 114 | buf += " Uid=\""; |
114 | buf += QString::number( uid() ); | 115 | buf += QString::number( uid() ); |
115 | // terminate it in the application... | 116 | // terminate it in the application... |
116 | buf += "\""; | 117 | buf += "\""; |
117 | } | 118 | } |
118 | 119 | ||
119 | bool Task::match ( const QRegExp &r ) const | 120 | bool Task::match ( const QRegExp &r ) const |
120 | { | 121 | { |
121 | // match on priority, description on due date... | 122 | // match on priority, description on due date... |
122 | bool match; | 123 | bool match; |
123 | match = false; | 124 | match = false; |
124 | if ( QString::number( mPriority ).find( r ) > -1 ) | 125 | if ( QString::number( mPriority ).find( r ) > -1 ) |
125 | match = true; | 126 | match = true; |
126 | else if ( mDue && mDueDate.toString().find( r ) > -1 ) | 127 | else if ( mDue && mDueDate.toString().find( r ) > -1 ) |
127 | match = true; | 128 | match = true; |
128 | else if ( mDesc.find( r ) > -1 ) | 129 | else if ( mDesc.find( r ) > -1 ) |
129 | match = true; | 130 | match = true; |
130 | return match; | 131 | return match; |
131 | } | 132 | } |
132 | 133 | ||
133 | static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) | 134 | static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) |
134 | { | 135 | { |
135 | VObject *ret = 0; | 136 | VObject *ret = 0; |
136 | if ( o && !value.isEmpty() ) | 137 | if ( o && !value.isEmpty() ) |
137 | ret = addPropValue( o, prop, value.latin1() ); | 138 | ret = addPropValue( o, prop, value.latin1() ); |
138 | return ret; | 139 | return ret; |
139 | } | 140 | } |
140 | 141 | ||
141 | static inline VObject *safeAddProp( VObject *o, const char *prop) | 142 | static inline VObject *safeAddProp( VObject *o, const char *prop) |
142 | { | 143 | { |
143 | VObject *ret = 0; | 144 | VObject *ret = 0; |
144 | if ( o ) | 145 | if ( o ) |
145 | ret = addProp( o, prop ); | 146 | ret = addProp( o, prop ); |
146 | return ret; | 147 | return ret; |
147 | } | 148 | } |
148 | 149 | ||
149 | 150 | ||