本文整理汇总了C++中BPath::SetTo方法的典型用法代码示例。如果您正苦于以下问题:C++ BPath::SetTo方法的具体用法?C++ BPath::SetTo怎么用?C++ BPath::SetTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BPath
的用法示例。
在下文中一共展示了BPath::SetTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
ImageView::SetImage(BMessage *pmsg)
{
// Replace current image with the image
// specified in the given BMessage
entry_ref ref;
if (!pmsg)
ref = fcurrentRef;
else if (pmsg->FindRef("refs", &ref) != B_OK)
// If refs not found, just ignore the message
return;
StatusCheck chk;
try {
BFile file(&ref, B_READ_ONLY);
chk = file.InitCheck();
BTranslatorRoster roster, *proster;
proster = SelectTranslatorRoster(roster);
if (!proster)
// throw exception
chk = B_ERROR;
// determine what type the image is
translator_info tinfo;
BMessage ioExtension;
if (ref != fcurrentRef)
// if new image, reset to first document
fdocumentIndex = 1;
chk = ioExtension.AddInt32("/documentIndex", fdocumentIndex);
chk = proster->Identify(&file, &ioExtension, &tinfo, 0, NULL,
B_TRANSLATOR_BITMAP);
// perform the actual translation
BBitmapStream outstream;
chk = proster->Translate(&file, &tinfo, &ioExtension, &outstream,
B_TRANSLATOR_BITMAP);
BBitmap *pbitmap = NULL;
chk = outstream.DetachBitmap(&pbitmap);
delete fpbitmap;
fpbitmap = pbitmap;
pbitmap = NULL;
fcurrentRef = ref;
// need to keep the ref around if user wants to switch pages
int32 documentCount = 0;
if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK &&
documentCount > 0)
fdocumentCount = documentCount;
else
fdocumentCount = 1;
// Set the name of the Window to reflect the file name
BWindow *pwin = Window();
BEntry entry(&ref);
BPath path;
if (entry.InitCheck() == B_OK) {
if (path.SetTo(&entry) == B_OK)
pwin->SetTitle(path.Leaf());
else
pwin->SetTitle(IMAGEWINDOW_TITLE);
} else
pwin->SetTitle(IMAGEWINDOW_TITLE);
UpdateInfoWindow(path, ioExtension, tinfo, proster);
// Resize parent window and set size limits to
// reflect the size of the new bitmap
float width, height;
BMenuBar *pbar = pwin->KeyMenuBar();
width = fpbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH + (BORDER_WIDTH * 2);
height = fpbitmap->Bounds().Height() +
pbar->Bounds().Height() + B_H_SCROLL_BAR_HEIGHT + (BORDER_HEIGHT * 2) + 1;
BScreen *pscreen = new BScreen(pwin);
BRect rctscreen = pscreen->Frame();
if (width > rctscreen.Width())
width = rctscreen.Width();
if (height > rctscreen.Height())
height = rctscreen.Height();
pwin->SetSizeLimits(B_V_SCROLL_BAR_WIDTH * 4, width,
pbar->Bounds().Height() + (B_H_SCROLL_BAR_HEIGHT * 4) + 1, height);
pwin->SetZoomLimits(width, height);
AdjustScrollBars();
//pwin->Zoom();
// Perform all of the hard work of resizing the
// window while taking into account the size of
// the screen, the tab and borders of the window
//
// HACK: Need to fix case where window un-zooms
// when the window is already the correct size
// for the current image
// repaint view
Invalidate();
} catch (StatusNotOKException) {
//.........这里部分代码省略.........
示例2: directory
void
KeymapWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
{
entry_ref ref;
int32 i = 0;
while (message->FindRef("refs", i++, &ref) == B_OK) {
fCurrentMap.Load(ref);
fAppliedMap = fCurrentMap;
}
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
fSystemListView->DeselectAll();
fUserListView->DeselectAll();
break;
}
case B_SAVE_REQUESTED:
{
entry_ref ref;
const char *name;
if (message->FindRef("directory", &ref) == B_OK
&& message->FindString("name", &name) == B_OK) {
BDirectory directory(&ref);
BEntry entry(&directory, name);
entry.GetRef(&ref);
fCurrentMap.SetName(name);
fCurrentMap.Save(ref);
fAppliedMap = fCurrentMap;
_FillUserMaps();
fCurrentMapName = name;
_SelectCurrentMap();
}
break;
}
case kMsgMenuFileOpen:
fOpenPanel->Show();
break;
case kMsgMenuFileSaveAs:
fSavePanel->Show();
break;
case kChangeKeyboardLayout:
{
entry_ref ref;
BPath path;
if (message->FindRef("ref", &ref) == B_OK)
path.SetTo(&ref);
_SetKeyboardLayout(path.Path());
break;
}
case kMsgSwitchShortcuts:
_SwitchShortcutKeys();
break;
case kMsgMenuFontChanged:
{
BMenuItem *item = fFontMenu->FindMarked();
if (item != NULL) {
BFont font;
font.SetFamilyAndStyle(item->Label(), NULL);
fKeyboardLayoutView->SetFont(font);
fTextControl->TextView()->SetFontAndColor(&font);
}
break;
}
case kMsgSystemMapSelected:
case kMsgUserMapSelected:
{
BListView* listView;
BListView* otherListView;
if (message->what == kMsgSystemMapSelected) {
listView = fSystemListView;
otherListView = fUserListView;
} else {
listView = fUserListView;
otherListView = fSystemListView;
}
int32 index = listView->CurrentSelection();
if (index < 0)
break;
// Deselect item in other BListView
otherListView->DeselectAll();
if (index == 0 && listView == fUserListView) {
// we can safely ignore the "(Current)" item
break;
}
KeymapListItem* item
= static_cast<KeymapListItem*>(listView->ItemAt(index));
//.........这里部分代码省略.........
示例3: MessageReceived
bool RHServer::MessageReceived( HTTPRequest *request )
{
if (strlen(request->GetRequestLine()) > 4047)
{
log_printf( "%ld ABUSE: Client may be attempting to perform overflow exploit, terminating connection\n", sn );
HTTPResponse response;
response.SetHTMLMessage( 501 ); // Not Implemented
request->SendReply( &response );
return true;
}
// ****
// Make log entry of request and headers
// ****
//printf ("request: %s\n", request->GetRequestLine());
log_printf( "%ld Request-Line: %s\n", sn, request->GetRequestLine() );
const char *header;
for ( int32 i = 0; (header = request->HeaderAt(i)); i++ )
log_printf( "%ld Header: %s\n", sn, header );
// ****
// Setup URI
// ****
// Setup the broken URI
brokenURI brURI;
request->ParseURI( &brURI );
int32 slength = uri_unescape_str( brURI.path, brURI.path, 4096 );
// ****
// Set Web Directory based on the "host" name from "virtual hosts" table.
// ****
VHost *vhost;
BPath webDirectory;
const char *webIndex;
// Get host_name
// If hostName was not found in URI, set to Host header or default if none
if( brURI.host[0] == 0 )
{
if( !request->FindHeader( kHEAD_HOST, brURI.host, 64 ) )
strcpy( brURI.host, kDEFAULT_HOST ); // Set to default host
}
// Find Host in virtual hosts table
if( (vhost = virtualHosts->FindVHost( brURI.host )) == NULL )
{
if( (vhost = virtualHosts->FindVHost( kDEFAULT_HOST )) == NULL )
{
// Could not find a default web directory
HTTPResponse response;
response.SetHTMLMessage( 500, "500 No default web directory!" ); // Internal Server Error
request->SendReply( &response );
return false;
}
}
webDirectory.SetTo( vhost->GetWebroot() );
webIndex = ( vhost->GetIndex() ); // this is by default "index.html" if not present in virtual hosts table
// ****
// Append index to URI and check for security violations
// ****
// Append index (default file name) from virtual hosts table if not present in path
if( ((brURI.path[0] == 0)||(brURI.path[slength-1] == '/'))&&(slength+11<4096) )
strcat( brURI.path, webIndex );
// Have they attempted a security violation?
if( strstr( brURI.path, ".." )||strstr( brURI.path, "./" ) )
{
HTTPResponse response;
response.SetHTMLMessage( 403 ); // Forbidden
request->SendReply( &response );
return true;
}
// ****
// Setup PB
// ****
RequestPB pb;
pb.request = request;
pb.webDirectory = &webDirectory;
pb.vresources = &vhost->vresources;
pb.realms = &vhost->realms;
pb.brURI = &brURI;
pb.environ = environ;
pb.authenticate = true;
pb.sn = sn;
pb.cookie = NULL;
// ****
// Call hmodule_roster::HandleRequest() to process the request
// ****
hmodule_roster->HandleRequest( &pb );
//.........这里部分代码省略.........
示例4: trackerMessenger
status_t
GrepWindow::_SelectFilesInTracker(BList* folderList, BMessage* refsMessage)
{
// loops over Tracker windows, find each windowRef,
// extract the refs that are children of windowRef,
// add refs to selection-message
status_t status = B_OK;
BMessenger trackerMessenger(TRACKER_SIGNATURE);
BMessage windowSendMessage;
BMessage windowReplyMessage;
BMessage selectionSendMessage;
BMessage selectionReplyMessage;
if (!trackerMessenger.IsValid())
return status;
// loop over Tracker windows
for (int32 windowCount = 1; ; windowCount++) {
windowSendMessage.MakeEmpty();
windowReplyMessage.MakeEmpty();
windowSendMessage.what = B_GET_PROPERTY;
windowSendMessage.AddSpecifier("Path");
windowSendMessage.AddSpecifier("Poses");
windowSendMessage.AddSpecifier("Window", windowCount);
status = trackerMessenger.SendMessage(&windowSendMessage,
&windowReplyMessage);
if (status != B_OK)
return status;
entry_ref windowRef;
status = windowReplyMessage.FindRef("result", &windowRef);
if (status != B_OK)
break;
int32 folderCount = folderList->CountItems();
// loop over folders in folderList
for (int32 x = 0; x < folderCount; x++) {
BPath* folderPath = static_cast<BPath*>(folderList->ItemAt(x));
if (folderPath == NULL)
break;
BString folderString = folderPath->Path();
BEntry windowEntry;
BPath windowPath;
BString windowString;
status = windowEntry.SetTo(&windowRef);
if (status != B_OK)
break;
status = windowPath.SetTo(&windowEntry);
if (status != B_OK)
break;
windowString = windowPath.Path();
// if match, loop over items in refsMessage
// and add those that live in window/folder
// to a selection message
if (windowString == folderString) {
selectionSendMessage.MakeEmpty();
selectionSendMessage.what = B_SET_PROPERTY;
selectionReplyMessage.MakeEmpty();
// loop over refs and add to message
entry_ref ref;
for (int32 index = 0; ; index++) {
status = refsMessage->FindRef("refs", index, &ref);
if (status != B_OK)
break;
BDirectory directory(&windowRef);
BEntry entry(&ref);
if (directory.Contains(&entry))
selectionSendMessage.AddRef("data", &ref);
}
// finish selection message
selectionSendMessage.AddSpecifier("Selection");
selectionSendMessage.AddSpecifier("Poses");
selectionSendMessage.AddSpecifier("Window", windowCount);
trackerMessenger.SendMessage(&selectionSendMessage,
&selectionReplyMessage);
}
}
}
return B_OK;
}
示例5: CopyStrucFile
void TJerFile::CopyStrucFile(const char *SrcDir, const char *DestDir, BList *Diff)
{
entry_ref *truc;
BEntry *entry;
BPath chemin;
BPath Destination;
char *Relative;
char *TheRelativePathAndName;
/*
printf("------------------------------------\n");
printf("ZIPPathName : %s \n",ZIPPathName);
printf("SrcDir : %s \n",SrcDir);
printf("DestDir : %s \n",DestDir);
printf("------------------------------------\n");
*/
BMessage *AMessage;
AMessage = new BMessage(B_RESET_STATUS_BAR);
AMessage->AddFloat("maximum",Diff->CountItems());
MyInvoker.Invoke(AMessage);
delete AMessage;
try
{
for (int ind=0;ind < Diff->CountItems();ind++ )
{
truc = (entry_ref *)(Diff->ItemAt(ind));
if (truc!=NULL)
{
entry = new BEntry(truc);
entry->GetPath(&chemin);
if (CreateZIP == true)
{
// printf("Zipping............\n");
char *titi;
titi = (char *)malloc(sizeof(char)*(strlen(DestDir) + strlen(FBackupName) +2 )); //count the \0 and the / for the directory!
strcpy(titi,DestDir);
strcat(titi,"/");
strcat(titi,FBackupName);
// string titi(DestDir);
/*
printf("------------------------------------\n");
printf("ZIPPathName : %s \n",ZIPPathName);
printf("chemin : %s \n",chemin.Path());
printf("titi : %s \n",titi.c_str());
printf("SrcDir : %s \n",SrcDir);
printf("DestDir : %s \n",DestDir);
printf("------------------------------------\n");
*/
// titi = titi + "/BeBackup.zip";
// AddFileToZIP(chemin.Path(),titi.c_str());
AddFileToZIP(chemin.Path(),titi);
}
else
{
GetRelativePath(SrcDir,chemin.Path(),&Relative);
CreateCompletePath(DestDir,Relative);
GetRelativePathAndName(SrcDir,chemin.Path(),&TheRelativePathAndName);
Destination.SetTo(DestDir);
string toto(Destination.Path());
toto = toto + TheRelativePathAndName;
CopyFile(chemin.Path(),toto.c_str());
}
delete entry;
}
else
printf("Items is null...\n");
}
} //Try
catch(GeneralException &e)
{
printf("Exception while copying... %s %s",e.Message.c_str(),e.Location.c_str());
}
}
示例6: BAlert
void
GrepWindow::_OnSelectInTracker()
{
if (fSearchResults->CurrentSelection() < 0) {
BAlert* alert = new BAlert("Info",
B_TRANSLATE("Please select the files you wish to have selected for you in "
"Tracker."),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(NULL);
return;
}
BMessage message;
BString filePath;
BPath folderPath;
BList folderList;
BString lastFolderAddedToList;
for (int32 index = 0; ; index++) {
BStringItem* item = dynamic_cast<BStringItem*>(
fSearchResults->ItemAt(index));
if (item == NULL)
break;
// only open selected and top level (file) items
if (!item->IsSelected() || item->OutlineLevel() > 0)
continue;
// check if this was previously opened
if (filePath == item->Text())
continue;
filePath = item->Text();
entry_ref file_ref;
if (get_ref_for_path(filePath.String(), &file_ref) != B_OK)
continue;
message.AddRef("refs", &file_ref);
// add parent folder to list of folders to open
folderPath.SetTo(filePath.String());
if (folderPath.GetParent(&folderPath) == B_OK) {
BPath* path = new BPath(folderPath);
if (path->Path() != lastFolderAddedToList) {
// catches some duplicates
folderList.AddItem(path);
lastFolderAddedToList = path->Path();
} else
delete path;
}
}
_RemoveFolderListDuplicates(&folderList);
_OpenFoldersInTracker(&folderList);
int32 aShortWhile = 100000;
snooze(aShortWhile);
if (!_AreAllFoldersOpenInTracker(&folderList)) {
for (int32 x = 0; x < 5; x++) {
aShortWhile += 100000;
snooze(aShortWhile);
_OpenFoldersInTracker(&folderList);
}
}
if (!_AreAllFoldersOpenInTracker(&folderList)) {
BString str1;
str1 << B_TRANSLATE("%APP_NAME couldn't open one or more folders.");
str1.ReplaceFirst("%APP_NAME",APP_NAME);
BAlert* alert = new BAlert(NULL, str1.String(), B_TRANSLATE("OK"),
NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(NULL);
goto out;
}
_SelectFilesInTracker(&folderList, &message);
out:
// delete folderList contents
int32 folderCount = folderList.CountItems();
for (int32 x = 0; x < folderCount; x++)
delete static_cast<BPath*>(folderList.ItemAt(x));
}
示例7: BMessage
status_t
PackageView::_InstallTypeChanged(int32 index)
{
if (index < 0)
return B_ERROR;
// Clear the choice list
for (int32 i = fDestination->CountItems() - 1; i >= 0; i--) {
BMenuItem* item = fDestination->RemoveItem(i);
delete item;
}
fCurrentType = index;
pkg_profile* profile = fInfo.GetProfile(index);
if (profile == NULL)
return B_ERROR;
BString typeDescription = profile->description;
if (typeDescription.IsEmpty())
typeDescription = profile->name;
fInstallTypeDescriptionView->SetText(typeDescription.String());
BPath path;
BVolume volume;
if (profile->path_type == P_INSTALL_PATH) {
BMenuItem* item = NULL;
if (find_directory(B_SYSTEM_NONPACKAGED_DIRECTORY, &path) == B_OK) {
dev_t device = dev_for_path(path.Path());
if (volume.SetTo(device) == B_OK && !volume.IsReadOnly()
&& path.Append("apps") == B_OK) {
item = _AddDestinationMenuItem(path.Path(), volume.FreeBytes(),
path.Path());
}
}
if (item != NULL) {
item->SetMarked(true);
fCurrentPath.SetTo(path.Path());
fDestination->AddSeparatorItem();
}
_AddMenuItem(B_TRANSLATE("Other" B_UTF8_ELLIPSIS),
new BMessage(P_MSG_OPEN_PANEL), fDestination);
fDestField->SetEnabled(true);
} else if (profile->path_type == P_USER_PATH) {
bool defaultPathSet = false;
BVolumeRoster roster;
while (roster.GetNextVolume(&volume) != B_BAD_VALUE) {
BDirectory mountPoint;
if (volume.IsReadOnly() || !volume.IsPersistent()
|| volume.GetRootDirectory(&mountPoint) != B_OK) {
continue;
}
if (path.SetTo(&mountPoint, NULL) != B_OK)
continue;
char volumeName[B_FILE_NAME_LENGTH];
volume.GetName(volumeName);
BMenuItem* item = _AddDestinationMenuItem(volumeName,
volume.FreeBytes(), path.Path());
// The first volume becomes the default element
if (!defaultPathSet) {
item->SetMarked(true);
fCurrentPath.SetTo(path.Path());
defaultPathSet = true;
}
}
fDestField->SetEnabled(true);
} else
fDestField->SetEnabled(false);
return B_OK;
}
示例8: dir
void
DeskbarView::MessageReceived(BMessage* message)
{
switch (message->what) {
case MD_CHECK_SEND_NOW:
// also happens in DeskbarView::MouseUp() with
// B_TERTIARY_MOUSE_BUTTON pressed
BMailDaemon().CheckAndSendQueuedMail();
break;
case MD_CHECK_FOR_MAILS:
BMailDaemon().CheckMail(message->FindInt32("account"));
break;
case MD_SEND_MAILS:
BMailDaemon().SendQueuedMail();
break;
case MD_OPEN_NEW:
{
char* argv[] = {(char *)"New Message", (char *)"mailto:"};
be_roster->Launch("text/x-email", 2, argv);
break;
}
case MD_OPEN_PREFS:
be_roster->Launch("application/x-vnd.Haiku-Mail");
break;
case MD_REFRESH_QUERY:
_RefreshMailQuery();
break;
case B_QUERY_UPDATE:
{
int32 what;
dev_t device;
ino_t directory;
const char *name;
entry_ref ref;
message->FindInt32("opcode", &what);
message->FindInt32("device", &device);
message->FindInt64("directory", &directory);
switch (what) {
case B_ENTRY_CREATED:
if (message->FindString("name", &name) == B_OK) {
ref.device = device;
ref.directory = directory;
ref.set_name(name);
if (!_EntryInTrash(&ref))
fNewMessages++;
}
break;
case B_ENTRY_REMOVED:
node_ref node;
node.device = device;
node.node = directory;
BDirectory dir(&node);
BEntry entry(&dir, NULL);
entry.GetRef(&ref);
if (!_EntryInTrash(&ref))
fNewMessages--;
break;
}
fStatus = fNewMessages > 0 ? kStatusNewMail : kStatusNoMail;
Invalidate();
break;
}
case B_QUIT_REQUESTED:
BMailDaemon().Quit();
break;
// open received files in the standard mail application
case B_REFS_RECEIVED:
{
BMessage argv(B_ARGV_RECEIVED);
argv.AddString("argv", "E-mail");
entry_ref ref;
BPath path;
int i = 0;
while (message->FindRef("refs", i++, &ref) == B_OK
&& path.SetTo(&ref) == B_OK) {
//fprintf(stderr,"got %s\n", path.Path());
argv.AddString("argv", path.Path());
}
if (i > 1) {
argv.AddInt32("argc", i);
be_roster->Launch("text/x-email", &argv);
}
break;
}
default:
BView::MessageReceived(message);
}
}
示例9: process_refs
void process_refs(entry_ref dir_ref, BMessage *msg, void *)
{
try {
bool terminal;
BString script = load_addon_data(&terminal);
int32 refs; type_code type;
msg->GetInfo("refs",&type,&refs);
vector<BPath> paths(refs);
// set up argv
size_t argc=0;
vector<const char *> argv(refs+6);
BPath terminalPath;
if (terminal)
{
entry_ref terminal_ref;
be_roster->FindApp(TERMINAL_SIGNATURE, &terminal_ref);
terminalPath.SetTo(&terminal_ref);
argv[argc++]=terminalPath.Path();
}
argv[argc++]="/bin/sh";
argv[argc++]="-c";
argv[argc++]=script.String();
argv[argc++]="--";
entry_ref ref;
BEntry entry;
for (size_t n=0; msg->FindRef("refs", n, &ref) == B_OK; n++) {
entry.SetTo(&ref);
entry.GetPath(&paths[n]);
argv[argc++]=paths[n].Path();
}
// set the current directory/keep track of old
BPath wd, pwd(getcwd(NULL,0));
entry.SetTo(&dir_ref);
entry.GetPath(&wd);
chdir(wd.Path());
// set up dummy stdin
int oldin=dup(0);
close(0);
open("/dev/null",O_RDONLY);
// load the command
argv[argc]=NULL;
thread_id tid=load_image(argc, &argv.front(), (const char**)environ);
// restore stdin, pwd
dup2(oldin,0);
close(oldin);
chdir(pwd.Path());
if (tid<0)
throw strerror(tid);
else // if all is well, proceed
resume_thread(tid);
} catch (const char *error) {
BAlert *alert=new BAlert(
"TrackerScript error", error, "Phoey!",
0,0, B_WIDTH_AS_USUAL,B_STOP_ALERT);
alert->Go();
}
}
示例10: if
void
NotificationView::_LoadIcon()
{
// First try to get the icon from the caller application
app_info info;
BMessenger msgr = fDetails->ReturnAddress();
if (msgr.IsValid())
be_roster->GetRunningAppInfo(msgr.Team(), &info);
else if (fType == B_PROGRESS_NOTIFICATION)
be_roster->GetAppInfo("application/x-vnd.Haiku-notification_server",
&info);
BPath path;
path.SetTo(&info.ref);
fBitmap = _ReadNodeIcon(path.Path(), fParent->IconSize());
if (fBitmap)
return;
// If that failed get icons from app_server
if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) != B_OK)
return;
path.Append("app_server");
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() != B_OK)
return;
BResources res(&file);
if (res.InitCheck() != B_OK)
return;
// Which one should we choose?
const char* iconName = "";
switch (fType) {
case B_INFORMATION_NOTIFICATION:
iconName = "info";
break;
case B_ERROR_NOTIFICATION:
iconName = "stop";
break;
case B_IMPORTANT_NOTIFICATION:
iconName = "warn";
break;
default:
return;
}
// Allocate the bitmap
fBitmap = new BBitmap(BRect(0, 0, (float)B_LARGE_ICON - 1,
(float)B_LARGE_ICON - 1), B_RGBA32);
if (!fBitmap || fBitmap->InitCheck() != B_OK) {
fBitmap = NULL;
return;
}
// Load raw icon data
size_t size = 0;
const uint8* data = (const uint8*)res.LoadResource(B_VECTOR_ICON_TYPE,
iconName, &size);
if ((data == NULL
|| BIconUtils::GetVectorIcon(data, size, fBitmap) != B_OK))
fBitmap = NULL;
}
示例11: BPopUpMenu
MediaConverterWindow::MediaConverterWindow(BRect frame)
:
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("MediaConverter"),
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE
| B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS
| B_AUTO_UPDATE_SIZE_LIMITS),
fVideoQuality(75),
fAudioQuality(75),
fSaveFilePanel(NULL),
fOpenFilePanel(NULL),
fOutputDirSpecified(false),
fEnabled(true),
fConverting(false),
fCancelling(false)
{
BPath outputDir;
if (find_directory(B_USER_DIRECTORY, &outputDir) != B_OK)
outputDir.SetTo("/boot/home");
fOutputDir.SetTo(outputDir.Path());
fMenuBar = new BMenuBar("menubar");
_CreateMenu();
float padding = be_control_look->DefaultItemSpacing();
fListView = new MediaFileListView();
fListView->SetExplicitMinSize(BSize(padding * kMinSourceWidth, B_SIZE_UNSET));
BScrollView* scroller = new BScrollView(NULL, fListView, 0, false, true);
// file list view box
fSourcesBox = new BBox(B_FANCY_BORDER, scroller);
fSourcesBox->SetLayout(new BGroupLayout(B_HORIZONTAL, 0));
// fSourcesBox's layout adjusted in _UpdateLabels
// info box
fInfoView = new MediaFileInfoView();
fInfoView->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
B_ALIGN_VERTICAL_UNSET));
fInfoBox = new BBox(B_FANCY_BORDER, fInfoView);
// output menu fields
fFormatMenu = new BMenuField(NULL, B_TRANSLATE("File format:"),
new BPopUpMenu(""));
fAudioMenu = new BMenuField(NULL, B_TRANSLATE("Audio encoding:"),
new BPopUpMenu(""));
fVideoMenu = new BMenuField(NULL, B_TRANSLATE("Video encoding:"),
new BPopUpMenu(""));
// output folder
fDestButton = new BButton(B_TRANSLATE("Output folder"),
new BMessage(OUTPUT_FOLDER_MESSAGE));
BAlignment labelAlignment(be_control_look->DefaultLabelAlignment());
fOutputFolder = new BStringView(NULL, outputDir.Path());
fOutputFolder->SetExplicitAlignment(labelAlignment);
// start/end duration
fStartDurationTC = new BTextControl(NULL, "0", NULL);
BLayoutItem* startDuration = fStartDurationTC->CreateTextViewLayoutItem();
startDuration->SetExplicitSize(BSize(padding * kDurationWidth, B_SIZE_UNSET));
startDuration->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
B_ALIGN_VERTICAL_CENTER));
fEndDurationTC = new BTextControl(NULL, "0", NULL);
BLayoutItem* endDuration = fEndDurationTC->CreateTextViewLayoutItem();
endDuration->SetExplicitSize(BSize(padding * kDurationWidth, B_SIZE_UNSET));
endDuration->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
B_ALIGN_VERTICAL_CENTER));
// video quality
fVideoQualitySlider = new BSlider("VSlider", "" ,
new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL);
fVideoQualitySlider->SetModificationMessage(
new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE));
fVideoQualitySlider->SetValue(fVideoQuality);
fVideoQualitySlider->SetEnabled(false);
fVideoQualitySlider->SetExplicitSize(BSize(padding * kQualitySliderWidth,
B_SIZE_UNSET));
// audio quality
fAudioQualitySlider = new BSlider("ASlider", "" ,
new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL);
fAudioQualitySlider->SetModificationMessage(
new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE));
fAudioQualitySlider->SetValue(fAudioQuality);
fAudioQualitySlider->SetEnabled(false);
fAudioQualitySlider->SetExplicitSize(BSize(padding * kQualitySliderWidth,
B_SIZE_UNSET));
// output format box
BView* outputGrid = BLayoutBuilder::Grid<>()
.Add(fFormatMenu->CreateLabelLayoutItem(), 0, 0)
.Add(fFormatMenu->CreateMenuBarLayoutItem(), 1, 0)
.Add(fAudioMenu->CreateLabelLayoutItem(), 0, 1)
.Add(fAudioMenu->CreateMenuBarLayoutItem(), 1, 1)
.Add(fVideoMenu->CreateLabelLayoutItem(), 0, 2)
.Add(fVideoMenu->CreateMenuBarLayoutItem(), 1, 2)
.Add(fDestButton, 0, 3)
.Add(fOutputFolder, 1, 3)
.Add(fStartDurationTC->CreateLabelLayoutItem(), 0, 4)
.Add(startDuration, 1, 4)
.Add(fEndDurationTC->CreateLabelLayoutItem(), 0, 5)
//.........这里部分代码省略.........
示例12: packageReader
status_t
BPackageRoster::GetActivePackages(BPackageInstallationLocation location,
BPackageInfoSet& packageInfos)
{
// This method makes sense only on an installed Haiku, but not for the build
// tools.
#if defined(__HAIKU__) && !defined(HAIKU_HOST_PLATFORM_HAIKU)
// check the given location
directory_which packagesDirectory;
switch (location) {
case B_PACKAGE_INSTALLATION_LOCATION_SYSTEM:
packagesDirectory = B_SYSTEM_PACKAGES_DIRECTORY;
break;
case B_PACKAGE_INSTALLATION_LOCATION_COMMON:
packagesDirectory = B_COMMON_PACKAGES_DIRECTORY;
break;
case B_PACKAGE_INSTALLATION_LOCATION_HOME:
packagesDirectory = B_USER_PACKAGES_DIRECTORY;
break;
default:
return B_BAD_VALUE;
}
// find the package links directory
BPath packageLinksPath;
status_t error = find_directory(B_PACKAGE_LINKS_DIRECTORY,
&packageLinksPath);
if (error != B_OK)
return error;
// find and open the packages directory
BPath packagesDirPath;
error = find_directory(packagesDirectory, &packagesDirPath);
if (error != B_OK)
return error;
BDirectory directory;
error = directory.SetTo(packagesDirPath.Path());
if (error != B_OK)
return error;
// TODO: Implement that correctly be reading the activation files/directory!
// iterate through the packages
char buffer[sizeof(dirent) + B_FILE_NAME_LENGTH];
dirent* entry = (dirent*)&buffer;
while (directory.GetNextDirents(entry, sizeof(buffer), 1) == 1) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
// get the full package file path
BPath packagePath;
error = packagePath.SetTo(packagesDirPath.Path(), entry->d_name);
if (error != B_OK)
continue;
// read the package info from the file
BPackageReader packageReader(NULL);
error = packageReader.Init(packagePath.Path());
if (error != B_OK)
continue;
BPackageInfo info;
BPackageInfoContentHandler handler(info);
error = packageReader.ParseContent(&handler);
if (error != B_OK || info.InitCheck() != B_OK)
continue;
// check whether the package is really active by verifying that a
// package link exists for it
BString packageLinkName(info.Name());
packageLinkName << '-' << info.Version().ToString();
BPath packageLinkPath;
struct stat st;
if (packageLinkPath.SetTo(packageLinksPath.Path(), packageLinkName)
!= B_OK
|| lstat(packageLinkPath.Path(), &st) != 0) {
continue;
}
// add the info
error = packageInfos.AddInfo(info);
if (error != B_OK)
return error;
}
return B_OK;
#else
return B_NOT_SUPPORTED;
#endif
}
示例13: tracker
BPopUpMenu*
DeskbarView::_BuildMenu()
{
BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
menu->SetFont(be_plain_font);
menu->AddItem(new BMenuItem(B_TRANSLATE("Create new message"
B_UTF8_ELLIPSIS), new BMessage(MD_OPEN_NEW)));
menu->AddSeparatorItem();
BMessenger tracker(kTrackerSignature);
BNavMenu* navMenu;
BMenuItem* item;
BMessage* msg;
entry_ref ref;
BPath path;
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
path.Append("Mail/Menu Links");
BDirectory directory;
if (_CreateMenuLinks(directory, path)) {
int32 count = 0;
while (directory.GetNextRef(&ref) == B_OK) {
count++;
path.SetTo(&ref);
// the true here dereferences the symlinks all the way :)
BEntry entry(&ref, true);
// do we want to use the NavMenu, or just an ordinary BMenuItem?
// we are using the NavMenu only for directories and queries
bool useNavMenu = false;
if (entry.InitCheck() == B_OK) {
if (entry.IsDirectory())
useNavMenu = true;
else if (entry.IsFile()) {
// Files should use the BMenuItem unless they are queries
char mimeString[B_MIME_TYPE_LENGTH];
BNode node(&entry);
BNodeInfo info(&node);
if (info.GetType(mimeString) == B_OK
&& strcmp(mimeString, "application/x-vnd.Be-query")
== 0)
useNavMenu = true;
}
// clobber the existing ref only if the symlink derefernces
// completely, otherwise we'll stick with what we have
entry.GetRef(&ref);
}
msg = new BMessage(B_REFS_RECEIVED);
msg->AddRef("refs", &ref);
if (useNavMenu) {
item = new BMenuItem(navMenu = new BNavMenu(path.Leaf(),
B_REFS_RECEIVED, tracker), msg);
navMenu->SetNavDir(&ref);
} else
item = new BMenuItem(path.Leaf(), msg);
menu->AddItem(item);
if (entry.InitCheck() != B_OK)
item->SetEnabled(false);
}
if (count > 0)
menu->AddSeparatorItem();
}
// Hack for R5's buggy Query Notification
#ifdef HAIKU_TARGET_PLATFORM_BEOS
menu->AddItem(new BMenuItem(B_TRANSLATE("Refresh New Mail Count"),
new BMessage(MD_REFRESH_QUERY)));
#endif
// The New E-mail query
if (fNewMessages > 0) {
static BMessageFormat format(B_TRANSLATE(
"{0, plural, one{# new message} other{# new messages}}"));
BString string;
format.Format(string, fNewMessages);
_GetNewQueryRef(ref);
item = new BMenuItem(navMenu = new BNavMenu(string.String(),
B_REFS_RECEIVED, BMessenger(kTrackerSignature)),
msg = new BMessage(B_REFS_RECEIVED));
msg->AddRef("refs", &ref);
navMenu->SetNavDir(&ref);
menu->AddItem(item);
} else {
menu->AddItem(item = new BMenuItem(B_TRANSLATE("No new messages"),
NULL));
item->SetEnabled(false);
}
//.........这里部分代码省略.........
示例14: directory
void
KeymapWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
{
entry_ref ref;
int32 i = 0;
while (message->FindRef("refs", i++, &ref) == B_OK) {
fCurrentMap.Load(ref);
fAppliedMap = fCurrentMap;
}
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
fSystemListView->DeselectAll();
fUserListView->DeselectAll();
break;
}
case B_SAVE_REQUESTED:
{
entry_ref ref;
const char* name;
if (message->FindRef("directory", &ref) == B_OK
&& message->FindString("name", &name) == B_OK) {
BDirectory directory(&ref);
BEntry entry(&directory, name);
entry.GetRef(&ref);
fCurrentMap.SetName(name);
fCurrentMap.Save(ref);
fAppliedMap = fCurrentMap;
_FillUserMaps();
fCurrentMapName = name;
_SelectCurrentMap();
}
break;
}
case kMsgMenuFileOpen:
fOpenPanel->Show();
break;
case kMsgMenuFileSaveAs:
fSavePanel->Show();
break;
case kMsgShowModifierKeysWindow:
be_app->PostMessage(kMsgShowModifierKeysWindow);
break;
case kChangeKeyboardLayout:
{
entry_ref ref;
BPath path;
if (message->FindRef("ref", &ref) == B_OK)
path.SetTo(&ref);
_SetKeyboardLayout(path.Path());
break;
}
case kMsgSwitchShortcuts:
_SwitchShortcutKeys();
break;
case kMsgMenuFontChanged:
{
BMenuItem* item = fFontMenu->FindMarked();
if (item != NULL) {
BFont font;
font.SetFamilyAndStyle(item->Label(), NULL);
fKeyboardLayoutView->SetBaseFont(font);
fTextControl->TextView()->SetFontAndColor(&font);
}
break;
}
case kMsgSystemMapSelected:
case kMsgUserMapSelected:
{
BListView* listView;
BListView* otherListView;
if (message->what == kMsgSystemMapSelected) {
listView = fSystemListView;
otherListView = fUserListView;
} else {
listView = fUserListView;
otherListView = fSystemListView;
}
int32 index = listView->CurrentSelection();
if (index < 0)
break;
// Deselect item in other BListView
otherListView->DeselectAll();
if (index == 0 && listView == fUserListView) {
// we can safely ignore the "(Current)" item
break;
}
//.........这里部分代码省略.........
示例15: vol
void
AutoMounter::UnmountAndEjectVolume(BMessage *_DEVICE_MAP_ONLY(message))
{
#if _INCLUDES_CLASS_DEVICE_MAP
dev_t device;
if (message->FindInt32("device_id", &device) != B_OK)
return;
PRINT(("Unmount device %i\n", device));
AutoLock<BLooper> lock(this);
UnmountDeviceParams params;
params.device = device;
params.result = B_OK;
Partition *partition = fList.EachMountedPartition(UnmountIfMatchingID,
¶ms);
if (!partition) {
PRINT(("Couldn't unmount partition. Rescan and try again\n"));
// could not find partition - must have been mounted by someone
// else
// sync up and try again
// this should really be handled by watching for mount and unmount
// events like the tracker does, not doing that because it is
// a bigger change and we are close to freezing
fList.UnmountDisappearedPartitions();
DeviceScanParams syncRescanParams;
syncRescanParams.checkFloppies = true;
syncRescanParams.checkCDROMs = true;
syncRescanParams.checkOtherRemovable = true;
syncRescanParams.removableOrUnknownOnly = true;
fList.UpdateChangedDevices(&syncRescanParams);
partition = fList.EachMountedPartition(UnmountIfMatchingID, ¶ms);
}
if (!partition) {
PRINT(("Device not in list, unmounting directly\n"));
char path[B_FILE_NAME_LENGTH];
BVolume vol(device);
status_t err = vol.InitCheck();
if (err == B_OK) {
BDirectory mountPoint;
if (err == B_OK)
err = vol.GetRootDirectory(&mountPoint);
BPath mountPointPath;
if (err == B_OK)
err = mountPointPath.SetTo(&mountPoint, ".");
if (err == B_OK)
strcpy(path, mountPointPath.Path());
}
if (err == B_OK) {
PRINT(("unmounting '%s'\n", path));
err = unmount(path);
}
if (err == B_OK) {
PRINT(("deleting '%s'\n", path));
err = rmdir(path);
}
if (err != B_OK) {
PRINT(("error %s\n", strerror(err)));
BString text;
text << "Could not unmount disk";
(new BAlert("", text.String(), "OK", NULL, NULL, B_WIDTH_AS_USUAL,
B_WARNING_ALERT))->Go(0);
}
} else if (params.result != B_OK) {
BString text;
text << "Could not unmount disk " << partition->VolumeName() <<
". An item on the disk is busy.";
(new BAlert("", text.String(), "OK", NULL, NULL, B_WIDTH_AS_USUAL,
B_WARNING_ALERT))->Go(0);
}
#endif
}