diff --git a/__main__.py b/__main__.py
index 5edd96e..047ca98 100755
--- a/__main__.py
+++ b/__main__.py
@@ -72,6 +72,14 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
super(MainUI, self).__init__()
self.setupUi(self)
+ # Empty variables that will be infested soon
+ self.last_open_books = None
+ self.last_open_tab = None
+ self.last_open_path = None
+ self.thread = None # Background Thread
+ self.viewModel = None
+ self.current_contentView = None # For fullscreening purposes
+
# Initialize application
Settings(self).read_settings() # This should populate all variables that need
# to be remembered across sessions
@@ -79,16 +87,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Create the database in case it doesn't exist
database.DatabaseInit(self.database_path)
- # Background Thread
- self.thread = None
-
# Create and right align the statusbar label widget
self.statusMessage = QtWidgets.QLabel()
self.statusMessage.setObjectName('statusMessage')
self.statusBar.addPermanentWidget(self.statusMessage)
# Init the QListView
- self.viewModel = None
self.lib_ref = Library(self)
# Application wide temporary directory
@@ -127,9 +131,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tab_switch()
self.tabWidget.currentChanged.connect(self.tab_switch)
- # For fullscreening purposes
- self.current_contentView = None
-
# Tab closing
self.tabWidget.setTabsClosable(True)
# TODO
@@ -151,6 +152,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.exit_all.setContext(QtCore.Qt.ApplicationShortcut)
self.exit_all.activated.connect(self.closeEvent)
+ # Open last... open books.
+ self.open_files(self.last_open_books)
+ self.last_open_books = None
def resizeEvent(self, event=None):
if event:
@@ -316,11 +320,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
def list_doubleclick(self, myindex):
index = self.listView.model().index(myindex.row(), 0)
- file_exists = self.listView.model().data(index, QtCore.Qt.UserRole + 5)
-
- if not file_exists:
- return
-
metadata = self.listView.model().data(index, QtCore.Qt.UserRole + 3)
# Shift focus to the tab that has the book open (if there is one)
@@ -331,12 +330,30 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
return
path = metadata['path']
- contents = sorter.BookSorter(
- [path], 'reading', self.database_path, self.temp_dir.path()).initiate_threads()
+ self.open_files([path])
- tab_ref = Tab(contents, self.tabWidget)
- self.tabWidget.setCurrentWidget(tab_ref)
- self.format_contentView()
+ def open_files(self, file_paths):
+ # file_paths is expected to be a list
+ # This allows for threading file opening
+ # Which should speed up multiple file opening
+ # especially @ application start
+ if not file_paths:
+ return
+
+ contents = sorter.BookSorter(
+ file_paths, 'reading', self.database_path, self.temp_dir.path()).initiate_threads()
+
+ found_a_focusable_tab = False
+
+ for i in contents:
+ file_data = contents[i]
+ Tab(file_data, self.tabWidget)
+ if file_data['path'] == self.last_open_tab:
+ found_a_focusable_tab = True
+ self.tabWidget.setCurrentIndex(self.tabWidget.count() - 1)
+
+ if not found_a_focusable_tab:
+ self.tabWidget.setCurrentIndex(0)
def get_color(self):
signal_sender = self.sender().objectName()
@@ -445,13 +462,16 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.temp_dir.remove()
self.hide()
+ self.last_open_books = []
if self.tabWidget.count() > 1:
- all_metadata = []
+ all_metadata = []
for i in range(1, self.tabWidget.count()):
tab_metadata = self.tabWidget.widget(i).metadata
+ self.last_open_books.append(tab_metadata['path'])
all_metadata.append(tab_metadata)
+ Settings(self).save_settings()
self.thread = BackGroundTabUpdate(self.database_path, all_metadata)
self.thread.finished.connect(QtWidgets.qApp.exit)
self.thread.start()
diff --git a/resources/main.ui b/resources/main.ui
index 6eecf07..8cbc473 100644
--- a/resources/main.ui
+++ b/resources/main.ui
@@ -97,6 +97,8 @@
-
+
+
+
diff --git a/settings.py b/settings.py
index 880eba0..45899b7 100644
--- a/settings.py
+++ b/settings.py
@@ -58,6 +58,11 @@ class Settings:
'currentProfileIndex', 0))
self.settings.endGroup()
+ self.settings.beginGroup('lastOpen')
+ self.parent_window.last_open_books = self.settings.value('lastOpenFiles', [])
+ self.parent_window.last_open_tab = self.settings.value('lastOpenTab', 'library')
+ self.settings.endGroup()
+
def save_settings(self):
self.settings.beginGroup('mainWindow')
self.settings.setValue('windowSize', self.parent_window.size())
@@ -81,3 +86,17 @@ class Settings:
current_profile3])
self.settings.setValue('currentProfileIndex', current_profile_index)
self.settings.endGroup()
+
+ # TODO
+ # Last open order
+ # Last open highlighted
+ current_tab_index = self.parent_window.tabWidget.currentIndex()
+ if current_tab_index == 0:
+ last_open_tab = 'library'
+ else:
+ last_open_tab = self.parent_window.tabWidget.widget(current_tab_index).metadata['path']
+
+ self.settings.beginGroup('lastOpen')
+ self.settings.setValue('lastOpenFiles', self.parent_window.last_open_books)
+ self.settings.setValue('lastOpenTab', last_open_tab)
+ self.settings.endGroup()
diff --git a/sorter.py b/sorter.py
index 54e6918..99147a0 100644
--- a/sorter.py
+++ b/sorter.py
@@ -32,7 +32,7 @@ class BookSorter:
# This includes getting file info for the database
# Parsing for the reader proper
# Caching upon closing
- self.file_list = file_list
+ self.file_list = [i for i in file_list if os.path.exists(i)]
self.statistics = [0, (len(file_list))]
self.all_books = {}
self.hashes = []
@@ -145,7 +145,7 @@ class BookSorter:
content['Invalid'] = 'Possible Parse Error'
position = self.database_position(file_md5)
- self.all_books = {
+ self.all_books[file_md5] = {
'title': title,
'author': author,
'year': year,
diff --git a/widgets.py b/widgets.py
index c133746..5a5bc78 100644
--- a/widgets.py
+++ b/widgets.py
@@ -412,7 +412,6 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate):
self.temp_dir = temp_dir
def paint(self, painter, option, index):
- QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
# This is a hint for the future
# Color icon slightly red
# if option.state & QtWidgets.QStyle.State_Selected:
@@ -426,15 +425,23 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate):
# TODO
# Calculate progress on the basis of lines
+ if not file_exists:
+ read_icon = QtGui.QIcon.fromTheme('vcs-conflicting').pixmap(36)
+ painter.setOpacity(.7)
+ QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
+ painter.setOpacity(1)
+ x_draw = option.rect.bottomRight().x() - 30
+ y_draw = option.rect.bottomRight().y() - 35
+ painter.drawPixmap(x_draw, y_draw, read_icon)
+ return
+
+ QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
if position:
current_chapter = position['current_chapter']
total_chapters = position['total_chapters']
progress_percent = int(current_chapter * 100 / total_chapters)
- if not file_exists:
- read_icon = QtGui.QIcon.fromTheme('vcs-conflicting').pixmap(36)
- QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
- elif current_chapter == total_chapters:
+ if current_chapter == total_chapters:
QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
read_icon = QtGui.QIcon.fromTheme('vcs-normal').pixmap(36)
elif current_chapter == 1:
@@ -450,9 +457,6 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate):
if current_chapter != 1:
painter.drawPixmap(x_draw, y_draw, read_icon)
- else:
- QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
-
class MyAbsModel(QtGui.QStandardItemModel, QtCore.QAbstractItemModel):
def __init__(self, parent=None):