The Gnome Chemistry Utils 0.13.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
gcu::Application Class Reference

#include <gcu/application.h>

Inheritance diagram for gcu::Application:
gcu::DialogOwner

List of all members.

Public Member Functions

 Application (std::string name, std::string datadir=DATADIR, char const *help_name=NULL, char const *icon_name=NULL, CmdContext *cc=NULL)
virtual ~Application ()
void OnHelp (std::string s="")
bool HasHelp ()
std::string const & GetName () const
virtual GtkWindow * GetWindow ()
virtual bool FileProcess (G_GNUC_UNUSED const gchar *filename, G_GNUC_UNUSED const gchar *mime_type, G_GNUC_UNUSED bool bSave, G_GNUC_UNUSED GtkWindow *window, G_GNUC_UNUSED Document *pDoc=NULL)
char const * GetCurDir ()
void SetCurDir (char const *dir)
void SetCurDir (std::string const &dir)
void ShowURI (std::string &uri)
void OnBug (char const *uri=PACKAGE_BUGREPORT)
void OnWeb (char const *uri="http://gchemutils.nongnu.org/")
void OnMail (char const *MailAddress="mailto:gchemutils-main@nongnu.org")
void OnLiveAssistance ()
std::map< std::string,
GdkPixbufFormat * > & 
GetSupportedPixbufFormats ()
char const * GetPixbufTypeName (std::string &filename, char const *mime_type)
ContentType Load (std::string const &uri, const char *mime_type, Document *Doc, const char *options=NULL)
ContentType Load (GsfInput *input, const char *mime_type, Document *Doc, const char *options=NULL)
bool Save (std::string const &uri, const char *mime_type, Object const *Obj, ContentType type, const char *options=NULL)
bool Save (GsfOutput *output, const char *mime_type, Object const *Obj, ContentType type, const char *options=NULL)
virtual DocumentCreateNewDocument ()
std::string const & GetIconName ()
void RegisterOptions (GOptionEntry const *entries, char const *translation_domain=GETTEXT_PACKAGE)
void AddOptions (GOptionContext *context)
TypeId AddType (std::string TypeName, Object *(*CreateFunc)(), TypeId id=OtherType)
ObjectCreateObject (const std::string &TypeName, Object *parent=NULL)
void AddRule (TypeId type1, RuleId rule, TypeId type2)
void AddRule (const std::string &type1, RuleId rule, const std::string &type2)
const std::set< TypeId > & GetRules (TypeId type, RuleId rule)
const std::set< TypeId > & GetRules (const std::string &type, RuleId rule)
void SetCreationLabel (TypeId Id, std::string Label)
const std::string & GetCreationLabel (TypeId Id)
bool BuildObjectContextualMenu (Object *target, UIManager *uim, Object *object, double x, double y)
void AddMenuCallback (TypeId Id, BuildMenuCb cb)
const std::string & GetCreationLabel (const std::string &TypeName)
char * ConvertToCML (std::string const &uri, const char *mime_type, const char *options=NULL)
void ConvertFromCML (const char *cml, std::string const &uri, const char *mime_type, const char *options=NULL)
void ConvertFromCML (const char *cml, GsfOutput *output, const char *mime_type, const char *options=NULL)
std::set< Document * > GetDocs (void)
unsigned GetScreenResolution (void) const
void SetImageResolution (unsigned val)
unsigned GetImageResolution (void) const
unsigned & GetRefImageResolution (void)
void SetImageWidth (unsigned val)
unsigned GetImageWidth (void) const
unsigned & GetRefImageWidth (void)
void SetImageHeight (unsigned val)
unsigned GetImageHeight (void) const
unsigned & GetRefImageHeight (void)
void SetTransparentBackground (bool val)
bool GetTransparentBackground (void) const
bool & GetRefTransparentBackground (void)

Static Public Member Functions

static GOConfNode * GetConfDir ()
static ApplicationGetDefaultApplication ()

Protected Member Functions

virtual void NoMoreDocsEvent ()

Protected Attributes

std::map< std::string,
GdkPixbufFormat * > 
m_SupportedPixbufFormats
std::set< Document * > m_Docs

Detailed Description

This class is a base class for applications. It provides some basic services.

Definition at line 57 of file gcu/application.h.


Constructor & Destructor Documentation

gcu::Application::Application ( std::string  name,
std::string  datadir = DATADIR,
char const *  help_name = NULL,
char const *  icon_name = NULL,
CmdContext *  cc = NULL 
)
Parameters:
namethe name of the application.
datadirwhere data for the application are stored.
help_namethe name to use for the help file (with .xml extension). If NULL, the name parameter is used.
icon_namethe name to use for the default icon of all windows. If NULL, the help_name or name parameters will be used.

The datadir variable is used to build the full path to the help file: "file://"+datadir+"/gnome/help/"+name+"/"+LANG+"/"+name".xml".

virtual gcu::Application::~Application ( ) [virtual]

The destructor.


Member Function Documentation

void gcu::Application::AddMenuCallback ( TypeId  Id,
BuildMenuCb  cb 
)
Parameters:
Idthe TypeId of the Object derived class
cbthe BuildMenuCb callback to call when building the menu.

adds a callback for modifying the contextual menu of objects of type Id.

void gcu::Application::AddOptions ( GOptionContext *  context)
Parameters:
context,:a GOptionContext

Adds all registered options to the context. This should be called once just after creating the application and before parsing options.

void gcu::Application::AddRule ( TypeId  type1,
RuleId  rule,
TypeId  type2 
)
Parameters:
type1the TypeId of the first class in the rule
rulethe new rule value
type2the TypeId of the second class in the rule

Adds a rule.

void gcu::Application::AddRule ( const std::string &  type1,
RuleId  rule,
const std::string &  type2 
)
Parameters:
type1the name of the first class in the rule
rulethe new rule value
type2the name of the second class in the rule

Adds a rule.

TypeId gcu::Application::AddType ( std::string  TypeName,
Object *(*)()  CreateFunc,
TypeId  id = OtherType 
)
Parameters:
TypeNamethe name of the new type.
CreateFunca pointer to a function returning a pointer to a new object of the new type.
idthe Id of the type to create if a standard one or OtherType for a new type. In this last case, this parameter can be omitted.

This method is used to register a new type derived from Object.

Returns:
the Id of the new type.
bool gcu::Application::BuildObjectContextualMenu ( Object target,
UIManager *  uim,
Object object,
double  x,
double  y 
)
Parameters:
uimthe UIManager to populate.
objectthe Object on which occured the mouse click.
xx coordinate of the mouse click.
yy coordinate of the mouse click.

This method is called to build a contextual menu for the object. It is called by Object::BuildContextualMenu, so it should not be necessary to call it directly.

Returns:
true if something is added to the UIManager, false otherwise.
void gcu::Application::ConvertFromCML ( const char *  cml,
std::string const &  uri,
const char *  mime_type,
const char *  options = NULL 
)
Parameters:
cml,:the CML string to convert.
urithe uri of the document to which the document will be saved.
mime_typethe mime type of the document.
optionsoptions to pass to OpenBabel.

This method converts CML to a target.

void gcu::Application::ConvertFromCML ( const char *  cml,
GsfOutput *  output,
const char *  mime_type,
const char *  options = NULL 
)
Parameters:
cml,:the CML string to convert.
outputa target GsfOutput.
mime_typethe mime type of the document.
optionsoptions to pass to OpenBabel.

This method converts CML to a target.

char* gcu::Application::ConvertToCML ( std::string const &  uri,
const char *  mime_type,
const char *  options = NULL 
)
Parameters:
inputa source GsfInput.
mime_typethe mime type of the document.
optionsoptions to pass to OpenBabel.

This method converts the source to CML.

Returns:
the converted text as a newly allocate string or NULL.
virtual Document* gcu::Application::CreateNewDocument ( ) [inline, virtual]

Virtual method used to create documents. Default behavior does nothing and returns NULL.

Returns:
the newly created document or NULL.

Definition at line 234 of file gcu/application.h.

Object* gcu::Application::CreateObject ( const std::string &  TypeName,
Object parent = NULL 
)
Parameters:
TypeNamethe name of the new type.
parentthe parent of the newly created object or NULL. if NULL, the parameter can be omitted.

Used to create an object of type name TypeName. The AddType() method must have been called with the same TypeName parameter. if parent is given and not NULL, the new Object will be a child of parent. It will also be given a default Id.

Returns:
a pointer to the newly created Object or NULL if the Object could not be created.
virtual bool gcu::Application::FileProcess ( G_GNUC_UNUSED const gchar *  filename,
G_GNUC_UNUSED const gchar *  mime_type,
G_GNUC_UNUSED bool  bSave,
G_GNUC_UNUSED GtkWindow *  window,
G_GNUC_UNUSED Document pDoc = NULL 
) [inline, virtual]
Parameters:
filenamethe uri of the file.
mime_typethe mime type of the file if known.
bSavetrue if saving, and false if loading.
windowthe current top level window.
pDocan optional document.

Called by the FileChooser when a file name has been selected. This method does nothing in the parent class and must be implemented in children classes if they use the FileChooser.

Returns:
true if no error occured.

Definition at line 115 of file gcu/application.h.

static GOConfNode* gcu::Application::GetConfDir ( ) [static]

Method used to retrieve the base configuration node.

Returns:
the base configuration node.
const std::string& gcu::Application::GetCreationLabel ( TypeId  Id)
Parameters:
Idthe TypeId of a class
Returns:
the string defined by SetCreationLabel.
const std::string& gcu::Application::GetCreationLabel ( const std::string &  TypeName)
Parameters:
TypeNamethe name of a class
Returns:
the string defined by SetCreationLabel.
char const* gcu::Application::GetCurDir ( ) [inline]
Returns:
the path to the current directory.

Definition at line 121 of file gcu/application.h.

static Application* gcu::Application::GetDefaultApplication ( ) [static]
Returns:
a dummy Application instance which might be used when there is no other Application available.
gcu::Application::GetDocs ( void  ) [inline]
Returns:
the set of currently opened documents.

Definition at line 451 of file gcu/application.h.

std::string const& gcu::Application::GetIconName ( ) [inline]

Retrieves the icon name that should be set to every window owned by the application.

Returns:
the icon name for the appication.

Definition at line 246 of file gcu/application.h.

gcu::Application::GetImageHeight ( void  ) const [inline]
Returns:
the current image height used on export.

Definition at line 497 of file gcu/application.h.

gcu::Application::GetImageResolution ( void  ) const [inline]
Returns:
the current image resolution used on export.

Definition at line 469 of file gcu/application.h.

gcu::Application::GetImageWidth ( void  ) const [inline]
Returns:
the current image width used on export.

Definition at line 483 of file gcu/application.h.

std::string const& gcu::Application::GetName ( ) const [inline]
Returns:
the name of the application. Mostly useful to set the icon name of a new window.

Definition at line 95 of file gcu/application.h.

char const* gcu::Application::GetPixbufTypeName ( std::string &  filename,
char const *  mime_type 
)
Parameters:
filenamethe file name.
mime_typethe file mime type.

A default extension is appended to filename if none is detected.

Returns:
the GdkPixbuf name associated to mime_type or NULL if the file type is not supported by GdkPixbuf.
gcu::Application::GetRefImageHeight ( void  ) [inline]
Returns:
the current image height used on export as a reference.

Definition at line 497 of file gcu/application.h.

gcu::Application::GetRefImageResolution ( void  ) [inline]
Returns:
the current image resolution used on export as a reference.

Definition at line 469 of file gcu/application.h.

gcu::Application::GetRefImageWidth ( void  ) [inline]
Returns:
the current image width used on export as a reference.

Definition at line 483 of file gcu/application.h.

gcu::Application::GetRefTransparentBackground ( void  ) [inline]
Returns:
whether exported image have a transparent background as a reference.

Definition at line 509 of file gcu/application.h.

const std::set<TypeId>& gcu::Application::GetRules ( TypeId  type,
RuleId  rule 
)
Parameters:
typethe TypeId of a class
rulea RuleId value
Returns:
the set of rules correponding to the RuleId value for this class.
const std::set<TypeId>& gcu::Application::GetRules ( const std::string &  type,
RuleId  rule 
)
Parameters:
typethe name of a class
rulea RuleId value
Returns:
the set of rules correponding to the RuleId value for this class.
gcu::Application::GetScreenResolution ( void  ) const [inline]
Returns:
the current screen resolution.

Definition at line 455 of file gcu/application.h.

std::map<std::string, GdkPixbufFormat*>& gcu::Application::GetSupportedPixbufFormats ( ) [inline]
Returns:
a std::map of the supported pixbuf formats. Keys are the mime type names.

Definition at line 171 of file gcu/application.h.

References m_SupportedPixbufFormats.

gcu::Application::GetTransparentBackground ( void  ) const [inline]
Returns:
whether exported image have a transparent background.

Definition at line 509 of file gcu/application.h.

virtual GtkWindow* gcu::Application::GetWindow ( ) [inline, virtual]
Returns:
a GtkWindow if any. Should be overloaded by children classes.

Definition at line 100 of file gcu/application.h.

bool gcu::Application::HasHelp ( )
Returns:
true if both a help browser and a help file are available, false otherwise.
ContentType gcu::Application::Load ( std::string const &  uri,
const char *  mime_type,
Document Doc,
const char *  options = NULL 
)
Parameters:
urithe uri of the document to load.
mime_typethe mime type of the document.
Docthe document instance which will contain the loaded data.

This method loads a document using the appropriate gcu::Loader class instance.

Returns:
the found ContentType ot ContentTypeUnknown if an error occured.
ContentType gcu::Application::Load ( GsfInput *  input,
const char *  mime_type,
Document Doc,
const char *  options = NULL 
)
Parameters:
inputa GsfInput.
mime_typethe mime type of the document.
Docthe document instance which will contain the loaded data.

This method loads a document using the appropriate gcu::Loader class instance.

Returns:
the found ContentType ot ContentTypeUnknown if an error occured.
virtual void gcu::Application::NoMoreDocsEvent ( ) [inline, protected, virtual]

This method is called by the framework when all the documents have been removed from the set of opened documents. The default behavior is to do nothing Derived class might overide this method to change this.

Definition at line 435 of file gcu/application.h.

void gcu::Application::OnBug ( char const *  uri = PACKAGE_BUGREPORT) [inline]
Parameters:
urithe uri to the package bugs database. Default value is PACKAGE_BUGREPORT.

Opens the bugs web page in the default browser if any.

Definition at line 145 of file gcu/application.h.

References ShowURI().

void gcu::Application::OnHelp ( std::string  s = "")
Parameters:
san optional tag in the help file. Displays the help file using the file browser retrieved from GConf using the "/desktop/gnome/applications/help_viewer/exec" key. If a tag is given, it will be added to the help uri. For an application named "myapp" and a tag "mytag", the uri will be: helpfilename#myapp-mytag.
void gcu::Application::OnLiveAssistance ( )

Attempts to open the #gchemutils channel at irc.gimp.net.

void gcu::Application::OnMail ( char const *  MailAddress = "mailto:gchemutils-main@nongnu.org")
Parameters:
MailAddressthe mail adress to which a message will be sent. Defaults to the Gnome Chemistry Utils main list.

Creates a new empty message using the default mail if any.

void gcu::Application::OnWeb ( char const *  uri = "http://gchemutils.nongnu.org/") [inline]
Parameters:
urithe uri to the main web page of the program. Default value is "http://gchemutils.nongnu.org/".

Definition at line 152 of file gcu/application.h.

References ShowURI().

void gcu::Application::RegisterOptions ( GOptionEntry const *  entries,
char const *  translation_domain = GETTEXT_PACKAGE 
)
Parameters:
entries,:the entries to register.
translation_domain,:the entries to register.

Adds new command line options. Typically called from a plugin. The new options are added to the main group.

bool gcu::Application::Save ( std::string const &  uri,
const char *  mime_type,
Object const *  Obj,
ContentType  type,
const char *  options = NULL 
)
Parameters:
urithe uri to which the document should be saved.
mime_typethe mime type of the document.
Objthe object instance which contains the data to be saved.
typethe type of the data to be saved (see gcu::ContentType).

This method saves the document using the appropriate gcu::Loader class instance.

Returns:
true if no error occurred.
bool gcu::Application::Save ( GsfOutput *  output,
const char *  mime_type,
Object const *  Obj,
ContentType  type,
const char *  options = NULL 
)
Parameters:
outputa GsfOutput.
mime_typethe mime type of the document.
Objthe object instance which contains the data to be saved.
typethe type of the data to be saved (see gcu::ContentType).

This method saves the document using the appropriate gcu::Loader class instance using output as target.

Returns:
true if no error occurred.
void gcu::Application::SetCreationLabel ( TypeId  Id,
std::string  Label 
)
Parameters:
Idthe TypeId of a class
Labelthe string to display in a contextual menu

Used to give a label for contextual menus used when the creation of an instance of the class seems possible.

void gcu::Application::SetCurDir ( char const *  dir)
Parameters:
dirthe path to the new current directory.
void gcu::Application::SetCurDir ( std::string const &  dir)
Parameters:
dirthe path to the new current directory.
gcu::Application::SetImageHeight ( unsigned  Height) [inline]
Parameters:
Heightthe new image height.

Sets the image height used when exporting a pixmap. Applications can use either the image resolution or the width and height to select an exported image size, but not both.

Definition at line 497 of file gcu/application.h.

gcu::Application::SetImageResolution ( unsigned  ImageResolution) [inline]
Parameters:
ImageResolutionthe new image resolution.

Sets the image resolution used when exporting a pixmap. Applications can use either the image resolution or the width and height to select an exported image size, but not both.

Definition at line 469 of file gcu/application.h.

gcu::Application::SetImageWidth ( unsigned  Width) [inline]
Parameters:
Widththe new image width.

Sets the image width used when exporting a pixmap. Applications can use either the image resolution or the width and height to select an exported image size, but not both.

Definition at line 483 of file gcu/application.h.

gcu::Application::SetTransparentBackground ( bool  transparent) [inline]
Parameters:
transparentwhether an export image should have a transparent background.

Sets the transparency of the exported image when possible.

Definition at line 509 of file gcu/application.h.

void gcu::Application::ShowURI ( std::string &  uri)
Parameters:
urithe uri to display.

Displays uri in the default web browser if any.

Referenced by OnBug(), and OnWeb().


Member Data Documentation

The currently opened documents.

Definition at line 451 of file gcu/application.h.

std::map<std::string, GdkPixbufFormat*> gcu::Application::m_SupportedPixbufFormats [protected]

std::map of the supported pixbuf formats. Keys are the mime type names.

Definition at line 439 of file gcu/application.h.

Referenced by GetSupportedPixbufFormats().


The documentation for this class was generated from the following file: