Tracker: Regression fix

A crash of Tracker was triggered when accessing AddOn menu (by
shortcut or context-menu) for Pose on Desktop, because of it's
incapacity to read the mime type list (that wasn't built in
those cases).
This commit is contained in:
Philippe Saint-Pierre
2012-07-23 16:15:19 -04:00
parent dae0a4e0ab
commit 50d739dee5
3 changed files with 49 additions and 41 deletions
+40 -38
View File
@@ -130,7 +130,6 @@ class DraggableContainerIcon : public BView {
struct AddOneAddonParams { struct AddOneAddonParams {
BObjectList<BMenuItem> *primaryList; BObjectList<BMenuItem> *primaryList;
BObjectList<BMenuItem> *secondaryList; BObjectList<BMenuItem> *secondaryList;
BObjectList<BString> *mimeTypes;
}; };
struct StaggerOneParams { struct StaggerOneParams {
@@ -2814,33 +2813,33 @@ BContainerWindow::AddTrashContextMenus(BMenu *menu)
void void
BContainerWindow::EachAddon(bool (*eachAddon)(const Model *, const char *, BContainerWindow::EachAddon(bool (*eachAddon)(const Model *, const char *,
uint32 shortcut, bool primary, void *context), void *passThru) uint32 shortcut, bool primary, void *context), void *passThru,
BObjectList<BString> &mimeTypes)
{ {
BObjectList<Model> uniqueList(10, true); BObjectList<Model> uniqueList(10, true);
BPath path; BPath path;
bool bail = false; bool bail = false;
if (find_directory(B_BEOS_ADDONS_DIRECTORY, &path) == B_OK) if (find_directory(B_BEOS_ADDONS_DIRECTORY, &path) == B_OK)
bail = EachAddon(path, eachAddon, &uniqueList, passThru); bail = EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes);
if (!bail && find_directory(B_USER_ADDONS_DIRECTORY, &path) == B_OK) if (!bail && find_directory(B_USER_ADDONS_DIRECTORY, &path) == B_OK)
bail = EachAddon(path, eachAddon, &uniqueList, passThru); bail = EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes);
if (!bail && find_directory(B_COMMON_ADDONS_DIRECTORY, &path) == B_OK) if (!bail && find_directory(B_COMMON_ADDONS_DIRECTORY, &path) == B_OK)
EachAddon(path, eachAddon, &uniqueList, passThru); EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes);
} }
bool bool
BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *,
const char *, uint32 shortcut, bool primary, void *), const char *, uint32 shortcut, bool primary, void *),
BObjectList<Model> *uniqueList, void *params) BObjectList<Model> *uniqueList, void *params,
BObjectList<BString> &mimeTypes)
{ {
path.Append("Tracker"); path.Append("Tracker");
BDirectory dir; BDirectory dir;
BEntry entry; BEntry entry;
BObjectList<BString> *mimeTypes = ((AddOneAddonParams *)params)->mimeTypes;
if (dir.SetTo(path.Path()) != B_OK) if (dir.SetTo(path.Path()) != B_OK)
return false; return false;
@@ -2866,7 +2865,7 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *,
bool primary = false; bool primary = false;
if (mimeTypes->CountItems()) { if (mimeTypes.CountItems()) {
BFile file(&entry, B_READ_ONLY); BFile file(&entry, B_READ_ONLY);
if (file.InitCheck() == B_OK) { if (file.InitCheck() == B_OK) {
BAppFileInfo info(&file); BAppFileInfo info(&file);
@@ -2884,8 +2883,8 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *,
// check all supported types if it has some set // check all supported types if it has some set
if (!secondary) { if (!secondary) {
for (int32 i = mimeTypes->CountItems(); !primary && i-- > 0;) { for (int32 i = mimeTypes.CountItems(); !primary && i-- > 0;) {
BString *type = mimeTypes->ItemAt(i); BString *type = mimeTypes.ItemAt(i);
if (info.IsSupportedType(type->String())) { if (info.IsSupportedType(type->String())) {
BMimeType mimeType(type->String()); BMimeType mimeType(type->String());
if (info.Supports(&mimeType)) if (info.Supports(&mimeType))
@@ -2923,6 +2922,32 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *,
} }
void
BContainerWindow::BuildMimeTypeList(BObjectList<BString> &mimeTypes)
{
int32 count = PoseView()->SelectionList()->CountItems();
if (!count) {
// just add the type of the current directory
AddMimeTypeString(mimeTypes, TargetModel());
} else {
_UpdateSelectionMIMEInfo();
for (int32 index = 0; index < count; index++) {
BPose *pose = PoseView()->SelectionList()->ItemAt(index);
AddMimeTypeString(mimeTypes, pose->TargetModel());
// If it's a symlink, resolves it and add the Target's MimeType
if (pose->TargetModel()->IsSymLink()) {
Model* resolved = new Model(
pose->TargetModel()->EntryRef(), true, true);
if (resolved->InitCheck() == B_OK) {
AddMimeTypeString(mimeTypes, resolved);
}
delete resolved;
}
}
}
}
void void
BContainerWindow::BuildAddOnMenu(BMenu *menu) BContainerWindow::BuildAddOnMenu(BMenu *menu)
{ {
@@ -2952,44 +2977,21 @@ BContainerWindow::BuildAddOnMenu(BMenu *menu)
BObjectList<BMenuItem> primaryList; BObjectList<BMenuItem> primaryList;
BObjectList<BMenuItem> secondaryList; BObjectList<BMenuItem> secondaryList;
BObjectList<BString> mimeTypes(10, true);
BuildMimeTypeList(mimeTypes);
AddOneAddonParams params; AddOneAddonParams params;
params.primaryList = &primaryList; params.primaryList = &primaryList;
params.secondaryList = &secondaryList; params.secondaryList = &secondaryList;
// build a list of the MIME types of the selected items // build a list of the MIME types of the selected items
BObjectList<BString> mimeTypes(10, true);
int32 count = PoseView()->SelectionList()->CountItems(); EachAddon(AddOneAddon, &params, mimeTypes);
if (!count) {
// just add the type of the current directory
AddMimeTypeString(mimeTypes, TargetModel());
} else {
_UpdateSelectionMIMEInfo();
for (int32 index = 0; index < count; index++) {
BPose *pose = PoseView()->SelectionList()->ItemAt(index);
AddMimeTypeString(mimeTypes, pose->TargetModel());
// If it's a symlink, resolves it and add the Target's MimeType
if (pose->TargetModel()->IsSymLink()) {
Model* resolved = new Model(
pose->TargetModel()->EntryRef(), true, true);
if (resolved->InitCheck() == B_OK) {
AddMimeTypeString(mimeTypes, resolved);
}
delete resolved;
}
}
}
params.mimeTypes = &mimeTypes;
EachAddon(AddOneAddon, &params);
primaryList.SortItems(CompareLabels); primaryList.SortItems(CompareLabels);
secondaryList.SortItems(CompareLabels); secondaryList.SortItems(CompareLabels);
count = primaryList.CountItems(); int32 count = primaryList.CountItems();
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++)
menu->AddItem(primaryList.ItemAt(index)); menu->AddItem(primaryList.ItemAt(index));
+4 -2
View File
@@ -169,7 +169,8 @@ class BContainerWindow : public BWindow {
bool createNew = false, bool createFolder = true); bool createNew = false, bool createFolder = true);
// add-on iteration // add-on iteration
void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut, bool primary, void *), void *); void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut,
bool primary, void *), void *, BObjectList<BString> &);
BPopUpMenu *ContextMenu(); BPopUpMenu *ContextMenu();
@@ -233,6 +234,7 @@ class BContainerWindow : public BWindow {
virtual void SetUpDiskMenu(BMenu *); virtual void SetUpDiskMenu(BMenu *);
virtual void BuildAddOnMenu(BMenu *); virtual void BuildAddOnMenu(BMenu *);
void BuildMimeTypeList(BObjectList<BString>& mimeTypes);
enum UpdateMenuContext { enum UpdateMenuContext {
kMenuBarContext, kMenuBarContext,
@@ -249,7 +251,7 @@ class BContainerWindow : public BWindow {
const char *); const char *);
bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *), bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *),
BObjectList<Model> *, void *); BObjectList<Model> *, void *, BObjectList<BString> &);
void LoadAddOn(BMessage *); void LoadAddOn(BMessage *);
BPopUpMenu *fFileContextMenu; BPopUpMenu *fFileContextMenu;
+5 -1
View File
@@ -204,7 +204,11 @@ BDeskWindow::MenusBeginning()
AddOneShortcutParams params; AddOneShortcutParams params;
params.window = this; params.window = this;
params.currentAddonShortcuts = &fCurrentAddonShortcuts; params.currentAddonShortcuts = &fCurrentAddonShortcuts;
EachAddon(&AddOneShortcut, &params);
BObjectList<BString> mimeTypes(10, true);
BuildMimeTypeList(mimeTypes);
EachAddon(&AddOneShortcut, &params, mimeTypes);
} }
} }