1224ceba8SFrançois Revol /* 2224ceba8SFrançois Revol * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3224ceba8SFrançois Revol * Distributed under the terms of the MIT License. 4224ceba8SFrançois Revol */ 5224ceba8SFrançois Revol 6224ceba8SFrançois Revol 7224ceba8SFrançois Revol #include <Alert.h> 8224ceba8SFrançois Revol #include <Messenger.h> 9224ceba8SFrançois Revol #include <Roster.h> 10224ceba8SFrançois Revol #include <View.h> 11224ceba8SFrançois Revol 12224ceba8SFrançois Revol #include "PoseView.h" 13224ceba8SFrançois Revol 14224ceba8SFrançois Revol static void Error(BView *view, status_t status, bool unlock=false) 15224ceba8SFrançois Revol { 16224ceba8SFrançois Revol BAlert *alert; 17224ceba8SFrançois Revol if (view && unlock) 18224ceba8SFrançois Revol view->UnlockLooper(); 19224ceba8SFrançois Revol BString s(strerror(status)); 20224ceba8SFrançois Revol alert = new BAlert("Error", s.String(), "Ok"); 21224ceba8SFrançois Revol alert->Go(); 22224ceba8SFrançois Revol } 23224ceba8SFrançois Revol 24224ceba8SFrançois Revol /*! 25224ceba8SFrançois Revol \brief Tracker add-on entry 26224ceba8SFrançois Revol */ 27224ceba8SFrançois Revol extern "C" void 28224ceba8SFrançois Revol process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/) 29224ceba8SFrançois Revol { 30224ceba8SFrançois Revol status_t status; 31224ceba8SFrançois Revol BAlert *alert; 32224ceba8SFrançois Revol BMessenger msgr; 33224ceba8SFrançois Revol BPoseView *view = NULL; 34224ceba8SFrançois Revol BMessage poseViewBackup; 35224ceba8SFrançois Revol BMessage poseViewColumnBackup; 36224ceba8SFrançois Revol uint32 poseViewModeBackup; 37224ceba8SFrançois Revol BString windowTitleBackup; 38224ceba8SFrançois Revol 39224ceba8SFrançois Revol refs->PrintToStream(); 40224ceba8SFrançois Revol 41224ceba8SFrançois Revol status = refs->FindMessenger("TrackerViewToken", &msgr); 42224ceba8SFrançois Revol if (status < B_OK) { 43224ceba8SFrançois Revol Error(view, status); 44224ceba8SFrançois Revol return; 45224ceba8SFrançois Revol } 46224ceba8SFrançois Revol 47224ceba8SFrançois Revol status = B_ERROR; 48224ceba8SFrançois Revol if (!msgr.LockTarget()) { 49224ceba8SFrançois Revol Error(view, status); 50224ceba8SFrançois Revol return; 51224ceba8SFrançois Revol } 52224ceba8SFrançois Revol 53224ceba8SFrançois Revol status = B_BAD_HANDLER; 54224ceba8SFrançois Revol view = dynamic_cast<BPoseView *>(msgr.Target(NULL)); 55224ceba8SFrançois Revol if (!view) { 56224ceba8SFrançois Revol Error(view, status); 57224ceba8SFrançois Revol return; 58224ceba8SFrançois Revol } 59224ceba8SFrançois Revol if (dynamic_cast<BWindow *>(view->Looper()) == NULL) { 60224ceba8SFrançois Revol Error(view, status, true); 61224ceba8SFrançois Revol return; 62224ceba8SFrançois Revol } 63224ceba8SFrançois Revol 64224ceba8SFrançois Revol windowTitleBackup = view->Window()->Title(); 65224ceba8SFrançois Revol 66224ceba8SFrançois Revol view->SaveColumnState(poseViewColumnBackup); 67224ceba8SFrançois Revol view->SaveState(poseViewBackup); 68224ceba8SFrançois Revol view->SetDragEnabled(false); 69224ceba8SFrançois Revol view->SetSelectionRectEnabled(false); 70224ceba8SFrançois Revol view->SetPoseEditing(false); 71224ceba8SFrançois Revol poseViewModeBackup = view->ViewMode(); 72224ceba8SFrançois Revol 73224ceba8SFrançois Revol 74224ceba8SFrançois Revol view->SetViewMode(kIconMode); 75224ceba8SFrançois Revol 76224ceba8SFrançois Revol view->ShowBarberPole(); 77224ceba8SFrançois Revol 78224ceba8SFrançois Revol 79224ceba8SFrançois Revol view->UnlockLooper(); 80224ceba8SFrançois Revol 81224ceba8SFrançois Revol 82224ceba8SFrançois Revol 83224ceba8SFrançois Revol //alert = new BAlert("Error", "Plop", "Ok"); 84224ceba8SFrançois Revol //alert->Go(); 85224ceba8SFrançois Revol 86224ceba8SFrançois Revol 87224ceba8SFrançois Revol int32 score = 0; 88224ceba8SFrançois Revol int32 count = 300; 89224ceba8SFrançois Revol while (count--) { 90224ceba8SFrançois Revol status = B_ERROR; 91224ceba8SFrançois Revol if (!msgr.LockTarget()) { 92224ceba8SFrançois Revol Error(view, status); 93224ceba8SFrançois Revol return; 94224ceba8SFrançois Revol } 95224ceba8SFrançois Revol 96224ceba8SFrançois Revol BPose *pose; 97224ceba8SFrançois Revol for (int32 i = 0; (pose = view->PoseAtIndex(i)); i++) { 98224ceba8SFrançois Revol if (pose->IsSelected()) { 99*0fc05339SFrançois Revol if (pose->TargetModel()->IsFile()) 100224ceba8SFrançois Revol score++; 101*0fc05339SFrançois Revol if (pose->TargetModel()->IsDirectory()) 102*0fc05339SFrançois Revol score+=2; 103*0fc05339SFrançois Revol if (pose->TargetModel()->IsSymLink()) 104*0fc05339SFrançois Revol score-=10; 105224ceba8SFrançois Revol pose->Select(false); 106224ceba8SFrançois Revol } 107224ceba8SFrançois Revol BPoint location = pose->Location(); 108224ceba8SFrançois Revol location.x += ((rand() % 20) - 10); 109224ceba8SFrançois Revol location.y += ((rand() % 20) - 10); 110224ceba8SFrançois Revol pose->SetLocation(location); 111224ceba8SFrançois Revol } 112224ceba8SFrançois Revol 113224ceba8SFrançois Revol view->CheckPoseVisibility(); 114224ceba8SFrançois Revol 115224ceba8SFrançois Revol view->Invalidate(); 116224ceba8SFrançois Revol 117224ceba8SFrançois Revol BString str("Score: "); 118224ceba8SFrançois Revol str << score; 119224ceba8SFrançois Revol view->Window()->SetTitle(str.String()); 120224ceba8SFrançois Revol 121224ceba8SFrançois Revol view->UnlockLooper(); 122224ceba8SFrançois Revol snooze(100000); 123224ceba8SFrançois Revol } 124224ceba8SFrançois Revol 125224ceba8SFrançois Revol 126224ceba8SFrançois Revol status = B_ERROR; 127224ceba8SFrançois Revol if (!msgr.LockTarget()) { 128224ceba8SFrançois Revol Error(view, status); 129224ceba8SFrançois Revol return; 130224ceba8SFrançois Revol } 131224ceba8SFrançois Revol 132224ceba8SFrançois Revol /* 133224ceba8SFrançois Revol status = B_BAD_HANDLER; 134224ceba8SFrançois Revol view = dynamic_cast<BPoseView *>(msgr.Target(NULL)); 135224ceba8SFrançois Revol if (!view) 136224ceba8SFrançois Revol goto err1; 137224ceba8SFrançois Revol */ 138224ceba8SFrançois Revol 139224ceba8SFrançois Revol view->HideBarberPole(); 140224ceba8SFrançois Revol view->SetViewMode(poseViewModeBackup); 141224ceba8SFrançois Revol view->RestoreState(poseViewBackup); 142224ceba8SFrançois Revol view->RestoreColumnState(poseViewColumnBackup); 143224ceba8SFrançois Revol 144224ceba8SFrançois Revol view->Window()->SetTitle(windowTitleBackup.String()); 145224ceba8SFrançois Revol 146224ceba8SFrançois Revol /* 147224ceba8SFrançois Revol BMessage('_RRC') { 148224ceba8SFrançois Revol TrackerViewToken = BMessenger(port=32004, team=591, target=direct:0x131) 149224ceba8SFrançois Revol } */ 150224ceba8SFrançois Revol 151224ceba8SFrançois Revol 152224ceba8SFrançois Revol //be_roster->Launch("application/x-vnd.haiku-filetypes", refs); 153224ceba8SFrançois Revol 154224ceba8SFrançois Revol view->UnlockLooper(); 155224ceba8SFrançois Revol return; 156224ceba8SFrançois Revol 157224ceba8SFrançois Revol } 158