1 /* 2 * Copyright 2003-2008, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 //! Open Target Folder - opens the folder of the link target in Tracker 7 8 #include <stdio.h> 9 #include <string.h> 10 11 #include <Alert.h> 12 #include <Directory.h> 13 #include <Entry.h> 14 #include <Messenger.h> 15 #include <Path.h> 16 #include <SymLink.h> 17 18 19 extern "C" void 20 process_refs(entry_ref directoryRef, BMessage *msg, void *) 21 { 22 BDirectory directory(&directoryRef); 23 if (directory.InitCheck() != B_OK) 24 return; 25 26 int32 errors = 0; 27 entry_ref ref; 28 int32 index; 29 for (index = 0; msg->FindRef("refs", index, &ref) == B_OK; index ++) { 30 BSymLink link(&ref); 31 if (link.InitCheck() != B_OK || !link.IsSymLink()) { 32 errors++; 33 continue; 34 } 35 36 BEntry targetEntry; 37 BPath path; 38 if (link.MakeLinkedPath(&directory, &path) < B_OK 39 || targetEntry.SetTo(path.Path()) != B_OK 40 || targetEntry.GetParent(&targetEntry) != B_OK) { 41 (new BAlert("Open Target Folder", 42 "Cannot open target folder. Maybe this link is broken?", 43 "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL); 44 continue; 45 } 46 47 // create Tracker message... 48 entry_ref target; 49 targetEntry.GetRef(&target); 50 51 BMessage message(B_REFS_RECEIVED); 52 message.AddRef("refs", &target); 53 54 // ...and send it 55 BMessenger messenger("application/x-vnd.Be-TRAK"); 56 messenger.SendMessage(&message); 57 58 // TODO: select entry via scripting? 59 } 60 61 if (errors) { 62 (new BAlert("Open Target Folder", 63 "This add-on can only be used on symbolic links.\n" 64 "It opens the folder of the link target in Tracker.", 65 "Ok"))->Go(NULL); 66 } 67 } 68 69 70 int 71 main(int /*argc*/, char **/*argv*/) 72 { 73 fprintf(stderr, "This can only be used as a Tracker add-on.\n"); 74 return -1; 75 } 76