author | eilers <eilers> | 2003-08-01 12:30:16 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-01 12:30:16 (UTC) |
commit | 6c715b67a8f0e32a4edca5be91332622834c8d91 (patch) (unidiff) | |
tree | ae2d660e1fd9c990c2d725c075ce6c42480b0af8 /libopie/pim/otodoaccessxml.cpp | |
parent | cb45aa10043fdd6fddcab42ef0e07ddafc3d506d (diff) | |
download | opie-6c715b67a8f0e32a4edca5be91332622834c8d91.zip opie-6c715b67a8f0e32a4edca5be91332622834c8d91.tar.gz opie-6c715b67a8f0e32a4edca5be91332622834c8d91.tar.bz2 |
Merging changes from BRANCH_1_0 to HEAD
Diffstat (limited to 'libopie/pim/otodoaccessxml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 3d15354..f688735 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -42,97 +42,97 @@ namespace { | |||
42 | }; | 42 | }; |
43 | // FROM TT again | 43 | // FROM TT again |
44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) | 44 | char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) |
45 | { | 45 | { |
46 | char needleChar; | 46 | char needleChar; |
47 | char haystackChar; | 47 | char haystackChar; |
48 | if (!needle || !haystack || !hLen || !nLen) | 48 | if (!needle || !haystack || !hLen || !nLen) |
49 | return 0; | 49 | return 0; |
50 | 50 | ||
51 | const char* hsearch = haystack; | 51 | const char* hsearch = haystack; |
52 | 52 | ||
53 | if ((needleChar = *needle++) != 0) { | 53 | if ((needleChar = *needle++) != 0) { |
54 | nLen--; //(to make up for needle++) | 54 | nLen--; //(to make up for needle++) |
55 | do { | 55 | do { |
56 | do { | 56 | do { |
57 | if ((haystackChar = *hsearch++) == 0) | 57 | if ((haystackChar = *hsearch++) == 0) |
58 | return (0); | 58 | return (0); |
59 | if (hsearch >= haystack + hLen) | 59 | if (hsearch >= haystack + hLen) |
60 | return (0); | 60 | return (0); |
61 | } while (haystackChar != needleChar); | 61 | } while (haystackChar != needleChar); |
62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); | 62 | } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); |
63 | hsearch--; | 63 | hsearch--; |
64 | } | 64 | } |
65 | return ((char *)hsearch); | 65 | return ((char *)hsearch); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, | 70 | OTodoAccessXML::OTodoAccessXML( const QString& appName, |
71 | const QString& fileName ) | 71 | const QString& fileName ) |
72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) | 72 | : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) |
73 | { | 73 | { |
74 | if (!fileName.isEmpty() ) | 74 | if (!fileName.isEmpty() ) |
75 | m_file = fileName; | 75 | m_file = fileName; |
76 | else | 76 | else |
77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); | 77 | m_file = Global::applicationFileName( "todolist", "todolist.xml" ); |
78 | } | 78 | } |
79 | OTodoAccessXML::~OTodoAccessXML() { | 79 | OTodoAccessXML::~OTodoAccessXML() { |
80 | 80 | ||
81 | } | 81 | } |
82 | bool OTodoAccessXML::load() { | 82 | bool OTodoAccessXML::load() { |
83 | rec = 0; | 83 | rec = 0; |
84 | m_opened = true; | 84 | m_opened = true; |
85 | m_changed = false; | 85 | m_changed = false; |
86 | /* initialize dict */ | 86 | /* initialize dict */ |
87 | /* | 87 | /* |
88 | * UPDATE dict if you change anything!!! | 88 | * UPDATE dict if you change anything!!! |
89 | */ | 89 | */ |
90 | QAsciiDict<int> dict(21); | 90 | QAsciiDict<int> dict(26); |
91 | dict.setAutoDelete( TRUE ); | 91 | dict.setAutoDelete( TRUE ); |
92 | dict.insert("Categories" , new int(OTodo::Category) ); | 92 | dict.insert("Categories" , new int(OTodo::Category) ); |
93 | dict.insert("Uid" , new int(OTodo::Uid) ); | 93 | dict.insert("Uid" , new int(OTodo::Uid) ); |
94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); | 94 | dict.insert("HasDate" , new int(OTodo::HasDate) ); |
95 | dict.insert("Completed" , new int(OTodo::Completed) ); | 95 | dict.insert("Completed" , new int(OTodo::Completed) ); |
96 | dict.insert("Description" , new int(OTodo::Description) ); | 96 | dict.insert("Description" , new int(OTodo::Description) ); |
97 | dict.insert("Summary" , new int(OTodo::Summary) ); | 97 | dict.insert("Summary" , new int(OTodo::Summary) ); |
98 | dict.insert("Priority" , new int(OTodo::Priority) ); | 98 | dict.insert("Priority" , new int(OTodo::Priority) ); |
99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); | 99 | dict.insert("DateDay" , new int(OTodo::DateDay) ); |
100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 100 | dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); | 101 | dict.insert("DateYear" , new int(OTodo::DateYear) ); |
102 | dict.insert("Progress" , new int(OTodo::Progress) ); | 102 | dict.insert("Progress" , new int(OTodo::Progress) ); |
103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); | 103 | dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); |
104 | dict.insert("StartDate", new int(OTodo::StartDate) ); | 104 | dict.insert("StartDate", new int(OTodo::StartDate) ); |
105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 105 | dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
106 | dict.insert("State", new int(OTodo::State) ); | 106 | dict.insert("State", new int(OTodo::State) ); |
107 | dict.insert("Alarms", new int(OTodo::Alarms) ); | 107 | dict.insert("Alarms", new int(OTodo::Alarms) ); |
108 | dict.insert("Reminders", new int(OTodo::Reminders) ); | 108 | dict.insert("Reminders", new int(OTodo::Reminders) ); |
109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); | 109 | dict.insert("Notifiers", new int(OTodo::Notifiers) ); |
110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); | 110 | dict.insert("Maintainer", new int(OTodo::Maintainer) ); |
111 | dict.insert("rtype", new int(FRType) ); | 111 | dict.insert("rtype", new int(FRType) ); |
112 | dict.insert("rweekdays", new int(FRWeekdays) ); | 112 | dict.insert("rweekdays", new int(FRWeekdays) ); |
113 | dict.insert("rposition", new int(FRPosition) ); | 113 | dict.insert("rposition", new int(FRPosition) ); |
114 | dict.insert("rfreq", new int(FRFreq) ); | 114 | dict.insert("rfreq", new int(FRFreq) ); |
115 | dict.insert("start", new int(FRStart) ); | 115 | dict.insert("start", new int(FRStart) ); |
116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); | 116 | dict.insert("rhasenddate", new int(FRHasEndDate) ); |
117 | dict.insert("enddt", new int(FREndDate) ); | 117 | dict.insert("enddt", new int(FREndDate) ); |
118 | 118 | ||
119 | // here the custom XML parser from TT it's GPL | 119 | // here the custom XML parser from TT it's GPL |
120 | // but we want to push OpiePIM... to TT..... | 120 | // but we want to push OpiePIM... to TT..... |
121 | // mmap part from zecke :) | 121 | // mmap part from zecke :) |
122 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); | 122 | int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); |
123 | struct stat attribut; | 123 | struct stat attribut; |
124 | if ( fd < 0 ) return false; | 124 | if ( fd < 0 ) return false; |
125 | 125 | ||
126 | if ( fstat(fd, &attribut ) == -1 ) { | 126 | if ( fstat(fd, &attribut ) == -1 ) { |
127 | ::close( fd ); | 127 | ::close( fd ); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); | 130 | void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); |
131 | if ( map_addr == ( (caddr_t)-1) ) { | 131 | if ( map_addr == ( (caddr_t)-1) ) { |
132 | ::close(fd ); | 132 | ::close(fd ); |
133 | return false; | 133 | return false; |
134 | } | 134 | } |
135 | /* advise the kernel who we want to read it */ | 135 | /* advise the kernel who we want to read it */ |
136 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); | 136 | ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); |
137 | /* we do not the file any more */ | 137 | /* we do not the file any more */ |
138 | ::close( fd ); | 138 | ::close( fd ); |
@@ -791,84 +791,86 @@ QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | |||
791 | QMap<int, OTodo>::Iterator it; | 791 | QMap<int, OTodo>::Iterator it; |
792 | int item = 0; | 792 | int item = 0; |
793 | 793 | ||
794 | bool bCat = sortFilter & 1 ? true : false; | 794 | bool bCat = sortFilter & 1 ? true : false; |
795 | bool bOnly = sortFilter & 2 ? true : false; | 795 | bool bOnly = sortFilter & 2 ? true : false; |
796 | bool comp = sortFilter & 4 ? true : false; | 796 | bool comp = sortFilter & 4 ? true : false; |
797 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | 797 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { |
798 | 798 | ||
799 | /* show category */ | 799 | /* show category */ |
800 | /* -1 == unfiled */ | 800 | /* -1 == unfiled */ |
801 | if ( bCat && cat == -1 ) { | 801 | if ( bCat && cat == -1 ) { |
802 | if(!(*it).categories().isEmpty() ) | 802 | if(!(*it).categories().isEmpty() ) |
803 | continue; | 803 | continue; |
804 | }else if ( bCat && cat != 0) | 804 | }else if ( bCat && cat != 0) |
805 | if (!(*it).categories().contains( cat ) ) { | 805 | if (!(*it).categories().contains( cat ) ) { |
806 | continue; | 806 | continue; |
807 | } | 807 | } |
808 | /* isOverdue but we should not show overdue - why?*/ | 808 | /* isOverdue but we should not show overdue - why?*/ |
809 | /* if ( (*it).isOverdue() && !bOnly ) { | 809 | /* if ( (*it).isOverdue() && !bOnly ) { |
810 | qWarning("item is overdue but !bOnly"); | 810 | qWarning("item is overdue but !bOnly"); |
811 | continue; | 811 | continue; |
812 | } | 812 | } |
813 | */ | 813 | */ |
814 | if ( !(*it).isOverdue() && bOnly ) { | 814 | if ( !(*it).isOverdue() && bOnly ) { |
815 | continue; | 815 | continue; |
816 | } | 816 | } |
817 | 817 | ||
818 | if ((*it).isCompleted() && comp ) { | 818 | if ((*it).isCompleted() && comp ) { |
819 | continue; | 819 | continue; |
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | OTodoXMLContainer* con = new OTodoXMLContainer(); | 823 | OTodoXMLContainer* con = new OTodoXMLContainer(); |
824 | con->todo = (*it); | 824 | con->todo = (*it); |
825 | vector.insert(item, con ); | 825 | vector.insert(item, con ); |
826 | item++; | 826 | item++; |
827 | } | 827 | } |
828 | vector.resize( item ); | 828 | vector.resize( item ); |
829 | /* sort it now */ | 829 | /* sort it now */ |
830 | vector.sort(); | 830 | vector.sort(); |
831 | /* now get the uids */ | 831 | /* now get the uids */ |
832 | QArray<int> array( vector.count() ); | 832 | QArray<int> array( vector.count() ); |
833 | for (uint i= 0; i < vector.count(); i++ ) { | 833 | for (uint i= 0; i < vector.count(); i++ ) { |
834 | array[i] = ( vector.at(i) )->todo.uid(); | 834 | array[i] = ( vector.at(i) )->todo.uid(); |
835 | } | 835 | } |
836 | return array; | 836 | return array; |
837 | }; | 837 | }; |
838 | void OTodoAccessXML::removeAllCompleted() { | 838 | void OTodoAccessXML::removeAllCompleted() { |
839 | QMap<int, OTodo> events = m_events; | ||
839 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { | 840 | for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { |
840 | if ( (*it).isCompleted() ) | 841 | if ( (*it).isCompleted() ) |
841 | m_events.remove( it ); | 842 | events.remove( it.key() ); |
842 | } | 843 | } |
844 | m_events = events; | ||
843 | } | 845 | } |
844 | QBitArray OTodoAccessXML::supports()const { | 846 | QBitArray OTodoAccessXML::supports()const { |
845 | static QBitArray ar = sup(); | 847 | static QBitArray ar = sup(); |
846 | return ar; | 848 | return ar; |
847 | } | 849 | } |
848 | QBitArray OTodoAccessXML::sup() { | 850 | QBitArray OTodoAccessXML::sup() { |
849 | QBitArray ar( OTodo::CompletedDate +1 ); | 851 | QBitArray ar( OTodo::CompletedDate +1 ); |
850 | ar.fill( true ); | 852 | ar.fill( true ); |
851 | ar[OTodo::CrossReference] = false; | 853 | ar[OTodo::CrossReference] = false; |
852 | ar[OTodo::State ] = false; | 854 | ar[OTodo::State ] = false; |
853 | ar[OTodo::Reminders] = false; | 855 | ar[OTodo::Reminders] = false; |
854 | ar[OTodo::Notifiers] = false; | 856 | ar[OTodo::Notifiers] = false; |
855 | ar[OTodo::Maintainer] = false; | 857 | ar[OTodo::Maintainer] = false; |
856 | 858 | ||
857 | return ar; | 859 | return ar; |
858 | } | 860 | } |
859 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const | 861 | QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const |
860 | { | 862 | { |
861 | QArray<int> m_currentQuery( m_events.count() ); | 863 | QArray<int> m_currentQuery( m_events.count() ); |
862 | uint arraycounter = 0; | 864 | uint arraycounter = 0; |
863 | 865 | ||
864 | QMap<int, OTodo>::ConstIterator it; | 866 | QMap<int, OTodo>::ConstIterator it; |
865 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 867 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
866 | if ( it.data().match( r ) ) | 868 | if ( it.data().match( r ) ) |
867 | m_currentQuery[arraycounter++] = it.data().uid(); | 869 | m_currentQuery[arraycounter++] = it.data().uid(); |
868 | 870 | ||
869 | } | 871 | } |
870 | // Shrink to fit.. | 872 | // Shrink to fit.. |
871 | m_currentQuery.resize(arraycounter); | 873 | m_currentQuery.resize(arraycounter); |
872 | 874 | ||
873 | return m_currentQuery; | 875 | return m_currentQuery; |
874 | } | 876 | } |