Ejemplo n.º 1
0
void CSimpleFrame::OnConnect(CFrameEvent& WXUNUSED(event)) {
    wxLogTrace(wxT("Function Start/End"), wxT("CSimpleFrame::OnConnect - Function Begin"));
    
    CMainDocument*     pDoc = wxGetApp().GetDocument();
    CWizardAttach*     pWizard = NULL;
    wxString strComputer = wxEmptyString;
    wxString strName = wxEmptyString;
    wxString strURL = wxEmptyString;
    wxString strTeamName = wxEmptyString;
    std::string strProjectName;
    std::string strProjectURL;
    std::string strProjectAuthenticator;
    std::string strProjectInstitution;
    std::string strProjectDescription;
    std::string strProjectKnown;
    bool bCachedCredentials = false;
    ACCT_MGR_INFO ami;
    PROJECT_INIT_STATUS pis;
	CC_STATUS     status;
    int wasShown = 0;
    int wasVisible = 0;

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

    pDoc->ForceCacheUpdate();
    pDoc->GetCoreClientStatus(status, true);

	// If we are connected to the localhost, run a really quick screensaver
    //   test to trigger a firewall popup.
    pDoc->GetConnectedComputerName(strComputer);
    if (pDoc->IsComputerNameLocal(strComputer)) {
        wxGetApp().StartBOINCScreensaverTest();
        wxGetApp().StartBOINCDefaultScreensaverTest();
    }


    pDoc->rpc.get_project_init_status(pis);
    pDoc->rpc.acct_mgr_info(ami);

    if (detect_simple_account_credentials(
            strProjectName, strProjectURL, strProjectAuthenticator, strProjectInstitution, strProjectDescription, strProjectKnown
        )
    ){
        if (!pDoc->project((char*)strProjectURL.c_str())) {
            wasShown = IsShown();
            Show();
            wasVisible = wxGetApp().IsApplicationVisible();
            if (!wasVisible) {
                wxGetApp().ShowApplication(true);
            }
        
            pWizard = new CWizardAttach(this);

            pWizard->RunSimpleProjectAttach(
                wxURI::Unescape(strProjectName),
                wxURI::Unescape(strProjectURL),
                wxURI::Unescape(strProjectAuthenticator),
                wxURI::Unescape(strProjectInstitution),
                wxURI::Unescape(strProjectDescription),
                wxURI::Unescape(strProjectKnown)
            );
        }
    } else if (ami.acct_mgr_url.size() && ami.have_credentials) {
        // Fall through
        //
        // There isn't a need to bring up the attach wizard, the account manager will
        // take care of ataching to projects when it completes the RPCs
        //
    } else if (ami.acct_mgr_url.size() && !ami.have_credentials) {
        wasShown = IsShown();
        Show();
        wasVisible = wxGetApp().IsApplicationVisible();
        if (!wasVisible) {
            wxGetApp().ShowApplication(true);
        }

        pWizard = new CWizardAttach(this);
        if (pWizard->SyncToAccountManager()) {

            // _GRIDREPUBLIC, _PROGRESSTHRUPROCESSORS and _CHARITYENGINE
            // are defined for those branded builds on Windows only
#if defined(_GRIDREPUBLIC) || defined(_PROGRESSTHRUPROCESSORS) || defined(_CHARITYENGINE) || defined(__WXMAC__)
#ifdef __WXMAC__
            // For GridRepublic, Charity Engine or ProgressThruProcessors, 
            // the Mac installer put a branding file in our data directory
            long iBrandID = 0;  // 0 is unbranded (default) BOINC

            FILE *f = boinc_fopen("/Library/Application Support/BOINC Data/Branding", "r");
            if (f) {
                fscanf(f, "BrandId=%ld\n", &iBrandID);
                fclose(f);
            }
            if ((iBrandID > 0) && (iBrandID < 4))
#endif
            {
                // If successful, hide the main window if we showed it
                if (!wasVisible) {
                    wxGetApp().ShowApplication(false);
                }
#ifndef __WXMAC__   // See comment in CBOINCGUIApp::OnFinishInit()
                if (!wasShown) {
                    Hide();
                }
#endif
            }
#endif
        }
    } else if ((pis.url.size() || (0 >= pDoc->GetSimpleProjectCount())) && !status.disallow_attach) {
        Show();
        wxGetApp().ShowApplication(true);

        strURL = wxString(pis.url.c_str(), wxConvUTF8);
        bCachedCredentials = pis.url.length() && pis.has_account_key;

        pWizard = new CWizardAttach(this);
        pWizard->Run(strURL, bCachedCredentials);
    }

 	if (pWizard) {
        pWizard->Destroy();
        m_pBackgroundPanel->UpdateProjectView();
	}

    wxLogTrace(wxT("Function Start/End"), wxT("CSimpleFrame::OnConnect - Function End"));
}
Ejemplo n.º 2
0
// ---- command buttons handlers
// handles Add button clicked
void CDlgAdvPreferences::OnAddExclusiveApp(wxCommandEvent&) {
    wxString strMachineName;
    int i, j, n;
    bool hostIsMac = false;
    bool hostIsWin = false;
    bool isDuplicate;
    wxArrayString appNames;
    wxChar *extension = wxT("");
    wxString errmsg;
    CMainDocument* pDoc = wxGetApp().GetDocument();

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

    if (strstr(pDoc->state.host_info.os_name, "Darwin")) {
        hostIsMac = true;
        extension = wxT(".app");
    } else if (strstr(pDoc->state.host_info.os_name, "Microsoft")) {
        hostIsWin = true;
        extension = wxT(".exe");
    }
    
    pDoc->GetConnectedComputerName(strMachineName);
    if (pDoc->IsComputerNameLocal(strMachineName)) {
#ifdef __WXMAC__
        wxFileDialog picker(this, _("Applications to add"), 
                            wxT("/Applications"), wxT(""), wxT("*.app"), 
                            wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_CHANGE_DIR|wxFD_MULTIPLE|wxFD_CHANGE_DIR);
#elif defined(__WXMSW__)
//TODO: fill in the default directory for MSW
        wxFileDialog picker(this, _("Applications to add"), 
                            wxT("C:/Program Files"), wxT(""), wxT("*.exe"), 
                            wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_CHANGE_DIR|wxFD_MULTIPLE|wxFD_CHANGE_DIR);
#else
//TODO: fill in the default directory and wildcard for Linux
        wxFileDialog picker(this, _("Applications to add"), 
                            wxT("/"), wxT(""), wxT("*.*"), 
                            wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_CHANGE_DIR|wxFD_MULTIPLE|wxFD_CHANGE_DIR);
#endif
        if (picker.ShowModal() != wxID_OK) return;
        picker.GetFilenames(appNames);

        for (i=appNames.Count()-1; i>=0; --i) {
#ifdef __WXMSW__
            // Under Windows, filename may include paths if a shortcut selected
            wxString appNameOnly = appNames[i].AfterLast('\\');
            appNames[i] = appNameOnly;
#endif
            wxString directory = picker.GetDirectory();
            wxFileName fn(directory, appNames[i]);
            if (!fn.IsOk() || !fn.IsFileExecutable()) {
                errmsg.Printf(_("'%s' is not an executable application."), appNames[i].c_str());
                wxGetApp().SafeMessageBox(errmsg, _("Add Exclusive App"),
                            wxOK | wxICON_EXCLAMATION, this);
                appNames.RemoveAt(i);
                continue;
            }
        }
    } else {
        // We can't use file picker if connected to a remote computer, 
        // so show a dialog with textedit field so user can type app name
        wxChar path_separator = wxT('/');
        
        wxTextEntryDialog dlg(this, _("Name of application to add?"), _("Add exclusive app"));
        if (hostIsMac) {
            dlg.SetValue(extension);
        } else if (hostIsWin) {
            dlg.SetValue(extension);
            path_separator = wxT('\\');
        }
        if (dlg.ShowModal() != wxID_OK) return;
        
        wxString theAppName = dlg.GetValue();
        // Strip off path if present
        appNames.Add(theAppName.AfterLast(path_separator));
        
    }
        
    for (i=0; i<(int)appNames.Count(); ++i) {
        // wxFileName::IsFileExecutable() doesn't seem to work on Windows, 
        // and we can only perform minimal validation on remote hosts, so 
        // check filename extension on Mac and Win
        if (hostIsMac || hostIsWin) {
            if (!appNames[0].EndsWith(extension)) {
                errmsg.Printf(_("Application names must end with '%s'"), extension);
                wxGetApp().SafeMessageBox(errmsg, _("Add Exclusive App"),
                            wxOK | wxICON_EXCLAMATION, this);
                return;
            }
        }

        if (hostIsMac) {
            int suffix = appNames[i].Find('.', true);
            if (suffix != wxNOT_FOUND) {
                appNames[i].Truncate(suffix);
            }
        }

        // Skip requests for duplicate entries
        isDuplicate = false;
        n = m_exclusiveApsListBox->GetCount();
        for (j=0; j<n; ++j) {
            if ((m_exclusiveApsListBox->GetString(j)).Cmp(appNames[i]) == 0) {
                isDuplicate = true;
                break;
            }
        }
        if (isDuplicate) {
            errmsg.Printf(_("'%s' is already in the list."), appNames[i].c_str());
            wxGetApp().SafeMessageBox(errmsg, _("Add Exclusive App"),
                        wxOK | wxICON_EXCLAMATION, this);
            continue;
        }
        
        m_exclusiveApsListBox->Append(appNames[i]);
        m_bExclusiveAppsDataChanged = true;
    }
}
Ejemplo n.º 3
0
int CBOINCGUIApp::ConfirmExit() {
    CSkinAdvanced*  pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    CMainDocument*  pDoc = wxGetApp().GetDocument();
    wxString        strConnectedCompter = wxEmptyString;
    bool            bWasVisible;
    int             retval = 0;

    wxASSERT(pDoc);
    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
    
    pDoc->GetConnectedComputerName(strConnectedCompter);
    if (!pDoc->IsComputerNameLocal(strConnectedCompter)) {
        // Don't shut down remote clients on Manager exit
        return 1;
    }

    // Don't run confirmation dialog if logging out or shutting down Mac, 
    // or if emergency exit from AsyncRPCDlg
    if (s_bSkipExitConfirmation) return 1;

    // Don't run confirmation dialog if second instance of Manager 
    if (IsMgrMultipleInstance()) return 1;

    if (!m_iDisplayExitDialog) {
        // Mac: User doesn't want to display the dialog and just wants to use their previous value.
        // Win & Linux: User doesn't want to display the dialog and wants to shutdown the client.
        return 1;
    }

    bWasVisible = IsApplicationVisible();
    ShowApplication(true);

    CDlgExitMessage dlg(NULL);

    if (!pSkinAdvanced->GetExitMessage().IsEmpty()) {
        dlg.m_DialogExitMessage->SetLabel(pSkinAdvanced->GetExitMessage());
    }

#ifdef __WXMSW__
    if (m_iShutdownCoreClient) {
        dlg.m_DialogShutdownCoreClient->SetValue(TRUE);
    }
#endif

    if (m_iDisplayExitDialog) {
        dlg.m_DialogDisplay->SetValue(FALSE);
    }

    dlg.Fit();
    dlg.Centre();

    if (wxID_OK == dlg.ShowModal()) {
#ifdef __WXMAC__
        s_bSkipExitConfirmation = true;     // Don't ask twice (only affects Mac)
#else
        m_iShutdownCoreClient = dlg.m_DialogShutdownCoreClient->GetValue();
#endif
        m_iDisplayExitDialog = !dlg.m_DialogDisplay->GetValue();
        retval = true;

    }

    if (!bWasVisible) {
        ShowApplication(false);
    }

    return retval;       // User cancelled exit
}
Ejemplo n.º 4
0
void CViewWork::UpdateSelection() {
    int                 i, n, row;
    CTaskItemGroup*     pGroup = NULL;
    RESULT*             result = NULL;
    PROJECT*            project = NULL;
    CC_STATUS           status;
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    std::string         first_project_url;
    wxString            strMachineName;
    bool                wasSuspended=false;
    bool                all_same_project=false;
    bool                enableShowGraphics = false;
    bool                enableShowVMConsole = false;
    bool                enableSuspendResume = false;
    bool                enableAbort = false;
    bool                enableProperties = false;

    wxASSERT(NULL != pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    wxASSERT(NULL != m_pTaskPane);

    CBOINCBaseView::PreUpdateSelection();

    pGroup = m_TaskGroups[0];
    
    n = m_pListPane->GetSelectedItemCount();
    if (n > 0) {
        enableShowGraphics = true;
        enableShowVMConsole = true;
        enableSuspendResume = true;
        enableAbort = true;
        
        pDoc->GetCoreClientStatus(status);
        if (status.task_suspend_reason & ~(SUSPEND_REASON_CPU_THROTTLE)) {
            enableShowGraphics = false;
            enableShowVMConsole = false;
        }

        pDoc->GetConnectedComputerName(strMachineName);
        if (!pDoc->IsComputerNameLocal(strMachineName)) {
            enableShowGraphics = false;
            enableShowVMConsole = false;
        }
    }

    if (pDoc->m_ActiveTasksOnly) {
        m_pTaskPane->UpdateTask(
            pGroup->m_Tasks[BTN_ACTIVE_ONLY],
            _("Show all tasks"),
            _("Show all tasks.")
        );
    } else {
        m_pTaskPane->UpdateTask(
            pGroup->m_Tasks[BTN_ACTIVE_ONLY],
            _("Show active tasks"),
            _("Show only active tasks.")
        );
    }

    row = -1;
    for (i=0; i<n; i++) {
        // Step through all selected items
        row = m_pListPane->GetNextItem(row, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if (row < 0) break;     // Should never happen
        
        result = pDoc->result(m_iSortedIndexes[row]);
        if (!result) continue;
        if (i == 0) {
            wasSuspended = result->suspended_via_gui;
            if (result->suspended_via_gui) {
                m_pTaskPane->UpdateTask(
                    pGroup->m_Tasks[BTN_SUSPEND],
                    _("Resume"),
                    _("Resume work for this task.")
                );
            } else {
                m_pTaskPane->UpdateTask(
                    pGroup->m_Tasks[BTN_SUSPEND],
                    _("Suspend"),
                    _("Suspend work for this task.")
                );
            }
        } else {
            if (wasSuspended != result->suspended_via_gui) {
                // Disable Suspend / Resume button if the multiple selection
                // has a mix of suspended and not suspended tasks
                enableSuspendResume = false;
            }
        }
        
        // Disable Show VM console if the selected task hasn't registered a remote
        // desktop connection
        //
        if (!strlen(result->remote_desktop_addr)) {
            enableShowVMConsole = false;
        }

        // Disable Show Graphics button if the selected task can't display graphics
        //
        if (!strlen(result->web_graphics_url) && !strlen(result->graphics_exec_path)) {
            enableShowGraphics = false;
        }

        if (result->suspended_via_gui ||
            result->project_suspended_via_gui || 
            (result->scheduler_state != CPU_SCHED_SCHEDULED)
        ) {
            enableShowGraphics = false;
        }
       
        // Disable Abort button if any selected task already aborted
        if (
            result->active_task_state == PROCESS_ABORT_PENDING ||
            result->active_task_state == PROCESS_ABORTED ||
            result->state == RESULT_ABORTED 
        ) {
            enableAbort = false;
        }

       if (i == 0) {
            first_project_url = result->project_url;
            all_same_project = true;
        } else {
            if (first_project_url != result->project_url) {
                all_same_project = false;
            }
        }
        
        if (n == 1) {
            enableProperties = true;
        }
    }

    // To minimize flicker, set each button only once to the final desired state
    pGroup->m_Tasks[BTN_GRAPHICS]->m_pButton->Enable(enableShowGraphics);
    if (enableShowVMConsole) {
        pGroup->m_Tasks[BTN_VMCONSOLE]->m_pButton->Enable();
        if (pGroup->m_Tasks[BTN_VMCONSOLE]->m_pButton->Show()) {
            m_pTaskPane->FitInside();
        }
    } else {
        pGroup->m_Tasks[BTN_VMCONSOLE]->m_pButton->Disable();
        if (pGroup->m_Tasks[BTN_VMCONSOLE]->m_pButton->Hide()) {
            m_pTaskPane->FitInside();
        };
    }
    pGroup->m_Tasks[BTN_SUSPEND]->m_pButton->Enable(enableSuspendResume);
    pGroup->m_Tasks[BTN_ABORT]->m_pButton->Enable(enableAbort);
    pGroup->m_Tasks[BTN_PROPERTIES]->m_pButton->Enable(enableProperties);

    if (all_same_project) {
        project = pDoc->state.lookup_project(result->project_url);
        UpdateWebsiteSelection(GRP_WEBSITES, project);
        if(m_TaskGroups.size()>1) {
            m_pTaskPane->EnableTaskGroupTasks(m_TaskGroups[1]);
        }
    } else {
        UpdateWebsiteSelection(GRP_WEBSITES, NULL);
        if(m_TaskGroups.size()>1) {
            m_pTaskPane->DisableTaskGroupTasks(m_TaskGroups[1]);
        }
    }

    CBOINCBaseView::PostUpdateSelection();
}
Ejemplo n.º 5
0
void CBOINCBaseFrame::ShowConnectionFailedAlert() {
    CSkinAdvanced*      pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    wxString            strConnectedCompter = wxEmptyString;
    wxString            strDialogTitle = wxEmptyString;
    wxString            strDialogMessage = wxEmptyString;

    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCBaseFrame::ShowConnectionFailedAlert - Function Begin"));

    // Did BOINC crash on local computer? If so restart it and reconnect.
    pDoc->GetConnectedComputerName(strConnectedCompter);
    if (pDoc->IsComputerNameLocal(strConnectedCompter)) {
        if (pDoc->m_pClientManager->AutoRestart()) {
            boinc_sleep(0.5);       // Allow time for Client to restart
            if (pDoc->m_pClientManager->IsBOINCCoreRunning()) {
                pDoc->Reconnect();
                return;
            }
        } else {
            // Don't ask whether to reconnect to local client if it is not running
            if (!pDoc->m_pClientManager->IsBOINCCoreRunning()) {
                return;
            }
        }
    }

    // %s is the application name
    //    i.e. 'BOINC Manager', 'GridRepublic Manager'
    strDialogTitle.Printf(
        _("%s - Connection Failed"),
        pSkinAdvanced->GetApplicationName().c_str()
    );

    // 1st %s is the application name
    //    i.e. 'BOINC Manager', 'GridRepublic Manager'
    // 2st %s is the project name
    //    i.e. 'BOINC', 'GridRepublic'
    strDialogMessage.Printf(
        _("%s is not able to connect to a %s client.\nWould you like to try to connect again?"),
        pSkinAdvanced->GetApplicationName().c_str(),
        pSkinAdvanced->GetApplicationShortName().c_str()
    );

    ShowAlert(
        strDialogTitle,
        strDialogMessage,
        wxYES_NO | wxICON_QUESTION,
        false,
        AlertProcessResponse
    );

    // If we are minimized, set flag to show alert when maximized
    m_bShowConnectionFailedAlert = !IsShown();

    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCBaseFrame::ShowConnectionFailedAlert - Function End"));
}
Ejemplo n.º 6
0
void CBOINCClientManager::ShutdownBOINCCore(bool ShuttingDownManager) {
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function Begin"));

    CMainDocument*      pDoc = wxGetApp().GetDocument();
    wxInt32             iCount = 0;
    bool                bClientQuit = false;
    wxString            strConnectedCompter = wxEmptyString;
    wxString            strPassword = wxEmptyString;
    double              startTime = 0;
    wxDateTime          zeroTime = wxDateTime((time_t)0);
    wxDateTime          rpcCompletionTime = zeroTime;
    ASYNC_RPC_REQUEST   request;
    int                 quit_result;

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

#ifdef __WXMAC__
    // Mac Manager shuts down client only if Manager started client
    if (!m_bBOINCStartedByManager) return;
#endif

#ifdef __WXMSW__
    if (IsBOINCConfiguredAsDaemon()) {
        stop_daemon_via_daemonctrl();
        bClientQuit = true;
    } else
#endif
    {
        pDoc->GetConnectedComputerName(strConnectedCompter);
        if (!pDoc->IsComputerNameLocal(strConnectedCompter)) {
            RPC_CLIENT rpc;
            if (!rpc.init("localhost")) {
                pDoc->m_pNetworkConnection->GetLocalPassword(strPassword);
                rpc.authorize((const char*)strPassword.mb_str());
                if (IsBOINCCoreRunning()) {
                    rpc.quit();
                    for (iCount = 0; iCount <= 10; iCount++) {
                        if (!bClientQuit && !IsBOINCCoreRunning()) {
                            wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit Detected"));
                            bClientQuit = true;
                            break;
                        }
                        wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit NOT Detected, Sleeping..."));
                        ::wxSleep(1);
                    }
                } else {
                    bClientQuit = true;
                }
            }
            rpc.close();
        } else {
            if (IsBOINCCoreRunning()) {
                if (ShuttingDownManager) {
                    // Set event filtering to allow RPC completion 
                    // events but not events which start new RPCs
                    wxGetApp().SetEventFiltering(true);
                }
                quit_result = -1;
                request.clear();
                request.which_rpc = RPC_QUIT;
                request.rpcType = RPC_TYPE_ASYNC_NO_REFRESH;
                request.completionTime = &rpcCompletionTime;
                request.resultPtr = &quit_result;
                pDoc->RequestRPC(request);  // Issue an asynchronous Quit RPC

                // Client needs time to shut down project applications, so don't wait
                // for it to shut down; assume it will exit OK if Quit RPC succeeds.
                startTime = dtime();
                while ((dtime() - startTime) < 10.0) {  // Allow 10 seconds
                    boinc_sleep(0.25);          // Check 4 times per second
                    wxSafeYield(NULL, true);    // To allow handling RPC completion events
                    if (!bClientQuit && (rpcCompletionTime != zeroTime)) {
                        // If Quit RPC finished, check its returned value
                        if (quit_result) {
                            break;  // Quit RPC returned an error
                        }
                        wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit Detected"));
                        bClientQuit = true;
                        break;
                    }
                    wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit NOT Detected, Sleeping..."));
                }
            } else {
                bClientQuit = true;
            }
        }
    }

    if (!bClientQuit) {
        KillClient();
    }
    m_lBOINCCoreProcessId = 0;

    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function End"));
}