Skip to content

Commit 5d787d8

Browse files
committed
progress bar support for Mac for all classes, documentation changes. gdrive tests missing Mac+Win
1 parent 87305ef commit 5d787d8

14 files changed

Lines changed: 171 additions & 78 deletions

Documentation/Classes/FileTransfer_Dropbox.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ Allows to show a progress bar during long running operations or to get informed
296296

297297
The callback method is called whenever a new progress message is available from dbxcli and get's 3 parameter passed. The given ID, the progress text and the completeness ratio from 0-100%.
298298

299-
Note: only useable on Windows.
300-
301299
#### Example
302300

303301
```4D

Documentation/Classes/FileTransfer_GDrive.md

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ All function returns a result object
8989
#### Description
9090
Upload one file to server.
9191

92-
If file already exists it is overwritten.
92+
If file already exists another instance is created. It could make sense to delete existing files (or use deleteFile even if the file is not existing)
9393
If source or target contains spaces, encapsulate with quotes (char(34)).
9494

9595
After uploading a file, the result object returns false or true.
9696

9797
## download
9898

99-
### .download(source: Text; target: Text; {fileID: text; {{fileQuery: text}}) -> result : Object
99+
### .download(source: Text; target: Text; {fileID: text; {fileQuery: text}}) -> result : Object
100100
|Parameter|Type||Description|
101101
|---------|--- |:---:|------|
102102
|source|Text|->|path to remote file|
@@ -136,7 +136,7 @@ If the query returns 2 or more documents with the same name (but different locat
136136
#### Description
137137
Upload one file to server and import it as Google document.
138138

139-
If file already exists it is overwritten.
139+
If file already exists another instance is created. It could make sense to delete existing files (or use deleteFile even if the file is not existing)
140140
If source or target contains spaces, encapsulate with quotes (char(34)).
141141

142142
After uploading a file, the result object returns false or true.
@@ -190,6 +190,40 @@ By passing the type, this can be overwritten. The import/converting follow this
190190
|application/vnd.ms-powerpoint|application/vnd.google-apps.presentation|
191191
|text/tab-separated-values|application/vnd.google-apps.spreadsheet|
192192

193+
## export
194+
195+
### .export(source: Text; target: Text; {fileID: text; {mime: text}}) -> result : Object
196+
|Parameter|Type||Description|
197+
|---------|--- |:---:|------|
198+
|source|Text|->|path to remote file|
199+
|target|Text|->|POSIX path to local file|
200+
|fileID|Text|->|optional: Google file ID|
201+
|mime|Text|->|optional: overwrite mime|
202+
|result|Object|<-|result object|
203+
204+
#### Description
205+
Download one document from server, automatically convert to local file type.
206+
207+
If file already exists it is overwritten.
208+
If source or target contains spaces, encapsulate with quotes (char(34)).
209+
210+
After downloading a file, the result object returns false or true.
211+
212+
Specify file with name (source) for comfort or compatibility with Dropbox/cURL class.
213+
Better/Faster to specify file by Google ID.
214+
Pass either ID or source, only one.
215+
216+
|From|To|
217+
|---------|---------|
218+
|application/vnd.google-apps.document|application/rtf, application/vnd.oasis.opendocument.text, text/html, application/pdf, application/epub+zip, application/zip, application/vnd.openxmlformats-officedocument.wordprocessingml.document, text/plain|
219+
|application/vnd.google-apps.spreadsheet|application/x-vnd.oasis.opendocument.spreadsheet, text/tab-separated-values, application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/csv, application/zip, application/vnd.oasis.opendocument.spreadsheet|
220+
|application/vnd.google-apps.jam|application/pdf|
221+
|application/vnd.google-apps.script|application/vnd.google-apps.script+json|
222+
|application/vnd.google-apps.presentation|application/vnd.oasis.opendocument.presentation, application/pdf, application/vnd.openxmlformats-officedocument.presentationml.presentation, text/plain|
223+
|application/vnd.google-apps.form|application/zip|
224+
|application/vnd.google-apps.drawing|image/svg+xml, image/png, application/pdf, image/jpeg|
225+
|application/vnd.google-apps.site|text/plain|
226+
193227

194228
## getDirectoryListing
195229

@@ -206,11 +240,11 @@ result.data contains unfiltered answer from server.
206240
result.list contains collection, each representing one file/directory.
207241

208242
The answer is parsed and .list collection contains:
209-
- revision // file revision, for folders "-"
210-
- size // file size, such as "76 KiB" or "315 MiB", for folder "-"
211-
- date // date, such as "1 year ago", "3 days ago", for folders "-"
212-
- path // full path to download/access "/filename.pdf"
213-
243+
- Id // file Id, identifier for all other commands
244+
- path // file name
245+
- type // document type, such as doc, pdf, dir
246+
- Size // size, such as 1.0 KB
247+
- date // date, such as 2022-03-02 14:27:36
214248

215249
## createDirectory
216250

@@ -281,13 +315,13 @@ Moves a file on remote server to another directory (and/or rename it)
281315
|result|Object|<-|result object|
282316

283317
#### Description
284-
Allows to pass any valid Dropbox dbxcli command and execute it. Result is returned directly.
318+
Allows to pass any valid gdrive command and execute it. Result is returned directly.
285319

286320
## Settings commands
287321

288322
## .version()
289323

290-
###.version() -> result : object
324+
### .version() -> result : object
291325
|Parameter|Type||Description|
292326
|---------|--- |:---:|------|
293327
|result|Object|<-|result object|
@@ -296,9 +330,9 @@ Allows to pass any valid Dropbox dbxcli command and execute it. Result is return
296330
returns in result.data version information from cURL.
297331

298332
Example:
299-
dbxcli version: v3.0.0
300-
SDK version: 5.4.0
301-
Spec version: 097e9ba
333+
gdrive: 2.1.1
334+
Golang: go1.17.8
335+
OS/Arch: darwin/amd64
302336

303337

304338
## setPath
@@ -309,10 +343,10 @@ Spec version: 097e9ba
309343
|Path|Text|->|Path to local dbxcli installation|
310344

311345
#### Description
312-
Allows to use another dbxcli installation.
346+
Allows to use another gdrive installation.
313347

314348
Precompiled versions for Mac and Windows can be downloaded from:
315-
[dbxcli](https://github.com/dropbox/dbxcli)
349+
[gdrive](https://github.com/prasmussen/gdrive/releases)
316350

317351

318352
## setAsyncMode
@@ -352,7 +386,7 @@ Return object contains:
352386
|terminated|boolean|true if command finished execution|
353387
|responseError|Text|error message if command failed|
354388
|response|Text|message if command succeeded|
355-
|exitCode|Text|exit code returned by dbxcli|
389+
|exitCode|Text|exit code returned by gdrive|
356390
|errors|collection|optional: execution errors received by 4D|
357391

358392
## wait
@@ -380,9 +414,7 @@ The command returns after given wait time or before if execution is finished.
380414
#### Description
381415
Allows to show a progress bar during long running operations or to get informed when command execution is complete.
382416

383-
The callback method is called whenever a new progress message is available from dbxcli and get's 3 parameter passed. The given ID, the progress text and the completeness ratio from 0-100%.
384-
385-
Note: only useable on Windows.
417+
The callback method is called whenever a new progress message is available from gdrive and get's 3 parameter passed. The given ID, the progress text and the completeness ratio from 0-100%.
386418

387419
#### Example
388420

Documentation/Classes/FileTransfer_curl.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,6 @@ Allows to show a progress bar during long running operations or to get informed
464464

465465
The callback method is called whenever a new progress message is available from cURL and get's 3 parameter passed. The given ID, the progress text and the completeness ratio from 0-100%.
466466

467-
Note: only useable on Windows.
468-
469467
#### Example
470468

471469
```4D

Project/Sources/Classes/FileTransfer_Dropbox.4dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ Function _parseDirListing($success : Object)
142142

143143
Function _runWorker($para : Text)->$result : Object
144144
If (This:C1470._Callback#Null:C1517)
145-
$workerpara:=cs:C1710.SystemWorkerProperties.new(This:C1470.onData; This:C1470._Callback; This:C1470._CallbackID)
145+
$workerpara:=cs:C1710.SystemWorkerProperties.new("dropbox"; This:C1470.onData; This:C1470._Callback; This:C1470._CallbackID)
146146
Else
147-
$workerpara:=cs:C1710.SystemWorkerProperties.new(This:C1470.onData)
147+
$workerpara:=cs:C1710.SystemWorkerProperties.new("dropbox"; This:C1470.onData)
148148
End if
149149

150150
If ((This:C1470._Path) && (This:C1470._Path#""))

Project/Sources/Classes/FileTransfer_GDrive.4dm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ Class constructor()
33
If (Is macOS:C1572)
44
This:C1470._return:=Char:C90(10)
55
This:C1470._Path:="/opt/homebrew/bin/gdrive"
6+
$path:=Get 4D folder:C485(Current resources folder:K5:16)+"gdrive"+Folder separator:K24:12+"gdrive"
7+
This:C1470._Path:=Convert path system to POSIX:C1106($path)
68
Else
79
This:C1470._return:=Char:C90(10) //Char(13)+Char(10)
8-
This:C1470._Path:="gdrive.exe"
10+
$path:=Get 4D folder:C485(Current resources folder:K5:16)+"gdrive"+Folder separator:K24:12+"gdrive.exe"
11+
This:C1470._Path:=Convert path system to POSIX:C1106($path)
912
End if
1013
This:C1470._workerpath:="" // needed for export
1114

@@ -73,9 +76,10 @@ Function getDirectoryListing($targetpath : Text; $ID : Text; $max : Integer)->$s
7376
Function upload($sourcepath : Text; $targetpath : Text)->$success : Object
7477
//$sourcepath just file name for local directory, else full path in POSIX syntax
7578
// targetpath is full remote path (starting with /, ending with file name
79+
// delete files before if you want to overwrite them, else you get a 2nd instance with same name
7680
ASSERT:C1129($sourcepath#""; "source path must not be empty")
7781
//ASSERT($targetpath#""; "target path must not be empty")
78-
$success:=This:C1470.__uploadSub($sourcepath; $targetpath)
82+
$success:=This:C1470._uploadSub($sourcepath; $targetpath)
7983

8084
Function _uploadSub($sourcepath : Text; $targetpath : Text; $mime : Text)->$success : Object
8185
// need to find target file name (for --name parameter) and target folder (to find --parent ID)
@@ -355,9 +359,9 @@ Function _parseDirListing($success : Object)
355359

356360
Function _runWorker($para : Text)->$result : Object
357361
If (This:C1470._Callback#Null:C1517)
358-
$workerpara:=cs:C1710.SystemWorkerProperties.new(This:C1470.onData; This:C1470._Callback; This:C1470._CallbackID)
362+
$workerpara:=cs:C1710.SystemWorkerProperties.new("gdrive"; This:C1470.onData; This:C1470._Callback; This:C1470._CallbackID)
359363
Else
360-
$workerpara:=cs:C1710.SystemWorkerProperties.new(This:C1470.onData)
364+
$workerpara:=cs:C1710.SystemWorkerProperties.new("gdrive"; This:C1470.onData)
361365
End if
362366

363367
If ((This:C1470._Path) && (This:C1470._Path#""))

Project/Sources/Classes/FileTransfer_curl.4dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ Function _buildURL()->$url : Text
289289

290290
Function _runWorker($para : Text)->$result : Object
291291
If (This:C1470._Callback#Null:C1517)
292-
$workerpara:=cs:C1710.SystemWorkerProperties.new(This:C1470.onData; This:C1470._Callback; This:C1470._CallbackID)
292+
$workerpara:=cs:C1710.SystemWorkerProperties.new("curl"; This:C1470.onData; This:C1470._Callback; This:C1470._CallbackID)
293293
Else
294-
$workerpara:=cs:C1710.SystemWorkerProperties.new(This:C1470.onData)
294+
$workerpara:=cs:C1710.SystemWorkerProperties.new("curl"; This:C1470.onData)
295295
End if
296296

297297
If ((This:C1470._curlPath) && (This:C1470._curlPath#""))

Project/Sources/Classes/SystemWorkerProperties.4dm

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
Class constructor($data : Object; $callback : 4D:C1709.Function; $callbackID : Text)
1+
Class constructor($type : Text; $data : Object; $callback : 4D:C1709.Function; $callbackID : Text)
2+
This:C1470.type:=$type
23
This:C1470.encoding:="UTF-8"
34
This:C1470.dataType:="text"
45
This:C1470.hideWindow:=True:C214
56
This:C1470.data:=$data
6-
If (Count parameters:C259>1)
7+
If (Count parameters:C259>2)
78
This:C1470.callback:=$callback
89
This:C1470.callbackID:=$callbackID
910
ASSERT:C1129(Value type:C1509($callback)=Is object:K8:27; "Callback must be of type function")
@@ -26,20 +27,30 @@ Function onDataError($systemworker : Object; $data : Object)
2627
This:C1470.data.text+=$data.data
2728
//This._createFile("onDataError"; This.data.text) // debug
2829
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
30+
Case of
31+
: (This:C1470.type="gdrive")
32+
$pos:=Position:C15(Char:C90(13); This:C1470.data.text)
33+
If ($pos>0)
34+
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; Substring:C12(This:C1470.data.text; 1; $pos-1); -1)
35+
This:C1470.data.text:=Substring:C12(This:C1470.data.text; $pos+1)
36+
End if
37+
: (This:C1470.type="dropbox")
38+
$pos:=Position:C15(This:C1470._return; This:C1470.data.text)
39+
If ($pos>0)
40+
If ($pos=Length:C16(This:C1470.data.text)) // Dropbox
41+
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; This:C1470.data.text; -1)
42+
This:C1470.data.text:=""
43+
End if
44+
End if
45+
Else
46+
$pos:=Position:C15(This:C1470._return; This:C1470.data.text)
3547
$message:=Substring:C12(This:C1470.data.text; 1; $pos-1)
3648
This:C1470.data.text:=Substring:C12(This:C1470.data.text; $pos+1)
3749
$progress:=Num:C11(Substring:C12($message; 1; 3))
3850
If ($progress#0)
3951
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; $message; $progress)
4052
End if
41-
End if
42-
End if
53+
End case
4354
End if
4455
End if
4556

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
//%attributes = {}
2-
#DECLARE($ID : Text; $message : Text; $value : Integer)
3-
// called from cs.FileTransfer if callback is set via .useCallback()
4-
5-
// $ID is set through code - $message comes from curl
6-
7-
var ProgressBarID : Integer
8-
9-
If ((ProgressBarID=0) && ($value#100))
10-
ProgressBarID:=Progress New
11-
Progress SET TITLE(ProgressBarID; $ID)
12-
End if
13-
14-
If (ProgressBarID#0)
15-
Case of
16-
: ($value=100)
17-
Progress QUIT(ProgressBarID)
18-
ProgressBarID:=0
19-
: ($value<0)
20-
Progress SET MESSAGE(ProgressBarID; $message)
21-
Else
22-
Progress SET PROGRESS(ProgressBarID; $value/100)
23-
End case
24-
End if
1+
//%attributes = {}
2+
#DECLARE($ID : Text; $message : Text; $value : Integer)
3+
// called from cs.FileTransfer if callback is set via .useCallback()
4+
5+
// $ID is set through code - $message comes from curl
6+
7+
var ProgressBarID : Integer
8+
9+
If ((ProgressBarID=0) && ($value#100))
10+
ProgressBarID:=Progress New
11+
Progress SET TITLE(ProgressBarID; $ID)
12+
End if
13+
14+
If (ProgressBarID#0)
15+
Case of
16+
: ($value=100)
17+
Progress QUIT(ProgressBarID)
18+
ProgressBarID:=0
19+
: ($value<0)
20+
$message2:=Replace string:C233($message; " "; "") // ignore totally empty messages, happens with gdrive
21+
If ($message2#"")
22+
Progress SET MESSAGE(ProgressBarID; $message)
23+
End if
24+
Else
25+
Progress SET PROGRESS(ProgressBarID; $value/100)
26+
End case
27+
End if

Project/Sources/Methods/test_GDrive.4dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ If (False:C215)
5252
End if
5353
End if
5454

55-
If (False:C215)
55+
If (True:C214)
5656
$ftp.useCallback(Formula:C1597(ProgressCallback); "ProgressCallback")
57-
$source:=System folder:C487(Desktop:K41:16)+"result.pdf"
57+
$source:=System folder:C487(Desktop:K41:16)+"4d.dmg"
5858
$source:=Convert path system to POSIX:C1106($source)
59-
$target:="/Firma/test/test2.pdf"
59+
$target:="/Firma/test/test2.dmg"
6060
$result:=$ftp.upload($source; $target)
6161
If ($result.success)
6262
$answer:=$result.data

Project/Sources/Methods/test_dropbox.4dm

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ If (False:C215)
4444
End if
4545

4646

47-
If (True:C214)
48-
$ftp.useCallback(Formula:C1597(ProgressCallback); "Download 4D.dmg")
47+
If (False:C215)
48+
$ftp.useCallback(Formula:C1597(ProgressCallback); "uploading 4D.dmg")
4949
$ftp.setAsyncMode(True:C214)
5050

51-
$source:=System folder:C487(Desktop:K41:16)+"Heap.pdf"
51+
$source:=System folder:C487(Desktop:K41:16)+"4d.dmg"
5252
$source:=Convert path system to POSIX:C1106($source)
53-
$target:="/Firma/test2.pdf"
53+
$target:="/Firma/4d.dmg"
5454
$result:=$ftp.upload($source; $target)
5555

5656
// async, so we need to loop...
@@ -65,6 +65,27 @@ If (True:C214)
6565

6666
End if
6767

68+
If (True:C214)
69+
$ftp.useCallback(Formula:C1597(ProgressCallback); "uploading 4D.dmg")
70+
//$ftp.setAsyncMode(True)
71+
72+
$source:=System folder:C487(Desktop:K41:16)+"4d.dmg"
73+
$source:=Convert path system to POSIX:C1106($source)
74+
$target:="/Firma/4d.dmg"
75+
$result:=$ftp.upload($source; $target)
76+
77+
// async, so we need to loop...
78+
// normally we are supposed to do something else and either
79+
// check from time to time or to use the callback method to inform us (percent=100)
80+
//Repeat
81+
//$ftp.wait(1) // needed while our process is running
82+
//// wait is not needed if a form would be open or if a worker would handle the job
83+
//$status:=$ftp.status()
84+
85+
//Until (Bool($status.terminated))
86+
87+
End if
88+
6889
If (False:C215)
6990
$target:="/Firma/newdir"
7091
$result:=$ftp.createDirectory($target)

0 commit comments

Comments
 (0)