| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <Common.h>
- #include <WinInterface.h>
- #include <ScpMain.h>
- #include <TextsWin.h>
- #include <VCLCommon.h>
- #include <CustomWinConfiguration.h>
- #include "Copy.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "MoreButton"
- #pragma link "Rights"
- #pragma link "CopyParams"
- #pragma link "HistoryComboBox"
- #pragma resource "*.dfm"
- //---------------------------------------------------------------------------
- bool __fastcall DoCopyDialog(bool ToRemote,
- bool Move, TStrings * FileList, AnsiString & TargetDirectory,
- TGUICopyParamType * Params, int Options, int * OutputOptions)
- {
- bool Result;
- TCopyDialog *CopyDialog = new TCopyDialog(Application);
- try
- {
- if ((Options & coDisableTransferMode) != 0)
- {
- // If local and remote EOL types are the same, there is no need
- // for ASCII (or Automatic) mode
- Params->TransferMode = tmBinary;
- }
- CopyDialog->ToRemote = ToRemote;
- CopyDialog->Options = Options;
- if (OutputOptions != NULL)
- {
- CopyDialog->OutputOptions = *OutputOptions;
- }
- CopyDialog->Directory = TargetDirectory;
- CopyDialog->FileList = FileList;
- CopyDialog->Params = *Params;
- CopyDialog->Move = Move;
- Result = CopyDialog->Execute();
- if (Result)
- {
- TargetDirectory = CopyDialog->Directory;
- *Params = CopyDialog->Params;
- if (OutputOptions != NULL)
- {
- *OutputOptions = CopyDialog->OutputOptions;
- }
- }
- }
- __finally
- {
- delete CopyDialog;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- __fastcall TCopyDialog::TCopyDialog(TComponent* Owner)
- : TForm(Owner)
- {
- // on start set different value than we want to allow property-setter to proceed
- FToRemote = false;
- FMove = true;
- ToRemote = true;
- Move = false;
- FOptions = 0;
- FOutputOptions = 0;
- FPresetsMenu = new TPopupMenu(this);
- UseSystemSettings(this);
- }
- //---------------------------------------------------------------------------
- __fastcall TCopyDialog::~TCopyDialog()
- {
- delete FPresetsMenu;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::AdjustTransferControls()
- {
- if (FileList && FileList->Count)
- {
- if (!ToRemote && !Move && FLAGSET(FOutputOptions, cooRemoteTransfer))
- {
- AnsiString Label;
- if (FileList->Count == 1)
- {
- AnsiString FileName;
- if (!ToRemote) FileName = UnixExtractFileName(FFileList->Strings[0]);
- else FileName = ExtractFileName(FFileList->Strings[0]);
- Label = FMTLOAD(REMOTE_COPY_FILE, (FileName));
- }
- else
- {
- Label = FMTLOAD(REMOTE_COPY_FILES, (FFileList->Count));
- }
- // hack to remove trailing colon used for "duplicate" prompt
- if (!Label.IsEmpty() &&
- (Label.ByteType(Label.Length()) == mbSingleByte) &&
- (Label[Label.Length()] == ':'))
- {
- Label.SetLength(Label.Length() - 1);
- }
- DirectoryLabel->Caption = Label;
- }
- else
- {
- AnsiString TransferStr = LoadStr(!Move ? COPY_COPY : COPY_MOVE);
- // currently the copy dialog is shown when downloading to temp folder
- // only for drag&drop downloads, for we dare to display d&d specific prompt
- AnsiString DirectionStr =
- LoadStr(((Options & coTemp) != 0) ? COPY_TODROP :
- (RemotePaths() ? COPY_TOREMOTE : COPY_TOLOCAL));
- if (FileList->Count == 1)
- {
- AnsiString FileName;
- if (!ToRemote) FileName = UnixExtractFileName(FFileList->Strings[0]);
- else FileName = ExtractFileName(FFileList->Strings[0]);
- DirectoryLabel->Caption = FMTLOAD(COPY_FILE,
- (TransferStr, FileName, DirectionStr));
- }
- else
- {
- DirectoryLabel->Caption = FMTLOAD(COPY_FILES,
- (TransferStr, FFileList->Count, DirectionStr));
- }
- }
- }
- if (!Move)
- {
- if (!ToRemote && FLAGSET(FOutputOptions, cooRemoteTransfer))
- {
- Caption = LoadStr(REMOTE_COPY_TITLE);
- }
- else
- {
- Caption = LoadStr(COPY_COPY_CAPTION);
- }
- CopyButton->Caption = LoadStr(COPY_COPY_BUTTON);
- }
- else
- {
- Caption = LoadStr(COPY_MOVE_CAPTION);
- CopyButton->Caption = LoadStr(COPY_MOVE_BUTTON);
- }
- bool RemoteTransfer = FLAGSET(FOutputOptions, cooRemoteTransfer);
- assert(FLAGSET(Options, coAllowRemoteTransfer) || !RemoteTransfer);
- EnableControl(CopyParamsFrame, !RemoteTransfer);
- EnableControl(NewerOnlyCheck, FLAGCLEAR(Options, coDisableNewerOnly) && !RemoteTransfer);
- EnableControl(PresetsButton, !RemoteTransfer);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::AdjustControls()
- {
- if (FLAGSET(Options, coDoNotShowAgain))
- {
- SaveSettingsCheck->Caption = LoadStr(NEVER_SHOW_DIALOG_AGAIN);
- }
- RemoteDirectoryEdit->Visible = false;
- LocalDirectoryEdit->Visible = false;
- DirectoryEdit->Visible = FLAGCLEAR(Options, coTemp);
- EnableControl(DirectoryEdit, FLAGCLEAR(Options, coDisableDirectory));
- EnableControl(DirectoryLabel, DirectoryEdit->Enabled);
- EnableControl(LocalDirectoryBrowseButton, DirectoryEdit->Enabled);
- DirectoryLabel->FocusControl = DirectoryEdit;
- CopyParamsFrame->Direction = !ToRemote ? pdToLocal : pdToRemote;
- CopyParamsFrame->Options =
- FLAGMASK(FLAGCLEAR(Options, coDisableTransferMode), cfAllowTransferMode) |
- FLAGMASK(!Move, cfAllowExcludeMask) |
- FLAGMASK(!Move && ToRemote, cfAllowClearArchive);
- PresetsButton->Visible = FLAGCLEAR(Options, coDoNotUsePresets);
- AdjustTransferControls();
- LocalDirectoryBrowseButton->Visible = !ToRemote &&
- ((Options & coTemp) == 0);
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::SetToRemote(bool value)
- {
- if (FToRemote != value)
- {
- AnsiString ADirectory = DirectoryEdit->Text;
- FToRemote = value;
- DirectoryEdit->Text = ADirectory;
- AdjustControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::SetOptions(int value)
- {
- if (Options != value)
- {
- FOptions = value;
- AdjustControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::SetOutputOptions(int value)
- {
- if (OutputOptions != value)
- {
- SaveSettingsCheck->Checked = FLAGSET(FOutputOptions, cooDoNotShowAgain);
- FOutputOptions = (value & ~cooDoNotShowAgain);
- }
- }
- //---------------------------------------------------------------------------
- int __fastcall TCopyDialog::GetOutputOptions()
- {
- return FOutputOptions |
- FLAGMASK(SaveSettingsCheck->Checked, cooDoNotShowAgain);
- }
- //---------------------------------------------------------------------------
- THistoryComboBox * __fastcall TCopyDialog::GetDirectoryEdit()
- {
- return ToRemote ? RemoteDirectoryEdit : LocalDirectoryEdit;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCopyDialog::RemotePaths()
- {
- return (ToRemote || FLAGSET(FOutputOptions, cooRemoteTransfer));
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TCopyDialog::GetFileMask()
- {
- return RemotePaths() ? UnixExtractFileName(DirectoryEdit->Text) :
- ExtractFileName(DirectoryEdit->Text);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::SetParams(const TGUICopyParamType & value)
- {
- FParams = value;
- CopyParamsFrame->Params = value;
- DirectoryEdit->Text = Directory + FParams.FileMask;
- QueueCheck->Checked = FParams.Queue;
- QueueNoConfirmationCheck->Checked = FParams.QueueNoConfirmation;
- NewerOnlyCheck->Checked = FLAGCLEAR(Options, coDisableNewerOnly) && FParams.NewerOnly;
- }
- //---------------------------------------------------------------------------
- TGUICopyParamType __fastcall TCopyDialog::GetParams()
- {
- // overwrites TCopyParamType files only
- FParams = CopyParamsFrame->Params;
- FParams.FileMask = GetFileMask();
- FParams.Queue = QueueCheck->Checked;
- FParams.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
- FParams.NewerOnly = FLAGCLEAR(Options, coDisableNewerOnly) && NewerOnlyCheck->Checked;
- return FParams;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::SetDirectory(AnsiString value)
- {
- if (!value.IsEmpty())
- {
- value = RemotePaths() ?
- UnixIncludeTrailingBackslash(value) : IncludeTrailingBackslash(value);
- }
- DirectoryEdit->Text = value + GetFileMask();
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TCopyDialog::GetDirectory()
- {
- assert(DirectoryEdit);
- AnsiString Result = DirectoryEdit->Text;
- if (RemotePaths())
- {
- Result = UnixExtractFilePath(Result);
- if (!Result.IsEmpty())
- {
- Result = UnixIncludeTrailingBackslash(Result);
- }
- }
- else
- {
- Result = ExtractFilePath(Result);
- if (!Result.IsEmpty())
- {
- Result = IncludeTrailingBackslash(Result);
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::SetFileList(TStrings * value)
- {
- if (FFileList != value)
- {
- FFileList = value;
- AdjustControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::UpdateControls()
- {
- if (!ToRemote && FLAGSET(Options, coAllowRemoteTransfer))
- {
- AnsiString Directory = DirectoryEdit->Text;
- bool RemoteTransfer = (Directory.Pos("\\") == 0) && (Directory.Pos("/") > 0);
- if (RemoteTransfer != FLAGSET(FOutputOptions, cooRemoteTransfer))
- {
- FOutputOptions =
- (FOutputOptions & ~cooRemoteTransfer) |
- FLAGMASK(RemoteTransfer, cooRemoteTransfer);
- AdjustTransferControls();
- }
- }
- bool RemoteTransfer = FLAGSET(FOutputOptions, cooRemoteTransfer);
- EnableControl(QueueCheck,
- ((Options & (coDisableQueue | coTemp)) == 0) && !RemoteTransfer);
- EnableControl(QueueNoConfirmationCheck,
- (((Options & coTemp) == 0) && QueueCheck->Checked) && !RemoteTransfer);
- QueueNoConfirmationCheck->Visible = MoreButton->Expanded;
- EnableControl(SaveSettingsCheck, FLAGCLEAR(Options, coDisableSaveSettings) &&
- !RemoteTransfer);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::SetMove(bool value)
- {
- if (Move != value)
- {
- FMove = value;
- AdjustControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::FormShow(TObject * /*Sender*/)
- {
- assert(FileList && (FileList->Count > 0));
- if (DirectoryEdit->Enabled && DirectoryEdit->Visible)
- {
- DirectoryEdit->SetFocus();
- }
- else
- if (MoreButton->Expanded)
- {
- MorePanel->SetFocus();
- }
- else
- {
- CopyButton->SetFocus();
- }
- UpdateControls();
- InstallPathWordBreakProc(RemoteDirectoryEdit);
- InstallPathWordBreakProc(LocalDirectoryEdit);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCopyDialog::Execute()
- {
- // at start assume that copy param is current preset
- FPreset = GUIConfiguration->CopyParamCurrent;
- DirectoryEdit->Items = CustomWinConfiguration->History[
- ToRemote ? "RemoteTarget" : "LocalTarget"];
- MoreButton->Expanded = GUIConfiguration->CopyParamDialogExpanded;
- CopyParamsFrame->BeforeExecute();
- bool Result = (ShowModal() == mrOk);
- if (Result)
- {
- CopyParamsFrame->AfterExecute();
- Configuration->BeginUpdate();
- try
- {
- GUIConfiguration->CopyParamDialogExpanded = MoreButton->Expanded;
- if (FLAGSET(OutputOptions, cooSaveSettings) &&
- FLAGCLEAR(Options, coDisableSaveSettings))
- {
- GUIConfiguration->DefaultCopyParam = Params;
- }
- DirectoryEdit->SaveToHistory();
- CustomWinConfiguration->History[ToRemote ?
- "RemoteTarget" : "LocalTarget"] = DirectoryEdit->Items;
- }
- __finally
- {
- Configuration->EndUpdate();
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::FormCloseQuery(TObject * /*Sender*/,
- bool &CanClose)
- {
- if (ModalResult != mrCancel)
- {
- if (!RemotePaths() && ((Options & coTemp) == 0))
- {
- AnsiString Dir = Directory;
- AnsiString Drive = ExtractFileDrive(Dir);
- if (!DirectoryExists(Dir))
- {
- if (MessageDialog(FMTLOAD(CREATE_LOCAL_DIRECTORY, (Dir)),
- qtConfirmation, qaOK | qaCancel, HELP_NONE) != qaCancel)
- {
- if (!ForceDirectories(Dir))
- {
- SimpleErrorDialog(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (Dir)));
- CanClose = false;
- }
- }
- else
- {
- CanClose = False;
- }
- }
- if (!CanClose)
- {
- DirectoryEdit->SelectAll();
- DirectoryEdit->SetFocus();
- }
- };
- if (CanClose)
- {
- CopyParamsFrame->Validate();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::LocalDirectoryBrowseButtonClick(
- TObject * /*Sender*/)
- {
- assert(!ToRemote);
- AnsiString Directory;
- // if we are duplicating, we have remote path there
- if (RemotePaths())
- {
- Directory = LocalDirectoryEdit->Text;
- }
- if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
- {
- LocalDirectoryEdit->Text = Directory;
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::ControlChange(TObject * /*Sender*/)
- {
- UpdateControls();
- ResetSystemSettings(this);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::PresetsButtonClick(TObject * /*Sender*/)
- {
- TCopyParamType Param = Params;
- CopyParamListPopup(
- PresetsButton->ClientToScreen(TPoint(0, PresetsButton->Height)),
- FPresetsMenu, Params, FPreset, CopyParamClick, cplNone);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::CopyParamClick(TObject * Sender)
- {
- TCopyParamType Param = Params;
- if (CopyParamListPopupClick(Sender, Param, FPreset))
- {
- Params = Param;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCopyDialog::HelpButtonClick(TObject * /*Sender*/)
- {
- FormHelp(this);
- }
- //---------------------------------------------------------------------------
|