This source file includes following definitions.
- Action_Tracker_Addons_Start_LoadAddOns
- Action_Tracker_Addons_Start
- BF_GUI_FilesPanel_Action_Tracker_Addons_Run_Thread
- Action_Tracker_Addons_Run
1 #include <stdio.h>
2 #include "BF_GUI_FilesPanel.h"
3 #include "BF_Roster.h"
4 #include "BF_Dict.h"
5 #include "BF_GUI_CmdLine.h"
6 #include "BF_GUI_KeysMenu.h"
7 #include "BF_GUI_FilesPanel_Tasks.h"
8 #include "BF_GUI_WinMain.h"
9
10 #define ADDONS_FOLDER_SYS "/boot/home/config/add-ons/Tracker"
11 #define ADDONS_FOLDER_HOME "/boot/beos/system/add-ons/Tracker"
12 #define WIN_TITLE "Tracker Add-Ons"
13
14 void
15 BF_GUI_FilesPanel::Action_Tracker_Addons_Start_LoadAddOns(bool b_FromHome,BL_List &lo_MenuResult,bool b_LoadSIcons)
16 {
17 BF_NodeList loNode;
18 BF_GUI_ViewMenu_Item *po;
19 BL_String s;
20 BF_Node *poNode;
21
22 BF_Path oPath(b_FromHome?ADDONS_FOLDER_HOME:ADDONS_FOLDER_SYS);
23 BF_Roster_LoadNodeList(oPath,loNode,BF_ROSTER_LOAD_NODE_FILE|BF_ROSTER_LOAD_NODE_LINK|(b_LoadSIcons?BF_ROSTER_LOAD_SICON:0));
24
25 for(int i=0;i<loNode.CountItems();i++){
26 poNode = (BF_Node*)loNode.ItemAt(i);
27
28 s = oPath.Path();
29 s<<"/";
30 s<<poNode->sName;
31
32 po = new BF_GUI_ViewMenu_Item(poNode->sName.String(),s.String() );
33 lo_MenuResult.AddItem(po);
34 if(b_LoadSIcons && poNode->poSIcon) po->poSIcon = new BBitmap( poNode->poSIcon );
35 }
36 }
37
38 void
39 BF_GUI_FilesPanel::Action_Tracker_Addons_Start()
40 {
41
42 bool bShowIcons = poSysSetup->MainStyle() & BF_SETUP_FILESPANEL_TRACKERADDONS_SHOWICONS;
43 BL_List *ploMenu = new BL_List();
44
45 Action_Tracker_Addons_Start_LoadAddOns(true,*ploMenu,bShowIcons);
46 Action_Tracker_Addons_Start_LoadAddOns(false,*ploMenu,bShowIcons);
47
48 if(ploMenu->CountItems()==0){
49 BF_Dialog_Alert_Sep(BF_DictAt(BF_DICT_ERROR),BF_DictAt(BF_DICT_TRADDS_NONE),NULL,this);
50 return;
51 }
52
53 BF_GUI_Func_PanelsEnable(false);
54
55
56 BMessage oMessage(BF_MSG_FILEPANEL_TRACKER_ADDONS_SELECTED);
57 oMessage.AddPointer("bf_focus",(void*)this);
58 oMessage.AddPointer("bf_panel_focus",(void*)poWin->CurrentFocus());
59
60 float fMaxWidth=0;
61 {
62 BF_GUI_ViewMenu_Item *po;
63 float f;
64 for(int i=0;i<ploMenu->CountItems();i++){
65 po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i);
66 ASSERT(po);
67 f = poSysSetup->oFontToolView.oFont.StringWidth(po->sTitle.String());
68 if(f>fMaxWidth) fMaxWidth = f;
69 }
70 if(bShowIcons) fMaxWidth+=19;
71 }
72
73 {
74 float fTitleWidth = poSysSetup->oFontToolView.oFont.StringWidth(WIN_TITLE)+40;
75 if(fTitleWidth>fMaxWidth) fMaxWidth = fTitleWidth;
76 }
77
78 BRect oDlgRect(30,30,0,0);
79 if(!bWinPos_OnLeft){
80 BRect oRect(poWinView->Bounds());
81 oDlgRect.left+=oRect.Width()/2;
82 }
83
84 BF_GUI_Dialog *poDialog = new BF_GUI_Dialog(oDlgRect,WIN_TITLE,"dialog",oMessage,
85 bWinPos_OnLeft?BG_GUI_DIALOG_WINRESIZE_NONE:BG_GUI_DIALOG_WINRESIZE_MOVE_RCENTER,false);
86
87 float fHeight = poSysSetup->oFontToolView.fHeight;
88 if(fHeight<19 && bShowIcons) fHeight = 19;
89
90 BRect oMenuRect(0,0,0,0);
91 poDialog->LocalBounds(oMenuRect);
92 oMenuRect.right = oMenuRect.left + fMaxWidth;
93 oMenuRect.bottom = oMenuRect.top + 5 + fHeight*ploMenu->CountItems();
94
95
96 BView* poMenu = new BF_GUI_DlgView_VMenu(oMenuRect,"menu", B_FOLLOW_ALL,ploMenu,
97 bShowIcons?BF_GUI_DLGVIEW_VMENU_SICON:0);
98
99 poDialog->AddChild(poMenu);
100 poDialog->SetSizeBy(oMenuRect.Width(),oMenuRect.Height());
101 BF_GUI_Func_AddChildToMainView ( poDialog );
102
103 return;
104 }
105
106 #include <be/add-ons/tracker/TrackerAddOn.h>
107
108
109 int32
110 BF_GUI_FilesPanel_Action_Tracker_Addons_Run_Thread(void *data)
111 {
112 BMessage *poMessage = (BMessage*)data;
113 if(!poMessage) return -1;
114
115 entry_ref uEntryRef;
116 if(B_OK!=poMessage->FindRef("folder_ref",&uEntryRef)) return -1;
117
118 void (*Func_AddOn)(entry_ref dir_ref, BMessage *msg, void *);
119 if(B_OK!=poMessage->FindPointer("func",(void**)&Func_AddOn) || !Func_AddOn) return -1;
120
121 (*Func_AddOn)(uEntryRef,poMessage,NULL);
122
123 DELETE(poMessage);
124 return -1;
125 }
126
127 void
128 BF_GUI_FilesPanel::Action_Tracker_Addons_Run(const char *pc_AddOn)
129 {
130 ASSERT(pc_AddOn);
131
132 image_id uImage;
133 uImage = load_add_on(pc_AddOn);
134 if(0==uImage) return;
135
136 BEntry oEntry(oPath.Path());
137 entry_ref uEntryRef;
138
139 if(B_OK!=oEntry.GetRef(&uEntryRef)) return;
140
141 void (*Func_AddOn)(entry_ref dir_ref, BMessage *msg, void *);
142 if(B_OK!=get_image_symbol(uImage, "process_refs", B_SYMBOL_TYPE_TEXT, (void**)&Func_AddOn)) return;
143
144 BMessage *poMessage = new BMessage();
145 BF_NodeCollection loSelNode;
146 loNode.GetSelecting(loSelNode);
147 if(loSelNode.CountItems()==0) loSelNode.AddItem(Nodes_Focus());
148 if(loSelNode.CountItems()==0) return;
149 ASSERT(poMessage);
150
151 BF_Node *poNode=NULL;
152 entry_ref uNodeRef;
153 BL_String s;
154 for(int iNode=0;iNode<loSelNode.CountItems();iNode++){
155 poNode = loSelNode.NodeAt(iNode);
156 s=oPath.Path();
157 s<<"/";
158 s<<poNode->sName;
159 if(B_OK!=oEntry.SetTo(s.String()) || B_OK!=oEntry.GetRef(&uNodeRef)) continue;
160 poMessage->AddRef("refs",&uNodeRef);
161 }
162
163
164 poMessage->AddRef("folder_ref",&uEntryRef);
165 poMessage->AddPointer("func",(void*)Func_AddOn);
166
167
168 thread_id idThread = spawn_thread(BF_GUI_FilesPanel_Action_Tracker_Addons_Run_Thread,"tracker_addon_thread",B_THREAD_SUSPENDED,(void*)poMessage);
169 ASSERT(idThread>0,"can`t start thread\n");
170 ASSERT(B_OK==resume_thread(idThread));
171 set_thread_priority(idThread,1);