The Gnome Chemistry Utils 0.13.3
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-2011 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 2 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:
00073         Application (std::string name, std::string datadir = DATADIR, char const *help_name = NULL, char const *icon_name = NULL, CmdContext *cc = NULL);
00077         virtual ~Application ();
00078 
00087         void OnHelp (std::string s = "");
00091         bool HasHelp ();
00095         std::string const &GetName () const {return Name;}
00096 
00100         virtual GtkWindow * GetWindow () {return NULL;}
00101 
00115         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)
00116                 {return false;}
00117 
00121         char const* GetCurDir () {return CurDir.c_str ();}
00122 
00126         void SetCurDir (char const* dir);
00127 
00131         void SetCurDir (std::string const &dir);
00132 
00138         void ShowURI (std::string& uri);
00139 
00145         void OnBug (char const *uri = PACKAGE_BUGREPORT)
00146                 {std::string s (uri); ShowURI (s);}
00147 
00152         void OnWeb (char const *uri = "http://gchemutils.nongnu.org/")
00153                 {std::string s (uri); ShowURI (s);}
00154 
00161         void OnMail (char const *MailAddress = "mailto:gchemutils-main@nongnu.org");
00162 
00166         void OnLiveAssistance ();
00167 
00171         std::map<std::string, GdkPixbufFormat*> &GetSupportedPixbufFormats () {return m_SupportedPixbufFormats;}
00172 
00182         char const *GetPixbufTypeName (std::string& filename, char const *mime_type);
00183 
00193         ContentType Load (std::string const &uri, const char *mime_type, Document* Doc, const char *options = NULL);
00194                      
00204         ContentType Load (GsfInput *input, const char *mime_type, Document* Doc, const char *options = NULL);
00205                     
00216         bool Save (std::string const &uri, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00217                     
00228         bool Save (GsfOutput *output, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00229 
00234         virtual Document *CreateNewDocument () {return NULL;}
00235 
00240         static GOConfNode *GetConfDir ();
00241 
00246         std::string const &GetIconName () {return IconName;}
00247 
00255         void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00256 
00263         void AddOptions (GOptionContext *context);
00268         static Application *GetDefaultApplication ();
00269         static Application *GetApplication (char const *name);
00270         static Application *GetApplication (std::string &name);
00271 
00272         // Object creation related methods
00282         TypeId AddType (std::string TypeName, Object* (*CreateFunc) (), TypeId id = OtherType);
00283 
00294         Object* CreateObject (const std::string& TypeName, Object* parent = NULL);
00302         void AddRule (TypeId type1, RuleId rule, TypeId type2);
00310         void AddRule (const std::string& type1, RuleId rule, const std::string& type2);
00317          const std::set<TypeId>& GetRules (TypeId type, RuleId rule);
00318 
00325         const std::set<TypeId>& GetRules (const std::string& type, RuleId rule);
00326 
00334         void SetCreationLabel (TypeId Id, std::string Label);
00335 
00341         const std::string& GetCreationLabel (TypeId Id);
00342 
00353         bool BuildObjectContextualMenu (Object *target, UIManager *uim, Object *object, double x, double y);
00354 
00361         void AddMenuCallback (TypeId Id, BuildMenuCb cb);
00362                     
00368         const std::string& GetCreationLabel (const std::string& TypeName);
00369 
00370         TypeDesc const *GetTypeDescription (TypeId Id);
00371         CmdContext *GetCmdContext ();
00372 
00373 
00382         char* ConvertToCML (std::string const &uri, const char *mime_type, const char *options = NULL);
00383         char* ConvertToCML (GsfInput *input, const char *mime_type, const char *options = NULL);
00384 
00393         void ConvertFromCML (const char *cml, std::string const &uri, const char *mime_type, const char *options = NULL);
00394 
00403         void ConvertFromCML (const char *cml, GsfOutput *output, const char *mime_type, const char *options = NULL);
00404         std::list < Database > const &GetDatabases (char const *classname) {return m_Databases[classname];}
00405 
00406 protected:
00407         void RegisterBabelType (const char *mime_type, const char *type);
00408         virtual void CreateDefaultCmdContext () {}
00409 
00410 private:
00411         void AddDocument (Document *Doc) {m_Docs.insert (Doc);}
00412         void RemoveDocument (Document *Doc);
00413         int OpenBabelSocket ();
00414         char const *MimeToBabelType (char const *mime_type);
00415 
00416 private:
00417         std::string Name;
00418         std::string HelpName;
00419         std::string HelpBrowser;
00420         std::string HelpFilename;
00421         std::string CurDir;
00422         std::string IconName;
00423         static GOConfNode *m_ConfDir;
00424         std::list <option_data> m_Options;
00425         std::map <TypeId, TypeDesc> m_Types;
00426         std::map <std::string, std::string> m_BabelTypes;
00427 
00428 protected:
00429 
00435         virtual void NoMoreDocsEvent () {}
00439         std::map<std::string, GdkPixbufFormat*> m_SupportedPixbufFormats;
00440 
00441         CmdContext *m_CmdContext;
00442 
00443 private:
00444         std::map < std::string, std::list <Database> >m_Databases;
00451 GCU_PROT_PROP (std::set <Document*>, Docs)
00455 GCU_RO_PROP (unsigned, ScreenResolution)
00469 GCU_PROP (unsigned, ImageResolution)
00483 GCU_PROP (unsigned, ImageWidth)
00497 GCU_PROP (unsigned, ImageHeight)
00509 GCU_PROP (bool, TransparentBackground)
00510 };
00511 
00512 }       // namespace gcu
00513 
00514 #endif // GCU_APPLICATION_H