diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-03 15:19:18 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-03 15:19:18 +0200 |
commit | 19102c9076cf8790c25edbc72862e8bcd157ad79 (patch) | |
tree | e6433c188288e2cba91d6956c723ad15629563db /src/ui | |
parent | 4e076de8be2fd29d4c6489a041cc4b67a0246c2e (diff) |
Cleanup: Breaking up documentwidget.c
There's a lot of stuff in documentwidget.c. First, moving away the smaller helper code.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 70 |
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 | ||
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 | } |