iconForFile

  • Hi,
    I use [NSWorkspace sharedWorkspace] iconForFile:filePath] to get the 128x128
    icon of a file or a folder. It works well, but it is amazingly slow. It get
    the icon in about 1 second, much more that getting a thumbnail of a large
    jpg file by CGImageSourceCreateThumbnailAtIndex.
    Is a faster way, even an old carbon way, working on Tiger and Leopard?

    Best Regards
    --
    Lorenzo
    email: <archidea...>
  • On 16/11/2007, at 11:29 AM, Lorenzo wrote:

    > Hi,
    > I use [NSWorkspace sharedWorkspace] iconForFile:filePath] to get
    > the 128x128
    > icon of a file or a folder. It works well, but it is amazingly
    > slow. It get
    > the icon in about 1 second, much more that getting a thumbnail of a
    > large
    > jpg file by CGImageSourceCreateThumbnailAtIndex.
    > Is a faster way, even an old carbon way, working on Tiger and Leopard?
    >
    >
    > Best Regards
    > --
    > Lorenzo
    > email: <archidea...>

    Well, on my machine (G4 DP 1.25Ghz 1 Gig RAM)), it takes 0.002
    seconds to do it.  There is something else happening in your case I
    reckon.

    Here's my complete IBAction:

    - (IBAction)chooseFile:(id)sender
    {
    NSOpenPanel *panel;
    NSString *chosenFile;
    int result;
    NSString *title = @"Choose the file";
    NSString *okButtonTitle = @"Choose";
    panel = [NSOpenPanel openPanel];
    [panel setCanChooseDirectories:YES];
    [panel setCanChooseFiles:YES];
    [panel setAllowsMultipleSelection:NO];
    [panel setTitle:title];
    [panel setPrompt:okButtonTitle];
    result = [panel runModalForDirectory:nil file:nil types:nil];

    NSLog(@"time 1");

    if (result == NSOKButton) {
      chosenFile = [panel filename];
      NSImage *aImage = [[NSWorkspace sharedWorkspace]
    iconForFile:chosenFile];
      [myView setFileIcon:aImage];
      [myView setSize:NSMakeSize(128.0,128.0)];
      [myView setNeedsDisplay:YES];
      [slider setFloatValue:128.0];
      [currentSize setStringValue:@"128"];
    }

    NSLog(@"time 2");
    }

    2007-11-16 12:19:00.538 GetFileIcons[4121] time 1
    2007-11-16 12:19:00.540 GetFileIcons[4121] time 2

    Ron
  • I too use iconForFile and it's not slow at all.  In fact, my application
    does it for every file in a folder and even on folders of thousands, it's no
    where near the slowest part of the process.

    > From: Ron Fleckner <ronfleckner...>
    > Subject: Re: iconForFile
    >
    >
    >> I use [NSWorkspace sharedWorkspace] iconForFile:filePath] to get
    >> the 128x128
    >> icon of a file or a folder. It works well, but it is amazingly
    >> slow. It get
    >> the icon in about 1 second, much more that getting a thumbnail of a
    >> large
    >> jpg file by CGImageSourceCreateThumbnailAtIndex.
    >> Is a faster way, even an old carbon way, working on Tiger and Leopard?
  • On 16/11/2007, at 12:19 PM, Chris Williams wrote:

    > I too use iconForFile and it's not slow at all.  In fact, my
    > application
    > does it for every file in a folder and even on folders of thousands,
    > it's no
    > where near the slowest part of the process.

    I agree. I also use this and it's very quick. The only time it can be
    slow is when scanning a very large applications folder but even then
    the icons for the entire folder are returned in less than a second.

    Something else is going on here, have you done any profiling?

    --
    Rob Keniger
  • Did you try to display the icons of the folders in the Home folder?
    I mean, Music, Pictures, Documents, Public, Sites...
    Anyway iconForFile works slowly even with normal folders.
    I could display a pre-loaded folder icon, but in this case I cannot longer
    show the icons of the above special folders.

    Best Regards
    --
    Lorenzo
    email: <archidea...>

    > From: Ron Fleckner <ronfleckner...>
    > Date: Fri, 16 Nov 2007 12:23:44 +1100
    > To: Lorenzo <archidea...>
    > Cc: <cocoa-dev...>
    > Subject: Re: iconForFile
    >
    >
    > On 16/11/2007, at 11:29 AM, Lorenzo wrote:
    >
    >> Hi,
    >> I use [NSWorkspace sharedWorkspace] iconForFile:filePath] to get
    >> the 128x128
    >> icon of a file or a folder. It works well, but it is amazingly
    >> slow. It get
    >> the icon in about 1 second, much more that getting a thumbnail of a
    >> large
    >> jpg file by CGImageSourceCreateThumbnailAtIndex.
    >> Is a faster way, even an old carbon way, working on Tiger and Leopard?
    >>
    >>
    >> Best Regards
    >> --
    >> Lorenzo
    >> email: <archidea...>
    >
    > Well, on my machine (G4 DP 1.25Ghz 1 Gig RAM)), it takes 0.002
    > seconds to do it.  There is something else happening in your case I
    > reckon.
    >
    > Here's my complete IBAction:
    >
    > - (IBAction)chooseFile:(id)sender
    > {
    > NSOpenPanel *panel;
    > NSString *chosenFile;
    > int result;
    > NSString *title = @"Choose the file";
    > NSString *okButtonTitle = @"Choose";
    > panel = [NSOpenPanel openPanel];
    > [panel setCanChooseDirectories:YES];
    > [panel setCanChooseFiles:YES];
    > [panel setAllowsMultipleSelection:NO];
    > [panel setTitle:title];
    > [panel setPrompt:okButtonTitle];
    > result = [panel runModalForDirectory:nil file:nil types:nil];
    >
    > NSLog(@"time 1");
    >
    > if (result == NSOKButton) {
    > chosenFile = [panel filename];
    > NSImage *aImage = [[NSWorkspace sharedWorkspace]
    > iconForFile:chosenFile];
    > [myView setFileIcon:aImage];
    > [myView setSize:NSMakeSize(128.0,128.0)];
    > [myView setNeedsDisplay:YES];
    > [slider setFloatValue:128.0];
    > [currentSize setStringValue:@"128"];
    > }
    >
    > NSLog(@"time 2");
    > }
    >
    > 2007-11-16 12:19:00.538 GetFileIcons[4121] time 1
    > 2007-11-16 12:19:00.540 GetFileIcons[4121] time 2
    >
    > Ron
    >
  • On 11/16/07, Lorenzo <archidea...> wrote:
    > Did you try to display the icons of the folders in the Home folder?
    > I mean, Music, Pictures, Documents, Public, Sites...
    > Anyway iconForFile works slowly even with normal folders.
    > I could display a pre-loaded folder icon, but in this case I cannot longer
    > show the icons of the above special folders.

      Have you used the appropriate profiling tools to verify that this is
    indeed where the slowdown occurs? You have not addressed this crucial
    question. I just did a quick test myself and this:

    NSImage * img = [[NSWorkspace sharedWorkspace] iconForFile:pathToSomeFile];

      ... executes in a very small fraction of a second. If you're
    assuming that's where the slow-down is, test your assumptions using
    the proper tools. Evidence so far suggests this is not where your
    problem is.

    --
    I.S.
  • You were right. I found the bug. My mistake. Sorry.

    Best Regards
    --
    Lorenzo
    email: <archidea...>

    > From: "I. Savant" <idiotsavant2005...>
    > Date: Fri, 16 Nov 2007 09:53:43 -0500
    > To: Lorenzo <archidea...>
    > Cc: Ron Fleckner <ronfleckner...>, <cocoa-dev...>
    > Subject: Re: iconForFile
    >
    > On 11/16/07, Lorenzo <archidea...> wrote:
    >> Did you try to display the icons of the folders in the Home folder?
    >> I mean, Music, Pictures, Documents, Public, Sites...
    >> Anyway iconForFile works slowly even with normal folders.
    >> I could display a pre-loaded folder icon, but in this case I cannot longer
    >> show the icons of the above special folders.
    >
    > Have you used the appropriate profiling tools to verify that this is
    > indeed where the slowdown occurs? You have not addressed this crucial
    > question. I just did a quick test myself and this:
    >
    > NSImage * img = [[NSWorkspace sharedWorkspace] iconForFile:pathToSomeFile];
    >
    > ... executes in a very small fraction of a second. If you're
    > assuming that's where the slow-down is, test your assumptions using
    > the proper tools. Evidence so far suggests this is not where your
    > problem is.
    >
    > --
    > I.S.
  • Hi Lorenzo,

    it works on any file.  I tried it on the special Home folders as well
    to make sure.  A couple of other people have posted that
    NSWorkspace's -iconForFile works pretty fast for them, too.  I think
    that there must be some other issue involved in your case that you
    need to identify. Are you doing something else at the same time which
    might be hogging the CPU?  I'm no expert, but I would start looking
    at basic things first.  Something like, "Have you plugged in the
    power cord?  Is the unit on?" and those kind of questions.

    Ron

    On 17/11/2007, at 12:32 AM, Lorenzo wrote:

    > Did you try to display the icons of the folders in the Home folder?
    > I mean, Music, Pictures, Documents, Public, Sites...
    > Anyway iconForFile works slowly even with normal folders.
    > I could display a pre-loaded folder icon, but in this case I cannot
    > longer
    > show the icons of the above special folders.
    >
    > Best Regards
    > --
    > Lorenzo
    > email: <archidea...>
    >
    >> From: Ron Fleckner <ronfleckner...>
    >> Date: Fri, 16 Nov 2007 12:23:44 +1100
    >>
    >> On 16/11/2007, at 11:29 AM, Lorenzo wrote:
    >>
    >>> Hi,
    >>> I use [NSWorkspace sharedWorkspace] iconForFile:filePath] to get
    >>> the 128x128
    >>> icon of a file or a folder. It works well, but it is amazingly
    >>> slow. It get
    >>> the icon in about 1 second, much more that getting a thumbnail of a
    >>> large
    >>> jpg file by CGImageSourceCreateThumbnailAtIndex.
    >>> Is a faster way, even an old carbon way, working on Tiger and
    >>> Leopard?
    >>>
    >>>
    >>> Best Regards
    >>> --
    >>> Lorenzo
    >>> email: <archidea...>
    >>
    >> Well, on my machine (G4 DP 1.25Ghz 1 Gig RAM)), it takes 0.002
    >> seconds to do it.  There is something else happening in your case I
    >> reckon.
    >>
    >> Here's my complete IBAction:
    >>
    >> - (IBAction)chooseFile:(id)sender
    >> {
    >> NSOpenPanel *panel;
    >> NSString *chosenFile;
    >> int result;
    >> NSString *title = @"Choose the file";
    >> NSString *okButtonTitle = @"Choose";
    >> panel = [NSOpenPanel openPanel];
    >> [panel setCanChooseDirectories:YES];
    >> [panel setCanChooseFiles:YES];
    >> [panel setAllowsMultipleSelection:NO];
    >> [panel setTitle:title];
    >> [panel setPrompt:okButtonTitle];
    >> result = [panel runModalForDirectory:nil file:nil types:nil];
    >>
    >> NSLog(@"time 1");
    >>
    >> if (result == NSOKButton) {
    >> chosenFile = [panel filename];
    >> NSImage *aImage = [[NSWorkspace sharedWorkspace]
    >> iconForFile:chosenFile];
    >> [myView setFileIcon:aImage];
    >> [myView setSize:NSMakeSize(128.0,128.0)];
    >> [myView setNeedsDisplay:YES];
    >> [slider setFloatValue:128.0];
    >> [currentSize setStringValue:@"128"];
    >> }
    >>
    >> NSLog(@"time 2");
    >> }
    >>
    >> 2007-11-16 12:19:00.538 GetFileIcons[4121] time 1
    >> 2007-11-16 12:19:00.540 GetFileIcons[4121] time 2
    >>
    >> Ron
    >>
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today