TerminalManager.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //---------------------------------------------------------------------------
  2. #ifndef TerminalManagerH
  3. #define TerminalManagerH
  4. //---------------------------------------------------------------------------
  5. #include <Terminal.h>
  6. #include <Queue.h>
  7. #include <FileOperationProgress.h>
  8. #include <WinInterface.h>
  9. #include <Vcl.AppEvnts.hpp>
  10. //---------------------------------------------------------------------------
  11. class TCustomScpExplorerForm;
  12. class TTerminalQueue;
  13. class TAuthenticateForm;
  14. class ITaskbarList3;
  15. //---------------------------------------------------------------------------
  16. enum TTerminalPendingAction { tpNull, tpNone, tpReconnect, tpFree };
  17. //---------------------------------------------------------------------------
  18. class TManagedTerminal : public TTerminal
  19. {
  20. public:
  21. __fastcall TManagedTerminal(TSessionData * SessionData, TConfiguration * Configuration);
  22. virtual __fastcall ~TManagedTerminal();
  23. bool LocalBrowser;
  24. TSessionData * StateData;
  25. TObject * LocalExplorerState;
  26. TObject * RemoteExplorerState;
  27. TObject * OtherLocalExplorerState;
  28. TDateTime ReopenStart;
  29. TDateTime DirectoryLoaded;
  30. TTerminalThread * TerminalThread;
  31. TDateTime QueueOperationStart;
  32. // To distinguish sessions that were explicitly disconnected and
  33. // should not be reconnected when their tab is activated.
  34. bool Disconnected;
  35. bool DisconnectedTemporarily;
  36. // Sessions that should not close when they fail to connect
  37. // (i.e. those that were ever connected or were opened as a part of a workspace)
  38. bool Permanent;
  39. };
  40. //---------------------------------------------------------------------------
  41. class TTerminalManager : public TTerminalList
  42. {
  43. public:
  44. static TTerminalManager * __fastcall Instance(bool ForceCreation = true);
  45. static void __fastcall DestroyInstance();
  46. __fastcall TTerminalManager();
  47. __fastcall ~TTerminalManager();
  48. TManagedTerminal * __fastcall NewManagedTerminal(TSessionData * Data);
  49. TManagedTerminal * __fastcall NewLocalBrowser();
  50. TManagedTerminal * __fastcall NewSessions(TList * DataList);
  51. virtual void __fastcall FreeTerminal(TTerminal * Terminal);
  52. void __fastcall Move(TTerminal * Source, TTerminal * Target);
  53. void __fastcall DisconnectActiveTerminalIfPermanentFreeOtherwise();
  54. void __fastcall DisconnectActiveTerminal();
  55. void __fastcall ReconnectActiveTerminal();
  56. void __fastcall FreeActiveTerminal();
  57. void __fastcall CycleTerminals(bool Forward);
  58. bool __fastcall ConnectTerminal(TTerminal * Terminal);
  59. void __fastcall SetActiveTerminalWithAutoReconnect(TManagedTerminal * value);
  60. void __fastcall UpdateAppTitle();
  61. bool __fastcall CanOpenInPutty();
  62. void __fastcall OpenInPutty();
  63. void __fastcall NewSession(
  64. const UnicodeString & SessionUrl, bool ReloadSessions = true, TForm * LinkedForm = NULL, bool ReplaceExisting = false);
  65. void __fastcall Idle(bool SkipCurrentTerminal);
  66. UnicodeString __fastcall GetSessionTitle(TManagedTerminal * Terminal, bool Unique);
  67. UnicodeString __fastcall GetActiveSessionAppTitle();
  68. UnicodeString __fastcall GetAppProgressTitle();
  69. UnicodeString __fastcall FormatFormCaptionWithSession(TCustomForm * Form, const UnicodeString & Caption);
  70. void __fastcall HandleException(Exception * E);
  71. void __fastcall SaveWorkspace(TList * DataList);
  72. void __fastcall QueueStatusUpdated();
  73. bool __fastcall IsActiveTerminalForSite(TTerminal * Terminal, TSessionData * Data);
  74. TTerminal * __fastcall FindActiveTerminalForSite(TSessionData * Data);
  75. TTerminalQueue * __fastcall FindQueueForTerminal(TTerminal * Terminal);
  76. bool __fastcall UploadPublicKey(TTerminal * Terminal, TSessionData * Data, UnicodeString & FileName);
  77. UnicodeString GetPathForSessionTabName(const UnicodeString & Result);
  78. __property TCustomScpExplorerForm * ScpExplorer = { read = FScpExplorer, write = SetScpExplorer };
  79. __property TManagedTerminal * ActiveSession = { read = FActiveSession, write = SetActiveSession };
  80. __property TManagedTerminal * ActiveTerminal = { read = GetActiveTerminal };
  81. __property TTerminalQueue * ActiveQueue = { read = GetActiveQueue };
  82. __property int ActiveSessionIndex = { read = GetActiveSessionIndex, write = SetActiveSessionIndex };
  83. __property TStrings * SessionList = { read = GetSessionList };
  84. __property TTerminal * LocalTerminal = { read = FLocalTerminal };
  85. __property TManagedTerminal * Sessions[int Index] = { read = GetSession };
  86. __property bool Updating = { read = IsUpdating };
  87. protected:
  88. virtual TTerminal * __fastcall CreateTerminal(TSessionData * Data);
  89. void __fastcall DoConnectTerminal(TTerminal * Terminal, bool Reopen, bool AdHoc);
  90. virtual TTerminal * __fastcall NewTerminal(TSessionData * Data);
  91. private:
  92. static TTerminalManager * FInstance;
  93. TCustomScpExplorerForm * FScpExplorer;
  94. TManagedTerminal * FActiveSession;
  95. TTerminal * FLocalTerminal;
  96. bool FDestroying;
  97. TTerminalPendingAction FTerminalPendingAction;
  98. TStrings * FSessionList;
  99. TList * FQueues;
  100. TStrings * FTerminationMessages;
  101. UnicodeString FProgressTitle;
  102. UnicodeString FForegroundProgressTitle;
  103. TDateTime FDirectoryReadingStart;
  104. TAuthenticateForm * FAuthenticateForm;
  105. TCriticalSection * FQueueSection;
  106. DWORD FMainThread;
  107. int FPendingConfigurationChange;
  108. std::unique_ptr<TCriticalSection> FChangeSection;
  109. std::vector<std::pair<TTerminalQueue *, TQueueEvent> > FQueueEvents;
  110. unsigned int FTaskbarButtonCreatedMessage;
  111. ITaskbarList3 * FTaskbarList;
  112. int FAuthenticating;
  113. void * FBusyToken;
  114. bool FAuthenticationCancelled;
  115. std::unique_ptr<TApplicationEvents> FApplicationsEvents;
  116. bool FKeepAuthenticateForm;
  117. int FUpdating;
  118. bool __fastcall ConnectActiveTerminalImpl(bool Reopen);
  119. bool __fastcall ConnectActiveTerminal();
  120. TTerminalQueue * __fastcall NewQueue(TTerminal * Terminal);
  121. void __fastcall SetScpExplorer(TCustomScpExplorerForm * value);
  122. void __fastcall DoSetActiveSession(TManagedTerminal * value, bool AutoReconnect, bool LastTerminalClosed);
  123. void __fastcall SetActiveSession(TManagedTerminal * value);
  124. TManagedTerminal * GetActiveTerminal();
  125. void __fastcall UpdateAll();
  126. void __fastcall ApplicationException(TObject * Sender, Exception * E);
  127. void __fastcall ApplicationShowHint(UnicodeString & HintStr, bool & CanShow,
  128. THintInfo & HintInfo);
  129. void __fastcall ApplicationMessage(TMsg & Msg, bool & Handled);
  130. void __fastcall ConfigurationChange(TObject * Sender);
  131. void __fastcall TerminalUpdateStatus(TTerminal * Terminal, bool Active);
  132. void __fastcall TerminalQueryUser(TObject * Sender,
  133. const UnicodeString Query, TStrings * MoreMessages, unsigned int Answers,
  134. const TQueryParams * Params, unsigned int & Answer, TQueryType Type, void * Arg);
  135. void __fastcall TerminalPromptUser(TTerminal * Terminal,
  136. TPromptKind Kind, UnicodeString Name, UnicodeString Instructions, TStrings * Prompt,
  137. TStrings * Results, bool & Result, void * Arg);
  138. void __fastcall TerminalDisplayBanner(TTerminal * Terminal,
  139. UnicodeString SessionName, const UnicodeString & Banner, bool & NeverShowAgain,
  140. int Options, unsigned int & Params);
  141. void __fastcall TerminalShowExtendedException(TTerminal * Terminal,
  142. Exception * E, void * Arg);
  143. void __fastcall TerminalReadDirectoryProgress(TObject * Sender, int Progress,
  144. int ResolvedLinks, bool & Cancel);
  145. void __fastcall TerminalInformation(
  146. TTerminal * Terminal, const UnicodeString & Str, bool Status, int Phase, const UnicodeString & Additional);
  147. void __fastcall TerminalCustomCommand(TTerminal * Terminal, const UnicodeString & Command, bool & Handled);
  148. void __fastcall FreeAll();
  149. void __fastcall SessionReady();
  150. TStrings * __fastcall GetSessionList();
  151. int __fastcall GetActiveSessionIndex();
  152. TTerminalQueue * __fastcall GetActiveQueue();
  153. void __fastcall SaveTerminal(TTerminal * Terminal);
  154. void __fastcall SetActiveSessionIndex(int value);
  155. void __fastcall OperationFinished(::TFileOperation Operation, TOperationSide Side,
  156. bool Temp, const UnicodeString & FileName, bool Success,
  157. TOnceDoneOperation & OnceDoneOperation);
  158. void __fastcall OperationProgress(TFileOperationProgressType & ProgressData);
  159. void __fastcall DeleteLocalFile(const UnicodeString FileName, bool Alternative, int & Deleted);
  160. void __fastcall QueueEvent(TTerminalQueue * Queue, TQueueEvent Event);
  161. TAuthenticateForm * __fastcall MakeAuthenticateForm(TTerminal * Terminal);
  162. void __fastcall MasterPasswordPrompt();
  163. void __fastcall FileNameInputDialogInitializeRenameBaseName(
  164. TObject * Sender, TInputDialogData * Data);
  165. void __fastcall InitTaskbarButtonCreatedMessage();
  166. void __fastcall ReleaseTaskbarList();
  167. void __fastcall CreateTaskbarList();
  168. void __fastcall UpdateTaskbarList();
  169. void __fastcall AuthenticateFormCancel(TObject * Sender);
  170. void __fastcall DoSessionListChanged();
  171. TManagedTerminal * __fastcall DoNewSession(TSessionData * Data);
  172. static void __fastcall TerminalThreadIdle(void * Data, TObject * Sender);
  173. void __fastcall SetQueueConfiguration(TTerminalQueue * Queue);
  174. void __fastcall ApplicationModalBegin(TObject * Sender);
  175. void __fastcall ApplicationModalEnd(TObject * Sender);
  176. bool __fastcall HandleMouseWheel(WPARAM WParam, LPARAM LParam);
  177. void __fastcall DoConfigurationChange();
  178. bool __fastcall ShouldDisplayQueueStatusOnAppTitle();
  179. void __fastcall SetupTerminal(TTerminal * Terminal);
  180. void __fastcall CloseAutheticateForm();
  181. void __fastcall AuthenticatingDone();
  182. TRemoteFile * __fastcall CheckRights(
  183. TTerminal * Terminal, const UnicodeString & EntryType, const UnicodeString & FileName, bool & WrongRights);
  184. TManagedTerminal * __fastcall CreateManagedTerminal(TSessionData * Data);
  185. TManagedTerminal * __fastcall GetSession(int Index);
  186. bool IsUpdating();
  187. };
  188. //---------------------------------------------------------------------------
  189. #endif