RemoteTransfer.cpp 7.3 KB

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