2011-01-27 14:36:49 +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/>.
|
|
|
|
|
|
|
|
#define TESTBIGICONPOPUP 0
|
|
|
|
|
2011-11-24 11:10:07 +00:00
|
|
|
#define SORTPROJECTLIST 1
|
|
|
|
|
2011-01-27 14:36:49 +00:00
|
|
|
#include "stdwx.h"
|
|
|
|
#include "Events.h"
|
|
|
|
#include "app_ipc.h"
|
|
|
|
#include "BOINCGUIApp.h"
|
|
|
|
#include "MainDocument.h"
|
|
|
|
#include "SkinManager.h"
|
|
|
|
#include "wizardex.h"
|
|
|
|
#include "BOINCBaseWizard.h"
|
|
|
|
#include "WizardAttach.h"
|
|
|
|
#include "sg_ProjectPanel.h"
|
2015-11-23 19:45:40 +00:00
|
|
|
#include "str_replace.h"
|
2011-01-27 14:36:49 +00:00
|
|
|
#if TESTBIGICONPOPUP
|
|
|
|
#include "test/sah_40.xpm"
|
|
|
|
#include "test/einstein_icon.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CSimpleProjectPanel, CSimplePanelBase)
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(CSimpleProjectPanel, CSimplePanelBase)
|
2014-03-19 01:16:53 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
EVT_CHOICE(ID_SGPROJECTSELECTOR, CSimpleProjectPanel::OnProjectSelection)
|
|
|
|
#else
|
2014-03-18 20:08:55 +00:00
|
|
|
EVT_COMBOBOX(ID_SGPROJECTSELECTOR, CSimpleProjectPanel::OnProjectSelection)
|
2014-03-19 01:16:53 +00:00
|
|
|
#endif
|
2011-01-27 14:36:49 +00:00
|
|
|
EVT_BUTTON(ID_ADDROJECTBUTTON, CSimpleProjectPanel::OnAddProject)
|
|
|
|
#if TESTBIGICONPOPUP
|
|
|
|
EVT_BUTTON(ID_PROJECTWEBSITESBUTTON, CSimpleProjectPanel::OnProjectWebSiteButton)
|
|
|
|
EVT_BUTTON(ID_PROJECTCOMMANDBUTTON, CSimpleProjectPanel::OnProjectCommandButton)
|
|
|
|
#endif
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
#if TESTBIGICONPOPUP
|
|
|
|
static wxString tempArray[] = {_T("String1"), _T("String2"), _T("String3"), _T("String4") };
|
|
|
|
static wxBitmap bmArray[3];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CSimpleProjectPanel::CSimpleProjectPanel() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CSimpleProjectPanel::CSimpleProjectPanel( wxWindow* parent ) :
|
|
|
|
CSimplePanelBase( parent )
|
|
|
|
{
|
|
|
|
wxSize sz;
|
|
|
|
wxString str = wxEmptyString;
|
|
|
|
wxWindowDC dc(this);
|
|
|
|
|
|
|
|
m_UsingAccountManager = -1; // Force action the first time
|
|
|
|
m_CurrentSelectedProjectURL[0] = '\0';
|
|
|
|
|
|
|
|
m_sAddProjectString = _("Add Project");
|
|
|
|
m_sSynchronizeString = _("Synchronize");
|
2011-09-11 18:55:19 +00:00
|
|
|
m_sTotalWorkDoneString = _("Work done for this project");
|
2011-01-27 14:36:49 +00:00
|
|
|
|
|
|
|
m_sAddProjectToolTip = _("Volunteer for any or all of 30+ projects in many areas of science");
|
|
|
|
m_sSynchronizeToolTip = _("Synchronize projects with account manager system");
|
|
|
|
|
|
|
|
m_GotBGBitMap = false; // Can't be made until parent has been laid out.
|
2012-12-10 12:29:14 +00:00
|
|
|
SetForegroundColour(*wxBLACK);
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
wxBoxSizer* bSizer1;
|
|
|
|
bSizer1 = new wxBoxSizer( wxVERTICAL );
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
wxBoxSizer* bSizer2;
|
|
|
|
bSizer2 = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
2014-08-25 13:24:54 +00:00
|
|
|
bSizer1->AddSpacer(ADJUSTFORYDPI(5));
|
2012-12-10 12:29:14 +00:00
|
|
|
m_myProjectsLabel = new CTransparentStaticText( this, wxID_ANY, _("Projects:"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
m_myProjectsLabel->Wrap( -1 );
|
2014-08-25 13:24:54 +00:00
|
|
|
bSizer2->Add( m_myProjectsLabel, 0, wxRIGHT, ADJUSTFORXDPI(5) );
|
2011-01-27 14:36:49 +00:00
|
|
|
bSizer2->AddStretchSpacer();
|
|
|
|
|
|
|
|
int addProjectWidth, synchronizeWidth, y;
|
|
|
|
GetTextExtent(m_sAddProjectString, &addProjectWidth, &y);
|
|
|
|
GetTextExtent(m_sSynchronizeString, &synchronizeWidth, &y);
|
2013-02-22 07:43:44 +00:00
|
|
|
m_TaskAddProjectButton = new CTransparentButton( this, ID_ADDROJECTBUTTON,
|
2011-09-11 18:55:19 +00:00
|
|
|
(addProjectWidth > synchronizeWidth) ? m_sAddProjectString : m_sSynchronizeString,
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0
|
|
|
|
);
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2020-10-29 22:18:13 +00:00
|
|
|
bSizer2->Add( m_TaskAddProjectButton, 0, wxRIGHT | wxEXPAND, SIDEMARGINS );
|
2014-08-25 13:24:54 +00:00
|
|
|
bSizer1->Add( bSizer2, 0, wxEXPAND | wxTOP | wxLEFT, ADJUSTFORXDPI(10) );
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2011-05-14 01:57:15 +00:00
|
|
|
#ifndef __WXMAC__
|
2014-08-25 13:24:54 +00:00
|
|
|
bSizer1->AddSpacer(ADJUSTFORYDPI(5));
|
2011-01-27 14:36:49 +00:00
|
|
|
#endif
|
2012-12-10 12:29:14 +00:00
|
|
|
|
2011-01-27 14:36:49 +00:00
|
|
|
#if TESTBIGICONPOPUP
|
2012-12-10 12:29:14 +00:00
|
|
|
m_ProjectSelectionCtrl = new CBOINCBitmapComboBox( this, ID_SGPROJECTSELECTOR, wxT(""), wxDefaultPosition, wxSize(-1, 42), 4, tempArray, wxCB_READONLY );
|
2011-01-27 14:36:49 +00:00
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
bmArray[0] = *pSkinSimple->GetProjectImage()->GetBitmap();
|
|
|
|
m_ProjectSelectionCtrl->SetItemBitmap(0, bmArray[0]);
|
|
|
|
bmArray[1] = wxBitmap((const char**)sah_40_xpm);
|
|
|
|
m_ProjectSelectionCtrl->SetItemBitmap(1, bmArray[1]);
|
|
|
|
bmArray[2] = wxBitmap((const char**)einstein_icon_xpm);
|
|
|
|
m_ProjectSelectionCtrl->SetItemBitmap(3, bmArray[2]);
|
|
|
|
// m_ProjectSelectionCtrl->SetStringSelection(tempArray[1]);
|
|
|
|
m_ProjectSelectionCtrl->SetSelection(1);
|
|
|
|
#else
|
2012-12-10 12:29:14 +00:00
|
|
|
m_ProjectSelectionCtrl = new CBOINCBitmapComboBox( this, ID_SGPROJECTSELECTOR, wxT(""), wxDefaultPosition, wxSize(-1, 42), 0, NULL, wxCB_READONLY);
|
2011-01-27 14:36:49 +00:00
|
|
|
#endif
|
|
|
|
// TODO: Might want better wording for Project Selection Combo Box tooltip
|
|
|
|
str = _("Select a project to access with the controls below");
|
|
|
|
m_ProjectSelectionCtrl->SetToolTip(str);
|
2012-12-10 12:29:14 +00:00
|
|
|
bSizer1->Add( m_ProjectSelectionCtrl, 0, wxLEFT | wxRIGHT | wxEXPAND, SIDEMARGINS );
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2011-05-14 01:57:15 +00:00
|
|
|
#ifndef __WXMAC__
|
2014-08-25 13:24:54 +00:00
|
|
|
bSizer1->AddSpacer(ADJUSTFORYDPI(8));
|
2011-01-27 14:36:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Make sure m_TotalCreditValue string is large enough
|
2011-01-30 05:55:56 +00:00
|
|
|
m_fDisplayedCredit = 9999999999.99;
|
2013-06-03 17:25:41 +00:00
|
|
|
str.Printf(wxT("%s: %.0f"), m_sTotalWorkDoneString.c_str(), m_fDisplayedCredit);
|
2012-12-10 12:29:14 +00:00
|
|
|
m_TotalCreditValue = new CTransparentStaticText( this, wxID_ANY, str, wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE );
|
|
|
|
m_TotalCreditValue->Wrap( -1 );
|
|
|
|
|
|
|
|
bSizer1->Add( m_TotalCreditValue, 0, wxLEFT | wxRIGHT | wxEXPAND, SIDEMARGINS );
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2014-08-25 13:24:54 +00:00
|
|
|
bSizer1->AddSpacer(ADJUSTFORYDPI(5));
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
wxBoxSizer* bSizer3;
|
|
|
|
bSizer3 = new wxBoxSizer( wxHORIZONTAL );
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
m_ProjectWebSitesButton = new CSimpleProjectWebSitesPopupButton( this, ID_PROJECTWEBSITESBUTTON, _("Project Web Pages"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
bSizer3->Add( m_ProjectWebSitesButton, 0, wxEXPAND | wxALIGN_LEFT, 0 );
|
2011-01-27 14:36:49 +00:00
|
|
|
bSizer3->AddStretchSpacer();
|
|
|
|
|
|
|
|
m_ProjectCommandsButton = new CSimpleProjectCommandPopupButton( this, ID_PROJECTCOMMANDBUTTON, _("Project Commands"), wxDefaultPosition, wxDefaultSize, 0 );
|
2020-10-29 22:18:13 +00:00
|
|
|
bSizer3->Add( m_ProjectCommandsButton, 0, wxEXPAND, 0 );
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
bSizer1->Add( bSizer3, 0, wxLEFT | wxRIGHT | wxEXPAND, SIDEMARGINS );
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2014-08-25 13:24:54 +00:00
|
|
|
bSizer1->AddSpacer(ADJUSTFORYDPI(10));
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2014-08-30 11:15:31 +00:00
|
|
|
// Temporarily insert a dummy entry so sizer can
|
|
|
|
// get correct height of m_ProjectSelectionCtrl
|
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
wxBitmap* defaultBM = pSkinSimple->GetProjectImage()->GetBitmap();
|
|
|
|
m_ProjectSelectionCtrl->Insert("", *defaultBM, 0, (void*)NULL);
|
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
this->SetSizer( bSizer1 );
|
|
|
|
this->Layout();
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2014-08-30 11:15:31 +00:00
|
|
|
// Remove the dummy entry
|
|
|
|
m_ProjectSelectionCtrl->Delete(0);
|
|
|
|
|
2011-05-13 12:24:20 +00:00
|
|
|
m_TaskAddProjectButton->SetToolTip(wxEmptyString);
|
2011-01-27 14:36:49 +00:00
|
|
|
m_TaskAddProjectButton->Disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CSimpleProjectPanel::~CSimpleProjectPanel()
|
|
|
|
{
|
2011-10-25 11:19:42 +00:00
|
|
|
ProjectSelectionData *selData;
|
|
|
|
int count = m_ProjectSelectionCtrl->GetCount();
|
2012-12-10 12:29:14 +00:00
|
|
|
for(int j = count-1; j >=0; --j) {
|
2011-10-25 11:19:42 +00:00
|
|
|
selData = (ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(j);
|
|
|
|
delete selData;
|
2011-11-22 00:40:07 +00:00
|
|
|
// Indicate to Clear() we have cleaned up the Selection Data
|
2011-10-25 11:19:42 +00:00
|
|
|
m_ProjectSelectionCtrl->SetClientData(j, NULL);
|
2012-12-10 12:29:14 +00:00
|
|
|
}
|
2011-10-25 11:19:42 +00:00
|
|
|
m_ProjectSelectionCtrl->Clear();
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ProjectSelectionData* CSimpleProjectPanel::GetProjectSelectionData() {
|
|
|
|
int count = m_ProjectSelectionCtrl->GetCount();
|
|
|
|
if (count <= 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int n = m_ProjectSelectionCtrl->GetSelection();
|
|
|
|
return (ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CSimpleProjectPanel::UpdateInterface() {
|
2011-05-16 09:34:08 +00:00
|
|
|
int n, count = -1;
|
2011-01-27 14:36:49 +00:00
|
|
|
bool b_needMenuRebuild = false;
|
|
|
|
wxString str = wxEmptyString;
|
|
|
|
wxString projName = wxEmptyString;
|
2012-12-10 12:29:14 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2011-01-27 14:36:49 +00:00
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
|
|
|
|
// Should we display the synchronize button instead of the
|
|
|
|
// attach to project button?
|
|
|
|
if ( pDoc->IsConnected() ) {
|
|
|
|
CC_STATUS status;
|
|
|
|
int is_acct_mgr_detected = 0;
|
|
|
|
|
|
|
|
pDoc->GetCoreClientStatus(status);
|
|
|
|
|
|
|
|
if (pDoc->m_iAcct_mgr_info_rpc_result == 0) {
|
|
|
|
// We use an integer rather than a bool to force action the first time
|
|
|
|
is_acct_mgr_detected = pDoc->ami.acct_mgr_url.size() ? 1 : 0;
|
|
|
|
|
2011-05-13 12:24:20 +00:00
|
|
|
if ((m_UsingAccountManager != is_acct_mgr_detected) || (!m_TaskAddProjectButton->IsEnabled())) {
|
2011-01-27 14:36:49 +00:00
|
|
|
m_UsingAccountManager = is_acct_mgr_detected;
|
|
|
|
if (is_acct_mgr_detected) {
|
|
|
|
m_TaskAddProjectButton->SetLabel(m_sSynchronizeString);
|
2012-12-10 12:29:14 +00:00
|
|
|
m_TaskAddProjectButton->Enable();
|
|
|
|
m_TaskAddProjectButton->SetToolTip(m_sSynchronizeToolTip);
|
2011-01-27 14:36:49 +00:00
|
|
|
} else {
|
|
|
|
m_TaskAddProjectButton->SetLabel(m_sAddProjectString);
|
|
|
|
if (!status.disallow_attach) {
|
|
|
|
m_TaskAddProjectButton->Enable();
|
2011-05-11 00:50:52 +00:00
|
|
|
m_TaskAddProjectButton->SetToolTip(m_sAddProjectToolTip);
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-11 00:50:52 +00:00
|
|
|
this->Layout();
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-05-13 12:24:20 +00:00
|
|
|
m_TaskAddProjectButton->Disable();
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateProjectList();
|
|
|
|
|
|
|
|
count = m_ProjectSelectionCtrl->GetCount();
|
2011-05-16 09:34:08 +00:00
|
|
|
}
|
|
|
|
if (count > 0) {
|
|
|
|
n = m_ProjectSelectionCtrl->GetSelection();
|
|
|
|
if ((n < 0) || (n > count -1)) {
|
|
|
|
m_ProjectSelectionCtrl->SetSelection(0);
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if we need to rebuild the menu
|
|
|
|
char* ctrl_url = ((ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(n))->project_url;
|
|
|
|
if (strcmp(m_CurrentSelectedProjectURL, ctrl_url)) {
|
|
|
|
b_needMenuRebuild = true;
|
2015-11-23 19:45:40 +00:00
|
|
|
strlcpy(m_CurrentSelectedProjectURL, ctrl_url, sizeof(m_CurrentSelectedProjectURL));
|
2011-05-16 09:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PROJECT* project = pDoc->state.lookup_project(ctrl_url);
|
|
|
|
if ( project != NULL && project->last_rpc_time > m_Project_last_rpc_time ) {
|
|
|
|
b_needMenuRebuild = true;
|
|
|
|
m_Project_last_rpc_time = project->last_rpc_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b_needMenuRebuild) {
|
|
|
|
m_ProjectWebSitesButton->RebuildMenu();
|
|
|
|
}
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2011-05-16 09:34:08 +00:00
|
|
|
m_ProjectWebSitesButton->Enable();
|
|
|
|
m_ProjectCommandsButton->Enable();
|
|
|
|
|
|
|
|
if (m_fDisplayedCredit != project->user_total_credit) {
|
2015-08-26 19:50:11 +00:00
|
|
|
str.Printf(wxT("%s: %s"),
|
|
|
|
m_sTotalWorkDoneString.c_str(),
|
2015-09-22 18:22:07 +00:00
|
|
|
format_number(project->user_total_credit, 0)
|
2015-08-26 19:50:11 +00:00
|
|
|
);
|
2011-05-16 09:34:08 +00:00
|
|
|
UpdateStaticText(&m_TotalCreditValue, str);
|
|
|
|
m_TotalCreditValue->SetName(str); // For accessibility on Windows
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
2011-05-16 09:34:08 +00:00
|
|
|
projName = m_ProjectSelectionCtrl->GetStringSelection();
|
2013-11-17 20:29:11 +00:00
|
|
|
str.Printf(_("Pop up a menu of web sites for project %s"), projName.c_str());
|
2011-05-16 09:34:08 +00:00
|
|
|
m_ProjectWebSitesButton->SetToolTip(str);
|
|
|
|
str.Printf(_("Pop up a menu of commands to apply to project %s"), projName.c_str());
|
|
|
|
m_ProjectCommandsButton->SetToolTip(str);
|
|
|
|
} else {
|
|
|
|
m_ProjectWebSitesButton->Disable();
|
|
|
|
m_ProjectCommandsButton->Disable();
|
|
|
|
m_CurrentSelectedProjectURL[0] = '\0';
|
|
|
|
m_fDisplayedCredit = -1.0;
|
|
|
|
UpdateStaticText(&m_TotalCreditValue, wxEmptyString);
|
|
|
|
m_TotalCreditValue->SetName(wxEmptyString); // For accessibility on Windows
|
|
|
|
m_ProjectWebSitesButton->SetToolTip(wxEmptyString);
|
|
|
|
m_ProjectCommandsButton->SetToolTip(wxEmptyString);
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-26 10:16:16 +00:00
|
|
|
void CSimpleProjectPanel::ReskinInterface() {
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CSimpleProjectPanel::ReskinInterface - Function Begin"));
|
|
|
|
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
ProjectSelectionData* selData;
|
|
|
|
PROJECT* project;
|
|
|
|
char* ctrl_url;
|
|
|
|
|
|
|
|
CSimplePanelBase::ReskinInterface();
|
|
|
|
|
|
|
|
// Check to see if we need to reload the project icon
|
|
|
|
int ctrlCount = m_ProjectSelectionCtrl->GetCount();
|
|
|
|
for(int j=0; j<ctrlCount; j++) {
|
|
|
|
selData = (ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(j);
|
|
|
|
ctrl_url = selData->project_url;
|
|
|
|
project = pDoc->state.lookup_project(ctrl_url);
|
|
|
|
wxBitmap* projectBM = GetProjectSpecificBitmap(ctrl_url);
|
|
|
|
m_ProjectSelectionCtrl->SetItemBitmap(j, *projectBM);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CSimpleProjectPanel::ReskinInterface - Function Begin"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-04 18:44:16 +00:00
|
|
|
void CSimpleProjectPanel::OnAddProject(wxCommandEvent& event) {
|
2011-01-27 14:36:49 +00:00
|
|
|
if (m_UsingAccountManager) {
|
|
|
|
OnWizardUpdate();
|
|
|
|
} else {
|
2015-04-04 18:44:16 +00:00
|
|
|
OnWizardAttach(event);
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-04 18:44:16 +00:00
|
|
|
void CSimpleProjectPanel::OnWizardAttach(wxCommandEvent& event) {
|
2011-01-27 14:36:49 +00:00
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CProjectsComponent::OnWizardAttach - Function Begin"));
|
|
|
|
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2012-12-10 12:29:14 +00:00
|
|
|
CSimpleGUIPanel* pPanel = wxDynamicCast(GetParent(), CSimpleGUIPanel);
|
2011-01-27 14:36:49 +00:00
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(pPanel);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
if (!pDoc->IsUserAuthorized()) return;
|
|
|
|
|
|
|
|
if (!pDoc->IsConnected()) return;
|
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
pPanel->SetDlgOpen(true);
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2015-04-04 18:44:16 +00:00
|
|
|
pPanel->OnProjectsAttachToProject(event);
|
2012-12-10 12:29:14 +00:00
|
|
|
// btnAddProj->Refresh();
|
2011-01-27 14:36:49 +00:00
|
|
|
|
|
|
|
pPanel->SetDlgOpen(false);
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CProjectsComponent::OnWizardAttach - Function End"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CSimpleProjectPanel::OnWizardUpdate() {
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CProjectsComponent::OnWizardUpdate - Function Begin"));
|
|
|
|
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2012-12-10 12:29:14 +00:00
|
|
|
CSimpleGUIPanel* pPanel = wxDynamicCast(GetParent(), CSimpleGUIPanel);
|
2011-01-27 14:36:49 +00:00
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(pPanel);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
if (!pDoc->IsUserAuthorized()) return;
|
|
|
|
|
|
|
|
if (!pDoc->IsConnected()) return;
|
|
|
|
|
|
|
|
pPanel->SetDlgOpen(true);
|
|
|
|
|
|
|
|
CWizardAttach* pWizard = new CWizardAttach(this);
|
|
|
|
|
|
|
|
pWizard->SyncToAccountManager();
|
|
|
|
|
|
|
|
if (pWizard)
|
|
|
|
pWizard->Destroy();
|
|
|
|
|
|
|
|
// btnSynchronize->Refresh();
|
|
|
|
|
|
|
|
pPanel->SetDlgOpen(false);
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CProjectsComponent::OnWizardUpdate - Function End"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if TESTBIGICONPOPUP
|
|
|
|
void CSimpleProjectPanel::OnProjectWebSiteButton(wxCommandEvent& /*event*/) {
|
|
|
|
m_ProjectSelectionCtrl->Delete(0); /*** CAF *** FOR TESTING ONLY ***/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CSimpleProjectPanel::OnProjectCommandButton(wxCommandEvent& /*event*/) {
|
|
|
|
/*** CAF *** FOR TESTING ONLY ***/
|
|
|
|
static int i = 1;
|
|
|
|
wxString s;
|
|
|
|
|
|
|
|
if (++i > 8) i = 0;
|
|
|
|
int sel = i % 3;
|
|
|
|
// m_ProjectSelectionCtrl->SetStringSelection(tempArray[sel]);
|
|
|
|
m_ProjectSelectionCtrl->SetSelection(sel);
|
|
|
|
#if 0 //TESTBIGICONPOPUP
|
|
|
|
wxRect r;
|
|
|
|
wxWindowDC dc(this);
|
|
|
|
r = m_ProjectSelectionCtrl->GetRect();
|
|
|
|
dc.DrawBitmap(bmArray[sel], r.x + 9, r.y, false);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void CSimpleProjectPanel::OnProjectSelection(wxCommandEvent& /*event*/) {
|
|
|
|
UpdateInterface();
|
|
|
|
|
|
|
|
// const int sel = m_ProjectSelectionCtrl->GetSelection();
|
|
|
|
#if 0 //TESTBIGICONPOPUP
|
|
|
|
wxRect r;
|
|
|
|
wxWindowDC dc(this);
|
|
|
|
|
|
|
|
r = m_ProjectSelectionCtrl->GetRect();
|
|
|
|
dc.DrawBitmap(bmArray[sel], r.x + 9, r.y - 10, false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CSimpleProjectPanel::UpdateProjectList() {
|
2012-12-10 12:29:14 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
2011-01-27 14:36:49 +00:00
|
|
|
ProjectSelectionData* selData;
|
|
|
|
PROJECT* project;
|
2019-09-10 10:09:35 +00:00
|
|
|
int oldProjectSelection, newProjectSelection;
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
if ( pDoc->IsConnected() ) {
|
|
|
|
int projCnt = pDoc->GetSimpleProjectCount();
|
2011-01-27 14:36:49 +00:00
|
|
|
int ctrlCount = m_ProjectSelectionCtrl->GetCount();
|
2011-11-24 11:10:07 +00:00
|
|
|
oldProjectSelection = m_ProjectSelectionCtrl->GetSelection();
|
|
|
|
|
2012-12-10 12:29:14 +00:00
|
|
|
// If a new project has been added, figure out which one
|
2019-09-10 10:09:35 +00:00
|
|
|
for(int i=0; i<projCnt; i++) {
|
|
|
|
char* ctrl_url;
|
2011-11-24 11:10:07 +00:00
|
|
|
project = pDoc->state.projects[i];
|
|
|
|
bool found = false;
|
2019-09-10 10:09:35 +00:00
|
|
|
for(int j=0; j<ctrlCount; j++) {
|
2011-11-24 11:10:07 +00:00
|
|
|
ctrl_url = ((ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(j))->project_url;
|
|
|
|
if (!strcmp(project->master_url, ctrl_url)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2018-10-12 04:57:49 +00:00
|
|
|
// add new project
|
|
|
|
//
|
|
|
|
if (!found) {
|
|
|
|
const char* p = project->project_name.c_str();
|
|
|
|
if (strlen(p) == 0) {
|
|
|
|
p = project->master_url;
|
|
|
|
}
|
|
|
|
wxString projname(p, wxConvUTF8);
|
2011-11-24 11:10:07 +00:00
|
|
|
#if SORTPROJECTLIST
|
2019-09-10 10:09:35 +00:00
|
|
|
int alphaOrder,j;
|
2011-11-24 11:10:07 +00:00
|
|
|
for(j = 0; j < ctrlCount; ++j) {
|
|
|
|
alphaOrder = (m_ProjectSelectionCtrl->GetString(j)).CmpNoCase(projname);
|
|
|
|
if (alphaOrder > 0) {
|
|
|
|
break; // Insert the new item here (sorted by item label)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
selData = new ProjectSelectionData;
|
2015-11-23 19:45:40 +00:00
|
|
|
strlcpy(selData->project_url, project->master_url, sizeof(selData->project_url));
|
2011-11-24 11:10:07 +00:00
|
|
|
selData->project_files_downloaded_time = project->project_files_downloaded_time;
|
|
|
|
wxBitmap* projectBM = GetProjectSpecificBitmap(selData->project_url);
|
|
|
|
#if SORTPROJECTLIST
|
|
|
|
if (j < ctrlCount) {
|
|
|
|
m_ProjectSelectionCtrl->Insert(projname, *projectBM, j, (void*)selData);
|
|
|
|
if (j <= oldProjectSelection) {
|
|
|
|
++oldProjectSelection;
|
|
|
|
m_ProjectSelectionCtrl->SetSelection(oldProjectSelection);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2011-01-27 14:36:49 +00:00
|
|
|
m_ProjectSelectionCtrl->Append(projname, *projectBM, (void*)selData);
|
2011-11-24 11:10:07 +00:00
|
|
|
}
|
|
|
|
ctrlCount = m_ProjectSelectionCtrl->GetCount();
|
|
|
|
}
|
|
|
|
}
|
2011-01-27 14:36:49 +00:00
|
|
|
|
2011-11-24 11:10:07 +00:00
|
|
|
newProjectSelection = oldProjectSelection;
|
2011-01-27 14:36:49 +00:00
|
|
|
if ( projCnt < ctrlCount ) {
|
2012-12-10 12:29:14 +00:00
|
|
|
project = NULL;
|
2011-01-27 14:36:49 +00:00
|
|
|
// Check items in descending order so deletion won't change indexes of items yet to be checked
|
2019-09-10 10:09:35 +00:00
|
|
|
for(int j=ctrlCount-1; j>=0; --j) {
|
|
|
|
char* ctrl_url = ((ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(j))->project_url;
|
2012-12-10 12:29:14 +00:00
|
|
|
project = pDoc->state.lookup_project(ctrl_url);
|
|
|
|
if ( project == NULL ) {
|
2011-01-27 14:36:49 +00:00
|
|
|
selData = (ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(j);
|
|
|
|
delete selData;
|
2011-11-22 00:40:07 +00:00
|
|
|
// Indicate to Delete() we have cleaned up the Selection Data
|
|
|
|
m_ProjectSelectionCtrl->SetClientData(j, NULL);
|
2011-01-27 14:36:49 +00:00
|
|
|
m_ProjectSelectionCtrl->Delete(j);
|
2011-11-24 11:10:07 +00:00
|
|
|
if (j == oldProjectSelection) {
|
|
|
|
int newCount = m_ProjectSelectionCtrl->GetCount();
|
|
|
|
if (newProjectSelection < newCount) {
|
|
|
|
// Select the next item if one exists
|
|
|
|
m_ProjectSelectionCtrl->SetSelection(newProjectSelection);
|
|
|
|
} else if (newCount > 0) {
|
|
|
|
// Select the previous item if one exists
|
|
|
|
newProjectSelection = newCount-1;
|
|
|
|
m_ProjectSelectionCtrl->SetSelection(newProjectSelection);
|
|
|
|
} else {
|
|
|
|
newProjectSelection = -1;
|
|
|
|
m_ProjectSelectionCtrl->SetSelection(wxNOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
2012-12-10 12:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-27 14:36:49 +00:00
|
|
|
|
|
|
|
// Check to see if we need to reload the project icon
|
|
|
|
ctrlCount = m_ProjectSelectionCtrl->GetCount();
|
2019-09-10 10:09:35 +00:00
|
|
|
for(int j=0; j<ctrlCount; j++) {
|
2011-07-18 11:29:41 +00:00
|
|
|
selData = (ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(j);
|
2019-09-10 10:09:35 +00:00
|
|
|
char* ctrl_url = selData->project_url;
|
2011-01-27 14:36:49 +00:00
|
|
|
project = pDoc->state.lookup_project(ctrl_url);
|
2015-10-14 07:53:34 +00:00
|
|
|
if ( (project != NULL) && (project->project_files_downloaded_time > selData->project_files_downloaded_time) ) {
|
2011-01-27 14:36:49 +00:00
|
|
|
wxBitmap* projectBM = GetProjectSpecificBitmap(ctrl_url);
|
2011-07-18 11:29:41 +00:00
|
|
|
selData->project_files_downloaded_time = project->project_files_downloaded_time;
|
2011-01-27 14:36:49 +00:00
|
|
|
m_ProjectSelectionCtrl->SetItemBitmap(j, *projectBM);
|
|
|
|
}
|
|
|
|
}
|
2012-12-10 12:29:14 +00:00
|
|
|
}
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CSimpleProjectPanel::GetProjectIconLoc(char* project_url) {
|
2016-02-18 06:53:37 +00:00
|
|
|
char proj_dir[256];
|
2012-12-10 12:29:14 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
PROJECT* project = pDoc->state.lookup_project(project_url);
|
2015-04-08 04:35:56 +00:00
|
|
|
if (!project) return (std::string)"";
|
2016-02-18 06:53:37 +00:00
|
|
|
url_to_project_dir(project->master_url, proj_dir, sizeof(proj_dir));
|
|
|
|
return (std::string)proj_dir + "/stat_icon";
|
2011-01-27 14:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxBitmap* CSimpleProjectPanel::GetProjectSpecificBitmap(char* project_url) {
|
2012-12-10 12:29:14 +00:00
|
|
|
char defaultIcnPath[256];
|
2011-01-27 14:36:49 +00:00
|
|
|
CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();
|
|
|
|
|
|
|
|
wxASSERT(pSkinSimple);
|
|
|
|
|
2013-04-26 10:16:16 +00:00
|
|
|
// Only update it if project specific is found
|
2012-12-10 12:29:14 +00:00
|
|
|
if(boinc_resolve_filename(GetProjectIconLoc(project_url).c_str(), defaultIcnPath, sizeof(defaultIcnPath)) == 0) {
|
2014-08-26 10:56:21 +00:00
|
|
|
wxBitmap* projectBM;
|
2011-10-18 13:47:36 +00:00
|
|
|
wxString strIconPath = wxString(defaultIcnPath,wxConvUTF8);
|
|
|
|
if (wxFile::Exists(strIconPath)) {
|
2021-10-01 06:52:51 +00:00
|
|
|
// wxBitmapComboBox requires all its bitmaps to be the same size
|
|
|
|
// Our "project icon" bitmaps should all be 40 X 40
|
|
|
|
wxImage img = wxImage(strIconPath, wxBITMAP_TYPE_ANY);
|
|
|
|
if (img.IsOk()) {
|
2014-08-26 10:56:21 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
if ((GetXDPIScaling() > 1.05) || (GetYDPIScaling() > 1.05)) {
|
2021-10-01 06:52:51 +00:00
|
|
|
img.Rescale((int) (40*GetXDPIScaling()),
|
|
|
|
(int) (40*GetYDPIScaling()),
|
|
|
|
wxIMAGE_QUALITY_BILINEAR
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ((img.GetHeight() != 40) || (img.GetWidth() == 40)) {
|
|
|
|
img.Rescale(40, 40, wxIMAGE_QUALITY_BILINEAR);
|
2014-08-26 10:56:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
2021-10-01 06:52:51 +00:00
|
|
|
projectBM = new wxBitmap(img);
|
|
|
|
if (projectBM->IsOk()) {
|
2014-08-26 10:56:21 +00:00
|
|
|
return projectBM;
|
|
|
|
}
|
2021-10-01 06:52:51 +00:00
|
|
|
}
|
2011-10-18 13:47:36 +00:00
|
|
|
}
|
2012-12-10 12:29:14 +00:00
|
|
|
}
|
2011-01-27 14:36:49 +00:00
|
|
|
return pSkinSimple->GetProjectImage()->GetBitmap();
|
|
|
|
}
|