Ticket #1520: action_after_rev1.diff
File action_after_rev1.diff, 12.4 KB (added by , 15 years ago) |
---|
-
src/interface/resources/menus.xrc
171 171 <checkable>1</checkable> 172 172 </object> 173 173 </object> 174 <object class="wxMenu" name="ID_ACTIONAFTER"> 175 <label>Action after queue &completion</label> 176 <object class="wxMenuItem" name="ID_ACTIONAFTER_CLOSE"> 177 <label>&Close FileZilla</label> 178 <checkable>1</checkable> 179 </object> 180 <object class="wxMenuItem" name="ID_ACTIONAFTER_DISCONNECT"> 181 <label>&Disconnect from server</label> 182 <checkable>1</checkable> 183 </object> 184 <object class="wxMenuItem" name="ID_ACTIONAFTER_RUNCOMMAND"> 185 <label>&Run command...</label> 186 <checkable>1</checkable> 187 </object> 188 <object class="wxMenuItem" name="ID_ACTIONAFTER_REBOOT" platform="win"> 189 <label>&Reboot system</label> 190 <checkable>1</checkable> 191 </object> 192 <object class="wxMenuItem" name="ID_ACTIONAFTER_SHUTDOWN" platform="win"> 193 <label>&Shutdown system</label> 194 <checkable>1</checkable> 195 </object> 196 <object class="separator"/> 197 <object class="wxMenuItem" name="ID_ACTIONAFTER_DISABLE" platform="win"> 198 <label>&Do nothing</label> 199 <checkable>1</checkable> 200 </object> 201 </object> 174 202 </object> 175 203 <object class="wxMenu" name="ID_MENU_LOG"> 176 204 <object class="wxMenuItem" name="ID_MENU_SERVER_CMD"> … … 253 281 <help>Change the file permissions.</help> 254 282 </object> 255 283 </object> 256 </resource> 257 No newline at end of file 284 </resource> -
src/interface/QueueView.h
3 3 4 4 #include <set> 5 5 #include "dndobjects.h" 6 #include <wx/progdlg.h> 6 7 7 8 struct t_newEntry 8 9 { … … 12 13 wxLongLong size; 13 14 }; 14 15 16 enum ActionAfterState 17 { 18 ActionAfterState_Disabled, 19 ActionAfterState_Close, 20 ActionAfterState_Disconnect, 21 ActionAfterState_RunCommand, 22 // On Windows, wx can reboot or shutdown the system as well. 23 #ifdef __WXMSW__ 24 ActionAfterState_Reboot, 25 ActionAfterState_Shutdown 26 #endif 27 }; 28 15 29 class CStatusLineCtrl; 16 30 struct t_EngineData 17 31 { … … 108 122 retry, 109 123 remove 110 124 }; 125 126 enum ActionAfterState GetActionAfterState() const; 111 127 112 128 void ResetEngine(t_EngineData& data, const enum ResetReason reason); 113 129 void DeleteEngines(); … … 126 142 void DisplayQueueSize(); 127 143 void SaveQueue(); 128 144 bool ShouldUseBinaryMode(wxString filename); 145 146 bool IsActionAfter(enum ActionAfterState); 147 void ActionAfter(bool warned = false); 148 void ActionAfterWarnUser(wxString message); 129 149 130 150 void ProcessNotification(t_EngineData* pEngineData, CNotification* pNotification); 131 151 … … 158 178 int m_activeCountUp; 159 179 int m_activeMode; // 0 inactive, 1 only immediate transfers, 2 all 160 180 bool m_quit; 181 enum ActionAfterState m_actionAfterState; 182 wxString m_actionAfterRunCommand; 183 wxTimer* m_actionAfterTimer; 184 wxProgressDialog* m_actionAfterWarnDialog; 185 int m_actionAfterTimerCount; 161 186 162 187 wxLongLong m_totalQueueSize; 163 188 int m_filesWithUnknownSize; … … 192 217 void OnSetPriority(wxCommandEvent& event); 193 218 194 219 void OnExclusiveEngineRequestGranted(wxCommandEvent& event); 220 221 void OnActionAfterDisable(wxCommandEvent& event); 222 void OnActionAfterClose(wxCommandEvent& event); 223 void OnActionAfterDisconnect(wxCommandEvent& event); 224 void OnActionAfterRunCommand(wxCommandEvent& event); 225 void OnActionAfterTimerTick(wxTimerEvent & event); 226 #ifdef __WXMSW__ 227 void OnActionAfterReboot(wxCommandEvent& event); 228 void OnActionAfterShutdown(wxCommandEvent& event); 229 #endif 195 230 }; 196 231 197 232 #endif -
src/interface/QueueView.cpp
19 19 #include "queueview_failed.h" 20 20 #include "queueview_successful.h" 21 21 #include "commandqueue.h" 22 #include <wx/utils.h> 23 #include <wx/progdlg.h> 22 24 23 25 #ifdef _DEBUG 24 26 #define new DEBUG_NEW … … 142 144 DECLARE_EVENT_TYPE(fzEVT_ASKFORPASSWORD, -1) 143 145 DEFINE_EVENT_TYPE(fzEVT_ASKFORPASSWORD) 144 146 147 DECLARE_EVENT_TYPE(fzEVT_ACTIONAFTER_WARN, -1) 148 DEFINE_EVENT_TYPE(fzEVT_ACTIONAFTER_WARN) 149 145 150 BEGIN_EVENT_TABLE(CQueueView, CQueueViewBase) 146 151 EVT_FZ_NOTIFICATION(wxID_ANY, CQueueView::OnEngineEvent) 147 152 EVT_COMMAND(wxID_ANY, fzEVT_FOLDERTHREAD_COMPLETE, CQueueView::OnFolderThreadComplete) … … 155 160 EVT_MENU(XRCID("ID_REMOVEALL"), CQueueView::OnStopAndClear) 156 161 EVT_MENU(XRCID("ID_REMOVE"), CQueueView::OnRemoveSelected) 157 162 EVT_MENU(XRCID("ID_DEFAULT_FILEEXISTSACTION"), CQueueView::OnSetDefaultFileExistsAction) 163 EVT_MENU(XRCID("ID_ACTIONAFTER_DISABLE"), CQueueView::OnActionAfterDisable) 164 EVT_MENU(XRCID("ID_ACTIONAFTER_CLOSE"), CQueueView::OnActionAfterClose) 165 EVT_MENU(XRCID("ID_ACTIONAFTER_DISCONNECT"), CQueueView::OnActionAfterDisconnect) 166 EVT_MENU(XRCID("ID_ACTIONAFTER_RUNCOMMAND"), CQueueView::OnActionAfterRunCommand) 167 EVT_MENU(XRCID("ID_ACTIONAFTER_REBOOT"), CQueueView::OnActionAfterReboot) 168 EVT_MENU(XRCID("ID_ACTIONAFTER_SHUTDOWN"), CQueueView::OnActionAfterShutdown) 158 169 159 170 EVT_COMMAND(wxID_ANY, fzEVT_ASKFORPASSWORD, CQueueView::OnAskPassword) 160 171 161 172 EVT_LIST_ITEM_FOCUSED(wxID_ANY, CQueueView::OnFocusItemChanged) 162 173 174 EVT_TIMER(fzEVT_ACTIONAFTER_WARN,CQueueView::OnActionAfterTimerTick) 163 175 EVT_TIMER(wxID_ANY, CQueueView::OnTimer) 164 176 165 177 EVT_MENU(XRCID("ID_PRIORITY_HIGHEST"), CQueueView::OnSetPriority) … … 411 423 412 424 m_totalQueueSize = 0; 413 425 m_filesWithUnknownSize = 0; 426 427 m_actionAfterState = ActionAfterState_Disabled; 414 428 415 429 CreateColumns(_("Status")); 416 430 … … 1404 1418 if (m_activeMode) 1405 1419 { 1406 1420 m_activeMode = 0; 1421 1407 1422 if (!m_pQueue->GetSelection()) 1408 1423 { 1409 1424 CQueueViewBase* pFailed = m_pQueue->GetQueueView_Failed(); … … 1413 1428 else if (pSuccessful->GetItemCount()) 1414 1429 m_pQueue->SetSelection(2); 1415 1430 } 1431 ActionAfter(); 1416 1432 } 1417 1433 1418 1434 if (m_quit) … … 1869 1885 return; 1870 1886 1871 1887 pMenu->Check(XRCID("ID_PROCESSQUEUE"), IsActive() ? true : false); 1888 pMenu->Check(XRCID("ID_ACTIONAFTER_DISABLE"), IsActionAfter(ActionAfterState_Disabled) ? true : false); 1889 pMenu->Check(XRCID("ID_ACTIONAFTER_CLOSE"), IsActionAfter(ActionAfterState_Close) ? true : false); 1890 pMenu->Check(XRCID("ID_ACTIONAFTER_DISCONNECT"), IsActionAfter(ActionAfterState_Disconnect) ? true : false); 1891 pMenu->Check(XRCID("ID_ACTIONAFTER_RUNCOMMAND"), IsActionAfter(ActionAfterState_RunCommand) ? true : false); 1892 #ifdef __WXMSW__ 1893 pMenu->Check(XRCID("ID_ACTIONAFTER_REBOOT"), IsActionAfter(ActionAfterState_Reboot) ? true : false); 1894 pMenu->Check(XRCID("ID_ACTIONAFTER_SHUTDOWN"), IsActionAfter(ActionAfterState_Shutdown) ? true : false); 1895 #endif 1872 1896 pMenu->Enable(XRCID("ID_REMOVE"), GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1); 1873 1897 1874 1898 const bool hasSelection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1; … … 1890 1914 RemoveAll(); 1891 1915 } 1892 1916 1917 void CQueueView::OnActionAfterDisable(wxCommandEvent& event) 1918 { 1919 m_actionAfterState = ActionAfterState_Disabled; 1920 } 1921 1922 void CQueueView::OnActionAfterClose(wxCommandEvent& event) 1923 { 1924 if(event.IsChecked()) 1925 { // goes from non-checked to checked 1926 m_actionAfterState = ActionAfterState_Close; 1927 } 1928 else 1929 { // goes from checked to non-checked 1930 m_actionAfterState = ActionAfterState_Disabled; 1931 } 1932 } 1933 1934 void CQueueView::OnActionAfterDisconnect(wxCommandEvent& event) 1935 { 1936 if(event.IsChecked()) 1937 { // goes from non-checked to checked 1938 m_actionAfterState = ActionAfterState_Disconnect; 1939 } 1940 else 1941 { // goes from checked to non-checked 1942 m_actionAfterState = ActionAfterState_Disabled; 1943 } 1944 } 1945 1946 void CQueueView::OnActionAfterRunCommand(wxCommandEvent& event) 1947 { 1948 if(event.IsChecked()) 1949 { // goes from non-checked to checked 1950 m_actionAfterState = ActionAfterState_RunCommand; 1951 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")); 1952 1953 if (dlg.ShowModal() != wxID_OK) 1954 { 1955 m_actionAfterState = ActionAfterState_Disabled; 1956 return; 1957 } 1958 const wxString &command = dlg.GetValue(); 1959 1960 if (command == _T("")) 1961 { 1962 wxMessageBox(_("No command given, aborting."), _("Empty command"), wxICON_ERROR, m_pMainFrame); 1963 m_actionAfterState = ActionAfterState_Disabled; 1964 return; 1965 } 1966 m_actionAfterRunCommand = command; 1967 } 1968 else 1969 { // goes from checked to non-checked 1970 m_actionAfterState = ActionAfterState_Disabled; 1971 m_actionAfterRunCommand = _T(""); 1972 } 1973 } 1974 1975 #ifdef __WXMSW__ 1976 void CQueueView::OnActionAfterReboot(wxCommandEvent& event) 1977 { 1978 if(event.IsChecked()) // goes from non-checked to checked 1979 { 1980 m_actionAfterState = ActionAfterState_Reboot; 1981 } 1982 else // goes from checked to non-checked 1983 { 1984 m_actionAfterState = ActionAfterState_Disabled; 1985 } 1986 } 1987 1988 void CQueueView::OnActionAfterShutdown(wxCommandEvent& event) 1989 { 1990 if(event.IsChecked()) // goes from non-checked to checked 1991 { 1992 m_actionAfterState = ActionAfterState_Shutdown; 1993 } 1994 else // goes from checked to non-checked 1995 { 1996 m_actionAfterState = ActionAfterState_Disabled; 1997 } 1998 } 1999 #endif 2000 1893 2001 void CQueueView::RemoveAll() 1894 2002 { 1895 2003 // This function removes all inactive items and queues active items … … 1913 2021 } 1914 2022 } 1915 2023 SetItemCount(m_itemCount); 2024 m_actionAfterState = ActionAfterState_Disabled; 1916 2025 1917 2026 m_serverList = newServerList; 1918 2027 UpdateStatusLinePositions(); … … 2487 2596 2488 2597 SendNextCommand(*pEngineData); 2489 2598 } 2599 2600 enum ActionAfterState CQueueView::GetActionAfterState() const 2601 { 2602 return m_actionAfterState; 2603 } 2604 2605 bool CQueueView::IsActionAfter(enum ActionAfterState state) 2606 { 2607 return m_actionAfterState == state; 2608 } 2609 2610 void CQueueView::ActionAfter(bool warned /*=false*/) 2611 { 2612 switch(m_actionAfterState) { 2613 case ActionAfterState_Close: 2614 { 2615 m_pMainFrame->Close(); 2616 break; 2617 } 2618 case ActionAfterState_Disconnect: 2619 { 2620 if (m_pMainFrame->GetState()->IsRemoteConnected() && m_pMainFrame->GetState()->IsRemoteIdle()) 2621 m_pMainFrame->GetState()->m_pCommandQueue->ProcessCommand(new CDisconnectCommand()); 2622 m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. 2623 break; 2624 } 2625 case ActionAfterState_RunCommand: 2626 { 2627 wxExecute(m_actionAfterRunCommand); 2628 m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. 2629 break; 2630 } 2631 #ifdef __WXMSW__ 2632 case ActionAfterState_Reboot: 2633 { 2634 if(!warned) 2635 ActionAfterWarnUser(_T("The system will soon reboot unless you press cancel.")); 2636 else 2637 wxShutdown(wxSHUTDOWN_REBOOT); 2638 break; 2639 } 2640 2641 case ActionAfterState_Shutdown: 2642 { 2643 if(!warned) 2644 ActionAfterWarnUser(_T("The system will soon shutdown unless you press cancel.")); 2645 else 2646 wxShutdown(wxSHUTDOWN_POWEROFF); 2647 break; 2648 } 2649 #endif 2650 case ActionAfterState_Disabled: 2651 { 2652 m_actionAfterState = ActionAfterState_Disabled; // Resetting the state. 2653 break; 2654 } 2655 } 2656 2657 } 2658 2659 void CQueueView::ActionAfterWarnUser(wxString message) 2660 { 2661 m_actionAfterWarnDialog = new wxProgressDialog(_T("Queue completion dialog"),message,150,m_pMainFrame,wxPD_CAN_ABORT | wxPD_AUTO_HIDE | wxPD_CAN_SKIP); 2662 wxSize dialogSize = m_actionAfterWarnDialog->GetSize(); 2663 m_actionAfterWarnDialog->SetSize(dialogSize.GetWidth()/2,dialogSize.GetHeight()); 2664 m_actionAfterWarnDialog->CentreOnParent(); 2665 m_actionAfterWarnDialog->SetFocus(); 2666 m_pMainFrame->RequestUserAttention(wxUSER_ATTENTION_ERROR); 2667 2668 m_actionAfterTimer = new wxTimer(this,fzEVT_ACTIONAFTER_WARN); 2669 m_actionAfterTimerCount = 0; 2670 m_actionAfterTimer->Start(100,wxTIMER_CONTINUOUS); 2671 } 2672 2673 void CQueueView::OnActionAfterTimerTick(wxTimerEvent& event) 2674 { 2675 bool skipped = false; 2676 if(m_actionAfterTimerCount > 150) 2677 this->ActionAfter(true); 2678 else if(!m_actionAfterWarnDialog->Update(m_actionAfterTimerCount++,_T(""),&skipped)) 2679 { 2680 // User has pressed cancel! 2681 m_actionAfterState = ActionAfterState_Disabled; // resetting to disabled 2682 m_actionAfterWarnDialog->Destroy(); 2683 delete m_actionAfterTimer; 2684 } 2685 else if(skipped) 2686 this->ActionAfter(true); 2687 }