示例#1
0
bool CBOINCClientManager::AutoRestart() {
    double timeNow, timeDiff;
    if (IsBOINCCoreRunning()) return true;
#if ! (defined(__WXMAC__) || defined(__WXMSW__)) 
// Mac and Windows can restart Client as a daemon, but 
// Linux may not know Client's location if it didn't start the Client
    if (!m_bBOINCStartedByManager) return false;
#endif
    // Alert user if Client crashes 3 times in CLIENT_3_CRASH_MAX_TIME
    timeNow = dtime();
    timeDiff = timeNow - m_fAutoRestart1Time;
    if ((timeDiff) < (CLIENT_3_CRASH_MAX_TIME * 60)) {
        int                 response;
        ClientCrashDlg      *dlg = new ClientCrashDlg(timeDiff);
        if (dlg) {
            CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
            if (!pFrame->IsShown()) {
                pFrame->Show();
            }
            response = dlg->ShowModal();
            dlg->Destroy();
            if (response == wxID_CANCEL) return false;
            timeNow = 0;
            m_fAutoRestart1Time = 0;
            m_fAutoRestart2Time = 0;
        }
    }
    m_lBOINCCoreProcessId = 0;
    m_fAutoRestart1Time = m_fAutoRestart2Time;
    m_fAutoRestart2Time = timeNow;
    StartupBOINCCore();
    return true;
}
int CBOINCDialUpManager::ConnectionFailed() {
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    CSkinAdvanced*      pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    wxString            strDialogMessage = wxEmptyString;

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

    // %s is the project name
    //    i.e. 'BOINC', 'GridRepublic'
    strDialogMessage.Printf(
        _("%s failed to connect to the Internet."),
        pSkinAdvanced->GetApplicationShortName().c_str()
    );
    pFrame->ShowAlert(
        m_strDialogTitle,
        strDialogMessage,
        wxOK | wxICON_ERROR,
        true
    );
    m_bConnectedSuccessfully = false;

    return 0;
}
示例#3
0
/* Constructor */
CDlgItemProperties::CDlgItemProperties(wxWindow* parent) : 
    wxDialog( parent, ID_ANYDIALOG, wxEmptyString, wxDefaultPosition, 
                wxSize( 503,480 ), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ) {
    CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
    wxASSERT(pFrame);
    if (!pFrame) return;

    SetSizeHints( wxDefaultSize, wxDefaultSize );
    SetExtraStyle( GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY );
    
    m_bSizer1 = new wxBoxSizer( wxVERTICAL );
    
    m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
    m_scrolledWindow->SetScrollRate( 5, 5 );
    wxBoxSizer* m_bSizer2;
    m_bSizer2 = new wxBoxSizer( wxVERTICAL );
    
    m_gbSizer = new wxGridBagSizer( 0, 0 );
    m_gbSizer->SetCols(2);
    m_gbSizer->AddGrowableCol( 1 );
    m_gbSizer->SetFlexibleDirection( wxBOTH );
    m_gbSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
    
    m_bSizer2->Add( m_gbSizer, 1, wxEXPAND, 5 );
    
    m_scrolledWindow->SetSizer( m_bSizer2 );
    m_scrolledWindow->Layout();
    m_bSizer2->Fit( m_scrolledWindow );
    m_bSizer1->Add( m_scrolledWindow, 1, wxEXPAND | wxALL, 5 );
    
    m_btnClose = new wxButton( this, wxID_OK, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
    m_btnClose->SetDefault(); 
    m_bSizer1->Add( m_btnClose, 0, wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );
    
    SetSizer( m_bSizer1 );
    Layout();
    
    Centre( wxBOTH );

    m_current_row=0;

    int currentTabView = pFrame->GetCurrentViewPage();
    switch(currentTabView) {
    case VW_PROJ:
        m_strBaseConfigLocation = wxString(wxT("/DlgProjectProperties/"));
        break;
    case VW_TASK:
        m_strBaseConfigLocation = wxString(wxT("/DlgTaskProperties/"));
        break;
    default:
        m_strBaseConfigLocation = wxString(wxT("/DlgProperties/"));
        break;
    }

    RestoreState();
}
int CBOINCDialUpManager::Disconnect() {
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    CSkinAdvanced*      pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    wxString            strDialogMessage = wxEmptyString;
    GLOBAL_PREFS_MASK   mask;


    wxASSERT(pDoc);
    wxASSERT(pFrame);
    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));


    wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::Disconnect - Connection Detected, disconnect requested via the CC."));

    // Update current working preferences (including any overrides) from client
    pDoc->rpc.get_global_prefs_working_struct(pDoc->state.global_prefs, mask);
    if (pDoc->state.global_prefs.hangup_if_dialed) {
        wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::Disconnect - Connection Detected, Don't need the network, Hanging up."));
        if (m_pDialupManager->HangUp()) {

            // %s is the project name
            //    i.e. 'BOINC', 'GridRepublic'
            strDialogMessage.Printf(
                _("%s has successfully disconnected from the Internet."),
                pSkinAdvanced->GetApplicationShortName().c_str()
            );
            pFrame->ShowAlert(
                m_strDialogTitle,
                strDialogMessage,
                wxOK | wxICON_INFORMATION,
                true
            );
            m_bConnectedSuccessfully = false;

        } else {

            // %s is the project name
            //    i.e. 'BOINC', 'GridRepublic'
            strDialogMessage.Printf(
                _("%s failed to disconnected from the Internet."),
                pSkinAdvanced->GetApplicationShortName().c_str()
            );
            pFrame->ShowAlert(
                m_strDialogTitle,
                strDialogMessage,
                wxOK | wxICON_ERROR
            );
        }
    }

    return 0;
}
示例#5
0
// Work around a bug in wxWidgets 2.8.x which fails 
// to call OnExit() when Windows is shut down. This
// is supposed to be fixed in wxWidgets 2.9.x.
//
void CBOINCGUIApp::OnEndSession(wxCloseEvent& ) {
    s_bSkipExitConfirmation = true;

    CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
    wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, wxID_EXIT);
    // The event loop has already been stopped,
    // so we must call OnExit directly
    pFrame->OnExit(evt);
    OnExit();
}
int CBOINCDialUpManager::NotifyUserNeedConnection(bool bNotificationOnly) {
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    CSkinAdvanced*      pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    wxTimeSpan          tsLastDialupAlertSent;
    wxString            strDialogMessage = wxEmptyString;

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

    tsLastDialupAlertSent = wxDateTime::Now() - m_dtLastDialupAlertSent;
    if ((tsLastDialupAlertSent.GetMinutes() >= pFrame->GetReminderFrequency()) && (pFrame->GetReminderFrequency() != 0)) {
        wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::NotifyUserNeedConnection - Manager not shown, notify instead"));
        m_dtLastDialupAlertSent = wxDateTime::Now();

#ifdef __WXWIN__
        // 1st %s is the project name
        //    i.e. 'BOINC', 'GridRepublic'
        // 2st %s is the application name
        //    i.e. 'BOINC Manager', 'GridRepublic Manager'
        strDialogMessage.Printf(
            _("%s needs to connect to the Internet.  Please click to open %s."),
            pSkinAdvanced->GetApplicationShortName().c_str(),
            pSkinAdvanced->GetApplicationName().c_str()
        );
#else
        // %s is the project name
        //    i.e. 'BOINC', 'GridRepublic'
        strDialogMessage.Printf(
            _("%s is unable to communicate with a project and needs an Internet connection.\n"
              "Please connect to the Internet, then select the 'Do network communications' "
              "item from the Advanced menu."),
            pSkinAdvanced->GetApplicationShortName().c_str()
        );
#endif
        pFrame->ShowAlert(
            m_strDialogTitle,
            strDialogMessage,
            wxOK | wxICON_INFORMATION,
            bNotificationOnly
        );
    }

    return 0;
}
int CBOINCDialUpManager::NetworkAvailable() {
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    CSkinAdvanced*      pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    wxString            strDialogMessage = wxEmptyString;


    wxASSERT(pDoc);
    wxASSERT(pFrame);
    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));


    wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::NetworkAvailable - Connection Detected, notifing user of update to all projects"));

    m_bNotifyConnectionAvailable = false;

    // We are already online but BOINC for some reason is in a state
    //   where it belives it has some pending work to do, so give it
    //   a nudge

    // %s is the project name
    //    i.e. 'BOINC', 'GridRepublic'
    strDialogMessage.Printf(
        _("%s has detected it is now connected to the Internet.\n"
          "Updating all projects and retrying all transfers."),
        pSkinAdvanced->GetApplicationShortName().c_str()
    );

    pFrame->ShowAlert(
        m_strDialogTitle,
        strDialogMessage,
        wxOK | wxICON_INFORMATION,
        true
    );

    // Signal BOINC to update all projects and transfers.
    pDoc->rpc.network_available();

    return 0;
}
void CMainDocument::HandleCompletedRPC() {
    int retval = 0;
    wxMutexError mutexErr = wxMUTEX_NO_ERROR;
    int i, n, requestIndex = -1;
    bool stillWaitingForPendingRequests = false;
    
    if (!m_RPCThread) return;
   
    if (current_rpc_request.isActive) return;
    
    // We can get here either via a CRPCFinishedEvent event posted 
    // by the RPC thread or by a call from RequestRPC.  If we were 
    // called from RequestRPC, the CRPCFinishedEvent will still be 
    // on the event queue, so we get called twice.  Check for this here.
    if (current_rpc_request.which_rpc == 0) return; // already handled by a call from RequestRPC

    // Find our completed request in the queue
    n = (int) RPC_requests.size();
    for (i=0; i<n; ++i) {
        if (RPC_requests[i].isSameAs(current_rpc_request)) {
            requestIndex = i;
        } else {
            if (RPC_requests[i].rpcType == RPC_TYPE_WAIT_FOR_COMPLETION) {
                stillWaitingForPendingRequests = true;
            }
        }
    }
    
    if (! stillWaitingForPendingRequests) {
        if (m_RPCWaitDlg) {
            if (m_RPCWaitDlg->IsShown()) {
                m_RPCWaitDlg->EndModal(wxID_OK);
            }
                m_RPCWaitDlg->Destroy();
                m_RPCWaitDlg = NULL;
        }
        m_bWaitingForRPC = false;
    }

    if (requestIndex >= 0) {
        // Remove completed request from the queue
        RPC_requests.erase(RPC_requests.begin()+requestIndex);
    }
    
    retval = current_rpc_request.retval;

    
    if (current_rpc_request.completionTime) {
        *(current_rpc_request.completionTime) = wxDateTime::Now();
    }
    
    if (current_rpc_request.resultPtr) {
        *(current_rpc_request.resultPtr) = retval;
    }
    
    // Post-processing
    if (! retval) {
         if (current_rpc_request.rpcType == RPC_TYPE_ASYNC_WITH_REFRESH_AFTER) {
            if (!retval) {
                m_bNeedRefresh = true;
            }
        }
    
         if (current_rpc_request.rpcType == RPC_TYPE_ASYNC_WITH_UPDATE_TASKBAR_ICON_AFTER) {
            if (!retval) {
                m_bNeedTaskBarRefresh = true;
            }
        }
    
       switch (current_rpc_request.which_rpc) {
        case RPC_GET_STATE:
            if (current_rpc_request.exchangeBuf && !retval) {
                CC_STATE* arg1 = (CC_STATE*)current_rpc_request.arg1;
                CC_STATE* exchangeBuf = (CC_STATE*)current_rpc_request.exchangeBuf;
                arg1->projects.swap(exchangeBuf->projects);
                arg1->apps.swap(exchangeBuf->apps);
                arg1->app_versions.swap(exchangeBuf->app_versions);
                arg1->wus.swap(exchangeBuf->wus);
                arg1->results.swap(exchangeBuf->results);
                exchangeBuf->global_prefs = arg1->global_prefs;
                exchangeBuf->version_info = arg1->version_info;
                exchangeBuf->executing_as_daemon = arg1->executing_as_daemon;
                exchangeBuf->have_cuda = arg1->have_cuda;
                exchangeBuf->have_ati = arg1->have_ati;
            }
            break;
        case RPC_GET_RESULTS:
            if (current_rpc_request.exchangeBuf && !retval) {
                RESULTS* arg1 = (RESULTS*)current_rpc_request.arg1;
                RESULTS* exchangeBuf = (RESULTS*)current_rpc_request.exchangeBuf;
                arg1->results.swap(exchangeBuf->results);
            }
            break;
        case RPC_GET_FILE_TRANSFERS:
            if (current_rpc_request.exchangeBuf && !retval) {
                FILE_TRANSFERS* arg1 = (FILE_TRANSFERS*)current_rpc_request.arg1;
                FILE_TRANSFERS* exchangeBuf = (FILE_TRANSFERS*)current_rpc_request.exchangeBuf;
                arg1->file_transfers.swap(exchangeBuf->file_transfers);
            }
            break;
        case RPC_GET_SIMPLE_GUI_INFO2:
            if (!retval) {
                retval = CopyProjectsToStateBuffer(*(PROJECTS*)(current_rpc_request.arg1), *(CC_STATE*)(current_rpc_request.arg2));
            }
            if (current_rpc_request.exchangeBuf && !retval) {
                RESULTS* arg3 = (RESULTS*)current_rpc_request.arg3;
                RESULTS* exchangeBuf = (RESULTS*)current_rpc_request.exchangeBuf;
                arg3->results.swap(exchangeBuf->results);
            }
            break;
        case RPC_GET_PROJECT_STATUS1:
            if (!retval) {
                retval = CopyProjectsToStateBuffer(*(PROJECTS*)(current_rpc_request.arg1), *(CC_STATE*)(current_rpc_request.arg2));
            }
            break;
        case RPC_GET_ALL_PROJECTS_LIST:
            if (current_rpc_request.exchangeBuf && !retval) {
                ALL_PROJECTS_LIST* arg1 = (ALL_PROJECTS_LIST*)current_rpc_request.arg1;
                ALL_PROJECTS_LIST* exchangeBuf = (ALL_PROJECTS_LIST*)current_rpc_request.exchangeBuf;
                arg1->projects.swap(exchangeBuf->projects);
            }
            break;
        case RPC_GET_DISK_USAGE:
            if (current_rpc_request.exchangeBuf && !retval) {
                DISK_USAGE* arg1 = (DISK_USAGE*)current_rpc_request.arg1;
                DISK_USAGE* exchangeBuf = (DISK_USAGE*)current_rpc_request.exchangeBuf;
                arg1->projects.swap(exchangeBuf->projects);
                exchangeBuf->d_total = arg1->d_total;
                exchangeBuf->d_free = arg1->d_free;
                exchangeBuf->d_boinc = arg1->d_boinc;
                exchangeBuf->d_allowed = arg1->d_allowed;
            }
            break;
        case RPC_GET_NOTICES:
            if (current_rpc_request.exchangeBuf && !retval) {
                NOTICES* arg2 = (NOTICES*)current_rpc_request.arg2;
                NOTICES* exchangeBuf = (NOTICES*)current_rpc_request.exchangeBuf;
                arg2->notices.swap(exchangeBuf->notices);
            }
            if (!retval) {
                CachedNoticeUpdate();  // Call this only when notice buffer is stable
            }
            break;
        case RPC_GET_MESSAGES:
            if (current_rpc_request.exchangeBuf && !retval) {
                MESSAGES* arg2 = (MESSAGES*)current_rpc_request.arg2;
                MESSAGES* exchangeBuf = (MESSAGES*)current_rpc_request.exchangeBuf;
                arg2->messages.swap(exchangeBuf->messages);
            }
            if (!retval) {
                CachedMessageUpdate();  // Call this only when message buffer is stable
            }
            break;
        case RPC_GET_HOST_INFO:
            if (current_rpc_request.exchangeBuf && !retval) {
                HOST_INFO* arg1 = (HOST_INFO*)current_rpc_request.arg1;
                HOST_INFO* exchangeBuf = (HOST_INFO*)current_rpc_request.exchangeBuf;
                *exchangeBuf = *arg1;
            }
            break;
        case RPC_GET_STATISTICS:
            if (current_rpc_request.exchangeBuf && !retval) {
                PROJECTS* arg1 = (PROJECTS*)current_rpc_request.arg1;
                PROJECTS* exchangeBuf = (PROJECTS*)current_rpc_request.exchangeBuf;
                arg1->projects.swap(exchangeBuf->projects);
            }
            break;
            
        case RPC_GET_CC_STATUS:
            if (current_rpc_request.exchangeBuf && !retval) {
                CC_STATUS* arg1 = (CC_STATUS*)current_rpc_request.arg1;
                CC_STATUS* exchangeBuf = (CC_STATUS*)current_rpc_request.exchangeBuf;
                *exchangeBuf = *arg1;
            }
            break;
        case RPC_ACCT_MGR_INFO:
            if (current_rpc_request.exchangeBuf && !retval) {
                ACCT_MGR_INFO* arg1 = (ACCT_MGR_INFO*)current_rpc_request.arg1;
                ACCT_MGR_INFO* exchangeBuf = (ACCT_MGR_INFO*)current_rpc_request.exchangeBuf;
                *exchangeBuf = *arg1;
           }
            break;
        default:
            // We don't support double buffering for other RPC calls 
            wxASSERT(current_rpc_request.exchangeBuf == NULL);
            break;
        }
    }
    
    if (current_rpc_request.resultPtr) {
        // In case post-processing changed retval
        *(current_rpc_request.resultPtr) = retval;
    }

    // We must call ProcessEvent() rather than AddPendingEvent() here to 
    // guarantee integrity of data when other events are handled (such as 
    // Abort, Suspend/Resume, Show Graphics, Update, Detach, Reset, No 
    // New Work, etc.)  Otherwise, if one of those events is pending it 
    // might be processed first, and the data in the selected rows may not 
    // match the data which the user selected if any rows were added or 
    // deleted due to the RPC.  
    // The refresh event called here adjusts the selections to fix any 
    // such mismatch before other pending events are processed.  
    //
    // However, the refresh code may itself request a Demand RPC, which 
    // would cause undesirable recursion if we are already waiting for 
    // another Demand RPC to complete.  In that case, we defer the refresh 
    // until all pending Demand RPCs have been done.
    //
    if (m_bNeedRefresh && !m_bWaitingForRPC) {
        m_bNeedRefresh = false;
        // We must get the frame immediately before using it, 
        // since it may have been changed by SetActiveGUI().
        CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
        if (pFrame) {
            CFrameEvent event(wxEVT_FRAME_REFRESHVIEW, pFrame);
            pFrame->ProcessEvent(event);
        }
    }

    if (m_bNeedTaskBarRefresh && !m_bWaitingForRPC) {
        m_bNeedTaskBarRefresh = false;
        CTaskBarIcon* pTaskbar = wxGetApp().GetTaskBarIcon();
        if (pTaskbar) {
            CTaskbarEvent event(wxEVT_TASKBAR_REFRESH, pTaskbar);
            pTaskbar->ProcessEvent(event);
        }
    }

    if (current_rpc_request.rpcType == RPC_TYPE_ASYNC_WITH_REFRESH_EVENT_LOG_AFTER) {
        CDlgEventLog* eventLog = wxGetApp().GetEventLog();
        if (eventLog) {
            eventLog->OnRefresh();
        }
    }
    
    current_rpc_request.clear();

    // Start the next RPC request.  
    // We can't start this until finished processing the previous RPC's 
    // event because the two requests may write into the same buffer.
    if (RPC_requests.size() > 0) {
        // Wait for thread to unlock mutex with m_pRPC_Thread_Condition->Wait()
        mutexErr = m_pRPC_Thread_Mutex->Lock();  // Blocks until thread unlocks the mutex
        wxASSERT(mutexErr == wxMUTEX_NO_ERROR);

        // Make sure activation is an atomic operation
        RPC_requests[0].isActive = false;
        current_rpc_request = RPC_requests[0];
        current_rpc_request.isActive = true;

        m_pRPC_Thread_Condition->Signal();  // Unblock the thread

        // m_pRPC_Thread_Condition->Wait() will Lock() the mutex upon receiving Signal(), 
        // causing it to block again if we still have our lock on the mutex.
        mutexErr = m_pRPC_Thread_Mutex->Unlock();
        wxASSERT(mutexErr == wxMUTEX_NO_ERROR);
    }
}
int CMainDocument::RequestRPC(ASYNC_RPC_REQUEST& request, bool hasPriority) {
    std::vector<ASYNC_RPC_REQUEST>::iterator iter;
    int retval = 0;
    int response = wxID_OK;
    wxMutexError mutexErr = wxMUTEX_NO_ERROR;
    long delayTimeRemaining, timeToSleep;
    bool shown = false;
    
    if (!m_RPCThread) return -1;

    if ( (request.rpcType < RPC_TYPE_WAIT_FOR_COMPLETION) || 
            (request.rpcType >= NUM_RPC_TYPES) ) {
        wxASSERT(false);
        return -1;
    }
    
    // If we are quitting, cancel any pending RPCs
    if (request.which_rpc == RPC_QUIT) {
        if (current_rpc_request.isActive) {
            RPC_requests.erase(RPC_requests.begin()+1, RPC_requests.end());

        } else {
            RPC_requests.clear();
        }
    }
    
    // Check if a duplicate request is already on the queue
    for (iter=RPC_requests.begin(); iter!=RPC_requests.end(); iter++) {
        if (iter->isSameAs(request)) {
            return 0;
        }
    }

    if ((request.rpcType == RPC_TYPE_WAIT_FOR_COMPLETION) && (request.resultPtr == NULL)) {
        request.resultPtr = &retval;
    }
    
    if (hasPriority) {
        // We may want to set hasPriority for some user-initiated events. 
        // Since the user is waiting, insert this at head of request queue.
        // As of 8/14/08, hasPriority is never set true, so hasn't been tested.
        iter = RPC_requests.insert(RPC_requests.begin(), request);
    } else {
           RPC_requests.push_back(request);
    }
    
    // Start this RPC if no other RPC is already in progress.
    if (RPC_requests.size() == 1) {
        // Wait for thread to unlock mutex with m_pRPC_Thread_Condition->Wait()
        mutexErr = m_pRPC_Thread_Mutex->Lock();  // Blocks until thread unlocks the mutex
        wxASSERT(mutexErr == wxMUTEX_NO_ERROR);

        // Make sure activation is an atomic operation
        request.isActive = false;
        current_rpc_request = request;
        current_rpc_request.isActive = true;

        m_pRPC_Thread_Condition->Signal();  // Unblock the thread

        // m_pRPC_Thread_Condition->Wait() will Lock() the mutex upon receiving Signal(), 
        // causing it to block again if we still have our lock on the mutex.
        mutexErr = m_pRPC_Thread_Mutex->Unlock();
        wxASSERT(mutexErr == wxMUTEX_NO_ERROR);
    }

    // If this is a user-initiated event wait for completion but show 
    // a dialog allowing the user to cancel.
    if (request.rpcType == RPC_TYPE_WAIT_FOR_COMPLETION) {
    // TODO: proper handling if a second user request is received while first is pending ??
        if (m_bWaitingForRPC) {
            wxLogMessage(wxT("Second user RPC request while another was pending"));
            wxASSERT(false);
            return -1;
        }
        // Don't show dialog if RPC completes before RPC_WAIT_DLG_DELAY
        // or while BOINC is minimized
        CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
        wxStopWatch Dlgdelay = wxStopWatch();        
        m_RPCWaitDlg = new AsyncRPCDlg();
        m_bWaitingForRPC = true;
        
        // Allow RPC_WAIT_DLG_DELAY seconds for Demand RPC to complete before 
        // displaying "Please Wait" dialog, but keep checking for completion.
        delayTimeRemaining = RPC_WAIT_DLG_DELAY;
        while (true) {
            if (delayTimeRemaining >= 0) {  // Prevent overflow if minimized for a very long time
                delayTimeRemaining = RPC_WAIT_DLG_DELAY - Dlgdelay.Time();
            }
            
            if (pFrame) {
                shown = pFrame->IsShown();
            } else {
                shown = false;
            }
            
            if (shown) {
                if (delayTimeRemaining <= 0) break; // Display the Please Wait dialog
                timeToSleep = delayTimeRemaining;
            } else {
                // Don't show dialog while Manager is minimized, but do 
                // process events so user can maximize the manager. 
                //
                // NOTE: CBOINCGUIApp::FilterEvent() discards those events 
                // which might cause posting of more RPC requests while 
                // we are in this loop, to prevent undesirable recursion.
                // Since the manager is minimized, we don't have to worry about 
                // discarding crucial drawing or command events. 
                // The filter does allow the the Open Manager menu item from 
                // the system tray icon and wxEVT_RPC_FINISHED event. 
                //
                timeToSleep = DELAY_WHEN_MINIMIZED; // Allow user to maximize Manager
                wxSafeYield(NULL, true);
            }
            
            // OnRPCComplete() clears m_bWaitingForRPC if RPC completed 
            if (! m_bWaitingForRPC) {
                return retval;
            }
            
            mutexErr = m_pRPC_Request_Mutex->Lock();
            wxASSERT(mutexErr == wxMUTEX_NO_ERROR);

            // Simulate handling of CRPCFinishedEvent but don't allow any other 
            // events (so no user activity) to prevent undesirable recursion.
            // Since we don't need to filter and discard events, they remain on 
            // the queue until it is safe to process them.
            // Allow RPC thread to run while we wait for it.
            if (!current_rpc_request.isActive) {
                mutexErr = m_pRPC_Request_Mutex->Unlock();
                wxASSERT(mutexErr == wxMUTEX_NO_ERROR);
                
                HandleCompletedRPC();
                continue;
            }

            // Wait for RPC thread to wake us
            // This does the following:
            // (1) Unlocks the Mutex and puts the main thread to sleep as an atomic operation.
            // (2) On Signal from RPC thread: locks Mutex again and wakes the main thread.
            m_pRPC_Request_Condition->WaitTimeout(timeToSleep);

            mutexErr = m_pRPC_Request_Mutex->Unlock();
            wxASSERT(mutexErr == wxMUTEX_NO_ERROR);
        }
        
        // Demand RPC has taken longer than RPC_WAIT_DLG_DELAY seconds and 
        // Manager is not minimized, so display the "Please Wait" dialog 
        // with a Cancel button.  If the RPC does complete while the dialog 
        // is up, HandleCompletedRPC() will call EndModal with wxID_OK.
        //
        // NOTE: the Modal dialog permits processing of all events, but 
        // CBOINCGUIApp::FilterEvent() blocks those events which might cause 
        // posting of more RPC requests while in this dialog, to prevent 
        // undesirable recursion.
        //
        if (m_RPCWaitDlg) {
            response = m_RPCWaitDlg->ShowModal();
            // Remember time the dialog was closed for use by RunPeriodicRPCs()
            m_dtLasAsyncRPCDlgTime = wxDateTime::Now();
            if (response != wxID_OK) {
                // TODO: If user presses Cancel in Please Wait dialog but request 
                // has not yet been started, should we just remove it from queue? 
                // If we make that change, should we also add a separate menu item  
                // to reset the RPC connection (or does one already exist)?

                retval = -1;
                // If the RPC continues to get data after we return to 
                // our caller, it may try to write into a buffer or struct
                // which the caller has already deleted.  To prevent this, 
                // we close the socket (disconnect) and kill the RPC thread.
                // This is ugly but necessary.  We must then reconnect and 
                // start a new RPC thread.
                if (current_rpc_request.isActive) {
                    current_rpc_request.isActive = false;
                    rpcClient.close();
                    RPC_requests.clear();
                    current_rpc_request.clear();
                    m_bNeedRefresh = false;
                    m_bNeedTaskBarRefresh = false;

                    // We will be reconnected to the same client (if possible) by 
                    // CBOINCDialUpManager::OnPoll() and CNetworkConnection::Poll().
                    m_pNetworkConnection->SetStateDisconnected();
                }
                if (response == wxID_EXIT) {
                    pFrame = wxGetApp().GetFrame();
                    wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, wxID_EXIT);
                    s_bSkipExitConfirmation = true;
                    pFrame->AddPendingEvent(evt);
                }
            }
            if (m_RPCWaitDlg) {
                m_RPCWaitDlg->Destroy();
            }
            m_RPCWaitDlg = NULL;
            m_bWaitingForRPC = false;
        }
    }
    return retval;
}
示例#10
0
bool CBOINCGUIApp::SetActiveGUI(int iGUISelection, bool bShowWindow) {
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCGUIApp::SetActiveGUI - Function Begin"));
    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCGUIApp::SetActiveGUI - GUI Selection: '%d', Show: %d'"), iGUISelection, (int)bShowWindow);

    CBOINCBaseFrame* pNewFrame = NULL;
    CBOINCBaseFrame* pOldFrame = m_pFrame;
    wxInt32          iTop = 0;
    wxInt32          iLeft = 0;
    wxInt32          iHeight = 0;
    wxInt32          iWidth = 0;


    // Create the new window
    if ((iGUISelection != m_iGUISelected) || !m_pFrame) {

        // Retrieve the desired window state before creating the
        //   desired frames
        if (BOINC_ADVANCEDGUI == iGUISelection) {
            m_pConfig->SetPath(wxT("/"));
            m_pConfig->Read(wxT("YPos"), &iTop, 30);
            m_pConfig->Read(wxT("XPos"), &iLeft, 30);
            m_pConfig->Read(wxT("Width"), &iWidth, 800);
            m_pConfig->Read(wxT("Height"), &iHeight, 600);
            // Guard against a rare situation where registry values are zero
            if (iWidth < 50) iWidth = 800;
            if (iHeight < 50) iHeight = 600;
        } else {
            m_pConfig->SetPath(wxT("/Simple"));
            m_pConfig->Read(wxT("YPos"), &iTop, 30);
            m_pConfig->Read(wxT("XPos"), &iLeft, 30);

            // We don't save Simple View's width & height since it's 
            // window is not resizable, so don't try to read them
#ifdef __WXMAC__
//            m_pConfig->Read(wxT("Width"), &iWidth, 409);
//            m_pConfig->Read(wxT("Height"), &iHeight, 561);
            iWidth = 409;
            iHeight = 561;
#else
//            m_pConfig->Read(wxT("Width"), &iWidth, 416);
//            m_pConfig->Read(wxT("Height"), &iHeight, 570);
            iWidth = 416;
            iHeight = 570;
#endif
        }


        // Make sure that the new window is going to be visible
        //   on a screen
#ifdef __WXMAC__
    if (!IsWindowOnScreen(iLeft, iTop, iWidth, iHeight)) {
        iTop = iLeft = 30;
    }
#else
	    // If either co-ordinate is less then 0 then set it equal to 0 to ensure
	    // it displays on the screen.
	    if ( iLeft < 0 ) iLeft = 30;
	    if ( iTop < 0 ) iTop = 30;

	    // Read the size of the screen
	    wxInt32 iMaxWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
	    wxInt32 iMaxHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );

	    // Max sure that it doesn't go off to the right or bottom
	    if ( iLeft + iWidth > iMaxWidth ) iLeft = iMaxWidth - iWidth;
	    if ( iTop + iHeight > iMaxHeight ) iTop = iMaxHeight - iHeight;
#endif

        // Create the main window
        //
        if (BOINC_ADVANCEDGUI == iGUISelection) {
            // Initialize the advanced gui window
            pNewFrame = new CAdvancedFrame(
                m_pSkinManager->GetAdvanced()->GetApplicationName(), 
                m_pSkinManager->GetAdvanced()->GetApplicationIcon(),
                m_pSkinManager->GetAdvanced()->GetApplicationIcon32(),
                wxPoint(iLeft, iTop),
                wxSize(iWidth, iHeight)
            );
        } else {
            // Initialize the simple gui window
            pNewFrame = new CSimpleFrame(
                m_pSkinManager->GetAdvanced()->GetApplicationName(), 
                m_pSkinManager->GetAdvanced()->GetApplicationIcon(),
                m_pSkinManager->GetAdvanced()->GetApplicationIcon32(),
                wxPoint(iLeft, iTop),
                wxSize(iWidth, iHeight)
            );
        }

        wxASSERT(pNewFrame);

        if (pNewFrame) {
            SetTopWindow(pNewFrame);

            // Store the new frame for future use
            m_pFrame = pNewFrame;

            // Hide the old one if it exists.  We must do this 
            // after updating m_pFrame to prevent Mac OSX from
            // hiding the application
            if (pOldFrame) pOldFrame->Hide();

            // Delete the old one if it exists
            if (pOldFrame) pOldFrame->Destroy();

            if (iGUISelection != m_iGUISelected) {
                m_iGUISelected = iGUISelection;
                m_pConfig->SetPath(wxT("/"));
                m_pConfig->Write(wxT("GUISelection"), iGUISelection);
                m_pConfig->Flush();
            }
        }
    }

    // Show the new frame if needed 
    if (m_pFrame && bShowWindow) {
        if (m_pEventLog) {
            m_pEventLog->Show();
            m_pEventLog->Raise();
#ifdef __WXMSW__
            ::SetForegroundWindow((HWND)m_pEventLog->GetHWND());
#endif
        }

        if (!m_pFrame->IsShown()) {
            m_pFrame->Show();
        }
        if (m_pFrame->IsIconized()) {
            m_pFrame->Maximize(false);
        }
        m_pFrame->Raise();

#ifdef __WXMSW__
        ::SetForegroundWindow((HWND)m_pFrame->GetHWND());
#endif
    }

    wxLogTrace(wxT("Function Start/End"), wxT("CBOINCGUIApp::SetActiveGUI - Function End"));
    return true;
}
示例#11
0
bool CBOINCGUIApp::SetActiveGUI(int iGUISelection, bool bShowWindow) {
    CBOINCBaseFrame* pNewFrame = NULL;
    CBOINCBaseFrame* pOldFrame = m_pFrame;
    wxInt32          iTop = 0;
    wxInt32          iLeft = 0;
    wxInt32          iHeight = 0;
    wxInt32          iWidth = 0;


    // Create the new window
    if ((iGUISelection != m_iGUISelected) || !m_pFrame) {

        // Reterieve the desired window state before creating the
        //   desired frames
        if (BOINC_ADVANCEDGUI == iGUISelection) {
            m_pConfig->SetPath(wxT("/"));
            m_pConfig->Read(wxT("YPos"), &iTop, 30);
            m_pConfig->Read(wxT("XPos"), &iLeft, 30);
            m_pConfig->Read(wxT("Width"), &iWidth, 800);
            m_pConfig->Read(wxT("Height"), &iHeight, 600);
        } else {
            m_pConfig->SetPath(wxT("/Simple"));
            m_pConfig->Read(wxT("YPos"), &iTop, 30);
            m_pConfig->Read(wxT("XPos"), &iLeft, 30);
#ifdef __WXMAC__
            m_pConfig->Read(wxT("Width"), &iWidth, 409);
            m_pConfig->Read(wxT("Height"), &iHeight, 561);
#else
            m_pConfig->Read(wxT("Width"), &iWidth, 416);
            m_pConfig->Read(wxT("Height"), &iHeight, 570);
#endif
        }


        // Make sure that the new window is going to be visible
        //   on a screen
#ifdef __WXMAC__
        Rect titleRect = {iTop, iLeft, iTop+22, iLeft+iWidth };
        InsetRect(&titleRect, 5, 5);                // Make sure at least a 5X5 piece visible
        RgnHandle displayRgn = NewRgn();
        CopyRgn(GetGrayRgn(), displayRgn);          // Region encompassing all displays
        Rect menuRect = ((**GetMainDevice())).gdRect;
        menuRect.bottom = GetMBarHeight() + menuRect.top;
        RgnHandle menuRgn = NewRgn();
        RectRgn(menuRgn, &menuRect);                // Region hidden by menu bar
        DiffRgn(displayRgn, menuRgn, displayRgn);   // Subtract menu bar retion
        if (!RectInRgn(&titleRect, displayRgn))
            iTop = iLeft = 30;
        DisposeRgn(menuRgn);
        DisposeRgn(displayRgn);
#else
	    // If either co-ordinate is less then 0 then set it equal to 0 to ensure
	    // it displays on the screen.
	    if ( iLeft < 0 ) iLeft = 30;
	    if ( iTop < 0 ) iTop = 30;

	    // Read the size of the screen
	    wxInt32 iMaxWidth = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
	    wxInt32 iMaxHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );

	    // Max sure that it doesn't go off to the right or bottom
	    if ( iLeft + iWidth > iMaxWidth ) iLeft = iMaxWidth - iWidth;
	    if ( iTop + iHeight > iMaxHeight ) iTop = iMaxHeight - iHeight;
#endif

        // Create the main window
        //
        if (BOINC_ADVANCEDGUI == iGUISelection) {
            // Initialize the advanced gui window
            pNewFrame = new CAdvancedFrame(
                m_pSkinManager->GetAdvanced()->GetApplicationName(), 
                m_pSkinManager->GetAdvanced()->GetApplicationIcon(),
                m_pSkinManager->GetAdvanced()->GetApplicationIcon32(),
                wxPoint(iLeft, iTop),
                wxSize(iWidth, iHeight)
            );
        } else {
            // Initialize the simple gui window
            pNewFrame = new CSimpleFrame(
                m_pSkinManager->GetAdvanced()->GetApplicationName(), 
                m_pSkinManager->GetAdvanced()->GetApplicationIcon(),
                m_pSkinManager->GetAdvanced()->GetApplicationIcon32(),
                wxPoint(iLeft, iTop),
                wxSize(iWidth, iHeight)
            );
        }

        wxASSERT(pNewFrame);

        if (pNewFrame) {
            SetTopWindow(pNewFrame);

            // Store the new frame for future use
            m_pFrame = pNewFrame;

            // Hide the old one if it exists.  We must do this 
            // after updating m_pFrame to prevent Mac OSX from
            // hiding the application
            if (pOldFrame) pOldFrame->Hide();

            // Delete the old one if it exists
            // Note: this has the side effect of hiding the Event Log
            if (pOldFrame) pOldFrame->Destroy();

            // Show the new frame if needed (and show the Event Log if open)
            if (pNewFrame && bShowWindow) pNewFrame->Show();
        }
    }

    // Show the new frame if needed 
    if (m_pFrame && bShowWindow) {
        if (m_pEventLog) {
            m_pEventLog->Show();
            m_pEventLog->Raise();
#ifdef __WXMSW__
            ::SetForegroundWindow((HWND)m_pEventLog->GetHWND());
#endif
        }

        if (!m_pFrame->IsShown()) {
            m_pFrame->Show();
        }
        m_pFrame->Raise();

#ifdef __WXMSW__
        ::SetForegroundWindow((HWND)m_pFrame->GetHWND());
#endif
    }

    m_iGUISelected = iGUISelection;
    m_pConfig->SetPath(wxT("/"));
    m_pConfig->Write(wxT("GUISelection"), iGUISelection);

    return true;
}
示例#12
0
bool CDlgOptions::SaveSettings() {
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    CSkinAdvanced*      pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    long                lBuffer = 0;
    wxString            strBuffer = wxEmptyString;


    wxASSERT(pDoc);
    wxASSERT(pFrame);
    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));


    // General Tab
    if (pFrame->GetSelectedLanguage() != m_LanguageSelectionCtrl->GetSelection()) {
        wxString strDialogTitle;
        wxString strDialogMessage;

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

        // %s is the application name
        //    i.e. 'BOINC Manager', 'GridRepublic Manager'
        strDialogMessage.Printf(
            _("The %s's default language has been changed, in order for this change to take affect you must restart the %s."),
            pSkinAdvanced->GetApplicationName().c_str(),
            pSkinAdvanced->GetApplicationName().c_str()
        );

        pFrame->ShowAlert(
            strDialogTitle,
            strDialogMessage,
            wxOK | wxICON_INFORMATION
        );
    }

    pFrame->SetSelectedLanguage(m_LanguageSelectionCtrl->GetSelection());

    switch(m_ReminderFrequencyCtrl->GetSelection()) {
        case 0:
            pFrame->SetReminderFrequency(1);
            break;
        case 1:
            pFrame->SetReminderFrequency(60);
            break;
        case 2:
            pFrame->SetReminderFrequency(360);
            break;
        case 3:
            pFrame->SetReminderFrequency(1440);
            break;
        case 4:
            pFrame->SetReminderFrequency(10080);
            break;
        case 5:
            pFrame->SetReminderFrequency(0);
            break;
    }

    wxGetApp().SetBOINCMGRDisplayExitMessage(m_EnableBOINCManagerExitMessageCtrl->GetValue());
#ifdef __WXMSW__
    wxGetApp().SetBOINCMGRDisableAutoStart(!m_EnableBOINCManagerAutoStartCtrl->GetValue());

    // Connection Tab
    pFrame->SetDialupConnectionName(GetDefaultDialupConnection());
#endif

    // Proxy Tabs
    if (m_bRetrievedProxyConfiguration) {
        pDoc->proxy_info.use_http_proxy = m_EnableHTTPProxyCtrl->GetValue();
        pDoc->proxy_info.http_server_name = (const char*)m_HTTPAddressCtrl->GetValue().mb_str();
        pDoc->proxy_info.http_user_name = (const char*)m_HTTPUsernameCtrl->GetValue().mb_str();
        pDoc->proxy_info.http_user_passwd = (const char*)m_HTTPPasswordCtrl->GetValue().mb_str();
		if(pDoc->proxy_info.use_http_proxy) {
			pDoc->proxy_info.noproxy_hosts = (const char*)m_HTTPNoProxiesCtrl->GetValue().mb_str();
		}
        strBuffer = m_HTTPPortCtrl->GetValue();
        strBuffer.ToLong((long*)&lBuffer);
        pDoc->proxy_info.http_server_port = lBuffer;

        pDoc->proxy_info.use_socks_proxy = m_EnableSOCKSProxyCtrl->GetValue();
        pDoc->proxy_info.socks_server_name = (const char*)m_SOCKSAddressCtrl->GetValue().mb_str();
        pDoc->proxy_info.socks5_user_name = (const char*)m_SOCKSUsernameCtrl->GetValue().mb_str();
        pDoc->proxy_info.socks5_user_passwd = (const char*)m_SOCKSPasswordCtrl->GetValue().mb_str();
		if(pDoc->proxy_info.use_socks_proxy) {
			pDoc->proxy_info.noproxy_hosts = (const char*)m_SOCKSNoProxiesCtrl->GetValue().mb_str();
		}
        strBuffer = m_SOCKSPortCtrl->GetValue();
        strBuffer.ToLong((long*)&lBuffer);
        pDoc->proxy_info.socks_server_port = lBuffer;

        pDoc->SetProxyConfiguration();
    }

    return true;
}
示例#13
0
bool CDlgOptions::ReadSettings() {
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    wxString            strBuffer = wxEmptyString;
    wxArrayString       astrDialupConnections;


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


    // General Tab
    m_LanguageSelectionCtrl->Append(wxGetApp().GetSupportedLanguages());
    m_LanguageSelectionCtrl->SetSelection(pFrame->GetSelectedLanguage());

    m_ReminderFrequencyCtrl->Append(_("always"));
    m_ReminderFrequencyCtrl->Append(_("1 hour"));
    m_ReminderFrequencyCtrl->Append(_("6 hours"));
    m_ReminderFrequencyCtrl->Append(_("1 day"));
    m_ReminderFrequencyCtrl->Append(_("1 week"));
    m_ReminderFrequencyCtrl->Append(_("never"));

    switch(pFrame->GetReminderFrequency()) {
        case 1:
            m_ReminderFrequencyCtrl->SetSelection(0);
            break;
        case 60:
            m_ReminderFrequencyCtrl->SetSelection(1);
            break;
        case 360:
            m_ReminderFrequencyCtrl->SetSelection(2);
            break;
        case 1440:
            m_ReminderFrequencyCtrl->SetSelection(3);
            break;
        case 10080:
            m_ReminderFrequencyCtrl->SetSelection(4);
            break;
        case 0:
            m_ReminderFrequencyCtrl->SetSelection(5);
            break;
    }

    //m_ReminderFrequencyCtrl->SetValue(m_iReminderFrequency);

    m_EnableBOINCManagerExitMessageCtrl->SetValue(wxGetApp().GetBOINCMGRDisplayExitMessage() != 0);
#ifdef __WXMSW__
    m_EnableBOINCManagerAutoStartCtrl->SetValue(!wxGetApp().GetBOINCMGRDisableAutoStart());

    // Connection Tab
    if (pFrame) {
        pFrame->GetDialupManager()->GetISPNames(astrDialupConnections);

        m_DialupConnectionsCtrl->Append(astrDialupConnections);
        SetDefaultDialupConnection(pFrame->GetDialupConnectionName());
    } else {
        m_DialupSetDefaultCtrl->Disable();
        m_DialupClearDefaultCtrl->Disable();
    }
#endif

    // Proxy Tabs
    m_bRetrievedProxyConfiguration = (0 == pDoc->GetProxyConfiguration());
    if(!m_bRetrievedProxyConfiguration) {
        // We were unable to get the proxy configuration, so disable
        //   the controls
        m_EnableHTTPProxyCtrl->Enable(false);
        m_EnableSOCKSProxyCtrl->Enable(false);
    } else {
        m_EnableHTTPProxyCtrl->Enable(true);
        m_EnableSOCKSProxyCtrl->Enable(true);
    }

    m_EnableHTTPProxyCtrl->SetValue(pDoc->proxy_info.use_http_proxy);
    m_HTTPAddressCtrl->SetValue(wxString(pDoc->proxy_info.http_server_name.c_str(), wxConvUTF8));
    m_HTTPUsernameCtrl->SetValue(wxString(pDoc->proxy_info.http_user_name.c_str(), wxConvUTF8));
    m_HTTPPasswordCtrl->SetValue(wxString(pDoc->proxy_info.http_user_passwd.c_str(), wxConvUTF8));
	m_HTTPNoProxiesCtrl->SetValue(wxString(pDoc->proxy_info.noproxy_hosts.c_str(), wxConvUTF8));
    strBuffer.Printf(wxT("%d"), pDoc->proxy_info.http_server_port);
    m_HTTPPortCtrl->SetValue(strBuffer);

    m_EnableSOCKSProxyCtrl->SetValue(pDoc->proxy_info.use_socks_proxy);
    m_SOCKSAddressCtrl->SetValue(wxString(pDoc->proxy_info.socks_server_name.c_str(), wxConvUTF8));
    m_SOCKSUsernameCtrl->SetValue(wxString(pDoc->proxy_info.socks5_user_name.c_str(), wxConvUTF8));
    m_SOCKSPasswordCtrl->SetValue(wxString(pDoc->proxy_info.socks5_user_passwd.c_str(), wxConvUTF8));
	m_SOCKSNoProxiesCtrl->SetValue(wxString(pDoc->proxy_info.noproxy_hosts.c_str(),wxConvUTF8));
    strBuffer.Printf(wxT("%d"), pDoc->proxy_info.socks_server_port);
    m_SOCKSPortCtrl->SetValue(strBuffer);

    return true;
}
void CBOINCDialUpManager::OnPoll() {
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    static bool         bAlreadyRunningLoop = false;
    bool                bIsOnline = false;
    bool                bWantConnection = false;
    bool                bWantDisconnect = false;
    wxString            strDialogMessage = wxEmptyString;
    CC_STATUS           cc_status;


    // We are ready to rock and roll.
    if (!bAlreadyRunningLoop && pDoc) {
        wxASSERT(wxDynamicCast(pDoc, CMainDocument));
        wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));

        bAlreadyRunningLoop = true;

        // cache the various states

        // The dialup manager tells us if we are still dialing or if we have
        //   successfully connected.  IsNetworkAlive/IsOnline both report the
        //   success or failure of the dialup device to establish a connection
        //   to the outside world.
        pDoc->GetCoreClientStatus(cc_status);

        bIsOnline = (cc_status.network_status == NETWORK_STATUS_ONLINE);
        bWantConnection = (cc_status.network_status == NETWORK_STATUS_WANT_CONNECTION);
        bWantDisconnect = (cc_status.network_status == NETWORK_STATUS_WANT_DISCONNECT);

        // The timers are used to keep from spamming the user with the same
        //   messages over each iteration of the poll loop.  we only need to
        //   reset them during a connect event in case we randomly loose
        //   a connection.
        if (m_bResetTimers) {
            wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - Resetting dial-up notification timers"));

            m_bResetTimers = false;
            m_bSetConnectionTimer = false;
            ResetReminderTimers();
        }

        // Log out the trace information for debugging purposes.
        /*
        wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - Dialup Flags"));
        wxLogTrace(wxT("Function Status"),
            wxT("CBOINCDialUpManager::poll - -- bIsOnline = '%d', bIsDialing = '%d', m_bWasDialing = '%d', iNetworkStatus = '%d', bWantConnection = '%d'"),
            bIsOnline, bIsDialing, m_bWasDialing, iNetworkStatus, bWantConnection
        );
        wxLogTrace(wxT("Function Status"),
            wxT("CBOINCDialUpManager::poll - -- m_bResetTimers = '%d', m_bNotifyConnectionAvailable = '%d', m_bConnectedSuccessfully = '%d'"),
            m_bResetTimers, m_bNotifyConnectionAvailable, m_bConnectedSuccessfully
        );
        wxLogTrace(wxT("Function Status"),
            wxT("CBOINCDialUpManager::poll - -- confirm_before_connecting = '%d', hangup_if_dialed = '%d'"),
            pDoc->state.global_prefs.confirm_before_connecting, pDoc->state.global_prefs.hangup_if_dialed
        );
        */

#ifndef __WXMSW__           // notification logic for non MS-Windows systems
        if (!bIsOnline && bWantConnection) {
            // Make sure window is visable and active, don't want the message box
            // to pop up on top of anything else
            wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - Notify need Internet Connection"));
            if (pFrame->IsShown() && wxGetApp().IsActive()) {
                NotifyUserNeedConnection(false);
            }
            /*
            // this section commented out until taskbar/systray notification alerts are implemented
                          else {
                            // window is not visible, show alert
                            if (pTaskbar && pTaskbar->IsBalloonsSupported()) {
                                NotifyUserNeedConnection(true);
                            }
                        }
            */
        }
#else               // dialer stuff for MS-Windows systems
        bool  bIsDialing = m_pDialupManager->IsDialing();
        if (!bIsOnline && !bIsDialing && !m_bWasDialing && bWantConnection) {
            wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - !bIsOnline && !bIsDialing && !m_bWasDialing && bWantConnection"));
            if (!pFrame->IsShown()) {
                // BOINC Manager is hidden and displaying a dialog might interupt what they
                //   are doing.
                NotifyUserNeedConnection(true);
            } else {
                // BOINC Manager is visable and can process user input.
                m_bSetConnectionTimer = true;
                Connect();
            }
        } else if (!bIsDialing && !m_bWasDialing) {
            // We are not doing anything now, were we up to something before?
            if (bIsOnline && m_bConnectedSuccessfully && m_bNotifyConnectionAvailable) {
                // Ah ha, we are online and we initiated the connection, so we need to
                //   notify the CC that the network is available.
                wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - bIsOnline && m_bConnectedSuccessfully && m_bNotifyConnectionAvailable"));
                NetworkAvailable();
            } else if (bWantDisconnect && m_bConnectedSuccessfully) {
                // We are online, and the CC says it is safe to disconnect.  Since we
                //   initiated the connection we need to disconnect now.
                wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - bWantDisconnect && m_bConnectedSuccessfully"));
                Disconnect();
            }
        } else if (!bIsDialing && m_bWasDialing) {
            // We initiated a connection attempt and now we are either online or failed to
            //   connect because of a modem error or a users credentials were wrong.
            wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - !bIsDialing && m_bWasDialing"));

            if (m_bSetConnectionTimer) {
                m_bSetConnectionTimer = false;
                m_dtDialupConnectionTimeout = wxDateTime::Now();
                m_iConnectAttemptRetVal = ERR_NO_NETWORK_CONNECTION;
            }

            wxTimeSpan tsTimeout = wxDateTime::Now() - m_dtDialupConnectionTimeout;
            if (30 > tsTimeout.GetSeconds()) {
                if(m_iConnectAttemptRetVal != BOINC_SUCCESS) {
                    return;
                }
            }

            m_bWasDialing = false;
            m_bResetTimers = true;
            if (!m_iConnectAttemptRetVal) {
                ConnectionSucceeded();
            } else {
                ConnectionFailed();
            }
        } else if (bIsDialing && !m_bWasDialing) {
            // Setup the state machine so that it knows when we have finished the connection
            //   attempt.
            wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::poll - bIsDialing && !m_bWasDialing"));
            m_bWasDialing = true;
        }
#endif
        bAlreadyRunningLoop = false;
    }
}
int CBOINCDialUpManager::Connect() {
    CMainDocument*      pDoc = wxGetApp().GetDocument();
    CBOINCBaseFrame*    pFrame = wxGetApp().GetFrame();
    CSkinAdvanced*      pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    wxTimeSpan          tsLastDialupRequest;
    int                 iAnswer;
    wxString            strDialogMessage = wxEmptyString;
    GLOBAL_PREFS_MASK   mask;


    wxASSERT(pDoc);
    wxASSERT(pFrame);
    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    wxASSERT(wxDynamicCast(pFrame, CBOINCBaseFrame));
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));


    tsLastDialupRequest = wxDateTime::Now() - m_dtLastDialupRequest;
    if ((tsLastDialupRequest.GetMinutes() >= pFrame->GetReminderFrequency()) && (pFrame->GetReminderFrequency() != 0)) {
        wxLogTrace(wxT("Function Status"), wxT("CBOINCDialUpManager::Connect - Begin connection process"));
        m_dtLastDialupRequest = wxDateTime::Now();

        if (!pFrame->GetDialupConnectionName().empty()) {
            // We have a valid connection name that we can dial.
            // Update current working preferences (including any overrides) from client
            pDoc->rpc.get_global_prefs_working_struct(pDoc->state.global_prefs, mask);
            if(pDoc->state.global_prefs.confirm_before_connecting) {
                // %s is the project name
                //    i.e. 'BOINC', 'GridRepublic'
                strDialogMessage.Printf(
                    _("%s needs to connect to the Internet.\nMay it do so now?"),
                    pSkinAdvanced->GetApplicationShortName().c_str()
                );
                iAnswer = ::wxMessageBox(
                              strDialogMessage,
                              m_strDialogTitle,
                              wxYES_NO | wxICON_QUESTION,
                              pFrame
                          );
            } else {
                // %s is the project name
                //    i.e. 'BOINC', 'GridRepublic'
                strDialogMessage.Printf(
                    _("%s is connecting to the Internet."),
                    pSkinAdvanced->GetApplicationShortName().c_str()
                );
                pFrame->ShowAlert(
                    m_strDialogTitle,
                    strDialogMessage,
                    wxOK | wxICON_INFORMATION,
                    true
                );
                iAnswer = wxYES;
            }

            // Are we allow to connect?
            if (wxYES == iAnswer) {
                m_bNotifyConnectionAvailable = true;
                m_bConnectedSuccessfully = false;
                m_pDialupManager->Dial(
                    pFrame->GetDialupConnectionName(),
                    wxEmptyString,
                    wxEmptyString,
                    true
                );
            }
        } else {
            // The user hasn't given us a valid connection to dial.  Inform them
            //   that we need a connection and that they may need to set a default
            //   connection.

            // %s is the project name
            //    i.e. 'BOINC', 'GridRepublic'
            strDialogMessage.Printf(
                _("%s couldn't do Internet communication, and no default connection is selected.\n"
                  "Please connect to the Internet, or select a default connection\n"
                  "using Advanced/Options/Connections."),
                pSkinAdvanced->GetApplicationShortName().c_str()
            );

            pFrame->ShowAlert(
                m_strDialogTitle,
                strDialogMessage,
                wxOK | wxICON_INFORMATION,
                false
            );
        }
    }

    return 0;
}