2006-07-05 21:36:56 +00:00
|
|
|
#include "stdwx.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "BOINCGUIApp.h"
|
|
|
|
#include "sg_StatImageLoader.h"
|
2006-07-10 13:41:10 +00:00
|
|
|
#include "BOINCBaseFrame.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-08-26 04:17:56 +00:00
|
|
|
#define ID_CHECKFORPROJECTICONDOWNLOADED 13001
|
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-07-10 13:41:10 +00:00
|
|
|
};
|
2006-07-05 21:36:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(StatImageLoader, wxWindow)
|
|
|
|
EVT_PAINT(StatImageLoader::OnPaint)
|
|
|
|
EVT_LEFT_DOWN(StatImageLoader::PopUpMenu)
|
2006-07-10 13:41:10 +00:00
|
|
|
EVT_MENU(WEBSITE_URL_MENU_ID,StatImageLoader::OnMenuLinkClicked)
|
2006-07-10 17:47:21 +00:00
|
|
|
EVT_MENU(WEBSITE_URL_MENU_ID_REMOVE_PROJECT,StatImageLoader::OnMenuLinkClicked)
|
2006-08-26 04:17:56 +00:00
|
|
|
EVT_TIMER(ID_CHECKFORPROJECTICONDOWNLOADED, StatImageLoader::CheckForProjectIconDownloaded)
|
2006-07-05 21:36:56 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2006-08-07 15:33:03 +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-07-10 13:41:10 +00:00
|
|
|
CreateMenu();
|
2006-07-05 21:36:56 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
bool menuPoped = PopupMenu(statPopUpMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatImageLoader::CreateMenu()
|
|
|
|
{
|
2006-07-10 13:41:10 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2006-07-05 21:36:56 +00:00
|
|
|
wxASSERT(pDoc);
|
|
|
|
|
2006-07-20 17:57:23 +00:00
|
|
|
appSkin = SkinClass::Instance();
|
|
|
|
|
2006-07-11 23:19:53 +00:00
|
|
|
PROJECT* project = pDoc->state.lookup_project(m_prjUrl);
|
2006-08-26 04:17:56 +00:00
|
|
|
size_t urlCount = project->gui_urls.size();
|
2006-07-05 21:36:56 +00:00
|
|
|
|
|
|
|
// create pop up menu
|
|
|
|
statPopUpMenu = new wxMenu(wxSIMPLE_BORDER);
|
|
|
|
|
2006-08-26 04:17:56 +00:00
|
|
|
for(unsigned int i = 0; i < urlCount; i++){
|
2006-07-10 13:41:10 +00:00
|
|
|
wxMenuItem *urlItem = new wxMenuItem(statPopUpMenu, WEBSITE_URL_MENU_ID + i,wxString(project->gui_urls[i].name.c_str(), wxConvUTF8));
|
2006-07-05 21:36:56 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
urlItem->SetBackgroundColour(appSkin->GetAppBgCol());
|
|
|
|
#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
|
|
|
|
|
|
|
statPopUpMenu->AppendSeparator();
|
|
|
|
wxMenuItemList menuList = statPopUpMenu->GetMenuItems();
|
|
|
|
//wxMenuItem* separ = statPopUpMenu->FindItemByPosition(i);
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
menuList[statPopUpMenu->GetMenuItemCount()-1]->SetBackgroundColour(wxColour("RED"));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxMenuItem *urlItem = new wxMenuItem(statPopUpMenu, WEBSITE_URL_MENU_ID_REMOVE_PROJECT,wxT("Remove Project"));
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
urlItem->SetBackgroundColour(appSkin->GetAppBgCol());
|
|
|
|
#endif
|
|
|
|
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
|
|
|
//
|
|
|
|
/*
|
|
|
|
wxBitmap *btmTellFriend = new wxBitmap();
|
|
|
|
btmTellFriend->LoadFile("skins/default/graphic/micnTellFriend.png",wxBITMAP_TYPE_PNG);
|
|
|
|
itmTellFriend->SetBitmap(*btmTellFriend);
|
|
|
|
*/
|
|
|
|
}
|
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
|
|
|
wxObject *m_wxBtnObj = event.GetEventObject();
|
|
|
|
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-07-10 17:47:21 +00:00
|
|
|
}else{
|
|
|
|
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
|
|
|
|
2006-07-10 17:47:21 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxDynamicCast(m_parent->GetParent(),CBOINCBaseFrame);
|
|
|
|
wxASSERT(pFrame);
|
|
|
|
wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
|
|
|
|
pFrame->ExecuteBrowserLink(project->gui_urls[menuId].url.c_str());
|
|
|
|
}
|
2006-07-10 13:41:10 +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;
|
|
|
|
int prjCount = pDoc->GetProjectCount();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// PROJECT* project = pDoc->project(m_ProjIconIndex);
|
|
|
|
//project->get_name(strProjectName);
|
2006-07-20 17:57:23 +00:00
|
|
|
|
|
|
|
strMessage.Printf(
|
|
|
|
_("Are you sure you want to detach from project '%s'?"),
|
|
|
|
strProjectName.c_str()
|
|
|
|
);
|
|
|
|
|
|
|
|
iAnswer = ::wxMessageBox(
|
|
|
|
strMessage,
|
|
|
|
_("Detach from Project"),
|
|
|
|
wxYES_NO | wxICON_QUESTION,
|
|
|
|
this
|
|
|
|
);
|
|
|
|
|
|
|
|
if (wxYES == iAnswer) {
|
2006-07-31 13:59:21 +00:00
|
|
|
pDoc->ProjectDetach(indexOfProj);
|
2006-07-24 22:10:28 +00:00
|
|
|
pComp->RemoveProject(m_prjUrl);
|
2006-07-20 17:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-26 04:17:56 +00:00
|
|
|
void StatImageLoader::LoadStatIcon(const wxImage& image) {
|
2006-07-05 21:36:56 +00:00
|
|
|
Bitmap = wxBitmap();//delete existing bitmap since we are loading new one
|
|
|
|
int width = image.GetWidth();
|
|
|
|
int height = image.GetHeight();
|
|
|
|
Bitmap = wxBitmap(image);
|
|
|
|
SetSize(width, height);
|
2006-08-26 04:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StatImageLoader::LoadImage(std::string project_icon, const wxImage& defaultImage)
|
|
|
|
{
|
|
|
|
char defaultIcnPath[256];
|
|
|
|
bool defaultUsed = true;
|
|
|
|
if(boinc_resolve_filename(project_icon.c_str(), defaultIcnPath, sizeof(defaultIcnPath)) == 0){
|
|
|
|
wxImage* g_statIcn = new wxImage();
|
|
|
|
if ( g_statIcn->LoadFile(defaultIcnPath, wxBITMAP_TYPE_PNG) ) {
|
|
|
|
LoadStatIcon(g_statIcn);
|
|
|
|
defaultUsed = false;
|
|
|
|
} else {
|
|
|
|
// TODO - need to set a timer to switch this to load the real graphics once they are downloaded
|
|
|
|
LoadStatIcon(defaultImage);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
LoadStatIcon(defaultImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( defaultUsed ) {
|
|
|
|
projectIcon = project_icon;
|
|
|
|
numReloadTries = 80; // check for 10 minutes
|
|
|
|
attemptToReloadTimer = new wxTimer(this, ID_CHECKFORPROJECTICONDOWNLOADED);
|
|
|
|
attemptToReloadTimer->Start(7500);
|
|
|
|
}
|
2006-07-05 21:36:56 +00:00
|
|
|
}
|
|
|
|
|
2006-08-26 04:17:56 +00:00
|
|
|
void StatImageLoader::CheckForProjectIconDownloaded(wxTimerEvent& WXUNUSED(event)) {
|
|
|
|
char defaultIcnPath[256];
|
|
|
|
bool success = false;
|
|
|
|
if(boinc_resolve_filename(projectIcon.c_str(), defaultIcnPath, sizeof(defaultIcnPath)) == 0){
|
|
|
|
wxImage* g_statIcn = new wxImage();
|
|
|
|
if ( g_statIcn->LoadFile(defaultIcnPath, wxBITMAP_TYPE_PNG) ) {
|
|
|
|
LoadStatIcon(g_statIcn);
|
|
|
|
success = true;
|
|
|
|
Refresh();
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Try numReloadTries times (set in constructor) or until success
|
|
|
|
if ( success || numReloadTries-- <=0 ) {
|
|
|
|
attemptToReloadTimer->Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-21 08:23:26 +00:00
|
|
|
void StatImageLoader::OnPaint(wxPaintEvent& WXUNUSED(event))
|
2006-07-05 21:36:56 +00:00
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
if(Bitmap.Ok())
|
|
|
|
{
|
|
|
|
dc.DrawBitmap(Bitmap, 0, 0);
|
|
|
|
}
|
|
|
|
}
|