Pyro higlevel API
Classes | Public Member Functions | Static Public Member Functions | List of all members
os::RegistrarManager Class Reference

Class to access the registrar server. More...

Inheritance diagram for os::RegistrarManager:
os::Looper os::Handler

Classes

class  Private
 

Public Member Functions

 RegistrarManager ()
 Constructor. More...
 
 ~RegistrarManager ()
 Destructor. More...
 
void AddRef ()
 
void Put (bool bAll=false)
 Decrements the reference counter of the instance. More...
 
void HandleMessage (Message *pcMessage)
 Handle a message targeted at this handler. More...
 
void SetSynchronousMode (bool bSync)
 Sets whether the registrar manager class is in synchronous mode. More...
 
status_t RegisterType (String zMimeType, String zIdentifier, bool bOverwrite=false)
 Registers a new filetype. More...
 
status_t UnregisterType (String zMimeType)
 Unregisters a filetype. More...
 
status_t RegisterTypeIcon (String zMimeType, Path cIcon, bool bOverwrite=false)
 Sets a new icon for a filetype. More...
 
status_t RegisterTypeIconFromRes (String zMimeType, String zIconRes, bool bOverwrite=false)
 Sets a new icon for a filetype which will be extracted from the application resources. More...
 
status_t RegisterTypeExtension (String zMimeType, String zExtension)
 Registers a new extension for a type. More...
 
status_t ClearTypeExtensions (String zMimeType)
 Clears the extension list for a type. More...
 
status_t RegisterTypeHandler (String zMimeType, Path cHandler)
 Registers a new handler for a type. More...
 
status_t RegisterAsTypeHandler (String zMimeType)
 Registers the current application as a handler for a type. More...
 
status_t ClearTypeHandlers (String zMimeType)
 Clears the handler list for a type. More...
 
int32 GetTypeCount ()
 Returns the number of types that are registered for the calling user. More...
 
RegistrarFileType GetType (int32 nIndex)
 Returns a RegistrarFileType object that describes a specific type. More...
 
status_t SetDefaultHandler (String zMimeType, Path zHandler)
 Sets the default handler for a type. More...
 
status_t GetTypeAndIcon (String zFile, Point cIconSize, String *zTypeName, Image **pcIcon, Message *pcMessage=NULL)
 Returns a description and an image for a file. More...
 
status_t Launch (Window *pcParentWindow, String zFile, bool bVerbose=false, String zTitle="Select handler", bool bDefaultHandler=true)
 Launches a file. More...
 
void UpdateAppList (bool bForce=false)
 Update the application list. More...
 
RegistrarAppList GetAppList ()
 Returns the application list. More...
 
- Public Member Functions inherited from os::Looper
 Looper (const String &cName, int nPriority=NORMAL_PRIORITY, int nPortSize=DEFAULT_PORT_SIZE)
 The looper constructor. More...
 
virtual ~Looper ()
 Looper destructor. More...
 
void SetName (const String &cName)
 Rename the looper. More...
 
String GetName () const
 Get the loopers name. More...
 
bool IsPublic () const
 See if the looper's message port is public. More...
 
void SetPublic (bool bPublic)
 Make port public/private. More...
 
port_id GetMsgPort () const
 Obtain the low-level message port used by this looper. More...
 
thread_id GetThread () const
 Obtain the thread id of the looper thread. More...
 
proc_id GetProcess () const
 Obtain the process ID of the loopers thread. More...
 
status_t Lock ()
 Lock the looper object. More...
 
status_t Lock (bigtime_t nTimeout)
 Lock the looper with a timeout. More...
 
status_t SafeLock ()
 Attempt to lock the looper. More...
 
status_t Unlock ()
 Unlock the looper. More...
 
void SetMutex (Locker *pcMutex)
 Set a custom mutex to be used by the looper. More...
 
LockerGetMutex () const
 Get a pointer to the loopers mutex. More...
 
int GetLockCount () const
 Obtain the number of locks held on the looper. More...
 
thread_id GetLockingThread () const
 Obtaing the owner of the looper lock. More...
 
bool IsLocked () const
 Check if the looper lock is owned by the calling thread. More...
 
virtual thread_id Run ()
 Start and unlock the looper. More...
 
int Wait () const
 Wait for the looper thread to die. More...
 
status_t PostMessage (uint32 nCode)
 Deliver a message to the looper. More...
 
status_t PostMessage (Message *pcMsg)
 Deliver a message to the looper. More...
 
status_t PostMessage (uint32 cCode, Handler *pcHandler, Handler *pcReplyTo=NULL)
 Deliver a message to the looper. More...
 
status_t PostMessage (Message *pcMsg, Handler *pcHandler, Handler *pcReplyTo=NULL)
 Deliver a message to the looper. More...
 
void SpoolMessages ()
 Drain the low-level message port. More...
 
MessageGetCurrentMessage () const
 Obtain the message currently being processed. More...
 
MessageDetachCurrentMessage ()
 Steal the current message. More...
 
virtual void DispatchMessage (Message *pcMessage, Handler *pcHandler)
 The loopers message handling callback. More...
 
virtual void Started ()
 Called by the looper thread before entering the message loop. More...
 
virtual bool Idle ()
 Hook called each time the message queue is drained. More...
 
MessageQueueGetMessageQueue () const
 Obtain the internal message queue used by the looper. More...
 
virtual bool OkToQuit ()
 Check if it is ok to break the loop. More...
 
virtual void Quit ()
 Unconditionally terminate the looper. More...
 
void Terminate ()
 Unconditionally terminate the looper. More...
 
void AddTimer (Handler *pcTarget, int nID, bigtime_t nTimeout, bool bOneShot=true)
 Add a timer to the looper. More...
 
bool RemoveTimer (Handler *pcTarget, int nID)
 Delete a timer. More...
 
const handler_mapGetHandlerMap () const
 Get the internal handler list. More...
 
void AddHandler (Handler *pcHandler)
 Add a handler to the looper. More...
 
bool RemoveHandler (Handler *pcHandler)
 Remove a handler previously added by AddHandler() More...
 
HandlerFindHandler (const String &cName) const
 Search the looper for a named handler. More...
 
int GetHandlerCount () const
 Obtain the count of handlers added to this looper. More...
 
void SetDefaultHandler (Handler *pcHandler)
 Set the default target for incomming messages. More...
 
HandlerGetDefaultHandler () const
 Obtain the default handler for the looper. More...
 
void AddCommonFilter (MessageFilter *pcFilter)
 
void RemoveCommonFilter (MessageFilter *pcFilter)
 
const MsgFilterListGetCommonFilterList () const
 
- Public Member Functions inherited from os::Handler
 Handler (const String &cName)
 Construct a handler. More...
 
virtual ~Handler ()
 Destructor. More...
 
virtual void TimerTick (int nID)
 Timer dispatch member. More...
 
String GetName () const
 Get the handlers name. More...
 
void SetName (const String &cName)
 Rename the handler. More...
 
LooperGetLooper () const
 Get a pointer to the looper this handler belongs to. More...
 
void SetNextHandler (Handler *pcNextHandler)
 Set a handler that should handle messages this handler is not interrested in. More...
 
HandlerGetNextHandler () const
 Get the next handler in a handler chain. More...
 
void AddFilter (MessageFilter *pcFilter)
 
void RemoveFilter (MessageFilter *pcFilter)
 
const MsgFilterListGetFilterList () const
 
const uint32 GetToken ()
 Get the handlers token. More...
 

Static Public Member Functions

static RegistrarManagerGet ()
 Provides access to the RegistrarManager class. More...
 
- Static Public Member Functions inherited from os::Looper
static LooperGetLooperForThread (thread_id hThread)
 

Additional Inherited Members

- Public Types inherited from os::Looper
typedef std::map< int, Handler * > handler_map
 
- Protected Member Functions inherited from os::Looper
bool FilterMessage (Message *pcMsg, Handler **ppcTarget, std::list< MessageFilter * > *pcFilterList)
 

Detailed Description

Description:
The RegistrarManager class provides a way to access the registrar, a server which manages the known filetypes. It is especially useful for applications to register the filetypes that they can handle. It can also be used to get the filetype and icon for files or to launch files with their associated application.
An example to register the current application as a handler for jpeg images:
...
#include <pyro/image.h>
MyApp::MyApp() : os::Application( "application/x-vnd-MyApp" )
{
try
{
pcManager->RegisterType( "image/x-jpg", "JPEG image" );
pcManager->RegisterAsTypeHandler( "image/x-jpg" );
// Assumes that you added the filetype icon as a resource
pcManager->RegisterTypeIconFromRes( "image/x-jpg", "image_jpg.png" );
pcManager->Put();
}
}
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

Constructor & Destructor Documentation

RegistrarManager::RegistrarManager ( )
RegistrarManager::~RegistrarManager ( )

Member Function Documentation

void RegistrarManager::AddRef ( void  )
status_t RegistrarManager::ClearTypeExtensions ( String  zMimeType)
status_t RegistrarManager::ClearTypeHandlers ( String  zMimeType)
RegistrarManager * RegistrarManager::Get ( )
static
Description:
Creates a new registrar manager if it does not exist. Otherwise return a pointer to the current one.
Note:
Make sure you call Put() afterwards. If the creation fails, an exception will be thrown.
See Also
Put()
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References AddRef(), RegistrarManager(), and os::Looper::Run().

Referenced by InfoWin::HandleMessage(), HandlerSelector::HandlerSelector(), os::IconDirectoryView::IconDirectoryView(), and InfoWin::InfoWin().

RegistrarAppList RegistrarManager::GetAppList ( )
RegistrarFileType RegistrarManager::GetType ( int32  nIndex)
status_t RegistrarManager::GetTypeAndIcon ( String  zFile,
Point  cIconSize,
String zTypeName,
Image **  pcIcon,
Message pcMessage = NULL 
)
int32 RegistrarManager::GetTypeCount ( )
void RegistrarManager::HandleMessage ( Message pcMessage)
virtual
Description:
Overload this member to dispatch messages sendt to this handler. When a looper receives a message for one of it's handlers it will call the taget handlers HandleMessage() to allow the handler to dispatch the message.
The message passed in pcMessage is also available through os::Looper::GetCurrentMessage() and os::Looper::DetachCurrentMessage() until this member returns. This is normally not very usefull for HandleMessage() itself but it can be convinient for other members called from HandleMessage() in case they need data from the message that was not passed on from HandleMessage().
The looper will be locked when this member is called. The default implementation of this member will pass the message on to the next handler if one was set with SetNextHandler().
Note
Never do any lenthy operations in any hook members that are called from the looper thread if the looper is involved with the GUI (for example if the looper is a os::Window). The looper will not be able to dispatch messages until the hook returns so spending a long time in this members will make the GUI feel unresponsive.
Parameters
pcMessageThe message that should be handled. This message will be deleted by the looper when HandleMessage() returns unless you detach it with os::Looper::DetachCurrentMessage(),
See Also
os::Looper::DispatchMessage(), os::Looper::DetachCurrentMessage()
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

Reimplemented from os::Handler.

References os::Handler::HandleMessage().

status_t RegistrarManager::Launch ( Window pcParentWindow,
String  zFile,
bool  bVerbose = false,
os::String  zTitle = "Select handler",
bool  bDefaultHandler = true 
)
Description:
Launches a file. Executables will be started and other files will be run with their associated application. In verbose mode a dialog is presented to the user that lets him select the right filetype if no default handler is present.
Parameters
pcParentWindow- Parent window. Can be NULL. The handler selector will be centered in this window.
zFile- Absolute path to the file.
bVerbose- Activates verbose mode.
zTitle- Title of the handler selector.
bDefaultHandler- If set to false, the handler selector will always be shown.
Returns
0 if successful.
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::String::c_str(), os::Window::CenterInScreen(), os::Window::CenterInWindow(), os::Message::FindString(), os::Path::GetPath(), GetTypeAndIcon(), os::Window::MakeFocus(), os::Window::SetTitle(), and os::Window::Show().

Referenced by os::IconDirectoryView::HandleMessage(), and os::IconDirectoryView::Invoked().

void RegistrarManager::Put ( bool  bAll = false)
Description:
Decrements the reference counter of the instance.
Note:
Make sure that you do one call to this method for every Get() call in your appliction.
See Also
Get()
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::RegistrarManager::Private::m_bCloseAllOnQuit, os::RegistrarManager::Private::m_nRefCount, os::M_QUIT, and os::Looper::PostMessage().

Referenced by InfoWin::HandleMessage(), HandlerSelector::HandlerSelector(), InfoWin::InfoWin(), and os::IconDirectoryView::~IconDirectoryView().

status_t RegistrarManager::RegisterAsTypeHandler ( String  zMimeType)
Description:
Registers the current application as a handler for a type.
Parameters
zMimeType- Mimetype of the type.
Returns
0 if the call was successful.
See Also
RegisteTypeHandler()
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References RegisterTypeHandler().

status_t RegistrarManager::RegisterType ( String  zMimeType,
String  zIdentifier,
bool  bOverwrite = false 
)
Description:
Registers a new filetype.
Parameters
zMimeType- Mimetype of the new type.
zIdentifier- Name of the type.
bOverwrite- Whether the name should be overwritten if a type with the same mimetype already exists. false is almost always right.
Returns
0 if the call was successful.
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::Message::AddBool(), os::Message::AddInt64(), os::Message::AddString(), os::Message::GetCode(), os::Looper::GetMsgPort(), os::RegistrarManager::Private::m_bSync, os::RegistrarManager::Private::m_cServerLink, os::RegistrarManager::Private::m_pzUser, os::REGISTRAR_OK, os::REGISTRAR_REGISTER_TYPE, and os::Messenger::SendMessage().

status_t RegistrarManager::RegisterTypeExtension ( String  zMimeType,
String  zExtension 
)
Description:
Registers a new extension for a type. This is especially important for files on non native Syllable partitions.
Parameters
zMimeType- Mimetype of the type.
zExtension- Extension that should be registeread.
Returns
0 if the call was successful.
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::Message::AddInt64(), os::Message::AddString(), os::Message::GetCode(), os::Looper::GetMsgPort(), os::String::Lower(), os::RegistrarManager::Private::m_bSync, os::RegistrarManager::Private::m_cServerLink, os::RegistrarManager::Private::m_pzUser, os::REGISTRAR_OK, os::REGISTRAR_REGISTER_TYPE_EXTENSION, and os::Messenger::SendMessage().

status_t RegistrarManager::RegisterTypeHandler ( String  zMimeType,
Path  cHandler 
)
Description:
Registers a new handler for a type.
Note:
If this is the first handler that is registered for the type then it will become the default handler.
Parameters
zMimeType- Mimetype of the type.
cHandler- Absolute path to the handler.
Returns
0 if the call was successful.
See Also
RegisterAsTypeHandler()
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::Message::AddInt64(), os::Message::AddString(), os::Message::GetCode(), os::Looper::GetMsgPort(), os::Path::GetPath(), os::RegistrarManager::Private::m_bSync, os::RegistrarManager::Private::m_cServerLink, os::RegistrarManager::Private::m_pzUser, os::REGISTRAR_OK, os::REGISTRAR_REGISTER_TYPE_HANDLER, and os::Messenger::SendMessage().

Referenced by RegisterAsTypeHandler().

status_t RegistrarManager::RegisterTypeIcon ( String  zMimeType,
Path  cIcon,
bool  bOverwrite = false 
)
Description:
Sets a new icon for a filetype.
Parameters
zMimeType- Mimetype of the type.
zIcon- Path to the new icon. The icon should be in /boot/System/resources/icons/filetypes/.
bOverwrite- Whether the icon should be overwritten if a type with the same mimetype already exists. false is almost always right.
Returns
0 if the call was successful.
See Also
RegisterTypeIconFromRes()
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::Message::AddBool(), os::Message::AddInt64(), os::Message::AddString(), os::Message::GetCode(), os::Looper::GetMsgPort(), os::Path::GetPath(), os::RegistrarManager::Private::m_bSync, os::RegistrarManager::Private::m_cServerLink, os::RegistrarManager::Private::m_pzUser, os::REGISTRAR_OK, os::REGISTRAR_REGISTER_TYPE_ICON, and os::Messenger::SendMessage().

Referenced by RegisterTypeIconFromRes().

status_t RegistrarManager::RegisterTypeIconFromRes ( String  zMimeType,
String  zIconRes,
bool  bOverwrite = false 
)
Description:
Sets a new icon for a filetype. The icon will be extracted from the application resources.
Parameters
zMimeType- Mimetype of the type.
zIconRes- Resource name of the icon.
bOverwrite- Whether the icon should be overwritten if a type with the same mimetype already exists. false is almost always right.
Returns
0 if the call was successful.
See Also
RegisterTypeIcon()
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::String::c_str(), os::File::Flush(), os::Resources::GetResourceStream(), os::ResStream::Read(), RegisterTypeIcon(), os::FSNode::SetTo(), os::FSNode::Unset(), and os::File::Write().

status_t RegistrarManager::SetDefaultHandler ( String  zMimeType,
Path  zHandler 
)
Description:
Sets the default handler for a type. Make sure the handler is already registered.
Parameters
zMimeType- Mimetype of the type.
zHandler- Absoulte path to the handler.
Returns
0 if successful.
See Also
RegisterTypeHandler()
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::Message::AddInt64(), os::Message::AddString(), os::Message::GetCode(), os::Looper::GetMsgPort(), os::Path::GetPath(), os::RegistrarManager::Private::m_bSync, os::RegistrarManager::Private::m_cServerLink, os::RegistrarManager::Private::m_pzUser, os::REGISTRAR_OK, os::REGISTRAR_SET_DEFAULT_HANDLER, and os::Messenger::SendMessage().

void RegistrarManager::SetSynchronousMode ( bool  bSync)
Description:
Sets whether the registrar manager class is in synchronous mode. If this mode is activated, then all methods of this class will wait until the registrar server has updated its database.
Note:
The default value is false. This is ok in 99% of all cases.
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::RegistrarManager::Private::m_bSync.

status_t RegistrarManager::UnregisterType ( String  zMimeType)
void RegistrarManager::UpdateAppList ( bool  bForce = false)
Description:
The registrar manages a list of installed applications in the /Applications folder. Using this method you can tell it to update this list.
Parameters
bForce- Force the registrar to update the list.
Author
Arno Klenke (arno_.nosp@m.klen.nosp@m.ke@ya.nosp@m.hoo..nosp@m.de)

References os::Message::AddString(), os::RegistrarManager::Private::m_bSync, os::RegistrarManager::Private::m_cServerLink, os::RegistrarManager::Private::m_pzUser, os::REGISTRAR_UPDATE_APP_LIST, and os::Messenger::SendMessage().