void BTrashWatcher::UpdateTrashIcons() { BVolume boot; if (BVolumeRoster().GetBootVolume(&boot) != B_OK) return; BDirectory trashDir; if (FSGetTrashDir(&trashDir, boot.Device()) == B_OK) { // pull out the icons for the current trash state from resources and // apply them onto the trash directory node size_t largeSize = 0; size_t smallSize = 0; const void *largeData = GetTrackerResources()->LoadResource('ICON', fTrashFull ? kResTrashFullIcon : kResTrashIcon, &largeSize); const void *smallData = GetTrackerResources()->LoadResource('MICN', fTrashFull ? kResTrashFullIcon : kResTrashIcon, &smallSize); if (largeData) trashDir.WriteAttr(kAttrLargeIcon, 'ICON', 0, largeData, largeSize); else TRESPASS(); if (smallData) trashDir.WriteAttr(kAttrMiniIcon, 'MICN', 0, smallData, smallSize); else TRESPASS(); } }
bool LprSetupView::UpdateViewData() { if (*fServer->Text() && *fQueue->Text()) { try { LpsClient lpr(fServer->Text()); lpr.connect(); } catch (LPSException &err) { BAlert *alert = new BAlert("", err.what(), "OK"); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); return false; } fDir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, fServer->Text(), strlen(fServer->Text()) + 1); fDir->WriteAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, fQueue->Text(), strlen(fQueue->Text()) + 1); return true; } BAlert *alert = new BAlert("", "Please enter server address and printer" "queue name.", "OK"); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); return false; }
void BTrashWatcher::UpdateTrashIcons() { BVolumeRoster roster; BVolume volume; roster.Rewind(); BDirectory trashDir; while (roster.GetNextVolume(&volume) == B_OK) { if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK) { // pull out the icons for the current trash state from resources // and apply them onto the trash directory node size_t largeSize = 0; size_t smallSize = 0; const void* largeData = GetTrackerResources()->LoadResource('ICON', fTrashFull ? R_TrashFullIcon : R_TrashIcon, &largeSize); const void* smallData = GetTrackerResources()->LoadResource('MICN', fTrashFull ? R_TrashFullIcon : R_TrashIcon, &smallSize); #ifdef HAIKU_TARGET_PLATFORM_HAIKU size_t vectorSize = 0; const void* vectorData = GetTrackerResources()->LoadResource( B_VECTOR_ICON_TYPE, fTrashFull ? R_TrashFullIcon : R_TrashIcon, &vectorSize); if (vectorData) { trashDir.WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0, vectorData, vectorSize); } else TRESPASS(); #endif if (largeData) { trashDir.WriteAttr(kAttrLargeIcon, 'ICON', 0, largeData, largeSize); } else TRESPASS(); if (smallData) { trashDir.WriteAttr(kAttrMiniIcon, 'MICN', 0, smallData, smallSize); } else TRESPASS(); } } }
bool SetupView::CheckSetup() { if (*fServerAddress->Text() && *fQueuePort->Text()) { BNetEndpoint* ep = new BNetEndpoint(SOCK_STREAM); if (ep->InitCheck() == B_NO_ERROR) { uint16 port = atoi(fQueuePort->Text()); if (! port) port = 9100; if (ep->Connect(fServerAddress->Text(), port) != B_OK) { BString text; text << "Fail to connect to " << fServerAddress->Text() << ":" << (int) port << "!"; BAlert* alert = new BAlert("", text.String(), "OK"); alert->Go(); return false; }; char str[256]; sprintf(str, "%s:%d", fServerAddress->Text(), port); fPrinterDirectory->WriteAttr("transport_address", B_STRING_TYPE, 0, str, strlen(str) + 1); return true; }; }; BAlert* alert = new BAlert("", "please input parameters.", "OK"); alert->Go(); return false; }
bool IppSetupView::UpdateViewData() { string error_msg; if (*url->Text()) { IppContent *request = new IppContent; request->setOperationId(IPP_GET_PRINTER_ATTRIBUTES); request->setDelimiter(IPP_OPERATION_ATTRIBUTES_TAG); request->setCharset("attributes-charset", "utf-8"); request->setNaturalLanguage("attributes-natural-language", "en-us"); request->setURI("printer-uri", url->Text()); request->setDelimiter(IPP_END_OF_ATTRIBUTES_TAG); IppURLConnection conn(URL(url->Text())); conn.setIppRequest(request); conn.setRequestProperty("Connection", "close"); HTTP_RESPONSECODE response_code = conn.getResponseCode(); if (response_code == HTTP_OK) { const char *content_type = conn.getContentType(); if (content_type && !strncasecmp(content_type, "application/ipp", 15)) { const IppContent *ipp_response = conn.getIppResponse(); if (ipp_response->good()) { dir->WriteAttr(IPP_URL, B_STRING_TYPE, 0, url->Text(), strlen(url->Text()) + 1); return true; } else { error_msg = ipp_response->getStatusMessage(); } } else { error_msg = "cannot get a IPP response."; } } else if (response_code != HTTP_UNKNOWN) { error_msg = conn.getResponseMessage(); } else { error_msg = "cannot connect to the IPP server."; } } else { error_msg = "please input the printer URL."; } BAlert *alert = new BAlert("", error_msg.c_str(), "OK"); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); return false; }
bool TTracker::QuitRequested() { // don't allow user quitting if (CurrentMessage() && CurrentMessage()->FindBool("shortcut")) return false; gStatusWindow->AttemptToQuit(); // try quitting the copy/move/empty trash threads BVolume bootVolume; DEBUG_ONLY(status_t err =) BVolumeRoster().GetBootVolume(&bootVolume); ASSERT(err == B_OK); BMessage message; AutoLock<WindowList> lock(&fWindowList); // save open windows in a message inside an attribute of the desktop int32 count = fWindowList.CountItems(); for (int32 i = 0; i < count; i++) { BContainerWindow *window = dynamic_cast<BContainerWindow *> (fWindowList.ItemAt(i)); if (window && window->TargetModel() && !window->PoseView()->IsDesktopWindow()) { if (window->TargetModel()->IsRoot()) message.AddBool("open_disks_window", true); else { BEntry entry; BPath path; const entry_ref *ref = window->TargetModel()->EntryRef(); if (entry.SetTo(ref) == B_OK && entry.GetPath(&path) == B_OK) { int8 flags = window->IsMinimized() ? kOpenWindowMinimized : kOpenWindowNoFlags; uint32 deviceFlags = GetVolumeFlags(window->TargetModel()); // save state for every window which is // a) already open on another workspace // b) on a volume not capable of writing attributes if (window != FindContainerWindow(ref) || (deviceFlags & (B_FS_HAS_ATTR | B_FS_IS_READONLY)) != B_FS_HAS_ATTR) { BMessage stateMessage; window->SaveState(stateMessage); window->SetSaveStateEnabled(false); // This is to prevent its state to be saved to the node when closed. message.AddMessage("window state", &stateMessage); flags |= kOpenWindowHasState; } const char *target; bool pathAlreadyExists = false; for (int32 index = 0;message.FindString("paths", index, &target) == B_OK;index++) { if (!strcmp(target,path.Path())) { pathAlreadyExists = true; break; } } if (!pathAlreadyExists) message.AddString("paths", path.Path()); message.AddInt8(path.Path(), flags); } } } } lock.Unlock(); // write windows to open on disk BDirectory deskDir; if (!BootedInSafeMode() && FSGetDeskDir(&deskDir, bootVolume.Device()) == B_OK) { // if message is empty, delete the corresponding attribute if (message.CountNames(B_ANY_TYPE)) { size_t size = (size_t)message.FlattenedSize(); char *buffer = new char[size]; message.Flatten(buffer, (ssize_t)size); deskDir.WriteAttr(kAttrOpenWindows, B_MESSAGE_TYPE, 0, buffer, size); delete [] buffer; } else deskDir.RemoveAttr(kAttrOpenWindows); } for (int32 count = 0; count == 50; count++) { // wait 5 seconds for the copiing/moving to quit if (gStatusWindow->AttemptToQuit()) break; snooze(100000); } return _inherited::QuitRequested(); }
status_t RunPopUpMenu(BPoint where, BString &header, BString &fileName, CLanguageInterface *languageInterface) { status_t err; BPath path; BDirectory dir; err = GetSettingsDir(dir, path); err = B_ERROR; BPopUpMenu *menu = BuildPopUp(dir); if (menu == NULL) return B_ERROR; BMenuItem *item = menu->Go(where, false, true); //if (item && item->Message()) // item->Message()->PrintToStream(); switch ((item && item->Message()) ? item->Message()->what : 0) { case 'head': { if (item->Message()->FindString("template", &header) < B_OK) break; BString tmp; time_t now = time(NULL); struct tm *tim = localtime(&now); // date char *p; p = tmp.LockBuffer(100); memset(p, 0, 100); strftime(p, 100, "%Y-%m-%d", tim); tmp.UnlockBuffer(); header.ReplaceAll("%DATE%", tmp.String()); tmp.Truncate(0); p = tmp.LockBuffer(100); memset(p, 0, 100); strftime(p, 100, "%T", tim); tmp.UnlockBuffer(); header.ReplaceAll("%TIME%", tmp.String()); tmp.Truncate(0); // year p = tmp.LockBuffer(10); memset(p, 0, 10); strftime(p, 10, "%Y", tim); tmp.UnlockBuffer(); header.ReplaceAll("%YEAR%", tmp.String()); tmp.Truncate(0); // fetch from query on META:email==** ? p = tmp.LockBuffer(B_PATH_NAME_LENGTH); memset(p, 0, B_PATH_NAME_LENGTH); err = dir.ReadAttr("pe:author_people", B_STRING_TYPE, 0LL, p, B_PATH_NAME_LENGTH); tmp.UnlockBuffer(); //printf("ppl:%s\n", tmp.String()); BNode people; if (err > 0) people.SetTo(tmp.String()); tmp.Truncate(0); BString attr; static struct { const char *tmplName; const char *attrName; } attrMap[] = { { "%AUTHOR%", "META:name" }, { "%AUTHORMAIL%", "META:email" }, { "%COMPANY%", "META:company" }, { "%AUTHORURL%", "META:url" }, { NULL, NULL } }; int i; for (i = 0; attrMap[i].tmplName; i++) { p = attr.LockBuffer(256); memset(p, 0, 256); err = people.ReadAttr(attrMap[i].attrName, B_ANY_TYPE, 0LL, p, 256); //printf("ReadAttr: %d, %s\n", err, attr.String()); attr.UnlockBuffer(); tmp << attr; header.ReplaceAll(attrMap[i].tmplName, tmp.String()); tmp.Truncate(0); attr.Truncate(0); } BString fileNameNoExt(fileName); if (fileNameNoExt.FindLast('.') > -1) fileNameNoExt.Truncate(fileNameNoExt.FindLast('.')); header.ReplaceAll("%FILENAMENOEXT%", fileNameNoExt.String()); header.ReplaceAll("%FILENAME%", fileName.String()); /* tmp << "Haiku"; header.ReplaceAll("%PROJECT%", tmp.String()); tmp.Truncate(0); */ // better values for C++ BString language("C/C++"); BString commentLineStart("/*"); BString commentLineEnd(""); BString commentBlockStart("/*"); BString commentBlockCont(" *"); BString commentBlockLazy(""); BString commentBlockLineEnd(""); BString commentBlockEnd(" */"); if (languageInterface) { // if not C++ if (language != languageInterface->Name()) { language = languageInterface->Name(); commentLineStart = languageInterface->LineCommentStart(); commentLineEnd = languageInterface->LineCommentEnd(); // I'd miss a CommentCanSpanLines() // let's assume line end means can span if (commentLineEnd.Length()) { commentBlockStart = commentLineStart; commentBlockCont = ""; commentBlockLazy = ""; commentBlockLineEnd = ""; commentBlockEnd = commentLineEnd; } else { commentBlockStart = commentLineStart; commentBlockCont = commentLineStart; commentBlockLazy = commentLineStart; commentBlockLineEnd = commentLineEnd; commentBlockEnd = commentLineStart; } /* printf("LANG:'%s' CS:'%s' CE:'%s'\n", language.String(), commentLineStart.String(), commentLineEnd.String()); */ } } // comment start header.ReplaceAll("%COMMS%", commentBlockStart.String()); // comment cont'd header.ReplaceAll("%COMMC%", commentBlockCont.String()); // comment cont'd lazy (blank if possible) header.ReplaceAll("%COMML%", commentBlockLazy.String()); // comment end header.ReplaceAll("%COMME%", commentBlockEnd.String()); // comment line end commentBlockLineEnd << "\n"; header.ReplaceAll("\n", commentBlockLineEnd.String()); err = B_OK; break; } case 'optf': { const char *args[] = {path.Path(), NULL}; err = be_roster->Launch(sTrackerSig, 1, (char **)args); //printf("err %s\n", strerror(err)); err = B_CANCELED; break; } case 'seta': { MimeRefFilter filter("application/x-person"); BPath path; entry_ref people; if (find_directory(B_USER_DIRECTORY, &path) == B_OK) { path.Append("people"); get_ref_for_path(path.Path(), &people); } BFilePanel *panel; panel = new BFilePanel(B_OPEN_PANEL, NULL, &people, B_FILE_NODE, false, NULL, &filter); // trick to synchronously use BFilePanel PanelHandler *handler = new PanelHandler; if (panel->Window()->Lock()) { panel->Window()->AddHandler(handler); panel->Window()->Unlock(); } panel->SetTarget(BMessenger(handler)); panel->Show(); if (handler->Wait() < B_OK) break; if (!handler->Message()) break; if (handler->Message()->what == B_CANCEL) break; entry_ref ref; //panel->Message()->PrintToStream(); if (panel->GetNextSelectedRef(&ref) == B_OK) { //printf("ref:%s\n", ref.name); path.SetTo(&ref); dir.WriteAttr("pe:author_people", B_STRING_TYPE, 0LL, path.Path(), strlen(path.Path())); } delete panel; delete handler; err = B_CANCELED; break; } case B_ABOUT_REQUESTED: { BString tmpPath("/tmp/Pe-HeaderHeader-About-"); tmpPath << system_time() << "-" << getpid() << ".txt"; entry_ref ref; get_ref_for_path(tmpPath.String(), &ref); { BFile f(&ref, B_CREATE_FILE | B_WRITE_ONLY); err = f.InitCheck(); if (err < 0) break; f.Write(sAboutText, strlen(sAboutText)); f.SetPermissions(0444); } BMessage msg(B_REFS_RECEIVED); msg.AddRef("refs", &ref); err = be_app_messenger.SendMessage(&msg); err = B_CANCELED; break; } case 0: err = B_CANCELED; break; default: break; } delete menu; return err; }