Ejemplo n.º 1
0
// MoveItems
void
DragSortableListView::MoveItems(const BList& indices, int32 index)
{
	DeselectAll();
	// we remove the items while we look at them, the insertion index is decreased
	// when the items index is lower, so that we insert at the right spot after
	// removal
	BList removedItems;
	int32 count = indices.CountItems();
	for (int32 i = 0; i < count; i++) {
		int32 removeIndex = (int32)(addr_t)indices.ItemAtFast(i) - i;
		BListItem* item = RemoveItem(removeIndex);
		if (item && removedItems.AddItem((void*)item)) {
			if (removeIndex < index)
				index--;
		}
		// else ??? -> blow up
	}
	count = removedItems.CountItems();
	for (int32 i = 0; i < count; i++) {
		BListItem* item = (BListItem*)removedItems.ItemAtFast(i);
		if (AddItem(item, index)) {
			// after we're done, the newly inserted items will be selected
			Select(index, true);
			// next items will be inserted after this one
			index++;
		} else
			delete item;
	}
}
Ejemplo n.º 2
0
// CopyItems
void
DragSortableListView::CopyItems(const BList& indices, int32 toIndex)
{
	DeselectAll();
	// by inserting the items after we copied all items first, we avoid
	// cloning an item we already inserted and messing everything up
	// in other words, don't touch the list before we know which items
	// need to be cloned
	BList clonedItems;
	int32 count = indices.CountItems();
	for (int32 i = 0; i < count; i++) {
		int32 index = (int32)(addr_t)indices.ItemAtFast(i);
		BListItem* item = CloneItem(index);
		if (item && !clonedItems.AddItem((void*)(addr_t)item))
			delete item;
	}
	count = clonedItems.CountItems();
	for (int32 i = 0; i < count; i++) {
		BListItem* item = (BListItem*)clonedItems.ItemAtFast(i);
		if (AddItem(item, toIndex)) {
			// after we're done, the newly inserted items will be selected
			Select(toIndex, true);
			// next items will be inserted after this one
			toIndex++;
		} else
			delete item;
	}
}
Ejemplo n.º 3
0
// Draw
void
TestView::Draw(BRect updateRect)
{
	int32 count = fMouseSamples.CountItems();
	if (count > 0) {
		BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(0);
		MovePenTo(*p);
	}

	for (int32 i = 0; i < count; i++) {
		BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(i);
		StrokeLine(*p);
	}
}
Ejemplo n.º 4
0
status_t
Model::_SaveHistory(const BList& items) const
{
	BFile file;
	status_t status = _OpenFile(&file, PREFS_FILE,
		B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE,
		B_USER_SETTINGS_DIRECTORY, NULL);
	if (status != B_OK)
		return status;

	status = file.Lock();
	if (status != B_OK)
		return status;

	BMessage message;
	int32 count = items.CountItems();
	for (int32 i = 0; i < count; i++) {
		BString* string = static_cast<BString*>(items.ItemAtFast(i));

		if (message.AddString("string", string->String()) != B_OK)
			break;
	}

	status = message.Flatten(&file);
	file.SetSize(message.FlattenedSize());
	file.Sync();
	file.Unlock();

	return status;
}
Ejemplo n.º 5
0
// MoveItems
void
StyleListView::MoveItems(BList& items, int32 toIndex)
{
    if (!fCommandStack || !fStyleContainer)
        return;

    int32 count = items.CountItems();
    Style** styles = new (nothrow) Style*[count];
    if (!styles)
        return;

    for (int32 i = 0; i < count; i++) {
        StyleListItem* item
            = dynamic_cast<StyleListItem*>((BListItem*)items.ItemAtFast(i));
        styles[i] = item ? item->style : NULL;
    }

    MoveStylesCommand* command
        = new (nothrow) MoveStylesCommand(fStyleContainer,
                                          styles, count, toIndex);
    if (!command) {
        delete[] styles;
        return;
    }

    fCommandStack->Perform(command);
}
Ejemplo n.º 6
0
// CopyItems
void
StyleListView::CopyItems(BList& items, int32 toIndex)
{
    if (!fCommandStack || !fStyleContainer)
        return;

    int32 count = items.CountItems();
    Style* styles[count];

    for (int32 i = 0; i < count; i++) {
        StyleListItem* item
            = dynamic_cast<StyleListItem*>((BListItem*)items.ItemAtFast(i));
        styles[i] = item ? new (nothrow) Style(*item->style) : NULL;
    }

    AddStylesCommand* command
        = new (nothrow) AddStylesCommand(fStyleContainer,
                                         styles, count, toIndex);
    if (!command) {
        for (int32 i = 0; i < count; i++)
            delete styles[i];
        return;
    }

    fCommandStack->Perform(command);
}
Ejemplo n.º 7
0
void
PathListView::CopyItems(BList& items, int32 toIndex)
{
	if (fCommandStack == NULL || fPathContainer == NULL)
		return;

	int32 count = items.CountItems();
	VectorPath* paths[count];

	for (int32 i = 0; i < count; i++) {
		PathListItem* item
			= dynamic_cast<PathListItem*>((BListItem*)items.ItemAtFast(i));
		paths[i] = item ? new (nothrow) VectorPath(*item->path) : NULL;
	}

	AddPathsCommand* command = new(nothrow) AddPathsCommand(fPathContainer,
		paths, count, true, toIndex);
	if (command == NULL) {
		for (int32 i = 0; i < count; i++)
			delete paths[i];
		return;
	}

	fCommandStack->Perform(command);
}
Ejemplo n.º 8
0
void
PathListView::MoveItems(BList& items, int32 toIndex)
{
	if (fCommandStack == NULL || fPathContainer == NULL)
		return;

	int32 count = items.CountItems();
	VectorPath** paths = new (nothrow) VectorPath*[count];
	if (paths == NULL)
		return;

	for (int32 i = 0; i < count; i++) {
		PathListItem* item
			= dynamic_cast<PathListItem*>((BListItem*)items.ItemAtFast(i));
		paths[i] = item ? item->path : NULL;
	}

	MovePathsCommand* command = new (nothrow) MovePathsCommand(fPathContainer,
		paths, count, toIndex);
	if (command == NULL) {
		delete[] paths;
		return;
	}

	fCommandStack->Perform(command);
}
Ejemplo n.º 9
0
// SelectionChanged
void
DragSortableListView::SelectionChanged()
{
//printf("%s::SelectionChanged()", typeid(*this).name());
	// modify global Selection
	if (!fSelection || fSyncingToSelection)
		return;

	fModifyingSelection = true;

	BList selectables;
	for (int32 i = 0; BListItem* item = ItemAt(CurrentSelection(i)); i++) {
		Selectable* selectable = SelectableFor(item);
		if (selectable)
			selectables.AddItem((void*)selectable);
	}

	AutoNotificationSuspender _(fSelection);

	int32 count = selectables.CountItems();
	if (count == 0) {
//printf("  deselecting all\n");
		if (!fSyncingToSelection)
			fSelection->DeselectAll();
	} else {
//printf("  selecting %ld items\n", count);
		for (int32 i = 0; i < count; i++) {
			Selectable* selectable = (Selectable*)selectables.ItemAtFast(i);
			fSelection->Select(selectable, i > 0);
		}
	}

	fModifyingSelection = false;
}
Ejemplo n.º 10
0
// MoveItems
void
TransformerListView::MoveItems(BList& items, int32 toIndex)
{
	if (!fCommandStack || !fShape)
		return;

	int32 count = items.CountItems();
	Transformer** transformers = new (nothrow) Transformer*[count];
	if (!transformers)
		return;

	for (int32 i = 0; i < count; i++) {
		TransformerItem* item
			= dynamic_cast<TransformerItem*>((BListItem*)items.ItemAtFast(i));
		transformers[i] = item ? item->transformer : NULL;
	}

	MoveTransformersCommand* command
		= new (nothrow) MoveTransformersCommand(fShape,
												transformers, count, toIndex);
	if (!command) {
		delete[] transformers;
		return;
	}

	fCommandStack->Perform(command);
}
Ejemplo n.º 11
0
// MessageReceived
void
ShapeListView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case MSG_REMOVE:
			RemoveSelected();
			break;
		case MSG_DUPLICATE: {
			int32 count = CountSelectedItems();
			int32 index = 0;
			BList items;
			for (int32 i = 0; i < count; i++) {
				index = CurrentSelection(i);
				BListItem* item = ItemAt(index);
				if (item)
					items.AddItem((void*)item);
			}
			CopyItems(items, index + 1);
			break;
		}
		case MSG_RESET_TRANSFORMATION: {
			BList shapes;
			_GetSelectedShapes(shapes);
			int32 count = shapes.CountItems();
			if (count < 0)
				break;

			Transformable* transformables[count];
			for (int32 i = 0; i < count; i++) {
				Shape* shape = (Shape*)shapes.ItemAtFast(i);
				transformables[i] = shape;
			}

			ResetTransformationCommand* command = 
				new ResetTransformationCommand(transformables, count);

			fCommandStack->Perform(command);
			break;
		}
		case MSG_FREEZE_TRANSFORMATION: {
			BList shapes;
			_GetSelectedShapes(shapes);
			int32 count = shapes.CountItems();
			if (count < 0)
				break;

			FreezeTransformationCommand* command = 
				new FreezeTransformationCommand((Shape**)shapes.Items(),
					count);

			fCommandStack->Perform(command);
			break;
		}
		default:
			SimpleListView::MessageReceived(message);
			break;
	}
}
Ejemplo n.º 12
0
// RemoveItemList
void
DragSortableListView::RemoveItemList(const BList& indices)
{
	int32 count = indices.CountItems();
	for (int32 i = 0; i < count; i++) {
		int32 index = (int32)(addr_t)indices.ItemAtFast(i) - i;
		delete RemoveItem(index);
	}
}
Ejemplo n.º 13
0
PersonData *PeepsWindow::FindPerson(node_ref nref)
{
	PersonData *pdata=NULL;
	for(int32 i=0; i<gPeopleData.CountItems(); i++)
	{
		pdata=(PersonData*)gPeopleData.ItemAtFast(i);
		if(pdata->NodeRef()==nref)
			return pdata;
	}
	return NULL;
}
Ejemplo n.º 14
0
bool
PairsView::_HasBitmap(BList& bitmaps, BBitmap* bitmap)
{
	// TODO: if this takes too long, we could build a hash value for each
	// bitmap in a separate list
	for (int32 i = bitmaps.CountItems(); i-- > 0;) {
		BBitmap* item = (BBitmap*)bitmaps.ItemAtFast(i);
		if (!memcmp(item->Bits(), bitmap->Bits(), item->BitsLength()))
			return true;
	}

	return false;
}
Ejemplo n.º 15
0
bool
StyleListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
{
	// Let SimpleListView handle drag-sorting (when drag came from ourself)
	if (SimpleListView::HandleDropMessage(message, dropIndex))
		return true;

	if (fCommandStack == NULL || fStyleContainer == NULL)
		return false;

	// Drag may have come from another instance, like in another window.
	// Reconstruct the Styles from the archive and add them at the drop
	// index.
	int index = 0;
	BList styles;
	while (true) {
		BMessage archive;
		if (message->FindMessage("style archive", index, &archive) != B_OK)
			break;
		Style* style = new(std::nothrow) Style(&archive);
		if (style == NULL)
			break;
		
		if (!styles.AddItem(style)) {
			delete style;
			break;
		}

		index++;
	}

	int32 count = styles.CountItems();
	if (count == 0)
		return false;

	AddStylesCommand* command = new(std::nothrow) AddStylesCommand(
		fStyleContainer, (Style**)styles.Items(), count, dropIndex);

	if (command == NULL) {
		for (int32 i = 0; i < count; i++)
			delete (Style*)styles.ItemAtFast(i);
		return false;
	}

	fCommandStack->Perform(command);

	return true;
}
Ejemplo n.º 16
0
bool
PathListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
{
	// Let SimpleListView handle drag-sorting (when drag came from ourself)
	if (SimpleListView::HandleDropMessage(message, dropIndex))
		return true;

	if (fCommandStack == NULL || fPathContainer == NULL)
		return false;

	// Drag may have come from another instance, like in another window.
	// Reconstruct the Styles from the archive and add them at the drop
	// index.
	int index = 0;
	BList paths;
	while (true) {
		BMessage archive;
		if (message->FindMessage("path archive", index, &archive) != B_OK)
			break;

		VectorPath* path = new(std::nothrow) VectorPath(&archive);
		if (path == NULL)
			break;
		
		if (!paths.AddItem(path)) {
			delete path;
			break;
		}

		index++;
	}

	int32 count = paths.CountItems();
	if (count == 0)
		return false;

	AddPathsCommand* command = new(nothrow) AddPathsCommand(fPathContainer,
		(VectorPath**)paths.Items(), count, true, dropIndex);
	if (command == NULL) {
		for (int32 i = 0; i < count; i++)
			delete (VectorPath*)paths.ItemAtFast(i);
		return false;
	}

	fCommandStack->Perform(command);

	return true;
}
Ejemplo n.º 17
0
// RemoveItemList
void
TransformerListView::RemoveItemList(BList& items)
{
	if (!fCommandStack || !fShape)
		return;

	int32 count = items.CountItems();
	int32 indices[count];
	for (int32 i = 0; i < count; i++)
		indices[i] = IndexOf((BListItem*)items.ItemAtFast(i));

	RemoveTransformersCommand* command
		= new (nothrow) RemoveTransformersCommand(fShape,
												  indices, count);
	fCommandStack->Perform(command);
}
Ejemplo n.º 18
0
void
Model::FillHistoryMenu(BMenu* menu) const
{
	BList items;
	if (!_LoadHistory(items))
		return;

	for (int32 t = items.CountItems() - 1; t >= 0; --t) {
		BString* item = static_cast<BString*>(items.ItemAtFast(t));
		BMessage* message = new BMessage(MSG_SELECT_HISTORY);
		message->AddString("text", item->String());
		menu->AddItem(new BMenuItem(item->String(), message));
	}

	_FreeHistory(items);
}
Ejemplo n.º 19
0
// RemoveItemList
void
StyleListView::RemoveItemList(BList& items)
{
    if (!fCommandStack || !fStyleContainer)
        return;

    int32 count = items.CountItems();
    Style* styles[count];
    for (int32 i = 0; i < count; i++) {
        StyleListItem* item = dynamic_cast<StyleListItem*>(
                                  (BListItem*)items.ItemAtFast(i));
        if (item)
            styles[i] = item->style;
        else
            styles[i] = NULL;
    }

    RemoveStylesCommand* command
        = new (nothrow) RemoveStylesCommand(fStyleContainer,
                                            styles, count);
    fCommandStack->Perform(command);
}
Ejemplo n.º 20
0
void
PathListView::RemoveItemList(BList& items)
{
	if (fCommandStack == NULL || fPathContainer == NULL)
		return;

	int32 count = items.CountItems();
	VectorPath* paths[count];
	for (int32 i = 0; i < count; i++) {
		PathListItem* item = dynamic_cast<PathListItem*>(
			(BListItem*)items.ItemAtFast(i));
		if (item != NULL)
			paths[i] = item->path;
		else
			paths[i] = NULL;
	}

	RemovePathsCommand* command = new (nothrow) RemovePathsCommand(
		fPathContainer, paths, count);

	fCommandStack->Perform(command);
}
Ejemplo n.º 21
0
// MouseDown
void
TestView::MouseDown(BPoint where)
{
	// clear previous stroke
	int32 count = fMouseSamples.CountItems();
	for (int32 i = 0; i < count; i++)
		delete (BPoint*)fMouseSamples.ItemAtFast(i);
	fMouseSamples.MakeEmpty();
	FillRect(Bounds(), B_SOLID_LOW);

	// sample new stroke
	uint32 buttons;
	GetMouse(&where, &buttons);
	MovePenTo(where);
	while (buttons) {

		StrokeLine(where);
		fMouseSamples.AddItem(new BPoint(where));

		snooze(20000);
		GetMouse(&where, &buttons);
	}
}
Ejemplo n.º 22
0
// _CollectRandom
status_t
CollectingPlaylist::_CollectRandom(BList& collectables,
	const ServerObjectManager* library)
{
	uint64 defaultDuration = ItemDuration();

	int32 count = collectables.CountItems();
	int32 index = rand() % count;

	CollectablePlaylist* collectable
		= (CollectablePlaylist*)collectables.ItemAtFast(index);

	uint64 itemDuration = collectable->PreferredDuration();
	if (itemDuration == 0)
		itemDuration = defaultDuration;

	ClipPlaylistItem* item = new (nothrow) ClipPlaylistItem(collectable);
		// the item, if it was created, has it's own reference now
	if (!item) {
		print_error("CollectingPlaylist::_CollectRandom() - "
			"no memory to create ClipPlaylistItem\n");
		return B_NO_MEMORY;
	}

	if (!AddItem(item)) {
		delete item;
		print_error("CollectingPlaylist::_CollectRandom() - "
			"no memory to add ClipPlaylistItem\n");
		return B_NO_MEMORY;
	}

	item->SetStartFrame(0);
	item->SetDuration(itemDuration);
	item->SetTrack(0);

	return B_OK;
}
Ejemplo n.º 23
0
// ValidateItemLayout
void
SlideShowPlaylist::ValidateItemLayout()
{
	int64 duration = Value(PROPERTY_DURATION, (int64)0);
	if (duration == 0)
		return;

	int64 transitionDuration
		= Value(PROPERTY_TRANSITION_DURATION, (int64)0);
	// TODO: transition mode...

	int32 count = CountItems();

	BList managedItems;

	int64 minDuration = 0;
	int64 minItemDuration = transitionDuration * 3;
	int64 fixedItemsDuration = 0;
	int64 maxDuration = 0;
	int32 variableItemCount = 0;
	for (int32 i = 0; i < count; i++) {
		PlaylistItem* item = ItemAtFast(i);
		if (item->Track() > 1)
			// not a "managed" item
			continue;

		managedItems.AddItem(item);

		if (item->HasMaxDuration()) {
			int64 maxItemDuration = item->MaxDuration();
			minDuration += maxItemDuration;
			fixedItemsDuration += maxItemDuration;
			if (minItemDuration > maxItemDuration)
				minItemDuration = maxItemDuration;
		} else {
			minDuration += 3 * transitionDuration;
			variableItemCount++;
		}

		maxDuration += item->MaxDuration();
	}

	count = managedItems.CountItems();
	if (count == 0)
		return;

	if (duration < minDuration)
		duration = minDuration;
	if (duration > maxDuration)
		duration = maxDuration;

	// limit transition duration to 1/3 of the minimum item duration
	int64 maxTransitionDuration = minItemDuration / 3;

	if (transitionDuration > maxTransitionDuration)
		transitionDuration = maxTransitionDuration;

	int64 variableItemsDuration = duration - fixedItemsDuration
			+ transitionDuration * (count - variableItemCount);

	int64 startFrame = 0;
	int64 lastVariableStartFrame = 0;
	int32 variableItemIndex = 0;
	for (int32 i = 0; i < count; i++) {
		PlaylistItem* item = (PlaylistItem*)managedItems.ItemAtFast(i);
		// overlapping items
		item->SetClipOffset(0);
		item->SetTrack(i & 1);

		int64 nextStartFrame;
		if (item->HasMaxDuration()) {
			nextStartFrame = startFrame + item->MaxDuration()
								- transitionDuration;
		} else {
			variableItemIndex++;
			int64 nextVariableStartFrame = (variableItemsDuration - transitionDuration)
								* variableItemIndex / variableItemCount;
			nextStartFrame = startFrame + nextVariableStartFrame - lastVariableStartFrame;
			lastVariableStartFrame = nextVariableStartFrame;
		}
		item->SetStartFrame(startFrame);
		item->SetDuration(nextStartFrame - startFrame + transitionDuration);
		startFrame = nextStartFrame;

		// transition
		PropertyAnimator* animator = item->AlphaAnimator();
		if (!animator)
			continue;

		AutoNotificationSuspender _(animator);

		// remove all keyframes to get a clean start
		animator->MakeEmpty();
		KeyFrame* first = animator->InsertKeyFrameAt(0LL);
		KeyFrame* last = animator->InsertKeyFrameAt(item->Duration() - 1);

		if (!first || !last)
			continue;

		first->SetScale(1.0);
		last->SetScale(1.0);

		// transition in top items
		if (transitionDuration > 0 && !(i & 1)) {
			// item on first track, animated opacity property
			if (i > 0) {
				// fade in
				KeyFrame* key = animator->InsertKeyFrameAt(transitionDuration);
				key->SetScale(1.0);
				first->SetScale(0.0);
			}
			
			if (i < count - 1) {
				// fade out
				KeyFrame* key = animator->InsertKeyFrameAt(
									item->Duration() - 1 - transitionDuration);
				key->SetScale(1.0);
				last->SetScale(0.0);
			}
		}
	}
}
Ejemplo n.º 24
0
// _CollectSequence
status_t
CollectingPlaylist::_CollectSequence(BList& collectables,
	const ServerObjectManager* library)
{
	collectables.SortItems(compare_collectables);

	// find the transition clip, if we are supposed to have one
	Clip* transitionClip = NULL;
	BString transitionClipID = TransitionClipID();

	if (transitionClipID.Length() > 0) {
		transitionClip = dynamic_cast<Clip*>(library->FindObject(
			transitionClipID.String()));
		if (!transitionClip) {
			print_error("CollectingPlaylist::_CollectSequence() - "
				"didn't find transition clip: %s (ignoring)\n",
				transitionClipID.String());
		}
	}

	BString previousName;

	int64 startFrame = 0;
	uint64 maxDuration = Value(PROPERTY_DURATION, (int64)0);
	uint64 defaultDuration = ItemDuration();

	int32 count = collectables.CountItems();
	for (int32 i = 0; i < count; i++) {
		CollectablePlaylist* collectable
			= (CollectablePlaylist*)collectables.ItemAtFast(i);

		uint64 itemDuration = collectable->PreferredDuration();
		if (itemDuration == 0)
			itemDuration = defaultDuration;
		if (maxDuration > 0 && startFrame + itemDuration > maxDuration) {
			// we would go past our maximum duration, so stop here
			break;
		}

		ClipPlaylistItem* item = new (nothrow) ClipPlaylistItem(collectable);
			// the item, if it was created, has it's own reference now
		if (!item) {
			print_error("CollectingPlaylist::_CollectSequence() - "
				"no memory to create ClipPlaylistItem\n");
			return B_NO_MEMORY;
		}

		BString name(collectable->Name());
		if (i > 0 && name != previousName && transitionClip) {
//printf("new sequence starts at %ld\n", i);
			// a new sequence starts
			ClipPlaylistItem* transitionItem
				= new (nothrow) ClipPlaylistItem(transitionClip);
			if (!transitionItem || !AddItem(transitionItem)) {
				delete transitionItem;
				print_error("CollectingPlaylist::_CollectSequence() - "
					"no memory to create/add ClipPlaylistItem (transition)\n");
				return B_NO_MEMORY;
			}

			transitionItem->SetStartFrame(startFrame);
			int64 transitionDuration = transitionClip->Duration();
			transitionItem->SetDuration(transitionDuration);
			startFrame += transitionDuration;
		}

		if (!AddItem(item)) {
			delete item;
			print_error("CollectingPlaylist::_CollectSequence() - "
				"no memory to add ClipPlaylistItem\n");
			return B_NO_MEMORY;
		}

		item->SetStartFrame(startFrame);
		item->SetDuration(itemDuration);
		item->SetTrack(0);

		startFrame += itemDuration;
		previousName = name;
	}
	return B_OK;
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
// MessageReceived
void
StyleListView::MessageReceived(BMessage* message)
{
    switch (message->what) {
    case MSG_ADD: {
        Style* style;
        AddStylesCommand* command;
        rgb_color color;
        if (fCurrentColor != NULL)
            color = fCurrentColor->Color();
        else {
            color.red = 0;
            color.green = 0;
            color.blue = 0;
            color.alpha = 255;
        }
        new_style(color, fStyleContainer, &style, &command);
        fCommandStack->Perform(command);
        break;
    }
    case MSG_REMOVE:
        RemoveSelected();
        break;
    case MSG_DUPLICATE: {
        int32 count = CountSelectedItems();
        int32 index = 0;
        BList items;
        for (int32 i = 0; i < count; i++) {
            index = CurrentSelection(i);
            BListItem* item = ItemAt(index);
            if (item)
                items.AddItem((void*)item);
        }
        CopyItems(items, index + 1);
        break;
    }
    case MSG_RESET_TRANSFORMATION: {
        int32 count = CountSelectedItems();
        BList gradients;
        for (int32 i = 0; i < count; i++) {
            StyleListItem* item = dynamic_cast<StyleListItem*>(
                                      ItemAt(CurrentSelection(i)));
            if (item && item->style && item->style->Gradient())
                if (!gradients.AddItem(
                            (void*)item->style->Gradient()))
                    break;
        }
        count = gradients.CountItems();
        if (count < 0)
            break;

        Transformable* transformables[count];
        for (int32 i = 0; i < count; i++) {
            Gradient* gradient = (Gradient*)gradients.ItemAtFast(i);
            transformables[i] = gradient;
        }

        ResetTransformationCommand* command =
            new ResetTransformationCommand(transformables, count);

        fCommandStack->Perform(command);
        break;
    }
    default:
        SimpleListView::MessageReceived(message);
        break;
    }
}
Ejemplo n.º 27
0
void
Model::_FreeHistory(const BList& items) const
{
	for (int32 t = items.CountItems() - 1; t >= 0; --t)
		delete static_cast<BString*>((items.ItemAtFast(t)));
}