mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 08:44:40 +01:00
more fixes and better code
This commit is contained in:
parent
10f190d6c4
commit
bfd03d444e
5 changed files with 83 additions and 79 deletions
|
@ -17,11 +17,10 @@ class Application(Gtk.Application):
|
|||
win = None
|
||||
alive = True
|
||||
locked = False
|
||||
menu = Gio.Menu()
|
||||
db = Database()
|
||||
|
||||
settings_window = None
|
||||
settings_action = None
|
||||
|
||||
def __init__(self):
|
||||
Gtk.Application.__init__(self,
|
||||
application_id="org.gnome.TwoFactorAuth",
|
||||
|
@ -29,13 +28,15 @@ class Application(Gtk.Application):
|
|||
GLib.set_application_name(_("TwoFactorAuth"))
|
||||
GLib.set_prgname("Gnome-TwoFactorAuth")
|
||||
|
||||
self.menu = Gio.Menu()
|
||||
self.db = Database()
|
||||
self.cfg = SettingsReader()
|
||||
self.locked = self.cfg.read("state", "login")
|
||||
|
||||
result = GK.unlock_sync("Gnome-TwoFactorAuth", None)
|
||||
if result == GK.Result.CANCELLED:
|
||||
self.quit()
|
||||
|
||||
self.cfg = SettingsReader()
|
||||
if self.cfg.read("state", "login"):
|
||||
self.locked = True
|
||||
cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/TwoFactorAuth/style.css')
|
||||
cssProvider = Gtk.CssProvider()
|
||||
screen = Gdk.Screen.get_default()
|
||||
|
@ -94,9 +95,12 @@ class Application(Gtk.Application):
|
|||
logging.debug("Adding gnome shell menu")
|
||||
|
||||
def do_activate(self, *args):
|
||||
self.win = Window(self)
|
||||
self.win.show_all()
|
||||
self.add_window(self.win)
|
||||
if not self.win:
|
||||
self.win = Window(self)
|
||||
self.win.show_all()
|
||||
self.add_window(self.win)
|
||||
else:
|
||||
self.win.present()
|
||||
|
||||
def refresh_menu(self):
|
||||
if is_gnome():
|
||||
|
@ -130,8 +134,11 @@ class Application(Gtk.Application):
|
|||
"""
|
||||
Shows settings window
|
||||
"""
|
||||
settings_window = SettingsWindow(self.win)
|
||||
settings_window.show_window()
|
||||
if not self.settings_window:
|
||||
self.settings_window = SettingsWindow(self.win)
|
||||
self.settings_window.show_window()
|
||||
else:
|
||||
self.settings_window.present()
|
||||
|
||||
def on_quit(self, *args):
|
||||
"""
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from gi import require_version
|
||||
require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk, GObject, GLib
|
||||
from gi.repository import Gtk, Gdk, GLib
|
||||
from TwoFactorAuth.models.code import Code
|
||||
from TwoFactorAuth.models.settings import SettingsReader
|
||||
from TwoFactorAuth.models.database import Database
|
||||
|
@ -95,16 +95,23 @@ class AccountRow(Thread, Gtk.ListBoxRow):
|
|||
"""
|
||||
self.alive = False
|
||||
|
||||
def copy_code(self, event_box, box):
|
||||
def copy_code(self, *args):
|
||||
"""
|
||||
Copy code shows the code box for a while (10s by default)
|
||||
"""
|
||||
self.timer = 0
|
||||
self.parent.copy_code(event_box)
|
||||
code = self.get_code().get_secret_code()
|
||||
try:
|
||||
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
||||
clipboard.clear()
|
||||
clipboard.set_text(code, len(code))
|
||||
logging.debug("Secret code copied to clipboard")
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
self.code_box.set_visible(True)
|
||||
self.code_box.set_no_show_all(False)
|
||||
self.code_box.show_all()
|
||||
GObject.timeout_add_seconds(1, self.update_timer)
|
||||
GLib.timeout_add_seconds(1, self.update_timer)
|
||||
|
||||
def update_timer(self, *args):
|
||||
"""
|
||||
|
|
|
@ -168,7 +168,6 @@ class HeaderBar(Gtk.HeaderBar):
|
|||
self.toggle_settings_button(True)
|
||||
self.toggle_select_button(False)
|
||||
|
||||
|
||||
def is_on_select_mode(self):
|
||||
return self.remove_button.get_visible()
|
||||
|
||||
|
|
|
@ -62,11 +62,17 @@ class Window(Gtk.ApplicationWindow):
|
|||
"""
|
||||
keypress = Gdk.keyval_name(key_event.keyval).lower()
|
||||
if not self.app.locked:
|
||||
control_mask = Gdk.ModifierType.CONTROL_MASK
|
||||
count = self.app.db.count()
|
||||
if count > 0:
|
||||
if self.list_box.get_selected_row():
|
||||
index = self.list_box.get_selected_row().get_index()
|
||||
else:
|
||||
index = 0
|
||||
selected_row = self.list_box.get_row_at_index(index)
|
||||
control_mask = Gdk.ModifierType.CONTROL_MASK
|
||||
if keypress == "c":
|
||||
if key_event.state == control_mask:
|
||||
self.copy_code()
|
||||
selected_row.copy_code()
|
||||
elif keypress == "l":
|
||||
if key_event.state == control_mask:
|
||||
self.login_box.toggle_lock()
|
||||
|
@ -83,11 +89,7 @@ class Window(Gtk.ApplicationWindow):
|
|||
self.remove_account()
|
||||
elif keypress == "return":
|
||||
if count > 0:
|
||||
if self.list_box.get_selected_row():
|
||||
index = self.list_box.get_selected_row().get_index()
|
||||
else:
|
||||
index = 0
|
||||
self.list_box.get_row_at_index(index).toggle_code_box()
|
||||
selected_row.toggle_code_box()
|
||||
elif keypress == "backspace":
|
||||
if self.search_bar.is_empty():
|
||||
self.hb.search_button.set_active(False)
|
||||
|
@ -195,8 +197,8 @@ class Window(Gtk.ApplicationWindow):
|
|||
"""
|
||||
self.hb.toggle_select_mode()
|
||||
pass_enabled = self.app.cfg.read("state", "login")
|
||||
is_visible = self.hb.is_on_select_mode()
|
||||
if not is_visible:
|
||||
is_select_mode = self.hb.is_on_select_mode()
|
||||
if is_select_mode:
|
||||
self.list_box.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
|
||||
else:
|
||||
self.list_box.set_selection_mode(Gtk.SelectionMode.SINGLE)
|
||||
|
@ -213,11 +215,12 @@ class Window(Gtk.ApplicationWindow):
|
|||
code_label = row.get_code_label()
|
||||
visible = checkbox.get_visible()
|
||||
selected = checkbox.get_active()
|
||||
if not is_visible:
|
||||
style_context = code_label.get_style_context()
|
||||
if is_select_mode:
|
||||
self.select_account(checkbox)
|
||||
code_label.get_style_context().add_class("application-secret-code-select-mode")
|
||||
style_context.add_class("application-secret-code-select-mode")
|
||||
else:
|
||||
code_label.get_style_context().remove_class(
|
||||
style_context.remove_class(
|
||||
"application-secret-code-select-mode")
|
||||
|
||||
checkbox.set_visible(not visible)
|
||||
|
@ -303,25 +306,6 @@ class Window(Gtk.ApplicationWindow):
|
|||
self.list_box.add(AccountRow(self, uid, name, secret_code, image))
|
||||
self.list_box.show_all()
|
||||
|
||||
def copy_code(self, *args):
|
||||
"""
|
||||
Copy the secret code to clipboard
|
||||
"""
|
||||
if len(args) > 0:
|
||||
# if the code is called by clicking on copy button, select the
|
||||
# right ListBowRow
|
||||
row = args[0].get_parent().get_parent().get_parent()
|
||||
self.list_box.select_row(row)
|
||||
selected_row = self.list_box.get_selected_row()
|
||||
code = selected_row.get_code()
|
||||
try:
|
||||
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
||||
clipboard.clear()
|
||||
clipboard.set_text(code, len(code))
|
||||
logging.debug("Secret code copied to clipboard")
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
|
||||
def refresh_window(self):
|
||||
"""
|
||||
Refresh windows components
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-06-12 14:18+0200\n"
|
||||
"POT-Creation-Date: 2016-06-15 02:08+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"
|
||||
|
@ -52,6 +52,11 @@ msgctxt "shortcut window"
|
|||
msgid "Selection mode"
|
||||
msgstr ""
|
||||
|
||||
#: data/shortcuts.ui:64
|
||||
msgctxt "shortcut window"
|
||||
msgid "Lock the application"
|
||||
msgstr ""
|
||||
|
||||
#: data/about.ui:14
|
||||
msgid "Simple application to generate two-factor authentication code"
|
||||
msgstr ""
|
||||
|
@ -63,56 +68,50 @@ msgid ""
|
|||
"later</a> for details."
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:142
|
||||
msgid "Do you really want to remove selected accounts?"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:165
|
||||
msgid "Enter your password"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:169
|
||||
msgid "Unlock"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:235
|
||||
#: TwoFactorAuth/widgets/headerbar.py:43
|
||||
msgid "Remove selected accounts"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:243 TwoFactorAuth/widgets/add_account.py:28
|
||||
#: TwoFactorAuth/widgets/headerbar.py:50
|
||||
#: TwoFactorAuth/widgets/add_account.py:28
|
||||
#: TwoFactorAuth/widgets/add_account.py:43
|
||||
msgid "Add a new account"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:251
|
||||
#: TwoFactorAuth/widgets/headerbar.py:57
|
||||
msgid "Lock the Application"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:263
|
||||
#: TwoFactorAuth/widgets/headerbar.py:73
|
||||
msgid "Selection mode"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:272
|
||||
#: TwoFactorAuth/widgets/headerbar.py:80
|
||||
#: TwoFactorAuth/widgets/applications_list.py:88
|
||||
msgid "Search"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:277 TwoFactorAuth/widgets/add_account.py:48
|
||||
#: TwoFactorAuth/widgets/headerbar.py:84
|
||||
#: TwoFactorAuth/widgets/add_account.py:48
|
||||
#: TwoFactorAuth/widgets/change_password.py:143
|
||||
#: TwoFactorAuth/widgets/applications_list.py:80
|
||||
msgid "Cancel"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:296 TwoFactorAuth/widgets/settings.py:24
|
||||
#: TwoFactorAuth/application.py:65
|
||||
#: TwoFactorAuth/widgets/headerbar.py:96 TwoFactorAuth/widgets/settings.py:24
|
||||
#: TwoFactorAuth/application.py:60
|
||||
msgid "Settings"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:438
|
||||
#: TwoFactorAuth/widgets/no_account_window.py:19
|
||||
msgid "There's no account at the moment"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:536
|
||||
#: TwoFactorAuth/widgets/window.py:140
|
||||
msgid "Do you really want to remove selected accounts?"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/window.py:340
|
||||
msgid "Do you really want to remove this account?"
|
||||
msgstr ""
|
||||
|
||||
|
@ -156,25 +155,33 @@ msgstr ""
|
|||
msgid "Next"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/account_row.py:153
|
||||
#: TwoFactorAuth/widgets/login_window.py:23
|
||||
msgid "Enter your password"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/login_window.py:26
|
||||
msgid "Unlock"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/account_row.py:161
|
||||
msgid "Copy the generated code"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/account_row.py:163
|
||||
#: TwoFactorAuth/widgets/account_row.py:171
|
||||
msgid "Remove the account"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/account_row.py:169
|
||||
#: TwoFactorAuth/widgets/account_row.py:225
|
||||
#: TwoFactorAuth/widgets/account_row.py:177
|
||||
#: TwoFactorAuth/widgets/account_row.py:233
|
||||
#, python-format
|
||||
msgid "Expires in %s seconds"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/account_row.py:175
|
||||
#: TwoFactorAuth/widgets/account_row.py:183
|
||||
msgid "Error during the generation of code"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/widgets/account_row.py:221
|
||||
#: TwoFactorAuth/widgets/account_row.py:229
|
||||
msgid "Couldn't generate the secret code"
|
||||
msgstr ""
|
||||
|
||||
|
@ -198,18 +205,18 @@ msgstr ""
|
|||
msgid "Secret code generation time (s) :"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/application.py:29
|
||||
#: TwoFactorAuth/application.py:28
|
||||
msgid "TwoFactorAuth"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/application.py:73
|
||||
#: TwoFactorAuth/application.py:68
|
||||
msgid "Shortcuts"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/application.py:75
|
||||
#: TwoFactorAuth/application.py:70
|
||||
msgid "About"
|
||||
msgstr ""
|
||||
|
||||
#: TwoFactorAuth/application.py:76
|
||||
#: TwoFactorAuth/application.py:71
|
||||
msgid "Quit"
|
||||
msgstr ""
|
||||
|
|
Loading…
Add table
Reference in a new issue