3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / tracker / iconvader / IconVader.cpp
blob36b32a10a5cbf728a97e46e0b8874332475db07a
1 /*
2 * Copyright 2009, François Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
4 */
6 #include <Alert.h>
7 #include <Messenger.h>
8 #include <Roster.h>
9 #include <View.h>
11 #include "PoseView.h"
14 static void Error(BView *view, status_t status, bool unlock=false)
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();
25 extern "C" void
26 process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/)
28 status_t status;
29 BAlert *alert;
30 BMessenger msgr;
31 BPoseView *view = NULL;
32 BMessage poseViewBackup;
33 BMessage poseViewColumnBackup;
34 uint32 poseViewModeBackup;
35 BString windowTitleBackup;
37 refs->PrintToStream();
39 status = refs->FindMessenger("TrackerViewToken", &msgr);
40 if (status < B_OK) {
41 Error(view, status);
42 return;
45 status = B_ERROR;
46 if (!msgr.LockTarget()) {
47 Error(view, status);
48 return;
51 status = B_BAD_HANDLER;
52 view = dynamic_cast<BPoseView *>(msgr.Target(NULL));
53 if (!view) {
54 Error(view, status);
55 return;
57 if (dynamic_cast<BWindow *>(view->Looper()) == NULL) {
58 Error(view, status, true);
59 return;
62 windowTitleBackup = view->Window()->Title();
64 view->SaveColumnState(poseViewColumnBackup);
65 view->SaveState(poseViewBackup);
66 view->SetDragEnabled(false);
67 view->SetSelectionRectEnabled(false);
68 view->SetPoseEditing(false);
69 poseViewModeBackup = view->ViewMode();
71 view->SetViewMode(kIconMode);
72 view->ShowBarberPole();
74 view->UnlockLooper();
76 alert = new BAlert("Error", "IconVader:\nClick on the icons to get points."
77 "\nAvoid symlinks!", "OK");
78 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
79 alert->Go();
81 int32 score = 0;
82 int32 count = 300;
83 while (count--) {
84 status = B_ERROR;
85 if (!msgr.LockTarget()) {
86 Error(view, status);
87 return;
90 BPose *pose;
91 for (int32 i = 0; (pose = view->PoseAtIndex(i)); i++) {
92 if (pose->IsSelected()) {
93 if (pose->TargetModel()->IsFile())
94 score++;
95 if (pose->TargetModel()->IsDirectory())
96 score+=2;
97 if (pose->TargetModel()->IsSymLink())
98 score-=10;
99 pose->Select(false);
101 BPoint location = pose->Location(view);
102 location.x += ((rand() % 20) - 10);
103 location.y += ((rand() % 20) - 10);
104 pose->SetLocation(location, view);
107 view->CheckPoseVisibility();
109 view->Invalidate();
111 BString str("Score: ");
112 str << score;
113 view->Window()->SetTitle(str.String());
115 view->UnlockLooper();
116 snooze(100000);
119 BString scoreStr("You scored ");
120 scoreStr << score << " points!";
121 alert = new BAlert("Error", scoreStr.String(), "Cool!");
122 alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
123 alert->Go();
125 status = B_ERROR;
126 if (!msgr.LockTarget()) {
127 Error(view, status);
128 return;
132 status = B_BAD_HANDLER;
133 view = dynamic_cast<BPoseView *>(msgr.Target(NULL));
134 if (!view)
135 goto err1;
138 view->HideBarberPole();
139 view->SetViewMode(poseViewModeBackup);
140 view->RestoreState(poseViewBackup);
141 view->RestoreColumnState(poseViewColumnBackup);
143 view->Window()->SetTitle(windowTitleBackup.String());
146 BMessage('_RRC') {
147 TrackerViewToken = BMessenger(port=32004, team=591, target=direct:0x131)
148 } */
151 view->UnlockLooper();
152 return;