Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rmol committed Jul 19, 2021
1 parent fe91a5d commit e06894d
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 127 deletions.
220 changes: 122 additions & 98 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,8 @@ def __init__(self):
layout.setSpacing(0)
layout.addWidget(deletion_message, 0, 0, Qt.AlignRight | Qt.AlignVCenter)
layout.addWidget(spinner, 0, 1, Qt.AlignLeft | Qt.AlignVCenter)
layout.setColumnStretch(0, 2)
layout.setColumnStretch(1, 1)
layout.setColumnStretch(0, 9)
layout.setColumnStretch(1, 7)

self.setLayout(layout)

Expand Down Expand Up @@ -1222,8 +1222,8 @@ def __init__(self):

layout.addWidget(self.deletion_message, 0, 0, Qt.AlignRight | Qt.AlignVCenter)
layout.addWidget(spinner, 0, 1, Qt.AlignLeft | Qt.AlignVCenter)
layout.setColumnStretch(0, 2)
layout.setColumnStretch(1, 1)
layout.setColumnStretch(0, 9)
layout.setColumnStretch(1, 7)

self.setLayout(layout)

Expand Down Expand Up @@ -2714,38 +2714,17 @@ class ModalDialog(QDialog):
MARGIN = 40
NO_MARGIN = 0

def __init__(self, show_header=True, dangerous=False):
def __init__(self, show_header: bool = True, dangerous: bool = False):
parent = QApplication.activeWindow()
super().__init__(parent)
self.setObjectName("ModalDialog")
self.setModal(True)

self.show_header = show_header
self.dangerous = dangerous
if self.dangerous:
self.setProperty("class", "dangerous")

# Header for icon and task title
header_container = QWidget()
header_container_layout = QHBoxLayout()
header_container.setLayout(header_container_layout)
self.header_icon = SvgLabel("blank.svg", svg_size=QSize(64, 64))
self.header_icon.setObjectName("ModalDialog_header_icon")
self.header_spinner = QPixmap()
self.header_spinner_label = QLabel()
self.header_spinner_label.setObjectName("ModalDialog_header_spinner")
self.header_spinner_label.setMinimumSize(64, 64)
self.header_spinner_label.setVisible(False)
self.header_spinner_label.setPixmap(self.header_spinner)
self.header = QLabel()
self.header.setObjectName("ModalDialog_header")
header_container_layout.addWidget(self.header_icon)
header_container_layout.addWidget(self.header_spinner_label)
header_container_layout.addWidget(self.header, alignment=Qt.AlignCenter)
header_container_layout.addStretch()

self.header_line = QWidget()
self.header_line.setObjectName("ModalDialog_header_line")

# Widget for displaying error messages
self.error_details = QLabel()
self.error_details.setObjectName("ModalDialog_error_details")
Expand All @@ -2760,43 +2739,46 @@ def __init__(self, show_header=True, dangerous=False):
self.body.setScaledContents(True)
body_container = QWidget()
self.body_layout = QVBoxLayout()
self.body_layout.setContentsMargins(self.MARGIN, self.NO_MARGIN, self.MARGIN, self.MARGIN)
self.body_layout.setContentsMargins(
self.NO_MARGIN, self.NO_MARGIN, self.NO_MARGIN, self.NO_MARGIN
)
body_container.setLayout(self.body_layout)
self.body_layout.addWidget(self.body)

# Buttons to continue and cancel
window_buttons = QWidget()
window_buttons.setObjectName("ModalDialog_window_buttons")
button_layout = QVBoxLayout()
window_buttons.setLayout(button_layout)
self.cancel_button = QPushButton(_("CANCEL"))
self.cancel_button.setObjectName("ModalDialog_cancel_button")
self.cancel_button.setStyleSheet(self.BUTTON_CSS)
self.cancel_button.clicked.connect(self.close)
self.cancel_button.setAutoDefault(False)
self.continue_button = QPushButton(_("CONTINUE"))
self.continue_button.setObjectName("ModalDialog_primary_button")
self.continue_button.setStyleSheet(self.BUTTON_CSS)
self.continue_button.setDefault(True)
self.continue_button.setIconSize(QSize(21, 21))
button_box = QDialogButtonBox(Qt.Horizontal)
button_box.setObjectName("ModalDialog_button_box")
button_box.addButton(self.cancel_button, QDialogButtonBox.ActionRole)
button_box.addButton(self.continue_button, QDialogButtonBox.ActionRole)
button_layout.addWidget(button_box, alignment=Qt.AlignRight)
button_layout.setContentsMargins(self.NO_MARGIN, self.NO_MARGIN, self.MARGIN, self.MARGIN)

# Main widget layout
layout = QVBoxLayout(self)
layout.setContentsMargins(40, 40, 40, 40)
layout.setContentsMargins(self.MARGIN, self.MARGIN, self.MARGIN, self.MARGIN)
self.setLayout(layout)

if self.show_header:
# Header for icon and task title
header_container = QWidget()
header_container_layout = QHBoxLayout()
header_container.setLayout(header_container_layout)
self.header_icon = SvgLabel("blank.svg", svg_size=QSize(64, 64))
self.header_icon.setObjectName("ModalDialog_header_icon")
self.header_spinner = QPixmap()
self.header_spinner_label = QLabel()
self.header_spinner_label.setObjectName("ModalDialog_header_spinner")
self.header_spinner_label.setMinimumSize(64, 64)
self.header_spinner_label.setVisible(False)
self.header_spinner_label.setPixmap(self.header_spinner)
self.header = QLabel()
self.header.setObjectName("ModalDialog_header")
header_container_layout.addWidget(self.header_icon)
header_container_layout.addWidget(self.header_spinner_label)
header_container_layout.addWidget(self.header, alignment=Qt.AlignCenter)
header_container_layout.addStretch()

self.header_line = QWidget()
self.header_line.setObjectName("ModalDialog_header_line")

layout.addWidget(header_container)
layout.addWidget(self.header_line)

layout.addWidget(self.error_details)
layout.addWidget(body_container)
layout.addStretch()
layout.addWidget(window_buttons)
layout.addWidget(self.configure_buttons())

# Activestate animation.
self.button_animation = load_movie("activestate-wide.gif")
Expand All @@ -2808,6 +2790,51 @@ def __init__(self, show_header=True, dangerous=False):
self.header_animation.setScaledSize(QSize(64, 64))
self.header_animation.frameChanged.connect(self.animate_header)

def configure_buttons(self):
# Buttons to continue and cancel
window_buttons = QWidget()
window_buttons.setObjectName("ModalDialog_window_buttons")

button_layout = QVBoxLayout()
window_buttons.setLayout(button_layout)

self.cancel_button = QPushButton(_("CANCEL"))
self.cancel_button.setStyleSheet(self.BUTTON_CSS)
self.cancel_button.clicked.connect(self.close)

self.continue_button = QPushButton(_("CONTINUE"))
self.continue_button.setStyleSheet(self.BUTTON_CSS)
self.continue_button.setIconSize(QSize(21, 21))

button_box = QDialogButtonBox(Qt.Horizontal)
button_box.setObjectName("ModalDialog_button_box")

if self.dangerous:
self.cancel_button.setAutoDefault(True)
self.continue_button.setDefault(False)
self.cancel_button.setObjectName("ModalDialog_primary_button")
self.continue_button.setObjectName("ModalDialog_cancel_button")
else:
self.cancel_button.setAutoDefault(False)
self.continue_button.setDefault(True)
self.cancel_button.setObjectName("ModalDialog_cancel_button")
self.continue_button.setObjectName("ModalDialog_primary_button")

button_box.addButton(self.cancel_button, QDialogButtonBox.ActionRole)
button_box.addButton(self.continue_button, QDialogButtonBox.ActionRole)

self.confirmation_label = QLabel()
self.confirmation_label.setObjectName("ModalDialogConfirmation")
button_layout.addWidget(self.confirmation_label, 0, Qt.AlignLeft | Qt.AlignBottom)

button_layout.addWidget(button_box, alignment=Qt.AlignLeft)

button_layout.setContentsMargins(
self.NO_MARGIN, self.NO_MARGIN, self.NO_MARGIN, self.NO_MARGIN
)

return window_buttons

def keyPressEvent(self, event: QKeyEvent):
if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
if self.cancel_button.hasFocus():
Expand Down Expand Up @@ -3245,31 +3272,32 @@ def __init__(self, source, controller):
self.controller = controller

self.body.setText(self.make_body_text())
self.adjustSize()

self.continue_button.setText(_("YES, DELETE SOURCE ACCOUNT"))
self.continue_button.setText(_("YES, DELETE ENTIRE SOURCE ACCOUNT"))
self.continue_button.clicked.connect(self.delete_source)

self.confirmation_label.setText(_("Are you sure this is what you want?"))

self.adjustSize()

def make_body_text(self) -> str:
message_tuple = (
"<style>li {{line-height: 150%;}}</li></style>",
"<style>",
"p {{white-space: nowrap;}}",
"</style>",
"<p><b>",
_("When the entire account for a source is deleted:"),
"</b></p>",
"<ul>",
"<li>",
_("That source will not be able to log in with their codename again."),
"</li>",
"<li>",
"<p><b>\u2219</b>&nbsp;",
_("The source will not be able to log in with their codename again."),
"</p>",
"<p><b>\u2219</b>&nbsp;",
_("Your organization will not be able to send them replies."),
"</li>",
"<li>",
"</p>",
"<p><b>\u2219</b>&nbsp;",
_("All files and messages from that source will also be destroyed."),
"</li>",
"</ul>",
"<p>",
_("Are you sure this is what you want for {source}?"),
"</p>",
"<p>&nbsp;</p>",
)

return "".join(message_tuple).format(
Expand All @@ -3294,11 +3322,12 @@ def __init__(self, source, controller):
self.controller = controller

self.body.setText(self.make_body_text())
self.adjustSize()

self.continue_button.setText(_("YES, DELETE FILES AND MESSAGES"))
self.continue_button.clicked.connect(self.delete_conversation)

self.adjustSize()

def make_body_text(self) -> str:
files = 0
messages = 0
Expand All @@ -3314,34 +3343,36 @@ def make_body_text(self) -> str:
message_tuple = (
"<style>li {{line-height: 150%;}}</li></style>",
"<p>",
_("This will delete the following content associated with source {source}:"),
"</p>",
"<ul>",
"<li>",
ngettext("one message", "{message_count} messages", messages).format(
message_count=messages
_(
"You would like to delete {files_to_delete}, {replies_to_delete}, "
"{messages_to_delete} from the source account for {source}?"
),
"</li>",
"<li>",
ngettext("one file", "{file_count} files", files).format(file_count=files),
"</li>",
"<li>",
ngettext("one reply", "{reply_count} replies", replies).format(reply_count=replies),
"</li>",
"</ul>",
"</p>",
"<p>",
_(
"This will not delete the account or its metadata, and the source {source} "
"will still be able to log in to your SecureDrop and communicate with you."
"Preserving the account will retain its metadata, and the ability for {source} "
"to log in to your SecureDrop again."
),
"</p>",
)

files_to_delete = ngettext("one file", "{file_count} files", files).format(file_count=files)

replies_to_delete = ngettext("one reply", "{reply_count} replies", replies).format(
reply_count=replies
)

messages_to_delete = ngettext("one message", "{message_count} messages", messages).format(
message_count=messages
)

source = "<b>{}</b>".format(self.source.journalist_designation)

return "".join(message_tuple).format(
files=files,
messages=messages,
replies=replies,
source="<b>{}</b>".format(self.source.journalist_designation),
files_to_delete=files_to_delete,
messages_to_delete=messages_to_delete,
replies_to_delete=replies_to_delete,
source=source,
)

@pyqtSlot()
Expand Down Expand Up @@ -4011,14 +4042,6 @@ def update_label_width(self, width):
self.source_name_label.setText(self.source_name)


class DeleteSeparatorAction(QAction):
def __init__(self, parent):
self.text = _("DELETE")

super().__init__(self.text, parent)
self.setSeparator(True)


class DeleteSourceAction(QAction):
"""Use this action to delete the source record."""

Expand Down Expand Up @@ -4079,10 +4102,11 @@ def __init__(self, source, controller):
self.setStyleSheet(self.SOURCE_MENU_CSS)
separator_font = QFont()
separator_font.setLetterSpacing(QFont.AbsoluteSpacing, 2)
separator_font.setBold(True)

delete_section = DeleteSeparatorAction(self)
delete_section = self.addSection(_("DELETE"))
delete_section.setFont(separator_font)
self.addAction(delete_section)

self.addAction(DeleteConversationAction(self.source, self, self.controller))
self.addAction(DeleteSourceAction(self.source, self, self.controller))

Expand Down
4 changes: 1 addition & 3 deletions securedrop_client/resources/css/modal_dialog_button.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
background-color: #f1f1f6;
color: #fff;
border: 2px solid #f1f1f6;
margin: 0px 0px 0px 12px;
margin: 0;
height: 40px;
padding-left: 20px;
padding-right: 20px;
}
23 changes: 21 additions & 2 deletions securedrop_client/resources/css/sdclient.css
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,15 @@ QWidget#FileWidget_horizontal_line {
#ModalDialog_header {
min-height: 68px;
max-height: 68px;
margin: 0px 0px 0px 4px;
margin: 0;
font-family: 'Montserrat';
font-size: 24px;
font-weight: 600;
color: #2a319d;
}

#ModalDialog_header_line {
margin: 0px 40px 20px 40px;
margin: 0;
min-height: 2px;
max-height: 2px;
background-color: rgba(42, 49, 157, 0.15);
Expand All @@ -456,11 +456,30 @@ QWidget#FileWidget_horizontal_line {
font-family: 'Montserrat';
font-size: 16px;
color: #302aa3;
margin: 0;
padding: 0;
}

#ModalDialogConfirmation {
font-family: 'Montserrat';
font-size: 16px;
font-weight: 600;
color: #302aa3;
margin: 0;
}

#ModalDialog.dangerous #ModalDialogConfirmation {
color: #ff3366;
}

#ModalDialog_button_box {
border: 1px solid #ff0000;
}

#ModalDialog_button_box QPushButton {
margin: 0px 0px 0px 12px;
height: 40px;
margin: 0;
padding-left: 20px;
padding-right: 20px;
border: 2px solid #2a319d;
Expand Down
Loading

0 comments on commit e06894d

Please sign in to comment.