Return to DK Summary

Protocol


To use the examples given in this page, you'll need Attila Mezei's hey tool. It is a very useful tool that can send scripting messages from the terminal. Just launch BeHappy, open a terminal, and type the commands given after the $ character.

The BeHappy Application

To find the application, use it's signature: application/x.vnd-STertois.BeHappy. The following code will construct a BMessenger that can be used to send messages to BeHappy:

     BMessenger messenger("application/x.vnd-STertois.BeHappy");

But this code won't work if BeHappy isn't already running, so a better method is to use Launch to send a message:

     be_roster->Launch("application/x.vnd-STertois.BeHappy",message);

As BeHappy doesn't allow multiple instances of itself, doing this when it's already running won't launch a new BeHappy, but send the message to the existing one.
If BeHappy is launched with a 'Hide' message, it doesn't open any window, and wait for messages:

     BMessage launch('Hide');
     be_roster->Launch("application/x.vnd-STertois.BeHappy",&launch);


Opening a window

To open a BeHappy window, you must send the 'Open' message. If the message is empty, a window with the last used book will be opened. But you can also open a perticular book by adding a B_STRING_TYPE field "Name" to the message. The string value must be the add-on name. The folowing code will launch BeHappy and open it's documentation:

     BMessage launch('Open');
     launch.AddString("Name","BeHappy Documentation");
     be_roster->Launch("application/x.vnd-STertois.BeHappy",&message);

If BeHappy is already running, a window with the documentation will open.
If the book is found, a B_REPLY reply is given, with a "Messenger" field, giving the new window's messenger. If it isn't found, a B_MESSAGE_NOT_UNDERSTOOD reply is given. In that case, BeHappy won't quit by itself, even if you launched it with this message.

The 'Add-on' properties

The application has an 'Add-ons' property, that only recognise the B_DIRECT_SPECIFIER specifier, and the B_COUNT_PROPERTIES command. It returns the number of add-ons BeHappy has.

$ hey BeHappy count Add-ons
Reply BMessage(B_REPLY):
"result" (B_INT32_TYPE) : 4 (0x00000004)
"error" (B_INT32_TYPE) : 0 (0x00000000)

Then, the 'Add-on' property returns the name of a particular add-on. It supports the B_INDEX_SPECIFIER specifier, and the B_GET_PROPERTY command.

$ hey BeHappy get Add-on 3
Reply BMessage(B_REPLY):
"result" (B_STRING_TYPE) : "OpenGL specs"
"error" (B_INT32_TYPE) : 0 (0x00000000)

The 'Book' property

This is a window property, with the name of the currently opened book. It supports the B_DIRECT_SPECIFIER specifier, and the B_GET_PROPERTY and B_SET_PROPERTY commands.

$ hey BeHappy get Book of Window 0
Reply BMessage(B_REPLY):
"error" (B_INT32_TYPE) : 0 (0x00000000)
"result" (B_STRING_TYPE) : "Be Book"
$ hey BeHappy set Book of Window 0 to "BeHappy Documentation"
Reply BMessage(B_REPLY):
"error" (B_INT32_TYPE) : 0 (0x00000000)

The B_SET_PROPERTY command will return the B_BAD_INDEX error if the book isn't found.

The 'Index' property

This window property is the name of the currently selected index, in the top menu field. It supports the B_DIRECT_SPECIFIER specifier, and the B_GET_PROPERTY and B_SET_PROPERTY commands.

$ hey BeHappy get Index of Window 0
Reply BMessage(B_REPLY):
"error" (B_INT32_TYPE) : 0 (0x00000000)
"result" (B_STRING_TYPE) : "Summary"
$ hey BeHappy set Index of Window 0 to "Topics"
Reply BMessage(B_REPLY):
"error" (B_INT32_TYPE) : 0 (0x00000000)

The B_SET_PROPERTY command will return the B_BAD_INDEX error if the index isn't found.

The 'Topic' property

This window property is the name of the currently selected link, in the list below the menu field. If no topic is selected, this property is "". It supports the B_DIRECT_SPECIFIER specifier, and the B_GET_PROPERTY and B_SET_PROPERTY commands.

$ hey BeHappy get Topic of Window 0
Reply BMessage(B_REPLY):
"error" (B_INT32_TYPE) : 0 (0x00000000)
"result" (B_STRING_TYPE) : ""
$ hey BeHappy set Topic of Window 0 to "Parser"
Reply BMessage(B_REPLY):
"error" (B_INT32_TYPE) : 0 (0x00000000)

The B_SET_PROPERTY command will return the B_BAD_INDEX error if the link isn't found.

The 'FatherTopic' property

This property is like 'Topic', but can be more useful with an index that creates two lists in the BeHappy window. This topic is the 'father' topic, that means the topic selected in the upper list.

The 'ChildTopic' property

As for 'FatherTopic', this property is like 'Topic', but can be more useful with two lists in the BeHappy window. This topic is the 'child' topic, that means the topic selected in the lower list. You should use this propery after 'FatherTopic'.

The other properties

All the other window properties are available, which lets you do useful stuff...

$ hey BeHappy set Title of Window 0 to "Stupid Window"
Reply BMessage(B_REPLY):
"error" (B_INT32_TYPE) : 0 (0x00000000)


Thank you to Attila Mezei for his hey tool.

Next: The HappyCommander class

Return to DK Summary