mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: iCloudDriverUtil.createAllApps()
This commit is contained in:
parent
9fbaf75cb3
commit
aa392b45fc
2 changed files with 78 additions and 7 deletions
|
|
@ -6,13 +6,27 @@ unit uiCloudDriverUtil;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
Classes, SysUtils, fgl, Graphics,
|
||||
CocoaAll, CocoaUtils,
|
||||
uDCUtils,
|
||||
uDCUtils, uMyDarwin,
|
||||
uiCloudDriverConfig;
|
||||
|
||||
type
|
||||
|
||||
|
||||
{ TiCloudApp }
|
||||
|
||||
TiCloudApp = class
|
||||
public
|
||||
appName: String;
|
||||
displayName: String;
|
||||
contentCount: Integer;
|
||||
icon: NSImage;
|
||||
public
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
TiCloudApps = specialize TFPGObjectList<TiCloudApp>;
|
||||
|
||||
{ iCloudDriverUtil }
|
||||
|
||||
iCloudDriverUtil = class
|
||||
|
|
@ -20,10 +34,18 @@ type
|
|||
class function getPlistAppIconNames( const path: String ): NSArray;
|
||||
public
|
||||
class function createAppImage(const appName: String): NSImage;
|
||||
class function createAllApps: TiCloudApps;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TiCloudApp }
|
||||
|
||||
destructor TiCloudApp.Destroy;
|
||||
begin
|
||||
icon.release;
|
||||
end;
|
||||
|
||||
{ iCloudDriverUtil }
|
||||
|
||||
class function iCloudDriverUtil.getPlistAppIconNames(const path: String ): NSArray;
|
||||
|
|
@ -76,5 +98,55 @@ begin
|
|||
Result:= appImage;
|
||||
end;
|
||||
|
||||
class function iCloudDriverUtil.createAllApps: TiCloudApps;
|
||||
var
|
||||
manager: NSFileManager;
|
||||
filesInBasePath: NSArray;
|
||||
appName: NSString;
|
||||
appPath: NSString;
|
||||
appBasePath: NSString;
|
||||
app: TiCloudApp;
|
||||
|
||||
function pass( appName: NSString ): Boolean;
|
||||
var
|
||||
driverName: NSString;
|
||||
begin
|
||||
Result:= True;
|
||||
if appName.hasPrefix( NSSTR('.') ) then
|
||||
Exit;
|
||||
driverName:= NSSTR(iCloudDriverConfig.path.driver);
|
||||
driverName:= driverName.lastPathComponent;
|
||||
if appName.isEqualToString(driverName) then
|
||||
Exit;
|
||||
Result:= False;
|
||||
end;
|
||||
|
||||
function contentCountOfApp( appPath: NSString ): Integer;
|
||||
var
|
||||
filesOfApp: NSArray;
|
||||
begin
|
||||
appPath:= appPath.stringByAppendingString( NSSTR('/Documents') );
|
||||
filesOfApp:= manager.contentsOfDirectoryAtPath_error( appPath, nil );
|
||||
Result:= filesOfApp.count;
|
||||
end;
|
||||
|
||||
begin
|
||||
Result:= TiCloudApps.Create;
|
||||
appBasePath:= NSSTR( IncludeTrailingPathDelimiter(uDCUtils.ReplaceTilde(iCloudDriverConfig.path.base)) );
|
||||
manager:= NSFileManager.defaultManager;
|
||||
filesInBasePath:= manager.contentsOfDirectoryAtPath_error( appBasePath, nil );
|
||||
for appName in filesInBasePath do begin
|
||||
if pass(appName) then
|
||||
continue;
|
||||
appPath:= appBasePath.stringByAppendingString( appName );
|
||||
app:= TiCloudApp.Create;
|
||||
app.appName:= appName.UTF8String;
|
||||
app.displayName:= getMacOSDisplayNameFromPath( appPath.UTF8String );
|
||||
app.contentCount:= contentCountOfApp( appPath );
|
||||
app.icon:= createAppImage( app.appName );
|
||||
Result.Add( app );
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ uses
|
|||
{$ELSEIF DEFINED(UNIX)}
|
||||
, DCFileAttributes
|
||||
{$IF DEFINED(DARWIN)}
|
||||
, CocoaUtils, uDarwinUtil
|
||||
, CocoaAll, MacOSAll, CocoaUtils, uDarwinUtil, uClassesEx
|
||||
{$ELSEIF NOT DEFINED(HAIKU)}
|
||||
, Math, Contnrs, uGio, uXdg
|
||||
{$IFDEF GTK2_FIX}
|
||||
|
|
@ -372,6 +372,8 @@ function AdjustIconSize(ASize: Integer; APixelsPerInch: Integer): Integer;
|
|||
function StretchBitmap(var bmBitmap : Graphics.TBitmap; iIconSize : Integer;
|
||||
clBackColor : TColor; bFreeAtEnd : Boolean = False) : Graphics.TBitmap;
|
||||
|
||||
function NSImageToTBitmap( const image:NSImage ): TBitmap;
|
||||
function getBestNSImageWithSize( const srcImage:NSImage; const size:Integer ): NSImage;
|
||||
|
||||
implementation
|
||||
|
||||
|
|
@ -389,9 +391,6 @@ uses
|
|||
{$ELSE}
|
||||
, StrUtils, Types, DCBasicTypes
|
||||
{$ENDIF}
|
||||
{$IFDEF DARWIN}
|
||||
, CocoaAll, MacOSAll, uClassesEx
|
||||
{$ENDIF}
|
||||
{$IFDEF RabbitVCS}
|
||||
, uRabbitVCS
|
||||
{$ENDIF}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue