This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

This is the old design for the ApplicationClass; it's kept here mostly because of the points raised

2010-02-22

Bottom-Up

Document

typedef void (* EggDocumentSaveCallback) (EggDocumentHandle *handle,
                                          const gchar       *uri,
                                          gboolean           overwrite,
                                          gboolean           save_backup,
                                          GError            *error,
                                          gpointer           data);
typedef void (* EggDocumentOpenCallback) (EggDocumentHandle *handle,
                                          const gchar       *uri,
                                          gboolean           read_only,
                                          GError            *error,
                                          gpointer           data);
typedef void (* EggDocumentSetInfoCallback) (EggDocumentHandle *handle,
                                             const gchar       *uri,
                                             EggDocumentInfo   *info,
                                             GError            *error,
                                             gpointer           data);
typedef void (* EggDocumentGetInfoCallback) (EggDocumentHandle *handle,
                                             const gchar       *uri,
                                             EggDocumentInfo   *info,
                                             GError            *error,
                                             gpointer           data);

struct _EggDocumentClassIface
{
  GTypeInterface g_iface;

  /* vtable */
  EggDocumentFlags  (* get_flags)     (EggDocument             *document);
  void              (* set_flags)     (EggDocument             *document,
                                       EggDocumentFlags         flags);

  EggDocumentHandle (* save_document) (EggDocument             *document,
                                       const gchar             *save_uri,
                                       gboolean                 overwrite,
                                       gboolean                 save_backup,
                                       EggDocumentSaveCallback  callback,
                                       gpointer                 data);
  EggDocumentHandle (* open_document) (EggDocument             *document,
                                       const gchar             *uri,
                                       gboolean                 read_only,
                                       EggDocumentOpenCallback  callback,
                                       gpointer                 data);
  
  EggDocumentHandle (* set_info) (EggDocument                *document,
                                  EggDocumentInfo            *info,
                                  EggDocumentSetInfoCallback  callback,
                                  gpointer                    data);
  EggDocumentHandle (* get_info) (EggDocument                *document,
                                  EggDocumentGetInfoCallback  callback,
                                  gpointer                    data);
  
  void (* cancel_operation) (EggDocumentHandle *handle);
  
  /* signals */
  void (* changed) (EggDocument  *document);
  void (* error)   (EggDocument  *document,
                    const GError *error);
};

Document Model

struct _EggDocumentModel
{
  GObject parent_instance;

  /*< private >*/
  EggDocumentModelPrivate *priv;
};

struct _EggDocumentModel
{
  GObjectClass parent_class;

  /* vtable, not signals */
  EggDocument *(* create_document)       (EggDocumentModel *model,
                                          GType             document_type);
  void         (* set_document_property) (EggDocumentModel *model,
                                          EggDocument      *document,
                                          const gchar      *property_name,
                                          const GValue     *value);
  void         (* get_document_property) (EggDocumentModel *model,
                                          EggDocument      *document,
                                          const gchar      *property_name,
                                          GValue           *value);

  /* signals */
  void (* document_changed) (EggDocumentModel *model,
                             EggDocumentPath  *path,
                             EggDocument      *document);
  void (* document_add)     (EggDocumentModel *model,
                             EggDocumentPath  *path,
                             EggDocument      *document);
  void (* document_remove)  (EggDocumentModel *model,
                             EggDocumentPath  *path,
                             EggDocument      *document);

  /* padding for future expansion */
  void (*_egg_reserved1) (void)
  void (*_egg_reserved2) (void)
  void (*_egg_reserved3) (void)
  void (*_egg_reserved4) (void)
};

  enum { DOCUMENT_TEXT_PLAIN, DOCUMENT_TEXT_HTML };
  EggDocumentModel *model;

  model = egg_document_model_new (2,
                                  DOCUMENT_TEXT_PLAIN, DOCUMENT_TYPE_TEXT,
                                  DOCUMENT_TEXT_HTML, DOCUMENT_TYPE_HTML);

  EggDocument *document;
  EggDocumentPath *path;
  
  document = egg_document_model_create_document (DOCUMENT_TEXT_PLAIN, "file", "foo.txt", NULL);
  path = egg_document_path_new_from_string ("myapp:foo-txt");
  egg_document_model_add_document (model, path, document);

Application

struct _EggApplicationClass
{
  GObjectClass parent_class;

  /* vfuncs, not signals */

  /* override if you wish to parse the command line arguments */
  gboolean   (* application_init) (EggApplication *application,
                                   GOptionContext *context,
                                   gint           *argc,
                                   gchar        ***argv);

  /* override to manager the widget for the document
  GtkWidget *(* create_document_view) (GtkApplication *application,
                                       GtkDocument    *document);

  /* used to control the widget type of the document view */
  GType document_view_type;

  /* signals */

  /* return FALSE to stop the emission of the event */
  gboolean   (* application_quit) (EggApplication *application);

  /* emitted when the document model changes */
  void (* document_model_set) (EggApplication   *application,
                               EggDocumentModel *old_model);
  
  void (* document_view_add)    (EggApplication *application,
                                 EggDocument    *document,
                                 GtkWidget      *widget);
  void (* document_view_remove) (EggApplication *application,
                                 EggDocument    *document,
                                 GtkWidget      *widget);
};

struct _EggDocumentViewIface
{
  GTypeInterface g_iface;

  void    (* add_document)    (EggDocumentView *view,
                               EggDocument     *document);
  void    (* remove_document) (EggDocumentView *view,
                               EggDocument     *document);
  GSList *(* list_documents)  (EggDocumentView *view);
};

Comments


2024-10-23 11:36