# vPresent is an immersive presentation creation and display application.
# Copyright (C) 2007-2008 by Infiscape Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from PyQt4 import QtCore, QtGui


class Document(QtCore.QObject):
   def __init__(self, undoStack, parent = None):
      QtCore.QObject.__init__(self, parent)

      # Ensure that an undo stack exists for this document.
      if undoStack is None:
         undoStack = QtGui.QUndoStack()

      self.__undoStack = undoStack

   def __reduce__(self):
      '''
      Handles reduction of this type for pickling purposes. This is needed
      because QtCore.QObject cannot be pickled.
      '''
      return self.__class__, (None, None), self.__getstate__()

   def __getstate__(self):
      dict = self.__dict__.copy()

      # We cannot pickle the undo stack for this document, and there is no
      # point in doing so anyway.
      del dict['_Document__undoStack']

      return dict

   def __setstate__(self, dict):
      self.__dict__.update(dict)
      self.__undoStack = QtGui.QUndoStack()

   def getUndoStack(self):
      return self.__undoStack

   def getContent(self):
      assert False, "Not implemented!"

   def applySettings(self, env):
      pass

   def close(self):
      self.__undoStack = None
