Remove unused code

This commit is contained in:
Kovid Goyal 2017-02-07 20:05:46 +05:30
parent 145b39859e
commit af72200eca

View File

@ -1,163 +0,0 @@
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import hash_literals
import traceback
from ajax import encode_query
from dom import set_css, get_widget_css
from elementmaker import E
from modals import error_dialog, create_modal_container
from gettext import gettext as _
from utils import parse_url_params, debounce
from book_list.globals import get_session_data, set_boss, set_current_query
from book_list.theme import get_color
from book_list.ui import UI
from read_book.ui import ReadUI
class Boss:
def __init__(self, interface_data):
set_boss(self)
document.head.appendChild(E.style(get_widget_css()))
set_css(document.body, background_color=get_color('window-background'), color=get_color('window-foreground'))
create_modal_container()
self.interface_data = interface_data
self.current_library_id = interface_data['default_library']
self.current_library_name = interface_data['library_map'][self.current_library_id]
self.current_mode = 'book_list'
self.update_window_title()
div = E.div(id='book-list-container')
document.body.appendChild(div)
self.ui = UI(interface_data, div)
div = E.div(id='read-book-container', style="display:none")
document.body.appendChild(div)
self.read_ui = ReadUI(interface_data, div)
window.onerror = self.onerror.bind(self)
self.history_count = 0
data = parse_url_params()
set_current_query(data)
self.ui.apply_state() # Render the book list
if not data.mode or data.mode is 'book_list':
if data.panel is not self.ui.current_panel:
self.ui.show_panel(data.panel, push_state=False)
if data.mode is 'read_book':
try:
book_id = int(data.book_id)
except Exception:
book_id = None
if book_id is None:
if data.panel is not self.ui.current_panel:
self.ui.show_panel(data.panel, push_state=False)
else:
self.read_book(book_id, data.fmt)
setTimeout(def():
window.onpopstate = self.onpopstate.bind(self)
, 0) # We do this after event loop ticks over to avoid catching popstate events that some browsers send on page load
window.addEventListener('resize', debounce(self.on_resize.bind(self), 250))
def on_resize(self):
self.ui.on_resize()
self.read_ui.on_resize()
def apply_mode(self, mode):
mode = mode or self.current_mode
divid = 'read-book-container' if mode is 'read_book' else 'book-list-container'
for x in ['book-list-container', 'read-book-container']:
document.getElementById(x).style.display = 'block' if x is divid else 'none'
self.update_window_title()
@property
def has_history(self):
return self.history_count > 0
def update_window_title(self):
if self.current_mode is 'book_list':
document.title = 'calibre :: ' + self.current_library_name
elif self.current_mode is 'read_book':
document.title = self.read_ui.current_metadata.title
def onerror(self, msg, script_url, line_number, column_number, error_object):
console.log(error_object)
try:
fname = script_url.rpartition('/')[-1] or script_url
msg = msg + '<br><span style="font-size:smaller">' + 'Error at {}:{}:{}'.format(fname, line_number, column_number or '') + '</span>'
details = ''
if error_object:
details = traceback.format_exception(error_object).join('')
error_dialog(_('Unhandled error'), msg, details)
return True
except:
console.log('There was an error in the unhandled exception handler')
def onpopstate(self, ev):
data = parse_url_params()
set_current_query(data)
self.current_mode = mode = data.mode or 'book_list'
self.history_count -= 1
self.apply_mode()
if mode is 'book_list':
search = data.search or ''
if data.panel is not self.ui.current_panel:
self.ui.show_panel(data.panel, push_state=False)
if search is not self.ui.books_view.interface_data.search_result.query:
self.ui.books_view.change_search(search, push_state=False, panel_to_show=data.panel)
elif mode is 'read_book':
self.read_book(int(data.book_id), data.fmt)
def read_book(self, book_id, fmt, metadata):
self.current_mode = 'read_book'
self.apply_mode()
self.read_ui.load_book(book_id, fmt, metadata)
def reload_book(self):
self.read_ui.reload_book()
def redisplay_book(self):
self.read_ui.redisplay_book()
def return_to_book_list(self, book_id):
# Note that book_id could refer to a deleted book, that is, a book no
# longer in local storage
self.current_mode = 'book_list'
self.ui.show_panel(self.ui.ROOT_PANEL, force=True)
self.apply_mode()
def change_books(self, data):
data.search_result.sort = data.search_result.sort.split(',')[:2].join(',')
data.search_result.sort_order = data.search_result.sort_order.split(',')[:2].join(',')
sval = ''
for field, order in zip(data.search_result.sort.split(','), data.search_result.sort_order.split(',')):
sval += field + '.' + order + ','
get_session_data().set_library_option(self.interface_data.library_id, 'sort', sval.rstrip(','))
self.interface_data.metadata = data.metadata
self.interface_data.search_result = data.search_result
self.ui.refresh_books_view()
def push_state(self, replace=False, extra_query_data=None):
query = {}
idata = self.interface_data
if extra_query_data:
for k in extra_query_data:
query[k] = extra_query_data[k]
if self.current_mode is 'book_list':
if self.ui.current_panel is not self.ui.ROOT_PANEL:
query.panel = self.ui.current_panel
sq = idata.search_result.query
if sq:
query.search = sq
else:
query.mode = self.current_mode
if self.current_mode is 'read_book':
eqd = self.read_ui.url_data
for k in eqd:
query[k] = eqd[k]
if idata.library_id is not idata.default_library:
query.library_id = idata.library_id
set_current_query(query)
query = encode_query(query) or '?'
if replace:
window.history.replaceState(None, '', query)
else:
window.history.pushState(None, '', query)
self.history_count += 1