コード例 #1
0
ファイル: Directory.cpp プロジェクト: Ithamar/cosmoe
/*! \brief Re-initializes the BDirectory to the directory referred to by the
	supplied BEntry.
	\param entry the BEntry referring to the directory
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: \c NULL \a entry.
	- \c B_ENTRY_NOT_FOUND: Directory not found.
	- \c B_PERMISSION_DENIED: Directory permissions didn't allow operation.
	- \c B_NO_MEMORY: Insufficient memory for operation.
	- \c B_LINK_LIMIT: Indicates a cyclic loop within the file system.
	- \c B_BUSY: A node was busy.
	- \c B_FILE_ERROR: A general file error.
	- \c B_NO_MORE_FDS: The application has run out of file descriptors.
	\todo Implemented using SetTo(entry_ref*). Check, if necessary to
		  reimplement!
*/
status_t
BDirectory::SetTo(const BEntry *entry)
{
	if (!entry) {
		Unset();
		return (fCStatus = B_BAD_VALUE);
	}
	// open node
	entry_ref ref;
	status_t error = (entry ? B_OK : B_BAD_VALUE);
	if (error == B_OK && entry->InitCheck() != B_OK)
		error = B_BAD_VALUE;
	if (error == B_OK)
		error = entry->GetRef(&ref);
	if (error == B_OK)
		error = SetTo(&ref);
	set_status(error);
	return error;
}
コード例 #2
0
ファイル: TypeEditors.cpp プロジェクト: DonCN/haiku
void
MessageView::_UpdateMessage()
{
	BAutolock locker(fEditor);

	size_t viewSize = fEditor.ViewSize();
	// that may need some more memory...
	if ((off_t)viewSize < fEditor.FileSize())
		fEditor.SetViewSize(fEditor.FileSize());

	const char *buffer;
	if (fEditor.GetViewBuffer((const uint8 **)&buffer) == B_OK) {
		BMessage message;
		message.Unflatten(buffer);
		SetTo(message);
	}

	// restore old view size
	fEditor.SetViewSize(viewSize);
}
コード例 #3
0
void nsRegionPh :: Intersect( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight ) 
{
	if( aWidth > 0 && aHeight > 0 ) {
		/* Create a temporary tile to  assign to mRegion */
		PhTile_t tile;
		tile.rect.ul.x = aX;
		tile.rect.ul.y = aY;
		tile.rect.lr.x = (aX+aWidth-1);
		tile.rect.lr.y = (aY+aHeight-1);
		tile.next = NULL;
    
		PhTile_t *original = mRegion;
		mRegion = PhIntersectTilings( mRegion, &tile, NULL );
		PhFreeTiles( original );
		if ( mRegion == NULL )
			SetTo(0, 0, 1, 1);
	}
	else 
		SetRegionEmpty();
}
コード例 #4
0
ファイル: imap_config.cpp プロジェクト: mmanley/Antares
IMAPConfig::IMAPConfig(BMessage *archive)
	: BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME
		| B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME
		| B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
#ifdef USE_SSL
	 	| B_MAIL_PROTOCOL_HAS_FLAVORS
#endif
	 )
{
#ifdef USE_SSL
		AddFlavor("No encryption");
		AddFlavor("SSL");
#endif

	SetTo(archive);

	((BControl *)(FindView("leave_mail_remote")))->SetValue(B_CONTROL_ON);
	((BControl *)(FindView("leave_mail_remote")))->Hide();

	BRect frame = FindView("delete_remote_when_local")->Frame();

	((BControl *)(FindView("delete_remote_when_local")))->SetEnabled(true);
	((BControl *)(FindView("delete_remote_when_local")))->MoveBy(0,-25);


	frame.right -= 10;// FindView("pass")->Frame().right;
	/*frame.top += 10;
	frame.bottom += 10;*/

	BTextControl *folder = new BTextControl(frame,"root","Top mailbox folder: ","",NULL);
	folder->SetDivider(be_plain_font->StringWidth("Top mailbox folder: "));

	if (archive->HasString("root"))
		folder->SetText(archive->FindString("root"));

	AddChild(folder);

	ResizeToPreferred();
}
コード例 #5
0
ファイル: DString.cpp プロジェクト: histat/dc-nx
void DString::ReplaceString(const char *oldstring, const char *newstring)
{	
	char *str = String();
	char *hit = strstr(str, oldstring);
	if (!hit) return;	// avoid strlens in common case of no hits

	int oldlen = strlen(oldstring);
	int newlen = strlen(newstring);
	
	for(;;)
	{
		DString temp(str, (hit - str));
		temp.AppendString(newstring);
		temp.AppendString(hit + oldlen);
		
		SetTo(temp.String());
		
		int index = (hit - str) + newlen;
		str = String() + index;

		hit = strstr(str, oldstring);
		if (!hit) break;
	}
}
コード例 #6
0
//!	Load a map from a file
status_t
Keymap::Load(const entry_ref& ref)
{
	BEntry entry;
	status_t status = entry.SetTo(&ref, true);
	if (status != B_OK)
		return status;

	BFile file(&entry, B_READ_ONLY);
	status = SetTo(file);
	if (status != B_OK)
		return status;

	// fetch name from attribute and fall back to filename

	ssize_t bytesRead = file.ReadAttr("keymap:name", B_STRING_TYPE, 0, fName,
		sizeof(fName));
	if (bytesRead > 0)
		fName[bytesRead] = '\0';
	else
		strlcpy(fName, ref.name, sizeof(fName));

	return B_OK;
}
コード例 #7
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
BNetworkAddress::BNetworkAddress(const in6_addr& address, uint16 port)
{
	SetTo(address, port);
}
コード例 #8
0
ファイル: nsAttrValue.cpp プロジェクト: Egyptghost1/DOMinator
void
nsAttrValue::ParseAtomArray(const nsAString& aValue)
{
  nsAString::const_iterator iter, end;
  aValue.BeginReading(iter);
  aValue.EndReading(end);
  PRBool hasSpace = PR_FALSE;
  
  // skip initial whitespace
  while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
    hasSpace = PR_TRUE;
    ++iter;
  }

  if (iter == end) {
    SetTo(aValue);
    return;
  }

  nsAString::const_iterator start(iter);

  // get first - and often only - atom
  do {
    ++iter;
  } while (iter != end && !nsContentUtils::IsHTMLWhitespace(*iter));

  nsCOMPtr<nsIAtom> classAtom = do_GetAtom(Substring(start, iter));
  if (!classAtom) {
    Reset();
    return;
  }

  // skip whitespace
  while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
    hasSpace = PR_TRUE;
    ++iter;
  }

  if (iter == end && !hasSpace) {
    // we only found one classname and there was no whitespace so
    // don't bother storing a list
    ResetIfSet();
    nsIAtom* atom = nsnull;
    classAtom.swap(atom);
    SetPtrValueAndType(atom, eAtomBase);
    return;
  }

  if (!EnsureEmptyAtomArray()) {
    return;
  }

  AtomArray* array = GetAtomArrayValue();
  
  if (!array->AppendElement(classAtom)) {
    Reset();
    return;
  }

  // parse the rest of the classnames
  while (iter != end) {
    start = iter;

    do {
      ++iter;
    } while (iter != end && !nsContentUtils::IsHTMLWhitespace(*iter));

    classAtom = do_GetAtom(Substring(start, iter));

    if (!array->AppendElement(classAtom)) {
      Reset();
      return;
    }

    // skip whitespace
    while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
      ++iter;
    }
  }

  SetMiscAtomOrString(&aValue);
  return;
}
コード例 #9
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
BNetworkAddress::BNetworkAddress(in_addr_t address, uint16 port)
{
	SetTo(address, port);
}
コード例 #10
0
ファイル: EasyPath.cpp プロジェクト: HaikuArchives/LibWalter
EasyPath::EasyPath(const entry_ref &ref)
{
	SetTo(ref);
}
コード例 #11
0
ファイル: nsAttrValue.cpp プロジェクト: ehsan/mozilla-history
nsAttrValue::nsAttrValue(const nsIntMargin& aValue)
    : mBits(0)
{
  SetTo(aValue);
}
コード例 #12
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
BNetworkAddress::BNetworkAddress(int family, const char* host, uint16 port,
	uint32 flags)
{
	fStatus = SetTo(family, host, port, flags);
}
コード例 #13
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
BNetworkAddress::BNetworkAddress(const sockaddr_storage& address)
{
	SetTo(address);
}
コード例 #14
0
ファイル: Region.cpp プロジェクト: danilaslau/frotznet
Region& Region::operator=(const Region &copyRegion)
{
	return SetTo(copyRegion);
}
コード例 #15
0
void
TFilePanel::MessageReceived(BMessage* message)
{
	entry_ref ref;

	switch (message->what) {
		case B_REFS_RECEIVED:
			// item was double clicked in file panel (PoseView)
			if (message->FindRef("refs", &ref) == B_OK) {
				BEntry entry(&ref, true);
				if (entry.InitCheck() == B_OK) {
					// Double-click on dir or link-to-dir ALWAYS opens the
					// dir. If more than one dir is selected, the first is
					// entered.
					if (entry.IsDirectory()) {
						entry.GetRef(&ref);
						bool isDesktop = SwitchDirToDesktopIfNeeded(ref);

						PoseView()->SetIsDesktop(isDesktop);
						entry.SetTo(&ref);
						PoseView()->SwitchDir(&ref);
						SwitchDirMenuTo(&ref);
					} else {
						// Otherwise, we have a file or a link to a file.
						// AdjustButton has already tested the flavor;
						// all we have to do is see if the button is enabled.
						BButton* button = dynamic_cast<BButton*>(
							FindView("default button"));
						if (button == NULL)
							break;

						if (IsSavePanel()) {
							int32 count = 0;
							type_code type;
							message->GetInfo("refs", &type, &count);

							// Don't allow saves of multiple files
							if (count > 1) {
								ShowCenteredAlert(
									B_TRANSLATE(
										"Sorry, saving more than one "
										"item is not allowed."),
									B_TRANSLATE("Cancel"));
							} else {
								// if we are a savepanel, set up the
								// filepanel correctly then pass control
								// so we follow the same path as if the user
								// clicked the save button

								// set the 'name' fld to the current ref's
								// name notify the panel that the default
								// button should be enabled
								SetSaveText(ref.name);
								SelectionChanged();

								HandleSaveButton();
							}
							break;
						}

					  	// send handler a message and close
						BMessage openMessage(*fMessage);
						for (int32 index = 0; ; index++) {
					  		if (message->FindRef("refs", index, &ref) != B_OK)
								break;
							openMessage.AddRef("refs", &ref);
					  	}
						OpenSelectionCommon(&openMessage);
					}
				}
			}
			break;

		case kSwitchDirectory:
		{
			entry_ref ref;
			// this comes from dir menu or nav menu, so switch directories
			if (message->FindRef("refs", &ref) == B_OK) {
				BEntry entry(&ref, true);
				if (entry.GetRef(&ref) == B_OK)
					SetTo(&ref);
			}
			break;
		}

		case kSwitchToHome:
		{
			BPath homePath;
			entry_ref ref;
			if (find_directory(B_USER_DIRECTORY, &homePath) != B_OK
				|| get_ref_for_path(homePath.Path(), &ref) != B_OK) {
				break;
			}

			SetTo(&ref);
			break;
		}

		case kAddCurrentDir:
		{
			BPath path;
			if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true)
					!= B_OK) {
				break;
			}

			path.Append(kGoDirectory);
			BDirectory goDirectory(path.Path());

			if (goDirectory.InitCheck() == B_OK) {
				BEntry entry(TargetModel()->EntryRef());
				entry.GetPath(&path);

				BSymLink link;
				goDirectory.CreateSymLink(TargetModel()->Name(), path.Path(),
					&link);
			}
			break;
		}

		case kEditFavorites:
		{
			BPath path;
			if (find_directory (B_USER_SETTINGS_DIRECTORY, &path, true)
					!= B_OK) {
				break;
			}

			path.Append(kGoDirectory);
			BMessenger msgr(kTrackerSignature);
			if (msgr.IsValid()) {
				BMessage message(B_REFS_RECEIVED);
				entry_ref ref;
				if (get_ref_for_path(path.Path(), &ref) == B_OK) {
					message.AddRef("refs", &ref);
					msgr.SendMessage(&message);
				}
			}
			break;
		}

		case kCancelButton:
			PostMessage(B_QUIT_REQUESTED);
			break;

		case kResizeToFit:
			ResizeToFit();
			break;

		case kOpenDir:
			OpenDirectory();
			break;

		case kOpenParentDir:
			OpenParent();
			break;

		case kDefaultButton:
			if (fIsSavePanel) {
				if (PoseView()->IsFocus()
					&& PoseView()->SelectionList()->CountItems() == 1) {
					Model* model = (PoseView()->SelectionList()->
						FirstItem())->TargetModel();
					if (model->ResolveIfLink()->IsDirectory()) {
						PoseView()->CommitActivePose();
						PoseView()->OpenSelection();
						break;
					}
				}

				HandleSaveButton();
			} else
				HandleOpenButton();
			break;

		case B_OBSERVER_NOTICE_CHANGE:
		{
			int32 observerWhat;
			if (message->FindInt32("be:observe_change_what", &observerWhat)
					== B_OK) {
				switch (observerWhat) {
					case kDesktopFilePanelRootChanged:
					{
						bool desktopIsRoot = true;
						if (message->FindBool("DesktopFilePanelRoot",
								&desktopIsRoot) == B_OK) {
							TrackerSettings().
								SetDesktopFilePanelRoot(desktopIsRoot);
						}
						SetTo(TargetModel()->EntryRef());
						break;
					}
				}
			}
			break;
		}

		default:
			_inherited::MessageReceived(message);
			break;
	}
}
コード例 #16
0
void
nsTextFragment::Append(const PRUnichar* aBuffer, PRUint32 aLength, PRBool aUpdateBidi)
{
    // This is a common case because some callsites create a textnode
    // with a value by creating the node and then calling AppendData.
    if (mState.mLength == 0) {
        SetTo(aBuffer, aLength, aUpdateBidi);

        return;
    }

    // Should we optimize for aData.Length() == 0?

    if (mState.mIs2b) {
        // Already a 2-byte string so the result will be too
        PRUnichar* buff = (PRUnichar*)nsMemory::Realloc(m2b, (mState.mLength + aLength) * sizeof(PRUnichar));
        if (!buff) {
            return;
        }

        memcpy(buff + mState.mLength, aBuffer, aLength * sizeof(PRUnichar));
        mState.mLength += aLength;
        m2b = buff;

        if (aUpdateBidi) {
            UpdateBidiFlag(aBuffer, aLength);
        }

        return;
    }

    // Current string is a 1-byte string, check if the new data fits in one byte too.
    PRInt32 first16bit = FirstNon8Bit(aBuffer, aBuffer + aLength);

    if (first16bit != -1) { // aBuffer contains no non-8bit character
        // The old data was 1-byte, but the new is not so we have to expand it
        // all to 2-byte
        PRUnichar* buff = (PRUnichar*)nsMemory::Alloc((mState.mLength + aLength) *
                          sizeof(PRUnichar));
        if (!buff) {
            return;
        }

        // Copy data into buff
        LossyConvertEncoding8to16 converter(buff);
        copy_string(m1b, m1b+mState.mLength, converter);

        memcpy(buff + mState.mLength, aBuffer, aLength * sizeof(PRUnichar));
        mState.mLength += aLength;
        mState.mIs2b = PR_TRUE;

        if (mState.mInHeap) {
            nsMemory::Free(m2b);
        }
        m2b = buff;

        mState.mInHeap = PR_TRUE;

        if (aUpdateBidi) {
            UpdateBidiFlag(aBuffer + first16bit, aLength - first16bit);
        }

        return;
    }

    // The new and the old data is all 1-byte
    char* buff;
    if (mState.mInHeap) {
        buff = (char*)nsMemory::Realloc(const_cast<char*>(m1b),
                                        (mState.mLength + aLength) * sizeof(char));
        if (!buff) {
            return;
        }
    }
    else {
        buff = (char*)nsMemory::Alloc((mState.mLength + aLength) * sizeof(char));
        if (!buff) {
            return;
        }

        memcpy(buff, m1b, mState.mLength);
        mState.mInHeap = PR_TRUE;
    }

    // Copy aBuffer into buff.
    LossyConvertEncoding16to8 converter(buff + mState.mLength);
    copy_string(aBuffer, aBuffer + aLength, converter);

    m1b = buff;
    mState.mLength += aLength;

}
コード例 #17
0
void
DisplayItemClip::SetTo(const nsRect& aRect)
{
  SetTo(aRect, nullptr);
}
コード例 #18
0
ファイル: EasyPath.cpp プロジェクト: HaikuArchives/LibWalter
EasyPath::EasyPath(const char *string)
{
	SetTo(string);
}
コード例 #19
0
ファイル: EasyPath.cpp プロジェクト: HaikuArchives/LibWalter
EasyPath &
EasyPath::operator =(const char *string)
{
	SetTo(string);
	return *this;
}
コード例 #20
0
ファイル: EasyPath.cpp プロジェクト: HaikuArchives/LibWalter
EasyPath &
EasyPath::operator =(const EasyPath &path)
{
	SetTo(path);
	return *this;
}
コード例 #21
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
void
BNetworkAddress::SetTo(const sockaddr_dl& address)
{
	SetTo((sockaddr&)address);
}
コード例 #22
0
ファイル: EasyPath.cpp プロジェクト: HaikuArchives/LibWalter
EasyPath::EasyPath(const BString &string)
{
	SetTo(string);
}
コード例 #23
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
BNetworkAddress::BNetworkAddress(const char* host, uint16 port, uint32 flags)
{
	fStatus = SetTo(host, port, flags);
}
コード例 #24
0
ファイル: nsAttrValue.cpp プロジェクト: ehsan/mozilla-history
nsAttrValue::nsAttrValue(const nsAString& aValue)
    : mBits(0)
{
  SetTo(aValue);
}
コード例 #25
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
BNetworkAddress::BNetworkAddress(int family, const char* host,
	const char* service, uint32 flags)
{
	fStatus = SetTo(family, host, service, flags);
}
コード例 #26
0
ファイル: nsAttrValue.cpp プロジェクト: ehsan/mozilla-history
nsAttrValue::nsAttrValue(css::StyleRule* aValue, const nsAString* aSerialized)
    : mBits(0)
{
  SetTo(aValue, aSerialized);
}
コード例 #27
0
ファイル: NetworkAddress.cpp プロジェクト: looncraz/haiku
BNetworkAddress::BNetworkAddress(const sockaddr_in& address)
{
	SetTo(address);
}
コード例 #28
0
ファイル: EasyPath.cpp プロジェクト: HaikuArchives/LibWalter
EasyPath::EasyPath(const EasyPath &path)
{
	SetTo(path);
}
コード例 #29
0
ファイル: fd.cpp プロジェクト: simonsouth/haiku
	inline file_descriptor* SetTo(int fd, bool kernel,
		bool contextLocked = false)
	{
		return SetTo(get_current_io_context(kernel), fd, contextLocked);
	}
コード例 #30
0
ファイル: nsAttrValue.cpp プロジェクト: ehsan/mozilla-history
nsAttrValue::nsAttrValue(const nsAttrValue& aOther)
    : mBits(0)
{
  SetTo(aOther);
}