TerminalManager.h 9.5 KB

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