diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 90 |
1 files changed, 71 insertions, 19 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index fbfb94f3..7bf0beca 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -67,14 +67,49 @@ iDeclareType(PersistentDocumentState) | |||
67 | iDeclareTypeConstruction(PersistentDocumentState) | 67 | iDeclareTypeConstruction(PersistentDocumentState) |
68 | iDeclareTypeSerialization(PersistentDocumentState) | 68 | iDeclareTypeSerialization(PersistentDocumentState) |
69 | 69 | ||
70 | enum iReloadInterval { | ||
71 | never_RelodPeriod, | ||
72 | minute_ReloadInterval, | ||
73 | fiveMinutes_ReloadInterval, | ||
74 | fifteenMinutes_ReloadInterval, | ||
75 | hour_ReloadInterval, | ||
76 | fourHours_ReloadInterval, | ||
77 | twicePerDay_ReloadInterval, | ||
78 | day_ReloadInterval, | ||
79 | max_ReloadInterval | ||
80 | }; | ||
81 | |||
82 | static int seconds_ReloadInterval_(enum iReloadInterval d) { | ||
83 | static const int times[] = { 0, 1, 5, 15, 60, 4 * 60, 12 * 60, 24 * 60 }; | ||
84 | if (d < 0 || d >= max_ReloadInterval) return 0; | ||
85 | return times[d]; | ||
86 | } | ||
87 | |||
88 | static const char *label_ReloadInterval_(enum iReloadInterval d) { | ||
89 | static const char *labels[] = { | ||
90 | "Never", | ||
91 | "1 minute", | ||
92 | "5 minutes", | ||
93 | "15 minutes", | ||
94 | "1 hour", | ||
95 | "4 hours", | ||
96 | "12 hours", | ||
97 | "Once per day" | ||
98 | }; | ||
99 | if (d < 0 || d >= max_ReloadInterval) return 0; | ||
100 | return labels[d]; | ||
101 | } | ||
102 | |||
70 | struct Impl_PersistentDocumentState { | 103 | struct Impl_PersistentDocumentState { |
71 | iHistory *history; | 104 | iHistory *history; |
72 | iString * url; | 105 | iString * url; |
106 | enum iReloadInterval reloadInterval; | ||
73 | }; | 107 | }; |
74 | 108 | ||
75 | void init_PersistentDocumentState(iPersistentDocumentState *d) { | 109 | void init_PersistentDocumentState(iPersistentDocumentState *d) { |
76 | d->history = new_History(); | 110 | d->history = new_History(); |
77 | d->url = new_String(); | 111 | d->url = new_String(); |
112 | d->reloadInterval = 0; | ||
78 | } | 113 | } |
79 | 114 | ||
80 | void deinit_PersistentDocumentState(iPersistentDocumentState *d) { | 115 | void deinit_PersistentDocumentState(iPersistentDocumentState *d) { |
@@ -84,7 +119,7 @@ void deinit_PersistentDocumentState(iPersistentDocumentState *d) { | |||
84 | 119 | ||
85 | void serialize_PersistentDocumentState(const iPersistentDocumentState *d, iStream *outs) { | 120 | void serialize_PersistentDocumentState(const iPersistentDocumentState *d, iStream *outs) { |
86 | serialize_String(d->url, outs); | 121 | serialize_String(d->url, outs); |
87 | write16_Stream(outs, 0 /*d->zoomPercent*/); | 122 | writeU16_Stream(outs, d->reloadInterval & 7); |
88 | serialize_History(d->history, outs); | 123 | serialize_History(d->history, outs); |
89 | } | 124 | } |
90 | 125 | ||
@@ -94,7 +129,8 @@ void deserialize_PersistentDocumentState(iPersistentDocumentState *d, iStream *i | |||
94 | /* Oopsie, this should not have been written; invalid URL. */ | 129 | /* Oopsie, this should not have been written; invalid URL. */ |
95 | clear_String(d->url); | 130 | clear_String(d->url); |
96 | } | 131 | } |
97 | /*d->zoomPercent =*/ read16_Stream(ins); | 132 | const uint16_t params = readU16_Stream(ins); |
133 | d->reloadInterval = params & 7; | ||
98 | deserialize_History(d->history, ins); | 134 | deserialize_History(d->history, ins); |
99 | } | 135 | } |
100 | 136 | ||
@@ -1868,7 +1904,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1868 | } | 1904 | } |
1869 | return iTrue; | 1905 | return iTrue; |
1870 | } | 1906 | } |
1871 | else if (equal_Command(cmd, "document.reload") && document_App() == d) { | 1907 | else if (equal_Command(cmd, "document.reload") && document_Command(cmd) == d) { |
1872 | d->initNormScrollY = normScrollPos_DocumentWidget_(d); | 1908 | d->initNormScrollY = normScrollPos_DocumentWidget_(d); |
1873 | fetch_DocumentWidget_(d); | 1909 | fetch_DocumentWidget_(d); |
1874 | return iTrue; | 1910 | return iTrue; |
@@ -2083,13 +2119,6 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2083 | size_PtrArray(links), | 2119 | size_PtrArray(links), |
2084 | plural), 0, 0, "bookmark.links" } }, | 2120 | plural), 0, 0, "bookmark.links" } }, |
2085 | 2); | 2121 | 2); |
2086 | |||
2087 | // (const char *[]){ "Cancel", | ||
2088 | // format_CStr(uiTextAction_ColorEscape "Add %d | ||
2089 | // Bookmark%s", | ||
2090 | // size_PtrArray(links), plural) }, | ||
2091 | // (const char *[]){ "cancel", "bookmark.links" }, | ||
2092 | // 2); | ||
2093 | } | 2122 | } |
2094 | else { | 2123 | else { |
2095 | iConstForEach(PtrArray, j, links) { | 2124 | iConstForEach(PtrArray, j, links) { |
@@ -2112,16 +2141,38 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2112 | else if (equalWidget_Command(cmd, w, "menu.closed")) { | 2141 | else if (equalWidget_Command(cmd, w, "menu.closed")) { |
2113 | updateHover_DocumentWidget_(d, mouseCoord_Window(get_Window())); | 2142 | updateHover_DocumentWidget_(d, mouseCoord_Window(get_Window())); |
2114 | } | 2143 | } |
2144 | else if (equal_Command(cmd, "document.autoreload")) { | ||
2145 | if (d->mod.reloadInterval) { | ||
2146 | if (isValid_Time(&d->sourceTime) && | ||
2147 | elapsedSeconds_Time(&d->sourceTime) >= | ||
2148 | seconds_ReloadInterval_(d->mod.reloadInterval)) { | ||
2149 | postCommand_Widget(w, "document.reload"); | ||
2150 | } | ||
2151 | } | ||
2152 | } | ||
2153 | else if (equal_Command(cmd, "document.autoreload.menu") && document_App() == d) { | ||
2154 | iWidget *dlg = makeQuestion_Widget(uiTextAction_ColorEscape "AUTO-RELOAD", | ||
2155 | "Select the auto-reload interval for this tab.", | ||
2156 | (iMenuItem[]){ { "Cancel", 0, 0, NULL } }, | ||
2157 | 1); | ||
2158 | for (int i = 0; i < max_ReloadInterval; ++i) { | ||
2159 | insertChildAfterFlags_Widget( | ||
2160 | dlg, | ||
2161 | iClob(new_LabelWidget(label_ReloadInterval_(i), | ||
2162 | format_CStr("document.autoreload.set arg:%d", i))), | ||
2163 | i + 1, | ||
2164 | resizeToParentWidth_WidgetFlag | | ||
2165 | ((int) d->mod.reloadInterval == i ? selected_WidgetFlag : 0)); | ||
2166 | } | ||
2167 | arrange_Widget(dlg); | ||
2168 | return iTrue; | ||
2169 | } | ||
2170 | else if (equal_Command(cmd, "document.autoreload.set") && document_App() == d) { | ||
2171 | d->mod.reloadInterval = arg_Command(cmd); | ||
2172 | } | ||
2115 | return iFalse; | 2173 | return iFalse; |
2116 | } | 2174 | } |
2117 | 2175 | ||
2118 | #if 0 | ||
2119 | static int outlineHeight_DocumentWidget_(const iDocumentWidget *d) { | ||
2120 | if (isEmpty_Array(&d->outline)) return 0; | ||
2121 | return bottom_Rect(((const iOutlineItem *) constBack_Array(&d->outline))->rect); | ||
2122 | } | ||
2123 | #endif | ||
2124 | |||
2125 | static iRect playerRect_DocumentWidget_(const iDocumentWidget *d, const iGmRun *run) { | 2176 | static iRect playerRect_DocumentWidget_(const iDocumentWidget *d, const iGmRun *run) { |
2126 | const iRect docBounds = documentBounds_DocumentWidget_(d); | 2177 | const iRect docBounds = documentBounds_DocumentWidget_(d); |
2127 | return moved_Rect(run->bounds, addY_I2(topLeft_Rect(docBounds), -value_Anim(&d->scrollY))); | 2178 | return moved_Rect(run->bounds, addY_I2(topLeft_Rect(docBounds), -value_Anim(&d->scrollY))); |
@@ -2538,6 +2589,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2538 | { "Go to Root", navigateRoot_KeyShortcut, "navigate.root" }, | 2589 | { "Go to Root", navigateRoot_KeyShortcut, "navigate.root" }, |
2539 | { "---", 0, 0, NULL }, | 2590 | { "---", 0, 0, NULL }, |
2540 | { "Reload Page", reload_KeyShortcut, "navigate.reload" }, | 2591 | { "Reload Page", reload_KeyShortcut, "navigate.reload" }, |
2592 | { "Set Auto-Reload...", 0, 0, "document.autoreload.menu" }, | ||
2541 | { "---", 0, 0, NULL }, | 2593 | { "---", 0, 0, NULL }, |
2542 | { "Bookmark Page...", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, | 2594 | { "Bookmark Page...", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, |
2543 | { "Subscribe to Page...", subscribeToPage_KeyModifier, "feeds.subscribe" }, | 2595 | { "Subscribe to Page...", subscribeToPage_KeyModifier, "feeds.subscribe" }, |