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