Recent

Author Topic: Folders unit for Linux, OS X and windows  (Read 49255 times)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #30 on: October 12, 2010, 09:43:50 am »
Ok, good that you are back and hopefully the cooperation from now on will be always positive =)

But I have not found a single example or source reference to getting a users "pictures" folder on Ubunu or OS X in Lazarus?
If it already exists then that would be helpful to know :)

It doesn't exist yet.

Quote
I can provide functions that calls the API directly for:
-Windows
-OS X
-Gnome
Im working on KDE at the moment

Indeed, it would be excelent. Could you change from various routines to one single routine with a enumeration as parameter? And then provide a link to the source code for a new review.

Even better if you could develop directly in the desired end format.

I have prepared a place for this. I think it can be added in the unit lcl/lclintf.pas together with other system environment functions.
The implementations go into include files such as lcl/include/sysenvapis_mac.inc

qdos

  • Full Member
  • ***
  • Posts: 112
Re: Folders unit for Linux, OS X and windows
« Reply #31 on: October 12, 2010, 12:56:52 pm »
I can create simple routines that isolate each platform, then you can decide what to use.
Enumerating on Gnome for instance is very easy:

(* the function we are looking for *)
Function g_get_user_special_dir(directory:Integer):PChar;cdecl;external;

Const
CNT_DESKTOP   = 0;
CNT_DOCUMENTS = 1;
CNT_DOWNLOADS = 2;
CNT_MUSIC     = 3;
CNT_PICTURES  = 4;
CNT_PUBLIC    = 5;
CNT_TEMPLATES = 6;
CNT_VIDEOS    = 7;

procedure TForm1.Button1Click(Sender: TObject);
var
   FData: PChar;
   x: Integer;
begin
     for x:=CNT_DESKTOP to CNT_VIDEOS do
     Begin
          FData:=g_get_user_special_dir(x);
          if FData<>NIl then
          listbox1.items.add(strPas(FData));
     end;
end;


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #32 on: October 12, 2010, 01:05:47 pm »
Our function should have this interface:

type
  TUserSpecialDir= (usdDesktop, usdDocuments, usdDownloads, usdMusic, usdPictures, usdVideos);

function GetUserSpecialDir(ADirectory: TUserSpecialDir): string;

GNOME docs say nothing useful about what the "templates" and "shared" directories should be exactly, so they may be ignored. Their existence in all platforms is also doubtful.

PS: The function should return "" if the directory does not apply to the platform. usdDesktop for example doesn't apply to smartphones.

But the function should do a best effort result if a similar dir can be used. For example, let's say that there is no Downloads dir. One can then just return the same as the usdDocuments dir.
« Last Edit: October 12, 2010, 01:23:48 pm by felipemdc »

qdos

  • Full Member
  • ***
  • Posts: 112
Re: Folders unit for Linux, OS X and windows
« Reply #33 on: October 12, 2010, 01:23:05 pm »
GNOME docs say nothing useful about what the "templates" and "shared" directories should be exactly, so they may be ignored.

The "shared" should perhaps be included, I noticed that AMule used it for shared files. It may be similar to shared documents on the mac. I havent checked out the Win7 headers yet - but i suspect we will find something similar there. But we can deal with the details later.

Right now I have to finish the unit, which includes easy disk enumeration. Which is equally important. I also want to see if i can figure out mapping drives on the mac through code (not visible to user). I do this a lot in win32 services that needs to push files through the network.
This will make working with disks and paths across platforms a breeze, right down to sectors and block info (which i know is included in Lazarus, although with one API call missing). When that is done I can isolate the functions and give you a heads up.
« Last Edit: October 12, 2010, 01:26:36 pm by qdos »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #34 on: October 12, 2010, 01:25:58 pm »
Right now I have to finish the unit, which includes easy disk enumeration. Which is equally important. I also want to see if i can figure out mapping drives on the mac through code (not visible to user). I do this a lot in win32 services that needs to push files through the network.
This will make working with disks and paths across platforms a breeze, right down to sectors and block info (which i know is included in Lazarus, although with one API call missing). When that is done I can isolate the functions and give you a heads up.

Could you be more specific about which APIs are present in Lazarus which deal with disk enumeration, disk sectors and blocks? If there is something, it's probably in FPC.

qdos

  • Full Member
  • ***
  • Posts: 112
Re: Folders unit for Linux, OS X and windows
« Reply #35 on: October 12, 2010, 01:31:45 pm »
You use StatFS() on unix to get some basic info about discs, such as blocks used, capacity and total. You use this to calculate diskfree and disksize. On windows however the standard pascal functions for this return different information (sector etc.). So to make the information identical across linux, win32 and unix, I calculate the block values on win32. Since each class implements a different platform, you can typecast the disk-info class to it's native (e.g TJLCustomDiskInfo to TJLWinDiskInfo) and get access to the normal values as well. This preserves both standard values and system spesific values.
I use a unix api call that is not wrapped yet by lazarus.

Have 2 pick up kids now..

DimProfi

  • Full Member
  • ***
  • Posts: 126
    • http://www.dimprofi.de
Re: Folders unit for Linux, OS X and windows
« Reply #36 on: October 12, 2010, 01:40:26 pm »
@qdos & marcov
I love Happy Endings or hopefully Happy Continuations :)
Lazarus 1.2/FPC 2.6.4 (x86/x86_64/win32/win64/Linux) :: Be smart - use predictable {$INTERFACES CORBA}! :)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #37 on: October 12, 2010, 02:02:42 pm »
On windows however the standard pascal functions for this return different information (sector etc.).

Which pascal functions exactly?

Quote
I use a unix api call that is not wrapped yet by lazarus.

Which API?

qdos

  • Full Member
  • ***
  • Posts: 112
Re: Folders unit for Linux, OS X and windows
« Reply #38 on: October 12, 2010, 03:43:03 pm »
Standard pascal functions:
  • DiskFree()
  • DiskSize()

On OSX these are implemented using calls to statsFS(). You use this to sum up disk free/Size:
  var
    fs : tstatfs;
  Begin
    (..)
    result:=int64(fs.bavail)*int64(fs.bsize);
  end;


On windows they use the api function:

function GetDiskFreeSpace(drive:pchar;var sector_cluster,bytes_sector,
                          freeclusters,totalclusters:longint):longbool;
         stdcall;external 'kernel32' name 'GetDiskFreeSpaceA';

On unix, there is a note somewhere in the code that getfsstat() should also be implemented, which is the one i use.


But like i said. Details later.
I like to get the big picture done before i go into details.
« Last Edit: October 12, 2010, 03:47:53 pm by qdos »

qdos

  • Full Member
  • ***
  • Posts: 112
Re: Folders unit for Linux, OS X and windows
« Reply #39 on: October 12, 2010, 05:04:19 pm »
Hm. QT might be worse than i thought. The function we need is in QDesktopServices::StorageLocation()
I have no idea if Lazarus wraps this object.

Does anyone have/use QT here?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #40 on: October 12, 2010, 07:27:39 pm »
The Nokia docs says that it is a standard function from QtGUI:

http://doc.qt.nokia.com/4.5/qdesktopservices.html

Which is very good. But I couldn't find it in our Qt bindings. I'll ask Den Jean to add this class to the wrappers ...

qdos

  • Full Member
  • ***
  • Posts: 112
Re: Folders unit for Linux, OS X and windows
« Reply #41 on: October 13, 2010, 03:52:45 am »
The Nokia docs says that it is a standard function from QtGUI:

http://doc.qt.nokia.com/4.5/qdesktopservices.html

Which is very good. But I couldn't find it in our Qt bindings. I'll ask Den Jean to add this class to the wrappers ...

My point exactly :)
Could you get him to mail me the code? Or if he pushes it to SVN - the latest builld for win32/mac/gtk linux? Or can i download it from somewhere?
For some reason i cannt download from svn. I got a new router and for some reason i cant get it to work properly. I also installed Windows 7, it may be a block there.

Anyway - my mail is: (moved to profile). I should be able to wrap this up over the weekend.

And for those interested, here is a part of the class roadmap I'm working on:

- TLazServices
  + TLazCodec
      + TLazRLECodec
      + TLazZLIBCodec
  + TLazEncryption
      + TLazEncryptionRC4
      + TLazEncryptionSHA
      + TLazEncryptionGhost
  + TLazCompression
      + TLazCompressionRLE
      + TLazCompressionZLIB
  + TLazLocation
      + TLazLocationLocal
         + TLazLocationLocalDisk
            + TLazLocationLocalDiskWin
            + TLazLocationLocalUnix
                + TLazLocationLocalDarwin
            + TLazLocationLocalLinux
      + TLazLocationRemote
         + TLazLocationRemoteFTP
         + TLazLocationRemoteHTTP
             + TLazLocationRemoteREST
             + TLazLocationRemoteSVN
             + TLazLocationRemoteRO (Remobjects)
  + TLazShell
      + TLazShellDrives
      + TLazShellPaths
      + TLazShellMimeTypes (icon extraction and filetypes)
  + TLazGraphics
      + TLazGraphicsCodec [derives from TLazCodec]
         + TLazGraphicsCodec888
         + TLazGraphicsCodec545
         + TLazGraphicsCodec555
         + TLazGraphicsCodec87a
         + TLazGraphicsCodec89a
      + TLazGraphicsSurface
         + TLazGraphicsSurfaceRaw
         + TLazGraphicsSurfaceWin
         + TLazGraphicsSurfaceCarbon
         + TLazGraphicsSurfaceGTK
         + TLazGraphicsSurfaceKDE
      + TLazGraphicsColorSpace
         + TLazGraphicsColorSpaceRGB
         + TLazGraphicsColorSpaceHSV
         + TLazGraphicsColorSpaceIndexed
      + TLazGraphicsColor

"Shellcore" is from TLazLocation -> TLazShell (including subnodes). Actually LazLocation should probably be placed under Shell, since it deals with resource location and translation between systems. I coded such a system earlier. Where you could create an "adapter" class for say, an FTP folder -- then you could create an "adapter" for a remote share (not visible or initated by the user. We do it all by calling the API and providing correct credentials). And to copy a file from A to B you just wrote:

AdapterB.CopyFile(AdapterA.GetFileRef('\\somehost\somedir\somefile','admin','mypass'));

As long as there is an adapter for a storage target and source, you can copy, read and do whatever you like between them. You can even open a HTTP website as a read only source as long as you know a filename. This code earned me a lot of money and I have seen nothing like it anywhere to date.

:)
« Last Edit: October 13, 2010, 03:14:33 pm by qdos »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #42 on: October 13, 2010, 09:40:04 am »
Could you get him to mail me the code? Or if he pushes it to SVN - the latest builld for win32/mac/gtk linux? Or can i download it from somewhere?

Sure, I'll warn you when a new Qt4Pascal release is done with this class, but this depends on Den Jean schedule, so there is no guarantee that it will be ready before the weekend. He is usually quick, but no guarantees.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Folders unit for Linux, OS X and windows
« Reply #43 on: October 24, 2010, 02:38:24 pm »
Ok, Den Jean has made a new release of the Qt bindings with the required classes, but Lazarus won't use this new binding version before 0.9.30 is released, so in the mean time please attach a diff with your current code for Windows, Carbon and Gtk2. For Qt just put an empty implementation or commented code.

Please follow my previous recommendations and the previously mentioned place reserved for this code.

thanks,

 

TinyPortal © 2005-2018