6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
35 // NodePreloader manages caching up icons from apps and prefs folder for
40 #include <Directory.h>
42 #include <FindDirectory.h>
44 #include <NodeMonitor.h>
48 #include "IconCache.h"
49 #include "NodePreloader.h"
55 NodePreloader::InstallNodePreloader(const char* name
, BLooper
* host
)
57 NodePreloader
* result
= new NodePreloader(name
);
59 AutoLock
<BLooper
> lock(host
);
65 host
->AddHandler(result
);
73 NodePreloader::NodePreloader(const char* name
)
82 NodePreloader::~NodePreloader()
84 // block deletion while we are locked
85 fQuitRequested
= true;
94 Thread::Launch(NewMemberFunctionObject(&NodePreloader::Preload
, this));
99 NodePreloader::FindModel(node_ref itemNode
) const
101 for (int32 count
= fModelList
.CountItems() - 1; count
>= 0; count
--) {
102 Model
* model
= fModelList
.ItemAt(count
);
103 if (*model
->NodeRef() == itemNode
)
112 NodePreloader::MessageReceived(BMessage
* message
)
114 // respond to node monitor notifications
117 switch (message
->what
) {
120 switch (message
->FindInt32("opcode")) {
121 case B_ENTRY_REMOVED
:
123 AutoLock
<Benaphore
> locker(fLock
);
124 message
->FindInt32("device", &itemNode
.device
);
125 message
->FindInt64("node", &itemNode
.node
);
126 Model
* model
= FindModel(itemNode
);
130 //PRINT(("preloader removing file %s\n", model->Name()));
131 IconCache::sIconCache
->Removing(model
);
132 fModelList
.RemoveItem(model
);
139 AutoLock
<Benaphore
> locker(fLock
);
140 message
->FindInt32("device", &itemNode
.device
);
141 message
->FindInt64("node", &itemNode
.node
);
143 const char* attrName
;
144 message
->FindString("attr", &attrName
);
145 Model
* model
= FindModel(itemNode
);
149 BModelOpener
opener(model
);
150 IconCache::sIconCache
->IconChanged(model
->ResolveIfLink());
151 //PRINT(("preloader updating file %s\n", model->Name()));
159 _inherited::MessageReceived(message
);
166 NodePreloader::PreloadOne(const char* dirPath
)
168 //PRINT(("preloading directory %s\n", dirPath));
169 BDirectory
dir(dirPath
);
170 if (dir
.InitCheck() != B_OK
)
174 dir
.GetNodeRef(&nodeRef
);
176 // have to node monitor the whole directory
177 TTracker::WatchNode(&nodeRef
, B_WATCH_DIRECTORY
, this);
182 if (dir
.GetNextRef(&ref
) != B_OK
)
187 // only interrested in files
190 Model
* model
= new Model(&ref
, true);
191 if (model
->InitCheck() == B_OK
&& model
->IconFrom() == kUnknownSource
) {
192 TTracker::WatchNode(model
->NodeRef(),
193 B_WATCH_STAT
| B_WATCH_ATTR
, this);
194 IconCache::sIconCache
->Preload(model
, kNormalIcon
, B_MINI_ICON
,
196 fModelList
.AddItem(model
);
205 NodePreloader::Preload()
207 for (int32 count
= 100; count
>= 0; count
--) {
208 // wait for a little bit before going ahead to reduce disk access
211 if (fQuitRequested
) {
217 BMessenger
messenger(kTrackerSignature
);
218 if (!messenger
.IsValid()) {
219 // put out some message here!
223 ASSERT(fLock
.IsLocked());
225 if (find_directory(B_BEOS_APPS_DIRECTORY
, &path
) == B_OK
)
226 PreloadOne(path
.Path());
228 if (find_directory(B_BEOS_PREFERENCES_DIRECTORY
, &path
) == B_OK
)
229 PreloadOne(path
.Path());