Skip to content

Commit

Permalink
ask user to type project name to confirm its removal from the server
Browse files Browse the repository at this point in the history
(fix #128)
  • Loading branch information
alexbruy committed Sep 6, 2023
1 parent 0f986b0 commit 7f36764
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Mergin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from functools import partial
from qgis.PyQt.QtCore import pyqtSignal, QTimer, QUrl, QSettings, Qt
from qgis.PyQt.QtGui import QIcon, QDesktopServices, QPixmap
from qgis.PyQt.QtWidgets import QDialog
from qgis.core import (
QgsApplication,
QgsDataCollectionItem,
Expand Down Expand Up @@ -39,6 +40,7 @@
from .project_settings_widget import MerginProjectConfigFactory
from .projects_manager import MerginProjectsManager
from .sync_dialog import SyncDialog
from .remove_project_dialog import RemoveProjectDialog
from .utils import (
ServerType,
ClientError,
Expand Down Expand Up @@ -591,10 +593,13 @@ def clone_remote_project(self):
group_items["My projects"].reload()

def remove_remote_project(self):
msg = "Do you really want to remove project {} from server?".format(self.project_name)
btn_reply = QMessageBox.question(None, "Remove project", msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if btn_reply == QMessageBox.No:
dlg = RemoveProjectDialog(self.project_name)
if dlg.exec_() == QDialog.Rejected:
return
# ~ msg = "Do you really want to remove project {} from server?".format(self.project_name)
# ~ btn_reply = QMessageBox.question(None, "Remove project", msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
# ~ if btn_reply == QMessageBox.No:
# ~ return

try:
self.mc.delete_project(self.project_name)
Expand Down
25 changes: 25 additions & 0 deletions Mergin/remove_project_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os

from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox

ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_remove_project_dialog.ui")


class RemoveProjectDialog(QDialog):
def __init__(self, project_name, parent=None):
QDialog.__init__(self, parent)
self.ui = uic.loadUi(ui_file, self)

self.project_name = project_name
self.label.setText(
f"This action will remove your MerginMaps project '<b>{self.project_name}</b>' from the server. "
"This action cannot be undone.<br><br>"
"In order to delete project, enter project name in the field below and click 'Yes'."
)
self.buttonBox.button(QDialogButtonBox.Yes).setEnabled(False)

self.edit_project_name.textChanged.connect(self.project_name_changed)

def project_name_changed(self, text):
self.buttonBox.button(QDialogButtonBox.Yes).setEnabled(self.project_name == text)
83 changes: 83 additions & 0 deletions Mergin/ui/ui_remove_project_dialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>152</height>
</rect>
</property>
<property name="windowTitle">
<string>Remove project</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>This action will remove your MerginMaps project from the server. This action cannot be undone.

In order to delete project, enter project name in the field below and click &quot;Yes&quot;.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edit_project_name">
<property name="placeholderText">
<string>Enter project name</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::No|QDialogButtonBox::Yes</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 7f36764

Please sign in to comment.