Tracker: style fixes to QueryPoseView

This commit is contained in:
John Scipione
2014-06-20 21:29:26 -04:00
parent 388dbb6fe7
commit 961b4f97f7
2 changed files with 51 additions and 32 deletions
+43 -25
View File
@@ -59,10 +59,12 @@ All rights reserved.
#include <fs_attr.h> #include <fs_attr.h>
using std::nothrow;
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "QueryPoseView" #define B_TRANSLATION_CONTEXT "QueryPoseView"
using std::nothrow;
// Currently filtering out Trash doesn't node monitor too well - if you // Currently filtering out Trash doesn't node monitor too well - if you
// remove an item from the Trash, it doesn't show up in the query result // remove an item from the Trash, it doesn't show up in the query result
@@ -71,8 +73,13 @@ using std::nothrow;
// query results and add/remove appropriately. Right now only moving to // query results and add/remove appropriately. Right now only moving to
// Trash is supported // Trash is supported
// #pragma mark - BQueryPoseView
BQueryPoseView::BQueryPoseView(Model* model, BRect frame, uint32 resizeMask) BQueryPoseView::BQueryPoseView(Model* model, BRect frame, uint32 resizeMask)
: BPoseView(model, frame, kListMode, resizeMask), :
BPoseView(model, frame, kListMode, resizeMask),
fShowResultsFromTrash(false), fShowResultsFromTrash(false),
fQueryList(NULL), fQueryList(NULL),
fQueryListContainer(NULL), fQueryListContainer(NULL),
@@ -200,20 +207,23 @@ BQueryPoseView::ShouldShowPose(const Model* model, const PoseInfo* poseInfo)
// add_poses, etc. filter // add_poses, etc. filter
ASSERT(TargetModel()); ASSERT(TargetModel());
if (!fShowResultsFromTrash TTracker* tracker = dynamic_cast<TTracker*>(be_app);
&& dynamic_cast<TTracker*>(be_app)->InTrashNode(model->EntryRef())) if (!fShowResultsFromTrash && tracker != NULL
&& tracker->InTrashNode(model->EntryRef())) {
return false; return false;
}
bool result = _inherited::ShouldShowPose(model, poseInfo); bool result = _inherited::ShouldShowPose(model, poseInfo);
PoseList* oldPoseList = fQueryListContainer->OldPoseList(); PoseList* oldPoseList = fQueryListContainer->OldPoseList();
if (result && oldPoseList) { if (result && oldPoseList != NULL) {
// pose will get added - remove it from the old pose list // pose will get added - remove it from the old pose list
// because it is supposed to be showing // because it is supposed to be showing
BPose* pose = oldPoseList->FindPose(model); BPose* pose = oldPoseList->FindPose(model);
if (pose) if (pose != NULL)
oldPoseList->RemoveItem(pose); oldPoseList->RemoveItem(pose);
} }
return result; return result;
} }
@@ -224,7 +234,7 @@ BQueryPoseView::AddPosesCompleted()
ASSERT(Window()->IsLocked()); ASSERT(Window()->IsLocked());
PoseList* oldPoseList = fQueryListContainer->OldPoseList(); PoseList* oldPoseList = fQueryListContainer->OldPoseList();
if (oldPoseList) { if (oldPoseList != NULL) {
int32 count = oldPoseList->CountItems(); int32 count = oldPoseList->CountItems();
for (int32 index = count - 1; index >= 0; index--) { for (int32 index = count - 1; index >= 0; index--) {
BPose* pose = oldPoseList->ItemAt(index); BPose* pose = oldPoseList->ItemAt(index);
@@ -279,8 +289,8 @@ BQueryPoseView::InitDirentIterator(const entry_ref* ref)
fQueryList = fQueryListContainer->QueryList(); fQueryList = fQueryListContainer->QueryList();
if (fQueryListContainer->DynamicDateQuery()) { if (fQueryListContainer->DynamicDateQuery()) {
// calculate the time to trigger the query refresh - next midnight // calculate the time to trigger the query refresh - next midnight
time_t now = time(0); time_t now = time(0);
time_t nextMidnight = now + 60 * 60 * 24; time_t nextMidnight = now + 60 * 60 * 24;
@@ -399,37 +409,40 @@ bool
BQueryPoseView::ActiveOnDevice(dev_t device) const BQueryPoseView::ActiveOnDevice(dev_t device) const
{ {
int32 count = fQueryList->CountItems(); int32 count = fQueryList->CountItems();
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++) {
if (fQueryList->ItemAt(index)->TargetDevice() == device) if (fQueryList->ItemAt(index)->TargetDevice() == device)
return true; return true;
}
return false; return false;
} }
// #pragma mark - // #pragma mark - QueryEntryListCollection
QueryEntryListCollection::QueryEntryListCollection(Model* model, QueryEntryListCollection::QueryEntryListCollection(Model* model,
BHandler* target, PoseList* oldPoseList) BHandler* target, PoseList* oldPoseList)
: fQueryListRep(new QueryListRep(new BObjectList<BQuery>(5, true))) :
fQueryListRep(new QueryListRep(new BObjectList<BQuery>(5, true)))
{ {
Rewind(); Rewind();
attr_info info; attr_info info;
BQuery query; BQuery query;
if (!model->Node()) { BNode* modelNode = model->Node();
if (modelNode == NULL) {
fStatus = B_ERROR; fStatus = B_ERROR;
return; return;
} }
// read the actual query string // read the actual query string
fStatus = model->Node()->GetAttrInfo(kAttrQueryString, &info); fStatus = modelNode->GetAttrInfo(kAttrQueryString, &info);
if (fStatus != B_OK) if (fStatus != B_OK)
return; return;
BString buffer; BString buffer;
if (model->Node()->ReadAttr(kAttrQueryString, B_STRING_TYPE, 0, if (modelNode->ReadAttr(kAttrQueryString, B_STRING_TYPE, 0,
buffer.LockBuffer((int32)info.size), buffer.LockBuffer((int32)info.size),
(size_t)info.size) != info.size) { (size_t)info.size) != info.size) {
fStatus = B_ERROR; fStatus = B_ERROR;
@@ -440,7 +453,7 @@ QueryEntryListCollection::QueryEntryListCollection(Model* model,
// read the extra options // read the extra options
MoreOptionsStruct saveMoreOptions; MoreOptionsStruct saveMoreOptions;
if (ReadAttr(model->Node(), kAttrQueryMoreOptions, if (ReadAttr(modelNode, kAttrQueryMoreOptions,
kAttrQueryMoreOptionsForeign, B_RAW_TYPE, 0, &saveMoreOptions, kAttrQueryMoreOptionsForeign, B_RAW_TYPE, 0, &saveMoreOptions,
sizeof(MoreOptionsStruct), sizeof(MoreOptionsStruct),
&MoreOptionsStruct::EndianSwap) != kReadAttrFailed) { &MoreOptionsStruct::EndianSwap) != kReadAttrFailed) {
@@ -455,7 +468,7 @@ QueryEntryListCollection::QueryEntryListCollection(Model* model,
fQueryListRep->fRefreshEveryHour = false; fQueryListRep->fRefreshEveryHour = false;
fQueryListRep->fRefreshEveryMinute = false; fQueryListRep->fRefreshEveryMinute = false;
if (model->Node()->ReadAttr(kAttrDynamicDateQuery, B_BOOL_TYPE, 0, if (modelNode->ReadAttr(kAttrDynamicDateQuery, B_BOOL_TYPE, 0,
&fQueryListRep->fDynamicDateQuery, &fQueryListRep->fDynamicDateQuery,
sizeof(bool)) != sizeof(bool)) { sizeof(bool)) != sizeof(bool)) {
fQueryListRep->fDynamicDateQuery = false; fQueryListRep->fDynamicDateQuery = false;
@@ -481,13 +494,12 @@ QueryEntryListCollection::QueryEntryListCollection(Model* model,
status_t result = B_OK; status_t result = B_OK;
// get volumes to perform query on // get volumes to perform query on
if (model->Node()->GetAttrInfo(kAttrQueryVolume, &info) == B_OK) { if (modelNode->GetAttrInfo(kAttrQueryVolume, &info) == B_OK) {
char* buffer = NULL; char* buffer = NULL;
if ((buffer = (char*)malloc((size_t)info.size)) != NULL if ((buffer = (char*)malloc((size_t)info.size)) != NULL
&& model->Node()->ReadAttr(kAttrQueryVolume, B_MESSAGE_TYPE, 0, && modelNode->ReadAttr(kAttrQueryVolume, B_MESSAGE_TYPE, 0,
buffer, (size_t)info.size) == info.size) { buffer, (size_t)info.size) == info.size) {
BMessage message; BMessage message;
if (message.Unflatten(buffer) == B_OK) { if (message.Unflatten(buffer) == B_OK) {
for (int32 index = 0; ;index++) { for (int32 index = 0; ;index++) {
@@ -533,6 +545,7 @@ QueryEntryListCollection::QueryEntryListCollection(Model* model,
} }
fStatus = B_OK; fStatus = B_OK;
return; return;
} }
@@ -582,9 +595,13 @@ QueryEntryListCollection::Clone()
} }
// #pragma mark - QueryEntryListCollection
QueryEntryListCollection::QueryEntryListCollection( QueryEntryListCollection::QueryEntryListCollection(
const QueryEntryListCollection &cloneThis) const QueryEntryListCollection &cloneThis)
: EntryListBase(), :
EntryListBase(),
fQueryListRep(cloneThis.fQueryListRep) fQueryListRep(cloneThis.fQueryListRep)
{ {
// only to be used by the Clone routine // only to be used by the Clone routine
@@ -608,11 +625,12 @@ QueryEntryListCollection::GetNextEntry(BEntry* entry, bool traverse)
fQueryListRep->fQueryListIndex < count; fQueryListRep->fQueryListIndex < count;
fQueryListRep->fQueryListIndex++) { fQueryListRep->fQueryListIndex++) {
result = fQueryListRep->fQueryList-> result = fQueryListRep->fQueryList->
ItemAt(fQueryListRep->fQueryListIndex) ItemAt(fQueryListRep->fQueryListIndex)->
->GetNextEntry(entry, traverse); GetNextEntry(entry, traverse);
if (result == B_OK) if (result == B_OK)
break; break;
} }
return result; return result;
} }
@@ -626,13 +644,13 @@ QueryEntryListCollection::GetNextDirents(struct dirent* buffer, size_t length,
for (int32 queryCount = fQueryListRep->fQueryList->CountItems(); for (int32 queryCount = fQueryListRep->fQueryList->CountItems();
fQueryListRep->fQueryListIndex < queryCount; fQueryListRep->fQueryListIndex < queryCount;
fQueryListRep->fQueryListIndex++) { fQueryListRep->fQueryListIndex++) {
result = fQueryListRep->fQueryList-> result = fQueryListRep->fQueryList->
ItemAt(fQueryListRep->fQueryListIndex)->GetNextDirents(buffer, ItemAt(fQueryListRep->fQueryListIndex)->
length, count); GetNextDirents(buffer, length, count);
if (result > 0) if (result > 0)
break; break;
} }
return result; return result;
} }
+1
View File
@@ -181,4 +181,5 @@ private:
using namespace BPrivate; using namespace BPrivate;
#endif // _QUERY_POSE_VIEW_H #endif // _QUERY_POSE_VIEW_H