void MainWindow::MessageReceived(BMessage* message) { bool discard = false; // Figure out if we need the write lock on the Document. For most // messages we do, but exporting takes place in another thread and // locking is taken care of there. bool requiresWriteLock = true; switch (message->what) { case MSG_SAVE: case MSG_EXPORT: case MSG_SAVE_AS: case MSG_EXPORT_AS: requiresWriteLock = false; break; default: break; } if (requiresWriteLock && !fDocument->WriteLock()) { BWindow::MessageReceived(message); return; } if (message->WasDropped()) { const rgb_color* color; ssize_t length; // create styles from dropped colors for (int32 i = 0; message->FindData("RGBColor", B_RGB_COLOR_TYPE, i, (const void**)&color, &length) == B_OK; i++) { if (length != sizeof(rgb_color)) continue; char name[30]; sprintf(name, B_TRANSLATE_CONTEXT("Color (#%02x%02x%02x)", "Style name after dropping a color"), color->red, color->green, color->blue); Style* style = new (nothrow) Style(*color); style->SetName(name); Style* styles[1] = { style }; AddStylesCommand* styleCommand = new (nothrow) AddStylesCommand( fDocument->Icon()->Styles(), styles, 1, fDocument->Icon()->Styles()->CountStyles()); fDocument->CommandStack()->Perform(styleCommand); // don't handle anything else, // or we might paste the clipboard on B_PASTE discard = true; } } switch (message->what) { case B_REFS_RECEIVED: case B_SIMPLE_DATA: // If our icon is empty, open the file in this window, // otherwise forward to the application which will open // it in another window, unless we append. message->what = B_REFS_RECEIVED; if (fDocument->Icon()->Styles()->CountStyles() == 0 && fDocument->Icon()->Paths()->CountPaths() == 0 && fDocument->Icon()->Shapes()->CountShapes() == 0) { entry_ref ref; if (message->FindRef("refs", &ref) == B_OK) Open(ref); break; } if (modifiers() & B_SHIFT_KEY) { // We want the icon appended to this window. message->AddBool("append", true); message->AddPointer("window", this); } be_app->PostMessage(message); break; case B_PASTE: case B_MIME_DATA: { BMessage* clip = message; status_t err; if (discard) break; if (message->what == B_PASTE) { if (!be_clipboard->Lock()) break; clip = be_clipboard->Data(); } if (!clip || !clip->HasData("text/plain", B_MIME_TYPE)) { if (message->what == B_PASTE) be_clipboard->Unlock(); break; } Icon* icon = new (std::nothrow) Icon(*fDocument->Icon()); if (icon != NULL) { StyledTextImporter importer; err = importer.Import(icon, clip); if (err >= B_OK) { AutoWriteLocker locker(fDocument); SetIcon(NULL); // incorporate the loaded icon into the document // (either replace it or append to it) fDocument->MakeEmpty(false); // if append, the document savers are preserved fDocument->SetIcon(icon); SetIcon(icon); } } if (message->what == B_PASTE) be_clipboard->Unlock(); break; } case MSG_OPEN: // If our icon is empty, we want the icon to open in this // window. if (fDocument->Icon()->Styles()->CountStyles() == 0 && fDocument->Icon()->Paths()->CountPaths() == 0 && fDocument->Icon()->Shapes()->CountShapes() == 0) { message->AddPointer("window", this); } be_app->PostMessage(message); break; case MSG_SAVE: case MSG_EXPORT: { DocumentSaver* saver; if (message->what == MSG_SAVE) saver = fDocument->NativeSaver(); else saver = fDocument->ExportSaver(); if (saver != NULL) { saver->Save(fDocument); _PickUpActionBeforeSave(); break; } // else fall through } case MSG_SAVE_AS: case MSG_EXPORT_AS: { int32 exportMode; if (message->FindInt32("export mode", &exportMode) < B_OK) exportMode = EXPORT_MODE_MESSAGE; entry_ref ref; const char* name; if (message->FindRef("directory", &ref) == B_OK && message->FindString("name", &name) == B_OK) { // this message comes from the file panel BDirectory dir(&ref); BEntry entry; if (dir.InitCheck() >= B_OK && entry.SetTo(&dir, name, true) >= B_OK && entry.GetRef(&ref) >= B_OK) { // create the document saver and remember it for later DocumentSaver* saver = _CreateSaver(ref, exportMode); if (saver != NULL) { if (fDocument->WriteLock()) { if (exportMode == EXPORT_MODE_MESSAGE) fDocument->SetNativeSaver(saver); else fDocument->SetExportSaver(saver); _UpdateWindowTitle(); fDocument->WriteUnlock(); } saver->Save(fDocument); _PickUpActionBeforeSave(); } } // TODO: ... // _SyncPanels(fSavePanel, fOpenPanel); } else { // configure the file panel uint32 requestRefWhat = MSG_SAVE_AS; bool isExportMode = message->what == MSG_EXPORT_AS || message->what == MSG_EXPORT; if (isExportMode) requestRefWhat = MSG_EXPORT_AS; const char* saveText = _FileName(isExportMode); BMessage requestRef(requestRefWhat); if (saveText != NULL) requestRef.AddString("save text", saveText); requestRef.AddMessenger("target", BMessenger(this, this)); be_app->PostMessage(&requestRef); } break; } case B_CANCEL: // FilePanel was canceled, do not execute the fMessageAfterSave // next time a file panel is used, in case it was set! delete fMessageAfterSave; fMessageAfterSave = NULL; break; case MSG_UNDO: fDocument->CommandStack()->Undo(); break; case MSG_REDO: fDocument->CommandStack()->Redo(); break; case MSG_UNDO_STACK_CHANGED: { // relable Undo item and update enabled status BString label(B_TRANSLATE("Undo")); fUndoMI->SetEnabled(fDocument->CommandStack()->GetUndoName(label)); if (fUndoMI->IsEnabled()) fUndoMI->SetLabel(label.String()); else { fUndoMI->SetLabel(B_TRANSLATE_CONTEXT("<nothing to undo>", "Icon-O-Matic-Menu-Edit")); } // relable Redo item and update enabled status label.SetTo(B_TRANSLATE("Redo")); fRedoMI->SetEnabled(fDocument->CommandStack()->GetRedoName(label)); if (fRedoMI->IsEnabled()) fRedoMI->SetLabel(label.String()); else { fRedoMI->SetLabel(B_TRANSLATE_CONTEXT("<nothing to redo>", "Icon-O-Matic-Menu-Edit")); } break; } case MSG_MOUSE_FILTER_MODE: { uint32 mode; if (message->FindInt32("mode", (int32*)&mode) == B_OK) fCanvasView->SetMouseFilterMode(mode); break; } case MSG_ADD_SHAPE: { AddStylesCommand* styleCommand = NULL; Style* style = NULL; if (message->HasBool("style")) { new_style(fCurrentColor->Color(), fDocument->Icon()->Styles(), &style, &styleCommand); } AddPathsCommand* pathCommand = NULL; VectorPath* path = NULL; if (message->HasBool("path")) { new_path(fDocument->Icon()->Paths(), &path, &pathCommand); } if (!style) { // use current or first style int32 currentStyle = fStyleListView->CurrentSelection(0); style = fDocument->Icon()->Styles()->StyleAt(currentStyle); if (!style) style = fDocument->Icon()->Styles()->StyleAt(0); } Shape* shape = new (nothrow) Shape(style); Shape* shapes[1]; shapes[0] = shape; AddShapesCommand* shapeCommand = new (nothrow) AddShapesCommand( fDocument->Icon()->Shapes(), shapes, 1, fDocument->Icon()->Shapes()->CountShapes(), fDocument->Selection()); if (path && shape) shape->Paths()->AddPath(path); ::Command* command = NULL; if (styleCommand || pathCommand) { if (styleCommand && pathCommand) { Command** commands = new Command*[3]; commands[0] = styleCommand; commands[1] = pathCommand; commands[2] = shapeCommand; command = new CompoundCommand(commands, 3, B_TRANSLATE_CONTEXT("Add shape with path & style", "Icon-O-Matic-Menu-Shape"), 0); } else if (styleCommand) { Command** commands = new Command*[2]; commands[0] = styleCommand; commands[1] = shapeCommand; command = new CompoundCommand(commands, 2, B_TRANSLATE_CONTEXT("Add shape with style", "Icon-O-Matic-Menu-Shape"), 0); } else { Command** commands = new Command*[2]; commands[0] = pathCommand; commands[1] = shapeCommand; command = new CompoundCommand(commands, 2, B_TRANSLATE_CONTEXT("Add shape with path", "Icon-O-Matic-Menu-Shape"), 0); } } else { command = shapeCommand; } fDocument->CommandStack()->Perform(command); break; } // TODO: listen to selection in CanvasView to add a manipulator case MSG_PATH_SELECTED: { VectorPath* path; if (message->FindPointer("path", (void**)&path) < B_OK) path = NULL; fPathListView->SetCurrentShape(NULL); fStyleListView->SetCurrentShape(NULL); fTransformerListView->SetShape(NULL); fState->DeleteManipulators(); if (fDocument->Icon()->Paths()->HasPath(path)) { PathManipulator* pathManipulator = new (nothrow) PathManipulator(path); fState->AddManipulator(pathManipulator); } break; } case MSG_STYLE_SELECTED: case MSG_STYLE_TYPE_CHANGED: { Style* style; if (message->FindPointer("style", (void**)&style) < B_OK) style = NULL; if (!fDocument->Icon()->Styles()->HasStyle(style)) style = NULL; fStyleView->SetStyle(style); fPathListView->SetCurrentShape(NULL); fStyleListView->SetCurrentShape(NULL); fTransformerListView->SetShape(NULL); fState->DeleteManipulators(); Gradient* gradient = style ? style->Gradient() : NULL; if (gradient != NULL) { TransformGradientBox* transformBox = new (nothrow) TransformGradientBox(fCanvasView, gradient, NULL); fState->AddManipulator(transformBox); } break; } case MSG_SHAPE_SELECTED: { Shape* shape; if (message->FindPointer("shape", (void**)&shape) < B_OK) shape = NULL; if (!fIcon || !fIcon->Shapes()->HasShape(shape)) shape = NULL; fPathListView->SetCurrentShape(shape); fStyleListView->SetCurrentShape(shape); fTransformerListView->SetShape(shape); BList selectedShapes; ShapeContainer* shapes = fDocument->Icon()->Shapes(); int32 count = shapes->CountShapes(); for (int32 i = 0; i < count; i++) { shape = shapes->ShapeAtFast(i); if (shape->IsSelected()) { selectedShapes.AddItem((void*)shape); } } fState->DeleteManipulators(); if (selectedShapes.CountItems() > 0) { TransformShapesBox* transformBox = new (nothrow) TransformShapesBox( fCanvasView, (const Shape**)selectedShapes.Items(), selectedShapes.CountItems()); fState->AddManipulator(transformBox); } break; } case MSG_RENAME_OBJECT: fPropertyListView->FocusNameProperty(); break; default: BWindow::MessageReceived(message); } if (requiresWriteLock) fDocument->WriteUnlock(); }
bool FeedListener::ServerIsRunning(void) { BList teams; be_roster->GetAppList(FeedKit::ServerSignature, &teams); return teams.CountItems() > 0; };
status_t TerminalThemesAddon::ApplyThemeHaiku(BMessage &theme, uint32 flags) { BMessage termpref; BMessage lines; status_t err; struct termprefs tp; int32 ival; rgb_color color; BString s; err = MyMessage(theme, termpref); if (err) return err; if (termpref.FindInt32(TP_COLS, &ival) < B_OK) ival = 80; s = ""; s << ival; lines.AddString(PREF_COLS, s.String()); if (termpref.FindInt32(TP_ROWS, &ival) < B_OK) ival = 25; s = ""; s << ival; lines.AddString(PREF_ROWS, s.String()); if (termpref.FindInt32(TP_TABWIDTH, &ival) >= B_OK) { //XXX: handle that ? } BFont tFont; tp.p.font_size = 12; strcpy(tp.p.font, "Courier10 BT/Roman"); if (FindFont(termpref, TP_FONT, 0, &tFont) == B_OK) { font_family ff; font_style fs; tFont.GetFamilyAndStyle(&ff, &fs); s = ""; s << ff; lines.AddString(PREF_HALF_FONT_FAMILY, s.String()); s = ""; s << fs; lines.AddString(PREF_HALF_FONT_STYLE, s.String()); s = ""; s << tFont.Size(); lines.AddString(PREF_HALF_FONT_SIZE, s.String()); } if (FindRGBColor(termpref, TP_BG, 0, &color) != B_OK) color = make_color(255,255,255,255); s = ""; s << color.red << ", " << color.green << ", " << color.blue; lines.AddString(PREF_TEXT_BACK_COLOR, s.String()); if (FindRGBColor(termpref, TP_FG, 0, &color) != B_OK) color = make_color(0,0,0,255); s = ""; s << color.red << ", " << color.green << ", " << color.blue; lines.AddString(PREF_TEXT_FORE_COLOR, s.String()); if (FindRGBColor(termpref, TP_CURBG, 0, &color) != B_OK) color = make_color(255,255,255,255); s = ""; s << color.red << ", " << color.green << ", " << color.blue; lines.AddString(PREF_CURSOR_BACK_COLOR, s.String()); if (FindRGBColor(termpref, TP_CURFG, 0, &color) != B_OK) color = make_color(0,0,0,255); s = ""; s << color.red << ", " << color.green << ", " << color.blue; lines.AddString(PREF_CURSOR_FORE_COLOR, s.String()); if (FindRGBColor(termpref, TP_SELBG, 0, &color) != B_OK) color = make_color(0,0,0,255); s = ""; s << color.red << ", " << color.green << ", " << color.blue; lines.AddString(PREF_SELECT_BACK_COLOR, s.String()); if (FindRGBColor(termpref, TP_SELFG, 0, &color) != B_OK) color = make_color(255,255,255,255); s = ""; s << color.red << ", " << color.green << ", " << color.blue; lines.AddString(PREF_SELECT_FORE_COLOR, s.String()); /* XXX: handle PREF_IM_FORE_COLOR PREF_IM_BACK_COLOR PREF_IM_SELECT_COLOR */ if (termpref.FindInt32(TP_ENCODING, &ival) != B_OK) ival = 0; // UTF-8 s = ""; s << ival; //XXX: shouldn't really be touched... //lines.AddString(, s.String()); if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) { SaveHaikuTerminalSettings(lines); } if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) { BList teamList; app_info ainfo; int32 count, i; be_roster->GetAppList(&teamList); count = teamList.CountItems(); for (i = 0; i < count; i++) { if (be_roster->GetRunningAppInfo((team_id)(teamList.ItemAt(i)), &ainfo) == B_OK) { if (!strcmp(ainfo.signature, kHaikuTerminalAppSig)) { err = B_OK; //XXX: WRITEME /* BMessage msg(MSG_R5_SET_PREF); BMessenger msgr(NULL, ainfo.team); tp.x = 0; tp.y = 0; //msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref)); msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs)); msg.AddSpecifier("Window", 0L); err = msgr.SendMessage(&msg); */ } } } } return B_OK; }
void PlaylistListView::CopyItems(const BList& indices, int32 toIndex) { fCommandStack->Perform(new (nothrow) CopyPLItemsCommand(fPlaylist, (int32*)indices.Items(), indices.CountItems(), toIndex)); }
/*********************************************************** * 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 TExpandoMenuBar::AttachedToWindow() { BMessenger self(this); BList teamList; TBarApp::Subscribe(self, &teamList); float width = fVertical ? Frame().Width() : kMinimumWindowWidth; float height = -1.0f; // top or bottom mode, add be menu and sep for menubar tracking consistency if (!fVertical) { TBeMenu *beMenu = new TBeMenu(fBarView); TBarWindow::SetBeMenu(beMenu); fBeMenuItem = new TBarMenuTitle(kBeMenuWidth, Frame().Height(), AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_BeLogoIcon), beMenu, true); AddItem(fBeMenuItem); fSeparatorItem = new TTeamMenuItem(kSepItemWidth, height, fVertical); AddItem(fSeparatorItem); fSeparatorItem->SetEnabled(false); fFirstApp = 2; } else { fBeMenuItem = NULL; fSeparatorItem = NULL; } desk_settings *settings = ((TBarApp *)be_app)->Settings(); if (settings->sortRunningApps) teamList.SortItems(CompareByName); int32 count = teamList.CountItems(); for (int32 i = 0; i < count; i++) { BarTeamInfo *barInfo = (BarTeamInfo *)teamList.ItemAt(i); if ((barInfo->flags & B_BACKGROUND_APP) == 0 && strcasecmp(barInfo->sig, kDeskbarSignature) != 0) { if (settings->trackerAlwaysFirst && !strcmp(barInfo->sig, kTrackerSignature)) { AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, barInfo->name, barInfo->sig, width, height, fDrawLabel, fVertical), fFirstApp); } else { AddItem(new TTeamMenuItem(barInfo->teams, barInfo->icon, barInfo->name, barInfo->sig, width, height, fDrawLabel, fVertical)); } barInfo->teams = NULL; barInfo->icon = NULL; barInfo->name = NULL; barInfo->sig = NULL; } delete barInfo; } BMenuBar::AttachedToWindow(); if (CountItems() == 0) { // If we're empty, BMenuBar::AttachedToWindow() resizes us to some // weird value - we just override it again ResizeTo(width, 0); } if (fVertical) { sDoMonitor = true; sMonThread = spawn_thread(monitor_team_windows, "Expando Window Watcher", B_LOW_PRIORITY, this); resume_thread(sMonThread); } }
void Model::_FreeHistory(const BList& items) const { for (int32 t = items.CountItems() - 1; t >= 0; --t) delete static_cast<BString*>((items.ItemAtFast(t))); }
int32 AmInputQueue::RecordLoop() { while (mRecordAvail >= B_OK) { while (acquire_sem(mRecordAvail) == B_INTERRUPTED) ; BList items; if (mRecordLock.Lock()) { items = mRecordItems; mRecordItems.MakeEmpty(); mRecordLock.Unlock(); } AmSongRef songRef = AmGlobals().SongRef(mSong); if (songRef.IsValid()) { for (int32 i=0; i<items.CountItems(); i++) { record_item* ri = (record_item*)items.ItemAt(i); if (!ri) continue; { // READ SONG BLOCK #ifdef AM_TRACE_LOCKS printf("AmInputQueue::RecordLoop() read lock\n"); fflush(stdout); #endif const AmSong* song = songRef.ReadLock(); if (song) { ri->events = ArpExecFilters(ri->events, REALTIME_EXEC_TYPE, false); if (ri->events) ri->events = ri->events->HeadEvent(); songRef.ReadUnlock(song); } // END READ SONG BLOCK } { // WRITE SONG BLOCK AmSong* song = songRef.WriteLock(); if (song) { #if 1 /* New mechanism -- all events should have been supplied * a track by the last filter they went through. So, * record to the requested track. This wouldn't be * necessary if we had a full architecture -- that is, * the tracks were just another filter in the pipeline. */ AmTrack* track = 0; AmEvent* e = 0; AmEvent* head = ri->events; while ((e = _get_record_t_and_e(head, song, &head, &track)) != 0) { if (track) track->RecordEvents(e); else e->DeleteChain(); } if (head) head->DeleteChain(); ri->events = 0; #endif #if 0 AmTrack* track = song->Track(ri->track); if (track && ri->events) { track->RecordEvents(ri->events); ri->events = NULL; } #endif songRef.WriteUnlock(song); } // END WRITE SONG BLOCK } if (ri->events) ri->events->DeleteChain(); delete ri; } } } return B_OK; }
void PeepsWindow::MessageReceived(BMessage *msg) { switch(msg->what) { case B_ABOUT_REQUESTED: { be_app->PostMessage(msg); break; } case M_RUN_TOOL: { BString sig; if(msg->FindString("signature",&sig)==B_OK) { if(strcmp(sig.String(),"application/x-vnd.wgp-PeopleMover")==0) { be_roster->Launch(sig.String()); break; } // Get the filename for the currently-selected person int32 selection=fPeopleList->CurrentSelection(); if(selection<0) break; PeepsListItem *peepsitem=(PeepsListItem*)fPeopleList->ItemAt(selection); if(!peepsitem || peepsitem->IsGroup()) break; PersonItem *personitem=(PersonItem*)peepsitem; PersonData *persondata=personitem->GetData(); if(!persondata) break; entry_ref ref=persondata->FileRef(); BPath path(&ref); char *launchv[1]; launchv[0]=new char[255]; sprintf(launchv[0],"%s",path.Path()); be_roster->Launch(sig.String(),1,launchv,NULL); delete [] launchv[0]; } break; } case M_SHOW_ACTIONS: { uint32 buttons; BPoint pt; fPeopleList->GetMouse(&pt,&buttons,false); pt.x=(pt.x>5)?pt.x-5:0; pt.y=(pt.y>5)?pt.y-5:0; fPeopleList->ShowContextMenu(fPeopleList->ConvertToScreen(pt)); break; } case M_BITMAP_REMOVED: case M_PHOTO_MODIFIED: { fPeopleList->SaveImageData(); break; } case B_REFS_RECEIVED: case B_SIMPLE_DATA: { entry_ref ref; if(msg->FindRef("refs",0,&ref)==B_OK) { if(!IsPerson(ref)) { // Might be an image dropped on the photo view. find out which child is the // target BPoint pt; if(msg->FindPoint("_drop_offset",&pt)!=B_OK) break; BView *target=FindView(pt); if(!target || strcmp(target->Name(),"photoview")!=0) break; // This will set the image, if possible target->MessageReceived(msg); // Save the image data to a real file and attach the Person attributes // to it fPeopleList->SaveImageData(); } // Offer to move/copy file if not in People directory BDirectory dir,peopledir("/boot/home/people"); BEntry entry(&ref); entry.GetParent(&dir); if(dir!=peopledir) { BString refname(ref.name); BString errstr=TRANSLATE("%s is not currently stored in the People folder. Mr. Peeps! will not" " see it on startup unless it is stored there. Would you like to move it" " there?"); char errmsg[errstr.CountChars() - 2 + refname.CountChars() + 1]; sprintf(errmsg,errstr.String(),refname.String()); BAlert *alert=new BAlert("Mr. Peeps!",errmsg,TRANSLATE("Move"),TRANSLATE("Don't Move")); if(alert->Go()==0) { entry.MoveTo(&peopledir); entry.GetRef(&ref); } } if(!SelectPerson(ref)) AddPerson(ref,true); } break; } case M_PREV_ITEM: { if(fPeopleList->CountItems()==0) break; int32 selection=fPeopleList->CurrentSelection(); if(!fPeopleList->IsFocus()) { fPeopleList->MakeFocus(true); PeepsListItem *pitem=(PeepsListItem*)fPeopleList->ItemAt(selection); if(!pitem->IsGroup()) { fPeopleList->SyncData((PersonItem*)pitem); // fPeopleList->SaveData(); } fPeopleList->SaveData(); } if(selection>=0) { if(selection>0) fPeopleList->Select(selection-1); } else { fPeopleList->Select(0L); } break; } case M_NEXT_ITEM: { if(fPeopleList->CountItems()==0) break; int32 selection=fPeopleList->CurrentSelection(); if(!fPeopleList->IsFocus()) { fPeopleList->MakeFocus(true); PeepsListItem *pitem=(PeepsListItem*)fPeopleList->ItemAt(selection); if(!pitem->IsGroup()) { fPeopleList->SyncData((PersonItem*)pitem); // fPeopleList->SaveData(); } fPeopleList->SaveData(); } if(selection==fPeopleList->CountItems()-1 || selection<0) fPeopleList->Select(fPeopleList->CountItems()-1); else fPeopleList->Select(selection+1); break; } case M_MOD_DATA: case M_SAVE: { fPeopleList->SyncData(NULL); fPeopleList->SaveData(); break; } case M_ADD_PERSON: { entry_ref ref; status_t stat=CreatePerson(&ref); if(stat==B_FILE_EXISTS) { for(int32 i=0;i<gPeopleData.CountItems(); i++) { PersonData *pdata=(PersonData*)gPeopleData.ItemAt(i); if(BString(TRANSLATE("New Person")).ICompare(pdata->Name())==0) { int32 selection=fPeopleList->CurrentSelection(); if(selection>=0) { PeepsListItem *peepsitem=(PeepsListItem*)fPeopleList->ItemAt(selection); if(peepsitem && !peepsitem->IsGroup()) fPeopleList->Collapse(fPeopleList->Superitem(peepsitem)); } PersonItem *pitem=pdata->InstanceAt(0); GroupItem *gitem=(GroupItem*)fPeopleList->Superitem(pitem); if(!gitem->IsExpanded()) fPeopleList->Expand(gitem); fPeopleList->Select(fPeopleList->IndexOf(pitem)); fPeopleList->ScrollToSelection(); break; } } } else { // Add the current group to the New Person's file so that we end up staying // in the current group. if(stat==B_OK) { int32 selection=fPeopleList->CurrentSelection(); BString groupstr(TRANSLATE("Ungrouped")); if(selection>=0) { PeepsListItem *currentitem=(PeepsListItem*)fPeopleList->ItemAt(selection); if(currentitem->IsGroup()) groupstr=currentitem->Name(); else groupstr=((PersonItem*)currentitem)->Group(); } PersonData *pdata=new PersonData(ref); pdata->SetGroup(groupstr.String()); pdata->SetName(TRANSLATE("New Person")); pdata->SaveToFile(); delete pdata; AddPerson(ref,true); SortList(); SelectPerson(TRANSLATE("New Person")); dataview->SetFirstFieldFocus(); } } break; } case M_DELETE_PERSON: { int32 selection=fPeopleList->CurrentSelection(); if(selection<0) break; PeepsListItem *item=(PeepsListItem*)fPeopleList->ItemAt(selection); if(item->IsGroup()) DeleteGroup((GroupItem*)item); else { DeletePerson(((PersonItem*)item)->GetData()); } break; } case M_DISABLE_DELETE: { BMenuItem *item=fPeopleMenu->FindItem(TRANSLATE("Move To Trash")); if(item) item->SetEnabled(false); break; } case M_ENABLE_DELETE: { BMenuItem *item=fPeopleMenu->FindItem(TRANSLATE("Move To Trash")); if(item) item->SetEnabled(true); break; } case M_SET_LANGUAGE: { // Restart MrPeeps! gRestartApp=true; int32 language; if(msg->FindInt32("index",&language)!=B_OK) break; BMenuItem *item = fLanguageMenu->ItemAt(language); if(!item) break; fLocale = item->Label(); WriteLocaleSettings(); be_app->PostMessage(B_QUIT_REQUESTED); break; } case M_HANDLE_NO_SELECTION: { // This is the initial case. No selection means quite a few different // menu items are disabled. fTabMenu->SetEnabled(false); fEditMenu->SetEnabled(false); if(fToolPeopleAtAGlance) fToolPeopleAtAGlance->SetEnabled(false); if(fToolVCardExport) fToolVCardExport->SetEnabled(false); UpdateActions(true); break; } case M_HANDLE_GROUP_SELECTION: { // This is the initial case. No selection means quite a few different // menu items are disabled. fTabMenu->SetEnabled(false); fEditMenu->SetEnabled(true); if(fToolPeopleAtAGlance) fToolPeopleAtAGlance->SetEnabled(false); if(fToolVCardExport) fToolVCardExport->SetEnabled(false); UpdateActions(true); break; } case M_HANDLE_PERSON_SELECTION: { // This is the initial case. No selection means quite a few different // menu items are disabled. fTabMenu->SetEnabled(true); fEditMenu->SetEnabled(true); if(fToolPeopleAtAGlance) fToolPeopleAtAGlance->SetEnabled(true); if(fToolVCardExport) fToolVCardExport->SetEnabled(true); UpdateActions(false); break; } case M_SEND_PERSONAL_EMAIL: { if(dataview->Email()) { BMessage *emailmsg=new BMessage(M_SEND_EMAIL); emailmsg->AddString("address",dataview->Email()); be_app->PostMessage(emailmsg); } break; } case M_SEND_WORK_EMAIL: { if(dataview->WorkEmail()) { BMessage *emailmsg=new BMessage(M_SEND_EMAIL); emailmsg->AddString("address",dataview->WorkEmail()); be_app->PostMessage(emailmsg); } break; } case M_SEND_ALT_EMAIL: { if(dataview->Email3()) { BMessage *emailmsg=new BMessage(M_SEND_EMAIL); emailmsg->AddString("address",dataview->Email3()); be_app->PostMessage(emailmsg); } break; } case M_BROWSE_WWW_HOME: { if(dataview->URL()) { BMessage *wwwmsg=new BMessage(M_LAUNCH_BROWSER); wwwmsg->AddString("address",dataview->URL()); be_app->PostMessage(wwwmsg); } break; } case M_BROWSE_WWW_WORK: { if(dataview->WorkURL()) { BMessage *wwwmsg=new BMessage(M_LAUNCH_BROWSER); wwwmsg->AddString("address",dataview->WorkURL()); be_app->PostMessage(wwwmsg); } break; } case M_BROWSE_WWW_ALT: { if(dataview->OtherURL()) { BMessage *wwwmsg=new BMessage(M_LAUNCH_BROWSER); wwwmsg->AddString("address",dataview->OtherURL()); be_app->PostMessage(wwwmsg); } break; } case M_TAB_1: { fPeopleList->SyncData(); fPeopleList->SaveData(); dataview->ShowTab(0); if(!fPeopleList->IsFocus()) dataview->SetFirstFieldFocus(); break; } case M_TAB_2: { fPeopleList->SyncData(); fPeopleList->SaveData(); dataview->ShowTab(1); if(!fPeopleList->IsFocus()) dataview->SetFirstFieldFocus(); break; } case M_TAB_3: { fPeopleList->SyncData(); fPeopleList->SaveData(); dataview->ShowTab(2); if(!fPeopleList->IsFocus()) dataview->SetFirstFieldFocus(); break; } case M_TAB_4: { fPeopleList->SyncData(); fPeopleList->SaveData(); dataview->ShowTab(3); if(!fPeopleList->IsFocus()) dataview->SetFirstFieldFocus(); break; } case M_TAB_5: { fPeopleList->SyncData(); fPeopleList->SaveData(); dataview->ShowTab(4); if(!fPeopleList->IsFocus()) dataview->SetFirstFieldFocus(); break; } case M_UNDO: { dataview->UndoField(); break; } case M_CUT: { dataview->CutField(); break; } case M_COPY: { dataview->CopyField(); break; } case M_PASTE: { dataview->PasteField(); break; } case B_NODE_MONITOR: { HandleNodeMonitoring(msg); break; } default: { BWindow::MessageReceived(msg); break; } } }
// MessageReceived void DragSortableListView::MessageReceived(BMessage* message) { if (AcceptDragMessage(message)) { DragSortableListView *list = NULL; if (message->FindPointer("list", (void **)&list) == B_OK && list == this) { int32 count = CountItems(); if (fDropIndex < 0 || fDropIndex > count) fDropIndex = count; BList indices; int32 index; for (int32 i = 0; message->FindInt32("index", i, &index) == B_OK; i++) indices.AddItem((void*)(addr_t)index); if (indices.CountItems() > 0) { if (modifiers() & B_SHIFT_KEY) CopyItems(indices, fDropIndex); else MoveItems(indices, fDropIndex); } fDropIndex = -1; } } else { switch (message->what) { case MSG_TICK: { float scrollV = 0.0; BRect rect(Bounds()); BPoint point; uint32 buttons; GetMouse(&point, &buttons, false); if (rect.Contains(point)) { // calculate the vertical scrolling offset float hotDist = rect.Height() * SCROLL_AREA; if (point.y > rect.bottom - hotDist) scrollV = hotDist - (rect.bottom - point.y); else if (point.y < rect.top + hotDist) scrollV = (point.y - rect.top) - hotDist; } // scroll if (scrollV != 0.0 && fScrollView) { if (BScrollBar* scrollBar = fScrollView->ScrollBar(B_VERTICAL)) { float value = scrollBar->Value(); scrollBar->SetValue(scrollBar->Value() + scrollV); if (scrollBar->Value() != value) { // update mouse position uint32 buttons; BPoint point; GetMouse(&point, &buttons, false); uint32 transit = Bounds().Contains(point) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW; MouseMoved(point, transit, &fDragMessageCopy); } } } break; } case B_MODIFIERS_CHANGED: ModifiersChanged(); break; case B_MOUSE_WHEEL_CHANGED: { BListView::MessageReceived( message ); BPoint point; uint32 buttons; GetMouse(&point, &buttons, false); uint32 transit = Bounds().Contains(point) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW; MouseMoved(point, transit, &fDragMessageCopy); break; } default: BListView::MessageReceived( message ); break; } } }
/* EEAAAAAAAGHH! My new code uses the current time from the transport * to add signature information to the params. God I hope this is OK. */ int32 AmInputQueue::PerformLoop() { while (mPerformAvail >= B_OK) { while (acquire_sem(mPerformAvail) == B_INTERRUPTED) ; BList items; if (mPerformLock.Lock()) { items = mPerformItems; mPerformItems.MakeEmpty(); mPerformLock.Unlock(); } am_filter_params params; am_filter_params* p = 0; AmSongRef songRef = AmGlobals().SongRef(mSong); if (songRef.IsValid()) { for (int32 i=0; i<items.CountItems(); i++) { record_item* ri = (record_item*)items.ItemAt(i); if (!ri) continue; { // READ SONG BLOCK #ifdef AM_TRACE_LOCKS printf("AmInputQueue::PerformLoop() read lock\n"); fflush(stdout); #endif const AmSong* song = songRef.ReadLock(); const AmTrack* track = song ? song->Track(ri->track) : NULL; if (track) { p = 0; AmEvent* signatures = 0; AmTime currentTime = song->Transport().CurrentTime(); if (currentTime >= 0) { signatures = song->PlaybackList(currentTime, currentTime, PLAYBACK_NO_PERFORMANCE | PLAYBACK_NO_TEMPO | PLAYBACK_RAW_CONTEXT); if (signatures) { // printf("Sigs: \n"); signatures->PrintChain(); params.cur_signature = dynamic_cast<AmSignature*>(signatures); } else params.cur_signature = 0; p = ¶ms; } // Run events through input filters ri->events = ArpExecFilters(ri->events, REALTIME_EXEC_TYPE, false, p, 0, 0, 0, signatures); if (ri->events) ri->events = ri->events->HeadEvent(); // Run result through output filters. AmFilterHolderI* h = track->Filter(OUTPUT_PIPELINE); if (h) { AmEvent* pos = ri->events; while (pos) { if (!pos->NextFilter()) pos->SetNextFilter(h); pos = pos->NextEvent(); } ri->events = ArpExecFilters(ri->events, REALTIME_EXEC_TYPE, false, p, 0, 0, 0, signatures); if (ri->events) ri->events = ri->events->HeadEvent(); } song->Transport().Merge(ri->events); ri->events = NULL; } params.cur_signature = 0; songRef.ReadUnlock(song); // END READ SONG BLOCK } if (ri->events) ri->events->DeleteChain(); delete ri; } } } return B_OK; }
void update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what, const char* preferredFrom) { // clear menu (but leave the first entry, ie. "None") for (int32 i = menu->CountItems(); i-- > 1;) { delete menu->RemoveItem(i); } // fill it again menu->ItemAt(0)->SetMarked(true); BMessage applications; if (type == NULL || type->GetSupportingApps(&applications) != B_OK) return; char preferred[B_MIME_TYPE_LENGTH]; if (type->GetPreferredApp(preferred) != B_OK) preferred[0] = '\0'; int32 lastFullSupport; if (applications.FindInt32("be:sub", &lastFullSupport) != B_OK) lastFullSupport = -1; BList subList; BList superList; const char* signature; int32 i = 0; while (applications.FindString("applications", i, &signature) == B_OK) { BMenuItem* item = create_application_item(signature, what); if (i < lastFullSupport) subList.AddItem(item); else superList.AddItem(item); i++; } // sort lists subList.SortItems(compare_menu_items); superList.SortItems(compare_menu_items); // add lists to the menu if (subList.CountItems() != 0 || superList.CountItems() != 0) menu->AddSeparatorItem(); for (int32 i = 0; i < subList.CountItems(); i++) { menu->AddItem((BMenuItem*)subList.ItemAt(i)); } // Add type separator if (superList.CountItems() != 0 && subList.CountItems() != 0) menu->AddSeparatorItem(); for (int32 i = 0; i < superList.CountItems(); i++) { menu->AddItem((BMenuItem*)superList.ItemAt(i)); } // make items unique and select current choice bool lastItemSame = false; const char* lastSignature = NULL; BMenuItem* last = NULL; BMenuItem* select = NULL; for (int32 index = 0; index < menu->CountItems(); index++) { BMenuItem* item = menu->ItemAt(index); if (item == NULL) continue; if (item->Message() == NULL || item->Message()->FindString("signature", &signature) != B_OK) continue; if ((preferredFrom == NULL && !strcasecmp(signature, preferred)) || (preferredFrom != NULL && !strcasecmp(signature, preferredFrom))) { select = item; } if (last == NULL || strcmp(last->Label(), item->Label())) { if (lastItemSame) add_signature(last, lastSignature); lastItemSame = false; last = item; lastSignature = signature; continue; } lastItemSame = true; add_signature(last, lastSignature); last = item; lastSignature = signature; } if (lastItemSame) add_signature(last, lastSignature); if (select != NULL) { // We don't select the item earlier, so that the menu field can // pick up the signature as well as label. select->SetMarked(true); } else if ((preferredFrom == NULL && preferred[0]) || (preferredFrom != NULL && preferredFrom[0])) { // The preferred application is not an application that support // this file type! BMenuItem* item = create_application_item(preferredFrom ? preferredFrom : preferred, what); menu->AddSeparatorItem(); menu->AddItem(item); item->SetMarked(item); } }
void Win::UrlTypedHandler( bool show_all ) { // printf( "Win::UrlTypedHandler()\n" ); // get the stripped list from GlobalHistory BList* slist = ( ( App* )be_app )->GetGlobalHistory()->GetStrippedList(); // create the matching urls list BList* list = new BList( 0 ); BString typed_url; // the typed url BString cached_url; // the cached url BString cached_url_proto( "" ); // protocol of the cached url if( show_all == true ) typed_url.SetTo( "" ); else { typed_url.SetTo( navview->urlview->Text() ); typed_url.ToLower(); } // printf( " typed_url: %s length: %ld\n", typed_url.String(), typed_url.Length() ); int32 count = slist->CountItems(); for( int32 i = 0; i < count; i++ ) { GlobalHistoryItem* item = ( GlobalHistoryItem* )slist->ItemAt( i ); if( item != NULL ) { cached_url.SetTo( item->Text() ); // printf( " cached_url: %s\n", cached_url.String() ); if( typed_url.Length() != 0 ) { // if the typed url matches beginning of cached url, add it if( strncmp( cached_url.String(), typed_url.String(), typed_url.Length() ) == 0 ) { list->AddItem( new BStringItem( cached_url.String() ) ); } else { // if the urls dont match, take away the protocol of the cached url if( cached_url.FindFirst( "://" ) > 0 ) { cached_url.MoveInto( cached_url_proto, 0, cached_url.FindFirst( "://" ) + 3 ); } // if the urls fit now if( strncmp( cached_url.String(), typed_url.String(), typed_url.Length() ) == 0 ) { // add the missing proto again if( cached_url_proto.Length() != 0 ) cached_url.Prepend( cached_url_proto ); list->AddItem( new BStringItem( cached_url.String() ) ); } else { // if they still don't fit, remove 'www.' from cached url if( cached_url.FindFirst( "www." ) == 0 ) { cached_url.Remove( 0, 4 ); } // check if they finally fit if( strncmp( cached_url.String(), typed_url.String(), typed_url.Length() ) == 0 ) { // add missing 'www.' and proto cached_url.Prepend( "www." ); if( cached_url_proto.Length() != 0 ) cached_url.Prepend( cached_url_proto ); list->AddItem( new BStringItem( cached_url.String() ) ); } } cached_url_proto.SetTo( "" ); } } else { list->AddItem( new BStringItem( cached_url.String() ) ); } } // if( item != NULL ) } // delete slist ( not needed anymore ) for( int32 i = 0; i < count; i++ ) { GlobalHistoryItem* item = ( GlobalHistoryItem* )slist->ItemAt( i ); if( item != NULL ) { slist->RemoveItem( item ); delete item; } } delete slist; // add the urlpopupwindow if needed if( list->CountItems() > 0 ) { CreateUrlPopUpWindow(); // add the list urlpopupwindow->Lock(); urlpopupwindow->ListToDisplay( list ); urlpopupwindow->Unlock(); } else { if( urlpopupwindow != NULL ) { urlpopupwindow->Lock(); urlpopupwindow->Quit(); urlpopupwindow = NULL; } } }
void WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu) { CALLED(); BPath targetDirectory; BPath srcDirectory; BPath trashPath; BPath testPath; BDirectory targetDir; BDiskDevice device; BPartition* partition; BVolume targetVolume; status_t err = B_OK; int32 entries = 0; entry_ref testRef; const char* mountError = B_TRANSLATE("The disk can't be mounted. Please " "choose a different disk."); BMessenger messenger(fWindow); ProgressReporter reporter(messenger, new BMessage(MSG_STATUS_MESSAGE)); CopyEngine engine(&reporter); BList unzipEngines; PartitionMenuItem* targetItem = (PartitionMenuItem*)targetMenu->FindMarked(); PartitionMenuItem* srcItem = (PartitionMenuItem*)srcMenu->FindMarked(); if (!srcItem || !targetItem) { ERR("bad menu items\n"); goto error; } // check if target is initialized // ask if init or mount as is if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) { if (!partition->IsMounted()) { if ((err = partition->Mount()) < B_OK) { _SetStatusMessage(mountError); ERR("BPartition::Mount"); goto error; } } if ((err = partition->GetVolume(&targetVolume)) != B_OK) { ERR("BPartition::GetVolume"); goto error; } if ((err = partition->GetMountPoint(&targetDirectory)) != B_OK) { ERR("BPartition::GetMountPoint"); goto error; } } else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) { if (!device.IsMounted()) { if ((err = device.Mount()) < B_OK) { _SetStatusMessage(mountError); ERR("BDiskDevice::Mount"); goto error; } } if ((err = device.GetVolume(&targetVolume)) != B_OK) { ERR("BDiskDevice::GetVolume"); goto error; } if ((err = device.GetMountPoint(&targetDirectory)) != B_OK) { ERR("BDiskDevice::GetMountPoint"); goto error; } } else goto error; // shouldn't happen // check if target has enough space if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired) && ((new BAlert("", B_TRANSLATE("The destination disk may not have " "enough space. Try choosing a different disk or choose to not " "install optional items."), B_TRANSLATE("Try installing anyway"), B_TRANSLATE("Cancel"), 0, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { goto error; } if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) { if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) { ERR("BPartition::GetMountPoint"); goto error; } } else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) { if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) { ERR("BDiskDevice::GetMountPoint"); goto error; } } else goto error; // shouldn't happen // check not installing on itself if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) { _SetStatusMessage(B_TRANSLATE("You can't install the contents of a " "disk onto itself. Please choose a different disk.")); goto error; } // check not installing on boot volume if ((strncmp(BOOT_PATH, targetDirectory.Path(), strlen(BOOT_PATH)) == 0) && ((new BAlert("", B_TRANSLATE("Are you sure you want to install " "onto the current boot disk? The Installer will have to reboot " "your machine if you proceed."), B_TRANSLATE("OK"), B_TRANSLATE("Cancel"), 0, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { _SetStatusMessage("Installation stopped."); goto error; } // check if target volume's trash dir has anything in it // (target volume w/ only an empty trash dir is considered // an empty volume) if (find_directory(B_TRASH_DIRECTORY, &trashPath, false, &targetVolume) == B_OK && targetDir.SetTo(trashPath.Path()) == B_OK) { while (targetDir.GetNextRef(&testRef) == B_OK) { // Something in the Trash entries++; break; } } targetDir.SetTo(targetDirectory.Path()); // check if target volume otherwise has any entries while (entries == 0 && targetDir.GetNextRef(&testRef) == B_OK) { if (testPath.SetTo(&testRef) == B_OK && testPath != trashPath) entries++; } if (entries != 0 && ((new BAlert("", B_TRANSLATE("The target volume is not empty. Are " "you sure you want to install anyway?\n\nNote: The 'system' folder " "will be a clean copy from the source volume, all other folders " "will be merged, whereas files and links that exist on both the " "source and target volume will be overwritten with the source " "volume version."), B_TRANSLATE("Install anyway"), B_TRANSLATE("Cancel"), 0, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { // TODO: Would be cool to offer the option here to clean additional // folders at the user's choice (like /boot/common and /boot/develop). err = B_CANCELED; goto error; } // Begin actual installation _LaunchInitScript(targetDirectory); // Create the default indices which should always be present on a proper // boot volume. We don't care if the source volume does not have them. // After all, the user might be re-installing to another drive and may // want problems fixed along the way... err = _CreateDefaultIndices(targetDirectory); if (err != B_OK) goto error; // Mirror all the indices which are present on the source volume onto // the target volume. err = _MirrorIndices(srcDirectory, targetDirectory); if (err != B_OK) goto error; // Let the engine collect information for the progress bar later on engine.ResetTargets(srcDirectory.Path()); err = engine.CollectTargets(srcDirectory.Path(), fCancelSemaphore); if (err != B_OK) goto error; // Collect selected packages also if (fPackages) { BPath pkgRootDir(srcDirectory.Path(), PACKAGES_DIRECTORY); int32 count = fPackages->CountItems(); for (int32 i = 0; i < count; i++) { Package *p = static_cast<Package*>(fPackages->ItemAt(i)); BPath packageDir(pkgRootDir.Path(), p->Folder()); err = engine.CollectTargets(packageDir.Path(), fCancelSemaphore); if (err != B_OK) goto error; } } // collect information about all zip packages err = _ProcessZipPackages(srcDirectory.Path(), targetDirectory.Path(), &reporter, unzipEngines); if (err != B_OK) goto error; reporter.StartTimer(); // copy source volume err = engine.CopyFolder(srcDirectory.Path(), targetDirectory.Path(), fCancelSemaphore); if (err != B_OK) goto error; // copy selected packages if (fPackages) { BPath pkgRootDir(srcDirectory.Path(), PACKAGES_DIRECTORY); int32 count = fPackages->CountItems(); for (int32 i = 0; i < count; i++) { Package *p = static_cast<Package*>(fPackages->ItemAt(i)); BPath packageDir(pkgRootDir.Path(), p->Folder()); err = engine.CopyFolder(packageDir.Path(), targetDirectory.Path(), fCancelSemaphore); if (err != B_OK) goto error; } } // Extract all zip packages. If an error occured, delete the rest of // the engines, but stop extracting. for (int32 i = 0; i < unzipEngines.CountItems(); i++) { UnzipEngine* engine = reinterpret_cast<UnzipEngine*>( unzipEngines.ItemAtFast(i)); if (err == B_OK) err = engine->UnzipPackage(); delete engine; } if (err != B_OK) goto error; _LaunchFinishScript(targetDirectory); BMessenger(fWindow).SendMessage(MSG_INSTALL_FINISHED); return; error: BMessage statusMessage(MSG_RESET); if (err == B_CANCELED) _SetStatusMessage(B_TRANSLATE("Installation canceled.")); else statusMessage.AddInt32("error", err); ERR("_PerformInstall failed"); BMessenger(fWindow).SendMessage(&statusMessage); }
BView * DefaultMediaTheme::MakeViewFor(BParameterGroup& group, const BRect* hintRect) { CALLED(); if (group.Flags() & B_HIDDEN_PARAMETER) return NULL; BRect rect; if (hintRect != NULL) rect = *hintRect; GroupView *view = new GroupView(rect, group.Name()); // Create the parameter views - but don't add them yet rect.OffsetTo(B_ORIGIN); rect.InsetBySelf(5, 5); BList views; for (int32 i = 0; i < group.CountParameters(); i++) { BParameter *parameter = group.ParameterAt(i); if (parameter == NULL) continue; BView *parameterView = MakeSelfHostingViewFor(*parameter, hintRect ? &rect : NULL); if (parameterView == NULL) continue; parameterView->SetViewColor(view->ViewColor()); // ToDo: dunno why this is needed, but the controls // sometimes (!) have a white background without it views.AddItem(parameterView); } // Identify a title view, and add it at the top if present TitleView *titleView = dynamic_cast<TitleView *>((BView *)views.ItemAt(0)); if (titleView != NULL) { view->AddChild(titleView); rect.OffsetBy(0, titleView->Bounds().Height()); } // Add the sub-group views rect.right = rect.left + 20; rect.bottom = rect.top + 20; float lastHeight = 0; for (int32 i = 0; i < group.CountGroups(); i++) { BParameterGroup *subGroup = group.GroupAt(i); if (subGroup == NULL) continue; BView *groupView = MakeViewFor(*subGroup, &rect); if (groupView == NULL) continue; if (i > 0) { // add separator view BRect separatorRect(groupView->Frame()); separatorRect.left -= 3; separatorRect.right = separatorRect.left + 1; if (lastHeight > separatorRect.Height()) separatorRect.bottom = separatorRect.top + lastHeight; view->AddChild(new SeparatorView(separatorRect)); } view->AddChild(groupView); rect.OffsetBy(groupView->Bounds().Width() + 5, 0); lastHeight = groupView->Bounds().Height(); if (lastHeight > rect.Height()) rect.bottom = rect.top + lastHeight - 1; } view->ResizeTo(rect.left + 10, rect.bottom + 5); view->SetContentBounds(view->Bounds()); if (group.CountParameters() == 0) return view; // add the parameter views part of the group if (group.CountGroups() > 0) { rect.top = rect.bottom + 10; rect.bottom = rect.top + 20; } bool center = false; for (int32 i = 0; i < views.CountItems(); i++) { BView *parameterView = static_cast<BView *>(views.ItemAt(i)); if (parameterView->Bounds().Width() + 5 > rect.Width()) rect.right = parameterView->Bounds().Width() + rect.left + 5; // we don't need to add the title view again if (parameterView == titleView) continue; // if there is a BChannelSlider (ToDo: or any vertical slider?) // the views will be centered if (dynamic_cast<BChannelSlider *>(parameterView) != NULL) center = true; parameterView->MoveTo(parameterView->Frame().left, rect.top); view->AddChild(parameterView); rect.OffsetBy(0, parameterView->Bounds().Height() + 5); } if (views.CountItems() > (titleView != NULL ? 1 : 0)) view->ResizeTo(rect.right + 5, rect.top + 5); // center the parameter views if needed, and tweak some views float width = view->Bounds().Width(); for (int32 i = 0; i < views.CountItems(); i++) { BView *subView = static_cast<BView *>(views.ItemAt(i)); BRect frame = subView->Frame(); if (center) subView->MoveTo((width - frame.Width()) / 2, frame.top); else { // tweak the PopUp views to look better if (dynamic_cast<BOptionPopUp *>(subView) != NULL) subView->ResizeTo(width, frame.Height()); } } view->SetContentBounds(view->Bounds()); return view; }
void PairsView::_ReadRandomIcons() { // TODO: maybe read the icons only once at startup // clean out any previous icons for (int i = 0; i < fCardBitmaps.CountItems(); i++) delete ((BBitmap*)fCardBitmaps.ItemAt(i)); fCardBitmaps.MakeEmpty(); BDirectory appsDirectory; BDirectory prefsDirectory; BPath path; if (find_directory(B_BEOS_APPS_DIRECTORY, &path) == B_OK) appsDirectory.SetTo(path.Path()); if (find_directory(B_BEOS_PREFERENCES_DIRECTORY, &path) == B_OK) prefsDirectory.SetTo(path.Path()); // read vector icons from apps and prefs folder and put them // into a BList as BBitmaps BList bitmaps; BEntry entry; while (appsDirectory.GetNextEntry(&entry) == B_OK || prefsDirectory.GetNextEntry(&entry) == B_OK) { BNode node(&entry); BNodeInfo nodeInfo(&node); if (nodeInfo.InitCheck() < B_OK) continue; uint8* data; size_t size; type_code type; if (nodeInfo.GetIcon(&data, &size, &type) < B_OK) continue; if (type != B_VECTOR_ICON_TYPE) { delete[] data; continue; } BBitmap* bitmap = new BBitmap( BRect(0, 0, kBitmapSize - 1, kBitmapSize - 1), 0, B_RGBA32); if (BIconUtils::GetVectorIcon(data, size, bitmap) < B_OK) { delete[] data; delete bitmap; continue; } delete[] data; if (_HasBitmap(bitmaps, bitmap) || !bitmaps.AddItem(bitmap)) delete bitmap; else if (bitmaps.CountItems() >= 128) { // this is enough to choose from, stop eating memory... break; } } // pick random bitmaps from the ones we got in the list srand((unsigned)time(0)); for (int i = 0; i < fNumOfCards / 2; i++) { int32 index = rand() % bitmaps.CountItems(); BBitmap* bitmap = ((BBitmap*)bitmaps.RemoveItem(index)); if (bitmap == NULL) { char buffer[512]; snprintf(buffer, sizeof(buffer), B_TRANSLATE("Pairs did not find " "enough vector icons in the system; it needs at least %d."), fNumOfCards / 2); BAlert* alert = new BAlert("fatal", buffer, B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_FROM_WIDEST, B_STOP_ALERT); alert->Go(); exit(1); } fCardBitmaps.AddItem(bitmap); } // delete the remaining bitmaps from the list while (BBitmap* bitmap = (BBitmap*)bitmaps.RemoveItem(0L)) delete bitmap; }
SDL_bool clipboard_copy_text( struct machine *oric ) { unsigned char *vidmem = (&oric->mem[oric->vid_addr]); int line, col; // TEXT BString text; BList textruns; textruns.AddItem(new_run(0, 0)); for (line = 0; line < 28; line++) { for (col = 0; col < 40; col++) { bool inverted = false; unsigned char c = vidmem[line * 40 + col]; if (c > 127) { inverted = true; c -= 128; } if (c < 8) { textruns.AddItem(new_run(text.Length(), c)); text << ' '; } else if (c < ' ' || c == 127) { text << ' '; } else if (c == 0x60) { text << B_UTF8_COPYRIGHT; } else text << (char)c; } text << '\n'; } //printf("%s\n", text.String()); BMessage *clip = NULL; if (be_clipboard->Lock()) { be_clipboard->Clear(); clip = be_clipboard->Data(); if (clip) { clip->AddData("text/plain", B_MIME_TYPE, text.String(), text.Length()); int arraySize = sizeof(text_run_array) + textruns.CountItems() * sizeof(text_run); text_run_array *array = (text_run_array *)malloc(arraySize); array->count = textruns.CountItems(); for (int i = 0; i < array->count; i++) { memcpy(&array->runs[i], textruns.ItemAt(i), sizeof(text_run)); } clip->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE, array, arraySize); free(array); be_clipboard->Commit(); } be_clipboard->Unlock(); } for (int i = 0; i < textruns.CountItems(); i++) { delete (text_run *)(textruns.ItemAt(i)); } textruns.MakeEmpty(); return SDL_TRUE; }
void TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) { bool vertSwap = (fVertical != vertical); bool leftSwap = (fLeft != left); fState = state; fVertical = vertical; fLeft = left; fTop = top; BRect screenFrame = (BScreen(Window())).Frame(); PlaceBeMenu(); if (fVertical){ #if SA_CLOCK PlaceClock(); // tray dependent on clock location #endif PlaceTray(vertSwap, leftSwap, screenFrame); } else { PlaceTray(vertSwap, leftSwap, screenFrame); #if SA_CLOCK PlaceClock(); // clock is dependent on tray location #endif } // We need to keep track of what apps are expanded. BList expandedItems; BString *signature = NULL; if (fVertical && Expando() && static_cast<TBarApp *>(be_app)->Settings()->superExpando) { // Get a list of the Signatures of expanded apps - Can't use team_id because // there can be more than one team per application if (fVertical && Expando() && vertical && fExpando) { for (int index = 0; index < fExpando->CountItems(); index++) { TTeamMenuItem *item = dynamic_cast<TTeamMenuItem *>(fExpando->ItemAt(index)); if (item != NULL && item->IsExpanded()) { signature = new BString(item->Signature()); expandedItems.AddItem((void *)signature); } } } } PlaceApplicationBar(screenFrame); SizeWindow(screenFrame); PositionWindow(screenFrame); Window()->UpdateIfNeeded(); // Re-expand those apps. if (expandedItems.CountItems() > 0) { for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) { signature = static_cast<BString *>(expandedItems.ItemAt(sigIndex)); if (signature == NULL) continue; // Start at the 'bottom' of the list working up. // Prevents being thrown off by expanding items. for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { TTeamMenuItem *item = dynamic_cast<TTeamMenuItem *>(fExpando->ItemAt(teamIndex)); if (item != NULL && !signature->Compare(item->Signature())) { item->ToggleExpandState(false); break; } } } // Clean up expanded signature list. while (!expandedItems.IsEmpty()) { delete static_cast<BString *>(expandedItems.RemoveItem((int32)0)); } fExpando->SizeWindow(); } Invalidate(); }
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); }
// CountModules int32 ModuleList::CountModules() const { return fModules.CountItems(); }
void Accounts::Save() { for (int32 i = gAccounts.CountItems();i-- > 0;) ((Account *)gAccounts.ItemAt(i))->Save(); }
status_t BEmailMessage::RenderToRFC822(BPositionIO *file) { if (_body == NULL) return B_MAIL_INVALID_MAIL; // Do real rendering if (From() == NULL) { // set the "From:" string SendViaAccount(_account_id); } BList recipientList; get_address_list(recipientList, To(), extract_address); get_address_list(recipientList, CC(), extract_address); get_address_list(recipientList, _bcc, extract_address); BString recipients; for (int32 i = recipientList.CountItems(); i-- > 0;) { char *address = (char *)recipientList.RemoveItem((int32)0); recipients << '<' << address << '>'; if (i) recipients << ','; free(address); } // add the date field int32 creationTime = time(NULL); { char date[128]; struct tm tm; localtime_r(&creationTime, &tm); size_t length = strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S", &tm); // GMT offsets are full hours, yes, but you never know :-) snprintf(date + length, sizeof(date) - length, " %+03d%02d", tm.tm_gmtoff / 3600, (tm.tm_gmtoff / 60) % 60); SetHeaderField("Date", date); } // add a message-id // empirical evidence indicates message id must be enclosed in // angle brackets and there must be an "at" symbol in it BString messageID; messageID << "<"; messageID << system_time(); messageID << "-BeMail@"; char host[255]; if (gethostname(host, sizeof(host)) < 0 || !host[0]) strcpy(host, "zoidberg"); messageID << host; messageID << ">"; SetHeaderField("Message-Id", messageID.String()); status_t err = BMailComponent::RenderToRFC822(file); if (err < B_OK) return err; file->Seek(-2, SEEK_CUR); // Remove division between headers err = _body->RenderToRFC822(file); if (err < B_OK) return err; // Set the message file's attributes. Do this after the rest of the file // is filled in, in case the daemon attempts to send it before it is ready // (since the daemon may send it when it sees the status attribute getting // set to "Pending"). if (BFile *attributed = dynamic_cast <BFile *>(file)) { BNodeInfo(attributed).SetType(B_MAIL_TYPE); attributed->WriteAttrString(B_MAIL_ATTR_RECIPIENTS,&recipients); BString attr; attr = To(); attributed->WriteAttrString(B_MAIL_ATTR_TO,&attr); attr = CC(); attributed->WriteAttrString(B_MAIL_ATTR_CC,&attr); attr = Subject(); attributed->WriteAttrString(B_MAIL_ATTR_SUBJECT,&attr); attr = ReplyTo(); attributed->WriteAttrString(B_MAIL_ATTR_REPLY,&attr); attr = From(); attributed->WriteAttrString(B_MAIL_ATTR_FROM,&attr); if (Priority() != 3 /* Normal is 3 */) { sprintf (attr.LockBuffer (40), "%d", Priority()); attr.UnlockBuffer(-1); attributed->WriteAttrString(B_MAIL_ATTR_PRIORITY,&attr); } attr = "Pending"; attributed->WriteAttrString(B_MAIL_ATTR_STATUS, &attr); attr = "1.0"; attributed->WriteAttrString(B_MAIL_ATTR_MIME, &attr); attributed->WriteAttr(B_MAIL_ATTR_ACCOUNT, B_INT32_TYPE, 0, &_account_id, sizeof(int32)); attributed->WriteAttr(B_MAIL_ATTR_WHEN, B_TIME_TYPE, 0, &creationTime, sizeof(int32)); int32 flags = B_MAIL_PENDING | B_MAIL_SAVE; attributed->WriteAttr(B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0, &flags, sizeof(int32)); attributed->WriteAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, &_account_id, sizeof(int32)); } return B_OK; }
void PlaylistListView::RemoveItemList(const BList& indices, bool intoTrash) { fCommandStack->Perform(new (nothrow) RemovePLItemsCommand(fPlaylist, (int32*)indices.Items(), indices.CountItems(), intoTrash)); }
BEmailMessage * BEmailMessage::ReplyMessage(mail_reply_to_mode replyTo, bool accountFromMail, const char *quoteStyle) { BEmailMessage *reply = new BEmailMessage; // Set ReplyTo: if (replyTo == B_MAIL_REPLY_TO_ALL) { reply->SetTo(From()); BList list; get_address_list(list, CC(), extract_address); get_address_list(list, To(), extract_address); // Filter out the sender BMailAccounts accounts; BMailAccountSettings* account = accounts.AccountByID(Account()); BString sender; if (account) sender = account->ReturnAddress(); extract_address(sender); BString cc; for (int32 i = list.CountItems(); i-- > 0;) { char *address = (char *)list.RemoveItem((int32)0); // add everything which is not the sender and not already in the list if (sender.ICompare(address) && cc.FindFirst(address) < 0) { if (cc.Length() > 0) cc << ", "; cc << address; } free(address); } if (cc.Length() > 0) reply->SetCC(cc.String()); } else if (replyTo == B_MAIL_REPLY_TO_SENDER || ReplyTo() == NULL) reply->SetTo(From()); else reply->SetTo(ReplyTo()); // Set special "In-Reply-To:" header (used for threading) const char *messageID = _body ? _body->HeaderField("Message-Id") : NULL; if (messageID != NULL) reply->SetHeaderField("In-Reply-To", messageID); // quote body text reply->SetBodyTextTo(BodyText()); if (quoteStyle) reply->Body()->Quote(quoteStyle); // Set the subject (and add a "Re:" if needed) BString string = Subject(); if (string.ICompare("re:", 3) != 0) string.Prepend("Re: "); reply->SetSubject(string.String()); // set the matching outbound chain if (accountFromMail) reply->SendViaAccountFrom(this); return reply; }
void TTeamMenu::AttachedToWindow() { RemoveItems(0, CountItems(), true); // remove all items BMessenger self(this); BList teamList; TBarApp::Subscribe(self, &teamList); TBarView* barview = (dynamic_cast<TBarApp*>(be_app))->BarView(); bool dragging = barview && barview->Dragging(); int32 iconSize = static_cast<TBarApp*>(be_app)->IconSize(); desk_settings* settings = ((TBarApp*)be_app)->Settings(); float width = sMinimumWindowWidth - iconSize - 4; if (settings->sortRunningApps) teamList.SortItems(CompareByName); int32 count = teamList.CountItems(); for (int32 i = 0; i < count; i++) { // add items back BarTeamInfo* barInfo = (BarTeamInfo*)teamList.ItemAt(i); TTeamMenuItem* item = new TTeamMenuItem(barInfo->teams, barInfo->icon, barInfo->name, barInfo->sig, width, -1, !settings->hideLabels, true); if (settings->trackerAlwaysFirst && strcmp(barInfo->sig, kTrackerSignature) == 0) { AddItem(item, 0); } else AddItem(item); if (dragging && item != NULL) { bool canhandle = (dynamic_cast<TBarApp*>(be_app))->BarView()-> AppCanHandleTypes(item->Signature()); if (item->IsEnabled() != canhandle) item->SetEnabled(canhandle); BMenu* menu = item->Submenu(); if (menu) menu->SetTrackingHook(barview->MenuTrackingHook, barview->GetTrackingHookData()); } } if (CountItems() == 0) { BMenuItem* item = new BMenuItem("no application running", NULL); item->SetEnabled(false); AddItem(item); } if (dragging && barview->LockLooper()) { SetTrackingHook(barview->MenuTrackingHook, barview->GetTrackingHookData()); barview->DragStart(); barview->UnlockLooper(); } BMenu::AttachedToWindow(); }
void AttributeWindow::MessageReceived(BMessage* message) { switch (message->what) { case kMsgAttributeUpdated: case kMsgAlignmentChosen: case kMsgTypeChosen: _CheckDisplayAs(); _CheckAcceptable(); break; case kMsgDisplayAsChosen: fSpecialControl->SetEnabled(!_DefaultDisplayAs()->IsMarked()); _CheckAcceptable(); break; case kMsgVisibilityChanged: { bool enabled = fVisibleCheckBox->Value() != B_CONTROL_OFF; fDisplayAsMenuField->SetEnabled(enabled); fWidthControl->SetEnabled(enabled); fAlignmentMenuField->SetEnabled(enabled); fEditableCheckBox->SetEnabled(enabled); _CheckDisplayAs(); _CheckAcceptable(); break; } case kMsgAccept: { BMessage attributes; status_t status = fMimeType.GetAttrInfo(&attributes); if (status == B_OK) { // replace the entry, and remove any equivalent entries BList list; const char* newAttribute = fAttributeControl->Text(); list.AddItem(_NewItemFromCurrent()); const char* attribute; for (int32 i = 0; attributes.FindString("attr:name", i, &attribute) == B_OK; i++) { if (!strcmp(fAttribute.Name(), attribute) || !strcmp(newAttribute, attribute)) { // remove this item continue; } AttributeItem* item = create_attribute_item(attributes, i); if (item != NULL) list.AddItem(item); } list.SortItems(compare_attributes); // Copy them to a new message (their memory is still part of the // original BMessage) BMessage newAttributes; for (int32 i = 0; i < list.CountItems(); i++) { AttributeItem* item = (AttributeItem*)list.ItemAt(i); newAttributes.AddString("attr:name", item->Name()); newAttributes.AddString("attr:public_name", item->PublicName()); newAttributes.AddInt32("attr:type", (int32)item->Type()); newAttributes.AddString("attr:display_as", item->DisplayAs()); newAttributes.AddInt32("attr:alignment", item->Alignment()); newAttributes.AddInt32("attr:width", item->Width()); newAttributes.AddBool("attr:viewable", item->Visible()); newAttributes.AddBool("attr:editable", item->Editable()); delete item; } status = fMimeType.SetAttrInfo(&newAttributes); } if (status != B_OK) error_alert(B_TRANSLATE("Could not change attributes"), status); PostMessage(B_QUIT_REQUESTED); break; } default: BWindow::MessageReceived(message); break; } }
//------------------------------------------------------------------------- // // Show - Display the file dialog // //------------------------------------------------------------------------- NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) { PRBool result = PR_TRUE; nsFilePanelBeOS *ppanel; file_panel_mode panel_mode; bool allow_multiple_selection = false; uint32 node_flavors; if (mMode == modeGetFolder) { node_flavors = B_DIRECTORY_NODE; panel_mode = B_OPEN_PANEL; } else if (mMode == modeOpen) { node_flavors = B_FILE_NODE; panel_mode = B_OPEN_PANEL; } else if (mMode == modeOpenMultiple) { node_flavors = B_FILE_NODE; panel_mode = B_OPEN_PANEL; allow_multiple_selection = true; } else if (mMode == modeSave) { node_flavors = B_FILE_NODE; panel_mode = B_SAVE_PANEL; } else { printf("nsFilePicker::Show() wrong mode"); return PR_FALSE; } ppanel = new nsFilePanelBeOS( panel_mode, //file_panel_mode mode node_flavors, //uint32 node_flavors allow_multiple_selection, //bool allow_multiple_selection false, //bool modal true //bool hide_when_done ); if (!ppanel) return PR_FALSE; // set title if (!mTitle.IsEmpty()) { char *title_utf8 = ToNewUTF8String(mTitle); ppanel->Window()->SetTitle(title_utf8); Recycle(title_utf8); } // set default text if (!mDefault.IsEmpty()) { char *defaultText = ToNewUTF8String(mDefault); ppanel->SetSaveText(defaultText); Recycle(defaultText); } // set initial directory nsCAutoString initialDir; if (mDisplayDirectory) mDisplayDirectory->GetNativePath(initialDir); if(initialDir.IsEmpty()) { #ifdef FILEPICKER_SAVE_LAST_DIR if (strlen(mLastUsedDirectory) < 2) initialDir.Assign("/boot/home"); else initialDir.Assign(mLastUsedDirectory); #else ppanel->SetPanelDirectory(initialDir.get()); #endif } #ifdef FILEPICKER_SAVE_LAST_DIR ppanel->SetPanelDirectory(initialDir.get()); #endif // set modal feel if (ppanel->LockLooper()) { ppanel->Window()->SetFeel(B_MODAL_APP_WINDOW_FEEL); ppanel->UnlockLooper(); } // Show File Panel ppanel->Show(); ppanel->WaitForSelection(); if (ppanel->IsCancelSelected()) { result = PR_FALSE; } if ((mMode == modeOpen || mMode == modeOpenMultiple || mMode == modeGetFolder) && ppanel->IsOpenSelected()) { BList *list = ppanel->OpenRefs(); uint32 numfiles = list->CountItems(); if ((list) && numfiles >= 1) { nsresult rv = NS_NewISupportsArray(getter_AddRefs(mFiles)); for (uint32 i = 0; i< numfiles; i++) { BPath *path = (BPath *)list->ItemAt(i); if (path->InitCheck() == B_OK) { mFile.Truncate(); // Single and Multiple are exclusive now, though, maybe there is sense // to assign also first list element to mFile even in openMultiple case ? if (mMode == modeOpenMultiple) { nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1", &rv); NS_ENSURE_SUCCESS(rv,rv); rv = file->InitWithNativePath(nsDependentCString(path->Path())); NS_ENSURE_SUCCESS(rv,rv); rv = mFiles->AppendElement(file); NS_ENSURE_SUCCESS(rv,rv); } else { if (i == 0) mFile.Assign(path->Path()); } } else { printf("path.init failed \n"); } } } else { printf("list not init \n"); } } else if (mMode == modeSave && ppanel->IsSaveSelected()) { BString savefilename = ppanel->SaveFileName(); entry_ref ref = ppanel->SaveDirRef(); BPath path(&ref); if (path.InitCheck() == B_OK) { path.Append(savefilename.String(), true); mFile.Assign(path.Path()); } } else { result = PR_FALSE; } // set current directory to mDisplayDirectory entry_ref dir_ref; ppanel->GetPanelDirectory(&dir_ref); BEntry dir_entry(&dir_ref); BPath dir_path; dir_entry.GetPath(&dir_path); if (!mDisplayDirectory) mDisplayDirectory = do_CreateInstance("@mozilla.org/file/local;1"); if (mDisplayDirectory) mDisplayDirectory->InitWithNativePath(nsDependentCString(dir_path.Path())); if (ppanel->Lock()) { ppanel->Quit(); } if (result) { PRInt16 returnOKorReplace = returnOK; #ifdef FILEPICKER_SAVE_LAST_DIR strncpy(mLastUsedDirectory, dir_path.Path(), B_PATH_NAME_LENGTH+1); if (mDisplayDirectory) mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) ); #endif if (mMode == modeSave) { // we must check if file already exists PRBool exists = PR_FALSE; nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1")); NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); file->InitWithNativePath(mFile); file->Exists(&exists); if (exists) returnOKorReplace = returnReplace; } *retval = returnOKorReplace; } else { *retval = returnCancel; } return NS_OK; // TODO: implement filters }
status_t TerminalThemesAddon::ApplyThemeR5(BMessage &theme, uint32 flags) { BMessage termpref; status_t err; struct termprefs tp; err = MyMessage(theme, termpref); if (err) return err; tp.magic = TP_MAGIC; tp.version = TP_VERSION; tp.x = 0; // don't open at specific coords tp.y = 0; if (termpref.FindInt32(TP_COLS, (int32 *)&tp.p.cols) != B_OK) tp.p.cols = 80; if (termpref.FindInt32(TP_ROWS, (int32 *)&tp.p.rows) != B_OK) tp.p.rows = 25; if (termpref.FindInt32(TP_TABWIDTH, (int32 *)&tp.p.tab_width) != B_OK) tp.p.tab_width = 8; BFont tFont; tp.p.font_size = 12; strcpy(tp.p.font, "Courier10 BT/Roman"); if (FindFont(termpref, TP_FONT, 0, &tFont) == B_OK) { font_family ff; font_style fs; tFont.GetFamilyAndStyle(&ff, &fs); strcpy(tp.p.font, ff); strcat(tp.p.font, "/"); strcat(tp.p.font, fs); tp.p.font_size = (uint32)tFont.Size(); } tp.p.cursor_blink_rate = 1000000; tp.p.refresh_rate = 0; if (FindRGBColor(termpref, TP_BG, 0, &tp.p.bg) != B_OK) tp.p.bg = make_color(255,255,255,255); if (FindRGBColor(termpref, TP_FG, 0, &tp.p.fg) != B_OK) tp.p.fg = make_color(0,0,0,255); if (FindRGBColor(termpref, TP_CURBG, 0, &tp.p.curbg) != B_OK) tp.p.curbg = make_color(255,255,255,255); if (FindRGBColor(termpref, TP_CURFG, 0, &tp.p.curfg) != B_OK) tp.p.curfg = make_color(0,0,0,255); if (FindRGBColor(termpref, TP_SELBG, 0, &tp.p.selbg) != B_OK) tp.p.selbg = make_color(0,0,0,255); if (FindRGBColor(termpref, TP_SELFG, 0, &tp.p.selfg) != B_OK) tp.p.selfg = make_color(255,255,255,255); if (termpref.FindInt32(TP_ENCODING, (int32 *)&tp.p.encoding) != B_OK) tp.p.encoding = 0; // UTF-8 if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) { BPath pTermPref; if (find_directory(B_USER_SETTINGS_DIRECTORY, &pTermPref) < B_OK) return EINVAL; pTermPref.Append("Terminal"); BFile fTermPref(pTermPref.Path(), B_WRITE_ONLY|B_CREATE_FILE|B_ERASE_FILE); if (fTermPref.InitCheck() != B_OK) { return fTermPref.InitCheck(); } fTermPref.Write(&tp, sizeof(struct termprefs)); BNodeInfo ni(&fTermPref); if (ni.InitCheck() == B_OK) ni.SetType("application/x-vnd.Be-pref"); } if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) { BList teamList; app_info ainfo; int32 count, i; be_roster->GetAppList(&teamList); count = teamList.CountItems(); for (i = 0; i < count; i++) { if (be_roster->GetRunningAppInfo((team_id)(teamList.ItemAt(i)), &ainfo) == B_OK) { if (!strcmp(ainfo.signature, kBeOSTerminalAppSig)) { err = B_OK; BMessage msg(MSG_R5_SET_PREF); BMessenger msgr(NULL, ainfo.team); tp.x = 0; tp.y = 0; //msg.AddData("", 'UBYT', &(tp.p), sizeof(struct tpref)); msg.AddData("", 'UBYT', &(tp), sizeof(struct termprefs)); msg.AddSpecifier("Window", 0L); err = msgr.SendMessage(&msg); } } } } return B_OK; }