diff options
| author | Philippe Saint-Pierre <stpere@gmail.com> | 2012-07-23 16:12:47 -0400 |
|---|---|---|
| committer | Philippe Saint-Pierre <stpere@gmail.com> | 2012-07-23 16:15:19 -0400 |
| commit | 50d739dee5fe3c635a052dfd435bcf6557f11639 (patch) | |
| tree | 4382a81da4c48290060f768e78b0b090aef58c66 | |
| parent | dae0a4e0abda9ce3dff8e31007a8f66bc14421c8 (diff) | |
Tracker: Regression fixhrev44389
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).
| -rw-r--r-- | src/kits/tracker/ContainerWindow.cpp | 78 | ||||
| -rw-r--r-- | src/kits/tracker/ContainerWindow.h | 6 | ||||
| -rw-r--r-- | src/kits/tracker/DeskWindow.cpp | 6 |
3 files changed, 49 insertions, 41 deletions
diff --git a/src/kits/tracker/ContainerWindow.cpp b/src/kits/tracker/ContainerWindow.cpp index e5b044bc8d..fc9649e375 100644 --- a/src/kits/tracker/ContainerWindow.cpp +++ b/src/kits/tracker/ContainerWindow.cpp @@ -130,7 +130,6 @@ class DraggableContainerIcon : public BView { struct AddOneAddonParams { BObjectList<BMenuItem> *primaryList; BObjectList<BMenuItem> *secondaryList; - BObjectList<BString> *mimeTypes; }; struct StaggerOneParams { @@ -2814,33 +2813,33 @@ BContainerWindow::AddTrashContextMenus(BMenu *menu) void 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); BPath path; bool bail = false; 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) - bail = EachAddon(path, eachAddon, &uniqueList, passThru); + bail = EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes); if (!bail && find_directory(B_COMMON_ADDONS_DIRECTORY, &path) == B_OK) - EachAddon(path, eachAddon, &uniqueList, passThru); + EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes); } bool BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, const char *, uint32 shortcut, bool primary, void *), - BObjectList<Model> *uniqueList, void *params) + BObjectList<Model> *uniqueList, void *params, + BObjectList<BString> &mimeTypes) { path.Append("Tracker"); BDirectory dir; BEntry entry; - - BObjectList<BString> *mimeTypes = ((AddOneAddonParams *)params)->mimeTypes; if (dir.SetTo(path.Path()) != B_OK) return false; @@ -2866,7 +2865,7 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, bool primary = false; - if (mimeTypes->CountItems()) { + if (mimeTypes.CountItems()) { BFile file(&entry, B_READ_ONLY); if (file.InitCheck() == B_OK) { BAppFileInfo info(&file); @@ -2884,8 +2883,8 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, // check all supported types if it has some set if (!secondary) { - for (int32 i = mimeTypes->CountItems(); !primary && i-- > 0;) { - BString *type = mimeTypes->ItemAt(i); + for (int32 i = mimeTypes.CountItems(); !primary && i-- > 0;) { + BString *type = mimeTypes.ItemAt(i); if (info.IsSupportedType(type->String())) { BMimeType mimeType(type->String()); if (info.Supports(&mimeType)) @@ -2924,6 +2923,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 BContainerWindow::BuildAddOnMenu(BMenu *menu) { BMenuItem* item = menu->FindItem(B_TRANSLATE("Add-ons")); @@ -2952,44 +2977,21 @@ BContainerWindow::BuildAddOnMenu(BMenu *menu) BObjectList<BMenuItem> primaryList; BObjectList<BMenuItem> secondaryList; + BObjectList<BString> mimeTypes(10, true); + BuildMimeTypeList(mimeTypes); AddOneAddonParams params; params.primaryList = &primaryList; params.secondaryList = &secondaryList; // build a list of the MIME types of the selected items - BObjectList<BString> mimeTypes(10, true); - - 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; - } - } - } - - params.mimeTypes = &mimeTypes; - EachAddon(AddOneAddon, ¶ms); + EachAddon(AddOneAddon, ¶ms, mimeTypes); primaryList.SortItems(CompareLabels); secondaryList.SortItems(CompareLabels); - count = primaryList.CountItems(); + int32 count = primaryList.CountItems(); for (int32 index = 0; index < count; index++) menu->AddItem(primaryList.ItemAt(index)); diff --git a/src/kits/tracker/ContainerWindow.h b/src/kits/tracker/ContainerWindow.h index 373b81a7a1..e312ab213e 100644 --- a/src/kits/tracker/ContainerWindow.h +++ b/src/kits/tracker/ContainerWindow.h @@ -169,7 +169,8 @@ class BContainerWindow : public BWindow { bool createNew = false, bool createFolder = true); // 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(); @@ -233,6 +234,7 @@ class BContainerWindow : public BWindow { virtual void SetUpDiskMenu(BMenu *); virtual void BuildAddOnMenu(BMenu *); + void BuildMimeTypeList(BObjectList<BString>& mimeTypes); enum UpdateMenuContext { kMenuBarContext, @@ -249,7 +251,7 @@ class BContainerWindow : public BWindow { const char *); bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *), - BObjectList<Model> *, void *); + BObjectList<Model> *, void *, BObjectList<BString> &); void LoadAddOn(BMessage *); BPopUpMenu *fFileContextMenu; diff --git a/src/kits/tracker/DeskWindow.cpp b/src/kits/tracker/DeskWindow.cpp index fa16d62c56..bddc16471c 100644 --- a/src/kits/tracker/DeskWindow.cpp +++ b/src/kits/tracker/DeskWindow.cpp @@ -204,7 +204,11 @@ BDeskWindow::MenusBeginning() AddOneShortcutParams params; params.window = this; params.currentAddonShortcuts = &fCurrentAddonShortcuts; - EachAddon(&AddOneShortcut, ¶ms); + + BObjectList<BString> mimeTypes(10, true); + BuildMimeTypeList(mimeTypes); + + EachAddon(&AddOneShortcut, ¶ms, mimeTypes); } } |
