From d6875fba63cc674d2d9cac64a66c3b4c9f3eaba1 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 8 Aug 2020 08:06:22 +0300 Subject: Moved recent URLs history to DocumentWidget App maintains the visited URLs database, but each DocumentWidget has its own stack of recent URLs for timeline navigation. --- src/history.c | 111 +++------------------------------------------------------- 1 file changed, 4 insertions(+), 107 deletions(-) (limited to 'src/history.c') diff --git a/src/history.c b/src/history.c index a2c4271f..c009f484 100644 --- a/src/history.c +++ b/src/history.c @@ -3,10 +3,8 @@ #include #include -#include -static const size_t maxStack_History_ = 50; /* back/forward navigable items */ -static const size_t maxAgeVisited_History_ = 3600 * 24 * 30; /* one month */ +static const size_t maxStack_History_ = 50; /* back/forward navigable items */ void init_RecentUrl(iRecentUrl *d) { init_String(&d->url); @@ -19,30 +17,11 @@ void deinit_RecentUrl(iRecentUrl *d) { delete_GmResponse(d->cachedResponse); } -void init_VisitedUrl(iVisitedUrl *d) { - initCurrent_Time(&d->when); - init_String(&d->url); -} - -void deinit_VisitedUrl(iVisitedUrl *d) { - deinit_String(&d->url); -} - -static int cmpUrl_VisitedUrl_(const void *a, const void *b) { - return cmpString_String(&((const iVisitedUrl *) a)->url, &((const iVisitedUrl *) b)->url); -} - -static int cmpNewer_VisitedUrl_(const void *insert, const void *existing) { - return seconds_Time(&((const iVisitedUrl *) insert )->when) > - seconds_Time(&((const iVisitedUrl *) existing)->when); -} - /*----------------------------------------------------------------------------------------------*/ struct Impl_History { - iArray recent; /* TODO: should be specific to a DocumentWidget */ - size_t recentPos; /* zero at the latest item */ - iSortedArray visited; + iArray recent; /* TODO: should be specific to a DocumentWidget */ + size_t recentPos; /* zero at the latest item */ }; iDefineTypeConstruction(History) @@ -50,13 +29,11 @@ iDefineTypeConstruction(History) void init_History(iHistory *d) { init_Array(&d->recent, sizeof(iRecentUrl)); d->recentPos = 0; - init_SortedArray(&d->visited, sizeof(iVisitedUrl), cmpUrl_VisitedUrl_); } void deinit_History(iHistory *d) { clear_History(d); deinit_Array(&d->recent); - deinit_SortedArray(&d->visited); } void save_History(const iHistory *d, const char *dirPath) { @@ -70,25 +47,6 @@ void save_History(const iHistory *d, const char *dirPath) { } } iRelease(f); - f = newCStr_File(concatPath_CStr(dirPath, "visited.txt")); - if (open_File(f, writeOnly_FileMode | text_FileMode)) { - iConstForEach(Array, i, &d->visited.values) { - const iVisitedUrl *item = i.value; - iDate date; - init_Date(&date, &item->when); - format_String(line, - "%04d-%02d-%02dT%02d:%02d:%02d %s\n", - date.year, - date.month, - date.day, - date.hour, - date.minute, - date.second, - cstr_String(&item->url)); - writeData_File(f, cstr_String(line), size_String(line)); - } - } - iRelease(f); delete_String(line); } @@ -111,29 +69,6 @@ void load_History(iHistory *d, const char *dirPath) { } } iRelease(f); - f = newCStr_File(concatPath_CStr(dirPath, "visited.txt")); - if (open_File(f, readOnly_FileMode | text_FileMode)) { - const iRangecc src = range_Block(collect_Block(readAll_File(f))); - iRangecc line = iNullRange; - iTime now; - initCurrent_Time(&now); - while (nextSplit_Rangecc(&src, "\n", &line)) { - int y, m, D, H, M, S; - sscanf(line.start, "%04d-%02d-%02dT%02d:%02d:%02d ", &y, &m, &D, &H, &M, &S); - if (!y) break; - iVisitedUrl item; - init_VisitedUrl(&item); - init_Time( - &item.when, - &(iDate){ .year = y, .month = m, .day = D, .hour = H, .minute = M, .second = S }); - if (secondsSince_Time(&now, &item.when) > maxAgeVisited_History_) { - continue; /* Too old. */ - } - initRange_String(&item.url, (iRangecc){ line.start + 20, line.end }); - insert_SortedArray(&d->visited, &item); - } - } - iRelease(f); } void clear_History(iHistory *d) { @@ -141,10 +76,6 @@ void clear_History(iHistory *d) { deinit_RecentUrl(s.value); } clear_Array(&d->recent); - iForEach(Array, v, &d->visited.values) { - deinit_VisitedUrl(v.value); - } - clear_SortedArray(&d->visited); } iRecentUrl *recentUrl_History(iHistory *d, size_t pos) { @@ -173,32 +104,15 @@ const iString *url_History(const iHistory *d, size_t pos) { return collectNew_String(); } -static void addVisited_History_(iHistory *d, const iString *url) { - iVisitedUrl visit; - init_VisitedUrl(&visit); - set_String(&visit.url, url); - size_t pos; - if (locate_SortedArray(&d->visited, &visit, &pos)) { - iVisitedUrl *old = at_SortedArray(&d->visited, pos); - if (cmpNewer_VisitedUrl_(&visit, old)) { - old->when = visit.when; - deinit_VisitedUrl(&visit); - return; - } - } - insert_SortedArray(&d->visited, &visit); -} - void replace_History(iHistory *d, const iString *url) { /* Update in the history. */ iRecentUrl *item = mostRecentUrl_History(d); if (item) { set_String(&item->url, url); } - addVisited_History_(d, url); } -void addUrl_History(iHistory *d, const iString *url ){ +void add_History(iHistory *d, const iString *url ){ /* Cut the trailing history items. */ if (d->recentPos > 0) { for (size_t i = 0; i < d->recentPos - 1; i++) { @@ -220,11 +134,6 @@ void addUrl_History(iHistory *d, const iString *url ){ remove_Array(&d->recent, 0); } } - addVisited_History_(d, url); -} - -void visitUrl_History(iHistory *d, const iString *url) { - addVisited_History_(d, url); } iBool goBack_History(iHistory *d) { @@ -247,18 +156,6 @@ iBool goForward_History(iHistory *d) { return iFalse; } -iTime urlVisitTime_History(const iHistory *d, const iString *url) { - iVisitedUrl item; - size_t pos; - iZap(item); - initCopy_String(&item.url, url); - if (locate_SortedArray(&d->visited, &item, &pos)) { - item.when = ((const iVisitedUrl *) constAt_SortedArray(&d->visited, pos))->when; - } - deinit_String(&item.url); - return item.when; -} - const iGmResponse *cachedResponse_History(const iHistory *d) { const iRecentUrl *item = constMostRecentUrl_History(d); return item ? item->cachedResponse : NULL; -- cgit v1.2.3