| 164 | EVT_MENU(XRCID("ID_ACTIONAFTER_DISABLE"), CQueueView::OnActionAfterDisable) |
| 165 | EVT_MENU(XRCID("ID_ACTIONAFTER_CLOSE"), CQueueView::OnActionAfterClose) |
| 166 | EVT_MENU(XRCID("ID_ACTIONAFTER_DISCONNECT"), CQueueView::OnActionAfterDisconnect) |
| 167 | EVT_MENU(XRCID("ID_ACTIONAFTER_RUNCOMMAND"), CQueueView::OnActionAfterRunCommand) |
| 168 | EVT_MENU(XRCID("ID_ACTIONAFTER_SHOWMESSAGE"), CQueueView::OnActionAfterShowMessage) |
| 169 | EVT_MENU(XRCID("ID_ACTIONAFTER_PLAYSOUND"), CQueueView::OnActionAfterPlaySound) |
| 170 | EVT_MENU(XRCID("ID_ACTIONAFTER_REBOOT"), CQueueView::OnActionAfterReboot) |
| 171 | EVT_MENU(XRCID("ID_ACTIONAFTER_SHUTDOWN"), CQueueView::OnActionAfterShutdown) |
| 1890 | pMenu->Check(XRCID("ID_ACTIONAFTER_DISABLE"), IsActionAfter(ActionAfterState_Disabled) ? true : false); |
| 1891 | pMenu->Check(XRCID("ID_ACTIONAFTER_CLOSE"), IsActionAfter(ActionAfterState_Close) ? true : false); |
| 1892 | pMenu->Check(XRCID("ID_ACTIONAFTER_DISCONNECT"), IsActionAfter(ActionAfterState_Disconnect) ? true : false); |
| 1893 | pMenu->Check(XRCID("ID_ACTIONAFTER_RUNCOMMAND"), IsActionAfter(ActionAfterState_RunCommand) ? true : false); |
| 1894 | pMenu->Check(XRCID("ID_ACTIONAFTER_SHOWMESSAGE"), IsActionAfter(ActionAfterState_ShowMessage) ? true : false); |
| 1895 | pMenu->Check(XRCID("ID_ACTIONAFTER_PLAYSOUND"), IsActionAfter(ActionAfterState_PlaySound) ? true : false); |
| 1896 | #ifdef __WXMSW__ |
| 1897 | pMenu->Check(XRCID("ID_ACTIONAFTER_REBOOT"), IsActionAfter(ActionAfterState_Reboot) ? true : false); |
| 1898 | pMenu->Check(XRCID("ID_ACTIONAFTER_SHUTDOWN"), IsActionAfter(ActionAfterState_Shutdown) ? true : false); |
| 1899 | #endif |
| 1921 | void CQueueView::OnActionAfterDisable(wxCommandEvent& event) |
| 1922 | { |
| 1923 | m_actionAfterState = ActionAfterState_Disabled; |
| 1924 | } |
| 1925 | |
| 1926 | void CQueueView::OnActionAfterClose(wxCommandEvent& event) |
| 1927 | { |
| 1928 | if(event.IsChecked()) |
| 1929 | { // goes from non-checked to checked |
| 1930 | m_actionAfterState = ActionAfterState_Close; |
| 1931 | } |
| 1932 | else |
| 1933 | { // goes from checked to non-checked |
| 1934 | m_actionAfterState = ActionAfterState_Disabled; |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | void CQueueView::OnActionAfterDisconnect(wxCommandEvent& event) |
| 1939 | { |
| 1940 | if(event.IsChecked()) |
| 1941 | { // goes from non-checked to checked |
| 1942 | m_actionAfterState = ActionAfterState_Disconnect; |
| 1943 | } |
| 1944 | else |
| 1945 | { // goes from checked to non-checked |
| 1946 | m_actionAfterState = ActionAfterState_Disabled; |
| 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | void CQueueView::OnActionAfterRunCommand(wxCommandEvent& event) |
| 1951 | { |
| 1952 | if(event.IsChecked()) |
| 1953 | { // goes from non-checked to checked |
| 1954 | m_actionAfterState = ActionAfterState_RunCommand; |
| 1955 | 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")); |
| 1956 | |
| 1957 | if (dlg.ShowModal() != wxID_OK) |
| 1958 | { |
| 1959 | m_actionAfterState = ActionAfterState_Disabled; |
| 1960 | return; |
| 1961 | } |
| 1962 | const wxString &command = dlg.GetValue(); |
| 1963 | |
| 1964 | if (command == _T("")) |
| 1965 | { |
| 1966 | wxMessageBox(_("No command given, aborting."), _("Empty command"), wxICON_ERROR, m_pMainFrame); |
| 1967 | m_actionAfterState = ActionAfterState_Disabled; |
| 1968 | return; |
| 1969 | } |
| 1970 | m_actionAfterRunCommand = command; |
| 1971 | } |
| 1972 | else |
| 1973 | { // goes from checked to non-checked |
| 1974 | m_actionAfterState = ActionAfterState_Disabled; |
| 1975 | m_actionAfterRunCommand = _T(""); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | void CQueueView::OnActionAfterShowMessage(wxCommandEvent& event) |
| 1980 | { |
| 1981 | if(event.IsChecked()) |
| 1982 | { // goes from non-checked to checked |
| 1983 | m_actionAfterState = ActionAfterState_ShowMessage; |
| 1984 | } |
| 1985 | else |
| 1986 | { // goes from checked to non-checked |
| 1987 | m_actionAfterState = ActionAfterState_Disabled; |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | void CQueueView::OnActionAfterPlaySound(wxCommandEvent& event) |
| 1992 | { |
| 1993 | if(event.IsChecked()) |
| 1994 | { // goes from non-checked to checked |
| 1995 | m_actionAfterState = ActionAfterState_PlaySound; |
| 1996 | } |
| 1997 | else |
| 1998 | { // goes from checked to non-checked |
| 1999 | m_actionAfterState = ActionAfterState_Disabled; |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | #ifdef __WXMSW__ |
| 2004 | void CQueueView::OnActionAfterReboot(wxCommandEvent& event) |
| 2005 | { |
| 2006 | if(event.IsChecked()) // goes from non-checked to checked |
| 2007 | { |
| 2008 | m_actionAfterState = ActionAfterState_Reboot; |
| 2009 | } |
| 2010 | else // goes from checked to non-checked |
| 2011 | { |
| 2012 | m_actionAfterState = ActionAfterState_Disabled; |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | void CQueueView::OnActionAfterShutdown(wxCommandEvent& event) |
| 2017 | { |
| 2018 | if(event.IsChecked()) // goes from non-checked to checked |
| 2019 | { |
| 2020 | m_actionAfterState = ActionAfterState_Shutdown; |
| 2021 | } |
| 2022 | else // goes from checked to non-checked |
| 2023 | { |
| 2024 | m_actionAfterState = ActionAfterState_Disabled; |
| 2025 | } |
| 2026 | } |
| 2027 | #endif |
| 2028 | |
| 2627 | |
| 2628 | enum ActionAfterState CQueueView::GetActionAfterState() const |
| 2629 | { |
| 2630 | return m_actionAfterState; |
| 2631 | } |
| 2632 | |
| 2633 | bool CQueueView::IsActionAfter(enum ActionAfterState state) |
| 2634 | { |
| 2635 | return m_actionAfterState == state; |
| 2636 | } |
| 2637 | |
| 2638 | void CQueueView::ActionAfter(bool warned /*=false*/) |
| 2639 | { |
| 2640 | switch(m_actionAfterState) |
| 2641 | { |
| 2642 | case ActionAfterState_Close: |
| 2643 | { |
| 2644 | //m_pMainFrame->Close(); |
| 2645 | wxSound(_T("resources/finished.wav")).Play(wxSOUND_ASYNC); |
| 2646 | break; |
| 2647 | } |
| 2648 | case ActionAfterState_Disconnect: |
| 2649 | { |
| 2650 | if (m_pMainFrame->GetState()->IsRemoteConnected() && m_pMainFrame->GetState()->IsRemoteIdle()) |
| 2651 | m_pMainFrame->GetState()->m_pCommandQueue->ProcessCommand(new CDisconnectCommand()); |
| 2652 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2653 | break; |
| 2654 | } |
| 2655 | case ActionAfterState_RunCommand: |
| 2656 | { |
| 2657 | wxExecute(m_actionAfterRunCommand); |
| 2658 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2659 | break; |
| 2660 | } |
| 2661 | case ActionAfterState_ShowMessage: |
| 2662 | { |
| 2663 | wxMessageDialog* dialog = new wxMessageDialog(m_pMainFrame, _T("No more files in the queue!"), _T("Queue completion"), wxOK | wxICON_INFORMATION); |
| 2664 | dialog->ShowModal(); |
| 2665 | m_pMainFrame->RequestUserAttention(wxUSER_ATTENTION_ERROR); |
| 2666 | |
| 2667 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2668 | break; |
| 2669 | } |
| 2670 | case ActionAfterState_PlaySound: |
| 2671 | { |
| 2672 | wxSound(wxGetApp().GetResourceDir() + _T("finished.wav")).Play(wxSOUND_ASYNC); |
| 2673 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2674 | break; |
| 2675 | } |
| 2676 | #ifdef __WXMSW__ |
| 2677 | case ActionAfterState_Reboot: |
| 2678 | { |
| 2679 | if(!warned) |
| 2680 | ActionAfterWarnUser(_T("The system will soon reboot unless you press cancel.")); |
| 2681 | else |
| 2682 | wxShutdown(wxSHUTDOWN_REBOOT); |
| 2683 | break; |
| 2684 | } |
| 2685 | |
| 2686 | case ActionAfterState_Shutdown: |
| 2687 | { |
| 2688 | if(!warned) |
| 2689 | ActionAfterWarnUser(_T("The system will soon shutdown unless you press cancel.")); |
| 2690 | else |
| 2691 | wxShutdown(wxSHUTDOWN_POWEROFF); |
| 2692 | break; |
| 2693 | } |
| 2694 | #endif |
| 2695 | case ActionAfterState_Disabled: |
| 2696 | { |
| 2697 | m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. |
| 2698 | break; |
| 2699 | } |
| 2700 | } |
| 2701 | } |
| 2702 | |
| 2703 | void CQueueView::ActionAfterWarnUser(wxString message) |
| 2704 | { |
| 2705 | m_actionAfterWarnDialog = new wxProgressDialog(_T("Queue completion dialog"), message, 150, m_pMainFrame, wxPD_CAN_ABORT | wxPD_AUTO_HIDE | wxPD_CAN_SKIP); |
| 2706 | wxSize dialogSize = m_actionAfterWarnDialog->GetSize(); |
| 2707 | m_actionAfterWarnDialog->SetSize(dialogSize.GetWidth() / 2, dialogSize.GetHeight()); |
| 2708 | m_actionAfterWarnDialog->CentreOnParent(); |
| 2709 | m_actionAfterWarnDialog->SetFocus(); |
| 2710 | m_pMainFrame->RequestUserAttention(wxUSER_ATTENTION_ERROR); |
| 2711 | |
| 2712 | m_actionAfterTimer = new wxTimer(this,fzEVT_ACTIONAFTER_WARN); |
| 2713 | m_actionAfterTimerCount = 0; |
| 2714 | m_actionAfterTimer->Start(100, wxTIMER_CONTINUOUS); |
| 2715 | } |
| 2716 | |
| 2717 | void CQueueView::OnActionAfterTimerTick(wxTimerEvent& event) |
| 2718 | { |
| 2719 | bool skipped = false; |
| 2720 | if(m_actionAfterTimerCount > 150) |
| 2721 | { |
| 2722 | m_actionAfterWarnDialog->Destroy(); |
| 2723 | delete m_actionAfterTimer; |
| 2724 | this->ActionAfter(true); |
| 2725 | } |
| 2726 | else if(!m_actionAfterWarnDialog->Update(m_actionAfterTimerCount++, _T(""), &skipped)) |
| 2727 | { |
| 2728 | // User has pressed cancel! |
| 2729 | m_actionAfterState = ActionAfterState_Disabled; // resetting to disabled |
| 2730 | m_actionAfterWarnDialog->Destroy(); |
| 2731 | delete m_actionAfterTimer; |
| 2732 | } |
| 2733 | else if(skipped) |
| 2734 | { |
| 2735 | m_actionAfterWarnDialog->Destroy(); |
| 2736 | delete m_actionAfterTimer; |
| 2737 | this->ActionAfter(true); |
| 2738 | } |
| 2739 | |
| 2740 | } |