Example #1
0
void ObservableHandler::_handleAddObserver(
	BMessage*								message) {

#if DEBUG
	BLooper* l = Looper();
	ASSERT(l);
	ASSERT(l->IsLocked());
#endif
	BMessage reply;

	BMessenger observer;
	status_t err = message->FindMessenger(
		"observer", &observer);
	if(err < B_OK) {
		PRINT((
			"* ObservableHandler::_handleAddObserver(): no observer specified!\n"));
		// send reply? +++++
		return;
	}

	if(m_released) {
		// already quitting
		reply.what = M_BAD_TARGET;
		reply.AddMessenger("target", BMessenger(this));
		reply.AddMessenger("observer", observer);
		message->SendReply(&reply);
		
		return;
	}
	else if(IndexOfTarget(observer.Target(0)) != -1) {
		// observer already added
		reply.what = M_BAD_OBSERVER;
		reply.AddMessenger("target", BMessenger(this));
		reply.AddMessenger("observer", observer);
		message->SendReply(&reply);
		
		return;
	}	

	// valid observer given

	// add it
	err = AddTarget(observer.Target(0));
	ASSERT(err == B_OK);

	// call hook
	observerAdded(observer);
}
Example #2
0
BMidiRoster::BMidiRoster()
{
	TRACE(("BMidiRoster::BMidiRoster"))

	// While our constructor is executing, some function may 
	// call MidiRoster() again, which causes an endless loop. 
	// To prevent this, we immediately fill in "roster"; now
	// subsequent calls to MidiRoster() won't mess up things.

	roster = this;

	fLooper = new BMidiRosterLooper();

	if (!fLooper->Init(this)) 
		return;

	BMessage msg;
	msg.what = MSG_REGISTER_APP;
	msg.AddMessenger("midi:messenger", BMessenger(fLooper));
	fServer = new BMessenger(MIDI_SERVER_SIGNATURE);

	if (fServer->SendMessage(&msg, fLooper, TIMEOUT) != B_OK) {
		WARN("Cannot send request to midi_server"); 
		return;
	}	

	// Although unlikely, we may receive the midi_server's
	// "app registered" reply before we lock the semaphore.
	// In that case, BMidiRosterLooper's MessageReceived()
	// will bump the semaphore count, and our acquire_sem() 
	// can grab the semaphore safely (without blocking).

	acquire_sem(fLooper->fInitLock);
}
Example #3
0
char *run_template_selector(BMessage msg_to_deliver, BMessenger target)
{
TemplateLooper *looper;
BMessenger *messenger;
BFilePanel *panel;
BMessage *msg;

	// create looper to deliver it to
	looper = new TemplateLooper();
	looper->Run();
	messenger = new BMessenger(NULL, looper);

	msg = new BMessage(M_TEMPLATE_SELECT);
	msg->AddMessage("message", &msg_to_deliver);
	msg->AddMessenger("target", target);
	
	// set starting dir to that of template directory
	entry_ref start_dir;
	GetTemplateDirectoryRef(&start_dir);

	// create panel
	panel = new BFilePanel(B_OPEN_PANEL, messenger, &start_dir, 0, false, msg, NULL, true);
	panel->Window()->SetTitle("Select Template");
	
	// and away we go
	if (TemplatePanel) delete TemplatePanel;
	TemplatePanel = panel;
	
	panel->Show();
}
Example #4
0
int32 SLooper::FinderThread() { 
        status_t ignored; 

        BMessage msg; 

        // add a BMessenger into msg 
        BMessenger myMessenger(this,this, &ignored); 
        msg.AddMessenger("messageTarget", myMessenger); 
        
        //Flatten it 
        ssize_t messengerBufferLength = msg.FlattenedSize(); 
        char *messengerBuffer = new char[messengerBufferLength]; 
        msg.Flatten(messengerBuffer, messengerBufferLength); 

        // wait for requests to come in 
        port_id toRespondTo; 

        while (read_port(finder, &ignored, &toRespondTo, sizeof(toRespondTo))>=0) { 
                // send requests back to the port ID we were given 
                write_port(toRespondTo, 0, messengerBuffer, messengerBufferLength); 
        } 

        delete messengerBuffer; 
        return 0; 
} 
Example #5
0
void
CannaLooper::SendInputStarted()
{
	BMessage* msg = new BMessage(B_INPUT_METHOD_EVENT);
	msg->AddInt32("be:opcode", B_INPUT_METHOD_STARTED);
	msg->AddMessenger("be:reply_to", BMessenger(NULL, this));
	EnqueueMessage(msg);

	SERIAL_PRINT(("CannaLooper: B_INPUT_METHOD_STARTED has been sent\n"));
}
Example #6
0
void ObservableLooper::_handleRemoveObserver(
    BMessage*								message) {

//	PRINT(("ObservableLooper::_handleRemoveObserver():\n"
//		"  %ld targets\n", CountTargets()));
    BMessage reply;

    BMessenger observer;
    status_t err = message->FindMessenger(
                       "observer", &observer);
    if(err < B_OK) {
        PRINT((
                  "* ObservableLooper::_handleRemoveObserver(): no observer specified!\n"));
        // send reply? +++++
        return;
    }

    // at this point, a reply of some sort will be sent
    reply.AddMessenger("target", BMessenger(this));
    reply.AddMessenger("observer", observer);

    int32 index = IndexOfTarget(observer.Target(0));
    if(index == -1) {
        reply.what = M_BAD_OBSERVER;
    }
    else {
        RemoveTarget(index);
        reply.what = M_OBSERVER_REMOVED;
    }

    message->SendReply(&reply);

    // call hook
    observerRemoved(observer);

    // time to shut down?
    if(m_quitting && !CountTargets()) {
        releaseComplete();
        BLooper::Quit();
    }
}
Example #7
0
void ObservableLooper::_handleAddObserver(
    BMessage*								message) {

    BMessage reply;

    BMessenger observer;
    status_t err = message->FindMessenger(
                       "observer", &observer);
    if(err < B_OK) {
        PRINT((
                  "* ObservableLooper::_handleAddObserver(): no observer specified!\n"));
        // send reply? +++++
        return;
    }

    // at this point, a reply of some sort will be sent
    reply.AddMessenger("target", BMessenger(this));
    reply.AddMessenger("observer", observer);

    if(m_quitting) {
        // already quitting
        reply.what = M_BAD_TARGET;
    }
    else if(IndexOfTarget(observer.Target(0)) != -1) {
        // observer already added
        reply.what = M_BAD_OBSERVER;
    }
    else {
        // add it
        err = AddTarget(observer.Target(0));
        ASSERT(err == B_OK);
        reply.what = M_OBSERVER_ADDED;
    }

    // send reply
    message->SendReply(&reply);

    // call hook
    observerAdded(observer);
}
Example #8
0
void ObservableHandler::_handleRemoveObserver(
	BMessage*								message) {

#if DEBUG
	BLooper* l = Looper();
	ASSERT(l);
	ASSERT(l->IsLocked());
#endif
	BMessage reply;

	BMessenger observer;
	status_t err = message->FindMessenger(
		"observer", &observer);
	if(err < B_OK) {
		PRINT((
			"* ObservableHandler::_handleRemoveObserver(): no observer specified!\n"));
		// send reply? +++++
		return;
	}

	int32 index = IndexOfTarget(observer.Target(0));
	if(index == -1) {
		reply.what = M_BAD_OBSERVER;
		
		reply.AddMessenger("target", BMessenger(this));
		reply.AddMessenger("observer", observer);
		message->SendReply(&reply);
		return;
	}
	
	// valid observer given; remove it & call notification hook
	RemoveTarget(index);
	observerRemoved(observer);
	
	// time to shut down?
	if(m_released && !CountTargets()) {
		releaseComplete();
		delete this; // BOOM!
	}
}
void
EventDispatcher::SendFakeMouseMoved(EventTarget& target, int32 viewToken)
{
	if (fStream == NULL)
		return;

	BMessage* fakeMove = new BMessage(kFakeMouseMoved);
	if (fakeMove == NULL)
		return;

	fakeMove->AddMessenger("target", target.Messenger());
	fakeMove->AddInt32("view_token", viewToken);

	fStream->InsertEvent(fakeMove);
}
Example #10
0
void DCCConnect::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
	case M_DCC_STOP_BUTTON: {
		Stopped();
	} break;

	case M_DCC_UPDATE_STATUS: {
		fLabel->SetText(msg->FindString("text"));
	} break;

	case M_DCC_GET_CONNECT_DATA: {
		BMessage reply;
		reply.AddString("port", fPort.String());
		reply.AddString("ip", fIp.String());
		reply.AddString("name", fFileName.String());
		reply.AddString("nick", fNick.String());
		reply.AddString("size", fSize.String());
		DCCReceive* recview(dynamic_cast<DCCReceive*>(this));
		if (recview != NULL) reply.AddBool("resume", recview->fResume);
		DCCSend* sendview(dynamic_cast<DCCSend*>(this));
		if (sendview != NULL) reply.AddMessenger("caller", sendview->fCaller);
		msg->SendReply(&reply);
	} break;

	case M_DCC_GET_RESUME_POS: {
		BMessage reply;
		DCCSend* sendview(dynamic_cast<DCCSend*>(this));
		if (sendview != NULL) reply.AddInt32("pos", sendview->fPos);
		msg->SendReply(&reply);
	} break;

	case M_DCC_UPDATE_TRANSFERRED: {
		fTotalTransferred = msg->FindInt32("transferred");
	} break;

	case M_DCC_UPDATE_AVERAGE: {
		fFinalRateAverage = msg->FindInt32("average");
	} break;

	default:
		BView::MessageReceived(msg);
	}
}
Example #11
0
void
IconView::_AddOrEditIcon()
{
	BMessage message;
	if (fHasRef && fType.Type() == NULL) {
		// in ref mode, Icon-O-Matic can change the icon directly, and
		// we'll pick it up via node monitoring
		message.what = B_REFS_RECEIVED;
		message.AddRef("refs", &fRef);
	} else {
		// in static or MIME type mode, Icon-O-Matic needs to return the
		// buffer it changed once its done
		message.what = B_EDIT_ICON_DATA;
		message.AddMessenger("reply to", BMessenger(this));

		::Icon* icon = fIconData;
		if (icon == NULL) {
			icon = new ::Icon();
			if (fHasRef)
				icon->SetTo(fRef, fType.Type());
			else
				icon->SetTo(fType);
		}

		if (icon->HasData()) {
			uint8* data;
			size_t size;
			if (icon->GetData(&data, &size) == B_OK) {
				message.AddData("icon data", B_VECTOR_ICON_TYPE, data, size);
				free(data);
			}

			// TODO: somehow figure out how names of objects in the icon
			// can be preserved. Maybe in a second (optional) attribute
			// where ever a vector icon attribute is present?
		}

		if (icon != fIconData)
			delete icon;
	}

	be_roster->Launch("application/x-vnd.haiku-icon_o_matic", &message);
}
Example #12
0
// MessageReceived
void
NetFSServer::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case NETFS_REQUEST_GET_MESSENGER:
		{
			// for the time being we process all requests here
			BMessage reply;
			reply.AddMessenger("messenger", be_app_messenger);
			_SendReply(message, &reply);
			break;
		}

		case NETFS_REQUEST_ADD_USER:
		{
			// get user name and password
			const char* user;
			const char* password;
			if (message->FindString("user", &user) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}
			if (message->FindString("password", &password) != B_OK)
				password = NULL;

			// add the user
			status_t error = fSecurityContext->AddUser(user, password);
			_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_REMOVE_USER:
		{
			// get user name
			const char* userName;
			if (message->FindString("user", &userName) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			// remove the user
			User* user;
			status_t error = fSecurityContext->RemoveUser(userName, &user);
			if (error == B_OK) {
				// propagate the information to the client connections
				AutoLocker<Locker> _(fLock);
				for (int32 i = 0;
					 ClientConnection* connection
					 	= (ClientConnection*)fClientConnections.ItemAt(i);
					 i++) {
					connection->UserRemoved(user);
				}

				user->RemoveReference();
			}

			_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_GET_USERS:
		{
			// get the users
			BMessage reply;
			BMessage users;
			status_t error = fSecurityContext->GetUsers(&users);
			if (error == B_OK)
				error = reply.AddMessage("users", &users);

			if (error == B_OK)
				_SendReply(message, &reply);
			else
				_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_GET_USER_STATISTICS:
		{
			// get user name
			const char* userName;
			if (message->FindString("user", &userName) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			// get the user
			User* user = fSecurityContext->FindUser(userName);
			if (!user) {
				_SendReply(message, B_ENTRY_NOT_FOUND);
				break;
			}
			Reference<User> userReference(user, true);

			// get the statistics
			BMessage statistics;
			status_t error = StatisticsManager::GetDefault()
				->GetUserStatistics(user, &statistics);

			// prepare the reply
			BMessage reply;
			if (error == B_OK)
				error = reply.AddMessage("statistics", &statistics);

			// send the reply
			if (error == B_OK)
				_SendReply(message, &reply);
			else
				_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_ADD_SHARE:
		{
			// get share name and path
			const char* share;
			const char* path;
			if (message->FindString("share", &share) != B_OK
				|| message->FindString("path", &path) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			// add the share
			status_t error = fSecurityContext->AddShare(share, path);

			if (error == B_OK)
				_ServerInfoUpdated();

			_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_REMOVE_SHARE:
		{
			// get share name
			const char* shareName;
			if (message->FindString("share", &shareName) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			// remove the share
			Share* share;
			status_t error = fSecurityContext->RemoveShare(shareName, &share);
			if (error == B_OK) {
				// propagate the information to the client connections
				AutoLocker<Locker> _(fLock);
				for (int32 i = 0;
					 ClientConnection* connection
					 	= (ClientConnection*)fClientConnections.ItemAt(i);
					 i++) {
					connection->ShareRemoved(share);
				}

				share->RemoveReference();
			}

			if (error == B_OK)
				_ServerInfoUpdated();

			_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_GET_SHARES:
		{
			// get the shares
			BMessage reply;
			BMessage shares;
			status_t error = fSecurityContext->GetShares(&shares);
			if (error == B_OK)
				error = reply.AddMessage("shares", &shares);

			if (error == B_OK)
				_SendReply(message, &reply);
			else
				_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_GET_SHARE_USERS:
		{
			// get share name
			const char* shareName;
			if (message->FindString("share", &shareName) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			AutoLocker<Locker> securityContextLocker(fSecurityContext);

			// get the share
			Share* share = fSecurityContext->FindShare(shareName);
			if (!share) {
				_SendReply(message, B_ENTRY_NOT_FOUND);
				break;
			}
			Reference<Share> shareReference(share, true);

			// get all users
			BMessage allUsers;
			status_t error = fSecurityContext->GetUsers(&allUsers);
			if (error != B_OK) {
				_SendReply(message, error);
				break;
			}

			// filter the users with mount permission
			BMessage users;
			const char* userName;
			for (int32 i = 0;
				 allUsers.FindString("users", i, &userName) == B_OK;
				 i++) {
				if (User* user = fSecurityContext->FindUser(userName)) {
					// get the user's permissions
					Permissions permissions = fSecurityContext
						->GetNodePermissions(share->GetPath(), user);
					user->RemoveReference();

					// add the user, if they have the permission to mount the
					// share
					if (permissions.ImpliesMountSharePermission()) {
						error = users.AddString("users", userName);
						if (error != B_OK) {
							_SendReply(message, error);
							break;
						}
					}
				}
			}

			securityContextLocker.Unlock();

			// prepare the reply
			BMessage reply;
			if (error == B_OK)
				error = reply.AddMessage("users", &users);

			// send the reply
			if (error == B_OK)
				_SendReply(message, &reply);
			else
				_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_GET_SHARE_STATISTICS:
		{
			// get share name
			const char* shareName;
			if (message->FindString("share", &shareName) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			// get the share
			Share* share = fSecurityContext->FindShare(shareName);
			if (!share) {
				_SendReply(message, B_ENTRY_NOT_FOUND);
				break;
			}
			Reference<Share> shareReference(share, true);

			// get the statistics
			BMessage statistics;
			status_t error = StatisticsManager::GetDefault()
				->GetShareStatistics(share, &statistics);

			// prepare the reply
			BMessage reply;
			if (error == B_OK)
				error = reply.AddMessage("statistics", &statistics);

			// send the reply
			if (error == B_OK)
				_SendReply(message, &reply);
			else
				_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_SET_USER_PERMISSIONS:
		{
			// get share and user name, and the permissions
			const char* shareName;
			const char* userName;
			uint32 permissions;
			if (message->FindString("share", &shareName) != B_OK
				|| message->FindString("user", &userName) != B_OK
				|| message->FindInt32("permissions", (int32*)&permissions)
					!= B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			// get the share and the user
			Share* share = fSecurityContext->FindShare(shareName);
			User* user = fSecurityContext->FindUser(userName);
			Reference<Share> shareReference(share);
			Reference<User> userReference(user);
			if (!share || !user) {
				_SendReply(message, B_ENTRY_NOT_FOUND);
				break;
			}

			// set the permissions
			status_t error = B_OK;
			if (permissions == 0) {
				fSecurityContext->ClearNodePermissions(share->GetPath(), user);
			} else {
				error = fSecurityContext->SetNodePermissions(share->GetPath(),
					user, permissions);
			}

			if (error == B_OK) {
				// propagate the information to the client connections
				AutoLocker<Locker> _(fLock);
				for (int32 i = 0;
					 ClientConnection* connection
					 	= (ClientConnection*)fClientConnections.ItemAt(i);
					 i++) {
					connection->UserPermissionsChanged(share, user,
						permissions);
				}
			}

			_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_GET_USER_PERMISSIONS:
		{
			// get share and user name
			const char* shareName;
			const char* userName;
			if (message->FindString("share", &shareName) != B_OK
				|| message->FindString("user", &userName) != B_OK) {
				_SendReply(message, B_BAD_VALUE);
				break;
			}

			// get the share and the user
			Share* share = fSecurityContext->FindShare(shareName);
			User* user = fSecurityContext->FindUser(userName);
			Reference<Share> shareReference(share);
			Reference<User> userReference(user);
			if (!share || !user) {
				_SendReply(message, B_ENTRY_NOT_FOUND);
				break;
			}

			// get the permissions
			Permissions permissions = fSecurityContext->GetNodePermissions(
				share->GetPath(), user);

			// prepare the reply
			BMessage reply;
			status_t error = reply.AddInt32("permissions",
				(int32)permissions.GetPermissions());

			// send it
			if (error == B_OK)
				_SendReply(message, &reply);
			else
				_SendReply(message, error);
			break;
		}

		case NETFS_REQUEST_SAVE_SETTINGS:
		{
			status_t error = _SaveSettings();

			// send a reply
			_SendReply(message, error);
			break;
		}
	}
}
Example #13
0
void
TTracker::RefsReceived(BMessage *message)
{
	OpenSelector selector = kOpen;
	if (message->HasInt32("launchUsingSelector"))
		selector = kRunOpenWithWindow;

	entry_ref handlingApp;
	if (message->FindRef("handler", &handlingApp) == B_OK)
		selector = kOpenWith;

	int32 count;
	uint32 type;
	message->GetInfo("refs", &type, &count);

	switch (selector) {
		case kRunOpenWithWindow:
			OpenContainerWindow(0, message, selector);
				// window adopts model
			break;

		case kOpenWith:
			{
				// Open With resulted in passing refs and a handler, open the files
				// with the handling app
				message->RemoveName("handler");

				// have to find out if handling app is the Tracker
				// if it is, just pass it to the active Tracker, no matter which Tracker
				// was chosen to handle the refs
				char signature[B_MIME_TYPE_LENGTH];
				signature[0] = '\0';
				{
					BFile handlingNode(&handlingApp, O_RDONLY);
					BAppFileInfo appInfo(&handlingNode);
					appInfo.GetSignature(signature);
				}

				if (strcasecmp(signature, kTrackerSignature) != 0) {
					// handling app not Tracker, pass entries to the apps RefsReceived
					TrackerLaunch(&handlingApp, message, true);
					break;
				}
				// fall thru, opening refs by the Tracker, as if they were double clicked
			}

		case kOpen:
			{
				// copy over "Poses" messenger so that refs received recipients know
				// where the open came from
				BMessage *bundleThis = NULL;
				BMessenger messenger;
				if (message->FindMessenger("TrackerViewToken", &messenger) == B_OK) {
					bundleThis = new BMessage();
					bundleThis->AddMessenger("TrackerViewToken", messenger);
				}

				for (int32 index = 0; index < count; index++) {
					entry_ref ref;
					message->FindRef("refs", index, &ref);

					const node_ref *nodeToClose = NULL;
					const node_ref *nodeToSelect = NULL;
					ssize_t numBytes;

					message->FindData("nodeRefsToClose", B_RAW_TYPE, index,
						(const void **)&nodeToClose, &numBytes);
					message->FindData("nodeRefToSelect", B_RAW_TYPE, index,
						(const void **)&nodeToSelect, &numBytes);

					OpenRef(&ref, nodeToClose, nodeToSelect, selector, bundleThis);
				}

				delete bundleThis;
				break;
			}
	}
}
Example #14
0
void VisionApp::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
	case M_ABOUT_CLOSE: {
		fAboutWin = 0;
		if (fShuttingDown) PostMessage(B_QUIT_REQUESTED);
	} break;

	case M_SETUP_SHOW: {
		if (fSetupWin)
			fSetupWin->Activate();
		else {
			fSetupWin = new SetupWindow();
			fSetupWin->Show();
		}
	} break;

	case M_SETUP_CLOSE: {
		SaveSettings();
		fSetupWin = 0;
		if (fClientWin == NULL) PostMessage(B_QUIT_REQUESTED);
	} break;

	case M_PREFS_SHOW: {
		if (fPrefsWin)
			fPrefsWin->Activate();
		else {
			fPrefsWin = new PrefsWindow();
			fPrefsWin->Show();
		}
	} break;

	case M_PREFS_CLOSE: {
		SaveSettings();
		fPrefsWin = 0;
	} break;

	case M_NETWORK_SHOW: {
		if (fNetWin)
			fNetWin->Activate();
		else {
			fNetWin = new NetworkWindow();
			fNetWin->Show();
		}
	} break;

	case M_NETWORK_CLOSE: {
		SaveSettings();
		fNetWin = 0;
	} break;

	case M_CONNECT_NETWORK: {
		BRect clientWinRect(GetRect("clientWinRect"));
		BMessage netData = GetNetwork(msg->FindString("network"));

		// sanity check
		if (netData.IsEmpty()) break;

		if (netData.FindBool("useDefaults")) {
			netData.RemoveName("nick");
			netData.RemoveName("realname");
			netData.RemoveName("ident");
			BMessage netDefaults(GetNetwork("defaults"));
			netData.AddString("realname", netDefaults.FindString("realname"));
			netData.AddString("ident", netDefaults.FindString("ident"));
			const char* nick(NULL);
			for (int32 i = 0; (nick = netDefaults.FindString("nick", i)) != NULL; i++)
				netData.AddString("nick", nick);
		}
		if (fClientWin == NULL) {
			fClientWin = new ClientWindow(clientWinRect);
			fWinThread = fClientWin->Thread();
			fClientWin->Show();
		}
		BMessage connMsg(M_MAKE_NEW_NETWORK);
		connMsg.AddMessage("network", &netData);
		fClientWin->PostMessage(&connMsg);
	} break;

	case M_JOIN_CHANNEL: {
		if (fClientWin == NULL) break;

		fClientWin->PostMessage(msg);
	} break;

	case M_DCC_FILE_WIN: {
		if (fDccFileWin) {
			fDccFileWin->PostMessage(msg);
		} else {
			DCCConnect* view;

			msg->FindPointer("view", reinterpret_cast<void**>(&view));
			fDccFileWin = new DCCFileWindow(view);
			fDccFileWin->Show();
		}
	} break;

	case M_DCC_MESSENGER:
		if (msg->IsSourceWaiting()) {
			BMessenger msgr(fDccFileWin);
			BMessage reply;
			reply.AddMessenger("msgr", msgr);
			msg->SendReply(&reply);
		}
		break;

	case M_DCC_FILE_WIN_DONE: {
		fDccFileWin = 0;
	} break;

	case M_DCC_COMPLETE: {
		Broadcast(msg);
	} break;

	case M_LOAD_URL: {
		BString url(msg->FindString("url"));
		if (url.Length() > 0) {
			LoadURL(url.String());
		}
	} break;

	default:
		BApplication::MessageReceived(msg);
	}
}
Example #15
0
void
TTracker::RefsReceived(BMessage* message)
{
	OpenSelector selector = kOpen;
	if (message->HasInt32("launchUsingSelector"))
		selector = kRunOpenWithWindow;

	entry_ref handlingApp;
	if (message->FindRef("handler", &handlingApp) == B_OK)
		selector = kOpenWith;

	int32 count;
	uint32 type;
	message->GetInfo("refs", &type, &count);

	switch (selector) {
		case kRunOpenWithWindow:
			OpenContainerWindow(0, message, selector);
				// window adopts model
			break;

		case kOpenWith:
		{
			// Open With resulted in passing refs and a handler,
			// open the files with the handling app
			message->RemoveName("handler");

			// have to find out if handling app is the Tracker
			// if it is, just pass it to the active Tracker,
			// no matter which Tracker was chosen to handle the refs
			char signature[B_MIME_TYPE_LENGTH];
			signature[0] = '\0';
			{
				BFile handlingNode(&handlingApp, O_RDONLY);
				BAppFileInfo appInfo(&handlingNode);
				appInfo.GetSignature(signature);
			}

			if (strcasecmp(signature, kTrackerSignature) != 0) {
				// handling app not Tracker, pass entries to the apps
				// RefsReceived
				TrackerLaunch(&handlingApp, message, true);
				break;
			}
		}
		// fall thru, opening refs by the Tracker as if they were
		// double-clicked
		case kOpen:
		{
			// copy over "Poses" messenger so that refs received
			// recipients know where the open came from
			BMessage* bundleThis = NULL;
			BMessage stackBundleThis;
			BMessenger messenger;
			if (message->FindMessenger("TrackerViewToken", &messenger)
					== B_OK) {
				bundleThis = &stackBundleThis;
				bundleThis->AddMessenger("TrackerViewToken", messenger);
			} else {
				// copy over any "be:*" fields -- e.g. /bin/open may include
				// "be:line" and "be:column"
				for (int32 i = 0;; i++) {
					char* name;
					type_code type;
					int32 count;
					status_t error = message->GetInfo(B_ANY_TYPE, i, &name,
						&type, &count);
					if (error != B_OK)
						break;

					if (strncmp(name, "be:", 3) != 0)
						continue;

					for (int32 k = 0; k < count; k++) {
						const void* data;
						ssize_t size;
						if (message->FindData(name, type, k, &data, &size)
								!= B_OK) {
							break;
						}
						if (stackBundleThis.AddData(name, type, data, size)
								!= B_OK) {
							break;
						}
						bundleThis = &stackBundleThis;
					}
				}
			}

			for (int32 index = 0; index < count; index++) {
				entry_ref ref;
				message->FindRef("refs", index, &ref);

				const node_ref* nodeToClose = NULL;
				const node_ref* nodeToSelect = NULL;
				ssize_t numBytes;

				message->FindData("nodeRefsToClose", B_RAW_TYPE, index,
					(const void**)&nodeToClose, &numBytes);
				message->FindData("nodeRefToSelect", B_RAW_TYPE, index,
					(const void**)&nodeToSelect, &numBytes);

				OpenRef(&ref, nodeToClose, nodeToSelect, selector,
					bundleThis);
			}

			break;
		}
	}
}