Document.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2000 Murray Cumming
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the Free
00016  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 #ifndef BAKERY_DOCUMENT_H
00020 #define BAKERY_DOCUMENT_H
00021 
00022 #include "bakery/View/View.h"
00023 #include <glibmm.h>
00024 
00025 #include <iostream>
00026 
00027 namespace Bakery
00028 {
00029 
00034 class Document
00035 {
00036 public: 
00037   Document();
00038   virtual ~Document();
00039 
00040   //TODO: It's probably not useful for this to be virtual:
00041   /* Saves the data to disk.
00042    * Asks the View to update this document before saving to disk,
00043    * but you should probably ensure that the document is updated more regularly than this,
00044    * so that different parts of the GUI are synchronized.
00045    * Only saves if the document has been modified.
00046    * bool indicates success.
00047    */
00048   virtual bool save();
00049 
00050   //TODO: It's probably not useful for this to be virtual:
00051   /* Loads data from disk, using the URI (set with set_file_uri()) then asks the View to update itself.
00052    * bool indicates success.
00053    */
00054   virtual bool load();
00055 
00056   //This can't be virtual because that would break ABI.
00057   //Hopefully it doesn't need to be.
00058   /* Loads data from disk, using the URI (set with set_file_uri()) then asks the View to update itself.
00059    * bool indicates success.
00060    */
00061   bool load_from_data(const guchar* data, std::size_t length);
00062 
00063 
00064   virtual bool get_modified() const;
00065   virtual void set_modified(bool bVal = true);
00066 
00068   virtual bool get_is_new() const;
00070   void set_is_new(bool bVal);
00071 
00072   virtual Glib::ustring get_contents() const;
00073   virtual void set_contents(const Glib::ustring& strVal);
00074 
00075   virtual Glib::ustring get_file_uri_with_extension(const Glib::ustring& uri);
00076 
00077   virtual Glib::ustring get_file_uri() const;
00078   virtual void set_file_uri(const Glib::ustring& file_uri, bool bEnforceFileExtension = false);
00079 
00081   virtual Glib::ustring get_name() const;
00082   static Glib::ustring util_file_uri_get_name(const Glib::ustring& file_uri, const Glib::ustring& file_extension);
00083 
00084   virtual bool get_read_only() const;
00085   virtual void set_read_only(bool bVal);
00086 
00088   virtual void set_view(ViewBase* pView);
00089   virtual ViewBase* get_view();
00090 
00091   virtual void set_file_extension(const Glib::ustring& strVal);
00092   virtual Glib::ustring get_file_extension() const;
00093 
00094   //Signals
00097   typedef sigc::signal<void, bool> type_signal_modified;
00098 
00102   type_signal_modified& signal_modified();
00103 
00104   typedef sigc::signal<void> type_signal_forget;
00105 
00109   type_signal_forget& signal_forget();
00110 
00112 
00113 protected:
00117   virtual bool load_after();
00118 
00122   virtual bool save_before();
00123 
00124   virtual bool read_from_disk();
00125   virtual bool write_to_disk();
00126 
00127   Glib::ustring m_strContents;
00128   Glib::ustring m_file_uri;
00129   Glib::ustring m_file_extension;
00130 
00131   ViewBase* m_pView;
00132 
00133   type_signal_modified signal_modified_;
00134   type_signal_forget signal_forget_;
00135   
00136   bool m_bModified;
00137   bool m_bIsNew; //see get_is_new().
00138   bool m_bReadOnly;
00139 };
00140 
00141 } //namespace
00142 
00143 #endif //GNOME_APPWITHDOCS_DOCUMENT_H

Generated on Thu Jan 17 07:44:58 2008 for bakery by  doxygen 1.5.4