@@ -50,6 +50,102 @@ using boost::property_tree::ptree;
50
50
51
51
namespace Astroid {
52
52
53
+ extern " C" bool ThreadView_on_load_changed (
54
+ WebKitWebView * w,
55
+ WebKitLoadEvent load_event,
56
+ gpointer user_data);
57
+
58
+ extern " C" gboolean ThreadView_decide_policy (
59
+ WebKitWebView * w,
60
+ WebKitPolicyDecision * decision,
61
+ WebKitPolicyDecisionType decision_type,
62
+ gpointer user_data);
63
+
64
+ struct ThreadView ::Private {
65
+ WebKitWebView * webview;
66
+ WebKitSettings * websettings;
67
+ WebKitWebContext * context;
68
+
69
+ /* event wrappers */
70
+ bool on_load_changed (ThreadView & self,
71
+ WebKitWebView * /* w */ ,
72
+ WebKitLoadEvent load_event) {
73
+ LOG (debug) << " tv: on_load_changed: " << load_event;
74
+ switch (load_event) {
75
+ case WEBKIT_LOAD_FINISHED:
76
+ LOG (debug) << " tv: load finished." ;
77
+ {
78
+ /* render */
79
+ self.wk_loaded = true ;
80
+
81
+ // also called in page_client
82
+ if (self.page_client ->ready ) on_ready_to_render ();
83
+ }
84
+ default :
85
+ break ;
86
+ }
87
+
88
+ return true ;
89
+ }
90
+
91
+ gboolean decide_policy (ThreadView & self,
92
+ WebKitWebView * /* w */ ,
93
+ WebKitPolicyDecision * decision,
94
+ WebKitPolicyDecisionType decision_type) {
95
+ LOG (debug) << " tv: decide policy" ;
96
+
97
+ switch (decision_type) {
98
+ case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: // navigate to {{{
99
+ {
100
+ WebKitNavigationPolicyDecision * navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
101
+ WebKitNavigationAction * nav_action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision);
102
+
103
+ if (webkit_navigation_action_get_navigation_type (nav_action)
104
+ == WEBKIT_NAVIGATION_TYPE_LINK_CLICKED) {
105
+
106
+ webkit_policy_decision_ignore (decision);
107
+
108
+ const gchar * uri_c =
109
+ webkit_uri_request_get_uri (webkit_navigation_action_get_request (nav_action));
110
+
111
+ ustring uri (uri_c);
112
+ LOG (info) << " tv: navigating to: " << uri;
113
+
114
+ ustring scheme = Glib::uri_parse_scheme (uri);
115
+
116
+ if (scheme == " mailto" ) {
117
+
118
+ uri = uri.substr (scheme.length ()+1 , uri.length () - scheme.length ()-1 );
119
+ UstringUtils::trim (uri);
120
+
121
+ self.main_window ->add_mode (new EditMessage (self.main_window , uri));
122
+
123
+ } else if (scheme == " id" || scheme == " mid" ) {
124
+ self.main_window ->add_mode (new ThreadIndex (self.main_window , uri));
125
+
126
+ } else if (scheme == " http" || scheme == " https" || scheme == " ftp" ) {
127
+ self.open_link (uri);
128
+
129
+ } else {
130
+ LOG (error) << " tv: unknown uri scheme. not opening." ;
131
+ }
132
+ }
133
+ } // }}}
134
+ break ;
135
+
136
+ case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
137
+ webkit_policy_decision_ignore (decision);
138
+ break ;
139
+
140
+ default :
141
+ webkit_policy_decision_ignore (decision);
142
+ return true ; // stop event
143
+ }
144
+
145
+ return true ; // stop event
146
+ }
147
+ }; // struct ThreadView::Private
148
+
53
149
ThreadView::ThreadView (MainWindow * mw, bool _edit_mode) : Mode (mw) { //
54
150
edit_mode = _edit_mode;
55
151
wk_loaded = false ;
@@ -64,7 +160,7 @@ namespace Astroid {
64
160
/* WebKit: set up webkit web view */
65
161
66
162
/* create web context */
67
- context = webkit_web_context_new_ephemeral ();
163
+ Private-> context = webkit_web_context_new_ephemeral ();
68
164
69
165
/* set up this extension interface */
70
166
page_client = new PageClient (this );
@@ -165,68 +261,7 @@ namespace Astroid {
165
261
WebKitPolicyDecisionType decision_type,
166
262
gpointer user_data) {
167
263
168
- return ((ThreadView *) user_data)->decide_policy (w, decision, decision_type);
169
- }
170
-
171
- gboolean ThreadView::decide_policy (
172
- WebKitWebView * /* w */ ,
173
- WebKitPolicyDecision * decision,
174
- WebKitPolicyDecisionType decision_type)
175
- {
176
-
177
- LOG (debug) << " tv: decide policy" ;
178
-
179
- switch (decision_type) {
180
- case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: // navigate to {{{
181
- {
182
- WebKitNavigationPolicyDecision * navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
183
- WebKitNavigationAction * nav_action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision);
184
-
185
- if (webkit_navigation_action_get_navigation_type (nav_action)
186
- == WEBKIT_NAVIGATION_TYPE_LINK_CLICKED) {
187
-
188
- webkit_policy_decision_ignore (decision);
189
-
190
- const gchar * uri_c = webkit_uri_request_get_uri (
191
- webkit_navigation_action_get_request (nav_action));
192
-
193
-
194
- ustring uri (uri_c);
195
- LOG (info) << " tv: navigating to: " << uri;
196
-
197
- ustring scheme = Glib::uri_parse_scheme (uri);
198
-
199
- if (scheme == " mailto" ) {
200
-
201
- uri = uri.substr (scheme.length ()+1 , uri.length () - scheme.length ()-1 );
202
- UstringUtils::trim (uri);
203
-
204
- main_window->add_mode (new EditMessage (main_window, uri));
205
-
206
- } else if (scheme == " id" || scheme == " mid" ) {
207
- main_window->add_mode (new ThreadIndex (main_window, uri));
208
-
209
- } else if (scheme == " http" || scheme == " https" || scheme == " ftp" ) {
210
- open_link (uri);
211
-
212
- } else {
213
-
214
- LOG (error) << " tv: unknown uri scheme. not opening." ;
215
- }
216
- }
217
- } // }}}
218
- break ;
219
-
220
- case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
221
- webkit_policy_decision_ignore (decision);
222
- break ;
223
-
224
- default :
225
- webkit_policy_decision_ignore (decision);
226
- return true ; // stop event
227
- }
228
-
229
- return true ; // stop event
264
+ return ((ThreadView *) user_data)->Private ::decide_policy (*user_data, w, decision, decision_type);
230
265
}
231
266
232
267
void ThreadView::open_link (ustring uri) {
@@ -296,29 +331,7 @@ namespace Astroid {
296
331
WebKitLoadEvent load_event,
297
332
gpointer user_data)
298
333
{
299
- return ((ThreadView *) user_data)->on_load_changed (w, load_event);
300
- }
301
-
302
- bool ThreadView::on_load_changed (
303
- WebKitWebView * /* w */ ,
304
- WebKitLoadEvent load_event)
305
- {
306
- LOG (debug) << " tv: on_load_changed: " << load_event;
307
- switch (load_event) {
308
- case WEBKIT_LOAD_FINISHED:
309
- LOG (debug) << " tv: load finished." ;
310
- {
311
- /* render */
312
- wk_loaded = true ;
313
-
314
- // also called in page_client
315
- if (page_client->ready ) on_ready_to_render ();
316
- }
317
- default :
318
- break ;
319
- }
320
-
321
- return true ;
334
+ return ((ThreadView *) user_data)->Private ::on_load_changed (*user_data, w, load_event);
322
335
}
323
336
324
337
void ThreadView::load_thread (refptr<NotmuchThread> _thread) {
@@ -929,9 +942,9 @@ namespace Astroid {
929
942
}
930
943
}
931
944
}
932
- main_window->add_mode (new EditMessage (main_window, to.str (),
933
- from.full_address (),
934
- cc.str (), bcc.str ()));
945
+ main_window->add_mode (new EditMessage (main_window, to.str (),
946
+ from.full_address (),
947
+ cc.str (), bcc.str ()));
935
948
}
936
949
return true ;
937
950
});
@@ -1077,7 +1090,7 @@ namespace Astroid {
1077
1090
});
1078
1091
1079
1092
keys.register_run (" thread_view.run" ,
1080
- [&] (Key, ustring cmd, ustring undo_cmd) {
1093
+ [&] (Key, ustring cmd, ustring undo_cmd) {
1081
1094
if (focused_message) {
1082
1095
cmd = ustring::compose (cmd, focused_message->tid , focused_message->mid );
1083
1096
undo_cmd = ustring::compose (undo_cmd, focused_message->tid , focused_message->mid );
0 commit comments