The Gnome Chemistry Utils  0.14.0
gcu/application.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gcu/application.h
6  *
7  * Copyright (C) 2005-2012 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #ifndef GCU_APPLICATION_H
26 #define GCU_APPLICATION_H
27 
28 #include "dialog-owner.h"
29 #include "structs.h"
30 #include "object.h"
31 #include <list>
32 #include <map>
33 #include <set>
34 #include <string>
35 #include <gcu/macros.h>
36 
38 namespace gcu {
39 
40 class Document;
41 class Dialog;
42 struct option_data;
43 class TypeDesc;
44 class CmdContext;
45 class UIManager;
46 
47 typedef struct {
48  std::string name;
49  std::string uri;
50 } Database;
51 
52 #define GCU_CONF_DIR "gchemutils"
53 
57 class Application: virtual public DialogOwner
58 {
59 friend class Document;
60 friend class Dialog;
61 public:
75  Application (std::string name, std::string datadir = DATADIR, char const *help_name = NULL, char const *icon_name = NULL, CmdContext *cc = NULL);
79  virtual ~Application ();
80 
89  void OnHelp (std::string s = "");
93  bool HasHelp ();
97  std::string const &GetName () const {return Name;}
98 
102  virtual GtkWindow * GetWindow () {return NULL;}
103 
117  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)
118  {return false;}
119 
123  char const* GetCurDir () {return CurDir.c_str ();}
124 
128  void SetCurDir (char const* dir);
129 
133  void SetCurDir (std::string const &dir);
134 
138  std::map<std::string, GdkPixbufFormat*> &GetSupportedPixbufFormats () {return m_SupportedPixbufFormats;}
139 
149  char const *GetPixbufTypeName (std::string& filename, char const *mime_type);
150 
162  ContentType Load (std::string const &uri, const char *mime_type, Document* Doc, const char *options = NULL);
163 
175  ContentType Load (GsfInput *input, const char *mime_type, Document* Doc, const char *options = NULL);
176 
189  bool Save (std::string const &uri, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
190 
203  bool Save (GsfOutput *output, const char *mime_type, Object const *Obj, ContentType type, const char *options = NULL);
204 
209  virtual Document *CreateNewDocument () {return NULL;}
210 
215  static GOConfNode *GetConfDir ();
216 
221  std::string const &GetIconName () {return IconName;}
222 
230  void RegisterOptions (GOptionEntry const *entries, char const *translation_domain = GETTEXT_PACKAGE);
231 
238  void AddOptions (GOptionContext *context);
239 
245 
251  static Application *GetApplication (char const *name);
252 
258  static Application *GetApplication (std::string &name);
259 
260  // Object creation related methods
270  TypeId AddType (std::string TypeName, Object* (*CreateFunc) (), TypeId id = OtherType);
271 
282  Object* CreateObject (const std::string& TypeName, Object* parent = NULL);
290  void AddRule (TypeId type1, RuleId rule, TypeId type2);
298  void AddRule (const std::string& type1, RuleId rule, const std::string& type2);
305  const std::set<TypeId>& GetRules (TypeId type, RuleId rule);
306 
313  const std::set<TypeId>& GetRules (const std::string& type, RuleId rule);
314 
322  void SetCreationLabel (TypeId Id, std::string Label);
323 
329  const std::string& GetCreationLabel (TypeId Id);
330 
342  bool BuildObjectContextualMenu (Object *target, UIManager *uim, Object *object, double x, double y);
343 
350  void AddMenuCallback (TypeId Id, BuildMenuCb cb);
351 
357  const std::string& GetCreationLabel (const std::string& TypeName);
358 
359  TypeDesc const *GetTypeDescription (TypeId Id);
360 
365 
374  char* ConvertToCML (std::string const &uri, const char *mime_type, const char *options = NULL);
375 
384  char* ConvertToCML (GsfInput *input, const char *mime_type, const char *options = NULL);
385 
394  void ConvertFromCML (const char *cml, std::string const &uri, const char *mime_type, const char *options = NULL);
395 
404  void ConvertFromCML (const char *cml, GsfOutput *output, const char *mime_type, const char *options = NULL);
405 
410  std::list < Database > const &GetDatabases (char const *classname) {return m_Databases[classname];}
411 
412 protected:
420  void RegisterBabelType (const char *mime_type, const char *type);
421 
426  virtual void CreateDefaultCmdContext () {}
427 
432  virtual bool LoopRunning () {return false;}
433 
439  virtual void NoMoreDocsEvent () {}
443  std::map<std::string, GdkPixbufFormat*> m_SupportedPixbufFormats;
444 
449 
450 private:
451  void AddDocument (Document *Doc) {m_Docs.insert (Doc);}
452  void RemoveDocument (Document *Doc);
453  int OpenBabelSocket ();
454  char const *MimeToBabelType (char const *mime_type);
455 
456 private:
457  std::string Name;
458  std::string HelpName;
459  std::string HelpBrowser;
460  std::string HelpFilename;
461  std::string CurDir;
462  std::string IconName;
463  static GOConfNode *m_ConfDir;
464  std::list <option_data> m_Options;
465  std::map <TypeId, TypeDesc> m_Types;
466  std::map <std::string, std::string> m_BabelTypes;
467  std::map < std::string, std::list <Database> >m_Databases;
468 
475 GCU_PROT_PROP (std::set <Document*>, Docs)
479 GCU_PROT_PROP (unsigned, ScreenResolution)
493 GCU_PROP (unsigned, ImageResolution)
507 GCU_PROP (unsigned, ImageWidth)
521 GCU_PROP (unsigned, ImageHeight)
533 GCU_PROP (bool, TransparentBackground)
534 };
535 
536 } // namespace gcu
537 
538 #endif // GCU_APPLICATION_H