Esempio n. 1
0
void PrefWindow::signal_app()
{
  //signal pref save to app if running...
  BMessenger *msgr = new BMessenger("application/x-vnd.StrokeIt.ME");
  if (msgr->IsValid())
    msgr->SendMessage( new BMessage('srlD') ); 
  delete msgr;
}
Esempio n. 2
0
void
MainWindow::Open(const BMessenger& externalObserver, const uint8* data,
                 size_t size)
{
    if (!_CheckSaveIcon(CurrentMessage()))
        return;

    if (!externalObserver.IsValid())
        return;

    Icon* icon = new (nothrow) Icon();
    if (!icon)
        return;

    if (data && size > 0) {
        // try to open the icon from the provided data
        FlatIconImporter flatImporter;
        status_t ret = flatImporter.Import(icon, const_cast<uint8*>(data),
                                           size);
        // NOTE: the const_cast is a bit ugly, but no harm is done
        // the reason is that the LittleEndianBuffer knows read and write
        // mode, in this case it is used read-only, and it does not assume
        // ownership of the buffer

        if (ret < B_OK) {
            // inform user of failure at this point
            BString helper(B_TRANSLATE("Opening the icon failed!"));
            helper << "\n\n" << B_TRANSLATE("Error: ") << strerror(ret);
            BAlert* alert = new BAlert(
                B_TRANSLATE_CONTEXT("bad news", "Title of error alert"),
                helper.String(),
                B_TRANSLATE_CONTEXT("Bummer",
                                    "Cancel button - error alert"),
                NULL, NULL);
            // launch alert asynchronously
            alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
            alert->Go(NULL);

            delete icon;
            return;
        }
    }

    AutoWriteLocker locker(fDocument);

    SetIcon(NULL);

    // incorporate the loaded icon into the document
    // (either replace it or append to it)
    fDocument->MakeEmpty();
    fDocument->SetIcon(icon);

    fDocument->SetNativeSaver(new MessengerSaver(externalObserver));

    locker.Unlock();

    SetIcon(icon);
}
Esempio n. 3
0
void
AGMSBayesianSpamFilterConfig::ShowSpamServerConfigurationWindow () {
	status_t    errorCode = B_OK;
	BMessage    maximizeCommand;
	BMessenger	messengerToServer;
	BMessage    replyMessage;

	// Make sure the server is running.
	if (!be_roster->IsRunning (kServerSignature)) {
			errorCode = be_roster->Launch (kServerSignature);
			if (errorCode != B_OK) {
				BPath path;
				entry_ref ref;
				directory_which places[] = {
					B_SYSTEM_NONPACKAGED_BIN_DIRECTORY,
					B_SYSTEM_BIN_DIRECTORY
				};
				for (int32 i = 0; i < 2; i++) {
					find_directory(places[i],&path);
					path.Append("spamdbm");
					if (!BEntry(path.Path()).Exists())
						continue;
					get_ref_for_path(path.Path(),&ref);
					if ((errorCode =  be_roster->Launch (&ref)) == B_OK)
						break;
				}
				if (errorCode != B_OK)
					goto ErrorExit;
			}
		}
	
	// Set up the messenger to the database server.
	messengerToServer =
		BMessenger (kServerSignature);
	if (!messengerToServer.IsValid ())
		goto ErrorExit;

	// Wait for the server to finish starting up, and for it to create the window.
	snooze (2000000);

	// Tell it to show its main window, in case it is hidden in server mode.
	maximizeCommand.what = B_SET_PROPERTY;
	maximizeCommand.AddBool ("data", false);
	maximizeCommand.AddSpecifier ("Minimize");
	maximizeCommand.AddSpecifier ("Window", (int32)0);
	errorCode = messengerToServer.SendMessage (&maximizeCommand, &replyMessage);
	if (errorCode != B_OK)
		goto ErrorExit;
	return; // Successful.

ErrorExit:
	BAlert* alert = new BAlert ("SpamFilterConfig Error", B_TRANSLATE("Sorry, "
		"unable to launch the spamdbm program to let you edit the server "
		"settings."), B_TRANSLATE("Close"));
	alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
	alert->Go ();
	return;
}
Esempio n. 4
0
status_t
MovieEncoder::SetMessenger(const BMessenger &messenger)
{
	if (!messenger.IsValid())
		return B_BAD_VALUE;
	
	fMessenger = messenger;
	return B_OK;
}
Esempio n. 5
0
status_t
GetPrinterServerMessenger(BMessenger& msgr)
{
	// If print server is not yet running, start it
	if (!be_roster->IsRunning(PSRV_SIGNATURE_TYPE))
		be_roster->Launch(PSRV_SIGNATURE_TYPE);
	
	msgr = BMessenger(PSRV_SIGNATURE_TYPE);
	return msgr.IsValid() ? B_OK : B_ERROR;
}
Esempio n. 6
0
status_t RouteAppNodeManager::setLogTarget(
	const BMessenger&							target) {
	
	BAutolock _l(this);
	
	if(!target.IsValid())
		return B_BAD_VALUE;
	
	m_logTarget = target;
	return B_OK;
}
Esempio n. 7
0
/*!	\brief Subscribes a target to node and/or mount watching, or unsubscribes
		   it from node watching.

	Depending of \a flags the action performed by this function varies:
	- \a flags is \c 0: The target is unsubscribed from watching the node.
	  \a node must not be \c NULL in this case.
	- \a flags contains \c B_WATCH_MOUNT: The target is subscribed to mount
	  watching.
	- \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
	  \c B_WATCH_ATTR, or \c B_WATCH_DIRECTORY: The target is subscribed to
	  watching the specified aspects of the node. \a node must not be \c NULL
	  in this case.

	Note, that the latter two cases are not mutual exlusive, i.e. mount and
	node watching can be requested with a single call.

	\param node node_ref referring to the node to be watched. May be \c NULL,
		   if only mount watching is requested.
	\param flags Flags indicating the actions to be performed.
	\param target Messenger referring to the target. Must be valid.
	\return \c B_OK, if everything went fine, another error code otherwise.
*/
status_t
watch_node(const node_ref *node, uint32 flags, BMessenger target)
{
	status_t error = (target.IsValid() ? B_OK : B_BAD_VALUE);
	if (error == B_OK) {
		BLooper *looper = NULL;
		BHandler *handler = target.Target(&looper);
		error = watch_node(node, flags, handler, looper);
	}
	return error;
}
Esempio n. 8
0
/*!	\brief Unsubscribes a target from node and mount monitoring.
	\param target Messenger referring to the target. Must be valid.
	\return \c B_OK, if everything went fine, another error code otherwise.
*/
status_t
stop_watching(BMessenger target)
{
	status_t error = (target.IsValid() ? B_OK : B_BAD_VALUE);
	if (error == B_OK) {
		BLooper *looper = NULL;
		BHandler *handler = target.Target(&looper);
		error = stop_watching(handler, looper);
	}
	return error;
}
Esempio n. 9
0
void ArpFontControl::MessageReceived(BMessage* msg)
{
	/* Redirect any messages I receive from my font ctrl to
	 * whomever I'm supposed to deliver to.
	 */
	if (msg->what == FONT_IMSG || msg->what == SIZE_IMSG) {
		BMessenger		messenger = Messenger();
		if (messenger.IsValid()) messenger.SendMessage(mMsgWhat);
		return;
	}
	inherited::MessageReceived(msg);
}
Esempio n. 10
0
/*!	\brief Unsubscribes a target from node and mount monitoring.
	\param target Messenger referring to the target. Must be valid.
	\return \c B_OK, if everything went fine, another error code otherwise.
*/
status_t
stop_watching(BMessenger target)
{
	if (!target.IsValid())
		return B_BAD_VALUE;

	BMessenger::Private messengerPrivate(target);
	port_id port = messengerPrivate.Port();
	int32 token = messengerPrivate.Token();

	return _kern_stop_notifying(port, token);
}
void
EventDispatcher::_SendFakeMouseMoved(BMessage* message)
{
	BMessenger target;
	int32 viewToken;
	if (message->FindInt32("view_token", &viewToken) != B_OK
		|| message->FindMessenger("target", &target) != B_OK)
		return;

	if (fDesktop == NULL)
		return;

	// Check if the target is still valid
	::EventTarget* eventTarget = NULL;

	fDesktop->LockSingleWindow();

	if (target.IsValid())
		eventTarget = fDesktop->FindTarget(target);

	fDesktop->UnlockSingleWindow();

	if (eventTarget == NULL)
		return;

	BMessage moved(B_MOUSE_MOVED);
	moved.AddPoint("screen_where", fLastCursorPosition);
	moved.AddInt32("buttons", fLastButtons);

	if (fDraggingMessage)
		moved.AddMessage("be:drag_message", &fDragMessage);

	if (fPreviousMouseTarget != NULL
		&& fPreviousMouseTarget->Messenger() != target) {
		_AddTokens(&moved, fPreviousMouseTarget, B_POINTER_EVENTS);
		_SendMessage(fPreviousMouseTarget->Messenger(), &moved,
			kMouseTransitImportance);

		_RemoveTokens(&moved);
	}

	moved.AddInt32("_view_token", viewToken);
		// this only belongs to the new target

	moved.AddBool("be:transit_only", true);
		// let the view know this what not user generated

	_SendMessage(target, &moved, kMouseTransitImportance);

	fPreviousMouseTarget = eventTarget;
}
Esempio n. 12
0
/*!	\brief Sets the BQuery's target and makes the query live.
	The query update messages are sent to the specified target. They might
	roll in immediately after calling Fetch().
	This methods fails, if called after Fetch(). To reuse a BQuery object it
	has to be reset via Clear().
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: \a messenger was not properly initialized.
	- \c B_NOT_ALLOWED: SetTarget() was called after Fetch().
*/
status_t
BQuery::SetTarget(BMessenger messenger)
{
    status_t error = (messenger.IsValid() ? B_OK : B_BAD_VALUE);
    if (error == B_OK && _HasFetched())
        error = B_NOT_ALLOWED;
    if (error == B_OK) {
        BMessenger::Private messengerPrivate(messenger);
        fPort = messengerPrivate.Port();
        fToken = (messengerPrivate.IsPreferredTarget()
                  ? -1 : messengerPrivate.Token());
        fLive = true;
    }
    return error;
}
Esempio n. 13
0
status_t
BPrinter::StartWatching(const BMessenger& listener)
{
	StopWatching();

	if (!listener.IsValid())
		return B_BAD_VALUE;

	fListener = new(std::nothrow) BMessenger(listener);
	if (!fListener)
		return B_NO_MEMORY;

	node_ref nodeRef;
	nodeRef.device = fPrinterEntryRef.device;
	nodeRef.node = fPrinterEntryRef.directory;

	return watch_node(&nodeRef, B_WATCH_DIRECTORY, *fListener);
}
void TScrollViewComponent::MessageReceived(BMessage *message)
{
//	char  *name; 
//	char **data;
//	float largeur,hauteur;
//	uint32  type; 
//	int32   count;
//	int32 ResizingMode,TheFlags;
//	BRect ANewFrame;
//	string truc1,truc2; 
	BMessenger *AMes;
	switch(message->what)
	{
		case MSG_PROPERTY_UPDATE :
				printf("TScrollViewComponent::Message Received. Message d'update recu!\n");
				AMes = new BMessenger(FInternalComponent->FHandler);
				if (AMes->IsValid())
				{
					AMes->SendMessage(message); // Send the message to the real ListView!
				}
				delete AMes;
				/*
				for (int32 i = 0; 
				message->GetInfo(B_STRING_TYPE, i, &name, &type, &count) == B_OK; 
				i++ ) 
				{ 				
					if (message->FindString(name,data)==B_OK)				         	
					{
						truc1 = name;
						truc2 = *data;
						FPropertyList->SetPropertyValue(truc1,truc2);												
						SetStandardProperties(name,*data);
						SetFrameProperties(name,*data,this);																			
						SetSizingProperties(name,*data,this);
						SetFlagsProperties(name,*data,this);	
//						if (strcmp(name,PROP_LABEL)==0) SetLabel(*data);
//						if (strcmp(name,PROP_MESSAGE)==0) SetLabel(*data); rien!
					}
				}
				*/
			break;
		default: BView::MessageReceived(message);
	}
}
Esempio n. 15
0
void TPanelWindowView::WorkspaceChanged()
{
	BList to_remove;
	int i;

	for ( i=0; i<fWorkspaceChangeNotifyList.CountItems(); i++ )
	{
		BMessenger *mess = static_cast<BMessenger*>(fWorkspaceChangeNotifyList.ItemAt(i));
		if ( !mess->IsValid() )
			to_remove.AddItem(mess);
		else
			mess->SendMessage( B_WORKSPACE_ACTIVATED );
	}

	for ( i=0; i<to_remove.CountItems(); i++ )
	{
		fWorkspaceChangeNotifyList.RemoveItem( to_remove.ItemAt(i) );
	}
}
Esempio n. 16
0
/*!	\brief Subscribes a target to node and/or mount watching, or unsubscribes
		   it from node watching.

	Depending of \a flags the action performed by this function varies:
	- \a flags is \c 0: The target is unsubscribed from watching the node.
	  \a node must not be \c NULL in this case.
	- \a flags contains \c B_WATCH_MOUNT: The target is subscribed to mount
	  watching.
	- \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
	  \c B_WATCH_ATTR, or \c B_WATCH_DIRECTORY: The target is subscribed to
	  watching the specified aspects of the node. \a node must not be \c NULL
	  in this case.

	Note, that the latter two cases are not mutual exlusive, i.e. mount and
	node watching can be requested with a single call.

	\param node node_ref referring to the node to be watched. May be \c NULL,
		   if only mount watching is requested.
	\param flags Flags indicating the actions to be performed.
	\param target Messenger referring to the target. Must be valid.
	\return \c B_OK, if everything went fine, another error code otherwise.
*/
status_t
watch_node(const node_ref *node, uint32 flags, BMessenger target)
{
	if (!target.IsValid())
		return B_BAD_VALUE;

	BMessenger::Private messengerPrivate(target);
	port_id port = messengerPrivate.Port();
	int32 token = messengerPrivate.Token();

	if (flags == B_STOP_WATCHING) {
		// unsubscribe from node node watching
		if (node == NULL)
			return B_BAD_VALUE;

		return _kern_stop_watching(node->device, node->node, port, token);
	}

	// subscribe to...
	// mount watching
	if (flags & B_WATCH_MOUNT) {
		status_t status = _kern_start_watching((dev_t)-1, (ino_t)-1,
			B_WATCH_MOUNT, port, token);
		if (status < B_OK)
			return status;

		flags &= ~B_WATCH_MOUNT;
	}

	// node watching
	if (flags != 0) {
		if (node == NULL)
			return B_BAD_VALUE;

		return _kern_start_watching(node->device, node->node, flags, port,
			token);
	}

	return B_OK;
}
Esempio n. 17
0
File: MSN.cpp Progetto: ModeenF/Caya
MSNP::MSNP()
	:
	fUsername(""),
	fServer("messenger.hotmail.com"),
	fPassword(""),
	fMainConnection(NULL),
	fSettings(false),
	fCachePath(""),
	fRunnerTime(40000000)
{
	AvatarLooper* fAvatarLooper = new AvatarLooper(this);
	BMessenger* mess = new BMessenger(NULL, fAvatarLooper);
	if (!mess->IsValid()) {
		printf("Avatar BMessenger error\n");
	}
	fAvatarLooper->Run();
	fAvatarRunner = new BMessageRunner(*mess, new BMessage(kAvatarCheckMessage), fRunnerTime);
	if (fAvatarRunner->InitCheck() != B_OK) {
		printf("Avatar MessageRunner error %s\n",
			strerror(fAvatarRunner->InitCheck()));
	}
}
Esempio n. 18
0
void
AgentDockHeaderString::MouseUp (BPoint where)
{
	SetViewColor (tint_color (ui_color (B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT));
	Parent()->SetViewColor (tint_color (ui_color (B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT));
	Invalidate();
	Parent()->Invalidate();
	
	// check if this header string belongs to notify list and send resize message if so
	BView *notifyList (Parent());
	if (notifyList && dynamic_cast<AgentDockHeader *>(notifyList) != NULL)
	{
		notifyList = notifyList->Parent();
		if (notifyList && dynamic_cast<AgentDockNotifyList *>(notifyList) != NULL)
		{
			BMessenger msgr (((AgentDockNotifyList *)notifyList)->pNotifyList());
			if (msgr.IsValid())
				msgr.SendMessage (M_NOTIFYLIST_RESIZE);
		}
	}

	BStringView::MouseUp (where);
}
Esempio n. 19
0
void _OwqList::OpenAddWindow(BMessage* row)
{
	if( !mAddWin.IsValid() ) {
		_OwqWindow*	win = new _OwqWindow( BMessenger(this), row );
		if( win ) {
			mAddWin = BMessenger(win);
			win->Show();
		}
	} else {
		BHandler*		target;
		BLooper*		looper;
		if( (target = mAddWin.Target(&looper)) != 0 ) {
			_OwqWindow*	win = dynamic_cast<_OwqWindow*>( target );
			if( win ) {
				if( row && win->Lock() ) {
					win->MessageReceived( row );
					win->Unlock();
				}
				win->Activate( true );
			}
		}
	}
}
Esempio n. 20
0
void TPanelWindowView::MessageReceived( BMessage *message )
{
	if ( fDebugLevel >= 20 )
		message->PrintToStream();

	if ( message->what == B_GET_PROPERTY
		 || message->what == B_SET_PROPERTY
		 || message->what == B_COUNT_PROPERTIES
		 || message->what == B_CREATE_PROPERTY
		 || message->what == B_DELETE_PROPERTY
		 || message->what == B_EXECUTE_PROPERTY )
	{
		int32 index, what;
		BMessage specifier;
		const char *property;
		if ( message->GetCurrentSpecifier( &index, &specifier, &what, &property ) == B_OK )
		{
			BMessage reply( B_REPLY );
			if ( message->what == B_GET_PROPERTY
				 || message->what == B_COUNT_PROPERTIES
				 || message->what == B_EXECUTE_PROPERTY )
			{
				if ( GetOptions( property, &reply ) )
					reply.AddInt32( "error", 0 );
				else
					reply.AddInt32( "error", -1 );
			}
			else if ( message->what == B_SET_PROPERTY )
			{
				if ( SetOptions( property, message ) )
					reply.AddInt32( "error", 0 );
				else
					reply.AddInt32( "error", -1 );
			}
			else if ( message->what == B_CREATE_PROPERTY )
			{
				if ( !strcasecmp( property, "tab" ) )
				{
					int32 index;
					if ( message->FindInt32( "index", &index ) != B_OK )
						index = -1;
					TShortcutPanel *panel = new TShortcutPanel( this );

					fPanels.Lock();
					if ( index >= 0 )
					{
						TInnerPanel *rightpanel = fPanels.ItemAt(index);
						AddPanel( panel, rightpanel );
					}
					else
					{
						AddPanel( panel );
					}
					fPanels.Unlock();

					ChangedSize(0);

					reply.AddInt32( "error", 0 );
				}
				else
					reply.AddInt32( "error", -1 );
			}
			else if ( message->what == B_DELETE_PROPERTY )
			{
				int32 index;
				if ( specifier.FindInt32( "index", &index ) != B_OK )
					reply.AddInt32( "error", -1 );
				else
				{
					fPanels.Lock();
					TInnerPanel *panel = fPanels.ItemAt(index);
					if ( !panel )
						reply.AddInt32( "error", -1 );
					else
					{
						if ( panel != fRunningAppPanel )
						{
							RemovePanel( panel );
							reply.AddInt32( "error", 0 );
						}
						else
							reply.AddInt32( "error", -1 );
					}
					fPanels.Unlock();
				}
			}
			message->SendReply( &reply );
		}
		return;
	}

	if ( message->WasDropped() )
	{
		BPoint point = message->DropPoint();
		ConvertFromScreen( &point );
		TInnerPanel *panel = PanelAt( point );
		if ( message->what == 'IDRG' )
		{
			TPanelIcon *item;
			if ( message->FindPointer( "source", (void**)&item ) == B_OK )
			{
				TRaisingIconPanel *previous_parent = item->fParent;
				TRaisingIconPanel *rpanel;
				if ( modifiers() & B_CONTROL_KEY )
				{
					rpanel = new TShortcutPanel(this);
					bool left = false;
					if ( point.x < (panel->Frame().left+(panel->Frame().Width()/2) ) )
					{
						left = true;
					}
						
					rpanel = new TShortcutPanel(this);
					AddPanel( rpanel, left ? panel : 0 );
				}
				else
					rpanel = dynamic_cast<TRaisingIconPanel*>(panel);
				if ( rpanel && rpanel != fRunningAppPanel )
				{
					TPanelIcon *icon = rpanel->IconAt( point, true );
					if ( previous_parent == fRunningAppPanel && dynamic_cast<TShortcutPanel*>(rpanel) )
					{
						int32 index = rpanel->IndexOf(icon);
						AddShortcut( dynamic_cast<TShortcutPanel*>(rpanel), dynamic_cast<TAppPanelIcon*>(item)->Ref(), index );
					}
					else if ( !dynamic_cast<TTrashIcon*>(icon) || (modifiers() & B_SHIFT_KEY) )
					{
						previous_parent->RemoveItem( item, false );
						int32 index = rpanel->IndexOf(icon);
						rpanel->AddItem( item, index );
					}
					else
					{
						if ( item->Removable() )
							RemoveShortcut(item);
					}
					if ( previous_parent->CountItems() == 0 && previous_parent != fRunningAppPanel )
						RemovePanel( previous_parent );
				}
			}
		}
		else
		{
			if ( panel && panel->HitsFrame( point ) )
			{
				panel->HandleDroppedMessage( message, point );
			}
			else
			{
				HandleDroppedMessage( message, point );
			}
		}

		return;
	}

	switch ( message->what )
	{
	case kPanelWindowViewTimer:
		{
			if ( DoIconSmallerWithTime() == 0 )
			{
				fTimer->SetInterval( 999999999 );
			}
			break;
		}
	case T_MENU_CLOSED:
		{
			DebugCall( 8, "Got T_MENU_CLOSED" );

			TAwarePopupMenu *source;
			if ( message->FindPointer( "source", (void**)&source ) == B_OK )
			{
				if ( source == fOpenMenu )
				{
					DebugCall( 9, "fOpenMenu is now 0" );

					fOpenMenu = 0;
					BPoint point;
					uint32 buttons;
					GetMouse( &point, &buttons );
					if ( !Bounds().Contains( point ) )
						Window()->PostMessage(B_EXITED_VIEW);
				}
			}
			break;
		}
	case B_SOME_APP_LAUNCHED:
		{
			team_id tid;
			if ( message->FindInt32( "be:team", &tid ) != B_OK )
				break;
			const char *sig;
			if ( message->FindString( "be:signature", &sig ) != B_OK )
				break;
			entry_ref ref;
			if ( message->FindRef( "be:ref", &ref ) != B_OK )
				break;
			int32 flags;
			if ( message->FindInt32( "be:flags", &flags ) != B_OK )
				break;

			if ( sig && strlen(sig) && ( ( flags & B_BACKGROUND_APP ) == 0 ) )
				AddTeam( tid, sig, ref );

			break;
		}
	case B_SOME_APP_QUIT:
		{
			team_id tid;
			if ( message->FindInt32( "be:team", &tid ) != B_OK )
				break;

			RemoveTeam( tid );

			break;
		}
	case B_SOME_APP_ACTIVATED:
		{
			team_id tid;
			if ( message->FindInt32( "be:team", &tid ) == B_OK )
			{
				TAppPanelIcon *icon = ItemWith( tid );

				if ( icon != fLastActiveAppIcon )
				{
					DebugCall( 10, "B_SOME_APP_ACTIVATED %p[..]->%p[%i]", fLastActiveAppIcon, icon, tid );

					if ( fLastActiveAppIcon )
						fLastActiveAppIcon->SetActive( false );
					if ( icon )
						icon->SetActive( true );
					fLastActiveAppIcon = icon;
				}
			}

			BString temp;
			message->FindString( "be:signature", &temp );

			if ( temp != "application/x-vnd.Be-TSKB" )
				fLastActivatedAppSig = temp;

			break;
		}
	case kDoBubbleHelp:
		{
			BPoint point;
			uint32 buttons;
			GetMouse(&point, &buttons);
			if ( fPreviousMousePosition != point )
			{
				if ( fBubbleCounter > 0 )
				{
					if ( fBubbleCounter >= 6 )
					{
						fBubbleHelp->HideBubble();
					}
					fBubbleCounter = 0;
				}
				fPreviousMousePosition = point;
			}
			else
			{
				BRegion region;
				GetClippingRegion(&region);
				if ( region.Contains( point ) )
				{
					fBubbleCounter ++;
					if ( fBubbleCounter == 6 )
					{
						ConvertToScreen(&point);
						TBubbleTarget *target = fBubbleHelp->TargetAt( point );
						if (dynamic_cast<TTrackerIcon*>(target)) {
							TTrackerIcon *trackerIcon = dynamic_cast<TTrackerIcon*>(target);
							point.x = Window()->Frame().left + trackerIcon->ContentLocation().x + trackerIcon->Frame().Width() + 4;
							point.y = Window()->Frame().top;
							float height = TBubbleHelp::BubbleHeight(target);
							point.y += height;
							point.y += (Window()->Frame().Height() - height)/2 -4;
						}
						fBubbleHelp->ShowBubble( point, target );
					}
//					else if ( fBubbleCounter == 12 )
//					{
//						fBubbleHelp->HideBubble();
//					}
				}
			}
			break;
		}
	case 'flsh':
		{
			BMessenger target;
			if ( message->FindMessenger("source", &target ) == B_OK && target.IsValid() )
			{
				TAppPanelIcon *teamicon = ItemWith( target.Team() );
				if ( teamicon )
				{
//					todo: flashing
					teamicon->Flash();
				}
			}
			break;
		}
	case 'mctx':
		{
//			todo: context menus
			break;
		}
	default:
		BView::MessageReceived(message);
	}
}
Esempio n. 21
0
void
NetPrefsServerView::MessageReceived (BMessage * msg)
{
  switch (msg->what)
  {
    case M_SERVER_ITEM_SELECTED:
      {
        BRow *row (fServerList->CurrentSelection ());
        if (row)
        {
          fEditButton->SetEnabled (true);
          fRemoveButton->SetEnabled (true);
        }
        else
        {
          fEditButton->SetEnabled (false);
          fRemoveButton->SetEnabled (false);
        }
      }
      break;

    case M_SERVER_ADD_ITEM:
      {
        BMessenger msgr (fEntryWin);
        if (msgr.IsValid ())
          fEntryWin->Activate ();
        else
        {
          fEntryWin = new ServerEntryWindow (this, new BMessage (M_SERVER_RECV_DATA), NULL, 0);
          fEntryWin->Show ();
        }
      }
      break;

    case M_SERVER_EDIT_ITEM:
      {
        BMessenger msgr (fEntryWin);
        if (msgr.IsValid ())
          fEntryWin->Activate ();
        else
        {
          BRow *row (fServerList->CurrentSelection ());
          if (!row)
            break;
          int32 count (0);
          ssize_t size (0);
          type_code type;
          fActiveNetwork->GetInfo ("server", &type, &count);
          const ServerData *compData;
          for (int32 i = 0; i < count; i++)
          {
            fActiveNetwork->FindData ("server", B_RAW_TYPE, i, reinterpret_cast < const void **>(&compData), &size);
            if (!strcmp (compData->serverName, ((BStringField *) row->GetField (1))->String ()))
              break;
	      }
          BMessage *invoke (new BMessage (M_SERVER_RECV_DATA));
          invoke->AddBool ("edit", true);
          fEntryWin = new ServerEntryWindow (this, invoke, compData, size);
          fEntryWin->Show ();
          }
      }
      break;


    case M_SERVER_REMOVE_ITEM:
      {
        RemoveServer ();
        fNetWin.SendMessage (M_SERVER_DATA_CHANGED);
      }
      break;

    case M_SERVER_RECV_DATA:
      {
        const ServerData *data;
        ssize_t size;
        Window ()->DisableUpdates ();
        msg->FindData ("server", B_RAW_TYPE, reinterpret_cast < const void **>(&data), &size);
        if (msg->HasBool ("edit"))
          RemoveServer ();
        UpdateNetworkData (data);
        AddServer (data);
        Window ()->EnableUpdates ();
        fNetWin.SendMessage (M_SERVER_DATA_CHANGED);
      }
      break;

    default:
      BView::MessageReceived (msg);
      break;
  }
}
Esempio n. 22
0
NetPrefsServerView::~NetPrefsServerView (void)
{
  BMessenger msgr (fEntryWin);
  if (msgr.IsValid ())
    msgr.SendMessage (B_QUIT_REQUESTED);
}
Esempio n. 23
0
void
TTracker::MessageReceived(BMessage *message)
{
	if (HandleScriptingMessage(message))
		return;

	switch (message->what) {
		case kGetInfo:
			OpenInfoWindows(message);
			break;

		case kMoveToTrash:
			MoveRefsToTrash(message);
			break;

		case kCloseWindowAndChildren:
			{
				const node_ref *itemNode;
				int32 bytes;
				message->FindData("node_ref", B_RAW_TYPE,
					(const void **)&itemNode, &bytes);
				CloseWindowAndChildren(itemNode);
				break;
			}
			
		case kCloseAllWindows:
			CloseAllWindows();
			break;

		case kFindButton:
			(new FindWindow())->Show();
			break;

		case kEditQuery:
			EditQueries(message);
			break;

		case kUnmountVolume:
			//	When the user attempts to unmount a volume from the mount
			//	context menu, this is where the message gets received.  Save
			//	pose locations and forward this to the automounter
			SaveAllPoseLocations();
			fAutoMounter->PostMessage(message);
			break;

		case kRunAutomounterSettings:
			AutomountSettingsDialog::RunAutomountSettings(fAutoMounter);
			break;

		case kShowSplash:
			{
				// The AboutWindow was moved out of the Tracker in preparation
				// for when we open source it. The AboutBox contains important
				// credit and license issues that shouldn't be modified, and
				// therefore shouldn't be open sourced. However, there is a public
				// API for 3rd party apps to tell the Tracker to open the AboutBox.
				run_be_about();
				break;
			}

		case kAddPrinter:
			// show the addprinter window
			run_add_printer_panel();
			break;
			
		case kMakeActivePrinter:
			// get the current selection
			SetDefaultPrinter(message);
			break;

#ifdef MOUNT_MENU_IN_DESKBAR

		case 'gmtv':
			{
				// Someone (probably the deskbar) has requested a list of
				// mountable volumes.
				BMessage reply;
				AutoMounterLoop()->EachMountableItemAndFloppy(&AddMountableItemToMessage,
				  &reply);
				message->SendReply(&reply);
				break;
			}

#endif

		case kMountVolume:
		case kMountAllNow:
			AutoMounterLoop()->PostMessage(message);
			break;


		case kRestoreBackgroundImage:
			{
				BDeskWindow *desktop = GetDeskWindow();
				AutoLock<BWindow> lock(desktop);
				desktop->UpdateDesktopBackgroundImages();
			}
			break;

 		case kShowSettingsWindow:
 			ShowSettingsWindow();
 			break;

		case kFavoriteCountChangedExternally:
			SendNotices(kFavoriteCountChangedExternally, message);
			break;

		case kStartWatchClipboardRefs:
		{
			BMessenger messenger;
			message->FindMessenger("target", &messenger);
			if (messenger.IsValid())
				fClipboardRefsWatcher->AddToNotifyList(messenger);
			break;
		}

		case kStopWatchClipboardRefs:
		{
			BMessenger messenger;
			message->FindMessenger("target", &messenger);
			if (messenger.IsValid())
				fClipboardRefsWatcher->RemoveFromNotifyList(messenger);
			break;
		}

		default:
			_inherited::MessageReceived(message);
			break;
	}
}
Esempio n. 24
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
NotificationWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case B_NODE_MONITOR:
		{
			_LoadSettings();
			_LoadAppFilters();
			break;
		}
		case B_COUNT_PROPERTIES:
		{
			BMessage reply(B_REPLY);
			BMessage specifier;
			const char* property = NULL;
			bool messageOkay = true;

			if (message->FindMessage("specifiers", 0, &specifier) != B_OK)
				messageOkay = false;
			if (specifier.FindString("property", &property) != B_OK)
				messageOkay = false;
			if (strcmp(property, "message") != 0)
				messageOkay = false;

			if (messageOkay)
				reply.AddInt32("result", fViews.size());
			else {
				reply.what = B_MESSAGE_NOT_UNDERSTOOD;
				reply.AddInt32("error", B_ERROR);
			}

			message->SendReply(&reply);
			break;
		}
		case B_CREATE_PROPERTY:
		case kNotificationMessage:
		{
			BMessage reply(B_REPLY);
			BNotification* notification = new BNotification(message);

			if (notification->InitCheck() == B_OK) {
				bigtime_t timeout;
				if (message->FindInt64("timeout", &timeout) != B_OK)
					timeout = -1;
				BMessenger messenger = message->ReturnAddress();
				app_info info;

				if (messenger.IsValid())
					be_roster->GetRunningAppInfo(messenger.Team(), &info);
				else
					be_roster->GetAppInfo("application/x-vnd.Be-SHEL", &info);

				NotificationView* view = new NotificationView(this,
					notification, timeout);

				bool allow = false;
				appfilter_t::iterator it = fAppFilters.find(info.signature);

				if (it == fAppFilters.end()) {
					AppUsage* appUsage = new AppUsage(notification->Group(),
						true);

					appUsage->Allowed(notification->Title(),
							notification->Type());
					fAppFilters[info.signature] = appUsage;
					allow = true;
				} else {
					allow = it->second->Allowed(notification->Title(),
						notification->Type());
				}

				if (allow) {
					BString groupName(notification->Group());
					appview_t::iterator aIt = fAppViews.find(groupName);
					AppGroupView* group = NULL;
					if (aIt == fAppViews.end()) {
						group = new AppGroupView(this,
							groupName == "" ? NULL : groupName.String());
						fAppViews[groupName] = group;
						GetLayout()->AddView(group);
					} else
						group = aIt->second;

					group->AddInfo(view);

					_ResizeAll();

					reply.AddInt32("error", B_OK);
				} else
					reply.AddInt32("error", B_NOT_ALLOWED);
			} else {
				reply.what = B_MESSAGE_NOT_UNDERSTOOD;
				reply.AddInt32("error", B_ERROR);
			}

			message->SendReply(&reply);
			break;
		}
		case kRemoveView:
		{
			NotificationView* view = NULL;
			if (message->FindPointer("view", (void**)&view) != B_OK)
				return;

			views_t::iterator it = find(fViews.begin(), fViews.end(), view);

			if (it != fViews.end())
				fViews.erase(it);

			_ResizeAll();
			break;
		}
		default:
			BWindow::MessageReceived(message);
	}
}
Esempio n. 26
0
int32 DCCSend::Transfer(void* arg)
{
	BMessenger msgr(reinterpret_cast<DCCSend*>(arg));
	BMessage reply, ipdata;
	BLooper* looper(NULL);

	if (msgr.IsValid()) msgr.SendMessage(M_DCC_GET_CONNECT_DATA, &reply);

	BMessenger callmsgr;
	reply.FindMessenger("caller", &callmsgr);

	callmsgr.SendMessage(M_GET_IP, &ipdata);

	BPath path(reply.FindString("name"));
	BString fileName, status;
	struct sockaddr_in address;
	struct in_addr sendaddr;
	memset(&sendaddr, 0, sizeof(struct in_addr));
	int sd, dccSock(-1);

	fileName.Append(path.Leaf());
	fileName.ReplaceAll(" ", "_");

	if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
		return 0;
	}

	memset(&address, 0, sizeof(struct sockaddr_in));
	address.sin_family = AF_INET;
	address.sin_addr.s_addr = INADDR_ANY;
	address.sin_port = htons(atoi(reply.FindString("port")));

	int sin_size;
	sin_size = (sizeof(struct sockaddr_in));

	UpdateStatus(msgr, S_DCC_LOCK_ACQUIRE B_UTF8_ELLIPSIS);

	vision_app->AcquireDCCLock();

	if (!msgr.IsValid() || bind(sd, (sockaddr*)&address, sin_size) < 0) {
		UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
		vision_app->ReleaseDCCLock();

		close(sd);
		return 0;
	}

	UpdateStatus(msgr, S_DCC_ACK_WAIT);

	sendaddr.s_addr = inet_addr(ipdata.FindString("ip"));

	if (msgr.IsValid()) {
		status = "PRIVMSG ";
		status << reply.FindString("nick") << " :\1DCC SEND " << fileName << " "
			   << htonl(sendaddr.s_addr) << " " << reply.FindString("port") << " "
			   << reply.FindString("size") << "\1";

		BMessage msg(M_SERVER_SEND);
		msg.AddString("data", status.String());
		if (callmsgr.IsValid()) callmsgr.SendMessage(&msg);

		UpdateStatus(msgr, S_DCC_LISTEN_CALL);
		if (listen(sd, 1) < 0) {
			UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
			vision_app->ReleaseDCCLock();
			close(sd);
			return 0;
		}
	}

	struct timeval t;
	t.tv_sec = 2;
	t.tv_usec = 0;

	uint32 try_count(0);

	while (msgr.Target(&looper) != NULL) {
		fd_set rset;

		FD_ZERO(&rset);
		FD_SET(sd, &rset);

		if (select(sd + 1, &rset, 0, 0, &t) < 0) {
			UpdateStatus(msgr, S_DCC_ESTABLISH_ERROR);
			vision_app->ReleaseDCCLock();
			close(sd);
			return 0;
		}

		if (FD_ISSET(sd, &rset)) {
			dccSock = accept(sd, (sockaddr*)&address, (socklen_t*)&sin_size);
			UpdateStatus(msgr, S_DCC_ESTABLISH_SUCCEEDED);
			break;
		}

		++try_count;
		status = S_DCC_WAIT_FOR_CONNECTION;
		status << try_count << ".";
		UpdateStatus(msgr, status.String());
	}

	vision_app->ReleaseDCCLock();

	char set[4];
	memset(set, 1, sizeof(set));
	close(sd);
	BFile file;

	file.SetTo(reply.FindString("name"), B_READ_ONLY);
	int32 bytes_sent(0L), seekpos(0L);

	BMessage resumeData;
	msgr.SendMessage(M_DCC_GET_RESUME_POS, &resumeData);

	if (resumeData.HasInt32("pos")) {
		resumeData.FindInt32("pos", &seekpos);
		file.Seek(seekpos, SEEK_SET);
		UpdateBar(msgr, seekpos, 0, 0, true);
		bytes_sent = seekpos;
	}

	status = S_DCC_SEND1;
	status << path.Leaf() << S_DCC_SEND2 << reply.FindString("nick") << ".";
	UpdateStatus(msgr, status.String());

	int cps(0);

	if (file.InitCheck() == B_NO_ERROR) {
		bigtime_t last(system_time()), now;
		const uint32 DCC_BLOCK_SIZE(atoi(vision_app->GetString("dccBlockSize")));
#ifdef __INTEL__
		char buffer[DCC_BLOCK_SIZE];
#else
		char* buffer = new char[DCC_BLOCK_SIZE];
#endif
		int period(0);
		ssize_t count(0);
		bigtime_t start = system_time();

		while ((msgr.Target(&looper) != NULL) &&
			   (count = file.Read(buffer, DCC_BLOCK_SIZE - 1)) > 0) {
			int sent;

			if ((sent = send(dccSock, buffer, count, 0)) < count) {
				UpdateStatus(msgr, S_DCC_WRITE_ERROR);
				break;
			}

			uint32 confirm(0), newSize(bytes_sent + count);
			fd_set rset, eset;
			FD_ZERO(&rset);
			FD_ZERO(&eset);
			FD_SET(dccSock, &rset);
			t.tv_sec = 0;
			t.tv_usec = 10;

			while ((confirm < newSize) && (recv(dccSock, &confirm, sizeof(confirm), 0) > 0)) {
				confirm = ntohl(confirm);
				bytes_sent = confirm;
			}

			BMessage msg(M_DCC_UPDATE_TRANSFERRED);
			msg.AddInt32("transferred", bytes_sent);
			msgr.SendMessage(&msg);

			now = system_time();
			period += sent;

			bool hit(false);

			if (now - last > 500000) {
				cps = (int)ceil((bytes_sent - seekpos) / ((now - start) / 1000000.0));
				BMessage updmsg(M_DCC_UPDATE_AVERAGE);
				updmsg.AddInt32("average", cps);
				msgr.SendMessage(&updmsg);
				last = now;
				period = 0;
				hit = true;
			}
			UpdateBar(msgr, sent, cps, bytes_sent, hit);
		}
#ifndef __INTEL__
		delete[] buffer;
#endif
	}
	if (msgr.IsValid()) {
		BMessage msg(M_DCC_STOP_BUTTON);
		msgr.SendMessage(&msg);
	}

	if (dccSock > 0) {
		close(dccSock);
	}

	if (file.InitCheck() == B_OK) file.Unset();

	return 0;
}
Esempio n. 27
0
void
TTracker::MessageReceived(BMessage *message)
{
	if (HandleScriptingMessage(message))
		return;

	switch (message->what) {
		case kGetInfo:
			OpenInfoWindows(message);
			break;

		case kMoveToTrash:
			MoveRefsToTrash(message);
			break;

		case kCloseWindowAndChildren:
			{
				const node_ref *itemNode;
				int32 bytes;
				message->FindData("node_ref", B_RAW_TYPE,
					(const void **)&itemNode, &bytes);
				CloseWindowAndChildren(itemNode);
				break;
			}

		case kCloseAllWindows:
			CloseAllWindows();
			break;

		case kCloseAllInWorkspace:
			CloseAllInWorkspace();
			break;

		case kFindButton:
			(new FindWindow())->Show();
			break;

		case kEditQuery:
			EditQueries(message);
			break;

		case kShowSplash:
			run_be_about();
			break;

		case kAddPrinter:
			// show the addprinter window
			run_add_printer_panel();
			break;

		case kMakeActivePrinter:
			// get the current selection
			SetDefaultPrinter(message);
			break;

#ifdef MOUNT_MENU_IN_DESKBAR

		case 'gmtv':
		{
			// Someone (probably the deskbar) has requested a list of
			// mountable volumes.
			BMessage reply;
			AutoMounterLoop()->EachMountableItemAndFloppy(&AddMountableItemToMessage,
			  &reply);
			message->SendReply(&reply);
			break;
		}

#endif

		case kUnmountVolume:
			// When the user attempts to unmount a volume from the mount
			// context menu, this is where the message gets received.
			// Save pose locations and forward this to the automounter
			SaveAllPoseLocations();
			// Fall through...
		case kMountVolume:
		case kMountAllNow:
			MountServer().SendMessage(message);
			break;

		case kRunAutomounterSettings:
			AutomountSettingsDialog::RunAutomountSettings(MountServer());
			break;

		case kRestoreBackgroundImage:
		{
			BDeskWindow *desktop = GetDeskWindow();
			AutoLock<BWindow> lock(desktop);
			desktop->UpdateDesktopBackgroundImages();
			break;
		}

 		case kShowSettingsWindow:
 			ShowSettingsWindow();
 			break;

		case kFavoriteCountChangedExternally:
			SendNotices(kFavoriteCountChangedExternally, message);
			break;

		case kStartWatchClipboardRefs:
		{
			BMessenger messenger;
			message->FindMessenger("target", &messenger);
			if (messenger.IsValid())
				fClipboardRefsWatcher->AddToNotifyList(messenger);
			break;
		}

		case kStopWatchClipboardRefs:
		{
			BMessenger messenger;
			message->FindMessenger("target", &messenger);
			if (messenger.IsValid())
				fClipboardRefsWatcher->RemoveFromNotifyList(messenger);
			break;
		}

		case kFSClipboardChanges:
			fClipboardRefsWatcher->UpdatePoseViews(message);
			break;

		case kShowVolumeSpaceBar:
		case kSpaceBarColorChanged:
			gPeriodicUpdatePoses.DoPeriodicUpdate(true);
			break;

		case B_LOCALE_CHANGED:
		{
			BLocaleRoster::Default()->Refresh();
			bool localize;
			if (message->FindBool("filesys", &localize) == B_OK)
				gLocalizedNamePreferred = localize;
			break;
		}

		default:
			_inherited::MessageReceived(message);
			break;
	}
}
Esempio n. 28
0
void
NotificationView::_LoadIcon()
{
	// First try to get the icon from the caller application
	app_info info;
	BMessenger msgr = fDetails->ReturnAddress();

	if (msgr.IsValid())
		be_roster->GetRunningAppInfo(msgr.Team(), &info);
	else if (fType == B_PROGRESS_NOTIFICATION)
		be_roster->GetAppInfo("application/x-vnd.Haiku-notification_server",
			&info);

	BPath path;
	path.SetTo(&info.ref);

	fBitmap = _ReadNodeIcon(path.Path(), fParent->IconSize());
	if (fBitmap)
		return;

	// If that failed get icons from app_server
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) != B_OK)
		return;

	path.Append("app_server");

	BFile file(path.Path(), B_READ_ONLY);
	if (file.InitCheck() != B_OK)
		return;

	BResources res(&file);
	if (res.InitCheck() != B_OK)
		return;

	// Which one should we choose?
	const char* iconName = "";
	switch (fType) {
		case B_INFORMATION_NOTIFICATION:
			iconName = "info";
			break;
		case B_ERROR_NOTIFICATION:
			iconName = "stop";
			break;
		case B_IMPORTANT_NOTIFICATION:
			iconName = "warn";
			break;
		default:
			return;
	}

	// Allocate the bitmap
	fBitmap = new BBitmap(BRect(0, 0, (float)B_LARGE_ICON - 1,
		(float)B_LARGE_ICON - 1), B_RGBA32);
	if (!fBitmap || fBitmap->InitCheck() != B_OK) {
		fBitmap = NULL;
		return;
	}

	// Load raw icon data
	size_t size = 0;
	const uint8* data = (const uint8*)res.LoadResource(B_VECTOR_ICON_TYPE,
		iconName, &size);
	if ((data == NULL
		|| BIconUtils::GetVectorIcon(data, size, fBitmap) != B_OK))
		fBitmap = NULL;
}
Esempio n. 29
0
void
NotificationWindow::MessageReceived(BMessage* message)
{
    switch (message->what) {
    case B_NODE_MONITOR:
    {
        LoadSettings();
        LoadAppFilters();
        break;
    }
    case kResizeToFit:
        ResizeAll();
        break;
    case B_COUNT_PROPERTIES:
    {
        BMessage reply(B_REPLY);
        BMessage specifier;
        const char* property = NULL;
        bool messageOkay = true;

        if (message->FindMessage("specifiers", 0, &specifier) != B_OK)
            messageOkay = false;
        if (specifier.FindString("property", &property) != B_OK)
            messageOkay = false;
        if (strcmp(property, "message") != 0)
            messageOkay = false;

        if (messageOkay)
            reply.AddInt32("result", fViews.size());
        else {
            reply.what = B_MESSAGE_NOT_UNDERSTOOD;
            reply.AddInt32("error", B_ERROR);
        }

        message->SendReply(&reply);
        break;
    }
    case B_CREATE_PROPERTY:
    case kNotificationMessage:
    {
        int32 type;
        const char* content = NULL;
        const char* title = NULL;
        const char* app = NULL;
        BMessage reply(B_REPLY);
        bool messageOkay = true;

        if (message->FindInt32("type", &type) != B_OK)
            type = B_INFORMATION_NOTIFICATION;
        if (message->FindString("content", &content) != B_OK)
            messageOkay = false;
        if (message->FindString("title", &title) != B_OK)
            messageOkay = false;
        if (message->FindString("app", &app) != B_OK
                && message->FindString("appTitle", &app) != B_OK)
            messageOkay = false;

        if (messageOkay) {
            NotificationView* view = new NotificationView(this,
                    (notification_type)type, app, title, content,
                    new BMessage(*message));

            appfilter_t::iterator fIt = fAppFilters.find(app);
            bool allow = false;
            if (fIt == fAppFilters.end()) {
                app_info info;
                BMessenger messenger = message->ReturnAddress();
                if (messenger.IsValid())
                    be_roster->GetRunningAppInfo(messenger.Team(), &info);
                else
                    be_roster->GetAppInfo("application/x-vnd.Be-SHEL", &info);

                AppUsage* appUsage = new AppUsage(info.ref, app, true);
                fAppFilters[app] = appUsage;

                appUsage->Allowed(title, (notification_type)type);

                allow = true;
            } else
                allow = fIt->second->Allowed(title, (notification_type)type);

            if (allow) {
                appview_t::iterator aIt = fAppViews.find(app);
                AppGroupView* group = NULL;
                if (aIt == fAppViews.end()) {
                    group = new AppGroupView(this, app);
                    fAppViews[app] = group;
                    fBorder->AddChild(group);
                } else
                    group = aIt->second;

                group->AddInfo(view);

                ResizeAll();

                reply.AddInt32("error", B_OK);
            } else
                reply.AddInt32("error", B_NOT_ALLOWED);
        } else {
            reply.what = B_MESSAGE_NOT_UNDERSTOOD;
            reply.AddInt32("error", B_ERROR);
        }

        message->SendReply(&reply);
        break;
    }
    case kRemoveView:
    {
        void* _ptr;
        message->FindPointer("view", &_ptr);

        NotificationView* info
            = reinterpret_cast<NotificationView*>(_ptr);

        fBorder->RemoveChild(info);

        std::vector<NotificationView*>::iterator i
            = find(fViews.begin(), fViews.end(), info);
        if (i != fViews.end())
            fViews.erase(i);

        delete info;

        ResizeAll();
        break;
    }
    default:
        BWindow::MessageReceived(message);
    }
}
Esempio n. 30
0
filter_result
Server::Filter(BMessage* message, BHandler **target)
{
	filter_result result = B_DISPATCH_MESSAGE;

	switch (message->what) {
		case IM_MESSAGE_RECEIVED:
		{
			BString id = message->FindString("id");
			if (id.Length() > 0) {
				bool found = false;
				ContactLinker* item = fRosterMap.ValueFor(id, &found);
				if (found) {
					ChatWindow* win = item->GetChatWindow();
					item->ShowWindow();
					win->PostMessage(message);
				}
			}
			result = B_SKIP_MESSAGE;
			break;
		}
		case CAYA_CLOSE_CHAT_WINDOW:
		{
			BString id = message->FindString("id");
			if (id.Length() > 0) {
				bool found = false;
				ContactLinker* item = fRosterMap.ValueFor(id, &found);

				if (found)
					item->HideWindow();
			}
			result = B_SKIP_MESSAGE;
			break;
		}
		case IM_MESSAGE:
			result = ImMessage(message);
			break;

		case CAYA_REPLICANT_MESSENGER:
		{
			BMessenger* messenger = new BMessenger();

			status_t ret = message->FindMessenger(
				"messenger", messenger);

			if (ret != B_OK || !messenger->IsValid()) {
				message->PrintToStream();
				printf("err %s\n", strerror(ret));
				break;
			}
			AccountManager* accountManager = AccountManager::Get();
			accountManager->SetReplicantMessenger(messenger);
			accountManager->ReplicantStatusNotify(accountManager->Status());
			break;
		}

		default:
			// Dispatch not handled messages to main window
			break;
	}

	return result;
}