예제 #1
0
status_t
BDaemonClient::GetInstallationLocationInfo(
	BPackageInstallationLocation location, BInstallationLocationInfo& _info)
{
	status_t error = _InitMessenger();
	if (error != B_OK)
		return error;

	// send the request
	BMessage request(B_MESSAGE_GET_INSTALLATION_LOCATION_INFO);
	error = request.AddInt32("location", location);
	if (error != B_OK)
		return error;

	BMessage reply;
	fDaemonMessenger.SendMessage(&request, &reply);
	if (reply.what != B_MESSAGE_GET_INSTALLATION_LOCATION_INFO_REPLY)
		return B_ERROR;

	// extract the location info
	int32 baseDirectoryDevice;
	int64 baseDirectoryNode;
	int32 packagesDirectoryDevice;
	int64 packagesDirectoryNode;
	int64 changeCount;
	BPackageInfoSet activePackages;
	BPackageInfoSet inactivePackages;
	if ((error = reply.FindInt32("base directory device", &baseDirectoryDevice))
			!= B_OK
		|| (error = reply.FindInt64("base directory node", &baseDirectoryNode))
			!= B_OK
		|| (error = reply.FindInt32("packages directory device",
			&packagesDirectoryDevice)) != B_OK
		|| (error = reply.FindInt64("packages directory node",
			&packagesDirectoryNode)) != B_OK
		|| (error = _ExtractPackageInfoSet(reply, "active packages",
			activePackages)) != B_OK
		|| (error = _ExtractPackageInfoSet(reply, "inactive packages",
			inactivePackages)) != B_OK
		|| (error = reply.FindInt64("change count", &changeCount)) != B_OK) {
		return error;
	}

	_info.Unset();
	_info.SetLocation(location);
	_info.SetBaseDirectoryRef(node_ref(baseDirectoryDevice, baseDirectoryNode));
	_info.SetPackagesDirectoryRef(
		node_ref(packagesDirectoryDevice, packagesDirectoryNode));
	_info.SetActivePackageInfos(activePackages);
	_info.SetInactivePackageInfos(inactivePackages);
	_info.SetChangeCount(changeCount);

	return B_OK;
}
예제 #2
0
/*! This method is called when BMediaFormats asks for any updates
 	made to our format list.
	If there were any changes since the last time, the whole
	list will be sent back.
*/
void 
FormatManager::GetFormats(BMessage& message)
{
	BAutolock locker(fLock);

	bigtime_t lastUpdate;
	if (message.FindInt64("last_timestamp", &lastUpdate) == B_OK
		&& lastUpdate >= fLastUpdate) {
		// There weren't any changes since last time.
		BMessage reply;
		reply.AddBool("need_update", false);

		message.SendReply(&reply, (BHandler*)NULL, TIMEOUT);
		return;
	}

	// Add all meta formats to the list
	BMessage reply;
	reply.AddBool("need_update", true);
	reply.AddInt64("timestamp", system_time());

	int32 count = fList.CountItems();
	printf("FormatManager::GetFormats(): put %" B_PRId32 " formats into "
		"message\n", count);
	for (int32 i = 0; i < count; i++) {
		meta_format* format = fList.ItemAt(i);
		reply.AddData("formats", MEDIA_META_FORMAT_TYPE, format,
			sizeof(meta_format));
	}

	message.SendReply(&reply, (BHandler*)NULL, TIMEOUT);
}
예제 #3
0
/*!	\brief Returns the time interval between two messages and the number of
		   times the message has still to be sent.

	Both parameters (\a interval and \a count) may be \c NULL.

	\param interval Pointer to a pre-allocated bigtime_t variable to be set
		   to the time interval. May be \c NULL.
	\param count Pointer to a pre-allocated int32 variable to be set
		   to the number of times the message has still to be sent.
		   May be \c NULL.
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: The message runner is not longer valid. All the
	  messages that had to be sent have already been sent.
*/
status_t
BMessageRunner::GetInfo(bigtime_t *interval, int32 *count) const
{
	status_t error =  (fToken >= 0 ? B_OK : B_BAD_VALUE);
	// compose the request message
	BMessage request(B_REG_GET_MESSAGE_RUNNER_INFO);
	if (error == B_OK)
		error = request.AddInt32("token", fToken);
	// send the request
	BMessage reply;
	if (error == B_OK)
		error = BRoster::Private().SendTo(&request, &reply, false);
	// evaluate the reply
	if (error == B_OK) {
		if (reply.what == B_REG_SUCCESS) {
			// count
			int32 _count;
			if (reply.FindInt32("count", &_count) == B_OK) {
				if (count)
					*count = _count;
			} else
				error = B_ERROR;
			// interval
			bigtime_t _interval;
			if (reply.FindInt64("interval", &_interval) == B_OK) {
				if (interval)
					*interval = _interval;
			} else
				error = B_ERROR;
		} else
			reply.FindInt32("error", &error);
	}
	return error;
}
예제 #4
0
void
ScreenshotWindow::_ReadSettings()
{
	BMessage settings;

	BPath settingsPath;
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath) != B_OK)
		return;

	settingsPath.Append("Screenshot_settings");

	BFile file(settingsPath.Path(), B_READ_ONLY);
	if (file.InitCheck() == B_OK)
		settings.Unflatten(&file);

	if (settings.FindInt32("type", &fImageFileType) != B_OK)
		fImageFileType = B_PNG_FORMAT;
	settings.FindBool("includeBorder", &fIncludeBorder);
	settings.FindBool("includeCursor", &fIncludeCursor);
	settings.FindBool("grabActiveWindow", &fGrabActiveWindow);
	settings.FindInt64("delay", &fDelay);
	settings.FindString("outputFilename", &fOutputFilename);

	_SetupOutputPathMenu(settings);
}
예제 #5
0
bool
SATWindow::SetSettings(const BMessage& message)
{
	uint64 id;
	if (message.FindInt64("window_id", (int64*)&id) != B_OK)
		return false;
	fId = id;
	return true;
}
예제 #6
0
/** We share one global list for all BMediaFormats in the team - since the
 *	format data can change at any time, we have to update the list to ensure
 *	that we are working on the latest data set. The list is always sorted by
 *	description. The formats lock has to be held when you call this function.
 */
static status_t
update_media_formats()
{
	if (!sLock.IsLocked())
		return B_NOT_ALLOWED;

	// We want the add-ons to register themselves with the format manager, so
	// the list is up to date.
	AddOnManager::GetInstance()->RegisterAddOns();

	BMessage reply;
	FormatManager::GetInstance()->GetFormats(sLastFormatsUpdate, reply);

	// do we need an update at all?
	bool needUpdate;
	if (reply.FindBool("need_update", &needUpdate) < B_OK)
		return B_ERROR;
	if (!needUpdate)
		return B_OK;

	// update timestamp and check if the message is okay
	type_code code;
	int32 count;
	if (reply.FindInt64("timestamp", &sLastFormatsUpdate) < B_OK
		|| reply.GetInfo("formats", &code, &count) < B_OK)
		return B_ERROR;

	// overwrite already existing formats

	int32 index = 0;
	for (; index < sFormats.CountItems() && index < count; index++) {
		meta_format* item = sFormats.ItemAt(index);

		const meta_format* newItem;
		ssize_t size;
		if (reply.FindData("formats", MEDIA_META_FORMAT_TYPE, index,
				(const void**)&newItem, &size) == B_OK)
			*item = *newItem;
	}

	// allocate additional formats

	for (; index < count; index++) {
		const meta_format* newItem;
		ssize_t size;
		if (reply.FindData("formats", MEDIA_META_FORMAT_TYPE, index,
				(const void**)&newItem, &size) == B_OK)
			sFormats.AddItem(new meta_format(*newItem));
	}

	// remove no longer used formats

	while (count < sFormats.CountItems())
		delete sFormats.RemoveItemAt(count);

	return B_OK;
}
예제 #7
0
status_t find_time(const BMessage& msg, const char* name, int32 i, AmTime* timeVal)
{
	status_t res = msg.FindInt64(name, i, (int64*)timeVal);
	if (res != B_OK) {
		int32 val;
		res = msg.FindInt32(name, i, &val);
		if (res == B_OK) *timeVal = val;
	}
	return res;
}
예제 #8
0
// constructor
MediaClip::MediaClip(const entry_ref* ref, const BMessage& archive)
	: FileBasedClip(ref),
	  fHasVideoTrack(false),
	  fHasAudioTrack(false),
	  fBounds(0, 0, -1, -1),
	  fVideoFrameCount(0),
	  fAudioFrameCount(0),
	  fVideoFPS(0.0),
	  fAudioFPS(0.0)
{
	if (archive.FindInt64("video frames", (int64*)&fVideoFrameCount) == B_OK
		&& archive.FindFloat("video fps", &fVideoFPS) == B_OK
		&& archive.FindRect("bounds", &fBounds) == B_OK)
		fHasVideoTrack = true;

	if (archive.FindInt64("audio frames", (int64*)&fAudioFrameCount) == B_OK
		&& archive.FindFloat("audio fps", &fAudioFPS) == B_OK)
		fHasAudioTrack = true;

	SetValue(PROPERTY_WIDTH, fBounds.Width() + 1);
	SetValue(PROPERTY_HEIGHT, fBounds.Height() + 1);
}
예제 #9
0
status_t
get_key_repeat_delay(bigtime_t *delay)
{
	BMessage command(IS_GET_KEY_REPEAT_DELAY);
	BMessage reply;

	_control_input_server_(&command, &reply);

	if (reply.FindInt64("delay", delay) != B_OK)
		*delay = 200;

	return B_OK;
}
예제 #10
0
status_t
get_click_speed(bigtime_t *speed)
{
	BMessage command(IS_GET_CLICK_SPEED);
	BMessage reply;

	status_t err = _control_input_server_(&command, &reply);
	if (err != B_OK)
		return err;

	if (reply.FindInt64("speed", speed) != B_OK)
		*speed = 500000;

	return B_OK;
}
예제 #11
0
//------------------------------------------------------------------------------
void TMessageEasyFindTest::MessageEasyFindTest1()
{
	BRect r(0, 0, -1, -1);
	BPoint p(0, 0);
	BMessage msg;
	CPPUNIT_ASSERT(msg.FindRect("data") == r);
	CPPUNIT_ASSERT(msg.FindPoint("data") == p);
	CPPUNIT_ASSERT(msg.FindString("data") == NULL);
	CPPUNIT_ASSERT(msg.FindInt8("data") == 0);
	CPPUNIT_ASSERT(msg.FindInt16("data") == 0);
	CPPUNIT_ASSERT(msg.FindInt32("data") == 0);
	CPPUNIT_ASSERT(msg.FindInt64("data") == 0);
	CPPUNIT_ASSERT(msg.FindBool("data") == false);
	CPPUNIT_ASSERT(msg.FindFloat("data") == 0);
	CPPUNIT_ASSERT(msg.FindDouble("data") == 0);
}
예제 #12
0
파일: Key.cpp 프로젝트: AmirAbrams/haiku
status_t
BKey::Unflatten(const BMessage& message)
{
	BKeyType type;
	if (message.FindUInt32("type", (uint32*)&type) != B_OK || type != Type())
		return B_BAD_VALUE;

	const void* data = NULL;
	ssize_t dataLength = 0;
	if (message.FindUInt32("purpose", (uint32*)&fPurpose) != B_OK
		|| message.FindString("identifier", &fIdentifier) != B_OK
		|| message.FindString("secondaryIdentifier", &fSecondaryIdentifier)
			!= B_OK
		|| message.FindString("owner", &fOwner) != B_OK
		|| message.FindInt64("creationTime", &fCreationTime) != B_OK
		|| message.FindData("data", B_RAW_TYPE, &data, &dataLength) != B_OK
		|| dataLength < 0) {
		return B_ERROR;
	}

	return SetData((const uint8*)data, (size_t)dataLength);
}
예제 #13
0
int32 ticker(void *data) {
	
	BMessage	*msg = (BMessage *)data;
	
	int64	snooze_time = 0;
	msg->FindInt64("snooze", &snooze_time);

	BLooper		*looper = 0;
	msg->FindPointer("looper", (void **)&looper);

	delete msg;
	
	if (looper==0 || snooze_time==0) return 10;
	
	long long nexttick = system_time();
	
	for (;;) {
		nexttick += snooze_time;
		snooze_until(nexttick,  B_SYSTEM_TIMEBASE);
		looper->PostMessage('tick');
	}
	return 0;
}
예제 #14
0
status_t ExtractQueryVolumes(BNode *node, vollist *volumes) {
	int32 length = 0;
	char *attr = ReadAttribute(*node, kTrackerQueryVolume, &length);
	BVolumeRoster roster;

	if (attr == NULL) {
		roster.Rewind();
		BVolume vol;
		
		while (roster.GetNextVolume(&vol) == B_NO_ERROR) {
			if ((vol.IsPersistent() == true) && (vol.KnowsQuery() == true)) {
				volumes->push_back(vol);
			};
		};
	} else {
		BMessage msg;
		msg.Unflatten(attr);

//		!*YOINK*!d from that project... with the funny little doggie as a logo...
//		OpenTracker, that's it!
			
		time_t created;
		off_t capacity;
		
		for (int32 index = 0; msg.FindInt32("creationDate", index, &created) == B_OK;
			index++) {
			
			if ((msg.FindInt32("creationDate", index, &created) != B_OK)
				|| (msg.FindInt64("capacity", index, &capacity) != B_OK))
				return B_ERROR;
		
			BVolume volume;
			BString deviceName = "";
			BString volumeName = "";
			BString fshName = "";
		
			if (msg.FindString("deviceName", &deviceName) == B_OK
				&& msg.FindString("volumeName", &volumeName) == B_OK
				&& msg.FindString("fshName", &fshName) == B_OK) {
				// New style volume identifiers: We have a couple of characteristics,
				// and compute a score from them. The volume with the greatest score
				// (if over a certain threshold) is the one we're looking for. We
				// pick the first volume, in case there is more than one with the
				// same score.
				int foundScore = -1;
				roster.Rewind();
				
				char name[B_FILE_NAME_LENGTH];
				
				while (roster.GetNextVolume(&volume) == B_OK) {
					if (volume.IsPersistent() && volume.KnowsQuery()) {
						// get creation time and fs_info
						BDirectory root;
						volume.GetRootDirectory(&root);
						time_t cmpCreated;
						fs_info info;
						if (root.GetCreationTime(&cmpCreated) == B_OK
							&& fs_stat_dev(volume.Device(), &info) == 0) {
							// compute the score
							int score = 0;
		
							// creation time
							if (created == cmpCreated)
								score += 5;
							// capacity
							if (capacity == volume.Capacity())
								score += 4;
							// device name
							if (deviceName == info.device_name)
								score += 3;
							// volume name
							if (volumeName == info.volume_name)
								score += 2;
							// fsh name
							if (fshName == info.fsh_name)
								score += 1;
		
							// check score
							if (score >= 9 && score > foundScore) {
								volume.GetName(name);
								volumes->push_back(volume);
							}
						}
					}
				}
			} else {
				// Old style volume identifiers: We have only creation time and
				// capacity. Both must match.
				roster.Rewind();
				while (roster.GetNextVolume(&volume) == B_OK)
					if (volume.IsPersistent() && volume.KnowsQuery()) {
						BDirectory root;
						volume.GetRootDirectory(&root);
						time_t cmpCreated;
						root.GetCreationTime(&cmpCreated);
						if (created == cmpCreated && capacity == volume.Capacity()) {
							volumes->push_back(volume);
						}
					}
			}
		};
	};

	return B_OK;	
};
void
PartitionsPage::_FillPartitionsView(BView* view)
{
	// show | name | type | size | path

	int32 rowNumber = 0;

	BMessage message;
	for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK;
			i++, rowNumber++) {
		// get partition data
		bool show;
		BString name;
		BString type;
		BString path;
		int64 size;
		message.FindBool("show", &show);
		message.FindString("name", &name);
		message.FindString("type", &type);
		message.FindString("path", &path);
		message.FindInt64("size", &size);

		// check box
		BCheckBox* checkBox = new BCheckBox("show", "",
			_CreateControlMessage(kMessageShow, i));
		if (show)
			checkBox->SetValue(1);

		// name
		BTextControl* nameControl = new BTextControl("name", "",
			name.String(), _CreateControlMessage(kMessageName, i));
		nameControl->SetExplicitMinSize(BSize(StringWidth("WWWWWWWWWWWWWW"),
			B_SIZE_UNSET));

		// size
		BString sizeText;
		_CreateSizeText(size, &sizeText);
		sizeText << ", " << type.String();
		BStringView* typeView = new BStringView("type", sizeText.String());
		typeView->SetExplicitAlignment(
			BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET));

		// path
		BStringView* pathView = new BStringView("path", path.String());
		pathView->SetExplicitAlignment(
			BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET));

		if (rowNumber > 0) {
			BLayoutBuilder::Grid<>((BGridLayout*)view->GetLayout())
				.Add(new BSeparatorView(B_HORIZONTAL), 0, rowNumber, 4, 1)
				.SetRowWeight(rowNumber, 0);
			rowNumber++;
		}

		BLayoutBuilder::Grid<>((BGridLayout*)view->GetLayout())
			.Add(checkBox, 0, rowNumber, 1, 2)
			.Add(nameControl, 1, rowNumber, 1, 2)
			.Add(BSpaceLayoutItem::CreateHorizontalStrut(10), 2, rowNumber)
			.Add(typeView, 3, rowNumber)
			.Add(pathView, 3, rowNumber + 1)
			.SetRowWeight(rowNumber + 1, 1);
		rowNumber++;
	}
}
예제 #16
0
void
NotifyList::MouseDown (BPoint myPoint)
{
  BMessage *msg (Window()->CurrentMessage());
  int32 selected (IndexOf (myPoint));
  if (selected >= 0)
  {
    BMessage *inputMsg (Window()->CurrentMessage());
    int32 mousebuttons (0),
          keymodifiers (0);
    
    NotifyListItem *item ((NotifyListItem *)ItemAt(selected));
    if (!item)
      return;
    
    inputMsg->FindInt32 ("buttons", &mousebuttons);
    inputMsg->FindInt32 ("modifiers", &keymodifiers);
    
    bigtime_t sysTime;
    msg->FindInt64 ("when", &sysTime);
    uint16 clicks = CheckClickCount (myPoint, fLastClick, sysTime, fLastClickTime, fClickCount) % 3;
    
    // slight kludge to make sure the expand/collapse triangles behave how they should
    // -- needed since OutlineListView's Expand/Collapse-related functions are not virtual
    if (mousebuttons == B_PRIMARY_MOUSE_BUTTON)
    {
      if (((clicks % 2) == 0) && item->GetState())
      {
        // react to double click by creating a new messageagent or selecting
        // an existing one (use /query logic in parsecmd)
        BString data (item->Text());
        data.Prepend ("/QUERY ");
        BMessage submitMsg (M_SUBMIT);
        submitMsg.AddString ("input", data.String());
        submitMsg.AddBool ("history", false);
        // don't clear in case user has something typed in text control
        submitMsg.AddBool ("clear", false);
        WindowListItem *winItem ((WindowListItem *)vision_app->pClientWin()->pWindowList()->ItemAt(
          vision_app->pClientWin()->pWindowList()->CurrentSelection()));
        if (winItem)
        {
          BMessenger msgr (winItem->pAgent());
          if (msgr.IsValid())
            msgr.SendMessage(&submitMsg);
        }
      }
      else
        Select (selected);
    }
    
    if ((keymodifiers & B_SHIFT_KEY)  == 0
    && (keymodifiers & B_OPTION_KEY)  == 0
    && (keymodifiers & B_COMMAND_KEY) == 0
    && (keymodifiers & B_CONTROL_KEY) == 0)
    {
      if (mousebuttons == B_SECONDARY_MOUSE_BUTTON)
      {
        if (item)
        {
          if(!item->IsSelected())
            Select (IndexOf (myPoint));

          BuildPopUp();

          fMyPopUp->Go (
            ConvertToScreen (myPoint),
            true,
            true,
            ConvertToScreen (ItemFrame (selected)),
            true);
        }
      }
    }
  }

}
void
EventDispatcher::_EventLoop()
{
	BMessage* event;
	while (fStream->GetNextEvent(&event)) {
		BAutolock _(this);
		fLastUpdate = system_time();

		EventTarget* current = NULL;
		EventTarget* previous = NULL;
		bool pointerEvent = false;
		bool keyboardEvent = false;
		bool addedTokens = false;

		switch (event->what) {
			case kFakeMouseMoved:
				_SendFakeMouseMoved(event);
				break;
			case B_MOUSE_MOVED:
			{
				BPoint where;
				if (event->FindPoint("where", &where) == B_OK)
					fLastCursorPosition = where;

				if (fDraggingMessage)
					event->AddMessage("be:drag_message", &fDragMessage);

				if (!HasCursorThread()) {
					// There is no cursor thread, we need to move the cursor
					// ourselves
					BAutolock _(fCursorLock);

					if (fHWInterface != NULL) {
						fHWInterface->MoveCursorTo(fLastCursorPosition.x,
							fLastCursorPosition.y);
					}
				}

				// This is for B_NO_POINTER_HISTORY - we always want the
				// latest mouse moved event in the queue only
				if (fNextLatestMouseMoved == NULL)
					fNextLatestMouseMoved = fStream->PeekLatestMouseMoved();
				else if (fNextLatestMouseMoved != event) {
					// Drop older mouse moved messages if the server is lagging
					// too much (if the message is older than 100 msecs)
					bigtime_t eventTime;
					if (event->FindInt64("when", &eventTime) == B_OK) {
						if (system_time() - eventTime > 100000)
							break;
					}
				}

				// supposed to fall through
			}
			case B_MOUSE_DOWN:
			case B_MOUSE_UP:
			{
#ifdef TRACE_EVENTS
				if (event->what != B_MOUSE_MOVED)
					printf("mouse up/down event, previous target = %p\n", fPreviousMouseTarget);
#endif
				pointerEvent = true;

				if (fMouseFilter == NULL)
					break;

				EventTarget* mouseTarget = fPreviousMouseTarget;
				int32 viewToken = B_NULL_TOKEN;
				if (fMouseFilter->Filter(event, &mouseTarget, &viewToken,
						fNextLatestMouseMoved) == B_SKIP_MESSAGE) {
					// this is a work-around if the wrong B_MOUSE_UP
					// event is filtered out
					if (event->what == B_MOUSE_UP
						&& event->FindInt32("buttons") == 0) {
						fSuspendFocus = false;
						_RemoveTemporaryListeners();
					}
					break;
				}

				int32 buttons;
				if (event->FindInt32("buttons", &buttons) == B_OK)
					fLastButtons = buttons;
				else
					fLastButtons = 0;

				// The "where" field will be filled in by the receiver
				// (it's supposed to be expressed in local window coordinates)
				event->RemoveName("where");
				event->AddPoint("screen_where", fLastCursorPosition);

				if (event->what == B_MOUSE_MOVED
					&& fPreviousMouseTarget != NULL
					&& mouseTarget != fPreviousMouseTarget) {
					// Target has changed, we need to notify the previous target
					// that the mouse has exited its views
					addedTokens = _AddTokens(event, fPreviousMouseTarget,
						B_POINTER_EVENTS);
					if (addedTokens)
						_SetFeedFocus(event);

					_SendMessage(fPreviousMouseTarget->Messenger(), event,
						kMouseTransitImportance);
					previous = fPreviousMouseTarget;
				}

				current = fPreviousMouseTarget = mouseTarget;

				if (current != NULL) {
					int32 focusView = viewToken;
					addedTokens |= _AddTokens(event, current, B_POINTER_EVENTS,
						fNextLatestMouseMoved, &focusView);

					bool noPointerHistoryFocus = focusView != viewToken;

					if (viewToken != B_NULL_TOKEN)
						event->AddInt32("_view_token", viewToken);

					if (addedTokens && !noPointerHistoryFocus)
						_SetFeedFocus(event);
					else if (noPointerHistoryFocus) {
						// No tokens were added or the focus shouldn't get a
						// mouse moved
						break;
					}

					_SendMessage(current->Messenger(), event,
						event->what == B_MOUSE_MOVED
							? kMouseMovedImportance : kStandardImportance);
				}
				break;
			}

			case B_KEY_DOWN:
			case B_KEY_UP:
			case B_UNMAPPED_KEY_DOWN:
			case B_UNMAPPED_KEY_UP:
			case B_MODIFIERS_CHANGED:
			case B_INPUT_METHOD_EVENT:
				ETRACE(("key event, focus = %p\n", fFocus));

				if (fKeyboardFilter != NULL
					&& fKeyboardFilter->Filter(event, &fFocus) == B_SKIP_MESSAGE)
					break;

				keyboardEvent = true;

				if (fFocus != NULL && _AddTokens(event, fFocus,
						B_KEYBOARD_EVENTS)) {
					// if tokens were added, we need to explicetly suspend
					// focus in the event - if not, the event is simply not
					// forwarded to the target
					addedTokens = true;

					if (!fSuspendFocus)
						_SetFeedFocus(event);
				}

				// supposed to fall through

			default:
				// TODO: the keyboard filter sets the focus - ie. no other
				//	focus messages that go through the event dispatcher can
				//	go through.
				if (event->what == B_MOUSE_WHEEL_CHANGED)
					current = fPreviousMouseTarget;
				else
					current = fFocus;

				if (current != NULL && (!fSuspendFocus || addedTokens)) {
					_SendMessage(current->Messenger(), event,
						kStandardImportance);
				}
				break;
		}

		if (keyboardEvent || pointerEvent) {
			// send the event to the additional listeners

			if (addedTokens) {
				_RemoveTokens(event);
				_UnsetFeedFocus(event);
			}
			if (pointerEvent) {
				// this is added in the Desktop mouse processing
				// but it's only intended for the focus view
				event->RemoveName("_view_token");
			}

			for (int32 i = fTargets.CountItems(); i-- > 0;) {
				EventTarget* target = fTargets.ItemAt(i);

				// We already sent the event to the all focus and last focus
				// tokens
				if (current == target || previous == target)
					continue;

				// Don't send the message if there are no tokens for this event
				if (!_AddTokens(event, target,
						keyboardEvent ? B_KEYBOARD_EVENTS : B_POINTER_EVENTS,
						event->what == B_MOUSE_MOVED
							? fNextLatestMouseMoved : NULL))
					continue;

				if (!_SendMessage(target->Messenger(), event,
						event->what == B_MOUSE_MOVED
							? kMouseMovedImportance : kListenerImportance)) {
					// the target doesn't seem to exist anymore, let's remove it
					fTargets.RemoveItemAt(i);
				}
			}

			if (event->what == B_MOUSE_UP && fLastButtons == 0) {
				// no buttons are pressed anymore
				fSuspendFocus = false;
				_RemoveTemporaryListeners();
				if (fDraggingMessage)
					_DeliverDragMessage();
			}
		}

		if (fNextLatestMouseMoved == event)
			fNextLatestMouseMoved = NULL;
		delete event;
	}

	// The loop quit, therefore no more events are coming from the input
	// server, it must have died. Unset ourselves and notify the desktop.
	fThread = -1;
		// Needed to avoid problems with wait_for_thread in _Unset()
	_Unset();

	if (fDesktop)
		fDesktop->PostMessage(AS_EVENT_STREAM_CLOSED);
}
예제 #18
0
status_t
InstalledPackageInfo::SetTo(const char *packageName, const char *version, 
		bool create)
{
	_ClearItemList();
	fCreate = create;
	fStatus = B_NO_INIT;
	fVersion = version;

	if (!packageName)
		return fStatus;

	BPath configPath;
	if (find_directory(B_USER_CONFIG_DIRECTORY, &configPath) != B_OK) {
		fStatus = B_ERROR;
		return fStatus;
	}
	
	if (fPathToInfo.SetTo(configPath.Path(), kPackagesDir) != B_OK) {
		fStatus = B_ERROR;
		return fStatus;
	}
	
	// Check whether the directory exists
	BDirectory packageDir(fPathToInfo.Path());
	fStatus = packageDir.InitCheck();
	if (fStatus == B_ENTRY_NOT_FOUND) {
		// If not, create it
		packageDir.SetTo(configPath.Path());
		if (packageDir.CreateDirectory(kPackagesDir, &packageDir) != B_OK) {
			fStatus = B_ERROR;
			return fStatus;
		}
	}

	BString filename = packageName;
	filename << version << ".pdb";
	if (fPathToInfo.Append(filename.String()) != B_OK) {
		fStatus = B_ERROR;
		return fStatus;
	}

	BFile package(fPathToInfo.Path(), B_READ_ONLY);
	fStatus = package.InitCheck();
	if (fStatus == B_OK) {
		// The given package exists, so we can unflatten the data to a message
		// and then pass it further
		BMessage info;
		if (info.Unflatten(&package) != B_OK || info.what != P_PACKAGE_INFO) {
			fStatus = B_ERROR;
			return fStatus;
		}

		int32 count;
		fStatus = info.FindString("package_name", &fName);
		fStatus |= info.FindString("package_desc", &fDescription);
		fStatus |= info.FindString("package_version", &fVersion);
		int64 spaceNeeded = 0;
		fStatus |= info.FindInt64("package_size", &spaceNeeded);
		fSpaceNeeded = static_cast<uint64>(spaceNeeded);
		fStatus |= info.FindInt32("file_count", &count);
		if (fStatus != B_OK) {
			fStatus = B_ERROR;
			return fStatus;
		}

		int32 i;
		BString itemPath;
		for (i = 0; i < count; i++) {
			if (info.FindString("items", i, &itemPath) != B_OK) {
				fStatus = B_ERROR;
				return fStatus;
			}
			fInstalledItems.AddItem(new BString(itemPath)); // Or maybe BPath better?
		}
		fIsUpToDate = true;
	}
	else if (fStatus == B_ENTRY_NOT_FOUND) {
		if (create) {
			fStatus = B_OK;
			fIsUpToDate = false;
		}
	}

	return fStatus;
}
예제 #19
0
status_t
SATGroup::RestoreGroup(const BMessage& archive, StackAndTile* sat)
{
	// create new group
	SATGroup* group = new (std::nothrow)SATGroup;
	if (!group)
		return B_NO_MEMORY;
	BReference<SATGroup> groupRef;
	groupRef.SetTo(group, true);

	int32 nHTabs, nVTabs;
	status_t status;
	status = archive.FindInt32("htab_count", &nHTabs);
	if (status != B_OK)
		return status;
	status = archive.FindInt32("vtab_count", &nVTabs);
	if (status != B_OK)
		return status;

	vector<BReference<Tab> > tempHTabs;
	for (int i = 0; i < nHTabs; i++) {
		BReference<Tab> tab = group->_AddHorizontalTab();
		if (!tab)
			return B_NO_MEMORY;
		tempHTabs.push_back(tab);
	}
	vector<BReference<Tab> > tempVTabs;
	for (int i = 0; i < nVTabs; i++) {
		BReference<Tab> tab = group->_AddVerticalTab();
		if (!tab)
			return B_NO_MEMORY;
		tempVTabs.push_back(tab);
	}

	BMessage areaArchive;
	for (int32 i = 0; archive.FindMessage("area", i, &areaArchive) == B_OK;
		i++) {
		uint32 leftTab, rightTab, topTab, bottomTab;
		if (areaArchive.FindInt32("left_tab", (int32*)&leftTab) != B_OK
			|| areaArchive.FindInt32("right_tab", (int32*)&rightTab) != B_OK
			|| areaArchive.FindInt32("top_tab", (int32*)&topTab) != B_OK
			|| areaArchive.FindInt32("bottom_tab", (int32*)&bottomTab) != B_OK)
			return B_ERROR;

		if (leftTab >= tempVTabs.size() || rightTab >= tempVTabs.size())
			return B_BAD_VALUE;
		if (topTab >= tempHTabs.size() || bottomTab >= tempHTabs.size())
			return B_BAD_VALUE;

		Tab* left = tempVTabs[leftTab];
		Tab* right = tempVTabs[rightTab];
		Tab* top = tempHTabs[topTab];
		Tab* bottom = tempHTabs[bottomTab];

		// adding windows to area
		uint64 windowId;
		SATWindow* prevWindow = NULL;
		for (int32 i = 0; areaArchive.FindInt64("window", i,
			(int64*)&windowId) == B_OK; i++) {
			SATWindow* window = sat->FindSATWindow(windowId);
			if (!window)
				continue;

			if (prevWindow == NULL) {
				if (!group->AddWindow(window, left, top, right, bottom))
					continue;
				prevWindow = window;
			} else {
				if (!prevWindow->StackWindow(window))
					continue;
				prevWindow = window;
			}
		}
	}
	return B_OK;
}