diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/media.c | 34 | ||||
-rw-r--r-- | src/media.h | 18 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 70 |
3 files changed, 67 insertions, 55 deletions
diff --git a/src/media.c b/src/media.c index dcda0664..cd3dfb82 100644 --- a/src/media.c +++ b/src/media.c | |||
@@ -22,6 +22,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
22 | 22 | ||
23 | #include "media.h" | 23 | #include "media.h" |
24 | #include "gmdocument.h" | 24 | #include "gmdocument.h" |
25 | #include "gmrequest.h" | ||
25 | #include "ui/window.h" | 26 | #include "ui/window.h" |
26 | #include "audio/player.h" | 27 | #include "audio/player.h" |
27 | #include "app.h" | 28 | #include "app.h" |
@@ -295,3 +296,36 @@ iPlayer *audioPlayer_Media(const iMedia *d, iMediaId audioId) { | |||
295 | } | 296 | } |
296 | return NULL; | 297 | return NULL; |
297 | } | 298 | } |
299 | |||
300 | /*----------------------------------------------------------------------------------------------*/ | ||
301 | |||
302 | static void updated_MediaRequest_(iAnyObject *obj) { | ||
303 | iMediaRequest *d = obj; | ||
304 | postCommandf_App("media.updated link:%u request:%p", d->linkId, d); | ||
305 | } | ||
306 | |||
307 | static void finished_MediaRequest_(iAnyObject *obj) { | ||
308 | iMediaRequest *d = obj; | ||
309 | postCommandf_App("media.finished link:%u request:%p", d->linkId, d); | ||
310 | } | ||
311 | |||
312 | void init_MediaRequest(iMediaRequest *d, iDocumentWidget *doc, unsigned int linkId, const iString *url) { | ||
313 | d->doc = doc; | ||
314 | d->linkId = linkId; | ||
315 | d->req = new_GmRequest(certs_App()); | ||
316 | setUrl_GmRequest(d->req, url); | ||
317 | iConnect(GmRequest, d->req, updated, d, updated_MediaRequest_); | ||
318 | iConnect(GmRequest, d->req, finished, d, finished_MediaRequest_); | ||
319 | submit_GmRequest(d->req); | ||
320 | } | ||
321 | |||
322 | void deinit_MediaRequest(iMediaRequest *d) { | ||
323 | iDisconnect(GmRequest, d->req, updated, d, updated_MediaRequest_); | ||
324 | iDisconnect(GmRequest, d->req, finished, d, finished_MediaRequest_); | ||
325 | iRelease(d->req); | ||
326 | } | ||
327 | |||
328 | iDefineObjectConstructionArgs(MediaRequest, | ||
329 | (iDocumentWidget *doc, unsigned int linkId, const iString *url), | ||
330 | doc, linkId, url) | ||
331 | iDefineClass(MediaRequest) | ||
diff --git a/src/media.h b/src/media.h index 9db6659d..12334936 100644 --- a/src/media.h +++ b/src/media.h | |||
@@ -64,3 +64,21 @@ size_t numAudio_Media (const iMedia *); | |||
64 | iMediaId findLinkAudio_Media (const iMedia *, uint16_t linkId); | 64 | iMediaId findLinkAudio_Media (const iMedia *, uint16_t linkId); |
65 | iBool audioInfo_Media (const iMedia *, iMediaId audioId, iGmAudioInfo *info_out); | 65 | iBool audioInfo_Media (const iMedia *, iMediaId audioId, iGmAudioInfo *info_out); |
66 | iPlayer * audioPlayer_Media (const iMedia *, iMediaId audioId); | 66 | iPlayer * audioPlayer_Media (const iMedia *, iMediaId audioId); |
67 | |||
68 | |||
69 | /*----------------------------------------------------------------------------------------------*/ | ||
70 | |||
71 | iDeclareType(GmRequest) | ||
72 | iDeclareType(DocumentWidget) | ||
73 | |||
74 | iDeclareClass(MediaRequest) | ||
75 | |||
76 | struct Impl_MediaRequest { | ||
77 | iObject object; | ||
78 | iDocumentWidget *doc; | ||
79 | unsigned int linkId; | ||
80 | iGmRequest * req; | ||
81 | }; | ||
82 | |||
83 | iDeclareObjectConstructionArgs(MediaRequest, iDocumentWidget *doc, unsigned int linkId, | ||
84 | const iString *url) | ||
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 | ||
58 | iDeclareClass(MediaRequest) | ||
59 | |||
60 | struct Impl_MediaRequest { | ||
61 | iObject object; | ||
62 | iDocumentWidget *doc; | ||
63 | iGmLinkId linkId; | ||
64 | iGmRequest * req; | ||
65 | }; | ||
66 | |||
67 | static void updated_MediaRequest_(iAnyObject *obj) { | ||
68 | iMediaRequest *d = obj; | ||
69 | postCommandf_App("media.updated link:%u request:%p", d->linkId, d); | ||
70 | } | ||
71 | |||
72 | static void finished_MediaRequest_(iAnyObject *obj) { | ||
73 | iMediaRequest *d = obj; | ||
74 | postCommandf_App("media.finished link:%u request:%p", d->linkId, d); | ||
75 | } | ||
76 | |||
77 | void 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 | |||
87 | void 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 | |||
93 | iDefineObjectConstructionArgs(MediaRequest, | ||
94 | (iDocumentWidget *doc, iGmLinkId linkId, const iString *url), | ||
95 | doc, linkId, url) | ||
96 | iDefineClass(MediaRequest) | ||
97 | |||
98 | /*----------------------------------------------------------------------------------------------*/ | 58 | /*----------------------------------------------------------------------------------------------*/ |
99 | 59 | ||
100 | iDeclareType(Model) | 60 | iDeclareType(PersistentDocumentState) |
101 | iDeclareTypeConstruction(Model) | 61 | iDeclareTypeConstruction(PersistentDocumentState) |
102 | iDeclareTypeSerialization(Model) | 62 | iDeclareTypeSerialization(PersistentDocumentState) |
103 | 63 | ||
104 | struct Impl_Model { | 64 | struct Impl_PersistentDocumentState { |
105 | /* state that persists across sessions */ | ||
106 | iHistory *history; | 65 | iHistory *history; |
107 | iString * url; | 66 | iString * url; |
108 | }; | 67 | }; |
109 | 68 | ||
110 | void init_Model(iModel *d) { | 69 | void 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 | ||
115 | void deinit_Model(iModel *d) { | 74 | void 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 | ||
120 | void serialize_Model(const iModel *d, iStream *outs) { | 79 | void 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 | ||
126 | void deserialize_Model(iModel *d, iStream *ins) { | 85 | void 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 | ||
132 | iDefineTypeConstruction(Model) | 91 | iDefineTypeConstruction(PersistentDocumentState) |
133 | 92 | ||
134 | /*----------------------------------------------------------------------------------------------*/ | 93 | /*----------------------------------------------------------------------------------------------*/ |
135 | 94 | ||
@@ -167,7 +126,7 @@ enum iDocumentWidgetFlag { | |||
167 | struct Impl_DocumentWidget { | 126 | struct 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 | ||
291 | static void requestUpdated_DocumentWidget_(iAnyObject *obj) { | 250 | static 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 | ||
2654 | void serializeState_DocumentWidget(const iDocumentWidget *d, iStream *outs) { | 2614 | void serializeState_DocumentWidget(const iDocumentWidget *d, iStream *outs) { |
2655 | serialize_Model(&d->mod, outs); | 2615 | serialize_PersistentDocumentState(&d->mod, outs); |
2656 | } | 2616 | } |
2657 | 2617 | ||
2658 | void deserializeState_DocumentWidget(iDocumentWidget *d, iStream *ins) { | 2618 | void 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 | } |