From 4ed5476f25fb7f5ca58d9eae18d3f08dc53faccb Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Tue, 12 Nov 2013 03:23:26 -0800 Subject: [PATCH] MGR: Fixes for wxWebView-based notices: - Fix protocol-relative URLs under MS Windows - Put dividers between notices, but not before first or after last --- clientgui/NoticeListCtrl.cpp | 32 ++++++++++++++++++++++++++++++-- clientgui/NoticeListCtrl.h | 1 + 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/clientgui/NoticeListCtrl.cpp b/clientgui/NoticeListCtrl.cpp index 513c0725ad..ebd9f05b3f 100644 --- a/clientgui/NoticeListCtrl.cpp +++ b/clientgui/NoticeListCtrl.cpp @@ -51,6 +51,7 @@ BEGIN_EVENT_TABLE( CNoticeListCtrl, wxWindow ) ////@begin CNoticeListCtrl event table entries EVT_WEBVIEW_NAVIGATING(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnLinkClicked) + EVT_WEBVIEW_ERROR(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnWebViewError) ////@end CNoticeListCtrl event table entries END_EVENT_TABLE() @@ -175,10 +176,29 @@ void CNoticeListCtrl::SetItemCount(int newCount) { eol_to_br(strDescription); localize(strDescription); + // RSS feeds and web pages may use protocol-relative (scheme-relative) + // URLs, such as + // Since the html comes from a web server via http, the scheme is + // assumed to also be http. But we have cached the html in a local + // file, so it is no longer associated with the http protocol / scheme. + // Therefore all our URLs must explicity specify the http protocol. + // + // The second argument to wxWebView::SetPage is supposed to take care + // of this automatically, but fails to do so under Windows, so we do + // it here explicitly. + strDescription.Replace(wxT("\"//"), wxT("\"http://")); + dtBuffer.Set((time_t)np->create_time); strCreateTime = dtBuffer.Format(); - strBuffer = wxT("
"); + // Put dividers between notices, but not before first or after last + if (i == 0) { + strBuffer = wxEmptyString; + } else { + strBuffer = wxT("
"); + } + + strBuffer += wxT("
"); if (!strTitle.IsEmpty()) { strTemp.Printf( @@ -203,7 +223,7 @@ void CNoticeListCtrl::SetItemCount(int newCount) { strBuffer += strTemp; } - strBuffer += wxT("

"); + strBuffer += wxT("
"); } m_noticesBody += strBuffer; } @@ -228,6 +248,14 @@ void CNoticeListCtrl::OnLinkClicked( wxWebViewEvent& event ) { } +void CNoticeListCtrl::OnWebViewError( wxWebViewEvent& event ) { + fprintf(stderr, "wxWebView error: target=%s, URL=%s\n", + event.GetTarget().c_str(), event.GetURL().c_str()); + + event.Skip(); +} + + /*! * Update the UI. */ diff --git a/clientgui/NoticeListCtrl.h b/clientgui/NoticeListCtrl.h index a231d198cb..04db8aaedb 100644 --- a/clientgui/NoticeListCtrl.h +++ b/clientgui/NoticeListCtrl.h @@ -46,6 +46,7 @@ public: ////@begin CNoticeListCtrl event handler declarations void OnLinkClicked( wxWebViewEvent& event ); + void OnWebViewError( wxWebViewEvent& event ); ////@end CNoticeListCtrl event handler declarations