| 164 | EVT_MENU(XRCID("ID_ACTIONAFTER_DISABLE"), CQueueView::OnActionAfter) |
| 165 | EVT_MENU(XRCID("ID_ACTIONAFTER_CLOSE"), CQueueView::OnActionAfter) |
| 166 | EVT_MENU(XRCID("ID_ACTIONAFTER_DISCONNECT"), CQueueView::OnActionAfter) |
| 167 | EVT_MENU(XRCID("ID_ACTIONAFTER_RUNCOMMAND"), CQueueView::OnActionAfter) |
| 168 | EVT_MENU(XRCID("ID_ACTIONAFTER_SHOWMESSAGE"), CQueueView::OnActionAfter) |
| 169 | EVT_MENU(XRCID("ID_ACTIONAFTER_PLAYSOUND"), CQueueView::OnActionAfter) |
| 170 | EVT_MENU(XRCID("ID_ACTIONAFTER_REBOOT"), CQueueView::OnActionAfter) |
| 171 | EVT_MENU(XRCID("ID_ACTIONAFTER_SHUTDOWN"), CQueueView::OnActionAfter) |
| 1890 | pMenu->Check(XRCID("ID_ACTIONAFTER_DISABLE"), IsActionAfter(ActionAfterState_Disabled)); |
| 1891 | pMenu->Check(XRCID("ID_ACTIONAFTER_CLOSE"), IsActionAfter(ActionAfterState_Close)); |
| 1892 | pMenu->Check(XRCID("ID_ACTIONAFTER_DISCONNECT"), IsActionAfter(ActionAfterState_Disconnect)); |
| 1893 | pMenu->Check(XRCID("ID_ACTIONAFTER_RUNCOMMAND"), IsActionAfter(ActionAfterState_RunCommand)); |
| 1894 | pMenu->Check(XRCID("ID_ACTIONAFTER_SHOWMESSAGE"), IsActionAfter(ActionAfterState_ShowMessage)); |
| 1895 | pMenu->Check(XRCID("ID_ACTIONAFTER_PLAYSOUND"), IsActionAfter(ActionAfterState_PlaySound)); |
| 1896 | #ifdef __WXMSW__ |
| 1897 | pMenu->Check(XRCID("ID_ACTIONAFTER_REBOOT"), IsActionAfter(ActionAfterState_Reboot)); |
| 1898 | pMenu->Check(XRCID("ID_ACTIONAFTER_SHUTDOWN"), IsActionAfter(ActionAfterState_Shutdown)); |
| 1899 | #endif |
| 1921 | void CQueueView::OnActionAfter(wxCommandEvent& event) |
| 1922 | { |
| 1923 | if (!event.IsChecked() || event.GetId() == XRCID("ID_ACTIONAFTER_DISABLE")) |
| 1924 | { // Goes from checked to non-checked or disable is pressed |
| 1925 | m_actionAfterState = ActionAfterState_Disabled; |
| 1926 | m_actionAfterRunCommand = _T(""); |
| 1927 | } |
| 1928 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_DISABLE")) |
| 1929 | m_actionAfterState = ActionAfterState_Disabled; |
| 1930 | |
| 1931 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_CLOSE")) |
| 1932 | m_actionAfterState = ActionAfterState_Close; |
| 1933 | |
| 1934 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_DISCONNECT")) |
| 1935 | m_actionAfterState = ActionAfterState_Disconnect; |
| 1936 | |
| 1937 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_SHOWMESSAGE")) |
| 1938 | m_actionAfterState = ActionAfterState_ShowMessage; |
| 1939 | |
| 1940 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_PLAYSOUND")) |
| 1941 | m_actionAfterState = ActionAfterState_PlaySound; |
| 1942 | |
| 1943 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_RUNCOMMAND")) |
| 1944 | { |
| 1945 | m_actionAfterState = ActionAfterState_RunCommand; |
| 1946 | wxTextEntryDialog dlg(m_pMainFrame, _("Please enter a path and executable to run.\nE.g. c:\\somePath\\file.exe under MS Windows or /somePath/file under Unix.\nYou can also optionally specify program arguments."), _("Enter command")); |
| 1947 | |
| 1948 | if (dlg.ShowModal() != wxID_OK) |
| 1949 | { |
| 1950 | m_actionAfterState = ActionAfterState_Disabled; |
| 1951 | return; |
| 1952 | } |
| 1953 | const wxString &command = dlg.GetValue(); |
| 1954 | |
| 1955 | if (command == _T("")) |
| 1956 | { |
| 1957 | wxMessageBox(_("No command given, aborting."), _("Empty command"), wxICON_ERROR, m_pMainFrame); |
| 1958 | m_actionAfterState = ActionAfterState_Disabled; |
| 1959 | return; |
| 1960 | } |
| 1961 | m_actionAfterRunCommand = command; |
| 1962 | } |
| 1963 | |
| 1964 | #ifdef __WXMSW__ |
| 1965 | |
| 1966 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_REBOOT")) |
| 1967 | m_actionAfterState = ActionAfterState_Reboot; |
| 1968 | |
| 1969 | else if (event.GetId() == XRCID("ID_ACTIONAFTER_SHUTDOWN")) |
| 1970 | m_actionAfterState = ActionAfterState_Shutdown; |
| 1971 | |
| 1972 | #endif |
| 1973 | |
| 1974 | } |
| 1975 | |
| 2574 | |
| 2575 | enum ActionAfterState CQueueView::GetActionAfterState() const |
| 2576 | { |
| 2577 | return m_actionAfterState; |
| 2578 | } |
| 2579 | |
| 2580 | bool CQueueView::IsActionAfter(enum ActionAfterState state) |
| 2581 | { |
| 2582 | return m_actionAfterState == state; |
| 2583 | } |
| 2584 | |
| 2585 | void CQueueView::ActionAfter(bool warned /*=false*/) |
| 2586 | { |
| 2587 | switch(m_actionAfterState) |
| 2588 | { |
| 2589 | case ActionAfterState_Close: |
| 2590 | { |
| 2591 | //m_pMainFrame->Close(); |
| 2592 | wxSound(_T("resources/finished.wav")).Play(wxSOUND_ASYNC); |
| 2593 | break; |
| 2594 | } |
| 2595 | case ActionAfterState_Disconnect: |
| 2596 | { |
| 2597 | if (m_pMainFrame->GetState()->IsRemoteConnected() && m_pMainFrame->GetState()->IsRemoteIdle()) |
| 2598 | m_pMainFrame->GetState()->m_pCommandQueue->ProcessCommand(new CDisconnectCommand()); |
| 2599 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2600 | break; |
| 2601 | } |
| 2602 | case ActionAfterState_RunCommand: |
| 2603 | { |
| 2604 | wxExecute(m_actionAfterRunCommand); |
| 2605 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2606 | break; |
| 2607 | } |
| 2608 | case ActionAfterState_ShowMessage: |
| 2609 | { |
| 2610 | wxMessageDialog* dialog = new wxMessageDialog(m_pMainFrame, _T("No more files in the queue!"), _T("Queue completion"), wxOK | wxICON_INFORMATION); |
| 2611 | dialog->ShowModal(); |
| 2612 | m_pMainFrame->RequestUserAttention(wxUSER_ATTENTION_ERROR); |
| 2613 | |
| 2614 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2615 | break; |
| 2616 | } |
| 2617 | case ActionAfterState_PlaySound: |
| 2618 | { |
| 2619 | wxSound(wxGetApp().GetResourceDir() + _T("finished.wav")).Play(wxSOUND_ASYNC); |
| 2620 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2621 | break; |
| 2622 | } |
| 2623 | #ifdef __WXMSW__ |
| 2624 | case ActionAfterState_Reboot: |
| 2625 | { |
| 2626 | if (!warned) |
| 2627 | ActionAfterWarnUser(_T("The system will soon reboot unless you press cancel.")); |
| 2628 | else |
| 2629 | wxShutdown(wxSHUTDOWN_REBOOT); |
| 2630 | break; |
| 2631 | } |
| 2632 | |
| 2633 | case ActionAfterState_Shutdown: |
| 2634 | { |
| 2635 | if (!warned) |
| 2636 | ActionAfterWarnUser(_T("The system will soon shutdown unless you press cancel.")); |
| 2637 | else |
| 2638 | wxShutdown(wxSHUTDOWN_POWEROFF); |
| 2639 | break; |
| 2640 | } |
| 2641 | #endif |
| 2642 | case ActionAfterState_Disabled: |
| 2643 | { |
| 2644 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2645 | break; |
| 2646 | } |
| 2647 | } |
| 2648 | } |
| 2649 | |
| 2650 | void CQueueView::ActionAfterWarnUser(wxString message) |
| 2651 | { |
| 2652 | m_actionAfterWarnDialog = new wxProgressDialog(_T("Queue completion dialog"), message, 150, m_pMainFrame, wxPD_CAN_ABORT | wxPD_AUTO_HIDE | wxPD_CAN_SKIP); |
| 2653 | wxSize dialogSize = m_actionAfterWarnDialog->GetSize(); |
| 2654 | m_actionAfterWarnDialog->SetSize(dialogSize.GetWidth() / 2, dialogSize.GetHeight()); |
| 2655 | m_actionAfterWarnDialog->CentreOnParent(); |
| 2656 | m_actionAfterWarnDialog->SetFocus(); |
| 2657 | m_pMainFrame->RequestUserAttention(wxUSER_ATTENTION_ERROR); |
| 2658 | |
| 2659 | m_actionAfterTimer = new wxTimer(this,fzEVT_ACTIONAFTER_WARN); |
| 2660 | m_actionAfterTimerCount = 0; |
| 2661 | m_actionAfterTimer->Start(100, wxTIMER_CONTINUOUS); |
| 2662 | } |
| 2663 | |
| 2664 | void CQueueView::OnActionAfterTimerTick(wxTimerEvent& event) |
| 2665 | { |
| 2666 | bool skipped = false; |
| 2667 | if (m_actionAfterTimerCount > 150) |
| 2668 | { |
| 2669 | m_actionAfterWarnDialog->Destroy(); |
| 2670 | delete m_actionAfterTimer; |
| 2671 | this->ActionAfter(true); |
| 2672 | } |
| 2673 | else if (!m_actionAfterWarnDialog->Update(m_actionAfterTimerCount++, _T(""), &skipped)) |
| 2674 | { |
| 2675 | // User has pressed cancel! |
| 2676 | m_actionAfterState = ActionAfterState_Disabled; // resetting to disabled |
| 2677 | m_actionAfterWarnDialog->Destroy(); |
| 2678 | delete m_actionAfterTimer; |
| 2679 | } |
| 2680 | else if (skipped) |
| 2681 | { |
| 2682 | m_actionAfterWarnDialog->Destroy(); |
| 2683 | delete m_actionAfterTimer; |
| 2684 | this->ActionAfter(true); |
| 2685 | } |
| 2686 | |
| 2687 | } |