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 
00046 typedef struct {
00047         std::string name;
00048         std::string uri;
00049 } Database;
00050 
00054 typedef enum {
00058         NormalWindowState,
00062         MaximizedWindowState,
00066         MinimizedWindowState,
00070         FullScreenWindowState
00071 } WindowState;
00072 
00073 #define GCU_CONF_DIR "gchemutils"
00074 
00078 class Application: virtual public DialogOwner
00079 {
00080 friend class Document;
00081 friend class Dialog;
00082 friend class ApplicationPrivate;
00083 public:
00095         Application (std::string name, std::string datadir = DATADIR, char const *help_name = NULL, char const *icon_name = NULL, CmdContext *cc = NULL);
00099         virtual ~Application ();
00100 
00109         void OnHelp (std::string s = "");
00113         bool HasHelp ();
00117         std::string const &GetName () const {return Name;}
00118 
00122         virtual GtkWindow * GetWindow () {return NULL;}
00123 
00137         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)
00138                 {return false;}
00139 
00143         char const* GetCurDir () {return CurDir.c_str ();}
00144 
00148         void SetCurDir (char const* dir);
00149 
00153         void SetCurDir (std::string const &dir);
00154 
00160         void ShowURI (std::string& uri);
00161 
00167         void OnBug (char const *uri = PACKAGE_BUGREPORT)
00168                 {std::string s (uri); ShowURI (s);}
00169 
00174         void OnWeb (char const *uri = "http://gchemutils.nongnu.org/")
00175                 {std::string s (uri); ShowURI (s);}
00176 
00183         void OnMail (char const *MailAddress = "mailto:gchemutils-main@nongnu.org");
00184 
00188         void OnLiveAssistance ();
00189 
00194         GtkWidget *GetImageResolutionWidget ();
00195 
00200         GtkWidget *GetImageSizeWidget ();
00201 
00205         std::map<std::string, GdkPixbufFormat*> &GetSupportedPixbufFormats () {return m_SupportedPixbufFormats;}
00206 
00216         char const *GetPixbufTypeName (std::string& filename, char const *mime_type);
00217 
00227         ContentType Load (std::string const &uri, const gchar *mime_type, Document* Doc, const char *options = NULL);
00228                      
00238         ContentType Load (GsfInput *input, const gchar *mime_type, Document* Doc, const char *options = NULL);
00239                     
00250         bool Save (std::string const &uri, const gchar *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00251                     
00262         bool Save (GsfOutput *output, const gchar *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
00263 
00264 
00269         virtual Document *CreateNewDocument () {return NULL;}
00270 
00275         static GOConfNode *GetConfDir ();
00276 
00281         std::string const &GetIconName () {return IconName;}
00282 
00290         void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
00291 
00298         void AddOptions (GOptionContext *context);
00302         static WindowState GetDefaultWindowState () {return DefaultWindowState;}
00307         static Application *GetDefaultApplication ();
00308         static Application *GetApplication (char const *name);
00309         static Application *GetApplication (std::string &name);
00310 
00311         // Object creation related methods
00321         TypeId AddType (std::string TypeName, Object* (*CreateFunc) (), TypeId id = OtherType);
00322 
00333         Object* CreateObject (const std::string& TypeName, Object* parent = NULL);
00334 
00345         bool BuildObjectContextualMenu (Object *target, GtkUIManager *UIManager, Object *object, double x, double y);
00353         void AddRule (TypeId type1, RuleId rule, TypeId type2);
00361         void AddRule (const std::string& type1, RuleId rule, const std::string& type2);
00368          const std::set<TypeId>& GetRules (TypeId type, RuleId rule);
00369 
00376         const std::set<TypeId>& GetRules (const std::string& type, RuleId rule);
00377 
00385         void SetCreationLabel (TypeId Id, std::string Label);
00386 
00392         const std::string& GetCreationLabel (TypeId Id);
00393 
00399         const std::string& GetCreationLabel (const std::string& TypeName);
00400 
00407         void AddMenuCallback (TypeId Id, BuildMenuCb cb);
00408 
00409         TypeDesc const *GetTypeDescription (TypeId Id);
00410         CmdContext *GetCmdContext ();
00411 
00412         char* ConvertToCML (std::string const &uri, const char *mime_type, const char *options = NULL);
00413         char* ConvertToCML (GsfInput *input, const char *mime_type, const char *options = NULL);
00414         void ConvertFromCML (const char *cml, std::string const &uri, const char *mime_type, const char *options = NULL);
00415         void ConvertFromCML (const char *cml, GsfOutput *output, const char *mime_type, const char *options = NULL);
00416         std::list < Database > const &GetDatabases (char const *classname) {return m_Databases[classname];}
00417 
00418 protected:
00419 
00425         virtual void NoMoreDocsEvent () {gtk_main_quit ();}
00426 
00427         void RegisterBabelType (const char *mime_type, const char *type);
00428 
00429 private:
00430         void AddDocument (Document *Doc) {m_Docs.insert (Doc);}
00431         void RemoveDocument (Document *Doc);
00432         int OpenBabelSocket ();
00433         char const *MimeToBabelType (char const *mime_type);
00434 
00435 private:
00436         std::string Name;
00437         std::string HelpName;
00438         std::string HelpBrowser;
00439         std::string HelpFilename;
00440         std::string CurDir;
00441         std::string IconName;
00442         static GOConfNode *m_ConfDir;
00443         std::list <option_data> m_Options;
00444         static WindowState DefaultWindowState;
00445         std::map <TypeId, TypeDesc> m_Types;
00446         std::map <std::string, std::string> m_BabelTypes;
00447 
00448 protected:
00452         std::map<std::string, GdkPixbufFormat*> m_SupportedPixbufFormats;
00453 
00454         CmdContext *m_CmdContext;
00455 
00456 private:
00457         std::map < std::string, std::list <Database> >m_Databases;
00464 GCU_PROT_PROP (std::set <Document*>, Docs)
00468 GCU_RO_PROP (unsigned, ScreenResolution)
00482 GCU_PROP (unsigned, ImageResolution)
00496 GCU_PROP (unsigned, ImageWidth)
00510 GCU_PROP (unsigned, ImageHeight)
00522 GCU_PROP (bool, TransparentBackground)
00526 GCU_RO_PROP (GtkRecentManager*, RecentManager)
00527 };
00528 
00529 }       // namespace gcu
00530 
00531 #endif // GCU_APPLICATION_H