From 66b9606d49af508a2414121d8aaa8956de1d037e Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Mon, 21 Feb 2011 17:46:36 +0000 Subject: Add support to ziped Gutemberg files --- diff --git a/activity/activity.info b/activity/activity.info index 345af14..5aec38c 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -5,5 +5,5 @@ icon = activity-read exec = sugar-activity readactivity.ReadActivity show_launcher = no activity_version = 88 -mime_types = application/pdf;image/vnd.djvu;image/x.djvu;image/tiff;application/x-cbz;application/x-cbr;application/epub+zip;text/plain +mime_types = application/pdf;image/vnd.djvu;image/x.djvu;image/tiff;application/x-cbz;application/x-cbr;application/epub+zip;text/plain;application/zip license = GPLv2+ diff --git a/readactivity.py b/readactivity.py index 2a43084..1fb2ffc 100644 --- a/readactivity.py +++ b/readactivity.py @@ -790,7 +790,7 @@ class ReadActivity(activity.Activity): mimetype = mime.get_for_file(filepath) if mimetype == 'application/epub+zip': self._view = epubadapter.EpubViewer() - elif mimetype == 'text/plain': + elif mimetype == 'text/plain' or mimetype == 'application/zip' : self._view = textadapter.TextViewer() else: self._view = evinceadapter.EvinceViewer() diff --git a/textadapter.py b/textadapter.py index a82c153..2e96447 100644 --- a/textadapter.py +++ b/textadapter.py @@ -1,10 +1,12 @@ import os +import zipfile import logging import gtk import pango import gobject import threading +from sugar import mime from sugar.graphics import style PAGE_SIZE = 38 @@ -22,6 +24,7 @@ class TextViewer(gobject.GObject): } def setup(self, activity): + self._activity = activity activity._scrolled = gtk.ScrolledWindow() activity._scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) activity._scrolled.props.shadow_type = gtk.SHADOW_NONE @@ -57,7 +60,22 @@ class TextViewer(gobject.GObject): self.highlight_tag.set_property('background', 'yellow') def load_document(self, file_path): - self._etext_file = open(file_path.replace('file://', ''), 'r') + + file_name = file_path.replace('file://', '') + mimetype = mime.get_for_file(file_path) + if mimetype == 'application/zip': + logging.error('opening zip file') + self.zf = zipfile.ZipFile(file_path.replace('file://', ''), 'r') + self.book_files = self.zf.namelist() + extract_path = os.path.join(self._activity.get_activity_root(), + 'instance') + for book_file in self.book_files: + if (book_file != 'annotations.pkl'): + self.zf.extract(book_file, extract_path) + file_name = os.path.join(extract_path, book_file) + + logging.error('opening file_name %s' % file_name) + self._etext_file = open(file_name, 'r') self.page_index = [0] pagecount = 0 -- cgit v0.9.1