void BVolumeWindow::MenusBeginning() { _inherited::MenusBeginning(); if (!fMenuBar) return; BVolume boot; BVolumeRoster().GetBootVolume(&boot); bool ejectableVolumeSelected = false; int32 count = PoseView()->SelectionList()->CountItems(); for (int32 index = 0; index < count; index++) { Model *model = PoseView()->SelectionList()->ItemAt(index)->TargetModel(); if (model->IsVolume()) { BVolume volume; volume.SetTo(model->NodeRef()->device); if (volume != boot) { ejectableVolumeSelected = true; break; } } } BMenuItem* item = fMenuBar->FindItem(kUnmountVolume); if (item) item->SetEnabled(ejectableVolumeSelected); }
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(); } }
status_t QueryMenu::SetPredicate(const char *expr, BVolume *volume) { status_t status; // Set the volume if (volume == NULL) { BVolume bootVolume; BVolumeRoster().GetBootVolume(&bootVolume); if ( (status = fQuery->SetVolume(&bootVolume)) != B_OK) return status; } else if ((status = fQuery->SetVolume(volume)) != B_OK) return status; if ((status = fQuery->SetPredicate(expr)) < B_OK) return status; // Force query thread to exit if still running fCancelQuery = true; fQueryLock.Lock(); // Remove all existing menu items (if any... ) RemoveEntries(); fQueryLock.Unlock(); // Resolve Query/Build Menu in seperate thread thread_id thread; thread = spawn_thread(query_thread, "query menu thread", B_NORMAL_PRIORITY, this); return resume_thread(thread); }
bool TStatusWindow::_Exists(const char* status) { BVolume volume; BVolumeRoster().GetBootVolume(&volume); BQuery query; query.SetVolume(&volume); query.PushAttr(INDEX_STATUS); query.PushString(status); query.PushOp(B_EQ); query.Fetch(); BEntry entry; if (query.GetNextEntry(&entry) == B_NO_ERROR) return true; 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(); }
void TTracker::ReadyToRun() { gStatusWindow = new BStatusWindow(); InitMimeTypes(); InstallDefaultTemplates(); InstallIndices(); HideVarDir(); fTrashWatcher = new BTrashWatcher(); fTrashWatcher->Run(); fClipboardRefsWatcher = new BClipboardRefsWatcher(); fClipboardRefsWatcher->Run(); fAutoMounter = new AutoMounter(); fAutoMounter->Run(); fTaskLoop = new StandAloneTaskLoop(true); bool openDisksWindow = false; // open desktop window BContainerWindow *deskWindow = NULL; BVolume bootVol; BVolumeRoster().GetBootVolume(&bootVol); BDirectory deskDir; if (FSGetDeskDir(&deskDir, bootVol.Device()) == B_OK) { // create desktop BEntry entry; deskDir.GetEntry(&entry); Model *model = new Model(&entry); if (model->InitCheck() == B_OK) { AutoLock<WindowList> lock(&fWindowList); deskWindow = new BDeskWindow(&fWindowList); AutoLock<BWindow> windowLock(deskWindow); deskWindow->CreatePoseView(model); deskWindow->Init(); } else delete model; // open previously open windows attr_info attrInfo; if (!BootedInSafeMode() && deskDir.GetAttrInfo(kAttrOpenWindows, &attrInfo) == B_OK) { char *buffer = (char *)malloc((size_t)attrInfo.size); BMessage message; if (deskDir.ReadAttr(kAttrOpenWindows, B_MESSAGE_TYPE, 0, buffer, (size_t)attrInfo.size) == attrInfo.size && message.Unflatten(buffer) == B_OK) { node_ref nodeRef; deskDir.GetNodeRef(&nodeRef); int32 stateMessageCounter = 0; const char *path; for (int32 outer = 0;message.FindString("paths", outer, &path) == B_OK;outer++) { int8 flags = 0; for (int32 inner = 0;message.FindInt8(path, inner, &flags) == B_OK;inner++) { BEntry entry(path, true); if (entry.InitCheck() == B_OK) { Model *model = new Model(&entry); if (model->InitCheck() == B_OK && model->IsContainer()) { BMessage state; bool restoreStateFromMessage = false; if ((flags & kOpenWindowHasState) != 0 && message.FindMessage("window state", stateMessageCounter++, &state) == B_OK) restoreStateFromMessage = true; if (restoreStateFromMessage) OpenContainerWindow(model, 0, kOpen, kRestoreWorkspace | (flags & kOpenWindowMinimized ? kIsHidden : 0U), false, &state); else OpenContainerWindow(model, 0, kOpen, kRestoreWorkspace | (flags & kOpenWindowMinimized ? kIsHidden : 0U)); } else delete model; } } } if (message.HasBool("open_disks_window")) openDisksWindow = true; } free(buffer); } } // create model for root of everything if (deskWindow) { BEntry entry("/"); Model model(&entry); if (model.InitCheck() == B_OK) { if (TrackerSettings().ShowDisksIcon()) { // add the root icon to desktop window BMessage message; message.what = B_NODE_MONITOR; message.AddInt32("opcode", B_ENTRY_CREATED); message.AddInt32("device", model.NodeRef()->device); message.AddInt64("node", model.NodeRef()->node); message.AddInt64("directory", model.EntryRef()->directory); message.AddString("name", model.EntryRef()->name); deskWindow->PostMessage(&message, deskWindow->PoseView()); } if (openDisksWindow) OpenContainerWindow(new Model(model), 0, kOpen, kRestoreWorkspace); } } // kick off building the mime type list for find panels, etc. fMimeTypeList = new MimeTypeList(); if (!BootedInSafeMode()) // kick of transient query killer DeleteTransientQueriesTask::StartUpTransientQueryCleaner(); }
/*********************************************************** * InitGUI ***********************************************************/ void HAddressView::InitGUI() { float divider = StringWidth(_("Subject:")) + 20; divider = max_c(divider , StringWidth(_("From:"))+20); divider = max_c(divider , StringWidth(_("To:"))+20); divider = max_c(divider , StringWidth(_("Bcc:"))+20); BRect rect = Bounds(); rect.top += 5; rect.left += 20 + divider; rect.right = Bounds().right - 5; rect.bottom = rect.top + 25; BTextControl *ctrl; ResourceUtils rutils; const char* name[] = {"to","subject","from","cc","bcc"}; for(int32 i = 0;i < 5;i++) { ctrl = new BTextControl(BRect(rect.left,rect.top ,(i == 1)?rect.right+divider:rect.right ,rect.bottom) ,name[i],"","",NULL ,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_WILL_DRAW|B_NAVIGABLE); if(i == 1) { ctrl->SetLabel(_("Subject:")); ctrl->SetDivider(divider); ctrl->MoveBy(-divider,0); }else{ ctrl->SetDivider(0); } BMessage *msg = new BMessage(M_MODIFIED); msg->AddPointer("pointer",ctrl); ctrl->SetModificationMessage(msg); ctrl->SetEnabled(!fReadOnly); AddChild(ctrl); rect.OffsetBy(0,25); switch(i) { case 0: fTo = ctrl; break; case 1: fSubject = ctrl; break; case 2: fFrom = ctrl; fFrom->SetEnabled(false); fFrom->SetFlags(fFrom->Flags() & ~B_NAVIGABLE); break; case 3: fCc = ctrl; break; case 4: fBcc = ctrl; break; } } // BRect menuRect= Bounds(); menuRect.top += 5; menuRect.left += 22; menuRect.bottom = menuRect.top + 25; menuRect.right = menuRect.left + 16; BMenu *toMenu = new BMenu(_("To:")); BMenu *ccMenu = new BMenu(_("Cc:")); BMenu *bccMenu = new BMenu(_("Bcc:")); BQuery query; BVolume volume; BVolumeRoster().GetBootVolume(&volume); query.SetVolume(&volume); query.SetPredicate("((META:email=*)&&(BEOS:TYPE=application/x-person))"); if(!fReadOnly && query.Fetch() == B_OK) { BString addr[4],name,group,nick; entry_ref ref; BList peopleList; while(query.GetNextRef(&ref) == B_OK) { BNode node(&ref); if(node.InitCheck() != B_OK) continue; ReadNodeAttrString(&node,"META:name",&name); ReadNodeAttrString(&node,"META:email",&addr[0]); ReadNodeAttrString(&node,"META:email2",&addr[1]); ReadNodeAttrString(&node,"META:email3",&addr[2]); ReadNodeAttrString(&node,"META:email4",&addr[3]); ReadNodeAttrString(&node,"META:group",&group); ReadNodeAttrString(&node,"META:nickname",&nick); for(int32 i = 0;i < 4;i++) { if(addr[i].Length() > 0) { if(nick.Length() > 0) { nick += " <"; nick += addr[i]; nick += ">"; fAddrList.AddItem(strdup(nick.String())); } fAddrList.AddItem(strdup(addr[i].String())); BString title = name; title << " <" << addr[i] << ">"; AddPersonToList(peopleList,title.String(),group.String()); } } } // Sort people data peopleList.SortItems(HAddressView::SortPeople); // Build menus BTextControl *control[3] = {fTo,fCc,fBcc}; BMenu *menus[3] = {toMenu,ccMenu,bccMenu}; int32 count = peopleList.CountItems(); PersonData *data; bool needSeparator = false; bool hasSeparator = false; for(int32 k = 0;k < 3;k++) { for(int32 i = 0;i < count;i++) { BMessage *msg = new BMessage(M_ADDR_MSG); msg->AddPointer("pointer",control[k]); data = (PersonData*)peopleList.ItemAt(i); msg->AddString("email",data->email); if(needSeparator && !hasSeparator && strlen(data->group) == 0) { menus[k]->AddSeparatorItem(); hasSeparator = true; }else needSeparator = true; AddPerson(menus[k],data->email,data->group,msg,0,0); } hasSeparator = false; needSeparator = false; } // free all data while(count > 0) { data = (PersonData*)peopleList.RemoveItem(--count); free(data->email); free(data->group); delete data; } } BMenuField *field = new BMenuField(menuRect,"ToMenu","",toMenu, B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW); field->SetDivider(0); field->SetEnabled(!fReadOnly); AddChild(field); rect = menuRect; rect.OffsetBy(0,28); rect.left = Bounds().left + 5; rect.right = rect.left + 16; rect.top += 26; rect.bottom = rect.top + 16; ArrowButton *arrow = new ArrowButton(rect,"addr_arrow" ,new BMessage(M_EXPAND_ADDRESS)); AddChild(arrow); //==================== From menu BMenu *fromMenu = new BMenu(_("From:")); BPath path; ::find_directory(B_USER_SETTINGS_DIRECTORY,&path); path.Append(APP_NAME); path.Append("Accounts"); BDirectory dir(path.Path()); BEntry entry; status_t err = B_OK; int32 account_count = 0; while(err == B_OK) { if((err = dir.GetNextEntry(&entry)) == B_OK && !entry.IsDirectory()) { char name[B_FILE_NAME_LENGTH+1]; entry.GetName(name); BMessage *msg = new BMessage(M_ACCOUNT_CHANGE); msg->AddString("name",name); BMenuItem *item = new BMenuItem(name,msg); fromMenu->AddItem(item); item->SetTarget(this,Window()); account_count++; } } if(account_count != 0) { int32 smtp_account; ((HApp*)be_app)->Prefs()->GetData("smtp_account",&smtp_account); BMenuItem *item(NULL); if(account_count > smtp_account) item = fromMenu->ItemAt(smtp_account); if(!item) item = fromMenu->ItemAt(0); if(item) { ChangeAccount(item->Label()); item->SetMarked(true); } }else{ (new BAlert("",_("Could not find mail accounts"),_("OK"),NULL,NULL,B_WIDTH_AS_USUAL,B_INFO_ALERT))->Go(); Window()->PostMessage(B_QUIT_REQUESTED); } fromMenu->SetRadioMode(true); menuRect.OffsetBy(0,25*2); field = new BMenuField(menuRect,"FromMenu","",fromMenu, B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW); field->SetDivider(0); AddChild(field); //=================== CC menu menuRect.OffsetBy(0,25); field = new BMenuField(menuRect,"CcMenu","",ccMenu, B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW); field->SetDivider(0); field->SetEnabled(!fReadOnly); AddChild(field); //=================== BCC menu menuRect.OffsetBy(0,25); field = new BMenuField(menuRect,"BccMenu","",bccMenu, B_FOLLOW_TOP|B_FOLLOW_LEFT,B_WILL_DRAW); field->SetDivider(0); field->SetEnabled(!fReadOnly); AddChild(field); }
void MainWindow::_UpdateMenus(BDiskDevice* disk, partition_id selectedPartition, partition_id parentID) { while (BMenuItem* item = fFormatMenu->RemoveItem(0L)) delete item; while (BMenuItem* item = fDiskInitMenu->RemoveItem(0L)) delete item; fCreateMI->SetEnabled(false); fUnmountMI->SetEnabled(false); fDiskInitMenu->SetEnabled(false); fFormatMenu->SetEnabled(false); if (!disk) { fWipeMI->SetEnabled(false); fEjectMI->SetEnabled(false); fSurfaceTestMI->SetEnabled(false); } else { // fWipeMI->SetEnabled(true); fWipeMI->SetEnabled(false); fEjectMI->SetEnabled(disk->IsRemovableMedia()); // fSurfaceTestMI->SetEnabled(true); fSurfaceTestMI->SetEnabled(false); // Create menu and items BPartition* parentPartition = NULL; if (selectedPartition <= -2) { // a partitionable space item is selected parentPartition = disk->FindDescendant(parentID); } if (parentPartition && parentPartition->ContainsPartitioningSystem()) fCreateMI->SetEnabled(true); bool prepared = disk->PrepareModifications() == B_OK; fFormatMenu->SetEnabled(prepared); fDeleteMI->SetEnabled(prepared); BPartition* partition = disk->FindDescendant(selectedPartition); BDiskSystem diskSystem; fDDRoster.RewindDiskSystems(); while (fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) { if (!diskSystem.SupportsInitializing()) continue; BMessage* message = new BMessage(MSG_INITIALIZE); message->AddInt32("parent id", parentID); message->AddString("disk system", diskSystem.PrettyName()); BString label = diskSystem.PrettyName(); label << B_UTF8_ELLIPSIS; BMenuItem* item = new BMenuItem(label.String(), message); // TODO: Very unintuitive that we have to use PrettyName (vs Name) item->SetEnabled(partition != NULL && partition->CanInitialize(diskSystem.PrettyName())); if (disk->ID() == selectedPartition && !diskSystem.IsFileSystem()) { // Disk is selected, and DiskSystem is a partition map fDiskInitMenu->AddItem(item); } else if (diskSystem.IsFileSystem()) { // Otherwise a filesystem fFormatMenu->AddItem(item); } } // Mount items if (partition) { fFormatMenu->SetEnabled(!partition->IsMounted() && !partition->IsReadOnly() && partition->Device()->HasMedia() && fFormatMenu->CountItems() > 0); fDiskInitMenu->SetEnabled(!partition->IsMounted() && !partition->IsReadOnly() && partition->Device()->HasMedia() && partition->IsDevice() && fDiskInitMenu->CountItems() > 0); fDeleteMI->SetEnabled(!partition->IsMounted() && !partition->IsDevice()); fMountMI->SetEnabled(!partition->IsMounted()); bool unMountable = false; if (partition->IsMounted()) { // see if this partition is the boot volume BVolume volume; BVolume bootVolume; if (BVolumeRoster().GetBootVolume(&bootVolume) == B_OK && partition->GetVolume(&volume) == B_OK) { unMountable = volume != bootVolume; } else unMountable = true; } fUnmountMI->SetEnabled(unMountable); } else { fDeleteMI->SetEnabled(false); fMountMI->SetEnabled(false); fFormatMenu->SetEnabled(false); fDiskInitMenu->SetEnabled(false); } if (prepared) disk->CancelModifications(); fMountAllMI->SetEnabled(true); } if (selectedPartition < 0) { fDeleteMI->SetEnabled(false); fMountMI->SetEnabled(false); } }
void BDirMenu::Populate(const BEntry *startEntry, BWindow *originatingWindow, bool includeStartEntry, bool select, bool reverse, bool addShortcuts) { try { if (!startEntry) throw (status_t)B_ERROR; Model model(startEntry); ThrowOnInitCheckError(&model); ModelMenuItem *menu = new ModelMenuItem(&model, this, true, true); if (fMenuBar) fMenuBar->AddItem(menu); BEntry entry(*startEntry); bool showDesktop, showDisksIcon; { TrackerSettings settings; showDesktop = settings.DesktopFilePanelRoot(); showDisksIcon = settings.ShowDisksIcon(); } // might start one level above startEntry if (!includeStartEntry) { BDirectory parent; BDirectory dir(&entry); // if we're at the root directory skip "mnt" and go straight to "/" if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) parent.SetTo("/"); else entry.GetParent(&parent); parent.GetEntry(&entry); } BVolume bootVol; BVolumeRoster().GetBootVolume(&bootVol); BDirectory desktopDir; FSGetDeskDir(&desktopDir, bootVol.Device()); BEntry desktopEntry; desktopDir.GetEntry(&desktopEntry); for (;;) { BNode node(&entry); ThrowOnInitCheckError(&node); PoseInfo info; ReadAttrResult result = ReadAttr(&node, kAttrPoseInfo, kAttrPoseInfoForeign, B_RAW_TYPE, 0, &info, sizeof(PoseInfo), &PoseInfo::EndianSwap); BDirectory parent; entry.GetParent(&parent); bool hitRoot = false; // if we're at the root directory skip "mnt" and go straight to "/" BDirectory dir(&entry); if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { hitRoot = true; parent.SetTo("/"); } if (showDesktop) { BEntry root("/"); // warp from "/" to Desktop properly if (entry == root) { if (showDisksIcon) AddDisksIconToMenu(reverse); entry = desktopEntry; } if (entry == desktopEntry) hitRoot = true; } if (result == kReadAttrFailed || !info.fInvisible || (showDesktop && desktopEntry == entry)) AddItemToDirMenu(&entry, originatingWindow, reverse, addShortcuts); if (hitRoot) { if (!showDesktop && showDisksIcon && *startEntry != "/") AddDisksIconToMenu(reverse); break; } parent.GetEntry(&entry); } // select last item in menu if (!select) return; ModelMenuItem *item = dynamic_cast<ModelMenuItem *>(ItemAt(CountItems() - 1)); if (item) { item->SetMarked(true); if (menu) { entry.SetTo(item->TargetModel()->EntryRef()); ThrowOnError(menu->SetEntry(&entry)); } } } catch (status_t err) { PRINT(("BDirMenu::Populate: caught error %s\n", strerror(err))); if (!CountItems()) { BString error; error << "Error [" << strerror(err) << "] populating menu"; AddItem(new BMenuItem(error.String(), 0)); } } }