From e69845eff9eb0c699aba5cd79fb962d7ffc3b26f Mon Sep 17 00:00:00 2001 From: GRiker Date: Fri, 12 Mar 2010 10:48:56 -0700 Subject: [PATCH 1/2] GwR add startswith, split to PersistentTemporaryFile --- src/calibre/ptempfile.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/calibre/ptempfile.py b/src/calibre/ptempfile.py index f4bcfa8675..b71ff15f65 100644 --- a/src/calibre/ptempfile.py +++ b/src/calibre/ptempfile.py @@ -51,6 +51,31 @@ class PersistentTemporaryFile(object): except: pass + def startswith(self,*args): + if len(args): + str = args[0] + beg = 0 + end = len(str) + else: + return False + + if len(args) > 1: + begin = args[1] + if len(args) > 2: + end = args[2] + if self._name[beg:end].startswith(str): + return True + return False + + def split(self,*args): + if len(args): + sep = args[0] + if len(args) > 1: + maxsplit = args[1] + return self._name.split(sep,maxsplit) + else: + return self._name.split(sep) + def PersistentTemporaryDirectory(suffix='', prefix='', dir=None): ''' From 3fcb4a4883a12a2800b9dd27adc7d508adb2aa08 Mon Sep 17 00:00:00 2001 From: GRiker Date: Sat, 13 Mar 2010 03:49:17 -0700 Subject: [PATCH 2/2] GwR Fetch annotations marks books as read if > 96% --- src/calibre/gui2/ui.py | 8 ++++++++ src/calibre/ptempfile.py | 26 -------------------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 86aaa7c89c..88c8f3ccca 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -982,6 +982,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): update_progress = pyqtSignal(int) update_done = pyqtSignal() + FINISHED_READING_PCT_THRESHOLD = 96 def __init__(self, parent, db, annotation_map, done_callback): QThread.__init__(self, parent) @@ -1064,6 +1065,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): ka_soup.insert(0,divTag) return ka_soup + def mark_book_as_read(self,id): + read_tag = gprefs.get('catalog_epub_mobi_read_tag') + self.db.set_tags(id, [read_tag], append=True) + def canceled(self): self.pd.hide() @@ -1091,6 +1096,9 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): mi.comments = unicode(user_notes_soup.prettify()) # Update library comments self.db.set_comment(id, mi.comments) + # Update 'read' tag + if bm.bookmark.percent_read >= self.FINISHED_READING_PCT_THRESHOLD: + self.mark_book_as_read(id) # Add bookmark file to id self.db.add_format_with_hooks(id, bm.bookmark.bookmark_extension, bm.bookmark.path, index_is_id=True) diff --git a/src/calibre/ptempfile.py b/src/calibre/ptempfile.py index b71ff15f65..b7b4d49509 100644 --- a/src/calibre/ptempfile.py +++ b/src/calibre/ptempfile.py @@ -51,32 +51,6 @@ class PersistentTemporaryFile(object): except: pass - def startswith(self,*args): - if len(args): - str = args[0] - beg = 0 - end = len(str) - else: - return False - - if len(args) > 1: - begin = args[1] - if len(args) > 2: - end = args[2] - if self._name[beg:end].startswith(str): - return True - return False - - def split(self,*args): - if len(args): - sep = args[0] - if len(args) > 1: - maxsplit = args[1] - return self._name.split(sep,maxsplit) - else: - return self._name.split(sep) - - def PersistentTemporaryDirectory(suffix='', prefix='', dir=None): ''' Return the path to a newly created temporary directory that will