File deletion

This commit is contained in:
BasioMeusPuga
2017-11-07 09:59:33 +05:30
parent 4c8a0f8c4c
commit b0e1cab93e
2 changed files with 46 additions and 10 deletions

View File

@@ -1,18 +1,20 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" TODO """ TODO
Define every widget in code because you're going to need to create separate tabs ✓ sqlite3 for cover images cache
Override the keypress event of the textedit ✓ sqlite3 for storing metadata
✓ Drop down for SortBy (library view)
✓ Define every widget in code because you're going to need to create separate tabs
✓ Override the keypress event of the textedit
Goodreads API: Ratings, Read, Recommendations Goodreads API: Ratings, Read, Recommendations
Get ISBN using python-isbnlib Get ISBN using python-isbnlib
All ebooks should be returned as HTML All ebooks should be returned as HTML
Theming Theming
Search bar in toolbar Search bar in toolbar
Drop down for SortBy (library view) / TOC (book view) Drop down for TOC (book view)
Pagination Pagination
sqlite3 for storing metadata
sqlite3 for caching files open @ time of exit sqlite3 for caching files open @ time of exit
sqlite3 for cover images cache
Use format* icons for toolbar buttons Use format* icons for toolbar buttons
Information dialog widget Information dialog widget
Check file hashes upon restart Check file hashes upon restart
@@ -39,8 +41,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
Settings(self).read_settings() # This should populate all variables that need Settings(self).read_settings() # This should populate all variables that need
# to be remembered across sessions # to be remembered across sessions
Toolbars(self) Toolbars(self)
# I don't know why this is needed # This is an ugly ugly hack
# I can't access the Qcombobox any other way # I can't seem to access the Qcombobox the usual way
self.librarySortingBox = self.LibraryToolBar.children()[-1:][0] self.librarySortingBox = self.LibraryToolBar.children()[-1:][0]
database.DatabaseInit(self.database_path) database.DatabaseInit(self.database_path)
@@ -59,7 +61,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.tabWidget.tabCloseRequested.connect(self.close_tab_class) self.tabWidget.tabCloseRequested.connect(self.close_tab_class)
# ListView # ListView
self.listView.setSpacing(10) self.listView.setSpacing(15)
self.reload_listview() self.reload_listview()
self.listView.doubleClicked.connect(self.listclick) self.listView.doubleClicked.connect(self.listclick)
@@ -88,6 +90,31 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
database.DatabaseFunctions(self.database_path).add_to_database(parsed_books) database.DatabaseFunctions(self.database_path).add_to_database(parsed_books)
self.reload_listview() self.reload_listview()
def delete_books(self):
selected_books = self.listView.selectedIndexes()
if selected_books:
def ifcontinue(box_button):
if box_button.text() == '&Yes':
selected_hashes = []
for i in selected_books:
book_row = i.row()
book_data = i.data(QtCore.Qt.UserRole)
selected_hashes.append(book_data['book_hash'])
self.listView.model().removeRow(book_row)
database.DatabaseFunctions(
self.database_path).delete_from_database(selected_hashes)
selected_number = len(selected_books)
msg_box = QtWidgets.QMessageBox()
msg_box.setText(f'Delete {selected_number} book(s)?')
msg_box.setIcon(QtWidgets.QMessageBox.Question)
msg_box.setWindowTitle('Confirm deletion')
msg_box.setStandardButtons(
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
msg_box.buttonClicked.connect(ifcontinue)
msg_box.show()
msg_box.exec_()
def reload_listview(self): def reload_listview(self):
lib_ref = Library(self) lib_ref = Library(self)
lib_ref.load_listView() lib_ref.load_listView()
@@ -169,6 +196,7 @@ class Library:
book_cover = i[8] book_cover = i[8]
book_tags = i[6] book_tags = i[6]
additional_data = { additional_data = {
'book_title': i[1],
'book_path': i[4], 'book_path': i[4],
'book_isbn': i[5], 'book_isbn': i[5],
'book_hash': i[7]} 'book_hash': i[7]}
@@ -259,7 +287,7 @@ class Toolbars:
addButton.triggered.connect(self.parent_window.open_file) addButton.triggered.connect(self.parent_window.open_file)
settingsButton.triggered.connect(self.parent_window.create_tab_class) settingsButton.triggered.connect(self.parent_window.create_tab_class)
deleteButton.triggered.connect(self.parent_window.reload_listview) deleteButton.triggered.connect(self.parent_window.delete_books)
# Sorter # Sorter
sorting_choices = ['Title', 'Author', 'Year'] sorting_choices = ['Title', 'Author', 'Year']
@@ -277,7 +305,6 @@ class Toolbars:
self.parent_window.LibraryToolBar.addAction(deleteButton) self.parent_window.LibraryToolBar.addAction(deleteButton)
self.parent_window.LibraryToolBar.addSeparator() self.parent_window.LibraryToolBar.addSeparator()
self.parent_window.LibraryToolBar.addAction(settingsButton) self.parent_window.LibraryToolBar.addAction(settingsButton)
self.parent_window.LibraryToolBar.addSeparator()
self.parent_window.LibraryToolBar.addWidget(spacer) self.parent_window.LibraryToolBar.addWidget(spacer)
self.parent_window.LibraryToolBar.addWidget(sortingBox) self.parent_window.LibraryToolBar.addWidget(sortingBox)

View File

@@ -121,3 +121,12 @@ class DatabaseFunctions:
# except sqlite3.OperationalError: # except sqlite3.OperationalError:
except KeyError: except KeyError:
print('SQLite is in rebellion, Commander') print('SQLite is in rebellion, Commander')
def delete_from_database(self, file_hashes):
# 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}'")
self.database.commit()