void FontManager::MessageReceived(BMessage* message) { switch (message->what) { case B_NODE_MONITOR: { // TODO: support removing fonts! int32 opcode; if (message->FindInt32("opcode", &opcode) != B_OK) return; switch (opcode) { case B_ENTRY_CREATED: { const char* name; node_ref nodeRef; if (message->FindInt32("device", &nodeRef.device) != B_OK || message->FindInt64("directory", &nodeRef.node) != B_OK || message->FindString("name", &name) != B_OK) break; // TODO: make this better (possible under Haiku) snooze(100000); // let the font be written completely before trying to open it BEntry entry; if (set_entry(nodeRef, name, entry) != B_OK) break; if (entry.IsDirectory()) { // a new directory to watch for us _AddPath(entry); } else { // a new font font_directory* directory = _FindDirectory(nodeRef); if (directory == NULL) { // unknown directory? how come? break; } _AddFont(*directory, entry); } break; } case B_ENTRY_MOVED: { // has the entry been moved into a monitored directory or has // it been removed from one? const char* name; node_ref nodeRef; uint64 fromNode; uint64 node; if (message->FindInt32("device", &nodeRef.device) != B_OK || message->FindInt64("to directory", &nodeRef.node) != B_OK || message->FindInt64("from directory", (int64 *)&fromNode) != B_OK || message->FindInt64("node", (int64 *)&node) != B_OK || message->FindString("name", &name) != B_OK) break; font_directory* directory = _FindDirectory(nodeRef); BEntry entry; if (set_entry(nodeRef, name, entry) != B_OK) break; if (directory != NULL) { // something has been added to our watched font directories // test, if the source directory is one of ours as well nodeRef.node = fromNode; font_directory* fromDirectory = _FindDirectory(nodeRef); if (entry.IsDirectory()) { if (fromDirectory == NULL) { // there is a new directory to watch for us _AddPath(entry); FTRACE("new directory moved in"); } else { // A directory from our watched directories has // been renamed or moved within the watched // directories - we only need to update the // path names of the styles in that directory nodeRef.node = node; directory = _FindDirectory(nodeRef); if (directory != NULL) { for (int32 i = 0; i < directory->styles.CountItems(); i++) { FontStyle* style = directory->styles.ItemAt(i); style->UpdatePath(directory->directory); } } FTRACE("directory renamed"); } } else { if (fromDirectory != NULL) { // find style in source and move it to the target nodeRef.node = node; FontStyle* style = fromDirectory->FindStyle(nodeRef); if (style != NULL) { fromDirectory->styles.RemoveItem(style, false); directory->styles.AddItem(style); style->UpdatePath(directory->directory); } FTRACE(("font moved")); } else { FTRACE(("font added: %s\n", name)); _AddFont(*directory, entry); } } } else { // and entry has been removed from our font directories if (entry.IsDirectory()) { if (entry.GetNodeRef(&nodeRef) == B_OK && (directory = _FindDirectory(nodeRef)) != NULL) _RemoveDirectory(directory); } else { // remove font style from directory _RemoveStyle(nodeRef.device, fromNode, node); } } break; } case B_ENTRY_REMOVED: { node_ref nodeRef; uint64 directoryNode; if (message->FindInt32("device", &nodeRef.device) != B_OK || message->FindInt64("directory", (int64 *)&directoryNode) != B_OK || message->FindInt64("node", &nodeRef.node) != B_OK) break; font_directory* directory = _FindDirectory(nodeRef); if (directory != NULL) { // the directory has been removed, so we remove it as well _RemoveDirectory(directory); } else { // remove font style from directory _RemoveStyle(nodeRef.device, directoryNode, nodeRef.node); } break; } } break; } } }