author | zecke <zecke> | 2002-04-13 16:27:19 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-13 16:27:19 (UTC) |
commit | def870c6fcccf2b20d7ce3821055391b18243a24 (patch) (unidiff) | |
tree | 006357788654cf0e18c76640bd821cf87731d952 | |
parent | e42465b45553f51cf7c7d24130aa3a90a6be3ddd (diff) | |
download | opie-def870c6fcccf2b20d7ce3821055391b18243a24.zip opie-def870c6fcccf2b20d7ce3821055391b18243a24.tar.gz opie-def870c6fcccf2b20d7ce3821055391b18243a24.tar.bz2 |
multiple categories
-rw-r--r-- | libopie/tododb.cpp | 25 | ||||
-rw-r--r-- | libopie/todoevent.cpp | 27 | ||||
-rw-r--r-- | libopie/todoevent.h | 15 | ||||
-rw-r--r-- | libopie/todovcalresource.cpp | 2 |
4 files changed, 46 insertions, 23 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index 10ea2f0..7814c4f 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -1,157 +1,158 @@ | |||
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 | namespace { | 9 | namespace { |
10 | 10 | ||
11 | class FileToDoResource : public ToDoResource { | 11 | class FileToDoResource : public ToDoResource { |
12 | public: | 12 | public: |
13 | FileToDoResource() {}; | 13 | FileToDoResource() {}; |
14 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ | 14 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ |
15 | // prepare the XML | 15 | // prepare the XML |
16 | XMLElement *tasks = new XMLElement( ); | 16 | XMLElement *tasks = new XMLElement( ); |
17 | tasks->setTagName("Tasks" ); | 17 | tasks->setTagName("Tasks" ); |
18 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ | 18 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ |
19 | XMLElement::AttributeMap map; | 19 | XMLElement::AttributeMap map; |
20 | XMLElement *task = new XMLElement(); | 20 | XMLElement *task = new XMLElement(); |
21 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); | 21 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); |
22 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); | 22 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); |
23 | map.insert( "Priority", QString::number( (*it).priority() ) ); | 23 | map.insert( "Priority", QString::number( (*it).priority() ) ); |
24 | if(!(*it).category().isEmpty() ){ | 24 | QArray<int> arrat = (*it).categories(); |
25 | QArray<int> arrat(1); | 25 | QString attr; |
26 | arrat = Qtopia::Record::idsFromString( (*it).category() ); | 26 | for(uint i=0; i < arrat.count(); i++ ){ |
27 | map.insert( "Categories", QString::number( arrat[0] ) ); | 27 | attr.append(QString::number(arrat[i])+";" ); |
28 | }else | 28 | } |
29 | map.insert( "Categories", QString::null ); | 29 | if(!attr.isEmpty() ) // remove the last ; |
30 | attr.remove(attr.length()-1, 1 ); | ||
31 | map.insert( "Categories", attr ); | ||
32 | //else | ||
33 | //map.insert( "Categories", QString::null ); | ||
30 | map.insert( "Description", (*it).description() ); | 34 | map.insert( "Description", (*it).description() ); |
31 | if( (*it).hasDate() ){ | 35 | if( (*it).hasDate() ){ |
32 | map.insert("DateYear", QString::number( (*it).date().year() ) ); | 36 | map.insert("DateYear", QString::number( (*it).date().year() ) ); |
33 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); | 37 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); |
34 | map.insert("DateDay", QString::number( (*it).date().day() ) ); | 38 | map.insert("DateDay", QString::number( (*it).date().day() ) ); |
35 | } | 39 | } |
36 | map.insert("Uid", QString::number( (*it).uid() ) ); | 40 | map.insert("Uid", QString::number( (*it).uid() ) ); |
37 | task->setTagName("Task" ); | 41 | task->setTagName("Task" ); |
38 | task->setAttributes( map ); | 42 | task->setAttributes( map ); |
39 | tasks->appendChild(task); | 43 | tasks->appendChild(task); |
40 | } | 44 | } |
41 | QFile file( name); | 45 | QFile file( name); |
42 | if( file.open(IO_WriteOnly ) ){ | 46 | if( file.open(IO_WriteOnly ) ){ |
43 | QTextStream stream(&file ); | 47 | QTextStream stream(&file ); |
44 | stream << "<!DOCTYPE Tasks>" << endl; | 48 | stream << "<!DOCTYPE Tasks>" << endl; |
45 | tasks->save(stream ); | 49 | tasks->save(stream ); |
46 | delete tasks; | 50 | delete tasks; |
47 | file.close(); | 51 | file.close(); |
48 | return true; | 52 | return true; |
49 | } | 53 | } |
50 | return false; | 54 | return false; |
51 | } | 55 | } |
52 | QValueList<ToDoEvent> load( const QString &name ){ | 56 | QValueList<ToDoEvent> load( const QString &name ){ |
53 | qWarning("loading tododb" ); | 57 | qWarning("loading tododb" ); |
54 | QValueList<ToDoEvent> m_todos; | 58 | QValueList<ToDoEvent> m_todos; |
55 | XMLElement *root = XMLElement::load( name ); | 59 | XMLElement *root = XMLElement::load( name ); |
56 | if(root != 0l ){ // start parsing | 60 | if(root != 0l ){ // start parsing |
57 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); | 61 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); |
58 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start | 62 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start |
59 | XMLElement *element = root->firstChild(); | 63 | XMLElement *element = root->firstChild(); |
60 | element = element->firstChild(); | 64 | element = element->firstChild(); |
61 | while( element ){ | 65 | while( element ){ |
62 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); | 66 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); |
63 | QString dummy; | 67 | QString dummy; |
64 | ToDoEvent event; | 68 | ToDoEvent event; |
65 | bool ok; | 69 | bool ok; |
66 | int dumInt; | 70 | int dumInt; |
67 | // completed | 71 | // completed |
68 | dummy = element->attribute("Completed" ); | 72 | dummy = element->attribute("Completed" ); |
69 | dumInt = dummy.toInt(&ok ); | 73 | dumInt = dummy.toInt(&ok ); |
70 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); | 74 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); |
71 | // hasDate | 75 | // hasDate |
72 | dummy = element->attribute("HasDate" ); | 76 | dummy = element->attribute("HasDate" ); |
73 | dumInt = dummy.toInt(&ok ); | 77 | dumInt = dummy.toInt(&ok ); |
74 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); | 78 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); |
75 | // set the date | 79 | // set the date |
76 | bool hasDa = dumInt; | 80 | bool hasDa = dumInt; |
77 | if ( hasDa ) { //parse the date | 81 | if ( hasDa ) { //parse the date |
78 | int year, day, month = 0; | 82 | int year, day, month = 0; |
79 | year = day = month; | 83 | year = day = month; |
80 | // year | 84 | // year |
81 | dummy = element->attribute("DateYear" ); | 85 | dummy = element->attribute("DateYear" ); |
82 | dumInt = dummy.toInt(&ok ); | 86 | dumInt = dummy.toInt(&ok ); |
83 | if( ok ) year = dumInt; | 87 | if( ok ) year = dumInt; |
84 | // month | 88 | // month |
85 | dummy = element->attribute("DateMonth" ); | 89 | dummy = element->attribute("DateMonth" ); |
86 | dumInt = dummy.toInt(&ok ); | 90 | dumInt = dummy.toInt(&ok ); |
87 | if(ok ) month = dumInt; | 91 | if(ok ) month = dumInt; |
88 | dummy = element->attribute("DateDay" ); | 92 | dummy = element->attribute("DateDay" ); |
89 | dumInt = dummy.toInt(&ok ); | 93 | dumInt = dummy.toInt(&ok ); |
90 | if(ok ) day = dumInt; | 94 | if(ok ) day = dumInt; |
91 | // set the date | 95 | // set the date |
92 | QDate date( year, month, day ); | 96 | QDate date( year, month, day ); |
93 | event.setDate( date); | 97 | event.setDate( date); |
94 | } | 98 | } |
95 | dummy = element->attribute("Priority" ); | 99 | dummy = element->attribute("Priority" ); |
96 | dumInt = dummy.toInt(&ok ); | 100 | dumInt = dummy.toInt(&ok ); |
97 | if(!ok ) dumInt = ToDoEvent::NORMAL; | 101 | if(!ok ) dumInt = ToDoEvent::NORMAL; |
98 | event.setPriority( dumInt ); | 102 | event.setPriority( dumInt ); |
99 | //description | 103 | //description |
100 | dummy = element->attribute("Description" ); | 104 | dummy = element->attribute("Description" ); |
101 | event.setDescription( dummy ); | 105 | event.setDescription( dummy ); |
102 | // category | 106 | // category |
103 | dummy = element->attribute("Categories" ); | 107 | dummy = element->attribute("Categories" ); |
104 | dumInt = dummy.toInt(&ok ); | 108 | QStringList ids = QStringList::split(";", dummy ); |
105 | if(ok ) { | 109 | event.setCategories( ids ); |
106 | QArray<int> arrat(1); | 110 | |
107 | arrat[0] = dumInt; | ||
108 | event.setCategory( Qtopia::Record::idsToString( arrat ) ); | ||
109 | } | ||
110 | //uid | 111 | //uid |
111 | dummy = element->attribute("Uid" ); | 112 | dummy = element->attribute("Uid" ); |
112 | dumInt = dummy.toInt(&ok ); | 113 | dumInt = dummy.toInt(&ok ); |
113 | if(ok ) event.setUid( dumInt ); | 114 | if(ok ) event.setUid( dumInt ); |
114 | m_todos.append( event ); | 115 | m_todos.append( event ); |
115 | element = element->nextChild(); // next element | 116 | element = element->nextChild(); // next element |
116 | } | 117 | } |
117 | //} | 118 | //} |
118 | }else { | 119 | }else { |
119 | qWarning("could not load" ); | 120 | qWarning("could not load" ); |
120 | } | 121 | } |
121 | delete root; | 122 | delete root; |
122 | qWarning("returning" ); | 123 | qWarning("returning" ); |
123 | return m_todos; | 124 | return m_todos; |
124 | } | 125 | } |
125 | }; | 126 | }; |
126 | 127 | ||
127 | } | 128 | } |
128 | 129 | ||
129 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ | 130 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ |
130 | m_fileName = fileName; | 131 | m_fileName = fileName; |
131 | if( fileName.isEmpty() && res == 0 ){ | 132 | if( fileName.isEmpty() && res == 0 ){ |
132 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); | 133 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); |
133 | res = new FileToDoResource(); | 134 | res = new FileToDoResource(); |
134 | //qWarning("%s", m_fileName.latin1() ); | 135 | //qWarning("%s", m_fileName.latin1() ); |
135 | }else if(res == 0 ){ // let's create a ToDoResource for xml | 136 | }else if(res == 0 ){ // let's create a ToDoResource for xml |
136 | res = new FileToDoResource(); | 137 | res = new FileToDoResource(); |
137 | } | 138 | } |
138 | m_res = res; | 139 | m_res = res; |
139 | load(); | 140 | load(); |
140 | } | 141 | } |
141 | ToDoResource* ToDoDB::resource(){ | 142 | ToDoResource* ToDoDB::resource(){ |
142 | return m_res; | 143 | return m_res; |
143 | }; | 144 | }; |
144 | void ToDoDB::setResource( ToDoResource *res ) | 145 | void ToDoDB::setResource( ToDoResource *res ) |
145 | { | 146 | { |
146 | delete m_res; | 147 | delete m_res; |
147 | m_res = res; | 148 | m_res = res; |
148 | } | 149 | } |
149 | ToDoDB::~ToDoDB() | 150 | ToDoDB::~ToDoDB() |
150 | { | 151 | { |
151 | delete m_res; | 152 | delete m_res; |
152 | } | 153 | } |
153 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, | 154 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, |
154 | bool all ) | 155 | bool all ) |
155 | { | 156 | { |
156 | QValueList<ToDoEvent> events; | 157 | QValueList<ToDoEvent> events; |
157 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 158 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp index 7dbf907..28b2e98 100644 --- a/libopie/todoevent.cpp +++ b/libopie/todoevent.cpp | |||
@@ -1,176 +1,191 @@ | |||
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 QString &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" ); | 15 | qWarning("todoEvent c'tor" ); |
16 | m_date = date; | 16 | m_date = date; |
17 | m_isCompleted = completed; | 17 | m_isCompleted = completed; |
18 | m_hasDate = hasDate; | 18 | m_hasDate = hasDate; |
19 | m_priority = priority; | 19 | m_priority = priority; |
20 | m_category = category; | 20 | m_category = category; |
21 | m_desc = Qtopia::simplifyMultiLineSpace(description ); | 21 | m_desc = Qtopia::simplifyMultiLineSpace(description ); |
22 | if (uid == -1 ) { | 22 | if (uid == -1 ) { |
23 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); | 23 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); |
24 | uid = uidgen->generate(); | 24 | uid = uidgen->generate(); |
25 | delete uidgen; | 25 | delete uidgen; |
26 | }// generate the ids | 26 | }// generate the ids |
27 | m_uid = uid; | 27 | m_uid = uid; |
28 | } | 28 | } |
29 | QArray<int> ToDoEvent::categories()const | 29 | QArray<int> ToDoEvent::categories()const |
30 | { | 30 | { |
31 | QArray<int> array(1); // currently the datebook can be only in one category | 31 | QArray<int> array(m_category.count() ); // currently the datebook can be only in one category |
32 | array = Qtopia::Record::idsFromString( category() ); | 32 | array = Qtopia::Record::idsFromString( m_category.join(";") ); |
33 | return array; | 33 | return array; |
34 | } | 34 | } |
35 | bool ToDoEvent::match( const QRegExp ®Exp )const | 35 | bool ToDoEvent::match( const QRegExp ®Exp )const |
36 | { | 36 | { |
37 | if( QString::number( m_priority ).find( regExp ) != -1 ){ | 37 | if( QString::number( m_priority ).find( regExp ) != -1 ){ |
38 | return true; | 38 | return true; |
39 | }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ | 39 | }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){ |
40 | return true; | 40 | return true; |
41 | }else if(m_desc.find( regExp ) != -1 ){ | 41 | }else if(m_desc.find( regExp ) != -1 ){ |
42 | return true; | 42 | return true; |
43 | } | 43 | } |
44 | return false; | 44 | return false; |
45 | } | 45 | } |
46 | bool ToDoEvent::isCompleted() const | 46 | bool ToDoEvent::isCompleted() const |
47 | { | 47 | { |
48 | return m_isCompleted; | 48 | return m_isCompleted; |
49 | } | 49 | } |
50 | bool ToDoEvent::hasDate() const | 50 | bool ToDoEvent::hasDate() const |
51 | { | 51 | { |
52 | return m_hasDate; | 52 | return m_hasDate; |
53 | } | 53 | } |
54 | int ToDoEvent::priority()const | 54 | int ToDoEvent::priority()const |
55 | { | 55 | { |
56 | return m_priority; | 56 | return m_priority; |
57 | } | 57 | } |
58 | QString ToDoEvent::category()const | 58 | QStringList ToDoEvent::allCategories()const |
59 | { | 59 | { |
60 | return m_category; | 60 | return m_category; |
61 | } | 61 | } |
62 | void ToDoEvent::insertCategory(const QString &str ) | ||
63 | { | ||
64 | m_category.append( str ); | ||
65 | } | ||
66 | void ToDoEvent::clearCategories() | ||
67 | { | ||
68 | m_category.clear(); | ||
69 | } | ||
70 | void ToDoEvent::setCategories(const QStringList &list ) | ||
71 | { | ||
72 | m_category = list; | ||
73 | qWarning("todoevent: %s", list.join(";" ).latin1() ); | ||
74 | } | ||
62 | QDate ToDoEvent::date()const | 75 | QDate ToDoEvent::date()const |
63 | { | 76 | { |
64 | return m_date; | 77 | return m_date; |
65 | } | 78 | } |
79 | |||
66 | QString ToDoEvent::description()const | 80 | QString ToDoEvent::description()const |
67 | { | 81 | { |
68 | return m_desc; | 82 | return m_desc; |
69 | } | 83 | } |
70 | void ToDoEvent::setCompleted( bool completed ) | 84 | void ToDoEvent::setCompleted( bool completed ) |
71 | { | 85 | { |
72 | m_isCompleted = completed; | 86 | m_isCompleted = completed; |
73 | } | 87 | } |
74 | void ToDoEvent::setHasDate( bool hasDate ) | 88 | void ToDoEvent::setHasDate( bool hasDate ) |
75 | { | 89 | { |
76 | m_hasDate = hasDate; | 90 | m_hasDate = hasDate; |
77 | } | 91 | } |
78 | void ToDoEvent::setDescription(const QString &desc ) | 92 | void ToDoEvent::setDescription(const QString &desc ) |
79 | { | 93 | { |
80 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); | 94 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); |
81 | } | 95 | } |
82 | void ToDoEvent::setCategory( const QString &cat ) | 96 | void ToDoEvent::setCategory( const QString &cat ) |
83 | { | 97 | { |
84 | qWarning("setCategory %s", cat.latin1() ); | 98 | qWarning("setCategory %s", cat.latin1() ); |
85 | m_category = cat; | 99 | m_category.clear(); |
100 | m_category << cat; | ||
86 | } | 101 | } |
87 | void ToDoEvent::setPriority(int prio ) | 102 | void ToDoEvent::setPriority(int prio ) |
88 | { | 103 | { |
89 | m_priority = prio; | 104 | m_priority = prio; |
90 | } | 105 | } |
91 | void ToDoEvent::setDate( QDate date ) | 106 | void ToDoEvent::setDate( QDate date ) |
92 | { | 107 | { |
93 | m_date = date; | 108 | m_date = date; |
94 | } | 109 | } |
95 | bool ToDoEvent::isOverdue( ) | 110 | bool ToDoEvent::isOverdue( ) |
96 | { | 111 | { |
97 | if( m_hasDate ) | 112 | if( m_hasDate ) |
98 | return QDate::currentDate() > m_date; | 113 | return QDate::currentDate() > m_date; |
99 | return false; | 114 | return false; |
100 | } | 115 | } |
101 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ | 116 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ |
102 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 117 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
103 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 118 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
104 | if( hasDate() && toDoEvent.hasDate() ){ | 119 | if( hasDate() && toDoEvent.hasDate() ){ |
105 | if( date() == toDoEvent.date() ){ // let's the priority decide | 120 | if( date() == toDoEvent.date() ){ // let's the priority decide |
106 | return priority() < toDoEvent.priority(); | 121 | return priority() < toDoEvent.priority(); |
107 | }else{ | 122 | }else{ |
108 | return date() < toDoEvent.date(); | 123 | return date() < toDoEvent.date(); |
109 | } | 124 | } |
110 | } | 125 | } |
111 | return false; | 126 | return false; |
112 | } | 127 | } |
113 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const | 128 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const |
114 | { | 129 | { |
115 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 130 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
116 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 131 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
117 | if( hasDate() && toDoEvent.hasDate() ){ | 132 | if( hasDate() && toDoEvent.hasDate() ){ |
118 | if( date() == toDoEvent.date() ){ // let's the priority decide | 133 | if( date() == toDoEvent.date() ){ // let's the priority decide |
119 | return priority() <= toDoEvent.priority(); | 134 | return priority() <= toDoEvent.priority(); |
120 | }else{ | 135 | }else{ |
121 | return date() <= toDoEvent.date(); | 136 | return date() <= toDoEvent.date(); |
122 | } | 137 | } |
123 | } | 138 | } |
124 | return true; | 139 | return true; |
125 | } | 140 | } |
126 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const | 141 | bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const |
127 | { | 142 | { |
128 | if( !hasDate() && !toDoEvent.hasDate() ) return false; | 143 | if( !hasDate() && !toDoEvent.hasDate() ) return false; |
129 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 144 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
130 | if( hasDate() && toDoEvent.hasDate() ){ | 145 | if( hasDate() && toDoEvent.hasDate() ){ |
131 | if( date() == toDoEvent.date() ){ // let's the priority decide | 146 | if( date() == toDoEvent.date() ){ // let's the priority decide |
132 | return priority() > toDoEvent.priority(); | 147 | return priority() > toDoEvent.priority(); |
133 | }else{ | 148 | }else{ |
134 | return date() > toDoEvent.date(); | 149 | return date() > toDoEvent.date(); |
135 | } | 150 | } |
136 | } | 151 | } |
137 | return false; | 152 | return false; |
138 | } | 153 | } |
139 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const | 154 | bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const |
140 | { | 155 | { |
141 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 156 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
142 | if( !hasDate() && toDoEvent.hasDate() ) return false; | 157 | if( !hasDate() && toDoEvent.hasDate() ) return false; |
143 | if( hasDate() && toDoEvent.hasDate() ){ | 158 | if( hasDate() && toDoEvent.hasDate() ){ |
144 | if( date() == toDoEvent.date() ){ // let's the priority decide | 159 | if( date() == toDoEvent.date() ){ // let's the priority decide |
145 | return priority() > toDoEvent.priority(); | 160 | return priority() > toDoEvent.priority(); |
146 | }else{ | 161 | }else{ |
147 | return date() > toDoEvent.date(); | 162 | return date() > toDoEvent.date(); |
148 | } | 163 | } |
149 | } | 164 | } |
150 | return true; | 165 | return true; |
151 | } | 166 | } |
152 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const | 167 | bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const |
153 | { | 168 | { |
154 | 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_category ) | 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 ) |
155 | return true; | 170 | return true; |
156 | return false; | 171 | return false; |
157 | } | 172 | } |
158 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) | 173 | ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item ) |
159 | { | 174 | { |
160 | m_date = item.m_date; | 175 | m_date = item.m_date; |
161 | m_isCompleted = item.m_isCompleted; | 176 | m_isCompleted = item.m_isCompleted; |
162 | m_hasDate = item.m_hasDate; | 177 | m_hasDate = item.m_hasDate; |
163 | m_priority = item.m_priority; | 178 | m_priority = item.m_priority; |
164 | m_category = item.m_category; | 179 | m_category = item.m_category; |
165 | m_desc = item.m_desc; | 180 | m_desc = item.m_desc; |
166 | m_uid = item.m_uid; | 181 | m_uid = item.m_uid; |
167 | return *this; | 182 | return *this; |
168 | } | 183 | } |
169 | 184 | ||
170 | 185 | ||
171 | 186 | ||
172 | 187 | ||
173 | 188 | ||
174 | 189 | ||
175 | 190 | ||
176 | 191 | ||
diff --git a/libopie/todoevent.h b/libopie/todoevent.h index ac996a1..0d477fd 100644 --- a/libopie/todoevent.h +++ b/libopie/todoevent.h | |||
@@ -1,57 +1,64 @@ | |||
1 | 1 | ||
2 | #ifndef todoevent_h | 2 | #ifndef todoevent_h |
3 | #define todoevent_h | 3 | #define todoevent_h |
4 | 4 | ||
5 | #include <qstringlist.h> | ||
5 | #include <qdatetime.h> | 6 | #include <qdatetime.h> |
6 | 7 | ||
7 | class ToDoEvent { | 8 | class ToDoEvent { |
8 | friend class ToDoDB; | 9 | friend class ToDoDB; |
9 | public: | 10 | public: |
10 | enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; | 11 | enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; |
11 | ToDoEvent( bool completed = false, int priority = NORMAL, | 12 | ToDoEvent( bool completed = false, int priority = NORMAL, |
12 | const QString &category = QString::null, | 13 | const QStringList &category = QStringList(), |
13 | const QString &description = QString::null , | 14 | const QString &description = QString::null , |
14 | bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); | 15 | bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); |
15 | ToDoEvent(const ToDoEvent & ); | 16 | ToDoEvent(const ToDoEvent & ); |
16 | bool isCompleted() const; | 17 | bool isCompleted() const; |
17 | bool hasDate() const; | 18 | bool hasDate() const; |
18 | int priority()const ; | 19 | int priority()const ; |
19 | QString category()const; | 20 | QStringList allCategories()const; |
20 | QArray<int> categories() const; | 21 | QArray<int> categories() const; |
21 | QDate date()const; | 22 | QDate date()const; |
22 | QString description()const; | 23 | QString description()const; |
23 | 24 | ||
24 | int uid()const { return m_uid;}; | 25 | int uid()const { return m_uid;}; |
25 | void setCompleted(bool completed ); | 26 | void setCompleted(bool completed ); |
26 | void setHasDate( bool hasDate ); | 27 | void setHasDate( bool hasDate ); |
27 | // if the category doesn't exist we will create it | 28 | // if the category doesn't exist we will create it |
29 | // this sets the the Category after this call category will be the only category | ||
28 | void setCategory( const QString &category ); | 30 | void setCategory( const QString &category ); |
31 | // adds a category to the Categories of this event | ||
32 | void insertCategory(const QString &category ); | ||
33 | void clearCategories(); | ||
34 | void setCategories(const QStringList& ); | ||
35 | |||
29 | void setPriority(int priority ); | 36 | void setPriority(int priority ); |
30 | void setDate( QDate date ); | 37 | void setDate( QDate date ); |
31 | void setDescription(const QString& ); | 38 | void setDescription(const QString& ); |
32 | bool isOverdue(); | 39 | bool isOverdue(); |
33 | 40 | ||
34 | bool match( const QRegExp &r )const; | 41 | bool match( const QRegExp &r )const; |
35 | 42 | ||
36 | void setUid(int id) {m_uid = id; }; | 43 | void setUid(int id) {m_uid = id; }; |
37 | bool operator<(const ToDoEvent &toDoEvent )const; | 44 | bool operator<(const ToDoEvent &toDoEvent )const; |
38 | bool operator<=(const ToDoEvent &toDoEvent )const; | 45 | bool operator<=(const ToDoEvent &toDoEvent )const; |
39 | bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; | 46 | bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; |
40 | bool operator>(const ToDoEvent &toDoEvent )const; | 47 | bool operator>(const ToDoEvent &toDoEvent )const; |
41 | bool operator>=(const ToDoEvent &toDoEvent)const; | 48 | bool operator>=(const ToDoEvent &toDoEvent)const; |
42 | bool operator==(const ToDoEvent &toDoEvent )const; | 49 | bool operator==(const ToDoEvent &toDoEvent )const; |
43 | ToDoEvent &operator=(const ToDoEvent &toDoEvent ); | 50 | ToDoEvent &operator=(const ToDoEvent &toDoEvent ); |
44 | private: | 51 | private: |
45 | class ToDoEventPrivate; | 52 | class ToDoEventPrivate; |
46 | ToDoEventPrivate *d; | 53 | ToDoEventPrivate *d; |
47 | QDate m_date; | 54 | QDate m_date; |
48 | bool m_isCompleted:1; | 55 | bool m_isCompleted:1; |
49 | bool m_hasDate:1; | 56 | bool m_hasDate:1; |
50 | int m_priority; | 57 | int m_priority; |
51 | QString m_category; | 58 | QStringList m_category; |
52 | QString m_desc; | 59 | QString m_desc; |
53 | int m_uid; | 60 | int m_uid; |
54 | }; | 61 | }; |
55 | 62 | ||
56 | 63 | ||
57 | #endif | 64 | #endif |
diff --git a/libopie/todovcalresource.cpp b/libopie/todovcalresource.cpp index a6afe68..75f2197 100644 --- a/libopie/todovcalresource.cpp +++ b/libopie/todovcalresource.cpp | |||
@@ -3,97 +3,97 @@ | |||
3 | .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org> | 3 | .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org> |
4 | .>+-= the use of vobject was inspired by libkcal | 4 | .>+-= the use of vobject was inspired by libkcal |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qvaluelist.h> | 30 | #include <qvaluelist.h> |
31 | #include <opie/todoevent.h> | 31 | #include <opie/todoevent.h> |
32 | #include <opie/todovcalresource.h> | 32 | #include <opie/todovcalresource.h> |
33 | 33 | ||
34 | #include "../library/backend/vobject_p.h" | 34 | #include "../library/backend/vobject_p.h" |
35 | #include "../library/backend/timeconversion.h" | 35 | #include "../library/backend/timeconversion.h" |
36 | #include "../library/backend/qfiledirect_p.h" | 36 | #include "../library/backend/qfiledirect_p.h" |
37 | 37 | ||
38 | static VObject *vobjByEvent( const ToDoEvent &event ) | 38 | static VObject *vobjByEvent( const ToDoEvent &event ) |
39 | { | 39 | { |
40 | VObject *task = newVObject( VCTodoProp ); | 40 | VObject *task = newVObject( VCTodoProp ); |
41 | if( task == 0 ) | 41 | if( task == 0 ) |
42 | return 0l; | 42 | return 0l; |
43 | if( event.hasDate() ) | 43 | if( event.hasDate() ) |
44 | addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) ); | 44 | addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) ); |
45 | 45 | ||
46 | if( event.isCompleted() ) | 46 | if( event.isCompleted() ) |
47 | addPropValue( task, VCStatusProp, "COMPLETED"); | 47 | addPropValue( task, VCStatusProp, "COMPLETED"); |
48 | 48 | ||
49 | QString string = QString::number(event.priority() ); | 49 | QString string = QString::number(event.priority() ); |
50 | addPropValue( task, VCPriorityProp, string.local8Bit() ); | 50 | addPropValue( task, VCPriorityProp, string.local8Bit() ); |
51 | addPropValue( task, VCCategoriesProp, event.category().local8Bit() ); | 51 | addPropValue( task, VCCategoriesProp, event.allCategories().join(";").local8Bit() ); |
52 | addPropValue( task, VCDescriptionProp, event.description().local8Bit() ); | 52 | addPropValue( task, VCDescriptionProp, event.description().local8Bit() ); |
53 | addPropValue( task, VCSummaryProp, event.description().left(15).local8Bit() ); | 53 | addPropValue( task, VCSummaryProp, event.description().left(15).local8Bit() ); |
54 | return task; | 54 | return task; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | static ToDoEvent eventByVObj( VObject *obj ){ | 57 | static ToDoEvent eventByVObj( VObject *obj ){ |
58 | ToDoEvent event; | 58 | ToDoEvent event; |
59 | VObject *ob; | 59 | VObject *ob; |
60 | QCString name; | 60 | QCString name; |
61 | // no uid, attendees, ... and no fun | 61 | // no uid, attendees, ... and no fun |
62 | // description | 62 | // description |
63 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ | 63 | if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){ |
64 | name = vObjectStringZValue( ob ); | 64 | name = vObjectStringZValue( ob ); |
65 | event.setDescription( name ); | 65 | event.setDescription( name ); |
66 | } | 66 | } |
67 | // completed | 67 | // completed |
68 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ | 68 | if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){ |
69 | name = vObjectStringZValue( ob ); | 69 | name = vObjectStringZValue( ob ); |
70 | if( name == "COMPLETED" ){ | 70 | if( name == "COMPLETED" ){ |
71 | event.setCompleted( true ); | 71 | event.setCompleted( true ); |
72 | }else{ | 72 | }else{ |
73 | event.setCompleted( false ); | 73 | event.setCompleted( false ); |
74 | } | 74 | } |
75 | }else | 75 | }else |
76 | event.setCompleted( false ); | 76 | event.setCompleted( false ); |
77 | // priority | 77 | // priority |
78 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { | 78 | if ((ob = isAPropertyOf(obj, VCPriorityProp))) { |
79 | name = vObjectStringZValue( ob ); | 79 | name = vObjectStringZValue( ob ); |
80 | bool ok; | 80 | bool ok; |
81 | event.setPriority(name.toInt(&ok) ); | 81 | event.setPriority(name.toInt(&ok) ); |
82 | } | 82 | } |
83 | //due date | 83 | //due date |
84 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ | 84 | if((ob = isAPropertyOf(obj, VCDueProp)) ){ |
85 | event.setHasDate( true ); | 85 | event.setHasDate( true ); |
86 | name = vObjectStringZValue( ob ); | 86 | name = vObjectStringZValue( ob ); |
87 | event.setDate( TimeConversion::fromISO8601( name).date() ); | 87 | event.setDate( TimeConversion::fromISO8601( name).date() ); |
88 | } | 88 | } |
89 | // categories | 89 | // categories |
90 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ | 90 | if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){ |
91 | name = vObjectStringZValue( ob ); | 91 | name = vObjectStringZValue( ob ); |
92 | qWarning("Categories:%s", name.data() ); | 92 | qWarning("Categories:%s", name.data() ); |
93 | } | 93 | } |
94 | 94 | ||
95 | return event; | 95 | return event; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | 98 | ||
99 | QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file) | 99 | QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file) |