Skip to content

Commit

Permalink
replace QMessageBox with QInputDialog ensuring that the user typed th… (
Browse files Browse the repository at this point in the history
#522)

* replace QMessageBox with QInputDialog ensuring that the user typed the full name of the project to delete

* Looping over failed attempts

* Translations, format

* Font colour

* pre-commit

* Fixed destructing ordering

* html tags

* username needed too

* translatability

* Accomodating nickpicking (:

* Fixed incorrectly access username
  • Loading branch information
why-not-try-calmer authored Jun 1, 2023
1 parent 7a80de6 commit 0baf70c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
43 changes: 31 additions & 12 deletions qfieldsync/gui/cloud_projects_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
QFileDialog,
QHBoxLayout,
QHeaderView,
QInputDialog,
QMenu,
QMessageBox,
QPushButton,
Expand Down Expand Up @@ -790,21 +791,39 @@ def on_project_launch_button_clicked(self) -> None:
self.launch()

def on_project_delete_button_clicked(self) -> None:
button_pressed = QMessageBox.question(
self,
self.tr("Delete QFieldCloud project"),
self.tr(
'Are you sure you want to delete the QFieldCloud project "{}"? Nevertheless, your local files will remain.'
).format(self.current_cloud_project.name),
)
username = self.network_manager.user_details["username"]
project_name = self.current_cloud_project.name
expected_input = f"{username}/{project_name}"

def ask(maybe_warning: str = ""):
delete_msg = self.tr("Delete QFieldCloud project")
are_you_sure = self.tr(
"Are you sure you want to delete this QFieldCloud project?"
)
confirm_with = self.tr("To confirm deletion, please type")
reassuring_remark = self.tr(
"The project will be permanently deleted from QFieldCloud, your local copy will remain unaffected"
)
return QInputDialog().getText(
self,
delete_msg,
f"<p><b>{are_you_sure}</b></p>{maybe_warning}<p>{confirm_with} <em>{expected_input}</em>. {reassuring_remark}.</p>",
)

if button_pressed != QMessageBox.Yes:
return
text, ok = ask()

self.projectsStack.setEnabled(False)
if ok:
clean_text = text.strip()
error = self.tr("Incorrect project name!")
while clean_text != expected_input:
updated_text, updated_ok = ask(f"<p style='color:red'>{error}</p>")
if not updated_ok:
return
clean_text = updated_text.strip()

reply = self.network_manager.delete_project(self.current_cloud_project.id)
reply.finished.connect(lambda: self.on_delete_project_reply_finished(reply))
self.projectsStack.setEnabled(False)
reply = self.network_manager.delete_project(self.current_cloud_project.id)
reply.finished.connect(lambda: self.on_delete_project_reply_finished(reply))

def on_delete_project_reply_finished(self, reply: QNetworkReply) -> None:
self.projectsStack.setEnabled(True)
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/setting_manager

0 comments on commit 0baf70c

Please sign in to comment.