1 /* 2 * Copyright 2003-2008, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2015 Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 * 6 * Authors: 7 * Axel Dörfler, axeld@pinc-software.de 8 * John Scipione, jscipione@gmail.com 9 */ 10 11 12 //! Open Target Folder - opens the folder of the link target in Tracker 13 14 15 #include <stdio.h> 16 #include <string.h> 17 18 #include <Alert.h> 19 #include <Entry.h> 20 #include <Messenger.h> 21 #include <Path.h> 22 #include <SymLink.h> 23 24 #include <tracker_private.h> 25 26 27 using namespace BPrivate; 28 29 extern "C" void 30 process_refs(entry_ref directoryRef, BMessage* message, void*) 31 { 32 entry_ref ref; 33 uint32 selectCount = 0; 34 35 // create Tracker messenger... 36 BMessenger messenger(kTrackerSignature); 37 38 // create select message... 39 BMessage selectMessage(kSelect); 40 41 for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { 42 BSymLink link(&ref); 43 if (link.InitCheck() != B_OK || !link.IsSymLink()) { 44 BAlert* alert = new BAlert("Open Target Folder", 45 "This add-on can only be used on symbolic links.\n" 46 "It opens the folder of the link target in Tracker.", 47 "OK"); 48 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 49 alert->Go(NULL); 50 break; 51 } 52 53 BEntry targetEntry(&ref, true); 54 if (targetEntry.InitCheck() != B_OK) { 55 BAlert* alert = new BAlert("Open Target Folder", 56 "Cannot open target entry. Maybe this link is broken?", 57 "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); 58 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 59 alert->Go(NULL); 60 break; 61 } 62 63 BEntry parentEntry; 64 if (targetEntry.GetParent(&parentEntry) != B_OK) { 65 BAlert* alert = new BAlert("Open Target Folder", 66 "Cannot open target entry folder. Maybe this link is broken?", 67 "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); 68 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 69 alert->Go(NULL); 70 break; 71 } 72 73 entry_ref parent; 74 if (parentEntry.GetRef(&parent) != B_OK) { 75 BAlert* alert = new BAlert("Open Target Folder", 76 "Unable to locate entry_ref for the target entry folder.", 77 "OK"); 78 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); 79 alert->Go(NULL); 80 break; 81 } 82 83 // create Tracker message... 84 BMessage trackerMessage(B_REFS_RECEIVED); 85 trackerMessage.AddRef("refs", &parent); 86 87 // ...and send it 88 messenger.SendMessage(&trackerMessage); 89 90 entry_ref target; 91 if (targetEntry.GetRef(&target) != B_OK) { 92 // don't alert, selection is not critical 93 break; 94 } 95 96 // add ref to selection message 97 selectMessage.AddRef("refs", &target); 98 selectCount++; 99 } 100 101 // ...and send it 102 if (selectCount > 0) 103 messenger.SendMessage(&selectMessage); 104 } 105 106 107 int 108 main(int /*argc*/, char** /*argv*/) 109 { 110 fprintf(stderr, "This can only be used as a Tracker add-on.\n"); 111 return -1; 112 } 113