Ejemplo n.º 1
0
status_t
IMAPStorage::AddNewMessage(int32 uid, int32 flags, BPositionIO** file)
{
    if (file != NULL)
        *file = NULL;
    // TODO: make sure there is not a valid mail with this name
    BString fileName = "Downloading file... uid: ";
    fileName << uid;

    BPath filePath = fMailboxPath;
    filePath.Append(fileName);
    TRACE("AddNewMessage %s\n", filePath.Path());
    BFile* newFile = new BFile(filePath.Path(), B_READ_WRITE | B_CREATE_FILE
                               | B_ERASE_FILE);
    if (newFile == NULL)
        return B_NO_MEMORY;

    StorageMailEntry storageEntry;
    storageEntry.uid = uid;
    storageEntry.flags = flags;
    storageEntry.fileName = fileName;
    newFile->GetNodeRef(&storageEntry.nodeRef);

    if (_WriteUniqueID(*newFile, uid) != B_OK) {
        delete newFile;
        return B_ERROR;
    }

    status_t status = _WriteFlags(flags, *newFile);
    if (status != B_OK) {
        delete newFile;
        return status;
    }

    if (file)
        *file = newFile;
    else
        delete newFile;
    fMailEntryMap[uid] = storageEntry;
    return B_OK;
}
Ejemplo n.º 2
0
/*! Message must contain an archivable view for later rehydration.
	This function takes over ownership of the provided message on success
	only.
	Returns the current replicant ID.
*/
status_t
TReplicantTray::AddIcon(BMessage* archive, int32* id, const entry_ref* addOn)
{
	if (archive == NULL || id == NULL)
		return B_ERROR;

	// find entry_ref

	entry_ref ref;
	if (addOn) {
		// Use it if we got it
		ref = *addOn;
	} else {
		const char* signature;

		status_t status = archive->FindString("add_on", &signature);
		if (status == B_OK) {
			BRoster roster;
			status = roster.FindApp(signature, &ref);
		}
		if (status < B_OK)
			return status;
	}

	BFile file;
	status_t status = file.SetTo(&ref, B_READ_ONLY);
	if (status < B_OK)
		return status;

	node_ref nodeRef;
	status = file.GetNodeRef(&nodeRef);
	if (status < B_OK)
		return status;

	BEntry entry(&ref, true);
		// TODO: this resolves an eventual link for the item being added - this
		// is okay for now, but in multi-user environments, one might want to
		// have links that carry the be:deskbar_item_status attribute
	status = entry.InitCheck();
	if (status != B_OK)
		return status;

	*id = 999;
	if (archive->what == B_ARCHIVED_OBJECT)
		archive->what = 0;

	BRect originalBounds = archive->FindRect("_frame");
		// this is a work-around for buggy replicants that change their size in
		// AttachedToWindow() (such as "SVM")

	// TODO: check for name collisions?
	status = fShelf->AddReplicant(archive, BPoint(1, 1));
	if (status != B_OK)
		return status;

	int32 count = fShelf->CountReplicants();
	BView* view;
	fShelf->ReplicantAt(count - 1, &view, (uint32*)id, NULL);

	if (originalBounds != view->Bounds()) {
		// The replicant changed its size when added to the window, so we need
		// to recompute all over again (it's already done once via
		// BShelf::AddReplicant() and TReplicantShelf::CanAcceptReplicantView())
		RealignReplicants();
	}

	float oldWidth = Bounds().Width();
	float oldHeight = Bounds().Height();
	float width, height;
	GetPreferredSize(&width, &height);
	if (oldWidth != width || oldHeight != height)
		AdjustPlacement();

	// add the item to the add-on list

	AddItem(*id, nodeRef, entry, addOn != NULL);
	return B_OK;
}