The Gnome Chemistry Utils  0.13.6
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 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:
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 
00140         void ShowURI (std::string& uri);
00141 
00147         void OnBug (char const *uri = PACKAGE_BUGREPORT)
00148                 {std::string s (uri); ShowURI (s);}
00149 
00154         void OnWeb (char const *uri = "http://gchemutils.nongnu.org/")
00155                 {std::string s (uri); ShowURI (s);}
00156 
00163         void OnMail (char const *MailAddress = "mailto:gchemutils-main@nongnu.org");
00164 
00168         void OnLiveAssistance ();
00169 
00173         std::map<std::string, GdkPixbufFormat*> &GetSupportedPixbufFormats () {return m_SupportedPixbufFormats;}
00174 
00184         char const *GetPixbufTypeName (std::string& filename, char const *mime_type);
00185 
00197         ContentType Load (std::string const &uri, const char *mime_type, Document* Doc, const char *options = NULL);
00198 
00210         ContentType Load (GsfInput *input, const char *mime_type, Document* Doc, const char *options = NULL);
00211 
00224         bool Save (std::string const &uri, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00225 
00238         bool Save (GsfOutput *output, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00239 
00244         virtual Document *CreateNewDocument () {return NULL;}
00245 
00250         static GOConfNode *GetConfDir ();
00251 
00256         std::string const &GetIconName () {return IconName;}
00257 
00265         void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00266 
00273         void AddOptions (GOptionContext *context);
00274 
00279         static Application *GetDefaultApplication ();
00280 
00286         static Application *GetApplication (char const *name);
00287 
00293         static Application *GetApplication (std::string &name);
00294 
00295         // Object creation related methods
00305         TypeId AddType (std::string TypeName, Object* (*CreateFunc) (), TypeId id = OtherType);
00306 
00317         Object* CreateObject (const std::string& TypeName, Object* parent = NULL);
00325         void AddRule (TypeId type1, RuleId rule, TypeId type2);
00333         void AddRule (const std::string& type1, RuleId rule, const std::string& type2);
00340          const std::set<TypeId>& GetRules (TypeId type, RuleId rule);
00341 
00348         const std::set<TypeId>& GetRules (const std::string& type, RuleId rule);
00349 
00357         void SetCreationLabel (TypeId Id, std::string Label);
00358 
00364         const std::string& GetCreationLabel (TypeId Id);
00365 
00377         bool BuildObjectContextualMenu (Object *target, UIManager *uim, Object *object, double x, double y);
00378 
00385         void AddMenuCallback (TypeId Id, BuildMenuCb cb);
00386 
00392                     const std::string& GetCreationLabel (const std::string& TypeName);
00393 
00394         TypeDesc const *GetTypeDescription (TypeId Id);
00395 
00399         CmdContext *GetCmdContext ();
00400 
00409         char* ConvertToCML (std::string const &uri, const char *mime_type, const char *options = NULL);
00410 
00419         char* ConvertToCML (GsfInput *input, const char *mime_type, const char *options = NULL);
00420 
00429         void ConvertFromCML (const char *cml, std::string const &uri, const char *mime_type, const char *options = NULL);
00430 
00439         void ConvertFromCML (const char *cml, GsfOutput *output, const char *mime_type, const char *options = NULL);
00440 
00443                     std::list < Database > const &GetDatabases (char const *classname) {return m_Databases[classname];}
00444 
00445 protected:
00453         void RegisterBabelType (const char *mime_type, const char *type);
00454 
00459         virtual void CreateDefaultCmdContext () {}
00460 
00465         virtual bool LoopRunning () {return false;}
00466 
00472         virtual void NoMoreDocsEvent () {}
00476         std::map<std::string, GdkPixbufFormat*> m_SupportedPixbufFormats;
00477 
00481         CmdContext *m_CmdContext;
00482 
00483 private:
00484         void AddDocument (Document *Doc) {m_Docs.insert (Doc);}
00485         void RemoveDocument (Document *Doc);
00486         int OpenBabelSocket ();
00487         char const *MimeToBabelType (char const *mime_type);
00488 
00489 private:
00490         std::string Name;
00491         std::string HelpName;
00492         std::string HelpBrowser;
00493         std::string HelpFilename;
00494         std::string CurDir;
00495         std::string IconName;
00496         static GOConfNode *m_ConfDir;
00497         std::list <option_data> m_Options;
00498         std::map <TypeId, TypeDesc> m_Types;
00499         std::map <std::string, std::string> m_BabelTypes;
00500         std::map < std::string, std::list <Database> >m_Databases;
00501 
00508 GCU_PROT_PROP (std::set <Document*>, Docs)
00512 GCU_PROT_PROP (unsigned, ScreenResolution)
00526 GCU_PROP (unsigned, ImageResolution)
00540 GCU_PROP (unsigned, ImageWidth)
00554 GCU_PROP (unsigned, ImageHeight)
00566 GCU_PROP (bool, TransparentBackground)
00567 };
00568 
00569 }       // namespace gcu
00570 
00571 #endif // GCU_APPLICATION_H