1 /* 2 * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <Alert.h> 8 #include <Messenger.h> 9 #include <Roster.h> 10 #include <View.h> 11 12 #include "PoseView.h" 13 14 static void Error(BView *view, status_t status, bool unlock=false) 15 { 16 BAlert *alert; 17 if (view && unlock) 18 view->UnlockLooper(); 19 BString s(strerror(status)); 20 alert = new BAlert("Error", s.String(), "OK"); 21 alert->Go(); 22 } 23 24 /*! 25 \brief Tracker add-on entry 26 */ 27 extern "C" void 28 process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/) 29 { 30 status_t status; 31 BAlert *alert; 32 BMessenger msgr; 33 BPoseView *view = NULL; 34 BMessage poseViewBackup; 35 BMessage poseViewColumnBackup; 36 uint32 poseViewModeBackup; 37 BString windowTitleBackup; 38 39 refs->PrintToStream(); 40 41 status = refs->FindMessenger("TrackerViewToken", &msgr); 42 if (status < B_OK) { 43 Error(view, status); 44 return; 45 } 46 47 status = B_ERROR; 48 if (!msgr.LockTarget()) { 49 Error(view, status); 50 return; 51 } 52 53 status = B_BAD_HANDLER; 54 view = dynamic_cast<BPoseView *>(msgr.Target(NULL)); 55 if (!view) { 56 Error(view, status); 57 return; 58 } 59 if (dynamic_cast<BWindow *>(view->Looper()) == NULL) { 60 Error(view, status, true); 61 return; 62 } 63 64 windowTitleBackup = view->Window()->Title(); 65 66 view->SaveColumnState(poseViewColumnBackup); 67 view->SaveState(poseViewBackup); 68 view->SetDragEnabled(false); 69 view->SetSelectionRectEnabled(false); 70 view->SetPoseEditing(false); 71 poseViewModeBackup = view->ViewMode(); 72 73 74 view->SetViewMode(kIconMode); 75 76 view->ShowBarberPole(); 77 78 79 view->UnlockLooper(); 80 81 82 83 alert = new BAlert("Error", "IconVader:\nClick on the icons to get points.\nAvoid symlinks!", "OK"); 84 alert->Go(); 85 86 87 int32 score = 0; 88 int32 count = 300; 89 while (count--) { 90 status = B_ERROR; 91 if (!msgr.LockTarget()) { 92 Error(view, status); 93 return; 94 } 95 96 BPose *pose; 97 for (int32 i = 0; (pose = view->PoseAtIndex(i)); i++) { 98 if (pose->IsSelected()) { 99 if (pose->TargetModel()->IsFile()) 100 score++; 101 if (pose->TargetModel()->IsDirectory()) 102 score+=2; 103 if (pose->TargetModel()->IsSymLink()) 104 score-=10; 105 pose->Select(false); 106 } 107 #ifdef __HAIKU__ 108 BPoint location = pose->Location(view); 109 #else 110 BPoint location = pose->Location(); 111 #endif 112 location.x += ((rand() % 20) - 10); 113 location.y += ((rand() % 20) - 10); 114 #ifdef __HAIKU__ 115 pose->SetLocation(location, view); 116 #else 117 pose->SetLocation(location); 118 #endif 119 } 120 121 view->CheckPoseVisibility(); 122 123 view->Invalidate(); 124 125 BString str("Score: "); 126 str << score; 127 view->Window()->SetTitle(str.String()); 128 129 view->UnlockLooper(); 130 snooze(100000); 131 } 132 133 BString scoreStr("You scored "); 134 scoreStr << score << " points!"; 135 alert = new BAlert("Error", scoreStr.String(), "Cool!"); 136 alert->Go(); 137 138 139 status = B_ERROR; 140 if (!msgr.LockTarget()) { 141 Error(view, status); 142 return; 143 } 144 145 /* 146 status = B_BAD_HANDLER; 147 view = dynamic_cast<BPoseView *>(msgr.Target(NULL)); 148 if (!view) 149 goto err1; 150 */ 151 152 view->HideBarberPole(); 153 view->SetViewMode(poseViewModeBackup); 154 view->RestoreState(poseViewBackup); 155 view->RestoreColumnState(poseViewColumnBackup); 156 157 view->Window()->SetTitle(windowTitleBackup.String()); 158 159 /* 160 BMessage('_RRC') { 161 TrackerViewToken = BMessenger(port=32004, team=591, target=direct:0x131) 162 } */ 163 164 165 //be_roster->Launch("application/x-vnd.haiku-filetypes", refs); 166 167 view->UnlockLooper(); 168 return; 169 170 } 171