RemoteTransfer.cpp 6.0 KB

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