1224ceba8SFrançois Revol /*
2*3fa198daSAugustin Cavalier * Copyright 2009, François Revol, <revol@free.fr>.
3224ceba8SFrançois Revol * Distributed under the terms of the MIT License.
4224ceba8SFrançois Revol */
5224ceba8SFrançois Revol
6224ceba8SFrançois Revol #include <Alert.h>
7224ceba8SFrançois Revol #include <Messenger.h>
8224ceba8SFrançois Revol #include <Roster.h>
9224ceba8SFrançois Revol #include <View.h>
10224ceba8SFrançois Revol
11224ceba8SFrançois Revol #include "PoseView.h"
12224ceba8SFrançois Revol
13*3fa198daSAugustin Cavalier
Error(BView * view,status_t status,bool unlock=false)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));
20fcc3e627SStephan Aßmus alert = new BAlert("Error", s.String(), "OK");
21aed35104SHumdinger alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
22224ceba8SFrançois Revol alert->Go();
23224ceba8SFrançois Revol }
24224ceba8SFrançois Revol
25224ceba8SFrançois Revol extern "C" void
process_refs(entry_ref dir,BMessage * refs,void *)26224ceba8SFrançois Revol process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/)
27224ceba8SFrançois Revol {
28224ceba8SFrançois Revol status_t status;
29224ceba8SFrançois Revol BAlert *alert;
30224ceba8SFrançois Revol BMessenger msgr;
31224ceba8SFrançois Revol BPoseView *view = NULL;
32224ceba8SFrançois Revol BMessage poseViewBackup;
33224ceba8SFrançois Revol BMessage poseViewColumnBackup;
34224ceba8SFrançois Revol uint32 poseViewModeBackup;
35224ceba8SFrançois Revol BString windowTitleBackup;
36224ceba8SFrançois Revol
37224ceba8SFrançois Revol refs->PrintToStream();
38224ceba8SFrançois Revol
39224ceba8SFrançois Revol status = refs->FindMessenger("TrackerViewToken", &msgr);
40224ceba8SFrançois Revol if (status < B_OK) {
41224ceba8SFrançois Revol Error(view, status);
42224ceba8SFrançois Revol return;
43224ceba8SFrançois Revol }
44224ceba8SFrançois Revol
45224ceba8SFrançois Revol status = B_ERROR;
46224ceba8SFrançois Revol if (!msgr.LockTarget()) {
47224ceba8SFrançois Revol Error(view, status);
48224ceba8SFrançois Revol return;
49224ceba8SFrançois Revol }
50224ceba8SFrançois Revol
51224ceba8SFrançois Revol status = B_BAD_HANDLER;
52224ceba8SFrançois Revol view = dynamic_cast<BPoseView *>(msgr.Target(NULL));
53224ceba8SFrançois Revol if (!view) {
54224ceba8SFrançois Revol Error(view, status);
55224ceba8SFrançois Revol return;
56224ceba8SFrançois Revol }
57224ceba8SFrançois Revol if (dynamic_cast<BWindow *>(view->Looper()) == NULL) {
58224ceba8SFrançois Revol Error(view, status, true);
59224ceba8SFrançois Revol return;
60224ceba8SFrançois Revol }
61224ceba8SFrançois Revol
62224ceba8SFrançois Revol windowTitleBackup = view->Window()->Title();
63224ceba8SFrançois Revol
64224ceba8SFrançois Revol view->SaveColumnState(poseViewColumnBackup);
65224ceba8SFrançois Revol view->SaveState(poseViewBackup);
66224ceba8SFrançois Revol view->SetDragEnabled(false);
67224ceba8SFrançois Revol view->SetSelectionRectEnabled(false);
68224ceba8SFrançois Revol view->SetPoseEditing(false);
69224ceba8SFrançois Revol poseViewModeBackup = view->ViewMode();
70224ceba8SFrançois Revol
71224ceba8SFrançois Revol view->SetViewMode(kIconMode);
72224ceba8SFrançois Revol view->ShowBarberPole();
73224ceba8SFrançois Revol
74224ceba8SFrançois Revol view->UnlockLooper();
75224ceba8SFrançois Revol
76aed35104SHumdinger alert = new BAlert("Error", "IconVader:\nClick on the icons to get points."
77aed35104SHumdinger "\nAvoid symlinks!", "OK");
78aed35104SHumdinger alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
79eb0703faSFrançois Revol alert->Go();
80224ceba8SFrançois Revol
81224ceba8SFrançois Revol int32 score = 0;
82224ceba8SFrançois Revol int32 count = 300;
83224ceba8SFrançois Revol while (count--) {
84224ceba8SFrançois Revol status = B_ERROR;
85224ceba8SFrançois Revol if (!msgr.LockTarget()) {
86224ceba8SFrançois Revol Error(view, status);
87224ceba8SFrançois Revol return;
88224ceba8SFrançois Revol }
89224ceba8SFrançois Revol
90224ceba8SFrançois Revol BPose *pose;
91224ceba8SFrançois Revol for (int32 i = 0; (pose = view->PoseAtIndex(i)); i++) {
92224ceba8SFrançois Revol if (pose->IsSelected()) {
930fc05339SFrançois Revol if (pose->TargetModel()->IsFile())
94224ceba8SFrançois Revol score++;
950fc05339SFrançois Revol if (pose->TargetModel()->IsDirectory())
960fc05339SFrançois Revol score+=2;
970fc05339SFrançois Revol if (pose->TargetModel()->IsSymLink())
980fc05339SFrançois Revol score-=10;
99224ceba8SFrançois Revol pose->Select(false);
100224ceba8SFrançois Revol }
101f930131dSRene Gollent BPoint location = pose->Location(view);
102224ceba8SFrançois Revol location.x += ((rand() % 20) - 10);
103224ceba8SFrançois Revol location.y += ((rand() % 20) - 10);
104f930131dSRene Gollent pose->SetLocation(location, view);
105224ceba8SFrançois Revol }
106224ceba8SFrançois Revol
107224ceba8SFrançois Revol view->CheckPoseVisibility();
108224ceba8SFrançois Revol
109224ceba8SFrançois Revol view->Invalidate();
110224ceba8SFrançois Revol
111224ceba8SFrançois Revol BString str("Score: ");
112224ceba8SFrançois Revol str << score;
113224ceba8SFrançois Revol view->Window()->SetTitle(str.String());
114224ceba8SFrançois Revol
115224ceba8SFrançois Revol view->UnlockLooper();
116224ceba8SFrançois Revol snooze(100000);
117224ceba8SFrançois Revol }
118224ceba8SFrançois Revol
119eb0703faSFrançois Revol BString scoreStr("You scored ");
120eb0703faSFrançois Revol scoreStr << score << " points!";
121eb0703faSFrançois Revol alert = new BAlert("Error", scoreStr.String(), "Cool!");
122aed35104SHumdinger alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
123eb0703faSFrançois Revol alert->Go();
124eb0703faSFrançois Revol
125224ceba8SFrançois Revol status = B_ERROR;
126224ceba8SFrançois Revol if (!msgr.LockTarget()) {
127224ceba8SFrançois Revol Error(view, status);
128224ceba8SFrançois Revol return;
129224ceba8SFrançois Revol }
130224ceba8SFrançois Revol
131224ceba8SFrançois Revol /*
132224ceba8SFrançois Revol status = B_BAD_HANDLER;
133224ceba8SFrançois Revol view = dynamic_cast<BPoseView *>(msgr.Target(NULL));
134224ceba8SFrançois Revol if (!view)
135224ceba8SFrançois Revol goto err1;
136224ceba8SFrançois Revol */
137224ceba8SFrançois Revol
138224ceba8SFrançois Revol view->HideBarberPole();
139224ceba8SFrançois Revol view->SetViewMode(poseViewModeBackup);
140224ceba8SFrançois Revol view->RestoreState(poseViewBackup);
141224ceba8SFrançois Revol view->RestoreColumnState(poseViewColumnBackup);
142224ceba8SFrançois Revol
143224ceba8SFrançois Revol view->Window()->SetTitle(windowTitleBackup.String());
144224ceba8SFrançois Revol
145224ceba8SFrançois Revol /*
146224ceba8SFrançois Revol BMessage('_RRC') {
147224ceba8SFrançois Revol TrackerViewToken = BMessenger(port=32004, team=591, target=direct:0x131)
148224ceba8SFrançois Revol } */
149224ceba8SFrançois Revol
150224ceba8SFrançois Revol
151224ceba8SFrançois Revol view->UnlockLooper();
152224ceba8SFrançois Revol return;
153224ceba8SFrançois Revol
154224ceba8SFrançois Revol }
155