Tracker: style fixes to Model class

This commit is contained in:
John Scipione
2014-06-20 21:02:01 -04:00
parent 40ef04f38e
commit c8d910f76b
2 changed files with 217 additions and 179 deletions
+51 -15
View File
@@ -38,6 +38,9 @@ All rights reserved.
// Consider moving iconFrom logic to BPose // Consider moving iconFrom logic to BPose
// use a more efficient way of storing file type and preferred app strings // use a more efficient way of storing file type and preferred app strings
#include "Model.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -60,8 +63,6 @@ All rights reserved.
#include <Volume.h> #include <Volume.h>
#include <VolumeRoster.h> #include <VolumeRoster.h>
#include "Model.h"
#include "Attributes.h" #include "Attributes.h"
#include "Bitmaps.h" #include "Bitmaps.h"
#include "FindPanel.h" #include "FindPanel.h"
@@ -71,23 +72,29 @@ All rights reserved.
#include "Tracker.h" #include "Tracker.h"
#include "Utilities.h" #include "Utilities.h"
#ifdef CHECK_OPEN_MODEL_LEAKS #ifdef CHECK_OPEN_MODEL_LEAKS
BObjectList<Model>* writableOpenModelList = NULL; BObjectList<Model>* writableOpenModelList = NULL;
BObjectList<Model>* readOnlyOpenModelList = NULL; BObjectList<Model>* readOnlyOpenModelList = NULL;
#endif #endif
namespace BPrivate { namespace BPrivate {
extern extern
#ifdef _IMPEXP_BE #ifdef _IMPEXP_BE
_IMPEXP_BE _IMPEXP_BE
#endif #endif
bool CheckNodeIconHintPrivate(const BNode*, bool); bool CheckNodeIconHintPrivate(const BNode*, bool);
} } // namespace BPrivate
// #pragma mark - Model()
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Model" #define B_TRANSLATION_CONTEXT "Model"
Model::Model() Model::Model()
: :
fPreferredAppName(NULL), fPreferredAppName(NULL),
@@ -362,6 +369,9 @@ Model::Name() const
case kDesktopNode: case kDesktopNode:
return B_TRANSLATE_NOCOLLECT(kDesktopNodeName); return B_TRANSLATE_NOCOLLECT(kDesktopNodeName);
default:
break;
} }
if (fHasLocalizedName && gLocalizedNamePreferred) if (fHasLocalizedName && gLocalizedNamePreferred)
@@ -378,6 +388,7 @@ Model::OpenNode(bool writable)
return B_OK; return B_OK;
OpenNodeCommon(writable); OpenNodeCommon(writable);
return fStatus; return fStatus;
} }
@@ -399,6 +410,7 @@ Model::UpdateStatAndOpenNode(bool writable)
return fStatus; return fStatus;
OpenNodeCommon(writable); OpenNodeCommon(writable);
return fStatus; return fStatus;
} }
@@ -605,7 +617,8 @@ Model::FinishSettingUpType()
// disk again for models that do not have an icon defined by the node // disk again for models that do not have an icon defined by the node
if (IsNodeOpen() if (IsNodeOpen()
&& fBaseType != kLinkNode && fBaseType != kLinkNode
&& !CheckNodeIconHintPrivate(fNode, dynamic_cast<TTracker*>(be_app) == NULL) && !CheckNodeIconHintPrivate(fNode,
dynamic_cast<TTracker*>(be_app) == NULL)
&& !HasVectorIconHint(fNode)) { && !HasVectorIconHint(fNode)) {
// when checking for the node icon hint, if we are libtracker, // when checking for the node icon hint, if we are libtracker,
// only check for small icons - checking for the large icons // only check for small icons - checking for the large icons
@@ -691,7 +704,7 @@ Model::FinishSettingUpType()
char name[B_FILE_NAME_LENGTH]; char name[B_FILE_NAME_LENGTH];
BVolume volume(NodeRef()->device); BVolume volume(NodeRef()->device);
if (volume.InitCheck() == B_OK && volume.GetName(name) == B_OK) { if (volume.InitCheck() == B_OK && volume.GetName(name) == B_OK) {
if (fVolumeName) if (fVolumeName != NULL)
DeletePreferredAppVolumeNameLinkTo(); DeletePreferredAppVolumeNameLinkTo();
fVolumeName = strdup(name); fVolumeName = strdup(name);
@@ -834,13 +847,15 @@ Model::GetPreferredAppForBrokenSymLink(BString &result)
= info.GetPreferredApp(result.LockBuffer(B_MIME_TYPE_LENGTH)); = info.GetPreferredApp(result.LockBuffer(B_MIME_TYPE_LENGTH));
result.UnlockBuffer(); result.UnlockBuffer();
if (error != B_OK) if (error != B_OK) {
// Tracker will have to do // Tracker will have to do
result = kTrackerSignature; result = kTrackerSignature;
} }
}
// Node monitor updating stuff // #pragma mark - Node monitor updating methods
void void
Model::UpdateEntryRef(const node_ref* dirNode, const char* name) Model::UpdateEntryRef(const node_ref* dirNode, const char* name)
@@ -949,7 +964,9 @@ Model::StatChanged()
return false; return false;
} }
// Mime handling stuff
// #pragma mark - Mime handling methods
bool bool
Model::IsDropTarget(const Model* forDocument, bool traverse) const Model::IsDropTarget(const Model* forDocument, bool traverse) const
@@ -964,7 +981,8 @@ Model::IsDropTarget(const Model* forDocument, bool traverse) const
default: default:
break; break;
} }
if (!forDocument)
if (forDocument == NULL)
return true; return true;
if (traverse) { if (traverse) {
@@ -983,9 +1001,10 @@ Model::IsDropTarget(const Model* forDocument, bool traverse) const
return SupportsMimeType(mimeType, 0) != kDoesNotSupportType; return SupportsMimeType(mimeType, 0) != kDoesNotSupportType;
} }
// do some mime-based matching // do some mime-based matching
const char* documentMimeType = forDocument->MimeType(); const char* documentMimeType = forDocument->MimeType();
if (!documentMimeType) if (documentMimeType == NULL)
return false; return false;
return SupportsMimeType(documentMimeType, 0) != kDoesNotSupportType; return SupportsMimeType(documentMimeType, 0) != kDoesNotSupportType;
@@ -995,11 +1014,11 @@ Model::IsDropTarget(const Model* forDocument, bool traverse) const
Model::CanHandleResult Model::CanHandleResult
Model::CanHandleDrops() const Model::CanHandleDrops() const
{ {
if (IsDirectory()) if (IsDirectory()) {
// directories take anything // directories take anything
// resolve permissions here // resolve permissions here
return kCanHandle; return kCanHandle;
}
if (IsSymLink()) { if (IsSymLink()) {
// descend into symlink and try again on it's target // descend into symlink and try again on it's target
@@ -1039,6 +1058,7 @@ enum {
kMatch kMatch
}; };
static int32 static int32
MatchMimeTypeString(/*const */BString* documentType, const char* handlerType) MatchMimeTypeString(/*const */BString* documentType, const char* handlerType)
{ {
@@ -1050,9 +1070,10 @@ MatchMimeTypeString(/*const */BString* documentType, const char* handlerType)
int32 supertypeOnlyLength = 0; int32 supertypeOnlyLength = 0;
const char* tmp = strstr(handlerType, "/"); const char* tmp = strstr(handlerType, "/");
if (!tmp) if (tmp == NULL) {
// no subtype - supertype string only // no subtype - supertype string only
supertypeOnlyLength = (int32)strlen(handlerType); supertypeOnlyLength = (int32)strlen(handlerType);
}
if (supertypeOnlyLength) { if (supertypeOnlyLength) {
// compare just the supertype // compare just the supertype
@@ -1089,8 +1110,8 @@ Model::SupportsMimeType(const char* type, const BObjectList<BString>* list,
return kDoesNotSupportType; return kDoesNotSupportType;
for (int32 index = 0; ; index++) { for (int32 index = 0; ; index++) {
// check if this model lists the type of dropped document as supported // check if this model lists the type of dropped document as supported
const char* mimeSignature; const char* mimeSignature;
ssize_t bufferLength; ssize_t bufferLength;
@@ -1109,7 +1130,7 @@ Model::SupportsMimeType(const char* type, const BObjectList<BString>* list,
int32 match; int32 match;
if (type || (list != NULL && list->IsEmpty())) { if (type != NULL || (list != NULL && list->IsEmpty())) {
BString typeString(type); BString typeString(type);
match = MatchMimeTypeString(&typeString, mimeSignature); match = MatchMimeTypeString(&typeString, mimeSignature);
} else { } else {
@@ -1148,6 +1169,7 @@ Model::IsDropTargetForList(const BObjectList<BString>* list) const
default: default:
break; break;
} }
return SupportsMimeType(0, list) != kDoesNotSupportType; return SupportsMimeType(0, list) != kDoesNotSupportType;
} }
@@ -1284,6 +1306,7 @@ Model::GetVersionString(BString &result, version_kind kind)
sprintf(vstr, "%" B_PRId32 ".%" B_PRId32 ".%" B_PRId32, version.major, sprintf(vstr, "%" B_PRId32 ".%" B_PRId32 ".%" B_PRId32, version.major,
version.middle, version.minor); version.middle, version.minor);
result = vstr; result = vstr;
return B_OK; return B_OK;
} }
@@ -1359,30 +1382,41 @@ Model::PrintToStream(int32 level, bool deep)
case kUnknownSource: case kUnknownSource:
PRINT(("unknown\n")); PRINT(("unknown\n"));
break; break;
case kUnknownNotFromNode: case kUnknownNotFromNode:
PRINT(("unknown but not from a node\n")); PRINT(("unknown but not from a node\n"));
break; break;
case kTrackerDefault: case kTrackerDefault:
PRINT(("tracker default\n")); PRINT(("tracker default\n"));
break; break;
case kTrackerSupplied: case kTrackerSupplied:
PRINT(("tracker supplied\n")); PRINT(("tracker supplied\n"));
break; break;
case kMetaMime: case kMetaMime:
PRINT(("metamime\n")); PRINT(("metamime\n"));
break; break;
case kPreferredAppForType: case kPreferredAppForType:
PRINT(("preferred app for type\n")); PRINT(("preferred app for type\n"));
break; break;
case kPreferredAppForNode: case kPreferredAppForNode:
PRINT(("preferred app for node\n")); PRINT(("preferred app for node\n"));
break; break;
case kNode: case kNode:
PRINT(("node\n")); PRINT(("node\n"));
break; break;
case kVolume: case kVolume:
PRINT(("volume\n")); PRINT(("volume\n"));
break; break;
default:
break;
} }
PRINT(("model %s opened %s \n", !IsNodeOpen() ? "not " : "", PRINT(("model %s opened %s \n", !IsNodeOpen() ? "not " : "",
@@ -1497,6 +1531,7 @@ Model::TrackIconSource(icon_size size)
#ifdef CHECK_OPEN_MODEL_LEAKS #ifdef CHECK_OPEN_MODEL_LEAKS
namespace BPrivate { namespace BPrivate {
#include <stdio.h> #include <stdio.h>
void void
@@ -1514,6 +1549,7 @@ DumpOpenModels(bool extensive)
printf("%s\n", readOnlyOpenModelList->ItemAt(index)->Name()); printf("%s\n", readOnlyOpenModelList->ItemAt(index)->Name());
} }
} }
if (writableOpenModelList) { if (writableOpenModelList) {
int32 count = writableOpenModelList->CountItems(); int32 count = writableOpenModelList->CountItems();
printf("%ld models open writable:\n", count); printf("%ld models open writable:\n", count);
+6 -4
View File
@@ -31,11 +31,10 @@ of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders. names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
#ifndef _NU_MODEL_H
#define _NU_MODEL_H
// Dedicated to BModel // Dedicated to BModel
#ifndef _NU_MODEL_H
#define _NU_MODEL_H
#include <AppFileInfo.h> #include <AppFileInfo.h>
@@ -53,6 +52,7 @@ class BHandler;
class BEntry; class BEntry;
class BQuery; class BQuery;
#if __GNUC__ && __GNUC__ < 3 #if __GNUC__ && __GNUC__ < 3
// using std::stat instead of just stat here because of what // using std::stat instead of just stat here because of what
// seems to be a gcc bug involving namespace and struct stat interaction // seems to be a gcc bug involving namespace and struct stat interaction
@@ -63,6 +63,7 @@ typedef struct std::stat StatStruct;
typedef struct stat StatStruct; typedef struct stat StatStruct;
#endif #endif
namespace BPrivate { namespace BPrivate {
enum { enum {
@@ -115,7 +116,7 @@ class Model {
const StatStruct* StatBuf() const; const StatStruct* StatBuf() const;
BNode* Node() const; BNode* Node() const;
// returns null if not Open // returns NULL if not open
void GetPath(BPath*) const; void GetPath(BPath*) const;
void GetEntry(BEntry*) const; void GetEntry(BEntry*) const;
@@ -544,4 +545,5 @@ ModelNodeLazyOpener::OpenNode(bool writable)
} // namespace BPrivate } // namespace BPrivate
#endif // _NU_MODEL_H #endif // _NU_MODEL_H