def ComicMenu(archive_path, title, user=None): """The 'main menu' for a comic. this allows for different functions to be added.""" oc = ObjectContainer(title2=unicode(os.path.basename(archive_path)), no_cache=True) state = DATABASE.comic_read_state(user, archive_path) # Full comic oc.add(PhotoAlbumObject( key=Callback(Comic, archive_path=archive_path, user=user), rating_key=hashlib.md5(archive_path).hexdigest(), title=unicode(utils.decorate_title(archive_path, user, state, title)), thumb=utils.thumb_transcode(Callback(get_cover, archive_path=archive_path)))) # Resume if state == utils.State.IN_PROGRESS: cur, total = DATABASE.get_page_state(user, archive_path) if cur > 0: oc.add(PhotoAlbumObject(title=unicode(L('resume')), thumb=R('resume.png'), key=Callback(Comic, archive_path=archive_path, user=user, page=cur), rating_key=hashlib.md5('{}{}'.format(archive_path, cur)).hexdigest())) # Read/Unread toggle if state == utils.State.UNREAD or state == utils.State.IN_PROGRESS: oc.add(DirectoryObject(title=unicode(L('mark_read')), thumb=R('mark-read.png'), key=Callback(MarkRead, user=user, archive_path=archive_path))) else: oc.add(DirectoryObject(title=unicode(L('mark_unread')), thumb=R('mark-unread.png'), key=Callback(MarkUnread, user=user, archive_path=archive_path))) return oc
def get_image(archive_path, filename, user): """Return the contents of `filename` from within `archive_path`. also do some other stuff.""" archive = archives.get_archive(archive_path) x, total_pages = DATABASE.get_page_state(user, archive_path) m = utils.PAGE_NUM_REGEX.search(filename) cur_page = int(m.group(1)) if m else 0 Log.Info('{}: <{}> ({}/{})'.format(user, os.path.basename(archive_path), cur_page, total_pages)) if cur_page > 0: DATABASE.set_page_state(user, archive_path, cur_page) return utils.data_object(archive, filename)
def decorate_title(archive, user, state, title): if state == State.UNREAD: indicator = Prefs['unread_symbol'] elif state == State.IN_PROGRESS: cur, total = DATABASE.get_page_state(user, archive) if cur <= 0 or total <= 0: indicator = Prefs['in_progress_symbol'] else: indicator = '{} [{}/{}]'.format(Prefs['in_progress_symbol'], cur, total) elif state == State.READ: indicator = Prefs['read_symbol'] else: return title return '{} {}'.format('' if indicator is None else indicator.strip(), title)