RemoteTransfer.cpp 6.3 KB

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