Ticket #1520: action_after_rev1.diff

File action_after_rev1.diff, 12.4 KB (added by Eirik, 12 years ago)

The diff

  • src/interface/resources/menus.xrc

     
    171171        <checkable>1</checkable>
    172172      </object>
    173173    </object>
     174    <object class="wxMenu" name="ID_ACTIONAFTER">
     175      <label>Action after queue &amp;completion</label>
     176      <object class="wxMenuItem" name="ID_ACTIONAFTER_CLOSE">
     177        <label>&amp;Close FileZilla</label>
     178        <checkable>1</checkable>
     179      </object>
     180      <object class="wxMenuItem" name="ID_ACTIONAFTER_DISCONNECT">
     181        <label>&amp;Disconnect from server</label>
     182        <checkable>1</checkable>
     183      </object>
     184      <object class="wxMenuItem" name="ID_ACTIONAFTER_RUNCOMMAND">
     185        <label>&amp;Run command...</label>
     186        <checkable>1</checkable>
     187      </object>
     188      <object class="wxMenuItem" name="ID_ACTIONAFTER_REBOOT" platform="win">
     189        <label>&amp;Reboot system</label>
     190        <checkable>1</checkable>
     191      </object>
     192      <object class="wxMenuItem" name="ID_ACTIONAFTER_SHUTDOWN" platform="win">
     193        <label>&amp;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>&amp;Do nothing</label>
     199        <checkable>1</checkable>
     200      </object>
     201    </object>
    174202  </object>
    175203  <object class="wxMenu" name="ID_MENU_LOG">
    176204    <object class="wxMenuItem" name="ID_MENU_SERVER_CMD">
     
    253281      <help>Change the file permissions.</help>
    254282    </object>
    255283  </object>
    256 </resource>
    257  No newline at end of file
     284</resource>
  • src/interface/QueueView.h

     
    33
    44#include <set>
    55#include "dndobjects.h"
     6#include <wx/progdlg.h>
    67
    78struct t_newEntry
    89{
     
    1213    wxLongLong size;
    1314};
    1415
     16enum 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
    1529class CStatusLineCtrl;
    1630struct t_EngineData
    1731{
     
    108122        retry,
    109123        remove
    110124    };
     125   
     126  enum ActionAfterState GetActionAfterState() const;
    111127
    112128    void ResetEngine(t_EngineData& data, const enum ResetReason reason);
    113129    void DeleteEngines();
     
    126142    void DisplayQueueSize();
    127143    void SaveQueue();
    128144    bool ShouldUseBinaryMode(wxString filename);
     145   
     146 bool IsActionAfter(enum ActionAfterState);
     147 void ActionAfter(bool warned = false);
     148 void ActionAfterWarnUser(wxString message);
    129149
    130150    void ProcessNotification(t_EngineData* pEngineData, CNotification* pNotification);
    131151
     
    158178    int m_activeCountUp;
    159179    int m_activeMode; // 0 inactive, 1 only immediate transfers, 2 all
    160180    bool m_quit;
     181    enum ActionAfterState m_actionAfterState;
     182    wxString m_actionAfterRunCommand;
     183    wxTimer* m_actionAfterTimer;
     184 wxProgressDialog* m_actionAfterWarnDialog;
     185 int m_actionAfterTimerCount;
    161186
    162187    wxLongLong m_totalQueueSize;
    163188    int m_filesWithUnknownSize;
     
    192217    void OnSetPriority(wxCommandEvent& event);
    193218
    194219    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
    195230};
    196231
    197232#endif
  • src/interface/QueueView.cpp

     
    1919#include "queueview_failed.h"
    2020#include "queueview_successful.h"
    2121#include "commandqueue.h"
     22#include <wx/utils.h>
     23#include <wx/progdlg.h>
    2224
    2325#ifdef _DEBUG
    2426#define new DEBUG_NEW
     
    142144DECLARE_EVENT_TYPE(fzEVT_ASKFORPASSWORD, -1)
    143145DEFINE_EVENT_TYPE(fzEVT_ASKFORPASSWORD)
    144146
     147DECLARE_EVENT_TYPE(fzEVT_ACTIONAFTER_WARN, -1)
     148DEFINE_EVENT_TYPE(fzEVT_ACTIONAFTER_WARN)
     149
    145150BEGIN_EVENT_TABLE(CQueueView, CQueueViewBase)
    146151EVT_FZ_NOTIFICATION(wxID_ANY, CQueueView::OnEngineEvent)
    147152EVT_COMMAND(wxID_ANY, fzEVT_FOLDERTHREAD_COMPLETE, CQueueView::OnFolderThreadComplete)
     
    155160EVT_MENU(XRCID("ID_REMOVEALL"), CQueueView::OnStopAndClear)
    156161EVT_MENU(XRCID("ID_REMOVE"), CQueueView::OnRemoveSelected)
    157162EVT_MENU(XRCID("ID_DEFAULT_FILEEXISTSACTION"), CQueueView::OnSetDefaultFileExistsAction)
     163EVT_MENU(XRCID("ID_ACTIONAFTER_DISABLE"), CQueueView::OnActionAfterDisable)
     164EVT_MENU(XRCID("ID_ACTIONAFTER_CLOSE"), CQueueView::OnActionAfterClose)
     165EVT_MENU(XRCID("ID_ACTIONAFTER_DISCONNECT"), CQueueView::OnActionAfterDisconnect)
     166EVT_MENU(XRCID("ID_ACTIONAFTER_RUNCOMMAND"), CQueueView::OnActionAfterRunCommand)
     167EVT_MENU(XRCID("ID_ACTIONAFTER_REBOOT"), CQueueView::OnActionAfterReboot)
     168EVT_MENU(XRCID("ID_ACTIONAFTER_SHUTDOWN"), CQueueView::OnActionAfterShutdown)
    158169
    159170EVT_COMMAND(wxID_ANY, fzEVT_ASKFORPASSWORD, CQueueView::OnAskPassword)
    160171
    161172EVT_LIST_ITEM_FOCUSED(wxID_ANY, CQueueView::OnFocusItemChanged)
    162173
     174EVT_TIMER(fzEVT_ACTIONAFTER_WARN,CQueueView::OnActionAfterTimerTick)
    163175EVT_TIMER(wxID_ANY, CQueueView::OnTimer)
    164176
    165177EVT_MENU(XRCID("ID_PRIORITY_HIGHEST"), CQueueView::OnSetPriority)
     
    411423
    412424    m_totalQueueSize = 0;
    413425    m_filesWithUnknownSize = 0;
     426   
     427    m_actionAfterState = ActionAfterState_Disabled;
    414428
    415429    CreateColumns(_("Status"));
    416430
     
    14041418    if (m_activeMode)
    14051419    {
    14061420        m_activeMode = 0;
     1421       
    14071422        if (!m_pQueue->GetSelection())
    14081423        {
    14091424            CQueueViewBase* pFailed = m_pQueue->GetQueueView_Failed();
     
    14131428            else if (pSuccessful->GetItemCount())
    14141429                m_pQueue->SetSelection(2);
    14151430        }
     1431    ActionAfter();
    14161432    }
    14171433
    14181434    if (m_quit)
     
    18691885        return;
    18701886
    18711887    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
    18721896    pMenu->Enable(XRCID("ID_REMOVE"), GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1);
    18731897
    18741898    const bool hasSelection = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1;
     
    18901914    RemoveAll();
    18911915}
    18921916
     1917void CQueueView::OnActionAfterDisable(wxCommandEvent& event)
     1918{
     1919  m_actionAfterState = ActionAfterState_Disabled;
     1920}
     1921
     1922void 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
     1934void 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
     1946void 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__
     1976void 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
     1988void 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
    18932001void CQueueView::RemoveAll()
    18942002{
    18952003    // This function removes all inactive items and queues active items
     
    19132021        }
    19142022    }
    19152023    SetItemCount(m_itemCount);
     2024  m_actionAfterState = ActionAfterState_Disabled;
    19162025
    19172026    m_serverList = newServerList;
    19182027    UpdateStatusLinePositions();
     
    24872596
    24882597    SendNextCommand(*pEngineData);
    24892598}
     2599
     2600enum ActionAfterState CQueueView::GetActionAfterState() const
     2601{
     2602  return m_actionAfterState;
     2603}
     2604
     2605bool CQueueView::IsActionAfter(enum ActionAfterState state)
     2606{
     2607  return m_actionAfterState == state;
     2608}
     2609
     2610void 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
     2659void 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
     2673void 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}