fix few stuff and add inAppNotifications

This commit is contained in:
Bilal Elmoussaoui 2016-07-31 03:20:48 +02:00
parent 90aa37dbcf
commit cd7b49fd65
10 changed files with 171 additions and 24 deletions

View file

@ -55,7 +55,11 @@ class Application(Gtk.Application):
if result == GK.Result.CANCELLED:
self.quit()
cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/TwoFactorAuth/style.css')
if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
cssFileName = "gnome-twofactorauth-post3.20.css"
else:
cssFileName = "ggnome-twofactorauth-pre3.20.css"
cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/TwoFactorAuth/%s' % cssFileName)
cssProvider = Gtk.CssProvider()
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()

View file

@ -7,6 +7,7 @@ app_PYTHON = \
accounts_list.py \
accounts_window.py \
login_window.py \
inapp_notification.py \
headerbar.py \
applications_list.py \
application_row.py \

View file

@ -67,6 +67,7 @@ class AccountRow(Thread, Gtk.ListBoxRow):
code = None
code_generated = True
alive = True
notification = None
def __init__(self, parent, window, app):
Thread.__init__(self)
@ -153,6 +154,8 @@ class AccountRow(Thread, Gtk.ListBoxRow):
code = self.get_code().get_secret_code()
try:
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.window.notification.update(_('Code "%s" copied to clipboard' % str(code)))
self.window.notification.show()
clipboard.clear()
clipboard.set_text(code, len(code))
logging.debug("Secret code copied to clipboard")
@ -371,6 +374,8 @@ class AccountRow(Thread, Gtk.ListBoxRow):
confirmation = ConfirmationMessage(self.window, message)
confirmation.show()
if confirmation.get_confirmation():
self.window.notification.update(_('"%s" was removed' % self.name))
self.window.notification.show()
self.kill()
self.window.accounts_list.remove(self)
self.window.app.db.remove_by_id(self.get_id())

View file

@ -23,6 +23,7 @@ from gi.repository import Gtk, Gdk, Gio
import logging
from TwoFactorAuth.utils import screenshot_area, current_date_time
from TwoFactorAuth.widgets.applications_list import ApplicationChooserWindow
from TwoFactorAuth.widgets.inapp_notification import InAppNotification
from TwoFactorAuth.models.code import Code
from TwoFactorAuth.models.qr_reader import QRReader
from TwoFactorAuth.utils import get_icon
@ -55,6 +56,8 @@ class AddAccount(Gtk.Window):
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
self.set_resizable(False)
self.set_transient_for(self.parent)
self.notification = InAppNotification()
self.connect("key_press_event", self.on_key_press)
def generate_header_bar(self):
@ -124,6 +127,7 @@ class AddAccount(Gtk.Window):
vbox.add(hbox_name)
vbox.add(hbox_secret_code)
labels_box.pack_start(vbox, True, False, 6)
main_box.pack_start(self.notification, False, False, 0)
main_box.pack_start(logo_box, False, True, 6)
main_box.pack_start(labels_box, False, True, 6)
self.add(main_box)
@ -137,6 +141,9 @@ class AddAccount(Gtk.Window):
self.name_entry.set_text(data["issuer"])
self.secret_code.set_text(data["secret"])
self.apply_button.set_sensitive(True)
else:
self.notification.update(_("Selected area is not a valid QR code"))
self.notification.show()
def on_key_press(self, key, key_event):
"""
@ -206,7 +213,7 @@ class AddAccount(Gtk.Window):
applications_choose_window.present()
self.step = 2
else:
self.name_entry.grab_focus_without_selecting()
self.secret_code.grab_focus_without_selecting()
self.show_all()
def close_window(self, *args):

View file

@ -0,0 +1,77 @@
from gi import require_version
require_version("Gtk", "3.0")
from gi.repository import Gtk, Gio, GLib
from gettext import gettext as _
import logging
class InAppNotification(Gtk.Revealer):
timer = 0
def __init__(self, message="", undo_action=None, timeout=5):
Gtk.Revealer.__init__(self)
self.timeout = timeout
self.set_transition_type(Gtk.RevealerTransitionType.SLIDE_DOWN)
self.message = message
self.undo_action = undo_action
self.generate_components()
GLib.timeout_add_seconds(1, self.update_timer)
def generate_components(self):
self.get_style_context().add_class("top")
frame = Gtk.Frame()
self.main_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
frame.props.width_request = 100
frame.get_style_context().add_class("app-notification")
self.undo_button = Gtk.Button()
self.undo_button.set_label(_("Undo"))
if self.undo_action is not None:
self.undo_button.connect("clicked", self.undo_action)
else:
self.undo_button.set_visible(False)
self.undo_button.set_no_show_all(True)
delete_button = Gtk.Button()
delete_icon = Gio.ThemedIcon(name="edit-delete-symbolic")
delete_image = Gtk.Image.new_from_gicon(
delete_icon, Gtk.IconSize.BUTTON)
delete_button.set_tooltip_text(_("Hide notification"))
delete_button.set_image(delete_image)
delete_button.connect("clicked", self.on_hide_notification)
self.message_label = Gtk.Label()
self.message_label.set_text(self.message)
self.main_box.pack_end(delete_button, False, False, 6)
self.main_box.pack_end(self.undo_button, False, False, 6)
self.main_box.pack_start(self.message_label, False, False, 6)
frame.add(self.main_box)
self.add(frame)
def on_hide_notification(self, *args):
self.hide()
def show(self):
self.set_reveal_child(True)
def hide(self):
self.set_reveal_child(False)
def update(self, message, undo_action = None):
self.message_label.set_text(message)
self.timer = 0
if undo_action is not None:
self.undo_button.set_visible(True)
self.undo_button.set_no_show_all(False)
self.undo_action = undo_action
self.undo_button.connect("clicked", self.undo_action)
def update_timer(self):
if self.get_reveal_child():
if self.timer == self.timeout:
self.hide()
self.timer = 0
else:
self.timer += 1
return True

View file

@ -25,6 +25,7 @@ from TwoFactorAuth.widgets.accounts_window import AccountsWindow
from TwoFactorAuth.widgets.login_window import LoginWindow
from TwoFactorAuth.widgets.no_account_window import NoAccountWindow
from TwoFactorAuth.widgets.headerbar import HeaderBar
from TwoFactorAuth.widgets.inapp_notification import InAppNotification
from hashlib import sha256
from gettext import gettext as _
import logging
@ -59,6 +60,8 @@ class Window(Gtk.ApplicationWindow):
self.set_resizable(False)
self.connect("key_press_event", self.on_key_press)
self.connect("delete-event", lambda x, y: self.app.on_quit())
self.notification = InAppNotification()
self.main_box.pack_start(self.notification, False, False, 0)
self.add(self.main_box)
def on_key_press(self, app, key_event):

View file

@ -0,0 +1,27 @@
.applications-list {
background-color: @theme_bg_color;
}
.application-list-row:selected GtkImage {
color: @theme_fg_selected_color;
}
.application-name {
font-weight: bold;
font-size: 12px;
}
.application-logo-add {
margin-right: 5px;
margin-bottom: 10px;
}
.account-secret-code,
.account-timer {
font-size: 11px;
margin-top: 0;
margin-bottom: 5px;
margin-left: 60px;
}
.application-secret-code-select-mode {
margin-left: 98px;
}
.choose-popover GtkLabel {
padding: 10px;
}

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/TwoFactorAuth">
<file>style.css</file>
<file>gnome-twofactorauth-post3.20.css</file>
<file>gnome-twofactorauth-pre3.20.css</file>
<file preprocess="xml-stripblanks">about.ui</file>
<file preprocess="xml-stripblanks">shortcuts.ui</file>
</gresource>

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-19 12:39+0100\n"
"POT-Creation-Date: 2016-07-31 03:20+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -97,8 +97,8 @@ msgid "Remove selected accounts"
msgstr ""
#: TwoFactorAuth/widgets/headerbar.py:71
#: TwoFactorAuth/widgets/add_account.py:49
#: TwoFactorAuth/widgets/add_account.py:64
#: TwoFactorAuth/widgets/add_account.py:50
#: TwoFactorAuth/widgets/add_account.py:67
msgid "Add a new account"
msgstr ""
@ -116,14 +116,14 @@ msgid "Search"
msgstr ""
#: TwoFactorAuth/widgets/headerbar.py:105
#: TwoFactorAuth/widgets/add_account.py:69
#: TwoFactorAuth/widgets/add_account.py:72
#: TwoFactorAuth/widgets/change_password.py:162
#: TwoFactorAuth/widgets/applications_list.py:114
msgid "Cancel"
msgstr ""
#: TwoFactorAuth/widgets/headerbar.py:117 TwoFactorAuth/widgets/settings.py:42
#: TwoFactorAuth/application.py:78
#: TwoFactorAuth/application.py:82
msgid "Settings"
msgstr ""
@ -131,22 +131,26 @@ msgstr ""
msgid "There's no account at the moment"
msgstr ""
#: TwoFactorAuth/widgets/add_account.py:74
#: TwoFactorAuth/widgets/add_account.py:77
msgid "Add"
msgstr ""
#: TwoFactorAuth/widgets/add_account.py:82
#: TwoFactorAuth/widgets/add_account.py:85
msgid "Scan a QR code"
msgstr ""
#: TwoFactorAuth/widgets/add_account.py:104
#: TwoFactorAuth/widgets/add_account.py:107
msgid "Account Name"
msgstr ""
#: TwoFactorAuth/widgets/add_account.py:112
#: TwoFactorAuth/widgets/add_account.py:115
msgid "Secret Code"
msgstr ""
#: TwoFactorAuth/widgets/add_account.py:145
msgid "Selected area is not a valid QR code"
msgstr ""
#: TwoFactorAuth/widgets/change_password.py:36
msgid "Apply"
msgstr ""
@ -183,41 +187,51 @@ msgstr ""
msgid "Unlock"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:219
#: TwoFactorAuth/widgets/account_row.py:157
#, python-format
msgid "Code \"%s\" copied to clipboard"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:222
msgid "Remove the account"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:229
#: TwoFactorAuth/widgets/account_row.py:232
msgid "Copy the generated code"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:239
#: TwoFactorAuth/widgets/account_row.py:242
msgid "Edit the account"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:249
#: TwoFactorAuth/widgets/account_row.py:252
msgid "Save the new account name"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:257
#: TwoFactorAuth/widgets/account_row.py:381
#: TwoFactorAuth/widgets/account_row.py:260
#: TwoFactorAuth/widgets/account_row.py:386
#, python-format
msgid "Expires in %s seconds"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:263
#: TwoFactorAuth/widgets/account_row.py:266
msgid "Error during the generation of code"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:308
#: TwoFactorAuth/widgets/account_row.py:311
msgid "Couldn't generate the secret code"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:370
#: TwoFactorAuth/widgets/account_row.py:373
#, python-format
msgid "Do you really want to remove \"%s\"?"
msgstr ""
#: TwoFactorAuth/widgets/account_row.py:377
#, python-format
msgid "\"%s\" was removed"
msgstr ""
#: TwoFactorAuth/widgets/settings.py:70
msgid "Behavior"
msgstr ""
@ -234,18 +248,26 @@ msgstr ""
msgid "Auto-lock the application (m):"
msgstr ""
#: TwoFactorAuth/widgets/inapp_notification.py:28
msgid "Undo"
msgstr ""
#: TwoFactorAuth/widgets/inapp_notification.py:39
msgid "Hide notification"
msgstr ""
#: TwoFactorAuth/application.py:46
msgid "TwoFactorAuth"
msgstr ""
#: TwoFactorAuth/application.py:86
#: TwoFactorAuth/application.py:90
msgid "Shortcuts"
msgstr ""
#: TwoFactorAuth/application.py:88
#: TwoFactorAuth/application.py:92
msgid "About"
msgstr ""
#: TwoFactorAuth/application.py:89
#: TwoFactorAuth/application.py:93
msgid "Quit"
msgstr ""