Tracker: Write Trash icon attrs only once

Also create Trash if does not exist but check the if the icon
attrs are set separately.

Only set the vector trash icon #ifdef __HAIKU__ does this
even matter anymore?
This commit is contained in:
John Scipione
2014-07-17 14:51:26 -04:00
parent 7f68dcb4a7
commit 537e1fff3e
+16 -11
View File
@@ -2498,13 +2498,8 @@ FSGetTrashDir(BDirectory* trashDir, dev_t dev)
return result; return result;
result = trashDir->SetTo(path.Path()); result = trashDir->SetTo(path.Path());
if (result == B_OK) { if (result != B_OK) {
// Directory already exists, we're done // Trash directory does not exist yet, create it.
return B_OK;
}
// The trash directory does not exist yet - change that!
result = create_directory(path.Path(), 0755); result = create_directory(path.Path(), 0755);
if (result != B_OK) if (result != B_OK)
return result; return result;
@@ -2513,7 +2508,7 @@ FSGetTrashDir(BDirectory* trashDir, dev_t dev)
if (result != B_OK) if (result != B_OK)
return result; return result;
// make trash invisible // make Trash directory invisible
StatStruct sbuf; StatStruct sbuf;
trashDir->GetStat(&sbuf); trashDir->GetStat(&sbuf);
@@ -2522,22 +2517,32 @@ FSGetTrashDir(BDirectory* trashDir, dev_t dev)
poseInfo.fInitedDirectory = sbuf.st_ino; poseInfo.fInitedDirectory = sbuf.st_ino;
trashDir->WriteAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo, trashDir->WriteAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo,
sizeof(PoseInfo)); sizeof(PoseInfo));
}
// set trash icon // set Trash icons (if they haven't already been set)
attr_info attrInfo;
size_t size; size_t size;
const void* data const void* data;
= GetTrackerResources()->LoadResource('ICON', R_TrashIcon, &size); if (trashDir->GetAttrInfo(kAttrLargeIcon, &attrInfo) == B_ENTRY_NOT_FOUND) {
data = GetTrackerResources()->LoadResource('ICON', R_TrashIcon, &size);
if (data != NULL) if (data != NULL)
trashDir->WriteAttr(kAttrLargeIcon, 'ICON', 0, data, size); trashDir->WriteAttr(kAttrLargeIcon, 'ICON', 0, data, size);
}
if (trashDir->GetAttrInfo(kAttrMiniIcon, &attrInfo) == B_ENTRY_NOT_FOUND) {
data = GetTrackerResources()->LoadResource('MICN', R_TrashIcon, &size); data = GetTrackerResources()->LoadResource('MICN', R_TrashIcon, &size);
if (data != NULL) if (data != NULL)
trashDir->WriteAttr(kAttrMiniIcon, 'MICN', 0, data, size); trashDir->WriteAttr(kAttrMiniIcon, 'MICN', 0, data, size);
}
#ifdef __HAIKU__
if (trashDir->GetAttrInfo(kAttrIcon, &attrInfo) == B_ENTRY_NOT_FOUND) {
data = GetTrackerResources()->LoadResource(B_VECTOR_ICON_TYPE, data = GetTrackerResources()->LoadResource(B_VECTOR_ICON_TYPE,
R_TrashIcon, &size); R_TrashIcon, &size);
if (data != NULL) if (data != NULL)
trashDir->WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0, data, size); trashDir->WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0, data, size);
}
#endif // __HAIKU__
return B_OK; return B_OK;
} }