Skip to content

Commit 87305ef

Browse files
committed
Mac progress bar support
1 parent 84450f1 commit 87305ef

5 files changed

Lines changed: 182 additions & 164 deletions

File tree

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
Class constructor($data : Object; $callback : 4D:C1709.Function; $callbackID : Text)
2-
This:C1470.encoding:="UTF-8"
3-
This:C1470.dataType:="text"
4-
This:C1470.hideWindow:=True:C214
5-
This:C1470.data:=$data
6-
If (Count parameters:C259>1)
7-
This:C1470.callback:=$callback
8-
This:C1470.callbackID:=$callbackID
9-
ASSERT:C1129(Value type:C1509($callback)=Is object:K8:27; "Callback must be of type function")
10-
ASSERT:C1129(OB Instance of:C1731($callback; 4D:C1709.Function); "Callback must be of type function")
11-
ASSERT:C1129($callbackID#""; "Callback ID Method must not be empty")
12-
End if
13-
If (Is macOS:C1572)
14-
This:C1470._return:=Char:C90(10)
15-
Else
16-
This:C1470._return:=Char:C90(13)
17-
End if
18-
19-
//Function onData($systemworker : Object; $data : Object)
20-
// not needed for Curl or Dropbox
21-
22-
Function onDataError($systemworker : Object; $data : Object)
23-
// called when data is received from curl or dropbox to handle progress bar
24-
25-
If (String:C10($data.data)#"")
26-
This:C1470.data.text+=$data.data
27-
//This._createFile("onDataError"; This.data.text) // debug
28-
If (This:C1470.callback#Null:C1517)
29-
$pos:=Position:C15(This:C1470._return; This:C1470.data.text)
30-
If ($pos>0)
31-
If ($pos=Length:C16(This:C1470.data.text)) // Dropbox
32-
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; This:C1470.data.text; -1)
33-
This:C1470.data.text:=""
34-
Else // Curl
35-
$message:=Substring:C12(This:C1470.data.text; 1; $pos-1)
36-
This:C1470.data.text:=Substring:C12(This:C1470.data.text; $pos+1)
37-
$progress:=Num:C11(Substring:C12($message; 1; 3))
38-
If ($progress#0)
39-
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; $message; $progress)
40-
End if
41-
End if
42-
End if
43-
End if
44-
End if
45-
46-
Function onTerminate($systemworker : Object; $data : Object)
47-
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; ""; 100)
48-
//This._createFile("onTerminate"; $data.data)
49-
50-
51-
52-
Function _createFile($title : Text; $textBody : Text)
53-
// debug
1+
Class constructor($data : Object; $callback : 4D:C1709.Function; $callbackID : Text)
2+
This:C1470.encoding:="UTF-8"
3+
This:C1470.dataType:="text"
4+
This:C1470.hideWindow:=True:C214
5+
This:C1470.data:=$data
6+
If (Count parameters:C259>1)
7+
This:C1470.callback:=$callback
8+
This:C1470.callbackID:=$callbackID
9+
ASSERT:C1129(Value type:C1509($callback)=Is object:K8:27; "Callback must be of type function")
10+
ASSERT:C1129(OB Instance of:C1731($callback; 4D:C1709.Function); "Callback must be of type function")
11+
ASSERT:C1129($callbackID#""; "Callback ID Method must not be empty")
12+
End if
13+
If (Is macOS:C1572)
14+
This:C1470._return:=Char:C90(13)
15+
Else
16+
This:C1470._return:=Char:C90(13)
17+
End if
18+
19+
//Function onData($systemworker : Object; $data : Object)
20+
// not needed for Curl or Dropbox
21+
22+
Function onDataError($systemworker : Object; $data : Object)
23+
// called when data is received from curl or dropbox to handle progress bar
24+
25+
If (String:C10($data.data)#"")
26+
This:C1470.data.text+=$data.data
27+
//This._createFile("onDataError"; This.data.text) // debug
28+
If (This:C1470.callback#Null:C1517)
29+
$pos:=Position:C15(This:C1470._return; This:C1470.data.text)
30+
If ($pos>0)
31+
If ($pos=Length:C16(This:C1470.data.text)) // Dropbox
32+
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; This:C1470.data.text; -1)
33+
This:C1470.data.text:=""
34+
Else // Curl
35+
$message:=Substring:C12(This:C1470.data.text; 1; $pos-1)
36+
This:C1470.data.text:=Substring:C12(This:C1470.data.text; $pos+1)
37+
$progress:=Num:C11(Substring:C12($message; 1; 3))
38+
If ($progress#0)
39+
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; $message; $progress)
40+
End if
41+
End if
42+
End if
43+
End if
44+
End if
45+
46+
Function onTerminate($systemworker : Object; $data : Object)
47+
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; ""; 100)
48+
//This._createFile("onTerminate"; $data.data)
49+
50+
51+
52+
Function _createFile($title : Text; $textBody : Text)
53+
// debug
5454
TEXT TO DOCUMENT:C1237(Get 4D folder:C485(Current resources folder:K5:16)+$title+".txt"; $textBody)

Project/Sources/Methods/test_GDrive.4dm

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ If (False:C215)
1010
End if
1111
End if
1212

13-
// try service settings
14-
$path:=System folder:C487(Desktop:K41:16)+"dtest-342209-2b8950784dab.json"
15-
$service:=Convert path system to POSIX:C1106($path)
16-
$result:=$ftp.setServiceAccount($service)
1713

1814
If (False:C215)
1915
$source:="/" // only root/top level
@@ -56,7 +52,6 @@ If (False:C215)
5652
End if
5753
End if
5854

59-
// upload große datei, progress bar - Windows
6055
If (False:C215)
6156
$ftp.useCallback(Formula:C1597(ProgressCallback); "ProgressCallback")
6257
$source:=System folder:C487(Desktop:K41:16)+"result.pdf"
@@ -105,7 +100,6 @@ End if
105100

106101

107102
If (False:C215)
108-
// only Windows, Callback not available on Mac
109103
$ftp.useCallback(Formula:C1597(ProgressCallback); "Download 4D.dmg")
110104
$ftp.setAsyncMode(True:C214)
111105

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ If (True:C214)
8787
End if
8888

8989
If (True:C214)
90-
// only Windows, Callback not available on Mac
9190
$source:="/large/4D.dmg"
9291
$ftp.setCurlPrefix("--limit-rate 25M")
9392
$ftp.useCallback(Formula:C1597(ProgressCallback); "Download 4D.dmg")
Lines changed: 90 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,90 @@
1-
//%attributes = {}
2-
var $ftp : cs:C1710.FileTransfer_Dropbox
3-
$ftp:=cs:C1710.FileTransfer_Dropbox.new()
4-
//$ftp.setPath(" /Users/thomas/Desktop/dbxcli")
5-
6-
7-
If (False:C215)
8-
$source:="/"
9-
$result:=$ftp.version($source)
10-
If ($result.success)
11-
$answer:=$result.data
12-
End if
13-
End if
14-
15-
16-
If (False:C215)
17-
$source:="/"
18-
$result:=$ftp.getDirectoryListing($source)
19-
If ($result.success)
20-
$answer:=$result.data
21-
End if
22-
End if
23-
24-
25-
// upload große datei, progress bar - Windows
26-
If (False:C215)
27-
$ftp.useCallback(Formula:C1597(ProgressCallback); "ProgressCallback")
28-
$source:=System folder:C487(Desktop:K41:16)+"Heap.pdf"
29-
$source:=Convert path system to POSIX:C1106($source)
30-
$target:="/Firma/test2.pdf"
31-
$result:=$ftp.upload($source; $target)
32-
If ($result.success)
33-
$answer:=$result.data
34-
End if
35-
End if
36-
37-
If (False:C215)
38-
$ftp.useCallback(Formula:C1597(ProgressCallback); "ProgressCallback")
39-
$target:=System folder:C487(Desktop:K41:16)+"result.pdf"
40-
$target:=Convert path system to POSIX:C1106($target)
41-
$source:="/Firma/test2.pdf"
42-
$result:=$ftp.download($source; $target)
43-
If ($result.success)
44-
$answer:=$result.data
45-
End if
46-
End if
47-
48-
49-
If (True:C214)
50-
// only Windows, Callback not available on Mac
51-
$ftp.useCallback(Formula:C1597(ProgressCallback); "Download 4D.dmg")
52-
$ftp.setAsyncMode(True:C214)
53-
54-
$source:=System folder:C487(Desktop:K41:16)+"Heap.pdf"
55-
$source:=Convert path system to POSIX:C1106($source)
56-
$target:="/Firma/test2.pdf"
57-
$result:=$ftp.upload($source; $target)
58-
59-
// async, so we need to loop...
60-
// normally we are supposed to do something else and either
61-
// check from time to time or to use the callback method to inform us (percent=100)
62-
Repeat
63-
$ftp.wait(1) // needed while our process is running
64-
// wait is not needed if a form would be open or if a worker would handle the job
65-
$status:=$ftp.status()
66-
67-
Until (Bool:C1537($status.terminated))
68-
69-
End if
70-
71-
If (False:C215)
72-
$target:="/Firma/newdir"
73-
$result:=$ftp.createDirectory($target)
74-
If ($result.success)
75-
$answer:=$result.data
76-
End if
77-
End if
78-
79-
If (False:C215)
80-
$target:="/Firma/newdir"
81-
$result:=$ftp.deleteDirectory($target; True:C214) // delete even with content
82-
If ($result.success)
83-
$answer:=$result.data
84-
End if
85-
End if
86-
87-
If (False:C215)
88-
$target:="/Firma/test2.pdf"
89-
$result:=$ftp.deleteFile($target)
90-
If ($result.success)
91-
$answer:=$result.data
92-
End if
93-
End if
1+
//%attributes = {}
2+
var $ftp : cs:C1710.FileTransfer_Dropbox
3+
$ftp:=cs:C1710.FileTransfer_Dropbox.new()
4+
//$ftp.setPath(" /Users/thomas/Desktop/dbxcli")
5+
6+
7+
If (False:C215)
8+
$source:="/"
9+
$result:=$ftp.version($source)
10+
If ($result.success)
11+
$answer:=$result.data
12+
End if
13+
End if
14+
15+
16+
If (False:C215)
17+
$source:="/"
18+
$result:=$ftp.getDirectoryListing($source)
19+
If ($result.success)
20+
$answer:=$result.data
21+
End if
22+
End if
23+
24+
If (False:C215)
25+
$ftp.useCallback(Formula:C1597(ProgressCallback); "ProgressCallback")
26+
$source:=System folder:C487(Desktop:K41:16)+"Heap.pdf"
27+
$source:=Convert path system to POSIX:C1106($source)
28+
$target:="/Firma/test2.pdf"
29+
$result:=$ftp.upload($source; $target)
30+
If ($result.success)
31+
$answer:=$result.data
32+
End if
33+
End if
34+
35+
If (False:C215)
36+
$ftp.useCallback(Formula:C1597(ProgressCallback); "ProgressCallback")
37+
$target:=System folder:C487(Desktop:K41:16)+"result.pdf"
38+
$target:=Convert path system to POSIX:C1106($target)
39+
$source:="/Firma/test2.pdf"
40+
$result:=$ftp.download($source; $target)
41+
If ($result.success)
42+
$answer:=$result.data
43+
End if
44+
End if
45+
46+
47+
If (True:C214)
48+
$ftp.useCallback(Formula:C1597(ProgressCallback); "Download 4D.dmg")
49+
$ftp.setAsyncMode(True:C214)
50+
51+
$source:=System folder:C487(Desktop:K41:16)+"Heap.pdf"
52+
$source:=Convert path system to POSIX:C1106($source)
53+
$target:="/Firma/test2.pdf"
54+
$result:=$ftp.upload($source; $target)
55+
56+
// async, so we need to loop...
57+
// normally we are supposed to do something else and either
58+
// check from time to time or to use the callback method to inform us (percent=100)
59+
Repeat
60+
$ftp.wait(1) // needed while our process is running
61+
// wait is not needed if a form would be open or if a worker would handle the job
62+
$status:=$ftp.status()
63+
64+
Until (Bool:C1537($status.terminated))
65+
66+
End if
67+
68+
If (False:C215)
69+
$target:="/Firma/newdir"
70+
$result:=$ftp.createDirectory($target)
71+
If ($result.success)
72+
$answer:=$result.data
73+
End if
74+
End if
75+
76+
If (False:C215)
77+
$target:="/Firma/newdir"
78+
$result:=$ftp.deleteDirectory($target; True:C214) // delete even with content
79+
If ($result.success)
80+
$answer:=$result.data
81+
End if
82+
End if
83+
84+
If (False:C215)
85+
$target:="/Firma/test2.pdf"
86+
$result:=$ftp.deleteFile($target)
87+
If ($result.success)
88+
$answer:=$result.data
89+
End if
90+
End if
Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
//%attributes = {}
2-
var $ftp : cs:C1710.FileTransfer_curl
3-
$ftp:=cs:C1710.FileTransfer_curl.new("www.4d.com"; ""; ""; "https")
4-
$ftp.setConnectTimeout(5)
5-
6-
$source:="/de"
7-
$target:=System folder:C487(Desktop:K41:16)+"newtest2.txt"
8-
$target:=Convert path system to POSIX:C1106($target)
9-
$ftp.setCurlPrefix("--location") // follow 301 or 302
10-
$result:=$ftp.download($source; $target)
11-
If ($result.success)
12-
$answer:=$result.data
2+
If (False:C215)
3+
var $ftp : cs:C1710.FileTransfer_curl
4+
$ftp:=cs:C1710.FileTransfer_curl.new("www.4d.com"; ""; ""; "https")
5+
$ftp.setConnectTimeout(5)
6+
7+
$source:="/de"
8+
$target:=System folder:C487(Desktop:K41:16)+"newtest2.txt"
9+
$target:=Convert path system to POSIX:C1106($target)
10+
$ftp.setCurlPrefix("--location") // follow 301 or 302
11+
$result:=$ftp.download($source; $target)
12+
If ($result.success)
13+
$answer:=$result.data
14+
End if
15+
1316
End if
1417

18+
19+
If (True:C214)
20+
var $ftp : cs:C1710.FileTransfer_curl
21+
$ftp:=cs:C1710.FileTransfer_curl.new("download.4d.com"; ""; ""; "https")
22+
$ftp.setConnectTimeout(5)
23+
24+
$ftp.useCallback(Formula:C1597(ProgressCallback); "Download 4D.dmg")
25+
$ftp.setAsyncMode(True:C214)
26+
27+
$source:="/Products/4D_v19R3/Installers/4D_v19_R3_Mac.dmg"
28+
$target:=System folder:C487(Desktop:K41:16)+"4d.dmg"
29+
$target:=Convert path system to POSIX:C1106($target)
30+
$ftp.setCurlPrefix("--location") // follow 301 or 302
31+
$result:=$ftp.download($source; $target)
32+
Repeat
33+
$ftp.wait(1) // needed while our process is running
34+
// wait is not needed if a form would be open or if a worker would handle the job
35+
$status:=$ftp.status()
36+
37+
Until (Bool:C1537($status.terminated))
38+
If ($result.success)
39+
$answer:=$result.data
40+
End if
41+
42+
End if

0 commit comments

Comments
 (0)