本文整理汇总了C++中BString::String方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::String方法的具体用法?C++ BString::String怎么用?C++ BString::String使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::String方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MessageReceived
void ChatWindow::MessageReceived( BMessage* aMessage ) {
switch( aMessage->what ) {
case SHOW_MESSAGE:
{
const char *msg;
aMessage->FindString( "msg", &msg );
time_t _now = time( NULL );
struct tm *now = localtime( &_now );
BString *str = NULL;
BString *str2 = NULL;
char *string = NULL;
Person *person = NULL;
for( int i = 0; i < iWindow->GetProfile()->GetUserlist()->GetList()->CountItems(); i++ ) {
person = ( Person* ) iWindow->GetProfile()->GetUserlist()->GetList()->ItemAt( i );
if( iWho == person->GetUIN() ) {
str = new BString();
str->SetTo( person->GetDisplay() );
break;
}
}
if( !str ) {
str = new BString();
*str << ( int32 ) iWho;
}
BFont *font = new BFont( be_plain_font );
font->SetSize( 16.0 );
font->SetEncoding( B_ISO_8859_2 );
rgb_color yellow = { 255, 255, 0, 0 };
rgb_color red = { 255, 0, 0, 0 };
rgb_color white = { 255, 255, 255, 0 };
string = ( char* ) calloc( strlen( "[00:00] " ), 1 );
sprintf( string, "[%02d:%02d] ", now->tm_hour, now->tm_min);
str2 = new BString();
str2->SetTo( string );
free( string );
iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2->Length(), font, B_FONT_ALL, &yellow );
iChat->Insert( iChat->TextLength(), str2->String(), str2->Length() );
str->Append( ": " );
iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str->Length(), font, B_FONT_ALL, &red );
iChat->Insert( iChat->TextLength(), str->String(), str->Length() );
str2->SetTo( msg );
str2->Append( "\n" );
iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2->Length(), font, B_FONT_ALL, &white );
iChat->Insert( iChat->TextLength(), str2->String(), str2->Length() );
BScrollBar * scrollBar = iScrollView->ScrollBar( B_VERTICAL );
if( scrollBar->LockLooper() ) {
float max,min;
scrollBar->GetRange( &min, &max );
scrollBar->SetValue( max );
scrollBar->UnlockLooper();
}
delete str;
delete str2;
break;
}
case BEGG_SEND:
{
if( iSayControl->LockLooper()) {
if( !(*iSayControl->Text() ) ) {
/* nothing to send */
iSayControl->UnlockLooper();
break;
}
/* first we add message into chat window */
time_t _now = time( NULL );
struct tm * now = localtime( &_now );
BString str;
BString str2;
char *string;
// int id = iNetwork->GetIdent();
BFont *font = new BFont( be_plain_font );
font->SetSize( 16.0 );
font->SetEncoding( B_ISO_8859_2 );
rgb_color yellow = { 255, 255, 0, 0 };
rgb_color green = { 0, 255, 0, 0 };
rgb_color white = { 255, 255, 255, 0 };
string = ( char* ) calloc( strlen( "[00:00] " ), 1 );
sprintf( string, "[%02d:%02d] ", now->tm_hour, now->tm_min );
str2.SetTo( string );
free( string );
iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2.Length(), font, B_FONT_ALL, &yellow );
iChat->Insert( iChat->TextLength(), str2.String(), str2.Length() );
str.SetTo( iWindow->GetProfile()->GetProfileName() );
str.Append( ": " );
iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str.Length(), font, B_FONT_ALL, &green );
iChat->Insert( iChat->TextLength(), str.String(), str.Length() );
str2.SetTo( iSayControl->Text() );
str2.Append( "\n" );
iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2.Length(), font, B_FONT_ALL, &white );
iChat->Insert( iChat->TextLength(), str2.String(), str2.Length() );
/* scroll down */
BScrollBar * scrollBar = iScrollView->ScrollBar( B_VERTICAL );
if( scrollBar->LockLooper() ) {
float max,min;
//.........这里部分代码省略.........
示例2: MessageReceived
void PrefsWindow::MessageReceived(BMessage* message)
{
switch(message->what)
{
case PrefsConstants::K_PREFS_VIEW_RESET_COLOUR_DEFAULTS:
{
ResetToDefaults(PrefsConstants::K_RESET_COLOUR_PREFS);
}
break;
case PrefsConstants::K_PREFS_VIEW_RESET_COMMAND_DEFAULTS:
{
ResetToDefaults(PrefsConstants::K_RESET_COMMAND_PREFS);
}
break;
case PrefsConstants::K_PREFS_VIEW_RESET_TOOLBAR_DEFAULTS:
{
ResetToDefaults(PrefsConstants::K_RESET_TOOLBAR_PREFS);
}
break;
case PrefsConstants::K_PREFS_VIEW_RESET_GENERAL_DEFAULTS:
{
ResetToDefaults(PrefsConstants::K_RESET_GENERAL_PREFS);
}
break;
case PrefsConstants::K_PREFS_UPDATE:
{
//update the preferences message, from view values
BString prefsID;
if (message->FindString(K_PREFS_ID, &prefsID) == B_OK)
{
BView *changedView = m_parent->FindView(prefsID.String());
prefsLock.Lock();
//different view have different kinds of values
if (is_instance_of(changedView, BTextControl))
{
//a textcontrol value was changed, update preferences with new text
BTextControl *textControl = dynamic_cast<BTextControl*>(changedView);
preferences.ReplaceString(prefsID.String(), textControl->Text());
}
else if (is_instance_of(changedView, BCheckBox))
{
//a checkbox value was changed, update preferences with new bool value(on/off)
BCheckBox *checkBox = dynamic_cast<BCheckBox*>(changedView);
preferences.ReplaceBool(prefsID.String(), checkBox->Value());
}
else if (is_instance_of(changedView, BSlider))
{
//a slider value was changed, update preferences with new slider value
BSlider *slider = dynamic_cast<BSlider*>(changedView);
preferences.ReplaceInt32(prefsID.String(), slider->Value());
}
else if (is_instance_of(changedView, ColourButton))
{
//a colourcontrol value was changed, update preferences with new colour
ColourButton *colourControl = dynamic_cast<ColourButton*>(changedView);
preferences.ReplaceData(prefsID.String(),B_RGB_COLOR_TYPE, &colourControl->Value(), sizeof(rgb_color));
}
prefsLock.Unlock();
}
}
break;
case PrefsConstants::K_LOAD_PREFERENCES:
{
//set preferences view values to values of the preferences message
BString prefsID;
if (message->FindString(K_PREFS_ID, &prefsID) == B_OK)
{
//find out which view value has to be updated
BView *changedView = m_parent->FindView(prefsID.String());
prefsLock.Lock();
char *name;
uint32 type;
int32 count;
for (int32 i = 0; preferences.GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i++)
{
//find out what kind of field we are using
switch (type)
{
case B_INT32_TYPE:
{
int32 value;
preferences.FindInt32(name, &value);
if (is_instance_of(changedView, BSlider))
{
BSlider *slider = dynamic_cast<BSlider*>(changedView);
slider->SetValue(value);
}
}
break;
case B_BOOL_TYPE:
{
bool value;
preferences.FindBool(name, &value);
if (is_instance_of(changedView, BCheckBox))
{
BCheckBox *checkBox = dynamic_cast<BCheckBox*>(changedView);
checkBox->SetValue(value);
}
}
break;
//.........这里部分代码省略.........
示例3: data
status_t
DebugReportGenerator::_DumpDebuggedThreadInfo(BFile& _output,
::Thread* thread)
{
AutoLocker< ::Team> locker;
if (thread->State() != THREAD_STATE_STOPPED)
return B_OK;
status_t error;
StackTrace* trace = NULL;
for (;;) {
trace = thread->GetStackTrace();
if (trace != NULL)
break;
locker.Unlock();
fTraceWaitingThread = thread;
do {
error = acquire_sem(fTeamDataSem);
} while (error == B_INTERRUPTED);
if (error != B_OK)
break;
locker.Lock();
}
BString data("\t\tFrame\t\tIP\t\t\tFunction Name\n");
WRITE_AND_CHECK(_output, data);
data = "\t\t-----------------------------------------------\n";
WRITE_AND_CHECK(_output, data);
for (int32 i = 0; StackFrame* frame = trace->FrameAt(i); i++) {
char functionName[512];
BString sourcePath;
target_addr_t ip = frame->InstructionPointer();
FunctionInstance* functionInstance;
Statement* statement;
if (fTeam->GetStatementAtAddress(ip,
functionInstance, statement) == B_OK) {
BReference<Statement> statementReference(statement, true);
int32 line = statement->StartSourceLocation().Line();
LocatableFile* sourceFile = functionInstance->GetFunction()
->SourceFile();
if (sourceFile != NULL) {
sourceFile->GetPath(sourcePath);
sourcePath.SetToFormat("(%s:%" B_PRId32 ")",
sourcePath.String(), line);
}
}
data.SetToFormat("\t\t%#08" B_PRIx64 "\t%#08" B_PRIx64 "\t%s %s\n",
frame->FrameAddress(), ip, UiUtils::FunctionNameForFrame(
frame, functionName, sizeof(functionName)),
sourcePath.String());
WRITE_AND_CHECK(_output, data);
// only dump the topmost frame
if (i == 0) {
locker.Unlock();
error = _DumpFunctionDisassembly(_output, frame->InstructionPointer());
if (error != B_OK)
return error;
error = _DumpStackFrameMemory(_output, thread->GetCpuState(),
frame->FrameAddress(), thread->GetTeam()->GetArchitecture()
->StackGrowthDirection());
if (error != B_OK)
return error;
locker.Lock();
}
if (frame->CountParameters() == 0 && frame->CountLocalVariables() == 0)
continue;
data = "\t\t\tVariables:\n";
WRITE_AND_CHECK(_output, data);
error = fNodeManager->SetStackFrame(thread, frame);
if (error != B_OK)
continue;
ValueNodeContainer* container = fNodeManager->GetContainer();
AutoLocker<ValueNodeContainer> containerLocker(container);
for (int32 i = 0; i < container->CountChildren(); i++) {
data.Truncate(0L);
ValueNodeChild* child = container->ChildAt(i);
containerLocker.Unlock();
_ResolveValueIfNeeded(child->Node(), frame, 1);
containerLocker.Lock();
UiUtils::PrintValueNodeGraph(data, child, 3, 1);
WRITE_AND_CHECK(_output, data);
}
data = "\n";
WRITE_AND_CHECK(_output, data);
}
data = "\n\t\tRegisters:\n";
WRITE_AND_CHECK(_output, data);
//.........这里部分代码省略.........
示例4: BWindow
ChatWindow::ChatWindow( Network *aNetwork, MainWindow *aWindow, uin_t aWho )
: BWindow( CHATWIN_RECT, CHATWIN_NAME,
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE )
{
iNetwork = aNetwork;
iWindow = aWindow;
iWho = aWho;
SetSizeLimits( 300, 2000, 200, 2000 );
/*
we're fixing a title and checking that we have that number in our people list
if true, set to iDisplay
*/
Person *person;
BString title = Title();
BString *pe = NULL;
for( int i = 0; i < iWindow->GetProfile()->GetUserlist()->GetList()->CountItems(); i++ ) {
person = ( Person* ) iWindow->GetProfile()->GetUserlist()->GetList()->ItemAt( i );
if( aWho == person->GetUIN() ) {
pe = new BString( person->GetDisplay() );
break;
}
}
if( !pe ) {
pe = new BString();
pe->SetTo( _T("[Stranger]") );
}
title.Append( pe->String() );
title << " (" << iWho << ")";
SetTitle( title.String());
/* making a default background */
BRect r = Bounds();
BView *someView;
someView = new BView( r, "some view", B_FOLLOW_ALL, B_WILL_DRAW );
someView->SetViewColor( 60, 60, 60 );
AddChild( someView );
/* 'chat' at base of BTextView */
r = someView->Bounds();
r.InsetBy( 10, 10 );
r.right -= B_V_SCROLL_BAR_WIDTH;
r.bottom -= 25;
BRect textRect = BRect( 5, 5, r.Width() - 5, r.Height() - 5 );
iChat = new BTextView( r, "chat view", textRect, B_FOLLOW_ALL, B_WILL_DRAW );
iChat->MakeEditable( false );
iChat->SetStylable( true );
BFont *font = new BFont( be_plain_font );
font->SetSize( 15.0 );
font->SetEncoding( B_ISO_8859_2 );
iChat->SetFontAndColor( font );
iScrollView = new BScrollView( "scroll view", iChat, B_FOLLOW_ALL, 0, false, true );
someView->AddChild( iScrollView );
iChat->SetViewColor( 70, 70, 70 );
/* new message edit box */
r = someView->Bounds();
r.InsetBy( 10, 10 );
r.top = r.bottom - 15;
iSayControl = new BTextControl( r, "say control", "", NULL, new BMessage( BEGG_SEND ), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM );
iSayControl->MakeFocus( true );
float width, height;
iSayControl->GetPreferredSize( &width, &height );
iSayControl->SetDivider( width / 2 );
iSayControl->SetFont( font );
someView->AddChild( iSayControl );
}
示例5: message
//.........这里部分代码省略.........
_SetOutputFolder(inEntry);
fOutputDirSpecified = true;
break;
case OPEN_FILE_MESSAGE:
// Execute Open Panel
if (!fOpenFilePanel) {
fOpenFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
B_FILE_NODE, true, NULL, NULL, false, true);
fOpenFilePanel->SetTarget(this);
}
fOpenFilePanel->Show();
break;
case B_REFS_RECEIVED:
// Media Files Seleced by Open Panel
DetachCurrentMessage();
msg->what = B_REFS_RECEIVED;
BMessenger(be_app).SendMessage(msg);
// fall through
case B_CANCEL:
break;
case QUIT_MESSAGE:
MediaConverterWindow::QuitRequested();
break;
case PREVIEW_MESSAGE:
{
// Build the command line to launch the preview application.
// TODO: Launch the default app instead of hardcoded MediaPlayer!
int32 srcIndex = fListView->CurrentSelection();
BMediaFile* inFile = NULL;
status_t status = GetSourceFileAt(srcIndex, &inFile, &inRef);
const char* argv[3];
BString startPosString;
BPath path;
if (status == B_OK) {
argv[0] = "-pos";
// NOTE: -pos argument is currently not supported by Haiku
// MediaPlayer.
startPosString << fStartDurationTC->Text();
startPosString << "000";
argv[1] = startPosString.String();
status = inEntry.SetTo(&inRef);
}
if (status == B_OK) {
status = inEntry.GetPath(&path);
if (status == B_OK)
argv[2] = path.Path();
}
if (status == B_OK) {
status = be_roster->Launch(
"application/x-vnd.Haiku-MediaPlayer",
3, (char**)argv, NULL);
}
if (status != B_OK && status != B_ALREADY_RUNNING) {
BString errorString(B_TRANSLATE("Error launching: %strError%"));
errorString.ReplaceFirst("%strError%", strerror(status));
BAlert* alert = new BAlert(B_TRANSLATE("Error"),
errorString.String(), B_TRANSLATE("OK"));
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go();
}
break;
}
case VIDEO_QUALITY_CHANGED_MESSAGE:
{
int32 value;
msg->FindInt32("be:value", &value);
snprintf(buffer, sizeof(buffer),
B_TRANSLATE("Video quality: %3d%%"), (int8)value);
fVideoQualitySlider->SetLabel(buffer);
fVideoQuality = value;
break;
}
case AUDIO_QUALITY_CHANGED_MESSAGE:
{
int32 value;
msg->FindInt32("be:value", &value);
snprintf(buffer, sizeof(buffer),
B_TRANSLATE("Audio quality: %3d%%"), (int8)value);
fAudioQualitySlider->SetLabel(buffer);
fAudioQuality = value;
break;
}
default:
BWindow::MessageReceived(msg);
}
}
示例6: AddToList
// PickJoystick
// Present a list of all game controllers and let the user choose the one to
// use. This will configure the "stick" object for that controller.
void
StickItWindow::PickJoystick(BJoystick *stick)
{
int32 numDevices = stick->CountDevices();
BString temp1("BJoystick::CountDevices()");
temp1 << ", Num = " << numDevices;
temp1 = AddToList(fListView1, temp1.String());
status_t err = B_ERROR;
if (numDevices) {
temp1 << "There are " << numDevices
<< " Joysticks device types available";
temp1 = AddToList(fListView1, temp1.String());
for (int32 i = 0; i < numDevices; i++) {
char devName[B_OS_NAME_LENGTH];
err = stick->GetDeviceName(i, devName);
temp1 << "BJoystick::GetDeviceName(), id = " << i << ", name = "
<< devName;
temp1 = AddToList(fListView1, temp1.String());
if (err == B_OK) {
err = stick->Open(devName);
temp1 = AddToList(fListView1, "BJoystick::Open()");
int32 count = stick->CountSticks();
temp1 << "BJoystick::CountSticks(), number of sticks = "
<< count;
temp1 = AddToList(fListView1, temp1.String());
count = stick->CountAxes();
temp1 << "BJoystick::CountAxes(), number of Axes = "
<< count;
temp1 = AddToList(fListView1, temp1.String());
count = stick->CountButtons();
temp1 << "BJoystick::CountButtons(), number of Buttons = "
<< count;
temp1 = AddToList(fListView1, temp1.String());
count = stick->CountHats();
temp1 << "BJoystick::CountHats(), number of Hats = "
<< count;
temp1 = AddToList(fListView1, temp1.String());
count = stick->CountDevices();
temp1 << "BJoystick::CountDevices(), number of Devices = "
<< count;
temp1 = AddToList(fListView1, temp1.String());
if (err != B_ERROR) {
BString name;
err = stick->GetControllerModule(&name);
temp1 << "BJoystick::GetControllerModule(), name = "
<< name;
temp1 = AddToList(fListView1, temp1.String());
if (name == "Legacy") {
bool b = stick->EnterEnhancedMode();
if (b) {
temp1 << "BJoystick::EnterEnhancedMode(), OK";
temp1 = AddToList(fListView1, temp1.String());
} else {
temp1 << "BJoystick::EnterEnhancedMode(), Not OK";
temp1 = AddToList(fListView1, temp1.String());
}
}
err = stick->GetControllerName(&name);
temp1 << "BJoystick::GetControllerName(), name = " << name;
temp1 = AddToList(fListView1, temp1.String());
if (err == B_OK) {
stick->Close();
temp1 = AddToList(fListView1, "BJoystick::Close()");
temp1 << i+1 << " " << name.String();
temp1 = AddToList(fListView2, temp1.String());
} else {
temp1 << "Error = " << strerror(err);
temp1 = AddToList(fListView1, temp1.String());
temp1 << "*** Can't get name of controller "
<< devName;
temp1 = AddToList(fListView1, temp1.String());
}
} else {
temp1 << "Error = " << strerror(err) << "err nr = " << err;
temp1 = AddToList(fListView1, temp1.String());
temp1 << "No controller on " << devName;
temp1 = AddToList(fListView1, temp1.String());
}
} else {
temp1 << "Error = " << strerror(err);
temp1 = AddToList(fListView1, temp1.String());
temp1 << "*** Error while reading controller list.";
temp1 = AddToList(fListView1, temp1.String());
}
}
} else {
temp1 << "Error = " << strerror(err);
temp1 = AddToList(fListView1, temp1.String());
temp1 = AddToList(fListView1, "*** No game ports detected.");
}
//.........这里部分代码省略.........
示例7: CopyDirectory
void GenesisCopyWindow::CopyDirectory(const char *dirname, const char *destination, const char *destdirname)
////////////////////////////////////////////////////////////////////////
{
BEntry srcentry(dirname);
BEntry dstentry;
char name[B_FILE_NAME_LENGTH];
BString fulldestdir;
if (srcentry.InitCheck()!=B_OK)
return;
if (!srcentry.Exists())
return;
srcentry.GetName(name);
fulldestdir.SetTo(destination);
if (destdirname)
fulldestdir << "/" << destdirname;
else
fulldestdir << "/" << name;
dstentry.SetTo(fulldestdir.String());
if (dstentry.InitCheck()!=B_OK)
return;
if (!dstentry.Exists())
{
if (create_directory(fulldestdir.String(), 0777)!=B_OK) // TODO: jo a 0777?
return;
}
BDirectory dir;
dir.SetTo(dirname);
if (dir.InitCheck()==B_OK)
{
BEntry entry;
if (dir.GetEntry(&entry)==B_OK)
{
while (dir.GetNextEntry(&entry)==B_OK)
{
entry.GetName(name);
if (entry.IsDirectory())
{
BString fullname;
fullname.SetTo(dirname);
fullname << "/" << name;
CopyDirectory(fullname.String(), fulldestdir.String());
}
else if (entry.IsSymLink())
{
BString fullname;
fullname.SetTo(dirname);
fullname << "/" << name;
CopyLink(fullname.String(), fulldestdir.String());
}
else
{
BString fullname;
fullname.SetTo(dirname);
fullname << "/" << name;
CopyFile(fullname.String(), fulldestdir.String());
}
}
}
}
// Copy attributes...
CopyAttr(dirname, fulldestdir.String());
}
示例8: CopyLink
bool GenesisCopyWindow::CopyLink(const char *linkname, const char *destination, const char *destfilename)
////////////////////////////////////////////////////////////////////////
{
BSymLink srclink;
BSymLink dstlink;
BDirectory dstdir;
BEntry srcentry;
BEntry symlinkentry;
BPath LinkPath;
char name[B_FILE_NAME_LENGTH];
struct stat statbuf;
entry_ref ref;
srcentry.SetTo(linkname);
srcentry.GetName(name);
srcentry.GetRef(&ref);
symlinkentry.SetTo(&ref, true);
symlinkentry.GetPath(&LinkPath);
if (destfilename)
sprintf(name,"%s",destfilename);
if (srcentry.GetStat(&statbuf)!=B_OK)
return false;
dstdir.SetTo(destination);
if (dstdir.InitCheck()!=B_OK)
return false;
Lock();
m_FileBar->Update(-m_FileBar->CurrentValue()); // Reset to 0.0
m_FileBar->SetMaxValue(1);
m_FileBar->SetTrailingText(name);
Unlock();
if (dstdir.CreateSymLink(name, LinkPath.Path(), &dstlink)!=B_OK && !m_SkipSymLinkCreationError)
{
BString text;
text << "Cannot create '" << name << "' symbolic link in '" << LinkPath.Path() << "'";
BAlert *myAlert = new BAlert("Copy",text.String(),"Abort","Skip all","Skip",B_WIDTH_AS_USUAL,B_OFFSET_SPACING,B_WARNING_ALERT);
myAlert->SetShortcut(0, B_ESCAPE);
switch (myAlert->Go())
{
case 0:
Close();
kill_thread(m_CopyThread);
break;
case 1:
m_SkipSymLinkCreationError = true;
break;
}
return false;
}
Lock();
m_FileBar->Update(1);
Unlock();
dstlink.SetPermissions(statbuf.st_mode);
dstlink.SetOwner(statbuf.st_uid);
dstlink.SetGroup(statbuf.st_gid);
dstlink.SetModificationTime(statbuf.st_mtime);
dstlink.SetCreationTime(statbuf.st_crtime);
// Copy attributes...
BString destlinkname;
destlinkname.SetTo("");
destlinkname << destination << "/" << name;
CopyAttr(linkname, destlinkname.String());
return true;
}
示例9: CopyFile
bool GenesisCopyWindow::CopyFile(const char *filename, const char *destination, const char *destfilename)
////////////////////////////////////////////////////////////////////////
{
char name[B_FILE_NAME_LENGTH];
BString destname;
BEntry srcentry(filename);
BEntry dstentry(destination);
struct stat statbuf;
ssize_t len;
srcentry.GetName(name);
destname.SetTo(destination);
destname += "/";
if (destfilename)
destname += destfilename;
else
destname += name;
BEntry dstfileentry(destname.String());
if (dstfileentry.InitCheck()!=B_OK)
return false;
if (dstfileentry.Exists() && !m_OverwriteAll)
{
BString text;
text << "File '" << name << "' already exists. Do you want to overwrite it?";
BAlert *myAlert = new BAlert("Copy",text.String(),"Abort","Overwrite all","Overwrite",B_WIDTH_AS_USUAL,B_OFFSET_SPACING,B_WARNING_ALERT);
myAlert->SetShortcut(0, B_ESCAPE);
switch (myAlert->Go())
{
case 0:
Close();
kill_thread(m_CopyThread);
break;
case 1:
m_OverwriteAll = true;
break;
}
}
BFile srcfile(filename, B_READ_ONLY);
BFile dstfile(destname.String(), B_WRITE_ONLY | B_CREATE_FILE);
if (srcentry.InitCheck()!=B_OK)
return false;
if (dstentry.InitCheck()!=B_OK)
return false;
if (!srcentry.Exists())
return false;
if (!dstentry.Exists())
{
return false;
}
if (srcentry.GetStat(&statbuf)!=B_OK)
{
return false;
}
unsigned char *buf = new unsigned char[statbuf.st_blksize];
if (!buf)
{
return false;
}
Lock();
m_FileBar->Update(-m_FileBar->CurrentValue()); // Reset to 0.0
m_FileBar->SetMaxValue(statbuf.st_size);
m_FileBar->SetTrailingText(name);
Unlock();
while (true)
{
len = srcfile.Read(buf, statbuf.st_blksize);
if (len>0)
{
dstfile.Write(buf, len);
Lock();
m_FileBar->Update(len);
Unlock();
}
else if (len<0) // error
{
delete [] buf;
return false;
}
else // No more bytes to copy, we are done...
break;
}
dstfile.SetPermissions(statbuf.st_mode);
dstfile.SetOwner(statbuf.st_uid);
dstfile.SetGroup(statbuf.st_gid);
dstfile.SetModificationTime(statbuf.st_mtime);
dstfile.SetCreationTime(statbuf.st_crtime);
//.........这里部分代码省略.........
示例10: GetFirstSelection
GenesisCopyWindow::GenesisCopyWindow(CustomListView *list, PanelView *destpanel, const char *destination, BLooper* looper, BWindow *mainwindow) :
BWindow(BRect(0,0,320,140), "Copy...", B_TITLED_WINDOW , B_WILL_DRAW)
////////////////////////////////////////////////////////////////////////
{
BRect rect;
m_CustomListView = list;
m_DestPanel = destpanel;
m_DestPath.SetTo(destination);
m_Looper = looper;
m_Window = mainwindow;
m_SingleCopy = false;
m_Paused = false;
m_SkipAllCopyError = false;
m_OverwriteAll = false;
m_SkipSymLinkCreationError = false;
// After the delete process we have to select an item if no item selected...
m_Selection = GetFirstSelection();
// First we have to remove the parent selection if selected...
// RemoveParentSelection();
m_FileCount = m_CustomListView->CountSelectedEntries(CT_WITHOUTPARENT);
if (m_FileCount == 1)
m_SingleCopy = true;
SetType(B_FLOATING_WINDOW);
SetFeel(B_MODAL_SUBSET_WINDOW_FEEL);
SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_CLOSABLE);
AddToSubset(mainwindow);
m_View = new BView(Bounds(), "copyview", B_FOLLOW_ALL, B_WILL_DRAW);
m_View->SetViewColor(216, 216, 216, 0);
AddChild(m_View);
// Bottom View
rect = Bounds();
rect.top = rect.bottom-44;
BView *BottomView = new BView(rect, "infobottomview", B_FOLLOW_BOTTOM, B_WILL_DRAW);
BottomView->SetViewColor(180, 190, 200, 0);
m_View->AddChild(BottomView);
/*
// More checkbox
rect = BottomView->Bounds();
rect.top = rect.bottom-30;
rect.bottom = rect.bottom-14;
rect.left = 20;
rect.right = rect.left+40;
m_MoreCB = new BCheckBox(rect,"more","Show more",new BMessage(COPY_MORE), B_FOLLOW_BOTTOM, B_WILL_DRAW);
m_MoreCB->ResizeToPreferred();
BottomView->AddChild(m_MoreCB);
*/
// OK Button
rect = BottomView->Bounds();
rect.top = rect.bottom-34;
rect.bottom = rect.bottom-14;
rect.left = rect.right-80;
rect.right = rect.right-20;
m_CopyButton = new BButton(rect,"copy","Copy",new BMessage(BUTTON_MSG_COPY),B_FOLLOW_BOTTOM,B_WILL_DRAW);
BottomView->AddChild(m_CopyButton);
//Cancel Button
rect = BottomView->Bounds();
rect.top = rect.bottom-34;
rect.bottom = rect.bottom-14;
rect.left = rect.right-160;
rect.right = rect.right-100;
m_CancelButton = new BButton(rect,"cancel","Cancel",new BMessage(BUTTON_MSG_CANCELCOPY),B_FOLLOW_BOTTOM,B_WILL_DRAW);
BottomView->AddChild(m_CancelButton);
SetDefaultButton(m_CopyButton);
// Info string
rect = Bounds();
rect.left += 24;
rect.right -= 24;
if (m_SingleCopy)
rect.top += 8;
else
rect.top += 16;
rect.bottom = rect.top+20;
m_Label = new BStringView(rect,"filename","Copy");
m_Label->SetAlignment(B_ALIGN_CENTER);
m_Label->SetViewColor(216,216,216);
m_Label->SetLowColor(216,216,216);
m_Label->SetHighColor(0,0,0);
AddChild(m_Label);
// Edit field
rect = BottomView->Bounds();
if (m_SingleCopy)
rect.top = rect.top+36;
else
rect.top = rect.top+56;
rect.bottom = rect.top+32;
rect.left += 20;
//.........这里部分代码省略.........
示例11: SetTo
//------------------------------------------------------------------------------
void BSliderEditor::SetTo(BMessage* archive)
{
BControlEditor::SetTo(archive);
Init();
BString Label;
archive->FindString("_minlbl", &Label);
fMinLabel->SetText(Label.String());
Label = "";
archive->FindString("_maxlbl", &Label);
fMinLabel->SetText(Label.String());
thumb_style style = B_BLOCK_THUMB;
if (archive->FindInt16("_sstyle", (int16*)&style))
{
DEBUG_ARCHIVE("_sstyle");
}
SetThumbStyle(style);
int32 orient = B_HORIZONTAL;
if (archive->FindInt32("_orient", &orient))
{
DEBUG_ARCHIVE("_orient");
}
SetOrientation(orient);
fOrientation->Menu()->ItemAt(orient)->SetMarked(true);
int16 hashmarks = B_HASH_MARKS_NONE;
if (archive->FindInt16("_hashloc", &hashmarks))
{
DEBUG_ARCHIVE("_hashloc");
}
SetHashLabel(hashmarks);
int32 hashcount = 0;
if (archive->FindInt32("_hashcount", &hashcount))
{
DEBUG_ARCHIVE("_hashcount");
}
fHashCount->SetText((BString() << hashcount).String());
int32 min = 0;
if (archive->FindInt32("_min", &min))
{
DEBUG_ARCHIVE("_min");
}
fMinValue->SetText((BString() << min).String());
int32 max = 0;
if (archive->FindInt32("_max", &max))
{
DEBUG_ARCHIVE("_max");
}
fMaxValue->SetText((BString() << max).String());
BMessage modmsg;
if (archive->FindMessage("_mod_msg", &modmsg) == B_OK)
{
// TODO: expand
// This is a very simple way to handle messages; it might be nice to
// have a BMessage editor which would allow for more complex control
// message definitions.
char msg[5];
msg[0] = 0;
strncpy(msg, (char *)(new int32(flipcode(modmsg.what))), 4);
msg[4] = 0;
fModMsg->SetText(msg);
}
else
{
fModMsg->SetText("");
}
int32 increment = 1;
if (archive->FindInt32("_incrementvalue", &increment))
{
DEBUG_ARCHIVE("_incrementvalue");
}
fIncrValue->SetText((BString() << increment).String());
rgb_color barcolor;
if (archive->FindInt32("_bcolor", (int32*)&barcolor))
{
DEBUG_ARCHIVE("_bcolor");
}
else
{
char colortext[12];
sprintf(colortext, "%lX", *(int32*)&barcolor);
fBarColor->SetText(colortext);
}
rgb_color fillcolor;
if (archive->FindInt32("_fcolor", (int32*)&barcolor))
{
fUseFillCheck->SetValue(B_CONTROL_OFF);
fFillColor->SetEnabled(false);
}
//.........这里部分代码省略.........
示例12: if
status_t
WidgetAttributeText::AttrAsString(const Model *model, BString *result,
const char *attrName, int32 attrType,
float width, BView *view, int64 *resultingValue)
{
int64 value;
status_t error = model->InitCheck();
if (error != B_OK)
return error;
switch (attrType) {
case B_TIME_TYPE:
if (strcmp(attrName, kAttrStatModified) == 0)
value = model->StatBuf()->st_mtime;
else if (strcmp(attrName, kAttrStatCreated) == 0)
value = model->StatBuf()->st_crtime;
else {
TRESPASS();
// not yet supported
return B_ERROR;
}
TruncTimeBase(result, value, view, width);
if (resultingValue)
*resultingValue = value;
return B_OK;
case B_STRING_TYPE:
if (strcmp(attrName, kAttrPath) == 0) {
BEntry entry(model->EntryRef());
BPath path;
BString tmp;
if (entry.InitCheck() == B_OK && entry.GetPath(&path) == B_OK) {
tmp = path.Path();
TruncateLeaf(&tmp);
} else
tmp = "-";
if (width > 0) {
TruncStringBase(result, tmp.String(), tmp.Length(), view,
width);
} else
*result = tmp.String();
return B_OK;
}
break;
case kSizeType:
// TruncFileSizeBase(result, model->StatBuf()->st_size, view, width);
return B_OK;
break;
default:
TRESPASS();
// not yet supported
return B_ERROR;
}
TRESPASS();
return B_ERROR;
}
示例13: keymap
/*! Save a keymap as C source file - this is used to get the default keymap
into the input_server, for example.
\a mapName is usually the path of the input keymap, and is used as the
name of the keymap (the path will be removed, as well as its suffix).
*/
status_t
Keymap::SaveAsCppHeader(const char* fileName, const char* mapName)
{
BString name = mapName;
// cut off path
int32 index = name.FindLast('/');
if (index > 0)
name.Remove(0, index + 1);
// prune ".keymap"
index = name.FindLast('.');
if (index > 0)
name.Truncate(index);
FILE* file = fopen(fileName, "w");
if (file == NULL)
return errno;
fputs("/*\n"
" * Haiku Default System Keymap\n"
" * This file is automatically generated. Do not edit!\n"
" */\n", file);
fputs("#ifndef\t_SYSTEM_KEYMAP_H\n"
"#define\t_SYSTEM_KEYMAP_H\n\n\n", file);
fputs("#include <InterfaceDefs.h>\n\n\n", file);
fputs("#ifdef __cplusplus\n"
"extern \"C\" {\n"
"#endif\n\n", file);
fprintf(file, "const char *kSystemKeymapName = \"%s\";\n\n", name.String());
fputs("const key_map kSystemKeymap = {\n", file);
// version, default lock settings, modifier keys
fprintf(file, "\tversion:%" B_PRIu32 ",\n", fKeys.version);
fprintf(file, "\tcaps_key:0x%" B_PRIx32 ",\n", fKeys.caps_key);
fprintf(file, "\tscroll_key:0x%" B_PRIx32 ",\n", fKeys.scroll_key);
fprintf(file, "\tnum_key:0x%" B_PRIx32 ",\n", fKeys.num_key);
fprintf(file, "\tleft_shift_key:0x%" B_PRIx32 ",\n", fKeys.left_shift_key);
fprintf(file, "\tright_shift_key:0x%" B_PRIx32 ",\n",
fKeys.right_shift_key);
fprintf(file, "\tleft_command_key:0x%" B_PRIx32 ",\n",
fKeys.left_command_key);
fprintf(file, "\tright_command_key:0x%" B_PRIx32 ",\n",
fKeys.right_command_key);
fprintf(file, "\tleft_control_key:0x%" B_PRIx32 ",\n",
fKeys.left_control_key);
fprintf(file, "\tright_control_key:0x%" B_PRIx32 ",\n",
fKeys.right_control_key);
fprintf(file, "\tleft_option_key:0x%" B_PRIx32 ",\n",
fKeys.left_option_key);
fprintf(file, "\tright_option_key:0x%" B_PRIx32 ",\n",
fKeys.right_option_key);
fprintf(file, "\tmenu_key:0x%" B_PRIx32 ",\n", fKeys.menu_key);
fprintf(file, "\tlock_settings:0x%" B_PRIx32 ",\n", fKeys.lock_settings);
// maps
dump_map(file, "control_map", fKeys.control_map);
dump_map(file, "option_caps_shift_map", fKeys.option_caps_shift_map);
dump_map(file, "option_caps_map", fKeys.option_caps_map);
dump_map(file, "option_shift_map", fKeys.option_shift_map);
dump_map(file, "option_map", fKeys.option_map);
dump_map(file, "caps_shift_map", fKeys.caps_shift_map);
dump_map(file, "caps_map", fKeys.caps_map);
dump_map(file, "shift_map", fKeys.shift_map);
dump_map(file, "normal_map", fKeys.normal_map);
// dead keys
dump_keys(file, "acute_dead_key", fKeys.acute_dead_key);
dump_keys(file, "grave_dead_key", fKeys.grave_dead_key);
dump_keys(file, "circumflex_dead_key", fKeys.circumflex_dead_key);
dump_keys(file, "dieresis_dead_key", fKeys.dieresis_dead_key);
dump_keys(file, "tilde_dead_key", fKeys.tilde_dead_key);
// dead key tables
fprintf(file, "\tacute_tables:0x%" B_PRIx32 ",\n", fKeys.acute_tables);
fprintf(file, "\tgrave_tables:0x%" B_PRIx32 ",\n", fKeys.grave_tables);
fprintf(file, "\tcircumflex_tables:0x%" B_PRIx32 ",\n",
fKeys.circumflex_tables);
fprintf(file, "\tdieresis_tables:0x%" B_PRIx32 ",\n",
fKeys.dieresis_tables);
fprintf(file, "\ttilde_tables:0x%" B_PRIx32 ",\n", fKeys.tilde_tables);
fputs("};\n\n", file);
fputs("const uchar kSystemKeyChars[] = {\n", file);
for (uint32 i = 0; i < fCharsSize; i++) {
if (i % 10 == 0) {
if (i > 0)
fputs("\n", file);
fputs("\t", file);
} else
fputs(" ", file);
fprintf(file, "0x%02x,", (uint8)fChars[i]);
//.........这里部分代码省略.........