The Gnome Chemistry Utils  0.13.7
gcu/application.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /*
00004  * Gnome Chemistry Utils
00005  * gcu/application.h
00006  *
00007  * Copyright (C) 2005-2012 Jean Bréfort <jean.brefort@normalesup.org>
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License as
00011  * published by the Free Software Foundation; either version 3 of the
00012  * License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00022  * USA
00023  */
00024 
00025 #ifndef GCU_APPLICATION_H
00026 #define GCU_APPLICATION_H
00027 
00028 #include "dialog-owner.h"
00029 #include "structs.h"
00030 #include "object.h"
00031 #include <list>
00032 #include <map>
00033 #include <set>
00034 #include <string>
00035 #include <gcu/macros.h>
00036 
00038 namespace gcu {
00039 
00040 class Document;
00041 class Dialog;
00042 struct option_data;
00043 class TypeDesc;
00044 class CmdContext;
00045 class UIManager;
00046 
00047 typedef struct {
00048         std::string name;
00049         std::string uri;
00050 } Database;
00051 
00052 #define GCU_CONF_DIR "gchemutils"
00053 
00057 class Application: virtual public DialogOwner
00058 {
00059 friend class Document;
00060 friend class Dialog;
00061 public:
00075         Application (std::string name, std::string datadir = DATADIR, char const *help_name = NULL, char const *icon_name = NULL, CmdContext *cc = NULL);
00079         virtual ~Application ();
00080 
00089         void OnHelp (std::string s = "");
00093         bool HasHelp ();
00097         std::string const &GetName () const {return Name;}
00098 
00102         virtual GtkWindow * GetWindow () {return NULL;}
00103 
00117         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)
00118                 {return false;}
00119 
00123         char const* GetCurDir () {return CurDir.c_str ();}
00124 
00128         void SetCurDir (char const* dir);
00129 
00133         void SetCurDir (std::string const &dir);
00134 
00138         std::map<std::string, GdkPixbufFormat*> &GetSupportedPixbufFormats () {return m_SupportedPixbufFormats;}
00139 
00149         char const *GetPixbufTypeName (std::string& filename, char const *mime_type);
00150 
00162         ContentType Load (std::string const &uri, const char *mime_type, Document* Doc, const char *options = NULL);
00163 
00175         ContentType Load (GsfInput *input, const char *mime_type, Document* Doc, const char *options = NULL);
00176 
00189         bool Save (std::string const &uri, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00190 
00203         bool Save (GsfOutput *output, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00204 
00209         virtual Document *CreateNewDocument () {return NULL;}
00210 
00215         static GOConfNode *GetConfDir ();
00216 
00221         std::string const &GetIconName () {return IconName;}
00222 
00230         void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00231 
00238         void AddOptions (GOptionContext *context);
00239 
00244         static Application *GetDefaultApplication ();
00245 
00251         static Application *GetApplication (char const *name);
00252 
00258         static Application *GetApplication (std::string &name);
00259 
00260         // Object creation related methods
00270         TypeId AddType (std::string TypeName, Object* (*CreateFunc) (), TypeId id = OtherType);
00271 
00282         Object* CreateObject (const std::string& TypeName, Object* parent = NULL);
00290         void AddRule (TypeId type1, RuleId rule, TypeId type2);
00298         void AddRule (const std::string& type1, RuleId rule, const std::string& type2);
00305          const std::set<TypeId>& GetRules (TypeId type, RuleId rule);
00306 
00313         const std::set<TypeId>& GetRules (const std::string& type, RuleId rule);
00314 
00322         void SetCreationLabel (TypeId Id, std::string Label);
00323 
00329         const std::string& GetCreationLabel (TypeId Id);
00330 
00342         bool BuildObjectContextualMenu (Object *target, UIManager *uim, Object *object, double x, double y);
00343 
00350         void AddMenuCallback (TypeId Id, BuildMenuCb cb);
00351 
00357         const std::string& GetCreationLabel (const std::string& TypeName);
00358 
00359         TypeDesc const *GetTypeDescription (TypeId Id);
00360 
00364         CmdContext *GetCmdContext ();
00365 
00374         char* ConvertToCML (std::string const &uri, const char *mime_type, const char *options = NULL);
00375 
00384         char* ConvertToCML (GsfInput *input, const char *mime_type, const char *options = NULL);
00385 
00394         void ConvertFromCML (const char *cml, std::string const &uri, const char *mime_type, const char *options = NULL);
00395 
00404         void ConvertFromCML (const char *cml, GsfOutput *output, const char *mime_type, const char *options = NULL);
00405 
00410         std::list < Database > const &GetDatabases (char const *classname) {return m_Databases[classname];}
00411 
00412 protected:
00420         void RegisterBabelType (const char *mime_type, const char *type);
00421 
00426         virtual void CreateDefaultCmdContext () {}
00427 
00432         virtual bool LoopRunning () {return false;}
00433 
00439         virtual void NoMoreDocsEvent () {}
00443         std::map<std::string, GdkPixbufFormat*> m_SupportedPixbufFormats;
00444 
00448         CmdContext *m_CmdContext;
00449 
00450 private:
00451         void AddDocument (Document *Doc) {m_Docs.insert (Doc);}
00452         void RemoveDocument (Document *Doc);
00453         int OpenBabelSocket ();
00454         char const *MimeToBabelType (char const *mime_type);
00455 
00456 private:
00457         std::string Name;
00458         std::string HelpName;
00459         std::string HelpBrowser;
00460         std::string HelpFilename;
00461         std::string CurDir;
00462         std::string IconName;
00463         static GOConfNode *m_ConfDir;
00464         std::list <option_data> m_Options;
00465         std::map <TypeId, TypeDesc> m_Types;
00466         std::map <std::string, std::string> m_BabelTypes;
00467         std::map < std::string, std::list <Database> >m_Databases;
00468 
00475 GCU_PROT_PROP (std::set <Document*>, Docs)
00479 GCU_PROT_PROP (unsigned, ScreenResolution)
00493 GCU_PROP (unsigned, ImageResolution)
00507 GCU_PROP (unsigned, ImageWidth)
00521 GCU_PROP (unsigned, ImageHeight)
00533 GCU_PROP (bool, TransparentBackground)
00534 };
00535 
00536 }       // namespace gcu
00537 
00538 #endif // GCU_APPLICATION_H