diff --git a/__main__.py b/__main__.py index 0a39bf4..71459b5 100755 --- a/__main__.py +++ b/__main__.py @@ -144,7 +144,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.listView.verticalScrollBar().setSingleStep(7) self.listView.doubleClicked.connect(self.list_doubleclick) self.listView.setItemDelegate(LibraryDelegate(self.temp_dir.path())) - self.reload_listview() + self.lib_ref.generate_model('build') + self.lib_ref.create_proxymodel() # Keyboard shortcuts self.exit_all = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self) @@ -208,13 +209,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): for i in selected_books: data = i.data(QtCore.Qt.UserRole + 3) selected_hashes.append(data['hash']) + database.DatabaseFunctions( self.database_path).delete_from_database(selected_hashes) - self.viewModel = None # TODO - # Delete the item from the model instead - # of reconstructing it - # The same goes for addition - self.reload_listview() + + self.lib_ref.generate_model('build') + self.lib_ref.create_proxymodel() selected_number = len(selected_books) msg_box = QtWidgets.QMessageBox() @@ -227,10 +227,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): msg_box.show() msg_box.exec_() - def reload_listview(self): - if not self.viewModel: - self.lib_ref.generate_model('build') - def tab_switch(self): if self.tabWidget.currentIndex() == 0: @@ -282,13 +278,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): # We're also updating the underlying model to have real-time # updates on the read status - # Find index of the model item that corresponds to the tab - + # Set a baseline model index in case the item gets deleted # E.g It's open in a tab and deleted from the library model_index = None - start_index = self.viewModel.index(0, 0) + # Find index of the model item that corresponds to the tab matching_item = self.viewModel.match( start_index, QtCore.Qt.UserRole + 6, diff --git a/database.py b/database.py index 854eaae..af4b6d4 100644 --- a/database.py +++ b/database.py @@ -127,9 +127,15 @@ class DatabaseFunctions: # file_hashes is expected as a list that will be iterated upon # This should enable multiple deletion - for i in file_hashes: - self.database.execute( - f"DELETE FROM books WHERE Hash = '{i}'") + first = file_hashes[0] + sql_command = f"DELETE FROM books WHERE Hash = '{first}'" + + if len(file_hashes) > 1: + for i in file_hashes[1:]: + sql_command += f" OR Hash = '{i}'" + + self.database.execute(sql_command) + self.database.commit() self.close_database() diff --git a/library.py b/library.py index 2e86312..0ee7738 100644 --- a/library.py +++ b/library.py @@ -121,8 +121,6 @@ class Library: item.setIcon(QtGui.QIcon(img_pixmap)) self.parent_window.viewModel.appendRow(item) - self.create_proxymodel() - def create_proxymodel(self): self.proxy_model = QtCore.QSortFilterProxyModel() self.proxy_model.setSourceModel(self.parent_window.viewModel) diff --git a/parsers/epub.py b/parsers/epub.py index 1235a2f..3c66225 100644 --- a/parsers/epub.py +++ b/parsers/epub.py @@ -58,38 +58,38 @@ class ParseEPUB: cover_item = self.book.get_item_with_id(cover) if cover_item: return cover_item.get_content() - - # In case no cover_item is returned, - # we look for a cover in the guide - for j in self.book.guide: - try: - if (j['title'].lower in ['cover', 'cover-image', 'coverimage'] or - j['type'] == 'coverimagestandard'): - image_path = j['href'] - break - except KeyError: - pass - - # And if all else fails, we find - # the first image referenced in the book - # Fuck everything - if not image_path: - for j in self.book.items: - if j.media_type == 'application/xhtml+xml': - _regex = re.search(r"src=\"(.*)\"\/", j.content.decode('utf-8')) - if _regex: - image_path = _regex[1] - break - - for k in self.book.get_items_of_type(ebooklib.ITEM_IMAGE): - if os.path.basename(k.file_name) == os.path.basename(image_path): - image_content = k.get_content() - break - - return image_content - except KeyError: - return None + pass + + # In case no cover_item is returned, we look for a cover in the guide + for i in self.book.guide: + try: + if (i['title'].lower in ['cover', 'cover-image', 'coverimage'] or + i['type'] == 'coverimagestandard'): + image_path = i['href'] + break + except KeyError: + pass + + # If that fails, we find the first image referenced in the book + if not image_path: + for i in self.book.items: + if i.media_type == 'application/xhtml+xml': + _regex = re.search(r"src=\"(.*)\"\/", i.content.decode('utf-8')) + if _regex: + image_path = _regex[1] + break + + if image_path: + for i in self.book.get_items_of_type(ebooklib.ITEM_IMAGE): + if os.path.basename(i.file_name) == os.path.basename(image_path): + return i.get_content() + + # And if that too fails, we get the first image referenced in the file + for i in self.book.items: + if i.media_type == 'image/jpeg' or i.media_type == 'image/png': + return i.get_content() + def get_isbn(self): try: diff --git a/pie_chart.py b/pie_chart.py index fee52a4..1a3763a 100644 --- a/pie_chart.py +++ b/pie_chart.py @@ -59,7 +59,7 @@ class GeneratePie(): lPath = "%s %s %s" % (lLineOne, lArc, lLineTwo) lGradient = GRADIENTS[lIndex] - lSvgPath += "" % ( + lSvgPath += "" % ( lPath, lGradient) lIndex += 1 @@ -68,19 +68,19 @@ class GeneratePie(): xmlns:xlink="http://www.w3.org/1999/xlink"> - - + + - - + + %s - + """ % (lSvgPath, lOffsetX, lOffsetY) diff --git a/resources/NotFound.png b/resources/NotFound.png new file mode 100644 index 0000000..3d4f76a Binary files /dev/null and b/resources/NotFound.png differ diff --git a/widgets.py b/widgets.py index adfb764..6a43571 100644 --- a/widgets.py +++ b/widgets.py @@ -360,7 +360,7 @@ class LibraryDelegate(QtWidgets.QStyledItemDelegate): QtWidgets.QStyledItemDelegate.paint(self, painter, option, index) pie_chart.GeneratePie(progress_percent, self.temp_dir).generate() svg_path = os.path.join(self.temp_dir, 'lector_progress.svg') - read_icon = QtGui.QIcon(svg_path).pixmap(34) + read_icon = QtGui.QIcon(svg_path).pixmap(32) x_draw = option.rect.bottomRight().x() - 30 y_draw = option.rect.bottomRight().y() - 35