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