1
0

RemoteTransfer.cpp 7.4 KB

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