2 * Copyright 2009 Jonas Sundström, jonas@kirilla.com
3 * Copyright 1998-2007 Matthijs Hollemans
4 * All rights reserved. Distributed under the terms of the MIT License.
6 #ifndef _TRACKER_ADDON_APP_LAUNCH_H
7 #define _TRACKER_ADDON_APP_LAUNCH_H
13 #include <TrackerAddOn.h>
17 process_refs(entry_ref directory
, BMessage
* refs
, void* reserved
)
19 // When this header file is included by an application it becomes
20 // ready to be used as a Tracker add-on. This function will launch
21 // the application with the entry_refs given by Tracker to the addon.
23 // The "directory" entry_ref holds the entry_ref of the folder from where
24 // the addon was launched. If launched from a query it's probably invalid.
25 // The "refs" BMessage is a standard B_REFS_RECEIVED message whose
26 // "refs" array contains the entry_refs of the selected files.
27 // The last argument, "reserved", is currently unused.
29 refs
->AddRef("dir_ref", &directory
);
30 // The folder's entry_ref might be useful to some applications.
31 // We include it by a different name than the other entry_refs.
32 // It could be useful to know if an application got its refs as a
33 // Tracker addon. A B_REFS_RECEIVED message with a "dir_ref"
34 // provides such a hint.
36 // get the path of the Tracker add-on
39 status_t status
= get_next_image_info(0, &cookie
, &image
);
41 while (status
== B_OK
) {
42 if (((char*)process_refs
>= (char*)image
.text
43 && (char*)process_refs
<= (char*)image
.text
+ image
.text_size
)
44 || ((char*)process_refs
>= (char*)image
.data
45 && (char*)process_refs
<= (char*)image
.data
+ image
.data_size
))
48 status
= get_next_image_info(0, &cookie
, &image
);
52 if (get_ref_for_path(image
.name
, &addonRef
) != B_OK
)
55 status
= be_roster
->Launch(&addonRef
, refs
);
56 if (status
== B_OK
|| status
== B_ALREADY_RUNNING
)
59 // If launching by entry_ref fails it's probably futile to
60 // launch by signature this way, but we can try anyway.
63 if (be_roster
->GetAppInfo(&addonRef
, &appInfo
) != B_OK
)
66 be_roster
->Launch(appInfo
.signature
, refs
);
70 #endif // _TRACKER_ADDON_APP_LAUNCH_H