2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-10-20 15:00:14 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2006-10-20 15:00:14 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2006-10-20 15:00:14 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-10-20 15:00:14 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-20 15:00:14 +00:00
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "sg_StatImageLoader.h"
|
|
|
|
#endif
|
|
|
|
|
2006-07-05 21:36:56 +00:00
|
|
|
#include "stdwx.h"
|
2006-10-20 15:00:14 +00:00
|
|
|
#include "diagnostics.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "mfile.h"
|
|
|
|
#include "miofile.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error_numbers.h"
|
2006-07-05 21:36:56 +00:00
|
|
|
#include "BOINCGUIApp.h"
|
2006-10-20 15:00:14 +00:00
|
|
|
#include "SkinManager.h"
|
|
|
|
#include "MainDocument.h"
|
2006-07-10 13:41:10 +00:00
|
|
|
#include "BOINCBaseFrame.h"
|
2006-10-20 15:00:14 +00:00
|
|
|
#include "sg_StatImageLoader.h"
|
2006-07-24 22:10:28 +00:00
|
|
|
#include "sg_ProjectsComponent.h"
|
2006-08-26 04:17:56 +00:00
|
|
|
#include "app_ipc.h"
|
2006-07-20 17:57:23 +00:00
|
|
|
|
2006-07-10 13:41:10 +00:00
|
|
|
enum{
|
|
|
|
WEBSITE_URL_MENU_ID = 34500,
|
2006-07-10 17:47:21 +00:00
|
|
|
WEBSITE_URL_MENU_ID_REMOVE_PROJECT = 34550,
|
2006-09-26 21:53:00 +00:00
|
|
|
WEBSITE_URL_MENU_ID_HOMEPAGE = 34551,
|
2006-07-10 13:41:10 +00:00
|
|
|
};
|
2006-07-05 21:36:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(StatImageLoader, wxWindow)
|
2006-10-30 03:41:32 +00:00
|
|
|
EVT_PAINT(StatImageLoader::OnPaint)
|
|
|
|
EVT_LEFT_DOWN(StatImageLoader::PopUpMenu)
|
|
|
|
EVT_MENU(WEBSITE_URL_MENU_ID,StatImageLoader::OnMenuLinkClicked)
|
|
|
|
EVT_MENU(WEBSITE_URL_MENU_ID_REMOVE_PROJECT,StatImageLoader::OnMenuLinkClicked)
|
2006-07-05 21:36:56 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
StatImageLoader::StatImageLoader(wxWindow* parent, std::string url) :
|
|
|
|
wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(40,40), wxNO_BORDER)
|
2006-07-10 13:41:10 +00:00
|
|
|
{
|
2006-07-11 23:19:53 +00:00
|
|
|
m_prjUrl = url;
|
2006-10-16 20:46:57 +00:00
|
|
|
project_files_downloaded_time = 1;
|
|
|
|
project_last_rpc_time = 1;
|
|
|
|
BuildUserStatToolTip();
|
|
|
|
statPopUpMenu = new wxMenu(wxSIMPLE_BORDER);
|
|
|
|
AddMenuItems();
|
2006-07-05 21:36:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-10-10 02:53:25 +00:00
|
|
|
StatImageLoader::~StatImageLoader() {
|
2006-10-12 02:18:08 +00:00
|
|
|
delete statPopUpMenu;
|
2006-10-10 02:53:25 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-11-03 00:23:14 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
void StatImageLoader::PopUpMenu(wxMouseEvent& event)
|
|
|
|
{
|
|
|
|
// pop up menu: move menu down a bit so tooltip does not obscure it
|
|
|
|
PopupMenu(statPopUpMenu, event.m_x-10, event.m_y+40);
|
|
|
|
}
|
|
|
|
#else
|
2006-07-21 08:23:26 +00:00
|
|
|
void StatImageLoader::PopUpMenu(wxMouseEvent& WXUNUSED(event))
|
2006-07-05 21:36:56 +00:00
|
|
|
{
|
|
|
|
// pop up menu
|
2006-09-15 16:47:04 +00:00
|
|
|
PopupMenu(statPopUpMenu);
|
2006-07-05 21:36:56 +00:00
|
|
|
}
|
2006-11-03 00:23:14 +00:00
|
|
|
#endif
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-09-08 21:48:06 +00:00
|
|
|
void StatImageLoader::RebuildMenu() {
|
2006-10-16 20:46:57 +00:00
|
|
|
for(int i=(int) statPopUpMenu->GetMenuItemCount()-1; i>=0;i--){
|
|
|
|
wxMenuItem* item = statPopUpMenu->FindItemByPosition(i);
|
|
|
|
statPopUpMenu->Delete(item);
|
|
|
|
}
|
|
|
|
AddMenuItems();
|
2006-09-08 21:48:06 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-10-16 20:46:57 +00:00
|
|
|
void StatImageLoader::BuildUserStatToolTip() {
|
2006-11-22 09:51:59 +00:00
|
|
|
wxString strBuffer = wxEmptyString;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
PROJECT* project = pDoc->state.lookup_project(m_prjUrl);
|
|
|
|
|
|
|
|
strBuffer.Printf(
|
2006-12-04 19:00:37 +00:00
|
|
|
_("%s. Work done by %s: %0.2f"),
|
2006-11-22 09:51:59 +00:00
|
|
|
wxString(project->project_name.c_str(), wxConvUTF8).c_str(),
|
|
|
|
wxString(project->user_name.c_str(), wxConvUTF8).c_str(),
|
|
|
|
project->user_total_credit
|
|
|
|
);
|
|
|
|
|
|
|
|
SetToolTip(new wxToolTip(strBuffer));
|
2006-10-16 20:46:57 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-10-16 20:46:57 +00:00
|
|
|
void StatImageLoader::AddMenuItems()
|
2006-07-05 21:36:56 +00:00
|
|
|
{
|
2006-11-03 00:23:14 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2006-07-05 21:36:56 +00:00
|
|
|
wxASSERT(pDoc);
|
2006-10-23 06:48:48 +00:00
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
2006-07-20 17:57:23 +00:00
|
|
|
|
2006-11-03 03:48:59 +00:00
|
|
|
#ifndef __WXMAC__
|
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
|
|
|
|
wxASSERT(pSkinSimple);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinSimple, CSkinSimple));
|
|
|
|
#endif
|
2006-07-11 23:19:53 +00:00
|
|
|
PROJECT* project = pDoc->state.lookup_project(m_prjUrl);
|
2006-09-08 21:48:06 +00:00
|
|
|
urlCount = project->gui_urls.size();
|
2006-07-05 21:36:56 +00:00
|
|
|
|
2006-09-26 21:53:00 +00:00
|
|
|
// Add the home page link
|
|
|
|
wxMenuItem *urlItem = new wxMenuItem(statPopUpMenu, WEBSITE_URL_MENU_ID_HOMEPAGE,wxString(project->project_name.c_str(), wxConvUTF8));
|
2006-10-23 06:48:48 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
urlItem->SetBackgroundColour(*pSkinSimple->GetBackgroundImage()->GetBackgroundColor());
|
|
|
|
#endif
|
2006-09-26 21:53:00 +00:00
|
|
|
Connect( WEBSITE_URL_MENU_ID_HOMEPAGE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(StatImageLoader::OnMenuLinkClicked) );
|
|
|
|
statPopUpMenu->Append(urlItem);
|
|
|
|
|
|
|
|
|
|
|
|
// Add any GUI urls
|
2006-08-26 04:17:56 +00:00
|
|
|
for(unsigned int i = 0; i < urlCount; i++){
|
2007-05-30 14:04:10 +00:00
|
|
|
urlItem = new wxMenuItem(statPopUpMenu, WEBSITE_URL_MENU_ID + i, wxGetTranslation(wxString(project->gui_urls[i].name.c_str(), wxConvUTF8)));
|
2006-10-23 06:48:48 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
urlItem->SetBackgroundColour(*pSkinSimple->GetBackgroundImage()->GetBackgroundColor());
|
|
|
|
#endif
|
2006-07-10 13:41:10 +00:00
|
|
|
Connect( WEBSITE_URL_MENU_ID + i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(StatImageLoader::OnMenuLinkClicked) );
|
|
|
|
|
2006-07-05 21:36:56 +00:00
|
|
|
statPopUpMenu->Append(urlItem);
|
|
|
|
}
|
2006-07-10 17:47:21 +00:00
|
|
|
|
2006-09-26 21:53:00 +00:00
|
|
|
// Add the 'remove project' option
|
2009-03-05 23:25:41 +00:00
|
|
|
if (!project->attached_via_acct_mgr) {
|
|
|
|
statPopUpMenu->AppendSeparator();
|
|
|
|
wxMenuItemList menuList = statPopUpMenu->GetMenuItems();
|
2006-10-30 03:41:32 +00:00
|
|
|
#ifdef __WXMSW__
|
2009-04-23 03:40:49 +00:00
|
|
|
menuList[statPopUpMenu->GetMenuItemCount()-1]->SetBackgroundColour(wxColour(_T("RED")));
|
2006-10-30 03:41:32 +00:00
|
|
|
#endif
|
2006-07-10 17:47:21 +00:00
|
|
|
|
2009-03-05 23:25:41 +00:00
|
|
|
urlItem = new wxMenuItem(statPopUpMenu, WEBSITE_URL_MENU_ID_REMOVE_PROJECT, _("Remove Project"));
|
2006-10-23 06:48:48 +00:00
|
|
|
#ifdef __WXMSW__
|
2009-03-05 23:25:41 +00:00
|
|
|
urlItem->SetBackgroundColour(*pSkinSimple->GetBackgroundImage()->GetBackgroundColor());
|
2006-10-23 06:48:48 +00:00
|
|
|
#endif
|
2009-03-05 23:25:41 +00:00
|
|
|
Connect( WEBSITE_URL_MENU_ID_REMOVE_PROJECT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(StatImageLoader::OnMenuLinkClicked) );
|
|
|
|
statPopUpMenu->Append(urlItem);
|
|
|
|
}
|
2006-07-05 21:36:56 +00:00
|
|
|
}
|
2006-10-30 03:41:32 +00:00
|
|
|
|
|
|
|
|
2006-07-10 13:41:10 +00:00
|
|
|
void StatImageLoader::OnMenuLinkClicked(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
wxASSERT(pDoc);
|
2006-07-10 17:47:21 +00:00
|
|
|
int menuIDevt = event.GetId();
|
2006-07-10 13:41:10 +00:00
|
|
|
|
2006-07-10 17:47:21 +00:00
|
|
|
if(menuIDevt == WEBSITE_URL_MENU_ID_REMOVE_PROJECT){
|
2006-07-20 17:57:23 +00:00
|
|
|
//call detach project function
|
|
|
|
OnProjectDetach();
|
2006-09-26 21:53:00 +00:00
|
|
|
} else if (menuIDevt == WEBSITE_URL_MENU_ID_HOMEPAGE ) {
|
2009-12-19 05:16:41 +00:00
|
|
|
wxLaunchDefaultBrowser(wxString(m_prjUrl.c_str(),wxConvUTF8));
|
2006-09-26 21:53:00 +00:00
|
|
|
} else{
|
2006-07-10 17:47:21 +00:00
|
|
|
int menuId = menuIDevt - WEBSITE_URL_MENU_ID;
|
2006-07-11 23:19:53 +00:00
|
|
|
PROJECT* project = pDoc->state.lookup_project(m_prjUrl);
|
2006-07-10 17:47:21 +00:00
|
|
|
project->gui_urls[menuId].name.c_str();
|
2006-07-10 13:41:10 +00:00
|
|
|
|
2009-12-19 05:16:41 +00:00
|
|
|
wxLaunchDefaultBrowser(wxString(project->gui_urls[menuId].url.c_str(),wxConvUTF8));
|
2006-07-10 17:47:21 +00:00
|
|
|
}
|
2006-07-10 13:41:10 +00:00
|
|
|
}
|
2006-10-30 03:41:32 +00:00
|
|
|
|
|
|
|
|
2006-07-20 17:57:23 +00:00
|
|
|
void StatImageLoader::OnProjectDetach() {
|
|
|
|
wxInt32 iAnswer = 0;
|
|
|
|
std::string strProjectName;
|
|
|
|
wxString strMessage = wxEmptyString;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
2006-07-24 22:10:28 +00:00
|
|
|
CProjectsComponent* pComp = wxDynamicCast(GetParent(), CProjectsComponent);
|
2006-07-20 17:57:23 +00:00
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
2006-07-24 22:10:28 +00:00
|
|
|
wxASSERT(pComp);
|
2006-07-20 17:57:23 +00:00
|
|
|
|
|
|
|
if (!pDoc->IsUserAuthorized())
|
|
|
|
return;
|
|
|
|
|
2006-07-31 13:59:21 +00:00
|
|
|
int indexOfProj = -1;
|
2008-09-30 09:36:07 +00:00
|
|
|
int prjCount = pDoc->GetSimpleProjectCount();
|
2006-07-31 13:59:21 +00:00
|
|
|
for(int m = 0; m < prjCount; m++){
|
|
|
|
PROJECT* project = pDoc->project(m);
|
|
|
|
project->get_name(strProjectName);
|
|
|
|
if(project->master_url == m_prjUrl){
|
|
|
|
indexOfProj = m;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-20 17:57:23 +00:00
|
|
|
strMessage.Printf(
|
|
|
|
_("Are you sure you want to detach from project '%s'?"),
|
|
|
|
strProjectName.c_str()
|
|
|
|
);
|
|
|
|
|
2008-08-20 16:07:06 +00:00
|
|
|
iAnswer = wxGetApp().SafeMessageBox(
|
2006-07-20 17:57:23 +00:00
|
|
|
strMessage,
|
|
|
|
_("Detach from Project"),
|
|
|
|
wxYES_NO | wxICON_QUESTION,
|
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if (wxYES == iAnswer) {
|
2006-07-31 13:59:21 +00:00
|
|
|
pDoc->ProjectDetach(indexOfProj);
|
2006-10-31 15:27:00 +00:00
|
|
|
pComp->UpdateProjectArray();
|
2006-07-20 17:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-09-15 16:47:04 +00:00
|
|
|
void StatImageLoader::LoadStatIcon(wxBitmap& image) {
|
2006-07-05 21:36:56 +00:00
|
|
|
int width = image.GetWidth();
|
|
|
|
int height = image.GetHeight();
|
2006-10-30 03:41:32 +00:00
|
|
|
Bitmap = wxBitmap(image);
|
2006-07-05 21:36:56 +00:00
|
|
|
SetSize(width, height);
|
2006-08-26 04:17:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-31 18:43:55 +00:00
|
|
|
std::string StatImageLoader::GetProjectIconLoc() {
|
|
|
|
char urlDirectory[256];
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
PROJECT* project = pDoc->state.lookup_project(m_prjUrl);
|
|
|
|
url_to_project_dir((char*)project->master_url.c_str() ,urlDirectory);
|
2006-12-20 00:05:12 +00:00
|
|
|
return (std::string)urlDirectory + "/stat_icon";
|
2006-10-31 18:43:55 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-10-27 02:08:55 +00:00
|
|
|
void StatImageLoader::LoadImage() {
|
|
|
|
std::string dirProjectGraphic;
|
|
|
|
|
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
2006-08-26 04:17:56 +00:00
|
|
|
|
|
|
|
char defaultIcnPath[256];
|
2006-10-31 18:43:55 +00:00
|
|
|
if(boinc_resolve_filename(GetProjectIconLoc().c_str(), defaultIcnPath, sizeof(defaultIcnPath)) == 0){
|
2006-09-15 16:47:04 +00:00
|
|
|
wxBitmap* btmpStatIcn = new wxBitmap();
|
2006-12-20 00:05:12 +00:00
|
|
|
if ( btmpStatIcn->LoadFile(wxString(defaultIcnPath,wxConvUTF8), wxBITMAP_TYPE_ANY) ) {
|
2006-09-15 16:47:04 +00:00
|
|
|
LoadStatIcon(*btmpStatIcn);
|
2006-08-26 04:17:56 +00:00
|
|
|
} else {
|
2006-10-27 02:08:55 +00:00
|
|
|
LoadStatIcon(*pSkinSimple->GetProjectImage()->GetBitmap());
|
2006-08-26 04:17:56 +00:00
|
|
|
}
|
2006-10-27 02:08:55 +00:00
|
|
|
delete btmpStatIcn;
|
2006-08-26 04:17:56 +00:00
|
|
|
}else{
|
2006-10-27 02:08:55 +00:00
|
|
|
LoadStatIcon(*pSkinSimple->GetProjectImage()->GetBitmap());
|
2006-08-26 04:17:56 +00:00
|
|
|
}
|
2006-10-27 02:08:55 +00:00
|
|
|
}
|
|
|
|
|
2006-07-05 21:36:56 +00:00
|
|
|
|
2006-10-16 20:46:57 +00:00
|
|
|
void StatImageLoader::ReloadProjectSpecificIcon() {
|
2006-08-26 04:17:56 +00:00
|
|
|
char defaultIcnPath[256];
|
2006-10-16 20:46:57 +00:00
|
|
|
// Only update if it is project specific is found
|
2006-10-31 18:43:55 +00:00
|
|
|
if(boinc_resolve_filename(GetProjectIconLoc().c_str(), defaultIcnPath, sizeof(defaultIcnPath)) == 0){
|
2006-09-15 16:47:04 +00:00
|
|
|
wxBitmap* btmpStatIcn = new wxBitmap();
|
2006-12-20 00:05:12 +00:00
|
|
|
if ( btmpStatIcn->LoadFile(wxString(defaultIcnPath,wxConvUTF8), wxBITMAP_TYPE_ANY) ) {
|
2006-09-15 16:47:04 +00:00
|
|
|
LoadStatIcon(*btmpStatIcn);
|
2006-10-16 20:46:57 +00:00
|
|
|
RebuildMenu();
|
2006-08-26 04:17:56 +00:00
|
|
|
Refresh();
|
|
|
|
Update();
|
|
|
|
}
|
2006-10-27 02:08:55 +00:00
|
|
|
delete btmpStatIcn;
|
2006-08-26 04:17:56 +00:00
|
|
|
}
|
2006-10-16 20:46:57 +00:00
|
|
|
}
|
2006-09-08 21:48:06 +00:00
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-10-16 20:46:57 +00:00
|
|
|
void StatImageLoader::UpdateInterface() {
|
2006-09-08 21:48:06 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
PROJECT* project = pDoc->state.lookup_project(m_prjUrl);
|
|
|
|
|
2006-10-16 20:46:57 +00:00
|
|
|
// Check to see if we need to reload the stat icon
|
|
|
|
if ( project > NULL && project->project_files_downloaded_time > project_files_downloaded_time ) {
|
|
|
|
ReloadProjectSpecificIcon();
|
|
|
|
project_files_downloaded_time = project->project_files_downloaded_time;
|
2006-08-26 04:17:56 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 20:46:57 +00:00
|
|
|
// Check to see if we need to rebuild the hoover and menu
|
|
|
|
if ( project > NULL && project->last_rpc_time > project_last_rpc_time ) {
|
|
|
|
RebuildMenu();
|
|
|
|
BuildUserStatToolTip();
|
|
|
|
project_last_rpc_time = project->last_rpc_time;
|
|
|
|
}
|
2006-09-08 21:48:06 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 03:41:32 +00:00
|
|
|
|
2006-07-21 08:23:26 +00:00
|
|
|
void StatImageLoader::OnPaint(wxPaintEvent& WXUNUSED(event))
|
2006-07-05 21:36:56 +00:00
|
|
|
{
|
2006-10-30 03:41:32 +00:00
|
|
|
wxPaintDC dc(this);
|
|
|
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
|
|
|
if(Bitmap.Ok()) {
|
|
|
|
dc.DrawBitmap(Bitmap, 0, 0);
|
|
|
|
}
|
2006-07-05 21:36:56 +00:00
|
|
|
}
|