@@ -50,6 +50,102 @@ using boost::property_tree::ptree;
5050
5151namespace Astroid {
5252
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+
53149 ThreadView::ThreadView (MainWindow * mw, bool _edit_mode) : Mode (mw) { //
54150 edit_mode = _edit_mode;
55151 wk_loaded = false ;
@@ -64,7 +160,7 @@ namespace Astroid {
64160 /* WebKit: set up webkit web view */
65161
66162 /* create web context */
67- context = webkit_web_context_new_ephemeral ();
163+ Private-> context = webkit_web_context_new_ephemeral ();
68164
69165 /* set up this extension interface */
70166 page_client = new PageClient (this );
@@ -165,68 +261,7 @@ namespace Astroid {
165261 WebKitPolicyDecisionType decision_type,
166262 gpointer user_data) {
167263
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);
230265 }
231266
232267 void ThreadView::open_link (ustring uri) {
@@ -296,29 +331,7 @@ namespace Astroid {
296331 WebKitLoadEvent load_event,
297332 gpointer user_data)
298333 {
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);
322335 }
323336
324337 void ThreadView::load_thread (refptr<NotmuchThread> _thread) {
@@ -929,9 +942,9 @@ namespace Astroid {
929942 }
930943 }
931944 }
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 ()));
935948 }
936949 return true ;
937950 });
@@ -1077,7 +1090,7 @@ namespace Astroid {
10771090 });
10781091
10791092 keys.register_run (" thread_view.run" ,
1080- [&] (Key, ustring cmd, ustring undo_cmd) {
1093+ [&] (Key, ustring cmd, ustring undo_cmd) {
10811094 if (focused_message) {
10821095 cmd = ustring::compose (cmd, focused_message->tid , focused_message->mid );
10831096 undo_cmd = ustring::compose (undo_cmd, focused_message->tid , focused_message->mid );
0 commit comments