void TeamWindow::MessageReceived(BMessage* message) { switch (message->what) { case MSG_TEAM_RESTART_REQUESTED: { fListener->TeamRestartRequested(); break; } case MSG_CHOOSE_DEBUG_REPORT_LOCATION: { try { char filename[B_FILE_NAME_LENGTH]; UiUtils::ReportNameForTeam(fTeam, filename, sizeof(filename)); BMessenger msgr(this); fFilePanel = new BFilePanel(B_SAVE_PANEL, &msgr, NULL, 0, false, new BMessage(MSG_GENERATE_DEBUG_REPORT)); fFilePanel->SetSaveText(filename); fFilePanel->Show(); } catch (...) { delete fFilePanel; fFilePanel = NULL; } break; } case MSG_GENERATE_DEBUG_REPORT: { delete fFilePanel; fFilePanel = NULL; BPath path; entry_ref ref; if (message->FindRef("directory", &ref) == B_OK && message->HasString("name")) { path.SetTo(&ref); path.Append(message->FindString("name")); if (get_ref_for_path(path.Path(), &ref) == B_OK) fListener->DebugReportRequested(&ref); } break; } case MSG_DEBUG_REPORT_SAVED: { BString data; data.SetToFormat("Debug report successfully saved to '%s'", message->FindString("path")); BAlert *alert = new(std::nothrow) BAlert("Report saved", data.String(), "Close"); if (alert == NULL) break; alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); break; } case MSG_SHOW_INSPECTOR_WINDOW: { if (fInspectorWindow) { fInspectorWindow->Activate(true); } else { try { fInspectorWindow = InspectorWindow::Create(fTeam, fListener, this); if (fInspectorWindow != NULL) { BMessage settings; fInspectorWindow->LoadSettings(fUiSettings); fInspectorWindow->Show(); } } catch (...) { // TODO: notify user } } target_addr_t address; if (message->FindUInt64("address", &address) == B_OK) { BMessage addressMessage(MSG_INSPECT_ADDRESS); addressMessage.AddUInt64("address", address); fInspectorWindow->PostMessage(&addressMessage); } break; } case MSG_INSPECTOR_WINDOW_CLOSED: { _SaveInspectorSettings(CurrentMessage()); fInspectorWindow = NULL; break; } case MSG_SHOW_BREAK_CONDITION_CONFIG_WINDOW: { if (fBreakConditionConfigWindow) { fBreakConditionConfigWindow->Activate(true); } else { try { fBreakConditionConfigWindow = BreakConditionConfigWindow::Create( fTeam, fListener, this); if (fBreakConditionConfigWindow != NULL) fBreakConditionConfigWindow->Show(); } catch (...) { // TODO: notify user } } break; } case MSG_BREAK_CONDITION_CONFIG_WINDOW_CLOSED: { fBreakConditionConfigWindow = NULL; break; } case MSG_SHOW_WATCH_VARIABLE_PROMPT: { target_addr_t address; uint32 type; int32 length; if (message->FindUInt64("address", &address) != B_OK || message->FindUInt32("type", &type) != B_OK || message->FindInt32("length", &length) != B_OK) { break; } try { WatchPromptWindow* window = WatchPromptWindow::Create( fTeam->GetArchitecture(), address, type, length, fListener); window->Show(); } catch (...) { // TODO: notify user } break; } case B_REFS_RECEIVED: { entry_ref locatedPath; if (message->FindRef("refs", &locatedPath) != B_OK) break; _HandleResolveMissingSourceFile(locatedPath); break; } case MSG_LOCATE_SOURCE_IF_NEEDED: { _HandleLocateSourceRequest(); break; } case MSG_SOURCE_ENTRY_QUERY_COMPLETE: { BStringList* entries; if (message->FindPointer("entries", (void**)&entries) != B_OK) break; ObjectDeleter<BStringList> entryDeleter(entries); _HandleLocateSourceRequest(entries); fActiveSourceWorker = -1; break; } case MSG_THREAD_RUN: case MSG_THREAD_STOP: case MSG_THREAD_STEP_OVER: case MSG_THREAD_STEP_INTO: case MSG_THREAD_STEP_OUT: if (fActiveThread != NULL && fTraceUpdateRunner == NULL) { fListener->ThreadActionRequested(fActiveThread->ID(), message->what); } break; case MSG_CLEAR_STACK_TRACE: { if (fTraceUpdateRunner != NULL) { _SetActiveStackTrace(NULL); _UpdateRunButtons(); } break; } case MSG_THREAD_STATE_CHANGED: { int32 threadID; if (message->FindInt32("thread", &threadID) != B_OK) break; _HandleThreadStateChanged(threadID); break; } case MSG_THREAD_CPU_STATE_CHANGED: { int32 threadID; if (message->FindInt32("thread", &threadID) != B_OK) break; _HandleCpuStateChanged(threadID); break; } case MSG_THREAD_STACK_TRACE_CHANGED: { int32 threadID; if (message->FindInt32("thread", &threadID) != B_OK) break; _HandleStackTraceChanged(threadID); break; } case MSG_IMAGE_DEBUG_INFO_CHANGED: { int32 imageID; if (message->FindInt32("image", &imageID) != B_OK) break; _HandleImageDebugInfoChanged(imageID); break; } case MSG_CONSOLE_OUTPUT_RECEIVED: { int32 fd; BString output; if (message->FindInt32("fd", &fd) != B_OK || message->FindString("output", &output) != B_OK) { break; } fConsoleOutputView->ConsoleOutputReceived(fd, output); break; } case MSG_USER_BREAKPOINT_CHANGED: { UserBreakpoint* breakpoint; if (message->FindPointer("breakpoint", (void**)&breakpoint) != B_OK) break; BReference<UserBreakpoint> breakpointReference(breakpoint, true); _HandleUserBreakpointChanged(breakpoint); break; } case MSG_WATCHPOINT_CHANGED: { Watchpoint* watchpoint; if (message->FindPointer("watchpoint", (void**)&watchpoint) != B_OK) break; BReference<Watchpoint> watchpointReference(watchpoint, true); _HandleWatchpointChanged(watchpoint); break; } case MSG_FUNCTION_SOURCE_CODE_CHANGED: { _HandleSourceCodeChanged(); break; } default: BWindow::MessageReceived(message); break; } }
void QPopupMenu::EntryCreated(const entry_ref &ref, ino_t node) { BNode file; if (file.SetTo(&ref) < B_OK) return; // Make sure the pop-up menu is ready for additions. Need a bunch of // groups at the top, a divider line, and miscellaneous people added below // the line. int32 items = CountItems(); if (!items) AddSeparatorItem(); // Does the file have a group attribute? OK to have none. BString groups; const char *kNoGroup = "NoGroup!"; ReadAttrString(&file, "META:group", &groups); if (groups.Length() <= 0) groups = kNoGroup; // Add the e-mail address to the all people group. Then add it to all the // group menus that it exists in (based on the comma separated list of // groups from the People file), optionally making the group menu if it // doesn't exist. If it's in the special NoGroup! list, then add it below // the groups. bool allPeopleGroupDone = false; BMenu *groupMenu; do { BString group; if (!allPeopleGroupDone) { // Create the default group for all people, if it doesn't exist yet. group = "All People"; allPeopleGroupDone = true; } else { // Break out the next group from the comma separated string. int32 comma; if ((comma = groups.FindFirst(',')) > 0) { groups.MoveInto(group, 0, comma); groups.Remove(0, 1); } else group.Adopt(groups); } // trim white spaces int32 i = 0; for (i = 0; isspace(group.ByteAt(i)); i++) {} if (i) group.Remove(0, i); for (i = group.Length() - 1; isspace(group.ByteAt(i)); i--) {} group.Truncate(i + 1); groupMenu = NULL; BMenuItem *superItem = NULL; // Corresponding item for group menu. if (group.Length() > 0 && group != kNoGroup) { BMenu *sub; // Look for submenu with label == group name for (int32 i = 0; i < items; i++) { if ((sub = SubmenuAt(i)) != NULL) { superItem = sub->Superitem(); if (!strcmp(superItem->Label(), group.String())) { groupMenu = sub; i++; break; } } } // If no submenu, create one if (!groupMenu) { // Find where it should go (alphabetical) int32 mindex = 0; for (; mindex < fGroups; mindex++) { if (strcmp(ItemAt(mindex)->Label(), group.String()) > 0) break; } groupMenu = new BMenu(group.String()); groupMenu->SetFont(be_plain_font); AddItem(groupMenu, mindex); superItem = groupMenu->Superitem(); superItem->SetMessage(new BMessage(B_SIMPLE_DATA)); if (fTargetHandler) superItem->SetTarget(fTargetHandler); fGroups++; } } BString name; ReadAttrString(&file, "META:name", &name); BString email; ReadAttrString(&file, "META:email", &email); if (email.Length() != 0 || name.Length() != 0) AddPersonItem(&ref, node, name, email, NULL, groupMenu, superItem); // support for 3rd-party People apps for (int16 i = 2; i < 6; i++) { char attr[16]; sprintf(attr, "META:email%d", i); if (ReadAttrString(&file, attr, &email) >= B_OK && email.Length() > 0) AddPersonItem(&ref, node, name, email, attr, groupMenu, superItem); } } while (groups.Length() > 0); }
void THeaderView::InitEmailCompletion() { // get boot volume BVolume volume; BVolumeRoster().GetBootVolume(&volume); BQuery query; query.SetVolume(&volume); query.SetPredicate("META:email=**"); // Due to R5 BFS bugs, you need two stars, META:email=** for the query. // META:email="*" will just return one entry and stop, same with // META:email=* and a few other variations. Grumble. query.Fetch(); entry_ref ref; while (query.GetNextRef (&ref) == B_OK) { BNode file; if (file.SetTo(&ref) == B_OK) { // Add the e-mail address as an auto-complete string. BString email; if (file.ReadAttrString("META:email", &email) >= B_OK) fEmailList.AddChoice(email.String()); // Also add the quoted full name as an auto-complete string. Can't // do unquoted since auto-complete isn't that smart, so the user // will have to type a quote mark if he wants to select someone by // name. BString fullName; if (file.ReadAttrString("META:name", &fullName) >= B_OK) { if (email.FindFirst('<') < 0) { email.ReplaceAll('>', '_'); email.Prepend("<"); email.Append(">"); } fullName.ReplaceAll('\"', '_'); fullName.Prepend("\""); fullName << "\" " << email; fEmailList.AddChoice(fullName.String()); } // support for 3rd-party People apps. Looks like a job for // multiple keyword (so you can have several e-mail addresses in // one attribute, perhaps comma separated) indices! Which aren't // yet in BFS. for (int16 i = 2; i < 6; i++) { char attr[16]; sprintf(attr, "META:email%d", i); if (file.ReadAttrString(attr, &email) >= B_OK) fEmailList.AddChoice(email.String()); } } } }
BOOTIL_EXPORT bool Popup( const BString & strName, const BString & strText ) { MessageBoxA( NULL, strText.c_str(), strName.c_str(), MB_OK | MB_ICONASTERISK ); return true; }
BOOTIL_EXPORT void OpenWebpage( const BString & strURL ) { ShellExecute( NULL, "open", strURL.c_str(), NULL, NULL, SW_SHOWNORMAL ); }
status_t POP3Protocol::Open(const char* server, int port, int) { ReportProgress(0, 0, B_TRANSLATE("Connecting to POP3 server" B_UTF8_ELLIPSIS)); if (port <= 0) port = fUseSSL ? 995 : 110; fLog = ""; // Prime the error message BString error_msg, servString; error_msg << B_TRANSLATE("Error while connecting to server %serv"); servString << server; error_msg.ReplaceFirst("%serv", servString); if (port != 110) error_msg << ":" << port; uint32 hostIP = inet_addr(server); // first see if we can parse it as a numeric address if (hostIP == 0 || hostIP == ~0UL) { struct hostent * he = gethostbyname(server); hostIP = he ? *((uint32*)he->h_addr) : 0; } if (hostIP == 0) { error_msg << B_TRANSLATE(": Connection refused or host not found"); ShowError(error_msg.String()); return B_NAME_NOT_FOUND; } delete fServerConnection; fServerConnection = NULL; if (fUseSSL) { fServerConnection = new(std::nothrow) BSecureSocket( BNetworkAddress(server, port)); } else { fServerConnection = new(std::nothrow) BSocket(BNetworkAddress( server, port)); } if (fServerConnection == NULL) return B_NO_MEMORY; if (fServerConnection->InitCheck() != B_OK) return fServerConnection->InitCheck(); BString line; status_t err = ReceiveLine(line); if (err < 0) { fServerConnection->Disconnect(); error_msg << ": " << strerror(err); ShowError(error_msg.String()); return B_ERROR; } if (strncmp(line.String(), "+OK", 3) != 0) { if (line.Length() > 0) { error_msg << B_TRANSLATE(". The server said:\n") << line.String(); } else error_msg << B_TRANSLATE(": No reply.\n"); ShowError(error_msg.String()); fServerConnection->Disconnect(); return B_ERROR; } fLog = line; return B_OK; }
status_t POP3Protocol::RetrieveInternal(const char *command, int32 message, BPositionIO *write_to, bool post_progress) { const int bufSize = 1024 * 30; // To avoid waiting for the non-arrival of the next data packet, try to // receive only the message size, plus the 3 extra bytes for the ".\r\n" // after the message. Of course, if we get it wrong (or it is a huge // message or has lines starting with escaped periods), it will then switch // back to receiving full buffers until the message is done. int amountToReceive = MessageSize (message) + 3; if (amountToReceive >= bufSize || amountToReceive <= 0) amountToReceive = bufSize - 1; BString bufBString; // Used for auto-dealloc on return feature. char *buf = bufBString.LockBuffer (bufSize); int amountInBuffer = 0; int amountReceived; int testIndex; char *testStr; bool cont = true; bool flushWholeBuffer = false; write_to->Seek(0,SEEK_SET); if (SendCommand(command) != B_OK) return B_ERROR; while (cont) { status_t result = fServerConnection->WaitForReadable( POP3_RETRIEVAL_TIMEOUT); if (result == B_TIMED_OUT) { // No data available, even after waiting a minute. fLog = "POP3 timeout - no data received after a long wait."; return B_ERROR; } if (amountToReceive > bufSize - 1 - amountInBuffer) amountToReceive = bufSize - 1 - amountInBuffer; amountReceived = fServerConnection->Read(buf + amountInBuffer, amountToReceive); if (amountReceived < 0) { fLog = strerror(errno); return errno; } if (amountReceived == 0) { fLog = "POP3 data supposedly ready to receive but not received!"; return B_ERROR; } amountToReceive = bufSize - 1; // For next time, read a full buffer. amountInBuffer += amountReceived; buf[amountInBuffer] = 0; // NUL stops tests past the end of buffer. // Look for lines starting with a period. A single period by itself on // a line "\r\n.\r\n" marks the end of the message (thus the need for // at least five characters in the buffer for testing). A period // "\r\n.Stuff" at the start of a line get deleted "\r\nStuff", since // POP adds one as an escape code to let you have message text with // lines starting with a period. For convenience, assume that no // messages start with a period on the very first line, so we can // search for the previous line's "\r\n". for (testIndex = 0; testIndex <= amountInBuffer - 5; testIndex++) { testStr = buf + testIndex; if (testStr[0] == '\r' && testStr[1] == '\n' && testStr[2] == '.') { if (testStr[3] == '\r' && testStr[4] == '\n') { // Found the end of the message marker. Ignore remaining data. if (amountInBuffer > testIndex + 5) printf ("POP3Protocol::RetrieveInternal Ignoring %d bytes " "of extra data past message end.\n", amountInBuffer - (testIndex + 5)); amountInBuffer = testIndex + 2; // Don't include ".\r\n". buf[amountInBuffer] = 0; cont = false; } else { // Remove an extra period at the start of a line. // Inefficient, but it doesn't happen often that you have a // dot starting a line of text. Of course, a file with a // lot of double period lines will get processed very // slowly. memmove (buf + testIndex + 2, buf + testIndex + 3, amountInBuffer - (testIndex + 3) + 1 /* for NUL at end */); amountInBuffer--; // Watch out for the end of buffer case, when the POP text // is "\r\n..X". Don't want to leave the resulting // "\r\n.X" in the buffer (flush out the whole buffer), // since that will get mistakenly evaluated again in the // next loop and delete a character by mistake. if (testIndex >= amountInBuffer - 4 && testStr[2] == '.') { printf ("POP3Protocol::RetrieveInternal: Jackpot! " "You have hit the rare situation with an escaped " "period at the end of the buffer. Aren't you happy" "it decodes it correctly?\n"); flushWholeBuffer = true; } } } } if (cont && !flushWholeBuffer) { // Dump out most of the buffer, but leave the last 4 characters for // comparison continuity, in case the line starting with a period // crosses a buffer boundary. if (amountInBuffer > 4) { write_to->Write(buf, amountInBuffer - 4); if (post_progress) ReportProgress(amountInBuffer - 4,0); memmove (buf, buf + amountInBuffer - 4, 4); amountInBuffer = 4; } } else { // Dump everything - end of message or flushing the whole buffer. write_to->Write(buf, amountInBuffer); if (post_progress) ReportProgress(amountInBuffer,0); amountInBuffer = 0; } } return B_OK; }
TMailWindow* TMailApp::NewWindow(const entry_ref* ref, const char* to, bool resend, BMessenger* trackerMessenger) { BScreen screen(B_MAIN_SCREEN_ID); BRect screenFrame = screen.Frame(); BRect r; if (fMailWindowFrame.Width() < 64 || fMailWindowFrame.Height() < 20) { // default size r.Set(6, TITLE_BAR_HEIGHT, 6 + WIND_WIDTH, TITLE_BAR_HEIGHT + WIND_HEIGHT); } else r = fMailWindowFrame; // make sure the window is not larger than the screen space if (r.Height() > screenFrame.Height()) r.bottom = r.top + screenFrame.Height(); if (r.Width() > screenFrame.Width()) r.bottom = r.top + screenFrame.Width(); // cascading windows r.OffsetBy(((fWindowCount + 5) % 10) * 15 - 75, ((fWindowCount + 5) % 10) * 15 - 75); // make sure the window is still on screen if (r.left - 6 < screenFrame.left) r.OffsetTo(screenFrame.left + 8, r.top); if (r.left + 20 > screenFrame.right) r.OffsetTo(6, r.top); if (r.top - 26 < screenFrame.top) r.OffsetTo(r.left, screenFrame.top + 26); if (r.top + 20 > screenFrame.bottom) r.OffsetTo(r.left, TITLE_BAR_HEIGHT); if (r.Width() < WIND_WIDTH) r.right = r.left + WIND_WIDTH; fWindowCount++; BString title; BFile file; if (!resend && ref && file.SetTo(ref, O_RDONLY) == B_OK) { BString name; if (file.ReadAttrString(B_MAIL_ATTR_NAME, &name) == B_OK) { title << name; BString subject; if (file.ReadAttrString(B_MAIL_ATTR_SUBJECT, &subject) == B_OK) title << " -> " << subject; } } if (title == "") title = B_TRANSLATE_SYSTEM_NAME("Mail"); TMailWindow* window = new TMailWindow(r, title.String(), this, ref, to, &fContentFont, resend, trackerMessenger); fWindowList.AddItem(window); return window; }
void TMailApp::ArgvReceived(int32 argc, char **argv) { BEntry entry; BString names; BString ccNames; BString bccNames; BString subject; BString body; BMessage enclosure(B_REFS_RECEIVED); // a "mailto:" with no name should open an empty window // so remember if we got a "mailto:" even if there isn't a name // that goes along with it (this allows deskbar replicant to open // an empty message even when Mail is already running) bool gotmailto = false; for (int32 loop = 1; loop < argc; loop++) { if (strcmp(argv[loop], "-h") == 0 || strcmp(argv[loop], "--help") == 0) { printf(" usage: %s [ mailto:<address> ] [ -subject \"<text>\" ] [ ccto:<address> ] [ bccto:<address> ] " "[ -body \"<body text>\" ] [ enclosure:<path> ] [ <message to read> ...] \n", argv[0]); fPrintHelpAndExit = true; be_app->PostMessage(B_QUIT_REQUESTED); return; } else if (strncmp(argv[loop], "mailto:", 7) == 0) { if (names.Length()) names += ", "; char *options; if ((options = strchr(argv[loop],'?')) != NULL) { names.Append(argv[loop] + 7, options - argv[loop] - 7); if (!strncmp(++options,"subject=",8)) subject = options + 8; } else names += argv[loop] + 7; gotmailto = true; } else if (strncmp(argv[loop], "ccto:", 5) == 0) { if (ccNames.Length()) ccNames += ", "; ccNames += argv[loop] + 5; } else if (strncmp(argv[loop], "bccto:", 6) == 0) { if (bccNames.Length()) bccNames += ", "; bccNames += argv[loop] + 6; } else if (strcmp(argv[loop], "-subject") == 0) subject = argv[++loop]; else if (strcmp(argv[loop], "-body") == 0 && argv[loop + 1]) body = argv[++loop]; else if (strncmp(argv[loop], "enclosure:", 10) == 0) { BEntry tmp(argv[loop] + 10, true); if (tmp.InitCheck() == B_OK && tmp.Exists()) { entry_ref ref; tmp.GetRef(&ref); enclosure.AddRef("refs", &ref); } } else if (entry.SetTo(argv[loop]) == B_NO_ERROR) { BMessage msg(B_REFS_RECEIVED); entry_ref ref; entry.GetRef(&ref); msg.AddRef("refs", &ref); RefsReceived(&msg); } } if (gotmailto || names.Length() || ccNames.Length() || bccNames.Length() || subject.Length() || body.Length() || enclosure.HasRef("refs")) { TMailWindow *window = NewWindow(NULL, names.String()); window->SetTo(names.String(), subject.String(), ccNames.String(), bccNames.String(), &body, &enclosure); window->Show(); } }
void ArgvReceived(int32 argc, char **argv) { int i, j; BMessage msg(InfoPopper::AddMessage); InfoPopper::info_type type = InfoPopper::Information; const char *app = "Command Line"; const char *title = "Something Happened"; BString content; float progress = 0.0; const char *messageID = NULL; int32 timeout = 0; const char *iconFile = NULL; const char *onClickApp; entry_ref onClickFile; const char *onClickArgv; entry_ref onClickRef; for (i = 1; i < argc; i++) { //printf("argv[%d] = %s\n", i, argv[i]); if (!strcmp(argv[i], "--help")) { return Usage(); } else if (!strcmp(argv[i], "--type")) { if (++i >= argc) return Usage(); type = (InfoPopper::info_type)atoi(argv[i]); for (j=0; kTypeNames[j]; j++) { if (!strncmp(kTypeNames[j], argv[i], strlen(argv[i]))) { type = (InfoPopper::info_type)j; }; }; } else if (!strcmp(argv[i], "--app")) { if (++i >= argc) return Usage(); app = argv[i]; } else if (!strcmp(argv[i], "--title")) { if (++i >= argc) return Usage(); title = argv[i]; } else if (!strcmp(argv[i], "--messageID")) { if (++i >= argc) return Usage(); messageID = argv[i]; msg.AddString("messageID", messageID); } else if (!strcmp(argv[i], "--progress")) { if (++i >= argc) return Usage(); progress = atof(argv[i]); msg.AddFloat("progress", progress); } else if (!strcmp(argv[i], "--timeout")) { if (++i >= argc) return Usage(); timeout = atol(argv[i]); msg.AddInt32("timeout", timeout); #if 0 } else if (!strcmp(argv[i], "--empty")) { /* like alert's --empty */ iconFile = NULL; } else if (!strcmp(argv[i], "--info")) { iconFile = "info"; } else if (!strcmp(argv[i], "--idea")) { } else if (!strcmp(argv[i], "--warning")) { } else if (!strcmp(argv[i], "--stop")) { #endif } else if (!strcmp(argv[i], "--icon")) { bool isOverlay = false; if (++i >= argc) return Usage(); iconFile = argv[i]; if (!strncmp(iconFile, "overlay:", 8)) { iconFile += 8; isOverlay = true; }; if (!strncmp(iconFile, "attr:", 5)) { iconFile += 5; msg.AddInt32(isOverlay?"overlayIconType":"iconType", InfoPopper::Attribute); } else { msg.AddInt32(isOverlay?"overlayIconType":"iconType", InfoPopper::Contents); }; entry_ref ref; if (get_ref_for_path(iconFile, &ref) < B_OK) { fprintf(stderr, "bad icon path\n"); return Usage(); }; msg.AddRef(isOverlay?"overlayIconRef":"iconRef", &ref); } else if (!strcmp(argv[i], "--onClickApp")) { if (++i >= argc) return Usage(); onClickApp = argv[i]; msg.AddString("onClickApp", onClickApp); } else if (!strcmp(argv[i], "--onClickFile")) { if (++i >= argc) return Usage(); if (get_ref_for_path(argv[i], &onClickFile) < B_OK) { fprintf(stderr, "bad path\n"); return Usage(); }; msg.AddRef("onClickFile", &onClickFile); } else if (!strcmp(argv[i], "--onClickArgv")) { if (++i >= argc) return Usage(); onClickArgv = argv[i]; msg.AddString("onClickArgv", onClickArgv); } else if (!strcmp(argv[i], "--onClickRef")) { if (++i >= argc) return Usage(); if (get_ref_for_path(argv[i], &onClickRef) < B_OK) { fprintf(stderr, "bad path\n"); return Usage(); } msg.AddRef("onClickRef", &onClickRef); } else { if (content.Length()) content << "\n"; content << argv[i]; } } msg.AddInt8("type", (int8)type); msg.AddString("app", app); msg.AddString("title", title); msg.AddString("content", content); be_app_messenger.SendMessage(&msg); }
EventListItem::EventListItem(BString UID,BString Summary,time_t StartTime):BStringItem(Summary.String()){ mSummary = Summary; mUID = UID; mStartTime = StartTime; }
KeymapWindow::KeymapWindow() : BWindow(BRect(80, 50, 880, 380), B_TRANSLATE_SYSTEM_NAME("Keymap"), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { SetLayout(new BGroupLayout(B_VERTICAL)); fKeyboardLayoutView = new KeyboardLayoutView("layout"); fKeyboardLayoutView->SetKeymap(&fCurrentMap); fTextControl = new BTextControl(B_TRANSLATE("Sample and clipboard:"), "", NULL); fSwitchShortcutsButton = new BButton("switch", "", new BMessage(kMsgSwitchShortcuts)); fRevertButton = new BButton("revertButton", B_TRANSLATE("Revert"), new BMessage(kMsgRevertKeymap)); // controls pane AddChild(BGroupLayoutBuilder(B_VERTICAL) .Add(_CreateMenu()) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .Add(_CreateMapLists(), 0.25) .Add(BGroupLayoutBuilder(B_VERTICAL, 10) .Add(fKeyboardLayoutView) //.Add(new BStringView("text label", "Sample and clipboard:")) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .Add(_CreateDeadKeyMenuField(), 0.0) .AddGlue() .Add(fSwitchShortcutsButton)) .Add(fTextControl) .AddGlue(0.0) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .AddGlue(0.0) .Add(fRevertButton))) .SetInsets(10, 10, 10, 10))); fKeyboardLayoutView->SetTarget(fTextControl->TextView()); fTextControl->MakeFocus(); // Make sure the user keymap directory exists BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Keymap"); entry_ref ref; get_ref_for_path(path.Path(), &ref); BDirectory userKeymapsDir(&ref); if (userKeymapsDir.InitCheck() != B_OK) create_directory(path.Path(), S_IRWXU | S_IRWXG | S_IRWXO); BMessenger messenger(this); fOpenPanel = new BFilePanel(B_OPEN_PANEL, &messenger, &ref, B_FILE_NODE, false, NULL); fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, &ref, B_FILE_NODE, false, NULL); BRect windowFrame; BString keyboardLayout; _LoadSettings(windowFrame, keyboardLayout); _SetKeyboardLayout(keyboardLayout.String()); ResizeTo(windowFrame.Width(), windowFrame.Height()); MoveTo(windowFrame.LeftTop()); // TODO: this might be a bug in the interface kit, but scrolling to // selection does not correctly work unless the window is shown. Show(); Lock(); // Try and find the current map name in the two list views (if the name // was read at all) _SelectCurrentMap(); KeymapListItem* current = static_cast<KeymapListItem*>(fUserListView->FirstItem()); fCurrentMap.Load(current->EntryRef()); fPreviousMap = fCurrentMap; fAppliedMap = fCurrentMap; fCurrentMap.SetTarget(this, new BMessage(kMsgKeymapUpdated)); _UpdateButtons(); _UpdateDeadKeyMenu(); _UpdateSwitchShortcutButton(); Unlock(); }
/*! Marks the menu items corresponding to the dead key state of the current key map. */ void KeymapWindow::_UpdateDeadKeyMenu() { BString trigger; fCurrentMap.GetDeadKeyTrigger(kDeadKeyAcute, trigger); if (!trigger.Length()) trigger = kDeadKeyTriggerNone; BMenuItem* menuItem = fAcuteMenu->FindItem(trigger.String()); if (menuItem) menuItem->SetMarked(true); fCurrentMap.GetDeadKeyTrigger(kDeadKeyCircumflex, trigger); if (!trigger.Length()) trigger = kDeadKeyTriggerNone; menuItem = fCircumflexMenu->FindItem(trigger.String()); if (menuItem) menuItem->SetMarked(true); fCurrentMap.GetDeadKeyTrigger(kDeadKeyDiaeresis, trigger); if (!trigger.Length()) trigger = kDeadKeyTriggerNone; menuItem = fDiaeresisMenu->FindItem(trigger.String()); if (menuItem) menuItem->SetMarked(true); fCurrentMap.GetDeadKeyTrigger(kDeadKeyGrave, trigger); if (!trigger.Length()) trigger = kDeadKeyTriggerNone; menuItem = fGraveMenu->FindItem(trigger.String()); if (menuItem) menuItem->SetMarked(true); fCurrentMap.GetDeadKeyTrigger(kDeadKeyTilde, trigger); if (!trigger.Length()) trigger = kDeadKeyTriggerNone; menuItem = fTildeMenu->FindItem(trigger.String()); if (menuItem) menuItem->SetMarked(true); }
status_t CLanguageFamily::ParseTypeExpression(const BString& expression, TeamTypeInformation* info, Type*& _resultType) const { status_t result = B_OK; Type* baseType = NULL; BString parsedName = expression; BString baseTypeName; BString arraySpecifier; parsedName.RemoveAll(" "); int32 modifierIndex = -1; modifierIndex = parsedName.FindFirst('*'); if (modifierIndex == -1) modifierIndex = parsedName.FindFirst('&'); if (modifierIndex == -1) modifierIndex = parsedName.FindFirst('['); if (modifierIndex == -1) modifierIndex = parsedName.Length(); parsedName.MoveInto(baseTypeName, 0, modifierIndex); modifierIndex = parsedName.FindFirst('['); if (modifierIndex >= 0) { parsedName.MoveInto(arraySpecifier, modifierIndex, parsedName.Length() - modifierIndex); } result = info->LookupTypeByName(baseTypeName, TypeLookupConstraints(), baseType); if (result != B_OK) return result; BReference<Type> typeRef; typeRef.SetTo(baseType, true); if (!parsedName.IsEmpty()) { AddressType* derivedType = NULL; // walk the list of modifiers trying to add each. for (int32 i = 0; i < parsedName.Length(); i++) { if (!IsModifierValid(parsedName[i])) return B_BAD_VALUE; address_type_kind typeKind; switch (parsedName[i]) { case '*': { typeKind = DERIVED_TYPE_POINTER; break; } case '&': { typeKind = DERIVED_TYPE_REFERENCE; break; } default: { return B_BAD_VALUE; } } if (derivedType == NULL) { result = baseType->CreateDerivedAddressType(typeKind, derivedType); } else { result = derivedType->CreateDerivedAddressType(typeKind, derivedType); } if (result != B_OK) return result; typeRef.SetTo(derivedType, true); } _resultType = derivedType; } else _resultType = baseType; if (!arraySpecifier.IsEmpty()) { ArrayType* arrayType = NULL; int32 startIndex = 1; do { int32 size = strtoul(arraySpecifier.String() + startIndex, NULL, 10); if (size < 0) return B_ERROR; if (arrayType == NULL) { result = _resultType->CreateDerivedArrayType(0, size, true, arrayType); } else { result = arrayType->CreateDerivedArrayType(0, size, true, arrayType); } if (result != B_OK) return result; typeRef.SetTo(arrayType, true); startIndex = arraySpecifier.FindFirst('[', startIndex + 1); } while (startIndex >= 0); // since a C/C++ array is essentially pointer math, // the resulting array has to be wrapped in a pointer to // ensure the element addresses wind up being against the // correct address. AddressType* addressType = NULL; result = arrayType->CreateDerivedAddressType(DERIVED_TYPE_POINTER, addressType); if (result != B_OK) return result; _resultType = addressType; } typeRef.Detach(); return result; }
void TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref) { BAutolock autolock(sSubscriberLock); if (!autolock.IsLocked()) return; // have we already seen this team, is this another instance of // a known app? BarTeamInfo* multiLaunchTeam = NULL; int32 teamCount = sBarTeamInfoList.CountItems(); for (int32 i = 0; i < teamCount; i++) { BarTeamInfo* barInfo = (BarTeamInfo*)sBarTeamInfoList.ItemAt(i); if (barInfo->teams->HasItem((void*)team)) return; if (strcasecmp(barInfo->sig, sig) == 0) multiLaunchTeam = barInfo; } if (multiLaunchTeam != NULL) { multiLaunchTeam->teams->AddItem((void*)team); int32 subsCount = sSubscribers.CountItems(); if (subsCount > 0) { BMessage message(kAddTeam); message.AddInt32("team", team); message.AddString("sig", multiLaunchTeam->sig); for (int32 i = 0; i < subsCount; i++) ((BMessenger*)sSubscribers.ItemAt(i))->SendMessage(&message); } return; } BFile file(ref, B_READ_ONLY); BAppFileInfo appMime(&file); BString name; if (!gLocalizedNamePreferred || BLocaleRoster::Default()->GetLocalizedFileName(name, *ref) != B_OK) name = ref->name; BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig), new BBitmap(kIconRect, kIconFormat), strdup(name.String())); barInfo->teams->AddItem((void*)team); if (appMime.GetIcon(barInfo->icon, B_MINI_ICON) != B_OK) appMime.GetTrackerIcon(barInfo->icon, B_MINI_ICON); sBarTeamInfoList.AddItem(barInfo); if (fSettings.expandNewTeams) BarView()->AddExpandedItem(sig); int32 subsCount = sSubscribers.CountItems(); if (subsCount > 0) { for (int32 i = 0; i < subsCount; i++) { BMessenger* messenger = (BMessenger*)sSubscribers.ItemAt(i); BMessage message(B_SOME_APP_LAUNCHED); BList* tList = new BList(*(barInfo->teams)); message.AddPointer("teams", tList); BBitmap* icon = new BBitmap(barInfo->icon); ASSERT(icon); message.AddPointer("icon", icon); message.AddInt32("flags", static_cast<int32>(barInfo->flags)); message.AddString("name", barInfo->name); message.AddString("sig", barInfo->sig); messenger->SendMessage(&message); } } }
void TMailApp::MessageReceived(BMessage *msg) { TMailWindow *window = NULL; entry_ref ref; switch (msg->what) { case M_NEW: { int32 type; msg->FindInt32("type", &type); switch (type) { case M_NEW: window = NewWindow(); break; case M_RESEND: { msg->FindRef("ref", &ref); BNode file(&ref); BString string; if (file.InitCheck() == B_OK) file.ReadAttrString(B_MAIL_ATTR_TO, &string); window = NewWindow(&ref, string.String(), true); break; } case M_FORWARD: case M_FORWARD_WITHOUT_ATTACHMENTS: { TMailWindow *sourceWindow; if (msg->FindPointer("window", (void **)&sourceWindow) < B_OK || !sourceWindow->Lock()) break; msg->FindRef("ref", &ref); window = NewWindow(); if (window->Lock()) { window->Forward(&ref, sourceWindow, type == M_FORWARD); window->Unlock(); } sourceWindow->Unlock(); break; } case M_REPLY: case M_REPLY_TO_SENDER: case M_REPLY_ALL: case M_COPY_TO_NEW: { TMailWindow *sourceWindow; if (msg->FindPointer("window", (void **)&sourceWindow) < B_OK || !sourceWindow->Lock()) break; msg->FindRef("ref", &ref); window = NewWindow(); if (window->Lock()) { if (type == M_COPY_TO_NEW) window->CopyMessage(&ref, sourceWindow); else window->Reply(&ref, sourceWindow, type); window->Unlock(); } sourceWindow->Unlock(); break; } } if (window) window->Show(); break; } case M_PREFS: if (fPrefsWindow) fPrefsWindow->Activate(true); else { fPrefsWindow = new TPrefsWindow(BRect(fPrefsWindowPos.x, fPrefsWindowPos.y, fPrefsWindowPos.x + PREF_WIDTH, fPrefsWindowPos.y + PREF_HEIGHT), &fContentFont, NULL, &fWrapMode, &fAttachAttributes, &fColoredQuotes, &fDefaultAccount, &fUseAccountFrom, &fReplyPreamble, &fSignature, &fMailCharacterSet, &fWarnAboutUnencodableCharacters, &fStartWithSpellCheckOn, &fAutoMarkRead, &fShowToolBar); fPrefsWindow->Show(); } break; case PREFS_CHANGED: { // Notify all Mail windows TMailWindow *window; for (int32 i = 0; (window=(TMailWindow *)fWindowList.ItemAt(i)) != NULL; i++) { window->Lock(); window->UpdatePreferences(); window->UpdateViews(); window->Unlock(); } break; } case M_ACCOUNTS: be_roster->Launch("application/x-vnd.Haiku-Mail"); break; case M_EDIT_SIGNATURE: if (fSigWindow) fSigWindow->Activate(true); else { fSigWindow = new TSignatureWindow(fSignatureWindowFrame); fSigWindow->Show(); } break; case M_FONT: FontChange(); break; case REFS_RECEIVED: if (msg->HasPointer("window")) { msg->FindPointer("window", (void **)&window); BMessage message(*msg); window->PostMessage(&message, window); } break; case WINDOW_CLOSED: switch (msg->FindInt32("kind")) { case MAIL_WINDOW: { TMailWindow *window; if( msg->FindPointer( "window", (void **)&window ) == B_OK ) fWindowList.RemoveItem(window); fWindowCount--; break; } case PREFS_WINDOW: fPrefsWindow = NULL; msg->FindPoint("window pos", &fPrefsWindowPos); break; case SIG_WINDOW: fSigWindow = NULL; msg->FindRect("window frame", &fSignatureWindowFrame); break; } if (!fWindowCount && !fSigWindow && !fPrefsWindow) be_app->PostMessage(B_QUIT_REQUESTED); break; case B_REFS_RECEIVED: RefsReceived(msg); break; case B_PRINTER_CHANGED: _ClearPrintSettings(); break; default: BApplication::MessageReceived(msg); } }
status_t POP3Protocol::SyncMessages() { bool leaveOnServer; if (fSettings.FindBool("leave_mail_on_server", &leaveOnServer) != B_OK) leaveOnServer = true; // create directory if not exist create_directory(fDestinationDir, 0777); printf("POP3Protocol::SyncMessages()\n"); _ReadManifest(); SetTotalItems(2); ReportProgress(0, 1, B_TRANSLATE("Connect to server" B_UTF8_ELLIPSIS)); status_t error = Connect(); if (error < B_OK) { ResetProgress(); return error; } ReportProgress(0, 1, B_TRANSLATE("Getting UniqueIDs" B_UTF8_ELLIPSIS)); error = _UniqueIDs(); if (error < B_OK) { ResetProgress(); Disconnect(); return error; } BStringList toDownload; NotHere(fManifest, fUniqueIDs, &toDownload); int32 numMessages = toDownload.CountStrings(); if (numMessages == 0) { CheckForDeletedMessages(); ResetProgress(); Disconnect(); return B_OK; } ResetProgress(); SetTotalItems(toDownload.CountStrings()); printf("POP3: Messages to download: %i\n", (int)toDownload.CountStrings()); for (int32 i = 0; i < toDownload.CountStrings(); i++) { const char* uid = toDownload.StringAt(i); int32 toRetrieve = fUniqueIDs.IndexOf(uid); if (toRetrieve < 0) { // should not happen! error = B_NAME_NOT_FOUND; printf("POP3: uid %s index %i not found in fUniqueIDs!\n", uid, (int)toRetrieve); continue; } BPath path(fDestinationDir); BString fileName = "Downloading file... uid: "; fileName += uid; fileName.ReplaceAll("/", "_SLASH_"); path.Append(fileName); BEntry entry(path.Path()); BFile file(&entry, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); error = file.InitCheck(); if (error != B_OK) { printf("POP3: Can't create file %s\n ", path.Path()); break; } BMailMessageIO mailIO(this, &file, toRetrieve); entry_ref ref; entry.GetRef(&ref); // the ref becomes invalid after renaming the file thus we already // write the status here MarkMessageAsRead(ref, B_UNREAD); int32 size = MessageSize(toRetrieve); if (fFetchBodyLimit < 0 || size <= fFetchBodyLimit) { error = mailIO.Seek(0, SEEK_END); if (error < 0) { printf("POP3: Failed to download body %s\n ", uid); break; } NotifyHeaderFetched(ref, &file); NotifyBodyFetched(ref, &file); if (!leaveOnServer) Delete(toRetrieve); } else { int32 dummy; error = mailIO.ReadAt(0, &dummy, 1); if (error < 0) { printf("POP3: Failed to download header %s\n ", uid); break; } NotifyHeaderFetched(ref, &file); } ReportProgress(0, 1); if (file.WriteAttr("MAIL:unique_id", B_STRING_TYPE, 0, uid, strlen(uid)) < 0) { error = B_ERROR; } file.WriteAttr("MAIL:size", B_INT32_TYPE, 0, &size, sizeof(int32)); // save manifest in case we get disturbed fManifest.Add(uid); _WriteManifest(); } ResetProgress(); CheckForDeletedMessages(); Disconnect(); return error; }
void TMailApp::ReadyToRun() { // Create needed indices for META:group, META:email, MAIL:draft, // INDEX_SIGNATURE, INDEX_STATUS on the boot volume BVolume volume; BVolumeRoster().GetBootVolume(&volume); fs_create_index(volume.Device(), "META:group", B_STRING_TYPE, 0); fs_create_index(volume.Device(), "META:email", B_STRING_TYPE, 0); fs_create_index(volume.Device(), "MAIL:draft", B_INT32_TYPE, 0); fs_create_index(volume.Device(), INDEX_SIGNATURE, B_STRING_TYPE, 0); fs_create_index(volume.Device(), INDEX_STATUS, B_STRING_TYPE, 0); fs_create_index(volume.Device(), B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0); // Load dictionaries BPath indexDir; BPath dictionaryDir; BPath userDictionaryDir; BPath userIndexDir; BPath dataPath; BPath indexPath; BDirectory directory; BEntry entry; // Locate dictionaries directory find_directory(B_SYSTEM_DATA_DIRECTORY, &indexDir, true); indexDir.Append("spell_check"); dictionaryDir = indexDir; //Locate user dictionary directory find_directory(B_USER_CONFIG_DIRECTORY, &userIndexDir, true); userIndexDir.Append("data/spell_check"); userDictionaryDir = userIndexDir; // Create directory if needed directory.CreateDirectory(userIndexDir.Path(), NULL); // Setup directory paths indexDir.Append(kIndexDirectory); dictionaryDir.Append(kDictDirectory); userIndexDir.Append(kIndexDirectory); userDictionaryDir.Append(kDictDirectory); // Create directories if needed directory.CreateDirectory(indexDir.Path(), NULL); directory.CreateDirectory(dictionaryDir.Path(), NULL); directory.CreateDirectory(userIndexDir.Path(), NULL); directory.CreateDirectory(userDictionaryDir.Path(), NULL); dataPath = dictionaryDir; dataPath.Append("words"); // Only Load if Words Dictionary if (BEntry(kWordsPath).Exists() || BEntry(dataPath.Path()).Exists()) { // If "/boot/optional/goodies/words" exists but there is no // system dictionary, copy words if (!BEntry(dataPath.Path()).Exists() && BEntry(kWordsPath).Exists()) { BFile words(kWordsPath, B_READ_ONLY); BFile copy(dataPath.Path(), B_WRITE_ONLY | B_CREATE_FILE); char buffer[4096]; ssize_t size; while ((size = words.Read( buffer, 4096)) > 0) copy.Write(buffer, size); BNodeInfo(©).SetType("text/plain"); } // Load dictionaries directory.SetTo(dictionaryDir.Path()); BString leafName; gUserDict = -1; while (gDictCount < MAX_DICTIONARIES && directory.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { dataPath.SetTo(&entry); indexPath = indexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kMetaphone); indexPath.Append(leafName.String()); gWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), true); indexPath = indexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kExact); indexPath.Append(leafName.String()); gExactWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), false); gDictCount++; } // Create user dictionary if it does not exist dataPath = userDictionaryDir; dataPath.Append("user"); if (!BEntry(dataPath.Path()).Exists()) { BFile user(dataPath.Path(), B_WRITE_ONLY | B_CREATE_FILE); BNodeInfo(&user).SetType("text/plain"); } // Load user dictionary if (BEntry(userDictionaryDir.Path()).Exists()) { gUserDictFile = new BFile(dataPath.Path(), B_WRITE_ONLY | B_OPEN_AT_END); gUserDict = gDictCount; indexPath = userIndexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kMetaphone); indexPath.Append(leafName.String()); gWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), true); indexPath = userIndexDir; leafName.SetTo(dataPath.Leaf()); leafName.Append(kExact); indexPath.Append(leafName.String()); gExactWords[gDictCount] = new Words(dataPath.Path(), indexPath.Path(), false); gDictCount++; } } // Create a new window if starting up without any extra arguments. if (!fPrintHelpAndExit && !fWindowCount) { TMailWindow *window; window = NewWindow(); window->Show(); } }
status_t POP3Protocol::Login(const char *uid, const char *password, int method) { status_t err; BString error_msg, userString; error_msg << B_TRANSLATE("Error while authenticating user %user"); userString << uid; error_msg.ReplaceFirst("%user", userString); if (method == 1) { //APOP int32 index = fLog.FindFirst("<"); if(index != B_ERROR) { ReportProgress(0, 0, B_TRANSLATE("Sending APOP authentication" B_UTF8_ELLIPSIS)); int32 end = fLog.FindFirst(">",index); BString timestamp(""); fLog.CopyInto(timestamp, index, end - index + 1); timestamp += password; char md5sum[33]; MD5Digest((unsigned char*)timestamp.String(), md5sum); BString cmd = "APOP "; cmd += uid; cmd += " "; cmd += md5sum; cmd += CRLF; err = SendCommand(cmd.String()); if (err != B_OK) { error_msg << B_TRANSLATE(". The server said:\n") << fLog; ShowError(error_msg.String()); return err; } return B_OK; } else { error_msg << B_TRANSLATE(": The server does not support APOP."); ShowError(error_msg.String()); return B_NOT_ALLOWED; } } ReportProgress(0, 0, B_TRANSLATE("Sending username" B_UTF8_ELLIPSIS)); BString cmd = "USER "; cmd += uid; cmd += CRLF; err = SendCommand(cmd.String()); if (err != B_OK) { error_msg << B_TRANSLATE(". The server said:\n") << fLog; ShowError(error_msg.String()); return err; } ReportProgress(0, 0, B_TRANSLATE("Sending password" B_UTF8_ELLIPSIS)); cmd = "PASS "; cmd += password; cmd += CRLF; err = SendCommand(cmd.String()); if (err != B_OK) { error_msg << B_TRANSLATE(". The server said:\n") << fLog; ShowError(error_msg.String()); return err; } return B_OK; }
void TMailApp::RefsReceived(BMessage *msg) { bool have_names = false; BString names; char type[B_FILE_NAME_LENGTH]; int32 item = 0; BFile file; TMailWindow *window; entry_ref ref; // // If a tracker window opened me, get a messenger from it. // BMessenger messenger; if (msg->HasMessenger("TrackerViewToken")) msg->FindMessenger("TrackerViewToken", &messenger); while (msg->HasRef("refs", item)) { msg->FindRef("refs", item++, &ref); if ((window = FindWindow(ref)) != NULL) window->Activate(true); else { file.SetTo(&ref, O_RDONLY); if (file.InitCheck() == B_NO_ERROR) { BNodeInfo node(&file); node.GetType(type); if (strcmp(type, B_MAIL_TYPE) == 0 || strcmp(type, B_PARTIAL_MAIL_TYPE) == 0) { window = NewWindow(&ref, NULL, false, &messenger); window->Show(); } else if(strcmp(type, "application/x-person") == 0) { /* Got a People contact info file, see if it has an Email address. */ BString name; BString email; attr_info info; char *attrib; if (file.GetAttrInfo("META:email", &info) == B_NO_ERROR) { attrib = (char *) malloc(info.size + 1); file.ReadAttr("META:email", B_STRING_TYPE, 0, attrib, info.size); attrib[info.size] = 0; // Just in case it wasn't NUL terminated. email << attrib; free(attrib); /* we got something... */ if (email.Length() > 0) { /* see if we can get a username as well */ if(file.GetAttrInfo("META:name", &info) == B_NO_ERROR) { attrib = (char *) malloc(info.size + 1); file.ReadAttr("META:name", B_STRING_TYPE, 0, attrib, info.size); attrib[info.size] = 0; // Just in case it wasn't NUL terminated. name << "\"" << attrib << "\" "; email.Prepend("<"); email.Append(">"); free(attrib); } if (names.Length() == 0) { names << name << email; } else { names << ", " << name << email; } have_names = true; email.SetTo(""); name.SetTo(""); } } } else if (strcmp(type, kDraftType) == 0) { window = NewWindow(); // If it's a draft message, open it window->OpenMessage(&ref); window->Show(); } } /* end of else(file.InitCheck() == B_NO_ERROR */ } } if (have_names) { window = NewWindow(NULL, names.String()); window->Show(); } }
void File::ExtractFile( int i, const BString & FileName ) { XZip::UnzipItem( ( XZip::HZIP )m_pRead, i, FileName.c_str() ); }
status_t MediaFileInfo::LoadInfo(BMediaFile* file) { _Reset(); if (!file) return B_BAD_VALUE; BMediaTrack* track; media_format format; memset(&format, 0, sizeof(format)); media_codec_info codecInfo; bool audioDone(false), videoDone(false); bigtime_t audioDuration = 0; bigtime_t videoDuration = 0; int32 tracks = file->CountTracks(); int64 videoFrames = 0; int64 audioFrames = 0; status_t ret = B_OK; for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) { track = file->TrackAt(i); if (track == NULL) return B_ERROR; ret = track->InitCheck(); if (ret != B_OK) return ret; ret = track->EncodedFormat(&format); if (ret != B_OK) return ret; if (format.IsVideo()) { memset(&format, 0, sizeof(format)); format.type = B_MEDIA_RAW_VIDEO; ret = track->DecodedFormat(&format); if (ret != B_OK) return ret; media_raw_video_format *rvf = &(format.u.raw_video); ret = track->GetCodecInfo(&codecInfo); if (ret != B_OK) return ret; video.format << codecInfo.pretty_name; videoDuration = track->Duration(); videoFrames = track->CountFrames(); BString details; snprintf(details.LockBuffer(256), 256, B_TRANSLATE_COMMENT("%u x %u, %.2ffps / %Ld frames", "Width x Height, fps / frames"), format.Width(), format.Height(), rvf->field_rate / rvf->interlace, videoFrames); details.UnlockBuffer(); video.details << details; videoDone = true; } else if (format.IsAudio()) { memset(&format, 0, sizeof(format)); format.type = B_MEDIA_RAW_AUDIO; ret = track->DecodedFormat(&format); if (ret != B_OK) return ret; media_raw_audio_format *raf = &(format.u.raw_audio); char bytesPerSample = (char)(raf->format & 0xf); BString details; if (bytesPerSample == 1 || bytesPerSample == 2) { snprintf(details.LockBuffer(16), 16, B_TRANSLATE("%d bit "), bytesPerSample * 8); } else { snprintf(details.LockBuffer(16), 16, B_TRANSLATE("%d byte "), bytesPerSample); } details.UnlockBuffer(); audio.details << details; ret = track->GetCodecInfo(&codecInfo); if (ret != B_OK) return ret; audio.format << codecInfo.pretty_name; audioDuration = track->Duration(); audioFrames = track->CountFrames(); BString channels; if (raf->channel_count == 1) { snprintf(channels.LockBuffer(64), 64, B_TRANSLATE("%.1f kHz mono / %lld frames"), raf->frame_rate / 1000.f, audioFrames); } else if (raf->channel_count == 2) { snprintf(channels.LockBuffer(64), 64, B_TRANSLATE("%.1f kHz stereo / %lld frames"), raf->frame_rate / 1000.f, audioFrames); } else { snprintf(channels.LockBuffer(64), 64, B_TRANSLATE("%.1f kHz %ld channel / %lld frames"), raf->frame_rate / 1000.f, raf->channel_count, audioFrames); } channels.UnlockBuffer(); audio.details << channels; audioDone = true; } ret = file->ReleaseTrack(track); if (ret != B_OK) return ret; } useconds = MAX(audioDuration, videoDuration); duration << (int32)(useconds / 1000000) << B_TRANSLATE(" seconds"); return B_OK; }
BOOTIL_EXPORT void DebuggerOutput( const BString & strText ) { OutputDebugString( strText.c_str() ); }
void GetExtension(const BString &name, BString &string) { int i = name.Length(); while ((i >= 0) && (name[i] != '.')) i--; if (i >= 0) string = BString(&name.String()[i+1]); string.ToUpper(); }
BOOTIL_EXPORT void ChangeDir( const BString & strName ) { chdir( strName.c_str() ); }
bool CraftingManager::HandleNextCraftingStage(Object* object, Object* target,Message* message, ObjectControllerCmdProperties* cmdProperties) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(object); CraftingSession* session = playerObject->getCraftingSession(); BString dataStr; uint32 counter = 1; if(!session) return false; message->getStringUnicode16(dataStr); if(dataStr.getLength() == 0) { //Command Line Entry counter = session->getCounter(); } else { uint32 resultCount = swscanf(dataStr.getUnicode16(),L"%u",&counter); if(resultCount != 1) { gCraftingSessionFactory->destroySession(session); return false; } } switch(session->getStage()) { case 1: { //Player's Macro is wrong! :p } break; case 2: { session->assemble(counter); } break; case 3: { session->experimentationStage(counter); } break; case 4: { session->customizationStage(counter); //session->creationStage(counter); } break; case 5: { session->creationStage(counter); } break; default: { } break; } return true; }
THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming, BEmailMessage *mail, bool resending, uint32 defaultCharacterSet, uint32 defaultChain) : BBox(rect, "m_header", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW, B_NO_BORDER), fAccountMenu(NULL), fEncodingMenu(NULL), fChain(defaultChain), fAccountTo(NULL), fAccount(NULL), fBcc(NULL), fCc(NULL), fSubject(NULL), fTo(NULL), fDateLabel(NULL), fDate(NULL), fIncoming(incoming), fCharacterSetUserSees(defaultCharacterSet), fResending(resending), fBccMenu(NULL), fCcMenu(NULL), fToMenu(NULL), fEmailList(NULL) { BMenuField* field; BMessage* msg; float x = StringWidth( /* The longest title string in the header area */ TR("Attachments: ")) + 9; float y = TO_FIELD_V; BMenuBar* dummy = new BMenuBar(BRect(0, 0, 100, 15), "Dummy"); AddChild(dummy); float width, menuBarHeight; dummy->GetPreferredSize(&width, &menuBarHeight); dummy->RemoveSelf(); delete dummy; float menuFieldHeight = menuBarHeight + 6; float controlHeight = menuBarHeight + floorf(be_plain_font->Size() / 1.15); if (!fIncoming) { InitEmailCompletion(); InitGroupCompletion(); } // Prepare the character set selection pop-up menu (we tell the user that // it is the Encoding menu, even though it is really the character set). // It may appear in the first line, to the right of the From box if the // user is reading an e-mail. It appears on the second line, to the right // of the e-mail account menu, if the user is composing a message. It lets // the user quickly select a character set different from the application // wide default one, and also shows them which character set is active. If // you are reading a message, you also see an item that says "Automatic" // for automatic decoding character set choice. It can slide around as the // window is resized when viewing a message, but not when composing // (because the adjacent pop-up menu can't resize dynamically due to a BeOS // bug). float widestCharacterSet = 0; bool markedCharSet = false; BMenuItem* item; fEncodingMenu = new BPopUpMenu(B_EMPTY_STRING); BCharacterSetRoster roster; BCharacterSet charset; while (roster.GetNextCharacterSet(&charset) == B_OK) { BString name(charset.GetPrintName()); const char* mime = charset.GetMIMEName(); if (mime) name << " (" << mime << ")"; uint32 convertID; if (mime == NULL || strcasecmp(mime, "UTF-8") != 0) convertID = charset.GetConversionID(); else convertID = B_MAIL_UTF8_CONVERSION; msg = new BMessage(kMsgEncoding); msg->AddInt32("charset", convertID); fEncodingMenu->AddItem(item = new BMenuItem(name.String(), msg)); if (convertID == fCharacterSetUserSees && !markedCharSet) { item->SetMarked(true); markedCharSet = true; } if (StringWidth(name.String()) > widestCharacterSet) widestCharacterSet = StringWidth(name.String()); } msg = new BMessage(kMsgEncoding); msg->AddInt32("charset", B_MAIL_US_ASCII_CONVERSION); fEncodingMenu->AddItem(item = new BMenuItem("US-ASCII", msg)); if (fCharacterSetUserSees == B_MAIL_US_ASCII_CONVERSION && !markedCharSet) { item->SetMarked(true); markedCharSet = true; } if (!resending && fIncoming) { // reading a message, display the Automatic item fEncodingMenu->AddSeparatorItem(); msg = new BMessage(kMsgEncoding); msg->AddInt32("charset", B_MAIL_NULL_CONVERSION); fEncodingMenu->AddItem(item = new BMenuItem("Automatic", msg)); if (!markedCharSet) item->SetMarked(true); } // First line of the header, From for reading e-mails (includes the // character set choice at the right), To when composing (nothing else in // the row). BRect r; char string[20]; if (fIncoming && !resending) { // Set up the character set pop-up menu on the right of "To" box. r.Set (windowRect.Width() - widestCharacterSet - StringWidth (TR("Decoding:")) - 2 * SEPARATOR_MARGIN, y - 2, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight); field = new BMenuField (r, "decoding", TR("Decoding:"), fEncodingMenu, true /* fixedSize */, B_FOLLOW_TOP | B_FOLLOW_RIGHT, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP); field->SetDivider(field->StringWidth(TR("Decoding:")) + 5); AddChild(field); r.Set(SEPARATOR_MARGIN, y, field->Frame().left - SEPARATOR_MARGIN, y + menuFieldHeight); sprintf(string, TR("From:")); } else { r.Set(x - 12, y, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight); string[0] = 0; } y += controlHeight; fTo = new TTextControl(r, string, new BMessage(TO_FIELD), fIncoming, resending, B_FOLLOW_LEFT_RIGHT); fTo->SetFilter(mail_to_filter); if (!fIncoming || resending) { fTo->SetChoiceList(&fEmailList); fTo->SetAutoComplete(true); } else { fTo->SetDivider(x - 12 - SEPARATOR_MARGIN); fTo->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); } AddChild(fTo); msg = new BMessage(FIELD_CHANGED); msg->AddInt32("bitmask", FIELD_TO); fTo->SetModificationMessage(msg); if (!fIncoming || resending) { r.right = r.left - 5; r.left = r.right - ceilf(be_plain_font->StringWidth(TR("To:")) + 25); r.top -= 1; fToMenu = new QPopupMenu(TR("To:")); field = new BMenuField(r, "", "", fToMenu, true, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); field->SetDivider(0.0); field->SetEnabled(true); AddChild(field); } // "From:" accounts Menu and Encoding Menu. if (!fIncoming || resending) { // Put the character set box on the right of the From field. r.Set(windowRect.Width() - widestCharacterSet - StringWidth(TR("Encoding:")) - 2 * SEPARATOR_MARGIN, y - 2, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight); BMenuField* encodingField = new BMenuField(r, "encoding", TR("Encoding:"), fEncodingMenu, true /* fixedSize */, B_FOLLOW_TOP | B_FOLLOW_RIGHT, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP); encodingField->SetDivider(encodingField->StringWidth(TR("Encoding:")) + 5); AddChild(encodingField); field = encodingField; // And now the "from account" pop-up menu, on the left side, taking the // remaining space. fAccountMenu = new BPopUpMenu(B_EMPTY_STRING); BList chains; if (GetOutboundMailChains(&chains) >= B_OK) { bool marked = false; for (int32 i = 0; i < chains.CountItems(); i++) { BMailChain *chain = (BMailChain *)chains.ItemAt(i); BString name = chain->Name(); if ((msg = chain->MetaData()) != NULL) { name << ": " << msg->FindString("real_name") << " <" << msg->FindString("reply_to") << ">"; } BMenuItem *item = new BMenuItem(name.String(), msg = new BMessage(kMsgFrom)); msg->AddInt32("id", chain->ID()); if (defaultChain == chain->ID()) { item->SetMarked(true); marked = true; } fAccountMenu->AddItem(item); delete chain; } if (!marked) { BMenuItem *item = fAccountMenu->ItemAt(0); if (item != NULL) { item->SetMarked(true); fChain = item->Message()->FindInt32("id"); } else { fAccountMenu->AddItem(item = new BMenuItem("<none>",NULL)); item->SetEnabled(false); fChain = ~0UL; } // default chain is invalid, set to marked // TODO: do this differently, no casting and knowledge // of TMailApp here.... if (TMailApp* app = dynamic_cast<TMailApp*>(be_app)) app->SetDefaultChain(fChain); } } r.Set(SEPARATOR_MARGIN, y - 2, field->Frame().left - SEPARATOR_MARGIN, y + menuFieldHeight); field = new BMenuField(r, "account", TR("From:"), fAccountMenu, true /* fixedSize */, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP); AddChild(field, encodingField); field->SetDivider(x - 12 - SEPARATOR_MARGIN + kMenuFieldDividerOffset); field->SetAlignment(B_ALIGN_RIGHT); y += controlHeight; } else { // To: account bool account = count_pop_accounts() > 0; r.Set(SEPARATOR_MARGIN, y, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight); if (account) r.right -= SEPARATOR_MARGIN + ACCOUNT_FIELD_WIDTH; fAccountTo = new TTextControl(r, TR("To:"), NULL, fIncoming, false, B_FOLLOW_LEFT_RIGHT); fAccountTo->SetEnabled(false); fAccountTo->SetDivider(x - 12 - SEPARATOR_MARGIN); fAccountTo->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); AddChild(fAccountTo); if (account) { r.left = r.right + 6; r.right = windowRect.Width() - SEPARATOR_MARGIN; fAccount = new TTextControl(r, TR("Account:"), NULL, fIncoming, false, B_FOLLOW_RIGHT | B_FOLLOW_TOP); fAccount->SetEnabled(false); AddChild(fAccount); } y += controlHeight; } --y; r.Set(SEPARATOR_MARGIN, y, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight); y += controlHeight; fSubject = new TTextControl(r, TR("Subject:"), new BMessage(SUBJECT_FIELD), fIncoming, false, B_FOLLOW_LEFT_RIGHT); AddChild(fSubject); (msg = new BMessage(FIELD_CHANGED))->AddInt32("bitmask", FIELD_SUBJECT); fSubject->SetModificationMessage(msg); fSubject->SetDivider(x - 12 - SEPARATOR_MARGIN); fSubject->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); if (fResending) fSubject->SetEnabled(false); --y; if (!fIncoming) { r.Set(x - 12, y, CC_FIELD_H + CC_FIELD_WIDTH, y + menuFieldHeight); fCc = new TTextControl(r, "", new BMessage(CC_FIELD), fIncoming, false); fCc->SetFilter(mail_to_filter); fCc->SetChoiceList(&fEmailList); fCc->SetAutoComplete(true); AddChild(fCc); (msg = new BMessage(FIELD_CHANGED))->AddInt32("bitmask", FIELD_CC); fCc->SetModificationMessage(msg); r.right = r.left - 5; r.left = r.right - ceilf(be_plain_font->StringWidth(TR("Cc:")) + 25); r.top -= 1; fCcMenu = new QPopupMenu(TR("Cc:")); field = new BMenuField(r, "", "", fCcMenu, true, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); field->SetDivider(0.0); field->SetEnabled(true); AddChild(field); r.Set(BCC_FIELD_H + be_plain_font->StringWidth(TR("Bcc:")), y, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight); y += controlHeight; fBcc = new TTextControl(r, "", new BMessage(BCC_FIELD), fIncoming, false, B_FOLLOW_LEFT_RIGHT); fBcc->SetFilter(mail_to_filter); fBcc->SetChoiceList(&fEmailList); fBcc->SetAutoComplete(true); AddChild(fBcc); (msg = new BMessage(FIELD_CHANGED))->AddInt32("bitmask", FIELD_BCC); fBcc->SetModificationMessage(msg); r.right = r.left - 5; r.left = r.right - ceilf(be_plain_font->StringWidth(TR("Bcc:")) + 25); r.top -= 1; fBccMenu = new QPopupMenu(TR("Bcc:")); field = new BMenuField(r, "", "", fBccMenu, true, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); field->SetDivider(0.0); field->SetEnabled(true); AddChild(field); } else { y -= SEPARATOR_MARGIN; r.Set(SEPARATOR_MARGIN, y, x - 12 - 1, y + menuFieldHeight); fDateLabel = new BStringView(r, "", kDateLabel); fDateLabel->SetAlignment(B_ALIGN_RIGHT); AddChild(fDateLabel); fDateLabel->SetHighColor(0, 0, 0); r.Set(r.right + 9, y, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight); fDate = new BStringView(r, "", ""); AddChild(fDate); fDate->SetHighColor(0, 0, 0); y += controlHeight + 5; LoadMessage(mail); } ResizeTo(Bounds().Width(), y); }
void MarkupParser::_ParseText(const BString& text) { int32 start = 0; int32 offset = 0; int32 charCount = text.CountChars(); const char* c = text.String(); while (offset <= charCount) { uint32 nextChar = UTF8ToCharCode(&c); switch (nextChar) { case '\n': case '\0': _CopySpan(text, start, offset); _FinishParagraph(); start = offset + 1; break; case '\'': if (offset + 2 < charCount && c[0] == '\'') { int32 tickCount = 2; if (c[1] == '\'') tickCount = 3; // Copy previous span using current style, excluding the // ticks. _CopySpan(text, start, offset); if (tickCount == 2) _ToggleStyle(fItalicStyle); else if (tickCount == 3) _ToggleStyle(fBoldStyle); // Don't include the ticks in the next span. offset += tickCount - 1; start = offset + 1; c += tickCount - 1; } break; case '=': // Detect headings if (offset == start && fCurrentParagraph.IsEmpty() && offset + 2 < charCount && c[0] == '=' && c[1] == ' ') { fCurrentParagraph.SetStyle(fHeadingParagraphStyle); fCurrentCharacterStyle = &fHeadingStyle; offset += 2; c += 2; start = offset + 1; } else if (offset > start && offset + 2 < charCount && c[0] == '=' && c[1] == '\n') { _CopySpan(text, start, offset - 1); _FinishParagraph(); offset += 2; c += 2; start = offset + 1; } break; case ' ': // Detect bullets at line starts if (offset == start && fCurrentParagraph.IsEmpty() && offset + 2 < charCount && c[0] == '*' && c[1] == ' ') { fCurrentParagraph.SetStyle(fBulletStyle); offset += 2; c += 2; start = offset + 1; } break; default: break; } offset++; } }
void THeaderView::InitGroupCompletion() { // get boot volume BVolume volume; BVolumeRoster().GetBootVolume(&volume); // Build a list of all unique groups and the addresses they expand to. BQuery query; query.SetVolume(&volume); query.SetPredicate("META:group=**"); query.Fetch(); map<BString *, BString *, CompareBStrings> groupMap; entry_ref ref; BNode file; while (query.GetNextRef(&ref) == B_OK) { if (file.SetTo(&ref) != B_OK) continue; BString groups; if (ReadAttrString(&file, "META:group", &groups) < B_OK || groups.Length() == 0) continue; BString address; ReadAttrString(&file, "META:email", &address); // avoid adding an empty address if (address.Length() == 0) continue; char *group = groups.LockBuffer(groups.Length()); char *next = strchr(group, ','); for (;;) { if (next) *next = 0; while (*group && *group == ' ') group++; BString *groupString = new BString(group); BString *addressListString = NULL; // nobody is in this group yet, start it off if (groupMap[groupString] == NULL) { addressListString = new BString(*groupString); addressListString->Append(" "); groupMap[groupString] = addressListString; } else { addressListString = groupMap[groupString]; addressListString->Append(", "); delete groupString; } // Append the user's address to the end of the string with the // comma separated list of addresses. If not present, add the // < and > brackets around the address. if (address.FindFirst ('<') < 0) { address.ReplaceAll ('>', '_'); address.Prepend ("<"); address.Append(">"); } addressListString->Append(address); if (!next) break; group = next + 1; next = strchr(group, ','); } } map<BString *, BString *, CompareBStrings>::iterator iter; for (iter = groupMap.begin(); iter != groupMap.end();) { BString *group = iter->first; BString *addr = iter->second; fEmailList.AddChoice(addr->String()); ++iter; groupMap.erase(group); delete group; delete addr; } }
void UrlWrapper::RefsReceived(BMessage* msg) { char buff[B_PATH_NAME_LENGTH]; int32 index = 0; entry_ref ref; char* args[] = { const_cast<char*>("urlwrapper"), buff, NULL }; status_t err; while (msg->FindRef("refs", index++, &ref) == B_OK) { BFile f(&ref, B_READ_ONLY); BNodeInfo ni(&f); BString mimetype; BString extension(ref.name); extension.Remove(0, extension.FindLast('.') + 1); if (f.InitCheck() == B_OK && ni.InitCheck() == B_OK) { ni.GetType(mimetype.LockBuffer(B_MIME_TYPE_LENGTH)); mimetype.UnlockBuffer(); // Internet Explorer Shortcut if (mimetype == "text/x-url" || extension == "url") { // http://filext.com/file-extension/URL // http://www.cyanwerks.com/file-format-url.html off_t size; if (f.GetSize(&size) < B_OK) continue; BString contents; BString url; if (f.ReadAt(0LL, contents.LockBuffer(size), size) < B_OK) continue; contents.UnlockBuffer(); while (contents.Length()) { BString line; int32 cr = contents.FindFirst('\n'); if (cr < 0) cr = contents.Length(); //contents.MoveInto(line, 0, cr); contents.CopyInto(line, 0, cr); contents.Remove(0, cr+1); line.RemoveAll("\r"); if (!line.Length()) continue; if (!line.ICompare("URL=", 4)) { line.MoveInto(url, 4, line.Length()); break; } } if (url.Length()) { BUrl u(url.String()); args[1] = (char*)u.UrlString().String(); mimetype = kURLHandlerSigBase; mimetype += u.Protocol(); err = be_roster->Launch(mimetype.String(), 1, args + 1); if (err != B_OK && err != B_ALREADY_RUNNING) err = be_roster->Launch(kAppSig, 1, args + 1); continue; } } if (mimetype == "text/x-webloc" || extension == "webloc") { // OSX url shortcuts // XML file + resource fork off_t size; if (f.GetSize(&size) < B_OK) continue; BString contents; BString url; if (f.ReadAt(0LL, contents.LockBuffer(size), size) < B_OK) continue; contents.UnlockBuffer(); int state = 0; while (contents.Length()) { BString line; int32 cr = contents.FindFirst('\n'); if (cr < 0) cr = contents.Length(); contents.CopyInto(line, 0, cr); contents.Remove(0, cr+1); line.RemoveAll("\r"); if (!line.Length()) continue; int32 s, e; switch (state) { case 0: if (!line.ICompare("<?xml", 5)) state = 1; break; case 1: if (!line.ICompare("<plist", 6)) state = 2; break; case 2: if (!line.ICompare("<dict>", 6)) state = 3; break; case 3: if (line.IFindFirst("<key>URL</key>") > -1) state = 4; break; case 4: if ((s = line.IFindFirst("<string>")) > -1 && (e = line.IFindFirst("</string>")) > s) { state = 5; s += 8; line.MoveInto(url, s, e - s); break; } else state = 3; break; default: break; } if (state == 5) { break; } } if (url.Length()) { BUrl u(url.String()); args[1] = (char*)u.UrlString().String(); mimetype = kURLHandlerSigBase; mimetype += u.Protocol(); err = be_roster->Launch(mimetype.String(), 1, args + 1); if (err != B_OK && err != B_ALREADY_RUNNING) err = be_roster->Launch(kAppSig, 1, args + 1); continue; } } // NetPositive Bookmark or any file with a META:url attribute if (f.ReadAttr("META:url", B_STRING_TYPE, 0LL, buff, B_PATH_NAME_LENGTH) > 0) { BUrl u(buff); args[1] = (char*)u.UrlString().String(); mimetype = kURLHandlerSigBase; mimetype += u.Protocol(); err = be_roster->Launch(mimetype.String(), 1, args + 1); if (err != B_OK && err != B_ALREADY_RUNNING) err = be_roster->Launch(kAppSig, 1, args + 1); continue; } } } }