diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -1,18 +1,20 @@ | |||
1 | #include "app.h" | 1 | #include "app.h" |
2 | #include "bookmarks.h" | ||
2 | #include "embedded.h" | 3 | #include "embedded.h" |
3 | #include "gmcerts.h" | 4 | #include "gmcerts.h" |
5 | #include "gmdocument.h" | ||
4 | #include "gmutil.h" | 6 | #include "gmutil.h" |
5 | #include "history.h" | 7 | #include "history.h" |
6 | #include "visited.h" | 8 | #include "ui/color.h" |
7 | #include "ui/command.h" | 9 | #include "ui/command.h" |
8 | #include "ui/window.h" | 10 | #include "ui/documentwidget.h" |
9 | #include "ui/inputwidget.h" | 11 | #include "ui/inputwidget.h" |
10 | #include "ui/labelwidget.h" | 12 | #include "ui/labelwidget.h" |
11 | #include "ui/sidebarwidget.h" | 13 | #include "ui/sidebarwidget.h" |
12 | #include "ui/documentwidget.h" | ||
13 | #include "ui/util.h" | ||
14 | #include "ui/text.h" | 14 | #include "ui/text.h" |
15 | #include "ui/color.h" | 15 | #include "ui/util.h" |
16 | #include "ui/window.h" | ||
17 | #include "visited.h" | ||
16 | 18 | ||
17 | #include <the_Foundation/commandline.h> | 19 | #include <the_Foundation/commandline.h> |
18 | #include <the_Foundation/file.h> | 20 | #include <the_Foundation/file.h> |
@@ -60,6 +62,7 @@ struct Impl_App { | |||
60 | iBool pendingRefresh; | 62 | iBool pendingRefresh; |
61 | iGmCerts * certs; | 63 | iGmCerts * certs; |
62 | iVisited * visited; | 64 | iVisited * visited; |
65 | iBookmarks * bookmarks; | ||
63 | int zoomPercent; | 66 | int zoomPercent; |
64 | int tabEnum; | 67 | int tabEnum; |
65 | /* Preferences: */ | 68 | /* Preferences: */ |
@@ -157,6 +160,7 @@ static const char *magicState_App_ = "lgL1"; | |||
157 | static const char *magicTabDocument_App_ = "tabd"; | 160 | static const char *magicTabDocument_App_ = "tabd"; |
158 | 161 | ||
159 | static iBool loadState_App_(iApp *d) { | 162 | static iBool loadState_App_(iApp *d) { |
163 | iUnused(d); | ||
160 | iFile *f = iClob(newCStr_File(concatPath_CStr(dataDir_App_, stateFileName_App_))); | 164 | iFile *f = iClob(newCStr_File(concatPath_CStr(dataDir_App_, stateFileName_App_))); |
161 | if (open_File(f, readOnly_FileMode)) { | 165 | if (open_File(f, readOnly_FileMode)) { |
162 | char magic[4]; | 166 | char magic[4]; |
@@ -225,9 +229,11 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
225 | d->zoomPercent = 100; | 229 | d->zoomPercent = 100; |
226 | d->certs = new_GmCerts(dataDir_App_); | 230 | d->certs = new_GmCerts(dataDir_App_); |
227 | d->visited = new_Visited(); | 231 | d->visited = new_Visited(); |
232 | d->bookmarks = new_Bookmarks(); | ||
228 | d->tabEnum = 0; | 233 | d->tabEnum = 0; |
229 | loadPrefs_App_(d); | 234 | loadPrefs_App_(d); |
230 | load_Visited(d->visited, dataDir_App_); | 235 | load_Visited(d->visited, dataDir_App_); |
236 | load_Bookmarks(d->bookmarks, dataDir_App_); | ||
231 | #if defined (iHaveLoadEmbed) | 237 | #if defined (iHaveLoadEmbed) |
232 | /* Load the resources from a file. */ { | 238 | /* Load the resources from a file. */ { |
233 | if (!load_Embed(concatPath_CStr(cstr_String(execPath_App()), "../resources.bin"))) { | 239 | if (!load_Embed(concatPath_CStr(cstr_String(execPath_App()), "../resources.bin"))) { |
@@ -248,6 +254,8 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
248 | static void deinit_App(iApp *d) { | 254 | static void deinit_App(iApp *d) { |
249 | saveState_App_(d); | 255 | saveState_App_(d); |
250 | savePrefs_App_(d); | 256 | savePrefs_App_(d); |
257 | save_Bookmarks(d->bookmarks, dataDir_App_); | ||
258 | delete_Bookmarks(d->bookmarks); | ||
251 | save_Visited(d->visited, dataDir_App_); | 259 | save_Visited(d->visited, dataDir_App_); |
252 | delete_Visited(d->visited); | 260 | delete_Visited(d->visited); |
253 | delete_GmCerts(d->certs); | 261 | delete_GmCerts(d->certs); |
@@ -407,6 +415,10 @@ iVisited *visited_App(void) { | |||
407 | return app_.visited; | 415 | return app_.visited; |
408 | } | 416 | } |
409 | 417 | ||
418 | iBookmarks *bookmarks_App(void) { | ||
419 | return app_.bookmarks; | ||
420 | } | ||
421 | |||
410 | static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | 422 | static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { |
411 | if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { | 423 | if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { |
412 | setUiScale_Window(get_Window(), | 424 | setUiScale_Window(get_Window(), |
@@ -504,7 +516,7 @@ iBool handleCommand_App(const char *cmd) { | |||
504 | } | 516 | } |
505 | else if (equal_Command(cmd, "tabs.new")) { | 517 | else if (equal_Command(cmd, "tabs.new")) { |
506 | const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0; | 518 | const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0; |
507 | iDocumentWidget *newDoc = newTab_App(isDuplicate ? document_App() : NULL); | 519 | newTab_App(isDuplicate ? document_App() : NULL); |
508 | if (!isDuplicate) { | 520 | if (!isDuplicate) { |
509 | postCommand_App("navigate.home"); | 521 | postCommand_App("navigate.home"); |
510 | } | 522 | } |
@@ -585,6 +597,15 @@ iBool handleCommand_App(const char *cmd) { | |||
585 | refresh_App(); | 597 | refresh_App(); |
586 | return iTrue; | 598 | return iTrue; |
587 | } | 599 | } |
600 | else if (equal_Command(cmd, "bookmark.add")) { | ||
601 | iDocumentWidget *doc = document_App(); | ||
602 | add_Bookmarks(d->bookmarks, url_DocumentWidget(doc), | ||
603 | bookmarkTitle_DocumentWidget(doc), | ||
604 | collectNew_String(), | ||
605 | siteIcon_GmDocument(document_DocumentWidget(doc))); | ||
606 | postCommand_App("bookmarks.changed"); | ||
607 | return iTrue; | ||
608 | } | ||
588 | else { | 609 | else { |
589 | return iFalse; | 610 | return iFalse; |
590 | } | 611 | } |