diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-10 12:36:42 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-10 12:36:42 +0300 |
commit | b7f40b587087ce4d594ef10af509a5ab92f20466 (patch) | |
tree | 9fc55a0409cb8ad9d038d6bd02e07d7aebe75506 /src/app.c | |
parent | 77ecd8cb2fec2c61f37f4c5561b18fad6fe6137a (diff) |
Preferences: Memory size limit
Memory used for RAM storage of media along with navigation history so it can be restored instantly.
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -210,6 +210,7 @@ static iString *serializePrefs_App_(const iApp *d) { | |||
210 | appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling); | 210 | appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling); |
211 | appendFormat_String(str, "imageloadscroll arg:%d\n", d->prefs.loadImageInsteadOfScrolling); | 211 | appendFormat_String(str, "imageloadscroll arg:%d\n", d->prefs.loadImageInsteadOfScrolling); |
212 | appendFormat_String(str, "cachesize.set arg:%d\n", d->prefs.maxCacheSize); | 212 | appendFormat_String(str, "cachesize.set arg:%d\n", d->prefs.maxCacheSize); |
213 | appendFormat_String(str, "memorysize.set arg:%d\n", d->prefs.maxMemorySize); | ||
213 | appendFormat_String(str, "decodeurls arg:%d\n", d->prefs.decodeUserVisibleURLs); | 214 | appendFormat_String(str, "decodeurls arg:%d\n", d->prefs.decodeUserVisibleURLs); |
214 | appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth); | 215 | appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth); |
215 | /* TODO: Set up an array of booleans in Prefs and do these in a loop. */ | 216 | /* TODO: Set up an array of booleans in Prefs and do these in a loop. */ |
@@ -991,6 +992,33 @@ void trimCache_App(void) { | |||
991 | iRelease(docs); | 992 | iRelease(docs); |
992 | } | 993 | } |
993 | 994 | ||
995 | void trimMemory_App(void) { | ||
996 | iApp *d = &app_; | ||
997 | size_t memorySize = 0; | ||
998 | const size_t limit = d->prefs.maxMemorySize * 1000000; | ||
999 | iObjectList *docs = listDocuments_App(NULL); | ||
1000 | iForEach(ObjectList, i, docs) { | ||
1001 | memorySize += memorySize_History(history_DocumentWidget(i.object)); | ||
1002 | } | ||
1003 | init_ObjectListIterator(&i, docs); | ||
1004 | iBool wasPruned = iFalse; | ||
1005 | while (memorySize > limit) { | ||
1006 | iDocumentWidget *doc = i.object; | ||
1007 | const size_t pruned = pruneLeastImportantMemory_History(history_DocumentWidget(doc)); | ||
1008 | if (pruned) { | ||
1009 | memorySize -= pruned; | ||
1010 | wasPruned = iTrue; | ||
1011 | } | ||
1012 | next_ObjectListIterator(&i); | ||
1013 | if (!i.value) { | ||
1014 | if (!wasPruned) break; | ||
1015 | wasPruned = iFalse; | ||
1016 | init_ObjectListIterator(&i, docs); | ||
1017 | } | ||
1018 | } | ||
1019 | iRelease(docs); | ||
1020 | } | ||
1021 | |||
994 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { | 1022 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { |
995 | if (!isEmpty_Periodic(&d->periodic)) { | 1023 | if (!isEmpty_Periodic(&d->periodic)) { |
996 | return iFalse; | 1024 | return iFalse; |
@@ -1577,7 +1605,9 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | |||
1577 | postCommandf_App("searchurl address:%s", | 1605 | postCommandf_App("searchurl address:%s", |
1578 | cstrText_InputWidget(findChild_Widget(d, "prefs.searchurl"))); | 1606 | cstrText_InputWidget(findChild_Widget(d, "prefs.searchurl"))); |
1579 | postCommandf_App("cachesize.set arg:%d", | 1607 | postCommandf_App("cachesize.set arg:%d", |
1580 | toInt_String(text_InputWidget(findChild_Widget(d, "prefs.cachesize")))); | 1608 | toInt_String(text_InputWidget(findChild_Widget(d, "prefs.cachesize")))); |
1609 | postCommandf_App("memorysize.set arg:%d", | ||
1610 | toInt_String(text_InputWidget(findChild_Widget(d, "prefs.memorysize")))); | ||
1581 | postCommandf_App("ca.file path:%s", | 1611 | postCommandf_App("ca.file path:%s", |
1582 | cstrText_InputWidget(findChild_Widget(d, "prefs.ca.file"))); | 1612 | cstrText_InputWidget(findChild_Widget(d, "prefs.ca.file"))); |
1583 | postCommandf_App("ca.path path:%s", | 1613 | postCommandf_App("ca.path path:%s", |
@@ -2139,6 +2169,13 @@ iBool handleCommand_App(const char *cmd) { | |||
2139 | } | 2169 | } |
2140 | return iTrue; | 2170 | return iTrue; |
2141 | } | 2171 | } |
2172 | else if (equal_Command(cmd, "memorysize.set")) { | ||
2173 | d->prefs.maxMemorySize = arg_Command(cmd); | ||
2174 | if (d->prefs.maxMemorySize <= 0) { | ||
2175 | d->prefs.maxMemorySize = 0; | ||
2176 | } | ||
2177 | return iTrue; | ||
2178 | } | ||
2142 | else if (equal_Command(cmd, "searchurl")) { | 2179 | else if (equal_Command(cmd, "searchurl")) { |
2143 | iString *url = &d->prefs.searchUrl; | 2180 | iString *url = &d->prefs.searchUrl; |
2144 | setCStr_String(url, suffixPtr_Command(cmd, "address")); | 2181 | setCStr_String(url, suffixPtr_Command(cmd, "address")); |
@@ -2417,6 +2454,8 @@ iBool handleCommand_App(const char *cmd) { | |||
2417 | iTrue); | 2454 | iTrue); |
2418 | setText_InputWidget(findChild_Widget(dlg, "prefs.cachesize"), | 2455 | setText_InputWidget(findChild_Widget(dlg, "prefs.cachesize"), |
2419 | collectNewFormat_String("%d", d->prefs.maxCacheSize)); | 2456 | collectNewFormat_String("%d", d->prefs.maxCacheSize)); |
2457 | setText_InputWidget(findChild_Widget(dlg, "prefs.memorysize"), | ||
2458 | collectNewFormat_String("%d", d->prefs.maxMemorySize)); | ||
2420 | setToggle_Widget(findChild_Widget(dlg, "prefs.decodeurls"), d->prefs.decodeUserVisibleURLs); | 2459 | setToggle_Widget(findChild_Widget(dlg, "prefs.decodeurls"), d->prefs.decodeUserVisibleURLs); |
2421 | setText_InputWidget(findChild_Widget(dlg, "prefs.searchurl"), &d->prefs.searchUrl); | 2460 | setText_InputWidget(findChild_Widget(dlg, "prefs.searchurl"), &d->prefs.searchUrl); |
2422 | setText_InputWidget(findChild_Widget(dlg, "prefs.ca.file"), &d->prefs.caFile); | 2461 | setText_InputWidget(findChild_Widget(dlg, "prefs.ca.file"), &d->prefs.caFile); |