author | zecke <zecke> | 2002-11-15 15:31:47 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-11-15 15:31:47 (UTC) |
commit | 5a6e66edad1070f624d54320278d00372f112213 (patch) (unidiff) | |
tree | ab1028759194edace4c79cf90d18dc1362a84aa9 | |
parent | 05f56fbbbe9ea5546f7503f4852fcab9c5b10a00 (diff) | |
download | opie-5a6e66edad1070f624d54320278d00372f112213.zip opie-5a6e66edad1070f624d54320278d00372f112213.tar.gz opie-5a6e66edad1070f624d54320278d00372f112213.tar.bz2 |
Add the implementation for the XRef Manager
Add it to libopie.pro
Adjust OPimRecord to use the new manager
The backends do not support xref yet
-rw-r--r-- | libopie/libopie.pro | 6 | ||||
-rw-r--r-- | libopie/pim/opimrecord.cpp | 63 | ||||
-rw-r--r-- | libopie/pim/opimrecord.h | 33 | ||||
-rw-r--r-- | libopie/pim/opimxref.cpp | 47 | ||||
-rw-r--r-- | libopie/pim/opimxref.h | 7 | ||||
-rw-r--r-- | libopie/pim/opimxrefmanager.cpp | 69 | ||||
-rw-r--r-- | libopie/pim/opimxrefmanager.h | 5 | ||||
-rw-r--r-- | libopie/pim/opimxrefpartner.cpp | 43 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 18 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 18 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.cpp | 63 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 33 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxref.cpp | 47 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxref.h | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxrefmanager.cpp | 69 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxrefmanager.h | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimxrefpartner.cpp | 43 |
17 files changed, 374 insertions, 202 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro index 79d15bb..3e6156e 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro | |||
@@ -1,83 +1,89 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = ofontmenu.h \ | 3 | HEADERS = ofontmenu.h \ |
4 | ocolorbutton.h \ | 4 | ocolorbutton.h \ |
5 | ofiledialog.h ofileselector.h tododb.h \ | 5 | ofiledialog.h ofileselector.h tododb.h \ |
6 | ocheckitem.h todoevent.h todoresource.h \ | 6 | ocheckitem.h todoevent.h todoresource.h \ |
7 | todovcalresource.h xmltree.h \ | 7 | todovcalresource.h xmltree.h \ |
8 | colordialog.h colorpopupmenu.h \ | 8 | colordialog.h colorpopupmenu.h \ |
9 | oclickablelabel.h oprocctrl.h \ | 9 | oclickablelabel.h oprocctrl.h \ |
10 | oprocess.h odevice.h \ | 10 | oprocess.h odevice.h \ |
11 | otimepicker.h otabwidget.h \ | 11 | otimepicker.h otabwidget.h \ |
12 | otabbar.h otabinfo.h \ | 12 | otabbar.h otabinfo.h \ |
13 | ofontselector.h \ | 13 | ofontselector.h \ |
14 | pim/opimrecord.h \ | 14 | pim/opimrecord.h \ |
15 | pim/otodo.h \ | 15 | pim/otodo.h \ |
16 | pim/orecordlist.h \ | 16 | pim/orecordlist.h \ |
17 | pim/opimaccesstemplate.h \ | 17 | pim/opimaccesstemplate.h \ |
18 | pim/opimaccessbackend.h \ | 18 | pim/opimaccessbackend.h \ |
19 | pim/otodoaccess.h \ | 19 | pim/otodoaccess.h \ |
20 | pim/otodoaccessbackend.h \ | 20 | pim/otodoaccessbackend.h \ |
21 | pim/ocontact.h \ | 21 | pim/ocontact.h \ |
22 | pim/ocontactaccess.h \ | 22 | pim/ocontactaccess.h \ |
23 | pim/ocontactaccessbackend.h \ | 23 | pim/ocontactaccessbackend.h \ |
24 | pim/ocontactaccessbackend_xml.h \ | 24 | pim/ocontactaccessbackend_xml.h \ |
25 | pim/ocontactaccessbackend_vcard.h \ | 25 | pim/ocontactaccessbackend_vcard.h \ |
26 | pim/obackendfactory.h \ | 26 | pim/obackendfactory.h \ |
27 | pim/opimcache.h \ | 27 | pim/opimcache.h \ |
28 | pim/otodoaccessvcal.h \ | 28 | pim/otodoaccessvcal.h \ |
29 | pim/orecur.h \ | 29 | pim/orecur.h \ |
30 | pim/opimstate.h \ | 30 | pim/opimstate.h \ |
31 | pim/opimxrefpartner.h \ | ||
32 | pim/opimxref.h \ | ||
33 | pim/opimxrefmanager.h \ | ||
31 | orecurrancewidget.h \ | 34 | orecurrancewidget.h \ |
32 | oticker.h | 35 | oticker.h |
33 | # pim/otodoaccesssql.h \ | 36 | # pim/otodoaccesssql.h \ |
34 | 37 | ||
35 | SOURCES = ofontmenu.cc \ | 38 | SOURCES = ofontmenu.cc \ |
36 | ocolorbutton.cpp \ | 39 | ocolorbutton.cpp \ |
37 | xmltree.cc \ | 40 | xmltree.cc \ |
38 | ofiledialog.cc ofileselector.cc \ | 41 | ofiledialog.cc ofileselector.cc \ |
39 | ocheckitem.cpp tododb.cpp todoevent.cpp \ | 42 | ocheckitem.cpp tododb.cpp todoevent.cpp \ |
40 | todovcalresource.cpp colordialog.cpp \ | 43 | todovcalresource.cpp colordialog.cpp \ |
41 | colorpopupmenu.cpp oclickablelabel.cpp \ | 44 | colorpopupmenu.cpp oclickablelabel.cpp \ |
42 | oprocctrl.cpp oprocess.cpp \ | 45 | oprocctrl.cpp oprocess.cpp \ |
43 | odevice.cpp otimepicker.cpp \ | 46 | odevice.cpp otimepicker.cpp \ |
44 | otabwidget.cpp otabbar.cpp \ | 47 | otabwidget.cpp otabbar.cpp \ |
45 | ofontselector.cpp \ | 48 | ofontselector.cpp \ |
46 | pim/otodo.cpp \ | 49 | pim/otodo.cpp \ |
47 | pim/opimrecord.cpp \ | 50 | pim/opimrecord.cpp \ |
48 | pim/otodoaccess.cpp \ | 51 | pim/otodoaccess.cpp \ |
49 | pim/otodoaccessbackend.cpp \ | 52 | pim/otodoaccessbackend.cpp \ |
50 | pim/otodoaccessxml.cpp \ | 53 | pim/otodoaccessxml.cpp \ |
51 | pim/ocontact.cpp \ | 54 | pim/ocontact.cpp \ |
52 | pim/ocontactaccess.cpp \ | 55 | pim/ocontactaccess.cpp \ |
53 | pim/ocontactaccessbackend_vcard.cpp \ | 56 | pim/ocontactaccessbackend_vcard.cpp \ |
54 | pim/otodoaccessvcal.cpp \ | 57 | pim/otodoaccessvcal.cpp \ |
55 | pim/orecur.cpp \ | 58 | pim/orecur.cpp \ |
56 | pim/opimstate.cpp \ | 59 | pim/opimstate.cpp \ |
60 | pim/opimxrefpartner.cpp \ | ||
61 | pim/opimxref.cpp \ | ||
62 | pim/opimxrefmanager.cpp \ | ||
57 | orecurrancewidget.cpp \ | 63 | orecurrancewidget.cpp \ |
58 | oticker.cpp | 64 | oticker.cpp |
59 | # pim/otodoaccesssql.cpp \ | 65 | # pim/otodoaccesssql.cpp \ |
60 | 66 | ||
61 | TARGET = opie | 67 | TARGET = opie |
62 | INCLUDEPATH += $(OPIEDIR)/include | 68 | INCLUDEPATH += $(OPIEDIR)/include |
63 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 69 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
64 | #VERSION = 1.0.0 | 70 | #VERSION = 1.0.0 |
65 | 71 | ||
66 | # LIBS += -lopiesql | 72 | # LIBS += -lopiesql |
67 | 73 | ||
68 | INTERFACES = otimepickerbase.ui orecurrancebase.ui | 74 | INTERFACES = otimepickerbase.ui orecurrancebase.ui |
69 | 75 | ||
70 | TRANSLATIONS = ../i18n/de/libopie.ts \ | 76 | TRANSLATIONS = ../i18n/de/libopie.ts \ |
71 | ../i18n/en/libopie.ts \ | 77 | ../i18n/en/libopie.ts \ |
72 | ../i18n/es/libopie.ts \ | 78 | ../i18n/es/libopie.ts \ |
73 | ../i18n/fr/libopie.ts \ | 79 | ../i18n/fr/libopie.ts \ |
74 | ../i18n/hu/libopie.ts \ | 80 | ../i18n/hu/libopie.ts \ |
75 | ../i18n/ja/libopie.ts \ | 81 | ../i18n/ja/libopie.ts \ |
76 | ../i18n/ko/libopie.ts \ | 82 | ../i18n/ko/libopie.ts \ |
77 | ../i18n/no/libopie.ts \ | 83 | ../i18n/no/libopie.ts \ |
78 | ../i18n/pl/libopie.ts \ | 84 | ../i18n/pl/libopie.ts \ |
79 | ../i18n/pt/libopie.ts \ | 85 | ../i18n/pt/libopie.ts \ |
80 | ../i18n/pt_BR/libopie.ts \ | 86 | ../i18n/pt_BR/libopie.ts \ |
81 | ../i18n/sl/libopie.ts \ | 87 | ../i18n/sl/libopie.ts \ |
82 | ../i18n/zh_CN/libopie.ts \ | 88 | ../i18n/zh_CN/libopie.ts \ |
83 | ../i18n/zh_TW/libopie.ts | 89 | ../i18n/zh_TW/libopie.ts |
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp index 21cf131..0e3be9d 100644 --- a/libopie/pim/opimrecord.cpp +++ b/libopie/pim/opimrecord.cpp | |||
@@ -1,132 +1,81 @@ | |||
1 | #include <qpe/categories.h> | 1 | #include <qpe/categories.h> |
2 | #include <qpe/categoryselect.h> | 2 | #include <qpe/categoryselect.h> |
3 | 3 | ||
4 | #include "opimrecord.h" | 4 | #include "opimrecord.h" |
5 | 5 | ||
6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | 6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); |
7 | 7 | ||
8 | 8 | ||
9 | OPimRecord::OPimRecord( int uid ) | 9 | OPimRecord::OPimRecord( int uid ) |
10 | : Qtopia::Record() { | 10 | : Qtopia::Record() { |
11 | 11 | ||
12 | setUid( uid ); | 12 | setUid( uid ); |
13 | } | 13 | } |
14 | OPimRecord::~OPimRecord() { | 14 | OPimRecord::~OPimRecord() { |
15 | } | 15 | } |
16 | OPimRecord::OPimRecord( const OPimRecord& rec ) | 16 | OPimRecord::OPimRecord( const OPimRecord& rec ) |
17 | : Qtopia::Record( rec ) | 17 | : Qtopia::Record( rec ) |
18 | { | 18 | { |
19 | (*this) = rec; | 19 | (*this) = rec; |
20 | } | 20 | } |
21 | 21 | ||
22 | OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { | 22 | OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { |
23 | Qtopia::Record::operator=( rec ); | 23 | Qtopia::Record::operator=( rec ); |
24 | m_relations = rec.m_relations; | 24 | m_xrefman = rec.m_xrefman; |
25 | 25 | ||
26 | return *this; | 26 | return *this; |
27 | } | 27 | } |
28 | /* | 28 | /* |
29 | * category names | 29 | * category names |
30 | */ | 30 | */ |
31 | QStringList OPimRecord::categoryNames()const { | 31 | QStringList OPimRecord::categoryNames()const { |
32 | QStringList list; | 32 | QStringList list; |
33 | QArray<int> cats = categories(); | 33 | QArray<int> cats = categories(); |
34 | Categories catDB; | 34 | Categories catDB; |
35 | catDB.load( categoryFileName() ); | 35 | catDB.load( categoryFileName() ); |
36 | 36 | ||
37 | for (uint i = 0; i < cats.count(); i++ ) { | 37 | for (uint i = 0; i < cats.count(); i++ ) { |
38 | list << catDB.label("Todo List", cats[i] ); | 38 | list << catDB.label("Todo List", cats[i] ); |
39 | } | 39 | } |
40 | 40 | ||
41 | return list; | 41 | return list; |
42 | } | 42 | } |
43 | void OPimRecord::setCategoryNames( const QStringList& ) { | 43 | void OPimRecord::setCategoryNames( const QStringList& ) { |
44 | 44 | ||
45 | } | 45 | } |
46 | void OPimRecord::addCategoryName( const QString& ) { | 46 | void OPimRecord::addCategoryName( const QString& ) { |
47 | Categories catDB; | 47 | Categories catDB; |
48 | catDB.load( categoryFileName() ); | 48 | catDB.load( categoryFileName() ); |
49 | 49 | ||
50 | 50 | ||
51 | } | 51 | } |
52 | bool OPimRecord::isEmpty()const { | 52 | bool OPimRecord::isEmpty()const { |
53 | return ( uid() == 0 ); | 53 | return ( uid() == 0 ); |
54 | } | 54 | } |
55 | QStringList OPimRecord::relatedApps()const{ | 55 | /*QString OPimRecord::crossToString()const { |
56 | QStringList list; | ||
57 | QMap<QString, QArray<int> >::ConstIterator it; | ||
58 | for ( it = m_relations.begin(); it != m_relations.end(); ++it ) { | ||
59 | list << it.key(); | ||
60 | } | ||
61 | return list; | ||
62 | } | ||
63 | QArray<int> OPimRecord::relations(const QString& app )const { | ||
64 | QArray<int> tmp; | ||
65 | QMap<QString, QArray<int> >::ConstIterator it; | ||
66 | it = m_relations.find( app); | ||
67 | if ( it != m_relations.end() ) | ||
68 | tmp = it.data(); | ||
69 | return tmp; | ||
70 | } | ||
71 | void OPimRecord::clearRelation( const QString& app ) { | ||
72 | m_relations.remove( app ); | ||
73 | } | ||
74 | void OPimRecord::addRelation( const QString& app, int id ) { | ||
75 | |||
76 | QMap<QString, QArray<int> >::Iterator it; | ||
77 | QArray<int> tmp; | ||
78 | |||
79 | it = m_relations.find( app ); | ||
80 | if ( it == m_relations.end() ) { | ||
81 | tmp.resize(1 ); | ||
82 | tmp[0] = id; | ||
83 | }else{ | ||
84 | tmp = it.data(); | ||
85 | tmp.resize( tmp.size() + 1 ); | ||
86 | tmp[tmp.size() - 1] = id; | ||
87 | } | ||
88 | m_relations.replace( app, tmp ); | ||
89 | } | ||
90 | void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { | ||
91 | |||
92 | QMap<QString, QArray<int> >::Iterator it; | ||
93 | QArray<int> tmp; | ||
94 | |||
95 | it = m_relations.find( app); | ||
96 | if ( it == m_relations.end() ) { | ||
97 | tmp = ids; | ||
98 | }else{ | ||
99 | tmp = it.data(); | ||
100 | int offset = tmp.size()-1; | ||
101 | tmp.resize( tmp.size() + ids.size() ); | ||
102 | for (uint i = 0; i < ids.size(); i++ ) { | ||
103 | tmp[offset+i] = ids[i]; | ||
104 | } | ||
105 | |||
106 | } | ||
107 | m_relations.replace( app, tmp ); | ||
108 | } | ||
109 | QString OPimRecord::crossToString()const { | ||
110 | QString str; | 56 | QString str; |
111 | QMap<QString, QArray<int> >::ConstIterator it; | 57 | QMap<QString, QArray<int> >::ConstIterator it; |
112 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { | 58 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { |
113 | QArray<int> id = it.data(); | 59 | QArray<int> id = it.data(); |
114 | for ( uint i = 0; i < id.size(); ++i ) { | 60 | for ( uint i = 0; i < id.size(); ++i ) { |
115 | str += it.key() + "," + QString::number( i ) + ";"; | 61 | str += it.key() + "," + QString::number( i ) + ";"; |
116 | } | 62 | } |
117 | } | 63 | } |
118 | str = str.remove( str.length()-1, 1); // strip the ; | 64 | str = str.remove( str.length()-1, 1); // strip the ; |
119 | //qWarning("IDS " + str ); | 65 | //qWarning("IDS " + str ); |
120 | 66 | ||
121 | return str; | 67 | return str; |
122 | } | 68 | }*/ |
123 | /* if uid = 1 assign a new one */ | 69 | /* if uid = 1 assign a new one */ |
124 | void OPimRecord::setUid( int uid ) { | 70 | void OPimRecord::setUid( int uid ) { |
125 | if ( uid == 1) | 71 | if ( uid == 1) |
126 | uid = uidGen().generate(); | 72 | uid = uidGen().generate(); |
127 | 73 | ||
128 | Qtopia::Record::setUid( uid ); | 74 | Qtopia::Record::setUid( uid ); |
129 | }; | 75 | }; |
130 | Qtopia::UidGen &OPimRecord::uidGen() { | 76 | Qtopia::UidGen &OPimRecord::uidGen() { |
131 | return m_uidGen; | 77 | return m_uidGen; |
132 | } | 78 | } |
79 | OPimXRefManager &OPimRecord::xrefmanager() { | ||
80 | return m_xrefman; | ||
81 | } | ||
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h index d9ccad4..1642a5e 100644 --- a/libopie/pim/opimrecord.h +++ b/libopie/pim/opimrecord.h | |||
@@ -1,133 +1,116 @@ | |||
1 | #ifndef OPIE_PIM_RECORD_H | 1 | #ifndef OPIE_PIM_RECORD_H |
2 | #define OPIE_PIM_RECORD_H | 2 | #define OPIE_PIM_RECORD_H |
3 | 3 | ||
4 | #include <qmap.h> | 4 | #include <qmap.h> |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | #include <qpe/palmtoprecord.h> | 8 | #include <qpe/palmtoprecord.h> |
9 | 9 | ||
10 | #include <opie/opimxrefmanager.h> | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * This is the base class for | 13 | * This is the base class for |
13 | * all PIM Records | 14 | * all PIM Records |
14 | * | 15 | * |
15 | */ | 16 | */ |
16 | class OPimRecord : public Qtopia::Record { | 17 | class OPimRecord : public Qtopia::Record { |
17 | public: | 18 | public: |
18 | /** | 19 | /** |
19 | * c'tor | 20 | * c'tor |
20 | * uid of 0 isEmpty | 21 | * uid of 0 isEmpty |
21 | * uid of 1 will be assigned a new one | 22 | * uid of 1 will be assigned a new one |
22 | */ | 23 | */ |
23 | OPimRecord(int uid = 0); | 24 | OPimRecord(int uid = 0); |
24 | ~OPimRecord(); | 25 | ~OPimRecord(); |
25 | 26 | ||
26 | /** | 27 | /** |
27 | * copy c'tor | 28 | * copy c'tor |
28 | */ | 29 | */ |
29 | OPimRecord( const OPimRecord& rec ); | 30 | OPimRecord( const OPimRecord& rec ); |
30 | 31 | ||
31 | /** | 32 | /** |
32 | * copy operator | 33 | * copy operator |
33 | */ | 34 | */ |
34 | OPimRecord &operator=( const OPimRecord& ); | 35 | OPimRecord &operator=( const OPimRecord& ); |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * category names resolved | 38 | * category names resolved |
38 | */ | 39 | */ |
39 | QStringList categoryNames()const; | 40 | QStringList categoryNames()const; |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * set category names they will be resolved | 43 | * set category names they will be resolved |
43 | */ | 44 | */ |
44 | void setCategoryNames( const QStringList& ); | 45 | void setCategoryNames( const QStringList& ); |
45 | 46 | ||
46 | /** | 47 | /** |
47 | * addCategoryName adds a name | 48 | * addCategoryName adds a name |
48 | * to the internal category list | 49 | * to the internal category list |
49 | */ | 50 | */ |
50 | void addCategoryName( const QString& ); | 51 | void addCategoryName( const QString& ); |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * if a Record isEmpty | 54 | * if a Record isEmpty |
54 | * it's empty if it's 0 | 55 | * it's empty if it's 0 |
55 | */ | 56 | */ |
56 | virtual bool isEmpty()const; | 57 | virtual bool isEmpty()const; |
57 | 58 | ||
58 | /** | 59 | /** |
59 | * toRichText summary | 60 | * toRichText summary |
60 | */ | 61 | */ |
61 | virtual QString toRichText()const = 0; | 62 | virtual QString toRichText()const = 0; |
62 | 63 | ||
63 | /** | 64 | /** |
64 | * a small one line summary | 65 | * a small one line summary |
65 | */ | 66 | */ |
66 | virtual QString toShortText()const = 0; | 67 | virtual QString toShortText()const = 0; |
67 | 68 | ||
68 | /** | 69 | /** |
69 | * the name of the Record | 70 | * the name of the Record |
70 | */ | 71 | */ |
71 | virtual QString type()const = 0; | 72 | virtual QString type()const = 0; |
72 | 73 | ||
73 | /** | 74 | /** |
74 | * converts the internal structure to a map | 75 | * converts the internal structure to a map |
75 | */ | 76 | */ |
76 | virtual QMap<int, QString> toMap()const = 0; | 77 | virtual QMap<int, QString> toMap()const = 0; |
77 | 78 | ||
78 | /** | 79 | /** |
79 | * key value representation of extra items | 80 | * key value representation of extra items |
80 | */ | 81 | */ |
81 | virtual QMap<QString, QString> toExtraMap()const = 0; | 82 | virtual QMap<QString, QString> toExtraMap()const = 0; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * the name for a recordField | 85 | * the name for a recordField |
85 | */ | 86 | */ |
86 | virtual QString recordField(int)const = 0; | 87 | virtual QString recordField(int)const = 0; |
87 | 88 | ||
88 | /** | 89 | /** |
89 | * the related apps names | 90 | * returns a reference of the |
91 | * Cross Reference Manager | ||
92 | * Partner One is THIS PIM RECORD! | ||
93 | * Two is the Partner where we link to | ||
90 | */ | 94 | */ |
91 | QStringList relatedApps()const; | 95 | OPimXRefManager& xrefmanager(); |
92 | |||
93 | /** | ||
94 | * the realtions between an app | ||
95 | */ | ||
96 | QArray<int> relations( const QString& app )const; | ||
97 | |||
98 | /** | ||
99 | * clear the relations for all relations | ||
100 | * with app | ||
101 | */ | ||
102 | void clearRelation( const QString& app ); | ||
103 | |||
104 | /** | ||
105 | * add a relation | ||
106 | */ | ||
107 | void addRelation( const QString& app, int id ); | ||
108 | |||
109 | /** | ||
110 | * set the relations for an app | ||
111 | */ | ||
112 | void setRelations( const QString&, QArray<int> ids ); | ||
113 | 96 | ||
114 | /** | 97 | /** |
115 | * set the uid | 98 | * set the uid |
116 | */ | 99 | */ |
117 | virtual void setUid( int uid ); | 100 | virtual void setUid( int uid ); |
118 | 101 | ||
119 | protected: | 102 | protected: |
120 | Qtopia::UidGen &uidGen(); | 103 | Qtopia::UidGen &uidGen(); |
121 | QString crossToString()const; | 104 | // QString crossToString()const; |
122 | 105 | ||
123 | private: | 106 | private: |
124 | class OPimRecordPrivate; | 107 | class OPimRecordPrivate; |
125 | OPimRecordPrivate *d; | 108 | OPimRecordPrivate *d; |
126 | QMap<QString, QArray<int> > m_relations; | 109 | OPimXRefManager m_xrefman; |
127 | static Qtopia::UidGen m_uidGen; | 110 | static Qtopia::UidGen m_uidGen; |
128 | 111 | ||
129 | }; | 112 | }; |
130 | 113 | ||
131 | 114 | ||
132 | 115 | ||
133 | #endif | 116 | #endif |
diff --git a/libopie/pim/opimxref.cpp b/libopie/pim/opimxref.cpp new file mode 100644 index 0000000..5cae871 --- a/dev/null +++ b/libopie/pim/opimxref.cpp | |||
@@ -0,0 +1,47 @@ | |||
1 | #include "opimxref.h" | ||
2 | |||
3 | OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two ) | ||
4 | : m_partners(2) | ||
5 | { | ||
6 | m_partners[0] = one; | ||
7 | m_partners[1] = two; | ||
8 | } | ||
9 | OPimXRef::OPimXRef() | ||
10 | : m_partners(2) | ||
11 | { | ||
12 | |||
13 | } | ||
14 | OPimXRef::OPimXRef( const OPimXRef& ref) { | ||
15 | *this = ref; | ||
16 | } | ||
17 | OPimXRef::~OPimXRef() { | ||
18 | } | ||
19 | OPimXRef &OPimXRef::operator=( const OPimXRef& ref) { | ||
20 | m_partners = ref.m_partners; | ||
21 | m_partners.detach(); | ||
22 | |||
23 | return* this; | ||
24 | } | ||
25 | bool OPimXRef::operator==( const OPimXRef& oper ) { | ||
26 | if ( m_partners == oper.m_partners ) return true; | ||
27 | |||
28 | return false; | ||
29 | } | ||
30 | OPimXRefPartner OPimXRef::partner( enum Partners par) const{ | ||
31 | return m_partners[par]; | ||
32 | } | ||
33 | void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) { | ||
34 | m_partners[par] = part; | ||
35 | } | ||
36 | bool OPimXRef::containsString( const QString& string ) const{ | ||
37 | if ( m_partners[One].appName() == string || | ||
38 | m_partners[Two].appName() == string ) return true; | ||
39 | |||
40 | return false; | ||
41 | } | ||
42 | bool OPimXRef::containsUid( int uid ) const{ | ||
43 | if ( m_partners[One].uid() == uid || | ||
44 | m_partners[Two].uid() == uid ) return true; | ||
45 | |||
46 | return false; | ||
47 | } | ||
diff --git a/libopie/pim/opimxref.h b/libopie/pim/opimxref.h index 72154ac..354739a 100644 --- a/libopie/pim/opimxref.h +++ b/libopie/pim/opimxref.h | |||
@@ -1,36 +1,39 @@ | |||
1 | #ifndef OPIM_XREF_H | 1 | #ifndef OPIM_XREF_H |
2 | #define OPIM_XREF_H | 2 | #define OPIM_XREF_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | 6 | ||
7 | #include <opie/opimxrefpartner.h> | 7 | #include <opie/opimxrefpartner.h> |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * this is a Cross Referecne between | 10 | * this is a Cross Referecne between |
11 | * two Cross Reference Partners | 11 | * two Cross Reference Partners |
12 | */ | 12 | */ |
13 | class OPimXRef { | 13 | class OPimXRef { |
14 | public: | 14 | public: |
15 | typedef QValueList<OPimXRef> ValueList; | 15 | typedef QValueList<OPimXRef> ValueList; |
16 | enum Partners { One, Two }; | 16 | enum Partners { One, Two }; |
17 | OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); | 17 | OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); |
18 | OPimXRef(); | 18 | OPimXRef(); |
19 | OPimXRef( const OPimXRef& ); | 19 | OPimXRef( const OPimXRef& ); |
20 | ~OPimXRef(); | 20 | ~OPimXRef(); |
21 | 21 | ||
22 | OPimXRef &operator=( const OPimXRef& ); | 22 | OPimXRef &operator=( const OPimXRef& ); |
23 | bool operator==( const OPimXRef ); | 23 | bool operator==( const OPimXRef& ); |
24 | 24 | ||
25 | OPimXRefPartner partner( enum Partners ); | 25 | OPimXRefPartner partner( enum Partners )const; |
26 | 26 | ||
27 | void setPartner( enum Partners, const OPimXRefPartner& ); | 27 | void setPartner( enum Partners, const OPimXRefPartner& ); |
28 | 28 | ||
29 | bool containsString( const QString& appName)const; | ||
30 | bool containsUid( int uid )const; | ||
31 | |||
29 | private: | 32 | private: |
30 | QArray<OPimXRefPartner> m_partners; | 33 | QArray<OPimXRefPartner> m_partners; |
31 | 34 | ||
32 | class Private; | 35 | class Private; |
33 | Private *d; | 36 | Private *d; |
34 | }; | 37 | }; |
35 | 38 | ||
36 | #endif | 39 | #endif |
diff --git a/libopie/pim/opimxrefmanager.cpp b/libopie/pim/opimxrefmanager.cpp new file mode 100644 index 0000000..d49f5f5 --- a/dev/null +++ b/libopie/pim/opimxrefmanager.cpp | |||
@@ -0,0 +1,69 @@ | |||
1 | #include "opimxrefmanager.h" | ||
2 | |||
3 | |||
4 | OPimXRefManager::OPimXRefManager() { | ||
5 | } | ||
6 | OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) { | ||
7 | m_list = ref.m_list; | ||
8 | } | ||
9 | OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) { | ||
10 | m_list = ref.m_list; | ||
11 | return *this; | ||
12 | } | ||
13 | bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) { | ||
14 | // if ( m_list == ref.m_list ) return true; | ||
15 | |||
16 | return false; | ||
17 | } | ||
18 | void OPimXRefManager::add( const OPimXRef& ref) { | ||
19 | m_list.append( ref ); | ||
20 | } | ||
21 | void OPimXRefManager::remove( const OPimXRef& ref) { | ||
22 | m_list.remove( ref ); | ||
23 | } | ||
24 | void OPimXRefManager::replace( const OPimXRef& ref) { | ||
25 | m_list.remove( ref ); | ||
26 | m_list.append( ref ); | ||
27 | } | ||
28 | void OPimXRefManager::clear() { | ||
29 | m_list.clear(); | ||
30 | } | ||
31 | QStringList OPimXRefManager::apps()const { | ||
32 | OPimXRef::ValueList::ConstIterator it; | ||
33 | QStringList list; | ||
34 | |||
35 | QString str; | ||
36 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | ||
37 | str = (*it).partner( OPimXRef::One ).appName(); | ||
38 | if ( !list.contains( str ) ) list << str; | ||
39 | |||
40 | str = (*it).partner( OPimXRef::Two ).appName(); | ||
41 | if ( !list.contains( str ) ) list << str; | ||
42 | } | ||
43 | return list; | ||
44 | } | ||
45 | OPimXRef::ValueList OPimXRefManager::list()const { | ||
46 | return m_list; | ||
47 | } | ||
48 | OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{ | ||
49 | OPimXRef::ValueList list; | ||
50 | OPimXRef::ValueList::ConstIterator it; | ||
51 | |||
52 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | ||
53 | if ( (*it).containsString( appName ) ) | ||
54 | list.append( (*it) ); | ||
55 | } | ||
56 | |||
57 | return list; | ||
58 | } | ||
59 | OPimXRef::ValueList OPimXRefManager::list( int uid )const { | ||
60 | OPimXRef::ValueList list; | ||
61 | OPimXRef::ValueList::ConstIterator it; | ||
62 | |||
63 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | ||
64 | if ( (*it).containsUid( uid ) ) | ||
65 | list.append( (*it) ); | ||
66 | } | ||
67 | |||
68 | return list; | ||
69 | } | ||
diff --git a/libopie/pim/opimxrefmanager.h b/libopie/pim/opimxrefmanager.h index 147895d..9b003a3 100644 --- a/libopie/pim/opimxrefmanager.h +++ b/libopie/pim/opimxrefmanager.h | |||
@@ -1,36 +1,41 @@ | |||
1 | #ifndef OPIM_XREF_MANAGER_H | 1 | #ifndef OPIM_XREF_MANAGER_H |
2 | #define OPIM_XREF_MANAGER_H | 2 | #define OPIM_XREF_MANAGER_H |
3 | 3 | ||
4 | #include <qstringlist.h> | ||
5 | |||
4 | #include <opie/opimxref.h> | 6 | #include <opie/opimxref.h> |
5 | 7 | ||
6 | /** | 8 | /** |
7 | * This is a simple manager for | 9 | * This is a simple manager for |
8 | * OPimXRefs. | 10 | * OPimXRefs. |
9 | * It allows addition, removing, replacing | 11 | * It allows addition, removing, replacing |
10 | * clearing and 'querying' the XRef... | 12 | * clearing and 'querying' the XRef... |
11 | */ | 13 | */ |
12 | class OPimXRefManager { | 14 | class OPimXRefManager { |
13 | public: | 15 | public: |
14 | OPimXRefManager(); | 16 | OPimXRefManager(); |
15 | OPimXRefManager( const OPimXRefManager& ); | 17 | OPimXRefManager( const OPimXRefManager& ); |
16 | ~OPimXRefManager(); | 18 | ~OPimXRefManager(); |
17 | 19 | ||
18 | OPimXRefManager& operator=( const OPimXRefManager& ); | 20 | OPimXRefManager& operator=( const OPimXRefManager& ); |
19 | bool operator==( const OPimXRefManager& ); | 21 | bool operator==( const OPimXRefManager& ); |
20 | 22 | ||
21 | void add( const OPimXRef& ); | 23 | void add( const OPimXRef& ); |
22 | void remove( const OPimXRef& ); | 24 | void remove( const OPimXRef& ); |
23 | void replace( const OPimXRef& ); | 25 | void replace( const OPimXRef& ); |
24 | 26 | ||
25 | void clear(); | 27 | void clear(); |
26 | 28 | ||
27 | /** | 29 | /** |
28 | * apps participating | 30 | * apps participating |
29 | */ | 31 | */ |
30 | QStringList apps()const; | 32 | QStringList apps()const; |
31 | OPimXRef::ValueList list()const; | 33 | OPimXRef::ValueList list()const; |
32 | OPimXRef::ValueList list( const QString& appName )const; | 34 | OPimXRef::ValueList list( const QString& appName )const; |
33 | OPimXRef::ValueList list( int uid )const; | 35 | OPimXRef::ValueList list( int uid )const; |
36 | |||
37 | private: | ||
38 | OPimXRef::ValueList m_list; | ||
34 | }; | 39 | }; |
35 | 40 | ||
36 | #endif | 41 | #endif |
diff --git a/libopie/pim/opimxrefpartner.cpp b/libopie/pim/opimxrefpartner.cpp new file mode 100644 index 0000000..028f4e6 --- a/dev/null +++ b/libopie/pim/opimxrefpartner.cpp | |||
@@ -0,0 +1,43 @@ | |||
1 | #include "opimxrefpartner.h" | ||
2 | |||
3 | OPimXRefPartner::OPimXRefPartner( const QString& appName, | ||
4 | int uid, int field ) | ||
5 | : m_app(appName), m_uid(uid), m_field( field ) { | ||
6 | } | ||
7 | OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) { | ||
8 | *this = ref; | ||
9 | } | ||
10 | OPimXRefPartner::~OPimXRefPartner() { | ||
11 | } | ||
12 | OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) { | ||
13 | m_app = par.m_app; | ||
14 | m_uid = par.m_uid; | ||
15 | m_field = par.m_field; | ||
16 | |||
17 | return *this; | ||
18 | } | ||
19 | bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) { | ||
20 | if ( m_app != par.m_app ) return false; | ||
21 | if ( m_uid != par.m_uid ) return false; | ||
22 | if ( m_field != par.m_field ) return false; | ||
23 | |||
24 | return true; | ||
25 | } | ||
26 | QString OPimXRefPartner::appName()const { | ||
27 | return m_app; | ||
28 | } | ||
29 | int OPimXRefPartner::uid()const { | ||
30 | return m_uid; | ||
31 | } | ||
32 | int OPimXRefPartner::field()const { | ||
33 | return m_field; | ||
34 | } | ||
35 | void OPimXRefPartner::setAppName( const QString& appName ) { | ||
36 | m_app = appName; | ||
37 | } | ||
38 | void OPimXRefPartner::setUid( int uid ) { | ||
39 | m_uid = uid; | ||
40 | } | ||
41 | void OPimXRefPartner::setField( int field ) { | ||
42 | m_field = field; | ||
43 | } | ||
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 591e467..c1682c6 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -142,451 +142,435 @@ bool OTodoAccessXML::save() { | |||
142 | QString strNewFile = m_file + ".new"; | 142 | QString strNewFile = m_file + ".new"; |
143 | QFile f( strNewFile ); | 143 | QFile f( strNewFile ); |
144 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 144 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
145 | return false; | 145 | return false; |
146 | 146 | ||
147 | int written; | 147 | int written; |
148 | QString out; | 148 | QString out; |
149 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 149 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
150 | 150 | ||
151 | // for all todos | 151 | // for all todos |
152 | QMap<int, OTodo>::Iterator it; | 152 | QMap<int, OTodo>::Iterator it; |
153 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 153 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
154 | out+= "<Task " + toString( (*it) ) + " />\n"; | 154 | out+= "<Task " + toString( (*it) ) + " />\n"; |
155 | QCString cstr = out.utf8(); | 155 | QCString cstr = out.utf8(); |
156 | written = f.writeBlock( cstr.data(), cstr.length() ); | 156 | written = f.writeBlock( cstr.data(), cstr.length() ); |
157 | 157 | ||
158 | /* less written then we wanted */ | 158 | /* less written then we wanted */ |
159 | if ( written != (int)cstr.length() ) { | 159 | if ( written != (int)cstr.length() ) { |
160 | f.close(); | 160 | f.close(); |
161 | QFile::remove( strNewFile ); | 161 | QFile::remove( strNewFile ); |
162 | return false; | 162 | return false; |
163 | } | 163 | } |
164 | out = QString::null; | 164 | out = QString::null; |
165 | } | 165 | } |
166 | 166 | ||
167 | out += "</Tasks>"; | 167 | out += "</Tasks>"; |
168 | QCString cstr = out.utf8(); | 168 | QCString cstr = out.utf8(); |
169 | written = f.writeBlock( cstr.data(), cstr.length() ); | 169 | written = f.writeBlock( cstr.data(), cstr.length() ); |
170 | 170 | ||
171 | if ( written != (int)cstr.length() ) { | 171 | if ( written != (int)cstr.length() ) { |
172 | f.close(); | 172 | f.close(); |
173 | QFile::remove( strNewFile ); | 173 | QFile::remove( strNewFile ); |
174 | return false; | 174 | return false; |
175 | } | 175 | } |
176 | /* flush before renaming */ | 176 | /* flush before renaming */ |
177 | f.close(); | 177 | f.close(); |
178 | 178 | ||
179 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { | 179 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { |
180 | // qWarning("error renaming"); | 180 | // qWarning("error renaming"); |
181 | QFile::remove( strNewFile ); | 181 | QFile::remove( strNewFile ); |
182 | } | 182 | } |
183 | 183 | ||
184 | m_changed = false; | 184 | m_changed = false; |
185 | return true; | 185 | return true; |
186 | } | 186 | } |
187 | QArray<int> OTodoAccessXML::allRecords()const { | 187 | QArray<int> OTodoAccessXML::allRecords()const { |
188 | QArray<int> ids( m_events.count() ); | 188 | QArray<int> ids( m_events.count() ); |
189 | QMap<int, OTodo>::ConstIterator it; | 189 | QMap<int, OTodo>::ConstIterator it; |
190 | int i = 0; | 190 | int i = 0; |
191 | 191 | ||
192 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 192 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
193 | ids[i] = it.key(); | 193 | ids[i] = it.key(); |
194 | i++; | 194 | i++; |
195 | } | 195 | } |
196 | return ids; | 196 | return ids; |
197 | } | 197 | } |
198 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) { | 198 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) { |
199 | QArray<int> ids(0); | 199 | QArray<int> ids(0); |
200 | return ids; | 200 | return ids; |
201 | } | 201 | } |
202 | OTodo OTodoAccessXML::find( int uid )const { | 202 | OTodo OTodoAccessXML::find( int uid )const { |
203 | OTodo todo; | 203 | OTodo todo; |
204 | todo.setUid( 0 ); // isEmpty() | 204 | todo.setUid( 0 ); // isEmpty() |
205 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); | 205 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); |
206 | if ( it != m_events.end() ) | 206 | if ( it != m_events.end() ) |
207 | todo = it.data(); | 207 | todo = it.data(); |
208 | 208 | ||
209 | return todo; | 209 | return todo; |
210 | } | 210 | } |
211 | void OTodoAccessXML::clear() { | 211 | void OTodoAccessXML::clear() { |
212 | if (m_opened ) | 212 | if (m_opened ) |
213 | m_changed = true; | 213 | m_changed = true; |
214 | 214 | ||
215 | m_events.clear(); | 215 | m_events.clear(); |
216 | } | 216 | } |
217 | bool OTodoAccessXML::add( const OTodo& todo ) { | 217 | bool OTodoAccessXML::add( const OTodo& todo ) { |
218 | // qWarning("add"); | 218 | // qWarning("add"); |
219 | m_changed = true; | 219 | m_changed = true; |
220 | m_events.insert( todo.uid(), todo ); | 220 | m_events.insert( todo.uid(), todo ); |
221 | 221 | ||
222 | return true; | 222 | return true; |
223 | } | 223 | } |
224 | bool OTodoAccessXML::remove( int uid ) { | 224 | bool OTodoAccessXML::remove( int uid ) { |
225 | m_changed = true; | 225 | m_changed = true; |
226 | m_events.remove( uid ); | 226 | m_events.remove( uid ); |
227 | 227 | ||
228 | return true; | 228 | return true; |
229 | } | 229 | } |
230 | bool OTodoAccessXML::replace( const OTodo& todo) { | 230 | bool OTodoAccessXML::replace( const OTodo& todo) { |
231 | m_changed = true; | 231 | m_changed = true; |
232 | m_events.replace( todo.uid(), todo ); | 232 | m_events.replace( todo.uid(), todo ); |
233 | 233 | ||
234 | return true; | 234 | return true; |
235 | } | 235 | } |
236 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, | 236 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, |
237 | const QDate& end, | 237 | const QDate& end, |
238 | bool includeNoDates ) { | 238 | bool includeNoDates ) { |
239 | QArray<int> ids( m_events.count() ); | 239 | QArray<int> ids( m_events.count() ); |
240 | QMap<int, OTodo>::Iterator it; | 240 | QMap<int, OTodo>::Iterator it; |
241 | 241 | ||
242 | int i = 0; | 242 | int i = 0; |
243 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 243 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
244 | if ( !it.data().hasDueDate() ) { | 244 | if ( !it.data().hasDueDate() ) { |
245 | if ( includeNoDates ) { | 245 | if ( includeNoDates ) { |
246 | ids[i] = it.key(); | 246 | ids[i] = it.key(); |
247 | i++; | 247 | i++; |
248 | } | 248 | } |
249 | }else if ( it.data().dueDate() >= start && | 249 | }else if ( it.data().dueDate() >= start && |
250 | it.data().dueDate() <= end ) { | 250 | it.data().dueDate() <= end ) { |
251 | ids[i] = it.key(); | 251 | ids[i] = it.key(); |
252 | i++; | 252 | i++; |
253 | } | 253 | } |
254 | } | 254 | } |
255 | ids.resize( i ); | 255 | ids.resize( i ); |
256 | return ids; | 256 | return ids; |
257 | } | 257 | } |
258 | QArray<int> OTodoAccessXML::overDue() { | 258 | QArray<int> OTodoAccessXML::overDue() { |
259 | QArray<int> ids( m_events.count() ); | 259 | QArray<int> ids( m_events.count() ); |
260 | int i = 0; | 260 | int i = 0; |
261 | 261 | ||
262 | QMap<int, OTodo>::Iterator it; | 262 | QMap<int, OTodo>::Iterator it; |
263 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 263 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
264 | if ( it.data().isOverdue() ) { | 264 | if ( it.data().isOverdue() ) { |
265 | ids[i] = it.key(); | 265 | ids[i] = it.key(); |
266 | i++; | 266 | i++; |
267 | } | 267 | } |
268 | } | 268 | } |
269 | ids.resize( i ); | 269 | ids.resize( i ); |
270 | return ids; | 270 | return ids; |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
274 | /* private */ | 274 | /* private */ |
275 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, | 275 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, |
276 | const QCString& attr, const QString& val) { | 276 | const QCString& attr, const QString& val) { |
277 | // qWarning("parse to do from XMLElement" ); | 277 | // qWarning("parse to do from XMLElement" ); |
278 | 278 | ||
279 | int *find=0; | 279 | int *find=0; |
280 | 280 | ||
281 | find = (*dict)[ attr.data() ]; | 281 | find = (*dict)[ attr.data() ]; |
282 | if (!find ) { | 282 | if (!find ) { |
283 | // qWarning("Unknown option" + it.key() ); | 283 | // qWarning("Unknown option" + it.key() ); |
284 | ev.setCustomField( attr, val ); | 284 | ev.setCustomField( attr, val ); |
285 | return; | 285 | return; |
286 | } | 286 | } |
287 | 287 | ||
288 | switch( *find ) { | 288 | switch( *find ) { |
289 | case OTodo::Uid: | 289 | case OTodo::Uid: |
290 | ev.setUid( val.toInt() ); | 290 | ev.setUid( val.toInt() ); |
291 | break; | 291 | break; |
292 | case OTodo::Category: | 292 | case OTodo::Category: |
293 | ev.setCategories( ev.idsFromString( val ) ); | 293 | ev.setCategories( ev.idsFromString( val ) ); |
294 | break; | 294 | break; |
295 | case OTodo::HasDate: | 295 | case OTodo::HasDate: |
296 | ev.setHasDueDate( val.toInt() ); | 296 | ev.setHasDueDate( val.toInt() ); |
297 | break; | 297 | break; |
298 | case OTodo::Completed: | 298 | case OTodo::Completed: |
299 | ev.setCompleted( val.toInt() ); | 299 | ev.setCompleted( val.toInt() ); |
300 | break; | 300 | break; |
301 | case OTodo::Description: | 301 | case OTodo::Description: |
302 | ev.setDescription( val ); | 302 | ev.setDescription( val ); |
303 | break; | 303 | break; |
304 | case OTodo::Summary: | 304 | case OTodo::Summary: |
305 | ev.setSummary( val ); | 305 | ev.setSummary( val ); |
306 | break; | 306 | break; |
307 | case OTodo::Priority: | 307 | case OTodo::Priority: |
308 | ev.setPriority( val.toInt() ); | 308 | ev.setPriority( val.toInt() ); |
309 | break; | 309 | break; |
310 | case OTodo::DateDay: | 310 | case OTodo::DateDay: |
311 | m_day = val.toInt(); | 311 | m_day = val.toInt(); |
312 | break; | 312 | break; |
313 | case OTodo::DateMonth: | 313 | case OTodo::DateMonth: |
314 | m_month = val.toInt(); | 314 | m_month = val.toInt(); |
315 | break; | 315 | break; |
316 | case OTodo::DateYear: | 316 | case OTodo::DateYear: |
317 | m_year = val.toInt(); | 317 | m_year = val.toInt(); |
318 | break; | 318 | break; |
319 | case OTodo::Progress: | 319 | case OTodo::Progress: |
320 | ev.setProgress( val.toInt() ); | 320 | ev.setProgress( val.toInt() ); |
321 | break; | 321 | break; |
322 | case OTodo::CrossReference: | 322 | case OTodo::CrossReference: |
323 | { | 323 | { |
324 | /* | 324 | /* |
325 | * A cross refernce looks like | 325 | * A cross refernce looks like |
326 | * appname,id;appname,id | 326 | * appname,id;appname,id |
327 | * we need to split it up | 327 | * we need to split it up |
328 | */ | 328 | */ |
329 | QStringList refs = QStringList::split(';', val ); | 329 | QStringList refs = QStringList::split(';', val ); |
330 | QStringList::Iterator strIt; | 330 | QStringList::Iterator strIt; |
331 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 331 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
332 | int pos = (*strIt).find(','); | 332 | int pos = (*strIt).find(','); |
333 | if ( pos > -1 ) | 333 | if ( pos > -1 ) |
334 | ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 334 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
335 | 335 | ||
336 | } | 336 | } |
337 | break; | 337 | break; |
338 | } | 338 | } |
339 | case OTodo::HasAlarmDateTime: | 339 | case OTodo::HasAlarmDateTime: |
340 | ev.setHasAlarmDateTime( val.toInt() ); | 340 | ev.setHasAlarmDateTime( val.toInt() ); |
341 | break; | 341 | break; |
342 | case OTodo::AlarmDateTime: { | 342 | case OTodo::AlarmDateTime: { |
343 | /* this sounds better ;) zecke */ | 343 | /* this sounds better ;) zecke */ |
344 | ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) ); | 344 | ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) ); |
345 | break; | 345 | break; |
346 | } | 346 | } |
347 | default: | 347 | default: |
348 | break; | 348 | break; |
349 | } | 349 | } |
350 | } | 350 | } |
351 | QString OTodoAccessXML::toString( const OTodo& ev )const { | 351 | QString OTodoAccessXML::toString( const OTodo& ev )const { |
352 | QString str; | 352 | QString str; |
353 | 353 | ||
354 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 354 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
355 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 355 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
356 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 356 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
357 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 357 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
358 | 358 | ||
359 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 359 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
360 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 360 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
361 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 361 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
362 | 362 | ||
363 | if ( ev.hasDueDate() ) { | 363 | if ( ev.hasDueDate() ) { |
364 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 364 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
365 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 365 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
366 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 366 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
367 | } | 367 | } |
368 | // qWarning( "Uid %d", ev.uid() ); | 368 | // qWarning( "Uid %d", ev.uid() ); |
369 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 369 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
370 | 370 | ||
371 | // append the extra options | 371 | // append the extra options |
372 | /* FIXME Qtopia::Record this is currently not | 372 | /* FIXME Qtopia::Record this is currently not |
373 | * possible you can set custom fields | 373 | * possible you can set custom fields |
374 | * but don' iterate over the list | 374 | * but don' iterate over the list |
375 | * I may do #define private protected | 375 | * I may do #define private protected |
376 | * for this case - cough --zecke | 376 | * for this case - cough --zecke |
377 | */ | 377 | */ |
378 | /* | 378 | /* |
379 | QMap<QString, QString> extras = ev.extras(); | 379 | QMap<QString, QString> extras = ev.extras(); |
380 | QMap<QString, QString>::Iterator extIt; | 380 | QMap<QString, QString>::Iterator extIt; |
381 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 381 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
382 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 382 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
383 | */ | 383 | */ |
384 | // cross refernce | 384 | // cross refernce |
385 | QStringList list = ev.relatedApps(); | ||
386 | QStringList::Iterator listIt; | ||
387 | QString refs; | ||
388 | str += "CrossReference=\""; | ||
389 | bool added = false; | ||
390 | for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { | ||
391 | added = true; | ||
392 | QArray<int> ints = ev.relations( (*listIt) ); | ||
393 | for ( uint i = 0; i< ints.count(); i++ ) { | ||
394 | str += (*listIt) + "," + QString::number( i ) + ";"; | ||
395 | } | ||
396 | } | ||
397 | if ( added ) | ||
398 | str = str.remove( str.length()-1, 1 ); | ||
399 | |||
400 | str += "\" "; | ||
401 | 385 | ||
402 | str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; | 386 | str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; |
403 | 387 | ||
404 | return str; | 388 | return str; |
405 | } | 389 | } |
406 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 390 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
407 | return Qtopia::Record::idsToString( ints ); | 391 | return Qtopia::Record::idsToString( ints ); |
408 | } | 392 | } |
409 | 393 | ||
410 | /* internal class for sorting | 394 | /* internal class for sorting |
411 | * | 395 | * |
412 | * Inspired by todoxmlio.cpp from TT | 396 | * Inspired by todoxmlio.cpp from TT |
413 | */ | 397 | */ |
414 | 398 | ||
415 | struct OTodoXMLContainer { | 399 | struct OTodoXMLContainer { |
416 | OTodo todo; | 400 | OTodo todo; |
417 | }; | 401 | }; |
418 | 402 | ||
419 | namespace { | 403 | namespace { |
420 | inline QString string( const OTodo& todo) { | 404 | inline QString string( const OTodo& todo) { |
421 | return todo.summary().isEmpty() ? | 405 | return todo.summary().isEmpty() ? |
422 | todo.description().left(20 ) : | 406 | todo.description().left(20 ) : |
423 | todo.summary(); | 407 | todo.summary(); |
424 | } | 408 | } |
425 | inline int completed( const OTodo& todo1, const OTodo& todo2) { | 409 | inline int completed( const OTodo& todo1, const OTodo& todo2) { |
426 | int ret = 0; | 410 | int ret = 0; |
427 | if ( todo1.isCompleted() ) ret++; | 411 | if ( todo1.isCompleted() ) ret++; |
428 | if ( todo2.isCompleted() ) ret--; | 412 | if ( todo2.isCompleted() ) ret--; |
429 | return ret; | 413 | return ret; |
430 | } | 414 | } |
431 | inline int priority( const OTodo& t1, const OTodo& t2) { | 415 | inline int priority( const OTodo& t1, const OTodo& t2) { |
432 | return ( t1.priority() - t2.priority() ); | 416 | return ( t1.priority() - t2.priority() ); |
433 | } | 417 | } |
434 | inline int description( const OTodo& t1, const OTodo& t2) { | 418 | inline int description( const OTodo& t1, const OTodo& t2) { |
435 | return QString::compare( string(t1), string(t2) ); | 419 | return QString::compare( string(t1), string(t2) ); |
436 | } | 420 | } |
437 | inline int deadline( const OTodo& t1, const OTodo& t2) { | 421 | inline int deadline( const OTodo& t1, const OTodo& t2) { |
438 | int ret = 0; | 422 | int ret = 0; |
439 | if ( t1.hasDueDate() && | 423 | if ( t1.hasDueDate() && |
440 | t2.hasDueDate() ) | 424 | t2.hasDueDate() ) |
441 | ret = t2.dueDate().daysTo( t1.dueDate() ); | 425 | ret = t2.dueDate().daysTo( t1.dueDate() ); |
442 | else if ( t1.hasDueDate() ) | 426 | else if ( t1.hasDueDate() ) |
443 | ret = -1; | 427 | ret = -1; |
444 | else if ( t2.hasDueDate() ) | 428 | else if ( t2.hasDueDate() ) |
445 | ret = 1; | 429 | ret = 1; |
446 | else | 430 | else |
447 | ret = 0; | 431 | ret = 0; |
448 | 432 | ||
449 | return ret; | 433 | return ret; |
450 | } | 434 | } |
451 | 435 | ||
452 | }; | 436 | }; |
453 | 437 | ||
454 | /* | 438 | /* |
455 | * Returns: | 439 | * Returns: |
456 | * 0 if item1 == item2 | 440 | * 0 if item1 == item2 |
457 | * | 441 | * |
458 | * non-zero if item1 != item2 | 442 | * non-zero if item1 != item2 |
459 | * | 443 | * |
460 | * This function returns int rather than bool so that reimplementations | 444 | * This function returns int rather than bool so that reimplementations |
461 | * can return one of three values and use it to sort by: | 445 | * can return one of three values and use it to sort by: |
462 | * | 446 | * |
463 | * 0 if item1 == item2 | 447 | * 0 if item1 == item2 |
464 | * | 448 | * |
465 | * > 0 (positive integer) if item1 > item2 | 449 | * > 0 (positive integer) if item1 > item2 |
466 | * | 450 | * |
467 | * < 0 (negative integer) if item1 < item2 | 451 | * < 0 (negative integer) if item1 < item2 |
468 | * | 452 | * |
469 | */ | 453 | */ |
470 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { | 454 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { |
471 | public: | 455 | public: |
472 | OTodoXMLVector(int size, bool asc, int sort) | 456 | OTodoXMLVector(int size, bool asc, int sort) |
473 | : QVector<OTodoXMLContainer>( size ) | 457 | : QVector<OTodoXMLContainer>( size ) |
474 | { | 458 | { |
475 | setAutoDelete( true ); | 459 | setAutoDelete( true ); |
476 | m_asc = asc; | 460 | m_asc = asc; |
477 | m_sort = sort; | 461 | m_sort = sort; |
478 | } | 462 | } |
479 | /* return the summary/description */ | 463 | /* return the summary/description */ |
480 | QString string( const OTodo& todo) { | 464 | QString string( const OTodo& todo) { |
481 | return todo.summary().isEmpty() ? | 465 | return todo.summary().isEmpty() ? |
482 | todo.description().left(20 ) : | 466 | todo.description().left(20 ) : |
483 | todo.summary(); | 467 | todo.summary(); |
484 | } | 468 | } |
485 | /** | 469 | /** |
486 | * we take the sortorder( switch on it ) | 470 | * we take the sortorder( switch on it ) |
487 | * | 471 | * |
488 | */ | 472 | */ |
489 | int compareItems( Item d1, Item d2 ) { | 473 | int compareItems( Item d1, Item d2 ) { |
490 | bool seComp, sePrio, seDesc, seDeadline; | 474 | bool seComp, sePrio, seDesc, seDeadline; |
491 | seComp = sePrio = seDeadline = seDesc = false; | 475 | seComp = sePrio = seDeadline = seDesc = false; |
492 | int ret =0; | 476 | int ret =0; |
493 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; | 477 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; |
494 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; | 478 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; |
495 | 479 | ||
496 | /* same item */ | 480 | /* same item */ |
497 | if ( con1->todo.uid() == con2->todo.uid() ) | 481 | if ( con1->todo.uid() == con2->todo.uid() ) |
498 | return 0; | 482 | return 0; |
499 | 483 | ||
500 | switch ( m_sort ) { | 484 | switch ( m_sort ) { |
501 | /* completed */ | 485 | /* completed */ |
502 | case 0: { | 486 | case 0: { |
503 | ret = completed( con1->todo, con2->todo ); | 487 | ret = completed( con1->todo, con2->todo ); |
504 | seComp = TRUE; | 488 | seComp = TRUE; |
505 | break; | 489 | break; |
506 | } | 490 | } |
507 | /* priority */ | 491 | /* priority */ |
508 | case 1: { | 492 | case 1: { |
509 | ret = priority( con1->todo, con2->todo ); | 493 | ret = priority( con1->todo, con2->todo ); |
510 | sePrio = TRUE; | 494 | sePrio = TRUE; |
511 | break; | 495 | break; |
512 | } | 496 | } |
513 | /* description */ | 497 | /* description */ |
514 | case 2: { | 498 | case 2: { |
515 | ret = description( con1->todo, con2->todo ); | 499 | ret = description( con1->todo, con2->todo ); |
516 | seDesc = TRUE; | 500 | seDesc = TRUE; |
517 | break; | 501 | break; |
518 | } | 502 | } |
519 | /* deadline */ | 503 | /* deadline */ |
520 | case 3: { | 504 | case 3: { |
521 | ret = deadline( con1->todo, con2->todo ); | 505 | ret = deadline( con1->todo, con2->todo ); |
522 | seDeadline = TRUE; | 506 | seDeadline = TRUE; |
523 | break; | 507 | break; |
524 | } | 508 | } |
525 | default: | 509 | default: |
526 | ret = 0; | 510 | ret = 0; |
527 | break; | 511 | break; |
528 | }; | 512 | }; |
529 | /* | 513 | /* |
530 | * FIXME do better sorting if the first sort criteria | 514 | * FIXME do better sorting if the first sort criteria |
531 | * ret equals 0 start with complete and so on... | 515 | * ret equals 0 start with complete and so on... |
532 | */ | 516 | */ |
533 | 517 | ||
534 | /* twist it we're not ascending*/ | 518 | /* twist it we're not ascending*/ |
535 | if (!m_asc) | 519 | if (!m_asc) |
536 | ret = ret * -1; | 520 | ret = ret * -1; |
537 | 521 | ||
538 | if ( ret ) | 522 | if ( ret ) |
539 | return ret; | 523 | return ret; |
540 | 524 | ||
541 | // default did not gave difference let's try it other way around | 525 | // default did not gave difference let's try it other way around |
542 | /* | 526 | /* |
543 | * General try if already checked if not test | 527 | * General try if already checked if not test |
544 | * and return | 528 | * and return |
545 | * 1.Completed | 529 | * 1.Completed |
546 | * 2.Priority | 530 | * 2.Priority |
547 | * 3.Description | 531 | * 3.Description |
548 | * 4.DueDate | 532 | * 4.DueDate |
549 | */ | 533 | */ |
550 | if (!seComp ) { | 534 | if (!seComp ) { |
551 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { | 535 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { |
552 | if (!m_asc ) ret *= -1; | 536 | if (!m_asc ) ret *= -1; |
553 | return ret; | 537 | return ret; |
554 | } | 538 | } |
555 | } | 539 | } |
556 | if (!sePrio ) { | 540 | if (!sePrio ) { |
557 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { | 541 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { |
558 | if (!m_asc ) ret *= -1; | 542 | if (!m_asc ) ret *= -1; |
559 | return ret; | 543 | return ret; |
560 | } | 544 | } |
561 | } | 545 | } |
562 | if (!seDesc ) { | 546 | if (!seDesc ) { |
563 | if ( (ret = description(con1->todo, con2->todo ) ) ) { | 547 | if ( (ret = description(con1->todo, con2->todo ) ) ) { |
564 | if (!m_asc) ret *= -1; | 548 | if (!m_asc) ret *= -1; |
565 | return ret; | 549 | return ret; |
566 | } | 550 | } |
567 | } | 551 | } |
568 | if (!seDeadline) { | 552 | if (!seDeadline) { |
569 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { | 553 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { |
570 | if (!m_asc) ret *= -1; | 554 | if (!m_asc) ret *= -1; |
571 | return ret; | 555 | return ret; |
572 | } | 556 | } |
573 | } | 557 | } |
574 | 558 | ||
575 | return 0; | 559 | return 0; |
576 | } | 560 | } |
577 | private: | 561 | private: |
578 | bool m_asc; | 562 | bool m_asc; |
579 | int m_sort; | 563 | int m_sort; |
580 | 564 | ||
581 | }; | 565 | }; |
582 | 566 | ||
583 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | 567 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, |
584 | int sortFilter, int cat ) { | 568 | int sortFilter, int cat ) { |
585 | qWarning("sorted! %d cat", cat); | 569 | qWarning("sorted! %d cat", cat); |
586 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); | 570 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); |
587 | QMap<int, OTodo>::Iterator it; | 571 | QMap<int, OTodo>::Iterator it; |
588 | int item = 0; | 572 | int item = 0; |
589 | 573 | ||
590 | bool bCat = sortFilter & 1 ? true : false; | 574 | bool bCat = sortFilter & 1 ? true : false; |
591 | bool bOnly = sortFilter & 2 ? true : false; | 575 | bool bOnly = sortFilter & 2 ? true : false; |
592 | bool comp = sortFilter & 4 ? true : false; | 576 | bool comp = sortFilter & 4 ? true : false; |
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index 591e467..c1682c6 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -142,451 +142,435 @@ bool OTodoAccessXML::save() { | |||
142 | QString strNewFile = m_file + ".new"; | 142 | QString strNewFile = m_file + ".new"; |
143 | QFile f( strNewFile ); | 143 | QFile f( strNewFile ); |
144 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 144 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
145 | return false; | 145 | return false; |
146 | 146 | ||
147 | int written; | 147 | int written; |
148 | QString out; | 148 | QString out; |
149 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 149 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
150 | 150 | ||
151 | // for all todos | 151 | // for all todos |
152 | QMap<int, OTodo>::Iterator it; | 152 | QMap<int, OTodo>::Iterator it; |
153 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 153 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
154 | out+= "<Task " + toString( (*it) ) + " />\n"; | 154 | out+= "<Task " + toString( (*it) ) + " />\n"; |
155 | QCString cstr = out.utf8(); | 155 | QCString cstr = out.utf8(); |
156 | written = f.writeBlock( cstr.data(), cstr.length() ); | 156 | written = f.writeBlock( cstr.data(), cstr.length() ); |
157 | 157 | ||
158 | /* less written then we wanted */ | 158 | /* less written then we wanted */ |
159 | if ( written != (int)cstr.length() ) { | 159 | if ( written != (int)cstr.length() ) { |
160 | f.close(); | 160 | f.close(); |
161 | QFile::remove( strNewFile ); | 161 | QFile::remove( strNewFile ); |
162 | return false; | 162 | return false; |
163 | } | 163 | } |
164 | out = QString::null; | 164 | out = QString::null; |
165 | } | 165 | } |
166 | 166 | ||
167 | out += "</Tasks>"; | 167 | out += "</Tasks>"; |
168 | QCString cstr = out.utf8(); | 168 | QCString cstr = out.utf8(); |
169 | written = f.writeBlock( cstr.data(), cstr.length() ); | 169 | written = f.writeBlock( cstr.data(), cstr.length() ); |
170 | 170 | ||
171 | if ( written != (int)cstr.length() ) { | 171 | if ( written != (int)cstr.length() ) { |
172 | f.close(); | 172 | f.close(); |
173 | QFile::remove( strNewFile ); | 173 | QFile::remove( strNewFile ); |
174 | return false; | 174 | return false; |
175 | } | 175 | } |
176 | /* flush before renaming */ | 176 | /* flush before renaming */ |
177 | f.close(); | 177 | f.close(); |
178 | 178 | ||
179 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { | 179 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { |
180 | // qWarning("error renaming"); | 180 | // qWarning("error renaming"); |
181 | QFile::remove( strNewFile ); | 181 | QFile::remove( strNewFile ); |
182 | } | 182 | } |
183 | 183 | ||
184 | m_changed = false; | 184 | m_changed = false; |
185 | return true; | 185 | return true; |
186 | } | 186 | } |
187 | QArray<int> OTodoAccessXML::allRecords()const { | 187 | QArray<int> OTodoAccessXML::allRecords()const { |
188 | QArray<int> ids( m_events.count() ); | 188 | QArray<int> ids( m_events.count() ); |
189 | QMap<int, OTodo>::ConstIterator it; | 189 | QMap<int, OTodo>::ConstIterator it; |
190 | int i = 0; | 190 | int i = 0; |
191 | 191 | ||
192 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 192 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
193 | ids[i] = it.key(); | 193 | ids[i] = it.key(); |
194 | i++; | 194 | i++; |
195 | } | 195 | } |
196 | return ids; | 196 | return ids; |
197 | } | 197 | } |
198 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) { | 198 | QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int ) { |
199 | QArray<int> ids(0); | 199 | QArray<int> ids(0); |
200 | return ids; | 200 | return ids; |
201 | } | 201 | } |
202 | OTodo OTodoAccessXML::find( int uid )const { | 202 | OTodo OTodoAccessXML::find( int uid )const { |
203 | OTodo todo; | 203 | OTodo todo; |
204 | todo.setUid( 0 ); // isEmpty() | 204 | todo.setUid( 0 ); // isEmpty() |
205 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); | 205 | QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); |
206 | if ( it != m_events.end() ) | 206 | if ( it != m_events.end() ) |
207 | todo = it.data(); | 207 | todo = it.data(); |
208 | 208 | ||
209 | return todo; | 209 | return todo; |
210 | } | 210 | } |
211 | void OTodoAccessXML::clear() { | 211 | void OTodoAccessXML::clear() { |
212 | if (m_opened ) | 212 | if (m_opened ) |
213 | m_changed = true; | 213 | m_changed = true; |
214 | 214 | ||
215 | m_events.clear(); | 215 | m_events.clear(); |
216 | } | 216 | } |
217 | bool OTodoAccessXML::add( const OTodo& todo ) { | 217 | bool OTodoAccessXML::add( const OTodo& todo ) { |
218 | // qWarning("add"); | 218 | // qWarning("add"); |
219 | m_changed = true; | 219 | m_changed = true; |
220 | m_events.insert( todo.uid(), todo ); | 220 | m_events.insert( todo.uid(), todo ); |
221 | 221 | ||
222 | return true; | 222 | return true; |
223 | } | 223 | } |
224 | bool OTodoAccessXML::remove( int uid ) { | 224 | bool OTodoAccessXML::remove( int uid ) { |
225 | m_changed = true; | 225 | m_changed = true; |
226 | m_events.remove( uid ); | 226 | m_events.remove( uid ); |
227 | 227 | ||
228 | return true; | 228 | return true; |
229 | } | 229 | } |
230 | bool OTodoAccessXML::replace( const OTodo& todo) { | 230 | bool OTodoAccessXML::replace( const OTodo& todo) { |
231 | m_changed = true; | 231 | m_changed = true; |
232 | m_events.replace( todo.uid(), todo ); | 232 | m_events.replace( todo.uid(), todo ); |
233 | 233 | ||
234 | return true; | 234 | return true; |
235 | } | 235 | } |
236 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, | 236 | QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, |
237 | const QDate& end, | 237 | const QDate& end, |
238 | bool includeNoDates ) { | 238 | bool includeNoDates ) { |
239 | QArray<int> ids( m_events.count() ); | 239 | QArray<int> ids( m_events.count() ); |
240 | QMap<int, OTodo>::Iterator it; | 240 | QMap<int, OTodo>::Iterator it; |
241 | 241 | ||
242 | int i = 0; | 242 | int i = 0; |
243 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 243 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
244 | if ( !it.data().hasDueDate() ) { | 244 | if ( !it.data().hasDueDate() ) { |
245 | if ( includeNoDates ) { | 245 | if ( includeNoDates ) { |
246 | ids[i] = it.key(); | 246 | ids[i] = it.key(); |
247 | i++; | 247 | i++; |
248 | } | 248 | } |
249 | }else if ( it.data().dueDate() >= start && | 249 | }else if ( it.data().dueDate() >= start && |
250 | it.data().dueDate() <= end ) { | 250 | it.data().dueDate() <= end ) { |
251 | ids[i] = it.key(); | 251 | ids[i] = it.key(); |
252 | i++; | 252 | i++; |
253 | } | 253 | } |
254 | } | 254 | } |
255 | ids.resize( i ); | 255 | ids.resize( i ); |
256 | return ids; | 256 | return ids; |
257 | } | 257 | } |
258 | QArray<int> OTodoAccessXML::overDue() { | 258 | QArray<int> OTodoAccessXML::overDue() { |
259 | QArray<int> ids( m_events.count() ); | 259 | QArray<int> ids( m_events.count() ); |
260 | int i = 0; | 260 | int i = 0; |
261 | 261 | ||
262 | QMap<int, OTodo>::Iterator it; | 262 | QMap<int, OTodo>::Iterator it; |
263 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 263 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
264 | if ( it.data().isOverdue() ) { | 264 | if ( it.data().isOverdue() ) { |
265 | ids[i] = it.key(); | 265 | ids[i] = it.key(); |
266 | i++; | 266 | i++; |
267 | } | 267 | } |
268 | } | 268 | } |
269 | ids.resize( i ); | 269 | ids.resize( i ); |
270 | return ids; | 270 | return ids; |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
274 | /* private */ | 274 | /* private */ |
275 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, | 275 | void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, |
276 | const QCString& attr, const QString& val) { | 276 | const QCString& attr, const QString& val) { |
277 | // qWarning("parse to do from XMLElement" ); | 277 | // qWarning("parse to do from XMLElement" ); |
278 | 278 | ||
279 | int *find=0; | 279 | int *find=0; |
280 | 280 | ||
281 | find = (*dict)[ attr.data() ]; | 281 | find = (*dict)[ attr.data() ]; |
282 | if (!find ) { | 282 | if (!find ) { |
283 | // qWarning("Unknown option" + it.key() ); | 283 | // qWarning("Unknown option" + it.key() ); |
284 | ev.setCustomField( attr, val ); | 284 | ev.setCustomField( attr, val ); |
285 | return; | 285 | return; |
286 | } | 286 | } |
287 | 287 | ||
288 | switch( *find ) { | 288 | switch( *find ) { |
289 | case OTodo::Uid: | 289 | case OTodo::Uid: |
290 | ev.setUid( val.toInt() ); | 290 | ev.setUid( val.toInt() ); |
291 | break; | 291 | break; |
292 | case OTodo::Category: | 292 | case OTodo::Category: |
293 | ev.setCategories( ev.idsFromString( val ) ); | 293 | ev.setCategories( ev.idsFromString( val ) ); |
294 | break; | 294 | break; |
295 | case OTodo::HasDate: | 295 | case OTodo::HasDate: |
296 | ev.setHasDueDate( val.toInt() ); | 296 | ev.setHasDueDate( val.toInt() ); |
297 | break; | 297 | break; |
298 | case OTodo::Completed: | 298 | case OTodo::Completed: |
299 | ev.setCompleted( val.toInt() ); | 299 | ev.setCompleted( val.toInt() ); |
300 | break; | 300 | break; |
301 | case OTodo::Description: | 301 | case OTodo::Description: |
302 | ev.setDescription( val ); | 302 | ev.setDescription( val ); |
303 | break; | 303 | break; |
304 | case OTodo::Summary: | 304 | case OTodo::Summary: |
305 | ev.setSummary( val ); | 305 | ev.setSummary( val ); |
306 | break; | 306 | break; |
307 | case OTodo::Priority: | 307 | case OTodo::Priority: |
308 | ev.setPriority( val.toInt() ); | 308 | ev.setPriority( val.toInt() ); |
309 | break; | 309 | break; |
310 | case OTodo::DateDay: | 310 | case OTodo::DateDay: |
311 | m_day = val.toInt(); | 311 | m_day = val.toInt(); |
312 | break; | 312 | break; |
313 | case OTodo::DateMonth: | 313 | case OTodo::DateMonth: |
314 | m_month = val.toInt(); | 314 | m_month = val.toInt(); |
315 | break; | 315 | break; |
316 | case OTodo::DateYear: | 316 | case OTodo::DateYear: |
317 | m_year = val.toInt(); | 317 | m_year = val.toInt(); |
318 | break; | 318 | break; |
319 | case OTodo::Progress: | 319 | case OTodo::Progress: |
320 | ev.setProgress( val.toInt() ); | 320 | ev.setProgress( val.toInt() ); |
321 | break; | 321 | break; |
322 | case OTodo::CrossReference: | 322 | case OTodo::CrossReference: |
323 | { | 323 | { |
324 | /* | 324 | /* |
325 | * A cross refernce looks like | 325 | * A cross refernce looks like |
326 | * appname,id;appname,id | 326 | * appname,id;appname,id |
327 | * we need to split it up | 327 | * we need to split it up |
328 | */ | 328 | */ |
329 | QStringList refs = QStringList::split(';', val ); | 329 | QStringList refs = QStringList::split(';', val ); |
330 | QStringList::Iterator strIt; | 330 | QStringList::Iterator strIt; |
331 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 331 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
332 | int pos = (*strIt).find(','); | 332 | int pos = (*strIt).find(','); |
333 | if ( pos > -1 ) | 333 | if ( pos > -1 ) |
334 | ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 334 | ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
335 | 335 | ||
336 | } | 336 | } |
337 | break; | 337 | break; |
338 | } | 338 | } |
339 | case OTodo::HasAlarmDateTime: | 339 | case OTodo::HasAlarmDateTime: |
340 | ev.setHasAlarmDateTime( val.toInt() ); | 340 | ev.setHasAlarmDateTime( val.toInt() ); |
341 | break; | 341 | break; |
342 | case OTodo::AlarmDateTime: { | 342 | case OTodo::AlarmDateTime: { |
343 | /* this sounds better ;) zecke */ | 343 | /* this sounds better ;) zecke */ |
344 | ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) ); | 344 | ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) ); |
345 | break; | 345 | break; |
346 | } | 346 | } |
347 | default: | 347 | default: |
348 | break; | 348 | break; |
349 | } | 349 | } |
350 | } | 350 | } |
351 | QString OTodoAccessXML::toString( const OTodo& ev )const { | 351 | QString OTodoAccessXML::toString( const OTodo& ev )const { |
352 | QString str; | 352 | QString str; |
353 | 353 | ||
354 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 354 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
355 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 355 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
356 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 356 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
357 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 357 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
358 | 358 | ||
359 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 359 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
360 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 360 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
361 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 361 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
362 | 362 | ||
363 | if ( ev.hasDueDate() ) { | 363 | if ( ev.hasDueDate() ) { |
364 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 364 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
365 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 365 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
366 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 366 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
367 | } | 367 | } |
368 | // qWarning( "Uid %d", ev.uid() ); | 368 | // qWarning( "Uid %d", ev.uid() ); |
369 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 369 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
370 | 370 | ||
371 | // append the extra options | 371 | // append the extra options |
372 | /* FIXME Qtopia::Record this is currently not | 372 | /* FIXME Qtopia::Record this is currently not |
373 | * possible you can set custom fields | 373 | * possible you can set custom fields |
374 | * but don' iterate over the list | 374 | * but don' iterate over the list |
375 | * I may do #define private protected | 375 | * I may do #define private protected |
376 | * for this case - cough --zecke | 376 | * for this case - cough --zecke |
377 | */ | 377 | */ |
378 | /* | 378 | /* |
379 | QMap<QString, QString> extras = ev.extras(); | 379 | QMap<QString, QString> extras = ev.extras(); |
380 | QMap<QString, QString>::Iterator extIt; | 380 | QMap<QString, QString>::Iterator extIt; |
381 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 381 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
382 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 382 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
383 | */ | 383 | */ |
384 | // cross refernce | 384 | // cross refernce |
385 | QStringList list = ev.relatedApps(); | ||
386 | QStringList::Iterator listIt; | ||
387 | QString refs; | ||
388 | str += "CrossReference=\""; | ||
389 | bool added = false; | ||
390 | for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { | ||
391 | added = true; | ||
392 | QArray<int> ints = ev.relations( (*listIt) ); | ||
393 | for ( uint i = 0; i< ints.count(); i++ ) { | ||
394 | str += (*listIt) + "," + QString::number( i ) + ";"; | ||
395 | } | ||
396 | } | ||
397 | if ( added ) | ||
398 | str = str.remove( str.length()-1, 1 ); | ||
399 | |||
400 | str += "\" "; | ||
401 | 385 | ||
402 | str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; | 386 | str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; |
403 | 387 | ||
404 | return str; | 388 | return str; |
405 | } | 389 | } |
406 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 390 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
407 | return Qtopia::Record::idsToString( ints ); | 391 | return Qtopia::Record::idsToString( ints ); |
408 | } | 392 | } |
409 | 393 | ||
410 | /* internal class for sorting | 394 | /* internal class for sorting |
411 | * | 395 | * |
412 | * Inspired by todoxmlio.cpp from TT | 396 | * Inspired by todoxmlio.cpp from TT |
413 | */ | 397 | */ |
414 | 398 | ||
415 | struct OTodoXMLContainer { | 399 | struct OTodoXMLContainer { |
416 | OTodo todo; | 400 | OTodo todo; |
417 | }; | 401 | }; |
418 | 402 | ||
419 | namespace { | 403 | namespace { |
420 | inline QString string( const OTodo& todo) { | 404 | inline QString string( const OTodo& todo) { |
421 | return todo.summary().isEmpty() ? | 405 | return todo.summary().isEmpty() ? |
422 | todo.description().left(20 ) : | 406 | todo.description().left(20 ) : |
423 | todo.summary(); | 407 | todo.summary(); |
424 | } | 408 | } |
425 | inline int completed( const OTodo& todo1, const OTodo& todo2) { | 409 | inline int completed( const OTodo& todo1, const OTodo& todo2) { |
426 | int ret = 0; | 410 | int ret = 0; |
427 | if ( todo1.isCompleted() ) ret++; | 411 | if ( todo1.isCompleted() ) ret++; |
428 | if ( todo2.isCompleted() ) ret--; | 412 | if ( todo2.isCompleted() ) ret--; |
429 | return ret; | 413 | return ret; |
430 | } | 414 | } |
431 | inline int priority( const OTodo& t1, const OTodo& t2) { | 415 | inline int priority( const OTodo& t1, const OTodo& t2) { |
432 | return ( t1.priority() - t2.priority() ); | 416 | return ( t1.priority() - t2.priority() ); |
433 | } | 417 | } |
434 | inline int description( const OTodo& t1, const OTodo& t2) { | 418 | inline int description( const OTodo& t1, const OTodo& t2) { |
435 | return QString::compare( string(t1), string(t2) ); | 419 | return QString::compare( string(t1), string(t2) ); |
436 | } | 420 | } |
437 | inline int deadline( const OTodo& t1, const OTodo& t2) { | 421 | inline int deadline( const OTodo& t1, const OTodo& t2) { |
438 | int ret = 0; | 422 | int ret = 0; |
439 | if ( t1.hasDueDate() && | 423 | if ( t1.hasDueDate() && |
440 | t2.hasDueDate() ) | 424 | t2.hasDueDate() ) |
441 | ret = t2.dueDate().daysTo( t1.dueDate() ); | 425 | ret = t2.dueDate().daysTo( t1.dueDate() ); |
442 | else if ( t1.hasDueDate() ) | 426 | else if ( t1.hasDueDate() ) |
443 | ret = -1; | 427 | ret = -1; |
444 | else if ( t2.hasDueDate() ) | 428 | else if ( t2.hasDueDate() ) |
445 | ret = 1; | 429 | ret = 1; |
446 | else | 430 | else |
447 | ret = 0; | 431 | ret = 0; |
448 | 432 | ||
449 | return ret; | 433 | return ret; |
450 | } | 434 | } |
451 | 435 | ||
452 | }; | 436 | }; |
453 | 437 | ||
454 | /* | 438 | /* |
455 | * Returns: | 439 | * Returns: |
456 | * 0 if item1 == item2 | 440 | * 0 if item1 == item2 |
457 | * | 441 | * |
458 | * non-zero if item1 != item2 | 442 | * non-zero if item1 != item2 |
459 | * | 443 | * |
460 | * This function returns int rather than bool so that reimplementations | 444 | * This function returns int rather than bool so that reimplementations |
461 | * can return one of three values and use it to sort by: | 445 | * can return one of three values and use it to sort by: |
462 | * | 446 | * |
463 | * 0 if item1 == item2 | 447 | * 0 if item1 == item2 |
464 | * | 448 | * |
465 | * > 0 (positive integer) if item1 > item2 | 449 | * > 0 (positive integer) if item1 > item2 |
466 | * | 450 | * |
467 | * < 0 (negative integer) if item1 < item2 | 451 | * < 0 (negative integer) if item1 < item2 |
468 | * | 452 | * |
469 | */ | 453 | */ |
470 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { | 454 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { |
471 | public: | 455 | public: |
472 | OTodoXMLVector(int size, bool asc, int sort) | 456 | OTodoXMLVector(int size, bool asc, int sort) |
473 | : QVector<OTodoXMLContainer>( size ) | 457 | : QVector<OTodoXMLContainer>( size ) |
474 | { | 458 | { |
475 | setAutoDelete( true ); | 459 | setAutoDelete( true ); |
476 | m_asc = asc; | 460 | m_asc = asc; |
477 | m_sort = sort; | 461 | m_sort = sort; |
478 | } | 462 | } |
479 | /* return the summary/description */ | 463 | /* return the summary/description */ |
480 | QString string( const OTodo& todo) { | 464 | QString string( const OTodo& todo) { |
481 | return todo.summary().isEmpty() ? | 465 | return todo.summary().isEmpty() ? |
482 | todo.description().left(20 ) : | 466 | todo.description().left(20 ) : |
483 | todo.summary(); | 467 | todo.summary(); |
484 | } | 468 | } |
485 | /** | 469 | /** |
486 | * we take the sortorder( switch on it ) | 470 | * we take the sortorder( switch on it ) |
487 | * | 471 | * |
488 | */ | 472 | */ |
489 | int compareItems( Item d1, Item d2 ) { | 473 | int compareItems( Item d1, Item d2 ) { |
490 | bool seComp, sePrio, seDesc, seDeadline; | 474 | bool seComp, sePrio, seDesc, seDeadline; |
491 | seComp = sePrio = seDeadline = seDesc = false; | 475 | seComp = sePrio = seDeadline = seDesc = false; |
492 | int ret =0; | 476 | int ret =0; |
493 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; | 477 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; |
494 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; | 478 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; |
495 | 479 | ||
496 | /* same item */ | 480 | /* same item */ |
497 | if ( con1->todo.uid() == con2->todo.uid() ) | 481 | if ( con1->todo.uid() == con2->todo.uid() ) |
498 | return 0; | 482 | return 0; |
499 | 483 | ||
500 | switch ( m_sort ) { | 484 | switch ( m_sort ) { |
501 | /* completed */ | 485 | /* completed */ |
502 | case 0: { | 486 | case 0: { |
503 | ret = completed( con1->todo, con2->todo ); | 487 | ret = completed( con1->todo, con2->todo ); |
504 | seComp = TRUE; | 488 | seComp = TRUE; |
505 | break; | 489 | break; |
506 | } | 490 | } |
507 | /* priority */ | 491 | /* priority */ |
508 | case 1: { | 492 | case 1: { |
509 | ret = priority( con1->todo, con2->todo ); | 493 | ret = priority( con1->todo, con2->todo ); |
510 | sePrio = TRUE; | 494 | sePrio = TRUE; |
511 | break; | 495 | break; |
512 | } | 496 | } |
513 | /* description */ | 497 | /* description */ |
514 | case 2: { | 498 | case 2: { |
515 | ret = description( con1->todo, con2->todo ); | 499 | ret = description( con1->todo, con2->todo ); |
516 | seDesc = TRUE; | 500 | seDesc = TRUE; |
517 | break; | 501 | break; |
518 | } | 502 | } |
519 | /* deadline */ | 503 | /* deadline */ |
520 | case 3: { | 504 | case 3: { |
521 | ret = deadline( con1->todo, con2->todo ); | 505 | ret = deadline( con1->todo, con2->todo ); |
522 | seDeadline = TRUE; | 506 | seDeadline = TRUE; |
523 | break; | 507 | break; |
524 | } | 508 | } |
525 | default: | 509 | default: |
526 | ret = 0; | 510 | ret = 0; |
527 | break; | 511 | break; |
528 | }; | 512 | }; |
529 | /* | 513 | /* |
530 | * FIXME do better sorting if the first sort criteria | 514 | * FIXME do better sorting if the first sort criteria |
531 | * ret equals 0 start with complete and so on... | 515 | * ret equals 0 start with complete and so on... |
532 | */ | 516 | */ |
533 | 517 | ||
534 | /* twist it we're not ascending*/ | 518 | /* twist it we're not ascending*/ |
535 | if (!m_asc) | 519 | if (!m_asc) |
536 | ret = ret * -1; | 520 | ret = ret * -1; |
537 | 521 | ||
538 | if ( ret ) | 522 | if ( ret ) |
539 | return ret; | 523 | return ret; |
540 | 524 | ||
541 | // default did not gave difference let's try it other way around | 525 | // default did not gave difference let's try it other way around |
542 | /* | 526 | /* |
543 | * General try if already checked if not test | 527 | * General try if already checked if not test |
544 | * and return | 528 | * and return |
545 | * 1.Completed | 529 | * 1.Completed |
546 | * 2.Priority | 530 | * 2.Priority |
547 | * 3.Description | 531 | * 3.Description |
548 | * 4.DueDate | 532 | * 4.DueDate |
549 | */ | 533 | */ |
550 | if (!seComp ) { | 534 | if (!seComp ) { |
551 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { | 535 | if ( (ret = completed( con1->todo, con2->todo ) ) ) { |
552 | if (!m_asc ) ret *= -1; | 536 | if (!m_asc ) ret *= -1; |
553 | return ret; | 537 | return ret; |
554 | } | 538 | } |
555 | } | 539 | } |
556 | if (!sePrio ) { | 540 | if (!sePrio ) { |
557 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { | 541 | if ( (ret = priority( con1->todo, con2->todo ) ) ) { |
558 | if (!m_asc ) ret *= -1; | 542 | if (!m_asc ) ret *= -1; |
559 | return ret; | 543 | return ret; |
560 | } | 544 | } |
561 | } | 545 | } |
562 | if (!seDesc ) { | 546 | if (!seDesc ) { |
563 | if ( (ret = description(con1->todo, con2->todo ) ) ) { | 547 | if ( (ret = description(con1->todo, con2->todo ) ) ) { |
564 | if (!m_asc) ret *= -1; | 548 | if (!m_asc) ret *= -1; |
565 | return ret; | 549 | return ret; |
566 | } | 550 | } |
567 | } | 551 | } |
568 | if (!seDeadline) { | 552 | if (!seDeadline) { |
569 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { | 553 | if ( (ret = deadline( con1->todo, con2->todo ) ) ) { |
570 | if (!m_asc) ret *= -1; | 554 | if (!m_asc) ret *= -1; |
571 | return ret; | 555 | return ret; |
572 | } | 556 | } |
573 | } | 557 | } |
574 | 558 | ||
575 | return 0; | 559 | return 0; |
576 | } | 560 | } |
577 | private: | 561 | private: |
578 | bool m_asc; | 562 | bool m_asc; |
579 | int m_sort; | 563 | int m_sort; |
580 | 564 | ||
581 | }; | 565 | }; |
582 | 566 | ||
583 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | 567 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, |
584 | int sortFilter, int cat ) { | 568 | int sortFilter, int cat ) { |
585 | qWarning("sorted! %d cat", cat); | 569 | qWarning("sorted! %d cat", cat); |
586 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); | 570 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); |
587 | QMap<int, OTodo>::Iterator it; | 571 | QMap<int, OTodo>::Iterator it; |
588 | int item = 0; | 572 | int item = 0; |
589 | 573 | ||
590 | bool bCat = sortFilter & 1 ? true : false; | 574 | bool bCat = sortFilter & 1 ? true : false; |
591 | bool bOnly = sortFilter & 2 ? true : false; | 575 | bool bOnly = sortFilter & 2 ? true : false; |
592 | bool comp = sortFilter & 4 ? true : false; | 576 | bool comp = sortFilter & 4 ? true : false; |
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp index 21cf131..0e3be9d 100644 --- a/libopie2/opiepim/core/opimrecord.cpp +++ b/libopie2/opiepim/core/opimrecord.cpp | |||
@@ -1,132 +1,81 @@ | |||
1 | #include <qpe/categories.h> | 1 | #include <qpe/categories.h> |
2 | #include <qpe/categoryselect.h> | 2 | #include <qpe/categoryselect.h> |
3 | 3 | ||
4 | #include "opimrecord.h" | 4 | #include "opimrecord.h" |
5 | 5 | ||
6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | 6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); |
7 | 7 | ||
8 | 8 | ||
9 | OPimRecord::OPimRecord( int uid ) | 9 | OPimRecord::OPimRecord( int uid ) |
10 | : Qtopia::Record() { | 10 | : Qtopia::Record() { |
11 | 11 | ||
12 | setUid( uid ); | 12 | setUid( uid ); |
13 | } | 13 | } |
14 | OPimRecord::~OPimRecord() { | 14 | OPimRecord::~OPimRecord() { |
15 | } | 15 | } |
16 | OPimRecord::OPimRecord( const OPimRecord& rec ) | 16 | OPimRecord::OPimRecord( const OPimRecord& rec ) |
17 | : Qtopia::Record( rec ) | 17 | : Qtopia::Record( rec ) |
18 | { | 18 | { |
19 | (*this) = rec; | 19 | (*this) = rec; |
20 | } | 20 | } |
21 | 21 | ||
22 | OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { | 22 | OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { |
23 | Qtopia::Record::operator=( rec ); | 23 | Qtopia::Record::operator=( rec ); |
24 | m_relations = rec.m_relations; | 24 | m_xrefman = rec.m_xrefman; |
25 | 25 | ||
26 | return *this; | 26 | return *this; |
27 | } | 27 | } |
28 | /* | 28 | /* |
29 | * category names | 29 | * category names |
30 | */ | 30 | */ |
31 | QStringList OPimRecord::categoryNames()const { | 31 | QStringList OPimRecord::categoryNames()const { |
32 | QStringList list; | 32 | QStringList list; |
33 | QArray<int> cats = categories(); | 33 | QArray<int> cats = categories(); |
34 | Categories catDB; | 34 | Categories catDB; |
35 | catDB.load( categoryFileName() ); | 35 | catDB.load( categoryFileName() ); |
36 | 36 | ||
37 | for (uint i = 0; i < cats.count(); i++ ) { | 37 | for (uint i = 0; i < cats.count(); i++ ) { |
38 | list << catDB.label("Todo List", cats[i] ); | 38 | list << catDB.label("Todo List", cats[i] ); |
39 | } | 39 | } |
40 | 40 | ||
41 | return list; | 41 | return list; |
42 | } | 42 | } |
43 | void OPimRecord::setCategoryNames( const QStringList& ) { | 43 | void OPimRecord::setCategoryNames( const QStringList& ) { |
44 | 44 | ||
45 | } | 45 | } |
46 | void OPimRecord::addCategoryName( const QString& ) { | 46 | void OPimRecord::addCategoryName( const QString& ) { |
47 | Categories catDB; | 47 | Categories catDB; |
48 | catDB.load( categoryFileName() ); | 48 | catDB.load( categoryFileName() ); |
49 | 49 | ||
50 | 50 | ||
51 | } | 51 | } |
52 | bool OPimRecord::isEmpty()const { | 52 | bool OPimRecord::isEmpty()const { |
53 | return ( uid() == 0 ); | 53 | return ( uid() == 0 ); |
54 | } | 54 | } |
55 | QStringList OPimRecord::relatedApps()const{ | 55 | /*QString OPimRecord::crossToString()const { |
56 | QStringList list; | ||
57 | QMap<QString, QArray<int> >::ConstIterator it; | ||
58 | for ( it = m_relations.begin(); it != m_relations.end(); ++it ) { | ||
59 | list << it.key(); | ||
60 | } | ||
61 | return list; | ||
62 | } | ||
63 | QArray<int> OPimRecord::relations(const QString& app )const { | ||
64 | QArray<int> tmp; | ||
65 | QMap<QString, QArray<int> >::ConstIterator it; | ||
66 | it = m_relations.find( app); | ||
67 | if ( it != m_relations.end() ) | ||
68 | tmp = it.data(); | ||
69 | return tmp; | ||
70 | } | ||
71 | void OPimRecord::clearRelation( const QString& app ) { | ||
72 | m_relations.remove( app ); | ||
73 | } | ||
74 | void OPimRecord::addRelation( const QString& app, int id ) { | ||
75 | |||
76 | QMap<QString, QArray<int> >::Iterator it; | ||
77 | QArray<int> tmp; | ||
78 | |||
79 | it = m_relations.find( app ); | ||
80 | if ( it == m_relations.end() ) { | ||
81 | tmp.resize(1 ); | ||
82 | tmp[0] = id; | ||
83 | }else{ | ||
84 | tmp = it.data(); | ||
85 | tmp.resize( tmp.size() + 1 ); | ||
86 | tmp[tmp.size() - 1] = id; | ||
87 | } | ||
88 | m_relations.replace( app, tmp ); | ||
89 | } | ||
90 | void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { | ||
91 | |||
92 | QMap<QString, QArray<int> >::Iterator it; | ||
93 | QArray<int> tmp; | ||
94 | |||
95 | it = m_relations.find( app); | ||
96 | if ( it == m_relations.end() ) { | ||
97 | tmp = ids; | ||
98 | }else{ | ||
99 | tmp = it.data(); | ||
100 | int offset = tmp.size()-1; | ||
101 | tmp.resize( tmp.size() + ids.size() ); | ||
102 | for (uint i = 0; i < ids.size(); i++ ) { | ||
103 | tmp[offset+i] = ids[i]; | ||
104 | } | ||
105 | |||
106 | } | ||
107 | m_relations.replace( app, tmp ); | ||
108 | } | ||
109 | QString OPimRecord::crossToString()const { | ||
110 | QString str; | 56 | QString str; |
111 | QMap<QString, QArray<int> >::ConstIterator it; | 57 | QMap<QString, QArray<int> >::ConstIterator it; |
112 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { | 58 | for (it = m_relations.begin(); it != m_relations.end(); ++it ) { |
113 | QArray<int> id = it.data(); | 59 | QArray<int> id = it.data(); |
114 | for ( uint i = 0; i < id.size(); ++i ) { | 60 | for ( uint i = 0; i < id.size(); ++i ) { |
115 | str += it.key() + "," + QString::number( i ) + ";"; | 61 | str += it.key() + "," + QString::number( i ) + ";"; |
116 | } | 62 | } |
117 | } | 63 | } |
118 | str = str.remove( str.length()-1, 1); // strip the ; | 64 | str = str.remove( str.length()-1, 1); // strip the ; |
119 | //qWarning("IDS " + str ); | 65 | //qWarning("IDS " + str ); |
120 | 66 | ||
121 | return str; | 67 | return str; |
122 | } | 68 | }*/ |
123 | /* if uid = 1 assign a new one */ | 69 | /* if uid = 1 assign a new one */ |
124 | void OPimRecord::setUid( int uid ) { | 70 | void OPimRecord::setUid( int uid ) { |
125 | if ( uid == 1) | 71 | if ( uid == 1) |
126 | uid = uidGen().generate(); | 72 | uid = uidGen().generate(); |
127 | 73 | ||
128 | Qtopia::Record::setUid( uid ); | 74 | Qtopia::Record::setUid( uid ); |
129 | }; | 75 | }; |
130 | Qtopia::UidGen &OPimRecord::uidGen() { | 76 | Qtopia::UidGen &OPimRecord::uidGen() { |
131 | return m_uidGen; | 77 | return m_uidGen; |
132 | } | 78 | } |
79 | OPimXRefManager &OPimRecord::xrefmanager() { | ||
80 | return m_xrefman; | ||
81 | } | ||
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h index d9ccad4..1642a5e 100644 --- a/libopie2/opiepim/core/opimrecord.h +++ b/libopie2/opiepim/core/opimrecord.h | |||
@@ -1,133 +1,116 @@ | |||
1 | #ifndef OPIE_PIM_RECORD_H | 1 | #ifndef OPIE_PIM_RECORD_H |
2 | #define OPIE_PIM_RECORD_H | 2 | #define OPIE_PIM_RECORD_H |
3 | 3 | ||
4 | #include <qmap.h> | 4 | #include <qmap.h> |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | #include <qpe/palmtoprecord.h> | 8 | #include <qpe/palmtoprecord.h> |
9 | 9 | ||
10 | #include <opie/opimxrefmanager.h> | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * This is the base class for | 13 | * This is the base class for |
13 | * all PIM Records | 14 | * all PIM Records |
14 | * | 15 | * |
15 | */ | 16 | */ |
16 | class OPimRecord : public Qtopia::Record { | 17 | class OPimRecord : public Qtopia::Record { |
17 | public: | 18 | public: |
18 | /** | 19 | /** |
19 | * c'tor | 20 | * c'tor |
20 | * uid of 0 isEmpty | 21 | * uid of 0 isEmpty |
21 | * uid of 1 will be assigned a new one | 22 | * uid of 1 will be assigned a new one |
22 | */ | 23 | */ |
23 | OPimRecord(int uid = 0); | 24 | OPimRecord(int uid = 0); |
24 | ~OPimRecord(); | 25 | ~OPimRecord(); |
25 | 26 | ||
26 | /** | 27 | /** |
27 | * copy c'tor | 28 | * copy c'tor |
28 | */ | 29 | */ |
29 | OPimRecord( const OPimRecord& rec ); | 30 | OPimRecord( const OPimRecord& rec ); |
30 | 31 | ||
31 | /** | 32 | /** |
32 | * copy operator | 33 | * copy operator |
33 | */ | 34 | */ |
34 | OPimRecord &operator=( const OPimRecord& ); | 35 | OPimRecord &operator=( const OPimRecord& ); |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * category names resolved | 38 | * category names resolved |
38 | */ | 39 | */ |
39 | QStringList categoryNames()const; | 40 | QStringList categoryNames()const; |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * set category names they will be resolved | 43 | * set category names they will be resolved |
43 | */ | 44 | */ |
44 | void setCategoryNames( const QStringList& ); | 45 | void setCategoryNames( const QStringList& ); |
45 | 46 | ||
46 | /** | 47 | /** |
47 | * addCategoryName adds a name | 48 | * addCategoryName adds a name |
48 | * to the internal category list | 49 | * to the internal category list |
49 | */ | 50 | */ |
50 | void addCategoryName( const QString& ); | 51 | void addCategoryName( const QString& ); |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * if a Record isEmpty | 54 | * if a Record isEmpty |
54 | * it's empty if it's 0 | 55 | * it's empty if it's 0 |
55 | */ | 56 | */ |
56 | virtual bool isEmpty()const; | 57 | virtual bool isEmpty()const; |
57 | 58 | ||
58 | /** | 59 | /** |
59 | * toRichText summary | 60 | * toRichText summary |
60 | */ | 61 | */ |
61 | virtual QString toRichText()const = 0; | 62 | virtual QString toRichText()const = 0; |
62 | 63 | ||
63 | /** | 64 | /** |
64 | * a small one line summary | 65 | * a small one line summary |
65 | */ | 66 | */ |
66 | virtual QString toShortText()const = 0; | 67 | virtual QString toShortText()const = 0; |
67 | 68 | ||
68 | /** | 69 | /** |
69 | * the name of the Record | 70 | * the name of the Record |
70 | */ | 71 | */ |
71 | virtual QString type()const = 0; | 72 | virtual QString type()const = 0; |
72 | 73 | ||
73 | /** | 74 | /** |
74 | * converts the internal structure to a map | 75 | * converts the internal structure to a map |
75 | */ | 76 | */ |
76 | virtual QMap<int, QString> toMap()const = 0; | 77 | virtual QMap<int, QString> toMap()const = 0; |
77 | 78 | ||
78 | /** | 79 | /** |
79 | * key value representation of extra items | 80 | * key value representation of extra items |
80 | */ | 81 | */ |
81 | virtual QMap<QString, QString> toExtraMap()const = 0; | 82 | virtual QMap<QString, QString> toExtraMap()const = 0; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * the name for a recordField | 85 | * the name for a recordField |
85 | */ | 86 | */ |
86 | virtual QString recordField(int)const = 0; | 87 | virtual QString recordField(int)const = 0; |
87 | 88 | ||
88 | /** | 89 | /** |
89 | * the related apps names | 90 | * returns a reference of the |
91 | * Cross Reference Manager | ||
92 | * Partner One is THIS PIM RECORD! | ||
93 | * Two is the Partner where we link to | ||
90 | */ | 94 | */ |
91 | QStringList relatedApps()const; | 95 | OPimXRefManager& xrefmanager(); |
92 | |||
93 | /** | ||
94 | * the realtions between an app | ||
95 | */ | ||
96 | QArray<int> relations( const QString& app )const; | ||
97 | |||
98 | /** | ||
99 | * clear the relations for all relations | ||
100 | * with app | ||
101 | */ | ||
102 | void clearRelation( const QString& app ); | ||
103 | |||
104 | /** | ||
105 | * add a relation | ||
106 | */ | ||
107 | void addRelation( const QString& app, int id ); | ||
108 | |||
109 | /** | ||
110 | * set the relations for an app | ||
111 | */ | ||
112 | void setRelations( const QString&, QArray<int> ids ); | ||
113 | 96 | ||
114 | /** | 97 | /** |
115 | * set the uid | 98 | * set the uid |
116 | */ | 99 | */ |
117 | virtual void setUid( int uid ); | 100 | virtual void setUid( int uid ); |
118 | 101 | ||
119 | protected: | 102 | protected: |
120 | Qtopia::UidGen &uidGen(); | 103 | Qtopia::UidGen &uidGen(); |
121 | QString crossToString()const; | 104 | // QString crossToString()const; |
122 | 105 | ||
123 | private: | 106 | private: |
124 | class OPimRecordPrivate; | 107 | class OPimRecordPrivate; |
125 | OPimRecordPrivate *d; | 108 | OPimRecordPrivate *d; |
126 | QMap<QString, QArray<int> > m_relations; | 109 | OPimXRefManager m_xrefman; |
127 | static Qtopia::UidGen m_uidGen; | 110 | static Qtopia::UidGen m_uidGen; |
128 | 111 | ||
129 | }; | 112 | }; |
130 | 113 | ||
131 | 114 | ||
132 | 115 | ||
133 | #endif | 116 | #endif |
diff --git a/libopie2/opiepim/core/opimxref.cpp b/libopie2/opiepim/core/opimxref.cpp new file mode 100644 index 0000000..5cae871 --- a/dev/null +++ b/libopie2/opiepim/core/opimxref.cpp | |||
@@ -0,0 +1,47 @@ | |||
1 | #include "opimxref.h" | ||
2 | |||
3 | OPimXRef::OPimXRef( const OPimXRefPartner& one, const OPimXRefPartner& two ) | ||
4 | : m_partners(2) | ||
5 | { | ||
6 | m_partners[0] = one; | ||
7 | m_partners[1] = two; | ||
8 | } | ||
9 | OPimXRef::OPimXRef() | ||
10 | : m_partners(2) | ||
11 | { | ||
12 | |||
13 | } | ||
14 | OPimXRef::OPimXRef( const OPimXRef& ref) { | ||
15 | *this = ref; | ||
16 | } | ||
17 | OPimXRef::~OPimXRef() { | ||
18 | } | ||
19 | OPimXRef &OPimXRef::operator=( const OPimXRef& ref) { | ||
20 | m_partners = ref.m_partners; | ||
21 | m_partners.detach(); | ||
22 | |||
23 | return* this; | ||
24 | } | ||
25 | bool OPimXRef::operator==( const OPimXRef& oper ) { | ||
26 | if ( m_partners == oper.m_partners ) return true; | ||
27 | |||
28 | return false; | ||
29 | } | ||
30 | OPimXRefPartner OPimXRef::partner( enum Partners par) const{ | ||
31 | return m_partners[par]; | ||
32 | } | ||
33 | void OPimXRef::setPartner( enum Partners par, const OPimXRefPartner& part) { | ||
34 | m_partners[par] = part; | ||
35 | } | ||
36 | bool OPimXRef::containsString( const QString& string ) const{ | ||
37 | if ( m_partners[One].appName() == string || | ||
38 | m_partners[Two].appName() == string ) return true; | ||
39 | |||
40 | return false; | ||
41 | } | ||
42 | bool OPimXRef::containsUid( int uid ) const{ | ||
43 | if ( m_partners[One].uid() == uid || | ||
44 | m_partners[Two].uid() == uid ) return true; | ||
45 | |||
46 | return false; | ||
47 | } | ||
diff --git a/libopie2/opiepim/core/opimxref.h b/libopie2/opiepim/core/opimxref.h index 72154ac..354739a 100644 --- a/libopie2/opiepim/core/opimxref.h +++ b/libopie2/opiepim/core/opimxref.h | |||
@@ -1,36 +1,39 @@ | |||
1 | #ifndef OPIM_XREF_H | 1 | #ifndef OPIM_XREF_H |
2 | #define OPIM_XREF_H | 2 | #define OPIM_XREF_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | 6 | ||
7 | #include <opie/opimxrefpartner.h> | 7 | #include <opie/opimxrefpartner.h> |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * this is a Cross Referecne between | 10 | * this is a Cross Referecne between |
11 | * two Cross Reference Partners | 11 | * two Cross Reference Partners |
12 | */ | 12 | */ |
13 | class OPimXRef { | 13 | class OPimXRef { |
14 | public: | 14 | public: |
15 | typedef QValueList<OPimXRef> ValueList; | 15 | typedef QValueList<OPimXRef> ValueList; |
16 | enum Partners { One, Two }; | 16 | enum Partners { One, Two }; |
17 | OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); | 17 | OPimXRef( const OPimXRefPartner& ONE, const OPimXRefPartner& ); |
18 | OPimXRef(); | 18 | OPimXRef(); |
19 | OPimXRef( const OPimXRef& ); | 19 | OPimXRef( const OPimXRef& ); |
20 | ~OPimXRef(); | 20 | ~OPimXRef(); |
21 | 21 | ||
22 | OPimXRef &operator=( const OPimXRef& ); | 22 | OPimXRef &operator=( const OPimXRef& ); |
23 | bool operator==( const OPimXRef ); | 23 | bool operator==( const OPimXRef& ); |
24 | 24 | ||
25 | OPimXRefPartner partner( enum Partners ); | 25 | OPimXRefPartner partner( enum Partners )const; |
26 | 26 | ||
27 | void setPartner( enum Partners, const OPimXRefPartner& ); | 27 | void setPartner( enum Partners, const OPimXRefPartner& ); |
28 | 28 | ||
29 | bool containsString( const QString& appName)const; | ||
30 | bool containsUid( int uid )const; | ||
31 | |||
29 | private: | 32 | private: |
30 | QArray<OPimXRefPartner> m_partners; | 33 | QArray<OPimXRefPartner> m_partners; |
31 | 34 | ||
32 | class Private; | 35 | class Private; |
33 | Private *d; | 36 | Private *d; |
34 | }; | 37 | }; |
35 | 38 | ||
36 | #endif | 39 | #endif |
diff --git a/libopie2/opiepim/core/opimxrefmanager.cpp b/libopie2/opiepim/core/opimxrefmanager.cpp new file mode 100644 index 0000000..d49f5f5 --- a/dev/null +++ b/libopie2/opiepim/core/opimxrefmanager.cpp | |||
@@ -0,0 +1,69 @@ | |||
1 | #include "opimxrefmanager.h" | ||
2 | |||
3 | |||
4 | OPimXRefManager::OPimXRefManager() { | ||
5 | } | ||
6 | OPimXRefManager::OPimXRefManager( const OPimXRefManager& ref) { | ||
7 | m_list = ref.m_list; | ||
8 | } | ||
9 | OPimXRefManager &OPimXRefManager::operator=( const OPimXRefManager& ref) { | ||
10 | m_list = ref.m_list; | ||
11 | return *this; | ||
12 | } | ||
13 | bool OPimXRefManager::operator==( const OPimXRefManager& /*ref*/) { | ||
14 | // if ( m_list == ref.m_list ) return true; | ||
15 | |||
16 | return false; | ||
17 | } | ||
18 | void OPimXRefManager::add( const OPimXRef& ref) { | ||
19 | m_list.append( ref ); | ||
20 | } | ||
21 | void OPimXRefManager::remove( const OPimXRef& ref) { | ||
22 | m_list.remove( ref ); | ||
23 | } | ||
24 | void OPimXRefManager::replace( const OPimXRef& ref) { | ||
25 | m_list.remove( ref ); | ||
26 | m_list.append( ref ); | ||
27 | } | ||
28 | void OPimXRefManager::clear() { | ||
29 | m_list.clear(); | ||
30 | } | ||
31 | QStringList OPimXRefManager::apps()const { | ||
32 | OPimXRef::ValueList::ConstIterator it; | ||
33 | QStringList list; | ||
34 | |||
35 | QString str; | ||
36 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | ||
37 | str = (*it).partner( OPimXRef::One ).appName(); | ||
38 | if ( !list.contains( str ) ) list << str; | ||
39 | |||
40 | str = (*it).partner( OPimXRef::Two ).appName(); | ||
41 | if ( !list.contains( str ) ) list << str; | ||
42 | } | ||
43 | return list; | ||
44 | } | ||
45 | OPimXRef::ValueList OPimXRefManager::list()const { | ||
46 | return m_list; | ||
47 | } | ||
48 | OPimXRef::ValueList OPimXRefManager::list( const QString& appName )const{ | ||
49 | OPimXRef::ValueList list; | ||
50 | OPimXRef::ValueList::ConstIterator it; | ||
51 | |||
52 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | ||
53 | if ( (*it).containsString( appName ) ) | ||
54 | list.append( (*it) ); | ||
55 | } | ||
56 | |||
57 | return list; | ||
58 | } | ||
59 | OPimXRef::ValueList OPimXRefManager::list( int uid )const { | ||
60 | OPimXRef::ValueList list; | ||
61 | OPimXRef::ValueList::ConstIterator it; | ||
62 | |||
63 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | ||
64 | if ( (*it).containsUid( uid ) ) | ||
65 | list.append( (*it) ); | ||
66 | } | ||
67 | |||
68 | return list; | ||
69 | } | ||
diff --git a/libopie2/opiepim/core/opimxrefmanager.h b/libopie2/opiepim/core/opimxrefmanager.h index 147895d..9b003a3 100644 --- a/libopie2/opiepim/core/opimxrefmanager.h +++ b/libopie2/opiepim/core/opimxrefmanager.h | |||
@@ -1,36 +1,41 @@ | |||
1 | #ifndef OPIM_XREF_MANAGER_H | 1 | #ifndef OPIM_XREF_MANAGER_H |
2 | #define OPIM_XREF_MANAGER_H | 2 | #define OPIM_XREF_MANAGER_H |
3 | 3 | ||
4 | #include <qstringlist.h> | ||
5 | |||
4 | #include <opie/opimxref.h> | 6 | #include <opie/opimxref.h> |
5 | 7 | ||
6 | /** | 8 | /** |
7 | * This is a simple manager for | 9 | * This is a simple manager for |
8 | * OPimXRefs. | 10 | * OPimXRefs. |
9 | * It allows addition, removing, replacing | 11 | * It allows addition, removing, replacing |
10 | * clearing and 'querying' the XRef... | 12 | * clearing and 'querying' the XRef... |
11 | */ | 13 | */ |
12 | class OPimXRefManager { | 14 | class OPimXRefManager { |
13 | public: | 15 | public: |
14 | OPimXRefManager(); | 16 | OPimXRefManager(); |
15 | OPimXRefManager( const OPimXRefManager& ); | 17 | OPimXRefManager( const OPimXRefManager& ); |
16 | ~OPimXRefManager(); | 18 | ~OPimXRefManager(); |
17 | 19 | ||
18 | OPimXRefManager& operator=( const OPimXRefManager& ); | 20 | OPimXRefManager& operator=( const OPimXRefManager& ); |
19 | bool operator==( const OPimXRefManager& ); | 21 | bool operator==( const OPimXRefManager& ); |
20 | 22 | ||
21 | void add( const OPimXRef& ); | 23 | void add( const OPimXRef& ); |
22 | void remove( const OPimXRef& ); | 24 | void remove( const OPimXRef& ); |
23 | void replace( const OPimXRef& ); | 25 | void replace( const OPimXRef& ); |
24 | 26 | ||
25 | void clear(); | 27 | void clear(); |
26 | 28 | ||
27 | /** | 29 | /** |
28 | * apps participating | 30 | * apps participating |
29 | */ | 31 | */ |
30 | QStringList apps()const; | 32 | QStringList apps()const; |
31 | OPimXRef::ValueList list()const; | 33 | OPimXRef::ValueList list()const; |
32 | OPimXRef::ValueList list( const QString& appName )const; | 34 | OPimXRef::ValueList list( const QString& appName )const; |
33 | OPimXRef::ValueList list( int uid )const; | 35 | OPimXRef::ValueList list( int uid )const; |
36 | |||
37 | private: | ||
38 | OPimXRef::ValueList m_list; | ||
34 | }; | 39 | }; |
35 | 40 | ||
36 | #endif | 41 | #endif |
diff --git a/libopie2/opiepim/core/opimxrefpartner.cpp b/libopie2/opiepim/core/opimxrefpartner.cpp new file mode 100644 index 0000000..028f4e6 --- a/dev/null +++ b/libopie2/opiepim/core/opimxrefpartner.cpp | |||
@@ -0,0 +1,43 @@ | |||
1 | #include "opimxrefpartner.h" | ||
2 | |||
3 | OPimXRefPartner::OPimXRefPartner( const QString& appName, | ||
4 | int uid, int field ) | ||
5 | : m_app(appName), m_uid(uid), m_field( field ) { | ||
6 | } | ||
7 | OPimXRefPartner::OPimXRefPartner( const OPimXRefPartner& ref ) { | ||
8 | *this = ref; | ||
9 | } | ||
10 | OPimXRefPartner::~OPimXRefPartner() { | ||
11 | } | ||
12 | OPimXRefPartner &OPimXRefPartner::operator=( const OPimXRefPartner& par ) { | ||
13 | m_app = par.m_app; | ||
14 | m_uid = par.m_uid; | ||
15 | m_field = par.m_field; | ||
16 | |||
17 | return *this; | ||
18 | } | ||
19 | bool OPimXRefPartner::operator==( const OPimXRefPartner& par ) { | ||
20 | if ( m_app != par.m_app ) return false; | ||
21 | if ( m_uid != par.m_uid ) return false; | ||
22 | if ( m_field != par.m_field ) return false; | ||
23 | |||
24 | return true; | ||
25 | } | ||
26 | QString OPimXRefPartner::appName()const { | ||
27 | return m_app; | ||
28 | } | ||
29 | int OPimXRefPartner::uid()const { | ||
30 | return m_uid; | ||
31 | } | ||
32 | int OPimXRefPartner::field()const { | ||
33 | return m_field; | ||
34 | } | ||
35 | void OPimXRefPartner::setAppName( const QString& appName ) { | ||
36 | m_app = appName; | ||
37 | } | ||
38 | void OPimXRefPartner::setUid( int uid ) { | ||
39 | m_uid = uid; | ||
40 | } | ||
41 | void OPimXRefPartner::setField( int field ) { | ||
42 | m_field = field; | ||
43 | } | ||