summaryrefslogtreecommitdiff
path: root/UCoreWorkers.pas
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2024-12-23 23:59:45 +0100
committerTomas Bzatek <tbzatek@redhat.com>2025-11-27 19:36:10 +0100
commitb9703b29819b619037cc282d719c187e51bacd30 (patch)
treebd6d73e5fb6bcb6eb307844103b3dff185f2ac9a /UCoreWorkers.pas
parenta9634b933f71a9045e61d29c486f2d51d39fd1e2 (diff)
downloadtuxcmd-b9703b29819b619037cc282d719c187e51bacd30.tar.xz
Port to g-i generated glib2 bindings
Includes switch to FPC -Mobjfpc and related pointer style fixes.
Diffstat (limited to 'UCoreWorkers.pas')
-rw-r--r--UCoreWorkers.pas73
1 files changed, 40 insertions, 33 deletions
diff --git a/UCoreWorkers.pas b/UCoreWorkers.pas
index c6a8d28..307e695 100644
--- a/UCoreWorkers.pas
+++ b/UCoreWorkers.pas
@@ -20,7 +20,7 @@
unit UCoreWorkers;
interface
-uses glib2, gtk2, SyncObjs, Classes, GTKForms, ULibc, UEngines, UCoreUtils, UVFSCore, uVFSprototypes, UCore, UDirDelete;
+uses lazglib2, lazgobject2, gtk2, SyncObjs, Classes, GTKForms, ULibc, UEngines, UCoreUtils, UVFSCore, uVFSprototypes, UCore, UDirDelete;
type TWorkerThreadJobType = (WORKER_JOB_DUMMY, WORKER_JOB_DELETE, WORKER_JOB_COPY, WORKER_JOB_MOVE, WORKER_JOB_EXTRACT_TO_TEMP,
@@ -28,7 +28,7 @@ type TWorkerThreadJobType = (WORKER_JOB_DUMMY, WORKER_JOB_DELETE, WORKER_JOB_COP
type TVFSCallbackThread = class(TThread)
private
- FThreadID: __pthread_t;
+ FPThreadID: __pthread_t;
FFinished: boolean;
VFSCallbackEvent: TSimpleEvent;
@@ -216,8 +216,7 @@ procedure ProcessThreadEvents(SenderThread: TVFSCallbackThread);
implementation
uses SysUtils, DateUtils, StrUtils, UConfig, UOverwrite, ULocale,
- UCoreClasses, URemoteWait, UMain, UGnome, UNewDir, UProgress,
- UError, crc;
+ URemoteWait, UMain, UGnome, UNewDir, UProgress, UError, crc;
@@ -245,7 +244,7 @@ end;
procedure TVFSCallbackThread.PrepareExecute;
begin
- FThreadID := pthread_self;
+ FPThreadID := pthread_self;
VFSCallbackCancelled := False;
end;
@@ -253,7 +252,7 @@ end;
procedure vfs_ask_question_callback(const AMessage: PChar; const Choices: PPChar; choice: PInteger; cancel_choice: Integer; user_data: Pointer); cdecl;
var Thread: TVFSCallbackThread;
begin
- Thread := user_data;
+ Thread := TVFSCallbackThread(user_data);
if (Thread = nil) { or (not (Thread is TVFSCallbackThread))} then begin
DebugMsg(['(ERROR): vfs_ask_question_callback: user_data is not TVFSCallbackThread, exiting.']);
Exit;
@@ -271,7 +270,7 @@ begin
Thread.VFSCallbackCancelled := (choice^ < 0) or (choice^ = cancel_choice);
Exit;
end;
- if pthread_self = Thread.FThreadID then begin
+ if pthread_self = Thread.FPThreadID then begin
DebugMsg(['******* vfs_ask_question_callback spawned, user_data = ', user_data, ', ThreadID = ', pthread_self]);
Thread.VFSAskQuestion_Message := AMessage;
Thread.VFSAskQuestion_Choices := Choices;
@@ -285,7 +284,7 @@ begin
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.']);
- DebugMsg([' ThreadID = 0x', IntToHex(pthread_self, 16), ', TVFSCallbackThread ID = 0x', IntToHex(Thread.FThreadID, 16), ', Application.ThreadID = 0x', IntToHex(Application.ThreadID, 16)]);
+ DebugMsg([' ThreadID = 0x', IntToHex(pthread_self, 16), ', TVFSCallbackThread ID = 0x', IntToHex(Thread.FPThreadID, 16), ', Application.ThreadID = 0x', IntToHex(Application.ThreadID, 16)]);
end;
function vfs_ask_password_callback(const AMessage: PChar; const default_user: PChar; const default_domain: PChar; const default_password: PChar; flags: TVFSAskPasswordFlags;
@@ -295,7 +294,7 @@ var Thread: TVFSCallbackThread;
def_pass: PChar;
begin
Result := False;
- Thread := user_data;
+ Thread := TVFSCallbackThread(user_data);
if (Thread = nil) { or (not (Thread is TVFSCallbackThread))} then begin
DebugMsg(['(ERROR): vfs_ask_question_callback: user_data is not TVFSCallbackThread, exiting.']);
Exit;
@@ -342,7 +341,7 @@ begin
Result := HandleVFSAskPasswordCallback(Thread.DialogsParentWindow.FWidget, AMessage, default_user, default_domain, def_pass, flags, username, password, anonymous, domain, password_save);
Thread.VFSCallbackCancelled := Result = False;
end else
- if pthread_self = Thread.FThreadID then begin
+ if pthread_self = Thread.FPThreadID then begin
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;
@@ -364,7 +363,7 @@ begin
end else
begin
DebugMsg(['!! (ERROR): vfs_ask_password_callback spawned neither from the main thread nor from active TVFSCallbackThread, dropping the callback to prevent data corruption.']);
- DebugMsg([' ThreadID = 0x', IntToHex(pthread_self, 16), ', TVFSCallbackThread ID = 0x', IntToHex(Thread.FThreadID, 16), ', Application.ThreadID = 0x', IntToHex(Application.ThreadID, 16)]);
+ DebugMsg([' ThreadID = 0x', IntToHex(pthread_self, 16), ', TVFSCallbackThread ID = 0x', IntToHex(Thread.FPThreadID, 16), ', Application.ThreadID = 0x', IntToHex(Application.ThreadID, 16)]);
end;
// Save password back to the engine
@@ -984,6 +983,8 @@ end;
Result := False;
Exit;
end;
+ s := '';
+ s2 := '';
GetCopyProgressErrorLabels(TWorkerThread(Sender), Error, s, s2);
case ShowDirDeleteDialog(DIR_DELETE_SET_COPY_ERROR, s, s2, StrToUTF8(Error^.message)) of
DIR_DELETE_IGNORE : Result := True;
@@ -1028,7 +1029,7 @@ var DefResponse: integer; // Global variables for this function
if (g_error_matches (LocalError, TUXCMD_ERROR, gint(TUXCMD_ERROR_CANCELLED))) then
g_propagate_error (Error, LocalError)
else begin
- g_set_error(Error, TUXCMD_ERROR, gint(MaskErrorCode), LocalError^.message);
+ g_set_error_literal(Error, TUXCMD_ERROR, gint(MaskErrorCode), LocalError^.message);
g_error_free(LocalError);
end;
end;
@@ -1063,7 +1064,7 @@ var DefResponse: integer; // Global variables for this function
BSize := DestEngine.GetBlockSize;
Buffer := malloc(BSize);
if Buffer = nil then begin
- g_set_error(Error, TUXCMD_ERROR, gint(TUXCMD_ERROR_ALLOC_FAILED), '%m');
+ g_set_error(Error, TUXCMD_ERROR, gint(TUXCMD_ERROR_ALLOC_FAILED), '%m', []);
CopyFilesWorker_ProgressFunc(Self, 0, Error^); // Memory allocation failed
Exit;
end;
@@ -1132,7 +1133,7 @@ var DefResponse: integer; // Global variables for this function
Result := False;
try
AEngine := nil;
- FCopyProgressFunc := CopyFilesWorker_ProgressFunc;
+ FCopyProgressFunc := @CopyFilesWorker_ProgressFunc;
// local -> local
if (SrcEngine is TLocalTreeEngine) and (DestEngine is TLocalTreeEngine)
@@ -1387,6 +1388,8 @@ var DefResponse: integer; // Global variables for this function
Result := False;
Exit;
end;
+ s := '';
+ s2 := '';
GetCopyProgressErrorLabels(Self, Error, s, s2);
s3 := StrToUTF8(Error^.message);
if (Error^.domain = TUXCMD_ERROR) then
@@ -1566,9 +1569,9 @@ begin
if List.Count > 0 then begin
StartPassed := True;
if SrcEngine is TVFSEngine then
- StartPassed := StartPassed and (SrcEngine as TVFSEngine).StartCopyOperation(@vfs_ask_question_callback, @vfs_ask_password_callback, @vfs_copy_progress_callback, Self);
+ StartPassed := StartPassed and (SrcEngine as TVFSEngine).StartCopyOperation(PVFSAskQuestionCallback(@vfs_ask_question_callback), PVFSAskPasswordCallback(@vfs_ask_password_callback), PVFSProgressCallback(@vfs_copy_progress_callback), Self);
if DestEngine is TVFSEngine then
- StartPassed := StartPassed and (DestEngine as TVFSEngine).StartCopyOperation(@vfs_ask_question_callback, @vfs_ask_password_callback, @vfs_copy_progress_callback, Self);
+ StartPassed := StartPassed and (DestEngine as TVFSEngine).StartCopyOperation(PVFSAskQuestionCallback(@vfs_ask_question_callback), PVFSAskPasswordCallback(@vfs_ask_password_callback), PVFSProgressCallback(@vfs_copy_progress_callback), Self);
if StartPassed then
for i := 0 to List.Count - 1 do begin
@@ -1614,9 +1617,9 @@ begin
// We need to ensure these to be called in case of error
if SrcEngine is TVFSEngine then
- (SrcEngine as TVFSEngine).StopCopyOperation(@vfs_copy_progress_callback, Self);
+ (SrcEngine as TVFSEngine).StopCopyOperation(PVFSProgressCallback(@vfs_copy_progress_callback), Self);
if DestEngine is TVFSEngine then
- (DestEngine as TVFSEngine).StopCopyOperation(@vfs_copy_progress_callback, Self);
+ (DestEngine as TVFSEngine).StopCopyOperation(PVFSProgressCallback(@vfs_copy_progress_callback), Self);
end;
end;
@@ -1869,6 +1872,8 @@ var FD: TEngineFileDes;
xx: string;
begin
Result := False;
+ x := 0;
+ xx := '';
AEngine.GetFileSystemInfo(FilePath, x, TDF, xx);
// Calculate part size
if SplitMaxSize = 0 then begin
@@ -1949,6 +1954,8 @@ begin
CommitGUIUpdate;
repeat
+ x := 0;
+ xx := '';
AEngine.GetFileSystemInfo(FilePath, x, TDF, xx);
// Delete target files if necessary
if SplitDeleteTarget and ((TDF < 512) or (TDF < FileSize) or (TDF < SplitMaxSize)) then try
@@ -2279,19 +2286,19 @@ function TOpenDirThread.ChangeDir(Engine: TPanelEngine; Path: string; var SelIte
NewPath := IncludeTrailingPathDelimiter(NewPath);
end;
-var APath: string;
+var FPath: string;
begin
Result := False;
try
- APath := Engine.Path;
- if Path = '..' then GoUp(APath)
+ FPath := Engine.Path;
+ if Path = '..' then GoUp(FPath)
else begin
- APath := IncludeTrailingPathDelimiter(APath);
+ FPath := IncludeTrailingPathDelimiter(FPath);
Path := IncludeTrailingPathDelimiter(Path);
if (Length(Path) > 0) and (Path[1] <> '/')
- then APath := APath + Path
- else APath := Path;
- APath := IncludeTrailingPathDelimiter(APath);
+ then FPath := FPath + Path
+ else FPath := Path;
+ FPath := IncludeTrailingPathDelimiter(FPath);
end;
// AutoFallback loop
@@ -2301,15 +2308,15 @@ begin
ChDirError := nil;
end;
if Engine is TVFSEngine
- then Result := (Engine as TVFSEngine).ChangeDirEx(APath, @vfs_ask_question_callback, @vfs_ask_password_callback, nil, Self, @ChDirError)
- else Result := Engine.ChangeDir(APath, @ChDirError);
+ then Result := (Engine as TVFSEngine).ChangeDirEx(FPath, PVFSAskQuestionCallback(@vfs_ask_question_callback), PVFSAskPasswordCallback(@vfs_ask_password_callback), nil, Self, @ChDirError)
+ else Result := Engine.ChangeDir(FPath, @ChDirError);
if not Result then begin
- PrefixTuxcmdError(@ChDirError, ExcludeTrailingPathDelimiter(APath));
- GoUp(APath);
+ PrefixTuxcmdError(@ChDirError, ExcludeTrailingPathDelimiter(FPath));
+ GoUp(FPath);
end;
- until Result or (not AutoFallback) or (Length(APath) <= 1);
+ until Result or (not AutoFallback) or (Length(FPath) <= 1);
if Result then
- Engine.Path := APath;
+ Engine.Path := FPath;
except
on E: Exception do begin
Result := False;
@@ -2333,7 +2340,7 @@ begin
xEngine.SavePath := AEngine.Path;
// AEngine must be set here since VFSOpenEx callbacks will reference it
AEngine := xEngine;
- VFSOpenResult := (AEngine as TVFSEngine).VFSOpenEx(AFullPath, @vfs_ask_question_callback, @vfs_ask_password_callback, nil, Self, @VFSOpenError);
+ VFSOpenResult := (AEngine as TVFSEngine).VFSOpenEx(AFullPath, PVFSAskQuestionCallback(@vfs_ask_question_callback), PVFSAskPasswordCallback(@vfs_ask_password_callback), nil, Self, @VFSOpenError);
end else VFSOpenResult := True;
if VFSOpenResult and (not FCancelled) then begin
@@ -2374,7 +2381,7 @@ procedure TOpenConnectionThread.Execute;
begin
PrepareExecute;
try
- OpenResult := (AEngine as TVFSEngine).VFSOpenURI(URI, @vfs_ask_question_callback, @vfs_ask_password_callback, nil, Self, @OpenError);
+ OpenResult := (AEngine as TVFSEngine).VFSOpenURI(URI, PVFSAskQuestionCallback(@vfs_ask_question_callback), PVFSAskPasswordCallback(@vfs_ask_password_callback), nil, Self, @OpenError);
finally
FFinished := True;
end;