summaryrefslogtreecommitdiff
path: root/src/app.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-08 08:06:22 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-08 08:06:22 +0300
commitd6875fba63cc674d2d9cac64a66c3b4c9f3eaba1 (patch)
treea12111a19b594fc17792a7a851d1526597470121 /src/app.c
parent9abe27c63e088bf1e139d108cbc29ac39222d74c (diff)
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.
Diffstat (limited to 'src/app.c')
-rw-r--r--src/app.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/app.c b/src/app.c
index 0d15bce1..5b31faa7 100644
--- a/src/app.c
+++ b/src/app.c
@@ -3,6 +3,7 @@
3#include "gmcerts.h" 3#include "gmcerts.h"
4#include "gmutil.h" 4#include "gmutil.h"
5#include "history.h" 5#include "history.h"
6#include "visited.h"
6#include "ui/command.h" 7#include "ui/command.h"
7#include "ui/window.h" 8#include "ui/window.h"
8#include "ui/inputwidget.h" 9#include "ui/inputwidget.h"
@@ -55,7 +56,8 @@ struct Impl_App {
55 iSortedArray tickers; 56 iSortedArray tickers;
56 iBool pendingRefresh; 57 iBool pendingRefresh;
57 iGmCerts * certs; 58 iGmCerts * certs;
58 iHistory * history; 59// iHistory * history;
60 iVisited * visited;
59 /* Preferences: */ 61 /* Preferences: */
60 iBool retainWindowSize; 62 iBool retainWindowSize;
61 float uiScale; 63 float uiScale;
@@ -149,9 +151,9 @@ static void init_App_(iApp *d, int argc, char **argv) {
149 d->retainWindowSize = iTrue; 151 d->retainWindowSize = iTrue;
150 d->pendingRefresh = iFalse; 152 d->pendingRefresh = iFalse;
151 d->certs = new_GmCerts(dataDir_App_); 153 d->certs = new_GmCerts(dataDir_App_);
152 d->history = new_History(); 154 d->visited = new_Visited();
153 loadPrefs_App_(d); 155 loadPrefs_App_(d);
154 load_History(d->history, dataDir_App_); 156 load_Visited(d->visited, dataDir_App_);
155#if defined (iHaveLoadEmbed) 157#if defined (iHaveLoadEmbed)
156 /* Load the resources from a file. */ { 158 /* Load the resources from a file. */ {
157 if (!load_Embed(concatPath_CStr(cstr_String(execPath_App()), "../resources.bin"))) { 159 if (!load_Embed(concatPath_CStr(cstr_String(execPath_App()), "../resources.bin"))) {
@@ -170,8 +172,8 @@ static void init_App_(iApp *d, int argc, char **argv) {
170 172
171static void deinit_App(iApp *d) { 173static void deinit_App(iApp *d) {
172 savePrefs_App_(d); 174 savePrefs_App_(d);
173 save_History(d->history, dataDir_App_); 175 save_Visited(d->visited, dataDir_App_);
174 delete_History(d->history); 176 delete_Visited(d->visited);
175 delete_GmCerts(d->certs); 177 delete_GmCerts(d->certs);
176 deinit_SortedArray(&d->tickers); 178 deinit_SortedArray(&d->tickers);
177 delete_Window(d->window); 179 delete_Window(d->window);
@@ -313,8 +315,8 @@ iGmCerts *certs_App(void) {
313 return app_.certs; 315 return app_.certs;
314} 316}
315 317
316iHistory *history_App(void) { 318iVisited *visited_App(void) {
317 return app_.history; 319 return app_.visited;
318} 320}
319 321
320static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { 322static iBool handlePrefsCommands_(iWidget *d, const char *cmd) {
@@ -332,40 +334,43 @@ iDocumentWidget *document_App(void) {
332} 334}
333 335
334iDocumentWidget *document_Command(const char *cmd) { 336iDocumentWidget *document_Command(const char *cmd) {
337 /* Explicitly referenced. */
335 iAnyObject *obj = pointerLabel_Command(cmd, "doc"); 338 iAnyObject *obj = pointerLabel_Command(cmd, "doc");
336 if (obj) { 339 if (obj) {
337 return obj; 340 return obj;
338 } 341 }
342 /* Implicit via source widget. */
339 obj = pointer_Command(cmd); 343 obj = pointer_Command(cmd);
340 if (obj && isInstance_Object(obj, &Class_DocumentWidget)) { 344 if (obj && isInstance_Object(obj, &Class_DocumentWidget)) {
341 return obj; 345 return obj;
342 } 346 }
347 /* Currently visible document. */
343 return document_App(); 348 return document_App();
344} 349}
345 350
346iBool handleCommand_App(const char *cmd) { 351iBool handleCommand_App(const char *cmd) {
347 iApp *d = &app_; 352 iApp *d = &app_;
348 iWidget *root = d->window->root;
349 if (equal_Command(cmd, "open")) { 353 if (equal_Command(cmd, "open")) {
350 const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url"))); 354 const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url")));
351 iUrl parts; 355 iUrl parts;
352 init_Url(&parts, url); 356 init_Url(&parts, url);
353 if (equalCase_Rangecc(&parts.protocol, "http") || 357 if (equalCase_Rangecc(&parts.protocol, "http") ||
354 equalCase_Rangecc(&parts.protocol, "https")) { 358 equalCase_Rangecc(&parts.protocol, "https")) {
355 visitUrl_History(d->history, url);
356 openInDefaultBrowser_App(url); 359 openInDefaultBrowser_App(url);
357 return iTrue; 360 return iTrue;
358 } 361 }
362 iDocumentWidget *doc = document_Command(cmd);
363 iHistory *history = history_DocumentWidget(doc);
359 const iBool isHistory = argLabel_Command(cmd, "history") != 0; 364 const iBool isHistory = argLabel_Command(cmd, "history") != 0;
360 if (!isHistory) { 365 if (!isHistory) {
361 if (argLabel_Command(cmd, "redirect")) { 366 if (argLabel_Command(cmd, "redirect")) {
362 replace_History(d->history, url); 367 replace_History(history, url);
363 } 368 }
364 else { 369 else {
365 addUrl_History(d->history, url); 370 add_History(history, url);
366 } 371 }
367 } 372 }
368 iDocumentWidget *doc = findChild_Widget(root, "document"); 373 visitUrl_Visited(d->visited, url);
369 setInitialScroll_DocumentWidget(doc, argLabel_Command(cmd, "scroll") * gap_UI); 374 setInitialScroll_DocumentWidget(doc, argLabel_Command(cmd, "scroll") * gap_UI);
370 setUrlFromCache_DocumentWidget(doc, url, isHistory); 375 setUrlFromCache_DocumentWidget(doc, url, isHistory);
371 } 376 }
@@ -403,18 +408,6 @@ iBool handleCommand_App(const char *cmd) {
403 const iInt2 pos = coord_Command(cmd); 408 const iInt2 pos = coord_Command(cmd);
404 SDL_SetWindowPosition(d->window->win, pos.x, pos.y); 409 SDL_SetWindowPosition(d->window->win, pos.x, pos.y);
405 } 410 }
406 else if (equal_Command(cmd, "document.changed")) {
407 /* TODO: Update current history item with this actual/redirected URL. */
408 return iFalse;
409 }
410 else if (equal_Command(cmd, "navigate.back")) {
411 goBack_History(d->history);
412 return iTrue;
413 }
414 else if (equal_Command(cmd, "navigate.forward")) {
415 goForward_History(d->history);
416 return iTrue;
417 }
418 else if (equal_Command(cmd, "navigate.home")) { 411 else if (equal_Command(cmd, "navigate.home")) {
419 iString *homePath = newCStr_String(dataDir_App_); 412 iString *homePath = newCStr_String(dataDir_App_);
420 clean_Path(homePath); 413 clean_Path(homePath);