diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-12-27 17:28:00 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-12-27 17:28:00 +0100 |
| commit | ff6b0244b39ccdb30a499038382d2676d9c278be (patch) | |
| tree | a966c4e951b61310e47f15ff85b3e80b5e5bc16e /UCoreWorkers.pas | |
| parent | 2e39205afb249626b24b1af2251297ff039a60ca (diff) | |
| download | tuxcmd-ff6b0244b39ccdb30a499038382d2676d9c278be.tar.xz | |
Kylix fixes, cleanup
Diffstat (limited to 'UCoreWorkers.pas')
| -rw-r--r-- | UCoreWorkers.pas | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/UCoreWorkers.pas b/UCoreWorkers.pas index 97077aa..3fb394a 100644 --- a/UCoreWorkers.pas +++ b/UCoreWorkers.pas @@ -29,7 +29,6 @@ type TWorkerThreadJobType = (WORKER_JOB_DUMMY, WORKER_JOB_DELETE, WORKER_JOB_COP type TVFSCallbackThread = class(TThread) private FThreadID: __pthread_t; - FCopyProgressFunc: TEngineProgressFunc; FFinished: boolean; VFSCallbackEvent: TSimpleEvent; @@ -80,6 +79,8 @@ type TVFSCallbackThread = class(TThread) // Copy worker progress values FTotalSize, FTotalDone, FFileSize: cuLongLong; + FCopySkipAllErrors: boolean; + FCopyProgressFunc: TEngineProgressFunc; // Dialogs FCancelMessage: string; @@ -92,30 +93,31 @@ type TVFSCallbackThread = class(TThread) FGUIProgress1Pos, FGUIProgress2Pos, FGUIProgress1Max, FGUIProgress2Max: Int64; FGUIProgress1Text, FGUIProgress2Text, FGUILabel1Text, FGUILabel2Text: string; FGUIChanged: boolean; - procedure UpdateProgress1(const Progress: Int64; const ProgressText: string); - procedure UpdateProgress2(const Progress: Int64; const ProgressText: string); - procedure SetProgress1Params(const ProgressMax: Int64); - procedure SetProgress2Params(const ProgressMax: Int64); - procedure UpdateCaption1(const CaptionText: string); - procedure UpdateCaption2(const CaptionText: string); FDirDeleteButtonsType: TFDirDeleteButtonSet; FDirDeleteTitle, FDirDeleteFileName: string; FDirDeleteError: PGError; - function ShowDirDeleteDialog(ButtonsType: TFDirDeleteButtonSet; const Title, FileName: string; Error: PGError): integer; FOverwriteShowAppend: boolean; FOverwriteSourceItem, FOverwriteDestItem: PDataItem; FOverwriteSourceFile, FOverwriteDestFile, FOverwriteRenameStr: string; - function ShowOverwriteDialog(ShowAppend: boolean; SourceItem, DestItem: PDataItem; const SourceFile, DestFile: string; var RenameStr: string): integer; FNewDirCaption, FNewDirLabel, FNewDirEdit: string; - function ShowNewDirDialog(Caption, LabelCaption, Edit: string): integer; FMsgBoxText: string; FMsgBoxButtons: TMessageButtons; FMsgBoxStyle: TMessageStyle; FMsgBoxDefault, FMsgBoxEscape, FDialogResultMsgBox: TMessageButton; + + procedure UpdateProgress1(const Progress: Int64; const ProgressText: string); + procedure UpdateProgress2(const Progress: Int64; const ProgressText: string); + procedure SetProgress1Params(const ProgressMax: Int64); + procedure SetProgress2Params(const ProgressMax: Int64); + procedure UpdateCaption1(const CaptionText: string); + procedure UpdateCaption2(const CaptionText: string); + function ShowDirDeleteDialog(ButtonsType: TFDirDeleteButtonSet; const Title, FileName: string; Error: PGError): integer; + function ShowOverwriteDialog(ShowAppend: boolean; SourceItem, DestItem: PDataItem; const SourceFile, DestFile: string; var RenameStr: string): integer; + function ShowNewDirDialog(Caption, LabelCaption, Edit: string): integer; function ShowMessageBox(const Text: string; Buttons: TMessageButtons; Style: TMessageStyle; Default, Escape: TMessageButton): TMessageButton; @@ -140,8 +142,6 @@ type TVFSCallbackThread = class(TThread) CopyTargetPath: string; - FCopySkipAllErrors: boolean; - QuickRenameDataItem: PDataItem; ExtractFromVFSAll: boolean; @@ -262,11 +262,12 @@ begin if pthread_self = Application.ThreadID then begin DebugMsg(['!! (WARNING): vfs_ask_question_callback called from the main thread, expected spawn from a TVFSCallbackThread']); HandleVFSAskQuestionCallback(Thread.DialogsParentWindow.FWidget, AMessage, Choices, choice); - if (choice <> nil) then Thread.VFSCallbackCancelled := (choice^ < 0) or (choice^ = cancel_choice); + if (choice <> nil) then + Thread.VFSCallbackCancelled := (choice^ < 0) or (choice^ = cancel_choice); Exit; end; if pthread_self = Thread.FThreadID then begin - DebugMsg(['******* vfs_ask_question_callback spawned, user_data = 0x', IntToHex(QWord(user_data), 16), ', ThreadID = 0x', IntToHex(pthread_self, 16)]); + DebugMsg(['******* vfs_ask_question_callback spawned, user_data = ', user_data, ', ThreadID = ', pthread_self]); Thread.VFSAskQuestion_Message := AMessage; Thread.VFSAskQuestion_Choices := Choices; Thread.VFSAskQuestion_Choice := choice; @@ -274,7 +275,8 @@ begin Thread.VFSCallbackEvent.ResetEvent; Thread.VFSCallbackEvent.WaitFor(INFINITE); DebugMsg(['******* thread: resuming...']); - if (choice <> nil) then Thread.VFSCallbackCancelled := (choice^ < 0) or (choice^ = cancel_choice); + if (choice <> nil) then + Thread.VFSCallbackCancelled := (choice^ < 0) or (choice^ = cancel_choice); Exit; end; DebugMsg(['!! (ERROR): vfs_ask_question_callback spawned neither from the main thread nor from active TVFSCallbackThread, dropping the callback to prevent data corruption.']); @@ -336,7 +338,7 @@ begin Thread.VFSCallbackCancelled := Result = False; end else if pthread_self = Thread.FThreadID then begin - DebugMsg(['******* vfs_ask_password_callback spawned, user_data = 0x', IntToHex(QWord(user_data), 16), ', ThreadID = 0x', IntToHex(pthread_self, 16), ', Application.ThreadID = 0x', IntToHex(Application.ThreadID, 16)]); + DebugMsg(['******* vfs_ask_password_callback spawned, user_data = ', user_data, ', ThreadID = ', pthread_self, ', Application.ThreadID = ', Application.ThreadID]); Thread.VFSAskPassword_Message := AMessage; Thread.VFSAskPassword_default_user := default_user; Thread.VFSAskPassword_default_domain := default_domain; @@ -374,20 +376,6 @@ begin password_save^ := VFS_PASSWORD_SAVE_NEVER; end; -// Keep in sync with uVFSprototypes.pas/TVFSProgressCallback -function vfs_copy_progress_callback(position: guint64; error: PGError; user_data: Pointer): gboolean; cdecl; -begin -// DebugMsg(['VFSCopyCallBackFunc called (iPos = ', iPos, ', iMax = ', iMax, ')']); - Result := True; - if not Assigned(user_data) then Exit; - if Assigned(TVFSCallbackThread(user_data).FCopyProgressFunc) then - try - Result := TVFSCallbackThread(user_data).FCopyProgressFunc(user_data, position, error); - except - on E: Exception do DebugMsg(['*** Exception raised in vfs_copy_progress_callback(position=', position, ', user_data=', user_data, '): (', E.ClassName, '): ', E.Message]); - end; -end; - (********************************************************************************************************************************) (********************************************************************************************************************************) procedure TWorkerThread.Execute; @@ -425,6 +413,7 @@ begin FDialogShowMsgBox := False; ErrorHappened := False; FGUIChanged := False; + FCopyProgressFunc := nil; JobType := WORKER_JOB_DUMMY; // Defaults, keep in sync with class interface @@ -911,22 +900,35 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) + + // Keep in sync with uVFSprototypes.pas/TVFSProgressCallback + function vfs_copy_progress_callback(position: guint64; error: PGError; user_data: Pointer): gboolean; cdecl; + begin + Result := True; + if not Assigned(user_data) then Exit; + if Assigned(TWorkerThread(user_data).FCopyProgressFunc) then + try + Result := TWorkerThread(user_data).FCopyProgressFunc(user_data, position, error); + except + on E: Exception do DebugMsg(['*** Exception raised in vfs_copy_progress_callback(position=', position, ', user_data=', user_data, '): (', E.ClassName, '): ', E.Message]); + end; + end; + // Keep in sync with UEngines.pas/TEngineProgressFunc function CopyFilesWorker_ProgressFunc(Sender: Pointer; BytesDone: Int64; Error: PGError): boolean; cdecl; begin Result := True; -// DebugMsg(['*** CopyFilesWorker: ProgressFunc called (Sender=', QWord(Sender), ', BytesDone=', BytesDone, ')']); try - if Assigned(Sender) and (TObject(Sender) is TWorkerThread) then - with TWorkerThread(Sender) do begin - if BytesDone = 0 then UpdateProgress1(0, '0%') - else UpdateProgress1(BytesDone, Format('%d%%', [Round(BytesDone / FFileSize * 100)])); - UpdateProgress2(FTotalDone + BytesDone, Format('%d%%', [Round((FTotalDone + BytesDone) / FTotalSize * 100)])); - Result := not FCancelled; - CommitGUIUpdate; - end else DebugMsg(['*** CopyFilesWorker: Sender is not TWorkerThread']); + if Assigned(Sender) and (TObject(Sender) is TWorkerThread) then + with TWorkerThread(Sender) do begin + if BytesDone = 0 then UpdateProgress1(0, '0%') + else UpdateProgress1(BytesDone, Format('%d%%', [Round(BytesDone / FFileSize * 100)])); + UpdateProgress2(FTotalDone + BytesDone, Format('%d%%', [Round((FTotalDone + BytesDone) / FTotalSize * 100)])); + Result := not FCancelled; + CommitGUIUpdate; + end else DebugMsg(['*** CopyFilesWorker: Sender is not TWorkerThread']); except - on E: Exception do DebugMsg(['*** Exception raised in ProgressFunc(Sender=', QWord(Sender), ', BytesDone=', BytesDone, '): (', E.ClassName, '): ', E.Message]); + on E: Exception do DebugMsg(['*** Exception raised in ProgressFunc(Sender=', Sender, ', BytesDone=', BytesDone, '): (', E.ClassName, '): ', E.Message]); end; end; @@ -1190,7 +1192,7 @@ var DefResponse: integer; // Global variables for this function end; // DebugMsg(['(II) CopyFilesWorker.DoOperation: finished']); except - on E: Exception do DebugMsg(['*** Exception raised in DoOperation(AFileRec=', QWord(AFileRec), ', Dst=', Dst, ', ErrorKind=', ErrorKind, ', Append=', Append, '): (', E.ClassName, '): ', E.Message]); + on E: Exception do DebugMsg(['*** Exception raised in DoOperation(AFileRec=', AFileRec, ', Dst=', Dst, ', ErrorKind=', ErrorKind, ', Append=', Append, '): (', E.ClassName, '): ', E.Message]); end; end; @@ -1354,7 +1356,7 @@ var DefResponse: integer; // Global variables for this function end; // DebugMsg(['(II) CopyFilesWorker.HandleCopy: finished']); except - on E: Exception do DebugMsg(['*** Exception raised in HandleCopy(AFileRec=', QWord(AFileRec), ', NewFilePath=', NewFilePath, '): (', E.ClassName, '): ', E.Message]); + on E: Exception do DebugMsg(['*** Exception raised in HandleCopy(AFileRec=', AFileRec, ', NewFilePath=', NewFilePath, '): (', E.ClassName, '): ', E.Message]); end; end; |
