Re: FSCopyAsync Example + Updating UI
Re: FSCopyAsync Example + Updating UI
- Subject: Re: FSCopyAsync Example + Updating UI
- From: Mike Abdullah <email@hidden>
- Date: Thu, 26 Oct 2006 09:43:02 +0100
Mark there is no need to use any global variables or a timer. As
long as you have a pointer to the controller object, you can send
methods to it from within the callback. Trust me, it works fine.
Mike.
On 26 Oct 2006, at 03:25, Mark Manes wrote:
I ended up doing a cheesball thing probably.. I used .. *cough*
global variables and a NSTimer that reviews the status. I'd be
inclined to pass an object that represents a Controller ... the
question is-- can I send methods from within the callback to the
Controller?
Hmmmm..
Mike.. I appreciate your help.. I truly do. :)
-mark=
On Oct 24, 2006, at 3:02 AM, Mike Abdullah wrote:
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