Skip to content

Commit

Permalink
Adding functionality to delete Source
Browse files Browse the repository at this point in the history
A Source Profile Short menu, which is responsible for displaying Source
name and Hamburger Button Menu. Hamburger button menu contains single
operation to delete the Source.

Resolves: freedomofpress#18
  • Loading branch information
ultimatecoder committed Nov 5, 2018
1 parent 7249c6f commit f9cb4b6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
13 changes: 11 additions & 2 deletions securedrop_client/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from PyQt5.QtCore import Qt
from securedrop_client import __version__
from securedrop_client.gui.widgets import (ToolBar, MainView, LoginDialog,
ConversationView)
ConversationView,
SourceProfileShortWidget)
from securedrop_client.resources import load_icon


Expand Down Expand Up @@ -220,7 +221,15 @@ def show_conversation_for(self, source):
"identity details released. She feels "
"horrible. She wants the children who survived "
"to find peace. Thanks.")
self.main_view.update_view(conversation)

container = QWidget()
layout = QVBoxLayout()
container.setLayout(layout)
source_profile = SourceProfileShortWidget(source)

layout.addWidget(source_profile)
layout.addWidget(conversation)
self.main_view.update_view(container)

def set_status(self, message, duration=5000):
"""
Expand Down
86 changes: 84 additions & 2 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import logging
import arrow
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter
from PyQt5.QtGui import QPainter, QIcon
from PyQt5.QtWidgets import (QListWidget, QTextEdit, QLabel, QToolBar, QAction,
QWidget, QListWidgetItem, QHBoxLayout,
QPushButton, QVBoxLayout, QLineEdit, QScrollArea,
QPlainTextEdit, QSpacerItem, QSizePolicy, QDialog)
QPlainTextEdit, QSpacerItem, QSizePolicy, QDialog,
QMenu, QToolButton)
from securedrop_client.resources import load_svg, load_image
from securedrop_client.utils import humanize_filesize

Expand Down Expand Up @@ -530,3 +531,84 @@ def add_reply(self, reply, files=None):
Add a reply from a journalist.
"""
self.conversation_layout.addWidget(ReplyWidget(reply))
if files:
for f in files:
self.conversation_layout.addWidget(FileWidget(f, 'right'))


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

def __init__(self, source, parent):
self.source = source
self.text = _("Delete")
super().__init__(self.text, parent)
self.triggered.connect(self._delete_source)

def _delete_source(self):
self.source.delete()


class SourceMenu(QMenu):
"""
Renders Menu for performing various operations to Source.
Note: It only supports "delete" operation at the moment.
"""

def __init__(self, source):
super().__init__()
self.source = source
actions = (
DeleteSourceAction(self.source, self),
)
for action in actions:
self.addAction(action)


class HamburgerMenuButton(QToolButton):
"""
A menu button for displaying source menu
"""

def __init__(self, source):
super().__init__()
self.source = source
hamburger_icon = load_image("hamburger_icon.png")
self.setIcon(QIcon(hamburger_icon))
self.setMenu(SourceMenu(self.source))
self.setPopupMode(QToolButton.InstantPopup)


class TitleLabel(QLabel):
"""
Centered aligned, Heading level 3 label
"""

def __init__(self, text):
html_text = "<h3>%s</h3>" % (text,)
super().__init__(_(html_text))
self.setAlignment(Qt.AlignCenter)


class SourceProfileShortWidget(QWidget):
"""
Renders a Source Profile short view.
It contains a journalist designation and menu to perform single operation
delete at the moment.
"""

def __init__(self, source):
super().__init__()
self.source = source
self.layout = QHBoxLayout()
self.setLayout(self.layout)
widgets = (
TitleLabel(self.source.journalist_designation),
HamburgerMenuButton(self.source)
)
for widget in widgets:
self.layout.addWidget(widget)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f9cb4b6

Please sign in to comment.