RemoteTransfer.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <VCLCommon.h>
  6. #include <TextsWin.h>
  7. #include <CustomWinConfiguration.h>
  8. #include <CoreMain.h>
  9. #include <WinInterface.h>
  10. #include <GUITools.h>
  11. #include "RemoteTransfer.h"
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "HistoryComboBox"
  15. #pragma resource "*.dfm"
  16. //---------------------------------------------------------------------------
  17. bool __fastcall DoRemoteCopyDialog(
  18. TStrings * Sessions, TStrings * Directories,
  19. TDirectRemoteCopy AllowDirectCopy, bool Multi, void *& Session, UnicodeString & Target, UnicodeString & FileMask,
  20. bool & DirectCopy, void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists, bool TargetConfirmed)
  21. {
  22. bool Result;
  23. TRemoteTransferDialog * Dialog = SafeFormCreate<TRemoteTransferDialog>();
  24. try
  25. {
  26. Dialog->Init(Multi, Sessions, Directories, AllowDirectCopy, CurrentSession, OnDirectoryExists, TargetConfirmed);
  27. Result = Dialog->Execute(Session, Target, FileMask, DirectCopy);
  28. }
  29. __finally
  30. {
  31. delete Dialog;
  32. }
  33. return Result;
  34. }
  35. //---------------------------------------------------------------------------
  36. __fastcall TRemoteTransferDialog::TRemoteTransferDialog(TComponent * Owner)
  37. : TForm(Owner)
  38. {
  39. UseSystemSettings(this);
  40. Caption = LoadStr(REMOTE_COPY_TITLE);
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TRemoteTransferDialog::Init(
  44. bool Multi, TStrings * Sessions, TStrings * Directories, TDirectRemoteCopy AllowDirectCopy,
  45. void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists, bool TargetConfirmed)
  46. {
  47. FMulti = Multi;
  48. SessionCombo->Items = Sessions;
  49. FDirectories = Directories;
  50. DebugAssert(SessionCombo->Items->Count > 0);
  51. DebugAssert(SessionCombo->Items->Count == FDirectories->Count);
  52. FAllowDirectCopy = AllowDirectCopy;
  53. FCurrentSession = CurrentSession;
  54. FOnDirectoryExists = OnDirectoryExists;
  55. FTargetConfirmed = TargetConfirmed;
  56. LoadDialogImage(Image, L"Duplicate L to R");
  57. }
  58. //---------------------------------------------------------------------------
  59. bool __fastcall TRemoteTransferDialog::Execute(void *& Session, UnicodeString & Target,
  60. UnicodeString & FileMask, bool & DirectCopy)
  61. {
  62. for (int Index = 0; Index < SessionCombo->Items->Count; Index++)
  63. {
  64. if (SessionCombo->Items->Objects[Index] == Session)
  65. {
  66. SessionCombo->ItemIndex = Index;
  67. break;
  68. }
  69. }
  70. DirectoryEdit->Items = CustomWinConfiguration->History[L"RemoteTarget"];
  71. DirectoryEdit->Text = UnixIncludeTrailingBackslash(Target) + FileMask;
  72. FDirectCopy = DirectCopy;
  73. FOriginalTarget = Target;
  74. UpdateNotDirectCopyCheck();
  75. bool Result = (ShowModal() == DefaultResult(this));
  76. if (Result)
  77. {
  78. Session = GetSelectedSession();
  79. CustomWinConfiguration->History[L"RemoteTarget"] = DirectoryEdit->Items;
  80. Target = GetTarget();
  81. FileMask = GetFileMask();
  82. DirectCopy = !NotDirectCopyCheck->Checked;
  83. }
  84. return Result;
  85. }
  86. //---------------------------------------------------------------------------
  87. UnicodeString TRemoteTransferDialog::GetTarget()
  88. {
  89. return UnixExtractFilePath(DirectoryEdit->Text);
  90. }
  91. //---------------------------------------------------------------------------
  92. UnicodeString TRemoteTransferDialog::GetFileMask()
  93. {
  94. return UnixExtractFileName(DirectoryEdit->Text);
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TRemoteTransferDialog::UpdateControls()
  98. {
  99. EnableControl(NotDirectCopyCheck,
  100. IsCurrentSessionSelected() &&
  101. (FAllowDirectCopy != drcDisallow));
  102. EnableControl(OkButton, !DirectoryEdit->Text.IsEmpty());
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TRemoteTransferDialog::ControlChange(TObject * /*Sender*/)
  106. {
  107. UpdateControls();
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TRemoteTransferDialog::FormShow(TObject * /*Sender*/)
  111. {
  112. InstallPathWordBreakProc(DirectoryEdit);
  113. UpdateControls();
  114. DirectoryEdit->SetFocus();
  115. }
  116. //---------------------------------------------------------------------------
  117. void __fastcall TRemoteTransferDialog::HelpButtonClick(TObject * /*Sender*/)
  118. {
  119. FormHelp(this);
  120. }
  121. //---------------------------------------------------------------------------
  122. void __fastcall TRemoteTransferDialog::SessionComboChange(TObject * /*Sender*/)
  123. {
  124. DirectoryEdit->Text =
  125. UnixIncludeTrailingBackslash(FDirectories->Strings[SessionCombo->ItemIndex]) +
  126. UnixExtractFileName(DirectoryEdit->Text);
  127. UpdateNotDirectCopyCheck();
  128. UpdateControls();
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TRemoteTransferDialog::UpdateNotDirectCopyCheck()
  132. {
  133. if (IsCurrentSessionSelected())
  134. {
  135. NotDirectCopyCheck->Checked = !FDirectCopy;
  136. }
  137. else
  138. {
  139. NotDirectCopyCheck->Checked = true;
  140. }
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TRemoteTransferDialog::FormCloseQuery(TObject * /*Sender*/,
  144. bool & /*CanClose*/)
  145. {
  146. if (ModalResult == DefaultResult(this))
  147. {
  148. bool TargetConfirmed =
  149. FTargetConfirmed &&
  150. UnixSamePath(GetTarget(), FOriginalTarget);
  151. if (!TargetConfirmed &&
  152. !IsFileNameMask(GetFileMask()) &&
  153. FOnDirectoryExists(GetSelectedSession(), DirectoryEdit->Text))
  154. {
  155. DirectoryEdit->Text = UnixCombinePaths(DirectoryEdit->Text, AnyMask);
  156. }
  157. if (!IsFileNameMask(GetFileMask()) && FMulti)
  158. {
  159. UnicodeString Message =
  160. FormatMultiFilesToOneConfirmation(DirectoryEdit->Text, true);
  161. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_NONE) == qaCancel)
  162. {
  163. Abort();
  164. }
  165. }
  166. if (IsCurrentSessionSelected() &&
  167. ((FAllowDirectCopy == drcConfirmCommandSession) || (FAllowDirectCopy == drcConfirmCommandSessionDirs)) &&
  168. !NotDirectCopyCheck->Checked &&
  169. GUIConfiguration->ConfirmCommandSession)
  170. {
  171. TMessageParams Params(mpNeverAskAgainCheck);
  172. int ObjectNamePart = (FAllowDirectCopy == drcConfirmCommandSession) ? 1 : 2;
  173. UnicodeString ObjectName = LoadStrPart(REMOTE_COPY_COMMAND_SESSION_FILES_DIRECTORIES, ObjectNamePart);
  174. UnicodeString Message = FMTLOAD(REMOTE_COPY_COMMAND_SESSION3, (ObjectName, ObjectName, ObjectName));
  175. unsigned int Answer = MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HelpKeyword, &Params);
  176. if (Answer == qaNeverAskAgain)
  177. {
  178. GUIConfiguration->ConfirmCommandSession = false;
  179. }
  180. else if (Answer != qaOK)
  181. {
  182. Abort();
  183. }
  184. }
  185. }
  186. }
  187. //---------------------------------------------------------------------------
  188. void __fastcall TRemoteTransferDialog::NotDirectCopyCheckClick(
  189. TObject * /*Sender*/)
  190. {
  191. if (IsCurrentSessionSelected())
  192. {
  193. FDirectCopy = !NotDirectCopyCheck->Checked;
  194. }
  195. }
  196. //---------------------------------------------------------------------------
  197. void * TRemoteTransferDialog::GetSelectedSession()
  198. {
  199. return SessionCombo->Items->Objects[SessionCombo->ItemIndex];
  200. }
  201. //---------------------------------------------------------------------------
  202. bool __fastcall TRemoteTransferDialog::IsCurrentSessionSelected()
  203. {
  204. return (GetSelectedSession() == FCurrentSession);
  205. }
  206. //---------------------------------------------------------------------------