tags:

views:

227

answers:

2

Firefox doesn't currently bounce the Downloads box in the dock when a download is finished, like Safari, Chrome and Camino do.

If Firefox was written in Objective C, you could very easily add the one line of Objective C code required to do this. However, it's not. Is there a way to call this Cocoa function from C++ so that it can be added to Firefox for the benefit of all Mac users?

+3  A: 

What I'd recommend, and I had to do this for a project I was working on, you could have a few files of obj-c++ that provide both a C/C++ api and internally use obj-c code to trigger the doc flashing.

Essentially you create a standard C/C++ header file. In the code side you make the file a .m or .mm file.

This would then let you write the obj-c one liner in questions directly into a C/C++ function, and since the header file is in plain C/C++ it won't be a compiler error for the non .mm files in the project.

This of course assumes that compiling with a compiler (like GCC) that speaks both languages.

A simple and (tested) example of this approach would be:

TriggerBounce.h

void TriggerBounce(char * filepath);

TriggerBounce.m

#import <Cocoa/Cocoa.h>

void TriggerBounce(char * filepath) {
    NSString *pathToFile = [NSString stringWithCString:filepath encoding:NSUTF8StringEncoding];
    [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.DownloadFileFinished" object:pathToFile]; 
}
Bryan McLemore
+3  A: 

You can use the Carbon API's CFNotificationCenterPostNotification. Carbon is pure C.

Documentation and code samples here.

diciu
I thought Carbon was going the way of the Dodo. In fact, using Carbon locks you out of 64 bit. I notice that you mention CFNotificationCenterPostNotification, though, which looks like a Core Foundation class. That might be OK.
Daniel Yankowsky
Yes, it's not Carbon. Core Foundation, Core Services, and a few other frameworks that *can be* accessed through the Carbon framework are available in 64-bit. In fact, even some parts of Carbon (e.g., Carbon Event Manager) are available in 64-bit.
Peter Hosey