2012-11-30 11:57:23 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "NoticeListCtrl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
2013-06-14 04:28:14 +00:00
|
|
|
#include "diagnostics.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "mfile.h"
|
|
|
|
#include "miofile.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "wizardex.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "browser.h"
|
2012-11-30 11:57:23 +00:00
|
|
|
#include "Events.h"
|
|
|
|
#include "BOINCGUIApp.h"
|
2013-06-14 04:28:14 +00:00
|
|
|
#include "SkinManager.h"
|
2012-11-30 11:57:23 +00:00
|
|
|
#include "MainDocument.h"
|
|
|
|
#include "NoticeListCtrl.h"
|
|
|
|
|
|
|
|
////@begin XPM images
|
|
|
|
////@end XPM images
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
/* CNoticeListCtrl type definition
|
2012-11-30 11:57:23 +00:00
|
|
|
*/
|
2013-11-11 14:36:30 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( CNoticeListCtrl, wxWindow )
|
2012-11-30 11:57:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* CNoticeListCtrl event table definition
|
|
|
|
*/
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
BEGIN_EVENT_TABLE( CNoticeListCtrl, wxWindow )
|
2012-11-30 11:57:23 +00:00
|
|
|
|
|
|
|
////@begin CNoticeListCtrl event table entries
|
2013-11-11 14:36:30 +00:00
|
|
|
EVT_WEBVIEW_NAVIGATING(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnLinkClicked)
|
2013-11-12 11:23:26 +00:00
|
|
|
EVT_WEBVIEW_ERROR(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnWebViewError)
|
2012-11-30 11:57:23 +00:00
|
|
|
////@end CNoticeListCtrl event table entries
|
|
|
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* CNoticeListCtrl constructors
|
|
|
|
*/
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
CNoticeListCtrl::CNoticeListCtrl( ) {
|
2012-11-30 11:57:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
CNoticeListCtrl::CNoticeListCtrl( wxWindow* parent ) {
|
2012-11-30 11:57:23 +00:00
|
|
|
Create( parent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
CNoticeListCtrl::~CNoticeListCtrl( ) {
|
2012-11-30 11:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* CNoticeListCtrl creator
|
|
|
|
*/
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
bool CNoticeListCtrl::Create( wxWindow* parent ) {
|
2012-11-30 11:57:23 +00:00
|
|
|
////@begin CNoticeListCtrl member initialisation
|
|
|
|
////@end CNoticeListCtrl member initialisation
|
|
|
|
|
|
|
|
////@begin CNoticeListCtrl creation
|
2013-11-11 14:36:30 +00:00
|
|
|
wxWindow::Create( parent, ID_LIST_NOTIFICATIONSVIEW, wxDefaultPosition, wxDefaultSize,
|
2012-11-30 11:57:23 +00:00
|
|
|
wxSUNKEN_BORDER | wxTAB_TRAVERSAL );
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
m_browser = wxWebView::New( this, ID_LIST_NOTIFICATIONSVIEW );
|
2012-11-30 11:57:23 +00:00
|
|
|
////@end CNoticeListCtrl creation
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
wxBoxSizer *topsizer;
|
|
|
|
topsizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
topsizer->Add(m_browser, 1, wxEXPAND);
|
|
|
|
SetAutoLayout(true);
|
|
|
|
SetSizer(topsizer);
|
|
|
|
|
|
|
|
m_itemCount = 0;
|
2014-05-06 04:02:35 +00:00
|
|
|
m_noticesBody = wxT("<html><head></head><body></body></html>");
|
2013-11-11 14:36:30 +00:00
|
|
|
|
2012-12-21 13:38:42 +00:00
|
|
|
// Display the fetching notices message until we have notices
|
2012-12-20 12:13:46 +00:00
|
|
|
// to display or have determined that there are no notices.
|
|
|
|
m_bDisplayFetchingNotices = false;
|
2012-11-30 11:57:23 +00:00
|
|
|
m_bDisplayEmptyNotice = true;
|
2012-12-21 13:38:42 +00:00
|
|
|
m_bNeedsReloading = false;
|
2012-11-30 11:57:23 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
int CNoticeListCtrl::GetItemCount() {
|
|
|
|
return m_itemCount;
|
2012-11-30 11:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
void CNoticeListCtrl::SetItemCount(int newCount) {
|
|
|
|
int i;
|
2012-11-30 11:57:23 +00:00
|
|
|
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2013-06-14 04:28:14 +00:00
|
|
|
CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
|
2012-11-30 11:57:23 +00:00
|
|
|
wxString strTitle = wxEmptyString;
|
|
|
|
wxString strDescription = wxEmptyString;
|
|
|
|
wxString strProjectName = wxEmptyString;
|
|
|
|
wxString strURL = wxEmptyString;
|
2013-06-14 04:28:14 +00:00
|
|
|
wxString strCreateTime = wxEmptyString;
|
|
|
|
wxString strCategory = wxEmptyString;
|
2012-11-30 11:57:23 +00:00
|
|
|
wxString strBuffer = wxEmptyString;
|
|
|
|
wxString strTemp = wxEmptyString;
|
|
|
|
wxDateTime dtBuffer;
|
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
2013-06-14 04:28:14 +00:00
|
|
|
wxASSERT(pSkinAdvanced);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
m_itemCount = newCount;
|
2014-05-06 04:02:35 +00:00
|
|
|
m_noticesBody = wxT("<html><head></head><body><font face=helvetica>");
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
for (i=0; i<newCount; ++i) {
|
|
|
|
if (pDoc->IsConnected()) {
|
|
|
|
NOTICE* np = pDoc->notice((unsigned int)i);
|
2013-06-14 04:28:14 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strCategory = wxString(np->category, wxConvUTF8);
|
2013-06-14 04:28:14 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strProjectName = wxString(np->project_name, wxConvUTF8);
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strURL = wxString(np->link, wxConvUTF8);
|
2013-06-14 04:28:14 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strTitle = wxString(np->title, wxConvUTF8);
|
|
|
|
|
|
|
|
// Fix-up title
|
|
|
|
if (strCategory == wxT("client")) {
|
|
|
|
strBuffer.Printf(
|
|
|
|
wxT("_(\"Notice from %s\")"),
|
|
|
|
pSkinAdvanced->GetApplicationShortName().c_str()
|
|
|
|
);
|
|
|
|
if (strProjectName.size()) {
|
|
|
|
strTemp.Printf(wxT("%s: %s"), strProjectName.c_str(), strBuffer.c_str());
|
|
|
|
} else {
|
|
|
|
strTemp.Printf(wxT("%s"), strBuffer.c_str());
|
|
|
|
}
|
|
|
|
} else if (strCategory == wxT("scheduler")) {
|
|
|
|
strTemp.Printf(wxT("%s: %s"), strProjectName.c_str(), wxT("_(\"Notice from server\")"));
|
2012-11-30 11:57:23 +00:00
|
|
|
} else {
|
2013-11-11 14:36:30 +00:00
|
|
|
if (strProjectName.size()) {
|
|
|
|
strTemp.Printf(wxT("%s: %s"), strProjectName.c_str(), strTitle.c_str());
|
|
|
|
} else {
|
|
|
|
strTemp = strTitle;
|
|
|
|
}
|
2012-11-30 11:57:23 +00:00
|
|
|
}
|
2013-06-14 04:28:14 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strTitle = strTemp;
|
|
|
|
eol_to_br(strTitle);
|
|
|
|
localize(strTitle);
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strDescription = wxString(np->description.c_str(), wxConvUTF8);
|
|
|
|
eol_to_br(strDescription);
|
|
|
|
localize(strDescription);
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-12 11:23:26 +00:00
|
|
|
// RSS feeds and web pages may use protocol-relative (scheme-relative)
|
|
|
|
// URLs, such as <img src="//sample.com/test.jpg"/>
|
|
|
|
// 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://"));
|
2014-01-15 07:30:08 +00:00
|
|
|
strDescription.Replace(wxT("</a>"), wxT("</a> "));
|
2013-11-12 11:23:26 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
dtBuffer.Set((time_t)np->create_time);
|
|
|
|
strCreateTime = dtBuffer.Format();
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-12 11:23:26 +00:00
|
|
|
// Put dividers between notices, but not before first or after last
|
|
|
|
if (i == 0) {
|
|
|
|
strBuffer = wxEmptyString;
|
|
|
|
} else {
|
|
|
|
strBuffer = wxT("<hr>");
|
|
|
|
}
|
|
|
|
|
|
|
|
strBuffer += wxT("<table border=0 cellpadding=5><tr><td>");
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
if (!strTitle.IsEmpty()) {
|
|
|
|
strTemp.Printf(
|
|
|
|
wxT("<b>%s</b><br>"),
|
|
|
|
strTitle.c_str()
|
|
|
|
);
|
|
|
|
strBuffer += strTemp;
|
|
|
|
}
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strBuffer += strDescription;
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strBuffer += wxT("<br><font size=-2 color=#8f8f8f>");
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
strBuffer += strCreateTime;
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
if (!strURL.IsEmpty()) {
|
|
|
|
strTemp.Printf(
|
2013-11-11 15:35:31 +00:00
|
|
|
wxT(" · <a href=%s>%s</a> "),
|
2013-11-11 14:36:30 +00:00
|
|
|
strURL.c_str(),
|
|
|
|
_("more...")
|
|
|
|
);
|
|
|
|
strBuffer += strTemp;
|
|
|
|
}
|
2012-11-30 11:57:23 +00:00
|
|
|
|
2013-11-12 11:23:26 +00:00
|
|
|
strBuffer += wxT("</font></td></tr></table>");
|
2013-11-11 14:36:30 +00:00
|
|
|
}
|
|
|
|
m_noticesBody += strBuffer;
|
2012-11-30 11:57:23 +00:00
|
|
|
}
|
2014-05-06 04:02:35 +00:00
|
|
|
m_noticesBody += wxT("</font></body></html>");
|
2013-11-11 14:36:30 +00:00
|
|
|
m_browser->SetPage(m_noticesBody, wxT("http://"));
|
2012-11-30 11:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CNoticeListCtrl::Clear() {
|
2012-12-21 13:38:42 +00:00
|
|
|
m_bNeedsReloading = true;
|
2012-12-14 11:40:35 +00:00
|
|
|
UpdateUI();
|
2012-11-30 11:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-11 14:36:30 +00:00
|
|
|
void CNoticeListCtrl::OnLinkClicked( wxWebViewEvent& event ) {
|
|
|
|
if (event.GetURL().StartsWith(wxT("http://")) || event.GetURL().StartsWith(wxT("https://"))) {
|
|
|
|
event.Veto(); // Tell wxWebView not to follow link
|
|
|
|
wxLaunchDefaultBrowser(event.GetURL());
|
2014-05-06 04:06:24 +00:00
|
|
|
} else {
|
|
|
|
event.Skip();
|
2013-11-11 14:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-12 11:23:26 +00:00
|
|
|
void CNoticeListCtrl::OnWebViewError( wxWebViewEvent& event ) {
|
|
|
|
fprintf(stderr, "wxWebView error: target=%s, URL=%s\n",
|
2013-11-12 11:45:39 +00:00
|
|
|
(event.GetTarget().ToStdString()).c_str(), (event.GetURL().ToStdString()).c_str());
|
2013-11-12 11:23:26 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-30 11:57:23 +00:00
|
|
|
/*!
|
|
|
|
* Update the UI.
|
|
|
|
*/
|
2013-11-11 14:36:30 +00:00
|
|
|
bool CNoticeListCtrl::UpdateUI() {
|
2012-11-30 11:57:23 +00:00
|
|
|
static bool bAlreadyRunning = false;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
// Call Freeze() / Thaw() only when actually needed;
|
|
|
|
// otherwise it causes unnecessary redraws
|
2012-12-18 12:55:22 +00:00
|
|
|
int noticeCount = pDoc->GetNoticeCount();
|
2012-12-21 13:38:42 +00:00
|
|
|
if ((noticeCount < 0) || (!pDoc->IsConnected()) || m_bNeedsReloading) {
|
2012-12-20 12:13:46 +00:00
|
|
|
if (GetItemCount()) {
|
|
|
|
SetItemCount(0);
|
2013-01-17 10:03:12 +00:00
|
|
|
Refresh();
|
2012-12-20 12:13:46 +00:00
|
|
|
}
|
2013-01-17 10:03:12 +00:00
|
|
|
// Display "Fetching Notices" text only when connected
|
|
|
|
m_bDisplayFetchingNotices = pDoc->IsConnected();
|
2012-12-20 12:13:46 +00:00
|
|
|
m_bDisplayEmptyNotice = false;
|
2012-12-21 13:38:42 +00:00
|
|
|
m_bNeedsReloading = false;
|
2012-12-20 12:13:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noticeCount == 0) {
|
|
|
|
if (GetItemCount()) {
|
|
|
|
SetItemCount(0);
|
2013-01-17 10:03:12 +00:00
|
|
|
Refresh();
|
2012-12-20 12:13:46 +00:00
|
|
|
}
|
|
|
|
m_bDisplayFetchingNotices = false;
|
2012-11-30 11:57:23 +00:00
|
|
|
m_bDisplayEmptyNotice = true;
|
2012-12-21 13:38:42 +00:00
|
|
|
m_bNeedsReloading = false;
|
2012-11-30 11:57:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bAlreadyRunning) {
|
|
|
|
bAlreadyRunning = true;
|
|
|
|
if (
|
|
|
|
pDoc->IsConnected() &&
|
|
|
|
(pDoc->notices.complete ||
|
2012-12-20 12:13:46 +00:00
|
|
|
((int)GetItemCount() != noticeCount))
|
2012-11-30 11:57:23 +00:00
|
|
|
) {
|
|
|
|
pDoc->notices.complete = false;
|
|
|
|
Freeze();
|
2012-12-18 12:55:22 +00:00
|
|
|
SetItemCount(noticeCount);
|
2012-12-20 12:13:46 +00:00
|
|
|
m_bDisplayFetchingNotices = false;
|
2012-12-18 12:55:22 +00:00
|
|
|
m_bDisplayEmptyNotice = false;
|
2012-11-30 11:57:23 +00:00
|
|
|
Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
bAlreadyRunning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|