Skip to content

Commit 26739d3

Browse files
committed
options for popups when sending highlights
1 parent 5afacee commit 26739d3

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

h2o/button_actions.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def make_sender() -> HighlightSender:
6060
prefs["last_send_time"] = strftime("%Y-%m-%d %H:%M:%S", gmtime())
6161

6262
info = f"Success: {amt} highlight{' has' if amt == 1 else 's have'} been sent to obsidian."
63-
info_dialog(parent, "Highlights Sent", info, show=True)
63+
if prefs['highlights_sent_dialog']:
64+
info_dialog(parent, "Highlights Sent", info, show=True)
6465
else:
6566
info_dialog(parent, "No Highlights Sent", "No highlights to send.", show=True)
6667

@@ -97,14 +98,17 @@ def send_all_highlights(parent, db):
9798
:param parent: QDialog or other window that is the parent of the info dialogs this function makes
9899
:param db: calibre database: Cache().new_api
99100
"""
100-
confirm = QMessageBox()
101-
confirm.setText("Are you sure you want to send ALL highlights to obsidian? This cannot be undone.")
102-
confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
103-
confirm.setIcon(QMessageBox.Question)
104-
confirmed = confirm.exec()
101+
if prefs['confirm_send_all']:
102+
confirm = QMessageBox()
103+
confirm.setText("Are you sure you want to send ALL highlights to obsidian? This cannot be undone.")
104+
confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
105+
confirm.setIcon(QMessageBox.Question)
106+
confirmed = confirm.exec()
105107

106-
if confirmed == QMessageBox.Yes:
107-
send_highlights(parent, db)
108+
if confirmed != QMessageBox.Yes:
109+
return
110+
111+
send_highlights(parent, db)
108112

109113

110114
def send_new_selected_highlights(parent, db):
@@ -145,14 +149,15 @@ def send_all_selected_highlights(parent, db):
145149
:param db: calibre database: Cache().new_api
146150
"""
147151

148-
confirm = QMessageBox()
149-
confirm.setText("Are you sure you want to send ALL highlights of the selected books to obsidian? This cannot be undone.")
150-
confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
151-
confirm.setIcon(QMessageBox.Question)
152-
confirmed = confirm.exec()
152+
if prefs['confirm_send_all']:
153+
confirm = QMessageBox()
154+
confirm.setText("Are you sure you want to send ALL highlights of the selected books to obsidian? This cannot be undone.")
155+
confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
156+
confirm.setIcon(QMessageBox.Question)
157+
confirmed = confirm.exec()
153158

154-
if confirmed != QMessageBox.Yes:
155-
return
159+
if confirmed != QMessageBox.Yes:
160+
return
156161

157162
try:
158163
parent.library_view # check if this exists

h2o/config.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
prefs.defaults['body_format'] = body_default_format
2525
prefs.defaults['no_notes_format'] = no_notes_default_format
2626
prefs.defaults['header_format'] = header_default_format
27-
prefs.defaults['use_header'] = "" # empty string is equal to false
27+
prefs.defaults['use_header'] = False # empty string is equal to false
2828
prefs.defaults['prev_send'] = None # the send time before last_send_time
2929
prefs.defaults['display_help_on_menu_open'] = True
3030
prefs.defaults['sort_key'] = sort_key_default
31+
prefs.defaults['confirm_send_all'] = True # confirmation dialog when sending all highlights
32+
prefs.defaults['highlights_sent_dialog'] = True # show popup with how many highlights were sent
3133

3234

3335
class ConfigWidget(QWidget):
@@ -198,7 +200,7 @@ def save_settings(self):
198200
prefs['body_format'] = self.body_format_input.toPlainText()
199201
prefs['no_notes_format'] = self.no_notes_format_input.toPlainText()
200202
prefs['header_format'] = self.header_format_input.toPlainText()
201-
prefs['use_header'] = "True" if self.header_checkbox.isChecked() else "" # empty string is equal to false
203+
prefs['use_header'] = self.header_checkbox.isChecked()
202204

203205
def ok_button(self):
204206
self.save_settings()
@@ -270,6 +272,20 @@ def __init__(self):
270272

271273
self.l.addSpacing(self.spacing)
272274

275+
# checkbox for confirmation dialog
276+
self.show_confirmation_checkbox = QCheckBox("Confirmation dialog when sending all highlights")
277+
if prefs['confirm_send_all']:
278+
self.show_confirmation_checkbox.setChecked(True)
279+
self.l.addWidget(self.show_confirmation_checkbox)
280+
281+
# checkbox for showing how many highlights were sent
282+
self.show_count_checkbox = QCheckBox("After sending highlights, show how many were sent")
283+
if prefs['highlights_sent_dialog']:
284+
self.show_count_checkbox.setChecked(True)
285+
self.l.addWidget(self.show_count_checkbox)
286+
287+
self.l.addSpacing(self.spacing)
288+
273289
# ok and cancel buttons
274290
self.buttons = QDialogButtonBox()
275291
self.buttons.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
@@ -284,6 +300,8 @@ def set_time_now(self):
284300
def save_settings(self):
285301
prefs['vault_name'] = self.vault_input.text()
286302
prefs['sort_key'] = self.sort_input.text()
303+
prefs['confirm_send_all'] = self.show_confirmation_checkbox.isChecked()
304+
prefs['highlights_sent_dialog'] = self.show_count_checkbox.isChecked()
287305

288306
# validate time input
289307
send_time = self.time_input.text()

0 commit comments

Comments
 (0)