bakery  2.6
Document.h
Go to the documentation of this file.
1 /*
2  * Copyright 2000 Murray Cumming
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #ifndef BAKERY_DOCUMENT_H
20 #define BAKERY_DOCUMENT_H
21 
22 #include "bakery/View/View.h"
23 #include <glibmm.h>
24 
25 #include <iostream>
26 
27 namespace Bakery
28 {
29 
34 class Document
35 {
36 public:
37  Document();
38  virtual ~Document();
39 
40  /* Saves the data to disk.
41  * Asks the View to update this document before saving to disk,
42  * but you should probably ensure that the document is updated more regularly than this,
43  * so that different parts of the GUI are synchronized.
44  * Only saves if the document has been modified.
45  * bool indicates success.
46  */
47  bool save();
48 
49  /* Loads data from disk, using the URI (set with set_file_uri()) then asks the View to update itself.
50  * bool indicates success.
51  */
52  bool load();
53 
54  //This can't be virtual because that would break ABI.
55  //Hopefully it doesn't need to be.
56  /* Loads data from disk, using the URI (set with set_file_uri()) then asks the View to update itself.
57  * bool indicates success.
58  */
59  bool load_from_data(const guchar* data, std::size_t length);
60 
61 
62  virtual bool get_modified() const;
63  virtual void set_modified(bool bVal = true);
64 
66  virtual bool get_is_new() const;
68  void set_is_new(bool bVal);
69 
70  virtual Glib::ustring get_contents() const;
71  virtual void set_contents(const Glib::ustring& strVal);
72 
73  virtual Glib::ustring get_file_uri_with_extension(const Glib::ustring& uri);
74 
75  virtual Glib::ustring get_file_uri() const;
76  virtual void set_file_uri(const Glib::ustring& file_uri, bool bEnforceFileExtension = false);
77 
79  virtual Glib::ustring get_name() const;
80  static Glib::ustring util_file_uri_get_name(const Glib::ustring& file_uri, const Glib::ustring& file_extension);
81 
82  virtual bool get_read_only() const;
83  virtual void set_read_only(bool bVal);
84 
86  virtual void set_view(ViewBase* pView);
87  virtual ViewBase* get_view();
88 
89  virtual void set_file_extension(const Glib::ustring& strVal);
90  virtual Glib::ustring get_file_extension() const;
91 
92  //Signals
95  typedef sigc::signal<void, bool> type_signal_modified;
96 
101 
102  typedef sigc::signal<void> type_signal_forget;
103 
108 
110 
111 protected:
115  virtual bool load_after();
116 
120  virtual bool save_before();
121 
122  virtual bool read_from_disk();
123  virtual bool write_to_disk();
124 
125  Glib::ustring m_strContents;
126  Glib::ustring m_file_uri;
127  Glib::ustring m_file_extension;
128 
130 
133 
135  bool m_bIsNew; //see get_is_new().
137 };
138 
139 } //namespace
140 
141 #endif //GNOME_APPWITHDOCS_DOCUMENT_H
virtual Glib::ustring get_file_uri() const
This is a base class for View.
Definition: ViewBase.h:31
ViewBase * m_pView
Definition: Document.h:129
virtual bool load_after()
Allow app to update icons/title bar.
sigc::signal< void, bool > type_signal_modified
For instance, void on_document_modified(bool modified);.
Definition: Document.h:95
virtual void set_view(ViewBase *pView)
If you don't want to use a View, then don't use set_view().
virtual void set_read_only(bool bVal)
virtual bool read_from_disk()
void set_is_new(bool bVal)
Called by App_WithDoc::init_create_document().
static Glib::ustring util_file_uri_get_name(const Glib::ustring &file_uri, const Glib::ustring &file_extension)
virtual bool get_modified() const
virtual bool get_is_new() const
Whether this just a default document.
type_signal_modified signal_modified_
Definition: Document.h:131
The Document is like the 'Model' in the Model-View-Controller framework.
Definition: Document.h:34
Glib::ustring m_file_uri
Definition: Document.h:126
virtual Glib::ustring get_contents() const
bool m_bIsNew
Definition: Document.h:135
type_signal_forget & signal_forget()
This signal is emitted when the view should forget the document.
virtual bool get_read_only() const
sigc::signal< void > type_signal_forget
Definition: Document.h:102
virtual Glib::ustring get_file_extension() const
bool m_bModified
Definition: Document.h:134
virtual ViewBase * get_view()
virtual void set_file_extension(const Glib::ustring &strVal)
Glib::ustring m_file_extension
Definition: Document.h:127
Glib::ustring m_strContents
Definition: Document.h:125
virtual ~Document()
virtual void set_contents(const Glib::ustring &strVal)
type_signal_modified & signal_modified()
This signal is emitted when the document has been modified.
bool m_bReadOnly
Definition: Document.h:136
type_signal_forget signal_forget_
Definition: Document.h:132
virtual void set_file_uri(const Glib::ustring &file_uri, bool bEnforceFileExtension=false)
virtual Glib::ustring get_file_uri_with_extension(const Glib::ustring &uri)
virtual Glib::ustring get_name() const
Gets filename part of file_uri, or 'untitled'.
bool load_from_data(const guchar *data, std::size_t length)
virtual bool save_before()
overrideable.
virtual bool write_to_disk()
virtual void set_modified(bool bVal=true)