mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: MacCloud/Options: step-93: Options for S3
This commit is contained in:
parent
c797022d0e
commit
cfb951952f
7 changed files with 187 additions and 6 deletions
|
|
@ -143,6 +143,12 @@
|
|||
<Unit>
|
||||
<Filename Value="wfx/ui/uwfxoptionsoauth2.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="uWFXOptionsOAuth2"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="wfx/ui/uwfxoptionss3.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="uWFXOptionsS3"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type
|
|||
class function createInstance: TCloudDriver; override;
|
||||
constructor Create( const config: TS3Config );
|
||||
function clone: TCloudDriver; override;
|
||||
function getEndPointByRegion(const region: String): String; override;
|
||||
end;
|
||||
|
||||
var
|
||||
|
|
@ -57,5 +58,10 @@ begin
|
|||
Result:= newClient;
|
||||
end;
|
||||
|
||||
function TAliyunOSSClient.getEndPointByRegion( const region: String ): String;
|
||||
begin
|
||||
Result:= 'oss-' + region + '.aliyuncs.com';
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ type
|
|||
procedure setConnectionData( const connectionData: TAWSConnectionData ); virtual; abstract;
|
||||
function getAccessKey: TAWSAccessKey; virtual; abstract;
|
||||
procedure setAccessKey( const accessKey: TAWSAccessKey ); virtual; abstract;
|
||||
function getEndPointByRegion( const region: String ): String; virtual; abstract;
|
||||
end;
|
||||
|
||||
{ TAWSConstHeader }
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ type
|
|||
_controller: TWFXConfigItemsController;
|
||||
_logoImageView: NSImageView;
|
||||
_nameTextField: NSTextField;
|
||||
_statusImageview: NSImageView;
|
||||
_saveButton: NSButton;
|
||||
_noteTextView: NSTextView;
|
||||
public
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type
|
|||
|
||||
TWFXOAuth2PropertyView = objcclass( TWFXPropertyView )
|
||||
protected
|
||||
_statusImageview: NSImageView;
|
||||
_connectButton: NSButton;
|
||||
private
|
||||
procedure connectOrDisconnect( sender: NSObject ); message 'TWFXOAuth2PropertyView_connectOrDisconnect:';
|
||||
|
|
|
|||
158
plugins/wfx/MacCloud/src/wfx/ui/uwfxoptionss3.pas
Normal file
158
plugins/wfx/MacCloud/src/wfx/ui/uwfxoptionss3.pas
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
unit uWFXOptionsS3;
|
||||
|
||||
{$mode ObjFPC}{$H+}
|
||||
{$modeswitch objectivec2}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
CocoaAll, uMiniCocoa,
|
||||
uCloudDriver, uAWSCore,
|
||||
uWFXPlugin, uWFXUtil, uWFXOptionsCore,
|
||||
uMiniUtil;
|
||||
|
||||
type
|
||||
|
||||
{ TWFXS3PropertyView }
|
||||
|
||||
TWFXS3PropertyView = objcclass( TWFXPropertyView )
|
||||
protected
|
||||
_regionTextField: NSTextField;
|
||||
_accessKeyIDTextField: NSTextField;
|
||||
_accessKeySecretTextField: NSTextField;
|
||||
_bucketTextField: NSTextField;
|
||||
private
|
||||
procedure saveConnection( sender: NSObject ); message 'TWFXS3PropertyView_saveConnection:';
|
||||
procedure initPropertyView; message 'TWFXS3PropertyView_initPropertyView';
|
||||
public
|
||||
procedure loadConnectionProperties( const index: Integer ); override;
|
||||
function initWithFrame(frameRect: NSRect): id; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
const
|
||||
CONST_AUTH_NOTES =
|
||||
'1. AccessKeyID and SerectAccessKey will be saved in the macOS KeyChains to obtain system-level security.'#13#13 +
|
||||
'2. The confidential information can only be read by your own macOS permissions.';
|
||||
|
||||
{ TWFXS3PropertyView }
|
||||
|
||||
procedure TWFXS3PropertyView.loadConnectionProperties( const index: Integer );
|
||||
var
|
||||
configItem: TWFXConnectionConfigItem;
|
||||
client: TAWSCloudDriver;
|
||||
data: TAWSConnectionData;
|
||||
accessKey: TAWSAccessKey;
|
||||
begin
|
||||
configItem:= _controller.currentConfigItem;
|
||||
if configItem = nil then
|
||||
Exit;
|
||||
client:= TAWSCloudDriver( configItem.driver );
|
||||
data:= client.getConnectionData;
|
||||
accessKey:= client.getAccessKey;
|
||||
_logoImageView.setImage( TWFXPluginUtil.driverMainIcon(configItem.driver) );
|
||||
_nameTextField.setStringValue( configItem.name );
|
||||
_regionTextField.setStringValue( StringToNSString(data.region) );
|
||||
_accessKeyIDTextField.setStringValue( StringToNSString(accessKey.id) );
|
||||
_accessKeySecretTextField.setStringValue( StringToNSString(accessKey.secret) );
|
||||
_bucketTextField.setStringValue( StringToNSString(data.defaultBucket) );
|
||||
end;
|
||||
|
||||
procedure TWFXS3PropertyView.saveConnection(sender: NSObject);
|
||||
var
|
||||
configItem: TWFXConnectionConfigItem;
|
||||
client: TAWSCloudDriver;
|
||||
data: TAWSConnectionData;
|
||||
accessKey: TAWSAccessKey;
|
||||
begin
|
||||
configItem:= _controller.currentConfigItem;
|
||||
if configItem = nil then
|
||||
Exit;
|
||||
|
||||
client:= TAWSCloudDriver( configItem.driver );
|
||||
|
||||
data.region:= _regionTextField.stringValue.UTF8String;
|
||||
data.endPoint:= client.getEndPointByRegion( data.region );
|
||||
data.defaultBucket:= _bucketTextField.stringValue.UTF8String;;
|
||||
client.setConnectionData( data );
|
||||
|
||||
accessKey:= TAWSAccessKey.Create(
|
||||
_accessKeyIDTextField.stringValue.UTF8String,
|
||||
_accessKeySecretTextField.stringValue.UTF8String );
|
||||
client.setAccessKey( accessKey );
|
||||
|
||||
_controller.saveConnection( _nameTextField.stringValue );
|
||||
end;
|
||||
|
||||
procedure TWFXS3PropertyView.initPropertyView;
|
||||
|
||||
procedure addLabel( const title: String; const rect: NSRect );
|
||||
var
|
||||
nsLabel: NSTextField;
|
||||
begin
|
||||
nsLabel:= NSTextField.alloc.initWithFrame( rect );
|
||||
nsLabel.setEditable( False );
|
||||
nsLabel.setDrawsBackground( False );
|
||||
nsLabel.setBordered( False );
|
||||
nsLabel.setStringValue( StringToNSString(title) );
|
||||
nsLabel.setAlignment( 2 );
|
||||
self.addSubview( nsLabel );
|
||||
nsLabel.release;
|
||||
end;
|
||||
|
||||
begin
|
||||
_logoImageView:= NSImageView.alloc.initWithFrame( NSMakeRect(200,530,32,32) );
|
||||
self.addSubview( _logoImageView );
|
||||
_logoImageView.release;
|
||||
|
||||
addLabel( 'Name:', NSMakeRect(20,480,120,20) );
|
||||
_nameTextField:= NSTextField.alloc.initWithFrame( NSMakeRect(146,480,250,22) );
|
||||
self.addSubview( _nameTextField );
|
||||
_nameTextField.release;
|
||||
|
||||
addLabel( 'Region:', NSMakeRect(20,440,120,20) );
|
||||
_regionTextField:= NSTextField.alloc.initWithFrame( NSMakeRect(146,440,250,22) );
|
||||
self.addSubview( _regionTextField );
|
||||
_regionTextField.release;
|
||||
|
||||
addLabel( 'Access Key ID:', NSMakeRect(20,400,120,20) );
|
||||
_accessKeyIDTextField:= NSTextField.alloc.initWithFrame( NSMakeRect(146,400,250,22) );
|
||||
self.addSubview( _accessKeyIDTextField );
|
||||
_accessKeyIDTextField.release;
|
||||
|
||||
addLabel( 'Serect Access Key:', NSMakeRect(20,360,120,20) );
|
||||
_accessKeySecretTextField:= NSTextField.alloc.initWithFrame( NSMakeRect(146,360,250,22) );
|
||||
self.addSubview( _accessKeySecretTextField );
|
||||
_accessKeySecretTextField.release;
|
||||
|
||||
addLabel( 'Bucket:', NSMakeRect(20,320,120,20) );
|
||||
_bucketTextField:= NSTextField.alloc.initWithFrame( NSMakeRect(146,320,250,22) );
|
||||
self.addSubview( _bucketTextField );
|
||||
_bucketTextField.release;
|
||||
|
||||
_saveButton:= NSButton.alloc.initWithFrame( NSMakeRect(200,260,100,22) );
|
||||
_saveButton.setBezelStyle( NSRoundedBezelStyle );
|
||||
_saveButton.setTitle( NSSTR('Save') );
|
||||
_saveButton.setTarget( self );
|
||||
_saveButton.setAction( ObjCSelector('TWFXS3PropertyView_saveConnection:') );
|
||||
self.addSubView( _saveButton );
|
||||
_saveButton.release;
|
||||
|
||||
_noteTextView:= NSTextView.alloc.initWithFrame( NSMakeRect(20,50,400,50) );
|
||||
_noteTextView.setFont( NSFont.systemFontOfSize(11));
|
||||
_noteTextView.setEditable( False );
|
||||
_noteTextView.setDrawsBackground( False );
|
||||
_noteTextView.setString( StringToNSString(CONST_AUTH_NOTES) );
|
||||
self.addSubView( _noteTextView );
|
||||
_noteTextView.release;
|
||||
end;
|
||||
|
||||
function TWFXS3PropertyView.initWithFrame(frameRect: NSRect): id;
|
||||
begin
|
||||
Result:= inherited;
|
||||
self.initPropertyView;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
|
@ -8,8 +8,9 @@ interface
|
|||
uses
|
||||
Classes, SysUtils, DateUtils,
|
||||
CocoaAll, uMiniCocoa,
|
||||
uCloudDriver, uWFXPlugin, uWFXUtil,
|
||||
uWFXOptionsCore, uWFXOptionsFrame,
|
||||
uCloudDriver, uOAuth2Client,
|
||||
uWFXPlugin, uWFXUtil,
|
||||
uWFXOptionsCore, uWFXOptionsOAuth2, uWFXOptionsS3,
|
||||
uMiniUtil;
|
||||
|
||||
type
|
||||
|
|
@ -297,6 +298,7 @@ procedure TWFXOptionsWindow.saveConnection( name: NSString );
|
|||
var
|
||||
configItem: TWFXConnectionConfigItem;
|
||||
currentIndex: Integer;
|
||||
nameIndex: Integer;
|
||||
|
||||
procedure alertDuplicateName;
|
||||
var
|
||||
|
|
@ -313,7 +315,11 @@ var
|
|||
begin
|
||||
if name.length = 0 then
|
||||
Exit;
|
||||
if self.configItems.indexOf(name) >= 0 then begin
|
||||
|
||||
currentIndex:= self.connectionListView.selectedRow;
|
||||
nameIndex:= self.configItems.indexOf( name );
|
||||
|
||||
if (nameIndex>=0) and (nameIndex<>currentIndex) then begin
|
||||
alertDuplicateName;
|
||||
Exit;
|
||||
end;
|
||||
|
|
@ -321,7 +327,6 @@ begin
|
|||
configItem:= self.currentConfigItem;
|
||||
configItem.setName( name );
|
||||
configItem.setModificationTime( LocalTimeToUniversal(now) );
|
||||
currentIndex:= self.connectionListView.selectedRow;
|
||||
self.connectionListView.reloadData;
|
||||
self.connectionListView.selectRow_byExtendingSelection( currentIndex, False );
|
||||
end;
|
||||
|
|
@ -338,11 +343,16 @@ end;
|
|||
|
||||
procedure TWFXOptionsWindow.onSelectedConnectionChanged( const selectedIndex: Integer );
|
||||
var
|
||||
configItem: TWFXConnectionConfigItem;
|
||||
newView: TWFXPropertyView;
|
||||
rightRect: NSRect;
|
||||
begin
|
||||
rightRect:= NSMakeRect(0,0,440,600);
|
||||
newView:= TWFXOAuth2PropertyView.alloc.initWithFrame( rightRect ) ;
|
||||
configItem:= self.currentConfigItem;
|
||||
if configItem.driver is TOAuth2SessionCloudDriver then
|
||||
newView:= TWFXOAuth2PropertyView.alloc.initWithFrame( rightRect )
|
||||
else
|
||||
newView:= TWFXS3PropertyView.alloc.initWithFrame( rightRect ) ;
|
||||
newView.setController( self );
|
||||
if Assigned(self.propertyView) then
|
||||
self.propertyView.removeFromSuperview;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue