diff options
Diffstat (limited to 'src/visited.c')
-rw-r--r-- | src/visited.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/visited.c b/src/visited.c index af976be5..ea9a73c9 100644 --- a/src/visited.c +++ b/src/visited.c | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | #include <the_Foundation/file.h> | 4 | #include <the_Foundation/file.h> |
5 | #include <the_Foundation/path.h> | 5 | #include <the_Foundation/path.h> |
6 | #include <the_Foundation/ptrarray.h> | ||
6 | #include <the_Foundation/sortedarray.h> | 7 | #include <the_Foundation/sortedarray.h> |
7 | 8 | ||
8 | static const size_t maxAgeVisited_Visited_ = 3600 * 24 * 30; /* one month */ | 9 | static const size_t maxAgeVisited_Visited_ = 3600 * 24 * 30; /* one month */ |
@@ -99,6 +100,16 @@ void clear_Visited(iVisited *d) { | |||
99 | clear_SortedArray(&d->visited); | 100 | clear_SortedArray(&d->visited); |
100 | } | 101 | } |
101 | 102 | ||
103 | static size_t find_Visited_(const iVisited *d, const iString *url) { | ||
104 | iVisitedUrl visit; | ||
105 | init_VisitedUrl(&visit); | ||
106 | set_String(&visit.url, url); | ||
107 | size_t pos = iInvalidPos; | ||
108 | locate_SortedArray(&d->visited, &visit, &pos); | ||
109 | deinit_VisitedUrl(&visit); | ||
110 | return pos; | ||
111 | } | ||
112 | |||
102 | void visitUrl_Visited(iVisited *d, const iString *url) { | 113 | void visitUrl_Visited(iVisited *d, const iString *url) { |
103 | iVisitedUrl visit; | 114 | iVisitedUrl visit; |
104 | init_VisitedUrl(&visit); | 115 | init_VisitedUrl(&visit); |
@@ -115,6 +126,14 @@ void visitUrl_Visited(iVisited *d, const iString *url) { | |||
115 | insert_SortedArray(&d->visited, &visit); | 126 | insert_SortedArray(&d->visited, &visit); |
116 | } | 127 | } |
117 | 128 | ||
129 | void removeUrl_Visited(iVisited *d, const iString *url) { | ||
130 | size_t pos = find_Visited_(d, url); | ||
131 | if (pos != iInvalidPos) { | ||
132 | deinit_VisitedUrl(at_SortedArray(&d->visited, pos)); | ||
133 | remove_Array(&d->visited.values, pos); | ||
134 | } | ||
135 | } | ||
136 | |||
118 | iTime urlVisitTime_Visited(const iVisited *d, const iString *url) { | 137 | iTime urlVisitTime_Visited(const iVisited *d, const iString *url) { |
119 | iVisitedUrl item; | 138 | iVisitedUrl item; |
120 | size_t pos; | 139 | size_t pos; |
@@ -126,3 +145,17 @@ iTime urlVisitTime_Visited(const iVisited *d, const iString *url) { | |||
126 | deinit_String(&item.url); | 145 | deinit_String(&item.url); |
127 | return item.when; | 146 | return item.when; |
128 | } | 147 | } |
148 | |||
149 | static int cmpWhenDescending_VisitedUrlPtr_(const void *a, const void *b) { | ||
150 | const iVisitedUrl *s = *(const void **) a, *t = *(const void **) b; | ||
151 | return -cmp_Time(&s->when, &t->when); | ||
152 | } | ||
153 | |||
154 | const iArray *list_Visited(const iVisited *d, size_t count) { | ||
155 | iPtrArray *urls = collectNew_PtrArray(); | ||
156 | iConstForEach(Array, i, &d->visited.values) { | ||
157 | pushBack_PtrArray(urls, i.value); | ||
158 | } | ||
159 | sort_Array(urls, cmpWhenDescending_VisitedUrlPtr_); | ||
160 | return urls; | ||
161 | } | ||