This source file includes following definitions.
- Action_Search_0
- Action_Search_1
- Message_AddItem
- Run_OnOtherVolume
- Search_CheckTextFile
- Run_OnBootVolume
- Search_InFileCheck
- Search_AddResult
- Run
- Close
- BF_GUI_FilesPanel_SearchDialog_Thread
- ReadyForClose
- MessageReceived
- AttachedToWindow
1
2
3
4
5
6
7
8
9
10
11 #include <Volume.h>
12 #include <Path.h>
13
14 #include "BF_Dict.h"
15 #include "BF_GUI_FilesPanel_Search.h"
16 #include "BF_GUI_Func.h"
17 #include "BF_GUI_WinMain.h"
18 #include "BF_Roster.h"
19 #include "BL_File.h"
20
21 void
22 BF_GUI_FilesPanel::Action_Search_0()
23 {
24
25
26 BMessage oMessage(BF_MSG_FILEPANEL_SEARCH_SETUP_CLOSE);
27 oMessage.AddPointer("bf_focus",this);
28 oMessage.AddPointer("bf_current_folder",Path().String());
29
30 BF_GUI_Func_PanelsEnable(false);
31
32 BF_GUI_Dialog *poDialog = new BF_GUI_Dialog(BRect(0,0,300,0),
33 BF_DictAt(BF_DICT_SEARCH),"dialog",oMessage,BG_GUI_DIALOG_WINRESIZE_MOVE_CENTER);
34
35 BRect oRect;
36 poDialog->LocalBounds(oRect);
37
38
39 poDialog->LocalBounds(oRect);
40 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
41 BF_GUI_ViewEdit_Create(oRect,BF_DictAt(BF_DICT_FILESEARCH_FILENAME),poDialog,"name","*",
42 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE);
43 oRect.top = oRect.bottom + 5;
44
45 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
46 BF_GUI_ViewEdit_Create(oRect,BF_DictAt(BF_DICT_FILESEARCH_BYTEXT),poDialog,"text","",
47 B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE);
48 oRect.top = oRect.bottom + 5;
49
50 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
51 poDialog->AddChild(new BF_GUI_ViewCheck(oRect,"from_current_folder",
52 BF_DictAt(BF_DICT_FILESEARCH_FROMCURFOLDER),
53 false,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_NAVIGABLE));
54 oRect.top = oRect.bottom + 5;
55
56 oRect.bottom = oRect.top;
57 poDialog->AddChild(new BF_GUI_ViewFrame(oRect,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP));
58 oRect.top = oRect.bottom + 5;
59
60 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
61 poDialog->AddChild(new BF_GUI_ViewText(oRect,"comment",BF_DictAt(BF_DICT_FILESEARCH_ONVOLUMES)
62 ,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_WILL_DRAW,false));
63 oRect.top = oRect.bottom+5;
64
65 {
66 BL_List *ploItem = new BL_List();
67 BF_GUI_ViewMenu_Item *poItem = NULL;
68
69
70 bool bShowIcons = poSysSetup->MainStyle() & BF_SETUP_SEARCH_SETUP_VOLICONS;
71
72 BF_NodeList loNodeVol;
73 BF_Roster_VolumeList(loNodeVol,
74 ( (bShowIcons)?BF_ROSTER_LOADVOLS_SICON:0 )
75 );
76 BF_Volume *poNode;
77
78 for(int i=0;i<loNodeVol.CountItems();i++){
79 poNode = (BF_Volume*)loNodeVol.ItemAt(i);
80
81 if(poNode->bBootVolume) poNode->sName="boot";
82
83 poItem = new BF_GUI_ViewMenu_Item(poNode->sName.String(),poNode->sName.String() );
84 ploItem->AddItem(poItem);
85 if(poNode->poSIcon && bShowIcons) poItem->poSIcon = new BBitmap( poNode->poSIcon );
86
87 poItem->bSelected = poNode->bBootVolume;
88 }
89 oRect.bottom = oRect.top+70;
90 BF_GUI_DlgView_VMenu *poMenu = new BF_GUI_DlgView_VMenu(oRect,"volumes",B_FOLLOW_ALL,
91 ploItem,BF_GUI_DLGVIEW_VMENU_SICON|BF_GUI_DLGVIEW_VMENU_CAN_SELECTING);
92 poDialog->AddChild(poMenu);
93 oRect.top = oRect.bottom+5;
94 }
95
96 oRect.bottom = oRect.top;
97 poDialog->AddChild(new BF_GUI_ViewFrame(oRect,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP));
98 oRect.top = oRect.bottom + 5;
99
100
101 poDialog->AddOkCancelMenu(oRect);
102
103 poDialog->SetHeightFromLastChild();
104 poDialog->MoveToCenter( poWinView );
105 BF_GUI_Func_AddChildToMainView ( poDialog );
106 }
107
108 void
109 BF_GUI_FilesPanel::Action_Search_1(BMessage* po_Message)
110 {
111 ASSERT(po_Message);
112
113 bool bOk;
114 ASSERT(B_OK==po_Message->FindBool(BF_GUI_DIALOG_MESSAGE_DATA_OK,&bOk));
115 if(!bOk){
116 BF_GUI_Func_PanelsEnable(true);
117 MakeFocus();
118 return;
119 }
120
121
122
123 const char *pcFileName = po_Message->FindString("name");
124 const char *pcText = po_Message->FindString("text");
125 bool bFromCurrentFolder=false;
126 ASSERT(B_OK==po_Message->FindBool("from_current_folder",&bFromCurrentFolder));;
127
128 ASSERT(pcFileName && pcText);
129
130 BRect oRect(poWinView->Bounds());
131 oRect.left+=40;
132 oRect.right-=40;
133 oRect.top+=40;
134 oRect.bottom-=40;
135 BF_GUI_FilesPanel_SearchDialog *poDialog = new BF_GUI_FilesPanel_SearchDialog(oRect,
136 pcFileName,this,oPath);
137 poDialog->sSearchText = pcText;
138 poDialog->bFromCurrentFolder = bFromCurrentFolder;
139
140 poDialog->oCurrentFolder.SetTo(po_Message->FindString("bf_current_folder"));
141
142
143 BL_Get_SList_FromMessage(*po_Message,"volumes_sel",poDialog->lsVol);
144
145 poDialog->MoveToCenter( poWinView );
146 BF_GUI_Func_AddChildToMainView ( poDialog );
147 }
148
149 BF_GUI_FilesPanel_SearchDialog::BF_GUI_FilesPanel_SearchDialog(
150 const BRect & o_Rect,
151 const char *pc_SearchName,
152 BF_GUI_FilesPanel *po_Panel,
153 BF_Path & o_Path)
154 :BF_GUI_Dialog(o_Rect,BF_DictAt(BF_DICT_SEARCH),"search",BMessage(),BG_GUI_DIALOG_WINRESIZE_RESIZE_ALL)
155 {
156 oMessage.what = BF_MSG_FILEPANEL_SEARCH_CLOSE;
157 oMessage.AddPointer("bf_focus",po_Panel);
158
159 sSearchName = pc_SearchName;
160 poPanel = po_Panel;
161 idThreadQuery = 0;
162 poSearch = NULL;
163 oPath = o_Path;
164 bFromCurrentFolder = false;
165
166 BRect oRect;
167 LocalBounds(oRect);
168 oRect.bottom-=poSysSetup->oFontToolView.fHeight*3+5;
169 BL_List *ploCol = new BL_List();
170 float fWidthSize = poSysSetup->oFontToolView.oFont.StringWidth("1234567890121")+10;
171 ploCol->AddItem(new BF_GUI_DlgView_VCMenu_Column(BF_DictAt(BF_DICT_NAME),oRect.Width()-fWidthSize));
172 ploCol->AddItem(new BF_GUI_DlgView_VCMenu_Column(BF_DictAt(BF_DICT_NAME),fWidthSize));
173 poList = new BF_GUI_DlgView_VCMenu(oRect,"results",B_FOLLOW_ALL,new BL_List(),BF_GUI_DLGVIEW_VMENU_SICON,
174 ploCol);
175 AddChild(poList);
176
177 oRect.top = oRect.bottom + 5;
178 oRect.bottom = oRect.top+poSysSetup->oFontToolView.fHeight;
179 poComment = new BF_GUI_ViewText(oRect,"comment",BF_DictAt(BF_DICT_FILESEARCH_PROGRESS),B_FOLLOW_BOTTOM|B_FOLLOW_LEFT_RIGHT,0,false);
180 AddChild(poComment);
181
182 BL_List *ploMenu = new BL_List();
183 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_GOTO),"go"));
184 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_CANCEL),"cancel"));
185 AddMenu(oRect,ploMenu);
186 }
187
188 BF_GUI_FilesPanel_SearchDialog::~BF_GUI_FilesPanel_SearchDialog()
189 {
190 if(idThreadQuery) kill_thread(idThreadQuery);
191 }
192
193 BF_GUI_FilesPanel_Search::BF_GUI_FilesPanel_Search(BF_GUI_FilesPanel_SearchDialog *po_Dialog)
194 {
195 ASSERT(po_Dialog);
196 poDialogParent = po_Dialog;
197 bReqClose = false;
198 {
199 LOCK_WIN();
200 oPath = poDialogParent->oPath;
201 sSearchName = poDialogParent->sSearchName;
202 sSearchText = poDialogParent->sSearchText;
203 poDialogParent->poSearch = this;
204 bFromCurrentFolder = poDialogParent->bFromCurrentFolder;
205 oCurrentFolder = poDialogParent->oCurrentFolder;
206 }
207 oMsgAdd.what = BF_MSG_FILEPANEL_SEARCH_ADDITEM;
208 }
209
210 void
211 BF_GUI_FilesPanel_Search::Message_AddItem(BF_GUI_ViewMenu_Item *po_MenuItem)
212 {
213 ASSERT(po_MenuItem);
214 oMsgAdd.MakeEmpty();
215 oMsgAdd.AddPointer("bf_Item",po_MenuItem);
216
217 BMessenger oMessenger(poDialogParent);
218 oMessenger.SendMessage(&oMsgAdd);
219 }
220
221 void
222 BF_GUI_FilesPanel_Search::Run_OnOtherVolume(const char *pc_Path)
223 {
224
225 ASSERT(pc_Path);
226 BF_Path oPath(pc_Path);
227 BF_NodeList loNode;
228 BL_String s;
229 if(!BF_Roster_LoadNodeList(oPath,loNode,BF_ROSTER_LOAD_NODE_ALL_REAL)) return;
230
231 BF_Node *poNode=NULL;
232
233 Debug_Info(pc_Path);
234
235
236 for(int i=0;i<loNode.CountItems();i++){
237 poNode = loNode.NodeAt(i);
238
239
240 if(poNode->bLink && poNode->iType==BF_NODE_TYPE_DIR) continue;
241
242
243 if(poNode->CheckByMask(sSearchName.String())){
244 s = pc_Path;
245 s<<"/";
246 s<<poNode->sName;
247 Search_AddResult(poNode,s);
248 }
249
250 if(poNode->iType==BF_NODE_TYPE_DIR){
251 s = pc_Path;
252 s<<"/";
253 s<<poNode->sName;
254 Run_OnOtherVolume(s.String());
255 }
256
257 loNode.DeleteItem(poNode);
258 i--;
259 }
260 }
261
262
263 bool
264 BF_GUI_FilesPanel_Search::Search_CheckTextFile(const char *pc_PathName,BL_String & s1)
265 {
266 BL_File oFile(pc_PathName,B_READ_ONLY);
267 if(B_OK!=oFile.InitCheck()) return false;
268 while(B_OK==oFile.ReadString(&s1)){
269 if(bReqClose) return false;
270 if(s1.FindFirst(poDialogParent->sSearchText.String())>=0){
271 return true;
272 }
273 }
274 return false;
275 }
276
277 void
278 BF_GUI_FilesPanel_Search::Run_OnBootVolume()
279 {
280 status_t uRes;
281 BL_String s,s1,s2;
282
283
284 oQuery.Clear();
285
286 s="/boot";
287
288 {
289 s = (const char*)oPath.GetVolume(true);
290 entry_ref uRef;
291 uRes = BF_Roster_LoadEntryRef(s.String(),uRef);
292 if(uRes!=B_OK){
293 BF_Dialog_Alert_Sep_Error(uRes,poDialogParent);
294 return;
295 }
296 BVolume oVol(uRef.device);
297 uRes = oVol.InitCheck();
298 if(uRes!=B_OK){
299 BF_Dialog_Alert_Sep_Error(uRes,poDialogParent);
300 return;
301 }
302 uRes = oQuery.SetVolume(&oVol);
303 if(uRes!=B_OK){
304 BF_Dialog_Alert_Sep_Error(uRes,poDialogParent);
305 return;
306 }
307 }
308
309 oQuery.PushAttr("name");
310 oQuery.PushString(sSearchName.String());
311 oQuery.PushOp(B_EQ);
312
313 uRes = oQuery.Fetch();
314 if(B_OK!=uRes){
315 BF_Dialog_Alert_Sep_Error(uRes,poDialogParent);
316 return;
317 }
318
319 BEntry oEntry,oEntryParent;
320 BPath oPath;
321 char pc[500];
322 BF_Node oNode;
323
324
325 while(B_OK==oQuery.GetNextEntry(&oEntry)){
326 oEntry.GetName(pc);
327 s1 = pc;
328 oEntry.GetParent(&oEntryParent);
329 oPath.SetTo(&oEntryParent);
330 s = oPath.Path();
331 s<<"/";
332 s<<s1;
333
334 if(bFromCurrentFolder){
335 if(!oCurrentFolder.InFolder(oPath.Path())) continue;
336 }
337
338 BF_Node *poNode = BF_Roster_LoadNode(oPath.Path(),s1.String(),BF_ROSTER_LOAD_SICON);
339
340 if(sSearchText!=""){
341 oNode.Set(poNode,true);
342 DELETE(poNode);
343 poNode = &oNode;
344
345 if(poNode->iType!=BF_NODE_TYPE_FILE) continue;
346
347 if(poDialogParent->poComment){
348 s2=BF_DictAt(BF_DICT_FILESEARCH_PROGRESS);
349 s2<<s1;
350 LOCK_WIN();
351 poDialogParent->poComment->sTitle = s2;
352 poDialogParent->poComment->Draw(poDialogParent->poComment->Bounds());
353 }
354
355
356 BL_File oFile(s.String(),B_READ_ONLY);
357 bool bFounded=false;
358 if(B_OK!=oFile.InitCheck()) continue;
359 while(B_OK==oFile.ReadString(&s1)){
360 if(bReqClose) return;
361 if(s1.FindFirst(poDialogParent->sSearchText.String())>=0){
362 bFounded = true;
363 break;
364 }
365 }
366 if(!bFounded) continue;
367
368 if(poDialogParent->poComment){
369 LOCK_WIN();
370 poDialogParent->poComment->sTitle = BF_DictAt(BF_DICT_FILESEARCH_PROGRESS);
371 poDialogParent->poComment->Draw(poDialogParent->poComment->Bounds());
372 }
373 }
374
375 if(bReqClose) return;
376
377 Search_AddResult(poNode,s);
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392 if(poNode!=&oNode) DELETE(poNode);
393
394 }
395 return;
396
397 }
398
399 bool
400 BF_GUI_FilesPanel_Search::Search_InFileCheck(BF_Node *po_Node,BL_String &s_FullPath)
401 {
402 ASSERT(po_Node);
403
404 if(sSearchText=="") return true;
405 if(po_Node->iType!=BF_NODE_TYPE_FILE) return false;
406
407 BL_String s;
408
409
410 if(poDialogParent->poComment){
411
412 s=BF_DictAt(BF_DICT_FILESEARCH_PROGRESS);
413 s<<po_Node->sName;
414 LOCK_WIN();
415 poDialogParent->poComment->sTitle = s;
416 poDialogParent->poComment->Draw(poDialogParent->poComment->Bounds());
417 }
418
419
420
421
422 BL_File oFile(s_FullPath.String(),B_READ_ONLY);
423 bool bFounded=false;
424 if(B_OK!=oFile.InitCheck()) return false;
425 while(B_OK==oFile.ReadString(&s)){
426 if(bReqClose) return false;
427 if(s.FindFirst(poDialogParent->sSearchText.String())>=0){
428 bFounded = true;
429 break;
430 }
431 }
432
433 if(poDialogParent->poComment){
434 LOCK_WIN();
435 poDialogParent->poComment->sTitle = BF_DictAt(BF_DICT_FILESEARCH_PROGRESS);
436 poDialogParent->poComment->Draw(poDialogParent->poComment->Bounds());
437 }
438 return bFounded;
439 }
440
441 void
442 BF_GUI_FilesPanel_Search::Search_AddResult(BF_Node *po_Node,BL_String &s_FullPath)
443 {
444 ASSERT(po_Node);
445
446 if(!po_Node->poSIcon) BF_Roster_ReloadNode(s_FullPath.String(),po_Node,BF_ROSTER_LOAD_SICON,true);
447
448 if(!Search_InFileCheck(po_Node,s_FullPath)) return;
449
450
451 BF_GUI_ViewMenu_Item *poItem = new BF_GUI_ViewMenu_Item(s_FullPath.String(),s_FullPath.String(),
452 (po_Node && po_Node->poSIcon)?new BBitmap(po_Node->poSIcon):NULL);
453 switch(po_Node->iType){
454 case BF_NODE_TYPE_DIR:
455 s_FullPath=BF_DictAt(BF_DICT_DIR);
456 break;
457 default:
458 s_FullPath = po_Node->iSize;
459 }
460 poItem->loColItem.AddItem(new BF_GUI_ViewMenu_Item(s_FullPath.String(),""));
461
462 Message_AddItem(poItem);
463 }
464
465 void
466 BF_GUI_FilesPanel_Search::Run()
467 {
468
469 for(int iVol=0;iVol<poDialogParent->lsVol.CountItems();iVol++){
470 BL_String *ps = poDialogParent->lsVol.StringAt(iVol);
471 ASSERT(ps);
472
473
474
475
476
477
478 if(*ps=="boot"){
479 Run_OnBootVolume();
480 }else{
481 BL_String s("/");
482 s<<*ps;
483 Run_OnOtherVolume(s.String());
484 }
485 }
486
487
488
489
490
491 }
492
493 void
494 BF_GUI_FilesPanel_Search::Close()
495 {
496 oMsgAdd.what = BF_MSG_FILEPANEL_SEARCH_THREAD_FINISHED;
497
498 BMessenger oMessenger(poDialogParent);
499 oMessenger.SendMessage(&oMsgAdd);
500 }
501
502
503 int32
504 BF_GUI_FilesPanel_SearchDialog_Thread(void *data)
505 {
506 BF_GUI_FilesPanel_SearchDialog *poDialog = (BF_GUI_FilesPanel_SearchDialog*)data;
507
508 BF_GUI_FilesPanel_Search oSearch(poDialog);
509 oSearch.Run();
510 oSearch.Close();
511 return 0;
512 }
513
514 bool
515 BF_GUI_FilesPanel_SearchDialog::ReadyForClose()
516 {
517 if(poSearch) poSearch->bReqClose = true;
518 return 0==idThreadQuery;
519 }
520
521 void
522 BF_GUI_FilesPanel_SearchDialog::MessageReceived(BMessage* po_Message)
523 {
524 switch(po_Message->what){
525 case BF_MSG_FILEPANEL_SEARCH_THREAD_FINISHED:{
526 idThreadQuery = 0;
527 poSearch = NULL;
528
529 BL_String s;
530 s = BF_DictAt(BF_DICT_FILESEARCH_FOUNDED);
531 s<<" ";
532 s<<poList->ploMenu->CountItems();
533 s<<" ";
534 s<<BF_DictAt(BF_DICT_FILESEARCH_FILES);
535 poComment->sTitle = s;
536 poComment->Draw(poComment->Bounds());
537 break;}
538 case BF_MSG_FILEPANEL_SEARCH_ADDITEM:{
539 BF_GUI_ViewMenu_Item *poItem = NULL;
540 ASSERT(B_OK==po_Message->FindPointer("bf_Item",(void**)&poItem) && poItem);
541
542 poList->AddItem(poItem);
543
544
545
546
547
548
549
550
551 {
552 BL_String s;
553 s=BF_DictAt(BF_DICT_FILESEARCH_FOUNDED);
554 s<<" ";
555 s<<poList->ploMenu->CountItems();
556 s<<" ";
557 s<<BF_DictAt(BF_DICT_FILESEARCH_FILES);
558 poComment->sTitle = s;
559 poComment->Draw(poComment->Bounds());
560 }
561
562 break;}
563 default:
564 BF_GUI_Dialog::MessageReceived(po_Message);
565 }
566 }
567
568 void
569 BF_GUI_FilesPanel_SearchDialog::AttachedToWindow(void)
570 {
571 BF_GUI_Dialog::AttachedToWindow();
572
573 idThreadQuery = spawn_thread(BF_GUI_FilesPanel_SearchDialog_Thread,"search",B_THREAD_SUSPENDED,(void*)this);
574 ASSERT(idThreadQuery>0,"can`t start search_thread\n");
575 ASSERT(B_OK==resume_thread(idThreadQuery));
576 set_thread_priority(idThreadQuery,1);
577
578 }