diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2013-08-01 16:04:21 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2013-08-05 14:19:28 (GMT) |
commit | c8b4a945a348149c56daccc8c94da70af8bc9b3a (patch) | |
tree | bab2464de54c6c8ae978ebd66dbf1d36311a8c37 | |
parent | 9daed3dbbacceaa710cc2f9b95fa65ce4eaad7d6 (diff) |
Prevent open a file two times
With latests changes (empty panel addition) the canvas is set more than
one time, then the read_file can be triggered more than one time.
Check if a file is already openened to not open it two times.
This prevent a bug where the book is displayed two times, side by side.
This patch also avoid a situation where the book can't be shared because
the self._tempfile is not set when the file is opened at start because
is reopened the activity from the journal.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | readactivity.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/readactivity.py b/readactivity.py index 236030b..8c2d37e 100644 --- a/readactivity.py +++ b/readactivity.py @@ -699,11 +699,10 @@ class ReadActivity(activity.Activity): tempfile = os.path.join(self.get_activity_root(), 'instance', 'tmp%i%s' % (time.time(), extension)) os.link(file_path, tempfile) - self._tempfile = tempfile # enable collaboration self.activity_button.page.share.props.sensitive = True - self._load_document('file://' + self._tempfile) + self._load_document('file://' + tempfile) # FIXME: This should obviously be fixed properly GObject.timeout_add_seconds(1, @@ -766,7 +765,6 @@ class ReadActivity(activity.Activity): del self.unused_download_tubes - self._tempfile = tempfile file_path = os.path.join(self.get_activity_root(), 'instance', '%i' % time.time()) _logger.debug("Saving file %s to datastore...", file_path) @@ -864,7 +862,11 @@ class ReadActivity(activity.Activity): filepath -- string starting with file:// """ + if self._tempfile is not None: + # prevent reopen + return filename = filepath.replace('file://', '') + self._tempfile = filename if not os.path.exists(filename) or os.path.getsize(filename) == 0: return mimetype = mime.get_for_file(filepath) |