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 | 122 |
3 files changed, 114 insertions, 60 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 bacf8ff7..e87b1413 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) { |
@@ -1757,6 +1716,48 @@ static iBool processPlayerEvents_DocumentWidget_(iDocumentWidget *d, const SDL_E | |||
1757 | return iFalse; | 1716 | return iFalse; |
1758 | } | 1717 | } |
1759 | 1718 | ||
1719 | static size_t linkOrdinalFromKey_(int key) { | ||
1720 | if (key >= '1' && key <= '9') { | ||
1721 | return key - '1'; | ||
1722 | } | ||
1723 | if (key < 'a' || key > 'z') { | ||
1724 | return iInvalidPos; | ||
1725 | } | ||
1726 | int ord = key - 'a' + 9; | ||
1727 | #if defined (iPlatformApple) | ||
1728 | /* Skip keys that would conflict with default system shortcuts: hide, minimize, quit, close. */ | ||
1729 | if (key == 'h' || key == 'm' || key == 'q' || key == 'w') { | ||
1730 | return iInvalidPos; | ||
1731 | } | ||
1732 | if (key > 'h') ord--; | ||
1733 | if (key > 'm') ord--; | ||
1734 | if (key > 'q') ord--; | ||
1735 | if (key > 'w') ord--; | ||
1736 | #endif | ||
1737 | return ord; | ||
1738 | } | ||
1739 | |||
1740 | static iChar linkOrdinalChar_(size_t ord) { | ||
1741 | if (ord < 9) { | ||
1742 | return 0x278a + ord; | ||
1743 | } | ||
1744 | #if defined (iPlatformApple) | ||
1745 | if (ord < 9 + 22) { | ||
1746 | int key = 'a' + ord - 9; | ||
1747 | if (key >= 'h') key++; | ||
1748 | if (key >= 'm') key++; | ||
1749 | if (key >= 'q') key++; | ||
1750 | if (key >= 'w') key++; | ||
1751 | return 0x24b6 + key - 'a'; | ||
1752 | } | ||
1753 | #else | ||
1754 | if (ord < 9 + 26) { | ||
1755 | return 0x24b6 + ord - 9; | ||
1756 | } | ||
1757 | #endif | ||
1758 | return 0; | ||
1759 | } | ||
1760 | |||
1760 | static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *ev) { | 1761 | static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *ev) { |
1761 | iWidget *w = as_Widget(d); | 1762 | iWidget *w = as_Widget(d); |
1762 | if (ev->type == SDL_USEREVENT && ev->user.code == command_UserEventCode) { | 1763 | if (ev->type == SDL_USEREVENT && ev->user.code == command_UserEventCode) { |
@@ -1787,12 +1788,12 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1787 | } | 1788 | } |
1788 | } | 1789 | } |
1789 | if (ev->type == SDL_KEYDOWN) { | 1790 | if (ev->type == SDL_KEYDOWN) { |
1790 | const int mods = keyMods_Sym(ev->key.keysym.mod); | 1791 | const int key = ev->key.keysym.sym; |
1791 | const int key = ev->key.keysym.sym; | ||
1792 | if ((d->flags & showLinkNumbers_DocumentWidgetFlag) && | 1792 | if ((d->flags & showLinkNumbers_DocumentWidgetFlag) && |
1793 | ((key >= '1' && key <= '9') || (key >= 'a' && key <= 'z'))) { | 1793 | ((key >= '1' && key <= '9') || (key >= 'a' && key <= 'z'))) { |
1794 | const size_t ord = isdigit(key) ? key - SDLK_1 : (key - 'a' + 9); | 1794 | const size_t ord = linkOrdinalFromKey_(key); |
1795 | iConstForEach(PtrArray, i, &d->visibleLinks) { | 1795 | iConstForEach(PtrArray, i, &d->visibleLinks) { |
1796 | if (ord == iInvalidPos) break; | ||
1796 | const iGmRun *run = i.ptr; | 1797 | const iGmRun *run = i.ptr; |
1797 | if (run->flags & decoration_GmRunFlag && | 1798 | if (run->flags & decoration_GmRunFlag && |
1798 | visibleLinkOrdinal_DocumentWidget_(d, run->linkId) == ord) { | 1799 | visibleLinkOrdinal_DocumentWidget_(d, run->linkId) == ord) { |
@@ -1954,6 +1955,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1954 | if (processPlayerEvents_DocumentWidget_(d, ev)) { | 1955 | if (processPlayerEvents_DocumentWidget_(d, ev)) { |
1955 | return iTrue; | 1956 | return iTrue; |
1956 | } | 1957 | } |
1958 | /* The left mouse button. */ | ||
1957 | switch (processEvent_Click(&d->click, ev)) { | 1959 | switch (processEvent_Click(&d->click, ev)) { |
1958 | case started_ClickResult: | 1960 | case started_ClickResult: |
1959 | iChangeFlags(d->flags, selecting_DocumentWidgetFlag, iFalse); | 1961 | iChangeFlags(d->flags, selecting_DocumentWidgetFlag, iFalse); |
@@ -2204,8 +2206,8 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
2204 | else { | 2206 | else { |
2205 | if (d->showLinkNumbers && run->linkId && run->flags & decoration_GmRunFlag) { | 2207 | if (d->showLinkNumbers && run->linkId && run->flags & decoration_GmRunFlag) { |
2206 | const size_t ord = visibleLinkOrdinal_DocumentWidget_(d->widget, run->linkId); | 2208 | const size_t ord = visibleLinkOrdinal_DocumentWidget_(d->widget, run->linkId); |
2207 | if (ord < 9 + 26) { | 2209 | const iChar ordChar = linkOrdinalChar_(ord); |
2208 | const iChar ordChar = ord < 9 ? 0x278a + ord : (0x24b6 + ord - 9); | 2210 | if (ordChar) { |
2209 | drawString_Text(run->font, | 2211 | drawString_Text(run->font, |
2210 | init_I2(d->viewPos.x - gap_UI / 3, visPos.y), | 2212 | init_I2(d->viewPos.x - gap_UI / 3, visPos.y), |
2211 | fg, | 2213 | fg, |
@@ -2656,11 +2658,11 @@ const iString *bookmarkTitle_DocumentWidget(const iDocumentWidget *d) { | |||
2656 | } | 2658 | } |
2657 | 2659 | ||
2658 | void serializeState_DocumentWidget(const iDocumentWidget *d, iStream *outs) { | 2660 | void serializeState_DocumentWidget(const iDocumentWidget *d, iStream *outs) { |
2659 | serialize_Model(&d->mod, outs); | 2661 | serialize_PersistentDocumentState(&d->mod, outs); |
2660 | } | 2662 | } |
2661 | 2663 | ||
2662 | void deserializeState_DocumentWidget(iDocumentWidget *d, iStream *ins) { | 2664 | void deserializeState_DocumentWidget(iDocumentWidget *d, iStream *ins) { |
2663 | deserialize_Model(&d->mod, ins); | 2665 | deserialize_PersistentDocumentState(&d->mod, ins); |
2664 | parseUser_DocumentWidget_(d); | 2666 | parseUser_DocumentWidget_(d); |
2665 | updateFromHistory_DocumentWidget_(d); | 2667 | updateFromHistory_DocumentWidget_(d); |
2666 | } | 2668 | } |