summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c70
1 files changed, 15 insertions, 55 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 5e30cc2a..cef1275b 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -55,81 +55,40 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
55#include <ctype.h> 55#include <ctype.h>
56#include <errno.h> 56#include <errno.h>
57 57
58iDeclareClass(MediaRequest)
59
60struct Impl_MediaRequest {
61 iObject object;
62 iDocumentWidget *doc;
63 iGmLinkId linkId;
64 iGmRequest * req;
65};
66
67static void updated_MediaRequest_(iAnyObject *obj) {
68 iMediaRequest *d = obj;
69 postCommandf_App("media.updated link:%u request:%p", d->linkId, d);
70}
71
72static void finished_MediaRequest_(iAnyObject *obj) {
73 iMediaRequest *d = obj;
74 postCommandf_App("media.finished link:%u request:%p", d->linkId, d);
75}
76
77void init_MediaRequest(iMediaRequest *d, iDocumentWidget *doc, iGmLinkId linkId, const iString *url) {
78 d->doc = doc;
79 d->linkId = linkId;
80 d->req = new_GmRequest(certs_App());
81 setUrl_GmRequest(d->req, url);
82 iConnect(GmRequest, d->req, updated, d, updated_MediaRequest_);
83 iConnect(GmRequest, d->req, finished, d, finished_MediaRequest_);
84 submit_GmRequest(d->req);
85}
86
87void deinit_MediaRequest(iMediaRequest *d) {
88 iDisconnect(GmRequest, d->req, updated, d, updated_MediaRequest_);
89 iDisconnect(GmRequest, d->req, finished, d, finished_MediaRequest_);
90 iRelease(d->req);
91}
92
93iDefineObjectConstructionArgs(MediaRequest,
94 (iDocumentWidget *doc, iGmLinkId linkId, const iString *url),
95 doc, linkId, url)
96iDefineClass(MediaRequest)
97
98/*----------------------------------------------------------------------------------------------*/ 58/*----------------------------------------------------------------------------------------------*/
99 59
100iDeclareType(Model) 60iDeclareType(PersistentDocumentState)
101iDeclareTypeConstruction(Model) 61iDeclareTypeConstruction(PersistentDocumentState)
102iDeclareTypeSerialization(Model) 62iDeclareTypeSerialization(PersistentDocumentState)
103 63
104struct Impl_Model { 64struct Impl_PersistentDocumentState {
105 /* state that persists across sessions */
106 iHistory *history; 65 iHistory *history;
107 iString * url; 66 iString * url;
108}; 67};
109 68
110void init_Model(iModel *d) { 69void init_PersistentDocumentState(iPersistentDocumentState *d) {
111 d->history = new_History(); 70 d->history = new_History();
112 d->url = new_String(); 71 d->url = new_String();
113} 72}
114 73
115void deinit_Model(iModel *d) { 74void deinit_PersistentDocumentState(iPersistentDocumentState *d) {
116 delete_String(d->url); 75 delete_String(d->url);
117 delete_History(d->history); 76 delete_History(d->history);
118} 77}
119 78
120void serialize_Model(const iModel *d, iStream *outs) { 79void serialize_PersistentDocumentState(const iPersistentDocumentState *d, iStream *outs) {
121 serialize_String(d->url, outs); 80 serialize_String(d->url, outs);
122 write16_Stream(outs, 0 /*d->zoomPercent*/); 81 write16_Stream(outs, 0 /*d->zoomPercent*/);
123 serialize_History(d->history, outs); 82 serialize_History(d->history, outs);
124} 83}
125 84
126void deserialize_Model(iModel *d, iStream *ins) { 85void deserialize_PersistentDocumentState(iPersistentDocumentState *d, iStream *ins) {
127 deserialize_String(d->url, ins); 86 deserialize_String(d->url, ins);
128 /*d->zoomPercent =*/ read16_Stream(ins); 87 /*d->zoomPercent =*/ read16_Stream(ins);
129 deserialize_History(d->history, ins); 88 deserialize_History(d->history, ins);
130} 89}
131 90
132iDefineTypeConstruction(Model) 91iDefineTypeConstruction(PersistentDocumentState)
133 92
134/*----------------------------------------------------------------------------------------------*/ 93/*----------------------------------------------------------------------------------------------*/
135 94
@@ -167,7 +126,7 @@ enum iDocumentWidgetFlag {
167struct Impl_DocumentWidget { 126struct Impl_DocumentWidget {
168 iWidget widget; 127 iWidget widget;
169 enum iRequestState state; 128 enum iRequestState state;
170 iModel mod; 129 iPersistentDocumentState mod;
171 int flags; 130 int flags;
172 iString * titleUser; 131 iString * titleUser;
173 iGmRequest * request; 132 iGmRequest * request;
@@ -215,7 +174,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
215 init_Widget(w); 174 init_Widget(w);
216 setId_Widget(w, "document000"); 175 setId_Widget(w, "document000");
217 setFlags_Widget(w, hover_WidgetFlag, iTrue); 176 setFlags_Widget(w, hover_WidgetFlag, iTrue);
218 init_Model(&d->mod); 177 init_PersistentDocumentState(&d->mod);
219 d->flags = 0; 178 d->flags = 0;
220 iZap(d->certExpiry); 179 iZap(d->certExpiry);
221 d->certFlags = 0; 180 d->certFlags = 0;
@@ -285,7 +244,7 @@ void deinit_DocumentWidget(iDocumentWidget *d) {
285 deinit_PtrArray(&d->visibleLinks); 244 deinit_PtrArray(&d->visibleLinks);
286 delete_String(d->certSubject); 245 delete_String(d->certSubject);
287 delete_String(d->titleUser); 246 delete_String(d->titleUser);
288 deinit_Model(&d->mod); 247 deinit_PersistentDocumentState(&d->mod);
289} 248}
290 249
291static void requestUpdated_DocumentWidget_(iAnyObject *obj) { 250static void requestUpdated_DocumentWidget_(iAnyObject *obj) {
@@ -1950,6 +1909,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1950 if (processPlayerEvents_DocumentWidget_(d, ev)) { 1909 if (processPlayerEvents_DocumentWidget_(d, ev)) {
1951 return iTrue; 1910 return iTrue;
1952 } 1911 }
1912 /* The left mouse button. */
1953 switch (processEvent_Click(&d->click, ev)) { 1913 switch (processEvent_Click(&d->click, ev)) {
1954 case started_ClickResult: 1914 case started_ClickResult:
1955 iChangeFlags(d->flags, selecting_DocumentWidgetFlag, iFalse); 1915 iChangeFlags(d->flags, selecting_DocumentWidgetFlag, iFalse);
@@ -2652,11 +2612,11 @@ const iString *bookmarkTitle_DocumentWidget(const iDocumentWidget *d) {
2652} 2612}
2653 2613
2654void serializeState_DocumentWidget(const iDocumentWidget *d, iStream *outs) { 2614void serializeState_DocumentWidget(const iDocumentWidget *d, iStream *outs) {
2655 serialize_Model(&d->mod, outs); 2615 serialize_PersistentDocumentState(&d->mod, outs);
2656} 2616}
2657 2617
2658void deserializeState_DocumentWidget(iDocumentWidget *d, iStream *ins) { 2618void deserializeState_DocumentWidget(iDocumentWidget *d, iStream *ins) {
2659 deserialize_Model(&d->mod, ins); 2619 deserialize_PersistentDocumentState(&d->mod, ins);
2660 parseUser_DocumentWidget_(d); 2620 parseUser_DocumentWidget_(d);
2661 updateFromHistory_DocumentWidget_(d); 2621 updateFromHistory_DocumentWidget_(d);
2662} 2622}