* Added "sortInodes" parameter to CachedEntryIteratorList constructor.
* Moved static CompareInode() to CachedEntryIterator::_CompareInodes(). * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27869 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -43,23 +43,28 @@ All rights reserved.
|
||||
#include "NodeWalker.h"
|
||||
#include "ObjectList.h"
|
||||
|
||||
|
||||
TWalkerWrapper::TWalkerWrapper(WALKER_NS::TWalker *walker)
|
||||
: fWalker(walker),
|
||||
fStatus(B_OK)
|
||||
:
|
||||
fWalker(walker),
|
||||
fStatus(B_OK)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TWalkerWrapper::~TWalkerWrapper()
|
||||
{
|
||||
delete fWalker;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TWalkerWrapper::InitCheck() const
|
||||
{
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TWalkerWrapper::GetNextEntry(BEntry *entry, bool traverse)
|
||||
{
|
||||
@@ -67,6 +72,7 @@ TWalkerWrapper::GetNextEntry(BEntry *entry, bool traverse)
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TWalkerWrapper::GetNextRef(entry_ref *ref)
|
||||
{
|
||||
@@ -74,55 +80,70 @@ TWalkerWrapper::GetNextRef(entry_ref *ref)
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
TWalkerWrapper::GetNextDirents(struct dirent *buffer, size_t length, int32 count)
|
||||
TWalkerWrapper::GetNextDirents(struct dirent *buffer, size_t length,
|
||||
int32 count)
|
||||
{
|
||||
int32 result = fWalker->GetNextDirents(buffer, length, count);
|
||||
fStatus = result < 0 ? result : (result ? B_OK : B_ENTRY_NOT_FOUND);
|
||||
fStatus = result < B_OK ? result : (result ? B_OK : B_ENTRY_NOT_FOUND);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TWalkerWrapper::Rewind()
|
||||
{
|
||||
return fWalker->Rewind();
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
TWalkerWrapper::CountEntries()
|
||||
{
|
||||
return fWalker->CountEntries();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
EntryListBase::EntryListBase()
|
||||
: fStatus(B_OK)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EntryListBase::InitCheck() const
|
||||
{
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
dirent *
|
||||
EntryListBase::Next(dirent *ent)
|
||||
{
|
||||
return (dirent *)((char *)ent + ent->d_reclen + sizeof(dirent));
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
CachedEntryIterator::CachedEntryIterator(BEntryList *iterator, int32 numEntries,
|
||||
bool sortInodes)
|
||||
: fIterator(iterator),
|
||||
fEntryRefBuffer(NULL),
|
||||
fCacheSize(numEntries),
|
||||
fNumEntries(0),
|
||||
fIndex(0),
|
||||
fDirentBuffer(NULL),
|
||||
fCurrentDirent(NULL),
|
||||
fSortInodes(sortInodes),
|
||||
fSortedList(NULL),
|
||||
fEntryBuffer(NULL)
|
||||
bool sortInodes)
|
||||
:
|
||||
fIterator(iterator),
|
||||
fEntryRefBuffer(NULL),
|
||||
fCacheSize(numEntries),
|
||||
fNumEntries(0),
|
||||
fIndex(0),
|
||||
fDirentBuffer(NULL),
|
||||
fCurrentDirent(NULL),
|
||||
fSortInodes(sortInodes),
|
||||
fSortedList(NULL),
|
||||
fEntryBuffer(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -135,6 +156,7 @@ CachedEntryIterator::~CachedEntryIterator()
|
||||
delete [] fEntryBuffer;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
CachedEntryIterator::GetNextEntry(BEntry *result, bool traverse)
|
||||
{
|
||||
@@ -158,14 +180,16 @@ CachedEntryIterator::GetNextEntry(BEntry *result, bool traverse)
|
||||
fIndex = 0;
|
||||
}
|
||||
*result = fEntryBuffer[fIndex++];
|
||||
if (fIndex > fNumEntries)
|
||||
if (fIndex > fNumEntries) {
|
||||
// we are at the end of the cache we loaded up, time to return
|
||||
// an error, if we had one
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
CachedEntryIterator::GetNextRef(entry_ref *ref)
|
||||
{
|
||||
@@ -198,17 +222,18 @@ CachedEntryIterator::GetNextRef(entry_ref *ref)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
CompareInode(const dirent *ent1, const dirent *ent2)
|
||||
/*static*/ int
|
||||
CachedEntryIterator::_CompareInodes(const dirent *ent1, const dirent *ent2)
|
||||
{
|
||||
if (ent1->d_ino < ent2->d_ino)
|
||||
return -1;
|
||||
else if (ent1->d_ino == ent2->d_ino)
|
||||
if (ent1->d_ino == ent2->d_ino)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
CachedEntryIterator::GetNextDirents(struct dirent *ent, size_t size,
|
||||
int32 count)
|
||||
@@ -236,14 +261,17 @@ CachedEntryIterator::GetNextDirents(struct dirent *ent, size_t size,
|
||||
|
||||
fNumEntries += count;
|
||||
|
||||
int32 currentDirentSize = fCurrentDirent->d_reclen + (ssize_t)sizeof(dirent);
|
||||
int32 currentDirentSize = fCurrentDirent->d_reclen
|
||||
+ (ssize_t)sizeof(dirent);
|
||||
bufferRemain -= currentDirentSize;
|
||||
if (bufferRemain < (sizeof(dirent) + B_FILE_NAME_LENGTH))
|
||||
if (bufferRemain < (sizeof(dirent) + B_FILE_NAME_LENGTH)) {
|
||||
// cant fit a big entryRef in the buffer, just bail
|
||||
// and start from scratch
|
||||
break;
|
||||
}
|
||||
|
||||
fCurrentDirent = (dirent *)((char *)fCurrentDirent + currentDirentSize);
|
||||
fCurrentDirent
|
||||
= (dirent *)((char *)fCurrentDirent + currentDirentSize);
|
||||
}
|
||||
fCurrentDirent = fDirentBuffer;
|
||||
if (fSortInodes) {
|
||||
@@ -256,14 +284,15 @@ CachedEntryIterator::GetNextDirents(struct dirent *ent, size_t size,
|
||||
fSortedList->AddItem(fCurrentDirent, 0);
|
||||
fCurrentDirent = Next(fCurrentDirent);
|
||||
}
|
||||
fSortedList->SortItems(CompareInode);
|
||||
fSortedList->SortItems(&_CompareInodes);
|
||||
fCurrentDirent = fDirentBuffer;
|
||||
}
|
||||
fIndex = 0;
|
||||
}
|
||||
if (fIndex >= fNumEntries)
|
||||
if (fIndex >= fNumEntries) {
|
||||
// we are done, no more dirents left
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fSortInodes)
|
||||
fCurrentDirent = fSortedList->ItemAt(fIndex);
|
||||
@@ -282,6 +311,7 @@ CachedEntryIterator::GetNextDirents(struct dirent *ent, size_t size,
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
CachedEntryIterator::Rewind()
|
||||
{
|
||||
@@ -296,12 +326,14 @@ CachedEntryIterator::Rewind()
|
||||
return fIterator->Rewind();
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
CachedEntryIterator::CountEntries()
|
||||
{
|
||||
return fIterator->CountEntries();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CachedEntryIterator::SetTo(BEntryList *iterator)
|
||||
{
|
||||
@@ -311,25 +343,35 @@ CachedEntryIterator::SetTo(BEntryList *iterator)
|
||||
fIterator = iterator;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
CachedDirectoryEntryList::CachedDirectoryEntryList(const BDirectory &dir)
|
||||
: CachedEntryIterator(0, 40, true),
|
||||
fDir(dir)
|
||||
: CachedEntryIterator(0, 40, true),
|
||||
fDir(dir)
|
||||
{
|
||||
fStatus = fDir.InitCheck();
|
||||
SetTo(&fDir);
|
||||
}
|
||||
|
||||
|
||||
CachedDirectoryEntryList::~CachedDirectoryEntryList()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
DirectoryEntryList::DirectoryEntryList(const BDirectory &dir)
|
||||
: fDir(dir)
|
||||
:
|
||||
fDir(dir)
|
||||
{
|
||||
fStatus = fDir.InitCheck();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DirectoryEntryList::GetNextEntry(BEntry *entry, bool traverse)
|
||||
{
|
||||
@@ -337,6 +379,7 @@ DirectoryEntryList::GetNextEntry(BEntry *entry, bool traverse)
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DirectoryEntryList::GetNextRef(entry_ref *ref)
|
||||
{
|
||||
@@ -344,6 +387,7 @@ DirectoryEntryList::GetNextRef(entry_ref *ref)
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
DirectoryEntryList::GetNextDirents(struct dirent *buffer, size_t length,
|
||||
int32 count)
|
||||
@@ -352,6 +396,7 @@ DirectoryEntryList::GetNextDirents(struct dirent *buffer, size_t length,
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DirectoryEntryList::Rewind()
|
||||
{
|
||||
@@ -359,6 +404,7 @@ DirectoryEntryList::Rewind()
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
DirectoryEntryList::CountEntries()
|
||||
{
|
||||
@@ -366,12 +412,17 @@ DirectoryEntryList::CountEntries()
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
EntryIteratorList::EntryIteratorList()
|
||||
: fList(5, true),
|
||||
fCurrentIndex(0)
|
||||
:
|
||||
fList(5, true),
|
||||
fCurrentIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EntryIteratorList::~EntryIteratorList()
|
||||
{
|
||||
int32 count = fList.CountItems();
|
||||
@@ -394,10 +445,11 @@ EntryIteratorList::AddItem(BEntryList *walker)
|
||||
fList.AddItem(walker);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EntryIteratorList::GetNextEntry(BEntry *entry, bool traverse)
|
||||
{
|
||||
for (;;) {
|
||||
while (true) {
|
||||
if (fCurrentIndex >= fList.CountItems()) {
|
||||
fStatus = B_ENTRY_NOT_FOUND;
|
||||
break;
|
||||
@@ -412,10 +464,11 @@ EntryIteratorList::GetNextEntry(BEntry *entry, bool traverse)
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EntryIteratorList::GetNextRef(entry_ref *ref)
|
||||
{
|
||||
for (;;) {
|
||||
while (true) {
|
||||
if (fCurrentIndex >= fList.CountItems()) {
|
||||
fStatus = B_ENTRY_NOT_FOUND;
|
||||
break;
|
||||
@@ -430,17 +483,20 @@ EntryIteratorList::GetNextRef(entry_ref *ref)
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
EntryIteratorList::GetNextDirents(struct dirent *buffer, size_t length, int32 count)
|
||||
EntryIteratorList::GetNextDirents(struct dirent *buffer, size_t length,
|
||||
int32 count)
|
||||
{
|
||||
int32 result = 0;
|
||||
for (;;) {
|
||||
while (true) {
|
||||
if (fCurrentIndex >= fList.CountItems()) {
|
||||
fStatus = B_ENTRY_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
|
||||
result = fList.ItemAt(fCurrentIndex)->GetNextDirents(buffer, length, count);
|
||||
result = fList.ItemAt(fCurrentIndex)->GetNextDirents(buffer, length,
|
||||
count);
|
||||
if (result > 0) {
|
||||
fStatus = B_OK;
|
||||
break;
|
||||
@@ -451,6 +507,7 @@ EntryIteratorList::GetNextDirents(struct dirent *buffer, size_t length, int32 co
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
EntryIteratorList::Rewind()
|
||||
{
|
||||
@@ -462,6 +519,7 @@ EntryIteratorList::Rewind()
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
EntryIteratorList::CountEntries()
|
||||
{
|
||||
@@ -475,13 +533,17 @@ EntryIteratorList::CountEntries()
|
||||
}
|
||||
|
||||
|
||||
CachedEntryIteratorList::CachedEntryIteratorList()
|
||||
: CachedEntryIterator(0, 10, true)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
CachedEntryIteratorList::CachedEntryIteratorList(bool sortInodes)
|
||||
: CachedEntryIterator(NULL, 10, sortInodes)
|
||||
{
|
||||
fStatus = B_OK;
|
||||
SetTo(&fIteratorList);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CachedEntryIteratorList::AddItem(BEntryList *walker)
|
||||
{
|
||||
|
||||
@@ -117,6 +117,8 @@ public:
|
||||
// CachedEntryIterator does not get to own the <iterator>
|
||||
|
||||
private:
|
||||
static int _CompareInodes(const dirent *ent1, const dirent *ent2);
|
||||
|
||||
BEntryList *fIterator;
|
||||
entry_ref *fEntryRefBuffer;
|
||||
int32 fCacheSize;
|
||||
@@ -185,8 +187,8 @@ protected:
|
||||
|
||||
class CachedEntryIteratorList : public CachedEntryIterator {
|
||||
public:
|
||||
CachedEntryIteratorList();
|
||||
void AddItem(BEntryList *);
|
||||
CachedEntryIteratorList(bool sortInodes = true);
|
||||
void AddItem(BEntryList *list);
|
||||
|
||||
protected:
|
||||
EntryIteratorList fIteratorList;
|
||||
|
||||
@@ -566,8 +566,7 @@ AddSupportingAppForTypeToQuery(SearchForSignatureEntryList *queryIterator,
|
||||
static const entry_ref *
|
||||
AddOneRefSignatures(const entry_ref *ref, void *castToIterator)
|
||||
{
|
||||
// ToDo:
|
||||
// resolve cases where each entry has a different type and
|
||||
// TODO: resolve cases where each entry has a different type and
|
||||
// their supporting apps are disjoint sets
|
||||
|
||||
SearchForSignatureEntryList *queryIterator =
|
||||
@@ -684,7 +683,6 @@ OpenWithPoseView::OpenSelection(BPose *pose, int32 *)
|
||||
// publishers to fix up sniffers
|
||||
}
|
||||
|
||||
|
||||
BMessage message(*window->EntryList());
|
||||
// make a clone to send
|
||||
message.RemoveName("launchUsingSelector");
|
||||
@@ -787,22 +785,25 @@ OpenWithPoseView::CreatePoses(Model **models, PoseInfo *poseInfoArray, int32 cou
|
||||
_inherited::CreatePoses(models, poseInfoArray, count, resultingPoses, insertionSort,
|
||||
lastPoseIndexPtr, boundsPtr, forceDraw);
|
||||
|
||||
if (resultingPoses)
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if (resultingPoses) {
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
if (resultingPoses[index] && fHaveCommonPreferredApp
|
||||
&& *(models[index]->EntryRef()) == fPreferredRef)
|
||||
&& *(models[index]->EntryRef()) == fPreferredRef) {
|
||||
// this is our preferred app, select it's pose
|
||||
SelectPose(resultingPoses[index], IndexOfPose(resultingPoses[index]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OpenWithPoseView::KeyDown(const char *bytes, int32 count)
|
||||
{
|
||||
if (bytes[0] == B_TAB)
|
||||
if (bytes[0] == B_TAB) {
|
||||
// just shift the focus, don't tab to the next pose
|
||||
BView::KeyDown(bytes, count);
|
||||
else
|
||||
} else
|
||||
_inherited::KeyDown(bytes, count);
|
||||
}
|
||||
|
||||
@@ -1442,40 +1443,40 @@ SearchForSignatureEntryList::RelationDescription(const BMessage *entriesToOpen,
|
||||
return;
|
||||
|
||||
case kSupportsSupertype:
|
||||
{
|
||||
mimeType.SetTo(model.MimeType());
|
||||
// status_t result = mimeType.GetSupertype(&mimeType);
|
||||
{
|
||||
mimeType.SetTo(model.MimeType());
|
||||
// status_t result = mimeType.GetSupertype(&mimeType);
|
||||
|
||||
char *type = (char *)mimeType.Type();
|
||||
char *tmp = strchr(type, '/');
|
||||
if (tmp)
|
||||
*tmp = '\0';
|
||||
char *type = (char *)mimeType.Type();
|
||||
char *tmp = strchr(type, '/');
|
||||
if (tmp)
|
||||
*tmp = '\0';
|
||||
|
||||
//PRINT(("getting supertype for %s, result %s, got %s\n",
|
||||
// model.MimeType(), strerror(result), mimeType.Type()));
|
||||
*description = "Handles any ";
|
||||
// *description += mimeType.Type();
|
||||
*description += type;
|
||||
return;
|
||||
}
|
||||
//PRINT(("getting supertype for %s, result %s, got %s\n",
|
||||
// model.MimeType(), strerror(result), mimeType.Type()));
|
||||
*description = "Handles any ";
|
||||
// *description += mimeType.Type();
|
||||
*description += type;
|
||||
return;
|
||||
}
|
||||
|
||||
case kSupportsType:
|
||||
{
|
||||
mimeType.SetTo(model.MimeType());
|
||||
{
|
||||
mimeType.SetTo(model.MimeType());
|
||||
|
||||
if (preferredApp && *applicationModel->EntryRef() == *preferredApp)
|
||||
// application matches cached preferred app, we are done
|
||||
*description = "Preferred for ";
|
||||
else
|
||||
*description = "Handles ";
|
||||
if (preferredApp && *applicationModel->EntryRef() == *preferredApp)
|
||||
// application matches cached preferred app, we are done
|
||||
*description = "Preferred for ";
|
||||
else
|
||||
*description = "Handles ";
|
||||
|
||||
char shortDescription[256];
|
||||
if (mimeType.GetShortDescription(shortDescription) == B_OK)
|
||||
*description += shortDescription;
|
||||
else
|
||||
*description += mimeType.Type();
|
||||
return;
|
||||
}
|
||||
char shortDescription[256];
|
||||
if (mimeType.GetShortDescription(shortDescription) == B_OK)
|
||||
*description += shortDescription;
|
||||
else
|
||||
*description += mimeType.Type();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1628,7 +1629,8 @@ ConditionalAllAppsIterator::GetNextRef(entry_ref *ref)
|
||||
|
||||
|
||||
int32
|
||||
ConditionalAllAppsIterator::GetNextDirents(struct dirent *buffer, size_t length, int32 count)
|
||||
ConditionalAllAppsIterator::GetNextDirents(struct dirent *buffer, size_t length,
|
||||
int32 count)
|
||||
{
|
||||
if (!Iterate())
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user