* Cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34442 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-12-02 11:42:49 +00:00
parent fc7864091e
commit a8af8078a4
+399 -422
View File
@@ -87,428 +87,6 @@ const char *kAttrNickname = "META:nickname";
const char *kNetPositiveSignature = "application/x-vnd.Be-NPOS"; const char *kNetPositiveSignature = "application/x-vnd.Be-NPOS";
const char *kPeopleSignature = "application/x-vnd.Be-PEPL"; const char *kPeopleSignature = "application/x-vnd.Be-PEPL";
namespace BPrivate {
class ExtraAttributeLazyInstaller {
public:
ExtraAttributeLazyInstaller(const char *type);
~ExtraAttributeLazyInstaller();
bool AddExtraAttribute(const char *publicName, const char *name,
uint32 type, bool viewable, bool editable, float width,
int32 alignment, bool extra);
status_t InitCheck() const;
public:
BMimeType fMimeType;
BMessage fExtraAttrs;
bool fDirty;
};
}
ExtraAttributeLazyInstaller::ExtraAttributeLazyInstaller(const char *type)
: fMimeType(type),
fDirty(false)
{
if (fMimeType.InitCheck() == B_OK)
fMimeType.GetAttrInfo(&fExtraAttrs);
}
ExtraAttributeLazyInstaller::~ExtraAttributeLazyInstaller()
{
if (fMimeType.InitCheck() == B_OK && fDirty)
fMimeType.SetAttrInfo(&fExtraAttrs);
}
bool
ExtraAttributeLazyInstaller::AddExtraAttribute(const char *publicName, const char *name,
uint32 type, bool viewable, bool editable, float width, int32 alignment,
bool extra)
{
for (int32 index = 0; ; index++) {
const char *oldPublicName;
if (fExtraAttrs.FindString("attr:public_name", index, &oldPublicName) != B_OK)
break;
if (strcmp(oldPublicName, publicName) == 0)
// already got this extra atribute, no work left
return false;
}
fExtraAttrs.AddString("attr:public_name", publicName);
fExtraAttrs.AddString("attr:name", name);
fExtraAttrs.AddInt32("attr:type", (int32)type);
fExtraAttrs.AddBool("attr:viewable", viewable);
fExtraAttrs.AddBool("attr:editable", editable);
fExtraAttrs.AddInt32("attr:width", (int32)width);
fExtraAttrs.AddInt32("attr:alignment", alignment);
fExtraAttrs.AddBool("attr:extra", extra);
fDirty = true;
return true;
}
bool
TTracker::InstallMimeIfNeeded(const char *type, int32 bitsID,
const char *shortDescription, const char *longDescription,
const char *preferredAppSignature, uint32 forceMask)
{
// used by InitMimeTypes - checks if a metamime of a given <type> is
// installed and if it has all the specified attributes; if not, the
// whole mime type is installed and all attributes are set; nulls can
// be passed for attributes that don't matter; returns true if anything
// had to be changed
#ifndef __HAIKU__
# define B_BITMAP_NO_SERVER_LINK 0
#endif
#ifdef __HAIKU__
BBitmap vectorIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_RGBA32);
#endif
BBitmap largeIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
BBitmap miniIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
char tmp[B_MIME_TYPE_LENGTH];
BMimeType mime(type);
bool installed = mime.IsInstalled();
if (!installed
#ifdef __HAIKU__
|| (bitsID >= 0 && ((forceMask & kForceLargeIcon)
|| mime.GetIcon(&vectorIcon, B_LARGE_ICON) != B_OK))
#endif
|| (bitsID >= 0 && ((forceMask & kForceLargeIcon)
|| mime.GetIcon(&largeIcon, B_LARGE_ICON) != B_OK))
|| (bitsID >= 0 && ((forceMask & kForceMiniIcon)
|| mime.GetIcon(&miniIcon, B_MINI_ICON) != B_OK))
|| (shortDescription && ((forceMask & kForceShortDescription)
|| mime.GetShortDescription(tmp) != B_OK))
|| (longDescription && ((forceMask & kForceLongDescription)
|| mime.GetLongDescription(tmp) != B_OK))
|| (preferredAppSignature && ((forceMask & kForcePreferredApp)
|| mime.GetPreferredApp(tmp) != B_OK))) {
if (!installed)
mime.Install();
if (bitsID >= 0) {
#ifdef __HAIKU__
const uint8* iconData;
size_t iconSize;
if (GetTrackerResources()->
GetIconResource(bitsID, &iconData, &iconSize) == B_OK)
mime.SetIcon(iconData, iconSize);
#endif
if (GetTrackerResources()->
GetIconResource(bitsID, B_LARGE_ICON, &largeIcon) == B_OK)
mime.SetIcon(&largeIcon, B_LARGE_ICON);
if (GetTrackerResources()->
GetIconResource(bitsID, B_MINI_ICON, &miniIcon) == B_OK)
mime.SetIcon(&miniIcon, B_MINI_ICON);
}
if (shortDescription)
mime.SetShortDescription(shortDescription);
if (longDescription)
mime.SetLongDescription(longDescription);
if (preferredAppSignature)
mime.SetPreferredApp(preferredAppSignature);
return true;
}
return false;
}
void
TTracker::InitMimeTypes()
{
InstallMimeIfNeeded(B_DIR_MIMETYPE, kResFolderIcon,
"Folder", "Folder container for file system items.", kTrackerSignature);
InstallMimeIfNeeded(B_APP_MIME_TYPE, kResAppIcon,
"Be Application", "Generic Be Application executable.", kTrackerSignature);
InstallMimeIfNeeded(B_FILE_MIMETYPE, kResFileIcon,
"Generic file", "Generic document file.", kTrackerSignature);
InstallMimeIfNeeded(B_VOLUME_MIMETYPE, kResHardDiskIcon,
"Be Volume", "Disk volume.", kTrackerSignature);
InstallMimeIfNeeded(B_QUERY_MIMETYPE, kResQueryIcon,
"Be Query", "Query to locate items on disks.", kTrackerSignature);
InstallMimeIfNeeded(B_QUERY_TEMPLATE_MIMETYPE, kResQueryTemplateIcon,
"Be Query Template", "", kTrackerSignature);
InstallMimeIfNeeded(B_LINK_MIMETYPE, kResBrokenLinkIcon,
"Symbolic Link", "Link to another item in the file system.", kTrackerSignature);
InstallMimeIfNeeded(B_ROOT_MIMETYPE, kResRootIcon,
"Be Root", "File system root.", kTrackerSignature);
InstallMimeIfNeeded(B_BOOKMARK_MIMETYPE, kResBookmarkIcon,
"Bookmark", "Bookmark for a web page.", kNetPositiveSignature);
{
// install a couple of extra fields for bookmark
ExtraAttributeLazyInstaller installer(B_BOOKMARK_MIMETYPE);
installer.AddExtraAttribute("URL", "META:url", B_STRING_TYPE, true, true,
170, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Keywords", "META:keyw", B_STRING_TYPE, true, true,
130, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Title", "META:title", B_STRING_TYPE, true, true,
130, B_ALIGN_LEFT, false);
}
InstallMimeIfNeeded(B_PERSON_MIMETYPE, kResPersonIcon,
"Person", "Contact information for a person.", kPeopleSignature);
{
ExtraAttributeLazyInstaller installer(B_PERSON_MIMETYPE);
installer.AddExtraAttribute("Contact Name", kAttrName, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Company", kAttrCompany, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Address", kAttrAddress, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("City", kAttrCity, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("State", kAttrState, B_STRING_TYPE, true, true,
50, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Zip", kAttrZip, B_STRING_TYPE, true, true,
50, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Country", kAttrCountry, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("E-mail", kAttrEmail, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Home Phone", kAttrHomePhone, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Work Phone", kAttrWorkPhone, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Fax", kAttrFax, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("URL", kAttrURL, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Group", kAttrGroup, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Nickname", kAttrNickname, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
}
InstallMimeIfNeeded(B_PRINTER_SPOOL_MIMETYPE, kResSpoolFileIcon,
"Printer spool", "Printer spool file.", "application/x-vnd.Be-PRNT");
{
#if B_BEOS_VERSION_DANO
ExtraAttributeLazyInstaller installer(B_PRINTER_SPOOL_MIMETYPE);
installer.AddExtraAttribute("Status", PSRV_SPOOL_ATTR_STATUS, B_STRING_TYPE, true, false,
60, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Page Count", PSRV_SPOOL_ATTR_PAGECOUNT, B_INT32_TYPE, true, false,
40, B_ALIGN_RIGHT, false);
installer.AddExtraAttribute("Description", PSRV_SPOOL_ATTR_DESCRIPTION, B_STRING_TYPE, true, true,
100, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Printer Name", PSRV_SPOOL_ATTR_PRINTER, B_STRING_TYPE, true, false,
80, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Job creator type", PSRV_SPOOL_ATTR_MIMETYPE, B_ASCII_TYPE, true, false,
60, B_ALIGN_LEFT, false);
#else
ExtraAttributeLazyInstaller installer(B_PRINTER_SPOOL_MIMETYPE);
installer.AddExtraAttribute("Page Count", "_spool/Page Count", B_INT32_TYPE, true, false,
40, B_ALIGN_RIGHT, false);
installer.AddExtraAttribute("Description", "_spool/Description", B_ASCII_TYPE, true, true,
100, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Printer Name", "_spool/Printer", B_ASCII_TYPE, true, false,
80, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Job creator type", "_spool/MimeType", B_ASCII_TYPE, true, false,
60, B_ALIGN_LEFT, false);
#endif
}
InstallMimeIfNeeded(B_PRINTER_MIMETYPE, kResGenericPrinterIcon,
"Printer", "Printer queue.", kTrackerSignature /*application/x-vnd.Be-PRNT*/);
// for now set tracker as a default handler for the printer because we
// just want to open it as a folder
#if B_BEOS_VERSION_DANO
{
ExtraAttributeLazyInstaller installer(B_PRINTER_MIMETYPE);
installer.AddExtraAttribute("Driver", PSRV_PRINTER_ATTR_DRV_NAME, B_STRING_TYPE, true, false,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Transport", PSRV_PRINTER_ATTR_TRANSPORT, B_STRING_TYPE, true, false,
60, B_ALIGN_RIGHT, false);
installer.AddExtraAttribute("Connection", PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, true, false,
40, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Description", PSRV_PRINTER_ATTR_COMMENTS, B_STRING_TYPE, true, true,
140, B_ALIGN_LEFT, false);
}
#endif
}
void
TTracker::InstallIndices()
{
BVolumeRoster roster;
BVolume volume;
roster.Rewind();
while (roster.GetNextVolume(&volume) == B_OK) {
if (volume.IsReadOnly() || !volume.IsPersistent()
|| !volume.KnowsAttr() || !volume.KnowsQuery())
continue;
InstallIndices(volume.Device());
}
}
void
TTracker::InstallIndices(dev_t device)
{
status_t error = fs_create_index(device, kAttrQueryLastChange, B_INT32_TYPE, 0);
error = fs_create_index(device, "_trk/recentQuery", B_INT32_TYPE, 0);
}
const int32 kDefaultQueryTemplateCount = 3;
extern const AttributeTemplate kDefaultQueryTemplate[];
extern const AttributeTemplate kBookmarkQueryTemplate[];
extern const AttributeTemplate kPersonQueryTemplate[];
extern const AttributeTemplate kEmailQueryTemplate[];
void
TTracker::InstallDefaultTemplates()
{
BNode node;
BString query(kQueryTemplates);
query += "/application_octet-stream";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kDefaultQueryTemplate, 3);
fileNode << tmp;
}
(query = kQueryTemplates) += "/application_x-vnd.Be-bookmark";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kBookmarkQueryTemplate, 3);
fileNode << tmp;
}
(query = kQueryTemplates) += "/application_x-person";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kPersonQueryTemplate, 3);
fileNode << tmp;
}
(query = kQueryTemplates) += "/text_x-email";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kEmailQueryTemplate, 3);
fileNode << tmp;
}
}
static void
InstallTemporaryBackgroundImages(BNode *node, BMessage *message)
{
int32 size = message->FlattenedSize();
char *buffer = new char [size];
message->Flatten(buffer, size);
node->WriteAttr(kBackgroundImageInfo, B_MESSAGE_TYPE, 0, buffer, (size_t)size);
delete [] buffer;
}
static void
AddTemporaryBackgroundImages(BMessage *message, const char *imagePath,
BackgroundImage::Mode mode, BPoint offset, uint32 workspaces, bool textWidgetOutlines)
{
message->AddString(kBackgroundImageInfoPath, imagePath);
message->AddInt32(kBackgroundImageInfoWorkspaces, (int32)workspaces);
message->AddInt32(kBackgroundImageInfoMode, mode);
message->AddBool(kBackgroundImageInfoTextOutline, textWidgetOutlines);
message->AddPoint(kBackgroundImageInfoOffset, offset);
}
#if 0 // dead code, don't know what it was used for
static void
InstallTemporaryBackgroundImagesIfNeeded(BNode *node, const char *imagePath,
BackgroundImage::Mode mode, BPoint offset, uint32 workspaces, bool textWidgetOutlines)
{
attr_info info;
if (node->GetAttrInfo(kBackgroundImageInfo, &info) != B_OK) {
BMessage message;
AddTemporaryBackgroundImages(&message, imagePath, mode, offset, workspaces,
textWidgetOutlines);
InstallTemporaryBackgroundImages(node, &message);
}
}
#endif
void
TTracker::InstallTemporaryBackgroundImages()
{
// make the large Haiku Logo the default background
BPath path;
status_t status = find_directory(B_SYSTEM_DATA_DIRECTORY, &path);
if (status < B_OK) {
BString errorMessage;
errorMessage << "At " << __PRETTY_FUNCTION__ << "\n";
errorMessage << "find_directory() failed. \nReason: ";
errorMessage << strerror(status);
(new BAlert("AlertError", errorMessage.String(), "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
return;
}
path.Append("artwork");
// FSFindTrackerSettingsDir(&path, false);
// path.Append(kDefaultFolderTemplate);
BString defaultBackgroundImage("/HAIKU logo - white on blue - big.png");
#if 0
BString defaultBackgroundTexture("/backgroundTexture.tga");
BNode node;
if (BContainerWindow::DefaultStateSourceNode(kDefaultFolderTemplate, &node, true)) {
// install a default background texture for folders in icon view mode
InstallTemporaryBackgroundImagesIfNeeded(&node,
(BString(path.Path()) << defaultBackgroundTexture).String(),
BackgroundImage::kTiled,
BPoint(0, 0), 0xffffffff, false);
}
#endif
BDirectory dir;
if (FSGetBootDeskDir(&dir) == B_OK) {
// install a default background if there is no background defined yet
attr_info info;
if (dir.GetAttrInfo(kBackgroundImageInfo, &info) != B_OK) {
BScreen screen(B_MAIN_SCREEN_ID);
BPoint logoPos;
logoPos.x = floorf((screen.Frame().Width() - 605) * (sqrtf(5) - 1) / 2);
logoPos.y = floorf((screen.Frame().Height() - 190) * 0.9);
BMessage message;
AddTemporaryBackgroundImages(&message,
(BString(path.Path()) << defaultBackgroundImage).String(),
BackgroundImage::kAtOffset,
logoPos, 0xffffffff, false);
::InstallTemporaryBackgroundImages(&dir, &message);
}
}
}
// the following templates are in big endian and we rely on the Tracker // the following templates are in big endian and we rely on the Tracker
// translation support to swap them on little endian machines // translation support to swap them on little endian machines
// //
@@ -517,6 +95,7 @@ TTracker::InstallTemporaryBackgroundImages()
// correct machine has to be used here // correct machine has to be used here
const BRect kDefaultFrame(40, 40, 500, 350); const BRect kDefaultFrame(40, 40, 500, 350);
const int32 kDefaultQueryTemplateCount = 3;
const AttributeTemplate kDefaultQueryTemplate[] = const AttributeTemplate kDefaultQueryTemplate[] =
/* /boot/home/config/settings/Tracker/DefaultQueryTemplates/application_octet-stream */ /* /boot/home/config/settings/Tracker/DefaultQueryTemplates/application_octet-stream */
@@ -648,3 +227,401 @@ const AttributeTemplate kEmailQueryTemplate[] =
}, },
}; };
namespace BPrivate {
class ExtraAttributeLazyInstaller {
public:
ExtraAttributeLazyInstaller(const char *type);
~ExtraAttributeLazyInstaller();
bool AddExtraAttribute(const char *publicName, const char *name,
uint32 type, bool viewable, bool editable, float width,
int32 alignment, bool extra);
status_t InitCheck() const;
public:
BMimeType fMimeType;
BMessage fExtraAttrs;
bool fDirty;
};
} // namespace BPrivate
ExtraAttributeLazyInstaller::ExtraAttributeLazyInstaller(const char *type)
:
fMimeType(type),
fDirty(false)
{
if (fMimeType.InitCheck() == B_OK)
fMimeType.GetAttrInfo(&fExtraAttrs);
}
ExtraAttributeLazyInstaller::~ExtraAttributeLazyInstaller()
{
if (fMimeType.InitCheck() == B_OK && fDirty)
fMimeType.SetAttrInfo(&fExtraAttrs);
}
bool
ExtraAttributeLazyInstaller::AddExtraAttribute(const char *publicName,
const char *name, uint32 type, bool viewable, bool editable, float width,
int32 alignment, bool extra)
{
for (int32 index = 0; ; index++) {
const char *oldPublicName;
if (fExtraAttrs.FindString("attr:public_name", index, &oldPublicName) != B_OK)
break;
if (strcmp(oldPublicName, publicName) == 0)
// already got this extra atribute, no work left
return false;
}
fExtraAttrs.AddString("attr:public_name", publicName);
fExtraAttrs.AddString("attr:name", name);
fExtraAttrs.AddInt32("attr:type", (int32)type);
fExtraAttrs.AddBool("attr:viewable", viewable);
fExtraAttrs.AddBool("attr:editable", editable);
fExtraAttrs.AddInt32("attr:width", (int32)width);
fExtraAttrs.AddInt32("attr:alignment", alignment);
fExtraAttrs.AddBool("attr:extra", extra);
fDirty = true;
return true;
}
// #pragma mark -
static void
InstallTemporaryBackgroundImages(BNode* node, BMessage* message)
{
int32 size = message->FlattenedSize();
try {
char* buffer = new char[size];
message->Flatten(buffer, size);
node->WriteAttr(kBackgroundImageInfo, B_MESSAGE_TYPE, 0, buffer,
(size_t)size);
delete[] buffer;
} catch (...) {
}
}
static void
AddTemporaryBackgroundImages(BMessage *message, const char *imagePath,
BackgroundImage::Mode mode, BPoint offset, uint32 workspaces,
bool textWidgetOutlines)
{
message->AddString(kBackgroundImageInfoPath, imagePath);
message->AddInt32(kBackgroundImageInfoWorkspaces, (int32)workspaces);
message->AddInt32(kBackgroundImageInfoMode, mode);
message->AddBool(kBackgroundImageInfoTextOutline, textWidgetOutlines);
message->AddPoint(kBackgroundImageInfoOffset, offset);
}
// #pragma mark -
bool
TTracker::InstallMimeIfNeeded(const char *type, int32 bitsID,
const char *shortDescription, const char *longDescription,
const char *preferredAppSignature, uint32 forceMask)
{
// used by InitMimeTypes - checks if a metamime of a given <type> is
// installed and if it has all the specified attributes; if not, the
// whole mime type is installed and all attributes are set; nulls can
// be passed for attributes that don't matter; returns true if anything
// had to be changed
BBitmap vectorIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_RGBA32);
BBitmap largeIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
BBitmap miniIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
char tmp[B_MIME_TYPE_LENGTH];
BMimeType mime(type);
bool installed = mime.IsInstalled();
if (!installed
|| (bitsID >= 0 && ((forceMask & kForceLargeIcon)
|| mime.GetIcon(&vectorIcon, B_LARGE_ICON) != B_OK))
|| (bitsID >= 0 && ((forceMask & kForceLargeIcon)
|| mime.GetIcon(&largeIcon, B_LARGE_ICON) != B_OK))
|| (bitsID >= 0 && ((forceMask & kForceMiniIcon)
|| mime.GetIcon(&miniIcon, B_MINI_ICON) != B_OK))
|| (shortDescription && ((forceMask & kForceShortDescription)
|| mime.GetShortDescription(tmp) != B_OK))
|| (longDescription && ((forceMask & kForceLongDescription)
|| mime.GetLongDescription(tmp) != B_OK))
|| (preferredAppSignature && ((forceMask & kForcePreferredApp)
|| mime.GetPreferredApp(tmp) != B_OK))) {
if (!installed)
mime.Install();
if (bitsID >= 0) {
const uint8* iconData;
size_t iconSize;
if (GetTrackerResources()->
GetIconResource(bitsID, &iconData, &iconSize) == B_OK)
mime.SetIcon(iconData, iconSize);
if (GetTrackerResources()->
GetIconResource(bitsID, B_LARGE_ICON, &largeIcon) == B_OK)
mime.SetIcon(&largeIcon, B_LARGE_ICON);
if (GetTrackerResources()->
GetIconResource(bitsID, B_MINI_ICON, &miniIcon) == B_OK)
mime.SetIcon(&miniIcon, B_MINI_ICON);
}
if (shortDescription)
mime.SetShortDescription(shortDescription);
if (longDescription)
mime.SetLongDescription(longDescription);
if (preferredAppSignature)
mime.SetPreferredApp(preferredAppSignature);
return true;
}
return false;
}
void
TTracker::InitMimeTypes()
{
InstallMimeIfNeeded(B_DIR_MIMETYPE, kResFolderIcon, "Folder",
"Folder container for file system items.", kTrackerSignature);
InstallMimeIfNeeded(B_APP_MIME_TYPE, kResAppIcon, "Be Application",
"Generic Be Application executable.", kTrackerSignature);
InstallMimeIfNeeded(B_FILE_MIMETYPE, kResFileIcon,
"Generic file", "Generic document file.", kTrackerSignature);
InstallMimeIfNeeded(B_VOLUME_MIMETYPE, kResHardDiskIcon,
"Be Volume", "Disk volume.", kTrackerSignature);
InstallMimeIfNeeded(B_QUERY_MIMETYPE, kResQueryIcon,
"Be Query", "Query to locate items on disks.", kTrackerSignature);
InstallMimeIfNeeded(B_QUERY_TEMPLATE_MIMETYPE, kResQueryTemplateIcon,
"Be Query Template", "", kTrackerSignature);
InstallMimeIfNeeded(B_LINK_MIMETYPE, kResBrokenLinkIcon, "Symbolic Link",
"Link to another item in the file system.", kTrackerSignature);
InstallMimeIfNeeded(B_ROOT_MIMETYPE, kResRootIcon,
"Be Root", "File system root.", kTrackerSignature);
InstallMimeIfNeeded(B_BOOKMARK_MIMETYPE, kResBookmarkIcon,
"Bookmark", "Bookmark for a web page.", kNetPositiveSignature);
{
// install a couple of extra fields for bookmark
ExtraAttributeLazyInstaller installer(B_BOOKMARK_MIMETYPE);
installer.AddExtraAttribute("URL", "META:url", B_STRING_TYPE, true, true,
170, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Keywords", "META:keyw", B_STRING_TYPE, true, true,
130, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Title", "META:title", B_STRING_TYPE, true, true,
130, B_ALIGN_LEFT, false);
}
InstallMimeIfNeeded(B_PERSON_MIMETYPE, kResPersonIcon,
"Person", "Contact information for a person.", kPeopleSignature);
{
ExtraAttributeLazyInstaller installer(B_PERSON_MIMETYPE);
installer.AddExtraAttribute("Contact Name", kAttrName, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Company", kAttrCompany, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Address", kAttrAddress, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("City", kAttrCity, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("State", kAttrState, B_STRING_TYPE, true, true,
50, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Zip", kAttrZip, B_STRING_TYPE, true, true,
50, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Country", kAttrCountry, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("E-mail", kAttrEmail, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Home Phone", kAttrHomePhone, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Work Phone", kAttrWorkPhone, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Fax", kAttrFax, B_STRING_TYPE, true, true,
90, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("URL", kAttrURL, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Group", kAttrGroup, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Nickname", kAttrNickname, B_STRING_TYPE, true, true,
120, B_ALIGN_LEFT, false);
}
InstallMimeIfNeeded(B_PRINTER_SPOOL_MIMETYPE, kResSpoolFileIcon,
"Printer spool", "Printer spool file.", "application/x-vnd.Be-PRNT");
{
#if B_BEOS_VERSION_DANO
ExtraAttributeLazyInstaller installer(B_PRINTER_SPOOL_MIMETYPE);
installer.AddExtraAttribute("Status", PSRV_SPOOL_ATTR_STATUS, B_STRING_TYPE, true, false,
60, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Page Count", PSRV_SPOOL_ATTR_PAGECOUNT, B_INT32_TYPE, true, false,
40, B_ALIGN_RIGHT, false);
installer.AddExtraAttribute("Description", PSRV_SPOOL_ATTR_DESCRIPTION, B_STRING_TYPE, true, true,
100, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Printer Name", PSRV_SPOOL_ATTR_PRINTER, B_STRING_TYPE, true, false,
80, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Job creator type", PSRV_SPOOL_ATTR_MIMETYPE, B_ASCII_TYPE, true, false,
60, B_ALIGN_LEFT, false);
#else
ExtraAttributeLazyInstaller installer(B_PRINTER_SPOOL_MIMETYPE);
installer.AddExtraAttribute("Page Count", "_spool/Page Count", B_INT32_TYPE, true, false,
40, B_ALIGN_RIGHT, false);
installer.AddExtraAttribute("Description", "_spool/Description", B_ASCII_TYPE, true, true,
100, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Printer Name", "_spool/Printer", B_ASCII_TYPE, true, false,
80, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Job creator type", "_spool/MimeType", B_ASCII_TYPE, true, false,
60, B_ALIGN_LEFT, false);
#endif
}
InstallMimeIfNeeded(B_PRINTER_MIMETYPE, kResGenericPrinterIcon,
"Printer", "Printer queue.", kTrackerSignature /*application/x-vnd.Be-PRNT*/);
// for now set tracker as a default handler for the printer because we
// just want to open it as a folder
#if B_BEOS_VERSION_DANO
{
ExtraAttributeLazyInstaller installer(B_PRINTER_MIMETYPE);
installer.AddExtraAttribute("Driver", PSRV_PRINTER_ATTR_DRV_NAME, B_STRING_TYPE, true, false,
120, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Transport", PSRV_PRINTER_ATTR_TRANSPORT, B_STRING_TYPE, true, false,
60, B_ALIGN_RIGHT, false);
installer.AddExtraAttribute("Connection", PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, true, false,
40, B_ALIGN_LEFT, false);
installer.AddExtraAttribute("Description", PSRV_PRINTER_ATTR_COMMENTS, B_STRING_TYPE, true, true,
140, B_ALIGN_LEFT, false);
}
#endif
}
void
TTracker::InstallIndices()
{
BVolumeRoster roster;
BVolume volume;
roster.Rewind();
while (roster.GetNextVolume(&volume) == B_OK) {
if (volume.IsReadOnly() || !volume.IsPersistent()
|| !volume.KnowsAttr() || !volume.KnowsQuery())
continue;
InstallIndices(volume.Device());
}
}
void
TTracker::InstallIndices(dev_t device)
{
status_t error = fs_create_index(device, kAttrQueryLastChange, B_INT32_TYPE, 0);
error = fs_create_index(device, "_trk/recentQuery", B_INT32_TYPE, 0);
}
void
TTracker::InstallDefaultTemplates()
{
BNode node;
BString query(kQueryTemplates);
query += "/application_octet-stream";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kDefaultQueryTemplate, 3);
fileNode << tmp;
}
(query = kQueryTemplates) += "/application_x-vnd.Be-bookmark";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kBookmarkQueryTemplate, 3);
fileNode << tmp;
}
(query = kQueryTemplates) += "/application_x-person";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kPersonQueryTemplate, 3);
fileNode << tmp;
}
(query = kQueryTemplates) += "/text_x-email";
if (!BContainerWindow::DefaultStateSourceNode(query.String(), &node, false))
if (BContainerWindow::DefaultStateSourceNode(query.String(), &node, true)) {
AttributeStreamFileNode fileNode(&node);
AttributeStreamTemplateNode tmp(kEmailQueryTemplate, 3);
fileNode << tmp;
}
}
void
TTracker::InstallTemporaryBackgroundImages()
{
// make the large Haiku Logo the default background
BPath path;
status_t status = find_directory(B_SYSTEM_DATA_DIRECTORY, &path);
if (status < B_OK) {
BString errorMessage;
errorMessage << "At " << __PRETTY_FUNCTION__ << "\n";
errorMessage << "find_directory() failed. \nReason: ";
errorMessage << strerror(status);
(new BAlert("AlertError", errorMessage.String(), "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
return;
}
path.Append("artwork");
BString defaultBackgroundImage("/HAIKU logo - white on blue - big.png");
BDirectory dir;
if (FSGetBootDeskDir(&dir) == B_OK) {
// install a default background if there is no background defined yet
attr_info info;
if (dir.GetAttrInfo(kBackgroundImageInfo, &info) != B_OK) {
BScreen screen(B_MAIN_SCREEN_ID);
BPoint logoPos;
logoPos.x
= floorf((screen.Frame().Width() - 605) * (sqrtf(5) - 1) / 2);
logoPos.y = floorf((screen.Frame().Height() - 190) * 0.9);
BMessage message;
AddTemporaryBackgroundImages(&message,
(BString(path.Path()) << defaultBackgroundImage).String(),
BackgroundImage::kAtOffset, logoPos, 0xffffffff, false);
::InstallTemporaryBackgroundImages(&dir, &message);
}
}
}