• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: FSCopyAsync Example + Updating UI
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FSCopyAsync Example + Updating UI


  • Subject: Re: FSCopyAsync Example + Updating UI
  • From: Mike Abdullah <email@hidden>
  • Date: Tue, 24 Oct 2006 11:02:16 +0100

Well the callback function will tell you when you are done. Rather than using a pointer to your progress indicator, I would use a pointer to some controller object.

It's then up to that controller object to intelligently update the progress indicator, or simply "know" that the copy is done. Two possible approaches I think could be:

1.
Create your own NSFileManager style class. This is in charge of setting up the async file operations, and can then create its own callback methods to alert other parts of your app as to what is going on.


2.
Create a class that acts as a "wrapper" sort of thing around a file. You then ask the file to copy itself, which it internally does using the Async functions. Again, use callback methods to let other objects in your app know what is going on.


Mike.

On 24 Oct 2006, at 04:36, Mark Manes wrote:

Mike,

First off--thank you for taking the time to write back. I realized earlier today that I could pass the pointer of the ProgressIndicator along to the callback... and that it would work. I am about to try that. Now that I have your email I am sure I will be successful. I still think I am interested in having a way to know when the async function is done--or a way of sending a message to the main app so that I can send another file to be copied when the first file is complete. The project I am working on needs to send multiple files from various places on the system. So I need to know when the copy is complete before sending another.

Any ideas on that?

Many thanks for your email!

-mark=



On Oct 23, 2006, at 5:53 AM, Mike Abdullah wrote:

OK, it's actually fairly simple to do this in reality Mark. I've got part of my app up and running doing what you want, mainly due to various other bits of help from people on this list.

OK, so first you need a callback function, something like:

static void MAFileOperationAsyncCallback(FSFileOperationRef fileOp,
										 const FSRef *currentItem,
										 FSFileOperationStage stage,
										 OSStatus error,
										 CFDictionaryRef statusDictionary,
										 void *info)

To start the copy, use the FSCopyObjectAsync function. You need to feed it information about the source and destination FSRefs. Also, specify your callback function and a callback interval - I find 0.5 works pretty well. Most importantly though, you need to supply with that function a pointer to an object uniquely identifying that particular operation.

Then, use something like this to actually schedule your callback function:

FSFileOperationScheduleWithRunLoop(fileOpeRef,
								      [[NSRunLoop currentRunLoop] getCFRunLoop],
								      (CFStringRef)NSDefaultRunLoopMode);

After that you should be all set. In your callback function, use the *info pointer to find the object identifying that particular copy operation and call whatever methods you like in order to update a progress bar.

The best thing of all is that you don't even have to run this in a separate thread!

Mike.

On 23 Oct 2006, at 00:02, Mark Manes wrote:

Greetings,

I am looking for an example of how to properly implement FSCopyAsync that allows me to update the status of the UI during the callback. Clearly I can't call a method within the callback as I don't have the objects necessary. I see people discuss the use of NSRunLoop -- but I don't quite get it.

I'd love a working example that copied files and updated the progress using NSProgressIndicator.

Seems like a pretty common thing that people might want to do--I am sure it would benefit many of someone would take the time to show a good example.

PS: I did see the Apple documetnation on FSCopyAsync and in fact I have the code working that copies the files properly. I just want to tell my user what is going on. :)

Many thanks in advance!

-mark=

Mark D. Manes


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >FSCopyAsync Example + Updating UI (From: Mark Manes <email@hidden>)
 >Re: FSCopyAsync Example + Updating UI (From: Mike Abdullah <email@hidden>)

  • Prev by Date: NSSplitView iTunes Like
  • Next by Date: Re: NSTableView with NSArray and C-array question
  • Previous by thread: Re: FSCopyAsync Example + Updating UI
  • Next by thread: Re: FSCopyAsync Example + Updating UI
  • Index(es):
    • Date
    • Thread