Commit fd63e9c5 authored by Falk Alexander Seidl's avatar Falk Alexander Seidl

Use dconf as settings interface

Dropped the config file settings implementation. Using dconf instead.
parent 0cb68ef9
...@@ -344,12 +344,10 @@ ...@@ -344,12 +344,10 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="show_password_button"> <object class="GtkToggleButton" id="show_password_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
<child> <child>
<object class="GtkImage" id="show_password_button_image"> <object class="GtkImage" id="show_password_button_image">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -361,7 +359,6 @@ ...@@ -361,7 +359,6 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
color: alpha(currentColor,0.5); color: alpha(currentColor,0.5);
} }
#SubtitleLabel {
color: red;
}
.PathbarButtonActive { .PathbarButtonActive {
box-shadow: none; box-shadow: none;
transition-property: none; transition-property: none;
......
...@@ -11,6 +11,12 @@ gnome.compile_resources( ...@@ -11,6 +11,12 @@ gnome.compile_resources(
install: true install: true
) )
# Installing the schema file
install_data(
project_id + '.gschema.xml',
install_dir: 'share/glib-2.0/schemas'
)
# Merging the translations with the desktop file # Merging the translations with the desktop file
i18n.merge_file( i18n.merge_file(
output: project_id + '.desktop', output: project_id + '.desktop',
......
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema path="/run/terminal/KeepassGtk/" id="run.terminal.KeepassGtk" gettext-domain="keepassgtk">
<key type="b" name="dark-theme">
<default>false</default>
<summary>Use dark Gtk theme</summary>
<description>Use the dark variant of your Gtk theme. Please note that not every Gtk theme has a dark variant.</description>
</key>
<key type="b" name="first-start-screen">
<default>true</default>
<summary>Reopen last opened database</summary>
<description>Automatically open the unlock screen of the last opened database, otherwise show the welcome screen.</description>
</key>
<key type="b" name="save-automatically">
<default>false</default>
<summary>Save every change automatically</summary>
<description>Save every change you made instantly into the database. Please note that you cannot revert changes if Autosave is enabled.</description>
</key>
<key type="i" name="database-lock-timeout">
<default>5</default>
<summary>Lock database after x minutes</summary>
<description>Automatically lock your database after a given amount of minutes to improve the security.</description>
</key>
<key type="i" name="clear-clipboard">
<default>30</default>
<summary>Clear clipboard after x seconds</summary>
<description>After copying the password clear the clipboard for security reasons.</description>
</key>
<key type="b" name="show-password-fields">
<default>false</default>
<summary>Display passwords in plain text</summary>
<description>Show the passwords in the entry fields by default.</description>
</key>
<key type="ai" name="window-size">
<default>[800, 500]</default>
<summary>Window size</summary>
<description>Remember the window size.</description>
</key>
<key type="s" name="last-opened-database">
<default>""</default>
<summary>Last opened database</summary>
<description>Path to the last opened database.</description>
</key>
</schema>
</schemalist>
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="settings_theme_description"> <object class="GtkLabel" id="settings_theme_description">
<property name="name">SubtitleLabel</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
...@@ -170,7 +171,7 @@ ...@@ -170,7 +171,7 @@
<property name="halign">start</property> <property name="halign">start</property>
<property name="valign">end</property> <property name="valign">end</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="label" translatable="yes">First Start Screen</property> <property name="label" translatable="yes">Hide First Start Screen</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -180,6 +181,7 @@ ...@@ -180,6 +181,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="settings_fstart_description"> <object class="GtkLabel" id="settings_fstart_description">
<property name="name">SubtitleLabel</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
...@@ -297,6 +299,7 @@ ...@@ -297,6 +299,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="settings_save_description"> <object class="GtkLabel" id="settings_save_description">
<property name="name">SubtitleLabel</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
...@@ -414,6 +417,7 @@ ...@@ -414,6 +417,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="settings_lockdb_description"> <object class="GtkLabel" id="settings_lockdb_description">
<property name="name">SubtitleLabel</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
...@@ -439,21 +443,14 @@ ...@@ -439,21 +443,14 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkMenuButton" id="settings_lockdb_menubutton"> <object class="GtkSpinButton" id="settings_lockdb_spin_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">center</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="margin_right">15</property> <property name="margin_right">15</property>
<property name="popover">settings_lockdb_popover</property> <property name="max_length">2</property>
<child> <property name="input_purpose">number</property>
<object class="GtkLabel" id="settings_lockdb_menubutton_label"> <property name="numeric">True</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Off</property>
</object>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -500,12 +497,13 @@ ...@@ -500,12 +497,13 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="settings_clearcb_description"> <object class="GtkLabel" id="settings_clearcb_description">
<property name="name">SubtitleLabel</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
<property name="valign">start</property> <property name="valign">start</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="label" translatable="yes">Clear Clipboard after copying password</property> <property name="label" translatable="yes">Clear Clipboard after x seconds</property>
<attributes> <attributes>
<attribute name="foreground" value="#555557575353"/> <attribute name="foreground" value="#555557575353"/>
<attribute name="size" value="9500"/> <attribute name="size" value="9500"/>
...@@ -525,13 +523,14 @@ ...@@ -525,13 +523,14 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkSwitch" id="settings_clearcb_switch"> <object class="GtkSpinButton" id="settings_clearcb_spin_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="halign">center</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="margin_right">15</property> <property name="margin_right">15</property>
<property name="hexpand">False</property> <property name="max_length">4</property>
<property name="input_purpose">number</property>
<property name="numeric">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -578,6 +577,7 @@ ...@@ -578,6 +577,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="settings_showpw_description"> <object class="GtkLabel" id="settings_showpw_description">
<property name="name">SubtitleLabel</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">start</property> <property name="halign">start</property>
...@@ -637,113 +637,4 @@ ...@@ -637,113 +637,4 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkPopover" id="settings_lockdb_popover">
<property name="can_focus">False</property>
<property name="relative_to">settings_lockdb_menubutton</property>
<child>
<object class="GtkBox" id="popover_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkModelButton" id="popover_entry_off">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.settings_timeout_off</property>
<property name="text" translatable="yes">Off</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="popover_entry_30sec">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.settings_timeout_30sec</property>
<property name="text" translatable="yes">30 seconds</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="popover_entry_1min">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.settings_timeout_1min</property>
<property name="text" translatable="yes">1 minute</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="popover_entry_5min">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.settings_timeout_5min</property>
<property name="text" translatable="yes">5 minutes</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="popover_entry_15min">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.settings_timeout_15min</property>
<property name="text" translatable="yes">15 minutes</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="popover_entry_30min">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.settings_timeout_30min</property>
<property name="text" translatable="yes">30 minutes</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="popover_entry_1h">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.settings_timeout_1h</property>
<property name="text" translatable="yes">1 hour</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
</object>
</interface> </interface>
...@@ -3,6 +3,7 @@ import sys ...@@ -3,6 +3,7 @@ import sys
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gio, Gtk from gi.repository import GLib, Gio, Gtk
from keepassgtk.main_window import MainWindow from keepassgtk.main_window import MainWindow
from keepassgtk.settings_dialog import SettingsDialog
class Application(Gtk.Application): class Application(Gtk.Application):
...@@ -15,6 +16,7 @@ class Application(Gtk.Application): ...@@ -15,6 +16,7 @@ class Application(Gtk.Application):
def do_startup(self): def do_startup(self):
Gtk.Application.do_startup(self) Gtk.Application.do_startup(self)
GLib.set_application_name('KeepassGtk')
GLib.set_prgname("KeepassGtk") GLib.set_prgname("KeepassGtk")
self.assemble_application_menu() self.assemble_application_menu()
...@@ -52,12 +54,7 @@ class Application(Gtk.Application): ...@@ -52,12 +54,7 @@ class Application(Gtk.Application):
self.set_app_menu(app_menu) self.set_app_menu(app_menu)
def on_settings_menu_clicked(self, action, param): def on_settings_menu_clicked(self, action, param):
builder = Gtk.Builder() SettingsDialog(self.window).on_settings_menu_clicked(action, param)
builder.add_from_resource("/run/terminal/KeepassGtk/settings_dialog.ui")
settings_dialog = builder.get_object("settings_dialog")
settings_dialog.set_modal(True)
settings_dialog.set_transient_for(self.window)
settings_dialog.present()
def on_about_menu_clicked(self, action, param): def on_about_menu_clicked(self, action, param):
builder = Gtk.Builder() builder = Gtk.Builder()
......
import os import os
from os.path import exists, join from os.path import exists, join
from gi.repository import GLib from gi.repository import GLib, Gio
cfg = GLib.KeyFile() setting = Gio.Settings.new("run.terminal.KeepassGtk")
HOME = os.getenv("HOME") clear_clipboard = "clear-clipboard"
CONFIG_PATH = join(HOME, '.config/keepassgtk') dark_theme = "dark-theme"
CONFIG_FILE = join(CONFIG_PATH, 'config.conf') database_lock_timeout = "database-lock-timeout"
first_start_screen = "first-start-screen"
last_opened_database = "last-opened-database"
save_automatically = "save-automatically"
show_password_fields = "show-password-fields"
window_size = "window-size"
# def get_clear_clipboard():
# Create Config (First Run) return setting.get_int(clear_clipboard)
#
def set_clear_clipboard(value):
setting.set_int(clear_clipboard, value)
def configure(): def get_dark_theme():
if not exists(CONFIG_PATH): return setting.get_boolean(dark_theme)
create_config_dir(CONFIG_PATH)
if not exists(CONFIG_FILE): def set_dark_theme(value):
create_config_file(CONFIG_FILE) setting.set_boolean(dark_theme, value)
def get_database_lock_timeout():
return setting.get_int(database_lock_timeout)
def create_config_dir(path): def set_database_lock_timeout(value):
os.mkdir(path) setting.set_int(database_lock_timeout, value)
def get_first_start_screen():
return setting.get_boolean(first_start_screen)
def create_config_file(filename): def set_first_start_screen(value):
create_config_entry_string('settings', 'theme-variant', 'white') setting.set_boolean(first_start_screen, value)
cfg.save_to_file(filename)
# def get_last_opened_database():
# Write Into Config return setting.get_string(last_opened_database)
#
def set_last_opened_database(value):
setting.set_string(last_opened_database, value)
def create_config_entry_string(group, key, string): def get_save_automatically():
cfg.set_string(group, key, string) return setting.get_boolean(save_automatically)
def set_save_automatically(value):
setting.set_boolean(save_automatically, value)
def create_config_entry_integer(group, key, integer): def get_show_password_fields():
cfg.set_integer(group, key, integer) return setting.get_boolean(show_password_fields)
def set_show_password_fields(value):
setting.set_boolean(show_password_fields, value)
def create_config_entry_double(group, key, double): def get_window_size():
cfg.set_double(group, key, double) return setting.get_value(window_size)
def set_window_size(list):
def create_config_entry_boolean(group, key, boolean): g_variant = GLib.Variant('ai', list)
cfg.set_boolean(group, key, boolean) setting.set_value(window_size, g_variant)
#
# Checks
#
def has_group(group):
cfg.load_from_file(CONFIG_FILE, GLib.KeyFileFlags.KEEP_COMMENTS)
return cfg.has_group(group)
# def has_key(key, group):
# config_file = cfg.load_from_file(CONFIG_FILE, GLib.KeyFileFlags.KEEP_COMMENTS)
# group = cfg.
# return cfg.has_key(group, key)
def get_string(key, group):
cfg.load_from_file(CONFIG_FILE, GLib.KeyFileFlags.KEEP_COMMENTS)
return cfg.get_string(key, group)
#
# Save Config
#
def save_config():
cfg.save_to_file(CONFIG_FILE)
def unref_config():
cfg.unref()
from gi.repository import Gio, Gdk, Gtk from gi.repository import Gio, GLib, Gdk, Gtk
from keepassgtk.logging_manager import LoggingManager from keepassgtk.logging_manager import LoggingManager
from keepassgtk.database_manager import DatabaseManager from keepassgtk.database_manager import DatabaseManager
from keepassgtk.create_database import CreateDatabase from keepassgtk.create_database import CreateDatabase
...@@ -29,11 +29,11 @@ class MainWindow(Gtk.ApplicationWindow): ...@@ -29,11 +29,11 @@ class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
keepassgtk.config_manager.configure()
self.assemble_window() self.assemble_window()
def assemble_window(self): def assemble_window(self):
self.set_default_size(800, 500) window_size = keepassgtk.config_manager.get_window_size()
self.set_default_size(window_size[0], window_size[1])
self.create_headerbar() self.create_headerbar()
self.first_start_screen() self.first_start_screen()
...@@ -41,6 +41,7 @@ class MainWindow(Gtk.ApplicationWindow): ...@@ -41,6 +41,7 @@ class MainWindow(Gtk.ApplicationWindow):
self.connect("delete-event", self.on_application_quit) self.connect("delete-event", self.on_application_quit)
self.custom_css() self.custom_css()
self.apply_theme()
# #
# Headerbar # Headerbar
...@@ -82,23 +83,26 @@ class MainWindow(Gtk.ApplicationWindow): ...@@ -82,23 +83,26 @@ class MainWindow(Gtk.ApplicationWindow):
context.add_provider_for_screen( context.add_provider_for_screen(
screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER) screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
def apply_theme(self):
gtk_settings = Gtk.Settings.get_default()
if keepassgtk.config_manager.get_dark_theme() is True:
gtk_settings.set_property("gtk-application-prefer-dark-theme", True)
else:
gtk_settings.set_property("gtk-application-prefer-dark-theme", False)
# #
# First Start Screen # First Start Screen
# #
def first_start_screen(self): def first_start_screen(self):
if keepassgtk.config_manager.has_group("history") and keepassgtk.config_manager.get_string("history", "last-opened-db") != "" and exists(keepassgtk.config_manager.get_string("history", "last-opened-db")): filepath = keepassgtk.config_manager.get_last_opened_database()
self.logging_manager.log_debug(
"Found last opened database entry (" + if keepassgtk.config_manager.get_first_start_screen() is True and filepath is not "":
keepassgtk.config_manager.get_string( self.logging_manager.log_debug("Found last opened database entry (" + filepath + ")")
"history", "last-opened-db") + ")")
tab_title = ntpath.basename(filepath)
tab_title = ntpath.basename(keepassgtk.config_manager.get_string( self.start_database_opening_routine(tab_title, filepath)
"history", "last-opened-db"))
self.start_database_opening_routine(
tab_title,
keepassgtk.config_manager.get_string(
"history", "last-opened-db"))
else: else:
self.logging_manager.log_debug( self.logging_manager.log_debug(
"No / Not valid last opened database entry found.") "No / Not valid last opened database entry found.")
...@@ -337,12 +341,17 @@ class MainWindow(Gtk.ApplicationWindow): ...@@ -337,12 +341,17 @@ class MainWindow(Gtk.ApplicationWindow):
db.database_manager.save_database() db.database_manager.save_database()
self.quit_dialog.destroy() self.quit_dialog.destroy()
self.save_window_size()
self.application.quit() self.application.quit()
# #
# Application Quit Dialog # Application Quit Dialog
# #
def save_window_size(self):
window_size = [self.get_size().width, self.get_size().height]
keepassgtk.config_manager.set_window_size(window_size)
def on_application_quit(self, window, event): def on_application_quit(self, window, event):
unsaved_databases_list = [] unsaved_databases_list = []
for db in self.opened_databases: for db in self.opened_databases:
...@@ -378,4 +387,7 @@ class MainWindow(Gtk.ApplicationWindow): ...@@ -378,4 +387,7 @@ class MainWindow(Gtk.ApplicationWindow):
self.quit_dialog.present() self.quit_dialog.present()
return(True) return(True)
else:
self.save_window_size()
...@@ -17,6 +17,8 @@ class ScrolledPage(Gtk.ScrolledWindow): ...@@ -17,6 +17,8 @@ class ScrolledPage(Gtk.ScrolledWindow):
password_property_row = NotImplemented password_property_row = NotImplemented
password_property_value_entry = NotImplemented password_property_value_entry = NotImplemented
show_password_button = NotImplemented
generate_password_button = NotImplemented
url_property_row = NotImplemented url_property_row = NotImplemented
url_property_value_entry = NotImplemented url_property_value_entry = NotImplemented
......
from gi.repository import Gtk
import keepassgtk.config_manager
import gi
class SettingsDialog():
window = NotImplemented
builder = NotImplemented
def __init__(self, window):
self.window = window
self.builder = Gtk.Builder()
self.builder.add_from_resource("/run/terminal/KeepassGtk/settings_dialog.ui")
def on_settings_menu_clicked(self, action, param):
settings_dialog = self.builder.get_object("settings_dialog")
settings_dialog.set_modal(True)
settings_dialog.set_transient_for(self.window)
settings_dialog.present()
self.set_config_values()
def set_config_values(self):