Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
def BrowseDir(cur_dir, page_size=20, offset=0, user=None):
    """Browse directories, with paging. Show directories and compatible archives."""
    t1 = time.time()
    oc = ObjectContainer(title2=unicode(os.path.basename(cur_dir)), no_cache=True)
    try:
        dir_list = utils.filtered_listdir(cur_dir)
        page = dir_list[offset:offset + page_size]
    except Exception as e:
        Log.Error(e)
        return error_message('bad path', 'bad path')
    for item, is_dir in page:
        full_path = os.path.join(cur_dir, item)
        if is_dir:
            state = DATABASE.dir_read_state(user, full_path)
            oc.add(DirectoryObject(
                key=Callback(BrowseDir, cur_dir=full_path, page_size=page_size, user=user),
                title=unicode(utils.decorate_directory(user, state, item)),
                thumb=R('folder.png')))
        else:
            state = DATABASE.comic_read_state(user, full_path)
            title = os.path.splitext(item)[0]
            oc.add(DirectoryObject(
                key=Callback(ComicMenu, archive_path=full_path, title=title, user=user),
                title=unicode(utils.decorate_title(full_path, user, state, title)),
                thumb=utils.thumb_transcode(Callback(get_cover, archive_path=full_path))))

    if offset + page_size < len(dir_list):
        oc.add(NextPageObject(key=Callback(BrowseDir, cur_dir=cur_dir,
                              page_size=page_size, offset=offset + page_size, user=user)))
    t2 = time.time()
    Log.Info('Directory loaded in {:.0f} ms. {}'.format((t2 - t1) * 1000.0, cur_dir))
    return oc
Esempio n. 4
0
def BrowseDir(cur_dir, page_size=20, offset=0, user=None):
    """Browse directories, with paging. Show directories and compatible archives."""
    t1 = time.time()
    oc = ObjectContainer(title2=unicode(os.path.basename(cur_dir)), no_cache=True)
    try:
        dir_list = utils.filtered_listdir(cur_dir)
        page = dir_list[offset:offset + page_size]
    except Exception as e:
        Log.Error('BrowseDir: failed to get directory listing.')
        Log.Error('BrowseDir: {}, cur_dir={}, page_size={}, offset={}, user={}'.format(
            e, cur_dir, page_size, offset, user))
        return error_message('bad path', 'bad path')

    # Read/Unread toggle
    if os.path.abspath(cur_dir) != os.path.abspath(Prefs['cb_path']):
        oc.add(DirectoryObject(title=unicode(L('mark_all_read')), thumb=R('mark-read.png'),
                                key=Callback(Confirmation, f='MarkReadDir', action=L('mark_all_read'), user=user, path=cur_dir)))
        oc.add(DirectoryObject(title=unicode(L('mark_all_unread')), thumb=R('mark-unread.png'),
                                key=Callback(Confirmation, f='MarkUnreadDir', action=L('mark_all_unread'), user=user, path=cur_dir)))        
    for item, is_dir in page:
        full_path = os.path.join(cur_dir, item)
        if is_dir:
            state = DATABASE.dir_read_state(user, full_path)
            oc.add(DirectoryObject(
                key=Callback(BrowseDir, cur_dir=full_path, page_size=page_size, user=user),
                title=unicode(utils.decorate_directory(user, state, item)),
                thumb=R('folder.png')))
        else:
            state = DATABASE.comic_read_state(user, full_path)
            title = os.path.splitext(item)[0]
            oc.add(DirectoryObject(
                key=Callback(ComicMenu, archive_path=full_path, title=title, user=user),
                title=unicode(utils.decorate_title(full_path, user, state, title)),
                thumb=utils.thumb_transcode(Callback(get_cover, archive_path=full_path))))

    if offset + page_size < len(dir_list):
        oc.add(NextPageObject(key=Callback(BrowseDir, cur_dir=cur_dir,
                              page_size=page_size, offset=offset + page_size, user=user)))
    t2 = time.time()
    Log.Info('Directory loaded in {:.0f} ms. {}'.format((t2 - t1) * 1000.0, cur_dir))
    return oc